當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。