WorldOfTanksBridge.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. class WorldOfTanksBridge extends BridgeAbstract {
  3. const MAINTAINER = 'mitsukarenai';
  4. const NAME = 'World of Tanks';
  5. const URI = 'http://worldoftanks.eu/';
  6. const DESCRIPTION = 'News about the tank slaughter game.';
  7. const PARAMETERS = array( array(
  8. 'category' => array(
  9. // TODO: should be a list
  10. 'name' => 'nom de la catégorie'
  11. ),
  12. 'lang' => array(
  13. 'name' => 'Langue',
  14. 'type' => 'list',
  15. 'values' => array(
  16. 'Français' => 'fr',
  17. 'English' => 'en',
  18. 'Español' => 'es',
  19. 'Deutsch' => 'de',
  20. 'Čeština' => 'cs',
  21. 'Polski' => 'pl',
  22. 'Türkçe' => 'tr'
  23. )
  24. )
  25. ));
  26. private $title = '';
  27. public function getURI(){
  28. if(!is_null($this->getInput('lang'))){
  29. $lang = $this->getInput('lang');
  30. $uri = self::URI . $lang . '/news/';
  31. if(!empty($this->getInput('category'))) {
  32. $uri .= 'pc-browser/' . $this->getInput('category') . '/';
  33. }
  34. return $uri;
  35. }
  36. return parent::getURI();
  37. }
  38. public function getName(){
  39. return $this->title ?: parent::getName();
  40. }
  41. public function collectData(){
  42. $html = getSimpleHTMLDOM($this->getURI())
  43. or returnServerError('Could not request ' . $this->getURI());
  44. debugMessage("loaded HTML from " . $this->getURI());
  45. // customize name
  46. $this->title = $html->find('title', 0)->innertext;
  47. foreach($html->find('.b-imgblock_ico') as $infoLink){
  48. $this->parseLine($infoLink);
  49. }
  50. }
  51. private function parseLine($infoLink){
  52. $item = array();
  53. $item['uri'] = self::URI . $infoLink->href;
  54. // now load that uri from cache
  55. debugMessage('loading page ' . $item['uri']);
  56. $articlePage = getSimpleHTMLDOMCached($item['uri']);
  57. $content = $articlePage->find('.l-content', 0);
  58. defaultLinkTo($content, self::URI);
  59. $item['title'] = $content->find('h1', 0)->innertext;
  60. $item['content'] = $content->find('.b-content', 0)->innertext;
  61. $item['timestamp'] = $content->find('.b-statistic_time', 0)->getAttribute("data-timestamp");
  62. $this->items[] = $item;
  63. }
  64. }