From 18495dbbc344133736bfe732c7bec71bd67fc461 Mon Sep 17 00:00:00 2001 From: Martin Schuette Date: Sun, 29 Jun 2014 17:58:01 +0000 Subject: [PATCH] extra function ff_hh_beautify_hw_name --- freifunk-versions.php | 47 ++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/freifunk-versions.php b/freifunk-versions.php index 7b5e567..da0b8a9 100644 --- a/freifunk-versions.php +++ b/freifunk-versions.php @@ -3,7 +3,7 @@ Plugin Name: Freifunk Hamburg Firmware List Shortcode Plugin URI: http://mschuette.name/ Description: Defines shortcodes to display Freifunk Hamburg Firmware versions -Version: 0.4 +Version: 0.4dev Author: Martin Schuette Author URI: http://mschuette.name/ Licence: 2-clause BSD @@ -94,23 +94,7 @@ function ff_hh_shortcode_versions( $atts, $content, $name ) { 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('bullet-m', 'bullet-m / nanostation-loco-m', $hw); - $hw = str_replace('-m', ' M2', $hw); - $hw = str_replace('-', ' ', $hw); - $hw = ucwords($hw); - } elseif (!strncmp($hw, 'd-link', 6)) { - if ($grep) $hw = str_replace($grep, '', $hw); - $hw = str_replace('-', ' ', $hw); - $hw = str_replace('d link dir ', 'D-Link DIR-', $hw); - } + $hw = ff_hh_beautify_hw_name($hw, $grep); $outstr .= sprintf("\n%s", $hw); // factory versions @@ -138,3 +122,30 @@ function ff_hh_shortcode_versions( $atts, $content, $name ) { // $outstr .= '
'.print_r($manifest, true).'
'; return $outstr; } + +// some crude rules to add capitalization and whitespace to the +// hardware model name. +// set $discard_vendor to strip the vendor name +// (used for single-vendor lists, e.g. $discard_vendor = 'tp-link') +function ff_hh_beautify_hw_name($hw, $discard_vendor = "") { + if (!strncmp($hw, 'tp-link', 7)) { + if ($discard_vendor) $hw = str_replace($discard_vendor, '', $hw); + $hw = strtoupper($hw); + $hw = str_replace('-', ' ', $hw); + $hw = str_replace('TP LINK ', 'TP-Link ', $hw); + $hw = str_replace(' TL ', ' TL-', $hw); + } elseif (!strncmp($hw, 'ubiquiti', 8)) { + if ($discard_vendor) $hw = str_replace($discard_vendor, '', $hw); + $hw = str_replace('bullet-m', 'bullet-m / nanostation-loco-m', $hw); + $hw = str_replace('-m', ' M2', $hw); + $hw = str_replace('-', ' ', $hw); + $hw = ucwords($hw); + } elseif (!strncmp($hw, 'd-link', 6)) { + if ($discard_vendor) $hw = str_replace($discard_vendor, '', $hw); + $hw = str_replace('-', ' ', $hw); + $hw = str_replace('d link ', 'D-Link ', $hw); + $hw = str_replace(' dir ', ' DIR-', $hw); + } + return $hw; +} +