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/src/Source/Qsp.php

69 lines
2.9 KiB
PHP
Raw Normal View History

2017-01-30 13:33:01 +02:00
<?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/>.
*/
2019-07-29 09:35:32 +03:00
namespace Oreolek\Source;
2017-01-30 13:33:01 +02:00
2019-07-29 09:35:32 +03:00
use \Oreolek\Game;
use \Oreolek\Source;
2017-01-30 13:33:01 +02:00
class Qsp extends Source {
public $title = "Библиотека QSP";
protected function parse() {
2017-07-13 18:07:14 +03:00
$text = $this->get_text("http://qsp.su/index.php?option=com_sobi2&sobi2Task=rss&no_html=1&catid=1&Itemid=55");
2018-03-24 21:49:32 +02:00
$this->loadStr($text);
2017-07-13 18:07:14 +03:00
unset($text);
2018-03-24 21:49:32 +02:00
$this->dom->filter('channel item')->each(function($gameBlock){
$date = trim($gameBlock->filter('pubDate')->text(), "() \t\n\r\0\x0B");
2017-01-30 13:33:01 +02:00
$date = new \DateTime($date);
2018-03-24 21:49:32 +02:00
if ($date === false) return;
2017-01-30 13:33:01 +02:00
$date = $date->format('U');
2018-03-24 21:49:32 +02:00
if ($date < $this->period) return;
2017-01-30 13:33:01 +02:00
$game = new Game;
2018-03-24 21:49:32 +02:00
$game->author = trim($gameBlock->filter('category')->text());
$game->title = trim($gameBlock->filter('title')->text());
$game->url = trim($gameBlock->filter('link:first-child')->text());
$game->description = trim($gameBlock->filter('description')->text());
2017-01-30 13:33:01 +02:00
$this->output .= $game->print();
2018-03-24 21:49:32 +02:00
});
2017-01-30 13:33:01 +02:00
}
2018-03-29 10:42:44 +03:00
public function checkPage($url) {
return (strpos($url,'http://qsp.su') !== FALSE);
}
public function page($url) {
$game = new Game;
$game->url = $url;
try {
$game->author = trim($this->dom->filter('#sobi2Details_field_author')->text());
$game->author = trim(str_replace($this->dom->filter('#sobi2Listing_field_author_label')->text(), '', $game->author));
$game->title = trim($this->dom->filter('.sobi2Details h1')->first()->text());
$game->description = trim($this->dom->filter('#sobi2Details_field_description')->text());
$game->platform = 'QSP';
$game->url_download = trim($this->dom->filter('h2 a')->attr('href'));
$game->url_download_description = 'Архив для интерпретатора QSP';
$game->image = trim($this->dom->filter('.sobi2DetailsImage')->first()->attr('src'));
preg_match('/\d?\d\.\d?\d\.\d{4}/', $this->dom->filter('.sobi2DetailsFooter tr:first-child td')->text(), $matches);
$game->date = new \DateTime($matches[0]);
} catch (\Exception $e) {
echo 'Ошибка парсинга. Проверьте URL.'.PHP_EOL;
echo $e->getTraceAsString();
die();
}
return $game;
}
2017-01-30 13:33:01 +02:00
}