diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..15154f0d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +.git +cache/* +DEBUG +Dockerfile +whitelist.txt +phpcs.xml +CHANGELOG.md +CONTRIBUTING.md \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index cd5e2d9a..5c746a4d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,12 +3,26 @@ sudo: false language: php install: - - pear channel-update pear.php.net - - pear install PHP_CodeSniffer + - if [[ $TRAVIS_PHP_VERSION == "hhvm" ]]; then + composer global require squizlabs/PHP_CodeSniffer; + else + pear channel-update pear.php.net; + pear install PHP_CodeSniffer; + fi + - if [[ $TRAVIS_PHP_VERSION == "7.0" ]]; then + composer global require phpunit/phpunit ^6; + fi script: - phpenv rehash - - phpcs . --standard=phpcs.xml --warning-severity=0 --extensions=php -p + - if [[ $TRAVIS_PHP_VERSION == "hhvm" ]]; then + /home/travis/.composer/vendor/bin/phpcs . --standard=phpcs.xml --warning-severity=0 --extensions=php -p; + else + phpcs . --standard=phpcs.xml --warning-severity=0 --extensions=php -p; + fi + - if [[ $TRAVIS_PHP_VERSION == "7.0" ]]; then + phpunit --configuration=phpunit.xml --include-path=lib/; + fi matrix: fast_finish: true diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..35caac84 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ +FROM ulsmith/alpine-apache-php7 + +COPY ./ /app/public/ + +RUN chown -R apache:root /app/public \ No newline at end of file diff --git a/README.md b/README.md index 45bbc6d9..1fcf6023 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ rss-bridge === -[![LICENSE](https://img.shields.io/badge/license-UNLICENSE-blue.svg)](UNLICENSE) [![Build Status](https://travis-ci.org/RSS-Bridge/rss-bridge.svg?branch=master)](https://travis-ci.org/RSS-Bridge/rss-bridge) +[![LICENSE](https://img.shields.io/badge/license-UNLICENSE-blue.svg)](UNLICENSE) [![GitHub release](https://img.shields.io/github/release/rss-bridge/rss-bridge.svg)](https://github.com/rss-bridge/rss-bridge/releases/latest) [![Debian Release](https://img.shields.io/badge/dynamic/json.svg?label=debian%20release&url=https%3A%2F%2Fsources.debian.org%2Fapi%2Fsrc%2Frss-bridge%2F&query=%24.versions%5B0%5D.version&colorB=blue)](https://tracker.debian.org/pkg/rss-bridge) [![Guix Release](https://img.shields.io/badge/guix%20release-unknown-light--gray.svg)](https://www.gnu.org/software/guix/packages/R/) [![Build Status](https://travis-ci.org/RSS-Bridge/rss-bridge.svg?branch=master)](https://travis-ci.org/RSS-Bridge/rss-bridge) [![Docker Build Status](https://img.shields.io/docker/build/rssbridge/rss-bridge.svg)](https://hub.docker.com/r/rssbridge/rss-bridge/) -rss-bridge is a PHP project capable of generating ATOM feeds for websites which don't have one. +RSS-Bridge is a PHP project capable of generating RSS and Atom feeds for websites which don't have one. It can be used on webservers or as stand alone application in CLI mode. -Supported sites/pages (main) +Supported sites/pages (examples) === * `Bandcamp` : Returns last release from [bandcamp](https://bandcamp.com/) for a tag @@ -25,106 +25,188 @@ Supported sites/pages (main) * `Wikipedia`: highlighted articles from [Wikipedia](https://wikipedia.org/) in English, German, French or Esperanto * `YouTube` : YouTube user channel, playlist or search -Plus [many other bridges](bridges/) to enable, thanks to the community +And [many more](bridges/), thanks to the community! Output format === -Output format can take several forms: -* `Atom` : ATOM Feed, for use in RSS/Feed readers -* `Html` : Simple html page. -* `Json` : Json, for consumption by other applications. -* `Mrss` : MRSS Feed, for use in RSS/Feed readers -* `Plaintext` : raw text (php object, as returned by print_r) - +RSS-Bridge is capable of producing several output formats: + +* `Atom` : Atom feed, for use in feed readers +* `Html` : Simple HTML page +* `Json` : JSON, for consumption by other applications +* `Mrss` : MRSS feed, for use in feed readers +* `Plaintext` : Raw text, for consumption by other applications + +You can extend RSS-Bridge with your own format, using the [Format API](https://github.com/RSS-Bridge/rss-bridge/wiki/Format-API)! + Screenshot === Welcome screen: ![Screenshot](https://github.com/RSS-Bridge/rss-bridge/wiki/images/screenshot_rss-bridge_welcome.png) - -RSS-Bridge hashtag (#rss-bridge) search on Twitter, in ATOM format (as displayed by Firefox): + +*** + +RSS-Bridge hashtag (#rss-bridge) search on Twitter, in Atom format (as displayed by Firefox): ![Screenshot](https://github.com/RSS-Bridge/rss-bridge/wiki/images/screenshot_twitterbridge_atom.png) - + Requirements === - * PHP 5.6, e.g. `AddHandler application/x-httpd-php56 .php` in `.htaccess` - * `openssl` extension enabled in PHP config (`php.ini`) - * `allow_url_fopen=1` in `php.ini` +RSS-Bridge requires PHP 5.6 or higher with following extensions enabled: -Enabling/Disabling bridges + - [`openssl`](https://secure.php.net/manual/en/book.openssl.php) + - [`libxml`](https://secure.php.net/manual/en/book.libxml.php) + - [`mbstring`](https://secure.php.net/manual/en/book.mbstring.php) + - [`simplexml`](https://secure.php.net/manual/en/book.simplexml.php) + - [`curl`](https://secure.php.net/manual/en/book.curl.php) + - [`json`](https://secure.php.net/manual/en/book.json.php) + +Find more information on our [Wiki](https://github.com/rss-bridge/rss-bridge/wiki) + +Enable / Disable bridges === -By default, the script creates `whitelist.txt` and adds the main bridges (see above). `whitelist.txt` is ignored by git, you can edit it: - * to enable extra bridges (one bridge per line) - * to disable main bridges (remove the line) - * to enable all bridges (just one wildcard `*` as file content) +RSS-Bridge allows you to take full control over which bridges are displayed to the user. That way you can host your own RSS-Bridge service with your favorite collection of bridges! -New bridges are disabled by default, so make sure to check regularly what's new and whitelist what you want! +Find more information on the [Wiki](https://github.com/RSS-Bridge/rss-bridge/wiki/Whitelisting) + +**Notice**: By default RSS-Bridge will only show a small subset of bridges. Make sure to read up on [whitelisting](https://github.com/RSS-Bridge/rss-bridge/wiki/Whitelisting) to unlock the full potential of RSS-Bridge! Deploy === + +Thanks to the community, hosting your own instance of RSS-Bridge is as easy as clicking a button! + [![Deploy on Scalingo](https://cdn.scalingo.com/deploy/button.svg)](https://my.scalingo.com/deploy?source=https://github.com/sebsauvage/rss-bridge) - +[![Deploy to Docker Cloud](https://files.cloud.docker.com/images/deploy-to-dockercloud.svg)](https://cloud.docker.com/stack/deploy/?repo=https://github.com/rss-bridge/rss-bridge) + +Getting involved +=== + +There are many ways for you to getting involved with RSS-Bridge. Here are a few things: + +- Share RSS-Bridge with your friends (Twitter, Facebook, ..._you name it_...) +- Report broken bridges or bugs by opening [Issues](https://github.com/RSS-Bridge/rss-bridge/issues) on GitHub +- Request new features or suggest ideas (via [Issues](https://github.com/RSS-Bridge/rss-bridge/issues)) +- Discuss bugs, features, ideas or [issues](https://github.com/RSS-Bridge/rss-bridge/issues) +- Add new bridges or improve the API +- Improve the [Wiki](https://github.com/RSS-Bridge/rss-bridge/wiki) +- Host an instance of RSS-Bridge for your personal use or make it available to the community :sparkling_heart: + Authors === -We are RSS Bridge Community, a group of developers continuing the project initiated by sebsauvage, webmaster of [sebsauvage.net](http://sebsauvage.net), author of [Shaarli](http://sebsauvage.net/wiki/doku.php?id=php:shaarli) and [ZeroBin](http://sebsauvage.net/wiki/doku.php?id=php:zerobin). -Patch/contributors : +We are RSS-Bridge community, a group of developers continuing the project initiated by sebsauvage, webmaster of [sebsauvage.net](http://sebsauvage.net), author of [Shaarli](http://sebsauvage.net/wiki/doku.php?id=php:shaarli) and [ZeroBin](http://sebsauvage.net/wiki/doku.php?id=php:zerobin). - * Yves ASTIER ([Draeli](https://github.com/Draeli)) : PHP optimizations, fixes, dynamic brigde/format list with all stuff behind and extend cache system. Mail : contact /at\ yves-astier.com - * [Mitsukarenai](https://github.com/Mitsukarenai) : Initial inspiration, collaborator - * [ArthurHoaro](https://github.com/ArthurHoaro) - * [BoboTiG](https://github.com/BoboTiG) - * [Astalaseven](https://github.com/Astalaseven) - * [qwertygc](https://github.com/qwertygc) - * [Djuuu](https://github.com/Djuuu) - * [Anadrark](https://github.com/Anadrark]) - * [Grummfy](https://github.com/Grummfy) - * [Polopollo](https://github.com/Polopollo) - * [16mhz](https://github.com/16mhz) - * [kranack](https://github.com/kranack) - * [logmanoriginal](https://github.com/logmanoriginal) - * [polo2ro](https://github.com/polo2ro) - * [Riduidel](https://github.com/Riduidel) - * [superbaillot.net](http://superbaillot.net/) - * [vinzv](https://github.com/vinzv) - * [teromene](https://github.com/teromene) - * [nel50n](https://github.com/nel50n) - * [nyutag](https://github.com/nyutag) - * [ORelio](https://github.com/ORelio) - * [Pitchoule](https://github.com/Pitchoule) - * [pit-fgfjiudghdf](https://github.com/pit-fgfjiudghdf) - * [aledeg](https://github.com/aledeg) - * [alexAubin](https://github.com/alexAubin) - * [cnlpete](https://github.com/cnlpete) - * [corenting](https://github.com/corenting) - * [Daiyousei](https://github.com/Daiyousei) - * [erwang](https://github.com/erwang) - * [gsurrel](https://github.com/gsurrel) - * [kraoc](https://github.com/kraoc) - * [lagaisse](https://github.com/lagaisse) - * [az5he6ch](https://github.com/az5he6ch) - * [niawag](https://github.com/niawag) - * [JeremyRand](https://github.com/JeremyRand) - * [mro](https://github.com/mro) +**Contributors** (sorted alphabetically): + + + * [16mhz](https://api.github.com/users/16mhz) + * [Ahiles3005](https://api.github.com/users/Ahiles3005) + * [Albirew](https://api.github.com/users/Albirew) + * [AmauryCarrade](https://api.github.com/users/AmauryCarrade) + * [ArthurHoaro](https://api.github.com/users/ArthurHoaro) + * [Astalaseven](https://api.github.com/users/Astalaseven) + * [Astyan-42](https://api.github.com/users/Astyan-42) + * [Daiyousei](https://api.github.com/users/Daiyousei) + * [Djuuu](https://api.github.com/users/Djuuu) + * [Draeli](https://api.github.com/users/Draeli) + * [EtienneM](https://api.github.com/users/EtienneM) + * [Frenzie](https://api.github.com/users/Frenzie) + * [Ginko-Aloe](https://api.github.com/users/Ginko-Aloe) + * [Glandos](https://api.github.com/users/Glandos) + * [GregThib](https://api.github.com/users/GregThib) + * [Grummfy](https://api.github.com/users/Grummfy) + * [JackNUMBER](https://api.github.com/users/JackNUMBER) + * [JeremyRand](https://api.github.com/users/JeremyRand) + * [Jocker666z](https://api.github.com/users/Jocker666z) + * [LogMANOriginal](https://api.github.com/users/LogMANOriginal) + * [MonsieurPoutounours](https://api.github.com/users/MonsieurPoutounours) + * [ORelio](https://api.github.com/users/ORelio) + * [PaulVayssiere](https://api.github.com/users/PaulVayssiere) + * [Piranhaplant](https://api.github.com/users/Piranhaplant) + * [Riduidel](https://api.github.com/users/Riduidel) + * [Strubbl](https://api.github.com/users/Strubbl) + * [TheRadialActive](https://api.github.com/users/TheRadialActive) + * [TwizzyDizzy](https://api.github.com/users/TwizzyDizzy) + * [WalterBarrett](https://api.github.com/users/WalterBarrett) + * [ZeNairolf](https://api.github.com/users/ZeNairolf) + * [adamchainz](https://api.github.com/users/adamchainz) + * [aledeg](https://api.github.com/users/aledeg) + * [alexAubin](https://api.github.com/users/alexAubin) + * [az5he6ch](https://api.github.com/users/az5he6ch) + * [b1nj](https://api.github.com/users/b1nj) + * [benasse](https://api.github.com/users/benasse) + * [captn3m0](https://api.github.com/users/captn3m0) + * [chemel](https://api.github.com/users/chemel) + * [ckiw](https://api.github.com/users/ckiw) + * [cnlpete](https://api.github.com/users/cnlpete) + * [corenting](https://api.github.com/users/corenting) + * [da2x](https://api.github.com/users/da2x) + * [eMerzh](https://api.github.com/users/eMerzh) + * [em92](https://api.github.com/users/em92) + * [griffaurel](https://api.github.com/users/griffaurel) + * [hunhejj](https://api.github.com/users/hunhejj) + * [j0k3r](https://api.github.com/users/j0k3r) + * [jdigilio](https://api.github.com/users/jdigilio) + * [kranack](https://api.github.com/users/kranack) + * [kraoc](https://api.github.com/users/kraoc) + * [laBecasse](https://api.github.com/users/laBecasse) + * [lagaisse](https://api.github.com/users/lagaisse) + * [lalannev](https://api.github.com/users/lalannev) + * [ldidry](https://api.github.com/users/ldidry) + * [m0zes](https://api.github.com/users/m0zes) + * [matthewseal](https://api.github.com/users/matthewseal) + * [mcbyte-it](https://api.github.com/users/mcbyte-it) + * [mdemoss](https://api.github.com/users/mdemoss) + * [melangue](https://api.github.com/users/melangue) + * [metaMMA](https://api.github.com/users/metaMMA) + * [mickael-bertrand](https://api.github.com/users/mickael-bertrand) + * [mitsukarenai](https://api.github.com/users/mitsukarenai) + * [mro](https://api.github.com/users/mro) + * [mxmehl](https://api.github.com/users/mxmehl) + * [nel50n](https://api.github.com/users/nel50n) + * [niawag](https://api.github.com/users/niawag) + * [pellaeon](https://api.github.com/users/pellaeon) + * [pit-fgfjiudghdf](https://api.github.com/users/pit-fgfjiudghdf) + * [pitchoule](https://api.github.com/users/pitchoule) + * [pmaziere](https://api.github.com/users/pmaziere) + * [prysme01](https://api.github.com/users/prysme01) + * [quentinus95](https://api.github.com/users/quentinus95) + * [qwertygc](https://api.github.com/users/qwertygc) + * [regisenguehard](https://api.github.com/users/regisenguehard) + * [rogerdc](https://api.github.com/users/rogerdc) + * [sebsauvage](https://api.github.com/users/sebsauvage) + * [sublimz](https://api.github.com/users/sublimz) + * [sysadminstory](https://api.github.com/users/sysadminstory) + * [tameroski](https://api.github.com/users/tameroski) + * [teromene](https://api.github.com/users/teromene) + * [triatic](https://api.github.com/users/triatic) + * [wtuuju](https://api.github.com/users/wtuuju) Licenses === -Code is [Public Domain](UNLICENSE). -Including `PHP Simple HTML DOM Parser` under the [MIT License](http://opensource.org/licenses/MIT) +The source code for RSS-Bridge is [Public Domain](UNLICENSE). +RSS-Bridge uses third party libraries with their own license: + + * [`PHP Simple HTML DOM Parser`](http://simplehtmldom.sourceforge.net/) licensed under the [MIT License](http://opensource.org/licenses/MIT) + * [`php-urljoin`](https://github.com/fluffy-critter/php-urljoin) licensed under the [MIT License](http://opensource.org/licenses/MIT) Technical notes === - * There is a cache so that source services won't ban you even if you hammer the rss-bridge with requests. Each bridge can have a different duration for the cache. The `cache` subdirectory will be automatically created and cached objects older than 24 hours get purged. - * To implement a new Bridge, [follow the specifications](https://github.com/RSS-Bridge/rss-bridge/wiki/Bridge-API) and take a look at existing Bridges for examples. - * To enable debug mode (disabling cache and enabling error reporting), create an empty file named `DEBUG` in the root directory (next to `index.php`). - * For more information refer to the [Wiki](https://github.com/RSS-Bridge/rss-bridge/wiki) + + * RSS-Bridge uses caching to prevent services from banning your server for repeatedly updating feeds. The specific cache duration can be different between bridges. Cached files are deleted automatically after 24 hours. + * You can implement your own bridge, [following these instructions](https://github.com/RSS-Bridge/rss-bridge/wiki/Bridge-API). + * You can enable debug mode to disable caching. Find more information on the [Wiki](https://github.com/RSS-Bridge/rss-bridge/wiki/Debug-mode) Rant === @@ -133,10 +215,10 @@ Rant Your catchword is "share", but you don't want us to share. You want to keep us within your walled gardens. That's why you've been removing RSS links from webpages, hiding them deep on your website, or removed feeds entirely, replacing it with crippled or demented proprietary API. **FUCK YOU.** -You're not social when you hamper sharing by removing feeds. You're happy to have customers creating content for your ecosystem, but you don't want this content out - a content you do not even own. Google Takeout is just a gimmick. We want our data to flow, we want RSS or ATOM feeds. +You're not social when you hamper sharing by removing feeds. You're happy to have customers creating content for your ecosystem, but you don't want this content out - a content you do not even own. Google Takeout is just a gimmick. We want our data to flow, we want RSS or Atom feeds. -We want to share with friends, using open protocols: RSS, ATOM, XMPP, whatever. Because no one wants to have *your* service with *your* applications using *your* API force-feeding them. Friends must be free to choose whatever software and service they want. +We want to share with friends, using open protocols: RSS, Atom, XMPP, whatever. Because no one wants to have *your* service with *your* applications using *your* API force-feeding them. Friends must be free to choose whatever software and service they want. We are rebuilding bridges you have wilfully destroyed. -Get your shit together: Put RSS/ATOM back in. +Get your shit together: Put RSS/Atom back in. diff --git a/bridges/AmazonPriceTrackerBridge.php b/bridges/AmazonPriceTrackerBridge.php new file mode 100644 index 00000000..e31a03bb --- /dev/null +++ b/bridges/AmazonPriceTrackerBridge.php @@ -0,0 +1,187 @@ + array( + 'name' => 'ASIN', + 'required' => true, + 'exampleValue' => 'B071GB1VMQ', + // https://stackoverflow.com/a/12827734 + 'pattern' => 'B[\dA-Z]{9}|\d{9}(X|\d)', + ), + 'tld' => array( + 'name' => 'Country', + 'type' => 'list', + 'required' => true, + 'values' => array( + 'Australia' => 'com.au', + 'Brazil' => 'com.br', + 'Canada' => 'ca', + 'China' => 'cn', + 'France' => 'fr', + 'Germany' => 'de', + 'India' => 'in', + 'Italy' => 'it', + 'Japan' => 'co.jp', + 'Mexico' => 'com.mx', + 'Netherlands' => 'nl', + 'Spain' => 'es', + 'United Kingdom' => 'co.uk', + 'United States' => 'com', + ), + 'defaultValue' => 'com', + ), + )); + + protected $title; + + /** + * Generates domain name given a amazon TLD + */ + private function getDomainName() { + return 'https://www.amazon.' . $this->getInput('tld'); + } + + /** + * Generates URI for a Amazon product page + */ + public function getURI() { + if (!is_null($this->getInput('asin'))) { + return $this->getDomainName() . '/dp/' . $this->getInput('asin') . '/'; + } + return parent::getURI(); + } + + /** + * Scrapes the product title from the html page + * returns the default title if scraping fails + */ + private function getTitle($html) { + $titleTag = $html->find('#productTitle', 0); + + if (!$titleTag) { + return $this->getDefaultTitle(); + } else { + return trim(html_entity_decode($titleTag->innertext, ENT_QUOTES)); + } + } + + /** + * Title used by the feed if none could be found + */ + private function getDefaultTitle() { + return 'Amazon.' . $this->getInput('tld') . ': ' . $this->getInput('asin'); + } + + /** + * Returns name for the feed + * Uses title (already scraped) if it has one + */ + public function getName() { + if (isset($this->title)) { + return $this->title; + } else { + return parent::getName(); + } + } + + private function parseDynamicImage($attribute) { + $json = json_decode(html_entity_decode($attribute), true); + + if ($json and count($json) > 0) { + return array_keys($json)[0]; + } + } + + /** + * Returns a generated image tag for the product + */ + private function getImage($html) { + $imageSrc = $html->find('#main-image-container img', 0); + + if ($imageSrc) { + $hiresImage = $imageSrc->getAttribute('data-old-hires'); + $dynamicImageAttribute = $imageSrc->getAttribute('data-a-dynamic-image'); + $image = $hiresImage ?: $this->parseDynamicImage($dynamicImageAttribute); + } + $image = $image ?: 'https://placekitten.com/200/300'; + + return << +EOT; + } + + /** + * Return \simple_html_dom object + * for the entire html of the product page + */ + private function getHtml() { + $uri = $this->getURI(); + + return getSimpleHTMLDOM($uri) ?: returnServerError('Could not request Amazon.'); + } + + private function scrapePriceFromMetrics($html) { + $asinData = $html->find('#cerberus-data-metrics', 0); + + //