Item class - Used as feed element in Feed class
Author: Anis uddin Ahmad (anisniit@gmail.com)
Ejemplo n.º 1
0
 /**
  * Handles the RSS action. Constructs the rss feed of the latest posts. The
  * number of posts to return is stored in the configuration section
  *
  * @return Response
  */
 public function rssAction()
 {
     $feed = new RSS2();
     $feed->setEncoding('UTF-8');
     $feed->setTitle($this->config->rss->title);
     $feed->setDescription($this->config->rss->description);
     $feed->setLink($this->getFullUrl());
     $posts = $this->finder->getLatest(1);
     foreach ($posts as $post) {
         $feedItem = new Item();
         $feedItem->setTitle($post->getTitle());
         $feedItem->setLink($this->getFullUrl('/post/' . $post->getSlug()));
         $feedItem->setDescription($post->getContent());
         $feedItem->setDate($post->getDate());
         $feed->addItem($feedItem);
     }
     $response = new Response();
     $response->setHeader('Content-Type', 'application/xml');
     $response->setContent($feed->generateFeed());
     return $response;
 }
Ejemplo n.º 2
0
 /**
  * Add a FeedItem to the main class
  *
  * @access   public
  * @param    Item    instance of Item class
  * @return   self
  */
 public function addItem(Item $feedItem)
 {
     if ($feedItem->getVersion() != $this->version) {
         die('Feed type mismatch: This instance can handle ' . $this->version . ' feeds only, but item with type ' . $feedItem->getVersion() . ' given.');
     }
     $this->items[] = $feedItem;
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * Add a FeedItem to the main class
  *
  * @access   public
  * @param    Item   $feedItem instance of Item class
  * @return   self
  * @throws   \InvalidArgumentException if the given item version mismatches.
  */
 public function addItem(Item $feedItem)
 {
     if ($feedItem->getVersion() != $this->version) {
         $msg = sprintf('Feed type mismatch: This instance can handle %s feeds only, but item for %s feeds given.', $this->version, $feedItem->getVersion());
         throw new \InvalidArgumentException($msg);
     }
     $this->items[] = $feedItem;
     return $this;
 }