SuperbWallpapersBridge.php 2.2 KB

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