WorldOfTanksBridge.php 2.3 KB

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