<?php
declare(strict_types=1);
require_once __DIR__ . '/../app/config/bootstrap.php';
require_once __DIR__ . '/../app/models/SiteSetting.php';

header('Content-Type: text/plain; charset=utf-8');

$base = rtrim(APP_URL, '/');
$sitemap = $base . appPath('/public/sitemap.php');
$extra = (new SiteSetting())->getMany(['seo_robots_extra']);
$lines = [
    'User-agent: *',
    'Allow: /',
    'Sitemap: ' . $sitemap,
];
$more = trim((string)($extra['seo_robots_extra'] ?? ''));
if ($more !== '') {
    foreach (preg_split('/\R/', $more) as $line) {
        $line = trim($line);
        if ($line !== '') {
            $lines[] = $line;
        }
    }
}
echo implode("\n", $lines) . "\n";
