PageRenderTime 51ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/AFelipeTrujillo/goblog
PHP | 1444 lines | 899 code | 207 blank | 338 comment | 150 complexity | fb209d1794f4d0112aed3e14f713b7a3 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1

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

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