@@ -38,7 +38,8 @@ |
||
| 38 | 38 | $_GET['langCode'] = $modx_lang_attribute; |
| 39 | 39 | |
| 40 | 40 | // MAGIC AUTOLOAD CLASSES FUNCTION |
| 41 | -function autoloadda9d06472ccb71b84928677ce2a6ca89($class) { |
|
| 41 | +function autoloadda9d06472ccb71b84928677ce2a6ca89($class) |
|
| 42 | +{ |
|
| 42 | 43 | static $classes = null; |
| 43 | 44 | if ($classes === null) { |
| 44 | 45 | $classes = array( |
@@ -12,7 +12,8 @@ discard block |
||
| 12 | 12 | * @link http://kcfinder.sunhater.com |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | -class uploader { |
|
| 15 | +class uploader |
|
| 16 | +{ |
|
| 16 | 17 | |
| 17 | 18 | /** Release version */ |
| 18 | 19 | const VERSION = "2.54"; |
@@ -104,7 +105,8 @@ discard block |
||
| 104 | 105 | /** Magic method which allows read-only access to protected or private class properties |
| 105 | 106 | * @param string $property |
| 106 | 107 | * @return mixed */ |
| 107 | - public function __get($property) { |
|
| 108 | + public function __get($property) |
|
| 109 | + { |
|
| 108 | 110 | return property_exists($this, $property) ? $this->$property : null; |
| 109 | 111 | } |
| 110 | 112 | |
@@ -112,13 +114,16 @@ discard block |
||
| 112 | 114 | * uploader constructor. |
| 113 | 115 | * @param DocumentParser $modx |
| 114 | 116 | */ |
| 115 | - public function __construct(DocumentParser $modx) { |
|
| 117 | + public function __construct(DocumentParser $modx) |
|
| 118 | + { |
|
| 116 | 119 | |
| 117 | 120 | //MODX |
| 118 | 121 | try { |
| 119 | 122 | if ($modx instanceof DocumentParser) { |
| 120 | 123 | $this->modx = $modx; |
| 121 | - } else throw new Exception('MODX should be instance of DocumentParser'); |
|
| 124 | + } else { |
|
| 125 | + throw new Exception('MODX should be instance of DocumentParser'); |
|
| 126 | + } |
|
| 122 | 127 | } catch (Exception $e) { |
| 123 | 128 | die($e->getMessage()); |
| 124 | 129 | } |
@@ -133,12 +138,14 @@ discard block |
||
| 133 | 138 | // SET CMS INTEGRATION ATTRIBUTE |
| 134 | 139 | if (isset($this->get['cms']) && |
| 135 | 140 | in_array($this->get['cms'], array("drupal")) |
| 136 | - ) |
|
| 137 | - $this->cms = $this->get['cms']; |
|
| 141 | + ) { |
|
| 142 | + $this->cms = $this->get['cms']; |
|
| 143 | + } |
|
| 138 | 144 | |
| 139 | 145 | // LINKING UPLOADED FILE |
| 140 | - if (count($_FILES)) |
|
| 141 | - $this->file = &$_FILES[key($_FILES)]; |
|
| 146 | + if (count($_FILES)) { |
|
| 147 | + $this->file = &$_FILES[key($_FILES)]; |
|
| 148 | + } |
|
| 142 | 149 | |
| 143 | 150 | // LOAD DEFAULT CONFIGURATION |
| 144 | 151 | require "config.php"; |
@@ -148,31 +155,37 @@ discard block |
||
| 148 | 155 | if (isset($_CONFIG['_sessionVar']) && |
| 149 | 156 | is_array($_CONFIG['_sessionVar']) |
| 150 | 157 | ) { |
| 151 | - foreach ($_CONFIG['_sessionVar'] as $key => $val) |
|
| 152 | - if ((substr($key, 0, 1) != "_") && isset($_CONFIG[$key])) |
|
| 158 | + foreach ($_CONFIG['_sessionVar'] as $key => $val) { |
|
| 159 | + if ((substr($key, 0, 1) != "_") && isset($_CONFIG[$key])) |
|
| 153 | 160 | $this->config[$key] = $val; |
| 154 | - if (!isset($this->config['_sessionVar']['self'])) |
|
| 155 | - $this->config['_sessionVar']['self'] = array(); |
|
| 161 | + } |
|
| 162 | + if (!isset($this->config['_sessionVar']['self'])) { |
|
| 163 | + $this->config['_sessionVar']['self'] = array(); |
|
| 164 | + } |
|
| 156 | 165 | $this->session = &$this->config['_sessionVar']['self']; |
| 157 | - } else |
|
| 158 | - $this->session = &$_SESSION; |
|
| 166 | + } else { |
|
| 167 | + $this->session = &$_SESSION; |
|
| 168 | + } |
|
| 159 | 169 | |
| 160 | 170 | // IMAGE DRIVER INIT |
| 161 | 171 | if (isset($this->config['imageDriversPriority'])) { |
| 162 | 172 | $this->config['imageDriversPriority'] = |
| 163 | 173 | text::clearWhitespaces($this->config['imageDriversPriority']); |
| 164 | 174 | $driver = image::getDriver(explode(' ', $this->config['imageDriversPriority'])); |
| 165 | - if ($driver !== false) |
|
| 166 | - $this->imageDriver = $driver; |
|
| 175 | + if ($driver !== false) { |
|
| 176 | + $this->imageDriver = $driver; |
|
| 177 | + } |
|
| 167 | 178 | } |
| 168 | 179 | if ((!isset($driver) || ($driver === false)) && |
| 169 | 180 | (image::getDriver(array($this->imageDriver)) === false) |
| 170 | - ) |
|
| 171 | - die("Cannot find any of the supported PHP image extensions!"); |
|
| 181 | + ) { |
|
| 182 | + die("Cannot find any of the supported PHP image extensions!"); |
|
| 183 | + } |
|
| 172 | 184 | |
| 173 | 185 | // WATERMARK INIT |
| 174 | - if (isset($this->config['watermark']) && is_string($this->config['watermark'])) |
|
| 175 | - $this->config['watermark'] = array('file' => $this->config['watermark']); |
|
| 186 | + if (isset($this->config['watermark']) && is_string($this->config['watermark'])) { |
|
| 187 | + $this->config['watermark'] = array('file' => $this->config['watermark']); |
|
| 188 | + } |
|
| 176 | 189 | |
| 177 | 190 | // GET TYPE DIRECTORY |
| 178 | 191 | $this->types = &$this->config['types']; |
@@ -186,9 +199,10 @@ discard block |
||
| 186 | 199 | |
| 187 | 200 | // LOAD TYPE DIRECTORY SPECIFIC CONFIGURATION IF EXISTS |
| 188 | 201 | if (is_array($this->types[$this->type])) { |
| 189 | - foreach ($this->types[$this->type] as $key => $val) |
|
| 190 | - if (in_array($key, $this->typeSettings)) |
|
| 202 | + foreach ($this->types[$this->type] as $key => $val) { |
|
| 203 | + if (in_array($key, $this->typeSettings)) |
|
| 191 | 204 | $this->config[$key] = $val; |
| 205 | + } |
|
| 192 | 206 | $this->types[$this->type] = isset($this->types[$this->type]['type']) |
| 193 | 207 | ? $this->types[$this->type]['type'] : ""; |
| 194 | 208 | } |
@@ -198,12 +212,14 @@ discard block |
||
| 198 | 212 | $ip = '/^' . implode('\.', array($ip, $ip, $ip, $ip)) . '$/'; |
| 199 | 213 | if (preg_match($ip, $_SERVER['HTTP_HOST']) || |
| 200 | 214 | preg_match('/^[^\.]+$/', $_SERVER['HTTP_HOST']) |
| 201 | - ) |
|
| 202 | - $this->config['cookieDomain'] = ""; |
|
| 203 | - elseif (!strlen($this->config['cookieDomain'])) |
|
| 204 | - $this->config['cookieDomain'] = $_SERVER['HTTP_HOST']; |
|
| 205 | - if (!strlen($this->config['cookiePath'])) |
|
| 206 | - $this->config['cookiePath'] = "/"; |
|
| 215 | + ) { |
|
| 216 | + $this->config['cookieDomain'] = ""; |
|
| 217 | + } elseif (!strlen($this->config['cookieDomain'])) { |
|
| 218 | + $this->config['cookieDomain'] = $_SERVER['HTTP_HOST']; |
|
| 219 | + } |
|
| 220 | + if (!strlen($this->config['cookiePath'])) { |
|
| 221 | + $this->config['cookiePath'] = "/"; |
|
| 222 | + } |
|
| 207 | 223 | |
| 208 | 224 | // UPLOAD FOLDER INIT |
| 209 | 225 | |
@@ -239,26 +255,30 @@ discard block |
||
| 239 | 255 | $this->typeDir = "{$this->config['uploadDir']}/{$this->type}"; |
| 240 | 256 | $this->typeURL = "{$this->config['uploadURL']}/{$this->type}"; |
| 241 | 257 | } |
| 242 | - if (!is_dir($this->config['uploadDir'])) |
|
| 243 | - @mkdir($this->config['uploadDir'], $this->config['dirPerms']); |
|
| 258 | + if (!is_dir($this->config['uploadDir'])) { |
|
| 259 | + @mkdir($this->config['uploadDir'], $this->config['dirPerms']); |
|
| 260 | + } |
|
| 244 | 261 | |
| 245 | 262 | // HOST APPLICATIONS INIT |
| 246 | - if (isset($this->get['CKEditorFuncNum'])) |
|
| 247 | - $this->opener['CKEditor']['funcNum'] = $this->get['CKEditorFuncNum']; |
|
| 263 | + if (isset($this->get['CKEditorFuncNum'])) { |
|
| 264 | + $this->opener['CKEditor']['funcNum'] = $this->get['CKEditorFuncNum']; |
|
| 265 | + } |
|
| 248 | 266 | if (isset($this->get['opener']) && |
| 249 | 267 | (strtolower($this->get['opener']) == "tinymce") && |
| 250 | 268 | isset($this->config['_tinyMCEPath']) && |
| 251 | 269 | strlen($this->config['_tinyMCEPath']) |
| 252 | - ) |
|
| 253 | - $this->opener['TinyMCE'] = true; |
|
| 270 | + ) { |
|
| 271 | + $this->opener['TinyMCE'] = true; |
|
| 272 | + } |
|
| 254 | 273 | |
| 255 | 274 | // LOCALIZATION |
| 256 | - foreach ($this->langInputNames as $key) |
|
| 257 | - if (isset($this->get[$key]) && |
|
| 275 | + foreach ($this->langInputNames as $key) { |
|
| 276 | + if (isset($this->get[$key]) && |
|
| 258 | 277 | preg_match('/^[a-z][a-z\._\-]*$/i', $this->get[$key]) && |
| 259 | 278 | file_exists("lang/" . strtolower($this->get[$key]) . ".php") |
| 260 | 279 | ) { |
| 261 | 280 | $this->lang = $this->get[$key]; |
| 281 | + } |
|
| 262 | 282 | break; |
| 263 | 283 | } |
| 264 | 284 | $this->localize($this->lang); |
@@ -269,28 +289,34 @@ discard block |
||
| 269 | 289 | ) { |
| 270 | 290 | $htaccess = "{$this->config['uploadDir']}/.htaccess"; |
| 271 | 291 | if (!file_exists($htaccess)) { |
| 272 | - if (!@file_put_contents($htaccess, $this->get_htaccess())) |
|
| 273 | - $this->backMsg("Cannot write to upload folder. {$this->config['uploadDir']}"); |
|
| 292 | + if (!@file_put_contents($htaccess, $this->get_htaccess())) { |
|
| 293 | + $this->backMsg("Cannot write to upload folder. {$this->config['uploadDir']}"); |
|
| 294 | + } |
|
| 274 | 295 | } else { |
| 275 | - if (false === ($data = @file_get_contents($htaccess))) |
|
| 276 | - $this->backMsg("Cannot read .htaccess"); |
|
| 277 | - if (($data != $this->get_htaccess()) && !@file_put_contents($htaccess, $data)) |
|
| 278 | - $this->backMsg("Incorrect .htaccess file. Cannot rewrite it!"); |
|
| 296 | + if (false === ($data = @file_get_contents($htaccess))) { |
|
| 297 | + $this->backMsg("Cannot read .htaccess"); |
|
| 298 | + } |
|
| 299 | + if (($data != $this->get_htaccess()) && !@file_put_contents($htaccess, $data)) { |
|
| 300 | + $this->backMsg("Incorrect .htaccess file. Cannot rewrite it!"); |
|
| 301 | + } |
|
| 279 | 302 | } |
| 280 | 303 | } |
| 281 | 304 | |
| 282 | 305 | // CHECK & CREATE UPLOAD FOLDER |
| 283 | 306 | if (!is_dir($this->typeDir)) { |
| 284 | - if (!mkdir($this->typeDir, $this->config['dirPerms'])) |
|
| 285 | - $this->backMsg("Cannot create {dir} folder.", array('dir' => $this->type)); |
|
| 286 | - } elseif (!is_readable($this->typeDir)) |
|
| 287 | - $this->backMsg("Cannot read upload folder."); |
|
| 307 | + if (!mkdir($this->typeDir, $this->config['dirPerms'])) { |
|
| 308 | + $this->backMsg("Cannot create {dir} folder.", array('dir' => $this->type)); |
|
| 309 | + } |
|
| 310 | + } elseif (!is_readable($this->typeDir)) { |
|
| 311 | + $this->backMsg("Cannot read upload folder."); |
|
| 312 | + } |
|
| 288 | 313 | } |
| 289 | 314 | |
| 290 | 315 | /** |
| 291 | 316 | * @return array|bool|int|null|string|void |
| 292 | 317 | */ |
| 293 | - protected function getTransaliasSettings() { |
|
| 318 | + protected function getTransaliasSettings() |
|
| 319 | + { |
|
| 294 | 320 | $modx = evolutionCMS(); |
| 295 | 321 | |
| 296 | 322 | // Cleaning uploaded filename? |
@@ -314,7 +340,8 @@ discard block |
||
| 314 | 340 | * @param $filename |
| 315 | 341 | * @return mixed|string |
| 316 | 342 | */ |
| 317 | - protected function normalizeFilename($filename) { |
|
| 343 | + protected function normalizeFilename($filename) |
|
| 344 | + { |
|
| 318 | 345 | if ($this->getTransaliasSettings()) { |
| 319 | 346 | $format = strrchr($filename, "."); |
| 320 | 347 | $filename = str_replace($format, "", $filename); |
@@ -327,7 +354,8 @@ discard block |
||
| 327 | 354 | * @param $dirname |
| 328 | 355 | * @return string |
| 329 | 356 | */ |
| 330 | - protected function normalizeDirname($dirname) { |
|
| 357 | + protected function normalizeDirname($dirname) |
|
| 358 | + { |
|
| 331 | 359 | return $this->modx->stripAlias($dirname); |
| 332 | 360 | } |
| 333 | 361 | |
@@ -335,19 +363,21 @@ discard block |
||
| 335 | 363 | * @param array|null $aFile |
| 336 | 364 | * @return bool|mixed |
| 337 | 365 | */ |
| 338 | - protected function checkUploadedFile(array $aFile=null) { |
|
| 366 | + protected function checkUploadedFile(array $aFile=null) |
|
| 367 | + { |
|
| 339 | 368 | $config = &$this->config; |
| 340 | 369 | $file = ($aFile === null) ? $this->file : $aFile; |
| 341 | 370 | |
| 342 | - if (!is_array($file) || !isset($file['name'])) |
|
| 343 | - return $this->label("Unknown error."); |
|
| 371 | + if (!is_array($file) || !isset($file['name'])) { |
|
| 372 | + return $this->label("Unknown error."); |
|
| 373 | + } |
|
| 344 | 374 | |
| 345 | 375 | $extension = file::getExtension($file['name']); |
| 346 | 376 | $typePatt = strtolower(text::clearWhitespaces($this->types[$this->type])); |
| 347 | 377 | |
| 348 | 378 | // CHECK FOR UPLOAD ERRORS |
| 349 | - if ($file['error']) |
|
| 350 | - return |
|
| 379 | + if ($file['error']) { |
|
| 380 | + return |
|
| 351 | 381 | ($file['error'] == UPLOAD_ERR_INI_SIZE) ? |
| 352 | 382 | $this->label("The uploaded file exceeds {size} bytes.", |
| 353 | 383 | array('size' => ini_get('upload_max_filesize'))) : ( |
@@ -364,14 +394,17 @@ discard block |
||
| 364 | 394 | $this->label("Failed to write file.") : |
| 365 | 395 | $this->label("Unknown error.") |
| 366 | 396 | ))))); |
| 397 | + } |
|
| 367 | 398 | |
| 368 | 399 | // HIDDEN FILENAMES CHECK |
| 369 | - elseif (substr($file['name'], 0, 1) == ".") |
|
| 370 | - return $this->label("File name shouldn't begins with '.'"); |
|
| 400 | + elseif (substr($file['name'], 0, 1) == ".") { |
|
| 401 | + return $this->label("File name shouldn't begins with '.'"); |
|
| 402 | + } |
|
| 371 | 403 | |
| 372 | 404 | // EXTENSION CHECK |
| 373 | - elseif (!$this->validateExtension($extension, $this->type)) |
|
| 374 | - return $this->label("Denied file extension."); |
|
| 405 | + elseif (!$this->validateExtension($extension, $this->type)) { |
|
| 406 | + return $this->label("Denied file extension."); |
|
| 407 | + } |
|
| 375 | 408 | |
| 376 | 409 | // SPECIAL DIRECTORY TYPES CHECK (e.g. *img) |
| 377 | 410 | elseif (preg_match('/^\*([^ ]+)(.*)?$/s', $typePatt, $patt)) { |
@@ -381,25 +414,30 @@ discard block |
||
| 381 | 414 | $type = new $class(); |
| 382 | 415 | $cfg = $config; |
| 383 | 416 | $cfg['filename'] = $file['name']; |
| 384 | - if (strlen($params)) |
|
| 385 | - $cfg['params'] = trim($params); |
|
| 417 | + if (strlen($params)) { |
|
| 418 | + $cfg['params'] = trim($params); |
|
| 419 | + } |
|
| 386 | 420 | $response = $type->checkFile($file['tmp_name'], $cfg); |
| 387 | - if ($response !== true) |
|
| 388 | - return $this->label($response); |
|
| 389 | - } else |
|
| 390 | - return $this->label("Non-existing directory type."); |
|
| 421 | + if ($response !== true) { |
|
| 422 | + return $this->label($response); |
|
| 423 | + } |
|
| 424 | + } else { |
|
| 425 | + return $this->label("Non-existing directory type."); |
|
| 426 | + } |
|
| 391 | 427 | } |
| 392 | 428 | |
| 393 | 429 | // IMAGE RESIZE |
| 394 | 430 | $img = image::factory($this->imageDriver, $file['tmp_name']); |
| 395 | - if (!$img->initError && !$this->imageResize($img, $file['tmp_name'])) |
|
| 396 | - return $this->label("The image is too big and/or cannot be resized."); |
|
| 431 | + if (!$img->initError && !$this->imageResize($img, $file['tmp_name'])) { |
|
| 432 | + return $this->label("The image is too big and/or cannot be resized."); |
|
| 433 | + } |
|
| 397 | 434 | |
| 398 | 435 | |
| 399 | 436 | // CHECK FOR MODX MAX FILE SIZE |
| 400 | 437 | $actualfilesize=filesize($file['tmp_name']); |
| 401 | - if (isset($this->config['maxfilesize']) && $actualfilesize > $this->config['maxfilesize']) |
|
| 402 | - return $this->label("File is too big: ".$actualfilesize." Bytes. (max ".$this->config['maxfilesize']." Bytes)"); |
|
| 438 | + if (isset($this->config['maxfilesize']) && $actualfilesize > $this->config['maxfilesize']) { |
|
| 439 | + return $this->label("File is too big: ".$actualfilesize." Bytes. (max ".$this->config['maxfilesize']." Bytes)"); |
|
| 440 | + } |
|
| 403 | 441 | |
| 404 | 442 | return true; |
| 405 | 443 | } |
@@ -410,27 +448,32 @@ discard block |
||
| 410 | 448 | * @param bool $existing |
| 411 | 449 | * @return bool|string |
| 412 | 450 | */ |
| 413 | - protected function checkInputDir($dir, $inclType=true, $existing=true) { |
|
| 451 | + protected function checkInputDir($dir, $inclType=true, $existing=true) |
|
| 452 | + { |
|
| 414 | 453 | $dir = path::normalize($dir); |
| 415 | - if (substr($dir, 0, 1) == "/") |
|
| 416 | - $dir = substr($dir, 1); |
|
| 454 | + if (substr($dir, 0, 1) == "/") { |
|
| 455 | + $dir = substr($dir, 1); |
|
| 456 | + } |
|
| 417 | 457 | |
| 418 | - if ((substr($dir, 0, 1) == ".") || (substr(basename($dir), 0, 1) == ".")) |
|
| 419 | - return false; |
|
| 458 | + if ((substr($dir, 0, 1) == ".") || (substr(basename($dir), 0, 1) == ".")) { |
|
| 459 | + return false; |
|
| 460 | + } |
|
| 420 | 461 | |
| 421 | 462 | if ($inclType) { |
| 422 | 463 | $first = explode("/", $dir); |
| 423 | 464 | $first = $first[0]; |
| 424 | - if ($first != $this->type) |
|
| 425 | - return false; |
|
| 465 | + if ($first != $this->type) { |
|
| 466 | + return false; |
|
| 467 | + } |
|
| 426 | 468 | $return = $this->removeTypeFromPath($dir); |
| 427 | 469 | } else { |
| 428 | 470 | $return = $dir; |
| 429 | 471 | $dir = "{$this->type}/$dir"; |
| 430 | 472 | } |
| 431 | 473 | |
| 432 | - if (!$existing) |
|
| 433 | - return $return; |
|
| 474 | + if (!$existing) { |
|
| 475 | + return $return; |
|
| 476 | + } |
|
| 434 | 477 | |
| 435 | 478 | $path = "{$this->config['uploadDir']}/$dir"; |
| 436 | 479 | return (is_dir($path) && is_readable($path)) ? $return : false; |
@@ -441,21 +484,25 @@ discard block |
||
| 441 | 484 | * @param $type |
| 442 | 485 | * @return bool |
| 443 | 486 | */ |
| 444 | - protected function validateExtension($ext, $type) { |
|
| 487 | + protected function validateExtension($ext, $type) |
|
| 488 | + { |
|
| 445 | 489 | $ext = trim(strtolower($ext)); |
| 446 | - if (!isset($this->types[$type])) |
|
| 447 | - return false; |
|
| 490 | + if (!isset($this->types[$type])) { |
|
| 491 | + return false; |
|
| 492 | + } |
|
| 448 | 493 | |
| 449 | 494 | $exts = strtolower(text::clearWhitespaces($this->config['deniedExts'])); |
| 450 | 495 | if (strlen($exts)) { |
| 451 | 496 | $exts = explode(" ", $exts); |
| 452 | - if (in_array($ext, $exts)) |
|
| 453 | - return false; |
|
| 497 | + if (in_array($ext, $exts)) { |
|
| 498 | + return false; |
|
| 499 | + } |
|
| 454 | 500 | } |
| 455 | 501 | |
| 456 | 502 | $exts = trim($this->types[$type]); |
| 457 | - if (!strlen($exts) || substr($exts, 0, 1) == "*") |
|
| 458 | - return true; |
|
| 503 | + if (!strlen($exts) || substr($exts, 0, 1) == "*") { |
|
| 504 | + return true; |
|
| 505 | + } |
|
| 459 | 506 | |
| 460 | 507 | if (substr($exts, 0, 1) == "!") { |
| 461 | 508 | $exts = explode(" ", trim(strtolower(substr($exts, 1)))); |
@@ -470,7 +517,8 @@ discard block |
||
| 470 | 517 | * @param $path |
| 471 | 518 | * @return mixed |
| 472 | 519 | */ |
| 473 | - protected function getTypeFromPath($path) { |
|
| 520 | + protected function getTypeFromPath($path) |
|
| 521 | + { |
|
| 474 | 522 | return preg_match('/^([^\/]*)\/.*$/', $path, $patt) |
| 475 | 523 | ? $patt[1] : $path; |
| 476 | 524 | } |
@@ -479,7 +527,8 @@ discard block |
||
| 479 | 527 | * @param $path |
| 480 | 528 | * @return string |
| 481 | 529 | */ |
| 482 | - protected function removeTypeFromPath($path) { |
|
| 530 | + protected function removeTypeFromPath($path) |
|
| 531 | + { |
|
| 483 | 532 | return preg_match('/^[^\/]*\/(.*)$/', $path, $patt) |
| 484 | 533 | ? $patt[1] : ""; |
| 485 | 534 | } |
@@ -489,16 +538,20 @@ discard block |
||
| 489 | 538 | * @param null $file |
| 490 | 539 | * @return bool |
| 491 | 540 | */ |
| 492 | - protected function imageResize($image, $file=null) { |
|
| 541 | + protected function imageResize($image, $file=null) |
|
| 542 | + { |
|
| 493 | 543 | |
| 494 | 544 | if (!($image instanceof image)) { |
| 495 | 545 | $img = image::factory($this->imageDriver, $image); |
| 496 | - if ($img->initError) return false; |
|
| 546 | + if ($img->initError) { |
|
| 547 | + return false; |
|
| 548 | + } |
|
| 497 | 549 | $file = $image; |
| 498 | - } elseif ($file === null) |
|
| 499 | - return false; |
|
| 500 | - else |
|
| 501 | - $img = $image; |
|
| 550 | + } elseif ($file === null) { |
|
| 551 | + return false; |
|
| 552 | + } else { |
|
| 553 | + $img = $image; |
|
| 554 | + } |
|
| 502 | 555 | |
| 503 | 556 | $orientation = 1; |
| 504 | 557 | if (function_exists("exif_read_data")) { |
@@ -520,8 +573,9 @@ discard block |
||
| 520 | 573 | ) |
| 521 | 574 | ) && |
| 522 | 575 | ($orientation == 1) |
| 523 | - ) |
|
| 524 | - return true; |
|
| 576 | + ) { |
|
| 577 | + return true; |
|
| 578 | + } |
|
| 525 | 579 | |
| 526 | 580 | |
| 527 | 581 | // PROPORTIONAL RESIZE |
@@ -541,15 +595,17 @@ discard block |
||
| 541 | 595 | $width = $img->getPropWidth($height); |
| 542 | 596 | } |
| 543 | 597 | |
| 544 | - if (isset($width) && isset($height) && !$img->resize($width, $height)) |
|
| 545 | - return false; |
|
| 598 | + if (isset($width) && isset($height) && !$img->resize($width, $height)) { |
|
| 599 | + return false; |
|
| 600 | + } |
|
| 546 | 601 | |
| 547 | 602 | // RESIZE TO FIT |
| 548 | 603 | } elseif ( |
| 549 | 604 | $this->config['maxImageWidth'] && $this->config['maxImageHeight'] && |
| 550 | 605 | !$img->resizeFit($this->config['maxImageWidth'], $this->config['maxImageHeight']) |
| 551 | - ) |
|
| 552 | - return false; |
|
| 606 | + ) { |
|
| 607 | + return false; |
|
| 608 | + } |
|
| 553 | 609 | |
| 554 | 610 | // AUTO FLIP AND ROTATE FROM EXIF |
| 555 | 611 | if ((($orientation == 2) && !$img->flipHorizontal()) || |
@@ -559,11 +615,13 @@ discard block |
||
| 559 | 615 | (($orientation == 6) && !$img->rotate(90)) || |
| 560 | 616 | (($orientation == 7) && (!$img->flipHorizontal() || !$img->rotate(90))) || |
| 561 | 617 | (($orientation == 8) && !$img->rotate(270)) |
| 562 | - ) |
|
| 563 | - return false; |
|
| 564 | - if (($orientation >= 2) && ($orientation <= 8) && ($this->imageDriver == "imagick")) |
|
| 565 | - try { |
|
| 618 | + ) { |
|
| 619 | + return false; |
|
| 620 | + } |
|
| 621 | + if (($orientation >= 2) && ($orientation <= 8) && ($this->imageDriver == "imagick")) { |
|
| 622 | + try { |
|
| 566 | 623 | $img->image->setImageProperty('exif:Orientation', "1"); |
| 624 | + } |
|
| 567 | 625 | } catch (Exception $e) {} |
| 568 | 626 | |
| 569 | 627 | // WATERMARK |
@@ -599,22 +657,26 @@ discard block |
||
| 599 | 657 | * @param bool $overwrite |
| 600 | 658 | * @return bool |
| 601 | 659 | */ |
| 602 | - protected function makeThumb($file, $overwrite=true) { |
|
| 660 | + protected function makeThumb($file, $overwrite=true) |
|
| 661 | + { |
|
| 603 | 662 | $img = image::factory($this->imageDriver, $file); |
| 604 | 663 | |
| 605 | 664 | // Drop files which are not images |
| 606 | - if ($img->initError) |
|
| 607 | - return true; |
|
| 665 | + if ($img->initError) { |
|
| 666 | + return true; |
|
| 667 | + } |
|
| 608 | 668 | |
| 609 | 669 | $thumb = substr($file, strlen($this->config['uploadDir'])); |
| 610 | 670 | $thumb = $this->config['uploadDir'] . "/" . $this->config['thumbsDir'] . "/" . $thumb; |
| 611 | 671 | $thumb = path::normalize($thumb); |
| 612 | 672 | $thumbDir = dirname($thumb); |
| 613 | - if (!is_dir($thumbDir) && !@mkdir($thumbDir, $this->config['dirPerms'], true)) |
|
| 614 | - return false; |
|
| 673 | + if (!is_dir($thumbDir) && !@mkdir($thumbDir, $this->config['dirPerms'], true)) { |
|
| 674 | + return false; |
|
| 675 | + } |
|
| 615 | 676 | |
| 616 | - if (!$overwrite && is_file($thumb)) |
|
| 617 | - return true; |
|
| 677 | + if (!$overwrite && is_file($thumb)) { |
|
| 678 | + return true; |
|
| 679 | + } |
|
| 618 | 680 | |
| 619 | 681 | // Images with smaller resolutions than thumbnails |
| 620 | 682 | /*if (($img->width <= $this->config['thumbWidth']) && |
@@ -627,8 +689,9 @@ discard block |
||
| 627 | 689 | |
| 628 | 690 | // Resize image |
| 629 | 691 | } else */ |
| 630 | - if (!$img->resizeFit($this->config['thumbWidth'], $this->config['thumbHeight'])) |
|
| 631 | - return false; |
|
| 692 | + if (!$img->resizeFit($this->config['thumbWidth'], $this->config['thumbHeight'])) { |
|
| 693 | + return false; |
|
| 694 | + } |
|
| 632 | 695 | |
| 633 | 696 | if ( $this->imageDriver == 'gd' ) { |
| 634 | 697 | $width = imagesx( $img->image ); |
@@ -653,7 +716,8 @@ discard block |
||
| 653 | 716 | /** |
| 654 | 717 | * @param $langCode |
| 655 | 718 | */ |
| 656 | - protected function localize($langCode) { |
|
| 719 | + protected function localize($langCode) |
|
| 720 | + { |
|
| 657 | 721 | require "lang/{$langCode}.php"; |
| 658 | 722 | setlocale(LC_ALL, $lang['_locale']); |
| 659 | 723 | $this->charset = $lang['_charset']; |
@@ -673,11 +737,13 @@ discard block |
||
| 673 | 737 | * @param array|null $data |
| 674 | 738 | * @return mixed |
| 675 | 739 | */ |
| 676 | - protected function label($string, array $data=null) { |
|
| 740 | + protected function label($string, array $data=null) |
|
| 741 | + { |
|
| 677 | 742 | $return = isset($this->labels[$string]) ? $this->labels[$string] : $string; |
| 678 | - if (is_array($data)) |
|
| 679 | - foreach ($data as $key => $val) |
|
| 743 | + if (is_array($data)) { |
|
| 744 | + foreach ($data as $key => $val) |
|
| 680 | 745 | $return = str_replace("{{$key}}", $val, $return); |
| 746 | + } |
|
| 681 | 747 | return $return; |
| 682 | 748 | } |
| 683 | 749 | |
@@ -685,10 +751,12 @@ discard block |
||
| 685 | 751 | * @param $message |
| 686 | 752 | * @param array|null $data |
| 687 | 753 | */ |
| 688 | - protected function backMsg($message, array $data=null) { |
|
| 754 | + protected function backMsg($message, array $data=null) |
|
| 755 | + { |
|
| 689 | 756 | $message = $this->label($message, $data); |
| 690 | - if (isset($this->file['tmp_name']) && file_exists($this->file['tmp_name'])) |
|
| 691 | - @unlink($this->file['tmp_name']); |
|
| 757 | + if (isset($this->file['tmp_name']) && file_exists($this->file['tmp_name'])) { |
|
| 758 | + @unlink($this->file['tmp_name']); |
|
| 759 | + } |
|
| 692 | 760 | $this->callBack("", $message); |
| 693 | 761 | die; |
| 694 | 762 | } |
@@ -697,11 +765,14 @@ discard block |
||
| 697 | 765 | * @param $url |
| 698 | 766 | * @param string $message |
| 699 | 767 | */ |
| 700 | - protected function callBack($url, $message="") { |
|
| 768 | + protected function callBack($url, $message="") |
|
| 769 | + { |
|
| 701 | 770 | $message = text::jsValue($message); |
| 702 | 771 | $CKfuncNum = isset($this->opener['CKEditor']['funcNum']) |
| 703 | 772 | ? $this->opener['CKEditor']['funcNum'] : 0; |
| 704 | - if (!$CKfuncNum) $CKfuncNum = 0; |
|
| 773 | + if (!$CKfuncNum) { |
|
| 774 | + $CKfuncNum = 0; |
|
| 775 | + } |
|
| 705 | 776 | header("Content-Type: text/html; charset={$this->charset}"); |
| 706 | 777 | |
| 707 | 778 | ?><html> |
@@ -741,7 +812,8 @@ discard block |
||
| 741 | 812 | /** |
| 742 | 813 | * @return string |
| 743 | 814 | */ |
| 744 | - protected function get_htaccess() { |
|
| 815 | + protected function get_htaccess() |
|
| 816 | + { |
|
| 745 | 817 | return "<IfModule mod_php4.c> |
| 746 | 818 | php_value engine off |
| 747 | 819 | </IfModule> |