1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- /*
- Microblog bot for game release notifications
- Copyright (C) 2017 Alexander Yakovlev
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- namespace Source;
- use \Game;
- class HyperbookEn extends Source {
- public $title = "Гиперкнига";
- protected function parse() {
- $text = $this->get_text('http://ifiction.net/lib.php?sort=time');
- $this->dom->loadStr($text, []);
- unset($text);
- $container = $this->dom->find('#listPubs');
- $games = [];
- foreach ($container->find("h3") as $heading) {
- $game = new Game;
- $link = $heading->find('a')[0];
- $game->title = $link->innerHtml;
- $game->url = $link->getAttribute('href');
- $game->url = str_replace('file', 'http://ifiction.net/comments.php?id=', $game->url);
- $games[] = $game;
- }
- $i = 0;
- foreach ($container->find("div") as $author) {
- if ($author->getAttribute('style') !== 'text-align:left;margin-bottom:4px;') {
- continue;
- }
- $games[$i]->author = $author->innerHtml;
- $i++;
- }
- $i = 0;
- foreach ($container->find("div.small") as $small) {
- if(
- $small->getAttribute('style') === 'float: left; width: 20%; text-align:right;' &&
- is_null($games[$i]->date)
- ) {
- $games[$i]->date = $small->innerHtml;
- }
- elseif ($small->getAttribute('style') === NULL) {
- $games[$i]->description = $small->innerHtml;
- $i++;
- }
- }
- foreach ($games as $game) {
- $date = \DateTime::createFromFormat('d.m.y', $game->date);
- if ($date === false) continue;
- $date = $date->format('U');
- if ($date < $this->period) continue;
-
- $this->games[] = $game;
- }
- }
- }
|