2015-03-03 00:42:16 +03:00
|
|
|
<?php
|
|
|
|
class WallpaperStopBridge extends BridgeAbstract {
|
|
|
|
|
2016-08-30 12:23:55 +03:00
|
|
|
const MAINTAINER = "nel50n";
|
|
|
|
const NAME = "WallpaperStop Bridge";
|
|
|
|
const URI = "http://www.wallpaperstop.com";
|
|
|
|
const DESCRIPTION = "Returns the latests wallpapers from WallpaperStop";
|
2015-11-05 18:50:18 +03:00
|
|
|
|
2016-08-30 12:23:55 +03:00
|
|
|
const PARAMETERS = array( array(
|
2016-08-27 22:03:26 +03:00
|
|
|
'c'=>array('name'=>'Category'),
|
|
|
|
's'=>array('name'=>'subcategory'),
|
|
|
|
'm'=>array(
|
2016-08-22 02:25:56 +03:00
|
|
|
'name'=>'Max number of wallpapers',
|
2016-08-30 01:03:36 +03:00
|
|
|
'type'=>'number',
|
|
|
|
'defaultValue'=>20
|
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-30 01:03:36 +03:00
|
|
|
'defaultValue'=>'1920x1200'
|
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(){
|
2016-08-30 01:03:36 +03:00
|
|
|
$category = $this->getInput('c');
|
|
|
|
$subcategory = $this->getInput('s');
|
|
|
|
$resolution = $this->getInput('r');
|
2015-03-03 00:42:16 +03:00
|
|
|
|
2016-08-30 01:03:36 +03:00
|
|
|
$num = 0;
|
|
|
|
$max = $this->getInput('m');
|
|
|
|
$lastpage = 1;
|
2015-03-03 00:42:16 +03:00
|
|
|
|
2016-08-30 01:03:36 +03:00
|
|
|
for ($page = 1; $page <= $lastpage; $page++) {
|
2016-08-30 12:23:55 +03:00
|
|
|
$link = self::URI.'/'.$category.'-wallpaper/'.(!empty($subcategory)?$subcategory.'-wallpaper/':'').'desktop-wallpaper-'.$page.'.html';
|
2016-08-30 01:03:36 +03:00
|
|
|
$html = $this->getSimpleHTMLDOM($link)
|
|
|
|
or $this->returnServerError('No results for this query.');
|
2015-03-03 00:42:16 +03:00
|
|
|
|
2016-08-30 01:03:36 +03:00
|
|
|
if ($page === 1) {
|
|
|
|
preg_match('/-(\d+)\.html$/', $html->find('.pagination > .last', 0)->href, $matches);
|
|
|
|
$lastpage = min($matches[1], ceil($max/20));
|
|
|
|
}
|
2015-03-03 00:42:16 +03:00
|
|
|
|
2016-08-30 01:03:36 +03:00
|
|
|
foreach($html->find('article.item') as $element) {
|
|
|
|
$wplink = $element->getAttribute('data-permalink');
|
2016-08-30 12:23:55 +03:00
|
|
|
if (preg_match('%^'.self::URI.'/(.+)/([^/]+)-(\d+)\.html$%', $wplink, $matches)) {
|
2016-08-30 01:03:36 +03:00
|
|
|
$thumbnail = $element->find('img', 0);
|
2015-03-03 00:42:16 +03:00
|
|
|
|
2016-08-30 01:03:36 +03:00
|
|
|
$item = array();
|
2016-08-30 12:23:55 +03:00
|
|
|
$item['uri'] = self::URI.'/wallpapers/'.str_replace('wallpaper', 'wallpapers', $matches[1]).'/'.$matches[2].'-'.$resolution.'-'.$matches[3].'.jpg';
|
2016-08-30 01:03:36 +03:00
|
|
|
$item['id'] = $matches[3];
|
|
|
|
$item['timestamp'] = time();
|
|
|
|
$item['title'] = $thumbnail->title;
|
2016-08-30 12:23:55 +03:00
|
|
|
$item['content'] = $item['title'].'<br><a href="'.$wplink.'"><img src="'.self::URI.$thumbnail->src.'" /></a>';
|
2016-08-30 01:03:36 +03:00
|
|
|
$this->items[] = $item;
|
2015-03-03 00:42:16 +03:00
|
|
|
|
2016-08-30 01:03:36 +03:00
|
|
|
$num++;
|
|
|
|
if ($num >= $max)
|
|
|
|
break 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-03-03 00:42:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getName(){
|
2016-09-01 23:53:01 +03:00
|
|
|
$subcategory=$this->getInput('s');
|
|
|
|
return 'WallpaperStop - '.$this->getInput('c').(!empty($subcategory) ? ' > '.$subcategory : '').' ['.$this->getInput('r').']';
|
2015-03-03 00:42:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getCacheDuration(){
|
|
|
|
return 43200; // 12 hours
|
|
|
|
}
|
|
|
|
}
|