<?php

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

class W3cComponent extends Object {
	
	public $criteriumId = 3;	
	
	function getRank($url)
	{	
		$fp = FirePHP::getInstance(true);
		$curl = new cURL();		
		
		$w3curl = 'http://validator.w3.org/check?uri='.urlencode($url);
		$content = $curl->get($w3curl);
		//$fp->log($content);
		
		$doc = new DOMDocument();
		@$doc->loadHTML($content);
		$xpath = new DOMXPath($doc);
		$xquery =  '//td[@class="invalid"]';
		$entries = $xpath->query($xquery);
		foreach ($entries as $entry)
		{
			$w3cRankString = $entry->nodeValue;
			break;
		}
		preg_match('/([0-9]+) Error.*/', $w3cRankString, $matches);
		//$fp->log($matches);
		$w3cRank = intval($matches[1]);
		//$fp->log($w3cRank,'W3C');
				
		return $w3cRank;
	}
	
}

?>