web/wp-includes/class-wp-editor.php
changeset 204 09a1c134465b
parent 194 32102edaa81b
equal deleted inserted replaced
203:f507feede89a 204:09a1c134465b
    30 	public static function parse_settings($editor_id, $settings) {
    30 	public static function parse_settings($editor_id, $settings) {
    31 		$set = wp_parse_args( $settings,  array(
    31 		$set = wp_parse_args( $settings,  array(
    32 			'wpautop' => true, // use wpautop?
    32 			'wpautop' => true, // use wpautop?
    33 			'media_buttons' => true, // show insert/upload button(s)
    33 			'media_buttons' => true, // show insert/upload button(s)
    34 			'textarea_name' => $editor_id, // set the textarea name to something different, square brackets [] can be used here
    34 			'textarea_name' => $editor_id, // set the textarea name to something different, square brackets [] can be used here
    35 			'textarea_rows' => get_option('default_post_edit_rows', 10), // rows="..."
    35 			'textarea_rows' => 20,
    36 			'tabindex' => '',
    36 			'tabindex' => '',
    37 			'editor_css' => '', // intended for extra styles for both visual and HTML editors buttons, needs to include the <style> tags, can use "scoped".
    37 			'tabfocus_elements' => ':prev,:next', // the previous and next element ID to move the focus to when pressing the Tab key in TinyMCE
       
    38 			'editor_css' => '', // intended for extra styles for both visual and Text editors buttons, needs to include the <style> tags, can use "scoped".
    38 			'editor_class' => '', // add extra class(es) to the editor textarea
    39 			'editor_class' => '', // add extra class(es) to the editor textarea
    39 			'teeny' => false, // output the minimal editor config used in Press This
    40 			'teeny' => false, // output the minimal editor config used in Press This
    40 			'dfw' => false, // replace the default fullscreen with DFW (needs specific DOM elements and css)
    41 			'dfw' => false, // replace the default fullscreen with DFW (needs specific DOM elements and css)
    41 			'tinymce' => true, // load TinyMCE, can be used to pass settings directly to TinyMCE using an array()
    42 			'tinymce' => true, // load TinyMCE, can be used to pass settings directly to TinyMCE using an array()
    42 			'quicktags' => true // load Quicktags, can be used to pass settings directly to Quicktags using an array()
    43 			'quicktags' => true // load Quicktags, can be used to pass settings directly to Quicktags using an array()
    48 		if ( self::$this_tinymce )
    49 		if ( self::$this_tinymce )
    49 			self::$has_tinymce = true;
    50 			self::$has_tinymce = true;
    50 
    51 
    51 		if ( self::$this_quicktags )
    52 		if ( self::$this_quicktags )
    52 			self::$has_quicktags = true;
    53 			self::$has_quicktags = true;
       
    54 
       
    55 		if ( empty( $set['editor_height'] ) )
       
    56 			return $set;
       
    57 
       
    58 		if ( 'content' === $editor_id ) {
       
    59 			// A cookie (set when a user resizes the editor) overrides the height.
       
    60 			$cookie = (int) get_user_setting( 'ed_size' );
       
    61 
       
    62 			// Upgrade an old TinyMCE cookie if it is still around, and the new one isn't.
       
    63 			if ( ! $cookie && isset( $_COOKIE['TinyMCE_content_size'] ) ) {
       
    64 				parse_str( $_COOKIE['TinyMCE_content_size'], $cookie );
       
    65  				$cookie = $cookie['ch'];
       
    66 			}
       
    67 
       
    68 			if ( $cookie )
       
    69 				$set['editor_height'] = $cookie;
       
    70 		}
       
    71 
       
    72 		if ( $set['editor_height'] < 50 )
       
    73 			$set['editor_height'] = 50;
       
    74 		elseif ( $set['editor_height'] > 5000 )
       
    75 			$set['editor_height'] = 5000;
    53 
    76 
    54 		return $set;
    77 		return $set;
    55 	}
    78 	}
    56 
    79 
    57 	/**
    80 	/**
    64 	public static function editor( $content, $editor_id, $settings = array() ) {
    87 	public static function editor( $content, $editor_id, $settings = array() ) {
    65 
    88 
    66 		$set = self::parse_settings($editor_id, $settings);
    89 		$set = self::parse_settings($editor_id, $settings);
    67 		$editor_class = ' class="' . trim( $set['editor_class'] . ' wp-editor-area' ) . '"';
    90 		$editor_class = ' class="' . trim( $set['editor_class'] . ' wp-editor-area' ) . '"';
    68 		$tabindex = $set['tabindex'] ? ' tabindex="' . (int) $set['tabindex'] . '"' : '';
    91 		$tabindex = $set['tabindex'] ? ' tabindex="' . (int) $set['tabindex'] . '"' : '';
    69 		$rows = ' rows="' . (int) $set['textarea_rows'] . '"';
       
    70 		$switch_class = 'html-active';
    92 		$switch_class = 'html-active';
    71 		$toolbar = $buttons = '';
    93 		$toolbar = $buttons = '';
    72 
    94 
       
    95 		if ( ! empty( $set['editor_height'] ) )
       
    96 			$height = ' style="height: ' . $set['editor_height'] . 'px"';
       
    97 		else
       
    98 			$height = ' rows="' . $set['textarea_rows'] . '"';
       
    99 
    73 		if ( !current_user_can( 'upload_files' ) )
   100 		if ( !current_user_can( 'upload_files' ) )
    74 			$set['media_buttons'] = false;
   101 			$set['media_buttons'] = false;
    75 
   102 
    76 		if ( self::$this_quicktags && self::$this_tinymce ) {
   103 		if ( self::$this_quicktags && self::$this_tinymce ) {
    77 			$switch_class = 'html-active';
   104 			$switch_class = 'html-active';
    78 
   105 
       
   106 			// 'html' and 'switch-html' are used for the "Text" editor tab.
    79 			if ( 'html' == wp_default_editor() ) {
   107 			if ( 'html' == wp_default_editor() ) {
    80 				add_filter('the_editor_content', 'wp_htmledit_pre');
   108 				add_filter('the_editor_content', 'wp_htmledit_pre');
    81 			} else {
   109 			} else {
    82 				add_filter('the_editor_content', 'wp_richedit_pre');
   110 				add_filter('the_editor_content', 'wp_richedit_pre');
    83 				$switch_class = 'tmce-active';
   111 				$switch_class = 'tmce-active';
    84 			}
   112 			}
    85 
   113 
    86 			$buttons .= '<a id="' . $editor_id . '-html" class="hide-if-no-js wp-switch-editor switch-html" onclick="switchEditors.switchto(this);">' . __('HTML') . "</a>\n";
   114 			$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";
    87 			$buttons .= '<a id="' . $editor_id . '-tmce" class="hide-if-no-js wp-switch-editor switch-tmce" onclick="switchEditors.switchto(this);">' . __('Visual') . "</a>\n";
   115 			$buttons .= '<a id="' . $editor_id . '-tmce" class="wp-switch-editor switch-tmce" onclick="switchEditors.switchto(this);">' . __('Visual') . "</a>\n";
    88 		}
   116 		}
    89 
   117 
    90 		echo '<div id="wp-' . $editor_id . '-wrap" class="wp-editor-wrap ' . $switch_class . '">';
   118 		echo '<div id="wp-' . $editor_id . '-wrap" class="wp-core-ui wp-editor-wrap ' . $switch_class . '">';
    91 
   119 
    92 		if ( self::$editor_buttons_css ) {
   120 		if ( self::$editor_buttons_css ) {
    93 			wp_print_styles('editor-buttons');
   121 			wp_print_styles('editor-buttons');
    94 			self::$editor_buttons_css = false;
   122 			self::$editor_buttons_css = false;
    95 		}
   123 		}
    96 
   124 
    97 		if ( !empty($set['editor_css']) )
   125 		if ( !empty($set['editor_css']) )
    98 			echo $set['editor_css'] . "\n";
   126 			echo $set['editor_css'] . "\n";
    99 
   127 
   100 		if ( !empty($buttons) || $set['media_buttons'] ) {
   128 		if ( !empty($buttons) || $set['media_buttons'] ) {
   101 			echo '<div id="wp-' . $editor_id . '-editor-tools" class="wp-editor-tools">';
   129 			echo '<div id="wp-' . $editor_id . '-editor-tools" class="wp-editor-tools hide-if-no-js">';
   102 			echo $buttons;
   130 			echo $buttons;
   103 
   131 
   104 			if ( $set['media_buttons'] ) {
   132 			if ( $set['media_buttons'] ) {
   105 				self::$has_medialib = true;
   133 				self::$has_medialib = true;
   106 
   134 
   107 				if ( !function_exists('media_buttons') )
   135 				if ( !function_exists('media_buttons') )
   108 					include(ABSPATH . 'wp-admin/includes/media.php');
   136 					include(ABSPATH . 'wp-admin/includes/media.php');
   109 
   137 
   110 				echo '<div id="wp-' . $editor_id . '-media-buttons" class="hide-if-no-js wp-media-buttons">';
   138 				echo '<div id="wp-' . $editor_id . '-media-buttons" class="wp-media-buttons">';
   111 				do_action('media_buttons', $editor_id);
   139 				do_action('media_buttons', $editor_id);
   112 				echo "</div>\n";
   140 				echo "</div>\n";
   113 			}
   141 			}
   114 			echo "</div>\n";
   142 			echo "</div>\n";
   115 		}
   143 		}
   116 
   144 
   117 		$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>');
   145 		$the_editor = apply_filters('the_editor', '<div id="wp-' . $editor_id . '-editor-container" class="wp-editor-container"><textarea' . $editor_class . $height . $tabindex . ' cols="40" name="' . $set['textarea_name'] . '" id="' . $editor_id . '">%s</textarea></div>');
   118 		$content = apply_filters('the_editor_content', $content);
   146 		$content = apply_filters('the_editor_content', $content);
   119 
   147 
   120 		printf($the_editor, $content);
   148 		printf($the_editor, $content);
   121 		echo "\n</div>\n\n";
   149 		echo "\n</div>\n\n";
   122 
   150 
   123 		self::editor_settings($editor_id, $set);
   151 		self::editor_settings($editor_id, $set);
   124 	}
   152 	}
   125 
   153 
   126 	public static function editor_settings($editor_id, $set) {
   154 	public static function editor_settings($editor_id, $set) {
   127 		global $editor_styles, $post;
   155 		global $editor_styles;
   128 		$first_run = false;
   156 		$first_run = false;
   129 
   157 
   130 		if ( empty(self::$first_init) ) {
   158 		if ( empty(self::$first_init) ) {
   131 			if ( is_admin() ) {
   159 			if ( is_admin() ) {
   132 				add_action( 'admin_print_footer_scripts', array( __CLASS__, 'editor_js'), 50 );
   160 				add_action( 'admin_print_footer_scripts', array( __CLASS__, 'editor_js'), 50 );
   168 				$plugins = array( 'inlinepopups', 'spellchecker', 'tabfocus', 'paste', 'media', 'fullscreen', 'wordpress', 'wpeditimage', 'wpgallery', 'wplink', 'wpdialogs' );
   196 				$plugins = array( 'inlinepopups', 'spellchecker', 'tabfocus', 'paste', 'media', 'fullscreen', 'wordpress', 'wpeditimage', 'wpgallery', 'wplink', 'wpdialogs' );
   169 				$first_run = true;
   197 				$first_run = true;
   170 				$ext_plugins = '';
   198 				$ext_plugins = '';
   171 
   199 
   172 				if ( $set['teeny'] ) {
   200 				if ( $set['teeny'] ) {
   173 					self::$plugins = $plugins = apply_filters( 'teeny_mce_plugins', array('inlinepopups', 'fullscreen', 'wordpress', 'wplink', 'wpdialogs'), $editor_id );
   201 					self::$plugins = $plugins = apply_filters( 'teeny_mce_plugins', array('inlinepopups', 'fullscreen', 'wordpress', 'wplink', 'wpdialogs' ), $editor_id );
   174 				} else {
   202 				} else {
   175 					/*
   203 					/*
   176 					The following filter takes an associative array of external plugins for TinyMCE in the form 'plugin_name' => 'url'.
   204 					The following filter takes an associative array of external plugins for TinyMCE in the form 'plugin_name' => 'url'.
   177 					It adds the plugin's name to TinyMCE's plugins init and the call to PluginManager to load the plugin.
   205 					It adds the plugin's name to TinyMCE's plugins init and the call to PluginManager to load the plugin.
   178 					The url should be absolute and should include the js file name to be loaded. Example:
   206 					The url should be absolute and should include the js file name to be loaded. Example:
   207 							}
   235 							}
   208 						}
   236 						}
   209 
   237 
   210 						foreach ( $mce_external_plugins as $name => $url ) {
   238 						foreach ( $mce_external_plugins as $name => $url ) {
   211 
   239 
   212 							if ( is_ssl() ) $url = str_replace('http://', 'https://', $url);
   240 							$url = set_url_scheme( $url );
   213 
   241 
   214 							$plugins[] = '-' . $name;
   242 							$plugins[] = '-' . $name;
   215 
   243 
   216 							$plugurl = dirname($url);
   244 							$plugurl = dirname($url);
   217 							$strings = $str1 = $str2 = '';
   245 							$strings = $str1 = $str2 = '';
   308 					'gecko_spellcheck' => true,
   336 					'gecko_spellcheck' => true,
   309 					'fix_list_elements' => true,
   337 					'fix_list_elements' => true,
   310 					'keep_styles' => false,
   338 					'keep_styles' => false,
   311 					'entities' => '38,amp,60,lt,62,gt',
   339 					'entities' => '38,amp,60,lt,62,gt',
   312 					'accessibility_focus' => true,
   340 					'accessibility_focus' => true,
   313 					'tabfocus_elements' => 'title,publish',
       
   314 					'media_strict' => false,
   341 					'media_strict' => false,
   315 					'paste_remove_styles' => true,
   342 					'paste_remove_styles' => true,
   316 					'paste_remove_spans' => true,
   343 					'paste_remove_spans' => true,
   317 					'paste_strip_class_attributes' => 'all',
   344 					'paste_strip_class_attributes' => 'all',
   318 					'paste_text_use_dialog' => true,
   345 					'paste_text_use_dialog' => true,
       
   346 					'webkit_fake_resize' => false,
   319 					'spellchecker_rpc_url' => self::$baseurl . '/plugins/spellchecker/rpc.php',
   347 					'spellchecker_rpc_url' => self::$baseurl . '/plugins/spellchecker/rpc.php',
   320 					'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',
   348 					'schema' => 'html5',
   321 					'wpeditimage_disable_captions' => $no_captions,
   349 					'wpeditimage_disable_captions' => $no_captions,
   322 					'wp_fullscreen_content_css' => self::$baseurl . '/plugins/wpfullscreen/css/wp-fullscreen.css',
   350 					'wp_fullscreen_content_css' => self::$baseurl . '/plugins/wpfullscreen/css/wp-fullscreen.css',
   323 					'plugins' => implode( ',', $plugins )
   351 					'plugins' => implode( ',', $plugins )
   324 				);
   352 				);
   325 
   353 
   333 					if ( is_child_theme() ) {
   361 					if ( is_child_theme() ) {
   334 						$template_uri = get_template_directory_uri();
   362 						$template_uri = get_template_directory_uri();
   335 						$template_dir = get_template_directory();
   363 						$template_dir = get_template_directory();
   336 
   364 
   337 						foreach ( $editor_styles as $key => $file ) {
   365 						foreach ( $editor_styles as $key => $file ) {
   338 							if ( $file && file_exists( "$template_dir/$file" ) ) {
   366 							if ( $file && file_exists( "$template_dir/$file" ) )
   339 								$mce_css[] = "$template_uri/$file";
   367 								$mce_css[] = "$template_uri/$file";
   340 							}
       
   341 						}
   368 						}
   342 					}
   369 					}
   343 
   370 
   344 					foreach ( $editor_styles as $file ) {
   371 					foreach ( $editor_styles as $file ) {
   345 						if ( $file && file_exists( "$style_dir/$file" ) )
   372 						if ( $file && file_exists( "$style_dir/$file" ) )
   356 				if ( ! empty($mce_css) )
   383 				if ( ! empty($mce_css) )
   357 					self::$first_init['content_css'] = $mce_css;
   384 					self::$first_init['content_css'] = $mce_css;
   358 			}
   385 			}
   359 
   386 
   360 			if ( $set['teeny'] ) {
   387 			if ( $set['teeny'] ) {
   361 				$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 );
   388 				$mce_buttons = apply_filters( 'teeny_mce_buttons', array('bold', 'italic', 'underline', 'blockquote', 'strikethrough', 'bullist', 'numlist', 'justifyleft', 'justifycenter', 'justifyright', 'undo', 'redo', 'link', 'unlink', 'fullscreen'), $editor_id );
   362 				$mce_buttons_2 = $mce_buttons_3 = $mce_buttons_4 = array();
   389 				$mce_buttons_2 = $mce_buttons_3 = $mce_buttons_4 = array();
   363 			} else {
   390 			} else {
   364 				$mce_buttons = apply_filters('mce_buttons', array('bold', 'italic', 'strikethrough', '|', 'bullist', 'numlist', 'blockquote', '|', 'justifyleft', 'justifycenter', 'justifyright', '|', 'link', 'unlink', 'wp_more', '|', 'spellchecker', 'fullscreen', 'wp_adv' ), $editor_id);
   391 				$mce_buttons = apply_filters('mce_buttons', array('bold', 'italic', 'strikethrough', 'bullist', 'numlist', 'blockquote', 'justifyleft', 'justifycenter', 'justifyright', 'link', 'unlink', 'wp_more', 'spellchecker', 'fullscreen', 'wp_adv' ), $editor_id);
   365 				$mce_buttons_2 = apply_filters('mce_buttons_2', array( 'formatselect', 'underline', 'justifyfull', 'forecolor', '|', 'pastetext', 'pasteword', 'removeformat', '|', 'charmap', '|', 'outdent', 'indent', '|', 'undo', 'redo', 'wp_help' ), $editor_id);
   392 				$mce_buttons_2 = apply_filters('mce_buttons_2', array( 'formatselect', 'underline', 'justifyfull', 'forecolor', 'pastetext', 'pasteword', 'removeformat', 'charmap', 'outdent', 'indent', 'undo', 'redo', 'wp_help' ), $editor_id);
   366 				$mce_buttons_3 = apply_filters('mce_buttons_3', array(), $editor_id);
   393 				$mce_buttons_3 = apply_filters('mce_buttons_3', array(), $editor_id);
   367 				$mce_buttons_4 = apply_filters('mce_buttons_4', array(), $editor_id);
   394 				$mce_buttons_4 = apply_filters('mce_buttons_4', array(), $editor_id);
   368 			}
   395 			}
   369 
   396 
   370 			$body_class = $editor_id;
   397 			$body_class = $editor_id;
   371 
   398 
   372 			if ( isset($post) )
   399 			if ( $post = get_post() )
   373 				$body_class .= " post-type-$post->post_type";
   400 				$body_class .= ' post-type-' . $post->post_type;
   374 
   401 
   375 			if ( !empty($set['tinymce']['body_class']) ) {
   402 			if ( !empty($set['tinymce']['body_class']) ) {
   376 				$body_class .= ' ' . $set['tinymce']['body_class'];
   403 				$body_class .= ' ' . $set['tinymce']['body_class'];
   377 				unset($set['tinymce']['body_class']);
   404 				unset($set['tinymce']['body_class']);
   378 			}
   405 			}
   396 				'apply_source_formatting' => (bool) !$set['wpautop'],
   423 				'apply_source_formatting' => (bool) !$set['wpautop'],
   397 				'theme_advanced_buttons1' => implode($mce_buttons, ','),
   424 				'theme_advanced_buttons1' => implode($mce_buttons, ','),
   398 				'theme_advanced_buttons2' => implode($mce_buttons_2, ','),
   425 				'theme_advanced_buttons2' => implode($mce_buttons_2, ','),
   399 				'theme_advanced_buttons3' => implode($mce_buttons_3, ','),
   426 				'theme_advanced_buttons3' => implode($mce_buttons_3, ','),
   400 				'theme_advanced_buttons4' => implode($mce_buttons_4, ','),
   427 				'theme_advanced_buttons4' => implode($mce_buttons_4, ','),
       
   428 				'tabfocus_elements' => $set['tabfocus_elements'],
   401 				'body_class' => $body_class
   429 				'body_class' => $body_class
   402 			);
   430 			);
   403 
   431 
       
   432 			// The main editor doesn't use the TinyMCE resizing cookie.
       
   433 			$mceInit['theme_advanced_resizing_use_cookie'] = 'content' !== $editor_id || empty( $set['editor_height'] );
       
   434 
   404 			if ( $first_run )
   435 			if ( $first_run )
   405 				$mceInit = array_merge(self::$first_init, $mceInit);
   436 				$mceInit = array_merge(self::$first_init, $mceInit);
   406 
   437 
   407 			if ( is_array($set['tinymce']) )
   438 			if ( is_array($set['tinymce']) )
   408 				$mceInit = array_merge($mceInit, $set['tinymce']);
   439 				$mceInit = array_merge($mceInit, $set['tinymce']);
   409 
   440 
   410 			// For people who really REALLY know what they're doing with TinyMCE
   441 			// For people who really REALLY know what they're doing with TinyMCE
   411 			// You can modify initArray to add, remove, change elements of the config before tinyMCE.init
   442 			// You can modify $mceInit to add, remove, change elements of the config before tinyMCE.init
   412 			// Setting "valid_elements", "invalid_elements" and "extended_valid_elements" can be done through this filter.
   443 			// Setting "valid_elements", "invalid_elements" and "extended_valid_elements" can be done through this filter.
   413 			// Best is to use the default cleanup by not specifying valid_elements, as TinyMCE contains full set of XHTML 1.0.
   444 			// Best is to use the default cleanup by not specifying valid_elements, as TinyMCE contains full set of XHTML 1.0.
   414 			if ( $set['teeny'] ) {
   445 			if ( $set['teeny'] ) {
   415 				$mceInit = apply_filters('teeny_mce_before_init', $mceInit, $editor_id);
   446 				$mceInit = apply_filters('teeny_mce_before_init', $mceInit, $editor_id);
   416 			} else {
   447 			} else {
   536 <?php
   567 <?php
   537 
   568 
   538 		$baseurl = self::$baseurl;
   569 		$baseurl = self::$baseurl;
   539 
   570 
   540 		if ( $tmce_on ) {
   571 		if ( $tmce_on ) {
   541 			if ( $compressed )
   572 			if ( $compressed ) {
   542 				echo "<script type='text/javascript' src='{$baseurl}/wp-tinymce.php?c=1&amp;$version'></script>\n";
   573 				echo "<script type='text/javascript' src='{$baseurl}/wp-tinymce.php?c=1&amp;$version'></script>\n";
   543 			else
   574 			} else {
   544 				echo "<script type='text/javascript' src='{$baseurl}/tiny_mce.js?$version'></script>\n";
   575 				echo "<script type='text/javascript' src='{$baseurl}/tiny_mce.js?$version'></script>\n";
       
   576 				echo "<script type='text/javascript' src='{$baseurl}/wp-tinymce-schema.js?$version'></script>\n";
       
   577 			}
   545 
   578 
   546 			if ( 'en' != self::$mce_locale && isset($lang) )
   579 			if ( 'en' != self::$mce_locale && isset($lang) )
   547 				echo "<script type='text/javascript'>\n$lang\n</script>\n";
   580 				echo "<script type='text/javascript'>\n$lang\n</script>\n";
   548 			else
   581 			else
   549 				echo "<script type='text/javascript' src='{$baseurl}/langs/wp-langs-en.js?$version'></script>\n";
   582 				echo "<script type='text/javascript' src='{$baseurl}/langs/wp-langs-en.js?$version'></script>\n";
   550 		}
   583 		}
       
   584 
       
   585 		$mce = ( self::$has_tinymce && wp_default_editor() == 'tinymce' ) || ! self::$has_quicktags;
   551 ?>
   586 ?>
   552 
   587 
   553 	<script type="text/javascript">
   588 	<script type="text/javascript">
       
   589 		var wpActiveEditor;
       
   590 
   554 		(function(){
   591 		(function(){
   555 			var init, ed, qt, first_init, mce = <?php echo wp_default_editor() == 'tinymce' ? 'true' : 'false'; ?>;
   592 			var init, ed, qt, first_init, DOM, el, i, mce = <?php echo (int) $mce; ?>;
   556 
   593 
   557 			if ( typeof(tinymce) == 'object' ) {
   594 			if ( typeof(tinymce) == 'object' ) {
       
   595 				DOM = tinymce.DOM;
   558 				// mark wp_theme/ui.css as loaded
   596 				// mark wp_theme/ui.css as loaded
   559 				tinymce.DOM.files[tinymce.baseURI.getURI() + '/themes/advanced/skins/wp_theme/ui.css'] = true;
   597 				DOM.files[tinymce.baseURI.getURI() + '/themes/advanced/skins/wp_theme/ui.css'] = true;
       
   598 
       
   599 				DOM.events.add( DOM.select('.wp-editor-wrap'), 'mousedown', function(e){
       
   600 					if ( this.id )
       
   601 						wpActiveEditor = this.id.slice(3, -5);
       
   602 				});
   560 
   603 
   561 				for ( ed in tinyMCEPreInit.mceInit ) {
   604 				for ( ed in tinyMCEPreInit.mceInit ) {
   562 					if ( first_init ) {
   605 					if ( first_init ) {
   563 						init = tinyMCEPreInit.mceInit[ed] = tinymce.extend( {}, first_init, tinyMCEPreInit.mceInit[ed] );
   606 						init = tinyMCEPreInit.mceInit[ed] = tinymce.extend( {}, first_init, tinyMCEPreInit.mceInit[ed] );
   564 					} else {
   607 					} else {
   566 					}
   609 					}
   567 
   610 
   568 					if ( mce )
   611 					if ( mce )
   569 						try { tinymce.init(init); } catch(e){}
   612 						try { tinymce.init(init); } catch(e){}
   570 				}
   613 				}
       
   614 			} else {
       
   615 				if ( tinyMCEPreInit.qtInit ) {
       
   616 					for ( i in tinyMCEPreInit.qtInit ) {
       
   617 						el = tinyMCEPreInit.qtInit[i].id;
       
   618 						if ( el )
       
   619 							document.getElementById('wp-'+el+'-wrap').onmousedown = function(){ wpActiveEditor = this.id.slice(3, -5); }
       
   620 					}
       
   621 				}
   571 			}
   622 			}
   572 
   623 
   573 			if ( typeof(QTags) == 'function' ) {
   624 			if ( typeof(QTags) == 'function' ) {
   574 				for ( qt in tinyMCEPreInit.qtInit ) {
   625 				for ( qt in tinyMCEPreInit.qtInit ) {
   575 					try { quicktags( tinyMCEPreInit.qtInit[qt] ); } catch(e){}
   626 					try { quicktags( tinyMCEPreInit.qtInit[qt] ); } catch(e){}
   576 				}
   627 				}
   577 			}
   628 			}
   578 		})();
   629 		})();
   579 
   630 		<?php
   580 		var wpActiveEditor;
       
   581 
       
   582 		jQuery('.wp-editor-wrap').mousedown(function(e){
       
   583 			wpActiveEditor = this.id.slice(3, -5);
       
   584 		});
       
   585 
       
   586 <?php
       
   587 
   631 
   588 		if ( self::$ext_plugins )
   632 		if ( self::$ext_plugins )
   589 			echo self::$ext_plugins . "\n";
   633 			echo self::$ext_plugins . "\n";
   590 
   634 
   591 		if ( ! $compressed && $tmce_on ) {
   635 		if ( ! $compressed && $tmce_on ) {
   592 ?>
   636 			?>
   593 		(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');}});})();
   637 			(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');}});})();
   594 <?php
   638 			<?php
   595 		}
   639 		}
   596 
   640 
   597 		if ( !is_admin() )
   641 		if ( !is_admin() )
   598 			echo 'var ajaxurl = "' . admin_url( 'admin-ajax.php', 'relative' ) . '";';
   642 			echo 'var ajaxurl = "' . admin_url( 'admin-ajax.php', 'relative' ) . '";';
   599 ?>
   643 
   600 	</script>
   644 		?>
   601 <?php
   645 		</script>
       
   646 		<?php
   602 
   647 
   603 		if ( in_array('wplink', self::$plugins, true) || in_array('link', self::$qt_buttons, true) )
   648 		if ( in_array('wplink', self::$plugins, true) || in_array('link', self::$qt_buttons, true) )
   604 			self::wp_link_dialog();
   649 			self::wp_link_dialog();
   605 
   650 
   606 		if ( in_array('wpfullscreen', self::$plugins, true) || in_array('fullscreen', self::$qt_buttons, true) )
   651 		if ( in_array('wpfullscreen', self::$plugins, true) || in_array('fullscreen', self::$qt_buttons, true) )
   608 
   653 
   609 		do_action('after_wp_tiny_mce', self::$mce_settings);
   654 		do_action('after_wp_tiny_mce', self::$mce_settings);
   610 	}
   655 	}
   611 
   656 
   612 	public static function wp_fullscreen_html() {
   657 	public static function wp_fullscreen_html() {
   613 		global $content_width, $post;
   658 		global $content_width;
       
   659 		$post = get_post();
   614 
   660 
   615 		$width = isset($content_width) && 800 > $content_width ? $content_width : 800;
   661 		$width = isset($content_width) && 800 > $content_width ? $content_width : 800;
   616 		$width = $width + 22; // compensate for the padding and border
   662 		$width = $width + 22; // compensate for the padding and border
   617 		$dfw_width = get_user_setting( 'dfw_width', $width );
   663 		$dfw_width = get_user_setting( 'dfw_width', $width );
   618 		$save = isset($post->post_status) && $post->post_status == 'publish' ? __('Update') : __('Save');
   664 		$save = isset($post->post_status) && $post->post_status == 'publish' ? __('Update') : __('Save');
   622 		<div id="wp-fullscreen-toolbar">
   668 		<div id="wp-fullscreen-toolbar">
   623 			<div id="wp-fullscreen-close"><a href="#" onclick="fullscreen.off();return false;"><?php _e('Exit fullscreen'); ?></a></div>
   669 			<div id="wp-fullscreen-close"><a href="#" onclick="fullscreen.off();return false;"><?php _e('Exit fullscreen'); ?></a></div>
   624 			<div id="wp-fullscreen-central-toolbar" style="width:<?php echo $width; ?>px;">
   670 			<div id="wp-fullscreen-central-toolbar" style="width:<?php echo $width; ?>px;">
   625 
   671 
   626 			<div id="wp-fullscreen-mode-bar"><div id="wp-fullscreen-modes">
   672 			<div id="wp-fullscreen-mode-bar"><div id="wp-fullscreen-modes">
   627 				<a href="#" onclick="fullscreen.switchmode('tinymce');return false;"><?php _e('Visual'); ?></a>
   673 				<a href="#" onclick="fullscreen.switchmode('tinymce');return false;"><?php _e( 'Visual' ); ?></a>
   628 				<a href="#" onclick="fullscreen.switchmode('html');return false;"><?php _e('HTML'); ?></a>
   674 				<a href="#" onclick="fullscreen.switchmode('html');return false;"><?php _ex( 'Text', 'Name for the Text editor tab (formerly HTML)' ); ?></a>
   629 			</div></div>
   675 			</div></div>
   630 
   676 
   631 			<div id="wp-fullscreen-button-bar"><div id="wp-fullscreen-buttons" class="wp_themeSkin">
   677 			<div id="wp-fullscreen-button-bar"><div id="wp-fullscreen-buttons" class="wp_themeSkin">
   632 	<?php
   678 	<?php
   633 
   679 
   665 		} ?>
   711 		} ?>
   666 
   712 
   667 			</div></div>
   713 			</div></div>
   668 
   714 
   669 			<div id="wp-fullscreen-save">
   715 			<div id="wp-fullscreen-save">
   670 				<span><?php if ( $post->post_status == 'publish' ) _e('Updated.'); else _e('Saved.'); ?></span>
   716 				<input type="button" class="button-primary right" value="<?php echo $save; ?>" onclick="fullscreen.save();" />
   671 				<img src="<?php echo admin_url('images/wpspin_light.gif'); ?>" alt="" />
   717 				<span class="spinner"></span>
   672 				<input type="button" class="button-primary" value="<?php echo $save; ?>" onclick="fullscreen.save();" />
   718 				<span class="fs-saved"><?php if ( $post->post_status == 'publish' ) _e('Updated.'); else _e('Saved.'); ?></span>
   673 			</div>
   719 			</div>
   674 
   720 
   675 			</div>
   721 			</div>
   676 		</div>
   722 		</div>
   677 	</div>
   723 	</div>
   766 	<?php wp_nonce_field( 'internal-linking', '_ajax_linking_nonce', false ); ?>
   812 	<?php wp_nonce_field( 'internal-linking', '_ajax_linking_nonce', false ); ?>
   767 	<div id="link-selector">
   813 	<div id="link-selector">
   768 		<div id="link-options">
   814 		<div id="link-options">
   769 			<p class="howto"><?php _e( 'Enter the destination URL' ); ?></p>
   815 			<p class="howto"><?php _e( 'Enter the destination URL' ); ?></p>
   770 			<div>
   816 			<div>
   771 				<label><span><?php _e( 'URL' ); ?></span><input id="url-field" type="text" tabindex="10" name="href" /></label>
   817 				<label><span><?php _e( 'URL' ); ?></span><input id="url-field" type="text" name="href" /></label>
   772 			</div>
   818 			</div>
   773 			<div>
   819 			<div>
   774 				<label><span><?php _e( 'Title' ); ?></span><input id="link-title-field" type="text" tabindex="20" name="linktitle" /></label>
   820 				<label><span><?php _e( 'Title' ); ?></span><input id="link-title-field" type="text" name="linktitle" /></label>
   775 			</div>
   821 			</div>
   776 			<div class="link-target">
   822 			<div class="link-target">
   777 				<label><input type="checkbox" id="link-target-checkbox" tabindex="30" /> <?php _e( 'Open link in a new window/tab' ); ?></label>
   823 				<label><input type="checkbox" id="link-target-checkbox" /> <?php _e( 'Open link in a new window/tab' ); ?></label>
   778 			</div>
   824 			</div>
   779 		</div>
   825 		</div>
   780 		<?php $show_internal = '1' == get_user_setting( 'wplink', '0' ); ?>
   826 		<?php $show_internal = '1' == get_user_setting( 'wplink', '0' ); ?>
   781 		<p class="howto toggle-arrow <?php if ( $show_internal ) echo 'toggle-arrow-active'; ?>" id="internal-toggle"><?php _e( 'Or link to existing content' ); ?></p>
   827 		<p class="howto toggle-arrow <?php if ( $show_internal ) echo 'toggle-arrow-active'; ?>" id="internal-toggle"><?php _e( 'Or link to existing content' ); ?></p>
   782 		<div id="search-panel"<?php if ( ! $show_internal ) echo ' style="display:none"'; ?>>
   828 		<div id="search-panel"<?php if ( ! $show_internal ) echo ' style="display:none"'; ?>>
   783 			<div class="link-search-wrapper">
   829 			<div class="link-search-wrapper">
   784 				<label>
   830 				<label>
   785 					<span><?php _e( 'Search' ); ?></span>
   831 					<span class="search-label"><?php _e( 'Search' ); ?></span>
   786 					<input type="text" id="search-field" class="link-search-field" tabindex="60" autocomplete="off" />
   832 					<input type="search" id="search-field" class="link-search-field" autocomplete="off" />
   787 					<img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
   833 					<span class="spinner"></span>
   788 				</label>
   834 				</label>
   789 			</div>
   835 			</div>
   790 			<div id="search-results" class="query-results">
   836 			<div id="search-results" class="query-results">
   791 				<ul></ul>
   837 				<ul></ul>
   792 				<div class="river-waiting">
   838 				<div class="river-waiting">
   793 					<img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
   839 					<span class="spinner"></span>
   794 				</div>
   840 				</div>
   795 			</div>
   841 			</div>
   796 			<div id="most-recent-results" class="query-results">
   842 			<div id="most-recent-results" class="query-results">
   797 				<div class="query-notice"><em><?php _e( 'No search term specified. Showing recent items.' ); ?></em></div>
   843 				<div class="query-notice"><em><?php _e( 'No search term specified. Showing recent items.' ); ?></em></div>
   798 				<ul></ul>
   844 				<ul></ul>
   799 				<div class="river-waiting">
   845 				<div class="river-waiting">
   800 					<img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
   846 					<span class="spinner"></span>
   801 				</div>
   847 				</div>
   802 			</div>
   848 			</div>
   803 		</div>
   849 		</div>
   804 	</div>
   850 	</div>
   805 	<div class="submitbox">
   851 	<div class="submitbox">
       
   852 		<div id="wp-link-update">
       
   853 			<input type="submit" value="<?php esc_attr_e( 'Add Link' ); ?>" class="button-primary" id="wp-link-submit" name="wp-link-submit">
       
   854 		</div>
   806 		<div id="wp-link-cancel">
   855 		<div id="wp-link-cancel">
   807 			<a class="submitdelete deletion" href="#"><?php _e( 'Cancel' ); ?></a>
   856 			<a class="submitdelete deletion" href="#"><?php _e( 'Cancel' ); ?></a>
   808 		</div>
       
   809 		<div id="wp-link-update">
       
   810 			<input type="submit" tabindex="100" value="<?php esc_attr_e( 'Add Link' ); ?>" class="button-primary" id="wp-link-submit" name="wp-link-submit">
       
   811 		</div>
   857 		</div>
   812 	</div>
   858 	</div>
   813 	</form>
   859 	</form>
   814 	</div>
   860 	</div>
   815 	<?php
   861 	<?php