| Server IP : 188.114.96.3 / Your IP : 216.73.216.143 Web Server : Apache System : Linux sv058.home.net.pl 6.8.2 husak_dirty_pages_fix #1 SMP PREEMPT_DYNAMIC Tue Apr 2 22:06:51 CEST 2024 x86_64 User : ( 3194769) PHP Version : 8.5.12 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /polana/includes/ |
Upload File : |
<?php
declare(strict_types=1);
/** Public site translations: only manually approved records are shown. */
function polana_site_translation_columns(): array
{
return [
'home_title' => 'Tytuł SEO strony głównej',
'home_description' => 'Opis SEO strony głównej',
'home_lead' => 'Lead strony głównej',
'home_about_title' => 'Nagłówek O nas',
'home_about_text' => 'Tekst O nas',
'contact_title' => 'Tytuł SEO kontaktu',
'contact_description' => 'Opis SEO kontaktu',
'opening_hours' => 'Godziny otwarcia',
'site_splash_badge' => 'Zaślepka – etykieta',
'site_splash_title' => 'Zaślepka – nagłówek',
'site_splash_text' => 'Zaślepka – opis',
'site_splash_note' => 'Zaślepka – stopka',
];
}
function polana_site_translation_hash(string $scope, string $source): string
{
return hash('sha256', $scope . "\0" . $source);
}
function polana_site_translation_ready(): bool
{
static $ready = null;
if ($ready !== null) return $ready;
try {
$ready = (bool)db()->query("SHOW TABLES LIKE 'polana_site_translations'")->fetchColumn();
} catch (Throwable $e) {
error_log('[POLANA_I18N_SCHEMA] ' . $e->getMessage());
$ready = false;
}
return $ready;
}
function polana_site_translation_create(): void
{
db()->exec("CREATE TABLE IF NOT EXISTS polana_site_translations (
translation_id CHAR(64) CHARACTER SET ascii COLLATE ascii_bin PRIMARY KEY,
scope VARCHAR(20) NOT NULL,
source_text MEDIUMTEXT NOT NULL,
translated_text MEDIUMTEXT NOT NULL,
state ENUM('draft','published') NOT NULL DEFAULT 'draft',
reviewed_at DATETIME NULL,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX idx_state (scope, state)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci");
}
/** Single SELECT per public request; never publish draft machine text. */
function polana_site_translation_cache(): array
{
static $cache = null;
if ($cache !== null) return $cache;
$cache = [];
if (!polana_site_translation_ready()) return $cache;
try {
foreach (db()->query("SELECT translation_id, scope, source_text, translated_text FROM polana_site_translations WHERE state='published'") as $record) {
$cache[(string)$record['translation_id']] = $record;
}
} catch (Throwable $e) { error_log('[POLANA_I18N_READ] '.$e->getMessage()); }
return $cache;
}
function polana_site_translation_published(string $scope, string $source): ?string
{
if ($source === '') return null;
$record = polana_site_translation_cache()[polana_site_translation_hash($scope, $source)] ?? null;
if (!is_array($record)) return null;
// If the source text changed after approval, an old translation must not remain approved.
if ($scope === 'setting' && (string)$record['source_text'] !== $source &&
(string)$record['source_text'] !== trim(setting($source))) return null;
$value = $record['translated_text'] ?? null;
return is_string($value) && trim($value) !== '' ? $value : null;
}
/** A reviewed override takes precedence; manually maintained *_en setting is next. */
function polana_site_setting(string $key, string $default = '', string $englishFallback = ''): string
{
$pl = setting($key, $default);
if (polana_lang() !== 'en' || $pl === '') return $pl;
$published = polana_site_translation_published('setting', $key);
if ($published !== null) return $published;
$configuredEnglish = setting($key.'_en');
return $configuredEnglish !== '' ? $configuredEnglish : ($englishFallback !== '' ? $englishFallback : $pl);
}