2015-03-31 11:47:17 +03:00
|
|
|
<?php
|
|
|
|
class PickyWallpapersBridge extends BridgeAbstract {
|
|
|
|
|
2016-08-30 12:23:55 +03:00
|
|
|
const MAINTAINER = "nel50n";
|
|
|
|
const NAME = "PickyWallpapers Bridge";
|
|
|
|
const URI = "http://www.pickywallpapers.com/";
|
2016-09-25 18:04:28 +03:00
|
|
|
const CACHE_TIMEOUT = 43200; // 12h
|
2016-08-30 12:23:55 +03:00
|
|
|
const DESCRIPTION = "Returns the latests wallpapers from PickyWallpapers";
|
2015-11-05 18:50:18 +03:00
|
|
|
|
2016-08-30 12:23:55 +03:00
|
|
|
const PARAMETERS = array( array(
|
2016-08-29 21:41:15 +03:00
|
|
|
'c'=>array(
|
|
|
|
'name'=>'category',
|
|
|
|
'required'=>true
|
|
|
|
),
|
2016-08-27 22:03:26 +03:00
|
|
|
's'=>array('name'=>'subcategory'),
|
|
|
|
'm'=>array(
|
2016-08-22 02:25:56 +03:00
|
|
|
'name'=>'Max number of wallpapers',
|
2016-08-29 21:41:15 +03:00
|
|
|
'defaultValue'=>12,
|
2016-08-22 02:25:56 +03:00
|
|
|
'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-29 21:41:15 +03:00
|
|
|
'defaultValue'=>'1920x1200',
|
2016-08-22 02:25:56 +03:00
|
|
|
'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(){
|
2016-08-29 21:41:15 +03:00
|
|
|
$lastpage = 1;
|
|
|
|
$num = 0;
|
|
|
|
$max = $this->getInput('m');
|
|
|
|
$resolution = $this->getInput('r'); // Wide wallpaper default
|
2015-03-31 11:47:17 +03:00
|
|
|
|
2016-08-29 21:41:15 +03:00
|
|
|
for ($page = 1; $page <= $lastpage; $page++) {
|
2016-09-26 00:22:33 +03:00
|
|
|
$html = getSimpleHTMLDOM($this->getURI().'/page-'.$page.'/')
|
|
|
|
or returnServerError('No results for this query.');
|
2015-03-31 11:47:17 +03:00
|
|
|
|
2016-08-29 21:41:15 +03:00
|
|
|
if ($page === 1) {
|
|
|
|
preg_match('/page-(\d+)\/$/', $html->find('.pages li a', -2)->href, $matches);
|
|
|
|
$lastpage = min($matches[1], ceil($max/12));
|
|
|
|
}
|
2015-03-31 11:47:17 +03:00
|
|
|
|
2016-08-29 21:41:15 +03:00
|
|
|
foreach($html->find('.items li img') as $element) {
|
2015-03-31 11:47:17 +03:00
|
|
|
|
2016-08-29 21:41:15 +03:00
|
|
|
$item = array();
|
2016-08-30 12:23:55 +03:00
|
|
|
$item['uri'] = str_replace('www', 'wallpaper', self::URI).'/'.$resolution.'/'.basename($element->src);
|
2016-08-29 21:41:15 +03:00
|
|
|
$item['timestamp'] = time();
|
|
|
|
$item['title'] = $element->alt;
|
|
|
|
$item['content'] = $item['title'].'<br><a href="'.$item['uri'].'">'.$element.'</a>';
|
|
|
|
$this->items[] = $item;
|
2015-03-31 11:47:17 +03:00
|
|
|
|
2016-08-29 21:41:15 +03:00
|
|
|
$num++;
|
|
|
|
if ($num >= $max)
|
|
|
|
break 2;
|
2015-03-31 11:47:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-29 21:41:15 +03:00
|
|
|
public function getURI(){
|
|
|
|
$subcategory = $this->getInput('s');
|
2016-08-30 12:23:55 +03:00
|
|
|
$link = self::URI.$this->getInput('r').'/'.$this->getInput('c').'/'.$subcategory;
|
2016-08-29 21:41:15 +03:00
|
|
|
return $link;
|
|
|
|
}
|
|
|
|
|
2015-03-31 11:47:17 +03:00
|
|
|
public function getName(){
|
2016-08-29 21:41:15 +03:00
|
|
|
$subcategory = $this->getInput('s');
|
|
|
|
return 'PickyWallpapers - '.$this->getInput('c')
|
|
|
|
.($subcategory? ' > '.$subcategory : '')
|
|
|
|
.' ['.$this->getInput('r').']';
|
2015-03-31 11:47:17 +03:00
|
|
|
}
|
|
|
|
}
|