home *** CD-ROM | disk | FTP | other *** search
/ HTML Examples / WP.iso / wordpress / wp-includes / class-wp-editor.php < prev    next >
Encoding:
PHP Script  |  2017-10-18  |  59.2 KB  |  1,752 lines

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