diff --git a/bridges/PickyWallpapersBridge.php b/bridges/PickyWallpapersBridge.php
index 6fa77ca..001cd1d 100644
--- a/bridges/PickyWallpapersBridge.php
+++ b/bridges/PickyWallpapersBridge.php
@@ -1,73 +1,73 @@
array('name'=>'category'),
+ 'c'=>array(
+ 'name'=>'category',
+ 'required'=>true
+ ),
's'=>array('name'=>'subcategory'),
'm'=>array(
'name'=>'Max number of wallpapers',
+ 'defaultValue'=>12,
'type'=>'number'
),
'r'=>array(
'name'=>'resolution',
'exampleValue'=>'1920x1200, 1680x1050,…',
+ 'defaultValue'=>'1920x1200',
'pattern'=>'[0-9]{3,4}x[0-9]{3,4}'
)
));
public function collectData(){
- $html = '';
- if (!$this->getInput('c')) {
- $this->returnClientError('You must specify at least a category (?c=...).');
- } else {
- $baseUri = 'http://www.pickywallpapers.com';
+ $lastpage = 1;
+ $num = 0;
+ $max = $this->getInput('m');
+ $resolution = $this->getInput('r'); // Wide wallpaper default
- $this->category = $this->getInput('c');
- $this->subcategory = $this->getInput('s') ?: '';
- $this->resolution = $this->getInput('r') ?: '1920x1200'; // Wide wallpaper default
+ for ($page = 1; $page <= $lastpage; $page++) {
+ $html = $this->getSimpleHTMLDOM($this->getURI().'/page-'.$page.'/')
+ or $this->returnServerError('No results for this query.');
- $num = 0;
- $max = $this->getInput('m') ?: 12;
- $lastpage = 1;
+ if ($page === 1) {
+ preg_match('/page-(\d+)\/$/', $html->find('.pages li a', -2)->href, $matches);
+ $lastpage = min($matches[1], ceil($max/12));
+ }
- for ($page = 1; $page <= $lastpage; $page++) {
- $link = $baseUri.'/'.$this->resolution.'/'.$this->category.'/'.(!empty($this->subcategory)?$this->subcategory.'/':'').'page-'.$page.'/';
- $html = $this->getSimpleHTMLDOM($link) or $this->returnServerError('No results for this query.');
+ foreach($html->find('.items li img') as $element) {
- if ($page === 1) {
- preg_match('/page-(\d+)\/$/', $html->find('.pages li a', -2)->href, $matches);
- $lastpage = min($matches[1], ceil($max/12));
- }
+ $item = array();
+ $item['uri'] = str_replace('www', 'wallpaper', $this->uri).'/'.$resolution.'/'.basename($element->src);
+ $item['timestamp'] = time();
+ $item['title'] = $element->alt;
+ $item['content'] = $item['title'].'
'.$element.'';
+ $this->items[] = $item;
- foreach($html->find('.items li img') as $element) {
-
- $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'].'
'.$element.'';
- $this->items[] = $item;
-
- $num++;
- if ($num >= $max)
- break 2;
- }
+ $num++;
+ if ($num >= $max)
+ break 2;
}
}
}
+ public function getURI(){
+ $subcategory = $this->getInput('s');
+ $link = $this->uri.$this->getInput('r').'/'.$this->getInput('c').'/'.$subcategory;
+ return $link;
+ }
+
public function getName(){
- return 'PickyWallpapers - '.$this->category.(!empty($this->subcategory) ? ' > '.$this->subcategory : '').' ['.$this->resolution.']';
+ $subcategory = $this->getInput('s');
+ return 'PickyWallpapers - '.$this->getInput('c')
+ .($subcategory? ' > '.$subcategory : '')
+ .' ['.$this->getInput('r').']';
}
public function getCacheDuration(){