diff --git a/freifunkmeta.php b/freifunkmeta.php index 5dfbfbc..7f10408 100644 --- a/freifunkmeta.php +++ b/freifunkmeta.php @@ -10,7 +10,7 @@ Author URI: http://mschuette.name/ define('FF_META_DEFAULT_CACHETIME', 15); define('FF_META_DEFAULT_DIR', 'https://raw.githubusercontent.com/freifunk/directory.api.freifunk.net/master/directory.json'); -define('FF_META_DEFAULT_URL', 'http://meta.hamburg.freifunk.net/ffhh.json'); +define('FF_META_DEFAULT_CITY', 'hamburg'); /* gets metadata from URL, handles caching */ function ff_meta_getmetadata ($url) { @@ -38,25 +38,22 @@ if ( ! shortcode_exists( 'ff_contact' ) ) { // Example: // [ff_state] // [ff_state hamburg] -// [ff_state url="http://meta.hamburg.freifunk.net/ffhh.json"] function ff_meta_shortcode_handler( $atts, $content, $name ) { - $default_url = get_option( 'ff_meta_url', FF_META_DEFAULT_URL ); - extract(shortcode_atts( array( - 'url' => $default_url, - ), $atts)); - - // check for city name - if (!empty($atts[0])) { + // $atts[0] holds the city name, if given + if (empty($atts[0])) { + $city = get_option( 'ff_meta_city', FF_META_DEFAULT_CITY ); + } else { $city = $atts[0]; - if (false === ($directory = ff_meta_getmetadata ( FF_META_DEFAULT_DIR )) - || empty($directory[$city])) { - return ''; - } - $url = $directory[$city]; } - if (empty($url) || false === ($metadata = ff_meta_getmetadata ($url))) { - return ''; + if (false === ($directory = ff_meta_getmetadata ( FF_META_DEFAULT_DIR )) + || empty($directory[$city])) { + return "\n"; + } + $url = $directory[$city]; + + if (false === ($metadata = ff_meta_getmetadata ($url))) { + return "\n"; } $outstr = "
Data from external URLs is cached for this number of minutes.
"; } -function ff_meta_url_callback() { - $url = get_option( 'ff_meta_url', FF_META_DEFAULT_URL ); - echo "" - ."This will be the default for all tags without url=\"xyz\" or city parameter.
"; +function ff_meta_city_callback() { + if (false === ($directory = ff_meta_getmetadata ( FF_META_DEFAULT_DIR ))) { + // TODO: error handling + return; + } + $default_city = get_option( 'ff_meta_city', FF_META_DEFAULT_CITY ); + + echo ""; + echo "This is the default city parameter.
"; } function ff_meta_options_page() {