相信正在使用織夢dedecms作為網(wǎng)站管理程序的站長朋友對織夢自帶的ckeditor編輯器一定感到非常糾心:其難看的外觀,不太好用的添加視頻功能,超級弱智的圖片上傳項(xiàng),就連按個"tab"鍵都要跳出編輯框...這些無不讓我們對其深惡痛絕(可能說得有點(diǎn)夸張)!
本人最近開了一個新站,最初因?yàn)檫@個ckeditor編輯器給編輯工作帶來了諸多不便,所以最后痛下決心:改成百度ueditor。
為什么改成ueditor而不是別的編輯器呢?原因主要有三點(diǎn):
一、ueditor界面相當(dāng)美觀,用起來舒服;
二、功能強(qiáng)悍,比如圖片上傳功能:它支持批量上傳,圖片搜索,還有非常不錯的圖片管理器;再比如視頻添加功能:直接填寫優(yōu)酷土豆等視頻網(wǎng)址即可,不用像ckeditor那樣非常麻煩地去找".swf"的flash地址;
三、基于百度雄厚的實(shí)力,相信這個ueditor功能也會越來越強(qiáng)大。
是不是心動了?想體驗(yàn)ueditor的朋友可以去我的小創(chuàng)意網(wǎng)(www.smallcy.com)看看,相信會帶給你不錯的體驗(yàn)。
不過ueditor裝上后也不是馬上就能用的(至于怎么安裝,大家可以在官方論壇上找),一般都會存在一些小問題。下面我就來談?wù)勂渲幸粋€非常重要的問題的解決方案。
安裝完ueditor后,我們可以在ueditor的配置文件中對其界面寬度進(jìn)行設(shè)置,但問題就出在這里,在這里設(shè)置的寬度是對全局而言,即所有網(wǎng)站內(nèi)的編輯器寬度都一樣。但對于我們dedecms用戶而言,一般前臺和后臺編輯器寬度不一致,這樣就會造成編輯器越界的問題。解決方案:將ueditor寬度設(shè)置放在編輯器調(diào)用階段,具體做法如下:
1. /include/helpers/util.helper.php中增加以下代碼:
if ( ! function_exists('GetEditorD'))
{
function GetEditorD($fname, $fvalue, $nheight="350", $etype="Basic", $gtype="print", $isfullpage="FALSE",$bbcode=false)
{
if(!function_exists('SpGetEditorD'))
{
require_once(DEDEINC."/inc/inc_fun_funAdmin.php");
}
return SpGetEditorD($fname, $fvalue, $nheight, $etype, $gtype, $isfullpage, $bbcode);
}
}
2. /include/inc/inc_fun_funAdmin.php中增加以下代碼:
function SpGetEditorD($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;
}
}else if($GLOBALS['cfg_html_editor']=='ueditor')
{
$fvalue = $fvalue=='' ? '<p></p>' : $fvalue;
$code = '<script type="text/javascript" charset="gbk" src="'.$GLOBALS['cfg_cmspath'].'/include/ueditor/editor_config.js"></script>
<script type="text/javascript" charset="gbk" src="'.$GLOBALS['cfg_cmspath'].'/include/ueditor/editor_all_min.js"></script>
<link rel="stylesheet" type="text/css" href="'.$GLOBALS['cfg_cmspath'].'/include/ueditor/themes/default/ueditor.css"/>
<textarea name="'.$fname.'" id="'.$fname.'" style="width:100%;">'.$fvalue.'</textarea>
<script type="text/javascript">
var ue = new baidu.editor.ui.Editor({ initialFrameWidth:824 });ue.render("'.$fname.'"); //紅色處為修改寬度
</script>';
if($gtype=="print")
{
echo $code;
}
else
{
return $code;
}
}
else {
/*
// ------------------------------------------------------------------------
// 當(dāng)前版本,暫時取消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();
}
*/
}
}
3. 在編輯器調(diào)取頁面將以下代碼:
<?php GetEditor("body","",350,"Member"); ?>
改為:
<?php GetEditorD("body","",350,"Member"); ?>
以上方案的思想是:在不同界面使用不同的編輯器調(diào)用函數(shù)。
當(dāng)然你可以根據(jù)需要對以上代碼進(jìn)行刪改,還有什么問題可以去小創(chuàng)意網(wǎng)(www.smallcy.com)咨詢。
申請創(chuàng)業(yè)報道,分享創(chuàng)業(yè)好點(diǎn)子。點(diǎn)擊此處,共同探討創(chuàng)業(yè)新機(jī)遇!