Merge branch '3.6-rc'
[friendica-addons.git/.git] / googlemaps / googlemaps.php
1 <?php
2 /**
3  * Name: Google Maps
4  * Description: Use Google Maps for displaying locations. After activation the post location just beneath your avatar in your posts will link to Google Maps.
5  * Version: 0.1
6  * Author: Michael Vogel <https://pirati.ca/profile/heluecht>
7  *
8  */
9 use Friendica\Core\Addon;
10 use Friendica\Core\Cache;
11
12 function googlemaps_install()
13 {
14         Addon::registerHook('render_location', 'addon/googlemaps/googlemaps.php', 'googlemaps_location');
15
16         logger("installed googlemaps");
17 }
18
19 function googlemaps_uninstall()
20 {
21         Addon::unregisterHook('render_location', 'addon/googlemaps/googlemaps.php', 'googlemaps_location');
22
23         logger("removed googlemaps");
24 }
25
26 function googlemaps_location($a, &$item) {
27
28         if(! (strlen($item['location']) || strlen($item['coord'])))
29                 return;
30
31         if ($item['coord'] != "")
32                 $target = "http://maps.google.com/?q=".urlencode($item['coord']);
33         else
34                 $target = "http://maps.google.com/?q=".urlencode($item['location']);
35
36         if ($item['location'] != "")
37                 $title = $item['location'];
38         else
39                 $title = $item['coord'];
40
41         $item['html'] = '<a target="map" title="'.$title.'" href= "'.$target.'">'.$title.'</a>';
42 }