| @@ -22,14 +22,14 @@ | ||
| 22 | 22 | * @return string completed img tag | 
| 23 | 23 | * @link https://book.cakephp.org/3.0/en/views/helpers/html.html#linking-to-images | 
| 24 | 24 | */ | 
| 25 | - public function thumb($path, $options = [], $thumb = 'default') | |
| 25 | + public function thumb($path, $options = [ ], $thumb = 'default') | |
| 26 | 26 |      { | 
| 27 | 27 |          if ($thumb !== 'default') { | 
| 28 | 28 |              $path = preg_replace('/default/', $thumb, $path); | 
| 29 | 29 | } | 
| 30 | 30 | |
| 31 | 31 |          if (!is_array($options)) { | 
| 32 | - $options = []; | |
| 32 | + $options = [ ]; | |
| 33 | 33 | } | 
| 34 | 34 | |
| 35 | 35 | return $this->Html->image($path, $options); | 
| @@ -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,7 +46,7 @@ discard block | ||
| 46 | 46 | * | 
| 47 | 47 | * @var array | 
| 48 | 48 | */ | 
| 49 | - protected $_files = []; | |
| 49 | + protected $_files = [ ]; | |
| 50 | 50 | |
| 51 | 51 | /** | 
| 52 | 52 | * @inheritdoc | 
| @@ -54,14 +54,14 @@ discard block | ||
| 54 | 54 | public function initialize(array $config) | 
| 55 | 55 |      {
 | 
| 56 | 56 |          foreach ($config as $field => $fieldOptions) {
 | 
| 57 | - $this->_config = []; | |
| 57 | + $this->_config = [ ]; | |
| 58 | 58 | |
| 59 | 59 |              if (is_array($fieldOptions)) {
 | 
| 60 | - $this->_config[$this->_table->getAlias()][$field] = array_merge($this->_defaultConfig, $fieldOptions); | |
| 60 | + $this->_config[ $this->_table->getAlias() ][ $field ] = array_merge($this->_defaultConfig, $fieldOptions); | |
| 61 | 61 |              } else {
 | 
| 62 | 62 | $field = $fieldOptions; | 
| 63 | 63 | |
| 64 | - $this->_config[$this->_table->getAlias()][$field] = $this->_defaultConfig; | |
| 64 | + $this->_config[ $this->_table->getAlias() ][ $field ] = $this->_defaultConfig; | |
| 65 | 65 | } | 
| 66 | 66 | } | 
| 67 | 67 | } | 
| @@ -69,25 +69,25 @@ 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->_table->getAlias()])) {
 | |
| 74 | +        if (!empty($config = $this->_config[ $this->_table->getAlias() ])) {
 | |
| 75 | 75 |              foreach ($config as $field => $fieldOptions) {
 | 
| 76 | 76 | // Check for temporary file | 
| 77 | -                if (isset($data[$field]) && !empty($data[$field]['name']) && file_exists($data[$field]['tmp_name'])) {
 | |
| 77 | +                if (isset($data[ $field ]) && !empty($data[ $field ][ 'name' ]) && file_exists($data[ $field ][ 'tmp_name' ])) {
 | |
| 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['_' . $field] = $data[$field]; | |
| 80 | + $data[ '_'.$field ] = $data[ $field ]; | |
| 81 | 81 | |
| 82 | - $this->_files[$field] = $data[$field]; | |
| 83 | - $this->_files[$field]['path'] = $this->_prepareDir($fieldOptions['path']); | |
| 84 | - $this->_files[$field]['name'] = $this->_prepareName($data, $field); | |
| 82 | + $this->_files[ $field ] = $data[ $field ]; | |
| 83 | + $this->_files[ $field ][ 'path' ] = $this->_prepareDir($fieldOptions[ 'path' ]); | |
| 84 | + $this->_files[ $field ][ 'name' ] = $this->_prepareName($data, $field); | |
| 85 | 85 | |
| 86 | - $data[$field] = $this->_files[$field]['name']; | |
| 86 | + $data[ $field ] = $this->_files[ $field ][ 'name' ]; | |
| 87 | 87 |                  } else {
 | 
| 88 | -                    if (isset($data[$field]) && is_array($data[$field])) {
 | |
| 88 | +                    if (isset($data[ $field ]) && is_array($data[ $field ])) {
 | |
| 89 | 89 | // Delete file array from data when is not attached | 
| 90 | - unset($data[$field]); | |
| 90 | + unset($data[ $field ]); | |
| 91 | 91 | } | 
| 92 | 92 | } | 
| 93 | 93 | } | 
| @@ -97,7 +97,7 @@ discard block | ||
| 97 | 97 | /** | 
| 98 | 98 | * @inheritdoc | 
| 99 | 99 | */ | 
| 100 | - public function afterSave(Event $event, EntityInterface $entity, $options = []) | |
| 100 | + public function afterSave(Event $event, EntityInterface $entity, $options = [ ]) | |
| 101 | 101 |      {
 | 
| 102 | 102 |          //if ($created !== true && empty($this->_files)) {
 | 
| 103 | 103 | |
| @@ -123,11 +123,11 @@ discard block | ||
| 123 | 123 |      {
 | 
| 124 | 124 |          foreach ($this->_files as $fieldName => $fieldOptions) {
 | 
| 125 | 125 | // Path to default file | 
| 126 | - $fileName = $fieldOptions['path'] . DS . $this->_files[$fieldName]['name']; | |
| 126 | + $fileName = $fieldOptions[ 'path' ].DS.$this->_files[ $fieldName ][ 'name' ]; | |
| 127 | 127 | |
| 128 | -            if (move_uploaded_file($this->_files[$fieldName]['tmp_name'], $fileName) || rename($this->_files[$fieldName]['tmp_name'], $fileName)) {
 | |
| 129 | -                if (isset($this->_config[$this->_table->getAlias()][$fieldName]['thumbs'])) {
 | |
| 130 | - $this->prepareThumbs($fileName, $this->_config[$this->_table->getAlias()][$fieldName]); | |
| 128 | +            if (move_uploaded_file($this->_files[ $fieldName ][ 'tmp_name' ], $fileName) || rename($this->_files[ $fieldName ][ 'tmp_name' ], $fileName)) {
 | |
| 129 | +                if (isset($this->_config[ $this->_table->getAlias() ][ $fieldName ][ 'thumbs' ])) {
 | |
| 130 | + $this->prepareThumbs($fileName, $this->_config[ $this->_table->getAlias() ][ $fieldName ]); | |
| 131 | 131 | } | 
| 132 | 132 | } | 
| 133 | 133 | } | 
| @@ -144,16 +144,16 @@ discard block | ||
| 144 | 144 | // Get field list of model schema | 
| 145 | 145 | $modelSchema = $model->schema(); | 
| 146 | 146 | |
| 147 | -        foreach ($this->settings[$model->alias] as $fieldName => $fieldOptions) {
 | |
| 147 | +        foreach ($this->settings[ $model->alias ] as $fieldName => $fieldOptions) {
 | |
| 148 | 148 | // Check is field in model schema | 
| 149 | -            if (isset($modelSchema[$fieldName])) {
 | |
| 149 | +            if (isset($modelSchema[ $fieldName ])) {
 | |
| 150 | 150 | $dataField = $model->findById($model->id); | 
| 151 | 151 | |
| 152 | -                if (is_array($dataField) && !empty($dataField[$model->alias][$fieldName])) {
 | |
| 152 | +                if (is_array($dataField) && !empty($dataField[ $model->alias ][ $fieldName ])) {
 | |
| 153 | 153 | // Pattern for original file with thumbs | 
| 154 | - $filePattern = $this->settings[$model->alias][$fieldName]['path'] . DS . substr($dataField[$model->alias][$fieldName], 0, 14); | |
| 154 | + $filePattern = $this->settings[ $model->alias ][ $fieldName ][ 'path' ].DS.substr($dataField[ $model->alias ][ $fieldName ], 0, 14); | |
| 155 | 155 | |
| 156 | -                    foreach (glob($filePattern . '*') as $fileName) {
 | |
| 156 | +                    foreach (glob($filePattern.'*') as $fileName) {
 | |
| 157 | 157 | // Remove file | 
| 158 | 158 | @unlink($fileName); | 
| 159 | 159 | } | 
| @@ -175,14 +175,14 @@ discard block | ||
| 175 | 175 |      {
 | 
| 176 | 176 |          if (is_file($originalFile) && is_array($settingParams)) {
 | 
| 177 | 177 | // Check image library | 
| 178 | -            if (!extension_loaded($settingParams['library'])) {
 | |
| 179 | -                throw new LibraryException(__d('file', 'The library identified by {0} is not loaded!', $settingParams['library']));
 | |
| 178 | +            if (!extension_loaded($settingParams[ 'library' ])) {
 | |
| 179 | +                throw new LibraryException(__d('file', 'The library identified by {0} is not loaded!', $settingParams[ 'library' ]));
 | |
| 180 | 180 | } | 
| 181 | 181 | |
| 182 | 182 | // Get extension from original file | 
| 183 | 183 | $fileExtension = $this->getExtension($originalFile); | 
| 184 | 184 | |
| 185 | -            switch ($settingParams['library']) {
 | |
| 185 | +            switch ($settingParams[ 'library' ]) {
 | |
| 186 | 186 | // Get image resource | 
| 187 | 187 | case 'gd': | 
| 188 | 188 |                      switch ($fileExtension) {
 | 
| @@ -220,7 +220,7 @@ discard block | ||
| 220 | 220 | |
| 221 | 221 | break; | 
| 222 | 222 | default: | 
| 223 | -                    throw new LibraryException(__d('file', 'The library identified by {0} it is not known as image processing!', $settingParams['library']));
 | |
| 223 | +                    throw new LibraryException(__d('file', 'The library identified by {0} it is not known as image processing!', $settingParams[ 'library' ]));
 | |
| 224 | 224 | } | 
| 225 | 225 | |
| 226 | 226 | $offsetX = 0; | 
| @@ -229,48 +229,48 @@ discard block | ||
| 229 | 229 | $cropX = 0; | 
| 230 | 230 | $cropY = 0; | 
| 231 | 231 | |
| 232 | -            foreach ($settingParams['thumbs'] as $thumbName => $thumbParam) {
 | |
| 232 | +            foreach ($settingParams[ 'thumbs' ] as $thumbName => $thumbParam) {
 | |
| 233 | 233 |                  if (is_array($thumbParam)) {
 | 
| 234 | -                    if (isset($thumbParam['width']) && is_array($thumbParam['width']) && count($thumbParam['width']) === 1) {
 | |
| 235 | - list($newWidth, $newHeight) = $this->_byWidth($originalWidth, $originalHeight, $thumbParam['width'][0]); | |
| 236 | -                    } elseif (isset($thumbParam['height']) && is_array($thumbParam['height']) && count($thumbParam['height']) === 1) {
 | |
| 237 | - list($newWidth, $newHeight) = $this->_byHeight($originalWidth, $originalHeight, $thumbParam['height'][0]); | |
| 238 | -                    } elseif (isset($thumbParam['shorter']) && is_array($thumbParam['shorter']) && count($thumbParam['shorter']) === 2) {
 | |
| 239 | - list($newWidth, $newHeight) = $this->_byShorter($originalWidth, $originalHeight, $thumbParam['shorter'][0], $thumbParam['shorter'][1]); | |
| 240 | -                    } elseif (isset($thumbParam['longer']) && is_array($thumbParam['longer']) && count($thumbParam['longer']) === 2) {
 | |
| 241 | - list($newWidth, $newHeight) = $this->_byLonger($originalWidth, $originalHeight, $thumbParam['longer'][0], $thumbParam['longer'][1]); | |
| 242 | -                    } elseif (isset($thumbParam['fit']) && is_array($thumbParam['fit']) && count($thumbParam['fit']) === 2) {
 | |
| 243 | - list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->_byFit($originalWidth, $originalHeight, $thumbParam['fit'][0], $thumbParam['fit'][1]); | |
| 244 | -                    } elseif (isset($thumbParam['fit']) && is_array($thumbParam['fit']) && count($thumbParam['fit']) === 3) {
 | |
| 245 | - list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->_byFit($originalWidth, $originalHeight, $thumbParam['fit'][0], $thumbParam['fit'][1], $thumbParam['fit'][2]); | |
| 246 | -                    } elseif (isset($thumbParam['square']) && is_array($thumbParam['square']) && count($thumbParam['square']) === 1) {
 | |
| 247 | - list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->_bySquare($originalWidth, $originalHeight, $thumbParam['square'][0]); | |
| 248 | -                    } elseif (isset($thumbParam['square']) && is_array($thumbParam['square']) && count($thumbParam['square']) === 2) {
 | |
| 249 | - list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->_bySquare($originalWidth, $originalHeight, $thumbParam['square'][0], $thumbParam['square'][1]); | |
| 234 | +                    if (isset($thumbParam[ 'width' ]) && is_array($thumbParam[ 'width' ]) && count($thumbParam[ 'width' ]) === 1) {
 | |
| 235 | + list($newWidth, $newHeight) = $this->_byWidth($originalWidth, $originalHeight, $thumbParam[ 'width' ][ 0 ]); | |
| 236 | +                    } elseif (isset($thumbParam[ 'height' ]) && is_array($thumbParam[ 'height' ]) && count($thumbParam[ 'height' ]) === 1) {
 | |
| 237 | + list($newWidth, $newHeight) = $this->_byHeight($originalWidth, $originalHeight, $thumbParam[ 'height' ][ 0 ]); | |
| 238 | +                    } elseif (isset($thumbParam[ 'shorter' ]) && is_array($thumbParam[ 'shorter' ]) && count($thumbParam[ 'shorter' ]) === 2) {
 | |
| 239 | + list($newWidth, $newHeight) = $this->_byShorter($originalWidth, $originalHeight, $thumbParam[ 'shorter' ][ 0 ], $thumbParam[ 'shorter' ][ 1 ]); | |
| 240 | +                    } elseif (isset($thumbParam[ 'longer' ]) && is_array($thumbParam[ 'longer' ]) && count($thumbParam[ 'longer' ]) === 2) {
 | |
| 241 | + list($newWidth, $newHeight) = $this->_byLonger($originalWidth, $originalHeight, $thumbParam[ 'longer' ][ 0 ], $thumbParam[ 'longer' ][ 1 ]); | |
| 242 | +                    } elseif (isset($thumbParam[ 'fit' ]) && is_array($thumbParam[ 'fit' ]) && count($thumbParam[ 'fit' ]) === 2) {
 | |
| 243 | + list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->_byFit($originalWidth, $originalHeight, $thumbParam[ 'fit' ][ 0 ], $thumbParam[ 'fit' ][ 1 ]); | |
| 244 | +                    } elseif (isset($thumbParam[ 'fit' ]) && is_array($thumbParam[ 'fit' ]) && count($thumbParam[ 'fit' ]) === 3) {
 | |
| 245 | + list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->_byFit($originalWidth, $originalHeight, $thumbParam[ 'fit' ][ 0 ], $thumbParam[ 'fit' ][ 1 ], $thumbParam[ 'fit' ][ 2 ]); | |
| 246 | +                    } elseif (isset($thumbParam[ 'square' ]) && is_array($thumbParam[ 'square' ]) && count($thumbParam[ 'square' ]) === 1) {
 | |
| 247 | + list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->_bySquare($originalWidth, $originalHeight, $thumbParam[ 'square' ][ 0 ]); | |
| 248 | +                    } elseif (isset($thumbParam[ 'square' ]) && is_array($thumbParam[ 'square' ]) && count($thumbParam[ 'square' ]) === 2) {
 | |
| 249 | + list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->_bySquare($originalWidth, $originalHeight, $thumbParam[ 'square' ][ 0 ], $thumbParam[ 'square' ][ 1 ]); | |
| 250 | 250 |                      } else {
 | 
| 251 | 251 |                          throw new ThumbsException(__d('file', 'Unknown type of creating thumbnails!'));
 | 
| 252 | 252 | } | 
| 253 | 253 | |
| 254 | 254 |                      $thumbFile = str_replace('default', $thumbName, $originalFile);
 | 
| 255 | 255 | |
| 256 | -                    switch ($settingParams['library']) {
 | |
| 256 | +                    switch ($settingParams[ 'library' ]) {
 | |
| 257 | 257 | // Get image resource | 
| 258 | 258 | case 'gd': | 
| 259 | 259 | $newImage = imagecreatetruecolor($newWidth, $newHeight); | 
| 260 | 260 | |
| 261 | -                            if (is_array($settingParams['background'])) {
 | |
| 261 | +                            if (is_array($settingParams[ 'background' ])) {
 | |
| 262 | 262 | // Set background color and transparent indicates | 
| 263 | - imagefill($newImage, 0, 0, imagecolorallocatealpha($newImage, $settingParams['background'][0], $settingParams['background'][1], $settingParams['background'][2], $settingParams['background'][3])); | |
| 263 | + imagefill($newImage, 0, 0, imagecolorallocatealpha($newImage, $settingParams[ 'background' ][ 0 ], $settingParams[ 'background' ][ 1 ], $settingParams[ 'background' ][ 2 ], $settingParams[ 'background' ][ 3 ])); | |
| 264 | 264 | } | 
| 265 | 265 | |
| 266 | 266 | imagecopyresampled($newImage, $sourceImage, 0, 0, 0, 0, $newWidth, $newHeight, $originalWidth, $originalHeight); | 
| 267 | 267 | |
| 268 | -                            if ((isset($thumbParam['square']) && is_array($thumbParam['square'])) || (isset($thumbParam['fit']) && is_array($thumbParam['fit']))) {
 | |
| 268 | +                            if ((isset($thumbParam[ 'square' ]) && is_array($thumbParam[ 'square' ])) || (isset($thumbParam[ 'fit' ]) && is_array($thumbParam[ 'fit' ]))) {
 | |
| 269 | 269 | $fitImage = imagecreatetruecolor($newWidth + (2 * $offsetX) - (2 * $cropX), $newHeight + (2 * $offsetY) - (2 * $cropY)); | 
| 270 | 270 | |
| 271 | -                                if (is_array($settingParams['background'])) {
 | |
| 271 | +                                if (is_array($settingParams[ 'background' ])) {
 | |
| 272 | 272 | // Set background color and transparent indicates | 
| 273 | - imagefill($fitImage, 0, 0, imagecolorallocatealpha($fitImage, $settingParams['background'][0], $settingParams['background'][1], $settingParams['background'][2], $settingParams['background'][3])); | |
| 273 | + imagefill($fitImage, 0, 0, imagecolorallocatealpha($fitImage, $settingParams[ 'background' ][ 0 ], $settingParams[ 'background' ][ 1 ], $settingParams[ 'background' ][ 2 ], $settingParams[ 'background' ][ 3 ])); | |
| 274 | 274 | } | 
| 275 | 275 | |
| 276 | 276 | imagecopyresampled($fitImage, $newImage, $offsetX, $offsetY, $cropX, $cropY, $newWidth, $newHeight, $newWidth, $newHeight); | 
| @@ -282,10 +282,10 @@ discard block | ||
| 282 | 282 | imagesavealpha($newImage, true); | 
| 283 | 283 | |
| 284 | 284 | // Watermark | 
| 285 | -                            if (isset($thumbParam['watermark']) && ($watermarkSource = file_get_contents($settingParams['watermark'])) !== false) {
 | |
| 285 | +                            if (isset($thumbParam[ 'watermark' ]) && ($watermarkSource = file_get_contents($settingParams[ 'watermark' ])) !== false) {
 | |
| 286 | 286 | $watermarkImage = imagecreatefromstring($watermarkSource); | 
| 287 | 287 | |
| 288 | - list($watermarkPositionX, $watermarkPositionY) = $this->getPosition(imagesx($newImage), imagesy($newImage), imagesx($watermarkImage), imagesy($watermarkImage), $offsetX, $offsetY, $thumbParam['watermark']); | |
| 288 | + list($watermarkPositionX, $watermarkPositionY) = $this->getPosition(imagesx($newImage), imagesy($newImage), imagesx($watermarkImage), imagesy($watermarkImage), $offsetX, $offsetY, $thumbParam[ 'watermark' ]); | |
| 289 | 289 | |
| 290 | 290 | // Set transparent | 
| 291 | 291 | imagealphablending($newImage, true); | 
| @@ -320,16 +320,16 @@ discard block | ||
| 320 | 320 |                              $newImage->setimagebackgroundcolor('transparent');
 | 
| 321 | 321 | $newImage->extentimage($newWidth + (2 * $offsetX), $newHeight + (2 * $offsetY), -$offsetX, -$offsetY); | 
| 322 | 322 | |
| 323 | -                            if ((isset($thumbParam['square']) && is_array($thumbParam['square'])) || (isset($thumbParam['fit']) && is_array($thumbParam['fit']))) {
 | |
| 323 | +                            if ((isset($thumbParam[ 'square' ]) && is_array($thumbParam[ 'square' ])) || (isset($thumbParam[ 'fit' ]) && is_array($thumbParam[ 'fit' ]))) {
 | |
| 324 | 324 | $newImage->cropimage($newWidth + (2 * $offsetX) - (2 * $cropX), $newHeight + (2 * $offsetY) - (2 * $cropY), $cropX, $cropY); | 
| 325 | 325 | } | 
| 326 | 326 | |
| 327 | 327 | // Watermark | 
| 328 | -                            if (isset($thumbParam['watermark']) && ($watermarkSource = file_get_contents($settingParams['watermark'])) !== false) {
 | |
| 328 | +                            if (isset($thumbParam[ 'watermark' ]) && ($watermarkSource = file_get_contents($settingParams[ 'watermark' ])) !== false) {
 | |
| 329 | 329 | $watermarkImage = new \Imagick(); | 
| 330 | 330 | $watermarkImage->readimageblob($watermarkSource); | 
| 331 | 331 | |
| 332 | - list($watermarkPositionX, $watermarkPositionY) = $this->getPosition($newWidth, $newHeight, $watermarkImage->getimagewidth(), $watermarkImage->getimageheight(), $offsetX, $offsetY, $thumbParam['watermark']); | |
| 332 | + list($watermarkPositionX, $watermarkPositionY) = $this->getPosition($newWidth, $newHeight, $watermarkImage->getimagewidth(), $watermarkImage->getimageheight(), $offsetX, $offsetY, $thumbParam[ 'watermark' ]); | |
| 333 | 333 | |
| 334 | 334 | $newImage->compositeimage($watermarkImage, \Imagick::COMPOSITE_OVER, $watermarkPositionX, $watermarkPositionY); | 
| 335 | 335 | } | 
| @@ -408,43 +408,43 @@ discard block | ||
| 408 | 408 |      {
 | 
| 409 | 409 |          switch (intval($positionValue)) {
 | 
| 410 | 410 | case 1: // Top left | 
| 411 | - return [$offsetX, $offsetY]; | |
| 411 | + return [ $offsetX, $offsetY ]; | |
| 412 | 412 | |
| 413 | 413 | break; | 
| 414 | 414 | case 2: // Top center | 
| 415 | - return [($newWidth / 2) - ($watermarkWidth / 2), 0 + $offsetY]; | |
| 415 | + return [ ($newWidth / 2) - ($watermarkWidth / 2), 0 + $offsetY ]; | |
| 416 | 416 | |
| 417 | 417 | break; | 
| 418 | 418 | case 3: // Top right | 
| 419 | - return [($newWidth - $watermarkWidth) - $offsetX, 0 + $offsetY]; | |
| 419 | + return [ ($newWidth - $watermarkWidth) - $offsetX, 0 + $offsetY ]; | |
| 420 | 420 | |
| 421 | 421 | break; | 
| 422 | 422 | case 4: // Middle left | 
| 423 | - return [$offsetX, ($newHeight / 2) - ($watermarkHeight / 2)]; | |
| 423 | + return [ $offsetX, ($newHeight / 2) - ($watermarkHeight / 2) ]; | |
| 424 | 424 | |
| 425 | 425 | break; | 
| 426 | 426 | case 5: // Middle center | 
| 427 | - return [($newWidth / 2) - ($watermarkWidth / 2), ($newHeight / 2) - ($watermarkHeight / 2)]; | |
| 427 | + return [ ($newWidth / 2) - ($watermarkWidth / 2), ($newHeight / 2) - ($watermarkHeight / 2) ]; | |
| 428 | 428 | |
| 429 | 429 | break; | 
| 430 | 430 | case 6: // Middle right | 
| 431 | - return [($newWidth - $watermarkWidth) - $offsetX, ($newHeight / 2) - ($watermarkHeight / 2)]; | |
| 431 | + return [ ($newWidth - $watermarkWidth) - $offsetX, ($newHeight / 2) - ($watermarkHeight / 2) ]; | |
| 432 | 432 | |
| 433 | 433 | break; | 
| 434 | 434 | case 7: // Bottom left | 
| 435 | - return [$offsetX, ($newHeight - $watermarkHeight) - $offsetY]; | |
| 435 | + return [ $offsetX, ($newHeight - $watermarkHeight) - $offsetY ]; | |
| 436 | 436 | |
| 437 | 437 | break; | 
| 438 | 438 | case 8: // Bottom center | 
| 439 | - return [($newWidth / 2) - ($watermarkWidth / 2), ($newHeight - $watermarkHeight) - $offsetY]; | |
| 439 | + return [ ($newWidth / 2) - ($watermarkWidth / 2), ($newHeight - $watermarkHeight) - $offsetY ]; | |
| 440 | 440 | |
| 441 | 441 | break; | 
| 442 | 442 | case 9: // Bottom right | 
| 443 | - return [($newWidth - $watermarkWidth) - $offsetX, ($newHeight - $watermarkHeight) - $offsetY]; | |
| 443 | + return [ ($newWidth - $watermarkWidth) - $offsetX, ($newHeight - $watermarkHeight) - $offsetY ]; | |
| 444 | 444 | |
| 445 | 445 | break; | 
| 446 | 446 | default: | 
| 447 | - return [$offsetX, $offsetY]; | |
| 447 | + return [ $offsetX, $offsetY ]; | |
| 448 | 448 | |
| 449 | 449 | break; | 
| 450 | 450 | } | 
| @@ -462,7 +462,7 @@ discard block | ||
| 462 | 462 | */ | 
| 463 | 463 | protected function _prepareName($data, $fieldName) | 
| 464 | 464 |      {
 | 
| 465 | - $name = Text::uuid() . '_default.' . $this->getExtension($this->_files[$fieldName]['name']); | |
| 465 | + $name = Text::uuid().'_default.'.$this->getExtension($this->_files[ $fieldName ][ 'name' ]); | |
| 466 | 466 | |
| 467 | 467 | return $name; | 
| 468 | 468 | } | 
| @@ -476,7 +476,7 @@ discard block | ||
| 476 | 476 | */ | 
| 477 | 477 | protected function _prepareDir($dirPath) | 
| 478 | 478 |      {
 | 
| 479 | -        $dirPath = WWW_ROOT . str_replace('/', DS, $dirPath);
 | |
| 479 | +        $dirPath = WWW_ROOT.str_replace('/', DS, $dirPath);
 | |
| 480 | 480 | |
| 481 | 481 |          if (!is_dir($dirPath) && mb_strlen($dirPath) > 0) {
 | 
| 482 | 482 | mkdir($dirPath, 0777, true); | 
| @@ -506,7 +506,7 @@ discard block | ||
| 506 | 506 | $newHeight = intval($newWidth * ($originalHeight / $originalWidth)); | 
| 507 | 507 | } | 
| 508 | 508 | |
| 509 | - return [$newWidth, $newHeight]; | |
| 509 | + return [ $newWidth, $newHeight ]; | |
| 510 | 510 | } | 
| 511 | 511 | |
| 512 | 512 | /** | 
| @@ -528,7 +528,7 @@ discard block | ||
| 528 | 528 | $newWidth = intval($newHeight * ($originalWidth / $originalHeight)); | 
| 529 | 529 | } | 
| 530 | 530 | |
| 531 | - return [$newWidth, $newHeight]; | |
| 531 | + return [ $newWidth, $newHeight ]; | |
| 532 | 532 | } | 
| 533 | 533 | |
| 534 | 534 | /** | 
| @@ -551,7 +551,7 @@ discard block | ||
| 551 | 551 | list($newWidth, $newHeight) = $this->_byHeight($originalWidth, $originalHeight, $newHeight); | 
| 552 | 552 | } | 
| 553 | 553 | |
| 554 | - return [$newWidth, $newHeight]; | |
| 554 | + return [ $newWidth, $newHeight ]; | |
| 555 | 555 | } | 
| 556 | 556 | |
| 557 | 557 | /** | 
| @@ -574,7 +574,7 @@ discard block | ||
| 574 | 574 | list($newWidth, $newHeight) = $this->_byHeight($originalWidth, $originalHeight, $newHeight); | 
| 575 | 575 | } | 
| 576 | 576 | |
| 577 | - return [$newWidth, $newHeight]; | |
| 577 | + return [ $newWidth, $newHeight ]; | |
| 578 | 578 | } | 
| 579 | 579 | |
| 580 | 580 | /** | 
| @@ -603,7 +603,7 @@ discard block | ||
| 603 | 603 |              } else {
 | 
| 604 | 604 | $newSizes = $this->_byLonger($originalWidth, $originalHeight, $newWidth, $newHeight); | 
| 605 | 605 | |
| 606 | -                if ($newWidth < $newSizes[0] || $newHeight < $newSizes[1]) {
 | |
| 606 | +                if ($newWidth < $newSizes[ 0 ] || $newHeight < $newSizes[ 1 ]) {
 | |
| 607 | 607 | $newSizes = $this->_byShorter($originalWidth, $originalHeight, $newWidth, $newHeight); | 
| 608 | 608 | } | 
| 609 | 609 | } | 
| @@ -613,25 +613,25 @@ discard block | ||
| 613 | 613 |              } else {
 | 
| 614 | 614 | $newSizes = $this->_byShorter($originalWidth, $originalHeight, $newWidth, $newHeight); | 
| 615 | 615 | |
| 616 | -                if ($newWidth > $newSizes[0] || $newHeight > $newSizes[1]) {
 | |
| 616 | +                if ($newWidth > $newSizes[ 0 ] || $newHeight > $newSizes[ 1 ]) {
 | |
| 617 | 617 | $newSizes = $this->_byLonger($originalWidth, $originalHeight, $newWidth, $newHeight); | 
| 618 | 618 | } | 
| 619 | 619 | } | 
| 620 | 620 | } | 
| 621 | 621 | |
| 622 | -        if ($newWidth < $newSizes[0]) {
 | |
| 623 | - $cropX = ($newSizes[0] - $newWidth) / 2; | |
| 622 | +        if ($newWidth < $newSizes[ 0 ]) {
 | |
| 623 | + $cropX = ($newSizes[ 0 ] - $newWidth) / 2; | |
| 624 | 624 |          } else {
 | 
| 625 | - $offsetX = ($newWidth - $newSizes[0]) / 2; | |
| 625 | + $offsetX = ($newWidth - $newSizes[ 0 ]) / 2; | |
| 626 | 626 | } | 
| 627 | 627 | |
| 628 | -        if ($newHeight < $newSizes[1]) {
 | |
| 629 | - $cropY = ($newSizes[1] - $newHeight) / 2; | |
| 628 | +        if ($newHeight < $newSizes[ 1 ]) {
 | |
| 629 | + $cropY = ($newSizes[ 1 ] - $newHeight) / 2; | |
| 630 | 630 |          } else {
 | 
| 631 | - $offsetY = ($newHeight - $newSizes[1]) / 2; | |
| 631 | + $offsetY = ($newHeight - $newSizes[ 1 ]) / 2; | |
| 632 | 632 | } | 
| 633 | 633 | |
| 634 | - return [$newSizes[0], $newSizes[1], $offsetX, $offsetY, $cropX, $cropY]; | |
| 634 | + return [ $newSizes[ 0 ], $newSizes[ 1 ], $offsetX, $offsetY, $cropX, $cropY ]; | |
| 635 | 635 | } | 
| 636 | 636 | |
| 637 | 637 | /** | 
| @@ -678,6 +678,6 @@ discard block | ||
| 678 | 678 | } | 
| 679 | 679 | } | 
| 680 | 680 | |
| 681 | - return [$newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY]; | |
| 681 | + return [ $newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY ]; | |
| 682 | 682 | } | 
| 683 | 683 | } |