forked from symphonycms2-extensions/richtext_redactor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.driver.php
413 lines (340 loc) · 20.2 KB
/
extension.driver.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
<?php
Class extension_richtext_redactor extends Extension{
private $buttons = array('html', 'formatting', 'bold', 'italic', 'deleted', 'unorderedlist', 'orderedlist', 'outdent', 'indent', 'image', 'video', 'file', 'table', 'link', 'fontcolor', 'backcolor', 'alignleft', 'aligncenter', 'alignright', 'justify', 'horizontalrule');
private $airbuttons = array('formatting', 'bold', 'italic', 'deleted', 'unorderedlist', 'orderedlist', 'outdent', 'indent', 'fontcolor', 'backcolor');
private $allowedtags = array("code", "span", "div", "label", "a", "br", "p", "b", "i", "del", "strike", "u", "img", "video", "audio", "iframe", "object", "embed", "param", "blockquote", "mark", "cite", "small", "ul", "ol", "li", "hr", "dl", "dt", "dd", "sup", "sub", "big", "pre", "code", "figure", "figcaption", "strong", "em", "table", "tr", "td", "th", "tbody", "thead", "tfoot", "h1", "h2", "h3", "h4", "h5", "h6");
private $languages = array(
"English" => "en",
"Albanian" => "sq",
"Arabic" => "ar",
"Argentinian Spanish" => "es_ar",
"Belorussian" => "by",
"Bosnian" => "ba",
"Brazilian Portuguese" => "pt_br",
"Bulgarian" => "bg",
"Catalan" => "ca",
"Chinese Simplified" => "zh_cn",
"Chinese Traditional" => "zh_tw",
"Croatian" => "hr",
"Czech" => "cs",
"Danish" => "da",
"Dutch" => "nl",
"Esperanto" => "eo",
"Finnish" => "fi",
"French" => "fr",
"German" => "de",
"Greek" => "el",
"Hungarian" => "hu",
"Indonesian" => "id",
"Italian" => "it",
"Japanese" => "ja",
"Korean" => "ko",
"Latvian" => "lv",
"Lithuanian" => "lt",
"Norwegian" => "no_NB",
"Persian" => "fa",
"Polish" => "pl",
"Portuguese" => "pt_pt",
"Romanian" => "ro",
"Russian" => "ru",
"Serbian Cyrillic" => "sr-cir",
"Serbian Latin" => "sr-lat",
"Slovak" => "sk",
"Spanish" => "es",
"Swedish" => "sv",
"Turkish" => "tr",
"Ukrainian" => "ua",
"Vietnamese" => "vi"
);
public function install() {
Symphony::Configuration()->set('lang', 'en', 'redactor');
Symphony::Configuration()->set('direction_ltr', 'yes', 'redactor');
Symphony::Configuration()->set('enable_toolbar', 'yes', 'redactor');
Symphony::Configuration()->set('enable_source', 'yes', 'redactor');
Symphony::Configuration()->set('enable_focus', 'no', 'redactor');
Symphony::Configuration()->set('enable_shortcuts', 'yes', 'redactor');
Symphony::Configuration()->set('enable_autoresizing', 'yes', 'redactor');
Symphony::Configuration()->set('enable_cleanup', 'yes', 'redactor');
Symphony::Configuration()->set('enable_fixed', 'no', 'redactor');
Symphony::Configuration()->set('enable_fixedbox', 'no', 'redactor');
Symphony::Configuration()->set('enable_paragraphy', 'yes', 'redactor');
Symphony::Configuration()->set('enable_convertlinks', 'yes', 'redactor');
Symphony::Configuration()->set('enable_convertdivs', 'yes', 'redactor');
Symphony::Configuration()->set('enable_fileupload', 'no', 'redactor');
Symphony::Configuration()->set('enable_imageupload', 'yes', 'redactor');
Symphony::Configuration()->set('enable_overlay', 'yes', 'redactor');
Symphony::Configuration()->set('enable_observeimages', 'yes', 'redactor');
Symphony::Configuration()->set('enable_airmode', 'no', 'redactor');
Symphony::Configuration()->set('enable_wym', 'no', 'redactor');
Symphony::Configuration()->set('enable_mobile', 'yes', 'redactor');
Symphony::Configuration()->set('buttons', implode($this->buttons, ','), 'redactor');
Symphony::Configuration()->set('airbuttons', implode($this->airbuttons, ','), 'redactor');
Symphony::Configuration()->set('allowedtags', implode($this->allowedtags, ','), 'redactor');
Symphony::Configuration()->set('filepath', WORKSPACE . '/redactor/files', 'redactor');
Symphony::Configuration()->set('imagepath', WORKSPACE . '/redactor/images', 'redactor');
Symphony::Configuration()->write();
return (General::realiseDirectory(Symphony::Configuration()->get('filepath', 'redactor')) &&
General::realiseDirectory(Symphony::Configuration()->get('imagepath', 'redactor')));
}
/*-------------------------------------------------------------------------
Delegate
-------------------------------------------------------------------------*/
public function getSubscribedDelegates(){
return array(
array(
'page' => '/backend/',
'delegate' => 'InitaliseAdminPageHead',
'callback' => 'initaliseAdminPageHead'
),
array(
'page' => '/system/preferences/',
'delegate' => 'AddCustomPreferenceFieldsets',
'callback' => 'appendPreferences'
),
array(
'page' => '/system/preferences/',
'delegate' => 'Save',
'callback' => 'savePreferences'
)
);
}
/*-------------------------------------------------------------------------
Delegated functions
-------------------------------------------------------------------------*/
public function initaliseAdminPageHead($context) {
$page = Administration::instance()->Page;
// only on publish pages
if(!$page instanceOf contentPublish) return;
// which are showing new/edit form
$callback = Administration::instance()->getPageCallback();
if(!in_array($callback['context']['page'], array('new', 'edit'))) return;
Administration::instance()->Page->addStylesheetToHead(URL . '/extensions/richtext_redactor/lib/redactor.css', 'screen', 200);
Administration::instance()->Page->addStylesheetToHead(URL . '/extensions/richtext_redactor/assets/redactor.css', 'screen', 210);
Administration::instance()->Page->addScriptToHead(URL . '/extensions/richtext_redactor/lib/jquery.redactor.js', 200);
Administration::instance()->Page->addScriptToHead(URL . '/extensions/richtext_redactor/lib/redactor.min.js', 201);
Administration::instance()->Page->addScriptToHead(URL . '/symphony/extension/richtext_redactor/redactor/', 202);
$code = Symphony::Configuration()->get('lang','redactor');
if(isset($code) && $code != 'en') {
Administration::instance()->Page->addScriptToHead(URL . '/extensions/richtext_redactor/lib/lang/' . $code . '.js', 203);
}
}
public function appendPreferences($context) {
$group = new XMLElement('fieldset');
$group->setAttribute('class', 'redactor settings');
$group->appendChild(new XMLElement('legend', 'Redactor RichText Editor'));
$columns = new XMLElement('div',null, array("class" => "group"));
// First Column
$div = new XMLElement('div',null, array("class" => "options"));
$label = Widget::Label();
$input = Widget::Input('settings[redactor][enable_focus]', 'yes', 'checkbox');
if(Symphony::Configuration()->get('enable_focus', 'redactor') == 'yes') $input->setAttribute('checked', 'checked');
$label->setValue($input->generate() . ' ' . __('Set focus to Redactor editor on page load'));
$div->appendChild($label);
$label = Widget::Label();
$input = Widget::Input('settings[redactor][enable_toolbar]', 'yes', 'checkbox');
if(Symphony::Configuration()->get('enable_toolbar', 'redactor') == 'yes') $input->setAttribute('checked', 'checked');
$label->setValue($input->generate() . ' ' . __('Display the Toolbar in the Redactor editor'));
$div->appendChild($label);
$label = Widget::Label();
$input = Widget::Input('settings[redactor][enable_source]', 'yes', 'checkbox');
if(Symphony::Configuration()->get('enable_source', 'redactor') == 'yes') $input->setAttribute('checked', 'checked');
$label->setValue($input->generate() . ' ' . __('Enable the HTML source button on the toolbar'));
$div->appendChild($label);
$label = Widget::Label();
$input = Widget::Input('settings[redactor][enable_airmode]', 'yes', 'checkbox');
if(Symphony::Configuration()->get('enable_airmode', 'redactor') == 'yes') $input->setAttribute('checked', 'checked');
$label->setValue($input->generate() . ' ' . __('Enable air-mode'));
$div->appendChild($label);
$label = Widget::Label();
$input = Widget::Input('settings[redactor][enable_wym]', 'yes', 'checkbox');
if(Symphony::Configuration()->get('enable_wym', 'redactor') == 'yes') $input->setAttribute('checked', 'checked');
$label->setValue($input->generate() . ' ' . __('Enable visual structure mode'));
$div->appendChild($label);
$label = Widget::Label();
$input = Widget::Input('settings[redactor][enable_autoresizing]', 'yes', 'checkbox');
if(Symphony::Configuration()->get('enable_autoresizing', 'redactor') == 'yes') $input->setAttribute('checked', 'checked');
$label->setValue($input->generate() . ' ' . __('Enable height autoresizing'));
$div->appendChild($label);
$label = Widget::Label();
$input = Widget::Input('settings[redactor][enable_observeimages]', 'yes', 'checkbox');
if(Symphony::Configuration()->get('enable_observeimages', 'redactor') == 'yes') $input->setAttribute('checked', 'checked');
$label->setValue($input->generate() . ' ' . __('Enable image properties dialog'));
$div->appendChild($label);
$label = Widget::Label();
$input = Widget::Input('settings[redactor][enable_paragraphy]', 'yes', 'checkbox');
if(Symphony::Configuration()->get('enable_paragraphy', 'redactor') == 'yes') $input->setAttribute('checked', 'checked');
$label->setValue($input->generate() . ' ' . __('Enable formatting to paragraphs'));
$div->appendChild($label);
$label = Widget::Label();
$input = Widget::Input('settings[redactor][enable_cleanup]', 'yes', 'checkbox');
if(Symphony::Configuration()->get('enable_cleanup', 'redactor') == 'yes') $input->setAttribute('checked', 'checked');
$label->setValue($input->generate() . ' ' . __('Enable text cleanup on paste'));
$div->appendChild($label);
$label = Widget::Label();
$input = Widget::Input('settings[redactor][enable_convertlinks]', 'yes', 'checkbox');
if(Symphony::Configuration()->get('enable_convertlinks', 'redactor') == 'yes') $input->setAttribute('checked', 'checked');
$label->setValue($input->generate() . ' ' . __('Automatically replace URLs with hyperlinks'));
$div->appendChild($label);
$label = Widget::Label();
$input = Widget::Input('settings[redactor][enable_convertdivs]', 'yes', 'checkbox');
if(Symphony::Configuration()->get('enable_convertdivs', 'redactor') == 'yes') $input->setAttribute('checked', 'checked');
$label->setValue($input->generate() . ' ' . __('Automatically replace divs to paragraphs'));
$div->appendChild($label);
$label = Widget::Label();
$input = Widget::Input('settings[redactor][enable_fileupload]', 'yes', 'checkbox');
if(Symphony::Configuration()->get('enable_fileupload', 'redactor') == 'yes') $input->setAttribute('checked', 'checked');
$label->setValue($input->generate() . ' ' . __('Enable file upload from the Redactor editor'));
$div->appendChild($label);
$label = Widget::Label();
$input = Widget::Input('settings[redactor][enable_imageupload]', 'yes', 'checkbox');
if(Symphony::Configuration()->get('enable_imageupload', 'redactor') == 'yes') $input->setAttribute('checked', 'checked');
$label->setValue($input->generate() . ' ' . __('Enable image upload from the Redactor editor'));
$div->appendChild($label);
$label = Widget::Label();
$input = Widget::Input('settings[redactor][enable_shortcuts]', 'yes', 'checkbox');
if(Symphony::Configuration()->get('enable_shortcuts', 'redactor') == 'yes') $input->setAttribute('checked', 'checked');
$label->setValue($input->generate() . ' ' . __('Enable keydown / keyup shortcuts functionality'));
$div->appendChild($label);
$label = Widget::Label();
$input = Widget::Input('settings[redactor][enable_mobile]', 'yes', 'checkbox');
if(Symphony::Configuration()->get('enable_mobile', 'redactor') == 'yes') $input->setAttribute('checked', 'checked');
$label->setValue($input->generate() . ' ' . __('Enable the editor for mobile devices'));
$div->appendChild($label);
$label = Widget::Label();
$input = Widget::Input('settings[redactor][enable_overlay]', 'yes', 'checkbox');
if(Symphony::Configuration()->get('enable_overlay', 'redactor') == 'yes') $input->setAttribute('checked', 'checked');
$label->setValue($input->generate() . ' ' . __('Enable overlay for modal Redactor windows'));
$div->appendChild($label);
$label = Widget::Label();
$input = Widget::Input('settings[redactor][enable_fixed]', 'yes', 'checkbox');
if(Symphony::Configuration()->get('enable_fixed', 'redactor') == 'yes') $input->setAttribute('checked', 'checked');
$label->setValue($input->generate() . ' ' . __('The toolbar will remain at the top of the browser window (fixed) at all times'));
$div->appendChild($label);
$label = Widget::Label();
$input = Widget::Input('settings[redactor][enable_fixedbox]', 'yes', 'checkbox');
if(Symphony::Configuration()->get('enable_fixedbox', 'redactor') == 'yes') $input->setAttribute('checked', 'checked');
$label->setValue($input->generate() . ' ' . __('This option makes a fixed toolbar to the width of the editor (in fixed mode)'));
$div->appendChild($label);
$label = Widget::Label();
$input = Widget::Input('settings[redactor][direction_ltr]', 'yes', 'checkbox');
if(Symphony::Configuration()->get('direction_ltr', 'redactor') == 'yes') $input->setAttribute('checked', 'checked');
$label->setValue($input->generate() . ' ' . __('Text direction is Left-To-Right (ltr). Uncheck for Right-To-Left (rtl)'));
$div->appendChild($label);
$columns->appendChild($div);
// Second Column
$div = new XMLElement('div');
// Language options
$options = array();
$language = Symphony::Configuration()->get('lang','redactor');
foreach($this->languages as $lang=>$code)
$options[$code] = array($code, (($code == $language) ? true : false) ,__($lang));
$label = Widget::Label();
$input = Widget::Select('settings[redactor][lang]', $options);
$label->setValue(__('Language') . $input->generate());
$div->appendChild($label);
// Toolbar buttons
$options = array();
$buttons = Symphony::Configuration()->get('buttons','redactor');
$buttons = explode(',', $buttons);
foreach($this->buttons as $item)
$options[$item] = array($item, (in_array($item, $buttons) ? true : false), __(ucfirst($item)));
$label = Widget::Label();
$input = Widget::Select('settings[redactor][buttons][]', $options, array('multiple' => 'multiple'));
$label->setValue(__('Toolbar Buttons') . $input->generate());
$div->appendChild($label);
// Air buttons
$options = array();
$airbuttons = Symphony::Configuration()->get('airbuttons','redactor');
$airbuttons = explode(',', $airbuttons);
foreach($this->buttons as $item)
$options[$item] = array($item, (in_array($item, $airbuttons) ? true : false), __(ucfirst($item)));
$label = Widget::Label();
$input = Widget::Select('settings[redactor][airbuttons][]', $options, array('multiple' => 'multiple'));
$label->setValue(__('Air Buttons (in air mode)') . $input->generate());
$div->appendChild($label);
// Allowed Tags
$options = array();
$allowedtags = Symphony::Configuration()->get('allowedtags','redactor');
$allowedtags = explode(',', $allowedtags);
$options = array();
foreach($this->allowedtags as $item)
$options[$item] = array($item, (in_array($item, $allowedtags) ? true : false), __(ucfirst($item)));
$label = Widget::Label();
$input = Widget::Select('settings[redactor][allowedtags][]', $options, array('multiple' => 'multiple'));
$label->setValue(__('Allowed Tags') . $input->generate());
$div->appendChild($label);
// File Upload location
$label = Widget::Label();
$input = Widget::Input('settings[redactor][filepath]', Symphony::Configuration()->get('filepath', 'redactor'), 'text');
$label->setValue(__('File upload location') . $input->generate());
$div->appendChild($label);
$div->appendChild(new XMLElement('span',"The directory where uploaded files are stored (default: WORKSPACE/redactor/files)", array("class"=>"help")));
// File Upload location
$label = Widget::Label();
$input = Widget::Input('settings[redactor][imagepath]', Symphony::Configuration()->get('imagepath', 'redactor'), 'text');
$label->setValue(__('Image upload location') . $input->generate());
$div->appendChild($label);
$div->appendChild(new XMLElement('span',"The directory where uploaded images are stored (default: WORKSPACE/redactor/images)", array("class"=>"help")));
$columns->appendChild($div);
$group->appendChild($columns);
$context['wrapper']->appendChild($group);
}
public function savePreferences($context) {
if(!isset($context['settings']['redactor']['enable_airmode']))
$context['settings']['redactor']['enable_airmode'] = 'no';
if(!isset($context['settings']['redactor']['enable_wym']))
$context['settings']['redactor']['enable_wym'] = 'no';
if(!isset($context['settings']['redactor']['enable_paragraphy']))
$context['settings']['redactor']['enable_paragraphy'] = 'no';
if(!isset($context['settings']['redactor']['enable_cleanup']))
$context['settings']['redactor']['enable_cleanup'] = 'no';
if(!isset($context['settings']['redactor']['enable_fileupload']))
$context['settings']['redactor']['enable_fileupload'] = 'no';
if(!isset($context['settings']['redactor']['enable_imageupload']))
$context['settings']['redactor']['enable_imageupload'] = 'no';
if(!isset($context['settings']['redactor']['enable_shortcuts']))
$context['settings']['redactor']['enable_shortcuts'] = 'no';
if(!isset($context['settings']['redactor']['enable_mobile']))
$context['settings']['redactor']['enable_mobile'] = 'no';
if(!isset($context['settings']['redactor']['enable_autoresizing']))
$context['settings']['redactor']['enable_autoresizing'] = 'no';
if(!isset($context['settings']['redactor']['enable_toolbar']))
$context['settings']['redactor']['enable_toolbar'] = 'no';
if(!isset($context['settings']['redactor']['enable_source']))
$context['settings']['redactor']['enable_source'] = 'no';
if(!isset($context['settings']['redactor']['enable_fixed']))
$context['settings']['redactor']['enable_fixed'] = 'no';
if(!isset($context['settings']['redactor']['enable_fixedbox']))
$context['settings']['redactor']['enable_fixedbox'] = 'no';
if(!isset($context['settings']['redactor']['enable_convertlinks']))
$context['settings']['redactor']['enable_convertlinks'] = 'no';
if(!isset($context['settings']['redactor']['enable_convertdivs']))
$context['settings']['redactor']['enable_convertdivs'] = 'no';
if(!isset($context['settings']['redactor']['enable_overlay']))
$context['settings']['redactor']['enable_overlay'] = 'no';
if(!isset($context['settings']['redactor']['enable_focus']))
$context['settings']['redactor']['enable_focus'] = 'no';
if(!isset($context['settings']['redactor']['direction_ltr']))
$context['settings']['redactor']['direction_ltr'] = 'no';
if(!isset($context['settings']['redactor']['enable_observeimages']))
$context['settings']['redactor']['enable_observeimages'] = 'no';
$buttons = $context['settings']['redactor']['buttons'];
if(isset($buttons)) {
$context['settings']['redactor']['buttons'] = implode(',', $buttons);
} else {
$context['settings']['redactor']['buttons'] = '';
}
$airbuttons = $context['settings']['redactor']['airbuttons'];
if(isset($airbuttons)) {
$context['settings']['redactor']['airbuttons'] = implode(',', $airbuttons);
} else {
$context['settings']['redactor']['airbuttons'] = '';
}
$allowedTags = $context['settings']['redactor']['allowedtags'];
if(isset($allowedTags)) {
$context['settings']['redactor']['allowedtags'] = implode(',', $allowedTags);
} else {
$context['settings']['redactor']['allowedtags'] = '';
}
}
}