private static function generateSitemapIndex()
 {
     $sitemapIndex = new SitemapIndex();
     foreach (glob("*.xml") as $filename) {
         if ($filename != 'sitemap.xml') {
             $sitemapIndex->add(Url::base(true) . '/' . $filename, date('c', time()));
         }
     }
     // Write it to a file
     file_put_contents('sitemap.xml', (string) $sitemapIndex);
     echo "Generate sitemap index complete <br>";
 }
 /**
  * Creates a Sitemap index given an Iterator of Sitemaps
  * @param Iterator $sitemaps
  * @return mixed
  */
 public function createSitemapIndex(Iterator $sitemaps)
 {
     $groupName = $this->randomHash();
     $sitemapIndexes = new ArrayObject();
     $sitemapIndex = new SitemapIndex();
     $lastmod = date(DateTime::W3C);
     foreach ($sitemaps as $sitemapPath) {
         // Ignoring because this is an edge case for HUGE sites...like Facebook.
         // @codeCoverageIgnoreStart
         if ($sitemapIndex->hasMaxUrlCount()) {
             $sitemapIndexes->append($this->writeSitemap($groupName, $sitemapIndex));
             $sitemapIndex = new SitemapIndex();
         }
         // @codeCoverageIgnoreEnd
         $sitemapIndex->add($this->fileUrl($sitemapPath), $lastmod);
     }
     $sitemapIndexes->append($this->writeSitemap($groupName, $sitemapIndex));
     // This will probably never happen, as it would mean over 2.5 Billion URLs in the
     // sitemap.  So unless Facebook uses this library, this will never happen, so ignore
     // it from code coverage.
     // @codeCoverageIgnoreStart
     if ($sitemapIndexes->count() > 1) {
         return $this->createSitemapIndex($sitemapIndexes->getIterator());
     }
     // @codeCoverageIgnoreEnd
     return $this->fileUrl($sitemapIndexes[0]);
 }
Ejemplo n.º 3
0
 public function publishersAction(Request $request)
 {
     $siteMapIndex = new SitemapIndex();
     $router = $this->get('router');
     /** @var \Doctrine\ORM\EntityManager $em */
     $em = $this->getDoctrine()->getManager();
     $publishers = $em->getRepository('OjsJournalBundle:Publisher')->findAll();
     foreach ($publishers as $publisher) {
         /** @var Publisher $publisher */
         $siteMapIndex->add($request->getScheme() . ':' . $router->generate('ojs_publisher_sitemap', ['publisher' => $publisher->getSlug(), '_format' => 'xml']), $publisher->getUpdated()->format('Y-m-d'));
     }
     return $this->response($siteMapIndex);
 }