mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-03-31 18:54:29 +00:00
Fix back-compat for quicktags, introduce QTags.addButton(), see #16695
git-svn-id: https://develop.svn.wordpress.org/trunk@18511 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -22,20 +22,20 @@ class WP_Editor {
|
||||
var $can_richedit;
|
||||
var $default_editor;
|
||||
var $first_init;
|
||||
var $tinymce = false;
|
||||
var $quicktags = false;
|
||||
var $this_tinymce = false;
|
||||
var $this_quicktags = false;
|
||||
|
||||
function __construct() {
|
||||
$this->can_richedit = user_can_richedit();
|
||||
$this->default_editor = $this->wp_default_editor();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Outputs the HTML and enqueues the JavaScript for a single instance of the editor.
|
||||
*
|
||||
* $param $content The initial content of the editor.
|
||||
* $param $editor_id ID for the textarea and TinyMCE and Quicktags instances (can contain only ASCII letters and numbers).
|
||||
* $param $settings See below for description.
|
||||
*
|
||||
* @param $content The initial content of the editor.
|
||||
* @param $editor_id ID for the textarea and TinyMCE and Quicktags instances (can contain only ASCII letters and numbers).
|
||||
* @param $settings See below for description.
|
||||
*/
|
||||
function editor( $content, $editor_id, $settings = array() ) {
|
||||
|
||||
@@ -52,8 +52,8 @@ class WP_Editor {
|
||||
'quicktags' => true // load Quicktags, can be used to pass settings directly to Quicktags using an array()
|
||||
) );
|
||||
|
||||
$this->tinymce = !empty($set['tinymce']) && $this->can_richedit;
|
||||
$this->quicktags = !empty($set['quicktags']);
|
||||
$this->this_tinymce = !empty($set['tinymce']) && $this->can_richedit;
|
||||
$this->this_quicktags = !empty($set['quicktags']);
|
||||
$editor_class = ' class="' . trim( $set['editor_class'] . ' wp-editor-area' ) . '"';
|
||||
$tabindex = $set['tabindex'] ? ' tabindex="' . (int) $set['tabindex'] . '"' : '';
|
||||
$rows = ' rows="' . (int) $set['textarea_rows'] . '"';
|
||||
@@ -63,7 +63,7 @@ class WP_Editor {
|
||||
if ( !current_user_can( 'upload_files' ) )
|
||||
$set['media_buttons'] = false;
|
||||
|
||||
if ( $this->can_richedit && $this->quicktags && $this->tinymce ) {
|
||||
if ( $this->can_richedit && $this->this_quicktags && $this->this_tinymce ) {
|
||||
$switch_class = 'html-active';
|
||||
|
||||
if ( 'html' == $this->default_editor ) {
|
||||
@@ -76,7 +76,7 @@ class WP_Editor {
|
||||
$buttons .= '<a id="' . $editor_id . '-html" class="hide-if-no-js wp-switch-editor switch-html" onclick="switchEditors.go(this);return false;">' . __('HTML') . "</a>\n";
|
||||
$buttons .= '<a id="' . $editor_id . '-tmce" class="hide-if-no-js wp-switch-editor switch-tmce" onclick="switchEditors.go(this);return false;">' . __('Visual') . "</a>\n";
|
||||
}
|
||||
|
||||
|
||||
echo '<div id="wp-' . $editor_id . '-wrap" class="wp-editor-wrap ' . $switch_class . '">';
|
||||
|
||||
if ( !empty($set['editor_css']) )
|
||||
@@ -89,7 +89,7 @@ class WP_Editor {
|
||||
if ( $set['media_buttons'] ) {
|
||||
if ( !function_exists('media_buttons') )
|
||||
include(ABSPATH . 'wp-admin/includes/media.php');
|
||||
|
||||
|
||||
echo '<div id="wp-' . $editor_id . '-media-buttons" class="hide-if-no-js wp-media-buttons">';
|
||||
do_action('media_buttons', $editor_id);
|
||||
echo "</div>\n";
|
||||
@@ -117,14 +117,14 @@ class WP_Editor {
|
||||
global $editor_styles;
|
||||
$first_run = false;
|
||||
|
||||
if ( $this->quicktags ) {
|
||||
if ( $this->this_quicktags ) {
|
||||
$qtbuttons = apply_filters( 'quicktags_buttons', array(), $editor_id );
|
||||
$qtbuttons_disabled = apply_filters( 'quicktags_disabled_buttons', array(), $editor_id );
|
||||
|
||||
$qtInit = array(
|
||||
'quicktags_id' => $editor_id,
|
||||
'quicktags_buttons' => implode($qtbuttons, ','),
|
||||
'quicktags_disabled_buttons' => implode($qtbuttons_disabled, ',')
|
||||
'id' => $editor_id,
|
||||
'buttons' => implode($qtbuttons, ','),
|
||||
'disabled_buttons' => implode($qtbuttons_disabled, ',')
|
||||
);
|
||||
|
||||
if ( is_array($settings['quicktags']) )
|
||||
@@ -132,8 +132,8 @@ class WP_Editor {
|
||||
|
||||
$this->qt_settings[$editor_id] = $qtInit;
|
||||
}
|
||||
|
||||
if ( $this->tinymce ) {
|
||||
|
||||
if ( $this->this_tinymce ) {
|
||||
|
||||
if ( empty($this->first_init) ) {
|
||||
$this->baseurl = includes_url('js/tinymce');
|
||||
@@ -154,10 +154,10 @@ class WP_Editor {
|
||||
If the plugin uses a button, it should be added with one of the "$mce_buttons" filters.
|
||||
*/
|
||||
$mce_external_plugins = apply_filters('mce_external_plugins', array());
|
||||
|
||||
|
||||
$ext_plugins = '';
|
||||
if ( ! empty($mce_external_plugins) ) {
|
||||
|
||||
|
||||
/*
|
||||
The following filter loads external language files for TinyMCE plugins.
|
||||
It takes an associative array 'plugin_name' => 'path', where path is the
|
||||
@@ -168,10 +168,10 @@ class WP_Editor {
|
||||
If that is not found, en.js will be tried next.
|
||||
*/
|
||||
$mce_external_languages = apply_filters('mce_external_languages', array());
|
||||
|
||||
|
||||
$loaded_langs = array();
|
||||
$strings = '';
|
||||
|
||||
|
||||
if ( ! empty($mce_external_languages) ) {
|
||||
foreach ( $mce_external_languages as $name => $path ) {
|
||||
if ( @is_file($path) && @is_readable($path) ) {
|
||||
@@ -181,58 +181,58 @@ class WP_Editor {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach ( $mce_external_plugins as $name => $url ) {
|
||||
|
||||
|
||||
if ( is_ssl() ) $url = str_replace('http://', 'https://', $url);
|
||||
|
||||
|
||||
$plugins[] = '-' . $name;
|
||||
|
||||
|
||||
$plugurl = dirname($url);
|
||||
$strings = $str1 = $str2 = '';
|
||||
if ( ! in_array($name, $loaded_langs) ) {
|
||||
$path = str_replace( WP_CONTENT_URL, '', $plugurl );
|
||||
$path = WP_CONTENT_DIR . $path . '/langs/';
|
||||
|
||||
|
||||
if ( function_exists('realpath') )
|
||||
$path = trailingslashit( realpath($path) );
|
||||
|
||||
|
||||
if ( @is_file($path . $mce_locale . '.js') )
|
||||
$strings .= @file_get_contents($path . $mce_locale . '.js') . "\n";
|
||||
|
||||
|
||||
if ( @is_file($path . $mce_locale . '_dlg.js') )
|
||||
$strings .= @file_get_contents($path . $mce_locale . '_dlg.js') . "\n";
|
||||
|
||||
|
||||
if ( 'en' != $mce_locale && empty($strings) ) {
|
||||
if ( @is_file($path . 'en.js') ) {
|
||||
$str1 = @file_get_contents($path . 'en.js');
|
||||
$strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.', $str1, 1 ) . "\n";
|
||||
}
|
||||
|
||||
|
||||
if ( @is_file($path . 'en_dlg.js') ) {
|
||||
$str2 = @file_get_contents($path . 'en_dlg.js');
|
||||
$strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.', $str2, 1 ) . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( ! empty($strings) )
|
||||
$ext_plugins .= "\n" . $strings . "\n";
|
||||
}
|
||||
|
||||
|
||||
$ext_plugins .= 'tinyMCEPreInit.load_ext("' . $plugurl . '", "' . $mce_locale . '");' . "\n";
|
||||
$ext_plugins .= 'tinymce.PluginManager.load("' . $name . '", "' . $url . '");' . "\n";
|
||||
|
||||
|
||||
$this->ext_plugins .= $ext_plugins;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$plugins = array_unique( apply_filters('tiny_mce_plugins', $plugins) );
|
||||
|
||||
if ( 'content' == $editor_id ) // enable DFW only on Add/Edit Post screens for now
|
||||
$plugins[] = 'wpfullscreen';
|
||||
|
||||
$this->plugins = $plugins;
|
||||
|
||||
|
||||
/*
|
||||
The following filter allows localization scripts to change the languages displayed in the spellchecker's drop-down menu.
|
||||
By default it uses Google's spellchecker API, but can be configured to use PSpell/ASpell if installed on the server.
|
||||
@@ -288,7 +288,7 @@ class WP_Editor {
|
||||
'wp_fullscreen_content_css' => "$this->baseurl/plugins/wpfullscreen/css/wp-fullscreen.css",
|
||||
'plugins' => implode( ',', $plugins )
|
||||
);
|
||||
|
||||
|
||||
// load editor_style.css if the current theme supports it
|
||||
if ( ! empty( $editor_styles ) && is_array( $editor_styles ) ) {
|
||||
$mce_css = array();
|
||||
@@ -311,9 +311,9 @@ class WP_Editor {
|
||||
} else {
|
||||
$mce_css = '';
|
||||
}
|
||||
|
||||
|
||||
$mce_css = trim( apply_filters( 'mce_css', $mce_css ), ' ,' );
|
||||
|
||||
|
||||
if ( ! empty($mce_css) )
|
||||
$this->first_init['content_css'] = $mce_css;
|
||||
}
|
||||
@@ -351,7 +351,7 @@ class WP_Editor {
|
||||
'theme_advanced_buttons3' => implode($mce_buttons_3, ','),
|
||||
'theme_advanced_buttons4' => implode($mce_buttons_4, ',')
|
||||
);
|
||||
|
||||
|
||||
if ( $first_run )
|
||||
$mceInit = array_merge($this->first_init, $mceInit);
|
||||
|
||||
@@ -367,7 +367,7 @@ class WP_Editor {
|
||||
} else {
|
||||
$mceInit = apply_filters('tiny_mce_before_init', $mceInit, $editor_id);
|
||||
}
|
||||
|
||||
|
||||
if ( empty($mceInit['theme_advanced_buttons3']) && !empty($mceInit['theme_advanced_buttons4']) ) {
|
||||
$mceInit['theme_advanced_buttons3'] = $mceInit['theme_advanced_buttons4'];
|
||||
$mceInit['theme_advanced_buttons4'] = '';
|
||||
@@ -375,9 +375,9 @@ class WP_Editor {
|
||||
|
||||
$this->mce_settings[$editor_id] = $mceInit;
|
||||
$first_run = false;
|
||||
} // end if $this->tinymce
|
||||
} // end if $this->this_tinymce
|
||||
}
|
||||
|
||||
|
||||
function _parse_init($init) {
|
||||
$options = '';
|
||||
|
||||
@@ -395,7 +395,7 @@ class WP_Editor {
|
||||
|
||||
return '{' . trim( $options, ' ,' ) . '}';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find out which editor should be displayed by default.
|
||||
*
|
||||
@@ -419,21 +419,16 @@ class WP_Editor {
|
||||
wp_enqueue_script('quicktags');
|
||||
wp_enqueue_script('word-count');
|
||||
wp_enqueue_script('wplink');
|
||||
wp_enqueue_script('editor');
|
||||
wp_enqueue_style('editor-buttons');
|
||||
|
||||
|
||||
wp_enqueue_script('wpdialogs-popup');
|
||||
wp_enqueue_style('wp-jquery-ui-dialog');
|
||||
|
||||
if ( $this->tinymce )
|
||||
wp_enqueue_script('editor');
|
||||
else
|
||||
wp_enqueue_script('utils');
|
||||
|
||||
if ( in_array('wpfullscreen', $this->plugins, true) )
|
||||
wp_enqueue_script('wp-fullscreen');
|
||||
|
||||
if ( !is_admin() )
|
||||
add_thickbox();
|
||||
add_thickbox();
|
||||
}
|
||||
|
||||
function editor_js() {
|
||||
@@ -447,6 +442,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).
|
||||
*/
|
||||
$version = 'ver=' . $tinymce_version;
|
||||
$tmce_on = !empty($this->mce_settings);
|
||||
|
||||
if ( ! isset($concatenate_scripts) )
|
||||
script_concat_settings();
|
||||
@@ -454,11 +450,11 @@ class WP_Editor {
|
||||
$compressed = $compress_scripts && $concatenate_scripts && isset($_SERVER['HTTP_ACCEPT_ENCODING'])
|
||||
&& false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip');
|
||||
|
||||
if ( $this->tinymce && 'en' != $this->mce_locale )
|
||||
if ( $tmce_on && 'en' != $this->mce_locale )
|
||||
include_once(ABSPATH . WPINC . '/js/tinymce/langs/wp-langs.php');
|
||||
|
||||
$mceInit = $qtInit = '';
|
||||
if ( !empty($this->mce_settings) ) {
|
||||
if ( $tmce_on ) {
|
||||
foreach ( $this->mce_settings as $editor_id => $init ) {
|
||||
$options = $this->_parse_init( $init );
|
||||
$mceInit .= "'$editor_id':{$options},\n";
|
||||
@@ -503,7 +499,7 @@ class WP_Editor {
|
||||
</script>
|
||||
<?php
|
||||
|
||||
if ( $this->tinymce ) {
|
||||
if ( $tmce_on ) {
|
||||
if ( $compressed )
|
||||
echo "<script type='text/javascript' src='$this->baseurl/wp-tinymce.php?c=1&$version'></script>\n";
|
||||
else
|
||||
@@ -570,7 +566,7 @@ class WP_Editor {
|
||||
|
||||
ed.execCommand('mceInsertContent', false, h);
|
||||
} else if ( typeof quicktags != 'undefined' ) {
|
||||
quicktags.insertContent(wpActiveEditor, h);
|
||||
QTags.insertContent(wpActiveEditor, h);
|
||||
} else {
|
||||
jQuery('#'+wpActiveEditor).val( jQuery('#'+wpActiveEditor).val() + h );
|
||||
}
|
||||
@@ -582,7 +578,7 @@ class WP_Editor {
|
||||
if ( $this->ext_plugins )
|
||||
echo "$this->ext_plugins\n";
|
||||
|
||||
if ( ! $compressed && $this->tinymce ) {
|
||||
if ( ! $compressed && $tmce_on ) {
|
||||
?>
|
||||
(function(){var t=tinyMCEPreInit,sl=tinymce.ScriptLoader,ln=t.ref.language,th=t.ref.theme,pl=t.ref.plugins;sl.markDone(t.base+'/langs/'+ln+'.js');sl.markDone(t.base+'/themes/'+th+'/langs/'+ln+'.js');sl.markDone(t.base+'/themes/'+th+'/langs/'+ln+'_dlg.js');sl.markDone(t.base+'/themes/advanced/skins/wp_theme/ui.css');tinymce.each(pl.split(','),function(n){if(n&&n.charAt(0)!='-'){sl.markDone(t.base+'/plugins/'+n+'/langs/'+ln+'.js');sl.markDone(t.base+'/plugins/'+n+'/langs/'+ln+'_dlg.js');}});})();
|
||||
<?php
|
||||
@@ -605,7 +601,7 @@ class WP_Editor {
|
||||
|
||||
function wp_fullscreen_html() {
|
||||
global $content_width, $post;
|
||||
|
||||
|
||||
$width = isset($content_width) && 800 > $content_width ? $content_width : 800;
|
||||
$width = $width + 10; // compensate for the padding
|
||||
$dfw_width = get_user_setting( 'dfw_width', $width );
|
||||
@@ -616,19 +612,19 @@ class WP_Editor {
|
||||
<div id="wp-fullscreen-toolbar">
|
||||
<div id="wp-fullscreen-close"><a href="#" onclick="fullscreen.off();return false;"><?php _e('Exit fullscreen'); ?></a></div>
|
||||
<div id="wp-fullscreen-central-toolbar" style="width:<?php echo $width; ?>px;">
|
||||
|
||||
|
||||
<div id="wp-fullscreen-mode-bar"><div id="wp-fullscreen-modes">
|
||||
<a href="#" onclick="fullscreen.switchmode('tinymce');return false;"><?php _e('Visual'); ?></a>
|
||||
<a href="#" onclick="fullscreen.switchmode('html');return false;"><?php _e('HTML'); ?></a>
|
||||
</div></div>
|
||||
|
||||
|
||||
<div id="wp-fullscreen-button-bar"><div id="wp-fullscreen-buttons" class="wp_themeSkin">
|
||||
<?php
|
||||
|
||||
|
||||
$media_link_type = 'image';
|
||||
if ( is_multisite() && ( ( ! $mu_media_buttons = get_site_option( 'mu_media_buttons' ) ) || empty( $mu_media_buttons['image'] ) ) )
|
||||
$media_link_type = 'media';
|
||||
|
||||
|
||||
$buttons = array(
|
||||
// format: title, onclick, show in both editors
|
||||
'bold' => array( 'title' => __('Bold (Ctrl + B)'), 'onclick' => 'fullscreen.b();', 'both' => false ),
|
||||
@@ -645,15 +641,15 @@ class WP_Editor {
|
||||
'3' => 'separator',
|
||||
'help' => array( 'title' => __('Help (Alt + Shift + H)'), 'onclick' => 'fullscreen.help();', 'both' => false )
|
||||
);
|
||||
|
||||
|
||||
$buttons = apply_filters( 'wp_fullscreen_buttons', $buttons );
|
||||
|
||||
|
||||
foreach ( $buttons as $button => $args ) {
|
||||
if ( 'separator' == $args ) { ?>
|
||||
<div><span aria-orientation="vertical" role="separator" class="mceSeparator"></span></div>
|
||||
<?php continue;
|
||||
} ?>
|
||||
|
||||
|
||||
<div<?php if ( $args['both'] ) { ?> class="wp-fullscreen-both"<?php } ?>>
|
||||
<a title="<?php echo $args['title']; ?>" onclick="<?php echo $args['onclick']; ?>return false;" class="mceButton mceButtonEnabled mce_<?php echo $button; ?>" href="#" id="wp_fs_<?php echo $button; ?>" role="button" aria-pressed="false">
|
||||
<span class="mceIcon mce_<?php echo $button; ?>"></span>
|
||||
@@ -661,39 +657,39 @@ class WP_Editor {
|
||||
</div>
|
||||
<?php
|
||||
} ?>
|
||||
|
||||
|
||||
</div></div>
|
||||
|
||||
|
||||
<div id="wp-fullscreen-save">
|
||||
<span><?php if ( $post->post_status == 'publish' ) _e('Updated.'); else _e('Saved.'); ?></span>
|
||||
<img src="images/wpspin_light.gif" alt="" />
|
||||
<input type="button" class="button-primary" value="<?php echo $save; ?>" onclick="fullscreen.save();" />
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="wp-fullscreen-wrap" style="width:<?php echo $dfw_width; ?>px;">
|
||||
<label id="wp-fullscreen-title-prompt-text" for="wp-fullscreen-title"><?php echo apply_filters( 'enter_title_here', __( 'Enter title here' ), $post ); ?></label>
|
||||
<input type="text" id="wp-fullscreen-title" value="" autocomplete="off" />
|
||||
|
||||
|
||||
<div id="wp-fullscreen-container">
|
||||
<textarea id="wp_mce_fullscreen"></textarea>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="wp-fullscreen-status">
|
||||
<div id="wp-fullscreen-count"><?php printf( __( 'Word count: %s' ), '<span class="word-count">0</span>' ); ?></div>
|
||||
<div id="wp-fullscreen-tagline"><?php _e('Just write.'); ?></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="fullscreen-overlay" id="fullscreen-overlay"></div>
|
||||
<div class="fullscreen-overlay fullscreen-fader fade-600" id="fullscreen-fader"></div>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Performs post queries for internal linking.
|
||||
*
|
||||
@@ -705,7 +701,7 @@ class WP_Editor {
|
||||
function wp_link_query( $args = array() ) {
|
||||
$pts = get_post_types( array( 'public' => true ), 'objects' );
|
||||
$pt_names = array_keys( $pts );
|
||||
|
||||
|
||||
$query = array(
|
||||
'post_type' => $pt_names,
|
||||
'suppress_filters' => true,
|
||||
@@ -716,21 +712,21 @@ class WP_Editor {
|
||||
'orderby' => 'post_date',
|
||||
'posts_per_page' => 20,
|
||||
);
|
||||
|
||||
|
||||
$args['pagenum'] = isset( $args['pagenum'] ) ? absint( $args['pagenum'] ) : 1;
|
||||
|
||||
|
||||
if ( isset( $args['s'] ) )
|
||||
$query['s'] = $args['s'];
|
||||
|
||||
|
||||
$query['offset'] = $args['pagenum'] > 1 ? $query['posts_per_page'] * ( $args['pagenum'] - 1 ) : 0;
|
||||
|
||||
|
||||
// Do main query.
|
||||
$get_posts = new WP_Query;
|
||||
$posts = $get_posts->query( $query );
|
||||
// Check if any posts were found.
|
||||
if ( ! $get_posts->post_count )
|
||||
return false;
|
||||
|
||||
|
||||
// Build results.
|
||||
$results = array();
|
||||
foreach ( $posts as $post ) {
|
||||
@@ -738,7 +734,7 @@ class WP_Editor {
|
||||
$info = mysql2date( __( 'Y/m/d' ), $post->post_date );
|
||||
else
|
||||
$info = $pts[ $post->post_type ]->labels->singular_name;
|
||||
|
||||
|
||||
$results[] = array(
|
||||
'ID' => $post->ID,
|
||||
'title' => trim( esc_html( strip_tags( get_the_title( $post ) ) ) ),
|
||||
@@ -746,10 +742,10 @@ class WP_Editor {
|
||||
'info' => $info,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dialog for internal linking.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user