1. 程式人生 > >dede後臺添加優酷等視頻iframe鏈接時被替換成了圖片

dede後臺添加優酷等視頻iframe鏈接時被替換成了圖片

multi ESS lin each functions 成了 ebo 修改 ast

添加文章時 添加優酷視頻 :<iframe height=498 width=510 src=‘技術分享圖片http://player.youku.com/embed/XNDAzNTAzODE4OA==‘ frameborder=0 ‘allowfullscreen‘></iframe>

提交後被替換成

<iframe frameborder="0" height="498" src="/uploads/allimg/190128/1U9241554-1.jpg" width="510"></iframe>

經測試,發現問題出在保存之前對body內容的處理上

//遠程圖片本地化

if
($remote==1) { $body = GetCurContent($body); //dede/inc/inc_archives_functions.php 644行 }

把函數GetCurContent做如下修改可暫時解決(未側式是否會引起其他問題,應該把所有的圖片格式都枚舉出來)

/**
 * 獲得文章body裏的外部資源
 *
 * @access    public
 * @param     string  $body  文檔內容
 * @return    string
 */
function GetCurContent($body)
{
    global
$cfg_multi_site,$cfg_basehost,$cfg_basedir,$cfg_image_dir,$arcID,$cuserLogin,$dsql; $cfg_uploaddir = $cfg_image_dir; $htd = new DedeHttpDown(); $basehost = "http://".$_SERVER["HTTP_HOST"]; $img_array = array(); preg_match_all("/src=[\"|‘|\s]([^\"|^\‘|^\s]*?)/isU",$body,$img_array); $img_array
= array_unique($img_array[1]); $imgUrl = $cfg_uploaddir./.MyDate("ymd", time()); $imgPath = $cfg_basedir.$imgUrl; if(!is_dir($imgPath./)) { MkdirAll($imgPath, $GLOBALS[cfg_dir_purview]); CloseFtp(); } $milliSecond = MyDate(His,time()); foreach($img_array as $key=>$value) { if(preg_match("#".$basehost."#i", $value)) { continue; } if($cfg_basehost != $basehost && preg_match("#".$cfg_basehost."#i", $value)) { continue; } if(!preg_match("#^(http|https):\/\/#i", $value)) { continue; } $htd->OpenUrl($value); $itype = $htd->GetHead("content-type"); $itype = substr($value, -4, 4); if(!preg_match("#\.(jpg|gif|png)#i", $itype)) { if($itype==image/gif) { $itype = ".gif"; } else if($itype==image/png) { $itype = ".png"; }else if($itype==‘image/jpg‘){ //不知道jpeg格式的是否一樣,如果不一樣還得增加jpeg判斷 $itype = ‘.jpg‘; } else { continue; //原函數未處理沒有後綴名的情況,應該在這裏判斷視頻或者。。。。。。,這樣寫將不再解析除了 gif png jpg 以外的圖片格式,如 bmp } } $milliSecondN = dd2char($milliSecond.mt_rand(1000, 8000)); $value = trim($value); $rndFileName = $imgPath./.$milliSecondN.-.$key.$itype; $fileurl = $imgUrl./.$milliSecondN.-.$key.$itype; $rs = $htd->SaveToBin($rndFileName); if($rs) { $info = ‘‘; $imginfos = GetImageSize($rndFileName, $info); $fsize = filesize($rndFileName); //保存圖片附件信息 $inquery = "INSERT INTO `#@__uploads`(arcid,title,url,mediatype,width,height,playtime,filesize,uptime,mid) VALUES ({$arcID},$rndFileName,$fileurl,1,{$imginfos[0]},$imginfos[1],0,$fsize,".time().",".$cuserLogin->getUserID()."); "; $dsql->ExecuteNoneQuery($inquery); $fid = $dsql->GetLastID(); AddMyAddon($fid, $fileurl); if($cfg_multi_site == Y) { $fileurl = $cfg_basehost.$fileurl; } $body = str_replace($value, $fileurl, $body); @WaterImg($rndFileName, down); } } $htd->Close(); return $body; }

dede後臺添加優酷等視頻iframe鏈接時被替換成了圖片