From 86a6f68af42e111544f191ab9c9e410484d8ecb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Mon, 29 Aug 2016 00:56:31 +0200 Subject: [PATCH] [HDWallpapersBridge] code simplification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Mazière --- bridges/HDWallpapersBridge.php | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/bridges/HDWallpapersBridge.php b/bridges/HDWallpapersBridge.php index 8133c6e8..fde1aaab 100644 --- a/bridges/HDWallpapersBridge.php +++ b/bridges/HDWallpapersBridge.php @@ -1,31 +1,24 @@ array('name'=>'category'), + 'c'=>array( + 'name'=>'category', + 'defaultValue'=>'latest_wallpapers' + ), 'm'=>array('name'=>'max number of wallpapers'), 'r'=>array( 'name'=>'resolution', + 'defaultValue'=>'1920x1200', 'exampleValue'=>'1920x1200, 1680x1050,…' ) )); public function collectData(){ - $html = ''; - $baseUri = 'http://www.hdwallpapers.in'; - - $this->category = $this->getInput('c') ?: 'latest_wallpapers'; // Latest default - $this->resolution = $this->getInput('r') ?: '1920x1200'; // Wide wallpaper default - $category = $this->category; if (strrpos($category, 'wallpapers') !== strlen($category)-strlen('wallpapers')) { $category .= '-desktop-wallpapers'; @@ -36,7 +29,7 @@ class HDWallpapersBridge extends BridgeAbstract { $lastpage = 1; for ($page = 1; $page <= $lastpage; $page++) { - $link = $baseUri.'/'.$category.'/page/'.$page; + $link = $this->uri.'/'.$category.'/page/'.$page; $html = $this->getSimpleHTMLDOM($link) or $this->returnServerError('No results for this query.'); if ($page === 1) { @@ -49,10 +42,10 @@ class HDWallpapersBridge extends BridgeAbstract { $item = array(); // http://www.hdwallpapers.in/download/yosemite_reflections-1680x1050.jpg - $item['uri'] = $baseUri.'/download'.str_replace('wallpapers.html', $this->resolution.'.jpg', $element->href); + $item['uri'] = $this->uri.'/download'.str_replace('wallpapers.html', $this->getInput('r').'.jpg', $element->href); $item['timestamp'] = time(); $item['title'] = $element->find('p', 0)->text(); - $item['content'] = $item['title'].'
'; + $item['content'] = $item['title'].'
'; $this->items[] = $item; $num++; @@ -63,7 +56,7 @@ class HDWallpapersBridge extends BridgeAbstract { } public function getName(){ - return 'HDWallpapers - '.str_replace(['__', '_'], [' & ', ' '], $this->category).' ['.$this->resolution.']'; + return 'HDWallpapers - '.str_replace(['__', '_'], [' & ', ' '], $this->getInput('c')).' ['.$this->getInput('r').']'; } public function getCacheDuration(){