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/Instory.php

60 lines
2 KiB
PHP

<?php
/*
A set of utilities for tracking text-based game releases
Copyright (C) 2017-2018 Alexander Yakovlev
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Source;
use \Game;
class Instory extends Source {
public $title = "Instory";
protected function parse() {
$this->parseFeed('http://instory.top/feed/');
}
protected function parseFeed($feedUrl) {
$string = $this->get_text($feedUrl);
$string = mb_convert_encoding($string, 'UTF-8', 'auto');
$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');
},
];
try {
$games = $service->parse($string)[0]['value'];
} catch (\Sabre\Xml\LibXMLException $e) {
echo $e->getMessage();
echo $e->getTraceAsString();
return "";
}
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']);
$game->author = trim($gameBlock['{http://purl.org/dc/elements/1.1/}creator']);
$this->output .= $game->print();
}
}
}