本文整理汇总了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);
}
示例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'];
}
示例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));
}
示例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'];
}
示例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'];
}
示例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;
}
}
示例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;
}
示例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()];
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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();
}
示例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');
}
}
示例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;
}