예제 #1
0
파일: formatters.php 프로젝트: larakit/lk
 function human_file_size($size)
 {
     if ($size >= 1073741824) {
         $fileSize = round($size / 1024 / 1024 / 1024, 1) . ' ГБ';
     } elseif ($size >= 1048576) {
         $fileSize = round($size / 1024 / 1024, 1) . ' МБ';
     } elseif ($size >= 1024) {
         $fileSize = round($size / 1024, 1) . ' КБ';
     } else {
         $fileSize = \Larakit\Helper\HelperText::plural($size, 'байт', 'байта', 'байтов');
     }
     return $fileSize;
 }
예제 #2
0
파일: FormIde.php 프로젝트: larakit/lk
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $elements = [];
     //добавим геттеры в контейнеры
     //добавим сеттеры в контейнеры
     foreach (Register::$containers as $container) {
         $this->info($container);
         foreach ($this->form_element_methods_get as $method) {
             $params = $this->getMethodParams($container, $method);
             $this->putPhpDoc($container, 'string', $method, $params);
         }
         foreach ($this->form_element_methods_set as $method) {
             $params = $this->getMethodParams($container, $method);
             $this->putPhpDoc($container, $container, $method, $params);
         }
     }
     //добавим элементы в контейнеры
     foreach (Register::$elements as $name => $data) {
         $class = Arr::get($data, 'class');
         foreach (Register::$containers as $container) {
             $params = $this->getMethodParams($class, 'laraform');
             $method = \Illuminate\Support\Str::camel('put_' . $name);
             $this->putPhpDoc($container, $class, $method, $params);
         }
         foreach ($this->form_element_methods_get as $method) {
             $params = $this->getMethodParams($class, $method);
             $this->putPhpDoc($class, 'string', $method, $params);
         }
         foreach ($this->form_element_methods_set as $method) {
             $params = $this->getMethodParams($class, $method);
             $this->putPhpDoc($class, $class, $method, $params);
         }
     }
     $data = $this->ret;
     $content = \View::make('larakit::!.quickform.ide-helper', ['data' => $data, 'tab' => "\t"]);
     file_put_contents(base_path() . '/_ide_helper_laraform.php', $content);
     $this->info('IDE helper сгенерирован для ' . HelperText::plural_with_number(count($this->classes), 'элемента', 'элементов', 'элементов'));
 }
예제 #3
0
 function attachFile($source)
 {
     /** @var Model $this */
     \DB::beginTransaction();
     try {
         if ($source instanceof UploadedFile) {
             //                $source    = new UploadedFile(1, 1);
             $ext = $source->getClientOriginalExtension();
             $file_name = mb_substr($source->getClientOriginalName(), 0, 0 - mb_strlen($ext) - 1);
         } else {
             $ext = \File::extension($source);
             $file_name = \File::name($source);
         }
         $ext = mb_strtolower($ext);
         $tmp = file_get_contents($source);
         $tmp_name = storage_path('/attaches/' . date('Y_m_d_H-i-s') . '/' . \Str::slug($this->getMorphClass()) . '.' . $ext);
         if (!file_exists(dirname($tmp_name))) {
             mkdir(dirname($tmp_name), 0777, true);
         }
         file_put_contents($tmp_name, $tmp);
         unset($tmp);
         if (!file_exists($tmp_name)) {
             throw new Exception(laralang('larakit::attach.errors.exists', ['file' => larasafepath($tmp_name)]));
         }
         $attach = Attach\Attach::fromModel($this);
         $config = $this->attachConfig();
         //проверка на максимальный размер
         $maxsize = Arr::get($config, 'maxsize');
         $size = \File::size($tmp_name);
         if ($maxsize < $size) {
             throw new Exception(laralang('larakit::attach.errors.maxsize', ['maxsize' => HelperText::fileSize($maxsize, 0)]));
         }
         //проверка на разрешенные EXT
         $enabled_exts = Arr::get($config, 'ext');
         if (!in_array($ext, $enabled_exts)) {
             throw new Exception(laralang('larakit::attach.errors.ext', ['enabled_exts' => implode(', ', $enabled_exts)]));
         }
         //проверка на разрешенные MIME
         $expected_mimes = HelperFile::mimes_by_ext($ext);
         $mime = HelperFile::mime($tmp_name);
         if (!in_array($mime, $expected_mimes)) {
             throw new Exception(laralang('larakit::attach.errors.ext', ['enabled_exts' => implode(', ', $enabled_exts)]));
         }
         $img = getimagesize($tmp_name);
         if (false !== $img) {
             $this->attach_w = Arr::get($img, 0);
             $this->attach_h = Arr::get($img, 1);
         }
         $this->attach_user_id = Me::id();
         $this->attach_ext = $ext;
         $this->attach_size = $size;
         $this->attach_mime = $mime;
         $this->attach_file = $file_name . '.' . $ext;
         $this->attach_name = $file_name;
         $this->save();
         $attach->setId($this->id)->processing($tmp_name);
         \DB::commit();
         $val = true;
     } catch (\Exception $e) {
         \DB::rollBack();
         $val = $e->getMessage();
     }
     if (file_exists($tmp_name)) {
         if (false !== mb_strpos($source, '//')) {
             unlink($tmp_name);
         }
     }
     return $val;
 }
예제 #4
0
 function getAttachSizeAttribute()
 {
     return HelperText::fileSize($this->model->attach_size);
 }
예제 #5
0
파일: Accessor.php 프로젝트: larakit/lk
 function actionAttach()
 {
     if (!Acl::factory($this->model)->reason('edit')) {
         //            <div class="btn-group btn-group-block">
         //              <button type="button" class="btn btn-default"><i class="fa fa-paperclip"></i></button>
         //              <button type="button" class="btn btn-default"><i class="fa fa-file-pdf-o"></i> &nbsp; брендбук_на_согласование.pdf</button>
         //              <button type="button" class="btn btn-default"><i class="fa fa-remove"></i></button>
         //            </div>
         $btn_paperclip = \HtmlButton::setAttribute('data-action', 'attach')->addClass('btn btn-default js-btn')->setTitle('Прикрепить файл')->setContent('<i class="fa fa-paperclip"></i>');
         $btn_remove = '';
         $btn_file = '';
         $btn_size = '';
         $btn_mime = '';
         $btn_img = '';
         $name = $this->model->attach_name;
         if ($name) {
             $btn_size = \HtmlButton::addClass('btn btn-default')->setContent(HelperText::fileSize($this->model->attach_size));
             $btn_mime = \HtmlButton::addClass('btn btn-default')->setContent($this->model->attach_mime);
             $btn_file = \HtmlButton::setAttribute('data-action', 'attach_name')->addClass('btn btn-default js-btn')->setContent($name);
             $btn_remove = \HtmlButton::setAttribute('data-action', 'attach_clear')->addClass('btn btn-default js-btn')->setTitle('Удалить вложение')->setContent('<i class="fa text-danger fa-remove"></i>');
         }
         $ret = \HtmlDiv::addClass('btn-group')->setContent($btn_paperclip . $btn_file . $btn_size . $btn_remove);
         return $ret;
     }
     return '';
 }
예제 #6
0
파일: TraitEntity.php 프로젝트: larakit/lk
 static function getEntityNamePlural($cnt)
 {
     return HelperText::plural($cnt, static::translate('plurals.1'), static::translate('plurals.2'), static::translate('plurals.5'), static::translate('plurals.0'));
 }