dhtmlext.php

来自「php 开发的内容管理系统」· PHP 代码 · 共 218 行

PHP
218
字号
<?php
/**
 * Extended dhtmltextarea editor for XOOPS
 *
 * @copyright	The XOOPS project http://www.xoops.org/
 * @license		http://www.fsf.org/copyleft/gpl.html GNU public license
 * @author		Taiwen Jiang (phppp or D.J.) <php_pp@hotmail.com>
 * @since		4.00
 * @version		$Id$
 * @package		xoopseditor
 */
if (!defined("XOOPS_ROOT_PATH")) {
    die("XOOPS root path not defined");
}

include_once XOOPS_ROOT_PATH."/class/xoopsform/formdhtmltextarea.php";
include_once XOOPS_ROOT_PATH."/Frameworks/textsanitizer/module.textsanitizer.php";

class XoopsFormDhtmlTextAreaExtended extends XoopsFormDhtmlTextArea 
{

	var $url;
	/**
	 * Constructor
	 *
     * @param	string  $caption    Caption
     * @param	string  $name       "name" attribute
     * @param	string  $value      Initial text
     * @param	int     $rows       Number of rows
     * @param	int     $cols       Number of columns
     * @param	string  $hiddentext Hidden Text
	 */
	function XoopsFormDhtmlTextAreaExtended($caption, $name, $value, $rows=5, $cols=50, $hiddentext="xoopsHiddenText")
	{
		$this->XoopsFormDhtmlTextArea($caption, $name, $value, $rows, $cols, $hiddentext);
		$this->url = XOOPS_URL."/class/xoopseditor/dhtmlext";
	}

	/**
	 * Prepare HTML for output
	 *
     * @return	string  HTML
	 */
	function render()
	{
      	//$ret = '<script language="JavaScript" type="text/javascript" src="' . $this->url . "/" . $GLOBALS["xoopsConfig"]['language'].'.js"></script>';
      	$ret = '<script language="JavaScript" type="text/javascript" src="' . $this->url . '/xoops.js"></script>';
		$ret .= $this->_codeIcon()."<br />\n";
		$ret .= $this->_fontArray()."<br /><br />\n\n";
		$ret .= "<textarea id='".$this->getName()."' name='".$this->getName()."' onselect=\"xoopsSavePosition('".$this->getName()."');\" onclick=\"xoopsSavePosition('".$this->getName()."');\" onkeyup=\"xoopsSavePosition('".$this->getName()."');\" cols='".$this->getCols()."' rows='".$this->getRows()."'".$this->getExtra().">".$this->getValue()."</textarea><br />\n";
		$ret .= $this->_renderSmileys();
		return $ret;
	}

	/**
	 * prepare HTML for output of the smiley list.
     *
	 * @return	string HTML
	 */
	function _renderSmileys()
	{
		$myts =& MyTextSanitizer::getInstance();
		$smiles = $myts->getSmileys();
		$ret = '';
		$MAX_DIS=10;
		if (empty($smiles)) {
			$db =& Database::getInstance();
			if ($result = $db->query('SELECT * FROM '.$db->prefix('smiles').' WHERE display=1')) {
				$i_MAX_DIS=0;
				while ($smiles = $db->fetchArray($result)) {
					$ret .= "<img onclick='xoopsCodeSmilie(\"".$this->getName()."\", \" ".$smiles['code']." \");' onmouseover='style.cursor=\"hand\"' src='".XOOPS_UPLOAD_URL."/".htmlspecialchars($smiles['smile_url'], ENT_QUOTES)."' alt='' />";
					$i_MAX_DIS++;
					if($i_MAX_DIS==$MAX_DIS) {
						$ret .="<br />";
						$i_MAX_DIS=0;
					}
				}
			}
		} else {
			$count = count($smiles);
			$i_MAX_DIS=0;
			for ($i = 0; $i < $count; $i++) {
				if ($smiles[$i]['display'] == 1) {
					$ret .= "<img onclick='xoopsCodeSmilie(\"".$this->getName()."\", \" ".$smiles[$i]['code']." \");' onmouseover='style.cursor=\"hand\"' src='".XOOPS_UPLOAD_URL."/".$myts->oopsHtmlSpecialChars($smiles[$i]['smile_url'])."' border='0' alt='' />";
					$i_MAX_DIS++;
					if($i_MAX_DIS==$MAX_DIS) {
						$ret .="<br />";
						$i_MAX_DIS=0;
					}
				}
			}
		}
		$ret .= "&nbsp;[<a href='#moresmiley' onmouseover='style.cursor=\"hand\"' alt='' onclick='openWithSelfMain(\"".XOOPS_URL."/misc.php?action=showpopups&amp;type=smilies&amp;target=".$this->getName()."\",\"smilies\",300,475);'>"._MORE."</a>]";

		return $ret;
	}

	function _codeIcon()
	{
		$textarea_id = $this->getName();
		$image_path = $this->url . "/images";
		$code = "<a name='moresmiley'></a>
			<img src='".XOOPS_URL."/images/url.gif' alt='"._ALTURL."' onclick='xoopsCodeUrl(\"$textarea_id\", \"".htmlspecialchars(_ENTERURL, ENT_QUOTES)."\", \"".htmlspecialchars(_ENTERWEBTITLE, ENT_QUOTES)."\");' onmouseover='style.cursor=\"hand\"'/>&nbsp;
			<img src='".XOOPS_URL."/images/email.gif' alt='"._ALTEMAIL."' onclick='xoopsCodeEmail(\"$textarea_id\", \"".htmlspecialchars(_ENTEREMAIL, ENT_QUOTES)."\");'  onmouseover='style.cursor=\"hand\"'/>&nbsp;
			<img src='".XOOPS_URL."/images/imgsrc.gif' alt='"._ALTIMG."' onclick='xoopsCodeImg(\"$textarea_id\", \"".htmlspecialchars(_ENTERIMGURL, ENT_QUOTES)."\", \"".htmlspecialchars(_ENTERIMGPOS, ENT_QUOTES)."\", \"".htmlspecialchars(_IMGPOSRORL, ENT_QUOTES)."\", \"".htmlspecialchars(_ERRORIMGPOS, ENT_QUOTES)."\", \"".htmlspecialchars(_ENTERWIDTH, ENT_QUOTES)."\");'  onmouseover='style.cursor=\"hand\"'/>&nbsp;
			<img src='".XOOPS_URL."/images/image.gif' alt='"._ALTIMAGE."' onclick='openWithSelfMain(\"".XOOPS_URL."/imagemanager.php?target=".$textarea_id."\",\"imgmanager\",400,430);'  onmouseover='style.cursor=\"hand\"'/>&nbsp;";
		if(!defined("XOOPS_ENABLE_EXTENDEDCODE") || XOOPS_ENABLE_EXTENDEDCODE ==1){
			if(defined("EXTCODE_ENABLE_FLASH") && EXTCODE_ENABLE_FLASH == 1){
				$code .= "<img src='".$image_path."/swf.gif' alt='"._ALTFLASH."'  onclick='xoopsCodeFlash(\"$textarea_id\",\"".htmlspecialchars(_ENTERFLASHURL, ENT_QUOTES)."\",\"".htmlspecialchars(_ENTERHEIGHT, ENT_QUOTES)."\",\"".htmlspecialchars(_ENTERWIDTH, ENT_QUOTES)."\", ".EXTCODE_ENABLE_DIMENSION_DETECT.");'  onmouseover='style.cursor=\"hand\"'/>&nbsp;";
			}
			if(defined("EXTCODE_ENABLE_WMP") && EXTCODE_ENABLE_WMP == 1){
				$code .= "<img src='".$image_path."/wmp.gif' alt='"._ALTWMP."'  onclick='xoopsCodeWmp(\"$textarea_id\",\"".htmlspecialchars(_ENTERWMPURL, ENT_QUOTES)."\",\"".htmlspecialchars(_ENTERHEIGHT, ENT_QUOTES)."\",\"".htmlspecialchars(_ENTERWIDTH, ENT_QUOTES)."\");'  onmouseover='style.cursor=\"hand\"'/>&nbsp;";
			}
			if(defined("EXTCODE_ENABLE_MMS") && EXTCODE_ENABLE_MMS == 1){
				$code .= "<img src='".$image_path."/mmssrc.gif' alt='"._ALTMMS."' onclick='xoopsCodeMms(\"$textarea_id\",\"".htmlspecialchars(_ENTERMMSURL, ENT_QUOTES)."\",\"".htmlspecialchars(_ENTERHEIGHT, ENT_QUOTES)."\",\"".htmlspecialchars(_ENTERWIDTH, ENT_QUOTES)."\");'  onmouseover='style.cursor=\"hand\"'/>&nbsp;";
			}
			if(defined("EXTCODE_ENABLE_RTSP") && EXTCODE_ENABLE_RTSP == 1){
				$code .= "<img src='".$image_path."/rtspimg.gif' alt='"._ALTRTSP."' onclick='xoopsCodeRtsp(\"$textarea_id\",\"".htmlspecialchars(_ENTERRTSPURL, ENT_QUOTES)."\",\"".htmlspecialchars(_ENTERHEIGHT, ENT_QUOTES)."\",\"".htmlspecialchars(_ENTERWIDTH, ENT_QUOTES)."\");'  onmouseover='style.cursor=\"hand\"'/>&nbsp;";
			}
			if(defined("EXTCODE_ENABLE_IFRAME") && EXTCODE_ENABLE_IFRAME == 1){
				$code .= "<img src='".$image_path."/iframe.gif' alt='"._ALTIFRAME."' onclick='xoopsCodeIframe(\"$textarea_id\",\"".htmlspecialchars(_ENTERIFRAMEURL, ENT_QUOTES)."\",\"".htmlspecialchars(_ENTERHEIGHT, ENT_QUOTES)."\");'  onmouseover='style.cursor=\"hand\"'/>&nbsp;";
			}
			if(defined("EXTCODE_ENABLE_WIKI") && EXTCODE_ENABLE_WIKI == 1){
				$code .= "<img src='".$image_path."/wiki.gif' alt='"._ALTWIKI."' onclick='xoopsCodeWiki(\"$textarea_id\",\"".htmlspecialchars(_ENTERWIKITERM, ENT_QUOTES)."\");'  onmouseover='style.cursor=\"hand\"'/>&nbsp;";
			}
		}
		$code .="
			<img src='".XOOPS_URL."/images/code.gif' alt='"._ALTCODE."' onclick='xoopsCodeCode(\"$textarea_id\", \"".htmlspecialchars(_ENTERCODE, ENT_QUOTES)."\");'  onmouseover='style.cursor=\"hand\"'/>&nbsp;
			<img src='".XOOPS_URL."/images/quote.gif' alt='"._ALTQUOTE."' onclick='xoopsCodeQuote(\"$textarea_id\", \"".htmlspecialchars(_ENTERQUOTE, ENT_QUOTES)."\");' onmouseover='style.cursor=\"hand\"'/>
		";
		return($code);
	}

	function _fontArray()
	{
		$textarea_id = $this->getName();
		$hiddentext = $this->_hiddenText;
		$fontStr = "<script type=\"text/javascript\" language=\"JavaScript\">
			var _editor_dialog = ''
			//+ '<select id=\'{$textarea_id}Size\' onchange=\'setVisible(\"xoopsHiddenText\"); setElementSize(\"{$hiddentext}\",this.options[this.selectedIndex].value);\'>'
			+ '<select id=\'{$textarea_id}Size\' onchange=\'_setElementSize(\"{$hiddentext}\",this.options[this.selectedIndex].value, \"$textarea_id\");\'>'
			+ '<option value=\'SIZE\'>"._SIZE."</option>'
			";
		foreach($GLOBALS["formtextdhtml_sizes"] as $_val => $_name) {
			$fontStr .= " + '<option value=\'{$_val}\'>{$_name}</option>'";
		};
		$fontStr .= " + '</select>'";
		
		$fontStr .= "
			+ '<select id=\'{$textarea_id}Font\' onchange=\'_setElementFont(\"{$hiddentext}\",this.options[this.selectedIndex].value, \"$textarea_id\");\'>'
			+ '<option value=\'FONT\'>"._FONT."</option>'
			";
		$fontarray = !empty($GLOBALS["formtextdhtml_fonts"]) ? $GLOBALS["formtextdhtml_fonts"] : array("Arial", "Courier", "Georgia", "Helvetica", "Impact", "Verdana", "Haettenschweiler");
		foreach($fontarray as $font) {
			$fontStr .= " + '<option value=\'{$font}\'>{$font}</option>'";
		};
		$fontStr .= " + '</select>'";
		
		$fontStr .= "
			+ '<select id=\'{$textarea_id}Color\' onchange=\'_setElementColor(\"{$hiddentext}\",this.options[this.selectedIndex].value, \"$textarea_id\");\'>'
			+ '<option value=\'COLOR\'>"._COLOR."</option>';
			var _color_array = new Array('00', '33', '66', '99', 'CC', 'FF');
			for(var i = 0; i < _color_array.length; i ++) {
				for(var j = 0; j < _color_array.length; j ++) {
					for(var k = 0; k < _color_array.length; k ++) {
						var _color_ele = _color_array[i] + _color_array[j] + _color_array[k];
						_editor_dialog += '<option value=\''+_color_ele+'\' style=\'background-color:#'+_color_ele+';color:#'+_color_ele+';\'>#'+_color_ele+'</option>';
					}
				}
			}
			_editor_dialog += '</select>';";
		
		$fontStr .= "document.write(_editor_dialog); </script>";
		
		$styleStr = "<img src='".XOOPS_URL."/images/bold.gif' alt='"._ALTBOLD."' onmouseover='style.cursor=\"hand\"' onclick='_makeBold(\"".$hiddentext."\", \"$textarea_id\");' />&nbsp;";
		$styleStr .= "<img src='".XOOPS_URL."/images/italic.gif' alt='"._ALTITALIC."' onmouseover='style.cursor=\"hand\"' onclick='_makeItalic(\"".$hiddentext."\", \"$textarea_id\");' />&nbsp;";
		$styleStr .= "<img src='".XOOPS_URL."/images/underline.gif' alt='"._ALTUNDERLINE."' onmouseover='style.cursor=\"hand\"' onclick='_makeUnderline(\"".$hiddentext."\", \"$textarea_id\");'/>&nbsp;";
		$styleStr .= "<img src='".XOOPS_URL."/images/linethrough.gif' alt='"._ALTLINETHROUGH."' onmouseover='style.cursor=\"hand\"' onclick='_makeLineThrough(\"".$hiddentext."\", \"$textarea_id\");' /></a>&nbsp;";
		$styleStr .= "<input type='text' id='".$textarea_id."Addtext' size='20' />&nbsp;<input type='button' onclick='xoopsCodeText(\"$textarea_id\", \"".$hiddentext."\", \"".htmlspecialchars(_ENTERTEXTBOX, ENT_QUOTES)."\")' value='"._ADD."' />";

		$fontStr = $fontStr."<br />\n".$styleStr."&nbsp;&nbsp;<span id='".$hiddentext."'>"._EXAMPLE."</span>\n";
		return($fontStr);
	}
}


/**
 * Pseudo class
 *
 * @author	    phppp (D.J.)
 * @copyright	copyright (c) 2005 XOOPS.org
 */

class FormDhtmlExt extends XoopsFormDhtmlTextAreaExtended
{
	/**
	 * Constructor
	 *
     * @param	array   $configs  Editor Options
     * @param	binary 	$checkCompatible  true - return false on failure
	 */
	function FormDhtmlExt($configs, $checkCompatible = false)
	{
		if(!empty($configs)) {
			foreach($configs as $key => $val){
				${$key} = $val;
				$this->$key = $val;
			}
		}
		$value = isset($value) ? $value : "";
		$rows = isset($rows) ? $rows : 5;
		$cols = isset($cols) ? $cols : 50;
		$hiddentext = empty($hiddentext) ? "xoopsHiddenText" : $hiddentext;
		$this->XoopsFormDhtmlTextAreaExtended("", $name, $value, $rows, $cols, $hiddentext);
	}
}

?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?