原文链接
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
P
O
S
T
[
′
m
e
s
s
a
g
e
′
]
=
u
r
l
d
e
c
o
d
e
(
_POST['message'] = urldecode(
POST[′message′]=urldecode(_POST[‘message’]);
t
h
i
s
−
>
m
o
d
e
l
(
′
d
r
a
f
t
′
)
−
>
s
a
v
e
d
r
a
f
t
(
this->model('draft')->save_draft(
this−>model(′draft′)−>savedraft(_GET[‘item_id’], $_GET[‘type’], $this->user_id, $_POST);
9.修改/app/article/main.php
打开/app/article/main.php
大概62行,修改为
a r t i c l e i n f o [ ′ m e s s a g e ′ ] = F O R M A T : : p a r s e a t t a c h s ( h t m l s p e c i a l c h a r s d e c o d e ( article_info['message'] = FORMAT::parse_attachs(htmlspecialchars_decode( articleinfo[′message′]=FORMAT::parseattachs(htmlspecialcharsdecode(article_info[‘message’]));
大概212行,修改为
foreach ($article_list AS $key => $val)
{
a
r
t
i
c
l
e
l
i
s
t
[
article_list[
articlelist[key][‘user_info’] =
a
r
t
i
c
l
e
u
s
e
r
s
i
n
f
o
[
article_users_info[
articleusersinfo[val[‘uid’]];
a
r
t
i
c
l
e
l
i
s
t
[
article_list[
articlelist[key][‘message’] = htmlspecialchars_decode($val[‘message’]);
}
10.修改/app/question/main.php
打开/app/question/main.php
大概254行,修改为
//$answer[‘answer_content’] =
t
h
i
s
−
>
m
o
d
e
l
(
′
q
u
e
s
t
i
o
n
′
)
−
>
p
a
r
s
e
a
t
u
s
e
r
(
F
O
R
M
A
T
:
:
p
a
r
s
e
a
t
t
a
c
h
s
(
n
l
2
b
r
(
F
O
R
M
A
T
:
:
p
a
r
s
e
b
b
c
o
d
e
(
this->model('question')->parse_at_user(FORMAT::parse_attachs(nl2br(FORMAT::parse_bbcode(
this−>model(′question′)−>parseatuser(FORMAT::parseattachs(nl2br(FORMAT::parsebbcode(answer[‘answer_content’]))));
$answer[‘answer_content’] =
t
h
i
s
−
>
m
o
d
e
l
(
′
q
u
e
s
t
i
o
n
′
)
−
>
p
a
r
s
e
a
t
u
s
e
r
(
F
O
R
M
A
T
:
:
p
a
r
s
e
a
t
t
a
c
h
s
(
h
t
m
l
s
p
e
c
i
a
l
c
h
a
r
s
d
e
c
o
d
e
(
this->model('question')->parse_at_user(FORMAT::parse_attachs(htmlspecialchars_decode(
this−>model(′question′)−>parseatuser(FORMAT::parseattachs(htmlspecialcharsdecode(answer[‘answer_content’])));
大概305行,修改为
//
q
u
e
s
t
i
o
n
i
n
f
o
[
′
q
u
e
s
t
i
o
n
d
e
t
a
i
l
′
]
=
F
O
R
M
A
T
:
:
p
a
r
s
e
a
t
t
a
c
h
s
(
n
l
2
b
r
(
F
O
R
M
A
T
:
:
p
a
r
s
e
b
b
c
o
d
e
(
question_info['question_detail'] = FORMAT::parse_attachs(nl2br(FORMAT::parse_bbcode(
questioninfo[′questiondetail′]=FORMAT::parseattachs(nl2br(FORMAT::parsebbcode(question_info[‘question_detail’])));
q
u
e
s
t
i
o
n
i
n
f
o
[
′
q
u
e
s
t
i
o
n
d
e
t
a
i
l
′
]
=
F
O
R
M
A
T
:
:
p
a
r
s
e
a
t
t
a
c
h
s
(
h
t
m
l
s
p
e
c
i
a
l
c
h
a
r
s
d
e
c
o
d
e
(
question_info['question_detail'] = FORMAT::parse_attachs(htmlspecialchars_decode(
questioninfo[′questiondetail′]=FORMAT::parseattachs(htmlspecialcharsdecode(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’])
{
p
o
s
t
s
l
i
s
t
[
posts_list[
postslist[key][‘answer_users’] =
t
h
i
s
−
>
m
o
d
e
l
(
′
q
u
e
s
t
i
o
n
′
)
−
>
g
e
t
a
n
s
w
e
r
u
s
e
r
s
b
y
q
u
e
s
t
i
o
n
i
d
(
this->model('question')->get_answer_users_by_question_id(
this−>model(′question′)−>getanswerusersbyquestionid(val[‘question_id’], 2, KaTeX parse error: Expected 'EOF', got '}' at position 40: … }̲ …val[‘message’]){
p
o
s
t
s
l
i
s
t
[
posts_list[
postslist[key][‘message’] = strip_tags(htmlspecialchars_decode(KaTeX parse error: Expected 'EOF', got '}' at position 35: … }̲ …val[‘question_detail’]){
p
o
s
t
s
l
i
s
t
[
posts_list[
postslist[key][‘question_detail’] = strip_tags(htmlspecialchars_decode($val[‘message’]));
}
}
}
12.修改\views\default\question\index.tpl.htm
修改\views\default\question\ajax\answer.tpl.htm
这两个文件具体改了什么忘了,自己对照吧