readUri() public static method

Read a feed located at $uri
public static readUri ( string $uri, Horde_Http_Client $httpclient = null ) : Horde_Feed_Base
$uri string The URI to fetch the feed from.
$httpclient Horde_Http_Client The HTTP client to use.
return Horde_Feed_Base
示例#1
0
文件: Home.php 项目: horde/horde-web
 /**
  *
  * @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'));
 }
示例#2
0
 /**
  * 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']);
 }
示例#3
0
文件: Feed.php 项目: DSNS-LAB/Dmail
 /**
  */
 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();
     }
 }
示例#4
0
<?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");
    }
}
示例#5
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);
示例#6
0
文件: App.php 项目: horde/horde-web
 /**
  *
  * 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));
 }
示例#7
0
文件: read.php 项目: jubinpatel/horde
<?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";
}