<?php
//图片本地化插件
//dedecms中的:
function rnd_pic_fun( $saveremoteimg , $body ) {
global $tpbdh_imgUrl,$tpbdh_imgPath,$webdb;

$daytimeurl = strftime("%Y%m%d",time());
$milliSecond = strftime("%H%M%S",time());



//$imgUrl = "http://www.52qqxj.com/upload/edit_pic/".$daytimeurl;//网址
$imgUrl = $webdb['www_url'].$tpbdh_imgUrl.$daytimeurl;//网址
$imgPath = $tpbdh_imgPath.$daytimeurl;//硬盘


        if(!empty($saveremoteimg))
         {
                 $body = stripslashes($body);
                 $img_array = array();
				 
				 preg_match_all("/http:\/\/([^ '\"<>]+)\.(gif|jpg|png)/is",$body,$img_array);
				 $img_array = array_unique($img_array[0]);
                 //preg_match_all("/(src|SRC)=[\"|'| ]{0,}(http:\/\/(.*)\.(gif|jpg|jpeg|bmp|png))/isU",$body,$img_array);
                 //$img_array = array_unique($img_array[2]);
				 
				 //print_r($img_array);exit;
				 
                 set_time_limit(0);

                 if(!is_dir($imgPath)) @mkdir($imgPath,0777);
                 foreach($img_array as $key =>$value)
                 {
                         $value = trim($value);
                         $get_file = @file_get_contents($value);
                         $rndFileName = $imgPath."/".$milliSecond.$key.".".substr($value,-3,3);
                         $fileurl = $imgUrl."/".$milliSecond.$key.".".substr($value,-3,3);
						 echo $value."   文件下载到本地 ".$fileurl;
                         if($get_file)
                         {
                                 $fp = @fopen($rndFileName,"w");
                                 @fwrite($fp,$get_file);
                                 @fclose($fp);
                         }
                         $body = ereg_replace($value,$fileurl,$body);
                 }
                 $body = txt_htmlarea_addslashes($body);

         }
		 
		 
		return $body ;

}