-
Notifications
You must be signed in to change notification settings - Fork 26
/
Plugin.php
141 lines (127 loc) · 4.48 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php namespace OFFLINE\ResponsiveImages;
use Backend\FormWidgets\FileUpload;
use Cms\Classes\Theme;
use Illuminate\Support\Facades\Event;
use October\Rain\Exception\ApplicationException;
use OFFLINE\ResponsiveImages\Classes\Focuspoint\File as FocusFile;
use OFFLINE\ResponsiveImages\Classes\Focuspoint\FocuspointExtension;
use OFFLINE\ResponsiveImages\Classes\SVG\SVGInliner;
use OFFLINE\ResponsiveImages\Console\ConvertCommand;
use OFFLINE\ResponsiveImages\Console\GenerateResizedImages;
use OFFLINE\ResponsiveImages\Console\Clear;
use System\Classes\PluginBase;
use System\Models\File;
use System\Traits\AssetMaker;
use URL;
/**
* ResponsiveImages Plugin Information File
*/
class Plugin extends PluginBase
{
use AssetMaker;
/**
* Boot method, called right before the request route.
*
* @return array
*/
public function boot()
{
$this->app['Illuminate\Contracts\Http\Kernel']
->pushMiddleware('OFFLINE\ResponsiveImages\Classes\ResponsiveImagesMiddleware');
FocuspointExtension::boot();
}
/**
* Returns information about this plugin.
*
* @return array
*/
public function pluginDetails()
{
return [
'name' => 'offline.responsiveimages::lang.plugin.name',
'description' => 'offline.responsiveimages::lang.plugin.description',
'author' => 'offline.responsiveimages::lang.plugin.author',
'homepage' => 'https://github.com/OFFLINE-GmbH/oc-responsive-images-plugin',
'icon' => 'icon-file-image-o',
];
}
/**
* Registers any back-end permissions.
*
* @return array
*/
public function registerPermissions()
{
return [
'offline.responsiveimages.manage_settings' => [
'tab' => 'offline.responsiveimages::lang.plugin.name',
'label' => 'offline.responsiveimages::lang.plugin.manage_settings_permission',
],
];
}
/**
* Registers any back-end settings.
*
* @return array
*/
public function registerSettings()
{
return [
'config' => [
'label' => 'offline.responsiveimages::lang.plugin.name',
'description' => 'offline.responsiveimages::lang.plugin.manage_settings',
'category' => 'system::lang.system.categories.cms',
'icon' => 'icon-file-image-o',
'class' => 'Offline\ResponsiveImages\Models\Settings',
'order' => 500,
'keywords' => 'responsive images',
'permissions' => ['offline.responsiveimages.manage_settings'],
],
];
}
public function register()
{
$this->registerConsoleCommand('responsiveimages:generate', GenerateResizedImages::class);
$this->registerConsoleCommand('responsiveimages:convert', ConvertCommand::class);
$this->registerConsoleCommand('responsiveimages:clear', Clear::class);
}
public function registerMarkupTags()
{
return [
'functions' => [
'svg' => function ($path, $vars = []) {
$theme = Theme::getActiveTheme();
if (!$theme) {
return '';
}
$themeDir = $theme->getId();
// Try to fetch the file from the current theme.
$themePath = themes_path(implode('/', [$themeDir, $path]));
// If the file does not exist, check if there is a parent theme.
if (!file_exists($themePath) && $parentTheme = $theme->getParentTheme()) {
$themeDir = $parentTheme->getId();
$parentThemeDir = themes_path(implode('/', [$parentTheme->getId(), $path]));
if (file_exists($path)) {
$path = $parentThemeDir;
}
}
return (new SVGInliner($themeDir))->inline($path, $vars);
},
],
];
}
/**
* Returns the extra report widgets.
*
* @return array
*/
public function registerReportWidgets()
{
return [
'OFFLINE\ResponsiveImages\ReportWidgets\ClearCache' => [
'label' => 'offline.responsiveimages::lang.reportwidgets.clearcache.label',
'context' => 'dashboard'
]
];
}
}