<?php
if (!defined('IN_HANFOX')) exit('Access Denied');

require(APP_PATH.'module/webdata.php');

$type = trim($_GET['type']);
$web_id = intval($_GET['wid']);

if (in_array($type, array('prank', 'srank', 'arank', 'instat', 'outstat', 'error'))) {
	$web = get_one_website($web_id);
	if (!$web) {
		exit();
	}
	
	$time = time() + (3600 * 24 * $options['data_update_cycle']);
	if ($web['web_utime'] < $time) {
		#google pagerank
		if ($type == 'prank') {
			 $rank = get_pagerank($web['web_url']);
			 
			 $DB->query("UPDATE ".$DB->table('webdata')." SET web_prank='$rank' WHERE web_id=".$web['web_id']);
		}
		
		#sogou rank
		if ($type == 'srank') {
			$rank = get_sogourank($web['web_url']);
			$DB->query("UPDATE ".$DB->table('webdata')." SET web_srank='$rank' WHERE web_id=".$web['web_id']);
		}
		
		#alexa
		if ($type == 'arank') {
			$rank = get_alexarank($web['web_url']);
			$DB->query("UPDATE ".$DB->table('webdata')." SET web_arank='$rank' WHERE web_id=".$web['web_id']);
		}
	}
	
	#instat
	if ($type == 'instat') {
		$parts = parse_url($_SERVER['HTTP_REFERER']);
		if (!empty($parts['host'])) {
			$DB->query("UPDATE ".$DB->table('website')." a, ".$DB->table('webdata')." b SET b.web_instat=b.web_instat+1 WHERE a.web_id=b.web_id AND web_url LIKE 'http://".$parts['host']."%'");
		}
		unset($parts);
	}
	
	#outstat
	if ($type == 'outstat') {
		$DB->query("UPDATE ".$DB->table('webdata')." SET web_outstat=web_outstat+1 WHERE web_id=".$web['web_id']);
	}
	
	#error
	if ($type == 'error') {
		$DB->query("UPDATE ".$DB->table('website')." SET web_errors=web_errors+1 WHERE web_id=".$web['web_id']);
	}
}
?>