public function getAliases($version, $slug) { $modpack = Modpack::where('slug', '=', $slug)->first(); $modpack_aliases = $modpack->aliases; $title = 'Add A Modpack Alias - ' . $this->site_name; return View::make('modpackaliases.view', ['chosen' => true, 'title' => $title, 'aliases' => $modpack_aliases, 'modpack' => $modpack]); }
public function testModpackDeletePost() { $modpack = Modpack::where('slug', '=', 'testmodpack2')->firstOrFail(); $this->call('POST', '/modpack/delete/' . $modpack->id); $this->assertRedirectedTo('/modpack/list'); $this->assertSessionHas('success'); }
private function fetchBuild($slug, $build) { $response = array(); if (Cache::has('modpack.' . $slug) && empty($this->client) && empty($this->key)) { $modpack = Cache::Get('modpack.' . $slug); } else { $modpack = Modpack::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"); } $buildpass = $build; if (Cache::has('modpack.' . $slug . '.build.' . $build) && empty($this->client) && empty($this->key)) { $build = Cache::get('modpack.' . $slug . '.build.' . $build); } else { $build = Build::with('Modversions')->where("modpack_id", "=", $modpack->id)->where("version", "=", $build)->first(); if (empty($this->client) && empty($this->key)) { Cache::put('modpack.' . $slug . '.build.' . $buildpass, $build, 5); } } if (empty($build)) { return array("error" => "Build does not exist"); } $response['minecraft'] = $build->minecraft; $response['minecraft_md5'] = $build->minecraft_md5; $response['java'] = $build->min_java; $response['memory'] = $build->min_memory; $response['forge'] = $build->forge; $response['mods'] = array(); if (!Input::has('include')) { if (Cache::has('modpack.' . $slug . '.build.' . $buildpass . 'modversion') && empty($this->client) && empty($this->key)) { $response['mods'] = Cache::get('modpack.' . $slug . '.build.' . $buildpass . 'modversion'); } else { foreach ($build->modversions as $modversion) { $response['mods'][] = array("name" => $modversion->mod->name, "version" => $modversion->version, "md5" => $modversion->md5, "url" => Config::get('solder.mirror_url') . 'mods/' . $modversion->mod->name . '/' . $modversion->mod->name . '-' . $modversion->version . '.zip'); } usort($response['mods'], function ($a, $b) { return strcasecmp($a['name'], $b['name']); }); Cache::put('modpack.' . $slug . '.build.' . $buildpass . 'modversion', $response['mods'], 5); } } else { if (Input::get('include') == "mods") { if (Cache::has('modpack.' . $slug . '.build.' . $buildpass . 'modversion.include.mods') && empty($this->client) && empty($this->key)) { $response['mods'] = Cache::get('modpack.' . $slug . '.build.' . $buildpass . 'modversion.include.mods'); } else { foreach ($build->modversions as $modversion) { $response['mods'][] = array("name" => $modversion->mod->name, "version" => $modversion->version, "md5" => $modversion->md5, "pretty_name" => $modversion->mod->pretty_name, "author" => $modversion->mod->author, "description" => $modversion->mod->description, "link" => $modversion->mod->link, "donate" => $modversion->mod->donatelink, "url" => Config::get('solder.mirror_url') . 'mods/' . $modversion->mod->name . '/' . $modversion->mod->name . '-' . $modversion->version . '.zip'); } usort($response['mods'], function ($a, $b) { return strcasecmp($a['name'], $b['name']); }); Cache::put('modpack.' . $slug . '.build.' . $buildpass . 'modversion.include.mods', $response['mods'], 5); } } else { $request = explode(",", Input::get('include')); if (Cache::has('modpack.' . $slug . '.build.' . $buildpass . 'modversion.include.' . $request) && empty($this->client) && empty($this->key)) { $response['mods'] = Cache::get('modpack.' . $slug . '.build.' . $buildpass . 'modversion.include.' . $request); } else { foreach ($build->modversions as $modversion) { $data = array("name" => $modversion->mod->name, "version" => $modversion->version, "md5" => $modversion->md5); $mod = (array) $modversion->mod; $mod = $mod['attributes']; foreach ($request as $type) { if (isset($mod[$type])) { $data[$type] = $mod[$type]; } } $response['mods'][] = $data; } usort($response['mods'], function ($a, $b) { return strcasecmp($a['name'], $b['name']); }); Cache::put('modpack.' . $slug . '.build.' . $buildpass . 'modversion.include.' . $request, $response['mods'], 5); } } } return $response; }
public function getModpackSearch($version) { $modpack_id_array = []; $modpacks_array = []; $input = Input::only('mods', 'tags'); if ($version == 'all') { $modpack = Modpack::where('id', '!=', '0'); //there has to be a better way } else { $version_name = $this->getVersion($version); $minecraft_version = MinecraftVersion::where('name', $version_name)->first(); $modpack = Modpack::where('minecraft_version_id', $minecraft_version->id); } if ($input['mods']) { $input_mod_array = explode(',', $input['mods']); foreach ($input_mod_array as $mod) { $modpack->whereHas('mods', function ($q) use($mod) { $q->where('mods.id', '=', $mod); }); } } if ($input['tags']) { $input_tags_array = explode(',', $input['tags']); foreach ($input_tags_array as $tag) { $modpack->whereHas('tags', function ($q) use($tag) { $q->where('modpack_tags.id', '=', $tag); }); } } $modpacks = $modpack->with('creators')->with('launcher')->with('version')->get(); foreach ($modpacks as $modpack) { if (in_array($modpack->id, $modpack_id_array)) { continue; } $modpacks_array[] = $this->buildModpackArray($modpack); } return $this->buildDTModpackOutput($modpacks_array); }
public function getServers($modpack_slug = null) { $query_array = []; $selected_tags = []; $selected_country = false; $selected_permission = false; $selected_modpack = $modpack_slug; $modpack_line = 'for all Modpacks, '; $tag_line = 'with any tags, '; $country_line = 'in any country, '; $permission_line = 'and with any permission.'; $permissions_array = ['whitelist' => "Whitelist", 'greylist' => "Greylist", 'open' => "Open"]; $id_permissions_array = ['whitelist' => 1, 'greylist' => 2, 'open' => 3]; $input = Input::only('tags', 'country', 'permission'); $countries = Server::countryList(); $tags = ServerTag::all(); $table_javascript = route('tdf', ['servers', 'all']); if (!$modpack_slug) { $title = 'Modded Minecraft Servers - ' . $this->site_name; $meta_description = 'Modded Minecraft servers for all the packs we list. With powerful searching and filtering.'; $modpack_name = null; } else { $modpack = Modpack::where('slug', $modpack_slug)->first(); if (!$modpack) { return Redirect::to(action('ServerController@getServers')); } $title = $modpack->name . ' Servers - ' . $this->site_name; $meta_description = 'Minecraft Servers for the ' . $modpack->name . ' modpack. With powerful searching and filtering.'; $modpack_name = $modpack->name; $modpack_line = 'for ' . $modpack->name . ', '; $query_array[] = 'modpack=' . $modpack->id; } if ($input['tags']) { $tags_array = []; $tag_names = []; $tags_javascript_string = ''; $tag_line = 'including the tags '; foreach ($tags as $t) { $tags_array[$t->slug] = $t->id; $tag_names[$t->slug] = $t->name; } $exploded_tags = explode(',', strtolower($input['tags'])); foreach ($exploded_tags as $t) { if (array_key_exists($t, $tags_array)) { $tags_javascript_string .= $tags_array[$t] . ','; $selected_tags[] = $t; $tag_line .= $tag_names[$t] . ', '; } } $tag_line = rtrim($tag_line, ', ') . ', '; $query_array[] = 'tags=' . rtrim($tags_javascript_string, ','); } if ($input['country']) { $country_code = $input['country']; $query_array[] = 'country=' . $country_code; $selected_country = $country_code; $country_line = 'in ' . $countries[$country_code] . ', '; } if ($input['permission']) { $permission = $input['permission']; $query_array[] = 'permission=' . $id_permissions_array[$permission]; $selected_permission = $input['permission']; $permission_line = 'and with ' . strtolower($permissions_array[$permission]) . ' permissions.'; } $query_count = 0; foreach ($query_array as $q) { if ($query_count == 0) { $table_javascript .= '?'; } else { $table_javascript .= '&'; } $table_javascript .= $q; $query_count++; } $display_line = 'Displaying servers ' . $modpack_line . $tag_line . $country_line . $permission_line; return View::make('servers.list', ['title' => $title, 'meta_description' => $meta_description, 'table_javascript' => $table_javascript, 'modpack_name' => $modpack_name, 'countries' => $countries, 'chosen' => true, 'permissions' => $permissions_array, 'selected_tags' => $selected_tags, 'selected_country' => $selected_country, 'selected_permission' => $selected_permission, 'selected_modpack' => $selected_modpack, 'display_line' => $display_line]); }
public function getModpack($version, $slug) { $mods_javascript = route('tdf_name', ['modpackmods', $version, $slug]); $friendly_version = $this->getVersion($version); $modpack = Modpack::where('slug', '=', $slug)->first(); if (!$modpack) { $redirect = new URLRedirect(); $do_redirect = $redirect->getRedirect(Request::path()); if ($do_redirect) { return Redirect::to($do_redirect->target, 301); } App::abort(404); } $can_edit = false; $has_servers = false; if (Auth::check()) { $maintainer = $modpack->maintainers()->where('user_id', Auth::id())->first(); if ($maintainer) { $can_edit = true; } } $launcher = $modpack->launcher; $creators = $modpack->creators; $creators_formatted = implode(', ', array_map(function ($creator) { return $creator['name']; }, $creators->toArray())); $pack_code = $modpack->code; $tags = $modpack->tags; $tags_formatted = implode(', ', array_map(function ($tag) { return link_to(action('SearchController@getModpackSearch') . '?tag=' . $tag['slug'], $tag['name'], ['title' => $tag['deck']]); }, $tags->toArray())); $server_count = $modpack->servers()->where('active', 1)->count(); $twitch_streams = $modpack->twitchStreams()->orderBy('viewers', 'desc')->get(); $lets_plays = $modpack->youtubeVideos()->where('category_id', 1)->get(); if ($server_count > 0) { $has_servers = true; } $server_javascript = route('tdf', ['servers', 'all']) . '?modpack=' . $modpack->id; $raw_links = ['website' => $modpack->website, 'download_link' => $modpack->download_link, 'donate_link' => $modpack->donate_link, 'wiki_link' => $modpack->wiki_link]; $links = []; foreach ($raw_links as $index => $link) { if (!empty($link)) { $links[] = ['type' => $index, 'link' => $link]; } } $links_formatted = implode(' | ', array_map(function ($link) { if ($link['type'] == 'website') { return "<a href='{$link['link']}'><i class='fa fa-external-link'></i>Website</a>"; } if ($link['type'] == 'download_link') { return "<a href='{$link['link']}'><i class='fa fa-download'></i>Download</a>"; } if ($link['type'] == 'donate_link') { return "<a href='{$link['link']}'><i class='fa fa-dollar'></i>Donate</a>"; } if ($link['type'] == 'wiki_link') { return "<a href='{$link['link']}'><i class='fa fa-book'></i>Wiki</a>"; } return ''; }, $links)); $table_javascript = [$mods_javascript, $server_javascript]; $markdown_html = Parsedown::instance()->setBreaksEnabled(true)->text(strip_tags($modpack->description)); $modpack_description = str_replace('<table>', '<table class="table table-striped table-bordered">', $markdown_html); $title = $modpack->name . ' - ' . $friendly_version . ' Modpack - ' . $this->site_name; $meta_description = $modpack->deck; return View::make('modpacks.detail', ['table_javascript' => $table_javascript, 'modpack' => $modpack, 'modpack_description' => $modpack_description, 'links' => $links, 'links_formatted' => $links_formatted, 'launcher' => $launcher, 'creators' => $creators, 'creators_formatted' => $creators_formatted, 'tags' => $tags, 'tags_formatted' => $tags_formatted, 'servers' => $has_servers, 'title' => $title, 'meta_description' => $meta_description, 'pack_code' => $pack_code, 'version' => $version, 'twitch_streams' => $twitch_streams, 'lets_plays' => $lets_plays, 'has_servers' => $has_servers, 'can_edit' => $can_edit, 'sticky_tabs' => true]); }
private function getModpacks() { $modpacks_yml = file_get_contents(Config::get('solder.repo_location') . 'modpacks.yml'); $modpacks = Spyc::YAMLLoad($modpacks_yml); $modpacks = $modpacks['modpacks']; $blocked_packs = array('technicssp', 'custom1', 'custom2', 'custom3'); foreach ($modpacks as $key => $name) { if (!in_array($key, $blocked_packs)) { $modpack = Modpack::where('slug', '=', $key)->first(); if (empty($modpack)) { $modpack = new Modpack(); $modpack->name = $name; $modpack->slug = $key; $modpack->save(); } if (!$this->getModpack($modpack)) { return Response::json(array("error" => "Error grabbing data for " . $modpack->name)); } } } }