?? editor_class.php
字號:
<?php
/* /////////////////////////////////////////////////////////////////////////
* editor_class.php
* -------------------
* author : Chris Bolt
* copyright : (C) Chris Bolt 2003-2004. All Rights Reserved
* version : 2.2.4
* purpose : Generates WYSIWYG PRO DHTML output
///////////////////////////////////////////////////////////////////////////*/
/*
CLASS WYSIWYGPRO
Purpose: configure and then display WYSIWYGPRO DHTML output
basically this file grabs one of 2 possible editors depending on the browser type and version. it then removes features from that file that are not requested or that have been requested for removal and then either returns or prints the code.
Requirements:
Requires config.php
*/
class wysiwygPro {
// Begin
// declare class variables
var $classname = "wysiwygPro";
// variables that are set by the user
var $name='htmlCode';
var $original_name='htmlCode';
var $code='';
var $baseURL='';
var $stylesheet='';
var $remove_array='';
var $dontremoveserver = false;
var $dsbleimgmngr = false;
var $guidelines = '1';
var $showbookmarkmngr = 'true';
var $hyperlink_function = 'open_hyperlink_window(##name##,this)';
var $hyperlink_function2 = 'open_hyperlink_window(parent.wp_current_obj,this)';
var $font_menu =
'<div class="off" onClick="parent.wp_change_font(parent.wp_current_obj,\'Arial\');off(this)" title="Arial" onMouseOver="on(this)" onMouseOut="off(this)" style="font-family:\'Arial\'"><nobr>Arial</nobr></div>
<div class="off" onClick="parent.wp_change_font(parent.wp_current_obj,\'Times New Roman\');off(this)" title="Times New Roman" onMouseOver="on(this)" onMouseOut="off(this)" style="font-family:\'Times New Roman\'"><nobr>Times New Roman</nobr></div>
<div class="off" onClick="parent.wp_change_font(parent.wp_current_obj,\'Courier\');off(this)" title="Courier" onMouseOver="on(this)" onMouseOut="off(this)" style="font-family:\'Courier\'"><nobr>Courier</nobr></div>
<div class="off" onClick="parent.wp_change_font(parent.wp_current_obj,\'Georgia\');off(this)" title="Georgia" onMouseOver="on(this)" onMouseOut="off(this)" style="font-family:\'Georgia\'"><nobr>Georgia</nobr></div>
<div class="off" onClick="parent.wp_change_font(parent.wp_current_obj,\'Verdana\');off(this)" title="Verdana" onMouseOver="on(this)" onMouseOut="off(this)" style="font-family:\'Verdana\'"><nobr>Verdana</nobr></div>
<div class="off" onClick="parent.wp_change_font(parent.wp_current_obj,\'Geneva\');off(this)" title="Geneva" onMouseOver="on(this)" onMouseOut="off(this)" style="font-family:\'Geneva\'"><nobr>Geneva</nobr></div>';
var $format_menu = '
<div class="off" onClick="parent.wp_change_format(parent.wp_current_obj,\'<div>\');off(this)" onMouseOver="on(this)" onMouseOut="off(this)"><nobr>
<div style="position: static; float: none; clear: both; display: block; visibility: visible">##normal##</div>
</nobr></div>
<div class="off" onClick="parent.wp_change_format(parent.wp_current_obj,\'<h1>\');off(this)" onMouseOver="on(this)" onMouseOut="off(this)"><nobr>
<h1 style="position: static; float: none; clear: both; display: block; visibility: visible">##heading_1##</h1>
</nobr></div>
<div class="off" onClick="parent.wp_change_format(parent.wp_current_obj,\'<h2>\');off(this)" onMouseOver="on(this)" onMouseOut="off(this)"><nobr>
<h2 style="position: static; float: none; clear: both; display: block; visibility: visible">##heading_2##</h2>
</nobr></div>
<div class="off" onClick="parent.wp_change_format(parent.wp_current_obj,\'<h3>\');off(this)" onMouseOver="on(this)" onMouseOut="off(this)"><nobr>
<h3 style="position: static; float: none; clear: both; display: block; visibility: visible">##heading_3##</h3>
</nobr></div>
<div class="off" onClick="parent.wp_change_format(parent.wp_current_obj,\'<h4>\');off(this)" onMouseOver="on(this)" onMouseOut="off(this)"><nobr>
<h4 style="position: static; float: none; clear: both; display: block; visibility: visible">##heading_4##</h4>
</nobr></div>
<div class="off" onClick="parent.wp_change_format(parent.wp_current_obj,\'<h5>\');off(this)" onMouseOver="on(this)" onMouseOut="off(this)"><nobr>
<h5 style="position: static; float: none; clear: both; display: block; visibility: visible">##heading_5##</h5>
</nobr></div>
<div class="off" onClick="parent.wp_change_format(parent.wp_current_obj,\'<h6>\');off(this)" onMouseOver="on(this)" onMouseOut="off(this)"><nobr>
<h6 style="position: static; float: none; clear: both; display: block; visibility: visible">##heading_6##</h6>
</nobr></div>
<div class="off" onClick="parent.wp_change_format(parent.wp_current_obj,\'<pre>\');off(this)" onMouseOver="on(this)" onMouseOut="off(this)"><nobr>
<pre style="position: static; float: none; clear: both; display: block; visibility: visible">##pre_formatted##</pre>
</nobr></div>
<div class="off" onClick="parent.wp_change_format(parent.wp_current_obj,\'<address>\');off(this)" onMouseOver="on(this)" onMouseOut="off(this)"><nobr>
<address style="position: static; float: none; clear: both; display: block; visibility: visible">
Address
</address>
<nobr></div>
';
var $size_menu = '
<div class="off" onClick="parent.wp_change_font_size(parent.wp_current_obj,\'1\');off(this)" onMouseOver="on(this)" onMouseOut="off(this)"><font size="1">##1##</font></div>
<div class="off" onClick="parent.wp_change_font_size(parent.wp_current_obj,\'2\');off(this)" onMouseOver="on(this)" onMouseOut="off(this)"><font size="2">##2##</font></div>
<div class="off" onClick="parent.wp_change_font_size(parent.wp_current_obj,\'3\');off(this)" onMouseOver="on(this)" onMouseOut="off(this)"><font size="3">##3##</font></div>
<div class="off" onClick="parent.wp_change_font_size(parent.wp_current_obj,\'4\');off(this)" onMouseOver="on(this)" onMouseOut="off(this)"><font size="4">##4##</font></div>
<div class="off" onClick="parent.wp_change_font_size(parent.wp_current_obj,\'5\');off(this)" onMouseOver="on(this)" onMouseOut="off(this)"><font size="5">##5##</font></div>
<div class="off" onClick="parent.wp_change_font_size(parent.wp_current_obj,\'6\');off(this)" onMouseOver="on(this)" onMouseOut="off(this)"><font size="6">##6##</font></div>
<div class="off" onClick="parent.wp_change_font_size(parent.wp_current_obj,\'7\');off(this)" onMouseOver="on(this)" onMouseOut="off(this)"><font size="7">##7##</font></div>
';
var $save_button = '';
var $custom_objects = '';
var $links = '';
var $usexhtml = 'false';
var $xhtml_lang = "en";
var $encoding = "iso-8859-1";
var $usep = 'false';
var $subsequent = 'false';
var $color_swatches = '';
var $instance_img_dir = '';
var $instance_doc_dir = '';
var $doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
var $charset = '';
// internal variables
// browsers
var $is_ie55 = false;
var $is_ie50 = false;
var $is_gecko = false;
var $gecko_revision = 1.3;
var $unsupported = false;
// other stuff
var $baseURL2 = '';
var $domain = '';
var $set_style = '';
var $image_window = 'image.php';
var $class_menu = '';
var $save_name = '';
var $has_expired = true;
var $WYSIWYGPRO_code = '';
var $instance_lang = DEFAULT_LANG;
/***************************************************************************
wysiwygPro
Public: constructor
$save_name: string to save this configuration as. If WYSIWYGPRO is requested again with the same save_name the file will be generated from a cache file rather than generated from scratch.
If no paramater is set WYSIWYG PRO will perform no configuration saving.
*/
function wysiwygPro($save_name='') {
if (!defined('WP_CONFIG')) {
die('<p><b>WYSIWYGPRO - Setup Error:</b> You did not include \'config.php\' before declaring this class!</p>');
}
////////////////////
// no-cache headers
// send headers to prevent caching by proxy servers. This is extremely important because all browser detection is done by this script, and this script outputs different code depending on browser and platform.
// Note that the script containing this class must either not output anything before calling this class or use ob_start (); and ob_end_flush();
if (NOCACHE) {
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // expires in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
}
///////////////////////
// browser detection
///////////////////////
$browser_string = strtolower($_SERVER["HTTP_USER_AGENT"]);
$is_mac = strstr($browser_string, 'mac');
$is_opera = strstr($browser_string, 'opera');
$is_konq = strstr($browser_string, 'khtml');
$is_camino = strstr($browser_string, 'camino');
$ie_version = preg_replace('/.*msie/sm', '', $browser_string);
$ie_version = substr ($ie_version, 0,4);
$gecko_version = preg_replace('/.*rv:/sm', '', $browser_string);
$gecko_version = substr ($gecko_version, 0,3);
$this->gecko_revision = $gecko_version;
if ((($ie_version*10) >= 55) && !$is_opera && !$is_mac) {
$this->is_ie55 = true;
$add_to_cache_name = '_ie55';
} elseif ((($ie_version*10) >= 50) && !$is_opera && !$is_mac) {
$this->is_ie50 = true;
$add_to_cache_name = '_ie50';
} elseif (strstr($browser_string, 'gecko') && !$is_opera && !$is_konq && !$is_camino && $gecko_version >= '1.3') {
$this->is_gecko = true;
$add_to_cache_name = '_gecko';
if ($this->gecko_revision >= 1.5) {
$add_to_cache_name .= '14';
}
} else {
$this->unsupported = true;
$add_to_cache_name = '_unsupported';
}
// Now that we have done browser detection it is safe to check for caching and do the caching
if (!empty($save_name)) {
$save_name = $save_name.$add_to_cache_name;
// make sure the save name is safe to use as a filename (incase the user wants to use the current URL as the cache name)
$save_name = preg_replace ("/[\/\\\?&%#~:]/", '', $save_name);
$this->save_name = $save_name;
// check if this file has expired
$this->has_expired = $this->expired($this->save_name);
} else {
$this->has_expired = true;
}
if ($this->has_expired) {
// If we reach here then the cache has expired or no save name has been set for this configuration
/////////////////
// check globals
/////////////////
// check we have been sent a valid directory and that the template files for the Internet Explorer editor and the alternative browser editor exist.
if ((!file_exists (WP_FILE_DIRECTORY.'templates/IE5editor.tpl')) || (!file_exists (WP_FILE_DIRECTORY.'templates/MozEditor.tpl'))) {
die("<p><b>WysiwygPro - Setup Error:</b> WysiwygPro cannot find its file library. Your WP_FILE_DIRECTORY setting is incorrect, or some files are missing. This paramater should be set to the full file path to the 'editor_files' folder. This value should be set in config.php.</p>");
}
if (!file_exists (WP_FILE_DIRECTORY.'lang/'.DEFAULT_LANG)) {
die("<p><b>WysiwygPro - Setup Error:</b> your default language file does not exist.");
}
// add features not supported by ie50 to the remove array
if ($this->is_ie50 == true) {
$this->remove('ie50_remove');
}
// read the contents of the editor code from the file into a variable.
// choose a file based on the user agent
if (($this->is_ie55) || ($this->is_ie50)) {
$code_file = 'templates/IE5editor.tpl';
} elseif ($this->is_gecko) {
$code_file = 'templates/MozEditor.tpl';
} else {
$code_file = 'templates/textEditor.tpl';
}
// open file into a variable that we can work with
$this->WYSIWYGPRO_code = stripslashes(implode("", @file(WP_FILE_DIRECTORY.$code_file)));
}
}
// Internal functions:
/***************************************************************************
expired
Method: returns true if the cache has expired.
*/
function expired ($file) {
if (! @file_exists (SAVE_DIRECTORY . $file)) {
return true;
}
if ((filemtime (SAVE_DIRECTORY . $file)) < (time () - SAVE_LENGTH)) {
return true;
}
return false;
}
/***************************************************************************
remove
Method: Adds items to the remove array. (note the so called 'remove array' is not yet an actual array!)
items: a comma separated list of items to add
*/
function remove($items) {
if ($this->has_expired) {
if (isset ($items) ? $items : '') {
if (!empty($this->remove_array)) {
$this->remove_array .= (','.$items);
} else {
$this->remove_array=$items;
}
}
}
}
/***************************************************************************
wp_replace
Method: pastes variables into the editor
array: search and replace array
*/
function wp_replace($code, $array) {
$search = array();
$replace = array();
foreach($array as $k => $v) {
array_push($search, '##'.$k.'##');
array_push($replace, $v);
}
return str_replace($search, $replace, $code);
}
/***************************************************************************
wp_entities
Method: replaces html code with WP entities ready for use
*/
function wp_entities($code) {
// convert anchors:
$code = preg_replace("/<a name=\"(.*?)\".*?>(.*?)<\/a>/smi", "<img name=\"\$1\" src=\"".WP_WEB_DIRECTORY."/images/bookmark_symbol.gif\" contenteditable=\"false\" width=\"16\" height=\"13\">\$2", $code);
//$code = preg_replace("/<a(.*?)href=\"#(.*?)\"(.*?)>/smi", "<a\$1href=\"WP_BOOKMARK#\$2\"\$3>", $code);
// Both browsers will ignore ASP tags so we need to make them into comments here
$code = preg_replace("/<%(.*?)\%>/smi", "<!--asp\$1-->", $code);
if ($this->is_gecko) {
// Mozilla will completely ignore PHP tags so we need to convert them into comments here instead
$code = preg_replace("/<\?php(.*?)\?>/smi", "<!--p\$1-->", $code);
// hack to stop bug in Mozilla where row modifications cause an endless loop if table html is not all on one line (Note for future development: is this a bug in Mozilla or a flaw in the table editing script?)
// table
$code = preg_replace("/<table([^>]*?)>\s+/smi", "<table\$1>", $code);
// tbody
$code = preg_replace("/<tbody([^>]*?)>\s+/smi", "<tbody\$1>", $code);
// close tbody
$code = preg_replace("/<\/tbody>\s+/smi", "</tbody>", $code);
// thead
$code = preg_replace("/<thead([^>]*?)>\s+/smi", "<thead\$1>", $code);
// close thead
$code = preg_replace("/<\/thead>\s+/smi", "</thead>", $code);
// tfoot
$code = preg_replace("/<tfoot([^>]*?)>\s+/smi", "<tfoot\$1>", $code);
// close tfoot
$code = preg_replace("/<\/tfoot>\s+/smi", "</tfoot>", $code);
// tr
$code = preg_replace("/<tr([^>]*?)>\s+/smi", "<tr\$1>", $code);
// close tr
$code = preg_replace("/<\/tr>\s+/smi", "</tr>", $code);
// close td
$code = preg_replace("/<\/td>\s+/smi", "</td>", $code);
}
$code = preg_replace("/<font>(.*?)<\/font>/smi", "\$1", $code);
return $code;
}
// Public functions that set paramaters:
/***************************************************************************
set_name
Public: sets the name of the code
$name: the name of the textarea that will hold the edited HTML code
*/
function set_name($name='htmlCode') {
if ($this->has_expired) {
if (!empty($name)) {
$this->name = preg_replace("/[^A-Za-z0-9_]/smi", '', $name);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -