<?php
/*
* Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.html or http://ckeditor.com/license
*/
/**
* \brief CKEditor class that can be used to create editor
* instances in PHP pages on server side.
* @see http://ckeditor.com
*
* Sample usage:
* @code
* $CKEditor = new CKEditor();
* $CKEditor->editor("editor1", "<p>Initial value.</p>");
* @endcode
*/
class CKEditor
{
/**
* The version of %CKEditor.
* \private
*/
var $version = '3.6.4';
/**
* A constant string unique for each release of %CKEditor.
* \private
*/
var $_timestamp = 'C6HH5UF';
/**
* URL to the %CKEditor installation directory (absolute or relative to document root).
* If not set, CKEditor will try to guess it's path.
*
* Example usage:
* @code
* $CKEditor->basePath = '/ckeditor/';
* @endcode
*/
var $basePath;
/**
* An array that holds the global %CKEditor configuration.
* For the list of available options, see http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html
*
* Example usage:
* @code
* $CKEditor->config['height'] = 400;
* // Use @@ at the beggining of a string to ouput it without surrounding quotes.
* $CKEditor->config['width'] = '@@screen.width * 0.8';
* @endcode
*/
var $config = array();
/**
* A boolean variable indicating whether CKEditor has been initialized.
* Set it to true only if you have already included
* <script> tag loading ckeditor.js in your website.
*/
var $initialized = false;
/**
* Boolean variable indicating whether created code should be printed out or returned by a function.
*
* Example 1: get the code creating %CKEditor instance and print it on a page with the "echo" function.
* @code
* $CKEditor = new CKEditor();
* $CKEditor->returnOutput = true;
* $code = $CKEditor->editor("editor1", "<p>Initial value.</p>");
* echo "<p>Editor 1:</p>";
* echo $code;
* @endcode
*/
var $returnOutput = false;
/**
* An array with textarea attributes.
*
* When %CKEditor is created with the editor() method, a HTML <textarea> element is created,
* it will be displayed to anyone with JavaScript disabled or with incompatible browser.
*/
var $textareaAttributes = array( "rows" => 8, "cols" => 60 );
/**
* A string indicating the creation date of %CKEditor.
* Do not change it unless you want to force browsers to not use previously cached version of %CKEditor.
*/
var $timestamp = "C6HH5UF";
/**
* An array that holds event listeners.
* \private
*/
var $_events = array();
/**
* An array that holds global event listeners.
* \private
*/
var $_globalEvents = array();
/**
* Main Constructor.
*
* @param $basePath (string) URL to the %CKEditor installation directory (optional).
*/
function CKEditor($basePath = null) {
if (!empty($basePath)) {
$this->basePath = $basePath;
}
}
/**
* Creates a %CKEditor instance.
* In incompatible browsers %CKEditor will downgrade to plain HTML <textarea> element.
*
* @param $name (string) Name of the %CKEditor instance (this will be also the "name" attribute of textarea element).
* @param $value (string) Initial value (optional).
* @param $config (array) The specific configurations to apply to this editor instance (optional).
* @param $events (array) Event listeners for this editor instance (optional).
*
* Example usage:
* @code
* $CKEditor = new CKEditor();
* $CKEditor->editor("field1", "<p>Initial value.</p>");
* @endcode
*
* Advanced example:
* @code
* $CKEditor = new CKEditor();
* $config = array();
* $config['toolbar'] = array(
* array( 'Source', '-', 'Bold', 'Italic', 'Underline', 'Strike' ),
* array( 'Image', 'Link', 'Unlink', 'Anchor' )
* );
* $events['instanceReady'] = 'function (ev) {
* alert("Loaded: " + ev.editor.name);
* }';
* $CKEditor->editor("field1", "<p>Initial value.</p>", $config, $events);
* @endcode
*/
function editor($name, $value = "", $config = array(), $events = array())
{
$attr = "";
foreach ($this->textareaAttributes as $key => $val) {
$attr.= " " . $key . '="' . str_replace('"', '"', $val) . '"';
}
$out = "<textarea name=\"" . $name . "\"" . $attr . ">" . htmlspecialchars($value) . "</textarea>\n";
if (!$this->initialized) {
$out .= $this->init();
}
$_config = $this->configSettings($config, $events);
$js = $this->returnGlobalEvents();
if (!empty($_config))
$js .= "CKEDITOR.replace('".$name."', ".$this->jsEncode($_config).");";
else
$js .= "CKEDITOR.replace('".$name."');";
$out .= $this->script($js);
if (!$this->returnOutput) {
print $out;
$out = "";
}
return $out;
}
/**
* Replaces a <textarea> with a %CKEditor instance.
*
* @param $id (string) The id or name of textarea element.
* @param $config (array) The specific configurations to apply to this editor instance (optional).
* @param $events (array) Event listeners for this editor instance (optional).
*
* Example 1: adding %CKEditor to <textarea name="article"></textarea> element:
* @code
* $CKEditor = new CKEditor();
* $CKEditor->replace("article");
* @endcode
*/
function replace($id, $config = array(), $events = array())
{
$out = "";
if (!$this->initialized) {
$out .= $this->init();
}
$_config = $this->configSettings($config, $events);
$js = $this->returnGlobalEvents();
if (!empty($_config)) {
$js .= "CKEDITOR.replace('".$id."', ".$this->jsEncode($_config).");";
}
else {
$js .= "CKEDITOR.replace('".$id."');";
}
$out .= $this->script($js);
if (!$this->returnOutput) {
print $out;
$out = "";
}
return $out;
}
/**
* Replace all <textarea> elements available in the document with editor instances.
*
* @param $className (string) If set, replace all textareas with class className in the page.
*
* Example 1: replace all <textarea> elements in the page.
* @code
* $CKEditor = new CKEditor();
* $CKEditor->replaceAll();
* @endcode
*
* Example 2: replace all <textarea class="myClassName"> elements in the page.
* @code
* $CKEditor = new CKEditor();
* $CKEditor->replaceAll( 'myClassName' );
* @endcode
*/
function replaceAll($className = null)
{
$out = "";
if (!$this->initialized) {
$out .= $this->init();
}
$_config = $this->configSettings();
$js = $this->returnGlobalEvents();
if (empty($_config)) {
if (empty($className)) {
$js .= "CKEDITOR.replaceAll();";
}
else {
$js .= "CKEDITOR.replaceAll('".$className."');";
}
}
else {
$classDetection = "";
$js .= "CKEDITOR.replaceAll( function(textarea, config) {\n";
if (!empty($className)) {
$js .= " var classRegex = new RegExp('(?:^| )' + '". $className ."' + '(?:$| )');\n";
$js .= " if (!classRegex.test(textarea.className))\n";
$js .= " return false;\n";
}
$js .= " CKEDITOR.tools.extend(config, ". $this->jsEncode($_config) .", true);";
$js .= "} );";
}
$out .= $this->script($js);
if (!$this->returnOutput) {
print $out;
$out = "";
}
return $out;
}
/**
* Adds event listener.
* Events are fired by %CKEditor in various situations.
*
* @param $event (string) Event name.
* @param $javascriptCode (string) Javascript anonymous function or function name.
*
* Example usage:
* @code
* $CKEditor->addEventHandler('instanceReady', 'function (ev) {
* alert("Loaded: " + ev.editor.name);
* }');
* @endcode
*/
function addEventHandler($event, $javascriptCode)
{
if (!isset($this->_events[$event])) {
$this->_events[$event] = array();
}
// Avoid duplicates.
if (!in_array($javascriptCode, $this->_events[$event])) {
$this->_events[$event][] = $javascriptCode;
}
}
/**
* Clear registered event handlers.
* Note: this function will have no effect on already created editor instances.
*
* @param $event (string) Event name, if
beyondwild
- 粉丝: 9993
- 资源: 4918
最新资源
- 基于Matlab的10kW虚拟同步发电机小信号稳定控制仿真研究,10kW同步发电机(VSG)小信号稳定控制matlab仿真 【985双一流专业的电气工程博士自用仿真】 参数可改 1从lunwen中
- 有源电力滤波器对并网变流器谐波补偿研究:光伏发电并网应用下的效果分析及其优化策略,26 有源电力滤波器补偿并网变流器谐波 以光伏发电并网为应用场景 在并网联络线处加入有源电力滤波器 补偿前thd:0
- 改进IEEE 33节点系统下的潮流计算与电压分析:含风机光伏接入,电动机应用,不含特定内容(风光280除外),改进的IEEE33节点,潮流计算,电压分析,可加风机光伏,接电动机 含风光380,不含2
- lightningx.deb
- Simulink仿真下的自适应巡航控制(ACC)系统建模:速度与间距控制策略探究,Simulink仿真:基于模型预测的自适应巡航控制系(ACC)建模 参考文献:无 仿真平台:MATLAB Simuli
- 基于三菱PLC与MCGS组态的农田智能灌溉系统:详解梯形图程序、接线图与IO分配及组态画面,基于三菱PLC和MCGS组态农田智能灌溉系统 带解释的梯形图程序,接线图原理图图纸,io分配,组态画面 ,核
- 基于MATLAB的新能源与储能技术模型构建:光伏、飞轮储能、燃料电池与锂电池的综合应用,基于MATLAB搭建的光伏,飞轮储能,燃料电池和锂电池的模型,可以再此基础上搭建个各种形式的新能源和储能模型
- 微秒制造与超快激光应用研究:飞秒激光与石英玻璃的交互机制探索与COMSOL仿真分析,研究背景:随着微秒制造的发展,对超快激光的应用越来越广泛,对超快激光与物质作用机理的研究也越来越深入,目前做超快激光
- 西门子S7-200 PLC四层电梯组态仿真设计与程序实现,西门子S7-200PLC程序和组态王4层电梯四层电梯带组态仿真组态设计PLC设计 ,核心关键词:西门子S7-200PLC程序; 四层电梯;
- 直驱永磁同步风力发电机MATLAB仿真模型设计与分析,直驱永磁同步风力发电机MATLAB仿真模型 ,核心关键词:直驱永磁同步风力发电机; MATLAB仿真模型; 风电技术; 能源转换; 仿真模拟; 电
- 电压型单相双极性SPWM逆变仿真模型详解:原理、调制策略及载波与调制波频率影响分析,电压型单相双极性SPWM逆变仿真模型 含有对应的仿真说明,包含原理,调制策略 针对不同载波频率,调制波频率的仿真说
- COMSOL变压器油流注放电模型:仿真分析与应用探讨,COMSOL变压器油流注放电模型 ,核心关键词:COMSOL; 变压器; 油流注放电模型; 仿真模拟 ,COMSOL中变压器油流注放电模型的建立与
- "改进粒子群算法GAPSO:Matlab编程下的基本、混沌与遗传粒子群算法的程序与结果对比分析",改进粒子群算法GAPSO 采用matlab编程,有基本粒子群、混沌粒子群和遗传粒子群三种算法的程序和结
- COMSOL 6.0超声相控阵仿真模型:压力声学与固体力学对比建模介绍,COMSOL超声相控阵仿真模型 模型介绍:本链接有两个模型,分别使用压力声学与固体力学对超声相控阵无损检测进行仿真,负有模型说明
- 永磁同步电机一阶非线性自抗扰(ADRC)matlab仿真模型与参数调优研究,永磁同步电机一阶非线性自抗扰(ADRC)matlab,simulink模型 参数已调好含有参考文档,送自抗扰相关电子书 不
- 传统轿车ABS防抱死系统模糊控制策略研究:与PID及逻辑门限值控制的效能对比,联合仿真优化模型文件夹包含代码与模型原件,课题名称:传统轿车ABS防抱死系统控制策略研究 课题内容:基于Carsim和S
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈