<?php
/**
* Google Image Parser
*
* Lookup cover images from Google
*
* @package Engines
* @author Andreas Götz <hide@address.com>
* @link http://images.google.com Google image search
* @version $Id: google.php,v 1.7 2008/01/08 19:38:55 andig2 Exp $
*/
$GLOBALS['googleServer'] = 'http://images.google.com';
/**
* Get meta information about the engine
*
* @todo Include image search capabilities etc in meta information
*/
function googleMeta()
{
return array('name' => 'Google', 'stable' => 1);
}
/**
* Search an image on Google
*
* Searches for a given title on the google and returns the found links in
* an array
*
* @param string The search string
* @return array Associative array with id and title
*/
function googleSearch($title)
{
global $googleServer;
global $CLIENTERROR;
$resp = httpClient($googleServer.'/images?q='.urlencode($title), 1);
if (!$resp['success']) $CLIENTERROR .= $resp['error']."\n";
/* Google changed Image search site (end of June 2006)
link is now found in javascript only and looks like: (without newlines and spaces)
dyn.Img("http://www.luds.net/gwall5.php&h=600&w=800&sz=62&hl=de&start=1",
"",
"ehsHcj85v2n-OM:",
"www.luds.net/fond_ecrans/wBart%2520%26%2520Homer%25204.gif",
"142",
"106",
"wBart & <b>Homer</b> 4.gif",
"",
"",
"800 x 600 Pixel - 62k",
"gif",
"www.luds.net",
"",
"");
The Thumb-URL of this example is:
http://images.google.com/images?q=tbn:ehsHcj85v2n-OM:www.luds.net/fond_ecrans/wBart%2520%26%2520Homer%25204.gif
*/
$result = array();
if (preg_match_all('/dyn.Img\(".*?&h=(\d+)&w=(\d+).*?",".*?","(.*?)","(.*?)",.*?\);/', $resp['data'], $data, PREG_SET_ORDER ))
{
foreach ($data as $row)
{
$info = array();
$info['title'] = $row[2].'x'.$row[1]; // width x height
$info['imgsmall'] = $googleServer.'/images?q=tbn:'.$row[3].$row[4]; // small thumbnail url
$info['coverurl'] = $row[4]; // resulting target url
$result[] = $info;
}
}
return $result;
}
?>