From 4788e5616cbc0cbaaf147f2854e69d3ebd65f5a4 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Mon, 7 Dec 2015 18:15:32 +0100 Subject: [PATCH] www: introduce automatic breadcrumbs This way, every time we touch our Menu.xml the page's breadcrumbs are automatically switched. :) While there, clean the old $pgtitle setup so all of them translate properly. They are still used for the menu bar title, that will require more effort to unfold. Stay tuned. @adschellevis if this is not the correct way to do it feel free to refactor the MVC parts. --- .../models/OPNsense/Base/Menu/MenuSystem.php | 26 +++++++ src/pkg/miniupnpd.xml | 1 - src/www/diag_limiter_info.php | 2 +- src/www/diag_logs_ppp.php | 1 - src/www/diag_pf_info.php | 3 +- src/www/diag_system_activity.php | 2 +- src/www/diag_system_pftop.php | 2 +- src/www/fbegin.inc | 3 +- src/www/guiconfig.inc | 19 +++-- src/www/head.inc | 2 +- src/www/services_upnp.php | 71 +------------------ 11 files changed, 48 insertions(+), 84 deletions(-) diff --git a/src/opnsense/mvc/app/models/OPNsense/Base/Menu/MenuSystem.php b/src/opnsense/mvc/app/models/OPNsense/Base/Menu/MenuSystem.php index 8b0a61dd1..5196881a3 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Base/Menu/MenuSystem.php +++ b/src/opnsense/mvc/app/models/OPNsense/Base/Menu/MenuSystem.php @@ -1,4 +1,5 @@ root->getChildren(); + $breadcrumbs = array(); + + while ($nodes != null) { + $next = null; + foreach ($nodes as $node) { + if ($node->Selected) { + $breadcrumbs[] = array('name' => $node->VisibleName); + /* only go as far as the first reachable URL */ + $next = empty($node->Url) ? $node->Children : null; + break; + } + } + $nodes = $next; + } + + return $breadcrumbs; + } } diff --git a/src/pkg/miniupnpd.xml b/src/pkg/miniupnpd.xml index 2737f9191..d1f370ec7 100644 --- a/src/pkg/miniupnpd.xml +++ b/src/pkg/miniupnpd.xml @@ -1,6 +1,5 @@ - Services: Universal Plug and Play: Settings miniupnpd 20100712 diff --git a/src/www/diag_limiter_info.php b/src/www/diag_limiter_info.php index f377f450b..04b79f8ab 100644 --- a/src/www/diag_limiter_info.php +++ b/src/www/diag_limiter_info.php @@ -28,7 +28,7 @@ require_once("guiconfig.inc"); -$pgtitle = gettext("Diagnostics: Limiter Info"); +$pgtitle = array(gettext('Diagnostics'), gettext('Limiter Info')); $shortcut_section = "trafficshaper-limiters"; if(isset($_POST['getactivity'])) { diff --git a/src/www/diag_logs_ppp.php b/src/www/diag_logs_ppp.php index fdf5e40ed..fd15d31ae 100644 --- a/src/www/diag_logs_ppp.php +++ b/src/www/diag_logs_ppp.php @@ -48,7 +48,6 @@ if (isset($_POST['filtertext'])) { $filtertext = htmlspecialchars($_POST['filtertext']); } -$pgtitle = array(gettext("Status"),gettext("System logs"),gettext("PPP")); include("head.inc"); ?> diff --git a/src/www/diag_pf_info.php b/src/www/diag_pf_info.php index f15b6490f..00c1c9ab4 100644 --- a/src/www/diag_pf_info.php +++ b/src/www/diag_pf_info.php @@ -1,4 +1,5 @@ diff --git a/src/www/fbegin.inc b/src/www/fbegin.inc index 5648f4e75..21e18f2ec 100644 --- a/src/www/fbegin.inc +++ b/src/www/fbegin.inc @@ -87,6 +87,7 @@ foreach ($ifarr as $key => $descr) { } unset($ifarr); $menuSystem = $menu->getItems($_SERVER['REQUEST_URI']); +$menuBreadcrumbs = $menu->getBreadcrumbs(); $aclObj = new \OPNsense\Core\ACL(); @@ -223,7 +224,7 @@ if($need_alert_display == true) {
    -
  • +
  • diff --git a/src/www/guiconfig.inc b/src/www/guiconfig.inc index 6fafeb524..a5e5fa2c0 100644 --- a/src/www/guiconfig.inc +++ b/src/www/guiconfig.inc @@ -297,12 +297,19 @@ function pprint_port($port) { return $pport; } -function gentitle($title) { - $navlevelsep = ": "; /* navigation level separator string */ - if(!is_array($title)) - return $title; - else - return join($navlevelsep, $title); +function gentitle($breadcrumbs) +{ + $navlevelsep = ': '; + $output = $breadcrumbs; + + if (isset($breadcrumbs[0]['name'])) { + $output = array(); + foreach ($breadcrumbs as $crumb) { + $output[] = gettext($crumb['name']); + } + } + + return join($navlevelsep, $output); } function clear_log($logfile, $restart_syslogd = true) diff --git a/src/www/head.inc b/src/www/head.inc index cbf77f72a..b88f19417 100644 --- a/src/www/head.inc +++ b/src/www/head.inc @@ -16,7 +16,7 @@ function system_get_language_code() { $g['theme'] = get_current_theme(); -$pagetitle = gentitle( $pgtitle ); +$pagetitle = gentitle( $pgtitle ); /* XXX zap me */ ?> diff --git a/src/www/services_upnp.php b/src/www/services_upnp.php index 270a2dbd3..acbfa0baf 100644 --- a/src/www/services_upnp.php +++ b/src/www/services_upnp.php @@ -137,9 +137,7 @@ global $listtags; $listtags = array_flip(array('build_port_path', 'onetoone', 'queue', 'rule', 'servernat', 'alias', 'additional_files_needed', 'tab', 'menu', 'rowhelperfield', 'service', 'step', 'package', 'columnitem', 'option', 'item', 'field', 'package', 'file')); $pkg = parse_xml_config_raw('/usr/local/pkg/miniupnpd.xml', 'packagegui', false); -$name = $pkg['name']; -$title = $pkg['title']; -$pgtitle = $title; +$pgtitle = array(gettext('Services'), gettext('Universal Plug and Play'), gettext('Settings')); if($config['installedpackages'] && !is_array($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'])) $config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'] = array(); @@ -513,73 +511,6 @@ include("head.inc"); \n"; - switch($type){ - case "input": - echo "\n"; - break; - case "checkbox": - echo "\n"; - break; - case "password": - echo "\n"; - break; - case "textarea": - echo "\n"; - case "select": - echo "\n"; - break; - case "interfaces_selection": - $size = ($size ? "size=\"{$size}\"" : ''); - $multiple = ''; - if (isset($rowhelper['multiple'])) { - $fieldname .= '[]'; - $multiple = "multiple=\"multiple\""; - } - echo "\n"; - break; - case "select_source": - echo "\n"; - break; - } - echo "\n"; -} function fixup_string($string) { global $config;