public function getTableModpacks($get_version = 'all') { $cache_key = 'table-modpacks-' . $get_version; if (Cache::tags('modpacks')->has($cache_key)) { $modpacks_array = Cache::tags('modpacks')->get($cache_key); } else { $modpacks_array = []; $modpack_id_array = []; $get_version = $this->getVersion($get_version); if ($get_version == 'all') { $raw_modpacks = Modpack::with('creators')->with('version')->with('launcher')->get(); } else { $raw_version = MinecraftVersion::where('name', '=', $get_version)->with('modpacks')->first(); $raw_modpacks = $raw_version->modpacks()->with('creators')->with('version')->with('launcher')->get(); } foreach ($raw_modpacks as $modpack) { if (in_array($modpack->id, $modpack_id_array)) { continue; } $modpacks_array[] = $this->buildModpackArray($modpack); $mod_id_array[] = $modpack->id; } Cache::tags('modpacks')->forever($cache_key, $modpacks_array); } return $this->buildDTModpackOutput($modpacks_array); }
private function fetchModpack($slug) { $response = array(); if (Cache::has('modpack.' . $slug) && empty($this->client) && empty($this->key)) { $modpack = Cache::get('modpack.' . $slug); } else { $modpack = Modpack::with('Builds')->where("slug", "=", $slug)->first(); if (empty($this->client) && empty($this->key)) { Cache::put('modpack.' . $slug, $modpack, 5); } } if (empty($modpack)) { return array("error" => "Modpack does not exist"); } if ($modpack->private == 1 && !isset($this->key)) { if (!isset($this->client)) { return array("error" => "Modpack does not exist"); } else { if (!in_array($modpack->id, array_map(function ($modpack) { return $modpack->id; }, $this->client->modpacks->all()))) { return array("error" => "Modpack does not exist"); } } } $response['name'] = $modpack->slug; $response['display_name'] = $modpack->name; $response['url'] = $modpack->url; $response['icon'] = $modpack->icon_url; $response['icon_md5'] = $modpack->icon_md5; $response['logo'] = $modpack->logo_url; $response['logo_md5'] = $modpack->logo_md5; $response['background'] = $modpack->background_url; $response['background_md5'] = $modpack->background_md5; $response['recommended'] = $modpack->recommended; $response['latest'] = $modpack->latest; $response['builds'] = array(); foreach ($modpack->builds as $build) { if ($build->is_published) { if (!$build->private || isset($this->key)) { array_push($response['builds'], $build->version); } else { if (isset($this->client)) { foreach ($this->client->modpacks as $pmodpack) { if ($modpack->id == $pmodpack->id) { array_push($response['builds'], $build->version); } } } } } } return $response; }
private function fetch_modpack($slug) { $response = array(); if (Cache::has('modpack.' . $slug)) { $modpack = Cache::Get('modpack.' . $slug); } else { $modpack = Modpack::with('Builds')->where("slug", "=", $slug)->first(); Cache::put('modpack.' . $slug, $modpack, 5); } if (empty($modpack)) { return array("error" => "Modpack does not exist"); } $response['name'] = $modpack->slug; $response['display_name'] = $modpack->name; $response['url'] = $modpack->url; $response['icon_md5'] = $modpack->icon_md5; $response['logo_md5'] = $modpack->logo_md5; $response['background_md5'] = $modpack->background_md5; $response['recommended'] = $modpack->recommended; $response['latest'] = $modpack->latest; $response['builds'] = array(); foreach ($modpack->builds as $build) { if ($build->is_published) { array_push($response['builds'], $build->version); } } return $response; }
private function fetch_modpack($slug) { $response = array(); if (Cache::has('modpack.' . $slug) && empty($this->client)) { $modpack = Cache::get('modpack.' . $slug); } else { $modpack = Modpack::with('Builds')->where("slug", "=", $slug)->first(); if (empty($this->client)) { Cache::put('modpack.' . $slug, $modpack, 5); } } if (empty($modpack)) { return array("error" => "Modpack does not exist"); } $response['name'] = $modpack->slug; $response['display_name'] = $modpack->name; $response['url'] = $modpack->url; $resourcePath = URL::to_asset('resources/' . $modpack->slug); if ($modpack->icon == 0 && !empty($modpack->icon_md5)) { $response['icon'] = Config::get('solder.mirror_url') . $modpack->slug . "/resources/icon.png"; } else { if ($modpack->icon == 0 && empty($modpack->icon_md5)) { $response['icon'] = URL::to_asset('resources/default/icon.png'); $modpack->icon_md5 = md5_file(path('public') . 'resources/default/icon.png'); } else { if (Config::get('solder.use_s3')) { $response['icon'] = Config::get('solder.s3_url') . 'resources/' . $modpack->slug . '/icon.png?' . TimeUtils::getTimestampDate($modpack->updated_at); } else { $response['icon'] = $resourcePath . "/icon.png"; } } } $response['icon_md5'] = $modpack->icon_md5; if ($modpack->logo == 0 && !empty($modpack->logo_md5)) { $response['logo'] = Config::get('solder.mirror_url') . $modpack->slug . "/resources/logo.png"; } else { if ($modpack->logo == 0 && empty($modpack->logo_md5)) { $response['logo'] = URL::to_asset('resources/default/logo.png'); $modpack->logo_md5 = md5_file(path('public') . 'resources/default/logo.png'); } else { if (Config::get('solder.use_s3')) { $response['logo'] = Config::get('solder.s3_url') . 'resources/' . $modpack->slug . '/logo.png?' . TimeUtils::getTimestampDate($modpack->updated_at); } else { $response['logo'] = $resourcePath . "/logo.png"; } } } $response['logo_md5'] = $modpack->logo_md5; if ($modpack->background == 0 && !empty($modpack->background_md5)) { $response['background'] = Config::get('solder.mirror_url') . $modpack->slug . "/resources/background.png"; } else { if ($modpack->background == 0 && empty($modpack->background_md5)) { $response['background'] = URL::to_asset('resources/default/background.png'); $modpack->background_md5 = md5_file(path('public') . 'resources/default/background.png'); } else { if (Config::get('solder.use_s3')) { $response['background'] = Config::get('solder.s3_url') . 'resources/' . $modpack->slug . '/background.png?' . TimeUtils::getTimestampDate($modpack->updated_at); } else { $response['background'] = $resourcePath . "/background.png"; } } } $response['background_md5'] = $modpack->background_md5; $response['recommended'] = $modpack->recommended; $response['latest'] = $modpack->latest; $response['builds'] = array(); foreach ($modpack->builds as $build) { if ($build->is_published) { if (!$build->private) { array_push($response['builds'], $build->version); } else { if (isset($this->client)) { foreach ($this->client->modpacks as $pmodpack) { if ($modpack->id == $pmodpack->id) { array_push($response['builds'], $build->version); } } } } } } return $response; }