formwysiwygtextarea.php

来自「php 开发的内容管理系统」· PHP 代码 · 共 718 行 · 第 1/3 页

PHP
718
字号
<?php 
/**
 * Editor framework 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		1.00
 * @version		$Id$
 * @package		xoopseditor
 */
 
if (!defined("XOOPS_ROOT_PATH")) {
    die("XOOPS root path not defined");
}
/**
* A textarea with wysiwyg buttons
* 
* @author Samuels 
* @copyright copyright (c) 2000-2003 XOOPS.org
* @package kernel
* @subpackage form
*/

include_once(dirname(__FILE__) . '/preferences.php');


class XoopsFormWysiwygTextArea extends XoopsFormElement {
    var $options;
    var $value;
    var $width = "100%";
    var $height = "400px";
    var $url;
    var $skin;
    var $fonts;
    var $direction;

	/**
	 * Constructor
	 *
     * @param	array   $configs  Editor Options
     * @param	binary 	$checkCompatible  true - return false on failure
	 */
	function XoopsFormWysiwygTextArea($configs, $checkCompatible = false)
	{
	    if(!empty($configs)) {
	        foreach($configs as $key => $val) {
	            if (method_exists($this, 'set'.Ucfirst($key))) {
	                $this->{'set'.Ucfirst($key)}($val);
	            }else{
	                $this->$key = $val;
	            }
	        }
	    }
		if($checkCompatible && !$this->isCompatible()) {
			return false;
		}
	}

	/*
	function setConfig($configs)
	{
	    foreach($configs as $key=>$val){
			$this->$key = $val;
	    }
	}
	*/
	
    function getDirection()
    {
	    if(empty($this->direction)){
	    	$this->direction = _XK_P_TDIRECTION;
    	}
        return $this->direction;
    }
    
    function setDirection($direction)
    {
        $this->direction = $direction;
    } 
    
    function getSkin()
    {
	    if(empty($this->skin)){
	    	$this->skin = _XK_P_SKIN;
    	}
        return $this->skin;
    } 
    
    function setSkin($skin)
    {
        $this->skin = $skin;
    }
    
    function getUrl()
    {
	    if(empty($this->url)){
	    	$this->url = _XK_P_PATH;
    	}  
        return $this->url;
    } 
    function setUrl($value)
    {
        $this->url = $value;
    } 
    
    function getValue()
    {
        return $this->value;
    } 
    
    function setValue($value)
    {
        $this->value = $value;
    } 
    
    function setWidth($width)
    {
	    if(!empty($width)){
        	$this->width = $width;
    	}
    } 
    
    function getWidth()
    {
        return $this->width;
    } 
    
    function setHeight($height)
    {
	    if(!empty($height)){
        	$this->height = $height;
    	}
    } 
    
    function getHeight()
    {
        return $this->height;
    } 
    
    function getFonts()
    {
	    if(empty($this->fonts) || count($this->fonts)==0){
        	$this->fonts = array('Courier New' => 'Courier New, Courier, monospace', 'MS Serif' => 'MS Serif, New York, serif', 'Verdana' => 'Verdana, Geneva, Arial, Helvetica, sans-serif');
	    }	    
        return $this->fonts;
    } 
    
    function setFonts($fonts)
    {
        if(is_array($fonts)){
			$myts =& MyTextSanitizer::getInstance();
	        foreach($fonts as $key => $val){
		        $key = $myts->htmlSpecialChars($key);
		        $val = $myts->htmlSpecialChars($val);
	        	$this->fonts[$key] = $val;
        	}
        }
    } 
    
 	function getOptions()
    {
	    if(empty($this->options) || count($this->options)==0){
		    $this->options = array_filter(array_map("trim", explode(",", _XK_P_FULLTOOLBAR)));
	    }
        return $this->options;
    } 
    
    function setOptions($options)
    {
        if ($options == 'small'){
	        $this->options = array_filter(array_map("trim", explode(",", _XK_P_SMALLTOOLBAR)));
        }elseif(is_array($options)){
	        $this->options = $options;
        }
    } 

    function getThemeCSS()
    {
        global $xoopsConfig;
        if (getcss($xoopsConfig['theme_set']))return getcss($xoopsConfig['theme_set']);
        else return '';
    } 

    function setThemeCSS($themeCss)
    {
        $this->themeCss = $themeCss;
    } 

    /**
    * Prepare HTML for output
    * 
    * @return string HTML
    */
    function render()
    { 
        // include files
        include_once XOOPS_ROOT_PATH . '' . $this->getUrl() . '/include/functions.inc.php';
        static $koivi_js_loaded = false;
        static $koivi_tabletools_loaded = false;

		if(isset($GLOBALS["KOIVI_FONTLIST"])){
			$this->setFonts($GLOBALS["KOIVI_FONTLIST"]);
		}
        $url = XOOPS_URL . '' . $this->getUrl();
        $skinUrl = $url . '/skins/' . $this->getSkin();
        $isie = checkBrowser();
        $toggleMode = false;
        $themeCss = false;
        $colorPalette = false;
        $extraDivs = ''; 

        if (!$koivi_js_loaded) {
            $form = '<script language="JavaScript" type="text/javascript" src="' . $url . '/include/js/cntextmenu.js"></script>';
            $form .= '<script language="JavaScript" type="text/javascript" src="' . $url . '/include/js/editor.js"></script>';
            $form .= '<script language="JavaScript" type="text/javascript" src="' . $url . '/include/js/xhtml.js"></script>';
            $koivi_js_loaded = true;
        } else {
            $form = '';
        } 
        if (in_array('createtable', $this->getOptions()) && $koivi_tabletools_loaded == false) {
            $form .= '<script language="JavaScript" type="text/javascript" src="' . $url . '/include/js/table_tools.js"></script>';
            $koivi_tabletools_loaded = true;
        } 

        $form .= '<link href="' . $skinUrl . '/' . $this->getSkin() . '.css" rel="Stylesheet" type="text/css" />
				<div id="alleditor' . $this->getName() . '" style="width:' . $this->getWidth() . ';border:1px solid silver;">
					<div id="toolbar' . $this->getName() . '" class="' . $this->getSkin() . 'toolbarBackCell">';

        if (in_array('floating', $this->getOptions())) {
            $form .= '	<div class="' . $this->getSkin() . 'editorStatus">
							<img alt=""  src="' . $skinUrl . '/minimize.gif" onclick="XK_hideToolbar(\'' . $this->getName() . '\',\'' . $skinUrl . '\')" />
							<img id="floatButton' . $this->getName() . '" alt="' . _XK_FLOAT . '" title="' . _XK_FLOAT . '" src="' . $skinUrl . '/floating.gif" onclick="XK_floatingToolbar(\'' . $this->getName() . '\',\'' . $this->getSkin() . '\')"/>
							<img id="maximizeButton' . $this->getName() . '" alt="' . _XK_FLOAT . '" title="' . _XK_FLOAT . '" src="' . $skinUrl . '/fullscreen.gif" onclick="XK_maximizeEditor(\'' . $this->getName() . '\')"/>
						</div>';
        } 

        $form .= '<div id="buttons' . $this->getName() . '" class="' . $this->getSkin() . 'toolBar">';

        foreach ($this->getOptions() as $tool) {

⌨️ 快捷键说明

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