Archived
1
0
Fork 0
This repository has been archived on 2020-07-31. You can view files and clone it, but cannot push or open issues or pull requests.
news-script/Source/Hyperbook.php

52 lines
1.6 KiB
PHP

<?php
namespace Source;
use \Game;
class Hyperbook extends Source {
public $title = "Гиперкнига";
protected $games = array();
protected $rootUrl = 'http://hyperbook.ru';
protected function parse() {
$text = $this->get_text($this->rootUrl.'/lib.php?sort=time');
$this->loadStr($text);
unset($text);
$this->dom->filter("#listPubs h3 a")->each(function($link) {
$game = new Game;
$game->title = $link->text();
$game->url = $link->attr('href');
$game->url = str_replace('file', $this->rootUrl.'/comments.php?id=', $game->url);
$this->games[] = $game;
});
$this->dom->filter("#listPubs div")->reduce(function($node) {
if ($node->attr('style') === 'text-align:left;margin-bottom:4px;')
return true;
return false;
})->each(function($author, $i) {
$this->games[$i]->author = $author->text();
});
$this->dom->filter("#listPubs div")->reduce(function($node) {
if ($node->attr('style') === 'float: left; width: 20%; text-align:right;')
return true;
return false;
})->each(function($date, $i){
$this->games[$i]->date = $date->text();
});
$this->dom->filter("#listPubs div")->reduce(function($node) {
if ($node->attr('style') === NULL)
return true;
return false;
})->each(function($dsc, $i){
$this->games[$i]->description = $dsc->text();
});
foreach ($this->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->output .= $game->print();
}
}
}