-
Notifications
You must be signed in to change notification settings - Fork 1
/
Plugin.php
169 lines (149 loc) · 5.7 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php namespace Gviabcua\DevTools;
use System\Classes\PluginBase;
use System\Classes\SettingsManager;
use Event;
use Backend;
use BackendAuth;
use BackendMenu;
use Gviabcua\DevTools\Models\Settings as Tools;
use Db;
class Plugin extends PluginBase
{
public $elevated = true;
public function pluginDetails()
{
return [
'name' => 'gviabcua.devtools::lang.plugin.name',
'description' => 'gviabcua.devtools::lang.plugin.description',
'author' => 'gviabcua.devtools::lang.plugin.author',
'icon' => 'icon-wrench',
'homepage' => 'https://github.com/gergo85/oc-devtools'
];
}
public function registerSettings()
{
return [
'devtool' => [
'label' => 'gviabcua.devtools::lang.help.menu_label',
'description' => 'gviabcua.devtools::lang.help.menu_description',
'icon' => 'icon-wrench',
'class' => 'Gviabcua\DevTools\Models\Settings',
'category' => SettingsManager::CATEGORY_SYSTEM,
'permissions' => ['gviabcua.devtools.settings']
]
];
}
public function registerFormWidgets()
{
return [
'Gviabcua\DevTools\FormWidgets\Help' => [
'label' => 'Help',
'code' => 'help'
]
];
}
public function registerPermissions()
{
return [
'gviabcua.devtools.editor' => [
'tab' => 'gviabcua.devtools::lang.plugin.name',
'label' => 'gviabcua.devtools::lang.editor.permission',
'order' => 100,
'roles' => ['developer']
],
'gviabcua.devtools.settings' => [
'tab' => 'gviabcua.devtools::lang.plugin.name',
'label' => 'gviabcua.devtools::lang.help.permission',
'order' => 200,
'roles' => ['developer']
]
];
}
public function boot()
{
// Add new menu
BackendMenu::registerCallback(function($manager) {
$manager->registerMenuItems('Gviabcua.DevTools', [
'editor' => [
'label' => 'gviabcua.devtools::lang.editor.menu_label',
'url' => Backend::url('gviabcua/devtools/editor'),
'icon' => 'icon-file-code-o',
'iconSvg' => 'plugins/gviabcua/devtools/assets/images/devtools-icon.svg',
'permissions' => ['gviabcua.devtools.editor'],
'order' => 390,
'sideMenu' => [
'assets' => [
'label' => 'gviabcua.devtools::lang.editor.plugins',
'icon' => 'icon-cubes',
'url' => 'javascript:;',
'attributes' => ['data-menu-item' => 'assets'],
'counterLabel' => 'cms::lang.asset.unsaved_label',
'order' => 100
]
]
]
]);
});
// Add new features
Event::listen('backend.form.extendFields', function($form)
{
// Security check
if (!BackendAuth::check()) {
return;
}
// Help docs
if ($this->tools_enabled('help') && (get_class($form->config->model) == 'Cms\Classes\Page' || get_class($form->config->model) == 'Cms\Classes\Partial' || get_class($form->config->model) == 'Cms\Classes\Layout') || get_class($form->config->model) == 'Gviabcua\DevTools\Classes\Asset') {
if (get_class($form->config->model) == 'Gviabcua\DevTools\Classes\Asset') {
$content = 'php';
}
else {
$content = 'cms';
}
$form->addSecondaryTabFields([
'help' => [
'label' => '',
'tab' => 'gviabcua.devtools::lang.help.tab',
'type' => 'help',
'content' => $content
]
]);
return;
}
// Wysiwyg editor
if ($this->tools_enabled('wysiwyg') && get_class($form->config->model) == 'Cms\Classes\Content') {
foreach ($form->getFields() as $field) {
if (!empty($field->config['type']) && $field->config['type'] == 'codeeditor') {
$field->config['type'] = $field->config['widget'] = 'richeditor';
}
}
}
});
}
public function tools_enabled($name)
{
// Security check
if ($name != 'help' && $name != 'wysiwyg') {
return false;
}
// Is enabled
if (!Tools::get($name.'_enabled', false)) {
return false;
}
// My account
$admin = BackendAuth::getUser();
// Is superuser
if (Tools::get($name.'_superuser', false) && $admin->is_superuser == 1) {
return true;
}
// Is admin group
if (Tools::get($name.'_admingroup', false) > 0 && Db::table('backend_users_groups')->where(['user_id' => $admin->id, 'user_group_id' => Tools::get($name.'_admingroup', false)])->count() == 1) {
return true;
}
// Is current user
if (Tools::get($name.'_adminid', false) > 0 && $admin->id == Tools::get($name.'_adminid', false)) {
return true;
}
// Finish
return false;
}
}