Archived
1
0
Fork 0

Гиперкнига (заодно и пустой Dashingdon)

This commit is contained in:
Alexander Yakovlev 2018-03-25 02:35:24 +07:00
parent 1b0c20b975
commit aa7b65a299
2 changed files with 30 additions and 45 deletions

View file

@ -10,7 +10,7 @@ class Dashingdon extends Source {
public $title = "DashingDon";
protected function parse() {
$text = $this->get_text("https://dashingdon.com/screenreader/");
$this->dom->loadStr($text, []);
$this->loadStr($text);
unset($text);
}
}

View file

@ -5,55 +5,40 @@ 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');
try {
$this->dom->loadStr($text, []);
} catch (\Exception $e) {
echo $e->getMessage();
echo $e->getTraceAsString();
return "";
}
$this->loadStr($text);
unset($text);
$container = $this->dom->find('#listPubs');
$games = [];
try {
$headings = $container->find("h3");
} catch (\Exception $e ) {
echo $e->getMessage();
echo $e->getTraceAsString();
return "";
}
foreach ($headings as $heading) {
$this->dom->filter("#listPubs h3 a")->each(function($link) {
$game = new Game;
$link = $heading->find('a')[0];
$game->title = $link->innerHtml;
$game->url = $link->getAttribute('href');
$game->title = $link->text();
$game->url = $link->attr('href');
$game->url = str_replace('file', 'http://hyperbook.ru/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) {
$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');