/**
  * Sets the feed item parameters, based on an associative array
  *
  * @param array an associative array
  *
  * @return sfFeedItem the current sfFeedItem object
  */
 public function initialize($item_array)
 {
     parent::initialize($item_array);
     $this->setLongitude(isset($item_array['longitude']) ? $item_array['longitude'] : '');
     $this->setLatitude(isset($item_array['latitude']) ? $item_array['latitude'] : '');
     return $this;
 }
 /**
  * Sets the feed item parameters, based on an associative array
  *
  * @param array an associative array
  *
  * @return sfFeedItem the current sfFeedItem object
  */
 public function initialize($item_array)
 {
     parent::initialize($item_array);
     $this->setDctermsAbstract(isset($item_array['dcterms_abstract']) ? $item_array['dcterms_abstract'] : '');
     $this->setPermalink(isset($item_array['permalink']) ? $item_array['permalink'] : '');
     $this->setDcIdentifier(isset($item_array['dc_identifier']) ? $item_array['dc_identifier'] : '');
     $this->setDcPublisher(isset($item_array['dc_publisher']) ? $item_array['dc_publisher'] : '');
     $this->setLocations(isset($item_array['locations']) ? $item_array['locations'] : '');
 }
Ejemplo n.º 3
0
 /**
  *
  * @param array $historyEntries Many objects of History class
  * @return sfRss201Feed
  */
 public function getFeed($historyEntries)
 {
     $this->createFeed();
     $i = 0;
     foreach ($historyEntries as $historyEntry) {
         $user = $historyEntry->getUser();
         $content = (string) $historyEntry;
         $item = new sfFeedItem();
         $item->initialize(array('title' => strip_tags($content), 'link' => 'http://' . RaykuCommon::getCurrentHttpDomain(), 'pubDate' => strtotime($historyEntry->getCreatedAt()), 'description' => $content));
         $this->feed->addItem($item);
     }
     return $this->feed;
 }
Ejemplo n.º 4
0
define('SF_ROOT_DIR', realpath(dirname(__FILE__) . '/../../../..'));
define('SF_APP', 'frontend');
include dirname(__FILE__) . '/../../../../test/bootstrap/functional.php';
$b = new sfTestBrowser();
$b->initialize();
$t = new lime_test(15, new lime_output_color());
$enclosureParams = array('url' => 'foo.com', 'length' => '1234', 'mimeType' => 'foobarmimetype');
$enclosure = new sfFeedEnclosure();
$enclosure->initialize($enclosureParams);
$item_params = array('title' => 'foo', 'link' => 'http://www.example.com', 'description' => 'foobar baz', 'content' => 'hey, do you foo, bar?', 'authorName' => 'francois', 'authorEmail' => '*****@*****.**', 'authorLink' => 'http://francois.toto.com', 'pubDate' => '12345', 'comments' => 'this is foo bar baz', 'uniqueId' => 'hello world', 'enclosure' => $enclosure, 'categories' => array('foo', 'bar'));
$item = new sfFeedItem();
$t->isa_ok($item->initialize($item_params), 'sfFeedItem', 'initialize() returns the current feed item object');
$t->is($item->getTitle(), $item_params['title'], 'getTitle() gets the item title');
$t->is($item->getLink(), $item_params['link'], 'getLink() gets the item link');
$t->is($item->getDescription(), $item_params['description'], 'getDescription() gets the item description');
$t->is($item->getContent(), $item_params['content'], 'getContent() gets the item content');
$t->is($item->getAuthorName(), $item_params['authorName'], 'getAuthorName() gets the item author name');
$t->is($item->getAuthorEmail(), $item_params['authorEmail'], 'getAuthorEmail() gets the item author email');
$t->is($item->getAuthorLink(), $item_params['authorLink'], 'getAuthorLink() gets the item author link');
$t->is($item->getPubDate(), $item_params['pubDate'], 'getPubDate() gets the item publication date');
$t->is($item->getComments(), $item_params['comments'], 'getComments() gets the item comments');
$t->is($item->getUniqueId(), $item_params['uniqueId'], 'getUniqueId() gets the item unique id');
$t->is($item->getEnclosure(), $item_params['enclosure'], 'getEnclosure() gets the item enclosure');
$t->is($item->getCategories(), $item_params['categories'], 'getCategories() gets the item categories');
$item_params = array('title' => 'foo', 'link' => 'http://www.example.com', 'content' => 'hey, do you <strong>foo</strong>, my dear bar?');
$item = new sfFeedItem();
$item->initialize($item_params);
$t->is($item->getDescription(), strip_tags($item_params['content']), 'getDescription() gets the stripped item content when no description is defined');
sfConfig::set('app_feed_item_max_length', 5);
$t->is($item->getDescription(), 'hey, [...]', 'getDescription() gets the stripped item content truncated to a maximaum size when no description is defined');
Ejemplo n.º 5
0
$t->isnt($generatedItem->getAuthorLink(), $feedItem->getAuthorLink(), 'The author link property cannot be set from a RSS feed');
$t->is($generatedItem->getPubDate(), $feedItem->getPubdate(), 'The publication date property is properly set');
$t->is($generatedItem->getComments(), $feedItem->getComments(), 'The comments property is properly set');
$t->is($generatedItem->getUniqueId(), $feedItem->getUniqueId(), 'The unique id property is properly set');
$t->is($generatedItem->getEnclosure()->__toString(), $feedItem->getEnclosure()->__toString(), 'The enclosure property is properly set');
$t->is($generatedItem->getCategories(), $feedItem->getCategories(), 'The categories property is properly set');
$generatedItem = $items[1];
$t->is($generatedItem->getAuthorEmail(), $feedItem2->getAuthorEmail(), 'The author email property is properly set, even if there is no email address');
$t->diag('RSS 0.91');
$feed = new sfRssFeed();
$feed->setVersion('0.91');
$feed->initialize($feedParams);
$feedItem = new sfFeedItem();
$feedItem->initialize($itemParams);
$feed->addItem($feedItem);
$feedItem2 = new sfFeedItem();
$feedItem2->initialize($item2Params);
$feed->addItem($feedItem2);
$feedString = $feed->asXml();
$generatedFeed = new sfRssFeed();
$generatedFeed->fromXml($feedString);
$t->isnt($generatedFeed->getCategories(), $feed->getCategories(), '<category> doesn\'t exist in a RSS0.91 feed');
$items = $generatedFeed->getItems();
$generatedItem = $items[0];
$t->isnt($generatedItem->getAuthorEmail(), $feedItem->getAuthorEmail(), '<item><author> doesn\'t exist in a RSS0.91 feed');
$t->isnt($generatedItem->getAuthorName(), $feedItem->getAuthorName(), '<item><author> doesn\'t exist in a RSS0.91 feed');
$t->isnt($generatedItem->getPubDate(), $feedItem->getPubdate(), '<item><pubDate> doesn\'t exist in a RSS0.91 feed');
$t->isnt($generatedItem->getComments(), $feedItem->getComments(), '<item><comments> doesn\'t exist in a RSS0.91 feed');
$t->isnt($generatedItem->getUniqueId(), $feedItem->getUniqueId(), '<item><guid> doesn\'t exist in a RSS0.91 feed');
$t->is($generatedItem->getEnclosure(), '', '<item><enclosure> doesn\'t exist in a RSS0.91 feed');
$t->isnt($generatedItem->getCategories(), $feedItem->getCategories(), '<item><category> doesn\'t exist in a RSS0.91 feed');
Ejemplo n.º 6
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');