Example #1
0
 /**
  * Создать ленту
  *
  * @param array $rows
  * @param array $parameters
  *
  * @return sfFeed
  */
 private function buildFeed(array $rows, array $parameters)
 {
     // default parameters
     $parameters = array_merge(sfConfig::get('app_feeds_default_parameters', array()), $parameters);
     $feed = sfFeed::newInstance($parameters['feed_type']);
     $feed->setTitle($parameters['title']);
     $feed->setLink($parameters['link']);
     $feed->setAuthorName($parameters['author_name']);
     if (isset($parameters['author_email'])) {
         $feed->setAuthorEmail($parameters['author_email']);
     }
     foreach ($rows as $row) {
         $item = new sfFeedItem();
         $item->setTitle($row['title']);
         $item->setAuthorName($row['author_name']);
         if (isset($parameters['permalink_url'])) {
             $item->setLink(sprintf('@%s?%s=%s', $parameters['permalink_url'], $parameters['permalink_param_name'], $row[$parameters['permalink_param_column']]));
         }
         if (isset($row['author_email'])) {
             $item->setAuthorEmail($row['author_email']);
         }
         $item->setPubdate(strtotime($row['created_at']) - date('Z', strtotime($row['created_at'])));
         $item->setUniqueId($row['id']);
         $item->setDescription($row['description']);
         $feed->addItem($item);
     }
     $this->feed = $feed;
     $this->getContext()->getResponse()->setContentType($feed->getContentType());
     $this->setTemplate('feed');
 }
Example #2
0
 public function executeQuestion()
 {
     $question = QuestionPeer::getQuestionFromTitle($this->getRequestParameter('stripped_title'));
     $this->forward404Unless($question);
     // answers
     $c = new Criteria();
     $c->add(AnswerPeer::QUESTION_ID, $question->getId());
     $c->addDescendingOrderByColumn(AnswerPeer::CREATED_AT);
     $c->setLimit(sfConfig::get('app_feed_max_questions'));
     $answers = AnswerPeer::doSelect($c);
     $feed = sfFeed::newInstance('rss201rev2');
     // channel
     $feed->setTitle($question->getTitle() . ' feed');
     $feed->setLink('@question?stripped_title=' . $question->getStrippedTitle());
     $feed->setFeedUrl('@feed_question?stripped_title=' . $question->getStrippedTitle());
     $feed->setDescription('Latest answers to the question: ' . $question->getTitle());
     // items
     $feed->setItems($answers);
     $this->feed = $feed;
 }
Example #3
0
 public function initialize($feed_array)
 {
     $this->setVersion(isset($feed_array['version']) ? $feed_array['version'] : '');
     parent::initialize($feed_array);
     return $this;
 }
Example #4
0
    $t->pass('addItem() accepts sfFeedItem objects');
} catch (Exception $e) {
    $t->fail('addItem() accepts sfFeedItem objects');
}
$t->is(count($feed->getItems()), 1, 'addItem() adds an item to the feed');
$feed->setItems();
$t->is(count($feed->getItems()), 0, 'setItems() with no arguments reinitializes the feed items');
$feed->addItems(array(new sfFeedItem(), new sfFeedItem(), new sfFeedItem()));
$t->is(count($feed->getItems()), 3, 'addItems() adds several items at once');
$feed->setItems();
try {
    $feed->addItemFromArray(array());
    $t->pass('addItemFromArray() accepts an array');
} catch (Exception $e) {
    $t->fail('addItemFromArray() accepts an array');
}
$t->is(count($feed->getItems()), 1, 'addItemFromArray() adds an item to the feed');
$feed_params = array('title' => 'foo', 'link' => 'bar', 'description' => 'foobar baz', 'language' => 'fr', 'authorName' => 'francois', 'authorEmail' => '*****@*****.**', 'authorLink' => 'http://francois.toto.com', 'subtitle' => 'this is foo bar', 'categories' => array('foo', 'bar'), 'feedUrl' => 'http://www.example.com', 'encoding' => 'UTF-16');
$feed = new sfFeed();
$feed->initialize($feed_params);
$item1_params = array('title' => 'foo', 'pubDate' => '1');
$item1 = new sfFeedItem();
$item1->initialize($item1_params);
$item2_params = array('title' => 'bar', 'pubDate' => '3');
$item2 = new sfFeedItem();
$item2->initialize($item2_params);
$item3_params = array('title' => 'baz', 'pubDate' => '2');
$item3 = new sfFeedItem();
$item3->initialize($item3_params);
$feed->addItems(array($item1, $item2, $item3));
$t->is($feed->getLatestPostDate(), '3', 'getLatestPostDate() returns the latest post date of all feed items');