<?php
/**
 * common.inc.php
 *
 * @version $Id: common.inc.php,v 1.1.1.1 2004/09/30 05:38:32 peter Exp $
 * @copyright 2002 Be Corp
 **/
include_once "class/ini.class.php";
/**
* Document::error()
* 
* { Description }
*/
/*some config*/
define("_TEXTFORMAT","yes");//是否进行文章内容格式化，yes,no
define("_RKEYWORD","no");//是否进行关键词替换，yes,no
define("_USE_CONF_CACHE","yes");//是否进行系统缓存,yes,no
define("_USE_TEXT_MARK","no");//是否添加文本的水印,yes,no
/*some config end*/
function error($message){
       global $module;
        ob_end_clean();
        ob_start();
        echo "<script language=javascript>alert('" . $message . "');history.back(1);</script>";
        exit;
}

/**
* Document::succ()
* 
* { 成功跳转 }
*/

function succ($url, $message){
        ob_end_clean();
        ob_start();
        $url = str_replace(' ', '', $url);
        echo "<script language=javascript>alert('" . $message . "');location.href='" . $url . "';</script>";
        exit;
}
/**
* Document::mk_dir()
* 
* { Description }
*/
function mk_dir($dir_name){
        $dir_names = explode("/", $dir_name);
        $temp="";
        for($i = 0;$i < count($dir_names)-1;$i++){
                $temp .= $dir_names[$i] . "/";
                if (!is_dir($temp)){
                        $oldmask = umask(0);
                        mkdir($temp, 0777);
                        umask($oldmask);
                }
        }
}
/**
* Document::thumb_images()
* 
* { Description }
* 
* @param string $option 
*/
/*
function thumb_images($sourcepic, $destpic, $res, $quality, $option = "GD"){
	global $gallery_conf;
	print_r($gallery_conf);
	$option=$gallery_conf[thumb_way]?$gallery_conf[thumb_way]:"GD";
        if ($option == "netpbm"){
                $image_info = getimagesize($sourcepic);
                thumb_image_netpbm($sourcepic, $destpic, $quality, $res, $image_info);
        }else{
        	if(!function_exists(imagecreatefromjpeg)) error("Your server Not support GD");
        	if(!file_exists($sourcepic)) return "No this file";
                if (eregi("\.(jpg|jpeg)$", $sourcepic)) $im = imagecreatefromjpeg($sourcepic);
                if ($im != ""){
                        $dims = explode("x", $res);
                        $newh = $dims[1];
                        $neww = $newh / imagesy($im) * imagesx($im);
                        if ($neww > imagesx($im)){
                                $neww = imagesx($im);
                                $newh = imagesy($im);
                        }
                        if ($neww > $dims[0]){
                                $neww = $dims[0];
                                $newh = $neww / imagesx($im) * imagesy($im);
                        }
                        $im2 = imagecreatetruecolor($neww, $newh);
                        //ImageCopyResized($im2, $im, 0, 0, 0, 0, $neww, $newh, imagesx($im), imagesy($im));
                        imagecopyresampled($im2,$im,0,0,0,0,$neww,$newh,ImageSX($im),ImageSY($im));
                        if (eregi("\.(jpg|jpeg)$", $sourcepic)) imagejpeg($im2, $destpic, $quality);
                        ImageDestroy($im);
                        ImageDestroy($im2);
                }else{
                        error("Error loading file!");
                }
        }
}*/
function thumb_images($sourcepic, $destpic, $res, $quality, $option = "GD"){
	global $gallery_conf;
	$option=$gallery_conf[thumb_way]?$gallery_conf[thumb_way]:"GD";
        if ($option == "netpbm"){
                $image_info = getimagesize($sourcepic);
                thumb_image_netpbm($sourcepic, $destpic, $quality, $res, $image_info);
        }else{
        	if(!function_exists(imagecreatefromjpeg)) error("Your server Not support GD");
        	if(!file_exists($sourcepic)) return "No this file";
                if (eregi("\.(jpg|jpeg)$", $sourcepic)) $im = imagecreatefromjpeg($sourcepic);
                if (eregi("\.gif$", $sourcepic)){
                	 $im = imagecreatefromgif($sourcepic);
                	 if(!function_exists(imagecreatefromgif)) error("Your GD Not Support GIF File");
                	}
                if (eregi("\.png$", $sourcepic)) $im = imagecreatefrompng($sourcepic);
                if ($im != ""){
             $dims = explode("x", $res);
				$dx=$dims[0]/$dims[1];//完善后比例
				$sxx = imagesx($im) ;
				$syy = imagesy($im);
				$sx = $sxx / $syy;//前比例
				if($dx<=1){
				if($sx>$dx){
					$rsxx=$syy*$dx;
					$rsyy=$syy;
				}else{
					$rsxx=$sxx;
					$rsyy=$sxx/$dx;
				}
				}else{
				if($sx>$dx){
					$rsxx=$syy*$dx;
					$rsyy=$syy;
				}else{
					$rsxx=$sxx;
					$rsyy=$sxx/$dx;
				}				
				}
				$xs = ($sxx-$rsxx)/2;
				$ys = ($syy-$rsyy)/2;
                        $newh = $dims[1];
				$neww = $dims[0];
                        $im2 = imagecreatetruecolor($neww, $newh);
                        //ImageCopyResized($im2, $im, 0, 0, 0, 0, $neww, $newh, imagesx($im), imagesy($im));
                        imagecopyresampled($im2,$im,0,0,$xs,$ys,$neww,$newh,$rsxx,$rsyy);
                        //if (eregi("\.(jpg|jpeg)$", $sourcepic))
                         imagejpeg($im2, $destpic, $quality);
                        ImageDestroy($im);
                        ImageDestroy($im2);
                }else{
                        error("Error loading file!");
                }
        }
}
/*
分页类
*/
class pages
{
	var $cnt;
	var $start;
	var $lim=10;
	var $zapros;
	var $query;
	var $type="normal";
	var $script;
	var $vars;
	var $titlenext=_LANG_0673;
	var $titleprev=_LANG_0674;
	var $center=true;
	function pages(){
		if(empty($this->start)){
			global $_REQUEST;
			$this->start=$_REQUEST[start];
			if(empty($this->start)){
				$this->start=0;
			}
		}
		if(empty($this->script)){
			global $PHP_SELF;
			$this->script=$PHP_SELF;
		}
	}
	function check()
	{
		$do[0]="";
		if($this->cnt > $this->lim){
			$do[1]=true;}
		else{
			$do[1]=false;}
		$do[2]=$this->cnt;
		return $do;
	}
	function make_list()
	{
		$wtd=$this->check();
		$start=$this->start;
		$lim=$this->lim;
		$allrec=$wtd[2];
		if($wtd[1]){
			if($this->center) print "<div align=\"center\">";
			$page=($start/$lim)+1;
			$allpages=(ceil($allrec/$lim));
			$last = $start-$lim;
			$next = $start+$lim;
			if(is_array($this->vars)){
				foreach($this->vars as $key=>$val)
				{
					$suffix.="&$key=$val";
				}
			}
			if($allpages>1){
			$ret = "<table width=100% border=0 cellpadding=0 cellspacing=0><tr height=25 bgcolor=#e5e5e5 valign=middle><td align=left> <b>"._LANG_0675."</b>&nbsp;&nbsp;";
			$ret .="&nbsp;"._LANG_0676."$page/$allpages &nbsp; $lim "._LANG_0677."&nbsp;&nbsp;"._LANG_0678."".$allrec.""._LANG_0679."&nbsp;&nbsp;</td><td align=right>";
			$ret .="<a href=\"$this->script?start=0$suffix\">"._LANG_0680."</a>&nbsp;&nbsp;";
			if($start>0){
			$ret .="<a title=\"$this->titleprev\" href=\"$this->script?start=$last$suffix\">"._LANG_0681."</a>&nbsp;&nbsp;";
			}
			if ($start != ($allpage - 1)*$lim  && $page<$allpages) {
			$ret .="<a title=\"$this->titlenext\" href=\"$this->script?start=$next$suffix\">"._LANG_0682."</a>&nbsp;&nbsp;";
			}
			$nl=($allpages-1)*$lim;
			$ret .="<a href=\"$this->script?start=$nl$suffix\">"._LANG_0683."</a>&nbsp;&nbsp;";
			$ret.=""._LANG_0684." <select style=\"FONT-SIZE: 9px; FONT-FAMILY: Arial\" name=page onChange=\"javascript:location.href=this.options[selectedIndex].value\">";
			for($n=1;$n<=$allpages;$n++){
			$sel=($page == $n)?"selected":"";
			$nu=($n-1)*$lim;
			$url = "$this->script?start=$nu$suffix";
			$ret.="<option value=\"$url\" $sel >$n";
			}
			$ret.="</select>"._LANG_0685."</td></tr></table>";
			}
			echo  $ret;
		}
	}
	function get_list()
	{
		$wtd=$this->check();
		$start=$this->start;
		$lim=$this->lim;
		$allrec=$wtd[2];
		if($wtd[1]){
			if($this->center) $ret.= "<div align=\"center\">";
			$page=($start/$lim)+1;
			$allpages=(ceil($allrec/$lim));
			$last = $start-$lim;
			$next = $start+$lim;
			if(is_array($this->vars)){
				foreach($this->vars as $key=>$val)
				{
					$suffix.="&$key=$val";
				}
			}
			if($allpages>1){
			$ret = "<table width=100% border=0 cellpadding=0 cellspacing=0><tr height=25 bgcolor=#e5e5e5 valign=middle><td align=left> <b>"._LANG_0675."</b>&nbsp;&nbsp;";
			$ret .="&nbsp;"._LANG_0676.":$page/$allpages &nbsp;"._LANG_0678."".$allrec.""._LANG_0679."&nbsp;&nbsp;</td><td align=right>";
			$ret .="<a href=\"$this->script?$suffix\">"._LANG_0680."</a>&nbsp;&nbsp;";
			if($start>0){
			$ret .="<a title=\"$this->titleprev\" href=\"$this->script?start=$last$suffix\">"._LANG_0681."</a>&nbsp;&nbsp;";
			}
			if ($start != ($allpage - 1)*$lim  && $page<$allpages) {
			$ret .="<a title=\"$this->titlenext\" href=\"$this->script?start=$next$suffix\">"._LANG_0682."</a>&nbsp;&nbsp;";
			}
			$nl=($allpages-1)*$lim;
			$ret .="<a href=\"$this->script?start=$nl$suffix\">"._LANG_0683."</a>&nbsp;&nbsp;";
			
			$ret.=""._LANG_0684." <select style=\"FONT-SIZE: 9px; FONT-FAMILY: Arial\" name=page onChange=\"javascript:location.href=this.options[selectedIndex].value\">";
			for($n=1;$n<=$allpages;$n++){
			$sel=($page == $n)?"selected":"";
			$nu=($n-1)*$lim;
			$url = "$this->script?start=$nu$suffix";
			$ret.="<option value=\"$url\" $sel >$n";
			}
			$ret.="</select>"._LANG_0685."</td></tr></table>";
			}			
		}
		return $ret;
	}
	function get_html_list()
	{
		$wtd=$this->check();
		$start=$this->start;
		$lim=$this->lim;
		$allrec=$wtd[2];
		$end = $this->vars["end"];
		if($wtd[1]){
			if($this->center) $ret.= "<div align=\"center\">";
			$page=($start/$lim)+1;
			$allpages=(ceil($allrec/$lim));
			$last = $start-$lim;
			$next = $start+$lim;
			if($allpages>1){
			$ret = "<table width=100% border=0 cellpadding=0 cellspacing=0><tr height=25 bgcolor=#e5e5e5 valign=middle><td align=left> <b>"._LANG_0675."</b>&nbsp;&nbsp;";
			$ret .="&nbsp;"._LANG_0676.":$page/$allpages &nbsp;"._LANG_0678."".$allrec.""._LANG_0679."&nbsp;&nbsp;</td><td align=right>";
			$ret .="<a href=\"$this->script,0$end\">"._LANG_0680."</a>&nbsp;&nbsp;";
			if($start>0){
			$ret .="<a title=\"$this->titleprev\" href=\"$this->script,$last$end\">"._LANG_0681."</a>&nbsp;&nbsp;";
			}
			if ($start != ($allpage - 1)*$lim  && $page<$allpages) {
			$ret .="<a title=\"$this->titlenext\" href=\"$this->script,$next$end\">"._LANG_0682."</a>&nbsp;&nbsp;";
			}
			$nl=($allpages-1)*$lim;
			$ret .="<a href=\"$this->script,$nl$end\">"._LANG_0683."</a>&nbsp;&nbsp;";
			
			$ret.=""._LANG_0684." <select style=\"FONT-SIZE: 9px; FONT-FAMILY: Arial\" name=page onChange=\"javascript:location.href=this.options[selectedIndex].value\">";
			for($n=1;$n<=$allpages;$n++){
			$sel=($page == $n)?"selected":"";
			$nu=($n-1)*$lim;
			$url = "$this->script,$nu".$end;
			$ret.="<option value=\"$url\" $sel >$n";
			}
			$ret.="</select>"._LANG_0685."</td></tr></table>";
			}			
		}
		return $ret;
	}
}

 #other function
 /**
 * cp_remote_file()
 * 从html中解析URL,远程复制
 * @param $pre
 * @param $url
 * @param $end
 * @return 
 **/
function cp_remote_file($pre, $url, $end){
	global $HTTP_HOST, $REQUEST_URI, $SCRIPT_NAME;
	$pre = stripslashes($pre);
	$end = stripslashes($end);
	$src_file = $url;
	$ctime=date("Y-m-d",time());
	$filename=pathinfo($src_file);
	$filename=$filename[basename];
	$dst_file = "images/articles/" . $ctime . "/" . $filename;
	mk_dir("images/articles/" . $ctime . "/");
	if(file_exists($dst_file)) $dst_file="images/articles/" . $ctime . "/copy_" . $filename;
	if(eregi("http://", $src_file) && eregi($HTTP_HOST, $src_file)){
		$ret = $src_file;
	}elseif(!eregi("http://", $src_file)){
		$ret = $src_file;
	}
	else{
	if(remote_copy($src_file, $dst_file)){
		$ret = PLUS_URL."/" .$dst_file;
	}else{
		$ret = $src_file;
}
}
if(!eregi("http://", $src_file)){
	//$filepath = (!empty($REQUEST_URI)) ? $REQUEST_URI : $SCRIPT_NAME;
//	$filepath = $HTTP_HOST . $filepath;
	$ret = PLUS_URL."/" . $ret;
}
	//trace($ret);
return $pre . $ret . $end;
}
/**
 * remote_copy()
 * 远程复制
 * @param $src_file 源文件
 * @param $dst_file 目标文件
 * @return 
 **/
function remote_copy($src_file, $dst_file){
	// 可以从网络或本地将文件拷贝到目的文
	$fd_src = @fopen($src_file, "r");
	if (!$fd_src) return false;
	$fd_dst = fopen($dst_file, "wb+");
	if (!$fd_dst){
		fclose($fd_src);
		return false;
	}
	while (!feof($fd_src)){
		$buffer = fread($fd_src, 1024);
		fwrite($fd_dst, $buffer);
	}
	fclose($fd_src);
	fclose($fd_dst);
	return true;
}

function trace($var){
	global $_REQUEST;
	if(is_array($var)){
		print "<pre>";
		print_r($var);
	}else{
		print $var;
	}
	print "</pre>";
	exit;
}
/**
* Document::plusfwrite()
* 
* { Description }
*/

function plusfwrite(){
        if (isPost()){
        }else{
                return false;
        }
        if (myRefererCheck($errstr)){
        }else{
                return false;
        }
        return true;
}

/**
* Document::isPost()
* 
* { Description }
*/
function isPost(){
        global $REQUEST_METHOD;
        if ($REQUEST_METHOD == "POST"){
                return true;
        }else{
                return false;
        }
}
/**
* Document::showMsg()
* show msg
* { Description }
*/
function showMsg($msg){
        echo html_table_header(_LANG_0686, 1);
        echo "<tr class=\"tablerow\"><td align=\"center\">$msg</td></tr>";
        echo html_table_footer();
}

function getsubcids2($pid = 0, $deepth = "1",$catetree)
{ 
	// deepth -1:全部下面的ID
	$tree = $catetree;
	$ids = $pid;
	if (count($tree[$pid][child]) > 0) {
		foreach($tree[$pid][child] as $id) {
			if($tree[$id][status]!='yes') continue;
			if ($deepth == 0) {
				return $ids;
			} elseif ($deepth > 0) {
				$ids .= "," . getsubcids($id, $deepth-1 ,$tree);
			} elseif ($deepth == "-1") {
				$ids .= "," . getsubcids($id, "-1",$tree);
			} 
		} 
	} 
	return $ids;
}

//new 
function dogetsubcids($pid = 0, $deepth = "1",$catetree)
{ 
	// deepth -1:全部下面的ID
	$tree = $catetree;
	$ids = $pid;
	if (count($tree[$pid][child]) > 0) {
		foreach($tree[$pid][child] as $id) {
			if($tree[$id][status]!='yes') continue;
			if ($deepth == 0) {
				return $ids;
			} elseif ($deepth > 0) {
				$ids .= "," . dogetsubcids($id, $deepth-1 ,$tree);
			} elseif ($deepth == "-1") {
				$ids .= "," . dogetsubcids($id, "-1",$tree);
			} 
		} 
	} 
	return $ids;
}

function cacheSubCids($cid=0){
	global $catetree;
	foreach($catetree as  $cid=>$var){
		$cfile="cache/cache_".$cid.".cache";
		$subcids = dogetsubcids($cid,"-1",$catetree);
		$fp=fopen($cfile,"w");
		fputs($fp,$subcids);
		fclose($fp);
	}
}

function getsubcids($pid = 0, $deepth = "1",$catetree){
		$cfile="cache/cache_".$pid.".cache";
		if(file_exists($cfile)){
			$fp=fopen($cfile,"r");
			$ret=fread($fp,filesize($cfile));
			fclose($fp);
		}else{
			$ret = dogetsubcids($pid,$deepth ,$catetree);
		}
		return $ret;
}
function getAsubcids($pid = 0, $deepth = "1",$catetree)
{ 
	// deepth -1:全部下面的ID
	$tree = $catetree;
	$ids = $pid;
	if (count($tree[$pid][child]) > 0) {
		foreach($tree[$pid][child] as $id) {
			if($tree[$id][status]!='yes') continue;
			if($catetree[$cid][ctype] =="page" ||$catetree[$cid][ctype] =="url" || $catetree[$cid][ctype] =="bbs" || $catetree[$cid][ctype] =="member") continue;
			if ($deepth == 0) {
				return $ids;
			} elseif ($deepth > 0) {
				$ids .= "," . getsubcids($id, $deepth-1 ,$tree);
			} elseif ($deepth == "-1") {
				$ids .= "," . getsubcids($id, "-1",$tree);
			} 
		} 
	} 
	return $ids;
}
function getCategory(){
	global $PlusDB;
	$file=PLUS_ROOT_PATH."/cache/category.cache.php";
	if(file_exists($file)  && _USE_CONF_CACHE=="yes"){
		include($file);
		$catetree=Unserialize($str);
	}else{
		mk_dir("cache/");
		$catetree = geArticleCategoryList();
		$str='<?$str=\''.Serialize($catetree).'\';?>';
		$fp=fopen($file,"w");	
		@fwrite($fp,$str);
		fclose($fp);
	}	
	return $catetree;
}

 function geArticleCategoryList()
            {
            global $PlusDB;
            $grdb = $PlusDB->prefix("group_right");
            $sql="select * from $grdb where 1=1";
            if($rt = $PlusDB->query($sql)){
            	$right=array();
				while($row=$rt->fetchRow()){
				        $right[$row[cid]][]=$row[gid];
				}
            }
            //trace($right);
            $sql="select id,title,english_name,pid,o_num,cate_template,list_template,detail_template,cate_mod as mod1,intro,other_1,page_title,page_keyword,page_discription,page_num,page_col,other_2,other_3,status from ".$PlusDB->prefix("category")." where 1=1 order by o_num asc";
            $rt=$PlusDB->query($sql);
            while ($row=$rt->fetchRow($rt))
                {
					if(count($right)>0) $row["mod"] = $right[$row["id"]]; else $row["mod"]=array();
                $tree[$row["pid"]]["child"][] = $row["id"];
                $tree[$row["id"]]["name"]=$row["title"];
				  $tree[$row["id"]]["status"]=$row["status"];
                $tree[$row["id"]]["english_name"]=$row["english_name"];
                $tree[$row["id"]]["pid"]=$row["pid"];
                $tree[$row["id"]]["o_num"]=$row["o_num"];
                $tree[$row["id"]]["cate_template"]=$row["cate_template"];
                $tree[$row["id"]]["list_template"]=$row["list_template"];
                $tree[$row["id"]]["detail_template"]=$row["detail_template"];
                $tree[$row["id"]]["mod"]=$row["mod"];
                $tree[$row["id"]]["intro"]=$row["intro"];
                $tree[$row["id"]]["ctype"]=$row["other_1"];
				  $tree[$row["id"]]["page_title"]=$row["page_title"];
				  $tree[$row["id"]]["page_keyword"]=$row["page_keyword"];
				  $page_setting=Unserialize($row["page_discription"]);
		if(!is_array($page_setting)){
			$page_setting[title_max]=$row["page_discription"];
			$page_setting[page_num]=$row["page_num"];
			$page_setting[page_col]=$row["page_col"];
		}
		$tree[$row["id"]]["page_setting"]=$page_setting;
		//$tree[$row["id"]]["page_discription"]=$row["page_discription"];
		$tree[$row["id"]]["page_num"]=$row["page_num"];
		$tree[$row["id"]]["page_col"]=$row["page_col"];
		$tree[$row["id"]]["url"]=$row["other_3"];
		$tree[$row["id"]]["topicid"]=$row["other_2"];
                }
            return $tree;
            }

function getConfigration(){
	global $PlusDB;
	$file=PLUS_ROOT_PATH."/cache/config.cache.php";
	$conf_array=array();
	if(file_exists($file)  && _USE_CONF_CACHE=="yes"){
		include($file);
		$conf_array=Unserialize($str);
	}
	
	if(count($conf_array)>5){
		 
	}else{
		mk_dir("cache/");
		$confdb  = $PlusDB->prefix("configration");
		$sql="select conf_id,conf_title,conf_set,type from $confdb  where conf_id>0";
		$rt=$PlusDB->query($sql);
		$conf_array=array();
		while($row=$rt->fetchRow())
		{
			$conf_array[$row["type"]][$row["conf_title"]]=$row["conf_set"];
		}
		$fp=fopen($file,"w");	
		$str='<?$str=\''.Serialize($conf_array).'\';?>';
		@fwrite($fp,$str);
		fclose($fp);
	}
	return $conf_array;
}


/**
* Document::format_text()
* 
* { Description }
* 
* @param integer $html 
* @param integer $word_wrap 
* @param integer $bbcode 
* @param integer $bbcode_img 
*/
function format_text($text, $html = 0, $word_wrap = 0, $bbcode = 0, $bbcode_img = 0,$imagezoom=0){
	$text = trim($text);
	if ($word_wrap && $text != ""){
		$text = preg_replace("/([^\n\r ?&\.\/<>\"\\-]{" . $word_wrap . "})/i", " \\1\n", $text);
	}
	if ($html == 0){
		$text = str_replace("&lt;", "&amp;lt;", $text);
		$text = str_replace("&gt;", "&amp;gt;", $text);
		$text = str_replace("<", "&lt;", $text);
		$text = str_replace(">", "&gt;", $text);
	}
	if(!get_magic_quotes_gpc()) $text = stripslashes($text);
	if(_TEXTFORMAT=="yes") 
	{
	//$text = str_replace("\n", "<br />", $text);
	$text = eregi_replace("<br /></t", "</t", $text);
	$text = eregi_replace("<br /><t", "<t", $text);	
	$text = eregi_replace("<br />\r<br />","<br />",$text);
	$text = eregi_replace("<br />\r\n<br />","<br />",$text);
	$text = eregi_replace("<br /><P>","<P>",$text);
	$text = eregi_replace("<BR><BR>","<BR>",$text);
	$text = eregi_replace("<br><br />","<BR>",$text);
	}
	//$text = preg_replace("/\<br \/\>/is", "<script src=".PLUS_URL."/adshow.php?tid=1></script>", $text, 1);
	if ($bbcode == 1){
		$text=	plus_bbcode($text);
	}
	//$text = keywordText($text);
	//$text = linkText($text);
	$text = str_replace("\\'", "'", $text);
	if(_RKEYWORD=="yes") $text = keywordText($text);
	if($imagezoom==9){
		//$patt_src = "/(<img.*src=[\s]*)(['\"]?)([^\s\"']+)(['\"]?)([^>\"']*)>/iseU";
		//$patt_src = "/(<img.*src=[\s]*)(['\"\\\'\\\"]{0,1})([^\s\"']+)(['\"\\\'\\\"]{0,1})( *)([^>]*)>/ise";
		$patt_src="/(\<img[^\<\>]*)(src)(\=[\"|\'|\\\"|\\\']*)([^\"\'\s\>\\]+)([\"|\'|\\\"|\\\']*)([^\<\>]*)(\>)/ise";
		$inner = "onload='res(this,450,450)' border='0'  style='border:1px #000000 solid' alt='点击浏览原图' ";
	//	preg_match($patt_src,$text,$out);
	//	trace($out);
		$text=preg_replace($patt_src, "\"<a href=\\4 target=_blank>\\1\\2\\3\\4\\5 $inner\\6 </a>\"", $text);
	}
	//checkOverLoad();
	if(_USE_TEXT_MARK=='yes') $text=makeSec($text);
	return $text;
}
    function plus_bbcode($string) { 
        $string = preg_replace("/\[b\](.*?)\[\/b\]/si", "<b>\\1</b>", $string); 
        $string = preg_replace("/\[i\](.*?)\[\/i\]/si", "<i>\\1</i>", $string); 
        $string = preg_replace("/\[u\](.*?)\[\/u\]/si", "<u>\\1</u>", $string); 
        $string = preg_replace("/\[p\](.*?)\[\/p\]/si", "<p>\\1</p>", $string); 
        $string = preg_replace("/\[code\](.*?)\[\/code\]/si", "<blockquote><pre>\\1</pre></blockquote>", $string); 
        $string = preg_replace("/\[quote\](.*?)\[\/quote\]/si", "<table border=\"0\" width=\"90%\" cellspacing=\"0\" cellpadding=\"0\"><tr><td>Quote:</td></tr><tr><td align=left><hr size=1 width=95%>\\1</td></tr></table>", $string); 
        $string = preg_replace("/(^|\s)(http:\/\/\S+)/si", "\\1<a href=\"\\2\">\\2</a>", $string); 
        $string = preg_replace("/(^|\s)(www\.\S+)/si", "\\1<a href=\"http://\\2\">\\2</a>", $string); 
        $string = preg_replace("/\[url\](http|https|ftp)(:\/\/\S+?)\[\/url\]/si", 
                               "<a href=\"\\1\\2\" target=\"_blank\">\\1\\2</a>", $string); 
        $string = preg_replace("/\[url\](\S+?)\[\/url\]/si", 
                               "<a href=\"http://\\1\" target=\"_blank\">\\1</a>", $string); 
        $string = preg_replace("/\[url=(http|https|ftp)(:\/\/\S+?)\](.*?)\[\/url\]/si", 
                               "<a href=\"\\1\\2\" target=\"_blank\">\\3</a>", $string); 
        $string = preg_replace("/\[url=(\S+?)\](\S+?)\[\/url\]/si", 
                               "<a href=\"http://\\1\" target=\"_blank\">\\2</a>", $string); 
        $string = preg_replace("/\[email\](\S+?@\S+?\\.\S+?)\[\/email\]/si", 
                               "<a href=\"mailto:\\1\">\\1</a>", $string); 
        $string = preg_replace("/\[img\](\S+?)\[\/img\]/si", 
                               "<img src=\"\\1\" border=0 alt=\"\\1\">", $string);
         $string = preg_replace("/\[color=(['\"]?)([^\"']*)\\1](.*)\[\/color\]/si",
                               "<span style='color: \\2;'>\\3</span>",$string);
         $string = preg_replace("/\[size=(['\"]?)([^\"']*)\\1](.*)\[\/size\]/si",
         	              "<span style='font-size: \\2;'>\\3</span>",$string);
         $string = preg_replace("/\[flash](.*)\[\/flash\]/sU"," <OBJECT       codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0        classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000><PARAM NAME=\"movie\" VALUE=\"\\1\"><PARAM NAME=\"quality\" VALUE=\"high\"><embed src=\"\\1\" quality=high      pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\"        type=\"application/x-shockwave-flash\"  wmode=\"transparent\">              </embed>       </OBJECT><br><img src='modules/forum/images/swf.gif' align='absmiddle'><a href=\\1 target=_blank>新窗口显示</a>",$string);
         $string = preg_replace("/\[font=(['\"]?)([^\"']*)\\1](.*)\[\/font\]/sU","<span style='font-family: \\2;'>\\3</span>",$string);
         $string = preg_replace("/\[list]/sU","<ul>",$string);
         $string = preg_replace("/\[\/list]/sU","</ul>",$string);
         $string = preg_replace("/\[li](.*)\[\/li\]/sU","<li>\\1</li>",$string);
        return $string; 
    } 
        function show_code($code)
        {
        	return highlight_string($code);	
        }
        /**
* Document::checkEmail()
* 
* { Description }
*/
function checkEmail($email){
        if (!$email || !eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$", $email)){
                return false;
        }
        return true;
}

function makeCacheCategory(){
		$file="cache/category.cache.php";
		@mk_dir("cache/");
		$catetree=geArticleCategoryList();
		$str='<?$str=\''.Serialize($catetree).'\';?>';
		$fp=fopen($file,"w");	
		@fwrite($fp,$str);
		fclose($fp);
		cacheSubCids();
}
function getCategoryPath($cid,$ret="")
{
	global $catetree;
	if($cid==0) return "";
	$ret=$catetree[$cid][english_name]."/".$ret;
	$pid=$catetree[$cid][pid];
	if($pid>0)
	{
		$ret=getCategoryPath($pid,$ret);
	}
	return $ret;
}

function getPosition($cid,$ret="")
{
	global $catetree;
	if($cid==0) return "";
	$url=ge_url($cid);
	$ret="<a href=$url class='plink'>".$catetree[$cid][name]."</a>&nbsp;&raquo;&nbsp;".$ret;
	$pid=$catetree[$cid][pid];
	if($pid>0)
	{
		$ret=getPosition($pid,$ret);
	}
	return $ret;
}

function redirect($url){
	    echo "<script language='javascript'>";
	    echo "      location='$url';";
    	    echo "</script>"; 
}

function checkCateAccess($cid){
	global $user_info,$_PlusdB,$catetree,$member;
	if($cid==0 || empty($cid) || $cid=="") return TRUE;
	$mods=$catetree[$cid][mod];
	if(count($mods)==0) return TRUE;
	$mods=$catetree[$cid][mod];
	$ulevel=$user_info[user_level];
	if(in_array($ulevel,$mods)){
		return TRUE;
	}else{
		return FALSE;
}
}

if(!$url) {
	$url = preg_replace("/(?:([\?&]sid\=[a-z0-9]{32}&?))/is", "", $HTTP_SERVER_VARS[HTTP_REFERER]);
	$url = substr($url, -1) == "?" ? substr($url, 0, -1) : $url;
}
// 移动文件
/**
* Document::move_file()
* 
* { Description }
*/
function move_file($s_dir, $d_dir, $filename, $d_filename){ 
        // dir必须用/结尾
        // 建立的文件夹都是0777属性
        mk_dir($d_dir);
        copy($s_dir . $filename, $d_dir . $d_filename);
        @unlink($s_dir . $filename);
        return true;
} 
// 删除文件和目录
/**
* Document::delete_dir()
* 
* { Description }
*/
function delete_dir ($del_path) { // be careful with this.. you could remove your entire site if its pointed to root :)
        // set path to current dir
        $this_path = getcwd();

        if (is_dir($del_path)){ 
                // open dir, read files
                chdir($del_path);
                $handle = opendir('.');
                while (($file = readdir($handle)) !== false){
                        if (($file != ".") && ($file != "..")){
                                if (is_dir($file)){ // do recursive stuff if the "file" is a dir
                                        delete_dir($file . "/");
                                }
                                if (is_file($file)){ // delete all files in the dir
                                        chdir($this_path);
                                        unlink($del_path . $file);
                                        chdir($del_path);
                                }
                        }
                }
                closedir($handle); //close dir
        } 
        // go to where we know
        chdir($this_path); 
        // replace the web path with the dir path and remove the now empty dir
        rmdir(ereg_replace("/", "\\", $del_path));
        return;
} 
function doCheck($s,$text){

			$reNonBlank='/[\S]/';
			$reHexColor='/^#[0-9a-fA-F]{6}$/';
			$reInt='/^\d+$/';
			$reSignedInt='/^(\+|-)?\d+$/';
			$reFloat='/^\d+(\.\d+)?$/';
			$reSignedFloat='/^(\+|-)?\d+(\.\d+)?$/';
			$reChar='/^[\w\-]+$/';
			$reEMail='/^\w[\w\-\.]+\@\w[\w\-]+(\.\w[\w\-]+)+$/';
			$reIP='/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/';
			//$rePostalCA='/^(\w\d){3}$/';
			$reURL='/^http(s)?\:\/\/\w[\w\-]+(\.\w[\w\-]+)+([\/\%\?\&\+\#\.\w\-]+)*$/';
			switch($s){
				case "blank":$pat = $reNonBlank;break;
				case "color":$pat = $reHexColor;break;
				case "int":$pat = $reInt;break;
				case "singleint":$pat = $reSignedInt;break;
				case "float":$pat = $reFloat;break;
				case "singlefload":$pat = $reSignedFloat;break;
				case "char":$pat = $reChar;break;
				case "ip":$pat = $reIP;break;
				case "url":$pat = $reURL;break;
				default:$pat = $reNonBlank;
			}
			if(!preg_match($pat,$text)){
				return FALSE;}
				else{
					return TRUE;
				}
			}


function selCss($cid){
					switch($cid){
	case 12:
	case 8:
	case 13:
	case 16:
	case 37:
	case 14:
	case 15:
		$css="graphics";
		break;
	case 29:
	case 30:
	case 31:
	case 32:
	case 10:
		$css="digitalimage";
		break;
	case 38:
	case 39:
	case 40:
	case 41:
	case 44:
		$css="cg";
		break;
	case 6:
	case 33:
	case 34:
	case 35:
	case 36:
		$css="mutimedia";
		break;
	case 26:
	case 27:
	case 28:
	case 4:
		$css="theoretics";
		break;
	case 9:
	case 17:
	case 18:
	case 19:
	case 20:
		$css="webmedia";
		break;
	case 2:
	case 21:
	case 22:
	case 23:
	case 24:
	case 25:
		$css="comic";
		break;
	default:
	$css="home";
	}	
		return $css;
			}

function SiteInfo(){
	global $PlusDB;
	echo show_button(array("PHPINFO","License",_LANG_0695),array("info.php","admin.php?action=checkLicense","admin.php?module=stats"));

	//内容
	$sql="select count(*) from ".$PlusDB->prefix(articles) ." where 1=1";
	$num=$PlusDB->GetOne($sql);
	echo html_table_header(_LANG_0696,2);
	echo   "<tr class=".form_class()."><td width=\"30%\">&nbsp;"._LANG_0697."</td><td width=\"70%\">&nbsp;$num "._LANG_0698."</td></tr>";
	//章节
	$sql="select count(*) from ".$PlusDB->prefix(contents) ." where 1=1";
	$num=$PlusDB->GetOne($sql);
	echo   "<tr class=".form_class()."><td width=\"30%\">&nbsp;"._LANG_0699."</td><td width=\"70%\">&nbsp;$num "._LANG_0698."</td></tr>";

	//待审核内容
	$sql="select count(*) from ".$PlusDB->prefix(articles) ." where 1=1 and active!='yes' ";
	$num=$PlusDB->GetOne($sql);
	echo      "<tr class=".form_class()."><td width=\"30%\">&nbsp;"._LANG_0700."</td><td width=\"70%\">&nbsp;<a href=admin.php?action=filterArticle&cid=&isactive=no&x=9&y=11>$num "._LANG_0698."</a></td></tr>";
	//附件
	$sql="select count(*) from ".$PlusDB->prefix(attachments) ." where 1=1  ";
	$num=$PlusDB->GetOne($sql);
	echo      "<tr class=".form_class()."><td width=\"30%\">&nbsp;"._LANG_0701."</td><td width=\"70%\">&nbsp;$num </td></tr>";
	//图片
	$sql="select count(*) from ".$PlusDB->prefix(images) ." where 1=1  ";
	$num=$PlusDB->GetOne($sql);
	echo      "<tr class=".form_class()."><td width=\"30%\">&nbsp;"._LANG_0702."</td><td width=\"70%\">&nbsp;$num </td></tr>";
	//订单
	$sql="select count(*) from ".$PlusDB->prefix(cart) ." where 1=1  ";
	$num=$PlusDB->GetOne($sql);
	echo      "<tr class=".form_class()."><td width=\"30%\">&nbsp;"._LANG_0703."</td><td width=\"70%\">&nbsp;<a href=admin.php?module=cart>$num </a></td></tr>";
	//新订单
	$sql="select count(*) from ".$PlusDB->prefix(cart) ." where 1=1 and ispay='no' and isover='no' ";
	$num=$PlusDB->GetOne($sql);
	echo      "<tr class=".form_class()."><td width=\"30%\">&nbsp;"._LANG_0704."</td><td width=\"70%\">&nbsp;<a href=admin.php?module=cart>$num </a></td></tr>";
	//已经付款订单
	$sql="select count(*) from ".$PlusDB->prefix(cart) ." where 1=1 and ispay='yes' and isover='no' ";
	$num=$PlusDB->GetOne($sql);
	echo      "<tr class=".form_class()."><td width=\"30%\">&nbsp;"._LANG_0705."</td><td width=\"70%\">&nbsp;<a href=admin.php?module=cart&ispay=yes&isover=no>$num </a></td></tr>";
	//已经发货订单
	$sql="select count(*) from ".$PlusDB->prefix(cart) ." where 1=1 and ispay='yes' and isover='yes' ";
	$num=$PlusDB->GetOne($sql);
	echo      "<tr class=".form_class()."><td width=\"30%\">&nbsp;"._LANG_0706."</td><td width=\"70%\">&nbsp;<a href=admin.php?module=cart&ispay=yes&isover=no>$num </a></td></tr>";
	echo html_table_footer();
	echo html_table_header(_LANG_0707,2);
	echo      "<tr class=".form_class()."><td width=\"30%\">&nbsp;"._LANG_0708."</td><td width=\"70%\">&nbsp;".getenv("HTTP_ACCEPT_LANGUAGE")."</td></tr>";
	echo      "<tr class=".form_class()."><td width=\"30%\">&nbsp;"._LANG_0709."</td><td width=\"70%\">&nbsp;".getenv("SERVER_NAME")."</td></tr>";
	echo      "<tr class=".form_class()."><td width=\"30%\">&nbsp;"._LANG_0710."</td><td width=\"70%\">&nbsp;".getenv("SERVER_NAME")."</td></tr>";
	echo      "<tr class=".form_class()."><td width=\"30%\">&nbsp;"._LANG_0711."</td><td width=\"70%\">&nbsp;".getenv("HTTP_ACCEPT_LANGUAGE")."</td></tr>";
	echo      "<tr class=".form_class()."><td width=\"30%\">&nbsp;"._LANG_0712."</td><td width=\"70%\">&nbsp;".getenv("SERVER_PORT")."</td></tr>";
	echo      "<tr class=".form_class()."><td width=\"30%\">&nbsp;"._LANG_0713."</td><td width=\"70%\">&nbsp;".PHP_OS."</td></tr>";
	echo      "<tr class=".form_class()."><td width=\"30%\">&nbsp;"._LANG_0714."</td><td width=\"70%\">&nbsp;".date(_DATA,time())."</td></tr>";
	echo      "<tr class=".form_class()."><td width=\"30%\">&nbsp;"._LANG_0715."</td><td width=\"70%\">&nbsp;".getenv("SERVER_SOFTWARE")."</td></tr>";
	echo      "<tr class=".form_class()."><td width=\"30%\">&nbsp;"._LANG_0716."</td><td width=\"70%\">&nbsp;".getenv("server_protocol")."</td></tr>";
	echo      "<tr class=".form_class()."><td width=\"30%\">&nbsp;"._LANG_0717."</td><td width=\"70%\">&nbsp;".intval(diskfreespace(".") / (1024 * 1024)).'Mb'."</td></tr>";
	echo html_table_footer();
}

function getTopId($cid){
		global $catetree;
		$pid = $catetree[$cid][pid];
		if($pid>0){
			$pid = getTopId($pid);
			return $pid;
		}else{
			return $cid;	
	}
}

function getUpIds($cid,$ret=""){
		global $catetree;
		$ret[]=$cid;
		$pid = $catetree[$cid][pid];
		if($pid>0){
			$ret = getUpIds($pid,$ret);
		}else{
			$ret[]=0;
	}
				return $ret;	
}

	function adminTabMenu($items,$thisitem,$bg='#ffffff',$hi='#336699',$font1='#000000',$font2='#ffffff'){
		echo "<table width=\"100%\"  border=\"0\" align=center cellpadding=0 cellspacing=0 height=20 id=\"editnav\"><tr>";
	foreach($items as $title=>$url){
		if($thisitem==$title){
			$abg = $hi;
			$font = $font2;
		}else{
			$abg = $bg;
			$font = $font1;
		}
		echo "<td bgcolor=$abg align=center nowrap>&nbsp;&nbsp;&nbsp;<a href='$url'><font color=$font>$title</font></a>&nbsp;&nbsp;&nbsp;</td>";
	}
		echo "<td width=100%></td></tr></table>";
	}

function filtertxt($msg){
	if(!get_magic_quotes_gpc()){
	include_once "include/big5_func.inc";
	$msg=big5_addslashes($msg);
	}else{
	$msg=$msg;
	}
	return $msg;
}

function adminNav($vars){
	global $PlusDB;
	$module=$vars["module"];
	$action = $vars["action"];
	switch($module){
		//购物车
		case "cart":
			$ret=""._LANG_1110."&nbsp;&raquo;&nbsp;<a href=admin.php?module=cart>"._LANG_1169."</a>&nbsp;&raquo;&nbsp;";
			switch($action){
				case "viewOrder": 
				$ret.=""._LANG_1111."&nbsp;&raquo;&nbsp;";
				$oid=$vars[oid];
				$sql="select * from ".$PlusDB->prefix("cart")." where id='$oid'";
				$row=$PlusDB->GetRow($sql);
				//trace($row);
				$ret.=$row["oid"];
				break;
			}
			break;
		case "fetch":
			$ret="<a href=admin.php?module=fetch>"._LANG_1112."</a>&nbsp;&raquo;&nbsp;";
		switch($action){
				case "addSite": $ret.=""._LANG_1113."&nbsp;&raquo;&nbsp;";break;
				case "editFetchSite": $ret.=""._LANG_1114."&nbsp;&raquo;&nbsp;";break;
				default: $ret.=""._LANG_1115."&nbsp;&raquo;&nbsp;";
			}
			break;
			//访问统计
		case "stats":
			$ret=""._LANG_1116."&nbsp;&raquo;&nbsp;";
			switch($action){
				case "last": $ret.=""._LANG_1117."&nbsp;&raquo;&nbsp;";break;
				case "ref": $ret.=""._LANG_1118."&nbsp;&raquo;&nbsp;";break;
				case "ip": $ret.=""._LANG_1119."&nbsp;&raquo;&nbsp;";break;
				case "bro": $ret.=""._LANG_1120."&nbsp;&raquo;&nbsp;";break;
				default: $ret.=""._LANG_1121."&nbsp;&raquo;&nbsp;";
			}
		break;
		case "link": $ret.=""._LANG_1122."&nbsp;&raquo;&nbsp;";break;
		//广告管理
		case "ad":
			$ret="<a href=admin.php?module=ad>"._LANG_1123."</a>&nbsp;&raquo;&nbsp;";
			switch($action){
				case "addAd": $ret.=""._LANG_1124."&nbsp;&raquo;&nbsp;";break;
				case "editAd": $ret.=""._LANG_1125."&nbsp;&raquo;&nbsp;";break;
				default: $ret.=""._LANG_1126."&nbsp;&raquo;&nbsp;";
			}
			break;
		//模板编辑
		case "template":
			$ret="<a href=admin.php?module=template>"._LANG_1127."</a>&nbsp;&raquo;&nbsp;";
			$t_path = $vars["t_path"];
			$ret.=$t_path;
			if($action=="edit") $ret.=_LANG_1128;
		break;
		//自定义内容
		case "blocks":
			$ret = "<a href=admin.php?module=blocks>"._LANG_1129."</a>&nbsp;&raquo;&nbsp;";
				switch($action){
				case "viewBlock": $ret.=""._LANG_1130."&nbsp;&raquo;&nbsp;";break;
				case "editBlock": $ret.=""._LANG_1131."&nbsp;&raquo;&nbsp;";break;
				default: $ret.=""._LANG_1132."&nbsp;&raquo;&nbsp;";
			}
			break;
		//投票
		case "poll":
			$ret="<a href=admin.php?module=poll>"._LANG_1133."</a>&nbsp;&raquo;&nbsp;";
			switch($action){
				case "addPoll": $ret.=""._LANG_1134."&nbsp;&raquo;&nbsp;";break;
				case "addOption":
					$ret.=""._LANG_1135."&nbsp;&raquo;&nbsp;";
					$pid = $vars[pid];
					$row=$PlusDB->GetRow("select title from ".$PlusDB->prefix(poll)." where id='$pid'");
					$ret.=$row[title]."&nbsp;&raquo;&nbsp;";
				break;
				case "editPoll":
					$ret.=""._LANG_1136."&nbsp;&raquo;&nbsp;";
					$pid = $vars[pid];
					$row=$PlusDB->GetRow("select title from ".$PlusDB->prefix(poll)." where id='$pid'");
					$ret.=$row[title]."&nbsp;&raquo;&nbsp;";
				break;
				default: $ret.=""._LANG_1137."&nbsp;&raquo;&nbsp;";
			}
			break;
			case "member":
				$ret="<A HREF=\"admin.php?module=member\">"._LANG_1138."</A> &nbsp;&raquo;&nbsp;";
				switch($action){
				case "addMember": $ret.=""._LANG_1139."&nbsp;&raquo;&nbsp;";break;
				case "adminEditMember": $ret.=""._LANG_1140."&nbsp;&raquo;&nbsp;";break;
				case "filterMember": $ret.=""._LANG_1141."&nbsp;&raquo;&nbsp;";break;
				default: $ret.=""._LANG_1142."&nbsp;&raquo;&nbsp;";
			}
			break;
			default:
			   $ret="";
				switch($action){
					case "filterArticle":
						$ret = ""._LANG_1143." &nbsp;&raquo;&nbsp;";
					break;
					case "listCategory":
						$ret = ""._LANG_1144." &nbsp;&raquo;&nbsp;";
					break;
					case "addCategory":
						$ret = ""._LANG_1145." &nbsp;&raquo;&nbsp;";
					break;
					case "selectCate":
						$ret = ""._LANG_1146." &nbsp;&raquo;&nbsp;";
					break;
					case "addArticle":
						$ret = ""._LANG_1147." &nbsp;&raquo;&nbsp;";
					break;
					case "addCh":
						$ret = ""._LANG_1148." &nbsp;&raquo;&nbsp;";
					break;
					case "chapterList":
						$ret = ""._LANG_1149." &nbsp;&raquo;&nbsp;";
					break;
					case "image":
						$ret = ""._LANG_1150." &nbsp;&raquo;&nbsp;";
					break;
					case "attach":
						$ret = ""._LANG_1151." &nbsp;&raquo;&nbsp;";
					break;
					case "editAttach":
						$ret = ""._LANG_1152." &nbsp;&raquo;&nbsp;";
					break;

					case "listTopic":
						$ret = ""._LANG_1153." &nbsp;&raquo;&nbsp;";
					break;
					case "editTopic":
						$ret = ""._LANG_1154." &nbsp;&raquo;&nbsp;";
					break;
					case "listTopicContent":
						$ret = ""._LANG_1155." &nbsp;&raquo;&nbsp;";
					break;
					case "addTopic":
						$ret = ""._LANG_1156." &nbsp;&raquo;&nbsp;";
					break;
					case "listKeyword":
						$ret = ""._LANG_1157." &nbsp;&raquo;&nbsp;";
					break;
					case "addKeyword":
						$ret = ""._LANG_1158." &nbsp;&raquo;&nbsp;";
					break;

					case "editKeyword":
						$ret = ""._LANG_1159." &nbsp;&raquo;&nbsp;";
					break;
					case "listKeywordContent":
						$ret = ""._LANG_1160." &nbsp;&raquo;&nbsp;";
					break;
					case "listConf":
						$ret = ""._LANG_1161." &nbsp;&raquo;&nbsp;";
					break;
					case "outPut":
						$ret = ""._LANG_1162." &nbsp;&raquo;&nbsp;";
					break;
					case "outOneCate":
						$ret = ""._LANG_1163." &nbsp;&raquo;&nbsp;";
					break;
					case "addKeyword":
						$ret = ""._LANG_1164." &nbsp;&raquo;&nbsp;";
					break;
					case "editCategory":
						$ret = ""._LANG_1165." &nbsp;&raquo;&nbsp;";
					break;
					case "listArticle":
						$ret = ""._LANG_1166." &nbsp;&raquo;&nbsp;";
					break;
					case "editArticle":
						$ret = ""._LANG_1167." &nbsp;&raquo;&nbsp;";
					break;
					case "siteInfo":
						$ret = ""._LANG_1168." &nbsp;&raquo;&nbsp;";
					break;
			}
			//echo $ret;
				$cid=$vars["cid"];
				$aid = $vars["aid"];
				$chid = $vars["chid"];
                if(is_numeric($cid)){
                	$ret.= get_cate_path($cid);
               	}elseif(is_numeric($aid)){
               		$sql="select title,cid from ".$PlusDB->prefix("articles")." where id='$aid'";
               		$row=$PlusDB->GetRow($sql);
					//trace($row);
                		$ret.= get_cate_path($row["cid"]);
                		$ret.= "<a href=admin.php?action=editArticle&aid=$aid>$row[title]</a>&nbsp;&raquo;&nbsp; ";    		
              	}elseif(is_numeric($chid)){
              		$sql="select a.id as aid,a.title,a.cid from ".$PlusDB->prefix('articles')." a left join  ".$PlusDB->prefix(contents)." c on (c.aid=a.id)  where c.id='$chid'";
              		$row=$PlusDB->GetRow($sql);
                		$ret.= get_cate_path($row[cid]);         
                		$ret.= "<a href=admin.php?action=editArticle&aid=$row[aid]>$row[title]</a>&nbsp;&raquo;&nbsp; ";    		
              	}
	}
		return $ret;
}
function keywordText($text){
global $art;
$keyword = $art->getKeyword();
if(count($keyword) > 0){
        foreach($keyword as $key => $value){
                $search_array[] = '/(>?[^>^<]*)('.$value.')([^>^<]*<)/i';
                $replace_array[] = "\\1<a href=\"".PLUS_URL."/index.php?action=listKeywordC&kid=$key\" target=\"_blank\" title=\"$value\"><u>$value</u></a>\\3";
				//$replace_array[] = "ddddddddddd";
        }
        $text = preg_replace($search_array,$replace_array, $text, 1);
}
return $text;
}

function delThePoint($aid,$atid,$point){
	global $user_info,$PlusDB;
	$udb =$PlusDB->prefix("user_extra");
	$ldb = $PlusDB->prefix("user_log");
	$ulevel = $user_info[user_level];
	$uid = $user_info[user_id];
	if($ulevel == "Guest"){
		echo "请先登陆";
		exit;
	}else{
		$sql="select point from 	$udb where id='$uid' ";
		$points = $PlusDB->GetOne($sql);
		if($points<$point){
			echo "你的点数不足,请进行冲值！";
			return FALSE;
		}else{
		//检查此用户24小时内是否消费过
		$sql="select UNIX_TIMESTAMP(ctime) from $ldb where uid='$uid' and aid='$aid' and atid='$atid'";
		$lasttime = $PlusDB->GetOne($sql);
		if($lasttime && $lasttime >(time()-24*60*60)){
				return TRUE;
		}
		$sql="update $udb set point=point-$point where id='$uid' ";
		if($PlusDB->query($sql)){
			$now=date("Y-m-d H:i:s");
			$sql="insert into $ldb (aid,atid,uid,ctime,point) values ('$aid','$atid','$uid','$now','$point')";
			$PlusDB->query($sql);
			return TRUE;	
		}else{
			echo "无法成功扣除点数，请和管理员联系!";	
			return FALSE;
	}
	}
}
}
class member_ini{
	/*密码处理函数*/
	function passwordProcess($password,$ctype="normal"){
		//if(strlen($password)>10 || strlen($password)<3) error("密码长度不能超过10字节或者小于3字节");
		switch($ctype){
		case "md5":
			$pass = md5($password);
			break;
		case "base64":
			$pass = base64_encode($password);
			break;
		default:
			$pass=$password;
		}
		return $pass;
	}
}

function makeSec($text){
	$color="#ffffff";
	$hans=array("abc","123","ilove2");
	//$num=count($hans);
	//$id=ceil(rand(0,$num-1));
	$text = preg_replace('/\r/ie','make_pass(5,5,$color)',$text);
	return $text;
}

function thumb_image_netpbm($src, $dest, $quality, $size, $image_info){
	global $gallery_conf;
        $convert_path = $gallery_conf[netpbm_path];
        $dims = explode("x", $size);
        $width = $dims[0];
        $height = $dims[1];

        $types = array(1 => "gif", 2 => "jpeg", 3 => "png");
        $target = ($width > $height) ? $width : $height;
        $command = $convert_path . "/" . check_executable($types[$image_info[2]] . "topnm") . " " . $src . " | " . $convert_path . "/" . check_executable("pnmscale") . " --quiet -xysize " . $target . " " . $target . " | ";
        if ($image_info[2] == 1){
                $command .= $convert_path . "/" . check_executable("ppmquant") . " 256 | " . $convert_path . "/" . check_executable("ppmtogif") . " > " . $dest;
        }elseif ($image_info[2] == 3){
                $command .= $convert_path . "/" . check_executable("pnmtopng") . " > " . $dest;
        }else{
                $jpeg_exec = (file_exists($convert_path . "/" . check_executable("pnmtojpeg"))) ? check_executable("pnmtojpeg") : check_executable("ppmtojpeg");
                $command .= $convert_path . "/" . $jpeg_exec . " --quality=" . $quality . " > " . $dest;
        }
        //echo $command;
        system($command);
        return (file_exists($dest)) ? 1 : 0;
}
function check_executable($file_name){
        if (substr(PHP_OS, 0, 3) == "WIN" && !eregi("\.exe$", $file_name)){
                $file_name .= ".exe";
        }elseif (substr(PHP_OS, 0, 3) != "WIN"){
                $file_name = eregi_replace("\.exe$", "", $file_name);
        }
        return $file_name;
}
	function make_pass($min, $max,$color){
	$length = mt_rand($min, $max);
	$deck = array_merge (
	        range("0", "9"),
	        range("a", "z"),
	        range("A", "Z")
	        );
		for($i = 0; $i < $length; $i++){
			$shuffle = mt_rand(0, sizeof($deck)-1);
			$pass .= $deck[$shuffle];
		}
		$pass="<font color=$color>$pass</font>\r";
		return $pass;
}

function msubstr($str, $start, $len)
{
	$str=trim($str);
    $strlen = $start + $len;
    for($z = $start;$z < $strlen;$z++) {
        if (ord(substr($str, $z, 1)) > 0xa0) {
            $tmpstr .= substr($str, $z, 2);
            $z++;
        } else
            $tmpstr .= substr($str, $z, 1);
    } 
    return $tmpstr;
} 
function getOneCate($cid){
global $PlusDB;
$cdb=$PlusDB->prefix(category);
$sql="select * from $cdb where id='$cid'";
return $PlusDB->getrow($sql);
}
?>