WorldOfTanks.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. define('WORLD_OF_TANKS', 'http://worldoftanks.eu/');
  3. define('NEWS', '/news/');
  4. class WorldOfTanks 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->update = "2015-09-12";
  13. $this->parameters[] =
  14. '[
  15. {
  16. "name" : "ID de la catégorie",
  17. "type" : "number",
  18. "identifier" : "category"
  19. },
  20. {
  21. "name" : "Langue",
  22. "identifier" : "lang",
  23. "type" : "list",
  24. "values" : [
  25. {
  26. "name" : "Français",
  27. "value" : "fr"
  28. },
  29. {
  30. "name" : "English",
  31. "value" : "en"
  32. },
  33. {
  34. "name" : "Español",
  35. "value" : "es"
  36. },
  37. {
  38. "name" : "Deutsch",
  39. "value" : "de"
  40. },
  41. {
  42. "name" : "Čeština",
  43. "value" : "cs"
  44. },
  45. {
  46. "name" : "Polski",
  47. "value" : "pl"
  48. },
  49. {
  50. "name" : "Türkçe",
  51. "value" : "tr"
  52. }
  53. ]
  54. }
  55. ]';
  56. }
  57. public function collectData(array $param){
  58. if (!empty($param['lang'])) {
  59. $this->lang = $param['lang'];
  60. }
  61. if(empty($param['category'])) {
  62. $this->uri = WORLD_OF_TANKS.$this->lang.NEWS;
  63. } else {
  64. $this->uri = WORLD_OF_TANKS.$this->lang.NEWS.'pc-browser/'.$param['category']."/";
  65. }
  66. $html = $this->file_get_html($this->getURI()) or $this->returnError('Could not request '.$this->getURI(), 404);
  67. $this->message("loaded HTML from ".$this->getURI());
  68. // customize name
  69. $this->name = $html->find('title', 0)->innertext;
  70. foreach($html->find('.b-imgblock_ico') as $infoLink) {
  71. $this->parseLine($infoLink);
  72. }
  73. }
  74. public function parseLine($infoLink) {
  75. $item = new Item();
  76. $item->uri = WORLD_OF_TANKS.$infoLink->href;
  77. // now load that uri from cache
  78. // $this->message("loading page ".$item->uri);
  79. $articlePage = str_get_html($this->get_cached($item->uri));
  80. $content = $articlePage->find('.l-content', 0);
  81. HTMLSanitizer::defaultImageSrcTo($content, WORLD_OF_TANKS);
  82. $item->title = $content->find('h1', 0)->innertext;
  83. $item->content = $content->find('.b-content', 0)->innertext;
  84. // $item->name = $auteur->innertext;
  85. $item->timestamp = $content->find('.b-statistic_time', 0)->getAttribute("data-timestamp");
  86. $this->items[] = $item;
  87. }
  88. public function getName(){
  89. return $this->name;
  90. }
  91. public function getURI(){
  92. return $this->uri;
  93. }
  94. public function getCacheDuration(){
  95. return 3600; // 2h hours
  96. }
  97. public function getDescription(){
  98. return "Toutes les actualités les plus brulantes de ce simulateur de destruction d'acier.";
  99. }
  100. }