/** * Get a Horde_Feed object for the feed described by this outline element. * * @return Horde_Feed_Base */ public function getFeed() { if (!$this['xmlUrl']) { throw new Horde_Feed_Exception('No XML URL in <outline/> element'); } return Horde_Feed::readUri($this['xmlUrl']); }
/** * * @param Horde_Controller_Response $response */ protected function _index(Horde_Controller_Response $response) { $view = $this->getView(); $view->page_title = 'The Horde Project'; $view->maxHordeItems = 5; $view->maxPlanetItems = 10; $cache = $GLOBALS['injector']->getInstance('Horde_Cache'); // Get the planet feed. if ($planet = $cache->get('planet', 600)) { $view->planet = unserialize($planet); } else { try { $view->planet = Horde_Feed::readUri('http://planet.horde.org/rss/'); } catch (Exception $e) { $view->planet = null; } $cache->set('planet', serialize($view->planet)); } // Get the complete Horde feed (no tags) if ($hordefeed = $cache->get('hordefeed', 600)) { $view->hordefeed = unserialize($hordefeed); } else { try { $view->hordefeed = Horde_Feed::readUri($GLOBALS['feed_url']); } catch (Exception $e) { $view->hordefeed = null; } $cache->set('hordefeed', serialize($view->hordefeed)); } $layout = $this->getInjector()->getInstance('Horde_Core_Ui_Layout'); $layout->setView($view); $layout->setLayoutName('home'); $response->setBody($layout->render('index')); }
public function testNotAFeed() { try { $feed = Horde_Feed::readFile($this->_feedDir . 'NotAFeed.xml'); } catch (Exception $e) { $this->assertInstanceOf('Horde_Feed_Exception', $e); return; } $this->fail('Expected a Horde_Feed_Exception when parsing content that is not a feed of any kind'); }
public function testEntryOnly() { $feed = Horde_Feed::readFile(__DIR__ . '/fixtures/TestAtomFeedEntryOnly.xml'); $this->assertEquals(1, $feed->count(), 'The entry-only feed should report one entry.'); foreach ($feed as $entry) { } $this->assertEquals('Horde_Feed_Entry_Atom', get_class($entry), 'The single entry should be an instance of Horde_Feed_Entry_Atom'); $this->assertEquals('1', $entry->id(), 'The single entry should have id 1'); $this->assertEquals('Bug', $entry->title(), 'The entry\'s title should be "Bug"'); }
/** */ private function _read() { if (empty($this->_params['uri'])) { return; } $key = md5($this->_params['uri']); $cache = $GLOBALS['injector']->getInstance('Horde_Cache'); $feed = $cache->get($key, $this->_params['interval']); if (!empty($feed)) { $this->_feed = unserialize($feed); } try { $client = $GLOBALS['injector']->getInstance('Horde_Core_Factory_HttpClient')->create(); $feed = Horde_Feed::readUri($this->_params['uri'], $client); $cache->set($key, serialize($feed)); $this->_feed = $feed; } catch (Exception $e) { $this->_feed = $e->getMessage(); } }
public function testGroupedBlogrolls() { $feed = Horde_Feed::readFile($this->_feedDir . 'MySubscriptionsGrouped.opml'); }
public function testCount() { $f = Horde_Feed::readFile(__DIR__ . '/fixtures/TestAtomFeed.xml'); $this->assertEquals($f->count(), 2, 'Feed count should be 2'); }
<?php /** * Example of deleting Atom posts with Horde_Feed. * * @package Feed */ /* Get a Horde framework include_path set up. */ require 'Horde/Autoloader.php'; /* Load the feed we want to delete something from. */ try { $feed = Horde_Feed::readUri('http://www.example.com/Feed/'); } catch (Horde_Feed_Exception $e) { die('An error occurred loading the feed: ' . $e->getMessage() . "\n"); } /* We want to delete all entries that are two weeks old. */ $twoWeeksAgo = strtotime('-2 weeks'); foreach ($feed as $entry) { /* Check the updated timestamp. */ if (strtotime($entry->updated) >= $twoWeeksAgo) { continue; } /* Deleting the old posts is easy. */ try { $entry->delete(); } catch (Horde_Feed_Exception $e) { die('An error occurred deleting feed entries: ' . $e->getMessage() . "\n"); } }
#!/usr/bin/env php <?php /** * @package Feed */ /* Get a Horde framework include_path set up. */ require 'Horde/Autoloader.php'; $p = new Horde_Argv_Parser(array('usage' => "%prog opml_url\n\nExample:\n%prog subscriptions.opml")); list($values, $args) = $p->parseArgs(); if (count($args) != 1) { $p->printHelp(); exit(1); } $blogroll = Horde_Feed::readFile($args[0]); echo $blogroll->title . "\n\n"; foreach ($blogroll as $blog) { $feed = $blog->getFeed(); echo $feed->title . "\n\n"; foreach ($feed as $entry) { echo "{$entry->title}\n"; } echo "\n\n"; } exit(0);
#!/usr/bin/env php <?php /** * @package Feed */ /* Get a Horde framework include_path set up. */ require 'Horde/Autoloader.php'; $p = new Horde_Argv_Parser(array('usage' => "%prog feed_url\n\nExample:\n%prog http://graphics8.nytimes.com/services/xml/rss/nyt/HomePage.xml")); list($values, $args) = $p->parseArgs(); if (count($args) != 1) { $p->printHelp(); exit(1); } $feed = Horde_Feed::readUri($args[0]); echo count($feed) . " entries:\n\n"; foreach ($feed as $i => $entry) { echo $i + 1 . '. ' . $entry->title() . "\n"; } exit(0);
/** * * Specific application's page * * @param Horde_Controller_Response $response */ protected function _app(Horde_Controller_Response $response) { $view = $this->getView(); $view->page_title = $view->appnameHuman . ' - The Horde Project'; $layout = $this->getInjector()->getInstance('Horde_Core_Ui_Layout'); $template = 'app'; // Do we know about this app? if (file_exists($GLOBALS['fs_base'] . '/app/views/App/apps/' . urlencode($this->_matchDict->app)) === false) { $view->page_title = '404 Not Found'; $template = '404'; } // Build the bug/news widget // The tag for the search should *normally* be the app name $cache = HordeWeb_Utils::getCache(); $slugs = array($this->_matchDict->app); $view->latestNews = array(); foreach ($slugs as $slug) { $base_feed_url = Horde::url($GLOBALS['feed_url'])->add('tag_id', $slug)->setRaw(true); if ($latestnews = $cache->get('hordefeed' . $slug, 600)) { $view->latestNews = unserialize($latestnews); } else { try { $i = 1; foreach (Horde_Feed::readUri($base_feed_url) as $entry) { $view->latestNews[] = $entry; if (++$i > 5) { break; } } } catch (Exception $e) { } $cache->set('hordefeed' . $slug, serialize($view->latestNews)); } } $layout->setView($view); $layout->setLayoutName('main'); $response->setBody($layout->render($template)); }
/** * @dataProvider getLexicon */ public function testParse($file) { $feed = Horde_Feed::readFile($file); $this->assertGreaterThan(0, count($feed)); }
public function setUp() { $this->feed = Horde_Feed::readFile(__DIR__ . '/fixtures/TestAtomFeed.xml'); $this->nsfeed = Horde_Feed::readFile(__DIR__ . '/fixtures/TestAtomFeedNamespaced.xml'); }
<?php /** * Example of reading feeds with Horde_Feed. * * @package Feed */ /* Get a Horde framework include_path set up. */ require 'Horde/Autoloader.php'; /* Get the New York Times headlines. */ $uri = 'http://graphics8.nytimes.com/services/xml/rss/nyt/HomePage.xml'; try { $feed = Horde_Feed::readUri($uri); } catch (Exception $e) { die('An error occurred loading the feed: ' . $e->getMessage() . "\n"); } /* You can iterate over the entries in the feed simply by * iterating over the feed itself. */ foreach ($feed as $entry) { echo "title: {$entry->title()}\n"; if ($entry->author->name()) { echo "author: {$entry->author->name()}\n"; } echo "description:\n{$entry->description()}\n\n"; } /* The properties of the feed itself are available through * regular member variable access: */ echo "feed title: {$feed->title()}\n"; if ($feed->author->name()) { echo "feed author: {$feed->author}->name()\n"; }