/** * render * * @author Christopher M. Black <*****@*****.**> * * @param SimpleXMLElement $xmlElement * * @return string * @throws \Exception */ public function render(SimpleXMLElement $xmlElement = null) { $headerString = '<' . $this->getRoot() . '>'; // add media if (!empty($this->getMedia())) { $headerString .= $this->getMedia()->render(); } // Add title if (empty($this->getTitle())) { throw new \Exception('title is required for all articles'); } else { $headerString .= '<h1>' . $this->getTitle() . '</h1>'; } // Add subtitle if (!empty($this->getSubTitle())) { $headerString .= '<h2>' . $this->getSubTitle() . '</h2>'; } // add kicker if (!empty($this->getKicker())) { $headerString .= '<h3 class="op-kicker">' . $this->getKicker() . '</h3>'; } // look and add authors if present if (!empty($this->getAuthors())) { foreach ($this->getAuthors() as $author) { $headerString .= $author->render(); } } if (!empty($this->getModifiedDate())) { $headerString .= '<time class="op-modified" dateTime="' . Base::formatRSSDate($this->getModifiedDate()) . '">' . Base::formatUserDate($this->getModifiedDate()) . '</time>'; } if (!empty($this->getPublishedDate())) { $headerString .= '<time class="op-published" dateTime="' . Base::formatRSSDate($this->getPublishedDate()) . '">' . Base::formatUserDate($this->getPublishedDate()) . '</time>'; } $ads = $this->getAds(); if (!empty($ads)) { $headerString .= '<section class="op-ad-template">'; foreach ($ads as $ad) { $headerString .= $ad->render(); } $headerString .= '</section>'; } $headerString .= '</' . $this->getRoot() . '>'; return $headerString; }
/** * setPubDate * * @author Christopher M. Black <*****@*****.**> * * @param string|int $pubDate * @param boolean $alsoSetHeaderPublishedDate * * @return Article */ public function setPubDate($pubDate, $alsoSetHeaderPublishedDate = true) { if ($alsoSetHeaderPublishedDate) { $this->setPublishedDate($pubDate); } else { $this->_pubDate = Base::formatRSSDate($pubDate); } return $this; }
/** * channel * * @since 0.1.1 * @version 0.1.1 * * @author Christopher M. Black <*****@*****.**> * * @param array $parameters valid keys: * - title (required) * - link (required) * - description (required) * - language * - lastBuildDate (autoadded if not passed) * * @return \FBIARss * @throws \Exception */ public function channel($parameters) { if (!array_key_exists('title', $parameters) || !array_key_exists('description', $parameters) || !array_key_exists('link', $parameters)) { throw new \Exception('Required channel parameter missing : title, description or link'); } if (array_key_exists('lastBuildDate', $parameters)) { if (!empty($parameters['lastBuildDate'])) { $parameters['lastBuildDate'] = BaseElement::formatRSSDate($parameters['lastBuildDate']); } else { $parameters['lastBuildDate'] = BaseElement::formatRSSDate(); } } else { $parameters['lastBuildDate'] = BaseElement::formatRSSDate(); } $this->channel = $parameters; return $this; }