apply WP coding style
This commit is contained in:
parent
765dce0720
commit
7ed0325a9a
|
@ -15,7 +15,7 @@ define('FF_HH_CACHETIME', 15);
|
||||||
/* gets metadata from URL, handles caching */
|
/* gets metadata from URL, handles caching */
|
||||||
function ff_hh_getmanifest( $basedir ) {
|
function ff_hh_getmanifest( $basedir ) {
|
||||||
// Caching
|
// Caching
|
||||||
if ( WP_DEBUG || ( false === ( $manifest = get_transient( "ff_hh_manifest" ) ) ) ) {
|
if ( WP_DEBUG || ( false === ( $manifest = get_transient( 'ff_hh_manifest' ) ) ) ) {
|
||||||
$manifest = array();
|
$manifest = array();
|
||||||
$url = $basedir . 'sysupgrade/manifest';
|
$url = $basedir . 'sysupgrade/manifest';
|
||||||
$http_response = wp_remote_get( $url ); // TODO: error handling
|
$http_response = wp_remote_get( $url ); // TODO: error handling
|
||||||
|
@ -34,7 +34,7 @@ function ff_hh_getmanifest ($basedir) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$cachetime = FF_HH_CACHETIME * MINUTE_IN_SECONDS;
|
$cachetime = FF_HH_CACHETIME * MINUTE_IN_SECONDS;
|
||||||
set_transient( "ff_hh_manifest", $manifest, $cachetime );
|
set_transient( 'ff_hh_manifest', $manifest, $cachetime );
|
||||||
}
|
}
|
||||||
return $manifest;
|
return $manifest;
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ function ff_hh_getmanifest ($basedir) {
|
||||||
/* gets latest version from first manifest line */
|
/* gets latest version from first manifest line */
|
||||||
function ff_hh_getlatest( $basedir ) {
|
function ff_hh_getlatest( $basedir ) {
|
||||||
// Caching
|
// Caching
|
||||||
if ( false === ( $sw_ver = get_transient( "ff_hh_latestversion" ) ) ) {
|
if ( false === ( $sw_ver = get_transient( 'ff_hh_latestversion' ) ) ) {
|
||||||
$sw_ver = 'unknown';
|
$sw_ver = 'unknown';
|
||||||
$input = wp_remote_retrieve_body( wp_remote_get( $basedir . 'sysupgrade/manifest' ) );
|
$input = wp_remote_retrieve_body( wp_remote_get( $basedir . 'sysupgrade/manifest' ) );
|
||||||
foreach ( explode( "\n", $input ) as $line ) {
|
foreach ( explode( "\n", $input ) as $line ) {
|
||||||
|
@ -50,7 +50,7 @@ function ff_hh_getlatest ($basedir) {
|
||||||
if ( $ret === 4 ) {
|
if ( $ret === 4 ) {
|
||||||
// break processing on first matching line
|
// break processing on first matching line
|
||||||
$cachetime = FF_HH_CACHETIME * MINUTE_IN_SECONDS;
|
$cachetime = FF_HH_CACHETIME * MINUTE_IN_SECONDS;
|
||||||
set_transient( "ff_hh_latestversion", $sw_ver, $cachetime );
|
set_transient( 'ff_hh_latestversion', $sw_ver, $cachetime );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,16 +101,22 @@ function ff_hh_shortcode_versions( $atts, $content, $name ) {
|
||||||
$hw_ver_links = array();
|
$hw_ver_links = array();
|
||||||
foreach ( $versions as $hw_ver => $filename ) {
|
foreach ( $versions as $hw_ver => $filename ) {
|
||||||
$filename = str_replace( '-sysupgrade', '', $filename );
|
$filename = str_replace( '-sysupgrade', '', $filename );
|
||||||
$hw_ver_links[] = sprintf('<a href="%s%s">%s.x</a>',
|
$hw_ver_links[] = sprintf(
|
||||||
FF_HH_STABLE_BASEDIR.'factory/', $filename, $hw_ver);
|
'<a href="%s%s">%s.x</a>',
|
||||||
|
FF_HH_STABLE_BASEDIR.'factory/',
|
||||||
|
$filename, $hw_ver
|
||||||
|
);
|
||||||
}
|
}
|
||||||
$outstr .= '<td>Hardware Version ' . join( ', ', $hw_ver_links ) . '</td>';
|
$outstr .= '<td>Hardware Version ' . join( ', ', $hw_ver_links ) . '</td>';
|
||||||
|
|
||||||
// sysupgrade versions
|
// sysupgrade versions
|
||||||
$hw_ver_links = array();
|
$hw_ver_links = array();
|
||||||
foreach ( $versions as $hw_ver => $filename ) {
|
foreach ( $versions as $hw_ver => $filename ) {
|
||||||
$hw_ver_links[] = sprintf('<a href="%s%s">%s.x</a>',
|
$hw_ver_links[] = sprintf(
|
||||||
FF_HH_STABLE_BASEDIR.'sysupgrade/', $filename, $hw_ver);
|
'<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 .= '<td>Hardware Version ' . join( ', ', $hw_ver_links ) . '</td>';
|
||||||
|
|
||||||
|
@ -127,7 +133,7 @@ function ff_hh_shortcode_versions( $atts, $content, $name ) {
|
||||||
// hardware model name.
|
// hardware model name.
|
||||||
// set $discard_vendor to strip the vendor name
|
// set $discard_vendor to strip the vendor name
|
||||||
// (used for single-vendor lists, e.g. $discard_vendor = 'tp-link' )
|
// (used for single-vendor lists, e.g. $discard_vendor = 'tp-link' )
|
||||||
function ff_hh_beautify_hw_name($hw, $discard_vendor = "") {
|
function ff_hh_beautify_hw_name( $hw, $discard_vendor = '' ) {
|
||||||
if ( ! strncmp( $hw, 'tp-link', 7 ) ) {
|
if ( ! strncmp( $hw, 'tp-link', 7 ) ) {
|
||||||
if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
|
if ( $discard_vendor ) $hw = str_replace( $discard_vendor, '', $hw );
|
||||||
$hw = strtoupper( $hw );
|
$hw = strtoupper( $hw );
|
||||||
|
|
|
@ -15,7 +15,9 @@ class SimpleTests extends WP_UnitTestCase {
|
||||||
array( 'd-link-dir-615-rev-e1', 'd-link', 'DIR-615 rev e1' ),
|
array( 'd-link-dir-615-rev-e1', 'd-link', 'DIR-615 rev e1' ),
|
||||||
);
|
);
|
||||||
foreach ( $cmplist as $item ) {
|
foreach ( $cmplist as $item ) {
|
||||||
$this->assertEquals($item[2], trim(ff_hh_beautify_hw_name($item[0], $item[1])));
|
$expect = $item[2];
|
||||||
|
$result = ff_hh_beautify_hw_name( $item[0], $item[1] );
|
||||||
|
$this->assertEquals( $expect, trim( $result ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue