1
0
mirror of git://f0xx.org/android_cast synced 2026-07-29 08:19:00 +03:00
Files
android_cast/examples/platform/footer.php
Anton Afanasyeu 4803caebce Shared platform footer template for hub and all PHP consoles.
Centralize copyright in examples/platform/footer.config.php, render via
footer.php in crashes/builder/login layouts, and serve hub through index.php.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-02 18:54:13 +02:00

86 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
/**
* Shared footer fragment for Android Cast web consoles and hub.
*
* Configure: examples/platform/footer.config.php (see footer.config.example.php).
* Usage: <?php platform_render_footer(); ?> or platform_render_footer(['use_i18n' => false]);
*/
function platform_footer_h(mixed $value): string
{
return htmlspecialchars((string) $value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
}
/** @return array<string, mixed> */
function platform_footer_config(): array
{
static $loaded = null;
if ($loaded !== null) {
return $loaded;
}
$path = __DIR__ . '/footer.config.php';
if (!is_file($path)) {
$path = __DIR__ . '/footer.config.example.php';
}
$loaded = require $path;
return is_array($loaded) ? $loaded : [];
}
function platform_footer_year(array $cfg): int
{
if (array_key_exists('year', $cfg) && $cfg['year'] !== null) {
return (int) $cfg['year'];
}
return (int) date('Y');
}
function platform_footer_plain_text(array $cfg, int $year): string
{
$symbol = trim((string) ($cfg['copyright_symbol'] ?? '(c)'));
$holder = trim((string) ($cfg['holder'] ?? ''));
$showYear = (bool) ($cfg['show_year'] ?? true);
$parts = [];
if ($symbol !== '') {
$parts[] = $symbol;
}
if ($holder !== '') {
$parts[] = $holder;
}
$line = implode(' ', $parts);
if ($showYear && $line !== '') {
return $line . ', ' . $year;
}
if ($showYear && $line === '') {
return (string) $year;
}
return $line;
}
/**
* @param array{use_i18n?: bool, extra_class?: string} $opts
*/
function platform_render_footer(array $opts = []): void
{
$cfg = platform_footer_config();
$year = platform_footer_year($cfg);
$text = platform_footer_plain_text($cfg, $year);
$class = (string) ($opts['extra_class'] ?? ($cfg['footer_class'] ?? 'bottom-bar'));
$useI18n = $opts['use_i18n'] ?? (bool) ($cfg['use_i18n'] ?? true);
$i18nKey = (string) ($cfg['i18n_key'] ?? 'footer.copyright');
if ($useI18n && $i18nKey !== '') {
echo '<footer class="' . platform_footer_h($class) . '"'
. ' data-i18n="' . platform_footer_h($i18nKey) . '"'
. ' data-year="' . $year . '">'
. platform_footer_h($text)
. '</footer>';
return;
}
echo '<footer class="' . platform_footer_h($class) . '">' . platform_footer_h($text) . '</footer>';
}