<?php
/**
 * Complete Sitemap Generator for Xoiar.com
 * Generates an XML sitemap with all pages:
 * - Home, 10 tools, 6 courses (7 days + certificate each), 10 games, all blog posts, legal pages
 * - 3500+ dictionary words (each as a separate URL)
 *
 * Run this script and save the output as sitemap.xml
 */

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+ WORDS) ==========
// This is your full word list from the dictionary (copy from your earlier array)
// For brevity, only a small sample is shown. Replace with your actual 3500+ words.
$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 actual full 3500+ word list !!!

echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';

// Add dictionary word pages (using the same URL pattern as your existing sitemap)
foreach ($all_words as $word) {
    $url = $base_url . '/tools/dictionary.php?word=' . urlencode($word);
    echo url_entry($url, 0.5, 'monthly');
}

// ========== 2. STATIC PAGES ==========
// Homepage
echo url_entry($base_url . '/', 1.0, 'daily');

// Learning 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');
}

// Language Courses: 6 languages × 9 pages each (main index + 7 days + certificate)
$languages = ['english', 'urdu', 'arabic', 'russian', 'korean', 'chinese'];
foreach ($languages as $lang) {
    // Main course page (if you have a main page like /courses/english.php)
    echo url_entry($base_url . '/courses/' . $lang . '.php', 0.8, 'weekly');
    // Days 1-7
    for ($day = 1; $day <= 7; $day++) {
        echo url_entry($base_url . '/courses/' . $lang . '/day' . $day . '.php', 0.7, 'weekly');
    }
    // Certificate page
    echo url_entry($base_url . '/courses/' . $lang . '/certificate.php', 0.6, 'monthly');
}

// Games (10)
$games = [
    'word-scramble.php',
    'vocabulary-spelling.php',
    'crossword-puzzle.php',
    'vocabulary-thinking.php',
    'hangman.php',
    'spelling-word-recognition.php',
    'vocabulary-match.php',
    'bilingual-memory.php',
    'daily-challenge.php',
    'grammar-quiz.php'
];
foreach ($games as $game) {
    echo url_entry($base_url . '/games/' . $game, 0.7, 'weekly');
}
// Games index page
echo url_entry($base_url . '/games/index.php', 0.6, 'weekly');

// Blog posts (preserve all existing slugs from your urdupro.info sitemap – adapt to xoiar.com)
$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 & information 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 URDU DICTIONARY URLS (if needed) ==========
// These are from your original urdupro.info sitemap – adapt to xoiar.com
$existing_urdu_urls = [
    '%DB%81%DB%8C%D9%84%D9%88',   // hello
    '%D9%85%D8%AD%D8%A8%D8%AA',   // mohabbat
    '%DA%AF%DA%BE%D8%B1',         // ghar
    '%D9%88%D9%82%D8%AA',         // waqt
    '%D8%AF%D9%88%D8%B3%D8%AA'    // dost
];
foreach ($existing_urdu_urls as $urdu_word) {
    $url = $base_url . '/tools/urdu-dictionary.php?word=' . $urdu_word;
    echo url_entry($url, 0.64, 'monthly');
}

echo '</urlset>';
?>