allow city name instead of url="xyz"

This commit is contained in:
Martin Schuette 2014-04-03 22:31:01 +00:00
parent df93dd00ab
commit f69ab834c0
2 changed files with 13 additions and 2 deletions

View file

@ -20,7 +20,7 @@ Text:
Contact Jena: Contact Jena:
[ff_contact url="http://freifunk-jena.de/jena.json"] [ff_contact jena]
Output: Output:

View file

@ -33,6 +33,7 @@ if ( ! shortcode_exists( 'ff_contact' ) ) {
} }
// Example: // Example:
// [ff_state] // [ff_state]
// [ff_state hamburg]
// [ff_state url="http://meta.hamburg.freifunk.net/ffhh.json"] // [ff_state url="http://meta.hamburg.freifunk.net/ffhh.json"]
function ff_meta_shortcode_handler( $atts, $content, $name ) { function ff_meta_shortcode_handler( $atts, $content, $name ) {
$default_url = get_option( 'ff_meta_url' ); $default_url = get_option( 'ff_meta_url' );
@ -40,6 +41,16 @@ function ff_meta_shortcode_handler( $atts, $content, $name ) {
'url' => $default_url, 'url' => $default_url,
), $atts)); ), $atts));
// check for city name
if (!empty($atts[0])) {
$city = $atts[0];
if (false === ($directory = ff_meta_getmetadata (get_option( 'ff_meta_dir' )))
|| empty($directory[$city])) {
return '';
}
$url = $directory[$city];
}
if (empty($url) || false === ($metadata = ff_meta_getmetadata ($url))) { if (empty($url) || false === ($metadata = ff_meta_getmetadata ($url))) {
return ''; return '';
} }
@ -195,7 +206,7 @@ function ff_meta_url_callback() {
$url = "http://meta.hamburg.freifunk.net/ffhh.json"; $url = "http://meta.hamburg.freifunk.net/ffhh.json";
} }
echo "<input type='text' name='ff_meta_url' id='ff_meta_url_id' class='large-text code' value='$url' />" echo "<input type='text' name='ff_meta_url' id='ff_meta_url_id' class='large-text code' value='$url' />"
."<p class='description'>This will be the default for all tags without url=\"xyz\" parameter.</p>"; ."<p class='description'>This will be the default for all tags without url=\"xyz\" or city parameter.</p>";
} }
function ff_meta_options_page() { function ff_meta_options_page() {