7cccb65024168970a57a91800ce98be01ddea74c
[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 use Friendica\Core\Logger
12
13 function googlemaps_install()
14 {
15         Addon::registerHook('render_location', 'addon/googlemaps/googlemaps.php', 'googlemaps_location');
16
17         Logger::log("installed googlemaps");
18 }
19
20 function googlemaps_uninstall()
21 {
22         Addon::unregisterHook('render_location', 'addon/googlemaps/googlemaps.php', 'googlemaps_location');
23
24         Logger::log("removed googlemaps");
25 }
26
27 function googlemaps_location($a, &$item)
28 {
29
30         if(! (strlen($item['location']) || strlen($item['coord']))) {
31                 return;
32         }
33
34         if ($item['coord'] != ""){ 
35                 $target = "http://maps.google.com/?q=".urlencode($item['coord']);
36         } else {
37                 $target = "http://maps.google.com/?q=".urlencode($item['location']);
38         }
39
40         if ($item['location'] != "") {
41                 $title = $item['location'];
42         } else {
43                 $title = $item['coord'];
44         }
45
46         $item['html'] = '<a target="map" title="'.$title.'" href= "'.$target.'">'.$title.'</a>';
47 }