66 lines
2.3 KiB
PHP
66 lines
2.3 KiB
PHP
<?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;
|
|
use \App\Models\Language;
|
|
use \App\Models\Platform;
|
|
use \App\Models\Author;
|
|
use \App\Source;
|
|
|
|
class Urq extends Source {
|
|
public $title = "Библиотека URQ";
|
|
public $keyword = 'urq';
|
|
public $platform = 'URQ';
|
|
public function parse() {
|
|
$text = $this->get_text('http://urq.plut.info/node/209');
|
|
$this->loadStr($text);
|
|
unset($text);
|
|
$platform = Platform::findByName($this->platform);
|
|
$this->dom->filter('.view-NewGames tr')->each(function($gameBlock) use($platform) {
|
|
$game = new Game;
|
|
$author = trim($gameBlock->filter('.views-field-taxonomy-vocabulary-2')->first()->text());
|
|
$game->title = trim($gameBlock->filter('.views-field-title')->text());
|
|
$game->release_date = new \DateTime();
|
|
$game->url = 'http://urq.plut.info'.trim($gameBlock->filter('.views-field-title a')->attr('href'));
|
|
$game->source_id = (int) str_replace('http://urq.plut.info/node/', '', $game->url);
|
|
$game = $this->findGame($game);
|
|
$game->save();
|
|
|
|
$language = Language::findByCode('ru');
|
|
$game->languages()->sync([$language->id]);
|
|
|
|
$game->platforms()->sync([$platform->id]);
|
|
|
|
if (!empty($author)) {
|
|
$author_model = Author::findByName($author);
|
|
if (empty($author_model)) {
|
|
$author_model = new Author();
|
|
$author_model->name = $author;
|
|
$author_model->save();
|
|
}
|
|
$game->authors()->sync([$author_model->id]);
|
|
}
|
|
});
|
|
}
|
|
public function checkPage($url) {
|
|
return (strpos($url,'http://urq.plut.info/node/') !== FALSE);
|
|
}
|
|
}
|