/** * @return string */ public function __toString() { $urlSet = new Urlset(); $this->addProducts($urlSet); $this->addTags($urlSet); $this->output->addProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="/xml-sitemap.xsl"'); return $this->output->getOutput($urlSet); }
* @return boolean */ $buildSitemap = function (array $entries, $domain, $folder) { $urlSet = new Urlset(); foreach ($entries as $path => $entry) { $url = new Url("{$domain}{$path}"); // todo better detection of domain by env $url->setLastMod($entry['lastmod']); // todo check if exists $url->setChangeFreq($entry['changefreq']); // todo check if exists $url->setPriority($entry['priority']); // todo check if exists $urlSet->addUrl($url); } $output = new Output(); $output->setIndentString(' '); // change indentation from 4 to 2 spaces $tempSitemap = __DIR__ . "/../../web/public/{$folder}/sitemap-new.xml"; $finalSitemap = __DIR__ . "/../../web/public/{$folder}/sitemap.xml"; $sitemapHandle = fopen($tempSitemap, 'w'); fwrite($sitemapHandle, $output->getOutput($urlSet)); fclose($sitemapHandle); rename($tempSitemap, $finalSitemap); }; /********************************************* * blog.jacobemerick.com *********************************************/ $reduceToMostRecentBlogPost = function ($recentPost, $post) { if (is_null($recentPost)) { return $post;