1.下载ckeditor3.6及ckfinder2.1
2.ckeditor和ckfinder瘦身
删除fckeditor目录下所有"下滑线开头的文件或文件夹"
删除skins目录下的除kama外的目录
lang目录下除en.js\zh-cn.js文件,其它文件的全部删除
删除根目录下的 changes.html(更新列表),install.html(安装指向),license.html(使用许可);
删除_samples和_source文件夹,分别为示例文件和未压缩源程序
删除根目录下changelog.txt,install.txt,license.txt文件
删除core/lang目录下除en.js,zh-cn.js的所有语言文件
3.Thinkphp配置
将ckeditor文件夹放到你项目的Public目录下,再将ckfinder放到ckeditor目录下;文件结构如下:
复制ckeditor/ckeditor_php5.php到/lib/Vendor/ckeditor下
(注:复制ckeditor_php5.php是因为我用的php版本是PHP5,你如果是PHP4的话就要复制ckeditor_php4.php,lib是我的thinkphp核心文件包)
修改/lib/Vendor/ckeditor/ckeditor_php5.php文件的$basePath变量为你当前ckeditor路径:
public $basePath='/Public/ckeditor/';
其实现在就可以使用ckeditor了,只不过还不能上传图片;
4.设置ckfinder插件
打开/Public/ckeditor/config.js做修改如下:
CKEDITOR.editorConfig = function( config ) { config.language = 'zh-cn'; config.uiColor = '#eef5fd'; config.filebrowserBrowseUrl = location.hash + '/Public/ckeditor/ckfinder/ckfinder.html'; config.filebrowserImageBrowseUrl = location.hash + '/Public/ckeditor/ckfinder/ckfinder.html?Type=Images'; config.filebrowserFlashBrowseUrl = location.hash+'/Public/ckeditor/ckfinder/ckfinder.html?Type=Flash'; config.filebrowserImageUploadUrl = location.hash + '/Public/ckeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images'; config.filebrowserFlashUploadUrl = location.hash + '/Public/ckeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'; };
OK这样就和ckfinder关联上了,接下来就要设置文件的上传路径和重命名了;
5.设置ckfinder文件上传按日期路径和按时间重命名
打开/Public/ckeditor/ckfinder/config.php找到$baseUrl这个变量做如下修改,注意红色部分:
$baseUrl = '/Public/Uploads/'; //这是你的上传路径
$date_dir = '/'.date('Y').'/'.date('m').'/'.date('d');
$thum_dir = date('Y').'/'.date('m').'/'.date('d').'/';
$config['Thumbnails'] = Array( 'url' => $baseUrl . $thum_dir . '_thumbs', 'directory' => $baseDir . $thum_dir . '_thumbs', 'enabled' => true, 'directAccess' => false, 'maxWidth' => 100, 'maxHeight' => 100, 'bmpSupported' => false, 'quality' => 80); $config['ResourceType'][] = Array( 'name' => 'Files', // Single quotes not allowed 'url' => $baseUrl . 'files' . $date_dir, 'directory' => $baseDir . 'files' . $date_dir, 'maxSize' => 0, 'allowedExtensions' => '7z,aiff,asf,avi,bmp,csv,doc,docx,fla,flv,gif,gz,gzip,jpeg,jpg,mid,mov,mp3,mp4,mpc,mpeg,mpg,ods,odt,pdf,png,ppt,pptx,pxd,qt,ram,rar,rm,rmi,rmvb,rtf,sdc,sitd,swf,sxc,sxw,tar,tgz,tif,tiff,txt,vsd,wav,wma,wmv,xls,xlsx,zip', 'deniedExtensions' => ''); $config['ResourceType'][] = Array( 'name' => 'Images', 'url' => $baseUrl . 'images' . $date_dir, 'directory' => $baseDir . 'images' . $date_dir, 'maxSize' => 0, 'allowedExtensions' => 'bmp,gif,jpeg,jpg,png', 'deniedExtensions' => ''); $config['ResourceType'][] = Array( 'name' => 'Flash', 'url' => $baseUrl . 'flash' . $date_dir, 'directory' => $baseDir . 'flash' . $date_dir, 'maxSize' => 0, 'allowedExtensions' => 'swf,flv', 'deniedExtensions' => '');
打开/Public/ckeditor/ckfinder/core/connector/php/php5/CommandHandler/FileUpload.php
做如下修改:
if ($sFileName != $sUnsafeFileName) { $iErrorNumber = CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID_NAME_RENAMED; } $sExtension=CKFinder_Connector_Utils_FileSystem::getExtension($sFileName); $sFileName=date('Ymd').'_'.date('His').'.'.$sExtension; $oRegistry->set("FileUpload_fileName", $sFileName);
OK终于完成啦,下面就是调用啦;
6.调用
function set_ckeditor($content, $name='CKeditor', $type='Full') { vendor("ckeditor.ckeditor_php5");//包含CKeditor类库,TP引入第三方类库的系统方法,其路径是相对于vendor目录来说的。 $CKEditor= new CKEditor(); //实例化FCKeditor对象 //$CKEditor->config['height'] = 300; //$CKEditor->config['width'] = 870; $CKEditor->config['uiColor'] = '#E5E5E5';//背景颜色 $CKEditor->config['toolbarLocation'] = 'top';// /* $CKEditor->config['toolbar'] = array( array( 'Font','FontSize', 'Bold', 'Italic', 'Underline','TextColor'), array( 'JustifyLeft','JustifyCenter','JustifyRight'), array( 'Smiley','Image'), ); */ $CKEditor->config['toolbar'] = $type;//可以显示全部功能按钮 $CKEditor->returnOutput = true; //返回生成的HTMl代码,默认为FALSE,只是输出 $html=$CKEditor->editor("text", $content,$config);//也可以初始化内容 //$html=$CKEditor->editor($content);//创建在线编辑器html代码字符串,并赋值给字符串变量$html. $this->assign($name,$html);//将$html的值赋给模板变量$html.在模板里通过{$CKeditor}可以直接引用。 }