diff options
author | Phil Davis <phil.davis@inf.org> | 2015-12-10 19:09:43 +0545 |
---|---|---|
committer | Phil Davis <phil.davis@inf.org> | 2015-12-10 19:09:43 +0545 |
commit | ef325a6cf6ce582c18d892497f6ea72e117e7ab0 (patch) | |
tree | 37d0c7e334b90e4737323c969888d1eae12e2a43 /src | |
parent | c0499d48618013412a4b2ace07b04dde7a0df955 (diff) | |
download | pfsense-ef325a6cf6ce582c18d892497f6ea72e117e7ab0.zip pfsense-ef325a6cf6ce582c18d892497f6ea72e117e7ab0.tar.gz |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/usr/local/www/index.php | 69 | ||||
-rw-r--r-- | src/usr/local/www/widgets/include/carp_status.inc | 2 | ||||
-rw-r--r-- | src/usr/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) <?php foreach ($columnWidgets as $widgetname => $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 = '<a href="' . $widgetlink . '"> ' . $widgetconfig['name'] . '</a>'; 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 @@ <?php //set variable for custom title -$carp_status_title = "Carp Status"; +$carp_status_title = "CARP Status"; $carp_status_title_link = "carp_status.php"; ?> 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 @@ <?php //set variable for custom title -$dyn_dns_status_title = "Dyn DNS Status"; +$dyn_dns_status_title = "Dynamic DNS Status"; $dyn_dns_status_title_link = "services_dyndns.php"; ?> |