当前位置: 首页 >
phpcms >  技术文章 > 

PHPCMS V9更新ckeditor

来源 : 转载     时间 : 2021-11-11 10:35:29     浏览 :   

以下示例ckeditor版本4.11.1


1、下载最新版本ckeditor,并将ckeditor解压至 statics/js 目录下

2、修改文件 phpcms/libs/classes/form.class.php

3、将 public static function editor 修改为以下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
    /**
     * 编辑器
     * @param int $textareaid
     * @param int $toolbar 
     * @param string $module 模块名称
     * @param int $catid 栏目id
     * @param int $color 编辑器颜色
     * @param boole $allowupload  是否允许上传
     * @param boole $allowbrowser 是否允许浏览文件
     * @param string $alowuploadexts 允许上传类型
     * @param string $height 编辑器高度
     * @param string $disabled_page 是否禁用分页和子标题
     */
    public static function editor($textareaid 'content'$toolbar 'basic'$module ''$catid ''$color ''$allowupload = 0, $allowbrowser = 1,$alowuploadexts '',$height = 200,$disabled_page = 0, $allowuploadnum '10') {
         
 
        $show_page = ($module == 'content' && !$disabled_page) ? 'true' 'false';
        $authkey = upload_key("$allowuploadnum,$alowuploadexts,$allowbrowser");
 
        $str '<script type="text/javascript" src="'.JS_PATH.'ckeditor-4.11.1/ckeditor.js"></script>';
        $str .="
 
            <script>
 
                CKEDITOR.replace('".$textareaid."',{
                    toolbar:[
                        { name: 'document', items: ['Source''-''Print''-''Templates' ] },
                        { name: 'styles', items: [ 'Styles''Format''Font''FontSize' ] },
                        { name: 'clipboard', items: [ 'Cut''Copy''Paste''PasteText''PasteFromWord''-''Undo''Redo' ] },
                        { name: 'editing', items: [ 'Find''Replace''-''SelectAll''-''Scayt' ] },
                        { name: 'basicstyles', items: [ 'Bold''Italic''Underline''Strike''Subscript''Superscript''-''CopyFormatting''RemoveFormat' ] },
                        { name: 'paragraph', items: [ 'NumberedList''BulletedList''-''Outdent''Indent''-''Blockquote''CreateDiv''-''JustifyLeft''JustifyCenter''JustifyRight''JustifyBlock''-''BidiLtr''BidiRtl'] },
                        { name: 'links', items: [ 'Link''Unlink''Anchor' ] },
                        { name: 'insert', items: [ 'Image''Flash''Table''HorizontalRule''Smiley''SpecialChar''PageBreak''Iframe' ] },
                        { name: 'colors', items: [ 'TextColor''BGColor' ] },
                        { name: 'tools', items: [ 'Maximize''ShowBlocks'] },
                        { name: 'extra', items: [ 'CodeSnippet'] }
                    ],
                    extraPlugins: 'codesnippet,pastefromexcel',
                    codeSnippet_theme: 'monokai',
                    removePlugins:[ 'elementspath'],
                    font_names:'宋体;微软雅黑;Arial;Helvetica;sans-serif;Times New Roman;Verdana',
                    language: 'zh-cn',
                     
                    height:".$height.",
 
                    pages:".$show_page.",
                    subtitle:".$show_page.",
                    textareaid:'".$textareaid."',
                    module:'".$module."',
                    catid:'".$catid."',
 
                    flashupload:true,
                    alowuploadexts:'".$alowuploadexts."',
                    allowbrowser:'".$allowbrowser."',
                    allowuploadnum:'".$allowuploadnum."',
                    authkey:'".$authkey."',
                    filebrowserUploadUrl: 'index.php?m=attachment&c=attachments&a=ckeditor_upload&module=".$module."&catid=".$catid."&dosubmit=1'
 
                });
 
 
            </script>
            ";
         
        return $str;
    }



4、修正上传,编辑 phpcms/modules/attachment/attachments.php

5、复制attachments.php 的public function upload(),并粘贴为新函数,重命名为:public function ckeditor_upload()

6、ckeditor_upload()函数完整代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
    /**
     * ckeditor常规上传
     */
    public function ckeditor_upload() {
        $grouplist = getcache('grouplist','member');
        if($this->isadmin==0 && !$grouplist[$this->groupid]['allowattachment']) return false;
        if($this->isadmin==1) define('IN_ADMIN',true);
        pc_base::load_sys_class('attachment','',0);
        $module = trim($_GET['module']);
        $catid intval($_GET['catid']);
        $siteid $this->get_siteid();
        $site_setting = get_site_setting($siteid);
        $site_allowext $site_setting['upload_allowext'];       
        $attachment new attachment($module,$catid,$siteid);
        $attachment->set_userid($this->userid);
        $a $attachment->upload('upload',$site_allowext);
        if($a){
            $filepath $attachment->uploadedfiles[0]['filepath'];
            $fn intval($_GET['CKEditorFuncNum']);
            $this->upload_json($a[0],$filepath,$attachment->uploadedfiles[0]['filename']);
            #$attachment->mkhtml($fn,$this->upload_url.$filepath,''); 编辑返回
         
            $result = [
                        "uploaded"=>true,
                        #"fileName"=>$attachment->uploadedfiles[0]['filename'],
                        "fileName"=>$this->upload_url.$filepath,
                        "url"=>$this->upload_url.$filepath,
                        "error"=>[
                            "message"=>""
                        ]
                    ];
        }else{
            $result = [
                "uploaded"=>false,
                "error"=>[
                    "message"=>"上传错误"
                ]
            ];
        }
        echo json_encode($result,JSON_UNESCAPED_UNICODE);
    }



石家庄捷搜网络致力于PHPCMS网站建设,模板制作,系统二次开发服务。

如果PHPCMS系统相关需求的可以联系我们。

客服微信:13832394380

  • 联系我们

  • 邮箱:794421925@qq.com
  • 电话:13832394380
  • Q Q:794421925 点击交谈
  • 地址:石家庄市南二环西路31号昊邦大厦A1602

Copyright © 2008-2021 石家庄捷搜网络科技有限公司 版权所有 备案号:冀ICP备16025780号-1