<?php
namespace Source;
use \Game;
class Questbook extends Source {
public $title = "Библиотека книг-игр";
protected function parse() {
$string = $this->get_text('http://quest-book.ru/directory/rss/');
$service = new \Sabre\Xml\Service();
$service->elementMap = [
'{}item' => function(\Sabre\Xml\Reader $reader) {
return \Sabre\Xml\Deserializer\keyValue($reader, '');
},
'{}channel' => function(\Sabre\Xml\Reader $reader) {
return \Sabre\Xml\Deserializer\repeatingElements($reader, '{}item');
];
$games = $service->parse($string)[0]['value'];
unset($string);
foreach ($games as $gameBlock) {
$date = strtotime($gameBlock['pubDate']);
if ($date < $this->period) continue;
$game = new Game;
$game->title = trim($gameBlock['title']);
$game->url = trim($gameBlock['link']);
$game->description = trim($gameBlock['description']);
$this->output .= $game->print();
}