2015-03-03 00:42:16 +03:00
|
|
|
<?php
|
|
|
|
class WallpaperStopBridge extends BridgeAbstract {
|
|
|
|
|
|
|
|
private $category;
|
|
|
|
private $subcategory;
|
|
|
|
private $resolution;
|
|
|
|
|
2016-08-27 22:03:26 +03:00
|
|
|
public $maintainer = "nel50n";
|
|
|
|
public $name = "WallpaperStop Bridge";
|
|
|
|
public $uri = "http://www.wallpaperstop.com/";
|
|
|
|
public $description = "Returns the latests wallpapers from WallpaperStop";
|
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,…',
|
2016-08-27 22:03:26 +03:00
|
|
|
)
|
|
|
|
));
|
2015-11-05 18:50:18 +03:00
|
|
|
|
|
|
|
|
2016-08-25 02:24:53 +03:00
|
|
|
public function collectData(){
|
|
|
|
$param=$this->parameters[$this->queriedContext];
|
2015-03-03 00:42:16 +03:00
|
|
|
$html = '';
|
2016-08-25 02:24:53 +03:00
|
|
|
if (!isset($param['c']['value'])) {
|
2016-08-17 15:45:08 +03:00
|
|
|
$this->returnClientError('You must specify at least a category (?c=...).');
|
2015-03-03 00:42:16 +03:00
|
|
|
} else {
|
|
|
|
$baseUri = 'http://www.wallpaperstop.com';
|
|
|
|
|
2016-08-25 02:24:53 +03:00
|
|
|
$this->category = $param['c']['value'];
|
|
|
|
$this->subcategory = $param['s']['value'] ?: '';
|
|
|
|
$this->resolution = $param['r']['value'] ?: '1920x1200'; // Wide wallpaper default
|
2015-03-03 00:42:16 +03:00
|
|
|
|
|
|
|
$num = 0;
|
2016-08-25 02:24:53 +03:00
|
|
|
$max = $param['m']['value'] ?: 20;
|
2015-03-03 00:42:16 +03:00
|
|
|
$lastpage = 1;
|
|
|
|
|
|
|
|
for ($page = 1; $page <= $lastpage; $page++) {
|
|
|
|
$link = $baseUri.'/'.$this->category.'-wallpaper/'.(!empty($this->subcategory)?$this->subcategory.'-wallpaper/':'').'desktop-wallpaper-'.$page.'.html';
|
2016-07-08 20:06:35 +03:00
|
|
|
$html = $this->getSimpleHTMLDOM($link) or $this->returnServerError('No results for this query.');
|
2015-03-03 00:42:16 +03:00
|
|
|
|
|
|
|
if ($page === 1) {
|
|
|
|
preg_match('/-(\d+)\.html$/', $html->find('.pagination > .last', 0)->href, $matches);
|
|
|
|
$lastpage = min($matches[1], ceil($max/20));
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach($html->find('article.item') as $element) {
|
|
|
|
$wplink = $element->getAttribute('data-permalink');
|
|
|
|
if (preg_match('%^http://www\.wallpaperstop\.com/(.+)/([^/]+)-(\d+)\.html$%', $wplink, $matches)) {
|
|
|
|
$thumbnail = $element->find('img', 0);
|
|
|
|
|
2016-08-22 19:55:59 +03:00
|
|
|
$item = array();
|
|
|
|
$item['uri'] = $baseUri.'/wallpapers/'.str_replace('wallpaper', 'wallpapers', $matches[1]).'/'.$matches[2].'-'.$this->resolution.'-'.$matches[3].'.jpg';
|
|
|
|
$item['id'] = $matches[3];
|
|
|
|
$item['timestamp'] = time();
|
|
|
|
$item['title'] = $thumbnail->title;
|
|
|
|
$item['content'] = $item['title'].'<br><a href="'.$wplink.'"><img src="'.$baseUri.$thumbnail->src.'" /></a>';
|
2015-03-03 00:42:16 +03:00
|
|
|
$this->items[] = $item;
|
|
|
|
|
|
|
|
$num++;
|
|
|
|
if ($num >= $max)
|
|
|
|
break 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName(){
|
|
|
|
return 'WallpaperStop - '.$this->category.(!empty($this->subcategory) ? ' > '.$this->subcategory : '').' ['.$this->resolution.']';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCacheDuration(){
|
|
|
|
return 43200; // 12 hours
|
|
|
|
}
|
|
|
|
}
|