From ad9f54618c8884f68180703bd15d38d701639be6 Mon Sep 17 00:00:00 2001 From: Zack Spear Date: Wed, 7 May 2025 15:06:38 -0700 Subject: [PATCH] refactor: implement panel generation functions for menu pages - Added `generatePanel` and `generatePanels` functions to encapsulate panel creation logic for menu items. - Updated `MainContentNotab.php` and `MainContentTabbed.php` to utilize the new functions, improving code reusability and readability. - Introduced `generateContent` function to handle content generation based on Markdown flag. --- .../include/DefaultPageLayout/MainContent.php | 80 ++++++- .../DefaultPageLayout/MainContentNotab.php | 23 +- .../DefaultPageLayout/MainContentTabbed.php | 196 ++++++++---------- .../plugins/dynamix/styles/default-base.css | 10 +- 4 files changed, 178 insertions(+), 131 deletions(-) diff --git a/emhttp/plugins/dynamix/include/DefaultPageLayout/MainContent.php b/emhttp/plugins/dynamix/include/DefaultPageLayout/MainContent.php index a5505b624..e37d51073 100644 --- a/emhttp/plugins/dynamix/include/DefaultPageLayout/MainContent.php +++ b/emhttp/plugins/dynamix/include/DefaultPageLayout/MainContent.php @@ -32,6 +32,84 @@ function process_icon($icon, $docroot, $root) { } return $icon; } + +/** + * Generates a Panel DOM element for menu items + * + * @param array $pg Page data array containing name, Title, Icon + * @param string $path Current path + * @param string $defaultIcon Default icon to use if none specified + * @param string $docroot Document root path + * @param bool $useTabCookie Whether to add tab cookie onclick handler + * @return string HTML for the Panel element + */ +function generatePanel($pg, $path, $defaultIcon, $docroot, $useTabCookie = false) { + $panelTitle = htmlspecialchars($pg['Title']); + $icon = _var($pg, 'Icon', $defaultIcon); + $icon = process_icon($icon, $docroot, $pg['root']); + + $onclick = $useTabCookie ? ' onclick="$.cookie(\'one\',\'tab1\')"' : ''; + + return sprintf( + '
+ + %s +
%s
+
+
', + $path, + $pg['name'], + $onclick, + $icon, + _($panelTitle) + ); +} + +/** + * Generates all panels for a menu page + * + * @param array $page Page data array containing Type and name + * @param string $path Current path + * @param string $defaultIcon Default icon to use if none specified + * @param string $docroot Document root path + * @param bool $useTabCookie Whether to add tab cookie onclick handler + * @return string HTML for all panels or empty string if not a menu page + */ +function generatePanels($page, $path, $defaultIcon, $docroot, $useTabCookie = false) { + if (!isset($page['Type']) || $page['Type'] != 'menu') { + return ''; + } + + $output = ''; + $pgs = find_pages($page['name']); + foreach ($pgs as $pg) { + $output .= generatePanel($pg, $path, $defaultIcon, $docroot, $useTabCookie); + } + return $output; +} + +/** + * Generates the content for a page + * + * @param array $page Page data array containing text and Markdown flag + * @return string Parsed text ready for eval + * + * Usage example: + * '.generateContent($page)); ?> + */ +function generateContent($page) { + if (empty($page['Markdown']) || $page['Markdown'] == 'true') { + return Markdown(parse_text($page['text'])); + } + return parse_text($page['text']); +} ?> - \ No newline at end of file + + + \ No newline at end of file diff --git a/emhttp/plugins/dynamix/include/DefaultPageLayout/MainContentNotab.php b/emhttp/plugins/dynamix/include/DefaultPageLayout/MainContentNotab.php index 690b151da..d36f189e9 100644 --- a/emhttp/plugins/dynamix/include/DefaultPageLayout/MainContentNotab.php +++ b/emhttp/plugins/dynamix/include/DefaultPageLayout/MainContentNotab.php @@ -16,28 +16,9 @@ - - - - -
- - -
-
-
- - + - - '.Markdown(parse_text($page['text']))); ?> - - '.parse_text($page['text'])); ?> - + '.generateContent($page)); ?> diff --git a/emhttp/plugins/dynamix/include/DefaultPageLayout/MainContentTabbed.php b/emhttp/plugins/dynamix/include/DefaultPageLayout/MainContentTabbed.php index ecdcbfd64..28c3aa879 100644 --- a/emhttp/plugins/dynamix/include/DefaultPageLayout/MainContentTabbed.php +++ b/emhttp/plugins/dynamix/include/DefaultPageLayout/MainContentTabbed.php @@ -1,81 +1,65 @@ -
- - -
"; - } - } - annotate($page['file']); - // Handle menu type pages - if (isset($page['Type']) && $page['Type'] == 'menu'): - $pgs = find_pages($page['name']); - foreach ($pgs as $pg): - // Set title variable with proper escaping (suppress errors) - @$title = htmlspecialchars($pg['Title']); - $icon = _var($pg, 'Icon', $defaultIcon); - $icon = process_icon($icon, $docroot, $pg['root']); ?> -
- - -
-
-
- '.Markdown(parse_text($page['text']))); - } else { - eval('?>'.parse_text($page['text'])); - } - ?> - - + + + + + + + + + - \ No newline at end of file diff --git a/emhttp/plugins/dynamix/styles/default-base.css b/emhttp/plugins/dynamix/styles/default-base.css index 0fb7a996e..e8f253f2e 100644 --- a/emhttp/plugins/dynamix/styles/default-base.css +++ b/emhttp/plugins/dynamix/styles/default-base.css @@ -448,10 +448,11 @@ div.title { border-bottom: 1px solid var(--table-border-color); background-color: var(--title-header-background-color); letter-spacing: 1.8px; -} -div.title span.left { font-size: 1.4rem; } +/* div.title span.left { + font-size: 1.4rem; +} */ div.title span.right { font-size: 1.4rem; padding-top: 2px; @@ -1936,6 +1937,7 @@ span#wlan0 { div.title { color: var(--text-color); + font-size: 1.6rem; margin: 20px 0 10px 0; padding: 10px 0; clear: both; @@ -1943,10 +1945,10 @@ span#wlan0 { border-bottom: 1px solid var(--border-color); letter-spacing: 1.8px; } - div.title span.left { + /* div.title span.left { font-size: 1.6rem; text-transform: uppercase; - } + } */ div.title span.right { font-size: 1.6rem; padding-right: 10px;