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

50 lines
1.6 KiB
PHP
Raw Normal View History

2017-02-16 07:33:46 +02:00
<?php
namespace Source;
use \Game;
class Itch extends Source {
public $title = "Itch.io";
protected function parse_tag($url) {
2017-02-16 07:33:46 +02:00
$service = new \Sabre\Xml\Service();
2017-02-17 08:45:38 +02:00
$xml = $this->get_text($url);
2017-02-16 07:33:46 +02:00
$service->elementMap = [
'{}item' => function(\Sabre\Xml\Reader $reader) {
$game = new Game;
$keyValue = \Sabre\Xml\Deserializer\keyValue($reader, '{}item');
2017-03-10 08:14:45 +02:00
if (isset($keyValue['{}pubDate'])) {
$game->date = strtotime($keyValue['{}pubDate']);
if ($game->date < $this->period) {
return $game;
}
}
2017-02-16 07:33:46 +02:00
if (isset($keyValue['{}plainTitle'])) {
$game->title = $keyValue['{}plainTitle'];
}
if (isset($keyValue['{}link'])) {
$game->url = $keyValue['{}link'];
}
if (isset($keyValue['{}description'])) {
2017-03-10 08:14:45 +02:00
$game->description = trim(strip_tags($keyValue['{}description'], '<p><a><br>'));
2017-02-16 07:33:46 +02:00
}
2017-03-10 08:14:45 +02:00
$game_page = $this->get_text($game->url);
2017-07-13 18:07:14 +03:00
$this->dom->loadStr($game_page, []);
2017-03-10 08:14:45 +02:00
$lines = $this->dom->find('.game_info_panel_widget tr');
foreach ($lines as $line) {
$text = $line->find('td');
if ($text->innerHtml == 'Author') {
$game->author = strip_tags($text->nextSibling()->innerHtml);
}
2017-02-16 07:33:46 +02:00
}
2017-03-10 08:14:45 +02:00
$this->output .= $game->print();
2017-02-16 07:33:46 +02:00
return $game;
},
];
$dom = $service->parse($xml);
}
protected function parse() {
$this->parse_tag("https://itch.io/games/newest/tag-text-based.xml");
$this->parse_tag("https://itch.io/games/newest/tag-interactive-fiction.xml");
}
2017-02-16 07:33:46 +02:00
}