HEX
Server: Apache/2.4.25 (Debian)
System: Linux server17 4.9.0-19-amd64 #1 SMP Debian 4.9.320-2 (2022-06-30) x86_64
User: web37 (1062)
PHP: 7.4.30
Disabled: show_source, highlight_file, apache_child_terminate, apache_get_modules, apache_note, apache_setenv, virtual, dl, disk_total_space, posix_getpwnam, posix_getpwuid, posix_mkfifo, posix_mknod, posix_setpgid, posix_setsid, posix_setuid, posix_uname, proc_nice, openlog, syslog, pfsockopen
Upload Files
File: /var/www/web37/htdocs/fickanzeiger/components/SiteMapGenerator.php
<?php
/**
 * Arfooo
 * 
 * @package    Arfooo
 * @copyright  Copyright (c) Arfooo Annuaire (fr) and Arfooo Directory (en)
 *             by Guillaume Hocine (c) 2007 - 2010
 *             http://www.arfooo.com/ (fr) and http://www.arfooo.net/ (en)
 * @author     Guillaume Hocine & Adrian Galewski
 * @license    http://creativecommons.org/licenses/by/2.0/fr/ Creative Commons
 */


class SiteMapGenerator
{
    private $linksCountPerFile = 50000;
    private $totalLinksCount = 0;
    private $savePath = "";
    private $xml;
    private $fp;

    public function setLinksCountPerFile($linksCount)
    {
        $this->linksCountPerFile = $linksCount;
    }

    public function setSavePath($savePath)
    {
        $this->savePath = $savePath;
    }

    private function createNewSiteMapFile()
    {
        $lp = intval($this->totalLinksCount / $this->linksCountPerFile) + 1;
        if ($lp == 1) {
            $lp = "";
        }
        $filename = "sitemap$lp.xml";
        $this->fp = fopen($this->savePath . $filename, "w");

        $xml = $this->xml = new XmlWriter();
        $xml->openMemory();
        $xml->setIndent(true);
        $xml->setIndentString(' ');
        $xml->startDocument('1.0', 'UTF-8');
        $xml->startElement("urlset");
        $xml->writeAttribute("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");

        fwrite($this->fp, $xml->flush());
    }

    public function addLink($location, $lastmod, $changefreq, $priority)
    {
        if ($this->totalLinksCount % $this->linksCountPerFile == 0) {
            if ($this->fp) {
                $this->endSiteMap();
            }
            $this->createNewSiteMapFile();
        }

        $this->totalLinksCount++;

        $xml = $this->xml;
        $xml->startElement("url");
        $xml->writeElement("loc", $location);

        if ($lastmod != "") {
            $xml->writeElement("lastmod", $lastmod);
        }
        if ($changefreq != "") {
            $xml->writeElement("changefreq", $changefreq);
        }
        if ($priority != "") {
            $xml->writeElement("priority", $priority);
        }
        $xml->endElement();
        fwrite($this->fp, $xml->flush());
    }

    public function endSiteMap()
    {
        $this->xml->endElement();
        fwrite($this->fp, $this->xml->flush());
        fclose($this->fp);
    }
}