]> git.mxchange.org Git - friendica-addons.git/blob - openstreetmap/openstreetmap.php
OSM improvements - increase zoom, return quickly if no location to render
[friendica-addons.git] / openstreetmap / openstreetmap.php
1 <?php
2 /**
3  * Name: Open Street Map
4  * Description: Use openstreetmap.org for displaying locations.
5  * Version: 1.0
6  * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
7  * 
8  *
9  */
10
11
12 function openstreetmap_install() {
13
14         register_hook('render_location', 'addon/openstreetmap/openstreetmap.php', 'openstreetmap_location');
15
16         logger("installed openstreetmap");
17 }
18
19
20 function openstreetmap_uninstall() {
21
22         unregister_hook('render_location', 'addon/openstreetmap/openstreetmap.php', 'openstreetmap_location');
23
24         logger("removed openstreetmap");
25 }
26
27
28
29 function openstreetmap_location($a, &$item) {
30
31         if(! (strlen($item['location']) || strlen($item['coord'])))
32                 return; 
33
34         $location = '';
35         $coord = '';
36
37         $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://www.openstreetmap.org/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
38
39         if($item['coord']) {
40                 $coords = explode(' ', $item['coord']);
41                 if(count($coords) > 1) {
42                         $coord = '<a target="map" title="' . $item['coord'] . '" href="http://www.openstreetmap.org/?lat=' . urlencode($coords[0]) . '&lon=' . urlencode($coords[1]) . '&zoom=18">' . $item['coord'] . '</a>' ;
43                 }
44         }
45         if(strlen($coord)) {
46                 if($location)
47                         $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
48                 else
49                         $location = '<span class="smalltext">' . $coord . '</span>';
50         }
51         $item['html'] = $location;
52         return;
53 }
54