Tinymce_Advanced

The TinyMCE Advanced Tinymce Advanced class.

Defined (1)

The class is defined in the following location(s).

/tinymce-advanced.php  
  1. class Tinymce_Advanced { 
  2.  
  3. private $required_version = '4.7-beta'; 
  4. private $user_settings; 
  5. private $admin_settings; 
  6. private $admin_options; 
  7. private $editor_id; 
  8. private $disabled_for_editor = false; 
  9.  
  10. private $plugins; 
  11. private $options; 
  12. private $toolbar_1; 
  13. private $toolbar_2; 
  14. private $toolbar_3; 
  15. private $toolbar_4; 
  16. private $used_buttons = array(); 
  17. private $all_buttons = array(); 
  18. private $buttons_filter = array(); 
  19. private $fontsize_formats = '8px 10px 12px 14px 16px 20px 24px 28px 32px 36px 48px 60px 72px 96px'; 
  20.  
  21.  
  22. private function get_default_user_settings() { 
  23. return array( 
  24. 'options' => 'menubar, advlist',  
  25. 'toolbar_1' => 'formatselect, bold, italic, blockquote, bullist, numlist, alignleft, aligncenter, alignright, link, unlink, undo, redo',  
  26. 'toolbar_2' => 'fontselect, fontsizeselect, outdent, indent, pastetext, removeformat, charmap, wp_more, forecolor, table, wp_help',  
  27. 'toolbar_3' => '',  
  28. 'toolbar_4' => '',  
  29. 'plugins' => 'anchor, code, insertdatetime, nonbreaking, print, searchreplace, table, visualblocks, visualchars, advlist, wptadv',  
  30. ); 
  31.  
  32. private function get_default_admin_settings() { 
  33. return array( 
  34. 'options' => array(),  
  35. ); 
  36.  
  37. private function get_all_plugins() { 
  38. return array( 
  39. 'advlist',  
  40. 'anchor',  
  41. 'code',  
  42. 'contextmenu',  
  43. 'emoticons',  
  44. 'importcss',  
  45. 'insertdatetime',  
  46. 'link',  
  47. 'nonbreaking',  
  48. 'print',  
  49. 'searchreplace',  
  50. 'table',  
  51. 'visualblocks',  
  52. 'visualchars',  
  53. 'wptadv',  
  54. ); 
  55.  
  56. private function get_all_user_options() { 
  57. return array( 
  58. 'advlist',  
  59. 'advlink',  
  60. 'contextmenu',  
  61. 'menubar',  
  62. 'fontsize_formats',  
  63. ); 
  64.  
  65. private function get_all_admin_options() { 
  66. return array( 
  67. 'importcss',  
  68. 'no_autop',  
  69. 'paste_images',  
  70. ); 
  71.  
  72. private function get_editor_locations() { 
  73. return array( 
  74. 'edit_post_screen',  
  75. 'rest_of_wpadmin',  
  76. 'on_front_end',  
  77. ); 
  78.  
  79. public function __construct() { 
  80. if ( ! defined('ABSPATH') ) { 
  81. return; 
  82.  
  83. register_activation_hook( __FILE__, array( $this, 'check_plugin_version' ) ); 
  84.  
  85. add_action( 'plugins_loaded', array( $this, 'set_paths' ), 50 ); 
  86.  
  87. if ( is_admin() ) { 
  88. add_action( 'admin_menu', array( $this, 'add_menu' ) ); 
  89. add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); 
  90. add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) ); 
  91. add_filter( 'plugin_action_links', array( $this, 'add_settings_link' ), 10, 2 ); 
  92. add_action( 'before_wp_tiny_mce', array( $this, 'show_version_warning' ) ); 
  93.  
  94. add_filter( 'wp_editor_settings', array( $this, 'disable_for_editor' ), 10, 2 ); 
  95.  
  96. add_filter( 'mce_buttons', array( $this, 'mce_buttons_1' ), 999, 2 ); 
  97. add_filter( 'mce_buttons_2', array( $this, 'mce_buttons_2' ), 999 ); 
  98. add_filter( 'mce_buttons_3', array( $this, 'mce_buttons_3' ), 999 ); 
  99. add_filter( 'mce_buttons_4', array( $this, 'mce_buttons_4' ), 999 ); 
  100.  
  101. add_filter( 'tiny_mce_before_init', array( $this, 'mce_options' ) ); 
  102. add_filter( 'mce_external_plugins', array( $this, 'mce_external_plugins' ), 999 ); 
  103. add_filter( 'tiny_mce_plugins', array( $this, 'tiny_mce_plugins' ), 999 ); 
  104. add_action( 'after_wp_tiny_mce', array( $this, 'after_wp_tiny_mce' ) ); 
  105.  
  106. public function disable_for_editor( $settings, $editor_id ) { 
  107. static $editor_style_added = false; 
  108.  
  109. if ( empty( $this->admin_settings ) ) { 
  110. $this->load_settings(); 
  111.  
  112. $this->disabled_for_editor = false; 
  113. $this->editor_id = $editor_id; 
  114.  
  115. if ( ! empty( $this->admin_settings['disabled_editors'] ) ) { 
  116. $disabled_editors = explode( ', ', $this->admin_settings['disabled_editors'] ); 
  117. $current_screen = isset( $GLOBALS['current_screen'] ) ? $GLOBALS['current_screen'] : new stdClass; 
  118.  
  119. if ( is_admin() ) { 
  120. if ( $editor_id === 'content' && ( $current_screen->id === 'post' || $current_screen->id === 'page' ) ) { 
  121. if ( in_array( 'edit_post_screen', $disabled_editors, true ) ) { 
  122. $this->disabled_for_editor = true; 
  123. } elseif ( in_array( 'rest_of_wpadmin', $disabled_editors, true ) ) { 
  124. $this->disabled_for_editor = true; 
  125. } elseif ( in_array( 'on_front_end', $disabled_editors, true ) ) { 
  126. $this->disabled_for_editor = true; 
  127.  
  128. if ( ! $this->disabled_for_editor && ! $editor_style_added ) { 
  129. if ( $this->check_admin_setting( 'importcss' ) && $this->has_editor_style() !== 'present' ) { 
  130. add_editor_style(); 
  131.  
  132. $editor_style_added = true; 
  133.  
  134. return $settings; 
  135.  
  136. private function is_disabled() { 
  137. return $this->disabled_for_editor; 
  138.  
  139. private function has_editor_style() { 
  140. if ( ! current_theme_supports( 'editor-style' ) ) { 
  141. return 'not-supporetd'; 
  142.  
  143. $editor_stylesheets = get_editor_stylesheets(); 
  144.  
  145. if ( is_array( $editor_stylesheets ) ) { 
  146. foreach ( $editor_stylesheets as $url ) { 
  147. if ( strpos( $url, 'editor-style.css' ) !== false ) { 
  148. return 'present'; 
  149.  
  150. return 'not-present'; 
  151.  
  152. // When using a plugin that changes the paths dinamically, set these earlier than 'plugins_loaded' 50. 
  153. public function set_paths() { 
  154. if ( ! defined( 'TADV_URL' ) ) 
  155. define( 'TADV_URL', plugin_dir_url( __FILE__ ) ); 
  156.  
  157. if ( ! defined( 'TADV_PATH' ) ) 
  158. define( 'TADV_PATH', plugin_dir_path( __FILE__ ) ); 
  159.  
  160. public function load_textdomain() { 
  161. load_plugin_textdomain( 'tinymce-advanced', false, 'tinymce-advanced/langs' ); 
  162.  
  163. public function enqueue_scripts( $page ) { 
  164. if ( 'settings_page_tinymce-advanced' == $page ) { 
  165. wp_enqueue_script( 'tadv-js', TADV_URL . 'js/tadv.js', array( 'jquery-ui-sortable' ), '4.0', true ); 
  166. wp_enqueue_style( 'tadv-mce-skin', includes_url( 'js/tinymce/skins/lightgray/skin.min.css' ), array(), '4.0' ); 
  167. wp_enqueue_style( 'tadv-css', TADV_URL . 'css/tadv-styles.css', array( 'editor-buttons' ), '4.0' ); 
  168.  
  169. add_action( 'admin_footer', array( $this, 'load_mce_translation' ) ); 
  170.  
  171. public function load_mce_translation() { 
  172. if ( ! class_exists( '_WP_Editors' ) ) { 
  173. require( ABSPATH . WPINC . '/class-wp-editor.php' ); 
  174.  
  175. ?> 
  176. <script>var tadvTranslation = <?php echo _WP_Editors::wp_mce_translation( '', true ); ?>;</script> 
  177. <?php 
  178.  
  179. public function load_settings() { 
  180. if ( empty( $this->admin_settings ) ) { 
  181. $this->admin_settings = get_option( 'tadv_admin_settings', false ); 
  182.  
  183. if ( empty( $this->user_settings ) ) { 
  184. $this->user_settings = get_option( 'tadv_settings', false ); 
  185.  
  186. // load defaults if the options don't exist... 
  187. if ( $this->admin_settings === false ) { 
  188. $this->admin_settings = $this->get_default_admin_settings(); 
  189.  
  190. $this->admin_options = ! empty( $this->admin_settings['options'] ) ? explode( ', ', $this->admin_settings['options'] ) : array(); 
  191.  
  192. if ( $this->user_settings === false ) { 
  193. $this->user_settings = $this->get_default_user_settings(); 
  194.  
  195. $this->options = ! empty( $this->user_settings['options'] ) ? explode( ', ', $this->user_settings['options'] ) : array(); 
  196. $this->plugins = ! empty( $this->user_settings['plugins'] ) ? explode( ', ', $this->user_settings['plugins'] ) : array(); 
  197. $this->toolbar_1 = ! empty( $this->user_settings['toolbar_1'] ) ? explode( ', ', $this->user_settings['toolbar_1'] ) : array(); 
  198. $this->toolbar_2 = ! empty( $this->user_settings['toolbar_2'] ) ? explode( ', ', $this->user_settings['toolbar_2'] ) : array(); 
  199. $this->toolbar_3 = ! empty( $this->user_settings['toolbar_3'] ) ? explode( ', ', $this->user_settings['toolbar_3'] ) : array(); 
  200. $this->toolbar_4 = ! empty( $this->user_settings['toolbar_4'] ) ? explode( ', ', $this->user_settings['toolbar_4'] ) : array(); 
  201.  
  202. $this->used_buttons = array_merge( $this->toolbar_1, $this->toolbar_2, $this->toolbar_3, $this->toolbar_4 ); 
  203. $this->get_all_buttons(); 
  204.  
  205. public function show_version_warning() { 
  206. if ( is_admin() && current_user_can( 'update_plugins' ) && get_current_screen()->base === 'post' ) { 
  207. $this->warn_if_unsupported(); 
  208.  
  209. public function warn_if_unsupported() { 
  210. if ( ! $this->check_minimum_supported_version() ) { 
  211. $wp_ver = ! empty( $GLOBALS['wp_version'] ) ? $GLOBALS['wp_version'] : '(undefined)'; 
  212.  
  213. ?> 
  214. <div class="error notice is-dismissible"><p> 
  215. <?php 
  216.  
  217. printf( __( 'TinyMCE Advanced requires WordPress version %1$s or newer. It appears that you are running %2$s. This can make the editor unstable.', 'tinymce-advanced' ),  
  218. $this->required_version,  
  219. esc_html( $wp_ver ) 
  220. ); 
  221.  
  222. echo '<br>'; 
  223.  
  224. printf( __( 'Please upgrade your WordPress installation or download an <a href="%s">older version of the plugin</a>.', 'tinymce-advanced' ),  
  225. 'https://wordpress.org/plugins/tinymce-advanced/download/' 
  226. ); 
  227.  
  228. ?> 
  229. </p></div> 
  230. <?php 
  231.  
  232. // Min version 
  233. private function check_minimum_supported_version() { 
  234. include( ABSPATH . WPINC . '/version.php' ); // get an unmodified $wp_version 
  235. $wp_version = str_replace( '-src', '', $wp_version ); 
  236.  
  237. return ( version_compare( $wp_version, $this->required_version, '>=' ) ); 
  238.  
  239. public function check_plugin_version() { 
  240. $version = get_option( 'tadv_version', 0 ); 
  241.  
  242. if ( ! $version || $version < 4000 ) { 
  243. // First install or upgrade to TinyMCE 4.0 
  244. $this->user_settings = $this->get_default_user_settings(); 
  245. $this->admin_settings = $this->get_default_admin_settings(); 
  246.  
  247. update_option( 'tadv_settings', $this->user_settings ); 
  248. update_option( 'tadv_admin_settings', $this->admin_settings ); 
  249. update_option( 'tadv_version', 4000 ); 
  250.  
  251. if ( $version < 4000 ) { 
  252. // Upgrade to TinyMCE 4.0, clean options 
  253. delete_option('tadv_options'); 
  254. delete_option('tadv_toolbars'); 
  255. delete_option('tadv_plugins'); 
  256. delete_option('tadv_btns1'); 
  257. delete_option('tadv_btns2'); 
  258. delete_option('tadv_btns3'); 
  259. delete_option('tadv_btns4'); 
  260. delete_option('tadv_allbtns'); 
  261.  
  262. public function get_all_buttons() { 
  263. if ( ! empty( $this->all_buttons ) ) 
  264. return $this->all_buttons; 
  265.  
  266. $buttons = array( 
  267. // Core 
  268. 'bold' => 'Bold',  
  269. 'italic' => 'Italic',  
  270. 'underline' => 'Underline',  
  271. 'strikethrough' => 'Strikethrough',  
  272. 'alignleft' => 'Align left',  
  273. 'aligncenter' => 'Align center',  
  274. 'alignright' => 'Align right',  
  275. 'alignjustify' => 'Justify',  
  276. 'styleselect' => 'Formats',  
  277. 'formatselect' => 'Paragraph',  
  278. 'fontselect' => 'Font Family',  
  279. 'fontsizeselect' => 'Font Sizes',  
  280. 'cut' => 'Cut',  
  281. 'copy' => 'Copy',  
  282. 'paste' => 'Paste',  
  283. 'bullist' => 'Bulleted list',  
  284. 'numlist' => 'Numbered list',  
  285. 'outdent' => 'Decrease indent',  
  286. 'indent' => 'Increase indent',  
  287. 'blockquote' => 'Blockquote',  
  288. 'undo' => 'Undo',  
  289. 'redo' => 'Redo',  
  290. 'removeformat' => 'Clear formatting',  
  291. 'subscript' => 'Subscript',  
  292. 'superscript' => 'Superscript',  
  293.  
  294. // From plugins 
  295. 'hr' => 'Horizontal line',  
  296. 'link' => 'Insert/edit link',  
  297. 'unlink' => 'Remove link',  
  298. 'image' => 'Insert/edit image',  
  299. 'charmap' => 'Special character',  
  300. 'pastetext' => 'Paste as text',  
  301. 'print' => 'Print',  
  302. 'anchor' => 'Anchor',  
  303. 'searchreplace' => 'Find and replace',  
  304. 'visualblocks' => 'Show blocks',  
  305. 'visualchars' => 'Show invisible characters',  
  306. 'code' => 'Source code',  
  307. 'wp_code' => 'Code',  
  308. 'fullscreen' => 'Fullscreen',  
  309. 'insertdatetime' => 'Insert date/time',  
  310. 'media' => 'Insert/edit video',  
  311. 'nonbreaking' => 'Nonbreaking space',  
  312. 'table' => 'Table',  
  313. 'ltr' => 'Left to right',  
  314. 'rtl' => 'Right to left',  
  315. 'emoticons' => 'Emoticons',  
  316. 'forecolor' => 'Text color',  
  317. 'backcolor' => 'Background color',  
  318.  
  319. // Layer plugin ? 
  320. // 'insertlayer' => 'Layer',  
  321.  
  322. // WP 
  323. 'wp_adv' => 'Toolbar Toggle',  
  324. 'wp_help' => 'Keyboard Shortcuts',  
  325. 'wp_more' => 'Read more...',  
  326. 'wp_page' => 'Page break',  
  327.  
  328. 'tadv_mark' => 'Mark',  
  329. ); 
  330.  
  331. // add/remove allowed buttons 
  332. $buttons = apply_filters( 'tadv_allowed_buttons', $buttons ); 
  333.  
  334. $this->all_buttons = $buttons; 
  335. $this->buttons_filter = array_keys( $buttons ); 
  336. return $buttons; 
  337.  
  338. public function get_plugins( $plugins = array() ) { 
  339.  
  340. if ( ! is_array( $this->used_buttons ) ) { 
  341. $this->load_settings(); 
  342.  
  343. if ( in_array( 'anchor', $this->used_buttons, true ) ) 
  344. $plugins[] = 'anchor'; 
  345.  
  346. if ( in_array( 'visualchars', $this->used_buttons, true ) ) 
  347. $plugins[] = 'visualchars'; 
  348.  
  349. if ( in_array( 'visualblocks', $this->used_buttons, true ) ) 
  350. $plugins[] = 'visualblocks'; 
  351.  
  352. if ( in_array( 'nonbreaking', $this->used_buttons, true ) ) 
  353. $plugins[] = 'nonbreaking'; 
  354.  
  355. if ( in_array( 'emoticons', $this->used_buttons, true ) ) 
  356. $plugins[] = 'emoticons'; 
  357.  
  358. if ( in_array( 'insertdatetime', $this->used_buttons, true ) ) 
  359. $plugins[] = 'insertdatetime'; 
  360.  
  361. if ( in_array( 'table', $this->used_buttons, true ) ) 
  362. $plugins[] = 'table'; 
  363.  
  364. if ( in_array( 'print', $this->used_buttons, true ) ) 
  365. $plugins[] = 'print'; 
  366.  
  367. if ( in_array( 'searchreplace', $this->used_buttons, true ) ) 
  368. $plugins[] = 'searchreplace'; 
  369.  
  370. if ( in_array( 'code', $this->used_buttons, true ) ) 
  371. $plugins[] = 'code'; 
  372.  
  373. // if ( in_array( 'insertlayer', $this->used_buttons, true ) ) 
  374. // $plugins[] = 'layer'; 
  375.  
  376. // From options 
  377. if ( $this->check_user_setting( 'advlist' ) ) 
  378. $plugins[] = 'advlist'; 
  379.  
  380. if ( $this->check_user_setting( 'advlink' ) ) 
  381. $plugins[] = 'link'; 
  382.  
  383. if ( $this->check_admin_setting( 'importcss' ) ) 
  384. $plugins[] = 'importcss'; 
  385.  
  386. if ( $this->check_user_setting( 'contextmenu' ) ) 
  387. $plugins[] = 'contextmenu'; 
  388.  
  389. // add/remove used plugins 
  390. $plugins = apply_filters( 'tadv_used_plugins', $plugins, $this->used_buttons ); 
  391.  
  392. return array_unique( $plugins ); 
  393.  
  394. private function check_user_setting( $setting ) { 
  395. if ( ! is_array( $this->options ) ) { 
  396. $this->load_settings(); 
  397.  
  398. // Back-compat for 'fontsize_formats' 
  399. if ( $setting === 'fontsize_formats' && $this->check_admin_setting( 'fontsize_formats' ) ) { 
  400. return true; 
  401.  
  402. return in_array( $setting, $this->options, true ); 
  403.  
  404. private function check_admin_setting( $setting ) { 
  405. if ( ! is_array( $this->admin_options ) ) { 
  406. $this->load_settings(); 
  407.  
  408. if ( strpos( $setting, 'enable_' ) === 0 ) { 
  409. $disabled_editors = ! empty( $this->admin_settings['disabled_editors'] ) ? explode( ', ', $this->admin_settings['disabled_editors'] ) : array(); 
  410. return ! in_array( str_replace( 'enable_', '', $setting ), $disabled_editors ); 
  411.  
  412. return in_array( $setting, $this->admin_options, true ); 
  413.  
  414. public function mce_buttons_1( $original, $editor_id ) { 
  415. if ( $this->is_disabled() ) { 
  416. return $original; 
  417.  
  418. if ( ! is_array( $this->options ) ) { 
  419. $this->load_settings(); 
  420.  
  421. $buttons_1 = $this->toolbar_1; 
  422.  
  423. if ( is_array( $original ) && ! empty( $original ) ) { 
  424. $original = array_diff( $original, $this->buttons_filter ); 
  425. $buttons_1 = array_merge( $buttons_1, $original ); 
  426.  
  427. return $buttons_1; 
  428.  
  429. public function mce_buttons_2( $original ) { 
  430. if ( $this->is_disabled() ) { 
  431. return $original; 
  432.  
  433. if ( ! is_array( $this->options ) ) { 
  434. $this->load_settings(); 
  435.  
  436. $buttons_2 = $this->toolbar_2; 
  437.  
  438. if ( is_array( $original ) && ! empty( $original ) ) { 
  439. $original = array_diff( $original, $this->buttons_filter ); 
  440. $buttons_2 = array_merge( $buttons_2, $original ); 
  441.  
  442. return $buttons_2; 
  443.  
  444. public function mce_buttons_3( $original ) { 
  445. if ( $this->is_disabled() ) { 
  446. return $original; 
  447.  
  448. if ( ! is_array( $this->options ) ) { 
  449. $this->load_settings(); 
  450.  
  451. $buttons_3 = $this->toolbar_3; 
  452.  
  453. if ( is_array( $original ) && ! empty( $original ) ) { 
  454. $original = array_diff( $original, $this->buttons_filter ); 
  455. $buttons_3 = array_merge( $buttons_3, $original ); 
  456.  
  457. return $buttons_3; 
  458.  
  459. public function mce_buttons_4( $original ) { 
  460. if ( $this->is_disabled() ) { 
  461. return $original; 
  462.  
  463. if ( ! is_array( $this->options ) ) { 
  464. $this->load_settings(); 
  465.  
  466. $buttons_4 = $this->toolbar_4; 
  467.  
  468. if ( is_array( $original ) && ! empty( $original ) ) { 
  469. $original = array_diff( $original, $this->buttons_filter ); 
  470. $buttons_4 = array_merge( $buttons_4, $original ); 
  471.  
  472. return $buttons_4; 
  473.  
  474. public function mce_options( $init ) { 
  475. if ( $this->is_disabled() ) { 
  476. return $init; 
  477.  
  478. $init['image_advtab'] = true; 
  479. $init['rel_list'] = '[{text: "None", value: ""}, {text: "Nofollow", value: "nofollow"}]'; 
  480.  
  481. if ( $this->check_admin_setting( 'no_autop' ) ) { 
  482. $init['wpautop'] = false; 
  483. $init['indent'] = true; 
  484. $init['tadv_noautop'] = true; 
  485.  
  486. if ( $this->check_user_setting('menubar') ) { 
  487. $init['menubar'] = true; 
  488.  
  489. if ( ! in_array( 'wp_adv', $this->toolbar_1, true ) ) { 
  490. $init['wordpress_adv_hidden'] = false; 
  491.  
  492. if ( $this->check_admin_setting( 'importcss' ) ) { 
  493. // $init['importcss_selector_filter'] = 'function(sel) {return /^\.[a-z0-9]+$/i.test(sel);}'; 
  494. $init['importcss_file_filter'] = 'editor-style.css'; 
  495.  
  496. if ( $this->check_user_setting( 'fontsize_formats' ) ) { 
  497. $init['fontsize_formats'] = $this->fontsize_formats; 
  498.  
  499. if ( $this->check_user_setting( 'paste_images' ) ) { 
  500. $init['paste_data_images'] = true; 
  501.  
  502. if ( in_array( 'table', $this->plugins, true ) ) { 
  503. $init['table_toolbar'] = false; 
  504.  
  505. return $init; 
  506.  
  507. public function after_wp_tiny_mce() { 
  508. if ( $this->is_disabled() ) { 
  509. return; 
  510.  
  511. ?> 
  512. <script> 
  513. !function(a, b) {"undefined"!=typeof a&&"undefined"!=typeof b&&a(function() {b.addButton("sofbg-axcell", "¶", function(b, c) { 
  514. var d=a(c), e=a.trim(d.val()), f="table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|" + 
  515. "address|math|style|p|h[1-6]|hr|fieldset|legend|tmadv|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary"; 
  516. -1!==e.indexOf("</p>")&&-1===e.indexOf("\n\n")&&(e=e.replace(new RegExp("<(?:"+f+")(?: [^>]*)?>", "gi"), "\n$&"),  
  517. e=e.replace(new RegExp("</(?:"+f+")>", "gi"), "$&\n"), e=e.replace(/(<br(?: [^>]*)?>)[\r\n\t]*/gi, "$1\n"),  
  518. e=e.replace(/>\n[\r\n\t]+</g, ">\n<"), e=e.replace(/^<li/gm, " <li"), e=e.replace(/<td>\u00a0<\/td>/g, "<td> </td>"),  
  519. d.val(a.trim(e)))}, "", "", "Fix line breaks")})}(window.jQuery, window.QTags); 
  520. </script> 
  521. <?php 
  522.  
  523. public function htmledit( $content ) { 
  524. return $content; 
  525.  
  526. public function mce_external_plugins( $mce_plugins ) { 
  527. if ( $this->is_disabled() ) { 
  528. return $mce_plugins; 
  529.  
  530. if ( ! is_array( $this->plugins ) ) { 
  531. $this->plugins = array(); 
  532.  
  533. $this->plugins[] = 'wptadv'; 
  534.  
  535. $this->plugins = array_intersect( $this->plugins, $this->get_all_plugins() ); 
  536.  
  537. $plugpath = TADV_URL . 'mce/'; 
  538. $mce_plugins = (array) $mce_plugins; 
  539. $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; 
  540.  
  541. foreach ( $this->plugins as $plugin ) { 
  542. $mce_plugins["$plugin"] = $plugpath . $plugin . "/plugin{$suffix}.js"; 
  543.  
  544. return $mce_plugins; 
  545.  
  546. public function tiny_mce_plugins( $plugins ) { 
  547. if ( $this->is_disabled() ) { 
  548. return $plugins; 
  549.  
  550. if ( in_array( 'image', $this->used_buttons, true ) && ! in_array( 'image', $plugins, true ) ) { 
  551. $plugins[] = 'image'; 
  552.  
  553. if ( ( in_array( 'rtl', $this->used_buttons, true ) || in_array( 'ltr', $this->used_buttons, true ) ) && 
  554. ! in_array( 'directionality', (array) $plugins, true ) ) { 
  555.  
  556. $plugins[] = 'directionality'; 
  557.  
  558. return $plugins; 
  559.  
  560. private function parse_buttons( $toolbar_id = false, $buttons = false ) { 
  561. if ( $toolbar_id && ! $buttons && ! empty( $_POST[$toolbar_id] ) ) 
  562. $buttons = $_POST[$toolbar_id]; 
  563.  
  564. if ( is_array( $buttons ) ) { 
  565. $_buttons = array_map( array( @$this, 'filter_name' ), $buttons ); 
  566. return implode( ', ', array_filter( $_buttons ) ); 
  567.  
  568. return ''; 
  569.  
  570. private function filter_name( $str ) { 
  571. if ( empty( $str ) || ! is_string( $str ) ) 
  572. return ''; 
  573. // Button names 
  574. return preg_replace( '/[^a-z0-9_]/i', '', $str ); 
  575.  
  576. private function sanitize_settings( $settings ) { 
  577. $_settings = array(); 
  578.  
  579. if ( ! is_array( $settings ) ) { 
  580. return $_settings; 
  581.  
  582. foreach( $settings as $name => $value ) { 
  583. $name = preg_replace( '/[^a-z0-9_]+/', '', $name ); 
  584.  
  585. if ( strpos( $name, 'toolbar_' ) === 0 ) { 
  586. $_settings[$name] = $this->parse_buttons( false, explode( ', ', $value ) ); 
  587. } else if ( 'options' === $name || 'plugins' === $name || 'disabled_plugins' === $name ) { 
  588. $_settings[$name] = preg_replace( '/[^a-z0-9_, ]+/', '', $value ); 
  589.  
  590. return $_settings; 
  591.  
  592. private function validate_settings( $settings, $checklist ) { 
  593. if ( empty( $settings ) ) { 
  594. return ''; 
  595. } elseif ( is_string( $settings ) ) { 
  596. $settings = explode( ', ', $settings ); 
  597. } elseif ( ! is_array( $settings ) ) { 
  598. return ''; 
  599.  
  600. $_settings = array(); 
  601.  
  602. foreach ( $settings as $value ) { 
  603. if ( in_array( $value, $checklist, true ) ) { 
  604. $_settings[] = $value; 
  605.  
  606. return implode( ', ', $_settings ); 
  607.  
  608. private function save_settings( $all_settings = null ) { 
  609. $settings = $user_settings = array(); 
  610.  
  611. if ( empty( $this->buttons_filter ) ) { 
  612. $this->get_all_buttons(); 
  613.  
  614. if ( ! empty( $all_settings['settings'] ) ) { 
  615. $user_settings = $all_settings['settings']; 
  616.  
  617. for ( $i = 1; $i < 5; $i++ ) { 
  618. $toolbar_name = 'toolbar_' . $i; 
  619.  
  620. if ( ! empty( $user_settings[ $toolbar_name ] ) ) { 
  621. $toolbar = explode( ', ', $user_settings[ $toolbar_name ] ); 
  622. } elseif ( ! empty( $_POST[ $toolbar_name ] ) && is_array( $_POST[ $toolbar_name ] ) ) { 
  623. $toolbar = $_POST[ $toolbar_name ]; 
  624. } else { 
  625. $toolbar = array(); 
  626.  
  627. if ( $i > 1 && ( $wp_adv = array_search( 'wp_adv', $toolbar ) ) !== false ) { 
  628. unset( $toolbar[ $wp_adv ] ); 
  629.  
  630. $settings[ $toolbar_name ] = $this->validate_settings( $toolbar, $this->buttons_filter ); 
  631.  
  632. if ( ! empty( $user_settings['options'] ) ) { 
  633. $options = explode( ', ', $user_settings['options'] ); 
  634. } elseif ( ! empty( $_POST['options'] ) && is_array( $_POST['options'] ) ) { 
  635. $options = $_POST['options']; 
  636. } else { 
  637. $options = array(); 
  638.  
  639. $settings['options'] = $this->validate_settings( $options, $this->get_all_user_options() ); 
  640.  
  641. if ( ! empty( $user_settings['plugins'] ) ) { 
  642. $plugins = explode( ', ', $user_settings['plugins'] ); 
  643. } elseif ( ! empty( $_POST['options']['menubar'] ) ) { 
  644. $plugins = array( 'anchor', 'code', 'insertdatetime', 'nonbreaking', 'print', 'searchreplace', 'table', 'visualblocks', 'visualchars' ); 
  645. } else { 
  646. $plugins = array(); 
  647.  
  648. // Merge the submitted plugins with plugins needed for the buttons. 
  649. $this->user_settings = $settings; 
  650. $this->load_settings(); 
  651. $plugins = $this->get_plugins( $plugins ); 
  652.  
  653. $settings['plugins'] = $this->validate_settings( $plugins, $this->get_all_plugins() ); 
  654.  
  655. $this->user_settings = $settings; 
  656. $this->load_settings(); 
  657.  
  658. // Save the new settings. 
  659. update_option( 'tadv_settings', $settings ); 
  660.  
  661. if ( ! is_multisite() || current_user_can( 'manage_sites' ) ) { 
  662. $this->save_admin_settings( $all_settings ); 
  663.  
  664. private function save_admin_settings( $all_settings = null ) { 
  665. $admin_settings = $save_admin_settings = array(); 
  666.  
  667. if ( ! empty( $all_settings['admin_settings'] ) ) { 
  668. $admin_settings = $all_settings['admin_settings']; 
  669.  
  670. if ( ! empty( $admin_settings ) ) { 
  671. if ( ! empty( $admin_settings['options'] ) ) { 
  672. $save_admin_settings['options'] = $this->validate_settings( $admin_settings['options'], $this->get_all_admin_options() ); 
  673. } else { 
  674. $save_admin_settings['options'] = ''; 
  675.  
  676. $disabled_editors = array_intersect( $this->get_editor_locations(), explode( ', ', $admin_settings['disabled_editors'] ) ); 
  677. } elseif ( isset( $_POST['tadv-save'] ) ) { 
  678. if ( ! empty( $_POST['admin_options'] ) && is_array( $_POST['admin_options'] ) ) { 
  679. $save_admin_settings['options'] = $this->validate_settings( $_POST['admin_options'], $this->get_all_admin_options() ); 
  680.  
  681. if ( ! empty( $_POST['tadv_enable_at'] ) && is_array( $_POST['tadv_enable_at'] ) ) { 
  682. $tadv_enable_at = $_POST['tadv_enable_at']; 
  683. } else { 
  684. $tadv_enable_at = array(); 
  685.  
  686. $disabled_editors = array_diff( $this->get_editor_locations(), $tadv_enable_at ); 
  687. } else { 
  688. return; 
  689.  
  690. $save_admin_settings['disabled_editors'] = implode( ', ', $disabled_editors ); 
  691.  
  692. $this->admin_settings = $save_admin_settings; 
  693. update_option( 'tadv_admin_settings', $save_admin_settings ); 
  694.  
  695. public function settings_page() { 
  696. if ( ! defined( 'TADV_ADMIN_PAGE' ) ) { 
  697. define( 'TADV_ADMIN_PAGE', true ); 
  698.  
  699. include_once( TADV_PATH . 'tadv_admin.php' ); 
  700.  
  701. public function add_menu() { 
  702. add_options_page( 'TinyMCE Advanced', 'TinyMCE Advanced', 'manage_options', 'tinymce-advanced', array( $this, 'settings_page' ) ); 
  703.  
  704. /** 
  705. * Add a link to the settings page 
  706. */ 
  707. public function add_settings_link( $links, $file ) { 
  708. if ( $file === 'tinymce-advanced/tinymce-advanced.php' && current_user_can( 'manage_options' ) ) { 
  709. $settings_link = sprintf( '<a href="%s">%s</a>', admin_url( 'options-general.php?page=tinymce-advanced' ), __( 'Settings', 'tinymce-advanced' ) ); 
  710. array_unshift( $links, $settings_link ); 
  711.  
  712. return $links;