51 lines
1.6 KiB
PHP
51 lines
1.6 KiB
PHP
<?php
|
|
namespace Source;
|
|
|
|
use \Game;
|
|
|
|
class Hyperbook extends Source {
|
|
public $title = "Гиперкнига";
|
|
protected $games = array();
|
|
protected function parse() {
|
|
$text = $this->get_text('http://hyperbook.ru/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', 'http://hyperbook.ru/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();
|
|
}
|
|
}
|
|
}
|