-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathPlugin.php
More file actions
191 lines (166 loc) · 8.14 KB
/
Copy pathPlugin.php
File metadata and controls
191 lines (166 loc) · 8.14 KB
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?php
namespace ShahiemSeymor\Ckeditor;
use App;
use Backend;
use Event;
use Illuminate\Foundation\AliasLoader;
use ShahiemSeymor\Ckeditor\Models\Settings;
use System\Classes\PluginManager;
use System\Classes\PluginBase;
use System\Classes\SettingsManager;
class Plugin extends PluginBase
{
public function pluginDetails()
{
return [
'name' => 'CKEditor',
'description' => 'shahiemseymor.ckeditor::lang.plugin.description',
'author' => 'Shahiem Seymor',
'icon' => 'icon-paperclip',
'homepage' => 'https://octobercms.com/plugin/shahiemseymor-ckeditor'
];
}
public function registerFormWidgets()
{
return [
'ShahiemSeymor\Ckeditor\FormWidgets\Wysiwyg' => [
'label' => 'Wysiwyg',
'alias' => 'wysiwyg'
]
];
}
public function registerSettings()
{
return [
'settings' => [
'label' => 'CKEditor',
'description' => 'shahiemseymor.ckeditor::lang.settings.description',
'icon' => 'icon-paperclip',
'context' => 'mysettings',
'category' => SettingsManager::CATEGORY_MYSETTINGS,
'class' => 'ShahiemSeymor\Ckeditor\Models\Settings'
]
];
}
public function registerComponents()
{
return [
'ShahiemSeymor\Ckeditor\Components\Ckeditor' => 'ckeditor',
];
}
public function boot()
{
Event::listen('backend.form.extendFields', function($form)
{
$editors = ['richeditor', 'codeeditor', 'Eein\Wysiwyg\FormWidgets\Trumbowyg', 'RainLab\Blog\FormWidgets\BlogMarkdown'];
if($form->model instanceof \ShahiemSeymor\Ckeditor\Models\Settings)
{
if(PluginManager::instance()->hasPlugin('Radiantweb.Problog'))
{
$form->addFields([
'show_radiantweb_problog_as_wysiwyg' => [
'label' => 'shahiemseymor.ckeditor::lang.show.radiantweb_problog',
'type' => 'switch',
'span' => 'auto',
'default' => 'false',
'comment' => 'shahiemseymor.ckeditor::lang.plugins.comment',
'tab' => 'shahiemseymor.ckeditor::lang.plugins.tab'
]
], 'primary');
}
if(PluginManager::instance()->hasPlugin('Radiantweb.Proevents'))
{
$form->addFields([
'show_radiantweb_proevents_as_wysiwyg' => [
'label' => 'shahiemseymor.ckeditor::lang.show.radiantweb_proevents',
'type' => 'switch',
'span' => 'auto',
'default' => 'false',
'comment' => 'shahiemseymor.ckeditor::lang.plugins.comment',
'tab' => 'shahiemseymor.ckeditor::lang.plugins.tab'
]
], 'primary');
}
if(PluginManager::instance()->hasPlugin('RainLab.Pages'))
{
$form->addFields([
'show_rainlab_pages_as_wysiwyg' => [
'label' => 'shahiemseymor.ckeditor::lang.show.rainlab_static_pages',
'type' => 'switch',
'span' => 'auto',
'default' => 'false',
'comment' => 'shahiemseymor.ckeditor::lang.plugins.comment',
'tab' => 'shahiemseymor.ckeditor::lang.plugins.tab'
]
], 'primary');
}
if(PluginManager::instance()->hasPlugin('RainLab.Editable'))
{
$form->addFields([
'show_rainlab_editable_as_wysiwyg' => [
'label' => 'shahiemseymor.ckeditor::lang.show.rainlab_editable',
'type' => 'switch',
'span' => 'auto',
'default' => 'false',
'comment' => 'shahiemseymor.ckeditor::lang.plugins.comment',
'tab' => 'shahiemseymor.ckeditor::lang.plugins.tab'
]
], 'primary');
}
if(PluginManager::instance()->hasPlugin('RainLab.Blog'))
{
$form->addFields([
'show_rainlab_blog_as_wysiwyg' => [
'label' => 'shahiemseymor.ckeditor::lang.show.rainlab_blog',
'type' => 'switch',
'span' => 'auto',
'default' => 'false',
'comment' => 'shahiemseymor.ckeditor::lang.plugins.comment',
'tab' => 'shahiemseymor.ckeditor::lang.plugins.tab'
]
], 'primary');
}
if(PluginManager::instance()->hasPlugin('ShahiemSeymor.Maintenance'))
{
$form->addFields([
'show_shahiem_maintenance_as_wysiwyg' => [
'label' => 'shahiemseymor.ckeditor::lang.show.shahiemseymor_maintenance',
'type' => 'switch',
'span' => 'auto',
'default' => 'false',
'comment' => 'shahiemseymor.ckeditor::lang.plugins.comment',
'tab' => 'shahiemseymor.ckeditor::lang.plugins.tab'
]
], 'primary');
}
}
if(Settings::get('show_cms_pages_as_wysiwyg', false) && get_class($form->config->model) == 'Cms\Classes\Page')
return static::useEditor($form, $editors);
if(Settings::get('show_cms_content_as_wysiwyg', false) && get_class($form->config->model) == 'Cms\Classes\Content')
return static::useEditor($form, $editors);
if(Settings::get('show_cms_partial_as_wysiwyg', false) && get_class($form->config->model) == 'Cms\Classes\Partial')
return static::useEditor($form, $editors);
if(Settings::get('show_cms_layouts_as_wysiwyg', false) && get_class($form->config->model) == 'Cms\Classes\Layout')
return static::useEditor($form, $editors);
if(Settings::get('show_rainlab_blog_as_wysiwyg', false) && $form->model instanceof \RainLab\Blog\Models\Post)
return static::useEditor($form, $editors);
if(Settings::get('show_shahiem_maintenance_as_wysiwyg', false) && $form->model instanceof \ShahiemSeymor\Maintenance\Models\Settings)
return static::useEditor($form, ['richeditor', 'Eein\Wysiwyg\FormWidgets\Trumbowyg']);
if(Settings::get('show_rainlab_pages_as_wysiwyg', false) && get_class($form->config->model) == 'RainLab\Pages\Classes\Page')
return static::useEditor($form, $editors);
if(Settings::get('show_radiantweb_problog_as_wysiwyg', false) && $form->model instanceof \Radiantweb\Problog\Models\Post)
return static::useEditor($form, $editors);
if(Settings::get('show_radiantweb_proevents_as_wysiwyg', false) && $form->model instanceof \Radiantweb\Proevents\Models\Event)
return static::useEditor($form, $editors);
});
}
public static function useEditor($form, $editor)
{
foreach ($form->getFields() as $field)
{
if (empty($field->config['type']) || !in_array($field->config['type'], $editor))
continue;
$field->config['type'] = $field->config['widget'] = 'ShahiemSeymor\Ckeditor\FormWidgets\Wysiwyg';
}
}
}