Move WP_Editor to a _WP_Editors encapsulation.

* WP_Editor will return in 3.4 as a one true API for editor instances. Stick to wp_editor() for now.
 * TinyMCE can now be forced on with tinymce = true. It defaults to the value for user_can_richedit().
 * Restores wp_default_editor(), wp_link_query(), wp_link_dialog(), wp_fullscreen_html().
fixes #19320.


git-svn-id: http://svn.automattic.com/wordpress/trunk@19420 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin 2011-11-23 19:06:52 +00:00
parent 689dade993
commit a7c296dd47
6 changed files with 137 additions and 180 deletions

View File

@ -1127,7 +1127,7 @@ case 'wp-link-ajax':
$args['pagenum'] = ! empty( $_POST['page'] ) ? absint( $_POST['page'] ) : 1; $args['pagenum'] = ! empty( $_POST['page'] ) ? absint( $_POST['page'] ) : 1;
require(ABSPATH . WPINC . '/class-wp-editor.php'); require(ABSPATH . WPINC . '/class-wp-editor.php');
$results = WP_Editor::wp_link_query( $args ); $results = _WP_Editors::wp_link_query( $args );
if ( ! isset( $results ) ) if ( ! isset( $results ) )
die( '0' ); die( '0' );

View File

@ -711,18 +711,12 @@ function wp_dashboard_quick_press_output() {
function wp_tiny_mce( $teeny = false, $settings = false ) { function wp_tiny_mce( $teeny = false, $settings = false ) {
_deprecated_function( __FUNCTION__, '3.3', 'wp_editor()' ); _deprecated_function( __FUNCTION__, '3.3', 'wp_editor()' );
global $wp_editor;
static $num = 1; static $num = 1;
if ( !is_a($wp_editor, 'WP_Editor') ) { if ( ! class_exists('_WP_Editors' ) )
if ( !class_exists('WP_Editor') ) require_once( ABSPATH . WPINC . '/class-wp-editor.php' );
require_once( ABSPATH . WPINC . '/class-wp-editor.php' );
$wp_editor = new WP_Editor; $editor_id = 'content' . $num++;
}
$editor_id = 'content' . $num;
++$num;
$set = array( $set = array(
'teeny' => $teeny, 'teeny' => $teeny,
@ -730,8 +724,8 @@ function wp_tiny_mce( $teeny = false, $settings = false ) {
'quicktags' => false 'quicktags' => false
); );
$set = $wp_editor->parse_settings($editor_id, $set); $set = _WP_Editors::parse_settings($editor_id, $set);
$wp_editor->editor_settings($editor_id, $set); _WP_Editors::editor_settings($editor_id, $set);
} }
/** /**
@ -761,15 +755,6 @@ function wp_quicktags() {
_deprecated_function( __FUNCTION__, '3.3', 'wp_editor()' ); _deprecated_function( __FUNCTION__, '3.3', 'wp_editor()' );
} }
/**
* @deprecated 3.3.0
* @deprecated Use wp_editor()
* @see wp_editor()
*/
function wp_fullscreen_html() {
_deprecated_function( __FUNCTION__, '3.3', 'wp_editor()' );
}
/** /**
* Returns the screen layout options. * Returns the screen layout options.
* *

View File

@ -8,31 +8,26 @@
* Private, not included by default. See wp_editor() in wp-includes/general-template.php. * Private, not included by default. See wp_editor() in wp-includes/general-template.php.
*/ */
class WP_Editor { final class _WP_Editors {
public static $mce_locale;
var $mce_settings = array(); private static $mce_settings = array();
var $qt_settings = array(); private static $qt_settings = array();
var $plugins = array(); private static $plugins = array();
var $qt_buttons = array(); private static $qt_buttons = array();
var $mce_locale; private static $ext_plugins;
var $ext_plugins; private static $baseurl;
var $baseurl; private static $first_init;
var $can_richedit; private static $this_tinymce = false;
var $default_editor; private static $this_quicktags = false;
var $first_init; private static $has_tinymce = false;
var $this_tinymce = false; private static $has_quicktags = false;
var $this_quicktags = false; private static $has_medialib = false;
var $has_tinymce = false; private static $editor_buttons_css = true;
var $has_quicktags = false;
var $has_medialib = false;
var $editor_buttons_css = true;
function __construct() { private function __construct() {}
$this->can_richedit = user_can_richedit();
$this->default_editor = $this->wp_default_editor();
}
function parse_settings($editor_id, $settings) { public static function parse_settings($editor_id, $settings) {
$set = wp_parse_args( $settings, array( $set = wp_parse_args( $settings, array(
'wpautop' => true, // use wpautop? 'wpautop' => true, // use wpautop?
'media_buttons' => true, // show insert/upload button(s) 'media_buttons' => true, // show insert/upload button(s)
@ -43,18 +38,22 @@ class WP_Editor {
'editor_class' => '', // add extra class(es) to the editor textarea 'editor_class' => '', // add extra class(es) to the editor textarea
'teeny' => false, // output the minimal editor config used in Press This 'teeny' => false, // output the minimal editor config used in Press This
'dfw' => false, // replace the default fullscreen with DFW (needs specific DOM elements and css) 'dfw' => false, // replace the default fullscreen with DFW (needs specific DOM elements and css)
'tinymce' => true, // load TinyMCE, can be used to pass settings directly to TinyMCE using an array() 'tinymce' => null, // load TinyMCE, can be used to pass settings directly to TinyMCE using an array()
'quicktags' => true // load Quicktags, can be used to pass settings directly to Quicktags using an array() 'quicktags' => true // load Quicktags, can be used to pass settings directly to Quicktags using an array()
) ); ) );
$this->this_tinymce = !empty($set['tinymce']) && $this->can_richedit; if ( null === $set['tinymce'] )
$this->this_quicktags = !empty($set['quicktags']); self::$this_tinymce = user_can_richedit();
else
self::$this_tinymce = (bool) $set['tinymce'];
if ( $this->this_tinymce ) self::$this_quicktags = (bool) $set['quicktags'];
$this->has_tinymce = true;
if ( $this->this_quicktags ) if ( self::$this_tinymce )
$this->has_quicktags = true; self::$has_tinymce = true;
if ( self::$this_quicktags )
self::$has_quicktags = true;
return $set; return $set;
} }
@ -64,11 +63,11 @@ class WP_Editor {
* *
* @param string $content The initial content of the editor. * @param string $content The initial content of the editor.
* @param string $editor_id ID for the textarea and TinyMCE and Quicktags instances (can contain only ASCII letters and numbers). * @param string $editor_id ID for the textarea and TinyMCE and Quicktags instances (can contain only ASCII letters and numbers).
* @param array $settings See WP_Editor::_parse_settings for description. * @param array $settings See the _parse_settings() method for description.
*/ */
function editor( $content, $editor_id, $settings = array() ) { public static function editor( $content, $editor_id, $settings = array() ) {
$set = $this->parse_settings($editor_id, $settings); $set = self::parse_settings($editor_id, $settings);
$editor_class = ' class="' . trim( $set['editor_class'] . ' wp-editor-area' ) . '"'; $editor_class = ' class="' . trim( $set['editor_class'] . ' wp-editor-area' ) . '"';
$tabindex = $set['tabindex'] ? ' tabindex="' . (int) $set['tabindex'] . '"' : ''; $tabindex = $set['tabindex'] ? ' tabindex="' . (int) $set['tabindex'] . '"' : '';
$rows = ' rows="' . (int) $set['textarea_rows'] . '"'; $rows = ' rows="' . (int) $set['textarea_rows'] . '"';
@ -78,10 +77,10 @@ class WP_Editor {
if ( !current_user_can( 'upload_files' ) ) if ( !current_user_can( 'upload_files' ) )
$set['media_buttons'] = false; $set['media_buttons'] = false;
if ( $this->this_quicktags && $this->this_tinymce ) { if ( self::$this_quicktags && self::$this_tinymce ) {
$switch_class = 'html-active'; $switch_class = 'html-active';
if ( 'html' == $this->default_editor ) { if ( 'html' == wp_default_editor() ) {
add_filter('the_editor_content', 'wp_htmledit_pre'); add_filter('the_editor_content', 'wp_htmledit_pre');
} else { } else {
add_filter('the_editor_content', 'wp_richedit_pre'); add_filter('the_editor_content', 'wp_richedit_pre');
@ -94,9 +93,9 @@ class WP_Editor {
echo '<div id="wp-' . $editor_id . '-wrap" class="wp-editor-wrap ' . $switch_class . '">'; echo '<div id="wp-' . $editor_id . '-wrap" class="wp-editor-wrap ' . $switch_class . '">';
if ( $this->editor_buttons_css ) { if ( self::$editor_buttons_css ) {
wp_print_styles('editor-buttons'); wp_print_styles('editor-buttons');
$this->editor_buttons_css = false; self::$editor_buttons_css = false;
} }
if ( !empty($set['editor_css']) ) if ( !empty($set['editor_css']) )
@ -107,7 +106,7 @@ class WP_Editor {
echo $buttons; echo $buttons;
if ( $set['media_buttons'] ) { if ( $set['media_buttons'] ) {
$this->has_medialib = true; self::$has_medialib = true;
if ( !function_exists('media_buttons') ) if ( !function_exists('media_buttons') )
include(ABSPATH . 'wp-admin/includes/media.php'); include(ABSPATH . 'wp-admin/includes/media.php');
@ -125,24 +124,24 @@ class WP_Editor {
printf($the_editor, $content); printf($the_editor, $content);
echo "\n</div>\n\n"; echo "\n</div>\n\n";
$this->editor_settings($editor_id, $set); self::editor_settings($editor_id, $set);
} }
function editor_settings($editor_id, $set) { public static function editor_settings($editor_id, $set) {
global $editor_styles; global $editor_styles;
$first_run = false; $first_run = false;
if ( empty($this->first_init) ) { if ( empty(self::$first_init) ) {
if ( is_admin() ) { if ( is_admin() ) {
add_action( 'admin_print_footer_scripts', array($this, 'editor_js'), 50 ); add_action( 'admin_print_footer_scripts', array( __CLASS__, 'editor_js'), 50 );
add_action( 'admin_footer', array($this, 'enqueue_scripts'), 1 ); add_action( 'admin_footer', array( __CLASS__, 'enqueue_scripts'), 1 );
} else { } else {
add_action( 'wp_print_footer_scripts', array($this, 'editor_js'), 50 ); add_action( 'wp_print_footer_scripts', array( __CLASS__, 'editor_js'), 50 );
add_action( 'wp_footer', array($this, 'enqueue_scripts'), 1 ); add_action( 'wp_footer', array( __CLASS__, 'enqueue_scripts'), 1 );
} }
} }
if ( $this->this_quicktags ) { if ( self::$this_quicktags ) {
$qtInit = array( $qtInit = array(
'id' => $editor_id, 'id' => $editor_id,
@ -159,22 +158,22 @@ class WP_Editor {
$qtInit['buttons'] .= ',fullscreen'; $qtInit['buttons'] .= ',fullscreen';
$qtInit = apply_filters('quicktags_settings', $qtInit, $editor_id); $qtInit = apply_filters('quicktags_settings', $qtInit, $editor_id);
$this->qt_settings[$editor_id] = $qtInit; self::$qt_settings[$editor_id] = $qtInit;
$this->qt_buttons = array_merge( $this->qt_buttons, explode(',', $qtInit['buttons']) ); self::$qt_buttons = array_merge( self::$qt_buttons, explode(',', $qtInit['buttons']) );
} }
if ( $this->this_tinymce ) { if ( self::$this_tinymce ) {
if ( empty($this->first_init) ) { if ( empty(self::$first_init) ) {
$this->baseurl = includes_url('js/tinymce'); self::$baseurl = includes_url('js/tinymce');
$this->mce_locale = $mce_locale = ( '' == get_locale() ) ? 'en' : strtolower( substr(get_locale(), 0, 2) ); // only ISO 639-1 self::$mce_locale = $mce_locale = ( '' == get_locale() ) ? 'en' : strtolower( substr(get_locale(), 0, 2) ); // only ISO 639-1
$no_captions = (bool) apply_filters( 'disable_captions', '' ); $no_captions = (bool) apply_filters( 'disable_captions', '' );
$plugins = array( 'inlinepopups', 'spellchecker', 'tabfocus', 'paste', 'media', 'fullscreen', 'wordpress', 'wpeditimage', 'wpgallery', 'wplink', 'wpdialogs' ); $plugins = array( 'inlinepopups', 'spellchecker', 'tabfocus', 'paste', 'media', 'fullscreen', 'wordpress', 'wpeditimage', 'wpgallery', 'wplink', 'wpdialogs' );
$first_run = true; $first_run = true;
if ( $set['teeny'] ) { if ( $set['teeny'] ) {
$this->plugins = $plugins = apply_filters( 'teeny_mce_plugins', array('inlinepopups', 'fullscreen', 'wordpress', 'wplink', 'wpdialogs'), $editor_id ); self::$plugins = $plugins = apply_filters( 'teeny_mce_plugins', array('inlinepopups', 'fullscreen', 'wordpress', 'wplink', 'wpdialogs'), $editor_id );
$ext_plugins = ''; $ext_plugins = '';
} else { } else {
/* /*
@ -253,7 +252,7 @@ class WP_Editor {
$ext_plugins .= 'tinyMCEPreInit.load_ext("' . $plugurl . '", "' . $mce_locale . '");' . "\n"; $ext_plugins .= 'tinyMCEPreInit.load_ext("' . $plugurl . '", "' . $mce_locale . '");' . "\n";
$ext_plugins .= 'tinymce.PluginManager.load("' . $name . '", "' . $url . '");' . "\n"; $ext_plugins .= 'tinymce.PluginManager.load("' . $name . '", "' . $url . '");' . "\n";
$this->ext_plugins .= $ext_plugins; self::$ext_plugins .= $ext_plugins;
} }
} }
@ -263,7 +262,7 @@ class WP_Editor {
if ( $set['dfw'] ) if ( $set['dfw'] )
$plugins[] = 'wpfullscreen'; $plugins[] = 'wpfullscreen';
$this->plugins = $plugins; self::$plugins = $plugins;
/* /*
The following filter allows localization scripts to change the languages displayed in the spellchecker's drop-down menu. The following filter allows localization scripts to change the languages displayed in the spellchecker's drop-down menu.
@ -273,12 +272,12 @@ class WP_Editor {
*/ */
$mce_spellchecker_languages = apply_filters('mce_spellchecker_languages', '+English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr,German=de,Italian=it,Polish=pl,Portuguese=pt,Spanish=es,Swedish=sv'); $mce_spellchecker_languages = apply_filters('mce_spellchecker_languages', '+English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr,German=de,Italian=it,Polish=pl,Portuguese=pt,Spanish=es,Swedish=sv');
$this->first_init = array( self::$first_init = array(
'mode' => 'exact', 'mode' => 'exact',
'width' => '100%', 'width' => '100%',
'theme' => 'advanced', 'theme' => 'advanced',
'skin' => 'wp_theme', 'skin' => 'wp_theme',
'language' => $this->mce_locale, 'language' => self::$mce_locale,
'spellchecker_languages' => $mce_spellchecker_languages, 'spellchecker_languages' => $mce_spellchecker_languages,
'theme_advanced_toolbar_location' => 'top', 'theme_advanced_toolbar_location' => 'top',
'theme_advanced_toolbar_align' => 'left', 'theme_advanced_toolbar_align' => 'left',
@ -317,7 +316,7 @@ class WP_Editor {
'paste_text_use_dialog' => true, 'paste_text_use_dialog' => true,
'extended_valid_elements' => 'article[*],aside[*],audio[*],canvas[*],command[*],datalist[*],details[*],embed[*],figcaption[*],figure[*],footer[*],header[*],hgroup[*],keygen[*],mark[*],meter[*],nav[*],output[*],progress[*],section[*],source[*],summary,time[*],video[*],wbr', 'extended_valid_elements' => 'article[*],aside[*],audio[*],canvas[*],command[*],datalist[*],details[*],embed[*],figcaption[*],figure[*],footer[*],header[*],hgroup[*],keygen[*],mark[*],meter[*],nav[*],output[*],progress[*],section[*],source[*],summary,time[*],video[*],wbr',
'wpeditimage_disable_captions' => $no_captions, 'wpeditimage_disable_captions' => $no_captions,
'wp_fullscreen_content_css' => "$this->baseurl/plugins/wpfullscreen/css/wp-fullscreen.css", 'wp_fullscreen_content_css' => self::$baseurl . '/plugins/wpfullscreen/css/wp-fullscreen.css',
'plugins' => implode( ',', $plugins ) 'plugins' => implode( ',', $plugins )
); );
@ -352,7 +351,7 @@ class WP_Editor {
$mce_css = trim( apply_filters( 'mce_css', $mce_css ), ' ,' ); $mce_css = trim( apply_filters( 'mce_css', $mce_css ), ' ,' );
if ( ! empty($mce_css) ) if ( ! empty($mce_css) )
$this->first_init['content_css'] = $mce_css; self::$first_init['content_css'] = $mce_css;
} }
if ( $set['teeny'] ) { if ( $set['teeny'] ) {
@ -389,7 +388,7 @@ class WP_Editor {
); );
if ( $first_run ) if ( $first_run )
$mceInit = array_merge($this->first_init, $mceInit); $mceInit = array_merge(self::$first_init, $mceInit);
if ( is_array($set['tinymce']) ) if ( is_array($set['tinymce']) )
$mceInit = array_merge($mceInit, $set['tinymce']); $mceInit = array_merge($mceInit, $set['tinymce']);
@ -409,11 +408,11 @@ class WP_Editor {
$mceInit['theme_advanced_buttons4'] = ''; $mceInit['theme_advanced_buttons4'] = '';
} }
$this->mce_settings[$editor_id] = $mceInit; self::$mce_settings[$editor_id] = $mceInit;
} // end if $this->this_tinymce } // end if self::$this_tinymce
} }
function _parse_init($init) { private static function _parse_init($init) {
$options = ''; $options = '';
foreach ( $init as $k => $v ) { foreach ( $init as $k => $v ) {
@ -431,50 +430,31 @@ class WP_Editor {
return '{' . trim( $options, ' ,' ) . '}'; return '{' . trim( $options, ' ,' ) . '}';
} }
/** public static function enqueue_scripts() {
* Find out which editor should be displayed by default.
*
* Works out which of the two editors to display as the current editor for a
* user.
*
* @since 2.5.0
*
* @return string Either 'tinymce', or 'html', or 'test'
*/
function wp_default_editor() {
$r = user_can_richedit() ? 'tinymce' : 'html'; // defaults
if ( $user = wp_get_current_user() ) { // look for cookie
$ed = get_user_setting('editor', 'tinymce');
$r = ( in_array($ed, array('tinymce', 'html', 'test') ) ) ? $ed : $r;
}
return apply_filters( 'wp_default_editor', $r ); // filter
}
function enqueue_scripts() {
wp_enqueue_script('word-count'); wp_enqueue_script('word-count');
if ( $this->has_tinymce ) if ( self::$has_tinymce )
wp_enqueue_script('editor'); wp_enqueue_script('editor');
if ( $this->has_quicktags ) if ( self::$has_quicktags )
wp_enqueue_script('quicktags'); wp_enqueue_script('quicktags');
if ( in_array('wplink', $this->plugins, true) || in_array('link', $this->qt_buttons, true) ) { if ( in_array('wplink', self::$plugins, true) || in_array('link', self::$qt_buttons, true) ) {
wp_enqueue_script('wplink'); wp_enqueue_script('wplink');
wp_enqueue_script('wpdialogs-popup'); wp_enqueue_script('wpdialogs-popup');
wp_enqueue_style('wp-jquery-ui-dialog'); wp_enqueue_style('wp-jquery-ui-dialog');
} }
if ( in_array('wpfullscreen', $this->plugins, true) || in_array('fullscreen', $this->qt_buttons, true) ) if ( in_array('wpfullscreen', self::$plugins, true) || in_array('fullscreen', self::$qt_buttons, true) )
wp_enqueue_script('wp-fullscreen'); wp_enqueue_script('wp-fullscreen');
if ( $this->has_medialib ) { if ( self::$has_medialib ) {
add_thickbox(); add_thickbox();
wp_enqueue_script('media-upload'); wp_enqueue_script('media-upload');
} }
} }
function editor_js() { public static function editor_js() {
global $tinymce_version, $concatenate_scripts, $compress_scripts; global $tinymce_version, $concatenate_scripts, $compress_scripts;
/** /**
@ -485,7 +465,7 @@ class WP_Editor {
* If the plugin has a popup dialog, a query string can be added to the button action that opens it (in the plugin's code). * If the plugin has a popup dialog, a query string can be added to the button action that opens it (in the plugin's code).
*/ */
$version = 'ver=' . $tinymce_version; $version = 'ver=' . $tinymce_version;
$tmce_on = !empty($this->mce_settings); $tmce_on = !empty(self::$mce_settings);
if ( ! isset($concatenate_scripts) ) if ( ! isset($concatenate_scripts) )
script_concat_settings(); script_concat_settings();
@ -493,13 +473,13 @@ class WP_Editor {
$compressed = $compress_scripts && $concatenate_scripts && isset($_SERVER['HTTP_ACCEPT_ENCODING']) $compressed = $compress_scripts && $concatenate_scripts && isset($_SERVER['HTTP_ACCEPT_ENCODING'])
&& false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'); && false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip');
if ( $tmce_on && 'en' != $this->mce_locale ) if ( $tmce_on && 'en' != self::$mce_locale )
include_once(ABSPATH . WPINC . '/js/tinymce/langs/wp-langs.php'); include_once(ABSPATH . WPINC . '/js/tinymce/langs/wp-langs.php');
$mceInit = $qtInit = ''; $mceInit = $qtInit = '';
if ( $tmce_on ) { if ( $tmce_on ) {
foreach ( $this->mce_settings as $editor_id => $init ) { foreach ( self::$mce_settings as $editor_id => $init ) {
$options = $this->_parse_init( $init ); $options = self::_parse_init( $init );
$mceInit .= "'$editor_id':{$options},"; $mceInit .= "'$editor_id':{$options},";
} }
$mceInit = '{' . trim($mceInit, ',') . '}'; $mceInit = '{' . trim($mceInit, ',') . '}';
@ -507,9 +487,9 @@ class WP_Editor {
$mceInit = '{}'; $mceInit = '{}';
} }
if ( !empty($this->qt_settings) ) { if ( !empty(self::$qt_settings) ) {
foreach ( $this->qt_settings as $editor_id => $init ) { foreach ( self::$qt_settings as $editor_id => $init ) {
$options = $this->_parse_init( $init ); $options = self::_parse_init( $init );
$qtInit .= "'$editor_id':{$options},"; $qtInit .= "'$editor_id':{$options},";
} }
$qtInit = '{' . trim($qtInit, ',') . '}'; $qtInit = '{' . trim($qtInit, ',') . '}';
@ -518,43 +498,45 @@ class WP_Editor {
} }
$ref = array( $ref = array(
'plugins' => implode( ',', $this->plugins ), 'plugins' => implode( ',', self::$plugins ),
'theme' => 'advanced', 'theme' => 'advanced',
'language' => $this->mce_locale 'language' => self::$mce_locale
); );
do_action('before_wp_tiny_mce', $this->mce_settings); do_action('before_wp_tiny_mce', self::$mce_settings);
?> ?>
<script type="text/javascript"> <script type="text/javascript">
tinyMCEPreInit = { tinyMCEPreInit = {
base : "<?php echo $this->baseurl; ?>", base : "<?php echo self::$baseurl; ?>",
suffix : "", suffix : "",
query : "<?php echo $version; ?>", query : "<?php echo $version; ?>",
mceInit : <?php echo $mceInit; ?>, mceInit : <?php echo $mceInit; ?>,
qtInit : <?php echo $qtInit; ?>, qtInit : <?php echo $qtInit; ?>,
ref : <?php echo $this->_parse_init( $ref ); ?>, ref : <?php echo self::_parse_init( $ref ); ?>,
load_ext : function(url,lang){var sl=tinymce.ScriptLoader;sl.markDone(url+'/langs/'+lang+'.js');sl.markDone(url+'/langs/'+lang+'_dlg.js');} load_ext : function(url,lang){var sl=tinymce.ScriptLoader;sl.markDone(url+'/langs/'+lang+'.js');sl.markDone(url+'/langs/'+lang+'_dlg.js');}
}; };
</script> </script>
<?php <?php
$baseurl = self::$baseurl;
if ( $tmce_on ) { if ( $tmce_on ) {
if ( $compressed ) if ( $compressed )
echo "<script type='text/javascript' src='$this->baseurl/wp-tinymce.php?c=1&amp;$version'></script>\n"; echo "<script type='text/javascript' src='{$baseurl}/wp-tinymce.php?c=1&amp;$version'></script>\n";
else else
echo "<script type='text/javascript' src='$this->baseurl/tiny_mce.js?$version'></script>\n"; echo "<script type='text/javascript' src='{$baseurl}/tiny_mce.js?$version'></script>\n";
if ( 'en' != $this->mce_locale && isset($lang) ) if ( 'en' != self::$mce_locale && isset($lang) )
echo "<script type='text/javascript'>\n$lang\n</script>\n"; echo "<script type='text/javascript'>\n$lang\n</script>\n";
else else
echo "<script type='text/javascript' src='$this->baseurl/langs/wp-langs-en.js?$version'></script>\n"; echo "<script type='text/javascript' src='{$baseurl}/langs/wp-langs-en.js?$version'></script>\n";
} }
?> ?>
<script type="text/javascript"> <script type="text/javascript">
(function(){ (function(){
var init, ed, qt, first_init, mce = <?php echo $this->default_editor == 'tinymce' ? 'true' : 'false'; ?>; var init, ed, qt, first_init, mce = <?php echo wp_default_editor() == 'tinymce' ? 'true' : 'false'; ?>;
if ( typeof(tinymce) == 'object' ) { if ( typeof(tinymce) == 'object' ) {
for ( ed in tinyMCEPreInit.mceInit ) { for ( ed in tinyMCEPreInit.mceInit ) {
@ -584,8 +566,8 @@ class WP_Editor {
<?php <?php
if ( $this->ext_plugins ) if ( self::$ext_plugins )
echo "$this->ext_plugins\n"; echo self::$ext_plugins . "\n";
if ( ! $compressed && $tmce_on ) { if ( ! $compressed && $tmce_on ) {
?> ?>
@ -599,16 +581,16 @@ class WP_Editor {
</script> </script>
<?php <?php
if ( in_array('wplink', $this->plugins, true) || in_array('link', $this->qt_buttons, true) ) if ( in_array('wplink', self::$plugins, true) || in_array('link', self::$qt_buttons, true) )
$this->wp_link_dialog(); self::wp_link_dialog();
if ( in_array('wpfullscreen', $this->plugins, true) || in_array('fullscreen', $this->qt_buttons, true) ) if ( in_array('wpfullscreen', self::$plugins, true) || in_array('fullscreen', self::$qt_buttons, true) )
$this->wp_fullscreen_html(); self::wp_fullscreen_html();
do_action('after_wp_tiny_mce', $this->mce_settings); do_action('after_wp_tiny_mce', self::$mce_settings);
} }
function wp_fullscreen_html() { public static function wp_fullscreen_html() {
global $content_width, $post; global $content_width, $post;
$width = isset($content_width) && 800 > $content_width ? $content_width : 800; $width = isset($content_width) && 800 > $content_width ? $content_width : 800;
@ -705,7 +687,7 @@ class WP_Editor {
* @param array $args Optional. Accepts 'pagenum' and 's' (search) arguments. * @param array $args Optional. Accepts 'pagenum' and 's' (search) arguments.
* @return array Results. * @return array Results.
*/ */
function wp_link_query( $args = array() ) { public static function wp_link_query( $args = array() ) {
$pts = get_post_types( array( 'public' => true ), 'objects' ); $pts = get_post_types( array( 'public' => true ), 'objects' );
$pt_names = array_keys( $pts ); $pt_names = array_keys( $pts );
@ -758,7 +740,7 @@ class WP_Editor {
* *
* @since 3.1.0 * @since 3.1.0
*/ */
function wp_link_dialog() { public static function wp_link_dialog() {
?> ?>
<div style="display:none;"> <div style="display:none;">
<form id="wp-link" tabindex="-1"> <form id="wp-link" tabindex="-1">

View File

@ -2616,27 +2616,6 @@ function wp_timezone_supported() {
return true; return true;
} }
/**
* Find out which editor should be displayed
*
* @see WP_Editor::wp_default_editor()
* @since 2.5.0
* @deprecated 3.5
*
* @return bool
*/
function wp_default_editor() {
_deprecated_function( __FUNCTION__, '3.3' );
global $wp_editor;
if ( !is_a($wp_editor, 'WP_Editor') ) {
require_once( ABSPATH . WPINC . '/class-wp-editor.php' );
$wp_editor = new WP_Editor;
}
return $wp_editor->wp_default_editor();
}
/** /**
* Display editor: TinyMCE, HTML, or both. * Display editor: TinyMCE, HTML, or both.
* *

View File

@ -1766,11 +1766,29 @@ function user_can_richedit() {
} }
/** /**
* Loads and initializes WP_Editor class (if needed), passes the settings for an instance of the editor * Find out which editor should be displayed by default.
*
* Works out which of the two editors to display as the current editor for a
* user.
*
* @since 2.5.0
*
* @return string Either 'tinymce', or 'html', or 'test'
*/
function wp_default_editor() {
$r = user_can_richedit() ? 'tinymce' : 'html'; // defaults
if ( $user = wp_get_current_user() ) { // look for cookie
$ed = get_user_setting('editor', 'tinymce');
$r = ( in_array($ed, array('tinymce', 'html', 'test') ) ) ? $ed : $r;
}
return apply_filters( 'wp_default_editor', $r ); // filter
}
/**
* Renders an editor.
* *
* Using this function is the proper way to output all needed components for both TinyMCE and Quicktags. * Using this function is the proper way to output all needed components for both TinyMCE and Quicktags.
* WP_Editor shouldn't be instantiated separately as it keeps track of loaded scripts. * _WP_Editors should not be used directly. See http://core.trac.wordpress.org/ticket/17144.
* See http://core.trac.wordpress.org/ticket/17144.
* *
* NOTE: Once initialized the TinyMCE editor cannot be safely moved in the DOM. For that reason * NOTE: Once initialized the TinyMCE editor cannot be safely moved in the DOM. For that reason
* running wp_editor() inside of a metabox is not a good idea unless only Quicktags is used. * running wp_editor() inside of a metabox is not a good idea unless only Quicktags is used.
@ -1783,17 +1801,13 @@ function user_can_richedit() {
* *
* @param string $content Initial content for the editor. * @param string $content Initial content for the editor.
* @param string $editor_id HTML ID attribute value for the textarea and TinyMCE. Can only be /[a-z]+/. * @param string $editor_id HTML ID attribute value for the textarea and TinyMCE. Can only be /[a-z]+/.
* @param array $settings See WP_Editor::editor(). * @param array $settings See _WP_Editors::editor().
*/ */
function wp_editor( $content, $editor_id, $settings = array() ) { function wp_editor( $content, $editor_id, $settings = array() ) {
global $wp_editor; if ( ! class_exists( '_WP_Editors' ) )
if ( !is_a($wp_editor, 'WP_Editor') ) {
require( ABSPATH . WPINC . '/class-wp-editor.php' ); require( ABSPATH . WPINC . '/class-wp-editor.php' );
$wp_editor = new WP_Editor;
}
$wp_editor->editor($content, $editor_id, $settings); _WP_Editors::editor($content, $editor_id, $settings);
} }
/** /**

View File

@ -1,16 +1,13 @@
<?php <?php
// escape text only if it needs translating
function mce_escape($text) { function mce_escape($text) {
global $wp_editor; return esc_js($text);
if ( 'en' == $wp_editor->mce_locale )
return $text;
else
return esc_js($text);
} }
$lang = 'tinyMCE.addI18n({' . $this->mce_locale . ':{ if ( ! class_exists( '_WP_Editors' ) )
require( ABSPATH . WPINC . '/class-wp-editor.php' );
$lang = 'tinyMCE.addI18n({' . _WP_Editors::$mce_locale . ':{
common:{ common:{
edit_confirm:"' . mce_escape( __('Do you want to use the WYSIWYG mode for this textarea?') ) . '", edit_confirm:"' . mce_escape( __('Do you want to use the WYSIWYG mode for this textarea?') ) . '",
apply:"' . mce_escape( __('Apply') ) . '", apply:"' . mce_escape( __('Apply') ) . '",
@ -232,7 +229,7 @@ words:"' . mce_escape( __('Words:') ) . ' "
} }
}}); }});
tinyMCE.addI18n("' . $this->mce_locale . '.advanced",{ tinyMCE.addI18n("' . _WP_Editors::$mce_locale . '.advanced",{
style_select:"' . mce_escape( /* translators: TinyMCE font styles */ _x('Styles', 'TinyMCE font styles') ) . '", style_select:"' . mce_escape( /* translators: TinyMCE font styles */ _x('Styles', 'TinyMCE font styles') ) . '",
font_size:"' . mce_escape( __('Font size') ) . '", font_size:"' . mce_escape( __('Font size') ) . '",
fontdefault:"' . mce_escape( __('Font family') ) . '", fontdefault:"' . mce_escape( __('Font family') ) . '",
@ -298,7 +295,7 @@ rich_text_area:"' . mce_escape( __('Rich Text Area') ) . '",
toolbar:"' . mce_escape( __('Toolbar') ) . '" toolbar:"' . mce_escape( __('Toolbar') ) . '"
}); });
tinyMCE.addI18n("' . $this->mce_locale . '.advanced_dlg",{ tinyMCE.addI18n("' . _WP_Editors::$mce_locale . '.advanced_dlg",{
about_title:"' . mce_escape( __('About TinyMCE') ) . '", about_title:"' . mce_escape( __('About TinyMCE') ) . '",
about_general:"' . mce_escape( __('About') ) . '", about_general:"' . mce_escape( __('About') ) . '",
about_help:"' . mce_escape( __('Help') ) . '", about_help:"' . mce_escape( __('Help') ) . '",
@ -352,7 +349,7 @@ accessibility_help:"' . mce_escape( __('Accessibility Help') ) . '",
accessibility_usage_title:"' . mce_escape( __('General Usage') ) . '" accessibility_usage_title:"' . mce_escape( __('General Usage') ) . '"
}); });
tinyMCE.addI18n("' . $this->mce_locale . '.media_dlg",{ tinyMCE.addI18n("' . _WP_Editors::$mce_locale . '.media_dlg",{
title:"' . mce_escape( __('Insert / edit embedded media') ) . '", title:"' . mce_escape( __('Insert / edit embedded media') ) . '",
general:"' . mce_escape( __('General') ) . '", general:"' . mce_escape( __('General') ) . '",
advanced:"' . mce_escape( __('Advanced') ) . '", advanced:"' . mce_escape( __('Advanced') ) . '",
@ -462,7 +459,7 @@ poster:"' . mce_escape( __('Poster') ) . '",
source:"' . mce_escape( __('Source') ) . '" source:"' . mce_escape( __('Source') ) . '"
}); });
tinyMCE.addI18n("' . $this->mce_locale . '.wordpress",{ tinyMCE.addI18n("' . _WP_Editors::$mce_locale . '.wordpress",{
wp_adv_desc:"' . mce_escape( __('Show/Hide Kitchen Sink (Alt + Shift + Z)') ) . '", wp_adv_desc:"' . mce_escape( __('Show/Hide Kitchen Sink (Alt + Shift + Z)') ) . '",
wp_more_desc:"' . mce_escape( __('Insert More Tag (Alt + Shift + T)') ) . '", wp_more_desc:"' . mce_escape( __('Insert More Tag (Alt + Shift + T)') ) . '",
wp_page_desc:"' . mce_escape( __('Insert Page break (Alt + Shift + P)') ) . '", wp_page_desc:"' . mce_escape( __('Insert Page break (Alt + Shift + P)') ) . '",
@ -477,7 +474,7 @@ editgallery:"' . mce_escape( __('Edit Gallery') ) . '",
delgallery:"' . mce_escape( __('Delete Gallery') ) . '" delgallery:"' . mce_escape( __('Delete Gallery') ) . '"
}); });
tinyMCE.addI18n("' . $this->mce_locale . '.wpeditimage",{ tinyMCE.addI18n("' . _WP_Editors::$mce_locale . '.wpeditimage",{
edit_img:"' . mce_escape( __('Edit Image') ) . '", edit_img:"' . mce_escape( __('Edit Image') ) . '",
del_img:"' . mce_escape( __('Delete Image') ) . '", del_img:"' . mce_escape( __('Delete Image') ) . '",
adv_settings:"' . mce_escape( __('Advanced Settings') ) . '", adv_settings:"' . mce_escape( __('Advanced Settings') ) . '",