mirror of
https://github.com/unraid/webgui.git
synced 2026-01-06 09:39:58 -06:00
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.
This commit is contained in:
@@ -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(
|
||||
'<div class="Panel">
|
||||
<a href="/%s/%s"%s>
|
||||
<span>%s</span>
|
||||
<div class="PanelText">%s</div>
|
||||
</a>
|
||||
</div>',
|
||||
$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:
|
||||
* <? eval('?>'.generateContent($page)); ?>
|
||||
*/
|
||||
function generateContent($page) {
|
||||
if (empty($page['Markdown']) || $page['Markdown'] == 'true') {
|
||||
return Markdown(parse_text($page['text']));
|
||||
}
|
||||
return parse_text($page['text']);
|
||||
}
|
||||
?>
|
||||
|
||||
<?php require_once __DIR__ . "/$contentInclude"; ?>
|
||||
<?php require_once __DIR__ . "/$contentInclude"; ?>
|
||||
|
||||
<?
|
||||
/**
|
||||
* Legacy carryover. Ideally wouldn't be needed.
|
||||
*/
|
||||
unset($pages, $page, $pgs, $pg, $icon, $nchan, $running, $start, $stop, $row, $script, $opt, $nchan_run);
|
||||
?>
|
||||
Reference in New Issue
Block a user