@@ -33,12 +33,12 @@ discard block |
||
33 | 33 | parent::before(); |
34 | 34 | $configs = AppRecord::getConfigs('app', 'Content'); |
35 | 35 | // prevent null-type config data |
36 | - if ((int)$configs['gallerySize'] > 0) { |
|
37 | - $this->maxSize = (int)$configs['gallerySize'] * 1024; |
|
36 | + if ((int) $configs['gallerySize'] > 0) { |
|
37 | + $this->maxSize = (int) $configs['gallerySize'] * 1024; |
|
38 | 38 | } |
39 | 39 | |
40 | - if ((int)$configs['galleryResize'] > 0) { |
|
41 | - $this->maxResize = (int)$configs['galleryResize']; |
|
40 | + if ((int) $configs['galleryResize'] > 0) { |
|
41 | + $this->maxResize = (int) $configs['galleryResize']; |
|
42 | 42 | } |
43 | 43 | } |
44 | 44 | |
@@ -117,8 +117,8 @@ discard block |
||
117 | 117 | } |
118 | 118 | |
119 | 119 | // check if directory exist |
120 | - if (!Directory::exist('/upload/gallery/' . $id)) { |
|
121 | - Directory::create('/upload/gallery/' . $id); |
|
120 | + if (!Directory::exist('/upload/gallery/'.$id)) { |
|
121 | + Directory::create('/upload/gallery/'.$id); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | // get file object |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | |
131 | 131 | // check file size |
132 | 132 | if ($file->getSize() < 1 || $file->getSize() > $this->maxSize) { |
133 | - throw new ForbiddenException(__('File size is too big. Max size: %size%kb', ['size' => (int)($this->maxSize/1024)])); |
|
133 | + throw new ForbiddenException(__('File size is too big. Max size: %size%kb', ['size' => (int) ($this->maxSize / 1024)])); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | // check file extension |
@@ -139,41 +139,41 @@ discard block |
||
139 | 139 | } |
140 | 140 | |
141 | 141 | // create origin directory |
142 | - $originPath = '/upload/gallery/' . $id . '/orig/'; |
|
142 | + $originPath = '/upload/gallery/'.$id.'/orig/'; |
|
143 | 143 | if (!Directory::exist($originPath)) { |
144 | 144 | Directory::create($originPath); |
145 | 145 | } |
146 | 146 | |
147 | 147 | // lets make a new file name |
148 | - $fileName = App::$Security->simpleHash($file->getClientOriginalName() . $file->getSize()); |
|
149 | - $fileNewName = $fileName . '.' . $file->guessExtension(); |
|
148 | + $fileName = App::$Security->simpleHash($file->getClientOriginalName().$file->getSize()); |
|
149 | + $fileNewName = $fileName.'.'.$file->guessExtension(); |
|
150 | 150 | // check if image is already loaded |
151 | - if (File::exist($originPath . $fileNewName)) { |
|
151 | + if (File::exist($originPath.$fileNewName)) { |
|
152 | 152 | throw new ForbiddenException(__('File is always exists!')); |
153 | 153 | } |
154 | 154 | // save file from tmp to gallery origin directory |
155 | 155 | $file->move(Normalize::diskFullPath($originPath), $fileNewName); |
156 | 156 | |
157 | 157 | // lets resize preview image for it |
158 | - $thumbPath = '/upload/gallery/' . $id . '/thumb/'; |
|
158 | + $thumbPath = '/upload/gallery/'.$id.'/thumb/'; |
|
159 | 159 | if (!Directory::exist($thumbPath)) { |
160 | 160 | Directory::create($thumbPath); |
161 | 161 | } |
162 | 162 | |
163 | 163 | $thumb = new Image(); |
164 | - $thumb->setCacheDir(root . '/Private/Cache/images'); |
|
164 | + $thumb->setCacheDir(root.'/Private/Cache/images'); |
|
165 | 165 | |
166 | 166 | // open original file, resize it and save |
167 | - $thumbSaveName = Normalize::diskFullPath($thumbPath) . '/' . $fileName . '.jpg'; |
|
168 | - $thumb->open(Normalize::diskFullPath($originPath) . DIRECTORY_SEPARATOR . $fileNewName) |
|
167 | + $thumbSaveName = Normalize::diskFullPath($thumbPath).'/'.$fileName.'.jpg'; |
|
168 | + $thumb->open(Normalize::diskFullPath($originPath).DIRECTORY_SEPARATOR.$fileNewName) |
|
169 | 169 | ->cropResize($this->maxResize) |
170 | 170 | ->save($thumbSaveName, 'jpg', 90); |
171 | 171 | $thumb = null; |
172 | 172 | |
173 | 173 | $this->setJsonHeader(); |
174 | 174 | return json_encode(['status' => 1, 'file' => [ |
175 | - 'thumbnailUrl' => '/upload/gallery/' . $id . '/thumb/' . $fileName . '.jpg', |
|
176 | - 'url' => '/upload/gallery/' . $id . '/orig/' . $fileNewName, |
|
175 | + 'thumbnailUrl' => '/upload/gallery/'.$id.'/thumb/'.$fileName.'.jpg', |
|
176 | + 'url' => '/upload/gallery/'.$id.'/orig/'.$fileNewName, |
|
177 | 177 | 'name' => $fileNewName |
178 | 178 | ]]); |
179 | 179 | } |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | throw new NativeException('Permission denied'); |
198 | 198 | } |
199 | 199 | |
200 | - $thumbDir = Normalize::diskFullPath('/upload/gallery/' . $id . '/orig/'); |
|
200 | + $thumbDir = Normalize::diskFullPath('/upload/gallery/'.$id.'/orig/'); |
|
201 | 201 | if (!Directory::exist($thumbDir)) { |
202 | 202 | throw new NotFoundException('Nothing found'); |
203 | 203 | } |
@@ -212,10 +212,10 @@ discard block |
||
212 | 212 | $fileExt = Str::lastIn($file, '.'); |
213 | 213 | $fileName = Str::sub($file, 0, -Str::length($fileExt)); |
214 | 214 | $output[] = [ |
215 | - 'thumbnailUrl' => '/upload/gallery/' . $id . '/thumb/' . $fileName . '.jpg', |
|
216 | - 'url' => '/upload/gallery/' . $id . '/orig/' . $file, |
|
215 | + 'thumbnailUrl' => '/upload/gallery/'.$id.'/thumb/'.$fileName.'.jpg', |
|
216 | + 'url' => '/upload/gallery/'.$id.'/orig/'.$file, |
|
217 | 217 | 'name' => $file, |
218 | - 'size' => File::size('/upload/gallery/' . $id . '/orig/' . $file) |
|
218 | + 'size' => File::size('/upload/gallery/'.$id.'/orig/'.$file) |
|
219 | 219 | ]; |
220 | 220 | } |
221 | 221 | |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | public function actionGallerydelete($id, $file = null) |
235 | 235 | { |
236 | 236 | if ($file === null || Str::likeEmpty($file)) { |
237 | - $file = (string)$this->request->query->get('file', null); |
|
237 | + $file = (string) $this->request->query->get('file', null); |
|
238 | 238 | } |
239 | 239 | // check passed data |
240 | 240 | if (Str::likeEmpty($file) || !Obj::isLikeInt($id)) { |
@@ -249,8 +249,8 @@ discard block |
||
249 | 249 | } |
250 | 250 | |
251 | 251 | // generate path |
252 | - $thumb = '/upload/gallery/' . $id . '/thumb/' . $fileName . '.jpg'; |
|
253 | - $full = '/upload/gallery/' . $id . '/orig/' . $file; |
|
252 | + $thumb = '/upload/gallery/'.$id.'/thumb/'.$fileName.'.jpg'; |
|
253 | + $full = '/upload/gallery/'.$id.'/orig/'.$file; |
|
254 | 254 | |
255 | 255 | // check if file exists and remove |
256 | 256 | if (File::exist($thumb) || File::exist($full)) { |