本文整理汇总了PHP中Zend\Feed\Reader\Reader::importFile方法的典型用法代码示例。如果您正苦于以下问题:PHP Reader::importFile方法的具体用法?PHP Reader::importFile怎么用?PHP Reader::importFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Feed\Reader\Reader
的用法示例。
在下文中一共展示了Reader::importFile方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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));
}
示例2: 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;
}
示例3: printf
<?php
use Zend\Feed\Reader\Reader;
require_once __DIR__ . '/../vendor/autoload.php';
if ($argc != 5) {
printf("[%s] Invalid arguments (requires 4, received %d)\n", $argv[0], $argc);
printf("Usage:\n %s [blog-rss] [security-config] [template] [homepage-path]\n", $argv[0]);
exit(1);
}
$blogRssPath = $argv[1];
$securityConfigPath = $argv[2];
$template = $argv[3];
$homepagePath = $argv[4];
$items = array();
$max = 4;
$feed = Reader::importFile($blogRssPath);
$count = 0;
foreach ($feed as $item) {
$items[] = array('title' => $item->getTitle(), 'href' => $item->getLink(), 'date' => $item->getDateCreated());
$count += 1;
if ($count == $max) {
break;
}
}
$securityConfig = (include $securityConfigPath);
$count = 0;
foreach ($securityConfig['security']['advisories'] as $issue => $item) {
$items[] = array('title' => $item['title'], 'href' => sprintf('/security/advisory/%s', $issue), 'date' => DateTime::createFromFormat('D, d F Y H:i:s O', $item['date']));
$count += 1;
if ($count == $max) {
break;
示例4: testImportsFile
public function testImportsFile()
{
try {
$feed = Reader\Reader::importFile(__DIR__ . '/Reader/Entry/_files/Atom/title/plain/atom10.xml');
} catch (\Exception $e) {
$this->fail($e->getMessage());
}
}
示例5: testImportsFile
public function testImportsFile()
{
$feed = Reader\Reader::importFile(dirname(__FILE__) . '/Entry/_files/Atom/title/plain/atom10.xml');
$this->assertInstanceOf('Zend\\Feed\\Reader\\Feed\\FeedInterface', $feed);
}
示例6: getFeedAjax
/**
* Return feed content and settings in JSON format.
*
* @return mixed
*/
public function getFeedAjax()
{
if (!($id = $this->params()->fromQuery('id'))) {
return $this->output('Missing feed id', self::STATUS_ERROR);
}
$touchDevice = $this->params()->fromQuery('touch-device') !== null ? $this->params()->fromQuery('touch-device') === '1' : false;
$config = $this->getServiceLocator()->get('VuFind\\Config')->get('rss');
if (!isset($config[$id])) {
return $this->output('Missing feed configuration', self::STATUS_ERROR);
}
$config = $config[$id];
if (!$config->active) {
return $this->output('Feed inactive', self::STATUS_ERROR);
}
if (!($url = $config->url)) {
return $this->output('Missing feed URL', self::STATUS_ERROR);
}
$translator = $this->getServiceLocator()->get('VuFind\\Translator');
$language = $translator->getLocale();
if (isset($url[$language])) {
$url = trim($url[$language]);
} else {
if (isset($url['*'])) {
$url = trim($url['*']);
} else {
return $this->output('Missing feed URL', self::STATUS_ERROR);
}
}
$type = $config->type;
$channel = null;
// Check for cached version
$cacheEnabled = false;
$cacheDir = $this->getServiceLocator()->get('VuFind\\CacheManager')->getCache('feed')->getOptions()->getCacheDir();
$cacheKey = $config->toArray();
$cacheKey['language'] = $language;
$localFile = "{$cacheDir}/" . md5(var_export($cacheKey, true)) . '.xml';
$cacheConfig = $this->getServiceLocator()->get('VuFind\\Config')->get('config');
$maxAge = isset($cacheConfig->Content->feedcachetime) ? $cacheConfig->Content->feedcachetime : false;
$httpService = $this->getServiceLocator()->get('VuFind\\Http');
Reader::setHttpClient($httpService->createClient());
if ($maxAge) {
$cacheEnabled = true;
if (is_readable($localFile) && time() - filemtime($localFile) < $maxAge * 60) {
$channel = Reader::importFile($localFile);
}
}
if (!$channel) {
// No cache available, read from source.
if (preg_match('/^http(s)?:\\/\\//', $url)) {
// Absolute URL
$channel = Reader::import($url);
} else {
if (substr($url, 0, 1) === '/') {
// Relative URL
$url = substr($this->getServerUrl('home'), 0, -1) . $url;
$channel = Reader::import($url);
} else {
// Local file
if (!is_file($url)) {
return $this->output("File {$url} could not be found", self::STATUS_ERROR);
}
$channel = Reader::importFile($url);
}
}
}
if (!$channel) {
return $this->output('Parsing failed', self::STATUS_ERROR);
}
if ($cacheEnabled) {
file_put_contents($localFile, $channel->saveXml());
}
$content = ['title' => 'getTitle', 'text' => 'getContent', 'image' => 'getEnclosure', 'link' => 'getLink', 'date' => 'getDateCreated'];
$dateFormat = isset($config->dateFormat) ? $config->dateFormat : 'j.n.';
$itemsCnt = isset($config->items) ? $config->items : null;
$items = [];
foreach ($channel as $item) {
$data = [];
foreach ($content as $setting => $method) {
if (!isset($config->content[$setting]) || $config->content[$setting] != 0) {
$tmp = $item->{$method}();
if (is_object($tmp)) {
$tmp = get_object_vars($tmp);
}
if ($setting == 'image') {
if (!$tmp || stripos($tmp['type'], 'image') === false) {
// Attempt to parse image URL from content
if ($tmp = $this->extractImage($item->getContent())) {
$tmp = ['url' => $tmp];
}
}
} else {
if ($setting == 'date') {
if (isset($tmp['date'])) {
$tmp = new \DateTime($tmp['date']);
$tmp = $tmp->format($dateFormat);
//.........这里部分代码省略.........
示例7: processReadFeed
/**
* Utility function for processing a feed (see readFeed, readFeedFromUrl).
*
* @param array $feedConfig Configuration
* @param Zend\Mvc\Controller\Plugin\Url $urlHelper Url helper
* @param string $viewUrl View URL
* @param string $id Feed id (needed when the
* feed content is shown on a content page or in a modal)
*
* @return mixed null|array
*/
protected function processReadFeed($feedConfig, $urlHelper, $viewUrl, $id = null)
{
$config = $feedConfig['result'];
$url = $feedConfig['url'];
$type = $config->type;
$cacheKey = $config->toArray();
$cacheKey['language'] = $this->translator->getLocale();
$modal = false;
$showFullContentOnSite = isset($config->linkTo) && in_array($config->linkTo, ['modal', 'content-page']);
$modal = $config->linkTo == 'modal';
$contentPage = $config->linkTo == 'content-page';
$dateFormat = isset($config->dateFormat) ? $config->dateFormat : 'j.n.';
$contentDateFormat = isset($config->contentDateFormat) ? $config->contentDateFormat : 'j.n.Y';
$itemsCnt = isset($config->items) ? $config->items : null;
$elements = isset($config->content) ? $config->content : [];
$channel = null;
// Check for cached version
$cacheDir = $this->cacheManager->getCache('feed')->getOptions()->getCacheDir();
$localFile = "{$cacheDir}/" . md5(var_export($cacheKey, true)) . '.xml';
$maxAge = isset($this->mainConfig->Content->feedcachetime) ? $this->mainConfig->Content->feedcachetime : 10;
Reader::setHttpClient($this->http->createClient());
if ($maxAge) {
if (is_readable($localFile) && time() - filemtime($localFile) < $maxAge * 60) {
$channel = Reader::importFile($localFile);
}
}
if (!$channel) {
// No cache available, read from source.
if (preg_match('/^http(s)?:\\/\\//', $url)) {
// Absolute URL
$channel = Reader::import($url);
} else {
if (substr($url, 0, 1) === '/') {
// Relative URL
$url = substr($viewUrl, 0, -1) . $url;
try {
$channel = Reader::import($url);
} catch (\Exception $e) {
$this->logError("Error importing feed from url {$url}");
$this->logError(" " . $e->getMessage());
}
} else {
// Local file
if (!is_file($url)) {
$this->logError("File {$url} could not be found");
throw new \Exception('Error reading feed');
}
$channel = Reader::importFile($url);
}
}
if ($channel) {
file_put_contents($localFile, $channel->saveXml());
}
}
if (!$channel) {
return false;
}
$content = ['title' => 'getTitle', 'text' => 'getContent', 'image' => 'getEnclosure', 'link' => 'getLink', 'date' => 'getDateCreated', 'contentDate' => 'getDateCreated'];
$xpathContent = ['html' => '//item/content:encoded'];
$items = [];
$cnt = 0;
$xpath = null;
$cnt = 0;
foreach ($channel as $item) {
if (!$xpath) {
$xpath = $item->getXpath();
}
$data = [];
$data['modal'] = $modal;
foreach ($content as $setting => $method) {
if (!isset($elements[$setting]) || $elements[$setting] != 0) {
$value = $item->{$method}();
if (is_object($value)) {
$value = get_object_vars($value);
}
if ($setting == 'image') {
if (!$value || stripos($value['type'], 'image') === false) {
// Attempt to parse image URL from content
if ($value = $this->extractImage($item->getContent())) {
$value = ['url' => $value];
}
}
} else {
if ($setting == 'date') {
if (isset($value['date'])) {
$value = new \DateTime($value['date']);
if ($dateFormat) {
$value = $value->format($dateFormat);
}
//.........这里部分代码省略.........