mirror of
git://f0xx.org/android_cast
synced 2026-07-29 03:38:52 +03:00
footer changes, remote access changes
This commit is contained in:
@@ -6,6 +6,11 @@ declare(strict_types=1);
|
||||
*
|
||||
* Configure: examples/platform/footer.config.php (see footer.config.example.php).
|
||||
* Usage: <?php platform_render_footer(); ?> or platform_render_footer(['use_i18n' => false]);
|
||||
*
|
||||
* Layout (each row omitted when empty):
|
||||
* [ top — full width ]
|
||||
* [ left | right ] — main row (copyright defaults on left when left unset)
|
||||
* [ bottom — full width ]
|
||||
*/
|
||||
|
||||
function platform_footer_h(mixed $value): string
|
||||
@@ -28,7 +33,8 @@ function platform_footer_config(): array
|
||||
return is_array($loaded) ? $loaded : [];
|
||||
}
|
||||
|
||||
function platform_footer_year(array $cfg): int
|
||||
/** @param array<string, mixed> $cfg */
|
||||
function platform_footer_year_end(array $cfg): int
|
||||
{
|
||||
if (array_key_exists('year', $cfg) && $cfg['year'] !== null) {
|
||||
return (int) $cfg['year'];
|
||||
@@ -37,9 +43,34 @@ function platform_footer_year(array $cfg): int
|
||||
return (int) date('Y');
|
||||
}
|
||||
|
||||
function platform_footer_plain_text(array $cfg, int $year): string
|
||||
/**
|
||||
* Year label: single year or range (e.g. 2026–2026) when year_start is set.
|
||||
*
|
||||
* @param array<string, mixed> $cfg
|
||||
*/
|
||||
function platform_footer_year_label(array $cfg): string
|
||||
{
|
||||
$symbol = trim((string) ($cfg['copyright_symbol'] ?? '(c)'));
|
||||
$end = platform_footer_year_end($cfg);
|
||||
$start = isset($cfg['year_start']) ? (int) $cfg['year_start'] : 0;
|
||||
if ($start > 0) {
|
||||
if ($start === $end) {
|
||||
return (string) $start;
|
||||
}
|
||||
|
||||
return $start . "\u{2013}" . $end;
|
||||
}
|
||||
|
||||
return (string) $end;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default left line: © holder[, year|year-range].
|
||||
*
|
||||
* @param array<string, mixed> $cfg
|
||||
*/
|
||||
function platform_footer_default_left(array $cfg): string
|
||||
{
|
||||
$symbol = trim((string) ($cfg['copyright_symbol'] ?? "\u{00A9}"));
|
||||
$holder = trim((string) ($cfg['holder'] ?? ''));
|
||||
$showYear = (bool) ($cfg['show_year'] ?? true);
|
||||
$parts = [];
|
||||
@@ -50,36 +81,117 @@ function platform_footer_plain_text(array $cfg, int $year): string
|
||||
$parts[] = $holder;
|
||||
}
|
||||
$line = implode(' ', $parts);
|
||||
if ($showYear && $line !== '') {
|
||||
return $line . ', ' . $year;
|
||||
if (!$showYear) {
|
||||
return $line;
|
||||
}
|
||||
if ($showYear && $line === '') {
|
||||
return (string) $year;
|
||||
$yearLabel = platform_footer_year_label($cfg);
|
||||
if ($line === '') {
|
||||
return $yearLabel;
|
||||
}
|
||||
|
||||
return $line;
|
||||
return $line . ', ' . $yearLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{use_i18n?: bool, extra_class?: string} $opts
|
||||
* Resolve optional row text (null/empty = omit row). Supports per-render overrides in $opts.
|
||||
*
|
||||
* @param array<string, mixed> $cfg
|
||||
* @param array<string, mixed> $opts
|
||||
*/
|
||||
function platform_footer_field(array $cfg, array $opts, string $key): ?string
|
||||
{
|
||||
if (array_key_exists($key, $opts)) {
|
||||
$v = $opts[$key];
|
||||
if ($v === null || $v === false) {
|
||||
return null;
|
||||
}
|
||||
$t = trim((string) $v);
|
||||
|
||||
return $t === '' ? null : $t;
|
||||
}
|
||||
if (!array_key_exists($key, $cfg)) {
|
||||
return null;
|
||||
}
|
||||
$v = $cfg[$key];
|
||||
if ($v === null || $v === false) {
|
||||
return null;
|
||||
}
|
||||
$t = trim((string) $v);
|
||||
|
||||
return $t === '' ? null : $t;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $cfg
|
||||
* @param array<string, mixed> $opts
|
||||
*/
|
||||
function platform_footer_resolve_left(array $cfg, array $opts): ?string
|
||||
{
|
||||
$custom = platform_footer_field($cfg, $opts, 'left');
|
||||
if ($custom !== null) {
|
||||
return $custom;
|
||||
}
|
||||
$built = platform_footer_default_left($cfg);
|
||||
|
||||
return $built === '' ? null : $built;
|
||||
}
|
||||
|
||||
/** @deprecated Use platform_footer_default_left(); kept for scripts/tests. */
|
||||
function platform_footer_plain_text(array $cfg, int $year): string
|
||||
{
|
||||
$cfg = array_merge($cfg, ['year' => $year]);
|
||||
|
||||
return platform_footer_default_left($cfg);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{use_i18n?: bool, extra_class?: string, top?: ?string, left?: ?string, right?: ?string, bottom?: ?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');
|
||||
$top = platform_footer_field($cfg, $opts, 'top');
|
||||
$left = platform_footer_resolve_left($cfg, $opts);
|
||||
$right = platform_footer_field($cfg, $opts, 'right');
|
||||
$bottom = platform_footer_field($cfg, $opts, 'bottom');
|
||||
|
||||
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;
|
||||
$baseClass = (string) ($opts['extra_class'] ?? ($cfg['footer_class'] ?? 'bottom-bar'));
|
||||
$classes = trim($baseClass . ' platform-footer');
|
||||
if ($top === null && $bottom === null && $right === null) {
|
||||
$classes .= ' platform-footer--single-row';
|
||||
}
|
||||
|
||||
echo '<footer class="' . platform_footer_h($class) . '">' . platform_footer_h($text) . '</footer>';
|
||||
$useI18n = $opts['use_i18n'] ?? (bool) ($cfg['use_i18n'] ?? true);
|
||||
$i18nKey = (string) ($cfg['i18n_key'] ?? 'footer.copyright');
|
||||
$leftUsesDefault = platform_footer_field($cfg, $opts, 'left') === null;
|
||||
$yearEnd = platform_footer_year_end($cfg);
|
||||
|
||||
echo '<footer class="' . platform_footer_h($classes) . '">';
|
||||
|
||||
if ($top !== null) {
|
||||
echo '<div class="platform-footer__top">' . platform_footer_h($top) . '</div>';
|
||||
}
|
||||
|
||||
if ($left !== null || $right !== null) {
|
||||
echo '<div class="platform-footer__main">';
|
||||
if ($left !== null) {
|
||||
echo '<div class="platform-footer__left"';
|
||||
if ($useI18n && $i18nKey !== '' && $leftUsesDefault) {
|
||||
echo ' data-i18n="' . platform_footer_h($i18nKey) . '"'
|
||||
. ' data-year="' . platform_footer_h(platform_footer_year_label($cfg)) . '"'
|
||||
. ' data-year-end="' . $yearEnd . '"';
|
||||
}
|
||||
echo '>' . platform_footer_h($left) . '</div>';
|
||||
}
|
||||
if ($right !== null) {
|
||||
echo '<div class="platform-footer__right">' . platform_footer_h($right) . '</div>';
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
if ($bottom !== null) {
|
||||
echo '<div class="platform-footer__bottom">' . platform_footer_h($bottom) . '</div>';
|
||||
}
|
||||
|
||||
echo '</footer>';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user