Exemplo n.º 1
0
 public function getMods($version = 'all')
 {
     $mods = [];
     $limit = 100;
     $offset = 0;
     $input = Input::only('limit', 'offset');
     if ($input['limit']) {
         $limit = $input['limit'];
     }
     if ($input['offset']) {
         $offset = $input['offset'];
     }
     if ($version == 'all') {
         $raw_mods = Mod::select('id', 'name', 'deck', 'website', 'download_link', 'wiki_link', 'description', 'slug', 'created_at', 'updated_at')->skip($offset)->take($limit)->get();
         $mod_count = Mod::select('id')->count();
     } else {
         $version = $this->getVersion($version);
         $raw_version = MinecraftVersion::where('name', '=', $version)->first();
         $version_id = $raw_version->id;
         if (!$raw_version) {
             return Response::json(['error' => 'Not a valid version.']);
         }
         $query = Mod::whereHas('versions', function ($q) use($version_id) {
             $q->where('minecraft_versions.id', '=', $version_id);
         });
         $mod_count = $query->count();
         $query->skip($offset)->take($limit);
         $raw_mods = $query->get();
     }
     if (!$raw_mods) {
         return Response::json(['error' => 'No results.']);
     }
     foreach ($raw_mods as $mod) {
         $mods['results'][] = ['id' => $mod->id, 'name' => $mod->name, 'short_description' => $mod->deck, 'website' => $mod->website, 'download_link' => $mod->download_link, 'donate_link' => $mod->website, 'wiki_link' => $mod->wiki_link, 'description' => $mod->description, 'slug' => $mod->slug, 'created_at' => $mod->created_at, 'updated_at' => $mod->updated_at];
     }
     $mods['meta'] = ['total_results' => $mod_count, 'limit' => $limit, 'offset' => $offset];
     return Response::json($mods);
 }
Exemplo n.º 2
0
 public function getModpackSearch()
 {
     $results = false;
     $query_array = [];
     $mod_select_array = [];
     $version_select = [];
     $selected_mods = [];
     $selected_tags = [];
     $url_version = 'all';
     $title = 'Modpack Finder - ' . $this->site_name;
     $meta_description = 'Find and discover amazing modpacks. Refine your search for packs that include specific mods and tags.';
     $input = Input::only('tag', 'tags', 'mods', 'version');
     $minecraft_versions = MinecraftVersion::where('name', '!=', '1.8')->get();
     $tags = ModpackTag::all();
     foreach ($minecraft_versions as $v) {
         $version_slug = $this->getVersionSlug($v->name);
         $version_select[$version_slug] = $v->name;
     }
     if ($input['version'] && $input['version'] != 'all') {
         $results = true;
         $url_version = $input['version'];
         $version = $this->getVersion($url_version);
         $minecraft_version = MinecraftVersion::where('name', $version)->first();
         $mods = $minecraft_version->mods;
         foreach ($mods as $mod) {
             $id = $mod->id;
             $mod_select_array[$id] = $mod->name;
         }
         if ($input['mods']) {
             $mods_string = '';
             $exploded_mods = explode(',', strtolower($input['mods']));
             foreach ($exploded_mods as $mod) {
                 $mods_string .= $mod . ',';
                 $selected_mods[] = $mod;
             }
             $query_array[] = 'mods=' . rtrim($mods_string, ',');
         }
     }
     if ($input['version'] == 'all') {
         $results = true;
     }
     if ($input['tags']) {
         $tags_array = [];
         $tags_javascript_string = '';
         foreach ($tags as $t) {
             $tags_array[$t->slug] = $t->id;
         }
         $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;
             }
         }
         $query_array[] = 'tags=' . rtrim($tags_javascript_string, ',');
     }
     if ($input['tag']) {
         $tag = ModpackTag::where('slug', $input['tag'])->first();
         if (!$tag) {
             return Redirect::action('SearchController@getModpackSearch');
         }
         $title = $tag->name . ' Modpacks - Pack Finder - ' . $this->site_name;
         $meta_description = 'Find and discover ' . $tag->name . ' Modpacks. Refine your search for packs that include specific mods.';
         $selected_tags[] = $tag->slug;
         $query_array[] = 'tags=' . $tag->id;
     }
     $table_javascript = route('tdf', ['modpackfinder', $url_version]);
     $query_count = 0;
     foreach ($query_array as $q) {
         if ($query_count == 0) {
             $table_javascript .= '?';
         } else {
             $table_javascript .= '&';
         }
         $table_javascript .= $q;
         $results = true;
         $query_count++;
     }
     return View::make('search.modpack', ['chosen' => true, 'title' => $title, 'results' => $results, 'table_javascript' => $table_javascript, 'mods' => $mod_select_array, 'selected_mods' => $selected_mods, 'selected_tags' => $selected_tags, 'selected_version' => $input['version'], 'version_select' => $version_select, 'url_version' => $url_version, 'search_javascript' => true, 'meta_description' => $meta_description]);
 }
Exemplo n.º 3
0
 public function getServer($id, $slug)
 {
     $server = Server::find($id);
     $countries = Server::countryList();
     if (!$server) {
         return Redirect::action('ServerController@getServers', [], 301);
     }
     if ($slug != $server->slug) {
         return Redirect::action('ServerController@getServer', [$server->id, $server->slug], 301);
     }
     $can_edit = false;
     if (Auth::check()) {
         if (Auth::id() == $server->user_id) {
             $can_edit = true;
         }
     }
     $mods_javascript = route('tdf', ['servermods', 'all']) . '?id=' . $server->id;
     $players_javascript = route('tdf', ['serverplayers', 'all']) . '?id=' . $server->id;
     $table_javascript = [$mods_javascript, $players_javascript];
     $raw_links = ['website' => $server->website, 'application_url' => $server->application_url];
     $links = [];
     foreach ($raw_links as $index => $link) {
         if ($link != '') {
             $links["{$index}"] = $link;
         }
     }
     $tags = $server->tags;
     $status = $server->status;
     $modpack = $server->modpack;
     $version = MinecraftVersion::where('id', $modpack->minecraft_version_id)->first();
     $version_slug = preg_replace('/\\./', '-', $version->name);
     $country_name = $countries[$server->country];
     $country_code = strtolower($server->country);
     $markdown_html = Parsedown::instance()->setBreaksEnabled(true)->text(strip_tags($server->description));
     $description = str_replace('<table>', '<table class="table table-striped table-bordered">', $markdown_html);
     if ($server->last_world_reset == '0000-00-00') {
         $server->last_world_reset = null;
     }
     if ($server->next_world_reset == '0000-00-00') {
         $server->next_world_reset = null;
     }
     $title = $server->name . ' - ' . $modpack->name . ' Server - ' . $this->site_name;
     $meta_description = $server->deck;
     return View::make('servers.detail', ['server' => $server, 'status' => $status, 'tags' => $tags, 'links' => $links, 'modpack' => $modpack, 'version' => $version, 'version_slug' => $version_slug, 'country_code' => $country_code, 'country_name' => $country_name, 'description' => $description, 'can_edit' => $can_edit, 'title' => $title, 'meta_description' => $meta_description, 'table_javascript' => $table_javascript]);
 }
Exemplo n.º 4
0
 public function getModsSelect($version)
 {
     $version = $this->getVersion($version);
     $sort_array = [];
     $mods_array = [];
     $raw_version = MinecraftVersion::where('name', '=', $version)->first();
     $raw_mods = $raw_version->mods;
     foreach ($raw_mods as $mod) {
         $mod_id = $mod->id;
         $sort_array[$mod_id] = $mod->name;
     }
     natcasesort($sort_array);
     foreach ($sort_array as $k => $mod) {
         $mods_array[] = ['name' => $mod, 'value' => $k];
     }
     return Response::json($mods_array);
 }
Exemplo n.º 5
0
 public function postEdit($id)
 {
     $mod_select_array = [];
     $selected_mods = [];
     $selected_tags = [];
     $selected_creators = [];
     $selected_maintainers = [];
     $can_edit_maintainers = false;
     $title = 'Edit A Modpack - ' . $this->site_name;
     $modpack = Modpack::find($id);
     if (Auth::check()) {
         $maintainer = $modpack->maintainers()->where('user_id', Auth::id())->first();
         if (!$maintainer) {
             if ($this->checkRoute()) {
                 $can_edit_maintainers = true;
             } else {
                 return Redirect::route('index');
             }
         }
     } else {
         return Redirect::route('index');
     }
     $minecraft_version = MinecraftVersion::where('id', '=', $modpack->minecraft_version_id)->first();
     $creators = $modpack->creators;
     $mods = $modpack->mods;
     $tags = $modpack->tags;
     $maintainers = $modpack->maintainers;
     $input = Input::only('name', 'launcher', 'selected_mods', 'selected_creators', 'selected_tags', 'selected_maintainers', 'deck', 'website', 'download_link', 'donate_link', 'wiki_link', 'description', 'slug');
     $messages = ['unique' => 'This modpack already exists in the database. If it requires an update let us know!', 'url' => 'The :attribute field is not a valid URL.'];
     $validator = Validator::make($input, ['name' => 'required|unique:modpacks,name,' . $modpack->id, 'launcher' => 'required', 'selected_mods' => 'required', 'selected_creators' => 'required', 'deck' => 'required', 'website' => 'url', 'download_url' => 'url', 'wiki_url' => 'url', 'donate_link' => 'url'], $messages);
     if ($validator->fails()) {
         return Redirect::action('ModController@getEdit', [$modpack->id])->withErrors($validator)->withInput();
     }
     $modpack->name = $input['name'];
     $modpack->launcher_id = $input['launcher'];
     $modpack->deck = $input['deck'];
     $modpack->website = $input['website'];
     $modpack->download_link = $input['download_link'];
     $modpack->donate_link = $input['donate_link'];
     $modpack->wiki_link = $input['wiki_link'];
     $modpack->description = $input['description'];
     if ($input['slug'] == '' || $input['slug'] == $modpack->slug) {
         $slug = Str::slug($input['name']);
     } else {
         $slug = $input['slug'];
     }
     $modpack->slug = $slug;
     $modpack->last_ip = Request::getClientIp();
     $success = $modpack->save();
     if ($success) {
         foreach ($creators as $c) {
             $modpack->creators()->detach($c->id);
         }
         $modpack->creators()->attach($input['selected_creators']);
         foreach ($mods as $m) {
             $modpack->mods()->detach($m->id);
         }
         $modpack->mods()->attach($input['selected_mods']);
         foreach ($tags as $t) {
             $modpack->tags()->detach($t->id);
         }
         if ($input['selected_tags']) {
             $modpack->tags()->attach($input['selected_tags']);
         }
         if ($can_edit_maintainers) {
             foreach ($maintainers as $m) {
                 $modpack->maintainers()->detach($m->id);
             }
             if ($input['selected_maintainers']) {
                 $modpack->maintainers()->attach($input['selected_maintainers']);
             }
         }
         $version_mods = $minecraft_version->mods;
         $updated_modpack = Modpack::find($modpack->id);
         foreach ($updated_modpack->mods as $m) {
             $selected_mods[] = $m->id;
         }
         foreach ($updated_modpack->tags as $t) {
             $selected_tags[] = $t->id;
         }
         foreach ($updated_modpack->creators as $c) {
             $selected_creators[] = $c->id;
         }
         foreach ($updated_modpack->maintainers as $m) {
             $selected_maintainers[] = $m->id;
         }
         foreach ($version_mods as $mod) {
             $id = $mod->id;
             $mod_select_array[$id] = $mod->name;
         }
         foreach ($mods as $mod) {
             $id = $mod->id;
             $mod_select_array[$id] = $mod->name;
         }
         Cache::tags('modpacks')->flush();
         Cache::tags('modpackmods')->flush();
         Cache::tags('modmodpacks')->flush();
         Queue::push('BuildCache');
         return View::make('modpacks.edit', ['title' => $title, 'chosen' => true, 'success' => true, 'modpack' => $updated_modpack, 'version' => $minecraft_version->name, 'mods' => $mod_select_array, 'selected_mods' => $selected_mods, 'selected_creators' => $selected_creators, 'selected_tags' => $selected_tags, 'selected_maintainers' => $selected_maintainers, 'can_edit_maintainers' => $can_edit_maintainers]);
     }
     return Redirect::action('ModController@getEdit', [$modpack->id])->withErrors(['message' => 'Unable to edit modpack.'])->withInput();
 }