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

82 lines
3.2 KiB
PHP
Raw Normal View History

2017-01-23 09:00:42 +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/>.
*/
2017-01-23 09:15:26 +02:00
namespace Source;
use \Game;
2017-01-23 09:00:42 +02:00
class Instead extends Source {
public $title = "INSTEAD репозиторий";
2018-04-07 13:41:19 +03:00
protected $baseUrl = 'http://instead-games.ru/';
2017-01-23 09:00:42 +02:00
protected function insteadfeed($url) {
2017-07-13 18:07:14 +03:00
$text = $this->get_text($url);
2018-03-24 21:42:13 +02:00
$this->loadStr($text);
2017-07-13 18:07:14 +03:00
unset($text);
2018-03-24 21:42:13 +02:00
$this->dom->filter('.game')->each(function($gameBlock) {
$date = trim($gameBlock->filter('.b .date b')->text());
2017-01-23 09:15:26 +02:00
$date = \DateTime::createFromFormat('Y.m.d', $date);
2017-01-23 09:00:42 +02:00
$date = $date->format('U');
2018-03-24 21:42:13 +02:00
if ($date < $this->period) return;
2018-08-03 08:22:05 +03:00
$url = $this->baseUrl.trim($gameBlock->filter('h2:first-child a:first-child')->first()->attr('href'));
$game = $this->page($url);
2017-01-23 09:00:42 +02:00
$this->output .= $game->print();
2018-03-24 21:42:13 +02:00
});
2017-01-23 09:00:42 +02:00
}
protected function parse() {
$this->insteadfeed("http://instead-games.ru/");
if (FORMAT === 'HTML') {
$this->output .= "<h5>Песочница</h5>\n";
} elseif (FORMAT === 'MARKDOWN') {
$this->output .= "##### Песочница\n";
}
2017-01-23 09:00:42 +02:00
$this->insteadfeed("http://instead-games.ru/index.php?approved=0");
}
2018-03-29 09:33:41 +03:00
public function checkPage($url) {
return (strpos($url,'http://instead-games.ru/game.php') !== FALSE);
}
public function page($url) {
$text = $this->get_text($url);
$this->loadStr($text);
unset($text);
$game = new Game;
$game->url = $url;
2018-04-07 14:06:05 +03:00
$game->platform = 'INSTEAD';
2018-04-07 13:41:19 +03:00
$text = trim($this->dom->filter('#panel')->text());
preg_match('/Дата: ([0-9]{4}\.[01][0-9]\.[0-3][0-9])Размер/', $text, $matches);
2018-04-07 14:06:05 +03:00
$game->date = \DateTime::createFromFormat('Y.m.d', $matches[1]);
2018-04-07 13:41:19 +03:00
preg_match('/Автор: (.+)Дата/', $text, $matches);
$game->author = trim($matches[1]);
$game->title = trim($this->dom->filter('h2')->first()->text());
$game->description = trim($this->dom->filter('.gamedsc')->first()->html());
if($this->dom->filter('#instead-em')->first()) {
$game->url_online = $this->baseUrl.$this->dom->filter('#instead-em')->attr('href');
$game->url_online_description = 'Играть онлайн';
}
$game->url_download = $this->baseUrl.ltrim($this->dom->selectLink('Скачать')->first()->attr('href'), '/');
$link = $this->dom->selectLink('Обсудить')->first();
if ($link->count() > 0) {
$game->url_discussion = $link->attr('href');
}
$image = $this->dom->filter('#screenshots a')->first();
if ($image->count() > 0) {
$game->image = $this->baseUrl.$image->attr('href');
}
2018-04-07 13:41:19 +03:00
return $game;
2018-03-29 09:33:41 +03:00
}
2017-01-23 09:00:42 +02:00
}