2015-03-31 11:47:17 +03:00
|
|
|
<?php
|
|
|
|
class PickyWallpapersBridge extends BridgeAbstract {
|
|
|
|
|
|
|
|
private $category;
|
|
|
|
private $subcategory;
|
|
|
|
private $resolution;
|
|
|
|
|
2016-08-27 22:03:26 +03:00
|
|
|
public $maintainer = "nel50n";
|
|
|
|
public $name = "PickyWallpapers Bridge";
|
|
|
|
public $uri = "http://www.pickywallpapers.com/";
|
|
|
|
public $description = "Returns the latests wallpapers from PickyWallpapers";
|
2015-11-05 18:50:18 +03:00
|
|
|
|
2016-08-27 22:03:26 +03:00
|
|
|
public $parameters = array( array(
|
|
|
|
'c'=>array('name'=>'category'),
|
|
|
|
's'=>array('name'=>'subcategory'),
|
|
|
|
'm'=>array(
|
2016-08-22 02:25:56 +03:00
|
|
|
'name'=>'Max number of wallpapers',
|
|
|
|
'type'=>'number'
|
2016-08-27 22:03:26 +03:00
|
|
|
),
|
|
|
|
'r'=>array(
|
2016-08-22 02:25:56 +03:00
|
|
|
'name'=>'resolution',
|
|
|
|
'exampleValue'=>'1920x1200, 1680x1050,…',
|
|
|
|
'pattern'=>'[0-9]{3,4}x[0-9]{3,4}'
|
2016-08-27 22:03:26 +03:00
|
|
|
)
|
|
|
|
));
|
2016-08-22 02:25:56 +03:00
|
|
|
|
2015-11-05 18:50:18 +03:00
|
|
|
|
2016-08-25 02:24:53 +03:00
|
|
|
public function collectData(){
|
2015-03-31 11:47:17 +03:00
|
|
|
$html = '';
|
2016-08-28 21:38:01 +03:00
|
|
|
if (!$this->getInput('c')) {
|
2016-08-17 15:45:08 +03:00
|
|
|
$this->returnClientError('You must specify at least a category (?c=...).');
|
2015-03-31 11:47:17 +03:00
|
|
|
} else {
|
|
|
|
$baseUri = 'http://www.pickywallpapers.com';
|
|
|
|
|
2016-08-28 02:25:33 +03:00
|
|
|
$this->category = $this->getInput('c');
|
|
|
|
$this->subcategory = $this->getInput('s') ?: '';
|
|
|
|
$this->resolution = $this->getInput('r') ?: '1920x1200'; // Wide wallpaper default
|
2015-03-31 11:47:17 +03:00
|
|
|
|
|
|
|
$num = 0;
|
2016-08-28 02:25:33 +03:00
|
|
|
$max = $this->getInput('m') ?: 12;
|
2015-03-31 11:47:17 +03:00
|
|
|
$lastpage = 1;
|
|
|
|
|
|
|
|
for ($page = 1; $page <= $lastpage; $page++) {
|
|
|
|
$link = $baseUri.'/'.$this->resolution.'/'.$this->category.'/'.(!empty($this->subcategory)?$this->subcategory.'/':'').'page-'.$page.'/';
|
2016-07-08 20:06:35 +03:00
|
|
|
$html = $this->getSimpleHTMLDOM($link) or $this->returnServerError('No results for this query.');
|
2015-03-31 11:47:17 +03:00
|
|
|
|
|
|
|
if ($page === 1) {
|
|
|
|
preg_match('/page-(\d+)\/$/', $html->find('.pages li a', -2)->href, $matches);
|
|
|
|
$lastpage = min($matches[1], ceil($max/12));
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach($html->find('.items li img') as $element) {
|
|
|
|
|
2016-08-22 19:55:59 +03:00
|
|
|
$item = array();
|
|
|
|
$item['uri'] = str_replace('www', 'wallpaper', $baseUri).'/'.$this->resolution.'/'.basename($element->src);
|
|
|
|
$item['timestamp'] = time();
|
|
|
|
$item['title'] = $element->alt;
|
|
|
|
$item['content'] = $item['title'].'<br><a href="'.$item['uri'].'">'.$element.'</a>';
|
2015-03-31 11:47:17 +03:00
|
|
|
$this->items[] = $item;
|
|
|
|
|
|
|
|
$num++;
|
|
|
|
if ($num >= $max)
|
|
|
|
break 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName(){
|
|
|
|
return 'PickyWallpapers - '.$this->category.(!empty($this->subcategory) ? ' > '.$this->subcategory : '').' ['.$this->resolution.']';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCacheDuration(){
|
|
|
|
return 43200; // 12 hours
|
|
|
|
}
|
|
|
|
}
|