// 是否下载图片 $yct = 1; // 下载远程图片 if ($yct || $base64) { $temp = preg_replace('/
/siU', '', $value);
$temp = preg_replace('//siU', '', $temp);
if (preg_match_all("/(src)=([\"|']?)([^ \"'>]+)\\2/i", $temp, $imgs)) {
foreach ($imgs[3] 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'])) {
continue;
}
$content = base64_decode(str_replace($result[1], '', $img));
if (strlen($content) > 30000000) {
continue;
}
$rt = \Phpcmf\Service::L('upload')->base64_image([
'ext' => $ext,
$torname => $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']) {
continue;
}
$att = \Phpcmf\Service::M('Attachment')->save_data($rt['data'], 'ueditor:'.$rid);
if ($att['code']) {
// 归档成功
$value = str_replace($img, $rt['data']['url'], $value);
$img = $att['code'];
// 标记附件
\Phpcmf\Service::M('Attachment')->save_ueditor_aid($rid, $att['code']);
}
} else {
$ext = _get_image_ext($img);
if (!$ext) {
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 = \Phpcmf\Service::R(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) {
// 可以下载文件
// 下载远程文件
$rt = \Phpcmf\Service::L('upload')->down_file([
'url' => $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,
]);
if ($rt['code']) {
$att = \Phpcmf\Service::M('Attachment')->save_data($rt['data'], 'ueditor:'.$rid);
if ($att['code']) {
// 归档成功
$value = str_replace($img, $rt['data']['url'], $value);
$img = $att['code'];
// 标记附件
\Phpcmf\Service::M('Attachment')->save_ueditor_aid($rid, $att['code']);
}
}
}
}
}
}
}
}
}
}
}
// 最后得到的文档内容
$save[0][$torname] = $value;