Example #1
0
 public function send(JustifFormRequest $request)
 {
     \Mail::send('emails.justificatif', array('username' => $request->get('username'), 'email' => $request->get('email'), 'justif' => $request->get('justificatif')), function ($message) use($request) {
         $email = $request->email;
         $username = $request->username;
         $justif = $request->file('justificatif');
         if ($justif->isValid()) {
             $path = config('images.inscription');
             $files = \File::files($path);
             $newfile = $path . '/' . $username;
             foreach ($files as $file) {
                 $fileWithoutExtension = substr($file, 0, -4);
                 if ($fileWithoutExtension === $newfile) {
                     \File::Delete($fileWithoutExtension . '.png');
                     \File::Delete($fileWithoutExtension . '.pdf');
                     \File::Delete($fileWithoutExtension . '.jpg');
                 }
             }
             $extension = $justif->getClientOriginalExtension();
             $name = $username . '.' . $extension;
             $justif->move($path, $name);
         }
         $file = $path . '/' . $name;
         $message->attach($file);
         $message->from($request->email);
         $message->to('*****@*****.**', 'Equipe Roadweb')->subject('envoi de justificatif');
         $message->setReplyTo($email);
     });
     return \Redirect::route('compte')->with('message', 'Votre justificatif a bien été envoyé ! Vous serez informé de la validation de vos droits dans les 24 à 48h.');
 }
Example #2
0
 public function deleteFileByField($value, $field)
 {
     global $settingsManager;
     error_log("Delete file by field: {$field} / value: {$value}");
     $file = new File();
     $file->Load("{$field} = ?", array($value));
     if ($file->{$field} == $value) {
         $ok = $file->Delete();
         if ($ok) {
             $uploadFilesToS3 = $settingsManager->getSetting("Files: Upload Files to S3");
             if ($uploadFilesToS3 == "1") {
                 $uploadFilesToS3Key = $settingsManager->getSetting("Files: Amazon S3 Key for File Upload");
                 $uploadFilesToS3Secret = $settingsManager->getSetting("Files: Amazone S3 Secret for File Upload");
                 $s3Bucket = $settingsManager->getSetting("Files: S3 Bucket");
                 $uploadname = CLIENT_NAME . "/" . $file->filename;
                 error_log("Delete from S3:" . $uploadname);
                 $s3FileSys = new S3FileSystem($uploadFilesToS3Key, $uploadFilesToS3Secret);
                 $res = $s3FileSys->deleteObject($s3Bucket, $uploadname);
             } else {
                 error_log("Delete:" . CLIENT_BASE_PATH . 'data/' . $file->filename);
                 unlink(CLIENT_BASE_PATH . 'data/' . $file->filename);
             }
         } else {
             return false;
         }
     }
     return true;
 }
 public function deletePost($deletePostId)
 {
     $deletePost = Posts::find($deletePostId);
     if ($deletePost->photo != 'noImage.jpg') {
         //delete the image associative with the post
         \File::Delete('img/Post/' . $deletePost->photo);
     }
     $deletePost->delete();
     return redirect('home');
 }
 protected function deletePresentation($id, $presentationId)
 {
     if ($id == null || $presentationId == null) {
         return Response::json('invalid ids', 400);
     }
     $Presentation = Presentation::where('Project_FK', '=', $id)->where('id', '=', $presentationId)->first();
     if (empty($Presentation)) {
         return Response::json('presentation is empty', 400);
     }
     \File::Delete(public_path() . "\\presentations\\" . $Presentation->file);
     $Presentation->delete();
 }
 public function deleteProfileImage($employeeId)
 {
     $file = new File();
     $file->Load('name = ?', array('profile_image_' . $employeeId));
     if ($file->name == 'profile_image_' . $employeeId) {
         $ok = $file->Delete();
         if ($ok) {
             error_log("Delete File:" . CLIENT_BASE_PATH . $file->filename);
             unlink(CLIENT_BASE_PATH . 'data/' . $file->filename);
         } else {
             return false;
         }
     }
     return true;
 }
Example #6
0
 public function deleteFileByField($value, $field)
 {
     $file = new File();
     $file->Load("{$field} = ?", array($value));
     if ($file->{$field} == $value) {
         $ok = $file->Delete();
         if ($ok) {
             error_log("Delete:" . CLIENT_BASE_PATH . 'data/' . $file->filename);
             unlink(CLIENT_BASE_PATH . 'data/' . $file->filename);
         } else {
             return false;
         }
     }
     return true;
 }
Example #7
0
 public function pictChange(Request $request)
 {
     $pk = \Input::get('primkey');
     $oldFile = \Input::get('profilpic');
     $raport = Raport::find($pk);
     $destinationPath = 'bower_components/dist/photos/students/' . $raport->angkatan;
     // upload path
     try {
         \File::makeDirectory($destinationPath, 0755, true, true);
         \File::Delete($oldFile);
         if ($request->image != null) {
             $extension = $request->image->getClientOriginalExtension();
             // getting image extension
             $fileName = $pk . '.' . $extension;
             // renaming image
             $request->image->move($destinationPath, $fileName);
             // uploading file to given path
             $raport->pict = '/' . $destinationPath . '/' . $fileName;
             $raport->save();
         } else {
             $raport->pict = null;
         }
     } catch (\Illuminate\Database\QueryException $e) {
         $request->session()->flash('alert-danger', 'Gagal Mengganti Foto');
     }
     return redirect()->back()->with('error', 'Failed');
 }
 public function updateCapture(Request $request, $id)
 {
     $this->validate($request, ['pokemon' => 'required|exists:pokemon,id', 'photo' => 'image']);
     // Get info on the capture
     $capture = Capture::findOrFail($id);
     if ($request->hasFile('photo')) {
         // Generate a new file name
         $fileName = uniqid() . '.' . $request->file('photo')->getClientOriginalExtension();
         \Image::make($request->file('photo'))->resize(320, null, function ($constraint) {
             $constraint->aspectRatio();
         })->save('img/captures/' . $fileName);
         // Delete the old image
         \File::Delete('img/captures/' . $capture->photo);
         $capture->photo = $fileName;
     }
     if (\Carbon\Carbon::now()->diffInDays($capture->updated_at) > 5) {
         if ($capture->attack < 350) {
             $capture->attack += rand(0, 10);
             if ($capture->attack > 350) {
                 $capture->attack = 350;
             }
         }
         if ($capture->defense < 350) {
             $capture->defense += rand(0, 10);
             if ($capture->defense > 350) {
                 $capture->defense = 350;
             }
         }
     }
     $capture->pokemon_id = $request->pokemon;
     $capture->save();
     return redirect('pokecentre/captures');
 }
 /**
  * Remove the specified Profiles from storage.
  * @param  int $id
  * @return Response
  */
 public function destroy($id)
 {
     $profiles = $this->profilesRepository->find($id);
     if (empty($profiles)) {
         Flash::error('Profiles not found');
         return redirect(route('profiles.index'));
     }
     $docfrente = $profiles->docfrente;
     $docverso = $profiles->docverso;
     $foto = $profiles->foto;
     if ($docfrente) {
         if (\File::exists(base_path() . '/public/images/' . $docfrente)) {
             \File::Delete(base_path() . '/public/images/' . $docfrente);
         }
     }
     if ($docverso) {
         if (\File::exists(base_path() . '/public/images/' . $docverso)) {
             \File::Delete(base_path() . '/public/images/' . $docverso);
         }
     }
     if ($foto) {
         if (\File::exists(base_path() . '/public/images/' . $foto)) {
             \File::Delete(base_path() . '/public/images/' . $foto);
         }
     }
     $this->profilesRepository->delete($id);
     Flash::success('Profiles deleted successfully.');
     return redirect(route('profiles.index'));
 }
 /**
  * Update the specified Companies in storage.
  * @param  int              $id
  * @param UpdateCompaniesRequest $request
  * @return Response
  */
 public function update($id, UpdateCompaniesRequest $request)
 {
     $companies = $this->companiesRepository->find($id);
     if (empty($companies)) {
         Flash::error('Companies not found');
         return redirect(route('companies.index'));
     }
     $name = Input::file('logo')->getClientOriginalName();
     if (isset($name)) {
         \File::Delete(base_path() . '/public/images/' . $companies->logo);
         Image::make(Input::file('logo'))->save(base_path() . '/public/images/' . $name);
         $company = $this->companiesRepository->updateRich(['company' => $request->input('company'), 'logo' => $name], $id);
     } else {
         $companies = $this->companiesRepository->updateRich($request->all(), $id);
     }
     Flash::success('Companies updated successfully.');
     return redirect(route('companies.index'));
 }
Example #11
0
 public function Create($post_name, $user_id, $id_word = null, $id_rewrite = false)
 {
     $user_id = (int) $user_id;
     if (!POSTGood($post_name, self::$formats)) {
         return 1;
     }
     if ($id_word and !preg_match("/^[a-zA-Z0-9._-]+\$/", $id_word)) {
         return 3;
     }
     $new_file_info = POSTSafeMove($post_name, $this->base_dir);
     if (!$new_file_info) {
         return 2;
     }
     $way = $this->base_dir . $new_file_info['tmp_name'];
     $hash = md5_file($this->base_dir . $new_file_info['tmp_name']);
     $sql_part = $id_word ? " OR `id_word`=:id_word" : '';
     $data = $id_word ? array('id_word' => $id_word) : false;
     $line = getDB()->fetchRow("SELECT `id` FROM `{$this->db}` " . "WHERE `hash`='" . $hash . "'" . $sql_part, $data, 'num');
     if ($line) {
         $file_similar = new File($line[0]);
         $similar_info = $file_similar->getInfo();
         if ($similar_info['hash'] == $hash) {
             if (file_exists($way)) {
                 unlink($way);
             }
             $this->id = $similar_info['id'];
             $this->user_id = $similar_info['user_id'];
             $this->id_word = $similar_info['id_word'];
             $this->name = $similar_info['name'];
             $this->size = $similar_info['size'];
             $this->hash = $similar_info['hash'];
             $this->downloads = $similar_info['downloads'];
             $this->way = $file_similar->getWay();
             return 7;
         } else {
             if (!$id_rewrite) {
                 if (file_exists($way)) {
                     unlink($way);
                 }
                 return 4;
             } else {
                 if (!$file_similar->Delete()) {
                     return 6;
                 }
                 unset($file_similar);
             }
         }
     }
     $sql = "INSERT INTO {$this->db} (id_word, user_id, way, name, size, hash) " . "VALUES (:id_word, :user_id, :fway, :fname, :fsize, '{$hash}')";
     $result = getDB()->ask($sql, array('id_word' => $id_word ? $id_word : '', 'user_id' => $user_id, 'fway' => $new_file_info['tmp_name'], 'fname' => $new_file_info['name'], 'fsize' => $new_file_info['size_mb']));
     if ($result) {
         $this->id = getDB()->lastInsertId();
         $this->user_id = $user_id;
         $this->id_word = $id_word ? $id_word : '';
         $this->way = $way;
         $this->name = $new_file_info['name'];
         $this->size = $new_file_info['size_mb'];
         $this->hash = $hash;
         $this->downloads = 0;
     } else {
         if (file_exists($way)) {
             unlink($way);
         }
         return 5;
     }
     return 0;
 }
 /**
  * Remove the specified Musclegroups from storage.
  * @param  int $id
  * @return Response
  */
 public function destroy($id)
 {
     $musclegroups = $this->musclegroupsRepository->find($id);
     if (empty($musclegroups)) {
         Flash::error('Musclegroups not found');
         return redirect(route('musclegroups.index'));
     }
     $icone = $musclegroups->icone;
     if ($icone) {
         if (\File::exists(base_path() . '/public/images/' . $icone)) {
             \File::Delete(base_path() . '/public/images/' . $icone);
         }
     }
     $this->musclegroupsRepository->delete($id);
     Flash::success('Musclegroups deleted successfully.');
     return redirect(route('musclegroups.index'));
 }
 /**
  * Remove the specified Productphotos from storage.
  * @param  int $id
  * @return Response
  */
 public function destroy($id)
 {
     $productphotos = $this->productphotosRepository->find($id);
     if (empty($productphotos)) {
         Flash::error('Productphotos not found');
         return redirect(route('productphotos.index'));
     }
     $foto = $productphotos->foto;
     if ($foto) {
         if (\File::exists(base_path() . '/public/images/' . $foto)) {
             \File::Delete(base_path() . '/public/images/' . $foto);
         }
     }
     $this->productphotosRepository->delete($id);
     Flash::success('Productphotos deleted successfully.');
     return redirect(route('productphotos.index'));
 }
Example #14
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $slug)
 {
     // Validation
     $this->validate($request, ['first_name' => 'required|min:2|max:20', 'last_name' => 'required|min:2|max:30', 'age' => 'required|between:0,130|integer', 'profile_image' => 'image|between:0,2000']);
     // Find the user or staff member to edit where slug is equal to whatever came back from the form
     $staffMember = Staff::where('slug', $slug)->firstOrFail();
     // Makes changes to the database
     $staffMember->first_name = $request->first_name;
     $staffMember->last_name = $request->last_name;
     $staffMember->age = $request->age;
     // Referencing the existing slug and assigning to it the new slug based on changes made to the staff members name
     $staffMember->slug = str_slug($request->first_name . ' ' . $request->last_name);
     // If the user provided a new image then save that image
     if ($request->hasFile('profile_image')) {
         // Change the image file name, move the image file and resize the image
         // Grab the file extension of the image
         $fileExtension = $request->file('profile_image')->getClientOriginalExtension();
         // Generate a new profile image name to avoid duplication and join the two together
         //                            ^ ^
         $fileName = 'staff-' . uniqid() . '.' . $fileExtension;
         //                             -
         $request->file('profile_image')->move('img/staff', $fileName);
         // Grabbed the profile image and resized it
         \Image::make('img/staff/' . $fileName)->resize(240, null, function ($constrait) {
             $constrait->aspectRatio();
         })->save('img/staff/' . $fileName);
         // Delete the old image
         \File::Delete('img/staff/' . $staffMember->profile_image);
         // Tell the database of the new image
         $staffMember->profile_image = $fileName;
     }
     // Save the changes to the database
     $staffMember->save();
     // Redirect user to the staff members page with the updated changes
     return redirect('about/' . $staffMember->slug);
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     $validator = Validator::make($request->all(), ['first_name' => 'required', 'last_name' => 'required']);
     if ($validator->fails()) {
         $messages = $validator->messages();
         return redirect::route('agent_edit', $id)->withErrors($validator)->withInput();
     } else {
         $agent = Agent::find($id);
         $first_name = $request->input('first_name');
         $last_name = $request->input('last_name');
         $password = $request->input('password');
         $phone = $request->input('phone');
         $agent->first_name = $first_name;
         $agent->last_name = $last_name;
         if ($phone) {
             $agent->phone = $phone;
         }
         if ($password != '') {
             $agent->password = $password;
         }
         if ($request->file('user_image')) {
             $file = Input::file('user_image');
             $imagename = time() . '.' . $file->getClientOriginalExtension();
             if (file_exists(public_path('upload/agentprofile/' . $agent->image)) && $agent->image != '') {
                 $image_path = public_path('upload/agentprofile/' . $agent->image);
                 $image_thumb_path = public_path('upload/agentprofile/thumb/' . $agent->image);
                 \File::Delete($image_path);
                 \File::Delete($image_thumb_path);
             }
             $path = public_path('upload/agentprofile/' . $imagename);
             $image = \Image::make($file->getRealPath())->save($path);
             $th_path = public_path('upload/agentprofile/thumb/' . $imagename);
             $image = \Image::make($file->getRealPath())->resize(128, 128)->save($th_path);
             $agent->image = $imagename;
         }
         $agent->save();
         return redirect::route('agent_management')->with('success', 'Agent updated successfully.');
     }
 }
Example #16
0
 /**
  * Remove the specified Gyms from storage.
  * @param  int $id
  * @return Response
  */
 public function destroy($id)
 {
     $gyms = $this->gymsRepository->find($id);
     if (empty($gyms)) {
         Flash::error('Gyms not found');
         return redirect(route('gyms.index'));
     }
     $logotipoAtual = $gyms->logotipo;
     if ($logotipoAtual) {
         if (\File::exists(base_path() . '/public/images/' . $logotipoAtual)) {
             \File::Delete(base_path() . '/public/images/' . $logotipoAtual);
         }
     }
     $this->gymsRepository->delete($id);
     Flash::success('Gyms deleted successfully.');
     return redirect(route('gyms.index'));
 }
Example #17
0
 private static function ConvertToMp4($vi, $filename, $directory, $vbitrate, $abitrate, $scale, $callback)
 {
     $tools = Video_Tools::Get();
     $vbitrate = ($vbitrate <= 40 ? 'crf=' : 'ratetol=1.0:bitrate=') . $vbitrate;
     $tmp_file = File::Temporary($directory, self::EXTENSION_AVI);
     $cmd = (!empty($tools->nice) ? $tools->nice . ' ' : '') . $tools->mencoder . ' ' . escapeshellarg($filename) . ' ' . '-o ' . escapeshellarg($tmp_file) . ' ' . '-sws 9 ' . '-noskip ' . '-ovc x264 ' . '-x264encopts ' . escapeshellarg($vbitrate . ':bframes=1:me=umh:partitions=all:trellis=1:qp_step=4:qcomp=0.7:direct_pred=auto:keyint=300:threads=' . self::THREADS) . ' ' . '-vf ' . escapeshellarg((!empty($scale) ? $scale . ',' : '') . 'harddup') . ' ' . ($vi->has_audio ? '-oac faac -faacopts ' . escapeshellarg('br=' . $abitrate . ':mpeg=4:object=2') . ' -channels ' . self::CHANNELS_AAC . ' -srate ' . self::SAMPLE_RATE_AAC . ' ' : ' -nosound ') . '-ofps ' . escapeshellarg($vi->video_fps);
     if (self::ExecuteCmdAsync($cmd, $callback)) {
         File::Delete($tmp_file);
         throw new BaseException('Video conversion was interrupted by user request');
     }
     // Verify video file generated
     if (filesize($tmp_file) == 0) {
         File::Delete($tmp_file);
         throw new BaseException('Unable to convert video file to H.264/AAC MP4', $filename, $output);
     }
     // Get the filenames of the extracted raw streams
     $directory = Dir::StripTrailingSlash($directory);
     $basename = basename($tmp_file, '.' . self::EXTENSION_AVI);
     $videofile = $directory . '/' . $basename . '_video.h264';
     $audiofile_raw = $directory . '/' . $basename . '_audio.raw';
     $audiofile = $directory . '/' . $basename . '_audio.aac';
     // Extract the raw streams
     $cmd = (!empty($tools->nice) ? $tools->nice . ' ' : '') . $tools->mp4box . ' -aviraw video ' . escapeshellarg($tmp_file) . ' 2>&1';
     self::Log($cmd);
     $output = shell_exec($cmd);
     self::Log($output);
     if (!file_exists($videofile)) {
         File::Delete($tmp_file);
         throw new BaseException('Unable to extract video from file using MP4Box', $videofile, $output);
     }
     $output_file = File::Temporary($directory, self::EXTENSION_MP4);
     // Process video files that do have an audio stream
     if ($vi->has_audio) {
         $cmd = (!empty($tools->nice) ? $tools->nice . ' ' : '') . $tools->mp4box . ' -aviraw audio ' . escapeshellarg($tmp_file) . ' 2>&1';
         self::Log($cmd);
         $output = shell_exec($cmd);
         self::Log($output);
         if (!file_exists($audiofile_raw)) {
             File::Delete($tmp_file);
             File::Delete($videofile);
             throw new BaseException('Unable to extract audio from file using MP4Box', $audiofile_raw, $output);
         }
         rename($audiofile_raw, $audiofile);
         $cmd = (!empty($tools->nice) ? $tools->nice . ' ' : '') . $tools->mp4box . ' -add ' . escapeshellarg($videofile) . ' -add ' . escapeshellarg($audiofile) . ' -fps ' . escapeshellarg($vi->video_fps) . ' -inter 500 ' . escapeshellarg($output_file) . ' 2>&1';
         self::Log($cmd);
         $output = shell_exec($cmd);
         self::Log($output);
         File::Delete($audiofile);
     } else {
         $cmd = (!empty($tools->nice) ? $tools->nice . ' ' : '') . $tools->mp4box . ' -add ' . escapeshellarg($videofile) . ' -fps ' . escapeshellarg($vi->video_fps) . ' -inter 500 ' . escapeshellarg($output_file) . ' 2>&1';
         self::Log($cmd);
         $output = shell_exec($cmd);
         self::Log($output);
     }
     // Remove temporary files
     File::Delete($tmp_file);
     File::Delete($videofile);
     if (!file_exists($output_file)) {
         throw new BaseException('Unable to generate MP4 file using MP4Box', $output_file, $output);
     }
     return $output_file;
 }
Example #18
0
 public static function Import($settings)
 {
     $DB = GetDB();
     ProgressBarShow('pb-import');
     $file = TEMP_DIR . '/' . File::Sanitize($settings['import_file']);
     $fp = fopen($file, 'r');
     $filesize = filesize($file);
     $line = $read = $imported = 0;
     $expected = count($settings['fields']);
     while (!feof($fp)) {
         $line++;
         $string = fgets($fp);
         $read += strlen($string);
         $data = explode($settings['delimiter'], trim($string));
         ProgressBarUpdate('pb-import', $read / $filesize * 100);
         // Line does not have the expected number of fields
         if (count($data) != $expected) {
             continue;
         }
         $video = array();
         $defaults = array('category_id' => $settings['category_id'], 'sponsor_id' => $settings['sponsor_id'], 'username' => $settings['username'], 'duration' => Format::DurationToSeconds($settings['duration']), 'status' => $settings['status'], 'next_status' => $settings['status'], 'allow_comments' => $settings['allow_comments'], 'allow_ratings' => $settings['allow_ratings'], 'allow_embedding' => $settings['allow_embedding'], 'is_private' => $settings['is_private'], 'date_added' => Database_MySQL::Now(), 'is_featured' => 0, 'is_user_submitted' => 0, 'conversion_failed' => 0, 'tags' => null, 'title' => null, 'description' => null);
         foreach ($settings['fields'] as $index => $field) {
             if (!empty($field)) {
                 $video[$field] = trim($data[$index]);
             }
         }
         // Setup clips
         $clips = array();
         $thumbs = array();
         $clip_type = 'URL';
         if (isset($video['embed_code'])) {
             // Cannot convert or thumbnail from embed code
             $settings['flag_convert'] = $settings['flag_thumb'] = false;
             $clips[] = $video['embed_code'];
             $clip_type = 'Embed';
         } else {
             if (isset($video['gallery_url'])) {
                 $http = new HTTP();
                 if (!$http->Get($video['gallery_url'])) {
                     // Broken gallery URL, continue
                     continue;
                 }
                 list($thumbs, $clips) = Video_Source_Gallery::ExtractUrls($http->url, $http->body);
             } else {
                 if (!isset($video['video_url']) && isset($video['base_video_url'])) {
                     if (!preg_match('~/$~', $video['base_video_url'])) {
                         $video['base_video_url'] .= '/';
                     }
                     foreach (explode(',', $video['video_filename']) as $filename) {
                         $clips[] = $video['base_video_url'] . $filename;
                     }
                 } else {
                     $clips[] = $video['video_url'];
                 }
             }
         }
         // Check for duplicate clips
         $duplicate = false;
         foreach ($clips as $clip) {
             if (!Request::Get('flag_skip_imported_check') && $DB->QueryCount('SELECT COUNT(*) FROM `tbx_imported` WHERE `video_url`=?', array($clip)) > 0) {
                 $duplicate = true;
             }
             $DB->Update('REPLACE INTO `tbx_imported` VALUES (?)', array($clip));
         }
         // Dupe found
         if ($duplicate) {
             continue;
         }
         // Setup thumbs
         if (!isset($video['gallery_url']) && !isset($video['thumbnail_url']) && isset($video['base_thumbnail_url'])) {
             if (!preg_match('~/$~', $video['base_thumbnail_url'])) {
                 $video['base_thumbnail_url'] .= '/';
             }
             foreach (explode(',', String::FormatCommaSeparated($video['thumbnail_filename'])) as $filename) {
                 $thumbs[] = $video['base_thumbnail_url'] . $filename;
             }
         } else {
             if (!isset($video['gallery_url']) && isset($video['thumbnail_url'])) {
                 $thumbs[] = $video['thumbnail_url'];
             }
         }
         // Setup duration
         if (isset($video['duration_seconds'])) {
             $video['duration'] = $video['duration_seconds'];
         } else {
             if (isset($video['duration_formatted'])) {
                 $video['duration'] = Format::DurationToSeconds($video['duration_formatted']);
             }
         }
         // Use description for title
         if (empty($video['title'])) {
             $video['title'] = isset($video['description']) ? $video['description'] : '';
         }
         // Use title for description
         if (empty($video['description'])) {
             $video['description'] = isset($video['title']) ? $video['title'] : '';
         }
         // Use title for tags
         if (empty($video['tags'])) {
             $video['tags'] = isset($video['title']) ? $video['title'] : '';
         }
         // Setup category
         if (isset($video['category']) && ($category_id = $DB->QuerySingleColumn('SELECT `category_id` FROM `tbx_category` WHERE `name` LIKE ?', array($video['category']))) !== false) {
             $video['category_id'] = $category_id;
         } else {
             if (($category_id = GetBestCategory($video['title'] . ' ' . $video['description'])) !== null) {
                 $video['category_id'] = $category_id;
             }
         }
         // Merge in the defaults
         $video = array_merge($defaults, $video);
         // Format tags and convert to UTF-8
         $video['tags'] = Tags::Format($video['tags']);
         $video = String::ToUTF8($video);
         if (Request::Get('flag_convert')) {
             $video['status'] = STATUS_QUEUED;
         }
         // Add to database
         $video['video_id'] = DatabaseAdd('tbx_video', $video);
         DatabaseAdd('tbx_video_custom', $video);
         DatabaseAdd('tbx_video_stat', $video);
         if ($video['is_private']) {
             $video['private_id'] = sha1(uniqid(mt_rand(), true));
             DatabaseAdd('tbx_video_private', $video);
         }
         if ($video['status'] == STATUS_QUEUED) {
             $video['queued'] = time();
             DatabaseAdd('tbx_conversion_queue', $video);
         }
         if (Request::Get('flag_thumb')) {
             $video['queued'] = time();
             DatabaseAdd('tbx_thumb_queue', $video);
         }
         if ($video['status'] == STATUS_ACTIVE && !$video['is_private']) {
             Tags::AddToFrequency($video['tags']);
         }
         // Add clips
         foreach ($clips as $clip) {
             DatabaseAdd('tbx_video_clip', array('video_id' => $video['video_id'], 'type' => $clip_type, 'clip' => $clip));
         }
         $dir = new Video_Dir(Video_Dir::DirNameFromId($video['video_id']));
         // Process thumbs
         $thumb_ids = array();
         foreach ($thumbs as $thumb) {
             $http = new HTTP();
             if ($http->Get($thumb, $thumb)) {
                 if (Video_Thumbnail::CanResize()) {
                     $thumb_temp = $dir->AddTempFromVar($http->body, 'jpg');
                     $thumb_file = Video_Thumbnail::Resize($thumb_temp, Config::Get('thumb_size'), Config::Get('thumb_quality'), $dir->GetThumbsDir());
                 } else {
                     $thumb_file = $dir->AddThumbFromVar($http->body);
                 }
                 if (!empty($thumb_file)) {
                     $thumb_ids[] = DatabaseAdd('tbx_video_thumbnail', array('video_id' => $video['video_id'], 'thumbnail' => str_replace(Config::Get('document_root'), '', $thumb_file)));
                 }
             }
         }
         // Determine number of thumbnails and select random display thumbnail
         $num_thumbnails = count($thumb_ids);
         $display_thumbnail = null;
         if ($num_thumbnails > 0) {
             // Select display thumbnail randomly from the first 40%
             $display_thumbnail = $thumb_ids[rand(0, floor(0.4 * $num_thumbnails))];
         }
         DatabaseUpdate('tbx_video', array('video_id' => $video['video_id'], 'num_thumbnails' => $num_thumbnails, 'display_thumbnail' => $display_thumbnail));
         $imported++;
     }
     fclose($fp);
     UpdateCategoryStats();
     UpdateSponsorStats($settings['sponsor_id']);
     $t = new Template();
     $t->ClearCache('categories.tpl');
     ProgressBarHide('pb-import', NumberFormatInteger($imported) . ' videos have been imported!');
     // Start up the thumbnail and converson queues if needed
     if (!Config::Get('flag_using_cron')) {
         if (Request::Get('flag_convert')) {
             ConversionQueue::Start();
         }
         if (Request::Get('flag_thumb')) {
             ThumbQueue::Start();
         }
     }
     File::Delete($file);
 }
 function _menuFile()
 {
     if (Session::getValue('USERINFO_USER_ID') != null) {
         $file_name = Session::getValue('menufile');
         if (empty($file_name)) {
             $file_name = 'menu_item_' . Session::getValue('USERINFO_USER_ID') . '_' . date("YmdHis") . '.js';
         }
         $menuFile = Util::formatPath(MIGUELBASE_CACHE_DIR . '/' . $file_name);
         if (file_exists($menuFile) && time() - filemtime($menuFile) < MIGUELBASE_CACHE_TIME) {
             File::Touch($menuFile);
         } else {
             //Si existe, se borra
             if (file_exists($menuFile)) {
                 File::Delete($menuFile);
             }
             //Se crea, segĂșn el perfil de usuario
             switch (Session::getValue('USERINFO_PROFILE_ID')) {
                 case 1:
                     $strFile = 'menu_admin';
                     break;
                 case 2:
                 case 3:
                     $strFile = 'menu_profesor';
                     break;
                 case 4:
                     $strFile = 'menu_alumno';
                     break;
                 case 5:
                     $strFile = 'menu_secretaria';
                     break;
                 default:
                     $strFile = 'menu';
                     break;
             }
             include_once Util::app_Path("common/control/classes/miguel_menubar.class.php");
             $menubar = new miguel_MenuBar($strFile . '.xml');
             $str_content = 'var MENU_ITEMS = [';
             for ($i = 0; $i < $menubar->countMenu(); $i++) {
                 $str_content .= $menubar->getMenuCode($i, $superior);
             }
             $str_content .= '];';
             if (file_exists($menuFile)) {
                 File::Delete($menuFile);
             }
             File::Write($menuFile, $str_content);
         }
         $this->setViewVariable('menufile', MIGUEL_URLDIR . 'var/cache/' . "{$file_name}");
         Session::setValue('menufile', $file_name);
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $slug)
 {
     //validation
     $this->validate($request, ['first_name' => 'required|min:2|max:20', 'last_name' => 'required|min:2|max:30', 'age' => 'required|between:0,130|integer', 'profile_image' => 'image|between:1,2000']);
     //Find the staff member to edit
     $staffMember = \App\Staff::where('slug', $slug)->firstOrFail();
     $staffMember->first_name = $request->first_name;
     $staffMember->last_name = $request->last_name;
     $staffMember->age = $request->age;
     $staffMember->slug = str_slug($request->first_name . ' ' . $request->last_name);
     //if the user provided the new image
     if ($request->hasFile('profile_image')) {
         //generate a new file name and extention
         $fileExtension = $request->file('profile_image')->getClientOriginalExtension();
         $fileName = 'staff-' . uniqid() . '.' . $fileExtension;
         //move file in to its destination
         $request->file('profile_image')->move('img/staff/', $fileName);
         \Image::make('img/staff/' . $fileName)->resize(240, null, function ($constraint) {
             $constraint->aspectRatio();
         })->save('img/staff/' . $fileName);
         //delete the old image
         \File::Delete('img/staff/' . $staffMember->profile_image);
         //tell the database of the new image
         $staffMember->profile_image = $fileName;
     }
     $staffMember->save();
     return redirect('about/' . $staffMember->slug);
 }
 public function update(Request $request, $id)
 {
     $product = Product::findOrFail($id);
     $validator = Validator::make($request->all(), ['name' => 'required|max:100', 'model' => 'max:100', 'category_id' => 'required|array', 'photo' => 'image|max:2048']);
     if (!$validator->fails()) {
         $categories_id = $request->input('category_id');
         if ($request->hasFile('photo')) {
             $uploaded_photo = $request->file('photo');
             $extension = $uploaded_photo->getClientOriginalExtension();
             $filename = md5(time()) . '.' . $extension;
             $destinationPath = public_path('img');
             $uploaded_photo->move($destinationPath, $filename);
             if ($product->photo) {
                 $old_cover = $product->photo;
                 $filepath = public_path('img/' . $old_cover);
                 try {
                     \File::Delete($filepath);
                 } catch (FileNotFoundException $e) {
                     // file has been deleted or not exist
                 }
             }
             // save photo change
             $product->photo = $filename;
             $product->save();
         }
         // save product change
         $product->name = $request->input('name');
         $product->model = $request->input('model');
         $product->save();
         // update pivot table
         $product->categories()->sync($categories_id);
         return redirect('products')->with('successMsg', $request->input('name') . ' has been successfully edited.');
     } else {
         return redirect()->back()->withErrors($validator)->withInput();
     }
 }
 public function deleteMarker($deleteMarkerId)
 {
     $deleteMarker = Marker_location::find($deleteMarkerId);
     $allImages = $deleteMarker->PhotoMapImageUploader;
     foreach ($allImages as $image) {
         \File::Delete('img/PhotoMap/' . $image->locationImage);
     }
     $deleteMarker->delete();
     return redirect('photoMap');
 }
Example #23
0
     }
     $file = new File($file);
     if (!$file->Download()) {
         header("Location: " . BASE_URL . "index.php?mode=404");
     }
     break;
 case 'delete_file':
     $file = Filter::input('file', 'post', 'stringLow');
     if (!$file) {
         break;
     }
     if (empty($user) or $user->lvl() < 15) {
         break;
     }
     $file = new File($file);
     if ($file->Delete()) {
         aExit(0);
     } else {
         aExit(1);
     }
     break;
 case 'restore':
     $email = Filter::input('email', 'post', 'mail', true);
     if (!$email) {
         aExit(1, lng('INCOMPLETE_FORM'));
     }
     CaptchaCheck(2);
     $sql = "SELECT `{$bd_users['id']}` FROM `{$bd_names['users']}` " . "WHERE `{$bd_users['email']}`=:email";
     $result = getDB()->fetchRow($sql, array('email' => $email), 'num');
     if (!$result) {
         aExit(3, lng('RESTORE_NOT_EXIST'));
 public function upload_image()
 {
     $destinationPath = '../uploads/';
     $id = Input::get('person_id');
     $file = Input::file('file');
     $today = date("Y-m-d-H-i-s");
     $w = 0;
     $h = 0;
     if (Input::file('file')->isValid()) {
         $person = DB::table('persons')->where('person_id', '=', $id)->first();
         $filename = $file->getClientOriginalName();
         if (file_exists(public_path() . '/uploads/' . $person->profile_img)) {
             \File::Delete(public_path() . '/uploads/' . $person->profile_img);
         }
         DB::table('persons')->where('person_id', '=', $id)->update(['profile_img' => $today . "-" . $id . "-" . $filename]);
         $img = \Image::make($file)->fit(300, 300)->save('../public/uploads/' . $today . "-" . $id . "-" . $filename);
         $result["status"] = "Complete";
         return response()->json($result, 200);
     } else {
         $result["status"] = "Error";
         return response()->json($result, 200);
     }
 }
Example #25
0
 /**
  * Remove the specified Brands from storage.
  * @param  int $id
  * @return Response
  */
 public function destroy($id)
 {
     $brands = $this->brandsRepository->find($id);
     if (empty($brands)) {
         Flash::error('Brands not found');
         return redirect(route('brands.index'));
     }
     $logo = $brands->logo;
     if ($logo) {
         if (\File::exists(base_path() . '/public/images/' . $logo)) {
             \File::Delete(base_path() . '/public/images/' . $logo);
         }
     }
     $this->brandsRepository->delete($id);
     Flash::success('Brands deleted successfully.');
     return redirect(route('brands.index'));
 }
 /**
  * Remove the specified Outlinesports from storage.
  * @param  int $id
  * @return Response
  */
 public function destroy($id)
 {
     $outlinesports = $this->outlinesportsRepository->find($id);
     if (empty($outlinesports)) {
         Flash::error('Outlinesports not found');
         return redirect(route('outlinesports.index'));
     }
     $icone = $outlinesports->icone;
     if ($icone) {
         if (\File::exists(base_path() . '/public/images/' . $icone)) {
             \File::Delete(base_path() . '/public/images/' . $icone);
         }
     }
     $foto = $outlinesports->foto;
     if ($foto) {
         if (\File::exists(base_path() . '/public/images/' . $foto)) {
             \File::Delete(base_path() . '/public/images/' . $foto);
         }
     }
     $this->outlinesportsRepository->delete($id);
     Flash::success('Outlinesports deleted successfully.');
     return redirect(route('outlinesports.index'));
 }
 public function updateCapture(Request $request, $id)
 {
     // Validation
     $this->validate($request, ['pokemon' => 'required|exists:pokemon,id', 'photo' => 'image']);
     // Get info on the capture
     $capture = Capture::findOrFail($id);
     // Only run if the using attempts to upload a new photo
     if ($request->hasFile('photo')) {
         // Generate a new file name
         $fileName = uniqid() . '.' . $request->file('photo')->getClientOriginalExtension();
         // Resize the image
         \Image::make($request->file('photo'))->resize(320, null, function ($constraint) {
             $constraint->aspectRatio();
         })->save('img/captures/' . $fileName);
         // Delete the old image
         \File::Delete('img/captures' . $capture->photo);
         // Make sure the capture is updated with the new file
         $capture->photo = $fileName;
     }
     // Check if the user has provided any changes
     $capture->save();
     // Redirect the user to their captures
     return redirect('pokecentre/captures');
 }
 public function doRelease($id)
 {
     // Find info on the Pokemon the user wants to release
     try {
         $capture = Capture::where('user_id', \Auth::user()->id)->where('id', $id)->firstOrFail();
     } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
         return view('errors.captureNotFound');
     }
     // Delete the old image
     \File::Delete('img/captures/' . $capture->photo);
     \Session::flash('release', 'Bye bye ' . $capture->pokemon->name);
     Capture::destroy($id);
     return redirect('pokecentre/captures');
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $slug)
 {
     // Validation
     $this->validate($request, ['first_name' => 'required|min:2|max:20', 'last_name' => 'required|min:2|max:30', 'age' => 'required|integer|between:0,130', 'profile_image' => 'image|between:0,2000']);
     // Find the user or staff member to edit
     $staffMember = Staff::where('slug', $slug)->firstOrFail();
     $staffMember->first_name = $request->first_name;
     $staffMember->last_name = $request->last_name;
     $staffMember->age = $request->age;
     // Insert a slug into the request
     $staffMember->slug = str_slug($request->first_name . ' ' . $request->last_name);
     // If the user provided a new image
     if ($request->hasFile('profile_image')) {
         // Generare a new file name
         $fileExtension = $request->file('profile_image')->getClientOriginalExtension();
         $fileName = 'staff-' . uniqid() . '.' . $fileExtension;
         $request->file('profile_image')->move('img/staff', $fileName);
         \Image::make('img/staff/' . $fileName)->resize(240, null, function ($constraint) {
             $constraint->aspectRatio();
         })->save('img/staff/' . $fileName);
         // Delete the old image
         \File::Delete('img/staff/' . $staffMember->profile_image);
         // Tell  database
         $staffMember->profile_image = $fileName;
     }
     // Update the database
     $staffMember->save();
     return redirect('about/' . $staffMember->slug);
 }
Example #30
0
	public function deleteFileByField($value, $field){
		LogManager::getInstance()->info("Delete file by field: $field / value: $value");
		$file = new File();
		$file->Load("$field = ?",array($value));
		if($file->$field == $value){
			$ok = $file->Delete();
			if($ok){			
				$uploadFilesToS3 = SettingsManager::getInstance()->getSetting("Files: Upload Files to S3");
				
				if($uploadFilesToS3 == "1"){
					$uploadFilesToS3Key = SettingsManager::getInstance()->getSetting("Files: Amazon S3 Key for File Upload");
					$uploadFilesToS3Secret = SettingsManager::getInstance()->getSetting("Files: Amazone S3 Secret for File Upload");
					$s3Bucket = SettingsManager::getInstance()->getSetting("Files: S3 Bucket");
					
					$uploadname = CLIENT_NAME."/".$file->filename;
					LogManager::getInstance()->info("Delete from S3:".$uploadname);
					
					$s3FileSys = new S3FileSystem($uploadFilesToS3Key, $uploadFilesToS3Secret);
					$res = $s3FileSys->deleteObject($s3Bucket, $uploadname);
						
				}else{
					LogManager::getInstance()->info("Delete:".CLIENT_BASE_PATH.'data/'.$file->filename);
					unlink(CLIENT_BASE_PATH.'data/'.$file->filename);
				}
				
				
			}else{
				return false;
			}
		}
		return true;
	}