Completed
Pull Request — develop (#740)
by Maxim
06:37
created
manager/media/browser/mcpuk/core/uploader.php 1 patch
Spacing   +41 added lines, -42 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
   *      @link http://kcfinder.sunhater.com
13 13
   */
14 14
 
15
-class uploader {
15
+class uploader{
16 16
 
17 17
 /** Release version */
18 18
     const VERSION = "2.54";
@@ -72,8 +72,8 @@  discard block
 block discarded – undo
72 72
 
73 73
 /** Next three properties are got from the current language file
74 74
   * @var string */
75
-    protected $dateTimeFull;   // Currently not used
76
-    protected $dateTimeMid;    // Currently not used
75
+    protected $dateTimeFull; // Currently not used
76
+    protected $dateTimeMid; // Currently not used
77 77
     protected $dateTimeSmall;
78 78
 
79 79
 /** Contain Specified language labels
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 /** Magic method which allows read-only access to protected or private class properties
105 105
   * @param string $property
106 106
   * @return mixed */
107
-    public function __get($property) {
107
+    public function __get($property){
108 108
         return property_exists($this, $property) ? $this->$property : null;
109 109
     }
110 110
 
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
      * uploader constructor.
113 113
      * @param DocumentParser $modx
114 114
      */
115
-    public function __construct(DocumentParser $modx) {
115
+    public function __construct(DocumentParser $modx){
116 116
 
117 117
         //MODX
118 118
         try {
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 
196 196
         // COOKIES INIT
197 197
         $ip = '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)';
198
-        $ip = '/^' . implode('\.', array($ip, $ip, $ip, $ip)) . '$/';
198
+        $ip = '/^'.implode('\.', array($ip, $ip, $ip, $ip)).'$/';
199 199
         if (preg_match($ip, $_SERVER['HTTP_HOST']) ||
200 200
             preg_match('/^[^\.]+$/', $_SERVER['HTTP_HOST'])
201 201
         )
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
         ) {
214 214
             list($unused, $protocol, $domain, $unused, $port, $path) = $patt;
215 215
             $path = path::normalize($path);
216
-            $this->config['uploadURL'] = "$protocol://$domain" . (strlen($port) ? ":$port" : "") . "/$path";
216
+            $this->config['uploadURL'] = "$protocol://$domain".(strlen($port) ? ":$port" : "")."/$path";
217 217
             $this->config['uploadDir'] = strlen($this->config['uploadDir'])
218 218
                 ? path::normalize($this->config['uploadDir'])
219 219
                 : path::url2fullPath("/$path");
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
         foreach ($this->langInputNames as $key)
257 257
             if (isset($this->get[$key]) &&
258 258
                 preg_match('/^[a-z][a-z\._\-]*$/i', $this->get[$key]) &&
259
-                file_exists("lang/" . strtolower($this->get[$key]) . ".php")
259
+                file_exists("lang/".strtolower($this->get[$key]).".php")
260 260
             ) {
261 261
                 $this->lang = $this->get[$key];
262 262
                 break;
@@ -290,12 +290,12 @@  discard block
 block discarded – undo
290 290
     /**
291 291
      * @return array|bool|int|null|string|void
292 292
      */
293
-    protected function getTransaliasSettings() {
293
+    protected function getTransaliasSettings(){
294 294
 		$modx = evolutionCMS();
295 295
 
296 296
 		// Cleaning uploaded filename?
297 297
 		$setting = $modx->getDatabase()->select('count(*)', $modx->getDatabase()->getFullTableName('system_settings'), 'setting_name="clean_uploaded_filename" AND setting_value=1');
298
-		if ($modx->getDatabase()->getValue($setting)>0) {
298
+		if ($modx->getDatabase()->getValue($setting) > 0) {
299 299
 			// Transalias plugin active?
300 300
 			$res = $modx->getDatabase()->select('properties', $modx->getDatabase()->getFullTableName('site_plugins'), 'name="TransAlias" AND disabled=0');
301 301
 			if ($properties = $modx->getDatabase()->getValue($res)) {
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
      * @param $filename
315 315
      * @return mixed|string
316 316
      */
317
-    protected function normalizeFilename($filename) {
317
+    protected function normalizeFilename($filename){
318 318
 		if ($this->getTransaliasSettings()) {
319 319
         		$format = strrchr($filename, ".");
320 320
         		$filename = str_replace($format, "", $filename);
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
      * @param $dirname
328 328
      * @return string
329 329
      */
330
-    protected function normalizeDirname($dirname) {
330
+    protected function normalizeDirname($dirname){
331 331
         return $this->modx->stripAlias($dirname);
332 332
     }
333 333
 
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
      * @param array|null $aFile
336 336
      * @return bool|mixed
337 337
      */
338
-    protected function checkUploadedFile(array $aFile=null) {
338
+    protected function checkUploadedFile(array $aFile = null){
339 339
         $config = &$this->config;
340 340
         $file = ($aFile === null) ? $this->file : $aFile;
341 341
 
@@ -361,8 +361,7 @@  discard block
 block discarded – undo
361 361
                 ($file['error'] == UPLOAD_ERR_NO_TMP_DIR) ?
362 362
                     $this->label("Missing a temporary folder.") : (
363 363
                 ($file['error'] == UPLOAD_ERR_CANT_WRITE) ?
364
-                    $this->label("Failed to write file.") :
365
-                    $this->label("Unknown error.")
364
+                    $this->label("Failed to write file.") : $this->label("Unknown error.")
366 365
             )))));
367 366
 
368 367
         // HIDDEN FILENAMES CHECK
@@ -397,7 +396,7 @@  discard block
 block discarded – undo
397 396
 
398 397
 
399 398
 	// CHECK FOR MODX MAX FILE SIZE
400
-	$actualfilesize=filesize($file['tmp_name']);
399
+	$actualfilesize = filesize($file['tmp_name']);
401 400
 	if (isset($this->config['maxfilesize']) && $actualfilesize > $this->config['maxfilesize'])
402 401
 	    return $this->label("File is too big: ".$actualfilesize." Bytes. (max ".$this->config['maxfilesize']." Bytes)");
403 402
 
@@ -410,7 +409,7 @@  discard block
 block discarded – undo
410 409
      * @param bool $existing
411 410
      * @return bool|string
412 411
      */
413
-    protected function checkInputDir($dir, $inclType=true, $existing=true) {
412
+    protected function checkInputDir($dir, $inclType = true, $existing = true){
414 413
         $dir = path::normalize($dir);
415 414
         if (substr($dir, 0, 1) == "/")
416 415
             $dir = substr($dir, 1);
@@ -441,7 +440,7 @@  discard block
 block discarded – undo
441 440
      * @param $type
442 441
      * @return bool
443 442
      */
444
-    protected function validateExtension($ext, $type) {
443
+    protected function validateExtension($ext, $type){
445 444
         $ext = trim(strtolower($ext));
446 445
         if (!isset($this->types[$type]))
447 446
             return false;
@@ -470,7 +469,7 @@  discard block
 block discarded – undo
470 469
      * @param $path
471 470
      * @return mixed
472 471
      */
473
-    protected function getTypeFromPath($path) {
472
+    protected function getTypeFromPath($path){
474 473
         return preg_match('/^([^\/]*)\/.*$/', $path, $patt)
475 474
             ? $patt[1] : $path;
476 475
     }
@@ -479,7 +478,7 @@  discard block
 block discarded – undo
479 478
      * @param $path
480 479
      * @return string
481 480
      */
482
-    protected function removeTypeFromPath($path) {
481
+    protected function removeTypeFromPath($path){
483 482
         return preg_match('/^[^\/]*\/(.*)$/', $path, $patt)
484 483
             ? $patt[1] : "";
485 484
     }
@@ -489,7 +488,7 @@  discard block
 block discarded – undo
489 488
      * @param null $file
490 489
      * @return bool
491 490
      */
492
-    protected function imageResize($image, $file=null) {
491
+    protected function imageResize($image, $file = null){
493 492
 
494 493
         if (!($image instanceof image)) {
495 494
             $img = image::factory($this->imageDriver, $image);
@@ -577,19 +576,19 @@  discard block
 block discarded – undo
577 576
             $img->watermark($this->config['watermark']['file'], $left, $top);
578 577
 		}
579 578
 
580
-        $options = array( 'file' => $file );
579
+        $options = array('file' => $file);
581 580
 
582
-        $type = exif_imagetype( $file );
581
+        $type = exif_imagetype($file);
583 582
 
584
-        switch ( $type ) {
583
+        switch ($type) {
585 584
             case IMAGETYPE_GIF:
586
-                return $img->output( 'gif', $options );
585
+                return $img->output('gif', $options);
587 586
 
588 587
             case IMAGETYPE_PNG:
589
-                return $img->output( 'png', $options );
588
+                return $img->output('png', $options);
590 589
 
591 590
             default:
592
-                return $img->output( 'jpeg', array_merge( $options, array( 'quality' => $this->config['jpegQuality'] ) ) );
591
+                return $img->output('jpeg', array_merge($options, array('quality' => $this->config['jpegQuality'])));
593 592
         }
594 593
 
595 594
     }
@@ -599,7 +598,7 @@  discard block
 block discarded – undo
599 598
      * @param bool $overwrite
600 599
      * @return bool
601 600
      */
602
-    protected function makeThumb($file, $overwrite=true) {
601
+    protected function makeThumb($file, $overwrite = true){
603 602
         $img = image::factory($this->imageDriver, $file);
604 603
 
605 604
         // Drop files which are not images
@@ -607,7 +606,7 @@  discard block
 block discarded – undo
607 606
             return true;
608 607
 
609 608
         $thumb = substr($file, strlen($this->config['uploadDir']));
610
-        $thumb = $this->config['uploadDir'] . "/" . $this->config['thumbsDir'] . "/" . $thumb;
609
+        $thumb = $this->config['uploadDir']."/".$this->config['thumbsDir']."/".$thumb;
611 610
         $thumb = path::normalize($thumb);
612 611
         $thumbDir = dirname($thumb);
613 612
         if (!is_dir($thumbDir) && !@mkdir($thumbDir, $this->config['dirPerms'], true))
@@ -630,15 +629,15 @@  discard block
 block discarded – undo
630 629
         if (!$img->resizeFit($this->config['thumbWidth'], $this->config['thumbHeight']))
631 630
             return false;
632 631
 
633
-        if ( $this->imageDriver == 'gd' ) {
634
-            $width  = imagesx( $img->image );
635
-            $height = imagesy( $img->image );
636
-            $back   = image::factory( $this->imageDriver, array( $width, $height ) );
637
-            $tile   = image::factory( $this->imageDriver, __DIR__ . '/../themes/' . $this->config['theme'] . '/img/bg_transparent.png' );
632
+        if ($this->imageDriver == 'gd') {
633
+            $width  = imagesx($img->image);
634
+            $height = imagesy($img->image);
635
+            $back   = image::factory($this->imageDriver, array($width, $height));
636
+            $tile   = image::factory($this->imageDriver, __DIR__.'/../themes/'.$this->config['theme'].'/img/bg_transparent.png');
638 637
 
639
-            imagesettile( $back->image, $tile->image );
640
-            imagefilledrectangle( $back->image, 0, 0, $width, $height, IMG_COLOR_TILED );
641
-            imagecopy( $back->image, $img->image, 0, 0, 0, 0, $width, $height );
638
+            imagesettile($back->image, $tile->image);
639
+            imagefilledrectangle($back->image, 0, 0, $width, $height, IMG_COLOR_TILED);
640
+            imagecopy($back->image, $img->image, 0, 0, 0, 0, $width, $height);
642 641
 
643 642
             $img = $back;
644 643
         }
@@ -653,7 +652,7 @@  discard block
 block discarded – undo
653 652
     /**
654 653
      * @param $langCode
655 654
      */
656
-    protected function localize($langCode) {
655
+    protected function localize($langCode){
657 656
         require "lang/{$langCode}.php";
658 657
         setlocale(LC_ALL, $lang['_locale']);
659 658
         $this->charset = $lang['_charset'];
@@ -673,7 +672,7 @@  discard block
 block discarded – undo
673 672
      * @param array|null $data
674 673
      * @return mixed
675 674
      */
676
-    protected function label($string, array $data=null) {
675
+    protected function label($string, array $data = null){
677 676
         $return = isset($this->labels[$string]) ? $this->labels[$string] : $string;
678 677
         if (is_array($data))
679 678
             foreach ($data as $key => $val)
@@ -685,7 +684,7 @@  discard block
 block discarded – undo
685 684
      * @param $message
686 685
      * @param array|null $data
687 686
      */
688
-    protected function backMsg($message, array $data=null) {
687
+    protected function backMsg($message, array $data = null){
689 688
         $message = $this->label($message, $data);
690 689
         if (isset($this->file['tmp_name']) && file_exists($this->file['tmp_name']))
691 690
             @unlink($this->file['tmp_name']);
@@ -697,7 +696,7 @@  discard block
 block discarded – undo
697 696
      * @param $url
698 697
      * @param string $message
699 698
      */
700
-    protected function callBack($url, $message="") {
699
+    protected function callBack($url, $message = ""){
701 700
         $message = text::jsValue($message);
702 701
         $CKfuncNum = isset($this->opener['CKEditor']['funcNum'])
703 702
             ? $this->opener['CKEditor']['funcNum'] : 0;
@@ -741,7 +740,7 @@  discard block
 block discarded – undo
741 740
     /**
742 741
      * @return string
743 742
      */
744
-    protected function get_htaccess() {
743
+    protected function get_htaccess(){
745 744
         return "<IfModule mod_php4.c>
746 745
   php_value engine off
747 746
 </IfModule>
Please login to merge, or discard this patch.