Changeset 19420 for trunk/wp-includes/class-wp-editor.php
- Timestamp:
- 11/23/2011 07:06:52 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/class-wp-editor.php
r19408 r19420 9 9 */ 10 10 11 class WP_Editor { 12 13 var $mce_settings = array(); 14 var $qt_settings = array(); 15 var $plugins = array(); 16 var $qt_buttons = array(); 17 var $mce_locale; 18 var $ext_plugins; 19 var $baseurl; 20 var $can_richedit; 21 var $default_editor; 22 var $first_init; 23 var $this_tinymce = false; 24 var $this_quicktags = false; 25 var $has_tinymce = false; 26 var $has_quicktags = false; 27 var $has_medialib = false; 28 var $editor_buttons_css = true; 29 30 function __construct() { 31 $this->can_richedit = user_can_richedit(); 32 $this->default_editor = $this->wp_default_editor(); 33 } 34 35 function parse_settings($editor_id, $settings) { 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 28 private function __construct() {} 29 30 public static function parse_settings($editor_id, $settings) { 36 31 $set = wp_parse_args( $settings, array( 37 32 'wpautop' => true, // use wpautop? … … 44 39 'teeny' => false, // output the minimal editor config used in Press This 45 40 'dfw' => false, // replace the default fullscreen with DFW (needs specific DOM elements and css) 46 'tinymce' => true, // load TinyMCE, can be used to pass settings directly to TinyMCE using an array()41 'tinymce' => null, // load TinyMCE, can be used to pass settings directly to TinyMCE using an array() 47 42 'quicktags' => true // load Quicktags, can be used to pass settings directly to Quicktags using an array() 48 43 ) ); 49 44 50 $this->this_tinymce = !empty($set['tinymce']) && $this->can_richedit; 51 $this->this_quicktags = !empty($set['quicktags']); 52 53 if ( $this->this_tinymce ) 54 $this->has_tinymce = true; 55 56 if ( $this->this_quicktags ) 57 $this->has_quicktags = true; 45 if ( null === $set['tinymce'] ) 46 self::$this_tinymce = user_can_richedit(); 47 else 48 self::$this_tinymce = (bool) $set['tinymce']; 49 50 self::$this_quicktags = (bool) $set['quicktags']; 51 52 if ( self::$this_tinymce ) 53 self::$has_tinymce = true; 54 55 if ( self::$this_quicktags ) 56 self::$has_quicktags = true; 58 57 59 58 return $set; … … 65 64 * @param string $content The initial content of the editor. 66 65 * @param string $editor_id ID for the textarea and TinyMCE and Quicktags instances (can contain only ASCII letters and numbers). 67 * @param array $settings See WP_Editor::_parse_settingsfor description.66 * @param array $settings See the _parse_settings() method for description. 68 67 */ 69 function editor( $content, $editor_id, $settings = array() ) {70 71 $set = $this->parse_settings($editor_id, $settings);68 public static function editor( $content, $editor_id, $settings = array() ) { 69 70 $set = self::parse_settings($editor_id, $settings); 72 71 $editor_class = ' class="' . trim( $set['editor_class'] . ' wp-editor-area' ) . '"'; 73 72 $tabindex = $set['tabindex'] ? ' tabindex="' . (int) $set['tabindex'] . '"' : ''; … … 79 78 $set['media_buttons'] = false; 80 79 81 if ( $this->this_quicktags && $this->this_tinymce ) {80 if ( self::$this_quicktags && self::$this_tinymce ) { 82 81 $switch_class = 'html-active'; 83 82 84 if ( 'html' == $this->default_editor) {83 if ( 'html' == wp_default_editor() ) { 85 84 add_filter('the_editor_content', 'wp_htmledit_pre'); 86 85 } else { … … 95 94 echo '<div id="wp-' . $editor_id . '-wrap" class="wp-editor-wrap ' . $switch_class . '">'; 96 95 97 if ( $this->editor_buttons_css ) {96 if ( self::$editor_buttons_css ) { 98 97 wp_print_styles('editor-buttons'); 99 $this->editor_buttons_css = false;98 self::$editor_buttons_css = false; 100 99 } 101 100 … … 108 107 109 108 if ( $set['media_buttons'] ) { 110 $this->has_medialib = true;109 self::$has_medialib = true; 111 110 112 111 if ( !function_exists('media_buttons') ) … … 126 125 echo "\n</div>\n\n"; 127 126 128 $this->editor_settings($editor_id, $set);129 } 130 131 function editor_settings($editor_id, $set) {127 self::editor_settings($editor_id, $set); 128 } 129 130 public static function editor_settings($editor_id, $set) { 132 131 global $editor_styles; 133 132 $first_run = false; 134 133 135 if ( empty( $this->first_init) ) {134 if ( empty(self::$first_init) ) { 136 135 if ( is_admin() ) { 137 add_action( 'admin_print_footer_scripts', array( $this, 'editor_js'), 50 );138 add_action( 'admin_footer', array( $this, 'enqueue_scripts'), 1 );136 add_action( 'admin_print_footer_scripts', array( __CLASS__, 'editor_js'), 50 ); 137 add_action( 'admin_footer', array( __CLASS__, 'enqueue_scripts'), 1 ); 139 138 } else { 140 add_action( 'wp_print_footer_scripts', array( $this, 'editor_js'), 50 );141 add_action( 'wp_footer', array( $this, 'enqueue_scripts'), 1 );142 } 143 } 144 145 if ( $this->this_quicktags ) {139 add_action( 'wp_print_footer_scripts', array( __CLASS__, 'editor_js'), 50 ); 140 add_action( 'wp_footer', array( __CLASS__, 'enqueue_scripts'), 1 ); 141 } 142 } 143 144 if ( self::$this_quicktags ) { 146 145 147 146 $qtInit = array( … … 160 159 161 160 $qtInit = apply_filters('quicktags_settings', $qtInit, $editor_id); 162 $this->qt_settings[$editor_id] = $qtInit;163 164 $this->qt_buttons = array_merge( $this->qt_buttons, explode(',', $qtInit['buttons']) );165 } 166 167 if ( $this->this_tinymce ) {168 169 if ( empty( $this->first_init) ) {170 $this->baseurl = includes_url('js/tinymce');171 $this->mce_locale = $mce_locale = ( '' == get_locale() ) ? 'en' : strtolower( substr(get_locale(), 0, 2) ); // only ISO 639-1161 self::$qt_settings[$editor_id] = $qtInit; 162 163 self::$qt_buttons = array_merge( self::$qt_buttons, explode(',', $qtInit['buttons']) ); 164 } 165 166 if ( self::$this_tinymce ) { 167 168 if ( empty(self::$first_init) ) { 169 self::$baseurl = includes_url('js/tinymce'); 170 self::$mce_locale = $mce_locale = ( '' == get_locale() ) ? 'en' : strtolower( substr(get_locale(), 0, 2) ); // only ISO 639-1 172 171 $no_captions = (bool) apply_filters( 'disable_captions', '' ); 173 172 $plugins = array( 'inlinepopups', 'spellchecker', 'tabfocus', 'paste', 'media', 'fullscreen', 'wordpress', 'wpeditimage', 'wpgallery', 'wplink', 'wpdialogs' ); … … 175 174 176 175 if ( $set['teeny'] ) { 177 $this->plugins = $plugins = apply_filters( 'teeny_mce_plugins', array('inlinepopups', 'fullscreen', 'wordpress', 'wplink', 'wpdialogs'), $editor_id );176 self::$plugins = $plugins = apply_filters( 'teeny_mce_plugins', array('inlinepopups', 'fullscreen', 'wordpress', 'wplink', 'wpdialogs'), $editor_id ); 178 177 $ext_plugins = ''; 179 178 } else { … … 254 253 $ext_plugins .= 'tinymce.PluginManager.load("' . $name . '", "' . $url . '");' . "\n"; 255 254 256 $this->ext_plugins .= $ext_plugins;255 self::$ext_plugins .= $ext_plugins; 257 256 } 258 257 } … … 264 263 $plugins[] = 'wpfullscreen'; 265 264 266 $this->plugins = $plugins;265 self::$plugins = $plugins; 267 266 268 267 /* … … 274 273 $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'); 275 274 276 $this->first_init = array(275 self::$first_init = array( 277 276 'mode' => 'exact', 278 277 'width' => '100%', 279 278 'theme' => 'advanced', 280 279 'skin' => 'wp_theme', 281 'language' => $this->mce_locale,280 'language' => self::$mce_locale, 282 281 'spellchecker_languages' => $mce_spellchecker_languages, 283 282 'theme_advanced_toolbar_location' => 'top', … … 318 317 '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', 319 318 'wpeditimage_disable_captions' => $no_captions, 320 'wp_fullscreen_content_css' => "$this->baseurl/plugins/wpfullscreen/css/wp-fullscreen.css",319 'wp_fullscreen_content_css' => self::$baseurl . '/plugins/wpfullscreen/css/wp-fullscreen.css', 321 320 'plugins' => implode( ',', $plugins ) 322 321 ); … … 353 352 354 353 if ( ! empty($mce_css) ) 355 $this->first_init['content_css'] = $mce_css;354 self::$first_init['content_css'] = $mce_css; 356 355 } 357 356 … … 390 389 391 390 if ( $first_run ) 392 $mceInit = array_merge( $this->first_init, $mceInit);391 $mceInit = array_merge(self::$first_init, $mceInit); 393 392 394 393 if ( is_array($set['tinymce']) ) … … 410 409 } 411 410 412 $this->mce_settings[$editor_id] = $mceInit;413 } // end if $this->this_tinymce414 } 415 416 function _parse_init($init) {411 self::$mce_settings[$editor_id] = $mceInit; 412 } // end if self::$this_tinymce 413 } 414 415 private static function _parse_init($init) { 417 416 $options = ''; 418 417 … … 432 431 } 433 432 434 /** 435 * Find out which editor should be displayed by default. 436 * 437 * Works out which of the two editors to display as the current editor for a 438 * user. 439 * 440 * @since 2.5.0 441 * 442 * @return string Either 'tinymce', or 'html', or 'test' 443 */ 444 function wp_default_editor() { 445 $r = user_can_richedit() ? 'tinymce' : 'html'; // defaults 446 if ( $user = wp_get_current_user() ) { // look for cookie 447 $ed = get_user_setting('editor', 'tinymce'); 448 $r = ( in_array($ed, array('tinymce', 'html', 'test') ) ) ? $ed : $r; 449 } 450 return apply_filters( 'wp_default_editor', $r ); // filter 451 } 452 453 function enqueue_scripts() { 433 public static function enqueue_scripts() { 454 434 wp_enqueue_script('word-count'); 455 435 456 if ( $this->has_tinymce )436 if ( self::$has_tinymce ) 457 437 wp_enqueue_script('editor'); 458 438 459 if ( $this->has_quicktags )439 if ( self::$has_quicktags ) 460 440 wp_enqueue_script('quicktags'); 461 441 462 if ( in_array('wplink', $this->plugins, true) || in_array('link', $this->qt_buttons, true) ) {442 if ( in_array('wplink', self::$plugins, true) || in_array('link', self::$qt_buttons, true) ) { 463 443 wp_enqueue_script('wplink'); 464 444 wp_enqueue_script('wpdialogs-popup'); … … 466 446 } 467 447 468 if ( in_array('wpfullscreen', $this->plugins, true) || in_array('fullscreen', $this->qt_buttons, true) )448 if ( in_array('wpfullscreen', self::$plugins, true) || in_array('fullscreen', self::$qt_buttons, true) ) 469 449 wp_enqueue_script('wp-fullscreen'); 470 450 471 if ( $this->has_medialib ) {451 if ( self::$has_medialib ) { 472 452 add_thickbox(); 473 453 wp_enqueue_script('media-upload'); … … 475 455 } 476 456 477 function editor_js() {457 public static function editor_js() { 478 458 global $tinymce_version, $concatenate_scripts, $compress_scripts; 479 459 … … 486 466 */ 487 467 $version = 'ver=' . $tinymce_version; 488 $tmce_on = !empty( $this->mce_settings);468 $tmce_on = !empty(self::$mce_settings); 489 469 490 470 if ( ! isset($concatenate_scripts) ) … … 494 474 && false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'); 495 475 496 if ( $tmce_on && 'en' != $this->mce_locale )476 if ( $tmce_on && 'en' != self::$mce_locale ) 497 477 include_once(ABSPATH . WPINC . '/js/tinymce/langs/wp-langs.php'); 498 478 499 479 $mceInit = $qtInit = ''; 500 480 if ( $tmce_on ) { 501 foreach ( $this->mce_settings as $editor_id => $init ) {502 $options = $this->_parse_init( $init );481 foreach ( self::$mce_settings as $editor_id => $init ) { 482 $options = self::_parse_init( $init ); 503 483 $mceInit .= "'$editor_id':{$options},"; 504 484 } … … 508 488 } 509 489 510 if ( !empty( $this->qt_settings) ) {511 foreach ( $this->qt_settings as $editor_id => $init ) {512 $options = $this->_parse_init( $init );490 if ( !empty(self::$qt_settings) ) { 491 foreach ( self::$qt_settings as $editor_id => $init ) { 492 $options = self::_parse_init( $init ); 513 493 $qtInit .= "'$editor_id':{$options},"; 514 494 } … … 519 499 520 500 $ref = array( 521 'plugins' => implode( ',', $this->plugins ),501 'plugins' => implode( ',', self::$plugins ), 522 502 'theme' => 'advanced', 523 'language' => $this->mce_locale503 'language' => self::$mce_locale 524 504 ); 525 505 526 do_action('before_wp_tiny_mce', $this->mce_settings);506 do_action('before_wp_tiny_mce', self::$mce_settings); 527 507 ?> 528 508 529 509 <script type="text/javascript"> 530 510 tinyMCEPreInit = { 531 base : "<?php echo $this->baseurl; ?>",511 base : "<?php echo self::$baseurl; ?>", 532 512 suffix : "", 533 513 query : "<?php echo $version; ?>", 534 514 mceInit : <?php echo $mceInit; ?>, 535 515 qtInit : <?php echo $qtInit; ?>, 536 ref : <?php echo $this->_parse_init( $ref ); ?>,516 ref : <?php echo self::_parse_init( $ref ); ?>, 537 517 load_ext : function(url,lang){var sl=tinymce.ScriptLoader;sl.markDone(url+'/langs/'+lang+'.js');sl.markDone(url+'/langs/'+lang+'_dlg.js');} 538 518 }; … … 540 520 <?php 541 521 522 $baseurl = self::$baseurl; 523 542 524 if ( $tmce_on ) { 543 525 if ( $compressed ) 544 echo "<script type='text/javascript' src=' $this->baseurl/wp-tinymce.php?c=1&$version'></script>\n";526 echo "<script type='text/javascript' src='{$baseurl}/wp-tinymce.php?c=1&$version'></script>\n"; 545 527 else 546 echo "<script type='text/javascript' src=' $this->baseurl/tiny_mce.js?$version'></script>\n";547 548 if ( 'en' != $this->mce_locale && isset($lang) )528 echo "<script type='text/javascript' src='{$baseurl}/tiny_mce.js?$version'></script>\n"; 529 530 if ( 'en' != self::$mce_locale && isset($lang) ) 549 531 echo "<script type='text/javascript'>\n$lang\n</script>\n"; 550 532 else 551 echo "<script type='text/javascript' src=' $this->baseurl/langs/wp-langs-en.js?$version'></script>\n";533 echo "<script type='text/javascript' src='{$baseurl}/langs/wp-langs-en.js?$version'></script>\n"; 552 534 } 553 535 ?> … … 555 537 <script type="text/javascript"> 556 538 (function(){ 557 var init, ed, qt, first_init, mce = <?php echo $this->default_editor== 'tinymce' ? 'true' : 'false'; ?>;539 var init, ed, qt, first_init, mce = <?php echo wp_default_editor() == 'tinymce' ? 'true' : 'false'; ?>; 558 540 559 541 if ( typeof(tinymce) == 'object' ) { … … 585 567 <?php 586 568 587 if ( $this->ext_plugins )588 echo "$this->ext_plugins\n";569 if ( self::$ext_plugins ) 570 echo self::$ext_plugins . "\n"; 589 571 590 572 if ( ! $compressed && $tmce_on ) { … … 600 582 <?php 601 583 602 if ( in_array('wplink', $this->plugins, true) || in_array('link', $this->qt_buttons, true) )603 $this->wp_link_dialog();604 605 if ( in_array('wpfullscreen', $this->plugins, true) || in_array('fullscreen', $this->qt_buttons, true) )606 $this->wp_fullscreen_html();607 608 do_action('after_wp_tiny_mce', $this->mce_settings);609 } 610 611 function wp_fullscreen_html() {584 if ( in_array('wplink', self::$plugins, true) || in_array('link', self::$qt_buttons, true) ) 585 self::wp_link_dialog(); 586 587 if ( in_array('wpfullscreen', self::$plugins, true) || in_array('fullscreen', self::$qt_buttons, true) ) 588 self::wp_fullscreen_html(); 589 590 do_action('after_wp_tiny_mce', self::$mce_settings); 591 } 592 593 public static function wp_fullscreen_html() { 612 594 global $content_width, $post; 613 595 … … 706 688 * @return array Results. 707 689 */ 708 function wp_link_query( $args = array() ) {690 public static function wp_link_query( $args = array() ) { 709 691 $pts = get_post_types( array( 'public' => true ), 'objects' ); 710 692 $pt_names = array_keys( $pts ); … … 759 741 * @since 3.1.0 760 742 */ 761 function wp_link_dialog() {743 public static function wp_link_dialog() { 762 744 ?> 763 745 <div style="display:none;">
Note: See TracChangeset
for help on using the changeset viewer.