wecenter 3.1.2替换编辑器为umeditor过程实录

2017-01-31 admin 36

wecenter 3.1.2替换编辑器为umeditor过程实录

WeCenter 是一款知识型的社交化开源社区程序,专注于企业和行业社区内容的整理、归类、检索和再发行。

wecenter一开始是用的是markdown编辑器,现在改成修改过的ckeditor,但总归是满足得了部分人,不能满足部分人。现在这里一步一步替换编辑器为umeditor。
使用的版本是wecenter 3.1.2
  • 1.下载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行位置,修改代码为
    1
    2
    3
    4
    5
    6
    7
    8
    9
    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
    在末尾添加
    1
    2
    3
    4
    5
    6
    7
    8

    /* 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;}
    <pre class="brush: js;">                                       
  • 4.修改publish.js

    打开/static/js/app/publish.js
    这个文件有两个地方需要修改,分别是
    1、大概17行,修改为
    1
    2
    3
    4
    5
    6
    7
    // 判断是否开启ck编辑器
        if (G_ADVANCED_EDITOR_ENABLE == 'Y')
        {
            // 初始化编辑器
            //var editor = CKEDITOR.replace( 'wmd-input' );
            var editor = UM.getEditor('wmd-input');
        }
    2、大概100行,修改为
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    // 自动保存草稿
    //$('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) {
                $('#question_detail_message').html(result.err + ' ' + _t('删除草稿') + '');
            }, 'json');
        }
    });
  • 5.修改question_detail.js

    打开/static/js/app/question_detail.js
    这个文件要修改一个地方
    大概23行,修改为
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    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) {
                                $('#answer_content_message').html(result.err + ' ' + _t('删除草稿') + '');
                            }, 'json');
                        }
                    }
     
                    // 自动保存草稿
                    //EDITOR.on( 'blur', EDITOR_CALLBACK);
                    EDITOR.addListener( 'blur', EDITOR_CALLBACK);
                }
  • 6.修改fileupload.js

    打开/static/js/fileupload.js
    大概365行,修改为
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    // 创建插入按钮
    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行,注释掉
    1
    2
    3
    4
    5
    6
    /* if (typeof CKEDITOR != 'undefined')
            {
                for ( instance in CKEDITOR.instances ) {
                    CKEDITOR.instances[instance].updateElement();
                }
            } */
    在大概716行,修改为
    1
    2
    //var editor = CKEDITOR.replace( 'editor_reply' );
    var editor = UM.getEditor( 'editor_reply' );
  • 8.修改/app/account/ajax.php

    打开/app/account/ajax.php
    大概435行,修改为
    1
    2
    3
    //fix
            $_POST['message'] = urldecode($_POST['message']);
            $this->model('draft')->save_draft($_GET['item_id'], $_GET['type'], $this->user_id, $_POST);
  • 9.修改/app/article/main.php

    打开/app/article/main.php
    大概62行,修改为
    1
    $article_info['message'] = FORMAT::parse_attachs(htmlspecialchars_decode($article_info['message']));
    大概212行,修改为
    1
    2
    3
    4
    5
    foreach ($article_list AS $key => $val)
    {
        $article_list[$key]['user_info'] = $article_users_info[$val['uid']];
        $article_list[$key]['message'] = htmlspecialchars_decode($val['message']);
    }
  • 10.修改/app/question/main.php

    打开/app/question/main.php
    大概254行,修改为
    1
    2
    //$answer['answer_content'] = $this->model('question')->parse_at_user(FORMAT::parse_attachs(nl2br(FORMAT::parse_bbcode($answer['answer_content']))));
    $answer['answer_content'] = $this->model('question')->parse_at_user(FORMAT::parse_attachs(htmlspecialchars_decode($answer['answer_content'])));
    大概305行,修改为
    1
    2
    //$question_info['question_detail'] = FORMAT::parse_attachs(nl2br(FORMAT::parse_bbcode($question_info['question_detail'])));
    $question_info['question_detail'] = FORMAT::parse_attachs(htmlspecialchars_decode($question_info['question_detail']));
  • 11.修改/app/explore/main.php

    打开/app/explore/main.php
    大概137行,需改为
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    if ($posts_list)
            {
                foreach ($posts_list AS $key => $val)
                {
                    if ($val['answer_count'])
                    {
                        $posts_list[$key]['answer_users'] = $this->model('question')->get_answer_users_by_question_id($val['question_id'], 2, $val['published_uid']);
                    }
                    if($val['message']){
                        $posts_list[$key]['message'] = strip_tags(htmlspecialchars_decode($val['message']));
                    }
                    if($val['question_detail']){
                        $posts_list[$key]['question_detail'] = strip_tags(htmlspecialchars_decode($val['message']));
                    }
                }
            }
  • 12.修改\views\default\question\index.tpl.htm

    修改\views\default\question\ajax\answer.tpl.htm

    这两个文件具体改了什么忘了,自己对照吧
  • 替换umeditor.zip