您现在的位置: 365建站网 > 365文章 > 织梦dede后台文章内容保存iframe变图片的解决方法

织梦dede后台文章内容保存iframe变图片的解决方法

文章来源:365jz.com     点击数:801    更新时间:2019-05-20 00:51   参与评论

织梦后台文章添加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

  1. //远程图片本地化
  2. if($remote==1)
  3. {
  4.     $body = GetCurContent($body);   //dede/inc/inc_archives_functions.php 644行  
  5. }

 


把函数GetCurContent做如下修改可暂时解决(未侧式是否会引起其他问题,应该把所有的图片格式都枚举出来)


</>code

  1. /**
  2.  * 获得文章body里的外部资源
  3.  *
  4.  * @access    public
  5.  * @param     string  $body  文档内容
  6.  * @return    string
  7.  */
  8. function GetCurContent($body)
  9. {
  10.     global $cfg_multi_site,$cfg_basehost,$cfg_basedir,$cfg_image_dir,$arcID,$cuserLogin,$dsql;
  11.     $cfg_uploaddir = $cfg_image_dir;
  12.     $htd = new DedeHttpDown();
  13.     $basehost = "http://".$_SERVER["HTTP_HOST"];
  14.     $img_array = array();
  15.     preg_match_all("/src=[\"|'|\s]([^\"|^\'|^\s]*?)/isU",$body,$img_array);
  16.     
  17.     $img_array = array_unique($img_array[1]);
  18.     $imgUrl = $cfg_uploaddir.'/'.MyDate("ymd", time());
  19.     $imgPath = $cfg_basedir.$imgUrl;
  20.     if(!is_dir($imgPath.'/'))
  21.     {
  22.         MkdirAll($imgPath, $GLOBALS['cfg_dir_purview']);
  23.         CloseFtp();
  24.     }
  25.     $milliSecond = MyDate('His',time());
  26.     foreach($img_array as $key=>$value)
  27.     {
  28.         if(preg_match("#".$basehost."#i", $value))
  29.         {
  30.             continue;
  31.         }
  32.         if($cfg_basehost != $basehost && preg_match("#".$cfg_basehost."#i", $value))
  33.         {
  34.             continue;
  35.         }
  36.         if(!preg_match("#^(http|https):\/\/#i", $value))
  37.         {
  38.             continue;
  39.         }
  40.         $htd->OpenUrl($value);
  41.         $itype = $htd->GetHead("content-type");
  42.         $itype = substr($value, -4, 4);
  43.         if(!preg_match("#\.(jpg|gif|png)#i", $itype))
  44.         {
  45.             if($itype=='image/gif')
  46.             {
  47.                 $itype = ".gif";
  48.             }
  49.             else if($itype=='image/png')
  50.             {
  51.                 $itype = ".png";
  52.             }else if($itype=='image/jpg'){  //不知道jpeg格式的是否一样,如果不一样还得增加jpeg判断
  53.                 $itype = '.jpg';
  54.             }
  55.             else
  56.             {
  57.                 continue;  //原函数未处理没有后缀名的情况,应该在这里判断视频或者。。。。。。,这样写将不再解析除了 gif png jpg 以外的图片格式,如 bmp
  58.             }
  59.         }
  60.         $milliSecondN = dd2char($milliSecond.mt_rand(1000, 8000));
  61.         $value = trim($value);
  62.         $rndFileName = $imgPath.'/'.$milliSecondN.'-'.$key.$itype;
  63.         $fileurl = $imgUrl.'/'.$milliSecondN.'-'.$key.$itype;
  64.         $rs = $htd->SaveToBin($rndFileName);
  65.         if($rs)
  66.         {
  67.             $info = '';
  68.             $imginfos = GetImageSize($rndFileName, $info);
  69.             $fsize = filesize($rndFileName);
  70.             //保存图片附件信息
  71.             $inquery = "INSERT INTO `axcms_uploads`(arcid,title,url,mediatype,width,height,playtime,filesize,uptime,mid)
  72.             VALUES ('{$arcID}','$rndFileName','$fileurl','1','{$imginfos[0]}','$imginfos[1]','0','$fsize','".time()."','".$cuserLogin->getUserID()."'); ";
  73.             $dsql->ExecuteNoneQuery($inquery);
  74.             $fid = $dsql->GetLastID();
  75.             AddMyAddon($fid, $fileurl);
  76.             if($cfg_multi_site == 'Y')
  77.             {
  78.                 $fileurl = $cfg_basehost.$fileurl;
  79.             }
  80.             $body = str_replace($value, $fileurl, $body);
  81.             @WaterImg($rndFileName, 'down');
  82.         }
  83.     }
  84.     $htd->Close();
  85.     return $body;
  86. }


如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛

发表评论 (801人查看0条评论)
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
昵称:
最新评论
------分隔线----------------------------

快速入口

· 365软件
· 杰创官网
· 建站工具
· 网站大全

其它栏目

· 建站教程
· 365学习

业务咨询

· 技术支持
· 服务时间:9:00-18:00
365建站网二维码

Powered by 365建站网 RSS地图 HTML地图

copyright © 2013-2024 版权所有 鄂ICP备17013400号