2012-02-10 02:10:12 +00:00
< ? php
/**
2012-02-19 13:28:43 +00:00
* Name : OpenStreetMap
2012-07-27 23:26:14 +00:00
* Description : Use OpenStreetMap for displaying locations . After activation the post location just beneath your avatar in your posts will link to openstreetmap .
2012-02-19 13:28:43 +00:00
* Version : 1.1
2012-02-10 02:10:12 +00:00
* Author : Mike Macgirvin < http :// macgirvin . com / profile / mike >
2012-02-19 13:28:43 +00:00
* Author : Klaus Weidenbach
2012-02-10 02:10:12 +00:00
*
*/
function openstreetmap_install () {
register_hook ( 'render_location' , 'addon/openstreetmap/openstreetmap.php' , 'openstreetmap_location' );
2013-01-08 23:41:27 +00:00
register_hook ( 'page_header' , 'addon/openstreetmap/openstreetmap.php' , 'openstreetmap_alterheader' );
2012-02-10 02:10:12 +00:00
logger ( " installed openstreetmap " );
}
function openstreetmap_uninstall () {
unregister_hook ( 'render_location' , 'addon/openstreetmap/openstreetmap.php' , 'openstreetmap_location' );
2013-01-08 23:41:27 +00:00
unregister_hook ( 'page_header' , 'addon/openstreetmap/openstreetmap.php' , 'openstreetmap_alterheader' );
2012-02-10 02:10:12 +00:00
logger ( " removed openstreetmap " );
}
2013-01-08 23:41:27 +00:00
function openstreetmap_alterheader ( $a , & $navHtml ) {
$addScriptTag = '<script type="text/javascript" src="' . $a -> get_baseurl () . '/addon/openstreetmap/openstreetmap.js' . '"></script>' . " \r \n " ;
$a -> page [ 'htmlhead' ] .= $addScriptTag ;
}
2012-02-10 02:10:12 +00:00
function openstreetmap_location ( $a , & $item ) {
2013-01-08 23:41:27 +00:00
//
2012-02-10 03:53:56 +00:00
if ( ! ( strlen ( $item [ 'location' ]) || strlen ( $item [ 'coord' ])))
2013-01-08 23:41:27 +00:00
return ;
2012-02-10 03:53:56 +00:00
2012-02-19 13:28:43 +00:00
/*
* Get the configuration variables from the . htconfig file .
2013-01-08 23:41:27 +00:00
*/
2012-02-19 13:28:43 +00:00
$tmsserver = get_config ( 'openstreetmap' , 'tmsserver' );
2012-02-19 22:26:41 +00:00
if ( ! $tmsserver )
$tmsserver = 'http://openstreetmap.org' ;
2012-02-19 13:28:43 +00:00
$zoom = get_config ( 'openstreetmap' , 'zoom' );
2012-02-19 22:26:41 +00:00
if ( ! $zoom )
$zoom = 17 ;
2012-02-19 13:28:43 +00:00
2012-02-10 02:10:12 +00:00
$location = '' ;
$coord = '' ;
2013-01-08 23:41:27 +00:00
if ( $item [ 'location' ] && ! $item [ 'coord' ] && true ){ //if only a location is given, find the lat-lon
$geo_account = 'demo' ;
$s = fetch_url ( 'http://api.geonames.org/search?maxRows=1&fuzzy=0.8&q=' . $item [ 'location' ] . '&username=' . $geo_account );
if ( $s ){
$xml = parse_xml_string ( $s );
if ( $xml -> geoname -> lat && $xml -> geoname -> lng ){
$item [ 'coord' ] = $xml -> geoname -> lat . ' ' . $xml -> geoname -> lng ;
}
}
}
2012-02-19 13:28:43 +00:00
$location = (( $item [ 'location' ]) ? '<a target="map" title="' . $item [ 'location' ] . '" href="' . $tmsserver . '?q=' . urlencode ( $item [ 'location' ]) . '">' . $item [ 'location' ] . '</a>' : '' );
2012-02-10 02:10:12 +00:00
if ( $item [ 'coord' ]) {
$coords = explode ( ' ' , $item [ 'coord' ]);
if ( count ( $coords ) > 1 ) {
2013-01-08 23:41:27 +00:00
$coord = '<a target="map" class="OSMMapLink" title="' . $item [ 'coord' ] . '" href="' . $tmsserver . '?lat=' . urlencode ( $coords [ 0 ]) . '&lon=' . urlencode ( $coords [ 1 ]) . '&zoom=' . $zoom . '"> Map </a>' ;
2012-02-10 02:10:12 +00:00
}
}
if ( strlen ( $coord )) {
if ( $location )
$location .= '<br /><span class="smalltext">(' . $coord . ')</span>' ;
else
$location = '<span class="smalltext">' . $coord . '</span>' ;
}
$item [ 'html' ] = $location ;
return ;
}
2012-02-19 13:28:43 +00:00
function openstreetmap_plugin_admin ( & $a , & $o ) {
2012-12-22 20:36:35 +00:00
$t = get_markup_template ( " admin.tpl " , " addon/openstreetmap/ " );
2012-02-19 22:26:41 +00:00
$tmsserver = get_config ( 'openstreetmap' , 'tmsserver' );
if ( ! $tmsserver )
$tmsserver = 'http://openstreetmap.org' ;
$zoom = get_config ( 'openstreetmap' , 'zoom' );
if ( ! $zoom )
$zoom = 17 ;
2012-12-25 20:25:09 +00:00
$o = replace_macros ( $t , array (
2013-11-19 13:10:27 +00:00
'$submit' => t ( 'Save Settings' ),
2013-01-08 23:41:27 +00:00
'$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)' )),
2012-02-19 13:28:43 +00:00
));
}
function openstreetmap_plugin_admin_post ( & $a ) {
$url = (( x ( $_POST , 'tmsserver' )) ? notags ( trim ( $_POST [ 'tmsserver' ])) : '' );
$zoom = (( x ( $_POST , 'zoom' )) ? intval ( trim ( $_POST [ 'zoom' ])) : '17' );
set_config ( 'openstreetmap' , 'tmsserver' , $url );
set_config ( 'openstreetmap' , 'zoom' , $zoom );
info ( t ( 'Settings updated.' ) . EOL );
}