Location: PHPKode > projects > VideoDB > videodb/engines/gamerankings.php
<?php
/**
 * Game Rankings
 *
 * Lookup info from Gamerankings
 *
 * @package Engines
 * @author  Mike Clark    <hide@address.com>
 * @link    http://www.gamerankings.com  Gamerankings
 */

$GLOBALS['gamerankingsServer']	= 'http://www.gamerankings.com';

/**
 * Get meta information about the engine
 *
 * @todo    Include image search capabilities etc in meta information
 */
function gamerankingsMeta()
{
    return array('name' => 'Game Rankings');
}

/**
 * Search for games on GameRankings
 *
 * Searches for a given title on gamerankings and returns the found links in
 * an array
 *
 * @param   string    The search string
 * @return  array     Associative array with id and title
 */
function gamerankingsSearch($title)
{

    global $gamerankingsServer;
    global $CLIENTERROR;

    $resp = httpClient($gamerankingsServer.'/itemrankings/simpleratings.asp?extsearch=on&itemname='.urlencode($title), 1);
    if (!$resp['success']) $CLIENTERROR .= $resp['error']."\n";

    $result = array();
    if (preg_match_all('/itemid=([0-9].+?)&.+?&nbsp;(.+?)<\/a>.+?<td width="8%" valign=top>(.+?)<\/td>/s', $resp['data'], $data, PREG_SET_ORDER))
    {

        foreach ($data as $row)
        {
            $info = array();
            $info['id']		= 'GR'.$row[1];
            $info['title']		= $row[2];
            $info['details']	= trim($row[3]);
            $result[]		= $info;
        }
    }

    return $result;
}

/**
 * Fetches the data for a given Gamerankings ID
 *
 * @author  Mike Clark <hide@address.com>
 * @param   int   GRID
 * @return  array Result data
 */
function gamerankingsData($grID)
{
	global $gamerankingsServer, $cache;
	global $CLIENTERROR;

	$grID = substr($grID,2);
	$data = array();  //result

	//fetch mainpage
	$resp = httpClient($gamerankingsServer.'/htmlpages2/'.$grID.'.asp', 1);
	if (!$resp[success]) {
		$CLIENTERROR .= $resp[error]."\n";
		return $data;
	}
	 #print htmlspecialchars($resp[data]);

	//title
	if (preg_match("/<title>(.+?)Reviews<\/title>/",$resp[data],$ary)) {
	#	print_r($ary);
		$data[title] = trim($ary[1]);
	}

	//Cover URL (verify if large image exists)
	if (preg_match("/http:\/\/img.gamespot.com\/gamespot\/images\/.+\.jpg/",$resp[data],$ary)) {
	#	print_r($ary);
		$data[coverurl] = $ary[0];
	}

	//Plot/Description
	if (preg_match("/align=left border=0 alt=\".+?\"><\/a>(.+?)</s",$resp[data],$ary)) {
		#print_r($ary);
		$data[plot] = trim($ary[1]);
	}

	//Rating
	if (!preg_match("#Avg Ratio:.+?(--).+?</b>#",$resp[data],$ary)) {
		if (preg_match("/Avg Ratio:.+?([0-9])([0-9])%/s",$resp[data],$ary)) {
		#	print_r($ary);
			$data[rating] = $ary[1].'.'.$ary[2];
		}	
	}

	return $data;
}

?>
Return current item: VideoDB