dede后台添加优酷等视频iframe链接时被替换成了图片

 添加文章时 添加优酷视频 :<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;
}

猜你喜欢

转载自www.cnblogs.com/djiz/p/10331485.html