diff --git a/freifunk_marker.png b/freifunk_marker.png new file mode 100644 index 0000000..279c962 Binary files /dev/null and b/freifunk_marker.png differ diff --git a/freifunkmeta.php b/freifunkmeta.php index 228e9f4..ece7799 100644 --- a/freifunkmeta.php +++ b/freifunkmeta.php @@ -35,6 +35,9 @@ if ( ! shortcode_exists( 'ff_services' ) ) { if ( ! shortcode_exists( 'ff_contact' ) ) { add_shortcode( 'ff_contact', 'ff_meta_shortcode_handler'); } +if ( ! shortcode_exists( 'ff_location' ) ) { + add_shortcode( 'ff_location', 'ff_meta_shortcode_handler'); +} // Example: // [ff_state] // [ff_state hamburg] @@ -63,6 +66,94 @@ function ff_meta_shortcode_handler( $atts, $content, $name ) { $outstr .= sprintf('%s', $state['nodes']); break; + case 'ff_location': + // normal per-city code + $loc = $metadata['location']; + $loc_name = (isset($loc['address']) && isset($loc['address']['Name'])) ? $loc['address']['Name'] : ''; + $loc_street = (isset($loc['address']) && isset($loc['address']['Street'])) ? $loc['address']['Street'] : ''; + $loc_zip = (isset($loc['address']) && isset($loc['address']['Zipcode'])) ? $loc['address']['Zipcode'] : ''; + $loc_city = isset($loc['city']) ? $loc['city'] : ''; + $loc_lon = isset($loc['lon']) ? $loc['lon'] : ''; + $loc_lat = isset($loc['lat']) ? $loc['lat'] : ''; + if (empty($loc_name) || empty($loc_street) || empty($loc_zip)) { + return ''; + } + + // TODO: style address + map as single box + // TODO: once it is "ready" package openlayers.js into the plugin (cf. http://docs.openlayers.org/library/deploying.html) + // TODO: handle missing values (i.e. only name & city) + $outstr .= '

'; + $outstr .= sprintf('%s
%s
%s %s', + $loc_name, $loc_street, $loc_zip, $loc_city); + $outstr .= '

'; + + // gather all location data + if ( false === ( $json_locs = get_transient( "ff_metadata_json_locs" ) ) ) { + $all_locs = array(); + $arr_select = array('lat' => 1, 'lon' => 1); + foreach ($directory as $tmp_city => $url) { + try { + $tmp_meta = ff_meta_getmetadata($url); + if (!empty($tmp_meta['location'])) { + $tmp_loc = array_intersect_key($tmp_meta['location'], $arr_select); + $all_locs[$tmp_city] = $tmp_loc; + } + } catch (Exception $e) { + // pass + } + } + $json_locs = json_encode($all_locs); + $cachetime = get_option( 'ff_meta_cachetime', FF_META_DEFAULT_CACHETIME) * MINUTE_IN_SECONDS; + set_transient( "ff_metadata_json_locs", $json_locs, $cachetime ); + } + + if ( !empty($loc_name) && !empty($loc_name) ) { + $icon_url = plugin_dir_url(__FILE__) . "freifunk_marker.png"; + $outstr .= << + + + + + +EOT; + } + break; + case 'ff_services': $outstr .= '