NewHome/admin/_guard.php

76 lines
3.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* admin/_guard.php —— 后台鉴权守卫 + 公共侧边栏(所有后台页面在 $P='../' 定义后 require
*/
$P = $P ?? '../';
require_once dirname(__DIR__) . '/includes/auth.php';
require_once dirname(__DIR__) . '/includes/layout.php';
require_login('login.php');
// 未修改初始/重置密码前,禁止进入其它后台页面(避免绕过强制改密)
if (hp_password_needs_change()) {
$self = basename((string) ($_SERVER['SCRIPT_NAME'] ?? ''));
if ($self !== 'force_password.php') {
header('Location: force_password.php');
exit;
}
}
/** 后台侧边栏(原顶部分区栏改为可收缩侧栏;含“本页功能”锚点容器) */
function admin_topbar(string $active = ''): void
{
global $P;
$site = setting_get('site_name', 'SecHome');
$admin = (string) ($_SESSION['admin'] ?? '');
// 立即执行:标记 body 供侧栏布局使用,并恢复折叠状态(避免首帧闪动)
echo '<script>(function(){var b=document.body;if(!b)return;b.classList.add("hp-admin-side");try{if(localStorage.getItem("hp-admin-side-collapsed")==="1")b.classList.add("hp-side-collapsed");}catch(e){}})();</script>' . "\n";
// 小屏顶部条(仅移动端显示:菜单按钮 + 站名 + 退出)
echo '<div class="admin-mobilebar">';
echo '<button type="button" class="amb-btn js-admin-side-toggle" title="展开 / 收起菜单" aria-label="展开或收起菜单">☰</button>';
echo '<a class="amb-brand" href="../index.php" title="查看前台首页">';
layout_logo_img('amb-logo', $site);
echo '<span>' . he($site) . ' · 后台</span></a>';
echo '<a class="amb-out" href="logout.php">退出</a>';
echo '</div>' . "\n";
echo '<aside class="admin-side" id="adminSide">';
// 品牌区 + 折叠按钮
echo '<div class="as-head">';
echo '<a class="as-brand" href="../index.php" title="查看前台首页">';
layout_logo_img('as-logo', $site);
echo '<span class="as-brand-tx">' . he($site) . '<em>后台管理</em></span></a>';
echo '<button type="button" class="as-toggle js-admin-side-toggle" title="收起 / 展开侧栏" aria-label="收起或展开侧栏"><span class="as-toggle-ic">«</span></button>';
echo '</div>';
// 主导航
$links = [
'nav' => ['nav.php', '导航管理', '🗂'],
'tools' => ['tools.php', '内部功能', '🧰'],
'articles' => ['articles.php', '文章管理', '📄'],
'exttools' => ['exttools.php', '外部工具', '🔗'],
'content' => ['content.php', '网站管理', '⚙'],
'notice' => ['notice.php', '更新公告', '📢'],
'visits' => ['visits.php', '风控管理', '🛡'],
];
echo '<nav class="as-nav">';
foreach ($links as $k => $lk) {
$cls = 'as-link' . ($active === $k ? ' active' : '');
echo '<a class="' . $cls . '" href="' . he($lk[0]) . '" title="' . he($lk[1]) . '">';
echo '<span class="as-ic">' . he($lk[2]) . '</span><span class="as-tx">' . he($lk[1]) . '</span></a>';
}
echo '</nav>';
// 本页功能(由 common.js 依据当前页区块自动生成)
echo '<div class="as-sec" id="adminSideSections" hidden>';
echo '<div class="as-sec-t"><span class="as-tx">本页功能</span></div>';
echo '<div class="as-sec-list" id="adminSideSectionList"></div>';
echo '</div>';
// 底部:前台入口 / 退出 / 当前管理员
echo '<div class="as-foot">';
echo '<a class="as-link" href="../index.php" title="查看前台首页"><span class="as-ic">⌂</span><span class="as-tx">查看前台</span></a>';
echo '<a class="as-link" href="logout.php" title="退出登录"><span class="as-ic">⎋</span><span class="as-tx">退出登录</span></a>';
echo '<div class="as-user as-tx" title="当前登录用户">当前用户(' . he($admin) . '</div>';
echo '</div>';
echo '</aside>' . "\n";
echo '<div class="admin-side-mask" id="adminSideMask"></div>' . "\n";
}