Completed
Push — develop ( 80f130...524d8a )
by Maxim
08:25
created
manager/media/browser/mcpuk/config.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -72,8 +72,8 @@
 block discarded – undo
72 72
     'maxImageWidth'  => $modx->config['maxImageWidth'],
73 73
     'maxImageHeight' => $modx->config['maxImageHeight'],
74 74
     'clientResize'   => $modx->config['clientResize'] && $modx->config['maxImageWidth'] && $modx->config['maxImageHeight'] ? array('maxWidth'  => $modx->config['maxImageWidth'],
75
-                                                                                                                                   'maxHeight' => $modx->config['maxImageHeight'],
76
-                                                                                                                                   'quality'   => $modx->config['jpegQuality'] / 100
75
+                                                                                                                                    'maxHeight' => $modx->config['maxImageHeight'],
76
+                                                                                                                                    'quality'   => $modx->config['jpegQuality'] / 100
77 77
     ) : array(),
78 78
 
79 79
     'thumbWidth'  => $modx->config['thumbWidth'],
Please login to merge, or discard this patch.
manager/media/browser/mcpuk/core/autoload.php 2 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -1,24 +1,24 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 /** This file is part of KCFinder project
4
-  *
5
-  *      @desc This file is included first, before each other
6
-  *   @package KCFinder
7
-  *   @version 2.54
8
-  *    @author Pavel Tzonkov <[email protected]>
9
-  * @copyright 2010-2014 KCFinder Project
10
-  *   @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2
11
-  *   @license http://www.opensource.org/licenses/lgpl-2.1.php LGPLv2
12
-  *      @link http://kcfinder.sunhater.com
13
-  *
14
-  * This file is the place you can put any code (at the end of the file),
15
-  * which will be executed before any other. Suitable for:
16
-  *     1. Set PHP ini settings using ini_set()
17
-  *     2. Custom session save handler with session_set_save_handler()
18
-  *     3. Any custom integration code. If you use any global variables
19
-  *        here, they can be accessed in config.php via $GLOBALS array.
20
-  *        It's recommended to use constants instead.
21
-  */
4
+ *
5
+ *      @desc This file is included first, before each other
6
+ *   @package KCFinder
7
+ *   @version 2.54
8
+ *    @author Pavel Tzonkov <[email protected]>
9
+ * @copyright 2010-2014 KCFinder Project
10
+ *   @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2
11
+ *   @license http://www.opensource.org/licenses/lgpl-2.1.php LGPLv2
12
+ *      @link http://kcfinder.sunhater.com
13
+ *
14
+ * This file is the place you can put any code (at the end of the file),
15
+ * which will be executed before any other. Suitable for:
16
+ *     1. Set PHP ini settings using ini_set()
17
+ *     2. Custom session save handler with session_set_save_handler()
18
+ *     3. Any custom integration code. If you use any global variables
19
+ *        here, they can be accessed in config.php via $GLOBALS array.
20
+ *        It's recommended to use constants instead.
21
+ */
22 22
 define('IN_MANAGER_MODE', true);
23 23
 define('MODX_API_MODE', true);
24 24
 include_once(__DIR__."/../../../../../index.php");
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -38,7 +38,8 @@
 block discarded – undo
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(
Please login to merge, or discard this patch.
manager/media/browser/mcpuk/core/uploader.php 2 patches
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 /** This file is part of KCFinder project
4
-  *
5
-  *      @desc Uploader class
6
-  *   @package KCFinder
7
-  *   @version 2.54
8
-  *    @author Pavel Tzonkov <[email protected]>
9
-  * @copyright 2010-2014 KCFinder Project
10
-  *   @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2
11
-  *   @license http://www.opensource.org/licenses/lgpl-2.1.php LGPLv2
12
-  *      @link http://kcfinder.sunhater.com
13
-  */
4
+ *
5
+ *      @desc Uploader class
6
+ *   @package KCFinder
7
+ *   @version 2.54
8
+ *    @author Pavel Tzonkov <[email protected]>
9
+ * @copyright 2010-2014 KCFinder Project
10
+ *   @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2
11
+ *   @license http://www.opensource.org/licenses/lgpl-2.1.php LGPLv2
12
+ *      @link http://kcfinder.sunhater.com
13
+ */
14 14
 
15 15
 class uploader {
16 16
 
@@ -18,92 +18,92 @@  discard block
 block discarded – undo
18 18
     const VERSION = "2.54";
19 19
 
20 20
 /** Config session-overrided settings
21
-  * @var array */
21
+ * @var array */
22 22
     protected $config = array();
23 23
 
24 24
 /** Default image driver
25
-  * @var string */
25
+ * @var string */
26 26
     protected $imageDriver = "gd";
27 27
 
28 28
 /** Opener applocation properties
29
-  *   $opener['name']                 Got from $_GET['opener'];
30
-  *   $opener['CKEditor']['funcNum']  CKEditor function number (got from $_GET)
31
-  *   $opener['TinyMCE']              Boolean
32
-  * @var array */
29
+ *   $opener['name']                 Got from $_GET['opener'];
30
+ *   $opener['CKEditor']['funcNum']  CKEditor function number (got from $_GET)
31
+ *   $opener['TinyMCE']              Boolean
32
+ * @var array */
33 33
     protected $opener = array();
34 34
 
35 35
 /** Got from $_GET['type'] or first one $config['types'] array key, if inexistant
36
-  * @var string */
36
+ * @var string */
37 37
     protected $type;
38 38
 
39 39
 /** Helper property. Local filesystem path to the Type Directory
40
-  * Equivalent: $config['uploadDir'] . "/" . $type
41
-  * @var string */
40
+ * Equivalent: $config['uploadDir'] . "/" . $type
41
+ * @var string */
42 42
     protected $typeDir;
43 43
 
44 44
 /** Helper property. Web URL to the Type Directory
45
-  * Equivalent: $config['uploadURL'] . "/" . $type
46
-  * @var string */
45
+ * Equivalent: $config['uploadURL'] . "/" . $type
46
+ * @var string */
47 47
     protected $typeURL;
48 48
 
49 49
 /** Linked to $config['types']
50
-  * @var array */
50
+ * @var array */
51 51
     protected $types = array();
52 52
 
53 53
 /** Settings which can override default settings if exists as keys in $config['types'][$type] array
54
-  * @var array */
54
+ * @var array */
55 55
     protected $typeSettings = array('disabled', 'theme', 'dirPerms', 'filePerms', 'denyZipDownload', 'maxImageWidth', 'maxImageHeight', 'thumbWidth', 'thumbHeight', 'jpegQuality', 'access', 'filenameChangeChars', 'dirnameChangeChars', 'denyExtensionRename', 'deniedExts', 'watermark');
56 56
 
57 57
 /** Got from language file
58
-  * @var string */
58
+ * @var string */
59 59
     protected $charset;
60 60
 
61 61
 /** The language got from $_GET['lng'] or $_GET['lang'] or... Please see next property
62
-  * @var string */
62
+ * @var string */
63 63
     protected $lang = 'en';
64 64
 
65 65
 /** Possible language $_GET keys
66
-  * @var array */
66
+ * @var array */
67 67
     protected $langInputNames = array('lang', 'langCode', 'lng', 'language', 'lang_code');
68 68
 
69 69
 /** Uploaded file(s) info. Linked to first $_FILES element
70
-  * @var array */
70
+ * @var array */
71 71
     protected $file;
72 72
 
73 73
 /** Next three properties are got from the current language file
74
-  * @var string */
74
+ * @var string */
75 75
     protected $dateTimeFull;   // Currently not used
76 76
     protected $dateTimeMid;    // Currently not used
77 77
     protected $dateTimeSmall;
78 78
 
79 79
 /** Contain Specified language labels
80
-  * @var array */
80
+ * @var array */
81 81
     protected $labels = array();
82 82
 
83 83
 /** Contain unprocessed $_GET array. Please use this instead of $_GET
84
-  * @var array */
84
+ * @var array */
85 85
     protected $get;
86 86
 
87 87
 /** Contain unprocessed $_POST array. Please use this instead of $_POST
88
-  * @var array */
88
+ * @var array */
89 89
     protected $post;
90 90
 
91 91
 /** Contain unprocessed $_COOKIE array. Please use this instead of $_COOKIE
92
-  * @var array */
92
+ * @var array */
93 93
     protected $cookie;
94 94
 
95 95
 /** Session array. Please use this property instead of $_SESSION
96
-  * @var array */
96
+ * @var array */
97 97
     protected $session;
98 98
 
99 99
 /** CMS integration attribute (got from $_GET['cms'])
100
-  * @var string */
100
+ * @var string */
101 101
     protected $cms = "";
102 102
 
103 103
     protected $modx = null;
104 104
 /** Magic method which allows read-only access to protected or private class properties
105
-  * @param string $property
106
-  * @return mixed */
105
+     * @param string $property
106
+     * @return mixed */
107 107
     public function __get($property) {
108 108
         return property_exists($this, $property) ? $this->$property : null;
109 109
     }
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
         )
137 137
             $this->cms = $this->get['cms'];
138 138
 
139
-		// LINKING UPLOADED FILE
139
+        // LINKING UPLOADED FILE
140 140
         if (count($_FILES))
141 141
             $this->file = &$_FILES[key($_FILES)];
142 142
 
@@ -217,8 +217,8 @@  discard block
 block discarded – undo
217 217
             $this->config['uploadDir'] = strlen($this->config['uploadDir'])
218 218
                 ? path::normalize($this->config['uploadDir'])
219 219
                 : path::url2fullPath("/$path");
220
-         $this->typeDir = "{$this->config['uploadDir']}/{$this->type}";
221
-         $this->typeURL = "{$this->config['siteURL']}/{$this->config['uploadURL']}/{$this->type}";
220
+            $this->typeDir = "{$this->config['uploadDir']}/{$this->type}";
221
+            $this->typeURL = "{$this->config['siteURL']}/{$this->config['uploadURL']}/{$this->type}";
222 222
 
223 223
         // SITE ROOT
224 224
         } elseif ($this->config['uploadURL'] == "/") {
@@ -291,23 +291,23 @@  discard block
 block discarded – undo
291 291
      * @return array|bool|int|null|string|void
292 292
      */
293 293
     protected function getTransaliasSettings() {
294
-		$modx = evolutionCMS();
295
-
296
-		// Cleaning uploaded filename?
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) {
299
-			// Transalias plugin active?
300
-			$res = $modx->getDatabase()->select('properties', $modx->getDatabase()->getFullTableName('site_plugins'), 'name="TransAlias" AND disabled=0');
301
-			if ($properties = $modx->getDatabase()->getValue($res)) {
302
-				$properties = $modx->parseProperties($properties, 'TransAlias', 'plugin');
303
-			} else {
304
-				$properties = NULL;
305
-			}
306
-		} else {
307
-			$properties = NULL;
308
-		}
309
-		return $properties;
310
-	}
294
+        $modx = evolutionCMS();
295
+
296
+        // Cleaning uploaded filename?
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) {
299
+            // Transalias plugin active?
300
+            $res = $modx->getDatabase()->select('properties', $modx->getDatabase()->getFullTableName('site_plugins'), 'name="TransAlias" AND disabled=0');
301
+            if ($properties = $modx->getDatabase()->getValue($res)) {
302
+                $properties = $modx->parseProperties($properties, 'TransAlias', 'plugin');
303
+            } else {
304
+                $properties = NULL;
305
+            }
306
+        } else {
307
+            $properties = NULL;
308
+        }
309
+        return $properties;
310
+    }
311 311
 
312 312
 
313 313
     /**
@@ -315,13 +315,13 @@  discard block
 block discarded – undo
315 315
      * @return mixed|string
316 316
      */
317 317
     protected function normalizeFilename($filename) {
318
-		if ($this->getTransaliasSettings()) {
319
-        		$format = strrchr($filename, ".");
320
-        		$filename = str_replace($format, "", $filename);
321
-            		$filename = $this->modx->stripAlias($filename).$format;
322
-        	}
323
-        	return $filename;
324
-	}
318
+        if ($this->getTransaliasSettings()) {
319
+                $format = strrchr($filename, ".");
320
+                $filename = str_replace($format, "", $filename);
321
+                    $filename = $this->modx->stripAlias($filename).$format;
322
+            }
323
+            return $filename;
324
+    }
325 325
 
326 326
     /**
327 327
      * @param $dirname
@@ -396,10 +396,10 @@  discard block
 block discarded – undo
396 396
             return $this->label("The image is too big and/or cannot be resized.");
397 397
 
398 398
 
399
-	// CHECK FOR MODX MAX FILE SIZE
400
-	$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)");
399
+    // CHECK FOR MODX MAX FILE SIZE
400
+    $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)");
403 403
 
404 404
         return true;
405 405
     }
@@ -575,7 +575,7 @@  discard block
 block discarded – undo
575 575
             $top = isset($this->config['watermark']['top'])
576 576
                 ? $this->config['watermark']['top'] : false;
577 577
             $img->watermark($this->config['watermark']['file'], $left, $top);
578
-		}
578
+        }
579 579
 
580 580
         $options = array( 'file' => $file );
581 581
 
Please login to merge, or discard this patch.
Braces   +193 added lines, -121 removed lines patch added patch discarded remove patch
@@ -12,7 +12,8 @@  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 18
 /** Release version */
18 19
     const VERSION = "2.54";
@@ -104,7 +105,8 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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>
Please login to merge, or discard this patch.
manager/media/browser/mcpuk/lib/class_image.php 2 patches
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -1,45 +1,45 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 /** This file is part of KCFinder project
4
-  *
5
-  *      @desc Abstract image driver class
6
-  *   @package KCFinder
7
-  *   @version 2.54
8
-  *    @author Pavel Tzonkov <[email protected]>
9
-  * @copyright 2010-2014 KCFinder Project
10
-  *   @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2
11
-  *   @license http://www.opensource.org/licenses/lgpl-2.1.php LGPLv2
12
-  *      @link http://kcfinder.sunhater.com
13
-  */
4
+ *
5
+ *      @desc Abstract image driver class
6
+ *   @package KCFinder
7
+ *   @version 2.54
8
+ *    @author Pavel Tzonkov <[email protected]>
9
+ * @copyright 2010-2014 KCFinder Project
10
+ *   @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2
11
+ *   @license http://www.opensource.org/licenses/lgpl-2.1.php LGPLv2
12
+ *      @link http://kcfinder.sunhater.com
13
+ */
14 14
 
15 15
 abstract class image {
16 16
     const DEFAULT_JPEG_QUALITY = 75;
17 17
 
18 18
 /** Image resource or object
19
-  * @var mixed */
19
+ * @var mixed */
20 20
     protected $image;
21 21
 
22 22
 /** Image width in pixels
23
-  * @var integer */
23
+ * @var integer */
24 24
     protected $width;
25 25
 
26 26
 /** Image height in pixels
27
-  * @var integer */
27
+ * @var integer */
28 28
     protected $height;
29 29
 
30 30
 /** Init error
31
-  * @var bool */
31
+ * @var bool */
32 32
     protected $initError = false;
33 33
 
34 34
 /** Driver specific options
35
-  * @var array */
35
+ * @var array */
36 36
     protected $options = array();
37 37
 
38 38
 
39 39
 /** Magic method which allows read-only access to all protected or private
40
-  * class properties
41
-  * @param string $property
42
-  * @return mixed */
40
+ * class properties
41
+ * @param string $property
42
+ * @return mixed */
43 43
 
44 44
     final public function __get($property) {
45 45
         return property_exists($this, $property) ? $this->$property : null;
@@ -47,15 +47,15 @@  discard block
 block discarded – undo
47 47
 
48 48
 
49 49
 /** Constructor. Parameter $image should be:
50
-  *   1. An instance of image driver class (copy instance).
51
-  *   2. An image represented by the type of the $image property
52
-  *      (resource or object).
53
-  *   3. An array with two elements. First - width, second - height.
54
-  *      Creates a blank image.
55
-  *   4. A filename string. Get image form file.
56
-  * Second parameter is used by pass some specific image driver options
57
-  * @param mixed $image
58
-  * @param array $options */
50
+ *   1. An instance of image driver class (copy instance).
51
+ *   2. An image represented by the type of the $image property
52
+ *      (resource or object).
53
+ *   3. An array with two elements. First - width, second - height.
54
+ *      Creates a blank image.
55
+ *   4. A filename string. Get image form file.
56
+ * Second parameter is used by pass some specific image driver options
57
+ * @param mixed $image
58
+ * @param array $options */
59 59
 
60 60
     public function __construct($image, array $options=array()) {
61 61
         $this->image = $this->width = $this->height = null;
@@ -70,10 +70,10 @@  discard block
 block discarded – undo
70 70
 
71 71
 
72 72
 /** Factory pattern to load selected driver. $image and $options are passed
73
-  * to the constructor of the image driver
74
-  * @param string $driver
75
-  * @param mixed $image
76
-  * @return object */
73
+ * to the constructor of the image driver
74
+ * @param string $driver
75
+ * @param mixed $image
76
+ * @return object */
77 77
 
78 78
     final static function factory($driver, $image, array $options=array()) {
79 79
         $class = "image_$driver";
@@ -82,9 +82,9 @@  discard block
 block discarded – undo
82 82
 
83 83
 
84 84
 /** Checks if the drivers in the array parameter could be used. Returns first
85
-  * found one
86
-  * @param array $drivers
87
-  * @return string */
85
+ * found one
86
+ * @param array $drivers
87
+ * @return string */
88 88
 
89 89
     final static function getDriver(array $drivers=array('gd')) {
90 90
         foreach ($drivers as $driver) {
@@ -101,9 +101,9 @@  discard block
 block discarded – undo
101 101
 
102 102
 
103 103
 /** Returns an array. Element 0 - image resource. Element 1 - width. Element 2 - height.
104
-  * Returns FALSE on failure.
105
-  * @param mixed $image
106
-  * @return array */
104
+ * Returns FALSE on failure.
105
+ * @param mixed $image
106
+ * @return array */
107 107
 
108 108
     final protected function buildImage($image) {
109 109
         $class = get_class($this);
@@ -126,8 +126,8 @@  discard block
 block discarded – undo
126 126
 
127 127
 
128 128
 /** Returns calculated proportional width from the given height
129
-  * @param integer $resizedHeight
130
-  * @return integer */
129
+ * @param integer $resizedHeight
130
+ * @return integer */
131 131
 
132 132
     final public function getPropWidth($resizedHeight) {
133 133
         $width = round(($this->width * $resizedHeight) / $this->height);
@@ -137,8 +137,8 @@  discard block
 block discarded – undo
137 137
 
138 138
 
139 139
 /** Returns calculated proportional height from the given width
140
-  * @param integer $resizedWidth
141
-  * @return integer */
140
+ * @param integer $resizedWidth
141
+ * @return integer */
142 142
 
143 143
     final public function getPropHeight($resizedWidth) {
144 144
         $height = round(($this->height * $resizedWidth) / $this->width);
@@ -148,45 +148,45 @@  discard block
 block discarded – undo
148 148
 
149 149
 
150 150
 /** Checks if PHP needs some extra extensions to use the image driver. This
151
-  * static method should be implemented into driver classes like abstract
152
-  * methods
153
-  * @return bool */
151
+ * static method should be implemented into driver classes like abstract
152
+ * methods
153
+ * @return bool */
154 154
     static function available() { return false; }
155 155
 
156 156
 /** Checks if file is an image. This static method should be implemented into
157
-  * driver classes like abstract methods
158
-  * @param string $file
159
-  * @return bool */
157
+ * driver classes like abstract methods
158
+ * @param string $file
159
+ * @return bool */
160 160
     static function checkImage($file) { return false; }
161 161
 
162 162
 /** Resize image. Should return TRUE on success or FALSE on failure
163
-  * @param integer $width
164
-  * @param integer $height
165
-  * @return bool */
163
+ * @param integer $width
164
+ * @param integer $height
165
+ * @return bool */
166 166
     abstract public function resize($width, $height);
167 167
 
168 168
 /** Resize image to fit in given resolution. Should returns TRUE on success
169
-  * or FALSE on failure. If $background is set, the image size will be
170
-  * $width x $height and the empty spaces (if any) will be filled with defined
171
-  * color. Background color examples: "#5f5", "#ff67ca", array(255, 255, 255)
172
-  * @param integer $width
173
-  * @param integer $height
174
-  * @param mixed $background
175
-  * @return bool */
169
+ * or FALSE on failure. If $background is set, the image size will be
170
+ * $width x $height and the empty spaces (if any) will be filled with defined
171
+ * color. Background color examples: "#5f5", "#ff67ca", array(255, 255, 255)
172
+ * @param integer $width
173
+ * @param integer $height
174
+ * @param mixed $background
175
+ * @return bool */
176 176
     abstract public function resizeFit($width, $height, $background=false);
177 177
 
178 178
 /** Resize and crop the image to fit in given resolution. Returns TRUE on
179
-  * success or FALSE on failure
180
-  * @param mixed $src
181
-  * @param integer $offset
182
-  * @return bool */
179
+ * success or FALSE on failure
180
+ * @param mixed $src
181
+ * @param integer $offset
182
+ * @return bool */
183 183
     abstract public function resizeCrop($width, $height, $offset=false);
184 184
 
185 185
 
186 186
 /** Rotate image
187
-  * @param integer $angle
188
-  * @param string $background
189
-  * @return bool */
187
+ * @param integer $angle
188
+ * @param string $background
189
+ * @return bool */
190 190
     abstract public function rotate($angle, $background="#000000");
191 191
 
192 192
     abstract public function flipHorizontal();
@@ -194,44 +194,44 @@  discard block
 block discarded – undo
194 194
     abstract public function flipVertical();
195 195
 
196 196
 /** Apply a PNG or GIF watermark to the image. $top and $left parameters sets
197
-  * the offset of the watermark in pixels. Boolean and NULL values are possible
198
-  * too. In default case (FALSE, FALSE) the watermark should be applyed to
199
-  * the bottom right corner. NULL values means center aligning. If the
200
-  * watermark is bigger than the image or it's partialy or fully outside the
201
-  * image, it shoudn't be applied
202
-  * @param string $file
203
-  * @param mixed $top
204
-  * @param mixed $left
205
-  * @return bool */
197
+ * the offset of the watermark in pixels. Boolean and NULL values are possible
198
+ * too. In default case (FALSE, FALSE) the watermark should be applyed to
199
+ * the bottom right corner. NULL values means center aligning. If the
200
+ * watermark is bigger than the image or it's partialy or fully outside the
201
+ * image, it shoudn't be applied
202
+ * @param string $file
203
+ * @param mixed $top
204
+ * @param mixed $left
205
+ * @return bool */
206 206
     abstract public function watermark($file, $left=false, $top=false);
207 207
 
208 208
 /** Should output the image. Second parameter is used to pass some options like
209
-  *   'file' - if is set, the output will be written to a file
210
-  *   'quality' - compression quality
211
-  * It's possible to use extra specific options required by image type ($type)
212
-  * @param string $type
213
-  * @param array $options
214
-  * @return bool */
209
+ *   'file' - if is set, the output will be written to a file
210
+ *   'quality' - compression quality
211
+ * It's possible to use extra specific options required by image type ($type)
212
+ * @param string $type
213
+ * @param array $options
214
+ * @return bool */
215 215
     abstract public function output($type='jpeg', array $options=array());
216 216
 
217 217
 /** This method should create a blank image with selected size. Should returns
218
-  * resource or object related to the created image, which will be passed to
219
-  * $image property
220
-  * @param integer $width
221
-  * @param integer $height
222
-  * @return mixed */
218
+ * resource or object related to the created image, which will be passed to
219
+ * $image property
220
+ * @param integer $width
221
+ * @param integer $height
222
+ * @return mixed */
223 223
     abstract protected function getBlankImage($width, $height);
224 224
 
225 225
 /** This method should create an image from source image. Only first parameter
226
-  * ($image) is input. Its type should be filename string or a type of the
227
-  * $image property. See the constructor reference for details. The
228
-  * parametters $width and $height are output only. Should returns resource or
229
-  * object related to the created image, which will be passed to $image
230
-  * property
231
-  * @param mixed $image
232
-  * @param integer $width
233
-  * @param integer $height
234
-  * @return mixed */
226
+ * ($image) is input. Its type should be filename string or a type of the
227
+ * $image property. See the constructor reference for details. The
228
+ * parametters $width and $height are output only. Should returns resource or
229
+ * object related to the created image, which will be passed to $image
230
+ * property
231
+ * @param mixed $image
232
+ * @param integer $width
233
+ * @param integer $height
234
+ * @return mixed */
235 235
     abstract protected function getImage($image, &$width, &$height);
236 236
 
237 237
 }
Please login to merge, or discard this patch.
Braces   +42 added lines, -21 removed lines patch added patch discarded remove patch
@@ -12,7 +12,8 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
         if ($image instanceof $class) {
111 121
             $width = $image->width;
@@ -117,8 +127,9 @@  discard block
 block discarded – undo
117 127
             $height = $image[1];
118 128
             $img = $this->getBlankImage($width, $height);
119 129
 
120
-        } else
121
-            $img = $this->getImage($image, $width, $height);
130
+        } else {
131
+                    $img = $this->getImage($image, $width, $height);
132
+        }
122 133
         return ($img !== false)
123 134
             ? array($img, $width, $height)
124 135
             : false;
@@ -129,9 +140,12 @@  discard block
 block discarded – undo
129 140
   * @param integer $resizedHeight
130 141
   * @return integer */
131 142
 
132
-    final public function getPropWidth($resizedHeight) {
143
+    final public function getPropWidth($resizedHeight)
144
+    {
133 145
         $width = round(($this->width * $resizedHeight) / $this->height);
134
-        if (!$width) $width = 1;
146
+        if (!$width) {
147
+            $width = 1;
148
+        }
135 149
         return $width;
136 150
     }
137 151
 
@@ -140,9 +154,12 @@  discard block
 block discarded – undo
140 154
   * @param integer $resizedWidth
141 155
   * @return integer */
142 156
 
143
-    final public function getPropHeight($resizedWidth) {
157
+    final public function getPropHeight($resizedWidth)
158
+    {
144 159
         $height = round(($this->height * $resizedWidth) / $this->width);
145
-        if (!$height) $height = 1;
160
+        if (!$height) {
161
+            $height = 1;
162
+        }
146 163
         return $height;
147 164
     }
148 165
 
@@ -151,13 +168,17 @@  discard block
 block discarded – undo
151 168
   * static method should be implemented into driver classes like abstract
152 169
   * methods
153 170
   * @return bool */
154
-    static function available() { return false; }
171
+    static function available()
172
+    {
173
+return false; }
155 174
 
156 175
 /** Checks if file is an image. This static method should be implemented into
157 176
   * driver classes like abstract methods
158 177
   * @param string $file
159 178
   * @return bool */
160
-    static function checkImage($file) { return false; }
179
+    static function checkImage($file)
180
+    {
181
+return false; }
161 182
 
162 183
 /** Resize image. Should return TRUE on success or FALSE on failure
163 184
   * @param integer $width
Please login to merge, or discard this patch.