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