<?php
	//////////////////////////////////////////////
	/////         叮咚网版权所有             /////
	/////         QQ 2207134109              /////
	//////////////////////////////////////////////
	/*
	此函数集合主要功能是解析网站的UBB代码
	此函数几乎覆盖整个用户可自定义的界面，所以请不要随意修改此页面内容
	在二次开发本程序时请注意不要与本页函数名字重合，否则会导致系统无法正常运行
	此功能是本站的核心功能之一
	*/
	function url_info_zm($url,$type){
		if($url == NULL){
		$url=$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
		}
			if($type==1){
		$back = preg_replace('/\&/','%',$url);
			}else{
		$back = preg_replace('/\%/','&',$url);
			}
		return $back;
		}
	//获取HTML栏目内容
	function dmfun($c1,$b1,$z1,$w1){
	$sql="SELECT {$c1},{$b1} FROM html WHERE htmlid='{$z1}' AND siteid='{$w1}'";
	@$view = mysql_query($sql);
	if($view && mysql_num_rows($view)>0){
	list($c2,$b2) = mysql_fetch_row($view);
	$xs=htmlspecialchars_decode($b2,ENT_QUOTES);
	}else{
	$xs='';
	}
	return $xs;
	}

	//处理随机数据
	function getRandStr($str){
		$arr = explode('|',$str);
		$rand = $arr[array_rand($arr)];
	return $rand;
	}
	function brStr($str){
		$brStr = str_replace('<br>','</li><li>',$str);
		$brStr = str_replace('<br/>','</li><li>',$brStr);
		return $brStr;
	}
	//返回链接函数
	function back($wapid){
		if($_GET['cid']==NULL || $_GET['cid']==0){
		$back='http://'.$_SERVER["HTTP_HOST"].'/index.php?cid=0&sid='.$GLOBALS['sid_info'];
		}else{
			$sql = "SELECT cid,siteid,gro FROM class WHERE siteid='{$wapid}' AND cid='{$_GET['cid']}'";
			@$result = mysql_query($sql);
			if($result && mysql_num_rows($result) > 0){
				list($cid,$siteid,$gro) = mysql_fetch_row($result);
				$back='http://'.$_SERVER["HTTP_HOST"].'/index.php?cid='.$gro.'&sid='.$GLOBALS['sid_info'];
			}
		}
		return $back;
	}
	function js($x){
		$js="var z".$x." = null;sw('z".$x."','cb2');";
		return $js;
	}
	//当前栏目位置导航
	/*导航_当前位置*/
	function class_info($cid,$str,$wapid){

		$sql="SELECT cid,{$str} FROM class WHERE siteid='{$wapid}' AND cid='{$cid}'";
		$result = mysql_query($sql);
		list($cid,$str) = mysql_fetch_row($result);
			if($str=='cn'){
			if($cid==0||$cid==NULL||$cid==''){
				$sql = "SELECT id,stitle FROM user WHERE id='{$wapid}'";
				$result = mysql_query($sql);
				list($wapid,$stitle) = mysql_fetch_row($result);
				$str = $stitle;
				mysql_free_result($result);
			}
		}
		return $str;
	}

	function nav_bar($str,$wapid){
		$class_nav=$str;
		$i=0;
		if($str==0){
			$html2 = NULL;
		}else{
			while($class_nav> 0){
				$html[$i].='<a href="http://'.$_SERVER["HTTP_HOST"].'/index.php?cid='.$class_nav.'">'.class_info($class_nav,"cn",$wapid).'</a>';
				$class_nav = class_info($class_nav,'gro',$wapid);
				$i++;
			}
		end($html);
		$key=key($html);
			for($i=$key;$i>=0;$i--){
				$html2.=$html[$i];
			}
	if($html2!=NULL&&$html2!=''){
			$html2='<a href="http://'.$_SERVER["HTTP_HOST"].'/index.php?sid='.$GLOBALS['sid_info'].'">首页</a>'.$html2;
		}
	}
	return $html2;
	}
	
	function RunUbb($content,$wapid){
	//全局引用变量
	$ver   = $GLOBALS['ver'];
	//$wapid = $GLOBALS['wapid'];
	if($ver==2||$ver==0){
	$wap2='\\1';
	}else{
	$wap2='';
	}
	if($ver==3){
	$wap3='\\1';
	}else{
	$wap3='';
	}if($ver==5){
	$wap5='\\1';
	}else{
	$wap5='';
	}
	//登录面板初始化
	$login = $GLOBALS['login'];
	if($login==1){
	$c='\\1';
	$w='';
	}else{
	$c='';
	$w='\\1';
	}
	//未读短信
	$sql="SELECT count(*) FROM message WHERE toid='".$id."' AND ifread='NULL'";
	@$result=mysql_query($sql);
	@list($num)=mysql_fetch_row($result);

	//未读消息为空则不提示
	if($num == 0){
	$nums = NULL;
	}else{
	$nums = $num;
	}
	//返回上级页面
	$back = back($wapid);
	if($login == 1){
	$bar = '<a href="http://'.$_SERVER["HTTP_HOST"].'/user/myfriend.php?">'.$GLOBALS['nc'].'</a>.<a href="http://'.$_SERVER['HTTP_HOST'].'/user/zone.php?">空间</a>.
	<a href="http://'.$_SERVER["HTTP_HOST"].'/message/sjx.php?">短信'.$nums.'</a>';
	}else{
	$bar = '<a href="http://'.$_SERVER["HTTP_HOST"].'/login.php?">登录</a>.<a href="http://'.$_SERVER["HTTP_HOST"].'/reg.php?">注册</a>后体验更多精彩';
	}
	//系统报时初始化
	$timeubb = date("Y-m-d-H-i");
	//获得分辨率宽度
	$width .= "<script language=\"javascript\">";
	$width .= "document.write(window.screen.width);";
	$width .= "</script>";
	//获得分辨率高度
	$height .= "<script language=\"javascript\">";
	$height .= "document.write(window.screen.height);";
	$height .= "</script>";
	//获得分辨率宽度
	$width2.="<script language=\"javascript\">";
	$width2.="document.write(document.body.clientwidth);";
	$width2.="</script>";
	//获得分辨率高度
	$height2.="<script language=\"javascript\">";
	$height2.="document.write(document.body.clientheight);";
	$height2.="</script>";

	//百度搜索初始化
	$baidu = '<form action="ssid=0/from=0/bd_page_type=1/uid=0/baiduid=73D00B7CEDB8F65603D06E5EDBA3EA38/s" method="get"><input type="text" name="word" maxlength="64" size="20" id="word"/><br><input type="hidden" value="upssntdnvelami" name="uc_param_str"/><input type="hidden" value="ib" name="sa"/><input type="hidden" value="111041" name="st_1"/><input type="hidden" value="102041" name="st_2"/><input type="hidden" value="ta@middle____,sz@176_220" name="pu"/><input type="hidden" name="idx" value="20000"/><input type="hidden" value="middle" name="tn_1"/><input type="hidden" value="middle" name="tn_2"/><input type="submit" value="搜网页" name="ct_1"/>&nbsp;<input type="submit" value="搜Wap" name="ct_2"/></form>';
	//
	$admin=$GLOBALS['admin'];
	if($admin==1||$admin==2){
	$ht='<a href="admin/wap_admin.php?">【管理后台】</a>';
	}else{
	$ht='';
	}
	//版本UBB区别
	if($ver==1){
	$div1='\\2<br>';
	$div2='\\2<br>';

	}else{
	$div1='<div class="\\1">\\2</div>';
	$div2='<div class="\\2">\\3</div>';
	}
	//执行UBB解析功能
	$ubb = array(
		'/\/\/\//',
		'/\[h1\](.+?)\[\/h1\]/si','/\[h2\](.+?)\[\/h2\]/si','/\[h3\](.+?)\[\/h3\]/si',
		'/\[hr\]/','/\[br\]/','/\[b\]/','/\[\/b\]/',
		'/\[div=([0-9a-zA-Z\_]*)\](.+?)?\[\/div\]/',
		'/\[div([0-9]*)=([0-9a-zA-Z]*)\](.+?)\[\/div\\1\]/',
		'/\[img\](.+?)\[\/img\]/',
		'/\[img\|([0-9]*)\*([0-9]*)\](.+?)\[\/img\]/',
		'/\[sid\]/',
		'/\[cid\]/',
		'/\[sid1\]/' ,
		'/\[url=(.+?)\](.+?)\[\/url\]/',
		'/\[table\](.+?)\[\/table\]/',
		'/\[table\=(.+?)\](.+?)\[\/table\]/',
		'/\[tr\](.+?)\[\/tr\]/',
		'/\[td\](.+?)\[\/td\]/',
		'/\[td\=(.+?)\](.+?)\[\/td\]/',
		'/\[td\]\[\/td\]/',
		'/\[\/td\]\[td\]/',
		'/\[index\](.+?)\[\/index\]/',
		'/\[back\](.+?)\[\/back\]/',
		'/\[topbar\]/',
		'/\[(article|bbs|sitelink|download|link)\=([0-9a-zA-Z\|]*)\_(.+?)\_(.+?)\_(.+?)\_(.+?)\]/e',
		'/\[time\]/',
		'/\[class=([0-9]*)\](.+?)\[\/class\]/',
		'/\[baidus\]/ ',
		'/\[ul=(.+?)\]\[li\](.+?)?\[\/li\]\[\/ul\]/e',
		'/\[ul=(.+?)\]/','/\[\/ul\]/',
		'/\[message\]/',
		'/\[js\](.+?)\[\/js\]/',
		'/\[css\](.+?)\[\/css\]/',
		'/\[login\](.+?)\[\/login\]/',
		'/\[nologin\](.+?)\[\/nologin\]/',
		'/\[width\]/','/\[height\]/',
		'/\[width2\]/','/\[height2\]/',
		'/\[gethtml\=(.+?)\]/e',
		'/\[admin\]/',
		'/\[localhost\]/',
		'/\[nav\]/',
		'/\[wap2\](.*)\[\/wap2\]/si','/\[wap3\](.*)\[\/wap3\]/si','/\[wap5\](.*)\[\/wap5\]/si',
		'/\[online\]/',
		'/\[rand\](.+?)\[\/rand\]/ei',
		'/\[floattop\]/',
		'/\[music\](.+?)\[\/music\]/'
	);
	$html = array(
		'<br>',
		'<h1>\\1</h1>','<h2>\\1</h2>','<h3>\\1</h3>',
		'<hr>','<br>','<b>','</b>',
		$div1,$div2,
		'<img src="\\1"  align="absmiddle" >',
		'<img src="\\3" style="width:\\1px;height:\\2px;"  align="absmiddle" />',
		$_GET['sid'],
		$_GET['cid'],
		$sid1,
		'<a href="\\1">\\2</a>',
		'<table border="0" cellpadding="0" cellspacing="0">
		\\1
		</table>',
		'<table class="\\1" border="0" cellpadding="0" cellspacing="0">
		\\2
		</table>',
		'<tr>
		\\1
		</tr>',
		'<td>
		\\1
		</td>',
		'<td class="\\1">
		\\2
		</td>',
		'<td>
		</td>',
		'</td>
		<td>',
		'<a href="http://'.$_SERVER["HTTP_HOST"].'/index.php?">\\1</a>',
		'<a href="'.$back.'">\\1</a>',
		$bar,
		'main_list_fun($wapid,"\1","\2","\3","\4","\5","\6",NULL)',
		$timeubb,
		'<a href="http://'.$_SERVER["HTTP_HOST"].'/index.php?cid=\\1">\\2</a>',
		$baidu,
		'<ul class="$1"><li>brStr("$2")</li></ul>',
		'<ul class="\\1">',
		'</ul>',
		NoReadMess($GLOBALS['id'],'ask_1'),
		'<script src="\\1" type="text/javascript"></script>',
		'<link href="\\1" rel="stylesheet" type="text/css" />',
		$c,$w,
		$width,$height,
		$width2,$height2,
		'dmfun(\'htmlid\',\'content\',$1,'.$wapid.')',
		$ht,
		$_SERVER["HTTP_HOST"],
		nav_bar($_GET['cid'],$wapid),
		$wap2,$wap3,$wap5,
		$GLOBALS['user_online_wapall'],
		'getRandStr(\'$1\')',
		'<span style="border-radius:1px;padding:0px;position:fixed;right:1em;bottom:1.5em;border:0px solid #F5F5F5;font:1.5em;  border:0;clear:both;
"><a href="#"><img src="http://'.$_SERVER['HTTP_HOST'].'/style/blacktop.png" alt="."/></a></span>',
		'<bgsound src="\\1" loop="-1">'
	);
		$content = preg_replace($ubb,$html,$content);
		return $content;
	}
	//执行两次UBB转换程序，转换遗漏的UBB代码。
	function UBB($content,$wapid){
		$backRun  =  RunUbb($content,$wapid);
		$backHtml =  RunUbb($backRun,$wapid);
	return $backHtml;
	}
	?>