织梦后台文章添加iframe前
保存文章后,就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内容的处理上
打开 dede\inc\inc_archives_functions.php 找到
preg_match_all("/src=[\"|'|\s]([^\"|^\'|^\s]*?)/isU",$body,$img_array);
改成
preg_match_all("/<img.*?src=[\"|'|\s]([^\"|^\'|^\s]*?)/isU",$body,$img_array);
保存,完成,重新插入iframe代码试试。
另外的方法:
</>code
- //远程图片本地化
- if($remote==1)
- {
- $body = GetCurContent($body); //dede/inc/inc_archives_functions.php 644行
- }
把函数GetCurContent做如下修改可暂时解决(未侧式是否会引起其他问题,应该把所有的图片格式都枚举出来)
</>code
- /**
- * 获得文章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 `axcms_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;
- }
如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛