Иностранная Гиперкнига
This commit is contained in:
parent
aa7b65a299
commit
dab34de99b
|
@ -6,15 +6,16 @@ use \Game;
|
|||
class Hyperbook extends Source {
|
||||
public $title = "Гиперкнига";
|
||||
protected $games = array();
|
||||
protected $rootUrl = 'http://hyperbook.ru';
|
||||
protected function parse() {
|
||||
$text = $this->get_text('http://hyperbook.ru/lib.php?sort=time');
|
||||
$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', 'http://hyperbook.ru/comments.php?id=', $game->url);
|
||||
$game->url = str_replace('file', $this->rootUrl.'/comments.php?id=', $game->url);
|
||||
$this->games[] = $game;
|
||||
});
|
||||
$this->dom->filter("#listPubs div")->reduce(function($node) {
|
||||
|
|
|
@ -1,52 +1,7 @@
|
|||
<?php
|
||||
namespace Source;
|
||||
|
||||
use \Game;
|
||||
|
||||
class HyperbookEn extends Source {
|
||||
class HyperbookEn extends Hyperbook {
|
||||
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->output .= $game->print();
|
||||
}
|
||||
}
|
||||
protected $rootUrl = 'http://ifiction.net';
|
||||
}
|
||||
|
|
Reference in a new issue