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