HyperbookEn.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 HyperbookEn extends Source {
  19. public $title = "Гиперкнига";
  20. protected function parse() {
  21. $text = $this->get_text('http://ifiction.net/lib.php?sort=time');
  22. $this->dom->loadStr($text, []);
  23. unset($text);
  24. $container = $this->dom->find('#listPubs');
  25. $games = [];
  26. foreach ($container->find("h3") as $heading) {
  27. $game = new Game;
  28. $link = $heading->find('a')[0];
  29. $game->title = $link->innerHtml;
  30. $game->url = $link->getAttribute('href');
  31. $game->url = str_replace('file', 'http://ifiction.net/comments.php?id=', $game->url);
  32. $games[] = $game;
  33. }
  34. $i = 0;
  35. foreach ($container->find("div") as $author) {
  36. if ($author->getAttribute('style') !== 'text-align:left;margin-bottom:4px;') {
  37. continue;
  38. }
  39. $games[$i]->author = $author->innerHtml;
  40. $i++;
  41. }
  42. $i = 0;
  43. foreach ($container->find("div.small") as $small) {
  44. if(
  45. $small->getAttribute('style') === 'float: left; width: 20%; text-align:right;' &&
  46. is_null($games[$i]->date)
  47. ) {
  48. $games[$i]->date = $small->innerHtml;
  49. }
  50. elseif ($small->getAttribute('style') === NULL) {
  51. $games[$i]->description = $small->innerHtml;
  52. $i++;
  53. }
  54. }
  55. foreach ($games as $game) {
  56. $date = \DateTime::createFromFormat('d.m.y', $game->date);
  57. if ($date === false) continue;
  58. $date = $date->format('U');
  59. if ($date < $this->period) continue;
  60. $this->games[] = $game;
  61. }
  62. }
  63. }