fieldtype = ['MEDIUMTEXT' => '']; $this->defaulttype = 'MEDIUMTEXT'; $this->rid = md5(FC_NOW_URL.\Phpcmf\Service::L('input')->get_user_agent().\Phpcmf\Service::L('input')->ip_address().\Phpcmf\Service::C()->uid); } /** * 字段相关属性参数 * * @param array $value 值 * @return string */ public function option($option) { if (!isset($option['attach_size']) || !$option['attach_size']) { $option['attach_size'] = 200; } if (!isset($option['toolbar']) || !$option['toolbar']) { $option['toolbar'] = "['style', ['style']], ['font', ['bold', 'italic', 'underline', 'clear']], ['fontname', ['fontsize']], ['color', ['color']], ['para', ['ul', 'ol', 'paragraph']], ['table', ['table']], ['link', ['link']], ['attach', ['attach']], ['picture', ['qsimage', 'picture', 'help']], ['video', ['video', 'llvideo']], ['view', ['codeview'] ]"; } if (!isset($option['toolbar_home']) || !$option['toolbar_home']) { $option['toolbar_home'] = "['style', ['style']], ['font', ['bold', 'italic', 'underline', 'clear']], ['fontname', ['fontsize']], ['color', ['color']], ['para', ['ul', 'ol', 'paragraph']], ['table', ['table']], ['link', ['link']], ['attach', ['attach']], ['picture', ['qsimage', 'picture', 'help']], ['video', ['video', 'llvideo']], ['view', ['codeview'] ]"; } if (!isset($option['attach_ext']) || !$option['attach_ext']) { $option['attach_ext'] = 'zip,rar,txt,doc'; } if (!isset($option['video_ext']) || !$option['video_ext']) { $option['video_ext'] = 'mp4'; } if (!isset($option['video_size']) || !$option['video_size']) { $option['video_size'] = 500; } if (!isset($option['image_ext']) || !$option['image_ext']) { $option['image_ext'] = 'jpg,gif,png,webp,jpeg'; } if (!isset($option['imagecut_ext']) || !$option['imagecut_ext']) { $option['imagecut_ext'] = ''; } if (!isset($option['image_size']) || !$option['image_size']) { $option['image_size'] = 10; } $wm = \Phpcmf\Service::C()->get_cache('site', SITE_ID, 'watermark', 'ueditor') ? '
'.dr_lang('系统强制开启水印').'
' : '
   
'.dr_lang('上传的图片会加上水印图').'
'; return [$this->_search_field().'
   
'.dr_lang('编辑器底部工具栏,有截取字符选择、提取缩略图、下载远程图等控制按钮').'
'.dr_lang('宽大于').'
'.dr_lang('高大于').'

'.dr_lang('将模块内容的标题作为图片title字符').'
'.dr_lang('将模块内容的标题作为图片alt字符').'
'.$wm. '
'.dr_lang('填写用于图片的扩展名格式,只能填写单个扩展名,用于截图粘贴时储存的扩展名').'
'.dr_lang('填写用于图片上传的扩展名格式,格式:jpg,gif,png,webp,jpeg').'
'.dr_lang('填写用于图片上传的最大允许上传的大小,单位MB').'

'.dr_lang('填写用于附件上传的最大允许上传的大小,单位MB').'
'.dr_lang('填写用于附件上传的扩展名,格式:rar,zip').'

'.dr_lang('填写用于视频上传的扩展名格式,格式:mp4,mov').'
'.dr_lang('填写用于视频上传的最大允许上传的大小,单位MB').'


'.$this->attachment($option, 0).'

'.dr_lang('用于字段为空时显示该填充值,并不会去主动变更数据库中的实际值;可以设置会员表字段,表示用当前登录会员信息来填充这个值').'

'.$this->field_type($option['fieldtype'], $option['fieldlength']), '
'.dr_lang('[整数]表示固定宽度;[整数%]表示百分比').'
' ]; } /** * 验证字段属性 */ public function edit_config($post) { if (isset($post['setting']['option']['imagecut_ext']) && $post['setting']['option']['imagecut_ext']) { if (strpos($post['setting']['option']['imagecut_ext'], ',') !== false) { return dr_return_data(0, dr_lang('图片粘贴扩展名只能填写单个扩展名')); } } return dr_return_data(1, 'ok'); } /** * 字段入库值 */ public function insert_value($field) { $value = str_replace('style=""', '', (string)$_POST['data'][$field['fieldname']]); $value = preg_replace("/cmsattachid=\"([0-9]+)\"/U", '', $value); // 第一张作为缩略图 $slt = isset($_POST['data']['thumb']) && isset($_POST['is_auto_thumb_'.$field['fieldname']]) && !$_POST['data']['thumb'] && $_POST['is_auto_thumb_'.$field['fieldname']]; $base64 = strpos($value, ';base64,'); // 下载远程图片 if ($slt || $base64) { $temp = preg_replace('//siU', '', $value); $temp = preg_replace('//siU', '', $temp); if (preg_match_all("/(src)=([\"|']?)([^ \"'>]+)\\2/i", $temp, $imgs)) { $reps = array_unique($imgs[3]); usort($reps, function ($a, $b) { return dr_strlen($b) - dr_strlen($a); }); foreach ($reps as $img) { if ($base64 && preg_match('/^(data:\s*image\/(\w+);base64,)/i', $img, $result)) { // 处理图片 $ext = strtolower($result[2]); if (!in_array($ext, ['png', 'jpg', 'jpeg', 'gif', 'webp'])) { CI_DEBUG && log_message('debug', 'Editor编辑器图片粘贴失败:扩展名不符合'.$ext); continue; } $content = base64_decode(str_replace($result[1], '', $img)); if (strlen($content) > 30000000) { CI_DEBUG && log_message('debug', 'Editor编辑器图片粘贴失败:图片内容过大,超过30MB'); continue; } $rt = \Phpcmf\Service::L('upload')->base64_image([ 'ext' => isset($field['setting']['option']['imagecut_ext']) && $field['setting']['option']['imagecut_ext'] ? $field['setting']['option']['imagecut_ext'] : $ext, 'content' => $content, 'watermark' => \Phpcmf\Service::C()->get_cache('site', SITE_ID, 'watermark', 'ueditor') || $field['setting']['option']['watermark'] ? 1 : 0, 'attachment' => \Phpcmf\Service::M('Attachment')->get_attach_info(intval($field['setting']['option']['attachment']), $field['setting']['option']['image_reduce']), ]); if (!$rt['code']) { CI_DEBUG && log_message('debug', 'Editor编辑器图片粘贴失败:'.$rt['msg']); continue; } $att = \Phpcmf\Service::M('Attachment')->save_data($rt['data'], 'ueditor:'.$this->rid); if ($att['code']) { // 归档成功 $value = str_replace($img, $rt['data']['url'], $value); $img = $att['code']; // 标记附件 \Phpcmf\Service::M('Attachment')->save_ueditor_aid($this->rid, $att['code']); } else { CI_DEBUG && log_message('debug', 'Editor编辑器图片归档失败:'.$rt['msg']); } } // 缩略图 if ($img && $slt) { $_field = \Phpcmf\Service::L('form')->fields; if (isset($_field['thumb']) && $_field['thumb']['fieldtype'] == 'File' && !\Phpcmf\Service::L('Field')->data[$_field['thumb']['ismain']]['thumb']) { if (!is_numeric($img)) { // 下载缩略图 $width = isset($field['setting']['option']['thumb']['width']) ? $field['setting']['option']['thumb']['width'] : 0; $height = isset($field['setting']['option']['thumb']['height']) ? $field['setting']['option']['thumb']['height'] : 0; // 获取图片信息 if ($width || $height) { $imageInfo = getimagesize($img); if ($imageInfo !== false) { // 宽度 if ($width && $imageInfo[0] < $width) { $img = ''; continue; } if ($height && $imageInfo[1] < $height) { $img = ''; continue; } } else { $img = ''; continue; } } // 判断域名白名单 $arr = parse_url($img); $domain = $arr['host']; if ($domain) { $sites = \Phpcmf\Service::R(WRITEPATH.'config/domain_site.php'); if (isset($sites[$domain])) { // 过滤站点域名 } elseif (strpos(SYS_UPLOAD_URL, $domain) !== false) { // 过滤附件白名单 } else { $file = dr_catcher_data($img, 8); if (!$file) { CI_DEBUG && log_message('debug', '服务器无法下载图片:'.$img); } else { // 尝试找一找附件库 $att = \Phpcmf\Service::M()->table('attachment')->like('related', 'ueditor')->where('filemd5', md5($file))->getRow(); if ($att) { $img = $att['id']; } else { // 下载归档 $rt = \Phpcmf\Service::L('upload')->down_file([ 'url' => html_entity_decode((string)$img), 'timeout' => 5, 'watermark' => \Phpcmf\Service::C()->get_cache('site', SITE_ID, 'watermark', 'ueditor') || $field['setting']['option']['watermark'] ? 1 : 0, 'attachment' => \Phpcmf\Service::M('Attachment')->get_attach_info(intval($field['setting']['option']['attachment']), $field['setting']['option']['image_reduce']), 'file_ext' => $ext, 'file_content' => $file, ]); if ($rt['code']) { $att = \Phpcmf\Service::M('Attachment')->save_data($rt['data'], 'ueditor:'.$this->rid); if ($att['code']) { // 归档成功 $value = str_replace($img, $rt['data']['url'], $value); $img = $att['code']; // 标记附件 \Phpcmf\Service::M('Attachment')->save_ueditor_aid($this->rid, $att['code']); } } else { CI_DEBUG && log_message('debug', 'Editor编辑器图片下载失败:'.$rt['msg']); } } } } } } \Phpcmf\Service::L('Field')->data[$_field['thumb']['ismain']]['thumb'] = $_POST['data']['thumb'] = $img; } } } } } // 去除站外链接 if (isset($_POST['is_remove_a_'.$field['fieldname']]) && $_POST['is_remove_a_'.$field['fieldname']] && preg_match_all("/(.*)<\/a>/Ui", $value, $arrs)) { $sites = \Phpcmf\Service::R(WRITEPATH.'config/domain_site.php'); foreach ($arrs[2] as $i => $a) { if (strpos($a, ' ') !== false) { list($a) = explode(' ', $a); } $a = trim($a, '"'); $a = trim($a, '\''); $arr = parse_url($a); if ($arr && $arr['host'] && !isset($sites[$arr['host']])) { // 去除a标签 $value = str_replace($arrs[0][$i], $arrs[3][$i], $value); } } } // 提取描述信息 if (isset($_POST['data']['description']) && isset($_POST['is_auto_description_'.$field['fieldname']]) && $_POST['is_auto_description_'.$field['fieldname']]) { \Phpcmf\Service::L('Field')->data[1]['description'] = $_POST['data']['description'] = dr_get_description($value); } // 替换分页 $value = str_replace('_ueditor_page_break_tag_', '
', $value); $value = str_replace(' style=""', '', $value); if (isset($field['setting']['validate']['xss']) && $field['setting']['validate']['xss']) { // 开启xss $value = \Phpcmf\Service::L('Security')->xss_clean($value); } // 入库操作 \Phpcmf\Service::L('Field')->data[$field['ismain']][$field['fieldname']] = htmlspecialchars($value); } /** * 获取附件id */ public function get_attach_id($value) { return \Phpcmf\Service::M('Attachment')->get_ueditor_aid($this->rid); } /** * 附件处理 */ public function attach($data, $_data) { $add = \Phpcmf\Service::M('Attachment')->get_ueditor_aid($this->rid, true); if (isset($_POST['data'][$this->field['fieldname']]) && $_POST['data'][$this->field['fieldname']] && preg_match_all("/<([a-z]+) cmsattachid=\"([0-9]+)\"/Ui", $_POST['data'][$this->field['fieldname']], $att)) { if ($add && is_array($add)) { $add = array_merge($add, $att[2]); } else { $add = $att[2]; } } return [$add, NULL]; } /** * 字段输出 * * @param array $value 数据库值 * @return string */ public function output($value) { return dr_ueditor_html($value, isset(\Phpcmf\Service::L('Field')->data['title']) ? \Phpcmf\Service::L('Field')->data['title'] : ''); } /** * 字段显示 * * @return string */ public function show($field, $value = null) { $html = '
'.htmlspecialchars_decode((string)$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'] ? ' * ' : '').dr_lang($field['name']); // 表单宽度设置 $width = \Phpcmf\Service::IS_MOBILE_USER() ? '100%' : ($field['setting']['option']['width'] ? $field['setting']['option']['width'] : '100%'); // 表单高度设置 $height = $field['setting']['option']['height'] ? $field['setting']['option']['height'] : ''; // 字段提示信息 $tips = $field['setting']['validate']['tips'] ? ''.$field['setting']['validate']['tips'].'' : ''; // 字段默认值 $value = dr_strlen($value) ? $value : $this->get_default_value($field['setting']['option']['value']); // 输出 $str = ''; // 防止重复加载JS if (!$this->is_load_js($field['fieldtype'])) { $str.= ' '; $this->set_load_js($field['fieldtype'], 1); } if (!isset($field['setting']['option']['attach_size']) || !$field['setting']['option']['attach_size']) { $option['attach_size'] = 200; } $p = dr_authcode([ 'size' => (!isset($field['setting']['option']['video_size']) || !$field['setting']['option']['video_size']) ? 500 : $field['setting']['option']['video_size'], 'exts' => (!isset($field['setting']['option']['video_ext']) || !$field['setting']['option']['video_ext']) ? 'mp4' : $field['setting']['option']['video_ext'], 'count' => 100, 'attachment' => $field['setting']['option']['attachment'], ], 'ENCODE'); $p2 = dr_authcode([ 'size' => (!isset($field['setting']['option']['image_size']) || !$field['setting']['option']['image_size']) ? 10 : $field['setting']['option']['image_size'], 'exts' => (!isset($field['setting']['option']['image_ext']) || !$field['setting']['option']['image_ext']) ? 'jpg,gif,png,webp,jpeg' : $field['setting']['option']['image_ext'], 'count' => 100, 'attachment' => $field['setting']['option']['attachment'], 'image_reduce' => $field['setting']['option']['image_reduce'], ], 'ENCODE'); $p3 = dr_authcode([ 'size' => (!isset($field['setting']['option']['attach_size']) || !$field['setting']['option']['attach_size']) ? 200 : $field['setting']['option']['attach_size'], 'exts' => (!isset($field['setting']['option']['attach_ext']) || !$field['setting']['option']['attach_ext']) ? 'zip,rar,txt,doc' : $field['setting']['option']['attach_ext'], 'count' => 100, 'attachment' => $field['setting']['option']['attachment'], ], 'ENCODE'); $str.= ""; if ($field['setting']['option']['imgtitle'] > 0) { $title = UEDITOR_IMG_TITLE; } elseif ($field['setting']['option']['imgtitle'] < 0) { $title = 'none'; } else { $title = ''; } if ($field['setting']['option']['imgalt'] > 0) { $alt = UEDITOR_IMG_TITLE; } elseif ($field['setting']['option']['imgalt'] < 0) { $alt = 'none'; } else { $alt = ''; } $tool = ''; if (IS_ADMIN) { if ($field['setting']['option']['toolbar']) { $tool = $this->_toolbar($field['setting']['option']['toolbar']); } } else { if ($field['setting']['option']['toolbar_home']) { $tool = $this->_toolbar($field['setting']['option']['toolbar_home']); } } $wm = \Phpcmf\Service::C()->get_cache('site', SITE_ID, 'watermark', 'ueditor') || $field['setting']['option']['watermark'] ? 1 : 0; $str.= \Phpcmf\Service::L('js_packer')->pack(" ", 0); if (isset($field['setting']['option']['show_bottom_boot']) && $field['setting']['option']['show_bottom_boot']) { $str.= '
'; } return $this->input_format($name, $text, $str.$tips); } private function _toolbar($json) { if (strpos($json, '"') !== false) { return ''; } return ',toolbar: ['.$json.']'; } }