<?php
header('Content-Type: application/xml; charset=utf-8');

$lang = 'en';
if (isset($_GET['lang']) && $_GET['lang'] === 'ar') {
    $lang = 'ar';
}

$base = 'https://in1.me';
$pages = [];

// Main pages
$pages[] = [
    'loc' => $base . '/',
    'priority' => '1.0',
    'changefreq' => 'weekly',
];

$pages[] = [
    'loc' => $base . '/?lang=ar',
    'priority' => '1.0',
    'changefreq' => 'weekly',
];

$pages[] = [
    'loc' => $base . '/terms.php',
    'priority' => '0.3',
    'changefreq' => 'monthly',
];

$pages[] = [
    'loc' => $base . '/terms.php?lang=ar',
    'priority' => '0.3',
    'changefreq' => 'monthly',
];

// Sub-sites
$sites = [
    ['loc' => 'https://in1.me/photostar', 'priority' => '0.8'],
    ['loc' => 'https://www.stars-host.com/', 'priority' => '0.8'],
    ['loc' => 'https://wlc.me/', 'priority' => '0.8'],
    ['loc' => 'https://in1.me/games', 'priority' => '0.8'],
    ['loc' => 'https://in1.me/pcloud-plugin', 'priority' => '0.8'],
];

foreach ($sites as $site) {
    $pages[] = [
        'loc' => $site['loc'],
        'priority' => $site['priority'],
        'changefreq' => 'monthly',
    ];
}

echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:xhtml="http://www.w3.org/1999/xhtml">
<?php foreach ($pages as $page): ?>
    <url>
        <loc><?php echo htmlspecialchars($page['loc'], ENT_XML1, 'UTF-8'); ?></loc>
        <priority><?php echo $page['priority']; ?></priority>
        <changefreq><?php echo $page['changefreq']; ?></changefreq>
        <?php if (strpos($page['loc'], '?lang=') === false && $page['loc'] !== $base . '/terms.php'): ?>
        <xhtml:link rel="alternate" hreflang="en" href="<?php echo $page['loc']; ?>" />
        <xhtml:link rel="alternate" hreflang="ar" href="<?php echo $page['loc']; ?>?lang=ar" />
        <xhtml:link rel="alternate" hreflang="x-default" href="<?php echo $page['loc']; ?>" />
        <?php endif; ?>
    </url>
<?php endforeach; ?>
</urlset>
