From 5d7f96e1b60bd05bdad8b77f92eed998d1e4279c Mon Sep 17 00:00:00 2001 From: "info@mschuette.name" Date: Wed, 2 Apr 2014 18:34:16 +0000 Subject: [PATCH] initial commit --- README.md | 9 +++ freifunkmeta.php | 158 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 167 insertions(+) create mode 100644 README.md create mode 100644 freifunkmeta.php diff --git a/README.md b/README.md new file mode 100644 index 0000000..d4b024f --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# Freifunk Metadata Wordpress Plugin + +A small Wordpress plugin to render Freifunk metadata. + +It reads (and caches) JSON input from a configured URL and provides shortcodes to output the data. + +Currently implemented are `[ff_services]` and `[ff_contact]`. + + diff --git a/freifunkmeta.php b/freifunkmeta.php new file mode 100644 index 0000000..e6d0f4e --- /dev/null +++ b/freifunkmeta.php @@ -0,0 +1,158 @@ + $default_url, + ), $atts)); + + $metadata = ff_meta_getmetadata ($url); + $services = $metadata['services']; + + // Output + $outstr = '
'; + return $outstr; +} + +if ( ! shortcode_exists( 'ff_contact' ) ) { + add_shortcode( 'ff_contact', 'ff_meta_shortcode_contact'); +} +// Example: +// [ff_contact] +// [ff_contact url="http://meta.hamburg.freifunk.net/ffhh.json"] +function ff_meta_shortcode_contact( $atts ) { + $default_url = get_option( 'ff_meta_url' ); + extract(shortcode_atts( array( + 'url' => $default_url, + ), $atts)); + + $metadata = ff_meta_getmetadata ($url); + $contact = $metadata['contact']; + + // Output -- rather ugly but the data is not uniform, some fields are URIs, some are usernames, ... + $outstr = '

'; + 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']); + } + # maybe we do not want public phone numbers... + #if (!empty($contact['phone'])) { + # $outstr .= sprintf("Telephon: %s
\n", $contact['phone']); + #} + $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_url' // 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_url', // ID + 'URL of meta.json', // Title + 'ff_meta_url_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 + ); +} + +function ff_meta_section_one_callback() { + echo 'This Plugin provides shortcodes to display information from the Freifunk meta.json.'; +} + +function ff_meta_url_callback() { + $url = get_option( 'ff_meta_url' ); + echo ""; +} + +function ff_meta_options_page() { + ?> +
+

Freifunk Meta Plugin Options

+
+ + + +
+
+