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_en/Itch.php

36 lines
1 KiB
PHP

<?php
namespace Source;
use \Game;
class Itch extends Source {
public $title = "Itch.io";
protected function parse() {
$service = new \Sabre\Xml\Service();
$xml = file_get_contents("https://itch.io/games/newest/tag-text-based.xml");
$service->elementMap = [
'{}item' => function(\Sabre\Xml\Reader $reader) {
$game = new Game;
$keyValue = \Sabre\Xml\Deserializer\keyValue($reader, '{}item');
if (isset($keyValue['{}plainTitle'])) {
$game->title = $keyValue['{}plainTitle'];
}
if (isset($keyValue['{}link'])) {
$game->url = $keyValue['{}link'];
}
if (isset($keyValue['{}description'])) {
$game->description = $keyValue['{}description'];
}
if (isset($keyValue['{}pubDate'])) {
$game->date = strtotime($keyValue['{}pubDate']);
}
if ($game->date >= $this->period) {
$this->output .= $game->print();
}
return $game;
},
];
$dom = $service->parse($xml);
}
}