protected function formatBody(Url $url)
 {
     $buffer = "\t" . '<loc>' . $this->escape($url->getLoc()) . '</loc>' . "\n";
     if ($url->getLastmod() !== null) {
         $buffer .= "\t" . '<lastmod>' . $this->escape($url->getLastmod()) . '</lastmod>' . "\n";
     }
     if ($url->getChangefreq() !== null) {
         $buffer .= "\t" . '<changefreq>' . $this->escape($url->getChangefreq()) . '</changefreq>' . "\n";
     }
     if ($url->getPriority() !== null) {
         $buffer .= "\t" . '<priority>' . $this->escape($url->getPriority()) . '</priority>' . "\n";
     }
     foreach ($url->getVideos() as $video) {
         $buffer .= $this->formatVideo($video);
     }
     foreach ($url->getImages() as $image) {
         $buffer .= $this->formatImage($image);
     }
     return $buffer;
 }
Пример #2
0
 /**
  * Add an entry to the sitemap.
  *
  * @param Url $url The URL to add. If the URL is relative, the base host will be prepended.
  *
  * @return Sitemap The current sitemap (for fluent interface).
  */
 public function add(Url $url)
 {
     if ($this->isSitemapIndexable() && $this->getCurrentSitemapIndex()->getUrlCount() >= $this->limit) {
         $this->addSitemapIndex($this->createSitemapIndex());
     }
     $loc = $url->getLoc();
     if (empty($loc)) {
         throw new \InvalidArgumentException('The url MUST have a loc attribute');
     }
     if ($this->baseHost !== null) {
         if ($this->needHost($loc)) {
             $url->setLoc($this->baseHost . $loc);
         }
         foreach ($url->getVideos() as $video) {
             if ($this->needHost($video->getThumbnailLoc())) {
                 $video->setThumbnailLoc($this->baseHost . $video->getThumbnailLoc());
             }
             if ($this->needHost($video->getContentLoc())) {
                 $video->setContentLoc($this->baseHost . $video->getContentLoc());
             }
             $player = $video->getPlayerLoc();
             if ($player !== null && $this->needHost($player['loc'])) {
                 $video->setPlayerLoc($this->baseHost . $player['loc'], $player['allow_embed'], $player['autoplay']);
             }
             $gallery = $video->getGalleryLoc();
             if ($gallery !== null && $this->needHost($gallery['loc'])) {
                 $video->setGalleryLoc($this->baseHost . $gallery['loc'], $gallery['title']);
             }
         }
         foreach ($url->getImages() as $image) {
             if ($this->needHost($image->getLoc())) {
                 $image->setLoc($this->baseHost . $image->getLoc());
             }
             if ($this->needHost($image->getLicense())) {
                 $image->setLicense($this->baseHost . $image->getLicense());
             }
         }
     }
     $this->dumper->dump($this->formatter->formatUrl($url));
     if ($this->isSitemapIndexable()) {
         $this->getCurrentSitemapIndex()->incrementUrl();
     }
     return $this;
 }
 public function formatUrl(Url $url)
 {
     return $this->escape($url->getLoc()) . "\n";
 }
 public function formatUrl(Url $url)
 {
     return sprintf("\t%s\n", $url->getLoc());
 }