\n"; } $url = $directory[$city]; if (false === ($metadata = ff_meta_getmetadata ($url))) { return "\n"; } $outstr = "
"; switch ($name) { case 'ff_state': $state = $metadata['state']; $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 .= ''; break; case 'ff_contact': $outstr .= '

'; $contact = $metadata['contact']; // Output -- rather ugly but the data is not uniform, some fields are URIs, some are usernames, ... if (!empty($contact['email'])) { $outstr .= sprintf("E-Mail: %s
\n", $contact['email'], $contact['email']); } if (!empty($contact['ml'])) { $outstr .= sprintf("Mailingliste: %s
\n", $contact['ml'], $contact['ml']); } if (!empty($contact['irc'])) { $outstr .= sprintf("IRC: %s
\n", $contact['irc'], $contact['irc']); } if (!empty($contact['twitter'])) { // catch username instead of URI if ($contact['twitter'][0] === "@") { $twitter_url = 'http://twitter.com/'.ltrim($contact['twitter'], "@"); $twitter_handle = $contact['twitter']; } else { $twitter_url = $contact['twitter']; $twitter_handle = '@' . substr($contact['twitter'], strrpos($contact['twitter'], '/') + 1); } $outstr .= sprintf("Twitter: %s
\n", $twitter_url, $twitter_handle); } if (!empty($contact['facebook'])) { $outstr .= sprintf("Facebook: %s
\n", $contact['facebook'], $contact['facebook']); } if (!empty($contact['googleplus'])) { $outstr .= sprintf("G+: %s
\n", $contact['googleplus'], $contact['googleplus']); } if (!empty($contact['jabber'])) { $outstr .= sprintf("XMPP: %s
\n", $contact['jabber'], $contact['jabber']); } $outstr .= '

'; break; default: return ""; break; } // Output $outstr .= ""; return $outstr; } // Options Page: add_action( 'admin_menu', 'ff_meta_admin_menu' ); function ff_meta_admin_menu() { add_options_page( 'FF Meta Plugin', // page title 'FF Meta', // menu title 'manage_options', // req'd capability 'ff_meta_plugin', // menu slug 'ff_meta_options_page' // callback function ); } add_action( 'admin_init', 'ff_meta_admin_init' ); function ff_meta_admin_init() { register_setting( 'ff_meta_settings-group', // group name 'ff_meta_cachetime' // option name ); register_setting( 'ff_meta_settings-group', // group name 'ff_meta_city' // option name ); add_settings_section( 'ff_meta_section-one', // ID 'Section One', // Title 'ff_meta_section_one_callback', // callback to fill 'ff_meta_plugin' // page to display on ); add_settings_field( 'ff_meta_city', // ID 'Default community', // Title 'ff_meta_city_callback', // callback to fill field 'ff_meta_plugin', // menu page=slug to display field on 'ff_meta_section-one', // section to display the field in array('label_for' => 'ff_meta_city_id') // ID of input element ); add_settings_field( 'ff_meta_cachetime', // ID 'Cache time', // Title 'ff_meta_cachetime_callback', // callback to fill field 'ff_meta_plugin', // menu page=slug to display field on 'ff_meta_section-one', // section to display the field in array('label_for' => 'ff_meta_cachetime_id') // ID of input element ); } function ff_meta_section_one_callback() { echo 'This Plugin provides shortcodes to display information from the Freifunk meta.json.'; } function ff_meta_cachetime_callback() { $time = get_option( 'ff_meta_cachetime', FF_META_DEFAULT_CACHETIME ); echo " minutes" ."

Data from external URLs is cached for this number of minutes.

"; } 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() { ?>

Freifunk Meta Plugin Options