Example #1
0
 /**
  * Add child tag
  *
  * Both single tags and compound tags can be added, to allow a nested structure.
  *
  * @param BWP_Sitemaps_Sitemap_Tag $tag the child tag to add
  * @throws LogicException if child tag already has a parent
  * @return $this
  */
 public function add_tag(BWP_Sitemaps_Sitemap_Tag $tag)
 {
     if ($tag->parent instanceof BWP_Sitemaps_Sitemap_Tag) {
         throw new LogicException('child tag already has a parent');
     }
     $tag->set_parent($this);
     // duplicate tag detected
     if (in_array($tag, $this->tags)) {
         return $this;
     }
     $this->tags[] = $tag;
     return $this;
 }
Example #2
0
 /**
  * {@inheritDoc}
  */
 protected function get_xml_item_body(array $item)
 {
     $sitemap = BWP_Sitemaps_Sitemap_Tag::create_compound_tag('sitemap');
     $sitemap->add_tag(BWP_Sitemaps_Sitemap_Tag::create_single_tag('loc', $item['location']));
     if (!empty($item['lastmod'])) {
         $sitemap->add_tag(BWP_Sitemaps_Sitemap_Tag::create_single_tag('lastmod', $item['lastmod']));
     }
     return $sitemap->get_xml();
 }
Example #3
0
 /**
  * Create an image tag from image item
  *
  * @param array $item
  * @return mixed BWP_Sitemaps_Sitemap_Tag_CompoundTag|null
  */
 protected function create_image_tag_from_sitemap_item(array $item)
 {
     if (!$this->provider->is_image_allowed() || !isset($item['image']) || !is_array($item['image'])) {
         return;
     }
     $image = $item['image'];
     // not valid location for image
     if (empty($image['location'])) {
         return;
     }
     $tags = $this->create_tags_from_sitemap_item($image, array('image:loc' => 'location', 'image:title' => 'title', 'image:caption' => 'caption'));
     $image_tag = BWP_Sitemaps_Sitemap_Tag::create_compound_tag('image:image')->add_tags($tags);
     return $image_tag;
 }
Example #4
0
 /**
  * {@inheritDoc}
  */
 protected function get_xml_item_body(array $item)
 {
     // allow overriding publication name via item data
     $item['name'] = !empty($item['name']) ? $item['name'] : $this->news_name;
     $url = BWP_Sitemaps_Sitemap_Tag::create_compound_tag('url');
     $location = BWP_Sitemaps_Sitemap_Tag::create_single_tag('loc', $item['location']);
     $news = BWP_Sitemaps_Sitemap_Tag::create_compound_tag('news:news');
     $news_publication = BWP_Sitemaps_Sitemap_Tag::create_compound_tag('news:publication');
     $news_publication_tags = $this->create_tags_from_sitemap_item($item, array('news:name' => 'name', 'news:language' => 'language'));
     $news_tags = $this->create_tags_from_sitemap_item($item, array('news:genres' => 'genres', 'news:publication_date' => 'pub_date', 'news:title' => 'title', 'news:keywords' => 'keywords'));
     $url->add_tags(array($location, $news->add_tag($news_publication->add_tags($news_publication_tags))->add_tags($news_tags)));
     if ($image = $this->create_image_tag_from_sitemap_item($item)) {
         $url->add_tag($image);
     }
     return $url->get_xml();
 }