]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/class-wp-editor.php
WordPress 4.2
[autoinstalls/wordpress.git] / wp-includes / class-wp-editor.php
index 200031bbdcbce014a4d5c6e2c33daf97a1bc1a0b..ae02621539284d96f90b1064ac9910c2e4d31d06 100644 (file)
@@ -48,7 +48,7 @@ final class _WP_Editors {
         *     @type string     $tabfocus_elements The previous and next element ID to move the focus to
         *                                         when pressing the Tab key in TinyMCE. Defualt ':prev,:next'.
         *     @type string     $editor_css        Intended for extra styles for both Visual and Text editors.
-        *                                         Should include <style> tags, and can use "scoped". Default empty.
+        *                                         Should include `<style>` tags, and can use "scoped". Default empty.
         *     @type string     $editor_class      Extra classes to add to the editor textarea elemen. Default empty.
         *     @type bool       $teeny             Whether to output the minimal editor config. Examples include
         *                                         Press This and the Comment editor. Default false.
@@ -76,20 +76,21 @@ final class _WP_Editors {
                $settings = apply_filters( 'wp_editor_settings', $settings, $editor_id );
 
                $set = wp_parse_args( $settings, array(
-                       'wpautop'           => true,
-                       'media_buttons'     => true,
-                       'default_editor'    => '',
-                       'drag_drop_upload'  => false,
-                       'textarea_name'     => $editor_id,
-                       'textarea_rows'     => 20,
-                       'tabindex'          => '',
-                       'tabfocus_elements' => ':prev,:next',
-                       'editor_css'        => '',
-                       'editor_class'      => '',
-                       'teeny'             => false,
-                       'dfw'               => false,
-                       'tinymce'           => true,
-                       'quicktags'         => true
+                       'wpautop'             => true,
+                       'media_buttons'       => true,
+                       'default_editor'      => '',
+                       'drag_drop_upload'    => false,
+                       'textarea_name'       => $editor_id,
+                       'textarea_rows'       => 20,
+                       'tabindex'            => '',
+                       'tabfocus_elements'   => ':prev,:next',
+                       'editor_css'          => '',
+                       'editor_class'        => '',
+                       'teeny'               => false,
+                       'dfw'                 => false,
+                       '_content_editor_dfw' => false,
+                       'tinymce'             => true,
+                       'quicktags'           => true
                ) );
 
                self::$this_tinymce = ( $set['tinymce'] && user_can_richedit() );
@@ -116,12 +117,6 @@ final class _WP_Editors {
                        // A cookie (set when a user resizes the editor) overrides the height.
                        $cookie = (int) get_user_setting( 'ed_size' );
 
-                       // Upgrade an old TinyMCE cookie if it is still around, and the new one isn't.
-                       if ( ! $cookie && isset( $_COOKIE['TinyMCE_content_size'] ) ) {
-                               parse_str( $_COOKIE['TinyMCE_content_size'], $cookie );
-                               $cookie = $cookie['ch'];
-                       }
-
                        if ( $cookie )
                                $set['editor_height'] = $cookie;
                }
@@ -177,13 +172,13 @@ final class _WP_Editors {
                                $switch_class = 'tmce-active';
                        }
 
-                       $buttons .= '<a id="' . $editor_id . '-html" class="wp-switch-editor switch-html" onclick="switchEditors.switchto(this);">' . _x( 'Text', 'Name for the Text editor tab (formerly HTML)' ) . "</a>\n";
-                       $buttons .= '<a id="' . $editor_id . '-tmce" class="wp-switch-editor switch-tmce" onclick="switchEditors.switchto(this);">' . __('Visual') . "</a>\n";
+                       $buttons .= '<button type="button" id="' . $editor_id . '-tmce" class="wp-switch-editor switch-tmce" onclick="switchEditors.switchto(this);">' . __('Visual') . "</button>\n";
+                       $buttons .= '<button type="button" id="' . $editor_id . '-html" class="wp-switch-editor switch-html" onclick="switchEditors.switchto(this);">' . _x( 'Text', 'Name for the Text editor tab (formerly HTML)' ) . "</button>\n";
                }
 
                $wrap_class = 'wp-core-ui wp-editor-wrap ' . $switch_class;
 
-               if ( $set['dfw'] ) {
+               if ( $set['_content_editor_dfw'] ) {
                        $wrap_class .= ' has-dfw';
                }
 
@@ -249,6 +244,10 @@ final class _WP_Editors {
                self::editor_settings($editor_id, $set);
        }
 
+       /**
+        * @param string $editor_id
+        * @param array  $set
+        */
        public static function editor_settings($editor_id, $set) {
                $first_run = false;
 
@@ -278,6 +277,10 @@ final class _WP_Editors {
                        if ( $set['dfw'] )
                                $qtInit['buttons'] .= ',fullscreen';
 
+                       if ( $set['_content_editor_dfw'] ) {
+                               $qtInit['buttons'] .= ',dfw';
+                       }
+
                        /**
                         * Filter the Quicktags settings.
                         *
@@ -351,6 +354,7 @@ final class _WP_Editors {
                                                'wordpress',
                                                'wpautoresize',
                                                'wpeditimage',
+                                               'wpemoji',
                                                'wpgallery',
                                                'wplink',
                                                'wpdialogs',
@@ -418,7 +422,7 @@ final class _WP_Editors {
                                                        $url = set_url_scheme( $url );
                                                        $mce_external_plugins[ $name ] = $url;
                                                        $plugurl = dirname( $url );
-                                                       $strings = $str1 = $str2 = '';
+                                                       $strings = '';
 
                                                        // Try to load langs/[locale].js and langs/[locale]_dlg.js
                                                        if ( ! in_array( $name, $loaded_langs, true ) ) {
@@ -489,17 +493,19 @@ final class _WP_Editors {
                                        'entities' => '38,amp,60,lt,62,gt',
                                        'entity_encoding' => 'raw',
                                        'keep_styles' => false,
+                                       'cache_suffix' => 'wp-mce-' . $GLOBALS['tinymce_version'],
 
                                        // Limit the preview styles in the menu/toolbar
                                        'preview_styles' => 'font-family font-size font-weight font-style text-decoration text-transform',
 
+                                       'end_container_on_empty_block' => true,
                                        'wpeditimage_disable_captions' => $no_captions,
                                        'wpeditimage_html5_captions' => current_theme_supports( 'html5', 'caption' ),
                                        'plugins' => implode( ',', $plugins ),
                                );
 
                                if ( ! empty( $mce_external_plugins ) ) {
-                                       self::$first_init['external_plugins'] = json_encode( $mce_external_plugins );
+                                       self::$first_init['external_plugins'] = wp_json_encode( $mce_external_plugins );
                                }
 
                                $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
@@ -545,6 +551,15 @@ final class _WP_Editors {
                                $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 );
                                $mce_buttons_2 = $mce_buttons_3 = $mce_buttons_4 = array();
                        } else {
+                               $mce_buttons = array( 'bold', 'italic', 'strikethrough', 'bullist', 'numlist', 'blockquote', 'hr', 'alignleft', 'aligncenter', 'alignright', 'link', 'unlink', 'wp_more', 'spellchecker' );
+
+                               if ( $set['_content_editor_dfw'] ) {
+                                       $mce_buttons[] = 'dfw';
+                               } else {
+                                       $mce_buttons[] = 'fullscreen';
+                               }
+
+                               $mce_buttons[] = 'wp_adv';
 
                                /**
                                 * Filter the first-row list of TinyMCE buttons (Visual tab).
@@ -554,7 +569,13 @@ final class _WP_Editors {
                                 * @param array  $buttons   First-row list of buttons.
                                 * @param string $editor_id Unique editor identifier, e.g. 'content'.
                                 */
-                               $mce_buttons = apply_filters( 'mce_buttons', array('bold', 'italic', 'strikethrough', 'bullist', 'numlist', 'blockquote', 'hr', 'alignleft', 'aligncenter', 'alignright', 'link', 'unlink', 'wp_more', 'spellchecker', 'fullscreen', 'wp_adv' ), $editor_id );
+                               $mce_buttons = apply_filters( 'mce_buttons', $mce_buttons, $editor_id );
+
+                               $mce_buttons_2 = array( 'formatselect', 'underline', 'alignjustify', 'forecolor', 'pastetext', 'removeformat', 'charmap', 'outdent', 'indent', 'undo', 'redo' );
+
+                               if ( ! wp_is_mobile() ) {
+                                       $mce_buttons_2[] = 'wp_help';
+                               }
 
                                /**
                                 * Filter the second-row list of TinyMCE buttons (Visual tab).
@@ -564,7 +585,7 @@ final class _WP_Editors {
                                 * @param array  $buttons   Second-row list of buttons.
                                 * @param string $editor_id Unique editor identifier, e.g. 'content'.
                                 */
-                               $mce_buttons_2 = apply_filters( 'mce_buttons_2', array( 'formatselect', 'underline', 'alignjustify', 'forecolor', 'pastetext', 'removeformat', 'charmap', 'outdent', 'indent', 'undo', 'redo', 'wp_help' ), $editor_id );
+                               $mce_buttons_2 = apply_filters( 'mce_buttons_2', $mce_buttons_2, $editor_id );
 
                                /**
                                 * Filter the third-row list of TinyMCE buttons (Visual tab).
@@ -600,6 +621,8 @@ final class _WP_Editors {
                                }
                        }
 
+                       $body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
+
                        if ( !empty($set['tinymce']['body_class']) ) {
                                $body_class .= ' ' . $set['tinymce']['body_class'];
                                unset($set['tinymce']['body_class']);
@@ -733,7 +756,15 @@ final class _WP_Editors {
                ) );
        }
 
-       public static function wp_mce_translation() {
+       /**
+        * Translates the default TinyMCE strings and returns them as JSON encoded object ready to be loaded with tinymce.addI18n().
+        * Can be used directly (_WP_Editors::wp_mce_translation()) by passing the same locale as set in the TinyMCE init object.
+        *
+        * @param string $mce_locale The locale used for the editor.
+        * @param bool $json_only optional Whether to include the JavaScript calls to tinymce.addI18n() and tinymce.ScriptLoader.markDone().
+        * @return string Translation object, JSON encoded.
+        */
+       public static function wp_mce_translation( $mce_locale = '', $json_only = false ) {
 
                $mce_translation = array(
                        // Default TinyMCE strings
@@ -852,6 +883,11 @@ final class _WP_Editors {
                        'Insert/edit link' => __( 'Insert/edit link' ),
                        'Remove link' => __( 'Remove link' ),
 
+                       'Color' => __( 'Color' ),
+                       'Custom color' => __( 'Custom color' ),
+                       'Custom...' => _x( 'Custom...', 'label for custom color' ),
+                       'No color' => __( 'No color' ),
+
                        // Spelling, search/replace plugins
                        'Could not find the specified string.' => __( 'Could not find the specified string.' ),
                        'Replace' => _x( 'Replace', 'find/replace' ),
@@ -868,6 +904,7 @@ final class _WP_Editors {
                        'Finish' => _x( 'Finish', 'spellcheck' ),
                        'Ignore all' => _x( 'Ignore all', 'spellcheck' ),
                        'Ignore' => _x( 'Ignore', 'spellcheck' ),
+                       'Add to Dictionary' => __( 'Add to Dictionary' ),
 
                        // TinyMCE tables
                        'Insert table' => __( 'Insert table' ),
@@ -875,6 +912,7 @@ final class _WP_Editors {
                        'Table properties' => __( 'Table properties' ),
                        'Row properties' => __( 'Table row properties' ),
                        'Cell properties' => __( 'Table cell properties' ),
+                       'Border color' => __( 'Border color' ),
 
                        'Row' => __( 'Row' ),
                        'Rows' => __( 'Rows' ),
@@ -903,10 +941,15 @@ final class _WP_Editors {
                        'Width' => __( 'Width' ),
                        'Caption' => __( 'Caption' ),
                        'Alignment' => __( 'Alignment' ),
+                       'H Align' => _x( 'H Align', 'horizontal table cell alignment' ),
                        'Left' => __( 'Left' ),
                        'Center' => __( 'Center' ),
                        'Right' => __( 'Right' ),
                        'None' => _x( 'None', 'table cell alignment attribute' ),
+                       'V Align' => _x( 'V Align', 'vertical table cell alignment' ),
+                       'Top' => __( 'Top' ),
+                       'Middle' => __( 'Middle' ),
+                       'Bottom' => __( 'Bottom' ),
 
                        'Row group' => __( 'Row group' ),
                        'Column group' => __( 'Column group' ),
@@ -927,7 +970,7 @@ final class _WP_Editors {
                        /* translators: word count */
                        'Words: {0}' => sprintf( __( 'Words: %s' ), '{0}' ),
                        '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.' ),
-                       'Rich Text Area. Press ALT-F9 for menu. Press ALT-F10 for toolbar. Press ALT-0 for help' => __( 'Rich Text Area. Press ALT-F9 for menu. Press ALT-F10 for toolbar. Press ALT-0 for help' ),
+                       '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' ),
                        '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.' ),
                        '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.' ),
 
@@ -945,7 +988,10 @@ final class _WP_Editors {
                        'Toolbar Toggle' => __( 'Toolbar Toggle' ),
                        'Insert Read More tag' => __( 'Insert Read More tag' ),
                        'Read more...' => __( 'Read more...' ), // Title on the placeholder inside the editor
-                       'Distraction Free Writing' => __( 'Distraction Free Writing' ),
+                       'Distraction-free writing mode' => __( 'Distraction-free writing mode' ),
+                       'No alignment' => __( 'No alignment' ), // Tooltip for the 'alignnone' button in the image toolbar
+                       'Remove' => __( 'Remove' ), // Tooltip for the 'remove' button in the image toolbar
+                       'Edit ' => __( 'Edit' ), // Tooltip for the 'edit' button in the image toolbar
                );
 
                /**
@@ -959,8 +1005,9 @@ final class _WP_Editors {
                 *      Url
                 */
 
-               $baseurl = self::$baseurl;
-               $mce_locale = self::$mce_locale;
+               if ( ! $mce_locale ) {
+                       $mce_locale = self::$mce_locale;
+               }
 
                /**
                 * Filter translated strings prepared for TinyMCE.
@@ -973,6 +1020,12 @@ final class _WP_Editors {
                $mce_translation = apply_filters( 'wp_mce_translation', $mce_translation, $mce_locale );
 
                foreach ( $mce_translation as $key => $value ) {
+                       // Remove strings that are not translated.
+                       if ( $key === $value ) {
+                               unset( $mce_translation[$key] );
+                               continue;
+                       }
+
                        if ( false !== strpos( $value, '&' ) ) {
                                $mce_translation[$key] = html_entity_decode( $value, ENT_QUOTES, 'UTF-8' );
                        }
@@ -983,7 +1036,13 @@ final class _WP_Editors {
                        $mce_translation['_dir'] = 'rtl';
                }
 
-               return "tinymce.addI18n( '$mce_locale', " . json_encode( $mce_translation ) . ");\n" .
+               if ( $json_only ) {
+                       return wp_json_encode( $mce_translation );
+               }
+
+               $baseurl = self::$baseurl ? self::$baseurl : includes_url( 'js/tinymce' );
+
+               return "tinymce.addI18n( '$mce_locale', " . wp_json_encode( $mce_translation ) . ");\n" .
                        "tinymce.ScriptLoader.markDone( '$baseurl/langs/$mce_locale.js' );\n";
        }
 
@@ -1185,7 +1244,7 @@ final class _WP_Editors {
                $width = isset( $content_width ) && 800 > $content_width ? $content_width : 800;
                $width = $width + 22; // compensate for the padding and border
                $dfw_width = get_user_setting( 'dfw_width', $width );
-               $save = isset( $post->post_status ) && $post->post_status == 'publish' ? __('Update') : __('Save');
+               $save = $post && $post->post_status == 'publish' ? __('Update') : __('Save');
 
                ?>
                <div id="wp-fullscreen-body" class="wp-core-ui<?php if ( is_rtl() ) echo ' rtl'; ?>" data-theme-width="<?php echo (int) $width; ?>" data-dfw-width="<?php echo (int) $dfw_width; ?>">
@@ -1219,7 +1278,7 @@ final class _WP_Editors {
 
                /**
                 * Filter the list of TinyMCE buttons for the fullscreen
-                * 'Distraction Free Writing' editor.
+                * 'Distraction-Free Writing' editor.
                 *
                 * @since 3.2.0
                 *
@@ -1250,7 +1309,7 @@ final class _WP_Editors {
 
                <div id="wp-fullscreen-save">
                        <input type="button" class="button button-primary right" value="<?php echo $save; ?>" onclick="wp.editor.fullscreen.save();" />
-                       <span class="wp-fullscreen-saved-message"><?php if ( $post->post_status == 'publish' ) _e('Updated.'); else _e('Saved.'); ?></span>
+                       <span class="wp-fullscreen-saved-message"><?php if ( $post && $post->post_status == 'publish' ) _e('Updated.'); else _e('Saved.'); ?></span>
                        <span class="wp-fullscreen-error-message"><?php _e('Save failed.'); ?></span>
                        <span class="spinner"></span>
                </div>
@@ -1277,7 +1336,7 @@ final class _WP_Editors {
         * @since 3.1.0
         *
         * @param array $args Optional. Accepts 'pagenum' and 's' (search) arguments.
-        * @return array Results.
+        * @return false|array Results.
         */
        public static function wp_link_query( $args = array() ) {
                $pts = get_post_types( array( 'public' => true ), 'objects' );
@@ -1382,13 +1441,13 @@ final class _WP_Editors {
                        <div id="link-options">
                                <p class="howto"><?php _e( 'Enter the destination URL' ); ?></p>
                                <div>
-                                       <label><span><?php _e( 'URL' ); ?></span><input id="url-field" type="text" name="href" /></label>
+                                       <label><span><?php _e( 'URL' ); ?></span><input id="wp-link-url" type="text" /></label>
                                </div>
-                               <div>
-                                       <label><span><?php _e( 'Title' ); ?></span><input id="link-title-field" type="text" name="linktitle" /></label>
+                               <div class="wp-link-text-field">
+                                       <label><span><?php _e( 'Link Text' ); ?></span><input id="wp-link-text" type="text" /></label>
                                </div>
                                <div class="link-target">
-                                       <label><span>&nbsp;</span><input type="checkbox" id="link-target-checkbox" /> <?php _e( 'Open link in a new window/tab' ); ?></label>
+                                       <label><span>&nbsp;</span><input type="checkbox" id="wp-link-target" /> <?php _e( 'Open link in a new window/tab' ); ?></label>
                                </div>
                        </div>
                        <p class="howto"><a href="#" id="wp-link-search-toggle"><?php _e( 'Or link to existing content' ); ?></a></p>
@@ -1396,7 +1455,7 @@ final class _WP_Editors {
                                <div class="link-search-wrapper">
                                        <label>
                                                <span class="search-label"><?php _e( 'Search' ); ?></span>
-                                               <input type="search" id="search-field" class="link-search-field" autocomplete="off" />
+                                               <input type="search" id="wp-link-search" class="link-search-field" autocomplete="off" />
                                                <span class="spinner"></span>
                                        </label>
                                </div>