SuperbWallpapersBridge.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. class SuperbWallpapersBridge extends BridgeAbstract {
  3. const MAINTAINER = 'nel50n';
  4. const NAME = 'Superb Wallpapers Bridge';
  5. const URI = 'http://www.superbwallpapers.com/';
  6. const CACHE_TIMEOUT = 43200; // 12h
  7. const DESCRIPTION = 'Returns the latests wallpapers from SuperbWallpapers';
  8. const PARAMETERS = array( array(
  9. 'c' => array(
  10. 'name' => 'category',
  11. 'required' => true
  12. ),
  13. 'm' => array(
  14. 'name' => 'Max number of wallpapers',
  15. 'type' => 'number'
  16. ),
  17. 'r' => array(
  18. 'name' => 'resolution',
  19. 'exampleValue' => '1920x1200, 1680x1050,…',
  20. 'defaultValue' => '1920x1200'
  21. )
  22. ));
  23. public function collectData(){
  24. $category = $this->getInput('c');
  25. $resolution = $this->getInput('r'); // Wide wallpaper default
  26. $num = 0;
  27. $max = $this->getInput('m') ?: 36;
  28. $lastpage = 1;
  29. // Get last page number
  30. $link = self::URI . '/' . $category . '/9999.html';
  31. $html = getSimpleHTMLDOM($link)
  32. or returnServerError('Could not load ' . $link);
  33. $lastpage = min($html->find('.paging .cpage', 0)->innertext(), ceil($max / 36));
  34. for($page = 1; $page <= $lastpage; $page++) {
  35. $link = self::URI . '/' . $category . '/' . $page . '.html';
  36. $html = getSimpleHTMLDOM($link)
  37. or returnServerError('No results for this query.');
  38. foreach($html->find('.wpl .i a') as $element) {
  39. $thumbnail = $element->find('img', 0);
  40. $item = array();
  41. $item['uri'] = str_replace('200x125', $this->resolution, $thumbnail->src);
  42. $item['timestamp'] = time();
  43. $item['title'] = $element->title;
  44. $item['content'] = $item['title'] . '<br><a href="' . $item['uri'] . '">' . $thumbnail . '</a>';
  45. $this->items[] = $item;
  46. $num++;
  47. if ($num >= $max)
  48. break 2;
  49. }
  50. }
  51. }
  52. public function getName(){
  53. if(!is_null($this->getInput('c')) && !is_null($this->getInput('r'))) {
  54. return self::NAME . '- ' . $this->getInput('c') . ' [' . $this->getInput('r') . ']';
  55. }
  56. return parent::getName();
  57. }
  58. }