mirror of
https://github.com/unraid/webgui.git
synced 2026-01-10 03:30:03 -06:00
Merge pull request #2139 from unraid/refactor/default-page-layout-content-output-abstraction
refactor: abstract main content logic into MainContent.php
This commit is contained in:
@@ -29,7 +29,7 @@ $alerts = '/tmp/plugins/my_alerts.txt';
|
||||
$wlan0 = file_exists('/sys/class/net/wlan0');
|
||||
|
||||
$safemode = _var($var,'safeMode')=='yes';
|
||||
$banner = "$config/plugins/dynamix/banner.png";
|
||||
$banner = "$config/webGui/banner.png";
|
||||
|
||||
$notes = '/var/tmp/unRAIDServer.txt';
|
||||
if (!file_exists($notes)) {
|
||||
@@ -71,20 +71,6 @@ if (count($pages)) {
|
||||
}
|
||||
if (count($running)) file_put_contents($nchan_pid,implode("\n",$running)."\n"); else @unlink($nchan_pid);
|
||||
}
|
||||
|
||||
function annotate($text)
|
||||
{
|
||||
echo "\n<!--\n",str_repeat("#", strlen($text)),"\n$text\n",str_repeat("#", strlen($text)),"\n-->\n";
|
||||
}
|
||||
|
||||
function generateReloadScript($loadMinutes)
|
||||
{
|
||||
if ($loadMinutes <= 0) {
|
||||
return '';
|
||||
}
|
||||
$interval = $loadMinutes * 60000;
|
||||
return "\n<script>timers.reload = setInterval(function(){if (nchanPaused === false)location.reload();},{$interval});</script>\n";
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html <?=$display['rtl']?>lang="<?=strtok($locale, '_') ?: 'en'?>" class="<?= $themeHelper->getThemeHtmlClass() ?>">
|
||||
@@ -108,7 +94,7 @@ function generateReloadScript($loadMinutes)
|
||||
<link type="text/css" rel="stylesheet" href="<?autov("/webGui/styles/default-color-palette.css")?>">
|
||||
<link type="text/css" rel="stylesheet" href="<?autov("/webGui/styles/default-base.css")?>">
|
||||
<link type="text/css" rel="stylesheet" href="<?autov("/webGui/styles/default-dynamix.css")?>">
|
||||
<link type="text/css" rel="stylesheet" href="<?autov("/plugins/dynamix/styles/dynamix-jquery-ui.css")?>">
|
||||
<link type="text/css" rel="stylesheet" href="<?autov("/webGui/styles/dynamix-jquery-ui.css")?>">
|
||||
<link type="text/css" rel="stylesheet" href="<?autov("/webGui/styles/themes/{$theme}.css")?>">
|
||||
|
||||
<style>
|
||||
@@ -140,103 +126,29 @@ if ($themeHelper->isSidebarTheme()) {
|
||||
<script src="<?autov('/webGui/javascript/dynamix.js')?>"></script>
|
||||
<script src="<?autov('/webGui/javascript/translate.'.($locale?:'en_US').'.js')?>"></script>
|
||||
|
||||
<?php require_once "$docroot/plugins/dynamix/include/DefaultPageLayout/HeadInlineJS.php"; ?>
|
||||
<? require_once "$docroot/webGui/include/DefaultPageLayout/HeadInlineJS.php"; ?>
|
||||
|
||||
<?php
|
||||
foreach ($buttonPages as $button) {
|
||||
annotate($button['file']);
|
||||
// include page specific stylesheets (if existing)
|
||||
$css = "/{$button['root']}/sheets/{$button['name']}";
|
||||
$css_stock = "$css.css";
|
||||
$css_theme = "$css-$theme.css"; // @todo add syslog for deprecation notice
|
||||
if (is_file($docroot.$css_stock)) {
|
||||
echo '<link type="text/css" rel="stylesheet" href="',autov($css_stock),'">',"\n";
|
||||
}
|
||||
if (is_file($docroot.$css_theme)) {
|
||||
echo '<link type="text/css" rel="stylesheet" href="',autov($css_theme),'">',"\n";
|
||||
}
|
||||
// create page content
|
||||
eval('?>'.parse_text($button['text']));
|
||||
annotate($button['file']);
|
||||
includePageStylesheets($button);
|
||||
eval('?>'.parse_text($button['text']));
|
||||
}
|
||||
|
||||
foreach ($pages as $page) {
|
||||
annotate($page['file']);
|
||||
includePageStylesheets($page);
|
||||
}
|
||||
?>
|
||||
|
||||
<?include "$docroot/plugins/dynamix.my.servers/include/myservers1.php"?>
|
||||
</head>
|
||||
<body>
|
||||
<div id="displaybox">
|
||||
|
||||
|
||||
<? include "$docroot/webGui/include/DefaultPageLayout/Header.php"; ?>
|
||||
<? include "$docroot/webGui/include/DefaultPageLayout/Navigation/Main.php"; ?>
|
||||
|
||||
<?
|
||||
// Build page content
|
||||
echo "<div class='tabs'>";
|
||||
$tab = 1;
|
||||
if (isset($myPage['Tabs'])) $display['tabs'] = strtolower($myPage['Tabs'])=='true' ? 0 : 1;
|
||||
$tabbed = $display['tabs']==0 && count($pages)>1;
|
||||
|
||||
foreach ($pages as $page) {
|
||||
$close = false;
|
||||
if (isset($page['Title'])) {
|
||||
eval("\$title=\"".htmlspecialchars($page['Title'])."\";");
|
||||
if ($tabbed) {
|
||||
echo "<div class='tab'><input type='radio' id='tab{$tab}' name='tabs' onclick='settab(this.id)'><label for='tab{$tab}'>";
|
||||
echo tab_title($title, $page['root'], _var($page, 'Tag', false));
|
||||
echo "</label><div class='content'>";
|
||||
$close = true;
|
||||
} else {
|
||||
if ($tab == 1) {
|
||||
echo "<div class='tab'><input type='radio' id='tab{$tab}' name='tabs'><div class='content shift'>";
|
||||
}
|
||||
echo "<div class='title'><span class='left'>";
|
||||
echo tab_title($title, $page['root'], _var($page, 'Tag', false));
|
||||
echo "</span></div>";
|
||||
}
|
||||
$tab++;
|
||||
}
|
||||
if (isset($page['Type']) && $page['Type'] == 'menu') {
|
||||
$pgs = find_pages($page['name']);
|
||||
foreach ($pgs as $pg) {
|
||||
@eval("\$title=\"".htmlspecialchars($pg['Title'])."\";");
|
||||
$icon = _var($pg, 'Icon', "<i class='icon-app PanelIcon'></i>");
|
||||
if (substr($icon, -4) == '.png') {
|
||||
$root = $pg['root'];
|
||||
if (file_exists("$docroot/$root/images/$icon")) {
|
||||
$icon = "<img src='/$root/images/$icon' class='PanelImg'>";
|
||||
} elseif (file_exists("$docroot/$root/$icon")) {
|
||||
$icon = "<img src='/$root/$icon' class='PanelImg'>";
|
||||
} else {
|
||||
$icon = "<i class='icon-app PanelIcon'></i>";
|
||||
}
|
||||
} elseif (substr($icon, 0, 5) == 'icon-') {
|
||||
$icon = "<i class='$icon PanelIcon'></i>";
|
||||
} elseif ($icon[0] != '<') {
|
||||
if (substr($icon, 0, 3) != 'fa-') {
|
||||
$icon = "fa-$icon";
|
||||
}
|
||||
$icon = "<i class='fa $icon PanelIcon'></i>";
|
||||
}
|
||||
echo "<div class=\"Panel\"><a href=\"/$path/{$pg['name']}\" onclick=\"$.cookie('one','tab1')\"><span>$icon</span><div class=\"PanelText\">"._($title)."</div></a></div>";
|
||||
}
|
||||
}
|
||||
annotate($page['file']);
|
||||
// include page specific stylesheets (if existing)
|
||||
$css = "/{$page['root']}/sheets/{$page['name']}";
|
||||
$css_stock = "$css.css";
|
||||
$css_theme = "$css-$theme.css";
|
||||
if (is_file($docroot.$css_stock)) echo '<link type="text/css" rel="stylesheet" href="',autov($css_stock),'">',"\n";
|
||||
if (is_file($docroot.$css_theme)) echo '<link type="text/css" rel="stylesheet" href="',autov($css_theme),'">',"\n";
|
||||
// create page content
|
||||
empty($page['Markdown']) || $page['Markdown']=='true' ? eval('?>'.Markdown(parse_text($page['text']))) : eval('?>'.parse_text($page['text']));
|
||||
if ($close) echo "</div></div>";
|
||||
}
|
||||
unset($pages,$page,$pgs,$pg,$icon,$nchan,$running,$start,$stop,$row,$script,$opt,$nchan_run);
|
||||
?>
|
||||
</div></div>
|
||||
|
||||
<? require_once "$docroot/webGui/include/DefaultPageLayout/Footer.php"; ?>
|
||||
<? require_once "$docroot/plugins/dynamix/include/DefaultPageLayout/MiscElements.php"; ?>
|
||||
<? require_once "$docroot/plugins/dynamix/include/DefaultPageLayout/BodyInlineJS.php"; ?>
|
||||
<? include "$docroot/webGui/include/DefaultPageLayout/MainContent.php"; ?>
|
||||
<? include "$docroot/webGui/include/DefaultPageLayout/Footer.php"; ?>
|
||||
<? include "$docroot/webGui/include/DefaultPageLayout/MiscElements.php"; ?>
|
||||
<? include "$docroot/webGui/include/DefaultPageLayout/BodyInlineJS.php"; ?>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
100
emhttp/plugins/dynamix/include/DefaultPageLayout/MainContent.php
Normal file
100
emhttp/plugins/dynamix/include/DefaultPageLayout/MainContent.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?
|
||||
/**
|
||||
* Main content template for the Unraid web interface.
|
||||
* Handles the rendering of tabs and page content.
|
||||
*/
|
||||
|
||||
$defaultIcon = "<i class=\"icon-app PanelIcon\"></i>";
|
||||
// Helper function to process icon
|
||||
function process_icon($icon, $docroot, $root) {
|
||||
global $defaultIcon;
|
||||
if (substr($icon, -4) == '.png') {
|
||||
if (file_exists("$docroot/$root/images/$icon")) {
|
||||
return "<img src=\"/$root/images/$icon\" class=\"PanelImg\">";
|
||||
} elseif (file_exists("$docroot/$root/$icon")) {
|
||||
return "<img src=\"/$root/$icon\" class=\"PanelImg\">";
|
||||
}
|
||||
return $defaultIcon;
|
||||
} elseif (substr($icon, 0, 5) == 'icon-') {
|
||||
return "<i class=\"$icon PanelIcon\"></i>";
|
||||
} elseif ($icon[0] != '<') {
|
||||
if (substr($icon, 0, 3) != 'fa-') {
|
||||
$icon = "fa-$icon";
|
||||
}
|
||||
return "<i class=\"fa $icon PanelIcon\"></i>";
|
||||
}
|
||||
return $icon;
|
||||
}
|
||||
|
||||
$tab = 1;
|
||||
// even if DisplaySettings is not enabled for tabs, pages with Tabs="true" will use tabs
|
||||
$display['tabs'] = isset($myPage['Tabs']) ? (strtolower($myPage['Tabs']) == 'true' ? 0 : 1) : 1;
|
||||
$tabbed = $display['tabs'] == 0 && count($pages) > 1;
|
||||
?>
|
||||
<div id="displaybox">
|
||||
<div class="tabs">
|
||||
<? foreach ($pages as $page):
|
||||
$close = false;
|
||||
if (isset($page['Title'])):
|
||||
$title = htmlspecialchars($page['Title']) ?? '';
|
||||
if ($tabbed): ?>
|
||||
<div class="tab">
|
||||
<input type="radio" id="tab<?= $tab ?>" name="tabs" onclick="settab(this.id)">
|
||||
<label for="tab<?= $tab ?>">
|
||||
<?= tab_title($title, $page['root'], _var($page, 'Tag', false)) ?>
|
||||
</label>
|
||||
<div class="content">
|
||||
<? $close = true;
|
||||
else:
|
||||
if ($tab == 1): ?>
|
||||
<div class="tab">
|
||||
<input type="radio" id="tab<?= $tab ?>" name="tabs">
|
||||
<div class="content shift">
|
||||
<? endif; ?>
|
||||
<div class="title">
|
||||
<span class="left">
|
||||
<?= tab_title($title, $page['root'], _var($page, 'Tag', false)) ?>
|
||||
</span>
|
||||
</div>
|
||||
<? endif;
|
||||
$tab++;
|
||||
endif;
|
||||
|
||||
// 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']); ?>
|
||||
<div class="Panel">
|
||||
<a href="/<?= $path ?>/<?= $pg['name'] ?>" onclick="$.cookie('one','tab1')">
|
||||
<span><?= $icon ?></span>
|
||||
<div class="PanelText"><?= _($title) ?></div>
|
||||
</a>
|
||||
</div>
|
||||
<? endforeach;
|
||||
endif;
|
||||
|
||||
// Annotate with HTML comment
|
||||
annotate($page['file']);
|
||||
|
||||
// Create page content
|
||||
if (empty($page['Markdown']) || $page['Markdown'] == 'true'):
|
||||
eval('?>'.Markdown(parse_text($page['text'])));
|
||||
else:
|
||||
eval('?>'.parse_text($page['text']));
|
||||
endif;
|
||||
|
||||
if ($close): ?>
|
||||
</div><!-- /.content -->
|
||||
</div><!-- /.tab -->
|
||||
<? endif;
|
||||
endforeach; ?>
|
||||
</div><!-- /.tabs -->
|
||||
</div><!-- /#displaybox -->
|
||||
<?
|
||||
// Clean up variables
|
||||
unset($pages, $page, $pgs, $pg, $icon, $nchan, $running, $start, $stop, $row, $script, $opt, $nchan_run);
|
||||
?>
|
||||
@@ -127,6 +127,19 @@ function generate_sidebar_icon_css($tasks, $buttons) {
|
||||
return $css;
|
||||
}
|
||||
|
||||
function includePageStylesheets($page) {
|
||||
global $docroot, $theme;
|
||||
$css = "/{$page['root']}/sheets/{$page['name']}";
|
||||
$css_stock = "$css.css";
|
||||
$css_theme = "$css-$theme.css"; // @todo add syslog for deprecation notice
|
||||
if (is_file($docroot.$css_stock)) echo '<link type="text/css" rel="stylesheet" href="',autov($css_stock),'">',"\n";
|
||||
if (is_file($docroot.$css_theme)) echo '<link type="text/css" rel="stylesheet" href="',autov($css_theme),'">',"\n";
|
||||
}
|
||||
|
||||
function annotate($text) {
|
||||
echo "\n<!--\n",str_repeat("#",strlen($text)),"\n$text\n",str_repeat("#",strlen($text)),"\n-->\n";
|
||||
}
|
||||
|
||||
// hack to embed function output in a quoted string (e.g., in a page Title)
|
||||
// see: http://stackoverflow.com/questions/6219972/why-embedding-functions-inside-of-strings-is-different-than-variables
|
||||
function _func($x) {return $x;}
|
||||
|
||||
Reference in New Issue
Block a user