@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | 'webp', |
37 | 37 | ], |
38 | 38 | 'path' => 'files', |
39 | - 'background' => [255, 255, 255, 127], |
|
39 | + 'background' => [ 255, 255, 255, 127 ], |
|
40 | 40 | 'watermark' => '', |
41 | - 'thumbs' => [], |
|
41 | + 'thumbs' => [ ], |
|
42 | 42 | ]; |
43 | 43 | |
44 | 44 | /** |
@@ -46,22 +46,22 @@ discard block |
||
46 | 46 | * |
47 | 47 | * @var array |
48 | 48 | */ |
49 | - protected $_files = []; |
|
49 | + protected $_files = [ ]; |
|
50 | 50 | |
51 | 51 | /** |
52 | 52 | * {@inheritDoc} |
53 | 53 | */ |
54 | 54 | public function initialize(array $config) |
55 | 55 | { |
56 | - $this->_config = []; |
|
56 | + $this->_config = [ ]; |
|
57 | 57 | |
58 | 58 | foreach ($config as $field => $fieldOptions) { |
59 | 59 | if (is_array($fieldOptions)) { |
60 | - $this->_config[$this->getTable()->getAlias()][$field] = array_merge($this->_defaultConfig, $fieldOptions); |
|
60 | + $this->_config[ $this->getTable()->getAlias() ][ $field ] = array_merge($this->_defaultConfig, $fieldOptions); |
|
61 | 61 | } else { |
62 | 62 | $field = $fieldOptions; |
63 | 63 | |
64 | - $this->_config[$this->getTable()->getAlias()][$field] = $this->_defaultConfig; |
|
64 | + $this->_config[ $this->getTable()->getAlias() ][ $field ] = $this->_defaultConfig; |
|
65 | 65 | } |
66 | 66 | } |
67 | 67 | } |
@@ -69,37 +69,37 @@ discard block |
||
69 | 69 | /** |
70 | 70 | * {@inheritDoc} |
71 | 71 | */ |
72 | - public function beforeMarshal(Event $event, $data = [], $options = []) |
|
72 | + public function beforeMarshal(Event $event, $data = [ ], $options = [ ]) |
|
73 | 73 | { |
74 | - if (!empty($config = $this->_config[$this->getTable()->getAlias()])) { |
|
74 | + if (!empty($config = $this->_config[ $this->getTable()->getAlias() ])) { |
|
75 | 75 | foreach ($config as $field => $fieldOptions) { |
76 | - if (is_numeric(key($data[$field]))) { |
|
77 | - foreach ($data[$field] as $r => $fileMuptlipe) { |
|
76 | + if (is_numeric(key($data[ $field ]))) { |
|
77 | + foreach ($data[ $field ] as $r => $fileMuptlipe) { |
|
78 | 78 | // Create archive file data with suffix on original field name |
79 | 79 | // @todo Create only when field name is used in database |
80 | - $data['_' . $r . '_' . $field] = $data[$field][$r]; |
|
80 | + $data[ '_'.$r.'_'.$field ] = $data[ $field ][ $r ]; |
|
81 | 81 | |
82 | - $this->_files[$r . '_' . $field] = $data[$field][$r]; |
|
83 | - $this->_files[$r . '_' . $field]['path'] = $this->_prepareDir($fieldOptions['path']); |
|
84 | - $this->_files[$r . '_' . $field]['name'] = $this->_prepareName($r . '_' . $field); |
|
82 | + $this->_files[ $r.'_'.$field ] = $data[ $field ][ $r ]; |
|
83 | + $this->_files[ $r.'_'.$field ][ 'path' ] = $this->_prepareDir($fieldOptions[ 'path' ]); |
|
84 | + $this->_files[ $r.'_'.$field ][ 'name' ] = $this->_prepareName($r.'_'.$field); |
|
85 | 85 | |
86 | - $data[$r . '_' . $field] = $this->_files[$r . '_' . $field]['name']; |
|
86 | + $data[ $r.'_'.$field ] = $this->_files[ $r.'_'.$field ][ 'name' ]; |
|
87 | 87 | } |
88 | - } elseif (isset($data[$field]) && !empty($data[$field]['name']) && file_exists($data[$field]['tmp_name'])) { |
|
88 | + } elseif (isset($data[ $field ]) && !empty($data[ $field ][ 'name' ]) && file_exists($data[ $field ][ 'tmp_name' ])) { |
|
89 | 89 | // Create archive file data with suffix on original field name |
90 | 90 | // @todo Create only when field name is used in database |
91 | 91 | // @todo Duplicate code |
92 | - $data['_' . $field] = $data[$field]; |
|
92 | + $data[ '_'.$field ] = $data[ $field ]; |
|
93 | 93 | |
94 | - $this->_files[$field] = $data[$field]; |
|
95 | - $this->_files[$field]['path'] = $this->_prepareDir($fieldOptions['path']); |
|
96 | - $this->_files[$field]['name'] = $this->_prepareName($field); |
|
94 | + $this->_files[ $field ] = $data[ $field ]; |
|
95 | + $this->_files[ $field ][ 'path' ] = $this->_prepareDir($fieldOptions[ 'path' ]); |
|
96 | + $this->_files[ $field ][ 'name' ] = $this->_prepareName($field); |
|
97 | 97 | |
98 | - $data[$field] = $this->_files[$field]['name']; |
|
98 | + $data[ $field ] = $this->_files[ $field ][ 'name' ]; |
|
99 | 99 | } else { |
100 | - if (isset($data[$field]) && is_array($data[$field])) { |
|
100 | + if (isset($data[ $field ]) && is_array($data[ $field ])) { |
|
101 | 101 | // Delete file array from data when is not attached |
102 | - unset($data[$field]); |
|
102 | + unset($data[ $field ]); |
|
103 | 103 | } |
104 | 104 | } |
105 | 105 | } |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | /** |
110 | 110 | * {@inheritDoc} |
111 | 111 | */ |
112 | - public function afterSave(Event $event, EntityInterface $entity, $options = []) |
|
112 | + public function afterSave(Event $event, EntityInterface $entity, $options = [ ]) |
|
113 | 113 | { |
114 | 114 | $this->prepareFile($entity); |
115 | 115 | } |
@@ -131,16 +131,16 @@ discard block |
||
131 | 131 | { |
132 | 132 | foreach ($this->_files as $fieldName => $fieldOptions) { |
133 | 133 | // Path to default file |
134 | - $fileName = $fieldOptions['path'] . DS . $this->_files[$fieldName]['name']; |
|
134 | + $fileName = $fieldOptions[ 'path' ].DS.$this->_files[ $fieldName ][ 'name' ]; |
|
135 | 135 | |
136 | - if (move_uploaded_file($fieldOptions['tmp_name'], $fileName) || (file_exists($fieldOptions['tmp_name']) && rename($fieldOptions['tmp_name'], $fileName))) { |
|
136 | + if (move_uploaded_file($fieldOptions[ 'tmp_name' ], $fileName) || (file_exists($fieldOptions[ 'tmp_name' ]) && rename($fieldOptions[ 'tmp_name' ], $fileName))) { |
|
137 | 137 | if (preg_match('/^[0-9]+_/', $fieldName, $fieldMatches)) { |
138 | - $fieldName = preg_replace('/^' . $fieldMatches[0] . '/', '', $fieldName); |
|
138 | + $fieldName = preg_replace('/^'.$fieldMatches[ 0 ].'/', '', $fieldName); |
|
139 | 139 | } |
140 | 140 | |
141 | - $fileTypes = $this->_config[$this->getTable()->getAlias()][$fieldName]; |
|
141 | + $fileTypes = $this->_config[ $this->getTable()->getAlias() ][ $fieldName ]; |
|
142 | 142 | |
143 | - if (isset($fieldOptions['type']) && mb_strpos($fieldOptions['type'], 'image/') !== false && in_array(mb_strtolower($fieldOptions['type']), $fileTypes['types'])) { |
|
143 | + if (isset($fieldOptions[ 'type' ]) && mb_strpos($fieldOptions[ 'type' ], 'image/') !== false && in_array(mb_strtolower($fieldOptions[ 'type' ]), $fileTypes[ 'types' ])) { |
|
144 | 144 | $this->prepareThumbs($fileName, $fileTypes); |
145 | 145 | } |
146 | 146 | } |
@@ -158,16 +158,16 @@ discard block |
||
158 | 158 | // Get field list of model schema |
159 | 159 | $modelSchema = $model->schema(); |
160 | 160 | |
161 | - foreach ($this->settings[$model->alias] as $fieldName => $fieldOptions) { |
|
161 | + foreach ($this->settings[ $model->alias ] as $fieldName => $fieldOptions) { |
|
162 | 162 | // Check is field in model schema |
163 | - if (isset($modelSchema[$fieldName])) { |
|
163 | + if (isset($modelSchema[ $fieldName ])) { |
|
164 | 164 | $dataField = $model->findById($model->id); |
165 | 165 | |
166 | - if (is_array($dataField) && !empty($dataField[$model->alias][$fieldName])) { |
|
166 | + if (is_array($dataField) && !empty($dataField[ $model->alias ][ $fieldName ])) { |
|
167 | 167 | // Pattern for original file with thumbs |
168 | - $filePattern = $this->settings[$model->alias][$fieldName]['path'] . DS . substr($dataField[$model->alias][$fieldName], 0, 14); |
|
168 | + $filePattern = $this->settings[ $model->alias ][ $fieldName ][ 'path' ].DS.substr($dataField[ $model->alias ][ $fieldName ], 0, 14); |
|
169 | 169 | |
170 | - foreach (glob($filePattern . '*') as $fileName) { |
|
170 | + foreach (glob($filePattern.'*') as $fileName) { |
|
171 | 171 | // Remove file |
172 | 172 | @unlink($fileName); |
173 | 173 | } |
@@ -189,14 +189,14 @@ discard block |
||
189 | 189 | { |
190 | 190 | if (is_file($originalFile) && is_array($settingParams)) { |
191 | 191 | // Check image library |
192 | - if (!extension_loaded($settingParams['library'])) { |
|
193 | - throw new LibraryException(__d('file', 'The library identified by {0} is not loaded!', $settingParams['library'])); |
|
192 | + if (!extension_loaded($settingParams[ 'library' ])) { |
|
193 | + throw new LibraryException(__d('file', 'The library identified by {0} is not loaded!', $settingParams[ 'library' ])); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | // Get extension from original file |
197 | 197 | $fileExtension = $this->getExtension($originalFile); |
198 | 198 | |
199 | - switch ($settingParams['library']) { |
|
199 | + switch ($settingParams[ 'library' ]) { |
|
200 | 200 | // Get image resource |
201 | 201 | case 'gd': |
202 | 202 | switch ($fileExtension) { |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | |
235 | 235 | break; |
236 | 236 | default: |
237 | - throw new LibraryException(__d('file', 'The library identified by {0} it is not known as image processing!', $settingParams['library'])); |
|
237 | + throw new LibraryException(__d('file', 'The library identified by {0} it is not known as image processing!', $settingParams[ 'library' ])); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | $offsetX = 0; |
@@ -243,48 +243,48 @@ discard block |
||
243 | 243 | $cropX = 0; |
244 | 244 | $cropY = 0; |
245 | 245 | |
246 | - foreach ($settingParams['thumbs'] as $thumbName => $thumbParam) { |
|
246 | + foreach ($settingParams[ 'thumbs' ] as $thumbName => $thumbParam) { |
|
247 | 247 | if (is_array($thumbParam)) { |
248 | - if (isset($thumbParam['width']) && is_array($thumbParam['width']) && count($thumbParam['width']) === 1) { |
|
249 | - list($newWidth, $newHeight) = $this->_byWidth($originalWidth, $originalHeight, $thumbParam['width'][0]); |
|
250 | - } elseif (isset($thumbParam['height']) && is_array($thumbParam['height']) && count($thumbParam['height']) === 1) { |
|
251 | - list($newWidth, $newHeight) = $this->_byHeight($originalWidth, $originalHeight, $thumbParam['height'][0]); |
|
252 | - } elseif (isset($thumbParam['shorter']) && is_array($thumbParam['shorter']) && count($thumbParam['shorter']) === 2) { |
|
253 | - list($newWidth, $newHeight) = $this->_byShorter($originalWidth, $originalHeight, $thumbParam['shorter'][0], $thumbParam['shorter'][1]); |
|
254 | - } elseif (isset($thumbParam['longer']) && is_array($thumbParam['longer']) && count($thumbParam['longer']) === 2) { |
|
255 | - list($newWidth, $newHeight) = $this->_byLonger($originalWidth, $originalHeight, $thumbParam['longer'][0], $thumbParam['longer'][1]); |
|
256 | - } elseif (isset($thumbParam['fit']) && is_array($thumbParam['fit']) && count($thumbParam['fit']) === 2) { |
|
257 | - list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->_byFit($originalWidth, $originalHeight, $thumbParam['fit'][0], $thumbParam['fit'][1]); |
|
258 | - } elseif (isset($thumbParam['fit']) && is_array($thumbParam['fit']) && count($thumbParam['fit']) === 3) { |
|
259 | - list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->_byFit($originalWidth, $originalHeight, $thumbParam['fit'][0], $thumbParam['fit'][1], $thumbParam['fit'][2]); |
|
260 | - } elseif (isset($thumbParam['square']) && is_array($thumbParam['square']) && count($thumbParam['square']) === 1) { |
|
261 | - list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->_bySquare($originalWidth, $originalHeight, $thumbParam['square'][0]); |
|
262 | - } elseif (isset($thumbParam['square']) && is_array($thumbParam['square']) && count($thumbParam['square']) === 2) { |
|
263 | - list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->_bySquare($originalWidth, $originalHeight, $thumbParam['square'][0], $thumbParam['square'][1]); |
|
248 | + if (isset($thumbParam[ 'width' ]) && is_array($thumbParam[ 'width' ]) && count($thumbParam[ 'width' ]) === 1) { |
|
249 | + list($newWidth, $newHeight) = $this->_byWidth($originalWidth, $originalHeight, $thumbParam[ 'width' ][ 0 ]); |
|
250 | + } elseif (isset($thumbParam[ 'height' ]) && is_array($thumbParam[ 'height' ]) && count($thumbParam[ 'height' ]) === 1) { |
|
251 | + list($newWidth, $newHeight) = $this->_byHeight($originalWidth, $originalHeight, $thumbParam[ 'height' ][ 0 ]); |
|
252 | + } elseif (isset($thumbParam[ 'shorter' ]) && is_array($thumbParam[ 'shorter' ]) && count($thumbParam[ 'shorter' ]) === 2) { |
|
253 | + list($newWidth, $newHeight) = $this->_byShorter($originalWidth, $originalHeight, $thumbParam[ 'shorter' ][ 0 ], $thumbParam[ 'shorter' ][ 1 ]); |
|
254 | + } elseif (isset($thumbParam[ 'longer' ]) && is_array($thumbParam[ 'longer' ]) && count($thumbParam[ 'longer' ]) === 2) { |
|
255 | + list($newWidth, $newHeight) = $this->_byLonger($originalWidth, $originalHeight, $thumbParam[ 'longer' ][ 0 ], $thumbParam[ 'longer' ][ 1 ]); |
|
256 | + } elseif (isset($thumbParam[ 'fit' ]) && is_array($thumbParam[ 'fit' ]) && count($thumbParam[ 'fit' ]) === 2) { |
|
257 | + list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->_byFit($originalWidth, $originalHeight, $thumbParam[ 'fit' ][ 0 ], $thumbParam[ 'fit' ][ 1 ]); |
|
258 | + } elseif (isset($thumbParam[ 'fit' ]) && is_array($thumbParam[ 'fit' ]) && count($thumbParam[ 'fit' ]) === 3) { |
|
259 | + list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->_byFit($originalWidth, $originalHeight, $thumbParam[ 'fit' ][ 0 ], $thumbParam[ 'fit' ][ 1 ], $thumbParam[ 'fit' ][ 2 ]); |
|
260 | + } elseif (isset($thumbParam[ 'square' ]) && is_array($thumbParam[ 'square' ]) && count($thumbParam[ 'square' ]) === 1) { |
|
261 | + list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->_bySquare($originalWidth, $originalHeight, $thumbParam[ 'square' ][ 0 ]); |
|
262 | + } elseif (isset($thumbParam[ 'square' ]) && is_array($thumbParam[ 'square' ]) && count($thumbParam[ 'square' ]) === 2) { |
|
263 | + list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->_bySquare($originalWidth, $originalHeight, $thumbParam[ 'square' ][ 0 ], $thumbParam[ 'square' ][ 1 ]); |
|
264 | 264 | } else { |
265 | 265 | throw new ThumbsException(__d('file', 'Unknown type of creating thumbnails!')); |
266 | 266 | } |
267 | 267 | |
268 | 268 | $thumbFile = str_replace('default', $thumbName, $originalFile); |
269 | 269 | |
270 | - switch ($settingParams['library']) { |
|
270 | + switch ($settingParams[ 'library' ]) { |
|
271 | 271 | // Get image resource |
272 | 272 | case 'gd': |
273 | 273 | $newImage = imagecreatetruecolor($newWidth, $newHeight); |
274 | 274 | |
275 | - if (is_array($settingParams['background'])) { |
|
275 | + if (is_array($settingParams[ 'background' ])) { |
|
276 | 276 | // Set background color and transparent indicates |
277 | - imagefill($newImage, 0, 0, imagecolorallocatealpha($newImage, $settingParams['background'][0], $settingParams['background'][1], $settingParams['background'][2], $settingParams['background'][3])); |
|
277 | + imagefill($newImage, 0, 0, imagecolorallocatealpha($newImage, $settingParams[ 'background' ][ 0 ], $settingParams[ 'background' ][ 1 ], $settingParams[ 'background' ][ 2 ], $settingParams[ 'background' ][ 3 ])); |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | imagecopyresampled($newImage, $sourceImage, 0, 0, 0, 0, $newWidth, $newHeight, $originalWidth, $originalHeight); |
281 | 281 | |
282 | - if ((isset($thumbParam['square']) && is_array($thumbParam['square'])) || (isset($thumbParam['fit']) && is_array($thumbParam['fit']))) { |
|
282 | + if ((isset($thumbParam[ 'square' ]) && is_array($thumbParam[ 'square' ])) || (isset($thumbParam[ 'fit' ]) && is_array($thumbParam[ 'fit' ]))) { |
|
283 | 283 | $fitImage = imagecreatetruecolor($newWidth + (2 * $offsetX) - (2 * $cropX), $newHeight + (2 * $offsetY) - (2 * $cropY)); |
284 | 284 | |
285 | - if (is_array($settingParams['background'])) { |
|
285 | + if (is_array($settingParams[ 'background' ])) { |
|
286 | 286 | // Set background color and transparent indicates |
287 | - imagefill($fitImage, 0, 0, imagecolorallocatealpha($fitImage, $settingParams['background'][0], $settingParams['background'][1], $settingParams['background'][2], $settingParams['background'][3])); |
|
287 | + imagefill($fitImage, 0, 0, imagecolorallocatealpha($fitImage, $settingParams[ 'background' ][ 0 ], $settingParams[ 'background' ][ 1 ], $settingParams[ 'background' ][ 2 ], $settingParams[ 'background' ][ 3 ])); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | imagecopyresampled($fitImage, $newImage, $offsetX, $offsetY, $cropX, $cropY, $newWidth, $newHeight, $newWidth, $newHeight); |
@@ -296,10 +296,10 @@ discard block |
||
296 | 296 | imagesavealpha($newImage, true); |
297 | 297 | |
298 | 298 | // Watermark |
299 | - if (isset($thumbParam['watermark']) && ($watermarkSource = file_get_contents($settingParams['watermark'])) !== false) { |
|
299 | + if (isset($thumbParam[ 'watermark' ]) && ($watermarkSource = file_get_contents($settingParams[ 'watermark' ])) !== false) { |
|
300 | 300 | $watermarkImage = imagecreatefromstring($watermarkSource); |
301 | 301 | |
302 | - list($watermarkPositionX, $watermarkPositionY) = $this->getPosition(imagesx($newImage), imagesy($newImage), imagesx($watermarkImage), imagesy($watermarkImage), $offsetX, $offsetY, $thumbParam['watermark']); |
|
302 | + list($watermarkPositionX, $watermarkPositionY) = $this->getPosition(imagesx($newImage), imagesy($newImage), imagesx($watermarkImage), imagesy($watermarkImage), $offsetX, $offsetY, $thumbParam[ 'watermark' ]); |
|
303 | 303 | |
304 | 304 | // Set transparent |
305 | 305 | imagealphablending($newImage, true); |
@@ -334,16 +334,16 @@ discard block |
||
334 | 334 | $newImage->setimagebackgroundcolor('transparent'); |
335 | 335 | $newImage->extentimage($newWidth + (2 * $offsetX), $newHeight + (2 * $offsetY), -$offsetX, -$offsetY); |
336 | 336 | |
337 | - if ((isset($thumbParam['square']) && is_array($thumbParam['square'])) || (isset($thumbParam['fit']) && is_array($thumbParam['fit']))) { |
|
337 | + if ((isset($thumbParam[ 'square' ]) && is_array($thumbParam[ 'square' ])) || (isset($thumbParam[ 'fit' ]) && is_array($thumbParam[ 'fit' ]))) { |
|
338 | 338 | $newImage->cropimage($newWidth + (2 * $offsetX) - (2 * $cropX), $newHeight + (2 * $offsetY) - (2 * $cropY), $cropX, $cropY); |
339 | 339 | } |
340 | 340 | |
341 | 341 | // Watermark |
342 | - if (isset($thumbParam['watermark']) && ($watermarkSource = file_get_contents($settingParams['watermark'])) !== false) { |
|
342 | + if (isset($thumbParam[ 'watermark' ]) && ($watermarkSource = file_get_contents($settingParams[ 'watermark' ])) !== false) { |
|
343 | 343 | $watermarkImage = new \Imagick(); |
344 | 344 | $watermarkImage->readimageblob($watermarkSource); |
345 | 345 | |
346 | - list($watermarkPositionX, $watermarkPositionY) = $this->getPosition($newWidth, $newHeight, $watermarkImage->getimagewidth(), $watermarkImage->getimageheight(), $offsetX, $offsetY, $thumbParam['watermark']); |
|
346 | + list($watermarkPositionX, $watermarkPositionY) = $this->getPosition($newWidth, $newHeight, $watermarkImage->getimagewidth(), $watermarkImage->getimageheight(), $offsetX, $offsetY, $thumbParam[ 'watermark' ]); |
|
347 | 347 | |
348 | 348 | $newImage->compositeimage($watermarkImage, \Imagick::COMPOSITE_OVER, $watermarkPositionX, $watermarkPositionY); |
349 | 349 | } |
@@ -420,43 +420,43 @@ discard block |
||
420 | 420 | { |
421 | 421 | switch (intval($positionValue)) { |
422 | 422 | case 1: // Top left |
423 | - return [$offsetX, $offsetY]; |
|
423 | + return [ $offsetX, $offsetY ]; |
|
424 | 424 | |
425 | 425 | break; |
426 | 426 | case 2: // Top center |
427 | - return [($newWidth / 2) - ($watermarkWidth / 2), 0 + $offsetY]; |
|
427 | + return [ ($newWidth / 2) - ($watermarkWidth / 2), 0 + $offsetY ]; |
|
428 | 428 | |
429 | 429 | break; |
430 | 430 | case 3: // Top right |
431 | - return [($newWidth - $watermarkWidth) - $offsetX, 0 + $offsetY]; |
|
431 | + return [ ($newWidth - $watermarkWidth) - $offsetX, 0 + $offsetY ]; |
|
432 | 432 | |
433 | 433 | break; |
434 | 434 | case 4: // Middle left |
435 | - return [$offsetX, ($newHeight / 2) - ($watermarkHeight / 2)]; |
|
435 | + return [ $offsetX, ($newHeight / 2) - ($watermarkHeight / 2) ]; |
|
436 | 436 | |
437 | 437 | break; |
438 | 438 | case 5: // Middle center |
439 | - return [($newWidth / 2) - ($watermarkWidth / 2), ($newHeight / 2) - ($watermarkHeight / 2)]; |
|
439 | + return [ ($newWidth / 2) - ($watermarkWidth / 2), ($newHeight / 2) - ($watermarkHeight / 2) ]; |
|
440 | 440 | |
441 | 441 | break; |
442 | 442 | case 6: // Middle right |
443 | - return [($newWidth - $watermarkWidth) - $offsetX, ($newHeight / 2) - ($watermarkHeight / 2)]; |
|
443 | + return [ ($newWidth - $watermarkWidth) - $offsetX, ($newHeight / 2) - ($watermarkHeight / 2) ]; |
|
444 | 444 | |
445 | 445 | break; |
446 | 446 | case 7: // Bottom left |
447 | - return [$offsetX, ($newHeight - $watermarkHeight) - $offsetY]; |
|
447 | + return [ $offsetX, ($newHeight - $watermarkHeight) - $offsetY ]; |
|
448 | 448 | |
449 | 449 | break; |
450 | 450 | case 8: // Bottom center |
451 | - return [($newWidth / 2) - ($watermarkWidth / 2), ($newHeight - $watermarkHeight) - $offsetY]; |
|
451 | + return [ ($newWidth / 2) - ($watermarkWidth / 2), ($newHeight - $watermarkHeight) - $offsetY ]; |
|
452 | 452 | |
453 | 453 | break; |
454 | 454 | case 9: // Bottom right |
455 | - return [($newWidth - $watermarkWidth) - $offsetX, ($newHeight - $watermarkHeight) - $offsetY]; |
|
455 | + return [ ($newWidth - $watermarkWidth) - $offsetX, ($newHeight - $watermarkHeight) - $offsetY ]; |
|
456 | 456 | |
457 | 457 | break; |
458 | 458 | default: |
459 | - return [$offsetX, $offsetY]; |
|
459 | + return [ $offsetX, $offsetY ]; |
|
460 | 460 | |
461 | 461 | break; |
462 | 462 | } |
@@ -473,7 +473,7 @@ discard block |
||
473 | 473 | */ |
474 | 474 | protected function _prepareName($fieldName) |
475 | 475 | { |
476 | - return Text::uuid() . '_default.' . $this->getExtension($this->_files[$fieldName]['name']); |
|
476 | + return Text::uuid().'_default.'.$this->getExtension($this->_files[ $fieldName ][ 'name' ]); |
|
477 | 477 | } |
478 | 478 | |
479 | 479 | /** |
@@ -485,7 +485,7 @@ discard block |
||
485 | 485 | */ |
486 | 486 | protected function _prepareDir($dirPath) |
487 | 487 | { |
488 | - $dirPath = WWW_ROOT . str_replace('/', DS, $dirPath); |
|
488 | + $dirPath = WWW_ROOT.str_replace('/', DS, $dirPath); |
|
489 | 489 | |
490 | 490 | if (!is_dir($dirPath) && mb_strlen($dirPath) > 0) { |
491 | 491 | mkdir($dirPath, 0777, true); |
@@ -515,7 +515,7 @@ discard block |
||
515 | 515 | $newHeight = intval($newWidth * ($originalHeight / $originalWidth)); |
516 | 516 | } |
517 | 517 | |
518 | - return [$newWidth, $newHeight]; |
|
518 | + return [ $newWidth, $newHeight ]; |
|
519 | 519 | } |
520 | 520 | |
521 | 521 | /** |
@@ -537,7 +537,7 @@ discard block |
||
537 | 537 | $newWidth = intval($newHeight * ($originalWidth / $originalHeight)); |
538 | 538 | } |
539 | 539 | |
540 | - return [$newWidth, $newHeight]; |
|
540 | + return [ $newWidth, $newHeight ]; |
|
541 | 541 | } |
542 | 542 | |
543 | 543 | /** |
@@ -560,7 +560,7 @@ discard block |
||
560 | 560 | list($newWidth, $newHeight) = $this->_byHeight($originalWidth, $originalHeight, $newHeight); |
561 | 561 | } |
562 | 562 | |
563 | - return [$newWidth, $newHeight]; |
|
563 | + return [ $newWidth, $newHeight ]; |
|
564 | 564 | } |
565 | 565 | |
566 | 566 | /** |
@@ -583,7 +583,7 @@ discard block |
||
583 | 583 | list($newWidth, $newHeight) = $this->_byHeight($originalWidth, $originalHeight, $newHeight); |
584 | 584 | } |
585 | 585 | |
586 | - return [$newWidth, $newHeight]; |
|
586 | + return [ $newWidth, $newHeight ]; |
|
587 | 587 | } |
588 | 588 | |
589 | 589 | /** |
@@ -612,7 +612,7 @@ discard block |
||
612 | 612 | } else { |
613 | 613 | $newSizes = $this->_byLonger($originalWidth, $originalHeight, $newWidth, $newHeight); |
614 | 614 | |
615 | - if ($newWidth < $newSizes[0] || $newHeight < $newSizes[1]) { |
|
615 | + if ($newWidth < $newSizes[ 0 ] || $newHeight < $newSizes[ 1 ]) { |
|
616 | 616 | $newSizes = $this->_byShorter($originalWidth, $originalHeight, $newWidth, $newHeight); |
617 | 617 | } |
618 | 618 | } |
@@ -622,25 +622,25 @@ discard block |
||
622 | 622 | } else { |
623 | 623 | $newSizes = $this->_byShorter($originalWidth, $originalHeight, $newWidth, $newHeight); |
624 | 624 | |
625 | - if ($newWidth > $newSizes[0] || $newHeight > $newSizes[1]) { |
|
625 | + if ($newWidth > $newSizes[ 0 ] || $newHeight > $newSizes[ 1 ]) { |
|
626 | 626 | $newSizes = $this->_byLonger($originalWidth, $originalHeight, $newWidth, $newHeight); |
627 | 627 | } |
628 | 628 | } |
629 | 629 | } |
630 | 630 | |
631 | - if ($newWidth < $newSizes[0]) { |
|
632 | - $cropX = ($newSizes[0] - $newWidth) / 2; |
|
631 | + if ($newWidth < $newSizes[ 0 ]) { |
|
632 | + $cropX = ($newSizes[ 0 ] - $newWidth) / 2; |
|
633 | 633 | } else { |
634 | - $offsetX = ($newWidth - $newSizes[0]) / 2; |
|
634 | + $offsetX = ($newWidth - $newSizes[ 0 ]) / 2; |
|
635 | 635 | } |
636 | 636 | |
637 | - if ($newHeight < $newSizes[1]) { |
|
638 | - $cropY = ($newSizes[1] - $newHeight) / 2; |
|
637 | + if ($newHeight < $newSizes[ 1 ]) { |
|
638 | + $cropY = ($newSizes[ 1 ] - $newHeight) / 2; |
|
639 | 639 | } else { |
640 | - $offsetY = ($newHeight - $newSizes[1]) / 2; |
|
640 | + $offsetY = ($newHeight - $newSizes[ 1 ]) / 2; |
|
641 | 641 | } |
642 | 642 | |
643 | - return [$newSizes[0], $newSizes[1], $offsetX, $offsetY, $cropX, $cropY]; |
|
643 | + return [ $newSizes[ 0 ], $newSizes[ 1 ], $offsetX, $offsetY, $cropX, $cropY ]; |
|
644 | 644 | } |
645 | 645 | |
646 | 646 | /** |
@@ -687,6 +687,6 @@ discard block |
||
687 | 687 | } |
688 | 688 | } |
689 | 689 | |
690 | - return [$newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY]; |
|
690 | + return [ $newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY ]; |
|
691 | 691 | } |
692 | 692 | } |
693 | 693 | \ No newline at end of file |