@@ -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,17 +105,21 @@ 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 | |
| 111 | - public function __construct($modx) { |
|
| 113 | + public function __construct($modx) |
|
| 114 | + { |
|
| 112 | 115 | |
| 113 | 116 | //MODX |
| 114 | 117 | try { |
| 115 | 118 | if ($modx instanceof DocumentParser) { |
| 116 | 119 | $this->modx = $modx; |
| 117 | - } else throw new Exception('MODX should be instance of DocumentParser'); |
|
| 120 | + } else { |
|
| 121 | + throw new Exception('MODX should be instance of DocumentParser'); |
|
| 122 | + } |
|
| 118 | 123 | } catch (Exception $e) { |
| 119 | 124 | die($e->getMessage()); |
| 120 | 125 | } |
@@ -129,26 +134,34 @@ discard block |
||
| 129 | 134 | // SET CMS INTEGRATION ATTRIBUTE |
| 130 | 135 | if (isset($this->get['cms']) && |
| 131 | 136 | in_array($this->get['cms'], array("drupal")) |
| 132 | - ) |
|
| 133 | - $this->cms = $this->get['cms']; |
|
| 137 | + ) { |
|
| 138 | + $this->cms = $this->get['cms']; |
|
| 139 | + } |
|
| 134 | 140 | |
| 135 | 141 | // LINKING UPLOADED FILE |
| 136 | - if (count($_FILES)) |
|
| 137 | - $this->file = &$_FILES[key($_FILES)]; |
|
| 142 | + if (count($_FILES)) { |
|
| 143 | + $this->file = &$_FILES[key($_FILES)]; |
|
| 144 | + } |
|
| 138 | 145 | |
| 139 | 146 | // LOAD DEFAULT CONFIGURATION |
| 140 | 147 | require "config.php"; |
| 141 | 148 | |
| 142 | 149 | // SETTING UP SESSION |
| 143 | - if (isset($_CONFIG['_sessionLifetime'])) |
|
| 144 | - ini_set('session.gc_maxlifetime', $_CONFIG['_sessionLifetime'] * 60); |
|
| 145 | - if (isset($_CONFIG['_sessionDir'])) |
|
| 146 | - ini_set('session.save_path', $_CONFIG['_sessionDir']); |
|
| 147 | - if (isset($_CONFIG['_sessionDomain'])) |
|
| 148 | - ini_set('session.cookie_domain', $_CONFIG['_sessionDomain']); |
|
| 150 | + if (isset($_CONFIG['_sessionLifetime'])) { |
|
| 151 | + ini_set('session.gc_maxlifetime', $_CONFIG['_sessionLifetime'] * 60); |
|
| 152 | + } |
|
| 153 | + if (isset($_CONFIG['_sessionDir'])) { |
|
| 154 | + ini_set('session.save_path', $_CONFIG['_sessionDir']); |
|
| 155 | + } |
|
| 156 | + if (isset($_CONFIG['_sessionDomain'])) { |
|
| 157 | + ini_set('session.cookie_domain', $_CONFIG['_sessionDomain']); |
|
| 158 | + } |
|
| 149 | 159 | switch ($this->cms) { |
| 150 | 160 | case "drupal": break; |
| 151 | - default: if (!session_id()) session_start(); break; |
|
| 161 | + default: if (!session_id()) { |
|
| 162 | + session_start(); |
|
| 163 | + } |
|
| 164 | + break; |
|
| 152 | 165 | } |
| 153 | 166 | |
| 154 | 167 | // RELOAD DEFAULT CONFIGURATION |
@@ -159,31 +172,37 @@ discard block |
||
| 159 | 172 | if (isset($_CONFIG['_sessionVar']) && |
| 160 | 173 | is_array($_CONFIG['_sessionVar']) |
| 161 | 174 | ) { |
| 162 | - foreach ($_CONFIG['_sessionVar'] as $key => $val) |
|
| 163 | - if ((substr($key, 0, 1) != "_") && isset($_CONFIG[$key])) |
|
| 175 | + foreach ($_CONFIG['_sessionVar'] as $key => $val) { |
|
| 176 | + if ((substr($key, 0, 1) != "_") && isset($_CONFIG[$key])) |
|
| 164 | 177 | $this->config[$key] = $val; |
| 165 | - if (!isset($this->config['_sessionVar']['self'])) |
|
| 166 | - $this->config['_sessionVar']['self'] = array(); |
|
| 178 | + } |
|
| 179 | + if (!isset($this->config['_sessionVar']['self'])) { |
|
| 180 | + $this->config['_sessionVar']['self'] = array(); |
|
| 181 | + } |
|
| 167 | 182 | $this->session = &$this->config['_sessionVar']['self']; |
| 168 | - } else |
|
| 169 | - $this->session = &$_SESSION; |
|
| 183 | + } else { |
|
| 184 | + $this->session = &$_SESSION; |
|
| 185 | + } |
|
| 170 | 186 | |
| 171 | 187 | // IMAGE DRIVER INIT |
| 172 | 188 | if (isset($this->config['imageDriversPriority'])) { |
| 173 | 189 | $this->config['imageDriversPriority'] = |
| 174 | 190 | text::clearWhitespaces($this->config['imageDriversPriority']); |
| 175 | 191 | $driver = image::getDriver(explode(' ', $this->config['imageDriversPriority'])); |
| 176 | - if ($driver !== false) |
|
| 177 | - $this->imageDriver = $driver; |
|
| 192 | + if ($driver !== false) { |
|
| 193 | + $this->imageDriver = $driver; |
|
| 194 | + } |
|
| 178 | 195 | } |
| 179 | 196 | if ((!isset($driver) || ($driver === false)) && |
| 180 | 197 | (image::getDriver(array($this->imageDriver)) === false) |
| 181 | - ) |
|
| 182 | - die("Cannot find any of the supported PHP image extensions!"); |
|
| 198 | + ) { |
|
| 199 | + die("Cannot find any of the supported PHP image extensions!"); |
|
| 200 | + } |
|
| 183 | 201 | |
| 184 | 202 | // WATERMARK INIT |
| 185 | - if (isset($this->config['watermark']) && is_string($this->config['watermark'])) |
|
| 186 | - $this->config['watermark'] = array('file' => $this->config['watermark']); |
|
| 203 | + if (isset($this->config['watermark']) && is_string($this->config['watermark'])) { |
|
| 204 | + $this->config['watermark'] = array('file' => $this->config['watermark']); |
|
| 205 | + } |
|
| 187 | 206 | |
| 188 | 207 | // GET TYPE DIRECTORY |
| 189 | 208 | $this->types = &$this->config['types']; |
@@ -197,9 +216,10 @@ discard block |
||
| 197 | 216 | |
| 198 | 217 | // LOAD TYPE DIRECTORY SPECIFIC CONFIGURATION IF EXISTS |
| 199 | 218 | if (is_array($this->types[$this->type])) { |
| 200 | - foreach ($this->types[$this->type] as $key => $val) |
|
| 201 | - if (in_array($key, $this->typeSettings)) |
|
| 219 | + foreach ($this->types[$this->type] as $key => $val) { |
|
| 220 | + if (in_array($key, $this->typeSettings)) |
|
| 202 | 221 | $this->config[$key] = $val; |
| 222 | + } |
|
| 203 | 223 | $this->types[$this->type] = isset($this->types[$this->type]['type']) |
| 204 | 224 | ? $this->types[$this->type]['type'] : ""; |
| 205 | 225 | } |
@@ -209,12 +229,14 @@ discard block |
||
| 209 | 229 | $ip = '/^' . implode('\.', array($ip, $ip, $ip, $ip)) . '$/'; |
| 210 | 230 | if (preg_match($ip, $_SERVER['HTTP_HOST']) || |
| 211 | 231 | preg_match('/^[^\.]+$/', $_SERVER['HTTP_HOST']) |
| 212 | - ) |
|
| 213 | - $this->config['cookieDomain'] = ""; |
|
| 214 | - elseif (!strlen($this->config['cookieDomain'])) |
|
| 215 | - $this->config['cookieDomain'] = $_SERVER['HTTP_HOST']; |
|
| 216 | - if (!strlen($this->config['cookiePath'])) |
|
| 217 | - $this->config['cookiePath'] = "/"; |
|
| 232 | + ) { |
|
| 233 | + $this->config['cookieDomain'] = ""; |
|
| 234 | + } elseif (!strlen($this->config['cookieDomain'])) { |
|
| 235 | + $this->config['cookieDomain'] = $_SERVER['HTTP_HOST']; |
|
| 236 | + } |
|
| 237 | + if (!strlen($this->config['cookiePath'])) { |
|
| 238 | + $this->config['cookiePath'] = "/"; |
|
| 239 | + } |
|
| 218 | 240 | |
| 219 | 241 | // UPLOAD FOLDER INIT |
| 220 | 242 | |
@@ -250,26 +272,30 @@ discard block |
||
| 250 | 272 | $this->typeDir = "{$this->config['uploadDir']}/{$this->type}"; |
| 251 | 273 | $this->typeURL = "{$this->config['uploadURL']}/{$this->type}"; |
| 252 | 274 | } |
| 253 | - if (!is_dir($this->config['uploadDir'])) |
|
| 254 | - @mkdir($this->config['uploadDir'], $this->config['dirPerms']); |
|
| 275 | + if (!is_dir($this->config['uploadDir'])) { |
|
| 276 | + @mkdir($this->config['uploadDir'], $this->config['dirPerms']); |
|
| 277 | + } |
|
| 255 | 278 | |
| 256 | 279 | // HOST APPLICATIONS INIT |
| 257 | - if (isset($this->get['CKEditorFuncNum'])) |
|
| 258 | - $this->opener['CKEditor']['funcNum'] = $this->get['CKEditorFuncNum']; |
|
| 280 | + if (isset($this->get['CKEditorFuncNum'])) { |
|
| 281 | + $this->opener['CKEditor']['funcNum'] = $this->get['CKEditorFuncNum']; |
|
| 282 | + } |
|
| 259 | 283 | if (isset($this->get['opener']) && |
| 260 | 284 | (strtolower($this->get['opener']) == "tinymce") && |
| 261 | 285 | isset($this->config['_tinyMCEPath']) && |
| 262 | 286 | strlen($this->config['_tinyMCEPath']) |
| 263 | - ) |
|
| 264 | - $this->opener['TinyMCE'] = true; |
|
| 287 | + ) { |
|
| 288 | + $this->opener['TinyMCE'] = true; |
|
| 289 | + } |
|
| 265 | 290 | |
| 266 | 291 | // LOCALIZATION |
| 267 | - foreach ($this->langInputNames as $key) |
|
| 268 | - if (isset($this->get[$key]) && |
|
| 292 | + foreach ($this->langInputNames as $key) { |
|
| 293 | + if (isset($this->get[$key]) && |
|
| 269 | 294 | preg_match('/^[a-z][a-z\._\-]*$/i', $this->get[$key]) && |
| 270 | 295 | file_exists("lang/" . strtolower($this->get[$key]) . ".php") |
| 271 | 296 | ) { |
| 272 | 297 | $this->lang = $this->get[$key]; |
| 298 | + } |
|
| 273 | 299 | break; |
| 274 | 300 | } |
| 275 | 301 | $this->localize($this->lang); |
@@ -280,31 +306,39 @@ discard block |
||
| 280 | 306 | ) { |
| 281 | 307 | $htaccess = "{$this->config['uploadDir']}/.htaccess"; |
| 282 | 308 | if (!file_exists($htaccess)) { |
| 283 | - if (!@file_put_contents($htaccess, $this->get_htaccess())) |
|
| 284 | - $this->backMsg("Cannot write to upload folder. {$this->config['uploadDir']}"); |
|
| 309 | + if (!@file_put_contents($htaccess, $this->get_htaccess())) { |
|
| 310 | + $this->backMsg("Cannot write to upload folder. {$this->config['uploadDir']}"); |
|
| 311 | + } |
|
| 285 | 312 | } else { |
| 286 | - if (false === ($data = @file_get_contents($htaccess))) |
|
| 287 | - $this->backMsg("Cannot read .htaccess"); |
|
| 288 | - if (($data != $this->get_htaccess()) && !@file_put_contents($htaccess, $data)) |
|
| 289 | - $this->backMsg("Incorrect .htaccess file. Cannot rewrite it!"); |
|
| 313 | + if (false === ($data = @file_get_contents($htaccess))) { |
|
| 314 | + $this->backMsg("Cannot read .htaccess"); |
|
| 315 | + } |
|
| 316 | + if (($data != $this->get_htaccess()) && !@file_put_contents($htaccess, $data)) { |
|
| 317 | + $this->backMsg("Incorrect .htaccess file. Cannot rewrite it!"); |
|
| 318 | + } |
|
| 290 | 319 | } |
| 291 | 320 | } |
| 292 | 321 | |
| 293 | 322 | // CHECK & CREATE UPLOAD FOLDER |
| 294 | 323 | if (!is_dir($this->typeDir)) { |
| 295 | - if (!mkdir($this->typeDir, $this->config['dirPerms'])) |
|
| 296 | - $this->backMsg("Cannot create {dir} folder.", array('dir' => $this->type)); |
|
| 297 | - } elseif (!is_readable($this->typeDir)) |
|
| 298 | - $this->backMsg("Cannot read upload folder."); |
|
| 324 | + if (!mkdir($this->typeDir, $this->config['dirPerms'])) { |
|
| 325 | + $this->backMsg("Cannot create {dir} folder.", array('dir' => $this->type)); |
|
| 326 | + } |
|
| 327 | + } elseif (!is_readable($this->typeDir)) { |
|
| 328 | + $this->backMsg("Cannot read upload folder."); |
|
| 329 | + } |
|
| 299 | 330 | } |
| 300 | 331 | |
| 301 | - public function upload() { |
|
| 332 | + public function upload() |
|
| 333 | + { |
|
| 302 | 334 | $config = &$this->config; |
| 303 | 335 | $file = &$this->file; |
| 304 | 336 | $url = $message = ""; |
| 305 | 337 | |
| 306 | 338 | if ($config['disabled'] || !$config['access']['files']['upload']) { |
| 307 | - if (isset($file['tmp_name'])) @unlink($file['tmp_name']); |
|
| 339 | + if (isset($file['tmp_name'])) { |
|
| 340 | + @unlink($file['tmp_name']); |
|
| 341 | + } |
|
| 308 | 342 | $message = $this->label("You don't have permissions to upload files."); |
| 309 | 343 | |
| 310 | 344 | } elseif (true === ($message = $this->checkUploadedFile())) { |
@@ -315,9 +349,9 @@ discard block |
||
| 315 | 349 | (false !== ($gdir = $this->checkInputDir($this->get['dir']))) |
| 316 | 350 | ) { |
| 317 | 351 | $udir = path::normalize("$dir$gdir"); |
| 318 | - if (substr($udir, 0, strlen($dir)) !== $dir) |
|
| 319 | - $message = $this->label("Unknown error."); |
|
| 320 | - else { |
|
| 352 | + if (substr($udir, 0, strlen($dir)) !== $dir) { |
|
| 353 | + $message = $this->label("Unknown error."); |
|
| 354 | + } else { |
|
| 321 | 355 | $l = strlen($dir); |
| 322 | 356 | $dir = "$udir/"; |
| 323 | 357 | $udir = substr($udir, $l); |
@@ -325,8 +359,9 @@ discard block |
||
| 325 | 359 | } |
| 326 | 360 | |
| 327 | 361 | if (!strlen($message)) { |
| 328 | - if (!is_dir(path::normalize($dir))) |
|
| 329 | - @mkdir(path::normalize($dir), $this->config['dirPerms'], true); |
|
| 362 | + if (!is_dir(path::normalize($dir))) { |
|
| 363 | + @mkdir(path::normalize($dir), $this->config['dirPerms'], true); |
|
| 364 | + } |
|
| 330 | 365 | |
| 331 | 366 | $filename = $this->normalizeFilename($file['name']); |
| 332 | 367 | $target = file::getInexistantFilename($dir . $filename); |
@@ -334,21 +369,25 @@ discard block |
||
| 334 | 369 | if (!@move_uploaded_file($file['tmp_name'], $target) && |
| 335 | 370 | !@rename($file['tmp_name'], $target) && |
| 336 | 371 | !@copy($file['tmp_name'], $target) |
| 337 | - ) |
|
| 338 | - $message = $this->label("Cannot move uploaded file to target folder."); |
|
| 339 | - else { |
|
| 340 | - if (function_exists('chmod')) |
|
| 341 | - @chmod($target, $this->config['filePerms']); |
|
| 372 | + ) { |
|
| 373 | + $message = $this->label("Cannot move uploaded file to target folder."); |
|
| 374 | + } else { |
|
| 375 | + if (function_exists('chmod')) { |
|
| 376 | + @chmod($target, $this->config['filePerms']); |
|
| 377 | + } |
|
| 342 | 378 | $this->makeThumb($target); |
| 343 | 379 | $url = $this->typeURL; |
| 344 | - if (isset($udir)) $url .= "/$udir"; |
|
| 380 | + if (isset($udir)) { |
|
| 381 | + $url .= "/$udir"; |
|
| 382 | + } |
|
| 345 | 383 | $url .= "/" . basename($target); |
| 346 | 384 | if (preg_match('/^([a-z]+)\:\/\/([^\/^\:]+)(\:(\d+))?\/(.+)$/', $url, $patt)) { |
| 347 | 385 | list($unused, $protocol, $domain, $unused, $port, $path) = $patt; |
| 348 | 386 | $base = "$protocol://$domain" . (strlen($port) ? ":$port" : "") . "/"; |
| 349 | 387 | $url = $base . path::urlPathEncode($path); |
| 350 | - } else |
|
| 351 | - $url = path::urlPathEncode($url); |
|
| 388 | + } else { |
|
| 389 | + $url = path::urlPathEncode($url); |
|
| 390 | + } |
|
| 352 | 391 | } |
| 353 | 392 | } |
| 354 | 393 | } |
@@ -356,16 +395,19 @@ discard block |
||
| 356 | 395 | if (strlen($message) && |
| 357 | 396 | isset($this->file['tmp_name']) && |
| 358 | 397 | file_exists($this->file['tmp_name']) |
| 359 | - ) |
|
| 360 | - @unlink($this->file['tmp_name']); |
|
| 398 | + ) { |
|
| 399 | + @unlink($this->file['tmp_name']); |
|
| 400 | + } |
|
| 361 | 401 | |
| 362 | - if (strlen($message) && method_exists($this, 'errorMsg')) |
|
| 363 | - $this->errorMsg($message); |
|
| 402 | + if (strlen($message) && method_exists($this, 'errorMsg')) { |
|
| 403 | + $this->errorMsg($message); |
|
| 404 | + } |
|
| 364 | 405 | $this->callBack($url, $message); |
| 365 | 406 | } |
| 366 | 407 | |
| 367 | 408 | |
| 368 | - protected function getTransaliasSettings() { |
|
| 409 | + protected function getTransaliasSettings() |
|
| 410 | + { |
|
| 369 | 411 | global $modx; |
| 370 | 412 | |
| 371 | 413 | // Cleaning uploaded filename? |
@@ -385,7 +427,8 @@ discard block |
||
| 385 | 427 | } |
| 386 | 428 | |
| 387 | 429 | |
| 388 | - protected function normalizeFilename($filename) { |
|
| 430 | + protected function normalizeFilename($filename) |
|
| 431 | + { |
|
| 389 | 432 | if ($this->getTransaliasSettings()) { |
| 390 | 433 | $format = strrchr($filename, "."); |
| 391 | 434 | $filename = str_replace($format, "", $filename); |
@@ -394,16 +437,19 @@ discard block |
||
| 394 | 437 | return $filename; |
| 395 | 438 | } |
| 396 | 439 | |
| 397 | - protected function normalizeDirname($dirname) { |
|
| 440 | + protected function normalizeDirname($dirname) |
|
| 441 | + { |
|
| 398 | 442 | return $this->modx->stripAlias($dirname); |
| 399 | 443 | } |
| 400 | 444 | |
| 401 | - protected function checkUploadedFile(array $aFile=null) { |
|
| 445 | + protected function checkUploadedFile(array $aFile=null) |
|
| 446 | + { |
|
| 402 | 447 | $config = &$this->config; |
| 403 | 448 | $file = ($aFile === null) ? $this->file : $aFile; |
| 404 | 449 | |
| 405 | - if (!is_array($file) || !isset($file['name'])) |
|
| 406 | - return $this->label("Unknown error"); |
|
| 450 | + if (!is_array($file) || !isset($file['name'])) { |
|
| 451 | + return $this->label("Unknown error"); |
|
| 452 | + } |
|
| 407 | 453 | |
| 408 | 454 | if (is_array($file['name'])) { |
| 409 | 455 | foreach ($file['name'] as $i => $name) { |
@@ -412,8 +458,9 @@ discard block |
||
| 412 | 458 | 'tmp_name' => $file['tmp_name'][$i], |
| 413 | 459 | 'error' => $file['error'][$i] |
| 414 | 460 | )); |
| 415 | - if ($return !== true) |
|
| 416 | - return "$name: $return"; |
|
| 461 | + if ($return !== true) { |
|
| 462 | + return "$name: $return"; |
|
| 463 | + } |
|
| 417 | 464 | } |
| 418 | 465 | return true; |
| 419 | 466 | } |
@@ -422,8 +469,8 @@ discard block |
||
| 422 | 469 | $typePatt = strtolower(text::clearWhitespaces($this->types[$this->type])); |
| 423 | 470 | |
| 424 | 471 | // CHECK FOR UPLOAD ERRORS |
| 425 | - if ($file['error']) |
|
| 426 | - return |
|
| 472 | + if ($file['error']) { |
|
| 473 | + return |
|
| 427 | 474 | ($file['error'] == UPLOAD_ERR_INI_SIZE) ? |
| 428 | 475 | $this->label("The uploaded file exceeds {size} bytes.", |
| 429 | 476 | array('size' => ini_get('upload_max_filesize'))) : ( |
@@ -440,14 +487,17 @@ discard block |
||
| 440 | 487 | $this->label("Failed to write file.") : |
| 441 | 488 | $this->label("Unknown error.") |
| 442 | 489 | ))))); |
| 490 | + } |
|
| 443 | 491 | |
| 444 | 492 | // HIDDEN FILENAMES CHECK |
| 445 | - elseif (substr($file['name'], 0, 1) == ".") |
|
| 446 | - return $this->label("File name shouldn't begins with '.'"); |
|
| 493 | + elseif (substr($file['name'], 0, 1) == ".") { |
|
| 494 | + return $this->label("File name shouldn't begins with '.'"); |
|
| 495 | + } |
|
| 447 | 496 | |
| 448 | 497 | // EXTENSION CHECK |
| 449 | - elseif (!$this->validateExtension($extension, $this->type)) |
|
| 450 | - return $this->label("Denied file extension."); |
|
| 498 | + elseif (!$this->validateExtension($extension, $this->type)) { |
|
| 499 | + return $this->label("Denied file extension."); |
|
| 500 | + } |
|
| 451 | 501 | |
| 452 | 502 | // SPECIAL DIRECTORY TYPES CHECK (e.g. *img) |
| 453 | 503 | elseif (preg_match('/^\*([^ ]+)(.*)?$/s', $typePatt, $patt)) { |
@@ -457,70 +507,84 @@ discard block |
||
| 457 | 507 | $type = new $class(); |
| 458 | 508 | $cfg = $config; |
| 459 | 509 | $cfg['filename'] = $file['name']; |
| 460 | - if (strlen($params)) |
|
| 461 | - $cfg['params'] = trim($params); |
|
| 510 | + if (strlen($params)) { |
|
| 511 | + $cfg['params'] = trim($params); |
|
| 512 | + } |
|
| 462 | 513 | $response = $type->checkFile($file['tmp_name'], $cfg); |
| 463 | - if ($response !== true) |
|
| 464 | - return $this->label($response); |
|
| 465 | - } else |
|
| 466 | - return $this->label("Non-existing directory type."); |
|
| 514 | + if ($response !== true) { |
|
| 515 | + return $this->label($response); |
|
| 516 | + } |
|
| 517 | + } else { |
|
| 518 | + return $this->label("Non-existing directory type."); |
|
| 519 | + } |
|
| 467 | 520 | } |
| 468 | 521 | |
| 469 | 522 | // IMAGE RESIZE |
| 470 | 523 | $img = image::factory($this->imageDriver, $file['tmp_name']); |
| 471 | - if (!$img->initError && !$this->imageResize($img, $file['tmp_name'])) |
|
| 472 | - return $this->label("The image is too big and/or cannot be resized."); |
|
| 524 | + if (!$img->initError && !$this->imageResize($img, $file['tmp_name'])) { |
|
| 525 | + return $this->label("The image is too big and/or cannot be resized."); |
|
| 526 | + } |
|
| 473 | 527 | |
| 474 | 528 | |
| 475 | 529 | // CHECK FOR MODX MAX FILE SIZE |
| 476 | 530 | $actualfilesize=filesize($file['tmp_name']); |
| 477 | - if (isset($this->config['maxfilesize']) && $actualfilesize > $this->config['maxfilesize']) |
|
| 478 | - return $this->label("File is too big: ".$actualfilesize." Bytes. (max ".$this->config['maxfilesize']." Bytes)"); |
|
| 531 | + if (isset($this->config['maxfilesize']) && $actualfilesize > $this->config['maxfilesize']) { |
|
| 532 | + return $this->label("File is too big: ".$actualfilesize." Bytes. (max ".$this->config['maxfilesize']." Bytes)"); |
|
| 533 | + } |
|
| 479 | 534 | |
| 480 | 535 | return true; |
| 481 | 536 | } |
| 482 | 537 | |
| 483 | - protected function checkInputDir($dir, $inclType=true, $existing=true) { |
|
| 538 | + protected function checkInputDir($dir, $inclType=true, $existing=true) |
|
| 539 | + { |
|
| 484 | 540 | $dir = path::normalize($dir); |
| 485 | - if (substr($dir, 0, 1) == "/") |
|
| 486 | - $dir = substr($dir, 1); |
|
| 541 | + if (substr($dir, 0, 1) == "/") { |
|
| 542 | + $dir = substr($dir, 1); |
|
| 543 | + } |
|
| 487 | 544 | |
| 488 | - if ((substr($dir, 0, 1) == ".") || (substr(basename($dir), 0, 1) == ".")) |
|
| 489 | - return false; |
|
| 545 | + if ((substr($dir, 0, 1) == ".") || (substr(basename($dir), 0, 1) == ".")) { |
|
| 546 | + return false; |
|
| 547 | + } |
|
| 490 | 548 | |
| 491 | 549 | if ($inclType) { |
| 492 | 550 | $first = explode("/", $dir); |
| 493 | 551 | $first = $first[0]; |
| 494 | - if ($first != $this->type) |
|
| 495 | - return false; |
|
| 552 | + if ($first != $this->type) { |
|
| 553 | + return false; |
|
| 554 | + } |
|
| 496 | 555 | $return = $this->removeTypeFromPath($dir); |
| 497 | 556 | } else { |
| 498 | 557 | $return = $dir; |
| 499 | 558 | $dir = "{$this->type}/$dir"; |
| 500 | 559 | } |
| 501 | 560 | |
| 502 | - if (!$existing) |
|
| 503 | - return $return; |
|
| 561 | + if (!$existing) { |
|
| 562 | + return $return; |
|
| 563 | + } |
|
| 504 | 564 | |
| 505 | 565 | $path = "{$this->config['uploadDir']}/$dir"; |
| 506 | 566 | return (is_dir($path) && is_readable($path)) ? $return : false; |
| 507 | 567 | } |
| 508 | 568 | |
| 509 | - protected function validateExtension($ext, $type) { |
|
| 569 | + protected function validateExtension($ext, $type) |
|
| 570 | + { |
|
| 510 | 571 | $ext = trim(strtolower($ext)); |
| 511 | - if (!isset($this->types[$type])) |
|
| 512 | - return false; |
|
| 572 | + if (!isset($this->types[$type])) { |
|
| 573 | + return false; |
|
| 574 | + } |
|
| 513 | 575 | |
| 514 | 576 | $exts = strtolower(text::clearWhitespaces($this->config['deniedExts'])); |
| 515 | 577 | if (strlen($exts)) { |
| 516 | 578 | $exts = explode(" ", $exts); |
| 517 | - if (in_array($ext, $exts)) |
|
| 518 | - return false; |
|
| 579 | + if (in_array($ext, $exts)) { |
|
| 580 | + return false; |
|
| 581 | + } |
|
| 519 | 582 | } |
| 520 | 583 | |
| 521 | 584 | $exts = trim($this->types[$type]); |
| 522 | - if (!strlen($exts) || substr($exts, 0, 1) == "*") |
|
| 523 | - return true; |
|
| 585 | + if (!strlen($exts) || substr($exts, 0, 1) == "*") { |
|
| 586 | + return true; |
|
| 587 | + } |
|
| 524 | 588 | |
| 525 | 589 | if (substr($exts, 0, 1) == "!") { |
| 526 | 590 | $exts = explode(" ", trim(strtolower(substr($exts, 1)))); |
@@ -531,26 +595,32 @@ discard block |
||
| 531 | 595 | return in_array($ext, $exts); |
| 532 | 596 | } |
| 533 | 597 | |
| 534 | - protected function getTypeFromPath($path) { |
|
| 598 | + protected function getTypeFromPath($path) |
|
| 599 | + { |
|
| 535 | 600 | return preg_match('/^([^\/]*)\/.*$/', $path, $patt) |
| 536 | 601 | ? $patt[1] : $path; |
| 537 | 602 | } |
| 538 | 603 | |
| 539 | - protected function removeTypeFromPath($path) { |
|
| 604 | + protected function removeTypeFromPath($path) |
|
| 605 | + { |
|
| 540 | 606 | return preg_match('/^[^\/]*\/(.*)$/', $path, $patt) |
| 541 | 607 | ? $patt[1] : ""; |
| 542 | 608 | } |
| 543 | 609 | |
| 544 | - protected function imageResize($image, $file=null) { |
|
| 610 | + protected function imageResize($image, $file=null) |
|
| 611 | + { |
|
| 545 | 612 | |
| 546 | 613 | if (!($image instanceof image)) { |
| 547 | 614 | $img = image::factory($this->imageDriver, $image); |
| 548 | - if ($img->initError) return false; |
|
| 615 | + if ($img->initError) { |
|
| 616 | + return false; |
|
| 617 | + } |
|
| 549 | 618 | $file = $image; |
| 550 | - } elseif ($file === null) |
|
| 551 | - return false; |
|
| 552 | - else |
|
| 553 | - $img = $image; |
|
| 619 | + } elseif ($file === null) { |
|
| 620 | + return false; |
|
| 621 | + } else { |
|
| 622 | + $img = $image; |
|
| 623 | + } |
|
| 554 | 624 | |
| 555 | 625 | $orientation = 1; |
| 556 | 626 | if (function_exists("exif_read_data")) { |
@@ -572,8 +642,9 @@ discard block |
||
| 572 | 642 | ) |
| 573 | 643 | ) && |
| 574 | 644 | ($orientation == 1) |
| 575 | - ) |
|
| 576 | - return true; |
|
| 645 | + ) { |
|
| 646 | + return true; |
|
| 647 | + } |
|
| 577 | 648 | |
| 578 | 649 | |
| 579 | 650 | // PROPORTIONAL RESIZE |
@@ -593,15 +664,17 @@ discard block |
||
| 593 | 664 | $width = $img->getPropWidth($height); |
| 594 | 665 | } |
| 595 | 666 | |
| 596 | - if (isset($width) && isset($height) && !$img->resize($width, $height)) |
|
| 597 | - return false; |
|
| 667 | + if (isset($width) && isset($height) && !$img->resize($width, $height)) { |
|
| 668 | + return false; |
|
| 669 | + } |
|
| 598 | 670 | |
| 599 | 671 | // RESIZE TO FIT |
| 600 | 672 | } elseif ( |
| 601 | 673 | $this->config['maxImageWidth'] && $this->config['maxImageHeight'] && |
| 602 | 674 | !$img->resizeFit($this->config['maxImageWidth'], $this->config['maxImageHeight']) |
| 603 | - ) |
|
| 604 | - return false; |
|
| 675 | + ) { |
|
| 676 | + return false; |
|
| 677 | + } |
|
| 605 | 678 | |
| 606 | 679 | // AUTO FLIP AND ROTATE FROM EXIF |
| 607 | 680 | if ((($orientation == 2) && !$img->flipHorizontal()) || |
@@ -611,11 +684,13 @@ discard block |
||
| 611 | 684 | (($orientation == 6) && !$img->rotate(90)) || |
| 612 | 685 | (($orientation == 7) && (!$img->flipHorizontal() || !$img->rotate(90))) || |
| 613 | 686 | (($orientation == 8) && !$img->rotate(270)) |
| 614 | - ) |
|
| 615 | - return false; |
|
| 616 | - if (($orientation >= 2) && ($orientation <= 8) && ($this->imageDriver == "imagick")) |
|
| 617 | - try { |
|
| 687 | + ) { |
|
| 688 | + return false; |
|
| 689 | + } |
|
| 690 | + if (($orientation >= 2) && ($orientation <= 8) && ($this->imageDriver == "imagick")) { |
|
| 691 | + try { |
|
| 618 | 692 | $img->image->setImageProperty('exif:Orientation', "1"); |
| 693 | + } |
|
| 619 | 694 | } catch (Exception $e) {} |
| 620 | 695 | |
| 621 | 696 | // WATERMARK |
@@ -646,22 +721,26 @@ discard block |
||
| 646 | 721 | |
| 647 | 722 | } |
| 648 | 723 | |
| 649 | - protected function makeThumb($file, $overwrite=true) { |
|
| 724 | + protected function makeThumb($file, $overwrite=true) |
|
| 725 | + { |
|
| 650 | 726 | $img = image::factory($this->imageDriver, $file); |
| 651 | 727 | |
| 652 | 728 | // Drop files which are not images |
| 653 | - if ($img->initError) |
|
| 654 | - return true; |
|
| 729 | + if ($img->initError) { |
|
| 730 | + return true; |
|
| 731 | + } |
|
| 655 | 732 | |
| 656 | 733 | $thumb = substr($file, strlen($this->config['uploadDir'])); |
| 657 | 734 | $thumb = $this->config['uploadDir'] . "/" . $this->config['thumbsDir'] . "/" . $thumb; |
| 658 | 735 | $thumb = path::normalize($thumb); |
| 659 | 736 | $thumbDir = dirname($thumb); |
| 660 | - if (!is_dir($thumbDir) && !@mkdir($thumbDir, $this->config['dirPerms'], true)) |
|
| 661 | - return false; |
|
| 737 | + if (!is_dir($thumbDir) && !@mkdir($thumbDir, $this->config['dirPerms'], true)) { |
|
| 738 | + return false; |
|
| 739 | + } |
|
| 662 | 740 | |
| 663 | - if (!$overwrite && is_file($thumb)) |
|
| 664 | - return true; |
|
| 741 | + if (!$overwrite && is_file($thumb)) { |
|
| 742 | + return true; |
|
| 743 | + } |
|
| 665 | 744 | |
| 666 | 745 | // Images with smaller resolutions than thumbnails |
| 667 | 746 | /*if (($img->width <= $this->config['thumbWidth']) && |
@@ -674,8 +753,9 @@ discard block |
||
| 674 | 753 | |
| 675 | 754 | // Resize image |
| 676 | 755 | } else */ |
| 677 | - if (!$img->resizeFit($this->config['thumbWidth'], $this->config['thumbHeight'])) |
|
| 678 | - return false; |
|
| 756 | + if (!$img->resizeFit($this->config['thumbWidth'], $this->config['thumbHeight'])) { |
|
| 757 | + return false; |
|
| 758 | + } |
|
| 679 | 759 | |
| 680 | 760 | if ( $this->imageDriver == 'gd' ) { |
| 681 | 761 | $width = imagesx( $img->image ); |
@@ -697,7 +777,8 @@ discard block |
||
| 697 | 777 | )); |
| 698 | 778 | } |
| 699 | 779 | |
| 700 | - protected function localize($langCode) { |
|
| 780 | + protected function localize($langCode) |
|
| 781 | + { |
|
| 701 | 782 | require "lang/{$langCode}.php"; |
| 702 | 783 | setlocale(LC_ALL, $lang['_locale']); |
| 703 | 784 | $this->charset = $lang['_charset']; |
@@ -712,27 +793,34 @@ discard block |
||
| 712 | 793 | $this->labels = $lang; |
| 713 | 794 | } |
| 714 | 795 | |
| 715 | - protected function label($string, array $data=null) { |
|
| 796 | + protected function label($string, array $data=null) |
|
| 797 | + { |
|
| 716 | 798 | $return = isset($this->labels[$string]) ? $this->labels[$string] : $string; |
| 717 | - if (is_array($data)) |
|
| 718 | - foreach ($data as $key => $val) |
|
| 799 | + if (is_array($data)) { |
|
| 800 | + foreach ($data as $key => $val) |
|
| 719 | 801 | $return = str_replace("{{$key}}", $val, $return); |
| 802 | + } |
|
| 720 | 803 | return $return; |
| 721 | 804 | } |
| 722 | 805 | |
| 723 | - protected function backMsg($message, array $data=null) { |
|
| 806 | + protected function backMsg($message, array $data=null) |
|
| 807 | + { |
|
| 724 | 808 | $message = $this->label($message, $data); |
| 725 | - if (isset($this->file['tmp_name']) && file_exists($this->file['tmp_name'])) |
|
| 726 | - @unlink($this->file['tmp_name']); |
|
| 809 | + if (isset($this->file['tmp_name']) && file_exists($this->file['tmp_name'])) { |
|
| 810 | + @unlink($this->file['tmp_name']); |
|
| 811 | + } |
|
| 727 | 812 | $this->callBack("", $message); |
| 728 | 813 | die; |
| 729 | 814 | } |
| 730 | 815 | |
| 731 | - protected function callBack($url, $message="") { |
|
| 816 | + protected function callBack($url, $message="") |
|
| 817 | + { |
|
| 732 | 818 | $message = text::jsValue($message); |
| 733 | 819 | $CKfuncNum = isset($this->opener['CKEditor']['funcNum']) |
| 734 | 820 | ? $this->opener['CKEditor']['funcNum'] : 0; |
| 735 | - if (!$CKfuncNum) $CKfuncNum = 0; |
|
| 821 | + if (!$CKfuncNum) { |
|
| 822 | + $CKfuncNum = 0; |
|
| 823 | + } |
|
| 736 | 824 | header("Content-Type: text/html; charset={$this->charset}"); |
| 737 | 825 | |
| 738 | 826 | ?><html> |
@@ -769,7 +857,8 @@ discard block |
||
| 769 | 857 | |
| 770 | 858 | } |
| 771 | 859 | |
| 772 | - protected function get_htaccess() { |
|
| 860 | + protected function get_htaccess() |
|
| 861 | + { |
|
| 773 | 862 | return "<IfModule mod_php4.c> |
| 774 | 863 | php_value engine off |
| 775 | 864 | </IfModule> |
@@ -14,7 +14,9 @@ |
||
| 14 | 14 | |
| 15 | 15 | require "core/autoload.php"; |
| 16 | 16 | $mtime = @filemtime(__FILE__); |
| 17 | -if ($mtime) httpCache::checkMTime($mtime); |
|
| 17 | +if ($mtime) { |
|
| 18 | + httpCache::checkMTime($mtime); |
|
| 19 | +} |
|
| 18 | 20 | $browser = new browser($modx); |
| 19 | 21 | $config = $browser->config; |
| 20 | 22 | ob_start(); |
@@ -10,11 +10,17 @@ |
||
| 10 | 10 | } |
| 11 | 11 | }; |
| 12 | 12 | <?php |
| 13 | - if(isset($_GET['type'])) $type = htmlspecialchars(trim($_GET['type']), ENT_QUOTES); |
|
| 14 | - elseif(isset($_GET['Type'])) $type = htmlspecialchars(trim($_GET['Type']), ENT_QUOTES); |
|
| 15 | - else $type = 'images'; |
|
| 13 | + if(isset($_GET['type'])) { |
|
| 14 | + $type = htmlspecialchars(trim($_GET['type']), ENT_QUOTES); |
|
| 15 | + } elseif(isset($_GET['Type'])) { |
|
| 16 | + $type = htmlspecialchars(trim($_GET['Type']), ENT_QUOTES); |
|
| 17 | + } else { |
|
| 18 | + $type = 'images'; |
|
| 19 | + } |
|
| 16 | 20 | |
| 17 | - if($type==='image') $type = 'images'; |
|
| 21 | + if($type==='image') { |
|
| 22 | + $type = 'images'; |
|
| 23 | + } |
|
| 18 | 24 | |
| 19 | 25 | $opener = (isset($_GET['editor'])) ? 'opener=' . htmlspecialchars(trim($_GET['editor']), ENT_QUOTES) : ''; |
| 20 | 26 | $request_uri = "{$opener}&type={$type}";
|
@@ -12,23 +12,27 @@ discard block |
||
| 12 | 12 | * @link http://kcfinder.sunhater.com |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | -class dir { |
|
| 15 | +class dir |
|
| 16 | +{ |
|
| 16 | 17 | |
| 17 | 18 | /** Checks if the given directory is really writable. The standard PHP |
| 18 | 19 | * function is_writable() does not work properly on Windows servers |
| 19 | 20 | * @param string $dir |
| 20 | 21 | * @return bool */ |
| 21 | 22 | |
| 22 | - static function isWritable($dir) { |
|
| 23 | + static function isWritable($dir) |
|
| 24 | + { |
|
| 23 | 25 | $dir = path::normalize($dir); |
| 24 | - if (!is_dir($dir)) |
|
| 25 | - return false; |
|
| 26 | + if (!is_dir($dir)) { |
|
| 27 | + return false; |
|
| 28 | + } |
|
| 26 | 29 | $i = 0; |
| 27 | 30 | do { |
| 28 | 31 | $file = "$dir/is_writable_" . md5($i++); |
| 29 | 32 | } while (file_exists($file)); |
| 30 | - if (!@touch($file)) |
|
| 31 | - return false; |
|
| 33 | + if (!@touch($file)) { |
|
| 34 | + return false; |
|
| 35 | + } |
|
| 32 | 36 | unlink($file); |
| 33 | 37 | return true; |
| 34 | 38 | } |
@@ -44,12 +48,16 @@ discard block |
||
| 44 | 48 | * @param array $failed |
| 45 | 49 | * @return mixed */ |
| 46 | 50 | |
| 47 | - static function prune($dir, $firstFailExit=true, array $failed=null) { |
|
| 48 | - if ($failed === null) $failed = array(); |
|
| 51 | + static function prune($dir, $firstFailExit=true, array $failed=null) |
|
| 52 | + { |
|
| 53 | + if ($failed === null) { |
|
| 54 | + $failed = array(); |
|
| 55 | + } |
|
| 49 | 56 | $files = self::content($dir); |
| 50 | 57 | if ($files === false) { |
| 51 | - if ($firstFailExit) |
|
| 52 | - return $dir; |
|
| 58 | + if ($firstFailExit) { |
|
| 59 | + return $dir; |
|
| 60 | + } |
|
| 53 | 61 | $failed[] = $dir; |
| 54 | 62 | return $failed; |
| 55 | 63 | } |
@@ -58,23 +66,27 @@ discard block |
||
| 58 | 66 | if (is_dir($file)) { |
| 59 | 67 | $failed_in = self::prune($file, $firstFailExit, $failed); |
| 60 | 68 | if ($failed_in !== true) { |
| 61 | - if ($firstFailExit) |
|
| 62 | - return $failed_in; |
|
| 63 | - if (is_array($failed_in)) |
|
| 64 | - $failed = array_merge($failed, $failed_in); |
|
| 65 | - else |
|
| 66 | - $failed[] = $failed_in; |
|
| 69 | + if ($firstFailExit) { |
|
| 70 | + return $failed_in; |
|
| 71 | + } |
|
| 72 | + if (is_array($failed_in)) { |
|
| 73 | + $failed = array_merge($failed, $failed_in); |
|
| 74 | + } else { |
|
| 75 | + $failed[] = $failed_in; |
|
| 76 | + } |
|
| 67 | 77 | } |
| 68 | 78 | } elseif (!@unlink($file)) { |
| 69 | - if ($firstFailExit) |
|
| 70 | - return $file; |
|
| 79 | + if ($firstFailExit) { |
|
| 80 | + return $file; |
|
| 81 | + } |
|
| 71 | 82 | $failed[] = $file; |
| 72 | 83 | } |
| 73 | 84 | } |
| 74 | 85 | |
| 75 | 86 | if (!@rmdir($dir)) { |
| 76 | - if ($firstFailExit) |
|
| 77 | - return $dir; |
|
| 87 | + if ($firstFailExit) { |
|
| 88 | + return $dir; |
|
| 89 | + } |
|
| 78 | 90 | $failed[] = $dir; |
| 79 | 91 | } |
| 80 | 92 | |
@@ -87,7 +99,8 @@ discard block |
||
| 87 | 99 | * @param array $options |
| 88 | 100 | * @return mixed */ |
| 89 | 101 | |
| 90 | - static function content($dir, array $options=null) { |
|
| 102 | + static function content($dir, array $options=null) |
|
| 103 | + { |
|
| 91 | 104 | |
| 92 | 105 | $defaultOptions = array( |
| 93 | 106 | 'types' => "all", // Allowed: "all" or possible return values |
@@ -97,23 +110,28 @@ discard block |
||
| 97 | 110 | 'followLinks' => true |
| 98 | 111 | ); |
| 99 | 112 | |
| 100 | - if (!is_dir($dir) || !is_readable($dir)) |
|
| 101 | - return false; |
|
| 113 | + if (!is_dir($dir) || !is_readable($dir)) { |
|
| 114 | + return false; |
|
| 115 | + } |
|
| 102 | 116 | |
| 103 | - if (strtoupper(substr(PHP_OS, 0, 3)) == "WIN") |
|
| 104 | - $dir = str_replace("\\", "/", $dir); |
|
| 117 | + if (strtoupper(substr(PHP_OS, 0, 3)) == "WIN") { |
|
| 118 | + $dir = str_replace("\\", "/", $dir); |
|
| 119 | + } |
|
| 105 | 120 | $dir = rtrim($dir, "/"); |
| 106 | 121 | |
| 107 | 122 | $dh = @opendir($dir); |
| 108 | - if ($dh === false) |
|
| 109 | - return false; |
|
| 123 | + if ($dh === false) { |
|
| 124 | + return false; |
|
| 125 | + } |
|
| 110 | 126 | |
| 111 | - if ($options === null) |
|
| 112 | - $options = $defaultOptions; |
|
| 127 | + if ($options === null) { |
|
| 128 | + $options = $defaultOptions; |
|
| 129 | + } |
|
| 113 | 130 | |
| 114 | - foreach ($defaultOptions as $key => $val) |
|
| 115 | - if (!isset($options[$key])) |
|
| 131 | + foreach ($defaultOptions as $key => $val) { |
|
| 132 | + if (!isset($options[$key])) |
|
| 116 | 133 | $options[$key] = $val; |
| 134 | + } |
|
| 117 | 135 | |
| 118 | 136 | $files = array(); |
| 119 | 137 | while (($file = @readdir($dh)) !== false) { |
@@ -124,28 +142,32 @@ discard block |
||
| 124 | 142 | do { |
| 125 | 143 | $ldir = dirname($lfile); |
| 126 | 144 | $lfile = @readlink($lfile); |
| 127 | - if (substr($lfile, 0, 1) != "/") |
|
| 128 | - $lfile = "$ldir/$lfile"; |
|
| 145 | + if (substr($lfile, 0, 1) != "/") { |
|
| 146 | + $lfile = "$ldir/$lfile"; |
|
| 147 | + } |
|
| 129 | 148 | $type = filetype($lfile); |
| 130 | 149 | } while ($type == "link"); |
| 131 | 150 | } |
| 132 | 151 | |
| 133 | 152 | if ((($type === "dir") && (($file == ".") || ($file == ".."))) || |
| 134 | 153 | !preg_match($options['pattern'], $file) |
| 135 | - ) |
|
| 136 | - continue; |
|
| 154 | + ) { |
|
| 155 | + continue; |
|
| 156 | + } |
|
| 137 | 157 | |
| 138 | 158 | if (($options['types'] === "all") || ($type === $options['types']) || |
| 139 | 159 | ((is_array($options['types'])) && in_array($type, $options['types'])) |
| 140 | - ) |
|
| 141 | - $files[] = $options['addPath'] ? "$dir/$file" : $file; |
|
| 160 | + ) { |
|
| 161 | + $files[] = $options['addPath'] ? "$dir/$file" : $file; |
|
| 162 | + } |
|
| 142 | 163 | } |
| 143 | 164 | closedir($dh); |
| 144 | 165 | usort($files, array("dir", "fileSort")); |
| 145 | 166 | return $files; |
| 146 | 167 | } |
| 147 | 168 | |
| 148 | - static function fileSort($a, $b) { |
|
| 169 | + static function fileSort($a, $b) |
|
| 170 | + { |
|
| 149 | 171 | if (function_exists("mb_strtolower")) { |
| 150 | 172 | $a = mb_strtolower($a); |
| 151 | 173 | $b = mb_strtolower($b); |
@@ -153,7 +175,9 @@ discard block |
||
| 153 | 175 | $a = strtolower($a); |
| 154 | 176 | $b = strtolower($b); |
| 155 | 177 | } |
| 156 | - if ($a == $b) return 0; |
|
| 178 | + if ($a == $b) { |
|
| 179 | + return 0; |
|
| 180 | + } |
|
| 157 | 181 | return ($a < $b) ? -1 : 1; |
| 158 | 182 | } |
| 159 | 183 | } |
@@ -12,7 +12,8 @@ discard block |
||
| 12 | 12 | * @link http://kcfinder.sunhater.com |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | -class input { |
|
| 15 | +class input |
|
| 16 | +{ |
|
| 16 | 17 | |
| 17 | 18 | /** Filtered $_GET array |
| 18 | 19 | * @var array */ |
@@ -26,7 +27,8 @@ discard block |
||
| 26 | 27 | * @var array */ |
| 27 | 28 | public $cookie; |
| 28 | 29 | |
| 29 | - public function __construct() { |
|
| 30 | + public function __construct() |
|
| 31 | + { |
|
| 30 | 32 | $this->get = &$_GET; |
| 31 | 33 | $this->post = &$_POST; |
| 32 | 34 | $this->cookie = &$_COOKIE; |
@@ -36,7 +38,8 @@ discard block |
||
| 36 | 38 | * @param string $property |
| 37 | 39 | * @return mixed */ |
| 38 | 40 | |
| 39 | - public function __get($property) { |
|
| 41 | + public function __get($property) |
|
| 42 | + { |
|
| 40 | 43 | return property_exists($this, $property) ? $this->$property : null; |
| 41 | 44 | } |
| 42 | 45 | } |
@@ -12,29 +12,36 @@ discard block |
||
| 12 | 12 | * @link http://kcfinder.sunhater.com |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | -class path { |
|
| 15 | +class path |
|
| 16 | +{ |
|
| 16 | 17 | |
| 17 | 18 | /** Get the absolute URL path of the given one. Returns FALSE if the URL |
| 18 | 19 | * is not valid or the current directory cannot be resolved (getcwd()) |
| 19 | 20 | * @param string $path |
| 20 | 21 | * @return string */ |
| 21 | 22 | |
| 22 | - static function rel2abs_url($path) { |
|
| 23 | - if (substr($path, 0, 1) == "/") return $path; |
|
| 23 | + static function rel2abs_url($path) |
|
| 24 | + { |
|
| 25 | + if (substr($path, 0, 1) == "/") { |
|
| 26 | + return $path; |
|
| 27 | + } |
|
| 24 | 28 | $dir = @getcwd(); |
| 25 | 29 | |
| 26 | - if (!isset($_SERVER['DOCUMENT_ROOT']) || ($dir === false)) |
|
| 27 | - return false; |
|
| 30 | + if (!isset($_SERVER['DOCUMENT_ROOT']) || ($dir === false)) { |
|
| 31 | + return false; |
|
| 32 | + } |
|
| 28 | 33 | |
| 29 | 34 | $dir = self::normalize($dir); |
| 30 | 35 | $doc_root = self::normalize($_SERVER['DOCUMENT_ROOT']); |
| 31 | 36 | |
| 32 | - if (substr($dir, 0, strlen($doc_root)) != $doc_root) |
|
| 33 | - return false; |
|
| 37 | + if (substr($dir, 0, strlen($doc_root)) != $doc_root) { |
|
| 38 | + return false; |
|
| 39 | + } |
|
| 34 | 40 | |
| 35 | 41 | $return = self::normalize(substr($dir, strlen($doc_root)) . "/$path"); |
| 36 | - if (substr($return, 0, 1) !== "/") |
|
| 37 | - $return = "/$return"; |
|
| 42 | + if (substr($return, 0, 1) !== "/") { |
|
| 43 | + $return = "/$return"; |
|
| 44 | + } |
|
| 38 | 45 | |
| 39 | 46 | return $return; |
| 40 | 47 | } |
@@ -44,7 +51,8 @@ discard block |
||
| 44 | 51 | * @param string $url |
| 45 | 52 | * @return string */ |
| 46 | 53 | |
| 47 | - static function url2fullPath($url) { |
|
| 54 | + static function url2fullPath($url) |
|
| 55 | + { |
|
| 48 | 56 | $url = self::normalize($url); |
| 49 | 57 | |
| 50 | 58 | $uri = isset($_SERVER['SCRIPT_NAME']) |
@@ -55,7 +63,9 @@ discard block |
||
| 55 | 63 | $uri = self::normalize($uri); |
| 56 | 64 | |
| 57 | 65 | if (substr($url, 0, 1) !== "/") { |
| 58 | - if ($uri === false) return false; |
|
| 66 | + if ($uri === false) { |
|
| 67 | + return false; |
|
| 68 | + } |
|
| 59 | 69 | $url = dirname($uri) . "/$url"; |
| 60 | 70 | } |
| 61 | 71 | |
@@ -63,7 +73,9 @@ discard block |
||
| 63 | 73 | return self::normalize($_SERVER['DOCUMENT_ROOT'] . "/$url"); |
| 64 | 74 | |
| 65 | 75 | } else { |
| 66 | - if ($uri === false) return false; |
|
| 76 | + if ($uri === false) { |
|
| 77 | + return false; |
|
| 78 | + } |
|
| 67 | 79 | |
| 68 | 80 | if (isset($_SERVER['SCRIPT_FILENAME'])) { |
| 69 | 81 | $scr_filename = self::normalize($_SERVER['SCRIPT_FILENAME']); |
@@ -71,13 +83,15 @@ discard block |
||
| 71 | 83 | } |
| 72 | 84 | |
| 73 | 85 | $count = count(explode('/', $uri)) - 1; |
| 74 | - for ($i = 0, $chdir = ""; $i < $count; $i++) |
|
| 75 | - $chdir .= "../"; |
|
| 86 | + for ($i = 0, $chdir = ""; $i < $count; $i++) { |
|
| 87 | + $chdir .= "../"; |
|
| 88 | + } |
|
| 76 | 89 | $chdir = self::normalize($chdir); |
| 77 | 90 | |
| 78 | 91 | $dir = getcwd(); |
| 79 | - if (($dir === false) || !@chdir($chdir)) |
|
| 80 | - return false; |
|
| 92 | + if (($dir === false) || !@chdir($chdir)) { |
|
| 93 | + return false; |
|
| 94 | + } |
|
| 81 | 95 | $rdir = getcwd(); |
| 82 | 96 | chdir($dir); |
| 83 | 97 | return ($rdir !== false) ? self::normalize($rdir . "/$url") : false; |
@@ -92,22 +106,29 @@ discard block |
||
| 92 | 106 | * @param string $path |
| 93 | 107 | * @return string */ |
| 94 | 108 | |
| 95 | - static function normalize($path) { |
|
| 109 | + static function normalize($path) |
|
| 110 | + { |
|
| 96 | 111 | if (strtoupper(substr(PHP_OS, 0, 3)) == "WIN") { |
| 97 | 112 | $path = preg_replace('/([^\\\])\\\([^\\\])/', "$1/$2", $path); |
| 98 | - if (substr($path, -1) == "\\") $path = substr($path, 0, -1); |
|
| 99 | - if (substr($path, 0, 1) == "\\") $path = "/" . substr($path, 1); |
|
| 113 | + if (substr($path, -1) == "\\") { |
|
| 114 | + $path = substr($path, 0, -1); |
|
| 115 | + } |
|
| 116 | + if (substr($path, 0, 1) == "\\") { |
|
| 117 | + $path = "/" . substr($path, 1); |
|
| 118 | + } |
|
| 100 | 119 | } |
| 101 | 120 | |
| 102 | 121 | $path = preg_replace('/\/+/s', "/", $path); |
| 103 | 122 | |
| 104 | 123 | $path = "/$path"; |
| 105 | - if (substr($path, -1) != "/") |
|
| 106 | - $path .= "/"; |
|
| 124 | + if (substr($path, -1) != "/") { |
|
| 125 | + $path .= "/"; |
|
| 126 | + } |
|
| 107 | 127 | |
| 108 | 128 | $expr = '/\/([^\/]{1}|[^\.\/]{2}|[^\/]{3,})\/\.\.\//s'; |
| 109 | - while (preg_match($expr, $path)) |
|
| 110 | - $path = preg_replace($expr, "/", $path); |
|
| 129 | + while (preg_match($expr, $path)) { |
|
| 130 | + $path = preg_replace($expr, "/", $path); |
|
| 131 | + } |
|
| 111 | 132 | |
| 112 | 133 | $path = substr($path, 0, -1); |
| 113 | 134 | $path = substr($path, 1); |
@@ -118,11 +139,13 @@ discard block |
||
| 118 | 139 | * @param string $path |
| 119 | 140 | * @return string */ |
| 120 | 141 | |
| 121 | - static function urlPathEncode($path) { |
|
| 142 | + static function urlPathEncode($path) |
|
| 143 | + { |
|
| 122 | 144 | $path = self::normalize($path); |
| 123 | 145 | $encoded = ""; |
| 124 | - foreach (explode("/", $path) as $dir) |
|
| 125 | - $encoded .= rawurlencode($dir) . "/"; |
|
| 146 | + foreach (explode("/", $path) as $dir) { |
|
| 147 | + $encoded .= rawurlencode($dir) . "/"; |
|
| 148 | + } |
|
| 126 | 149 | $encoded = substr($encoded, 0, -1); |
| 127 | 150 | return $encoded; |
| 128 | 151 | } |
@@ -131,11 +154,13 @@ discard block |
||
| 131 | 154 | * @param string $path |
| 132 | 155 | * @return string */ |
| 133 | 156 | |
| 134 | - static function urlPathDecode($path) { |
|
| 157 | + static function urlPathDecode($path) |
|
| 158 | + { |
|
| 135 | 159 | $path = self::normalize($path); |
| 136 | 160 | $decoded = ""; |
| 137 | - foreach (explode("/", $path) as $dir) |
|
| 138 | - $decoded .= rawurldecode($dir) . "/"; |
|
| 161 | + foreach (explode("/", $path) as $dir) { |
|
| 162 | + $decoded .= rawurldecode($dir) . "/"; |
|
| 163 | + } |
|
| 139 | 164 | $decoded = substr($decoded, 0, -1); |
| 140 | 165 | return $decoded; |
| 141 | 166 | } |
@@ -12,7 +12,8 @@ discard block |
||
| 12 | 12 | * @link http://kcfinder.sunhater.com |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | -class file { |
|
| 15 | +class file |
|
| 16 | +{ |
|
| 16 | 17 | |
| 17 | 18 | static $MIME = array( |
| 18 | 19 | 'ai' => 'application/postscript', |
@@ -105,10 +106,12 @@ discard block |
||
| 105 | 106 | * @param string $dir |
| 106 | 107 | * @return bool */ |
| 107 | 108 | |
| 108 | - static function isWritable($filename) { |
|
| 109 | + static function isWritable($filename) |
|
| 110 | + { |
|
| 109 | 111 | $filename = path::normalize($filename); |
| 110 | - if (!is_file($filename) || (false === ($fp = @fopen($filename, 'a+')))) |
|
| 111 | - return false; |
|
| 112 | + if (!is_file($filename) || (false === ($fp = @fopen($filename, 'a+')))) { |
|
| 113 | + return false; |
|
| 114 | + } |
|
| 112 | 115 | fclose($fp); |
| 113 | 116 | return true; |
| 114 | 117 | } |
@@ -118,7 +121,8 @@ discard block |
||
| 118 | 121 | * @param bool $toLower |
| 119 | 122 | * @return string */ |
| 120 | 123 | |
| 121 | - static function getExtension($filename, $toLower=true) { |
|
| 124 | + static function getExtension($filename, $toLower=true) |
|
| 125 | + { |
|
| 122 | 126 | return preg_match('/^.*\.([^\.]*)$/s', $filename, $patt) |
| 123 | 127 | ? ($toLower ? strtolower($patt[1]) : $patt[1]) : ""; |
| 124 | 128 | } |
@@ -134,7 +138,8 @@ discard block |
||
| 134 | 138 | * @param string $magic |
| 135 | 139 | * @return string */ |
| 136 | 140 | |
| 137 | - static function getMimeType($filename, $magic=null) { |
|
| 141 | + static function getMimeType($filename, $magic=null) |
|
| 142 | + { |
|
| 138 | 143 | if (class_exists("finfo")) { |
| 139 | 144 | $finfo = ($magic === null) |
| 140 | 145 | ? new finfo(FILEINFO_MIME) |
@@ -170,12 +175,15 @@ discard block |
||
| 170 | 175 | * @param string $tpl |
| 171 | 176 | * @return string */ |
| 172 | 177 | |
| 173 | - static function getInexistantFilename($filename, $dir=null, $tpl=null) { |
|
| 174 | - if ($tpl === null) $tpl = "{name}({sufix}){ext}"; |
|
| 178 | + static function getInexistantFilename($filename, $dir=null, $tpl=null) |
|
| 179 | + { |
|
| 180 | + if ($tpl === null) { |
|
| 181 | + $tpl = "{name}({sufix}){ext}"; |
|
| 182 | + } |
|
| 175 | 183 | $fullPath = ($dir === null); |
| 176 | - if ($fullPath) |
|
| 177 | - $dir = path::normalize(dirname($filename)); |
|
| 178 | - else { |
|
| 184 | + if ($fullPath) { |
|
| 185 | + $dir = path::normalize(dirname($filename)); |
|
| 186 | + } else { |
|
| 179 | 187 | $fdir = dirname($filename); |
| 180 | 188 | $dir = strlen($fdir) |
| 181 | 189 | ? path::normalize("$dir/$fdir") |
@@ -187,8 +195,9 @@ discard block |
||
| 187 | 195 | $tpl = str_replace('{name}', $name, $tpl); |
| 188 | 196 | $tpl = str_replace('{ext}', (strlen($ext) ? ".$ext" : ""), $tpl); |
| 189 | 197 | $i = 1; $file = "$dir/$filename"; |
| 190 | - while (file_exists($file)) |
|
| 191 | - $file = "$dir/" . str_replace('{sufix}', $i++, $tpl); |
|
| 198 | + while (file_exists($file)) { |
|
| 199 | + $file = "$dir/" . str_replace('{sufix}', $i++, $tpl); |
|
| 200 | + } |
|
| 192 | 201 | |
| 193 | 202 | return $fullPath |
| 194 | 203 | ? $file |
@@ -12,7 +12,8 @@ discard block |
||
| 12 | 12 | * @link http://kcfinder.sunhater.com |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | -abstract class image { |
|
| 15 | +abstract class image |
|
| 16 | +{ |
|
| 16 | 17 | const DEFAULT_JPEG_QUALITY = 75; |
| 17 | 18 | |
| 18 | 19 | /** Image resource or object |
@@ -41,7 +42,8 @@ discard block |
||
| 41 | 42 | * @param string $property |
| 42 | 43 | * @return mixed */ |
| 43 | 44 | |
| 44 | - final public function __get($property) { |
|
| 45 | + final public function __get($property) |
|
| 46 | + { |
|
| 45 | 47 | return property_exists($this, $property) ? $this->$property : null; |
| 46 | 48 | } |
| 47 | 49 | |
@@ -57,14 +59,16 @@ discard block |
||
| 57 | 59 | * @param mixed $image |
| 58 | 60 | * @param array $options */ |
| 59 | 61 | |
| 60 | - public function __construct($image, array $options=array()) { |
|
| 62 | + public function __construct($image, array $options=array()) |
|
| 63 | + { |
|
| 61 | 64 | $this->image = $this->width = $this->height = null; |
| 62 | 65 | $imageDetails = $this->buildImage($image); |
| 63 | 66 | |
| 64 | - if ($imageDetails !== false) |
|
| 65 | - list($this->image, $this->width, $this->height) = $imageDetails; |
|
| 66 | - else |
|
| 67 | - $this->initError = true; |
|
| 67 | + if ($imageDetails !== false) { |
|
| 68 | + list($this->image, $this->width, $this->height) = $imageDetails; |
|
| 69 | + } else { |
|
| 70 | + $this->initError = true; |
|
| 71 | + } |
|
| 68 | 72 | $this->options = $options; |
| 69 | 73 | } |
| 70 | 74 | |
@@ -75,7 +79,8 @@ discard block |
||
| 75 | 79 | * @param mixed $image |
| 76 | 80 | * @return object */ |
| 77 | 81 | |
| 78 | - final static function factory($driver, $image, array $options=array()) { |
|
| 82 | + final static function factory($driver, $image, array $options=array()) |
|
| 83 | + { |
|
| 79 | 84 | $class = "image_$driver"; |
| 80 | 85 | return new $class($image, $options); |
| 81 | 86 | } |
@@ -86,14 +91,18 @@ discard block |
||
| 86 | 91 | * @param array $drivers |
| 87 | 92 | * @return string */ |
| 88 | 93 | |
| 89 | - final static function getDriver(array $drivers=array('gd')) { |
|
| 94 | + final static function getDriver(array $drivers=array('gd')) |
|
| 95 | + { |
|
| 90 | 96 | foreach ($drivers as $driver) { |
| 91 | - if (!preg_match('/^[a-z0-9\_]+$/i', $driver)) |
|
| 92 | - continue; |
|
| 97 | + if (!preg_match('/^[a-z0-9\_]+$/i', $driver)) { |
|
| 98 | + continue; |
|
| 99 | + } |
|
| 93 | 100 | $class = "image_$driver"; |
| 94 | 101 | if (class_exists($class) && method_exists($class, "available")) { |
| 95 | 102 | eval("\$avail = $class::available();"); |
| 96 | - if ($avail) return $driver; |
|
| 103 | + if ($avail) { |
|
| 104 | + return $driver; |
|
| 105 | + } |
|
| 97 | 106 | } |
| 98 | 107 | } |
| 99 | 108 | return false; |
@@ -105,7 +114,8 @@ discard block |
||
| 105 | 114 | * @param mixed $image |
| 106 | 115 | * @return array */ |
| 107 | 116 | |
| 108 | - final protected function buildImage($image) { |
|
| 117 | + final protected function buildImage($image) |
|
| 118 | + { |
|
| 109 | 119 | $class = get_class($this); |
| 110 | 120 | |
| 111 | 121 | if ($image instanceof $class) { |
@@ -118,8 +128,9 @@ discard block |
||
| 118 | 128 | list($key, $height) = each($image); |
| 119 | 129 | $img = $this->getBlankImage($width, $height); |
| 120 | 130 | |
| 121 | - } else |
|
| 122 | - $img = $this->getImage($image, $width, $height); |
|
| 131 | + } else { |
|
| 132 | + $img = $this->getImage($image, $width, $height); |
|
| 133 | + } |
|
| 123 | 134 | |
| 124 | 135 | return ($img !== false) |
| 125 | 136 | ? array($img, $width, $height) |
@@ -131,9 +142,12 @@ discard block |
||
| 131 | 142 | * @param integer $resizedHeight |
| 132 | 143 | * @return integer */ |
| 133 | 144 | |
| 134 | - final public function getPropWidth($resizedHeight) { |
|
| 145 | + final public function getPropWidth($resizedHeight) |
|
| 146 | + { |
|
| 135 | 147 | $width = round(($this->width * $resizedHeight) / $this->height); |
| 136 | - if (!$width) $width = 1; |
|
| 148 | + if (!$width) { |
|
| 149 | + $width = 1; |
|
| 150 | + } |
|
| 137 | 151 | return $width; |
| 138 | 152 | } |
| 139 | 153 | |
@@ -142,9 +156,12 @@ discard block |
||
| 142 | 156 | * @param integer $resizedWidth |
| 143 | 157 | * @return integer */ |
| 144 | 158 | |
| 145 | - final public function getPropHeight($resizedWidth) { |
|
| 159 | + final public function getPropHeight($resizedWidth) |
|
| 160 | + { |
|
| 146 | 161 | $height = round(($this->height * $resizedWidth) / $this->width); |
| 147 | - if (!$height) $height = 1; |
|
| 162 | + if (!$height) { |
|
| 163 | + $height = 1; |
|
| 164 | + } |
|
| 148 | 165 | return $height; |
| 149 | 166 | } |
| 150 | 167 | |
@@ -153,13 +170,17 @@ discard block |
||
| 153 | 170 | * static method should be implemented into driver classes like abstract |
| 154 | 171 | * methods |
| 155 | 172 | * @return bool */ |
| 156 | - static function available() { return false; } |
|
| 173 | + static function available() |
|
| 174 | + { |
|
| 175 | +return false; } |
|
| 157 | 176 | |
| 158 | 177 | /** Checks if file is an image. This static method should be implemented into |
| 159 | 178 | * driver classes like abstract methods |
| 160 | 179 | * @param string $file |
| 161 | 180 | * @return bool */ |
| 162 | - static function checkImage($file) { return false; } |
|
| 181 | + static function checkImage($file) |
|
| 182 | + { |
|
| 183 | +return false; } |
|
| 163 | 184 | |
| 164 | 185 | /** Resize image. Should return TRUE on success or FALSE on failure |
| 165 | 186 | * @param integer $width |
@@ -12,7 +12,8 @@ discard block |
||
| 12 | 12 | * @link http://kcfinder.sunhater.com |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | -class httpCache { |
|
| 15 | +class httpCache |
|
| 16 | +{ |
|
| 16 | 17 | const DEFAULT_TYPE = "text/html"; |
| 17 | 18 | const DEFAULT_EXPIRE = 604800; // in seconds |
| 18 | 19 | |
@@ -25,15 +26,20 @@ discard block |
||
| 25 | 26 | * @param integer $expire |
| 26 | 27 | * @param array $headers */ |
| 27 | 28 | |
| 28 | - static function file($file, $type=null, $expire=null, array $headers=null) { |
|
| 29 | + static function file($file, $type=null, $expire=null, array $headers=null) |
|
| 30 | + { |
|
| 29 | 31 | $mtime = @filemtime($file); |
| 30 | - if ($mtime !== false) self::checkMTime($mtime); |
|
| 32 | + if ($mtime !== false) { |
|
| 33 | + self::checkMTime($mtime); |
|
| 34 | + } |
|
| 31 | 35 | |
| 32 | 36 | if ($type === null) { |
| 33 | 37 | $magic = ((substr($type, 0, 1) == "/") || preg_match('/^[a-z]\:/i', $type)) |
| 34 | 38 | ? $type : null; |
| 35 | 39 | $type = file::getMimeType($file, $magic); |
| 36 | - if (!$type) $type = null; |
|
| 40 | + if (!$type) { |
|
| 41 | + $type = null; |
|
| 42 | + } |
|
| 37 | 43 | } |
| 38 | 44 | |
| 39 | 45 | self::content(@file_get_contents($file), $mtime, $type, $expire, $headers, false); |
@@ -47,10 +53,17 @@ discard block |
||
| 47 | 53 | * @param array $headers |
| 48 | 54 | * @param bool $checkMTime */ |
| 49 | 55 | |
| 50 | - static function content($content, $mtime, $type=null, $expire=null, array $headers=null, $checkMTime=true) { |
|
| 51 | - if ($checkMTime) self::checkMTime($mtime); |
|
| 52 | - if ($type === null) $type = self::DEFAULT_TYPE; |
|
| 53 | - if ($expire === null) $expire = self::DEFAULT_EXPIRE; |
|
| 56 | + static function content($content, $mtime, $type=null, $expire=null, array $headers=null, $checkMTime=true) |
|
| 57 | + { |
|
| 58 | + if ($checkMTime) { |
|
| 59 | + self::checkMTime($mtime); |
|
| 60 | + } |
|
| 61 | + if ($type === null) { |
|
| 62 | + $type = self::DEFAULT_TYPE; |
|
| 63 | + } |
|
| 64 | + if ($expire === null) { |
|
| 65 | + $expire = self::DEFAULT_EXPIRE; |
|
| 66 | + } |
|
| 54 | 67 | $size = strlen($content); |
| 55 | 68 | $expires = gmdate("D, d M Y H:i:s", time() + $expire) . " GMT"; |
| 56 | 69 | header("Content-Type: $type"); |
@@ -58,7 +71,9 @@ discard block |
||
| 58 | 71 | header("Cache-Control: max-age=$expire"); |
| 59 | 72 | header("Pragma: !invalid"); |
| 60 | 73 | header("Content-Length: $size"); |
| 61 | - if ($headers !== null) foreach ($headers as $header) header($header); |
|
| 74 | + if ($headers !== null) { |
|
| 75 | + foreach ($headers as $header) header($header); |
|
| 76 | + } |
|
| 62 | 77 | echo $content; |
| 63 | 78 | } |
| 64 | 79 | |
@@ -68,7 +83,8 @@ discard block |
||
| 68 | 83 | * the PHP to be configured as Apache module. |
| 69 | 84 | * @param integer $mtime */ |
| 70 | 85 | |
| 71 | - static function checkMTime($mtime, $sendHeaders=null) { |
|
| 86 | + static function checkMTime($mtime, $sendHeaders=null) |
|
| 87 | + { |
|
| 72 | 88 | header("Last-Modified: " . gmdate("D, d M Y H:i:s", $mtime) . " GMT"); |
| 73 | 89 | |
| 74 | 90 | $headers = function_exists("getallheaders") |
@@ -82,11 +98,12 @@ discard block |
||
| 82 | 98 | $client_mtime = @strtotime($client_mtime[0]); |
| 83 | 99 | if ($client_mtime >= $mtime) { |
| 84 | 100 | header('HTTP/1.1 304 Not Modified'); |
| 85 | - if (is_array($sendHeaders) && count($sendHeaders)) |
|
| 86 | - foreach ($sendHeaders as $header) |
|
| 101 | + if (is_array($sendHeaders) && count($sendHeaders)) { |
|
| 102 | + foreach ($sendHeaders as $header) |
|
| 87 | 103 | header($header); |
| 88 | - elseif ($sendHeaders !== null) |
|
| 89 | - header($sendHeaders); |
|
| 104 | + } elseif ($sendHeaders !== null) { |
|
| 105 | + header($sendHeaders); |
|
| 106 | + } |
|
| 90 | 107 | |
| 91 | 108 | |
| 92 | 109 | die; |