编辑器远程抓取图片优化
parent
7813eafd3d
commit
240a201bf1
|
|
@ -307,6 +307,7 @@ class UeditorService
|
||||||
$ret = ResourcesService::AttachmentAdd($data);
|
$ret = ResourcesService::AttachmentAdd($data);
|
||||||
if($ret['code'] == 0)
|
if($ret['code'] == 0)
|
||||||
{
|
{
|
||||||
|
$ret['data']['source'] = htmlspecialchars($imgUrl);
|
||||||
array_push($list, $ret['data']);
|
array_push($list, $ret['data']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -375,29 +375,12 @@ class Uploader
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取请求头并检测死链
|
//打开输出缓冲区并获取远程图片
|
||||||
$heads = get_headers($imgUrl, 1);
|
$img = RequestGet($imgUrl);
|
||||||
if (!(stristr($heads[0], "200") && stristr($heads[0], "OK"))) {
|
if(empty($img)) {
|
||||||
$this->stateInfo = $this->getStateInfo("ERROR_DEAD_LINK");
|
$this->stateInfo = $this->getStateInfo("ERROR_DEAD_LINK");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//格式验证(扩展名验证和Content-Type验证)
|
|
||||||
$fileType = strtolower(strrchr($imgUrl, '.'));
|
|
||||||
if (!in_array($fileType, $this->config['allowFiles']) || !isset($heads['Content-Type']) || !stristr($heads['Content-Type'], "image")) {
|
|
||||||
$this->stateInfo = $this->getStateInfo("ERROR_HTTP_CONTENTTYPE");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//打开输出缓冲区并获取远程图片
|
|
||||||
ob_start();
|
|
||||||
$context = stream_context_create(
|
|
||||||
array('http' => array(
|
|
||||||
'follow_location' => false // don't follow redirects
|
|
||||||
))
|
|
||||||
);
|
|
||||||
readfile($imgUrl, false, $context);
|
|
||||||
$img = ob_get_contents();
|
|
||||||
ob_end_clean();
|
|
||||||
preg_match("/[\/]([^\/]*)[\.]?[^\.\/]*$/", $imgUrl, $m);
|
preg_match("/[\/]([^\/]*)[\.]?[^\.\/]*$/", $imgUrl, $m);
|
||||||
|
|
||||||
$this->oriName = $m ? $m[1]:"";
|
$this->oriName = $m ? $m[1]:"";
|
||||||
|
|
|
||||||
|
|
@ -23253,21 +23253,19 @@ UE.plugins['catchremoteimage'] = function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 获取源路径和新路径 */
|
/* 获取源路径和新路径 */
|
||||||
var i, newSrc, list = info.data || null;
|
var i, j, ci, cj, oldSrc, newSrc, list = info.data;
|
||||||
if(list == null || list.length <= 0 || list.length != imgs.length)
|
for (i = 0; ci = imgs[i++];) {
|
||||||
{
|
oldSrc = ci.getAttribute('_src') || ci.src || "";
|
||||||
return;
|
for (j = 0; cj = list[j++];) {
|
||||||
}
|
if (oldSrc == cj.source && cj.state == 'SUCCESS') {
|
||||||
|
//抓取失败时不做替换处理
|
||||||
// 循环处理图片替换
|
newSrc = catcherUrlPrefix + cj.url;
|
||||||
for (i = 0; i<imgs.length;i++) {
|
domUtils.setAttributes(ci, {
|
||||||
if((list[i] || null) != null && (list[i]['url'] || null) != null)
|
"src": newSrc,
|
||||||
{
|
"_src": newSrc
|
||||||
newSrc = catcherUrlPrefix + list[i]['url'];
|
});
|
||||||
domUtils.setAttributes(imgs[i], {
|
break;
|
||||||
"src": newSrc,
|
}
|
||||||
"_src": newSrc
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
me.fireEvent('catchremotesuccess')
|
me.fireEvent('catchremotesuccess')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue