diff --git a/README.md b/README.md index 0e419f9..065ece7 100644 --- a/README.md +++ b/README.md @@ -10,3 +10,15 @@ Input data is read from http://gw09.hamburg.freifunk.net/stable/sysupgrade/manif Output looks like this: ![shortcode output example](http://mschuette.name/wp/wp-upload/freifunk_versions.png) + +Arguments +--------- +An optional argument `grep` allows you show a subset of hardware versions, +Example: + +``` + TP-Link Firmware: [ff_hh_versions grep="tp-link"] + + Ubiquiti Firmware: [ff_hh_versions grep="ubiquiti"] +``` + diff --git a/freifunk-versions.php b/freifunk-versions.php index b79c7f3..b942e72 100644 --- a/freifunk-versions.php +++ b/freifunk-versions.php @@ -71,25 +71,41 @@ if ( ! shortcode_exists( 'ff_hh_versions' ) ) { } // Example: // [ff_hh_versions] +// [ff_hh_versions grep="ubiquiti"] function ff_hh_shortcode_versions( $atts, $content, $name ) { $manifest = ff_hh_getmanifest(FF_HH_STABLE_BASEDIR); $outstr = "
"; $outstr .= ''; + # optionally filter output by given substring + if (is_array($atts) + && array_key_exists('grep', $atts) + && !empty($atts['grep'])) { + $grep = $atts['grep']; + } else { + $grep = false; + } + foreach ($manifest as $hw => $versions) { + // filter + if ($grep && (false === strpos($hw, $grep))) { + continue; + } // beautify HW model names if (!strncmp($hw, 'tp-link', 7)) { + if ($grep) $hw = str_replace($grep, '', $hw); $hw = strtoupper($hw); $hw = str_replace('-', ' ', $hw); $hw = str_replace('TP LINK TL ', 'TP-Link TL-', $hw); } elseif (!strncmp($hw, 'ubiquiti', 8)) { + if ($grep) $hw = str_replace($grep, '', $hw); $hw = str_replace('ubiquiti-bullet-m', 'ubiquiti-bullet-m / nanostation-loco-m', $hw); $hw = str_replace('-m', ' M2', $hw); $hw = str_replace('-', ' ', $hw); $hw = ucwords($hw); } - $outstr .= sprintf('', $hw); + $outstr .= sprintf("\n", $hw); // factory versions $hw_ver_links = array();
ModellErstinstallationAktualisierung
%s
%s