Example #1
0
 public function get($code = null)
 {
     try {
         if (!$code) {
             throw new ApplicationException('Missing code');
         }
         $parts = explode('!', base64_decode($code));
         if (count($parts) < 2) {
             throw new ApplicationException('Invalid code');
         }
         list($id, $hash) = $parts;
         if (!($file = FileModel::find((int) $id))) {
             throw new ApplicationException('Unable to find file');
         }
         $verifyCode = self::getUniqueCode($file);
         if ($code != $verifyCode) {
             throw new ApplicationException('Invalid hash');
         }
         echo $file->output();
         exit;
     } catch (Exception $ex) {
     }
     /*
      * Fall back on Cms controller
      */
     return App::make('Cms\\Classes\\Controller')->setStatusCode(404)->run('/404');
 }
Example #2
0
 /**
  * File remove callback
  */
 public function onFileRemove()
 {
     if (Input::has('file_id')) {
         $file_id = Input::get('file_id');
         $file = File::find($file_id);
         if ($file) {
             $file->delete();
         }
     }
 }
 public function testDeleteFlagSoftDeleteModel()
 {
     Model::unguard();
     $user = SoftDeleteUser::create(['name' => 'Stevie', 'email' => '*****@*****.**']);
     Model::reguard();
     $user->avatar()->create(['data' => base_path() . '/tests/fixtures/plugins/database/tester/assets/images/avatar.png']);
     $this->assertNotNull($user->avatar);
     $avatarId = $user->avatar->id;
     $user->delete();
     $this->assertNotNull(FileModel::find($avatarId));
 }
Example #4
0
 public function formAfterDelete($model)
 {
     $fields = json_decode($model->fields);
     foreach ($fields as $value) {
         if (\Str::startsWith($value, 'attachment::')) {
             $id = explode('::', $value)[1];
             $file = \System\Models\File::find($id);
             if ($file) {
                 $file->delete();
             }
         }
     }
 }
 public function testDeleteFlagDeleteModel()
 {
     Model::unguard();
     $user = User::create(['name' => 'Stevie', 'email' => '*****@*****.**']);
     Model::reguard();
     $this->assertEmpty($user->photos);
     $user->photos()->create(['data' => base_path() . '/tests/fixtures/plugins/database/tester/assets/images/avatar.png']);
     $user->reloadRelations();
     $this->assertNotEmpty($user->photos);
     $photo = $user->photos->first();
     $this->assertNotNull($photo);
     $photoId = $photo->id;
     $user->delete();
     $this->assertNull(FileModel::find($photoId));
 }
 /**
  * Locates a file model based on the unique code.
  * @param $code string
  * @return System\Models\File
  */
 protected function findFileObject($code)
 {
     if (!$code) {
         throw new ApplicationException('Missing code');
     }
     $parts = explode('!', base64_decode($code));
     if (count($parts) < 2) {
         throw new ApplicationException('Invalid code');
     }
     list($id, $hash) = $parts;
     if (!($file = FileModel::find((int) $id))) {
         throw new ApplicationException('Unable to find file');
     }
     $verifyCode = self::getUniqueCode($file);
     if ($code != $verifyCode) {
         throw new ApplicationException('Invalid hash');
     }
     return $file;
 }
Example #7
0
 /**
  * Commit the changes of the attachment configuration form.
  */
 public function onSaveAttachmentConfig()
 {
     try {
         if (($file_id = post('file_id')) && ($file = File::find($file_id))) {
             $file->title = post('title');
             $file->description = post('description');
             $file->save();
             $file->thumb = $file->getThumb($this->imageWidth, $this->imageHeight, $this->thumbOptions);
             return ['item' => $file->toArray()];
         }
         throw new SystemException('Unable to find file, it may no longer exist');
     } catch (Exception $ex) {
         return json_encode(['error' => $ex->getMessage()]);
     }
 }
 public function onRemoveAttachment()
 {
     if (($file_id = post('file_id')) && ($file = File::find($file_id))) {
         $this->model->{$this->attribute}()->remove($file, $this->getSessionKey());
     }
 }
Example #9
0
 /**
  * Commit the changes of the attachment configuration form.
  */
 public function onSaveAttachmentConfig()
 {
     try {
         if (($file_id = post('file_id')) && ($file = File::find($file_id))) {
             $file->title = post('title');
             $file->description = post('description');
             $file->save();
             return ['displayName' => $file->title ?: $file->file_name];
         }
         throw new ApplicationException('Unable to find file, it may no longer exist');
     } catch (Exception $ex) {
         return json_encode(['error' => $ex->getMessage()]);
     }
 }