]> git.mxchange.org Git - friendica-addons.git/blob - openstreetmap/openstreetmap.php
Make OSM tile server configurable.
[friendica-addons.git] / openstreetmap / openstreetmap.php
1 <?php
2 /**
3  * Name: OpenStreetMap
4  * Description: Use OpenStreetMap for displaying locations.
5  * Version: 1.1
6  * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
7  * Author: Klaus Weidenbach
8  *
9  */
10
11 function openstreetmap_install() {
12         register_hook('render_location', 'addon/openstreetmap/openstreetmap.php', 'openstreetmap_location');
13
14         logger("installed openstreetmap");
15 }
16
17 function openstreetmap_uninstall() {
18         unregister_hook('render_location', 'addon/openstreetmap/openstreetmap.php', 'openstreetmap_location');
19
20         logger("removed openstreetmap");
21 }
22
23
24 function openstreetmap_location($a, &$item) {
25         if(! (strlen($item['location']) || strlen($item['coord'])))
26                 return; 
27
28         /*
29          * Get the configuration variables from the .htconfig file.
30          */
31         $tmsserver = get_config('openstreetmap','tmsserver');
32         $zoom = get_config('openstreetmap','zoom');
33
34         $location = '';
35         $coord = '';
36
37         $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="'.$tmsserver.'?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="'.$tmsserver.'?lat=' . urlencode($coords[0]) . '&lon=' . urlencode($coords[1]) . '&zoom='.$zoom.'">' . $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
55
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)')),
62         ));
63 }
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);
70 }