太阳成游戏网站

联系官方销售客服

QQ1835022299

028-61286886

太阳成游戏网站框架 版主:太阳成游戏网站框架研发组
怎么使用自定义字段类型怎么使用自定义字段类型想要修改的百度编
类型:太阳成游戏网站CMS 更新时间:2020-07-12 14:17:56 字段 编辑器

怎么使用:自定义字段类型,想要修改官方的百度编辑器,但是不想动官方原来的ueditor,想复制官方的ueditor字段类型增加一个比如:gitueditor字段类型,

按照官方教程/doc/940.html操作;

1、在www/api目录复制ueditor文件夹,重命名为gitueditor

2、在\dayrui\My\Field下新建\dayrui\My\Field\Field.php文件,内容:

 'Gitueditor',
        'name' => 'Github-百度编辑器',
        'used' => '',
        'namespace' => '',
    ],
];



新建文件:\dayrui\My\Field\Gitueditor.php 内容:

close_xss = 1; // 关闭xss验证
        $this->fieldtype = ['MEDIUMTEXT' => ''];
        $this->defaulttype = 'MEDIUMTEXT';
    }

    /**
     * 字段相关属性参数
     *
     * @param   array   $value  值
     * @return  string
     */
    public function option($option) {

        $option['mode'] = isset($option['mode']) ? $option['mode'] : 1;
        $option['page'] = isset($option['page']) ? $option['page'] : 0;
        $option['tool'] = isset($option['tool']) ? $option['tool'] : '\'bold\', \'italic\', \'underline\'';
        $option['mode2'] = isset($option['mode2']) ? $option['mode2'] : $option['mode'];
        $option['tool2'] = isset($option['tool2']) ? $option['tool2'] : $option['tool'];
        $option['mode3'] = isset($option['mode3']) ? $option['mode3'] : $option['mode'];
        $option['tool3'] = isset($option['tool3']) ? $option['tool3'] : $option['tool'];
        $option['value'] = isset($option['value']) ? $option['value'] : '';
        $option['width'] = isset($option['width']) ? $option['width'] : '100%';
        $option['height'] = isset($option['height']) ? $option['height'] : 300;
        $option['fieldtype'] = isset($option['fieldtype']) ? $option['fieldtype'] : '';
        $option['autofloat'] = isset($option['autofloat']) ? $option['autofloat'] : 0;
        $option['autoheight'] = isset($option['autoheight']) ? $option['autoheight'] : 0;
        $option['fieldlength'] = isset($option['fieldlength']) ? $option['fieldlength'] : '';
        $option['watermark'] = isset($option['watermark']) ? $option['watermark'] : '';
        $option['show_bottom_boot'] = isset($option['show_bottom_boot']) ? $option['show_bottom_boot'] : '';

        $wm = \Phpcmf\Service::C()->get_cache('site', SITE_ID, 'watermark', 'gitueditor') ? '
                    '.dr_lang('图片水印').'
                    
                        
                            '.dr_lang('系统强制开启水印').'
                        
                    
                
' : '                     '.dr_lang('图片水印').'                                                                            '.dr_lang('开启').'                              '.dr_lang('关闭').'                         
                  上传的图片会加上水印图                     
                
';         return ['                     '.dr_lang('下载远程图片').'                                                                            '.dr_lang('自动').'                              '.dr_lang('手动').'                         
                  自动模式下每一次编辑内容时都会下载图片;手动模式可以在编辑器下放工具栏中控制“是否下载”                                                                        '.dr_lang('下载图片模式').'                                                                            '.dr_lang('异步').'(Beta)                              '.dr_lang('同步').'                                            同步模式是在编辑内容时一次性下载完图片,图片多的时候容易卡死;
异步模式是在编辑内容时不会马上下载图片,他会进入任务队列中进行延迟下载                                      '.$wm.             '                                      '.dr_lang('底部工具栏').'                                                                            '.dr_lang('开启').'                              '.dr_lang('关闭').'                                            编辑器底部工具栏,有截取字符选择、提取缩略图、下载远程图等控制按钮                                                                            '.dr_lang('编辑器类型').'                                                                            '.dr_lang('Umeditor').'                              '.dr_lang('Ueditor').'                                                                                                     '.dr_lang('固定工具栏').'                                                                            '.dr_lang('开启').'                              '.dr_lang('关闭').'                                            编辑器图标栏会固定在页面,不会随浏览器滚动                                                                            '.dr_lang('自动伸长高度').'                                                                            '.dr_lang('开启').'                              '.dr_lang('关闭').'                                                               编辑器会自动增加高度                                                                            '.dr_lang('分页标签').'                                                                            '.dr_lang('开启').'                              '.dr_lang('关闭').'                                            文章内容的分页功能                                                                                             '.dr_lang('后台编辑器模式').'                                                                            '.dr_lang('完整').'                              '.dr_lang('精简').'                              '.dr_lang('自定义').'                                                                                                     '.dr_lang('工具栏').'                                          '.$option['tool'].'                     '.dr_lang('必须严格按照Ueditor工具栏格式\'fullscreen\', \'source\', \'|\', \'undo\', \'redo\'').'                                                                            '.dr_lang('前台编辑器模式').'                                                                            '.dr_lang('完整').'                              '.dr_lang('精简').'                              '.dr_lang('自定义').'                                                                                                     '.dr_lang('工具栏').'                                          '.$option['tool2'].'                     '.dr_lang('必须严格按照Ueditor工具栏格式\'fullscreen\', \'source\', \'|\', \'undo\', \'redo\'').'                                                                            '.dr_lang('移动端编辑器模式').'                                                                            '.dr_lang('完整').'                              '.dr_lang('精简').'                              '.dr_lang('自定义').'                                                                                                     '.dr_lang('工具栏').'                                          '.$option['tool3'].'                     '.dr_lang('必须严格按照Ueditor工具栏格式\'fullscreen\', \'source\', \'|\', \'undo\', \'redo\'').'                                      '.$this->attachment($option).'                                      '.dr_lang('默认存储值').'                                                                                                '.dr_lang('也可以设置会员表字段,表示用当前登录会员信息来填充这个值').'                                                       '.$this->field_type($option['fieldtype'], $option['fieldlength']),             '                     '.dr_lang('控件宽度').'                                                                       '.dr_lang('[整数]表示固定宽度;[整数%]表示百分比').'                                                                            '.dr_lang('控件高度').'                                                                                                             '         ];     }     /**      * 字段入库值      */     public function insert_value($field) {         //$table = [];         $value = \Phpcmf\Service::L('Field')->post[$field['fieldname']];         // 第一张作为缩略图         $slt = isset($_POST['data']['thumb']) && isset($_POST['is_auto_thumb'])  && !$_POST['data']['thumb'] && $_POST['is_auto_thumb'];         // 是否下载图片         $yct = $field['setting']['option']['down_img'] || (isset($_POST['is_auto_down_img']) && $_POST['is_auto_down_img']);         // 下载远程图片         if (($yct || $slt) && preg_match_all("/(src)=([\"|']?)([^ \"'>]+\.(gif|jpg|jpeg|png|webp))\\2/i", $value, $imgs)) {             foreach ($imgs[3] as $img) {                 if (strpos($img, '/api/gitueditor/') !== false                     || strpos($img, '/api/umeditor/') !== false) {                     continue;                 }                 // 下载图片                 if ($yct && strpos($img, 'http') === 0) {                     if (dr_is_app('mfile') && \Phpcmf\Service::M('mfile', 'mfile')->check_upload(\Phpcmf\Service::C()->uid)) {                         //用户存储空间已满                     } else {                         // 正常下载                         // 判断域名白名单                         $arr = parse_url($img);                         $domain = $arr['host'];                         if ($domain) {                             $sites = WRITEPATH.'config/domain_site.php';                             if (isset($sites[$domain])) {                                 // 过滤站点域名                             } elseif (strpos(SYS_UPLOAD_URL, $domain) !== false) {                                 // 过滤附件白名单                             } else {                                 $zj = 0;                                 $remote = \Phpcmf\Service::C()->get_cache('attachment');                                 if ($remote) {                                     foreach ($remote as $t) {                                         if (strpos($t['url'], $domain) !== false) {                                             $zj = 1;                                             break;                                         }                                     }                                 }                                 if ($zj == 0) {                                     // 可以下载文件                                     /*                            if ($field['setting']['option']['down_img_type']) {                               // 异步模式                                if (!$table) {                                  $table = \Phpcmf\Service::M('field')->get_table_name(SITE_ID, $field);                               }                               $rt = \Phpcmf\Service::M('cron')->add_cron(SITE_ID, 'ueditor_down_img', [                                  'url' => $img,                                  'table' => $table,                                  'field' => $field['fieldname'],                                  'siteid' => SITE_ID,                                  'member' => \Phpcmf\Service::C()->member,                                  'attachment' => \Phpcmf\Service::M('Attachment')->get_attach_info(intval($field['setting']['option']['attachment'])),                                  'image_reduce' => $field['setting']['option']['image_reduce'],                               ]);                               if (!$rt['code']) {                                  log_message('error', '远程图片下载-任务注册失败:'.$rt['msg']);                               }                               $value = str_replace($img, ROOT_THEME_PATH.'assets/images/down_img.jpg?id='.$rt['code'], $value);                               $img = '';                            } else {                                     */                                     // 同步模式                                     // 下载远程文件                                     $rt = \Phpcmf\Service::L('upload')->down_file([                                         'url' => $img,                                         'timeout' => 5,                                         'watermark' => \Phpcmf\Service::C()->get_cache('site', SITE_ID, 'watermark', 'gitueditor') || $field['setting']['option']['watermark'] ? 1 : 0,                                         'attachment' => \Phpcmf\Service::M('Attachment')->get_attach_info(intval($field['setting']['option']['attachment'])),                                     ]);                                     if ($rt['code']) {                                         $att = \Phpcmf\Service::M('Attachment')->save_data($rt['data'], 'ueditor_down_img');                                         if ($att['code']) {                                             // 归档成功                                             $value = str_replace($img, $rt['data']['url'], $value);                                             $img = $att['code'];                                         }                                     }                                     //}                                 }                             }                         }                     }                 }                 // 缩略图                 if ($img && $slt && !\Phpcmf\Service::L('Field')->data[1]['thumb']) {                     \Phpcmf\Service::L('Field')->data[1]['thumb'] = $img;                 }             }         }         // 提取描述信息         if (isset($_POST['data']['description']) && isset($_POST['is_auto_description']) && !$_POST['data']['description']) {             \Phpcmf\Service::L('Field')->data[1]['description'] = trim(dr_strcut(dr_clearhtml($value), 200));         }         // 替换分页         $value = str_replace('[object Object]', '', $value);         // 入库操作         if (isset($_GET['is_verify_iframe']) && $_GET['is_verify_iframe']) {             // 来自批量审核内容             \Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = ($value);         } else {             \Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = htmlspecialchars($value);         }     }     /**      * 字段输出      *      * @param   array   $value  数据库值      * @return  string      */     public function output($value) {         return htmlspecialchars_decode($value);     }     /**      * 字段显示      *      * @return  string      */     public function show($field, $value = null) {         $html = '                                    '.htmlspecialchars_decode($value).'                                           ';         return $this->input_format($field['fieldname'], $field['name'], $html);     }     /**      * 字段表单输入      *      */     public function input($field, $value = '') {         // 字段禁止修改时就返回显示字符串         if ($this->_not_edit($field, $value)) {             return $this->show($field, $value);         }         // 字段存储名称         $name = $field['fieldname'];         // 字段显示名称         $text = ($field['setting']['validate']['required'] ? ' * ' : '').$field['name'];         if (isset($_GET['is_verify_iframe']) && $_GET['is_verify_iframe']) {             // 来自批量审核内容             $str = ''.htmlspecialchars($value).'';             return $this->input_format($field['fieldname'], $text, $str);         }         // 表单宽度设置         $is_mobile = \Phpcmf\Service::C()->_is_mobile();         $width = $is_mobile ? '100%' : ($field['setting']['option']['width'] ? $field['setting']['option']['width'] : '100%');         // 表单高度设置         $height = $field['setting']['option']['height'] ? $field['setting']['option']['height'] : '300';         // 字段提示信息         $tips = $field['setting']['validate']['tips'] ? ''.$field['setting']['validate']['tips'].'' : '';         // 字段默认值         $value = htmlspecialchars_decode(strlen($value) ? $value : $this->get_default_value($field['setting']['option']['value']));         $uri = \Phpcmf\Service::L('router')->uri();         APP_DIR != 'member' && $uri = str_replace('member/', '', $uri);         // 输出         $str = '';         // 防止重复加载JS         if (!defined('PHPCMF_FIELD_UEDITOR')) {             $str.= '                                       ';             define('PHPCMF_FIELD_UEDITOR', 1);         }         $tool = IS_ADMIN ? "'fullscreen', 'source', '|', " : ''; // 后台引用时显示html工具栏         // 编辑器模式         if ($is_mobile) {             $mode = $field['setting']['option']['mode3'] ? $field['setting']['option']['mode3'] : $field['setting']['option']['mode'];             $field['setting']['option']['tool'] = $field['setting']['option']['tool3'] ? $field['setting']['option']['tool3'] : $field['setting']['option']['tool'];         } elseif (IS_ADMIN) {             $mode = $field['setting']['option']['mode'];         } else {             $mode = $field['setting']['option']['mode2'] ? $field['setting']['option']['mode2'] : $field['setting']['option']['mode'];             $field['setting']['option']['tool'] = $field['setting']['option']['tool2'] ? $field['setting']['option']['tool2'] : $field['setting']['option']['tool'];         }         // 编辑器工具         $pagebreak = (int)$field['setting']['option']['page'] ? ', \'pagebreak\'' : '';         switch ($mode) {             case 3: // 自定义                 $tool.= trim($field['setting']['option']['tool'], ',').$pagebreak;                 break;             case 2: // 精简                 $tool.= "'undo', 'redo', '|',                         'bold', 'italic', 'underline', 'strikethrough','|', 'pasteplain', 'forecolor', 'fontfamily', 'fontsize','|', 'link', 'simpleupload'$pagebreak";                 break;             case 1: // 默认                 $tool.= "'undo', 'redo', '|',             'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',             'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',             'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',             'directionalityltr', 'directionalityrtl', 'indent', '|',             'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',             'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',             'simpleupload', 'insertimage', 'emotion', 'scrawl', 'insertvideo', 'attachment', 'map', 'insertframe', 'insertcode', 'template', 'background', '|',             'horizontal', 'date', 'time', 'spechars', '|',             'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',             'print', 'preview', 'searchreplace', 'drafts'$pagebreak";                 break;         }         $str.= "$value";         $js = \Phpcmf\Service::L('js_packer');         $str.= $js->pack("                      var editorOption = {                 UEDITOR_HOME_URL: \"/api/gitueditor/\",                 serverUrl:\"/index.php?s=api&c=file&token=".dr_get_csrf_token()."&m=gitueditor&image_reduce=".intval($field['setting']['option']['image_reduce'])."&attachment=".intval($field['setting']['option']['attachment'])."&is_wm=".$field['setting']['option']['watermark']."&rid=".($uri.'/id:'.(int)$_GET['id'])."&\",                 lang: \"".SITE_LANGUAGE."\",                 langPath: \"".ROOT_URL."api/language/\",                 toolbars: [                     [ $tool ]                 ],                 initialContent:\"\",                 initialFrameWidth: \"".$width."\",                 initialFrameHeight: \"{$height}\",                 initialStyle:\"body{font-size:14px}\",                 wordCount:false,                 maximumWords:99999999999,                 elementPathEnabled:false,                 autoFloatEnabled:".($field['setting']['option']['autofloat'] ? 'true' : 'false').",                 autoHeightEnabled:".($field['setting']['option']['autoheight'] ? 'true' : 'false').",                 charset:\"utf-8\",             };             var editor = new baidu.editor.ui.Editor(editorOption);             editor.render(\"dr_$name\");                  ", 0);         if ($field['setting']['option']['show_bottom_boot']) {             $str.= '';             $str.= '                         提取第一个图片为缩略图                   ';             $str.= '                                      提取前200字为描述信息                   ';             if (!$field['setting']['option']['down_img']) {                 $str.= '                                      下载远程图片                   ';             }             $str.= '';         }         return $this->input_format($name, $text, $str.$tips);     } }


报错:

image


请问流程对吗?我就想复制一份ueditor然后自己自定义,是否还需要修改其他地方?请求指教下下

回帖
  • 小黄人 18html.com
    #1楼    小黄人 18html.com
    2020-07-11 15:26:36
    Chrome 0
    编辑器可难配置了!
  • sw586
    #2楼    sw586
    2020-07-11 15:30:07
    Chrome 0
    小黄人 18html.com 找到原因了umeditor没对应上改为gitumeditor对应自己的就好了,已经实现上传图片到图床了哈哈哈哈 阿里云、腾讯云等等滚蛋!
  • 小黄人 18html.com
    #3楼    小黄人 18html.com
    2020-07-11 15:31:16
    Chrome 0
    sw586图床吗?哪个图床?分享下
  • sw586
    #4楼    sw586
    2020-07-11 15:37:25
    Chrome 0
    小黄人 18html.com 有个小问题还没搞定,私信加个Q一起研究怎么样?Q发你私信了
  • 村长
    #5楼    村长
    2020-07-11 16:10:27
    Chrome 0
    记录一下
  • #6楼    太阳成游戏网站框架创始人
    2020-07-11 16:44:01
    Chrome 0

    image
    后端地址要改成你的地址,否则会报后端故障
  • sw586
    #7楼    sw586
    2020-07-11 17:54:04
    Chrome 0
    回复太阳成游戏网站框架创始人 谢谢大佬。请问缩略图的上传方式是\dayrui\Core\Controllers\Api\File.php
    /**
    * 文件上传
    */
    public function upload() {

    // 验证上传权限
    $this->_check_upload_auth();
    $p = $this->_get_upload_params();
    $rt = \Phpcmf\Service::L('upload')->upload_file([
    'path' => '',
    'form_name' => 'file_data',
    'file_exts' => @explode(',', $p['exts']),
    'file_size' => (int)$p['size'] * 1024 * 1024,
    'attachment' => \Phpcmf\Service::M('Attachment')->get_attach_info((int)$p['attachment'], (int)$p['image_reduce']),
    ]);
    if (!$rt['code']) {
    exit(dr_array2string($rt));
    }

    // 附件归档
    $data = \Phpcmf\Service::M('Attachment')->save_data($rt['data']);
    if (!$data['code']) {
    exit(dr_array2string($data));
    }

    // 上传成功
    if (IS_API_HTTP) {
    $data['data'] = [
    'id' => $data['code'],
    'url' => $rt['data']['url'],
    ];
    exit(dr_array2string($data));
    } else {
    exit(dr_array2string(['code' => 1, 'msg' => dr_lang('上传成功'), 'id' => $data['code'], 'info' => $rt['data']]));
    }

    }
    是这个吗 ,我想增加应该字段自定义类型的缩略图
  • #8楼    太阳成游戏网站框架创始人
    2020-07-11 18:11:01
    Chrome 0
    这个需要你自己去研究编写后端程序代码了,一般编辑器都会提供默认的demo后端程序代码
    满意答案
  • sw586
    #9楼    sw586
    2020-07-12 14:17:56
    Chrome 0
    太阳成游戏网站框架创始人:谢谢谢谢谢谢