<?php
if( !defined('ISDVBBS') ){
	header('HTTP/1.0 404 Not Found');
	exit;
}
require_once INC_PATH.'DV_Encoding.class.php';
$skinpath = $_tpl_skinPath = $spaceConfig_System['s_path'];
$_tpl_ispaceUrl = $mArchiveLink;
$_tpl_spaceUrl = $ModHtmlLinked;
if( $_Count_ArrArchiveLink > 1 ){
	$_arrTmp = explode('-',$arrArchiveLink[1]);
	$_count = count($_arrTmp);
	if( $_count == 4 ){
		$_cat_tID = is_numeric($_arrTmp[0]) ? $_arrTmp[0] : '0';
		$_strTmp = str_replace('.html','',$_arrTmp[3]);
		$_iPage = is_numeric($_strTmp) ? $_strTmp : 0;
		$_selType = is_numeric($_arrTmp[2]) ? $_arrTmp[2] : '0';
		$_keyWord = $_arrTmp[1];
	} elseif( $_count == 2 ){
		$_strTmp = str_replace('.html','',$_arrTmp[1]);
		$_iPage = is_numeric($_strTmp) ? $_strTmp : '0';
		$_cat_tID = $_arrTmp[0];
	} else{
		$_iPage = 1;
		$_strTmp = str_replace('.html','',$_arrTmp[0]);
		$_cat_tID = is_numeric($_strTmp) ? $_strTmp : '0';
	}
}
if( $_Count_ArrArchiveLink > 2 ){
	$_arrTmp = explode('-',$arrArchiveLink[2]);
	$_intCount = count($_arrTmp);
	if( $_intCount == 4 ){
		$_catID = $_arrTmp[0];
		$_strTmp = str_replace('.html','',$_arrTmp[3]);
		$_iPage = is_numeric($_strTmp) ? $_strTmp : '0' ;
		$_keyWord = $_arrTmp[1];
		$_selType = is_numeric($_arrTmp[2]) ? $_arrTmp[2] : '0' ;
	} elseif( $_intCount == 2 ){
		$_strTmp = str_replace('.html','',$_arrTmp[1]);
		$_iPage = is_numeric($_strTmp) ? $_strTmp : '0' ;
		$_catID = $_arrTmp[0];
	} else{
		$_iPage = 1;
		$_strTmp = str_replace('.html','',$_arrTmp[0]);
		$_catID = is_numeric($_strTmp) ? $_strTmp : '0';
	}
}
if( !isset($_cat_tID) || $_cat_tID === '' ) $_cat_tID = '0';
if( $_cat_tID !== '0' ){
	$_tpl_Descriptions = $_strDescriptions;
}
if( ( $_cat_tID === '0' && $_catID === '' ) || $_catID === '0' ){
	$_tpl_Descriptions = $lang['tpl.st.str1'];
	$_tpl_Descriptions_a = '';
}
if( $_cat_tID !== '0' && $_catID === '' ){
	$_tpl_Descriptions_a = $lang['tpl.str124'].'&nbsp;'.$lang['tpl.st.str1'];
}
if( $_cat_tID !== '0' && $_catID !== '' ){
	$_tpl_Descriptions_a = $lang['tpl.str124'].'&nbsp;{$_tpl_showCat}';
}
if( $_cat_tID === '0' && $_catID !== '' ){
	$_tpl_Descriptions = '{$_tpl_showCat}';
	$_tpl_Descriptions_a = '';
}
global $fsetting, $spaceSystemUpSetting, $spaceuploadbasedir;
$spaceuploadbasedir = basename($fsetting['forumuploadname']).'/'.basename($spaceSystemUpSetting[19]).'/';
print "<link href=\"{$_tpl_skinPath}css/space_index.css\" type=\"text/css\" rel=\"stylesheet\" />";
if (5 != $_cat_tID) {
print <<<EOT
        <div class="tag_top">
			<h1>{$lang['tpl.st.str13']}</h1>
EOT;
	$strmenunav = '';
	if ($_cat_tID <= 0 AND $_catID <= 0) {
		$syschatcat_parent = array(0 => '', 1 => '', 2 => '', 3 => '', 4 => '', 5 => '');
		if (!empty($spaceConfig_Syschatcat_parent) AND is_array($spaceConfig_Syschatcat_parent)) {
			foreach ($syschatcat_parent AS $index => $val1) {
				if (!empty($spaceConfig_Syschatcat_parent[$index]) AND is_array($spaceConfig_Syschatcat_parent[$index])) {
					foreach ($spaceConfig_Syschatcat_parent[$index] AS $val2) {
						$itmp = $index + 1;
						$syschatcat_parent[$index] .= "{$lang['tpl.str125']}<a href=\"?show_topic.{$itmp}.{$val2['scatid']}.html\">{$val2['scattitle']}</a>";
					}
				}
			}
		}
		print <<<EOT
			<h2>{$lang['tpl.str111']}{$syschatcat_parent[0]}</h2>
			<h2>{$lang['tpl.str112']}{$syschatcat_parent[4]}</h2>
			<h2>{$lang['tpl.str113']}{$syschatcat_parent[3]}</h2>
			<h2>{$lang['tpl.st.str21']}{$syschatcat_parent[5]}</h2>
			<h2>{$lang['tpl.str115']}{$syschatcat_parent[1]}</h2>
			<h2>{$lang['tpl.str116']}{$syschatcat_parent[2]}</h2>
EOT;
		$strmenunav = $lang['tpl.st.str1'];
	} elseif ($_cat_tID > 0) {
		$index = $_cat_tID - 1;
		$strtypemenu = '';
		if (!empty($spaceConfig_Syschatcat_parent[$index]) AND is_array($spaceConfig_Syschatcat_parent[$index])) {
			foreach ($spaceConfig_Syschatcat_parent[$index] AS $val) {
				$strtypemenu .= "{$lang['tpl.str125']}<a href=\"?show_topic.{$_cat_tID}.{$val['scatid']}.html\">{$val['scattitle']}</a>";
			}
		}
	print <<<EOT
			<h2>[{$lang['spaceStype'][$index]}]{$strtypemenu}</h2>
EOT;
		$strmenunav = $lang['spaceStype'][$index];
		if ($_catID > 0) {
			$strmenunav .= ' '.$lang['tpl.str124'].'  '.$spaceConfig_Syschatcat[$_catID]['scattitle'];
		}
	}
	print <<<EOT
		</div>
EOT;
} else {
	$strmenunav = $lang['tpl.st.str15'];
}
print <<<EOT
		<div class="tag_list">
			<h4><img src="{$skinpath}images/mright.gif" alt="" /> {$lang['tpl.st.str13']} {$lang['tpl.str124']}  {$strmenunav}  </h4>
EOT;
$topiclist =& showtopic_getTopicList($_cat_tID-1,$_catID, array('absolute_page'=>$_iPage, 'sel'=>$_POST['sel'], 'key_word'=>$_POST['searchword']));
if (!empty($topiclist['ResultSet']) AND is_array($topiclist['ResultSet'])) {
	$objenc =& DV_Encoding::GetEncoding($charset);
	if (5 == $_cat_tID) {	//	相册模式
		foreach ($topiclist['ResultSet'] AS $index => $val) {
			$separator = '';
			if (0 == $index % 5) {
				if (0 == $index) {
					$separator = '<div class="tag_photo">';
				} else {
					$separator = '</div><div class="tag_photo">';
				}
			}
			if ('' != $val['previewimage']) {
				$imgsrc = $val['previewimage'];
			} else {
				$imgsrc = $val['filename'];
			}
			$currsize = $val['filesize'];
			$units = 'B';
			if ($currsize > 1024) {
				$currsize = $currsize / 1024;
				$units = 'KB';
			}
			if ($currsize > 1024) {
				$currsize = $currsize / 1024;
				$units = 'MB';
			}
			if ($objenc->StrLength($val['username']) > 4) {
				$val['username'] = $objenc->SubString($val['username'], 0, 4).'...';
			}
			$currsize = number_format($currsize, 2);
			$postdate = gmdate("Y-m-d H:i:s",$val['dateandtime']+getUserTimeZoneOffset());
			print <<<EOT
			{$separator}
				<h1><a href="{$GLOBALS['ModHtmlLinked']}UserID_{$val['userid']}.showtopic.{$val['topicid']}.html" target="_blank"><img src="{$spaceuploadbasedir}{$imgsrc}" alt="{$val['title']}" width="110" height="110" border="0" style="padding:5px;" /></a><div class="name">{$lang['tpl.st.str16']}<a href="dispuser.php?id={$val['userid']}" target="_blank">{$val['username']}</a></div><div>{$lang['tpl.st.str17']}{$postdate}</div><div>{$lang['tpl.st.str18']}{$currsize}</div></h1>
EOT;
		}//end foreach
		print '</div><br />';
	} else {	//	其它模式
		if (empty($objenc)) {
			$objenc =& DV_Encoding::GetEncoding($GLOBALS['charset']);
		}
		foreach ($topiclist['ResultSet'] AS $val) {
			$crttitle = trim($val['title']);
			if ($objenc->StrLength($crttitle) > 50) {
				$crttitle = $objenc->SubString($crttitle, 0, 50).'...';
			}
			if ($val['catid'] > 0) {
				$cattitle = _getChannel($val['catid']);
				if ('' != $cattitle) {
					$cattitle = "{$lang['tpl.st.str6']}[<a href=\"{$GLOBALS['ModHtmlLinked']}UserID_{$GLOBALS['userid']}.showchannel.{$val['stype']}.{$val['catid']}.html\" target=\"_blank\">{$cattitle}</a>] -- ";
				}
			} else {
				$cattitle = '';
			}
			if ($objenc->StrLength($val['username']) > 4) {
				$val['username'] = $objenc->SubString($val['username'], 0, 4).'...';
			}
			$val['posttime'] = gmdate('Y-m-d H:i:s', $val['posttime']+getUserTimeZoneOffset());
			print <<<EOT
			<h1><em>{$lang['tpl.st.str10']}({$val['child']}) | {$lang['tpl.st.str11']}({$val['hits']})</em>{$lang['tpl.str126']}<a href="{$GLOBALS['ModHtmlLinked']}UserID_{$val['userid']}.showtopic.{$val['topicid']}.html" target="_blank" title="{$val['title']}">{$crttitle}</a></h1>
			<h2>{$cattitle}{$lang['tpl.st.str16']}<a href="dispuser.php?id={$val['userid']}" target="_blank" alt="{$lang['tpl.st.str20']}">{$val['username']}</a> -- {$lang['tpl.st.str12']}<span>{$val['posttime']}</span> </h2>
EOT;
		}//end foreach
	}
	if( $_cat_tID != 0 && $_catID == '' ){
		$_tpl_PageSearch = "{$mArchiveLink}show_topic.{$_cat_tID}";
	} else{
		if( $_catID == '' ) $_catID = 0;
		$_tpl_PageSearch = "{$mArchiveLink}show_topic.{$_cat_tID}.{$_catID}";
	}
	if( $keyword !== '' ){
		$_tpl_PageSearch .= "-".urlencode($_POST['searchword'])."-{$_POST['sel']}";
	}
	if( $_tpl_PageSearch !== '' ){
		$_tpl_PageSearch = $_tpl_PageSearch;
	}
	print <<<EOT
			<script type="text/JavaScript" src="space/script/pagination.js"></script>
			<h3 style="width: 776px; height: 30px; padding:0px; margin: 0px auto;overflow: hidden;">
			<script type="text/JavaScript">
				PageList({$topiclist['AbsolutePage']},3,{$topiclist['PageSize']},{$topiclist['RecordCount']},"{$_tpl_PageSearch}",5);
			</script>
			</h3>
EOT;
}
print <<<EOT
		</div>
EOT;

function _getChannel($channelid)
{
	global $spaceUserCat;
	static $cache = array();
	static $blncache1 = null;
	if (null === $blncache1) {
		$blncache1 = (!empty($spaceUserCat['result_set']) AND is_array($spaceUserCat['result_set']));
		$blncache2 = (!empty($spaceUserCat['result_set']) AND is_array($spaceUserCat['result_set']));
	}
	if (!$blncache1 AND !$blncache2) {
		return '';
	}
	if (empty($cache["{$channelid}"])) {
		foreach ($spaceUserCat['result_set'] AS $val) {
			if ($val['ucatid'] == $channelid) {
				$cache["{$channelid}"] = trim($val['ucattitle']);
				break;
			}
		}//end foreach
	}
	if (!isset($cache["{$channelid}"]) OR '' === $cache["{$channelid}"]) {
	}
	return trim($cache["{$channelid}"]);
}//end function _getChannel
?>
