<?php

App::import('Vendor', 'cURL', array ( 'file' => 'curl.php'));

class AlexaComponent extends Object {
	
	public $criteriumId = 2;	
	
	function getRank($url)
	{	
		$fp = FirePHP::getInstance(true);
		$curl = new cURL();		
		
		$alexaURL = 'http://www.alexa.com/siteinfo/'.urlencode($url);
		$content = $curl->get($alexaURL);
		$doc = new DOMDocument();
		@$doc->loadHTML($content);
		$xpath = new DOMXPath($doc);
		$xquery = '//div[@class="data down"]';		
		$entries = $xpath->query($xquery);
		foreach ($entries as $entry)
		{
			$alexaRankString = (string)$entry->nodeValue;
			break;
		}
		$alexaRank = preg_replace('/[^0-9]/', '', $alexaRankString);
		$fp->log($alexaRank,'Alexa');
		
		return $alexaRank;
	}
	
}
?>