Completed
Push — develop ( 62a102...75b835 )
by Maxim
05:41
created
manager/includes/extenders/manager.api.class.inc.php 5 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -192,6 +192,9 @@
 block discarded – undo
192 192
 		return $_;
193 193
 	}
194 194
 
195
+	/**
196
+	 * @param string $checksum
197
+	 */
195 198
 	function setSystemChecksum($checksum) {
196 199
 		global $modx;
197 200
 		$tbl_system_settings = $modx->getFullTableName('system_settings');
Please login to merge, or discard this patch.
Indentation   +183 added lines, -183 removed lines patch added patch discarded remove patch
@@ -10,215 +10,215 @@
 block discarded – undo
10 10
 // Content manager wrapper class
11 11
 class ManagerAPI {
12 12
 	
13
-	var $action; // action directive
13
+    var $action; // action directive
14 14
 
15
-	function __construct(){
16
-		global $action;
17
-		$this->action = $action; // set action directive
18
-	}
15
+    function __construct(){
16
+        global $action;
17
+        $this->action = $action; // set action directive
18
+    }
19 19
 	
20
-	function initPageViewState($id=0){
21
-		global $_PAGE;
22
-		$vsid = isset($_SESSION["mgrPageViewSID"]) ? $_SESSION["mgrPageViewSID"] : '';
23
-		if($vsid!=$this->action) {
24
-			$_SESSION["mgrPageViewSDATA"] = array(); // new view state
25
-			$_SESSION["mgrPageViewSID"] = $id>0 ? $id:$this->action; // set id
26
-		}
27
-		$_PAGE['vs'] = &$_SESSION["mgrPageViewSDATA"]; // restore viewstate
28
-	}
20
+    function initPageViewState($id=0){
21
+        global $_PAGE;
22
+        $vsid = isset($_SESSION["mgrPageViewSID"]) ? $_SESSION["mgrPageViewSID"] : '';
23
+        if($vsid!=$this->action) {
24
+            $_SESSION["mgrPageViewSDATA"] = array(); // new view state
25
+            $_SESSION["mgrPageViewSID"] = $id>0 ? $id:$this->action; // set id
26
+        }
27
+        $_PAGE['vs'] = &$_SESSION["mgrPageViewSDATA"]; // restore viewstate
28
+    }
29 29
 
30
-	// save page view state - not really necessary,
31
-	function savePageViewState($id=0){
32
-		global $_PAGE;
33
-		$_SESSION["mgrPageViewSDATA"] = $_PAGE['vs'];
34
-		$_SESSION["mgrPageViewSID"] = $id>0 ? $id:$this->action;
35
-	}
30
+    // save page view state - not really necessary,
31
+    function savePageViewState($id=0){
32
+        global $_PAGE;
33
+        $_SESSION["mgrPageViewSDATA"] = $_PAGE['vs'];
34
+        $_SESSION["mgrPageViewSID"] = $id>0 ? $id:$this->action;
35
+    }
36 36
 	
37
-	// check for saved form
38
-	function hasFormValues() {
39
-		if(isset($_SESSION["mgrFormValueId"])) {		
40
-			if($this->action==$_SESSION["mgrFormValueId"]) {
41
-				return true;
42
-			}
43
-			else {
44
-				$this->clearSavedFormValues();
45
-			}
46
-		}
47
-		return false;
48
-	}	
49
-	// saved form post from $_POST
50
-	function saveFormValues($id=0){
51
-		$_SESSION["mgrFormValues"] = $_POST;
52
-		$_SESSION["mgrFormValueId"] = $id>0 ? $id:$this->action;
53
-	}		
54
-	// load saved form values into $_POST
55
-	function loadFormValues(){
37
+    // check for saved form
38
+    function hasFormValues() {
39
+        if(isset($_SESSION["mgrFormValueId"])) {		
40
+            if($this->action==$_SESSION["mgrFormValueId"]) {
41
+                return true;
42
+            }
43
+            else {
44
+                $this->clearSavedFormValues();
45
+            }
46
+        }
47
+        return false;
48
+    }	
49
+    // saved form post from $_POST
50
+    function saveFormValues($id=0){
51
+        $_SESSION["mgrFormValues"] = $_POST;
52
+        $_SESSION["mgrFormValueId"] = $id>0 ? $id:$this->action;
53
+    }		
54
+    // load saved form values into $_POST
55
+    function loadFormValues(){
56 56
 		
57
-		if(!$this->hasFormValues()) return false;
57
+        if(!$this->hasFormValues()) return false;
58 58
 		
59
-		$p = $_SESSION["mgrFormValues"];
60
-		$this->clearSavedFormValues();
61
-		foreach($p as $k=>$v) {
62
-			$_POST[$k]=$v;
63
-		}
64
-		return true;
65
-	}
66
-	// clear form post
67
-	function clearSavedFormValues(){
68
-		unset($_SESSION["mgrFormValues"]);
69
-		unset($_SESSION["mgrFormValueId"]);	
70
-	}
59
+        $p = $_SESSION["mgrFormValues"];
60
+        $this->clearSavedFormValues();
61
+        foreach($p as $k=>$v) {
62
+            $_POST[$k]=$v;
63
+        }
64
+        return true;
65
+    }
66
+    // clear form post
67
+    function clearSavedFormValues(){
68
+        unset($_SESSION["mgrFormValues"]);
69
+        unset($_SESSION["mgrFormValueId"]);	
70
+    }
71 71
 	
72
-	function getHashType($db_value='') { // md5 | v1 | phpass
73
-		$c = substr($db_value,0,1);
74
-		if($c==='$')                                      return 'phpass';
75
-		elseif(strlen($db_value)===32)                    return 'md5';
76
-		elseif($c!=='$' && strpos($db_value,'>')!==false) return 'v1';
77
-		else                                              return 'unknown';
78
-	}
72
+    function getHashType($db_value='') { // md5 | v1 | phpass
73
+        $c = substr($db_value,0,1);
74
+        if($c==='$')                                      return 'phpass';
75
+        elseif(strlen($db_value)===32)                    return 'md5';
76
+        elseif($c!=='$' && strpos($db_value,'>')!==false) return 'v1';
77
+        else                                              return 'unknown';
78
+    }
79 79
 	
80
-	function genV1Hash($password, $seed='1')
81
-	{ // $seed is user_id basically
82
-		global $modx;
80
+    function genV1Hash($password, $seed='1')
81
+    { // $seed is user_id basically
82
+        global $modx;
83 83
 		
84
-		if(isset($modx->config['pwd_hash_algo']) && !empty($modx->config['pwd_hash_algo']))
85
-			$algorithm = $modx->config['pwd_hash_algo'];
86
-		else $algorithm = 'UNCRYPT';
84
+        if(isset($modx->config['pwd_hash_algo']) && !empty($modx->config['pwd_hash_algo']))
85
+            $algorithm = $modx->config['pwd_hash_algo'];
86
+        else $algorithm = 'UNCRYPT';
87 87
 		
88
-		$salt = md5($password . $seed);
88
+        $salt = md5($password . $seed);
89 89
 		
90
-		switch($algorithm)
91
-		{
92
-			case 'BLOWFISH_Y':
93
-				$salt = '$2y$07$' . substr($salt,0,22);
94
-				break;
95
-			case 'BLOWFISH_A':
96
-				$salt = '$2a$07$' . substr($salt,0,22);
97
-				break;
98
-			case 'SHA512':
99
-				$salt = '$6$' . substr($salt,0,16);
100
-				break;
101
-			case 'SHA256':
102
-				$salt = '$5$' . substr($salt,0,16);
103
-				break;
104
-			case 'MD5':
105
-				$salt = '$1$' . substr($salt,0,8);
106
-				break;
107
-		}
90
+        switch($algorithm)
91
+        {
92
+            case 'BLOWFISH_Y':
93
+                $salt = '$2y$07$' . substr($salt,0,22);
94
+                break;
95
+            case 'BLOWFISH_A':
96
+                $salt = '$2a$07$' . substr($salt,0,22);
97
+                break;
98
+            case 'SHA512':
99
+                $salt = '$6$' . substr($salt,0,16);
100
+                break;
101
+            case 'SHA256':
102
+                $salt = '$5$' . substr($salt,0,16);
103
+                break;
104
+            case 'MD5':
105
+                $salt = '$1$' . substr($salt,0,8);
106
+                break;
107
+        }
108 108
 		
109
-		if($algorithm!=='UNCRYPT')
110
-		{
111
-			$password = sha1($password) . crypt($password,$salt);
112
-		}
113
-		else $password = sha1($salt.$password);
109
+        if($algorithm!=='UNCRYPT')
110
+        {
111
+            $password = sha1($password) . crypt($password,$salt);
112
+        }
113
+        else $password = sha1($salt.$password);
114 114
 		
115
-		$result = strtolower($algorithm) . '>' . md5($salt.$password) . substr(md5($salt),0,8);
115
+        $result = strtolower($algorithm) . '>' . md5($salt.$password) . substr(md5($salt),0,8);
116 116
 		
117
-		return $result;
118
-	}
117
+        return $result;
118
+    }
119 119
 	
120
-	function getV1UserHashAlgorithm($uid)
121
-	{
122
-		global $modx;
123
-		$tbl_manager_users = $modx->getFullTableName('manager_users');
124
-		$rs = $modx->db->select('password',$tbl_manager_users,"id='{$uid}'");
125
-		$password = $modx->db->getValue($rs);
120
+    function getV1UserHashAlgorithm($uid)
121
+    {
122
+        global $modx;
123
+        $tbl_manager_users = $modx->getFullTableName('manager_users');
124
+        $rs = $modx->db->select('password',$tbl_manager_users,"id='{$uid}'");
125
+        $password = $modx->db->getValue($rs);
126 126
 		
127
-		if(strpos($password,'>')===false) $algo = 'NOSALT';
128
-		else
129
-		{
130
-			$algo = substr($password,0,strpos($password,'>'));
131
-		}
132
-		return strtoupper($algo);
133
-	}
127
+        if(strpos($password,'>')===false) $algo = 'NOSALT';
128
+        else
129
+        {
130
+            $algo = substr($password,0,strpos($password,'>'));
131
+        }
132
+        return strtoupper($algo);
133
+    }
134 134
 	
135
-	function checkHashAlgorithm($algorithm='')
136
-	{
137
-		$result = false;
138
-		if (!empty($algorithm))
139
-		{
140
-			switch ($algorithm)
141
-			{
142
-				case 'BLOWFISH_Y':
143
-					if (defined('CRYPT_BLOWFISH') && CRYPT_BLOWFISH == 1)
144
-					{
145
-						if (version_compare('5.3.7', PHP_VERSION) <= 0) $result = true;
146
-					}
147
-					break;
148
-				case 'BLOWFISH_A':
149
-					if (defined('CRYPT_BLOWFISH') && CRYPT_BLOWFISH == 1) $result = true;
150
-					break;
151
-				case 'SHA512':
152
-					if (defined('CRYPT_SHA512') && CRYPT_SHA512 == 1) $result = true;
153
-					break;
154
-				case 'SHA256':
155
-					if (defined('CRYPT_SHA256') && CRYPT_SHA256 == 1) $result = true;
156
-					break;
157
-				case 'MD5':
158
-					if (defined('CRYPT_MD5') && CRYPT_MD5 == 1 && PHP_VERSION != '5.3.7') $result = true;
159
-					break;
160
-				case 'UNCRYPT':
161
-					$result = true;
162
-					break;
163
-			}
164
-		}
165
-		return $result;
166
-	}
135
+    function checkHashAlgorithm($algorithm='')
136
+    {
137
+        $result = false;
138
+        if (!empty($algorithm))
139
+        {
140
+            switch ($algorithm)
141
+            {
142
+                case 'BLOWFISH_Y':
143
+                    if (defined('CRYPT_BLOWFISH') && CRYPT_BLOWFISH == 1)
144
+                    {
145
+                        if (version_compare('5.3.7', PHP_VERSION) <= 0) $result = true;
146
+                    }
147
+                    break;
148
+                case 'BLOWFISH_A':
149
+                    if (defined('CRYPT_BLOWFISH') && CRYPT_BLOWFISH == 1) $result = true;
150
+                    break;
151
+                case 'SHA512':
152
+                    if (defined('CRYPT_SHA512') && CRYPT_SHA512 == 1) $result = true;
153
+                    break;
154
+                case 'SHA256':
155
+                    if (defined('CRYPT_SHA256') && CRYPT_SHA256 == 1) $result = true;
156
+                    break;
157
+                case 'MD5':
158
+                    if (defined('CRYPT_MD5') && CRYPT_MD5 == 1 && PHP_VERSION != '5.3.7') $result = true;
159
+                    break;
160
+                case 'UNCRYPT':
161
+                    $result = true;
162
+                    break;
163
+            }
164
+        }
165
+        return $result;
166
+    }
167 167
 
168
-	function getSystemChecksum($check_files) {
169
-		$_ = array();
170
-		$check_files = trim($check_files);
171
-		$check_files = explode("\n", $check_files);
172
-		foreach($check_files as $file) {
173
-			$file = trim($file);
174
-			$file = MODX_BASE_PATH . $file;
175
-			if(!is_file($file)) continue;
176
-			$_[$file]= md5_file($file);
177
-		}
178
-		return serialize($_);
179
-	}
168
+    function getSystemChecksum($check_files) {
169
+        $_ = array();
170
+        $check_files = trim($check_files);
171
+        $check_files = explode("\n", $check_files);
172
+        foreach($check_files as $file) {
173
+            $file = trim($file);
174
+            $file = MODX_BASE_PATH . $file;
175
+            if(!is_file($file)) continue;
176
+            $_[$file]= md5_file($file);
177
+        }
178
+        return serialize($_);
179
+    }
180 180
 
181
-	function getModifiedSystemFilesList($check_files, $checksum) {
182
-		$_ = array();
183
-		$check_files = trim($check_files);
184
-		$check_files = explode("\n", $check_files);
185
-		$checksum = unserialize($checksum);
186
-		foreach($check_files as $file) {
187
-			$file = trim($file);
188
-			$filePath = MODX_BASE_PATH . $file;
189
-			if(!is_file($filePath)) continue;
190
-			if(md5_file($filePath) != $checksum[$filePath]) $_[] = $file;
191
-		}
192
-		return $_;
193
-	}
181
+    function getModifiedSystemFilesList($check_files, $checksum) {
182
+        $_ = array();
183
+        $check_files = trim($check_files);
184
+        $check_files = explode("\n", $check_files);
185
+        $checksum = unserialize($checksum);
186
+        foreach($check_files as $file) {
187
+            $file = trim($file);
188
+            $filePath = MODX_BASE_PATH . $file;
189
+            if(!is_file($filePath)) continue;
190
+            if(md5_file($filePath) != $checksum[$filePath]) $_[] = $file;
191
+        }
192
+        return $_;
193
+    }
194 194
 
195
-	function setSystemChecksum($checksum) {
196
-		global $modx;
197
-		$tbl_system_settings = $modx->getFullTableName('system_settings');
198
-		$sql = "REPLACE INTO {$tbl_system_settings} (setting_name, setting_value) VALUES ('sys_files_checksum','" . $modx->db->escape($checksum) . "')";
195
+    function setSystemChecksum($checksum) {
196
+        global $modx;
197
+        $tbl_system_settings = $modx->getFullTableName('system_settings');
198
+        $sql = "REPLACE INTO {$tbl_system_settings} (setting_name, setting_value) VALUES ('sys_files_checksum','" . $modx->db->escape($checksum) . "')";
199 199
         $modx->db->query($sql);
200
-	}
200
+    }
201 201
 	
202
-	function checkSystemChecksum() {
203
-		global $modx;
202
+    function checkSystemChecksum() {
203
+        global $modx;
204 204
 
205
-		if(!isset($modx->config['check_files_onlogin']) || empty($modx->config['check_files_onlogin'])) return '0';
205
+        if(!isset($modx->config['check_files_onlogin']) || empty($modx->config['check_files_onlogin'])) return '0';
206 206
 		
207
-		$current = $this->getSystemChecksum($modx->config['check_files_onlogin']);
208
-		if(empty($current)) return '0';
207
+        $current = $this->getSystemChecksum($modx->config['check_files_onlogin']);
208
+        if(empty($current)) return '0';
209 209
 		
210
-		if(!isset($modx->config['sys_files_checksum']) || empty($modx->config['sys_files_checksum']))
211
-		{
212
-			$this->setSystemChecksum($current);
213
-			return '0';
214
-		}
215
-		if($current===$modx->config['sys_files_checksum']) $result = '0';
216
-		else {
217
-			$result = $this->getModifiedSystemFilesList($modx->config['check_files_onlogin'], $modx->config['sys_files_checksum']);
218
-		} 
210
+        if(!isset($modx->config['sys_files_checksum']) || empty($modx->config['sys_files_checksum']))
211
+        {
212
+            $this->setSystemChecksum($current);
213
+            return '0';
214
+        }
215
+        if($current===$modx->config['sys_files_checksum']) $result = '0';
216
+        else {
217
+            $result = $this->getModifiedSystemFilesList($modx->config['check_files_onlogin'], $modx->config['sys_files_checksum']);
218
+        } 
219 219
 
220
-		return $result;
221
-	}
220
+        return $result;
221
+    }
222 222
 
223 223
     function getLastUserSetting($key=false) {
224 224
         global $modx;
Please login to merge, or discard this patch.
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 global $_PAGE; // page view state object. Usage $_PAGE['vs']['propertyname'] = $value;
9 9
 
10 10
 // Content manager wrapper class
11
-class ManagerAPI {
11
+class ManagerAPI{
12 12
 	
13 13
 	var $action; // action directive
14 14
 
@@ -17,27 +17,27 @@  discard block
 block discarded – undo
17 17
 		$this->action = $action; // set action directive
18 18
 	}
19 19
 	
20
-	function initPageViewState($id=0){
20
+	function initPageViewState($id = 0){
21 21
 		global $_PAGE;
22 22
 		$vsid = isset($_SESSION["mgrPageViewSID"]) ? $_SESSION["mgrPageViewSID"] : '';
23
-		if($vsid!=$this->action) {
23
+		if ($vsid != $this->action) {
24 24
 			$_SESSION["mgrPageViewSDATA"] = array(); // new view state
25
-			$_SESSION["mgrPageViewSID"] = $id>0 ? $id:$this->action; // set id
25
+			$_SESSION["mgrPageViewSID"] = $id > 0 ? $id : $this->action; // set id
26 26
 		}
27 27
 		$_PAGE['vs'] = &$_SESSION["mgrPageViewSDATA"]; // restore viewstate
28 28
 	}
29 29
 
30 30
 	// save page view state - not really necessary,
31
-	function savePageViewState($id=0){
31
+	function savePageViewState($id = 0){
32 32
 		global $_PAGE;
33 33
 		$_SESSION["mgrPageViewSDATA"] = $_PAGE['vs'];
34
-		$_SESSION["mgrPageViewSID"] = $id>0 ? $id:$this->action;
34
+		$_SESSION["mgrPageViewSID"] = $id > 0 ? $id : $this->action;
35 35
 	}
36 36
 	
37 37
 	// check for saved form
38
-	function hasFormValues() {
39
-		if(isset($_SESSION["mgrFormValueId"])) {		
40
-			if($this->action==$_SESSION["mgrFormValueId"]) {
38
+	function hasFormValues(){
39
+		if (isset($_SESSION["mgrFormValueId"])) {		
40
+			if ($this->action == $_SESSION["mgrFormValueId"]) {
41 41
 				return true;
42 42
 			}
43 43
 			else {
@@ -47,19 +47,19 @@  discard block
 block discarded – undo
47 47
 		return false;
48 48
 	}	
49 49
 	// saved form post from $_POST
50
-	function saveFormValues($id=0){
50
+	function saveFormValues($id = 0){
51 51
 		$_SESSION["mgrFormValues"] = $_POST;
52
-		$_SESSION["mgrFormValueId"] = $id>0 ? $id:$this->action;
52
+		$_SESSION["mgrFormValueId"] = $id > 0 ? $id : $this->action;
53 53
 	}		
54 54
 	// load saved form values into $_POST
55 55
 	function loadFormValues(){
56 56
 		
57
-		if(!$this->hasFormValues()) return false;
57
+		if (!$this->hasFormValues()) return false;
58 58
 		
59 59
 		$p = $_SESSION["mgrFormValues"];
60 60
 		$this->clearSavedFormValues();
61
-		foreach($p as $k=>$v) {
62
-			$_POST[$k]=$v;
61
+		foreach ($p as $k=>$v) {
62
+			$_POST[$k] = $v;
63 63
 		}
64 64
 		return true;
65 65
 	}
@@ -69,50 +69,50 @@  discard block
 block discarded – undo
69 69
 		unset($_SESSION["mgrFormValueId"]);	
70 70
 	}
71 71
 	
72
-	function getHashType($db_value='') { // md5 | v1 | phpass
73
-		$c = substr($db_value,0,1);
74
-		if($c==='$')                                      return 'phpass';
75
-		elseif(strlen($db_value)===32)                    return 'md5';
76
-		elseif($c!=='$' && strpos($db_value,'>')!==false) return 'v1';
72
+	function getHashType($db_value = ''){ // md5 | v1 | phpass
73
+		$c = substr($db_value, 0, 1);
74
+		if ($c === '$')                                      return 'phpass';
75
+		elseif (strlen($db_value) === 32)                    return 'md5';
76
+		elseif ($c !== '$' && strpos($db_value, '>') !== false) return 'v1';
77 77
 		else                                              return 'unknown';
78 78
 	}
79 79
 	
80
-	function genV1Hash($password, $seed='1')
80
+	function genV1Hash($password, $seed = '1')
81 81
 	{ // $seed is user_id basically
82 82
 		global $modx;
83 83
 		
84
-		if(isset($modx->config['pwd_hash_algo']) && !empty($modx->config['pwd_hash_algo']))
84
+		if (isset($modx->config['pwd_hash_algo']) && !empty($modx->config['pwd_hash_algo']))
85 85
 			$algorithm = $modx->config['pwd_hash_algo'];
86 86
 		else $algorithm = 'UNCRYPT';
87 87
 		
88
-		$salt = md5($password . $seed);
88
+		$salt = md5($password.$seed);
89 89
 		
90
-		switch($algorithm)
90
+		switch ($algorithm)
91 91
 		{
92 92
 			case 'BLOWFISH_Y':
93
-				$salt = '$2y$07$' . substr($salt,0,22);
93
+				$salt = '$2y$07$'.substr($salt, 0, 22);
94 94
 				break;
95 95
 			case 'BLOWFISH_A':
96
-				$salt = '$2a$07$' . substr($salt,0,22);
96
+				$salt = '$2a$07$'.substr($salt, 0, 22);
97 97
 				break;
98 98
 			case 'SHA512':
99
-				$salt = '$6$' . substr($salt,0,16);
99
+				$salt = '$6$'.substr($salt, 0, 16);
100 100
 				break;
101 101
 			case 'SHA256':
102
-				$salt = '$5$' . substr($salt,0,16);
102
+				$salt = '$5$'.substr($salt, 0, 16);
103 103
 				break;
104 104
 			case 'MD5':
105
-				$salt = '$1$' . substr($salt,0,8);
105
+				$salt = '$1$'.substr($salt, 0, 8);
106 106
 				break;
107 107
 		}
108 108
 		
109
-		if($algorithm!=='UNCRYPT')
109
+		if ($algorithm !== 'UNCRYPT')
110 110
 		{
111
-			$password = sha1($password) . crypt($password,$salt);
111
+			$password = sha1($password).crypt($password, $salt);
112 112
 		}
113 113
 		else $password = sha1($salt.$password);
114 114
 		
115
-		$result = strtolower($algorithm) . '>' . md5($salt.$password) . substr(md5($salt),0,8);
115
+		$result = strtolower($algorithm).'>'.md5($salt.$password).substr(md5($salt), 0, 8);
116 116
 		
117 117
 		return $result;
118 118
 	}
@@ -121,18 +121,18 @@  discard block
 block discarded – undo
121 121
 	{
122 122
 		global $modx;
123 123
 		$tbl_manager_users = $modx->getFullTableName('manager_users');
124
-		$rs = $modx->db->select('password',$tbl_manager_users,"id='{$uid}'");
124
+		$rs = $modx->db->select('password', $tbl_manager_users, "id='{$uid}'");
125 125
 		$password = $modx->db->getValue($rs);
126 126
 		
127
-		if(strpos($password,'>')===false) $algo = 'NOSALT';
127
+		if (strpos($password, '>') === false) $algo = 'NOSALT';
128 128
 		else
129 129
 		{
130
-			$algo = substr($password,0,strpos($password,'>'));
130
+			$algo = substr($password, 0, strpos($password, '>'));
131 131
 		}
132 132
 		return strtoupper($algo);
133 133
 	}
134 134
 	
135
-	function checkHashAlgorithm($algorithm='')
135
+	function checkHashAlgorithm($algorithm = '')
136 136
 	{
137 137
 		$result = false;
138 138
 		if (!empty($algorithm))
@@ -165,54 +165,54 @@  discard block
 block discarded – undo
165 165
 		return $result;
166 166
 	}
167 167
 
168
-	function getSystemChecksum($check_files) {
168
+	function getSystemChecksum($check_files){
169 169
 		$_ = array();
170 170
 		$check_files = trim($check_files);
171 171
 		$check_files = explode("\n", $check_files);
172
-		foreach($check_files as $file) {
172
+		foreach ($check_files as $file) {
173 173
 			$file = trim($file);
174
-			$file = MODX_BASE_PATH . $file;
175
-			if(!is_file($file)) continue;
176
-			$_[$file]= md5_file($file);
174
+			$file = MODX_BASE_PATH.$file;
175
+			if (!is_file($file)) continue;
176
+			$_[$file] = md5_file($file);
177 177
 		}
178 178
 		return serialize($_);
179 179
 	}
180 180
 
181
-	function getModifiedSystemFilesList($check_files, $checksum) {
181
+	function getModifiedSystemFilesList($check_files, $checksum){
182 182
 		$_ = array();
183 183
 		$check_files = trim($check_files);
184 184
 		$check_files = explode("\n", $check_files);
185 185
 		$checksum = unserialize($checksum);
186
-		foreach($check_files as $file) {
186
+		foreach ($check_files as $file) {
187 187
 			$file = trim($file);
188
-			$filePath = MODX_BASE_PATH . $file;
189
-			if(!is_file($filePath)) continue;
190
-			if(md5_file($filePath) != $checksum[$filePath]) $_[] = $file;
188
+			$filePath = MODX_BASE_PATH.$file;
189
+			if (!is_file($filePath)) continue;
190
+			if (md5_file($filePath) != $checksum[$filePath]) $_[] = $file;
191 191
 		}
192 192
 		return $_;
193 193
 	}
194 194
 
195
-	function setSystemChecksum($checksum) {
195
+	function setSystemChecksum($checksum){
196 196
 		global $modx;
197 197
 		$tbl_system_settings = $modx->getFullTableName('system_settings');
198
-		$sql = "REPLACE INTO {$tbl_system_settings} (setting_name, setting_value) VALUES ('sys_files_checksum','" . $modx->db->escape($checksum) . "')";
198
+		$sql = "REPLACE INTO {$tbl_system_settings} (setting_name, setting_value) VALUES ('sys_files_checksum','".$modx->db->escape($checksum)."')";
199 199
         $modx->db->query($sql);
200 200
 	}
201 201
 	
202
-	function checkSystemChecksum() {
202
+	function checkSystemChecksum(){
203 203
 		global $modx;
204 204
 
205
-		if(!isset($modx->config['check_files_onlogin']) || empty($modx->config['check_files_onlogin'])) return '0';
205
+		if (!isset($modx->config['check_files_onlogin']) || empty($modx->config['check_files_onlogin'])) return '0';
206 206
 		
207 207
 		$current = $this->getSystemChecksum($modx->config['check_files_onlogin']);
208
-		if(empty($current)) return '0';
208
+		if (empty($current)) return '0';
209 209
 		
210
-		if(!isset($modx->config['sys_files_checksum']) || empty($modx->config['sys_files_checksum']))
210
+		if (!isset($modx->config['sys_files_checksum']) || empty($modx->config['sys_files_checksum']))
211 211
 		{
212 212
 			$this->setSystemChecksum($current);
213 213
 			return '0';
214 214
 		}
215
-		if($current===$modx->config['sys_files_checksum']) $result = '0';
215
+		if ($current === $modx->config['sys_files_checksum']) $result = '0';
216 216
 		else {
217 217
 			$result = $this->getModifiedSystemFilesList($modx->config['check_files_onlogin'], $modx->config['sys_files_checksum']);
218 218
 		} 
@@ -220,28 +220,28 @@  discard block
 block discarded – undo
220 220
 		return $result;
221 221
 	}
222 222
 
223
-    function getLastUserSetting($key=false) {
223
+    function getLastUserSetting($key = false){
224 224
         global $modx;
225 225
         
226 226
         $rs = $modx->db->select('*', $modx->getFullTableName('user_settings'), "user = '{$_SESSION['mgrInternalKey']}'");
227 227
         
228
-        $usersettings = array ();
228
+        $usersettings = array();
229 229
         while ($row = $modx->db->getRow($rs)) {
230
-            if(substr($row['setting_name'], 0, 6) == '_LAST_') {
230
+            if (substr($row['setting_name'], 0, 6) == '_LAST_') {
231 231
                 $name = substr($row['setting_name'], 6);
232 232
                 $usersettings[$name] = $row['setting_value'];
233 233
             }
234 234
         }
235 235
         
236
-        if(!$key) return $usersettings;
236
+        if (!$key) return $usersettings;
237 237
         else return isset($usersettings[$key]) ? $usersettings[$key] : NULL;
238 238
     }
239 239
     
240
-    function saveLastUserSetting($settings, $val='') {
240
+    function saveLastUserSetting($settings, $val = ''){
241 241
         global $modx;
242 242
         
243
-        if(!empty($settings)) {
244
-            if(!is_array($settings)) $settings = array($settings=>$val);
243
+        if (!empty($settings)) {
244
+            if (!is_array($settings)) $settings = array($settings=>$val);
245 245
             
246 246
             foreach ($settings as $key => $val) {
247 247
                 $f = array();
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
         }
257 257
     }
258 258
     
259
-    function loadDatePicker($path) {
259
+    function loadDatePicker($path){
260 260
         global $modx;
261 261
         include_once($path);
262 262
         $dp = new DATEPICKER();
Please login to merge, or discard this patch.
Braces   +106 added lines, -59 removed lines patch added patch discarded remove patch
@@ -8,16 +8,19 @@  discard block
 block discarded – undo
8 8
 global $_PAGE; // page view state object. Usage $_PAGE['vs']['propertyname'] = $value;
9 9
 
10 10
 // Content manager wrapper class
11
-class ManagerAPI {
11
+class ManagerAPI
12
+{
12 13
 	
13 14
 	var $action; // action directive
14 15
 
15
-	function __construct(){
16
+	function __construct()
17
+	{
16 18
 		global $action;
17 19
 		$this->action = $action; // set action directive
18 20
 	}
19 21
 	
20
-	function initPageViewState($id=0){
22
+	function initPageViewState($id=0)
23
+	{
21 24
 		global $_PAGE;
22 25
 		$vsid = isset($_SESSION["mgrPageViewSID"]) ? $_SESSION["mgrPageViewSID"] : '';
23 26
 		if($vsid!=$this->action) {
@@ -28,33 +31,38 @@  discard block
 block discarded – undo
28 31
 	}
29 32
 
30 33
 	// save page view state - not really necessary,
31
-	function savePageViewState($id=0){
34
+	function savePageViewState($id=0)
35
+	{
32 36
 		global $_PAGE;
33 37
 		$_SESSION["mgrPageViewSDATA"] = $_PAGE['vs'];
34 38
 		$_SESSION["mgrPageViewSID"] = $id>0 ? $id:$this->action;
35 39
 	}
36 40
 	
37 41
 	// check for saved form
38
-	function hasFormValues() {
39
-		if(isset($_SESSION["mgrFormValueId"])) {		
42
+	function hasFormValues()
43
+	{
44
+		if(isset($_SESSION["mgrFormValueId"])) {
40 45
 			if($this->action==$_SESSION["mgrFormValueId"]) {
41 46
 				return true;
42
-			}
43
-			else {
47
+			} else {
44 48
 				$this->clearSavedFormValues();
45 49
 			}
46 50
 		}
47 51
 		return false;
48 52
 	}	
49 53
 	// saved form post from $_POST
50
-	function saveFormValues($id=0){
54
+	function saveFormValues($id=0)
55
+	{
51 56
 		$_SESSION["mgrFormValues"] = $_POST;
52 57
 		$_SESSION["mgrFormValueId"] = $id>0 ? $id:$this->action;
53 58
 	}		
54 59
 	// load saved form values into $_POST
55
-	function loadFormValues(){
60
+	function loadFormValues()
61
+	{
56 62
 		
57
-		if(!$this->hasFormValues()) return false;
63
+		if(!$this->hasFormValues()) {
64
+		    return false;
65
+		}
58 66
 		
59 67
 		$p = $_SESSION["mgrFormValues"];
60 68
 		$this->clearSavedFormValues();
@@ -64,31 +72,41 @@  discard block
 block discarded – undo
64 72
 		return true;
65 73
 	}
66 74
 	// clear form post
67
-	function clearSavedFormValues(){
75
+	function clearSavedFormValues()
76
+	{
68 77
 		unset($_SESSION["mgrFormValues"]);
69 78
 		unset($_SESSION["mgrFormValueId"]);	
70 79
 	}
71 80
 	
72
-	function getHashType($db_value='') { // md5 | v1 | phpass
81
+	function getHashType($db_value='')
82
+	{
83
+// md5 | v1 | phpass
73 84
 		$c = substr($db_value,0,1);
74
-		if($c==='$')                                      return 'phpass';
75
-		elseif(strlen($db_value)===32)                    return 'md5';
76
-		elseif($c!=='$' && strpos($db_value,'>')!==false) return 'v1';
77
-		else                                              return 'unknown';
85
+		if($c==='$') {
86
+		    return 'phpass';
87
+		} elseif(strlen($db_value)===32) {
88
+		    return 'md5';
89
+		} elseif($c!=='$' && strpos($db_value,'>')!==false) {
90
+		    return 'v1';
91
+		} else {
92
+		    return 'unknown';
93
+		}
78 94
 	}
79 95
 	
80 96
 	function genV1Hash($password, $seed='1')
81
-	{ // $seed is user_id basically
97
+	{
98
+// $seed is user_id basically
82 99
 		global $modx;
83 100
 		
84
-		if(isset($modx->config['pwd_hash_algo']) && !empty($modx->config['pwd_hash_algo']))
85
-			$algorithm = $modx->config['pwd_hash_algo'];
86
-		else $algorithm = 'UNCRYPT';
101
+		if(isset($modx->config['pwd_hash_algo']) && !empty($modx->config['pwd_hash_algo'])) {
102
+					$algorithm = $modx->config['pwd_hash_algo'];
103
+		} else {
104
+		    $algorithm = 'UNCRYPT';
105
+		}
87 106
 		
88 107
 		$salt = md5($password . $seed);
89 108
 		
90
-		switch($algorithm)
91
-		{
109
+		switch($algorithm) {
92 110
 			case 'BLOWFISH_Y':
93 111
 				$salt = '$2y$07$' . substr($salt,0,22);
94 112
 				break;
@@ -106,11 +124,11 @@  discard block
 block discarded – undo
106 124
 				break;
107 125
 		}
108 126
 		
109
-		if($algorithm!=='UNCRYPT')
110
-		{
127
+		if($algorithm!=='UNCRYPT') {
111 128
 			$password = sha1($password) . crypt($password,$salt);
129
+		} else {
130
+		    $password = sha1($salt.$password);
112 131
 		}
113
-		else $password = sha1($salt.$password);
114 132
 		
115 133
 		$result = strtolower($algorithm) . '>' . md5($salt.$password) . substr(md5($salt),0,8);
116 134
 		
@@ -124,9 +142,9 @@  discard block
 block discarded – undo
124 142
 		$rs = $modx->db->select('password',$tbl_manager_users,"id='{$uid}'");
125 143
 		$password = $modx->db->getValue($rs);
126 144
 		
127
-		if(strpos($password,'>')===false) $algo = 'NOSALT';
128
-		else
129
-		{
145
+		if(strpos($password,'>')===false) {
146
+		    $algo = 'NOSALT';
147
+		} else {
130 148
 			$algo = substr($password,0,strpos($password,'>'));
131 149
 		}
132 150
 		return strtoupper($algo);
@@ -135,27 +153,34 @@  discard block
 block discarded – undo
135 153
 	function checkHashAlgorithm($algorithm='')
136 154
 	{
137 155
 		$result = false;
138
-		if (!empty($algorithm))
139
-		{
140
-			switch ($algorithm)
141
-			{
156
+		if (!empty($algorithm)) {
157
+			switch ($algorithm) {
142 158
 				case 'BLOWFISH_Y':
143
-					if (defined('CRYPT_BLOWFISH') && CRYPT_BLOWFISH == 1)
144
-					{
145
-						if (version_compare('5.3.7', PHP_VERSION) <= 0) $result = true;
159
+					if (defined('CRYPT_BLOWFISH') && CRYPT_BLOWFISH == 1) {
160
+						if (version_compare('5.3.7', PHP_VERSION) <= 0) {
161
+						    $result = true;
162
+						}
146 163
 					}
147 164
 					break;
148 165
 				case 'BLOWFISH_A':
149
-					if (defined('CRYPT_BLOWFISH') && CRYPT_BLOWFISH == 1) $result = true;
166
+					if (defined('CRYPT_BLOWFISH') && CRYPT_BLOWFISH == 1) {
167
+					    $result = true;
168
+					}
150 169
 					break;
151 170
 				case 'SHA512':
152
-					if (defined('CRYPT_SHA512') && CRYPT_SHA512 == 1) $result = true;
171
+					if (defined('CRYPT_SHA512') && CRYPT_SHA512 == 1) {
172
+					    $result = true;
173
+					}
153 174
 					break;
154 175
 				case 'SHA256':
155
-					if (defined('CRYPT_SHA256') && CRYPT_SHA256 == 1) $result = true;
176
+					if (defined('CRYPT_SHA256') && CRYPT_SHA256 == 1) {
177
+					    $result = true;
178
+					}
156 179
 					break;
157 180
 				case 'MD5':
158
-					if (defined('CRYPT_MD5') && CRYPT_MD5 == 1 && PHP_VERSION != '5.3.7') $result = true;
181
+					if (defined('CRYPT_MD5') && CRYPT_MD5 == 1 && PHP_VERSION != '5.3.7') {
182
+					    $result = true;
183
+					}
159 184
 					break;
160 185
 				case 'UNCRYPT':
161 186
 					$result = true;
@@ -165,20 +190,24 @@  discard block
 block discarded – undo
165 190
 		return $result;
166 191
 	}
167 192
 
168
-	function getSystemChecksum($check_files) {
193
+	function getSystemChecksum($check_files)
194
+	{
169 195
 		$_ = array();
170 196
 		$check_files = trim($check_files);
171 197
 		$check_files = explode("\n", $check_files);
172 198
 		foreach($check_files as $file) {
173 199
 			$file = trim($file);
174 200
 			$file = MODX_BASE_PATH . $file;
175
-			if(!is_file($file)) continue;
201
+			if(!is_file($file)) {
202
+			    continue;
203
+			}
176 204
 			$_[$file]= md5_file($file);
177 205
 		}
178 206
 		return serialize($_);
179 207
 	}
180 208
 
181
-	function getModifiedSystemFilesList($check_files, $checksum) {
209
+	function getModifiedSystemFilesList($check_files, $checksum)
210
+	{
182 211
 		$_ = array();
183 212
 		$check_files = trim($check_files);
184 213
 		$check_files = explode("\n", $check_files);
@@ -186,41 +215,52 @@  discard block
 block discarded – undo
186 215
 		foreach($check_files as $file) {
187 216
 			$file = trim($file);
188 217
 			$filePath = MODX_BASE_PATH . $file;
189
-			if(!is_file($filePath)) continue;
190
-			if(md5_file($filePath) != $checksum[$filePath]) $_[] = $file;
218
+			if(!is_file($filePath)) {
219
+			    continue;
220
+			}
221
+			if(md5_file($filePath) != $checksum[$filePath]) {
222
+			    $_[] = $file;
223
+			}
191 224
 		}
192 225
 		return $_;
193 226
 	}
194 227
 
195
-	function setSystemChecksum($checksum) {
228
+	function setSystemChecksum($checksum)
229
+	{
196 230
 		global $modx;
197 231
 		$tbl_system_settings = $modx->getFullTableName('system_settings');
198 232
 		$sql = "REPLACE INTO {$tbl_system_settings} (setting_name, setting_value) VALUES ('sys_files_checksum','" . $modx->db->escape($checksum) . "')";
199 233
         $modx->db->query($sql);
200 234
 	}
201 235
 	
202
-	function checkSystemChecksum() {
236
+	function checkSystemChecksum()
237
+	{
203 238
 		global $modx;
204 239
 
205
-		if(!isset($modx->config['check_files_onlogin']) || empty($modx->config['check_files_onlogin'])) return '0';
240
+		if(!isset($modx->config['check_files_onlogin']) || empty($modx->config['check_files_onlogin'])) {
241
+		    return '0';
242
+		}
206 243
 		
207 244
 		$current = $this->getSystemChecksum($modx->config['check_files_onlogin']);
208
-		if(empty($current)) return '0';
245
+		if(empty($current)) {
246
+		    return '0';
247
+		}
209 248
 		
210
-		if(!isset($modx->config['sys_files_checksum']) || empty($modx->config['sys_files_checksum']))
211
-		{
249
+		if(!isset($modx->config['sys_files_checksum']) || empty($modx->config['sys_files_checksum'])) {
212 250
 			$this->setSystemChecksum($current);
213 251
 			return '0';
214 252
 		}
215
-		if($current===$modx->config['sys_files_checksum']) $result = '0';
216
-		else {
253
+		if($current===$modx->config['sys_files_checksum']) {
254
+		    $result = '0';
255
+		} else {
217 256
 			$result = $this->getModifiedSystemFilesList($modx->config['check_files_onlogin'], $modx->config['sys_files_checksum']);
218 257
 		} 
219 258
 
220 259
 		return $result;
221 260
 	}
222 261
 
223
-    function getLastUserSetting($key=false) {
262
+    function getLastUserSetting($key=false)
263
+    {
224 264
         global $modx;
225 265
         
226 266
         $rs = $modx->db->select('*', $modx->getFullTableName('user_settings'), "user = '{$_SESSION['mgrInternalKey']}'");
@@ -233,15 +273,21 @@  discard block
 block discarded – undo
233 273
             }
234 274
         }
235 275
         
236
-        if(!$key) return $usersettings;
237
-        else return isset($usersettings[$key]) ? $usersettings[$key] : NULL;
276
+        if(!$key) {
277
+            return $usersettings;
278
+        } else {
279
+            return isset($usersettings[$key]) ? $usersettings[$key] : NULL;
280
+        }
238 281
     }
239 282
     
240
-    function saveLastUserSetting($settings, $val='') {
283
+    function saveLastUserSetting($settings, $val='')
284
+    {
241 285
         global $modx;
242 286
         
243 287
         if(!empty($settings)) {
244
-            if(!is_array($settings)) $settings = array($settings=>$val);
288
+            if(!is_array($settings)) {
289
+                $settings = array($settings=>$val);
290
+            }
245 291
             
246 292
             foreach ($settings as $key => $val) {
247 293
                 $f = array();
@@ -256,7 +302,8 @@  discard block
 block discarded – undo
256 302
         }
257 303
     }
258 304
     
259
-    function loadDatePicker($path) {
305
+    function loadDatePicker($path)
306
+    {
260 307
         global $modx;
261 308
         include_once($path);
262 309
         $dp = new DATEPICKER();
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -234,7 +234,7 @@
 block discarded – undo
234 234
         }
235 235
         
236 236
         if(!$key) return $usersettings;
237
-        else return isset($usersettings[$key]) ? $usersettings[$key] : NULL;
237
+        else return isset($usersettings[$key]) ? $usersettings[$key] : null;
238 238
     }
239 239
     
240 240
     function saveLastUserSetting($settings, $val='') {
Please login to merge, or discard this patch.
manager/includes/extenders/modxmailer.class.inc.php 3 patches
Unused Use Statements   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,8 +8,8 @@
 block discarded – undo
8 8
  *******************************************************
9 9
  */
10 10
 
11
-use PHPMailer\PHPMailer\PHPMailer;
12 11
 use PHPMailer\PHPMailer\Exception;
12
+use PHPMailer\PHPMailer\PHPMailer;
13 13
 
14 14
 require MODX_MANAGER_PATH . 'includes/controls/phpmailer/Exception.php';
15 15
 require MODX_MANAGER_PATH . 'includes/controls/phpmailer/PHPMailer.php';
Please login to merge, or discard this patch.
Braces   +12 added lines, -6 removed lines patch added patch discarded remove patch
@@ -280,14 +280,16 @@  discard block
 block discarded – undo
280 280
     /**
281 281
      * @return string
282 282
      */
283
-    public function getMIMEHeader() {
283
+    public function getMIMEHeader()
284
+    {
284 285
         return $this->MIMEHeader;
285 286
     }
286 287
 
287 288
     /**
288 289
      * @return string
289 290
      */
290
-    public function getMIMEBody() {
291
+    public function getMIMEBody()
292
+    {
291 293
         return $this->MIMEBody;
292 294
     }
293 295
 
@@ -296,7 +298,8 @@  discard block
 block discarded – undo
296 298
      *
297 299
      * @return $this
298 300
      */
299
-    public function setMIMEHeader($header = '') {
301
+    public function setMIMEHeader($header = '')
302
+    {
300 303
         $this->MIMEHeader = $header;
301 304
 
302 305
         return $this;
@@ -307,7 +310,8 @@  discard block
 block discarded – undo
307 310
      *
308 311
      * @return $this
309 312
      */
310
-    public function setMIMEBody($body = '') {
313
+    public function setMIMEBody($body = '')
314
+    {
311 315
         $this->MIMEBody = $body;
312 316
 
313 317
         return $this;
@@ -318,7 +322,8 @@  discard block
 block discarded – undo
318 322
      *
319 323
      * @return $this
320 324
      */
321
-    public function setMailHeader($header = '') {
325
+    public function setMailHeader($header = '')
326
+    {
322 327
         $this->mailHeader = $header;
323 328
 
324 329
         return $this;
@@ -327,7 +332,8 @@  discard block
 block discarded – undo
327 332
     /**
328 333
      * @return string
329 334
      */
330
-    public function getMessageID() {
335
+    public function getMessageID()
336
+    {
331 337
         return trim($this->lastMessageID,'<>');
332 338
     }
333 339
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -11,9 +11,9 @@  discard block
 block discarded – undo
11 11
 use PHPMailer\PHPMailer\PHPMailer;
12 12
 use PHPMailer\PHPMailer\Exception;
13 13
 
14
-require MODX_MANAGER_PATH . 'includes/controls/phpmailer/Exception.php';
15
-require MODX_MANAGER_PATH . 'includes/controls/phpmailer/PHPMailer.php';
16
-require MODX_MANAGER_PATH . 'includes/controls/phpmailer/SMTP.php';
14
+require MODX_MANAGER_PATH.'includes/controls/phpmailer/Exception.php';
15
+require MODX_MANAGER_PATH.'includes/controls/phpmailer/PHPMailer.php';
16
+require MODX_MANAGER_PATH.'includes/controls/phpmailer/SMTP.php';
17 17
 
18 18
 /**
19 19
  * Class MODxMailer
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
     public function init(DocumentParser $modx)
34 34
     {
35 35
         $this->modx = $modx;
36
-        $this->PluginDir = MODX_MANAGER_PATH . 'includes/controls/phpmailer/';
36
+        $this->PluginDir = MODX_MANAGER_PATH.'includes/controls/phpmailer/';
37 37
 
38 38
         switch ($modx->config['email_method']) {
39 39
             case 'smtp':
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
             mb_language($this->mb_language);
98 98
             mb_internal_encoding($modx->config['modx_charset']);
99 99
         }
100
-        $exconf = MODX_MANAGER_PATH . 'includes/controls/phpmailer/config.inc.php';
100
+        $exconf = MODX_MANAGER_PATH.'includes/controls/phpmailer/config.inc.php';
101 101
         if (is_file($exconf)) {
102 102
             include($exconf);
103 103
         }
@@ -165,12 +165,12 @@  discard block
 block discarded – undo
165 165
         }
166 166
 
167 167
         if ($this->modx->debug) {
168
-            $debug_info = 'CharSet = ' . $this->CharSet . "\n";
169
-            $debug_info .= 'Encoding = ' . $this->Encoding . "\n";
170
-            $debug_info .= 'mb_language = ' . $this->mb_language . "\n";
171
-            $debug_info .= 'encode_header_method = ' . $this->encode_header_method . "\n";
168
+            $debug_info = 'CharSet = '.$this->CharSet."\n";
169
+            $debug_info .= 'Encoding = '.$this->Encoding."\n";
170
+            $debug_info .= 'mb_language = '.$this->mb_language."\n";
171
+            $debug_info .= 'encode_header_method = '.$this->encode_header_method."\n";
172 172
             $debug_info .= "send_mode = {$mode}\n";
173
-            $debug_info .= 'Subject = ' . $this->Subject . "\n";
173
+            $debug_info .= 'Subject = '.$this->Subject."\n";
174 174
             $log = "<pre>{$debug_info}\n{$header}\n{$org_body}</pre>";
175 175
             $this->modx->logEvent(1, 1, $log, 'MODxMailer debug information');
176 176
 
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
             ini_set('sendmail_from', $old_from);
235 235
         }
236 236
         if (!$rt) {
237
-            $msg = $this->Lang('instantiate') . "<br />\n";
237
+            $msg = $this->Lang('instantiate')."<br />\n";
238 238
             $msg .= "{$this->Subject}<br />\n";
239 239
             $msg .= "{$this->FromName}&lt;{$this->From}&gt;<br />\n";
240 240
             $msg .= mb_convert_encoding($body, $this->modx->config['modx_charset'], $this->CharSet);
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
      */
254 254
     public function SetError($msg)
255 255
     {
256
-        $msg .= '<pre>' . print_r(get_object_vars($this), true) . '</pre>';
256
+        $msg .= '<pre>'.print_r(get_object_vars($this), true).'</pre>';
257 257
         $this->modx->config['send_errormail'] = '0';
258 258
         $this->modx->logEvent(0, 3, $msg, 'phpmailer');
259 259
 
@@ -282,14 +282,14 @@  discard block
 block discarded – undo
282 282
     /**
283 283
      * @return string
284 284
      */
285
-    public function getMIMEHeader() {
285
+    public function getMIMEHeader(){
286 286
         return $this->MIMEHeader;
287 287
     }
288 288
 
289 289
     /**
290 290
      * @return string
291 291
      */
292
-    public function getMIMEBody() {
292
+    public function getMIMEBody(){
293 293
         return $this->MIMEBody;
294 294
     }
295 295
 
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
      *
299 299
      * @return $this
300 300
      */
301
-    public function setMIMEHeader($header = '') {
301
+    public function setMIMEHeader($header = ''){
302 302
         $this->MIMEHeader = $header;
303 303
 
304 304
         return $this;
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
      *
310 310
      * @return $this
311 311
      */
312
-    public function setMIMEBody($body = '') {
312
+    public function setMIMEBody($body = ''){
313 313
         $this->MIMEBody = $body;
314 314
 
315 315
         return $this;
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
      *
321 321
      * @return $this
322 322
      */
323
-    public function setMailHeader($header = '') {
323
+    public function setMailHeader($header = ''){
324 324
         $this->mailHeader = $header;
325 325
 
326 326
         return $this;
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
     /**
330 330
      * @return string
331 331
      */
332
-    public function getMessageID() {
333
-        return trim($this->lastMessageID,'<>');
332
+    public function getMessageID(){
333
+        return trim($this->lastMessageID, '<>');
334 334
     }
335 335
 }
Please login to merge, or discard this patch.
manager/includes/extenders/phpass.class.inc.php 4 patches
Doc Comments   +15 added lines patch added patch discarded remove patch
@@ -43,6 +43,9 @@  discard block
 block discarded – undo
43 43
         $this->random_state = microtime() . uniqid(mt_rand(), TRUE);
44 44
     }
45 45
 
46
+    /**
47
+     * @param integer $count
48
+     */
46 49
     function get_random_bytes($count)
47 50
     {
48 51
         $output = '';
@@ -66,6 +69,9 @@  discard block
 block discarded – undo
66 69
         return $output;
67 70
     }
68 71
 
72
+    /**
73
+     * @param integer $count
74
+     */
69 75
     function encode64($input, $count)
70 76
     {
71 77
         $output = '';
@@ -89,6 +95,9 @@  discard block
 block discarded – undo
89 95
         return $output;
90 96
     }
91 97
 
98
+    /**
99
+     * @param string $input
100
+     */
92 101
     function gensalt_private($input)
93 102
     {
94 103
         $output = '$P$';
@@ -137,6 +146,9 @@  discard block
 block discarded – undo
137 146
         return $output;
138 147
     }
139 148
 
149
+    /**
150
+     * @param string $input
151
+     */
140 152
     function gensalt_extended($input)
141 153
     {
142 154
         $count_log2 = min($this->iteration_count_log2 + 8, 24);
@@ -155,6 +167,9 @@  discard block
 block discarded – undo
155 167
         return $output;
156 168
     }
157 169
 
170
+    /**
171
+     * @param string $input
172
+     */
158 173
     function gensalt_blowfish($input)
159 174
     {
160 175
         // This one needs to use a different order of characters and a
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -24,13 +24,13 @@  discard block
 block discarded – undo
24 24
 // Obviously, since this code is in the public domain, the above are not
25 25
 // requirements (there can be none), but merely suggestions.
26 26
 //
27
-class PasswordHash {
27
+class PasswordHash{
28 28
     var $itoa64;
29 29
     var $iteration_count_log2;
30 30
     var $portable_hashes;
31 31
     var $random_state;
32 32
 
33
-    function __construct($iteration_count_log2=8, $portable_hashes=true)
33
+    function __construct($iteration_count_log2 = 8, $portable_hashes = true)
34 34
     {
35 35
         $this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
36 36
 
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 
41 41
         $this->portable_hashes = $portable_hashes;
42 42
 
43
-        $this->random_state = microtime() . uniqid(mt_rand(), TRUE);
43
+        $this->random_state = microtime().uniqid(mt_rand(), TRUE);
44 44
     }
45 45
 
46 46
     function get_random_bytes($count)
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
             $output = '';
57 57
             for ($i = 0; $i < $count; $i += 16) {
58 58
                 $this->random_state =
59
-                    md5(microtime() . $this->random_state);
59
+                    md5(microtime().$this->random_state);
60 60
                 $output .=
61 61
                     pack('H*', md5($this->random_state));
62 62
             }
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
         // consequently in lower iteration counts and hashes that are
127 127
         // quicker to crack (by non-PHP code).
128 128
         
129
-        $hash = md5($salt . $password, TRUE);
129
+        $hash = md5($salt.$password, TRUE);
130 130
         do {
131
-            $hash = md5($hash . $password, TRUE);
131
+            $hash = md5($hash.$password, TRUE);
132 132
         } while (--$count);
133 133
 
134 134
         $output = substr($setting, 0, 12);
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 
199 199
     function HashPassword($password)
200 200
     {
201
-        if ( strlen( $password ) > 4096 ) {
201
+        if (strlen($password) > 4096) {
202 202
             return '*';
203 203
         }
204 204
 
@@ -237,14 +237,14 @@  discard block
 block discarded – undo
237 237
 
238 238
     function CheckPassword($password, $stored_hash)
239 239
     {
240
-        if ( strlen( $password ) > 4096 ) {
240
+        if (strlen($password) > 4096) {
241 241
             return false;
242 242
         }
243 243
 
244 244
         $hash = $this->crypt_private($password, $stored_hash);
245
-        if (substr($hash,0,1) === '*')
245
+        if (substr($hash, 0, 1) === '*')
246 246
             $hash = crypt($password, $stored_hash);
247 247
 
248
-        return ($hash===$stored_hash) ? true : false;
248
+        return ($hash === $stored_hash) ? true : false;
249 249
     }
250 250
 }
Please login to merge, or discard this patch.
Braces   +47 added lines, -31 removed lines patch added patch discarded remove patch
@@ -24,7 +24,8 @@  discard block
 block discarded – undo
24 24
 // Obviously, since this code is in the public domain, the above are not
25 25
 // requirements (there can be none), but merely suggestions.
26 26
 //
27
-class PasswordHash {
27
+class PasswordHash
28
+{
28 29
     var $itoa64;
29 30
     var $iteration_count_log2;
30 31
     var $portable_hashes;
@@ -34,8 +35,9 @@  discard block
 block discarded – undo
34 35
     {
35 36
         $this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
36 37
 
37
-        if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31)
38
-            $iteration_count_log2 = 8;
38
+        if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31) {
39
+                    $iteration_count_log2 = 8;
40
+        }
39 41
         $this->iteration_count_log2 = $iteration_count_log2;
40 42
 
41 43
         $this->portable_hashes = $portable_hashes;
@@ -73,16 +75,20 @@  discard block
 block discarded – undo
73 75
         do {
74 76
             $value = ord($input[$i++]);
75 77
             $output .= $this->itoa64[$value & 0x3f];
76
-            if ($i < $count)
77
-                $value |= ord($input[$i]) << 8;
78
+            if ($i < $count) {
79
+                            $value |= ord($input[$i]) << 8;
80
+            }
78 81
             $output .= $this->itoa64[($value >> 6) & 0x3f];
79
-            if ($i++ >= $count)
80
-                break;
81
-            if ($i < $count)
82
-                $value |= ord($input[$i]) << 16;
82
+            if ($i++ >= $count) {
83
+                            break;
84
+            }
85
+            if ($i < $count) {
86
+                            $value |= ord($input[$i]) << 16;
87
+            }
83 88
             $output .= $this->itoa64[($value >> 12) & 0x3f];
84
-            if ($i++ >= $count)
85
-                break;
89
+            if ($i++ >= $count) {
90
+                            break;
91
+            }
86 92
             $output .= $this->itoa64[($value >> 18) & 0x3f];
87 93
         } while ($i < $count);
88 94
 
@@ -101,23 +107,27 @@  discard block
 block discarded – undo
101 107
     function crypt_private($password, $setting)
102 108
     {
103 109
         $output = '*0';
104
-        if (substr($setting, 0, 2) == $output)
105
-            $output = '*1';
110
+        if (substr($setting, 0, 2) == $output) {
111
+                    $output = '*1';
112
+        }
106 113
 
107 114
         $id = substr($setting, 0, 3);
108 115
         // We use "$P$", phpBB3 uses "$H$" for the same thing
109
-        if ($id != '$P$' && $id != '$H$')
110
-            return $output;
116
+        if ($id != '$P$' && $id != '$H$') {
117
+                    return $output;
118
+        }
111 119
 
112 120
         $count_log2 = strpos($this->itoa64, $setting[3]);
113
-        if ($count_log2 < 7 || $count_log2 > 30)
114
-            return $output;
121
+        if ($count_log2 < 7 || $count_log2 > 30) {
122
+                    return $output;
123
+        }
115 124
 
116 125
         $count = 1 << $count_log2;
117 126
 
118 127
         $salt = substr($setting, 4, 8);
119
-        if (strlen($salt) != 8)
120
-            return $output;
128
+        if (strlen($salt) != 8) {
129
+                    return $output;
130
+        }
121 131
 
122 132
         // We're kind of forced to use MD5 here since it's the only
123 133
         // cryptographic primitive available in all versions of PHP
@@ -208,26 +218,31 @@  discard block
 block discarded – undo
208 218
             $random = $this->get_random_bytes(16);
209 219
             $hash =
210 220
                 crypt($password, $this->gensalt_blowfish($random));
211
-            if (strlen($hash) == 60)
212
-                return $hash;
221
+            if (strlen($hash) == 60) {
222
+                            return $hash;
223
+            }
213 224
         }
214 225
 
215 226
         if (CRYPT_EXT_DES == 1 && !$this->portable_hashes) {
216
-            if (strlen($random) < 3)
217
-                $random = $this->get_random_bytes(3);
227
+            if (strlen($random) < 3) {
228
+                            $random = $this->get_random_bytes(3);
229
+            }
218 230
             $hash =
219 231
                 crypt($password, $this->gensalt_extended($random));
220
-            if (strlen($hash) == 20)
221
-                return $hash;
232
+            if (strlen($hash) == 20) {
233
+                            return $hash;
234
+            }
222 235
         }
223 236
 
224
-        if (strlen($random) < 6)
225
-            $random = $this->get_random_bytes(6);
237
+        if (strlen($random) < 6) {
238
+                    $random = $this->get_random_bytes(6);
239
+        }
226 240
         $hash =
227 241
             $this->crypt_private($password,
228 242
             $this->gensalt_private($random));
229
-        if (strlen($hash) == 34)
230
-            return $hash;
243
+        if (strlen($hash) == 34) {
244
+                    return $hash;
245
+        }
231 246
 
232 247
         // Returning '*' on error is safe here, but would _not_ be safe
233 248
         // in a crypt(3)-like function used _both_ for generating new
@@ -242,8 +257,9 @@  discard block
 block discarded – undo
242 257
         }
243 258
 
244 259
         $hash = $this->crypt_private($password, $stored_hash);
245
-        if (substr($hash,0,1) === '*')
246
-            $hash = crypt($password, $stored_hash);
260
+        if (substr($hash,0,1) === '*') {
261
+                    $hash = crypt($password, $stored_hash);
262
+        }
247 263
 
248 264
         return ($hash===$stored_hash) ? true : false;
249 265
     }
Please login to merge, or discard this patch.
Upper-Lower-Casing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 
41 41
         $this->portable_hashes = $portable_hashes;
42 42
 
43
-        $this->random_state = microtime() . uniqid(mt_rand(), TRUE);
43
+        $this->random_state = microtime() . uniqid(mt_rand(), true);
44 44
     }
45 45
 
46 46
     function get_random_bytes($count)
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
         // consequently in lower iteration counts and hashes that are
127 127
         // quicker to crack (by non-PHP code).
128 128
         
129
-        $hash = md5($salt . $password, TRUE);
129
+        $hash = md5($salt . $password, true);
130 130
         do {
131
-            $hash = md5($hash . $password, TRUE);
131
+            $hash = md5($hash . $password, true);
132 132
         } while (--$count);
133 133
 
134 134
         $output = substr($setting, 0, 12);
Please login to merge, or discard this patch.
manager/includes/menu.class.inc.php 2 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -40,6 +40,10 @@
 block discarded – undo
40 40
         $this->menu = $new;
41 41
     }
42 42
 
43
+    /**
44
+     * @param string $parentid
45
+     * @param integer $level
46
+     */
43 47
     function DrawSub($parentid, $level)
44 48
     {
45 49
         global $modx;
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -65,14 +65,14 @@  discard block
 block discarded – undo
65 65
                 $countChild++;
66 66
                 $id = $value[0];
67 67
                 $ph['id'] = $id;
68
-                $ph['li_class'] = $this->get_li_class($id) . $value[10];
68
+                $ph['li_class'] = $this->get_li_class($id).$value[10];
69 69
                 $ph['href'] = $value[3];
70 70
                 $ph['alt'] = $value[4];
71 71
                 $ph['target'] = $value[7];
72 72
                 $ph['onclick'] = $value[5];
73 73
                 $ph['a_class'] = $this->get_a_class($id);
74 74
                 $ph['LinkAttr'] = $this->getLinkAttr($id);
75
-                $ph['itemName'] = $value[2] . $this->getItemName($id);
75
+                $ph['itemName'] = $value[2].$this->getItemName($id);
76 76
 
77 77
                 $ph['DrawSub'] = '';
78 78
 
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
     function get_li_class($id)
112 112
     {
113 113
         if (isset($this->menu[$id])) {
114
-            return $this->defaults['parentClass'] . ' ';
114
+            return $this->defaults['parentClass'].' ';
115 115
         } else {
116 116
             return '';
117 117
         }
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
     function get_a_class($id)
121 121
     {
122 122
         if (isset($this->menu[$id])) {
123
-            return ' class="' . $this->defaults['parentLinkClass'] . '"';
123
+            return ' class="'.$this->defaults['parentLinkClass'].'"';
124 124
         } else {
125 125
             return '';
126 126
         }
Please login to merge, or discard this patch.
manager/includes/protect.inc.php 3 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -14,6 +14,10 @@
 block discarded – undo
14 14
 
15 15
 // sanitize array
16 16
 if (!function_exists('modx_sanitize_gpc')) {
17
+
18
+    /**
19
+     * @param string $values
20
+     */
17 21
     function modx_sanitize_gpc(& $values, $depth=0) {
18 22
         if(200 < $depth) exit('GPC Array nested too deep!');
19 23
         if(is_array($values)) {
Please login to merge, or discard this patch.
Braces   +22 added lines, -9 removed lines patch added patch discarded remove patch
@@ -6,37 +6,50 @@
 block discarded – undo
6 6
 error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);
7 7
 
8 8
 // Null is evil
9
-if (isset($_SERVER['QUERY_STRING']) && strpos(urldecode($_SERVER['QUERY_STRING']), chr(0)) !== false)
9
+if (isset($_SERVER['QUERY_STRING']) && strpos(urldecode($_SERVER['QUERY_STRING']), chr(0)) !== false) {
10 10
     die();
11
+}
11 12
 
12 13
 global $sanitize_seed;
13 14
 $sanitize_seed = 'sanitize_seed_' . base_convert(md5(__FILE__),16,36);
14 15
 
15 16
 // sanitize array
16 17
 if (!function_exists('modx_sanitize_gpc')) {
17
-    function modx_sanitize_gpc(& $values, $depth=0) {
18
-        if(200 < $depth) exit('GPC Array nested too deep!');
18
+    function modx_sanitize_gpc(& $values, $depth=0)
19
+    {
20
+        if(200 < $depth) {
21
+            exit('GPC Array nested too deep!');
22
+        }
19 23
         if(is_array($values)) {
20 24
             $depth++;
21 25
             foreach ($values as $key => $value) {
22
-                if (is_array($value)) modx_sanitize_gpc($value, $depth);
23
-                else                  $values[$key] = getSanitizedValue($value);
26
+                if (is_array($value)) {
27
+                    modx_sanitize_gpc($value, $depth);
28
+                } else {
29
+                    $values[$key] = getSanitizedValue($value);
30
+                }
24 31
             }
32
+        } else {
33
+            $values = getSanitizedValue($values);
25 34
         }
26
-        else $values = getSanitizedValue($values);
27 35
         
28 36
         return $values;
29 37
     }
30 38
 }
31 39
 
32
-function getSanitizedValue($value='') {
40
+function getSanitizedValue($value='')
41
+{
33 42
     global $sanitize_seed;
34 43
     
35
-    if(!$value) return $value;
44
+    if(!$value) {
45
+        return $value;
46
+    }
36 47
     
37 48
     $brackets = explode(' ', '[[ ]] [! !] [* *] [( )] {{ }} [+ +] [~ ~] [^ ^]');
38 49
     foreach($brackets as $bracket) {
39
-        if(strpos($value,$bracket)===false) continue;
50
+        if(strpos($value,$bracket)===false) {
51
+            continue;
52
+        }
40 53
         $sanitizedBracket = str_replace('#', $sanitize_seed, sprintf('#%s#%s#', substr($bracket,0,1), substr($bracket,1,1)));
41 54
         $value = str_replace($bracket,$sanitizedBracket,$value);
42 55
     }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -10,13 +10,13 @@  discard block
 block discarded – undo
10 10
     die();
11 11
 
12 12
 global $sanitize_seed;
13
-$sanitize_seed = 'sanitize_seed_' . base_convert(md5(__FILE__),16,36);
13
+$sanitize_seed = 'sanitize_seed_'.base_convert(md5(__FILE__), 16, 36);
14 14
 
15 15
 // sanitize array
16 16
 if (!function_exists('modx_sanitize_gpc')) {
17
-    function modx_sanitize_gpc(& $values, $depth=0) {
18
-        if(200 < $depth) exit('GPC Array nested too deep!');
19
-        if(is_array($values)) {
17
+    function modx_sanitize_gpc(& $values, $depth = 0){
18
+        if (200 < $depth) exit('GPC Array nested too deep!');
19
+        if (is_array($values)) {
20 20
             $depth++;
21 21
             foreach ($values as $key => $value) {
22 22
                 if (is_array($value)) modx_sanitize_gpc($value, $depth);
@@ -29,16 +29,16 @@  discard block
 block discarded – undo
29 29
     }
30 30
 }
31 31
 
32
-function getSanitizedValue($value='') {
32
+function getSanitizedValue($value = ''){
33 33
     global $sanitize_seed;
34 34
 
35
-    if(!$value) return $value;
35
+    if (!$value) return $value;
36 36
 
37 37
     $brackets = explode(' ', '[[ ]] [! !] [* *] [( )] {{ }} [+ +] [~ ~] [^ ^]');
38
-    foreach($brackets as $bracket) {
39
-        if(strpos($value,$bracket)===false) continue;
40
-        $sanitizedBracket = str_replace('#', $sanitize_seed, sprintf('#%s#%s#', substr($bracket,0,1), substr($bracket,1,1)));
41
-        $value = str_replace($bracket,$sanitizedBracket,$value);
38
+    foreach ($brackets as $bracket) {
39
+        if (strpos($value, $bracket) === false) continue;
40
+        $sanitizedBracket = str_replace('#', $sanitize_seed, sprintf('#%s#%s#', substr($bracket, 0, 1), substr($bracket, 1, 1)));
41
+        $value = str_replace($bracket, $sanitizedBracket, $value);
42 42
     }
43 43
     $value = str_ireplace('<script', 'sanitized_by_modx<s cript', $value);
44 44
     $value = preg_replace('/&#(\d+);/', 'sanitized_by_modx& #$1', $value);
@@ -46,13 +46,13 @@  discard block
 block discarded – undo
46 46
 }
47 47
 
48 48
 modx_sanitize_gpc($_GET);
49
-if( ! defined('IN_MANAGER_MODE') || IN_MANAGER_MODE !== true) {
49
+if (!defined('IN_MANAGER_MODE') || IN_MANAGER_MODE !== true) {
50 50
     modx_sanitize_gpc($_POST);
51 51
 }
52 52
 modx_sanitize_gpc($_COOKIE);
53 53
 modx_sanitize_gpc($_REQUEST);
54 54
 
55
-foreach (array ('PHP_SELF', 'HTTP_USER_AGENT', 'HTTP_REFERER', 'QUERY_STRING') as $key) {
55
+foreach (array('PHP_SELF', 'HTTP_USER_AGENT', 'HTTP_REFERER', 'QUERY_STRING') as $key) {
56 56
     $_SERVER[$key] = isset ($_SERVER[$key]) ? htmlspecialchars($_SERVER[$key], ENT_QUOTES) : null;
57 57
 }
58 58
 
Please login to merge, or discard this patch.
manager/includes/tmplvars.commands.inc.php 5 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -125,6 +125,9 @@  discard block
 block discarded – undo
125 125
 }
126 126
 
127 127
 // ParseCommand - separate @ cmd from params
128
+/**
129
+ * @param string $binding_string
130
+ */
128 131
 function ParseCommand($binding_string)
129 132
 {
130 133
     global $BINDINGS;
@@ -142,6 +145,9 @@  discard block
 block discarded – undo
142 145
 }
143 146
 
144 147
 // Parse MODX Template-Variables
148
+/**
149
+ * @return string
150
+ */
145 151
 function parseTvValues($param, $tvsArray)
146 152
 {
147 153
 	global $modx;
Please login to merge, or discard this patch.
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
 
120 120
 function ProcessFile($file) {
121 121
     // get the file
122
-	$buffer = @file_get_contents($file);
123
-	if ($buffer===false) $buffer = " Could not retrieve document '$file'.";
122
+    $buffer = @file_get_contents($file);
123
+    if ($buffer===false) $buffer = " Could not retrieve document '$file'.";
124 124
     return $buffer;
125 125
 }
126 126
 
@@ -144,21 +144,21 @@  discard block
 block discarded – undo
144 144
 // Parse MODX Template-Variables
145 145
 function parseTvValues($param, $tvsArray)
146 146
 {
147
-	global $modx;
148
-	$tvsArray = is_array($modx->documentObject) ? array_merge($tvsArray, $modx->documentObject) : $tvsArray;
149
-	if (strpos($param, '[*') !== false) {
150
-		$matches = $modx->getTagsFromContent($param, '[*', '*]');
151
-		foreach ($matches[0] as $i=>$match) {
152
-			if(isset($tvsArray[ $matches[1][$i] ])) {
153
-				if(is_array($tvsArray[ $matches[1][$i] ])) {
154
-					$value = $tvsArray[$matches[1][$i]]['value'];
155
-					$value = $value === '' ? $tvsArray[$matches[1][$i]]['default_text'] : $value;
156
-				} else {
157
-					$value = $tvsArray[ $matches[1][$i] ];
158
-				}
159
-				$param = str_replace($match, $value, $param);
160
-			}
161
-		}
162
-	}
163
-	return $param;
147
+    global $modx;
148
+    $tvsArray = is_array($modx->documentObject) ? array_merge($tvsArray, $modx->documentObject) : $tvsArray;
149
+    if (strpos($param, '[*') !== false) {
150
+        $matches = $modx->getTagsFromContent($param, '[*', '*]');
151
+        foreach ($matches[0] as $i=>$match) {
152
+            if(isset($tvsArray[ $matches[1][$i] ])) {
153
+                if(is_array($tvsArray[ $matches[1][$i] ])) {
154
+                    $value = $tvsArray[$matches[1][$i]]['value'];
155
+                    $value = $value === '' ? $tvsArray[$matches[1][$i]]['default_text'] : $value;
156
+                } else {
157
+                    $value = $tvsArray[ $matches[1][$i] ];
158
+                }
159
+                $param = str_replace($match, $value, $param);
160
+            }
161
+        }
162
+    }
163
+    return $param;
164 164
 }
165 165
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * Created by Raymond Irving Feb, 2005
5 5
  */
6 6
 global $BINDINGS; // Array of supported bindings. must be upper case
7
-$BINDINGS = array (
7
+$BINDINGS = array(
8 8
     'FILE',
9 9
     'CHUNK',
10 10
     'DOCUMENT',
@@ -14,13 +14,13 @@  discard block
 block discarded – undo
14 14
     'DIRECTORY'
15 15
 );
16 16
 
17
-function ProcessTVCommand($value, $name = '', $docid = '', $src='docform', $tvsArray = array()) {
17
+function ProcessTVCommand($value, $name = '', $docid = '', $src = 'docform', $tvsArray = array()){
18 18
     global $modx;
19 19
     $docid = intval($docid) ? intval($docid) : $modx->documentIdentifier;
20 20
     $nvalue = trim($value);
21 21
     if (substr($nvalue, 0, 1) != '@')
22 22
         return $value;
23
-    elseif(isset($modx->config['enable_bindings']) && $modx->config['enable_bindings']!=1 && $src==='docform') {
23
+    elseif (isset($modx->config['enable_bindings']) && $modx->config['enable_bindings'] != 1 && $src === 'docform') {
24 24
         return '@Bindings is disabled.';
25 25
     }
26 26
     else {
@@ -46,8 +46,8 @@  discard block
 block discarded – undo
46 46
                 break;
47 47
 
48 48
             case "SELECT" : // selects a record from the cms database
49
-                $rt = array ();
50
-                $replacementVars = array (
49
+                $rt = array();
50
+                $replacementVars = array(
51 51
                     'DBASE' => $modx->db->config['dbase'],
52 52
                     'PREFIX' => $modx->db->config['table_prefix']
53 53
                 );
@@ -88,8 +88,8 @@  discard block
 block discarded – undo
88 88
                 break;
89 89
 
90 90
             case 'DIRECTORY' :
91
-                $files = array ();
92
-                $path = $modx->config['base_path'] . $param;
91
+                $files = array();
92
+                $path = $modx->config['base_path'].$param;
93 93
                 if (substr($path, -1, 1) != '/') {
94 94
                     $path .= '/';
95 95
                 }
@@ -117,10 +117,10 @@  discard block
 block discarded – undo
117 117
     }
118 118
 }
119 119
 
120
-function ProcessFile($file) {
120
+function ProcessFile($file){
121 121
     // get the file
122 122
 	$buffer = @file_get_contents($file);
123
-	if ($buffer===false) $buffer = " Could not retrieve document '$file'.";
123
+	if ($buffer === false) $buffer = " Could not retrieve document '$file'.";
124 124
     return $buffer;
125 125
 }
126 126
 
@@ -129,12 +129,12 @@  discard block
 block discarded – undo
129 129
 {
130 130
     global $BINDINGS;
131 131
     $binding_array = array();
132
-    foreach($BINDINGS as $cmd)
132
+    foreach ($BINDINGS as $cmd)
133 133
     {
134
-        if(strpos($binding_string,'@'.$cmd)===0)
134
+        if (strpos($binding_string, '@'.$cmd) === 0)
135 135
         {
136
-            $code = substr($binding_string,strlen($cmd)+1);
137
-            $binding_array = array($cmd,trim($code));
136
+            $code = substr($binding_string, strlen($cmd) + 1);
137
+            $binding_array = array($cmd, trim($code));
138 138
             break;
139 139
         }
140 140
     }
@@ -149,12 +149,12 @@  discard block
 block discarded – undo
149 149
 	if (strpos($param, '[*') !== false) {
150 150
 		$matches = $modx->getTagsFromContent($param, '[*', '*]');
151 151
 		foreach ($matches[0] as $i=>$match) {
152
-			if(isset($tvsArray[ $matches[1][$i] ])) {
153
-				if(is_array($tvsArray[ $matches[1][$i] ])) {
152
+			if (isset($tvsArray[$matches[1][$i]])) {
153
+				if (is_array($tvsArray[$matches[1][$i]])) {
154 154
 					$value = $tvsArray[$matches[1][$i]]['value'];
155 155
 					$value = $value === '' ? $tvsArray[$matches[1][$i]]['default_text'] : $value;
156 156
 				} else {
157
-					$value = $tvsArray[ $matches[1][$i] ];
157
+					$value = $tvsArray[$matches[1][$i]];
158 158
 				}
159 159
 				$param = str_replace($match, $value, $param);
160 160
 			}
Please login to merge, or discard this patch.
Braces   +22 added lines, -18 removed lines patch added patch discarded remove patch
@@ -14,16 +14,16 @@  discard block
 block discarded – undo
14 14
     'DIRECTORY'
15 15
 );
16 16
 
17
-function ProcessTVCommand($value, $name = '', $docid = '', $src='docform', $tvsArray = array()) {
17
+function ProcessTVCommand($value, $name = '', $docid = '', $src='docform', $tvsArray = array())
18
+{
18 19
     global $modx;
19 20
     $docid = intval($docid) ? intval($docid) : $modx->documentIdentifier;
20 21
     $nvalue = trim($value);
21
-    if (substr($nvalue, 0, 1) != '@')
22
-        return $value;
23
-    elseif(isset($modx->config['enable_bindings']) && $modx->config['enable_bindings']!=1 && $src==='docform') {
22
+    if (substr($nvalue, 0, 1) != '@') {
23
+            return $value;
24
+    } elseif(isset($modx->config['enable_bindings']) && $modx->config['enable_bindings']!=1 && $src==='docform') {
24 25
         return '@Bindings is disabled.';
25
-    }
26
-    else {
26
+    } else {
27 27
         list ($cmd, $param) = ParseCommand($nvalue);
28 28
         $cmd = trim($cmd);
29 29
         $param = parseTvValues($param, $tvsArray);
@@ -39,10 +39,11 @@  discard block
 block discarded – undo
39 39
 
40 40
             case "DOCUMENT" : // retrieve a document and process it's content
41 41
                 $rs = $modx->getDocument($param);
42
-                if (is_array($rs))
43
-                    $output = $rs['content'];
44
-                else
45
-                    $output = "Unable to locate document $param";
42
+                if (is_array($rs)) {
43
+                                    $output = $rs['content'];
44
+                } else {
45
+                                    $output = "Unable to locate document $param";
46
+                }
46 47
                 break;
47 48
 
48 49
             case "SELECT" : // selects a record from the cms database
@@ -72,8 +73,10 @@  discard block
 block discarded – undo
72 73
 
73 74
                     // Grab document regardless of publish status
74 75
                     $doc = $modx->getPageInfo($parent_id, 0, 'id,parent,published');
75
-                    if ($doc['parent'] != 0 && !$doc['published'])
76
-                        continue; // hide unpublished docs if we're not at the top
76
+                    if ($doc['parent'] != 0 && !$doc['published']) {
77
+                                            continue;
78
+                    }
79
+                    // hide unpublished docs if we're not at the top
77 80
 
78 81
                     $tv = $modx->getTemplateVar($name, '*', $doc['id'], $doc['published']);
79 82
 
@@ -117,10 +120,13 @@  discard block
 block discarded – undo
117 120
     }
118 121
 }
119 122
 
120
-function ProcessFile($file) {
123
+function ProcessFile($file)
124
+{
121 125
     // get the file
122 126
 	$buffer = @file_get_contents($file);
123
-	if ($buffer===false) $buffer = " Could not retrieve document '$file'.";
127
+	if ($buffer===false) {
128
+	    $buffer = " Could not retrieve document '$file'.";
129
+	}
124 130
     return $buffer;
125 131
 }
126 132
 
@@ -129,10 +135,8 @@  discard block
 block discarded – undo
129 135
 {
130 136
     global $BINDINGS;
131 137
     $binding_array = array();
132
-    foreach($BINDINGS as $cmd)
133
-    {
134
-        if(strpos($binding_string,'@'.$cmd)===0)
135
-        {
138
+    foreach($BINDINGS as $cmd) {
139
+        if(strpos($binding_string,'@'.$cmd)===0) {
136 140
             $code = substr($binding_string,strlen($cmd)+1);
137 141
             $binding_array = array($cmd,trim($code));
138 142
             break;
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@
 block discarded – undo
55 55
                     $modx->setPlaceholder($rvKey, $rvValue);
56 56
                 }
57 57
                 $param = $modx->mergePlaceholderContent($param);
58
-                $rs = $modx->db->query("SELECT $param;");
58
+                $rs = $modx->db->query("select $param;");
59 59
                 $output = $rs;
60 60
                 break;
61 61
 
Please login to merge, or discard this patch.
manager/media/browser/mcpuk/core/browser.php 5 patches
Doc Comments   +9 added lines patch added patch discarded remove patch
@@ -666,6 +666,9 @@  discard block
 block discarded – undo
666 666
             return json_encode(array('version' => false));
667 667
     }
668 668
 
669
+    /**
670
+     * @param string $dir
671
+     */
669 672
     protected function moveUploadFile($file, $dir) {
670 673
         $message = $this->checkUploadedFile($file);
671 674
 
@@ -697,6 +700,9 @@  discard block
 block discarded – undo
697 700
         return "/" . basename($target);
698 701
     }
699 702
 
703
+    /**
704
+     * @param string $file
705
+     */
700 706
     protected function sendDefaultThumb($file=null) {
701 707
         if ($file !== null) {
702 708
             $ext = file::getExtension($file);
@@ -873,6 +879,9 @@  discard block
 block discarded – undo
873 879
         return "";
874 880
     }
875 881
 
882
+    /**
883
+     * @param string $message
884
+     */
876 885
     protected function errorMsg($message, array $data=null) {
877 886
         if (in_array($this->action, array("thumb", "upload", "download", "downloadDir")))
878 887
             die($this->label($message, $data));
Please login to merge, or discard this patch.
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 /** This file is part of KCFinder project
4
-  *
5
-  *      @desc Browser actions class
6
-  *   @package KCFinder
7
-  *   @version 2.54
8
-  *    @author Pavel Tzonkov <[email protected]>
9
-  * @copyright 2010-2014 KCFinder Project
10
-  *   @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2
11
-  *   @license http://www.opensource.org/licenses/lgpl-2.1.php LGPLv2
12
-  *      @link http://kcfinder.sunhater.com
13
-  */
4
+ *
5
+ *      @desc Browser actions class
6
+ *   @package KCFinder
7
+ *   @version 2.54
8
+ *    @author Pavel Tzonkov <[email protected]>
9
+ * @copyright 2010-2014 KCFinder Project
10
+ *   @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2
11
+ *   @license http://www.opensource.org/licenses/lgpl-2.1.php LGPLv2
12
+ *      @link http://kcfinder.sunhater.com
13
+ */
14 14
 
15 15
 class browser extends uploader {
16 16
     protected $action;
@@ -709,54 +709,54 @@  discard block
 block discarded – undo
709 709
         die;
710 710
     }
711 711
 
712
-	protected function getFiles($dir) {
713
-		$thumbDir = "{$this->config['uploadDir']}/{$this->config['thumbsDir']}/$dir";
714
-		$dir = "{$this->config['uploadDir']}/$dir";
715
-		$return = array();
716
-		$files = dir::content($dir, array('types' => "file"));
717
-		if ($files === false)
718
-			return $return;
719
-
720
-		foreach ($files as $file) {
721
-			$ext = file::getExtension($file);
722
-			$smallThumb = false;
723
-			if (in_array(strtolower($ext), array('png', 'jpg', 'gif', 'jpeg' )) ) {
724
-				$size = @getimagesize($file);
725
-				if (is_array($size) && count($size)) {
726
-					$thumb_file = "$thumbDir/" . basename($file);
727
-					if (!is_file($thumb_file) || filemtime($file) > filemtime($thumb_file))
728
-						$this->makeThumb($file);
729
-					$smallThumb =
730
-						($size[0] <= $this->config['thumbWidth']) &&
731
-						($size[1] <= $this->config['thumbHeight']) &&
732
-						in_array($size[2], array(IMAGETYPE_GIF, IMAGETYPE_PNG, IMAGETYPE_JPEG));
733
-				}
734
-			}
735
-			$stat = stat($file);
736
-			if ($stat === false) continue;
737
-			$name = basename($file);
738
-			$types = $this->config['types'];
739
-			$types = explode(' ',$types['images'].' '.$types['image']);
740
-			if (substr($name,0,1) == '.' && !$this->config['showHiddenFiles']) continue;
741
-			if ($this->type == 'images' && !in_array(strtolower($ext),$types)) continue;
742
-			$bigIcon = file_exists("themes/{$this->config['theme']}/img/files/big/$ext.png");
743
-			$smallIcon = file_exists("themes/{$this->config['theme']}/img/files/small/$ext.png");
744
-			$thumb = file_exists("$thumbDir/$name");
745
-			$return[] = array(
746
-				'name' => stripcslashes($name),
747
-				'size' => $stat['size'],
748
-				'mtime' => $stat['mtime'],
749
-				'date' => @strftime($this->dateTimeSmall, $stat['mtime']),
750
-				'readable' => is_readable($file),
751
-				'writable' => file::isWritable($file),
752
-				'bigIcon' => $bigIcon,
753
-				'smallIcon' => $smallIcon,
754
-				'thumb' => $thumb,
755
-				'smallThumb' => $smallThumb
756
-			);
757
-		}
758
-		return $return;
759
-	}
712
+    protected function getFiles($dir) {
713
+        $thumbDir = "{$this->config['uploadDir']}/{$this->config['thumbsDir']}/$dir";
714
+        $dir = "{$this->config['uploadDir']}/$dir";
715
+        $return = array();
716
+        $files = dir::content($dir, array('types' => "file"));
717
+        if ($files === false)
718
+            return $return;
719
+
720
+        foreach ($files as $file) {
721
+            $ext = file::getExtension($file);
722
+            $smallThumb = false;
723
+            if (in_array(strtolower($ext), array('png', 'jpg', 'gif', 'jpeg' )) ) {
724
+                $size = @getimagesize($file);
725
+                if (is_array($size) && count($size)) {
726
+                    $thumb_file = "$thumbDir/" . basename($file);
727
+                    if (!is_file($thumb_file) || filemtime($file) > filemtime($thumb_file))
728
+                        $this->makeThumb($file);
729
+                    $smallThumb =
730
+                        ($size[0] <= $this->config['thumbWidth']) &&
731
+                        ($size[1] <= $this->config['thumbHeight']) &&
732
+                        in_array($size[2], array(IMAGETYPE_GIF, IMAGETYPE_PNG, IMAGETYPE_JPEG));
733
+                }
734
+            }
735
+            $stat = stat($file);
736
+            if ($stat === false) continue;
737
+            $name = basename($file);
738
+            $types = $this->config['types'];
739
+            $types = explode(' ',$types['images'].' '.$types['image']);
740
+            if (substr($name,0,1) == '.' && !$this->config['showHiddenFiles']) continue;
741
+            if ($this->type == 'images' && !in_array(strtolower($ext),$types)) continue;
742
+            $bigIcon = file_exists("themes/{$this->config['theme']}/img/files/big/$ext.png");
743
+            $smallIcon = file_exists("themes/{$this->config['theme']}/img/files/small/$ext.png");
744
+            $thumb = file_exists("$thumbDir/$name");
745
+            $return[] = array(
746
+                'name' => stripcslashes($name),
747
+                'size' => $stat['size'],
748
+                'mtime' => $stat['mtime'],
749
+                'date' => @strftime($this->dateTimeSmall, $stat['mtime']),
750
+                'readable' => is_readable($file),
751
+                'writable' => file::isWritable($file),
752
+                'bigIcon' => $bigIcon,
753
+                'smallIcon' => $smallIcon,
754
+                'thumb' => $thumb,
755
+                'smallThumb' => $smallThumb
756
+            );
757
+        }
758
+        return $return;
759
+    }
760 760
 
761 761
     protected function getTree($dir, $index=0) {
762 762
         $path = explode("/", $dir);
Please login to merge, or discard this patch.
Spacing   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -12,12 +12,12 @@  discard block
 block discarded – undo
12 12
   *      @link http://kcfinder.sunhater.com
13 13
   */
14 14
 
15
-class browser extends uploader {
15
+class browser extends uploader{
16 16
     protected $action;
17 17
     protected $thumbsDir;
18 18
     protected $thumbsTypeDir;
19 19
 
20
-    public function __construct($modx) {
20
+    public function __construct($modx){
21 21
         parent::__construct($modx);
22 22
 
23 23
         if (isset($this->post['dir'])) {
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
             $this->get['dir'] = $dir;
33 33
         }
34 34
 
35
-        $thumbsDir = $this->config['uploadDir'] . "/" . $this->config['thumbsDir'];
35
+        $thumbsDir = $this->config['uploadDir']."/".$this->config['thumbsDir'];
36 36
         if ((
37 37
                 !is_dir($thumbsDir) &&
38 38
                 !@mkdir($thumbsDir, $this->config['dirPerms'])
@@ -70,9 +70,9 @@  discard block
 block discarded – undo
70 70
             $this->config['theme'] = $this->get['theme'];
71 71
     }
72 72
 
73
-    public function action() {
73
+    public function action(){
74 74
         $act = isset($this->get['act']) ? $this->get['act'] : "browser";
75
-        if(!preg_match('@^[0-9a-zA-Z_]+$@', $act)) $this->errorMsg("Unknown error.");
75
+        if (!preg_match('@^[0-9a-zA-Z_]+$@', $act)) $this->errorMsg("Unknown error.");
76 76
         if (!method_exists($this, "act_$act"))
77 77
             $act = "browser";
78 78
         $this->action = $act;
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
             $this->session['dir'] = $this->type;
95 95
         else {
96 96
             $type = $this->getTypeFromPath($this->session['dir']);
97
-            $dir = $this->config['uploadDir'] . "/" . $this->session['dir'];
97
+            $dir = $this->config['uploadDir']."/".$this->session['dir'];
98 98
             if (($type != $this->type) || !is_dir($dir) || !is_readable($dir))
99 99
                 $this->session['dir'] = $this->type;
100 100
         }
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
             : $return;
116 116
     }
117 117
 
118
-    protected function act_browser() {
118
+    protected function act_browser(){
119 119
         if (isset($this->get['dir']) &&
120 120
             is_dir("{$this->typeDir}/{$this->get['dir']}") &&
121 121
             is_readable("{$this->typeDir}/{$this->get['dir']}")
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
         return $this->output();
126 126
     }
127 127
 
128
-    protected function act_init() {
128
+    protected function act_init(){
129 129
         $tree = $this->getDirInfo($this->typeDir);
130 130
         $tree['dirs'] = $this->getTree($this->session['dir']);
131 131
         if (!is_array($tree['dirs']) || !count($tree['dirs']))
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
         return json_encode($data);
141 141
     }
142 142
 
143
-    protected function act_thumb() {
143
+    protected function act_thumb(){
144 144
         $this->getDir($this->get['dir'], true);
145 145
         if (!isset($this->get['file']) || !isset($this->get['dir']))
146 146
             $this->sendDefaultThumb();
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
             $this->sendDefaultThumb();
150 150
         $file = "{$this->thumbsDir}/{$this->type}/{$this->get['dir']}/$file";
151 151
         if (!is_file($file) || !is_readable($file)) {
152
-            $file = "{$this->config['uploadDir']}/{$this->type}/{$this->get['dir']}/" . basename($file);
152
+            $file = "{$this->config['uploadDir']}/{$this->type}/{$this->get['dir']}/".basename($file);
153 153
             if (!is_file($file) || !is_readable($file))
154 154
                 $this->sendDefaultThumb($file);
155 155
             $image = image::factory($this->imageDriver, $file);
@@ -171,13 +171,13 @@  discard block
 block discarded – undo
171 171
         httpCache::file($file, "image/jpeg");
172 172
     }
173 173
 
174
-    protected function act_expand() {
174
+    protected function act_expand(){
175 175
         return json_encode(array('dirs' => $this->getDirs($this->postDir())));
176 176
     }
177 177
 
178
-    protected function act_chDir() {
178
+    protected function act_chDir(){
179 179
         $this->postDir(); // Just for existing check
180
-        $this->session['dir'] = $this->type . "/" . $this->post['dir'];
180
+        $this->session['dir'] = $this->type."/".$this->post['dir'];
181 181
         $dirWritable = dir::isWritable("{$this->config['uploadDir']}/{$this->session['dir']}");
182 182
         return json_encode(array(
183 183
             'files' => $this->getFiles($this->session['dir']),
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
         ));
186 186
     }
187 187
 
188
-    protected function act_newDir() {
188
+    protected function act_newDir(){
189 189
         if (!$this->config['access']['dirs']['create'] ||
190 190
             !isset($this->post['dir']) ||
191 191
             !isset($this->post['newDir'])
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
         return true;
208 208
     }
209 209
 
210
-    protected function act_renameDir() {
210
+    protected function act_renameDir(){
211 211
         if (!$this->config['access']['dirs']['rename'] ||
212 212
             !isset($this->post['dir']) ||
213 213
             !isset($this->post['newName'])
@@ -222,15 +222,15 @@  discard block
 block discarded – undo
222 222
             $this->errorMsg("Unallowable characters in folder name.");
223 223
         if (substr($newName, 0, 1) == ".")
224 224
             $this->errorMsg("Folder name shouldn't begins with '.'");
225
-        if (!@rename($dir, dirname($dir) . "/$newName"))
225
+        if (!@rename($dir, dirname($dir)."/$newName"))
226 226
             $this->errorMsg("Cannot rename the folder.");
227 227
         $thumbDir = "$this->thumbsTypeDir/{$this->post['dir']}";
228 228
         if (is_dir($thumbDir))
229
-            @rename($thumbDir, dirname($thumbDir) . "/$newName");
229
+            @rename($thumbDir, dirname($thumbDir)."/$newName");
230 230
         return json_encode(array('name' => $newName));
231 231
     }
232 232
 
233
-    protected function act_deleteDir() {
233
+    protected function act_deleteDir(){
234 234
         if (!$this->config['access']['dirs']['delete'] ||
235 235
             !isset($this->post['dir']) ||
236 236
             !strlen(trim($this->post['dir']))
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
         return true;
251 251
     }
252 252
 
253
-    protected function act_upload() {
253
+    protected function act_upload(){
254 254
         if (!$this->config['access']['files']['upload'] ||
255 255
             !isset($this->post['dir'])
256 256
         )
@@ -275,11 +275,11 @@  discard block
 block discarded – undo
275 275
             return $this->moveUploadFile($this->file, $dir);
276 276
     }
277 277
 
278
-    protected function act_download() {
278
+    protected function act_download(){
279 279
         $dir = $this->postDir();
280 280
         if (!isset($this->post['dir']) ||
281 281
             !isset($this->post['file']) ||
282
-            strpos($this->post['file'],'../')!==false ||
282
+            strpos($this->post['file'], '../') !== false ||
283 283
             (false === ($file = "$dir/{$this->post['file']}")) ||
284 284
             !file_exists($file) || !is_readable($file)
285 285
         )
@@ -290,19 +290,19 @@  discard block
 block discarded – undo
290 290
         header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
291 291
         header("Cache-Control: private", false);
292 292
         header("Content-Type: application/octet-stream");
293
-        header('Content-Disposition: attachment; filename="' . str_replace('"', "_", $this->post['file']) . '"');
293
+        header('Content-Disposition: attachment; filename="'.str_replace('"', "_", $this->post['file']).'"');
294 294
         header("Content-Transfer-Encoding:­ binary");
295
-        header("Content-Length: " . filesize($file));
295
+        header("Content-Length: ".filesize($file));
296 296
         readfile($file);
297 297
         die;
298 298
     }
299 299
 
300
-    protected function act_rename() {
300
+    protected function act_rename(){
301 301
         $dir = $this->postDir();
302 302
         if (!$this->config['access']['files']['rename'] ||
303 303
             !isset($this->post['dir']) ||
304 304
             !isset($this->post['file']) ||
305
-            strpos($this->post['file'],'../')!==false ||
305
+            strpos($this->post['file'], '../') !== false ||
306 306
             !isset($this->post['newName']) ||
307 307
             (false === ($file = "$dir/{$this->post['file']}")) ||
308 308
             !file_exists($file) || !is_readable($file) || !file::isWritable($file)
@@ -337,16 +337,16 @@  discard block
 block discarded – undo
337 337
         $thumbFile = "$thumbDir/{$this->post['file']}";
338 338
 
339 339
         if (file_exists($thumbFile))
340
-            @rename($thumbFile, "$thumbDir/" . basename($newName));
340
+            @rename($thumbFile, "$thumbDir/".basename($newName));
341 341
         return true;
342 342
     }
343 343
 
344
-    protected function act_delete() {
344
+    protected function act_delete(){
345 345
         $dir = $this->postDir();
346 346
         if (!$this->config['access']['files']['delete'] ||
347 347
             !isset($this->post['dir']) ||
348 348
             !isset($this->post['file']) ||
349
-            strpos($this->post['file'],'../')!==false ||
349
+            strpos($this->post['file'], '../') !== false ||
350 350
             (false === ($file = "$dir/{$this->post['file']}")) ||
351 351
             !file_exists($file) || !is_readable($file) || !file::isWritable($file) ||
352 352
             !@unlink($file)
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
         return true;
359 359
     }
360 360
 
361
-    protected function act_cp_cbd() {
361
+    protected function act_cp_cbd(){
362 362
         $dir = $this->postDir();
363 363
         if (!$this->config['access']['files']['copy'] ||
364 364
             !isset($this->post['dir']) ||
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
             $this->errorMsg("Unknown error.");
370 370
 
371 371
         $error = array();
372
-        foreach($this->post['files'] as $file) {
372
+        foreach ($this->post['files'] as $file) {
373 373
             $file = path::normalize($file);
374 374
             if (substr($file, 0, 1) == ".") continue;
375 375
             $type = explode("/", $file);
@@ -382,11 +382,11 @@  discard block
 block discarded – undo
382 382
             if (!file_exists($path))
383 383
                 $error[] = $this->label("The file '{file}' does not exist.", $replace);
384 384
             elseif (substr($base, 0, 1) == ".")
385
-                $error[] = "$base: " . $this->label("File name shouldn't begins with '.'");
385
+                $error[] = "$base: ".$this->label("File name shouldn't begins with '.'");
386 386
             elseif (!$this->validateExtension($ext, $type))
387
-                $error[] = "$base: " . $this->label("Denied file extension.");
387
+                $error[] = "$base: ".$this->label("Denied file extension.");
388 388
             elseif (file_exists("$dir/$base"))
389
-                $error[] = "$base: " . $this->label("A file or folder with that name already exists.");
389
+                $error[] = "$base: ".$this->label("A file or folder with that name already exists.");
390 390
             elseif (!is_readable($path) || !is_file($path))
391 391
                 $error[] = $this->label("Cannot read '{file}'.", $replace);
392 392
             elseif (!@copy($path, "$dir/$base"))
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
         return true;
410 410
     }
411 411
 
412
-    protected function act_mv_cbd() {
412
+    protected function act_mv_cbd(){
413 413
         $dir = $this->postDir();
414 414
         if (!$this->config['access']['files']['move'] ||
415 415
             !isset($this->post['dir']) ||
@@ -420,7 +420,7 @@  discard block
 block discarded – undo
420 420
             $this->errorMsg("Unknown error.");
421 421
 
422 422
         $error = array();
423
-        foreach($this->post['files'] as $file) {
423
+        foreach ($this->post['files'] as $file) {
424 424
             $file = path::normalize($file);
425 425
             if (substr($file, 0, 1) == ".") continue;
426 426
             $type = explode("/", $file);
@@ -433,11 +433,11 @@  discard block
 block discarded – undo
433 433
             if (!file_exists($path))
434 434
                 $error[] = $this->label("The file '{file}' does not exist.", $replace);
435 435
             elseif (substr($base, 0, 1) == ".")
436
-                $error[] = "$base: " . $this->label("File name shouldn't begins with '.'");
436
+                $error[] = "$base: ".$this->label("File name shouldn't begins with '.'");
437 437
             elseif (!$this->validateExtension($ext, $type))
438
-                $error[] = "$base: " . $this->label("Denied file extension.");
438
+                $error[] = "$base: ".$this->label("Denied file extension.");
439 439
             elseif (file_exists("$dir/$base"))
440
-                $error[] = "$base: " . $this->label("A file or folder with that name already exists.");
440
+                $error[] = "$base: ".$this->label("A file or folder with that name already exists.");
441 441
             elseif (!is_readable($path) || !is_file($path))
442 442
                 $error[] = $this->label("Cannot read '{file}'.", $replace);
443 443
             elseif (!file::isWritable($path) || !@rename($path, "$dir/$base"))
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
         return true;
461 461
     }
462 462
 
463
-    protected function act_rm_cbd() {
463
+    protected function act_rm_cbd(){
464 464
         if (!$this->config['access']['files']['delete'] ||
465 465
             !isset($this->post['files']) ||
466 466
             !is_array($this->post['files']) ||
@@ -469,7 +469,7 @@  discard block
 block discarded – undo
469 469
             $this->errorMsg("Unknown error.");
470 470
 
471 471
         $error = array();
472
-        foreach($this->post['files'] as $file) {
472
+        foreach ($this->post['files'] as $file) {
473 473
             $file = path::normalize($file);
474 474
             if (substr($file, 0, 1) == ".") continue;
475 475
             $type = explode("/", $file);
@@ -492,25 +492,25 @@  discard block
 block discarded – undo
492 492
         return true;
493 493
     }
494 494
 
495
-    protected function act_downloadDir() {
495
+    protected function act_downloadDir(){
496 496
         $dir = $this->postDir();
497 497
         if (!isset($this->post['dir']) || $this->config['denyZipDownload'])
498 498
             $this->errorMsg("Unknown error.");
499
-        $filename = basename($dir) . ".zip";
499
+        $filename = basename($dir).".zip";
500 500
         do {
501
-            $file = md5(time() . session_id());
501
+            $file = md5(time().session_id());
502 502
             $file = "{$this->config['uploadDir']}/$file.zip";
503 503
         } while (file_exists($file));
504 504
         new zipFolder($file, $dir);
505 505
         header("Content-Type: application/x-zip");
506
-        header('Content-Disposition: attachment; filename="' . str_replace('"', "_", $filename) . '"');
507
-        header("Content-Length: " . filesize($file));
506
+        header('Content-Disposition: attachment; filename="'.str_replace('"', "_", $filename).'"');
507
+        header("Content-Length: ".filesize($file));
508 508
         readfile($file);
509 509
         unlink($file);
510 510
         die;
511 511
     }
512 512
 
513
-    protected function act_downloadSelected() {
513
+    protected function act_downloadSelected(){
514 514
         $dir = $this->postDir();
515 515
         if (!isset($this->post['dir']) ||
516 516
             !isset($this->post['files']) ||
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
         }
532 532
 
533 533
         do {
534
-            $file = md5(time() . session_id());
534
+            $file = md5(time().session_id());
535 535
             $file = "{$this->config['uploadDir']}/$file.zip";
536 536
         } while (file_exists($file));
537 537
 
@@ -543,14 +543,14 @@  discard block
 block discarded – undo
543 543
             $zip->close();
544 544
         }
545 545
         header("Content-Type: application/x-zip");
546
-        header('Content-Disposition: attachment; filename="selected_files_' . basename($file) . '"');
547
-        header("Content-Length: " . filesize($file));
546
+        header('Content-Disposition: attachment; filename="selected_files_'.basename($file).'"');
547
+        header("Content-Length: ".filesize($file));
548 548
         readfile($file);
549 549
         unlink($file);
550 550
         die;
551 551
     }
552 552
 
553
-    protected function act_downloadClipboard() {
553
+    protected function act_downloadClipboard(){
554 554
         if (!isset($this->post['files']) ||
555 555
             !is_array($this->post['files']) ||
556 556
             $this->config['denyZipDownload']
@@ -566,14 +566,14 @@  discard block
 block discarded – undo
566 566
             $type = $type[0];
567 567
             if ($type != $this->type)
568 568
                 continue;
569
-            $file = $this->config['uploadDir'] . "/$file";
569
+            $file = $this->config['uploadDir']."/$file";
570 570
             if (!is_file($file) || !is_readable($file))
571 571
                 continue;
572 572
             $zipFiles[] = $file;
573 573
         }
574 574
 
575 575
         do {
576
-            $file = md5(time() . session_id());
576
+            $file = md5(time().session_id());
577 577
             $file = "{$this->config['uploadDir']}/$file.zip";
578 578
         } while (file_exists($file));
579 579
 
@@ -585,14 +585,14 @@  discard block
 block discarded – undo
585 585
             $zip->close();
586 586
         }
587 587
         header("Content-Type: application/x-zip");
588
-        header('Content-Disposition: attachment; filename="clipboard_' . basename($file) . '"');
589
-        header("Content-Length: " . filesize($file));
588
+        header('Content-Disposition: attachment; filename="clipboard_'.basename($file).'"');
589
+        header("Content-Length: ".filesize($file));
590 590
         readfile($file);
591 591
         unlink($file);
592 592
         die;
593 593
     }
594 594
 
595
-    protected function act_check4Update() {
595
+    protected function act_check4Update(){
596 596
         if ($this->config['denyUpdateCheck'])
597 597
             return json_encode(array('version' => false));
598 598
 
@@ -632,24 +632,24 @@  discard block
 block discarded – undo
632 632
         // Curl extension
633 633
         ) {} elseif (
634 634
             function_exists("curl_init") &&
635
-            (false !== (   $curl = @curl_init($url)                                    )) &&
636
-            (              @ob_start()                 ||  (@curl_close($curl) && false)) &&
637
-            (              @curl_exec($curl)           ||  (@curl_close($curl) && false)) &&
638
-            ((false !== (  $ver = @ob_get_clean()   )) ||  (@curl_close($curl) && false)) &&
639
-            (              @curl_close($curl)          ||  true                         ) &&
635
+            (false !== ($curl = @curl_init($url))) &&
636
+            (@ob_start() || (@curl_close($curl) && false)) &&
637
+            (@curl_exec($curl) || (@curl_close($curl) && false)) &&
638
+            ((false !== ($ver = @ob_get_clean())) || (@curl_close($curl) && false)) &&
639
+            (@curl_close($curl) || true) &&
640 640
             preg_match($pattern, $ver)
641 641
 
642 642
         // Socket extension
643 643
         ) {} elseif (function_exists('socket_create')) {
644 644
             $cmd =
645
-                "GET $path " . strtoupper($protocol) . "/1.1\r\n" .
646
-                "Host: $host\r\n" .
645
+                "GET $path ".strtoupper($protocol)."/1.1\r\n".
646
+                "Host: $host\r\n".
647 647
                 "Connection: Close\r\n\r\n";
648 648
 
649
-            if ((false !== (  $socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP)  )) &&
650
-                (false !==    @socket_connect($socket, $host, $port)                    ) &&
651
-                (false !==    @socket_write($socket, $cmd, strlen($cmd))                ) &&
652
-                (false !== (  $ver = @socket_read($socket, 2048)                       )) &&
649
+            if ((false !== ($socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP))) &&
650
+                (false !== @socket_connect($socket, $host, $port)) &&
651
+                (false !== @socket_write($socket, $cmd, strlen($cmd))) &&
652
+                (false !== ($ver = @socket_read($socket, 2048))) &&
653 653
                 preg_match($responsePattern, $ver, $match)
654 654
             )
655 655
                 $ver = $match[2];
@@ -666,7 +666,7 @@  discard block
 block discarded – undo
666 666
             return json_encode(array('version' => false));
667 667
     }
668 668
 
669
-    protected function moveUploadFile($file, $dir) {
669
+    protected function moveUploadFile($file, $dir){
670 670
         $message = $this->checkUploadedFile($file);
671 671
 
672 672
         if ($message !== true) {
@@ -676,28 +676,28 @@  discard block
 block discarded – undo
676 676
         }
677 677
 
678 678
         $filename = $this->normalizeFilename($file['name']);
679
-        $target = "$dir/" . file::getInexistantFilename($filename, $dir);
679
+        $target = "$dir/".file::getInexistantFilename($filename, $dir);
680 680
 
681 681
         if (!@move_uploaded_file($file['tmp_name'], $target) &&
682 682
             !@rename($file['tmp_name'], $target) &&
683 683
             !@copy($file['tmp_name'], $target)
684 684
         ) {
685 685
             @unlink($file['tmp_name']);
686
-            return "{$file['name']}: " . $this->label("Cannot move uploaded file to target folder.");
686
+            return "{$file['name']}: ".$this->label("Cannot move uploaded file to target folder.");
687 687
         } elseif (function_exists('chmod'))
688 688
             chmod($target, $this->config['filePerms']);
689 689
         
690
-        $this->modx->invokeEvent('OnFileBrowserUpload',array(
690
+        $this->modx->invokeEvent('OnFileBrowserUpload', array(
691 691
             'filepath'=>realpath($dir),
692
-            'filename'=>str_replace("/","",str_replace($dir,"",realpath($target)))
692
+            'filename'=>str_replace("/", "", str_replace($dir, "", realpath($target)))
693 693
         ));
694 694
         
695 695
         $this->makeThumb($target);
696 696
         
697
-        return "/" . basename($target);
697
+        return "/".basename($target);
698 698
     }
699 699
 
700
-    protected function sendDefaultThumb($file=null) {
700
+    protected function sendDefaultThumb($file = null){
701 701
         if ($file !== null) {
702 702
             $ext = file::getExtension($file);
703 703
             $thumb = "themes/{$this->config['theme']}/img/files/big/$ext.png";
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
         die;
710 710
     }
711 711
 
712
-	protected function getFiles($dir) {
712
+	protected function getFiles($dir){
713 713
 		$thumbDir = "{$this->config['uploadDir']}/{$this->config['thumbsDir']}/$dir";
714 714
 		$dir = "{$this->config['uploadDir']}/$dir";
715 715
 		$return = array();
@@ -720,10 +720,10 @@  discard block
 block discarded – undo
720 720
 		foreach ($files as $file) {
721 721
 			$ext = file::getExtension($file);
722 722
 			$smallThumb = false;
723
-			if (in_array(strtolower($ext), array('png', 'jpg', 'gif', 'jpeg' )) ) {
723
+			if (in_array(strtolower($ext), array('png', 'jpg', 'gif', 'jpeg'))) {
724 724
 				$size = @getimagesize($file);
725 725
 				if (is_array($size) && count($size)) {
726
-					$thumb_file = "$thumbDir/" . basename($file);
726
+					$thumb_file = "$thumbDir/".basename($file);
727 727
 					if (!is_file($thumb_file) || filemtime($file) > filemtime($thumb_file))
728 728
 						$this->makeThumb($file);
729 729
 					$smallThumb =
@@ -736,9 +736,9 @@  discard block
 block discarded – undo
736 736
 			if ($stat === false) continue;
737 737
 			$name = basename($file);
738 738
 			$types = $this->config['types'];
739
-			$types = explode(' ',$types['images'].' '.$types['image']);
740
-			if (substr($name,0,1) == '.' && !$this->config['showHiddenFiles']) continue;
741
-			if ($this->type == 'images' && !in_array(strtolower($ext),$types)) continue;
739
+			$types = explode(' ', $types['images'].' '.$types['image']);
740
+			if (substr($name, 0, 1) == '.' && !$this->config['showHiddenFiles']) continue;
741
+			if ($this->type == 'images' && !in_array(strtolower($ext), $types)) continue;
742 742
 			$bigIcon = file_exists("themes/{$this->config['theme']}/img/files/big/$ext.png");
743 743
 			$smallIcon = file_exists("themes/{$this->config['theme']}/img/files/small/$ext.png");
744 744
 			$thumb = file_exists("$thumbDir/$name");
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
 		return $return;
759 759
 	}
760 760
 
761
-    protected function getTree($dir, $index=0) {
761
+    protected function getTree($dir, $index = 0){
762 762
         $path = explode("/", $dir);
763 763
 
764 764
         $pdir = "";
@@ -793,25 +793,25 @@  discard block
 block discarded – undo
793 793
         return $dirs;
794 794
     }
795 795
 
796
-    protected function postDir($existent=true) {
796
+    protected function postDir($existent = true){
797 797
         $dir = $this->typeDir;
798 798
         if (isset($this->post['dir']))
799
-            $dir .= "/" . $this->post['dir'];
799
+            $dir .= "/".$this->post['dir'];
800 800
         if ($existent && (!is_dir($dir) || !is_readable($dir)))
801 801
             $this->errorMsg("Inexistant or inaccessible folder.");
802 802
         return $dir;
803 803
     }
804 804
 
805
-    protected function getDir($existent=true) {
805
+    protected function getDir($existent = true){
806 806
         $dir = $this->typeDir;
807 807
         if (isset($this->get['dir']))
808
-            $dir .= "/" . $this->get['dir'];
808
+            $dir .= "/".$this->get['dir'];
809 809
         if ($existent && (!is_dir($dir) || !is_readable($dir)))
810 810
             $this->errorMsg("Inexistant or inaccessible folder.");
811 811
         return $dir;
812 812
     }
813 813
 
814
-    protected function getDirs($dir) {
814
+    protected function getDirs($dir){
815 815
         $dirs = dir::content($dir, array('types' => "dir"));
816 816
         $return = array();
817 817
         if (is_array($dirs)) {
@@ -826,7 +826,7 @@  discard block
 block discarded – undo
826 826
         return $return;
827 827
     }
828 828
 
829
-    protected function getDirInfo($dir, $removable=false) {
829
+    protected function getDirInfo($dir, $removable = false){
830 830
         if ((substr(basename($dir), 0, 1) == ".") || !is_dir($dir) || !is_readable($dir))
831 831
             return false;
832 832
         $dirs = dir::content($dir, array('types' => "dir"));
@@ -853,7 +853,7 @@  discard block
 block discarded – undo
853 853
         return $info;
854 854
     }
855 855
 
856
-    protected function output($data=null, $template=null) {
856
+    protected function output($data = null, $template = null){
857 857
         if (!is_array($data)) $data = array();
858 858
         if ($template === null)
859 859
             $template = $this->action;
@@ -873,7 +873,7 @@  discard block
 block discarded – undo
873 873
         return "";
874 874
     }
875 875
 
876
-    protected function errorMsg($message, array $data=null) {
876
+    protected function errorMsg($message, array $data = null){
877 877
         if (in_array($this->action, array("thumb", "upload", "download", "downloadDir")))
878 878
             die($this->label($message, $data));
879 879
         if (($this->action === null) || ($this->action == "browser"))
Please login to merge, or discard this patch.
Braces   +413 added lines, -261 removed lines patch added patch discarded remove patch
@@ -12,23 +12,29 @@  discard block
 block discarded – undo
12 12
   *      @link http://kcfinder.sunhater.com
13 13
   */
14 14
 
15
-class browser extends uploader {
15
+class browser extends uploader
16
+{
16 17
     protected $action;
17 18
     protected $thumbsDir;
18 19
     protected $thumbsTypeDir;
19 20
 
20
-    public function __construct($modx) {
21
+    public function __construct($modx)
22
+    {
21 23
         parent::__construct($modx);
22 24
 
23 25
         if (isset($this->post['dir'])) {
24 26
             $dir = $this->checkInputDir($this->post['dir'], true, false);
25
-            if ($dir === false) unset($this->post['dir']);
27
+            if ($dir === false) {
28
+                unset($this->post['dir']);
29
+            }
26 30
             $this->post['dir'] = $dir;
27 31
         }
28 32
 
29 33
         if (isset($this->get['dir'])) {
30 34
             $dir = $this->checkInputDir($this->get['dir'], true, false);
31
-            if ($dir === false) unset($this->get['dir']);
35
+            if ($dir === false) {
36
+                unset($this->get['dir']);
37
+            }
32 38
             $this->get['dir'] = $dir;
33 39
         }
34 40
 
@@ -44,8 +50,9 @@  discard block
 block discarded – undo
44 50
                 !is_dir("$thumbsDir/{$this->type}") &&
45 51
                 !@mkdir("$thumbsDir/{$this->type}", $this->config['dirPerms'])
46 52
             )
47
-        )
48
-            $this->errorMsg("Cannot access or create thumbnails folder.");
53
+        ) {
54
+                    $this->errorMsg("Cannot access or create thumbnails folder.");
55
+        }
49 56
 
50 57
         $this->thumbsDir = $thumbsDir;
51 58
         $this->thumbsTypeDir = "$thumbsDir/{$this->type}";
@@ -58,23 +65,29 @@  discard block
 block discarded – undo
58 65
 
59 66
         if (is_array($files) && count($files)) {
60 67
             $time = time();
61
-            foreach ($files as $file)
62
-                if (is_file($file) && ($time - filemtime($file) > 3600))
68
+            foreach ($files as $file) {
69
+                            if (is_file($file) && ($time - filemtime($file) > 3600))
63 70
                     unlink($file);
71
+            }
64 72
         }
65 73
 
66 74
         if (isset($this->get['theme']) &&
67 75
             ($this->get['theme'] == basename($this->get['theme'])) &&
68 76
             is_dir("themes/{$this->get['theme']}")
69
-        )
70
-            $this->config['theme'] = $this->get['theme'];
77
+        ) {
78
+                    $this->config['theme'] = $this->get['theme'];
79
+        }
71 80
     }
72 81
 
73
-    public function action() {
82
+    public function action()
83
+    {
74 84
         $act = isset($this->get['act']) ? $this->get['act'] : "browser";
75
-        if(!preg_match('@^[0-9a-zA-Z_]+$@', $act)) $this->errorMsg("Unknown error.");
76
-        if (!method_exists($this, "act_$act"))
77
-            $act = "browser";
85
+        if(!preg_match('@^[0-9a-zA-Z_]+$@', $act)) {
86
+            $this->errorMsg("Unknown error.");
87
+        }
88
+        if (!method_exists($this, "act_$act")) {
89
+                    $act = "browser";
90
+        }
78 91
         $this->action = $act;
79 92
         $method = "act_$act";
80 93
 
@@ -82,21 +95,22 @@  discard block
 block discarded – undo
82 95
             $message = $this->label("You don't have permissions to browse server.");
83 96
             if (in_array($act, array("browser", "upload")) ||
84 97
                 (substr($act, 0, 8) == "download")
85
-            )
86
-                $this->backMsg($message);
87
-            else {
98
+            ) {
99
+                            $this->backMsg($message);
100
+            } else {
88 101
                 header("Content-Type: text/plain; charset={$this->charset}");
89 102
                 die(json_encode(array('error' => $message)));
90 103
             }
91 104
         }
92 105
 
93
-        if (!isset($this->session['dir']))
94
-            $this->session['dir'] = $this->type;
95
-        else {
106
+        if (!isset($this->session['dir'])) {
107
+                    $this->session['dir'] = $this->type;
108
+        } else {
96 109
             $type = $this->getTypeFromPath($this->session['dir']);
97 110
             $dir = $this->config['uploadDir'] . "/" . $this->session['dir'];
98
-            if (($type != $this->type) || !is_dir($dir) || !is_readable($dir))
99
-                $this->session['dir'] = $this->type;
111
+            if (($type != $this->type) || !is_dir($dir) || !is_readable($dir)) {
112
+                            $this->session['dir'] = $this->type;
113
+            }
100 114
         }
101 115
         $this->session['dir'] = path::normalize($this->session['dir']);
102 116
 
@@ -106,8 +120,9 @@  discard block
 block discarded – undo
106 120
         } elseif (
107 121
             (substr($act, 0, 8) != "download") &&
108 122
             !in_array($act, array("thumb", "upload"))
109
-        )
110
-            header("Content-Type: text/plain; charset={$this->charset}");
123
+        ) {
124
+                    header("Content-Type: text/plain; charset={$this->charset}");
125
+        }
111 126
 
112 127
         $return = $this->$method();
113 128
         echo ($return === true)
@@ -115,21 +130,25 @@  discard block
 block discarded – undo
115 130
             : $return;
116 131
     }
117 132
 
118
-    protected function act_browser() {
133
+    protected function act_browser()
134
+    {
119 135
         if (isset($this->get['dir']) &&
120 136
             is_dir("{$this->typeDir}/{$this->get['dir']}") &&
121 137
             is_readable("{$this->typeDir}/{$this->get['dir']}")
122
-        )
123
-            $this->session['dir'] = path::normalize("{$this->type}/{$this->get['dir']}");
138
+        ) {
139
+                    $this->session['dir'] = path::normalize("{$this->type}/{$this->get['dir']}");
140
+        }
124 141
 
125 142
         return $this->output();
126 143
     }
127 144
 
128
-    protected function act_init() {
145
+    protected function act_init()
146
+    {
129 147
         $tree = $this->getDirInfo($this->typeDir);
130 148
         $tree['dirs'] = $this->getTree($this->session['dir']);
131
-        if (!is_array($tree['dirs']) || !count($tree['dirs']))
132
-            unset($tree['dirs']);
149
+        if (!is_array($tree['dirs']) || !count($tree['dirs'])) {
150
+                    unset($tree['dirs']);
151
+        }
133 152
         $files = $this->getFiles($this->session['dir']);
134 153
         $dirWritable = dir::isWritable("{$this->config['uploadDir']}/{$this->session['dir']}");
135 154
         $data = array(
@@ -140,21 +159,26 @@  discard block
 block discarded – undo
140 159
         return json_encode($data);
141 160
     }
142 161
 
143
-    protected function act_thumb() {
162
+    protected function act_thumb()
163
+    {
144 164
         $this->getDir($this->get['dir'], true);
145
-        if (!isset($this->get['file']) || !isset($this->get['dir']))
146
-            $this->sendDefaultThumb();
165
+        if (!isset($this->get['file']) || !isset($this->get['dir'])) {
166
+                    $this->sendDefaultThumb();
167
+        }
147 168
         $file = $this->get['file'];
148
-        if (basename($file) != $file)
149
-            $this->sendDefaultThumb();
169
+        if (basename($file) != $file) {
170
+                    $this->sendDefaultThumb();
171
+        }
150 172
         $file = "{$this->thumbsDir}/{$this->type}/{$this->get['dir']}/$file";
151 173
         if (!is_file($file) || !is_readable($file)) {
152 174
             $file = "{$this->config['uploadDir']}/{$this->type}/{$this->get['dir']}/" . basename($file);
153
-            if (!is_file($file) || !is_readable($file))
154
-                $this->sendDefaultThumb($file);
175
+            if (!is_file($file) || !is_readable($file)) {
176
+                            $this->sendDefaultThumb($file);
177
+            }
155 178
             $image = image::factory($this->imageDriver, $file);
156
-            if ($image->initError)
157
-                $this->sendDefaultThumb($file);
179
+            if ($image->initError) {
180
+                            $this->sendDefaultThumb($file);
181
+            }
158 182
             list($tmp, $tmp, $type) = getimagesize($file);
159 183
             if (in_array($type, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG)) &&
160 184
                 ($image->width <= $this->config['thumbWidth']) &&
@@ -165,17 +189,20 @@  discard block
 block discarded – undo
165 189
                     ($type == IMAGETYPE_PNG) ? "png" : "jpeg");
166 190
                 $mime = "image/$mime";
167 191
                 httpCache::file($file, $mime);
168
-            } else
169
-                $this->sendDefaultThumb($file);
192
+            } else {
193
+                            $this->sendDefaultThumb($file);
194
+            }
170 195
         }
171 196
         httpCache::file($file, "image/jpeg");
172 197
     }
173 198
 
174
-    protected function act_expand() {
199
+    protected function act_expand()
200
+    {
175 201
         return json_encode(array('dirs' => $this->getDirs($this->postDir())));
176 202
     }
177 203
 
178
-    protected function act_chDir() {
204
+    protected function act_chDir()
205
+    {
179 206
         $this->postDir(); // Just for existing check
180 207
         $this->session['dir'] = $this->type . "/" . $this->post['dir'];
181 208
         $dirWritable = dir::isWritable("{$this->config['uploadDir']}/{$this->session['dir']}");
@@ -185,81 +212,104 @@  discard block
 block discarded – undo
185 212
         ));
186 213
     }
187 214
 
188
-    protected function act_newDir() {
215
+    protected function act_newDir()
216
+    {
189 217
         if (!$this->config['access']['dirs']['create'] ||
190 218
             !isset($this->post['dir']) ||
191 219
             !isset($this->post['newDir'])
192
-        )
193
-            $this->errorMsg("Unknown error.");
220
+        ) {
221
+                    $this->errorMsg("Unknown error.");
222
+        }
194 223
 
195 224
         $dir = $this->postDir();
196 225
         $newDir = $this->normalizeDirname(trim($this->post['newDir']));
197
-        if (!strlen($newDir))
198
-            $this->errorMsg("Please enter new folder name.");
199
-        if (preg_match('/[\/\\\\]/s', $newDir))
200
-            $this->errorMsg("Unallowable characters in folder name.");
201
-        if (substr($newDir, 0, 1) == ".")
202
-            $this->errorMsg("Folder name shouldn't begins with '.'");
203
-        if (file_exists("$dir/$newDir"))
204
-            $this->errorMsg("A file or folder with that name already exists.");
205
-        if (!@mkdir("$dir/$newDir", $this->config['dirPerms']))
206
-            $this->errorMsg("Cannot create {dir} folder.", array('dir' => $newDir));
226
+        if (!strlen($newDir)) {
227
+                    $this->errorMsg("Please enter new folder name.");
228
+        }
229
+        if (preg_match('/[\/\\\\]/s', $newDir)) {
230
+                    $this->errorMsg("Unallowable characters in folder name.");
231
+        }
232
+        if (substr($newDir, 0, 1) == ".") {
233
+                    $this->errorMsg("Folder name shouldn't begins with '.'");
234
+        }
235
+        if (file_exists("$dir/$newDir")) {
236
+                    $this->errorMsg("A file or folder with that name already exists.");
237
+        }
238
+        if (!@mkdir("$dir/$newDir", $this->config['dirPerms'])) {
239
+                    $this->errorMsg("Cannot create {dir} folder.", array('dir' => $newDir));
240
+        }
207 241
         return true;
208 242
     }
209 243
 
210
-    protected function act_renameDir() {
244
+    protected function act_renameDir()
245
+    {
211 246
         if (!$this->config['access']['dirs']['rename'] ||
212 247
             !isset($this->post['dir']) ||
213 248
             !isset($this->post['newName'])
214
-        )
215
-            $this->errorMsg("Unknown error.");
249
+        ) {
250
+                    $this->errorMsg("Unknown error.");
251
+        }
216 252
 
217 253
         $dir = $this->postDir();
218 254
         $newName = $this->normalizeDirname(trim($this->post['newName']));
219
-        if (!strlen($newName))
220
-            $this->errorMsg("Please enter new folder name.");
221
-        if (preg_match('/[\/\\\\]/s', $newName))
222
-            $this->errorMsg("Unallowable characters in folder name.");
223
-        if (substr($newName, 0, 1) == ".")
224
-            $this->errorMsg("Folder name shouldn't begins with '.'");
225
-        if (!@rename($dir, dirname($dir) . "/$newName"))
226
-            $this->errorMsg("Cannot rename the folder.");
255
+        if (!strlen($newName)) {
256
+                    $this->errorMsg("Please enter new folder name.");
257
+        }
258
+        if (preg_match('/[\/\\\\]/s', $newName)) {
259
+                    $this->errorMsg("Unallowable characters in folder name.");
260
+        }
261
+        if (substr($newName, 0, 1) == ".") {
262
+                    $this->errorMsg("Folder name shouldn't begins with '.'");
263
+        }
264
+        if (!@rename($dir, dirname($dir) . "/$newName")) {
265
+                    $this->errorMsg("Cannot rename the folder.");
266
+        }
227 267
         $thumbDir = "$this->thumbsTypeDir/{$this->post['dir']}";
228
-        if (is_dir($thumbDir))
229
-            @rename($thumbDir, dirname($thumbDir) . "/$newName");
268
+        if (is_dir($thumbDir)) {
269
+                    @rename($thumbDir, dirname($thumbDir) . "/$newName");
270
+        }
230 271
         return json_encode(array('name' => $newName));
231 272
     }
232 273
 
233
-    protected function act_deleteDir() {
274
+    protected function act_deleteDir()
275
+    {
234 276
         if (!$this->config['access']['dirs']['delete'] ||
235 277
             !isset($this->post['dir']) ||
236 278
             !strlen(trim($this->post['dir']))
237
-        )
238
-            $this->errorMsg("Unknown error.");
279
+        ) {
280
+                    $this->errorMsg("Unknown error.");
281
+        }
239 282
 
240 283
         $dir = $this->postDir();
241 284
 
242
-        if (!dir::isWritable($dir))
243
-            $this->errorMsg("Cannot delete the folder.");
285
+        if (!dir::isWritable($dir)) {
286
+                    $this->errorMsg("Cannot delete the folder.");
287
+        }
244 288
         $result = !dir::prune($dir, false);
245
-        if (is_array($result) && count($result))
246
-            $this->errorMsg("Failed to delete {count} files/folders.",
289
+        if (is_array($result) && count($result)) {
290
+                    $this->errorMsg("Failed to delete {count} files/folders.",
247 291
                 array('count' => count($result)));
292
+        }
248 293
         $thumbDir = "$this->thumbsTypeDir/{$this->post['dir']}";
249
-        if (is_dir($thumbDir)) dir::prune($thumbDir);
294
+        if (is_dir($thumbDir)) {
295
+            dir::prune($thumbDir);
296
+        }
250 297
         return true;
251 298
     }
252 299
 
253
-    protected function act_upload() {
300
+    protected function act_upload()
301
+    {
254 302
         if (!$this->config['access']['files']['upload'] ||
255 303
             !isset($this->post['dir'])
256
-        )
257
-            $this->errorMsg("Unknown error.");
304
+        ) {
305
+                    $this->errorMsg("Unknown error.");
306
+        }
258 307
 
259 308
         $dir = $this->postDir();
260 309
 
261
-        if (!dir::isWritable($dir))
262
-            $this->errorMsg("Cannot access or write to upload folder.");
310
+        if (!dir::isWritable($dir)) {
311
+                    $this->errorMsg("Cannot access or write to upload folder.");
312
+        }
263 313
 
264 314
         if (is_array($this->file['name'])) {
265 315
             $return = array();
@@ -271,19 +321,22 @@  discard block
 block discarded – undo
271 321
                 ), $dir);
272 322
             }
273 323
             return implode("\n", $return);
274
-        } else
275
-            return $this->moveUploadFile($this->file, $dir);
324
+        } else {
325
+                    return $this->moveUploadFile($this->file, $dir);
326
+        }
276 327
     }
277 328
 
278
-    protected function act_download() {
329
+    protected function act_download()
330
+    {
279 331
         $dir = $this->postDir();
280 332
         if (!isset($this->post['dir']) ||
281 333
             !isset($this->post['file']) ||
282 334
             strpos($this->post['file'],'../')!==false ||
283 335
             (false === ($file = "$dir/{$this->post['file']}")) ||
284 336
             !file_exists($file) || !is_readable($file)
285
-        )
286
-            $this->errorMsg("Unknown error.");
337
+        ) {
338
+                    $this->errorMsg("Unknown error.");
339
+        }
287 340
 
288 341
         header("Pragma: public");
289 342
         header("Expires: 0");
@@ -297,7 +350,8 @@  discard block
 block discarded – undo
297 350
         die;
298 351
     }
299 352
 
300
-    protected function act_rename() {
353
+    protected function act_rename()
354
+    {
301 355
         $dir = $this->postDir();
302 356
         if (!$this->config['access']['files']['rename'] ||
303 357
             !isset($this->post['dir']) ||
@@ -306,42 +360,52 @@  discard block
 block discarded – undo
306 360
             !isset($this->post['newName']) ||
307 361
             (false === ($file = "$dir/{$this->post['file']}")) ||
308 362
             !file_exists($file) || !is_readable($file) || !file::isWritable($file)
309
-        )
310
-            $this->errorMsg("Unknown error.");
363
+        ) {
364
+                    $this->errorMsg("Unknown error.");
365
+        }
311 366
 
312 367
         if (isset($this->config['denyExtensionRename']) &&
313 368
             $this->config['denyExtensionRename'] &&
314 369
             (file::getExtension($this->post['file'], true) !==
315 370
                 file::getExtension($this->post['newName'], true)
316 371
             )
317
-        )
318
-            $this->errorMsg("You cannot rename the extension of files!");
372
+        ) {
373
+                    $this->errorMsg("You cannot rename the extension of files!");
374
+        }
319 375
 
320 376
         $newName = $this->normalizeFilename(trim($this->post['newName']));
321
-        if (!strlen($newName))
322
-            $this->errorMsg("Please enter new file name.");
323
-        if (preg_match('/[\/\\\\]/s', $newName))
324
-            $this->errorMsg("Unallowable characters in file name.");
325
-        if (substr($newName, 0, 1) == ".")
326
-            $this->errorMsg("File name shouldn't begins with '.'");
377
+        if (!strlen($newName)) {
378
+                    $this->errorMsg("Please enter new file name.");
379
+        }
380
+        if (preg_match('/[\/\\\\]/s', $newName)) {
381
+                    $this->errorMsg("Unallowable characters in file name.");
382
+        }
383
+        if (substr($newName, 0, 1) == ".") {
384
+                    $this->errorMsg("File name shouldn't begins with '.'");
385
+        }
327 386
         $newName = "$dir/$newName";
328
-        if (file_exists($newName))
329
-            $this->errorMsg("A file or folder with that name already exists.");
387
+        if (file_exists($newName)) {
388
+                    $this->errorMsg("A file or folder with that name already exists.");
389
+        }
330 390
         $ext = file::getExtension($newName);
331
-        if (!$this->validateExtension($ext, $this->type))
332
-            $this->errorMsg("Denied file extension.");
333
-        if (!@rename($file, $newName))
334
-            $this->errorMsg("Unknown error.");
391
+        if (!$this->validateExtension($ext, $this->type)) {
392
+                    $this->errorMsg("Denied file extension.");
393
+        }
394
+        if (!@rename($file, $newName)) {
395
+                    $this->errorMsg("Unknown error.");
396
+        }
335 397
 
336 398
         $thumbDir = "{$this->thumbsTypeDir}/{$this->post['dir']}";
337 399
         $thumbFile = "$thumbDir/{$this->post['file']}";
338 400
 
339
-        if (file_exists($thumbFile))
340
-            @rename($thumbFile, "$thumbDir/" . basename($newName));
401
+        if (file_exists($thumbFile)) {
402
+                    @rename($thumbFile, "$thumbDir/" . basename($newName));
403
+        }
341 404
         return true;
342 405
     }
343 406
 
344
-    protected function act_delete() {
407
+    protected function act_delete()
408
+    {
345 409
         $dir = $this->postDir();
346 410
         if (!$this->config['access']['files']['delete'] ||
347 411
             !isset($this->post['dir']) ||
@@ -350,152 +414,184 @@  discard block
 block discarded – undo
350 414
             (false === ($file = "$dir/{$this->post['file']}")) ||
351 415
             !file_exists($file) || !is_readable($file) || !file::isWritable($file) ||
352 416
             !@unlink($file)
353
-        )
354
-            $this->errorMsg("Unknown error.");
417
+        ) {
418
+                    $this->errorMsg("Unknown error.");
419
+        }
355 420
 
356 421
         $thumb = "{$this->thumbsTypeDir}/{$this->post['dir']}/{$this->post['file']}";
357
-        if (file_exists($thumb)) @unlink($thumb);
422
+        if (file_exists($thumb)) {
423
+            @unlink($thumb);
424
+        }
358 425
         return true;
359 426
     }
360 427
 
361
-    protected function act_cp_cbd() {
428
+    protected function act_cp_cbd()
429
+    {
362 430
         $dir = $this->postDir();
363 431
         if (!$this->config['access']['files']['copy'] ||
364 432
             !isset($this->post['dir']) ||
365 433
             !is_dir($dir) || !is_readable($dir) || !dir::isWritable($dir) ||
366 434
             !isset($this->post['files']) || !is_array($this->post['files']) ||
367 435
             !count($this->post['files'])
368
-        )
369
-            $this->errorMsg("Unknown error.");
436
+        ) {
437
+                    $this->errorMsg("Unknown error.");
438
+        }
370 439
 
371 440
         $error = array();
372 441
         foreach($this->post['files'] as $file) {
373 442
             $file = path::normalize($file);
374
-            if (substr($file, 0, 1) == ".") continue;
443
+            if (substr($file, 0, 1) == ".") {
444
+                continue;
445
+            }
375 446
             $type = explode("/", $file);
376 447
             $type = $type[0];
377
-            if ($type != $this->type) continue;
448
+            if ($type != $this->type) {
449
+                continue;
450
+            }
378 451
             $path = "{$this->config['uploadDir']}/$file";
379 452
             $base = basename($file);
380 453
             $replace = array('file' => $base);
381 454
             $ext = file::getExtension($base);
382
-            if (!file_exists($path))
383
-                $error[] = $this->label("The file '{file}' does not exist.", $replace);
384
-            elseif (substr($base, 0, 1) == ".")
385
-                $error[] = "$base: " . $this->label("File name shouldn't begins with '.'");
386
-            elseif (!$this->validateExtension($ext, $type))
387
-                $error[] = "$base: " . $this->label("Denied file extension.");
388
-            elseif (file_exists("$dir/$base"))
389
-                $error[] = "$base: " . $this->label("A file or folder with that name already exists.");
390
-            elseif (!is_readable($path) || !is_file($path))
391
-                $error[] = $this->label("Cannot read '{file}'.", $replace);
392
-            elseif (!@copy($path, "$dir/$base"))
393
-                $error[] = $this->label("Cannot copy '{file}'.", $replace);
394
-            else {
395
-                if (function_exists("chmod"))
396
-                    @chmod("$dir/$base", $this->config['filePerms']);
455
+            if (!file_exists($path)) {
456
+                            $error[] = $this->label("The file '{file}' does not exist.", $replace);
457
+            } elseif (substr($base, 0, 1) == ".") {
458
+                            $error[] = "$base: " . $this->label("File name shouldn't begins with '.'");
459
+            } elseif (!$this->validateExtension($ext, $type)) {
460
+                            $error[] = "$base: " . $this->label("Denied file extension.");
461
+            } elseif (file_exists("$dir/$base")) {
462
+                            $error[] = "$base: " . $this->label("A file or folder with that name already exists.");
463
+            } elseif (!is_readable($path) || !is_file($path)) {
464
+                            $error[] = $this->label("Cannot read '{file}'.", $replace);
465
+            } elseif (!@copy($path, "$dir/$base")) {
466
+                            $error[] = $this->label("Cannot copy '{file}'.", $replace);
467
+            } else {
468
+                if (function_exists("chmod")) {
469
+                                    @chmod("$dir/$base", $this->config['filePerms']);
470
+                }
397 471
                 $fromThumb = "{$this->thumbsDir}/$file";
398 472
                 if (is_file($fromThumb) && is_readable($fromThumb)) {
399 473
                     $toThumb = "{$this->thumbsTypeDir}/{$this->post['dir']}";
400
-                    if (!is_dir($toThumb))
401
-                        @mkdir($toThumb, $this->config['dirPerms'], true);
474
+                    if (!is_dir($toThumb)) {
475
+                                            @mkdir($toThumb, $this->config['dirPerms'], true);
476
+                    }
402 477
                     $toThumb .= "/$base";
403 478
                     @copy($fromThumb, $toThumb);
404 479
                 }
405 480
             }
406 481
         }
407
-        if (count($error))
408
-            return json_encode(array('error' => $error));
482
+        if (count($error)) {
483
+                    return json_encode(array('error' => $error));
484
+        }
409 485
         return true;
410 486
     }
411 487
 
412
-    protected function act_mv_cbd() {
488
+    protected function act_mv_cbd()
489
+    {
413 490
         $dir = $this->postDir();
414 491
         if (!$this->config['access']['files']['move'] ||
415 492
             !isset($this->post['dir']) ||
416 493
             !is_dir($dir) || !is_readable($dir) || !dir::isWritable($dir) ||
417 494
             !isset($this->post['files']) || !is_array($this->post['files']) ||
418 495
             !count($this->post['files'])
419
-        )
420
-            $this->errorMsg("Unknown error.");
496
+        ) {
497
+                    $this->errorMsg("Unknown error.");
498
+        }
421 499
 
422 500
         $error = array();
423 501
         foreach($this->post['files'] as $file) {
424 502
             $file = path::normalize($file);
425
-            if (substr($file, 0, 1) == ".") continue;
503
+            if (substr($file, 0, 1) == ".") {
504
+                continue;
505
+            }
426 506
             $type = explode("/", $file);
427 507
             $type = $type[0];
428
-            if ($type != $this->type) continue;
508
+            if ($type != $this->type) {
509
+                continue;
510
+            }
429 511
             $path = "{$this->config['uploadDir']}/$file";
430 512
             $base = basename($file);
431 513
             $replace = array('file' => $base);
432 514
             $ext = file::getExtension($base);
433
-            if (!file_exists($path))
434
-                $error[] = $this->label("The file '{file}' does not exist.", $replace);
435
-            elseif (substr($base, 0, 1) == ".")
436
-                $error[] = "$base: " . $this->label("File name shouldn't begins with '.'");
437
-            elseif (!$this->validateExtension($ext, $type))
438
-                $error[] = "$base: " . $this->label("Denied file extension.");
439
-            elseif (file_exists("$dir/$base"))
440
-                $error[] = "$base: " . $this->label("A file or folder with that name already exists.");
441
-            elseif (!is_readable($path) || !is_file($path))
442
-                $error[] = $this->label("Cannot read '{file}'.", $replace);
443
-            elseif (!file::isWritable($path) || !@rename($path, "$dir/$base"))
444
-                $error[] = $this->label("Cannot move '{file}'.", $replace);
445
-            else {
446
-                if (function_exists("chmod"))
447
-                    @chmod("$dir/$base", $this->config['filePerms']);
515
+            if (!file_exists($path)) {
516
+                            $error[] = $this->label("The file '{file}' does not exist.", $replace);
517
+            } elseif (substr($base, 0, 1) == ".") {
518
+                            $error[] = "$base: " . $this->label("File name shouldn't begins with '.'");
519
+            } elseif (!$this->validateExtension($ext, $type)) {
520
+                            $error[] = "$base: " . $this->label("Denied file extension.");
521
+            } elseif (file_exists("$dir/$base")) {
522
+                            $error[] = "$base: " . $this->label("A file or folder with that name already exists.");
523
+            } elseif (!is_readable($path) || !is_file($path)) {
524
+                            $error[] = $this->label("Cannot read '{file}'.", $replace);
525
+            } elseif (!file::isWritable($path) || !@rename($path, "$dir/$base")) {
526
+                            $error[] = $this->label("Cannot move '{file}'.", $replace);
527
+            } else {
528
+                if (function_exists("chmod")) {
529
+                                    @chmod("$dir/$base", $this->config['filePerms']);
530
+                }
448 531
                 $fromThumb = "{$this->thumbsDir}/$file";
449 532
                 if (is_file($fromThumb) && is_readable($fromThumb)) {
450 533
                     $toThumb = "{$this->thumbsTypeDir}/{$this->post['dir']}";
451
-                    if (!is_dir($toThumb))
452
-                        @mkdir($toThumb, $this->config['dirPerms'], true);
534
+                    if (!is_dir($toThumb)) {
535
+                                            @mkdir($toThumb, $this->config['dirPerms'], true);
536
+                    }
453 537
                     $toThumb .= "/$base";
454 538
                     @rename($fromThumb, $toThumb);
455 539
                 }
456 540
             }
457 541
         }
458
-        if (count($error))
459
-            return json_encode(array('error' => $error));
542
+        if (count($error)) {
543
+                    return json_encode(array('error' => $error));
544
+        }
460 545
         return true;
461 546
     }
462 547
 
463
-    protected function act_rm_cbd() {
548
+    protected function act_rm_cbd()
549
+    {
464 550
         if (!$this->config['access']['files']['delete'] ||
465 551
             !isset($this->post['files']) ||
466 552
             !is_array($this->post['files']) ||
467 553
             !count($this->post['files'])
468
-        )
469
-            $this->errorMsg("Unknown error.");
554
+        ) {
555
+                    $this->errorMsg("Unknown error.");
556
+        }
470 557
 
471 558
         $error = array();
472 559
         foreach($this->post['files'] as $file) {
473 560
             $file = path::normalize($file);
474
-            if (substr($file, 0, 1) == ".") continue;
561
+            if (substr($file, 0, 1) == ".") {
562
+                continue;
563
+            }
475 564
             $type = explode("/", $file);
476 565
             $type = $type[0];
477
-            if ($type != $this->type) continue;
566
+            if ($type != $this->type) {
567
+                continue;
568
+            }
478 569
             $path = "{$this->config['uploadDir']}/$file";
479 570
             $base = basename($file);
480 571
             $replace = array('file' => $base);
481
-            if (!is_file($path))
482
-                $error[] = $this->label("The file '{file}' does not exist.", $replace);
483
-            elseif (!@unlink($path))
484
-                $error[] = $this->label("Cannot delete '{file}'.", $replace);
485
-            else {
572
+            if (!is_file($path)) {
573
+                            $error[] = $this->label("The file '{file}' does not exist.", $replace);
574
+            } elseif (!@unlink($path)) {
575
+                            $error[] = $this->label("Cannot delete '{file}'.", $replace);
576
+            } else {
486 577
                 $thumb = "{$this->thumbsDir}/$file";
487
-                if (is_file($thumb)) @unlink($thumb);
578
+                if (is_file($thumb)) {
579
+                    @unlink($thumb);
580
+                }
488 581
             }
489 582
         }
490
-        if (count($error))
491
-            return json_encode(array('error' => $error));
583
+        if (count($error)) {
584
+                    return json_encode(array('error' => $error));
585
+        }
492 586
         return true;
493 587
     }
494 588
 
495
-    protected function act_downloadDir() {
589
+    protected function act_downloadDir()
590
+    {
496 591
         $dir = $this->postDir();
497
-        if (!isset($this->post['dir']) || $this->config['denyZipDownload'])
498
-            $this->errorMsg("Unknown error.");
592
+        if (!isset($this->post['dir']) || $this->config['denyZipDownload']) {
593
+                    $this->errorMsg("Unknown error.");
594
+        }
499 595
         $filename = basename($dir) . ".zip";
500 596
         do {
501 597
             $file = md5(time() . session_id());
@@ -510,23 +606,27 @@  discard block
 block discarded – undo
510 606
         die;
511 607
     }
512 608
 
513
-    protected function act_downloadSelected() {
609
+    protected function act_downloadSelected()
610
+    {
514 611
         $dir = $this->postDir();
515 612
         if (!isset($this->post['dir']) ||
516 613
             !isset($this->post['files']) ||
517 614
             !is_array($this->post['files']) ||
518 615
             $this->config['denyZipDownload']
519
-        )
520
-            $this->errorMsg("Unknown error.");
616
+        ) {
617
+                    $this->errorMsg("Unknown error.");
618
+        }
521 619
 
522 620
         $zipFiles = array();
523 621
         foreach ($this->post['files'] as $file) {
524 622
             $file = path::normalize($file);
525
-            if ((substr($file, 0, 1) == ".") || (strpos($file, '/') !== false))
526
-                continue;
623
+            if ((substr($file, 0, 1) == ".") || (strpos($file, '/') !== false)) {
624
+                            continue;
625
+            }
527 626
             $file = "$dir/$file";
528
-            if (!is_file($file) || !is_readable($file))
529
-                continue;
627
+            if (!is_file($file) || !is_readable($file)) {
628
+                            continue;
629
+            }
530 630
             $zipFiles[] = $file;
531 631
         }
532 632
 
@@ -538,8 +638,9 @@  discard block
 block discarded – undo
538 638
         $zip = new ZipArchive();
539 639
         $res = $zip->open($file, ZipArchive::CREATE);
540 640
         if ($res === TRUE) {
541
-            foreach ($zipFiles as $cfile)
542
-                $zip->addFile($cfile, basename($cfile));
641
+            foreach ($zipFiles as $cfile) {
642
+                            $zip->addFile($cfile, basename($cfile));
643
+            }
543 644
             $zip->close();
544 645
         }
545 646
         header("Content-Type: application/x-zip");
@@ -550,25 +651,30 @@  discard block
 block discarded – undo
550 651
         die;
551 652
     }
552 653
 
553
-    protected function act_downloadClipboard() {
654
+    protected function act_downloadClipboard()
655
+    {
554 656
         if (!isset($this->post['files']) ||
555 657
             !is_array($this->post['files']) ||
556 658
             $this->config['denyZipDownload']
557
-        )
558
-            $this->errorMsg("Unknown error.");
659
+        ) {
660
+                    $this->errorMsg("Unknown error.");
661
+        }
559 662
 
560 663
         $zipFiles = array();
561 664
         foreach ($this->post['files'] as $file) {
562 665
             $file = path::normalize($file);
563
-            if ((substr($file, 0, 1) == "."))
564
-                continue;
666
+            if ((substr($file, 0, 1) == ".")) {
667
+                            continue;
668
+            }
565 669
             $type = explode("/", $file);
566 670
             $type = $type[0];
567
-            if ($type != $this->type)
568
-                continue;
671
+            if ($type != $this->type) {
672
+                            continue;
673
+            }
569 674
             $file = $this->config['uploadDir'] . "/$file";
570
-            if (!is_file($file) || !is_readable($file))
571
-                continue;
675
+            if (!is_file($file) || !is_readable($file)) {
676
+                            continue;
677
+            }
572 678
             $zipFiles[] = $file;
573 679
         }
574 680
 
@@ -580,8 +686,9 @@  discard block
 block discarded – undo
580 686
         $zip = new ZipArchive();
581 687
         $res = $zip->open($file, ZipArchive::CREATE);
582 688
         if ($res === TRUE) {
583
-            foreach ($zipFiles as $cfile)
584
-                $zip->addFile($cfile, basename($cfile));
689
+            foreach ($zipFiles as $cfile) {
690
+                            $zip->addFile($cfile, basename($cfile));
691
+            }
585 692
             $zip->close();
586 693
         }
587 694
         header("Content-Type: application/x-zip");
@@ -592,16 +699,19 @@  discard block
 block discarded – undo
592 699
         die;
593 700
     }
594 701
 
595
-    protected function act_check4Update() {
596
-        if ($this->config['denyUpdateCheck'])
597
-            return json_encode(array('version' => false));
702
+    protected function act_check4Update()
703
+    {
704
+        if ($this->config['denyUpdateCheck']) {
705
+                    return json_encode(array('version' => false));
706
+        }
598 707
 
599 708
         // Caching HTTP request for 6 hours
600 709
         if (isset($this->session['checkVersion']) &&
601 710
             isset($this->session['checkVersionTime']) &&
602 711
             ((time() - $this->session['checkVersionTime']) < 21600)
603
-        )
604
-            return json_encode(array('version' => $this->session['checkVersion']));
712
+        ) {
713
+                    return json_encode(array('version' => $this->session['checkVersion']));
714
+        }
605 715
 
606 716
         $protocol = "http";
607 717
         $host = "kcfinder.sunhater.com";
@@ -651,27 +761,32 @@  discard block
 block discarded – undo
651 761
                 (false !==    @socket_write($socket, $cmd, strlen($cmd))                ) &&
652 762
                 (false !== (  $ver = @socket_read($socket, 2048)                       )) &&
653 763
                 preg_match($responsePattern, $ver, $match)
654
-            )
655
-                $ver = $match[2];
764
+            ) {
765
+                            $ver = $match[2];
766
+            }
656 767
 
657
-            if (isset($socket) && is_resource($socket))
658
-                @socket_close($socket);
768
+            if (isset($socket) && is_resource($socket)) {
769
+                            @socket_close($socket);
770
+            }
659 771
         }
660 772
 
661 773
         if (isset($ver) && preg_match($pattern, $ver)) {
662 774
             $this->session['checkVersion'] = $ver;
663 775
             $this->session['checkVersionTime'] = time();
664 776
             return json_encode(array('version' => $ver));
665
-        } else
666
-            return json_encode(array('version' => false));
777
+        } else {
778
+                    return json_encode(array('version' => false));
779
+        }
667 780
     }
668 781
 
669
-    protected function moveUploadFile($file, $dir) {
782
+    protected function moveUploadFile($file, $dir)
783
+    {
670 784
         $message = $this->checkUploadedFile($file);
671 785
 
672 786
         if ($message !== true) {
673
-            if (isset($file['tmp_name']))
674
-                @unlink($file['tmp_name']);
787
+            if (isset($file['tmp_name'])) {
788
+                            @unlink($file['tmp_name']);
789
+            }
675 790
             return "{$file['name']}: $message";
676 791
         }
677 792
 
@@ -684,8 +799,9 @@  discard block
 block discarded – undo
684 799
         ) {
685 800
             @unlink($file['tmp_name']);
686 801
             return "{$file['name']}: " . $this->label("Cannot move uploaded file to target folder.");
687
-        } elseif (function_exists('chmod'))
688
-            chmod($target, $this->config['filePerms']);
802
+        } elseif (function_exists('chmod')) {
803
+                    chmod($target, $this->config['filePerms']);
804
+        }
689 805
         
690 806
         $this->modx->invokeEvent('OnFileBrowserUpload',array(
691 807
             'filepath'=>realpath($dir),
@@ -697,25 +813,29 @@  discard block
 block discarded – undo
697 813
         return "/" . basename($target);
698 814
     }
699 815
 
700
-    protected function sendDefaultThumb($file=null) {
816
+    protected function sendDefaultThumb($file=null)
817
+    {
701 818
         if ($file !== null) {
702 819
             $ext = file::getExtension($file);
703 820
             $thumb = "themes/{$this->config['theme']}/img/files/big/$ext.png";
704 821
         }
705
-        if (!isset($thumb) || !file_exists($thumb))
706
-            $thumb = "themes/{$this->config['theme']}/img/files/big/..png";
822
+        if (!isset($thumb) || !file_exists($thumb)) {
823
+                    $thumb = "themes/{$this->config['theme']}/img/files/big/..png";
824
+        }
707 825
         header("Content-Type: image/png");
708 826
         readfile($thumb);
709 827
         die;
710 828
     }
711 829
 
712
-	protected function getFiles($dir) {
830
+	protected function getFiles($dir)
831
+	{
713 832
 		$thumbDir = "{$this->config['uploadDir']}/{$this->config['thumbsDir']}/$dir";
714 833
 		$dir = "{$this->config['uploadDir']}/$dir";
715 834
 		$return = array();
716 835
 		$files = dir::content($dir, array('types' => "file"));
717
-		if ($files === false)
718
-			return $return;
836
+		if ($files === false) {
837
+					return $return;
838
+		}
719 839
 
720 840
 		foreach ($files as $file) {
721 841
 			$ext = file::getExtension($file);
@@ -724,8 +844,9 @@  discard block
 block discarded – undo
724 844
 				$size = @getimagesize($file);
725 845
 				if (is_array($size) && count($size)) {
726 846
 					$thumb_file = "$thumbDir/" . basename($file);
727
-					if (!is_file($thumb_file) || filemtime($file) > filemtime($thumb_file))
728
-						$this->makeThumb($file);
847
+					if (!is_file($thumb_file) || filemtime($file) > filemtime($thumb_file)) {
848
+											$this->makeThumb($file);
849
+					}
729 850
 					$smallThumb =
730 851
 						($size[0] <= $this->config['thumbWidth']) &&
731 852
 						($size[1] <= $this->config['thumbHeight']) &&
@@ -733,12 +854,18 @@  discard block
 block discarded – undo
733 854
 				}
734 855
 			}
735 856
 			$stat = stat($file);
736
-			if ($stat === false) continue;
857
+			if ($stat === false) {
858
+			    continue;
859
+			}
737 860
 			$name = basename($file);
738 861
 			$types = $this->config['types'];
739 862
 			$types = explode(' ',$types['images'].' '.$types['image']);
740
-			if (substr($name,0,1) == '.' && !$this->config['showHiddenFiles']) continue;
741
-			if ($this->type == 'images' && !in_array(strtolower($ext),$types)) continue;
863
+			if (substr($name,0,1) == '.' && !$this->config['showHiddenFiles']) {
864
+			    continue;
865
+			}
866
+			if ($this->type == 'images' && !in_array(strtolower($ext),$types)) {
867
+			    continue;
868
+			}
742 869
 			$bigIcon = file_exists("themes/{$this->config['theme']}/img/files/big/$ext.png");
743 870
 			$smallIcon = file_exists("themes/{$this->config['theme']}/img/files/small/$ext.png");
744 871
 			$thumb = file_exists("$thumbDir/$name");
@@ -758,14 +885,17 @@  discard block
 block discarded – undo
758 885
 		return $return;
759 886
 	}
760 887
 
761
-    protected function getTree($dir, $index=0) {
888
+    protected function getTree($dir, $index=0)
889
+    {
762 890
         $path = explode("/", $dir);
763 891
 
764 892
         $pdir = "";
765
-        for ($i = 0; ($i <= $index && $i < count($path)); $i++)
766
-            $pdir .= "/{$path[$i]}";
767
-        if (strlen($pdir))
768
-            $pdir = substr($pdir, 1);
893
+        for ($i = 0; ($i <= $index && $i < count($path)); $i++) {
894
+                    $pdir .= "/{$path[$i]}";
895
+        }
896
+        if (strlen($pdir)) {
897
+                    $pdir = substr($pdir, 1);
898
+        }
769 899
 
770 900
         $fdir = "{$this->config['uploadDir']}/$pdir";
771 901
 
@@ -787,38 +917,48 @@  discard block
 block discarded – undo
787 917
                     }
788 918
                 }
789 919
             }
790
-        } else
791
-            return false;
920
+        } else {
921
+                    return false;
922
+        }
792 923
 
793 924
         return $dirs;
794 925
     }
795 926
 
796
-    protected function postDir($existent=true) {
927
+    protected function postDir($existent=true)
928
+    {
797 929
         $dir = $this->typeDir;
798
-        if (isset($this->post['dir']))
799
-            $dir .= "/" . $this->post['dir'];
800
-        if ($existent && (!is_dir($dir) || !is_readable($dir)))
801
-            $this->errorMsg("Inexistant or inaccessible folder.");
930
+        if (isset($this->post['dir'])) {
931
+                    $dir .= "/" . $this->post['dir'];
932
+        }
933
+        if ($existent && (!is_dir($dir) || !is_readable($dir))) {
934
+                    $this->errorMsg("Inexistant or inaccessible folder.");
935
+        }
802 936
         return $dir;
803 937
     }
804 938
 
805
-    protected function getDir($existent=true) {
939
+    protected function getDir($existent=true)
940
+    {
806 941
         $dir = $this->typeDir;
807
-        if (isset($this->get['dir']))
808
-            $dir .= "/" . $this->get['dir'];
809
-        if ($existent && (!is_dir($dir) || !is_readable($dir)))
810
-            $this->errorMsg("Inexistant or inaccessible folder.");
942
+        if (isset($this->get['dir'])) {
943
+                    $dir .= "/" . $this->get['dir'];
944
+        }
945
+        if ($existent && (!is_dir($dir) || !is_readable($dir))) {
946
+                    $this->errorMsg("Inexistant or inaccessible folder.");
947
+        }
811 948
         return $dir;
812 949
     }
813 950
 
814
-    protected function getDirs($dir) {
951
+    protected function getDirs($dir)
952
+    {
815 953
         $dirs = dir::content($dir, array('types' => "dir"));
816 954
         $return = array();
817 955
         if (is_array($dirs)) {
818 956
             $writable = dir::isWritable($dir);
819 957
             foreach ($dirs as $cdir) {
820 958
                 $info = $this->getDirInfo($cdir);
821
-                if ($info === false) continue;
959
+                if ($info === false) {
960
+                    continue;
961
+                }
822 962
                 $info['removable'] = $writable && $info['writable'];
823 963
                 $return[] = $info;
824 964
             }
@@ -826,17 +966,21 @@  discard block
 block discarded – undo
826 966
         return $return;
827 967
     }
828 968
 
829
-    protected function getDirInfo($dir, $removable=false) {
830
-        if ((substr(basename($dir), 0, 1) == ".") || !is_dir($dir) || !is_readable($dir))
831
-            return false;
969
+    protected function getDirInfo($dir, $removable=false)
970
+    {
971
+        if ((substr(basename($dir), 0, 1) == ".") || !is_dir($dir) || !is_readable($dir)) {
972
+                    return false;
973
+        }
832 974
         $dirs = dir::content($dir, array('types' => "dir"));
833 975
         if (is_array($dirs)) {
834
-            foreach ($dirs as $key => $cdir)
835
-                if (substr(basename($cdir), 0, 1) == ".")
976
+            foreach ($dirs as $key => $cdir) {
977
+                            if (substr(basename($cdir), 0, 1) == ".")
836 978
                     unset($dirs[$key]);
979
+            }
837 980
             $hasDirs = count($dirs) ? true : false;
838
-        } else
839
-            $hasDirs = false;
981
+        } else {
982
+                    $hasDirs = false;
983
+        }
840 984
 
841 985
         $writable = dir::isWritable($dir);
842 986
         $info = array(
@@ -847,24 +991,30 @@  discard block
 block discarded – undo
847 991
             'hasDirs' => $hasDirs
848 992
         );
849 993
 
850
-        if ($dir == "{$this->config['uploadDir']}/{$this->session['dir']}")
851
-            $info['current'] = true;
994
+        if ($dir == "{$this->config['uploadDir']}/{$this->session['dir']}") {
995
+                    $info['current'] = true;
996
+        }
852 997
 
853 998
         return $info;
854 999
     }
855 1000
 
856
-    protected function output($data=null, $template=null) {
857
-        if (!is_array($data)) $data = array();
858
-        if ($template === null)
859
-            $template = $this->action;
1001
+    protected function output($data=null, $template=null)
1002
+    {
1003
+        if (!is_array($data)) {
1004
+            $data = array();
1005
+        }
1006
+        if ($template === null) {
1007
+                    $template = $this->action;
1008
+        }
860 1009
 
861 1010
         if (file_exists("tpl/tpl_$template.php")) {
862 1011
             ob_start();
863 1012
             $eval = "unset(\$data);unset(\$template);unset(\$eval);";
864 1013
             $_ = $data;
865
-            foreach (array_keys($data) as $key)
866
-                if (preg_match('/^[a-z\d_]+$/i', $key))
1014
+            foreach (array_keys($data) as $key) {
1015
+                            if (preg_match('/^[a-z\d_]+$/i', $key))
867 1016
                     $eval .= "\$$key=\$_['$key'];";
1017
+            }
868 1018
             $eval .= "unset(\$_);require \"tpl/tpl_$template.php\";";
869 1019
             eval($eval);
870 1020
             return ob_get_clean();
@@ -873,12 +1023,14 @@  discard block
 block discarded – undo
873 1023
         return "";
874 1024
     }
875 1025
 
876
-    protected function errorMsg($message, array $data=null) {
877
-        if (in_array($this->action, array("thumb", "upload", "download", "downloadDir")))
878
-            die($this->label($message, $data));
879
-        if (($this->action === null) || ($this->action == "browser"))
880
-            $this->backMsg($message, $data);
881
-        else {
1026
+    protected function errorMsg($message, array $data=null)
1027
+    {
1028
+        if (in_array($this->action, array("thumb", "upload", "download", "downloadDir"))) {
1029
+                    die($this->label($message, $data));
1030
+        }
1031
+        if (($this->action === null) || ($this->action == "browser")) {
1032
+                    $this->backMsg($message, $data);
1033
+        } else {
882 1034
             $message = $this->label($message, $data);
883 1035
             die(json_encode(array('error' => $message)));
884 1036
         }
Please login to merge, or discard this patch.
Upper-Lower-Casing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -537,7 +537,7 @@  discard block
 block discarded – undo
537 537
 
538 538
         $zip = new ZipArchive();
539 539
         $res = $zip->open($file, ZipArchive::CREATE);
540
-        if ($res === TRUE) {
540
+        if ($res === true) {
541 541
             foreach ($zipFiles as $cfile)
542 542
                 $zip->addFile($cfile, basename($cfile));
543 543
             $zip->close();
@@ -579,7 +579,7 @@  discard block
 block discarded – undo
579 579
 
580 580
         $zip = new ZipArchive();
581 581
         $res = $zip->open($file, ZipArchive::CREATE);
582
-        if ($res === TRUE) {
582
+        if ($res === true) {
583 583
             foreach ($zipFiles as $cfile)
584 584
                 $zip->addFile($cfile, basename($cfile));
585 585
             $zip->close();
@@ -642,7 +642,7 @@  discard block
 block discarded – undo
642 642
         // Socket extension
643 643
         ) {} elseif (function_exists('socket_create')) {
644 644
             $cmd =
645
-                "GET $path " . strtoupper($protocol) . "/1.1\r\n" .
645
+                "get $path " . strtoupper($protocol) . "/1.1\r\n" .
646 646
                 "Host: $host\r\n" .
647 647
                 "Connection: Close\r\n\r\n";
648 648
 
Please login to merge, or discard this patch.
manager/media/browser/mcpuk/core/uploader.php 5 patches
Doc Comments   +18 added lines patch added patch discarded remove patch
@@ -385,6 +385,9 @@  discard block
 block discarded – undo
385 385
 	}
386 386
 
387 387
 
388
+	/**
389
+	 * @return string
390
+	 */
388 391
 	protected function normalizeFilename($filename) {
389 392
 		if ($this->getTransaliasSettings()) {
390 393
         		$format = strrchr($filename, ".");
@@ -394,6 +397,9 @@  discard block
 block discarded – undo
394 397
         	return $filename;
395 398
 	}
396 399
 
400
+	/**
401
+	 * @param string $dirname
402
+	 */
397 403
 	protected function normalizeDirname($dirname) {
398 404
         return $this->modx->stripAlias($dirname);
399 405
     }
@@ -506,6 +512,9 @@  discard block
 block discarded – undo
506 512
         return (is_dir($path) && is_readable($path)) ? $return : false;
507 513
     }
508 514
 
515
+    /**
516
+     * @param string $ext
517
+     */
509 518
     protected function validateExtension($ext, $type) {
510 519
         $ext = trim(strtolower($ext));
511 520
         if (!isset($this->types[$type]))
@@ -531,11 +540,17 @@  discard block
 block discarded – undo
531 540
         return in_array($ext, $exts);
532 541
     }
533 542
 
543
+    /**
544
+     * @return string
545
+     */
534 546
     protected function getTypeFromPath($path) {
535 547
         return preg_match('/^([^\/]*)\/.*$/', $path, $patt)
536 548
             ? $patt[1] : $path;
537 549
     }
538 550
 
551
+    /**
552
+     * @param string $path
553
+     */
539 554
     protected function removeTypeFromPath($path) {
540 555
         return preg_match('/^[^\/]*\/(.*)$/', $path, $patt)
541 556
             ? $patt[1] : "";
@@ -728,6 +743,9 @@  discard block
 block discarded – undo
728 743
         die;
729 744
     }
730 745
 
746
+    /**
747
+     * @param string $url
748
+     */
731 749
     protected function callBack($url, $message="") {
732 750
         $message = text::jsValue($message);
733 751
         $CKfuncNum = isset($this->opener['CKEditor']['funcNum'])
Please login to merge, or discard this patch.
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 /** This file is part of KCFinder project
4
-  *
5
-  *      @desc Uploader class
6
-  *   @package KCFinder
7
-  *   @version 2.54
8
-  *    @author Pavel Tzonkov <[email protected]>
9
-  * @copyright 2010-2014 KCFinder Project
10
-  *   @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2
11
-  *   @license http://www.opensource.org/licenses/lgpl-2.1.php LGPLv2
12
-  *      @link http://kcfinder.sunhater.com
13
-  */
4
+ *
5
+ *      @desc Uploader class
6
+ *   @package KCFinder
7
+ *   @version 2.54
8
+ *    @author Pavel Tzonkov <[email protected]>
9
+ * @copyright 2010-2014 KCFinder Project
10
+ *   @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2
11
+ *   @license http://www.opensource.org/licenses/lgpl-2.1.php LGPLv2
12
+ *      @link http://kcfinder.sunhater.com
13
+ */
14 14
 
15 15
 class uploader {
16 16
 
@@ -18,92 +18,92 @@  discard block
 block discarded – undo
18 18
     const VERSION = "2.54";
19 19
 
20 20
 /** Config session-overrided settings
21
-  * @var array */
21
+ * @var array */
22 22
     protected $config = array();
23 23
 
24 24
 /** Default image driver
25
-  * @var string */
25
+ * @var string */
26 26
     protected $imageDriver = "gd";
27 27
 
28 28
 /** Opener applocation properties
29
-  *   $opener['name']                 Got from $_GET['opener'];
30
-  *   $opener['CKEditor']['funcNum']  CKEditor function number (got from $_GET)
31
-  *   $opener['TinyMCE']              Boolean
32
-  * @var array */
29
+ *   $opener['name']                 Got from $_GET['opener'];
30
+ *   $opener['CKEditor']['funcNum']  CKEditor function number (got from $_GET)
31
+ *   $opener['TinyMCE']              Boolean
32
+ * @var array */
33 33
     protected $opener = array();
34 34
 
35 35
 /** Got from $_GET['type'] or first one $config['types'] array key, if inexistant
36
-  * @var string */
36
+ * @var string */
37 37
     protected $type;
38 38
 
39 39
 /** Helper property. Local filesystem path to the Type Directory
40
-  * Equivalent: $config['uploadDir'] . "/" . $type
41
-  * @var string */
40
+ * Equivalent: $config['uploadDir'] . "/" . $type
41
+ * @var string */
42 42
     protected $typeDir;
43 43
 
44 44
 /** Helper property. Web URL to the Type Directory
45
-  * Equivalent: $config['uploadURL'] . "/" . $type
46
-  * @var string */
45
+ * Equivalent: $config['uploadURL'] . "/" . $type
46
+ * @var string */
47 47
     protected $typeURL;
48 48
 
49 49
 /** Linked to $config['types']
50
-  * @var array */
50
+ * @var array */
51 51
     protected $types = array();
52 52
 
53 53
 /** Settings which can override default settings if exists as keys in $config['types'][$type] array
54
-  * @var array */
54
+ * @var array */
55 55
     protected $typeSettings = array('disabled', 'theme', 'dirPerms', 'filePerms', 'denyZipDownload', 'maxImageWidth', 'maxImageHeight', 'thumbWidth', 'thumbHeight', 'jpegQuality', 'access', 'filenameChangeChars', 'dirnameChangeChars', 'denyExtensionRename', 'deniedExts', 'watermark');
56 56
 
57 57
 /** Got from language file
58
-  * @var string */
58
+ * @var string */
59 59
     protected $charset;
60 60
 
61 61
 /** The language got from $_GET['lng'] or $_GET['lang'] or... Please see next property
62
-  * @var string */
62
+ * @var string */
63 63
     protected $lang = 'en';
64 64
 
65 65
 /** Possible language $_GET keys
66
-  * @var array */
66
+ * @var array */
67 67
     protected $langInputNames = array('lang', 'langCode', 'lng', 'language', 'lang_code');
68 68
 
69 69
 /** Uploaded file(s) info. Linked to first $_FILES element
70
-  * @var array */
70
+ * @var array */
71 71
     protected $file;
72 72
 
73 73
 /** Next three properties are got from the current language file
74
-  * @var string */
74
+ * @var string */
75 75
     protected $dateTimeFull;   // Currently not used
76 76
     protected $dateTimeMid;    // Currently not used
77 77
     protected $dateTimeSmall;
78 78
 
79 79
 /** Contain Specified language labels
80
-  * @var array */
80
+ * @var array */
81 81
     protected $labels = array();
82 82
 
83 83
 /** Contain unprocessed $_GET array. Please use this instead of $_GET
84
-  * @var array */
84
+ * @var array */
85 85
     protected $get;
86 86
 
87 87
 /** Contain unprocessed $_POST array. Please use this instead of $_POST
88
-  * @var array */
88
+ * @var array */
89 89
     protected $post;
90 90
 
91 91
 /** Contain unprocessed $_COOKIE array. Please use this instead of $_COOKIE
92
-  * @var array */
92
+ * @var array */
93 93
     protected $cookie;
94 94
 
95 95
 /** Session array. Please use this property instead of $_SESSION
96
-  * @var array */
96
+ * @var array */
97 97
     protected $session;
98 98
 
99 99
 /** CMS integration attribute (got from $_GET['cms'])
100
-  * @var string */
100
+ * @var string */
101 101
     protected $cms = "";
102 102
 
103 103
     protected $modx = null;
104 104
 /** Magic method which allows read-only access to protected or private class properties
105
-  * @param string $property
106
-  * @return mixed */
105
+     * @param string $property
106
+     * @return mixed */
107 107
     public function __get($property) {
108 108
         return property_exists($this, $property) ? $this->$property : null;
109 109
     }
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
         )
133 133
             $this->cms = $this->get['cms'];
134 134
 
135
-		// LINKING UPLOADED FILE
135
+        // LINKING UPLOADED FILE
136 136
         if (count($_FILES))
137 137
             $this->file = &$_FILES[key($_FILES)];
138 138
 
@@ -228,8 +228,8 @@  discard block
 block discarded – undo
228 228
             $this->config['uploadDir'] = strlen($this->config['uploadDir'])
229 229
                 ? path::normalize($this->config['uploadDir'])
230 230
                 : path::url2fullPath("/$path");
231
-         $this->typeDir = "{$this->config['uploadDir']}/{$this->type}";
232
-         $this->typeURL = "{$this->config['siteURL']}/{$this->config['uploadURL']}/{$this->type}";
231
+            $this->typeDir = "{$this->config['uploadDir']}/{$this->type}";
232
+            $this->typeURL = "{$this->config['siteURL']}/{$this->config['uploadURL']}/{$this->type}";
233 233
 
234 234
         // SITE ROOT
235 235
         } elseif ($this->config['uploadURL'] == "/") {
@@ -365,36 +365,36 @@  discard block
 block discarded – undo
365 365
     }
366 366
 
367 367
 
368
-	protected function getTransaliasSettings() {
369
-		global $modx;
370
-
371
-		// Cleaning uploaded filename?
372
-		$setting = $modx->db->select('count(*)', $modx->getFullTableName('system_settings'), 'setting_name="clean_uploaded_filename" AND setting_value=1');
373
-		if ($modx->db->getValue($setting)>0) {
374
-			// Transalias plugin active?
375
-			$res = $modx->db->select('properties', $modx->getFullTableName('site_plugins'), 'name="TransAlias" AND disabled=0');
376
-			if ($properties = $modx->db->getValue($res)) {
377
-				$properties = $modx->parseProperties($properties, 'TransAlias', 'plugin');
378
-			} else {
379
-				$properties = NULL;
380
-			}
381
-		} else {
382
-			$properties = NULL;
383
-		}
384
-		return $properties;
385
-	}
386
-
387
-
388
-	protected function normalizeFilename($filename) {
389
-		if ($this->getTransaliasSettings()) {
390
-        		$format = strrchr($filename, ".");
391
-        		$filename = str_replace($format, "", $filename);
392
-            		$filename = $this->modx->stripAlias($filename).$format;
393
-        	}
394
-        	return $filename;
395
-	}
396
-
397
-	protected function normalizeDirname($dirname) {
368
+    protected function getTransaliasSettings() {
369
+        global $modx;
370
+
371
+        // Cleaning uploaded filename?
372
+        $setting = $modx->db->select('count(*)', $modx->getFullTableName('system_settings'), 'setting_name="clean_uploaded_filename" AND setting_value=1');
373
+        if ($modx->db->getValue($setting)>0) {
374
+            // Transalias plugin active?
375
+            $res = $modx->db->select('properties', $modx->getFullTableName('site_plugins'), 'name="TransAlias" AND disabled=0');
376
+            if ($properties = $modx->db->getValue($res)) {
377
+                $properties = $modx->parseProperties($properties, 'TransAlias', 'plugin');
378
+            } else {
379
+                $properties = NULL;
380
+            }
381
+        } else {
382
+            $properties = NULL;
383
+        }
384
+        return $properties;
385
+    }
386
+
387
+
388
+    protected function normalizeFilename($filename) {
389
+        if ($this->getTransaliasSettings()) {
390
+                $format = strrchr($filename, ".");
391
+                $filename = str_replace($format, "", $filename);
392
+                    $filename = $this->modx->stripAlias($filename).$format;
393
+            }
394
+            return $filename;
395
+    }
396
+
397
+    protected function normalizeDirname($dirname) {
398 398
         return $this->modx->stripAlias($dirname);
399 399
     }
400 400
 
@@ -472,10 +472,10 @@  discard block
 block discarded – undo
472 472
             return $this->label("The image is too big and/or cannot be resized.");
473 473
 
474 474
 
475
-	// CHECK FOR MODX MAX FILE SIZE                
476
-	$actualfilesize=filesize($file['tmp_name']);
477
-	if (isset($this->config['maxfilesize']) && $actualfilesize > $this->config['maxfilesize'])
478
-	    return $this->label("File is too big: ".$actualfilesize." Bytes. (max ".$this->config['maxfilesize']." Bytes)");
475
+    // CHECK FOR MODX MAX FILE SIZE                
476
+    $actualfilesize=filesize($file['tmp_name']);
477
+    if (isset($this->config['maxfilesize']) && $actualfilesize > $this->config['maxfilesize'])
478
+        return $this->label("File is too big: ".$actualfilesize." Bytes. (max ".$this->config['maxfilesize']." Bytes)");
479 479
 
480 480
         return true;
481 481
     }
@@ -627,7 +627,7 @@  discard block
 block discarded – undo
627 627
             $top = isset($this->config['watermark']['top'])
628 628
                 ? $this->config['watermark']['top'] : false;
629 629
             $img->watermark($this->config['watermark']['file'], $left, $top);
630
-		}
630
+        }
631 631
 
632 632
         $options = array( 'file' => $file );
633 633
 
Please login to merge, or discard this patch.
Spacing   +46 added lines, -47 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
   *      @link http://kcfinder.sunhater.com
13 13
   */
14 14
 
15
-class uploader {
15
+class uploader{
16 16
 
17 17
 /** Release version */
18 18
     const VERSION = "2.54";
@@ -72,8 +72,8 @@  discard block
 block discarded – undo
72 72
 
73 73
 /** Next three properties are got from the current language file
74 74
   * @var string */
75
-    protected $dateTimeFull;   // Currently not used
76
-    protected $dateTimeMid;    // Currently not used
75
+    protected $dateTimeFull; // Currently not used
76
+    protected $dateTimeMid; // Currently not used
77 77
     protected $dateTimeSmall;
78 78
 
79 79
 /** Contain Specified language labels
@@ -104,11 +104,11 @@  discard block
 block discarded – undo
104 104
 /** Magic method which allows read-only access to protected or private class properties
105 105
   * @param string $property
106 106
   * @return mixed */
107
-    public function __get($property) {
107
+    public function __get($property){
108 108
         return property_exists($this, $property) ? $this->$property : null;
109 109
     }
110 110
 
111
-    public function __construct($modx) {
111
+    public function __construct($modx){
112 112
 
113 113
         //MODX
114 114
         try {
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
 
207 207
         // COOKIES INIT
208 208
         $ip = '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)';
209
-        $ip = '/^' . implode('\.', array($ip, $ip, $ip, $ip)) . '$/';
209
+        $ip = '/^'.implode('\.', array($ip, $ip, $ip, $ip)).'$/';
210 210
         if (preg_match($ip, $_SERVER['HTTP_HOST']) ||
211 211
             preg_match('/^[^\.]+$/', $_SERVER['HTTP_HOST'])
212 212
         )
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
         ) {
225 225
             list($unused, $protocol, $domain, $unused, $port, $path) = $patt;
226 226
             $path = path::normalize($path);
227
-            $this->config['uploadURL'] = "$protocol://$domain" . (strlen($port) ? ":$port" : "") . "/$path";
227
+            $this->config['uploadURL'] = "$protocol://$domain".(strlen($port) ? ":$port" : "")."/$path";
228 228
             $this->config['uploadDir'] = strlen($this->config['uploadDir'])
229 229
                 ? path::normalize($this->config['uploadDir'])
230 230
                 : path::url2fullPath("/$path");
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
         foreach ($this->langInputNames as $key)
268 268
             if (isset($this->get[$key]) &&
269 269
                 preg_match('/^[a-z][a-z\._\-]*$/i', $this->get[$key]) &&
270
-                file_exists("lang/" . strtolower($this->get[$key]) . ".php")
270
+                file_exists("lang/".strtolower($this->get[$key]).".php")
271 271
             ) {
272 272
                 $this->lang = $this->get[$key];
273 273
                 break;
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
             $this->backMsg("Cannot read upload folder.");
299 299
     }
300 300
 
301
-    public function upload() {
301
+    public function upload(){
302 302
         $config = &$this->config;
303 303
         $file = &$this->file;
304 304
         $url = $message = "";
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
                     @mkdir(path::normalize($dir), $this->config['dirPerms'], true);
330 330
 
331 331
                 $filename = $this->normalizeFilename($file['name']);
332
-                $target = file::getInexistantFilename($dir . $filename);
332
+                $target = file::getInexistantFilename($dir.$filename);
333 333
 
334 334
                 if (!@move_uploaded_file($file['tmp_name'], $target) &&
335 335
                     !@rename($file['tmp_name'], $target) &&
@@ -342,11 +342,11 @@  discard block
 block discarded – undo
342 342
                     $this->makeThumb($target);
343 343
                     $url = $this->typeURL;
344 344
                     if (isset($udir)) $url .= "/$udir";
345
-                    $url .= "/" . basename($target);
345
+                    $url .= "/".basename($target);
346 346
                     if (preg_match('/^([a-z]+)\:\/\/([^\/^\:]+)(\:(\d+))?\/(.+)$/', $url, $patt)) {
347 347
                         list($unused, $protocol, $domain, $unused, $port, $path) = $patt;
348
-                        $base = "$protocol://$domain" . (strlen($port) ? ":$port" : "") . "/";
349
-                        $url = $base . path::urlPathEncode($path);
348
+                        $base = "$protocol://$domain".(strlen($port) ? ":$port" : "")."/";
349
+                        $url = $base.path::urlPathEncode($path);
350 350
                     } else
351 351
                         $url = path::urlPathEncode($url);
352 352
                 }
@@ -365,12 +365,12 @@  discard block
 block discarded – undo
365 365
     }
366 366
 
367 367
 
368
-	protected function getTransaliasSettings() {
368
+	protected function getTransaliasSettings(){
369 369
 		global $modx;
370 370
 
371 371
 		// Cleaning uploaded filename?
372 372
 		$setting = $modx->db->select('count(*)', $modx->getFullTableName('system_settings'), 'setting_name="clean_uploaded_filename" AND setting_value=1');
373
-		if ($modx->db->getValue($setting)>0) {
373
+		if ($modx->db->getValue($setting) > 0) {
374 374
 			// Transalias plugin active?
375 375
 			$res = $modx->db->select('properties', $modx->getFullTableName('site_plugins'), 'name="TransAlias" AND disabled=0');
376 376
 			if ($properties = $modx->db->getValue($res)) {
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
 	}
386 386
 
387 387
 
388
-	protected function normalizeFilename($filename) {
388
+	protected function normalizeFilename($filename){
389 389
 		if ($this->getTransaliasSettings()) {
390 390
         		$format = strrchr($filename, ".");
391 391
         		$filename = str_replace($format, "", $filename);
@@ -394,11 +394,11 @@  discard block
 block discarded – undo
394 394
         	return $filename;
395 395
 	}
396 396
 
397
-	protected function normalizeDirname($dirname) {
397
+	protected function normalizeDirname($dirname){
398 398
         return $this->modx->stripAlias($dirname);
399 399
     }
400 400
 
401
-    protected function checkUploadedFile(array $aFile=null) {
401
+    protected function checkUploadedFile(array $aFile = null){
402 402
         $config = &$this->config;
403 403
         $file = ($aFile === null) ? $this->file : $aFile;
404 404
 
@@ -437,8 +437,7 @@  discard block
 block discarded – undo
437 437
                 ($file['error'] == UPLOAD_ERR_NO_TMP_DIR) ?
438 438
                     $this->label("Missing a temporary folder.") : (
439 439
                 ($file['error'] == UPLOAD_ERR_CANT_WRITE) ?
440
-                    $this->label("Failed to write file.") :
441
-                    $this->label("Unknown error.")
440
+                    $this->label("Failed to write file.") : $this->label("Unknown error.")
442 441
             )))));
443 442
 
444 443
         // HIDDEN FILENAMES CHECK
@@ -473,14 +472,14 @@  discard block
 block discarded – undo
473 472
 
474 473
 
475 474
 	// CHECK FOR MODX MAX FILE SIZE                
476
-	$actualfilesize=filesize($file['tmp_name']);
475
+	$actualfilesize = filesize($file['tmp_name']);
477 476
 	if (isset($this->config['maxfilesize']) && $actualfilesize > $this->config['maxfilesize'])
478 477
 	    return $this->label("File is too big: ".$actualfilesize." Bytes. (max ".$this->config['maxfilesize']." Bytes)");
479 478
 
480 479
         return true;
481 480
     }
482 481
 
483
-    protected function checkInputDir($dir, $inclType=true, $existing=true) {
482
+    protected function checkInputDir($dir, $inclType = true, $existing = true){
484 483
         $dir = path::normalize($dir);
485 484
         if (substr($dir, 0, 1) == "/")
486 485
             $dir = substr($dir, 1);
@@ -506,7 +505,7 @@  discard block
 block discarded – undo
506 505
         return (is_dir($path) && is_readable($path)) ? $return : false;
507 506
     }
508 507
 
509
-    protected function validateExtension($ext, $type) {
508
+    protected function validateExtension($ext, $type){
510 509
         $ext = trim(strtolower($ext));
511 510
         if (!isset($this->types[$type]))
512 511
             return false;
@@ -531,17 +530,17 @@  discard block
 block discarded – undo
531 530
         return in_array($ext, $exts);
532 531
     }
533 532
 
534
-    protected function getTypeFromPath($path) {
533
+    protected function getTypeFromPath($path){
535 534
         return preg_match('/^([^\/]*)\/.*$/', $path, $patt)
536 535
             ? $patt[1] : $path;
537 536
     }
538 537
 
539
-    protected function removeTypeFromPath($path) {
538
+    protected function removeTypeFromPath($path){
540 539
         return preg_match('/^[^\/]*\/(.*)$/', $path, $patt)
541 540
             ? $patt[1] : "";
542 541
     }
543 542
 
544
-    protected function imageResize($image, $file=null) {
543
+    protected function imageResize($image, $file = null){
545 544
 
546 545
         if (!($image instanceof image)) {
547 546
             $img = image::factory($this->imageDriver, $image);
@@ -629,24 +628,24 @@  discard block
 block discarded – undo
629 628
             $img->watermark($this->config['watermark']['file'], $left, $top);
630 629
 		}
631 630
 
632
-        $options = array( 'file' => $file );
631
+        $options = array('file' => $file);
633 632
 
634
-        $type = exif_imagetype( $file );
633
+        $type = exif_imagetype($file);
635 634
 
636
-        switch ( $type ) {
635
+        switch ($type) {
637 636
             case IMAGETYPE_GIF: 
638
-                return $img->output( 'gif', $options );
637
+                return $img->output('gif', $options);
639 638
 
640 639
             case IMAGETYPE_PNG: 
641
-                return $img->output( 'png', $options );
640
+                return $img->output('png', $options);
642 641
             
643 642
             default:
644
-                return $img->output( 'jpeg', array_merge( $options, array( 'quality' => $this->config['jpegQuality'] ) ) );
643
+                return $img->output('jpeg', array_merge($options, array('quality' => $this->config['jpegQuality'])));
645 644
         }
646 645
 
647 646
     }
648 647
 
649
-    protected function makeThumb($file, $overwrite=true) {
648
+    protected function makeThumb($file, $overwrite = true){
650 649
         $img = image::factory($this->imageDriver, $file);
651 650
 
652 651
         // Drop files which are not images
@@ -654,7 +653,7 @@  discard block
 block discarded – undo
654 653
             return true;
655 654
 
656 655
         $thumb = substr($file, strlen($this->config['uploadDir']));
657
-        $thumb = $this->config['uploadDir'] . "/" . $this->config['thumbsDir'] . "/" . $thumb;
656
+        $thumb = $this->config['uploadDir']."/".$this->config['thumbsDir']."/".$thumb;
658 657
         $thumb = path::normalize($thumb);
659 658
         $thumbDir = dirname($thumb);
660 659
         if (!is_dir($thumbDir) && !@mkdir($thumbDir, $this->config['dirPerms'], true))
@@ -677,15 +676,15 @@  discard block
 block discarded – undo
677 676
         if (!$img->resizeFit($this->config['thumbWidth'], $this->config['thumbHeight']))
678 677
             return false;
679 678
 
680
-        if ( $this->imageDriver == 'gd' ) {
681
-            $width  = imagesx( $img->image );
682
-            $height = imagesy( $img->image );
683
-            $back   = image::factory( $this->imageDriver, array( $width, $height ) );
684
-            $tile   = image::factory( $this->imageDriver, __DIR__ . '/../themes/' . $this->config['theme'] . '/img/bg_transparent.png' );
679
+        if ($this->imageDriver == 'gd') {
680
+            $width  = imagesx($img->image);
681
+            $height = imagesy($img->image);
682
+            $back   = image::factory($this->imageDriver, array($width, $height));
683
+            $tile   = image::factory($this->imageDriver, __DIR__.'/../themes/'.$this->config['theme'].'/img/bg_transparent.png');
685 684
             
686
-            imagesettile( $back->image, $tile->image );
687
-            imagefilledrectangle( $back->image, 0, 0, $width, $height, IMG_COLOR_TILED );
688
-            imagecopy( $back->image, $img->image, 0, 0, 0, 0, $width, $height );
685
+            imagesettile($back->image, $tile->image);
686
+            imagefilledrectangle($back->image, 0, 0, $width, $height, IMG_COLOR_TILED);
687
+            imagecopy($back->image, $img->image, 0, 0, 0, 0, $width, $height);
689 688
 
690 689
             $img = $back;
691 690
         }
@@ -697,7 +696,7 @@  discard block
 block discarded – undo
697 696
         ));
698 697
     }
699 698
 
700
-    protected function localize($langCode) {
699
+    protected function localize($langCode){
701 700
         require "lang/{$langCode}.php";
702 701
         setlocale(LC_ALL, $lang['_locale']);
703 702
         $this->charset = $lang['_charset'];
@@ -712,7 +711,7 @@  discard block
 block discarded – undo
712 711
         $this->labels = $lang;
713 712
     }
714 713
 
715
-    protected function label($string, array $data=null) {
714
+    protected function label($string, array $data = null){
716 715
         $return = isset($this->labels[$string]) ? $this->labels[$string] : $string;
717 716
         if (is_array($data))
718 717
             foreach ($data as $key => $val)
@@ -720,7 +719,7 @@  discard block
 block discarded – undo
720 719
         return $return;
721 720
     }
722 721
 
723
-    protected function backMsg($message, array $data=null) {
722
+    protected function backMsg($message, array $data = null){
724 723
         $message = $this->label($message, $data);
725 724
         if (isset($this->file['tmp_name']) && file_exists($this->file['tmp_name']))
726 725
             @unlink($this->file['tmp_name']);
@@ -728,7 +727,7 @@  discard block
 block discarded – undo
728 727
         die;
729 728
     }
730 729
 
731
-    protected function callBack($url, $message="") {
730
+    protected function callBack($url, $message = ""){
732 731
         $message = text::jsValue($message);
733 732
         $CKfuncNum = isset($this->opener['CKEditor']['funcNum'])
734 733
             ? $this->opener['CKEditor']['funcNum'] : 0;
@@ -769,7 +768,7 @@  discard block
 block discarded – undo
769 768
 
770 769
     }
771 770
 
772
-    protected function get_htaccess() {
771
+    protected function get_htaccess(){
773 772
         return "<IfModule mod_php4.c>
774 773
   php_value engine off
775 774
 </IfModule>
Please login to merge, or discard this patch.
Braces   +238 added lines, -149 removed lines patch added patch discarded remove patch
@@ -12,7 +12,8 @@  discard block
 block discarded – undo
12 12
   *      @link http://kcfinder.sunhater.com
13 13
   */
14 14
 
15
-class uploader {
15
+class uploader
16
+{
16 17
 
17 18
 /** Release version */
18 19
     const VERSION = "2.54";
@@ -104,17 +105,21 @@  discard block
 block discarded – undo
104 105
 /** Magic method which allows read-only access to protected or private class properties
105 106
   * @param string $property
106 107
   * @return mixed */
107
-    public function __get($property) {
108
+    public function __get($property)
109
+    {
108 110
         return property_exists($this, $property) ? $this->$property : null;
109 111
     }
110 112
 
111
-    public function __construct($modx) {
113
+    public function __construct($modx)
114
+    {
112 115
 
113 116
         //MODX
114 117
         try {
115 118
             if ($modx instanceof DocumentParser) {
116 119
                 $this->modx = $modx;
117
-            } else throw new Exception('MODX should be instance of DocumentParser');
120
+            } else {
121
+                throw new Exception('MODX should be instance of DocumentParser');
122
+            }
118 123
         } catch (Exception $e) {
119 124
             die($e->getMessage());
120 125
         }
@@ -129,26 +134,34 @@  discard block
 block discarded – undo
129 134
         // SET CMS INTEGRATION ATTRIBUTE
130 135
         if (isset($this->get['cms']) &&
131 136
             in_array($this->get['cms'], array("drupal"))
132
-        )
133
-            $this->cms = $this->get['cms'];
137
+        ) {
138
+                    $this->cms = $this->get['cms'];
139
+        }
134 140
 
135 141
 		// LINKING UPLOADED FILE
136
-        if (count($_FILES))
137
-            $this->file = &$_FILES[key($_FILES)];
142
+        if (count($_FILES)) {
143
+                    $this->file = &$_FILES[key($_FILES)];
144
+        }
138 145
 
139 146
         // LOAD DEFAULT CONFIGURATION
140 147
         require "config.php";
141 148
 
142 149
         // SETTING UP SESSION
143
-        if (isset($_CONFIG['_sessionLifetime']))
144
-            ini_set('session.gc_maxlifetime', $_CONFIG['_sessionLifetime'] * 60);
145
-        if (isset($_CONFIG['_sessionDir']))
146
-            ini_set('session.save_path', $_CONFIG['_sessionDir']);
147
-        if (isset($_CONFIG['_sessionDomain']))
148
-            ini_set('session.cookie_domain', $_CONFIG['_sessionDomain']);
150
+        if (isset($_CONFIG['_sessionLifetime'])) {
151
+                    ini_set('session.gc_maxlifetime', $_CONFIG['_sessionLifetime'] * 60);
152
+        }
153
+        if (isset($_CONFIG['_sessionDir'])) {
154
+                    ini_set('session.save_path', $_CONFIG['_sessionDir']);
155
+        }
156
+        if (isset($_CONFIG['_sessionDomain'])) {
157
+                    ini_set('session.cookie_domain', $_CONFIG['_sessionDomain']);
158
+        }
149 159
         switch ($this->cms) {
150 160
             case "drupal": break;
151
-            default: if (!session_id()) session_start(); break;
161
+            default: if (!session_id()) {
162
+                session_start();
163
+            }
164
+            break;
152 165
         }
153 166
 
154 167
         // RELOAD DEFAULT CONFIGURATION
@@ -159,31 +172,37 @@  discard block
 block discarded – undo
159 172
         if (isset($_CONFIG['_sessionVar']) &&
160 173
             is_array($_CONFIG['_sessionVar'])
161 174
         ) {
162
-            foreach ($_CONFIG['_sessionVar'] as $key => $val)
163
-                if ((substr($key, 0, 1) != "_") && isset($_CONFIG[$key]))
175
+            foreach ($_CONFIG['_sessionVar'] as $key => $val) {
176
+                            if ((substr($key, 0, 1) != "_") && isset($_CONFIG[$key]))
164 177
                     $this->config[$key] = $val;
165
-            if (!isset($this->config['_sessionVar']['self']))
166
-                $this->config['_sessionVar']['self'] = array();
178
+            }
179
+            if (!isset($this->config['_sessionVar']['self'])) {
180
+                            $this->config['_sessionVar']['self'] = array();
181
+            }
167 182
             $this->session = &$this->config['_sessionVar']['self'];
168
-        } else
169
-            $this->session = &$_SESSION;
183
+        } else {
184
+                    $this->session = &$_SESSION;
185
+        }
170 186
 
171 187
         // IMAGE DRIVER INIT
172 188
         if (isset($this->config['imageDriversPriority'])) {
173 189
             $this->config['imageDriversPriority'] =
174 190
                 text::clearWhitespaces($this->config['imageDriversPriority']);
175 191
             $driver = image::getDriver(explode(' ', $this->config['imageDriversPriority']));
176
-            if ($driver !== false)
177
-                $this->imageDriver = $driver;
192
+            if ($driver !== false) {
193
+                            $this->imageDriver = $driver;
194
+            }
178 195
         }
179 196
         if ((!isset($driver) || ($driver === false)) &&
180 197
             (image::getDriver(array($this->imageDriver)) === false)
181
-        )
182
-            die("Cannot find any of the supported PHP image extensions!");
198
+        ) {
199
+                    die("Cannot find any of the supported PHP image extensions!");
200
+        }
183 201
 
184 202
         // WATERMARK INIT
185
-        if (isset($this->config['watermark']) && is_string($this->config['watermark']))
186
-            $this->config['watermark'] = array('file' => $this->config['watermark']);
203
+        if (isset($this->config['watermark']) && is_string($this->config['watermark'])) {
204
+                    $this->config['watermark'] = array('file' => $this->config['watermark']);
205
+        }
187 206
 
188 207
         // GET TYPE DIRECTORY
189 208
         $this->types = &$this->config['types'];
@@ -197,9 +216,10 @@  discard block
 block discarded – undo
197 216
 
198 217
         // LOAD TYPE DIRECTORY SPECIFIC CONFIGURATION IF EXISTS
199 218
         if (is_array($this->types[$this->type])) {
200
-            foreach ($this->types[$this->type] as $key => $val)
201
-                if (in_array($key, $this->typeSettings))
219
+            foreach ($this->types[$this->type] as $key => $val) {
220
+                            if (in_array($key, $this->typeSettings))
202 221
                     $this->config[$key] = $val;
222
+            }
203 223
             $this->types[$this->type] = isset($this->types[$this->type]['type'])
204 224
                 ? $this->types[$this->type]['type'] : "";
205 225
         }
@@ -209,12 +229,14 @@  discard block
 block discarded – undo
209 229
         $ip = '/^' . implode('\.', array($ip, $ip, $ip, $ip)) . '$/';
210 230
         if (preg_match($ip, $_SERVER['HTTP_HOST']) ||
211 231
             preg_match('/^[^\.]+$/', $_SERVER['HTTP_HOST'])
212
-        )
213
-            $this->config['cookieDomain'] = "";
214
-        elseif (!strlen($this->config['cookieDomain']))
215
-            $this->config['cookieDomain'] = $_SERVER['HTTP_HOST'];
216
-        if (!strlen($this->config['cookiePath']))
217
-            $this->config['cookiePath'] = "/";
232
+        ) {
233
+                    $this->config['cookieDomain'] = "";
234
+        } elseif (!strlen($this->config['cookieDomain'])) {
235
+                    $this->config['cookieDomain'] = $_SERVER['HTTP_HOST'];
236
+        }
237
+        if (!strlen($this->config['cookiePath'])) {
238
+                    $this->config['cookiePath'] = "/";
239
+        }
218 240
 
219 241
         // UPLOAD FOLDER INIT
220 242
 
@@ -250,26 +272,30 @@  discard block
 block discarded – undo
250 272
             $this->typeDir = "{$this->config['uploadDir']}/{$this->type}";
251 273
             $this->typeURL = "{$this->config['uploadURL']}/{$this->type}";
252 274
         }
253
-        if (!is_dir($this->config['uploadDir']))
254
-            @mkdir($this->config['uploadDir'], $this->config['dirPerms']);
275
+        if (!is_dir($this->config['uploadDir'])) {
276
+                    @mkdir($this->config['uploadDir'], $this->config['dirPerms']);
277
+        }
255 278
 
256 279
         // HOST APPLICATIONS INIT
257
-        if (isset($this->get['CKEditorFuncNum']))
258
-            $this->opener['CKEditor']['funcNum'] = $this->get['CKEditorFuncNum'];
280
+        if (isset($this->get['CKEditorFuncNum'])) {
281
+                    $this->opener['CKEditor']['funcNum'] = $this->get['CKEditorFuncNum'];
282
+        }
259 283
         if (isset($this->get['opener']) &&
260 284
             (strtolower($this->get['opener']) == "tinymce") &&
261 285
             isset($this->config['_tinyMCEPath']) &&
262 286
             strlen($this->config['_tinyMCEPath'])
263
-        )
264
-            $this->opener['TinyMCE'] = true;
287
+        ) {
288
+                    $this->opener['TinyMCE'] = true;
289
+        }
265 290
 
266 291
         // LOCALIZATION
267
-        foreach ($this->langInputNames as $key)
268
-            if (isset($this->get[$key]) &&
292
+        foreach ($this->langInputNames as $key) {
293
+                    if (isset($this->get[$key]) &&
269 294
                 preg_match('/^[a-z][a-z\._\-]*$/i', $this->get[$key]) &&
270 295
                 file_exists("lang/" . strtolower($this->get[$key]) . ".php")
271 296
             ) {
272 297
                 $this->lang = $this->get[$key];
298
+        }
273 299
                 break;
274 300
             }
275 301
         $this->localize($this->lang);
@@ -280,31 +306,39 @@  discard block
 block discarded – undo
280 306
         ) {
281 307
             $htaccess = "{$this->config['uploadDir']}/.htaccess";
282 308
             if (!file_exists($htaccess)) {
283
-                if (!@file_put_contents($htaccess, $this->get_htaccess()))
284
-                    $this->backMsg("Cannot write to upload folder. {$this->config['uploadDir']}");
309
+                if (!@file_put_contents($htaccess, $this->get_htaccess())) {
310
+                                    $this->backMsg("Cannot write to upload folder. {$this->config['uploadDir']}");
311
+                }
285 312
             } else {
286
-                if (false === ($data = @file_get_contents($htaccess)))
287
-                    $this->backMsg("Cannot read .htaccess");
288
-                if (($data != $this->get_htaccess()) && !@file_put_contents($htaccess, $data))
289
-                    $this->backMsg("Incorrect .htaccess file. Cannot rewrite it!");
313
+                if (false === ($data = @file_get_contents($htaccess))) {
314
+                                    $this->backMsg("Cannot read .htaccess");
315
+                }
316
+                if (($data != $this->get_htaccess()) && !@file_put_contents($htaccess, $data)) {
317
+                                    $this->backMsg("Incorrect .htaccess file. Cannot rewrite it!");
318
+                }
290 319
             }
291 320
         }
292 321
 
293 322
         // CHECK & CREATE UPLOAD FOLDER
294 323
         if (!is_dir($this->typeDir)) {
295
-            if (!mkdir($this->typeDir, $this->config['dirPerms']))
296
-                $this->backMsg("Cannot create {dir} folder.", array('dir' => $this->type));
297
-        } elseif (!is_readable($this->typeDir))
298
-            $this->backMsg("Cannot read upload folder.");
324
+            if (!mkdir($this->typeDir, $this->config['dirPerms'])) {
325
+                            $this->backMsg("Cannot create {dir} folder.", array('dir' => $this->type));
326
+            }
327
+        } elseif (!is_readable($this->typeDir)) {
328
+                    $this->backMsg("Cannot read upload folder.");
329
+        }
299 330
     }
300 331
 
301
-    public function upload() {
332
+    public function upload()
333
+    {
302 334
         $config = &$this->config;
303 335
         $file = &$this->file;
304 336
         $url = $message = "";
305 337
 
306 338
         if ($config['disabled'] || !$config['access']['files']['upload']) {
307
-            if (isset($file['tmp_name'])) @unlink($file['tmp_name']);
339
+            if (isset($file['tmp_name'])) {
340
+                @unlink($file['tmp_name']);
341
+            }
308 342
             $message = $this->label("You don't have permissions to upload files.");
309 343
 
310 344
         } elseif (true === ($message = $this->checkUploadedFile())) {
@@ -315,9 +349,9 @@  discard block
 block discarded – undo
315 349
                 (false !== ($gdir = $this->checkInputDir($this->get['dir'])))
316 350
             ) {
317 351
                 $udir = path::normalize("$dir$gdir");
318
-                if (substr($udir, 0, strlen($dir)) !== $dir)
319
-                    $message = $this->label("Unknown error.");
320
-                else {
352
+                if (substr($udir, 0, strlen($dir)) !== $dir) {
353
+                                    $message = $this->label("Unknown error.");
354
+                } else {
321 355
                     $l = strlen($dir);
322 356
                     $dir = "$udir/";
323 357
                     $udir = substr($udir, $l);
@@ -325,8 +359,9 @@  discard block
 block discarded – undo
325 359
             }
326 360
 
327 361
             if (!strlen($message)) {
328
-                if (!is_dir(path::normalize($dir)))
329
-                    @mkdir(path::normalize($dir), $this->config['dirPerms'], true);
362
+                if (!is_dir(path::normalize($dir))) {
363
+                                    @mkdir(path::normalize($dir), $this->config['dirPerms'], true);
364
+                }
330 365
 
331 366
                 $filename = $this->normalizeFilename($file['name']);
332 367
                 $target = file::getInexistantFilename($dir . $filename);
@@ -334,21 +369,25 @@  discard block
 block discarded – undo
334 369
                 if (!@move_uploaded_file($file['tmp_name'], $target) &&
335 370
                     !@rename($file['tmp_name'], $target) &&
336 371
                     !@copy($file['tmp_name'], $target)
337
-                )
338
-                    $message = $this->label("Cannot move uploaded file to target folder.");
339
-                else {
340
-                    if (function_exists('chmod'))
341
-                        @chmod($target, $this->config['filePerms']);
372
+                ) {
373
+                                    $message = $this->label("Cannot move uploaded file to target folder.");
374
+                } else {
375
+                    if (function_exists('chmod')) {
376
+                                            @chmod($target, $this->config['filePerms']);
377
+                    }
342 378
                     $this->makeThumb($target);
343 379
                     $url = $this->typeURL;
344
-                    if (isset($udir)) $url .= "/$udir";
380
+                    if (isset($udir)) {
381
+                        $url .= "/$udir";
382
+                    }
345 383
                     $url .= "/" . basename($target);
346 384
                     if (preg_match('/^([a-z]+)\:\/\/([^\/^\:]+)(\:(\d+))?\/(.+)$/', $url, $patt)) {
347 385
                         list($unused, $protocol, $domain, $unused, $port, $path) = $patt;
348 386
                         $base = "$protocol://$domain" . (strlen($port) ? ":$port" : "") . "/";
349 387
                         $url = $base . path::urlPathEncode($path);
350
-                    } else
351
-                        $url = path::urlPathEncode($url);
388
+                    } else {
389
+                                            $url = path::urlPathEncode($url);
390
+                    }
352 391
                 }
353 392
             }
354 393
         }
@@ -356,16 +395,19 @@  discard block
 block discarded – undo
356 395
         if (strlen($message) &&
357 396
             isset($this->file['tmp_name']) &&
358 397
             file_exists($this->file['tmp_name'])
359
-        )
360
-            @unlink($this->file['tmp_name']);
398
+        ) {
399
+                    @unlink($this->file['tmp_name']);
400
+        }
361 401
 
362
-        if (strlen($message) && method_exists($this, 'errorMsg'))
363
-            $this->errorMsg($message);
402
+        if (strlen($message) && method_exists($this, 'errorMsg')) {
403
+                    $this->errorMsg($message);
404
+        }
364 405
         $this->callBack($url, $message);
365 406
     }
366 407
 
367 408
 
368
-	protected function getTransaliasSettings() {
409
+	protected function getTransaliasSettings()
410
+	{
369 411
 		global $modx;
370 412
 
371 413
 		// Cleaning uploaded filename?
@@ -385,7 +427,8 @@  discard block
 block discarded – undo
385 427
 	}
386 428
 
387 429
 
388
-	protected function normalizeFilename($filename) {
430
+	protected function normalizeFilename($filename)
431
+	{
389 432
 		if ($this->getTransaliasSettings()) {
390 433
         		$format = strrchr($filename, ".");
391 434
         		$filename = str_replace($format, "", $filename);
@@ -394,16 +437,19 @@  discard block
 block discarded – undo
394 437
         	return $filename;
395 438
 	}
396 439
 
397
-	protected function normalizeDirname($dirname) {
440
+	protected function normalizeDirname($dirname)
441
+	{
398 442
         return $this->modx->stripAlias($dirname);
399 443
     }
400 444
 
401
-    protected function checkUploadedFile(array $aFile=null) {
445
+    protected function checkUploadedFile(array $aFile=null)
446
+    {
402 447
         $config = &$this->config;
403 448
         $file = ($aFile === null) ? $this->file : $aFile;
404 449
 
405
-        if (!is_array($file) || !isset($file['name']))
406
-            return $this->label("Unknown error");
450
+        if (!is_array($file) || !isset($file['name'])) {
451
+                    return $this->label("Unknown error");
452
+        }
407 453
 
408 454
         if (is_array($file['name'])) {
409 455
             foreach ($file['name'] as $i => $name) {
@@ -412,8 +458,9 @@  discard block
 block discarded – undo
412 458
                     'tmp_name' => $file['tmp_name'][$i],
413 459
                     'error' => $file['error'][$i]
414 460
                 ));
415
-                if ($return !== true)
416
-                    return "$name: $return";
461
+                if ($return !== true) {
462
+                                    return "$name: $return";
463
+                }
417 464
             }
418 465
             return true;
419 466
         }
@@ -422,8 +469,8 @@  discard block
 block discarded – undo
422 469
         $typePatt = strtolower(text::clearWhitespaces($this->types[$this->type]));
423 470
 
424 471
         // CHECK FOR UPLOAD ERRORS
425
-        if ($file['error'])
426
-            return
472
+        if ($file['error']) {
473
+                    return
427 474
                 ($file['error'] == UPLOAD_ERR_INI_SIZE) ?
428 475
                     $this->label("The uploaded file exceeds {size} bytes.",
429 476
                         array('size' => ini_get('upload_max_filesize'))) : (
@@ -440,14 +487,17 @@  discard block
 block discarded – undo
440 487
                     $this->label("Failed to write file.") :
441 488
                     $this->label("Unknown error.")
442 489
             )))));
490
+        }
443 491
 
444 492
         // HIDDEN FILENAMES CHECK
445
-        elseif (substr($file['name'], 0, 1) == ".")
446
-            return $this->label("File name shouldn't begins with '.'");
493
+        elseif (substr($file['name'], 0, 1) == ".") {
494
+                    return $this->label("File name shouldn't begins with '.'");
495
+        }
447 496
 
448 497
         // EXTENSION CHECK
449
-        elseif (!$this->validateExtension($extension, $this->type))
450
-            return $this->label("Denied file extension.");
498
+        elseif (!$this->validateExtension($extension, $this->type)) {
499
+                    return $this->label("Denied file extension.");
500
+        }
451 501
 
452 502
         // SPECIAL DIRECTORY TYPES CHECK (e.g. *img)
453 503
         elseif (preg_match('/^\*([^ ]+)(.*)?$/s', $typePatt, $patt)) {
@@ -457,70 +507,84 @@  discard block
 block discarded – undo
457 507
                 $type = new $class();
458 508
                 $cfg = $config;
459 509
                 $cfg['filename'] = $file['name'];
460
-                if (strlen($params))
461
-                    $cfg['params'] = trim($params);
510
+                if (strlen($params)) {
511
+                                    $cfg['params'] = trim($params);
512
+                }
462 513
                 $response = $type->checkFile($file['tmp_name'], $cfg);
463
-                if ($response !== true)
464
-                    return $this->label($response);
465
-            } else
466
-                return $this->label("Non-existing directory type.");
514
+                if ($response !== true) {
515
+                                    return $this->label($response);
516
+                }
517
+            } else {
518
+                            return $this->label("Non-existing directory type.");
519
+            }
467 520
         }
468 521
 
469 522
         // IMAGE RESIZE
470 523
         $img = image::factory($this->imageDriver, $file['tmp_name']);
471
-        if (!$img->initError && !$this->imageResize($img, $file['tmp_name']))
472
-            return $this->label("The image is too big and/or cannot be resized.");
524
+        if (!$img->initError && !$this->imageResize($img, $file['tmp_name'])) {
525
+                    return $this->label("The image is too big and/or cannot be resized.");
526
+        }
473 527
 
474 528
 
475 529
 	// CHECK FOR MODX MAX FILE SIZE                
476 530
 	$actualfilesize=filesize($file['tmp_name']);
477
-	if (isset($this->config['maxfilesize']) && $actualfilesize > $this->config['maxfilesize'])
478
-	    return $this->label("File is too big: ".$actualfilesize." Bytes. (max ".$this->config['maxfilesize']." Bytes)");
531
+	if (isset($this->config['maxfilesize']) && $actualfilesize > $this->config['maxfilesize']) {
532
+		    return $this->label("File is too big: ".$actualfilesize." Bytes. (max ".$this->config['maxfilesize']." Bytes)");
533
+	}
479 534
 
480 535
         return true;
481 536
     }
482 537
 
483
-    protected function checkInputDir($dir, $inclType=true, $existing=true) {
538
+    protected function checkInputDir($dir, $inclType=true, $existing=true)
539
+    {
484 540
         $dir = path::normalize($dir);
485
-        if (substr($dir, 0, 1) == "/")
486
-            $dir = substr($dir, 1);
541
+        if (substr($dir, 0, 1) == "/") {
542
+                    $dir = substr($dir, 1);
543
+        }
487 544
 
488
-        if ((substr($dir, 0, 1) == ".") || (substr(basename($dir), 0, 1) == "."))
489
-            return false;
545
+        if ((substr($dir, 0, 1) == ".") || (substr(basename($dir), 0, 1) == ".")) {
546
+                    return false;
547
+        }
490 548
 
491 549
         if ($inclType) {
492 550
             $first = explode("/", $dir);
493 551
             $first = $first[0];
494
-            if ($first != $this->type)
495
-                return false;
552
+            if ($first != $this->type) {
553
+                            return false;
554
+            }
496 555
             $return = $this->removeTypeFromPath($dir);
497 556
         } else {
498 557
             $return = $dir;
499 558
             $dir = "{$this->type}/$dir";
500 559
         }
501 560
 
502
-        if (!$existing)
503
-            return $return;
561
+        if (!$existing) {
562
+                    return $return;
563
+        }
504 564
 
505 565
         $path = "{$this->config['uploadDir']}/$dir";
506 566
         return (is_dir($path) && is_readable($path)) ? $return : false;
507 567
     }
508 568
 
509
-    protected function validateExtension($ext, $type) {
569
+    protected function validateExtension($ext, $type)
570
+    {
510 571
         $ext = trim(strtolower($ext));
511
-        if (!isset($this->types[$type]))
512
-            return false;
572
+        if (!isset($this->types[$type])) {
573
+                    return false;
574
+        }
513 575
 
514 576
         $exts = strtolower(text::clearWhitespaces($this->config['deniedExts']));
515 577
         if (strlen($exts)) {
516 578
             $exts = explode(" ", $exts);
517
-            if (in_array($ext, $exts))
518
-                return false;
579
+            if (in_array($ext, $exts)) {
580
+                            return false;
581
+            }
519 582
         }
520 583
 
521 584
         $exts = trim($this->types[$type]);
522
-        if (!strlen($exts) || substr($exts, 0, 1) == "*")
523
-            return true;
585
+        if (!strlen($exts) || substr($exts, 0, 1) == "*") {
586
+                    return true;
587
+        }
524 588
 
525 589
         if (substr($exts, 0, 1) == "!") {
526 590
             $exts = explode(" ", trim(strtolower(substr($exts, 1))));
@@ -531,26 +595,32 @@  discard block
 block discarded – undo
531 595
         return in_array($ext, $exts);
532 596
     }
533 597
 
534
-    protected function getTypeFromPath($path) {
598
+    protected function getTypeFromPath($path)
599
+    {
535 600
         return preg_match('/^([^\/]*)\/.*$/', $path, $patt)
536 601
             ? $patt[1] : $path;
537 602
     }
538 603
 
539
-    protected function removeTypeFromPath($path) {
604
+    protected function removeTypeFromPath($path)
605
+    {
540 606
         return preg_match('/^[^\/]*\/(.*)$/', $path, $patt)
541 607
             ? $patt[1] : "";
542 608
     }
543 609
 
544
-    protected function imageResize($image, $file=null) {
610
+    protected function imageResize($image, $file=null)
611
+    {
545 612
 
546 613
         if (!($image instanceof image)) {
547 614
             $img = image::factory($this->imageDriver, $image);
548
-            if ($img->initError) return false;
615
+            if ($img->initError) {
616
+                return false;
617
+            }
549 618
             $file = $image;
550
-        } elseif ($file === null)
551
-            return false;
552
-        else
553
-            $img = $image;
619
+        } elseif ($file === null) {
620
+                    return false;
621
+        } else {
622
+                    $img = $image;
623
+        }
554 624
 
555 625
         $orientation = 1;
556 626
         if (function_exists("exif_read_data")) {
@@ -572,8 +642,9 @@  discard block
 block discarded – undo
572 642
             )
573 643
             ) &&
574 644
             ($orientation == 1)
575
-        )
576
-            return true;
645
+        ) {
646
+                    return true;
647
+        }
577 648
 
578 649
 
579 650
         // PROPORTIONAL RESIZE
@@ -593,15 +664,17 @@  discard block
 block discarded – undo
593 664
                 $width = $img->getPropWidth($height);
594 665
             }
595 666
 
596
-            if (isset($width) && isset($height) && !$img->resize($width, $height))
597
-                return false;
667
+            if (isset($width) && isset($height) && !$img->resize($width, $height)) {
668
+                            return false;
669
+            }
598 670
 
599 671
         // RESIZE TO FIT
600 672
         } elseif (
601 673
             $this->config['maxImageWidth'] && $this->config['maxImageHeight'] &&
602 674
             !$img->resizeFit($this->config['maxImageWidth'], $this->config['maxImageHeight'])
603
-        )
604
-            return false;
675
+        ) {
676
+                    return false;
677
+        }
605 678
 
606 679
         // AUTO FLIP AND ROTATE FROM EXIF
607 680
         if ((($orientation == 2) && !$img->flipHorizontal()) ||
@@ -611,11 +684,13 @@  discard block
 block discarded – undo
611 684
             (($orientation == 6) && !$img->rotate(90)) ||
612 685
             (($orientation == 7) && (!$img->flipHorizontal() || !$img->rotate(90))) ||
613 686
             (($orientation == 8) && !$img->rotate(270))
614
-        )
615
-            return false;
616
-        if (($orientation >= 2) && ($orientation <= 8) && ($this->imageDriver == "imagick"))
617
-            try {
687
+        ) {
688
+                    return false;
689
+        }
690
+        if (($orientation >= 2) && ($orientation <= 8) && ($this->imageDriver == "imagick")) {
691
+                    try {
618 692
                 $img->image->setImageProperty('exif:Orientation', "1");
693
+        }
619 694
             } catch (Exception $e) {}
620 695
         
621 696
         // WATERMARK
@@ -646,22 +721,26 @@  discard block
 block discarded – undo
646 721
 
647 722
     }
648 723
 
649
-    protected function makeThumb($file, $overwrite=true) {
724
+    protected function makeThumb($file, $overwrite=true)
725
+    {
650 726
         $img = image::factory($this->imageDriver, $file);
651 727
 
652 728
         // Drop files which are not images
653
-        if ($img->initError)
654
-            return true;
729
+        if ($img->initError) {
730
+                    return true;
731
+        }
655 732
 
656 733
         $thumb = substr($file, strlen($this->config['uploadDir']));
657 734
         $thumb = $this->config['uploadDir'] . "/" . $this->config['thumbsDir'] . "/" . $thumb;
658 735
         $thumb = path::normalize($thumb);
659 736
         $thumbDir = dirname($thumb);
660
-        if (!is_dir($thumbDir) && !@mkdir($thumbDir, $this->config['dirPerms'], true))
661
-            return false;
737
+        if (!is_dir($thumbDir) && !@mkdir($thumbDir, $this->config['dirPerms'], true)) {
738
+                    return false;
739
+        }
662 740
 
663
-        if (!$overwrite && is_file($thumb))
664
-            return true;
741
+        if (!$overwrite && is_file($thumb)) {
742
+                    return true;
743
+        }
665 744
 
666 745
         // Images with smaller resolutions than thumbnails
667 746
         /*if (($img->width <= $this->config['thumbWidth']) &&
@@ -674,8 +753,9 @@  discard block
 block discarded – undo
674 753
 
675 754
         // Resize image
676 755
         } else */
677
-        if (!$img->resizeFit($this->config['thumbWidth'], $this->config['thumbHeight']))
678
-            return false;
756
+        if (!$img->resizeFit($this->config['thumbWidth'], $this->config['thumbHeight'])) {
757
+                    return false;
758
+        }
679 759
 
680 760
         if ( $this->imageDriver == 'gd' ) {
681 761
             $width  = imagesx( $img->image );
@@ -697,7 +777,8 @@  discard block
 block discarded – undo
697 777
         ));
698 778
     }
699 779
 
700
-    protected function localize($langCode) {
780
+    protected function localize($langCode)
781
+    {
701 782
         require "lang/{$langCode}.php";
702 783
         setlocale(LC_ALL, $lang['_locale']);
703 784
         $this->charset = $lang['_charset'];
@@ -712,27 +793,34 @@  discard block
 block discarded – undo
712 793
         $this->labels = $lang;
713 794
     }
714 795
 
715
-    protected function label($string, array $data=null) {
796
+    protected function label($string, array $data=null)
797
+    {
716 798
         $return = isset($this->labels[$string]) ? $this->labels[$string] : $string;
717
-        if (is_array($data))
718
-            foreach ($data as $key => $val)
799
+        if (is_array($data)) {
800
+                    foreach ($data as $key => $val)
719 801
                 $return = str_replace("{{$key}}", $val, $return);
802
+        }
720 803
         return $return;
721 804
     }
722 805
 
723
-    protected function backMsg($message, array $data=null) {
806
+    protected function backMsg($message, array $data=null)
807
+    {
724 808
         $message = $this->label($message, $data);
725
-        if (isset($this->file['tmp_name']) && file_exists($this->file['tmp_name']))
726
-            @unlink($this->file['tmp_name']);
809
+        if (isset($this->file['tmp_name']) && file_exists($this->file['tmp_name'])) {
810
+                    @unlink($this->file['tmp_name']);
811
+        }
727 812
         $this->callBack("", $message);
728 813
         die;
729 814
     }
730 815
 
731
-    protected function callBack($url, $message="") {
816
+    protected function callBack($url, $message="")
817
+    {
732 818
         $message = text::jsValue($message);
733 819
         $CKfuncNum = isset($this->opener['CKEditor']['funcNum'])
734 820
             ? $this->opener['CKEditor']['funcNum'] : 0;
735
-        if (!$CKfuncNum) $CKfuncNum = 0;
821
+        if (!$CKfuncNum) {
822
+            $CKfuncNum = 0;
823
+        }
736 824
         header("Content-Type: text/html; charset={$this->charset}");
737 825
 
738 826
 ?><html>
@@ -769,7 +857,8 @@  discard block
 block discarded – undo
769 857
 
770 858
     }
771 859
 
772
-    protected function get_htaccess() {
860
+    protected function get_htaccess()
861
+    {
773 862
         return "<IfModule mod_php4.c>
774 863
   php_value engine off
775 864
 </IfModule>
Please login to merge, or discard this patch.
Upper-Lower-Casing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -376,10 +376,10 @@
 block discarded – undo
376 376
 			if ($properties = $modx->db->getValue($res)) {
377 377
 				$properties = $modx->parseProperties($properties, 'TransAlias', 'plugin');
378 378
 			} else {
379
-				$properties = NULL;
379
+				$properties = null;
380 380
 			}
381 381
 		} else {
382
-			$properties = NULL;
382
+			$properties = null;
383 383
 		}
384 384
 		return $properties;
385 385
 	}
Please login to merge, or discard this patch.
manager/media/browser/mcpuk/lib/class_fastImage.php 4 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -183,6 +183,9 @@  discard block
 block discarded – undo
183 183
 	}
184 184
 
185 185
 
186
+	/**
187
+	 * @param integer $n
188
+	 */
186 189
 	private function getChars($n)
187 190
 	{
188 191
 		$response = null;
@@ -225,6 +228,9 @@  discard block
 block discarded – undo
225 228
 	}
226 229
 
227 230
 
231
+	/**
232
+	 * @param false|string $str
233
+	 */
228 234
 	private function readInt($str)
229 235
 	{
230 236
 		$size = unpack("C*", $str);
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 					{
151 151
 						$state = 'skipframe';
152 152
 					}
153
-					elseif (in_array($b, array_merge(range(0xC0,0xC3), range(0xC5,0xC7), range(0xC9,0xCB), range(0xCD,0xCF))))
153
+					elseif (in_array($b, array_merge(range(0xC0, 0xC3), range(0xC5, 0xC7), range(0xC9, 0xCB), range(0xCD, 0xCF))))
154 154
 					{
155 155
 						$state = 'readsize';
156 156
 					}
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 		$response = null;
189 189
 
190 190
 		// do we need more data?
191
-		if ($this->strpos + $n -1 >= strlen($this->str))
191
+		if ($this->strpos + $n - 1 >= strlen($this->str))
192 192
 		{
193 193
 			$end = ($this->strpos + $n);
194 194
 
Please login to merge, or discard this patch.
Indentation   +218 added lines, -218 removed lines patch added patch discarded remove patch
@@ -13,227 +13,227 @@
 block discarded – undo
13 13
 
14 14
 class fastImage
15 15
 {
16
-	private $strpos = 0;
17
-	private $str;
18
-	private $uri;
19
-	private $type;
20
-	private $handle;
16
+    private $strpos = 0;
17
+    private $str;
18
+    private $uri;
19
+    private $type;
20
+    private $handle;
21 21
 
22
-	public function __construct($uri = null)
23
-	{
24
-		if ($uri) $this->load($uri);
25
-	}
22
+    public function __construct($uri = null)
23
+    {
24
+        if ($uri) $this->load($uri);
25
+    }
26 26
 
27 27
 
28
-	public function load($uri)
29
-	{
30
-		if ($this->handle) $this->close();
31
-
32
-		$this->uri = $uri;
33
-		$this->handle = fopen($uri, 'r');
34
-	}
35
-
36
-
37
-	public function close()
38
-	{
39
-		if (is_resource($this->handle)) fclose($this->handle);
40
-	}
28
+    public function load($uri)
29
+    {
30
+        if ($this->handle) $this->close();
31
+
32
+        $this->uri = $uri;
33
+        $this->handle = fopen($uri, 'r');
34
+    }
35
+
36
+
37
+    public function close()
38
+    {
39
+        if (is_resource($this->handle)) fclose($this->handle);
40
+    }
41 41
 
42 42
 
43
-	public function getSize()
44
-	{
45
-		$this->strpos = 0;
46
-		if ($this->getType())
47
-		{
48
-			return array_values($this->parseSize());
49
-		}
50
-
51
-		return false;
52
-	}
53
-
54
-
55
-	public function getType()
56
-	{
57
-		$this->strpos = 0;
58
-
59
-		if (!$this->type)
60
-		{
61
-			switch ($this->getChars(2))
62
-			{
63
-				case "BM":
64
-					return $this->type = 'bmp';
65
-				case "GI":
66
-					return $this->type = 'gif';
67
-				case chr(0xFF).chr(0xd8):
68
-					return $this->type = 'jpeg';
69
-				case chr(0x89).'P':
70
-					return $this->type = 'png';
71
-				default:
72
-					return false;
73
-			}
74
-		}
75
-
76
-		return $this->type;
77
-	}
78
-
79
-
80
-	private function parseSize()
81
-	{
82
-		$this->strpos = 0;
83
-
84
-		switch ($this->type)
85
-		{
86
-			case 'png':
87
-				return $this->parseSizeForPNG();
88
-			case 'gif':
89
-				return $this->parseSizeForGIF();
90
-			case 'bmp':
91
-				return $this->parseSizeForBMP();
92
-			case 'jpeg':
93
-				return $this->parseSizeForJPEG();
94
-		}
95
-
96
-		return null;
97
-	}
98
-
99
-
100
-	private function parseSizeForPNG()
101
-	{
102
-		$chars = $this->getChars(25);
103
-
104
-		return unpack("N*", substr($chars, 16, 8));
105
-	}
106
-
107
-
108
-	private function parseSizeForGIF()
109
-	{
110
-		$chars = $this->getChars(11);
111
-
112
-		return unpack("S*", substr($chars, 6, 4));
113
-	}
114
-
115
-
116
-	private function parseSizeForBMP()
117
-	{
118
-		$chars = $this->getChars(29);
119
-	 	$chars = substr($chars, 14, 14);
120
-		$type = unpack('C', $chars);
121
-
122
-		return (reset($type) == 40) ? unpack('L*', substr($chars, 4)) : unpack('L*', substr($chars, 4, 8));
123
-	}
124
-
125
-
126
-	private function parseSizeForJPEG()
127
-	{
128
-		$state = null;
129
-
130
-		while (true)
131
-		{
132
-			switch ($state)
133
-			{
134
-				default:
135
-					$this->getChars(2);
136
-					$state = 'started';
137
-					break;
138
-
139
-				case 'started':
140
-					$b = $this->getByte();
141
-					if ($b === false) return false;
142
-
143
-					$state = $b == 0xFF ? 'sof' : 'started';
144
-					break;
145
-
146
-				case 'sof':
147
-					$b = $this->getByte();
148
-					if (in_array($b, range(0xe0, 0xef)))
149
-					{
150
-						$state = 'skipframe';
151
-					}
152
-					elseif (in_array($b, array_merge(range(0xC0,0xC3), range(0xC5,0xC7), range(0xC9,0xCB), range(0xCD,0xCF))))
153
-					{
154
-						$state = 'readsize';
155
-					}
156
-					elseif ($b == 0xFF)
157
-					{
158
-						$state = 'sof';
159
-					}
160
-					else
161
-					{
162
-						$state = 'skipframe';
163
-					}
164
-					break;
165
-
166
-				case 'skipframe':
167
-					$skip = $this->readInt($this->getChars(2)) - 2;
168
-					$state = 'doskip';
169
-					break;
170
-
171
-				case 'doskip':
172
-					$this->getChars($skip);
173
-					$state = 'started';
174
-					break;
175
-
176
-				case 'readsize':
177
-					$c = $this->getChars(7);
178
-
179
-					return array($this->readInt(substr($c, 5, 2)), $this->readInt(substr($c, 3, 2)));
180
-			}
181
-		}
182
-	}
183
-
184
-
185
-	private function getChars($n)
186
-	{
187
-		$response = null;
188
-
189
-		// do we need more data?
190
-		if ($this->strpos + $n -1 >= strlen($this->str))
191
-		{
192
-			$end = ($this->strpos + $n);
193
-
194
-			while (strlen($this->str) < $end && $response !== false)
195
-			{
196
-				// read more from the file handle
197
-				$need = $end - ftell($this->handle);
198
-
199
-				if ($response = fread($this->handle, $need))
200
-				{
201
-					$this->str .= $response;
202
-				}
203
-				else
204
-				{
205
-					return false;
206
-				}
207
-			}
208
-		}
209
-
210
-		$result = substr($this->str, $this->strpos, $n);
211
-		$this->strpos += $n;
212
-
213
-		// we are dealing with bytes here, so force the encoding
214
-		return mb_convert_encoding($result, "8BIT");
215
-	}
216
-
217
-
218
-	private function getByte()
219
-	{
220
-		$c = $this->getChars(1);
221
-		$b = unpack("C", $c);
222
-
223
-		return reset($b);
224
-	}
225
-
226
-
227
-	private function readInt($str)
228
-	{
229
-		$size = unpack("C*", $str);
230
-
231
-	    	return ($size[1] << 8) + $size[2];
232
-	}
233
-
234
-
235
-	public function __destruct()
236
-	{
237
-		$this->close();
238
-	}
43
+    public function getSize()
44
+    {
45
+        $this->strpos = 0;
46
+        if ($this->getType())
47
+        {
48
+            return array_values($this->parseSize());
49
+        }
50
+
51
+        return false;
52
+    }
53
+
54
+
55
+    public function getType()
56
+    {
57
+        $this->strpos = 0;
58
+
59
+        if (!$this->type)
60
+        {
61
+            switch ($this->getChars(2))
62
+            {
63
+                case "BM":
64
+                    return $this->type = 'bmp';
65
+                case "GI":
66
+                    return $this->type = 'gif';
67
+                case chr(0xFF).chr(0xd8):
68
+                    return $this->type = 'jpeg';
69
+                case chr(0x89).'P':
70
+                    return $this->type = 'png';
71
+                default:
72
+                    return false;
73
+            }
74
+        }
75
+
76
+        return $this->type;
77
+    }
78
+
79
+
80
+    private function parseSize()
81
+    {
82
+        $this->strpos = 0;
83
+
84
+        switch ($this->type)
85
+        {
86
+            case 'png':
87
+                return $this->parseSizeForPNG();
88
+            case 'gif':
89
+                return $this->parseSizeForGIF();
90
+            case 'bmp':
91
+                return $this->parseSizeForBMP();
92
+            case 'jpeg':
93
+                return $this->parseSizeForJPEG();
94
+        }
95
+
96
+        return null;
97
+    }
98
+
99
+
100
+    private function parseSizeForPNG()
101
+    {
102
+        $chars = $this->getChars(25);
103
+
104
+        return unpack("N*", substr($chars, 16, 8));
105
+    }
106
+
107
+
108
+    private function parseSizeForGIF()
109
+    {
110
+        $chars = $this->getChars(11);
111
+
112
+        return unpack("S*", substr($chars, 6, 4));
113
+    }
114
+
115
+
116
+    private function parseSizeForBMP()
117
+    {
118
+        $chars = $this->getChars(29);
119
+            $chars = substr($chars, 14, 14);
120
+        $type = unpack('C', $chars);
121
+
122
+        return (reset($type) == 40) ? unpack('L*', substr($chars, 4)) : unpack('L*', substr($chars, 4, 8));
123
+    }
124
+
125
+
126
+    private function parseSizeForJPEG()
127
+    {
128
+        $state = null;
129
+
130
+        while (true)
131
+        {
132
+            switch ($state)
133
+            {
134
+                default:
135
+                    $this->getChars(2);
136
+                    $state = 'started';
137
+                    break;
138
+
139
+                case 'started':
140
+                    $b = $this->getByte();
141
+                    if ($b === false) return false;
142
+
143
+                    $state = $b == 0xFF ? 'sof' : 'started';
144
+                    break;
145
+
146
+                case 'sof':
147
+                    $b = $this->getByte();
148
+                    if (in_array($b, range(0xe0, 0xef)))
149
+                    {
150
+                        $state = 'skipframe';
151
+                    }
152
+                    elseif (in_array($b, array_merge(range(0xC0,0xC3), range(0xC5,0xC7), range(0xC9,0xCB), range(0xCD,0xCF))))
153
+                    {
154
+                        $state = 'readsize';
155
+                    }
156
+                    elseif ($b == 0xFF)
157
+                    {
158
+                        $state = 'sof';
159
+                    }
160
+                    else
161
+                    {
162
+                        $state = 'skipframe';
163
+                    }
164
+                    break;
165
+
166
+                case 'skipframe':
167
+                    $skip = $this->readInt($this->getChars(2)) - 2;
168
+                    $state = 'doskip';
169
+                    break;
170
+
171
+                case 'doskip':
172
+                    $this->getChars($skip);
173
+                    $state = 'started';
174
+                    break;
175
+
176
+                case 'readsize':
177
+                    $c = $this->getChars(7);
178
+
179
+                    return array($this->readInt(substr($c, 5, 2)), $this->readInt(substr($c, 3, 2)));
180
+            }
181
+        }
182
+    }
183
+
184
+
185
+    private function getChars($n)
186
+    {
187
+        $response = null;
188
+
189
+        // do we need more data?
190
+        if ($this->strpos + $n -1 >= strlen($this->str))
191
+        {
192
+            $end = ($this->strpos + $n);
193
+
194
+            while (strlen($this->str) < $end && $response !== false)
195
+            {
196
+                // read more from the file handle
197
+                $need = $end - ftell($this->handle);
198
+
199
+                if ($response = fread($this->handle, $need))
200
+                {
201
+                    $this->str .= $response;
202
+                }
203
+                else
204
+                {
205
+                    return false;
206
+                }
207
+            }
208
+        }
209
+
210
+        $result = substr($this->str, $this->strpos, $n);
211
+        $this->strpos += $n;
212
+
213
+        // we are dealing with bytes here, so force the encoding
214
+        return mb_convert_encoding($result, "8BIT");
215
+    }
216
+
217
+
218
+    private function getByte()
219
+    {
220
+        $c = $this->getChars(1);
221
+        $b = unpack("C", $c);
222
+
223
+        return reset($b);
224
+    }
225
+
226
+
227
+    private function readInt($str)
228
+    {
229
+        $size = unpack("C*", $str);
230
+
231
+            return ($size[1] << 8) + $size[2];
232
+    }
233
+
234
+
235
+    public function __destruct()
236
+    {
237
+        $this->close();
238
+    }
239 239
 }
Please login to merge, or discard this patch.
Braces   +26 added lines, -36 removed lines patch added patch discarded remove patch
@@ -21,13 +21,17 @@  discard block
 block discarded – undo
21 21
 
22 22
 	public function __construct($uri = null)
23 23
 	{
24
-		if ($uri) $this->load($uri);
24
+		if ($uri) {
25
+		    $this->load($uri);
26
+		}
25 27
 	}
26 28
 
27 29
 
28 30
 	public function load($uri)
29 31
 	{
30
-		if ($this->handle) $this->close();
32
+		if ($this->handle) {
33
+		    $this->close();
34
+		}
31 35
 
32 36
 		$this->uri = $uri;
33 37
 		$this->handle = fopen($uri, 'r');
@@ -36,15 +40,16 @@  discard block
 block discarded – undo
36 40
 
37 41
 	public function close()
38 42
 	{
39
-		if (is_resource($this->handle)) fclose($this->handle);
43
+		if (is_resource($this->handle)) {
44
+		    fclose($this->handle);
45
+		}
40 46
 	}
41 47
 
42 48
 
43 49
 	public function getSize()
44 50
 	{
45 51
 		$this->strpos = 0;
46
-		if ($this->getType())
47
-		{
52
+		if ($this->getType()) {
48 53
 			return array_values($this->parseSize());
49 54
 		}
50 55
 
@@ -56,10 +61,8 @@  discard block
 block discarded – undo
56 61
 	{
57 62
 		$this->strpos = 0;
58 63
 
59
-		if (!$this->type)
60
-		{
61
-			switch ($this->getChars(2))
62
-			{
64
+		if (!$this->type) {
65
+			switch ($this->getChars(2)) {
63 66
 				case "BM":
64 67
 					return $this->type = 'bmp';
65 68
 				case "GI":
@@ -81,8 +84,7 @@  discard block
 block discarded – undo
81 84
 	{
82 85
 		$this->strpos = 0;
83 86
 
84
-		switch ($this->type)
85
-		{
87
+		switch ($this->type) {
86 88
 			case 'png':
87 89
 				return $this->parseSizeForPNG();
88 90
 			case 'gif':
@@ -127,10 +129,8 @@  discard block
 block discarded – undo
127 129
 	{
128 130
 		$state = null;
129 131
 
130
-		while (true)
131
-		{
132
-			switch ($state)
133
-			{
132
+		while (true) {
133
+			switch ($state) {
134 134
 				default:
135 135
 					$this->getChars(2);
136 136
 					$state = 'started';
@@ -138,27 +138,22 @@  discard block
 block discarded – undo
138 138
 
139 139
 				case 'started':
140 140
 					$b = $this->getByte();
141
-					if ($b === false) return false;
141
+					if ($b === false) {
142
+					    return false;
143
+					}
142 144
 
143 145
 					$state = $b == 0xFF ? 'sof' : 'started';
144 146
 					break;
145 147
 
146 148
 				case 'sof':
147 149
 					$b = $this->getByte();
148
-					if (in_array($b, range(0xe0, 0xef)))
149
-					{
150
+					if (in_array($b, range(0xe0, 0xef))) {
150 151
 						$state = 'skipframe';
151
-					}
152
-					elseif (in_array($b, array_merge(range(0xC0,0xC3), range(0xC5,0xC7), range(0xC9,0xCB), range(0xCD,0xCF))))
153
-					{
152
+					} elseif (in_array($b, array_merge(range(0xC0,0xC3), range(0xC5,0xC7), range(0xC9,0xCB), range(0xCD,0xCF)))) {
154 153
 						$state = 'readsize';
155
-					}
156
-					elseif ($b == 0xFF)
157
-					{
154
+					} elseif ($b == 0xFF) {
158 155
 						$state = 'sof';
159
-					}
160
-					else
161
-					{
156
+					} else {
162 157
 						$state = 'skipframe';
163 158
 					}
164 159
 					break;
@@ -187,21 +182,16 @@  discard block
 block discarded – undo
187 182
 		$response = null;
188 183
 
189 184
 		// do we need more data?
190
-		if ($this->strpos + $n -1 >= strlen($this->str))
191
-		{
185
+		if ($this->strpos + $n -1 >= strlen($this->str)) {
192 186
 			$end = ($this->strpos + $n);
193 187
 
194
-			while (strlen($this->str) < $end && $response !== false)
195
-			{
188
+			while (strlen($this->str) < $end && $response !== false) {
196 189
 				// read more from the file handle
197 190
 				$need = $end - ftell($this->handle);
198 191
 
199
-				if ($response = fread($this->handle, $need))
200
-				{
192
+				if ($response = fread($this->handle, $need)) {
201 193
 					$this->str .= $response;
202
-				}
203
-				else
204
-				{
194
+				} else {
205 195
 					return false;
206 196
 				}
207 197
 			}
Please login to merge, or discard this patch.