Files
laysite/app/view/header.php
T

42 lines
2.4 KiB
PHP

<?php
use App\Content\Buttons;
use App\Content\View;
$e = View::escape(...);
$data = $header['payload'];
$brand = $data['brand'] ?: $site['name'];
?>
<header class="masthead masthead-<?= $e($header['preset']) ?>"<?= $showHeader ? '' : ' hidden' ?>>
<div class="wrap masthead-inner">
<?php foreach ($data['components'] as $component): ?>
<?php if ($component === 'brand'): ?>
<a class="wordmark site-brand" href="/" aria-label="<?= $e($brand) ?>,首页">
<?php if ($data['logo'] !== ''): ?><img src="<?= $e($data['logo']) ?>" alt="<?= $e($brand) ?>"><?php else: ?><?= $e($brand) ?><?php endif ?>
</a>
<?php elseif ($component === 'links' && $data['links']): ?>
<button class="menu-toggle" type="button" aria-expanded="false" aria-controls="primary-navigation" hidden>
<span></span><span></span><span class="sr-only">菜单</span>
</button>
<nav id="primary-navigation" class="primary-nav" aria-label="主导航">
<?php foreach ($data['links'] as [$url, $label]): ?>
<a href="<?= $e($url) ?>"<?= $url === $path ? ' aria-current="page"' : '' ?>><?= $e($label) ?></a>
<?php endforeach ?>
</nav>
<?php elseif ($component === 'action' && $data['action']): ?>
<?php [$url, $label, $style, $blank] = $data['action'][0]; ?>
<a class="<?= $e(Buttons::css($style)) ?> masthead-action" href="<?= $e($url) ?>"<?= Buttons::target($blank) ?>><?= $e($label) ?></a>
<?php elseif ($component === 'account' && $member): ?>
<?php if ($visitor): ?>
<a class="site-account" href="/account" aria-label="打开用户中心">
<?php if ($visitor['avatar'] !== ''): ?><img class="account-avatar" src="<?= $e($visitor['avatar']) ?>" alt="" width="36" height="36"><?php else: ?>
<span class="account-avatar account-initial" aria-hidden="true"><?= $e(mb_substr($visitor['name'], 0, 1)) ?></span>
<?php endif ?>
</a>
<?php else: ?>
<a class="button button-outline site-account" href="/account/login/<?= $e($header['id']) ?>">登录</a>
<?php endif ?>
<?php endif ?>
<?php endforeach ?>
</div>
</header>