2019-09-12 20:03:56 +03: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/>.
|
|
|
|
*/
|
|
|
|
namespace App\Sources;
|
|
|
|
|
|
|
|
use \App\Models\Game;
|
2020-04-19 09:05:55 +03:00
|
|
|
use \App\Models\Language;
|
|
|
|
use \App\Models\Platform;
|
|
|
|
use \App\Models\Author;
|
2019-09-12 20:03:56 +03:00
|
|
|
use \App\Source;
|
|
|
|
|
|
|
|
class Urq extends Source {
|
2019-09-13 08:56:52 +03:00
|
|
|
public $title = "Библиотека URQ";
|
2020-04-19 09:05:55 +03:00
|
|
|
public $keyword = 'urq';
|
|
|
|
public $platform = 'URQ';
|
2019-09-12 22:30:03 +03:00
|
|
|
public function parse() {
|
2019-09-12 20:03:56 +03:00
|
|
|
$text = $this->get_text('http://urq.plut.info/node/209');
|
|
|
|
$this->loadStr($text);
|
|
|
|
unset($text);
|
|
|
|
$games = $this->dom->filter('.view-NewGames tr')->each(function($gameBlock) {
|
|
|
|
$game = new Game;
|
2020-04-19 09:05:55 +03:00
|
|
|
$author = trim($gameBlock->filter('.views-field-taxonomy-vocabulary-2')->first()->text());
|
2019-09-12 20:03:56 +03:00
|
|
|
$game->title = trim($gameBlock->filter('.views-field-title')->text());
|
2020-04-19 09:05:55 +03:00
|
|
|
$game->release_date = new \DateTime();
|
2019-09-12 22:30:03 +03:00
|
|
|
$game->url = 'http://urq.plut.info'.trim($gameBlock->filter('.views-field-title a')->attr('href'));
|
2019-09-13 08:56:52 +03:00
|
|
|
$game->source_id = (int) str_replace('http://urq.plut.info/node/', '', $game->url);
|
2020-04-19 09:05:55 +03:00
|
|
|
$game = $this->findGame($game);
|
|
|
|
$game->save();
|
|
|
|
|
|
|
|
$language = Language::findByCode('ru');
|
|
|
|
if (!$game->languages()->where('code', 'ru')->exists()) {
|
|
|
|
$game->languages()->attach($language);
|
|
|
|
}
|
|
|
|
|
|
|
|
$model = Platform::where('title', $this->platform)->first();
|
|
|
|
if (!$model) {
|
|
|
|
$model = new Platform();
|
|
|
|
$model->title = $this->platform;
|
|
|
|
$model->save();
|
|
|
|
}
|
|
|
|
$game->platforms()->attach($model);
|
|
|
|
|
|
|
|
if (!empty($author)) {
|
|
|
|
$author_model = Author::findByName($author);
|
|
|
|
if (empty($author_model)) {
|
|
|
|
$author_model = new Author();
|
|
|
|
$author_model->name = $author;
|
|
|
|
$author_model->save();
|
|
|
|
}
|
|
|
|
if (!$game->authors()->where('name', $author)->exists()) {
|
|
|
|
$game->authors()->attach($author_model);
|
|
|
|
}
|
|
|
|
}
|
2019-09-12 20:03:56 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
public function checkPage($url) {
|
|
|
|
return (strpos($url,'http://urq.plut.info/node/') !== FALSE);
|
|
|
|
}
|
|
|
|
public function page($url) {
|
|
|
|
$game = new Game;
|
|
|
|
$game->url = $url;
|
|
|
|
$gameBlock = $this->dom->filter('.content');
|
|
|
|
$game->author = trim($gameBlock->filter('.field-name-taxonomy-vocabulary-2 a')->first()->text());
|
|
|
|
$game->title = trim($this->dom->filter('h1.title')->first()->text());
|
|
|
|
$game->description = $gameBlock->filter('.field-type-text-with-summary .field-items span.field-item')->first()->text();
|
|
|
|
$game->platform = $gameBlock->filter('.field-name-taxonomy-vocabulary-5 .field-items span.field-item a')->first()->text();
|
|
|
|
return $game;
|
|
|
|
}
|
|
|
|
}
|