<?php
/**
 * Sitemap XML Export Filter
 */

if (!defined('ROOT_DIR')) {
    die('You cannot access this file directly!');
}

class ExportFilter extends Export {
    
    public function get_export_csv() {
        header('Content-Type: application/xml; charset=UTF-8');
        
        $output = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
        $output .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
        
        // Startseite
        $output .= $this->addUrl('https://intelectra.de/');
        
        // Artikel aus der Datenbank holen
        $sql = "SELECT id, last_update FROM item WHERE active = 1";
        $result = $this->db->query($sql);
        
        while($row = $result->fetch_object()) {
            $url = 'https://intelectra.de/index.php?website_modul=website_item&id=' . $row->id;
            $output .= $this->addUrl($url, $row->last_update);
        }
        
        // Kategorien
        $sql = "SELECT id, last_update FROM itemgroup WHERE active = 1";
        $result = $this->db->query($sql);
        
        while($row = $result->fetch_object()) {
            $url = 'https://intelectra.de/index.php?website_modul=website_itemgroup&id=' . $row->id;
            $output .= $this->addUrl($url, $row->last_update);
        }
        
        $output .= '</urlset>';
        
        // Update export statistics
        $this->update_export_statistics(substr_count($output, '<url>'));
        
        return $output;
    }
    
    private function addUrl($loc, $lastmod = '') {
        $output = "  <url>\n";
        $output .= "    <loc>" . htmlspecialchars($loc) . "</loc>\n";
        if($lastmod) {
            $output .= "    <lastmod>" . date('Y-m-d', strtotime($lastmod)) . "</lastmod>\n";
        }
        $output .= "  </url>\n";
        return $output;
    }
} 