Example #1
0
 /**
  * Generates document with all sitemap items from $items array
  *
  * @param string $format (options: xml, html, txt, ror-rss, ror-rdf, sitemapindex)
  *
  * @return array
  */
 public function generate($format = 'xml')
 {
     if (!$this->model->getLink()) {
         $this->model->setLink(Config::get('app.url'));
     }
     if (!$this->model->getTitle()) {
         $this->model->setTitle('Sitemap for ' . $this->model->getLink());
     }
     $channel = array('title' => $this->model->getTitle(), 'link' => $this->model->getLink());
     if ($this->model->getUseCache()) {
         if (Cache::has($this->model->getCacheKey())) {
             $format == 'sitemapindex' ? $this->model->sitemaps = Cache::get($this->model->getCacheKey()) : ($this->model->items = Cache::get($this->model->getCacheKey()));
         } else {
             $format == 'sitemapindex' ? Cache::put($this->model->getCacheKey(), $this->model->getSitemaps(), $this->model->getCacheDuration()) : Cache::put($this->model->getCacheKey(), $this->model->getItems(), $this->model->getCacheDuration());
         }
     }
     switch ($format) {
         case 'ror-rss':
             return array('content' => View::make('sitemap::ror-rss', array('items' => $this->model->getItems(), 'channel' => $channel)), 'headers' => array('Content-type' => 'text/rss+xml; charset=utf-8'));
         case 'ror-rdf':
             return array('content' => View::make('sitemap::ror-rdf', array('items' => $this->model->getItems(), 'channel' => $channel)), 'headers' => array('Content-type' => 'text/rdf+xml; charset=utf-8'));
         case 'html':
             return array('content' => View::make('sitemap::html', array('items' => $this->model->getItems(), 'channel' => $channel)), 'headers' => array('Content-type' => 'text/html'));
         case 'txt':
             return array('content' => View::make('sitemap::txt', array('items' => $this->model->getItems())), 'headers' => array('Content-type' => 'text/plain'));
         case 'sitemapindex':
             return array('content' => View::make('sitemap::sitemapindex', array('sitemaps' => $this->model->getSitemaps())), 'headers' => array('Content-type' => 'text/xml; charset=utf-8'));
         default:
             return array('content' => View::make('sitemap::xml', array('items' => $this->model->getItems())), 'headers' => array('Content-type' => 'text/xml; charset=utf-8'));
     }
 }
 /**
  * Generates document with all sitemap items from $items array
  *
  * @param string $format (options: xml, html, txt, ror-rss, ror-rdf, sitemapindex, google-news)
  *
  * @return array
  */
 public function generate($format = 'xml')
 {
     // don't render (cache) more than 50000 elements in a single sitemap
     if (count($this->model->getItems()) > 50000) {
         // get only most recent 50000
         $this->model->limitSize();
     }
     // check if caching is enabled, there is a cached content and its duration isn't expired
     if ($this->isCached()) {
         $format == 'sitemapindex' ? $this->model->resetSitemaps(Cache::get($this->model->getCacheKey())) : $this->model->resetItems(Cache::get($this->model->getCacheKey()));
     } elseif ($this->model->getUseCache()) {
         $format == 'sitemapindex' ? Cache::put($this->model->getCacheKey(), $this->model->getSitemaps(), $this->model->getCacheDuration()) : Cache::put($this->model->getCacheKey(), $this->model->getItems(), $this->model->getCacheDuration());
     }
     if (!$this->model->getLink()) {
         $this->model->setLink(Config::get('app.url'));
     }
     if (!$this->model->getTitle()) {
         $this->model->setTitle('Sitemap for ' . $this->model->getLink());
     }
     $channel = ['title' => $this->model->getTitle(), 'link' => $this->model->getLink()];
     switch ($format) {
         case 'ror-rss':
             return ['content' => View::make('sitemap::ror-rss', ['items' => $this->model->getItems(), 'channel' => $channel])->render(), 'headers' => ['Content-type' => 'text/rss+xml; charset=utf-8']];
         case 'ror-rdf':
             return ['content' => View::make('sitemap::ror-rdf', ['items' => $this->model->getItems(), 'channel' => $channel])->render(), 'headers' => ['Content-type' => 'text/rdf+xml; charset=utf-8']];
         case 'html':
             return ['content' => View::make('sitemap::html', ['items' => $this->model->getItems(), 'channel' => $channel])->render(), 'headers' => ['Content-type' => 'text/html']];
         case 'txt':
             return ['content' => View::make('sitemap::txt', ['items' => $this->model->getItems()])->render(), 'headers' => ['Content-type' => 'text/plain']];
         case 'sitemapindex':
             return ['content' => View::make('sitemap::sitemapindex', ['sitemaps' => $this->model->getSitemaps()])->render(), 'headers' => ['Content-type' => 'text/xml; charset=utf-8']];
         default:
             return ['content' => View::make('sitemap::' . $format, ['items' => $this->model->getItems()])->render(), 'headers' => ['Content-type' => 'text/xml; charset=utf-8']];
     }
 }
Example #3
0
 /**
  * Check if content is cached
  *
  * @return bool
  */
 public function isCached()
 {
     if ($this->model->getUseCache()) {
         if (Cache::has($this->model->getCacheKey())) {
             return true;
         }
     }
     return false;
 }
Example #4
0
 /**
  * Generates document with all sitemap items from $items array
  *
  * @param string $format (options: xml, html, txt, ror-rss, ror-rdf, sitemapindex, google-news)
  *
  * @return array
  */
 public function generate($format = 'xml')
 {
     // don't render (cache) more than 50000 elements in a single sitemap (or 1000 for google-news sitemap)
     if ($format == 'google-news' && count($this->model->getItems()) > 1000) {
         $this->model->limitSize(1000);
     }
     if ($format != 'google-news' && count($this->model->getItems()) > 50000) {
         $this->model->limitSize();
     }
     // check if caching is enabled, there is a cached content and its duration isn't expired
     if ($this->isCached()) {
         $format == 'sitemapindex' ? $this->model->resetSitemaps(Cache::get($this->model->getCacheKey())) : $this->model->resetItems(Cache::get($this->model->getCacheKey()));
     } elseif ($this->model->getUseCache()) {
         $format == 'sitemapindex' ? Cache::put($this->model->getCacheKey(), $this->model->getSitemaps(), $this->model->getCacheDuration()) : Cache::put($this->model->getCacheKey(), $this->model->getItems(), $this->model->getCacheDuration());
     }
     if (!$this->model->getLink()) {
         $this->model->setLink(Config::get('app.url'));
     }
     if (!$this->model->getTitle()) {
         $this->model->setTitle('Sitemap for ' . $this->model->getLink());
     }
     $channel = ['title' => $this->model->getTitle(), 'link' => $this->model->getLink()];
     // check if styles are enabled
     if ($this->model->getUseStyles()) {
         // check for custom location
         if ($this->model->getSloc() != null) {
             $style = $this->model->getSloc() . $format . '.xsl';
         } else {
             // check if style exists
             if (file_exists(public_path() . '/vendor/sitemap/styles/' . $format . '.xsl')) {
                 $style = '/vendor/sitemap/styles/' . $format . '.xsl';
             } else {
                 $style = null;
             }
         }
     } else {
         $style = null;
     }
     switch ($format) {
         case 'ror-rss':
             return ['content' => View::make('sitemap::ror-rss', ['items' => $this->model->getItems(), 'channel' => $channel, 'style' => $style])->render(), 'headers' => ['Content-type' => 'text/rss+xml; charset=utf-8']];
         case 'ror-rdf':
             return ['content' => View::make('sitemap::ror-rdf', ['items' => $this->model->getItems(), 'channel' => $channel, 'style' => $style])->render(), 'headers' => ['Content-type' => 'text/rdf+xml; charset=utf-8']];
         case 'html':
             return ['content' => View::make('sitemap::html', ['items' => $this->model->getItems(), 'channel' => $channel, 'style' => $style])->render(), 'headers' => ['Content-type' => 'text/html']];
         case 'txt':
             return ['content' => View::make('sitemap::txt', ['items' => $this->model->getItems(), 'style' => $style])->render(), 'headers' => ['Content-type' => 'text/plain']];
         case 'sitemapindex':
             return ['content' => View::make('sitemap::sitemapindex', ['sitemaps' => $this->model->getSitemaps(), 'style' => $style])->render(), 'headers' => ['Content-type' => 'text/xml; charset=utf-8']];
         default:
             return ['content' => View::make('sitemap::' . $format, ['items' => $this->model->getItems(), 'style' => $style])->render(), 'headers' => ['Content-type' => 'text/xml; charset=utf-8']];
     }
 }