[HDWallpapersBridge] code simplification

Signed-off-by: Pierre Mazière <pierre.maziere@gmx.com>
This commit is contained in:
Pierre Mazière 2016-08-29 00:56:31 +02:00
parent 37d2e75d7d
commit 86a6f68af4

View file

@ -1,31 +1,24 @@
<?php <?php
class HDWallpapersBridge extends BridgeAbstract { class HDWallpapersBridge extends BridgeAbstract {
private $category;
private $resolution;
public $maintainer = "nel50n"; public $maintainer = "nel50n";
public $name = "HD Wallpapers Bridge"; public $name = "HD Wallpapers Bridge";
public $uri = "http://www.hdwallpapers.in/"; public $uri = "http://www.hdwallpapers.in/";
public $description = "Returns the latests wallpapers from HDWallpapers"; public $description = "Returns the latests wallpapers from HDWallpapers";
public $parameters = array( array( public $parameters = array( array(
'c'=>array('name'=>'category'), 'c'=>array(
'name'=>'category',
'defaultValue'=>'latest_wallpapers'
),
'm'=>array('name'=>'max number of wallpapers'), 'm'=>array('name'=>'max number of wallpapers'),
'r'=>array( 'r'=>array(
'name'=>'resolution', 'name'=>'resolution',
'defaultValue'=>'1920x1200',
'exampleValue'=>'1920x1200, 1680x1050,…' 'exampleValue'=>'1920x1200, 1680x1050,…'
) )
)); ));
public function collectData(){ 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; $category = $this->category;
if (strrpos($category, 'wallpapers') !== strlen($category)-strlen('wallpapers')) { if (strrpos($category, 'wallpapers') !== strlen($category)-strlen('wallpapers')) {
$category .= '-desktop-wallpapers'; $category .= '-desktop-wallpapers';
@ -36,7 +29,7 @@ class HDWallpapersBridge extends BridgeAbstract {
$lastpage = 1; $lastpage = 1;
for ($page = 1; $page <= $lastpage; $page++) { 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.'); $html = $this->getSimpleHTMLDOM($link) or $this->returnServerError('No results for this query.');
if ($page === 1) { if ($page === 1) {
@ -49,10 +42,10 @@ class HDWallpapersBridge extends BridgeAbstract {
$item = array(); $item = array();
// http://www.hdwallpapers.in/download/yosemite_reflections-1680x1050.jpg // 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['timestamp'] = time();
$item['title'] = $element->find('p', 0)->text(); $item['title'] = $element->find('p', 0)->text();
$item['content'] = $item['title'].'<br><a href="'.$item['uri'].'"><img src="'.$baseUri.$thumbnail->src.'" /></a>'; $item['content'] = $item['title'].'<br><a href="'.$item['uri'].'"><img src="'.$this->uri.$thumbnail->src.'" /></a>';
$this->items[] = $item; $this->items[] = $item;
$num++; $num++;
@ -63,7 +56,7 @@ class HDWallpapersBridge extends BridgeAbstract {
} }
public function getName(){ public function getName(){
return 'HDWallpapers - '.str_replace(['__', '_'], [' & ', ' '], $this->category).' ['.$this->resolution.']'; return 'HDWallpapers - '.str_replace(['__', '_'], [' & ', ' '], $this->getInput('c')).' ['.$this->getInput('r').']';
} }
public function getCacheDuration(){ public function getCacheDuration(){