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');
32 $zoom = get_config('openstreetmap','zoom');
37 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="'.$tmsserver.'?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
40 $coords = explode(' ', $item['coord']);
41 if(count($coords) > 1) {
42 $coord = '<a target="map" title="' . $item['coord'] . '" href="'.$tmsserver.'?lat=' . urlencode($coords[0]) . '&lon=' . urlencode($coords[1]) . '&zoom='.$zoom.'">' . $item['coord'] . '</a>' ;
47 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
49 $location = '<span class="smalltext">' . $coord . '</span>';
51 $item['html'] = $location;
56 function openstreetmap_plugin_admin (&$a, &$o) {
57 $t = file_get_contents( dirname(__file__)."/admin.tpl");
58 $o = replace_macros( $t, array(
59 '$submit' => t('Submit'),
60 '$tmsserver' => array('tmsserver', t('Tile Server URL'), get_config('openstreetmap','tmsserver' ), t('A list of <a href="http://wiki.openstreetmap.org/wiki/TMS" target="_blank">public tile servers</a>')),
61 '$zoom' => array('zoom', t('Default zoom'), get_config('openstreetmap','zoom' ), t('The default zoom level. (1:world, 18:highest)')),
64 function openstreetmap_plugin_admin_post (&$a) {
65 $url = ((x($_POST, 'tmsserver')) ? notags(trim($_POST['tmsserver'])) : '');
66 $zoom = ((x($_POST, 'zoom')) ? intval(trim($_POST['zoom'])) : '17');
67 set_config('openstreetmap', 'tmsserver', $url);
68 set_config('openstreetmap', 'zoom', $zoom);
69 info( t('Settings updated.'). EOL);