Changes to OpenStreetMap, show map inline, also lookup lat lon from location name
authorpokerazor <hanno-felix.wagner@stud.uni-due.de>
Tue, 8 Jan 2013 23:41:27 +0000 (00:41 +0100)
committerpokerazor <hanno-felix.wagner@stud.uni-due.de>
Tue, 8 Jan 2013 23:41:27 +0000 (00:41 +0100)
geonames/geonames.php
openstreetmap/openstreetmap.php

index 8226fc0bf6701170ac6518bd94cf185d2a4bfeb3..19725bef3ff53e1561f236cead784715fe8e9757 100755 (executable)
@@ -40,8 +40,8 @@ function geonames_install() {
         *
         */
 
-       register_hook('plugin_settings', 'addon/geonames/geonames.php', 'geonames_settings');
-       register_hook('plugin_settings_post', 'addon/geonames/geonames.php', 'geonames_settings_post');
+       register_hook('plugin_settings', 'addon/geonames/geonames.php', 'geonames_plugin_admin');
+       register_hook('plugin_settings_post', 'addon/geonames/geonames.php', 'geonames_plugin_admin_post');
 
        logger("installed geonames");
 }
@@ -58,8 +58,8 @@ function geonames_uninstall() {
         */
 
        unregister_hook('post_local',    'addon/geonames/geonames.php', 'geonames_post_hook');
-       unregister_hook('plugin_settings', 'addon/geonames/geonames.php', 'geonames_settings');
-       unregister_hook('plugin_settings_post', 'addon/geonames/geonames.php', 'geonames_settings_post');
+       unregister_hook('plugin_settings', 'addon/geonames/geonames.php', 'geonames_plugin_admin');
+       unregister_hook('plugin_settings_post', 'addon/geonames/geonames.php', 'geonames_plugin_admin_post');
 
 
        logger("removed geonames");
@@ -135,7 +135,7 @@ function geonames_post_hook($a, &$item) {
  *
  */
 
-function geonames_settings_post($a,$post) {
+function geonames_plugin_admin_post($a,$post) {
        if(! local_user() || (! x($_POST,'geonames-submit')))
                return;
        set_pconfig(local_user(),'geonames','enable',intval($_POST['geonames']));
@@ -153,7 +153,7 @@ function geonames_settings_post($a,$post) {
 
 
 
-function geonames_settings(&$a,&$s) {
+function geonames_plugin_admin(&$a,&$s) {
 
        if(! local_user())
                return;
index cb9abcd7df691117f281210dbbdf782b5582ea00..2c5975ebd82a5ab11d72d9482d80f5faf7479bd2 100755 (executable)
 
 function openstreetmap_install() {
        register_hook('render_location', 'addon/openstreetmap/openstreetmap.php', 'openstreetmap_location');
+       register_hook('page_header', 'addon/openstreetmap/openstreetmap.php', 'openstreetmap_alterheader');\r
 
        logger("installed openstreetmap");
 }
 
 function openstreetmap_uninstall() {
        unregister_hook('render_location', 'addon/openstreetmap/openstreetmap.php', 'openstreetmap_location');
+       unregister_hook('page_header', 'addon/openstreetmap/openstreetmap.php', 'openstreetmap_alterheader');
 
        logger("removed openstreetmap");
 }
 
+function openstreetmap_alterheader($a, &$navHtml) {
+       $addScriptTag='<script type="text/javascript" src="' . $a->get_baseurl() . '/addon/openstreetmap/openstreetmap.js' . '"></script>' . "\r\n";\r
+       $a->page['htmlhead'] .= $addScriptTag;
+}
 
 function openstreetmap_location($a, &$item) {
+
+       //
+
        if(! (strlen($item['location']) || strlen($item['coord'])))
-               return; 
+               return;
 
        /*
         * Get the configuration variables from the .htconfig file.
-        */
+       */
        $tmsserver = get_config('openstreetmap','tmsserver');
        if(! $tmsserver)
                $tmsserver = 'http://openstreetmap.org';
@@ -38,12 +47,27 @@ function openstreetmap_location($a, &$item) {
        $location = '';
        $coord = '';
 
+       
+       if($item['location'] && !$item['coord'] && true){ //if only a location is given, find the lat-lon
+               $geo_account='demo';
+\r
+               $s = fetch_url('http://api.geonames.org/search?maxRows=1&fuzzy=0.8&q=' . $item['location']  . '&username=' . $geo_account);\r
+\r
+               if($s){\r
+                       $xml = parse_xml_string($s);\r
+\r
+                       if($xml->geoname->lat && $xml->geoname->lng){\r
+                               $item['coord'] = $xml->geoname->lat . ' ' . $xml->geoname->lng;
+                       }\r
+               }
+       }
+
        $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="'.$tmsserver.'?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
 
        if($item['coord']) {
                $coords = explode(' ', $item['coord']);
                if(count($coords) > 1) {
-                       $coord = '<a target="map" title="' . $item['coord'] . '" href="'.$tmsserver.'?lat=' . urlencode($coords[0]) . '&lon=' . urlencode($coords[1]) . '&zoom='.$zoom.'">' . $item['coord'] . '</a>' ;
+                       $coord = '<a target="map" class="OSMMapLink" title="' . $item['coord'] . '" href="'.$tmsserver.'?lat=' . urlencode($coords[0]) . '&lon=' . urlencode($coords[1]) . '&zoom='.$zoom.'"> Map </a>' ;
                }
        }
        if(strlen($coord)) {
@@ -67,9 +91,9 @@ function openstreetmap_plugin_admin (&$a, &$o) {
                $zoom = 17;
 
        $o = replace_macros( $t, array(
-               '$submit' => t('Submit'),
-               '$tmsserver' => array('tmsserver', t('Tile Server URL'), $tmsserver, t('A list of <a href="http://wiki.openstreetmap.org/wiki/TMS" target="_blank">public tile servers</a>')),
-               '$zoom' => array('zoom', t('Default zoom'), $zoom, t('The default zoom level. (1:world, 18:highest)')),
+                       '$submit' => t('Submit'),
+                       '$tmsserver' => array('tmsserver', t('Tile Server URL'), $tmsserver, t('A list of <a href="http://wiki.openstreetmap.org/wiki/TMS" target="_blank">public tile servers</a>')),
+                       '$zoom' => array('zoom', t('Default zoom'), $zoom, t('The default zoom level. (1:world, 18:highest)')),
        ));
 }
 function openstreetmap_plugin_admin_post (&$a) {