<?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | PHP version 5                                                        |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2004 The PHP Group                                |
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.0 of the PHP license,       |
// | that is bundled with this package in the file LICENSE, and is        |
// | available through the world-wide-web at the following url:           |
// | http://www.php.net/license/3_0.txt.                                  |
// | If you did not receive a copy of the PHP license and are unable to   |
// | obtain it through the world-wide-web, please send a note to          |
// | license@php.net so we can mail you a copy immediately.               |
// +----------------------------------------------------------------------+
// | Authors: Original Author <author@example.com>                        |
// |          Your Name <you@example.com>                                 |
// +----------------------------------------------------------------------+
//
// $Id:$

function get_sql_list($s1, $s2, $s3, $s4, $s5, $s6)
{
    $getlist = new sqllist;
    return $getlist->get_sql_list($s1, $s2, $s3, $s4, $s5, $s6);
}
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 = WAPID;
    $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 admins($str=null){
		$admin = $GLOBALS['admin'];
		if ($admin == 1 || $admin == 2) {
			if($str == null){
				return '<a href="http://' . $_SERVER['HTTP_HOST'] . '/admin/wap_admin.php?">【管理后台】</a>';
			}
			return $str;
		}
		return null;
	}
function dd_html($title) {
    $w1 = WAPID;
    $sql = "SELECT content FROM dd_html WHERE title='{$title}' AND siteid='{$w1}'";
    @$view = mysql_query($sql);
    if ($view && mysql_num_rows($view) > 0) {
        list($content) = mysql_fetch_row($view);
        $xs = htmlspecialchars_decode($content, 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/>', '<br>', $str);
    $brStr = explode('<br>', $brStr);
    $brStr = implode("</li>\n<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 piclf($width, $height, $picstr, $urlstr) {
    $pic = explode('|', $picstr);
    $p = 0;
    foreach ($pic as $value) {
        $pic2[] = '<img src="' . $value . '" alt="Loding..." style="height:' . $height . ';width:' . $width . ';">';
        $p++;
    }
    $url = explode('|', $urlstr);
    $v = 0;
    foreach ($url as $value2) {
        $url2.= '<li><a href="' . $value2 . '">' . $pic2[$v] . '</a></li>';
        $v++;
    }
    if ($p != $v) {
        return '-= 语法错误，"|"号匹配不上! =-';
    }
    $max = $width * count($pic);
    for ($i = 0; $i < count($pic); $i++) {
        $line.= '<li>●</li>';
    }
    $str = '<div class="tupian"><style type="text/css"> .container103, .container103 *{margin:0; padding:0;}.container103{width:320px; height:150px; overflow:hidden;position:relative;}.slider{position:absolute;}.slider li{ list-style:none;display:inline;}.slider img{ width:' . $width . 'px; height:' . $height . 'px; display:block;}.slider3{width:' . $max . 'px;}.slider3 li{float:left;}.numline{ position:absolute; right:140px; bottom:13px;}.numline li{float: left; color: #FF7300; text-align: center; line-height: 16px; width: 10px; height: 16px; font-family: Arial; font-size: 12px; cursor: pointer; overflow: hidden; margin: 3px 1px; border: 0px solid #FF7300; }.numline li.on{ color: #1CA7E1; line-height: 21px; width: 10px; height: 21px; font-size: 16px; margin: 0 1px; border: 0;font-weight: bold;}</style><div class="container103" id="idTransformView3"> <ul class="slider slider3" id="idSlider3">' . $url2 . '
</ul><ul class="numline" id="idNum3">' . $line . '</ul></div><input type="hidden" id="KL_COUNT3" value="' . count($pic) . '"><input type="hidden" id="KL_COUNT_WITH3" value="' . $width . '"></div>
<script type="text/javascript" src="http://' . HTTP_HOST . '/style/js/piclf.js"></script>';
    return $str;
}
function vershow($ver, $str) {
    if (VER == $ver) {
        return $str;
    }
    return NULL;
}
function RunUbb($content, $wapid) {
    //登录面板初始化
    $login = $GLOBALS['login'];
    if ($login == 1) {
        $c = '\\1';
        $w = NULL;
    } else {
        $c = NULL;
        $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"] . '/user/message/list.php?">短信' . NoReadMessNums($GLOBALS['id']) . '</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>';
    //版本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(
        '/\[ver=([0-9]*)\](.+?)\[\/ver\]/ies',
        '/\[thisurl\]/',
        '/\/\/\//',
        '/\[qq=([0-9]*)_([0-9]*)\](.+?)\[\/qq\]/is',
        '/\[nickname\]/',
        '/\[myid\]/',
        '/\[crevalue\]/',
        '/\[span\](.+?)\[\/span\]/is',
        '/\[p\](.+?)\[\/p\]/is',
        '/\[center\](.+?)\[\/center\]/is',
        '/\[h1\](.+?)\[\/h1\]/si',
        '/\[h2\](.+?)\[\/h2\]/si',
        '/\[h3\](.+?)\[\/h3\]/si',
        '/\[color\=(.+?)\](.+?)\[\/color\]/si',
        '/\[size=(.+?)\](.+?)\[\/size\]/si',
        '/\[fly\](.+?)\[\/fly\]/si',
        '/\[hr\]/',
        '/\[br\]/',
        '/\[b\](.+?)\[\/b\]/si',
        '/\[div=([0-9a-zA-Z\_]*)\](.+?)?\[\/div\]/si',
        '/\[div([0-9]*)=([0-9a-zA-Z]*)\](.+?)\[\/div\\1\]/si',
        '/\[img\](.+?)\[\/img\]/',
        '/\[img\|([0-9]*)\*([0-9]*)\](.+?)\[\/img\]/si',
        '/\[sid\]/si',
        '/\[cid\]/',
        '/\[sid1\]/',
        '/\[hot=([a-zA-Z]*)_([0-9]*)\](.+?)\[\/hot\]/i',
        '/\[new=([a-zA-Z]*)_([0-9]*)\](.+?)\[\/new\]/i',
        '/\[good=([a-zA-Z]*)_([0-9]*)\](.+?)\[\/good\]/i',
        '/\[url=(.+?)\](.+?)\[\/url\]/',
        '/\[url\](.+?)\[\/url\]/',
        '/\[table\](.+?)\[\/table\]/si',
        '/\[table=(.+?)\](.+?)\[\/table\]/si',
        '/\[tr\](.+?)\[\/tr\]/si',
        '/\[td\](.+?)\[\/td\]/si',
        '/\[td=(.+?)\](.+?)\[\/td\]/si',
        '/\[td\]\[\/td\]/si',
        '/\[\/td\]\[td\]/si',
        '/\[index\](.+?)\[\/index\]/si',
        '/\[back\](.+?)\[\/back\]/si',
        '/\[topbar\]/si',
        '/\[(article|bbs|sitelink|download|link|chat)=([0-9a-zA-Z\|]*)\_(.+?)\_(.+?)\_(.+?)\_(.+?)\]/sie',
		'/\[loop\]\s*(.+?)?\s*\[show=(.+?)\]\s*(.+?)?\s*\[\/loop\]/',
        '/\[time\]/',
        '/\[class=([0-9]*)\](.+?)\[\/class\]/si',
        '/\[baidus\]/',
        '/\[form=(.+?)\|(.+?)\](.+?)\[\/form\]/is',
        '/\[input=(.+?)\|(.+?)\](.+?)\[\/input\]/is',
        '/\[sel=(.+?)\](.+?)\[\/sel]/is',
        '/\[option=(.+?)\](.+?)\[\/option\]/is',
        '/\[ul=(.+?)\]/',
        '/\[\/ul\]/',
        '/\[uli=(.+?)\](.+?)\[\/uli\]/sie',
        '/\[ul\]\[li\](.+?)\[\/li\]\[\/ul\]/sie',
        '/\[li\]/is',
        '/\[\/li\]/is',
        '/\[message\]/',
        '/\[js\](.+?)\[\/js\]/',
        '/\[css\](.+?)\[\/css\]/',
        '/\[login\](.+?)\[\/login\]/si',
        '/\[nologin\](.+?)\[\/nologin\]/',
        '/\[width\]/',
        '/\[height\]/si',
        '/\[width2\]/',
        '/\[height2\]/si',
        '/\[gethtml\=(.+?)\]/sie',
		'/\[\$dd_(.+?)\]/sie',
        '/\[admin\]/sie',
		'/\[admins\](.+?)\[\/admins\]/sie',
        '/\[localhost\]/',
        '/\[nav\]/',
        '/\[online\]/',
        '/\[rand\](.+?)\[\/rand\]/eis',
        '/\[floattop\]/',
        '/\[music\](.+?)\[\/music\]/si',
        '/\[piclf\=(.+?)\](.+?)\[\/piclf\]/sie',
		"/\[code\](.+?)\[\/code\]/eis",
        '/\/cy\;/',
        '/\/tp\;/',
        '/\/lh\;/',
        '/\/tx\;/',
        '/\/bb\;/',
        '/\/qd\;/',
        '/\/ch\;/',
        '/\/zt\;/',
        '/\/mg\;/',
        '/\/dk\;/',
        '/\/ll\;/',
        '/\/xs\;/',
        '/\/yj\;/',
        '/\/zk\;/',
        '/\/wq\;/',
        '/\/db\;/',
        '/\/zd\;/',
        '/\/cd\;/',
        '/\/ka\;/',
        '/\/ss\;/',
        '/\/mt\;/',
        '/\/dy\;/',
        '/\/ot\;/',
        '/\/wx\;/',
        '/\/sq\;/',
        '/\/gg\;/'
    );
    $html = array(
        'vershow("$1","$2")',
        'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'],
        '<br>',
        '<a target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin=\\1&site=qq&menu=yes"><img border="0" src="http://wpa.qq.com/pa?p=2:\\1:\\2" alt="\\3" title="\\3"/></a>',
        MYNAME,
        XID,
        crevalue,
        '<span>\\1</span>',
        '<p>\\1</p>',
        '<center>\\1</center>',
        '<h1>\\1</h1>',
        '<h2>\\1</h2>',
        '<h3>\\1</h3>',
        '<font color="\\1">\\2</font>',
        '<font size="\\1">\\2</font>',
        '<marquee  behavior="scroll" scrollamount="2" onMouseOut="this.start()" onMouseOver="this.stop()">\\1</marquee>',
        '<hr>',
        '<br>',
        '<b>\\1</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="http://' . $_SERVER['HTTP_HOST'] . '/\\1/list.php?action=hot&cid=\\2">\\3</a>',
        '<a href="http://' . $_SERVER['HTTP_HOST'] . '/\\1/list.php?action=new&cid=\\2">\\3</a>',
        '<a href="http://' . $_SERVER['HTTP_HOST'] . '/\\1/list.php?action=good&cid=\\2">\\3</a>',
        '<a href="\\1">\\2</a>',
        '<a href="\\1">\\1</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,
        'get_sql_list(\'\1\',\'\2\',\'\3\',\'\4\',\'\5\',\'\6\')',
		'showloop(\'\1\',\'\2\',\'\3\')',
        $timeubb,
        '<a href="http://' . $_SERVER["HTTP_HOST"] . '/index.php?cid=\\1">\\2</a>',
        $baidu,
        '<form method="\\1" action="\\2">\\3</form>',
        '<input type="\\1" name="\\2" value="\\3">',
        '<select name="\\1">\\2</select>',
        '<option value="\\1">\\2</option>',
        '<ul class="\\1">',
        '</ul>',
        'brStr(\'<ul class="\\1"><li>\\2</li></ul>\')',
        'brStr(\'<ul><li>$1</li></ul>\')',
        '<li>',
        '</li>',
        NoReadMessNums() ,
        '<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\')',
        'dd_html(\'$1\')',
        'admins()',
        'admins(\'$1\')',
        $_SERVER["HTTP_HOST"],
        nav_bar($_GET['cid'], $wapid) ,
        '暂未上线',
        '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">',
        'piclf(\'320\',\'150\',\'$2\',\'$1\')',
		'highlight_code(\'\\1\')',
        '<img src="http://' . HTTP_HOST . '/style/feel/f_static_000.png" alt="." style="height:25px;width:25px;">',
        '<img src="http://' . HTTP_HOST . '/style/feel/f_static_001.png" alt="." style="height:25px;width:25px;">',
        '<img src="http://' . HTTP_HOST . '/style/feel/f_static_002.png" alt="." style="height:25px;width:25px;">',
        '<img src="http://' . HTTP_HOST . '/style/feel/f_static_003.png" alt="." style="height:25px;width:25px;">',
        '<img src="http://' . HTTP_HOST . '/style/feel/f_static_004.png" alt="." style="height:25px;width:25px;">',
        '<img src="http://' . HTTP_HOST . '/style/feel/f_static_005.png" alt="." style="height:25px;width:25px;">',
        '<img src="http://' . HTTP_HOST . '/style/feel/f_static_006.png" alt="." style="height:25px;width:25px;">',
        '<img src="http://' . HTTP_HOST . '/style/feel/f_static_007.png" alt="." style="height:25px;width:25px;">',
        '<img src="http://' . HTTP_HOST . '/style/feel/f_static_008.png" alt="." style="height:25px;width:25px;">',
        '<img src="http://' . HTTP_HOST . '/style/feel/f_static_009.png" alt="." style="height:25px;width:25px;">',
        '<img src="http://' . HTTP_HOST . '/style/feel/f_static_010.png" alt="." style="height:25px;width:25px;">',
        '<img src="http://' . HTTP_HOST . '/style/feel/f_static_011.png" alt="." style="height:25px;width:25px;">',
        '<img src="http://' . HTTP_HOST . '/style/feel/f_static_012.png" alt="." style="height:25px;width:25px;">',
        '<img src="http://' . HTTP_HOST . '/style/feel/f_static_013.png" alt="." style="height:25px;width:25px;">',
        '<img src="http://' . HTTP_HOST . '/style/feel/f_static_014.png" alt="." style="height:25px;width:25px;">',
        '<img src="http://' . HTTP_HOST . '/style/feel/f_static_015.png" alt="." style="height:25px;width:25px;">',
        '<img src="http://' . HTTP_HOST . '/style/feel/f_static_016.png" alt="." style="height:25px;width:25px;">',
        '<img src="http://' . HTTP_HOST . '/style/feel/f_static_017.png" alt="." style="height:25px;width:25px;">',
        '<img src="http://' . HTTP_HOST . '/style/feel/f_static_018.png" alt="." style="height:25px;width:25px;">',
        '<img src="http://' . HTTP_HOST . '/style/feel/f_static_019.png" alt="." style="height:25px;width:25px;">',
        '<img src="http://' . HTTP_HOST . '/style/feel/f_static_020.png" alt="." style="height:25px;width:25px;">',
        '<img src="http://' . HTTP_HOST . '/style/feel/f_static_021.png" alt="." style="height:25px;width:25px;">',
        '<img src="http://' . HTTP_HOST . '/style/feel/f_static_022.png" alt="." style="height:25px;width:25px;">',
        '<img src="http://' . HTTP_HOST . '/style/feel/f_static_023.png" alt="." style="height:25px;width:25px;">',
        '<img src="http://' . HTTP_HOST . '/style/feel/f_static_024.png" alt="." style="height:25px;width:25px;">',
        '<img src="http://' . HTTP_HOST . '/style/feel/f_static_025.png" alt="." style="height:25px;width:25px;">'
    );
    $content = preg_replace($ubb, $html, $content);
    return $content;
}
//执行两次UBB转换程序，转换遗漏的UBB代码。
function UBB($content,$wapid) 
{
	$wapid = $wapid == NULL ? WAPID:$wapid;
    $backRun = RunUbb($content, $wapid);
    $backHtml = RunUbb($backRun, $wapid);
    return stripcslashes($backHtml);
}

