PageRenderTime 59ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-includes/class-wp-editor.php

https://gitlab.com/geyson/geyson
PHP | 1455 lines | 871 code | 199 blank | 385 comment | 135 complexity | ee6c66b9a58eb45407e81d7fe17cb0a5 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * Facilitates adding of the WordPress editor as used on the Write and Edit screens.
  4. *
  5. * @package WordPress
  6. * @since 3.3.0
  7. *
  8. * Private, not included by default. See wp_editor() in wp-includes/general-template.php.
  9. */
  10. final class _WP_Editors {
  11. public static $mce_locale;
  12. private static $mce_settings = array();
  13. private static $qt_settings = array();
  14. private static $plugins = array();
  15. private static $qt_buttons = array();
  16. private static $ext_plugins;
  17. private static $baseurl;
  18. private static $first_init;
  19. private static $this_tinymce = false;
  20. private static $this_quicktags = false;
  21. private static $has_tinymce = false;
  22. private static $has_quicktags = false;
  23. private static $has_medialib = false;
  24. private static $editor_buttons_css = true;
  25. private static $drag_drop_upload = false;
  26. private static $old_dfw_compat = false;
  27. private function __construct() {}
  28. /**
  29. * Parse default arguments for the editor instance.
  30. *
  31. * @static
  32. * @param string $editor_id ID for the current editor instance.
  33. * @param array $settings {
  34. * Array of editor arguments.
  35. *
  36. * @type bool $wpautop Whether to use wpautop(). Default true.
  37. * @type bool $media_buttons Whether to show the Add Media/other media buttons.
  38. * @type string $default_editor When both TinyMCE and Quicktags are used, set which
  39. * editor is shown on page load. Default empty.
  40. * @type bool $drag_drop_upload Whether to enable drag & drop on the editor uploading. Default false.
  41. * Requires the media modal.
  42. * @type string $textarea_name Give the textarea a unique name here. Square brackets
  43. * can be used here. Default $editor_id.
  44. * @type int $textarea_rows Number rows in the editor textarea. Default 20.
  45. * @type string|int $tabindex Tabindex value to use. Default empty.
  46. * @type string $tabfocus_elements The previous and next element ID to move the focus to
  47. * when pressing the Tab key in TinyMCE. Defualt ':prev,:next'.
  48. * @type string $editor_css Intended for extra styles for both Visual and Text editors.
  49. * Should include `<style>` tags, and can use "scoped". Default empty.
  50. * @type string $editor_class Extra classes to add to the editor textarea elemen. Default empty.
  51. * @type bool $teeny Whether to output the minimal editor config. Examples include
  52. * Press This and the Comment editor. Default false.
  53. * @type bool $dfw Deprecated in 4.1. Since 4.3 used only to enqueue wp-fullscreen-stub.js for backwards compatibility.
  54. * @type bool|array $tinymce Whether to load TinyMCE. Can be used to pass settings directly to
  55. * TinyMCE using an array. Default true.
  56. * @type bool|array $quicktags Whether to load Quicktags. Can be used to pass settings directly to
  57. * Quicktags using an array. Default true.
  58. * }
  59. * @return array Parsed arguments array.
  60. */
  61. public static function parse_settings( $editor_id, $settings ) {
  62. /**
  63. * Filter the wp_editor() settings.
  64. *
  65. * @since 4.0.0
  66. *
  67. * @see _WP_Editors()::parse_settings()
  68. *
  69. * @param array $settings Array of editor arguments.
  70. * @param string $editor_id ID for the current editor instance.
  71. */
  72. $settings = apply_filters( 'wp_editor_settings', $settings, $editor_id );
  73. $set = wp_parse_args( $settings, array(
  74. 'wpautop' => true,
  75. 'media_buttons' => true,
  76. 'default_editor' => '',
  77. 'drag_drop_upload' => false,
  78. 'textarea_name' => $editor_id,
  79. 'textarea_rows' => 20,
  80. 'tabindex' => '',
  81. 'tabfocus_elements' => ':prev,:next',
  82. 'editor_css' => '',
  83. 'editor_class' => '',
  84. 'teeny' => false,
  85. 'dfw' => false,
  86. '_content_editor_dfw' => false,
  87. 'tinymce' => true,
  88. 'quicktags' => true
  89. ) );
  90. self::$this_tinymce = ( $set['tinymce'] && user_can_richedit() );
  91. if ( self::$this_tinymce ) {
  92. if ( false !== strpos( $editor_id, '[' ) ) {
  93. self::$this_tinymce = false;
  94. _deprecated_argument( 'wp_editor()', '3.9', 'TinyMCE editor IDs cannot have brackets.' );
  95. }
  96. }
  97. self::$this_quicktags = (bool) $set['quicktags'];
  98. if ( self::$this_tinymce )
  99. self::$has_tinymce = true;
  100. if ( self::$this_quicktags )
  101. self::$has_quicktags = true;
  102. if ( $set['dfw'] ) {
  103. self::$old_dfw_compat = true;
  104. }
  105. if ( empty( $set['editor_height'] ) )
  106. return $set;
  107. if ( 'content' === $editor_id && empty( $set['tinymce']['wp_autoresize_on'] ) ) {
  108. // A cookie (set when a user resizes the editor) overrides the height.
  109. $cookie = (int) get_user_setting( 'ed_size' );
  110. if ( $cookie )
  111. $set['editor_height'] = $cookie;
  112. }
  113. if ( $set['editor_height'] < 50 )
  114. $set['editor_height'] = 50;
  115. elseif ( $set['editor_height'] > 5000 )
  116. $set['editor_height'] = 5000;
  117. return $set;
  118. }
  119. /**
  120. * Outputs the HTML for a single instance of the editor.
  121. *
  122. * @static
  123. * @param string $content The initial content of the editor.
  124. * @param string $editor_id ID for the textarea and TinyMCE and Quicktags instances (can contain only ASCII letters and numbers).
  125. * @param array $settings See the _parse_settings() method for description.
  126. */
  127. public static function editor( $content, $editor_id, $settings = array() ) {
  128. $set = self::parse_settings( $editor_id, $settings );
  129. $editor_class = ' class="' . trim( esc_attr( $set['editor_class'] ) . ' wp-editor-area' ) . '"';
  130. $tabindex = $set['tabindex'] ? ' tabindex="' . (int) $set['tabindex'] . '"' : '';
  131. $default_editor = 'html';
  132. $toolbar = $buttons = $autocomplete = '';
  133. $editor_id_attr = esc_attr( $editor_id );
  134. if ( $set['drag_drop_upload'] ) {
  135. self::$drag_drop_upload = true;
  136. }
  137. if ( ! empty( $set['editor_height'] ) ) {
  138. $height = ' style="height: ' . (int) $set['editor_height'] . 'px"';
  139. } else {
  140. $height = ' rows="' . (int) $set['textarea_rows'] . '"';
  141. }
  142. if ( ! current_user_can( 'upload_files' ) ) {
  143. $set['media_buttons'] = false;
  144. }
  145. if ( self::$this_tinymce ) {
  146. $autocomplete = ' autocomplete="off"';
  147. if ( self::$this_quicktags ) {
  148. $default_editor = $set['default_editor'] ? $set['default_editor'] : wp_default_editor();
  149. // 'html' is used for the "Text" editor tab.
  150. if ( 'html' !== $default_editor ) {
  151. $default_editor = 'tinymce';
  152. }
  153. $buttons .= '<button type="button" id="' . $editor_id_attr . '-tmce" class="wp-switch-editor switch-tmce"' .
  154. ' data-wp-editor-id="' . $editor_id_attr . '">' . __('Visual') . "</button>\n";
  155. $buttons .= '<button type="button" id="' . $editor_id_attr . '-html" class="wp-switch-editor switch-html"' .
  156. ' data-wp-editor-id="' . $editor_id_attr . '">' . _x( 'Text', 'Name for the Text editor tab (formerly HTML)' ) . "</button>\n";
  157. } else {
  158. $default_editor = 'tinymce';
  159. }
  160. }
  161. $switch_class = 'html' === $default_editor ? 'html-active' : 'tmce-active';
  162. $wrap_class = 'wp-core-ui wp-editor-wrap ' . $switch_class;
  163. if ( $set['_content_editor_dfw'] ) {
  164. $wrap_class .= ' has-dfw';
  165. }
  166. echo '<div id="wp-' . $editor_id_attr . '-wrap" class="' . $wrap_class . '">';
  167. if ( self::$editor_buttons_css ) {
  168. wp_print_styles( 'editor-buttons' );
  169. self::$editor_buttons_css = false;
  170. }
  171. if ( ! empty( $set['editor_css'] ) ) {
  172. echo $set['editor_css'] . "\n";
  173. }
  174. if ( ! empty( $buttons ) || $set['media_buttons'] ) {
  175. echo '<div id="wp-' . $editor_id_attr . '-editor-tools" class="wp-editor-tools hide-if-no-js">';
  176. if ( $set['media_buttons'] ) {
  177. self::$has_medialib = true;
  178. if ( ! function_exists( 'media_buttons' ) )
  179. include( ABSPATH . 'wp-admin/includes/media.php' );
  180. echo '<div id="wp-' . $editor_id_attr . '-media-buttons" class="wp-media-buttons">';
  181. /**
  182. * Fires after the default media button(s) are displayed.
  183. *
  184. * @since 2.5.0
  185. *
  186. * @param string $editor_id Unique editor identifier, e.g. 'content'.
  187. */
  188. do_action( 'media_buttons', $editor_id );
  189. echo "</div>\n";
  190. }
  191. echo '<div class="wp-editor-tabs">' . $buttons . "</div>\n";
  192. echo "</div>\n";
  193. }
  194. $quicktags_toolbar = '';
  195. if ( self::$this_quicktags ) {
  196. if ( 'content' === $editor_id && ! empty( $GLOBALS['current_screen'] ) && $GLOBALS['current_screen']->base === 'post' ) {
  197. $toolbar_id = 'ed_toolbar';
  198. } else {
  199. $toolbar_id = 'qt_' . $editor_id_attr . '_toolbar';
  200. }
  201. $quicktags_toolbar = '<div id="' . $toolbar_id . '" class="quicktags-toolbar"></div>';
  202. }
  203. /**
  204. * Filter the HTML markup output that displays the editor.
  205. *
  206. * @since 2.1.0
  207. *
  208. * @param string $output Editor's HTML markup.
  209. */
  210. $the_editor = apply_filters( 'the_editor', '<div id="wp-' . $editor_id_attr . '-editor-container" class="wp-editor-container">' .
  211. $quicktags_toolbar .
  212. '<textarea' . $editor_class . $height . $tabindex . $autocomplete . ' cols="40" name="' . esc_attr( $set['textarea_name'] ) . '" ' .
  213. 'id="' . $editor_id_attr . '">%s</textarea></div>' );
  214. // Prepare the content for the Visual or Text editor
  215. if ( self::$this_tinymce ) {
  216. add_filter( 'the_editor_content', 'format_for_editor', 10, 2 );
  217. }
  218. /**
  219. * Filter the default editor content.
  220. *
  221. * @since 2.1.0
  222. *
  223. * @param string $content Default editor content.
  224. */
  225. $content = apply_filters( 'the_editor_content', $content, $default_editor );
  226. // Back-compat for the `htmledit_pre` and `richedit_pre` filters
  227. if ( 'html' === $default_editor && has_filter( 'htmledit_pre' ) ) {
  228. // TODO: needs _deprecated_filter(), use _deprecated_function() as substitute for now
  229. _deprecated_function( 'add_filter( htmledit_pre )', '4.3.0', 'add_filter( format_for_editor )' );
  230. $content = apply_filters( 'htmledit_pre', $content );
  231. } elseif ( 'tinymce' === $default_editor && has_filter( 'richedit_pre' ) ) {
  232. _deprecated_function( 'add_filter( richedit_pre )', '4.3.0', 'add_filter( format_for_editor )' );
  233. $content = apply_filters( 'richedit_pre', $content );
  234. }
  235. if ( false !== stripos( $content, 'textarea' ) ) {
  236. $content = preg_replace( '%</textarea%i', '&lt;/textarea', $content );
  237. }
  238. printf( $the_editor, $content );
  239. echo "\n</div>\n\n";
  240. self::editor_settings( $editor_id, $set );
  241. }
  242. /**
  243. * @static
  244. *
  245. * @global string $wp_version
  246. * @global string $tinymce_version
  247. *
  248. * @param string $editor_id
  249. * @param array $set
  250. */
  251. public static function editor_settings($editor_id, $set) {
  252. global $wp_version, $tinymce_version;
  253. $first_run = false;
  254. if ( empty(self::$first_init) ) {
  255. if ( is_admin() ) {
  256. add_action( 'admin_print_footer_scripts', array( __CLASS__, 'editor_js' ), 50 );
  257. add_action( 'admin_print_footer_scripts', array( __CLASS__, 'enqueue_scripts' ), 1 );
  258. } else {
  259. add_action( 'wp_print_footer_scripts', array( __CLASS__, 'editor_js' ), 50 );
  260. add_action( 'wp_print_footer_scripts', array( __CLASS__, 'enqueue_scripts' ), 1 );
  261. }
  262. }
  263. if ( self::$this_quicktags ) {
  264. $qtInit = array(
  265. 'id' => $editor_id,
  266. 'buttons' => ''
  267. );
  268. if ( is_array($set['quicktags']) )
  269. $qtInit = array_merge($qtInit, $set['quicktags']);
  270. if ( empty($qtInit['buttons']) )
  271. $qtInit['buttons'] = 'strong,em,link,block,del,ins,img,ul,ol,li,code,more,close';
  272. if ( $set['_content_editor_dfw'] ) {
  273. $qtInit['buttons'] .= ',dfw';
  274. }
  275. /**
  276. * Filter the Quicktags settings.
  277. *
  278. * @since 3.3.0
  279. *
  280. * @param array $qtInit Quicktags settings.
  281. * @param string $editor_id The unique editor ID, e.g. 'content'.
  282. */
  283. $qtInit = apply_filters( 'quicktags_settings', $qtInit, $editor_id );
  284. self::$qt_settings[$editor_id] = $qtInit;
  285. self::$qt_buttons = array_merge( self::$qt_buttons, explode(',', $qtInit['buttons']) );
  286. }
  287. if ( self::$this_tinymce ) {
  288. if ( empty( self::$first_init ) ) {
  289. self::$baseurl = includes_url( 'js/tinymce' );
  290. $mce_locale = get_locale();
  291. self::$mce_locale = $mce_locale = empty( $mce_locale ) ? 'en' : strtolower( substr( $mce_locale, 0, 2 ) ); // ISO 639-1
  292. /** This filter is documented in wp-admin/includes/media.php */
  293. $no_captions = (bool) apply_filters( 'disable_captions', '' );
  294. $first_run = true;
  295. $ext_plugins = '';
  296. if ( $set['teeny'] ) {
  297. /**
  298. * Filter the list of teenyMCE plugins.
  299. *
  300. * @since 2.7.0
  301. *
  302. * @param array $plugins An array of teenyMCE plugins.
  303. * @param string $editor_id Unique editor identifier, e.g. 'content'.
  304. */
  305. self::$plugins = $plugins = apply_filters( 'teeny_mce_plugins', array( 'colorpicker', 'lists', 'fullscreen', 'image', 'wordpress', 'wpeditimage', 'wplink' ), $editor_id );
  306. } else {
  307. /**
  308. * Filter the list of TinyMCE external plugins.
  309. *
  310. * The filter takes an associative array of external plugins for
  311. * TinyMCE in the form 'plugin_name' => 'url'.
  312. *
  313. * The url should be absolute, and should include the js filename
  314. * to be loaded. For example:
  315. * 'myplugin' => 'http://mysite.com/wp-content/plugins/myfolder/mce_plugin.js'.
  316. *
  317. * If the external plugin adds a button, it should be added with
  318. * one of the 'mce_buttons' filters.
  319. *
  320. * @since 2.5.0
  321. *
  322. * @param array $external_plugins An array of external TinyMCE plugins.
  323. */
  324. $mce_external_plugins = apply_filters( 'mce_external_plugins', array() );
  325. $plugins = array(
  326. 'charmap',
  327. 'colorpicker',
  328. 'hr',
  329. 'lists',
  330. 'media',
  331. 'paste',
  332. 'tabfocus',
  333. 'textcolor',
  334. 'fullscreen',
  335. 'wordpress',
  336. 'wpautoresize',
  337. 'wpeditimage',
  338. 'wpemoji',
  339. 'wpgallery',
  340. 'wplink',
  341. 'wpdialogs',
  342. 'wptextpattern',
  343. 'wpview'
  344. );
  345. if ( ! self::$has_medialib ) {
  346. $plugins[] = 'image';
  347. }
  348. /**
  349. * Filter the list of default TinyMCE plugins.
  350. *
  351. * The filter specifies which of the default plugins included
  352. * in WordPress should be added to the TinyMCE instance.
  353. *
  354. * @since 3.3.0
  355. *
  356. * @param array $plugins An array of default TinyMCE plugins.
  357. */
  358. $plugins = array_unique( apply_filters( 'tiny_mce_plugins', $plugins ) );
  359. if ( ( $key = array_search( 'spellchecker', $plugins ) ) !== false ) {
  360. // Remove 'spellchecker' from the internal plugins if added with 'tiny_mce_plugins' filter to prevent errors.
  361. // It can be added with 'mce_external_plugins'.
  362. unset( $plugins[$key] );
  363. }
  364. if ( ! empty( $mce_external_plugins ) ) {
  365. /**
  366. * Filter the translations loaded for external TinyMCE 3.x plugins.
  367. *
  368. * The filter takes an associative array ('plugin_name' => 'path')
  369. * where 'path' is the include path to the file.
  370. *
  371. * The language file should follow the same format as wp_mce_translation(),
  372. * and should define a variable ($strings) that holds all translated strings.
  373. *
  374. * @since 2.5.0
  375. *
  376. * @param array $translations Translations for external TinyMCE plugins.
  377. */
  378. $mce_external_languages = apply_filters( 'mce_external_languages', array() );
  379. $loaded_langs = array();
  380. $strings = '';
  381. if ( ! empty( $mce_external_languages ) ) {
  382. foreach ( $mce_external_languages as $name => $path ) {
  383. if ( @is_file( $path ) && @is_readable( $path ) ) {
  384. include_once( $path );
  385. $ext_plugins .= $strings . "\n";
  386. $loaded_langs[] = $name;
  387. }
  388. }
  389. }
  390. foreach ( $mce_external_plugins as $name => $url ) {
  391. if ( in_array( $name, $plugins, true ) ) {
  392. unset( $mce_external_plugins[ $name ] );
  393. continue;
  394. }
  395. $url = set_url_scheme( $url );
  396. $mce_external_plugins[ $name ] = $url;
  397. $plugurl = dirname( $url );
  398. $strings = '';
  399. // Try to load langs/[locale].js and langs/[locale]_dlg.js
  400. if ( ! in_array( $name, $loaded_langs, true ) ) {
  401. $path = str_replace( content_url(), '', $plugurl );
  402. $path = WP_CONTENT_DIR . $path . '/langs/';
  403. if ( function_exists('realpath') )
  404. $path = trailingslashit( realpath($path) );
  405. if ( @is_file( $path . $mce_locale . '.js' ) )
  406. $strings .= @file_get_contents( $path . $mce_locale . '.js' ) . "\n";
  407. if ( @is_file( $path . $mce_locale . '_dlg.js' ) )
  408. $strings .= @file_get_contents( $path . $mce_locale . '_dlg.js' ) . "\n";
  409. if ( 'en' != $mce_locale && empty( $strings ) ) {
  410. if ( @is_file( $path . 'en.js' ) ) {
  411. $str1 = @file_get_contents( $path . 'en.js' );
  412. $strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.', $str1, 1 ) . "\n";
  413. }
  414. if ( @is_file( $path . 'en_dlg.js' ) ) {
  415. $str2 = @file_get_contents( $path . 'en_dlg.js' );
  416. $strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.', $str2, 1 ) . "\n";
  417. }
  418. }
  419. if ( ! empty( $strings ) )
  420. $ext_plugins .= "\n" . $strings . "\n";
  421. }
  422. $ext_plugins .= 'tinyMCEPreInit.load_ext("' . $plugurl . '", "' . $mce_locale . '");' . "\n";
  423. $ext_plugins .= 'tinymce.PluginManager.load("' . $name . '", "' . $url . '");' . "\n";
  424. }
  425. }
  426. }
  427. self::$plugins = $plugins;
  428. self::$ext_plugins = $ext_plugins;
  429. self::$first_init = array(
  430. 'theme' => 'modern',
  431. 'skin' => 'lightgray',
  432. 'language' => self::$mce_locale,
  433. 'formats' => '{' .
  434. 'alignleft: [' .
  435. '{selector: "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li", styles: {textAlign:"left"}},' .
  436. '{selector: "img,table,dl.wp-caption", classes: "alignleft"}' .
  437. '],' .
  438. 'aligncenter: [' .
  439. '{selector: "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li", styles: {textAlign:"center"}},' .
  440. '{selector: "img,table,dl.wp-caption", classes: "aligncenter"}' .
  441. '],' .
  442. 'alignright: [' .
  443. '{selector: "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li", styles: {textAlign:"right"}},' .
  444. '{selector: "img,table,dl.wp-caption", classes: "alignright"}' .
  445. '],' .
  446. 'strikethrough: {inline: "del"}' .
  447. '}',
  448. 'relative_urls' => false,
  449. 'remove_script_host' => false,
  450. 'convert_urls' => false,
  451. 'browser_spellcheck' => true,
  452. 'fix_list_elements' => true,
  453. 'entities' => '38,amp,60,lt,62,gt',
  454. 'entity_encoding' => 'raw',
  455. 'keep_styles' => false,
  456. 'cache_suffix' => 'wp-mce-' . $tinymce_version,
  457. // Limit the preview styles in the menu/toolbar
  458. 'preview_styles' => 'font-family font-size font-weight font-style text-decoration text-transform',
  459. 'end_container_on_empty_block' => true,
  460. 'wpeditimage_disable_captions' => $no_captions,
  461. 'wpeditimage_html5_captions' => current_theme_supports( 'html5', 'caption' ),
  462. 'plugins' => implode( ',', $plugins ),
  463. );
  464. if ( ! empty( $mce_external_plugins ) ) {
  465. self::$first_init['external_plugins'] = wp_json_encode( $mce_external_plugins );
  466. }
  467. $suffix = SCRIPT_DEBUG ? '' : '.min';
  468. $version = 'ver=' . $wp_version;
  469. $dashicons = includes_url( "css/dashicons$suffix.css?$version" );
  470. // WordPress default stylesheet and dashicons
  471. $mce_css = array(
  472. $dashicons,
  473. self::$baseurl . '/skins/wordpress/wp-content.css?' . $version
  474. );
  475. $editor_styles = get_editor_stylesheets();
  476. if ( ! empty( $editor_styles ) ) {
  477. foreach ( $editor_styles as $style ) {
  478. $mce_css[] = $style;
  479. }
  480. }
  481. /**
  482. * Filter the comma-delimited list of stylesheets to load in TinyMCE.
  483. *
  484. * @since 2.1.0
  485. *
  486. * @param array $stylesheets Comma-delimited list of stylesheets.
  487. */
  488. $mce_css = trim( apply_filters( 'mce_css', implode( ',', $mce_css ) ), ' ,' );
  489. if ( ! empty($mce_css) )
  490. self::$first_init['content_css'] = $mce_css;
  491. }
  492. if ( $set['teeny'] ) {
  493. /**
  494. * Filter the list of teenyMCE buttons (Text tab).
  495. *
  496. * @since 2.7.0
  497. *
  498. * @param array $buttons An array of teenyMCE buttons.
  499. * @param string $editor_id Unique editor identifier, e.g. 'content'.
  500. */
  501. $mce_buttons = apply_filters( 'teeny_mce_buttons', array('bold', 'italic', 'underline', 'blockquote', 'strikethrough', 'bullist', 'numlist', 'alignleft', 'aligncenter', 'alignright', 'undo', 'redo', 'link', 'unlink', 'fullscreen'), $editor_id );
  502. $mce_buttons_2 = $mce_buttons_3 = $mce_buttons_4 = array();
  503. } else {
  504. $mce_buttons = array( 'bold', 'italic', 'strikethrough', 'bullist', 'numlist', 'blockquote', 'hr', 'alignleft', 'aligncenter', 'alignright', 'link', 'unlink', 'wp_more', 'spellchecker' );
  505. if ( $set['_content_editor_dfw'] ) {
  506. $mce_buttons[] = 'dfw';
  507. } else {
  508. $mce_buttons[] = 'fullscreen';
  509. }
  510. $mce_buttons[] = 'wp_adv';
  511. /**
  512. * Filter the first-row list of TinyMCE buttons (Visual tab).
  513. *
  514. * @since 2.0.0
  515. *
  516. * @param array $buttons First-row list of buttons.
  517. * @param string $editor_id Unique editor identifier, e.g. 'content'.
  518. */
  519. $mce_buttons = apply_filters( 'mce_buttons', $mce_buttons, $editor_id );
  520. $mce_buttons_2 = array( 'formatselect', 'underline', 'alignjustify', 'forecolor', 'pastetext', 'removeformat', 'charmap', 'outdent', 'indent', 'undo', 'redo' );
  521. if ( ! wp_is_mobile() ) {
  522. $mce_buttons_2[] = 'wp_help';
  523. }
  524. /**
  525. * Filter the second-row list of TinyMCE buttons (Visual tab).
  526. *
  527. * @since 2.0.0
  528. *
  529. * @param array $buttons Second-row list of buttons.
  530. * @param string $editor_id Unique editor identifier, e.g. 'content'.
  531. */
  532. $mce_buttons_2 = apply_filters( 'mce_buttons_2', $mce_buttons_2, $editor_id );
  533. /**
  534. * Filter the third-row list of TinyMCE buttons (Visual tab).
  535. *
  536. * @since 2.0.0
  537. *
  538. * @param array $buttons Third-row list of buttons.
  539. * @param string $editor_id Unique editor identifier, e.g. 'content'.
  540. */
  541. $mce_buttons_3 = apply_filters( 'mce_buttons_3', array(), $editor_id );
  542. /**
  543. * Filter the fourth-row list of TinyMCE buttons (Visual tab).
  544. *
  545. * @since 2.5.0
  546. *
  547. * @param array $buttons Fourth-row list of buttons.
  548. * @param string $editor_id Unique editor identifier, e.g. 'content'.
  549. */
  550. $mce_buttons_4 = apply_filters( 'mce_buttons_4', array(), $editor_id );
  551. }
  552. $body_class = $editor_id;
  553. if ( $post = get_post() ) {
  554. $body_class .= ' post-type-' . sanitize_html_class( $post->post_type ) . ' post-status-' . sanitize_html_class( $post->post_status );
  555. if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
  556. $post_format = get_post_format( $post );
  557. if ( $post_format && ! is_wp_error( $post_format ) )
  558. $body_class .= ' post-format-' . sanitize_html_class( $post_format );
  559. else
  560. $body_class .= ' post-format-standard';
  561. }
  562. }
  563. $body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
  564. if ( !empty($set['tinymce']['body_class']) ) {
  565. $body_class .= ' ' . $set['tinymce']['body_class'];
  566. unset($set['tinymce']['body_class']);
  567. }
  568. $mceInit = array (
  569. 'selector' => "#$editor_id",
  570. 'resize' => 'vertical',
  571. 'menubar' => false,
  572. 'wpautop' => (bool) $set['wpautop'],
  573. 'indent' => ! $set['wpautop'],
  574. 'toolbar1' => implode($mce_buttons, ','),
  575. 'toolbar2' => implode($mce_buttons_2, ','),
  576. 'toolbar3' => implode($mce_buttons_3, ','),
  577. 'toolbar4' => implode($mce_buttons_4, ','),
  578. 'tabfocus_elements' => $set['tabfocus_elements'],
  579. 'body_class' => $body_class
  580. );
  581. // Merge with the first part of the init array
  582. $mceInit = array_merge( self::$first_init, $mceInit );
  583. if ( is_array( $set['tinymce'] ) )
  584. $mceInit = array_merge( $mceInit, $set['tinymce'] );
  585. /*
  586. * For people who really REALLY know what they're doing with TinyMCE
  587. * You can modify $mceInit to add, remove, change elements of the config
  588. * before tinyMCE.init. Setting "valid_elements", "invalid_elements"
  589. * and "extended_valid_elements" can be done through this filter. Best
  590. * is to use the default cleanup by not specifying valid_elements,
  591. * as TinyMCE checks against the full set of HTML 5.0 elements and attributes.
  592. */
  593. if ( $set['teeny'] ) {
  594. /**
  595. * Filter the teenyMCE config before init.
  596. *
  597. * @since 2.7.0
  598. *
  599. * @param array $mceInit An array with teenyMCE config.
  600. * @param string $editor_id Unique editor identifier, e.g. 'content'.
  601. */
  602. $mceInit = apply_filters( 'teeny_mce_before_init', $mceInit, $editor_id );
  603. } else {
  604. /**
  605. * Filter the TinyMCE config before init.
  606. *
  607. * @since 2.5.0
  608. *
  609. * @param array $mceInit An array with TinyMCE config.
  610. * @param string $editor_id Unique editor identifier, e.g. 'content'.
  611. */
  612. $mceInit = apply_filters( 'tiny_mce_before_init', $mceInit, $editor_id );
  613. }
  614. if ( empty( $mceInit['toolbar3'] ) && ! empty( $mceInit['toolbar4'] ) ) {
  615. $mceInit['toolbar3'] = $mceInit['toolbar4'];
  616. $mceInit['toolbar4'] = '';
  617. }
  618. self::$mce_settings[$editor_id] = $mceInit;
  619. } // end if self::$this_tinymce
  620. }
  621. /**
  622. *
  623. * @static
  624. * @param array $init
  625. * @return string
  626. */
  627. private static function _parse_init($init) {
  628. $options = '';
  629. foreach ( $init as $k => $v ) {
  630. if ( is_bool($v) ) {
  631. $val = $v ? 'true' : 'false';
  632. $options .= $k . ':' . $val . ',';
  633. continue;
  634. } elseif ( !empty($v) && is_string($v) && ( ('{' == $v{0} && '}' == $v{strlen($v) - 1}) || ('[' == $v{0} && ']' == $v{strlen($v) - 1}) || preg_match('/^\(?function ?\(/', $v) ) ) {
  635. $options .= $k . ':' . $v . ',';
  636. continue;
  637. }
  638. $options .= $k . ':"' . $v . '",';
  639. }
  640. return '{' . trim( $options, ' ,' ) . '}';
  641. }
  642. /**
  643. *
  644. * @static
  645. */
  646. public static function enqueue_scripts() {
  647. if ( self::$has_tinymce )
  648. wp_enqueue_script('editor');
  649. if ( self::$has_quicktags ) {
  650. wp_enqueue_script( 'quicktags' );
  651. wp_enqueue_style( 'buttons' );
  652. }
  653. if ( in_array('wplink', self::$plugins, true) || in_array('link', self::$qt_buttons, true) ) {
  654. wp_enqueue_script('wplink');
  655. }
  656. if ( self::$old_dfw_compat ) {
  657. wp_enqueue_script('wp-fullscreen-stub');
  658. }
  659. if ( self::$has_medialib ) {
  660. add_thickbox();
  661. wp_enqueue_script('media-upload');
  662. }
  663. /**
  664. * Fires when scripts and styles are enqueued for the editor.
  665. *
  666. * @since 3.9.0
  667. *
  668. * @param array $to_load An array containing boolean values whether TinyMCE
  669. * and Quicktags are being loaded.
  670. */
  671. do_action( 'wp_enqueue_editor', array(
  672. 'tinymce' => self::$has_tinymce,
  673. 'quicktags' => self::$has_quicktags,
  674. ) );
  675. }
  676. /**
  677. * Translates the default TinyMCE strings and returns them as JSON encoded object ready to be loaded with tinymce.addI18n().
  678. * Can be used directly (_WP_Editors::wp_mce_translation()) by passing the same locale as set in the TinyMCE init object.
  679. *
  680. * @static
  681. * @param string $mce_locale The locale used for the editor.
  682. * @param bool $json_only optional Whether to include the JavaScript calls to tinymce.addI18n() and tinymce.ScriptLoader.markDone().
  683. * @return string Translation object, JSON encoded.
  684. */
  685. public static function wp_mce_translation( $mce_locale = '', $json_only = false ) {
  686. $mce_translation = array(
  687. // Default TinyMCE strings
  688. 'New document' => __( 'New document' ),
  689. 'Formats' => _x( 'Formats', 'TinyMCE' ),
  690. 'Headings' => _x( 'Headings', 'TinyMCE' ),
  691. 'Heading 1' => __( 'Heading 1' ),
  692. 'Heading 2' => __( 'Heading 2' ),
  693. 'Heading 3' => __( 'Heading 3' ),
  694. 'Heading 4' => __( 'Heading 4' ),
  695. 'Heading 5' => __( 'Heading 5' ),
  696. 'Heading 6' => __( 'Heading 6' ),
  697. /* translators: block tags */
  698. 'Blocks' => _x( 'Blocks', 'TinyMCE' ),
  699. 'Paragraph' => __( 'Paragraph' ),
  700. 'Blockquote' => __( 'Blockquote' ),
  701. 'Div' => _x( 'Div', 'HTML tag' ),
  702. 'Pre' => _x( 'Pre', 'HTML tag' ),
  703. 'Preformatted' => _x( 'Preformatted', 'HTML tag' ),
  704. 'Address' => _x( 'Address', 'HTML tag' ),
  705. 'Inline' => _x( 'Inline', 'HTML elements' ),
  706. 'Underline' => __( 'Underline' ),
  707. 'Strikethrough' => __( 'Strikethrough' ),
  708. 'Subscript' => __( 'Subscript' ),
  709. 'Superscript' => __( 'Superscript' ),
  710. 'Clear formatting' => __( 'Clear formatting' ),
  711. 'Bold' => __( 'Bold' ),
  712. 'Italic' => __( 'Italic' ),
  713. 'Code' => _x( 'Code', 'editor button' ),
  714. 'Source code' => __( 'Source code' ),
  715. 'Font Family' => __( 'Font Family' ),
  716. 'Font Sizes' => __( 'Font Sizes' ),
  717. 'Align center' => __( 'Align center' ),
  718. 'Align right' => __( 'Align right' ),
  719. 'Align left' => __( 'Align left' ),
  720. 'Justify' => __( 'Justify' ),
  721. 'Increase indent' => __( 'Increase indent' ),
  722. 'Decrease indent' => __( 'Decrease indent' ),
  723. 'Cut' => __( 'Cut' ),
  724. 'Copy' => __( 'Copy' ),
  725. 'Paste' => __( 'Paste' ),
  726. 'Select all' => __( 'Select all' ),
  727. 'Undo' => __( 'Undo' ),
  728. 'Redo' => __( 'Redo' ),
  729. 'Ok' => __( 'OK' ),
  730. 'Cancel' => __( 'Cancel' ),
  731. 'Close' => __( 'Close' ),
  732. 'Visual aids' => __( 'Visual aids' ),
  733. 'Bullet list' => __( 'Bulleted list' ),
  734. 'Numbered list' => __( 'Numbered list' ),
  735. 'Square' => _x( 'Square', 'list style' ),
  736. 'Default' => _x( 'Default', 'list style' ),
  737. 'Circle' => _x( 'Circle', 'list style' ),
  738. 'Disc' => _x('Disc', 'list style' ),
  739. 'Lower Greek' => _x( 'Lower Greek', 'list style' ),
  740. 'Lower Alpha' => _x( 'Lower Alpha', 'list style' ),
  741. 'Upper Alpha' => _x( 'Upper Alpha', 'list style' ),
  742. 'Upper Roman' => _x( 'Upper Roman', 'list style' ),
  743. 'Lower Roman' => _x( 'Lower Roman', 'list style' ),
  744. // Anchor plugin
  745. 'Name' => _x( 'Name', 'Name of link anchor (TinyMCE)' ),
  746. 'Anchor' => _x( 'Anchor', 'Link anchor (TinyMCE)' ),
  747. 'Anchors' => _x( 'Anchors', 'Link anchors (TinyMCE)' ),
  748. // Fullpage plugin
  749. 'Document properties' => __( 'Document properties' ),
  750. 'Robots' => __( 'Robots' ),
  751. 'Title' => __( 'Title' ),
  752. 'Keywords' => __( 'Keywords' ),
  753. 'Encoding' => __( 'Encoding' ),
  754. 'Description' => __( 'Description' ),
  755. 'Author' => __( 'Author' ),
  756. // Media, image plugins
  757. 'Insert/edit image' => __( 'Insert/edit image' ),
  758. 'General' => __( 'General' ),
  759. 'Advanced' => __( 'Advanced' ),
  760. 'Source' => __( 'Source' ),
  761. 'Border' => __( 'Border' ),
  762. 'Constrain proportions' => __( 'Constrain proportions' ),
  763. 'Vertical space' => __( 'Vertical space' ),
  764. 'Image description' => __( 'Image description' ),
  765. 'Style' => __( 'Style' ),
  766. 'Dimensions' => __( 'Dimensions' ),
  767. 'Insert image' => __( 'Insert image' ),
  768. 'Insert date/time' => __( 'Insert date/time' ),
  769. 'Insert/edit video' => __( 'Insert/edit video' ),
  770. 'Poster' => __( 'Poster' ),
  771. 'Alternative source' => __( 'Alternative source' ),
  772. 'Paste your embed code below:' => __( 'Paste your embed code below:' ),
  773. 'Insert video' => __( 'Insert video' ),
  774. 'Embed' => __( 'Embed' ),
  775. // Each of these have a corresponding plugin
  776. 'Special character' => __( 'Special character' ),
  777. 'Right to left' => _x( 'Right to left', 'editor button' ),
  778. 'Left to right' => _x( 'Left to right', 'editor button' ),
  779. 'Emoticons' => __( 'Emoticons' ),
  780. 'Nonbreaking space' => __( 'Nonbreaking space' ),
  781. 'Page break' => __( 'Page break' ),
  782. 'Paste as text' => __( 'Paste as text' ),
  783. 'Preview' => __( 'Preview' ),
  784. 'Print' => __( 'Print' ),
  785. 'Save' => __( 'Save' ),
  786. 'Fullscreen' => __( 'Fullscreen' ),
  787. 'Horizontal line' => __( 'Horizontal line' ),
  788. 'Horizontal space' => __( 'Horizontal space' ),
  789. 'Restore last draft' => __( 'Restore last draft' ),
  790. 'Insert/edit link' => __( 'Insert/edit link' ),
  791. 'Remove link' => __( 'Remove link' ),
  792. 'Color' => __( 'Color' ),
  793. 'Custom color' => __( 'Custom color' ),
  794. 'Custom...' => _x( 'Custom...', 'label for custom color' ),
  795. 'No color' => __( 'No color' ),
  796. // Spelling, search/replace plugins
  797. 'Could not find the specified string.' => __( 'Could not find the specified string.' ),
  798. 'Replace' => _x( 'Replace', 'find/replace' ),
  799. 'Next' => _x( 'Next', 'find/replace' ),
  800. /* translators: previous */
  801. 'Prev' => _x( 'Prev', 'find/replace' ),
  802. 'Whole words' => _x( 'Whole words', 'find/replace' ),
  803. 'Find and replace' => __( 'Find and replace' ),
  804. 'Replace with' => _x('Replace with', 'find/replace' ),
  805. 'Find' => _x( 'Find', 'find/replace' ),
  806. 'Replace all' => _x( 'Replace all', 'find/replace' ),
  807. 'Match case' => __( 'Match case' ),
  808. 'Spellcheck' => __( 'Check Spelling' ),
  809. 'Finish' => _x( 'Finish', 'spellcheck' ),
  810. 'Ignore all' => _x( 'Ignore all', 'spellcheck' ),
  811. 'Ignore' => _x( 'Ignore', 'spellcheck' ),
  812. 'Add to Dictionary' => __( 'Add to Dictionary' ),
  813. // TinyMCE tables
  814. 'Insert table' => __( 'Insert table' ),
  815. 'Delete table' => __( 'Delete table' ),
  816. 'Table properties' => __( 'Table properties' ),
  817. 'Row properties' => __( 'Table row properties' ),
  818. 'Cell properties' => __( 'Table cell properties' ),
  819. 'Border color' => __( 'Border color' ),
  820. 'Row' => __( 'Row' ),
  821. 'Rows' => __( 'Rows' ),
  822. 'Column' => _x( 'Column', 'table column' ),
  823. 'Cols' => _x( 'Cols', 'table columns' ),
  824. 'Cell' => _x( 'Cell', 'table cell' ),
  825. 'Header cell' => __( 'Header cell' ),
  826. 'Header' => _x( 'Header', 'table header' ),
  827. 'Body' => _x( 'Body', 'table body' ),
  828. 'Footer' => _x( 'Footer', 'table footer' ),
  829. 'Insert row before' => __( 'Insert row before' ),
  830. 'Insert row after' => __( 'Insert row after' ),
  831. 'Insert column before' => __( 'Insert column before' ),
  832. 'Insert column after' => __( 'Insert column after' ),
  833. 'Paste row before' => __( 'Paste table row before' ),
  834. 'Paste row after' => __( 'Paste table row after' ),
  835. 'Delete row' => __( 'Delete row' ),
  836. 'Delete column' => __( 'Delete column' ),
  837. 'Cut row' => __( 'Cut table row' ),
  838. 'Copy row' => __( 'Copy table row' ),
  839. 'Merge cells' => __( 'Merge table cells' ),
  840. 'Split cell' => __( 'Split table cell' ),
  841. 'Height' => __( 'Height' ),
  842. 'Width' => __( 'Width' ),
  843. 'Caption' => __( 'Caption' ),
  844. 'Alignment' => __( 'Alignment' ),
  845. 'H Align' => _x( 'H Align', 'horizontal table cell alignment' ),
  846. 'Left' => __( 'Left' ),
  847. 'Center' => __( 'Center' ),
  848. 'Right' => __( 'Right' ),
  849. 'None' => _x( 'None', 'table cell alignment attribute' ),
  850. 'V Align' => _x( 'V Align', 'vertical table cell alignment' ),
  851. 'Top' => __( 'Top' ),
  852. 'Middle' => __( 'Middle' ),
  853. 'Bottom' => __( 'Bottom' ),
  854. 'Row group' => __( 'Row group' ),
  855. 'Column group' => __( 'Column group' ),
  856. 'Row type' => __( 'Row type' ),
  857. 'Cell type' => __( 'Cell type' ),
  858. 'Cell padding' => __( 'Cell padding' ),
  859. 'Cell spacing' => __( 'Cell spacing' ),
  860. 'Scope' => _x( 'Scope', 'table cell scope attribute' ),
  861. 'Insert template' => _x( 'Insert template', 'TinyMCE' ),
  862. 'Templates' => _x( 'Templates', 'TinyMCE' ),
  863. 'Background color' => __( 'Background color' ),
  864. 'Text color' => __( 'Text color' ),
  865. 'Show blocks' => _x( 'Show blocks', 'editor button' ),
  866. 'Show invisible characters' => __( 'Show invisible characters' ),
  867. /* translators: word count */
  868. 'Words: {0}' => sprintf( __( 'Words: %s' ), '{0}' ),
  869. 'Paste is now in plain text mode. Contents will now be pasted as plain text until you toggle this option off.' => __( 'Paste is now in plain text mode. Contents will now be pasted as plain text until you toggle this option off.' ) . "\n\n" . __( 'If you&#8217;re looking to paste rich content from Microsoft Word, try turning this option off. The editor will clean up text pasted from Word automatically.' ),
  870. 'Rich Text Area. Press ALT-F9 for menu. Press ALT-F10 for toolbar. Press ALT-0 for help' => __( 'Rich Text Area. Press Alt-Shift-H for help' ),
  871. 'You have unsaved changes are you sure you want to navigate away?' => __( 'The changes you made will be lost if you navigate away from this page.' ),
  872. 'Your browser doesn\'t support direct access to the clipboard. Please use the Ctrl+X/C/V keyboard shortcuts instead.' => __( 'Your browser does not support direct access to the clipboard. Please use keyboard shortcuts or your browser&#8217;s edit menu instead.' ),
  873. // TinyMCE menus
  874. 'Insert' => _x( 'Insert', 'TinyMCE menu' ),
  875. 'File' => _x( 'File', 'TinyMCE menu' ),
  876. 'Edit' => _x( 'Edit', 'TinyMCE menu' ),
  877. 'Tools' => _x( 'Tools', 'TinyMCE menu' ),
  878. 'View' => _x( 'View', 'TinyMCE menu' ),
  879. 'Table' => _x( 'Table', 'TinyMCE menu' ),
  880. 'Format' => _x( 'Format', 'TinyMCE menu' ),
  881. // WordPress strings
  882. 'Toolbar Toggle' => __( 'Toolbar Toggle' ),
  883. 'Insert Read More tag' => __( 'Insert Read More tag' ),
  884. 'Insert Page Break tag' => __( 'Insert Page Break tag' ),
  885. 'Read more...' => __( 'Read more...' ), // Title on the placeholder inside the editor
  886. 'Distraction-free writing mode' => __( 'Distraction-free writing mode' ),
  887. 'No alignment' => __( 'No alignment' ), // Tooltip for the 'alignnone' button in the image toolbar
  888. 'Remove' => __( 'Remove' ), // Tooltip for the 'remove' button in the image toolbar
  889. 'Edit ' => __( 'Edit' ), // Tooltip for the 'edit' button in the image toolbar
  890. // Shortcuts help modal
  891. 'Keyboard Shortcuts' => __( 'Keyboard Shortcuts' ),
  892. 'Default shortcuts,' => __( 'Default shortcuts,' ),
  893. 'Additional shortcuts,' => __( 'Additional shortcuts,' ),
  894. 'Focus shortcuts:' => __( 'Focus shortcuts:' ),
  895. 'Inline toolbar (when an image, link or preview is selected)' => __( 'Inline toolbar (when an image, link or preview is selected)' ),
  896. 'Editor menu (when enabled)' => __( 'Editor menu (when enabled)' ),
  897. 'Editor toolbar' => __( 'Editor toolbar' ),
  898. 'Elements path' => __( 'Elements path' ),
  899. 'Ctrl + Alt + letter:' => __( 'Ctrl + Alt + letter:' ),
  900. 'Shift + Alt + letter:' => __( 'Shift + Alt + letter:' ),
  901. 'Cmd + letter:' => __( 'Cmd + letter:' ),
  902. 'Ctrl + letter:' => __( 'Ctrl + letter:' ),
  903. 'Letter' => __( 'Letter' ),
  904. 'Action' => __( 'Action' ),
  905. 'To move focus to other buttons use Tab or the arrow keys. To return focus to the editor press Escape or use one of the buttons.' =>
  906. __( 'To move focus to other buttons use Tab or the arrow keys. To return focus to the editor press Escape or use one of the buttons.' ),
  907. 'When starting a new paragraph with one of these formatting shortcuts followed by a space, the formatting will be applied automatically. Press Backspace or Escape to undo.' =>
  908. __( 'When starting a new paragraph with one of these formatting shortcuts followed by a space, the formatting will be applied automatically. Press Backspace or Escape to undo.' ),
  909. 'The following formatting shortcuts are replaced when pressing Enter. Press Escape or the Undo button to undo.' =>
  910. __( 'The following formatting shortcuts are replaced when pressing Enter. Press Escape or the Undo button to undo.' ),
  911. );
  912. /**
  913. * Link plugin (not included):
  914. * Insert link
  915. * Target
  916. * New window
  917. * Text to display
  918. * The URL you entered seems to be an email address. Do you want to add the required mailto: prefix?
  919. * The URL you entered seems to be an external link. Do you want to add the required http:\/\/ prefix?
  920. * Url
  921. */
  922. if ( ! $mce_locale ) {
  923. $mce_locale = self::$mce_locale;
  924. }
  925. /**
  926. * Filter translated strings prepared for TinyMCE.
  927. *
  928. * @since 3.9.0
  929. *
  930. * @param array $mce_translation Key/value pairs of strings.
  931. * @param string $mce_locale Locale.
  932. */
  933. $mce_translation = apply_filters( 'wp_mce_translation', $mce_translation, $mce_locale );
  934. foreach ( $mce_translation as $key => $value ) {
  935. // Remove strings that are not translated.
  936. if ( $key === $value ) {
  937. unset( $mce_translation[$key] );
  938. continue;
  939. }
  940. if ( false !== strpos( $value, '&' ) ) {
  941. $mce_translation[$key] = html_entity_decode( $value, ENT_QUOTES, 'UTF-8' );
  942. }
  943. }
  944. // Set direction
  945. if ( is_rtl() ) {
  946. $mce_translation['_dir'] = 'rtl';
  947. }
  948. if ( $json_only ) {
  949. return wp_json_encode( $mce_translation );
  950. }
  951. $baseurl = self::$baseurl ? self::$baseurl : includes_url( 'js/tinymce' );
  952. return "tinymce.addI18n( '$mce_locale', " . wp_json_encode( $mce_translation ) . ");\n" .
  953. "tinymce.ScriptLoader.markDone( '$baseurl/langs/$mce_locale.js' );\n";
  954. }
  955. /**
  956. *
  957. * @static
  958. * @global string $wp_version
  959. * @global string $tinymce_version
  960. * @global bool $concatenate_scripts
  961. * @global bool $compress_scripts
  962. */
  963. public static function editor_js() {
  964. global $wp_version, $tinymce_version, $concatenate_scripts, $compress_scripts;
  965. /**
  966. * Filter "tiny_mce_version" is deprecated
  967. *
  968. * The tiny_mce_version filter is not needed since external plugins are loaded directly by TinyMCE.
  969. * These plugins can be refreshed by appending query string to the URL passed to "mce_external_plugins" filter.
  970. * If the plugin has a popup dialog, a query string can be added to the button action that opens it (in the plugin's code).
  971. */
  972. $version = 'ver=' . $tinymce_version;
  973. $tmce_on = !empty(self::$mce_settings);
  974. if ( ! isset($concatenate_scripts) )
  975. script_concat_settings();
  976. $compressed = $compress_scripts && $concatenate_scripts && isset($_SERVER['HTTP_ACCEPT_ENCODING'])
  977. && false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip');
  978. $mceInit = $qtInit = '';
  979. if ( $tmce_on ) {
  980. foreach ( self::$mce_settings as $editor_id => $init ) {
  981. $options = self::_parse_init( $init );
  982. $mceInit .= "'$editor_id':{$options},";
  983. }
  984. $mceInit = '{' . trim($mceInit, ',') . '}';
  985. } else {
  986. $mceInit = '{}';
  987. }
  988. if ( !empty(self::$qt_settings) ) {
  989. foreach ( self::$qt_settings as $editor_id => $init ) {
  990. $options = self::_parse_init( $init );
  991. $qtInit .= "'$editor_id':{$options},";
  992. }
  993. $qtInit = '{' . trim($qtInit, ',') . '}';
  994. } else {
  995. $qtInit = '{}';
  996. }
  997. $ref = array(
  998. 'plugins' => implode( ',', self::$plugins ),
  999. 'theme' => 'modern',
  1000. 'language' => self::$mce_locale
  1001. );
  1002. $suffix = SCRIPT_DEBUG ? '' : '.min';
  1003. /**
  1004. * Fires immediately before the TinyMCE settings are printed.
  1005. *
  1006. * @since 3.2.0
  1007. *
  1008. * @param array $mce_settings TinyMCE settings array.
  1009. */
  1010. do_action( 'before_wp_tiny_mce', self::$mce_settings );
  1011. ?>
  1012. <script type="text/javascript">
  1013. tinyMCEPreInit = {
  1014. baseURL: "<?php echo self::$baseurl; ?>",
  1015. suffix: "<?php echo $suffix; ?>",
  1016. <?php
  1017. if ( self::$drag_drop_upload ) {
  1018. echo 'dragDropUpload: true,';
  1019. }
  1020. ?>
  1021. mceInit: <?php echo $mceInit; ?>,
  1022. qtInit: <?php echo $qtInit; ?>,
  1023. ref: <?php echo self::_parse_init( $ref ); ?>,
  1024. load_ext: function(url,lang){var sl=tinymce.ScriptLoader;sl.markDone(url+'/langs/'+lang+'.js');sl.markDone(url+'/langs/'+lang+'_dlg.js');}
  1025. };
  1026. </script>
  1027. <?php
  1028. $baseurl = self::$baseurl;
  1029. // Load tinymce.js when running from /src, else load wp-tinymce.js.gz (production) or tinymce.min.js (SCRIPT_DEBUG)
  1030. $mce_suffix = false !== strpos( $wp_version, '-src' ) ? '' : '.min';
  1031. if ( $tmce_on ) {
  1032. if ( $compressed ) {
  1033. echo "<script type='text/javascript' src='{$baseurl}/wp-tinymce.php?c=1&amp;$version'></script>\n";
  1034. } else {
  1035. echo "<script type='text/javascript' src='{$baseurl}/tinymce{$mce_suffix}.js?$version'></script>\n";
  1036. echo "<script type='text/javascript' src='{$baseurl}/plugins/compat3x/plugin{$suffix}.js?$version'></script>\n";
  1037. }
  1038. echo "<script type='text/javascript'>\n" . self::wp_mce_translation() . "</script>\n";
  1039. if ( self::$ext_plugins ) {
  1040. // Load the old-format English strings to prevent unsightly labels in old style popups
  1041. echo "<script type='text/javascript' src='{$baseurl}/langs/wp-langs-en.js?$version'></script>\n";
  1042. }
  1043. }
  1044. /**
  1045. * Fires after tinymce.js is loaded, but before any TinyMCE editor
  1046. * instances are created.
  1047. *
  1048. * @since 3.9.0
  1049. *
  1050. * @param array $mce_settings TinyMCE settings array.
  1051. */
  1052. do_action( 'wp_tiny_mce_init', self::$mce_settings );
  1053. ?>
  1054. <script type="text/javascript">
  1055. <?php
  1056. if ( self::$ext_plugins )
  1057. echo self::$ext_plugins . "\n";
  1058. if ( ! is_admin() )
  1059. echo 'var ajaxurl = "' . admin_url( 'admin-ajax.php', 'relative' ) . '";';
  1060. ?>
  1061. ( function() {
  1062. var init, id, $wrap;
  1063. if ( typeof tinymce !== 'undefined' ) {
  1064. for ( id in tinyMCEPreInit.mceInit ) {
  1065. init = tinyMCEPreInit.mceInit[id];
  1066. $wrap = tinymce.$( '#wp-' + id + '-wrap' );
  1067. if ( ( $wrap.hasClass( 'tmce-active' ) || ! tinyMCEPreInit.qtInit.hasOwnProperty( id ) ) && ! init.wp_skip_init ) {
  1068. tinymce.init( init );
  1069. if ( ! window.wpActiveEditor ) {
  1070. window.wpActiveEditor = id;
  1071. }
  1072. }
  1073. }
  1074. }
  1075. if ( typeof quicktags !== 'undefined' ) {
  1076. for ( id in tinyMCEPreInit.qtInit ) {
  1077. quicktags( tinyMCEPreInit.qtInit[id] );
  1078. if ( ! window.wpActiveEditor ) {
  1079. window.wpActiveEditor = id;
  1080. }
  1081. }
  1082. }
  1083. }());
  1084. </script>
  1085. <?php
  1086. if ( in_array( 'wplink', self::$plugins, true ) || in_array( 'link', self::$qt_buttons, true ) )
  1087. self::wp_link_dialog();
  1088. /**
  1089. * Fires after any core TinyMCE editor instances are created.
  1090. *
  1091. * @since 3.2.0
  1092. *
  1093. * @param array $mce_settings TinyMCE settings array.
  1094. */
  1095. do_action( 'after_wp_tiny_mce', self::$mce_settings );
  1096. }
  1097. /**
  1098. *
  1099. * @static
  1100. * @global int $content_width
  1101. */
  1102. public static function wp_fullscreen_html() {
  1103. _deprecated_function( __FUNCTION__, '4.3' );
  1104. }
  1105. /**
  1106. * Performs post queries for internal linking.
  1107. *
  1108. * @since 3.1.0
  1109. *
  1110. * @static
  1111. * @param array $args Optional. Accepts 'pagenum' and 's' (search) arguments.
  1112. * @return false|array Results.
  1113. */
  1114. public static function wp_link_query( $args = array() ) {
  1115. $pts = get_post_types( array( 'public' => true ), 'objects' );
  1116. $pt_names = array_keys( $pts );
  1117. $query = array(
  1118. 'post_type' => $pt_names,
  1119. 'suppress_filters' => true,
  1120. 'update_post_term_cache' => false,
  1121. 'update_post_meta_cache' => false,
  1122. 'post_status' => 'publish',
  1123. 'posts_per_page' => 20,
  1124. );
  1125. $args['pagenum'] = isset( $args['pagenum'] ) ? absint( $args['pagenum'] ) : 1;
  1126. if ( isset( $args['s'] ) )
  1127. $query['s'] = $args['s'];
  1128. $query['offset'] = $args['pagenum'] > 1 ? $query['posts_per_page'] * ( $args['pagenum'] - 1 ) : 0;
  1129. /**
  1130. * Filter the link query arguments.
  1131. *
  1132. * Allows modification of the link query arguments before querying.
  1133. *
  1134. * @see WP_Query for a full list of arguments
  1135. *
  1136. * @since 3.7.0
  1137. *
  1138. * @param array $query An array of WP_Query arguments.
  1139. */
  1140. $query = apply_filters( 'wp_link_query_args', $query );
  1141. // Do main query.
  1142. $get_posts = new WP_Query;
  1143. $posts = $get_posts->query( $query );
  1144. // Check if any posts were found.
  1145. if ( ! $get_posts->post_count )
  1146. return false;
  1147. // Build results.
  1148. $results = array();
  1149. foreach ( $posts as $post ) {
  1150. if ( 'post' == $post->post_type )
  1151. $info = mysql2date( __( 'Y/m/d' ), $post->post_date );
  1152. else
  1153. $info = $pts[ $post->post_type ]->labels->singular_name;
  1154. $results[] = array(
  1155. 'ID' => $post->ID,
  1156. 'title' => trim( esc_html( strip_tags( get_the_title( $post ) ) ) ),
  1157. 'permalink' => get_permalink( $post->ID ),
  1158. 'info' => $info,
  1159. );
  1160. }
  1161. /**
  1162. * Filter the link query results.
  1163. *
  1164. * Allows modification of the returned link query results.
  1165. *
  1166. * @since 3.7.0
  1167. *
  1168. * @see 'wp_link_query_args' filter
  1169. *
  1170. * @param array $results {
  1171. * An associative array of query results.
  1172. *
  1173. * @type array {
  1174. * @type int $ID Post ID.
  1175. * @type string $title The trimmed, escaped post title.
  1176. * @type string $permalink Post permalink.
  1177. * @type string $info A 'Y/m/d'-formatted date for 'post' post type,
  1178. * the 'singular_name' post type label otherwise.
  1179. * }
  1180. * }
  1181. * @param array $query An array of WP_Query arguments.
  1182. */
  1183. return apply_filters( 'wp_link_query', $results, $query );
  1184. }
  1185. /**
  1186. * Dialog for internal linking.
  1187. *
  1188. * @since 3.1.0
  1189. *
  1190. * @static
  1191. */
  1192. public static function wp_link_dialog() {
  1193. $search_panel_visible = '1' == get_user_setting( 'wplink', '0' ) ? ' search-panel-visible' : '';
  1194. // display: none is required here, see #WP27605
  1195. ?>
  1196. <div id="wp-link-backdrop" style="display: none"></div>
  1197. <div id="wp-link-wrap" class="wp-core-ui<?php echo $search_panel_visible; ?>" style="display: none">
  1198. <form id="wp-link" tabindex="-1">
  1199. <?php wp_nonce_field( 'internal-linking', '_ajax_linking_nonce', false ); ?>
  1200. <div id="link-modal-title">
  1201. <?php _e( 'Insert/edit link' ) ?>
  1202. <button type="button" id="wp-link-close"><span class="screen-reader-text"><?php _e( 'Close' ); ?></span></button>
  1203. </div>
  1204. <div id="link-selector">
  1205. <div id="link-options">
  1206. <p class="howto"><?php _e( 'Enter the destination URL' ); ?></p>
  1207. <div>
  1208. <label><span><?php _e( 'URL' ); ?></span><input id="wp-link-url" type="text" /></label>
  1209. </div>
  1210. <div class="wp-link-text-field">
  1211. <label><span><?php _e( 'Link Text' ); ?></span><input id="wp-link-text" type="text" /></label>
  1212. </div>
  1213. <div class="link-target">
  1214. <label><span>&nbsp;</span><input type="checkbox" id="wp-link-target" /> <?php _e( 'Open link in a new window/tab' ); ?></label>
  1215. </div>
  1216. </div>
  1217. <p class="howto"><a href="#" id="wp-link-search-toggle"><?php _e( 'Or link to existing content' ); ?></a></p>
  1218. <div id="search-panel">
  1219. <div class="link-search-wrapper">
  1220. <label>
  1221. <span class="search-label"><?php _e( 'Search' ); ?></span>
  1222. <input type="search" id="wp-link-search" class="link-search-field" autocomplete="off" />
  1223. <span class="spinner"></span>

Large files files are truncated, but you can click here to view the full file