475765e31f
Add an explicit template renderer with HTML views and partials for the app, bootstrap, package, and catalog pages. Move shared reporting setup into config/reporting.php and relocate stylesheet assets under css/.
147 lines
4.5 KiB
PHP
147 lines
4.5 KiB
PHP
<?php
|
|
/*
|
|
* header.php
|
|
*
|
|
* Shared page header renderer for logged-in application pages.
|
|
*/
|
|
|
|
require_once __DIR__ . '/Template.php';
|
|
|
|
function app_header_h($s)
|
|
{
|
|
return RacketSandboxTemplate::escape($s);
|
|
}
|
|
|
|
function render_app_header($options)
|
|
{
|
|
echo app_header_html($options);
|
|
}
|
|
|
|
function app_header_html($options)
|
|
{
|
|
$title = (string)($options['title'] ?? '');
|
|
$navItems = $options['nav_items'] ?? array();
|
|
$user = $options['user'] ?? null;
|
|
$userPrefix = (string)($options['user_prefix'] ?? '');
|
|
$adminLabel = (string)($options['admin_label'] ?? 'admin');
|
|
$languageLabel = (string)($options['language_label'] ?? 'Language');
|
|
$language = (string)($options['language'] ?? 'en');
|
|
$languages = $options['languages'] ?? array();
|
|
$languageAction = (string)($options['language_action'] ?? '/');
|
|
$languageHidden = $options['language_hidden'] ?? array();
|
|
$logoutAction = (string)($options['logout_action'] ?? '');
|
|
$logoutLabel = (string)($options['logout_label'] ?? '');
|
|
$message = (string)($options['message'] ?? '');
|
|
$error = (string)($options['error'] ?? '');
|
|
|
|
return RacketSandboxTemplate::renderFile('app-header.html', array(
|
|
'title' => $title,
|
|
'nav_html' => app_header_nav_html($navItems),
|
|
'logout_html' => app_header_logout_html($logoutAction, $logoutLabel),
|
|
'user_html' => app_header_user_html($user, $userPrefix, $adminLabel),
|
|
'language_html' => app_header_language_html($languageLabel, $language, $languages, $languageAction, $languageHidden),
|
|
'message_html' => app_header_status_html('message', $message),
|
|
'error_html' => app_header_status_html('error', $error),
|
|
));
|
|
}
|
|
|
|
function app_header_status_html($class, $message)
|
|
{
|
|
if ($message === '') {
|
|
return '';
|
|
}
|
|
|
|
return RacketSandboxTemplate::renderFile('partials/message.html', array(
|
|
'class' => $class,
|
|
'message' => $message,
|
|
));
|
|
}
|
|
|
|
function app_header_nav_html($navItems)
|
|
{
|
|
$html = '';
|
|
|
|
foreach ($navItems as $item) {
|
|
if (!empty($item['separator_before'])) {
|
|
$html .= RacketSandboxTemplate::renderFile('partials/header-separator.html', array()) . "\n";
|
|
}
|
|
|
|
if (!empty($item['active'])) {
|
|
$html .= RacketSandboxTemplate::renderFile('partials/header-nav-active.html', array(
|
|
'label' => $item['label'] ?? '',
|
|
)) . "\n";
|
|
continue;
|
|
}
|
|
|
|
$html .= RacketSandboxTemplate::renderFile('partials/header-nav-link.html', array(
|
|
'url' => $item['url'] ?? '#',
|
|
'label' => $item['label'] ?? '',
|
|
)) . "\n";
|
|
}
|
|
|
|
return $html;
|
|
}
|
|
|
|
function app_header_logout_html($logoutAction, $logoutLabel)
|
|
{
|
|
if ($logoutAction === '' || $logoutLabel === '') {
|
|
return '';
|
|
}
|
|
|
|
return RacketSandboxTemplate::renderFile('partials/header-logout.html', array(
|
|
'logout_action' => $logoutAction,
|
|
'logout_label' => $logoutLabel,
|
|
)) . "\n";
|
|
}
|
|
|
|
function app_header_user_html($user, $userPrefix, $adminLabel)
|
|
{
|
|
if ($user === null) {
|
|
return '';
|
|
}
|
|
|
|
$adminHtml = '';
|
|
|
|
if ($user->isAdmin()) {
|
|
$adminHtml = RacketSandboxTemplate::renderFile('partials/header-admin-badge.html', array(
|
|
'admin_label' => $adminLabel,
|
|
));
|
|
}
|
|
|
|
return RacketSandboxTemplate::renderFile('partials/header-user.html', array(
|
|
'user_prefix' => $userPrefix,
|
|
'display_name' => $user->displayName(),
|
|
'admin_html' => $adminHtml,
|
|
)) . "\n";
|
|
}
|
|
|
|
function app_header_language_html($languageLabel, $language, $languages, $languageAction, $languageHidden)
|
|
{
|
|
$hiddenInputsHtml = '';
|
|
|
|
foreach ($languageHidden as $name => $value) {
|
|
$hiddenInputsHtml .= RacketSandboxTemplate::renderFile('partials/header-hidden-input.html', array(
|
|
'name' => $name,
|
|
'value' => $value,
|
|
)) . "\n";
|
|
}
|
|
|
|
$languageOptionsHtml = '';
|
|
|
|
foreach ($languages as $lang => $label) {
|
|
$selected = $lang === $language ? ' selected' : '';
|
|
$languageOptionsHtml .= RacketSandboxTemplate::renderFile('partials/select-option.html', array(
|
|
'value' => $lang,
|
|
'selected' => $selected,
|
|
'label' => $label,
|
|
)) . "\n";
|
|
}
|
|
|
|
return RacketSandboxTemplate::renderFile('partials/header-language.html', array(
|
|
'language_action' => $languageAction,
|
|
'hidden_inputs_html' => $hiddenInputsHtml,
|
|
'language_label' => $languageLabel,
|
|
'language_options_html' => $languageOptionsHtml,
|
|
)) . "\n";
|
|
}
|