Add navigation tabs to cPanel plugin navbar

Adds "Select Source" and "Restore" links to match the WHM navbar style.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
shuki
2026-03-05 19:27:34 +02:00
parent a5ab2c788a
commit b1c475da00

View File

@@ -8,6 +8,12 @@ use Fcntl qw(:DEFAULT);
my $CSS_FILE = '/usr/local/cpanel/base/frontend/jupiter/gniza/assets/gniza-whm.css'; my $CSS_FILE = '/usr/local/cpanel/base/frontend/jupiter/gniza/assets/gniza-whm.css';
my $LOGO_FILE = '/usr/local/cpanel/base/frontend/jupiter/gniza/assets/gniza-logo.svg'; my $LOGO_FILE = '/usr/local/cpanel/base/frontend/jupiter/gniza/assets/gniza-logo.svg';
my $_logo_data_uri = '';
my @NAV_ITEMS = (
{ url => 'index.live.cgi', label => 'Select Source' },
{ url => 'restore.live.cgi', label => 'Restore' },
);
# ── HTML Escaping ───────────────────────────────────────────── # ── HTML Escaping ─────────────────────────────────────────────
@@ -22,6 +28,45 @@ sub esc {
return $str; return $str;
} }
# ── Navigation ────────────────────────────────────────────────
sub render_nav {
my ($current_page) = @_;
my $logo = '';
if ($_logo_data_uri) {
$logo = qq{<div class="flex items-center gap-2">}
. qq{<img src="$_logo_data_uri" alt="" class="h-12 w-auto">}
. qq{<span class="text-3xl font-bold leading-none">GNIZA <span class="text-secondary">Backup</span></span>}
. qq{</div>};
}
my $menu_items = '';
for my $item (@NAV_ITEMS) {
my $active = ($item->{url} eq $current_page) ? ' active' : '';
my $label = esc($item->{label});
$menu_items .= qq{<li><a class="no-underline$active" href="$item->{url}">$label</a></li>\n};
}
my $html = qq{<div class="navbar bg-base-200 rounded-box mb-5">\n};
$html .= qq{ <div class="navbar-start">\n};
$html .= qq{ $logo\n} if $logo;
$html .= qq{ </div>\n};
$html .= qq{ <div class="navbar-end hidden lg:flex">\n};
$html .= qq{ <ul class="menu menu-horizontal gap-1">\n};
$html .= qq{ $menu_items};
$html .= qq{ </ul>\n};
$html .= qq{ </div>\n};
$html .= qq{ <div class="navbar-end lg:hidden">\n};
$html .= qq{ <details class="dropdown dropdown-end">\n};
$html .= qq{ <summary class="btn btn-ghost btn-sm"><svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" /></svg></summary>\n};
$html .= qq{ <ul class="dropdown-content menu bg-base-200 rounded-box shadow-sm mt-2 w-52 p-2">\n};
$html .= qq{ $menu_items};
$html .= qq{ </ul>\n};
$html .= qq{ </details>\n};
$html .= qq{ </div>\n};
$html .= qq{</div>\n};
return $html;
}
# ── Current User ───────────────────────────────────────────── # ── Current User ─────────────────────────────────────────────
sub get_current_user { sub get_current_user {
@@ -180,20 +225,17 @@ sub page_header {
$css = _unwrap_layers($css); $css = _unwrap_layers($css);
$css = _scope_to_container($css); $css = _scope_to_container($css);
# Inline logo as base64 data URI # Pre-compute logo data URI for render_nav()
my $logo_html = ''; if (!$_logo_data_uri && open my $lfh, '<', $LOGO_FILE) {
if (open my $lfh, '<', $LOGO_FILE) {
local $/; local $/;
my $svg_data = <$lfh>; my $svg_data = <$lfh>;
close $lfh; close $lfh;
require MIME::Base64; require MIME::Base64;
my $b64 = MIME::Base64::encode_base64($svg_data, ''); $_logo_data_uri = 'data:image/svg+xml;base64,' . MIME::Base64::encode_base64($svg_data, '');
$logo_html = qq{<div class="flex items-center justify-center gap-3 mb-4"><img src="data:image/svg+xml;base64,$b64" alt="gniza" style="height:40px;width:auto"></div>\n};
} }
return qq{<style>$css</style>\n} return qq{<style>$css</style>\n}
. qq{<div data-theme="gniza" class="font-sans text-base" style="padding:20px 10px 10px 10px">\n} . qq{<div data-theme="gniza" class="font-sans text-base" style="padding:20px 10px 10px 10px">\n};
. $logo_html;
} }
sub page_footer { sub page_footer {