add grep argument for multiple tables

This commit is contained in:
Martin Schuette 2014-05-25 20:06:18 +00:00
parent b3101f0dd5
commit c5b3ccf3eb
2 changed files with 29 additions and 1 deletions

View file

@ -10,3 +10,15 @@ Input data is read from http://gw09.hamburg.freifunk.net/stable/sysupgrade/manif
Output looks like this: Output looks like this:
![shortcode output example](http://mschuette.name/wp/wp-upload/freifunk_versions.png) ![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"]
```

View file

@ -71,25 +71,41 @@ if ( ! shortcode_exists( 'ff_hh_versions' ) ) {
} }
// Example: // Example:
// [ff_hh_versions] // [ff_hh_versions]
// [ff_hh_versions grep="ubiquiti"]
function ff_hh_shortcode_versions( $atts, $content, $name ) { function ff_hh_shortcode_versions( $atts, $content, $name ) {
$manifest = ff_hh_getmanifest(FF_HH_STABLE_BASEDIR); $manifest = ff_hh_getmanifest(FF_HH_STABLE_BASEDIR);
$outstr = "<div class=\"ff $name\">"; $outstr = "<div class=\"ff $name\">";
$outstr .= '<table><tr><th>Modell</th><th>Erstinstallation</th><th>Aktualisierung</th></tr>'; $outstr .= '<table><tr><th>Modell</th><th>Erstinstallation</th><th>Aktualisierung</th></tr>';
# 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) { foreach ($manifest as $hw => $versions) {
// filter
if ($grep && (false === strpos($hw, $grep))) {
continue;
}
// beautify HW model names // beautify HW model names
if (!strncmp($hw, 'tp-link', 7)) { if (!strncmp($hw, 'tp-link', 7)) {
if ($grep) $hw = str_replace($grep, '', $hw);
$hw = strtoupper($hw); $hw = strtoupper($hw);
$hw = str_replace('-', ' ', $hw); $hw = str_replace('-', ' ', $hw);
$hw = str_replace('TP LINK TL ', 'TP-Link TL-', $hw); $hw = str_replace('TP LINK TL ', 'TP-Link TL-', $hw);
} elseif (!strncmp($hw, 'ubiquiti', 8)) { } 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('ubiquiti-bullet-m', 'ubiquiti-bullet-m / nanostation-loco-m', $hw);
$hw = str_replace('-m', ' M2', $hw); $hw = str_replace('-m', ' M2', $hw);
$hw = str_replace('-', ' ', $hw); $hw = str_replace('-', ' ', $hw);
$hw = ucwords($hw); $hw = ucwords($hw);
} }
$outstr .= sprintf('<tr><td>%s</td>', $hw); $outstr .= sprintf("\n<tr><td>%s</td>", $hw);
// factory versions // factory versions
$hw_ver_links = array(); $hw_ver_links = array();