. */ namespace App\Sources; use \App\Models\Game; use \App\Models\Language; use \App\Models\Tag; use \App\Models\Author; use \App\Models\Platform; use \App\Source; class Instory extends Source { public $title = "Instory"; public $keyword = 'instory'; public $platform = 'Instory'; public function parse() { $this->parseIndex('https://instory.su/catalog/sandbox'); $this->parseIndex('https://instory.su/catalog'); } public function parseIndex($feedUrl) { $string = $this->get_text($feedUrl); $string = mb_convert_encoding($string, 'UTF-8', 'auto'); $this->loadStr($string); unset($string); $language = Language::findByCode('ru'); $platform = Platform::findByName($this->platform); $this->dom->filter('.container .at-card')->each(functioN($gameBlock) use($language, $platform) { $game = new Game; $game->title = trim($gameBlock->filter('h5')->text()); $url = trim($gameBlock->filter('h5 a')->attr('href')); $game->url = 'https://instory.su'.$url; if (strpos($url, '/story/') !== false) { $game->source_id = (int) str_replace('/story/', '', $url); } $game->description = trim($gameBlock->filter('.post-card__excerpt')->html()); $game->release_date = $this->downloader->convertDate($gameBlock->filter('.at-author__extend span')->text()); $game = $this->findGame($game); $author = trim($gameBlock->filter('.at-author__name a')->text()); $game->save(); $tags = []; $gameBlock->filter('.at-badge--cats .at-badge__content')->each(function($tag) use(&$tags){ $tags[] = trim($tag->text()); }); $game->languages()->sync([$language->id]); foreach ($tags as $tag) { $model = Tag::where('language_id', $language->id) ->where('title', $tag) ->first(); if (!$model) { $model = new Tag(); $model->language_id = $language->id; $model->title = $tag; $model->save(); } $game->tags()->syncWithoutDetaching([$model->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,'//instory.su/') !== FALSE); } }