FCKeditor 2.6.5下载与环境准备
1、首先访问官方网站获取FCKeditor 2.6.5的多语言版本包。下载地址为http://ckeditor.com/download,请注意区分:列表中第一个链接对应的是最新的3.0.1版本,而第二个链接才是所需的FCKeditor 2.6.5版本。
2、清理不必要的冗余文件以优化资源:
进入/FCKeditor/根目录,仅保留fckconfig.js、fckeditor.js、fckstyles.xml、fcktemplates.xml、fckeditor.php、fckeditor_php5.php以及fckeditor_php4.php这七个核心文件;
移除该目录下除上述七个文件之外的所有其他文件;
删除/editor/_source目录(通常以_开头的文件夹或文件均为可选组件,可安全移除);
删除/editor/filemanager/connectors/目录下除了php文件夹以外的所有其他语言连接器目录;
删除/editor/lang/目录下除了en.js、zh.js和zh-cn.js这三个语言文件之外的所有其他语言包文件。
3、打开/FCKeditor/fckconfig.js进行基础配置
修改以下变量设置:
将默认语言设置为简体中文:var FCKConfig.DefaultLanguage = 'zh-cn' ;
设置文件浏览器后端语言:var _FileBrowserLanguage = 'php' ;
设置快速上传后端语言:var _QuickUploadLanguage = 'php' ;
若要启用文件上传功能,还需进一步配置editor\filemanager\connectors\php\config.php文件。
找到$Config['Enabled'] = false ;这一行,将其修改为$Config['Enabled'] = true ;以开启上传权限;
同时更改$Config['UserFilesPath'] = '/userfiles/' ;为你实际使用的上传文件存储目录路径;
4. 调用方法示例
将FCKeditor文件夹放置于网站根目录下。
在需要插入编辑器的PHP文件中,引入/FCKeditor/fckeditor.php文件。
具体代码如下所示:
// 包含fckeditor类库文件
include("../FCKeditor/fckeditor.php") ;
// 定义编辑器基础路径
$sBasePath = "/FCKeditor/";
// 实例化一个Fckeditor对象,关联表单中的textarea元素名为content
$oFCKeditor = new FCKeditor('content') ;
$oFCKeditor->BasePath = $sBasePath ;
// 设置编辑器内的初始文本内容
$oFCKeditor->Value = 'This is some sample text' ;
$oFCKeditor->Create() ;
// 还可以根据需要设置以下属性
$oFCKeditor->Width
$oFCKeditor->Height
$oFCKeditor->ToolbarSet
......................................................................................................................................................
这是文章内容测试! <?php
include_once("fckeditor/fckeditor.php");
$oFCKeditor=new fckeditor('content');
$oFCKeditor->BasePath='fckeditor/';
$oFCKeditor->value='default text in editor';
$oFCKeditor->Width='800px';
$oFCKeditor->Height='300px';
$oFCKeditor->create();
//$fck=$oFCKeditor->CreateHtml();
?> 针对FCKeditor在处理中文文件名时出现乱码的问题,现提供以下解决方案:
测试环境说明:PHP 5版本,UTF-8编码格式。
1、修正上传中文文件时文件名乱码问题
在文件connectors/php/commands.php中查找以下代码行:
$sFileName = $oFile['name'] ;
在该行之后添加一行转换代码:
$sFileName = iconv("utf-8","gbk",$sFileName);
2、修正文件列表浏览时中文文件名显示乱码问题
在文件connectors/php/util.php中查找以下返回语句:
return ( utf8_encode( htmlspecialchars( $value ) ) ) ;
将其修改为:
return iconv('','utf-8',htmlspecialchars( $value ));
3、修正新建中文文件夹时的文件夹名乱码问题
在文件connectors/php/commands.php中查找以下赋值语句:
$sNewFolderName =
在该行之后添加一行转换代码:
$sNewFolderName = iconv("utf-8","gbk",$sNewFolderName);
注:FCKeditor 2.6.3版本及后续版本的html文件中已内置UTF-8文件头声明。
以下是一些补充说明
如果你经常登录网站后台或发布文章,希望为内容添加不同样式或字体,实现这一功能其实很简单,只需使用FCKeditor插件即可。下面通过实例演示具体操作。
前往FCKeditor官方网站 http://ckeditor.com/download 下载最新的源码包。
下载完成后需进行配置。源码包中包含fckeditor/_samples目录,里面有编写好的示例文件可直接运行参考。需要注意的是,默认情况下大部分功能可用,但上传图片功能可能无法直接使用。
接下来配置上传图片功能。
打开文件FCKeditor/editor/filemanager/browser/default/connectors/php/config.php:
查找$Config['Enabled'],将其值设置为'true';查找$Config['UserFilesPath'],将其设置为图片存放目录。该目录路径是相对于主目录(即根目录)而言的。如果在本地测试,根目录通常对应http://localhost。
至此基本配置已完成。下面提供一个简单的index.php示例文件。
<form name="form1" method="post" action="index.php" target="_blank"> <br><?php <BR>// 引用FCKeditor.php文件,其中包含了基本的类和数据结构 <br>include("fckeditor/fckeditor.php") ; <br><br>?> <br><input id="content" name="content" value="" type="hidden"> <iframe id="content___Frame" frameborder="0" height="100%" scrolling="no" width="100%" src="/test/bianyiqi/fckeditor/editor/fckeditor.html?InstanceName=content&Toolbar=Default"> </iframe> <br><input name="haiyang" value="明天第一时间我会更好" type="text"> <br><input type="submit" name="submit" value="提交"> <br></form> <?php
echo stripslashes($_POST['content']);
echo "
";
echo $_POST['haiyang'];
?> 直接进行测试即可。注意,index.php文件和fckeditor文件夹应位于同一级目录下。