ECShop 預設使用 FCKeditor,已停止維護多年。本文記錄將後台編輯器升級為百度 UEditor 1.4.3(2015 年最終版)的完整步驟,含 jQuery 衝突修正與商品編輯儲存 Bug 修復。
config.json 上傳路徑設定).DS_Store 檔案# 解壓 UEditor 至
/includes/ueditor/
# 解壓修正補丁至
/includes/ueditor/fix_jquery/
/admin/includes/lib_main.php - 替換編輯器生成函式找到 create_html_editor() 函式(約第 300 行),完整替換為:
<?php
/**
* 生成編輯器
* @param string $input_name 輸入框名稱
* @param string $input_value 輸入框值
*/
function create_html_editor($input_name, $input_value = '')
{
global $smarty;
$kindeditor = "
<script id='editor' name='$input_name' type='text/plain' style='width:1024px;height:500px;'>$input_value</script>
<script charset='utf-8' src='../includes/ueditor/ueditor.config.js'></script>
<script charset='utf-8' src='../includes/ueditor/ueditor.all.min.js'></script>
<script>
var ue = UE.getEditor('editor');
</script>
";
$smarty->assign('FCKeditor', $kindeditor);
}
?>
/admin/templates/pageheader.htm - 載入修正版 jQuery找到:
{insert_scripts files="../js/transport.js,common.js,../js/utils.js"}
替換為:
<script src="../includes/ueditor/fix_jquery/jquery.min.js"></script>
<script src="../includes/ueditor/fix_jquery/jquery.json-1.3.js"></script>
<script src="js/common.js"></script>
<script src="../includes/ueditor/fix_jquery/transport_json.js"></script>
{insert_scripts files="../js/utils.js"}
檔案:/admin/templates/goods_info.htm
找到:
document.forms['theForm'].reset();
註解掉:
// document.forms['theForm'].reset();
原因: 表單重置會清空 UEditor 的 iframe 內容,導致提交空值。
編輯 /includes/ueditor/php/config.json:
{
"imagePathFormat": "/data/ueditor/php/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}",
"scrawlPathFormat": "/data/ueditor/php/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}",
"snapscreenPathFormat": "/data/ueditor/php/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}",
"catcherPathFormat": "/data/ueditor/php/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}",
"videoPathFormat": "/data/ueditor/php/upload/video/{yyyy}{mm}{dd}/{time}{rand:6}",
"filePathFormat": "/data/ueditor/php/upload/file/{yyyy}{mm}{dd}/{time}{rand:6}",
"imageManagerListPath": "/data/ueditor/php/upload/image/",
"fileManagerListPath": "/data/ueditor/php/upload/file/"
}
確保上傳目錄可寫入:
chmod 777 /data/ueditor/php/upload/
| 現象 | 解決方案 |
|---|---|
| 編輯器區域空白/不顯示 | 檢查 JS 載入順序、確認路徑正確、瀏覽器控制台無 404 |
| 圖片上傳失敗 | 檢查 config.json 路徑、PHP 上傳目錄權限、php.ini upload_max_filesize |
| 內容儲存為空 | 確認已註冊 goods_info.htm 的 form.reset()、檢查表單 name 與 UEditor id 一致 |
| jQuery 衝突報錯 | 確認 pageheader.htm 已載入 fix_jquery 版本、無重複載入其他 jQuery |
goods_desc、article_content 等欄位內容正確完成上述步驟即可將 ECShop 後台編輯器現代化,獲得更好的使用體驗與相容性。建議定期檢查 UEditor 官方是否有安全性更新(雖 1.4.3 為最終版,但社群仍有維護分支)。