@@ -86,29 +86,37 @@ discard block |
||
86 | 86 | { |
87 | 87 | $icon = IconHelper::FILE; |
88 | 88 | |
89 | - if ($this->content_type == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document') |
|
90 | - $icon = IconHelper::FILE_WORD; |
|
89 | + if ($this->content_type == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document') { |
|
90 | + $icon = IconHelper::FILE_WORD; |
|
91 | + } |
|
91 | 92 | |
92 | - if ($this->content_type == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') |
|
93 | - $icon = IconHelper::FILE_EXCEL; |
|
93 | + if ($this->content_type == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') { |
|
94 | + $icon = IconHelper::FILE_EXCEL; |
|
95 | + } |
|
94 | 96 | |
95 | - if ($this->content_type == 'application/vnd.openxmlformats-officedocument.presentationml.presentation') |
|
96 | - $icon = IconHelper::FILE_POWERPOINT; |
|
97 | + if ($this->content_type == 'application/vnd.openxmlformats-officedocument.presentationml.presentation') { |
|
98 | + $icon = IconHelper::FILE_POWERPOINT; |
|
99 | + } |
|
97 | 100 | |
98 | - if ($this->content_type == 'application/x-zip-compressed') |
|
99 | - $icon = IconHelper::FILE_ARCHIVE; |
|
101 | + if ($this->content_type == 'application/x-zip-compressed') { |
|
102 | + $icon = IconHelper::FILE_ARCHIVE; |
|
103 | + } |
|
100 | 104 | |
101 | - if ($this->content_type == 'application/octet-stream') |
|
102 | - $icon = IconHelper::FILE_ARCHIVE; |
|
105 | + if ($this->content_type == 'application/octet-stream') { |
|
106 | + $icon = IconHelper::FILE_ARCHIVE; |
|
107 | + } |
|
103 | 108 | |
104 | - if (preg_match('/audio/', $this->content_type)) |
|
105 | - $icon = IconHelper::FILE_AUDIO; |
|
109 | + if (preg_match('/audio/', $this->content_type)) { |
|
110 | + $icon = IconHelper::FILE_AUDIO; |
|
111 | + } |
|
106 | 112 | |
107 | - if (preg_match('/pdf/', $this->content_type)) |
|
108 | - $icon = IconHelper::FILE_PDF; |
|
113 | + if (preg_match('/pdf/', $this->content_type)) { |
|
114 | + $icon = IconHelper::FILE_PDF; |
|
115 | + } |
|
109 | 116 | |
110 | - if ($this->type == FileType::VIDEO) |
|
111 | - $icon = IconHelper::FILE_VIDEO; |
|
117 | + if ($this->type == FileType::VIDEO) { |
|
118 | + $icon = IconHelper::FILE_VIDEO; |
|
119 | + } |
|
112 | 120 | |
113 | 121 | return $icon; |
114 | 122 | } |
@@ -224,8 +232,9 @@ discard block |
||
224 | 232 | |
225 | 233 | public function getRootPreviewPath() |
226 | 234 | { |
227 | - if ($this->isSvg()) |
|
228 | - return $this->getRootPath(); |
|
235 | + if ($this->isSvg()) { |
|
236 | + return $this->getRootPath(); |
|
237 | + } |
|
229 | 238 | |
230 | 239 | return Yii::$app->getModule('files')->storageFullPath . DIRECTORY_SEPARATOR . $this->filename . '.jpg'; |
231 | 240 | } |
@@ -256,8 +265,9 @@ discard block |
||
256 | 265 | |
257 | 266 | public function getHref() |
258 | 267 | { |
259 | - if (Yii::$app->getModule('files')->hostStatic) |
|
260 | - return Yii::$app->getModule('files')->hostStatic . $this->filename; |
|
268 | + if (Yii::$app->getModule('files')->hostStatic) { |
|
269 | + return Yii::$app->getModule('files')->hostStatic . $this->filename; |
|
270 | + } |
|
261 | 271 | return Url::to(['/files/default/get', 'hash' => $this->hash]); |
262 | 272 | } |
263 | 273 | |
@@ -333,8 +343,9 @@ discard block |
||
333 | 343 | isset($this->behaviors['files']) && |
334 | 344 | isset($this->behaviors['files']->attributes[$this->field]) && |
335 | 345 | isset($this->behaviors['files']->attributes[$this->field]['watermark']) |
336 | - ) |
|
337 | - $this->behaviors['files']->attributes[$this->field]['watermark']; |
|
346 | + ) { |
|
347 | + $this->behaviors['files']->attributes[$this->field]['watermark']; |
|
348 | + } |
|
338 | 349 | } |
339 | 350 | |
340 | 351 | /** |
@@ -355,14 +366,17 @@ discard block |
||
355 | 366 | */ |
356 | 367 | public function getPreviewWebPath(int $width = 0, bool $webp = false) |
357 | 368 | { |
358 | - if (!file_exists($this->getRootPath())) |
|
359 | - return null; |
|
369 | + if (!file_exists($this->getRootPath())) { |
|
370 | + return null; |
|
371 | + } |
|
360 | 372 | |
361 | - if (!$this->isVideo() && !$this->isImage()) |
|
362 | - throw new \ErrorException('Requiested file is not an image and its implsible to resize it.'); |
|
373 | + if (!$this->isVideo() && !$this->isImage()) { |
|
374 | + throw new \ErrorException('Requiested file is not an image and its implsible to resize it.'); |
|
375 | + } |
|
363 | 376 | |
364 | - if (Yii::$app->getModule('files')->hostStatic) |
|
365 | - return Yii::$app->getModule('files')->hostStatic . $this->makeNameWithSize($this->filename, $width, $height, $webp = false); |
|
377 | + if (Yii::$app->getModule('files')->hostStatic) { |
|
378 | + return Yii::$app->getModule('files')->hostStatic . $this->makeNameWithSize($this->filename, $width, $height, $webp = false); |
|
379 | + } |
|
366 | 380 | |
367 | 381 | return Url::toRoute(['/files/default/image', 'hash' => $this->hash, 'width' => $width, 'height' => $height, 'webp' => $webp]); |
368 | 382 | } |
@@ -406,8 +420,9 @@ discard block |
||
406 | 420 | */ |
407 | 421 | public function getPreviewRootPath($width = 0, $webp = false) |
408 | 422 | { |
409 | - if (!$this->isVideo() && !$this->isImage()) |
|
410 | - throw new \ErrorException('Requiested file is not an image and its implsible to resize it.'); |
|
423 | + if (!$this->isVideo() && !$this->isImage()) { |
|
424 | + throw new \ErrorException('Requiested file is not an image and its implsible to resize it.'); |
|
425 | + } |
|
411 | 426 | return $this->makeNameWithSize($this->rootPath, $width, $webp); |
412 | 427 | } |
413 | 428 |
@@ -26,8 +26,9 @@ |
||
26 | 26 | */ |
27 | 27 | public function run(): ?string |
28 | 28 | { |
29 | - if (!in_array($this->model->type, [FileType::IMAGE, FileType::VIDEO])) |
|
30 | - return null; |
|
29 | + if (!in_array($this->model->type, [FileType::IMAGE, FileType::VIDEO])) { |
|
30 | + return null; |
|
31 | + } |
|
31 | 32 | return $this->render('pictureWidget', [ |
32 | 33 | 'model' => $this->model, |
33 | 34 | 'width' => $this->width, |
@@ -21,8 +21,9 @@ |
||
21 | 21 | */ |
22 | 22 | public function run(): ?string |
23 | 23 | { |
24 | - if ($this->model->type !== FileType::VIDEO) |
|
25 | - return null; |
|
24 | + if ($this->model->type !== FileType::VIDEO) { |
|
25 | + return null; |
|
26 | + } |
|
26 | 27 | $source = Html::tag('source', null, ['src' => $this->model->getHref(), 'type' => $this->model->content_type]); |
27 | 28 | return Html::tag('video', $source, $this->options); |
28 | 29 | } |
@@ -46,14 +46,17 @@ discard block |
||
46 | 46 | private function loadAndCheckModel(string $hash): void |
47 | 47 | { |
48 | 48 | $this->model = File::findOne(['hash' => $hash]); |
49 | - if (!$this->model) |
|
50 | - throw new NotFoundHttpException("Запрашиваемый файл не найден"); |
|
49 | + if (!$this->model) { |
|
50 | + throw new NotFoundHttpException("Запрашиваемый файл не найден"); |
|
51 | + } |
|
51 | 52 | |
52 | - if (!$this->model->isImage() && !$this->model->isVideo()) |
|
53 | - throw new NotFoundHttpException("Запрашиваемый файл не является изображением"); |
|
53 | + if (!$this->model->isImage() && !$this->model->isVideo()) { |
|
54 | + throw new NotFoundHttpException("Запрашиваемый файл не является изображением"); |
|
55 | + } |
|
54 | 56 | |
55 | - if (!file_exists($this->model->rootPath)) |
|
56 | - throw new NotFoundHttpException('Запрашиваемый файл не найден на диске.'); |
|
57 | + if (!file_exists($this->model->rootPath)) { |
|
58 | + throw new NotFoundHttpException('Запрашиваемый файл не найден на диске.'); |
|
59 | + } |
|
57 | 60 | } |
58 | 61 | |
59 | 62 | /** |
@@ -65,8 +68,9 @@ discard block |
||
65 | 68 | { |
66 | 69 | $filename = Yii::createObject(ImagePreviewer::class, [$this->model, $width, $webp])->getUrl(); |
67 | 70 | |
68 | - if (!file_exists($filename)) |
|
69 | - throw new NotFoundHttpException('Запрашиваемый файл не найден на диске.'); |
|
71 | + if (!file_exists($filename)) { |
|
72 | + throw new NotFoundHttpException('Запрашиваемый файл не найден на диске.'); |
|
73 | + } |
|
70 | 74 | |
71 | 75 | $response = Yii::$app->response; |
72 | 76 | $response->format = Response::FORMAT_RAW; |
@@ -14,11 +14,13 @@ |
||
14 | 14 | { |
15 | 15 | $model = File::findOne(['hash' => $hash]); |
16 | 16 | |
17 | - if (!$model) |
|
18 | - throw new NotFoundHttpException("Запрашиваемый файл не найден"); |
|
17 | + if (!$model) { |
|
18 | + throw new NotFoundHttpException("Запрашиваемый файл не найден"); |
|
19 | + } |
|
19 | 20 | |
20 | - if (!file_exists($model->rootPath)) |
|
21 | - throw new NotFoundHttpException('Запрашиваемый файл не найден на диске.'); |
|
21 | + if (!file_exists($model->rootPath)) { |
|
22 | + throw new NotFoundHttpException('Запрашиваемый файл не найден на диске.'); |
|
23 | + } |
|
22 | 24 | |
23 | 25 | Yii::$app->response->headers->set('Last-Modified', date("c", $model->created)); |
24 | 26 | Yii::$app->response->headers->set('Cache-Control', 'public, max-age=' . (60 * 60 * 24 * 15)); |
@@ -72,8 +72,9 @@ discard block |
||
72 | 72 | */ |
73 | 73 | private function checkFormToken() |
74 | 74 | { |
75 | - if (in_array($this->action->id, $this->actionsToCheck) && FileInputWidget::generateToken() != Yii::$app->request->post('_fileFormToken')) |
|
76 | - throw new BadRequestHttpException('File-form token is wrong or missing.'); |
|
75 | + if (in_array($this->action->id, $this->actionsToCheck) && FileInputWidget::generateToken() != Yii::$app->request->post('_fileFormToken')) { |
|
76 | + throw new BadRequestHttpException('File-form token is wrong or missing.'); |
|
77 | + } |
|
77 | 78 | } |
78 | 79 | |
79 | 80 | /** |
@@ -86,12 +87,14 @@ discard block |
||
86 | 87 | |
87 | 88 | $zip = new ZipArchive; |
88 | 89 | $filename = Yii::getAlias("@webroot/assets/files.zip"); |
89 | - if (file_exists($filename)) |
|
90 | - @unlink($filename); |
|
90 | + if (file_exists($filename)) { |
|
91 | + @unlink($filename); |
|
92 | + } |
|
91 | 93 | if (sizeof($files) && $zip->open($filename, ZipArchive::CREATE)) { |
92 | 94 | |
93 | - foreach ($files as $file) |
|
94 | - $zip->addFile($file->rootPath, $file->title); |
|
95 | + foreach ($files as $file) { |
|
96 | + $zip->addFile($file->rootPath, $file->title); |
|
97 | + } |
|
95 | 98 | |
96 | 99 | $zip->close(); |
97 | 100 | header("Pragma: public"); |
@@ -163,8 +166,9 @@ discard block |
||
163 | 166 | |
164 | 167 | $view = Yii::$app->request->post('mode') == 'single' ? "_single" : "_file"; |
165 | 168 | |
166 | - if ($ratio) |
|
167 | - $this->getView()->registerJs("initCropper({$model->id}, '{$model->href}', {$ratio}, true);"); |
|
169 | + if ($ratio) { |
|
170 | + $this->getView()->registerJs("initCropper({$model->id}, '{$model->href}', {$ratio}, true);"); |
|
171 | + } |
|
168 | 172 | |
169 | 173 | return $this->renderAjax($view, [ |
170 | 174 | 'model' => $model, |
@@ -190,8 +194,9 @@ discard block |
||
190 | 194 | { |
191 | 195 | $model = File::findOne(['hash' => $hash]); |
192 | 196 | |
193 | - if (!$model) |
|
194 | - throw new NotFoundHttpException("Запрашиваемый файл не найден в базе."); |
|
197 | + if (!$model) { |
|
198 | + throw new NotFoundHttpException("Запрашиваемый файл не найден в базе."); |
|
199 | + } |
|
195 | 200 | |
196 | 201 | $response = Yii::$app->response; |
197 | 202 | $response->format = Response::FORMAT_RAW; |
@@ -200,8 +205,9 @@ discard block |
||
200 | 205 | Yii::$app->response->headers->set('Last-Modified', date("c", $model->created)); |
201 | 206 | Yii::$app->response->headers->set('Cache-Control', 'public, max-age=' . (60 * 60 * 24 * 15)); |
202 | 207 | |
203 | - if (!file_exists($model->rootPreviewPath)) |
|
204 | - throw new NotFoundHttpException('Preview not found.'); |
|
208 | + if (!file_exists($model->rootPreviewPath)) { |
|
209 | + throw new NotFoundHttpException('Preview not found.'); |
|
210 | + } |
|
205 | 211 | |
206 | 212 | $response->sendFile($model->rootPreviewPath, 'preview.jpg'); |
207 | 213 |
@@ -18,14 +18,17 @@ discard block |
||
18 | 18 | { |
19 | 19 | $this->ffmpegBin = Yii::$app->getModule('files')->ffmpeg; |
20 | 20 | |
21 | - if (!file_exists($this->ffmpegBin)) |
|
22 | - throw new \ErrorException("ffmpeg is not found: {$this->ffmpegBin}"); |
|
21 | + if (!file_exists($this->ffmpegBin)) { |
|
22 | + throw new \ErrorException("ffmpeg is not found: {$this->ffmpegBin}"); |
|
23 | + } |
|
23 | 24 | |
24 | - if (!is_executable($this->ffmpegBin)) |
|
25 | - throw new \ErrorException("ffmpeg is not executable: {$this->ffmpegBin}"); |
|
25 | + if (!is_executable($this->ffmpegBin)) { |
|
26 | + throw new \ErrorException("ffmpeg is not executable: {$this->ffmpegBin}"); |
|
27 | + } |
|
26 | 28 | |
27 | - if (!is_file($videoSourceFilename)) |
|
28 | - throw new \ErrorException('File not found on disk.'); |
|
29 | + if (!is_file($videoSourceFilename)) { |
|
30 | + throw new \ErrorException('File not found on disk.'); |
|
31 | + } |
|
29 | 32 | |
30 | 33 | $this->videoSourceFilename = $videoSourceFilename; |
31 | 34 | $this->outputImageFilename = $outputImageFilename; |
@@ -38,8 +41,9 @@ discard block |
||
38 | 41 | { |
39 | 42 | $command = "{$this->ffmpegBin} -i {$this->videoSourceFilename} -ss 00:00:03.000 -vframes 1 {$this->outputImageFilename}"; |
40 | 43 | exec($command, $out, $result); |
41 | - if ($result !== 0) |
|
42 | - throw new \ErrorException('FFmpeg frame extracting fail:' . print_r($out, true)); |
|
44 | + if ($result !== 0) { |
|
45 | + throw new \ErrorException('FFmpeg frame extracting fail:' . print_r($out, true)); |
|
46 | + } |
|
43 | 47 | } |
44 | 48 | |
45 | 49 | } |
@@ -30,8 +30,9 @@ discard block |
||
30 | 30 | $this->width = $width; |
31 | 31 | $this->webp = $webp; |
32 | 32 | |
33 | - if (!$this->model->isImage() && !$this->model->isVideo()) |
|
34 | - throw new ErrorException('File is not an image or video.'); |
|
33 | + if (!$this->model->isImage() && !$this->model->isVideo()) { |
|
34 | + throw new ErrorException('File is not an image or video.'); |
|
35 | + } |
|
35 | 36 | } |
36 | 37 | |
37 | 38 | /** |
@@ -39,8 +40,9 @@ discard block |
||
39 | 40 | */ |
40 | 41 | public function getUrl() |
41 | 42 | { |
42 | - if ($this->model->isSvg()) |
|
43 | - return $this->model->getRootPath(); |
|
43 | + if ($this->model->isSvg()) { |
|
44 | + return $this->model->getRootPath(); |
|
45 | + } |
|
44 | 46 | |
45 | 47 | $cachePath = Yii::$app->getModule('files')->cacheFullPath; |
46 | 48 | $jpegName = $this->model->makeNameWithSize($this->model->filename, $this->width); |
@@ -54,21 +56,25 @@ discard block |
||
54 | 56 | $sourceImagePath = $this->model->rootPath; |
55 | 57 | if ($this->model->isVideo()) { |
56 | 58 | $sourceImagePath = $this->fileName . '.jpeg'; |
57 | - if (!is_file($sourceImagePath)) |
|
58 | - Yii::createObject(VideoFrameExtractor::class, [ |
|
59 | + if (!is_file($sourceImagePath)) { |
|
60 | + Yii::createObject(VideoFrameExtractor::class, [ |
|
59 | 61 | $this->model->rootPath, |
60 | 62 | $sourceImagePath |
61 | 63 | ])->extract(); |
64 | + } |
|
62 | 65 | } |
63 | 66 | |
64 | - if (!is_file($this->fileName) || filesize($this->fileName) == 0) |
|
65 | - $this->createPreview($sourceImagePath); |
|
67 | + if (!is_file($this->fileName) || filesize($this->fileName) == 0) { |
|
68 | + $this->createPreview($sourceImagePath); |
|
69 | + } |
|
66 | 70 | |
67 | - if ($this->webp && !file_exists($this->fileNameWebp)) |
|
68 | - $this->createPreviewWebp(); |
|
71 | + if ($this->webp && !file_exists($this->fileNameWebp)) { |
|
72 | + $this->createPreviewWebp(); |
|
73 | + } |
|
69 | 74 | |
70 | - if ($this->webp) |
|
71 | - return $this->fileNameWebp; |
|
75 | + if ($this->webp) { |
|
76 | + return $this->fileNameWebp; |
|
77 | + } |
|
72 | 78 | |
73 | 79 | return $this->fileName; |
74 | 80 | } |
@@ -78,20 +84,24 @@ discard block |
||
78 | 84 | */ |
79 | 85 | protected function prepareFolder() |
80 | 86 | { |
81 | - if (!file_exists(Yii::$app->getModule('files')->cacheFullPath)) |
|
82 | - mkdir(Yii::$app->getModule('files')->cacheFullPath); |
|
87 | + if (!file_exists(Yii::$app->getModule('files')->cacheFullPath)) { |
|
88 | + mkdir(Yii::$app->getModule('files')->cacheFullPath); |
|
89 | + } |
|
83 | 90 | $folders = []; |
84 | 91 | $lastFolder = '/'; |
85 | 92 | $explodes = explode('/', $this->fileName); |
86 | 93 | array_pop($explodes); |
87 | - if (empty($explodes)) |
|
88 | - return; |
|
94 | + if (empty($explodes)) { |
|
95 | + return; |
|
96 | + } |
|
89 | 97 | foreach ($explodes as $folder) { |
90 | - if (empty($folder)) |
|
91 | - continue; |
|
98 | + if (empty($folder)) { |
|
99 | + continue; |
|
100 | + } |
|
92 | 101 | $lastFolder = $lastFolder . $folder . '/'; |
93 | - if (!file_exists($lastFolder)) |
|
94 | - mkdir($lastFolder); |
|
102 | + if (!file_exists($lastFolder)) { |
|
103 | + mkdir($lastFolder); |
|
104 | + } |
|
95 | 105 | $folders[] = $lastFolder; |
96 | 106 | } |
97 | 107 | } |
@@ -113,8 +123,9 @@ discard block |
||
113 | 123 | } |
114 | 124 | |
115 | 125 | $saveType = $img->image_type; |
116 | - if ($saveType == IMG_WEBP || $saveType == IMG_QUADRATIC) |
|
117 | - $saveType = IMG_JPEG; |
|
126 | + if ($saveType == IMG_WEBP || $saveType == IMG_QUADRATIC) { |
|
127 | + $saveType = IMG_JPEG; |
|
128 | + } |
|
118 | 129 | $img->save($this->fileName, $saveType); |
119 | 130 | } |
120 | 131 |