public function action_do_create()
 {
     Validator::register('checkresources', function ($attribute, $value, $parameters) {
         if (FileUtils::check_resource($value, "logo_180.png") && FileUtils::check_resource($value, "icon.png") && FileUtils::check_resource($value, "background.jpg")) {
             return true;
         } else {
             return false;
         }
     });
     $rules = array('name' => 'required|unique:modpacks', 'slug' => 'required|checkresources|unique:modpacks');
     $messages = array('name_required' => 'You must enter a modpack name.', 'slug_required' => 'You must enter a modpack slug', 'slug_checkresources' => 'Make sure all the resources required exist before submitting a pack!');
     $validation = Validator::make(Input::all(), $rules, $messages);
     if ($validation->fails()) {
         return Redirect::back()->with_errors($validation->errors);
     }
     $url = Config::get('solder.repo_location') . Input::get('slug') . '/resources/';
     try {
         $modpack = new Modpack();
         $modpack->name = Input::get('name');
         $modpack->slug = Str::slug(Input::get('slug'));
         $modpack->icon_md5 = UrlUtils::get_remote_md5($url . 'icon.png');
         $modpack->logo_md5 = UrlUtils::get_remote_md5($url . 'logo_180.png');
         $modpack->background_md5 = UrlUtils::get_remote_md5($url . 'background.jpg');
         $modpack->save();
         return Redirect::to('modpack/view/' . $modpack->id);
     } catch (Exception $e) {
         Log::exception($e);
     }
 }
 public function postCreate()
 {
     $rules = array('name' => 'required|unique:modpacks', 'slug' => 'required|unique:modpacks');
     $messages = array('name_required' => 'You must enter a modpack name.', 'slug_required' => 'You must enter a modpack slug');
     $validation = Validator::make(Input::all(), $rules, $messages);
     if ($validation->fails()) {
         return Redirect::to('modpack/create')->withErrors($validation->messages());
     }
     $modpack = new Modpack();
     $modpack->name = Input::get('name');
     $modpack->slug = Str::slug(Input::get('slug'));
     $modpack->icon_md5 = md5_file(public_path() . '/resources/default/icon.png');
     $modpack->icon_url = URL::asset('/resources/default/icon.png');
     $modpack->logo_md5 = md5_file(public_path() . '/resources/default/logo.png');
     $modpack->logo_url = URL::asset('/resources/default/logo.png');
     $modpack->background_md5 = md5_file(public_path() . '/resources/default/background.jpg');
     $modpack->background_url = URL::asset('/resources/default/background.jpg');
     $modpack->save();
     /* Gives creator modpack perms */
     $user = Auth::User();
     $perm = $user->permission;
     $modpacks = $perm->modpacks;
     if (!empty($modpacks)) {
         Log::info($modpack->name . ': Attempting to add modpack perm to user - ' . $user->username . ' - Modpack perm not empty');
         $newmodpacks = array_merge($modpacks, array($modpack->id));
         $perm->modpacks = $newmodpacks;
     } else {
         Log::info($modpack->name . ': Attempting to add modpack perm to user - ' . $user->username . ' - Modpack perm empty');
         $perm->modpacks = array($modpack->id);
     }
     $perm->save();
     try {
         $useS3 = Config::get('solder.use_s3');
         if ($useS3) {
             $resourcePath = storage_path() . '/resources/' . $modpack->slug;
         } else {
             $resourcePath = public_path() . '/resources/' . $modpack->slug;
         }
         /* Create new resources directory for modpack */
         if (!file_exists($resourcePath)) {
             mkdir($resourcePath, 0775, true);
         }
     } catch (Exception $e) {
         Log::error($e);
         return Redirect::to('modpack/create')->withErrors($e->getMessage());
     }
     return Redirect::to('modpack/view/' . $modpack->id);
 }
 public function postAdd($version)
 {
     if (!$this->checkRoute()) {
         return Redirect::route('index');
     }
     $url_version = $version;
     $version = $this->getVersion($version);
     $title = 'Add A Modpack - ' . $this->site_name;
     $minecraft_version = MinecraftVersion::where('name', '=', $version)->first();
     $input = Input::only('name', 'launcher', 'mods', 'tags', 'creators', 'deck', 'website', 'download_link', 'donate_link', 'wiki_link', 'description', 'slug');
     $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:modpacks,name', 'launcher' => 'required', 'mods' => 'required', 'creators' => 'required', 'deck' => 'required', 'website' => 'url', 'download_url' => 'url', 'wiki_url' => 'url', 'donate_link' => 'url'], $messages);
     if ($validator->fails()) {
         return Redirect::action('ModpackController@getAdd', [$url_version])->withErrors($validator)->withInput();
     }
     $modpack = new Modpack();
     $modpack->name = $input['name'];
     $modpack->launcher_id = $input['launcher'];
     $modpack->minecraft_version_id = $minecraft_version->id;
     $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'] == '') {
         $slug = Str::slug($input['name']);
     } else {
         $slug = $input['slug'];
     }
     $modpack->slug = $slug;
     $modpack->last_ip = Request::getClientIp();
     $success = $modpack->save();
     if ($success) {
         foreach ($input['creators'] as $creator) {
             $modpack->creators()->attach($creator);
         }
         foreach ($input['mods'] as $mod) {
             $modpack->mods()->attach($mod);
         }
         foreach ($input['tags'] as $tag) {
             $modpack->tags()->attach($tag);
         }
         $mods = $minecraft_version->mods;
         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.add', ['title' => $title, 'chosen' => true, 'success' => true, 'version' => $version, 'url_version' => $url_version, 'mods' => $mod_select_array]);
     }
     return Redirect::action('ModpackController@getAdd', [$url_version])->withErrors(['message' => 'Unable to add modpack.'])->withInput();
 }
Beispiel #4
0
 public function action_do_create()
 {
     $rules = array('name' => 'required|unique:modpacks', 'slug' => 'required|unique:modpacks');
     $messages = array('name_required' => 'You must enter a modpack name.', 'slug_required' => 'You must enter a modpack slug');
     $validation = Validator::make(Input::all(), $rules, $messages);
     if ($validation->fails()) {
         return Redirect::back()->with_errors($validation->errors);
     }
     try {
         $modpack = new Modpack();
         $modpack->name = Input::get('name');
         $modpack->slug = Str::slug(Input::get('slug'));
         $modpack->save();
         return Redirect::to('modpack/view/' . $modpack->id);
     } catch (Exception $e) {
         Log::exception($e);
     }
 }
Beispiel #5
0
 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));
             }
         }
     }
 }