Exemplo n.º 1
0
 public function getSubmissionVerdict($srcContent, $srcExt)
 {
     assert($srcExt == "cpp" || $srcExt == "java" || $srcExt == "py", "'Source code language must be C++, Java or Python'");
     $judgingBaseFolder = '../judging/';
     $submissionFolderName = uniqid();
     $submissionFolder = "{$judgingBaseFolder}{$submissionFolderName}/";
     // Write the source code file
     $srcFpath = "{$submissionFolder}main.{$srcExt}";
     File::makeDirectory($submissionFolder);
     File::put($srcFpath, $srcContent);
     // Create the required test case files
     $caseNo = 1;
     $testcases = $this->testcases()->get();
     foreach ($testcases as $tc) {
         $inFname = "test{$caseNo}.in";
         $outFname = "test{$caseNo}.ans";
         $inFpath = $submissionFolder . $inFname;
         $outFpath = $submissionFolder . $outFname;
         File::put($inFpath, $tc->input);
         File::put($outFpath, $tc->output);
         $caseNo += 1;
     }
     // Judge!
     $judgingScript = "python \"{$judgingBaseFolder}judge.py\"";
     $judgingArguments = sprintf('"%s" "%s" %d', $srcFpath, $submissionFolder, $this['time_limit']);
     $judgeCommand = "{$judgingScript} {$judgingArguments}";
     $verdict = shell_exec($judgeCommand);
     // Clean-up the submission directory
     File::deleteDirectory($submissionFolder);
     return $verdict;
 }
Exemplo n.º 2
0
 protected function saveImages($image, $sid, $index)
 {
     $v = Validator::make(['index' => $index, 'id' => $sid], ['index' => 'required|integer', 'id' => 'required|integer']);
     if ($v->fails()) {
         dd('wrong sid =' . $sid);
     }
     try {
         $image = Image::make($image);
         // check the directories
         if (!File::exists($this->saveImgDir)) {
             File::makeDirectory($this->saveImgDir);
         }
         if (!File::exists($this->saveImgDir . '/products')) {
             File::makeDirectory($this->saveImgDir . '/products');
         }
         if (!File::exists($this->saveImgDir . '/products/' . $sid)) {
             File::makeDirectory($this->saveImgDir . '/products/' . $sid);
         }
         // dir to save image
         $dir = $this->saveImgDir . '/products/' . $sid . '/' . $index;
         if (!File::exists($dir)) {
             File::makeDirectory($dir);
         }
         // save medium
         $image->fit(240, 240)->save($dir . '/medium.jpg');
         $this->images[$index]['medium'] = 'mircurius/img/products/' . $sid . '/' . $index . '/medium.jpg';
     } catch (Exception $e) {
         $error = (array) $image;
         $this->log(json_encode($error));
         $this->log($e);
     }
 }
Exemplo n.º 3
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $rules = ['name' => ['required', 'unique:archive,name', 'regex:' . config('app.expressions.dir')]];
     if ($this->systemAdmin) {
         $rules['department_id'] = 'required';
     }
     $validator = Validator::make($request->all(), $rules);
     if ($validator->fails()) {
         return redirect()->back()->withErrors($validator)->withInput();
     }
     DB::transaction(function () use($request) {
         #add all papers from department to archive
         $archive = Archive::create($request->all());
         $department = Department::findOrFail($request->get('department_id'));
         $paperObj = new PaperClass();
         $archivePath = 'archive/';
         if (!File::exists($archivePath . $archive->name)) {
             File::makeDirectory($archivePath . $archive->name);
         }
         $newPath = $archivePath . $archive->name . '/';
         $oldPath = $paperObj->prefix() . '/' . $department->keyword . '/';
         foreach ($department->papers()->archived()->get() as $paper) {
             $paper->archive()->associate($archive);
             $paper->save();
             File::move($oldPath . $paper->source, $newPath . $paper->source);
             if ($paper->payment_source) {
                 File::move($oldPath . $paper->payment_source, $newPath . $paper->payment_source);
             }
         }
     });
     return redirect()->action('Admin\\ArchiveController@index')->with('success', 'updated');
 }
Exemplo n.º 4
0
 private function checkSharedFolderExists()
 {
     $path = base_path($this->file_location . Config::get('lfm.shared_folder_name'));
     if (!File::exists($path)) {
         File::makeDirectory($path, $mode = 0777, true, true);
     }
 }
 protected function imageAvatar()
 {
     $path = 'upload/' . date('Ym/d/');
     $filename = KRandom::getRandStr() . '.jpg';
     if (!File::exists(public_path($path))) {
         File::makeDirectory(public_path($path), 493, true);
     }
     while (File::exists(public_path($path) . $filename)) {
         $filename = KRandom::getRandStr() . '.jpg';
     }
     $this->image->resize(new \Imagine\Image\Box(300, 300))->save(public_path($path) . $filename);
     ImageModel::createUploadedImage($path . $filename, URL::asset($path . $filename));
     $user = AuthModel::user();
     $url = URL::asset($path . $filename);
     if ($user) {
         if ($user->profile) {
             $user->profile->avatar = $url;
             $user->profile->save();
         } else {
             ProfileModel::create(array('user_id' => $user->id, 'avatar' => $url));
         }
     } else {
     }
     return $url;
 }
Exemplo n.º 6
0
 private function checkSharedFolderExists()
 {
     $path = $this->getPath('share');
     if (!File::exists($path)) {
         File::makeDirectory($path, $mode = 0777, true, true);
     }
 }
Exemplo n.º 7
0
 public function upload(UploadRequest $request)
 {
     $type = $request->input('type');
     if ($request->ajax()) {
         //确认文件是否有上传
         if ($request->hasFile('file')) {
             //code..
             $file = $request->file('file');
             if (!$file->isValid()) {
                 $result = ['status' => 'failed', 'msg' => '上传文件无效!'];
             } else {
                 $extension = $file->getClientOriginalExtension();
                 //取得上传文件的后缀名
                 $path = 'uploads/' . $type . '/';
                 $savePath = $path . date('Ymd', time());
                 File::exists($savePath) or File::makeDirectory($savePath, 0755, true);
                 $saveFileName = uniqid() . '_' . $type . '.' . $extension;
                 //函数基于以微秒计的当前时间,生成一个唯一的 ID。
                 $file->move($savePath, $saveFileName);
                 $fullFileName = $savePath . '/' . $saveFileName;
                 $result = ['status' => 'success', 'msg' => '上传成功!', 'path' => $fullFileName];
             }
         } else {
             $result = ['status' => 'failed', 'msg' => '请选择上传文件!'];
         }
         return $result;
     }
 }
 protected function storeDiskSettingsBackEnd($directory_name, $directory_driver, $is_directory_public = false)
 {
     $directory_url = null;
     $directory_root = null;
     $directory_path = null;
     $directory_name = str_replace('-', '_', slugify($directory_name));
     switch ($directory_driver) {
         case 'local':
         default:
             if ($is_directory_public) {
                 $directory_root = 'uploads/' . Environments::currentEnvironment() . '/' . $directory_name;
                 $directory_url = url($directory_root);
                 $directory_path = public_path($directory_root);
             } else {
                 $directory_root = 'app/' . Environments::currentEnvironment() . '/' . $directory_name;
                 $directory_url = url($directory_root);
                 $directory_path = public_path($directory_root);
             }
             break;
     }
     File::makeDirectory($directory_path, 0777, true);
     $disk = ['driver' => $directory_driver, 'root' => $directory_path];
     if ($is_directory_public) {
         $disk['visibility'] = 'public';
     }
     $this->addFileSystemDisk($directory_name, $disk, Environments::currentEnvironment());
     $this->mountElFinderDisk($directory_name, ['alias' => $directory_path, 'URL' => $directory_url, 'access' => ['readonly' => true, 'roles' => [RolesRepositoryEloquent::ADMIN], 'permissions' => [PermissionsRepositoryEloquent::CAN_READ_BACKUPS_DIRECTORY]]], Environments::currentEnvironment());
 }
 /**
  * Create a directory to store some working files.
  *
  * @return string
  */
 public function createTempDirectory()
 {
     $tempDirectory = storage_path('medialibrary/temp/' . str_random(16));
     File::makeDirectory($tempDirectory, 493, true);
     Gitignore::createIn(storage_path('medialibrary'));
     return $tempDirectory;
 }
 /**
  * Create directory tree for views, and fire the generator.
  */
 public function fire()
 {
     $directoryPath = dirname($this->getFileGenerationPath());
     if (!File::exists($directoryPath)) {
         File::makeDirectory($directoryPath, 0777, true);
     }
     parent::fire();
 }
Exemplo n.º 11
0
 protected function checkDirectory($namespace, $routePath)
 {
     $rootPath = config('routie.path');
     $routePath = isset($namespace) ? $rootPath . '/' . $routePath : $rootPath;
     if (!File::isDirectory($routePath)) {
         File::makeDirectory($routePath, 0775, true);
     }
     return $routePath;
 }
Exemplo n.º 12
0
 /**
  * Handle the event.
  *
  * @param  shopPurchased  $event
  * @return void
  */
 public function handle(shopPurchased $event)
 {
     $payment = $event->payment;
     $shop = $payment->itemable;
     $payment->update(['status' => 1]);
     $shop->update(['status' => 1]);
     File::makeDirectory(public_path() . '/img/files/shop/' . $shop->id, 0775, true, true);
     Addon::shop()->first()->buy();
 }
Exemplo n.º 13
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     //
     $this->validate($request, ['schedule' => 'required', 'category' => 'required', 'type' => 'required']);
     $data = new Item();
     $data->auction_schedule_id = $request->schedule;
     $data->users_id = Auth::user()->id;
     $data->ticket_no = $request->ticket_no;
     $data->category_id = $request->category;
     $data->type_id = $request->type;
     $data->price = $request->price;
     $data->description = $request->description;
     $data->save();
     $item_id = $data->id;
     $destinationPath = 'images/' . Auth::user()->id . '/' . $request->ticket_no;
     File::makeDirectory($destinationPath, 0777, TRUE, TRUE);
     foreach ($request->file('image') as $key => $photo) {
         if ($photo) {
             if ($photo->isValid()) {
                 // original
                 $filename_original = 'image_' . $key . '_original.jpg';
                 Image_::make($photo->getRealPath())->save($destinationPath . '/' . $filename_original);
                 $data = new Image();
                 $data->items_id = $item_id;
                 $data->url = $destinationPath . '/' . $filename_original;
                 $data->save();
                 // for grid view
                 $filename = $destinationPath . '/' . 'image_' . $key . '_349x200.jpg';
                 ph::resize_image($destinationPath . '/' . $filename_original, 349, 200, $filename);
                 $data = new Image();
                 $data->items_id = $item_id;
                 $data->url = $filename;
                 $data->save();
                 // for view page (big)
                 $filename = $destinationPath . '/' . 'image_' . $key . '_725x483.jpg';
                 ph::resize_image($destinationPath . '/' . $filename_original, 725, 483, $filename);
                 $data = new Image();
                 $data->items_id = $item_id;
                 $data->url = $filename;
                 $data->save();
                 // for view page (thumbnail)
                 $filename = $destinationPath . '/' . 'image_' . $key . '_173x126.jpg';
                 ph::resize_image($destinationPath . '/' . $filename_original, 173, 126, $filename);
                 $data = new Image();
                 $data->items_id = $item_id;
                 $data->url = $filename;
                 $data->save();
             } else {
                 Session::flash('message', 'uploaded file is not valid');
                 return redirect('/item');
             }
         }
     }
     Session::flash('message', 'Item with ticket #' . $request->ticket_no . ' was successfully created');
     return redirect('/item');
 }
Exemplo n.º 14
0
 /**
  * Move the thumbnail to the specific place
  *
  * @param $thumbnail
  * @param User $user
  * @return string
  */
 private function extractThumbnail($thumbnail, User $user)
 {
     $path = public_path() . '/content/profile_pictures/' . $user->id;
     if (!File::exists($path)) {
         File::makeDirectory($path, 0755, true);
     }
     $thumbnailName = time() . '-' . $thumbnail->getClientOriginalName();
     $thumbnail->move($path, $thumbnailName);
     return $thumbnailName;
 }
Exemplo n.º 15
0
 /**
  * Move the thumbnail to the specific place
  *
  * @param $thumbnail
  * @param Category $category
  * @return string
  */
 private function extractThumbnail($thumbnail, Category $category)
 {
     $path = public_path() . '/content/images/' . $category->slug;
     if (!File::exists($path)) {
         File::makeDirectory($path, 0755, true);
     }
     $thumbnailName = time() . '-' . $thumbnail->getClientOriginalName();
     $thumbnail->move($path, $thumbnailName);
     return $thumbnailName;
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker::create();
     if (!File::exists('public/upload/images/')) {
         File::makeDirectory('public/upload/images/', 775, true);
     }
     for ($i = 0; $i < 20; $i++) {
         Contact::create(["name" => $faker->name, "phone" => $faker->phoneNumber, "image" => $faker->image('public/upload/images', 200, 200), "user_id" => 1, "sort" => 0]);
     }
 }
 private function makeThumb($dest_path, $new_filename)
 {
     $thumb_folder_name = Config::get('lfm.thumb_folder_name');
     if (!File::exists($dest_path . $thumb_folder_name)) {
         File::makeDirectory($dest_path . $thumb_folder_name);
     }
     $thumb_img = Image::make($dest_path . $new_filename);
     $thumb_img->fit(200, 200)->save($dest_path . $thumb_folder_name . '/' . $new_filename);
     unset($thumb_img);
 }
Exemplo n.º 18
0
 /**
  * Get the path where an image will be cached
  *
  * @param Image $image
  *
  * @return string
  */
 public function getCachePathOf(Image $image)
 {
     $hash = $this->getHashOf($image);
     $cacheFolder = $this->illuminage->getCacheFolder();
     $hashedFolder = $cacheFolder . $this->getHashedPath($hash);
     if ($hashedFolder and !File::isDirectory($hashedFolder)) {
         @File::makeDirectory($hashedFolder, 511, true);
     }
     return $hashedFolder . $hash;
 }
Exemplo n.º 19
0
 /**
  * Check for cache path, and create if missing
  */
 protected function makeStorageSerializerDir()
 {
     $purifierCachePath = Config::get('purifier::config.cachePath');
     if (File::exists($purifierCachePath) === false) {
         File::makeDirectory($purifierCachePath);
         $gitIgnoreContent = '*';
         $gitIgnoreContent .= "\n" . '!.gitignore';
         File::put($purifierCachePath . '/.gitignore', $gitIgnoreContent);
     }
 }
Exemplo n.º 20
0
 /**
  * Handle the event.
  *
  * @param  UserRegistered  $event
  * @return void
  */
 public function handle(UserRegistered $event)
 {
     $user = $event->user;
     File::makeDirectory(public_path() . '/images/files/' . $user->id, 0775, true, true);
     /*Send Email to the Registered User*/
     Mail::send('emails.welcome', ['user' => $user], function ($msg) use($user) {
         $msg->from('*****@*****.**', 'Namamooz');
         $msg->to($user['email'], $user->full_name)->subject('Welcome To Namamooz');
     });
 }
Exemplo n.º 21
0
 private function checkDefaultFolderExists($type = 'share')
 {
     if ($type === 'user' && \Config::get('lfm.allow_multi_user') !== true) {
         return;
     }
     $path = $this->getPath($type);
     if (!File::exists($path)) {
         File::makeDirectory($path, $mode = 0777, true, true);
     }
 }
 /**
  * Process the form and create a new election.
  * @param $request
  * @return mixed
  */
 public function store(ElectionRequest $request)
 {
     // Determine the positions
     $positions = $this->determineElectionPositions($request);
     // Create the election
     $election = Election::create(['type' => $request->get('type'), 'bathstudent_id' => $request->get('bathstudent_id'), 'hustings_time' => $request->get('hustings_time'), 'hustings_location' => $request->stripped('hustings_location'), 'nominations_start' => $request->get('nominations_start'), 'nominations_end' => $request->get('nominations_end'), 'voting_start' => $request->get('voting_start'), 'voting_end' => $request->get('voting_end'), 'positions' => $positions]);
     File::makeDirectory($election->getManifestoPath(), 0775, true);
     Flash::success('Election created');
     return redirect()->route('elections.view', ['id' => $election->id]);
 }
Exemplo n.º 23
0
 public function index()
 {
     if (Input::get("code")) {
         $api_id = Config::get('registration::social.vk.api_id');
         $secret_key = Config::get('registration::social.vk.secret_key');
         $params = array('client_id' => $api_id, 'client_secret' => $secret_key, 'code' => Input::get("code"), 'redirect_uri' => "http://" . $_SERVER['HTTP_HOST'] . "/auth_soc/vk_res");
         $url = 'https://oauth.vk.com/access_token' . '?' . urldecode(http_build_query($params));
         $ch = curl_init($url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         $result = curl_exec($ch);
         curl_close($ch);
         $data = json_decode($result, true);
         if (isset($data['access_token'])) {
             $str = "https://api.vkontakte.ru/method/getProfiles?uid=" . $data['user_id'] . "&fields=photo_big&access_token=" . $data['access_token'];
             $resp2 = file_get_contents($str);
             $el = json_decode($resp2, true);
             $first_name = $el['response'][0]['first_name'];
             $last_name = $el['response'][0]['last_name'];
             $id_user = $el['response'][0]['uid'];
             $user = DB::table("users")->where("id_vk", $id_user)->first();
             if (!isset($user['id'])) {
                 $new_pass = str_random(6);
                 $user = Sentry::register(array('email' => $id_user, 'password' => $new_pass, 'id_vk' => $id_user, 'activated' => "1", 'first_name' => $first_name, 'last_name' => $last_name));
                 //качаем аватарку юзера
                 if ($el['response'][0]['photo_big'] && Config::get('registration::social.vk.foto')) {
                     $id_one = substr($user->id, 0, 1);
                     $destinationPath = "/storage/users/{$id_one}/{$user->id}/";
                     $path_server = public_path() . $destinationPath;
                     File::makeDirectory($path_server, $mode = 0777, true, true);
                     $foto_resource = file_get_contents($el['response'][0]['photo_big']);
                     $foto_user = time() . basename($el['response'][0]['photo_big']);
                     $f = fopen($_SERVER['DOCUMENT_ROOT'] . $destinationPath . $foto_user, 'w');
                     fwrite($f, $foto_resource);
                     fclose($f);
                     $user->photo = $destinationPath . $foto_user;
                     $user->save();
                 }
                 $user_auth = Sentry::findUserById($user->id);
                 Sentry::login($user_auth, Config::get('registration::social.vk.remember'));
             } else {
                 $user_auth = Sentry::findUserById($user['id']);
                 Sentry::login($user_auth, Config::get('registration::social.vk.remember'));
             }
             //if not empty redirect_url
             if (Config::get('registration::social.vk.redirect_url')) {
                 $redirect = Config::get('registration::social.vk.redirect_url');
                 Session::flash('id_user', $user_auth->id);
             } else {
                 $redirect = Session::get('url_previous', "/");
                 Session::forget('url_previous');
             }
             return Redirect::to($redirect);
         }
     }
 }
Exemplo n.º 24
0
 /**
  * @param null $path
  * @return mixed
  */
 public function save($path = null)
 {
     if (!is_null($path)) {
         $this->path = $path;
     }
     if (!is_dir($path = $this->getDestinationDirectory())) {
         File::makeDirectory($path, 0777, true);
     }
     $this->image->save($this->getDestinationFile());
     return $this->filename;
 }
Exemplo n.º 25
0
 /**
  * Handle the event.
  *
  * @param  UserRegistered  $event
  * @return void
  */
 public function handle(UserRegistered $event)
 {
     $newUser = $event->user;
     $newUser->info()->create(['user_id' => $newUser->id]);
     $newUser->usage()->create(['user_id' => $newUser->id, 'capacity' => 300]);
     $newUser->activity()->create(['user_id' => $newUser->id, 'status' => 1, 'online' => 1]);
     File::makeDirectory(public_path() . '/img/files/' . $newUser->id, 0775, true, true);
     //        Mail::send('emails.welcome', ['user'=>$newUser], function ($message)use ($newUser)  {
     //            $message->to($newUser['email'])->subject('welcome to skillema');
     //        });
 }
Exemplo n.º 26
0
 /**
  * Add a new folder
  *
  * @return mixed
  */
 public function getAddfolder()
 {
     $folder_name = Str::slug(Input::get('name'));
     $path = base_path(Config::get('sfm.dir'));
     if (!File::exists($path . "/" . $folder_name)) {
         File::makeDirectory($path . "/" . $folder_name, $mode = 0777, true, true);
         return "OK";
     } else {
         return Lang::get('filemanager::sfm.folder_exists');
     }
 }
 /**
  * Add a new folder
  *
  * @return mixed
  */
 public function getAddfolder()
 {
     $folder_name = Str::slug(Input::get('name'));
     $path = base_path($this->file_location);
     if (!File::exists($path . "/" . $folder_name)) {
         File::makeDirectory($path . "/" . $folder_name, $mode = 0777, true, true);
         return "OK";
     } else {
         return "A folder with this name already exists!";
     }
 }
Exemplo n.º 28
0
 private function create_scss()
 {
     $src = $this->zip_path . '/css/' . $this->fontname . '.css';
     $dst = $this->resources_path . 'sass/' . $this->fontname . '/components/';
     $cssfile = $this->embed() . $this->stripfontsrc(File::get($src));
     if (!File::exists($dst)) {
         File::makeDirectory($dst, 0755, true);
     }
     File::put($dst . 'fontello.scss', $cssfile);
     $this->info("saved: {$dst}fontello.scss.");
 }
Exemplo n.º 29
0
 public function newPicture($fileName, $image)
 {
     $path = public_path('/images/gallery/');
     File::exists($path) or File::makeDirectory($path, 0755, true);
     $image->resize(200, 200)->save($path . $fileName);
     $picture = new Image();
     $picture->user = Auth::user()->name;
     $picture->caption = Input::get('caption');
     $picture->imagePath = 'images/gallery/' . $fileName;
     $picture->save();
 }
Exemplo n.º 30
-1
 public function resize($filename, $sizeString)
 {
     // We can read the output path from our configuration file.
     $outputDir = Config::get('assets.images.paths.output');
     // Create an output file path from the size and the filename.
     $outputFile = $outputDir . '/' . $sizeString . '_' . $filename;
     // If the resized file already exists we will just return it.
     if (File::isFile($outputFile)) {
         return File::get($outputFile);
     }
     // File doesn't exist yet, so we will resize the original.
     $inputDir = Config::get('assets.images.paths.input');
     $inputFile = $inputDir . '/' . $filename;
     // Get the width and the height of the chosen size from the Config file.
     $sizeArr = Config::get('assets.images.sizes.' . $sizeString);
     $width = $sizeArr['width'];
     $height = $sizeArr['height'];
     // We want to crop the image so we set the resize mode and size.
     $size = new \Imagine\Image\Box($width, $height);
     $mode = \Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND;
     // Create the output directory if it doesn't exist yet.
     if (!File::isDirectory($outputDir)) {
         File::makeDirectory($outputDir);
     }
     // Open the file, resize it and save it.
     $this->imagine->open($inputFile)->thumbnail($size, $mode)->save($outputFile, array('quality' => 90));
     // Return the resized file.
     return File::get($outputFile);
 }