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