Add UserAgent and HTTP connection timeout
This commit is contained in:
parent
6f9c55df8a
commit
402b2fe7a9
@ -11,6 +11,8 @@ require 'model.php';
|
||||
|
||||
const DB_VERSION = 1;
|
||||
const APP_VERSION = 'master';
|
||||
const APP_USERAGENT = 'Miniflux - http://miniflux.net';
|
||||
const HTTP_TIMEOUT = 5;
|
||||
|
||||
|
||||
// For future use...
|
||||
|
@ -64,7 +64,7 @@ function import_feeds($content)
|
||||
function import_feed($url)
|
||||
{
|
||||
$reader = new Reader;
|
||||
$reader->download($url);
|
||||
$reader->download($url, HTTP_TIMEOUT, APP_USERAGENT);
|
||||
|
||||
$parser = $reader->getParser();
|
||||
|
||||
@ -268,7 +268,7 @@ function update_feeds()
|
||||
foreach (get_feeds() as $feed) {
|
||||
|
||||
$reader = new Reader;
|
||||
$reader->download($feed['feed_url']);
|
||||
$reader->download($feed['feed_url'], HTTP_TIMEOUT, APP_USERAGENT);
|
||||
$parser = $reader->getParser();
|
||||
|
||||
if ($parser !== false) {
|
||||
@ -284,7 +284,7 @@ function update_feed($feed_id)
|
||||
$feed = get_feed($feed_id);
|
||||
|
||||
$reader = new Reader;
|
||||
$reader->download($feed['feed_url']);
|
||||
$reader->download($feed['feed_url'], HTTP_TIMEOUT, APP_USERAGENT);
|
||||
$parser = $reader->getParser();
|
||||
|
||||
if ($parser !== false) {
|
||||
|
19
miniflux/vendor/PicoFeed/Export.php
vendored
19
miniflux/vendor/PicoFeed/Export.php
vendored
@ -6,6 +6,12 @@ class Export
|
||||
{
|
||||
private $content = array();
|
||||
|
||||
public $required_fields = array(
|
||||
'title',
|
||||
'site_url',
|
||||
'feed_url'
|
||||
);
|
||||
|
||||
|
||||
public function __construct(array $content)
|
||||
{
|
||||
@ -24,6 +30,19 @@ class Export
|
||||
|
||||
foreach ($this->content as $feed) {
|
||||
|
||||
$valid = true;
|
||||
|
||||
foreach ($this->required_fields as $field) {
|
||||
|
||||
if (! isset($feed[$field])) {
|
||||
|
||||
$valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (! $valid) continue;
|
||||
|
||||
$outline = $body->addChild('outline');
|
||||
$outline->addAttribute('xmlUrl', $feed['feed_url']);
|
||||
$outline->addAttribute('htmlUrl', $feed['site_url']);
|
||||
|
27
miniflux/vendor/PicoFeed/Reader.php
vendored
27
miniflux/vendor/PicoFeed/Reader.php
vendored
@ -16,7 +16,7 @@ class Reader
|
||||
}
|
||||
|
||||
|
||||
public function download($url)
|
||||
public function download($url, $timeout = 5, $user_agent = 'PicoFeed (https://github.com/fguillot/picoFeed)')
|
||||
{
|
||||
if (strpos($url, 'http') !== 0) {
|
||||
|
||||
@ -24,12 +24,35 @@ class Reader
|
||||
}
|
||||
|
||||
$this->url = $url;
|
||||
$this->content = @file_get_contents($this->url);
|
||||
$this->content = $this->fetchRemoteFile($url, $timeout, $user_agent);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function fetchRemoteFile($url, $timeout, $user_agent)
|
||||
{
|
||||
if (! \function_exists('curl_init')) {
|
||||
|
||||
return @file_get_contents($this->url);
|
||||
}
|
||||
|
||||
$ch = \curl_init();
|
||||
|
||||
\curl_setopt($ch, CURLOPT_URL, $url);
|
||||
\curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
\curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
\curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
|
||||
\curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
|
||||
|
||||
$content = \curl_exec($ch);
|
||||
|
||||
\curl_close($ch);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
return $this->content;
|
||||
|
Loading…
Reference in New Issue
Block a user