<?php
/*******************************************************************************************
' Software name: DJCMS Content Management System
' Version:3.0
' Web: http://www.djcms.net
' Author: 心情(qq:1130731)
' Copyright (C) 2009-2010 DJCMS官方 版权所有
' 法律申明：DJCMS程序所有代码100%原创、未引入任何网上代码,对一切抄袭行为、坚决严肃追究法律责任
'*******************************************************************************************/
defined('IN_DJCMS') or exit('Access Denied');
$starttime=ExecTime();

class djcms {
	
	public static $content;
	public static $currentTopicId = -444;
	public static $currentTypeId = -444;
    
	//禁止实例化
	private function __construct() {}
	
	//读取模板
	public static function load($filePath) {
		$cacheName="template_".$filePath;
		if (cacheStart == 1) {
	        if (!self::$content = memory('get', $cacheName)){
                self::$content = loadFile($filePath);
				memory('set', $cacheName, self::$content);
            }
	    } else {
		    self::$content = loadFile($filePath);
	    }
    }
	public static function parseStrip($str) {
		if (isExistStr(' '.$str,"{djcms:strip}")){
			preg_match_all(buildregx("{djcms:strip}(.*?){/djcms:strip}","is"), $str, $arv);
			$arvalen = count($arv[1]);
			for ($n = 0;$n < $arvalen;$n++){
				$x = preg_replace(buildregx("[\t ]*[\r\n]+[\t ]*","is"),"",$arv[1][$n]);
				$str = replaceStr($str,$arv[0][$n],$x);
			}
		}
		return $str;
	}
	//自定义标签
	public static function parseSelf() {
		if (isExistStr(self::$content, "{self:")) {
			$sql = "SELECT m_name,m_content FROM ".DB::table('selflabel')."";
		    $labelRule = "{self:(.*?)}";
			if (cacheStart == 1) {
	            if (!$selfLabelArray = memory('get', 'array_allselflabel_name_content')){
                    $query = DB::query($sql);
	                while ($row = DB::fetch($query)) {
						$selfLabelArray[]=$row;
		            }
			        memory('set', 'array_allselflabel_name_content',$selfLabelArray);
                }
	        } else {
				$query = DB::query($sql);
	            while ($row = DB::fetch($query)) {
					$selfLabelArray[]=$row;
		        }
	        }
		    $trow = array();
			foreach ($selfLabelArray as $row) {
		        $singleAttrValue = explode("$$$", decodeHtml($row['m_content']));
		        $singleLength = count($singleAttrValue);
		        if ($singleLength > 0) {
		            $singleNum = mt_rand(0, $singleLength - 1);
		            $trow[$row['m_name']] = $singleAttrValue[$singleNum];
		        } else {
		            $trow[$row['m_name']] = decodeHtml($row['m_content']);
		        }
		    }
		    preg_match_all(buildregx($labelRule,"is"), self::$content, $sar);
		    $len = count($sar[1]);
		    for ($m = 0;$m < $len;$m++) {
			    $labelName = trim($sar[1][$m]);
			    if (isset($trow[$labelName])) {
			        self::$content = replaceStr(self::$content, $sar[0][$m], $trow[$labelName]);
		        }
		    }
		}
	}
    //模板顶部标签
	public static function parseTopAndFoot() {
		$content = replaceStr(self::$content,"{djcms:top}",loadFileOnCache("template_",DJCMS_TEMPLATE."/head.html"));
		$content = replaceStr($content,"{djcms:foot}",loadFileOnCache("template_",DJCMS_TEMPLATE."/foot.html"));
		if (isExistStr($content,"{djcms:load")){
			preg_match_all(buildregx("{djcms:load(.*?)}","is"), $content, $arv);
			$arvalen = count($arv[1]);
			for ($n = 0;$n < $arvalen;$n++){
				$x = trim($arv[1][$n]);
				if (isExistFile(DJCMS_TEMPLATE.$x)){ 
				    $content = replaceStr($content, $arv[0][$n],loadFileOnCache("template_",DJCMS_TEMPLATE.$x));
				}
			}
		}
		$content = replaceStr($content, "images/", "/".sitePath."template/".defaultTemplate."/images/");
		if (gbookStart == 0) {
			$content = replaceStr($content, "{djcms:gbook}", "");
		} else {
			$content = replaceStr($content, "{djcms:gbook}", "<a href=\"/{djcms:sitepath}gbook.php\" target=\"_blank\"  >留言</a>");
		}
		self::$content = self::parseStrip($content);
	}
	
    //网站基本设置标签
	public static function parseGlobal() {
		if (isExistStr(self::$content, "{djcms:letterlist}")) self::$content = replaceStr(self::$content, "{djcms:letterlist}", getletterlist());
		if (isExistStr(self::$content, "{djcms:indexlink}")) self::$content = replaceStr(self::$content, "{djcms:indexlink}", getIndexLink());
		if (isExistStr(self::$content, "{djcms:topiclink}")) self::$content = replaceStr(self::$content, "{djcms:topiclink}", getTopicIndexLink(1));
		if (isExistStr(self::$content, "{djcms:newslink}")) self::$content = replaceStr(self::$content, "{djcms:newslink}", getNewsIndexLink());
		$content = replaceStr(self::$content, "{djcms:siteurl}", replaceStr(siteUrl,"http://",""));
		$content = replaceStr($content, "{djcms:sitepath}", sitePath);
		$content = replaceStr($content, "{djcms:adfolder}", siteAd);
		$content = replaceStr($content, "{djcms:sitename}", siteName);
		$content = replaceStr($content, "{djcms:copyright}", decodeHtml(copyRight));
		$content = replaceStr($content, "{djcms:des}", decodeHtml(siteDes));
		$content = replaceStr($content, "{djcms:sitevisitjs}", siteVisiteJs);
		$content = replaceStr($content, "{djcms:sitenotice}", decodeHtml(siteNotice));
		self::$content = replaceStr($content, "{djcms:keywords}", getKeywordsList(siteKeyWords,""));
		if (isExistStr(self::$content, "{djcms:allcount}")) self::$content = replaceStr(self::$content, "{djcms:allcount}", getDataCount("all"));
		if (isExistStr(self::$content, "{djcms:daycount}")) self::$content = replaceStr(self::$content, "{djcms:daycount}", getDataCount("day"));
		self::parseSlide();
		self::parseMaxHistory();
		if (runMode == "static") self::$content = replaceStr(self::$content, "{djcms:runinfo}", "");
	}
	
	//解释标签函数
	public static function parseAttr($attrStr) {
		$attrArray = explode(chr(32), $attrStr);
		$atlen = count($attrArray);
		for ($i = 0; $i < $atlen; $i++) {
		    $singleAttr = explode(chr(61), $attrArray[$i]);
		    $singleAttrKey = strtolower($singleAttr[0]);
		    $singleAttrValue = empty($singleAttr[1]) ? '' : $singleAttr[1];
		    $attrDictionary[$singleAttrKey] = $singleAttrValue;
		}
		return $attrDictionary;
	}
	
   //数据区域块列表标签
	public static function parseAreaList() {
		global $err_areaList;
		if (isExistStr(self::$content, "{djcms:arealist")) {
			$attrDictionary=array();
		    $totalStrAreaList='';
		    $labelRule = "{djcms:arealist(.*?)}(.*?){/djcms:arealist}";
		    $labelRuleVideolist = "{djcms:videolist(.*?)}(.*?){/djcms:videolist}";
	        preg_match_all(buildregx($labelRule, "is"), self::$content, $ar);
		    $typeStr = getTypeIdOnCache(0);
		    $arlen = count($ar[1]);
		    for ($m = 0;$m < $arlen;$m++) {
			    if (!empty($typeStr)) {
				    $labelAttrArealist = trim(preg_replace("/[ \r\n\t\f]{1,}/"," ",$ar[1][$m]));
			        $loopStrArealist = $ar[2][$m];
			        $x = self::parseAttr($labelAttrArealist);
				    $areaType=empty($x['areatype']) ? 'all' : $x['areatype'];
				    $letHas=empty($x['arealetter']) ? 'letter' : $x['arealetter'];
					$tagHas=empty($x['tag']) ? '' : $x['tag'];
				    unset($x);
			        if ($areaType == "letter") {
		                if (empty($letHas) || $letHas == "all") $letHas = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
			            $letHas = explode(",", strtoupper($letHas));
					    $len = count($letHas);
			            for ($j = 0;$j < $len;$j++) {
				            if (!empty($letHas[$j])) {
					            $tmp = $loopStrArealist;
					            $tmp = replaceStr($tmp, "[arealist:i]", $j+1);
					            $tmp = replaceStr($tmp, "[arealist:typename]", $letterHas[$j]);
					            if (isExistStr($tmp, "[arealist:count]")){
									$tcount = getcount('data', array('m_letter' => $letHas[$j]));
						            $tmp = replaceStr($tmp, "[arealist:count]", $tcount);
						        }
						        $tmp=replaceStr($tmp, "[arealist:link]", "/".sitePath."search.php?searchtype=4&searchword=".$letHas[$j]);
						        preg_match_all(buildregx($labelRuleVideolist,"is"), $tmp, $arv);
							    $arvalen = count($arv[1]);
						        for ($n = 0;$n < $arvalen;$n++){
							        $videoListStr = replaceStr($arv[0][$n], "arealetter", $letterHasArray[$j]);
							        $videoListStr = replaceStr($videoListStr, "areatype", "all");
							        $tmp = replaceStr($tmp, $arv[0][$n], $videoListStr);
						        }
					            $totalStrAreaList .= $tmp;
				            }
			            }
					}else if ($areaType == "tag"){
					    if (empty($tagHas)) $tagHas="all";
					    $tagHas = explode(",", $tagHas);
					    $taglen = count($tagHas);
			            for ($j = 0;$j < $taglen;$j++) {
						    if ($tagHas[$j]<>""){
							    $tmp=$loopStrArealist;
							    $tmp=replaceStr($tmp,"[arealist:i]",$j+1);
							    $tmp=replaceStr($tmp,"[arealist:typename]",$tagHas[$j]);
							    if (isExistStr($tmp,"[arealist:count]")){
									$tcount = getcount("data", "m_keyword+m_name LIKE '%".$tagHas[$j]."%'");
						            $tmp = replaceStr($tmp, "[arealist:count]", $tcount);
								}
							    $tmp=replaceStr($tmp,"[arealist:link]","/".sitePath."search.php?searchword=".$tagHas[$j]);
							    preg_match_all(buildregx($labelRuleVideolist,"is"), $tmp, $arv);
							    $arvalen = count($arv[1]);
						        for ($n = 0;$n < $arvalen;$n++){
								    $videoListStr=replaceStr($arv[0][$n],"areatag",$tagHas[$j]);
								    $videoListStr=replaceStr($videoListStr,"areatype","all");
								    $tmp=replaceStr($tmp,$arv[0][$n],$videoListStr);
								}
								$totalStrAreaList .= $tmp;
							}
						}
                    } else {
					    if ($areaType == "all") $areaTypeArray=explode(",", $typeStr);else $areaTypeArray=explode(",", $areaType);
					    $arealen = count($areaTypeArray);
			            for ($j = 0;$j < $arealen;$j++) {
				            $currentAreaType = intval(trim($areaTypeArray[$j]));
						    if (!is_numeric($currentAreaType)) die($err_areaList);
							if(empty($currentAreaType)){
						        $tmp="";
					        }else{
					            $AreaType = explode(",", getTypeNameTemplateArrayOnCache($currentAreaType));
					            $tmp = $loopStrArealist;
					            $tmp = replaceStr($tmp, "[arealist:i]", $j+1);
					            $tmp = replaceStr($tmp, "[arealist:typename]", $AreaType[0]);
					            $tmp = replaceStr($tmp, "[arealist:typeid]", $currentAreaType);
					            if (isExistStr($tmp, "[arealist:count]")) {
							        $tmp = replaceStr($tmp, "[arealist:count]", getNumPerType($currentAreaType));
						        }
					            $tmp = replaceStr($tmp, "[arealist:link]", getTypeLink($currentAreaType));
					            preg_match_all(buildregx($labelRuleVideolist,"is"), $tmp, $arv);
						        $arvlen = count($arv[1]);
					            for ($n = 0;$n < $arvlen;$n++) {
							        $videoListStr = replaceStr($arv[0][$n], "arealetter", "all");
							        $videoListStr = replaceStr($videoListStr, "areatype", $currentAreaType);
						            $tmp = replaceStr($tmp, $arv[0][$n], $videoListStr);
					            }
							}
				            $totalStrAreaList .= $tmp;
			            }
				    }
		        } else {
				    $totalStrAreaList = "";
		        }
			    self::$content = replaceStr(self::$content, $ar[0][$m], $totalStrAreaList);
				$totalStrAreaList="";
            }
		}
	}
    //单层循环数据列表标签
	public static function parseVideoList() {
        if (isExistStr(self::$content, "{djcms:videolist")) {
			$attrDictionary=array();
		    $ni = 1;
		    $labelRule = "{djcms:videolist(.*?)}(.*?){/djcms:videolist}";
		    $labelRuleField = "\[videolist:(.*?)\]";
		    preg_match_all(buildregx($labelRule,"is"), self::$content, $ar);
		    $arlen = count($ar[1]);
		    for ($m = 0;$m < $arlen;$m++) {
		        $labelAttrVideolist = trim(preg_replace("/[ \r\n\t\f]{1,}/"," ",$ar[1][$m]));
		        $loopstrVideoList = $ar[2][$m];
		        $attrDictionary = self::parseAttr($labelAttrVideolist);
			    $vnum = empty($attrDictionary['num']) ? 10 : intval($attrDictionary['num']);
		        $vorder = empty($attrDictionary['order']) ? '' : $attrDictionary['order'];
			    $vletter = empty($attrDictionary['letter']) ? '' : $attrDictionary['letter'];
		        $vtype = empty($attrDictionary['type']) ? 'all' : $attrDictionary['type'];
			    $vtopic = empty($attrDictionary['topic']) ? '' : $attrDictionary['topic'];
		        $vtime = empty($attrDictionary['time']) ? "" : $attrDictionary['time'];
		        $vstart = empty($attrDictionary['start']) ? 0 : intval($attrDictionary['start'])-1;
		        $vstate = empty($attrDictionary['state']) ? '' : $attrDictionary['state'];
		        $vcommend = empty($attrDictionary['commend']) ? '' : $attrDictionary['commend'];
			    $vid = empty($attrDictionary['id']) ? '' : $attrDictionary['id'];
			    unset($attrDictionary);
			    if (empty($vorder) && empty($vid)) $vorder = "time";
			    if (empty($vorder)) $vorder = "id";
		        switch ($vorder) {
				    case "id" : $orderStr = " ORDER BY m_id DESC";break;
				    case "hit" : $orderStr = " ORDER BY m_hit DESC";break;
					case "dayhit" : $orderStr =" ORDER BY m_dayhit DESC";break;
				    case "weekhit" : $orderStr =" ORDER BY m_weekhit DESC";break;
				    case "monthhit" : $orderStr =" ORDER BY m_monthhit DESC";break;
				    case "time" : $orderStr = " ORDER BY m_addtime DESC";break;
				    case "commend" : $orderStr = " ORDER BY m_commend DESC";break;
				    case "digg" : $orderStr = " ORDER BY m_digg DESC";break;
				    case "hot" : $orderStr = " ORDER BY m_hit DESC";break;
				    case "random" : $orderStr = " ORDER BY rand() DESC";break;
		        }
		        if (empty($vtype)) $vtype = 'all';
		        $vtypeStr = '';
		        if ($vtype != 'all') {
			        if ($vtype == 'current') {
				        $vtypeStr = getTypeIdOnCache(self::$currentTypeId);
			        } else {
					    if (strpos($vtype,',')>0) {
				            $vtypeArray=explode(",",$vtype);
				            foreach ($vtypeArray as $vtypestra){
				                $vtypeStr .= getTypeIdOnCache($vtypestra).",";
				            }
				            $vtypeStr = rtrim($vtypeStr,",");
				        } else {
				            $vtypeStr = getTypeIdOnCache($vtype);
				        }
			        }
			        if (strpos($vtypeStr,',') > 0) $whereType = " AND m_type IN ($vtypeStr) "; else $whereType = " AND m_type=$vtypeStr";
		        } else {
		            $whereType="";
		        }
		        if (!empty($vletter)) $whereLetter = " AND m_letter ='".strtoupper($vletter)."'"; else $whereLetter = "";
		        if (!empty($vid) && $vid != "all") {
			        if (strpos($vid,',') > 0) $whereId = " AND m_id IN($vid) "; else $whereId = " AND m_id=$vid";
		        } else {
			        $whereId = "";
		        }
				if (is_numeric($vstate)) {
				    $whereState=" AND m_state>=".intval($vstate);
				} else if ($vstate == "series"){
				    $whereState=" AND m_state>0";
				} else {
				    $whereState="";
			    }
		        if (!empty($vcommend)) {
		            switch (trim($vcommend)) {
			            case "all":$whereCommend = " AND m_commend>0";break;
			            default:
				            if (strpos($vcommend,',') > 0) $whereCommend = " AND m_commend IN($vcommend)"; else $whereCommend = " AND m_commend=$vcommend";
		            }
		        } else {
			        $whereCommend = "";
		        }
		        if (!empty($vtopic)) {
		            switch (trim($vtopic)) {
			            case "all":$whereTopic = " AND m_topic>0";break;
			            case "current":$whereTopic = " AND m_topic=".self::$currentTopicId;break;
			            default:
				            if (strpos($vtopic,',') > 0) $whereTopic = " AND m_topic IN($vtopic)"; else $whereTopic = " AND m_topic='$vtopic'";
		            }
		        } else {
		            $whereTopic = "";
		        }
		        switch ($vtime) {
		 	        case "day":
				        $ntime = gmmktime(0, 0, 0, gmdate('m'), gmdate('d'), gmdate('Y'));
				        $limitday = $ntime - (1 * 24 * 3600);
				        $whereTime = " AND m_addtime>".$limitday;
			        break;
			        case "week":
				        $ntime = gmmktime(0, 0, 0, gmdate('m'), gmdate('d'), gmdate('Y'));
				        $limitday = $ntime - (7 * 24 * 3600);
				        $whereTime = " AND m_addtime>".$limitday;
			        break;
			        case "month":
				        $ntime = gmmktime(0, 0, 0, gmdate('m'), gmdate('d'), gmdate('Y'));
				        $limitday = $ntime - (30 * 24 * 3600);
				        $whereTime = " AND m_addtime>".$limitday;
			        break;
			        default:
				        $whereTime = "";
		        }
		        $whereStr = replaceStr(" WHERE m_recycle=0".$whereType.$whereLetter.$whereTopic.$whereTime.$whereState.$whereCommend.$whereId, "WHERE AND ", "WHERE ");
		        //if (trim($whereStr) == "where") $whereStr = "";
		        preg_match_all(buildregx($labelRuleField,"is"), self::$content, $lar);
			    $matchfieldarr = $lar[1];
		        $matchfieldstrarr = $lar[0];
		        $loopstrTotal = "";
		        $i = 1;
		        $query = DB::query("SELECT * FROM ".DB::table('data')." $whereStr$orderStr LIMIT $vstart, $vnum");
	            while ($row = DB::fetch($query)) {
			        $loopnew = $loopstrVideoList;
			        foreach ($matchfieldarr as $f => $matchfieldstr) {
				        $matchfieldvalue = $matchfieldstrarr[$f];
						$matchfieldstr = trim(preg_replace("/[ \r\n\t\f]{1,}/"," ",$matchfieldstr));
				        if (strpos($matchfieldstr, chr(32)) > 0) {
				            $fieldtemparr = explode(chr(32), $matchfieldstr);
				            $fieldName = $fieldtemparr[0];
				            $fieldAttr = $fieldtemparr[1];
				        } else {
				            $fieldName = $matchfieldstr;
				            $fieldAttr = "";
				        }
			            switch (trim($fieldName)) {
				            case "id":
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, $row['m_id']);
				            break;
				            case "typeid":
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, $row['m_type']);
				            break;
				            case "letter":
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, $row['m_letter']);
				            break;
				            case "name":
					            $m_name = $row['m_name'];
							    $fieldAttrarr=self::parseAttr($fieldAttr);$namelen=empty($fieldAttrarr['len']) ? "" : intval($fieldAttrarr['len']);
							    $m_name=!empty($namelen)&&strlen($m_name)>$namelen ? msubstr($m_name,$namelen) : $m_name;
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, $m_name);
				            break;
				            case "colorname":
					            $m_color = $row['m_color'];$m_name = $row['m_name'];
							    $fieldAttrarr=self::parseAttr($fieldAttr);$colornamelen=empty($fieldAttrarr['len']) ? "" : intval($fieldAttrarr['len']);
							    $m_name=!empty($colornamelen)&&strlen($m_name)>$colornamelen ? msubstr($m_name,$colornamelen) : $m_name;
					            if (!empty($m_color)) $m_name = "<font color=".$m_color.">".$m_name."</font>";
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, $m_name);
				            break;
				            case "note":
				 	            $m_note = $row['m_note'];
							    $fieldAttrarr=self::parseAttr($fieldAttr);$notelen=empty($fieldAttrarr['len']) ? "" : intval($fieldAttrarr['len']);
							    $m_note=!empty($notelen)&&strlen($m_note)>$notelen ? msubstr($m_note,$notelen) : $m_note;
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, $m_note);
				            break;
				            case "actor":
					            $m_actor = $row['m_actor'];
							    $fieldAttrarr=self::parseAttr($fieldAttr);$actorlen=empty($fieldAttrarr['len']) ? "" : intval($fieldAttrarr['len']);
							    $m_actor=!empty($actorlen)&&strlen($m_actor)>$actorlen ? msubstr($m_actor,$actorlen) : $m_actor;
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, $m_actor);
				            break;
				            case "des":
					            $m_des = decodeHtml($row['m_des']);
							    $fieldAttrarr=self::parseAttr($fieldAttr);$deslen=empty($fieldAttrarr['len']) ? "200" : intval($fieldAttrarr['len']);
							    $m_des=strlen($m_des)>$deslen ? msubstr($m_des,$deslen) : $m_des;
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, $m_des);
				            break;
				            case "time":
							    $fieldAttrarr=self::parseAttr($fieldAttr);$timestyle=empty($fieldAttrarr['style']) ? "m-d" : $fieldAttrarr['style'];
					            $videoTime = $row['m_addtime'];
				                switch (trim($timestyle)) {
					                case "yyyy-mm-dd":
				                        $loopnew = replaceStr($loopnew, $matchfieldvalue, date("Y-m-d", $videoTime));
					                break;
					                case "yy-mm-dd":
				                        $loopnew = replaceStr($loopnew, $matchfieldvalue, date("y-m-d", $videoTime));
					                break;
					                case "y-m-d":
				                        $loopnew = replaceStr($loopnew, $matchfieldvalue, date("Y-n-d", $videoTime));
					                break;
					                default:
						                $loopnew = replaceStr($loopnew, $matchfieldvalue, date($timestyle, $videoTime));
				                }
				            break;
				            case "i":
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, $i);
				            break;
						    case "n":
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, $ni);
				            break;
				            case "typename":
				                $typename = explode(",", getTypeNameTemplateArrayOnCache(intval($row['m_type'])));
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, $typename[0]);
				            break;
				            case "typelink":
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, getTypeLink($row['m_type']));
				            break;
				            case "link":
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, getContentLink($row['m_type'], $row['m_id'],$row['m_enname'],$row['m_datetime'], "link"));
				            break;
				            case "playlink":
					            if (isAlertWin == 1) $playlink_str = "javascript:openWin('".getPlayLink2($row['m_type'], $row['m_id'],$row['m_enname'],$row['m_datetime'],0,0)."',".(alertWinW+10).",".(alertWinH+55).",250,100,1)"; else $playlink_str = getPlayLink2($row['m_type'], $row['m_id'],$row['m_enname'],$row['m_datetime'],0,0);
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, $playlink_str);
				            break;
				            case "pic":
				                if (!empty($row['m_pic'])) {
					                if (isExistStr($row['m_pic'], '://')) {
						                $loopnew = replaceStr($loopnew, $matchfieldvalue, $row['m_pic']);
					                } else {
						                $loopnew = replaceStr($loopnew, $matchfieldvalue, '/'.sitePath.$row['m_pic']);
					                }
					            } else {
						            $loopnew = replaceStr($loopnew, $matchfieldvalue, '/'.sitePath.'pic/nopic.gif');
					            }
				            break;
				            case "hit":
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, $row['m_hit']);
				            break;
				            case "state":
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, $row['m_state']);
				            break;
				            case "publishtime":
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, $row['m_publishyear']);
				            break;
				            case "publisharea":
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, $row['m_publisharea']);
				            break;
				            case "commend":
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, $row['m_commend']);
				            break;
				            case "from":
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, getFromStr($row['m_playdata']));
				            break;
						    case "keyword":
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, getKeywordsList($row['m_keyword']," "));
				            break;
						    case "digg":
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, $row['m_digg']);
				            break;
						    case "tread":
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, $row['m_tread']);
				            break;
							case "director":
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, getKeywordsList($row['m_director']," "));
				            break;
						    case "lang":
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, $row['m_lang']);
				            break;
							case "dayhit":
							    $loopnew = replaceStr($loopnew,$matchfieldvalue,$row['m_dayhit']);
							break;
						    case "weekhit":
							    $loopnew = replaceStr($loopnew,$matchfieldvalue,$row['m_weekhit']);
							break;
						    case "monthhit":
							    $loopnew = replaceStr($loopnew,$matchfieldvalue,$row['m_monthhit']);
							break;
						    case "score":
							    $loopnew = replaceStr($loopnew,$matchfieldvalue,$row['m_score']);
							break;
			            }
		            }
		            $i = $i + 1;
		            $loopstrTotal .= $loopnew;$ni=$ni+1;
		        }
		        self::$content = replaceStr(self::$content, $ar[0][$m], $loopstrTotal);
            }
		}
	}
    //搜索页-频道页分页列表标签
	public static function parsePageList($typeId, $currentPage, $pageListType) {
		global $lang,$totalPages;
		$labelRule = "{djcms:".$pageListType."list(.*?)}(.*?){/djcms:".$pageListType."list}";
		$labelRuleField = "\[".$pageListType."list:(.*?)\]";
		$labelRulePagelist = "\[".$pageListType."list:pagenumber(.*?)\]";
		$labelRulePagelist2 = "\{".$pageListType."list:pagenumber(.*?)\}(.*?){/".$pageListType."list:pagenumber}";
		preg_match_all(buildregx($labelRule, "is"), self::$content, $ar);
		$sql1="SELECT m_id,m_name,m_type,m_state,m_pic,m_hit,m_actor,m_des,m_topic,m_color,m_addtime,m_publishyear,m_publisharea,m_commend,m_playdata,m_note,m_keyword,m_digg,m_tread,m_enname,m_datetime,m_director,m_lang,m_dayhit,m_weekhit,m_monthhit,m_score FROM ".DB::table('data')." ";
		$arlen = count($ar[1]);
		for ($m = 0;$m < $arlen;$m++) {
			$attrChannel = trim(preg_replace("/[ \r\n\t\f]{1,}/"," ",$ar[1][$m]));
			$loopstrChannel = $ar[2][$m];
		    $attrDictionary = self::parseAttr($attrChannel);
			$vsize = empty($attrDictionary["size"]) ? 12 : intval($attrDictionary["size"]);
			$vorder = empty($attrDictionary["order"]) ? "time" : $attrDictionary["order"];
			switch ($vorder) {
				case "id" : $orderStr = " ORDER BY m_id DESC";break;
				case "hit" : $orderStr = " ORDER BY m_hit DESC";break;
				case "dayhit" : $orderStr =" ORDER BY m_dayhit DESC";break;
				case "weekhit" : $orderStr =" ORDER BY m_weekhit DESC";break;
				case "monthhit" : $orderStr =" ORDER BY m_monthhit DESC";break;
				case "time" : $orderStr = " ORDER BY m_addtime DESC";break;
				case "hot" : $orderStr = " ORDER BY m_hit DESC";break;
				case "digg" : $orderStr = " ORDER BY m_digg DESC";break;
				case "name" : $orderStr = " ORDER BY m_name ASC ";break;
				case "letter" : $orderStr = " ORDER BY m_letter ASC";break;
			}
			switch ($pageListType) {
				case "channel":
					$sql=$sql1." WHERE m_recycle=0 AND m_type IN ($typeId)".$orderStr;
				break;
				case "search":
					global $searchType,$searchword;
					switch ($searchType) {
						case -1 : $whereStr=" WHERE m_recycle=0 AND (m_name LIKE '%".$searchword."%' OR m_actor LIKE '%".$searchword."%' OR  m_director LIKE '%".$searchword."%')";break;
						case 0 : $whereStr=" WHERE m_recycle=0 AND m_name LIKE '%".$searchword."%'";break;
						case 1 : $whereStr=" WHERE m_recycle=0 AND (m_actor LIKE '%".$searchword."%' OR m_director LIKE '%".$searchword."%')";break;
						case 2 : $whereStr=" WHERE m_recycle=0 AND m_publisharea LIKE '%".$searchword."%'";break;
						case 3 : $whereStr=" WHERE m_recycle=0 AND m_publishyear LIKE '%".$searchword."%'";break;
						case 4 : $whereStr=" WHERE m_recycle=0 AND m_letter='".strtoupper($searchword)."'";break;
						case 5 : $whereStr=" WHERE m_recycle=0 AND m_lang LIKE '%".$searchword."%'";break;
	                }
					if (empty($searchword)) $whereStr = " WHERE 1=2";
					$sql=$sql1.$whereStr.$orderStr;
				break;
				case "topicpage":
					$sql=$sql1." WHERE `m_recycle`=0 AND `m_topic`='$typeId'".$orderStr;
				break;
				case "customvideo":
				    $vtype=empty($attrDictionary["type"]) ? 'all' : $attrDictionary["type"];
					$totalPages=empty($attrDictionary["maxpage"]) ? '' : $attrDictionary["maxpage"];
					if (is_numeric($totalPages)) $totalPages=intval($totalPages); else $totalPages=0;
					if ($vtype != 'all'){
					    if (strpos($vtype,',')>0) {
				            $vtypeArray=explode(",",$vtype);
				            foreach ($vtypeArray as $vtypestra){
				                $vtype=$vtype.getTypeIdOnCache($vtypestra).",";
				            }
				            $vtype=rtrim($vtype,",");
				        } else {
				            $vtype=getTypeIdOnCache($vtype);
				        }
			            if (strpos($vtype,',') > 0) $whereStr = " AND `m_type` in ($vtype) "; else $whereStr = " AND `m_type`=$vtype";
					} else {
						$whereStr="";
					}
					$sql=$sql1."WHERE m_recycle=0".$whereStr.$orderStr;
				break;
		    }
			$recordcount = DB::getCount($sql);
			preg_match_all(buildregx($labelRuleField, "is"), self::$content, $lar);
		    $matchfieldarr = $lar[1];
		    $matchfieldstrarr = $lar[0];
			$loopstrTotal = "";
			$i = 1;
			if ($recordcount == 0) {
				if ($pageListType == "channel") {
					$loopstrTotal = $lang['channellistInfo']['0'];
			    } elseif($pageListType == "search") {
					$loopstrTotal = $lang['searchlistInfo']['0'].$searchword.$lang['searchlistInfo']['1'];
			    } elseif($pageListType == "topicpage") {
					$loopstrTotal = $lang['topicpageInfo']['0'];
			    }
				$totalPages=0;
		    } else {
				if ($totalPages>ceil($recordcount/$vsize) || $pageListType!="customvideo") $totalPages = ceil($recordcount/$vsize);
			    if (intval($currentPage)>$totalPages) $currentPage=$totalPages;
			    $page = max(intval($currentPage), 1);
                $offset = $vsize*($page-1);
				$query = DB::query("$sql LIMIT $offset, $vsize");
	            while ($row = DB::fetch($query)) {
				    $loopnew = $loopstrChannel;
				    foreach ($matchfieldarr as $f => $matchfieldstr) {
					    $matchfieldvalue = $matchfieldstrarr[$f];
						$matchfieldstr = trim(preg_replace("/[ \r\n\t\f]{1,}/"," ",$matchfieldstr));
					    if (strpos($matchfieldstr, chr(32)) > 0) {
						    $fieldtemparr = explode(chr(32), $matchfieldstr);
						    $fieldName = $fieldtemparr[0];
						    $fieldAttr = $fieldtemparr[1];
					    } else {
						    $fieldName = $matchfieldstr;
						    $fieldAttr = "";
					    }
				        switch (trim($fieldName)) {
					        case "id":
						        $loopnew = replaceStr($loopnew, $matchfieldvalue, $row['m_id']);
					        break;
					        case "typeid":
						        $loopnew = replaceStr($loopnew, $matchfieldvalue, $row['m_type']);
					        break;
					        case "name":
					            $m_name = $row['m_name'];
							    $fieldAttrarr=self::parseAttr($fieldAttr);$namelen=empty($fieldAttrarr['len']) ? "" : intval($fieldAttrarr['len']);
							    $m_name=!empty($namelen)&&strlen($m_name)>$namelen ? msubstr($m_name,$namelen) : $m_name;
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, $m_name);
				            break;
					        case "colorname":
						        $m_color = $row['m_color'];$m_name = $row['m_name'];
								$fieldAttrarr=self::parseAttr($fieldAttr);$colornamelen=empty($fieldAttrarr['len']) ? "" : intval($fieldAttrarr['len']);
								$m_name=!empty($colornamelen)&&strlen($m_name)>$colornamelen ? msubstr($m_name,$colornamelen) : $m_name;
						        if (!empty($m_color)) $m_name = "<font color=".$m_color.">".$m_name."</font>";
						        $loopnew = replaceStr($loopnew, $matchfieldvalue, $m_name);
					        break;
					        case "note":
						        $m_note = $row['m_note'];
								$fieldAttrarr=self::parseAttr($fieldAttr);$notelen=empty($fieldAttrarr['len']) ? "" : intval($fieldAttrarr['len']);
								$m_note=!empty($notelen)&&strlen($m_note)>$notelen ? msubstr($m_name,$notelen) : $m_note;
						        $loopnew = replaceStr($loopnew, $matchfieldvalue, $m_note);
					        break;
					        case "actor":
						        $m_actor = $row['m_actor'];
								$fieldAttrarr=self::parseAttr($fieldAttr);$actorlen=empty($fieldAttrarr['len']) ? "" : intval($fieldAttrarr['len']);
								$m_actor=!empty($actorlen)&&strlen($m_actor)>$actorlen ? msubstr($m_name,$actorlen) : $m_actor;
						        $loopnew = replaceStr($loopnew, $matchfieldvalue, $m_actor);
					        break;
					        case "des":
						        $m_des = decodeHtml($row['m_des']);
								$fieldAttrarr=self::parseAttr($fieldAttr);$deslen=empty($fieldAttrarr['len']) ? "200" : intval($fieldAttrarr['len']);
								$m_des=!empty($deslen)&&strlen($m_des)>$deslen ? msubstr($m_des,$deslen) : $m_des;
						        $loopnew = replaceStr($loopnew, $matchfieldvalue, $m_des);
					        break;
					        case "time":
								$fieldAttrarr=self::parseAttr($fieldAttr);$timestyle=empty($fieldAttrarr['style']) ? "m-d" : $fieldAttrarr['style'];
						        $videoTime = $row['m_addtime'];
				    	        switch (trim($timestyle)) {
							        case "yyyy-mm-dd":
					    	            $loopnew = replaceStr($loopnew, $matchfieldvalue, date("Y-m-d", $videoTime));
						            break;
							        case "yy-mm-dd":
					   	 	            $loopnew = replaceStr($loopnew, $matchfieldvalue, date("y-m-d", $videoTime));
							        break;
							        case "y-m-d":
					    	            $loopnew = replaceStr($loopnew, $matchfieldvalue, date("Y-n-d", $videoTime));
							        break;
							        default:
							            $loopnew = replaceStr($loopnew, $matchfieldvalue, date($timestyle, $videoTime));
					            }
					        break;
					        case "i":
						        $loopnew = replaceStr($loopnew, $matchfieldvalue, $i);
					        break;
					        case "typename":
					            $typename = explode(",",getTypeNameTemplateArrayOnCache(intval($row['m_type'])));
						        $loopnew = replaceStr($loopnew, $matchfieldvalue, $typename[0]);
					        break;
					        case "typelink":
						        $loopnew = replaceStr($loopnew, $matchfieldvalue, getTypeLink($row['m_type']));
					        break;
					        case "link":
						        $loopnew = replaceStr($loopnew, $matchfieldvalue, getContentLink($row['m_type'], $row['m_id'],$row['m_enname'],$row['m_datetime'], "link"));
					        break;
					        case "playlink":
						        if (isAlertWin == 1) $playlink_str = "javascript:openWin('".getPlayLink2($row['m_type'], $row['m_id'],$row['m_enname'],$row['m_datetime'],0,0)."',".(alertWinW+10).",".(alertWinH+55).",250,100,1)";else $playlink_str = getPlayLink2($row['m_type'], $row['m_id'],$row['m_enname'],$row['m_datetime'],0,0);
						        $loopnew = replaceStr($loopnew, $matchfieldvalue, $playlink_str);
				            break;
					        case "pic":
					            if (!empty($row['m_pic'])) {
						            if (isExistStr($row['m_pic'], '://')) {
						                $loopnew = replaceStr($loopnew, $matchfieldvalue, $row['m_pic']);
					                } else {
						                $loopnew = replaceStr($loopnew, $matchfieldvalue, '/'.sitePath.$row['m_pic']);
					                }
					            } else {
						            $loopnew = replaceStr($loopnew, $matchfieldvalue, '/'.sitePath.'pic/nopic.gif');
					            }
					        break;
					        case "hit":
						        $loopnew = replaceStr($loopnew, $matchfieldvalue, $row['m_hit']);
					        break;
					        case "state":
						        $loopnew = replaceStr($loopnew, $matchfieldvalue, $row['m_state']);
					        break;
					        case "publishtime":
						        $loopnew = replaceStr($loopnew, $matchfieldvalue, $row['m_publishyear']);
					        break;
                            case "publisharea":
						         $loopnew = replaceStr($loopnew, $matchfieldvalue, $row['m_publisharea']);
					        break;
					        case "commend":
						        $loopnew = replaceStr($loopnew, $matchfieldvalue, $row['m_commend']);
					        break;
					        case "from":
						        $loopnew = replaceStr($loopnew, $matchfieldvalue, getFromStr($row['m_playdata']));
					        break;
							case "keyword":
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, getKeywordsList($row['m_keyword']));
				            break;
							case "digg":
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, $row['m_digg']);
				            break;
						    case "tread":
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, $row['m_tread']);
				            break;
							case "director":
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, getKeywordsList($row['m_director']," "));
				            break;
						    case "lang":
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, $row['m_lang']);
				            break;
							case "dayhit":
							    $loopnew = replaceStr($loopnew,$matchfieldvalue,$row['m_dayhit']);
							break;
						    case "weekhit":
							    $loopnew = replaceStr($loopnew,$matchfieldvalue,$row['m_weekhit']);
							break;
						    case "monthhit":
							    $loopnew = replaceStr($loopnew,$matchfieldvalue,$row['m_monthhit']);
							break;
						    case "score":
							    $loopnew = replaceStr($loopnew,$matchfieldvalue,$row['m_score']);
							break;
						}
					}
				    $i = $i + 1;
				    $loopstrTotal .= $loopnew;
				}
			}
			self::$content = replaceStr(self::$content, $ar[0][$m], $loopstrTotal);
			preg_match_all(buildregx($labelRulePagelist, "is"), self::$content, $plar);
			$plarlen = count($plar[1]);
			for ($p = 0;$p < $plarlen;$p++) {
				if ($recordcount == 0) {
					self::$content = replaceStr(self::$content, $plar[0][$p], "");
				} else {
					$fieldAttrarr=self::parseAttr($plar[1][$p]);$lenPagelist=empty($fieldAttrarr['len']) ? "10" : intval($fieldAttrarr['len']);
					$strPagelist = pageNumberLinkInfo($currentPage, $lenPagelist, $totalPages, $pageListType, $recordcount);
					self::$content = replaceStr(self::$content, $plar[0][$p], $strPagelist);
			    }
		    }
			$tPages=ifthen($totalPages==0,1,$totalPages);
			if (strpos(self::$content,"{/".$pageListType."list:pagenumber}")>0){
				preg_match_all(buildregx($labelRulePagelist2, "is"), self::$content, $plarl);
				$plarllen = count($plarl[1]);
				for ($p = 0;$p < $plarllen;$p++) {
					$fieldAttrarr = self::parseAttr($plarl[1][$p]);
					$lenPagelist = empty($fieldAttrarr['len']) ? "10" : intval($fieldAttrarr['len']);
					$strPagelist = $plarl[2][$p];
					$strPagelist = makePagenumberLoop($currentPage,$lenPagelist,$tPages,$pageListType,$strPagelist);
					self::$content = replaceStr(self::$content,$plarl[0][$p],$strPagelist);
		        }
		    }
			$content = replaceStr(self::$content,"{".$pageListType."list:page}",$currentPage);
			$content = replaceStr($content,"{".$pageListType."list:pagecount}",$tPages);
			$content = replaceStr($content,"{".$pageListType."list:recordcount}",$recordcount);
			$content = replaceStr($content,"{".$pageListType."list:firstlink}",getPageLink(1,$pageListType));
			$content = replaceStr($content,"{".$pageListType."list:backlink}",getPageLink(ifthen($currentPage>1,$currentPage-1,1),$pageListType));
			$content = replaceStr($content,"{".$pageListType."list:nextlink}",getPageLink(ifthen($currentPage<$tPages,$currentPage+1,$tPages),$pageListType));
			self::$content = replaceStr($content,"{".$pageListType."list:lastlink}",getPageLink($tPages,$pageListType));
        }
	}
	
	public static function getMenuArray($sId,$m,$by){
		if ($by == "news"){
			return self::getMenuByArray($sId,$m,getNewsTypeLists());
	    } else {
			return self::getMenuByArray($sId,$m,getTypeLists());
	    }
	}

	public static function getMenuByArray($sId, $m, $ary) {
	    $i = 0;
		$rsArray=array();
	    $tlist = $ary;
	    if ($m == "m_id") $m = "m_id";else $m = "m_upid";
	    foreach ($tlist as $row) {
		    if (strpos(" ,".$sId.",", ",".$row[$m].",") > 0 && $row['m_hide'] == 0) {
			    $rsArray[$i]['m_id'] = $row['m_id'];
			    $rsArray[$i]['m_upid'] = $row['m_upid'];
			    $rsArray[$i]['m_name'] = $row['m_name'];
			    $i++;
		    }
	   }
	   return $rsArray;
    }

    public static function parseMenuList($str = "") {
		$labelRule = "{djcms:".$str."menulist(.*?)}(.*?){/djcms:".$str."menulist}";
		$labelRuleField = "\[".$str."menulist:(.*?)\]";
		$attrDictionary=array();
		preg_match_all(buildregx($labelRule,"is"), self::$content, $mar);
		$len = count($mar[1]);
		for ($m = 0;$m < $len;$m++) {
			$loopstrTotal = "";
			$labelAttrMenulist = trim(preg_replace("/[ \r\n\t\f]{1,}/"," ",$mar[1][$m]));
			$loopstrMenulist = $mar[2][$m];
			$att = self::parseAttr($labelAttrMenulist);
			$vtype = empty($att["type"]) ? "top" : $att["type"];
			$vby = empty($att["by"]) ? "" : $att["by"];
			unset($att);
			switch (trim($vtype)) {
			    case "top":
				    $rsArray = self::getMenuArray(0, "m_upid", $vby);
				break;
				case "son":
					if ($vby == "news") { 
					    $curUpIdStr=getNewsTypeNameTemplateArrayOnCache(intval(self::$currentTypeId));
				    }else{ 
					    $curUpIdStr=getTypeNameTemplateArrayOnCache(intval(self::$currentTypeId));
					}
					$curUpIdStrArray = explode(",", $curUpIdStr);
					if (count($curUpIdStrArray) == 2){ 
					    $curUpId = $curUpIdStrArray[2]; 
					}else{ 
					    $curUpId=-444;
					}
					if ($curUpId=="") $curUpId=0;
					if (intval($curUpId) != 0){
						$rsArray=self::getMenuArray($curUpId,"m_upid",$vby);
					}else{
						$rsArray=self::getMenuArray(self::$currentTypeId,"m_upid",$vby);
					}
				break;
				case "all":
					$loopstrTotal = getAllMenuListOnCache(0, $vby);
				break;
				default:
					$vtypear = explode(',', $vtype);
					foreach ($vtypear as $vtypestr){
						$vtypearr[] = trim($vtypestr);
						if (!is_numeric(trim($vtypestr))) exit($lang['channellistInfo']['1']);
					}
				    $vtype = implode(',', $vtypearr);
				    unset($vtypearr);
				    if (empty($str)) {
					    $rsArray = self::getMenuArray($vtype, "m_id", $vby);
				    } else {
					    $rsArray = self::getMenuArray($vtype, "m_upid", $vby);
				    }
			}
			preg_match_all(buildregx($labelRuleField,"is"), $loopstrMenulist, $menuar);
			$matchfieldarr = $menuar[1];
			$matchfieldstrarr = $menuar[0];
			$i = 1;
			if (is_array($rsArray)) {
				foreach ($rsArray as $row) {
					$loopnew = $loopstrMenulist;
					if ($vby == "news"){
					    $tlink = getNewsTypeLink($row['m_id']);
				    }else{
					    $tlink = getTypeLink($row['m_id']);
					}
					foreach ($matchfieldarr as $f => $matchfieldstr) {
						$matchfieldvalue = $matchfieldstrarr[$f];
						$matchfieldstr = trim(preg_replace("/[ \r\n\t\f]{1,}/"," ",$matchfieldstr));
						if (strpos($matchfieldstr, chr(32)) > 0) {
							$fieldtemparr = explode(chr(32), $matchfieldstr);
							$fieldName = $fieldtemparr[0];
							$fieldAttr = $fieldtemparr[1];
						} else {
							$fieldName = $matchfieldstr;
							$fieldAttr = "";
						}
					    switch (trim($fieldName)) {
						    case "i":
							    $loopnew = replaceStr($loopnew,$matchfieldvalue, $i);
						    break;
						    case "typeid":
							    $loopnew = replaceStr($loopnew,$matchfieldvalue, $row['m_id']);
						    break;
						    case "typename":
							    $loopnew = replaceStr($loopnew,$matchfieldvalue, $row['m_name']);
						    break;
						    case "upid":
							    $loopnew = replaceStr($loopnew,$matchfieldvalue, $row['m_upid']);
						    break;
						    case "link":
							    $loopnew = replaceStr($loopnew,$matchfieldvalue, $tlink);
						    break;
					    }
				    }
					$i = $i + 1;
					$loopstrTotal.=$loopnew;
			    }
				unset($rsArray);
		    }
			self::$content = replaceStr(self::$content, $mar[0][$m], $loopstrTotal);
		}
		if (isExistStr(self::$content, "{djcms:smallmenulist")) self::parseMenuList("small");
	}

	public static function parseTopicList() {
		if (isExistStr(self::$content, "{djcms:topiclist")) {
		    $attrDictionary=array();
		    $labelRule = "{djcms:topiclist(.*?)}(.*?){/djcms:topiclist}";
		    $labelRuleField = "\[topiclist:(.*?)\]";
		    preg_match_all(buildregx($labelRule, "is"), self::$content, $ar);
		    $len = count($ar[1]);
		    for ($m = 0;$m < $len;$m++) {
			    $labelAttrTopiclist = trim(preg_replace("/[ \r\n\t\f]{1,}/"," ",$ar[1][$m]));
			    $loopstrTopiclist = $ar[2][$m];
			    $attrDictionary = self::parseAttr($labelAttrTopiclist);
			    $vtid=empty($attrDictionary["id"]) ? "all" : $attrDictionary["id"];
				$vnum=empty($attrDictionary["num"]) ? "10" : $attrDictionary["num"];
				$vstart = empty($attrDictionary['start']) ? 0 : intval($attrDictionary['start'])-1;
			    unset($attrDictionary);
			    switch ($vtid){
				    case "all" : $whereTopic = "";break;
				    default:
				        if (strpos($vtid, ",") > 0){ $whereTopic = " WHERE m_id IN(".$vtid.")"; } else { $whereTopic = " WHERE m_id=".$vtid;}
			    }
			    $sql="SELECT m_name,m_id,m_pic,m_enname,m_des FROM ".DB::table('topic')." $whereTopic ORDER BY m_sort ASC LIMIT $vstart, $vnum";
			    preg_match_all(buildregx($labelRuleField, "is"), self::$content, $lar);
			    $matchfieldarr = $lar[1];
			    $matchfieldstrarr = $lar[0];
			    $loopstrTotal = "";
			    $i = 1;
				$query = DB::query($sql);
                while($row = DB::fetch($query)) {
				    $loopstrTopiclistNew = $loopstrTopiclist;
				    foreach ($matchfieldarr as $f => $matchfieldstr) {
					    $matchfieldvalue = $matchfieldstrarr[$f];
						$matchfieldstr = trim(preg_replace("/[ \r\n\t\f]{1,}/"," ",$matchfieldstr));
					    if (strpos($matchfieldstr, chr(32)) > 0) {
						    $fieldtemparr = explode(chr(32), $matchfieldstr);
						    $fieldName = $fieldtemparr[0];
						    $fieldAttr = $fieldtemparr[1];
					    } else {
						    $fieldName = $matchfieldstr;
						    $fieldAttr = "";
					    }
					    switch (trim($fieldName)){
						    case "i":
							    $loopstrTopiclistNew = replaceStr($loopstrTopiclistNew, $matchfieldvalue, $i);
						    break;
						    case "name":
							    $m_name = $row['m_name'];
							    $fieldAttrarr=self::parseAttr($fieldAttr);$namelen=empty($fieldAttrarr['len']) ? "" : intval($fieldAttrarr['len']);
							    $m_name=!empty($namelen)&&strlen($m_name)>$namelen ? msubstr($m_name,$namelen) : $m_name;
							    $loopstrTopiclistNew = replaceStr($loopstrTopiclistNew, $matchfieldvalue, $m_name);
						    break;
						    case "count":
							    $count = getcount('data', array('m_topic' => $row['m_id']));
							    $loopstrTopiclistNew = replaceStr($loopstrTopiclistNew, $matchfieldvalue, $count);
						    break;
						    case "pic":
							    if (!empty($row['m_pic'])){
								    if (isExistStr($row['m_pic'], '://')) {
									    $loopstrTopiclistNew = replaceStr($loopstrTopiclistNew, $matchfieldvalue, $row['m_pic']);
								    } else {
									    $loopstrTopiclistNew = replaceStr($loopstrTopiclistNew, $matchfieldvalue, "/".sitePath."pic/zt/".$row['m_pic']);
								    }
							    } else {
								    $loopstrTopiclistNew = replaceStr($loopstrTopiclistNew, $matchfieldvalue, "/".sitePath."pic/nopic.gif");
							    }
						    break;
						    case "link":
							    $loopstrTopiclistNew = replaceStr($loopstrTopiclistNew, $matchfieldvalue, getTopicPageLink($row['m_id'],1));
						    break;
						    case "des":
							    $m_des = decodeHtml($row['m_des']);
							    $fieldAttrarr=self::parseAttr($fieldAttr);$deslen=empty($fieldAttrarr['len']) ? "200" : intval($fieldAttrarr['len']);
							    $m_des=strlen($m_des)>$deslen ? msubstr($m_des,$deslen) : $m_des;
							    $loopstrTopiclistNew = replaceStr($loopstrTopiclistNew, $matchfieldvalue, $m_des);
						    break;
					    }
				    }
				    $i = $i + 1;
				    $loopstrTotal .= $loopstrTopiclistNew;
		        }
			    self::$content = replaceStr(self::$content, $ar[0][$m], $loopstrTotal);
	        }
		}
	}

    public static function parseTopicIndex($currentPage,$totalPages){
		global $lang;
		if (isExistStr(self::$content,"{djcms:topicindexlist")){
			$attrDictionary=array();
			$labelRule = "{djcms:topicindexlist(.*?)}(.*?){/djcms:topicindexlist}";
		    $labelRuleField = "\[topicindexlist:(.*?)\]";
		    $labelRulePagelist = "\[topicindexlist:pagenumber(.*?)\]";
			$labelRulePagelist2="\{topicindexlist:pagenumber(.*?)\}(.*?){/topicindexlist:pagenumber}";
		    preg_match_all(buildregx($labelRule, "is"), self::$content, $ar);
		    $len = count($ar[1]);
		    for ($m = 0;$m < $len;$m++) {
			    $loopstrTotal="";
				$attrChannel = trim(preg_replace("/[ \r\n\t\f]{1,}/"," ",$ar[1][$m]));
			    $loopstrChannel = $ar[2][$m];
		        $attrDictionary = self::parseAttr($attrChannel);
				$vsize=empty($attrDictionary["size"]) ? 12 : intval($attrDictionary["size"]);
				unset($attrDictionary);
				$recordcount = getcount('topic');
				$totalPages = ceil($recordcount/$vsize);
				$page = max(intval($currentPage), 1);
                $offset = $vsize*($page-1);
			    preg_match_all(buildregx($labelRuleField, "is"), self::$content, $lar);
		        $matchfieldarr = $lar[1];
		        $matchfieldstrarr = $lar[0];
			    $i = 1;
				if ($recordcount == 0) {
				    $loopstrTotal=$lang['topicpageInfo']['0'];
				}else{
					$query = DB::query("select m_name,m_id,m_pic,m_enname,m_des from ".DB::table('topic')." ORDER BY m_sort asc limit $offset, $vsize");
                    while($row = DB::fetch($query)) {
			            $loopstrTopiclistNew = $loopstrChannel;
				        foreach ($matchfieldarr as $f => $matchfieldstr) {
					        $matchfieldvalue = $matchfieldstrarr[$f];
							$matchfieldstr = trim(preg_replace("/[ \r\n\t\f]{1,}/"," ",$matchfieldstr));
					        if (strpos($matchfieldstr, chr(32)) > 0) {
						        $fieldtemparr = explode(chr(32), $matchfieldstr);
						        $fieldName = $fieldtemparr[0];
						        $fieldAttr = $fieldtemparr[1];
					        } else {
						        $fieldName = $matchfieldstr;
						        $fieldAttr = "";
					        }
				            switch (trim($fieldName)) {
							    case "i":
								    $loopstrTopiclistNew=replaceStr($loopstrTopiclistNew,$matchfieldvalue,$i+1);
							    break;
							    case "name":
								    $loopstrTopiclistNew=replaceStr($loopstrTopiclistNew,$matchfieldvalue,$row['m_name']);
							    break;
							    case "count":
								    $count = getcount('data', array('m_topic' => $row['m_id']));
							        $loopstrTopiclistNew = replaceStr($loopstrTopiclistNew, $matchfieldvalue, $count);
							    break;
							    case "pic":
					                if (!empty($row['m_pic'])) {
						                if (isExistStr(strtolower($row['m_pic']), '://')) {
						                    $loopstrTopiclistNew = replaceStr($loopstrTopiclistNew, $matchfieldvalue, $row['m_pic']);
					                    } else {
						                    $loopstrTopiclistNew = replaceStr($loopstrTopiclistNew, $matchfieldvalue, '/'.sitePath."pic/zt/".$row['m_pic']);
					                    }
					                } else {
						                $loopstrTopiclistNew = replaceStr($loopstrTopiclistNew, $matchfieldvalue, '/'.sitePath.'pic/nopic.gif');
					                }
					            break;
							    case "link":
								    $loopstrTopiclistNew=replaceStr($loopstrTopiclistNew,$matchfieldvalue,getTopicPageLink($row['m_id'],1,$row['m_enname']));
							    break;
							    case "des":
							        $m_des = decodeHtml($row['m_des']);
							        $fieldAttrarr=self::parseAttr($fieldAttr);$deslen=empty($fieldAttrarr['len']) ? "200" : intval($fieldAttrarr['len']);
							        $m_des=strlen($m_des)>$deslen ? msubstr($m_des,$deslen) : $m_des;
							        $loopstrTopiclistNew = replaceStr($loopstrTopiclistNew, $matchfieldvalue, $m_des);
							    break;
						    }
					    }
					    $i = $i + 1;
					    $loopstrTotal .= $loopstrTopiclistNew;
			        }
			    }
			    self::$content = replaceStr(self::$content, $ar[0][$m], $loopstrTotal);
			    preg_match_all(buildregx($labelRulePagelist, "is"), self::$content, $plar);
			    $plarlen = count($plar[1]);
			    for ($p = 0;$p < $plarlen;$p++) {
				    if ($recordcount == 0) {
					    self::$content = replaceStr(self::$content, $plar[0][$p], "");
				    } else {
					    $fieldAttrarr=self::parseAttr($plar[1][$p]);$lenPagelist=empty($fieldAttrarr['len']) ? "10" : intval($fieldAttrarr['len']);
					    $strPagelist = pageNumberLinkInfo($currentPage, $lenPagelist, $totalPages, "topicindex", $recordcount);
					    self::$content = replaceStr(self::$content, $plar[0][$p], $strPagelist);
			        }
		        }
				$tPages=ifthen($totalPages==0,1,$totalPages);
			    if (strpos(self::$content,"{/topicindexlist:pagenumber}")>0){
				    preg_match_all(buildregx($labelRulePagelist2, "is"), self::$content, $plarl);
				    $plarllen = count($plarl[1]);
				    for ($p = 0;$p < $plarllen;$p++) {
					    $fieldAttrarr=self::parseAttr($plarl[1][$p]);
					    $lenPagelist=empty($fieldAttrarr['len']) ? "10" : intval($fieldAttrarr['len']);
					    $strPagelist=$plarl[2][$p];
					    $strPagelist=makePagenumberLoop($currentPage,$lenPagelist,$tPages,"topicindex",$strPagelist);
					    self::$content=replaceStr(self::$content,$plarl[0][$p],$strPagelist);
		            }
		        }
			    $content=replaceStr(self::$content,"{topicindexlist:page}",$currentPage);
			    $content=replaceStr($content,"{topicindexlist:pagecount}",$tPages);
			    $content=replaceStr($content,"{topicindexlist:recordcount}",$recordcount);
			    $content=replaceStr($content,"{topicindexlist:firstlink}",getPageLink(1,"topicindex"));
			    $content=replaceStr($content,"{topicindexlist:backlink}",getPageLink(ifthen($currentPage>1,$currentPage-1,1),"topicindex"));
			    $content=replaceStr($content,"{topicindexlist:nextlink}",getPageLink(ifthen($currentPage<$tPages,$currentPage+1,$tPages),"topicindex"));
			    self::$content=replaceStr($content,"{topicindexlist:lastlink}",getPageLink($tPages,"topicindex"));
            }
		}
	}
	
	public static function parseLinkList() {
		if (isExistStr(self::$content, "{djcms:linklist")) {
		    $attrDictionary=array();
		    $labelRule = "{djcms:linklist(.*?)}(.*?){/djcms:linklist}";
		    $labelRuleField = "\[linklist:(.*?)\]";
		    preg_match_all(buildregx($labelRule, "is"), self::$content, $ar);
		    $len = count($ar[1]);
		    for ($m = 0;$m < $len;$m++) {
		        $labelAttrLinklist = trim(preg_replace("/[ \r\n\t\f]{1,}/"," ",$ar[1][$m]));
		        $loopstrLinklist = $ar[2][$m];
		        $attrDictionary = self::parseAttr($labelAttrLinklist);
		        $vtype=empty($attrDictionary["type"]) ? "font" : $attrDictionary["type"];
			    unset($attrDictionary);
		        switch ($vtype) {
			        case "font" :
			            $whereStr = "WHERE m_type='font'".chr(32);break;
			        case "pic" :
			            $whereStr = "WHERE m_type='pic'".chr(32);break;
			        default :
			            $whereStr = "WHERE m_type='font'".chr(32);break;
		        }
		        $sql = "SELECT m_name,m_pic,m_url,m_des FROM ".DB::table('link')." $whereStr ORDER BY m_sort";
		        preg_match_all(buildregx($labelRuleField, "is"), $loopstrLinklist, $flar);
		        $matchfieldarr = $flar[1];
		        $matchfieldstrarr = $flar[0];
		        $loopstrTotal = "";
		        $i = 1;
				$query = DB::query($sql);
                while($row = DB::fetch($query)) {
		            $loopstrLinklistNew = $loopstrLinklist;
		            foreach ($flar[1] as $f => $matchfieldstr) {
					    $matchfieldvalue = $matchfieldstrarr[$f];
						$matchfieldstr = trim(preg_replace("/[ \r\n\t\f]{1,}/"," ",$matchfieldstr));
					    if (strpos($matchfieldstr, chr(32)) > 0) {
					        $fieldtemparr = explode(chr(32), $matchfieldstr);
					        $fieldName = $fieldtemparr[0];
					        $fieldAttr = $fieldtemparr[1];
					    } else {
					        $fieldName = $matchfieldstr;
					        $fieldAttr = "";
					    }
					    switch (trim($fieldName)) {
						    case "name":
						        $fieldAttrarr=self::parseAttr($fieldAttr);$namelen=empty($fieldAttrarr['len']) ? "8" : intval($fieldAttrarr['len']);
							    $loopstrLinklistNew = replaceStr($loopstrLinklistNew, $matchfieldvalue, msubstr($row['m_name'], intval($namelen)));
						    break;
						    case "link":
						        $loopstrLinklistNew = replaceStr($loopstrLinklistNew, $matchfieldvalue, $row['m_url']);
						    break;
						    case "pic":
						        $loopstrLinklistNew = replaceStr($loopstrLinklistNew, $matchfieldvalue, $row['m_pic']);
						    break;
						    case "des":
							    $m_des = decodeHtml($row['m_des']);
							    $fieldAttrarr=self::parseAttr($fieldAttr);$deslen=empty($fieldAttrarr['len']) ? "100" : intval($fieldAttrarr['len']);
							    $m_des=!empty($deslen)&&strlen($m_des)>$deslen ? msubstr($m_des,$deslen) : $m_des;
							    $loopstrLinklistNew = replaceStr($loopstrLinklistNew, $matchfieldvalue, $m_des);
						    break;
						    case "i":
						        $loopstrLinklistNew = replaceStr($loopstrLinklistNew, $matchfieldvalue, $i);
						    break;
					    }
		            }
		            $i = $i + 1;
		            $loopstrTotal .= $loopstrLinklistNew;
		        }
		        self::$content = replaceStr(self::$content,$ar[0][$m],$loopstrTotal);
		    }
		}
	}

	public static function parsePlayList($typeid,$dataId,$enname,$sDate,$playORdownData,$str){
		if (isExistStr(self::$content, "{playpage:playlist") || isExistStr(self::$content, "{playpage:downlist")) {
		    $labelRule = "{playpage:".$str."list(.*?)}(.*?){/playpage:".$str."list}";
		    $labelRuleField = "\[".$str."list:(.*?)\]";
	        preg_match_all(buildregx($labelRule, "is"), self::$content, $ar);
		    $arlen = count($ar[1]);
		    for ($m = 0;$m < $arlen;$m++) {
			    $loopstrPlaylist = $ar[2][$m];
				if ($str == 'play') {
				    if (IsFromSort==1) $playORdownData=ResetFromSort($playORdownData);
				}
		        $playDataArray = getPlayurlArray($playORdownData);
			    $vnum = count($playDataArray);
			    preg_match_all(buildregx($labelRuleField, "is"), $loopstrPlaylist, $lar);
			    $matchfieldarr = $lar[1];
			    $matchfieldstrarr = $lar[0];
			    $loopstrTotal = '';$i_2 = 0;
			    for ($i = 0;$i <= $vnum;$i++) {
					$singlePlayData=explode("$$",$playDataArray[$i]);$videoFrom=$i;$videoUrl=$singlePlayData[1];
				    $playerInfoStr = getPlayerIntroOnCache($str,$singlePlayData[0]);
					if (isExistStr($playerInfoStr,"__djcms__")){
						$playerSingleInfoArray=explode("__djcms__",$playerInfoStr);
					    $loopstrPlaylistNew=$loopstrPlaylist;
						if ($playerSingleInfoArray[1]=="1"){
					        $i_2 = $i_2 + 1;
					        foreach($matchfieldarr as $f => $matchfieldstr) {
					            $matchfieldvalue = $matchfieldstrarr[$f];
							    $matchfieldstr = trim(preg_replace("/[ \r\n\t\f]{1,}/"," ",$matchfieldstr));
					            if (strpos($matchfieldstr, chr(32)) > 0) {
					                $fieldtemparr = explode(chr(32), $matchfieldstr);
					                $fieldName = $fieldtemparr[0];
					                $fieldAttr = $fieldtemparr[1];
					            } else {
					                $fieldName = $matchfieldstr;
					                $fieldAttr = "";
					            }
					            switch (trim($fieldName)) {
						            case "from":
							            $loopstrPlaylistNew = replaceStr($loopstrPlaylistNew, $matchfieldvalue, $singlePlayData[0]);
						            break;
						            case "intro":
							            $loopstrPlaylistNew = replaceStr($loopstrPlaylistNew, $matchfieldvalue, $playerSingleInfoArray[0]);
						            break;
						            case "link":
							            $fieldAttrarr=self::parseAttr($fieldAttr);$target=empty($fieldAttrarr['target']) ? "" : intval($fieldAttrarr['target']);
									    $urlStr=getPlayUrlList($videoFrom,$videoUrl,$typeid,$dataId,$enname,$sDate,$str,$target);
							            $loopstrPlaylistNew = replaceStr($loopstrPlaylistNew, $matchfieldvalue, $urlStr);
						            break;
						            case "i":
							            $loopstrPlaylistNew = replaceStr($loopstrPlaylistNew, $matchfieldvalue, $i_2);
						            break;
					            }

				            }
				        } else {
					        $loopstrPlaylistNew = "";
				        }
					}else{
					    $loopstrPlaylistNew = "";
					}
				    $loopstrTotal .= $loopstrPlaylistNew;
			    }
			    self::$content = replaceStr(self::$content, $ar[0][$m], $loopstrTotal);
		        self::$content = replaceStr(self::$content, "{playpage:".$str."listlen}", $i_2);
            }
		}
	}
    
	public static function parseNews($row) {
		$labelRule = "\{news:(.*?)\}";
		$content = self::$content;
		preg_match_all(buildregx($labelRule, "is"), self::$content, $lar);
		$matchfieldarr = $lar[1];
		$matchfieldstrarr = $lar[0];
		foreach ($matchfieldarr as $f => $matchfieldstr) {
			$matchfieldvalue = $matchfieldstrarr[$f];
			$matchfieldstr = trim(preg_replace("/[ \r\n\t\f]{1,}/"," ",$matchfieldstr));
			if (strpos($matchfieldstr, chr(32)) > 0) {
				$fieldtemparr = explode(chr(32), $matchfieldstr);
				$fieldName = $fieldtemparr[0];
				$fieldAttr = $fieldtemparr[1];
			} else {
				$fieldName = $matchfieldstr;
				$fieldAttr = "";
			}
			switch (trim($fieldName)) {
				case "hit":
				    $content = replaceStr($content, $matchfieldvalue,"<span id=\"hit\">加载中</span><script>getNewsHit('".$row['m_id']."')</script>");
				break;
				case "title":case "name":
				    $m_title = $row['m_title'];
					$fieldAttrarr=self::parseAttr($fieldAttr);$m_titlelen=empty($fieldAttrarr['len']) ? "" : intval($fieldAttrarr['len']);
					$m_title=!empty($m_titlelen)&&strlen($m_title)>$m_titlelen ? msubstr($m_title,$m_titlelen) : $m_title;
					$content = replaceStr($content, $matchfieldvalue, $m_title);
					break;
				case "colortitle":case "colorname":
				    $m_color = $row['m_color'];$m_name = $row['m_title'];
					$fieldAttrarr=self::parseAttr($fieldAttr);$colornamelen=empty($fieldAttrarr['len']) ? "" : intval($fieldAttrarr['len']);
					$m_name=!empty($colornamelen)&&strlen($m_name)>$colornamelen ? msubstr($m_name,$colornamelen) : $m_name;
					if (!empty($m_color)) $m_name = "<font color=".$m_color.">".$m_name."</font>";
					$content = replaceStr($content, $matchfieldvalue, $m_name);
				break;
				case "outline":
				    $m_note = $row['m_outline'];
					$fieldAttrarr=self::parseAttr($fieldAttr);$notelen=empty($fieldAttrarr['len']) ? "" : intval($fieldAttrarr['len']);
					$m_note=!empty($notelen)&&strlen($m_note)>$notelen ? msubstr($m_note,$notelen) : $m_note;
					$content = replaceStr($content, $matchfieldvalue, $m_note);
				break;
				case "content":case "des":
					$m_des = decodeHtml($row['m_content']);
					$fieldAttrarr=self::parseAttr($fieldAttr);$deslen=empty($fieldAttrarr['len']) ? "" : intval($fieldAttrarr['len']);
					$m_des=!empty($deslen)&&strlen($m_des)>$deslen ? msubstr($m_des,$deslen) : $m_des;
					$content = replaceStr($content, $matchfieldvalue, $m_des);
				break;
				case "addtime":
				    $fieldAttrarr=self::parseAttr($fieldAttr);$timestyle=empty($fieldAttrarr['style']) ? "m-d" : $fieldAttrarr['style'];
					$videoTime = $row['m_addtime'];
				    switch (trim($timestyle)) {
					    case "yyyy-mm-dd":
				            $content = replaceStr($content, $matchfieldvalue, date("Y-m-d", $videoTime));
					    break;
					    case "yy-mm-dd":
				            $content = replaceStr($content, $matchfieldvalue, date("y-m-d", $videoTime));
					    break;
					    case "y-m-d":
				            $content = replaceStr($content, $matchfieldvalue, date("Y-n-d", $videoTime));
					    break;
					    default:
						    $content = replaceStr($content, $matchfieldvalue, date($timestyle, $videoTime));
				    }
				break;
			}
		}
		self::$content = $content;
	}
	
	public static function parseVideo($row) {
		$labelRule = "\{playpage:(.*?)\}";
		$content = self::$content;
		preg_match_all(buildregx($labelRule, "is"), self::$content, $lar);
		$matchfieldarr = $lar[1];
		$matchfieldstrarr = $lar[0];
		foreach ($matchfieldarr as $f => $matchfieldstr) {
			$matchfieldvalue = $matchfieldstrarr[$f];
			$matchfieldstr = trim(preg_replace("/[ \r\n\t\f]{1,}/"," ",$matchfieldstr));
			if (strpos($matchfieldstr, chr(32)) > 0) {
				$fieldtemparr = explode(chr(32), $matchfieldstr);
				$fieldName = $fieldtemparr[0];
				$fieldAttr = $fieldtemparr[1];
			} else {
				$fieldName = $matchfieldstr;
				$fieldAttr = "";
			}
			switch (trim($fieldName)) {
				case "name":
				    $m_title = $row['m_name'];
					$fieldAttrarr=self::parseAttr($fieldAttr);$m_titlelen=empty($fieldAttrarr['len']) ? "" : intval($fieldAttrarr['len']);
					$m_title=!empty($m_titlelen)&&strlen($m_title)>$m_titlelen ? msubstr($m_title,$m_titlelen) : $m_title;
					$content = replaceStr($content, $matchfieldvalue, $m_title);
					break;
				case "colorname":
				    $m_color = $row['m_color'];$m_name = $row['m_name'];
					$fieldAttrarr=self::parseAttr($fieldAttr);$colornamelen=empty($fieldAttrarr['len']) ? "" : intval($fieldAttrarr['len']);
					$m_name=!empty($colornamelen)&&strlen($m_name)>$colornamelen ? msubstr($m_name,$colornamelen) : $m_name;
					if (!empty($m_color)) $m_name = "<font color=".$m_color.">".$m_name."</font>";
					$content = replaceStr($content, $matchfieldvalue, $m_name);
				break;
				case "hits":
					$content = replaceStr($content, $matchfieldvalue, $row['m_hit']);
				break;
				case "note":
				 	$m_note = $row['m_note'];
					$fieldAttrarr=self::parseAttr($fieldAttr);$notelen=empty($fieldAttrarr['len']) ? "" : intval($fieldAttrarr['len']);
					$m_note=!empty($notelen)&&strlen($m_note)>$notelen ? msubstr($m_note,$notelen) : $m_note;
					$content = replaceStr($content, $matchfieldvalue, $m_note);
				break;
				case "actor":
					$m_actor = $row['m_actor'];
					$fieldAttrarr=self::parseAttr($fieldAttr);$actorlen=empty($fieldAttrarr['len']) ? "" : intval($fieldAttrarr['len']);
					$m_actor=!empty($actorlen)&&strlen($m_actor)>$actorlen ? msubstr($m_actor,$actorlen) : getKeywordsList($m_actor,"&nbsp;&nbsp;");
					$content = replaceStr($content, $matchfieldvalue, $m_actor);
				break;
				case "nolinkactor":
					$m_actor = $row['m_actor'];
					$fieldAttrarr=self::parseAttr($fieldAttr);$actorlen=empty($fieldAttrarr['len']) ? "" : intval($fieldAttrarr['len']);
					$m_actor=!empty($actorlen)&&strlen($m_actor)>$actorlen ? msubstr($m_actor,$actorlen) : $m_actor;
					$content = replaceStr($content, $matchfieldvalue, $m_actor);
				break;
				case "des":
					$m_des = doPseudo(decodeHtml($row['m_des']),$row['m_id']);
					$fieldAttrarr=self::parseAttr($fieldAttr);$deslen=empty($fieldAttrarr['len']) ? "" : intval($fieldAttrarr['len']);
					$m_des=!empty($deslen)&&strlen($m_des)>$deslen ? msubstr($m_des,$deslen) : $m_des;
					$content = replaceStr($content, $matchfieldvalue, $m_des);
				break;
				case "addtime":
				    $fieldAttrarr=self::parseAttr($fieldAttr);$timestyle=empty($fieldAttrarr['style']) ? "m-d" : $fieldAttrarr['style'];
					$videoTime = $row['m_addtime'];
				    switch (trim($timestyle)) {
					    case "yyyy-mm-dd":
				            $content = replaceStr($content, $matchfieldvalue, date("Y-m-d", $videoTime));
					    break;
					    case "yy-mm-dd":
				            $content = replaceStr($content, $matchfieldvalue, date("y-m-d", $videoTime));
					    break;
					    case "y-m-d":
				            $content = replaceStr($content, $matchfieldvalue, date("Y-n-d", $videoTime));
					    break;
					    default:
						    $content = replaceStr($content, $matchfieldvalue, date($timestyle, $videoTime));
				    }
				break;
			}
		}
		self::$content = $content;
	}

    public static function parseNewsList(){
		if (isExistStr(self::$content,"{djcms:newslist")){
		    $n=0;$ni=1;
		    $labelRule="{djcms:newslist(.*?)}(.*?){/djcms:newslist}";
		    $labelRuleField="\[newslist:(.*?)\]";
			preg_match_all(buildregx($labelRule,"is"), self::$content, $ar);
		    $arlen = count($ar[1]);
		    for ($m = 0;$m < $arlen;$m++) {
		        $labelAttrVideolist = trim(preg_replace("/[ \r\n\t\f]{1,}/"," ",$ar[1][$m]));
		        $loopstrVideoList = $ar[2][$m];
				$attrDictionary = self::parseAttr($labelAttrVideolist);
			    $vnum = empty($attrDictionary['num']) ? 10 : intval($attrDictionary['num']);
		        $vorder = empty($attrDictionary['order']) ? '' : $attrDictionary['order'];
			    $vletter = empty($attrDictionary['letter']) ? '' : $attrDictionary['letter'];
		        $vtype = empty($attrDictionary['type']) ? 'all' : $attrDictionary['type'];
		        $vtime = empty($attrDictionary['time']) ? "" : $attrDictionary['time'];
		        $vstart = empty($attrDictionary['start']) ? 0 : intval($attrDictionary['start'])-1;
		        $vcommend = empty($attrDictionary['commend']) ? '' : $attrDictionary['commend'];
			    $vid = empty($attrDictionary['id']) ? '' : $attrDictionary['id'];
				$avid = empty($attrDictionary['vid']) ? '' : $attrDictionary['vid'];
			    unset($attrDictionary);
				if (empty($vorder) && empty($vid)) $vorder = "time";
			    if (empty($vorder)) $vorder = "id";
			    switch ($vorder) {
				    case "id":$orderStr =" ORDER BY m_id DESC";break;
				    case "hit":$orderStr =" ORDER BY m_hit DESC";break;
				    case "dayhit":$orderStr =" ORDER BY m_dayhit DESC";break;
				    case "weekhit":$orderStr =" ORDER BY m_weekhit DESC";break;
				    case "monthhit":$orderStr =" ORDER BY m_monthhit DESC";break;
				    case "time":$orderStr =" ORDER BY m_addtime DESC";break;
				    case "commend":$orderStr =" ORDER BY m_commend DESC";break;
				    case "digg" : $orderStr =" ORDER BY m_digg DESC";break;
					case "random" : $orderStr = " ORDER BY rand() DESC";break;
				}
				if (empty($vtype)) $vtype = 'all';
		        $vtypeStr = '';
		        if ($vtype != 'all') {
			        if ($vtype == 'current') {
				        $vtypeStr = getNewsTypeIdOnCache(self::$currentTypeId);
			        } else {
					    if (strpos($vtype,',')>0) {
				            $vtypeArray=explode(",",$vtype);
				            foreach ($vtypeArray as $vtypestra){
				                $vtypeStr=$vtypeStr.getNewsTypeIdOnCache($vtypestra).",";
				            }
				            $vtypeStr=rtrim($vtypeStr,",");
				        } else {
				            $vtypeStr=getNewsTypeIdOnCache($vtype);
				        }
			        }
			        if (strpos($vtypeStr,',') > 0) $whereType = " AND m_type IN ($vtypeStr) "; else $whereType = " AND m_type=$vtypeStr";
		        } else {
		            $whereType="";
		        }
				if (!empty($vletter)) $whereLetter = " AND m_letter ='".strtoupper($vletter)."'"; else $whereLetter = "";
		        if (!empty($vid) && $vid != "all") {
			        if (strpos($vid,',') > 0) $whereId = " AND m_id IN($vid) "; else $whereId = " AND m_id=$vid";
		        } else {
			        $whereId = "";
		        }
				if (!empty($avid) && $avid != "all") {
                    if (strpos($avid,',') > 0) $whereVid = " AND m_vid IN($avid) "; else $whereVid = " AND m_vid=$avid";
			    } else {
				    $whereVid="";
			    }
		        if (!empty($vcommend)) {
		            switch (trim($vcommend)) {
			            case "all":$whereCommend = " AND m_commend>0";break;
			            default:
				            if (strpos($vcommend,',') > 0) $whereCommend = " AND m_commend IN($vcommend)"; else $whereCommend = " AND m_commend=$vcommend";
		            }
		        } else {
			        $whereCommend = "";
		        }
				switch (trim($vtime)) {
		 	        case "day":
				        $ntime = gmmktime(0, 0, 0, gmdate('m'), gmdate('d'), gmdate('Y'));
				        $limitday = $ntime - (1 * 24 * 3600);
				        $whereTime = " AND m_addtime>".$limitday;
			        break;
			        case "week":
				        $ntime = gmmktime(0, 0, 0, gmdate('m'), gmdate('d'), gmdate('Y'));
				        $limitday = $ntime - (7 * 24 * 3600);
				        $whereTime = " AND m_addtime>".$limitday;
			        break;
			        case "month":
				        $ntime = gmmktime(0, 0, 0, gmdate('m'), gmdate('d'), gmdate('Y'));
				        $limitday = $ntime - (30 * 24 * 3600);
				        $whereTime = " AND m_addtime>".$limitday;
			        break;
			        default:
				        $whereTime = "";
		        }
				$whereStr = replaceStr(" WHERE".$whereType.$whereLetter.$whereTime.$whereCommend.$whereId.$whereVid,"WHERE AND","WHERE");
				if (trim($whereStr) == "WHERE") $whereStr = "";
		        $sql = "SELECT `m_id`,`m_title`,`m_type`,`m_vid`,`m_pic`,`m_hit`,`m_author`,`m_content`,`m_color`,`m_addtime`,`m_from`,`m_outline`,`m_commend`,`m_letter`,`m_keyword`,`m_digg`,`m_tread`,`m_entitle`,`m_datetime`,`m_note` FROM ".DB::table('news')." $whereStr$orderStr LIMIT $vstart, $vnum";
		        preg_match_all(buildregx($labelRuleField,"is"), self::$content, $lar);
				$matchfieldarr = $lar[1];
		        $matchfieldstrarr = $lar[0];
		        $loopstrTotal = "";
		        $i = 1;
		        $query = DB::query($sql);
	            while ($row = DB::fetch($query)) {
			        $loopstrVlistNew = $loopstrVideoList;
			        foreach ($matchfieldarr as $f => $matchfieldstr) {
				        $matchfieldvalue = $matchfieldstrarr[$f];
						$matchfieldstr = trim(preg_replace("/[ \r\n\t\f]{1,}/"," ",$matchfieldstr));
				        if (strpos($matchfieldstr, chr(32)) > 0) {
				            $fieldtemparr = explode(chr(32), $matchfieldstr);
				            $fieldName = $fieldtemparr[0];
				            $fieldAttr = $fieldtemparr[1];
				        } else {
				            $fieldName = $matchfieldstr;
				            $fieldAttr = "";
				        }
			            switch (trim($fieldName)) {
						    case "id":
							    $loopstrVlistNew = replaceStr($loopstrVlistNew, $matchfieldvalue,$row['m_id']);
							break;
						    case "typeid":
							    $loopstrVlistNew = replaceStr($loopstrVlistNew, $matchfieldvalue,$row['m_type']);
							break;
						    case "letter":
							    $loopstrVlistNew = replaceStr($loopstrVlistNew, $matchfieldvalue,$row['m_letter']);
							break;
						    case "title":case "name":
							    $m_name = $row['m_title'];
							    $fieldAttrarr=self::parseAttr($fieldAttr);$namelen=empty($fieldAttrarr['len']) ? "" : intval($fieldAttrarr['len']);
							    $m_name=!empty($namelen)&&strlen($m_name)>$namelen ? msubstr($m_name,$namelen) : $m_name;
					            $loopstrVlistNew = replaceStr($loopstrVlistNew, $matchfieldvalue, $m_name);
							break;
							case "colortitle":case "colorname":
							    $m_color = $row['m_color'];$m_name = $row['m_title'];
							    $fieldAttrarr=self::parseAttr($fieldAttr);$colornamelen=empty($fieldAttrarr['len']) ? "" : intval($fieldAttrarr['len']);
							    $m_name=!empty($colornamelen)&&strlen($m_name)>$colornamelen ? msubstr($m_name,$colornamelen) : $m_name;
					            if (!empty($m_color)) $m_name = "<font color=".$m_color.">".$m_name."</font>";
					            $loopstrVlistNew = replaceStr($loopstrVlistNew, $matchfieldvalue, $m_name);
							break;
						    case "outline":
							    $m_note = $row['m_outline'];
							    $fieldAttrarr=self::parseAttr($fieldAttr);$notelen=empty($fieldAttrarr['len']) ? "" : intval($fieldAttrarr['len']);
							    $m_note=!empty($notelen)&&strlen($m_note)>$notelen ? msubstr($m_note,$notelen) : $m_note;
					            $loopstrVlistNew = replaceStr($loopstrVlistNew, $matchfieldvalue, $m_note);
							break;
						    case "author":
							    $m_actor = $row['m_author'];
							    $fieldAttrarr=self::parseAttr($fieldAttr);$actorlen=empty($fieldAttrarr['len']) ? "" : intval($fieldAttrarr['len']);
							    $m_actor=!empty($actorlen)&&strlen($m_actor)>$actorlen ? msubstr($m_actor,$actorlen) : $m_actor;
					            $loopstrVlistNew = replaceStr($loopstrVlistNew, $matchfieldvalue, $m_actor);
							break;
							case "content":case "des":
							    $m_des = decodeHtml($row['m_content']);
							    $fieldAttrarr=self::parseAttr($fieldAttr);$deslen=empty($fieldAttrarr['len']) ? "200" : intval($fieldAttrarr['len']);
							    $m_des=strlen($m_des)>$deslen ? msubstr($m_des,$deslen) : $m_des;
					            $loopstrVlistNew = replaceStr($loopstrVlistNew, $matchfieldvalue, $m_des);
							break;
							case "time":
							    $fieldAttrarr=self::parseAttr($fieldAttr);$timestyle=empty($fieldAttrarr['style']) ? "m-d" : $fieldAttrarr['style'];
					            $videoTime = $row['m_addtime'];
				                switch (trim($timestyle)) {
					                case "yyyy-mm-dd":
				                        $loopstrVlistNew = replaceStr($loopstrVlistNew, $matchfieldvalue, date("Y-m-d", $videoTime));
					                break;
					                case "yy-mm-dd":
				                        $loopstrVlistNew = replaceStr($loopstrVlistNew, $matchfieldvalue, date("y-m-d", $videoTime));
					                break;
					                case "y-m-d":
				                        $loopstrVlistNew = replaceStr($loopstrVlistNew, $matchfieldvalue, date("Y-n-d", $videoTime));
					                break;
					                default:
						                $loopstrVlistNew = replaceStr($loopstrVlistNew, $matchfieldvalue, date($timestyle, $videoTime));
				                }
				            break;
							case "i":
					            $loopstrVlistNew = replaceStr($loopstrVlistNew, $matchfieldvalue, $i);
				            break;
						    case "n":
					            $loopstrVlistNew = replaceStr($loopstrVlistNew, $matchfieldvalue, $ni);
				            break;
							case "typename":
				                $typename = explode(",", getNewsTypeNameTemplateArrayOnCache(intval($row['m_type'])));
					            $loopstrVlistNew = replaceStr($loopstrVlistNew, $matchfieldvalue, $typename[0]);
				            break;
				            case "typelink":
					            $loopstrVlistNew = replaceStr($loopstrVlistNew, $matchfieldvalue, getNewsTypeLink($row['m_type']));
				            break;
							case "newslink":case "link":
					            $loopstrVlistNew = replaceStr($loopstrVlistNew, $matchfieldvalue, getNewsArticleLink($row['m_type'], $row['m_id'], $row['m_entitle'], $row['m_datetime'], "link"));
				            break;
							case "pic":
				                if (!empty($row['m_pic'])) {
					                if (isExistStr($row['m_pic'], '://')) {
						                $loopstrVlistNew = replaceStr($loopstrVlistNew, $matchfieldvalue, $row['m_pic']);
					                } else {
						                $loopstrVlistNew = replaceStr($loopstrVlistNew, $matchfieldvalue, '/'.sitePath.$row['m_pic']);
					                }
					            } else {
						            $loopstrVlistNew = replaceStr($loopstrVlistNew, $matchfieldvalue, '/'.sitePath.'pic/nopic.gif');
					            }
				            break;
							case "hit":
					            $loopstrVlistNew = replaceStr($loopstrVlistNew, $matchfieldvalue, $row['m_hit']);
				            break;
						    case "vid":
							    $loopstrVlistNew = replaceStr($loopstrVlistNew,$matchfieldvalue,$row['m_vid']);
							break;
							case "from":
					            $loopstrVlistNew = replaceStr($loopstrVlistNew, $matchfieldvalue, $row['m_from']);
				            break;
							case "commend":
					            $loopstrVlistNew = replaceStr($loopstrVlistNew, $matchfieldvalue, $row['m_commend']);
				            break;
							case "keyword":
					            $loopstrVlistNew = replaceStr($loopstrVlistNew, $matchfieldvalue, getKeywordsList($row['m_keyword']));
				            break;
							case "digg":
					            $loopstrVlistNew = replaceStr($loopstrVlistNew, $matchfieldvalue, $row['m_digg']);
				            break;
						    case "tread":
					            $loopstrVlistNew = replaceStr($loopstrVlistNew, $matchfieldvalue, $row['m_tread']);
				            break;
						    case "note":
							    $loopstrVlistNew = replaceStr($loopstrVlistNew, $matchfieldvalue,parseNewsNote($row['m_note']));
							break;
						}
					}
					$i = $i + 1;
				    $loopstrTotal .= $loopstrVlistNew;$ni = $ni + 1;
				}
			    self::$content = replaceStr(self::$content, $ar[0][$m], $loopstrTotal);
			}
		}
	}
	
	public static function parseNewsPartList($typeId,$currentPage,$pageListType){
		global $lang;
		$attrDictionary=array();
		$labelRule = "{djcms:".$pageListType."list(.*?)}(.*?){/djcms:".$pageListType."list}";
		$labelRuleField = "\[".$pageListType."list:(.*?)\]";
		$labelRulePagelist = "\[".$pageListType."list:pagenumber(.*?)\]";
		$labelRulePagelist2="\{".$pageListType."list:pagenumber(.*?)\}(.*?){/".$pageListType."list:pagenumber}";
		preg_match_all(buildregx($labelRule, "is"), self::$content, $ar);
		$arlen = count($ar[1]);
		for ($m = 0;$m < $arlen;$m++) {
			$attrChannel = trim(preg_replace("/[ \r\n\t\f]{1,}/"," ",$ar[1][$m]));
			$loopstrChannel = $ar[2][$m];
		    $attrDictionary = self::parseAttr($attrChannel);
			$vsize=empty($attrDictionary["size"]) ? 12 : intval($attrDictionary["size"]);
			$vorder=empty($attrDictionary["order"]) ? "time" : $attrDictionary["order"];
			switch ($vorder) {
				case "id" : $orderStr =" ORDER BY m_id DESC";break;
				case "hit" : $orderStr =" ORDER BY m_hit DESC";break;
				case "dayhit" : $orderStr =" ORDER BY m_dayhit DESC";break;
				case "weekhit" : $orderStr =" ORDER BY m_weekhit DESC";break;
				case "monthhit" : $orderStr =" ORDER BY m_monthhit DESC";break;
				case "time" : $orderStr =" ORDER BY m_addtime DESC";break;
				case "digg" : $orderStr =" ORDER BY m_digg DESC";break;
				case "name" : $orderStr=" ORDER BY m_name ASC ";break;
				case "letter" : $orderStr=" ORDER BY m_letter ASC";break;
			}
			unset($attrDictionary);
			switch ($pageListType) {
				case "newspage":
					$whereStr = " WHERE m_recycle=0 AND m_type IN($typeId)";break;
				case "newssearch":
					global $searchType,$searchword;
					switch ($searchType) {
		                case -1 : $whereStr = " WHERE m_recycle=0 AND m_title LIKE '%$searchword%' OR m_keyword LIKE '%$searchword%'";break;
		                case 0 : $whereStr = " WHERE m_recycle=0 AND m_title LIKE '%$searchword%'";break;
		                case 1 : $whereStr = " WHERE m_recycle=0 AND m_author LIKE '%$searchword%'";break;
		                case 2 : $whereStr = " WHERE m_recycle=0 AND m_from LIKE '%$searchword%'";break;
		                case 3 : $whereStr = " WHERE m_recycle=0 AND m_outline LIKE '%$searchword%'";break;
		                case 4 : $whereStr = " WHERE m_recycle=0 AND m_letter = '".strtoupper($searchword)."'" ;break;
	                }
					if (empty($searchword)) $whereStr = " WHERE 1=2";
				    break;
		    }
			$sqlStr = "SELECT `m_id`,`m_title`,`m_type`,`m_vid`,`m_pic`,`m_hit`,`m_author`,`m_content`,`m_color`,`m_addtime`,`m_from`,`m_outline`,`m_commend`,`m_letter`,`m_keyword`,`m_digg`,`m_tread`,`m_entitle`,`m_datetime`,`m_note` FROM ".DB::table('news')." $whereStr$orderStr";
			$recordcount = db::getCount($sqlStr);$totalPages = ceil($recordcount/$vsize);
			$page = max(intval($currentPage), 1);
            $offset = $vsize*($page-1);
			preg_match_all(buildregx($labelRuleField, "is"), self::$content, $lar);
		    $matchfieldarr = $lar[1];
		    $matchfieldstrarr = $lar[0];
			$loopstrTotal = "";
			$i = 1;
			if ($recordcount == 0) {
				if ($pageListType == "newspage") {
					$loopstrTotal = $lang['channellistInfo']['0'];
			    } elseif($pageListType == "newssearch") {
					$loopstrTotal = $lang['searchlistInfo']['0'].$searchword.$lang['searchlistInfo']['1'];
			    }
		    } else {
		        $query = DB::query("$sqlStr limit $offset, $vsize");
	            while ($row = DB::fetch($query)) {
			        $loopnew = $loopstrChannel;
				    foreach ($matchfieldarr as $f => $matchfieldstr) {
					    $matchfieldvalue = $matchfieldstrarr[$f];
						$matchfieldstr = trim(preg_replace("/[ \r\n\t\f]{1,}/"," ",$matchfieldstr));
					    if (strpos($matchfieldstr, chr(32)) > 0) {
						    $fieldtemparr = explode(chr(32), $matchfieldstr);
						    $fieldName = $fieldtemparr[0];
						    $fieldAttr = $fieldtemparr[1];
					    } else {
						    $fieldName = $matchfieldstr;
						    $fieldAttr = "";
					    }
				        switch (trim($fieldName)) {
							case "id":
						        $loopnew = replaceStr($loopnew, $matchfieldvalue, $row['m_id']);
					        break;
					        case "typeid":
						        $loopnew = replaceStr($loopnew, $matchfieldvalue, $row['m_type']);
					        break;
							case "title":case "name":
							    $m_name = $row['m_title'];
								$fieldAttrarr=self::parseAttr($fieldAttr);$namelen=empty($fieldAttrarr['len']) ? "" : intval($fieldAttrarr['len']);
								$m_name=!empty($namelen)&&strlen($m_name)>$namelen ? msubstr($m_name,$namelen) : $m_name;
						        $loopnew = replaceStr($loopnew, $matchfieldvalue, $m_name);
							break;
							case "colortitle":case "colorname":
							    $m_color = $row['m_color'];$m_name = $row['m_title'];
								$fieldAttrarr=self::parseAttr($fieldAttr);$colornamelen=empty($fieldAttrarr['len']) ? "" : intval($fieldAttrarr['len']);
								$m_name=!empty($colornamelen)&&strlen($m_name)>$colornamelen ? msubstr($m_name,$colornamelen) : $m_name;
						        if (!empty($m_color)) $m_name = "<font color=".$m_color.">".$m_name."</font>";
						        $loopnew = replaceStr($loopnew, $matchfieldvalue, $m_name);
					        break;
							case "outline":
							    $m_note = $row['m_outline'];
								$fieldAttrarr=self::parseAttr($fieldAttr);$notelen=empty($fieldAttrarr['len']) ? "" : intval($fieldAttrarr['len']);
								$m_note=!empty($notelen)&&strlen($m_note)>$notelen ? msubstr($m_name,$notelen) : $m_note;
						        $loopnew = replaceStr($loopnew, $matchfieldvalue, $m_note);
					        break;
							case "author":
							    $m_actor = $row['m_author'];
								$fieldAttrarr=self::parseAttr($fieldAttr);$actorlen=empty($fieldAttrarr['len']) ? "" : intval($fieldAttrarr['len']);
								$m_actor=!empty($actorlen)&&strlen($m_actor)>$actorlen ? msubstr($m_name,$actorlen) : $m_actor;
						        $loopnew = replaceStr($loopnew, $matchfieldvalue, $m_actor);
					        break;
							case "content":case "des":
							    $m_des = decodeHtml($row['m_content']);
								$fieldAttrarr=self::parseAttr($fieldAttr);$deslen=empty($fieldAttrarr['len']) ? "200" : intval($fieldAttrarr['len']);
								$m_des=!empty($deslen)&&strlen($m_des)>$deslen ? msubstr($m_des,$deslen) : $m_des;
						        $loopnew = replaceStr($loopnew, $matchfieldvalue, $m_des);
					        break;
					        case "time":
								$fieldAttrarr=self::parseAttr($fieldAttr);$timestyle=empty($fieldAttrarr['style']) ? "m-d" : $fieldAttrarr['style'];
						        $videoTime = $row['m_addtime'];
				    	        switch (trim($timestyle)) {
							        case "yyyy-mm-dd":
					    	            $loopnew = replaceStr($loopnew, $matchfieldvalue, date("Y-m-d", $videoTime));
						            break;
							        case "yy-mm-dd":
					   	 	            $loopnew = replaceStr($loopnew, $matchfieldvalue, date("y-m-d", $videoTime));
							        break;
							        case "y-m-d":
					    	            $loopnew = replaceStr($loopnew, $matchfieldvalue, date("Y-n-d", $videoTime));
							        break;
							        default:
							            $loopnew = replaceStr($loopnew, $matchfieldvalue, date($timestyle, $videoTime));
					            }
					        break;
							case "i":
						        $loopnew = replaceStr($loopnew, $matchfieldvalue, $i);
					        break;
					        case "typename":
					            $typename = explode(",",getNewsTypeNameTemplateArrayOnCache(intval($row['m_type'])));
						        $loopnew = replaceStr($loopnew, $matchfieldvalue, $typename[0]);
					        break;
					        case "typelink":
						        $loopnew = replaceStr($loopnew, $matchfieldvalue, getNewsTypeLink($row['m_type']));
					        break;
					        case "newslink":case "link":
						        $loopnew = replaceStr($loopnew, $matchfieldvalue, getNewsArticleLink($row['m_type'], $row['m_id'], $row['m_entitle'], $row['m_datetime'], "link"));
					        break;
							case "pic":
					            if (!empty($row['m_pic'])) {
						            if (isExistStr($row['m_pic'], '://')) {
						                $loopnew = replaceStr($loopnew, $matchfieldvalue, $row['m_pic']);
					                } else {
						                $loopnew = replaceStr($loopnew, $matchfieldvalue, '/'.sitePath.$row['m_pic']);
					                }
					            } else {
						            $loopnew = replaceStr($loopnew, $matchfieldvalue, '/'.sitePath.'pic/nopic.gif');
					            }
					        break;
							case "hit":
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, $row['m_hit']);
				            break;
						    case "vid":
							    $loopnew = replaceStr($loopnew,$matchfieldvalue,$row['m_vid']);
							break;
							case "from":
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, $row['m_from']);
				            break;
							case "commend":
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, $row['m_commend']);
				            break;
							case "keyword":
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, getKeywordsList($row['m_keyword']));
				            break;
							case "digg":
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, $row['m_digg']);
				            break;
						    case "tread":
					            $loopnew = replaceStr($loopnew, $matchfieldvalue, $row['m_tread']);
				            break;
						    case "note":
							    $loopnew = replaceStr($loopnew, $matchfieldvalue,parseNewsNote($row['m_note']));
							break;
						}
					}
					$i = $i + 1;
				    $loopstrTotal .= $loopnew;
				}
			}
			self::$content = replaceStr(self::$content, $ar[0][$m], $loopstrTotal);
			preg_match_all(buildregx($labelRulePagelist, "is"), self::$content, $plar);
			$plarlen = count($plar[1]);
			for ($p = 0;$p < $plarlen;$p++) {
				if ($recordcount == 0) {
					self::$content = replaceStr(self::$content, $plar[0][$p], "");
				} else {
					$fieldAttrarr=self::parseAttr($plar[1][$p]);$lenPagelist=empty($fieldAttrarr['len']) ? "10" : intval($fieldAttrarr['len']);
					$strPagelist = pageNumberLinkInfo($currentPage, $lenPagelist, $totalPages, $pageListType, $recordcount);
					self::$content = replaceStr(self::$content, $plar[0][$p], $strPagelist);
			    }
		    }
			$tPages=ifthen($totalPages==0,1,$totalPages);
			if (strpos(self::$content,"{/".$pageListType."list:pagenumber}")>0){
				preg_match_all(buildregx($labelRulePagelist2, "is"), self::$content, $plarl);
				$plarllen = count($plarl[1]);
				for ($p = 0;$p < $plarllen;$p++) {
					$fieldAttrarr=self::parseAttr($plarl[1][$p]);
					$lenPagelist=empty($fieldAttrarr['len']) ? "10" : intval($fieldAttrarr['len']);
					$strPagelist=$plarl[2][$p];
					$strPagelist=makePagenumberLoop($currentPage,$lenPagelist,$tPages,$pageListType,$strPagelist);
					self::$content=replaceStr(self::$content,$plarl[0][$p],$strPagelist);
		        }
		    }
			$content=replaceStr(self::$content,"{".$pageListType."list:page}",$currentPage);
			$content=replaceStr($content,"{".$pageListType."list:pagecount}",$tPages);
			$content=replaceStr($content,"{".$pageListType."list:recordcount}",$recordcount);
			$content=replaceStr($content,"{".$pageListType."list:firstlink}",getPageLink(1,$pageListType));
			$content=replaceStr($content,"{".$pageListType."list:backlink}",getPageLink(ifthen($currentPage>1,$currentPage-1,1),$pageListType));
			$content=replaceStr($content,"{".$pageListType."list:nextlink}",getPageLink(ifthen($currentPage<$tPages,$currentPage+1,$tPages),$pageListType));
			self::$content=replaceStr($content,"{".$pageListType."list:lastlink}",getPageLink($tPages,$pageListType));
        }
	}

	public static function parseSlide() {
		$slideStr = "{djcms:slide";
		if (isExistStr(self::$content, $slideStr)) {
			$slideStr2 = getSubStrByFromAndEnd(self::$content, $slideStr, "}", "");
			$slidewarr = self::parseAttr($slideStr2);
			$slidew = $slidewarr['width'];$slideh=$slidewarr['height'];
			if (empty($slidew)) $slidew = 400;
			if (empty($slideh)) $slideh = 280;
			self::$content = replaceStr(self::$content, $slideStr.$slideStr2."}",flashslide($slidew, $slideh));
		}
	}

    public static function parseMaxHistory() {
		self::$content=replaceStr(self::$content,"{djcms:showhistory}","<a href=\"javascript:void(0)\" onclick=\"$"."MH.showHistory(1);\">我的观看历史</a>");
		$x="{djcms:maxhistory";
		if (isExistStr(self::$content,$x)){
			$y = getSubStrByFromAndEnd(self::$content, $x, "}", "");$q = self::parseAttr($y);
			$w = $q["width"];$h=$q["height"];$i=$q["num"];$c=empty($q["style"]) ? "" : $q["style"];
			if (empty($w)) $w=960;
			if (empty($h)) $h=170;
			if (empty($i)) $i=10;
			self::$content=replaceStr(self::$content,$x.$y."}","<script type=\"text/javascript\" src=\"/".sitePath."js/max_history.js\"></script><script type=\"text/javascript\">$"."MH.limit=".$i.";$"."MH.WriteHistoryBox(".$w.",".$h.",'".$c."');$"."MH.recordHistory({name:'{playpage:name}',link:'{playpage:url}',pic:'{playpage:pic}'})</script>");
	    }
	}
	
	public static function paresPreNextVideo($dataid,$typeFlag,$vtype){
		$preNextLabel="{playpage:prenext}";
		if (isExistStr(self::$content,$preNextLabel)){
		    $rown = DB::fetch_first("select m_id as nextid ,m_name as nextname,m_enname AS nextenname,m_datetime AS nextdatetime from ".DB::table('data')." WHERE m_type=".$vtype." AND m_recycle=0 AND m_id<".$dataid." ORDER BY m_id DESC LIMIT 1");
		    if (!is_array($rown)){
			    $nextid = 0; 
		    }else{
				$nextid=$rown["nextid"];$nextname = $rown["nextname"];$nextenname=$rown["nextenname"];$nextdatetime=$rown["nextdatetime"];
			}
		    $rowl = DB::fetch_first("select m_id as lastid,m_name  as lastname,m_enname AS lastenname,m_datetime AS lastdatetime from ".DB::table('data')." WHERE m_type=".$vtype." AND m_recycle=0 AND m_id>".$dataid." ORDER BY m_id ASC LIMIT 1");
		    if (!is_array($rowl)){  
			    $lastid = 0;  
			}else{
				$lastid=$rowl["lastid"];$lastname = $rowl["lastname"];$lastenname = $rowl["lastenname"];$lastdatetime = $rowl["lastdatetime"];
			}
		    if ($typeFlag=="play"){
		        if ($lastid == 0){ 
			        $mystr = "<span>上一篇:没有了</span> ";
			    }else{
				    $mystr = "<span>上一篇:<a href=".getPlayLink2($vtype,$lastid,$lastenname,$lastdatetime,0,0).">".$lastname."</a></span> ";
			    }
			    if ($nextid == 0){ 
			        $mystr = $mystr."<span>下一篇:没有了</span>";
			    }else{
				    $mystr = $mystr."<span>下一篇:<a href=".getPlayLink2($vtype,$nextid,$nextenname, $nextdatetime,0,0).">".$nextname."</a></span>";
			    }
		    }else{
			    if ($lastid == 0){ 
			        $mystr = "<span>上一篇:没有了</span> ";
			    }else{ 
			        $mystr = "<span>上一篇:<a href=".getContentLink($vtype,$lastid,$lastenname,$lastdatetime,"link").">".$lastname."</a></span> ";
			    }
			    if ($nextid == 0){  
			        $mystr = $mystr."<span>下一篇:没有了</span>";
			    }else{ 
			        $mystr = $mystr."<span>下一篇:<a href=".getContentLink($vtype,$nextid,$nextenname, $nextdatetime,"link").">".$nextname."</a></span>";
		        } 
		    self::$content=replaceStr(self::$content,$preNextLabel,$mystr);
			}
	    }
	}
	
	public static function paresPreNextNews($dataid,$vtype) {
		$preNextLabel="{news:prenext}";
		if (isExistStr(self::$content,$preNextLabel)){
		$rown = DB::fetch_first("select m_id as nextid ,m_title as nextname,m_entitle AS nextenname,m_datetime AS nextdatetime from ".DB::table('news')." WHERE m_type=".$vtype." AND m_recycle=0 AND m_id<".$dataid." ORDER BY m_id DESC LIMIT 1");
		if (!is_array($rown)){ 
		    $nextid = 0; 
		}else{ 
		    $nextid=$rown["nextid"];$nextname = $rown["nextname"];$nextenname=$rown["nextenname"];$nextdatetime=$rown["nextdatetime"];
		}
		$rowl = DB::fetch_first("select m_id as lastid,m_title  as lastname,m_entitle AS lastenname,m_datetime AS lastdatetime from ".DB::table('news')." WHERE m_type=".$vtype." AND m_recycle=0 AND m_id>".$dataid." ORDER BY m_id asc LIMIT 1");
		if (!is_array($rowl)){ 
		    $lastid =0; 
		}else{ 
		    $lastid=$rowl["lastid"];$lastname = $rowl["lastname"];$lastenname = $rowl["lastenname"];$lastdatetime = $rowl["lastdatetime"];
		}
		if ($lastid == 0){ 
		    $mystr = "<span>上一篇:没有了</span> ";
		}else{ 
		    $mystr = "<span>上一篇:<a href=".getNewsArticleLink($vtype,$lastid,$lastenname,$lastdatetime,"link").">".$lastname."</a></span> ";
		}
		if ($nextid == 0){ 
		    $mystr = $mystr."<span>下一篇:没有了</span>"; 
		}else{ 
		    $mystr = $mystr."<span>下一篇:<a href=".getNewsArticleLink($vtype,$nextid,$nextenname, $nextdatetime,"link").">".$nextname."</a></span>";
		}
		self::$content=replaceStr(self::$content,$preNextLabel,$mystr);
		}
	}
	
	public static function parsePlayPageSpecial() {
		$x="{playpage:mark";
		if (isExistStr(self::$content,$x)){
			$y=getSubStrByFromAndEnd(self::$content,$x,"}","");$q = self::parseAttr($y);
			$l=$q["len"];$c=$q["style"];$l=ifthen(empty($l),5,$l);$c=ifthen($c=="",0,1);
			self::$content = replaceStr(self::$content,$x.$y."}","<script type=\"text/javascript\">markVideo({playpage:id},{playpage:diggnum},{playpage:treadnum},{playpage:scorenum},".$l.",".$c.");</script>");
	    }
		$content = replaceStr(self::$content,"{playpage:digg}","<span id=\"digg_num\">{playpage:diggnum}</span><a href=\"javascript:void(0)\" onclick=\"diggVideo({playpage:id},'digg_num')\">顶一下</a>");
		$content = replaceStr($content,"{playpage:tread}","<span id=\"tread_num\">{playpage:treadnum}</span><a href=\"javascript:void(0)\" onclick=\"treadVideo({playpage:id},'tread_num')\">踩一下</a>");
		$content = replaceStr($content,"{playpage:reporterr}","<a href=\"javascript:void(0)\" onclick=\"reportErr({playpage:id})\">报 错</a>");
		$content = replaceStr($content,"{playpage:comment}","<div id=\"comment_list\">评论加载中..</div><script>viewComment(\"/".sitePath."comment.php?id={playpage:id}\",\"\")</script>");
		self::$content = replaceStr($content,"{playpage:hit}","<span id=\"hit\">加载中</span><script>getVideoHit('{playpage:id}')</script>");
	}
	
	public static function parseNewsPageSpecial() {
		$x="{news:mark";
		if (isExistStr(self::$content,$x)){
			$y=getSubStrByFromAndEnd(self::$content,$x,"}","");$q = self::parseAttr($y);
			$l=$q["len"];$c=$q["style"];$l=ifthen(empty($l),5,$l);$c=ifthen($c=="" || $c="radio",0,1);
			self::$content = replaceStr(self::$content,$x.$y."}","<script type=\"text/javascript\">markNews({news:id},{news:diggnum},{news:treadnum},{news:scorenum},".$l.",".$c.");</script>");
	    }
		$content = replaceStr(self::$content,"{news:digg}","<span id=\"digg_num\">{news:diggnum}</span><a href=\"javascript:void(0)\" onclick=\"diggNews({news:id},'digg_num')\">顶一下</a>");
		$content = replaceStr($content,"{news:tread}","<span id=\"tread_num\">{news:treadnum}</span><a href=\"javascript:void(0)\" onclick=\"treadNews({news:id},'tread_num')\">踩一下</a>");
		$content = replaceStr($content,"{news:comment}","<div  id=\"comment_list\">评论加载中..</div><script>viewComment(\"/".sitePath."comment.php?id={news:id}\",\"news\")</script>");
		self::$content = replaceStr($content,"{news:hit}","<span id=\"hit\">加载中</span><script>getNewsHit('{news:id}')</script>");
	}

    public static function parseIf() {
	    if (isExistStr(self::$content, "{if:")) {
		    $labelRule = "{if:(.*?)}(.*?){end if}";$labelRule2 = "{elseif";$labelRule3 = "{else}";$elseIfFlag = false;$ifFlag = false;
		    preg_match_all(buildregx($labelRule, "is"), self::$content, $iar);
		    $arlen = count($iar[1]);
		    for ($m = 0;$m < $arlen;$m++) {
			    $strIf = $iar[1][$m];
			    $strThen = $iar[2][$m];
			    if (isExistStr($strThen, $labelRule2)) {
				    $elseIfArray = explode($labelRule2, $strThen);$elseIfArrayLen = count($elseIfArray);$elseIfSubArray = explode($labelRule3, $elseIfArray[$elseIfArrayLen-1]);
				    $resultStr = $elseIfSubArray[1];
				    $elseIfArraystr0 = $elseIfArray[0];
				    @eval("if($strIf){\$resultStr=\"$elseIfArraystr0\";}");
				    for ($elseIfLen = 1;$elseIfLen < $elseIfArrayLen;$elseIfLen++){
					    $strElseIf = getSubStrByFromAndEnd($elseIfArray[$elseIfLen], ":", "}", "");
					    $strElseIfThen = getSubStrByFromAndEnd($elseIfArray[$elseIfLen], "}", "", "start");
					    @eval("if($strElseIf){\$resultStr=\"$strElseIfThen\";}");
					    @eval("if($strElseIf){\$elseIfFlag=true;}else{\$elseIfFlag=false;}");
					    if ($elseIfFlag) {break;}
				    }
				    $strElseIf0 = getSubStrByFromAndEnd($elseIfSubArray[0], ":", "}", "");
				    $strElseIfThen0 = getSubStrByFromAndEnd($elseIfSubArray[0], "}", "", "start");
				    @eval("if($strElseIf0){\$resultStr=\"$strElseIfThen0\";\$elseIfFlag=true;}");
				    self::$content = replaceStr(self::$content, $iar[0][$m], $resultStr);
			    } else {
				    if (isExistStr($strThen, "{else}")) {
					    $elsearray = explode($labelRule3, $strThen);
					    $strThen1 = $elsearray[0];
					    $strElse1 = $elsearray[1];
					    @eval("if($strIf){\$ifFlag=true;}else{\$ifFlag=false;}");
					    if ($ifFlag) self::$content = replaceStr(self::$content, $iar[0][$m], $strThen1); else self::$content = replaceStr(self::$content, $iar[0][$m], $strElse1);
				    } else {
				        @eval("if  ($strIf) { \$ifFlag=true;} else{ \$ifFlag=false;}");
				        if ($ifFlag) self::$content = replaceStr(self::$content, $iar[0][$m], $strThen); else self::$content = replaceStr(self::$content, $iar[0][$m], "");
			        }
			    }
		    }
	    }
	}
}
?>