/** * {@inheritdoc} */ public function format(FeedInterface $feed, $page, User $user = null, $generator = 'Phraseanet', Application $app = null) { $updated_on = $feed->getUpdatedOn(); $doc = new \DOMDocument('1.0', 'UTF-8'); $doc->formatOutput = true; $doc->standalone = true; $root = $this->addTag($doc, $doc, 'rss'); $root->setAttribute('version', self::VERSION); $root->setAttribute('xmlns:media', 'http://search.yahoo.com/mrss/'); $root->setAttribute('xmlns:atom', 'http://www.w3.org/2005/Atom'); $root->setAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); $channel = $this->addTag($doc, $root, 'channel'); $this->addTag($doc, $channel, 'title', $feed->getTitle()); $this->addTag($doc, $channel, 'dc:title', $feed->getTitle()); $this->addTag($doc, $channel, 'description', $feed->getSubtitle()); if (null !== $user) { $link = $this->linkGenerator->generate($feed, $user, self::FORMAT, $page); } else { $link = $this->linkGenerator->generatePublic($feed, self::FORMAT, $page); } if ($link instanceof FeedLink) { $this->addTag($doc, $channel, 'link', $link->getURI()); } if (isset($this->language)) { $this->addTag($doc, $channel, 'language', $this->language); } if (isset($this->copyright)) { $this->addTag($doc, $channel, 'copyright', $this->copyright); } if (isset($this->managingEditor)) { $this->addTag($doc, $channel, 'managingEditor', $this->managingEditor); } if (isset($this->webMaster)) { $this->addTag($doc, $channel, 'webMaster', $this->webMaster); } if ($updated_on instanceof DateTime) { $updated_on = $updated_on->format(DATE_RFC2822); $this->addTag($doc, $channel, 'pubDate', $updated_on); } if (isset($this->lastBuildDate) && $this->lastBuildDate instanceof DateTime) { $last_build = $this->lastBuildDate->format(DATE_RFC2822); $this->addTag($doc, $channel, 'lastBuildDate', $last_build); } if (isset($this->categories) && count($this->categories) > 0) { foreach ($this->categories as $category) { $this->addTag($doc, $channel, 'category', $category); } } if (isset($this->linkgenerator)) { $this->addTag($doc, $channel, 'generator', $this->linkgenerator); } if (isset($this->docs)) { $this->addTag($doc, $channel, 'docs', $this->docs); } if (isset($this->ttl)) { $this->addTag($doc, $channel, 'ttl', $this->ttl); } if (isset($this->image) && $this->image instanceof FeedRSSImage) { $image = $this->addTag($doc, $channel, 'image'); $this->addTag($doc, $image, 'url', $this->image->getUrl()); $this->addTag($doc, $image, 'title', $this->image->getTitle()); $this->addTag($doc, $image, 'link', $this->image->getLink()); if ($this->image->getWidth()) { $this->addTag($doc, $image, 'width', $this->image->getWidth()); } if ($this->image->getHeight()) { $this->addTag($doc, $image, 'height', $this->image->getHeight()); } if ($this->image->getDescription()) { $this->addTag($doc, $image, 'description', $this->image->getDescription()); } } if (isset($this->skipHours) && count($this->skipHours)) { $skipHours = $this->addTag($doc, $channel, 'skipHours'); foreach ($this->skipHours as $hour) { $this->addTag($doc, $skipHours, 'hour', $hour); } } if (isset($this->skipDays) && count($this->skipDays) > 0) { $skipDays = $this->addTag($doc, $channel, 'skipDays'); foreach ($this->skipDays as $day) { $this->addTag($doc, $skipDays, 'day', $day); } } if ($link instanceof FeedLink) { $self_link = $this->addTag($doc, $channel, 'atom:link'); $self_link->setAttribute('rel', 'self'); $self_link->setAttribute('href', $link->getURI()); } $next = $prev = null; if ($feed->hasPage($page + 1, self::PAGE_SIZE)) { if (null === $user) { $next = $this->linkGenerator->generatePublic($feed, self::FORMAT, $page + 1); } else { $next = $this->linkGenerator->generate($feed, $user, self::FORMAT, $page + 1); } } if ($feed->hasPage($page - 1, self::PAGE_SIZE)) { if (null === $user) { $prev = $this->linkGenerator->generatePublic($feed, self::FORMAT, $page - 1); } else { $prev = $this->linkGenerator->generate($feed, $user, self::FORMAT, $page - 1); } } $prefix = 'atom'; if ($prev instanceof FeedLink) { $prev_link = $this->addTag($doc, $channel, $prefix . 'link'); $prev_link->setAttribute('rel', 'previous'); $prev_link->setAttribute('href', $prev->getURI()); } if ($next instanceof FeedLink) { $next_link = $this->addTag($doc, $channel, $prefix . 'link'); $next_link->setAttribute('rel', 'next'); $next_link->setAttribute('href', $next->getURI()); } foreach ($feed->getEntries() as $item) { $this->addItem($app, $doc, $channel, $item); } return $doc->saveXML(); }
/** * {@inheritdoc} */ public function format(FeedInterface $feed, $page, User $user = null, $generator = 'Phraseanet', Application $app = null) { $updated_on = $feed->getUpdatedOn(); $document = new \DOMDocument('1.0', 'UTF-8'); $document->formatOutput = true; $document->standalone = true; $root = $this->addTag($document, $document, 'feed'); $root->setAttribute('xmlns', 'http://www.w3.org/2005/Atom'); $root->setAttribute('xmlns:media', 'http://search.yahoo.com/mrss/'); $this->addTag($document, $root, 'title', $feed->getTitle()); if ($updated_on instanceof \DateTime) { $updated_on = $updated_on->format(DATE_ATOM); $this->addTag($document, $root, 'updated', $updated_on); } $next = $prev = null; if ($feed->hasPage($page + 1, self::PAGE_SIZE)) { if (null === $user) { $next = $this->linkGenerator->generatePublic($feed, self::FORMAT, $page + 1); } else { $next = $this->linkGenerator->generate($feed, $user, self::FORMAT, $page + 1); } } if ($feed->hasPage($page - 1, self::PAGE_SIZE)) { if (null === $user) { $prev = $this->linkGenerator->generatePublic($feed, self::FORMAT, $page - 1); } else { $prev = $this->linkGenerator->generate($feed, $user, self::FORMAT, $page - 1); } } if (null !== $user) { $feedlink = $this->linkGenerator->generate($feed, $user, self::FORMAT, $page); } else { $feedlink = $this->linkGenerator->generatePublic($feed, self::FORMAT, $page); } if ($feedlink instanceof FeedLink) { $link = $this->addTag($document, $root, 'link'); $link->setAttribute('rel', 'self'); $link->setAttribute('href', $feedlink->getURI()); $this->addTag($document, $root, 'id', $feedlink->getURI()); } if ($prev instanceof FeedLink) { $prev_link = $this->addTag($document, $root, 'link'); $prev_link->setAttribute('rel', 'previous'); $prev_link->setAttribute('href', $prev->getURI()); } if ($next instanceof FeedLink) { $next_link = $this->addTag($document, $root, 'link'); $next_link->setAttribute('rel', 'next'); $next_link->setAttribute('href', $next->getURI()); } if (null !== $generator) { $this->addTag($document, $root, 'generator', $generator); } if (null !== $feed->getSubtitle()) { $this->addTag($document, $root, 'subtitle', $feed->getSubtitle()); } if (null !== $feed->getIconUrl()) { $this->addTag($document, $root, 'icon', $feed->getIconUrl()); } if (isset($this->author)) { $author = $this->addTag($document, $root, 'author'); if (isset($this->author_email)) { $this->addTag($document, $author, 'email', $this->author_email); } if (isset($this->author_name)) { $this->addTag($document, $author, 'name', $this->author_name); } if (isset($this->author_url)) { $this->addTag($document, $author, 'uri', $this->author_url); } } foreach ($feed->getEntries() as $item) { $this->addItem($app, $document, $root, $item, $feedlink); } return $document->saveXML(); }