Salad UN

To Taste The Salad Of Life.

« DedeCMS录入时间的修改方法DedeCMS用户登陆后评论自动记录用户名修改 »

DedeCMS抓取本机图片修改办法

[ At 2008-12-15 By Ash   1 comments ]

有时候需要将自己电脑里的网页复制到 cms里,那些 file:// 开头的图片不能被自动抓取到dedecms目录中,很麻烦。于是我修改了两个文件,使其具有此功能。
本人对dedecms不熟悉,不知道是否已经自带此功能,只是我没有打开。还忘高手不要见笑!


修改了include/pub_httpdown.php和admin/inc/inc_archives_functions.php两个文件

include/pub_httpdown.php:


修改
    //修改:使其可以解析 file:// 开头的图片
    preg_match_all("/(src|SRC)=[\"|'| ]{0,}(http|file:\/\/(.*)\.(gif|jpg|jpeg|bmp|png))/isU",$body,$img_array);
   
    $img_array = array_unique($img_array[2]);
   
    $imgUrl = $cfg_uploaddir."/".strftime("%y%m%d",time());
    $imgPath = $cfg_basedir.$imgUrl;
    if(!is_dir($imgPath."/")){
        MkdirAll($imgPath,$GLOBALS['cfg_dir_purview']);
        CloseFtp();
    }
    $milliSecond = strftime("%H%M%S",time());
   
    foreach($img_array as $key=>$value)
    {
        if(eregi($basehost,$value)) continue;
        if($cfg_basehost!=$basehost && eregi($cfg_basehost,$value)) continue;

        //修改:使其可以解析 file:// 开头的图片
        if(eregi("^http://",$value) || eregi("^file://",$value)){

            //随机命名文件
            $htd->OpenUrl($value);
            $itype = $htd->GetHead("content-type");
            if($itype=="image/gif") $itype = ".gif";
            else if($itype=="image/png") $itype = ".png";
            else $itype = ".jpg";
            $value = trim($value);
            $rndFileName = $imgPath."/".$milliSecond.$key.$itype;
            $fileurl = $imgUrl."/".$milliSecond.$key.$itype;
           
            //下载并保存文件
            $rs = $htd->SaveToBin($rndFileName);
           
            if($rs){
                $body = str_replace($value,$fileurl,$body);
                @WaterImg($rndFileName,'down');
            }
        }
       

    }

 

 


修改admin/inc/inc_archives_functions.php:
    function PrivateInit($url)
    {
            if($url=="") return ;
            $urls = "";
            $urls = @parse_url($url);
            $this->m_url = $url;
        if(is_array($urls))
        {
        
            if($urls["scheme"] == 'file'){//判断是否是本机图片
                //readfile($urls["path"]);
                $this->m_host = $urls["path"];
                $this->m_scheme = $urls["scheme"];
            }else{

 

 

修改
    //
    //用Http协议下载文件
    //
    function SaveToBin($savefilename)
    {
       
        if($this->m_scheme == 'file' && $this->m_host){//保存本机文件
           
            if ($this->m_httphead["content-type"] && @is_readable($this->m_host)) {

                $m_fp = @fopen($this->m_host, "r");
                $contents = @fread($m_fp, @filesize ($this->m_host));

                $fp = @fopen($savefilename,"w");
                @fwrite($fp,$contents);
                @fclose($m_fp);
                @fclose($fp);
            }


        }else{

 


 

修改

   //
    //开始HTTP会话
    //
    function PrivateStartSession($requestType="GET")
    {
        if($this->m_scheme == 'file'){//判断本机文件是否是图片
            if (@is_readable($this->m_host)) {
                $size = @getimagesize($this->m_host);
                if($size[0]>0 && $size[0]>0)$this->m_httphead["content-type"] = strtolower($size['mime']);
            }
            return;
        }

修改一个错误,正则写错了,不好意思,本人对正则不熟  admin/inc/inc_archives_functions.php
Copy codepreg_match_all("/(src|SRC)=[\"|'| ]{0,}([http|file]*:\/\/(.*)\.(gif|jpg|jpeg|bmp|png))/isU",$body,$img_array);
 

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

日历

最新评论及回复

最近发表

Powered By Z-Blog 1.8 Spirit Build 80722 Code detection by Codefense

Copyright 2008 www.s-un.cn. Some Rights Reserved.