Commit 7900f980 authored by lyricnz's avatar lyricnz
Browse files

A module to include geocoded Wikipedia results in searches (with possible

thumbnails).
parent 69f8ac4b
The GeoNames contrib project is a collection of modules to integrate with
the webservers and data provided by GeoNames http://www.geonames.org/
\ No newline at end of file
the webservers and data provided by GeoNames http://www.geonames.org/
=======================================================================
GeoNames Wikipedia Search: Integrate Wikipedia Results into Search
=======================================================================
Creates a new search type "Wikipedia" that includes results from
http://www.geonames.org/export/wikipedia-webservice.html#wikipediaSearch
The results provided by the module also include all values from the XML, including
coordinates and a thumbnail image.
[entry] => Array
(
[lang] => en
[title] => Stock Exchange Tower
[summary] => at 125 Old Broad Street. Standing at 103 m (339 feet) tall, with 26 floors, the tower was completed in 1970. It served as the headquarters and offices for the London Stock Exchange until its departure for new premises in Paternoster Square, in July 2004. ''Face to face'' trading was conducted on the trading floor of the exchange, until it was abolished in favour of electronic trading (...)
[feature] =>
[population] => 0
[elevation] => 0
[lat] => 51.5144
[lng] => -0.0867
[wikipediaUrl] => http://en.wikipedia.org/wiki/Stock_Exchange_Tower
[thumbnailImg] => http://www.geonames.org/img/wikipedia/11000/thumb-10323-100.jpg
)
These could be themed something like
/**
* Include a thumbnail in wikipedia search results (provided by geonames/wikipedia_search.module)
*/
function yourmodule_search_item($item, $type) {
switch ($item['type']) {
case 'wikipedia':
// Add coordinates to the extra information
$entry = $item['entry'];
$item['extra'] = array('LAT:' . $entry['lat'], 'LONG:' . $entry['lng']);
// Add a thumbnail image to the results
if ($entry['thumbnailImg']) {
$img_html = theme('image', $entry['thumbnailImg'], $item['title'], $item['title'], NULL, FALSE);
$link_html = l($img_html, $item['link'], array(), NULL, NULL, FALSE, TRUE);
$item['snippet'] = $link_html . $item['snippet'];
}
$html = theme_search_item($item, $type);
break;
default:
$html = theme_search_item($item, $type);
break;
}
return $html;
}
; $Id $
name = GeoNames Wikipedia Search
description = Integrate Wikipedia Results into Search
dependencies = search
package = Other
<?php
function wikipedia_search_install() {
}
function wikipedia_search_uninstall() {
}
<?php
/**
* Implementation of hook_search().
*/
function wikipedia_search_search($op = 'search', $keys = NULL) {
switch ($op) {
case 'name':
return t('Wikipedia');
case 'search':
$doc = file_get_contents('http://ws.geonames.org/wikipediaSearch?maxRows=20&q=' . urlencode($keys));
if ($doc != FALSE) {
$results = array();
$xml = new SimpleXMLElement($doc);
foreach ($xml->children() as $entry) {
// build a list of all the attributes in the entry
$fields = array();
foreach ($entry->children() as $field) {
$fields[$field->getName()] = (string) $field;
}
// build the search result
$results[] = array(
'link' => (string) $entry->wikipediaUrl,
'type' => 'wikipedia',
'title' => (string) $entry->title,
// 'user' not defined
// 'date' not defined
// 'extra' not defined
'snippet' => $img_html . search_excerpt($keys, $entry->summary),
'entry' => $fields, // all the extra
);
}
return $results;
}
break;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment