PluginProbe ʕ •ᴥ•ʔ
Advanced Editor Tools / 4.0.2
Advanced Editor Tools v4.0.2
trunk 1.0 1.0.1 2.0 2.2 3.0 3.0.1 3.1 3.2 3.2.4 3.2.7 3.3.9 3.3.9.1 3.3.9.2 3.4.2 3.4.2.1 3.4.5 3.4.5.1 3.4.9 3.5.8 3.5.9 3.5.9.1 4.0 4.0.1 4.0.2 4.1 4.1.1 4.1.7 4.1.9 4.2.3 4.2.3.1 4.2.5 4.2.8 4.3.10 4.3.10.1 4.3.8 4.4.1 4.4.3 4.5.6 4.6.3 4.6.7 4.7.11 4.8.0 4.8.1 4.8.2 5.0.0 5.0.1 5.1.0 5.2 5.2.1 5.3 5.4.0 5.5.0 5.5.1 5.6.0 5.9.0 5.9.1 5.9.2
tinymce-advanced / tinymce-advanced.php
tinymce-advanced Last commit date
css 12 years ago images 12 years ago js 12 years ago mce 12 years ago readme.txt 12 years ago screenshot-1.png 12 years ago screenshot-2.png 12 years ago tadv_admin.php 12 years ago tinymce-advanced.php 12 years ago uninstall.php 12 years ago
tinymce-advanced.php
517 lines
1 <?php
2 /*
3 Plugin Name: TinyMCE Advanced
4 Plugin URI: http://www.laptoptips.ca/projects/tinymce-advanced/
5 Description: Enables advanced features and plugins in TinyMCE, the visual editor in WordPress.
6 Version: 4.0.2
7 Author: Andrew Ozz
8 Author URI: http://www.laptoptips.ca/
9
10 Released under the GPL version 2.0, http://www.gnu.org/licenses/gpl-2.0.html
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License version 2.0 for more details.
16 */
17
18 if ( ! class_exists('Tinymce_Advanced') ) :
19
20 class Tinymce_Advanced {
21
22 private $settings;
23 private $admin_settings;
24 private $admin_options;
25
26 private $plugins;
27 private $options;
28 private $toolbar_1;
29 private $toolbar_2;
30 private $toolbar_3;
31 private $toolbar_4;
32 private $used_buttons = array();
33 private $all_buttons = array();
34 private $buttons_filter = array();
35 private $all_plugins = array( 'advlist','anchor','code','contextmenu','emoticons','importcss','insertdatetime','nonbreaking','print','searchreplace','table','visualblocks','visualchars','link' );
36
37 private $default_settings = array(
38 'options' => 'menubar,advlist',
39 'toolbar_1' => 'bold,italic,blockquote,bullist,numlist,alignleft,aligncenter,alignright,link,unlink,table,fullscreen,undo,redo,wp_adv',
40 'toolbar_2' => 'formatselect,alignjustify,strikethrough,outdent,indent,pastetext,removeformat,charmap,wp_more,emoticons,forecolor,wp_help',
41 'toolbar_3' => '',
42 'toolbar_4' => '',
43 'plugins' => 'anchor,code,insertdatetime,nonbreaking,print,searchreplace,table,visualblocks,visualchars,emoticons,advlist',
44 );
45
46 private $default_admin_settings = array( 'options' => array() );
47
48 function __construct() {
49 add_action( 'plugins_loaded', array( &$this, 'set_paths' ), 50 );
50
51 if ( is_admin() ) {
52 add_action( 'admin_menu', array( &$this, 'menu' ) );
53 add_action( 'admin_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
54 }
55
56 // Don't load on non-supported WP versions
57 if ( ! $this->check_minimum_supported_version() ) {
58 return;
59 }
60
61 add_filter( 'mce_buttons', array( &$this, 'mce_buttons_1' ), 999, 2 );
62 add_filter( 'mce_buttons_2', array( &$this, 'mce_buttons_2' ), 999 );
63 add_filter( 'mce_buttons_3', array( &$this, 'mce_buttons_3' ), 999 );
64 add_filter( 'mce_buttons_4', array( &$this, 'mce_buttons_4' ), 999 );
65
66 add_filter( 'tiny_mce_before_init', array( &$this, 'mce_options' ) );
67 add_filter( 'htmledit_pre', array( &$this, 'htmledit' ), 999 );
68 add_filter( 'mce_external_plugins', array( &$this, 'mce_external_plugins' ), 999 );
69 add_filter( 'tiny_mce_plugins', array( &$this, 'tiny_mce_plugins' ), 999 );
70 }
71
72 // When using a plugin that changes the paths dinamically, set these earlier than 'plugins_loaded' 50.
73 function set_paths() {
74 if ( ! defined( 'TADV_URL' ) )
75 define( 'TADV_URL', plugin_dir_url( __FILE__ ) );
76
77 if ( ! defined( 'TADV_PATH' ) )
78 define( 'TADV_PATH', plugin_dir_path( __FILE__ ) );
79 }
80
81 private function remove_settings( $all = false ) {
82 if ( $all ) {
83 delete_option( 'tadv_settings' );
84 delete_option( 'tadv_admin_settings' );
85 delete_option( 'tadv_version' );
86 }
87
88 // Delete old options
89 delete_option('tadv_options');
90 delete_option('tadv_toolbars');
91 delete_option('tadv_plugins');
92 delete_option('tadv_btns1');
93 delete_option('tadv_btns2');
94 delete_option('tadv_btns3');
95 delete_option('tadv_btns4');
96 delete_option('tadv_allbtns');
97 }
98
99 function enqueue_scripts( $page ) {
100 if ( 'settings_page_tinymce-advanced' == $page ) {
101 wp_enqueue_script( 'tadv-js', TADV_URL . 'js/tadv.js', array( 'jquery-ui-sortable' ), '4.0', true );
102 wp_enqueue_style( 'tadv-mce-skin', includes_url( 'js/tinymce/skins/lightgray/skin.min.css' ), array(), '4.0' );
103 wp_enqueue_style( 'tadv-css', TADV_URL . 'css/tadv-styles.css', array( 'editor-buttons' ), '4.0' );
104 }
105 }
106
107 function load_settings() {
108 if ( empty( $_POST ) ) {
109 $this->check_plugin_version();
110 }
111
112 if ( empty( $this->settings ) ) {
113 $this->admin_settings = get_option( 'tadv_admin_settings', false );
114 $this->settings = get_option( 'tadv_settings', false );
115 }
116
117 // load defaults if the options don't exist...
118 if ( $this->admin_settings === false )
119 $this->admin_settings = $this->default_admin_settings;
120
121 $this->admin_options = ! empty( $this->admin_settings['options'] ) ? explode( ',', $this->admin_settings['options'] ) : array();
122
123 if ( $this->settings === false )
124 $this->settings = $this->default_settings;
125
126 $this->options = ! empty( $this->settings['options'] ) ? explode( ',', $this->settings['options'] ) : array();
127 $this->plugins = ! empty( $this->settings['plugins'] ) ? explode( ',', $this->settings['plugins'] ) : array();
128 $this->toolbar_1 = ! empty( $this->settings['toolbar_1'] ) ? explode( ',', $this->settings['toolbar_1'] ) : array();
129 $this->toolbar_2 = ! empty( $this->settings['toolbar_2'] ) ? explode( ',', $this->settings['toolbar_2'] ) : array();
130 $this->toolbar_3 = ! empty( $this->settings['toolbar_3'] ) ? explode( ',', $this->settings['toolbar_3'] ) : array();
131 $this->toolbar_4 = ! empty( $this->settings['toolbar_4'] ) ? explode( ',', $this->settings['toolbar_4'] ) : array();
132
133 $this->used_buttons = array_merge( $this->toolbar_1, $this->toolbar_2, $this->toolbar_3, $this->toolbar_4 );
134 $this->get_all_buttons();
135 }
136
137 // Min version 3.9-RC1
138 private function check_minimum_supported_version() {
139 return ( isset( $GLOBALS['wp_db_version'] ) && $GLOBALS['wp_db_version'] > 27000 );
140 }
141
142 private function check_plugin_version() {
143 $version = get_option( 'tadv_version', 0 );
144
145 if ( ! $version || $version < 4000 ) {
146 // First install or upgrade to TinyMCE 4.0
147 $this->settings = $this->default_settings;
148 $this->admin_settings = $this->default_admin_settings;
149
150 update_option( 'tadv_settings', $this->settings );
151 update_option( 'tadv_admin_settings', $this->admin_settings );
152 update_option( 'tadv_version', 4000 );
153 }
154
155 if ( $version < 4000 ) {
156 // Upgrade to TinyMCE 4.0, clean options
157 $this->remove_settings();
158 }
159 }
160
161 function get_all_buttons() {
162 if ( ! empty( $this->all_buttons ) )
163 return $this->all_buttons;
164
165 $buttons = array(
166 // Core
167 'bold' => 'Bold',
168 'italic' => 'Italic',
169 'underline' => 'Underline',
170 'strikethrough' => 'Strikethrough',
171 'alignleft' => 'Align Left',
172 'aligncenter' => 'Align Center',
173 'alignright' => 'Align Right',
174 'alignjustify' => 'Justify',
175 'styleselect' => '<!--styleselect-->',
176 'formatselect' => '<!--formatselect-->',
177 'fontselect' => '<!--fontselect-->',
178 'fontsizeselect' => '<!--fontsizeselect-->',
179 'cut' => 'Cut',
180 'copy' => 'Copy',
181 'paste' => 'Paste',
182 'bullist' => 'Bullet List',
183 'numlist' => 'Numbered List',
184 'outdent' => 'Outdent',
185 'indent' => 'Indent',
186 'blockquote' => 'Quote',
187 'undo' => 'Undo',
188 'redo' => 'Redo',
189 'removeformat' => 'Remove Formatting',
190 'subscript' => 'Subscript',
191 'superscript' => 'Superscript',
192
193 // From plugins
194 'hr' => 'Horizontal Rule',
195 'link' => 'Link',
196 'unlink' => 'Remove Link',
197 'image' => 'Edit Image',
198 'charmap' => 'Character Map',
199 'pastetext' => 'Paste as Text',
200 'print' => 'Print',
201 'anchor' => 'Insert Anchor',
202 'searchreplace' => 'Search/Replace',
203 'visualblocks' => 'Visual Blocks',
204 // 'visualchars' => 'Hidden Chars',
205 'code' => 'HTML code',
206 'fullscreen' => 'Full Screen',
207 'insertdatetime' => 'Insert Date/Time',
208 'media' => 'Insert Media',
209 'nonbreaking' => 'Non-Break Space',
210 'table' => 'Table',
211 'ltr' => 'Left to Right',
212 'rtl' => 'Right to Left',
213 'emoticons' => 'Emoticons',
214 'forecolor' => 'Text Color',
215 'backcolor' => 'Text Background',
216
217 // Layer plugin ?
218 // 'insertlayer' => 'Layer',
219
220 // WP
221 'wp_adv' => 'Toolbar toggle',
222 'wp_help' => 'Help',
223 'wp_more' => 'More Tag',
224 'wp_page' => 'Page Break',
225 );
226
227 if ( function_exists('moxiecode_plugins_url') ) {
228 if ( moxiecode_plugins_url('imagemanager') )
229 $buttons['insertimage'] = 'MC Image Manager';
230
231 if ( moxiecode_plugins_url('filemanager') )
232 $buttons['insertfile'] = 'MC File Manager';
233 }
234
235 // add/remove allowed buttons
236 $buttons = apply_filters( 'tadv_allowed_buttons', $buttons );
237
238 $this->all_buttons = $buttons;
239 $this->buttons_filter = array_keys( $buttons );
240 return $buttons;
241 }
242
243 function get_plugins( $plugins = array() ) {
244
245 if ( ! is_array( $this->used_buttons ) ) {
246 $this->load_settings();
247 }
248
249 if ( in_array( 'anchor', $this->used_buttons, true ) )
250 $plugins[] = 'anchor';
251
252 if ( in_array( 'visualchars', $this->used_buttons, true ) )
253 $plugins[] = 'visualchars';
254
255 if ( in_array( 'visualblocks', $this->used_buttons, true ) )
256 $plugins[] = 'visualblocks';
257
258 if ( in_array( 'nonbreaking', $this->used_buttons, true ) )
259 $plugins[] = 'nonbreaking';
260
261 if ( in_array( 'emoticons', $this->used_buttons, true ) )
262 $plugins[] = 'emoticons';
263
264 if ( in_array( 'insertdatetime', $this->used_buttons, true ) )
265 $plugins[] = 'insertdatetime';
266
267 if ( in_array( 'table', $this->used_buttons, true ) )
268 $plugins[] = 'table';
269
270 if ( in_array( 'print', $this->used_buttons, true ) )
271 $plugins[] = 'print';
272
273 if ( in_array( 'searchreplace', $this->used_buttons, true ) )
274 $plugins[] = 'searchreplace';
275
276 if ( in_array( 'insertlayer', $this->used_buttons, true ) )
277 $plugins[] = 'layer';
278
279 // From options
280 if ( $this->check_setting( 'advlist' ) )
281 $plugins[] = 'advlist';
282
283 if ( $this->check_setting( 'advlink' ) )
284 $plugins[] = 'link';
285
286 if ( $this->check_admin_setting( 'importcss' ) )
287 $plugins[] = 'importcss';
288
289 if ( $this->check_setting( 'contextmenu' ) )
290 $plugins[] = 'contextmenu';
291
292 // add/remove used plugins
293 $plugins = apply_filters( 'tadv_used_plugins', $plugins, $this->used_buttons );
294
295 return array_unique( $plugins );
296 }
297
298 private function check_setting( $setting, $admin = false ) {
299 if ( ! is_array( $this->options ) ) {
300 $this->load_settings();
301 }
302
303 $array = $admin ? $this->admin_options : $this->options;
304 return in_array( $setting, $array, true );
305 }
306
307 private function check_admin_setting( $setting ) {
308 return $this->check_setting( $setting, true );
309 }
310
311 function mce_buttons_1( $original, $editor_id ) {
312 if ( ! is_array( $this->options ) ) {
313 $this->load_settings();
314 }
315
316 $buttons_1 = $this->toolbar_1;
317
318 if ( 'content' === $editor_id && ! in_array( 'wp_adv', $buttons_1, true ) ) {
319 add_action( 'wp_enqueue_editor', array( &$this, 'wp_enqueue_editor' ) );
320 }
321
322 if ( is_array( $original ) && ! empty( $original ) ) {
323 $original = array_diff( $original, $this->buttons_filter );
324 $buttons_1 = array_merge( $buttons_1, $original );
325 }
326
327 return $buttons_1;
328 }
329
330 function mce_buttons_2( $original ) {
331 if ( ! is_array( $this->options ) ) {
332 $this->load_settings();
333 }
334
335 $buttons_2 = $this->toolbar_2;
336
337 if ( is_array( $original ) && ! empty( $original ) ) {
338 $original = array_diff( $original, $this->buttons_filter );
339 $buttons_2 = array_merge( $buttons_2, $original );
340 }
341
342 return $buttons_2;
343 }
344
345 function mce_buttons_3( $original ) {
346 if ( ! is_array( $this->options ) ) {
347 $this->load_settings();
348 }
349
350 $buttons_3 = $this->toolbar_3;
351
352 if ( is_array( $original ) && ! empty( $original ) ) {
353 $original = array_diff( $original, $this->buttons_filter );
354 $buttons_3 = array_merge( $buttons_3, $original );
355 }
356
357 return $buttons_3;
358 }
359
360 function mce_buttons_4( $original ) {
361 if ( ! is_array( $this->options ) ) {
362 $this->load_settings();
363 }
364
365 $buttons_4 = $this->toolbar_4;
366
367 if ( is_array( $original ) && ! empty( $original ) ) {
368 $original = array_diff( $original, $this->buttons_filter );
369 $buttons_4 = array_merge( $buttons_4, $original );
370 }
371
372 return $buttons_4;
373 }
374
375 function mce_options( $init ) {
376 if ( $this->check_admin_setting( 'no_autop' ) ) {
377 $init['wpautop'] = false;
378 $init['indent'] = true;
379 $init['tadv_noautop'] = true;
380 }
381
382 if ( $this->check_setting('menubar') ) {
383 $init['menubar'] = true;
384 }
385
386 if ( $this->check_setting('image') ) {
387 $init['image_advtab'] = true;
388 }
389
390 if ( $this->check_setting( 'advlink' ) ) {
391 $init['rel_list'] = '[{text: "None", value: ""}, {text: "Nofollow", value: "nofollow"}]';
392 }
393
394 if ( ! in_array( 'wp_adv', $this->toolbar_1, true ) ) {
395 $init['wordpress_adv_hidden'] = false;
396 }
397
398 if ( $this->check_admin_setting( 'importcss' ) ) {
399 // $init['importcss_selector_filter'] = 'function(sel){return /^\.[a-z0-9]+$/i.test(sel);}';
400 $init['importcss_file_filter'] = 'editor-style.css';
401 }
402
403 return $init;
404 }
405
406 function htmledit( $c ) {
407 if ( $this->check_admin_setting( 'no_autop' ) ) {
408 $c = str_replace( array('&amp;', '&lt;', '&gt;'), array('&', '<', '>'), $c );
409 $c = wpautop( $c );
410 $c = preg_replace( '/^<p>(https?:\/\/[^<> "]+?)<\/p>$/im', '$1', $c );
411 $c = htmlspecialchars( $c, ENT_NOQUOTES, get_option( 'blog_charset' ) );
412 }
413 return $c;
414 }
415
416 function mce_external_plugins( $mce_plugins ) {
417 // import user created editor-style.css
418 if ( $this->check_admin_setting( 'editorstyle' ) ) {
419 add_editor_style();
420 }
421
422 if ( ! is_array( $this->plugins ) ) {
423 $this->plugins = array();
424 }
425
426 if ( $this->check_admin_setting( 'no_autop' ) || in_array( 'table', $this->plugins, true ) ) {
427 $this->plugins[] = 'wptadv';
428 }
429
430 $plugpath = TADV_URL . 'mce/';
431 $mce_plugins = (array) $mce_plugins;
432 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
433
434 foreach ( $this->plugins as $plugin ) {
435 $mce_plugins["$plugin"] = $plugpath . $plugin . "/plugin{$suffix}.js";
436 }
437
438 return $mce_plugins;
439 }
440
441 function tiny_mce_plugins( $plugins ) {
442 // This calls load_settings()
443 if ( $this->check_setting('image') && ! in_array( 'image', $plugins, true ) ) {
444 $plugins[] = 'image';
445 }
446
447 if ( ( in_array( 'rtl', $this->used_buttons, true ) || in_array( 'ltr', $this->used_buttons, true ) ) &&
448 ! in_array( 'directionality', (array) $plugins, true ) ) {
449
450 $plugins[] = 'directionality';
451 }
452
453 return $plugins;
454 }
455
456 function wp_enqueue_editor( $array ) {
457 if ( ! empty( $array['tinymce'] ) ) {
458 ?>
459 <script>if ( typeof setUserSetting !== 'undefined' ) setUserSetting( 'hidetb', '1' );</script>
460 <?php
461 }
462 }
463
464 private function parse_buttons( $toolbar_id = false, $buttons = false ) {
465 if ( $toolbar_id && ! $buttons && ! empty( $_POST[$toolbar_id] ) )
466 $buttons = $_POST[$toolbar_id];
467
468 if ( is_array( $buttons ) ) {
469 $_buttons = array_map( array( @$this, 'filter_name' ), $buttons );
470 return implode( ',', array_filter( $_buttons ) );
471 }
472
473 return '';
474 }
475
476 private function filter_name( $str ) {
477 if ( empty( $str ) || ! is_string( $str ) )
478 return '';
479 // Button names
480 return preg_replace( '/[^a-z0-9_]/i', '', $str );
481 }
482
483 private function sanitize_settings( $settings ) {
484 $_settings = array();
485
486 if ( ! is_array( $settings ) ) {
487 return $_settings;
488 }
489
490 foreach( $settings as $name => $value ) {
491 $name = preg_replace( '/[^a-z0-9_]+/', '', $name );
492
493 if ( strpos( $name, 'toolbar_' ) === 0 ) {
494 $_settings[$name] = $this->parse_buttons( false, explode( ',', $value ) );
495 } else if ( 'options' === $name || 'plugins' === $name || 'disabled_plugins' === $name ) {
496 $_settings[$name] = preg_replace( '/[^a-z0-9_,]+/', '', $value );
497 }
498 }
499
500 return $_settings;
501 }
502
503 function settings_page() {
504 if ( ! defined( 'TADV_ADMIN_PAGE' ) )
505 define( 'TADV_ADMIN_PAGE', true );
506
507 include_once( TADV_PATH . 'tadv_admin.php' );
508 }
509
510 function menu() {
511 add_options_page( 'TinyMCE Advanced', 'TinyMCE Advanced', 'manage_options', 'tinymce-advanced', array( &$this, 'settings_page' ) );
512 }
513 }
514
515 new Tinymce_Advanced;
516 endif;
517