/**
  * Sweet baby jesus, I know I know!
  *
  * Used to upload a blueprint and do the necessary
  * checks to ensure that the upload is valid
  *
  * @param NbtParser         $parser
  * @param ImageManipulate   $manipulator
  * @param Zipper            $zipper
  * @param PathBuilder       $pathBuilder
  * @param PostUploadRequest $request
  * @param Blueprint         $blueprint
  * @param BlueprintModsUsed $blueprintModsUsed
  * @param Filesystem        $file
  * @param Guard             $guard
  * @param Repository        $repository
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postUpload(NbtParser $parser, ImageManipulate $manipulator, Zipper $zipper, PathBuilder $pathBuilder, PostUploadRequest $request, Blueprint $blueprint, BlueprintModsUsed $blueprintModsUsed, Filesystem $file, Guard $guard, Repository $repository)
 {
     $input = $request->get('upload');
     // Make sure that the blueprint is valid
     // ...well sort of, it can't be checked for sure
     $parser->loadFile($request->file('upload.blueprint'));
     if (!array_key_exists(0, $parser->root) || empty($parser->root) || !array_key_exists('type', $parser->root[0])) {
         return redirect()->back()->with('blueprintNotValid', true)->withInput();
     }
     // Arrays to be inserted into the database
     // Blueprint things
     $blueprintInsert = [];
     // Process the blueprint
     foreach ($parser->root[0]['value'] as $key => $value) {
         $value['name'] != 'version' ?: ($blueprintInsert['bc_version'] = $value['value']);
         $value['name'] != 'sizeY' ?: ($blueprintInsert['sizeY'] = $value['value']);
         $value['name'] != 'sizeZ' ?: ($blueprintInsert['sizeZ'] = $value['value']);
         $value['name'] != 'sizeX' ?: ($blueprintInsert['sizeX'] = $value['value']);
     }
     // Set some fields that are easy to set, just to get it out of the way
     $blueprintInsert['name'] = trim($input['name']);
     $blueprintInsert['version'] = trim($input['version']);
     $blueprintInsert['author_name'] = trim($input['author_name']);
     $blueprintInsert['survival_creative'] = $input['play_mode'];
     $blueprintInsert['description'] = trim($input['description']);
     $blueprintInsert['user_id'] = $guard->user()->getAuthIdentifier();
     $blueprintInsert['uploaded_at'] = Carbon::now()->toDateTimeString();
     $blueprintInsert['archive_name'] = str_replace(' ', '', $input['name']) . '_' . getRandomId() . '.zip';
     // Get the buildcraft image storage path
     $buildcraftImagesStoragePath = $pathBuilder->create()->fromPublicPath($repository->get('blueprint.paths.storage.buildcraft.images'));
     // Get the buildcraft archives storage path
     $buildcraftArchivesStoragePath = $pathBuilder->create()->fromPublicPath($repository->get('blueprint.paths.storage.buildcraft.archives'));
     // Get the buildcraft temp storage path
     $buildcraftTempStoragePath = $pathBuilder->create()->fromPublicPath($repository->get('blueprint.paths.storage.buildcraft.temp'));
     // Compress and move the required screenshot
     $manipulator->setFileInfo($request->file('upload.required_screenshot'))->compress()->move($buildcraftImagesStoragePath)->createThumb(500)->exitClean();
     //Might as well add it to the insert array
     $blueprintInsert['screenshot'] = $manipulator->getFileName();
     // Get a temporary name for the blueprint
     $temporary_name = getRandomId() . '.' . $request->file('upload.blueprint')->getClientOriginalExtension();
     // Move the blueprint to a temporary folder in order to archive it.
     $request->file('upload.blueprint')->move($buildcraftTempStoragePath, $temporary_name);
     // Add blueprint to the archive
     $zipper->make($buildcraftArchivesStoragePath . $blueprintInsert['archive_name'])->add($buildcraftTempStoragePath . $temporary_name)->add($buildcraftImagesStoragePath . $blueprintInsert['screenshot']);
     // Compress and move the first optional screenshot
     // Get the file name, create a thumb
     // Also add the file to the archive
     if (null !== $request->file('upload.optional_screenshot_0')) {
         $manipulator->setFileInfo($request->file('upload.optional_screenshot_0'))->compress()->move($buildcraftImagesStoragePath)->createThumb(500)->exitClean();
         $blueprintInsert['screenshot_optional_0'] = $manipulator->getFileName();
         $zipper->add($buildcraftImagesStoragePath . $blueprintInsert['screenshot_optional_0']);
     } else {
         $blueprintInsert['screenshot_optional_0'] = null;
     }
     // Compress and move the second optional screenshot
     // Get the file name, create a thumb
     // Also add the file to the archive
     if (null !== $request->file('upload.optional_screenshot_1')) {
         $manipulator->setFileInfo($request->file('upload.optional_screenshot_1'))->compress()->move($buildcraftImagesStoragePath)->createThumb(500)->exitClean();
         $blueprintInsert['screenshot_optional_1'] = $manipulator->getFileName();
         $zipper->add($buildcraftImagesStoragePath . $blueprintInsert['screenshot_optional_1']);
     } else {
         $blueprintInsert['screenshot_optional_1'] = null;
     }
     //Clean up
     $zipper->close();
     if ($file->exists($buildcraftTempStoragePath . $temporary_name)) {
         $file->delete($buildcraftTempStoragePath . $temporary_name);
     }
     // Insert the blueprint data
     $blueprint->insert($blueprintInsert);
     // Get the last inserted id
     $blueprint_id = $blueprint->id;
     $modsUsedInsert = [];
     // Get a list of the mods used
     $mods_used = $this->getModsUsed($parser->root[0]);
     if (null !== $mods_used) {
         // Make a valid array to insert
         foreach ($mods_used as $key => $value) {
             $modsUsedInsert[] = ['blueprint_id' => $blueprint_id, 'mod_name' => $value];
         }
         // Insert into mods used too
         $blueprintModsUsed->insert($modsUsedInsert);
     }
     // Welp, that's that
     return redirect()->route('buildcraft::user::getUpload', ['user_id' => Auth::user()->id])->with('blueprintUploadSuccess', true);
 }
예제 #2
0
<?php

include_once '../../../config/config.php';
include_once $serverPath . 'utils/db/db_get.php';
$table = "urban_encounters";
header("Location: " . $baseURL . "assets/encounters/urban/show.php?id=" . getRandomId($table));
 public function add(Zipper $zipper, PathBuilder $pathBuilder, Request $request, BlueprintCollection $blueprintCollection, Filesystem $file, Repository $repository, Collection $collection)
 {
     $input = $request->get('collection');
     // Check if the blueprint already belongs to this collection
     $search = $blueprintCollection->where(['collection_id' => $input['id'], 'blueprint_id' => $input['blueprint_id']])->get()->toArray();
     if (!empty($search)) {
         return redirect()->back()->with('blueprintAlreadyInCollection', true);
     }
     // Insert the blueprint in the collection
     $insert = $blueprintCollection->insert(['collection_id' => $input['id'], 'blueprint_id' => $input['blueprint_id']]);
     if ($insert) {
         // Create an archive to server to the user rather than creating it when it's downloaded
         // Get all the collection current archives first
         $collection = $collection->select('id', 'archive_name', 'name')->where(['id' => $input['id']])->with(['blueprints' => function ($query) {
             $query->select('archive_name');
         }])->first();
         $buildcraftArchiveStoragePath = $pathBuilder->create()->fromPublicPath($repository->get('blueprint.paths.storage.buildcraft.archives'));
         // Delete the previous archive(if any)
         if (null !== $collection->archive_name) {
             $file->delete($buildcraftArchiveStoragePath . $collection->archive_name);
         }
         // Create a random name for the collection archive
         $collectionArchiveName = str_replace(' ', '', $collection->name) . '_' . getRandomId() . '_collection' . '.zip';
         // Start creating the archive
         $zipper->make($buildcraftArchiveStoragePath . $collectionArchiveName);
         foreach ($collection->blueprints as $key => $value) {
             // Add each archive to the the newly created archive
             $zipper->add($buildcraftArchiveStoragePath . $value->archive_name);
         }
         //Clean up
         $zipper->close();
         // Update the archive name in the collections table
         $collection->archive_name = $collectionArchiveName;
         $collection->save();
         // Welp, that's that
         return redirect()->back()->with('blueprintAddedToCollection', true);
     }
     // Or not
     return redirect()->back()->with('blueprintNotAddedToCollection', true);
 }
예제 #4
0
 /**
  * @param     $file
  * @param int $quality
  *
  * @return $this
  */
 public function setFileInfo($file, $quality = 40)
 {
     $buildcraftTempDirectoryPath = $this->pathBuilderInstance->create()->fromPublicPath(Config::get('blueprint.paths.storage.buildcraft.temp'));
     $this->file = $file;
     $this->quality = $quality;
     $this->file_extension = $file->getClientOriginalExtension();
     $this->file_name = getRandomId();
     $this->file->move($buildcraftTempDirectoryPath, $this->file_name . '.' . $this->file_extension);
     $this->file_path = $buildcraftTempDirectoryPath . $this->file_name . '.' . $this->file_extension;
     return $this;
 }