理论上可以替换包括百度ueditor在内的其他任何编辑器,步骤包括:
1.上传新编辑器代码
首先下载Kindeditor,解压后将文件夹命名为kindeditor,删除包内的无用文件,如asp*、jsp、examples、attached等,保留*-min.js
然后进入kindeditor/php/,修改file_manager_json.php文件:
$root_path = $php_path . '../../../images/upload/';
$root_url = $php_url . '../../../images/upload/';
再修改upload_json.php第16行:
$save_path = $php_path . '../../../images/upload/';
$save_url = $php_url . '../../../images/upload/';
最后将整个kindeditor文件夹上传至/ecshop/include/目录.
2.删除FckEditor引用及原始文件
接下来进入/admin/目录,删掉所有fckeditor的引用,找到以下文件:
article.php、filecheck.php、magazine_list.php、goods.php、shophelp.php、shopinfo.php、suppliers_goods.php、topic.php
在上述文件中查找下面其中一行并删除掉:
require_once(ROOT_PATH."includes/fckeditor/fckeditor.php");
include_once(ROOT_PATH.'includes/fckeditor/fckeditor.php');
然后可以删除掉整个fckeditor文件夹,即/includes/fckeditor/
3.修改编辑器兼容性功能及样式
- 首先找到/admin/includes/lib_main.php,将整个create_html_editor函数重写(第311行):
/**
* 生成编辑器
* @param string input_name 输入框名称
* @param string input_value 输入框值
* @param string params 额外参数
*/
function create_html_editor($input_name, $input_value = '', $params = '')
{
global $smarty;
$kindeditor="<script charset=\"utf-8\" src=\"../includes/kindeditor/kindeditor-min.js\"></script>
<script charset=\"utf-8\" src=\"../includes/kindeditor/plugins/autoheight/autoheight.js\"></script>
<script type=\"text/javascript\">
var editor;
function initEditor() {
KindEditor.ready(function(K) {
editor = K.create('textarea[name=\"$input_name\"]', {
allowFileManager : true,
autoHeightMode: true$params
});
});
}
initEditor();
</script>
<textarea id=\"$input_name\" name=\"$input_name\" style=\"width:100%\">$input_value</textarea>
";
$smarty->assign('FCKeditor', $kindeditor);
}
lib_main.php是后台的基本类库,很多功能都会自导加载这个文件,而上面这个函数将会以下其他地方引用到。
- 然后打开/admin/order.php第2469行,从include_once..到“$smarty->assign('fckeditor', $fckeditor)”
该功能用于订单打印模板修改,如果没找到以上代码,直接搜索fckeditor即可。将该段内容删除后再插入以下代码:
create_html_editor('FCKeditor1', $file_content, ",fullscreenMode:true,width:'100%'");
(注意这里我加了参数使页面打开时编辑器自动全屏。)
- 再修改/admin/mail_template.php,将第27行“include_once..fckeditor.php..”删除,
然后将第65行创建html editor的部分(同上面订单打印)替换为:
create_html_editor('content', $content['template_content']);
在这块代码下面第83行找到“载入指定模版”将elif中的全部内容删除并替换为以下代码:
elseif ($_REQUEST['act'] == 'loat_template') {
$tpl = intval($_GET['tpl']);
$content = load_template($tpl);
make_json_result($content);
}
这里是用于加载邮件模板的JSON请求,但是ecshop写的实在太蹩脚了简直无法直视…关键是不兼容kindeditor,只好做了修改。
- 以上内容改完后,还需要修改部分htm模板,首先是订单模板页order_templates.htm
将“{$fckeditor}”改为“{$FCKeditor}”即可,原因是公共函数中变量名改变了。然后是goods_info.htm
将第429行的button改为submit,否则商品详情可能无法保存。
最后是邮件模板页mail_template.htm,将整个文件替换为如下代码:
{if $full_page}
{include file="pageheader.htm"}
{insert_scripts files="../js/utils.js,listtable.js"}
<div class="form-div" id="conent_area">
{/if}
<form method="post" name="theForm" action="mail_template.php?act=save_template">
<table id="general-table">
<tr>
<td style="font-weight:bold" width="15%">{$lang.select_template}</td>
<td>
<select id="selTemplate" name="tpl" onchange="loadTemplate()" style="width:304px">
{html_options options=$templates selected=$cur}
</select>
</td>
</tr>
<tr>
<td style="font-weight: bold; " width="15%">{$lang.mail_subject}:</td>
<td><input type="text" name="subject" id="subject" style="width:300px" value="{$template.template_subject}"/></td>
</tr>
<tr>
<td colspan="2">{$FCKeditor}</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="hidden" name="is_html" value="1" />
<input type="submit" value="{$lang.button_submit}" class="button" />
</td>
</tr>
</table>
</form>
{if $full_page}
</div>
<script language="JavaScript">
{literal}
var orgContent = '';
/* 定义页面状态变量 */
onload = function() {
document.getElementById('selTemplate').focus();
document.forms['theForm'].reset();
// 开始检查订单
startCheckOrder();
}
/**
* 载入模板
*/
function loadTemplate() {
curContent = document.getElementById('content').value;
if (orgContent != curContent && orgContent != '' && !confirm(save_confirm))
return;
var tpl = document.getElementById('selTemplate').value;
Ajax.call('mail_template.php?is_ajax=1&act=loat_template', 'tpl=' + tpl, loadTemplateResponse, 'GET', 'JSON');
}
/**
* 将模板的内容载入到文本框中
*/
function loadTemplateResponse(result, textResult) {
if (result.error == 0) {
editor.html(result.content.template_content);
document.getElementById('subject').value = result.content.template_subject;
orgContent = '';
}
if (result.message.length > 0)
alert(result.message);
}
{/literal}
</script>
{include file="pagefooter.htm"}
{/if}
P.S.
后台无法读取cookie,原因是/ecshop/admin/templates/menu.htm中第380行调用了一个不存在的函数t_eval(),
其实这个函数在/ecshop/admin/js/menu.js中定义了只是从未引用而已,将其修改为以下代码:
this.SourceObject = eval("("+ document.getCookie(this.CookieName) +")");