Update to PicoFeed v0.1.7

This commit is contained in:
Frederic Guillot 2015-08-02 14:08:21 -04:00
parent e32f96eed2
commit cbbf20ebbd
12 changed files with 94 additions and 33 deletions

View File

@ -6,7 +6,7 @@
"fguillot/simple-validator": "v0.0.3", "fguillot/simple-validator": "v0.0.3",
"fguillot/json-rpc": "v0.0.3", "fguillot/json-rpc": "v0.0.3",
"fguillot/picodb": "v0.0.3", "fguillot/picodb": "v0.0.3",
"fguillot/picofeed": "v0.1.6", "fguillot/picofeed": "v0.1.7",
"fguillot/picofarad": "dev-master" "fguillot/picofarad": "dev-master"
}, },
"autoload": { "autoload": {

View File

@ -54,6 +54,8 @@ class ClassLoader
private $useIncludePath = false; private $useIncludePath = false;
private $classMap = array(); private $classMap = array();
private $classMapAuthoritative = false;
public function getPrefixes() public function getPrefixes()
{ {
if (!empty($this->prefixesPsr0)) { if (!empty($this->prefixesPsr0)) {
@ -248,6 +250,27 @@ class ClassLoader
return $this->useIncludePath; return $this->useIncludePath;
} }
/**
* Turns off searching the prefix and fallback directories for classes
* that have not been registered with the class map.
*
* @param bool $classMapAuthoritative
*/
public function setClassMapAuthoritative($classMapAuthoritative)
{
$this->classMapAuthoritative = $classMapAuthoritative;
}
/**
* Should class lookup fail if not found in the current class map?
*
* @return bool
*/
public function isClassMapAuthoritative()
{
return $this->classMapAuthoritative;
}
/** /**
* Registers this instance as an autoloader. * Registers this instance as an autoloader.
* *
@ -299,6 +322,9 @@ class ClassLoader
if (isset($this->classMap[$class])) { if (isset($this->classMap[$class])) {
return $this->classMap[$class]; return $this->classMap[$class];
} }
if ($this->classMapAuthoritative) {
return false;
}
$file = $this->findFileWithExtension($class, '.php'); $file = $this->findFileWithExtension($class, '.php');

View File

@ -156,17 +156,17 @@
}, },
{ {
"name": "fguillot/picofeed", "name": "fguillot/picofeed",
"version": "v0.1.6", "version": "v0.1.7",
"version_normalized": "0.1.6.0", "version_normalized": "0.1.7.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/fguillot/picoFeed.git", "url": "https://github.com/fguillot/picoFeed.git",
"reference": "1e89a3fd579cf3d83cc65c09047f92f81ce6a923" "reference": "8ed3f1a9f777938611645d523ddc707a7cd0e7d7"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/fguillot/picoFeed/zipball/1e89a3fd579cf3d83cc65c09047f92f81ce6a923", "url": "https://api.github.com/repos/fguillot/picoFeed/zipball/8ed3f1a9f777938611645d523ddc707a7cd0e7d7",
"reference": "1e89a3fd579cf3d83cc65c09047f92f81ce6a923", "reference": "8ed3f1a9f777938611645d523ddc707a7cd0e7d7",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -180,7 +180,7 @@
"suggest": { "suggest": {
"ext-curl": "PicoFeed will use cURL if present" "ext-curl": "PicoFeed will use cURL if present"
}, },
"time": "2015-07-12 23:33:40", "time": "2015-08-02 17:56:46",
"bin": [ "bin": [
"picofeed" "picofeed"
], ],

View File

@ -243,8 +243,7 @@ class Curl extends Client
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->timeout); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->timeout);
curl_setopt($ch, CURLOPT_USERAGENT, $this->user_agent); curl_setopt($ch, CURLOPT_USERAGENT, $this->user_agent);
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->prepareHeaders()); curl_setopt($ch, CURLOPT_HTTPHEADER, $this->prepareHeaders());
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, ini_get('open_basedir') === ''); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_MAXREDIRS, $this->max_redirects);
curl_setopt($ch, CURLOPT_ENCODING, ''); curl_setopt($ch, CURLOPT_ENCODING, '');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'php://memory'); curl_setopt($ch, CURLOPT_COOKIEJAR, 'php://memory');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'php://memory'); curl_setopt($ch, CURLOPT_COOKIEFILE, 'php://memory');
@ -310,8 +309,7 @@ class Curl extends Client
list($status, $headers) = HttpHeaders::parse(explode("\n", $this->response_headers[$this->response_headers_count - 1])); list($status, $headers) = HttpHeaders::parse(explode("\n", $this->response_headers[$this->response_headers_count - 1]));
// When restricted with open_basedir if ($follow_location && ($status == 301 || $status == 302)) {
if ($this->needToHandleRedirection($follow_location, $status)) {
return $this->handleRedirection($headers['Location']); return $this->handleRedirection($headers['Location']);
} }
@ -322,19 +320,6 @@ class Curl extends Client
); );
} }
/**
* Check if the redirection have to be handled manually
*
* @access private
* @param boolean $follow_location Flag
* @param integer $status HTTP status code
* @return boolean
*/
private function needToHandleRedirection($follow_location, $status)
{
return $follow_location && ini_get('open_basedir') !== '' && ($status == 301 || $status == 302);
}
/** /**
* Handle manually redirections when there is an open base dir restriction * Handle manually redirections when there is an open base dir restriction
* *

View File

@ -148,6 +148,24 @@ class Url
return empty($path) || $path{0} !== '/'; return empty($path) || $path{0} !== '/';
} }
/**
* Filters the path of a URI
*
* Imported from Guzzle library: https://github.com/guzzle/psr7/blob/master/src/Uri.php#L568-L582
*
* @access public
* @param $path
* @return string
*/
public function filterPath($path, $charUnreserved = 'a-zA-Z0-9_\-\.~', $charSubDelims = '!\$&\'\(\)\*\+,;=')
{
return preg_replace_callback(
'/(?:[^' . $charUnreserved . $charSubDelims . ':@\/%]+|%(?![A-Fa-f0-9]{2}))/',
function (array $matches) { return rawurlencode($matches[0]); },
$path
);
}
/** /**
* Get the path * Get the path
* *
@ -156,7 +174,7 @@ class Url
*/ */
public function getPath() public function getPath()
{ {
return empty($this->components['path']) ? '' : $this->components['path']; return $this->filterPath(empty($this->components['path']) ? '' : $this->components['path']);
} }
/** /**

View File

@ -149,6 +149,7 @@ class Attribute
'feeds.feedburner.com', 'feeds.feedburner.com',
'share.feedsportal.com', 'share.feedsportal.com',
'da.feedsportal.com', 'da.feedsportal.com',
'rc.feedsportal.com',
'rss.feedsportal.com', 'rss.feedsportal.com',
'res.feedsportal.com', 'res.feedsportal.com',
'res1.feedsportal.com', 'res1.feedsportal.com',

View File

@ -0,0 +1,25 @@
<?php
return array(
'grabber' => array(
'%.*%' => array(
'test_url' => 'http://www.lesnumeriques.com/blender/kitchenaid-diamond-5ksb1585-p27473/test.html',
'body' => array(
'//*[@id="product-content"]',
'//*[@id="news-content"]',
'//*[@id="article-content"]',
),
'strip' => array(
'//form',
'//div[contains(@class, "price-v4"])',
'//div[contains(@class, "authors-and-date")]',
'//div[contains(@class, "mini-product")]',
'//div[@id="articles-related-authors"]',
'//div[@id="tags-socials"]',
'//div[@id="user-reviews"]',
'//div[@id="product-reviews"]',
'//div[@id="publication-breadcrumbs-and-date"]',
'//div[@id="publication-breadcrumbs-and-date"]',
)
)
)
);

View File

@ -179,7 +179,7 @@ class Rss20 extends Writer
{ {
$xml->appendChild($this->dom->createElement( $xml->appendChild($this->dom->createElement(
'pubDate', 'pubDate',
date(DATE_RFC822, $value ?: time()) date(DATE_RSS, $value ?: time())
)); ));
} }

View File

@ -28,7 +28,7 @@ class ClientTest extends PHPUnit_Framework_TestCase
public function testPassthrough() public function testPassthrough()
{ {
$client = Client::getInstance(); $client = Client::getInstance();
$client->setUrl('http://miniflux.net/favicon.ico'); $client->setUrl('https://miniflux.net/favicon.ico');
$client->enablePassthroughMode(); $client->enablePassthroughMode();
$client->execute(); $client->execute();

View File

@ -28,7 +28,7 @@ class CurlTest extends PHPUnit_Framework_TestCase
public function testPassthrough() public function testPassthrough()
{ {
$client = new Curl; $client = new Curl;
$client->setUrl('http://miniflux.net/favicon.ico'); $client->setUrl('https://miniflux.net/favicon.ico');
$client->enablePassthroughMode(); $client->enablePassthroughMode();
$client->doRequest(); $client->doRequest();

View File

@ -288,5 +288,11 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
'', '',
Url::resolve('', '') Url::resolve('', '')
); );
// Test no-ascii paths
$this->assertEquals(
'http://lesjoiesducode.fr/post/125336534020/quand-la-page-doit-%C3%AAtre-pixel-perfect',
Url::resolve('http://lesjoiesducode.fr/post/125336534020/quand-la-page-doit-être-pixel-perfect', 'http://lesjoiesducode.fr/post/125336534020')
);
} }
} }

View File

@ -50,7 +50,7 @@ class Rss20WriterTest extends PHPUnit_Framework_TestCase
<generator>PicoFeed (https://github.com/fguillot/picoFeed)</generator> <generator>PicoFeed (https://github.com/fguillot/picoFeed)</generator>
<title>My site</title> <title>My site</title>
<description>My site</description> <description>My site</description>
<pubDate>'.date(DATE_RFC822).'</pubDate> <pubDate>'.date(DATE_RSS).'</pubDate>
<atom:link href="http://boo/feed.atom" rel="self" type="application/rss+xml"/> <atom:link href="http://boo/feed.atom" rel="self" type="application/rss+xml"/>
<link>http://boo/</link> <link>http://boo/</link>
<webMaster>me@here (Me)</webMaster> <webMaster>me@here (Me)</webMaster>
@ -58,7 +58,7 @@ class Rss20WriterTest extends PHPUnit_Framework_TestCase
<title>My article 1</title> <title>My article 1</title>
<link>http://foo/bar</link> <link>http://foo/bar</link>
<guid isPermaLink="true">http://foo/bar</guid> <guid isPermaLink="true">http://foo/bar</guid>
<pubDate>'.date(DATE_RFC822, strtotime('-2 days')).'</pubDate> <pubDate>'.date(DATE_RSS, strtotime('-2 days')).'</pubDate>
<description>Super summary</description> <description>Super summary</description>
<content:encoded><![CDATA[<p>content</p>]]></content:encoded> <content:encoded><![CDATA[<p>content</p>]]></content:encoded>
</item> </item>
@ -66,7 +66,7 @@ class Rss20WriterTest extends PHPUnit_Framework_TestCase
<title>My article 2</title> <title>My article 2</title>
<link>http://foo/bar2</link> <link>http://foo/bar2</link>
<guid isPermaLink="true">http://foo/bar2</guid> <guid isPermaLink="true">http://foo/bar2</guid>
<pubDate>'.date(DATE_RFC822, strtotime('-1 day')).'</pubDate> <pubDate>'.date(DATE_RSS, strtotime('-1 day')).'</pubDate>
<description>Super summary 2</description> <description>Super summary 2</description>
<content:encoded><![CDATA[<p>content 2 &nbsp; &copy; 2015</p>]]></content:encoded> <content:encoded><![CDATA[<p>content 2 &nbsp; &copy; 2015</p>]]></content:encoded>
</item> </item>
@ -74,7 +74,7 @@ class Rss20WriterTest extends PHPUnit_Framework_TestCase
<title>My article 3</title> <title>My article 3</title>
<link>http://foo/bar3</link> <link>http://foo/bar3</link>
<guid isPermaLink="true">http://foo/bar3</guid> <guid isPermaLink="true">http://foo/bar3</guid>
<pubDate>'.date(DATE_RFC822).'</pubDate> <pubDate>'.date(DATE_RSS).'</pubDate>
</item> </item>
</channel> </channel>
</rss> </rss>
@ -82,4 +82,4 @@ class Rss20WriterTest extends PHPUnit_Framework_TestCase
$this->assertEquals($expected_output, $generated_output); $this->assertEquals($expected_output, $generated_output);
} }
} }