version 0.2

This commit is contained in:
info@mschuette.name 2014-04-08 11:15:20 +00:00
parent 079192e873
commit 6e8c360c1a
2 changed files with 60 additions and 15 deletions

View file

@ -1,4 +1,12 @@
freifunk-versions freifunk-versions
================= =================
Wordpress plugin to render latest gluon firmware version table Wordpress plugin to render latest (Hamburg-flavoured)
[gluon firmware](https://github.com/freifunkhamburg/gluon) version table.
Provides shortcode `[ff_hh_versions]` to display table.
Input data is read from http://gw09.hamburg.freifunk.net/stable/sysupgrade/manifest
Output looks like this:
![shortcode output example](http://mschuette.name/wp/wp-upload/freifunk_versions.png)

View file

@ -3,25 +3,32 @@
Plugin Name: Freifunk Hamburg Firmware List Shortcode Plugin Name: Freifunk Hamburg Firmware List Shortcode
Plugin URI: http://mschuette.name/ Plugin URI: http://mschuette.name/
Description: Defines shortcodes to display Freifunk Hamburg Firmware versions Description: Defines shortcodes to display Freifunk Hamburg Firmware versions
Version: 0.1 Version: 0.2
Author: Martin Schuette Author: Martin Schuette
Author URI: http://mschuette.name/ Author URI: http://mschuette.name/
Licence: 2-clause BSD Licence: 2-clause BSD
*/ */
define('FF_HH_STABLE_BASEDIR', 'http://gw09.hamburg.freifunk.net/stable/sysupgrade/'); define('FF_HH_STABLE_BASEDIR', 'http://gw09.hamburg.freifunk.net/stable/');
define('FF_HH_CACHETIME', 15); define('FF_HH_CACHETIME', 15);
/* gets metadata from URL, handles caching */ /* gets metadata from URL, handles caching */
function ff_hh_getmanifest () { function ff_hh_getmanifest ($basedir) {
// Caching // Caching
if ( false === ( $manifest = get_transient( "ff_hh_manifest" ) ) ) { if ( false === ( $manifest = get_transient( "ff_hh_manifest" ) ) ) {
$manifest = array(); $manifest = array();
$input = wp_remote_retrieve_body( wp_remote_get(FF_HH_STABLE_BASEDIR . 'manifest') ); $input = wp_remote_retrieve_body( wp_remote_get($basedir . 'sysupgrade/manifest') );
foreach ( explode("\n", $input) as $line ) { foreach ( explode("\n", $input) as $line ) {
$ret = sscanf($line, '%s %s %s %s', $hw, $ver, $hash, $filename); $ret = sscanf($line, '%s %s %s %s', $hw, $sw_ver, $hash, $filename);
if ($ret === 4) if ($ret === 4) {
$manifest[] = compact('hw', 'ver', 'filename'); if (preg_match('/^(.*)-v(\d+)$/', $hw, $matches)) {
$hw = $matches[1];
$hw_ver = $matches[2];
} else {
$hw_ver = '1';
}
$manifest[$hw][$hw_ver] = $filename;
}
} }
$cachetime = FF_HH_CACHETIME * MINUTE_IN_SECONDS; $cachetime = FF_HH_CACHETIME * MINUTE_IN_SECONDS;
@ -36,17 +43,46 @@ if ( ! shortcode_exists( 'ff_hh_versions' ) ) {
// Example: // Example:
// [ff_hh_versions] // [ff_hh_versions]
function ff_hh_shortcode_handler( $atts, $content, $name ) { function ff_hh_shortcode_handler( $atts, $content, $name ) {
$manifest = ff_hh_getmanifest(); $manifest = ff_hh_getmanifest(FF_HH_STABLE_BASEDIR);
$outstr = "<div class=\"ff $name\">";
$outstr .= '<table><tr><th>Modell</th><th>Stable</th></tr>';
foreach ($manifest as $line) { $outstr = "<div class=\"ff $name\">";
$outstr .= sprintf('<tr><td>%s</td><td><a href="%s%s">%s</a></td></tr>', $line['hw'], FF_HH_STABLE_BASEDIR, $line['filename'], $line['ver']); $outstr .= '<table><tr><th>Modell</th><th>Erstinstallation</th><th>Aktualisierung</th></tr>';
foreach ($manifest as $hw => $versions) {
// beautify HW model names
if (!strncmp($hw, 'tp-link', 7)) {
$hw = strtoupper($hw);
$hw = str_replace('-', ' ', $hw);
$hw = str_replace('TP LINK TL ', 'TP-Link TL-', $hw);
} elseif (!strncmp($hw, 'ubiquiti', 8)) {
$hw = str_replace('-', ' ', $hw);
$hw = ucwords($hw);
}
$outstr .= sprintf('<tr><td>%s</td>', $hw);
// factory versions
$hw_ver_links = array();
foreach ($versions as $hw_ver => $filename) {
$filename = str_replace('-sysupgrade', '', $filename);
$hw_ver_links[] = sprintf('<a href="%s%s">%s.x</a>',
FF_HH_STABLE_BASEDIR.'factory/', $filename, $hw_ver);
}
$outstr .= '<td>Hardware Version ' . join(', ', $hw_ver_links) . '</td>';
// sysupgrade versions
$hw_ver_links = array();
foreach ($versions as $hw_ver => $filename) {
$hw_ver_links[] = sprintf('<a href="%s%s">%s.x</a>',
FF_HH_STABLE_BASEDIR.'sysupgrade/', $filename, $hw_ver);
}
$outstr .= '<td>Hardware Version ' . join(', ', $hw_ver_links) . '</td>';
$outstr .= '</tr>';
} }
$outstr .= '</table>'; $outstr .= '</table>';
//$outstr .= '<pre>'.print_r($manifest, true).'</pre>';
$outstr .= '</div>'; $outstr .= '</div>';
// $outstr .= '<pre>'.print_r($manifest, true).'</pre>';
return $outstr; return $outstr;
} }
@ -55,3 +91,4 @@ function ff_hh_uninstall_hook() {
delete_option( 'ff_hh_manifest' ); delete_option( 'ff_hh_manifest' );
} }