帝国CMS整合百度编辑器(UEditor)
帝国CMS整合百度编辑器本文关键字词:百度编辑器,帝国编辑器,整合百度编辑器,UEditor,帝国CMS整合百度编辑器
UEditor深度整合帝国ECMS。UEditor提供非常完善的后端通信API接口,使得UE编辑器整合CMS项目相当简单方便。所有图片、附件、视频等文件存放目录与后台数据记录,都延续使用ECMS的存放方式。本项目将持续已插件形式更新最新的UEditor和ECMS。
百度编辑器(ueditor)使用说明:
•第一步:下载百度编辑器原版(PHP版),解压到帝国/e/extend/ueditor/目录下, [下载地址]
•第二步:使用本项目上controller.php action_crawler.php文件替换/e/extend/ueditor/php/目录下的controller.php action_crawler.php文件。
•复制ueditor.toolbarconfig.js在/e/extend/ueditor/目录下
•第三步:修改帝国CMS字段HTML,在编辑器字段增加处理和编辑器引入代码。[字段管理方法]
<?php
$ziduan = 'newstext'; //编辑器使用的字段名称
if ($enews == 'MAddInfo' || $enews == 'MEditInfo') { //前台投稿
$qiantai = 1;
$ziduanzhi = $ecmsfirstpost == 1 ? "" : DoReqValue($mid, $ziduan, stripSlashes($r[$ziduan]));
} else { //后台
$qiantai = 0;
$ziduanzhi = $ecmsfirstpost == 1 ? "" : stripSlashes($r[$ziduan]);
}
?>
<script>var ClassId='<?=$classid?>',InfoId='<?=$id?>',FilePass='<?=$filepass?>',Ehash='<?=$ecms_hashur['ehref']?>',QianTai='<?=$qiantai?>';</script>
<script type="text/javascript" charset="utf-8" src="/e/extend/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/e/extend/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" charset="utf-8" src="/e/extend/ueditor/ueditor.toolbarconfig.js"></script>
<textarea id="<?=$ziduan?>" name="<?=$ziduan?>"><?=$ziduanzhi?></textarea>
<script type="text/javascript">
<?=$ziduan?> = UE.getEditor('<?=$ziduan?>',{
serverUrl: "/e/extend/ueditor/php/controller.php",//自己的请求接口
toolbars:Default,//工具栏配置文件,具体参考ueditor.toolbarconfig.js文件中说明
pageBreakTag:'[!--empirenews.page--]',//帝国分页标签
initialFrameWidth:'100%',//编辑器宽
initialFrameHeight:300//编辑器高
//等等其它配置自行添加,参考UE默认配置文件复制修改即可
});
//自定义请求参数
<?=$ziduan?>.ready(function(){
<?=$ziduan?>.execCommand('serverparam',{
'filepass':'<?=$filepass?>',//修改时候是信息ID
'classid' :'<?=$classid?>',
'qiantai':<?=$qiantai?>
});
});
</script>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#DBEAF5">
<tr>
<td bgcolor="#FFFFFF">
<input name="dokey" type="checkbox" value="1"<?=$r==1?' checked':''?>>关键字替换
<input name="copyimg" type="checkbox" id="copyimg" value="1">远程保存图片(
<input name="mark" type="checkbox" id="mark" value="1">
<a href="SetEnews.php" target="_blank">加水印</a>)
<input name="copyflash" type="checkbox" id="copyflash" value="1">远程保存FLASH(地址前缀:
<input name="qz_url" type="text" id="qz_url" size="">)
</td>
</tr>
<tr>
<td bgcolor="#FFFFFF">
<input name="repimgnexturl" type="checkbox" id="repimgnexturl" value="1"> 图片链接转为下一页 <input name="autopage" type="checkbox" id="autopage" value="1">自动分页,每 <input name="autosize" type="text" id="autosize" value="5000" size="5">个字节为一页 取第
<input name="getfirsttitlepic" type="text" id="getfirsttitlepic" value="" size="1">张上传图为标题图片(
<input name="getfirsttitlespic" type="checkbox" id="getfirsttitlespic" value="1">缩略图: 宽
<input name="getfirsttitlespicw" type="text" id="getfirsttitlespicw" size="3" value="<?=$public_r?>">*高
<input name="getfirsttitlespich" type="text" id="getfirsttitlespich" size="3" value="<?=$public_r?>">)
</td>
</tr>
</table>
字段HMTL代码修改截图:
编辑器调用截图:
注释:
编辑器的字段代码修改为你当前字段的字段名即可。
controller.php为上传等接口文件,替换官方原版的即可,在php目录下。
ueditor.toolbarconfig.js为工具栏配置文件js,默认配置两项,全功能和演示简版两种,其他的自行添加。另外此文件还提供了一个附件管理的外部接口js
注意:
修改百度编辑器的目录的时候,对应的文件也需要修改,比如引入的js路径,php文件路径等
ueditor.toolbarconfig.js源码:
/*其他的工具栏配置选项自定义即可,编辑器实例化的时候使用 “toolbars:变量名” 即可,比如toolbars:Basic*/
/*最原始的配置
var Default=[['fullscreen', 'source', '|', 'undo', 'redo', '|','bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|','rowspacingtop', 'rowspacingbottom', 'lineheight', '|','customstyle', 'paragraph', 'fontfamily', 'fontsize', '|','directionalityltr', 'directionalityrtl', 'indent', '|','justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|','link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|','simpleupload', 'insertimage', 'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', 'map', 'gmap', 'insertframe', 'insertcode', 'webapp', 'pagebreak', 'template', 'background', '|','horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|','inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|','print', 'preview', 'searchreplace', 'help', 'drafts']];
*/
/*以下配置我去除了一些无用的功能 比如谷歌地图国内打不开,百度APP等,代码高亮有BUG,暂时禁用*/
var Default=[['fullscreen','source','|','undo','redo','|','bold','italic','underline','fontborder','strikethrough','superscript','subscript','removeformat','formatmatch','autotypeset','blockquote','pasteplain','|','forecolor','backcolor','insertorderedlist','insertunorderedlist','selectall','cleardoc','|','rowspacingtop','rowspacingbottom','lineheight','|','customstyle','paragraph','fontfamily','fontsize','|','directionalityltr','directionalityrtl','indent','|','justifyleft','justifycenter','justifyright','justifyjustify','|','touppercase','tolowercase','|','link','unlink','anchor','|','imagenone','imageleft','imageright','imagecenter','|','simpleupload','insertimage','scrawl','insertvideo','attachment','map','insertframe','template','background','|','horizontal','date','time','spechars','snapscreen','wordimage','|','inserttable','deletetable','insertparagraphbeforetable','insertrow','deleterow','insertcol','deletecol','mergecells','mergeright','mergedown','splittocells','splittorows','splittocols','charts','|','print','preview','searchreplace','help','drafts','|','pagebreak']],/*Basic为测试简版,自己添加需要的即可*/Basic=[['fullscreen','source','undo','redo','|','bold','italic','underline','fontborder','strikethrough','superscript','subscript','|','removeformat','formatmatch','autotypeset','blockquote','pasteplain','|','forecolor','backcolor','insertorderedlist','insertunorderedlist','|','link','unlink','anchor','|','selectall','cleardoc','|','simpleupload','insertimage','attachment']];
/*********************************帝国CMS附件管理***************************************/
/*暂时未做此文件,使用的是官方默认的,有点小BUG,但是不影响大的使用,后期开发,后台更改路径的话,下面也做响应的修改*/
if(QianTai==0){//判断是后台
UE.registerUI('FileMain',function(editor,uiName){
var btn=new UE.ui.Button({name:'FileMain',title:'帝国CMS附件管理',cssRules:'',/*需要添加的额外样式,指定icon图标,这里默认使用一个重复的icon*/
onclick:function(){
window.open('/e/admin/ecmseditor/FileMain.php?type=1&classid='+ClassId+'&infoid='+InfoId+'&filepass='+FilePass+'&sinfo=1&doing=1'+Ehash,'','width=700,height=550,scrollbars=yes');
}});/*执行*/
return btn;},58/*index 指定添加到工具栏上的那个位置,默认时追加到最后,editorId 指定这个UI是那个编辑器实例上的,默认是页面上所有的编辑器都会添加这个按钮*/
);
}else if(QianTai==1){//判断是前台
}
controller.php源码:
<?php
//header('Access-Control-Allow-Origin: http://www.baidu.com'); //设置http://www.baidu.com允许跨域访问
//header('Access-Control-Allow-Headers: X-Requested-With,X_Requested_With'); //设置允许的跨域header
require ('../../../class/connect.php'); //引入数据库配置文件和公共函数文件
require ('../../../class/db_sql.php'); //引入数据库操作文件
require ('../../../data/dbcache/class.php'); //栏目缓存
$CONFIG = json_decode(preg_replace("/\/\*[\s\S]+?\*\//", "", file_get_contents("config.json")), true);
$link = db_connect(); //连接MYSQL
$empire = new mysqlquery(); //声明数据库操作
$qiantai = (int)$_GET['qiantai']; //是否前台
if ($qiantai) {
$userid = (int)getcvar('mluserid');
$username = RepPostVar(getcvar('mlusername'));
$user_fj = '' . $username;
} else {
$userid = getcvar('loginuserid', 1);
$username = getcvar('loginusername', 1);
$rnd = getcvar('loginrnd', 1);
$adminr = $empire->fetch1("select userid,groupid,classid,userprikey from {$dbtbpre}enewsuser where userid='$userid' and username='" . $username . "' and rnd='" . $rnd . "' and checked=0 limit 1");
$user_fj = $username;
}
$classid = (int)$_GET['classid'];
$filepass = (int)$_GET['filepass'];
$action = RepPostVar($_GET['action']);
//验证权限并用帝国的配置项
if ($action != 'config') {
//获取配置
$pr = $empire->fetch1("select * from {$dbtbpre}enewspublic");
$check = check();
if ($check) {
echo $check;
exit();
} else { //通过验证用帝国配置项及目录等
if ($qiantai) {
//前台大小 后缀等限制
$qaddtransize = $public_r['qaddtransize'] * 1024;
$CONFIG['imageMaxSize'] = $qaddtransize;
$CONFIG['scrawlMaxSize'] = $qaddtransize;
$CONFIG['catcherMaxSize'] = $qaddtransize;
$qaddtranimgtype = substr($pr['qaddtranimgtype'], 1, -1);
$qaddtranimgtype = explode('|', $qaddtranimgtype);
$CONFIG['imageAllowFiles'] = $qaddtranimgtype;
$CONFIG['imageManagerAllowFiles'] = $qaddtranimgtype;
$CONFIG['catcherAllowFiles'] = $qaddtranimgtype;
$qaddtranfilesize = $pr['qaddtranfilesize'] * 1024;
$CONFIG['fileMaxSize'] = $qaddtranfilesize;
$CONFIG['videoMaxSize'] = $qaddtranfilesize;
$qaddtranfiletype = substr($pr['qaddtranfiletype'], 1, -1);
$qaddtranfiletype = explode('|', $qaddtranfiletype);
$CONFIG['fileAllowFiles'] = $qaddtranfiletype;
$CONFIG['fileManagerAllowFiles'] = $qaddtranfiletype;
} else {
//后台大小 后缀等限制
$filesize = $public_r['filesize'] * 1024;
$CONFIG['imageMaxSize'] = $filesize;
$CONFIG['scrawlMaxSize'] = $filesize;
$CONFIG['catcherMaxSize'] = $filesize;
$CONFIG['videoMaxSize'] = $filesize;
$CONFIG['fileMaxSize'] = $filesize;
$filetype = substr($pr['filetype'], 1, -1);
$filetype = explode('|', $filetype);
$CONFIG['fileAllowFiles'] = $filetype;
$CONFIG['fileManagerAllowFiles'] = $filetype;
}
$classpath = ReturnFileSavePath($classid); //栏目附件目录
$time = time();
$filedir = '';
if ($public_r['filepath']) {
$filedir = date($public_r['filepath'], $time) . '/';
$filedir2 = date($public_r['filepath'], $time);
}
$uepath = $pr['newsurl'] . $classpath['filepath'] . $filedir . '{time}{rand:6}'; //百度编辑器上传路径
//$uepath='/'.$classpath['filepath'].$filedir.md5(uniqid());//百度编辑器上传路径
if ($pr['openfileserver'] == 1) { //开启远程附件
$ftp_r = $empire->fetch1("select * from {$dbtbpre}enewspostserver where pid=1"); //返回FTP
$truepath = $ftp_r['purl'] . $filedir; //日期栏目目录filepath
$bdpath = ECMS_PATH . $classpath['filepath'] . $filedir;
} else {
$truepath = $bdpath . $filedir;
$bdpath = ECMS_PATH . $classpath['filepath'] . $filedir;
}
//$CONFIG['imageUrlPrefix']=$public_r['fileurl'];
//$CONFIG['scrawlUrlPrefix']=$public_r['fileurl'];
//$CONFIG['snapscreenUrlPrefix']=$public_r['fileurl'];
//$CONFIG['catcherUrlPrefix']=$public_r['fileurl'];
//$CONFIG['videoUrlPrefix']=$public_r['fileurl'];
//$CONFIG['fileUrlPrefix']=$public_r['fileurl'];
$CONFIG['imagePathFormat'] = $uepath;
$CONFIG['scrawlPathFormat'] = $uepath;
$CONFIG['snapscreenPathFormat'] = $uepath;
$CONFIG['videoPathFormat'] = $uepath;
$CONFIG['filePathFormat'] = $uepath;
$CONFIG['catcherPathFormat'] = $uepath;
}
}
//验证函数
function check() {
global $adminr, $dbtbpre, $action, $empire, $pr, $qiantai;
if ($qiantai == 1) { //前台的验证
if ($pr['addnews_ok'] == 1) {
$error = '{"state": "网站已关闭投稿功能!"}';
} else if (($action == 'uploadimage' || $action == 'uploadscrawl' || $action == 'catchimage') && (!$pr['qaddtran'])) {
$error = '{"state": "网站已关闭上传图片功能!"}';
} else if (($action == 'uploadvideo' || $action == 'uploadfile') && !$pr['qaddtranfile']) {
$error = '{"state": "网站已关闭上传附件功能!"}';
}
} else { //后台的验证
if ($adminr) {
//通过验证
} else {
$error = '{"state": "请重新登录"}';
}
}
return $error;
}
switch ($action) {
case 'config':
$result = json_encode($CONFIG);
break;
/* 上传图片 */
case 'uploadimage':
/* 上传涂鸦 */
case 'uploadscrawl':
/* 上传视频 */
case 'uploadvideo':
/* 上传文件 */
case 'uploadfile':
$result = include ("action_upload.php");
$result = json_decode($result, TRUE);
if ($pr['openfileserver'] == 1) { //开启远程附件补充前缀
$result['url'] = str_replace('/d/file/', '', $ftp_r['purl']) . $result['url']; //FTP前缀
//$result['original']=$result['title'];//标题是路径还是名称
$result = json_encode($result);
} else {
$result['url'] = str_replace('/d/file/', '', $pr['fileurl']) . $result['url']; //FTP前缀
$result = json_encode($result);
}
break;
/* 列出图片 */
case 'listimage':
//$result = include("action_list.php");
$result = action_list();
break;
/* 列出文件 */
case 'listfile':
// $result = include("action_list.php");
$result = action_list();
break;
/* 抓取远程文件 */
case 'catchimage':
$result = include ("action_crawler.php");
$result = json_decode($result, TRUE);
if ($pr['openfileserver'] == 1) { //开启远程附件补充前缀
$result['url'] = str_replace('/d/file/', '', $ftp_r['purl']) . $result['url']; //FTP前缀
//$result['original']=$result['title'];//标题是路径还是名称
$result = json_encode($result);
} else {
$result['url'] = str_replace('/d/file/', '', $pr['fileurl']) . $result['url']; //FTP前缀
$result = json_encode($result);
}
break;
default:
$result = json_encode(array('state' => '请求地址出错'));
break;
}
/* 输出结果 */
if (isset($_GET["callback"])) {
if (preg_match("/^[\w_]+$/", $_GET["callback"])) {
echo htmlspecialchars($_GET["callback"]) . '(' . $result . ')';
} else {
echo json_encode(array('state' => 'callback参数不合法'));
}
} else {
echo $result;
}
$actionarr = array('uploadimage', 'uploadscrawl', 'uploadvideo', 'uploadfile', 'catchimage');
if (in_array($action, $actionarr)) {
$file_r = json_decode($result, true);
if ($action == 'uploadimage' || $action == 'catchimage' || $action == 'uploadscrawl') {
$type = 1;
} elseif ($action == 'uploadvideo') {
$type = 3;
} else {
$type = 0;
}
if ($action == "catchimage") //远程保存
{
for ($i = 0;$i < count($file_r['list']);$i++) {
if ($file_r['list'][$i]['state'] == "SUCCESS") {
$title = RepPostStr(trim($file_r['list'][$i]['title']));
$filesize = RepPostStr(trim($file_r['list'][$i]['size']));
$original = RepPostStr(trim($file_r['list'][$i]['original']));
eInsertFileTable($title, $filesize, $filedir2, $user_fj, $classid, $original, $type, $filepass, $filepass, $public_r, 0, 0, 0);
}
}
} else if ($file_r['state'] == "SUCCESS") {
$title = RepPostStr(trim($file_r));
//判断是否FLASH
$typearr = explode('.', $title);
if ($typearr == 'swf') {
$type = 2;
}
$filesize = RepPostStr(trim($file_r));
$original = RepPostStr(trim($file_r));
//帝国上传附件是md5的文件名
if (!$type) {
$original = $title;
}
eInsertFileTable($title, $filesize, $filedir2, $user_fj, $classid, $original, $type, $filepass, $filepass, $public_r, 0, 0, 0);
}
$efileftp_fr = array(); //远程附件的图片数组
$efileftp_fr = $bdpath . '/' . $title; //远程附件所用的本地图片路径
}
// 列出已经上传的图像和文件
function action_list() {
global $empire, $dbtbpre, $filepass, $classid, $user_fj, $action, $qiantai, $pr, $ftp_r;
$list = array();
$result = json_encode(array("state" => "no match file", "list" => $list, "start" => 0, "total" => 0));
$where = "classid='$classid' and id='$filepass'";
if ($qiantai == 1) {
$where.= " and adduser='$user_fj'";
}
if ($action == 'listimage') //图片
{
$where.= ' and type=1';
} else if ($action == 'listfile') //附件、多媒体、FLASH
{
$where.= ' and type<>1';
} else {
return $result;
}
$size = (int)$_GET['size'];
$start = (int)$_GET['start'];
$limit = $start . "," . $size;
$total = $empire->gettotal("select count(*) as total from {$dbtbpre}enewsfile_1 where " . $where);
$sql = $empire->query("select * from {$dbtbpre}enewsfile_1 where " . $where . " order by fileid DESC limit " . $limit);
$i = 0;
while ($r = $empire->fetch($sql)) {
$classpath = ReturnFileSavePath($r, $r); //栏目附件目录
if ($pr['openfileserver'] == 1) { //开启远程附件补充前缀
$classpath['filepath'] = str_replace('d/file/', '', $ftp_r['purl']) . $classpath['filepath']; //FTP前缀
} else {
$classpath['filepath'] = str_replace('d/file/', '', $pr['fileurl']) . $classpath['filepath'];
}
$list[$i]['url'] = $classpath['filepath'] . ($r['path'] ? $r['path'] . '/' : $r) . $r['filename'];
$list[$i]['mtime'] = $r['filetime'];
$i++;
}
/* 返回数据 */
if (!count($list)) {
return $result;
}
return $result = json_encode(array("state" => "SUCCESS", "list" => $list, "start" => $start, "total" => $total));
}
db_close();
$empire = null;
exit();
?>
action_crawler.php源码:<?php
/**
* 抓取远程图片
* User: Jinqn
* Date: 14-04-14
* Time: 下午19:18
*/
set_time_limit(0);
include("Uploader.class.php");
/* 上传配置 */
$config = array(
"pathFormat" => $CONFIG['catcherPathFormat'],
"maxSize" => $CONFIG['catcherMaxSize'],
"allowFiles" => $CONFIG['catcherAllowFiles'],
"oriName" => "remote.png"
);
$fieldName = $CONFIG['catcherFieldName'];
/* 抓取远程图片 */
$list = array();
if (isset($_POST[$fieldName])) {
$source = $_POST[$fieldName];
} else {
$source = $_GET[$fieldName];
}
foreach ($source as $imgUrl) {
$item = new Uploader($imgUrl, $config, "remote");
$info = $item->getFileInfo();
/* URL处理 */
if($pr['openfileserver']==1){//开启远程附件补充前缀
$info["url"]=str_replace('/d/file/', '', $ftp_r['purl']).$info["url"];//FTP前缀
}else{
$info["url"]=str_replace('/d/file/', '', $pr['fileurl']).$info["url"];//非FTP前缀
}
/* URL处理 */
array_push($list, array(
"state" => $info["state"],
"url" => $info["url"],
"size" => $info["size"],
"title" => htmlspecialchars($info["title"]),
"original" => htmlspecialchars($info["original"]),
"source" => htmlspecialchars($imgUrl)
));
}
/* 返回抓取数据 */
return json_encode(array(
'state'=> count($list) ? 'SUCCESS':'ERROR',
'list'=> $list
));
前台使用:前台使用例子:
修改内容模板加入下面代码(注意:#newstext为前台编辑器容器ID)
<style type="text/css">
/*解决代码高亮太长不换行*/
.syntaxhighlighter{word-break:break-all;}
</style>
<script src="/e/extend/ueditor/ueditor.parse.min.js"></script>
<script>uParse('#newstext', {rootPath: '/e/extend/ueditor/'})</script>
<div id="newstext">[!--newstext--]</div>
本项目仅测试于帝国CMS7.0(UFT-8)正式版,其他版本暂时未测,请自行测试,支持帝国商业版的远程附件功能。
未修改百度UE(UEditor)的其他代码,为了确保后期升级。至于图片水印和附件删除等功能,考虑到帝国CMS升级所以未作整合,暂时可以依靠帝国CMS自身的管理功能即可,水印也可批量添加。
前台高亮等使用参考百度编辑器官方说明。这里不多说。后期会开发附件管理,图片水印,以及在线图片裁剪等功能性融合系统。
水印及附件管理说明截图:
项目源码打包:
编辑器7.2问题请参考7.2安全参数做响应修改即可。
页:
[1]