]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/class-wp-editor.php
WordPress 4.7-scripts
[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                                 if ( $page_template = get_page_template_slug( $post ) ) {
685                                         $page_template = str_replace( '.', '-', basename( $page_template, '.php' ) );
686                                         $body_class .= ' page-template-' . sanitize_html_class( $page_template );
687                                 }
688                         }
689
690                         $body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_user_locale() ) ) );
691
692                         if ( !empty($set['tinymce']['body_class']) ) {
693                                 $body_class .= ' ' . $set['tinymce']['body_class'];
694                                 unset($set['tinymce']['body_class']);
695                         }
696
697                         $mceInit = array (
698                                 'selector' => "#$editor_id",
699                                 'resize' => 'vertical',
700                                 'menubar' => false,
701                                 'wpautop' => (bool) $set['wpautop'],
702                                 'indent' => ! $set['wpautop'],
703                                 'toolbar1' => implode($mce_buttons, ','),
704                                 'toolbar2' => implode($mce_buttons_2, ','),
705                                 'toolbar3' => implode($mce_buttons_3, ','),
706                                 'toolbar4' => implode($mce_buttons_4, ','),
707                                 'tabfocus_elements' => $set['tabfocus_elements'],
708                                 'body_class' => $body_class
709                         );
710
711                         // Merge with the first part of the init array
712                         $mceInit = array_merge( self::$first_init, $mceInit );
713
714                         if ( is_array( $set['tinymce'] ) )
715                                 $mceInit = array_merge( $mceInit, $set['tinymce'] );
716
717                         /*
718                          * For people who really REALLY know what they're doing with TinyMCE
719                          * You can modify $mceInit to add, remove, change elements of the config
720                          * before tinyMCE.init. Setting "valid_elements", "invalid_elements"
721                          * and "extended_valid_elements" can be done through this filter. Best
722                          * is to use the default cleanup by not specifying valid_elements,
723                          * as TinyMCE checks against the full set of HTML 5.0 elements and attributes.
724                          */
725                         if ( $set['teeny'] ) {
726
727                                 /**
728                                  * Filters the teenyMCE config before init.
729                                  *
730                                  * @since 2.7.0
731                                  *
732                                  * @param array  $mceInit   An array with teenyMCE config.
733                                  * @param string $editor_id Unique editor identifier, e.g. 'content'.
734                                  */
735                                 $mceInit = apply_filters( 'teeny_mce_before_init', $mceInit, $editor_id );
736                         } else {
737
738                                 /**
739                                  * Filters the TinyMCE config before init.
740                                  *
741                                  * @since 2.5.0
742                                  *
743                                  * @param array  $mceInit   An array with TinyMCE config.
744                                  * @param string $editor_id Unique editor identifier, e.g. 'content'.
745                                  */
746                                 $mceInit = apply_filters( 'tiny_mce_before_init', $mceInit, $editor_id );
747                         }
748
749                         if ( empty( $mceInit['toolbar3'] ) && ! empty( $mceInit['toolbar4'] ) ) {
750                                 $mceInit['toolbar3'] = $mceInit['toolbar4'];
751                                 $mceInit['toolbar4'] = '';
752                         }
753
754                         self::$mce_settings[$editor_id] = $mceInit;
755                 } // end if self::$this_tinymce
756         }
757
758         /**
759          *
760          * @static
761          * @param array $init
762          * @return string
763          */
764         private static function _parse_init($init) {
765                 $options = '';
766
767                 foreach ( $init as $k => $v ) {
768                         if ( is_bool($v) ) {
769                                 $val = $v ? 'true' : 'false';
770                                 $options .= $k . ':' . $val . ',';
771                                 continue;
772                         } elseif ( !empty($v) && is_string($v) && ( ('{' == $v{0} && '}' == $v{strlen($v) - 1}) || ('[' == $v{0} && ']' == $v{strlen($v) - 1}) || preg_match('/^\(?function ?\(/', $v) ) ) {
773                                 $options .= $k . ':' . $v . ',';
774                                 continue;
775                         }
776                         $options .= $k . ':"' . $v . '",';
777                 }
778
779                 return '{' . trim( $options, ' ,' ) . '}';
780         }
781
782         /**
783          *
784          * @static
785          */
786         public static function enqueue_scripts() {
787                 if ( self::$has_tinymce )
788                         wp_enqueue_script('editor');
789
790                 if ( self::$has_quicktags ) {
791                         wp_enqueue_script( 'quicktags' );
792                         wp_enqueue_style( 'buttons' );
793                 }
794
795                 if ( in_array('wplink', self::$plugins, true) || in_array('link', self::$qt_buttons, true) ) {
796                         wp_enqueue_script('wplink');
797                         wp_enqueue_script( 'jquery-ui-autocomplete' );
798                 }
799
800                 if ( self::$old_dfw_compat ) {
801                         wp_enqueue_script('wp-fullscreen-stub');
802                 }
803
804                 if ( self::$has_medialib ) {
805                         add_thickbox();
806                         wp_enqueue_script( 'media-upload' );
807                         wp_enqueue_script( 'wp-embed' );
808                 }
809
810                 /**
811                  * Fires when scripts and styles are enqueued for the editor.
812                  *
813                  * @since 3.9.0
814                  *
815                  * @param array $to_load An array containing boolean values whether TinyMCE
816                  *                       and Quicktags are being loaded.
817                  */
818                 do_action( 'wp_enqueue_editor', array(
819                         'tinymce'   => self::$has_tinymce,
820                         'quicktags' => self::$has_quicktags,
821                 ) );
822         }
823
824         private static function get_translation() {
825                 if ( empty( self::$translation ) ) {
826                         self::$translation = array(
827                         // Default TinyMCE strings
828                         'New document' => __( 'New document' ),
829                         'Formats' => _x( 'Formats', 'TinyMCE' ),
830
831                         'Headings' => _x( 'Headings', 'TinyMCE' ),
832                         'Heading 1' => array( __( 'Heading 1' ), 'access1' ),
833                         'Heading 2' => array( __( 'Heading 2' ), 'access2' ),
834                         'Heading 3' => array( __( 'Heading 3' ), 'access3' ),
835                         'Heading 4' => array( __( 'Heading 4' ), 'access4' ),
836                         'Heading 5' => array( __( 'Heading 5' ), 'access5' ),
837                         'Heading 6' => array( __( 'Heading 6' ), 'access6' ),
838
839                         /* translators: block tags */
840                         'Blocks' => _x( 'Blocks', 'TinyMCE' ),
841                         'Paragraph' => array( __( 'Paragraph' ), 'access7' ),
842                         'Blockquote' => array( __( 'Blockquote' ), 'accessQ' ),
843                         'Div' => _x( 'Div', 'HTML tag' ),
844                         'Pre' => _x( 'Pre', 'HTML tag' ),
845                         'Preformatted' => _x( 'Preformatted', 'HTML tag' ),
846                         'Address' => _x( 'Address', 'HTML tag' ),
847
848                         'Inline' => _x( 'Inline', 'HTML elements' ),
849                         'Underline' => array( __( 'Underline' ), 'metaU' ),
850                         'Strikethrough' => array( __( 'Strikethrough' ), 'accessD' ),
851                         'Subscript' => __( 'Subscript' ),
852                         'Superscript' => __( 'Superscript' ),
853                         'Clear formatting' => __( 'Clear formatting' ),
854                         'Bold' => array( __( 'Bold' ), 'metaB' ),
855                         'Italic' => array( __( 'Italic' ), 'metaI' ),
856                         'Code' => array( __( 'Code' ), 'accessX' ),
857                         'Source code' => __( 'Source code' ),
858                         'Font Family' => __( 'Font Family' ),
859                         'Font Sizes' => __( 'Font Sizes' ),
860
861                         'Align center' => array( __( 'Align center' ), 'accessC' ),
862                         'Align right' => array( __( 'Align right' ), 'accessR' ),
863                         'Align left' => array( __( 'Align left' ), 'accessL' ),
864                         'Justify' => array( __( 'Justify' ), 'accessJ' ),
865                         'Increase indent' => __( 'Increase indent' ),
866                         'Decrease indent' => __( 'Decrease indent' ),
867
868                         'Cut' => array( __( 'Cut' ), 'metaX' ),
869                         'Copy' => array( __( 'Copy' ), 'metaC' ),
870                         'Paste' => array( __( 'Paste' ), 'metaV' ),
871                         'Select all' => array( __( 'Select all' ), 'metaA' ),
872                         'Undo' => array( __( 'Undo' ), 'metaZ' ),
873                         'Redo' => array( __( 'Redo' ), 'metaY' ),
874
875                         'Ok' => __( 'OK' ),
876                         'Cancel' => __( 'Cancel' ),
877                         'Close' => __( 'Close' ),
878                         'Visual aids' => __( 'Visual aids' ),
879
880                         'Bullet list' => array( __( 'Bulleted list' ), 'accessU' ),
881                         'Numbered list' => array( __( 'Numbered list' ), 'accessO' ),
882                         'Square' => _x( 'Square', 'list style' ),
883                         'Default' => _x( 'Default', 'list style' ),
884                         'Circle' => _x( 'Circle', 'list style' ),
885                         'Disc' => _x('Disc', 'list style' ),
886                         'Lower Greek' => _x( 'Lower Greek', 'list style' ),
887                         'Lower Alpha' => _x( 'Lower Alpha', 'list style' ),
888                         'Upper Alpha' => _x( 'Upper Alpha', 'list style' ),
889                         'Upper Roman' => _x( 'Upper Roman', 'list style' ),
890                         'Lower Roman' => _x( 'Lower Roman', 'list style' ),
891
892                         // Anchor plugin
893                         'Name' => _x( 'Name', 'Name of link anchor (TinyMCE)' ),
894                         'Anchor' => _x( 'Anchor', 'Link anchor (TinyMCE)' ),
895                         'Anchors' => _x( 'Anchors', 'Link anchors (TinyMCE)' ),
896
897                         // Fullpage plugin
898                         'Document properties' => __( 'Document properties' ),
899                         'Robots' => __( 'Robots' ),
900                         'Title' => __( 'Title' ),
901                         'Keywords' => __( 'Keywords' ),
902                         'Encoding' => __( 'Encoding' ),
903                         'Description' => __( 'Description' ),
904                         'Author' => __( 'Author' ),
905
906                         // Media, image plugins
907                         'Insert/edit image' => array( __( 'Insert/edit image' ), 'accessM' ),
908                         'General' => __( 'General' ),
909                         'Advanced' => __( 'Advanced' ),
910                         'Source' => __( 'Source' ),
911                         'Border' => __( 'Border' ),
912                         'Constrain proportions' => __( 'Constrain proportions' ),
913                         'Vertical space' => __( 'Vertical space' ),
914                         'Image description' => __( 'Image description' ),
915                         'Style' => __( 'Style' ),
916                         'Dimensions' => __( 'Dimensions' ),
917                         'Insert image' => __( 'Insert image' ),
918                         'Insert date/time' => __( 'Insert date/time' ),
919                         'Insert/edit video' => __( 'Insert/edit video' ),
920                         'Poster' => __( 'Poster' ),
921                         'Alternative source' => __( 'Alternative source' ),
922                         'Paste your embed code below:' => __( 'Paste your embed code below:' ),
923                         'Insert video' => __( 'Insert video' ),
924                         'Embed' => __( 'Embed' ),
925
926                         // Each of these have a corresponding plugin
927                         'Special character' => __( 'Special character' ),
928                         'Right to left' => _x( 'Right to left', 'editor button' ),
929                         'Left to right' => _x( 'Left to right', 'editor button' ),
930                         'Emoticons' => __( 'Emoticons' ),
931                         'Nonbreaking space' => __( 'Nonbreaking space' ),
932                         'Page break' => __( 'Page break' ),
933                         'Paste as text' => __( 'Paste as text' ),
934                         'Preview' => __( 'Preview' ),
935                         'Print' => __( 'Print' ),
936                         'Save' => __( 'Save' ),
937                         'Fullscreen' => __( 'Fullscreen' ),
938                         'Horizontal line' => __( 'Horizontal line' ),
939                         'Horizontal space' => __( 'Horizontal space' ),
940                         'Restore last draft' => __( 'Restore last draft' ),
941                         'Insert/edit link' => array( __( 'Insert/edit link' ), 'metaK' ),
942                         'Remove link' => array( __( 'Remove link' ), 'accessS' ),
943
944                         'Color' => __( 'Color' ),
945                         'Custom color' => __( 'Custom color' ),
946                         'Custom...' => _x( 'Custom...', 'label for custom color' ), // no ellipsis
947                         'No color' => __( 'No color' ),
948
949                         // Spelling, search/replace plugins
950                         'Could not find the specified string.' => __( 'Could not find the specified string.' ),
951                         'Replace' => _x( 'Replace', 'find/replace' ),
952                         'Next' => _x( 'Next', 'find/replace' ),
953                         /* translators: previous */
954                         'Prev' => _x( 'Prev', 'find/replace' ),
955                         'Whole words' => _x( 'Whole words', 'find/replace' ),
956                         'Find and replace' => __( 'Find and replace' ),
957                         'Replace with' => _x('Replace with', 'find/replace' ),
958                         'Find' => _x( 'Find', 'find/replace' ),
959                         'Replace all' => _x( 'Replace all', 'find/replace' ),
960                         'Match case' => __( 'Match case' ),
961                         'Spellcheck' => __( 'Check Spelling' ),
962                         'Finish' => _x( 'Finish', 'spellcheck' ),
963                         'Ignore all' => _x( 'Ignore all', 'spellcheck' ),
964                         'Ignore' => _x( 'Ignore', 'spellcheck' ),
965                         'Add to Dictionary' => __( 'Add to Dictionary' ),
966
967                         // TinyMCE tables
968                         'Insert table' => __( 'Insert table' ),
969                         'Delete table' => __( 'Delete table' ),
970                         'Table properties' => __( 'Table properties' ),
971                         'Row properties' => __( 'Table row properties' ),
972                         'Cell properties' => __( 'Table cell properties' ),
973                         'Border color' => __( 'Border color' ),
974
975                         'Row' => __( 'Row' ),
976                         'Rows' => __( 'Rows' ),
977                         'Column' => _x( 'Column', 'table column' ),
978                         'Cols' => _x( 'Cols', 'table columns' ),
979                         'Cell' => _x( 'Cell', 'table cell' ),
980                         'Header cell' => __( 'Header cell' ),
981                         'Header' => _x( 'Header', 'table header' ),
982                         'Body' => _x( 'Body', 'table body' ),
983                         'Footer' => _x( 'Footer', 'table footer' ),
984
985                         'Insert row before' => __( 'Insert row before' ),
986                         'Insert row after' => __( 'Insert row after' ),
987                         'Insert column before' => __( 'Insert column before' ),
988                         'Insert column after' => __( 'Insert column after' ),
989                         'Paste row before' => __( 'Paste table row before' ),
990                         'Paste row after' => __( 'Paste table row after' ),
991                         'Delete row' => __( 'Delete row' ),
992                         'Delete column' => __( 'Delete column' ),
993                         'Cut row' => __( 'Cut table row' ),
994                         'Copy row' => __( 'Copy table row' ),
995                         'Merge cells' => __( 'Merge table cells' ),
996                         'Split cell' => __( 'Split table cell' ),
997
998                         'Height' => __( 'Height' ),
999                         'Width' => __( 'Width' ),
1000                         'Caption' => __( 'Caption' ),
1001                         'Alignment' => __( 'Alignment' ),
1002                         'H Align' => _x( 'H Align', 'horizontal table cell alignment' ),
1003                         'Left' => __( 'Left' ),
1004                         'Center' => __( 'Center' ),
1005                         'Right' => __( 'Right' ),
1006                         'None' => _x( 'None', 'table cell alignment attribute' ),
1007                         'V Align' => _x( 'V Align', 'vertical table cell alignment' ),
1008                         'Top' => __( 'Top' ),
1009                         'Middle' => __( 'Middle' ),
1010                         'Bottom' => __( 'Bottom' ),
1011
1012                         'Row group' => __( 'Row group' ),
1013                         'Column group' => __( 'Column group' ),
1014                         'Row type' => __( 'Row type' ),
1015                         'Cell type' => __( 'Cell type' ),
1016                         'Cell padding' => __( 'Cell padding' ),
1017                         'Cell spacing' => __( 'Cell spacing' ),
1018                         'Scope' => _x( 'Scope', 'table cell scope attribute' ),
1019
1020                         'Insert template' => _x( 'Insert template', 'TinyMCE' ),
1021                         'Templates' => _x( 'Templates', 'TinyMCE' ),
1022
1023                         'Background color' => __( 'Background color' ),
1024                         'Text color' => __( 'Text color' ),
1025                         'Show blocks' => _x( 'Show blocks', 'editor button' ),
1026                         'Show invisible characters' => __( 'Show invisible characters' ),
1027
1028                         /* translators: word count */
1029                         'Words: {0}' => sprintf( __( 'Words: %s' ), '{0}' ),
1030                         '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.' ),
1031                         '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.' ),
1032                         'Rich Text Area. Press Control-Option-H for help.' => __( 'Rich Text Area. Press Control-Option-H for help.' ),
1033                         '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.' ),
1034                         '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.' ),
1035
1036                         // TinyMCE menus
1037                         'Insert' => _x( 'Insert', 'TinyMCE menu' ),
1038                         'File' => _x( 'File', 'TinyMCE menu' ),
1039                         'Edit' => _x( 'Edit', 'TinyMCE menu' ),
1040                         'Tools' => _x( 'Tools', 'TinyMCE menu' ),
1041                         'View' => _x( 'View', 'TinyMCE menu' ),
1042                         'Table' => _x( 'Table', 'TinyMCE menu' ),
1043                         'Format' => _x( 'Format', 'TinyMCE menu' ),
1044
1045                         // WordPress strings
1046                         'Toolbar Toggle' => array( __( 'Toolbar Toggle' ), 'accessZ' ),
1047                         'Insert Read More tag' => array( __( 'Insert Read More tag' ), 'accessT' ),
1048                         'Insert Page Break tag' => array( __( 'Insert Page Break tag' ), 'accessP' ),
1049                         'Read more...' => __( 'Read more...' ), // Title on the placeholder inside the editor (no ellipsis)
1050                         'Distraction-free writing mode' => array( __( 'Distraction-free writing mode' ), 'accessW' ),
1051                         'No alignment' => __( 'No alignment' ), // Tooltip for the 'alignnone' button in the image toolbar
1052                         'Remove' => __( 'Remove' ), // Tooltip for the 'remove' button in the image toolbar
1053                         'Edit ' => __( 'Edit' ), // Tooltip for the 'edit' button in the image toolbar
1054                         'Paste URL or type to search' => __( 'Paste URL or type to search' ), // Placeholder for the inline link dialog
1055                         'Apply'  => __( 'Apply' ), // Tooltip for the 'apply' button in the inline link dialog
1056                         'Link options'  => __( 'Link options' ), // Tooltip for the 'link options' button in the inline link dialog
1057
1058                         // Shortcuts help modal
1059                         'Keyboard Shortcuts' => array( __( 'Keyboard Shortcuts' ), 'accessH' ),
1060                         'Default shortcuts,' => __( 'Default shortcuts,' ),
1061                         'Additional shortcuts,' => __( 'Additional shortcuts,' ),
1062                         'Focus shortcuts:' => __( 'Focus shortcuts:' ),
1063                         'Inline toolbar (when an image, link or preview is selected)' => __( 'Inline toolbar (when an image, link or preview is selected)' ),
1064                         'Editor menu (when enabled)' => __( 'Editor menu (when enabled)' ),
1065                         'Editor toolbar' => __( 'Editor toolbar' ),
1066                         'Elements path' => __( 'Elements path' ),
1067                         'Ctrl + Alt + letter:' => __( 'Ctrl + Alt + letter:' ),
1068                         'Shift + Alt + letter:' => __( 'Shift + Alt + letter:' ),
1069                         'Cmd + letter:' => __( 'Cmd + letter:' ),
1070                         'Ctrl + letter:' => __( 'Ctrl + letter:' ),
1071                         'Letter' => __( 'Letter' ),
1072                         'Action' => __( 'Action' ),
1073                         '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.' ),
1074                         '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.' =>
1075                                 __( '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.' ),
1076                         '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.' =>
1077                                 __( '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.' ),
1078                         'The following formatting shortcuts are replaced when pressing Enter. Press Escape or the Undo button to undo.' =>
1079                                 __( 'The following formatting shortcuts are replaced when pressing Enter. Press Escape or the Undo button to undo.' ),
1080                         '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.' =>
1081                                 __( '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.' ),
1082                         );
1083                 }
1084
1085                 /**
1086                  * Link plugin (not included):
1087                  *      Insert link
1088                  *      Target
1089                  *      New window
1090                  *      Text to display
1091                  *      The URL you entered seems to be an email address. Do you want to add the required mailto: prefix?
1092                  *      The URL you entered seems to be an external link. Do you want to add the required http:\/\/ prefix?
1093                  *      Url
1094                  */
1095
1096                 return self::$translation;
1097         }
1098
1099         /**
1100          * Translates the default TinyMCE strings and returns them as JSON encoded object ready to be loaded with tinymce.addI18n().
1101          * Can be used directly (_WP_Editors::wp_mce_translation()) by passing the same locale as set in the TinyMCE init object.
1102          *
1103          * @static
1104          * @param string $mce_locale The locale used for the editor.
1105          * @param bool $json_only optional Whether to include the JavaScript calls to tinymce.addI18n() and tinymce.ScriptLoader.markDone().
1106          * @return string Translation object, JSON encoded.
1107          */
1108         public static function wp_mce_translation( $mce_locale = '', $json_only = false ) {
1109                 if ( ! $mce_locale ) {
1110                         $mce_locale = self::$mce_locale;
1111                 }
1112
1113                 $mce_translation = self::get_translation();
1114                 
1115                 foreach ( $mce_translation as $name => $value ) {
1116                         if ( is_array( $value ) ) {
1117                                 $mce_translation[$name] = $value[0];
1118                         }
1119                 }
1120
1121                 /**
1122                  * Filters translated strings prepared for TinyMCE.
1123                  *
1124                  * @since 3.9.0
1125                  *
1126                  * @param array  $mce_translation Key/value pairs of strings.
1127                  * @param string $mce_locale      Locale.
1128                  */
1129                 $mce_translation = apply_filters( 'wp_mce_translation', $mce_translation, $mce_locale );
1130
1131                 foreach ( $mce_translation as $key => $value ) {
1132                         // Remove strings that are not translated.
1133                         if ( $key === $value ) {
1134                                 unset( $mce_translation[$key] );
1135                                 continue;
1136                         }
1137
1138                         if ( false !== strpos( $value, '&' ) ) {
1139                                 $mce_translation[$key] = html_entity_decode( $value, ENT_QUOTES, 'UTF-8' );
1140                         }
1141                 }
1142
1143                 // Set direction
1144                 if ( is_rtl() ) {
1145                         $mce_translation['_dir'] = 'rtl';
1146                 }
1147
1148                 if ( $json_only ) {
1149                         return wp_json_encode( $mce_translation );
1150                 }
1151
1152                 $baseurl = self::$baseurl ? self::$baseurl : includes_url( 'js/tinymce' );
1153
1154                 return "tinymce.addI18n( '$mce_locale', " . wp_json_encode( $mce_translation ) . ");\n" .
1155                         "tinymce.ScriptLoader.markDone( '$baseurl/langs/$mce_locale.js' );\n";
1156         }
1157
1158         /**
1159          *
1160          * @static
1161          * @global string $tinymce_version
1162          * @global bool   $concatenate_scripts
1163          * @global bool   $compress_scripts
1164          */
1165         public static function editor_js() {
1166                 global $tinymce_version, $concatenate_scripts, $compress_scripts;
1167
1168                 /**
1169                  * Filters "tiny_mce_version" is deprecated
1170                  *
1171                  * The tiny_mce_version filter is not needed since external plugins are loaded directly by TinyMCE.
1172                  * These plugins can be refreshed by appending query string to the URL passed to "mce_external_plugins" filter.
1173                  * 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).
1174                  */
1175                 $version = 'ver=' . $tinymce_version;
1176                 $tmce_on = !empty(self::$mce_settings);
1177
1178                 if ( ! isset($concatenate_scripts) )
1179                         script_concat_settings();
1180
1181                 $compressed = $compress_scripts && $concatenate_scripts && isset($_SERVER['HTTP_ACCEPT_ENCODING'])
1182                         && false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip');
1183
1184                 $mceInit = $qtInit = '';
1185                 if ( $tmce_on ) {
1186                         foreach ( self::$mce_settings as $editor_id => $init ) {
1187                                 $options = self::_parse_init( $init );
1188                                 $mceInit .= "'$editor_id':{$options},";
1189                         }
1190                         $mceInit = '{' . trim($mceInit, ',') . '}';
1191                 } else {
1192                         $mceInit = '{}';
1193                 }
1194
1195                 if ( !empty(self::$qt_settings) ) {
1196                         foreach ( self::$qt_settings as $editor_id => $init ) {
1197                                 $options = self::_parse_init( $init );
1198                                 $qtInit .= "'$editor_id':{$options},";
1199                         }
1200                         $qtInit = '{' . trim($qtInit, ',') . '}';
1201                 } else {
1202                         $qtInit = '{}';
1203                 }
1204
1205                 $ref = array(
1206                         'plugins' => implode( ',', self::$plugins ),
1207                         'theme' => 'modern',
1208                         'language' => self::$mce_locale
1209                 );
1210
1211                 $suffix = SCRIPT_DEBUG ? '' : '.min';
1212
1213                 /**
1214                  * Fires immediately before the TinyMCE settings are printed.
1215                  *
1216                  * @since 3.2.0
1217                  *
1218                  * @param array $mce_settings TinyMCE settings array.
1219                  */
1220                 do_action( 'before_wp_tiny_mce', self::$mce_settings );
1221                 ?>
1222
1223                 <script type="text/javascript">
1224                 tinyMCEPreInit = {
1225                         baseURL: "<?php echo self::$baseurl; ?>",
1226                         suffix: "<?php echo $suffix; ?>",
1227                         <?php
1228
1229                         if ( self::$drag_drop_upload ) {
1230                                 echo 'dragDropUpload: true,';
1231                         }
1232
1233                         ?>
1234                         mceInit: <?php echo $mceInit; ?>,
1235                         qtInit: <?php echo $qtInit; ?>,
1236                         ref: <?php echo self::_parse_init( $ref ); ?>,
1237                         load_ext: function(url,lang){var sl=tinymce.ScriptLoader;sl.markDone(url+'/langs/'+lang+'.js');sl.markDone(url+'/langs/'+lang+'_dlg.js');}
1238                 };
1239                 </script>
1240                 <?php
1241
1242                 $baseurl = self::$baseurl;
1243                 // Load tinymce.js when running from /src, else load wp-tinymce.js.gz (production) or tinymce.min.js (SCRIPT_DEBUG)
1244                 $mce_suffix = false !== strpos( get_bloginfo( 'version' ), '-src' ) ? '' : '.min';
1245
1246                 if ( $tmce_on ) {
1247                         if ( $compressed ) {
1248                                 echo "<script type='text/javascript' src='{$baseurl}/wp-tinymce.php?c=1&amp;$version'></script>\n";
1249                         } else {
1250                                 echo "<script type='text/javascript' src='{$baseurl}/tinymce{$mce_suffix}.js?$version'></script>\n";
1251                                 echo "<script type='text/javascript' src='{$baseurl}/plugins/compat3x/plugin{$suffix}.js?$version'></script>\n";
1252                         }
1253
1254                         echo "<script type='text/javascript'>\n" . self::wp_mce_translation() . "</script>\n";
1255
1256                         if ( self::$ext_plugins ) {
1257                                 // Load the old-format English strings to prevent unsightly labels in old style popups
1258                                 echo "<script type='text/javascript' src='{$baseurl}/langs/wp-langs-en.js?$version'></script>\n";
1259                         }
1260                 }
1261
1262                 /**
1263                  * Fires after tinymce.js is loaded, but before any TinyMCE editor
1264                  * instances are created.
1265                  *
1266                  * @since 3.9.0
1267                  *
1268                  * @param array $mce_settings TinyMCE settings array.
1269                  */
1270                 do_action( 'wp_tiny_mce_init', self::$mce_settings );
1271
1272                 ?>
1273                 <script type="text/javascript">
1274                 <?php
1275
1276                 if ( self::$ext_plugins )
1277                         echo self::$ext_plugins . "\n";
1278
1279                 if ( ! is_admin() )
1280                         echo 'var ajaxurl = "' . admin_url( 'admin-ajax.php', 'relative' ) . '";';
1281
1282                 ?>
1283
1284                 ( function() {
1285                         var init, id, $wrap;
1286
1287                         if ( typeof tinymce !== 'undefined' ) {
1288                                 for ( id in tinyMCEPreInit.mceInit ) {
1289                                         init = tinyMCEPreInit.mceInit[id];
1290                                         $wrap = tinymce.$( '#wp-' + id + '-wrap' );
1291
1292                                         if ( ( $wrap.hasClass( 'tmce-active' ) || ! tinyMCEPreInit.qtInit.hasOwnProperty( id ) ) && ! init.wp_skip_init ) {
1293                                                 tinymce.init( init );
1294
1295                                                 if ( ! window.wpActiveEditor ) {
1296                                                         window.wpActiveEditor = id;
1297                                                 }
1298                                         }
1299                                 }
1300                         }
1301
1302                         if ( typeof quicktags !== 'undefined' ) {
1303                                 for ( id in tinyMCEPreInit.qtInit ) {
1304                                         quicktags( tinyMCEPreInit.qtInit[id] );
1305
1306                                         if ( ! window.wpActiveEditor ) {
1307                                                 window.wpActiveEditor = id;
1308                                         }
1309                                 }
1310                         }
1311                 }());
1312                 </script>
1313                 <?php
1314
1315                 if ( in_array( 'wplink', self::$plugins, true ) || in_array( 'link', self::$qt_buttons, true ) ) {
1316                         self::wp_link_dialog();
1317                 }
1318
1319                 /**
1320                  * Fires after any core TinyMCE editor instances are created.
1321                  *
1322                  * @since 3.2.0
1323                  *
1324                  * @param array $mce_settings TinyMCE settings array.
1325                  */
1326                 do_action( 'after_wp_tiny_mce', self::$mce_settings );
1327         }
1328
1329         /**
1330          *
1331          * @static
1332          * @global int $content_width
1333          */
1334         public static function wp_fullscreen_html() {
1335                 _deprecated_function( __FUNCTION__, '4.3.0' );
1336         }
1337
1338         /**
1339          * Performs post queries for internal linking.
1340          *
1341          * @since 3.1.0
1342          *
1343          * @static
1344          * @param array $args Optional. Accepts 'pagenum' and 's' (search) arguments.
1345          * @return false|array Results.
1346          */
1347         public static function wp_link_query( $args = array() ) {
1348                 $pts = get_post_types( array( 'public' => true ), 'objects' );
1349                 $pt_names = array_keys( $pts );
1350
1351                 $query = array(
1352                         'post_type' => $pt_names,
1353                         'suppress_filters' => true,
1354                         'update_post_term_cache' => false,
1355                         'update_post_meta_cache' => false,
1356                         'post_status' => 'publish',
1357                         'posts_per_page' => 20,
1358                 );
1359
1360                 $args['pagenum'] = isset( $args['pagenum'] ) ? absint( $args['pagenum'] ) : 1;
1361
1362                 if ( isset( $args['s'] ) )
1363                         $query['s'] = $args['s'];
1364
1365                 $query['offset'] = $args['pagenum'] > 1 ? $query['posts_per_page'] * ( $args['pagenum'] - 1 ) : 0;
1366
1367                 /**
1368                  * Filters the link query arguments.
1369                  *
1370                  * Allows modification of the link query arguments before querying.
1371                  *
1372                  * @see WP_Query for a full list of arguments
1373                  *
1374                  * @since 3.7.0
1375                  *
1376                  * @param array $query An array of WP_Query arguments.
1377                  */
1378                 $query = apply_filters( 'wp_link_query_args', $query );
1379
1380                 // Do main query.
1381                 $get_posts = new WP_Query;
1382                 $posts = $get_posts->query( $query );
1383                 // Check if any posts were found.
1384                 if ( ! $get_posts->post_count )
1385                         return false;
1386
1387                 // Build results.
1388                 $results = array();
1389                 foreach ( $posts as $post ) {
1390                         if ( 'post' == $post->post_type )
1391                                 $info = mysql2date( __( 'Y/m/d' ), $post->post_date );
1392                         else
1393                                 $info = $pts[ $post->post_type ]->labels->singular_name;
1394
1395                         $results[] = array(
1396                                 'ID' => $post->ID,
1397                                 'title' => trim( esc_html( strip_tags( get_the_title( $post ) ) ) ),
1398                                 'permalink' => get_permalink( $post->ID ),
1399                                 'info' => $info,
1400                         );
1401                 }
1402
1403                 /**
1404                  * Filters the link query results.
1405                  *
1406                  * Allows modification of the returned link query results.
1407                  *
1408                  * @since 3.7.0
1409                  *
1410                  * @see 'wp_link_query_args' filter
1411                  *
1412                  * @param array $results {
1413                  *     An associative array of query results.
1414                  *
1415                  *     @type array {
1416                  *         @type int    $ID        Post ID.
1417                  *         @type string $title     The trimmed, escaped post title.
1418                  *         @type string $permalink Post permalink.
1419                  *         @type string $info      A 'Y/m/d'-formatted date for 'post' post type,
1420                  *                                 the 'singular_name' post type label otherwise.
1421                  *     }
1422                  * }
1423                  * @param array $query  An array of WP_Query arguments.
1424                  */
1425                 return apply_filters( 'wp_link_query', $results, $query );
1426         }
1427
1428         /**
1429          * Dialog for internal linking.
1430          *
1431          * @since 3.1.0
1432          *
1433          * @static
1434          */
1435         public static function wp_link_dialog() {
1436                 // display: none is required here, see #WP27605
1437                 ?>
1438                 <div id="wp-link-backdrop" style="display: none"></div>
1439                 <div id="wp-link-wrap" class="wp-core-ui" style="display: none" role="dialog" aria-labelledby="link-modal-title">
1440                 <form id="wp-link" tabindex="-1">
1441                 <?php wp_nonce_field( 'internal-linking', '_ajax_linking_nonce', false ); ?>
1442                 <h1 id="link-modal-title"><?php _e( 'Insert/edit link' ) ?></h1>
1443                 <button type="button" id="wp-link-close"><span class="screen-reader-text"><?php _e( 'Close' ); ?></span></button>
1444                 <div id="link-selector">
1445                         <div id="link-options">
1446                                 <p class="howto" id="wplink-enter-url"><?php _e( 'Enter the destination URL' ); ?></p>
1447                                 <div>
1448                                         <label><span><?php _e( 'URL' ); ?></span>
1449                                         <input id="wp-link-url" type="text" aria-describedby="wplink-enter-url" /></label>
1450                                 </div>
1451                                 <div class="wp-link-text-field">
1452                                         <label><span><?php _e( 'Link Text' ); ?></span>
1453                                         <input id="wp-link-text" type="text" /></label>
1454                                 </div>
1455                                 <div class="link-target">
1456                                         <label><span></span>
1457                                         <input type="checkbox" id="wp-link-target" /> <?php _e( 'Open link in a new tab' ); ?></label>
1458                                 </div>
1459                         </div>
1460                         <p class="howto" id="wplink-link-existing-content"><?php _e( 'Or link to existing content' ); ?></p>
1461                         <div id="search-panel">
1462                                 <div class="link-search-wrapper">
1463                                         <label>
1464                                                 <span class="search-label"><?php _e( 'Search' ); ?></span>
1465                                                 <input type="search" id="wp-link-search" class="link-search-field" autocomplete="off" aria-describedby="wplink-link-existing-content" />
1466                                                 <span class="spinner"></span>
1467                                         </label>
1468                                 </div>
1469                                 <div id="search-results" class="query-results" tabindex="0">
1470                                         <ul></ul>
1471                                         <div class="river-waiting">
1472                                                 <span class="spinner"></span>
1473                                         </div>
1474                                 </div>
1475                                 <div id="most-recent-results" class="query-results" tabindex="0">
1476                                         <div class="query-notice" id="query-notice-message">
1477                                                 <em class="query-notice-default"><?php _e( 'No search term specified. Showing recent items.' ); ?></em>
1478                                                 <em class="query-notice-hint screen-reader-text"><?php _e( 'Search or use up and down arrow keys to select an item.' ); ?></em>
1479                                         </div>
1480                                         <ul></ul>
1481                                         <div class="river-waiting">
1482                                                 <span class="spinner"></span>
1483                                         </div>
1484                                 </div>
1485                         </div>
1486                 </div>
1487                 <div class="submitbox">
1488                         <div id="wp-link-cancel">
1489                                 <button type="button" class="button"><?php _e( 'Cancel' ); ?></button>
1490                         </div>
1491                         <div id="wp-link-update">
1492                                 <input type="submit" value="<?php esc_attr_e( 'Add Link' ); ?>" class="button button-primary" id="wp-link-submit" name="wp-link-submit">
1493                         </div>
1494                 </div>
1495                 </form>
1496                 </div>
1497                 <?php
1498         }
1499 }