add [ff_hh_latestversion]

This commit is contained in:
info@mschuette.name 2014-04-08 11:55:11 +00:00
parent 97809fa23d
commit 7db6688e3a

View file

@ -37,12 +37,41 @@ function ff_hh_getmanifest ($basedir) {
return $manifest;
}
/* gets latest version from first manifest line */
function ff_hh_getlatest ($basedir) {
// Caching
if ( false === ( $sw_ver = get_transient( "ff_hh_latestversion" ) ) ) {
$sw_ver = 'unknown';
$input = wp_remote_retrieve_body( wp_remote_get($basedir . 'sysupgrade/manifest') );
foreach ( explode("\n", $input) as $line ) {
$ret = sscanf($line, '%s %s %s %s', $hw, $sw_ver, $hash, $filename);
if ($ret === 4) {
// break processing on first matching line
$cachetime = FF_HH_CACHETIME * MINUTE_IN_SECONDS;
set_transient( "ff_hh_latestversion", $sw_ver, $cachetime );
break;
}
}
}
return $sw_ver;
}
if ( ! shortcode_exists( 'ff_hh_latestversion' ) ) {
add_shortcode( 'ff_hh_latestversion', 'ff_hh_shortcode_latestversion');
}
// Example:
// [ff_hh_latestversion]
function ff_hh_shortcode_latestversion( $atts, $content, $name ) {
$sw_ver = ff_hh_getlatest(FF_HH_STABLE_BASEDIR);
$outstr = "<span class=\"ff $name\">$sw_ver</span>";
return $outstr;
}
if ( ! shortcode_exists( 'ff_hh_versions' ) ) {
add_shortcode( 'ff_hh_versions', 'ff_hh_shortcode_handler');
add_shortcode( 'ff_hh_versions', 'ff_hh_shortcode_versions');
}
// Example:
// [ff_hh_versions]
function ff_hh_shortcode_handler( $atts, $content, $name ) {
function ff_hh_shortcode_versions( $atts, $content, $name ) {
$manifest = ff_hh_getmanifest(FF_HH_STABLE_BASEDIR);
$outstr = "<div class=\"ff $name\">";