/**
  * Formats the specified response.
  * @param Response $response the response to be formatted.
  */
 public function format(Response $response)
 {
     $charset = $this->encoding === null ? $response->charset : $this->encoding;
     if (stripos($this->contentType, 'charset') === false) {
         $this->contentType .= '; charset=' . $charset;
     }
     $response->getHeaders()->set('Content-Type', $this->contentType);
     foreach ($response->data as $value) {
         $this->_sitemap->add($value['loc'], Helper::getValue($value['lastmod']), Helper::getValue($value['changefreq']), isset($value['priority']) ? $value['priority'] : null);
     }
     $response->content = $this->_sitemap->toString();
 }
 private static function generateSitemap($name, $urls)
 {
     $sitemap = new Sitemap();
     foreach ($urls as $url) {
         $sitemap->add($url, date('c', time()), ChangeFrequency::DAILY, 1.0);
     }
     // Write it to a file
     file_put_contents($name, (string) $sitemap);
     echo "Generate {$name} complete <br>";
 }
    public function testToString()
    {
        $expected = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>http://foo.com</loc>
    <lastmod>2005-01-02T00:00:00+00:00</lastmod>
    <changefreq>weekly</changefreq>
    <priority>1</priority>
  </url>
  <url>
    <loc>http://foo.com/about</loc>
    <lastmod>2005-01-01T00:00:00+00:00</lastmod>
  </url>
</urlset>

XML;
        $sitemap = new Sitemap();
        $sitemap->add('http://foo.com', '2005-01-02', ChangeFrequency::WEEKLY, 1.0);
        $sitemap->add('http://foo.com/about', '2005-01-01');
        $this->assertEquals($expected, $sitemap->toString());
    }
 /**
  * Generates the sitemap(s) using the iterator previously set.
  * @param \Iterator $iterator
  * @throws \RuntimeException
  * @return string The URL for the entry Sitemap
  */
 public function createSitemap(Iterator $iterator)
 {
     $groupName = $this->randomHash();
     $paths = new ArrayObject();
     $sitemap = new Sitemap();
     foreach ($iterator as $entry) {
         if ($sitemap->hasMaxUrlCount()) {
             $paths->append($this->writeSitemap($groupName, $sitemap));
             $sitemap = new Sitemap();
         }
         list($url, $lastmod, $changefreq, $priority) = $this->parseEntry($entry);
         $sitemap->add($url, $lastmod, $changefreq, $priority);
     }
     $paths->append($this->writeSitemap($groupName, $sitemap));
     if ($paths->count() > 1) {
         return $this->createSitemapIndex($paths->getIterator());
     }
     return $this->fileUrl($paths[0]);
 }
示例#5
0
 public function renderDefault()
 {
     $cache = new Cache($this->cacheStorage, 'sitemap');
     $string = $cache->load('full', function (&$dependencies) {
         $dependencies[Cache::EXPIRE] = '1 day';
         $map = new Cartographer\Sitemap();
         $map->add($this->link('//Auth:registration'), NULL, Freq::YEARLY);
         $map->add($this->link('//Auth:resetPassword'), NULL, Freq::YEARLY);
         $map->add($this->link('//Homepage:default'), filemtime(__DIR__ . '/../templates/views/Homepage/default.latte'), Freq::YEARLY);
         $map->add($this->link('//Text:about'), filemtime(__DIR__ . '/../templates/views/Text/about.latte'), Freq::YEARLY);
         foreach ($this->orm->schemas->findAll() as $schema) {
             $map->add($this->absoluteLink($schema), NULL, Freq::MONTHLY);
         }
         foreach ($this->orm->blocks->findAll() as $block) {
             $map->add($this->absoluteLink($block), NULL, Freq::MONTHLY);
         }
         foreach ($this->orm->contents->findAll() as $content) {
             $map->add($this->absoluteLink($content), NULL, Freq::YEARLY);
         }
         return $map->toString();
     });
     $this->getHttpResponse()->setContentType('application/xml');
     $this->sendResponse(new TextResponse($string));
 }
示例#6
0
 public function staticAction(Request $request)
 {
     $siteMap = new Sitemap();
     $router = $this->get('router');
     $maps = ['ojs_public_index', 'ojs_browse_index', 'ojs_publishers_index', 'ojs_journals_index', 'tos', 'privacy'];
     foreach ($maps as $map) {
         $siteMap->add($request->getSchemeAndHttpHost() . $router->generate($map), (new \DateTime())->format('Y-m-d'));
     }
     return $this->response($siteMap);
 }