4 * Description: Use OpenStreetMap for displaying locations.
6 * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
7 * Author: Klaus Weidenbach
11 function openstreetmap_install() {
12 register_hook('render_location', 'addon/openstreetmap/openstreetmap.php', 'openstreetmap_location');
14 logger("installed openstreetmap");
17 function openstreetmap_uninstall() {
18 unregister_hook('render_location', 'addon/openstreetmap/openstreetmap.php', 'openstreetmap_location');
20 logger("removed openstreetmap");
24 function openstreetmap_location($a, &$item) {
25 if(! (strlen($item['location']) || strlen($item['coord'])))
29 * Get the configuration variables from the .htconfig file.
31 $tmsserver = get_config('openstreetmap','tmsserver');
33 $tmsserver = 'http://openstreetmap.org';
34 $zoom = get_config('openstreetmap','zoom');
41 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="'.$tmsserver.'?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
44 $coords = explode(' ', $item['coord']);
45 if(count($coords) > 1) {
46 $coord = '<a target="map" title="' . $item['coord'] . '" href="'.$tmsserver.'?lat=' . urlencode($coords[0]) . '&lon=' . urlencode($coords[1]) . '&zoom='.$zoom.'">' . $item['coord'] . '</a>' ;
51 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
53 $location = '<span class="smalltext">' . $coord . '</span>';
55 $item['html'] = $location;
60 function openstreetmap_plugin_admin (&$a, &$o) {
61 $t = file_get_contents( dirname(__file__)."/admin.tpl");
62 $tmsserver = get_config('openstreetmap','tmsserver');
64 $tmsserver = 'http://openstreetmap.org';
65 $zoom = get_config('openstreetmap','zoom');
69 $o = replace_macros( $t, array(
70 '$submit' => t('Submit'),
71 '$tmsserver' => array('tmsserver', t('Tile Server URL'), $tmsserver, t('A list of <a href="http://wiki.openstreetmap.org/wiki/TMS" target="_blank">public tile servers</a>')),
72 '$zoom' => array('zoom', t('Default zoom'), $zoom, t('The default zoom level. (1:world, 18:highest)')),
75 function openstreetmap_plugin_admin_post (&$a) {
76 $url = ((x($_POST, 'tmsserver')) ? notags(trim($_POST['tmsserver'])) : '');
77 $zoom = ((x($_POST, 'zoom')) ? intval(trim($_POST['zoom'])) : '17');
78 set_config('openstreetmap', 'tmsserver', $url);
79 set_config('openstreetmap', 'zoom', $zoom);
80 info( t('Settings updated.'). EOL);