From ef325a6cf6ce582c18d892497f6ea72e117e7ab0 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Thu, 10 Dec 2015 19:09:43 +0545 Subject: Use the _title var to make the widget title Each widget has an include file that already has the required widget title in a var like $dyn_dns_status_title $carp_status_title etc. Use that var to set the displayed title of the widget, rather than the stuff that was capitalizing the file name and then having a list of special cases... This meant the loop that includes the widget include files had to be moved higher up in the code. --- src/usr/local/www/index.php | 69 +++++++++++++--------- src/usr/local/www/widgets/include/carp_status.inc | 2 +- .../local/www/widgets/include/dyn_dns_status.inc | 2 +- 3 files changed, 42 insertions(+), 31 deletions(-) diff --git a/src/usr/local/www/index.php b/src/usr/local/www/index.php index 7c943ff..d44b8f6 100644 --- a/src/usr/local/www/index.php +++ b/src/usr/local/www/index.php @@ -116,11 +116,40 @@ if ($g['disablecrashreporter'] != true) { } } +##build list of php include files +$phpincludefiles = array(); +$directory = "/usr/local/www/widgets/include/"; +$dirhandle = opendir($directory); +$filename = ""; + +while (false !== ($filename = readdir($dirhandle))) { + $phpincludefiles[] = $filename; +} + +## Include each widget include file. +## These define vars that specify the widget title and title link. +foreach ($phpincludefiles as $includename) { + if (!stristr($includename, ".inc")) { + continue; + } + if (file_exists($directory . $includename)) { + include($directory . $includename); + } +} + ##build list of widgets foreach (glob("/usr/local/www/widgets/widgets/*.widget.php") as $file) { $name = basename($file, '.widget.php'); - $widgets[ $name ] = array('name' => ucwords(str_replace('_', ' ', $name)), 'display' => 'none'); + // Get the widget title that should be in a var defined in the widget's inc file. + $widgettitle = ${$name . '_title'}; + + if ((strlen($widgettitle) == 0)) { + // Fall back to constructing a title from the file name of the widget. + $widgettitle = ucwords(str_replace('_', ' ', $name)); + } + + $widgets[ $name ] = array('name' => $widgettitle, 'display' => 'none'); } ##insert the system information widget as first, so as to be displayed first @@ -242,8 +271,16 @@ if ($config['widgets'] && $config['widgets']['sequence'] != "") { if (false !== $offset) $file = substr($file, 0, $offset); + // Get the widget title that should be in a var defined in the widget's inc file. + $widgettitle = ${$file . '_title'}; + + if ((strlen($widgettitle) == 0)) { + // Fall back to constructing a title from the file name of the widget. + $widgettitle = ucwords(str_replace('_', ' ', $file)); + } + $widgetsfromconfig[ $file ] = array( - 'name' => ucwords(str_replace('_', ' ', $file)), + 'name' => $widgettitle, 'col' => $col, 'display' => $display, ); @@ -260,32 +297,6 @@ if ($config['widgets'] && $config['widgets']['sequence'] != "") { } } -## Replace any known acronyms in widget names with suitable mixed-case forms -$input_acronyms = array("carp", "dns", "dyn dns", "gmirror", "ipsec", "ntp", "openvpn", "rss", "smart"); -$output_acronyms = array("CARP", "DNS", "Dynamic DNS", "gmirror", "IPsec", "NTP", "OpenVPN", "RSS", "SMART"); -foreach ($widgets as $widgetname => $widgetconfig) { - $widgets[$widgetname]['name'] = str_ireplace($input_acronyms, $output_acronyms, $widgetconfig['name']); -} - -##build list of php include files -$phpincludefiles = array(); -$directory = "/usr/local/www/widgets/include/"; -$dirhandle = opendir($directory); -$filename = ""; - -while (false !== ($filename = readdir($dirhandle))) { - $phpincludefiles[] = $filename; -} - -foreach ($phpincludefiles as $includename) { - if (!stristr($includename, ".inc")) { - continue; - } - if (file_exists($directory . $includename)) { - include($directory . $includename); - } -} - ## Set Page Title and Include Header $pgtitle = array(gettext("Status"), gettext("Dashboard")); include("head.inc"); @@ -379,7 +390,7 @@ foreach ($widgets as $widgetname => $widgetconfig) $widgetconfig): // Compose the widget title and include the title link if available - $widgetlink = ${str_replace(' ', '_', strtolower($widgetconfig['name'])) . '_title_link'}; + $widgetlink = ${$widgetname . '_title_link'}; if ((strlen($widgetlink) > 0)) { $wtitle = ' ' . $widgetconfig['name'] . ''; diff --git a/src/usr/local/www/widgets/include/carp_status.inc b/src/usr/local/www/widgets/include/carp_status.inc index 79d3c03..37334b0 100644 --- a/src/usr/local/www/widgets/include/carp_status.inc +++ b/src/usr/local/www/widgets/include/carp_status.inc @@ -1,7 +1,7 @@ diff --git a/src/usr/local/www/widgets/include/dyn_dns_status.inc b/src/usr/local/www/widgets/include/dyn_dns_status.inc index 8116fe7..b2588db 100644 --- a/src/usr/local/www/widgets/include/dyn_dns_status.inc +++ b/src/usr/local/www/widgets/include/dyn_dns_status.inc @@ -1,7 +1,7 @@ -- cgit v1.1