-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.php
115 lines (104 loc) · 3.07 KB
/
Plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php declare(strict_types=1);
namespace RatMD\Responsive;
use October\Rain\Exception\ApplicationException;
use RatMD\Responsive\Classes\ResponsiveHandler;
use RatMD\Responsive\Models\Setting;
use Response;
use System\Classes\PluginBase;
/**
* Plugin Information File
*
* @link https://docs.octobercms.com/3.x/extend/system/plugins.html
*/
class Plugin extends PluginBase
{
/**
* Details about this plugin.
*
* @return array
*/
public function pluginDetails()
{
return [
'name' => 'ratmd.responsive::lang.plugin.name',
'description' => 'ratmd.responsive::lang.plugin.description',
'author' => 'RatMD',
'icon' => 'icon-picture-o',
'homepage' => 'https://www.rat.md'
];
}
/**
* Register Plugin
*
* @return void
*/
public function register()
{
}
/**
* Boot Plugin
*
* @return void
*
* @throws ApplicationException The output path %s for the responsive images could not be created.
*/
public function boot()
{
$output = storage_path('/app/media/responsive-files');
if (!file_exists($output)) {
if (@mkdir($output, 0777, true) === false) {
throw new ApplicationException("The output path '$output' for the responsive images could not be created.");
}
}
}
/**
* Register Plugin Settings
*
* @return array
*/
public function registerSettings()
{
return [
'ratmd_responsive_settings' => [
'label' => 'ratmd.responsive::lang.settings.menu.label',
'description' => 'ratmd.responsive::lang.settings.menu.description',
'category' => 'CATEGORY_CMS',
'keywords' => 'responsive images convert',
'icon' => 'icon-picture-o',
'class' => Setting::class
]
];
}
/**
* Register Twig Markups
*
* @return array
*/
public function registerMarkupTags()
{
return [
'filters' => [
'convert' => function () {
$handler = new ResponsiveHandler();
return $handler->convert(...func_get_args());
}
],
'functions' => [
'picture' => function () {
$handler = new ResponsiveHandler();
$args = func_get_args();
if (func_num_args() === 1 && is_array($args[0])) {
return $handler->picture(
$args[0]['image'],
$args[0]['breakpoints'],
$args[0]['formats'] ?? [],
$args[0]['attributes'] ?? []
);
} else {
return $handler->picture(...func_get_args());
}
}
]
];
}
}