原文链接
http://www.kandaoni.com/experience/16
为了防止自己忘掉,还是放上来吧。改后有许多BUG…改的太多就不放上来了
wecenter 3.1.2替换编辑器为umeditor过程实录
WeCenter 是一款知识型的社交化开源社区程序,专注于企业和行业社区内容的整理、归类、检索和再发行。
wecenter一开始是用的是markdown编辑器,现在改成修改过的ckeditor,但总归是满足得了部分人,不能满足部分人。现在这里一步一步替换编辑器为umeditor。
使用的版本是wecenter 3.1.2
- 下载umeditor
我们先到
http://ueditor.baidu.com/website/onlinedemo.html
下载需要的版本,我下载的是
http://ueditor.baidu.com/build/build_down.php?n=umeditor&v=1_2_2-utf8-php
解压,命名文件夹为umeditor,复制到/static/
2. 修改functions.app.php
打开/system/functions.app.php
大概256行位置,修改代码为
function import_editor_static_files()
{
//TPL::import_js(‘js/editor/ckeditor/ckeditor.js’);
//TPL::import_js(‘js/editor/ckeditor/adapters/jquery.js’);
TPL::import_css(‘umeditor/themes/default/css/umeditor.css’);
TPL::import_js(‘umeditor/umeditor.config.js’);
TPL::import_js(‘umeditor/umeditor.min.js’);
TPL::import_js(‘umeditor/lang/zh-cn/zh-cn.js’);
}
3.添加兼容性css
打开文件/static/css/default/common.css
在末尾添加
/* fix umeditor */
.autosize{overflow-y:hidden !important;}
.edui-container{width:100% !important;}
.edui-body-container{width:100% !important;}
.modal-body .edui-body-container{width:100% !important;min-height:134px !important;}
.aw-editor-box .mod-head{border:none;}
4.修改publish.js
打开/static/js/app/publish.js
这个文件有两个地方需要修改,分别是
1、大概17行,修改为
// 判断是否开启ck编辑器
if (G_ADVANCED_EDITOR_ENABLE == ‘Y’)
{
// 初始化编辑器
//var editor = CKEDITOR.replace( ‘wmd-input’ );
var editor = UM.getEditor(‘wmd-input’);
}
2、大概100行,修改为
// 自动保存草稿
//$(‘textarea.wmd-input’).bind(‘blur’, function() {
editor.addListener(‘blur’, function() {
if (editor.hasContents())
{
$.post(G_BASE_URL + ‘/account/ajax/save_draft/item_id-1’ + PUBLISH_TYPE, ‘message=’ + encodeURIComponent(editor.getContent()),function (result) {
KaTeX parse error: Expected 'EOF', got '#' at position 3: ('#̲question_detail…(‘textarea#advanced_editor’).attr(‘value’, ‘’); AWS.User.delete_draft(1, ‘’ + PUBLISH_TYPE + ‘’); $(this).parent().html(’ ‘); return false;">’ + _t(‘删除草稿’) +’’);
}, ‘json’);
}
});
5.修改question_detail.js
打开/static/js/app/question_detail.js
这个文件要修改一个地方
大概23行,修改为
if (G_ADVANCED_EDITOR_ENABLE == ‘Y’)
{
//EDITOR = CKEDITOR.replace( ‘wmd-input’);
EDITOR = UM.getEditor(‘wmd-input’);
EDITOR_CALLBACK = function (evt)
{
//if (evt.editor.getData().length)
if (EDITOR.hasContents())
{
//$.post(G_BASE_URL + ‘/account/ajax/save_draft/’ + QUESTION_ID + ‘’ + ANSWER_TYPE, ‘message=’ + evt.editor.getData(), function (result) {
$.post(G_BASE_URL +’/account/ajax/save_draft/’ + QUESTION_ID + ‘’ + ANSWER_TYPE,‘message=’ + encodeURIComponent(EDITOR.getContent()), function (result) {
KaTeX parse error: Expected 'EOF', got '#' at position 3: ('#̲answer_content_…(‘textarea#advanced_editor’).attr(‘value’, ‘’); AWS.User.delete_draft(QUESTION_ID, ANSWER_TYPE); $(this).parent().html(’ ‘); return false;">’ + _t(‘删除草稿’) + ‘’);
}, ‘json’);
}
}
// 自动保存草稿
//EDITOR.on( ‘blur’, EDITOR_CALLBACK);
EDITOR.addListener( ‘blur’, EDITOR_CALLBACK);
}
6.修改fileupload.js
打开/static/js/fileupload.js
大概365行,修改为
// 创建插入按钮
createInsertBtn : function (attach_id)
{
var btn = this.toElement(this.options.insertBtnTemplate), _this = this;
$(btn).click(function()
{
//if (typeof CKEDITOR != ‘undefined’)
if (typeof UM != ‘undefined’)
{
//_this.editor.insertText("\n[attach]" + attach_id + “[/attach]\n”);
_this.editor.execCommand(‘insertHtml’, “
[attach]” + attach_id + “[/attach]
”);}
else
{
_this.editor.val( _this.editor.val() + “\n[attach]” + attach_id + “[/attach]\n”);
}
});
return btn;
},
7.修改aws.js
打开/static/js/aws.js
在大概134行,注释掉
/* if (typeof CKEDITOR != ‘undefined’)
{
for ( instance in CKEDITOR.instances ) {
CKEDITOR.instances[instance].updateElement();
}
} */
在大概716行,修改为
//var editor = CKEDITOR.replace( ‘editor_reply’ );
var editor = UM.getEditor( ‘editor_reply’ );
8.修改/app/account/ajax.php
打开/app/account/ajax.php
大概435行,修改为
//fix
_POST[‘message’]);
_GET[‘item_id’], $_GET[‘type’], $this->user_id, $_POST);
9.修改/app/article/main.php
打开/app/article/main.php
大概62行,修改为
article_info[‘message’]));
大概212行,修改为
foreach ($article_list AS $key => $val)
{
key][‘user_info’] =
val[‘uid’]];
key][‘message’] = htmlspecialchars_decode($val[‘message’]);
}
10.修改/app/question/main.php
打开/app/question/main.php
大概254行,修改为
//$answer[‘answer_content’] =
answer[‘answer_content’]))));
$answer[‘answer_content’] =
answer[‘answer_content’])));
大概305行,修改为
//
question_info[‘question_detail’])));
question_info[‘question_detail’]));
11.修改/app/explore/main.php
打开/app/explore/main.php
大概137行,需改为
if (KaTeX parse error: Expected '}', got 'EOF' at end of input: … foreach (posts_list AS $key => KaTeX parse error: Expected '}', got 'EOF' at end of input: … if (val[‘answer_count’])
{
key][‘answer_users’] =
val[‘question_id’], 2, KaTeX parse error: Expected 'EOF', got '}' at position 40: … }̲ …val[‘message’]){
key][‘message’] = strip_tags(htmlspecialchars_decode(KaTeX parse error: Expected 'EOF', got '}' at position 35: … }̲ …val[‘question_detail’]){
key][‘question_detail’] = strip_tags(htmlspecialchars_decode($val[‘message’]));
}
}
}
12.修改\views\default\question\index.tpl.htm
修改\views\default\question\ajax\answer.tpl.htm
这两个文件具体改了什么忘了,自己对照吧