mirror of
git://f0xx.org/android_cast
synced 2026-07-29 05:37:52 +03:00
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>
This commit is contained in:
27
examples/platform/README.md
Normal file
27
examples/platform/README.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# Shared platform pieces
|
||||
|
||||
## Footer (`footer.php`)
|
||||
|
||||
Single copyright footer for hub, crashes, tickets, graphs, and builder consoles.
|
||||
|
||||
**Configure:** edit `footer.config.php` (copy from `footer.config.example.php`).
|
||||
|
||||
| Key | Purpose |
|
||||
|-----|---------|
|
||||
| `holder` | Copyright name |
|
||||
| `copyright_symbol` | `(c)` or `©` |
|
||||
| `show_year` | Append year |
|
||||
| `year` | Fixed year, or `null` for current |
|
||||
| `use_i18n` | `data-i18n` for consoles with `i18n.js` |
|
||||
|
||||
**In PHP views:** `<?php platform_render_footer(); ?>` (loaded via each app `bootstrap.php`).
|
||||
|
||||
**Hub:** `examples/app_hub/index.php` (landing nginx runs it through PHP-FPM).
|
||||
|
||||
**Static HTML export:**
|
||||
|
||||
```bash
|
||||
php examples/platform/scripts/render-footer-html.php
|
||||
```
|
||||
|
||||
**Gitea** (`/git/`) uses the upstream Gitea UI; this footer does not apply there unless you customize Gitea templates separately.
|
||||
22
examples/platform/footer.config.example.php
Normal file
22
examples/platform/footer.config.example.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Site-wide footer (hub, crashes, tickets, graphs, builder).
|
||||
* Copy to footer.config.php and edit; footer.config.php is optional (defaults apply).
|
||||
*/
|
||||
return [
|
||||
// Visible copyright holder (also used in i18n {holder} if you customize strings).
|
||||
'holder' => 'Anton Afanaasyeu',
|
||||
// Prefix before the name: "(c)", "©", or "".
|
||||
'copyright_symbol' => '(c)',
|
||||
// Append current calendar year (or fixed year below).
|
||||
'show_year' => true,
|
||||
// null = (int) date('Y') at render time.
|
||||
'year' => null,
|
||||
// CSS class on <footer>.
|
||||
'footer_class' => 'bottom-bar',
|
||||
// When true, consoles with i18n.js replace text via data-i18n / data-year.
|
||||
'use_i18n' => true,
|
||||
'i18n_key' => 'footer.copyright',
|
||||
];
|
||||
4
examples/platform/footer.config.php
Normal file
4
examples/platform/footer.config.php
Normal file
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
return require __DIR__ . '/footer.config.example.php';
|
||||
85
examples/platform/footer.php
Normal file
85
examples/platform/footer.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?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>';
|
||||
}
|
||||
16
examples/platform/scripts/render-footer-html.php
Normal file
16
examples/platform/scripts/render-footer-html.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Emit a static footer.html from footer.config.php (for docs or static-only hosts).
|
||||
*
|
||||
* php examples/platform/scripts/render-footer-html.php > /path/to/footer.html
|
||||
*/
|
||||
|
||||
require_once dirname(__DIR__) . '/footer.php';
|
||||
|
||||
ob_start();
|
||||
platform_render_footer(['use_i18n' => false]);
|
||||
$footer = ob_get_clean();
|
||||
|
||||
echo $footer . "\n";
|
||||
Reference in New Issue
Block a user