PageRenderTime 48ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/opehei/wordpress-trunk
PHP | 859 lines | 637 code | 145 blank | 77 comment | 149 complexity | 0ef4af5ca99e450b1a307438eb5d8668 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.1, GPL-2.0
  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 function __construct() {}
  26. public static function parse_settings($editor_id, $settings) {
  27. $set = wp_parse_args( $settings, array(
  28. 'wpautop' => true, // use wpautop?
  29. 'media_buttons' => true, // show insert/upload button(s)
  30. 'textarea_name' => $editor_id, // set the textarea name to something different, square brackets [] can be used here
  31. 'textarea_rows' => 20,
  32. 'tabindex' => '',
  33. 'tabfocus_elements' => ':prev,:next', // the previous and next element ID to move the focus to when pressing the Tab key in TinyMCE
  34. 'editor_css' => '', // intended for extra styles for both visual and Text editors buttons, needs to include the <style> tags, can use "scoped".
  35. 'editor_class' => '', // add extra class(es) to the editor textarea
  36. 'teeny' => false, // output the minimal editor config used in Press This
  37. 'dfw' => false, // replace the default fullscreen with DFW (needs specific DOM elements and css)
  38. 'tinymce' => true, // load TinyMCE, can be used to pass settings directly to TinyMCE using an array()
  39. 'quicktags' => true // load Quicktags, can be used to pass settings directly to Quicktags using an array()
  40. ) );
  41. self::$this_tinymce = ( $set['tinymce'] && user_can_richedit() );
  42. self::$this_quicktags = (bool) $set['quicktags'];
  43. if ( self::$this_tinymce )
  44. self::$has_tinymce = true;
  45. if ( self::$this_quicktags )
  46. self::$has_quicktags = true;
  47. if ( empty( $set['editor_height'] ) )
  48. return $set;
  49. if ( 'content' === $editor_id ) {
  50. // A cookie (set when a user resizes the editor) overrides the height.
  51. $cookie = (int) get_user_setting( 'ed_size' );
  52. // Upgrade an old TinyMCE cookie if it is still around, and the new one isn't.
  53. if ( ! $cookie && isset( $_COOKIE['TinyMCE_content_size'] ) ) {
  54. parse_str( $_COOKIE['TinyMCE_content_size'], $cookie );
  55. $cookie = $cookie['ch'];
  56. }
  57. if ( $cookie )
  58. $set['editor_height'] = $cookie;
  59. }
  60. if ( $set['editor_height'] < 50 )
  61. $set['editor_height'] = 50;
  62. return $set;
  63. }
  64. /**
  65. * Outputs the HTML for a single instance of the editor.
  66. *
  67. * @param string $content The initial content of the editor.
  68. * @param string $editor_id ID for the textarea and TinyMCE and Quicktags instances (can contain only ASCII letters and numbers).
  69. * @param array $settings See the _parse_settings() method for description.
  70. */
  71. public static function editor( $content, $editor_id, $settings = array() ) {
  72. $set = self::parse_settings($editor_id, $settings);
  73. $editor_class = ' class="' . trim( $set['editor_class'] . ' wp-editor-area' ) . '"';
  74. $tabindex = $set['tabindex'] ? ' tabindex="' . (int) $set['tabindex'] . '"' : '';
  75. $switch_class = 'html-active';
  76. $toolbar = $buttons = '';
  77. if ( ! empty( $set['editor_height'] ) )
  78. $height = ' style="height: ' . $set['editor_height'] . 'px"';
  79. else
  80. $height = ' rows="' . $set['textarea_rows'] . '"';
  81. if ( !current_user_can( 'upload_files' ) )
  82. $set['media_buttons'] = false;
  83. if ( self::$this_quicktags && self::$this_tinymce ) {
  84. $switch_class = 'html-active';
  85. // 'html' and 'switch-html' are used for the "Text" editor tab.
  86. if ( 'html' == wp_default_editor() ) {
  87. add_filter('the_editor_content', 'wp_htmledit_pre');
  88. } else {
  89. add_filter('the_editor_content', 'wp_richedit_pre');
  90. $switch_class = 'tmce-active';
  91. }
  92. $buttons .= '<a id="' . $editor_id . '-html" class="hide-if-no-js wp-switch-editor switch-html" onclick="switchEditors.switchto(this);">' . __('Text') . "</a>\n";
  93. $buttons .= '<a id="' . $editor_id . '-tmce" class="hide-if-no-js wp-switch-editor switch-tmce" onclick="switchEditors.switchto(this);">' . __('Visual') . "</a>\n";
  94. }
  95. echo '<div id="wp-' . $editor_id . '-wrap" class="wp-editor-wrap ' . $switch_class . '">';
  96. if ( self::$editor_buttons_css ) {
  97. wp_print_styles('editor-buttons');
  98. self::$editor_buttons_css = false;
  99. }
  100. if ( !empty($set['editor_css']) )
  101. echo $set['editor_css'] . "\n";
  102. if ( !empty($buttons) || $set['media_buttons'] ) {
  103. echo '<div id="wp-' . $editor_id . '-editor-tools" class="wp-editor-tools">';
  104. echo $buttons;
  105. if ( $set['media_buttons'] ) {
  106. self::$has_medialib = true;
  107. if ( !function_exists('media_buttons') )
  108. include(ABSPATH . 'wp-admin/includes/media.php');
  109. echo '<div id="wp-' . $editor_id . '-media-buttons" class="hide-if-no-js wp-media-buttons">';
  110. do_action('media_buttons', $editor_id);
  111. echo "</div>\n";
  112. }
  113. echo "</div>\n";
  114. }
  115. $the_editor = apply_filters('the_editor', '<div id="wp-' . $editor_id . '-editor-container" class="wp-editor-container"><textarea' . $editor_class . $height . $tabindex . ' cols="40" name="' . $set['textarea_name'] . '" id="' . $editor_id . '">%s</textarea></div>');
  116. $content = apply_filters('the_editor_content', $content);
  117. printf($the_editor, $content);
  118. echo "\n</div>\n\n";
  119. self::editor_settings($editor_id, $set);
  120. }
  121. public static function editor_settings($editor_id, $set) {
  122. global $editor_styles;
  123. $first_run = false;
  124. if ( empty(self::$first_init) ) {
  125. if ( is_admin() ) {
  126. add_action( 'admin_print_footer_scripts', array( __CLASS__, 'editor_js'), 50 );
  127. add_action( 'admin_footer', array( __CLASS__, 'enqueue_scripts'), 1 );
  128. } else {
  129. add_action( 'wp_print_footer_scripts', array( __CLASS__, 'editor_js'), 50 );
  130. add_action( 'wp_footer', array( __CLASS__, 'enqueue_scripts'), 1 );
  131. }
  132. }
  133. if ( self::$this_quicktags ) {
  134. $qtInit = array(
  135. 'id' => $editor_id,
  136. 'buttons' => ''
  137. );
  138. if ( is_array($set['quicktags']) )
  139. $qtInit = array_merge($qtInit, $set['quicktags']);
  140. if ( empty($qtInit['buttons']) )
  141. $qtInit['buttons'] = 'strong,em,link,block,del,ins,img,ul,ol,li,code,more,spell,close';
  142. if ( $set['dfw'] )
  143. $qtInit['buttons'] .= ',fullscreen';
  144. $qtInit = apply_filters('quicktags_settings', $qtInit, $editor_id);
  145. self::$qt_settings[$editor_id] = $qtInit;
  146. self::$qt_buttons = array_merge( self::$qt_buttons, explode(',', $qtInit['buttons']) );
  147. }
  148. if ( self::$this_tinymce ) {
  149. if ( empty(self::$first_init) ) {
  150. self::$baseurl = includes_url('js/tinymce');
  151. self::$mce_locale = $mce_locale = ( '' == get_locale() ) ? 'en' : strtolower( substr(get_locale(), 0, 2) ); // only ISO 639-1
  152. $no_captions = (bool) apply_filters( 'disable_captions', '' );
  153. $plugins = array( 'inlinepopups', 'spellchecker', 'tabfocus', 'paste', 'media', 'fullscreen', 'wordpress', 'wplink', 'wpdialogs', 'wpview' );
  154. $first_run = true;
  155. $ext_plugins = '';
  156. if ( $set['teeny'] ) {
  157. self::$plugins = $plugins = apply_filters( 'teeny_mce_plugins', array('inlinepopups', 'fullscreen', 'wordpress', 'wplink', 'wpdialogs', 'wpview'), $editor_id );
  158. } else {
  159. /*
  160. The following filter takes an associative array of external plugins for TinyMCE in the form 'plugin_name' => 'url'.
  161. It adds the plugin's name to TinyMCE's plugins init and the call to PluginManager to load the plugin.
  162. The url should be absolute and should include the js file name to be loaded. Example:
  163. array( 'myplugin' => 'http://my-site.com/wp-content/plugins/myfolder/mce_plugin.js' )
  164. If the plugin uses a button, it should be added with one of the "$mce_buttons" filters.
  165. */
  166. $mce_external_plugins = apply_filters('mce_external_plugins', array());
  167. if ( ! empty($mce_external_plugins) ) {
  168. /*
  169. The following filter loads external language files for TinyMCE plugins.
  170. It takes an associative array 'plugin_name' => 'path', where path is the
  171. include path to the file. The language file should follow the same format as
  172. /tinymce/langs/wp-langs.php and should define a variable $strings that
  173. holds all translated strings.
  174. When this filter is not used, the function will try to load {mce_locale}.js.
  175. If that is not found, en.js will be tried next.
  176. */
  177. $mce_external_languages = apply_filters('mce_external_languages', array());
  178. $loaded_langs = array();
  179. $strings = '';
  180. if ( ! empty($mce_external_languages) ) {
  181. foreach ( $mce_external_languages as $name => $path ) {
  182. if ( @is_file($path) && @is_readable($path) ) {
  183. include_once($path);
  184. $ext_plugins .= $strings . "\n";
  185. $loaded_langs[] = $name;
  186. }
  187. }
  188. }
  189. foreach ( $mce_external_plugins as $name => $url ) {
  190. $url = set_url_scheme( $url );
  191. $plugins[] = '-' . $name;
  192. $plugurl = dirname($url);
  193. $strings = $str1 = $str2 = '';
  194. if ( ! in_array($name, $loaded_langs) ) {
  195. $path = str_replace( content_url(), '', $plugurl );
  196. $path = WP_CONTENT_DIR . $path . '/langs/';
  197. if ( function_exists('realpath') )
  198. $path = trailingslashit( realpath($path) );
  199. if ( @is_file($path . $mce_locale . '.js') )
  200. $strings .= @file_get_contents($path . $mce_locale . '.js') . "\n";
  201. if ( @is_file($path . $mce_locale . '_dlg.js') )
  202. $strings .= @file_get_contents($path . $mce_locale . '_dlg.js') . "\n";
  203. if ( 'en' != $mce_locale && empty($strings) ) {
  204. if ( @is_file($path . 'en.js') ) {
  205. $str1 = @file_get_contents($path . 'en.js');
  206. $strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.', $str1, 1 ) . "\n";
  207. }
  208. if ( @is_file($path . 'en_dlg.js') ) {
  209. $str2 = @file_get_contents($path . 'en_dlg.js');
  210. $strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.', $str2, 1 ) . "\n";
  211. }
  212. }
  213. if ( ! empty($strings) )
  214. $ext_plugins .= "\n" . $strings . "\n";
  215. }
  216. $ext_plugins .= 'tinyMCEPreInit.load_ext("' . $plugurl . '", "' . $mce_locale . '");' . "\n";
  217. $ext_plugins .= 'tinymce.PluginManager.load("' . $name . '", "' . $url . '");' . "\n";
  218. }
  219. }
  220. $plugins = array_unique( apply_filters('tiny_mce_plugins', $plugins) );
  221. }
  222. if ( $set['dfw'] )
  223. $plugins[] = 'wpfullscreen';
  224. self::$plugins = $plugins;
  225. self::$ext_plugins = $ext_plugins;
  226. /*
  227. translators: These languages show up in the spellchecker drop-down menu, in the order specified, and with the first
  228. language listed being the default language. They must be comma-separated and take the format of name=code, where name
  229. is the language name (which you may internationalize), and code is a valid ISO 639 language code. Please test the
  230. spellchecker with your values.
  231. */
  232. $mce_spellchecker_languages = __( 'English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr,German=de,Italian=it,Polish=pl,Portuguese=pt,Spanish=es,Swedish=sv' );
  233. /*
  234. The following filter allows localization scripts to change the languages displayed in the spellchecker's drop-down menu.
  235. By default it uses Google's spellchecker API, but can be configured to use PSpell/ASpell if installed on the server.
  236. The + sign marks the default language. More: http://www.tinymce.com/wiki.php/Plugin:spellchecker.
  237. */
  238. $mce_spellchecker_languages = apply_filters( 'mce_spellchecker_languages', '+' . $mce_spellchecker_languages );
  239. self::$first_init = array(
  240. 'mode' => 'exact',
  241. 'width' => '100%',
  242. 'theme' => 'advanced',
  243. 'skin' => 'wp_theme',
  244. 'language' => self::$mce_locale,
  245. 'spellchecker_languages' => $mce_spellchecker_languages,
  246. 'theme_advanced_toolbar_location' => 'top',
  247. 'theme_advanced_toolbar_align' => 'left',
  248. 'theme_advanced_statusbar_location' => 'bottom',
  249. 'theme_advanced_resizing' => true,
  250. 'theme_advanced_resize_horizontal' => false,
  251. 'dialog_type' => 'modal',
  252. 'formats' => "{
  253. alignleft : [
  254. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'left'}},
  255. {selector : 'img,table', classes : 'alignleft'}
  256. ],
  257. aligncenter : [
  258. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'center'}},
  259. {selector : 'img,table', classes : 'aligncenter'}
  260. ],
  261. alignright : [
  262. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'right'}},
  263. {selector : 'img,table', classes : 'alignright'}
  264. ],
  265. strikethrough : {inline : 'del'}
  266. }",
  267. 'relative_urls' => false,
  268. 'remove_script_host' => false,
  269. 'convert_urls' => false,
  270. 'remove_linebreaks' => true,
  271. 'gecko_spellcheck' => true,
  272. 'fix_list_elements' => true,
  273. 'keep_styles' => false,
  274. 'entities' => '38,amp,60,lt,62,gt',
  275. 'accessibility_focus' => true,
  276. 'media_strict' => false,
  277. 'paste_remove_styles' => true,
  278. 'paste_remove_spans' => true,
  279. 'paste_strip_class_attributes' => 'all',
  280. 'paste_text_use_dialog' => true,
  281. 'webkit_fake_resize' => false,
  282. 'spellchecker_rpc_url' => self::$baseurl . '/plugins/spellchecker/rpc.php',
  283. 'schema' => 'html5',
  284. 'wpeditimage_disable_captions' => $no_captions,
  285. 'wp_fullscreen_content_css' => self::$baseurl . '/plugins/wpfullscreen/css/wp-fullscreen.css',
  286. 'plugins' => implode( ',', $plugins )
  287. );
  288. // load editor_style.css if the current theme supports it
  289. if ( ! empty( $editor_styles ) && is_array( $editor_styles ) ) {
  290. $mce_css = array();
  291. $editor_styles = array_unique($editor_styles);
  292. $style_uri = get_stylesheet_directory_uri();
  293. $style_dir = get_stylesheet_directory();
  294. if ( is_child_theme() ) {
  295. $template_uri = get_template_directory_uri();
  296. $template_dir = get_template_directory();
  297. foreach ( $editor_styles as $key => $file ) {
  298. if ( $file && file_exists( "$template_dir/$file" ) )
  299. $mce_css[] = "$template_uri/$file";
  300. }
  301. }
  302. foreach ( $editor_styles as $file ) {
  303. if ( $file && file_exists( "$style_dir/$file" ) )
  304. $mce_css[] = "$style_uri/$file";
  305. }
  306. $mce_css = implode( ',', $mce_css );
  307. } else {
  308. $mce_css = '';
  309. }
  310. $mce_css = trim( apply_filters( 'mce_css', $mce_css ), ' ,' );
  311. if ( ! empty($mce_css) )
  312. self::$first_init['content_css'] = $mce_css;
  313. }
  314. if ( $set['teeny'] ) {
  315. $mce_buttons = apply_filters( 'teeny_mce_buttons', array('bold', 'italic', 'underline', 'blockquote', 'strikethrough', 'bullist', 'numlist', 'justifyleft', 'justifycenter', 'justifyright', 'undo', 'redo', 'link', 'unlink', 'fullscreen'), $editor_id );
  316. $mce_buttons_2 = $mce_buttons_3 = $mce_buttons_4 = array();
  317. } else {
  318. $mce_buttons = apply_filters('mce_buttons', array('bold', 'italic', 'strikethrough', 'bullist', 'numlist', 'blockquote', 'justifyleft', 'justifycenter', 'justifyright', 'link', 'unlink', 'wp_more', 'spellchecker', 'fullscreen', 'wp_adv' ), $editor_id);
  319. $mce_buttons_2 = apply_filters('mce_buttons_2', array( 'formatselect', 'underline', 'justifyfull', 'forecolor', 'pastetext', 'pasteword', 'removeformat', 'charmap', 'outdent', 'indent', 'undo', 'redo', 'wp_help' ), $editor_id);
  320. $mce_buttons_3 = apply_filters('mce_buttons_3', array(), $editor_id);
  321. $mce_buttons_4 = apply_filters('mce_buttons_4', array(), $editor_id);
  322. }
  323. $body_class = $editor_id;
  324. if ( $post = get_post() )
  325. $body_class .= ' post-type-' . $post->post_type;
  326. if ( !empty($set['tinymce']['body_class']) ) {
  327. $body_class .= ' ' . $set['tinymce']['body_class'];
  328. unset($set['tinymce']['body_class']);
  329. }
  330. if ( $set['dfw'] ) {
  331. // replace the first 'fullscreen' with 'wp_fullscreen'
  332. if ( ($key = array_search('fullscreen', $mce_buttons)) !== false )
  333. $mce_buttons[$key] = 'wp_fullscreen';
  334. elseif ( ($key = array_search('fullscreen', $mce_buttons_2)) !== false )
  335. $mce_buttons_2[$key] = 'wp_fullscreen';
  336. elseif ( ($key = array_search('fullscreen', $mce_buttons_3)) !== false )
  337. $mce_buttons_3[$key] = 'wp_fullscreen';
  338. elseif ( ($key = array_search('fullscreen', $mce_buttons_4)) !== false )
  339. $mce_buttons_4[$key] = 'wp_fullscreen';
  340. }
  341. $mceInit = array (
  342. 'elements' => $editor_id,
  343. 'wpautop' => (bool) $set['wpautop'],
  344. 'remove_linebreaks' => (bool) $set['wpautop'],
  345. 'apply_source_formatting' => (bool) !$set['wpautop'],
  346. 'theme_advanced_buttons1' => implode($mce_buttons, ','),
  347. 'theme_advanced_buttons2' => implode($mce_buttons_2, ','),
  348. 'theme_advanced_buttons3' => implode($mce_buttons_3, ','),
  349. 'theme_advanced_buttons4' => implode($mce_buttons_4, ','),
  350. 'tabfocus_elements' => $set['tabfocus_elements'],
  351. 'body_class' => $body_class
  352. );
  353. // The main editor doesn't use the TinyMCE resizing cookie.
  354. $mceInit['theme_advanced_resizing_use_cookie'] = 'content' !== $editor_id || empty( $set['editor_height'] );
  355. if ( $first_run )
  356. $mceInit = array_merge(self::$first_init, $mceInit);
  357. if ( is_array($set['tinymce']) )
  358. $mceInit = array_merge($mceInit, $set['tinymce']);
  359. // For people who really REALLY know what they're doing with TinyMCE
  360. // You can modify initArray to add, remove, change elements of the config before tinyMCE.init
  361. // Setting "valid_elements", "invalid_elements" and "extended_valid_elements" can be done through this filter.
  362. // Best is to use the default cleanup by not specifying valid_elements, as TinyMCE contains full set of XHTML 1.0.
  363. if ( $set['teeny'] ) {
  364. $mceInit = apply_filters('teeny_mce_before_init', $mceInit, $editor_id);
  365. } else {
  366. $mceInit = apply_filters('tiny_mce_before_init', $mceInit, $editor_id);
  367. }
  368. if ( empty($mceInit['theme_advanced_buttons3']) && !empty($mceInit['theme_advanced_buttons4']) ) {
  369. $mceInit['theme_advanced_buttons3'] = $mceInit['theme_advanced_buttons4'];
  370. $mceInit['theme_advanced_buttons4'] = '';
  371. }
  372. self::$mce_settings[$editor_id] = $mceInit;
  373. } // end if self::$this_tinymce
  374. }
  375. private static function _parse_init($init) {
  376. $options = '';
  377. foreach ( $init as $k => $v ) {
  378. if ( is_bool($v) ) {
  379. $val = $v ? 'true' : 'false';
  380. $options .= $k . ':' . $val . ',';
  381. continue;
  382. } elseif ( !empty($v) && is_string($v) && ( ('{' == $v{0} && '}' == $v{strlen($v) - 1}) || ('[' == $v{0} && ']' == $v{strlen($v) - 1}) || preg_match('/^\(?function ?\(/', $v) ) ) {
  383. $options .= $k . ':' . $v . ',';
  384. continue;
  385. }
  386. $options .= $k . ':"' . $v . '",';
  387. }
  388. return '{' . trim( $options, ' ,' ) . '}';
  389. }
  390. public static function enqueue_scripts() {
  391. wp_enqueue_script('word-count');
  392. if ( self::$has_tinymce )
  393. wp_enqueue_script('editor');
  394. if ( self::$has_quicktags )
  395. wp_enqueue_script('quicktags');
  396. if ( in_array('wplink', self::$plugins, true) || in_array('link', self::$qt_buttons, true) ) {
  397. wp_enqueue_script('wplink');
  398. wp_enqueue_script('wpdialogs-popup');
  399. wp_enqueue_style('wp-jquery-ui-dialog');
  400. }
  401. if ( in_array('wpfullscreen', self::$plugins, true) || in_array('fullscreen', self::$qt_buttons, true) )
  402. wp_enqueue_script('wp-fullscreen');
  403. if ( self::$has_medialib ) {
  404. add_thickbox();
  405. wp_enqueue_script('media-upload');
  406. }
  407. }
  408. public static function editor_js() {
  409. global $tinymce_version, $concatenate_scripts, $compress_scripts;
  410. /**
  411. * Filter "tiny_mce_version" is deprecated
  412. *
  413. * The tiny_mce_version filter is not needed since external plugins are loaded directly by TinyMCE.
  414. * These plugins can be refreshed by appending query string to the URL passed to "mce_external_plugins" filter.
  415. * 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).
  416. */
  417. $version = 'ver=' . $tinymce_version;
  418. $tmce_on = !empty(self::$mce_settings);
  419. if ( ! isset($concatenate_scripts) )
  420. script_concat_settings();
  421. $compressed = $compress_scripts && $concatenate_scripts && isset($_SERVER['HTTP_ACCEPT_ENCODING'])
  422. && false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip');
  423. if ( $tmce_on && 'en' != self::$mce_locale )
  424. include_once(ABSPATH . WPINC . '/js/tinymce/langs/wp-langs.php');
  425. $mceInit = $qtInit = '';
  426. if ( $tmce_on ) {
  427. foreach ( self::$mce_settings as $editor_id => $init ) {
  428. $options = self::_parse_init( $init );
  429. $mceInit .= "'$editor_id':{$options},";
  430. }
  431. $mceInit = '{' . trim($mceInit, ',') . '}';
  432. } else {
  433. $mceInit = '{}';
  434. }
  435. if ( !empty(self::$qt_settings) ) {
  436. foreach ( self::$qt_settings as $editor_id => $init ) {
  437. $options = self::_parse_init( $init );
  438. $qtInit .= "'$editor_id':{$options},";
  439. }
  440. $qtInit = '{' . trim($qtInit, ',') . '}';
  441. } else {
  442. $qtInit = '{}';
  443. }
  444. $ref = array(
  445. 'plugins' => implode( ',', self::$plugins ),
  446. 'theme' => 'advanced',
  447. 'language' => self::$mce_locale
  448. );
  449. $suffix = ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) ? '_src' : '';
  450. do_action('before_wp_tiny_mce', self::$mce_settings);
  451. ?>
  452. <script type="text/javascript">
  453. tinyMCEPreInit = {
  454. base : "<?php echo self::$baseurl; ?>",
  455. suffix : "<?php echo $suffix; ?>",
  456. query : "<?php echo $version; ?>",
  457. mceInit : <?php echo $mceInit; ?>,
  458. qtInit : <?php echo $qtInit; ?>,
  459. ref : <?php echo self::_parse_init( $ref ); ?>,
  460. load_ext : function(url,lang){var sl=tinymce.ScriptLoader;sl.markDone(url+'/langs/'+lang+'.js');sl.markDone(url+'/langs/'+lang+'_dlg.js');}
  461. };
  462. </script>
  463. <?php
  464. $baseurl = self::$baseurl;
  465. if ( $tmce_on ) {
  466. if ( $compressed )
  467. echo "<script type='text/javascript' src='{$baseurl}/wp-tinymce.php?c=1&amp;$version'></script>\n";
  468. else
  469. echo "<script type='text/javascript' src='{$baseurl}/tiny_mce.js?$version'></script>\n";
  470. if ( 'en' != self::$mce_locale && isset($lang) )
  471. echo "<script type='text/javascript'>\n$lang\n</script>\n";
  472. else
  473. echo "<script type='text/javascript' src='{$baseurl}/langs/wp-langs-en.js?$version'></script>\n";
  474. }
  475. $mce = ( self::$has_tinymce && wp_default_editor() == 'tinymce' ) || ! self::$has_quicktags;
  476. ?>
  477. <script type="text/javascript">
  478. var wpActiveEditor;
  479. (function(){
  480. var init, ed, qt, first_init, DOM, el, i, mce = <?php echo (int) $mce; ?>;
  481. if ( typeof(tinymce) == 'object' ) {
  482. DOM = tinymce.DOM;
  483. // mark wp_theme/ui.css as loaded
  484. DOM.files[tinymce.baseURI.getURI() + '/themes/advanced/skins/wp_theme/ui.css'] = true;
  485. DOM.events.add( DOM.select('.wp-editor-wrap'), 'mousedown', function(e){
  486. if ( this.id )
  487. wpActiveEditor = this.id.slice(3, -5);
  488. });
  489. for ( ed in tinyMCEPreInit.mceInit ) {
  490. if ( first_init ) {
  491. init = tinyMCEPreInit.mceInit[ed] = tinymce.extend( {}, first_init, tinyMCEPreInit.mceInit[ed] );
  492. } else {
  493. init = first_init = tinyMCEPreInit.mceInit[ed];
  494. }
  495. if ( mce )
  496. try { tinymce.init(init); } catch(e){}
  497. }
  498. } else {
  499. if ( tinyMCEPreInit.qtInit ) {
  500. for ( i in tinyMCEPreInit.qtInit ) {
  501. el = tinyMCEPreInit.qtInit[i].id;
  502. if ( el )
  503. document.getElementById('wp-'+el+'-wrap').onmousedown = function(){ wpActiveEditor = this.id.slice(3, -5); }
  504. }
  505. }
  506. }
  507. if ( typeof(QTags) == 'function' ) {
  508. for ( qt in tinyMCEPreInit.qtInit ) {
  509. try { quicktags( tinyMCEPreInit.qtInit[qt] ); } catch(e){}
  510. }
  511. }
  512. })();
  513. <?php
  514. if ( self::$ext_plugins )
  515. echo self::$ext_plugins . "\n";
  516. if ( ! $compressed && $tmce_on ) {
  517. ?>
  518. (function(){var t=tinyMCEPreInit,sl=tinymce.ScriptLoader,ln=t.ref.language,th=t.ref.theme,pl=t.ref.plugins;sl.markDone(t.base+'/langs/'+ln+'.js');sl.markDone(t.base+'/themes/'+th+'/langs/'+ln+'.js');sl.markDone(t.base+'/themes/'+th+'/langs/'+ln+'_dlg.js');sl.markDone(t.base+'/themes/advanced/skins/wp_theme/ui.css');tinymce.each(pl.split(','),function(n){if(n&&n.charAt(0)!='-'){sl.markDone(t.base+'/plugins/'+n+'/langs/'+ln+'.js');sl.markDone(t.base+'/plugins/'+n+'/langs/'+ln+'_dlg.js');}});})();
  519. <?php
  520. }
  521. if ( !is_admin() )
  522. echo 'var ajaxurl = "' . admin_url( 'admin-ajax.php', 'relative' ) . '";';
  523. ?>
  524. </script>
  525. <?php
  526. if ( in_array('wplink', self::$plugins, true) || in_array('link', self::$qt_buttons, true) )
  527. self::wp_link_dialog();
  528. if ( in_array('wpfullscreen', self::$plugins, true) || in_array('fullscreen', self::$qt_buttons, true) )
  529. self::wp_fullscreen_html();
  530. do_action('after_wp_tiny_mce', self::$mce_settings);
  531. }
  532. public static function wp_fullscreen_html() {
  533. global $content_width;
  534. $post = get_post();
  535. $width = isset($content_width) && 800 > $content_width ? $content_width : 800;
  536. $width = $width + 22; // compensate for the padding and border
  537. $dfw_width = get_user_setting( 'dfw_width', $width );
  538. $save = isset($post->post_status) && $post->post_status == 'publish' ? __('Update') : __('Save');
  539. ?>
  540. <div id="wp-fullscreen-body"<?php if ( is_rtl() ) echo ' class="rtl"'; ?>>
  541. <div id="fullscreen-topbar">
  542. <div id="wp-fullscreen-toolbar">
  543. <div id="wp-fullscreen-close"><a href="#" onclick="fullscreen.off();return false;"><?php _e('Exit fullscreen'); ?></a></div>
  544. <div id="wp-fullscreen-central-toolbar" style="width:<?php echo $width; ?>px;">
  545. <div id="wp-fullscreen-mode-bar"><div id="wp-fullscreen-modes">
  546. <a href="#" onclick="fullscreen.switchmode('tinymce');return false;"><?php _e( 'Visual' ); ?></a>
  547. <a href="#" onclick="fullscreen.switchmode('html');return false;"><?php _ex( 'Text', 'Name for the Text editor tab (formerly HTML)' ); ?></a>
  548. </div></div>
  549. <div id="wp-fullscreen-button-bar"><div id="wp-fullscreen-buttons" class="wp_themeSkin">
  550. <?php
  551. $buttons = array(
  552. // format: title, onclick, show in both editors
  553. 'bold' => array( 'title' => __('Bold (Ctrl + B)'), 'onclick' => 'fullscreen.b();', 'both' => false ),
  554. 'italic' => array( 'title' => __('Italic (Ctrl + I)'), 'onclick' => 'fullscreen.i();', 'both' => false ),
  555. '0' => 'separator',
  556. 'bullist' => array( 'title' => __('Unordered list (Alt + Shift + U)'), 'onclick' => 'fullscreen.ul();', 'both' => false ),
  557. 'numlist' => array( 'title' => __('Ordered list (Alt + Shift + O)'), 'onclick' => 'fullscreen.ol();', 'both' => false ),
  558. '1' => 'separator',
  559. 'blockquote' => array( 'title' => __('Blockquote (Alt + Shift + Q)'), 'onclick' => 'fullscreen.blockquote();', 'both' => false ),
  560. 'image' => array( 'title' => __('Insert/edit image (Alt + Shift + M)'), 'onclick' => "fullscreen.medialib();", 'both' => true ),
  561. '2' => 'separator',
  562. 'link' => array( 'title' => __('Insert/edit link (Alt + Shift + A)'), 'onclick' => 'fullscreen.link();', 'both' => true ),
  563. 'unlink' => array( 'title' => __('Unlink (Alt + Shift + S)'), 'onclick' => 'fullscreen.unlink();', 'both' => false ),
  564. '3' => 'separator',
  565. 'help' => array( 'title' => __('Help (Alt + Shift + H)'), 'onclick' => 'fullscreen.help();', 'both' => false )
  566. );
  567. $buttons = apply_filters( 'wp_fullscreen_buttons', $buttons );
  568. foreach ( $buttons as $button => $args ) {
  569. if ( 'separator' == $args ) { ?>
  570. <div><span aria-orientation="vertical" role="separator" class="mceSeparator"></span></div>
  571. <?php continue;
  572. } ?>
  573. <div<?php if ( $args['both'] ) { ?> class="wp-fullscreen-both"<?php } ?>>
  574. <a title="<?php echo $args['title']; ?>" onclick="<?php echo $args['onclick']; ?>return false;" class="mceButton mceButtonEnabled mce_<?php echo $button; ?>" href="#" id="wp_fs_<?php echo $button; ?>" role="button" aria-pressed="false">
  575. <span class="mceIcon mce_<?php echo $button; ?>"></span>
  576. </a>
  577. </div>
  578. <?php
  579. } ?>
  580. </div></div>
  581. <div id="wp-fullscreen-save">
  582. <input type="button" class="button-primary right" value="<?php echo $save; ?>" onclick="fullscreen.save();" />
  583. <span class="spinner"></span>
  584. <span class="fs-saved"><?php if ( $post->post_status == 'publish' ) _e('Updated.'); else _e('Saved.'); ?></span>
  585. </div>
  586. </div>
  587. </div>
  588. </div>
  589. <div id="wp-fullscreen-wrap" style="width:<?php echo $dfw_width; ?>px;">
  590. <?php if ( post_type_supports($post->post_type, 'title') ) { ?>
  591. <label id="wp-fullscreen-title-prompt-text" for="wp-fullscreen-title"><?php echo apply_filters( 'enter_title_here', __( 'Enter title here' ), $post ); ?></label>
  592. <input type="text" id="wp-fullscreen-title" value="" autocomplete="off" />
  593. <?php } ?>
  594. <div id="wp-fullscreen-container">
  595. <textarea id="wp_mce_fullscreen"></textarea>
  596. </div>
  597. <div id="wp-fullscreen-status">
  598. <div id="wp-fullscreen-count"><?php printf( __( 'Word count: %s' ), '<span class="word-count">0</span>' ); ?></div>
  599. <div id="wp-fullscreen-tagline"><?php _e('Just write.'); ?></div>
  600. </div>
  601. </div>
  602. </div>
  603. <div class="fullscreen-overlay" id="fullscreen-overlay"></div>
  604. <div class="fullscreen-overlay fullscreen-fader fade-600" id="fullscreen-fader"></div>
  605. <?php
  606. }
  607. /**
  608. * Performs post queries for internal linking.
  609. *
  610. * @since 3.1.0
  611. *
  612. * @param array $args Optional. Accepts 'pagenum' and 's' (search) arguments.
  613. * @return array Results.
  614. */
  615. public static function wp_link_query( $args = array() ) {
  616. $pts = get_post_types( array( 'public' => true ), 'objects' );
  617. $pt_names = array_keys( $pts );
  618. $query = array(
  619. 'post_type' => $pt_names,
  620. 'suppress_filters' => true,
  621. 'update_post_term_cache' => false,
  622. 'update_post_meta_cache' => false,
  623. 'post_status' => 'publish',
  624. 'order' => 'DESC',
  625. 'orderby' => 'post_date',
  626. 'posts_per_page' => 20,
  627. );
  628. $args['pagenum'] = isset( $args['pagenum'] ) ? absint( $args['pagenum'] ) : 1;
  629. if ( isset( $args['s'] ) )
  630. $query['s'] = $args['s'];
  631. $query['offset'] = $args['pagenum'] > 1 ? $query['posts_per_page'] * ( $args['pagenum'] - 1 ) : 0;
  632. // Do main query.
  633. $get_posts = new WP_Query;
  634. $posts = $get_posts->query( $query );
  635. // Check if any posts were found.
  636. if ( ! $get_posts->post_count )
  637. return false;
  638. // Build results.
  639. $results = array();
  640. foreach ( $posts as $post ) {
  641. if ( 'post' == $post->post_type )
  642. $info = mysql2date( __( 'Y/m/d' ), $post->post_date );
  643. else
  644. $info = $pts[ $post->post_type ]->labels->singular_name;
  645. $results[] = array(
  646. 'ID' => $post->ID,
  647. 'title' => trim( esc_html( strip_tags( get_the_title( $post ) ) ) ),
  648. 'permalink' => get_permalink( $post->ID ),
  649. 'info' => $info,
  650. );
  651. }
  652. return $results;
  653. }
  654. /**
  655. * Dialog for internal linking.
  656. *
  657. * @since 3.1.0
  658. */
  659. public static function wp_link_dialog() {
  660. ?>
  661. <div style="display:none;">
  662. <form id="wp-link" tabindex="-1">
  663. <?php wp_nonce_field( 'internal-linking', '_ajax_linking_nonce', false ); ?>
  664. <div id="link-selector">
  665. <div id="link-options">
  666. <p class="howto"><?php _e( 'Enter the destination URL' ); ?></p>
  667. <div>
  668. <label><span><?php _e( 'URL' ); ?></span><input id="url-field" type="text" name="href" /></label>
  669. </div>
  670. <div>
  671. <label><span><?php _e( 'Title' ); ?></span><input id="link-title-field" type="text" name="linktitle" /></label>
  672. </div>
  673. <div class="link-target">
  674. <label><input type="checkbox" id="link-target-checkbox" /> <?php _e( 'Open link in a new window/tab' ); ?></label>
  675. </div>
  676. </div>
  677. <?php $show_internal = '1' == get_user_setting( 'wplink', '0' ); ?>
  678. <p class="howto toggle-arrow <?php if ( $show_internal ) echo 'toggle-arrow-active'; ?>" id="internal-toggle"><?php _e( 'Or link to existing content' ); ?></p>
  679. <div id="search-panel"<?php if ( ! $show_internal ) echo ' style="display:none"'; ?>>
  680. <div class="link-search-wrapper">
  681. <label>
  682. <span class="search-label"><?php _e( 'Search' ); ?></span>
  683. <input type="search" id="search-field" class="link-search-field" autocomplete="off" />
  684. <span class="spinner"></span>
  685. </label>
  686. </div>
  687. <div id="search-results" class="query-results">
  688. <ul></ul>
  689. <div class="river-waiting">
  690. <span class="spinner"></span>
  691. </div>
  692. </div>
  693. <div id="most-recent-results" class="query-results">
  694. <div class="query-notice"><em><?php _e( 'No search term specified. Showing recent items.' ); ?></em></div>
  695. <ul></ul>
  696. <div class="river-waiting">
  697. <span class="spinner"></span>
  698. </div>
  699. </div>
  700. </div>
  701. </div>
  702. <div class="submitbox">
  703. <div id="wp-link-update">
  704. <input type="submit" value="<?php esc_attr_e( 'Add Link' ); ?>" class="button-primary" id="wp-link-submit" name="wp-link-submit">
  705. </div>
  706. <div id="wp-link-cancel">
  707. <a class="submitdelete deletion" href="#"><?php _e( 'Cancel' ); ?></a>
  708. </div>
  709. </div>
  710. </form>
  711. </div>
  712. <?php
  713. }
  714. }