39496-vm/patch_app.php
2026-04-06 04:21:26 +00:00

51 lines
1.5 KiB
PHP

<?php
$content = file_get_contents('includes/app.php');
$helper = <<<'EOD'
function get_platform_profile(): array {
static $profile = null;
if ($profile === null) {
$stmt = db()->query("SELECT * FROM platform_profile WHERE id = 1");
$profile = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$profile) {
$profile = ['name' => 'LMS Platform', 'description' => '', 'logo_path' => '', 'favicon_path' => ''];
}
}
return $profile;
}
EOD;
if (strpos($content, 'function get_platform_profile()') === false) {
$content = str_replace('function app_name(): string', $helper . 'function app_name(): string', $content);
}
// Update app_name() to use profile if exists
$app_name_new = <<<'EOD'
function app_name(): string
{
$prof = get_platform_profile();
if (!empty($prof['name'])) {
return trim($prof['name']);
}
return trim((string) ($_SERVER['PROJECT_NAME'] ?? 'Aula')) ?: 'Aula';
}
EOD;
$content = preg_replace('/function app_name\(\): string\s*\{[^}]+\}/s', $app_name_new, $content);
// Update render_head() to add favicon support
$render_head_old = '<title><?= h(page_title($title)) ?></title>';
$render_head_new = <<<'EOD'
<title><?= h(page_title($title)) ?></title>
<?php
$prof = get_platform_profile();
if (!empty($prof['favicon_path'])):
?>
<link rel="icon" href="<?= h(asset_url($prof['favicon_path'])) ?>" />
<?php endif; ?>
EOD;
$content = str_replace($render_head_old, $render_head_new, $content);
file_put_contents('includes/app.php', $content);
echo "Patched includes/app.php\n";