-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlugin.php
80 lines (68 loc) · 2.32 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
<?php namespace Filipac\ThemePreview;
use Backend\Facades\BackendAuth;
use Filipac\ThemePreview\Models\Settings;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Response;
use System\Classes\PluginBase;
use System\Classes\SettingsManager;
/**
* ThemePreview Plugin Information File
*/
class Plugin extends PluginBase
{
protected $deferred = true;
/**
* Returns information about this plugin.
*
* @return array
*/
public function pluginDetails()
{
return [
'name' => 'filipac.themepreview::lang.name',
'description' => 'filipac.themepreview::lang.description',
'author' => 'filipac',
'icon' => 'icon-cog'
];
}
public function boot()
{
$activeThemeFn = function ($app) {
$active = Settings::get('active', '0');
$permission = Settings::get('permission', 'cms.manage_themes');
if ($active == '0') {
return null;
}
$theme = Settings::get('theme', '');
return strlen($theme) > 0 && BackendAuth::getUser() !== null && BackendAuth::getUser()->hasAccess($permission) ? $theme : null;
};
app()['filipac.activetheme'] = $activeThemeFn;
\Event::listen('cms.theme.getActiveTheme', function () {
return app('filipac.activetheme');
});
}
public function registerPermissions()
{
return [
'filipac.themepreview.manage_settings' => [
'label' => 'filipac.themepreview::lang.permissions.manage_settings',
'tab' => 'cms::lang.permissions.name'
]
];
}
public function registerSettings()
{
return [
'settings_themepreview' => [
'label' => 'filipac.themepreview::lang.name',
'description' => 'filipac.themepreview::lang.description',
'category' => SettingsManager::CATEGORY_CMS,
'icon' => 'icon-cog',
'class' => 'filipac\ThemePreview\Models\Settings',
'order' => 500,
'permissions' => [ 'filipac.themepreview.manage_settings' ],
'keywords' => 'theme layout preview'
]
];
}
}