. */ 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); $this->dom->filter('.container .at-card')->each(functioN($gameBlock) { $game = new Game; $game->title = trim($gameBlock->filter('h5')->text()); $game->url = 'https://instory.su'.trim($gameBlock->filter('h5 a')->attr('href')); $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()); }); $language = Language::findByCode('ru'); if (!$game->languages()->where('code', 'ru')->exists()) { $game->languages()->attach($language); } 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()->attach($model); } $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); } } }); } public function checkPage($url) { return (strpos($url,'//instory.su/') !== FALSE); } }