FCKeditor结合PHP的使用

来源:互联网 发布:原油api数据 编辑:程序博客网 时间:2024/05/21 10:00

回顾以前代码时发现对FCKeditor不是很了解,研究一番,发现了不少问题。通过搜索他人成果和自己的亲身实践,将其总结如下。

一、FCKeditor的精简
1、根目录下保留php,xml,js文件,其他类型文件删除,删除_samples文件夹
2、editor/lang目录下只保留en.js和zh-cn.js
3、editor/filemanager/connectors目录下保留php的目录,其他类型的目录删除
4、editor/skins目录下只保留要使用的皮肤
二、FCKeditor的配置
1、基本配置:fckconfig.js
FCKConfig.SkinPath = FCKConfig.BasePath + 'skins/silver/' ;
或FCKConfig.SkinPath = FCKConfig.BasePath + 'skins/office2003/' ;//更换皮肤
FCKConfig.DefaultLanguage = 'zh-cn' ;//语言
FCKConfig.ToolbarSets["Default"] = [[…],[…],…,[…]] ;
//设置默认的工具栏工具集合
//一个[]内为一组,显示时组间自动加分隔符,'-'加一条竖线,'/'换行
//也可自定义工具集,如:
FCKConfig.ToolbarSets["Beatles"] = [
 ['Bold','Italic','-','OrderedList','UnorderedList','-','Link','Unlink','-','About']
] ;
//通过设置FCKeditor类对象ToolbarSet属性值为"Beatles"选择使用
//其他配置大多可以使用默认值
2、FCKeditor类对象:改变fckeditor_php4.php或fckeditor_php5.php(这两个文件只是不同版本对类的实现方式上有所不同)中下面的默认设置,也可以在实例化一个对象后为这些属性赋新值
function FCKeditor( $instanceName )或public function __construct( $instanceName )
{
 $this->InstanceName = $instanceName ;//要创建的
 $this->BasePath  = '/fckeditor/' ;//根路径
 $this->Width  = '100%' ;//默认宽度
 $this->Height  = '200' ;//默认高度
 $this->ToolbarSet = 'Default' ;//要使用的工具栏集合名称
 $this->Value  = '' ;

 $this->Config  = array() ;
}
3、上传文件功能的配置:editor/filemanager/connectors/php/config.php文件
$Config['Enabled'] = true ;//允许上传
$Config['UserFilesPath'] = '/beatles/project/editor/' ;//相对于服务器的根目录的路径
$Config['ConfigAllowedCommands'] = array('QuickUpload', 'FileUpload', 'GetFolders', 'GetFoldersAndFiles', 'CreateFolder') ;//根据需要设置
$Config['ConfigAllowedTypes'] = array('File', 'Image', 'Flash', 'Media') ;//根据需要设置,如只上传图片则只保留'Image',并最好在工具集中将不用的去掉
下面的各个数组可根据需要设置允许上传和禁止上传的文件类型
三、处理Windows下上传中文名称文件时的乱码问题(Linux下统一采用utf-8编码,不会产生问题)
editor/filemanager/connectors/php/util.php:(L73)
 return(utf8_encode(htmlspecialchars($value)));改为return mb_convert_encoding(htmlspecialchars($value),"UTF-8","GBK");
editor/filemanager/connectors/php/command.php:(L177)
 $sFileName=$oFile['name'];后面加上$sFileName=mb_convert_encoding($sFileName,"GBK","auto");
四、使用范例:
#editor.php文件:
……
<form action="#" method="post">
<?php
 include_once("fckeditor/fckeditor.php");
 $sBasePath = './fckeditor/';
 $oFCKeditor = new FCKeditor('input');
 $oFCKeditor->BasePath = $sBasePath ;
 $oFCKeditor->Width = '100%';
 $oFCKeditor->Height = '400px';
 $ofCKeditor->ToolbarSet='Default';
 $oFCKeditor->Value = 'Hello World!';
 echo $oFCKeditor->CreateHtml();
?>
<input type="submit" name="submit" value="submit">
</form>
……
#action.php文件:
<?php
$content = stripslashes($_POST['input']);//POST过程中引号等字符被转义了,这里先去掉转义符
echo $content;
?>