<?php
/**
 * @自动更新HTML静态文件模块
 * 
 * @目前模块可以实现在网页上放上相应代码当有人访问即可自动更新HTML文件
 * 
 * @适合用于使用虚拟主机的个人站点
 * 
 * @作者	溪梦缘曦
 *
 * @版本	AutoHtml V5.7.4 Final
 *
 * @起始	2008-02-01发布第一个版本,2013-06-20修改为当前版本
 *
 * @特别鸣谢	织梦技术论坛的各位朋友
 *
 */
require_once(dirname(__FILE__)."/../include/common.inc.php");
require_once(DEDEINC."/autohtml.class.php");
if(!in_array($type,array('index','list','freelist','rss','archives','spec','test'))){exit('<meta name=\'autohtml\' content=\'未知错误\' />');}
require_once($ah->cacheglobal);
if($type == 'archives')
{
	$arc = array();
	$ah->type = 'arc';
	$id = (isset($id) && is_numeric($id)) ? $id : 0;
	if($id=='0') $ah->Msg('文章ID错误。');
	if(file_exists($ah->cachefile)) require_once($ah->cachefile);

	$arc_interval = is_numeric($arc_interval) ? $arc_interval : 0;
	$arc_uptime[$id] = isset($arc_uptime[$id]) && is_numeric($arc_uptime[$id]) ? $arc_uptime[$id] : '0';
	$isuptime = $nowtime - $arc_uptime[$id] - $arc_interval * 60;

	$sd = ( $id > $arc_startid || $arc_startid == 0 ) ? 'Y' : 'N';
	$ed = ( $id < $arc_endid || $arc_endid == 0 ) ? 'Y' : 'N';
	$st = ( $arc_starttime < $nowtime || $arc_starttime == 0 ) ? 'Y' : 'N';
	$et = ( $arc_endtime > $nowtime || $arc_endtime == 0 ) ? 'Y' : 'N';
	$gt = ( $sd == 'Y' && $ed == 'Y' && $st == 'Y' && $et == 'Y' ) ? 'Y' : 'N'; 

	if( $gt == 'Y' && $arc_open == 'Y' && $isuptime > 0 )
	{
		$ah->make->arc($id);
	}
	else if( $arc_open == 'N')
	{
		$ah->Msg('已关闭文章页面更新。');
	}
	else
	{
		$ah->Msg('文件在时间范围内已经更新，不需要再次更新。');
	}
}
else if($type == 'list')
{
	$id = (isset($id) && is_numeric($id)) ? $id : 0;
	if($id=='0') $ah->Msg('栏目ID错误，请后台设置处参考设置方法。');

	if(file_exists($ah->cachefile))
	{
		require_once($ah->cachefile);
		$list_interval = is_numeric($list_interval) ? $list_interval : 0;
		$rss_interval = is_numeric($rss_interval) ? $rss_interval : 0;
		$list_uptime[$id] = isset($list_uptime[$id]) && is_numeric($list_uptime[$id]) ? $list_uptime[$id] : '0';
		$rss_uptime[$id] = isset($rss_uptime[$id]) && is_numeric($rss_uptime[$id]) ? $rss_uptime[$id] : '0';

		$isuptime = $nowtime - $list_uptime[$id] - $list_interval * 60;
		$isuptimerss = $nowtime - $rss_uptime[$id] - $rss_interval * 60;
	}
	else
	{
		$isuptime = $isuptimerss = 12345;
	}
	if( $isuptime > 0 && $list_open == 'Y')
	{
		$ah->make->arclist($id,$list_pages);
	}
	else if($list_open == 'N' )
	{
		$ah->Msg('已关闭栏目更新。');
	}
	else
	{
		$ah->Msg('列表文件在时间范围内已经更新，不需要再次更新。');
	}

	if( $isuptimerss > 0 && $rss_open == 'Y' )
	{
		$ah->make->rss($id,$rss_pages);
	}
	else if($rss_open == 'N')
	{
		$ah->Msg('已关闭RSS更新。');
	}
	else
	{
		$ah->Msg('当前栏目不需要重新生成RSS。');
	}
}
else if($type == 'freelist')
{
	$id = (isset($id) && is_numeric($id)) ? $id : 0;
	if($id=='0') $ah->Msg('自由列表ID错误，请后台设置处参考设置方法。');

	if(file_exists($ah->cachefile))
	{
		require_once($ah->cachefile);
		$freelist_interval = is_numeric($freelist_interval) ? $freelist_interval : 0;
		$freelist_uptime[$id] = isset($freelist_uptime[$id]) && is_numeric($freelist_uptime[$id]) ? $freelist_uptime[$id] : '0';
		$isuptime = $nowtime - $freelist_uptime[$id] - $freelist_interval * 60;
	}
	else
	{
		$isuptime = 12345;
	}

	if( $isuptime > 0 && $freelist_open == 'Y')
	{
		$ah->make->freelist($id,$freelist_pages);
	}
	else if( $freelist_open == 'N')
	{
		$ah->Msg( '已关闭自由列表更新。');
	}
	else
	{
		$ah->Msg('自由列表在时间范围内已经更新，不需要再次更新。');
	}
}
else if($type == 'index')
{
	$index_interval = is_numeric($index_interval) ? $index_interval : 0;
	$index_uptime = isset($index_uptime) && is_numeric($index_uptime) ? $index_uptime : 0;
	$isuptime = $nowtime - $index_uptime - $index_interval * 60;

	if( $index_open == 'Y' && $isuptime > 0 )
	{
		$tpl = "";
		$index_templet = str_replace("{style}",$cfg_df_style,$index_templet);
		if(file_exists($index_templet))
		{
			$tpl = $index_templet;
		}
		else if(file_exists(DEDEROOT.$index_templet))
		{
			$tpl = DEDEROOT.$index_templet;
		}
		else if(file_exists($cfg_basedir.$cfg_templets_dir."/".$index_templet))
		{
			$tpl = $cfg_basedir.$cfg_templets_dir."/".$index_templet;
		}
		if(empty($tpl)) $ah->Msg('请后台重新设置首页更新。');
		$ah->make->index($tpl,$index_indexFile);
	}
	else if($index_open == 'N' )
	{
		$ah->Msg('已关闭首页更新。');
	}
	else
	{
		$ah->Msg('首页在时间范围内已经更新，不需要再次更新。');
	}
}
else if($type == 'spec')
{
	$spec_interval = is_numeric($spec_interval) ? $spec_interval : 0;
	$spec_uptime = isset($spec_uptime) && is_numeric($spec_uptime) ? $spec_uptime : 0;

	$isuptime = $nowtime - $spec_uptime - $spec_interval * 60;
	if( $spec_open == 'Y' && $isuptime > 0 )
	{
		$ah->make->spec();
	}
	else if($spec_open == 'N' )
	{
		$ah->Msg('已关闭专题更新。');
	}
	else
	{
		$ah->Msg('专题在时间范围内已经更新，不需要再次更新。');
	}

}
else if($type == 'test')
{
	exit('正常运行');
}
?>