This repository was archived by the owner on Mar 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtadv_admin.php
516 lines (420 loc) · 17.5 KB
/
tadv_admin.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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
<?php
if ( ! defined( 'TADV_ADMIN_PAGE' ) ) {
exit;
}
// TODO
if ( ! current_user_can( 'manage_options' ) ) {
wp_die('Access denied');
}
$message = '';
$imgpath = TADV_URL . 'images/';
$tadv_options_updated = false;
$settings = $admin_settings = array();
if ( isset( $_POST['tadv-save'] ) ) {
check_admin_referer( 'tadv-save-buttons-order' );
$options_array = $admin_settings_array = $disabled_plugins = $plugins_array = array();
// User settings
for ( $i = 1; $i < 5; $i++ ) {
$tb = 'tb' . $i;
if ( $i > 1 && ! empty( $_POST[$tb] ) && is_array( $_POST[$tb] ) &&
( $wp_adv = array_search( 'wp_adv', $_POST[$tb] ) ) !== false ) {
// Remove the "Toolbar toggle" button from row 2, 3 or 4.
unset( $_POST[$tb][$wp_adv] );
}
$buttons = $this->parse_buttons( $tb );
// Layer plugin buttons??
$buttons = str_replace( 'insertlayer', 'insertlayer,moveforward,movebackward,absolute', $buttons );
$settings['toolbar_' . $i] = $buttons;
}
if ( ! empty( $_POST['advlist'] ) ) {
$options_array[] = 'advlist';
}
if ( ! empty( $_POST['contextmenu'] ) ) {
$options_array[] = 'contextmenu';
}
if ( ! empty( $_POST['advlink'] ) ) {
$options_array[] = 'advlink';
}
if ( ! empty( $_POST['menubar'] ) ) {
$options_array[] = 'menubar';
$plugins_array = array( 'anchor', 'code', 'insertdatetime', 'nonbreaking', 'print', 'searchreplace',
'table', 'visualblocks', 'visualchars' );
}
// Admin settings, TODO
if ( ! empty( $_POST['importcss'] ) ) {
$admin_settings_array[] = 'importcss';
}
if ( ! empty( $_POST['no_autop'] ) ) {
$admin_settings_array[] = 'no_autop';
}
if ( ! empty( $_POST['paste_images'] ) ) {
$admin_settings_array[] = 'paste_images';
}
if ( ! empty( $_POST['fontsize_formats'] ) ) {
$admin_settings_array[] = 'fontsize_formats';
}
if ( ! empty( $_POST['editorstyle'] ) ) {
$admin_settings_array[] = 'editorstyle';
}
if ( ! empty( $_POST['disabled_plugins'] ) && is_array( $_POST['disabled_plugins'] ) ) {
foreach( $_POST['disabled_plugins'] as $plugin ) {
if ( in_array( $this->all_plugins, $plugin, true ) ) {
$disabled_plugins[] = $plugin;
}
}
}
// Admin options
$admin_settings['options'] = implode( ',', $admin_settings_array );
$admin_settings['disabled_plugins'] = implode( ',', $disabled_plugins );
$this->admin_settings = $admin_settings;
update_option( 'tadv_admin_settings', $admin_settings );
// User options
// TODO allow editors, authors and contributors some access
$this->settings = $settings;
$this->load_settings();
// Special case
if ( in_array( 'image', $this->used_buttons, true ) ) {
$options_array[] = 'image';
}
$settings['options'] = implode( ',', $options_array );
$this->settings = $settings;
$this->load_settings();
// Merge the submitted plugins buttons
$settings['plugins'] = implode( ',', $this->get_plugins( $plugins_array ) );
$this->settings = $settings;
$this->plugins = $settings['plugins'];
// Save the new settings. TODO: per user
update_option( 'tadv_settings', $settings );
} elseif ( isset( $_POST['tadv-restore-defaults'] ) ) {
check_admin_referer( 'tadv-save-buttons-order' );
// TODO: only for admin || SA
$this->admin_settings = $this->default_admin_settings;
update_option( 'tadv_admin_settings', $this->default_admin_settings );
// TODO: all users that can have settings
$this->settings = $this->default_settings;
update_option( 'tadv_settings', $this->default_settings );
$message = '<div class="updated"><p>' . __('Default settings restored.', 'tinymce-advanced') . '</p></div>';
} elseif ( isset( $_POST['tadv-export-settings'] ) ) {
check_admin_referer( 'tadv-save-buttons-order' );
$this->load_settings();
$output = array( 'settings' => $this->settings );
// TODO: only admin || SA
$output['admin_settings'] = $this->admin_settings;
?>
<div class="wrap">
<h2><?php _e( 'TinyMCE Advanced Settings Export', 'tinymce-advanced' ); ?></h2>
<div class="tadv-import-export">
<p>
<?php _e( 'The settings are exported as a JSON encoded string.', 'tinymce-advanced' ); ?>
<?php _e( 'Please copy the content and save it in a <b>text</b> (.txt) file, using a plain text editor like Notepad.', 'tinymce-advanced' ); ?>
<?php _e( 'It is important that the export is not changed in any way, no spaces, line breaks, etc.', 'tinymce-advanced' ); ?>
</p>
<form action="">
<p><textarea readonly="readonly" id="tadv-export"><?php echo json_encode( $output ); ?></textarea></p>
<p><button type="button" class="button" id="tadv-export-select"><?php _e( 'Select All', 'tinymce-advanced' ); ?></button></p>
</form>
<p><a href=""><?php _e( 'Back to Editor Settings', 'tinymce-advanced' ); ?></a></p>
</div>
</div>
<?php
return;
} elseif ( isset( $_POST['tadv-import-settings'] ) ) {
check_admin_referer( 'tadv-save-buttons-order' );
// TODO: all users
?>
<div class="wrap">
<h2><?php _e( 'TinyMCE Advanced Settings Import', 'tinymce-advanced' ); ?></h2>
<div class="tadv-import-export">
<p><?php _e( 'The settings are imported from a JSON encoded string. Please paste the exported string in the text area below.', 'tinymce-advanced' ); ?></p>
<form action="" method="post">
<p><textarea id="tadv-import" name="tadv-import"></textarea></p>
<p>
<button type="button" class="button" id="tadv-import-verify"><?php _e( 'Verify', 'tinymce-advanced' ); ?></button>
<input type="submit" class="button button-primary alignright" name="tadv-import-submit" value="<?php _e( 'Import', 'tinymce-advanced' ); ?>" />
</p>
<?php wp_nonce_field('tadv-import'); ?>
<p id="tadv-import-error"></p>
</form>
<p><a href=""><?php _e( 'Back to Editor Settings', 'tinymce-advanced' ); ?></a></p>
</div>
</div>
<?php
return;
} elseif ( isset( $_POST['tadv-import-submit'] ) && ! empty( $_POST['tadv-import'] ) && is_string( $_POST['tadv-import'] ) ) {
check_admin_referer( 'tadv-import' );
// TODO: all users
$import = json_decode( trim( wp_unslash( $_POST['tadv-import'] ) ), true );
$settings = $admin_settings = array();
if ( is_array( $import ) ) {
if ( ! empty( $import['settings'] ) ) {
$settings = $this->sanitize_settings( $import['settings'] );
}
// only admin || SA
if ( ! empty( $import['admin_settings'] ) ) {
$admin_settings = $this->sanitize_settings( $import['admin_settings'] );
}
}
if ( empty( $settings ) ) {
$message = '<div class="error"><p>' . __('Importing of settings failed.', 'tinymce-advanced') . '</p></div>';
} else {
// only admin || SA
$this->admin_settings = $admin_settings;
update_option( 'tadv_admin_settings', $admin_settings );
// User options
// TODO: allow editors, authors and contributors some access
$this->settings = $settings;
$this->load_settings();
// Merge the submitted plugins and buttons
if ( ! empty( $settings['plugins'] ) ) {
$settings['plugins'] = implode( ',', $this->get_plugins( explode( ',', $settings['plugins'] ) ) );
}
$this->plugins = $settings['plugins'];
// Save the new settings
update_option( 'tadv_settings', $settings );
}
}
$this->load_settings();
if ( empty( $this->toolbar_1 ) && empty( $this->toolbar_2 ) && empty( $this->toolbar_3 ) && empty( $this->toolbar_4 ) ) {
$message = '<div class="error"><p>' . __( 'ERROR: All toolbars are empty. Default settings loaded.', 'tinymce-advanced' ) . '</p></div>';
$this->admin_settings = $this->default_admin_settings;
$this->settings = $this->default_settings;
$this->load_settings();
}
$used_buttons = array_merge( $this->toolbar_1, $this->toolbar_2, $this->toolbar_3, $this->toolbar_4 );
$all_buttons = $this->get_all_buttons();
?>
<div class="wrap" id="contain">
<h2><?php _e( 'Editor Settings', 'tinymce-advanced' ); ?></h2>
<?php
// TODO admin || SA
$this->warn_if_unsupported();
if ( isset( $_POST['tadv-save'] ) && empty( $message ) ) {
?><div class="updated"><p><?php _e( 'Settings saved.', 'tinymce-advanced' ); ?></p></div><?php
} else {
echo $message;
}
?>
<form id="tadvadmin" method="post" action="">
<p class="tadv-submit">
<input class="button-primary button-large" type="submit" name="tadv-save" value="<?php _e( 'Save Changes', 'tinymce-advanced' ); ?>" />
</p>
<div id="tadvzones">
<p><?php _e( 'New in TinyMCE 4.0/WordPress 3.9 is the editor menu. When it is enabled, most buttons are also available as menu items.', 'tinymce-advanced' ); ?></p>
<p><label>
<input type="checkbox" name="menubar" id="menubar" <?php if ( $this->check_setting( 'menubar' ) ) { echo ' checked="checked"'; } ?>>
<?php _e( 'Enable the editor menu.', 'tinymce-advanced' ); ?>
</label></p>
<div id="tadv-mce-menu" class="mce-container mce-menubar mce-toolbar mce-first mce-stack-layout-item
<?php if ( $this->check_setting( 'menubar' ) ) { echo ' enabled'; } ?>">
<div class="mce-container-body mce-flow-layout">
<div class="mce-widget mce-btn mce-menubtn mce-first mce-flow-layout-item">
<button type="button">
<span class="tadv-translate">File</span>
<i class="mce-caret"></i>
</button>
</div>
<div class="mce-widget mce-btn mce-menubtn mce-flow-layout-item">
<button type="button">
<span class="tadv-translate">Edit</span>
<i class="mce-caret"></i>
</button>
</div>
<div class="mce-widget mce-btn mce-menubtn mce-flow-layout-item">
<button type="button">
<span class="tadv-translate">Insert</span>
<i class="mce-caret"></i>
</button>
</div>
<div class="mce-widget mce-btn mce-menubtn mce-flow-layout-item mce-toolbar-item">
<button type="button">
<span class="tadv-translate">View</span>
<i class="mce-caret"></i>
</button>
</div>
<div class="mce-widget mce-btn mce-menubtn mce-flow-layout-item">
<button type="button">
<span class="tadv-translate">Format</span>
<i class="mce-caret"></i>
</button>
</div>
<div class="mce-widget mce-btn mce-menubtn mce-flow-layout-item">
<button type="button">
<span class="tadv-translate">Table</span>
<i class="mce-caret"></i>
</button>
</div>
<div class="mce-widget mce-btn mce-menubtn mce-last mce-flow-layout-item">
<button type="button">
<span class="tadv-translate">Tools</span>
<i class="mce-caret"></i>
</button>
</div>
</div>
</div>
<?php
$mce_text_buttons = array( 'styleselect', 'formatselect', 'fontselect', 'fontsizeselect' );
for ( $i = 1; $i < 5; $i++ ) {
$toolbar = "toolbar_$i";
?>
<div class="tadvdropzone mce-toolbar">
<ul id="tb<?php echo $i; ?>" class="container">
<?php
foreach( $this->$toolbar as $button ) {
if ( strpos( $button, 'separator' ) !== false || in_array( $button, array( 'moveforward', 'movebackward', 'absolute' ) ) ) {
continue;
}
if ( isset( $all_buttons[$button] ) ) {
$name = $all_buttons[$button];
unset( $all_buttons[$button] );
} else {
// error?..
continue;
}
?><li class="tadvmodule" id="<?php echo $button; ?>">
<?php
if ( in_array( $button, $mce_text_buttons, true ) ) {
?>
<div class="tadvitem mce-widget mce-btn mce-menubtn mce-fixed-width mce-listbox">
<div class="the-button">
<span class="descr"><?php echo $name; ?></span>
<i class="mce-caret"></i>
<input type="hidden" class="tadv-button" name="tb<?php echo $i; ?>[]" value="<?php echo $button; ?>" />
</div>
</div>
<?php
} else {
?>
<div class="tadvitem">
<i class="mce-ico mce-i-<?php echo $button; ?>" title="<?php echo $name; ?>"></i>
<span class="descr"><?php echo $name; ?></span>
<input type="hidden" class="tadv-button" name="tb<?php echo $i; ?>[]" value="<?php echo $button; ?>" />
</div>
<?php
}
?>
</li><?php
}
?>
</ul></div>
<?php
}
?>
</div>
<p><?php _e( 'Drag buttons from the unused buttons below and drop them in the toolbars above, or drag the buttons in the toolbars to rearrange them.', 'tinymce-advanced' ); ?></p>
<div id="unuseddiv">
<h3><?php _e( 'Unused Buttons', 'tinymce-advanced' ); ?></h3>
<ul id="unused" class="container">
<?php
foreach( $all_buttons as $button => $name ) {
if ( strpos( $button, 'separator' ) !== false ) {
continue;
}
?><li class="tadvmodule" id="<?php echo $button; ?>">
<?php
if ( in_array( $button, $mce_text_buttons, true ) ) {
?>
<div class="tadvitem mce-widget mce-btn mce-menubtn mce-fixed-width mce-listbox">
<div class="the-button">
<span class="descr"><?php echo $name; ?></span>
<i class="mce-caret"></i>
<input type="hidden" class="tadv-button" name="tb<?php echo $i; ?>[]" value="<?php echo $button; ?>" />
</div>
</div>
<?php
} else {
?>
<div class="tadvitem">
<i class="mce-ico mce-i-<?php echo $button; ?>" title="<?php echo $name; ?>"></i>
<span class="descr"><?php echo $name; ?></span>
<input type="hidden" class="tadv-button" name="tb<?php echo $i; ?>[]" value="<?php echo $button; ?>" />
</div>
<?php
}
?>
</li><?php
}
?>
</ul>
</div>
<p class="tadv-more-plugins"><?php _e( 'Also enable:', 'tinymce-advanced' ); ?>
<label>
<input type="checkbox" name="advlist" id="advlist" <?php if ( $this->check_setting('advlist') ) echo ' checked="checked"'; ?> />
<?php _e( 'List Style Options', 'tinymce-advanced' ); ?>
</label>
<label>
<input type="checkbox" name="contextmenu" id="contextmenu" <?php if ( $this->check_setting('contextmenu') ) echo ' checked="checked"'; ?> />
<?php _e( 'Context Menu', 'tinymce-advanced' ); ?>
</label>
<label>
<input type="checkbox" name="advlink" id="advlink" <?php if ( $this->check_setting('advlink') ) echo ' checked="checked"'; ?> />
<?php _e( 'Link (replaces the Insert/Edit Link dialog)', 'tinymce-advanced' ); ?>
</label>
</p>
<?php
if ( ! is_multisite() || current_user_can( 'manage_sites' ) ) {
?>
<div class="advanced-options">
<h3><?php _e( 'Advanced Options', 'tinymce-advanced' ); ?></h3>
<?php
if ( ! is_multisite() && ! current_theme_supports( 'editor-style' ) ) {
?>
<div>
<label><input type="checkbox" name="editorstyle" id="editorstyle" <?php if ( $this->check_admin_setting( 'editorstyle' ) ) echo ' checked="checked"'; ?> />
<?php _e( 'Import editor-style.css.', 'tinymce-advanced' ); ?></label>
<p>
<?php _e( 'It seems your theme does not support customised styles for the editor.', 'tinymce-advanced' ); ?>
<?php _e( 'You can create a CSS file named <code>editor-style.css</code> and upload it to your theme\'s directory.', 'tinymce-advanced' ); ?>
<?php _e( 'After that, enable this setting.', 'tinymce-advanced' ); ?>
</p>
</div>
<?php
}
?>
<div>
<label><input type="checkbox" name="importcss" id="importcss" <?php if ( $this->check_admin_setting( 'importcss' ) ) echo ' checked="checked"'; ?> />
<?php _e( 'Load the CSS classes used in editor-style.css and replace the Formats button and sub-menu.', 'tinymce-advanced' ); ?></label>
</div>
<div>
<label><input type="checkbox" name="no_autop" id="no_autop" <?php if ( $this->check_admin_setting( 'no_autop' ) ) echo ' checked="checked"'; ?> />
<?php _e( 'Stop removing the <p> and <br /> tags when saving and show them in the Text editor', 'tinymce-advanced' ); ?></label>
<p>
<?php _e( 'This will make it possible to use more advanced coding in the HTML editor without the back-end filtering affecting it much.', 'tinymce-advanced' ); ?>
<?php _e( 'However it may behave unexpectedly in rare cases, so test it thoroughly before enabling it permanently.', 'tinymce-advanced' ); ?>
<?php _e( 'Line breaks in the HTML editor would still affect the output, in particular do not use empty lines, line breaks inside HTML tags or multiple <br /> tags.', 'tinymce-advanced' ); ?>
</p>
</div>
<div>
<label><input type="checkbox" name="fontsize_formats" id="fontsize_formats" <?php if ( $this->check_admin_setting( 'fontsize_formats' ) ) echo ' checked="checked"'; ?> />
<?php _e( 'Replace font size settings', 'tinymce-advanced' ); ?></label>
<p><?php _e( 'Replaces the size setting available for fonts with: 8px 10px 12px 14px 16px 20px 24px 28px 32px 36px.', 'tinymce-advanced' ); ?></p>
</div>
<div>
<label><input type="checkbox" name="paste_images" id="paste_images" <?php if ( $this->check_admin_setting( 'paste_images' ) ) echo ' checked="checked"'; ?> />
<?php _e( 'Enable pasting of image source', 'tinymce-advanced' ); ?></label>
<p>
<?php _e( 'Works only in Firefox and Safari. These browsers support pasting of images directly in the editor and convert them to base64 encoded text.', 'tinymce-advanced' ); ?>
<?php _e( 'This is not acceptable for larger images like photos or graphics, but may be useful in some cases for very small images like icons, not larger than 2-3KB.', 'tinymce-advanced' ); ?>
<?php _e( 'These images will not be available in the Media Library.', 'tinymce-advanced' ); ?>
</p>
</div>
</div>
<div class="advanced-options">
<h3><?php _e( 'Administration', 'tinymce-advanced' ); ?></h3>
<div>
<input type="submit" class="button" name="tadv-export-settings" value="<?php _e( 'Export Settings', 'tinymce-advanced' ); ?>" />
<input type="submit" class="button" name="tadv-import-settings" value="<?php _e( 'Import Settings', 'tinymce-advanced' ); ?>" />
</div>
</div>
<?php
}
?>
<p class="tadv-submit">
<?php wp_nonce_field( 'tadv-save-buttons-order' ); ?>
<input class="button" type="submit" name="tadv-restore-defaults" value="<?php _e( 'Restore Default Settings', 'tinymce-advanced' ); ?>" />
<input class="button-primary button-large" type="submit" name="tadv-save" value="<?php _e( 'Save Changes', 'tinymce-advanced' ); ?>" />
</p>
</form>
<div id="wp-adv-error-message" class="tadv-error">
<?php _e( 'The [Toolbar toggle] button shows or hides the second, third, and forth button rows. It will only work when it is in the first row and there are buttons in the second row.', 'tinymce-advanced' ); ?>
</div>
</div><!-- /wrap -->