<?php
// Set the content type to XML and specify charset for UTF-8 encoded content
header('Content-Type: application/xml; charset=utf-8');

// Include your data model or class file; adjust the path as needed
require_once("../models/class.php");

// Initialize your data object; ensure that Mallper class has a method for fetching articles
$objData = new Mallper();

// Define a function to filter specific characters; adjust as needed
function filterZwnj($input) {
    $charactersToFilter = array('‌', 'Rzwnj', '&', ';'); // Ensure 'zwnj' is correctly represented
    $filteredInput = str_replace($charactersToFilter, '', $input);
    return $filteredInput;
}

// Begin the XML output for the sitemap
echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">

    <!-- Static URL example -->
    <url>
        <loc>https://www.kurdmedia.net/kurdi/</loc>
        <changefreq>hourly</changefreq>
    </url>

    <?php
    // Fetch article data; ensure 'getData' correctly fetches the desired articles
    $articles = $objData->getData('so_article', 'id', 'ignore');
    if (is_array($articles) && !empty($articles)) {
        foreach ($articles as $article) {
            $articleId = filterZwnj($article['id']); // Apply the filter if necessary
            echo '<url>';
            echo '<loc>https://kurdmedia.net/articles.php?id=' . htmlspecialchars($articleId) . '</loc>';
            echo '<changefreq>hourly</changefreq>';
            echo '</url>';
        }
    }
    ?>

</urlset>

