From c63e0dbbc25e8560fd6bd7b2a020789641818b97 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Thu, 26 Sep 2013 00:17:26 +0200 Subject: move simple enhancer config into json file --- dependencyinjection/dicontainer.php | 88 ++++------------------ utility/articleenhancer/articleenhancer.php | 2 +- utility/articleenhancer/cadenhancer.php | 47 ------------ .../cyanideandhappinessenhancer.php | 48 ------------ utility/articleenhancer/enhancers.json | 40 ++++++++++ utility/articleenhancer/escapistcomicenhancer.php | 49 ------------ utility/articleenhancer/leasticoulddoenhancer.php | 45 ----------- utility/articleenhancer/pennyarcadeenhancer.php | 47 ------------ utility/articleenhancer/themerepublicenhancer.php | 21 ------ 9 files changed, 57 insertions(+), 330 deletions(-) delete mode 100644 utility/articleenhancer/cadenhancer.php delete mode 100644 utility/articleenhancer/cyanideandhappinessenhancer.php create mode 100644 utility/articleenhancer/enhancers.json delete mode 100644 utility/articleenhancer/escapistcomicenhancer.php delete mode 100644 utility/articleenhancer/leasticoulddoenhancer.php delete mode 100644 utility/articleenhancer/pennyarcadeenhancer.php delete mode 100644 utility/articleenhancer/themerepublicenhancer.php 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 823ddcc18..9567628d6 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 @@ -. - * - */ - -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 @@ -. -* -*/ - -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 @@ -. - * - */ - -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 @@ -. - * - */ - -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 @@ -. - * - */ - -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 @@ - "//*[@class='post hentry']" - ), - $timeout - ); - } -} -?> \ No newline at end of file -- cgit v1.2.3 From eff84feac3affa2180923b905ae0987033b041e9 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Thu, 26 Sep 2013 00:28:34 +0200 Subject: changelog --- CHANGELOG | 2 ++ 1 file changed, 2 insertions(+) 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 -- cgit v1.2.3