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