PageRenderTime 57ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

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

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

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