Discuz伪静态代码

<?php
/**
 *	[伪静态跳转(xugui_redirect.{modulename})] (C)2012-2099 Powered by  懒人V难人.
 *	Version: 1.0
 *	Date: 2012-8-1 15:28
 */

if(!defined(‘IN_DISCUZ‘)) {
	exit(‘Access Denied‘);
}
class plugin_xugui_redirect {
	
	function plugin_xugui_redirect(){
		global $_G;
		//$this->tml=new template();
		$this->user_no_on = $_G[‘cache‘][‘plugin‘][‘xugui_redirect‘][‘user_no_on‘];
		$this->redirect_on = $_G[‘cache‘][‘plugin‘][‘xugui_redirect‘][‘redirect_on‘];
		$this->tag_rewrite_on = $_G[‘cache‘][‘plugin‘][‘xugui_redirect‘][‘tag_rewrite_on‘];
		$this->portal_cat_on = $_G[‘cache‘][‘plugin‘][‘xugui_redirect‘][‘portal_cat_on‘];
		$this->custom_replace = trim($_G[‘cache‘][‘plugin‘][‘xugui_redirect‘][‘custom_replace‘]);
		if(empty($this->custom_replace)){
			$this->custom_replace="comsenz.com->sharejie.com";
		}
	}
	private function getreplace_Url(){
		$Url=$_SERVER[‘REQUEST_URI‘];
		$pinfo=pathinfo($_SERVER[‘SCRIPT_NAME‘]);
		$pinfo[‘dirname‘]=($pinfo[‘dirname‘]=="\\"||$pinfo[‘dirname‘]=="/")?"":$pinfo[‘dirname‘];
		$Url=ltrim(str_replace($pinfo[‘dirname‘],"",$Url),‘/‘);
		$Url=str_replace(array(‘&extra‘,‘&page‘),array(‘&extra‘,‘&page‘),$Url);
		$tempUrl=output_replace(‘<a href="‘.$Url.‘">a</a>‘);	
		$tempUrl= preg_replace (‘/<a[^>]*?href="(.*?)"[^>]*>a<\/a>/i‘, "$1", $tempUrl);
		$tempUrl=str_replace(‘&‘, ‘&‘, $tempUrl);
		if(strpos($tempUrl, "http://")===0){
			return $tempUrl;
		}
		return "http://".$_SERVER[‘HTTP_HOST‘].$pinfo[‘dirname‘]."/".$tempUrl;
	}
	private function checkDomain($url){
		global $_G;
		if(!empty($_G[‘setting‘][‘output‘][‘str‘][‘search‘])) {
			if(empty($_G[‘setting‘][‘domain‘][‘app‘][‘default‘])) {
				$_G[‘setting‘][‘output‘][‘str‘][‘replace‘] = str_replace(‘{CURHOST}‘, $_G[‘siteurl‘], $_G[‘setting‘][‘output‘][‘str‘][‘replace‘]);
			}
			$pinfo=pathinfo($_SERVER[‘SCRIPT_NAME‘]);
			if($pinfo[‘dirname‘]!="\\"){
				return $url;
			}
			$Script_basename=$pinfo[‘basename‘];
			$A_Script_basename = str_replace($_G[‘setting‘][‘output‘][‘str‘][‘search‘], $_G[‘setting‘][‘output‘][‘str‘][‘replace‘], ‘<a href="‘.$Script_basename);
			$A_Script_basename=str_replace(‘<a href="‘,"",$A_Script_basename);
			if($A_Script_basename==$Script_basename){
				return $url;
			}
			$url_info=parse_url($A_Script_basename);
			if($url_info[‘host‘]!=$_SERVER[‘HTTP_HOST‘]){
				return str_replace($_SERVER[‘HTTP_HOST‘],$url_info[‘host‘],$url);
			}
		}
		return $url;
	}
	function common(){
		if(defined(‘IN_MODCP‘) || defined(‘IN_ADMINCP‘)) return "";
		global $_G;
		if($this->user_no_on){
			if($_G[‘groupid‘] !=‘7‘&&$_G[‘groupid‘] !=‘20‘){
				//禁用
				$_G[‘setting‘][‘output‘] = array("0"=>"0");
				return;
			}
		}
		//标签伪静态
		if($this->tag_rewrite_on&&!empty($_G[‘setting‘][‘output‘][‘preg‘][‘search‘])){
			$_G[‘setting‘][‘output‘][‘preg‘][‘search‘][‘xugui_tag_top‘]=‘/<a([^\>]*?)href\="misc.php\?mod\=tag"([^\>]*)\>/i‘;
			$_G[‘setting‘][‘output‘][‘preg‘][‘replace‘][‘xugui_tag_top‘]=‘<a$1href="tag_0.html"$4>‘;
			$_G[‘setting‘][‘output‘][‘preg‘][‘search‘][‘xugui_tag‘]=‘/<a([^\>]*?)href\="misc.php\?mod\=tag&(amp;)?id\=(\d+?)"([^\>]*)\>/i‘;
			$_G[‘setting‘][‘output‘][‘preg‘][‘replace‘][‘xugui_tag‘]=‘<a$1href="tag_$3.html"$4>‘;
			
		}
		if(!empty($this->custom_replace)){
			$replace_arr=explode("\r\n", $this->custom_replace);
			foreach ($replace_arr as $key=>$value){
				$temp_Arr=explode("->",$value);
				if(count($temp_Arr)!=2||empty($temp_Arr[0])||empty($temp_Arr[1])){continue;}
				$_G[‘setting‘][‘output‘][‘str‘][‘search‘][‘xugui_rep_‘.$key]=$temp_Arr[0];
				$_G[‘setting‘][‘output‘][‘str‘][‘replace‘][‘xugui_rep_‘.$key]=$temp_Arr[1];
			}
		}
		if($this->portal_cat_on&&!empty($_G[‘setting‘][‘output‘][‘preg‘][‘search‘])){
			$tab_domain=$_G[‘setting‘][‘domain‘][‘app‘][‘portal‘]?$_G[‘setting‘][‘domain‘][‘app‘][‘portal‘]:$_G[‘setting‘][‘domain‘][‘app‘][‘default‘];
			$_G[‘setting‘][‘output‘][‘preg‘][‘search‘][‘xugui_portal_cat‘]=‘/<a([^\>]*?)href\="portal.php\?mod\=list&(amp;)?catid\=(\d+?)"([^\>]*)\>/i‘;
			$_G[‘setting‘][‘output‘][‘preg‘][‘replace‘][‘xugui_portal_cat‘]=‘<a$1href="plist_$3.html"$4>‘;
			$_G[‘setting‘][‘output‘][‘preg‘][‘search‘][‘xugui_portal_cat_h‘]=‘/<a([^\>]*?)href\="http\:\/\/‘.$_SERVER[‘HTTP_HOST‘].‘\/portal\.php\?mod=list&(amp;)?catid=(\d+?)"([^\>]*)\>/i‘;
			$_G[‘setting‘][‘output‘][‘preg‘][‘replace‘][‘xugui_portal_cat_h‘]=‘<a$1href="http://‘.$_SERVER[‘HTTP_HOST‘].‘/plist_$3.html"$4>‘;

		}
		if($this->redirect_on){
			$purl=$this->getreplace_Url();
			$purl=$this->checkDomain($purl);
			//现在的地址
			$turl=strpos($_SERVER[‘REQUEST_URI‘],"http://")===0?$_SERVER[‘REQUEST_URI‘]:"http://".$_SERVER[‘HTTP_HOST‘].$_SERVER[‘REQUEST_URI‘];	
			if($turl!=$purl){
				header("HTTP/1.1 301 Moved Permanently");
				header("location: $purl");
				die();				
			}
		}		
	}

}


?>

  

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。