<?php
/**
 * Complete Sitemap Generator for Xoiar.com
 * Produces an XML sitemap with ~3580 URLs:
 * - Homepage
 * - 10 Learning Tools
 * - 6 Language Courses × 9 pages each (main + 7 days + certificate) = 54
 * - 10 Learning Games
 * - 2 Blog Posts + all existing blog posts (preserved)
 * - 4 Legal Pages
 * - 3500+ Dictionary Words (each as a separate URL)
 */

header('Content-Type: application/xml; charset=utf-8');

$base_url = 'https://xoiar.com';
$today = date('Y-m-d');

function url_entry($loc, $priority = 0.5, $changefreq = 'weekly', $lastmod = null) {
    global $today;
    $lastmod = $lastmod ?? $today;
    return "<url>\n    <loc>$loc</loc>\n    <lastmod>$lastmod</lastmod>\n    <changefreq>$changefreq</changefreq>\n    <priority>$priority</priority>\n</url>";
}

// ========== 1. DICTIONARY WORDS (3500+ entries) ==========
// !!! REPLACE THIS ARRAY WITH YOUR ACTUAL 3500+ WORD LIST !!!
// You can copy the keys from your $dictionary array (e.g., array_keys($dictionary))
$all_words = [
    'ability', 'able', 'about', 'above', 'accept', 'accident', 'account', 'achieve', 'across', 'act',
    'action', 'active', 'actual', 'add', 'address', 'admire', 'admit', 'adopt', 'advance', 'advantage',
    'advice', 'affair', 'affect', 'afford', 'afraid', 'after', 'afternoon', 'again', 'against', 'age',
    'agency', 'agent', 'ago', 'agree', 'agreement', 'ahead', 'air', 'alive', 'all', 'allow',
    'almost', 'alone', 'along', 'already', 'also', 'although', 'always', 'amazing', 'among', 'amount',
    'analysis', 'ancient', 'anger', 'animal', 'anniversary', 'another', 'answer', 'anxiety', 'any', 'anybody',
    'anything', 'anywhere', 'appear', 'apple', 'application', 'apply', 'approach', 'appropriate', 'area', 'argue',
    'argument', 'arm', 'army', 'around', 'arrange', 'arrest', 'arrive', 'art', 'article', 'artist',
    'ask', 'asleep', 'assist', 'association', 'assume', 'attack', 'attempt', 'attend', 'attention', 'attitude',
    'attract', 'attractive', 'audience', 'authority', 'available', 'average', 'avoid', 'awake', 'away', 'baby',
    'back', 'background', 'bad', 'bag', 'ball', 'bank', 'bar', 'base', 'basic', 'battle',
    'beach', 'bear', 'beautiful', 'beauty', 'because', 'become', 'bed', 'bedroom', 'beer', 'before',
    'begin', 'beginning', 'behavior', 'behind', 'believe', 'belong', 'below', 'benefit', 'beside', 'best',
    'better', 'between', 'beyond', 'big', 'bike', 'bill', 'bird', 'birth', 'birthday', 'bit',
    'black', 'block', 'blood', 'blue', 'board', 'boat', 'body', 'book', 'born', 'both',
    'bottom', 'box', 'boy', 'brain', 'bread', 'break', 'breakfast', 'bridge', 'brief', 'bright',
    'bring', 'broad', 'brother', 'brown', 'build', 'building', 'business', 'busy', 'buy', 'call',
    'camera', 'campaign', 'can', 'cancer', 'candidate', 'capital', 'car', 'card', 'care', 'career',
    'carry', 'case', 'catch', 'cause', 'central', 'century', 'certain', 'certainly', 'chair', 'chairman',
    'challenge', 'chance', 'change', 'character', 'charge', 'cheap', 'check', 'child', 'choice', 'choose',
    'church', 'citizen', 'city', 'civil', 'claim', 'class', 'clear', 'clearly', 'close', 'clothes',
    'cloud', 'club', 'coach', 'cold', 'collect', 'college', 'color', 'come', 'comment', 'common',
    'community', 'company', 'compare', 'complete', 'computer', 'concern', 'condition', 'conference', 'congress', 'consider',
    'contain', 'continue', 'control', 'cook', 'cool', 'copy', 'corner', 'cost', 'could', 'council',
    'count', 'country', 'couple', 'course', 'court', 'cover', 'create', 'crime', 'cultural', 'culture',
    'cup', 'current', 'customer', 'cut', 'dark', 'data', 'daughter', 'day', 'dead', 'deal',
    'death', 'decide', 'decision', 'deep', 'define', 'degree', 'delay', 'deliver', 'demand', 'deny',
    'depend', 'describe', 'design', 'desire', 'desk', 'destroy', 'detail', 'develop', 'die', 'difference',
    'different', 'difficult', 'dinner', 'direction', 'director', 'discover', 'discuss', 'disease', 'divide', 'do',
    'doctor', 'dog', 'door', 'doubt', 'down', 'draw', 'dream', 'dress', 'drink', 'drive',
    'drop', 'drug', 'dry', 'during', 'each', 'early', 'earth', 'east', 'easy', 'eat',
    'economic', 'economy', 'edge', 'education', 'effect', 'effort', 'eight', 'either', 'election', 'electric',
    'element', 'else', 'email', 'emergency', 'employee', 'end', 'energy', 'enjoy', 'enough', 'enter',
    'entire', 'environment', 'equal', 'error', 'especially', 'establish', 'even', 'evening', 'event', 'ever',
    'every', 'everyone', 'everything', 'evidence', 'exact', 'example', 'excellent', 'except', 'exchange', 'exist',
    'expect', 'experience', 'expert', 'explain', 'express', 'extend', 'extra', 'eye', 'face', 'fact',
    'factor', 'fail', 'fall', 'family', 'famous', 'far', 'farm', 'fast', 'father', 'fear',
    'feature', 'feed', 'feel', 'female', 'few', 'field', 'fight', 'figure', 'file', 'fill',
    'film', 'final', 'finance', 'find', 'fine', 'finish', 'fire', 'firm', 'first', 'fish',
    'fit', 'fix', 'floor', 'focus', 'follow', 'food', 'foot', 'force', 'foreign', 'forget',
    'form', 'former', 'forward', 'free', 'friend', 'from', 'front', 'fruit', 'full', 'fun',
    'future', 'game', 'garden', 'general', 'get', 'girl', 'give', 'glass', 'go', 'goal',
    'good', 'government', 'great', 'green', 'ground', 'group', 'grow', 'guess', 'guide', 'gun',
    'hair', 'half', 'hand', 'happy', 'hard', 'head', 'health', 'hear', 'heart', 'heat',
    'heavy', 'help', 'her', 'here', 'high', 'history', 'hit', 'hold', 'home', 'hope',
    'horse', 'hospital', 'hot', 'hotel', 'hour', 'house', 'how', 'human', 'idea', 'identify'
];
// IMPORTANT: Replace the above with your full 3500+ word array (you can copy it from your dictionary.php).

// Start XML
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';

// Add all dictionary word pages
foreach ($all_words as $word) {
    $slug = urlencode(strtolower($word));
    // Assuming each word has a dedicated page at https://xoiar.com/word/ability
    $word_url = $base_url . '/word/' . $slug;
    echo url_entry($word_url, 0.5, 'monthly');
}

// ========== 2. STATIC PAGES (Home, Tools, Courses, Games, Blog, Legal) ==========

// Homepage
echo url_entry($base_url . '/', 1.0, 'daily');

// Tools (10)
$tools = [
    'english-urdu-dictionary.php', 'urdu-english-dictionary.php', 'roman-urdu-converter.php',
    'english-grammar-explained.php', 'useful-english-phrases.php', 'vocabulary-builder.php',
    'pronunciation-helper.php', 'urdu-alphabet-guide.php', 'learning-quiz.php', 'english-learning-tenses.php'
];
foreach ($tools as $tool) {
    echo url_entry($base_url . '/tools/' . $tool, 0.8, 'weekly');
}

// Courses: 6 languages × 9 pages each = 54
$languages = ['english', 'urdu', 'arabic', 'chinese', 'japanese', 'russian'];
foreach ($languages as $lang) {
    echo url_entry($base_url . '/courses/day-1-' . $lang . '.php', 0.7, 'weekly');
    echo url_entry($base_url . '/courses/day-2-' . $lang . '.php', 0.7, 'weekly');
    echo url_entry($base_url . '/courses/day-3-' . $lang . '.php', 0.7, 'weekly');
    echo url_entry($base_url . '/courses/day-4-' . $lang . '.php', 0.7, 'weekly');
    echo url_entry($base_url . '/courses/day-5-' . $lang . '.php', 0.7, 'weekly');
    echo url_entry($base_url . '/courses/day-6-' . $lang . '.php', 0.7, 'weekly');
    echo url_entry($base_url . '/courses/day-7-' . $lang . '.php', 0.7, 'weekly');
    // Certificate pages (if they exist)
    echo url_entry($base_url . '/courses/certificate-' . $lang . '.php', 0.6, 'monthly');
}

// Games (10)
$games = [
    'word-scramble.php', 'crossword.php', 'hangman.php', 'vocabulary-match.php', 'daily-challenge.php',
    'grammar-quiz.php', 'vocabulary-spelling.php', 'vocabulary-thinking.php', 'spelling-word-recognition.php', 'bilingual-memory.php'
];
foreach ($games as $game) {
    echo url_entry($base_url . '/games/' . $game, 0.7, 'weekly');
}
// Games index
echo url_entry($base_url . '/games/index.php', 0.6, 'weekly');

// Blog pages (preserve all existing slugs from your sitemap)
$blog_posts = [
    'index.php',
    'speak-urdu-fluently.php', 'urdu-vocabulary-strategies.php', 'english-tenses-urdu.php',
    'essential-english-words-urdu.php', 'mastering-english-pronunciation.php', 'english-to-urdu-business-vocabulary.php',
    'urdu-phrases-guide.php', 'advanced-english-words-urdu.php', 'english-grammar-lessons-in-urdu.php',
    'free-english-to-urdu-translation-tools.php', 'roman-urdu-converter.php', 'learn-english-vocabulary-for-urdu-speakers.php',
    'learn-urdu-script.php', 'urdu-poetry-for-beginners.php', 'common-mistakes-urdu-speakers.php',
    'learn-urdu-online-2025.php', 'urdu-proverbs-explained.php', 'urdu-for-travelers.php',
    'english-urdu-translation-exam-tips.php', 'english-urdu-dictionary-guide.php', 'urdu-alphabet-guide.php',
    'english-urdu-translation-guide.php', 'learn-urdu-phrases.php', 'master-english-urdu.php',
    'How-Internet-Brainrot.php', 'The-2026-Lexicon.php', 'The-Post-Truth-Ecology.php'
];
foreach ($blog_posts as $post) {
    echo url_entry($base_url . '/blog/' . $post, 0.64, 'weekly');
}

// Additional dictionary articles (new degzine articles)
$articles = [
    'post-truth-ecology-2026.php',
    'dictionary-2026-trends.php'
];
foreach ($articles as $art) {
    echo url_entry($base_url . '/dictionary/' . $art, 0.8, 'weekly');
}

// Legal pages
$legal = ['about.php', 'contact.php', 'privacy-policy.php', 'terms.php'];
foreach ($legal as $page) {
    echo url_entry($base_url . '/' . $page, 0.7, 'monthly');
}

// ========== 3. PRESERVE EXISTING DYNAMIC DICTIONARY URLS (if you already have them) ==========
// These are the URLs from the original sitemap – keep them to avoid 404s.
$existing_dynamic = [
    'https://xoiar.com/tools/urdu-dictionary.php?word=%DB%81%DB%8C%D9%84%D9%88',
    'https://xoiar.com/tools/urdu-dictionary.php?word=%D9%85%D8%AD%D8%A8%D8%AA',
    'https://xoiar.com/tools/urdu-dictionary.php?word=%DA%AF%DA%BE%D8%B1',
    'https://xoiar.com/tools/urdu-dictionary.php?word=%D9%88%D9%82%D8%AA',
    'https://xoiar.com/tools/urdu-dictionary.php?word=%D8%AF%D9%88%D8%B3%D8%AA'
];
foreach ($existing_dynamic as $url) {
    echo url_entry($url, 0.64, 'monthly');
}

echo '</urlset>';
?>