diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-11-09 11:44:09 +0100 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-11-09 11:44:09 +0100 |
commit | b9e330109b58fac55c3728dd3c543552fcabd353 (patch) | |
tree | 93d386ca453b4b90f517018eb63a4b64df22e8ba | |
parent | e5d18a22c3c15acf61f97da4965a551b83df05cb (diff) |
update picofeed to 0.1.0
37 files changed, 400 insertions, 177 deletions
diff --git a/composer.json b/composer.json index 6050bcff4..a35672b65 100644 --- a/composer.json +++ b/composer.json @@ -32,6 +32,6 @@ "require": { "pear/net_url2": "~2.1", "ezyang/htmlpurifier": "~4.6", - "fguillot/picofeed": "0.1.0-dev-dev" + "fguillot/picofeed": "~0.1.0" } } diff --git a/composer.lock b/composer.lock index ce730f2ab..f8a96a493 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "a50b15fc49d316cb5b2db3e9e7ea78b3", + "hash": "3cbce8173a1c93656be80baf11715718", "packages": [ { "name": "ezyang/htmlpurifier", @@ -53,16 +53,16 @@ }, { "name": "fguillot/picofeed", - "version": "dev-0.1.0-dev", + "version": "v0.1.0", "source": { "type": "git", "url": "https://github.com/fguillot/picoFeed.git", - "reference": "e7e32522b487256c3164eeece30203313b09456a" + "reference": "d36a878e912a04c15f49da97e8d627280ae6918c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fguillot/picoFeed/zipball/e7e32522b487256c3164eeece30203313b09456a", - "reference": "e7e32522b487256c3164eeece30203313b09456a", + "url": "https://api.github.com/repos/fguillot/picoFeed/zipball/d36a878e912a04c15f49da97e8d627280ae6918c", + "reference": "d36a878e912a04c15f49da97e8d627280ae6918c", "shasum": "" }, "require": { @@ -86,7 +86,7 @@ ], "description": "Modern library to write or read feeds (RSS/Atom)", "homepage": "http://fguillot.github.io/picoFeed", - "time": "2014-11-05 01:21:29" + "time": "2014-11-08 14:43:27" }, { "name": "pear/net_url2", @@ -156,9 +156,7 @@ "packages-dev": [], "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "fguillot/picofeed": 20 - }, + "stability-flags": [], "prefer-stable": false, "platform": [], "platform-dev": [] diff --git a/vendor/autoload.php b/vendor/autoload.php index 3cd25b0d2..bf039c269 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer' . '/autoload_real.php'; -return ComposerAutoloaderInit4750e3a2a6327c742e19653287d1e34f::getLoader(); +return ComposerAutoloaderInit1a5ae2c0139f33f17ed4df8077538870::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 16fe7ad69..c601c9c64 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit4750e3a2a6327c742e19653287d1e34f +class ComposerAutoloaderInit1a5ae2c0139f33f17ed4df8077538870 { private static $loader; @@ -19,9 +19,9 @@ class ComposerAutoloaderInit4750e3a2a6327c742e19653287d1e34f return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInit4750e3a2a6327c742e19653287d1e34f', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit1a5ae2c0139f33f17ed4df8077538870', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(); - spl_autoload_unregister(array('ComposerAutoloaderInit4750e3a2a6327c742e19653287d1e34f', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit1a5ae2c0139f33f17ed4df8077538870', 'loadClassLoader')); $includePaths = require __DIR__ . '/include_paths.php'; array_push($includePaths, get_include_path()); @@ -46,14 +46,14 @@ class ComposerAutoloaderInit4750e3a2a6327c742e19653287d1e34f $includeFiles = require __DIR__ . '/autoload_files.php'; foreach ($includeFiles as $file) { - composerRequire4750e3a2a6327c742e19653287d1e34f($file); + composerRequire1a5ae2c0139f33f17ed4df8077538870($file); } return $loader; } } -function composerRequire4750e3a2a6327c742e19653287d1e34f($file) +function composerRequire1a5ae2c0139f33f17ed4df8077538870($file) { require $file; } diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index f7a314210..f3aa9a500 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -114,25 +114,25 @@ }, { "name": "fguillot/picofeed", - "version": "dev-0.1.0-dev", - "version_normalized": "dev-0.1.0-dev", + "version": "v0.1.0", + "version_normalized": "0.1.0.0", "source": { "type": "git", "url": "https://github.com/fguillot/picoFeed.git", - "reference": "e7e32522b487256c3164eeece30203313b09456a" + "reference": "d36a878e912a04c15f49da97e8d627280ae6918c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fguillot/picoFeed/zipball/e7e32522b487256c3164eeece30203313b09456a", - "reference": "e7e32522b487256c3164eeece30203313b09456a", + "url": "https://api.github.com/repos/fguillot/picoFeed/zipball/d36a878e912a04c15f49da97e8d627280ae6918c", + "reference": "d36a878e912a04c15f49da97e8d627280ae6918c", "shasum": "" }, "require": { "php": ">=5.3.0" }, - "time": "2014-11-05 01:21:29", + "time": "2014-11-08 14:43:27", "type": "library", - "installation-source": "dist", + "installation-source": "source", "autoload": { "psr-0": { "PicoFeed": "lib/" diff --git a/vendor/fguillot/picofeed/README.markdown b/vendor/fguillot/picofeed/README.markdown index 8f01b4e8e..868d532e9 100644 --- a/vendor/fguillot/picofeed/README.markdown +++ b/vendor/fguillot/picofeed/README.markdown @@ -42,6 +42,13 @@ Authors - [Bernhard Posselt](https://github.com/Raydiation) - [David Pennington](https://github.com/Xeoncross) +Real world usage +---------------- + +- [AnythingNew](http://anythingnew.co) +- [Miniflux](http://miniflux.net) +- [Owncloud News](https://github.com/owncloud/news) + Documentation ------------- @@ -53,5 +60,6 @@ Documentation - [OPML file importation](docs/opml-import.markdown) - [OPML file exportation](docs/opml-export.markdown) - [Web scraping](docs/grabber.markdown) +- [Exceptions](docs/exceptions.markdown) - [Debugging](docs/debugging.markdown) - [Configuration](docs/config.markdown) diff --git a/vendor/fguillot/picofeed/docs/config.markdown b/vendor/fguillot/picofeed/docs/config.markdown index bf6fdee1f..5e0dfea53 100644 --- a/vendor/fguillot/picofeed/docs/config.markdown +++ b/vendor/fguillot/picofeed/docs/config.markdown @@ -8,8 +8,8 @@ To change the default parameters, you have to use the Config class. Create a new instance and pass it to the Reader object like that: ```php -use PicoFeed\Reader; -use PicoFeed\Config; +use PicoFeed\Reader\Reader; +use PicoFeed\Config\Config; $config = new Config; $config->setClientUserAgent('My custom RSS Reader') @@ -80,7 +80,7 @@ $config->setProxyHostname('proxy.example.org'); - Argument value: port number (integer) ```php -$config->getProxyPort(8118); +$config->setProxyPort(8118); ``` ### Proxy username @@ -132,7 +132,7 @@ Parser ### Hash algorithm used for item id generation - Method name: `setParserHashAlgo()` -- Default value: `crc32b` +- Default value: `sha256` - Argument value: any value returned by the function `hash_algos()` (string) - See: http://php.net/hash_algos @@ -147,7 +147,7 @@ $config->setParserHashAlgo('sha1'); - Argument value: boolean ```php -$config->setContentFiltering(); +$config->setContentFiltering(false); ``` ### Timezone diff --git a/vendor/fguillot/picofeed/docs/debugging.markdown b/vendor/fguillot/picofeed/docs/debugging.markdown index bbe1fd067..a9f8ab163 100644 --- a/vendor/fguillot/picofeed/docs/debugging.markdown +++ b/vendor/fguillot/picofeed/docs/debugging.markdown @@ -1,13 +1,18 @@ Debugging ========= -Get log messages ----------------- +Logging +------- PicoFeed log in memory the execution flow, if a feed doesn't work correctly it's easy to see what is wrong. +### Reading messages + ```php -print_r(PicoFeed\Logging::getMessages()); +use PicoFeed\Logging\Logger; + +// All messages are stored inside an Array +print_r(Logger::getMessages()); ``` You will got an output like that: @@ -36,11 +41,46 @@ Array ) ``` -Remove messages ---------------- +### Remove messages -All messages are stored in memory, if you need to clear them just call the method `Logging::deleteMessages()`: +All messages are stored in memory, if you need to clear them just call the method `Logger::deleteMessages()`: ```php -PicoFeed\Logging::deleteMessages(); +Logger::deleteMessages(); +``` + +Command line utility +==================== + +PicoFeed provides a basic command line tool to debug feeds quickly. +The tool is located in the root directory project. + +### Usage + +```bash +$ ./picofeed +Usage: +./picofeed feed <feed-url> # Parse a feed a dump the ouput on stdout +./picofeed debug <feed-url> # Display all logging messages for a feed +./picofeed item <feed-url> <item-id> # Fetch only one item +./picofeed nofilter <feed-url> <item-id> # Fetch an item but with no content filtering +``` + +### Example + +```bash +$ ./picofeed debug https://linuxfr.org/ +Exception thrown ===> "Invalid SSL certificate" +Array +( + [0] => [2014-11-08 14:04:14] PicoFeed\Client\Curl Fetch URL: https://linuxfr.org/ + [1] => [2014-11-08 14:04:14] PicoFeed\Client\Curl Etag provided: + [2] => [2014-11-08 14:04:14] PicoFeed\Client\Curl Last-Modified provided: + [3] => [2014-11-08 14:04:16] PicoFeed\Client\Curl cURL total time: 1.850634 + [4] => [2014-11-08 14:04:16] PicoFeed\Client\Curl cURL dns lookup time: 0.00093 + [5] => [2014-11-08 14:04:16] PicoFeed\Client\Curl cURL connect time: 0.115213 + [6] => [2014-11-08 14:04:16] PicoFeed\Client\Curl cURL speed download: 0 + [7] => [2014-11-08 14:04:16] PicoFeed\Client\Curl cURL effective url: https://linuxfr.org/ + [8] => [2014-11-08 14:04:16] PicoFeed\Client\Curl cURL error: SSL certificate problem: Invalid certificate chain +) ``` diff --git a/vendor/fguillot/picofeed/docs/exceptions.markdown b/vendor/fguillot/picofeed/docs/exceptions.markdown new file mode 100644 index 000000000..399ba3ef6 --- /dev/null +++ b/vendor/fguillot/picofeed/docs/exceptions.markdown @@ -0,0 +1,28 @@ +Exceptions +========== + +All exceptions inherits from the standard `Exception` class. + +### Library Exceptions + +- `PicoFeed\PicoFeedException`: Base class exception for the library + +### Client Exceptions + +- `PicoFeed\Client\ClientException`: Base exception class for the Client class +- `PicoFeed\Client\InvalidCertificateException`: Invalid SSL certificate +- `PicoFeed\Client\InvalidUrlException`: Malformed URL, page not found (404), unable to establish a connection +- `PicoFeed\Client\MaxRedirectException`: Maximum of HTTP redirections reached +- `PicoFeed\Client\MaxSizeException`: The response size exceeds to maximum allowed +- `PicoFeed\Client\TimeoutException`: Connection timeout + +### Parser Exceptions + +- `PicoFeed\Parser\ParserException`: Base exception class for the Parser class +- `PicoFeed\Parser\MalformedXmlException`: XML Parser error + +### Reader Exceptions + +- `PicoFeed\Reader\ReaderException`: Base exception class for the Reader +- `PicoFeed\Reader\SubscriptionNotFoundException`: Unable to find a feed for the given website +- `PicoFeed\Reader\UnsupportedFeedFormatException`: Unable to detect the feed format diff --git a/vendor/fguillot/picofeed/docs/favicon.markdown b/vendor/fguillot/picofeed/docs/favicon.markdown index 92ae11928..14e25955d 100644 --- a/vendor/fguillot/picofeed/docs/favicon.markdown +++ b/vendor/fguillot/picofeed/docs/favicon.markdown @@ -5,15 +5,13 @@ Find and download the favicon ----------------------------- ```php - -use PicoFeed\Favicon; +use PicoFeed\Client\Favicon; $favicon = new Favicon; // The icon link is https://bits.wikimedia.org/favicon/wikipedia.ico $icon_link = $favicon->find('https://en.wikipedia.org/'); $icon_content = $favicon->getContent(); - ``` PicoFeed will try first to find the favicon from the meta tags and fallback to the `favicon.ico` located in the website's root if nothing is found. @@ -27,14 +25,12 @@ Check if a favicon link exists ------------------------------ ```php - -use PicoFeed\Favicon; +use PicoFeed\Client\Favicon; $favicon = new Favicon; // Return true if the file exists var_dump($favicon->exists('http://php.net/favicon.ico')); - ``` Use personalized HTTP settings @@ -43,14 +39,12 @@ Use personalized HTTP settings Like other classes, the Favicon class support the Config object as constructor argument: ```php - -use PicoFeed\Config; -use PicoFeed\Favicon; +use PicoFeed\Config\Config; +use PicoFeed\Client\Favicon; $config = new Config; $config->setClientUserAgent('My RSS Reader'); $favicon = new Favicon($config); $favicon->find('https://github.com'); - ```
\ No newline at end of file diff --git a/vendor/fguillot/picofeed/docs/feed-creation.markdown b/vendor/fguillot/picofeed/docs/feed-creation.markdown index 24329f82c..35a24a9d7 100644 --- a/vendor/fguillot/picofeed/docs/feed-creation.markdown +++ b/vendor/fguillot/picofeed/docs/feed-creation.markdown @@ -1,11 +1,13 @@ Feed creation ============= +PicoFeed can also generate Atom and RSS feeds. + Generate RSS 2.0 feed ---------------------- ```php -use PicoFeed\Writers\Rss20; +use PicoFeed\Syndication\Rss20; $writer = new Rss20(); $writer->title = 'My site'; @@ -48,7 +50,7 @@ Generate Atom feed ------------------ ```php -use PicoFeed\Writers\Atom; +use PicoFeed\Syndication\Atom; $writer = new Atom(); $writer->title = 'My site'; diff --git a/vendor/fguillot/picofeed/docs/feed-parsing.markdown b/vendor/fguillot/picofeed/docs/feed-parsing.markdown index 22f84339b..df881400e 100644 --- a/vendor/fguillot/picofeed/docs/feed-parsing.markdown +++ b/vendor/fguillot/picofeed/docs/feed-parsing.markdown @@ -13,7 +13,7 @@ try { $reader = new Reader; // Return a resource - $resource = $reader->download('https://linuxfr.org/news.atom'); + $resource = $reader->download('http://linuxfr.org/news.atom'); // Return the right parser instance according to the feed format $parser = $reader->getParser( @@ -59,16 +59,6 @@ Item::author = Syvolc Item::enclosure_url = Item::enclosure_type = Item::content = 18307 bytes ----- -Item::id = d0ebddc90bfc3f109f9be00a3bb0b4a770af7a647cdc88454fe15d79168e0dea -Item::title = Fuzix OS, parce que les petites choses sont belles -Item::url = http://linuxfr.org/news/fuzix-os-parce-que-les-petites-choses-sont-belles -Item::date = 1415112167 -Item::language = en-US -Item::author = Thomas DEBESSE -Item::enclosure_url = -Item::enclosure_type = -Item::content = 6104 bytes .... ``` @@ -134,7 +124,54 @@ catch (PicoFeedException $e) { HTTP caching ------------ -TODO +PicoFeed supports HTTP caching to avoid unnecessary processing. + +1. After the first download, save in your database the values of the Etag and LastModified HTTP headers +2. For the next requests, provide those values to the `download()` method and check if the feed was modified or not + +Here an example: + +```php +try { + + // Fetch from your database the previous values of the Etag and LastModified headers + $etag = '...'; + $last_modified = '...'; + + $reader = new Reader; + + // Provide those values to the download method + $resource = $reader->download('http://linuxfr.org/news.atom', $last_modified, $etag); + + // Return true if the remote content has changed + if ($resource->isModified()) { + + $parser = $reader->getParser( + $resource->getUrl(), + $resource->getContent(), + $resource->getEncoding() + ); + + $feed = $parser->execute(); + + // Save your feed in your database + // ... + + // Store the Etag and the LastModified headers in your database for the next requests + $etag = $resource->getEtag(); + $last_modified = $resource->getLastModified(); + + // ... + } + else { + + echo 'Not modified, nothing to do!'; + } +} +catch (PicoFeedException $e) { + // Do something... +} +``` Feed and item properties @@ -162,3 +199,24 @@ $feed->items[0]->getEnclosureUrl(); // Enclosure url $feed->items[0]->getEnclosureType(); // Enclosure mime-type (audio/mp3, image/png...) $feed->items[0]->getContent(); // Item content (filtered or raw) ``` + +RTL language detection +---------------------- + +There is an utility method to determine if a language code is Right-To-Left or not: + +```php +// Return true if RTL +Parser::isLanguageRTL($item->getLanguage()); +``` + +Known RTL languages are: + +- Arabic (ar-**) +- Farsi (fa-**) +- Urdu (ur-**) +- Pashtu (ps-**) +- Syriac (syr-**) +- Divehi (dv-**) +- Hebrew (he-**) +- Yiddish (yi-**) diff --git a/vendor/fguillot/picofeed/docs/grabber.markdown b/vendor/fguillot/picofeed/docs/grabber.markdown index 6a7dd2ada..2098b25d0 100644 --- a/vendor/fguillot/picofeed/docs/grabber.markdown +++ b/vendor/fguillot/picofeed/docs/grabber.markdown @@ -6,33 +6,48 @@ The web scraper is useful for feeds that display only a summary of articles, the How the content grabber works? ------------------------------ -1. Try with rules first (xpath patterns) for the domain name (see `PicoFeed\Rules\`) +1. Try with rules first (XPath queries) for the domain name (see `PicoFeed\Rules\`) 2. Try to find the text content by using common attributes for class and id 3. Finally, if nothing is found, the feed content is displayed -**The best results are obtained with Xpath rules file.** +**The best results are obtained with XPath rules file.** How to use the content scraper? ------------------------------- +Before parsing all items, just call the method `$parser->enableContentGrabber()`: + ```php -use PicoFeed\Reader; +use PicoFeed\Reader\Reader; +use PicoFeed\PicoFeedException; + +try { -$reader = new Reader; -$reader->download('http://www.egscomics.com/rss.php'); + $reader = new Reader; -$parser = $reader->getParser(); + // Return a resource + $resource = $reader->download('http://www.egscomics.com/rss.php'); -if ($parser !== false) { + // Return the right parser instance according to the feed format + $parser = $reader->getParser( + $resource->getUrl(), + $resource->getContent(), + $resource->getEncoding() + ); - $parser->enableContentGrabber(); // <= Enable the content grabber + // Enable content grabber before parsing items + $parser->enableContentGrabber(); + + // Return a Feed object $feed = $parser->execute(); - // ... +} +catch (PicoFeedException $e) { + // Do Something... } ``` When the content scraper is enabled, everything will be slower. -For each item a new HTTP request is made and the HTML downloaded is parsed with XML/Xpath. +**For each item a new HTTP request is made** and the HTML downloaded is parsed with XML/XPath. Configuration ------------- |