language = $language; return $this; } /** * * @param string $language * @return Feed_XML_RSS */ public function set_copyright($copyright) { $this->copyright = $copyright; return $this; } /** * * @param string $managingEditor * @return Feed_XML_RSS */ public function set_managingEditor($managingEditor) { $this->managingEditor = $managingEditor; return $this; } /** * * @param string $webMaster * @return Feed_XML_RSS */ public function set_webMaster($webMaster) { $this->webMaster = $webMaster; return $this; } /** * * @param DateTime $lastBuildDate * @return Feed_XML_RSS */ public function set_lastBuildDate(DateTime $lastBuildDate) { $this->lastBuildDate = $lastBuildDate; return $this; } /** * * @param string $category * @return Feed_XML_RSS */ public function set_category($category) { $this->categories[] = $category; return $this; } /** * * @param string $docs * @return Feed_XML_RSS */ public function set_docs($docs) { $this->docs = $docs; return $this; } /** * * @param int $ttl * @return Feed_XML_RSS */ public function set_ttl($ttl) { $this->ttl = $ttl; return $this; } /** * * @param Feed_XML_RSS_Image $image * @return Feed_XML_RSS */ public function set_image(Feed_XML_RSS_Image $image) { $this->image = $image; return $this; } /** * * @param string $skipHours * @return Feed_XML_RSS */ public function set_skipHour($hour) { $this->skipHours[] = (int) $hour; return $this; } /** * * @param string $skipDays * @return Feed_XML_RSS */ public function set_skipDays($day) { $this->skipDays[] = $day; return $this; } /** * * @return string */ public function render() { $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', $this->title); $this->addTag($doc, $channel, 'dc:title', $this->title); $this->addTag($doc, $channel, 'description', $this->subtitle); if ($this->link instanceof Feed_Link) $this->addTag($doc, $channel, 'link', $this->link->get_href()); if ($this->language) $this->addTag($doc, $channel, 'language', $this->language); if ($this->copyright) $this->addTag($doc, $channel, 'copyright', $this->copyright); if ($this->managingEditor) $this->addTag($doc, $channel, 'managingEditor', $this->managingEditor); if ($this->webMaster) $this->addTag($doc, $channel, 'webMaster', $this->webMaster); if ($this->updated_on instanceof DateTime) { $updated_on = $this->updated_on->format(DATE_RFC2822); $this->addTag($doc, $channel, 'pubDate', $updated_on); } if ($this->lastBuildDate instanceof DateTime) { $last_build = $this->lastBuildDate->format(DATE_RFC2822); $this->addTag($doc, $channel, 'lastBuildDate', $last_build); } if (count($this->categories) > 0) { foreach ($this->categories as $category) { $this->addTag($doc, $channel, 'category', $category); } } if ($this->generator) $this->addTag($doc, $channel, 'generator', $this->generator); if ($this->docs) $this->addTag($doc, $channel, 'docs', $this->docs); if ($this->ttl) $this->addTag($doc, $channel, 'ttl', $this->ttl); if ($this->image instanceof Feed_XML_RSS_Image) { $image = $this->addTag($doc, $channel, 'image'); $this->addTag($doc, $image, 'url', $this->image->get_url()); $this->addTag($doc, $image, 'title', $this->image->get_title()); $this->addTag($doc, $image, 'link', $this->image->get_link()); if ($this->image->get_width()) $this->addTag($doc, $image, 'width', $this->image->get_width()); if ($this->image->get_height()) $this->addTag($doc, $image, 'height', $this->image->get_height()); if ($this->image->get_description()) $this->addTag($doc, $image, 'description', $this->image->get_description()); } if (count($this->skipHours)) { $skipHours = $this->addTag($doc, $channel, 'skipHours'); foreach ($this->skipHours as $hour) { $this->addTag($doc, $skipHours, 'hour', $hour); } } if (count($this->skipDays) > 0) { $skipDays = $this->addTag($doc, $channel, 'skipDays'); foreach ($this->skipDays as $day) { $this->addTag($doc, $skipDays, 'day', $day); } } if ($this->link instanceof Feed_Link) { $self_link = $this->addTag($doc, $channel, 'atom:link'); $self_link->setAttribute('rel', 'self'); $self_link->setAttribute('href', $this->link->get_href()); } $this->add_navigation($doc, $channel, true); foreach ($this->items as $item) { $this->add_item($doc, $channel, $item); } return $doc->saveXML(); } /** * * @param DOMDocument $document * @param DOMNode $node * @param Feed_Entry_Adapter $entry * @return DOMElement */ protected function add_item(DOMDocument $document, DOMNode $node, Feed_Entry_Adapter $entry) { $item = $this->addTag($document, $node, 'item'); $link = $entry->get_link(); $this->addTag($document, $item, 'title', $entry->get_title()); $this->addTag($document, $item, 'description', $entry->get_subtitle()); $author = sprintf( '%s (%s)' , $entry->get_author_email() , $entry->get_author_name() ); $created_on = $entry->get_created_on()->format(DATE_RFC2822); $this->addTag($document, $item, 'author', $author); $this->addTag($document, $item, 'pubDate', $created_on); $this->addTag($document, $item, 'guid', $link->get_href()); $this->addTag($document, $item, 'link', $link->get_href()); /** * Missing : * * category Includes the item in one or more categories. More. * comments URL of a page for comments relating to the item. More. * enclosure Describes a media object that is attached to the item. More. * source The RSS channel that the item came from. More. * */ foreach ($entry->get_content() as $content) { $this->addContent($document, $item, $entry, $content); } return $item; } }