@@ -118,8 +118,9 @@ |
||
| 118 | 118 | function rotate($direction) |
| 119 | 119 | { |
| 120 | 120 | $degrees = 90; |
| 121 | - if ($direction == 2) |
|
| 122 | - $degrees = 270; |
|
| 121 | + if ($direction == 2) { |
|
| 122 | + $degrees = 270; |
|
| 123 | + } |
|
| 123 | 124 | $this->image = imagerotate($this->image, $degrees, 0); |
| 124 | 125 | } |
| 125 | 126 | |
@@ -44,11 +44,13 @@ |
||
| 44 | 44 | |
| 45 | 45 | $this->getView()->registerJs("yiiDownloadAllLink = '" . Url::toRoute('files/default/zip') . "'", View::POS_BEGIN, 'yiiDownloadAllLink'); |
| 46 | 46 | |
| 47 | - if ($this->passFirst && sizeof($this->files) > 0) |
|
| 48 | - $this->files = array_slice($this->files, 1); |
|
| 47 | + if ($this->passFirst && sizeof($this->files) > 0) { |
|
| 48 | + $this->files = array_slice($this->files, 1); |
|
| 49 | + } |
|
| 49 | 50 | |
| 50 | - if (empty($this->files)) |
|
| 51 | - return null; |
|
| 51 | + if (empty($this->files)) { |
|
| 52 | + return null; |
|
| 53 | + } |
|
| 52 | 54 | |
| 53 | 55 | return $this->render('fileListWidget', [ |
| 54 | 56 | 'files' => $this->files, |
@@ -50,7 +50,8 @@ discard block |
||
| 50 | 50 | <?= $model->title ?> |
| 51 | 51 | </div> |
| 52 | 52 | </a> |
| 53 | - <?php else: ?> |
|
| 53 | + <?php else { |
|
| 54 | + : ?> |
|
| 54 | 55 | |
| 55 | 56 | |
| 56 | 57 | <div data-title="<?= $model->title ?>" |
@@ -78,7 +79,9 @@ discard block |
||
| 78 | 79 | <?= Yii::t('files', 'View') ?> |
| 79 | 80 | </a> |
| 80 | 81 | </li> |
| 81 | - <?php endif; ?> |
|
| 82 | + <?php endif; |
|
| 83 | +} |
|
| 84 | +?> |
|
| 82 | 85 | </ul> |
| 83 | 86 | |
| 84 | 87 | <?php endif; ?> |
@@ -27,18 +27,21 @@ discard block |
||
| 27 | 27 | public function __construct(array $data) |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - if (!isset($data['id'])) |
|
| 31 | - throw new BadRequestHttpException('ID of file is not set.'); |
|
| 30 | + if (!isset($data['id'])) { |
|
| 31 | + throw new BadRequestHttpException('ID of file is not set.'); |
|
| 32 | + } |
|
| 32 | 33 | |
| 33 | - if (!isset($data['title'])) |
|
| 34 | - throw new BadRequestHttpException('Title of file is not set.'); |
|
| 34 | + if (!isset($data['title'])) { |
|
| 35 | + throw new BadRequestHttpException('Title of file is not set.'); |
|
| 36 | + } |
|
| 35 | 37 | |
| 36 | 38 | $this->_title = $data['title']; |
| 37 | 39 | |
| 38 | 40 | $this->_file = File::findOne($data['id']); |
| 39 | 41 | |
| 40 | - if (!$this->_file) |
|
| 41 | - throw new NotFoundHttpException('File not found.'); |
|
| 42 | + if (!$this->_file) { |
|
| 43 | + throw new NotFoundHttpException('File not found.'); |
|
| 44 | + } |
|
| 42 | 45 | |
| 43 | 46 | } |
| 44 | 47 | |
@@ -50,8 +53,9 @@ discard block |
||
| 50 | 53 | { |
| 51 | 54 | $this->_file->title = $this->_title; |
| 52 | 55 | |
| 53 | - if (!$this->_file->save()) |
|
| 54 | - throw new BadRequestHttpException('Unable to save file.'); |
|
| 56 | + if (!$this->_file->save()) { |
|
| 57 | + throw new BadRequestHttpException('Unable to save file.'); |
|
| 58 | + } |
|
| 55 | 59 | |
| 56 | 60 | return $this->_title; |
| 57 | 61 | } |
@@ -30,14 +30,17 @@ discard block |
||
| 30 | 30 | { |
| 31 | 31 | $this->_file = File::findOne($data['id']); |
| 32 | 32 | |
| 33 | - if (!$this->_file) |
|
| 34 | - throw new NotFoundHttpException('File not found'); |
|
| 33 | + if (!$this->_file) { |
|
| 34 | + throw new NotFoundHttpException('File not found'); |
|
| 35 | + } |
|
| 35 | 36 | |
| 36 | - if ($this->_file->type != FileType::IMAGE) |
|
| 37 | - throw new BadRequestHttpException('Requested file is not an image.'); |
|
| 37 | + if ($this->_file->type != FileType::IMAGE) { |
|
| 38 | + throw new BadRequestHttpException('Requested file is not an image.'); |
|
| 39 | + } |
|
| 38 | 40 | |
| 39 | - if (!file_exists($this->_file->rootPath)) |
|
| 40 | - throw new BadRequestHttpException('File not found in file storage.'); |
|
| 41 | + if (!file_exists($this->_file->rootPath)) { |
|
| 42 | + throw new BadRequestHttpException('File not found in file storage.'); |
|
| 43 | + } |
|
| 41 | 44 | |
| 42 | 45 | $this->_height = (int)$data['height']; |
| 43 | 46 | $this->_width = (int)$data['width']; |
@@ -79,8 +82,9 @@ discard block |
||
| 79 | 82 | if ($this->_file->save()) { |
| 80 | 83 | @unlink($oldPath); |
| 81 | 84 | return $this->_file->href; |
| 82 | - } else |
|
| 83 | - throw new ErrorException("Error while saving file model."); |
|
| 85 | + } else { |
|
| 86 | + throw new ErrorException("Error while saving file model."); |
|
| 87 | + } |
|
| 84 | 88 | |
| 85 | 89 | |
| 86 | 90 | } |
@@ -20,14 +20,17 @@ discard block |
||
| 20 | 20 | public function __construct($storagePath) |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - if (!$storagePath) |
|
| 24 | - throw new ErrorException('Storage path not set for path generator.'); |
|
| 23 | + if (!$storagePath) { |
|
| 24 | + throw new ErrorException('Storage path not set for path generator.'); |
|
| 25 | + } |
|
| 25 | 26 | |
| 26 | - if (!file_exists($storagePath)) |
|
| 27 | - mkdir($storagePath); |
|
| 27 | + if (!file_exists($storagePath)) { |
|
| 28 | + mkdir($storagePath); |
|
| 29 | + } |
|
| 28 | 30 | |
| 29 | - if (!file_exists($storagePath)) |
|
| 30 | - throw new ErrorException('Unable to create storage.'); |
|
| 31 | + if (!file_exists($storagePath)) { |
|
| 32 | + throw new ErrorException('Unable to create storage.'); |
|
| 33 | + } |
|
| 31 | 34 | |
| 32 | 35 | $folderName0 = rand(10, 99); |
| 33 | 36 | $folderName1 = rand(10, 99); |
@@ -38,10 +41,12 @@ discard block |
||
| 38 | 41 | $fullPath0 = $storagePath . $path0; |
| 39 | 42 | $fullPath1 = $storagePath . $path1; |
| 40 | 43 | |
| 41 | - if (!file_exists($fullPath0)) |
|
| 42 | - mkdir($fullPath0); |
|
| 43 | - if (!file_exists($fullPath1)) |
|
| 44 | - mkdir($fullPath1); |
|
| 44 | + if (!file_exists($fullPath0)) { |
|
| 45 | + mkdir($fullPath0); |
|
| 46 | + } |
|
| 47 | + if (!file_exists($fullPath1)) { |
|
| 48 | + mkdir($fullPath1); |
|
| 49 | + } |
|
| 45 | 50 | |
| 46 | 51 | $this->path = $path1 . DIRECTORY_SEPARATOR . md5(rand(0, 1000) . time()); |
| 47 | 52 | } |
@@ -73,8 +73,9 @@ discard block |
||
| 73 | 73 | */ |
| 74 | 74 | private function checkFormToken() |
| 75 | 75 | { |
| 76 | - if (in_array($this->action->id, $this->actionsToCheck) && FileInputWidget::generateToken() != Yii::$app->request->post('_fileFormToken')) |
|
| 77 | - throw new BadRequestHttpException('File-form token is wrong or missing.'); |
|
| 76 | + if (in_array($this->action->id, $this->actionsToCheck) && FileInputWidget::generateToken() != Yii::$app->request->post('_fileFormToken')) { |
|
| 77 | + throw new BadRequestHttpException('File-form token is wrong or missing.'); |
|
| 78 | + } |
|
| 78 | 79 | } |
| 79 | 80 | |
| 80 | 81 | /** |
@@ -87,12 +88,14 @@ discard block |
||
| 87 | 88 | |
| 88 | 89 | $zip = new ZipArchive; |
| 89 | 90 | $filename = Yii::getAlias("@webroot/assets/files.zip"); |
| 90 | - if (file_exists($filename)) |
|
| 91 | - @unlink($filename); |
|
| 91 | + if (file_exists($filename)) { |
|
| 92 | + @unlink($filename); |
|
| 93 | + } |
|
| 92 | 94 | if (sizeof($files) && $zip->open($filename, ZipArchive::CREATE)) { |
| 93 | 95 | |
| 94 | - foreach ($files as $file) |
|
| 95 | - $zip->addFile($file->rootPath, $file->title); |
|
| 96 | + foreach ($files as $file) { |
|
| 97 | + $zip->addFile($file->rootPath, $file->title); |
|
| 98 | + } |
|
| 96 | 99 | |
| 97 | 100 | $zip->close(); |
| 98 | 101 | header("Pragma: public"); |
@@ -164,8 +167,9 @@ discard block |
||
| 164 | 167 | |
| 165 | 168 | $view = Yii::$app->request->post('mode') == 'single' ? "_single" : "_file"; |
| 166 | 169 | |
| 167 | - if ($ratio) |
|
| 168 | - $this->getView()->registerJs("initCropper({$model->id}, '{$model->href}', {$ratio}, true);"); |
|
| 170 | + if ($ratio) { |
|
| 171 | + $this->getView()->registerJs("initCropper({$model->id}, '{$model->href}', {$ratio}, true);"); |
|
| 172 | + } |
|
| 169 | 173 | |
| 170 | 174 | return $this->renderAjax($view, [ |
| 171 | 175 | 'model' => $model, |
@@ -182,11 +186,13 @@ discard block |
||
| 182 | 186 | { |
| 183 | 187 | $model = File::findOne(['hash' => $hash]); |
| 184 | 188 | |
| 185 | - if (!$model) |
|
| 186 | - throw new NotFoundHttpException("Запрашиваемый файл не найден"); |
|
| 189 | + if (!$model) { |
|
| 190 | + throw new NotFoundHttpException("Запрашиваемый файл не найден"); |
|
| 191 | + } |
|
| 187 | 192 | |
| 188 | - if (!file_exists($model->rootPath)) |
|
| 189 | - throw new NotFoundHttpException('Запрашиваемый файл не найден на диске.'); |
|
| 193 | + if (!file_exists($model->rootPath)) { |
|
| 194 | + throw new NotFoundHttpException('Запрашиваемый файл не найден на диске.'); |
|
| 195 | + } |
|
| 190 | 196 | |
| 191 | 197 | Yii::$app->response->headers->set('Last-Modified', date("c", $model->created)); |
| 192 | 198 | Yii::$app->response->headers->set('Cache-Control', 'public, max-age=' . (60 * 60 * 24 * 15)); |
@@ -216,14 +222,17 @@ discard block |
||
| 216 | 222 | { |
| 217 | 223 | $model = File::findOne(['hash' => $hash]); |
| 218 | 224 | |
| 219 | - if (!$model) |
|
| 220 | - throw new NotFoundHttpException("Запрашиваемый файл не найден"); |
|
| 225 | + if (!$model) { |
|
| 226 | + throw new NotFoundHttpException("Запрашиваемый файл не найден"); |
|
| 227 | + } |
|
| 221 | 228 | |
| 222 | - if ($model->type != FileType::IMAGE) |
|
| 223 | - throw new NotFoundHttpException("Запрашиваемый файл не является изображением"); |
|
| 229 | + if ($model->type != FileType::IMAGE) { |
|
| 230 | + throw new NotFoundHttpException("Запрашиваемый файл не является изображением"); |
|
| 231 | + } |
|
| 224 | 232 | |
| 225 | - if (!file_exists($model->rootPath)) |
|
| 226 | - throw new NotFoundHttpException('Запрашиваемый файл не найден на диске.'); |
|
| 233 | + if (!file_exists($model->rootPath)) { |
|
| 234 | + throw new NotFoundHttpException('Запрашиваемый файл не найден на диске.'); |
|
| 235 | + } |
|
| 227 | 236 | |
| 228 | 237 | Yii::$app->response->headers->set('Last-Modified', date("c", $model->created)); |
| 229 | 238 | Yii::$app->response->headers->set('Cache-Control', 'public, max-age=' . (60 * 60 * 24 * 15)); |
@@ -233,8 +242,9 @@ discard block |
||
| 233 | 242 | |
| 234 | 243 | $filename = Yii::createObject(ImagePreviewer::class, [$model, $width, $webp])->getUrl(); |
| 235 | 244 | |
| 236 | - if (!file_exists($filename)) |
|
| 237 | - throw new NotFoundHttpException('Запрашиваемый файл не найден на диске.'); |
|
| 245 | + if (!file_exists($filename)) { |
|
| 246 | + throw new NotFoundHttpException('Запрашиваемый файл не найден на диске.'); |
|
| 247 | + } |
|
| 238 | 248 | |
| 239 | 249 | $response = Yii::$app->response; |
| 240 | 250 | $response->format = Response::FORMAT_RAW; |
@@ -275,8 +285,9 @@ discard block |
||
| 275 | 285 | { |
| 276 | 286 | $model = File::findOne(['hash' => $hash]); |
| 277 | 287 | |
| 278 | - if (!$model) |
|
| 279 | - throw new NotFoundHttpException("Запрашиваемый файл не найден в базе."); |
|
| 288 | + if (!$model) { |
|
| 289 | + throw new NotFoundHttpException("Запрашиваемый файл не найден в базе."); |
|
| 290 | + } |
|
| 280 | 291 | |
| 281 | 292 | $response = Yii::$app->response; |
| 282 | 293 | $response->format = Response::FORMAT_RAW; |
@@ -285,8 +296,9 @@ discard block |
||
| 285 | 296 | Yii::$app->response->headers->set('Last-Modified', date("c", $model->created)); |
| 286 | 297 | Yii::$app->response->headers->set('Cache-Control', 'public, max-age=' . (60 * 60 * 24 * 15)); |
| 287 | 298 | |
| 288 | - if (!file_exists($model->rootPreviewPath)) |
|
| 289 | - throw new NotFoundHttpException('Preview not found.'); |
|
| 299 | + if (!file_exists($model->rootPreviewPath)) { |
|
| 300 | + throw new NotFoundHttpException('Preview not found.'); |
|
| 301 | + } |
|
| 290 | 302 | |
| 291 | 303 | $response->sendFile($model->rootPreviewPath, 'preview.jpg'); |
| 292 | 304 | |
@@ -17,8 +17,9 @@ discard block |
||
| 17 | 17 | use yii\helpers\Html; |
| 18 | 18 | use yii\web\View; |
| 19 | 19 | |
| 20 | -if (is_array($model)) |
|
| 20 | +if (is_array($model)) { |
|
| 21 | 21 | $model = $model[0]; |
| 22 | +} |
|
| 22 | 23 | |
| 23 | 24 | $doc_contents = [ |
| 24 | 25 | 'application/msword', |
@@ -38,7 +39,8 @@ discard block |
||
| 38 | 39 | <?= Html::hiddenInput((new ReflectionClass($model->class))->getShortName() . "[{$model->field}_ids][]", $model->id) ?> |
| 39 | 40 | </div> |
| 40 | 41 | |
| 41 | - <?php else: ?> |
|
| 42 | + <?php else { |
|
| 43 | + : ?> |
|
| 42 | 44 | |
| 43 | 45 | <div data-title="<?= $model->title ?>" |
| 44 | 46 | id="yii2-file-object-<?= $model->id ?>" |
@@ -52,7 +54,9 @@ discard block |
||
| 52 | 54 | <?php if ($model->type != FileType::IMAGE): ?> |
| 53 | 55 | <?= $model->icon ?> |
| 54 | 56 | <?= $model->title ?> |
| 55 | - <?php endif; ?> |
|
| 57 | + <?php endif; |
|
| 58 | +} |
|
| 59 | +?> |
|
| 56 | 60 | </div> |
| 57 | 61 | <?php endif; ?> |
| 58 | 62 | |
@@ -34,27 +34,31 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | $this->_onlyUploaded = $onlyUploaded; |
| 36 | 36 | |
| 37 | - if (!isset($data['attribute']) || !$data['attribute'] || !isset($data['modelClass']) || !$data['modelClass']) |
|
| 38 | - throw new BadRequestHttpException("Attribute or class name not set."); |
|
| 37 | + if (!isset($data['attribute']) || !$data['attribute'] || !isset($data['modelClass']) || !$data['modelClass']) { |
|
| 38 | + throw new BadRequestHttpException("Attribute or class name not set."); |
|
| 39 | + } |
|
| 39 | 40 | |
| 40 | 41 | // Загружаем полученные данные |
| 41 | 42 | $this->_instance = $file; |
| 42 | 43 | $this->_attribute = $data['attribute']; |
| 43 | 44 | |
| 44 | - if (!file_exists($this->_instance->tempName)) |
|
| 45 | - throw new ErrorException("Tmp file not found on disk."); |
|
| 45 | + if (!file_exists($this->_instance->tempName)) { |
|
| 46 | + throw new ErrorException("Tmp file not found on disk."); |
|
| 47 | + } |
|
| 46 | 48 | |
| 47 | 49 | // Инициализируем класс владельца файла для валидаций и ставим сценарий |
| 48 | 50 | $this->_owner = new $data['modelClass']; |
| 49 | 51 | |
| 50 | - if (isset($data['scenario'])) |
|
| 51 | - $this->_owner->setScenario($data['scenario']); |
|
| 52 | + if (isset($data['scenario'])) { |
|
| 53 | + $this->_owner->setScenario($data['scenario']); |
|
| 54 | + } |
|
| 52 | 55 | |
| 53 | 56 | |
| 54 | 57 | if (isset($this->_owner->behaviors['files']->attributes[$this->_attribute]['validator'])) { |
| 55 | 58 | foreach ($this->_owner->behaviors['files']->attributes[$this->_attribute]['validator'] as $validator) { |
| 56 | - if (!$validator->validate($this->_instance, $error)) |
|
| 57 | - throw new BadRequestHttpException($error); |
|
| 59 | + if (!$validator->validate($this->_instance, $error)) { |
|
| 60 | + throw new BadRequestHttpException($error); |
|
| 61 | + } |
|
| 58 | 62 | } |
| 59 | 63 | |
| 60 | 64 | } |
@@ -70,10 +74,12 @@ discard block |
||
| 70 | 74 | $this->_model->content_type = $this->_instance->type; |
| 71 | 75 | $this->_model->size = $this->_instance->size; |
| 72 | 76 | $this->_model->type = $this->detectType(); |
| 73 | - if ($identity) |
|
| 74 | - $this->_model->user_id = $identity->id; |
|
| 75 | - if ($this->_model->type == FileType::VIDEO) |
|
| 76 | - $this->_model->video_status = 0; |
|
| 77 | + if ($identity) { |
|
| 78 | + $this->_model->user_id = $identity->id; |
|
| 79 | + } |
|
| 80 | + if ($this->_model->type == FileType::VIDEO) { |
|
| 81 | + $this->_model->video_status = 0; |
|
| 82 | + } |
|
| 77 | 83 | |
| 78 | 84 | //Генерируем полный новый адрес сохранения файла |
| 79 | 85 | $this->_fullPath = Yii::$app->getModule('files')->storageFullPath . DIRECTORY_SEPARATOR . $this->_model->filename; |
@@ -85,10 +91,12 @@ discard block |
||
| 85 | 91 | public function detectType() |
| 86 | 92 | { |
| 87 | 93 | $contentTypeArray = explode('/', $this->_model->content_type); |
| 88 | - if ($contentTypeArray[0] == 'image') |
|
| 89 | - return FileType::IMAGE; |
|
| 90 | - if ($contentTypeArray[0] == 'video') |
|
| 91 | - return FileType::VIDEO; |
|
| 94 | + if ($contentTypeArray[0] == 'image') { |
|
| 95 | + return FileType::IMAGE; |
|
| 96 | + } |
|
| 97 | + if ($contentTypeArray[0] == 'video') { |
|
| 98 | + return FileType::VIDEO; |
|
| 99 | + } |
|
| 92 | 100 | return FileType::FILE; |
| 93 | 101 | } |
| 94 | 102 | |
@@ -101,10 +109,11 @@ discard block |
||
| 101 | 109 | $path = Yii::$app->getModule('files')->storageFullPath . $this->_model->filename; |
| 102 | 110 | |
| 103 | 111 | if ($this->_model->save()) { |
| 104 | - if (!$this->_onlyUploaded) |
|
| 105 | - copy($this->_instance->tempName, $this->_fullPath); |
|
| 106 | - else |
|
| 107 | - $this->_instance->saveAs($this->_fullPath, false); |
|
| 112 | + if (!$this->_onlyUploaded) { |
|
| 113 | + copy($this->_instance->tempName, $this->_fullPath); |
|
| 114 | + } else { |
|
| 115 | + $this->_instance->saveAs($this->_fullPath, false); |
|
| 116 | + } |
|
| 108 | 117 | } |
| 109 | 118 | |
| 110 | 119 | if ($this->_model->type == FileType::IMAGE) { |