Make WordPress Core


Ignore:
Timestamp:
09/24/2011 04:43:19 AM (12 years ago)
Author:
azaozz
Message:

Fix wplink when TinyMCE is not loaded, fix image insertion when wpActiveEditor is not set, see #17144

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/class-wp-editor.php

    r18753 r18766  
    11<?php
    22/**
    3  * Adds the TinyMCE editor used on the Write and Edit screens.
     3 * Adds the WordPress editor used on the Write and Edit screens.
    44 *
    55 * @package WordPress
     
    1717    var $qt_settings = array();
    1818    var $plugins = array();
     19    var $qt_buttons = array();
    1920    var $mce_locale;
    2021    var $ext_plugins;
     
    4950            'editor_class' => '', // add extra class(es) to the editor textarea
    5051            'teeny' => false, // output the minimal editor config used in Press This
    51             'dfw' => false, // replace the default fullscreen with DFW (needs specific css)
     52            'dfw' => false, // replace the default fullscreen with DFW (needs specific DOM elements and css)
    5253            'tinymce' => true, // load TinyMCE, can be used to pass settings directly to TinyMCE using an array()
    5354            'quicktags' => true // load Quicktags, can be used to pass settings directly to Quicktags using an array()
     
    6566            $set['media_buttons'] = false;
    6667
    67         if ( $this->can_richedit && $this->this_quicktags && $this->this_tinymce ) {
     68        if ( $this->this_quicktags && $this->this_tinymce ) {
    6869            $switch_class = 'html-active';
    6970
     
    99100        }
    100101
    101         $the_editor = apply_filters('the_editor', '<div id="wp-' . $editor_id . '-editor-container" class="wp-editor-container"><textarea' . $editor_class . $rows . $tabindex . '" cols="40" name="' . $set['textarea_name'] . '" id="' . $editor_id . '">%s</textarea></div>');
     102        $the_editor = apply_filters('the_editor', '<div id="wp-' . $editor_id . '-editor-container" class="wp-editor-container"><textarea' . $editor_class . $rows . $tabindex . ' cols="40" name="' . $set['textarea_name'] . '" id="' . $editor_id . '">%s</textarea></div>');
    102103        $content = apply_filters('the_editor_content', $content);
    103104
     
    115116    }
    116117
    117     function editor_settings($editor_id, $settings) {
     118    function editor_settings($editor_id, $set) {
    118119        global $editor_styles;
    119120        $first_run = false;
    120121
    121122        if ( $this->this_quicktags ) {
    122             $qtbuttons = apply_filters( 'quicktags_buttons', array(), $editor_id );
    123             $qtbuttons_disabled = apply_filters( 'quicktags_disabled_buttons', array(), $editor_id );
     123            $qt_buttons = array();
    124124
    125125            $qtInit = array(
    126126                'id' => $editor_id,
    127                 'buttons' => implode($qtbuttons, ','),
    128                 'disabled_buttons' => implode($qtbuttons_disabled, ',')
     127                'buttons' => '',
     128                'disabled_buttons' => ''
    129129            );
    130130
    131             if ( is_array($settings['quicktags']) )
    132                 $qtInit = array_merge($qtInit, $settings['quicktags']);
     131            if ( is_array($set['quicktags']) )
     132                $qtInit = array_merge($qtInit, $set['quicktags']);
     133
     134            $qtInit = apply_filters( 'quicktags_settings', $qtInit, $editor_id );
    133135
    134136            $this->qt_settings[$editor_id] = $qtInit;
     137
     138            if ( !empty($qtInit['buttons']) || !empty($qtInit['disabled_buttons']) ) {
     139                if ( strpos( ',' . $qtInit['buttons'] . ',', ',link,' ) !== false )
     140                    $qt_buttons[] = 'link';
     141
     142                if ( strpos( ',' . $qtInit['disabled_buttons'] . ',', ',link,' ) !== false )
     143                    $qt_buttons = array();
     144            } else {
     145                $qt_buttons[] = 'link';
     146            }
     147
     148            if ( $set['dfw'] )
     149                $qt_buttons[] = 'fullscreen';
     150
     151            $this->qt_buttons = array_merge( $this->qt_buttons, $qt_buttons );
    135152        }
    136153
     
    144161                $first_run = true;
    145162
    146                 if ( $settings['teeny'] ) {
     163                if ( $set['teeny'] ) {
    147164                    $this->plugins = $plugins = apply_filters( 'teeny_mce_plugins', array('inlinepopups', 'fullscreen', 'wordpress', 'wplink', 'wpdialogs'), $editor_id );
    148165                    $ext_plugins = '';
     
    193210                            $strings = $str1 = $str2 = '';
    194211                            if ( ! in_array($name, $loaded_langs) ) {
    195                                 $path = str_replace( WP_CONTENT_URL, '', $plugurl );
     212                                $path = str_replace( content_url(), '', $plugurl );
    196213                                $path = WP_CONTENT_DIR . $path . '/langs/';
    197214
     
    231248                }
    232249
    233                 if ( $settings['dfw'] )
     250                if ( $set['dfw'] )
    234251                    $plugins[] = 'wpfullscreen';
    235252
     
    326343            }
    327344
    328             if ( $settings['teeny'] ) {
     345            if ( $set['teeny'] ) {
    329346                $mce_buttons = apply_filters( 'teeny_mce_buttons', array('bold', 'italic', 'underline', 'blockquote', 'separator', 'strikethrough', 'bullist', 'numlist', 'justifyleft', 'justifycenter', 'justifyright', 'undo', 'redo', 'link', 'unlink', 'fullscreen'), $editor_id );
    330347                $mce_buttons_2 = $mce_buttons_3 = $mce_buttons_4 = array();
     
    336353            }
    337354
    338             if ( $settings['dfw'] ) {
     355            if ( $set['dfw'] ) {
    339356                function replace_fullscreen(&$val) {
    340357                    if ( $val == 'fullscreen' )
     
    350367            $mceInit = array (
    351368                'elements' => $editor_id,
    352                 'wpautop' => (bool) $settings['wpautop'],
    353                 'remove_linebreaks' => (bool) $settings['wpautop'],
    354                 'apply_source_formatting' => (bool) !$settings['wpautop'],
     369                'wpautop' => (bool) $set['wpautop'],
     370                'remove_linebreaks' => (bool) $set['wpautop'],
     371                'apply_source_formatting' => (bool) !$set['wpautop'],
    355372                'theme_advanced_buttons1' => implode($mce_buttons, ','),
    356373                'theme_advanced_buttons2' => implode($mce_buttons_2, ','),
     
    362379                $mceInit = array_merge($this->first_init, $mceInit);
    363380
    364             if ( is_array($settings['tinymce']) )
    365                 $mceInit = array_merge($mceInit, $settings['tinymce']);
     381            if ( is_array($set['tinymce']) )
     382                $mceInit = array_merge($mceInit, $set['tinymce']);
    366383
    367384            // For people who really REALLY know what they're doing with TinyMCE
     
    369386            // Setting "valid_elements", "invalid_elements" and "extended_valid_elements" can be done through this filter.
    370387            // Best is to use the default cleanup by not specifying valid_elements, as TinyMCE contains full set of XHTML 1.0.
    371             if ( $settings['teeny'] ) {
     388            if ( $set['teeny'] ) {
    372389                $mceInit = apply_filters('teeny_mce_before_init', $mceInit, $editor_id);
    373390            } else {
     
    423440
    424441    function enqueue_scripts() {
    425         wp_enqueue_script('quicktags');
    426442        wp_enqueue_script('word-count');
    427         wp_enqueue_script('wplink');
    428         wp_enqueue_script('editor');
    429443        wp_enqueue_style('editor-buttons');
    430444
    431         wp_enqueue_script('wpdialogs-popup');
    432         wp_enqueue_style('wp-jquery-ui-dialog');
    433 
    434         if ( in_array('wpfullscreen', $this->plugins, true) )
     445        if ( $this->this_tinymce )
     446            wp_enqueue_script('editor');
     447
     448        if ( $this->this_quicktags )
     449            wp_enqueue_script('quicktags');
     450
     451        if ( in_array('wplink', $this->plugins, true) || in_array('link', $this->qt_buttons, true) ) {
     452            wp_enqueue_script('wplink');
     453            wp_enqueue_script('wpdialogs-popup');
     454            wp_enqueue_style('wp-jquery-ui-dialog');
     455        }
     456
     457        if ( in_array('wpfullscreen', $this->plugins, true) || in_array('fullscreen', $this->qt_buttons, true) )
    435458            wp_enqueue_script('wp-fullscreen');
    436459
     
    465488            foreach ( $this->mce_settings as $editor_id => $init ) {
    466489                $options = $this->_parse_init( $init );
    467                 $mceInit .= "'$editor_id':{$options},\n";
    468             }
    469             $mceInit = '{' . trim($mceInit, '\n,') . '}';
     490                $mceInit .= "'$editor_id':{$options},";
     491            }
     492            $mceInit = '{' . trim($mceInit, ',') . '}';
    470493        } else {
    471494            $mceInit = '{}';
     
    475498            foreach ( $this->qt_settings as $editor_id => $init ) {
    476499                $options = $this->_parse_init( $init );
    477                 $qtInit .= "'$editor_id':{$options},\n";
    478             }
    479             $qtInit = '{' . trim($qtInit, '\n,') . '}';
     500                $qtInit .= "'$editor_id':{$options},";
     501            }
     502            $qtInit = '{' . trim($qtInit, ',') . '}';
    480503        } else {
    481504            $qtInit = '{}';
     
    564587<?php
    565588
    566         if ( in_array( 'wplink', $this->plugins, true ) )
     589        if ( in_array('wplink', $this->plugins, true) || in_array('link', $this->qt_buttons, true) )
    567590            $this->wp_link_dialog();
    568591
    569         if ( in_array( 'wpfullscreen', $this->plugins, true ) )
     592        if ( in_array('wpfullscreen', $this->plugins, true) || in_array('fullscreen', $this->qt_buttons, true) )
    570593            $this->wp_fullscreen_html();
    571594
Note: See TracChangeset for help on using the changeset viewer.