Ejemplo n.º 1
0
 private function getMods()
 {
     $library_yml = file_get_contents(Config::get('solder.repo_location') . 'modlibrary.yml');
     $library = Spyc::YAMLLoad($library_yml);
     foreach ($library['mods'] as $name => $data) {
         try {
             $mod = Mod::where('name', '=', $name)->first();
             if (empty($mod)) {
                 $mod = new Mod();
                 $mod->name = $name;
                 if (isset($data['name'])) {
                     $mod->pretty_name = $data['name'];
                 }
                 if (isset($data['description'])) {
                     $mod->description = $data['description'];
                 }
                 if (isset($data['link'])) {
                     $mod->link = $data['link'];
                 }
                 if (isset($data['author'])) {
                     $mod->author = $data['author'];
                 }
             } else {
                 if (isset($data['name'])) {
                     $mod->pretty_name = $data['name'];
                 }
                 if (isset($data['description'])) {
                     $mod->description = $data['description'];
                 } else {
                     $mod->description = "";
                 }
                 if (isset($data['link'])) {
                     $mod->link = $data['link'];
                 } else {
                     $mod->link = "";
                 }
                 if (isset($data['author'])) {
                     $mod->author = $data['author'];
                 } else {
                     $mod->author = "";
                 }
             }
             $mod->save();
             $this->getModVersions($mod, $data['versions']);
         } catch (Exception $e) {
             Log::exception($e);
         }
     }
 }
Ejemplo n.º 2
0
 public function postCreate()
 {
     $rules = array('name' => 'required|unique:mods', 'pretty_name' => 'required', 'link' => 'url', 'donatelink' => 'url');
     $messages = array('name.required' => 'You must fill in a mod slug name.', 'name.unique' => 'The slug you entered is already taken', 'pretty_name.required' => 'You must enter in a mod name', 'link.url' => 'You must enter a properly formatted Website', 'donatelink.url' => 'You must enter a proper formatted Donation Link');
     $validation = Validator::make(Input::all(), $rules, $messages);
     if ($validation->fails()) {
         return Redirect::to('mod/create')->withErrors($validation->messages());
     }
     $mod = new Mod();
     $mod->name = Str::slug(Input::get('name'));
     $mod->pretty_name = Input::get('pretty_name');
     $mod->author = Input::get('author');
     $mod->description = Input::get('description');
     $mod->link = Input::get('link');
     $mod->donatelink = Input::get('donatelink');
     $mod->save();
     return Redirect::to('mod/view/' . $mod->id);
 }
Ejemplo n.º 3
0
 public function action_do_create()
 {
     $rules = array('name' => 'required|unique:mods', 'pretty_name' => 'required');
     $messages = array('name_required' => 'You must fill in a mod slug name.', 'name_unique' => 'The slug you entered is already taken', 'pretty_name_required' => 'You must enter in a mod name');
     $validation = Validator::make(Input::all(), $rules, $messages);
     if ($validation->fails()) {
         return Redirect::back()->with_errors($validation->errors);
     }
     try {
         $mod = new Mod();
         $mod->name = Str::slug(Input::get('name'));
         $mod->pretty_name = Input::get('pretty_name');
         $mod->author = Input::get('author');
         $mod->description = Input::get('description');
         $mod->link = Input::get('link');
         $mod->save();
         return Redirect::to('mod/view/' . $mod->id);
     } catch (Exception $e) {
         Log::exception($e);
     }
 }
Ejemplo n.º 4
0
 /**
  * POST /api/$version/mod-reply/$id.
  *
  * @api
  *
  * @return json
  */
 public function postModReply($id)
 {
     $user = $this->user();
     if ($user) {
         try {
             $parent = Mod::findOrFail(Input::get('parent'));
         } catch (Exception $e) {
             return $this->error('missing', 'beatmaps.modding');
         }
         if ($parent->beatmapset_id != $id) {
             // someone is trying to be a twat
             return $this->error('access-denied', 'beatmaps.modding');
         }
         if (Input::has('comment')) {
             try {
                 $mod = new Mod(['user_id' => $user->user_id, 'parent_item_id' => $parent->item_id, 'text' => Input::get('comment'), 'beatmapset_id' => $parent->beatmapset_id]);
                 $mod->save();
                 if (Input::get('reply-type') == 'fix') {
                     // we need to resolve the parent comment
                     if (Auth::user()->canEditMod($parent)) {
                         $parent->resolve();
                     } else {
                         return $this->error('access-denied', 'beatmaps.modding');
                     }
                 }
             } catch (Exception $e) {
                 // this error will be sent to sentry.
                 return Config::get('app.debug') ? Response::json(['error' => $e->getMessage()]) : $this->error('unknown', 'beatmaps.modding');
             }
         } else {
             return $this->error('no-comment', 'beatmaps.modding');
         }
         return Response::json(['success' => Lang::get('beatmaps.modding.success.reply')]);
     } else {
         return $this->error('access-denied', 'beatmaps.modding');
     }
 }
Ejemplo n.º 5
0
 /**
  * POST /api/$version/mod-reply/$id
  *
  * @api
  * @return json
  */
 public function postModReply($id)
 {
     $user = $this->user();
     if ($user) {
         try {
             $parent = Mod::findOrFail(Input::get("parent"));
         } catch (Exception $e) {
             return $this->error("missing", "beatmaps.modding");
         }
         if ($parent->beatmapset_id != $id) {
             // someone is trying to be a twat
             return $this->error("access-denied", "beatmaps.modding");
         }
         if (Input::has("comment")) {
             try {
                 $mod = new Mod(["user_id" => $user->user_id, "parent_item_id" => $parent->item_id, "text" => Input::get("comment"), "beatmapset_id" => $parent->beatmapset_id]);
                 $mod->save();
                 if (Input::get("reply-type") == "fix") {
                     // we need to resolve the parent comment
                     if (Auth::user()->canEditMod($parent)) {
                         $parent->resolve();
                     } else {
                         return $this->error("access-denied", "beatmaps.modding");
                     }
                 }
             } catch (Exception $e) {
                 // this error will be sent to sentry.
                 return Config::get("app.debug") ? Response::json(["error" => $e->getMessage()]) : $this->error("unknown", "beatmaps.modding");
             }
         } else {
             return $this->error("no-comment", "beatmaps.modding");
         }
         return Response::json(["success" => Lang::get("beatmaps.modding.success.reply")]);
     } else {
         return $this->error("access-denied", "beatmaps.modding");
     }
 }
Ejemplo n.º 6
0
 public function postAdd()
 {
     if (!$this->checkRoute()) {
         return Redirect::route('index');
     }
     $versions = MinecraftVersion::all();
     $title = 'Add A Mod - ' . $this->site_name;
     $input = Input::only('name', 'versions', 'author', 'deck', 'website', 'download_link', 'donate_link', 'wiki_link', 'description', 'slug', 'mod_list_hide');
     $messages = ['unique' => 'This mod 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:mods,name', 'author' => 'required', 'versions' => 'required', 'deck' => 'required', 'website' => 'url', 'download_url' => 'url', 'wiki_url' => 'url', 'donate_link' => 'url'], $messages);
     if ($validator->fails()) {
         return Redirect::action('ModController@getAdd')->withErrors($validator)->withInput();
     }
     $mod = new Mod();
     $mod->name = $input['name'];
     $mod->deck = $input['deck'];
     $mod->website = $input['website'];
     $mod->download_link = $input['download_link'];
     $mod->donate_link = $input['donate_link'];
     $mod->wiki_link = $input['wiki_link'];
     $mod->description = $input['description'];
     if ($input['slug'] == '') {
         $slug = Str::slug($input['name']);
     } else {
         $slug = $input['slug'];
     }
     if ($input['mod_list_hide'] == 1) {
         $mod->mod_list_hide = 1;
     }
     $mod->slug = $slug;
     $mod->last_ip = Request::getClientIp();
     $success = $mod->save();
     if ($success) {
         foreach ($input['author'] as $author) {
             $mod->authors()->attach($author);
         }
         foreach ($input['versions'] as $version) {
             $mod->versions()->attach($version);
         }
         Cache::tags('mods')->flush();
         Queue::push('BuildCache');
         return View::make('mods.add', ['title' => $title, 'chosen' => true, 'success' => true, 'versions' => $versions]);
     }
     return Redirect::action('ModController@getAdd')->withErrors(['message' => 'Unable to add mod.'])->withInput();
 }
Ejemplo n.º 7
0
 public function postImportMod($import_id)
 {
     if (!$this->checkRoute()) {
         return Redirect::route('index');
     }
     $import_mod = Import::find($import_id);
     $versions = MinecraftVersion::all();
     $title = 'Import A Mod - ' . $this->site_name;
     $input = Input::only('name', 'selected_versions', 'selected_authors', 'deck', 'website', 'download_link', 'donate_link', 'wiki_link', 'description', 'slug', 'mod_list_hide');
     $messages = ['unique' => 'This mod 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:mods,name', 'selected_authors' => 'required', 'versions' => 'selected_versions', 'deck' => 'required', 'website' => 'url', 'download_url' => 'url', 'wiki_url' => 'url', 'donate_link' => 'url'], $messages);
     if ($validator->fails()) {
         return Redirect::action('ImportController@getImportMod', [$import_mod->id])->withErrors($validator)->withInput();
     }
     $mod = new Mod();
     $mod->name = $input['name'];
     $mod->deck = $input['deck'];
     $mod->website = $input['website'];
     $mod->download_link = $input['download_link'];
     $mod->donate_link = $input['donate_link'];
     $mod->wiki_link = $input['wiki_link'];
     $mod->description = $input['description'];
     if ($input['slug'] == '') {
         $slug = Str::slug($input['name']);
     } else {
         $slug = $input['slug'];
     }
     if ($input['mod_list_hide'] == 1) {
         $mod->mod_list_hide = 1;
     }
     $mod->slug = $slug;
     $mod->last_ip = Request::getClientIp();
     $success = $mod->save();
     if ($success) {
         foreach ($input['selected_authors'] as $author) {
             $mod->authors()->attach($author);
         }
         foreach ($input['selected_versions'] as $version) {
             $mod->versions()->attach($version);
         }
         Cache::tags('mods')->flush();
         Queue::push('BuildCache');
         $import_mod->status = 1;
         $import_mod->save();
         $raw_mcf_mods = ImportMCFModlist::orderBy('name', 'asc')->get();
         $raw_nem_mods = ImportNEM::orderBy('name', 'asc')->get();
         $mcf_mods_array[0] = 'None';
         $nem_mods_array[0] = 'None';
         foreach ($raw_mcf_mods as $mcf_mod) {
             $mcf_mod_id = $mcf_mod->id;
             $mcf_mods_array[$mcf_mod_id] = $mcf_mod->name;
         }
         foreach ($raw_nem_mods as $nem_mod) {
             $nem_mod_id = $nem_mod->id;
             $nem_mods_array[$nem_mod_id] = $nem_mod->name;
         }
         return View::make('imports.import', ['title' => $title, 'chosen' => true, 'success' => true, 'mcf_mods_array' => $mcf_mods_array, 'nem_mods_array' => $nem_mods_array, 'versions' => $versions]);
     }
     return Redirect::action('ImportController@getImportMod', [$import_mod->id])->withErrors(['message' => 'Unable to import mod.'])->withInput();
 }