2015-04-08 15:25:00 +03:00
|
|
|
<?php
|
|
|
|
class HDWallpapersBridge extends BridgeAbstract {
|
2017-02-11 18:16:56 +03:00
|
|
|
const MAINTAINER = 'nel50n';
|
|
|
|
const NAME = 'HD Wallpapers Bridge';
|
2019-10-16 22:34:28 +03:00
|
|
|
const URI = 'https://www.hdwallpapers.in/';
|
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 HDWallpapers';
|
|
|
|
|
|
|
|
const PARAMETERS = array( array(
|
|
|
|
'c' => array(
|
|
|
|
'name' => 'category',
|
|
|
|
'defaultValue' => 'latest_wallpapers'
|
|
|
|
),
|
|
|
|
'm' => array(
|
|
|
|
'name' => 'max number of wallpapers'
|
|
|
|
),
|
|
|
|
'r' => array(
|
|
|
|
'name' => 'resolution',
|
2019-04-07 23:02:11 +03:00
|
|
|
'defaultValue' => 'HD',
|
|
|
|
'exampleValue' => 'HD, 1920x1200, 1680x1050,…'
|
2017-02-11 18:16:56 +03:00
|
|
|
)
|
|
|
|
));
|
|
|
|
|
|
|
|
public function collectData(){
|
2019-04-07 23:02:11 +03:00
|
|
|
$category = $this->getInput('c');
|
2017-07-29 20:28:00 +03:00
|
|
|
if(strrpos($category, 'wallpapers') !== strlen($category) - strlen('wallpapers')) {
|
2017-02-11 18:16:56 +03:00
|
|
|
$category .= '-desktop-wallpapers';
|
|
|
|
}
|
|
|
|
|
|
|
|
$num = 0;
|
|
|
|
$max = $this->getInput('m') ?: 14;
|
|
|
|
$lastpage = 1;
|
|
|
|
|
2017-07-29 20:28:00 +03:00
|
|
|
for($page = 1; $page <= $lastpage; $page++) {
|
2020-12-23 20:19:32 +03:00
|
|
|
$link = self::URI . $category . '/page/' . $page;
|
2017-02-11 18:16:56 +03:00
|
|
|
$html = getSimpleHTMLDOM($link)
|
|
|
|
or returnServerError('No results for this query.');
|
|
|
|
|
2017-07-29 20:28:00 +03:00
|
|
|
if($page === 1) {
|
2017-02-11 18:16:56 +03:00
|
|
|
preg_match('/page\/(\d+)$/', $html->find('.pagination a', -2)->href, $matches);
|
|
|
|
$lastpage = min($matches[1], ceil($max / 14));
|
|
|
|
}
|
|
|
|
|
2020-12-23 20:19:32 +03:00
|
|
|
$html = defaultLinkTo($html, self::URI);
|
|
|
|
|
2017-07-29 20:28:00 +03:00
|
|
|
foreach($html->find('.wallpapers .wall a') as $element) {
|
2017-02-11 18:16:56 +03:00
|
|
|
$thumbnail = $element->find('img', 0);
|
|
|
|
|
2020-12-23 20:19:32 +03:00
|
|
|
$search = array(self::URI, 'wallpapers.html');
|
|
|
|
$replace = array(self::URI . 'download/', $this->getInput('r') . '.jpg');
|
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
$item = array();
|
2020-12-23 20:19:32 +03:00
|
|
|
$item['uri'] = str_replace($search, $replace, $element->href);
|
2017-02-11 18:16:56 +03:00
|
|
|
|
|
|
|
$item['timestamp'] = time();
|
2019-04-07 23:02:11 +03:00
|
|
|
$item['title'] = $element->find('em1', 0)->text();
|
2017-02-11 18:16:56 +03:00
|
|
|
$item['content'] = $item['title']
|
|
|
|
. '<br><a href="'
|
|
|
|
. $item['uri']
|
|
|
|
. '"><img src="'
|
|
|
|
. $thumbnail->src
|
|
|
|
. '" /></a>';
|
|
|
|
|
2019-04-07 23:02:11 +03:00
|
|
|
$item['enclosures'] = array($item['uri']);
|
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('c')) && !is_null($this->getInput('r'))) {
|
2017-02-15 00:20:55 +03:00
|
|
|
return 'HDWallpapers - '
|
2019-11-01 20:06:38 +03:00
|
|
|
. str_replace(array('__', '_'), array(' & ', ' '), $this->getInput('c'))
|
2017-02-15 00:20:55 +03:00
|
|
|
. ' ['
|
|
|
|
. $this->getInput('r')
|
|
|
|
. ']';
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getName();
|
2017-02-11 18:16:56 +03:00
|
|
|
}
|
2015-04-08 15:25:00 +03:00
|
|
|
}
|