public function getMod($slug) { $table_javascript = route('tdf_name', ['modmodpacks', '0', $slug]); $mod = Mod::where('slug', '=', $slug)->first(); if (!$mod) { $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; if (Auth::check()) { $maintainer = $mod->maintainers()->where('user_id', Auth::id())->first(); if ($maintainer) { $can_edit = true; } } $authors = $mod->authors; $spotlights = $mod->youtubeVideos()->where('category_id', 2)->get(); $tutorials = $mod->youtubeVideos()->where('category_id', 3)->get(); $raw_links = ['website' => $mod->website, 'download_link' => $mod->download_link, 'donate_link' => $mod->donate_link, 'wiki_link' => $mod->wiki_link]; $links = []; foreach ($raw_links as $index => $link) { if ($link != '') { $links["{$index}"] = $link; } } $markdown_html = Parsedown::instance()->setBreaksEnabled(true)->text(strip_tags($mod->description)); $mod_description = str_replace('<table>', '<table class="table table-striped table-bordered">', $markdown_html); $title = $mod->name . ' - Mod - ' . $this->site_name; $meta_description = $mod->deck; return View::make('mods.detail', ['table_javascript' => $table_javascript, 'mod' => $mod, 'mod_description' => $mod_description, 'links' => $links, 'authors' => $authors, 'title' => $title, 'meta_description' => $meta_description, 'sticky_tabs' => true, 'spotlights' => $spotlights, 'tutorials' => $tutorials, 'can_edit' => $can_edit]); }
public function testModDeletePost() { $modpack = Mod::where('name', '=', 'testmod2')->firstOrFail(); $this->call('POST', '/mod/delete/' . $modpack->id); $this->assertRedirectedTo('/mod/list'); $this->assertSessionHas('success'); }
public function getMod($mod = null, $version = null) { if (empty($mod)) { return Response::json(array("error" => "No mod requested")); } if (Cache::has('mod.' . $mod)) { $mod = Cache::get('mod.' . $mod); } else { $modname = $mod; $mod = Mod::where('name', '=', $mod)->first(); Cache::put('mod.' . $modname, $mod, 5); } if (empty($mod)) { return Response::json(array('error' => 'Mod does not exist')); } if (empty($version)) { return Response::json($this->fetchMod($mod)); } return Response::json($this->fetchModversion($mod, $version)); }
public function getMod($mod = null, $version = null) { // begin northpl changes /*if (empty($mod)) return Response::json(array("error" => "No mod requested"));*/ //NorthPL -> allow to fetch mods by API if (empty($mod)) { return $this->fetchMods(); } // end northpl changes if (Cache::has('mod.' . $mod)) { $mod = Cache::get('mod.' . $mod); } else { $modname = $mod; $mod = Mod::where('name', '=', $mod)->first(); Cache::put('mod.' . $modname, $mod, 5); } if (empty($mod)) { return Response::json(array('error' => 'Mod does not exist')); } if (empty($version)) { return Response::json($this->fetchMod($mod)); } return Response::json($this->fetchModversion($mod, $version)); }
public function getMod($mod = null, $version = null) { if (empty($mod)) { if (Cache::has('modlist') && empty($this->client) && empty($this->key)) { $response['mods'] = Cache::get('modlist'); } else { foreach (Mod::all() as $mod) { $response['mods'][$mod->name] = $mod->pretty_name; } //usort($response['mod'], function($a, $b){return strcasecmp($a['name'], $b['name']);}); Cache::put('modlist', $response['mods'], 5); } return Response::json($response); } else { if (Cache::has('mod.' . $mod)) { $mod = Cache::get('mod.' . $mod); } else { $modname = $mod; $mod = Mod::where('name', '=', $mod)->first(); Cache::put('mod.' . $modname, $mod, 5); } if (empty($mod)) { return Response::json(array('error' => 'Mod does not exist')); } if (empty($version)) { return Response::json($this->fetchMod($mod)); } return Response::json($this->fetchModversion($mod, $version)); } }
/** * AJAX Methods for Modpack Manager **/ public function action_modify($action = null) { if (empty($action)) { return Response::error('500'); } switch ($action) { case "version": $affected = DB::table('build_modversion')->where('id', '=', Input::get('pivot_id'))->update(array('modversion_id' => Input::get('version'))); return Response::json(array('success' => 'Rows Affected: ' . $affected)); break; case "delete": $affected = DB::table('build_modversion')->where('id', '=', Input::get('pivot_id'))->delete(); return Response::json(array('success' => 'Rows Affected: ' . $affected)); break; case "add": $build = Build::find(Input::get('build')); $mod = Mod::where('name', '=', Input::get('mod-name'))->first(); $ver = ModVersion::where('mod_id', '=', $mod->id)->where('version', '=', Input::get('mod-version'))->first(); $build->modversions()->attach($ver->id); return Response::json(array('pretty_name' => $mod->pretty_name, 'version' => $ver->version)); break; case "recommended": $modpack = Modpack::find(Input::get('modpack')); $new_version = Input::get('recommended'); $modpack->recommended = $new_version; $modpack->save(); return Response::json(array("success" => "Updated " . $modpack->name . "'s recommended build to " . $new_version, "version" => $new_version)); break; case "latest": $modpack = Modpack::find(Input::get('modpack')); $new_version = Input::get('latest'); $modpack->latest = $new_version; $modpack->save(); return Response::json(array("success" => "Updated " . $modpack->name . "'s latest build to " . $new_version, "version" => $new_version)); break; case "published": $build = Build::find(Input::get('build')); $published = Input::get('published'); $build->is_published = $published ? true : false; $build->save(); return Response::json(array("success" => "Updated build " . $build->version . "'s published status.")); } }
/** * AJAX Methods for Modpack Manager **/ public function anyModify($action = null) { if (!Request::ajax()) { return Response::view('errors.missing', array(), 404); } if (empty($action)) { return Response::view('errors.500', array(), 500); } switch ($action) { case "version": $version_id = Input::get('version'); $modversion_id = Input::get('modversion_id'); $affected = DB::table('build_modversion')->where('build_id', '=', Input::get('build_id'))->where('modversion_id', '=', $modversion_id)->update(array('modversion_id' => $version_id)); if ($affected == 0) { if ($modversion_id != $version_id) { $status = 'failed'; } else { $status = 'aborted'; } } else { $status = 'success'; } return Response::json(array('status' => $status, 'reason' => 'Rows Affected: ' . $affected)); break; case "delete": $affected = DB::table('build_modversion')->where('build_id', '=', Input::get('build_id'))->where('modversion_id', '=', Input::get('modversion_id'))->delete(); $status = 'success'; if ($affected == 0) { $status = 'failed'; } return Response::json(array('status' => $status, 'reason' => 'Rows Affected: ' . $affected)); break; case "add": $build = Build::find(Input::get('build')); $mod = Mod::where('name', '=', Input::get('mod-name'))->first(); $ver = Modversion::where('mod_id', '=', $mod->id)->where('version', '=', Input::get('mod-version'))->first(); $affected = DB::table('build_modversion')->where('build_id', '=', $build->id)->where('modversion_id', '=', $ver->id)->get(); $duplicate = !empty($affected); if ($duplicate) { return Response::json(array('status' => 'failed', 'reason' => 'Duplicate Modversion found')); } else { $build->modversions()->attach($ver->id); return Response::json(array('status' => 'success', 'pretty_name' => $mod->pretty_name, 'version' => $ver->version)); } break; case "recommended": $modpack = Modpack::find(Input::get('modpack')); $new_version = Input::get('recommended'); $modpack->recommended = $new_version; $modpack->save(); Cache::forget('modpack.' . $modpack->slug); return Response::json(array("success" => "Updated " . $modpack->name . "'s recommended build to " . $new_version, "version" => $new_version)); break; case "latest": $modpack = Modpack::find(Input::get('modpack')); $new_version = Input::get('latest'); $modpack->latest = $new_version; $modpack->save(); Cache::forget('modpack.' . $modpack->slug); return Response::json(array("success" => "Updated " . $modpack->name . "'s latest build to " . $new_version, "version" => $new_version)); break; case "published": $build = Build::find(Input::get('build')); $published = Input::get('published'); $build->is_published = $published ? true : false; $build->save(); return Response::json(array("success" => "Updated build " . $build->version . "'s published status.")); case "private": $build = Build::find(Input::get('build')); $private = Input::get('private'); $build->private = $private ? true : false; $build->save(); return Response::json(array("success" => "Updated build " . $build->version . "'s private status.")); } }
public function getModModpacks($name) { $cache_key = 'table-modmodpacks-' . $name; if (Cache::tags('modmodpacks')->has($cache_key)) { $modpacks_array = Cache::tags('modmodpacks')->get($cache_key); } else { $modpack_id_array = []; $modpacks_array = []; $mod = Mod::where('slug', '=', $name)->first(); $modpacks = $mod->modpacks()->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); $modpack_id_array[] = $modpack->id; } Cache::tags('modmodpacks')->forever($cache_key, $modpacks_array); } return $this->buildDTModpackOutput($modpacks_array); }
private function getBuildMods($build, $mods) { $version_ids = array(); foreach ($mods as $name => $version) { $mod = Mod::where('name', '=', $name)->first(); if (!empty($mod)) { $version = ModVersion::where('mod_id', '=', $mod->id)->where('version', '=', $version)->first(); if (!empty($version)) { array_push($version_ids, $version->id); } } else { Log::write("Notice", "Mod with name " . $name . " does not exist in ModLibrary."); } } $build->modversions()->sync($version_ids); return true; }