summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Posselt <Raydiation@users.noreply.github.com>2013-09-26 03:48:44 -0700
committerBernhard Posselt <Raydiation@users.noreply.github.com>2013-09-26 03:48:44 -0700
commitcec643c249fb97a940b197287474341bdc598977 (patch)
treecb699c00b622df3ce85db1994384d939806c3a07
parent7ea5a6b4881621f5a6ce43e18d6bc748bbeb7637 (diff)
parenteff84feac3affa2180923b905ae0987033b041e9 (diff)
Merge pull request #372 from owncloud/enhancer-json
move simple enhancer config into json file
-rw-r--r--CHANGELOG2
-rw-r--r--dependencyinjection/dicontainer.php88
-rw-r--r--utility/articleenhancer/articleenhancer.php2
-rw-r--r--utility/articleenhancer/cadenhancer.php47
-rw-r--r--utility/articleenhancer/cyanideandhappinessenhancer.php48
-rw-r--r--utility/articleenhancer/enhancers.json40
-rw-r--r--utility/articleenhancer/escapistcomicenhancer.php49
-rw-r--r--utility/articleenhancer/leasticoulddoenhancer.php45
-rw-r--r--utility/articleenhancer/pennyarcadeenhancer.php47
-rw-r--r--utility/articleenhancer/themerepublicenhancer.php21
10 files changed, 59 insertions, 330 deletions
diff --git a/CHANGELOG b/CHANGELOG
index b588c3e3e..0b1023681 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,6 +2,8 @@ owncloud-news (1.605)
* Adding feeds does not block the input box any more
* Always display empty folders
* Better description for hiding/showing read articles
+* More article enhancers
+* Make it easier to add simple article enhancers by moving the data into a JSON configuration file
owncloud-news (1.604)
* Use 64bit integers to prevent running out of ids after a year for large installations
diff --git a/dependencyinjection/dicontainer.php b/dependencyinjection/dicontainer.php
index 94806b2f7..9efc9669d 100644
--- a/dependencyinjection/dicontainer.php
+++ b/dependencyinjection/dicontainer.php
@@ -61,13 +61,8 @@ use \OCA\News\Utility\Updater;
use \OCA\News\Utility\SimplePieFileFactory;
use \OCA\News\Utility\ArticleEnhancer\Enhancer;
-use \OCA\News\Utility\ArticleEnhancer\CyanideAndHappinessEnhancer;
-use \OCA\News\Utility\ArticleEnhancer\ThemeRepublicEnhancer;
-use OCA\News\Utility\ArticleEnhancer\CADEnhancer;
-use OCA\News\Utility\ArticleEnhancer\PennyArcadeEnhancer;
+use \OCA\News\Utility\ArticleEnhancer\ArticleEnhancer;
use OCA\News\Utility\ArticleEnhancer\TwoGAGEnhancer;
-use OCA\News\Utility\ArticleEnhancer\LeastICouldDoEnhancer;
-use OCA\News\Utility\ArticleEnhancer\EscapistComicEnhancer;
use \OCA\News\Middleware\CORSMiddleware;
@@ -262,61 +257,27 @@ class DIContainer extends BaseContainer {
$this['Enhancer'] = $this->share(function($c){
$enhancer = new Enhancer();
- // register fetchers in order
- // the most generic enhancer should be the last one
- $enhancer->registerEnhancer('explosm.net', $c['CyanideAndHappinessEnhancer']);
- $enhancer->registerEnhancer('themerepublic.net', $c['ThemeRepublicEnhancer']);
- $enhancer->registerEnhancer('cad-comic.com', $c['CADEnhancer']);
- $enhancer->registerEnhancer('penny-arcade.com', $c['PennyArcadeEnhancer']);
+ // register enhancers which need special implementation
$enhancer->registerEnhancer('twogag.com', $c['TwoGAGEnhancer']);
- $enhancer->registerEnhancer('leasticoulddo.com', $c['LeastICouldDoEnhancer']);
- $enhancer->registerEnhancer('escapistmagazine.com/articles/view/comics/critical-miss', $c['EscapistComicEnhancer']);
- $enhancer->registerEnhancer('escapistmagazine.com/articles/view/comics/critical-miss', $c['EscapistComicEnhancer']);
- $enhancer->registerEnhancer('escapistmagazine.com/articles/view/comics/namegame', $c['EscapistComicEnhancer']);
- $enhancer->registerEnhancer('escapistmagazine.com/articles/view/comics/stolen-pixels', $c['EscapistComicEnhancer']);
- $enhancer->registerEnhancer('escapistmagazine.com/articles/view/comics/bumhugparade', $c['EscapistComicEnhancer']);
- $enhancer->registerEnhancer('escapistmagazine.com/articles/view/comics/escapistradiotheater', $c['EscapistComicEnhancer']);
- $enhancer->registerEnhancer('escapistmagazine.com/articles/view/comics/paused', $c['EscapistComicEnhancer']);
- $enhancer->registerEnhancer('escapistmagazine.com/articles/view/comics/fraughtwithperil', $c['EscapistComicEnhancer']);
-
- return $enhancer;
- });
-
- $this['DefaultEnhancer'] = $this->share(function($c){
- return new DefaultEnhancer();
- });
-
- $this['CyanideAndHappinessEnhancer'] = $this->share(function($c){
- return new CyanideAndHappinessEnhancer(
- $c['SimplePieFileFactory'],
- $c['HTMLPurifier'],
- $c['feedFetcherTimeout']
- );
- });
- $this['ThemeRepublicEnhancer'] = $this->share(function($c){
- return new ThemeRepublicEnhancer(
- $c['SimplePieFileFactory'],
- $c['HTMLPurifier'],
- $c['feedFetcherTimeout']
+ // register simple enhancers from config json file
+ $enhancerConfig = file_get_contents(
+ __DIR__ . '/../utility/articleenhancer/enhancers.json'
);
- });
+ //print_r( json_decode($enhancerConfig, true) );
+ foreach(json_decode($enhancerConfig, true) as $feed => $config) {
+ $articleEnhancer = new ArticleEnhancer(
+ $c['HTMLPurifier'],
+ $c['SimplePieFileFactory'],
+ $config,
+ $c['feedFetcherTimeout']
+ );
+ $enhancer->registerEnhancer($feed, $articleEnhancer);
+ }
- $this['CADEnhancer'] = $this->share(function($c){
- return new CADEnhancer(
- $c['SimplePieFileFactory'],
- $c['HTMLPurifier'],
- $c['feedFetcherTimeout']
- );
+ return $enhancer;
});
- $this['PennyArcadeEnhancer'] = $this->share(function($c){
- return new PennyArcadeEnhancer(
- $c['SimplePieFileFactory'],
- $c['HTMLPurifier'],
- $c['feedFetcherTimeout']
- );
- });
$this['TwoGAGEnhancer'] = $this->share(function($c){
return new TwoGAGEnhancer(
@@ -326,23 +287,6 @@ class DIContainer extends BaseContainer {
);
});
- $this['LeastICouldDoEnhancer'] = $this->share(function($c){
- return new LeastICouldDoEnhancer(
- $c['SimplePieFileFactory'],
- $c['HTMLPurifier'],
- $c['feedFetcherTimeout']
- );
- });
-
- $this['EscapistComicEnhancer'] = $this->share(function($c){
- return new EscapistComicEnhancer(
- $c['SimplePieFileFactory'],
- $c['HTMLPurifier'],
- $c['feedFetcherTimeout']
- );
- });
-
-
$this['Fetcher'] = $this->share(function($c){
$fetcher = new Fetcher();
diff --git a/utility/articleenhancer/articleenhancer.php b/utility/articleenhancer/articleenhancer.php
index 6450f638d..1790d2457 100644
--- a/utility/articleenhancer/articleenhancer.php
+++ b/utility/articleenhancer/articleenhancer.php
@@ -28,7 +28,7 @@ namespace OCA\News\Utility\ArticleEnhancer;
use \OCA\News\Utility\SimplePieFileFactory;
-abstract class ArticleEnhancer {
+class ArticleEnhancer {
private $feedRegex;
diff --git a/utility/articleenhancer/cadenhancer.php b/utility/articleenhancer/cadenhancer.php
deleted file mode 100644
index 9df7f5eaf..000000000
--- a/utility/articleenhancer/cadenhancer.php
+++ /dev/null
@@ -1,47 +0,0 @@
-<?php
-
-/**
- * ownCloud - News
- *
- * @author Alessandro Cosentino
- * @author Bernhard Posselt
- * @copyright 2012 Alessandro Cosentino cosenal@gmail.com
- * @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
- *
- * You should have received a copy of the GNU Affero General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-namespace OCA\News\Utility\ArticleEnhancer;
-
-use \OCA\News\Utility\SimplePieFileFactory;
-
-
-class CADEnhancer extends ArticleEnhancer {
-
-
- public function __construct(SimplePieFileFactory $fileFactory, $purifier,
- $timeout){
- parent::__construct(
- $purifier,
- $fileFactory,
- array(
- '/cad-comic.com\/cad\/\d+\/$/' => '//*[@id=\'content\']/img'
- ),
- $timeout
- );
- }
-
-
-}
diff --git a/utility/articleenhancer/cyanideandhappinessenhancer.php b/utility/articleenhancer/cyanideandhappinessenhancer.php
deleted file mode 100644
index aaa38e037..000000000
--- a/utility/articleenhancer/cyanideandhappinessenhancer.php
+++ /dev/null
@@ -1,48 +0,0 @@
-<?php
-
-/**
-* ownCloud - News
-*
-* @author Alessandro Cosentino
-* @author Bernhard Posselt
-* @copyright 2012 Alessandro Cosentino cosenal@gmail.com
-* @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com
-*
-* This library is free software; you can redistribute it and/or
-* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
-* License as published by the Free Software Foundation; either
-* version 3 of the License, or any later version.
-*
-* This library is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
-*
-* You should have received a copy of the GNU Affero General Public
-* License along with this library. If not, see <http://www.gnu.org/licenses/>.
-*
-*/
-
-namespace OCA\News\Utility\ArticleEnhancer;
-
-use \OCA\News\Utility\SimplePieFileFactory;
-
-
-class CyanideAndHappinessEnhancer extends ArticleEnhancer {
-
-
- public function __construct(SimplePieFileFactory $fileFactory, $purifier,
- $timeout){
- parent::__construct(
- $purifier,
- $fileFactory,
- array(
- '/explosm.net\/comics/' => '//*[@id=\'maincontent\']/div[2]/div/img',
- '/explosm.net\/show/' => '//*[@id=\'videoPlayer\']/iframe'
- ),
- $timeout
- );
- }
-
-
-} \ No newline at end of file
diff --git a/utility/articleenhancer/enhancers.json b/utility/articleenhancer/enhancers.json
new file mode 100644
index 000000000..cd30b4880
--- /dev/null
+++ b/utility/articleenhancer/enhancers.json
@@ -0,0 +1,40 @@
+{
+ "cad-comic.com": {
+ "%cad-comic.com/cad/\\d+/$%": "//*[@id='content']/img"
+ },
+ "explosm.net": {
+ "%explosm.net/comics%": "//*[@id='maincontent']/div[2]/div/img",
+ "%explosm.net/show%": "//*[@id='videoPlayer']/iframe"
+ },
+ "themerepublic.net": {
+ "%feedproxy.google.com/~r/blogspot/DngUJ%": "//*[@class='post hentry']"
+ },
+ "penny-arcade.com": {
+ "%feeds.penny-arcade.com/~r/pa-mainsite%": "//*[starts-with(@class, \"post\")]"
+ },
+ "leasticoulddo.com": {
+ "%feedproxy.google.com/~r/LICD%": "//*[@id='comic-img']/a/img | //*[@id='comic-img']/img"
+ },
+ "escapistmagazine.com/articles/view/comics/critical-miss": {
+ "%escapistmagazine.com/articles/view/comics/critical-miss%": "//*[@class='body']/span/img"
+ },
+ "escapistmagazine.com/articles/view/comics/namegame": {
+ "%escapistmagazine.com/articles/view/comics/namegame%": "//*[@class='body']/span/p/img[@height != \"120\"]"
+ },
+ "escapistmagazine.com/articles/view/comics/stolen-pixels": {
+ "%escapistmagazine.com/articles/view/comics/stolen-pixels%": "//*[@class='body']/span/p[2]/img"
+ },
+ "escapistmagazine.com/articles/view/comics/bumhugparade": {
+ "%escapistmagazine.com/articles/view/comics/bumhugparade%": "//*[@class='body']/span/p[2]/img"
+ },
+ "escapistmagazine.com/articles/view/comics/escapistradiotheater": {
+ "%escapistmagazine.com/articles/view/comics/escapistradiotheater%": "//*[@class='body']/span/p[2]/img"
+ },
+ "escapistmagazine.com/articles/view/comics/paused": {
+ "%escapistmagazine.com/articles/view/comics/paused%": "//*[@class='body']/span/p[2]/img | //*[@class='body']/span/div/img"
+ },
+ "escapistmagazine.com/articles/view/comics/fraughtwithperil": {
+ "%escapistmagazine.com/articles/view/comics/fraughtwithperil%": "//*[@class='body']"
+ }
+}
+
diff --git a/utility/articleenhancer/escapistcomicenhancer.php b/utility/articleenhancer/escapistcomicenhancer.php
deleted file mode 100644
index a2238ed29..000000000
--- a/utility/articleenhancer/escapistcomicenhancer.php
+++ /dev/null
@@ -1,49 +0,0 @@
-<?php
-
-/**
- * ownCloud - News
- *
- * @author Alessandro Cosentino
- * @author Bernhard Posselt
- * @copyright 2012 Alessandro Cosentino cosenal@gmail.com
- * @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
- *
- * You should have received a copy of the GNU Affero General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-namespace OCA\News\Utility\ArticleEnhancer;
-
-use \OCA\News\Utility\SimplePieFileFactory;
-
-
-class EscapistComicEnhancer extends ArticleEnhancer {
-
-
- public function __construct(SimplePieFileFactory $fileFactory, $purifier,
- $timeout) {
- parent::__construct(
- $purifier,
- $fileFactory,
- array(
- '/escapistmagazine.com\/articles\/view\/comics\/critical-miss/' => '//*[@class=\'body\']/span/img',
- '/escapistmagazine.com\/articles\/view\/comics\/namegame/' => '//*[@class=\'body\']/span/p/img[@height != "120"]',
- '/escapistmagazine.com\/articles\/view\/comics\/(stolen-pixels|bumhugparade|escapistradiotheater)/' => '//*[@class=\'body\']/span/p[2]/img',
- '/escapistmagazine.com\/articles\/view\/comics\/paused/' => '//*[@class=\'body\']/span/p[2]/img | //*[@class=\'body\']/span/div/img',
- '/escapistmagazine.com\/articles\/view\/comics\/fraughtwithperil/' => '//*[@class=\'body\']',
- ),
- $timeout
- );
- }
-}
diff --git a/utility/articleenhancer/leasticoulddoenhancer.php b/utility/articleenhancer/leasticoulddoenhancer.php
deleted file mode 100644
index 4ba3f244c..000000000
--- a/utility/articleenhancer/leasticoulddoenhancer.php
+++ /dev/null
@@ -1,45 +0,0 @@
-<?php
-
-/**
- * ownCloud - News
- *
- * @author Alessandro Cosentino
- * @author Bernhard Posselt
- * @copyright 2012 Alessandro Cosentino cosenal@gmail.com
- * @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
- *
- * You should have received a copy of the GNU Affero General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-namespace OCA\News\Utility\ArticleEnhancer;
-
-use \OCA\News\Utility\SimplePieFileFactory;
-
-
-class LeastICouldDoEnhancer extends ArticleEnhancer {
-
-
- public function __construct(SimplePieFileFactory $fileFactory, $purifier,
- $timeout) {
- parent::__construct(
- $purifier,
- $fileFactory,
- array(
- '/feedproxy.google.com\/\~r\/LICD/' => '//*[@id=\'comic-img\']/a/img | //*[@id=\'comic-img\']/img'
- ),
- $timeout
- );
- }
-}
diff --git a/utility/articleenhancer/pennyarcadeenhancer.php b/utility/articleenhancer/pennyarcadeenhancer.php
deleted file mode 100644
index 3d2b1fd95..000000000
--- a/utility/articleenhancer/pennyarcadeenhancer.php
+++ /dev/null
@@ -1,47 +0,0 @@
-<?php
-
-/**
- * ownCloud - News
- *
- * @author Alessandro Cosentino
- * @author Bernhard Posselt
- * @copyright 2012 Alessandro Cosentino cosenal@gmail.com
- * @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
- *
- * You should have received a copy of the GNU Affero General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-namespace OCA\News\Utility\ArticleEnhancer;
-
-use \OCA\News\Utility\SimplePieFileFactory;
-
-
-class PennyArcadeEnhancer extends ArticleEnhancer {
-
-
- public function __construct(SimplePieFileFactory $fileFactory, $purifier,
- $timeout){
- parent::__construct(
- $purifier,
- $fileFactory,
- array(
- '/feeds.penny-arcade.com\/\~r\/pa-mainsite/' => '//*[starts-with(@class, "post")]'
- ),
- $timeout
- );
- }
-
-
-}
diff --git a/utility/articleenhancer/themerepublicenhancer.php b/utility/articleenhancer/themerepublicenhancer.php
deleted file mode 100644
index c13ff6027..000000000
--- a/utility/articleenhancer/themerepublicenhancer.php
+++ /dev/null
@@ -1,21 +0,0 @@
-<?php
-
-namespace OCA\News\Utility\ArticleEnhancer;
-
-use \OCA\News\Utility\SimplePieFileFactory;
-
-class ThemeRepublicEnhancer extends ArticleEnhancer {
-
- public function __construct(SimplePieFileFactory $fileFactory, $purifier,
- $timeout){
- parent::__construct(
- $purifier,
- $fileFactory,
- array(
- '/feedproxy.google.com\/~r\/blogspot\/DngUJ/' => "//*[@class='post hentry']"
- ),
- $timeout
- );
- }
-}
-?> \ No newline at end of file