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/Storymaze.php
2017-01-23 14:15:26 +07:00

36 lines
1.2 KiB
PHP

<?php
namespace Source;
use \Game;
class Storymaze extends Source {
public $title = "Storymaze";
protected function parse() {
$api = file_get_contents('http://storymaze.ru/api/stories/search?count=10&offset=0&asc=');
$api = json_decode($api, TRUE);
foreach ($api as $gameData) {
$date = strtotime($gameData['publishStart']);
if ($date < $this->period) continue;
$game = new Game;
$game->title = $gameData['name'];
$game->url = "http://storymaze.ru/story/view/".$gameData['id'].".html";
$game->description = $gameData['description'];
if (strpos($gameData['description'], '...</a>') !== FALSE) { // описание укорочено
$this->dom->loadFromUrl($game->url);
$storytext = $this->dom->find('.story-text p');
$description = "";
$length = count($storytext);
foreach ($storytext as $text) {
if($text->getAttribute('class') === 'story-name') {
continue;
}
$description .= trim($text->innerHtml);
}
$game->description = $description;
}
$game->author = $gameData['authorName'];
$this->output .= $game->print();
}
}
}