[
  {
    "path": ".gitignore",
    "content": "/vendor/\ncomposer.lock\n\n"
  },
  {
    "path": "LICENSE",
    "content": "The MIT License (MIT)\n\nCopyright (c) 2009-2017 Osman Üngür\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "**For the 90's people, i'm keeping this repository as 5.2 compatible. If you need PSR-0 and Composer compatible version, [here is a fork that maintained by Evert Pot](https://github.com/evert/sitemap-php).**\n\nWhat is sitemap-php ?\n----------\n\nFast and lightweight class for generating Google sitemap XML files and index of sitemap files. Written on PHP and uses XMLWriter extension (wrapper for libxml xmlWriter API) for creating XML files. XMLWriter extension is enabled by default in PHP 5 >= 5.1.2. If you having more than 50000 url, it splits items to seperated files. _(In benchmarks, 1.000.000 url was generating in 8 seconds)_\n\nHow to use\n----------\n\nInclude Sitemap.php file to your PHP document and call Sitemap class with your base domain.\n\n\tinclude 'Sitemap.php';\n\t$sitemap = new Sitemap('http://example.com');\t\n\nNow, we need to define path for saving XML files. This can be relative like `xmls` or absolute `/path/to/your/folder` and *must be a writable folder*. In default it uses same folder with your script.\n\n\t$sitemap->setPath('xmls/');\n\nGenerated XML file names defaulted to `sitemap-*.xml`, you can customize prefix of filenames with `setFilename` method.\n\n\t$sitemap->setFilename('customsitemap');\n\n\t\nWe'll add sitemap url's with `addItem` method. In this method, only first parameter (location) is required.\n\n\t$sitemap->addItem('/', '1.0', 'daily', 'Today');\n\t$sitemap->addItem('/about', '0.8', 'monthly', 'Jun 25');\n\t$sitemap->addItem('/contact', '0.6', 'yearly', '14-12-2009');\n\t$sitemap->addItem('/otherpage');\n\nw/ method chaining.\n\n\t$sitemap->addItem('/projects', '0.8')->addItem('/somepage')->addItem('/hiddenpage', '0.4', 'yearly', '01-01-2011')->addItem('/rss');\n\nfrom a sql result, or whatever.\n\n\t$query = Doctrine_Query::create()\n\t\t\t\t\t->select('p.created_at, p.slug')\n\t\t\t\t\t->from('Posts p')\n\t\t\t\t\t->orderBy('p.id DESC')\n\t\t\t\t\t->useResultCache(true);\n\t$posts =  $query->fetchArray(array(), Doctrine_Core::HYDRATE_ARRAY);\n    foreach ($posts as $post) {\n        $sitemap->addItem('/post/' . $post['slug'], '0.6', 'weekly', $post['created_at']);\n    }\n\nIf you need to change domain for sitemap instance, you can override it via `setDomain` method.\n\n\t$sitemap->setDomain('http://blog.example.com');\n\t\nFinally we create index for sitemap files. **This method also closes tags of latest generated xml file.**\n\n\t$sitemap->createSitemapIndex('http://example.com/sitemap/', 'Today');\n\t\nWhen you run your script, it generates and saves XML files to given path.\n\nsitemap-0.xml\n\n\t<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\t<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n\t <url>\n\t  <loc>http://example.com/</loc>\n\t  <priority>1.0</priority>\n\t  <changefreq>daily</changefreq>\n\t  <lastmod>2011-04-07</lastmod>\n\t </url>\n\t <url>\n\t  <loc>http://example.com/about</loc>\n\t  <priority>0.8</priority>\n\t  <changefreq>monthly</changefreq>\n\t  <lastmod>2011-06-25</lastmod>\n\t </url>\n\t <url>\n\t  <loc>http://example.com/contact</loc>\n\t  <priority>0.6</priority>\n\t  <changefreq>yearly</changefreq>\n\t  <lastmod>2009-12-14</lastmod>\n\t </url>\n\t <url>\n\t  <loc>http://example.com/otherpage</loc>\n\t  <priority>0.5</priority>\n\t </url>\n\t</urlset>\n\t\nsitemap-index.xml\n\n\t<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\t<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n\t <sitemap>\n\t  <loc>http://example.com/sitemap/sitemap-0.xml</loc>\n\t  <lastmod>2011-04-07</lastmod>\n\t </sitemap>\n\t</sitemapindex>\n\t\nYou need to submit sitemap-index.xml to Google Sitemaps.\n\n**Please note that, generating sitemaps not overrides any previous generated sitemap file. You need to delete old files before the operation.**\n\n\t$ rm -rv sitemap-*\n\nFor the truncating a file with php, use the following snippet:\n\n\t$handle = fopen(\"/path/to/sitemap/file.xml\", \"w\");\n\tfclose($handle);\n"
  },
  {
    "path": "composer.json",
    "content": "{\n    \"name\": \"osm/sitemap-php\",\n    \"description\": \"Fast and lightweight library for generating Google sitemap XML files and index of sitemaps\",\n    \"type\": \"library\",\n    \"license\": \"MIT\",\n    \"homepage\": \"https://github.com/o/sitemap-php/\",\n    \"authors\": [\n        {\n            \"email\": \"osmanungur@gmail.com\",\n            \"name\": \"Osman Ungur\"\n        },\n        {\n            \"homepage\": \"https://github.com/o/sitemap-php/graphs/contributors\",\n            \"name\": \"Community\"\n        }\n    ],\n    \"keywords\": [\n        \"google\",\n        \"sitemap\",\n        \"generator\",\n        \"xml\",\n        \"seo\"\n    ],\n    \"require\": {\n        \"php\": \">=5.6\"\n    },\n    \"require-dev\": {\n        \"phpunit/phpunit\": \"^5.7\"\n    },\n    \"autoload\": {\n        \"psr-4\": {\n            \"Osm\\\\Sitemap\\\\\": \"src/\"\n        }\n    },\n    \"minimum-stability\": \"dev\"\n}\n"
  },
  {
    "path": "phpunit.xml.dist",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<phpunit backupGlobals=\"false\"\n         backupStaticAttributes=\"false\"\n         colors=\"true\"\n         convertErrorsToExceptions=\"true\"\n         convertNoticesToExceptions=\"true\"\n         convertWarningsToExceptions=\"true\"\n         processIsolation=\"false\"\n         stopOnFailure=\"false\"\n         syntaxCheck=\"false\"\n         bootstrap=\"./vendor/autoload.php\">\n\n    <testsuites>\n        <testsuite name=\"Sitemap PHP Test Suite\">\n            <directory>tests</directory>\n        </testsuite>\n    </testsuites>\n\n    <groups>\n        <exclude>\n            <group>benchmark</group>\n        </exclude>\n    </groups>\n\n</phpunit>"
  },
  {
    "path": "src/AbstractGenerator.php",
    "content": "<?php\n\nnamespace Osm\\Sitemap;\n\nuse XMLWriter;\n\nabstract class AbstractGenerator\n{\n\n    const EXTENSION_XML = '.xml';\n\n    const SEPARATOR = '-';\n\n    /**\n     * @var XMLWriter\n     */\n    protected $xmlWriter;\n\n    /**\n     * @var string\n     */\n    protected $baseUrl;\n\n    /**\n     * @var string\n     */\n    protected $fileName;\n\n    /**\n     * @var string\n     */\n    protected $directory;\n\n    /**\n     * @var integer\n     */\n    protected $maximumUrlCount;\n\n    /**\n     * @var integer\n     */\n    protected $currentUrlCount = 0;\n\n    /**\n     * @var integer\n     */\n    protected $currentFileCount = 0;\n\n    /**\n     * AbstractGenerator constructor.\n     */\n    public function __construct()\n    {\n        $this->maximumUrlCount = $this->getDefaultMaximumUrlCount();\n    }\n\n    abstract protected function getDefaultMaximumUrlCount();\n\n    abstract protected function startXml();\n\n    /**\n     * @return int\n     */\n    public function getMaximumUrlCount()\n    {\n        return $this->maximumUrlCount;\n    }\n\n    /**\n     * @param int $maximumUrlCount\n     */\n    public function setMaximumUrlCount($maximumUrlCount)\n    {\n        $this->maximumUrlCount = $maximumUrlCount;\n    }\n\n    public function getCurrentXmlFileName()\n    {\n        if ($this->currentFileCount) {\n            return $this->directory.DIRECTORY_SEPARATOR.$this->fileName.self::SEPARATOR.$this->currentFileCount.self::EXTENSION_XML;\n        }\n\n        return $this->directory.DIRECTORY_SEPARATOR.$this->fileName.self::EXTENSION_XML;\n    }\n\n    protected function openXml()\n    {\n        $this->xmlWriter = new XMLWriter();\n        $this->xmlWriter->openURI($this->getCurrentXmlFileName());\n        $this->xmlWriter->startDocument('1.0', 'UTF-8');\n        $this->xmlWriter->setIndent(true);\n\n        $this->startXml();\n    }\n\n\n    public function closeXml()\n    {\n        $this->xmlWriter->endElement();\n        $this->xmlWriter->endDocument();\n    }\n\n    /**\n     * @return bool\n     */\n    protected function shouldANewFileToBeCreated()\n    {\n        return ($this->currentUrlCount % $this->maximumUrlCount) === 0;\n    }\n\n    /**\n     * @return string\n     */\n    public function getBaseUrl()\n    {\n        return $this->baseUrl;\n    }\n\n    /**\n     * @return string\n     */\n    public function getFileName()\n    {\n        return $this->fileName;\n    }\n\n    /**\n     * @return string\n     */\n    public function getDirectory()\n    {\n        return $this->directory;\n    }\n\n    /**\n     * @return int\n     */\n    public function getCurrentUrlCount()\n    {\n        return $this->currentUrlCount;\n    }\n\n    /**\n     * @return int\n     */\n    public function getCurrentFileCount()\n    {\n        return $this->currentFileCount;\n    }\n\n}"
  },
  {
    "path": "src/WebSitemapGenerator.php",
    "content": "<?php\n\nnamespace Osm\\Sitemap;\n\nclass WebSitemapGenerator extends AbstractGenerator\n{\n\n    const SCHEMA = 'http://www.sitemaps.org/schemas/sitemap/0.9';\n    const DEFAULT_DIRECTORY = './';\n    const DEFAULT_FILENAME = 'sitemap';\n\n    public function __construct($baseUrl, $directory = self::DEFAULT_DIRECTORY, $fileName = self::DEFAULT_FILENAME)\n    {\n        parent::__construct();\n        $this->baseUrl = $baseUrl;\n        $this->directory = $directory;\n        $this->fileName = $fileName;\n    }\n\n    protected function getDefaultMaximumUrlCount()\n    {\n        return 50000;\n    }\n\n    protected function startXml()\n    {\n        $this->xmlWriter->startElement('urlset');\n        $this->xmlWriter->writeAttribute('xmlns', self::SCHEMA);\n    }\n\n    protected function getFormattedLastModifiedDate(\\DateTime $dateTime)\n    {\n        return $dateTime->format(\\DateTime::W3C);\n    }\n\n    public function addItem(WebSitemapItem $item)\n    {\n        if ($this->shouldANewFileToBeCreated()) {\n            if ($this->currentFileCount) {\n                $this->closeXml();\n            }\n            $this->openXml();\n            ++$this->currentFileCount;\n        }\n        ++$this->currentUrlCount;\n        $this->xmlWriter->startElement('url');\n        $this->xmlWriter->writeElement('loc', $this->baseUrl.$item->getLocation());\n\n        if ($item->getPriority()) {\n            $this->xmlWriter->writeElement('priority', $item->getPriority());\n        }\n\n        if ($item->getChangeFrequency()) {\n            $this->xmlWriter->writeElement('changefreq', $item->getChangeFrequency());\n        }\n\n        if ($item->getLastModified()) {\n            $this->xmlWriter->writeElement(\n                'lastmod',\n                $this->getFormattedLastModifiedDate($item->getLastModified())\n            );\n        }\n\n        $this->xmlWriter->endElement();\n\n        return $this;\n    }\n\n\n}"
  },
  {
    "path": "src/WebSitemapItem.php",
    "content": "<?php\n\nnamespace Osm\\Sitemap;\n\n\nclass WebSitemapItem\n{\n\n    const DEFAULT_PRIORITY = 0.5;\n\n    const CHANGE_FREQ_ALWAYS = 'always';\n    const CHANGE_FREQ_HOURLY = 'hourly';\n    const CHANGE_FREQ_DAILY = 'daily';\n    const CHANGE_FREQ_WEEKLY = 'weekly';\n    const CHANGE_FREQ_MONTHLY = 'monthly';\n    const CHANGE_FREQ_YEARLY = 'yearly';\n    const CHANGE_FREQ_NEVER = 'never';\n\n    /**\n     * @var string\n     */\n    private $location;\n\n    /**\n     * @var float\n     */\n    private $priority;\n\n    /**\n     * @var string\n     */\n    private $changeFrequency;\n\n    /**\n     * @var \\DateTime\n     */\n    private $lastModified;\n\n    /**\n     * WebSitemapItem constructor.\n     * @param string $location\n     */\n    public function __construct($location)\n    {\n        $this->location = $location;\n    }\n\n    /**\n     * @return string\n     */\n    public function getLocation()\n    {\n        return $this->location;\n    }\n\n    /**\n     * @param string $location\n     */\n    public function setLocation($location)\n    {\n        $this->location = $location;\n    }\n\n    /**\n     * @return float\n     */\n    public function getPriority()\n    {\n        return $this->priority;\n    }\n\n    /**\n     * @param float $priority\n     */\n    public function setPriority($priority)\n    {\n        $this->priority = $priority;\n    }\n\n    /**\n     * @return string\n     */\n    public function getChangeFrequency()\n    {\n        return $this->changeFrequency;\n    }\n\n    /**\n     * @param string $changeFrequency\n     */\n    public function setChangeFrequency($changeFrequency)\n    {\n        $this->changeFrequency = $changeFrequency;\n    }\n\n    /**\n     * @return \\DateTime\n     */\n    public function getLastModified()\n    {\n        return $this->lastModified;\n    }\n\n    /**\n     * @param \\DateTime $lastModified\n     */\n    public function setLastModified($lastModified)\n    {\n        $this->lastModified = $lastModified;\n    }\n    \n}"
  },
  {
    "path": "tests/WebSitemapGeneratorTest.php",
    "content": "<?php\n\nnamespace Osm\\Sitemap;\n\nuse PHPUnit\\Framework\\TestCase;\n\nclass WebSitemapGeneratorTest extends TestCase\n{\n    const XML_FOLDER = __DIR__. '/xmls/';\n    const GENERATED_XML_FOLDER = self::XML_FOLDER . 'generated/';\n\n    public function testGetDefaultMaximumUrlCount()\n    {\n        $g = new WebSitemapGenerator('sitemap.nl');\n        $this->assertEquals(50000, $g->getMaximumUrlCount());\n\n        $g->setMaximumUrlCount(100);\n        $this->assertEquals(100, $g->getMaximumUrlCount());\n    }\n\n    public function testConstructor()\n    {\n        $g = new WebSitemapGenerator('sitemap.nl');\n        $this->assertEquals('sitemap.nl', $g->getBaseUrl());\n        $this->assertEquals('./', $g->getDirectory());\n        $this->assertEquals('sitemap', $g->getFileName());\n\n        $h = new WebSitemapGenerator('sub.sitemap.de', '/tmp', 'map');\n        $this->assertEquals('sub.sitemap.de', $h->getBaseUrl());\n        $this->assertEquals('/tmp', $h->getDirectory());\n        $this->assertEquals('map', $h->getFileName());\n    }\n\n    public function testStartXmlCalledAndFileCreated()\n    {\n        $filename = 'test-start-xml-called';\n        $filenameWithExt = $filename.'.xml';\n\n        $g = new WebSitemapGenerator('sitemap.nl', self::GENERATED_XML_FOLDER, $filename);\n        $g->addItem(new WebSitemapItem('/foo'));\n        $g->closeXml();\n\n        $this->assertFileExists(self::GENERATED_XML_FOLDER.$filenameWithExt);\n\n        $this->assertXmlFileEqualsXmlFile(\n            self::XML_FOLDER.$filenameWithExt,\n            self::GENERATED_XML_FOLDER.$filenameWithExt\n        );\n    }\n\n\n}\n"
  },
  {
    "path": "tests/xmls/generated/.gitkeep",
    "content": ""
  },
  {
    "path": "tests/xmls/generated/test-start-xml-called.xml",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n <url>\n  <loc>sitemap.nl/foo</loc>\n </url>\n</urlset>\n"
  },
  {
    "path": "tests/xmls/test-start-xml-called.xml",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n <url>\n  <loc>sitemap.nl/foo</loc>\n </url>\n</urlset>\n"
  }
]