www.gusucode.com > 08CMS空白站群系统 3.3 繁体 UTF-8 > upload/include/linkparse.cls.php

    <?php
load_cache('rprojects');
class linkparse{
	var $html = '';
	var $links = array();
	var $reflink = '';
	var $rpid = 0;
	var $jumpfile = '';
	function __construct(){
		$this->linkparse();
	}
	function linkparse(){
	}
	function setsource($html,$reflink,$rpid=0,$jumpfile=''){
		//if(!$html || !$reflink) return false;
		$this->html = $html;
		$this->reflink = $reflink;
		$this->rpid = $rpid;
		$this->jumpfile = $jumpfile;
	}
	function handlelinks(){
		$links = array();
		$aregions = array();
		$regex = "/<a(.+?)href[ ]*=[ |'|\"]*(.+?)[ |'|\"]+/is";
		if(preg_match_all($regex,$this->html,$matches)){
			$aregions = array_unique($matches[2]);
			foreach($aregions as $aregion){
				$nregion = fillurl($aregion,$this->reflink);
				$nregion = view_url($this->remotefile($nregion));
				$links[] = $nregion;
				$regex1 = regencode($aregion);
				$regex1 = "/href[ ]*=[ |'|\"]*".$regex1."[ |'|\"]+/is";
				$this->html = preg_replace($regex1,"href=\"$nregion\" ",$this->html);
			}
		}
		$regex = "/<[img|embed]([^<|>]+?)src[ ]*=[ |'|\"]*(.+?)[ |'|\"]+/is";
		if(preg_match_all($regex,$this->html,$matches)){
			$aregions = array_unique($matches[2]);
			foreach($aregions as $aregion){
				$nregion = fillurl($aregion,$this->reflink);
				$nregion = view_url($this->remotefile($nregion));
				$links[] = $nregion;
				$regex1 = regencode($aregion);
				$regex1 = "/src[ ]*=[ |'|\"]*".$regex1."[ |'|\"]+/is";
				$this->html = preg_replace($regex1,"src=\"$nregion\" ",$this->html);
			}
		}
		$this->links = $links;
		unset($links,$regex,$matches,$aregions,$nregion);
	}
	function handlelink($link){
		if(!$link) return '';
		$link = fillurl($link,$this->reflink);
		$link = $this->remotefile($link);
		return $link;
	}
	function remotefile($remotefile){
		global $c_upload;
		$filearr = $c_upload->remote_upload($remotefile,$this->rpid,$this->jumpfile);
		return $filearr['remote'];
	}		
}

?>