. */ namespace App\Sources; use \App\Models\Game; use \App\Models\Platform; use \App\Models\Language; use \App\Models\Author; use \App\Models\Tag; use \App\Source; use Log; class IFDB extends Source { public $title = "IFDB"; public $keyword = 'ifdb'; protected $urls = []; public function parse() { $service = new \Sabre\Xml\Service(); $xml = $this->get_text("http://ifdb.tads.org/allnew-rss"); $xml = tidy_repair_string($xml, [ 'output-xml' => true, 'input-xml' => true ]); $service->elementMap = [ '{}item' => function(\Sabre\Xml\Reader $reader) { $game = new Game; $author = ''; $keyValue = \Sabre\Xml\Deserializer\keyValue($reader, '{}item'); if (isset($keyValue['{}title'])) { $title = $keyValue['{}title']; if (strpos($title, 'A new listing') === FALSE) return []; $title = str_replace('A new listing for ', '', $title); $title = explode(' by ', $title); $game->title = $title[0]; if (isset($title[1])) { $author = $title[1]; } } if (isset($keyValue['{}link'])) { $game->url = trim($keyValue['{}link']); $id = str_replace('http:', 'https:', $game->url); $id = str_replace('https://ifdb.tads.org/viewgame?id=', '', $id); $game->source_id = $id; } $game = $this->findGame($game); if (isset($keyValue['{}description'])) { $game->description = $keyValue['{}description']; } if (isset($keyValue['{}pubDate'])) { $game->release_date = new \DateTime($keyValue['{}pubDate']); } if ($game->save() && !empty($author)) { $author_model = Author::findByName($author); if (empty($author_model)) { $author_model = new Author(); $author_model->name = $author; $author_model->save(); } $game->authors()->syncWithoutDetaching([$author_model->id]); } return $game; }, ]; $dom = $service->parse($xml); } }