PHPCMS V9 更新 ckeditor

2019-02-21 23:17:11     点击:

代码已验证 原创

以下示例ckeditor版本4.11.1


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

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

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

	/**
	 * 编辑器
	 * @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()函数完整代码如下:

	/**
	 * 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);
	}