Completed
Branch master (f418e9)
by Anthony
04:38
created
libs/ckfinder/core/connector/php/php4/Core/Registry.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
      * Set value
52 52
      *
53 53
      * @param string $key
54
-     * @param mixed $obj
54
+     * @param string $obj
55 55
      * @access public
56 56
      */
57 57
     function set($key, $obj)
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
      * Get value
64 64
      *
65 65
      * @param string $key
66
-     * @return mixed
66
+     * @return string
67 67
      * @access public
68 68
      */
69 69
     function get($key)
Please login to merge, or discard this patch.
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -27,49 +27,49 @@
 block discarded – undo
27 27
  */
28 28
 class CKFinder_Connector_Core_Registry
29 29
 {
30
-    /**
31
-     * Arrat that stores all values
32
-     *
33
-     * @var array
34
-     * @access private
35
-     */
36
-    var $_store = array();
30
+	/**
31
+	 * Arrat that stores all values
32
+	 *
33
+	 * @var array
34
+	 * @access private
35
+	 */
36
+	var $_store = array();
37 37
 
38
-    /**
39
-     * Chacke if value has been set
40
-     *
41
-     * @param string $key
42
-     * @return boolean
43
-     * @access private
44
-     */
45
-    function isValid($key)
46
-    {
47
-        return array_key_exists($key, $this->_store);
48
-    }
38
+	/**
39
+	 * Chacke if value has been set
40
+	 *
41
+	 * @param string $key
42
+	 * @return boolean
43
+	 * @access private
44
+	 */
45
+	function isValid($key)
46
+	{
47
+		return array_key_exists($key, $this->_store);
48
+	}
49 49
 
50
-    /**
51
-     * Set value
52
-     *
53
-     * @param string $key
54
-     * @param mixed $obj
55
-     * @access public
56
-     */
57
-    function set($key, $obj)
58
-    {
59
-        $this->_store[$key] = $obj;
60
-    }
50
+	/**
51
+	 * Set value
52
+	 *
53
+	 * @param string $key
54
+	 * @param mixed $obj
55
+	 * @access public
56
+	 */
57
+	function set($key, $obj)
58
+	{
59
+		$this->_store[$key] = $obj;
60
+	}
61 61
 
62
-    /**
63
-     * Get value
64
-     *
65
-     * @param string $key
66
-     * @return mixed
67
-     * @access public
68
-     */
69
-    function get($key)
70
-    {
71
-    	if ($this->isValid($key)) {
72
-    	    return $this->_store[$key];
73
-    	}
74
-    }
62
+	/**
63
+	 * Get value
64
+	 *
65
+	 * @param string $key
66
+	 * @return mixed
67
+	 * @access public
68
+	 */
69
+	function get($key)
70
+	{
71
+		if ($this->isValid($key)) {
72
+			return $this->_store[$key];
73
+		}
74
+	}
75 75
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@
 block discarded – undo
10 10
  * modifying or distribute this file or part of its contents. The contents of
11 11
  * this file is part of the Source Code of CKFinder.
12 12
  */
13
-if (!defined('IN_CKFINDER')) exit;
13
+if (!defined('IN_CKFINDER')) {
14
+	exit;
15
+}
14 16
 
15 17
 /**
16 18
  * @package CKFinder
Please login to merge, or discard this patch.
libs/ckfinder/core/connector/php/php4/Core/ResourceTypeConfig.php 4 patches
Doc Comments   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -221,7 +221,6 @@  discard block
 block discarded – undo
221 221
      * If allowed extensions are defined, return false if extension isn't on allowed list.
222 222
      *
223 223
      * @access public
224
-     * @param string $extension extension
225 224
      * @param boolean $renameIfRequired whether try to rename file or not
226 225
      * @return boolean
227 226
      */
@@ -314,8 +313,8 @@  discard block
 block discarded – undo
314 313
      * Check given path
315 314
      * Return true if path contains folder name that matches hidden folder names list
316 315
      *
317
-     * @param string $folderName
318 316
      * @access public
317
+     * @param string $path
319 318
      * @return boolean
320 319
      */
321 320
     function checkIsHiddenPath($path)
Please login to merge, or discard this patch.
Indentation   +321 added lines, -321 removed lines patch added patch discarded remove patch
@@ -27,325 +27,325 @@
 block discarded – undo
27 27
  */
28 28
 class CKFinder_Connector_Core_ResourceTypeConfig
29 29
 {
30
-    /**
31
-     * Resource name
32
-     *
33
-     * @var string
34
-     * @access private
35
-     */
36
-    var $_name = "";
37
-    /**
38
-     * Resource url
39
-     *
40
-     * @var string
41
-     * @access private
42
-     */
43
-    var $_url = "";
44
-    /**
45
-     * Directory path on a server
46
-     *
47
-     * @var string
48
-     * @access private
49
-     */
50
-    var $_directory = "";
51
-    /**
52
-     * Max size
53
-     *
54
-     * @var unknown_type
55
-     * @access private
56
-     */
57
-    var $_maxSize = 0;
58
-    /**
59
-     * Array with allowed extensions
60
-     *
61
-     * @var array[]string
62
-     * @access private
63
-     */
64
-    var $_allowedExtensions = array();
65
-    /**
66
-     * Array with denied extensions
67
-     *
68
-     * @var array[]string
69
-     * @access private
70
-     */
71
-    var $_deniedExtensions = array();
72
-    /**
73
-     * used for CKFinder_Connector_Core_Config object caching
74
-     *
75
-     * @var CKFinder_Connector_Core_Config
76
-     * @access private
77
-     */
78
-    var $_config;
79
-
80
-    /**
81
-     * Get ResourceType configuration
82
-     *
83
-     * @param string $resourceTypeNode
84
-     * @return array
85
-     *
86
-     */
87
-    function CKFinder_Connector_Core_ResourceTypeConfig($resourceTypeNode)
88
-    {
89
-        if (isset($resourceTypeNode["name"])) {
90
-            $this->_name = $resourceTypeNode["name"];
91
-        }
92
-
93
-        if (isset($resourceTypeNode["url"])) {
94
-            $this->_url = $resourceTypeNode["url"];
95
-        }
96
-
97
-        if (!strlen($this->_url)) {
98
-            $this->_url = "/";
99
-        }
100
-        else if(substr($this->_url,-1,1) != "/") {
101
-            $this->_url .= "/";
102
-        }
103
-
104
-        if (isset($resourceTypeNode["maxSize"])) {
105
-            $this->_maxSize = CKFinder_Connector_Utils_Misc::returnBytes((string)$resourceTypeNode["maxSize"]);
106
-        }
107
-
108
-        if (isset($resourceTypeNode["directory"])) {
109
-            $this->_directory = $resourceTypeNode["directory"];
110
-        }
111
-
112
-        if (!strlen($this->_directory)) {
113
-            $this->_directory = resolveUrl($this->_url);
114
-        }
115
-
116
-        if (isset($resourceTypeNode["allowedExtensions"])) {
117
-            if (is_array($resourceTypeNode["allowedExtensions"])) {
118
-                foreach ($resourceTypeNode["allowedExtensions"] as $e) {
119
-                    $this->_allowedExtensions[] = strtolower(trim((string)$e));
120
-                }
121
-            }
122
-            else {
123
-                $resourceTypeNode["allowedExtensions"] = trim((string)$resourceTypeNode["allowedExtensions"]);
124
-                if (strlen($resourceTypeNode["allowedExtensions"])) {
125
-                    $extensions = explode(",", $resourceTypeNode["allowedExtensions"]);
126
-                    foreach ($extensions as $e) {
127
-                        $this->_allowedExtensions[] = strtolower(trim($e));
128
-                    }
129
-                }
130
-            }
131
-        }
132
-
133
-        if (isset($resourceTypeNode["deniedExtensions"])) {
134
-            if (is_array($resourceTypeNode["deniedExtensions"])) {
135
-
136
-                foreach ($resourceTypeNode["deniedExtensions"] as $extension) {
137
-                    $this->_deniedExtensions[] = strtolower(trim((string)$e));
138
-                }
139
-            }
140
-            else {
141
-                $resourceTypeNode["deniedExtensions"] = trim((string)$resourceTypeNode["deniedExtensions"]);
142
-                if (strlen($resourceTypeNode["deniedExtensions"])) {
143
-                    $extensions = explode(",", $resourceTypeNode["deniedExtensions"]);
144
-                    foreach ($extensions as $e) {
145
-                        $this->_deniedExtensions[] = strtolower(trim($e));
146
-                    }
147
-                }
148
-            }
149
-        }
150
-    }
151
-
152
-    /**
153
-     * Get name
154
-     *
155
-     * @access public
156
-     * @return string
157
-     */
158
-    function getName()
159
-    {
160
-        return $this->_name;
161
-    }
162
-
163
-    /**
164
-     * Get url
165
-     *
166
-     * @access public
167
-     * @return string
168
-     */
169
-    function getUrl()
170
-    {
171
-        return $this->_url;
172
-    }
173
-
174
-    /**
175
-     * Get directory
176
-     *
177
-     * @access public
178
-     * @return string
179
-     */
180
-    function getDirectory()
181
-    {
182
-        return $this->_directory;
183
-    }
184
-
185
-    /**
186
-     * Get max size
187
-     *
188
-     * @access public
189
-     * @return int
190
-     */
191
-    function getMaxSize()
192
-    {
193
-        return $this->_maxSize;
194
-    }
195
-
196
-    /**
197
-     * Get allowed extensions
198
-     *
199
-     * @access public
200
-     * @return array[]string
201
-     */
202
-    function getAllowedExtensions()
203
-    {
204
-        return $this->_allowedExtensions;
205
-    }
206
-
207
-    /**
208
-     * Get denied extensions
209
-     *
210
-     * @access public
211
-     * @return array[]string
212
-     */
213
-    function getDeniedExtensions()
214
-    {
215
-        return $this->_deniedExtensions;
216
-    }
217
-
218
-    /**
219
-     * Check extension, return true if file name is valid.
220
-     * Return false if extension is on denied list.
221
-     * If allowed extensions are defined, return false if extension isn't on allowed list.
222
-     *
223
-     * @access public
224
-     * @param string $extension extension
225
-     * @param boolean $renameIfRequired whether try to rename file or not
226
-     * @return boolean
227
-     */
228
-    function checkExtension(&$fileName, $renameIfRequired = true)
229
-    {
230
-        if (strpos($fileName, '.') === false) {
231
-            return true;
232
-        }
233
-
234
-        if (is_null($this->_config)) {
235
-            $this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
236
-        }
237
-
238
-        $toCheck = array();
239
-
240
-        if ($this->_config->getCheckDoubleExtension()) {
241
-            $pieces = explode('.', $fileName);
242
-
243
-            // First, check the last extension (ex. in file.php.jpg, the "jpg").
244
-            if ( !$this->checkSingleExtension( $pieces[sizeof($pieces)-1] ) ) {
245
-                return false;
246
-            }
247
-
248
-            if ($renameIfRequired) {
249
-                // Check the other extensions, rebuilding the file name. If an extension is
250
-                // not allowed, replace the dot with an underscore.
251
-                $fileName = $pieces[0] ;
252
-                for ($i=1; $i<sizeof($pieces)-1; $i++) {
253
-                    $fileName .= $this->checkSingleExtension( $pieces[$i] ) ? '.' : '_' ;
254
-                    $fileName .= $pieces[$i];
255
-                }
256
-
257
-                // Add the last extension to the final name.
258
-                $fileName .= '.' . $pieces[sizeof($pieces)-1] ;
259
-            }
260
-        }
261
-        else {
262
-            // Check only the last extension (ex. in file.php.jpg, only "jpg").
263
-            return $this->checkSingleExtension( substr($fileName, strrpos($fileName,'.')+1) );
264
-        }
265
-
266
-        return true;
267
-    }
268
-
269
-    /**
270
-     * Check given folder name
271
-     * Return true if folder name matches hidden folder names list
272
-     *
273
-     * @param string $folderName
274
-     * @access public
275
-     * @return boolean
276
-     */
277
-    function checkIsHiddenFolder($folderName)
278
-    {
279
-        if (is_null($this->_config)) {
280
-            $this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
281
-        }
282
-
283
-        $regex = $this->_config->getHideFoldersRegex();
284
-        if ($regex) {
285
-            return preg_match($regex, $folderName);
286
-        }
287
-
288
-        return false;
289
-    }
290
-
291
-    /**
292
-     * Check given file name
293
-     * Return true if file name matches hidden file names list
294
-     *
295
-     * @param string $fileName
296
-     * @access public
297
-     * @return boolean
298
-     */
299
-    function checkIsHiddenFile($fileName)
300
-    {
301
-        if (is_null($this->_config)) {
302
-            $this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
303
-        }
304
-
305
-        $regex = $this->_config->getHideFilesRegex();
306
-        if ($regex) {
307
-            return preg_match($regex, $fileName);
308
-        }
309
-
310
-        return false;
311
-    }
312
-
313
-    /**
314
-     * Check given path
315
-     * Return true if path contains folder name that matches hidden folder names list
316
-     *
317
-     * @param string $folderName
318
-     * @access public
319
-     * @return boolean
320
-     */
321
-    function checkIsHiddenPath($path)
322
-    {
323
-        $_clientPathParts = explode("/", trim($path, "/"));
324
-        if ($_clientPathParts) {
325
-            foreach ($_clientPathParts as $_part) {
326
-                if ($this->checkIsHiddenFolder($_part)) {
327
-                    return true;
328
-                }
329
-            }
330
-        }
331
-
332
-        return false;
333
-    }
334
-
335
-    function checkSingleExtension($extension)
336
-    {
337
-        $extension = strtolower(ltrim($extension,'.'));
338
-
339
-        if (sizeof($this->_deniedExtensions)) {
340
-            if (in_array($extension, $this->_deniedExtensions)) {
341
-                return false;
342
-            }
343
-        }
344
-
345
-        if (sizeof($this->_allowedExtensions)) {
346
-            return in_array($extension, $this->_allowedExtensions);
347
-        }
348
-
349
-        return true;
350
-    }
30
+	/**
31
+	 * Resource name
32
+	 *
33
+	 * @var string
34
+	 * @access private
35
+	 */
36
+	var $_name = "";
37
+	/**
38
+	 * Resource url
39
+	 *
40
+	 * @var string
41
+	 * @access private
42
+	 */
43
+	var $_url = "";
44
+	/**
45
+	 * Directory path on a server
46
+	 *
47
+	 * @var string
48
+	 * @access private
49
+	 */
50
+	var $_directory = "";
51
+	/**
52
+	 * Max size
53
+	 *
54
+	 * @var unknown_type
55
+	 * @access private
56
+	 */
57
+	var $_maxSize = 0;
58
+	/**
59
+	 * Array with allowed extensions
60
+	 *
61
+	 * @var array[]string
62
+	 * @access private
63
+	 */
64
+	var $_allowedExtensions = array();
65
+	/**
66
+	 * Array with denied extensions
67
+	 *
68
+	 * @var array[]string
69
+	 * @access private
70
+	 */
71
+	var $_deniedExtensions = array();
72
+	/**
73
+	 * used for CKFinder_Connector_Core_Config object caching
74
+	 *
75
+	 * @var CKFinder_Connector_Core_Config
76
+	 * @access private
77
+	 */
78
+	var $_config;
79
+
80
+	/**
81
+	 * Get ResourceType configuration
82
+	 *
83
+	 * @param string $resourceTypeNode
84
+	 * @return array
85
+	 *
86
+	 */
87
+	function CKFinder_Connector_Core_ResourceTypeConfig($resourceTypeNode)
88
+	{
89
+		if (isset($resourceTypeNode["name"])) {
90
+			$this->_name = $resourceTypeNode["name"];
91
+		}
92
+
93
+		if (isset($resourceTypeNode["url"])) {
94
+			$this->_url = $resourceTypeNode["url"];
95
+		}
96
+
97
+		if (!strlen($this->_url)) {
98
+			$this->_url = "/";
99
+		}
100
+		else if(substr($this->_url,-1,1) != "/") {
101
+			$this->_url .= "/";
102
+		}
103
+
104
+		if (isset($resourceTypeNode["maxSize"])) {
105
+			$this->_maxSize = CKFinder_Connector_Utils_Misc::returnBytes((string)$resourceTypeNode["maxSize"]);
106
+		}
107
+
108
+		if (isset($resourceTypeNode["directory"])) {
109
+			$this->_directory = $resourceTypeNode["directory"];
110
+		}
111
+
112
+		if (!strlen($this->_directory)) {
113
+			$this->_directory = resolveUrl($this->_url);
114
+		}
115
+
116
+		if (isset($resourceTypeNode["allowedExtensions"])) {
117
+			if (is_array($resourceTypeNode["allowedExtensions"])) {
118
+				foreach ($resourceTypeNode["allowedExtensions"] as $e) {
119
+					$this->_allowedExtensions[] = strtolower(trim((string)$e));
120
+				}
121
+			}
122
+			else {
123
+				$resourceTypeNode["allowedExtensions"] = trim((string)$resourceTypeNode["allowedExtensions"]);
124
+				if (strlen($resourceTypeNode["allowedExtensions"])) {
125
+					$extensions = explode(",", $resourceTypeNode["allowedExtensions"]);
126
+					foreach ($extensions as $e) {
127
+						$this->_allowedExtensions[] = strtolower(trim($e));
128
+					}
129
+				}
130
+			}
131
+		}
132
+
133
+		if (isset($resourceTypeNode["deniedExtensions"])) {
134
+			if (is_array($resourceTypeNode["deniedExtensions"])) {
135
+
136
+				foreach ($resourceTypeNode["deniedExtensions"] as $extension) {
137
+					$this->_deniedExtensions[] = strtolower(trim((string)$e));
138
+				}
139
+			}
140
+			else {
141
+				$resourceTypeNode["deniedExtensions"] = trim((string)$resourceTypeNode["deniedExtensions"]);
142
+				if (strlen($resourceTypeNode["deniedExtensions"])) {
143
+					$extensions = explode(",", $resourceTypeNode["deniedExtensions"]);
144
+					foreach ($extensions as $e) {
145
+						$this->_deniedExtensions[] = strtolower(trim($e));
146
+					}
147
+				}
148
+			}
149
+		}
150
+	}
151
+
152
+	/**
153
+	 * Get name
154
+	 *
155
+	 * @access public
156
+	 * @return string
157
+	 */
158
+	function getName()
159
+	{
160
+		return $this->_name;
161
+	}
162
+
163
+	/**
164
+	 * Get url
165
+	 *
166
+	 * @access public
167
+	 * @return string
168
+	 */
169
+	function getUrl()
170
+	{
171
+		return $this->_url;
172
+	}
173
+
174
+	/**
175
+	 * Get directory
176
+	 *
177
+	 * @access public
178
+	 * @return string
179
+	 */
180
+	function getDirectory()
181
+	{
182
+		return $this->_directory;
183
+	}
184
+
185
+	/**
186
+	 * Get max size
187
+	 *
188
+	 * @access public
189
+	 * @return int
190
+	 */
191
+	function getMaxSize()
192
+	{
193
+		return $this->_maxSize;
194
+	}
195
+
196
+	/**
197
+	 * Get allowed extensions
198
+	 *
199
+	 * @access public
200
+	 * @return array[]string
201
+	 */
202
+	function getAllowedExtensions()
203
+	{
204
+		return $this->_allowedExtensions;
205
+	}
206
+
207
+	/**
208
+	 * Get denied extensions
209
+	 *
210
+	 * @access public
211
+	 * @return array[]string
212
+	 */
213
+	function getDeniedExtensions()
214
+	{
215
+		return $this->_deniedExtensions;
216
+	}
217
+
218
+	/**
219
+	 * Check extension, return true if file name is valid.
220
+	 * Return false if extension is on denied list.
221
+	 * If allowed extensions are defined, return false if extension isn't on allowed list.
222
+	 *
223
+	 * @access public
224
+	 * @param string $extension extension
225
+	 * @param boolean $renameIfRequired whether try to rename file or not
226
+	 * @return boolean
227
+	 */
228
+	function checkExtension(&$fileName, $renameIfRequired = true)
229
+	{
230
+		if (strpos($fileName, '.') === false) {
231
+			return true;
232
+		}
233
+
234
+		if (is_null($this->_config)) {
235
+			$this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
236
+		}
237
+
238
+		$toCheck = array();
239
+
240
+		if ($this->_config->getCheckDoubleExtension()) {
241
+			$pieces = explode('.', $fileName);
242
+
243
+			// First, check the last extension (ex. in file.php.jpg, the "jpg").
244
+			if ( !$this->checkSingleExtension( $pieces[sizeof($pieces)-1] ) ) {
245
+				return false;
246
+			}
247
+
248
+			if ($renameIfRequired) {
249
+				// Check the other extensions, rebuilding the file name. If an extension is
250
+				// not allowed, replace the dot with an underscore.
251
+				$fileName = $pieces[0] ;
252
+				for ($i=1; $i<sizeof($pieces)-1; $i++) {
253
+					$fileName .= $this->checkSingleExtension( $pieces[$i] ) ? '.' : '_' ;
254
+					$fileName .= $pieces[$i];
255
+				}
256
+
257
+				// Add the last extension to the final name.
258
+				$fileName .= '.' . $pieces[sizeof($pieces)-1] ;
259
+			}
260
+		}
261
+		else {
262
+			// Check only the last extension (ex. in file.php.jpg, only "jpg").
263
+			return $this->checkSingleExtension( substr($fileName, strrpos($fileName,'.')+1) );
264
+		}
265
+
266
+		return true;
267
+	}
268
+
269
+	/**
270
+	 * Check given folder name
271
+	 * Return true if folder name matches hidden folder names list
272
+	 *
273
+	 * @param string $folderName
274
+	 * @access public
275
+	 * @return boolean
276
+	 */
277
+	function checkIsHiddenFolder($folderName)
278
+	{
279
+		if (is_null($this->_config)) {
280
+			$this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
281
+		}
282
+
283
+		$regex = $this->_config->getHideFoldersRegex();
284
+		if ($regex) {
285
+			return preg_match($regex, $folderName);
286
+		}
287
+
288
+		return false;
289
+	}
290
+
291
+	/**
292
+	 * Check given file name
293
+	 * Return true if file name matches hidden file names list
294
+	 *
295
+	 * @param string $fileName
296
+	 * @access public
297
+	 * @return boolean
298
+	 */
299
+	function checkIsHiddenFile($fileName)
300
+	{
301
+		if (is_null($this->_config)) {
302
+			$this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
303
+		}
304
+
305
+		$regex = $this->_config->getHideFilesRegex();
306
+		if ($regex) {
307
+			return preg_match($regex, $fileName);
308
+		}
309
+
310
+		return false;
311
+	}
312
+
313
+	/**
314
+	 * Check given path
315
+	 * Return true if path contains folder name that matches hidden folder names list
316
+	 *
317
+	 * @param string $folderName
318
+	 * @access public
319
+	 * @return boolean
320
+	 */
321
+	function checkIsHiddenPath($path)
322
+	{
323
+		$_clientPathParts = explode("/", trim($path, "/"));
324
+		if ($_clientPathParts) {
325
+			foreach ($_clientPathParts as $_part) {
326
+				if ($this->checkIsHiddenFolder($_part)) {
327
+					return true;
328
+				}
329
+			}
330
+		}
331
+
332
+		return false;
333
+	}
334
+
335
+	function checkSingleExtension($extension)
336
+	{
337
+		$extension = strtolower(ltrim($extension,'.'));
338
+
339
+		if (sizeof($this->_deniedExtensions)) {
340
+			if (in_array($extension, $this->_deniedExtensions)) {
341
+				return false;
342
+			}
343
+		}
344
+
345
+		if (sizeof($this->_allowedExtensions)) {
346
+			return in_array($extension, $this->_allowedExtensions);
347
+		}
348
+
349
+		return true;
350
+	}
351 351
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
         if (!strlen($this->_url)) {
98 98
             $this->_url = "/";
99 99
         }
100
-        else if(substr($this->_url,-1,1) != "/") {
100
+        else if (substr($this->_url, -1, 1) != "/") {
101 101
             $this->_url .= "/";
102 102
         }
103 103
 
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
         }
233 233
 
234 234
         if (is_null($this->_config)) {
235
-            $this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
235
+            $this->_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config");
236 236
         }
237 237
 
238 238
         $toCheck = array();
@@ -241,26 +241,26 @@  discard block
 block discarded – undo
241 241
             $pieces = explode('.', $fileName);
242 242
 
243 243
             // First, check the last extension (ex. in file.php.jpg, the "jpg").
244
-            if ( !$this->checkSingleExtension( $pieces[sizeof($pieces)-1] ) ) {
244
+            if (!$this->checkSingleExtension($pieces[sizeof($pieces) - 1])) {
245 245
                 return false;
246 246
             }
247 247
 
248 248
             if ($renameIfRequired) {
249 249
                 // Check the other extensions, rebuilding the file name. If an extension is
250 250
                 // not allowed, replace the dot with an underscore.
251
-                $fileName = $pieces[0] ;
252
-                for ($i=1; $i<sizeof($pieces)-1; $i++) {
253
-                    $fileName .= $this->checkSingleExtension( $pieces[$i] ) ? '.' : '_' ;
251
+                $fileName = $pieces[0];
252
+                for ($i = 1; $i < sizeof($pieces) - 1; $i++) {
253
+                    $fileName .= $this->checkSingleExtension($pieces[$i]) ? '.' : '_';
254 254
                     $fileName .= $pieces[$i];
255 255
                 }
256 256
 
257 257
                 // Add the last extension to the final name.
258
-                $fileName .= '.' . $pieces[sizeof($pieces)-1] ;
258
+                $fileName .= '.'.$pieces[sizeof($pieces) - 1];
259 259
             }
260 260
         }
261 261
         else {
262 262
             // Check only the last extension (ex. in file.php.jpg, only "jpg").
263
-            return $this->checkSingleExtension( substr($fileName, strrpos($fileName,'.')+1) );
263
+            return $this->checkSingleExtension(substr($fileName, strrpos($fileName, '.') + 1));
264 264
         }
265 265
 
266 266
         return true;
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
     function checkIsHiddenFolder($folderName)
278 278
     {
279 279
         if (is_null($this->_config)) {
280
-            $this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
280
+            $this->_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config");
281 281
         }
282 282
 
283 283
         $regex = $this->_config->getHideFoldersRegex();
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
     function checkIsHiddenFile($fileName)
300 300
     {
301 301
         if (is_null($this->_config)) {
302
-            $this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
302
+            $this->_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config");
303 303
         }
304 304
 
305 305
         $regex = $this->_config->getHideFilesRegex();
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
 
335 335
     function checkSingleExtension($extension)
336 336
     {
337
-        $extension = strtolower(ltrim($extension,'.'));
337
+        $extension = strtolower(ltrim($extension, '.'));
338 338
 
339 339
         if (sizeof($this->_deniedExtensions)) {
340 340
             if (in_array($extension, $this->_deniedExtensions)) {
Please login to merge, or discard this patch.
Braces   +7 added lines, -9 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@  discard block
 block discarded – undo
10 10
  * modifying or distribute this file or part of its contents. The contents of
11 11
  * this file is part of the Source Code of CKFinder.
12 12
  */
13
-if (!defined('IN_CKFINDER')) exit;
13
+if (!defined('IN_CKFINDER')) {
14
+	exit;
15
+}
14 16
 
15 17
 /**
16 18
  * @package CKFinder
@@ -96,8 +98,7 @@  discard block
 block discarded – undo
96 98
 
97 99
         if (!strlen($this->_url)) {
98 100
             $this->_url = "/";
99
-        }
100
-        else if(substr($this->_url,-1,1) != "/") {
101
+        } else if(substr($this->_url,-1,1) != "/") {
101 102
             $this->_url .= "/";
102 103
         }
103 104
 
@@ -118,8 +119,7 @@  discard block
 block discarded – undo
118 119
                 foreach ($resourceTypeNode["allowedExtensions"] as $e) {
119 120
                     $this->_allowedExtensions[] = strtolower(trim((string)$e));
120 121
                 }
121
-            }
122
-            else {
122
+            } else {
123 123
                 $resourceTypeNode["allowedExtensions"] = trim((string)$resourceTypeNode["allowedExtensions"]);
124 124
                 if (strlen($resourceTypeNode["allowedExtensions"])) {
125 125
                     $extensions = explode(",", $resourceTypeNode["allowedExtensions"]);
@@ -136,8 +136,7 @@  discard block
 block discarded – undo
136 136
                 foreach ($resourceTypeNode["deniedExtensions"] as $extension) {
137 137
                     $this->_deniedExtensions[] = strtolower(trim((string)$e));
138 138
                 }
139
-            }
140
-            else {
139
+            } else {
141 140
                 $resourceTypeNode["deniedExtensions"] = trim((string)$resourceTypeNode["deniedExtensions"]);
142 141
                 if (strlen($resourceTypeNode["deniedExtensions"])) {
143 142
                     $extensions = explode(",", $resourceTypeNode["deniedExtensions"]);
@@ -257,8 +256,7 @@  discard block
 block discarded – undo
257 256
                 // Add the last extension to the final name.
258 257
                 $fileName .= '.' . $pieces[sizeof($pieces)-1] ;
259 258
             }
260
-        }
261
-        else {
259
+        } else {
262 260
             // Check only the last extension (ex. in file.php.jpg, only "jpg").
263 261
             return $this->checkSingleExtension( substr($fileName, strrpos($fileName,'.')+1) );
264 262
         }
Please login to merge, or discard this patch.
libs/ckfinder/core/connector/php/php4/ErrorHandler/FileUpload.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@
 block discarded – undo
36 36
      * Throw file upload error, return true if error has been thrown, false if error has been catched
37 37
      *
38 38
      * @param int $number
39
-     * @param string $text
39
+     * @param string $exit
40 40
      * @access public
41 41
      */
42 42
     function throwError($number, $uploaded = false, $exit = true) {
Please login to merge, or discard this patch.
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -32,50 +32,50 @@
 block discarded – undo
32 32
  */
33 33
 class CKFinder_Connector_ErrorHandler_FileUpload extends CKFinder_Connector_ErrorHandler_Base
34 34
 {
35
-    /**
36
-     * Throw file upload error, return true if error has been thrown, false if error has been catched
37
-     *
38
-     * @param int $number
39
-     * @param string $text
40
-     * @access public
41
-     */
42
-    function throwError($number, $uploaded = false, $exit = true) {
43
-        if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) {
44
-            return false;
45
-        }
35
+	/**
36
+	 * Throw file upload error, return true if error has been thrown, false if error has been catched
37
+	 *
38
+	 * @param int $number
39
+	 * @param string $text
40
+	 * @access public
41
+	 */
42
+	function throwError($number, $uploaded = false, $exit = true) {
43
+		if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) {
44
+			return false;
45
+		}
46 46
 
47
-        $oRegistry = & CKFinder_Connector_Core_Factory :: getInstance("Core_Registry");
48
-        $sFileName = $oRegistry->get("FileUpload_fileName");
49
-        $sFileUrl = $oRegistry->get("FileUpload_url");
47
+		$oRegistry = & CKFinder_Connector_Core_Factory :: getInstance("Core_Registry");
48
+		$sFileName = $oRegistry->get("FileUpload_fileName");
49
+		$sFileUrl = $oRegistry->get("FileUpload_url");
50 50
 
51
-        header('Content-Type: text/html; charset=utf-8');
51
+		header('Content-Type: text/html; charset=utf-8');
52 52
 
53
-        $errorMessage = CKFinder_Connector_Utils_Misc :: getErrorMessage($number, $sFileName);
54
-        if (!$uploaded) {
55
-            $sFileName = "";
56
-        }
53
+		$errorMessage = CKFinder_Connector_Utils_Misc :: getErrorMessage($number, $sFileName);
54
+		if (!$uploaded) {
55
+			$sFileName = "";
56
+		}
57 57
 
58
-        echo "<script type=\"text/javascript\">";
58
+		echo "<script type=\"text/javascript\">";
59 59
 
60
-        if (!empty($_GET['CKFinderFuncNum'])) {
61
-            $errorMessage = CKFinder_Connector_Utils_Misc::getErrorMessage($number, $sFileName);
60
+		if (!empty($_GET['CKFinderFuncNum'])) {
61
+			$errorMessage = CKFinder_Connector_Utils_Misc::getErrorMessage($number, $sFileName);
62 62
 
63
-            if (!$uploaded) {
64
-                $sFileUrl = "";
65
-                $sFileName = "";
66
-            }
63
+			if (!$uploaded) {
64
+				$sFileUrl = "";
65
+				$sFileName = "";
66
+			}
67 67
 
68
-            $funcNum = preg_replace("/[^0-9]/", "", $_GET['CKFinderFuncNum']);
69
-            echo "window.parent.CKFinder.tools.callFunction($funcNum, '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" .str_replace("'", "\\'", $errorMessage). "');";
70
-        }
71
-        else {
72
-            echo "window.parent.OnUploadCompleted('" . str_replace("'", "\\'", $sFileName) . "', '" . str_replace("'", "\\'", $errorMessage) . "') ;";
73
-        }
68
+			$funcNum = preg_replace("/[^0-9]/", "", $_GET['CKFinderFuncNum']);
69
+			echo "window.parent.CKFinder.tools.callFunction($funcNum, '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" .str_replace("'", "\\'", $errorMessage). "');";
70
+		}
71
+		else {
72
+			echo "window.parent.OnUploadCompleted('" . str_replace("'", "\\'", $sFileName) . "', '" . str_replace("'", "\\'", $errorMessage) . "') ;";
73
+		}
74 74
 
75
-        echo "</script>";
75
+		echo "</script>";
76 76
 
77
-        if ($exit) {
78
-            exit;
79
-        }
80
-    }
77
+		if ($exit) {
78
+			exit;
79
+		}
80
+	}
81 81
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 /**
22 22
  * Include base error handling class
23 23
  */
24
-require_once CKFINDER_CONNECTOR_LIB_DIR . "/ErrorHandler/Base.php";
24
+require_once CKFINDER_CONNECTOR_LIB_DIR."/ErrorHandler/Base.php";
25 25
 
26 26
 /**
27 27
  * File upload error handler
@@ -66,10 +66,10 @@  discard block
 block discarded – undo
66 66
             }
67 67
 
68 68
             $funcNum = preg_replace("/[^0-9]/", "", $_GET['CKFinderFuncNum']);
69
-            echo "window.parent.CKFinder.tools.callFunction($funcNum, '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" .str_replace("'", "\\'", $errorMessage). "');";
69
+            echo "window.parent.CKFinder.tools.callFunction($funcNum, '".str_replace("'", "\\'", $sFileUrl.$sFileName)."', '".str_replace("'", "\\'", $errorMessage)."');";
70 70
         }
71 71
         else {
72
-            echo "window.parent.OnUploadCompleted('" . str_replace("'", "\\'", $sFileName) . "', '" . str_replace("'", "\\'", $errorMessage) . "') ;";
72
+            echo "window.parent.OnUploadCompleted('".str_replace("'", "\\'", $sFileName)."', '".str_replace("'", "\\'", $errorMessage)."') ;";
73 73
         }
74 74
 
75 75
         echo "</script>";
Please login to merge, or discard this patch.
Braces   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@  discard block
 block discarded – undo
10 10
  * modifying or distribute this file or part of its contents. The contents of
11 11
  * this file is part of the Source Code of CKFinder.
12 12
  */
13
-if (!defined('IN_CKFINDER')) exit;
13
+if (!defined('IN_CKFINDER')) {
14
+	exit;
15
+}
14 16
 
15 17
 /**
16 18
  * @package CKFinder
@@ -67,8 +69,7 @@  discard block
 block discarded – undo
67 69
 
68 70
             $funcNum = preg_replace("/[^0-9]/", "", $_GET['CKFinderFuncNum']);
69 71
             echo "window.parent.CKFinder.tools.callFunction($funcNum, '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" .str_replace("'", "\\'", $errorMessage). "');";
70
-        }
71
-        else {
72
+        } else {
72 73
             echo "window.parent.OnUploadCompleted('" . str_replace("'", "\\'", $sFileName) . "', '" . str_replace("'", "\\'", $errorMessage) . "') ;";
73 74
         }
74 75
 
Please login to merge, or discard this patch.
libs/ckfinder/core/connector/php/php4/ErrorHandler/QuickUpload.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@
 block discarded – undo
36 36
      * Throw file upload error, return true if error has been thrown, false if error has been catched
37 37
      *
38 38
      * @param int $number
39
-     * @param string $text
39
+     * @param string $exit
40 40
      * @access public
41 41
      */
42 42
     function throwError($number, $uploaded = false, $exit = true) {
Please login to merge, or discard this patch.
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -32,52 +32,52 @@
 block discarded – undo
32 32
  */
33 33
 class CKFinder_Connector_ErrorHandler_QuickUpload extends CKFinder_Connector_ErrorHandler_Base
34 34
 {
35
-    /**
36
-     * Throw file upload error, return true if error has been thrown, false if error has been catched
37
-     *
38
-     * @param int $number
39
-     * @param string $text
40
-     * @access public
41
-     */
42
-    function throwError($number, $uploaded = false, $exit = true) {
43
-        if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) {
44
-            return false;
45
-        }
35
+	/**
36
+	 * Throw file upload error, return true if error has been thrown, false if error has been catched
37
+	 *
38
+	 * @param int $number
39
+	 * @param string $text
40
+	 * @access public
41
+	 */
42
+	function throwError($number, $uploaded = false, $exit = true) {
43
+		if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) {
44
+			return false;
45
+		}
46 46
 
47
-        $oRegistry = & CKFinder_Connector_Core_Factory :: getInstance("Core_Registry");
48
-        $sFileName = $oRegistry->get("FileUpload_fileName");
49
-        $sFileUrl = $oRegistry->get("FileUpload_url");
47
+		$oRegistry = & CKFinder_Connector_Core_Factory :: getInstance("Core_Registry");
48
+		$sFileName = $oRegistry->get("FileUpload_fileName");
49
+		$sFileUrl = $oRegistry->get("FileUpload_url");
50 50
 
51
-        header('Content-Type: text/html; charset=utf-8');
51
+		header('Content-Type: text/html; charset=utf-8');
52 52
 
53 53
 		/**
54 54
 		 * echo <script> is not called before CKFinder_Connector_Utils_Misc::getErrorMessage
55 55
 		 * because PHP has problems with including files that contain BOM character.
56 56
 		 * Having BOM character after <script> tag causes a javascript error.
57 57
 		 */
58
-        echo "<script type=\"text/javascript\">";
59
-        if (!empty($_GET['CKEditor'])) {
60
-            $errorMessage = CKFinder_Connector_Utils_Misc::getErrorMessage($number, $sFileName);
58
+		echo "<script type=\"text/javascript\">";
59
+		if (!empty($_GET['CKEditor'])) {
60
+			$errorMessage = CKFinder_Connector_Utils_Misc::getErrorMessage($number, $sFileName);
61 61
 
62
-            if (!$uploaded) {
63
-                $sFileUrl = "";
64
-                $sFileName = "";
65
-            }
62
+			if (!$uploaded) {
63
+				$sFileUrl = "";
64
+				$sFileName = "";
65
+			}
66 66
 
67
-            $funcNum = preg_replace("/[^0-9]/", "", $_GET['CKEditorFuncNum']);
68
-            echo "window.parent.CKEDITOR.tools.callFunction($funcNum, '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" .str_replace("'", "\\'", $errorMessage). "');";
69
-        }
70
-        else {
71
-            if (!$uploaded) {
72
-                echo "window.parent.OnUploadCompleted(" . $number . ", '', '', '') ;";
73
-            } else {
74
-                echo "window.parent.OnUploadCompleted(" . $number . ", '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" . str_replace("'", "\\'", $sFileName) . "', '') ;";
75
-            }
76
-        }
77
-        echo "</script>";
67
+			$funcNum = preg_replace("/[^0-9]/", "", $_GET['CKEditorFuncNum']);
68
+			echo "window.parent.CKEDITOR.tools.callFunction($funcNum, '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" .str_replace("'", "\\'", $errorMessage). "');";
69
+		}
70
+		else {
71
+			if (!$uploaded) {
72
+				echo "window.parent.OnUploadCompleted(" . $number . ", '', '', '') ;";
73
+			} else {
74
+				echo "window.parent.OnUploadCompleted(" . $number . ", '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" . str_replace("'", "\\'", $sFileName) . "', '') ;";
75
+			}
76
+		}
77
+		echo "</script>";
78 78
 
79
-        if ($exit) {
80
-            exit;
81
-        }
82
-    }
79
+		if ($exit) {
80
+			exit;
81
+		}
82
+	}
83 83
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 /**
22 22
  * Include base error handling class
23 23
  */
24
-require_once CKFINDER_CONNECTOR_LIB_DIR . "/ErrorHandler/Base.php";
24
+require_once CKFINDER_CONNECTOR_LIB_DIR."/ErrorHandler/Base.php";
25 25
 
26 26
 /**
27 27
  * File upload error handler
@@ -65,13 +65,13 @@  discard block
 block discarded – undo
65 65
             }
66 66
 
67 67
             $funcNum = preg_replace("/[^0-9]/", "", $_GET['CKEditorFuncNum']);
68
-            echo "window.parent.CKEDITOR.tools.callFunction($funcNum, '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" .str_replace("'", "\\'", $errorMessage). "');";
68
+            echo "window.parent.CKEDITOR.tools.callFunction($funcNum, '".str_replace("'", "\\'", $sFileUrl.$sFileName)."', '".str_replace("'", "\\'", $errorMessage)."');";
69 69
         }
70 70
         else {
71 71
             if (!$uploaded) {
72
-                echo "window.parent.OnUploadCompleted(" . $number . ", '', '', '') ;";
72
+                echo "window.parent.OnUploadCompleted(".$number.", '', '', '') ;";
73 73
             } else {
74
-                echo "window.parent.OnUploadCompleted(" . $number . ", '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" . str_replace("'", "\\'", $sFileName) . "', '') ;";
74
+                echo "window.parent.OnUploadCompleted(".$number.", '".str_replace("'", "\\'", $sFileUrl.$sFileName)."', '".str_replace("'", "\\'", $sFileName)."', '') ;";
75 75
             }
76 76
         }
77 77
         echo "</script>";
Please login to merge, or discard this patch.
Braces   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@  discard block
 block discarded – undo
10 10
  * modifying or distribute this file or part of its contents. The contents of
11 11
  * this file is part of the Source Code of CKFinder.
12 12
  */
13
-if (!defined('IN_CKFINDER')) exit;
13
+if (!defined('IN_CKFINDER')) {
14
+	exit;
15
+}
14 16
 
15 17
 /**
16 18
  * @package CKFinder
@@ -66,8 +68,7 @@  discard block
 block discarded – undo
66 68
 
67 69
             $funcNum = preg_replace("/[^0-9]/", "", $_GET['CKEditorFuncNum']);
68 70
             echo "window.parent.CKEDITOR.tools.callFunction($funcNum, '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" .str_replace("'", "\\'", $errorMessage). "');";
69
-        }
70
-        else {
71
+        } else {
71 72
             if (!$uploaded) {
72 73
                 echo "window.parent.OnUploadCompleted(" . $number . ", '', '', '') ;";
73 74
             } else {
Please login to merge, or discard this patch.
libs/ckfinder/core/connector/php/php4/Utils/FileSystem.php 4 patches
Doc Comments   +3 added lines, -5 removed lines patch added patch discarded remove patch
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
      * PHP4 Scandir
136 136
      * @static
137 137
      * @access public
138
-     * @param $directory directory name
138
+     * @param string $directory directory name
139 139
     */
140 140
     function php4_scandir($directory)
141 141
     {
@@ -404,7 +404,6 @@  discard block
 block discarded – undo
404 404
      * @static
405 405
      * @access public
406 406
      * @param string $dir
407
-     * @param int $mode
408 407
      * @return boolean
409 408
      */
410 409
     function createDirectoryRecursively($dir)
@@ -454,7 +453,7 @@  discard block
 block discarded – undo
454 453
      * @static
455 454
      * @access public
456 455
      * @param string $filePath absolute path to file
457
-     * @return boolean
456
+     * @return string
458 457
     */
459 458
     function detectHtml($filePath)
460 459
     {
@@ -515,8 +514,7 @@  discard block
 block discarded – undo
515 514
      * @access public
516 515
      * @param string $filePath absolute path to file
517 516
      * @param string $extension file extension
518
-     * @param integer $detectionLevel 0 = none, 1 = use getimagesize for images, 2 = use DetectHtml for images
519
-     * @return boolean
517
+     * @return string
520 518
     */
521 519
     function isImageValid($filePath, $extension)
522 520
     {
Please login to merge, or discard this patch.
Indentation   +523 added lines, -523 removed lines patch added patch discarded remove patch
@@ -26,220 +26,220 @@  discard block
 block discarded – undo
26 26
 class CKFinder_Connector_Utils_FileSystem
27 27
 {
28 28
 
29
-    /**
30
-     * This function behaves similar to System.IO.Path.Combine in C#, the only diffrenece is that it also accepts null values and treat them as empty string
31
-     *
32
-     * @static
33
-     * @access public
34
-     * @param string $path1 first path
35
-     * @param string $path2 scecond path
36
-     * @return string
37
-     */
38
-    function combinePaths($path1, $path2)
39
-    {
40
-        if (is_null($path1))  {
41
-            $path1 = "";
42
-        }
43
-        if (is_null($path2))  {
44
-            $path2 = "";
45
-        }
46
-        if (!strlen($path2)) {
47
-            if (strlen($path1)) {
48
-                $_lastCharP1 = substr($path1, -1, 1);
49
-                if ($_lastCharP1 != "/" && $_lastCharP1 != "\\") {
50
-                    $path1 .= DIRECTORY_SEPARATOR;
51
-                }
52
-            }
53
-        }
54
-        else {
55
-            $_firstCharP2 = substr($path2, 0, 1);
56
-            if (strlen($path1)) {
57
-                if (strpos($path2, $path1)===0) {
58
-                    return $path2;
59
-                }
60
-                $_lastCharP1 = substr($path1, -1, 1);
61
-                if ($_lastCharP1 != "/" && $_lastCharP1 != "\\" && $_firstCharP2 != "/" && $_firstCharP2 != "\\") {
62
-                    $path1 .= DIRECTORY_SEPARATOR;
63
-                }
64
-            }
65
-            else {
66
-                return $path2;
67
-            }
68
-        }
69
-        return $path1 . $path2;
70
-    }
71
-
72
-    /**
73
-     * Check whether $fileName is a valid file name, return true on success
74
-     *
75
-     * @static
76
-     * @access public
77
-     * @param string $fileName
78
-     * @return boolean
79
-     */
80
-    function checkFileName($fileName)
81
-    {
82
-        if (is_null($fileName) || !strlen($fileName) || substr($fileName,-1,1)=="." || false!==strpos($fileName, "..")) {
83
-            return false;
84
-        }
85
-
86
-        if (preg_match(CKFINDER_REGEX_INVALID_FILE, $fileName)) {
87
-            return false;
88
-        }
89
-
90
-        return true;
91
-    }
92
-
93
-    /**
94
-     * Unlink file/folder
95
-     *
96
-     * @static
97
-     * @access public
98
-     * @param string $path
99
-     * @return boolean
100
-     */
101
-    function unlink($path)
102
-    {
103
-        /*    make sure the path exists    */
104
-        if(!file_exists($path)) {
105
-            return false;
106
-        }
107
-
108
-        /*    If it is a file or link, just delete it    */
109
-        if(is_file($path) || is_link($path)) {
110
-            return @unlink($path);
111
-        }
112
-
113
-        /*    Scan the dir and recursively unlink    */
114
-        $files = CKFinder_Connector_Utils_FileSystem::php4_scandir($path);
115
-        if ($files) {
116
-            foreach($files as $filename)
117
-            {
118
-                if ($filename == '.' || $filename == '..') {
119
-                    continue;
120
-                }
121
-                $file = str_replace('//','/',$path.'/'.$filename);
122
-                CKFinder_Connector_Utils_FileSystem::unlink($file);
123
-            }
124
-        }
125
-
126
-        /*    Remove the parent dir    */
127
-        if(!@rmdir($path)) {
128
-            return false;
129
-        }
130
-
131
-        return true;
132
-    }
133
-
134
-    /**
135
-     * PHP4 Scandir
136
-     * @static
137
-     * @access public
138
-     * @param $directory directory name
139
-    */
140
-    function php4_scandir($directory)
141
-    {
142
-        if (!is_dir($directory) || (false === $fh = @opendir($directory))) {
143
-            return false;
144
-        }
145
-
146
-        $files = array ();
147
-        while (false !== ($filename = readdir($fh))) {
148
-            $files[] = $filename;
149
-        }
150
-
151
-        closedir($fh);
152
-
153
-        return $files;
154
-    }
155
-
156
-    /**
157
-     * Return file name without extension (without dot & last part after dot)
158
-     *
159
-     * @static
160
-     * @access public
161
-     * @param string $fileName
162
-     * @return string
163
-     */
164
-    function getFileNameWithoutExtension($fileName)
165
-    {
166
-        $dotPos = strrpos( $fileName, '.' );
167
-        if (false === $dotPos) {
168
-            return $fileName;
169
-        }
170
-
171
-        return substr($fileName, 0, $dotPos);
172
-    }
173
-
174
-    /**
175
-     * Get file extension (only last part - e.g. extension of file.foo.bar.jpg = jpg)
176
-     *
177
-     * @static
178
-     * @access public
179
-     * @param string $fileName
180
-     * @return string
181
-     */
182
-    function getExtension( $fileName )
183
-    {
184
-        $dotPos = strrpos( $fileName, '.' );
185
-        if (false === $dotPos) {
186
-            return "";
187
-        }
188
-
189
-        return substr( $fileName, strrpos( $fileName, '.' ) +1 ) ;
190
-    }
191
-
192
-    /**
29
+	/**
30
+	 * This function behaves similar to System.IO.Path.Combine in C#, the only diffrenece is that it also accepts null values and treat them as empty string
31
+	 *
32
+	 * @static
33
+	 * @access public
34
+	 * @param string $path1 first path
35
+	 * @param string $path2 scecond path
36
+	 * @return string
37
+	 */
38
+	function combinePaths($path1, $path2)
39
+	{
40
+		if (is_null($path1))  {
41
+			$path1 = "";
42
+		}
43
+		if (is_null($path2))  {
44
+			$path2 = "";
45
+		}
46
+		if (!strlen($path2)) {
47
+			if (strlen($path1)) {
48
+				$_lastCharP1 = substr($path1, -1, 1);
49
+				if ($_lastCharP1 != "/" && $_lastCharP1 != "\\") {
50
+					$path1 .= DIRECTORY_SEPARATOR;
51
+				}
52
+			}
53
+		}
54
+		else {
55
+			$_firstCharP2 = substr($path2, 0, 1);
56
+			if (strlen($path1)) {
57
+				if (strpos($path2, $path1)===0) {
58
+					return $path2;
59
+				}
60
+				$_lastCharP1 = substr($path1, -1, 1);
61
+				if ($_lastCharP1 != "/" && $_lastCharP1 != "\\" && $_firstCharP2 != "/" && $_firstCharP2 != "\\") {
62
+					$path1 .= DIRECTORY_SEPARATOR;
63
+				}
64
+			}
65
+			else {
66
+				return $path2;
67
+			}
68
+		}
69
+		return $path1 . $path2;
70
+	}
71
+
72
+	/**
73
+	 * Check whether $fileName is a valid file name, return true on success
74
+	 *
75
+	 * @static
76
+	 * @access public
77
+	 * @param string $fileName
78
+	 * @return boolean
79
+	 */
80
+	function checkFileName($fileName)
81
+	{
82
+		if (is_null($fileName) || !strlen($fileName) || substr($fileName,-1,1)=="." || false!==strpos($fileName, "..")) {
83
+			return false;
84
+		}
85
+
86
+		if (preg_match(CKFINDER_REGEX_INVALID_FILE, $fileName)) {
87
+			return false;
88
+		}
89
+
90
+		return true;
91
+	}
92
+
93
+	/**
94
+	 * Unlink file/folder
95
+	 *
96
+	 * @static
97
+	 * @access public
98
+	 * @param string $path
99
+	 * @return boolean
100
+	 */
101
+	function unlink($path)
102
+	{
103
+		/*    make sure the path exists    */
104
+		if(!file_exists($path)) {
105
+			return false;
106
+		}
107
+
108
+		/*    If it is a file or link, just delete it    */
109
+		if(is_file($path) || is_link($path)) {
110
+			return @unlink($path);
111
+		}
112
+
113
+		/*    Scan the dir and recursively unlink    */
114
+		$files = CKFinder_Connector_Utils_FileSystem::php4_scandir($path);
115
+		if ($files) {
116
+			foreach($files as $filename)
117
+			{
118
+				if ($filename == '.' || $filename == '..') {
119
+					continue;
120
+				}
121
+				$file = str_replace('//','/',$path.'/'.$filename);
122
+				CKFinder_Connector_Utils_FileSystem::unlink($file);
123
+			}
124
+		}
125
+
126
+		/*    Remove the parent dir    */
127
+		if(!@rmdir($path)) {
128
+			return false;
129
+		}
130
+
131
+		return true;
132
+	}
133
+
134
+	/**
135
+	 * PHP4 Scandir
136
+	 * @static
137
+	 * @access public
138
+	 * @param $directory directory name
139
+	 */
140
+	function php4_scandir($directory)
141
+	{
142
+		if (!is_dir($directory) || (false === $fh = @opendir($directory))) {
143
+			return false;
144
+		}
145
+
146
+		$files = array ();
147
+		while (false !== ($filename = readdir($fh))) {
148
+			$files[] = $filename;
149
+		}
150
+
151
+		closedir($fh);
152
+
153
+		return $files;
154
+	}
155
+
156
+	/**
157
+	 * Return file name without extension (without dot & last part after dot)
158
+	 *
159
+	 * @static
160
+	 * @access public
161
+	 * @param string $fileName
162
+	 * @return string
163
+	 */
164
+	function getFileNameWithoutExtension($fileName)
165
+	{
166
+		$dotPos = strrpos( $fileName, '.' );
167
+		if (false === $dotPos) {
168
+			return $fileName;
169
+		}
170
+
171
+		return substr($fileName, 0, $dotPos);
172
+	}
173
+
174
+	/**
175
+	 * Get file extension (only last part - e.g. extension of file.foo.bar.jpg = jpg)
176
+	 *
177
+	 * @static
178
+	 * @access public
179
+	 * @param string $fileName
180
+	 * @return string
181
+	 */
182
+	function getExtension( $fileName )
183
+	{
184
+		$dotPos = strrpos( $fileName, '.' );
185
+		if (false === $dotPos) {
186
+			return "";
187
+		}
188
+
189
+		return substr( $fileName, strrpos( $fileName, '.' ) +1 ) ;
190
+	}
191
+
192
+	/**
193 193
 	 * Read file, split it into small chunks and send it to the browser
194 194
 	 *
195
-     * @static
196
-     * @access public
195
+	 * @static
196
+	 * @access public
197 197
 	 * @param string $filename
198 198
 	 * @return boolean
199 199
 	 */
200
-    function readfileChunked($filename)
201
-    {
202
-        $chunksize = 1024 * 10; // how many bytes per chunk
203
-
204
-        $handle = fopen($filename, 'rb');
205
-        if ($handle === false) {
206
-            return false;
207
-        }
208
-        while (!feof($handle)) {
209
-            echo fread($handle, $chunksize);
210
-            @ob_flush();
211
-            flush();
212
-            @set_time_limit(8);
213
-        }
214
-        fclose($handle);
215
-        return true;
216
-    }
217
-
218
-    /**
219
-    * Replace accented UTF-8 characters by unaccented ASCII-7 "equivalents".
220
-    * The purpose of this function is to replace characters commonly found in Latin
221
-    * alphabets with something more or less equivalent from the ASCII range. This can
222
-    * be useful for converting a UTF-8 to something ready for a filename, for example.
223
-    * Following the use of this function, you would probably also pass the string
224
-    * through utf8_strip_non_ascii to clean out any other non-ASCII chars
225
-    *
226
-    * For a more complete implementation of transliteration, see the utf8_to_ascii package
227
-    * available from the phputf8 project downloads:
228
-    * http://prdownloads.sourceforge.net/phputf8
229
-    *
230
-    * @param string UTF-8 string
231
-    * @param string UTF-8 with accented characters replaced by ASCII chars
232
-    * @return string accented chars replaced with ascii equivalents
233
-    * @author Andreas Gohr <[email protected]>
234
-    * @see http://sourceforge.net/projects/phputf8/
235
-    */
236
-    function convertToAscii($str)
237
-    {
238
-        static $UTF8_LOWER_ACCENTS = NULL;
239
-        static $UTF8_UPPER_ACCENTS = NULL;
240
-
241
-        if ( is_null($UTF8_LOWER_ACCENTS) ) {
242
-            $UTF8_LOWER_ACCENTS = array(
200
+	function readfileChunked($filename)
201
+	{
202
+		$chunksize = 1024 * 10; // how many bytes per chunk
203
+
204
+		$handle = fopen($filename, 'rb');
205
+		if ($handle === false) {
206
+			return false;
207
+		}
208
+		while (!feof($handle)) {
209
+			echo fread($handle, $chunksize);
210
+			@ob_flush();
211
+			flush();
212
+			@set_time_limit(8);
213
+		}
214
+		fclose($handle);
215
+		return true;
216
+	}
217
+
218
+	/**
219
+	 * Replace accented UTF-8 characters by unaccented ASCII-7 "equivalents".
220
+	 * The purpose of this function is to replace characters commonly found in Latin
221
+	 * alphabets with something more or less equivalent from the ASCII range. This can
222
+	 * be useful for converting a UTF-8 to something ready for a filename, for example.
223
+	 * Following the use of this function, you would probably also pass the string
224
+	 * through utf8_strip_non_ascii to clean out any other non-ASCII chars
225
+	 *
226
+	 * For a more complete implementation of transliteration, see the utf8_to_ascii package
227
+	 * available from the phputf8 project downloads:
228
+	 * http://prdownloads.sourceforge.net/phputf8
229
+	 *
230
+	 * @param string UTF-8 string
231
+	 * @param string UTF-8 with accented characters replaced by ASCII chars
232
+	 * @return string accented chars replaced with ascii equivalents
233
+	 * @author Andreas Gohr <[email protected]>
234
+	 * @see http://sourceforge.net/projects/phputf8/
235
+	 */
236
+	function convertToAscii($str)
237
+	{
238
+		static $UTF8_LOWER_ACCENTS = NULL;
239
+		static $UTF8_UPPER_ACCENTS = NULL;
240
+
241
+		if ( is_null($UTF8_LOWER_ACCENTS) ) {
242
+			$UTF8_LOWER_ACCENTS = array(
243 243
   'à' => 'a', 'ô' => 'o', 'ď' => 'd', 'ḟ' => 'f', 'ë' => 'e', 'š' => 's', 'ơ' => 'o',
244 244
   'ß' => 'ss', 'ă' => 'a', 'ř' => 'r', 'ț' => 't', 'ň' => 'n', 'ā' => 'a', 'ķ' => 'k',
245 245
   'ŝ' => 's', 'ỳ' => 'y', 'ņ' => 'n', 'ĺ' => 'l', 'ħ' => 'h', 'ṗ' => 'p', 'ó' => 'o',
@@ -255,17 +255,17 @@  discard block
 block discarded – undo
255 255
   'â' => 'a', 'ľ' => 'l', 'ẅ' => 'w', 'ż' => 'z', 'ī' => 'i', 'ã' => 'a', 'ġ' => 'g',
256 256
   'ṁ' => 'm', 'ō' => 'o', 'ĩ' => 'i', 'ù' => 'u', 'į' => 'i', 'ź' => 'z', 'á' => 'a',
257 257
   'û' => 'u', 'þ' => 'th', 'ð' => 'dh', 'æ' => 'ae', 'µ' => 'u', 'ĕ' => 'e',
258
-            );
259
-        }
258
+			);
259
+		}
260 260
 
261
-        $str = str_replace(
262
-                array_keys($UTF8_LOWER_ACCENTS),
263
-                array_values($UTF8_LOWER_ACCENTS),
264
-                $str
265
-            );
261
+		$str = str_replace(
262
+				array_keys($UTF8_LOWER_ACCENTS),
263
+				array_values($UTF8_LOWER_ACCENTS),
264
+				$str
265
+			);
266 266
 
267
-        if ( is_null($UTF8_UPPER_ACCENTS) ) {
268
-            $UTF8_UPPER_ACCENTS = array(
267
+		if ( is_null($UTF8_UPPER_ACCENTS) ) {
268
+			$UTF8_UPPER_ACCENTS = array(
269 269
   'À' => 'A', 'Ô' => 'O', 'Ď' => 'D', 'Ḟ' => 'F', 'Ë' => 'E', 'Š' => 'S', 'Ơ' => 'O',
270 270
   'Ă' => 'A', 'Ř' => 'R', 'Ț' => 'T', 'Ň' => 'N', 'Ā' => 'A', 'Ķ' => 'K',
271 271
   'Ŝ' => 'S', 'Ỳ' => 'Y', 'Ņ' => 'N', 'Ĺ' => 'L', 'Ħ' => 'H', 'Ṗ' => 'P', 'Ó' => 'O',
@@ -281,309 +281,309 @@  discard block
 block discarded – undo
281 281
   'Â' => 'A', 'Ľ' => 'L', 'Ẅ' => 'W', 'Ż' => 'Z', 'Ī' => 'I', 'Ã' => 'A', 'Ġ' => 'G',
282 282
   'Ṁ' => 'M', 'Ō' => 'O', 'Ĩ' => 'I', 'Ù' => 'U', 'Į' => 'I', 'Ź' => 'Z', 'Á' => 'A',
283 283
   'Û' => 'U', 'Þ' => 'Th', 'Ð' => 'Dh', 'Æ' => 'Ae', 'Ĕ' => 'E',
284
-            );
285
-        }
286
-        $str = str_replace(
287
-                array_keys($UTF8_UPPER_ACCENTS),
288
-                array_values($UTF8_UPPER_ACCENTS),
289
-                $str
290
-            );
291
-        return $str;
292
-    }
293
-
294
-    /**
295
-     * Convert file name from UTF-8 to system encoding
296
-     *
297
-     * @static
298
-     * @access public
299
-     * @param string $fileName
300
-     * @return string
301
-     */
302
-    function convertToFilesystemEncoding($fileName)
303
-    {
304
-        $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
305
-        $encoding = $_config->getFilesystemEncoding();
306
-        if (is_null($encoding) || strcasecmp($encoding, "UTF-8") == 0 || strcasecmp($encoding, "UTF8") == 0) {
307
-            return $fileName;
308
-        }
309
-
310
-        if (!function_exists("iconv")) {
311
-            if (strcasecmp($encoding, "ISO-8859-1") == 0 || strcasecmp($encoding, "ISO8859-1") == 0 || strcasecmp($encoding, "Latin1") == 0) {
312
-                return str_replace("\0", "_", utf8_decode($fileName));
313
-            } else if (function_exists('mb_convert_encoding')) {
314
-
315
-                $encoded = @mb_convert_encoding($fileName, $encoding, 'UTF-8');
316
-                if (@mb_strlen($fileName, "UTF-8") != @mb_strlen($encoded, $encoding)) {
317
-                    return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName));
318
-                }
319
-                else {
320
-                    return str_replace("\0", "_", $encoded);
321
-                }
322
-            } else {
323
-                return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName));
324
-            }
325
-        }
326
-
327
-        $converted = @iconv("UTF-8", $encoding . "//IGNORE//TRANSLIT", $fileName);
328
-        if ($converted === false) {
329
-            return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName));
330
-        }
331
-
332
-        return $converted;
333
-    }
334
-
335
-    /**
336
-     * Convert file name from system encoding into UTF-8
337
-     *
338
-     * @static
339
-     * @access public
340
-     * @param string $fileName
341
-     * @return string
342
-     */
343
-    function convertToConnectorEncoding($fileName)
344
-    {
345
-        $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
346
-        $encoding = $_config->getFilesystemEncoding();
347
-        if (is_null($encoding) || strcasecmp($encoding, "UTF-8") == 0 || strcasecmp($encoding, "UTF8") == 0) {
348
-            return $fileName;
349
-        }
350
-
351
-        if (!function_exists("iconv")) {
352
-            if (strcasecmp($encoding, "ISO-8859-1") == 0 || strcasecmp($encoding, "ISO8859-1") == 0 || strcasecmp($encoding, "Latin1") == 0) {
353
-                return utf8_encode($fileName);
354
-            } else {
355
-                return $fileName;
356
-            }
357
-        }
358
-
359
-        $converted = @iconv($encoding, "UTF-8", $fileName);
360
-
361
-        if ($converted === false) {
362
-            return $fileName;
363
-        }
364
-
365
-        return $converted;
366
-    }
367
-
368
-    /**
369
-     * Find document root
370
-     *
371
-     * @return string
372
-     * @access public
373
-     */
374
-    function getDocumentRootPath()
375
-    {
376
-        /**
377
-         * The absolute pathname of the currently executing script.
378
-         * Notatka: If a script is executed with the CLI, as a relative path, such as file.php or ../file.php,
379
-         * $_SERVER['SCRIPT_FILENAME'] will contain the relative path specified by the user.
380
-         */
381
-        if (isset($_SERVER['SCRIPT_FILENAME'])) {
382
-            $sRealPath = dirname($_SERVER['SCRIPT_FILENAME']);
383
-        }
384
-        else {
385
-            /**
386
-             * realpath — Returns canonicalized absolute pathname
387
-             */
388
-            $sRealPath = realpath( './' ) ;
389
-        }
390
-
391
-        /**
392
-         * The filename of the currently executing script, relative to the document root.
393
-         * For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar
394
-         * would be /test.php/foo.bar.
395
-         */
396
-        $sSelfPath = dirname($_SERVER['PHP_SELF']);
397
-
398
-        return substr($sRealPath, 0, strlen($sRealPath) - strlen($sSelfPath));
399
-    }
400
-
401
-    /**
402
-     * Create directory recursively
403
-     *
404
-     * @static
405
-     * @access public
406
-     * @param string $dir
407
-     * @param int $mode
408
-     * @return boolean
409
-     */
410
-    function createDirectoryRecursively($dir)
411
-    {
412
-        if (is_dir($dir)) {
413
-            return true;
414
-        }
415
-
416
-        //attempt to create directory
417
-        $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
418
-        if ($perms = $_config->getChmodFolders()) {
419
-            $oldUmask = umask(0);
420
-            $bCreated = @mkdir($dir, $perms);
421
-            umask($oldUmask);
422
-        }
423
-        else {
424
-            $bCreated = @mkdir($dir);
425
-        }
426
-
427
-        if ($bCreated) {
428
-            return true;
429
-        }
430
-
431
-        //failed to create directory, perhaps we need to create parent directories first
432
-        if (!CKFinder_Connector_Utils_FileSystem::createDirectoryRecursively(dirname($dir))) {
433
-            return false;
434
-        }
435
-
436
-        //parent directories created successfully, let's try to create directory once again
437
-        if ($perms) {
438
-            $old_umask = umask(0);
439
-            $result = @mkdir($dir, $perms);
440
-            umask($old_umask);
441
-        }
442
-        else {
443
-            $result = @mkdir($dir);
444
-        }
445
-
446
-        return $result;
447
-    }
448
-
449
-    /**
450
-     * Detect HTML in the first KB to prevent against potential security issue with
451
-     * IE/Safari/Opera file type auto detection bug.
452
-     * Returns true if file contain insecure HTML code at the beginning.
453
-     *
454
-     * @static
455
-     * @access public
456
-     * @param string $filePath absolute path to file
457
-     * @return boolean
458
-    */
459
-    function detectHtml($filePath)
460
-    {
461
-        $fp = @fopen($filePath, 'rb');
462
-        if ( $fp === false || !flock( $fp, LOCK_SH ) ) {
463
-            return -1 ;
464
-        }
465
-        $chunk = fread($fp, 1024);
466
-        flock( $fp, LOCK_UN ) ;
467
-        fclose($fp);
468
-
469
-        $chunk = strtolower($chunk);
470
-
471
-        if (!$chunk) {
472
-            return false;
473
-        }
474
-
475
-        $chunk = trim($chunk);
476
-
477
-        if (preg_match("/<!DOCTYPE\W*X?HTML/sim", $chunk)) {
478
-            return true;
479
-        }
480
-
481
-        $tags = array('<body', '<head', '<html', '<img', '<pre', '<script', '<table', '<title');
482
-
483
-        foreach( $tags as $tag ) {
484
-            if(false !== strpos($chunk, $tag)) {
485
-                return true ;
486
-            }
487
-        }
488
-
489
-        //type = javascript
490
-        if (preg_match('!type\s*=\s*[\'"]?\s*(?:\w*/)?(?:ecma|java)!sim', $chunk)) {
491
-            return true ;
492
-        }
493
-
494
-        //href = javascript
495
-        //src = javascript
496
-        //data = javascript
497
-        if (preg_match('!(?:href|src|data)\s*=\s*[\'"]?\s*(?:ecma|java)script:!sim',$chunk)) {
498
-            return true ;
499
-        }
500
-
501
-        //url(javascript
502
-        if (preg_match('!url\s*\(\s*[\'"]?\s*(?:ecma|java)script:!sim', $chunk)) {
503
-            return true ;
504
-        }
505
-
506
-        return false ;
507
-    }
508
-
509
-    /**
510
-     * Check file content.
511
-     * Currently this function validates only image files.
512
-     * Returns false if file is invalid.
513
-     *
514
-     * @static
515
-     * @access public
516
-     * @param string $filePath absolute path to file
517
-     * @param string $extension file extension
518
-     * @param integer $detectionLevel 0 = none, 1 = use getimagesize for images, 2 = use DetectHtml for images
519
-     * @return boolean
520
-    */
521
-    function isImageValid($filePath, $extension)
522
-    {
523
-        if (!@is_readable($filePath)) {
524
-            return -1;
525
-        }
526
-
527
-        $imageCheckExtensions = array('gif', 'jpeg', 'jpg', 'png', 'psd', 'bmp', 'tiff');
528
-
529
-        // version_compare is available since PHP4 >= 4.0.7
530
-        if ( function_exists( 'version_compare' ) ) {
531
-            $sCurrentVersion = phpversion();
532
-            if ( version_compare( $sCurrentVersion, "4.2.0" ) >= 0 ) {
533
-                $imageCheckExtensions[] = "tiff";
534
-                $imageCheckExtensions[] = "tif";
535
-            }
536
-            if ( version_compare( $sCurrentVersion, "4.3.0" ) >= 0 ) {
537
-                $imageCheckExtensions[] = "swc";
538
-            }
539
-            if ( version_compare( $sCurrentVersion, "4.3.2" ) >= 0 ) {
540
-                $imageCheckExtensions[] = "jpc";
541
-                $imageCheckExtensions[] = "jp2";
542
-                $imageCheckExtensions[] = "jpx";
543
-                $imageCheckExtensions[] = "jb2";
544
-                $imageCheckExtensions[] = "xbm";
545
-                $imageCheckExtensions[] = "wbmp";
546
-            }
547
-        }
548
-
549
-        if ( !in_array( $extension, $imageCheckExtensions ) ) {
550
-            return true;
551
-        }
552
-
553
-        if ( @getimagesize( $filePath ) === false ) {
554
-            return false ;
555
-        }
556
-
557
-        return true;
558
-    }
559
-
560
-    /**
561
-     * Returns true if directory is not empty
562
-     *
563
-     * @access public
564
-     * @static
565
-     * @param string $serverPath
566
-     * @return boolean
567
-     */
568
-    function hasChildren($serverPath)
569
-    {
570
-        if (!is_dir($serverPath) || (false === $fh = @opendir($serverPath))) {
571
-            return false;
572
-        }
573
-
574
-        $hasChildren = false;
575
-        while (false !== ($filename = readdir($fh))) {
576
-            if ($filename == '.' || $filename == '..') {
577
-                continue;
578
-            } else if (is_dir($serverPath . DIRECTORY_SEPARATOR . $filename)) {
579
-                //we have found valid directory
580
-                $hasChildren = true;
581
-                break;
582
-            }
583
-        }
584
-
585
-        closedir($fh);
586
-
587
-        return $hasChildren;
588
-    }
284
+			);
285
+		}
286
+		$str = str_replace(
287
+				array_keys($UTF8_UPPER_ACCENTS),
288
+				array_values($UTF8_UPPER_ACCENTS),
289
+				$str
290
+			);
291
+		return $str;
292
+	}
293
+
294
+	/**
295
+	 * Convert file name from UTF-8 to system encoding
296
+	 *
297
+	 * @static
298
+	 * @access public
299
+	 * @param string $fileName
300
+	 * @return string
301
+	 */
302
+	function convertToFilesystemEncoding($fileName)
303
+	{
304
+		$_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
305
+		$encoding = $_config->getFilesystemEncoding();
306
+		if (is_null($encoding) || strcasecmp($encoding, "UTF-8") == 0 || strcasecmp($encoding, "UTF8") == 0) {
307
+			return $fileName;
308
+		}
309
+
310
+		if (!function_exists("iconv")) {
311
+			if (strcasecmp($encoding, "ISO-8859-1") == 0 || strcasecmp($encoding, "ISO8859-1") == 0 || strcasecmp($encoding, "Latin1") == 0) {
312
+				return str_replace("\0", "_", utf8_decode($fileName));
313
+			} else if (function_exists('mb_convert_encoding')) {
314
+
315
+				$encoded = @mb_convert_encoding($fileName, $encoding, 'UTF-8');
316
+				if (@mb_strlen($fileName, "UTF-8") != @mb_strlen($encoded, $encoding)) {
317
+					return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName));
318
+				}
319
+				else {
320
+					return str_replace("\0", "_", $encoded);
321
+				}
322
+			} else {
323
+				return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName));
324
+			}
325
+		}
326
+
327
+		$converted = @iconv("UTF-8", $encoding . "//IGNORE//TRANSLIT", $fileName);
328
+		if ($converted === false) {
329
+			return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName));
330
+		}
331
+
332
+		return $converted;
333
+	}
334
+
335
+	/**
336
+	 * Convert file name from system encoding into UTF-8
337
+	 *
338
+	 * @static
339
+	 * @access public
340
+	 * @param string $fileName
341
+	 * @return string
342
+	 */
343
+	function convertToConnectorEncoding($fileName)
344
+	{
345
+		$_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
346
+		$encoding = $_config->getFilesystemEncoding();
347
+		if (is_null($encoding) || strcasecmp($encoding, "UTF-8") == 0 || strcasecmp($encoding, "UTF8") == 0) {
348
+			return $fileName;
349
+		}
350
+
351
+		if (!function_exists("iconv")) {
352
+			if (strcasecmp($encoding, "ISO-8859-1") == 0 || strcasecmp($encoding, "ISO8859-1") == 0 || strcasecmp($encoding, "Latin1") == 0) {
353
+				return utf8_encode($fileName);
354
+			} else {
355
+				return $fileName;
356
+			}
357
+		}
358
+
359
+		$converted = @iconv($encoding, "UTF-8", $fileName);
360
+
361
+		if ($converted === false) {
362
+			return $fileName;
363
+		}
364
+
365
+		return $converted;
366
+	}
367
+
368
+	/**
369
+	 * Find document root
370
+	 *
371
+	 * @return string
372
+	 * @access public
373
+	 */
374
+	function getDocumentRootPath()
375
+	{
376
+		/**
377
+		 * The absolute pathname of the currently executing script.
378
+		 * Notatka: If a script is executed with the CLI, as a relative path, such as file.php or ../file.php,
379
+		 * $_SERVER['SCRIPT_FILENAME'] will contain the relative path specified by the user.
380
+		 */
381
+		if (isset($_SERVER['SCRIPT_FILENAME'])) {
382
+			$sRealPath = dirname($_SERVER['SCRIPT_FILENAME']);
383
+		}
384
+		else {
385
+			/**
386
+			 * realpath — Returns canonicalized absolute pathname
387
+			 */
388
+			$sRealPath = realpath( './' ) ;
389
+		}
390
+
391
+		/**
392
+		 * The filename of the currently executing script, relative to the document root.
393
+		 * For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar
394
+		 * would be /test.php/foo.bar.
395
+		 */
396
+		$sSelfPath = dirname($_SERVER['PHP_SELF']);
397
+
398
+		return substr($sRealPath, 0, strlen($sRealPath) - strlen($sSelfPath));
399
+	}
400
+
401
+	/**
402
+	 * Create directory recursively
403
+	 *
404
+	 * @static
405
+	 * @access public
406
+	 * @param string $dir
407
+	 * @param int $mode
408
+	 * @return boolean
409
+	 */
410
+	function createDirectoryRecursively($dir)
411
+	{
412
+		if (is_dir($dir)) {
413
+			return true;
414
+		}
415
+
416
+		//attempt to create directory
417
+		$_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
418
+		if ($perms = $_config->getChmodFolders()) {
419
+			$oldUmask = umask(0);
420
+			$bCreated = @mkdir($dir, $perms);
421
+			umask($oldUmask);
422
+		}
423
+		else {
424
+			$bCreated = @mkdir($dir);
425
+		}
426
+
427
+		if ($bCreated) {
428
+			return true;
429
+		}
430
+
431
+		//failed to create directory, perhaps we need to create parent directories first
432
+		if (!CKFinder_Connector_Utils_FileSystem::createDirectoryRecursively(dirname($dir))) {
433
+			return false;
434
+		}
435
+
436
+		//parent directories created successfully, let's try to create directory once again
437
+		if ($perms) {
438
+			$old_umask = umask(0);
439
+			$result = @mkdir($dir, $perms);
440
+			umask($old_umask);
441
+		}
442
+		else {
443
+			$result = @mkdir($dir);
444
+		}
445
+
446
+		return $result;
447
+	}
448
+
449
+	/**
450
+	 * Detect HTML in the first KB to prevent against potential security issue with
451
+	 * IE/Safari/Opera file type auto detection bug.
452
+	 * Returns true if file contain insecure HTML code at the beginning.
453
+	 *
454
+	 * @static
455
+	 * @access public
456
+	 * @param string $filePath absolute path to file
457
+	 * @return boolean
458
+	 */
459
+	function detectHtml($filePath)
460
+	{
461
+		$fp = @fopen($filePath, 'rb');
462
+		if ( $fp === false || !flock( $fp, LOCK_SH ) ) {
463
+			return -1 ;
464
+		}
465
+		$chunk = fread($fp, 1024);
466
+		flock( $fp, LOCK_UN ) ;
467
+		fclose($fp);
468
+
469
+		$chunk = strtolower($chunk);
470
+
471
+		if (!$chunk) {
472
+			return false;
473
+		}
474
+
475
+		$chunk = trim($chunk);
476
+
477
+		if (preg_match("/<!DOCTYPE\W*X?HTML/sim", $chunk)) {
478
+			return true;
479
+		}
480
+
481
+		$tags = array('<body', '<head', '<html', '<img', '<pre', '<script', '<table', '<title');
482
+
483
+		foreach( $tags as $tag ) {
484
+			if(false !== strpos($chunk, $tag)) {
485
+				return true ;
486
+			}
487
+		}
488
+
489
+		//type = javascript
490
+		if (preg_match('!type\s*=\s*[\'"]?\s*(?:\w*/)?(?:ecma|java)!sim', $chunk)) {
491
+			return true ;
492
+		}
493
+
494
+		//href = javascript
495
+		//src = javascript
496
+		//data = javascript
497
+		if (preg_match('!(?:href|src|data)\s*=\s*[\'"]?\s*(?:ecma|java)script:!sim',$chunk)) {
498
+			return true ;
499
+		}
500
+
501
+		//url(javascript
502
+		if (preg_match('!url\s*\(\s*[\'"]?\s*(?:ecma|java)script:!sim', $chunk)) {
503
+			return true ;
504
+		}
505
+
506
+		return false ;
507
+	}
508
+
509
+	/**
510
+	 * Check file content.
511
+	 * Currently this function validates only image files.
512
+	 * Returns false if file is invalid.
513
+	 *
514
+	 * @static
515
+	 * @access public
516
+	 * @param string $filePath absolute path to file
517
+	 * @param string $extension file extension
518
+	 * @param integer $detectionLevel 0 = none, 1 = use getimagesize for images, 2 = use DetectHtml for images
519
+	 * @return boolean
520
+	 */
521
+	function isImageValid($filePath, $extension)
522
+	{
523
+		if (!@is_readable($filePath)) {
524
+			return -1;
525
+		}
526
+
527
+		$imageCheckExtensions = array('gif', 'jpeg', 'jpg', 'png', 'psd', 'bmp', 'tiff');
528
+
529
+		// version_compare is available since PHP4 >= 4.0.7
530
+		if ( function_exists( 'version_compare' ) ) {
531
+			$sCurrentVersion = phpversion();
532
+			if ( version_compare( $sCurrentVersion, "4.2.0" ) >= 0 ) {
533
+				$imageCheckExtensions[] = "tiff";
534
+				$imageCheckExtensions[] = "tif";
535
+			}
536
+			if ( version_compare( $sCurrentVersion, "4.3.0" ) >= 0 ) {
537
+				$imageCheckExtensions[] = "swc";
538
+			}
539
+			if ( version_compare( $sCurrentVersion, "4.3.2" ) >= 0 ) {
540
+				$imageCheckExtensions[] = "jpc";
541
+				$imageCheckExtensions[] = "jp2";
542
+				$imageCheckExtensions[] = "jpx";
543
+				$imageCheckExtensions[] = "jb2";
544
+				$imageCheckExtensions[] = "xbm";
545
+				$imageCheckExtensions[] = "wbmp";
546
+			}
547
+		}
548
+
549
+		if ( !in_array( $extension, $imageCheckExtensions ) ) {
550
+			return true;
551
+		}
552
+
553
+		if ( @getimagesize( $filePath ) === false ) {
554
+			return false ;
555
+		}
556
+
557
+		return true;
558
+	}
559
+
560
+	/**
561
+	 * Returns true if directory is not empty
562
+	 *
563
+	 * @access public
564
+	 * @static
565
+	 * @param string $serverPath
566
+	 * @return boolean
567
+	 */
568
+	function hasChildren($serverPath)
569
+	{
570
+		if (!is_dir($serverPath) || (false === $fh = @opendir($serverPath))) {
571
+			return false;
572
+		}
573
+
574
+		$hasChildren = false;
575
+		while (false !== ($filename = readdir($fh))) {
576
+			if ($filename == '.' || $filename == '..') {
577
+				continue;
578
+			} else if (is_dir($serverPath . DIRECTORY_SEPARATOR . $filename)) {
579
+				//we have found valid directory
580
+				$hasChildren = true;
581
+				break;
582
+			}
583
+		}
584
+
585
+		closedir($fh);
586
+
587
+		return $hasChildren;
588
+	}
589 589
 }
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -37,10 +37,10 @@  discard block
 block discarded – undo
37 37
      */
38 38
     function combinePaths($path1, $path2)
39 39
     {
40
-        if (is_null($path1))  {
40
+        if (is_null($path1)) {
41 41
             $path1 = "";
42 42
         }
43
-        if (is_null($path2))  {
43
+        if (is_null($path2)) {
44 44
             $path2 = "";
45 45
         }
46 46
         if (!strlen($path2)) {
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
         else {
55 55
             $_firstCharP2 = substr($path2, 0, 1);
56 56
             if (strlen($path1)) {
57
-                if (strpos($path2, $path1)===0) {
57
+                if (strpos($path2, $path1) === 0) {
58 58
                     return $path2;
59 59
                 }
60 60
                 $_lastCharP1 = substr($path1, -1, 1);
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
                 return $path2;
67 67
             }
68 68
         }
69
-        return $path1 . $path2;
69
+        return $path1.$path2;
70 70
     }
71 71
 
72 72
     /**
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
      */
80 80
     function checkFileName($fileName)
81 81
     {
82
-        if (is_null($fileName) || !strlen($fileName) || substr($fileName,-1,1)=="." || false!==strpos($fileName, "..")) {
82
+        if (is_null($fileName) || !strlen($fileName) || substr($fileName, -1, 1) == "." || false !== strpos($fileName, "..")) {
83 83
             return false;
84 84
         }
85 85
 
@@ -101,30 +101,30 @@  discard block
 block discarded – undo
101 101
     function unlink($path)
102 102
     {
103 103
         /*    make sure the path exists    */
104
-        if(!file_exists($path)) {
104
+        if (!file_exists($path)) {
105 105
             return false;
106 106
         }
107 107
 
108 108
         /*    If it is a file or link, just delete it    */
109
-        if(is_file($path) || is_link($path)) {
109
+        if (is_file($path) || is_link($path)) {
110 110
             return @unlink($path);
111 111
         }
112 112
 
113 113
         /*    Scan the dir and recursively unlink    */
114 114
         $files = CKFinder_Connector_Utils_FileSystem::php4_scandir($path);
115 115
         if ($files) {
116
-            foreach($files as $filename)
116
+            foreach ($files as $filename)
117 117
             {
118 118
                 if ($filename == '.' || $filename == '..') {
119 119
                     continue;
120 120
                 }
121
-                $file = str_replace('//','/',$path.'/'.$filename);
121
+                $file = str_replace('//', '/', $path.'/'.$filename);
122 122
                 CKFinder_Connector_Utils_FileSystem::unlink($file);
123 123
             }
124 124
         }
125 125
 
126 126
         /*    Remove the parent dir    */
127
-        if(!@rmdir($path)) {
127
+        if (!@rmdir($path)) {
128 128
             return false;
129 129
         }
130 130
 
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
             return false;
144 144
         }
145 145
 
146
-        $files = array ();
146
+        $files = array();
147 147
         while (false !== ($filename = readdir($fh))) {
148 148
             $files[] = $filename;
149 149
         }
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
      */
164 164
     function getFileNameWithoutExtension($fileName)
165 165
     {
166
-        $dotPos = strrpos( $fileName, '.' );
166
+        $dotPos = strrpos($fileName, '.');
167 167
         if (false === $dotPos) {
168 168
             return $fileName;
169 169
         }
@@ -179,14 +179,14 @@  discard block
 block discarded – undo
179 179
      * @param string $fileName
180 180
      * @return string
181 181
      */
182
-    function getExtension( $fileName )
182
+    function getExtension($fileName)
183 183
     {
184
-        $dotPos = strrpos( $fileName, '.' );
184
+        $dotPos = strrpos($fileName, '.');
185 185
         if (false === $dotPos) {
186 186
             return "";
187 187
         }
188 188
 
189
-        return substr( $fileName, strrpos( $fileName, '.' ) +1 ) ;
189
+        return substr($fileName, strrpos($fileName, '.') + 1);
190 190
     }
191 191
 
192 192
     /**
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
         static $UTF8_LOWER_ACCENTS = NULL;
239 239
         static $UTF8_UPPER_ACCENTS = NULL;
240 240
 
241
-        if ( is_null($UTF8_LOWER_ACCENTS) ) {
241
+        if (is_null($UTF8_LOWER_ACCENTS)) {
242 242
             $UTF8_LOWER_ACCENTS = array(
243 243
   'à' => 'a', 'ô' => 'o', 'ď' => 'd', 'ḟ' => 'f', 'ë' => 'e', 'š' => 's', 'ơ' => 'o',
244 244
   'ß' => 'ss', 'ă' => 'a', 'ř' => 'r', 'ț' => 't', 'ň' => 'n', 'ā' => 'a', 'ķ' => 'k',
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
                 $str
265 265
             );
266 266
 
267
-        if ( is_null($UTF8_UPPER_ACCENTS) ) {
267
+        if (is_null($UTF8_UPPER_ACCENTS)) {
268 268
             $UTF8_UPPER_ACCENTS = array(
269 269
   'À' => 'A', 'Ô' => 'O', 'Ď' => 'D', 'Ḟ' => 'F', 'Ë' => 'E', 'Š' => 'S', 'Ơ' => 'O',
270 270
   'Ă' => 'A', 'Ř' => 'R', 'Ț' => 'T', 'Ň' => 'N', 'Ā' => 'A', 'Ķ' => 'K',
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
      */
302 302
     function convertToFilesystemEncoding($fileName)
303 303
     {
304
-        $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
304
+        $_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config");
305 305
         $encoding = $_config->getFilesystemEncoding();
306 306
         if (is_null($encoding) || strcasecmp($encoding, "UTF-8") == 0 || strcasecmp($encoding, "UTF8") == 0) {
307 307
             return $fileName;
@@ -314,19 +314,19 @@  discard block
 block discarded – undo
314 314
 
315 315
                 $encoded = @mb_convert_encoding($fileName, $encoding, 'UTF-8');
316 316
                 if (@mb_strlen($fileName, "UTF-8") != @mb_strlen($encoded, $encoding)) {
317
-                    return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName));
317
+                    return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u", "_", $fileName));
318 318
                 }
319 319
                 else {
320 320
                     return str_replace("\0", "_", $encoded);
321 321
                 }
322 322
             } else {
323
-                return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName));
323
+                return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u", "_", $fileName));
324 324
             }
325 325
         }
326 326
 
327
-        $converted = @iconv("UTF-8", $encoding . "//IGNORE//TRANSLIT", $fileName);
327
+        $converted = @iconv("UTF-8", $encoding."//IGNORE//TRANSLIT", $fileName);
328 328
         if ($converted === false) {
329
-            return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName));
329
+            return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u", "_", $fileName));
330 330
         }
331 331
 
332 332
         return $converted;
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
      */
343 343
     function convertToConnectorEncoding($fileName)
344 344
     {
345
-        $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
345
+        $_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config");
346 346
         $encoding = $_config->getFilesystemEncoding();
347 347
         if (is_null($encoding) || strcasecmp($encoding, "UTF-8") == 0 || strcasecmp($encoding, "UTF8") == 0) {
348 348
             return $fileName;
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
             /**
386 386
              * realpath — Returns canonicalized absolute pathname
387 387
              */
388
-            $sRealPath = realpath( './' ) ;
388
+            $sRealPath = realpath('./');
389 389
         }
390 390
 
391 391
         /**
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
         }
415 415
 
416 416
         //attempt to create directory
417
-        $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
417
+        $_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config");
418 418
         if ($perms = $_config->getChmodFolders()) {
419 419
             $oldUmask = umask(0);
420 420
             $bCreated = @mkdir($dir, $perms);
@@ -459,11 +459,11 @@  discard block
 block discarded – undo
459 459
     function detectHtml($filePath)
460 460
     {
461 461
         $fp = @fopen($filePath, 'rb');
462
-        if ( $fp === false || !flock( $fp, LOCK_SH ) ) {
463
-            return -1 ;
462
+        if ($fp === false || !flock($fp, LOCK_SH)) {
463
+            return -1;
464 464
         }
465 465
         $chunk = fread($fp, 1024);
466
-        flock( $fp, LOCK_UN ) ;
466
+        flock($fp, LOCK_UN);
467 467
         fclose($fp);
468 468
 
469 469
         $chunk = strtolower($chunk);
@@ -480,30 +480,30 @@  discard block
 block discarded – undo
480 480
 
481 481
         $tags = array('<body', '<head', '<html', '<img', '<pre', '<script', '<table', '<title');
482 482
 
483
-        foreach( $tags as $tag ) {
484
-            if(false !== strpos($chunk, $tag)) {
485
-                return true ;
483
+        foreach ($tags as $tag) {
484
+            if (false !== strpos($chunk, $tag)) {
485
+                return true;
486 486
             }
487 487
         }
488 488
 
489 489
         //type = javascript
490 490
         if (preg_match('!type\s*=\s*[\'"]?\s*(?:\w*/)?(?:ecma|java)!sim', $chunk)) {
491
-            return true ;
491
+            return true;
492 492
         }
493 493
 
494 494
         //href = javascript
495 495
         //src = javascript
496 496
         //data = javascript
497
-        if (preg_match('!(?:href|src|data)\s*=\s*[\'"]?\s*(?:ecma|java)script:!sim',$chunk)) {
498
-            return true ;
497
+        if (preg_match('!(?:href|src|data)\s*=\s*[\'"]?\s*(?:ecma|java)script:!sim', $chunk)) {
498
+            return true;
499 499
         }
500 500
 
501 501
         //url(javascript
502 502
         if (preg_match('!url\s*\(\s*[\'"]?\s*(?:ecma|java)script:!sim', $chunk)) {
503
-            return true ;
503
+            return true;
504 504
         }
505 505
 
506
-        return false ;
506
+        return false;
507 507
     }
508 508
 
509 509
     /**
@@ -527,16 +527,16 @@  discard block
 block discarded – undo
527 527
         $imageCheckExtensions = array('gif', 'jpeg', 'jpg', 'png', 'psd', 'bmp', 'tiff');
528 528
 
529 529
         // version_compare is available since PHP4 >= 4.0.7
530
-        if ( function_exists( 'version_compare' ) ) {
530
+        if (function_exists('version_compare')) {
531 531
             $sCurrentVersion = phpversion();
532
-            if ( version_compare( $sCurrentVersion, "4.2.0" ) >= 0 ) {
532
+            if (version_compare($sCurrentVersion, "4.2.0") >= 0) {
533 533
                 $imageCheckExtensions[] = "tiff";
534 534
                 $imageCheckExtensions[] = "tif";
535 535
             }
536
-            if ( version_compare( $sCurrentVersion, "4.3.0" ) >= 0 ) {
536
+            if (version_compare($sCurrentVersion, "4.3.0") >= 0) {
537 537
                 $imageCheckExtensions[] = "swc";
538 538
             }
539
-            if ( version_compare( $sCurrentVersion, "4.3.2" ) >= 0 ) {
539
+            if (version_compare($sCurrentVersion, "4.3.2") >= 0) {
540 540
                 $imageCheckExtensions[] = "jpc";
541 541
                 $imageCheckExtensions[] = "jp2";
542 542
                 $imageCheckExtensions[] = "jpx";
@@ -546,12 +546,12 @@  discard block
 block discarded – undo
546 546
             }
547 547
         }
548 548
 
549
-        if ( !in_array( $extension, $imageCheckExtensions ) ) {
549
+        if (!in_array($extension, $imageCheckExtensions)) {
550 550
             return true;
551 551
         }
552 552
 
553
-        if ( @getimagesize( $filePath ) === false ) {
554
-            return false ;
553
+        if (@getimagesize($filePath) === false) {
554
+            return false;
555 555
         }
556 556
 
557 557
         return true;
@@ -575,7 +575,7 @@  discard block
 block discarded – undo
575 575
         while (false !== ($filename = readdir($fh))) {
576 576
             if ($filename == '.' || $filename == '..') {
577 577
                 continue;
578
-            } else if (is_dir($serverPath . DIRECTORY_SEPARATOR . $filename)) {
578
+            } else if (is_dir($serverPath.DIRECTORY_SEPARATOR.$filename)) {
579 579
                 //we have found valid directory
580 580
                 $hasChildren = true;
581 581
                 break;
Please login to merge, or discard this patch.
Braces   +9 added lines, -13 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@  discard block
 block discarded – undo
10 10
 * modifying or distribute this file or part of its contents. The contents of
11 11
 * this file is part of the Source Code of CKFinder.
12 12
 */
13
-if (!defined('IN_CKFINDER')) exit;
13
+if (!defined('IN_CKFINDER')) {
14
+	exit;
15
+}
14 16
 
15 17
 /**
16 18
  * @package CKFinder
@@ -50,8 +52,7 @@  discard block
 block discarded – undo
50 52
                     $path1 .= DIRECTORY_SEPARATOR;
51 53
                 }
52 54
             }
53
-        }
54
-        else {
55
+        } else {
55 56
             $_firstCharP2 = substr($path2, 0, 1);
56 57
             if (strlen($path1)) {
57 58
                 if (strpos($path2, $path1)===0) {
@@ -61,8 +62,7 @@  discard block
 block discarded – undo
61 62
                 if ($_lastCharP1 != "/" && $_lastCharP1 != "\\" && $_firstCharP2 != "/" && $_firstCharP2 != "\\") {
62 63
                     $path1 .= DIRECTORY_SEPARATOR;
63 64
                 }
64
-            }
65
-            else {
65
+            } else {
66 66
                 return $path2;
67 67
             }
68 68
         }
@@ -315,8 +315,7 @@  discard block
 block discarded – undo
315 315
                 $encoded = @mb_convert_encoding($fileName, $encoding, 'UTF-8');
316 316
                 if (@mb_strlen($fileName, "UTF-8") != @mb_strlen($encoded, $encoding)) {
317 317
                     return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName));
318
-                }
319
-                else {
318
+                } else {
320 319
                     return str_replace("\0", "_", $encoded);
321 320
                 }
322 321
             } else {
@@ -380,8 +379,7 @@  discard block
 block discarded – undo
380 379
          */
381 380
         if (isset($_SERVER['SCRIPT_FILENAME'])) {
382 381
             $sRealPath = dirname($_SERVER['SCRIPT_FILENAME']);
383
-        }
384
-        else {
382
+        } else {
385 383
             /**
386 384
              * realpath — Returns canonicalized absolute pathname
387 385
              */
@@ -419,8 +417,7 @@  discard block
 block discarded – undo
419 417
             $oldUmask = umask(0);
420 418
             $bCreated = @mkdir($dir, $perms);
421 419
             umask($oldUmask);
422
-        }
423
-        else {
420
+        } else {
424 421
             $bCreated = @mkdir($dir);
425 422
         }
426 423
 
@@ -438,8 +435,7 @@  discard block
 block discarded – undo
438 435
             $old_umask = umask(0);
439 436
             $result = @mkdir($dir, $perms);
440 437
             umask($old_umask);
441
-        }
442
-        else {
438
+        } else {
443 439
             $result = @mkdir($dir);
444 440
         }
445 441
 
Please login to merge, or discard this patch.
libs/ckfinder/core/connector/php/php4/Utils/Misc.php 4 patches
Doc Comments   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -25,6 +25,9 @@  discard block
 block discarded – undo
25 25
  */
26 26
 class CKFinder_Connector_Utils_Misc
27 27
 {
28
+    /**
29
+     * @param integer $number
30
+     */
28 31
     function getErrorMessage($number, $arg = "") {
29 32
         $langCode = 'en';
30 33
         if (!empty($_GET['langCode']) && preg_match("/^[a-z\-]+$/", $_GET['langCode'])) {
@@ -113,7 +116,6 @@  discard block
 block discarded – undo
113 116
      *
114 117
      * @static
115 118
      * @access public
116
-     * @param string $filename
117 119
      * @return boolean
118 120
      */
119 121
     function setMemoryForImage($imageWidth, $imageHeight, $imageBits, $imageChannels)
Please login to merge, or discard this patch.
Indentation   +341 added lines, -341 removed lines patch added patch discarded remove patch
@@ -25,345 +25,345 @@
 block discarded – undo
25 25
  */
26 26
 class CKFinder_Connector_Utils_Misc
27 27
 {
28
-    function getErrorMessage($number, $arg = "") {
29
-        $langCode = 'en';
30
-        if (!empty($_GET['langCode']) && preg_match("/^[a-z\-]+$/", $_GET['langCode'])) {
31
-            if (file_exists(CKFINDER_CONNECTOR_LANG_PATH . "/" . $_GET['langCode'] . ".php"))
32
-                $langCode = $_GET['langCode'];
33
-        }
34
-        include CKFINDER_CONNECTOR_LANG_PATH . "/" . $langCode . ".php";
35
-        if ($number) {
36
-            if (!empty ($GLOBALS['CKFLang']['Errors'][$number])) {
37
-                $errorMessage = str_replace("%1", $arg, $GLOBALS['CKFLang']['Errors'][$number]);
38
-            } else {
39
-                $errorMessage = str_replace("%1", $number, $GLOBALS['CKFLang']['ErrorUnknown']);
40
-            }
41
-        } else {
42
-            $errorMessage = "";
43
-        }
44
-        return $errorMessage;
45
-    }
46
-
47
-    /**
48
-     * Convert any value to boolean, strings like "false", "FalSE" and "off" are also considered as false
49
-     *
50
-     * @static
51
-     * @access public
52
-     * @param mixed $value
53
-     * @return boolean
54
-     */
55
-    function booleanValue($value)
56
-    {
57
-        if (strcasecmp("false", $value) == 0 || strcasecmp("off", $value) == 0 || !$value) {
58
-            return false;
59
-        } else {
60
-            return true;
61
-        }
62
-    }
63
-
64
-    /**
65
-     * @link http://pl.php.net/manual/en/function.imagecopyresampled.php
66
-     * replacement to imagecopyresampled that will deliver results that are almost identical except MUCH faster (very typically 30 times faster)
67
-     *
68
-     * @static
69
-     * @access public
70
-     * @param string $dst_image
71
-     * @param string $src_image
72
-     * @param int $dst_x
73
-     * @param int $dst_y
74
-     * @param int $src_x
75
-     * @param int $src_y
76
-     * @param int $dst_w
77
-     * @param int $dst_h
78
-     * @param int $src_w
79
-     * @param int $src_h
80
-     * @param int $quality
81
-     * @return boolean
82
-     */
83
-    function fastImageCopyResampled (&$dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $quality = 3)
84
-    {
85
-        if (empty($src_image) || empty($dst_image)) {
86
-            return false;
87
-        }
88
-
89
-        if ($quality <= 1) {
90
-            $temp = imagecreatetruecolor ($dst_w + 1, $dst_h + 1);
91
-            imagecopyresized ($temp, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w + 1, $dst_h + 1, $src_w, $src_h);
92
-            imagecopyresized ($dst_image, $temp, 0, 0, 0, 0, $dst_w, $dst_h, $dst_w, $dst_h);
93
-            imagedestroy ($temp);
94
-
95
-        } elseif ($quality < 5 && (($dst_w * $quality) < $src_w || ($dst_h * $quality) < $src_h)) {
96
-            $tmp_w = $dst_w * $quality;
97
-            $tmp_h = $dst_h * $quality;
98
-            $temp = imagecreatetruecolor ($tmp_w + 1, $tmp_h + 1);
99
-            imagecopyresized ($temp, $src_image, 0, 0, $src_x, $src_y, $tmp_w + 1, $tmp_h + 1, $src_w, $src_h);
100
-            imagecopyresampled ($dst_image, $temp, $dst_x, $dst_y, 0, 0, $dst_w, $dst_h, $tmp_w, $tmp_h);
101
-            imagedestroy ($temp);
102
-
103
-        } else {
104
-            imagecopyresampled ($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
105
-        }
106
-
107
-        return true;
108
-    }
109
-
110
-    /**
111
-     * @link http://pl.php.net/manual/pl/function.imagecreatefromjpeg.php
112
-     * function posted by e dot a dot schultz at gmail dot com
113
-     *
114
-     * @static
115
-     * @access public
116
-     * @param string $filename
117
-     * @return boolean
118
-     */
119
-    function setMemoryForImage($imageWidth, $imageHeight, $imageBits, $imageChannels)
120
-    {
121
-        $MB = 1048576;  // number of bytes in 1M
122
-        $K64 = 65536;    // number of bytes in 64K
123
-        $TWEAKFACTOR = 2.4;  // Or whatever works for you
124
-        $memoryNeeded = round( ( $imageWidth * $imageHeight
125
-        * $imageBits
126
-        * $imageChannels / 8
127
-        + $K64
128
-        ) * $TWEAKFACTOR
129
-        ) + 3*$MB;
130
-
131
-        //ini_get('memory_limit') only works if compiled with "--enable-memory-limit" also
132
-        //Default memory limit is 8MB so well stick with that.
133
-        //To find out what yours is, view your php.ini file.
134
-        $memoryLimit = CKFinder_Connector_Utils_Misc::returnBytes(@ini_get('memory_limit'))/$MB;
135
-        if (!$memoryLimit) {
136
-            $memoryLimit = 8;
137
-        }
138
-
139
-        $memoryLimitMB = $memoryLimit * $MB;
140
-        if (function_exists('memory_get_usage')) {
141
-            if (memory_get_usage() + $memoryNeeded > $memoryLimitMB) {
142
-                $newLimit = $memoryLimit + ceil( ( memory_get_usage()
143
-                + $memoryNeeded
144
-                - $memoryLimitMB
145
-                ) / $MB
146
-                );
147
-                if (@ini_set( 'memory_limit', $newLimit . 'M' ) === false) {
148
-                    return false;
149
-                }
150
-            }
151
-        } else {
152
-            if ($memoryNeeded + 3*$MB > $memoryLimitMB) {
153
-                $newLimit = $memoryLimit + ceil(( 3*$MB
154
-                + $memoryNeeded
155
-                - $memoryLimitMB
156
-                ) / $MB
157
-                );
158
-                if (false === @ini_set( 'memory_limit', $newLimit . 'M' )) {
159
-                    return false;
160
-                }
161
-            }
162
-        }
163
-        return true;
164
-    }
165
-
166
-    /**
167
-     * convert shorthand php.ini notation into bytes, much like how the PHP source does it
168
-     * @link http://pl.php.net/manual/en/function.ini-get.php
169
-     *
170
-     * @static
171
-     * @access public
172
-     * @param string $val
173
-     * @return int
174
-     */
175
-    function returnBytes($val)
176
-    {
177
-        $val = trim($val);
178
-        if (!$val) {
179
-            return 0;
180
-        }
181
-        $last = strtolower($val[strlen($val)-1]);
182
-        switch($last) {
183
-            // The 'G' modifier is available since PHP 5.1.0
184
-            case 'g':
185
-                $val *= 1024;
186
-            case 'm':
187
-                $val *= 1024;
188
-            case 'k':
189
-                $val *= 1024;
190
-        }
191
-
192
-        return $val;
193
-    }
194
-
195
-    /**
196
-    * Checks if a value exists in an array (case insensitive)
197
-    *
198
-    * @static
199
-    * @access public
200
-    * @param string $needle
201
-    * @param array $haystack
202
-    * @return boolean
203
-    */
204
-    function inArrayCaseInsensitive($needle, $haystack)
205
-    {
206
-        if (!$haystack || !is_array($haystack)) {
207
-            return false;
208
-        }
209
-        $lcase = array();
210
-        foreach ($haystack as $key => $val) {
211
-            $lcase[$key] = strtolower($val);
212
-        }
213
-        return in_array($needle, $lcase);
214
-    }
215
-
216
-    /**
217
-    * UTF-8 compatible version of basename()
218
-    *
219
-    * @static
220
-    * @access public
221
-    * @param string $file
222
-    * @return string
223
-    */
224
-    function mbBasename($file)
225
-    {
226
-        $explode = explode('/', str_replace("\\", "/", $file));
227
-        return end($explode);
228
-    }
229
-
230
-    /**
231
-    * Source: http://pl.php.net/imagecreate
232
-    * (optimized for speed and memory usage, but yet not very efficient)
233
-    *
234
-    * @static
235
-    * @access public
236
-    * @param string $filename
237
-    * @return resource
238
-    */
239
-    function imageCreateFromBmp($filename)
240
-    {
241
-        //20 seconds seems to be a reasonable value to not kill a server and process images up to 1680x1050
242
-        @set_time_limit(20);
243
-
244
-        if (false === ($f1 = fopen($filename, "rb"))) {
245
-            return false;
246
-        }
247
-
248
-        $FILE = unpack("vfile_type/Vfile_size/Vreserved/Vbitmap_offset", fread($f1, 14));
249
-        if ($FILE['file_type'] != 19778) {
250
-            return false;
251
-        }
252
-
253
-        $BMP = unpack('Vheader_size/Vwidth/Vheight/vplanes/vbits_per_pixel'.
254
-        '/Vcompression/Vsize_bitmap/Vhoriz_resolution'.
255
-        '/Vvert_resolution/Vcolors_used/Vcolors_important', fread($f1, 40));
256
-
257
-        $BMP['colors'] = pow(2,$BMP['bits_per_pixel']);
258
-
259
-        if ($BMP['size_bitmap'] == 0) {
260
-            $BMP['size_bitmap'] = $FILE['file_size'] - $FILE['bitmap_offset'];
261
-        }
262
-
263
-        $BMP['bytes_per_pixel'] = $BMP['bits_per_pixel']/8;
264
-        $BMP['bytes_per_pixel2'] = ceil($BMP['bytes_per_pixel']);
265
-        $BMP['decal'] = ($BMP['width']*$BMP['bytes_per_pixel']/4);
266
-        $BMP['decal'] -= floor($BMP['width']*$BMP['bytes_per_pixel']/4);
267
-        $BMP['decal'] = 4-(4*$BMP['decal']);
268
-
269
-        if ($BMP['decal'] == 4) {
270
-            $BMP['decal'] = 0;
271
-        }
272
-
273
-        $PALETTE = array();
274
-        if ($BMP['colors'] < 16777216) {
275
-            $PALETTE = unpack('V'.$BMP['colors'], fread($f1, $BMP['colors']*4));
276
-        }
277
-
278
-        //2048x1536px@24bit don't even try to process larger files as it will probably fail
279
-        if ($BMP['size_bitmap'] > 3 * 2048 * 1536) {
280
-            return false;
281
-        }
282
-
283
-        $IMG = fread($f1, $BMP['size_bitmap']);
284
-        fclose($f1);
285
-        $VIDE = chr(0);
286
-
287
-        $res = imagecreatetruecolor($BMP['width'],$BMP['height']);
288
-        $P = 0;
289
-        $Y = $BMP['height']-1;
290
-
291
-        $line_length = $BMP['bytes_per_pixel']*$BMP['width'];
292
-
293
-        if ($BMP['bits_per_pixel'] == 24) {
294
-            while ($Y >= 0)
295
-            {
296
-                $X=0;
297
-                $temp = unpack( "C*", substr($IMG, $P, $line_length));
298
-
299
-                while ($X < $BMP['width'])
300
-                {
301
-                    $offset = $X*3;
302
-                    imagesetpixel($res, $X++, $Y, ($temp[$offset+3] << 16) + ($temp[$offset+2] << 8) + $temp[$offset+1]);
303
-                }
304
-                $Y--;
305
-                $P += $line_length + $BMP['decal'];
306
-            }
307
-        }
308
-        elseif ($BMP['bits_per_pixel'] == 8)
309
-        {
310
-            while ($Y >= 0)
311
-            {
312
-                $X=0;
313
-
314
-                $temp = unpack( "C*", substr($IMG, $P, $line_length));
315
-
316
-                while ($X < $BMP['width'])
317
-                {
318
-                    imagesetpixel($res, $X++, $Y, $PALETTE[$temp[$X] +1]);
319
-                }
320
-                $Y--;
321
-                $P += $line_length + $BMP['decal'];
322
-            }
323
-        }
324
-        elseif ($BMP['bits_per_pixel'] == 4)
325
-        {
326
-            while ($Y >= 0)
327
-            {
328
-                $X=0;
329
-                $i = 1;
330
-                $low = true;
331
-
332
-                $temp = unpack( "C*", substr($IMG, $P, $line_length));
333
-
334
-                while ($X < $BMP['width'])
335
-                {
336
-                    if ($low) {
337
-                        $index = $temp[$i] >> 4;
338
-                    }
339
-                    else {
340
-                        $index = $temp[$i++] & 0x0F;
341
-                    }
342
-                    $low = !$low;
343
-
344
-                    imagesetpixel($res, $X++, $Y, $PALETTE[$index +1]);
345
-                }
346
-                $Y--;
347
-                $P += $line_length + $BMP['decal'];
348
-            }
349
-        }
350
-        elseif ($BMP['bits_per_pixel'] == 1)
351
-        {
352
-            $COLOR = unpack("n",$VIDE.substr($IMG,floor($P),1));
353
-            if     (($P*8)%8 == 0) $COLOR[1] =  $COLOR[1]        >>7;
354
-            elseif (($P*8)%8 == 1) $COLOR[1] = ($COLOR[1] & 0x40)>>6;
355
-            elseif (($P*8)%8 == 2) $COLOR[1] = ($COLOR[1] & 0x20)>>5;
356
-            elseif (($P*8)%8 == 3) $COLOR[1] = ($COLOR[1] & 0x10)>>4;
357
-            elseif (($P*8)%8 == 4) $COLOR[1] = ($COLOR[1] & 0x8)>>3;
358
-            elseif (($P*8)%8 == 5) $COLOR[1] = ($COLOR[1] & 0x4)>>2;
359
-            elseif (($P*8)%8 == 6) $COLOR[1] = ($COLOR[1] & 0x2)>>1;
360
-            elseif (($P*8)%8 == 7) $COLOR[1] = ($COLOR[1] & 0x1);
361
-            $COLOR[1] = $PALETTE[$COLOR[1]+1];
362
-        }
363
-        else {
364
-            return false;
365
-        }
366
-
367
-        return $res;
368
-    }
28
+	function getErrorMessage($number, $arg = "") {
29
+		$langCode = 'en';
30
+		if (!empty($_GET['langCode']) && preg_match("/^[a-z\-]+$/", $_GET['langCode'])) {
31
+			if (file_exists(CKFINDER_CONNECTOR_LANG_PATH . "/" . $_GET['langCode'] . ".php"))
32
+				$langCode = $_GET['langCode'];
33
+		}
34
+		include CKFINDER_CONNECTOR_LANG_PATH . "/" . $langCode . ".php";
35
+		if ($number) {
36
+			if (!empty ($GLOBALS['CKFLang']['Errors'][$number])) {
37
+				$errorMessage = str_replace("%1", $arg, $GLOBALS['CKFLang']['Errors'][$number]);
38
+			} else {
39
+				$errorMessage = str_replace("%1", $number, $GLOBALS['CKFLang']['ErrorUnknown']);
40
+			}
41
+		} else {
42
+			$errorMessage = "";
43
+		}
44
+		return $errorMessage;
45
+	}
46
+
47
+	/**
48
+	 * Convert any value to boolean, strings like "false", "FalSE" and "off" are also considered as false
49
+	 *
50
+	 * @static
51
+	 * @access public
52
+	 * @param mixed $value
53
+	 * @return boolean
54
+	 */
55
+	function booleanValue($value)
56
+	{
57
+		if (strcasecmp("false", $value) == 0 || strcasecmp("off", $value) == 0 || !$value) {
58
+			return false;
59
+		} else {
60
+			return true;
61
+		}
62
+	}
63
+
64
+	/**
65
+	 * @link http://pl.php.net/manual/en/function.imagecopyresampled.php
66
+	 * replacement to imagecopyresampled that will deliver results that are almost identical except MUCH faster (very typically 30 times faster)
67
+	 *
68
+	 * @static
69
+	 * @access public
70
+	 * @param string $dst_image
71
+	 * @param string $src_image
72
+	 * @param int $dst_x
73
+	 * @param int $dst_y
74
+	 * @param int $src_x
75
+	 * @param int $src_y
76
+	 * @param int $dst_w
77
+	 * @param int $dst_h
78
+	 * @param int $src_w
79
+	 * @param int $src_h
80
+	 * @param int $quality
81
+	 * @return boolean
82
+	 */
83
+	function fastImageCopyResampled (&$dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $quality = 3)
84
+	{
85
+		if (empty($src_image) || empty($dst_image)) {
86
+			return false;
87
+		}
88
+
89
+		if ($quality <= 1) {
90
+			$temp = imagecreatetruecolor ($dst_w + 1, $dst_h + 1);
91
+			imagecopyresized ($temp, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w + 1, $dst_h + 1, $src_w, $src_h);
92
+			imagecopyresized ($dst_image, $temp, 0, 0, 0, 0, $dst_w, $dst_h, $dst_w, $dst_h);
93
+			imagedestroy ($temp);
94
+
95
+		} elseif ($quality < 5 && (($dst_w * $quality) < $src_w || ($dst_h * $quality) < $src_h)) {
96
+			$tmp_w = $dst_w * $quality;
97
+			$tmp_h = $dst_h * $quality;
98
+			$temp = imagecreatetruecolor ($tmp_w + 1, $tmp_h + 1);
99
+			imagecopyresized ($temp, $src_image, 0, 0, $src_x, $src_y, $tmp_w + 1, $tmp_h + 1, $src_w, $src_h);
100
+			imagecopyresampled ($dst_image, $temp, $dst_x, $dst_y, 0, 0, $dst_w, $dst_h, $tmp_w, $tmp_h);
101
+			imagedestroy ($temp);
102
+
103
+		} else {
104
+			imagecopyresampled ($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
105
+		}
106
+
107
+		return true;
108
+	}
109
+
110
+	/**
111
+	 * @link http://pl.php.net/manual/pl/function.imagecreatefromjpeg.php
112
+	 * function posted by e dot a dot schultz at gmail dot com
113
+	 *
114
+	 * @static
115
+	 * @access public
116
+	 * @param string $filename
117
+	 * @return boolean
118
+	 */
119
+	function setMemoryForImage($imageWidth, $imageHeight, $imageBits, $imageChannels)
120
+	{
121
+		$MB = 1048576;  // number of bytes in 1M
122
+		$K64 = 65536;    // number of bytes in 64K
123
+		$TWEAKFACTOR = 2.4;  // Or whatever works for you
124
+		$memoryNeeded = round( ( $imageWidth * $imageHeight
125
+		* $imageBits
126
+		* $imageChannels / 8
127
+		+ $K64
128
+		) * $TWEAKFACTOR
129
+		) + 3*$MB;
130
+
131
+		//ini_get('memory_limit') only works if compiled with "--enable-memory-limit" also
132
+		//Default memory limit is 8MB so well stick with that.
133
+		//To find out what yours is, view your php.ini file.
134
+		$memoryLimit = CKFinder_Connector_Utils_Misc::returnBytes(@ini_get('memory_limit'))/$MB;
135
+		if (!$memoryLimit) {
136
+			$memoryLimit = 8;
137
+		}
138
+
139
+		$memoryLimitMB = $memoryLimit * $MB;
140
+		if (function_exists('memory_get_usage')) {
141
+			if (memory_get_usage() + $memoryNeeded > $memoryLimitMB) {
142
+				$newLimit = $memoryLimit + ceil( ( memory_get_usage()
143
+				+ $memoryNeeded
144
+				- $memoryLimitMB
145
+				) / $MB
146
+				);
147
+				if (@ini_set( 'memory_limit', $newLimit . 'M' ) === false) {
148
+					return false;
149
+				}
150
+			}
151
+		} else {
152
+			if ($memoryNeeded + 3*$MB > $memoryLimitMB) {
153
+				$newLimit = $memoryLimit + ceil(( 3*$MB
154
+				+ $memoryNeeded
155
+				- $memoryLimitMB
156
+				) / $MB
157
+				);
158
+				if (false === @ini_set( 'memory_limit', $newLimit . 'M' )) {
159
+					return false;
160
+				}
161
+			}
162
+		}
163
+		return true;
164
+	}
165
+
166
+	/**
167
+	 * convert shorthand php.ini notation into bytes, much like how the PHP source does it
168
+	 * @link http://pl.php.net/manual/en/function.ini-get.php
169
+	 *
170
+	 * @static
171
+	 * @access public
172
+	 * @param string $val
173
+	 * @return int
174
+	 */
175
+	function returnBytes($val)
176
+	{
177
+		$val = trim($val);
178
+		if (!$val) {
179
+			return 0;
180
+		}
181
+		$last = strtolower($val[strlen($val)-1]);
182
+		switch($last) {
183
+			// The 'G' modifier is available since PHP 5.1.0
184
+			case 'g':
185
+				$val *= 1024;
186
+			case 'm':
187
+				$val *= 1024;
188
+			case 'k':
189
+				$val *= 1024;
190
+		}
191
+
192
+		return $val;
193
+	}
194
+
195
+	/**
196
+	 * Checks if a value exists in an array (case insensitive)
197
+	 *
198
+	 * @static
199
+	 * @access public
200
+	 * @param string $needle
201
+	 * @param array $haystack
202
+	 * @return boolean
203
+	 */
204
+	function inArrayCaseInsensitive($needle, $haystack)
205
+	{
206
+		if (!$haystack || !is_array($haystack)) {
207
+			return false;
208
+		}
209
+		$lcase = array();
210
+		foreach ($haystack as $key => $val) {
211
+			$lcase[$key] = strtolower($val);
212
+		}
213
+		return in_array($needle, $lcase);
214
+	}
215
+
216
+	/**
217
+	 * UTF-8 compatible version of basename()
218
+	 *
219
+	 * @static
220
+	 * @access public
221
+	 * @param string $file
222
+	 * @return string
223
+	 */
224
+	function mbBasename($file)
225
+	{
226
+		$explode = explode('/', str_replace("\\", "/", $file));
227
+		return end($explode);
228
+	}
229
+
230
+	/**
231
+	 * Source: http://pl.php.net/imagecreate
232
+	 * (optimized for speed and memory usage, but yet not very efficient)
233
+	 *
234
+	 * @static
235
+	 * @access public
236
+	 * @param string $filename
237
+	 * @return resource
238
+	 */
239
+	function imageCreateFromBmp($filename)
240
+	{
241
+		//20 seconds seems to be a reasonable value to not kill a server and process images up to 1680x1050
242
+		@set_time_limit(20);
243
+
244
+		if (false === ($f1 = fopen($filename, "rb"))) {
245
+			return false;
246
+		}
247
+
248
+		$FILE = unpack("vfile_type/Vfile_size/Vreserved/Vbitmap_offset", fread($f1, 14));
249
+		if ($FILE['file_type'] != 19778) {
250
+			return false;
251
+		}
252
+
253
+		$BMP = unpack('Vheader_size/Vwidth/Vheight/vplanes/vbits_per_pixel'.
254
+		'/Vcompression/Vsize_bitmap/Vhoriz_resolution'.
255
+		'/Vvert_resolution/Vcolors_used/Vcolors_important', fread($f1, 40));
256
+
257
+		$BMP['colors'] = pow(2,$BMP['bits_per_pixel']);
258
+
259
+		if ($BMP['size_bitmap'] == 0) {
260
+			$BMP['size_bitmap'] = $FILE['file_size'] - $FILE['bitmap_offset'];
261
+		}
262
+
263
+		$BMP['bytes_per_pixel'] = $BMP['bits_per_pixel']/8;
264
+		$BMP['bytes_per_pixel2'] = ceil($BMP['bytes_per_pixel']);
265
+		$BMP['decal'] = ($BMP['width']*$BMP['bytes_per_pixel']/4);
266
+		$BMP['decal'] -= floor($BMP['width']*$BMP['bytes_per_pixel']/4);
267
+		$BMP['decal'] = 4-(4*$BMP['decal']);
268
+
269
+		if ($BMP['decal'] == 4) {
270
+			$BMP['decal'] = 0;
271
+		}
272
+
273
+		$PALETTE = array();
274
+		if ($BMP['colors'] < 16777216) {
275
+			$PALETTE = unpack('V'.$BMP['colors'], fread($f1, $BMP['colors']*4));
276
+		}
277
+
278
+		//2048x1536px@24bit don't even try to process larger files as it will probably fail
279
+		if ($BMP['size_bitmap'] > 3 * 2048 * 1536) {
280
+			return false;
281
+		}
282
+
283
+		$IMG = fread($f1, $BMP['size_bitmap']);
284
+		fclose($f1);
285
+		$VIDE = chr(0);
286
+
287
+		$res = imagecreatetruecolor($BMP['width'],$BMP['height']);
288
+		$P = 0;
289
+		$Y = $BMP['height']-1;
290
+
291
+		$line_length = $BMP['bytes_per_pixel']*$BMP['width'];
292
+
293
+		if ($BMP['bits_per_pixel'] == 24) {
294
+			while ($Y >= 0)
295
+			{
296
+				$X=0;
297
+				$temp = unpack( "C*", substr($IMG, $P, $line_length));
298
+
299
+				while ($X < $BMP['width'])
300
+				{
301
+					$offset = $X*3;
302
+					imagesetpixel($res, $X++, $Y, ($temp[$offset+3] << 16) + ($temp[$offset+2] << 8) + $temp[$offset+1]);
303
+				}
304
+				$Y--;
305
+				$P += $line_length + $BMP['decal'];
306
+			}
307
+		}
308
+		elseif ($BMP['bits_per_pixel'] == 8)
309
+		{
310
+			while ($Y >= 0)
311
+			{
312
+				$X=0;
313
+
314
+				$temp = unpack( "C*", substr($IMG, $P, $line_length));
315
+
316
+				while ($X < $BMP['width'])
317
+				{
318
+					imagesetpixel($res, $X++, $Y, $PALETTE[$temp[$X] +1]);
319
+				}
320
+				$Y--;
321
+				$P += $line_length + $BMP['decal'];
322
+			}
323
+		}
324
+		elseif ($BMP['bits_per_pixel'] == 4)
325
+		{
326
+			while ($Y >= 0)
327
+			{
328
+				$X=0;
329
+				$i = 1;
330
+				$low = true;
331
+
332
+				$temp = unpack( "C*", substr($IMG, $P, $line_length));
333
+
334
+				while ($X < $BMP['width'])
335
+				{
336
+					if ($low) {
337
+						$index = $temp[$i] >> 4;
338
+					}
339
+					else {
340
+						$index = $temp[$i++] & 0x0F;
341
+					}
342
+					$low = !$low;
343
+
344
+					imagesetpixel($res, $X++, $Y, $PALETTE[$index +1]);
345
+				}
346
+				$Y--;
347
+				$P += $line_length + $BMP['decal'];
348
+			}
349
+		}
350
+		elseif ($BMP['bits_per_pixel'] == 1)
351
+		{
352
+			$COLOR = unpack("n",$VIDE.substr($IMG,floor($P),1));
353
+			if     (($P*8)%8 == 0) $COLOR[1] =  $COLOR[1]        >>7;
354
+			elseif (($P*8)%8 == 1) $COLOR[1] = ($COLOR[1] & 0x40)>>6;
355
+			elseif (($P*8)%8 == 2) $COLOR[1] = ($COLOR[1] & 0x20)>>5;
356
+			elseif (($P*8)%8 == 3) $COLOR[1] = ($COLOR[1] & 0x10)>>4;
357
+			elseif (($P*8)%8 == 4) $COLOR[1] = ($COLOR[1] & 0x8)>>3;
358
+			elseif (($P*8)%8 == 5) $COLOR[1] = ($COLOR[1] & 0x4)>>2;
359
+			elseif (($P*8)%8 == 6) $COLOR[1] = ($COLOR[1] & 0x2)>>1;
360
+			elseif (($P*8)%8 == 7) $COLOR[1] = ($COLOR[1] & 0x1);
361
+			$COLOR[1] = $PALETTE[$COLOR[1]+1];
362
+		}
363
+		else {
364
+			return false;
365
+		}
366
+
367
+		return $res;
368
+	}
369 369
 }
Please login to merge, or discard this patch.
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -28,10 +28,10 @@  discard block
 block discarded – undo
28 28
     function getErrorMessage($number, $arg = "") {
29 29
         $langCode = 'en';
30 30
         if (!empty($_GET['langCode']) && preg_match("/^[a-z\-]+$/", $_GET['langCode'])) {
31
-            if (file_exists(CKFINDER_CONNECTOR_LANG_PATH . "/" . $_GET['langCode'] . ".php"))
31
+            if (file_exists(CKFINDER_CONNECTOR_LANG_PATH."/".$_GET['langCode'].".php"))
32 32
                 $langCode = $_GET['langCode'];
33 33
         }
34
-        include CKFINDER_CONNECTOR_LANG_PATH . "/" . $langCode . ".php";
34
+        include CKFINDER_CONNECTOR_LANG_PATH."/".$langCode.".php";
35 35
         if ($number) {
36 36
             if (!empty ($GLOBALS['CKFLang']['Errors'][$number])) {
37 37
                 $errorMessage = str_replace("%1", $arg, $GLOBALS['CKFLang']['Errors'][$number]);
@@ -80,28 +80,28 @@  discard block
 block discarded – undo
80 80
      * @param int $quality
81 81
      * @return boolean
82 82
      */
83
-    function fastImageCopyResampled (&$dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $quality = 3)
83
+    function fastImageCopyResampled(&$dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $quality = 3)
84 84
     {
85 85
         if (empty($src_image) || empty($dst_image)) {
86 86
             return false;
87 87
         }
88 88
 
89 89
         if ($quality <= 1) {
90
-            $temp = imagecreatetruecolor ($dst_w + 1, $dst_h + 1);
91
-            imagecopyresized ($temp, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w + 1, $dst_h + 1, $src_w, $src_h);
92
-            imagecopyresized ($dst_image, $temp, 0, 0, 0, 0, $dst_w, $dst_h, $dst_w, $dst_h);
93
-            imagedestroy ($temp);
90
+            $temp = imagecreatetruecolor($dst_w + 1, $dst_h + 1);
91
+            imagecopyresized($temp, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w + 1, $dst_h + 1, $src_w, $src_h);
92
+            imagecopyresized($dst_image, $temp, 0, 0, 0, 0, $dst_w, $dst_h, $dst_w, $dst_h);
93
+            imagedestroy($temp);
94 94
 
95 95
         } elseif ($quality < 5 && (($dst_w * $quality) < $src_w || ($dst_h * $quality) < $src_h)) {
96 96
             $tmp_w = $dst_w * $quality;
97 97
             $tmp_h = $dst_h * $quality;
98
-            $temp = imagecreatetruecolor ($tmp_w + 1, $tmp_h + 1);
99
-            imagecopyresized ($temp, $src_image, 0, 0, $src_x, $src_y, $tmp_w + 1, $tmp_h + 1, $src_w, $src_h);
100
-            imagecopyresampled ($dst_image, $temp, $dst_x, $dst_y, 0, 0, $dst_w, $dst_h, $tmp_w, $tmp_h);
101
-            imagedestroy ($temp);
98
+            $temp = imagecreatetruecolor($tmp_w + 1, $tmp_h + 1);
99
+            imagecopyresized($temp, $src_image, 0, 0, $src_x, $src_y, $tmp_w + 1, $tmp_h + 1, $src_w, $src_h);
100
+            imagecopyresampled($dst_image, $temp, $dst_x, $dst_y, 0, 0, $dst_w, $dst_h, $tmp_w, $tmp_h);
101
+            imagedestroy($temp);
102 102
 
103 103
         } else {
104
-            imagecopyresampled ($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
104
+            imagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
105 105
         }
106 106
 
107 107
         return true;
@@ -118,20 +118,20 @@  discard block
 block discarded – undo
118 118
      */
119 119
     function setMemoryForImage($imageWidth, $imageHeight, $imageBits, $imageChannels)
120 120
     {
121
-        $MB = 1048576;  // number of bytes in 1M
122
-        $K64 = 65536;    // number of bytes in 64K
123
-        $TWEAKFACTOR = 2.4;  // Or whatever works for you
124
-        $memoryNeeded = round( ( $imageWidth * $imageHeight
121
+        $MB = 1048576; // number of bytes in 1M
122
+        $K64 = 65536; // number of bytes in 64K
123
+        $TWEAKFACTOR = 2.4; // Or whatever works for you
124
+        $memoryNeeded = round(($imageWidth * $imageHeight
125 125
         * $imageBits
126 126
         * $imageChannels / 8
127 127
         + $K64
128 128
         ) * $TWEAKFACTOR
129
-        ) + 3*$MB;
129
+        ) + 3 * $MB;
130 130
 
131 131
         //ini_get('memory_limit') only works if compiled with "--enable-memory-limit" also
132 132
         //Default memory limit is 8MB so well stick with that.
133 133
         //To find out what yours is, view your php.ini file.
134
-        $memoryLimit = CKFinder_Connector_Utils_Misc::returnBytes(@ini_get('memory_limit'))/$MB;
134
+        $memoryLimit = CKFinder_Connector_Utils_Misc::returnBytes(@ini_get('memory_limit')) / $MB;
135 135
         if (!$memoryLimit) {
136 136
             $memoryLimit = 8;
137 137
         }
@@ -139,23 +139,23 @@  discard block
 block discarded – undo
139 139
         $memoryLimitMB = $memoryLimit * $MB;
140 140
         if (function_exists('memory_get_usage')) {
141 141
             if (memory_get_usage() + $memoryNeeded > $memoryLimitMB) {
142
-                $newLimit = $memoryLimit + ceil( ( memory_get_usage()
142
+                $newLimit = $memoryLimit + ceil((memory_get_usage()
143 143
                 + $memoryNeeded
144 144
                 - $memoryLimitMB
145 145
                 ) / $MB
146 146
                 );
147
-                if (@ini_set( 'memory_limit', $newLimit . 'M' ) === false) {
147
+                if (@ini_set('memory_limit', $newLimit.'M') === false) {
148 148
                     return false;
149 149
                 }
150 150
             }
151 151
         } else {
152
-            if ($memoryNeeded + 3*$MB > $memoryLimitMB) {
153
-                $newLimit = $memoryLimit + ceil(( 3*$MB
152
+            if ($memoryNeeded + 3 * $MB > $memoryLimitMB) {
153
+                $newLimit = $memoryLimit + ceil((3 * $MB
154 154
                 + $memoryNeeded
155 155
                 - $memoryLimitMB
156 156
                 ) / $MB
157 157
                 );
158
-                if (false === @ini_set( 'memory_limit', $newLimit . 'M' )) {
158
+                if (false === @ini_set('memory_limit', $newLimit.'M')) {
159 159
                     return false;
160 160
                 }
161 161
             }
@@ -178,8 +178,8 @@  discard block
 block discarded – undo
178 178
         if (!$val) {
179 179
             return 0;
180 180
         }
181
-        $last = strtolower($val[strlen($val)-1]);
182
-        switch($last) {
181
+        $last = strtolower($val[strlen($val) - 1]);
182
+        switch ($last) {
183 183
             // The 'G' modifier is available since PHP 5.1.0
184 184
             case 'g':
185 185
                 $val *= 1024;
@@ -254,17 +254,17 @@  discard block
 block discarded – undo
254 254
         '/Vcompression/Vsize_bitmap/Vhoriz_resolution'.
255 255
         '/Vvert_resolution/Vcolors_used/Vcolors_important', fread($f1, 40));
256 256
 
257
-        $BMP['colors'] = pow(2,$BMP['bits_per_pixel']);
257
+        $BMP['colors'] = pow(2, $BMP['bits_per_pixel']);
258 258
 
259 259
         if ($BMP['size_bitmap'] == 0) {
260 260
             $BMP['size_bitmap'] = $FILE['file_size'] - $FILE['bitmap_offset'];
261 261
         }
262 262
 
263
-        $BMP['bytes_per_pixel'] = $BMP['bits_per_pixel']/8;
263
+        $BMP['bytes_per_pixel'] = $BMP['bits_per_pixel'] / 8;
264 264
         $BMP['bytes_per_pixel2'] = ceil($BMP['bytes_per_pixel']);
265
-        $BMP['decal'] = ($BMP['width']*$BMP['bytes_per_pixel']/4);
266
-        $BMP['decal'] -= floor($BMP['width']*$BMP['bytes_per_pixel']/4);
267
-        $BMP['decal'] = 4-(4*$BMP['decal']);
265
+        $BMP['decal'] = ($BMP['width'] * $BMP['bytes_per_pixel'] / 4);
266
+        $BMP['decal'] -= floor($BMP['width'] * $BMP['bytes_per_pixel'] / 4);
267
+        $BMP['decal'] = 4 - (4 * $BMP['decal']);
268 268
 
269 269
         if ($BMP['decal'] == 4) {
270 270
             $BMP['decal'] = 0;
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 
273 273
         $PALETTE = array();
274 274
         if ($BMP['colors'] < 16777216) {
275
-            $PALETTE = unpack('V'.$BMP['colors'], fread($f1, $BMP['colors']*4));
275
+            $PALETTE = unpack('V'.$BMP['colors'], fread($f1, $BMP['colors'] * 4));
276 276
         }
277 277
 
278 278
         //2048x1536px@24bit don't even try to process larger files as it will probably fail
@@ -284,22 +284,22 @@  discard block
 block discarded – undo
284 284
         fclose($f1);
285 285
         $VIDE = chr(0);
286 286
 
287
-        $res = imagecreatetruecolor($BMP['width'],$BMP['height']);
287
+        $res = imagecreatetruecolor($BMP['width'], $BMP['height']);
288 288
         $P = 0;
289
-        $Y = $BMP['height']-1;
289
+        $Y = $BMP['height'] - 1;
290 290
 
291
-        $line_length = $BMP['bytes_per_pixel']*$BMP['width'];
291
+        $line_length = $BMP['bytes_per_pixel'] * $BMP['width'];
292 292
 
293 293
         if ($BMP['bits_per_pixel'] == 24) {
294 294
             while ($Y >= 0)
295 295
             {
296
-                $X=0;
297
-                $temp = unpack( "C*", substr($IMG, $P, $line_length));
296
+                $X = 0;
297
+                $temp = unpack("C*", substr($IMG, $P, $line_length));
298 298
 
299 299
                 while ($X < $BMP['width'])
300 300
                 {
301
-                    $offset = $X*3;
302
-                    imagesetpixel($res, $X++, $Y, ($temp[$offset+3] << 16) + ($temp[$offset+2] << 8) + $temp[$offset+1]);
301
+                    $offset = $X * 3;
302
+                    imagesetpixel($res, $X++, $Y, ($temp[$offset + 3] << 16) + ($temp[$offset + 2] << 8) + $temp[$offset + 1]);
303 303
                 }
304 304
                 $Y--;
305 305
                 $P += $line_length + $BMP['decal'];
@@ -309,13 +309,13 @@  discard block
 block discarded – undo
309 309
         {
310 310
             while ($Y >= 0)
311 311
             {
312
-                $X=0;
312
+                $X = 0;
313 313
 
314
-                $temp = unpack( "C*", substr($IMG, $P, $line_length));
314
+                $temp = unpack("C*", substr($IMG, $P, $line_length));
315 315
 
316 316
                 while ($X < $BMP['width'])
317 317
                 {
318
-                    imagesetpixel($res, $X++, $Y, $PALETTE[$temp[$X] +1]);
318
+                    imagesetpixel($res, $X++, $Y, $PALETTE[$temp[$X] + 1]);
319 319
                 }
320 320
                 $Y--;
321 321
                 $P += $line_length + $BMP['decal'];
@@ -325,11 +325,11 @@  discard block
 block discarded – undo
325 325
         {
326 326
             while ($Y >= 0)
327 327
             {
328
-                $X=0;
328
+                $X = 0;
329 329
                 $i = 1;
330 330
                 $low = true;
331 331
 
332
-                $temp = unpack( "C*", substr($IMG, $P, $line_length));
332
+                $temp = unpack("C*", substr($IMG, $P, $line_length));
333 333
 
334 334
                 while ($X < $BMP['width'])
335 335
                 {
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
                     }
342 342
                     $low = !$low;
343 343
 
344
-                    imagesetpixel($res, $X++, $Y, $PALETTE[$index +1]);
344
+                    imagesetpixel($res, $X++, $Y, $PALETTE[$index + 1]);
345 345
                 }
346 346
                 $Y--;
347 347
                 $P += $line_length + $BMP['decal'];
@@ -349,16 +349,16 @@  discard block
 block discarded – undo
349 349
         }
350 350
         elseif ($BMP['bits_per_pixel'] == 1)
351 351
         {
352
-            $COLOR = unpack("n",$VIDE.substr($IMG,floor($P),1));
353
-            if     (($P*8)%8 == 0) $COLOR[1] =  $COLOR[1]        >>7;
354
-            elseif (($P*8)%8 == 1) $COLOR[1] = ($COLOR[1] & 0x40)>>6;
355
-            elseif (($P*8)%8 == 2) $COLOR[1] = ($COLOR[1] & 0x20)>>5;
356
-            elseif (($P*8)%8 == 3) $COLOR[1] = ($COLOR[1] & 0x10)>>4;
357
-            elseif (($P*8)%8 == 4) $COLOR[1] = ($COLOR[1] & 0x8)>>3;
358
-            elseif (($P*8)%8 == 5) $COLOR[1] = ($COLOR[1] & 0x4)>>2;
359
-            elseif (($P*8)%8 == 6) $COLOR[1] = ($COLOR[1] & 0x2)>>1;
360
-            elseif (($P*8)%8 == 7) $COLOR[1] = ($COLOR[1] & 0x1);
361
-            $COLOR[1] = $PALETTE[$COLOR[1]+1];
352
+            $COLOR = unpack("n", $VIDE.substr($IMG, floor($P), 1));
353
+            if (($P * 8) % 8 == 0) $COLOR[1] = $COLOR[1] >> 7;
354
+            elseif (($P * 8) % 8 == 1) $COLOR[1] = ($COLOR[1] & 0x40) >> 6;
355
+            elseif (($P * 8) % 8 == 2) $COLOR[1] = ($COLOR[1] & 0x20) >> 5;
356
+            elseif (($P * 8) % 8 == 3) $COLOR[1] = ($COLOR[1] & 0x10) >> 4;
357
+            elseif (($P * 8) % 8 == 4) $COLOR[1] = ($COLOR[1] & 0x8) >> 3;
358
+            elseif (($P * 8) % 8 == 5) $COLOR[1] = ($COLOR[1] & 0x4) >> 2;
359
+            elseif (($P * 8) % 8 == 6) $COLOR[1] = ($COLOR[1] & 0x2) >> 1;
360
+            elseif (($P * 8) % 8 == 7) $COLOR[1] = ($COLOR[1] & 0x1);
361
+            $COLOR[1] = $PALETTE[$COLOR[1] + 1];
362 362
         }
363 363
         else {
364 364
             return false;
Please login to merge, or discard this patch.
Braces   +28 added lines, -21 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@  discard block
 block discarded – undo
10 10
  * modifying or distribute this file or part of its contents. The contents of
11 11
  * this file is part of the Source Code of CKFinder.
12 12
  */
13
-if (!defined('IN_CKFINDER')) exit;
13
+if (!defined('IN_CKFINDER')) {
14
+	exit;
15
+}
14 16
 
15 17
 /**
16 18
  * @package CKFinder
@@ -28,8 +30,9 @@  discard block
 block discarded – undo
28 30
     function getErrorMessage($number, $arg = "") {
29 31
         $langCode = 'en';
30 32
         if (!empty($_GET['langCode']) && preg_match("/^[a-z\-]+$/", $_GET['langCode'])) {
31
-            if (file_exists(CKFINDER_CONNECTOR_LANG_PATH . "/" . $_GET['langCode'] . ".php"))
32
-                $langCode = $_GET['langCode'];
33
+            if (file_exists(CKFINDER_CONNECTOR_LANG_PATH . "/" . $_GET['langCode'] . ".php")) {
34
+                            $langCode = $_GET['langCode'];
35
+            }
33 36
         }
34 37
         include CKFINDER_CONNECTOR_LANG_PATH . "/" . $langCode . ".php";
35 38
         if ($number) {
@@ -304,8 +307,7 @@  discard block
 block discarded – undo
304 307
                 $Y--;
305 308
                 $P += $line_length + $BMP['decal'];
306 309
             }
307
-        }
308
-        elseif ($BMP['bits_per_pixel'] == 8)
310
+        } elseif ($BMP['bits_per_pixel'] == 8)
309 311
         {
310 312
             while ($Y >= 0)
311 313
             {
@@ -320,8 +322,7 @@  discard block
 block discarded – undo
320 322
                 $Y--;
321 323
                 $P += $line_length + $BMP['decal'];
322 324
             }
323
-        }
324
-        elseif ($BMP['bits_per_pixel'] == 4)
325
+        } elseif ($BMP['bits_per_pixel'] == 4)
325 326
         {
326 327
             while ($Y >= 0)
327 328
             {
@@ -335,8 +336,7 @@  discard block
 block discarded – undo
335 336
                 {
336 337
                     if ($low) {
337 338
                         $index = $temp[$i] >> 4;
338
-                    }
339
-                    else {
339
+                    } else {
340 340
                         $index = $temp[$i++] & 0x0F;
341 341
                     }
342 342
                     $low = !$low;
@@ -346,21 +346,28 @@  discard block
 block discarded – undo
346 346
                 $Y--;
347 347
                 $P += $line_length + $BMP['decal'];
348 348
             }
349
-        }
350
-        elseif ($BMP['bits_per_pixel'] == 1)
349
+        } elseif ($BMP['bits_per_pixel'] == 1)
351 350
         {
352 351
             $COLOR = unpack("n",$VIDE.substr($IMG,floor($P),1));
353
-            if     (($P*8)%8 == 0) $COLOR[1] =  $COLOR[1]        >>7;
354
-            elseif (($P*8)%8 == 1) $COLOR[1] = ($COLOR[1] & 0x40)>>6;
355
-            elseif (($P*8)%8 == 2) $COLOR[1] = ($COLOR[1] & 0x20)>>5;
356
-            elseif (($P*8)%8 == 3) $COLOR[1] = ($COLOR[1] & 0x10)>>4;
357
-            elseif (($P*8)%8 == 4) $COLOR[1] = ($COLOR[1] & 0x8)>>3;
358
-            elseif (($P*8)%8 == 5) $COLOR[1] = ($COLOR[1] & 0x4)>>2;
359
-            elseif (($P*8)%8 == 6) $COLOR[1] = ($COLOR[1] & 0x2)>>1;
360
-            elseif (($P*8)%8 == 7) $COLOR[1] = ($COLOR[1] & 0x1);
352
+            if     (($P*8)%8 == 0) {
353
+            	$COLOR[1] =  $COLOR[1]        >>7;
354
+            } elseif (($P*8)%8 == 1) {
355
+            	$COLOR[1] = ($COLOR[1] & 0x40)>>6;
356
+            } elseif (($P*8)%8 == 2) {
357
+            	$COLOR[1] = ($COLOR[1] & 0x20)>>5;
358
+            } elseif (($P*8)%8 == 3) {
359
+            	$COLOR[1] = ($COLOR[1] & 0x10)>>4;
360
+            } elseif (($P*8)%8 == 4) {
361
+            	$COLOR[1] = ($COLOR[1] & 0x8)>>3;
362
+            } elseif (($P*8)%8 == 5) {
363
+            	$COLOR[1] = ($COLOR[1] & 0x4)>>2;
364
+            } elseif (($P*8)%8 == 6) {
365
+            	$COLOR[1] = ($COLOR[1] & 0x2)>>1;
366
+            } elseif (($P*8)%8 == 7) {
367
+            	$COLOR[1] = ($COLOR[1] & 0x1);
368
+            }
361 369
             $COLOR[1] = $PALETTE[$COLOR[1]+1];
362
-        }
363
-        else {
370
+        } else {
364 371
             return false;
365 372
         }
366 373
 
Please login to merge, or discard this patch.
libs/ckfinder/core/connector/php/php4/Utils/XmlNode.php 4 patches
Doc Comments   -3 removed lines patch added patch discarded remove patch
@@ -107,7 +107,6 @@  discard block
 block discarded – undo
107 107
     /**
108 108
      * Set element value
109 109
      *
110
-     * @param string $name
111 110
      * @param string $value
112 111
      * @access public
113 112
      */
@@ -119,8 +118,6 @@  discard block
 block discarded – undo
119 118
     /**
120 119
      * Get element value
121 120
      *
122
-     * @param string $name
123
-     * @param string $value
124 121
      * @access public
125 122
      */
126 123
     function getValue()
Please login to merge, or discard this patch.
Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -27,158 +27,158 @@
 block discarded – undo
27 27
  */
28 28
 class Ckfinder_Connector_Utils_XmlNode
29 29
 {
30
-    /**
31
-     * Array that stores XML attributes
32
-     *
33
-     * @access private
34
-     * @var array
35
-     */
36
-    var $_attributes = array();
37
-    /**
38
-     * Array that stores child nodes
39
-     *
40
-     * @access private
41
-     * @var array
42
-     */
43
-    var $_childNodes = array();
44
-    /**
45
-     * Node name
46
-     *
47
-     * @access private
48
-     * @var string
49
-     */
50
-    var $_name;
51
-    /**
52
-     * Node value
53
-     *
54
-     * @access private
55
-     * @var string
56
-     */
57
-    var $_value;
58
-
59
-    /**
60
-     * Create new node
61
-     *
62
-     * @param string $nodeName node name
63
-     * @param string $nodeValue node value
64
-     * @return Ckfinder_Connector_Utils_XmlNode
65
-     */
66
-    function Ckfinder_Connector_Utils_XmlNode($nodeName, $nodeValue = null)
67
-    {
68
-        $this->_name = $nodeName;
69
-        if (!is_null($nodeValue)) {
70
-            $this->_value = $nodeValue;
71
-        }
72
-    }
73
-
74
-    function &getChild($name)
75
-    {
76
-        foreach ($this->_childNodes as $i => $node) {
77
-            if ($node->_name == $name) {
78
-                return $this->_childNodes[$i];
79
-            }
80
-        }
81
-        return null;
82
-    }
83
-
84
-    /**
85
-     * Add attribute
86
-     *
87
-     * @param string $name
88
-     * @param string $value
89
-     * @access public
90
-     */
91
-    function addAttribute($name, $value)
92
-    {
93
-        $this->_attributes[$name] = $value;
94
-    }
95
-
96
-    /**
97
-     * Get attribute value
98
-     *
99
-     * @param string $name
100
-     * @access public
101
-     */
102
-    function getAttribute($name)
103
-    {
104
-        return $this->_attributes[$name];
105
-    }
106
-
107
-    /**
108
-     * Set element value
109
-     *
110
-     * @param string $name
111
-     * @param string $value
112
-     * @access public
113
-     */
114
-    function setValue($value)
115
-    {
116
-        $this->_value = $value;
117
-    }
118
-
119
-    /**
120
-     * Get element value
121
-     *
122
-     * @param string $name
123
-     * @param string $value
124
-     * @access public
125
-     */
126
-    function getValue()
127
-    {
128
-        return $this->_value;
129
-    }
130
-
131
-    /**
132
-     * Adds new child at the end of the children
133
-     *
134
-     * @param Ckfinder_Connector_Utils_XmlNode $node
135
-     * @access public
136
-     */
137
-    function addChild(&$node)
138
-    {
139
-        $this->_childNodes[] =& $node;
140
-    }
141
-
142
-    /**
143
-     * Return a well-formed XML string based on Ckfinder_Connector_Utils_XmlNode element
144
-     *
145
-     * @return string
146
-     * @access public
147
-     */
148
-    function asXML()
149
-    {
150
-        $ret = "<" . $this->_name;
151
-
152
-        //print Attributes
153
-        if (sizeof($this->_attributes)>0) {
154
-            foreach ($this->_attributes as $_name => $_value) {
155
-                $ret .= " " . $_name . '="' . htmlspecialchars($_value) . '"';
156
-            }
157
-        }
158
-
159
-        //if there is nothing more
160
-        if (is_null($this->_value) && !sizeof($this->_childNodes)) {
161
-            $ret .= " />";
162
-            return $ret;
163
-        }
164
-
165
-        //close opening tag
166
-        $ret .= ">";
167
-
168
-        //print value
169
-        if (!is_null($this->_value)) {
170
-            $ret .= htmlspecialchars($this->_value);
171
-        }
172
-
173
-        //print child nodes
174
-        if (sizeof($this->_childNodes)>0) {
175
-            foreach ($this->_childNodes as $_node) {
176
-                $ret .= $_node->asXml();
177
-            }
178
-        }
179
-
180
-        $ret .= "</" . $this->_name . ">";
181
-
182
-        return $ret;
183
-    }
30
+	/**
31
+	 * Array that stores XML attributes
32
+	 *
33
+	 * @access private
34
+	 * @var array
35
+	 */
36
+	var $_attributes = array();
37
+	/**
38
+	 * Array that stores child nodes
39
+	 *
40
+	 * @access private
41
+	 * @var array
42
+	 */
43
+	var $_childNodes = array();
44
+	/**
45
+	 * Node name
46
+	 *
47
+	 * @access private
48
+	 * @var string
49
+	 */
50
+	var $_name;
51
+	/**
52
+	 * Node value
53
+	 *
54
+	 * @access private
55
+	 * @var string
56
+	 */
57
+	var $_value;
58
+
59
+	/**
60
+	 * Create new node
61
+	 *
62
+	 * @param string $nodeName node name
63
+	 * @param string $nodeValue node value
64
+	 * @return Ckfinder_Connector_Utils_XmlNode
65
+	 */
66
+	function Ckfinder_Connector_Utils_XmlNode($nodeName, $nodeValue = null)
67
+	{
68
+		$this->_name = $nodeName;
69
+		if (!is_null($nodeValue)) {
70
+			$this->_value = $nodeValue;
71
+		}
72
+	}
73
+
74
+	function &getChild($name)
75
+	{
76
+		foreach ($this->_childNodes as $i => $node) {
77
+			if ($node->_name == $name) {
78
+				return $this->_childNodes[$i];
79
+			}
80
+		}
81
+		return null;
82
+	}
83
+
84
+	/**
85
+	 * Add attribute
86
+	 *
87
+	 * @param string $name
88
+	 * @param string $value
89
+	 * @access public
90
+	 */
91
+	function addAttribute($name, $value)
92
+	{
93
+		$this->_attributes[$name] = $value;
94
+	}
95
+
96
+	/**
97
+	 * Get attribute value
98
+	 *
99
+	 * @param string $name
100
+	 * @access public
101
+	 */
102
+	function getAttribute($name)
103
+	{
104
+		return $this->_attributes[$name];
105
+	}
106
+
107
+	/**
108
+	 * Set element value
109
+	 *
110
+	 * @param string $name
111
+	 * @param string $value
112
+	 * @access public
113
+	 */
114
+	function setValue($value)
115
+	{
116
+		$this->_value = $value;
117
+	}
118
+
119
+	/**
120
+	 * Get element value
121
+	 *
122
+	 * @param string $name
123
+	 * @param string $value
124
+	 * @access public
125
+	 */
126
+	function getValue()
127
+	{
128
+		return $this->_value;
129
+	}
130
+
131
+	/**
132
+	 * Adds new child at the end of the children
133
+	 *
134
+	 * @param Ckfinder_Connector_Utils_XmlNode $node
135
+	 * @access public
136
+	 */
137
+	function addChild(&$node)
138
+	{
139
+		$this->_childNodes[] =& $node;
140
+	}
141
+
142
+	/**
143
+	 * Return a well-formed XML string based on Ckfinder_Connector_Utils_XmlNode element
144
+	 *
145
+	 * @return string
146
+	 * @access public
147
+	 */
148
+	function asXML()
149
+	{
150
+		$ret = "<" . $this->_name;
151
+
152
+		//print Attributes
153
+		if (sizeof($this->_attributes)>0) {
154
+			foreach ($this->_attributes as $_name => $_value) {
155
+				$ret .= " " . $_name . '="' . htmlspecialchars($_value) . '"';
156
+			}
157
+		}
158
+
159
+		//if there is nothing more
160
+		if (is_null($this->_value) && !sizeof($this->_childNodes)) {
161
+			$ret .= " />";
162
+			return $ret;
163
+		}
164
+
165
+		//close opening tag
166
+		$ret .= ">";
167
+
168
+		//print value
169
+		if (!is_null($this->_value)) {
170
+			$ret .= htmlspecialchars($this->_value);
171
+		}
172
+
173
+		//print child nodes
174
+		if (sizeof($this->_childNodes)>0) {
175
+			foreach ($this->_childNodes as $_node) {
176
+				$ret .= $_node->asXml();
177
+			}
178
+		}
179
+
180
+		$ret .= "</" . $this->_name . ">";
181
+
182
+		return $ret;
183
+	}
184 184
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
      */
137 137
     function addChild(&$node)
138 138
     {
139
-        $this->_childNodes[] =& $node;
139
+        $this->_childNodes[] = & $node;
140 140
     }
141 141
 
142 142
     /**
@@ -147,12 +147,12 @@  discard block
 block discarded – undo
147 147
      */
148 148
     function asXML()
149 149
     {
150
-        $ret = "<" . $this->_name;
150
+        $ret = "<".$this->_name;
151 151
 
152 152
         //print Attributes
153
-        if (sizeof($this->_attributes)>0) {
153
+        if (sizeof($this->_attributes) > 0) {
154 154
             foreach ($this->_attributes as $_name => $_value) {
155
-                $ret .= " " . $_name . '="' . htmlspecialchars($_value) . '"';
155
+                $ret .= " ".$_name.'="'.htmlspecialchars($_value).'"';
156 156
             }
157 157
         }
158 158
 
@@ -171,13 +171,13 @@  discard block
 block discarded – undo
171 171
         }
172 172
 
173 173
         //print child nodes
174
-        if (sizeof($this->_childNodes)>0) {
174
+        if (sizeof($this->_childNodes) > 0) {
175 175
             foreach ($this->_childNodes as $_node) {
176 176
                 $ret .= $_node->asXml();
177 177
             }
178 178
         }
179 179
 
180
-        $ret .= "</" . $this->_name . ">";
180
+        $ret .= "</".$this->_name.">";
181 181
 
182 182
         return $ret;
183 183
     }
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@
 block discarded – undo
10 10
  * modifying or distribute this file or part of its contents. The contents of
11 11
  * this file is part of the Source Code of CKFinder.
12 12
  */
13
-if (!defined('IN_CKFINDER')) exit;
13
+if (!defined('IN_CKFINDER')) {
14
+	exit;
15
+}
14 16
 
15 17
 /**
16 18
  * @package CKFinder
Please login to merge, or discard this patch.
libs/ckfinder/core/connector/php/php5/CommandHandler/CopyFiles.php 4 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -243,6 +243,10 @@
 block discarded – undo
243 243
         }
244 244
     }
245 245
 
246
+    /**
247
+     * @param integer $errorCode
248
+     * @param string $path
249
+     */
246 250
     private function appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path)
247 251
     {
248 252
         $oErrorNode = new CKFinder_Connector_Utils_XmlNode("Error");
Please login to merge, or discard this patch.
Indentation   +220 added lines, -220 removed lines patch added patch discarded remove patch
@@ -32,224 +32,224 @@
 block discarded – undo
32 32
  */
33 33
 class CKFinder_Connector_CommandHandler_CopyFiles extends CKFinder_Connector_CommandHandler_XmlCommandHandlerBase
34 34
 {
35
-    /**
36
-     * Command name
37
-     *
38
-     * @access private
39
-     * @var string
40
-     */
41
-    private $command = "CopyFiles";
42
-
43
-
44
-    /**
45
-     * handle request and build XML
46
-     * @access protected
47
-     *
48
-     */
49
-    protected function buildXml()
50
-    {
51
-        if (empty($_POST['CKFinderCommand']) || $_POST['CKFinderCommand'] != 'true') {
52
-            $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
53
-        }
54
-
55
-        $clientPath = $this->_currentFolder->getClientPath();
56
-        $sServerDir = $this->_currentFolder->getServerPath();
57
-        $currentResourceTypeConfig = $this->_currentFolder->getResourceTypeConfig();
58
-        $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
59
-        $_aclConfig = $_config->getAccessControlConfig();
60
-        $aclMasks = array();
61
-        $_resourceTypeConfig = array();
62
-
63
-        if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_RENAME | CKFINDER_CONNECTOR_ACL_FILE_UPLOAD | CKFINDER_CONNECTOR_ACL_FILE_DELETE)) {
64
-            $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED);
65
-        }
66
-
67
-        // Create the "Errors" node.
68
-        $oErrorsNode = new CKFinder_Connector_Utils_XmlNode("Errors");
69
-        $errorCode = CKFINDER_CONNECTOR_ERROR_NONE;
70
-        $copied = 0;
71
-        $copiedAll = 0;
72
-        if (!empty($_POST['copied'])) {
73
-            $copiedAll = intval($_POST['copied']);
74
-        }
75
-        $checkedPaths = array();
76
-
77
-        $oCopyFilesNode = new Ckfinder_Connector_Utils_XmlNode("CopyFiles");
78
-
79
-        if (!empty($_POST['files']) && is_array($_POST['files'])) {
80
-            foreach ($_POST['files'] as $index => $arr) {
81
-                if (empty($arr['name'])) {
82
-                    continue;
83
-                }
84
-                if (!isset($arr['name'], $arr['type'], $arr['folder'])) {
85
-                    $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
86
-                }
87
-
88
-                // file name
89
-                $name = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($arr['name']);
90
-                // resource type
91
-                $type = $arr['type'];
92
-                // client path
93
-                $path = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($arr['folder']);
94
-                // options
95
-                $options = (!empty($arr['options'])) ? $arr['options'] : '';
96
-
97
-                $destinationFilePath = $sServerDir.$name;
98
-
99
-                // check #1 (path)
100
-                if (!CKFinder_Connector_Utils_FileSystem::checkFileName($name) || preg_match(CKFINDER_REGEX_INVALID_PATH, $path)) {
101
-                    $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
102
-                }
103
-
104
-                // get resource type config for current file
105
-                if (!isset($_resourceTypeConfig[$type])) {
106
-                    $_resourceTypeConfig[$type] = $_config->getResourceTypeConfig($type);
107
-                }
108
-
109
-                // check #2 (resource type)
110
-                if (is_null($_resourceTypeConfig[$type])) {
111
-                    $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
112
-                }
113
-
114
-                // check #3 (extension)
115
-                if (!$_resourceTypeConfig[$type]->checkExtension($name, false)) {
116
-                    $errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION;
117
-                    $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
118
-                    continue;
119
-                }
120
-
121
-                // check #4 (extension) - when moving to another resource type, double check extension
122
-                if ($currentResourceTypeConfig->getName() != $type) {
123
-                    if (!$currentResourceTypeConfig->checkExtension($name, false)) {
124
-                        $errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION;
125
-                        $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
126
-                        continue;
127
-                    }
128
-                }
129
-
130
-                // check #5 (hidden folders)
131
-                // cache results
132
-                if (empty($checkedPaths[$path])) {
133
-                    $checkedPaths[$path] = true;
134
-
135
-                    if ($_resourceTypeConfig[$type]->checkIsHiddenPath($path)) {
136
-                        $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
137
-                    }
138
-                }
139
-
140
-                $sourceFilePath = $_resourceTypeConfig[$type]->getDirectory().$path.$name;
141
-
142
-                // check #6 (hidden file name)
143
-                if ($currentResourceTypeConfig->checkIsHiddenFile($name)) {
144
-                    $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
145
-                }
146
-
147
-                // check #7 (Access Control, need file view permission to source files)
148
-                if (!isset($aclMasks[$type."@".$path])) {
149
-                    $aclMasks[$type."@".$path] = $_aclConfig->getComputedMask($type, $path);
150
-                }
151
-
152
-                $isAuthorized = (($aclMasks[$type."@".$path] & CKFINDER_CONNECTOR_ACL_FILE_VIEW) == CKFINDER_CONNECTOR_ACL_FILE_VIEW);
153
-                if (!$isAuthorized) {
154
-                    $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED);
155
-                }
156
-
157
-                // check #8 (invalid file name)
158
-                if (!file_exists($sourceFilePath) || !is_file($sourceFilePath)) {
159
-                    $errorCode = CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND;
160
-                    $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
161
-                    continue;
162
-                }
163
-
164
-                // check #9 (max size)
165
-                if ($currentResourceTypeConfig->getName() != $type) {
166
-                    $maxSize = $currentResourceTypeConfig->getMaxSize();
167
-                    $fileSize = filesize($sourceFilePath);
168
-                    if ($maxSize && $fileSize>$maxSize) {
169
-                        $errorCode = CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG;
170
-                        $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
171
-                        continue;
172
-                    }
173
-                }
174
-
175
-                //$overwrite
176
-                // finally, no errors so far, we may attempt to copy a file
177
-                // protection against copying files to itself
178
-                if ($sourceFilePath == $destinationFilePath) {
179
-                    $errorCode = CKFINDER_CONNECTOR_ERROR_SOURCE_AND_TARGET_PATH_EQUAL;
180
-                    $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
181
-                    continue;
182
-                }
183
-                // check if file exists if we don't force overwriting
184
-                else if (file_exists($destinationFilePath) && strpos($options, "overwrite") === false) {
185
-                    if (strpos($options, "autorename") !== false) {
186
-                        $iCounter = 1;
187
-                        while (true)
188
-                        {
189
-                            $fileName = CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($name) .
190
-                                "(" . $iCounter . ")" . "." .
191
-                                CKFinder_Connector_Utils_FileSystem::getExtension($name);
192
-
193
-                            $destinationFilePath = $sServerDir.$fileName;
194
-                            if (!file_exists($destinationFilePath)) {
195
-                                break;
196
-                            }
197
-                            else {
198
-                                $iCounter++;
199
-                            }
200
-                        }
201
-                        if (!@copy($sourceFilePath, $destinationFilePath)) {
202
-                            $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED;
203
-                            $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
204
-                            continue;
205
-                        }
206
-                        else {
207
-                            $copied++;
208
-                        }
209
-                    }
210
-                    else {
211
-                        $errorCode = CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST;
212
-                        $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
213
-                        continue;
214
-                    }
215
-                }
216
-                // copy() overwrites without warning
217
-                else {
218
-                    if (!@copy($sourceFilePath, $destinationFilePath)) {
219
-                        $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED;
220
-                        $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
221
-                        continue;
222
-                    }
223
-                    else {
224
-                        $copied++;
225
-                    }
226
-                }
227
-            }
228
-        }
229
-
230
-        $this->_connectorNode->addChild($oCopyFilesNode);
231
-        if ($errorCode != CKFINDER_CONNECTOR_ERROR_NONE) {
232
-            $this->_connectorNode->addChild($oErrorsNode);
233
-        }
234
-        $oCopyFilesNode->addAttribute("copied", $copied);
235
-        $oCopyFilesNode->addAttribute("copiedTotal", $copiedAll + $copied);
236
-
237
-        /**
238
-         * Note: actually we could have more than one error.
239
-         * This is just a flag for CKFinder interface telling it to check all errors.
240
-         */
241
-        if ($errorCode != CKFINDER_CONNECTOR_ERROR_NONE) {
242
-            $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_COPY_FAILED);
243
-        }
244
-    }
245
-
246
-    private function appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path)
247
-    {
248
-        $oErrorNode = new CKFinder_Connector_Utils_XmlNode("Error");
249
-        $oErrorNode->addAttribute("code", $errorCode);
250
-        $oErrorNode->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($name));
251
-        $oErrorNode->addAttribute("type", $type);
252
-        $oErrorNode->addAttribute("folder", $path);
253
-        $oErrorsNode->addChild($oErrorNode);
254
-    }
35
+	/**
36
+	 * Command name
37
+	 *
38
+	 * @access private
39
+	 * @var string
40
+	 */
41
+	private $command = "CopyFiles";
42
+
43
+
44
+	/**
45
+	 * handle request and build XML
46
+	 * @access protected
47
+	 *
48
+	 */
49
+	protected function buildXml()
50
+	{
51
+		if (empty($_POST['CKFinderCommand']) || $_POST['CKFinderCommand'] != 'true') {
52
+			$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
53
+		}
54
+
55
+		$clientPath = $this->_currentFolder->getClientPath();
56
+		$sServerDir = $this->_currentFolder->getServerPath();
57
+		$currentResourceTypeConfig = $this->_currentFolder->getResourceTypeConfig();
58
+		$_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
59
+		$_aclConfig = $_config->getAccessControlConfig();
60
+		$aclMasks = array();
61
+		$_resourceTypeConfig = array();
62
+
63
+		if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_RENAME | CKFINDER_CONNECTOR_ACL_FILE_UPLOAD | CKFINDER_CONNECTOR_ACL_FILE_DELETE)) {
64
+			$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED);
65
+		}
66
+
67
+		// Create the "Errors" node.
68
+		$oErrorsNode = new CKFinder_Connector_Utils_XmlNode("Errors");
69
+		$errorCode = CKFINDER_CONNECTOR_ERROR_NONE;
70
+		$copied = 0;
71
+		$copiedAll = 0;
72
+		if (!empty($_POST['copied'])) {
73
+			$copiedAll = intval($_POST['copied']);
74
+		}
75
+		$checkedPaths = array();
76
+
77
+		$oCopyFilesNode = new Ckfinder_Connector_Utils_XmlNode("CopyFiles");
78
+
79
+		if (!empty($_POST['files']) && is_array($_POST['files'])) {
80
+			foreach ($_POST['files'] as $index => $arr) {
81
+				if (empty($arr['name'])) {
82
+					continue;
83
+				}
84
+				if (!isset($arr['name'], $arr['type'], $arr['folder'])) {
85
+					$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
86
+				}
87
+
88
+				// file name
89
+				$name = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($arr['name']);
90
+				// resource type
91
+				$type = $arr['type'];
92
+				// client path
93
+				$path = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($arr['folder']);
94
+				// options
95
+				$options = (!empty($arr['options'])) ? $arr['options'] : '';
96
+
97
+				$destinationFilePath = $sServerDir.$name;
98
+
99
+				// check #1 (path)
100
+				if (!CKFinder_Connector_Utils_FileSystem::checkFileName($name) || preg_match(CKFINDER_REGEX_INVALID_PATH, $path)) {
101
+					$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
102
+				}
103
+
104
+				// get resource type config for current file
105
+				if (!isset($_resourceTypeConfig[$type])) {
106
+					$_resourceTypeConfig[$type] = $_config->getResourceTypeConfig($type);
107
+				}
108
+
109
+				// check #2 (resource type)
110
+				if (is_null($_resourceTypeConfig[$type])) {
111
+					$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
112
+				}
113
+
114
+				// check #3 (extension)
115
+				if (!$_resourceTypeConfig[$type]->checkExtension($name, false)) {
116
+					$errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION;
117
+					$this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
118
+					continue;
119
+				}
120
+
121
+				// check #4 (extension) - when moving to another resource type, double check extension
122
+				if ($currentResourceTypeConfig->getName() != $type) {
123
+					if (!$currentResourceTypeConfig->checkExtension($name, false)) {
124
+						$errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION;
125
+						$this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
126
+						continue;
127
+					}
128
+				}
129
+
130
+				// check #5 (hidden folders)
131
+				// cache results
132
+				if (empty($checkedPaths[$path])) {
133
+					$checkedPaths[$path] = true;
134
+
135
+					if ($_resourceTypeConfig[$type]->checkIsHiddenPath($path)) {
136
+						$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
137
+					}
138
+				}
139
+
140
+				$sourceFilePath = $_resourceTypeConfig[$type]->getDirectory().$path.$name;
141
+
142
+				// check #6 (hidden file name)
143
+				if ($currentResourceTypeConfig->checkIsHiddenFile($name)) {
144
+					$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
145
+				}
146
+
147
+				// check #7 (Access Control, need file view permission to source files)
148
+				if (!isset($aclMasks[$type."@".$path])) {
149
+					$aclMasks[$type."@".$path] = $_aclConfig->getComputedMask($type, $path);
150
+				}
151
+
152
+				$isAuthorized = (($aclMasks[$type."@".$path] & CKFINDER_CONNECTOR_ACL_FILE_VIEW) == CKFINDER_CONNECTOR_ACL_FILE_VIEW);
153
+				if (!$isAuthorized) {
154
+					$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED);
155
+				}
156
+
157
+				// check #8 (invalid file name)
158
+				if (!file_exists($sourceFilePath) || !is_file($sourceFilePath)) {
159
+					$errorCode = CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND;
160
+					$this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
161
+					continue;
162
+				}
163
+
164
+				// check #9 (max size)
165
+				if ($currentResourceTypeConfig->getName() != $type) {
166
+					$maxSize = $currentResourceTypeConfig->getMaxSize();
167
+					$fileSize = filesize($sourceFilePath);
168
+					if ($maxSize && $fileSize>$maxSize) {
169
+						$errorCode = CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG;
170
+						$this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
171
+						continue;
172
+					}
173
+				}
174
+
175
+				//$overwrite
176
+				// finally, no errors so far, we may attempt to copy a file
177
+				// protection against copying files to itself
178
+				if ($sourceFilePath == $destinationFilePath) {
179
+					$errorCode = CKFINDER_CONNECTOR_ERROR_SOURCE_AND_TARGET_PATH_EQUAL;
180
+					$this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
181
+					continue;
182
+				}
183
+				// check if file exists if we don't force overwriting
184
+				else if (file_exists($destinationFilePath) && strpos($options, "overwrite") === false) {
185
+					if (strpos($options, "autorename") !== false) {
186
+						$iCounter = 1;
187
+						while (true)
188
+						{
189
+							$fileName = CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($name) .
190
+								"(" . $iCounter . ")" . "." .
191
+								CKFinder_Connector_Utils_FileSystem::getExtension($name);
192
+
193
+							$destinationFilePath = $sServerDir.$fileName;
194
+							if (!file_exists($destinationFilePath)) {
195
+								break;
196
+							}
197
+							else {
198
+								$iCounter++;
199
+							}
200
+						}
201
+						if (!@copy($sourceFilePath, $destinationFilePath)) {
202
+							$errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED;
203
+							$this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
204
+							continue;
205
+						}
206
+						else {
207
+							$copied++;
208
+						}
209
+					}
210
+					else {
211
+						$errorCode = CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST;
212
+						$this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
213
+						continue;
214
+					}
215
+				}
216
+				// copy() overwrites without warning
217
+				else {
218
+					if (!@copy($sourceFilePath, $destinationFilePath)) {
219
+						$errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED;
220
+						$this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
221
+						continue;
222
+					}
223
+					else {
224
+						$copied++;
225
+					}
226
+				}
227
+			}
228
+		}
229
+
230
+		$this->_connectorNode->addChild($oCopyFilesNode);
231
+		if ($errorCode != CKFINDER_CONNECTOR_ERROR_NONE) {
232
+			$this->_connectorNode->addChild($oErrorsNode);
233
+		}
234
+		$oCopyFilesNode->addAttribute("copied", $copied);
235
+		$oCopyFilesNode->addAttribute("copiedTotal", $copiedAll + $copied);
236
+
237
+		/**
238
+		 * Note: actually we could have more than one error.
239
+		 * This is just a flag for CKFinder interface telling it to check all errors.
240
+		 */
241
+		if ($errorCode != CKFINDER_CONNECTOR_ERROR_NONE) {
242
+			$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_COPY_FAILED);
243
+		}
244
+	}
245
+
246
+	private function appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path)
247
+	{
248
+		$oErrorNode = new CKFinder_Connector_Utils_XmlNode("Error");
249
+		$oErrorNode->addAttribute("code", $errorCode);
250
+		$oErrorNode->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($name));
251
+		$oErrorNode->addAttribute("type", $type);
252
+		$oErrorNode->addAttribute("folder", $path);
253
+		$oErrorsNode->addChild($oErrorNode);
254
+	}
255 255
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 /**
22 22
  * Include base XML command handler
23 23
  */
24
-require_once CKFINDER_CONNECTOR_LIB_DIR . "/CommandHandler/XmlCommandHandlerBase.php";
24
+require_once CKFINDER_CONNECTOR_LIB_DIR."/CommandHandler/XmlCommandHandlerBase.php";
25 25
 
26 26
 /**
27 27
  * Handle CopyFiles command
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
         $clientPath = $this->_currentFolder->getClientPath();
56 56
         $sServerDir = $this->_currentFolder->getServerPath();
57 57
         $currentResourceTypeConfig = $this->_currentFolder->getResourceTypeConfig();
58
-        $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
58
+        $_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config");
59 59
         $_aclConfig = $_config->getAccessControlConfig();
60 60
         $aclMasks = array();
61 61
         $_resourceTypeConfig = array();
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
                 if ($currentResourceTypeConfig->getName() != $type) {
166 166
                     $maxSize = $currentResourceTypeConfig->getMaxSize();
167 167
                     $fileSize = filesize($sourceFilePath);
168
-                    if ($maxSize && $fileSize>$maxSize) {
168
+                    if ($maxSize && $fileSize > $maxSize) {
169 169
                         $errorCode = CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG;
170 170
                         $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
171 171
                         continue;
@@ -186,8 +186,8 @@  discard block
 block discarded – undo
186 186
                         $iCounter = 1;
187 187
                         while (true)
188 188
                         {
189
-                            $fileName = CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($name) .
190
-                                "(" . $iCounter . ")" . "." .
189
+                            $fileName = CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($name).
190
+                                "(".$iCounter.")".".".
191 191
                                 CKFinder_Connector_Utils_FileSystem::getExtension($name);
192 192
 
193 193
                             $destinationFilePath = $sServerDir.$fileName;
Please login to merge, or discard this patch.
Braces   +7 added lines, -9 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@  discard block
 block discarded – undo
10 10
  * modifying or distribute this file or part of its contents. The contents of
11 11
  * this file is part of the Source Code of CKFinder.
12 12
  */
13
-if (!defined('IN_CKFINDER')) exit;
13
+if (!defined('IN_CKFINDER')) {
14
+	exit;
15
+}
14 16
 
15 17
 /**
16 18
  * @package CKFinder
@@ -193,8 +195,7 @@  discard block
 block discarded – undo
193 195
                             $destinationFilePath = $sServerDir.$fileName;
194 196
                             if (!file_exists($destinationFilePath)) {
195 197
                                 break;
196
-                            }
197
-                            else {
198
+                            } else {
198 199
                                 $iCounter++;
199 200
                             }
200 201
                         }
@@ -202,12 +203,10 @@  discard block
 block discarded – undo
202 203
                             $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED;
203 204
                             $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
204 205
                             continue;
205
-                        }
206
-                        else {
206
+                        } else {
207 207
                             $copied++;
208 208
                         }
209
-                    }
210
-                    else {
209
+                    } else {
211 210
                         $errorCode = CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST;
212 211
                         $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
213 212
                         continue;
@@ -219,8 +218,7 @@  discard block
 block discarded – undo
219 218
                         $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED;
220 219
                         $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
221 220
                         continue;
222
-                    }
223
-                    else {
221
+                    } else {
224 222
                         $copied++;
225 223
                     }
226 224
                 }
Please login to merge, or discard this patch.
libs/ckfinder/core/connector/php/php5/CommandHandler/MoveFiles.php 4 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -259,6 +259,10 @@
 block discarded – undo
259 259
         }
260 260
     }
261 261
 
262
+    /**
263
+     * @param integer $errorCode
264
+     * @param string $path
265
+     */
262 266
     private function appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path)
263 267
     {
264 268
         $oErrorNode = new CKFinder_Connector_Utils_XmlNode("Error");
Please login to merge, or discard this patch.
Indentation   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -32,240 +32,240 @@
 block discarded – undo
32 32
  */
33 33
 class CKFinder_Connector_CommandHandler_MoveFiles extends CKFinder_Connector_CommandHandler_XmlCommandHandlerBase
34 34
 {
35
-    /**
36
-     * Command name
37
-     *
38
-     * @access private
39
-     * @var string
40
-     */
41
-    private $command = "MoveFiles";
35
+	/**
36
+	 * Command name
37
+	 *
38
+	 * @access private
39
+	 * @var string
40
+	 */
41
+	private $command = "MoveFiles";
42 42
 
43 43
 
44
-    /**
45
-     * handle request and build XML
46
-     * @access protected
47
-     *
48
-     */
49
-    protected function buildXml()
50
-    {
51
-        if (empty($_POST['CKFinderCommand']) || $_POST['CKFinderCommand'] != 'true') {
52
-            $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
53
-        }
44
+	/**
45
+	 * handle request and build XML
46
+	 * @access protected
47
+	 *
48
+	 */
49
+	protected function buildXml()
50
+	{
51
+		if (empty($_POST['CKFinderCommand']) || $_POST['CKFinderCommand'] != 'true') {
52
+			$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
53
+		}
54 54
 
55
-        $clientPath = $this->_currentFolder->getClientPath();
56
-        $sServerDir = $this->_currentFolder->getServerPath();
57
-        $currentResourceTypeConfig = $this->_currentFolder->getResourceTypeConfig();
58
-        $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
59
-        $_aclConfig = $_config->getAccessControlConfig();
60
-        $aclMasks = array();
61
-        $_resourceTypeConfig = array();
55
+		$clientPath = $this->_currentFolder->getClientPath();
56
+		$sServerDir = $this->_currentFolder->getServerPath();
57
+		$currentResourceTypeConfig = $this->_currentFolder->getResourceTypeConfig();
58
+		$_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
59
+		$_aclConfig = $_config->getAccessControlConfig();
60
+		$aclMasks = array();
61
+		$_resourceTypeConfig = array();
62 62
 
63
-        if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_RENAME | CKFINDER_CONNECTOR_ACL_FILE_UPLOAD | CKFINDER_CONNECTOR_ACL_FILE_DELETE)) {
64
-            $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED);
65
-        }
63
+		if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FILE_RENAME | CKFINDER_CONNECTOR_ACL_FILE_UPLOAD | CKFINDER_CONNECTOR_ACL_FILE_DELETE)) {
64
+			$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED);
65
+		}
66 66
 
67
-        // Create the "Errors" node.
68
-        $oErrorsNode = new CKFinder_Connector_Utils_XmlNode("Errors");
69
-        $errorCode = CKFINDER_CONNECTOR_ERROR_NONE;
70
-        $moved = 0;
71
-        $movedAll = 0;
72
-        if (!empty($_POST['moved'])) {
73
-            $movedAll = intval($_POST['moved']);
74
-        }
75
-        $checkedPaths = array();
67
+		// Create the "Errors" node.
68
+		$oErrorsNode = new CKFinder_Connector_Utils_XmlNode("Errors");
69
+		$errorCode = CKFINDER_CONNECTOR_ERROR_NONE;
70
+		$moved = 0;
71
+		$movedAll = 0;
72
+		if (!empty($_POST['moved'])) {
73
+			$movedAll = intval($_POST['moved']);
74
+		}
75
+		$checkedPaths = array();
76 76
 
77
-        $oMoveFilesNode = new Ckfinder_Connector_Utils_XmlNode("MoveFiles");
77
+		$oMoveFilesNode = new Ckfinder_Connector_Utils_XmlNode("MoveFiles");
78 78
 
79
-        if (!empty($_POST['files']) && is_array($_POST['files'])) {
80
-            foreach ($_POST['files'] as $index => $arr) {
81
-                if (empty($arr['name'])) {
82
-                    continue;
83
-                }
84
-                if (!isset($arr['name'], $arr['type'], $arr['folder'])) {
85
-                    $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
86
-                }
79
+		if (!empty($_POST['files']) && is_array($_POST['files'])) {
80
+			foreach ($_POST['files'] as $index => $arr) {
81
+				if (empty($arr['name'])) {
82
+					continue;
83
+				}
84
+				if (!isset($arr['name'], $arr['type'], $arr['folder'])) {
85
+					$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
86
+				}
87 87
 
88
-                // file name
89
-                $name = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($arr['name']);
90
-                // resource type
91
-                $type = $arr['type'];
92
-                // client path
93
-                $path = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($arr['folder']);
94
-                // options
95
-                $options = (!empty($arr['options'])) ? $arr['options'] : '';
88
+				// file name
89
+				$name = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($arr['name']);
90
+				// resource type
91
+				$type = $arr['type'];
92
+				// client path
93
+				$path = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($arr['folder']);
94
+				// options
95
+				$options = (!empty($arr['options'])) ? $arr['options'] : '';
96 96
 
97
-                $destinationFilePath = $sServerDir.$name;
97
+				$destinationFilePath = $sServerDir.$name;
98 98
 
99
-                // check #1 (path)
100
-                if (!CKFinder_Connector_Utils_FileSystem::checkFileName($name) || preg_match(CKFINDER_REGEX_INVALID_PATH, $path)) {
101
-                    $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
102
-                }
99
+				// check #1 (path)
100
+				if (!CKFinder_Connector_Utils_FileSystem::checkFileName($name) || preg_match(CKFINDER_REGEX_INVALID_PATH, $path)) {
101
+					$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
102
+				}
103 103
 
104
-                // get resource type config for current file
105
-                if (!isset($_resourceTypeConfig[$type])) {
106
-                    $_resourceTypeConfig[$type] = $_config->getResourceTypeConfig($type);
107
-                }
104
+				// get resource type config for current file
105
+				if (!isset($_resourceTypeConfig[$type])) {
106
+					$_resourceTypeConfig[$type] = $_config->getResourceTypeConfig($type);
107
+				}
108 108
 
109
-                // check #2 (resource type)
110
-                if (is_null($_resourceTypeConfig[$type])) {
111
-                    $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
112
-                }
109
+				// check #2 (resource type)
110
+				if (is_null($_resourceTypeConfig[$type])) {
111
+					$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
112
+				}
113 113
 
114
-                // check #3 (extension)
115
-                if (!$_resourceTypeConfig[$type]->checkExtension($name, false)) {
116
-                    $errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION;
117
-                    $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
118
-                    continue;
119
-                }
114
+				// check #3 (extension)
115
+				if (!$_resourceTypeConfig[$type]->checkExtension($name, false)) {
116
+					$errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION;
117
+					$this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
118
+					continue;
119
+				}
120 120
 
121
-                // check #4 (extension) - when moving to another resource type, double check extension
122
-                if ($currentResourceTypeConfig->getName() != $type) {
123
-                    if (!$currentResourceTypeConfig->checkExtension($name, false)) {
124
-                        $errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION;
125
-                        $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
126
-                        continue;
127
-                    }
128
-                }
121
+				// check #4 (extension) - when moving to another resource type, double check extension
122
+				if ($currentResourceTypeConfig->getName() != $type) {
123
+					if (!$currentResourceTypeConfig->checkExtension($name, false)) {
124
+						$errorCode = CKFINDER_CONNECTOR_ERROR_INVALID_EXTENSION;
125
+						$this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
126
+						continue;
127
+					}
128
+				}
129 129
 
130
-                // check #5 (hidden folders)
131
-                // cache results
132
-                if (empty($checkedPaths[$path])) {
133
-                    $checkedPaths[$path] = true;
130
+				// check #5 (hidden folders)
131
+				// cache results
132
+				if (empty($checkedPaths[$path])) {
133
+					$checkedPaths[$path] = true;
134 134
 
135
-                    if ($_resourceTypeConfig[$type]->checkIsHiddenPath($path)) {
136
-                        $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
137
-                    }
138
-                }
135
+					if ($_resourceTypeConfig[$type]->checkIsHiddenPath($path)) {
136
+						$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
137
+					}
138
+				}
139 139
 
140
-                $sourceFilePath = $_resourceTypeConfig[$type]->getDirectory().$path.$name;
140
+				$sourceFilePath = $_resourceTypeConfig[$type]->getDirectory().$path.$name;
141 141
 
142
-                // check #6 (hidden file name)
143
-                if ($currentResourceTypeConfig->checkIsHiddenFile($name)) {
144
-                    $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
145
-                }
142
+				// check #6 (hidden file name)
143
+				if ($currentResourceTypeConfig->checkIsHiddenFile($name)) {
144
+					$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST);
145
+				}
146 146
 
147
-                // check #7 (Access Control, need file view permission to source files)
148
-                if (!isset($aclMasks[$type."@".$path])) {
149
-                    $aclMasks[$type."@".$path] = $_aclConfig->getComputedMask($type, $path);
150
-                }
147
+				// check #7 (Access Control, need file view permission to source files)
148
+				if (!isset($aclMasks[$type."@".$path])) {
149
+					$aclMasks[$type."@".$path] = $_aclConfig->getComputedMask($type, $path);
150
+				}
151 151
 
152
-                $isAuthorized = (($aclMasks[$type."@".$path] & CKFINDER_CONNECTOR_ACL_FILE_VIEW) == CKFINDER_CONNECTOR_ACL_FILE_VIEW);
153
-                if (!$isAuthorized) {
154
-                    $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED);
155
-                }
152
+				$isAuthorized = (($aclMasks[$type."@".$path] & CKFINDER_CONNECTOR_ACL_FILE_VIEW) == CKFINDER_CONNECTOR_ACL_FILE_VIEW);
153
+				if (!$isAuthorized) {
154
+					$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED);
155
+				}
156 156
 
157
-                // check #8 (invalid file name)
158
-                if (!file_exists($sourceFilePath) || !is_file($sourceFilePath)) {
159
-                    $errorCode = CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND;
160
-                    $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
161
-                    continue;
162
-                }
157
+				// check #8 (invalid file name)
158
+				if (!file_exists($sourceFilePath) || !is_file($sourceFilePath)) {
159
+					$errorCode = CKFINDER_CONNECTOR_ERROR_FILE_NOT_FOUND;
160
+					$this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
161
+					continue;
162
+				}
163 163
 
164
-                // check #9 (max size)
165
-                if ($currentResourceTypeConfig->getName() != $type) {
166
-                    $maxSize = $currentResourceTypeConfig->getMaxSize();
167
-                    $fileSize = filesize($sourceFilePath);
168
-                    if ($maxSize && $fileSize>$maxSize) {
169
-                        $errorCode = CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG;
170
-                        $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
171
-                        continue;
172
-                    }
173
-                }
164
+				// check #9 (max size)
165
+				if ($currentResourceTypeConfig->getName() != $type) {
166
+					$maxSize = $currentResourceTypeConfig->getMaxSize();
167
+					$fileSize = filesize($sourceFilePath);
168
+					if ($maxSize && $fileSize>$maxSize) {
169
+						$errorCode = CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG;
170
+						$this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
171
+						continue;
172
+					}
173
+				}
174 174
 
175
-                //$overwrite
176
-                // finally, no errors so far, we may attempt to copy a file
177
-                // protection against copying files to itself
178
-                if ($sourceFilePath == $destinationFilePath) {
179
-                    $errorCode = CKFINDER_CONNECTOR_ERROR_SOURCE_AND_TARGET_PATH_EQUAL;
180
-                    $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
181
-                    continue;
182
-                }
183
-                // check if file exists if we don't force overwriting
184
-                else if (file_exists($destinationFilePath)) {
185
-                    if (strpos($options, "overwrite") !== false) {
186
-                        if (!@unlink($destinationFilePath)) {
187
-                            $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED;
188
-                            $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
189
-                            continue;
190
-                        }
191
-                        else {
192
-                            if (!@rename($sourceFilePath, $destinationFilePath)) {
193
-                                $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED;
194
-                                $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
195
-                                continue;
196
-                            }
197
-                            else {
198
-                                $moved++;
199
-                            }
200
-                        }
201
-                    }
202
-                    else if (strpos($options, "autorename") !== false) {
203
-                        $iCounter = 1;
204
-                        while (true)
205
-                        {
206
-                            $fileName = CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($name) .
207
-                                "(" . $iCounter . ")" . "." .
208
-                                CKFinder_Connector_Utils_FileSystem::getExtension($name);
175
+				//$overwrite
176
+				// finally, no errors so far, we may attempt to copy a file
177
+				// protection against copying files to itself
178
+				if ($sourceFilePath == $destinationFilePath) {
179
+					$errorCode = CKFINDER_CONNECTOR_ERROR_SOURCE_AND_TARGET_PATH_EQUAL;
180
+					$this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
181
+					continue;
182
+				}
183
+				// check if file exists if we don't force overwriting
184
+				else if (file_exists($destinationFilePath)) {
185
+					if (strpos($options, "overwrite") !== false) {
186
+						if (!@unlink($destinationFilePath)) {
187
+							$errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED;
188
+							$this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
189
+							continue;
190
+						}
191
+						else {
192
+							if (!@rename($sourceFilePath, $destinationFilePath)) {
193
+								$errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED;
194
+								$this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
195
+								continue;
196
+							}
197
+							else {
198
+								$moved++;
199
+							}
200
+						}
201
+					}
202
+					else if (strpos($options, "autorename") !== false) {
203
+						$iCounter = 1;
204
+						while (true)
205
+						{
206
+							$fileName = CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($name) .
207
+								"(" . $iCounter . ")" . "." .
208
+								CKFinder_Connector_Utils_FileSystem::getExtension($name);
209 209
 
210
-                            $destinationFilePath = $sServerDir.$fileName;
211
-                            if (!file_exists($destinationFilePath)) {
212
-                                break;
213
-                            }
214
-                            else {
215
-                                $iCounter++;
216
-                            }
217
-                        }
218
-                        if (!@rename($sourceFilePath, $destinationFilePath)) {
219
-                            $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED;
220
-                            $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
221
-                            continue;
222
-                        }
223
-                        else {
224
-                            $moved++;
225
-                        }
226
-                    }
227
-                    else {
228
-                        $errorCode = CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST;
229
-                        $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
230
-                        continue;
231
-                    }
232
-                }
233
-                else {
234
-                    if (!@rename($sourceFilePath, $destinationFilePath)) {
235
-                        $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED;
236
-                        $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
237
-                        continue;
238
-                    }
239
-                    else {
240
-                        $moved++;
241
-                    }
242
-                }
243
-            }
244
-        }
210
+							$destinationFilePath = $sServerDir.$fileName;
211
+							if (!file_exists($destinationFilePath)) {
212
+								break;
213
+							}
214
+							else {
215
+								$iCounter++;
216
+							}
217
+						}
218
+						if (!@rename($sourceFilePath, $destinationFilePath)) {
219
+							$errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED;
220
+							$this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
221
+							continue;
222
+						}
223
+						else {
224
+							$moved++;
225
+						}
226
+					}
227
+					else {
228
+						$errorCode = CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST;
229
+						$this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
230
+						continue;
231
+					}
232
+				}
233
+				else {
234
+					if (!@rename($sourceFilePath, $destinationFilePath)) {
235
+						$errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED;
236
+						$this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
237
+						continue;
238
+					}
239
+					else {
240
+						$moved++;
241
+					}
242
+				}
243
+			}
244
+		}
245 245
 
246
-        $this->_connectorNode->addChild($oMoveFilesNode);
247
-        if ($errorCode != CKFINDER_CONNECTOR_ERROR_NONE) {
248
-            $this->_connectorNode->addChild($oErrorsNode);
249
-        }
250
-        $oMoveFilesNode->addAttribute("moved", $moved);
251
-        $oMoveFilesNode->addAttribute("movedTotal", $movedAll + $moved);
246
+		$this->_connectorNode->addChild($oMoveFilesNode);
247
+		if ($errorCode != CKFINDER_CONNECTOR_ERROR_NONE) {
248
+			$this->_connectorNode->addChild($oErrorsNode);
249
+		}
250
+		$oMoveFilesNode->addAttribute("moved", $moved);
251
+		$oMoveFilesNode->addAttribute("movedTotal", $movedAll + $moved);
252 252
 
253
-        /**
254
-         * Note: actually we could have more than one error.
255
-         * This is just a flag for CKFinder interface telling it to check all errors.
256
-         */
257
-        if ($errorCode != CKFINDER_CONNECTOR_ERROR_NONE) {
258
-            $this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_MOVE_FAILED);
259
-        }
260
-    }
253
+		/**
254
+		 * Note: actually we could have more than one error.
255
+		 * This is just a flag for CKFinder interface telling it to check all errors.
256
+		 */
257
+		if ($errorCode != CKFINDER_CONNECTOR_ERROR_NONE) {
258
+			$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_MOVE_FAILED);
259
+		}
260
+	}
261 261
 
262
-    private function appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path)
263
-    {
264
-        $oErrorNode = new CKFinder_Connector_Utils_XmlNode("Error");
265
-        $oErrorNode->addAttribute("code", $errorCode);
266
-        $oErrorNode->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($name));
267
-        $oErrorNode->addAttribute("type", $type);
268
-        $oErrorNode->addAttribute("folder", $path);
269
-        $oErrorsNode->addChild($oErrorNode);
270
-    }
262
+	private function appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path)
263
+	{
264
+		$oErrorNode = new CKFinder_Connector_Utils_XmlNode("Error");
265
+		$oErrorNode->addAttribute("code", $errorCode);
266
+		$oErrorNode->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($name));
267
+		$oErrorNode->addAttribute("type", $type);
268
+		$oErrorNode->addAttribute("folder", $path);
269
+		$oErrorsNode->addChild($oErrorNode);
270
+	}
271 271
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 /**
22 22
  * Include base XML command handler
23 23
  */
24
-require_once CKFINDER_CONNECTOR_LIB_DIR . "/CommandHandler/XmlCommandHandlerBase.php";
24
+require_once CKFINDER_CONNECTOR_LIB_DIR."/CommandHandler/XmlCommandHandlerBase.php";
25 25
 
26 26
 /**
27 27
  * Handle MoveFiles command
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
         $clientPath = $this->_currentFolder->getClientPath();
56 56
         $sServerDir = $this->_currentFolder->getServerPath();
57 57
         $currentResourceTypeConfig = $this->_currentFolder->getResourceTypeConfig();
58
-        $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
58
+        $_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config");
59 59
         $_aclConfig = $_config->getAccessControlConfig();
60 60
         $aclMasks = array();
61 61
         $_resourceTypeConfig = array();
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
                 if ($currentResourceTypeConfig->getName() != $type) {
166 166
                     $maxSize = $currentResourceTypeConfig->getMaxSize();
167 167
                     $fileSize = filesize($sourceFilePath);
168
-                    if ($maxSize && $fileSize>$maxSize) {
168
+                    if ($maxSize && $fileSize > $maxSize) {
169 169
                         $errorCode = CKFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG;
170 170
                         $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
171 171
                         continue;
@@ -203,8 +203,8 @@  discard block
 block discarded – undo
203 203
                         $iCounter = 1;
204 204
                         while (true)
205 205
                         {
206
-                            $fileName = CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($name) .
207
-                                "(" . $iCounter . ")" . "." .
206
+                            $fileName = CKFinder_Connector_Utils_FileSystem::getFileNameWithoutExtension($name).
207
+                                "(".$iCounter.")".".".
208 208
                                 CKFinder_Connector_Utils_FileSystem::getExtension($name);
209 209
 
210 210
                             $destinationFilePath = $sServerDir.$fileName;
Please login to merge, or discard this patch.
Braces   +11 added lines, -17 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@  discard block
 block discarded – undo
10 10
  * modifying or distribute this file or part of its contents. The contents of
11 11
  * this file is part of the Source Code of CKFinder.
12 12
  */
13
-if (!defined('IN_CKFINDER')) exit;
13
+if (!defined('IN_CKFINDER')) {
14
+	exit;
15
+}
14 16
 
15 17
 /**
16 18
  * @package CKFinder
@@ -187,19 +189,16 @@  discard block
 block discarded – undo
187 189
                             $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED;
188 190
                             $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
189 191
                             continue;
190
-                        }
191
-                        else {
192
+                        } else {
192 193
                             if (!@rename($sourceFilePath, $destinationFilePath)) {
193 194
                                 $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED;
194 195
                                 $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
195 196
                                 continue;
196
-                            }
197
-                            else {
197
+                            } else {
198 198
                                 $moved++;
199 199
                             }
200 200
                         }
201
-                    }
202
-                    else if (strpos($options, "autorename") !== false) {
201
+                    } else if (strpos($options, "autorename") !== false) {
203 202
                         $iCounter = 1;
204 203
                         while (true)
205 204
                         {
@@ -210,8 +209,7 @@  discard block
 block discarded – undo
210 209
                             $destinationFilePath = $sServerDir.$fileName;
211 210
                             if (!file_exists($destinationFilePath)) {
212 211
                                 break;
213
-                            }
214
-                            else {
212
+                            } else {
215 213
                                 $iCounter++;
216 214
                             }
217 215
                         }
@@ -219,24 +217,20 @@  discard block
 block discarded – undo
219 217
                             $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED;
220 218
                             $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
221 219
                             continue;
222
-                        }
223
-                        else {
220
+                        } else {
224 221
                             $moved++;
225 222
                         }
226
-                    }
227
-                    else {
223
+                    } else {
228 224
                         $errorCode = CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST;
229 225
                         $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
230 226
                         continue;
231 227
                     }
232
-                }
233
-                else {
228
+                } else {
234 229
                     if (!@rename($sourceFilePath, $destinationFilePath)) {
235 230
                         $errorCode = CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED;
236 231
                         $this->appendErrorNode($oErrorsNode, $errorCode, $name, $type, $path);
237 232
                         continue;
238
-                    }
239
-                    else {
233
+                    } else {
240 234
                         $moved++;
241 235
                     }
242 236
                 }
Please login to merge, or discard this patch.