| @@ -16,9 +16,9 @@ discard block | ||
| 16 | 16 | */ | 
| 17 | 17 | protected $_defaultConfig = [ | 
| 18 | 18 | 'library' => 'gd', | 
| 19 | - 'types' => [ // Default allowed types | |
| 20 | - 'image/bmp', | |
| 21 | - 'image/gif', | |
| 19 | + 'types' => [ // Default allowed types | |
| 20 | + 'image/bmp', | |
| 21 | + 'image/gif', | |
| 22 | 22 | 'image/jpeg', | 
| 23 | 23 | 'image/jpg', | 
| 24 | 24 | 'image/pjpeg', | 
| @@ -27,9 +27,9 @@ discard block | ||
| 27 | 27 | 'image/x-png', | 
| 28 | 28 | 'image/webp', | 
| 29 | 29 | ], | 
| 30 | - 'extensions' => [ // Default allowed extensions | |
| 31 | - 'bmp', | |
| 32 | - 'gif', | |
| 30 | + 'extensions' => [ // Default allowed extensions | |
| 31 | + 'bmp', | |
| 32 | + 'gif', | |
| 33 | 33 | 'jpeg', | 
| 34 | 34 | 'jpg', | 
| 35 | 35 | 'pjpg', | 
| @@ -201,11 +201,11 @@ discard block | ||
| 201 | 201 |              switch ($settingParams['library']) {
 | 
| 202 | 202 | // Get image resource | 
| 203 | 203 | case 'gd': | 
| 204 | -                	switch ($fileExtension) {
 | |
| 205 | - case 'bmp': | |
| 206 | - $sourceImage = imagecreatefrombmp($originalFile); | |
| 204 | +                    switch ($fileExtension) {
 | |
| 205 | + case 'bmp': | |
| 206 | + $sourceImage = imagecreatefrombmp($originalFile); | |
| 207 | 207 | |
| 208 | - break; | |
| 208 | + break; | |
| 209 | 209 | case 'gif': | 
| 210 | 210 | $sourceImage = imagecreatefromgif($originalFile); | 
| 211 | 211 | |
| @@ -314,14 +314,14 @@ discard block | ||
| 314 | 314 | |
| 315 | 315 | // Set resource file type | 
| 316 | 316 |                              switch ($fileExtension) {
 | 
| 317 | - case 'bmp': | |
| 318 | - imagebmp($newImage, $thumbFile); | |
| 317 | + case 'bmp': | |
| 318 | + imagebmp($newImage, $thumbFile); | |
| 319 | 319 | |
| 320 | - break; | |
| 321 | - case 'gif': | |
| 322 | - imagegif($newImage, $thumbFile); | |
| 320 | + break; | |
| 321 | + case 'gif': | |
| 322 | + imagegif($newImage, $thumbFile); | |
| 323 | 323 | |
| 324 | - break; | |
| 324 | + break; | |
| 325 | 325 | case 'png': | 
| 326 | 326 | imagepng($newImage, $thumbFile); | 
| 327 | 327 | |
| @@ -38,9 +38,9 @@ discard block | ||
| 38 | 38 | 'webp', | 
| 39 | 39 | ], | 
| 40 | 40 | 'path' => 'files', | 
| 41 | - 'background' => [255, 255, 255, 127], | |
| 41 | + 'background' => [ 255, 255, 255, 127 ], | |
| 42 | 42 | 'watermark' => '', | 
| 43 | - 'thumbs' => [], | |
| 43 | + 'thumbs' => [ ], | |
| 44 | 44 | ]; | 
| 45 | 45 | |
| 46 | 46 | /** | 
| @@ -48,22 +48,22 @@ discard block | ||
| 48 | 48 | * | 
| 49 | 49 | * @var array | 
| 50 | 50 | */ | 
| 51 | - protected $_files = []; | |
| 51 | + protected $_files = [ ]; | |
| 52 | 52 | |
| 53 | 53 | /** | 
| 54 | 54 |       * {@inheritDoc}
 | 
| 55 | 55 | */ | 
| 56 | 56 | public function initialize(array $config) | 
| 57 | 57 |      {
 | 
| 58 | - $this->_config = []; | |
| 58 | + $this->_config = [ ]; | |
| 59 | 59 | |
| 60 | 60 |          foreach ($config as $field => $fieldOptions) {
 | 
| 61 | 61 |              if (is_array($fieldOptions)) {
 | 
| 62 | - $this->_config[$this->getTable()->getAlias()][$field] = array_merge($this->_defaultConfig, $fieldOptions); | |
| 62 | + $this->_config[ $this->getTable()->getAlias() ][ $field ] = array_merge($this->_defaultConfig, $fieldOptions); | |
| 63 | 63 |              } else {
 | 
| 64 | 64 | $field = $fieldOptions; | 
| 65 | 65 | |
| 66 | - $this->_config[$this->getTable()->getAlias()][$field] = $this->_defaultConfig; | |
| 66 | + $this->_config[ $this->getTable()->getAlias() ][ $field ] = $this->_defaultConfig; | |
| 67 | 67 | } | 
| 68 | 68 | } | 
| 69 | 69 | } | 
| @@ -71,37 +71,37 @@ discard block | ||
| 71 | 71 | /** | 
| 72 | 72 |       * {@inheritDoc}
 | 
| 73 | 73 | */ | 
| 74 | - public function beforeMarshal(Event $event, $data = [], $options = []) | |
| 74 | + public function beforeMarshal(Event $event, $data = [ ], $options = [ ]) | |
| 75 | 75 |      {
 | 
| 76 | -        if (!empty($config = $this->_config[$this->getTable()->getAlias()])) {
 | |
| 76 | +        if (!empty($config = $this->_config[ $this->getTable()->getAlias() ])) {
 | |
| 77 | 77 |              foreach ($config as $field => $fieldOptions) {
 | 
| 78 | -                if (is_numeric(key($data[$field]))) {
 | |
| 79 | -                    foreach ($data[$field] as $r => $fileMuptlipe) {
 | |
| 78 | +                if (is_numeric(key($data[ $field ]))) {
 | |
| 79 | +                    foreach ($data[ $field ] as $r => $fileMuptlipe) {
 | |
| 80 | 80 | // Create archive file data with suffix on original field name | 
| 81 | 81 | // @todo Create only when field name is used in database | 
| 82 | - $data['_' . $r . '_' . $field] = $data[$field][$r]; | |
| 82 | + $data[ '_'.$r.'_'.$field ] = $data[ $field ][ $r ]; | |
| 83 | 83 | |
| 84 | - $this->_files[$r . '_' . $field] = $data[$field][$r]; | |
| 85 | - $this->_files[$r . '_' . $field]['path'] = $this->_prepareDir($fieldOptions['path']); | |
| 86 | - $this->_files[$r . '_' . $field]['name'] = $this->_prepareName($r . '_' . $field); | |
| 84 | + $this->_files[ $r.'_'.$field ] = $data[ $field ][ $r ]; | |
| 85 | + $this->_files[ $r.'_'.$field ][ 'path' ] = $this->_prepareDir($fieldOptions[ 'path' ]); | |
| 86 | + $this->_files[ $r.'_'.$field ][ 'name' ] = $this->_prepareName($r.'_'.$field); | |
| 87 | 87 | |
| 88 | - $data[$r . '_' . $field] = $this->_files[$r . '_' . $field]['name']; | |
| 88 | + $data[ $r.'_'.$field ] = $this->_files[ $r.'_'.$field ][ 'name' ]; | |
| 89 | 89 | } | 
| 90 | -                } elseif (isset($data[$field]) && !empty($data[$field]['name']) && file_exists($data[$field]['tmp_name'])) {
 | |
| 90 | +                } elseif (isset($data[ $field ]) && !empty($data[ $field ][ 'name' ]) && file_exists($data[ $field ][ 'tmp_name' ])) {
 | |
| 91 | 91 | // Create archive file data with suffix on original field name | 
| 92 | 92 | // @todo Create only when field name is used in database | 
| 93 | 93 | // @todo Duplicate code | 
| 94 | - $data['_' . $field] = $data[$field]; | |
| 94 | + $data[ '_'.$field ] = $data[ $field ]; | |
| 95 | 95 | |
| 96 | - $this->_files[$field] = $data[$field]; | |
| 97 | - $this->_files[$field]['path'] = $this->_prepareDir($fieldOptions['path']); | |
| 98 | - $this->_files[$field]['name'] = $this->_prepareName($field); | |
| 96 | + $this->_files[ $field ] = $data[ $field ]; | |
| 97 | + $this->_files[ $field ][ 'path' ] = $this->_prepareDir($fieldOptions[ 'path' ]); | |
| 98 | + $this->_files[ $field ][ 'name' ] = $this->_prepareName($field); | |
| 99 | 99 | |
| 100 | - $data[$field] = $this->_files[$field]['name']; | |
| 100 | + $data[ $field ] = $this->_files[ $field ][ 'name' ]; | |
| 101 | 101 |                  } else {
 | 
| 102 | -                    if (isset($data[$field]) && is_array($data[$field])) {
 | |
| 102 | +                    if (isset($data[ $field ]) && is_array($data[ $field ])) {
 | |
| 103 | 103 | // Delete file array from data when is not attached | 
| 104 | - unset($data[$field]); | |
| 104 | + unset($data[ $field ]); | |
| 105 | 105 | } | 
| 106 | 106 | } | 
| 107 | 107 | } | 
| @@ -111,7 +111,7 @@ discard block | ||
| 111 | 111 | /** | 
| 112 | 112 |       * {@inheritDoc}
 | 
| 113 | 113 | */ | 
| 114 | - public function afterSave(Event $event, EntityInterface $entity, $options = []) | |
| 114 | + public function afterSave(Event $event, EntityInterface $entity, $options = [ ]) | |
| 115 | 115 |      {
 | 
| 116 | 116 | $this->prepareFile($entity); | 
| 117 | 117 | } | 
| @@ -133,16 +133,16 @@ discard block | ||
| 133 | 133 |      {
 | 
| 134 | 134 |          foreach ($this->_files as $fieldName => $fieldOptions) {
 | 
| 135 | 135 | // Path to default file | 
| 136 | - $fileName = $fieldOptions['path'] . DS . $this->_files[$fieldName]['name']; | |
| 136 | + $fileName = $fieldOptions[ 'path' ].DS.$this->_files[ $fieldName ][ 'name' ]; | |
| 137 | 137 | |
| 138 | -            if (move_uploaded_file($fieldOptions['tmp_name'], $fileName) || (file_exists($fieldOptions['tmp_name']) && rename($fieldOptions['tmp_name'], $fileName))) {
 | |
| 138 | +            if (move_uploaded_file($fieldOptions[ 'tmp_name' ], $fileName) || (file_exists($fieldOptions[ 'tmp_name' ]) && rename($fieldOptions[ 'tmp_name' ], $fileName))) {
 | |
| 139 | 139 |                  if (preg_match('/^[0-9]+_/', $fieldName, $fieldMatches)) {
 | 
| 140 | -                    $fieldName = preg_replace('/^' . $fieldMatches[0] . '/', '', $fieldName);
 | |
| 140 | +                    $fieldName = preg_replace('/^'.$fieldMatches[ 0 ].'/', '', $fieldName);
 | |
| 141 | 141 | } | 
| 142 | 142 | |
| 143 | - $fileTypes = $this->_config[$this->getTable()->getAlias()][$fieldName]; | |
| 143 | + $fileTypes = $this->_config[ $this->getTable()->getAlias() ][ $fieldName ]; | |
| 144 | 144 | |
| 145 | -                if (isset($fieldOptions['type']) && mb_strpos($fieldOptions['type'], 'image/') !== false && in_array(mb_strtolower($fieldOptions['type']), $fileTypes['types'])) {
 | |
| 145 | +                if (isset($fieldOptions[ 'type' ]) && mb_strpos($fieldOptions[ 'type' ], 'image/') !== false && in_array(mb_strtolower($fieldOptions[ 'type' ]), $fileTypes[ 'types' ])) {
 | |
| 146 | 146 | $this->prepareThumbs($fileName, $fileTypes); | 
| 147 | 147 | } | 
| 148 | 148 | } | 
| @@ -160,16 +160,16 @@ discard block | ||
| 160 | 160 | // Get field list of model schema | 
| 161 | 161 | $modelSchema = $model->schema(); | 
| 162 | 162 | |
| 163 | -        foreach ($this->settings[$model->alias] as $fieldName => $fieldOptions) {
 | |
| 163 | +        foreach ($this->settings[ $model->alias ] as $fieldName => $fieldOptions) {
 | |
| 164 | 164 | // Check is field in model schema | 
| 165 | -            if (isset($modelSchema[$fieldName])) {
 | |
| 165 | +            if (isset($modelSchema[ $fieldName ])) {
 | |
| 166 | 166 | $dataField = $model->findById($model->id); | 
| 167 | 167 | |
| 168 | -                if (is_array($dataField) && !empty($dataField[$model->alias][$fieldName])) {
 | |
| 168 | +                if (is_array($dataField) && !empty($dataField[ $model->alias ][ $fieldName ])) {
 | |
| 169 | 169 | // Pattern for original file with thumbs | 
| 170 | - $filePattern = $this->settings[$model->alias][$fieldName]['path'] . DS . substr($dataField[$model->alias][$fieldName], 0, 14); | |
| 170 | + $filePattern = $this->settings[ $model->alias ][ $fieldName ][ 'path' ].DS.substr($dataField[ $model->alias ][ $fieldName ], 0, 14); | |
| 171 | 171 | |
| 172 | -                    foreach (glob($filePattern . '*') as $fileName) {
 | |
| 172 | +                    foreach (glob($filePattern.'*') as $fileName) {
 | |
| 173 | 173 | // Remove file | 
| 174 | 174 | @unlink($fileName); | 
| 175 | 175 | } | 
| @@ -191,14 +191,14 @@ discard block | ||
| 191 | 191 |      {
 | 
| 192 | 192 |          if (is_file($originalFile) && is_array($settingParams)) {
 | 
| 193 | 193 | // Check image library | 
| 194 | -            if (!extension_loaded($settingParams['library'])) {
 | |
| 195 | -                throw new LibraryException(__d('file', 'The library identified by {0} is not loaded!', $settingParams['library']));
 | |
| 194 | +            if (!extension_loaded($settingParams[ 'library' ])) {
 | |
| 195 | +                throw new LibraryException(__d('file', 'The library identified by {0} is not loaded!', $settingParams[ 'library' ]));
 | |
| 196 | 196 | } | 
| 197 | 197 | |
| 198 | 198 | // Get extension from original file | 
| 199 | 199 | $fileExtension = $this->getExtension($originalFile); | 
| 200 | 200 | |
| 201 | -            switch ($settingParams['library']) {
 | |
| 201 | +            switch ($settingParams[ 'library' ]) {
 | |
| 202 | 202 | // Get image resource | 
| 203 | 203 | case 'gd': | 
| 204 | 204 |                  	switch ($fileExtension) {
 | 
| @@ -240,7 +240,7 @@ discard block | ||
| 240 | 240 | |
| 241 | 241 | break; | 
| 242 | 242 | default: | 
| 243 | -                    throw new LibraryException(__d('file', 'The library identified by {0} it is not known as image processing!', $settingParams['library']));
 | |
| 243 | +                    throw new LibraryException(__d('file', 'The library identified by {0} it is not known as image processing!', $settingParams[ 'library' ]));
 | |
| 244 | 244 | } | 
| 245 | 245 | |
| 246 | 246 | $offsetX = 0; | 
| @@ -249,48 +249,48 @@ discard block | ||
| 249 | 249 | $cropX = 0; | 
| 250 | 250 | $cropY = 0; | 
| 251 | 251 | |
| 252 | -            foreach ($settingParams['thumbs'] as $thumbName => $thumbParam) {
 | |
| 252 | +            foreach ($settingParams[ 'thumbs' ] as $thumbName => $thumbParam) {
 | |
| 253 | 253 |                  if (is_array($thumbParam)) {
 | 
| 254 | -                    if (isset($thumbParam['width']) && is_array($thumbParam['width']) && count($thumbParam['width']) === 1) {
 | |
| 255 | - list($newWidth, $newHeight) = $this->_byWidth($originalWidth, $originalHeight, $thumbParam['width'][0]); | |
| 256 | -                    } elseif (isset($thumbParam['height']) && is_array($thumbParam['height']) && count($thumbParam['height']) === 1) {
 | |
| 257 | - list($newWidth, $newHeight) = $this->_byHeight($originalWidth, $originalHeight, $thumbParam['height'][0]); | |
| 258 | -                    } elseif (isset($thumbParam['shorter']) && is_array($thumbParam['shorter']) && count($thumbParam['shorter']) === 2) {
 | |
| 259 | - list($newWidth, $newHeight) = $this->_byShorter($originalWidth, $originalHeight, $thumbParam['shorter'][0], $thumbParam['shorter'][1]); | |
| 260 | -                    } elseif (isset($thumbParam['longer']) && is_array($thumbParam['longer']) && count($thumbParam['longer']) === 2) {
 | |
| 261 | - list($newWidth, $newHeight) = $this->_byLonger($originalWidth, $originalHeight, $thumbParam['longer'][0], $thumbParam['longer'][1]); | |
| 262 | -                    } elseif (isset($thumbParam['fit']) && is_array($thumbParam['fit']) && count($thumbParam['fit']) === 2) {
 | |
| 263 | - list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->_byFit($originalWidth, $originalHeight, $thumbParam['fit'][0], $thumbParam['fit'][1]); | |
| 264 | -                    } elseif (isset($thumbParam['fit']) && is_array($thumbParam['fit']) && count($thumbParam['fit']) === 3) {
 | |
| 265 | - list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->_byFit($originalWidth, $originalHeight, $thumbParam['fit'][0], $thumbParam['fit'][1], $thumbParam['fit'][2]); | |
| 266 | -                    } elseif (isset($thumbParam['square']) && is_array($thumbParam['square']) && count($thumbParam['square']) === 1) {
 | |
| 267 | - list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->_bySquare($originalWidth, $originalHeight, $thumbParam['square'][0]); | |
| 268 | -                    } elseif (isset($thumbParam['square']) && is_array($thumbParam['square']) && count($thumbParam['square']) === 2) {
 | |
| 269 | - list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->_bySquare($originalWidth, $originalHeight, $thumbParam['square'][0], $thumbParam['square'][1]); | |
| 254 | +                    if (isset($thumbParam[ 'width' ]) && is_array($thumbParam[ 'width' ]) && count($thumbParam[ 'width' ]) === 1) {
 | |
| 255 | + list($newWidth, $newHeight) = $this->_byWidth($originalWidth, $originalHeight, $thumbParam[ 'width' ][ 0 ]); | |
| 256 | +                    } elseif (isset($thumbParam[ 'height' ]) && is_array($thumbParam[ 'height' ]) && count($thumbParam[ 'height' ]) === 1) {
 | |
| 257 | + list($newWidth, $newHeight) = $this->_byHeight($originalWidth, $originalHeight, $thumbParam[ 'height' ][ 0 ]); | |
| 258 | +                    } elseif (isset($thumbParam[ 'shorter' ]) && is_array($thumbParam[ 'shorter' ]) && count($thumbParam[ 'shorter' ]) === 2) {
 | |
| 259 | + list($newWidth, $newHeight) = $this->_byShorter($originalWidth, $originalHeight, $thumbParam[ 'shorter' ][ 0 ], $thumbParam[ 'shorter' ][ 1 ]); | |
| 260 | +                    } elseif (isset($thumbParam[ 'longer' ]) && is_array($thumbParam[ 'longer' ]) && count($thumbParam[ 'longer' ]) === 2) {
 | |
| 261 | + list($newWidth, $newHeight) = $this->_byLonger($originalWidth, $originalHeight, $thumbParam[ 'longer' ][ 0 ], $thumbParam[ 'longer' ][ 1 ]); | |
| 262 | +                    } elseif (isset($thumbParam[ 'fit' ]) && is_array($thumbParam[ 'fit' ]) && count($thumbParam[ 'fit' ]) === 2) {
 | |
| 263 | + list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->_byFit($originalWidth, $originalHeight, $thumbParam[ 'fit' ][ 0 ], $thumbParam[ 'fit' ][ 1 ]); | |
| 264 | +                    } elseif (isset($thumbParam[ 'fit' ]) && is_array($thumbParam[ 'fit' ]) && count($thumbParam[ 'fit' ]) === 3) {
 | |
| 265 | + list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->_byFit($originalWidth, $originalHeight, $thumbParam[ 'fit' ][ 0 ], $thumbParam[ 'fit' ][ 1 ], $thumbParam[ 'fit' ][ 2 ]); | |
| 266 | +                    } elseif (isset($thumbParam[ 'square' ]) && is_array($thumbParam[ 'square' ]) && count($thumbParam[ 'square' ]) === 1) {
 | |
| 267 | + list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->_bySquare($originalWidth, $originalHeight, $thumbParam[ 'square' ][ 0 ]); | |
| 268 | +                    } elseif (isset($thumbParam[ 'square' ]) && is_array($thumbParam[ 'square' ]) && count($thumbParam[ 'square' ]) === 2) {
 | |
| 269 | + list($newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY) = $this->_bySquare($originalWidth, $originalHeight, $thumbParam[ 'square' ][ 0 ], $thumbParam[ 'square' ][ 1 ]); | |
| 270 | 270 |                      } else {
 | 
| 271 | 271 |                          throw new ThumbsException(__d('file', 'Unknown type of creating thumbnails!'));
 | 
| 272 | 272 | } | 
| 273 | 273 | |
| 274 | 274 |                      $thumbFile = str_replace('default', $thumbName, $originalFile);
 | 
| 275 | 275 | |
| 276 | -                    switch ($settingParams['library']) {
 | |
| 276 | +                    switch ($settingParams[ 'library' ]) {
 | |
| 277 | 277 | // Get image resource | 
| 278 | 278 | case 'gd': | 
| 279 | 279 | $newImage = imagecreatetruecolor($newWidth, $newHeight); | 
| 280 | 280 | |
| 281 | -                            if (is_array($settingParams['background'])) {
 | |
| 281 | +                            if (is_array($settingParams[ 'background' ])) {
 | |
| 282 | 282 | // Set background color and transparent indicates | 
| 283 | - imagefill($newImage, 0, 0, imagecolorallocatealpha($newImage, $settingParams['background'][0], $settingParams['background'][1], $settingParams['background'][2], $settingParams['background'][3])); | |
| 283 | + imagefill($newImage, 0, 0, imagecolorallocatealpha($newImage, $settingParams[ 'background' ][ 0 ], $settingParams[ 'background' ][ 1 ], $settingParams[ 'background' ][ 2 ], $settingParams[ 'background' ][ 3 ])); | |
| 284 | 284 | } | 
| 285 | 285 | |
| 286 | 286 | imagecopyresampled($newImage, $sourceImage, 0, 0, 0, 0, $newWidth, $newHeight, $originalWidth, $originalHeight); | 
| 287 | 287 | |
| 288 | -                            if ((isset($thumbParam['square']) && is_array($thumbParam['square'])) || (isset($thumbParam['fit']) && is_array($thumbParam['fit']))) {
 | |
| 288 | +                            if ((isset($thumbParam[ 'square' ]) && is_array($thumbParam[ 'square' ])) || (isset($thumbParam[ 'fit' ]) && is_array($thumbParam[ 'fit' ]))) {
 | |
| 289 | 289 | $fitImage = imagecreatetruecolor($newWidth + (2 * $offsetX) - (2 * $cropX), $newHeight + (2 * $offsetY) - (2 * $cropY)); | 
| 290 | 290 | |
| 291 | -                                if (is_array($settingParams['background'])) {
 | |
| 291 | +                                if (is_array($settingParams[ 'background' ])) {
 | |
| 292 | 292 | // Set background color and transparent indicates | 
| 293 | - imagefill($fitImage, 0, 0, imagecolorallocatealpha($fitImage, $settingParams['background'][0], $settingParams['background'][1], $settingParams['background'][2], $settingParams['background'][3])); | |
| 293 | + imagefill($fitImage, 0, 0, imagecolorallocatealpha($fitImage, $settingParams[ 'background' ][ 0 ], $settingParams[ 'background' ][ 1 ], $settingParams[ 'background' ][ 2 ], $settingParams[ 'background' ][ 3 ])); | |
| 294 | 294 | } | 
| 295 | 295 | |
| 296 | 296 | imagecopyresampled($fitImage, $newImage, $offsetX, $offsetY, $cropX, $cropY, $newWidth, $newHeight, $newWidth, $newHeight); | 
| @@ -302,10 +302,10 @@ discard block | ||
| 302 | 302 | imagesavealpha($newImage, true); | 
| 303 | 303 | |
| 304 | 304 | // Watermark | 
| 305 | -                            if (isset($thumbParam['watermark']) && ($watermarkSource = file_get_contents($settingParams['watermark'])) !== false) {
 | |
| 305 | +                            if (isset($thumbParam[ 'watermark' ]) && ($watermarkSource = file_get_contents($settingParams[ 'watermark' ])) !== false) {
 | |
| 306 | 306 | $watermarkImage = imagecreatefromstring($watermarkSource); | 
| 307 | 307 | |
| 308 | - list($watermarkPositionX, $watermarkPositionY) = $this->getPosition(imagesx($newImage), imagesy($newImage), imagesx($watermarkImage), imagesy($watermarkImage), $offsetX, $offsetY, $thumbParam['watermark']); | |
| 308 | + list($watermarkPositionX, $watermarkPositionY) = $this->getPosition(imagesx($newImage), imagesy($newImage), imagesx($watermarkImage), imagesy($watermarkImage), $offsetX, $offsetY, $thumbParam[ 'watermark' ]); | |
| 309 | 309 | |
| 310 | 310 | // Set transparent | 
| 311 | 311 | imagealphablending($newImage, true); | 
| @@ -344,16 +344,16 @@ discard block | ||
| 344 | 344 |                              $newImage->setimagebackgroundcolor('transparent');
 | 
| 345 | 345 | $newImage->extentimage($newWidth + (2 * $offsetX), $newHeight + (2 * $offsetY), -$offsetX, -$offsetY); | 
| 346 | 346 | |
| 347 | -                            if ((isset($thumbParam['square']) && is_array($thumbParam['square'])) || (isset($thumbParam['fit']) && is_array($thumbParam['fit']))) {
 | |
| 347 | +                            if ((isset($thumbParam[ 'square' ]) && is_array($thumbParam[ 'square' ])) || (isset($thumbParam[ 'fit' ]) && is_array($thumbParam[ 'fit' ]))) {
 | |
| 348 | 348 | $newImage->cropimage($newWidth + (2 * $offsetX) - (2 * $cropX), $newHeight + (2 * $offsetY) - (2 * $cropY), $cropX, $cropY); | 
| 349 | 349 | } | 
| 350 | 350 | |
| 351 | 351 | // Watermark | 
| 352 | -                            if (isset($thumbParam['watermark']) && ($watermarkSource = file_get_contents($settingParams['watermark'])) !== false) {
 | |
| 352 | +                            if (isset($thumbParam[ 'watermark' ]) && ($watermarkSource = file_get_contents($settingParams[ 'watermark' ])) !== false) {
 | |
| 353 | 353 | $watermarkImage = new \Imagick(); | 
| 354 | 354 | $watermarkImage->readimageblob($watermarkSource); | 
| 355 | 355 | |
| 356 | - list($watermarkPositionX, $watermarkPositionY) = $this->getPosition($newWidth, $newHeight, $watermarkImage->getimagewidth(), $watermarkImage->getimageheight(), $offsetX, $offsetY, $thumbParam['watermark']); | |
| 356 | + list($watermarkPositionX, $watermarkPositionY) = $this->getPosition($newWidth, $newHeight, $watermarkImage->getimagewidth(), $watermarkImage->getimageheight(), $offsetX, $offsetY, $thumbParam[ 'watermark' ]); | |
| 357 | 357 | |
| 358 | 358 | $newImage->compositeimage($watermarkImage, \Imagick::COMPOSITE_OVER, $watermarkPositionX, $watermarkPositionY); | 
| 359 | 359 | } | 
| @@ -413,43 +413,43 @@ discard block | ||
| 413 | 413 |      {
 | 
| 414 | 414 |          switch (intval($positionValue)) {
 | 
| 415 | 415 | case 1: // Top left | 
| 416 | - return [$offsetX, $offsetY]; | |
| 416 | + return [ $offsetX, $offsetY ]; | |
| 417 | 417 | |
| 418 | 418 | break; | 
| 419 | 419 | case 2: // Top center | 
| 420 | - return [($newWidth / 2) - ($watermarkWidth / 2), 0 + $offsetY]; | |
| 420 | + return [ ($newWidth / 2) - ($watermarkWidth / 2), 0 + $offsetY ]; | |
| 421 | 421 | |
| 422 | 422 | break; | 
| 423 | 423 | case 3: // Top right | 
| 424 | - return [($newWidth - $watermarkWidth) - $offsetX, 0 + $offsetY]; | |
| 424 | + return [ ($newWidth - $watermarkWidth) - $offsetX, 0 + $offsetY ]; | |
| 425 | 425 | |
| 426 | 426 | break; | 
| 427 | 427 | case 4: // Middle left | 
| 428 | - return [$offsetX, ($newHeight / 2) - ($watermarkHeight / 2)]; | |
| 428 | + return [ $offsetX, ($newHeight / 2) - ($watermarkHeight / 2) ]; | |
| 429 | 429 | |
| 430 | 430 | break; | 
| 431 | 431 | case 5: // Middle center | 
| 432 | - return [($newWidth / 2) - ($watermarkWidth / 2), ($newHeight / 2) - ($watermarkHeight / 2)]; | |
| 432 | + return [ ($newWidth / 2) - ($watermarkWidth / 2), ($newHeight / 2) - ($watermarkHeight / 2) ]; | |
| 433 | 433 | |
| 434 | 434 | break; | 
| 435 | 435 | case 6: // Middle right | 
| 436 | - return [($newWidth - $watermarkWidth) - $offsetX, ($newHeight / 2) - ($watermarkHeight / 2)]; | |
| 436 | + return [ ($newWidth - $watermarkWidth) - $offsetX, ($newHeight / 2) - ($watermarkHeight / 2) ]; | |
| 437 | 437 | |
| 438 | 438 | break; | 
| 439 | 439 | case 7: // Bottom left | 
| 440 | - return [$offsetX, ($newHeight - $watermarkHeight) - $offsetY]; | |
| 440 | + return [ $offsetX, ($newHeight - $watermarkHeight) - $offsetY ]; | |
| 441 | 441 | |
| 442 | 442 | break; | 
| 443 | 443 | case 8: // Bottom center | 
| 444 | - return [($newWidth / 2) - ($watermarkWidth / 2), ($newHeight - $watermarkHeight) - $offsetY]; | |
| 444 | + return [ ($newWidth / 2) - ($watermarkWidth / 2), ($newHeight - $watermarkHeight) - $offsetY ]; | |
| 445 | 445 | |
| 446 | 446 | break; | 
| 447 | 447 | case 9: // Bottom right | 
| 448 | - return [($newWidth - $watermarkWidth) - $offsetX, ($newHeight - $watermarkHeight) - $offsetY]; | |
| 448 | + return [ ($newWidth - $watermarkWidth) - $offsetX, ($newHeight - $watermarkHeight) - $offsetY ]; | |
| 449 | 449 | |
| 450 | 450 | break; | 
| 451 | 451 | default: | 
| 452 | - return [$offsetX, $offsetY]; | |
| 452 | + return [ $offsetX, $offsetY ]; | |
| 453 | 453 | |
| 454 | 454 | break; | 
| 455 | 455 | } | 
| @@ -466,7 +466,7 @@ discard block | ||
| 466 | 466 | */ | 
| 467 | 467 | protected function _prepareName($fieldName) | 
| 468 | 468 |      {
 | 
| 469 | - return Text::uuid() . '_default.' . $this->getExtension($this->_files[$fieldName]['name']); | |
| 469 | + return Text::uuid().'_default.'.$this->getExtension($this->_files[ $fieldName ][ 'name' ]); | |
| 470 | 470 | } | 
| 471 | 471 | |
| 472 | 472 | /** | 
| @@ -478,7 +478,7 @@ discard block | ||
| 478 | 478 | */ | 
| 479 | 479 | protected function _prepareDir($dirPath) | 
| 480 | 480 |      {
 | 
| 481 | -        $dirPath = WWW_ROOT . str_replace('/', DS, $dirPath);
 | |
| 481 | +        $dirPath = WWW_ROOT.str_replace('/', DS, $dirPath);
 | |
| 482 | 482 | |
| 483 | 483 |          if (!is_dir($dirPath) && mb_strlen($dirPath) > 0) {
 | 
| 484 | 484 | mkdir($dirPath, 0777, true); | 
| @@ -508,7 +508,7 @@ discard block | ||
| 508 | 508 | $newHeight = intval($newWidth * ($originalHeight / $originalWidth)); | 
| 509 | 509 | } | 
| 510 | 510 | |
| 511 | - return [$newWidth, $newHeight]; | |
| 511 | + return [ $newWidth, $newHeight ]; | |
| 512 | 512 | } | 
| 513 | 513 | |
| 514 | 514 | /** | 
| @@ -530,7 +530,7 @@ discard block | ||
| 530 | 530 | $newWidth = intval($newHeight * ($originalWidth / $originalHeight)); | 
| 531 | 531 | } | 
| 532 | 532 | |
| 533 | - return [$newWidth, $newHeight]; | |
| 533 | + return [ $newWidth, $newHeight ]; | |
| 534 | 534 | } | 
| 535 | 535 | |
| 536 | 536 | /** | 
| @@ -553,7 +553,7 @@ discard block | ||
| 553 | 553 | list($newWidth, $newHeight) = $this->_byHeight($originalWidth, $originalHeight, $newHeight); | 
| 554 | 554 | } | 
| 555 | 555 | |
| 556 | - return [$newWidth, $newHeight]; | |
| 556 | + return [ $newWidth, $newHeight ]; | |
| 557 | 557 | } | 
| 558 | 558 | |
| 559 | 559 | /** | 
| @@ -576,7 +576,7 @@ discard block | ||
| 576 | 576 | list($newWidth, $newHeight) = $this->_byHeight($originalWidth, $originalHeight, $newHeight); | 
| 577 | 577 | } | 
| 578 | 578 | |
| 579 | - return [$newWidth, $newHeight]; | |
| 579 | + return [ $newWidth, $newHeight ]; | |
| 580 | 580 | } | 
| 581 | 581 | |
| 582 | 582 | /** | 
| @@ -605,7 +605,7 @@ discard block | ||
| 605 | 605 |              } else {
 | 
| 606 | 606 | $newSizes = $this->_byLonger($originalWidth, $originalHeight, $newWidth, $newHeight); | 
| 607 | 607 | |
| 608 | -                if ($newWidth < $newSizes[0] || $newHeight < $newSizes[1]) {
 | |
| 608 | +                if ($newWidth < $newSizes[ 0 ] || $newHeight < $newSizes[ 1 ]) {
 | |
| 609 | 609 | $newSizes = $this->_byShorter($originalWidth, $originalHeight, $newWidth, $newHeight); | 
| 610 | 610 | } | 
| 611 | 611 | } | 
| @@ -615,25 +615,25 @@ discard block | ||
| 615 | 615 |              } else {
 | 
| 616 | 616 | $newSizes = $this->_byShorter($originalWidth, $originalHeight, $newWidth, $newHeight); | 
| 617 | 617 | |
| 618 | -                if ($newWidth > $newSizes[0] || $newHeight > $newSizes[1]) {
 | |
| 618 | +                if ($newWidth > $newSizes[ 0 ] || $newHeight > $newSizes[ 1 ]) {
 | |
| 619 | 619 | $newSizes = $this->_byLonger($originalWidth, $originalHeight, $newWidth, $newHeight); | 
| 620 | 620 | } | 
| 621 | 621 | } | 
| 622 | 622 | } | 
| 623 | 623 | |
| 624 | -        if ($newWidth < $newSizes[0]) {
 | |
| 625 | - $cropX = ($newSizes[0] - $newWidth) / 2; | |
| 624 | +        if ($newWidth < $newSizes[ 0 ]) {
 | |
| 625 | + $cropX = ($newSizes[ 0 ] - $newWidth) / 2; | |
| 626 | 626 |          } else {
 | 
| 627 | - $offsetX = ($newWidth - $newSizes[0]) / 2; | |
| 627 | + $offsetX = ($newWidth - $newSizes[ 0 ]) / 2; | |
| 628 | 628 | } | 
| 629 | 629 | |
| 630 | -        if ($newHeight < $newSizes[1]) {
 | |
| 631 | - $cropY = ($newSizes[1] - $newHeight) / 2; | |
| 630 | +        if ($newHeight < $newSizes[ 1 ]) {
 | |
| 631 | + $cropY = ($newSizes[ 1 ] - $newHeight) / 2; | |
| 632 | 632 |          } else {
 | 
| 633 | - $offsetY = ($newHeight - $newSizes[1]) / 2; | |
| 633 | + $offsetY = ($newHeight - $newSizes[ 1 ]) / 2; | |
| 634 | 634 | } | 
| 635 | 635 | |
| 636 | - return [$newSizes[0], $newSizes[1], $offsetX, $offsetY, $cropX, $cropY]; | |
| 636 | + return [ $newSizes[ 0 ], $newSizes[ 1 ], $offsetX, $offsetY, $cropX, $cropY ]; | |
| 637 | 637 | } | 
| 638 | 638 | |
| 639 | 639 | /** | 
| @@ -680,6 +680,6 @@ discard block | ||
| 680 | 680 | } | 
| 681 | 681 | } | 
| 682 | 682 | |
| 683 | - return [$newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY]; | |
| 683 | + return [ $newWidth, $newHeight, $offsetX, $offsetY, $cropX, $cropY ]; | |
| 684 | 684 | } | 
| 685 | 685 | } | 
| 686 | 686 | \ No newline at end of file |