IFDB.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /*
  3. Microblog bot for game release notifications
  4. Copyright (C) 2017 Alexander Yakovlev
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. namespace Source;
  17. use \Game;
  18. class IFDB extends Source {
  19. public $title = "IFDB";
  20. protected function parse() {
  21. $service = new \Sabre\Xml\Service();
  22. $xml = $this->get_text("http://ifdb.tads.org/allnew-rss");
  23. $service->elementMap = [
  24. '{}item' => function(\Sabre\Xml\Reader $reader) {
  25. $game = new Game;
  26. $keyValue = \Sabre\Xml\Deserializer\keyValue($reader, '{}item');
  27. if (isset($keyValue['{}title'])) {
  28. $title = $keyValue['{}title'];
  29. if (strpos($title, 'A new listing') === FALSE)
  30. return [];
  31. $title = str_replace('A new listing for ', '', $title);
  32. $title = explode(' by ', $title);
  33. $game->title = $title[0];
  34. $game->author = $title[1];
  35. }
  36. if (isset($keyValue['{}link'])) {
  37. $game->url = $keyValue['{}link'];
  38. }
  39. if (isset($keyValue['{}description'])) {
  40. $game->description = $keyValue['{}description'];
  41. }
  42. if (isset($keyValue['{}pubDate'])) {
  43. $game->date = strtotime($keyValue['{}pubDate']);
  44. }
  45. if ($game->date >= $this->period) {
  46. $this->games[] = $game;
  47. }
  48. return $game;
  49. },
  50. ];
  51. $dom = $service->parse($xml);
  52. }
  53. }