WorldOfTanksBridge.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. function getURI(){
  28. $lang = $this->getInput('lang');
  29. $uri = self::URI.$lang.'/news/';
  30. if(!empty($this->getInput('category'))) {
  31. $uri .= 'pc-browser/'.$this->getInput('category')."/";
  32. }
  33. return $uri;
  34. }
  35. public function getName(){
  36. return $this->title?:self::NAME;
  37. }
  38. public function collectData(){
  39. $html = getSimpleHTMLDOM($this->getURI())
  40. or returnServerError('Could not request '.$this->getURI());
  41. debugMessage("loaded HTML from ".$this->getURI());
  42. // customize name
  43. $this->title = $html->find('title', 0)->innertext;
  44. foreach($html->find('.b-imgblock_ico') as $infoLink) {
  45. $this->parseLine($infoLink);
  46. }
  47. }
  48. private function parseLine($infoLink) {
  49. $item = array();
  50. $item['uri'] = self::URI.$infoLink->href;
  51. // now load that uri from cache
  52. debugMessage("loading page ".$item['uri']);
  53. $articlePage = getSimpleHTMLDOMCached($item['uri']);
  54. $content = $articlePage->find('.l-content', 0);
  55. defaultImageSrcTo($content, self::URI);
  56. $item['title'] = $content->find('h1', 0)->innertext;
  57. $item['content'] = $content->find('.b-content', 0)->innertext;
  58. $item['timestamp'] = $content->find('.b-statistic_time', 0)->getAttribute("data-timestamp");
  59. $this->items[] = $item;
  60. }
  61. }