众所周知,dede自带的编辑器功能相对比较弱,百度的富文本编辑器很强大。可以有自动缩进等功能。
百度编辑器目前最新版本:1.4.3.3,首先查看你的dede 的编码版本为GBK还是UTF-8,否则会乱码。
下载地址:http://ueditor.baidu.com/website/download.html#ueditor
找到PHP版本,以下以dedecms 5.7 sp1 UTF-8举例。
替换方法如下:
1、在dede的include目录下建立文件夹ueditor,将下载下来文件utf8-php下的所有文件放在ueditor目录下面。
2、找到include/inc文件夹下面的inc_fun_funAdmin.php,把全部代码替换为如下。
[code]
<?php if(!defined(‘DEDEINC’)) exit(‘dedecms’);
/**
* 管理员后台基本函数
*
* @version $Id:inc_fun_funAdmin.php 1 13:58 2010年7月5日Z tianya $
* @package DedeCMS.Libraries
* @copyright Copyright (c) 2007 – 2010, DesDev, Inc.
* @license http://help.dedecms.com/usersguide/license.html
* @link http://www.dedecms.com
*/
/**
* 获取拼音信息
*
* @access public
* @param string $str 字符串
* @param int $ishead 是否为首字母
* @param int $isclose 解析后是否释放资源
* @return string
*/
function SpGetPinyin($str, $ishead=0, $isclose=1)
{
global $pinyins;
$restr = ”;
$str = trim($str);
$slen = strlen($str);
if($slen < 2)
{
return $str;
}
if(count($pinyins) == 0)
{
$fp = fopen(DEDEINC.’/data/pinyin.dat’, ‘r’);
while(!feof($fp))
{
$line = trim(fgets($fp));
$pinyins[$line[0].$line[1]] = substr($line, 3, strlen($line)-3);
}
fclose($fp);
}
for($i=0; $i<$slen; $i++)
{
if(ord($str[$i])>0x80)
{
$c = $str[$i].$str[$i+1];
$i++;
if(isset($pinyins[$c]))
{
if($ishead==0)
{
$restr .= $pinyins[$c];
}
else
{
$restr .= $pinyins[$c][0];
}
}else
{
$restr .= "_";
}
}else if( preg_match("/[a-z0-9]/i", $str[$i]) )
{
$restr .= $str[$i];
}
else
{
$restr .= "_";
}
}
if($isclose==0)
{
unset($pinyins);
}
return $restr;
}
/**
* 创建目录
*
* @access public
* @param string $spath 目录名称
* @return string
*/
function SpCreateDir($spath)
{
global $cfg_dir_purview,$cfg_basedir,$cfg_ftp_mkdir,$isSafeMode;
if($spath==”)
{
return true;
}
$flink = false;
$truepath = $cfg_basedir;
$truepath = str_replace("\\","/",$truepath);
$spaths = explode("/",$spath);
$spath = "";
foreach($spaths as $spath)
{
if($spath=="")
{
continue;
}
$spath = trim($spath);
$truepath .= "/".$spath;
if(!is_dir($truepath) || !is_writeable($truepath))
{
if(!is_dir($truepath))
{
$isok = MkdirAll($truepath,$cfg_dir_purview);
}
else
{
$isok = ChmodAll($truepath,$cfg_dir_purview);
}
if(!$isok)
{
echo "创建或修改目录:".$truepath." 失败!<br>";
CloseFtp();
return false;
}
}
}
CloseFtp();
return true;
}
function jsScript($js)
{
$out = "<script type=\"text/javascript\">";
$out .= "//<![CDATA[\n";
$out .= $js;
$out .= "\n//]]>";
$out .= "</script>\n";
return $out;
}
/**
* 获取编辑器
*
* @access public
* @param string $fname 表单名称
* @param string $fvalue 表单值
* @param string $nheight 内容高度
* @param string $etype 编辑器类型
* @param string $gtype 获取值类型
* @param string $isfullpage 是否全屏
* @return string
*/
function SpGetEditor($fname,$fvalue,$nheight="350",$etype="Basic",$gtype="print",$isfullpage="false",$bbcode=false)
{
global $cfg_ckeditor_initialized;
if(!isset($GLOBALS[‘cfg_html_editor’]))
{
$GLOBALS[‘cfg_html_editor’]=’fck’;
}
if($gtype=="")
{
$gtype = "print";
}
if($GLOBALS[‘cfg_html_editor’]==’fck’)
{
require_once(DEDEINC.’/FCKeditor/fckeditor.php’);
$fck = new FCKeditor($fname);
$fck->BasePath = $GLOBALS[‘cfg_cmspath’].’/include/FCKeditor/’ ;
$fck->Width = ‘100%’ ;
$fck->Height = $nheight ;
$fck->ToolbarSet = $etype ;
$fck->Config[‘FullPage’] = $isfullpage;
if($GLOBALS[‘cfg_fck_xhtml’]==’Y’)
{
$fck->Config[‘EnableXHTML’] = ‘true’;
$fck->Config[‘EnableSourceXHTML’] = ‘true’;
}
$fck->Value = $fvalue ;
if($gtype=="print")
{
$fck->Create();
}
else
{
return $fck->CreateHtml();
}
}
else if($GLOBALS[‘cfg_html_editor’]==’ckeditor’)
{
require_once(DEDEINC.’/ckeditor/ckeditor.php’);
$CKEditor = new CKEditor();
$CKEditor->basePath = $GLOBALS[‘cfg_cmspath’].’/include/ckeditor/’ ;
$config = $events = array();
$config[‘extraPlugins’] = ‘dedepage,multipic,addon’;
if($bbcode)
{
$CKEditor->initialized = true;
$config[‘extraPlugins’] .= ‘,bbcode’;
$config[‘fontSize_sizes’] = ’30/30%;50/50%;100/100%;120/120%;150/150%;200/200%;300/300%’;
$config[‘disableObjectResizing’] = ‘true’;
$config[‘smiley_path’] = $GLOBALS[‘cfg_cmspath’].’/images/smiley/’;
// 获取表情信息
require_once(DEDEDATA.’/smiley.data.php’);
$jsscript = array();
foreach($GLOBALS[‘cfg_smileys’] as $key=>$val)
{
$config[‘smiley_images’][] = $val[0];
$config[‘smiley_descriptions’][] = $val[3];
$jsscript[] = ‘"’.$val[3].’":"’.$key.’"’;
}
$jsscript = implode(‘,’, $jsscript);
echo jsScript(‘CKEDITOR.config.ubb_smiley = {‘.$jsscript.’}’);
}
$GLOBALS[‘tools’] = empty($toolbar[$etype])? $GLOBALS[‘tools’] : $toolbar[$etype] ;
$config[‘toolbar’] = $GLOBALS[‘tools’];
$config[‘height’] = $nheight;
$config[‘skin’] = ‘kama’;
$CKEditor->returnOutput = TRUE;
$code = $CKEditor->editor($fname, $fvalue, $config, $events);
if($gtype=="print")
{
echo $code;
}
else
{
return $code;
}
}
// 增加百度编辑器2015-5-1
else if($GLOBALS[‘cfg_html_editor’]==’ueditor’)
{
$fvalue = $fvalue==” ? ‘<p></p>’ : $fvalue;
$code = ‘<script type="text/javascript" charset="utf-8" src="’.$GLOBALS[‘cfg_cmspath’].’/include/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="’.$GLOBALS[‘cfg_cmspath’].’/include/ueditor/ueditor.all.js"></script>
<link rel="stylesheet" type="text/css" href="’.$GLOBALS[‘cfg_cmspath’].’/include/ueditor/themes/default/css/ueditor.min.css"/>
<textarea name="’.$fname.’" id="’.$fname.’" style="width:100%;">’.$fvalue.’</textarea>
<script type="text/javascript">var ue = new baidu.editor.ui.Editor();ue.render("’.$fname.’");</script>’;
if($gtype=="print")
{
echo $code;
}
else
{
return $code;
}
}
else {
/*
// ————————————————————————
// 当前版本,暂时取消dedehtml编辑器的支持
// ————————————————————————
require_once(DEDEINC.’/htmledit/dede_editor.php’);
$ded = new DedeEditor($fname);
$ded->BasePath = $GLOBALS[‘cfg_cmspath’].’/include/htmledit/’ ;
$ded->Width = ‘100%’ ;
$ded->Height = $nheight ;
$ded->ToolbarSet = strtolower($etype);
$ded->Value = $fvalue ;
if($gtype=="print")
{
$ded->Create();
}
else
{
return $ded->CreateHtml();
}
*/
}
}
/**
* 获取更新信息
*
* @return void
*/
function SpGetNewInfo()
{
global $cfg_version,$dsql;
$nurl = $_SERVER[‘HTTP_HOST’];
if( preg_match("#[a-z\-]{1,}\.[a-z]{2,}#i",$nurl) ) {
$nurl = urlencode($nurl);
}
else {
$nurl = "test";
}
$phpv = phpversion();
$sp_os = PHP_OS;
$mysql_ver = $dsql->GetVersion();
$offUrl = "http://new"."ver.a"."pi.de"."decms.com/index.php?c=info57&version={$cfg_version}&formurl={$nurl}&phpver={$phpv}&os={$sp_os}&mysqlver={$mysql_ver}";
return $offUrl;
}
?>
[/code]
3、修改图片保存目录,不修改也没关系,只不过默认保存在ueditor编辑器自己的目录下,为了统一,修改为dede自己的上传目录。打到ueditor\php目录,打开config.json,找到第12行,”imagePathFormat”开头的修改为。
[code] "imagePathFormat": "/uploads/allimg/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
[/code]
4、登录dede后台,系统,系统基本参数,核心设置,将HTML编辑器修改为ueditor。
至此全部完成
你真的以为完成了,其实到这里文章编辑发布都没有问题,但在编辑栏目页封面时会发现保存不了,添加栏目内容时没问题。
网上还是有高人解决了这个问题。
修改文件位置/dede/templates 文件 catalog_edit.htm、catalog_add.htm,将前后两个form移动到td内部。其他修改函数的不用操作。