<?php
ob_implicit_flush(true);
@set_time_limit(0);
require_once(dirname(__FILE__)."/admin_inc.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%原创、未引入任何网上代码,对一切抄袭行为、坚决严肃追究法律责任
'*******************************************************************************************/
viewHead("生成选项"."-" .$menuList[3][0]);
$flag = getForm("flag","get");$makenum = getForm("makenum","get");$mareplaycount = 0;
if (empty($flag)) $flag = 0; else $flag = intval($flag);
$action = getForm("action", "get");
switch ($action) {
	case "custom":  makecustom();break;
 	case "allcustom"  :makeAllCustom();break;
	case "baidu":makeBaidu();break;
	case "google":makeGoogle();break;
	case "rss":makeRss();break;
//video
	case "index":checkRunMode(runMode);makeIndex();break;
	case "map":makeAllmovie();break;
	case "js":makeVideoJs();break;
	case "channel":checkRunMode(runMode);makeChannel();break;
	case "allchannel":checkRunMode(runMode);makeAllChannel();break;
	case "channelbyids":checkRunMode(runMode);makeChannelByIDS();break;
	case "content":checkRunMode(runMode);makeContent();break;
	case "allcontent":checkRunMode(runMode);makeAllContent();break;
	case "topicindex":checkRunMode(runMode);makeTopicIndex();break;
	case "topic":checkRunMode(runMode);makeTopic();break;
	case "alltopic":checkRunMode(runMode);makeAllTopic();break;
	case "site":checkRunMode(runMode);makeSite();break;
	case "day":checkRunMode(runMode);makeDay();break;
	case "single":checkRunMode(runMode);makeSingle();break;
	case "selected":checkRunMode(runMode);makeSelected();break;
	case "lengthchannel" :checkRunMode(runMode);makelengthchannel();break;
	case "daysview" :checkRunMode(runMode);makeDaysview();break;
//news
	case "newsindex":checkRunMode(newsrunMode);makeNewsIndex();break;
	case "newsmap":makeAllnews();break;
	case "newsjs":makeNewsJs();break;
	case "newschannel":checkRunMode(newsrunMode);makeNewsPart();break;
	case "newsallchannel":checkRunMode(newsrunMode);makeAllNewsPart();break;
	case "newschannelbyids":checkRunMode(newsrunMode);makeNewsPartByIDS();break;
	case "newscontent":checkRunMode(newsrunMode);makeArticle();break;
	case "newsallcontent":checkRunMode(newsrunMode);makeAllArticle();break;
	case "newssite":checkRunMode(newsrunMode);makenewsSite();break;
	case "newsday":checkRunMode(newsrunMode);makenewsDay();break;
	case "newssingle":checkRunMode(newsrunMode);makenewsSingle();break;
	case "newsselected":checkRunMode(newsrunMode);makenewsSelected();break;
	case "newslengthchannel" :checkRunMode(newsrunMode);makenewslengthchannel();break;
	case "newsdaysview" :checkRunMode(newsrunMode);makenewsDaysview();break;
	default : main();break;
}
if ($action != "main"){ viewFoot();}

function checkRunMode($mode){
	if ($mode!="static") die("<div style='width:50%;margin-top:50px;background:#66CCCC;font-size:13px;'><br><font color='red'>网站运行模式非静态，不允许生成</font><br><br></div>");
}

function main() {
	global $menuList;
?>
<div id="append_parent"></div>
<div class="container" id="cpcontainer">
<!--当前导航-->
<script type="text/JavaScript">if(parent.$('admincpnav')) parent.$('admincpnav').innerHTML='后台首页&nbsp;&raquo;&nbsp;<?=$menuList[3][0]?>&nbsp;&raquo;&nbsp;生成选项';</script>
<ul id="makeHtmlTab">
<li id="li.v" onclick="toogletab('0')" style="cursor:pointer">生成视频相关</li>
<li id="li.n" onclick="toogletab('1')" style="cursor:pointer">生成新闻相关</li>
<li id="li.o" onclick="toogletab('2')" style="cursor:pointer">生成其它</li>
</ul>
<table class="tb">
	<tbody id="news" style="display:none;">
		<tr>
		<td><input type="button" value="生成新闻首页" class="btn" onClick="javascript:window.open('?action=newsindex','msg');"<?=ifthen(newsrunMode=="static",""," disabled")?>>&nbsp;&nbsp;<input type="button" value="生成地图页" class="btn" onClick="javascript:window.open('?action=newsmap','msg');">&nbsp;<input type="button" class="btn" value="生成JS调用" onClick="javascript:window.open('?action=newsjs','msg');">&nbsp;<input type="button" class="btn" value="一键生成全站" onClick="javascript:window.open('?action=newssite&action3=newssite','msg');"<?=ifthen(newsrunMode=="static",""," disabled")?>>&nbsp;<input type="button" class="btn" value="一键生成当天" onClick="javascript:window.open('?action=newsday','msg');"<?=ifthen(newsrunMode=="static",""," disabled")?>></td>
		</tr>
		<tr><td>
		<form action="?action=newschannel" method="post" target="msg" id="newscform">
		<select name="channel" id="channel" style="width:121px">
		<option value="">请选择分类</option>
		<?=makeNewsTypeOption(0,"&nbsp;|&nbsp;&nbsp;")?>
		</select>
		&nbsp;<input type="submit" class="btn" value="生成栏目页" onclick="$('newscform').action='?action=newschannel';"<?=ifthen(newsrunMode=="static",""," disabled")?>>
		<input type="button" class="btn" value="生成全部栏目页" onClick="javascript:window.open('?action=newsallchannel','msg');"<?=ifthen(newsrunMode=="static",""," disabled")?>>
		开始页数：<input type="text" id="startpage" name="startpage" value='1' size="3" maxlength="3"/>结束页数：<input type="text" id="endpage" name="endpage" value='1' size="3" maxlength="6"/>
		<input type="button" class="btn" value="生成部分栏目页" onclick="newssubmitform()"<?=ifthen(newsrunMode=="static",""," disabled")?>>
		</form>
		</td></tr>
		<tr><td>
		<form action="?action=newscontent" method="post" target="msg" id="newsviewform"<?=ifthen(newsrunMode=="static",""," disabled")?>>
		<select name="channel" id="channel" style="width:121px">
		<option value="">请选择分类</option>
		<?=makeNewsTypeOption(0,"&nbsp;|&nbsp;&nbsp;")?>
		</select>
		&nbsp;<input type="submit" class="btn" value="生成内容页" onclick="$('newsviewform').action='?action=newscontent';"<?=ifthen(newsrunMode=="static",""," disabled")?>>
		<input type="button" class="btn" value="生成全部内容页" onClick="javascript:window.open('?action=newsallcontent&action2=newsallcontent','msg');"<?=ifthen(newsrunMode=="static",""," disabled")?>>
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<input type="button" class="btn" value="生成" onClick="newssubmitvform()"<?=ifthen(newsrunMode=="static",""," disabled")?>>
		<select name="days" id="days">
        <?php for ($i = 1;$i < 7;$i++) {
echo "<option value=\"$i\">$i</option>";
}?>

		</select>
		日内内容页 
		</form>
		</td></tr>
	</tbody>
	<tbody id="other" style="display:none;">
		<tr><td>
		<form action="?action=topic" method="post" target="msg">
		<?php echo makeTopicSelect("channel","请选择专题","");?>
		<input type="submit" class="btn" value="生成专题分页"<?=ifthen(runMode=="static",""," disabled")?>>
		<input type="button" class="btn" value="生成专题首页列表" onClick="javascript:window.open('?action=topicindex','msg');"<?=ifthen(runMode=="static",""," disabled")?>>
		<input type="button" class="btn" value="一键生成全部专题" onClick="javascript:window.open('?action=alltopic&action2=alltopic&action3=topicindex','msg');"<?=ifthen(runMode=="static",""," disabled")?>>
		</form>
		</td></tr>
		<tr><td>
			<form action="?action=custom" method="post" target="msg" id="customform">
			<select name="custom" id="custom">
			<option value="">请选择自定义模板文件</option>
<?php
   $dh = dir(DJCMS_TEMPLATE);
   while($filename=$dh->read())
   {
      if(strpos($filename,"elf_")>0) echo "<option value='$filename'>$filename</option>\r\n";
   }
?>
			</select>
			<input type="submit" class="btn" value="生成自定义页" >
			<input type="button" class="btn" value="生成全部自定义页" onClick="submitcform()">
			</form>
		</td></tr>
	</tbody>
	<tbody id="video">
		<tr><td><input type="button" value="生成视频首页" class="btn" onClick="javascript:window.open('?action=index','msg');"<?=ifthen(runMode=="static",""," disabled")?>>&nbsp;&nbsp;<input type="button" value="生成地图页" class="btn" onClick="javascript:window.open('?action=map','msg');">&nbsp;<input type="button" value="生成JS调用" class="btn" onClick="javascript:window.open('?action=js','msg');">&nbsp;<input type="button" value="一键生成全站" class="btn" onClick="javascript:window.open('?action=site&action3=site','msg');"<?=ifthen(runMode=="static",""," disabled")?>>&nbsp;<input type="button" value="一键生成当天" class="btn" onClick="javascript:window.open('?action=day','msg');"<?=ifthen(runMode=="static",""," disabled")?>>
		</td>
		</tr>
		<tr><td>
		<form action="?action=channel" method="post" target="msg" id="cform"<?=ifthen(runMode=="static",""," disabled")?>>
		<select name="channel" id="channel" style="width:121px">
		<option value="">请选择分类</option>
		<?=makeTypeOption(0,"&nbsp;|&nbsp;&nbsp;")?>
		</select>
		&nbsp;<input type="submit" class="btn" value="生成栏目页" onclick="$('cform').action='?action=channel';"<?=ifthen(runMode=="static",""," disabled")?>>
		<input type="button" class="btn" value="生成全部栏目页" onClick="javascript:window.open('?action=allchannel','msg');"<?=ifthen(runMode=="static",""," disabled")?>>
		开始页数：<input type="text" id="startpage" name="startpage" value='1' size="3" maxlength="3"/>结束页数：<input type="text" id="endpage" name="endpage" value='1' size="3" maxlength="6"/>
		<input type="button"  class="btn"  value="生成部分栏目页" onclick="submitform()"<?=ifthen(runMode=="static",""," disabled")?>>
		</form>
		</td></tr>
		<tr><td>
		<form action="?action=content" method="post" target="msg" id="viewform"<?=ifthen(runMode=="static",""," disabled")?>>
		<select name="channel" id="channel" style="width:121px">
		<option value="">请选择分类</option>
		<?=makeTypeOption(0,"&nbsp;|&nbsp;&nbsp;")?>
		</select>
		&nbsp;<input type="submit" class="btn" value="生成内容页" onclick="$('viewform').action='?action=content';"<?=ifthen(runMode=="static",""," disabled")?>>
		<input type="button" class="btn" value="生成全部内容页" onClick="javascript:window.open('?action=allcontent&action2=allcontent','msg');"<?=ifthen(runMode=="static",""," disabled")?>>
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<input type="button" class="btn" value="生成" onClick="submitvform()"<?=ifthen(runMode=="static",""," disabled")?>>
		<select name="days" id="days">
		<?php 
		 for ($i = 1;$i < 7;$i++) {
            echo "<option value=\"$i\">$i</option>";
         }
         ?>
		</select>
		日内内容页 
		</form>
		<br />
		注意：网站在静态模式下，如果<a href="admin_config.php" target="main"><font color="blue">网站配置</font></a>中选择了<font color="red">"生成播放页"</font>，那么生成内容页的同时、将会生成播放页
		</td></tr>
	</tbody>
</table>
</div>
<script type="text/javascript">
function submitcform()
{
	$('customform').action="?action=allcustom"
	$('customform').submit()
}
function submitvform()
{
	$('viewform').action="?action=daysview"
	$('viewform').submit()
}
function submitform()
{
	$('cform').action="?action=lengthchannel"
	$('cform').submit()
}
function newssubmitvform()
{
	$('newsviewform').action="?action=newsdaysview"
	$('newsviewform').submit()
}
function newssubmitform()
{
	$('newscform').action="?action=newslengthchannel"
	$('newscform').submit()
}
var k='Makehtml_tab';
function toogletab(to){
	var a=['li.v','li.n','li.o'],b=['video','news','other'];
	var x=[[1,0,0],[0,1,0],[0,0,1]][to];
	for(var i=0;i<x.length;i++){
		$(a[i]).className = x[i]==1 ? 'hover':'';
		$(b[i]).style.display = x[i]==1 ? '':'none';
	}
	//setCookie(k,to,365*24);
}
toogletab(getCookie(k) | 0);
</script>
<iframe style="Z-INDEX: 1; VISIBILITY: inherit; WIDTH: 100%; HEIGHT: 305px;" name="msg"  frameBorder=0 scrolling=yes></iframe>
<?php
}

function makeSingle() {
	$id = getForm("id", "get");$back = getRefer();$from = getForm("from", "get");
	makeContentById($id);
	if (empty($from)){  alertMsg("",$back); } else {  alertMsg("",$from);}
}

function makenewsSingle() {
	$id = getForm("id", "get");$back = getRefer();$from = getForm("from", "get");
	makeArticleById($id);
	if (empty($from)){  alertMsg("",$back); } else {  alertMsg("",$from);}
}

function makeSelected() {
	$ids = dimplode(getForm("m_id","post"));$REFERER = getForm("REFERER","post");$back = getRefer();
	$idsArray = explode(",",$ids);
	$m=count($idsArray);
	for ($i = 0;$i < $m;$i++) {
		makeContentById($idsArray[$i]);
	}
	if (empty($REFERER)){  alertMsg("",$back); } else {  alertMsg("",$REFERER);}
}

function makenewsSelected() {
	$ids = dimplode(getForm("m_id","post"));$REFERER = getForm("REFERER","post");$back = getRefer();
	$idsArray = explode(",",$ids);
	$m=count($idsArray);
	for ($i = 0;$i < $m;$i++) {
		makeArticleById($idsArray[$i]);
	}
	if (empty($REFERER)){  alertMsg("",$back); } else {  alertMsg("",$REFERER);}
}

function makeIndex() {
	djcms::$content=loadFile(DJCMS_TEMPLATE."index.html");
	djcms::parseTopAndFoot();
	djcms::parseSelf();
	djcms::parseGlobal();
	djcms::$content=replaceCurrentTypeId(djcms::$content);
	djcms::parseMenuList("");
	djcms::parseAreaList();
	djcms::parseTopicList();
	djcms::parseVideoList();
	djcms::parseNewsList();
	djcms::parseLinkList();
	djcms::parseIf();
	$indexStr = djcms::$content;
	createTextFile(djcms::$content,"/index".fileSuffix);
	echo "首页生成完毕 <a target='_blank' href='../index".fileSuffix."'><font color=red>浏览首页</font></a><br>";
}

function makeNewsIndex() {
	$y=getNewsIndexLink();
	djcms::$content=loadFile(DJCMS_TEMPLATE."newsindex.html");
	djcms::parseTopAndFoot();
	djcms::parseSelf();
	djcms::parseGlobal();
	djcms::$content=replaceCurrentTypeId(djcms::$content);
	djcms::parseMenuList("");
	djcms::parseAreaList();
	djcms::parseTopicList();
	djcms::parseVideoList();
	djcms::parseNewsList();
	djcms::parseLinkList();
	djcms::parseIf();
	createTextFile(djcms::$content,$y);
	echo "首页生成完毕 <a target='_blank' href='../$y'><font color=red>浏览新闻首页</font></a><br>";
}

function makeAllmovie() {
	djcms::$content=loadFile(DJCMS_TEMPLATE."map.html");
	djcms::parseTopAndFoot();
	djcms::parseSelf();
	djcms::parseGlobal();
	djcms::$content=replaceCurrentTypeId(djcms::$content);
	djcms::parseMenuList("");
	djcms::parseAreaList();
	djcms::parseTopicList();
	djcms::parseVideoList();
	djcms::parseNewsList();
	djcms::parseLinkList();
	djcms::parseIf();
	$mapStr = replaceStr(djcms::$content,"{djcms:runinfo}","");
	createTextFile($mapStr,"/allmovie".fileSuffix);
	echo "地图页生成完毕 <a target='_blank' href='../allmovie".fileSuffix."'><font color=red>浏览地图页</font></a><br>";
}

function makeAllnews() {
	$x="/".ifthen((strpos("#dir2#dir4#dir6#dir8",newsMakeMode)>0),newsDirName3,newsDirName2)."/allnews".newsFileSuffix;
	djcms::$content=loadFile(DJCMS_TEMPLATE."newsmap.html");
	djcms::parseTopAndFoot();
	djcms::parseSelf();
	djcms::parseGlobal();
	djcms::$content=replaceCurrentTypeId(djcms::$content);
	djcms::parseMenuList("");
	djcms::parseAreaList();
	djcms::parseTopicList();
	djcms::parseVideoList();
	djcms::parseNewsList();
	djcms::parseLinkList();
	djcms::parseIf();
	$mapStr = replaceStr(djcms::$content,"{djcms:runinfo}","");
	createTextFile($mapStr,$x);
	echo "地图页生成完毕 <a target='_blank' href='../$x'><font color=red>浏览新闻地图页</font></a><br>";
}

function makeAllCustom() {
	$dh = dir(DJCMS_TEMPLATE);
	while ($filename = $dh->read()) {
	    if (strpos($filename,"elf_") > 0) makeCustomInfo($filename);
	}
}

function makeCustom() {
	$customtemplate = dimplode(getForm("custom", "both"));
	if (empty($customtemplate)) die("请选择模板");
	$x=explode(",",$customtemplate);
	$arraylen=count($x);
	for ($i = 0;$i < $arraylen;$i++) {
		makeCustomInfo($x[$i]);
    }
}

function makeCustomInfo($templatename) {
	global $customLink,$totalPages;
	$totalPages=0;
	$nameAnd = explode(".",$templatename);
	$customLink="/".sitePath.replaceStr(replaceStr($nameAnd[0],"self_",""),"@","/")."<page>.html";
	$templatePath = DJCMS_TEMPLATE.$templatename;
	$cacheName = "parse_customvideo_".$templatename;
	if (cacheStart == 1) {
		if (djcms::$content = memory('get', $cacheName)) {
        } else {
            parseCachePart("customvideo", $templatePath);
			memory('set', $cacheName, djcms::$content);
        }
	} else {
			parseCachePart("customvideo", $templatePath);
	}
	$tempStr = djcms::$content;
	if (strpos($tempStr,"{/customvideolist}")==0) $totalPages=1;
	for ($i = 1;$i <= $totalPages;$i++) {
		$link = getCustomLink($i);
		djcms::$content=replaceStr($tempStr,"{customvideo:page}",$i);
		djcms::ParsePageList("",$i,"customvideo");
		djcms::parseIf();
		createTextFile(djcms::$content, $link);
		echo "自定义文件<font color=red>".$link."</font>生成完毕 <a target='_blank' href='".$link."'><font color=red>浏览页面</font></a><br>";
	}
}

function makeVideoJs() {
	djcms::$content=loadFile(DJCMS_TEMPLATE."js.html");
	djcms::parseTopAndFoot();
	djcms::parseSelf();
	djcms::parseGlobal();
	djcms::parseMenuList("");
	djcms::parseNewsList();
	djcms::parseAreaList();
	djcms::parseVideoList();
	djcms::parseTopicList();
	djcms::$content = replaceCurrentTypeId(djcms::$content,-444);
	djcms::parseIf();
	$jsname="/js.js";
	createTextFile(djcms::$content,$jsname);
	echo "数据JS调用文件生成完毕 <a target='_blank' href='..".$jsname."'><font color=red>浏览</font></a><br>";
}

function makeNewsJs() {
	$x="/".ifthen((strpos("#dir2#dir4#dir6#dir8",newsMakeMode)>0),newsDirName3,newsDirName2)."/news.js";
	djcms::$content=loadFile(DJCMS_TEMPLATE."newsjs.html");
	djcms::parseTopAndFoot();
	djcms::parseSelf();
	djcms::parseGlobal();
	djcms::parseMenuList("");
	djcms::parseNewsList();
	djcms::parseAreaList();
	djcms::parseVideoList();
	djcms::parseTopicList();
	djcms::$content = replaceCurrentTypeId(djcms::$content);
	djcms::parseIf();
	createTextFile(djcms::$content,$x);
	echo "数据JS调用文件生成完毕 <a target='_blank' href='..".$x."'><font color=red>浏览</font></a><br>";
}

function makeTopic() {
	$channel = getForm("channel","both");$curTypeIndex = getForm("index","get");if (empty($channel)) die("请选择主题");
	if (is_numeric($curTypeIndex)) $curTypeIndex=intval($curTypeIndex); else $curTypeIndex=0;
	makeTopicById($channel,$$curTypeIndex);
}

function makeTopicById($topicId, $curTypeIndex){
	global $action,$action3;
	$currentPage= getForm("page","get");if (is_numeric($currentPage)) $currentPage=intval($currentPage); else $currentPage=1;
	$row = DB::fetch_first("SELECT m_id,m_name,m_template,m_enname FROM ".DB::table('topic')." WHERE m_id=$topicId");
	if (!is_array($row)) exit("不存在专题");
	if (empty($row['m_template'])) $row['m_template']="topicpage.html";
	$topicTemplatePath = DJCMS_TEMPLATE.$row['m_template'];
	$pSize = getPageSizeOnCache($topicTemplatePath,"topicpage",$row['m_template']);if (empty($pSize)) $pSize=12;
	echoBegin("","topicpage");
	$r = DB::fetch_first("SELECT count(*) as number FROM ".DB::table('data')." WHERE m_topic=".$topicId);
    $rCount = $r['number'];
	$m = $rCount % $pSize;
	$n = ($rCount / $pSize);
	if ($m == 0) $pCount = $n; else $pCount = $n + 1;
	$topicpageName = $row['m_name'];$topicEnname = $row['m_enname'];djcms::$currentTopicId = $row['m_id'];
	$cacheName = "parse_topicpage_".$topicId;
	if (cacheStart == 1) {
		if (djcms::$content = memory('get', $cacheName)) {
        } else {
            parseCachePart("topicpage",$topicTemplatePath);
			djcms::$content=replaceStr(djcms::$content,"{djcms:topicname}",$row['m_name']); 
            memory('set', $cacheName, djcms::$content);
        }
	} else {
			parseCachePart("topicpage",$topicTemplatePath);
			djcms::$content=replaceStr(djcms::$content,"{djcms:topicname}",$row['m_name']); 
	}
	$tempStr = djcms::$content;
	if ($rCount == 0){
		$topicpageLink = getTopicPageLink($row['m_id'],1,$topicEnname);
		djcms::$content = replaceStr($tempStr,"{topicpagelist:page}",1);
		djcms::parsePageList($row['m_id'],$i,"topicpage");
		djcms::parseIf();
		$channelStr = djcms::$content;
		createTextFile($channelStr,$topicpageLink);echoEach($topicpageName,$i,$topicpageLink,"topicpage");
	}
	if (strpos($tempStr,"{/djcms:topicpagelist}")==0) $pCount=1;
	if ($currentPage<1) $currentPage=1;
	$nCount=200+$currentPage-1;if ($pCount<$nCount) $nCount=$pCount;
	for ($i = $currentPage;$i <= $nCount;$i++) {
		$topicpageLink = getTopicPageLink($row['m_id'],$i,$topicEnname);
		djcms::$content=replaceStr($tempStr,"{topicpagelist:page}",$i);
		djcms::parsePageList($row['m_id'],$i,"topicpage");
		djcms::parseIf();
		$channelStr = djcms::$content;
		createTextFile($channelStr,$topicpageLink);echoEach($topicpageName,$i,$topicpageLink,"topicpage");
	}
	$currentPage = $i;
	if ($i >= $pCount) {
		$curTypeIndex = $curTypeIndex + 1;$currentPage = 1;
	}
	if ($action == "topic") {
	    if ($curTypeIndex < 1) {
		    echoChannelSuspend3($topicId, $curTypeIndex, $currentPage,makeTimeSpan);
		}
	} else {
		echoChannelSuspend($curTypeIndex, $action3, $currentPage,makeTimeSpan);
	}
}

function makeTopicIndex(){
	$currentPage= getForm("page","get");if (is_numeric($currentPage)) $currentPage=intval($currentPage); else $currentPage=1;
	$topicTemplatePath = DJCMS_TEMPLATE."/topicindex.html";
	$pSize = getPageSizeOnCache($topicTemplatePath,"topicindex","topicindex.html");if (empty($pSize)) $pSize=12;
	echoBegin("","topicindex");
	$allRecordset = db::getCount("SELECT m_name,m_id,m_pic,m_enname,m_des FROM ".DB::table('topic')." order by m_sort asc");
	$cacheName = "parse_tp_";
	if (cacheStart == 1) {
		if (djcms::$content = memory('get', $cacheName)) {
        } else {
            parseCachePart("topicindex",$topicTemplatePath);
            memory('set', $cacheName, djcms::$content);
        }
	} else {
			parseCachePart("topicindex",$topicTemplatePath);
	}
	$tempStr = djcms::$content;$pCount = ceil($allRecordset/$pSize);
	if ($allRecordset==0){
		$topicindexLink = getTopicIndexLink(1);
		djcms::$content = replaceStr($tempStr,"{topicindexlist:page}",1);
		djcms::parseTopicIndex($i,$pCount);
		djcms::parseIf();
		$channelStr = djcms::$content;
		createTextFile($channelStr,$topicindexLink);echoEach("",$i,$topicindexLink,"topicindex");
	}
	if (strpos($tempStr,"{/djcms:topicindexlist}")==0) $pCount=1;
	if ($currentPage<1) $currentPage=1;
	$nCount = 200 + $currentPage - 1;if ($pCount < $nCount){ $nCount = $pCount;}
	for ($i = $currentPage;$i <= $nCount;$i++) {
		$topicindexLink = getTopicIndexLink($i);
		djcms::$content = replaceStr($tempStr,"{topicindexlist:page}",$i);
		djcms::parseTopicIndex($i,$pCount);
		djcms::parseIf();
		$channelStr = djcms::$content;
		createTextFile($channelStr,$topicindexLink);echoEach("",$i,$topicindexLink,"topicindex");
    }
	$currentPage=$i;
	if ($nCount >= $pCount) {
		$action3 = getForm("action3","get");
		if (empty($action3)) {
			alertMsg("恭喜你，主题列表生成完毕","");exit;
        } else if ($action3=="topicindex") {
			alertMsg("一键生成主题列表全部搞定","");exit;
        }
    }else{
		echoChannelSuspend2("","","",$currentPage,makeTimeSpan);
    }
}

function makeAllTopic() {
	$curTypeIndex = getForm("index","get");$action3 = getForm("action3","get");
	$topicIdArray = getTopicIdArrayBySortOnCache();
	$topicIdArrayLen = count($topicIdArray);
	if (empty($curTypeIndex)) {
		$curTypeIndex = 0;
	} else {
		if (intval($curTypeIndex) > intval($topicIdArrayLen-1)) {
			if (empty($action3)) {
				alertMsg("生成全部主题内页完成","");exit;
		    } else if ($action3 == "topicindex") {
				echo "<script language='javascript'>self.location='?action=topicindex&action3=".$action3."';</script>";exit; 
		    }
		}
	}
	$topicId = $topicIdArray[$curTypeIndex];
	if (empty($topicId)) die("分类丢失"); else makeTopicById($topicId, $curTypeIndex);
}

function makeSite(){
	$action3 = getForm("action3","get");
	echo "<script language='javascript'>self.location='?action=allcontent&action2=allcontent&action3=".$action3."';</script>";
}

function makenewsSite(){
	$action3 = getForm("action3","get");
	echo "<script language='javascript'>self.location='?action=newsallcontent&action2=newsallcontent&action3=".$action3."';</script>";
}

function makeDay() {
	$page = getForm("page","get");
	$sqlStr = "SELECT m_id FROM ".DB::table('data')." WHERE m_wrong=0";
	$today_start = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$today_end = mktime(0,0,0,date('m'),date('d')+1,date('Y'));
	$whereStr = " AND `m_addtime` BETWEEN '{$today_start}' AND '{$today_end}'";
	$sqlStr = $sqlStr . $whereStr;
	$recordcount = db::getCount($sqlStr);
	if ($recordcount == 0) {
		die("当天没有视频<br>");
	}
	$pagesize=100;
	$pagecount = ceil($recordcount / $pagesize);
	if (empty($page)) $page=1; else $page=intval($page);
	echoBegin("正在开始生成当天数据,当前是第<font color='red'>".$page."</font>页,共<font color='red'>".$pagecount."</font>页<br>","content");
	$page = max(intval($page), 1);
    $limitstart = $pagesize*($page-1);
	$query = DB::query($sqlStr." LIMIT $limitstart,$pagesize");
    while($row = DB::fetch($query)) {
		makeContentById($row['m_id']);
	}
	if ($page > $pagecount) {
		$query = DB::query(replaceStr($sqlStr,"m_id","m_type")." GROUP BY m_type");$ids="";
        while($rowt = DB::fetch($query)) {
			if (!isTypeHide($rowt['m_type'])) {
				 if (empty($ids)) $ids = $rowt['m_type']; else $ids .= ",".$rowt['m_type'];
			}
		}
	    if (!empty($ids)) {
			 $tl = getTypeLists();
			 foreach ($tl as $vv) {
				 if (strpos(" ,".$ids.",",",".$vv['m_id'].",") > 0) {
					 if ($vv['m_upid'] > 0 && strpos(" ,".$ids.",",",".$vv['m_id'].",") == 0) $ids = $vv['m_id'].",".$ids;
				 }
			 }
		}
		if (!empty($ids)) {
		    echo "生成当天数据搞定<script language='javascript'>self.location='?action=channelbyids&ids=".$ids."&action3=site';</script>";exit; 
        } else {
		    alertMsg("一键生成全部搞定","");exit;
        }
    }
	echoDaySuspend($page+1,0,makeTimeSpan);
}

function makenewsDay() {
	$page = getForm("page","get");
	$sqlStr = "SELECT m_id FROM ".DB::table('news')." WHERE m_recycle=0";
	$today_start = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$today_end = mktime(0,0,0,date('m'),date('d')+1,date('Y'));
	$whereStr = " AND `m_addtime` BETWEEN '{$today_start}' AND '{$today_end}'";
	$sqlStr = $sqlStr . $whereStr;
	$recordcount = db::getCount($sqlStr);
	if ($recordcount == 0) {
		die("当天没有视频<br>");
	}
	$pagesize=100;
	$pagecount = ceil($recordcount / $pagesize);
	if (empty($page)) $page=1; else $page=intval($page);
	echoBegin("正在开始生成当天数据,当前是第<font color='red'>".$page."</font>页,共<font color='red'>".$pagecount."</font>页<br>","content");
	$page = max(intval($page), 1);
    $limitstart = $pagesize*($page-1);
	$query = DB::query($sqlStr." LIMIT $limitstart,$pagesize");
    while($row = DB::fetch($query)) {
		makeArticleById($row['m_id']);
	}
	if ($page > $pagecount) {
		$query = DB::query(replaceStr($sqlStr,"m_id","m_type")." GROUP BY m_type");$ids="";
        while($rowt = DB::fetch($query)) {
			if (!isNewsTypeHide($rowt['m_type'])) {
				 if (empty($ids)) $ids = $rowt['m_type']; else $ids .= ",".$rowt['m_type'];
			}
		}
	    if (!empty($ids)) {
			 $tl = getNewsTypeLists();
			 foreach ($tl as $vv) {
				 if (strpos(" ,".$ids.",",",".$vv['m_id'].",") > 0) {
					 if ($vv['m_upid'] > 0 && strpos(" ,".$ids.",",",".$vv['m_id'].",") == 0) $ids = $vv['m_id'].",".$ids;
				 }
			 }
		}
		if (!empty($ids)) {
		    echo "生成当天数据搞定<script language='javascript'>self.location='?action=newschannelbyids&ids=".$ids."&action3=newssite';</script>";exit; 
        } else {
		    alertMsg("一键生成全部搞定","");exit;
        }
    }
	echoDaySuspend($page+1,0,newsmakeTimeSpan);
}

function echoDaySuspend($curPage,$days,$sleep){
	global $action;
	echo "<br>暂停".$sleep."秒后继续生成<script language=\"javascript\">setTimeout(\"makeNextPage();\",".$sleep."000);function makeNextPage(){location.href='?action=".$action."&page=".$curPage."&days=".$days."';}</script>";
}

function makeAllContent() {
	$curTypeIndex = getForm("index","get");$action3 = getForm("action3","get");
	$typeIdArray = getTypeIdArrayBySortOnCache(0);
	$typeIdArrayLen = count($typeIdArray);
	if (empty($curTypeIndex)) {
		$curTypeIndex = 0;
	} else { 
		if (intval($curTypeIndex) > intval($typeIdArrayLen-1)) {
			if (empty($action3)) {
				alertMsg ("生成全部内容页完成","");exit();
			} else if ($action3 == "site") {
				echo "<script language='javascript'>self.location='?action=allchannel&action3=".$action3."';</script>";exit();
			}
		}
	}
	$typeId = $typeIdArray[$curTypeIndex];
   	if(empty($typeId)) exit("分类丢失"); else makeContentByChannel($typeId,false);
}

function makeAllArticle() {
	$curTypeIndex = getForm("index","get");$action3 = getForm("action3","get");
	$typeIdArray = getNewsTypeIdArrayBySortOnCache(0);
	$typeIdArrayLen = count($typeIdArray);
	if (empty($curTypeIndex)) {
		$curTypeIndex = 0;
	} else { 
		if (intval($curTypeIndex) > intval($typeIdArrayLen-1)) {
			if (empty($action3)) {
				alertMsg ("生成全部内容页完成","");exit();
			} else if ($action3 == "newssite") {
				echo "<script language='javascript'>self.location='?action=newsallchannel&action3=".$action3."';</script>";exit(); 
			}
		}
	}
	$typeId = $typeIdArray[$curTypeIndex];
   	if(empty($typeId)) exit("分类丢失"); else makeArticleByChannel($typeId,false);
}

function makeContent() {
	$channel = getForm("channel","both");if (empty($channel)) die("请选择分类");
	makeContentByChannel($channel,false);
}

function makeArticle() {
	$channel = getForm("channel","both");if (empty($channel)) die("请选择分类");
	makeArticleByChannel($channel,false);
}

function isTypeHide($channel) {
	$isTypeHide=strpos(" ,".getHideTypeIDS().",",",".trim($channel).",")>0;
	return $isTypeHide;
}

function isNewsTypeHide($channel) {
	$isNewsTypeHide=strpos(" ,".getHideNewsTypeIDS().",",",".trim($channel).",")>0;
	return $isNewsTypeHide;
}

function makeContentByChannel($channel, $isIncludeSub) {
	$action2 = getForm("action2","get");$action3=getForm("action3","get");
	$currentPage= getForm("page","get");$curTypeIndex=getForm("index","get");
	if (empty($curTypeIndex)) $curTypeIndex = 0;
	if ($isIncludeSub) {
		$typeIds = getTypeIdOnCache($channel);
		$sqlStr = "SELECT m_id FROM ".DB::table('data')." WHERE m_recycle=0 AND m_type IN (".$typeIds.")";
	} else {
		$typeIds = $channel;
		$sqlStr = "SELECT m_id FROM ".DB::table('data')." WHERE m_recycle=0 AND m_type=".$typeIds;
	}
	$nameAndTemplateArray = explode(",",getTypeNameTemplateArrayOnCache(intval($channel)));
	$typename = $nameAndTemplateArray[0];
	$recordcount = db::getCount($sqlStr);
	if (isTypeHide($channel) == true || $recordcount == 0) {
		if (empty($action2)) {
			echo "该分类<font color='red'>".$typename."</font>无视频或被隐藏<br>" ; return true;
		} else if ($action2 == 'allcontent') {
			echo "该分类<font color='red'>".$typename."</font>无视频或被隐藏<br>" ; echoContentSuspendPerChannel($curTypeIndex+1,$action2,$action3,makeTimeSpan);return true;
		}
	}
	$pagesize = 100;
	$pagecount = ceil($recordcount / $pagesize);
	if (empty($currentPage)) $currentPage=1; else $currentPage=intval($currentPage);
	echoBegin("正在开始生成栏目<font color='red'>".$typename."</font>的内容页,当前是第<font color='red'>".$currentPage."</font>页,共<font color='red'>".$pagecount."</font>页<br>","content");
	$currentPage = max(intval($currentPage), 1);
    $limitstart = $pagesize*($currentPage-1);
	$query = DB::query($sqlStr." LIMIT $limitstart,$pagesize");
    while($row = DB::fetch($query)) {
		makeContentById($row['m_id']);
	}
	if($currentPage >= $pagecount) {
		if (empty($action2)) {
			echo "恭喜此分类搞定" ; return true;
        } else if ($action2 == 'allcontent') {
			echo "恭喜此分类搞定" ; echoContentSuspendPerChannel($curTypeIndex+1,$action2,$action3,makeTimeSpan) ; return true;
        }
    }
	echoContentSuspend($curTypeIndex,$currentPage+1,$channel,$action2,$action3,makeTimeSpan);
}

function makeArticleByChannel($channel, $isIncludeSub) {
	$action2=getForm("action2","get");$action3=getForm("action3","get");
	$currentPage= getForm("page","get");$curTypeIndex=getForm("index","get");
	if (empty($curTypeIndex)) $curTypeIndex = 0;
	if ($isIncludeSub) {
		$typeIds = getNewsTypeIdOnCache($channel);
		$sqlStr = "SELECT m_id FROM ".DB::table('news')." WHERE m_recycle=0 AND m_type IN (".$typeIds.")";
	} else {
		$typeIds = $channel;
		$sqlStr = "SELECT m_id FROM ".DB::table('news')." WHERE m_recycle=0 AND m_type=".$typeIds;
	}
	$nameAndTemplateArray = explode(",",getNewsTypeNameTemplateArrayOnCache(intval($channel)));
	$typename = $nameAndTemplateArray[0];
	$recordcount = db::getCount($sqlStr);
	if (isTypeHide($channel) == true || $recordcount == 0) {
		if (empty($action2)) {
			echo "该分类<font color='red'>".$typename."</font>无新闻或被隐藏<br>" ; return true;
		} else if ($action2 == 'newsallcontent') {
			echo "该分类<font color='red'>".$typename."</font>无新闻或被隐藏<br>" ; echoContentSuspendPerChannel($curTypeIndex+1,$action2,$action3,newsMakeTimeSpan);return true;
		}
	}
	$pagesize = 100;
	$pagecount = ceil($recordcount / $pagesize);
	if (empty($currentPage)) $currentPage=1; else $currentPage=intval($currentPage);
	echoBegin("正在开始生成栏目<font color='red'>".$typename."</font>的内容页,当前是第<font color='red'>".$currentPage."</font>页,共<font color='red'>".$pagecount."</font>页<br>","content");
	$currentPage = max(intval($currentPage), 1);
    $limitstart = $pagesize*($currentPage-1);
	$query = DB::query($sqlStr." LIMIT $limitstart,$pagesize");
    while($row = DB::fetch($query)) {
		makeArticleById($row['m_id']);
	}
	if($currentPage >= $pagecount) {
		if (empty($action2)) {
			echo "恭喜此分类搞定" ; return true;
        } else if ($action2 == 'newsallcontent') {
			echo "恭喜此分类搞定" ; echoContentSuspendPerChannel($curTypeIndex+1,$action2,$action3,newsMakeTimeSpan) ; return true;
        }
    }
	echoContentSuspend($curTypeIndex,$currentPage+1,$channel,$action2,$action3,newsMakeTimeSpan);
}

function echoContentSuspend($typeIdIndex,$page,$channel,$action2,$action3,$sleep){
	global $action;
	echo "<br>暂停".$sleep."秒后继续生成<script language=\"javascript\">setTimeout(\"makeNextPage();\",".$sleep."000);function makeNextPage(){location.href='?action=".$action."&index=".$typeIdIndex."&channel=".$channel."&page=".$page."&action2=".$action2."&action3=".$action3."';}</script>";
}

function echoContentSuspendPerChannel($typeIdIndex,$action2,$action3,$sleep){
	global $action;
	echo "<br>暂停".$sleep."秒后继续生成<script language=\"javascript\">setTimeout(\"makeNextType();\",".$sleep."000);function makeNextType(){location.href='?action=".$action."&index=".$typeIdIndex."&action2=".$action2."&action3=".$action3."';}</script>";
}

function makeContentById($vId){
	$playn = 0;
	if (isAlertWin == 1) $playTemFileName = "openplay.html"; else  $playTemFileName = "play.html";
	$row = DB::fetch_first("SELECT `m_id`,`m_type`,`m_name`,`m_state`,`m_pic`,`m_hit`,`m_actor`,`m_des`,`m_topic`,`m_color`,`m_addtime`,`m_publishyear`,`m_publisharea`,`m_playdata`,`m_downdata`,`m_commend`,`m_note`,`m_digg`,`m_tread`,`m_keyword`,`m_enname`,`m_datetime`,`m_director`,`m_lang`,`m_score`,`m_recycle` FROM `".DB::table('data')."` WHERE `m_id`=$vId LIMIT 1");
	if (!is_array($row)) {
		echo "<font color='red'>影片ID:".$vId." 该影片所属分类被隐藏，跳过生成</font><br>";
		return false;
	}
	if ($row['m_recycle']==1) echo "<font color='red'>数据ID:".$vId." 该数据所属分类被隐藏，跳过生成</font><br>";
	$vType = $row['m_type'];$venname=$row['m_enname'];$vdatetime=$row['m_datetime'];
	$getTypeName = explode(",",getTypeNameTemplateArrayOnCache($vType));
	$contentPath = getContentLink($vType,$vId,$venname,$vdatetime,"");$contentLink=getContentLink($vType,$vId,$venname,$vdatetime,"link");
	$typeText = getTypeTextOnCache($vType);
	djcms::$currentTypeId=$vType;
	if (ismakeplay == 0) $playn = 1;
	for ($n = $playn;$n <= 1;$n++) {
		switch ($n) {
			case 0:
				$typeFlag = "parse_play_";
				$templatePath = DJCMS_TEMPLATE.$playTemFileName;
			break;
			case 1:
				$typeFlag = "parse_content_";
				if (empty($getTypeName[4])) $templatePath = DJCMS_TEMPLATE."content.html"; else $templatePath = DJCMS_TEMPLATE.$getTypeName[4];
			break;
		}
		$cacheName = $typeFlag.$vType;
		if (cacheStart==1) {
			if (djcms::$content = memory('get', $cacheName)) {
            } else {
                parseCachePart($typeFlag,$templatePath);
                memory('set', $cacheName, djcms::$content);
            }
		} else {
			parseCachePart($typeFlag,$templatePath);
		}
		djcms::parsePlayList($vType,$vId,$venname,$vdatetime,$row['m_playdata'],"play");
	    djcms::parsePlayList($vType,$vId,$venname,$vdatetime,$row['m_downdata'],"down");
		djcms::parseVideo($row);
		$content = replaceStr(djcms::$content,"{playpage:id}",$row['m_id']);
		$content = replaceStr($content,"{playpage:desktopurl}","/".sitePath."desktop.php?name={playpage:encodename}&url=".urlencode($contentLink));
		$content = replaceStr($content,"{playpage:encodename}",urlencode($row['m_name']));
		$content = replaceStr($content,"{playpage:lang}",$row['m_lang']);
		$content = replaceStr($content,"{playpage:diggnum}",$row['m_digg']);
		$content = replaceStr($content,"{playpage:treadnum}",$row['m_tread']);
		$content = replaceStr($content,"{playpage:scorenum}",$row['m_score']);
		$content = replaceStr($content,"{playpage:nolinkkeywords}",$row['m_keyword']);
		if (isExistStr($content,"{playpage:keywords}")) $content = replaceStr($content,"{playpage:keywords}",getKeywordsList($row['m_keyword'],"&nbsp;&nbsp;"));
		if (!empty($row['m_pic'])) {
		    if (strpos(' '.$row['m_pic'], 'http://') > 0) {
		        $content = replaceStr($content,"{playpage:pic}",$row['m_pic']);
		    } else {
		        $content = replaceStr($content,"{playpage:pic}","/".sitePath.$row['m_pic']);
		    }
	    } else {
		    $content = replaceStr($content,"{playpage:pic}","/".sitePath."pic/nopic.gif");
	    }
		$m_director=$row['m_director'];
		$content = replaceStr($content,"{playpage:director}",getKeywordsList($m_director,"&nbsp;&nbsp;"));
		$content = replaceStr($content,"{playpage:nolinkdirector}",$m_director);
		$content = replaceStr($content,"{playpage:publishtime}",$row['m_publishyear']);
		$content = replaceStr($content,"{playpage:publisharea}",$row['m_publisharea']);
		$content = replaceStr($content,"{playpage:state}",$row['m_state']);
		$content = replaceStr($content,"{playpage:commend}",$row['m_commend']);
		$content = replaceStr($content,"{playpage:link}",$contentLink);
		djcms::$content = replaceStr($content,"{playpage:url}","http://".siteUrl.$contentLink);
		switch ($typeFlag) {
			case "parse_content_":
				djcms::paresPreNextVideo($vId, $typeFlag, $vType);
				djcms::$content = replaceStr(djcms::$content,"{playpage:textlink}",$typeText."&nbsp;&nbsp;&raquo;&nbsp;&nbsp;".$row['m_name']);
				djcms::parseIf();
				createTextFile(djcms::$content,$contentPath);echoEach($row['m_name'],1,$contentLink,"content");
			break;
			case "parse_play_":
				$playORdownData=replaceStr($row['m_playdata'],"播客CC","FLV高清");
				$x=PlayData2Json2($playORdownData);
				djcms::$content = replaceStr(djcms::$content,"{playpage:playurlinfo}","<script>var VideoListJson=".$x[0].",urlinfo='".getPlayLink2($vType,$vId,$venname,$vdatetime,"<from>","<pos>")."';</script>");
				djcms::paresPreNextVideo($vId, $typeFlag, $vType);
				djcms::$content = replaceStr(djcms::$content,"{playpage:textlink}",$typeText."&nbsp;&nbsp;&raquo;&nbsp;&nbsp;<a href='".$contentLink."'>".$row['m_name']."</a>");
				djcms::$content = replaceStr(djcms::$content,"{playpage:player}","<iframe border=\"0\" src=\"/".sitePath."js/play.html\" marginWidth=\"0\" frameSpacing=\"0\" marginHeight=\"0\" frameBorder=\"0\" noResize scrolling=\"no\" width=\"100%\" height=\"488\" vspale=\"0\" style=\"z-index:9998;\"></iframe>");
				djcms::parseIf();
				makePlayByData($vType,$vId,$venname,$vdatetime,$x);
		}
	}
}

function makePlayByData($vType,$vId,$venname,$vdatetime,$PlayAry){
	$x=$PlayAry;
	if (ismakeplay==2){
		if ($x[1]>-1){
			$temp="$"."ary=array();";
			if (paramset==0){
				$temp .= "$"."x=explode(\"-\",$"."_SERVER['QUERY_STRING']);";
			} else {
				$temp .= "$"."x[0]=paramid;$"."x[1]=parampage;$"."x[2]=paramindex;";
			}
			for ($i = 0;$i <= $x[1];$i++) {
				$temp .= "$"."ary[".$i."]='".join($x[2][$i],"$")."';";
		    }
			$temp .= " $"."parte=explode(\"$\",$"."ary[$"."x[1]]);";
			$temp .= " $"."partname=$"."parte[$"."x[2]];";
			$temp="<"."?php \n".$temp."\n ?".">".replaceStr(djcms::$content,"{playpage:part}","<"."?=$"."partname?".">");
			$playLink = getPlayLink($vType,$vId,$venname,$vdatetime);
			createTextFile($temp,$playLink);
		}
	} else if (ismakeplay==3){
		for ($i = 0;$i <= $x[1];$i++) {
			$y=$x[2][$i];
			$yLen=count($y);
			for ($j = 0;$j < $yLen;$j++) {
				$temp=replaceStr(djcms::$content,"{playpage:part}",$y[$j]);
				$playLink = getPlayLink2($vType,$vId,$venname,$vdatetime,$i,$j);
				createTextFile($temp,$playLink);echoEach(" ".$y[$j]." ",$i,$playLink,"play");
			}
		}
	} else {
		$playLink = getPlayLink($vType,$vId,$venname,$vdatetime);
		$temp=replaceStr(djcms::$content,"{playpage:part}","");
		createTextFile($temp,$playLink);
	}
}

function makeArticleById($vId){
	global $currentId,$currentEnname,$currentDatetime;
	$row = DB::fetch_first("SELECT m_id,m_title,m_type,m_vid,m_pic,m_hit,m_author,m_content,m_topic,m_color,m_addtime,m_from,m_outline,m_commend,m_letter,m_keyword,m_digg,m_tread,m_entitle,m_datetime,m_note,m_score FROM ".DB::table('news')." WHERE m_id=$vId AND m_recycle=0 LIMIT 1");
	if (!is_array($row)) {
		echo "<font color='red'>该新闻被删除或隐藏</font><br>";
		return false;
	}
	$vType = $row['m_type'];$venname = $row['m_entitle'];$vdatetime = $row['m_datetime'];
	$typename = explode(",", getNewsTypeNameTemplateArrayOnCache(intval($vType)));
	if (empty($typename[4])) $contentTemplatePath = DJCMS_TEMPLATE."news.html"; else $contentTemplatePath = DJCMS_TEMPLATE.$typename[4];
	if (strpos(" ,".getHideNewsTypeIDS().",",",".$vType.",") > 0) exit("<font color='red'>数据ID:".$vId." 该数据所属分类被隐藏，跳过生成</font><br>");
	$contentPath = getNewsArticleLink($vType,$vId,$venname,$vdatetime,"");$contentLink = getNewsArticleLink($vType,$vId,$venname,$vdatetime,"link");
	$typeText = getNewsTypeTextOnCache($vType);
	$currentId=$vId;djcms::$currentTypeId=$vType;$currentEnname=$venname;$currentDatetime=$vdatetime;$typeFlag = "parse_article_";$cacheName = $typeFlag.$vType;
	if (cacheStart == 1) {
		if (!djcms::$content = memory('get', $cacheName)) {
            parseCachePart($typeFlag,$contentTemplatePath);
            memory('set', $cacheName, djcms::$content);
        }
	} else {
		 parseCachePart($typeFlag,$contentTemplatePath);
	}
	djcms::paresPreNextNews($vId,$vType);
	djcms::parseNews($row);
	$content = replaceStr(djcms::$content,"{news:id}",$row['m_id']);
	$content = replaceStr($content,"{news:encodetitle}",urlencode($row['m_id']));
	$content = replaceStr($content,"{news:note}",parseNewsNote($row['m_note']));
	$content = replaceStr($content,"{news:nolinkkeywords}",$row['m_keyword']);
	if (isExistStr($content,"{news:keywords}")) $content = replaceStr($content,"{news:keywords}",getKeywordsList($row['m_keyword'],"&nbsp;&nbsp;"));
	if (!empty($row['m_pic'])) {
		if (strpos(' '.$row['m_pic'], 'http://') > 0) {
		    $content = replaceStr($content,"{news:pic}",$row['m_pic']);
		} else {
		    $content = replaceStr($content,"{news:pic}","/".sitePath.$row['m_pic']);
		}
	} else {
		$content = replaceStr($content,"{news:pic}","/".sitePath."pic/nopic.gif");
	}
	$content = replaceStr($content,"{news:author}",$row['m_author']);
	$content = replaceStr($content,"{news:from}",$row['m_from']);
	$content = replaceStr($content,"{news:diggnum}",$row['m_digg']);
	$content = replaceStr($content,"{news:treadnum}",$row['m_tread']);
	$content = replaceStr($content,"{news:commend}",$row['m_commend']);
	$content = replaceStr($content,"{news:scorenum}",$row['m_score']);
	$content = replaceStr($content,"{news:link}",$contentLink);
	$content = replaceStr($content,"{news:url}","http://".siteUrl.$contentLink);
	djcms::$content = replaceStr($content,"{news:textlink}",$typeText."&nbsp;&nbsp;&raquo;&nbsp;&nbsp;".$row['m_title']);
	djcms::parseIf();
	if (isExistStr(djcms::$content,"{news:subcontent}") || isExistStr(djcms::$content,"{news:subtitle}") || isExistStr(djcms::$content,"{news:subpagenumber")){
		$x = split("#p#", $row['m_content']);$l=count($x);
		for ($i=0; $i < $l; $i++) {
			$tmp=djcms::$content;
			if (!isExistStr($x[$i],"#e#")) $x[$i]="  #e#".$x[$i];
			$y=split("#e#",$x[$i]);
			$tmp = replaceStr($tmp,"{news:subtitle}",$y[0]);
			$tmp = replaceStr($tmp,"{news:subcontent}",$y[1]);
			$contentPath=formatArticleLink($vType,$vId,$venname,$vdatetime,"",$i+1);$contentLink=formatArticleLink($vType,$vId,$venname,$vdatetime,"link",$i+1);
			echoEach($row['m_title']."  ".$y[0],$i,$contentLink,"news");
			$z=StrSlice($tmp,"{news:subpagenumber","}");
			$slidewarr = djcms::parseAttr($z);
			$y = $slidewarr['len'];if (empty($y)){ $y=10; }else{ $y=$y;}
			if ($l>0){
				$y=pageNumberLinkInfo($i+1,$y,$l,"newssubpage",$l+1);
			}else{
				$y="";
			}
			$tmp = replaceStr($tmp,"{news:subpagenumber".$z."}",$y);
			createTextFile($tmp,$contentPath);
		}
	}else{
		createTextFile(djcms::$content,$contentPath);echoEach($row['m_title'],1,$contentLink,"news");
	}
}

function makeChannelByIDS() {
	$curTypeIndex = getForm("index","get");$action3 = getForm("action3","get");$ids = trim(getForm("ids","get"));
	$typeIdArray = explode(",",$ids);
	$typeIdArrayLen = count($typeIdArray);
	if (empty($curTypeIndex)) {
		$curTypeIndex=0;
	} else { 
		if (intval($curTypeIndex) > intval($typeIdArrayLen-1)) {
			if (empty($action3)) {
				alertMsg("生成所有栏目全部搞定","");exit;
			} else if ($action3 == 'site') {
				makeIndex() ; makeAllmovie() ; alertMsg("一键生成全部搞定","");exit;
			}
		}
	}
	$typeId = $typeIdArray[$curTypeIndex];
   	if (empty($typeId)) die("分类丢失"); else makeChannelById($typeId, $curTypeIndex) ;
}

function makeNewsPartByIDS() {
	$curTypeIndex = getForm("index","get");$action3 = getForm("action3","get");$ids = trim(getForm("ids","get"));
	$typeIdArray = explode(",",$ids);
	$typeIdArrayLen = count($typeIdArray);
	if (empty($curTypeIndex)) {
		$curTypeIndex=0;
	} else { 
		if (intval($curTypeIndex) > intval($typeIdArrayLen-1)) {
			if (empty($action3)) {
				alertMsg("生成所有栏目全部搞定","");exit;
			} else if ($action3 == 'newssite') {
				makeNewsIndex() ; makeAllnews() ; alertMsg("一键生成全部搞定","");exit;
			}
		}
	}
	$typeId = $typeIdArray[$curTypeIndex];
   	if (empty($typeId)) die("分类丢失"); else makeNewsPartById($typeId, $curTypeIndex) ;
}

function makeAllChannel() {
	$curTypeIndex=getForm("index","get");$action3=getForm("action3","get");
	$typeIdArray = getTypeIdArrayBySortOnCache(0);
	$typeIdArrayLen = count($typeIdArray);
	if (empty($curTypeIndex)) {
		$curTypeIndex = 0;
	} else { 
		if (intval($curTypeIndex) > intval($typeIdArrayLen-1)) {
			if (empty($action3)) {
				alertMsg("生成所有栏目全部搞定","") ; exit();
			} else if ($action3 == 'site') {
				makeIndex() ; makeAllmovie() ; alertMsg("一键生成全部搞定","") ; exit;
			}
		}
	}
	$typeId = $typeIdArray[$curTypeIndex];
   	if (empty($typeId)) die("分类丢失"); else makeChannelById($typeId, $curTypeIndex);
}

function makeAllNewsPart() {
	$curTypeIndex=getForm("index","get");$action3=getForm("action3","get");
	$typeIdArray = getNewsTypeIdArrayBySortOnCache(0);
	$typeIdArrayLen = count($typeIdArray);
	if (empty($curTypeIndex)) {
		$curTypeIndex = 0;
	} else { 
		if (intval($curTypeIndex) > intval($typeIdArrayLen-1)) {
			if (empty($action3)) {
				alertMsg("生成所有栏目全部搞定","") ; exit();
			} else if ($action3 == 'newssite') {
				makeNewsIndex() ; makeAllnews() ; alertMsg("一键生成全部搞定","") ; exit;
			}
		}
	}
	$typeId = $typeIdArray[$curTypeIndex];
   	if (empty($typeId)) die("分类丢失"); else makeNewsPartById($typeId, $curTypeIndex);
}

function getTopicIdArrayBySortOnCache() {
	$cacheName="topicidarraybysort";
	if (cacheStart == 1) {
		if ($x = memory('get', $cacheName)) {
        } else {
            $x = explode(",",handleArrayIdStr(getTopicId()));
			memory('set', $cacheName, $x);
        }
    } else {
		$x = explode(",",handleArrayIdStr(getTopicId()));
    }
	return $x;
}

function getTypeIdArrayBySortOnCache($topId) {
	$cacheName="typeidarraybysort".$topId;
	if (cacheStart == 1) {
		if ($typeIdArray = memory('get', $cacheName)) {
        } else {
            $typeIdArray = explode(",",handleArrayIdStr(getTypeId($topId)));
            memory('set', $cacheName, $typeIdArray);
        }
    } else {
		$typeIdArray = explode(",",handleArrayIdStr(getTypeId($topId)));
    }
	return $typeIdArray;
}

function getNewsTypeIdArrayBySortOnCache($topId) {
	$cacheName="newstypeidarraybysort".$topId;
	if (cacheStart == 1) {
		if ($typeIdArray = memory('get', $cacheName)) {
        } else {
            $typeIdArray = explode(",",handleArrayIdStr(getNewsTypeId($topId)));
			memory('set', $cacheName, $typeIdArray);
        }
    } else {
		$typeIdArray = explode(",",handleArrayIdStr(getNewsTypeId($topId)));
    }
	return $typeIdArray;
}

function handleArrayIdStr($str) {
	if (substr($str, 0, 2) == "0,") return substr($str,2,(strlen($str)-2)); else return $str;
}

function makeChannel() {
	$channel = getForm("channel","both");$curTypeIndex=getForm("index","get");if (empty($channel)) die("请选择分类");
	if (is_numeric($curTypeIndex)) $curTypeIndex = intval($curTypeIndex); else $curTypeIndex = 0;
	makeChannelById($channel, $curTypeIndex);
}

function makeNewsPart() {
	$channel = getForm("channel","both");$curTypeIndex=getForm("index","get");if (empty($channel)) die("请选择分类");
	if (is_numeric($curTypeIndex)) $curTypeIndex = intval($curTypeIndex); else $curTypeIndex = 0;
	makeNewsPartById($channel, $curTypeIndex);
}

function makeLengthchannel() {
	$channel = getForm("channel","both");if (empty($channel)) die("请选择分类");
	$startPage = getForm("startpage","both");
	if (empty($startPage)) {
		die("请填写起始页");
	} else if(!is_numeric($startPage)) {
		die("请正确填写起始页");
	}
	$endPage = getForm("endpage","both");
	if (empty($endPage)) {
		die("请填写结束页");
	} else if(!is_numeric($endPage)) {
		die("请正确填写结束页");
	}
	$startPage = intval($startPage);$endPage = intval($endPage);
	if ($startPage <= 0) die("您输入的页数小于0");
	if ($startPage > $endPage) die("您输入的结束页小于开始页");
	makeLengthChannelById($channel, $startPage, $endPage);
}

function makenewslengthchannel() {
	$channel = getForm("channel","both");if (empty($channel)) die("请选择分类");
	$startpage = getForm("startpage","both");
	if (empty($channel)) die("请选择分类");
	if (empty($startpage)) {
		die("请填写起始页");
	} else if(!is_numeric($startpage)) {
		die("请正确填写起始页");
	}
	$endpage = getForm("endpage","both");
	if (empty($endpage)) {
		die("请填写结束页");
	} else if(!is_numeric($endpage)) {
		die("请正确填写结束页");
	}
	$startpage = intval($startpage);$endpage = intval($endpage);
	if ($startpage <= 0) die("您输入的页数小于0");
	if ($startpage > $endpage) die("您输入的结束页小于开始页");
	makeLengthPartById($channel, $startpage, $endpage);
}

function makeChannelById($typeId, $curTypeIndex){
	global $action,$action3,$ids;
	$currentPage= getForm("page","get");if (is_numeric($currentPage)) $currentPage = intval($currentPage); else $currentPage = 1;
	$nameAndTemplateArray = explode(",",getTypeNameTemplateArrayOnCache(intval($typeId)));
	if (empty($nameAndTemplateArray[1])) $channelTmpName = "channel.html"; else $channelTmpName = $nameAndTemplateArray[1];
	$channelTemplatePath = DJCMS_TEMPLATE.$channelTmpName;
	$pSize = getPageSizeOnCache($channelTemplatePath, "channel", $channelTmpName);if (empty($pSize)) $pSize=12;
	$typeIds = getTypeIdOnCache($typeId);
	echoBegin($nameAndTemplateArray[0], "channel");
	$r = DB::fetch_first("SELECT count(*) as number FROM ".DB::table('data')." WHERE m_type IN ($typeIds)");
    $TotalResult = $r['number'];
	djcms::$currentTypeId = $typeId;$cacheName = "parse_channel_".$typeId;
	if (cacheStart == 1) {
		if (!djcms::$content = memory('get', $cacheName)) {
            parseCachePart("channel", $channelTemplatePath);
            memory('set', $cacheName, djcms::$content);
        }
	} else {
		parseCachePart("channel", $channelTemplatePath);
	}
	$tempStr = djcms::$content;$pCount = ceil($TotalResult/$pSize);
	if (isTypeHide($typeId)) {
		echo "分类<font color=red >".$typename."</font>为隐藏状态、跳过生成";
		return true;
	}
	if ($TotalResult == 0) {
		djcms::$content = replaceStr($tempStr, "{channelpage:page}", 1);
		djcms::ParsePageList($typeIds, 1, "channel");
		djcms::parseIf();
		$channelLink = getChannelPagesLink($typeId, 1);
		createTextFile(djcms::$content, $channelLink);
		echoEach($nameAndTemplateArray[0], 1, $channelLink, "channel");
	}
	if (strpos($tempStr,"{/djcms:channellist}")==0) $pCount=1;
	if ($currentPage<1) $currentPage=1;
	$nCount = 200 + $currentPage - 1;if ($pCount < $nCount){ $nCount = $pCount;}
	for ($i = $currentPage;$i <= $nCount;$i++) {
		$channelLink = getChannelPagesLink($typeId, $i);
		djcms::$content = replaceStr($tempStr, "{channelpage:page}", $i);
		djcms::ParsePageList($typeIds, $i, "channel");
		djcms::parseIf();
		createTextFile(djcms::$content, $channelLink);
		echoEach($nameAndTemplateArray[0], $i, $channelLink, "channel");
	}
	$currentPage = $i;
	if ($i >= $pCount) {
		$curTypeIndex = $curTypeIndex + 1;$currentPage = 1;
	}
	if ($action == "channel") {
	    if ($curTypeIndex < 1) {
		    echoChannelSuspend3($typeId, $curTypeIndex, $currentPage,makeTimeSpan);
		}
	} else if ($action == "channelbyids"){
		echoChannelSuspend2($ids, $curTypeIndex, $action3, $currentPage,makeTimeSpan);
	} else {
		echoChannelSuspend($curTypeIndex, $action3, $currentPage,makeTimeSpan);
	}
}

function makeNewsPartById($typeId, $curTypeIndex){
	global $action,$action3,$ids;
	$currentPage= getForm("page","get");if (is_numeric($currentPage)) $currentPage = intval($currentPage); else $currentPage = 1;
	$nameAndTemplateArray = explode(",",getNewsTypeNameTemplateArrayOnCache(intval($typeId)));
	if (empty($nameAndTemplateArray[1])) $channelTmpName = "newspage.html"; else $channelTmpName = $nameAndTemplateArray[1];
	$channelTemplatePath = DJCMS_TEMPLATE.$channelTmpName;
	$pSize = getPageSizeOnCache($channelTemplatePath, "newspage", $channelTmpName);if (empty($pSize)) $pSize=12;
	$typeIds = getNewsTypeIdOnCache($typeId);
	echoBegin($nameAndTemplateArray[0], "newspage");
	$r = DB::fetch_first("SELECT count(*) as number FROM ".DB::table('news')." WHERE m_type IN ($typeIds)");
    $TotalResult = $r['number'];
	djcms::$currentTypeId = $typeId;$cacheName = "parse_npl_".$typeId;
	if (cacheStart == 1) {
		if (!djcms::$content = memory('get', $cacheName)) {
            parseCachePart("newspage", $channelTemplatePath);
            memory('set', $cacheName, djcms::$content);
        }
	} else {
		parseCachePart("newspage", $channelTemplatePath);
	}
	$tempStr = djcms::$content;$pCount = ceil($TotalResult/$pSize);
	if (isTypeHide($typeId)) {
		echo "分类<font color=red >".$typename."</font>为隐藏状态、跳过生成";
		return true;
	}
	if ($TotalResult == 0) {
		djcms::$content = replaceStr($tempStr, "{newspagelist:page}", 1);
		djcms::parseNewsPartList($typeIds, 1, "newspage");
		djcms::parseIf();
		$channelLink = getNewsPartLink($typeId, 1);
		createTextFile(djcms::$content, $channelLink);
		echoEach($nameAndTemplateArray[0], 1, $channelLink, "newspage");
	}
	if (strpos($tempStr,"{/djcms:newspagelist}")==0) $pCount=1;
	if ($currentPage<1) $currentPage=1;
	$nCount = 200 + $currentPage - 1;if ($pCount < $nCount){ $nCount = $pCount;}
	for ($i = $currentPage;$i <= $nCount;$i++) {
		$channelLink = getNewsPartLink($typeId, $i);
		djcms::$content = replaceStr($tempStr, "{newspagelist:page}", $i);
		djcms::parseNewsPartList($typeIds, $i, "newspage");
		djcms::parseIf();
		createTextFile(djcms::$content, $channelLink);
		echoEach($nameAndTemplateArray[0], $i, $channelLink, "newspage");
	}
	$currentPage = $i;
	if ($i >= $pCount) {
		$curTypeIndex = $curTypeIndex + 1;$currentPage = 1;
	}
	if ($action == "newschannel") {
	    if ($curTypeIndex < 1) {
		    echoChannelSuspend3($typeId, $curTypeIndex, $currentPage,makeTimeSpan);
		}
	} else if ($action == "channelbyids"){
		echoChannelSuspend2($ids, $curTypeIndex, $action3, $currentPage,makeTimeSpan);
	} else {
		echoChannelSuspend($curTypeIndex, $action3, $currentPage,makeTimeSpan);
	}
}

function makeLengthChannelById($typeId, $startpage, $endpage) {
	$nameAndTemplateArray = explode(",",getTypeNameTemplateArrayOnCache(intval($typeId)));
	if (empty($nameAndTemplateArray[1])) $channelTmpName = "channel.html"; else $channelTmpName = $nameAndTemplateArray[1];
	$channelTemplatePath = DJCMS_TEMPLATE.$channelTmpName;
	$pSize = getPageSizeOnCache($channelTemplatePath, "channel", $channelTmpName);if (empty($pSize)) $pSize=12;
	$typeIds = getTypeIdOnCache($typeId);
	echoBegin($nameAndTemplateArray[0], "channel");
	$r = DB::fetch_first("SELECT count(*) as number FROM ".DB::table('data')." WHERE m_recycle=0 AND m_type IN ($typeIds)");
    $TotalResult = $r['number'];
	if ($TotalResult == 0) {
		echo "分类<font color=red >该目录无数据</font>";
		return true;
	}
	$pagesize = $pSize;djcms::$currentTypeId = $typeId;$pCount = ceil($TotalResult/$pSize);
	$cacheName = "parse_channel_".$typeId;
	if (cacheStart == 1) {
		if (!djcms::$content = memory('get', $cacheName)) {
            parseCachePart("channel",$channelTemplatePath);
			memory('set', $cacheName, djcms::$content);
        }
	} else {
		parseCachePart("channel",$channelTemplatePath);
	}
	$tempStr = djcms::$content;
	if (strpos($tempStr,"{/djcms:channellist}")==0) $pCount=1;
	for ($i = 1;$i <= $pCount;$i++) {
		if ($i>=$startpage && $i<=$endpage){
		    $channelLink = getChannelPagesLink($typeId, $i);
		    djcms::$content = replaceStr($tempStr, "{channelpage:page}", $i);
		    djcms::ParsePageList($typeIds, $i, "channel");
		    djcms::parseIf();
		    createTextFile(djcms::$content, $channelLink);
		    echoEach($nameAndTemplateArray[0], $i, $channelLink, "channel");
		}
	}
}

function makeLengthPartById($typeId, $startpage, $endpage) {
	$nameAndTemplateArray = explode(",",getTypeNameTemplateArrayOnCache(intval($typeId)));
	if (empty($nameAndTemplateArray[1])) $channelTmpName = "newspage.html"; else $channelTmpName = $nameAndTemplateArray[1];
	$channelTemplatePath = DJCMS_TEMPLATE.$channelTmpName;
	$pSize = getPageSizeOnCache($channelTemplatePath, "newspage", $channelTmpName);if (empty($pSize)) $pSize=12;
	$typeIds = getTypeIdOnCache($typeId);
	echoBegin($nameAndTemplateArray[0], "newspage");
	$r = DB::fetch_first("SELECT count(*) as number FROM ".DB::table('news')." WHERE m_recycle=0 AND m_type IN ($typeIds)");
    $TotalResult = $r['number'];
	if ($TotalResult == 0) {
		echo "分类<font color=red >该目录无数据</font>";
		return true;
	}
	$pagesize = $pSize;djcms::$currentTypeId = $typeId;$pCount = ceil($TotalResult/$pSize);
	$cacheName = "parse_channel_".$typeId;
	if (cacheStart == 1) {
		if (!djcms::$content = memory('get', $cacheName)) {
            parseCachePart("newspage",$channelTemplatePath);
            memory('set', $cacheName, djcms::$content);
        }
	} else {
		parseCachePart("newspage",$channelTemplatePath);
	}
	$tempStr = djcms::$content;
	if ($TotalResult == 0) {
		echo "分类<font color=red >该目录无数据</font>";
		return true;
	}
	if (strpos($tempStr,"{/djcms:newspagelist}")==0) $pCount=1;
	for ($i = 1;$i <= $pCount;$i++) {
		if ($i>=$startpage && $i<=$endpage){
		    $channelLink = getNewsPartLink($typeId, $i);
		    djcms::$content = replaceStr($tempStr, "{newspagelist:page}", $i);
		    djcms::ParsePageList($typeIds, $i, "newspage");
		    djcms::parseIf();
		    createTextFile(djcms::$content, $channelLink);
		    echoEach($nameAndTemplateArray[0], $i, $channelLink, "newspage");
		}
	}
}

function parseCachePart($pageType, $templatePath) {
	switch ($pageType) {
		case "channel":
			djcms::$content=loadFile($templatePath);
	        djcms::parseTopAndFoot();
	        djcms::parseSelf();
	        djcms::parseGlobal();
			$z = getTypeField(djcms::$currentTypeId,"m_name,m_keyword,m_description","");
			$content = replaceStr(replaceCurrentTypeId(djcms::$content),"{channelpage:typetext}",getTypeTextOnCache(djcms::$currentTypeId));
			$content = replaceStr(replaceStr($content,"{channelpage:keywords}",$z[1]),"{channelpage:description}",$z[2]);
			djcms::$content = replaceStr($content,"{channelpage:typename}",$z[0]);
	        djcms::parseMenuList("");
	        djcms::parseNewsList();
	        djcms::parseAreaList();
	        djcms::parseVideoList();
	        djcms::parseTopicList();
		break;
		case "parse_content_":
		    djcms::$content=loadFile($templatePath);
			djcms::parsePlayPageSpecial();
	        djcms::parseTopAndFoot();
	        djcms::parseSelf();
	        djcms::parseGlobal();
			$typename = explode(",", getTypeNameTemplateArrayOnCache(intval(djcms::$currentTypeId)));
			djcms::$content = replaceStr(replaceCurrentTypeId(djcms::$content),"{playpage:typeid}",djcms::$currentTypeId);
			if (isExistStr(djcms::$content,"{playpage:typename}")) djcms::$content=replaceStr(djcms::$content,"{playpage:typename}",$typename[0]);
			if (isExistStr(djcms::$content,"{playpage:typelink}")) djcms::$content = replaceStr(djcms::$content,"{playpage:typelink}",getTypeLink(djcms::$currentTypeId));
			if (isExistStr(djcms::$content,"{playpage:upid}")) djcms::$content = replaceStr(djcms::$content,"{playpage:upid}",getTypeUpid(djcms::$currentTypeId));
	        djcms::parseMenuList("");
	        djcms::parseNewsList();
	        djcms::parseAreaList();
	        djcms::parseVideoList();
	        djcms::parseTopicList();
		break;
		case "parse_play_":
		    djcms::$content=loadFile($templatePath);
			djcms::parsePlayPageSpecial();
	        djcms::parseTopAndFoot();
	        djcms::parseSelf();
	        djcms::parseGlobal();
			$typename = explode(",", getTypeNameTemplateArrayOnCache(intval(djcms::$currentTypeId)));
			djcms::$content = replaceStr(replaceCurrentTypeId(djcms::$content),"{playpage:typeid}",djcms::$currentTypeId);
			if (isExistStr(djcms::$content,"{playpage:typename}")) djcms::$content=replaceStr(djcms::$content,"{playpage:typename}",$typename[0]);
			if (isExistStr(djcms::$content,"{playpage:typelink}")) djcms::$content = replaceStr(djcms::$content,"{playpage:typelink}",getTypeLink(djcms::$currentTypeId));
			if (isExistStr(djcms::$content,"{playpage:upid}")) djcms::$content = replaceStr(djcms::$content,"{playpage:upid}",getTypeUpid(djcms::$currentTypeId));
	        djcms::parseMenuList("");
	        djcms::parseNewsList();
	        djcms::parseAreaList();
	        djcms::parseVideoList();
	        djcms::parseTopicList();
		break;
		case "topicindex":
			djcms::$content=loadFile($templatePath);
			djcms::parseTopAndFoot();
			djcms::parseSelf();
			djcms::parseGlobal();
			djcms::$content=replaceCurrentTypeId(djcms::$content);
			djcms::$content=replaceTopicId(djcms::$content);
			djcms::parseMenuList("");
			djcms::parseAreaList();
			djcms::parseTopicList();
			djcms::parseVideoList();
			djcms::parseNewsList();
		break;
		case "topicpage":
			djcms::$content=loadFile($templatePath);
			djcms::parseTopAndFoot();
			djcms::parseSelf();
			djcms::parseGlobal();
		    djcms::$content=replaceTopicId(replaceCurrentTypeId(djcms::$content));
			djcms::parseMenuList("");
			djcms::parseAreaList();
			djcms::parseTopicList();
			djcms::parseVideoList();
			djcms::parseNewsList();
			djcms::parseLinkList();
		break;
		case "newspage":
			djcms::$content=loadFile($templatePath);
			djcms::parseTopAndFoot();
			djcms::parseSelf();
			djcms::parseGlobal();
			$z = getTypeField(djcms::$currentTypeId,"m_name,m_keyword,m_description","news");
			$content = replaceStr(djcms::$content,"{newspagelist:typetext}", getNewsTypeTextOnCache(djcms::$currentTypeId));     
			$content = replaceStr(replaceStr($content,"{newspagelist:keywords}",$z[1]),"{newspagelist:description}",$z[2]);
			djcms::$content = replaceStr($content,"{newspagelist:typename}",$z[0]);
			djcms::parseMenuList("");
			djcms::parseAreaList();
			djcms::parseTopicList();
			djcms::parseVideoList();
			djcms::parseNewsList();
		break;
		case "parse_article_":
			djcms::$content=loadFile($templatePath);
			djcms::parseNewsPageSpecial();
			djcms::parseTopAndFoot();
	        djcms::parseSelf();
	        djcms::parseGlobal();
			$typename = explode(",", getNewsTypeNameTemplateArrayOnCache(djcms::$currentTypeId));
			djcms::$content = replaceStr(djcms::$content,"{news:typeid}",djcms::$currentTypeId);
			djcms::$content = replaceStr(djcms::$content,"{djcms:currenttypeid}", djcms::$currentTypeId);
			if (isExistStr(djcms::$content,"{news:upid}")) djcms::$content = replaceStr(djcms::$content,"{news:upid}",getNewsTypeUpid(djcms::$currentTypeId));
			if (isExistStr(djcms::$content,"{news:typename}")) djcms::$content = replaceStr(djcms::$content,"{news:typename}",$typename[0]);
	        djcms::parseMenuList("");
	        djcms::parseNewsList();
	        djcms::parseAreaList();
	        djcms::parseVideoList();
	        djcms::parseTopicList();
		break;
		case "customvideo":
			djcms::$content=loadFile($templatePath);
			djcms::parseTopAndFoot();
	        djcms::parseSelf();
	        djcms::parseGlobal();
			djcms::$content=replaceStr(djcms::$content,"{djcms:runinfo}","");
			djcms::$content=replaceCurrentTypeId(djcms::$content);
			djcms::$content=replaceTopicId(djcms::$content);
	        djcms::parseMenuList("");
	        djcms::parseNewsList();
	        djcms::parseAreaList();
	        djcms::parseVideoList();
	        djcms::parseTopicList();
		break;
	}
}

function echoEach($str,$cur,$link,$pType){
	switch ($pType) {
		case "channel":case "newspage":
			echo " 成功生成栏目<font color='red'>".$str."</font>的第<font color='red'>".$cur."</font>页列表：<a href='".$link."' target='_blank'><font color='red'>".$link."</font></a><br>";
		break;
		case "content":
			echo " 成功生成<font color='red'>".$str."</font>的地址：<a href='".$link."' target='_blank'><font color='red'>".$link."</font></a><br>";
		break;
		case "play":
			echo " &nbsp;&nbsp;成功生成<font color='blue'>".$str."</font>播放地址：<a href='".$link."' target='_blank'><font color='blue'>".$link."</font></a><br>";
		break;
		case "news":
			echo " 成功生成新闻<font color='red'>".$str."</font>的地址：<a href='".$link."' target='_blank'><font color='red'>".$link."</font></a><br>";
		break;
		case "topicindex":
			echo " 成功生成主题列表<font color='red'>".$str."</font>的地址：<a href='".$link."' target='_blank'><font color='red'>".$link."</font></a><br>";
		break;
		case "topicpage":
			echo " 成功生成主题内页<font color='red'>".$str."</font>的地址：<a href='".$link."' target='_blank'><font color='red'>".$link."</font></a><br>";
		break;
	}
}

function echoBegin($str, $pType) {
	switch ($pType) {
		case "channel":case "newspage":
			echo "正在开始生成栏目<font color='red'>".$str."</font>的列表<br>";
		break;
		case "content":
			echo $str;
		break;
		case "topicindex":
			echo "正在开始生成专题主列表<br>"; 
		break;
		case "topicpage":
			echo "正在开始生成专题<font color='red'>".$str."</font>的列表<br>";
		break;
	}
}

function echoChannelSuspend($index,$action3,$currentPage,$sleep){
	global $action,$action3;
	echo "<br>暂停".$sleep."秒后继续生成<script language=\"javascript\">setTimeout(\"makeNextChannel();\",".$sleep."000);function makeNextChannel(){location.href='?action=".$action."&index=".$index."&action3=".$action3."&page=".$currentPage."';}</script>";
}

function echoChannelSuspend2($ids,$typeIdIndex,$action3,$currentPage,$sleep){
    global $action,$action3;
	echo "<br>暂停".$sleep."秒后继续生成<script language=\"javascript\">setTimeout(\"makeNextChannel();\",".$sleep."000);function makeNextChannel(){location.href='?action=".$action."&ids=".$ids."&index=".$typeIdIndex."&action3=".$action3."&page=".$currentPage."';}</script>";
}

function echoChannelSuspend3($channel,$typeIdIndex,$currentPage,$sleep){
	global $action;
	echo "<br>暂停".$sleep."秒后继续生成<script language=\"javascript\">setTimeout(\"makeNextChannel();\",".$sleep."000);function makeNextChannel(){location.href='?action=".$action."&channel=".$channel."&index=".$typeIdIndex."&page=".$currentPage."';}</script>";
}

function makeBaidu() {
	global $flag,$makenum,$allmakenum;
	if ($flag != 1) {
		echo "<br><div align=center><b>生成baidu地图</b>： 总输出数量<input type='text' id='allmakenum' value='500'>每页数量<input type='text' id='makenum' value='100'> <input type='button' class='btn' value='开始生成' onclick=\"javascript:location.href='?action=baidu&flag=1&allmakenum='+$('allmakenum').value+'&makenum='+$('makenum').value\" /></div>";
	} else {
		$makenum = empty($makenum) ? 100 : intval($makenum);
		$allmakenum = getForm("allmakenum","get");$allmakenum = empty($allmakenum) ? 500 : intval($allmakenum);
		$pagesize = $makenum;
		$pCount = ceil($allmakenum / $pagesize);
		$allcount = getDataCount("all");
		$allpage = ceil($allcount / $pagesize);
		if ($pCount > $allpage) $pCount = $allpage;
		for ($i = 1;$i <= $pCount;$i++) {
			$limitstart = ($i-1) * $pagesize;
			$sql = "SELECT m_id,m_name,m_pic,m_actor,m_des,m_addtime,m_type,m_enname,m_datetime FROM ".DB::table('data')." WHERE m_recycle=0 ORDER BY m_addtime DESC LIMIT $limitstart,$pagesize";
			$baiduStr =  "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n
							<document>\n
							<webSite>http://".siteUrl."</webSite>\n
							<webMaster>".siteName."</webMaster>\n
							<updatePeri>1800</updatePeri>\n";
			$query = DB::query($sql);
            while($row = DB::fetch($query)) {
				$vDes = $row['m_des'] ; if (empty($vDes)) $vDes = "";
				$vName = $row['m_name'] ; if (empty($vName)) $vName = "";
				$baiduStr .= "<item>\n
									  <title>".htmlspecialchars($vName)."</title>\n
									  <link>http://".siteUrl.getContentLink($row['m_type'],$row['m_id'],$row['m_enname'],$row['m_datetime'],"link")."</link>\n
									  <text>".htmlspecialchars(msubstr($vDes,300))."</text>\n";
				if(strpos(' '.$row['m_pic'],'http://') > 0) {
					$baiduStr .= "<image>".$row['m_pic']."</image>\n";
				} else {
					$baiduStr .= "<image>http://".siteUrl."/".sitePath.$row['m_pic']."</image>\n";
				}
				$baiduStr .= "<keywords>".$vName.",".$row['m_actor']."</keywords>\n
									  <author>".siteName."</author>\n
									  <source>".siteName."</source>\n
									  <pubDate>".date('Y-m-d H:i:s',$row['m_addtime'])."</pubDate>\n
									  </item>\n";
			}
			$baiduStr .= "</document>\n";
			$baiduStr = gb2utf8($baiduStr);
			if ($i == 1) $xmlUrl = ""; else $xmlUrl = "_".$i;
			createTextFile($baiduStr, "/baidu".$xmlUrl.".xml");
			echo "http://".siteUrl."/".sitePath."baidu".$xmlUrl.".xml"." 生成完毕 <a target='_blank' href='../baidu".$xmlUrl.".xml'><font color=red>浏览</font></a><br>";
			if($i == $pCount) {
				echo "生成完毕";
				exit("请通过<a href='http://news.baidu.com/newsop.html' target='_blank'>http://news.baidu.com/newsop.html</a>提交!");
			}
		}
	}
}

function makeGoogle() {
	global $flag,$makenum,$allmakenum;
	if ($flag != 1) {
		echo "<br><div align=center><b>生成google地图</b>： 总输出数量<input type='text' id='allmakenum' value='500'>每页数量<input type='text' id='makenum' value='100'> <input type='button' class='btn' value='开始生成' onclick=\"javascript:location.href='?action=google&flag=1&allmakenum='+$('allmakenum').value+'&makenum='+$('makenum').value\" /></div>";
	} else {
		$makenum = empty($makenum) ? 100 : intval($makenum);
		$allmakenum = getForm("allmakenum","get");$allmakenum = empty($allmakenum) ? 500 : intval($allmakenum);
		$pagesize = $makenum;
		$pCount = ceil($allmakenum / $pagesize);
		$allcount = getDataCount("all");
		$allpage = ceil($allcount / $pagesize);
		if ($pCount > $allpage) $pCount = $allpage;
		for ($i = 1;$i <= $pCount;$i++) {
			$limitstart = ($i-1) * $pagesize;
			$sql="SELECT m_id,m_name,m_pic,m_actor,m_des,m_addtime,m_type,m_enname,m_datetime FROM ".DB::table('data')." WHERE m_recycle=0 ORDER BY m_addtime DESC LIMIT $limitstart, $pagesize";
			$googleStr =  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n
							<urlset xmlns=\"http://www.google.com/schemas/sitemap/0.84\">\n
							<url>\n
							<loc>http://".siteUrl."</loc>\n
							</url>\n";
			$query = DB::query($sql);
            while($row = DB::fetch($query)) {
				$vDes = $row['m_des']; if(empty($vDes)) $vDes = "";
				$vName = $row['m_name']; if(empty($vName)) $vName = "";
				$googleStr .= "<url>\n
										  <loc>http://".siteUrl.getContentLink($row['m_type'],$row['m_id'],$row['m_enname'],$row['m_datetime'],"link")."</loc>\n
										  <lastmod>".date('Y-m-d H:i:s',$row['m_addtime'])."</lastmod>\n
										  </url>\n";
			}
			$googleStr .= "</urlset>\n";
			$googleStr = gb2utf8($googleStr);
			if ($i==1) $xmlUrl = ""; else $xmlUrl = "_".$i;
			createTextFile($googleStr, "/google".$xmlUrl.".xml");
			echo "http://".siteUrl."/".sitePath."google".$xmlUrl.".xml"." 生成完毕 <a target='_blank' href='../google".$xmlUrl.".xml'><font color=red>浏览</font></a><br>";
			if($i == $pCount) {
				echo "生成完毕";
				exit("请通过<a href='http://www.google.com/webmasters/tools/' target='_blank'>http://www.google.com/webmasters/tools/</a>提交!");
			}
		}
	}
}

function makeDaysview() {
	$days = getForm("days","both");$page=getForm("page","both");
	$number = 100;
	$ntime = gmmktime(0, 0, 0, gmdate('m'), gmdate('d'), gmdate('Y'));
	$limitday = $ntime - ($days * 24 * 3600);
	$sqlStr="SELECT m_id FROM ".DB::table('data')." WHERE m_addtime>".$limitday;
	$rCount = db::getCount($sqlStr);
	$pagecount = ceil($rCount / $number);
	if (empty($page)) $page=1; else $page=intval($page);
	if ($page > $pagecount) $page = $pagecount;
	if ($rCount==0) die("当天没有视频<br>");
	echoBegin("正在开始生成当天数据,当前是生成<font color='red'>".$page."</font> 页 共<font color='red'>".$pagecount."</font>页,共<font color='red'>".$rCount."</font>条<br>","content");
	$page = max(intval($page), 1);
    $offset = $number*($page-1);
	$query = DB::query("$sqlStr LIMIT $offset, $number");
    while($row = DB::fetch($query)) {
		makeContentById($row['m_id']);
	}
	if($page >= $pagecount) {
		die("生成最近".$days."天搞定");
    }
	echoDaySuspend($page+1,$days,makeTimeSpan);
}

function makenewsDaysview() {
	$days = getForm("days","both");
	$ntime = gmmktime(0, 0, 0, gmdate('m'), gmdate('d'), gmdate('Y'));
	$limitday = $ntime - ($days * 24 * 3600);
    $query = DB::query("SELECT m_id FROM ".DB::table('news')." WHERE m_addtime>".$limitday);
    while($row = DB::fetch($query)) {
		makeArticleById($row['m_id']);
	}
	unset($row);
}

function makeRss() {
	global $flag,$makenum,$allmakenum;
	if ($flag != 1) {
		echo "<br><div align=center><b>生成RSS地图</b>： 输出数量<input type='text' id='makenum' value='100'> <input type='button' class='btn' value='开始生成' onclick=\"javascript:location.href='?action=rss&flag=1&makenum='+$('makenum').value\" /></div>";
	} else {
		$makenum = empty($makenum) ? 100 : intval($makenum);
			$sql = "SELECT m_id,m_name,m_pic,m_actor,m_des,m_addtime,m_type,m_enname,m_datetime FROM ".DB::table('data')." WHERE m_recycle=0 ORDER BY  m_addtime DESC LIMIT 0,$makenum";
			$rssStr =  "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n
						<rss version='2.0'>\n
						<channel>\n
						<title><![CDATA[".siteName."]]></title>\n
						<description><![CDATA[".siteDes."]]></description>\n
						<link>http://".siteUrl."</link>\n
						<language>zh-cn</language>\n
						<docs>".siteName."</docs>\n
						<generator>Rss Powered By ".siteUrl."</generator>\n
						<image>\n
							<url>http://".siteUrl."/pic/logo.gif</url>\n
						</image>\n";
			$query = DB::query($sql);
            while($row = DB::fetch($query)) {
				$vDes = $row['m_des'] ; if (empty($vDes)) $vDes = "";
				$rssStr .= "<item>\n
								<title><![CDATA[".$row['m_name']."]]></title>\n
								<link>http://".siteUrl.getContentLink($row['m_type'],$row['m_id'],$row['m_enname'],$row['m_datetime'],"link")."</link>\n
								<author>".$row['m_actor']."</author>\n
								<pubDate>".date('Y-m-d H:i:s',$row['m_addtime'])."</pubDate>\n
								<description><![CDATA[".msubstr($vDes,300)."]]></description>\n	
							   </item>\n";
			}
			$rssStr .= "</channel></rss>\n";
			$rssStr = gb2utf8($rssStr);
			createTextFile($rssStr, "/rss.xml");
			echo "http://".siteUrl."/".sitePath."rss.xml"." 生成完毕 <a target='_blank' href='../rss.xml'><font color=red>浏览</font></a><br>";
	}
}
?>
