本文整理汇总了PHP中Zend_Feed_Reader::useHttpConditionalGet方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Feed_Reader::useHttpConditionalGet方法的具体用法?PHP Zend_Feed_Reader::useHttpConditionalGet怎么用?PHP Zend_Feed_Reader::useHttpConditionalGet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Feed_Reader
的用法示例。
在下文中一共展示了Zend_Feed_Reader::useHttpConditionalGet方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: pollAction
/**
* Polls all registered feeds. The actual polling is performed by the
* retrieved Models, so all we do here is get those Models and setup
* Zend_Feed_Reader caching/conditional GET support if configured.
* Polling is NOT performed for feeds which have a confirmed Pubsubhubbub
* subscription active.
*
* @return void
*/
public function pollAction()
{
try {
$feeds = Doctrine_Query::create()->from('Zfplanet_Model_Feed f')->where('f.uri NOT IN (SELECT s.topic_url FROM Zfplanet_Model_Subscription s' . ' WHERE s.subscription_state = ?)', Zend_Feed_Pubsubhubbub::SUBSCRIPTION_VERIFIED)->execute();
if (!$feeds) {
return;
}
$chelper = $this->_helper->getHelper('Cache');
if ($chelper->hasCache('feed')) {
Zend_Feed_Reader::setCache($chelper->getCache('feed'));
Zend_Feed_Reader::useHttpConditionalGet();
}
$notifier = $this->_getTwitterNotifier();
foreach ($feeds as $feed) {
if ($notifier->isEnabled()) {
$feed->setTwitterNotifier($notifier);
}
$feed->setLuceneIndexer($this->_getLuceneIndexer());
$feed->setLogger($this->getInvokeArg('bootstrap')->getResource('ErrorLog'));
$feed->synchronise();
}
$this->_helper->getHelper('Cache')->removePagesTagged(array('allentries'));
$this->_doPubsubhubbubNotification();
echo 'Polling completed without error', PHP_EOL;
} catch (Exception $e) {
$logger = $this->getInvokeArg('bootstrap')->getResource('ErrorLog');
$message = 'Other Error/Exception: ' . get_class($e) . ': ' . $e->getMessage() . PHP_EOL . 'Stack Trace: ' . PHP_EOL . $e->getTraceAsString();
$logger->log($message, Zend_Log::ERR);
echo $message;
}
}
示例2: getItems
/**
* Get feed items from specified url
*
* @param string $p_url
* @return Iterator
*/
private function getItems($p_url)
{
// get cache
$cache = Zend_Cache::factory('Core', 'File', array('lifetime' => 300, 'automatic_serialization' => true), array('cache_dir' => APPLICATION_PATH . '/../cache'));
// set reader
Zend_Feed_Reader::setCache($cache);
Zend_Feed_Reader::useHttpConditionalGet();
// get feed
$feed = Zend_Feed_Reader::import($p_url);
return $feed;
}
示例3: _initFeed
protected function _initFeed()
{
// set cache frontend options
$frontendOptions = array('lifetime' => 86400, 'automatic_serialization' => true);
// set cache backend options
$backendOptions = array('cache_dir' => APPLICATION_PATH . '/../data/cache');
// configure cache
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
// set feed to use cache and httpConditionalGet
Zend_Feed_Reader::setCache($cache);
Zend_Feed_Reader::useHttpConditionalGet();
}
示例4: fetch
/**
* Retrieve items from content source.
* @return int Number of items retrieved
*/
function fetch()
{
if ($this->_disabled) {
return 0;
}
$this->_items = array();
// reset
$frontendOptions = array('lifetime' => 7200, 'automatic_serialization' => true);
$backendOptions = array('cache_dir' => $this->_config->cacheDir);
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
Zend_Feed_Reader::setCache($cache);
Zend_Feed_Reader::useHttpConditionalGet();
$classname = $this->_getItemClass();
foreach (Zend_Feed_Reader::import($this->_config->url) as $entry) {
$this->_items[] = new $classname($entry, $this->_config->items);
}
uasort($this->_items, array('Polycast_Stalker', 'sortItems'));
$this->_items = array_slice($this->_items, 0, $this->_config->limit, true);
return count($this->_items);
}
示例5: _load
protected function _load()
{
if (!isset($this->_options[0])) {
throw new Exceptions_SeotoasterWidgetException('Rss feed url should be specified');
}
$scheme = 'http';
$feeds = array();
//little hack for options, needs to be somthing better
if (preg_match('~^https?$~', $this->_options[0])) {
$scheme = array_shift($this->_options);
$this->_options[0] = ltrim($this->_options[0], '/');
}
$feedUrl = $scheme . '://' . str_replace(' ', '+', html_entity_decode($this->_options[0]));
$maxResult = isset($this->_options[1]) ? $this->_options[1] : self::RSS_RESULT_COUNT;
Zend_Uri::setConfig(array('allow_unwise' => true));
if (!Zend_Uri::check($feedUrl)) {
throw new Exceptions_SeotoasterWidgetException('Rss feed url is not valid.');
}
Zend_Feed_Reader::setCache(Zend_Registry::get('cache'));
Zend_Feed_Reader::useHttpConditionalGet();
try {
$rss = Zend_Feed_Reader::import($feedUrl);
} catch (Exception $e) {
return $e->getMessage();
}
$i = 0;
foreach ($rss as $item) {
if ($i == $maxResult) {
break;
}
$feeds[] = array('title' => $item->getTitle(), 'link' => $item->getLink(), 'description' => Tools_Text_Tools::cutText(strip_tags($item->getDescription()), isset($this->_options[2]) ? $this->_options[2] : self::RSS_DESC_LENGTH), 'pubDate' => $item->getDateCreated(), 'content' => $item->getContent(), 'authors' => $item->getAuthors(), 'image' => $this->_getRssEntryImage($item->getContent()));
$i++;
}
$this->_view->useImage = isset($this->_options[3]) && $this->_options[3] == 'img' ? true : false;
$this->_view->feed = $feeds;
return $this->_view->render('rss.phtml');
}
示例6: _processResources
private static function _processResources(array $config)
{
if (self::$_lock) {
/**
* @see Conjoon_Log
*/
require_once 'Conjoon/Log.php';
Conjoon_Log::log("Conjoon_Modules_Groupware_Feeds_ImportHelper::_processResources " . "- possible race condition", Zend_Log::INFO);
}
self::$_lock = true;
$uri = $config['uri'];
$requestTimeout = $config['requestTimeout'];
$useCache = $config['useCache'];
$useConditionalGet = $config['useConditionalGet'];
$callback = $config['callback'];
/**
* @see Zend_Feed_Reader
*/
require_once 'Zend/Feed/Reader.php';
if ($useCache !== false) {
// set the reader's cache here
/**
* @see Conjoon_Cache_Factory
*/
require_once 'Conjoon/Cache/Factory.php';
/**
* @see Conjoon_Keys
*/
require_once 'Conjoon/Keys.php';
$frCache = Conjoon_Cache_Factory::getCache(Conjoon_Keys::CACHE_FEED_READER, Zend_Registry::get(Conjoon_Keys::REGISTRY_CONFIG_OBJECT)->toArray());
if ($frCache) {
Zend_Feed_Reader::setCache($frCache);
if ($useConditionalGet !== false) {
Zend_Feed_Reader::useHttpConditionalGet();
}
}
}
Zend_Feed_Reader::getHttpClient()->setConfig(array('timeout' => $requestTimeout));
$result = self::$callback($uri);
Zend_Feed_Reader::reset();
self::$_lock = false;
return $result;
}
示例7: _getFeedData
/**
* reads the RSS feeds and extracts the 'description' field from each one.
* Uses caching and http conditional GET to ensure that the feed is only
* read if it has been updated
*
* @return array
*/
protected function _getFeedData()
{
//Get the feed url from the configuration options
$options = $this->_getConfigOptions();
$feed_url = $options['feed']['url'];
$cache_dir = $options['cache']['directory'];
// set cache - this allows us to check whether the feed has been updated
$cache = Zend_Cache::factory('Core', 'File', array('lifetime' => null), array('cache_dir' => $cache_dir));
Zend_Feed_Reader::setCache($cache);
// set Reader properties to allow Conditional GET Requests
Zend_Feed_Reader::useHttpConditionalGet();
// disable SSL peer verification as it can cause problems from some isp's
$options = array('ssl' => array('verify_peer' => false, 'allow_self_signed' => true));
$adapter = new Zend_Http_Client_Adapter_Socket();
$adapter->setStreamContext($options);
Zend_Feed_Reader::getHttpClient()->setAdapter($adapter);
// interrogate the RSS feed
try {
$rss_data = Zend_Feed_Reader::import($feed_url);
} catch (Zend_Feed_Exception $e) {
// feed import failed
Zend_Registry::get('logger')->log('Exception importing feed: ' . $e->getMessage(), Zend_Log::WARN);
return null;
} catch (Zend_Http_Client_Exception $e) {
Zend_Registry::get('logger')->log('Error with URL: ' . $e->getMessage(), Zend_Log::WARN);
return null;
} catch (Exception $e) {
Zend_Registry::get('logger')->log('Unknown error when reading feed: ' . $e->getMessage(), Zend_Log::WARN);
return null;
}
$entries = array();
// response status will be 200 if new data, 304 if not modified
$last_response = Zend_Feed_Reader::getHttpClient()->getLastResponse();
if ($last_response) {
$response_status = $last_response->getStatus();
// Only process if new data
if (200 === $response_status) {
foreach ($rss_data as $item) {
$entry['description'] = $item->getDescription();
$entries[] = $entry;
}
if ($this->_getVerbose()) {
$this->getResponse()->appendBody(new Zend_Date() . ': ' . count($entries) . ' new entries downloaded from rss feed' . PHP_EOL);
}
} else {
if ($this->_getVerbose()) {
$this->getResponse()->appendBody(new Zend_Date() . ': ' . 'No new data found' . PHP_EOL);
}
}
}
return $entries;
}
示例8: processFeed
/**
* process feed
*/
public function processFeed($feed_options)
{
/**
* include required libraries
*/
require_once 'Zend/Cache.php';
require_once 'Zend/Feed/Reader.php';
/**
* cache init
*/
$frontendOptions = array('lifetime' => 60 * 5, 'automatic_serialization' => true);
$backendOptions = array('cache_dir' => ONXSHOP_PROJECT_DIR . 'var/cache/');
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
Zend_Feed_Reader::setCache($cache);
Zend_Feed_Reader::useHttpConditionalGet();
// Fetch the feed
try {
$feed = Zend_Feed_Reader::import($feed_options['url']);
} catch (Zend_Exception $e) {
// feed import failed
msg("Exception caught importing feed: {$e->getMessage()}", 'error');
//delete downloaded from cache (probably invalid)
// TODO: how to delete feed cache?
//dont cache actual controler
return false;
}
// Initialize the channel data array
$channel = array('title' => $feed->getTitle(), 'link' => $feed->getLink(), 'dateModified' => $feed->getDateModified(), 'description' => $feed->getDescription(), 'language' => $feed->getLanguage(), 'entries' => array());
// Loop over each channel item and store relevant data
//check if
foreach ($feed as $entry) {
$channel['entries'][] = array('title' => $entry->getTitle(), 'link' => $entry->getLink(), 'author' => $entry->getAuthor(), 'description' => $entry->getDescription(), 'content' => $entry->getContent(), 'pubDate' => $entry->getDateModified()->get(), 'image' => $entry->getElement()->getElementsByTagName("image")->item(0)->textContent);
}
$channel['encoding'] = 'utf8';
if (is_array($channel['entries'])) {
$this->tpl->assign('CHANNEL', $channel);
if ($channel['title'] != '' && $channel_options['channel_title']) {
$this->tpl->parse('content.channel_title');
}
if ($channel['image_url'] != '' && $channel_options['image']) {
$this->tpl->parse('content.image');
}
if ($channel['copyright'] != '' && $channel_options['copyright']) {
$this->tpl->parse('content.copyright');
}
//locale
$channel['copyright'] = recode_string("{$channel['encoding']}..utf8", $channel['copyright']);
//reverse order
//$rs = array_reverse($rs);
$i = 0;
foreach ($channel['entries'] as $item) {
if ($feed_options['items_limit'] == 0 || $i < $feed_options['items_limit']) {
$item['description'] = html_entity_decode($item['description']);
//problem with <p>
//$item['description'] = preg_replace("/<p>(.*)<\/p>/i", "$1", $item['description']);
//locale
$item['description'] = recode_string("{$channel['encoding']}..utf8", $item['description']);
$item['title'] = recode_string("{$channel['encoding']}..utf8", $item['title']);
//odd or even
if ($i % 2 == 0) {
$item['odd_even_class'] = "even";
} else {
$item['odd_even_class'] = "odd";
}
//prepare item
$item = $this->prepareItem($item);
//assign
$this->tpl->assign('ITEM', $item);
//parse
if ($item['description'] != '' && $feed_options['description']) {
$this->tpl->parse('content.item.description');
}
if ($item['content'] != '' && $feed_options['content']) {
$this->tpl->parse('content.item.content');
}
if ($item['pubDate'] != '' && $feed_options['pubdate']) {
$this->tpl->parse('content.item.pubdate');
}
if ($item['image'] != '') {
$this->tpl->parse('content.item.image');
}
$this->tpl->parse('content.item');
}
$i++;
}
} else {
msg("Feed '{$feed_options['url']}' not found...", 'error');
}
return true;
}