当前位置: 首页>>代码示例>>PHP>>正文


PHP Reader::import方法代码示例

本文整理汇总了PHP中Zend\Feed\Reader\Reader::import方法的典型用法代码示例。如果您正苦于以下问题:PHP Reader::import方法的具体用法?PHP Reader::import怎么用?PHP Reader::import使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Feed\Reader\Reader的用法示例。


在下文中一共展示了Reader::import方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getNewsFeed

 /**
  * Process RSS feed and return results.
  *
  * @param $feed_url
  * @param null $cache_name
  * @param int $cache_expires
  * @return array|mixed
  */
 public static function getNewsFeed($feed_url, $cache_name = NULL, $cache_expires = 900)
 {
     if (!is_null($cache_name)) {
         $feed_cache = Cache::get('feed_' . $cache_name);
     } else {
         $feed_cache = null;
     }
     if ($feed_cache) {
         return $feed_cache;
     }
     // Catch the occasional error when the RSS feed is malformed or the HTTP request times out.
     try {
         $news_feed = Reader::import($feed_url);
     } catch (\Exception $e) {
         $news_feed = NULL;
     }
     if (!is_null($news_feed)) {
         $latest_news = array();
         $article_num = 0;
         foreach ($news_feed as $item) {
             $article_num++;
             $news_item = array('num' => $article_num, 'title' => $item->getTitle(), 'timestamp' => $item->getDateModified()->getTimestamp(), 'description' => trim($item->getDescription()), 'link' => $item->getLink(), 'categories' => $item->getCategories()->getValues());
             $latest_news[] = $news_item;
         }
         $latest_news = array_slice($latest_news, 0, 10);
         if (!is_null($cache_name)) {
             Cache::set($latest_news, 'feed_' . $cache_name, array('feeds', $cache_name), $cache_expires);
         }
         return $latest_news;
     }
 }
开发者ID:einstein95,项目名称:FAOpen,代码行数:39,代码来源:Utilities.php

示例2: load

 /**
  * Loads a newsfeed object.
  *
  * @param string $feedurl
  * @param bool   $cache
  * @return Reader
  */
 public function load($url, $cache = true)
 {
     if ($cache) {
         Reader::setCache(new ZendCacheDriver('cache/expensive'));
     }
     $feed = Reader::import($url);
     return $feed;
 }
开发者ID:ceko,项目名称:concrete5-1,代码行数:15,代码来源:FeedService.php

示例3: read

 public function read() : array
 {
     $url = sprintf(self::ATOM_FORMAT, $this->user);
     $feed = FeedReader::import($url);
     $entries = Collection::create($feed)->filterChain($this->filters)->slice($this->limit)->map(function ($entry) {
         return ['title' => $entry->getTitle(), 'link' => $entry->getLink()];
     });
     return ['last_modified' => $feed->getDateModified(), 'link' => $feed->getLink(), 'links' => $entries->toArray()];
 }
开发者ID:vrkansagara,项目名称:mwop.net,代码行数:9,代码来源:AtomReader.php

示例4: load

 /**
  * Loads feed from an url or file path
  *
  * @param string $file
  *
  * @return Reader
  */
 public function load($file)
 {
     if (file_exists($file)) {
         $this->feed = ZendReader::importFile($file);
     } else {
         $this->feed = ZendReader::import($file);
     }
     return $this;
 }
开发者ID:nvbooster,项目名称:FeedBundle,代码行数:16,代码来源:Reader.php

示例5: load

 /**
  * Loads a newsfeed object.
  *
  * @param string $feedurl
  * @param int    $cache - number of seconds to cache the RSS feed data for
  * @return Reader
  */
 public function load($url, $cache = 3600)
 {
     if ($cache !== false) {
         Reader::setCache(new ZendCacheDriver('cache/expensive', $cache));
     }
     // Load the RSS feed, either from remote URL or from cache
     // (if specified above and still fresh)
     $feed = Reader::import($url);
     return $feed;
 }
开发者ID:kreativmind,项目名称:concrete5-5.7.0,代码行数:17,代码来源:FeedService.php

示例6: detectHubs

 /**
  * Simple utility function which imports any feed URL and
  * determines the existence of Hub Server endpoints. This works
  * best if directly given an instance of Zend_Feed_Reader_Atom|Rss
  * to leverage off.
  *
  * @param  \Zend\Feed\Reader\Feed\AbstractFeed|string $source
  * @return array
  * @throws Exception\InvalidArgumentException
  */
 public static function detectHubs($source)
 {
     if (is_string($source)) {
         $feed = Reader\Reader::import($source);
     } elseif ($source instanceof Reader\Feed\AbstractFeed) {
         $feed = $source;
     } else {
         throw new Exception\InvalidArgumentException('The source parameter was' . ' invalid, i.e. not a URL string or an instance of type' . ' Zend\\Feed\\Reader\\Feed\\AbstractFeed');
     }
     return $feed->getHubs();
 }
开发者ID:totolouis,项目名称:ZF2-Auth,代码行数:21,代码来源:PubSubHubbub.php

示例7: run

 public function run()
 {
     $feed = Reader::import($this->feedUrl);
     $data = array('title' => $feed->getTitle(), 'link' => $feed->getLink(), 'dateModified' => $feed->getDateModified(), 'description' => $feed->getDescription(), 'language' => $feed->getLanguage(), 'entries' => array());
     foreach ($feed as $entry) {
         $edata = array('title' => $entry->getTitle(), 'description' => $entry->getDescription(), 'dateModified' => $entry->getDateModified(), 'authors' => $entry->getAuthors(), 'link' => $entry->getLink(), 'content' => $entry->getContent());
         $data['entries'][] = $edata;
     }
     echo $this->render('default', ['data' => $data]);
     // $this->registerClientScript();
 }
开发者ID:kmergen,项目名称:yii2-feed,代码行数:11,代码来源:Feedreader.php

示例8: rssProxyAction

 public function rssProxyAction()
 {
     $overrideFeedUrl = $this->getEvent()->getRequest()->getQuery()->get('urlOverride');
     $limit = $this->getEvent()->getRequest()->getQuery()->get('limit');
     $instanceId = $this->getEvent()->getRequest()->getQuery()->get('instanceId');
     /** @var \Rcm\Service\PluginManager $pluginManager */
     $pluginManager = $this->serviceLocator->get('\\Rcm\\Service\\PluginManager');
     if ($instanceId > 0) {
         $instanceConfig = $pluginManager->getInstanceConfig($instanceId);
     } else {
         $instanceConfig = $pluginManager->getDefaultInstanceConfig('RcmRssFeed');
     }
     $feedUrl = $instanceConfig['rssFeedUrl'];
     $cacheKey = 'rcmrssfeed-' . md5($feedUrl);
     if ($this->cacheMgr->hasItem($cacheKey)) {
         $viewRssData = json_decode($this->cacheMgr->getItem($cacheKey));
         $this->sendJson($viewRssData);
     }
     if (!empty($overrideFeedUrl) && $overrideFeedUrl != 'null') {
         //$permissions = $this->userMgr->getLoggedInAdminPermissions();
         $permissions = null;
         /**
          * Only admins can override the url. This prevents people from using
          * our proxy to DDOS other sites.
          */
         $allowed = $this->rcmIsAllowed('sites.' . $this->siteId, 'admin');
         if ($allowed) {
             $feedUrl = $overrideFeedUrl;
         }
     }
     if (empty($limit)) {
         $limit = $instanceConfig['rssFeedLimit'];
     }
     $rssReader = new Reader();
     //Tried to add a timeout like this but it didnt work
     $httpClient = new Client($feedUrl, ['timeout' => 5]);
     $rssReader->setHttpClient($httpClient);
     try {
         $feedData = $rssReader->import($feedUrl);
     } catch (\Exception $e) {
         $feedData = [];
     }
     $feedCount = 0;
     $viewRssData = [];
     foreach ($feedData as $entry) {
         if ($feedCount == $limit) {
             break;
         }
         $viewRssData[] = ['feedtitle' => $entry->getTitle(), 'description' => $entry->getDescription(), 'dateModified' => $entry->getDateModified(), 'authors' => $entry->getAuthors(), 'feedlink' => $entry->getLink()];
         $feedCount++;
     }
     $this->cacheMgr->addItem($cacheKey, json_encode($viewRssData));
     $this->sendJson($viewRssData);
 }
开发者ID:reliv,项目名称:rcm-plugins,代码行数:54,代码来源:ProxyController.php

示例9: getEntries

 /**
  * @return array
  */
 public function getEntries()
 {
     if (empty($this->entries)) {
         $feeds = $this->getOutlet()->getFeeds();
         foreach ($feeds as $feed) {
             $reader = Reader::import($feed->getUrl());
             foreach ($reader as $entry) {
                 $this->entries[] = $entry;
             }
         }
     }
     return $this->entries;
 }
开发者ID:jpcercal,项目名称:web-scraping,代码行数:16,代码来源:WebScrapingFeed.php

示例10: import

 public function import()
 {
     $this->logger('Import ' . $this->uri, 'info', $this->logger_level);
     try {
         $this->feed = Reader::import($this->uri);
         if (!isset($this->feed)) {
             throw new \Exception('Unreadble');
         }
     } catch (\Exception $e) {
         $this->logger('Feed empty ', 'err', $this->logger_level);
         return false;
     }
 }
开发者ID:eduardohayashi,项目名称:camel-webspider,代码行数:13,代码来源:FeedReader.php

示例11: detectHubs

 /**
  * Simple utility function which imports any feed URL and
  * determines the existence of Hub Server endpoints. This works
  * best if directly given an instance of Zend_Feed_Reader_Atom|Rss
  * to leverage off.
  *
  * @param  Zend_Feed_Reader_FeedAbstract|\Zend\Feed\AbstractFeed|string $source
  * @return array
  */
 public static function detectHubs($source)
 {
     if (is_string($source)) {
         $feed = Reader\Reader::import($source);
     } elseif (is_object($source) && $source instanceof Reader\FeedAbstract) {
         $feed = $source;
     } elseif (is_object($source) && $source instanceof \Zend\Feed\AbstractFeed) {
         $feed = Reader\Reader::importFeed($source);
     } else {
         require_once 'Zend/Feed/Pubsubhubbub/Exception.php';
         throw new Exception('The source parameter was' . ' invalid, i.e. not a URL string or an instance of type' . ' Zend_Feed_Reader_FeedAbstract or Zend_Feed_Abstract');
     }
     return $feed->getHubs();
 }
开发者ID:bradley-holt,项目名称:zf2,代码行数:23,代码来源:PubSubHubbub.php

示例12: import

 /**
  * @inheritDoc
  *
  */
 public function import()
 {
     if (empty($this->feedUri) || !is_string($this->feedUri)) {
         throw new Exception\UnexpectedValueException(sprintf('Feed uri not valid.'));
     }
     $feed = Reader::import($this->feedUri);
     foreach ($feed as $entry) {
         if ($this->entryIsNew($entry)) {
             $postId = $this->createPostFromEntry($entry);
             if (!empty($this->entryParams['taxonomy'])) {
                 $this->createTermsFromEntry($postId, $entry);
             }
         }
     }
 }
开发者ID:bfolliot,项目名称:feed-importer,代码行数:19,代码来源:Importer.php

示例13: getData

 public function getData()
 {
     // Fetch the latest Slashdot headlines
     try {
         $slashdotRss = \Zend\Feed\Reader\Reader::import('http://rss.slashdot.org/Slashdot/slashdot');
     } catch (\Zend\Feed\Exception\Reader\RuntimeException $e) {
         // feed import failed
         echo "Exception caught importing feed: {$e->getMessage()}\n";
         exit;
     }
     // Initialize the channel/feed data array
     $channel = array('title' => $slashdotRss->getTitle(), 'link' => $slashdotRss->getLink(), 'description' => $slashdotRss->getDescription(), 'items' => array());
     // Loop over each channel item/entry and store relevant data for each
     foreach ($slashdotRss as $item) {
         $channel['items'][] = array('title' => $item->getTitle(), 'link' => $item->getLink(), 'description' => $item->getDescription());
     }
     return $channel;
 }
开发者ID:DevWellington,项目名称:my-zf2-example,代码行数:18,代码来源:FeedService.php

示例14: fetch

 public static function fetch($feed_url, $params = array())
 {
     try {
         $news_feed = Reader::import($feed_url);
     } catch (\Exception $e) {
         return array();
     }
     if (is_null($news_feed)) {
         return array();
     }
     $latest_news = array();
     $article_num = 0;
     foreach ($news_feed as $item) {
         $article_num++;
         $guid = $item->getId();
         $title = $item->getTitle();
         // Process categories.
         $categories_raw = $item->getCategories()->getValues();
         // Process main description.
         $description = trim($item->getDescription());
         // Remove extraneous tags.
         $description = str_replace(array("\r", "\n"), array('', ' '), $description);
         // Strip new lines.
         $description = preg_replace('/<a[^(>)]+>read more<\\/a>/iu', '', $description);
         // Remove "read more" link.
         $web_url = $item->getLink();
         if (is_array($web_url)) {
             $web_url = $web_url[0];
         }
         if (!$web_url && substr($guid, 0, 4) == 'http') {
             $web_url = $guid;
         }
         $author = $item->getAuthor();
         if (is_array($author)) {
             $author = $author[0]->nodeValue;
         }
         $news_item = array('guid' => 'rss_' . md5($guid), 'timestamp' => $item->getDateModified()->getTimestamp(), 'media_format' => 'mixed', 'title' => $title, 'body' => $description, 'web_url' => $web_url, 'author' => $author);
         $latest_news[] = $news_item;
     }
     return $latest_news;
 }
开发者ID:Lavoaster,项目名称:PVLive,代码行数:41,代码来源:Rss.php

示例15: read

 public function read()
 {
     $url = sprintf(self::ATOM_FORMAT, $this->user);
     $feed = FeedReader::import($url);
     $lastModified = $feed->getDateModified();
     $altLink = $feed->getLink();
     $entries = array();
     $i = 0;
     foreach ($feed as $entry) {
         if (!$this->filter($entry)) {
             continue;
         }
         $data = array('title' => $entry->getTitle(), 'link' => $entry->getLink());
         $entries[] = $data;
         $i++;
         if ($i > $this->limit) {
             break;
         }
     }
     return array('last_modified' => $lastModified, 'link' => $altLink, 'links' => $entries);
 }
开发者ID:bcremer,项目名称:mwop.net,代码行数:21,代码来源:AtomReader.php


注:本文中的Zend\Feed\Reader\Reader::import方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。