diff options
Diffstat (limited to 'vendor/fguillot/picofeed/lib/PicoFeed/Client')
5 files changed, 102 insertions, 27 deletions
diff --git a/vendor/fguillot/picofeed/lib/PicoFeed/Client/Client.php b/vendor/fguillot/picofeed/lib/PicoFeed/Client/Client.php index c8c812c1a..602416e42 100644 --- a/vendor/fguillot/picofeed/lib/PicoFeed/Client/Client.php +++ b/vendor/fguillot/picofeed/lib/PicoFeed/Client/Client.php @@ -199,16 +199,9 @@ abstract class Client $this->is_modified = false; } else if ($response['status'] == 200) { - - $etag = $this->getHeader($response, 'ETag'); - $last_modified = $this->getHeader($response, 'Last-Modified'); - - if ($this->isPropertyEquals('etag', $etag) || $this->isPropertyEquals('last_modified', $last_modified)) { - $this->is_modified = false; - } - - $this->etag = $etag; - $this->last_modified = $last_modified; + $this->is_modified = $this->hasBeenModified($response, $this->etag, $this->last_modified); + $this->etag = $this->getHeader($response, 'ETag'); + $this->last_modified = $this->getHeader($response, 'Last-Modified'); } if ($this->is_modified === false) { @@ -245,16 +238,39 @@ abstract class Client } /** - * Check if a class property equals to a value + * Check if a request has been modified according to the parameters * * @access public - * @param string $property Class property - * @param string $value Value + * @param array $response + * @param string $etag + * @param string $lastModified * @return boolean */ - private function isPropertyEquals($property, $value) + private function hasBeenModified($response, $etag, $lastModified) { - return $this->$property && $this->$property === $value; + $headers = array( + 'Etag' => $etag, + 'Last-Modified' => $lastModified + ); + + // Compare the values for each header that is present + $presentCacheHeaderCount = 0; + foreach ($headers as $key => $value) { + if (isset($response['headers'][$key])) { + if ($response['headers'][$key] !== $value) { + return true; + } + $presentCacheHeaderCount++; + } + } + + // If at least one header is present and the values match, the response + // was not modified + if ($presentCacheHeaderCount > 0) { + return false; + } + + return true; } /** @@ -324,7 +340,7 @@ abstract class Client Logger::setMessage(get_called_class().' HTTP header: '.$name.' => '.$value); } - return array($status, $headers); + return array($status, new HttpHeaders($headers)); } /** @@ -552,7 +568,7 @@ abstract class Client * * @access public * @param \PicoFeed\Config\Config $config Config instance - * @return \PicoFeed\Config\Config + * @return \PicoFeed\Client\Client */ public function setConfig($config) { diff --git a/vendor/fguillot/picofeed/lib/PicoFeed/Client/Curl.php b/vendor/fguillot/picofeed/lib/PicoFeed/Client/Curl.php index 2b0d7e1c0..54b3c6ef9 100644 --- a/vendor/fguillot/picofeed/lib/PicoFeed/Client/Curl.php +++ b/vendor/fguillot/picofeed/lib/PicoFeed/Client/Curl.php @@ -99,7 +99,7 @@ class Curl extends Client * Prepare HTTP headers * * @access private - * @return array + * @return string[] */ private function prepareHeaders() { @@ -123,7 +123,7 @@ class Curl extends Client * Prepare curl proxy context * * @access private - * @return resource + * @return resource $ch */ private function prepareProxyContext($ch) { @@ -199,6 +199,9 @@ class Curl extends Client $this->handleError($curl_errno); } + // Update the url if there where redirects + $this->url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); + curl_close($ch); } @@ -215,7 +218,7 @@ class Curl extends Client list($status, $headers) = $this->parseHeaders(explode("\r\n", $this->headers[$this->headers_counter - 1])); - // When resticted with open_basedir + // When restricted with open_basedir if ($this->needToHandleRedirection($follow_location, $status)) { return $this->handleRedirection($headers['Location']); } diff --git a/vendor/fguillot/picofeed/lib/PicoFeed/Client/Grabber.php b/vendor/fguillot/picofeed/lib/PicoFeed/Client/Grabber.php index 57661cb7b..1bca05664 100644 --- a/vendor/fguillot/picofeed/lib/PicoFeed/Client/Grabber.php +++ b/vendor/fguillot/picofeed/lib/PicoFeed/Client/Grabber.php @@ -3,7 +3,6 @@ namespace PicoFeed\Client; use DOMXPath; - use PicoFeed\Encoding\Encoding; use PicoFeed\Logging\Logger; use PicoFeed\Filter\Filter; @@ -148,7 +147,7 @@ class Grabber * * @access public * @param \PicoFeed\Config\Config $config Config instance - * @return \PicoFeed\Grabber + * @return Grabber */ public function setConfig($config) { @@ -179,6 +178,19 @@ class Grabber } /** + * Get filtered relevant content + * + * @access public + * @return string + */ + public function getFilteredContent() + { + $filter = Filter::html($this->content, $this->url); + $filter->setConfig($this->config); + return $filter->execute(); + } + + /** * Parse the HTML content * * @access public @@ -191,8 +203,8 @@ class Grabber Logger::setMessage(get_called_class().' Fix encoding'); Logger::setMessage(get_called_class().': HTTP Encoding "'.$this->encoding.'"'); - $this->html = Filter::stripHeadTags($this->html); $this->html = Encoding::convert($this->html, $this->encoding); + $this->html = Filter::stripHeadTags($this->html); Logger::setMessage(get_called_class().' Content length: '.strlen($this->html).' bytes'); $rules = $this->getRules(); @@ -228,6 +240,7 @@ class Grabber $client->setConfig($this->config); $client->execute($this->url); + $this->url = $client->getUrl(); $this->html = $client->getContent(); $this->encoding = $client->getEncoding(); diff --git a/vendor/fguillot/picofeed/lib/PicoFeed/Client/HttpHeaders.php b/vendor/fguillot/picofeed/lib/PicoFeed/Client/HttpHeaders.php new file mode 100644 index 000000000..4453a7871 --- /dev/null +++ b/vendor/fguillot/picofeed/lib/PicoFeed/Client/HttpHeaders.php @@ -0,0 +1,43 @@ +<?php + +namespace PicoFeed\Client; + +use ArrayAccess; + +/** + * Class to handle http headers case insensitivity + * + * @author Bernhard Posselt + * @package Client + */ +class HttpHeaders implements ArrayAccess +{ + private $headers = array(); + + public function __construct(array $headers) + { + foreach ($headers as $key => $value) { + $this->headers[strtolower($key)] = $value; + } + } + + public function offsetGet($offset) + { + return $this->headers[strtolower($offset)]; + } + + public function offsetSet($offset, $value) + { + $this->headers[strtolower($offset)] = $value; + } + + public function offsetExists($offset) + { + return isset($this->headers[strtolower($offset)]); + } + + public function offsetUnset($offset) + { + unset($this->headers[strtolower($offset)]); + } +} diff --git a/vendor/fguillot/picofeed/lib/PicoFeed/Client/Stream.php b/vendor/fguillot/picofeed/lib/PicoFeed/Client/Stream.php index a0058f9b0..32d045cb1 100644 --- a/vendor/fguillot/picofeed/lib/PicoFeed/Client/Stream.php +++ b/vendor/fguillot/picofeed/lib/PicoFeed/Client/Stream.php @@ -16,7 +16,7 @@ class Stream extends Client * Prepare HTTP headers * * @access private - * @return array + * @return string[] */ private function prepareHeaders() { @@ -128,11 +128,11 @@ class Stream extends Client * Decode body response according to the HTTP headers * * @access public - * @param string $body Raw body - * @param array $headers HTTP headers + * @param string $body Raw body + * @param HttpHeaders $headers HTTP headers * @return string */ - public function decodeBody($body, array $headers) + public function decodeBody($body, HttpHeaders $headers) { if (isset($headers['Transfer-Encoding']) && $headers['Transfer-Encoding'] === 'chunked') { $body = $this->decodeChunked($body); |