<?php
require_once(dirname(__FILE__)."/../inc/common.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%原创、未引入任何网上代码,对一切抄袭行为、坚决严肃追究法律责任
'*******************************************************************************************/
if (paramset==0 || runMode=="forgedStatic"){
    $paras = replaceStr(QUERY_STRING,fileSuffix,'');
    if (strpos($paras, "-") > 0) {
	    $parasArray = explode("-",$paras); $id = $parasArray[0]; $page = $parasArray[1];
    } else {
	    $id = $paras; $page = 1;
    }
}else{
	$id=getForm(paramid,"both") ; $page=getForm(parampage,"both");
}

if (empty($id)) {
	echoSaveStr("null");exit();
} else {
	if (is_numeric($id)){ $id = intval($id); } else { echoSaveStr("safe");exit();}
}

if (empty($page)) {
	$page=1;
} else {
	if (is_numeric($page)) { $page = intval($page); } else { echoSaveStr("safe");exit();}
}
getTopicPage($id,$page);

function getTopicPage($id,$page){
	$row = DB::fetch_first("SELECT m_id,m_name,m_template,m_enname FROM ".DB::table('topic')." WHERE m_id=$id");
	if (!is_array($row)) exit("不存在此专题");
	$topicTemplatePath = DJCMS_TEMPLATE.$row['m_template'];
	if (empty($row['m_template'])){ $row['m_template']="topic.html";}
	$x = DJCMS_TEMPLATE.$row['m_template'];
	djcms::$currentTopicId = $row['m_id'];$cacheName = "parse_topic_".$id;
	if (cacheStart == 1){
		if (djcms::$content = memory('get', $cacheName)) {
        } else {
            parseTopicIndexPart($topicTemplatePath);
            memory('set', $cacheName, djcms::$content);
        }
	} else {
		parseTopicIndexPart($topicTemplatePath);
	}
	djcms::$content=replaceStr(djcms::$content,"{djcms:topicname}",$row['m_name']); 
	djcms::$content=replaceStr(djcms::$content,"{topicpagelist:page}",$page);
	djcms::parsePageList($id,$page,"topicpage");
	djcms::parseIf();
	echo replaceStr(djcms::$content,"{djcms:runinfo}",getRunTime()); 
}

function parseTopicIndexPart($x)
{
	djcms::$content=loadFile($x);
	djcms::parseTopAndFoot();
	djcms::parseSelf();
	djcms::parseGlobal();
	djcms::parseMenuList("");
	djcms::parseNewsList();
	djcms::parseAreaList();
	djcms::parseVideoList();
	djcms::parseTopicList();
	djcms::parseLinkList();
	djcms::$content=replaceTopicId(replaceCurrentTypeId(djcms::$content));
}
?>
