百度新推出的UEditor是一个很不错的在线富文本编辑器,与CKEditor、KindEditor等属于同一个应用范畴。百度UEditor编辑器具有很多特色,比如支持多图批量上传、支持直接插入地图、拥有丰富美观的表情图片、支持代码高亮显示、支持自定义分页符等等符合国人操作习惯的特点,而且能够很好的迎合当前主流CMS中的内容编辑需求。下面我们就来将百度UEditor编辑器(1.1.8.1版)与国内优秀的CMS系统PHPCMS V9进行强强结合。
首先,我们需要修改 \phpcms\libs\classes\attachment.class.php 文件,使之与百度UEditor编辑器中的图片上传功能进行对接。现在,我们打开 \phpcms\libs\classes\attachment.class.php 文件,找到mkhtml函数的声明部分,我们可以通过搜索“function mkhtml(”从而很容易的找到它的位置,将此函数改为:
function mkhtml($fn,$fileurl,$message,$editor=null) { if(!$editor && !empty($_REQUEST['editortype'])){ $editor=$_REQUEST['editortype']; } switch($editor){ case 'ueditor': $title = htmlspecialchars($_POST['pictitle'], ENT_QUOTES); $message || $message='SUCCESS'; $str='{\'url\':\''.$fileurl.'\',\'title\':\''.$title.'\',\'state\':\''.$message.'\'}'; break; default: $str='<script type="text/javascript">window.parent.CKEDITOR.tools.callFunction('.$fn.', \''.$fileurl.'\', \''.$message.'\');</script>'; } exit($str); }
修改后保存。
然后,我们修改 \phpcms\libs\classes\form.class.php 文件,打开 \phpcms\libs\classes\form.class.php 文件,在代码:
class form {
后面另起一行,添加代码:
/** * UEditor Function * Author:admpub.com * Update:2012-03-26 20:14 */ public static function ueditor($textareaid = 'content', $toolbar = 'basic', $module = '', $catid = '', $color = '', $allowupload = 0, $allowbrowser = 1,$alowuploadexts = '',$height = 200,$disabled_page = 0, $allowuploadnum = '32') {//$toolbar = 'admpub'; if($toolbar == 'basic') { $toolbar = "['FullScreen',"; $toolbar .= defined('IN_ADMIN') ? "'Source'," : ''; $toolbar .= "'|', 'Undo', 'Redo', '|', 'Bold', 'Italic', 'Underline','InsertOrderedList', 'InsertUnorderedList','|', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyJustify', '|', 'Link', 'Unlink']"; } elseif($toolbar == 'full') { $toolbar = "['FullScreen',"; if(defined('IN_ADMIN')) { $toolbar .= "'Source',"; } else { $toolbar .= ''; } $toolbar .= "'|', 'Undo', 'Redo', '|', 'Bold', 'Italic', 'Underline', 'StrikeThrough', 'Superscript', 'Subscript', 'RemoveFormat', 'FormatMatch', '|', 'BlockQuote', '|', 'PastePlain', '|', 'ForeColor', 'BackColor', 'InsertOrderedList', 'InsertUnorderedList', '|', 'CustomStyle', 'Paragraph', 'RowSpacing', 'LineHeight', 'FontFamily', 'FontSize', '|', 'DirectionalityLtr', 'DirectionalityRtl', '|', '', 'Indent', '|', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyJustify', '|', 'Link', 'Unlink', 'Anchor', '|', 'ImageNone', 'ImageLeft', 'ImageRight', 'ImageCenter', '|', 'InsertImage', 'Emotion', 'InsertVideo', 'Map', 'GMap', 'InsertFrame', 'PageBreak','PageTitle', 'HighlightCode', '|', 'Horizontal', 'Date', 'Time', 'Spechars', '|', 'InsertTable', 'DeleteTable', 'InsertParagraphBeforeTable', 'InsertRow', 'DeleteRow', 'InsertCol', 'DeleteCol', 'MergeCells', 'MergeRight', 'MergeDown', 'SplittoCells', 'SplittoRows', 'SplittoCols', '|', 'SelectAll', 'ClearDoc', 'SearchReplace', 'Print', 'Preview', 'CheckImage', 'Help']"; } elseif($toolbar == 'desc') { $toolbar = "['FullScreen','Source','Undo', 'Redo', '|',"; $toolbar .= "'Bold', 'Italic', '|', 'InsertOrderedList', 'InsertUnorderedList', '|', 'Link', 'Unlink', '|', 'ImageNone', 'ImageLeft', 'ImageRight', 'ImageCenter', '|', 'InsertImage','HighlightCode']"; } else { $toolbar = "['FullScreen','Undo', 'Redo', '|','ForeColor', 'BackColor']"; } $str .= '<script type="text/javascript">'; $str .= 'var UEDITOR_HOME_URL="'.JS_PATH.'ueditor/";'; $str .= 'var ADMPUB_PIC_UPLOADFIELD_NAME="upload";'; $str .= 'var ADMPUB_PIC_DESCFIELD_NAME="pictitle";'; $str .= 'var ADMPUB_PIC_UPLOAD_URL="'.APP_PATH.'index.php?m=attachment&c=attachments&a=upload&module='.$module.'&catid='.$catid.'&editortype=ueditor&dosubmit=1";'; $str .= 'var ADMPUB_PIC_UPLOAD_MAXSIZE=2;'; $str .= 'var ADMPUB_PIC_UPLOAD_MAXNUM='.$allowuploadnum.';'; $str .= 'var ADMPUB_TOOLBARS=['.$toolbar.'];'; $str .= '</script>'; if(!defined('EDITOR_INIT')) { $str .= '<script type="text/javascript" src="'.JS_PATH.'ueditor/editor_config.js" charset="utf-8"></script>'; $str .= '<script type="text/javascript" src="'.JS_PATH.'ueditor/editor_all_min.js" charset="utf-8"></script>';// $str .= '<link rel="stylesheet" href="'.JS_PATH.'ueditor/themes/default/ueditor.css"/>'; define('EDITOR_INIT', 1); } $str .= "<script type=\"text/javascript\">\r\n"; $str .= "var editor = new baidu.editor.ui.Editor({textarea:'$textareaid',wordCount:false});\r\n"; $str .= "editor.render('$textareaid');\r\n"; $str .= '</script>'; $ext_str = "<div class='editor_bottom'>"; if(!defined('IMAGES_INIT')) { $ext_str .= '<script type="text/javascript" src="'.JS_PATH.'swfupload/swf2ckeditor.js"></script>'; define('IMAGES_INIT', 1); } $ext_str .= '</div>'; $str .= $ext_str; return $str; }
接着在代码:
public static function editor($textareaid = 'content', $toolbar = 'basic', $module = '', $catid = '', $color = '', $allowupload = 0, $allowbrowser = 1,$alowuploadexts = '',$height = 200,$disabled_page = 0, $allowuploadnum = '10') {
后面添加代码:
return self::ueditor($textareaid, $toolbar, $module, $catid, $color, $allowupload, $allowbrowser, $alowuploadexts, $height, $disabled_page, $allowuploadnum);
好了,到此为止,PHP代码部分我们已经修改完了,接下来只需要将我修改好的UEditor编辑器压缩包下载下来,解压缩,然后把里面的statics文件夹复制到网站根目录覆盖就可以了。
我修改后的UEditor编辑器已经可以完美的支持图片上传(使用PHPCMS V9的上传接口)、内容分页,还支持分页标题。所以您无需再次修改就能直接使用这些功能了。
转载地址:http://www.admpub.com/index.php/a/show/catid/18/id/510/index.html