<?php
require_once(WWWROOT . 'topsites/data/variables');
if(!isset($_GET['p']))
{
$_GET['p'] = 'default';
}
$page = str_replace(array('.', '/', '\\'), '', $_GET['p']);
$updated = FALSE;
if(!isset($GLOBALS['O_CRON']))
{
$now = time();
# See if it is time for reset
if($now - file_get_contents(WWWROOT . 'topsites/data/reset') >= $GLOBALS['RESET'])
{
require_once(WWWROOT . 'topsites/tsphp.php');
$updated = ResetCurrentHits('index.php');
}
# See if it is time for rerank
if(!$updated && $now - file_get_contents(WWWROOT . 'topsites/data/rerank') >= $GLOBALS['RERANK'])
{
require_once(WWWROOT . 'topsites/tsphp.php');
$updated = RerankAccounts('index.php');
}
# Update the page the surfer is requesting
if( $updated || !file_exists(WWWROOT . "topsites/cache/$page.time") )
{
require_once(WWWROOT . 'topsites/tsphp.php');
BuildPage($page);
}
}
if(!file_exists(WWWROOT . "topsites/cache/$page") || !file_exists(WWWROOT . "topsites/cache/$page.time"))
{
require_once(WWWROOT . 'topsites/tsphp.php');
BuildPage($page);
}
# Display cached page
$result = @readfile(WWWROOT . "topsites/cache/$page");
if($result === FALSE)
{
print "Error: Could not display requested page [$page]";
}
?>