<?php
/**
 * @自动更新HTML静态文件模块
 * 
 * 
 * @适合用于使用虚拟主机的个人站点
 * 
 * @织梦技术研究中心   http://bbs.dedejs.com
 *
 * @版本	AutoHtml V5.7.4 Final
 */
require_once(DEDEINC."/autohtml.class.php");
CheckPurview('sys_plus,sys_MakeHtml,temp_All');

$ahtype = 'msg';
$nowtime = Time();
$arr = array('arc','index','list','freelist','rss','spec','check');

if($act=="save")
{ 
	if(!empty($mod) && $mod != 'setting' && $mod != 'filedir' && $mod != 'abcd' )
	{
		if(empty($auto["{$mod}_open"])) $auto["{$mod}_open"] = "N";
		if(empty($auto["{$mod}_reload"])) $auto["{$mod}_reload"] = "N";
		//if(empty($auto["{$mod}_interval"])) $auto["{$mod}_interval"] = "60";
		if(empty($auto["{$mod}_pages"])) $auto["{$mod}_pages"] = "50";
	}
	foreach ($arr as $v)
	{
		if(isset($auto["{$v}_pages"]) && !is_numeric($auto["{$v}_pages"])) $auto["{$v}_pages"] = "50";
		if(isset($auto["{$v}_interval"]) && !is_numeric($auto["{$v}_interval"])) $auto["{$v}_interval"] = "60";
	}
	if(isset($auto["index_open"]) && $auto["index_open"] == "Y")
	{
		$row = $dsql->GetOne("Select * From #@__homepageset");
		$auto["index_templet"] = $row["templet"];
		$auto["index_indexFile"] = DEDEINC.'/'.$row["position"];
		$auto["index_templet"] = DEDEROOT.'/templets/'.str_replace('{style}',$cfg_df_style,$row["templet"]);
		$auto["index_interval"] = isset($auto["index_interval"]) && is_numeric($auto["index_interval"]) ? $auto["index_interval"] : 60;
	}

	if($mod == "list" && $auto["list_pages"] > 50)
	{
		$auto["list_pages"] = 50;
	}
	else if($mod == "freelist" && $auto["freelist_pages"] > 100)
	{
		$auto["freelist_pages"] = 100;
	}
	else if($mod=='arc')
	{
		unset($auto["{$mod}_pages"]);
		$auto["arc_endid"] = is_numeric($auto["arc_endid"]) ? $auto["arc_endid"] : 0;
		$auto["arc_startid"] = is_numeric($auto["arc_startid"]) ? $auto["arc_startid"] : 0;
		$auto["arc_endtime"] = empty($auto["arc_endtime"]) ? "0" : strtotime($auto["arc_endtime"]);
		$auto["arc_starttime"] = empty($auto["arc_starttime"]) ? "0" : strtotime($auto["arc_starttime"]);
		$auto["arc_reload"] = ( $auto["arc_endtime"] > $nowtime ) && $auto["arc_reload"] == "Y" ? "Y" : "N";
		$auto["arc_endtime"] = ( $auto["arc_endtime"] < 0 ) ? $auto["arc_endtime"] = '0' : $auto["arc_endtime"];
		$auto["arc_starttime"] = ( $auto["arc_starttime"] < 0 ) ? $auto["arc_starttime"] = '0' : $auto["arc_starttime"];
	}
	else if($mod=='filedir')
	{
		$auto["focus_dir"] = substr($auto["focus_dir"],-1,1)=='/'?$auto["focus_dir"]:$auto["focus_dir"].'/';
		if($auto["focus_dir"] != $cfg_cmspath.'/plus/')
		{
			$find = '/dirna.*?php\"/i';
			$content = file_get_contents(DEDEROOT."/plus/autohtml.php");
			$focusfile = str_replace("\\", '/', substr(DEDEROOT,0,-strlen($cfg_cmspath))).$auto["focus_dir"].'autohtml.php';
			if(preg_match($find,$content))
			{
				$content = preg_replace($find,'"'.DEDEROOT.'/include/common.inc.php"',$content);
			}
			$ah->PutFile($focusfile,$content); 
		}
	}
	else if($mod=='check')
	{
		unset($auto['check_reload']);
		if($auto["check_pages"] > 20) $auto["check_pages"] = 20;
		$auto["check_time"] = empty($auto["check_time"]) ? '' : join(',',$auto["check_time"]);
	}
	$ah->WriteGlobals($auto);
}
else if($act=="mb_update")
{
	$indexname = $ah -> GetIndexName();

	if(!empty($mod))
	{
		$mbup = array();
		if( $mod == "upone" || $mod == "delone" ) $mbup[$file] = "Y" ;
		if( $mod == "upall" || $mod == "delall" )
		{
			$mbup[$indexname] = "Y" ;
			foreach ($mbarr as $k => $v)
			{
				$mbup[$k] = "Y" ;
			}
		}
		$arr = $ah -> UpTpl($mbup);
	}
	else
	{
		$mbarr2['index'] = array( "$indexname" => "[网站]首页" );
		$ahtype = 'mblist';
	}
}
else if($act=="checkver")
{
	if($mod=="update")
	{
		$ah->UpModule();
	}
	else
	{
		$ah->CheckVer();
	}
}
else if($act=="author")
{
	$ah->Author();
}
else if(empty($act))
{
	if(!file_exists($ah->cacheglobal))
	{
		$auto = array('arc_startid'=>'0','arc_endid'=>'0','arc_starttime'=>'0','arc_endtime'=>'0');
		foreach ($arr as $v)
		{
			$auto["{$v}_open"] = "N";
			$auto["{$v}_reload"] = "N";
			$auto["{$v}_pages"] = "50";
			$auto["{$v}_interval"] = "60";
		}
		$auto["check_time"] = "";
		$auto["check_makearc"] = "N";
		$auto["check_makeindex"] = "N";
		$auto["settpl"] = "N";
		$auto["focus_dir"] = $cfg_cmspath."/plus/";
		$ah->WriteGlobals($auto);
	}

	$ahtype = '';
	require_once($ah->cacheglobal);
}
else
{
	exit('error');
}
require_once(dirname(__FILE__)."/autohtml_admin.htm");
?>