Example #1
0
 public static function fetch_feed(com_meego_planet_feed $feed, $index, $item_callback)
 {
     if (!is_callable($item_callback)) {
         throw InvalidArgumentException('Item processing callback must be a valid function');
     }
     midgardmvc_core::get_instance()->component->load_library('Feed');
     try {
         $fetched = ezcFeed::parse($feed->feed);
     } catch (Exception $e) {
         midgardmvc_core::get_instance()->log(__CLASS__, $e->getMessage(), 'info');
         return false;
     }
     $items = $fetched->item;
     array_walk($items, $item_callback, $feed);
     self::remove_missing($items, $feed);
 }
 /**
  * Executes the PHP function for the operator cleanup and modifies $operatorValue.
  * 
  * @param eZTemplate $tpl
  * @param string $operatorName
  * @param array $operatorParameters
  * @param string $rootNamespace
  * @param string $currentNamespace
  * @param mixed $operatorValue
  * @param array $namedParameters
  */
 public function modify($tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters)
 {
     switch ($operatorName) {
         case 'feedreader':
             $source = isset($namedParameters['source']) ? $namedParameters['source'] : '';
             $limit = isset($namedParameters['limit']) ? $namedParameters['limit'] : 0;
             $offset = isset($namedParameters['offset']) ? $namedParameters['offset'] : 0;
             $res = array();
             try {
                 $feed = ezcFeed::parse($source);
             } catch (Exception $e) {
                 $res['error'] = $e->getMessage();
                 $operatorValue = $res;
                 return;
             }
             $res['title'] = isset($feed->title) ? $feed->title->__toString() : null;
             $res['links'] = self::buildLinksArray(isset($feed->link) ? $feed->link : array());
             $items = isset($feed->item) ? $feed->item : array();
             $counter = 0;
             foreach ($items as $item) {
                 $counter++;
                 if ($counter <= $offset) {
                     continue;
                 }
                 $title = isset($item->title) ? $item->title->__toString() : null;
                 $description = isset($item->description) ? $item->description->__toString() : null;
                 $content = isset($item->content) ? $item->content->__toString() : null;
                 $published = isset($item->published) ? $item->published->date->format('U') : null;
                 $links = self::buildLinksArray(isset($item->link) ? $item->link : array());
                 $res['items'][] = array('title' => $title, 'links' => $links, 'description' => $description, 'content' => $content, 'published' => $published);
                 if ($counter == $limit + $offset) {
                     break;
                 }
             }
             $operatorValue = $res;
             break;
     }
 }
Example #3
0
<?php

require 'ezc-setup.php';
try {
    $feed = ezcFeed::parse('http://components.ez.no/rss/rss2.xml');
} catch (Exception $e) {
    $feed = ezcFeed::parse(dirname(__FILE__) . '/rss2.xml');
}
echo "<b>{$feed->title}</b><br/><br/>\n";
foreach ($feed->item as $item) {
    echo "<a href='{$item->link}'>{$item->title}</a><br/>";
    echo $item->Content->encoded, "<br/>";
}
Example #4
0
 public function testParseFeedWithAuthentication()
 {
     $this->markTestIncomplete('Accessing feeds with http authentication works. We will add a sensible test for this later, when we will have a test system with an anonymous account for feeds.');
     $feed = ezcFeed::parse('http://*****:*****@example.com/');
     $this->assertEquals("Feed title", $feed->title);
 }
Example #5
0
 public function __construct($src)
 {
     $zeta = \ezcFeed::parse($src);
     $this->rawData = $zeta;
 }