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


PHP Reader\Reader类代码示例

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


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

示例1: 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

示例2: getAuthors

 /**
  * Get an array with feed authors
  *
  * @return array
  */
 public function getAuthors()
 {
     if (array_key_exists('authors', $this->data)) {
         return $this->data['authors'];
     }
     $authors = array();
     $list = $this->getXpath()->query('//dc11:creator');
     if (!$list->length) {
         $list = $this->getXpath()->query('//dc10:creator');
     }
     if (!$list->length) {
         $list = $this->getXpath()->query('//dc11:publisher');
         if (!$list->length) {
             $list = $this->getXpath()->query('//dc10:publisher');
         }
     }
     if ($list->length) {
         foreach ($list as $author) {
             $authors[] = array('name' => $author->nodeValue);
         }
         $authors = new Collection\Author(Reader\Reader::arrayUnique($authors));
     } else {
         $authors = null;
     }
     $this->data['authors'] = $authors;
     return $this->data['authors'];
 }
开发者ID:tillk,项目名称:vufind,代码行数:32,代码来源:Feed.php

示例3: testCanDetectHubs

 public function testCanDetectHubs()
 {
     $feed = \Zend\Feed\Reader\Reader::importFile(__DIR__ . '/_files/rss20.xml');
     $this->assertEquals(array(
         'http://www.example.com/hub', 'http://www.example.com/hub2'
     ), PubSubHubbub\PubSubHubbub::detectHubs($feed));
 }
开发者ID:niallmccrudden,项目名称:zf2,代码行数:7,代码来源:PubSubHubbubTest.php

示例4: getAuthors

 /**
  * Get an array with feed authors
  *
  * @return array
  */
 public function getAuthors()
 {
     if (array_key_exists('authors', $this->_data)) {
         return $this->_data['authors'];
     }
     $authors = array();
     $list = $this->getXpath()->query($this->getXpathPrefix() . '//atom:author');
     if (!$list->length) {
         /**
          * TODO: Limit query to feed level els only!
          */
         $list = $this->getXpath()->query('//atom:author');
     }
     if ($list->length) {
         foreach ($list as $author) {
             $author = $this->_getAuthor($author);
             if (!empty($author)) {
                 $authors[] = $author;
             }
         }
     }
     if (count($authors) == 0) {
         $authors = null;
     } else {
         $authors = new Collection\Author(Reader\Reader::arrayUnique($authors));
     }
     $this->_data['authors'] = $authors;
     return $this->_data['authors'];
 }
开发者ID:brikou,项目名称:zend_feed,代码行数:34,代码来源:Entry.php

示例5: getAuthors

    /**
     * Get an array with feed authors
     *
     * @return array
     */
    public function getAuthors()
    {
        if (array_key_exists('authors', $this->_data)) {
            return $this->_data['authors'];
        }

        $list = $this->_xpath->query('//atom:author');

        $authors = array();

        if ($list->length) {
            foreach ($list as $author) {
                $author = $this->_getAuthor($author);
                if (!empty($author)) {
                    $authors[] = $author;
                }
            }
        }

        if (count($authors) == 0) {
            $authors = null;
        } else {
            $authors = new Collection\Author(
                Reader\Reader::arrayUnique($authors)
            );
        }

        $this->_data['authors'] = $authors;

        return $this->_data['authors'];
    }
开发者ID:niallmccrudden,项目名称:zf2,代码行数:36,代码来源:Feed.php

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: isFeed

 /**
  * Returns if the provided $content_type is a feed.
  *
  * @param string $document
  *   The actual HTML or XML document from the HTTP request.
  *
  * @return bool
  *   Returns true if this is a parsable feed, false if not.
  */
 public static function isFeed($data)
 {
     Reader::setExtensionManager(\Drupal::service('feed.bridge.reader'));
     try {
         $feed_type = Reader::detectType($data);
     } catch (\Exception $e) {
         return FALSE;
     }
     return $feed_type != Reader::TYPE_ANY;
 }
开发者ID:Tawreh,项目名称:mtg,代码行数:19,代码来源:Feed.php

示例11: 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

示例12: 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

示例13: 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

示例14: __construct

 /**
  * Constructor
  *
  * @param  DOMDocument $dom
  * @param  string $type
  */
 public function __construct(DOMDocument $dom, $type = null)
 {
     parent::__construct($dom, $type);
     $atomClass = Reader\Reader::getPluginLoader()->getClassName('Atom\\Feed');
     $this->_extensions['Atom\\Feed'] = new $atomClass($dom, $this->_data['type'], $this->_xpath);
     $atomClass = Reader\Reader::getPluginLoader()->getClassName('DublinCore\\Feed');
     $this->_extensions['DublinCore\\Feed'] = new $atomClass($dom, $this->_data['type'], $this->_xpath);
     foreach ($this->_extensions as $extension) {
         $extension->setXpathPrefix('/atom:feed');
     }
 }
开发者ID:navassouza,项目名称:zf2,代码行数:17,代码来源:Atom.php

示例15: __invoke

 public function __invoke($services)
 {
     $http = $services->get('http');
     FeedReader::setHttpClient($http);
     FeedReader::setExtensionManager($this->createExtensionManager());
     $config = $services->get('Config');
     $config = $config['github'];
     $reader = new AtomReader($config['user']);
     $reader->setLimit($config['limit']);
     return $reader;
 }
开发者ID:bcremer,项目名称:mwop.net,代码行数:11,代码来源:AtomReaderFactory.php


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