Completed
Push — develop ( 75b835...a38a21 )
by Maxim
09:33 queued 04:23
created
manager/includes/extenders/ex_phpcompat.inc.php 1 patch
Braces   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -5,13 +5,13 @@
 block discarded – undo
5 5
  * Time: 12:25
6 6
  */
7 7
 
8
-if (isset($this->phpcompat) && is_object($this->phpcompat)){
8
+if (isset($this->phpcompat) && is_object($this->phpcompat)) {
9 9
     return true;
10 10
 }
11 11
 
12
-if (!include_once(MODX_MANAGER_PATH . 'includes/extenders/phpcompat.class.inc.php')){
12
+if (!include_once(MODX_MANAGER_PATH . 'includes/extenders/phpcompat.class.inc.php')) {
13 13
     return false;
14
-}else{
14
+} else {
15 15
     $this->phpcompat = new PHPCOMPAT;
16 16
     return true;
17 17
 }
Please login to merge, or discard this patch.
manager/includes/extenders/ex_phpass.inc.php 1 patch
Braces   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -5,13 +5,13 @@
 block discarded – undo
5 5
  * Time: 19:14
6 6
  */
7 7
 
8
-if (isset($this->phpass) && is_object($this->phpass)){
8
+if (isset($this->phpass) && is_object($this->phpass)) {
9 9
     return true;
10 10
 }
11 11
 
12
-if (!include_once(MODX_MANAGER_PATH . 'includes/extenders/phpass.class.inc.php')){
12
+if (!include_once(MODX_MANAGER_PATH . 'includes/extenders/phpass.class.inc.php')) {
13 13
     return false;
14
-}else{
14
+} else {
15 15
     $this->phpass = new PasswordHash;
16 16
     return true;
17 17
 }
18 18
\ No newline at end of file
Please login to merge, or discard this patch.
manager/includes/extenders/dbapi.mysqli.class.inc.php 1 patch
Braces   +168 added lines, -70 removed lines patch added patch discarded remove patch
@@ -1,11 +1,13 @@  discard block
 block discarded – undo
1 1
 <?php
2
-class DBAPI {
2
+class DBAPI
3
+{
3 4
 	var $conn;
4 5
 	var $config;
5 6
 	var $lastQuery;
6 7
 	var $isConnected;
7 8
 
8
-	function __construct($host='', $dbase='', $uid='', $pwd='', $pre=NULL, $charset='', $connection_method='SET CHARACTER SET') {
9
+	function __construct($host='', $dbase='', $uid='', $pwd='', $pre=NULL, $charset='', $connection_method='SET CHARACTER SET')
10
+	{
9 11
 		$this->config['host'] = $host ? $host : $GLOBALS['database_server'];
10 12
 		$this->config['dbase'] = $dbase ? $dbase : $GLOBALS['dbase'];
11 13
 		$this->config['user'] = $uid ? $uid : $GLOBALS['database_user'];
@@ -15,7 +17,8 @@  discard block
 block discarded – undo
15 17
 		$this->config['table_prefix'] = ($pre !== NULL) ? $pre : $GLOBALS['table_prefix'];
16 18
 	}
17 19
 
18
-	function connect($host = '', $dbase = '', $uid = '', $pwd = '', $tmp = 0) {
20
+	function connect($host = '', $dbase = '', $uid = '', $pwd = '', $tmp = 0)
21
+	{
19 22
 		global $modx;
20 23
 		$uid     = $uid   ? $uid   : $this->config['user'];
21 24
 		$pwd     = $pwd   ? $pwd   : $this->config['pass'];
@@ -63,15 +66,19 @@  discard block
 block discarded – undo
63 66
 		}
64 67
 	}
65 68
 
66
-	function disconnect() {
69
+	function disconnect()
70
+	{
67 71
 		$this->conn->close();
68 72
 		$this->conn = null;
69 73
 		$this->isConnected = false;
70 74
 	}
71 75
 
72
-	function escape($s, $safecount=0) {
76
+	function escape($s, $safecount=0)
77
+	{
73 78
 		$safecount++;
74
-		if (1000<$safecount) exit("Too many loops '{$safecount}'");
79
+		if (1000<$safecount) {
80
+		    exit("Too many loops '{$safecount}'");
81
+		}
75 82
 		if (empty ($this->conn) || !is_object($this->conn)) {
76 83
 			$this->connect();
77 84
 		}
@@ -89,16 +96,21 @@  discard block
 block discarded – undo
89 96
 		return $s;
90 97
 	}
91 98
 
92
-	function query($sql,$watchError=true) {
99
+	function query($sql,$watchError=true)
100
+	{
93 101
 		global $modx;
94 102
 		if (empty ($this->conn) || !is_object($this->conn)) {
95 103
 			$this->connect();
96 104
 		}
97 105
 		$tstart = $modx->getMicroTime();
98
-		if(is_array($sql)) $sql = join("\n", $sql);
106
+		if(is_array($sql)) {
107
+		    $sql = join("\n", $sql);
108
+		}
99 109
 		$this->lastQuery = $sql;
100 110
 		if (!($result = $this->conn->query($sql))) {
101
-			if(!$watchError) return;
111
+			if(!$watchError) {
112
+			    return;
113
+			}
102 114
             switch(mysqli_errno($this->conn)) {
103 115
                 case 1054:
104 116
                 case 1060:
@@ -117,15 +129,26 @@  discard block
 block discarded – undo
117 129
 				$debug = debug_backtrace();
118 130
 				array_shift($debug);
119 131
 				$debug_path = array();
120
-				foreach ($debug as $line) $debug_path[] = $line['function'];
132
+				foreach ($debug as $line) {
133
+				    $debug_path[] = $line['function'];
134
+				}
121 135
 				$debug_path = implode(' > ', array_reverse($debug_path));
122 136
 				$modx->queryCode .= "<fieldset style='text-align:left'><legend>Query " . ($modx->executedQueries + 1) . " - " . sprintf("%2.2f ms", $totaltime*1000) . "</legend>";
123 137
 				$modx->queryCode .= $sql . '<br><br>';
124
-				if ($modx->event->name) $modx->queryCode .= 'Current Event  => ' . $modx->event->name . '<br>';
125
-				if ($modx->event->activePlugin) $modx->queryCode .= 'Current Plugin => ' . $modx->event->activePlugin . '<br>';
126
-				if ($modx->currentSnippet) $modx->queryCode .= 'Current Snippet => ' . $modx->currentSnippet . '<br>';
127
-				if (stripos($sql, 'select')===0) $modx->queryCode .= 'Record Count => ' . $this->getRecordCount($result) . '<br>';
128
-				else $modx->queryCode .= 'Affected Rows => ' . $this->getAffectedRows() . '<br>';
138
+				if ($modx->event->name) {
139
+				    $modx->queryCode .= 'Current Event  => ' . $modx->event->name . '<br>';
140
+				}
141
+				if ($modx->event->activePlugin) {
142
+				    $modx->queryCode .= 'Current Plugin => ' . $modx->event->activePlugin . '<br>';
143
+				}
144
+				if ($modx->currentSnippet) {
145
+				    $modx->queryCode .= 'Current Snippet => ' . $modx->currentSnippet . '<br>';
146
+				}
147
+				if (stripos($sql, 'select')===0) {
148
+				    $modx->queryCode .= 'Record Count => ' . $this->getRecordCount($result) . '<br>';
149
+				} else {
150
+				    $modx->queryCode .= 'Affected Rows => ' . $this->getAffectedRows() . '<br>';
151
+				}
129 152
 				$modx->queryCode .= 'Functions Path => ' . $debug_path . '<br>';
130 153
 				$modx->queryCode .= "</fieldset><br />";
131 154
 			}
@@ -134,7 +157,8 @@  discard block
 block discarded – undo
134 157
 		}
135 158
 	}
136 159
 
137
-	function delete($from, $where='', $orderby='', $limit = '') {
160
+	function delete($from, $where='', $orderby='', $limit = '')
161
+	{
138 162
 		global $modx;
139 163
 		if (!$from) {
140 164
 			$modx->messageQuit("Empty \$from parameters in DBAPI::delete().");
@@ -143,19 +167,32 @@  discard block
 block discarded – undo
143 167
 			$where   = trim($where);
144 168
 			$orderby = trim($orderby);
145 169
 			$limit   = trim($limit);
146
-			if($where!==''    && stripos($where,  'WHERE')!==0)    $where   = "WHERE {$where}";
147
-			if($orderby!== '' && stripos($orderby,'ORDER BY')!==0) $orderby = "ORDER BY {$orderby}";
148
-			if($limit!== ''   && stripos($limit,  'LIMIT')!==0)    $limit   = "LIMIT {$limit}";
170
+			if($where!==''    && stripos($where,  'WHERE')!==0) {
171
+			    $where   = "WHERE {$where}";
172
+			}
173
+			if($orderby!== '' && stripos($orderby,'ORDER BY')!==0) {
174
+			    $orderby = "ORDER BY {$orderby}";
175
+			}
176
+			if($limit!== ''   && stripos($limit,  'LIMIT')!==0) {
177
+			    $limit   = "LIMIT {$limit}";
178
+			}
149 179
 			return $this->query("DELETE FROM {$from} {$where} {$orderby} {$limit}");
150 180
 		}
151 181
 	}
152 182
 
153
-	function select($fields = "*", $from = "", $where = "", $orderby = "", $limit = "") {
183
+	function select($fields = "*", $from = "", $where = "", $orderby = "", $limit = "")
184
+	{
154 185
 		global $modx;
155 186
 		
156
-		if(is_array($fields)) $fields = $this->_getFieldsStringFromArray($fields);
157
-		if(is_array($from))   $from   = $this->_getFromStringFromArray($from);
158
-		if(is_array($where))  $where  = join(' ', $where);
187
+		if(is_array($fields)) {
188
+		    $fields = $this->_getFieldsStringFromArray($fields);
189
+		}
190
+		if(is_array($from)) {
191
+		    $from   = $this->_getFromStringFromArray($from);
192
+		}
193
+		if(is_array($where)) {
194
+		    $where  = join(' ', $where);
195
+		}
159 196
 		
160 197
 		if (!$from) {
161 198
 			$modx->messageQuit("Empty \$from parameters in DBAPI::select().");
@@ -167,13 +204,20 @@  discard block
 block discarded – undo
167 204
         $where   = trim($where);
168 205
         $orderby = trim($orderby);
169 206
         $limit   = trim($limit);
170
-        if($where!==''   && stripos($where,'WHERE')!==0)   $where   = "WHERE {$where}";
171
-        if($orderby!=='' && stripos($orderby,'ORDER')!==0) $orderby = "ORDER BY {$orderby}";
172
-        if($limit!==''   && stripos($limit,'LIMIT')!==0)   $limit   = "LIMIT {$limit}";
207
+        if($where!==''   && stripos($where,'WHERE')!==0) {
208
+            $where   = "WHERE {$where}";
209
+        }
210
+        if($orderby!=='' && stripos($orderby,'ORDER')!==0) {
211
+            $orderby = "ORDER BY {$orderby}";
212
+        }
213
+        if($limit!==''   && stripos($limit,'LIMIT')!==0) {
214
+            $limit   = "LIMIT {$limit}";
215
+        }
173 216
 		return $this->query("SELECT {$fields} FROM {$from} {$where} {$orderby} {$limit}");
174 217
 	}
175 218
 
176
-	function update($fields, $table, $where = "") {
219
+	function update($fields, $table, $where = "")
220
+	{
177 221
 		global $modx;
178 222
 		if (!$table) {
179 223
 			$modx->messageQuit("Empty \$table parameter in DBAPI::update().");
@@ -181,9 +225,9 @@  discard block
 block discarded – undo
181 225
 			$table = $this->replaceFullTableName($table);
182 226
 			if (is_array($fields)) {
183 227
 				foreach ($fields as $key => $value) {
184
-					if(is_null($value) || strtolower($value) === 'null'){
228
+					if(is_null($value) || strtolower($value) === 'null') {
185 229
 						$flds = 'NULL';
186
-					}else{
230
+					} else {
187 231
 						$flds = "'" . $value . "'";
188 232
 					}
189 233
 					$fields[$key] = "`{$key}` = ".$flds;
@@ -191,12 +235,15 @@  discard block
 block discarded – undo
191 235
 				$fields = implode(",", $fields);
192 236
 			}
193 237
 			$where = trim($where);
194
-			if($where!=='' && stripos($where, 'WHERE')!==0) $where = "WHERE {$where}";
238
+			if($where!=='' && stripos($where, 'WHERE')!==0) {
239
+			    $where = "WHERE {$where}";
240
+			}
195 241
 			return $this->query("UPDATE {$table} SET {$fields} {$where}");
196 242
 		}
197 243
 	}
198 244
 
199
-	function insert($fields, $intotable, $fromfields = "*", $fromtable = "", $where = "", $limit = "") {
245
+	function insert($fields, $intotable, $fromfields = "*", $fromtable = "", $where = "", $limit = "")
246
+	{
200 247
 		global $modx;
201 248
 		if (!$intotable) {
202 249
 			$modx->messageQuit("Empty \$intotable parameters in DBAPI::insert().");
@@ -213,68 +260,99 @@  discard block
 block discarded – undo
213 260
 					$fields = "(".implode(",", array_keys($fields)).")";
214 261
 					$where = trim($where);
215 262
 					$limit = trim($limit);
216
-					if($where!=='' && stripos($where, 'WHERE')!==0) $where = "WHERE {$where}";
217
-					if($limit!=='' && stripos($limit, 'LIMIT')!==0) $limit = "LIMIT {$limit}";
263
+					if($where!=='' && stripos($where, 'WHERE')!==0) {
264
+					    $where = "WHERE {$where}";
265
+					}
266
+					if($limit!=='' && stripos($limit, 'LIMIT')!==0) {
267
+					    $limit = "LIMIT {$limit}";
268
+					}
218 269
 					$rt = $this->query("INSERT INTO {$intotable} {$fields} SELECT {$fromfields} FROM {$fromtable} {$where} {$limit}");
219 270
 				}
220 271
 			}
221
-			if (($lid = $this->getInsertId())===false) $modx->messageQuit("Couldn't get last insert key!");
272
+			if (($lid = $this->getInsertId())===false) {
273
+			    $modx->messageQuit("Couldn't get last insert key!");
274
+			}
222 275
 			return $lid;
223 276
 		}
224 277
 	}
225 278
 
226
-    function save($fields, $table, $where='') { // This is similar to "replace into table".
279
+    function save($fields, $table, $where='')
280
+    {
281
+// This is similar to "replace into table".
227 282
         
228
-        if($where === '')                                                  $mode = 'insert';
229
-        elseif($this->getRecordCount($this->select('*',$table,$where))==0) $mode = 'insert';
230
-        else                                                               $mode = 'update';
283
+        if($where === '') {
284
+            $mode = 'insert';
285
+        } elseif($this->getRecordCount($this->select('*',$table,$where))==0) {
286
+            $mode = 'insert';
287
+        } else {
288
+            $mode = 'update';
289
+        }
231 290
         
232
-        if($mode==='insert') return $this->insert($fields, $table);
233
-        else                 return $this->update($fields, $table, $where);
291
+        if($mode==='insert') {
292
+            return $this->insert($fields, $table);
293
+        } else {
294
+            return $this->update($fields, $table, $where);
295
+        }
234 296
     }
235 297
     
236
-	function isResult($rs) {
298
+	function isResult($rs)
299
+	{
237 300
 		return is_object($rs);
238 301
 	}
239 302
 
240
-	function freeResult($rs) {
303
+	function freeResult($rs)
304
+	{
241 305
 		$rs->free_result();
242 306
 	}
243 307
 
244
-	function numFields($rs) {
308
+	function numFields($rs)
309
+	{
245 310
 		return $rs->field_count;
246 311
 	}
247 312
 
248
-	function fieldName($rs,$col=0) {
313
+	function fieldName($rs,$col=0)
314
+	{
249 315
 		$field = $rs->fetch_field_direct($col);
250 316
 		return $field->name;
251 317
 	}
252 318
 
253
-	function selectDb($name) {
319
+	function selectDb($name)
320
+	{
254 321
 		$this->conn->select_db($name);
255 322
 	}
256 323
 
257 324
 
258
-	function getInsertId($conn=NULL) {
259
-		if (!is_object($conn)) $conn =& $this->conn;
325
+	function getInsertId($conn=NULL)
326
+	{
327
+		if (!is_object($conn)) {
328
+		    $conn =& $this->conn;
329
+		}
260 330
 		return $conn->insert_id;
261 331
 	}
262 332
 
263
-	function getAffectedRows($conn=NULL) {
264
-		if (!is_object($conn)) $conn =& $this->conn;
333
+	function getAffectedRows($conn=NULL)
334
+	{
335
+		if (!is_object($conn)) {
336
+		    $conn =& $this->conn;
337
+		}
265 338
 		return $conn->affected_rows;
266 339
 	}
267 340
 
268
-	function getLastError($conn=NULL) {
269
-		if (!is_object($conn)) $conn =& $this->conn;
341
+	function getLastError($conn=NULL)
342
+	{
343
+		if (!is_object($conn)) {
344
+		    $conn =& $this->conn;
345
+		}
270 346
 		return $conn->error;
271 347
 	}
272 348
 
273
-	function getRecordCount($ds) {
349
+	function getRecordCount($ds)
350
+	{
274 351
 		return (is_object($ds)) ? $ds->num_rows : 0;
275 352
 	}
276 353
 
277
-	function getRow($ds, $mode = 'assoc') {
354
+	function getRow($ds, $mode = 'assoc')
355
+	{
278 356
 		if (is_object($ds)) {
279 357
 			if ($mode == 'assoc') {
280 358
 				return $ds->fetch_assoc();
@@ -291,7 +369,8 @@  discard block
 block discarded – undo
291 369
 		}
292 370
 	}
293 371
 
294
-	function getColumn($name, $dsq) {
372
+	function getColumn($name, $dsq)
373
+	{
295 374
 		if (!is_object($dsq)) {
296 375
 			$dsq = $this->query($dsq);
297 376
 		}
@@ -304,7 +383,8 @@  discard block
 block discarded – undo
304 383
 		}
305 384
 	}
306 385
 
307
-	function getColumnNames($dsq) {
386
+	function getColumnNames($dsq)
387
+	{
308 388
 		if (!is_object($dsq)) {
309 389
 			$dsq = $this->query($dsq);
310 390
 		}
@@ -318,7 +398,8 @@  discard block
 block discarded – undo
318 398
 		}
319 399
 	}
320 400
 
321
-	function getValue($dsq) {
401
+	function getValue($dsq)
402
+	{
322 403
 		if (!is_object($dsq)) {
323 404
 			$dsq = $this->query($dsq);
324 405
 		}
@@ -328,7 +409,8 @@  discard block
 block discarded – undo
328 409
 		}
329 410
 	}
330 411
 
331
-	function getTableMetaData($table) {
412
+	function getTableMetaData($table)
413
+	{
332 414
 		$metadata = false;
333 415
 		if (!empty ($table)) {
334 416
 			$sql = "SHOW FIELDS FROM $table";
@@ -342,7 +424,8 @@  discard block
 block discarded – undo
342 424
 		return $metadata;
343 425
 	}
344 426
 
345
-	function prepareDate($timestamp, $fieldType = 'DATETIME') {
427
+	function prepareDate($timestamp, $fieldType = 'DATETIME')
428
+	{
346 429
 		$date = '';
347 430
 		if (!$timestamp === false && $timestamp > 0) {
348 431
 			switch ($fieldType) {
@@ -363,8 +446,11 @@  discard block
 block discarded – undo
363 446
 		return $date;
364 447
 	}
365 448
 
366
-	function makeArray($rs='',$index=false){
367
-		if (!$rs) return false;
449
+	function makeArray($rs='',$index=false)
450
+	{
451
+		if (!$rs) {
452
+		    return false;
453
+		}
368 454
 		$rsArray = array();
369 455
 		$iterator = 0;
370 456
 		while ($row = $this->getRow($rs)) {
@@ -375,11 +461,13 @@  discard block
 block discarded – undo
375 461
 		return $rsArray;
376 462
 	}
377 463
 
378
-	function getVersion() {
464
+	function getVersion()
465
+	{
379 466
 		return $this->conn->server_info;
380 467
 	}
381 468
 
382
-	function replaceFullTableName($str,$force=null) {
469
+	function replaceFullTableName($str,$force=null)
470
+	{
383 471
 		$str = trim($str);
384 472
 		$dbase  = trim($this->config['dbase'],'`');
385 473
 		$prefix = $this->config['table_prefix'];
@@ -393,7 +481,8 @@  discard block
 block discarded – undo
393 481
 		return $result;
394 482
 	}
395 483
 
396
-	function optimize($table_name) {
484
+	function optimize($table_name)
485
+	{
397 486
 		$rs = $this->query("OPTIMIZE TABLE {$table_name}");
398 487
 		if ($rs) {
399 488
 			$rs = $this->query("ALTER TABLE {$table_name}");
@@ -401,28 +490,37 @@  discard block
 block discarded – undo
401 490
 		return $rs;
402 491
 	}
403 492
 
404
-	function truncate($table_name) {
493
+	function truncate($table_name)
494
+	{
405 495
 		$rs = $this->query("TRUNCATE {$table_name}");
406 496
 		return $rs;
407 497
 	}
408 498
 
409
-	function dataSeek($result, $row_number) {
499
+	function dataSeek($result, $row_number)
500
+	{
410 501
 		return $result->data_seek($row_number);
411 502
 	}
412 503
 	
413
-    function _getFieldsStringFromArray($fields=array()) {
504
+    function _getFieldsStringFromArray($fields=array())
505
+    {
414 506
         
415
-        if(empty($fields)) return '*';
507
+        if(empty($fields)) {
508
+            return '*';
509
+        }
416 510
         
417 511
         $_ = array();
418 512
         foreach($fields as $k=>$v) {
419
-            if($k!==$v) $_[] = "{$v} as {$k}";
420
-            else        $_[] = $v;
513
+            if($k!==$v) {
514
+                $_[] = "{$v} as {$k}";
515
+            } else {
516
+                $_[] = $v;
517
+            }
421 518
         }
422 519
         return join(',', $_);
423 520
     }
424 521
     
425
-    function _getFromStringFromArray($tables=array()) {
522
+    function _getFromStringFromArray($tables=array())
523
+    {
426 524
         $_ = array();
427 525
         foreach($tables as $k=>$v) {
428 526
             $_[] = $v;
Please login to merge, or discard this patch.
manager/includes/extenders/ex_export_site.inc.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -5,8 +5,7 @@
 block discarded – undo
5 5
  * Time: 14:24
6 6
  */
7 7
 
8
-if(include_once(MODX_MANAGER_PATH . 'includes/extenders/export.class.inc.php'))
9
-{
8
+if(include_once(MODX_MANAGER_PATH . 'includes/extenders/export.class.inc.php')) {
10 9
     $this->export = new EXPORT_SITE;
11 10
     return true;
12 11
 } else {
Please login to merge, or discard this patch.
manager/includes/extenders/dbapi.mysql.class.inc.php 1 patch
Braces   +207 added lines, -110 removed lines patch added patch discarded remove patch
@@ -5,7 +5,8 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 
8
-class DBAPI {
8
+class DBAPI
9
+{
9 10
 
10 11
    var $conn;
11 12
    var $config;
@@ -16,7 +17,8 @@  discard block
 block discarded – undo
16 17
     * @name:  DBAPI
17 18
     *
18 19
     */
19
-   function __construct($host='',$dbase='', $uid='',$pwd='',$pre=NULL,$charset='',$connection_method='SET CHARACTER SET') {
20
+   function __construct($host='',$dbase='', $uid='',$pwd='',$pre=NULL,$charset='',$connection_method='SET CHARACTER SET')
21
+   {
20 22
       $this->config['host'] = $host ? $host : $GLOBALS['database_server'];
21 23
       $this->config['dbase'] = $dbase ? $dbase : $GLOBALS['dbase'];
22 24
       $this->config['user'] = $uid ? $uid : $GLOBALS['database_user'];
@@ -32,7 +34,8 @@  discard block
 block discarded – undo
32 34
     * @desc:  called in the constructor to set up arrays containing the types
33 35
     *         of database fields that can be used with specific PHP types
34 36
     */
35
-   function initDataTypes() {
37
+   function initDataTypes()
38
+   {
36 39
       $this->dataTypes['numeric'] = array (
37 40
          'INT',
38 41
          'INTEGER',
@@ -78,7 +81,8 @@  discard block
 block discarded – undo
78 81
     * @name:  connect
79 82
     *
80 83
     */
81
-   function connect($host = '', $dbase = '', $uid = '', $pwd = '', $persist = 0) {
84
+   function connect($host = '', $dbase = '', $uid = '', $pwd = '', $persist = 0)
85
+   {
82 86
       global $modx;
83 87
       $uid = $uid ? $uid : $this->config['user'];
84 88
       $pwd = $pwd ? $pwd : $this->config['pass'];
@@ -88,17 +92,16 @@  discard block
 block discarded – undo
88 92
       $connection_method = $this->config['connection_method'];
89 93
       $tstart = $modx->getMicroTime();
90 94
       $safe_count = 0;
91
-      while(!$this->conn && $safe_count<3)
92
-      {
93
-          if($persist!=0) $this->conn = mysql_pconnect($host, $uid, $pwd);
94
-          else            $this->conn = mysql_connect($host, $uid, $pwd, true);
95
+      while(!$this->conn && $safe_count<3) {
96
+          if($persist!=0) {
97
+              $this->conn = mysql_pconnect($host, $uid, $pwd);
98
+          } else {
99
+              $this->conn = mysql_connect($host, $uid, $pwd, true);
100
+          }
95 101
           
96
-          if(!$this->conn)
97
-          {
98
-            if(isset($modx->config['send_errormail']) && $modx->config['send_errormail'] !== '0')
99
-            {
100
-               if($modx->config['send_errormail'] <= 2)
101
-               {
102
+          if(!$this->conn) {
103
+            if(isset($modx->config['send_errormail']) && $modx->config['send_errormail'] !== '0') {
104
+               if($modx->config['send_errormail'] <= 2) {
102 105
                   $logtitle    = 'Failed to create the database connection!';
103 106
                   $request_uri = $modx->htmlspecialchars($_SERVER['REQUEST_URI']);
104 107
                   $ua          = $modx->htmlspecialchars($_SERVER['HTTP_USER_AGENT']);
@@ -146,30 +149,36 @@  discard block
 block discarded – undo
146 149
     * @name:  disconnect
147 150
     *
148 151
     */
149
-   function disconnect() {
152
+   function disconnect()
153
+   {
150 154
       @ mysql_close($this->conn);
151 155
       $this->conn = null;
152 156
       $this->isConnected = false;
153 157
    }
154 158
 
155
-   function escape($s, $safecount=0) {
159
+   function escape($s, $safecount=0)
160
+   {
156 161
       
157 162
       $safecount++;
158
-      if(1000<$safecount) exit("Too many loops '{$safecount}'");
163
+      if(1000<$safecount) {
164
+          exit("Too many loops '{$safecount}'");
165
+      }
159 166
       
160 167
       if (empty ($this->conn) || !is_resource($this->conn)) {
161 168
          $this->connect();
162 169
        }
163 170
        
164 171
       if(is_array($s)) {
165
-          if(count($s) === 0) $s = '';
166
-          else {
172
+          if(count($s) === 0) {
173
+              $s = '';
174
+          } else {
167 175
               foreach($s as $i=>$v) {
168 176
                   $s[$i] = $this->escape($v,$safecount);
169 177
               }
170 178
           }
179
+      } else {
180
+          $s = mysql_real_escape_string($s, $this->conn);
171 181
       }
172
-      else $s = mysql_real_escape_string($s, $this->conn);
173 182
           return $s;
174 183
    }
175 184
 
@@ -178,16 +187,21 @@  discard block
 block discarded – undo
178 187
     * @desc:  Mainly for internal use.
179 188
     * Developers should use select, update, insert, delete where possible
180 189
     */
181
-   function query($sql,$watchError=true) {
190
+   function query($sql,$watchError=true)
191
+   {
182 192
       global $modx;
183 193
       if (empty ($this->conn) || !is_resource($this->conn)) {
184 194
          $this->connect();
185 195
       }
186 196
       $tstart = $modx->getMicroTime();
187
-      if(is_array($sql)) $sql = join("\n", $sql);
197
+      if(is_array($sql)) {
198
+          $sql = join("\n", $sql);
199
+      }
188 200
       $this->lastQuery = $sql;
189 201
       if (!$result = @ mysql_query($sql, $this->conn)) {
190
-         if(!$watchError) return;
202
+         if(!$watchError) {
203
+             return;
204
+         }
191 205
             switch(mysql_errno()) {
192 206
                 case 1054:
193 207
                 case 1060:
@@ -206,15 +220,26 @@  discard block
 block discarded – undo
206 220
             $debug = debug_backtrace();
207 221
             array_shift($debug);	
208 222
             $debug_path = array();
209
-            foreach ($debug as $line) $debug_path[] = $line['function'];
223
+            foreach ($debug as $line) {
224
+                $debug_path[] = $line['function'];
225
+            }
210 226
             $debug_path = implode(' > ',array_reverse($debug_path));
211 227
             $modx->queryCode .= "<fieldset style='text-align:left'><legend>Query " . ($modx->executedQueries + 1) . " - " . sprintf("%2.2f ms", $totaltime*1000) . "</legend>";
212 228
             $modx->queryCode .= $sql . '<br><br>';
213
-            if ($modx->event->name) $modx->queryCode .= 'Current Event  => ' . $modx->event->name . '<br>';
214
-            if ($modx->event->activePlugin) $modx->queryCode .= 'Current Plugin => ' . $modx->event->activePlugin . '<br>';
215
-            if ($modx->currentSnippet) $modx->queryCode .= 'Current Snippet => ' . $modx->currentSnippet . '<br>';
216
-            if (stripos($sql, 'select')===0) $modx->queryCode .= 'Record Count => ' . $this->getRecordCount($result) . '<br>';
217
-            else $modx->queryCode .= 'Affected Rows => ' . $this->getAffectedRows() . '<br>';
229
+            if ($modx->event->name) {
230
+                $modx->queryCode .= 'Current Event  => ' . $modx->event->name . '<br>';
231
+            }
232
+            if ($modx->event->activePlugin) {
233
+                $modx->queryCode .= 'Current Plugin => ' . $modx->event->activePlugin . '<br>';
234
+            }
235
+            if ($modx->currentSnippet) {
236
+                $modx->queryCode .= 'Current Snippet => ' . $modx->currentSnippet . '<br>';
237
+            }
238
+            if (stripos($sql, 'select')===0) {
239
+                $modx->queryCode .= 'Record Count => ' . $this->getRecordCount($result) . '<br>';
240
+            } else {
241
+                $modx->queryCode .= 'Affected Rows => ' . $this->getAffectedRows() . '<br>';
242
+            }
218 243
             $modx->queryCode .= 'Functions Path => ' . $debug_path . '<br>';
219 244
             $modx->queryCode .= "</fieldset><br />";
220 245
          }
@@ -227,18 +252,25 @@  discard block
 block discarded – undo
227 252
     * @name:  delete
228 253
     *
229 254
     */
230
-   function delete($from, $where='', $orderby='', $limit = '') {
255
+   function delete($from, $where='', $orderby='', $limit = '')
256
+   {
231 257
       global $modx;
232
-      if (!$from)
233
-         $modx->messageQuit("Empty \$from parameters in DBAPI::delete().");
234
-      else {
258
+      if (!$from) {
259
+               $modx->messageQuit("Empty \$from parameters in DBAPI::delete().");
260
+      } else {
235 261
          $from = $this->replaceFullTableName($from);
236 262
          $where   = trim($where);
237 263
          $orderby = trim($orderby);
238 264
          $limit   = trim($limit);
239
-         if($where!==''   && stripos($where,   'WHERE')!==0)    $where   = "WHERE {$where}";
240
-         if($orderby!=='' && stripos($orderby, 'ORDER BY')!==0) $orderby = "ORDER BY {$orderby}";
241
-         if($limit!==''   && stripos($limit,   'LIMIT')!==0)    $limit   = "LIMIT {$limit}";
265
+         if($where!==''   && stripos($where,   'WHERE')!==0) {
266
+             $where   = "WHERE {$where}";
267
+         }
268
+         if($orderby!=='' && stripos($orderby, 'ORDER BY')!==0) {
269
+             $orderby = "ORDER BY {$orderby}";
270
+         }
271
+         if($limit!==''   && stripos($limit,   'LIMIT')!==0) {
272
+             $limit   = "LIMIT {$limit}";
273
+         }
242 274
          return $this->query("DELETE FROM {$from} {$where} {$orderby} {$limit}");
243 275
       }
244 276
    }
@@ -247,12 +279,19 @@  discard block
 block discarded – undo
247 279
     * @name:  select
248 280
     *
249 281
     */
250
-   function select($fields = "*", $from = "", $where = "", $orderby = "", $limit = "") {
282
+   function select($fields = "*", $from = "", $where = "", $orderby = "", $limit = "")
283
+   {
251 284
       global $modx;
252 285
       
253
-      if(is_array($fields)) $fields = $this->_getFieldsStringFromArray($fields);
254
-      if(is_array($from))   $from   = $this->_getFromStringFromArray($from);
255
-      if(is_array($where))  $where  = join(' ', $where);
286
+      if(is_array($fields)) {
287
+          $fields = $this->_getFieldsStringFromArray($fields);
288
+      }
289
+      if(is_array($from)) {
290
+          $from   = $this->_getFromStringFromArray($from);
291
+      }
292
+      if(is_array($where)) {
293
+          $where  = join(' ', $where);
294
+      }
256 295
       
257 296
       if (!$from) {
258 297
          $modx->messageQuit("Empty \$from parameters in DBAPI::select().");
@@ -264,9 +303,15 @@  discard block
 block discarded – undo
264 303
       $where   = trim($where);
265 304
       $orderby = trim($orderby);
266 305
       $limit   = trim($limit);
267
-      if($where!==''   && stripos($where,'WHERE')!==0)   $where   = "WHERE {$where}";
268
-      if($orderby!=='' && stripos($orderby,'ORDER')!==0) $orderby = "ORDER BY {$orderby}";
269
-      if($limit!==''   && stripos($limit,'LIMIT')!==0)   $limit   = "LIMIT {$limit}";
306
+      if($where!==''   && stripos($where,'WHERE')!==0) {
307
+          $where   = "WHERE {$where}";
308
+      }
309
+      if($orderby!=='' && stripos($orderby,'ORDER')!==0) {
310
+          $orderby = "ORDER BY {$orderby}";
311
+      }
312
+      if($limit!==''   && stripos($limit,'LIMIT')!==0) {
313
+          $limit   = "LIMIT {$limit}";
314
+      }
270 315
       return $this->query("SELECT {$fields} FROM {$from} {$where} {$orderby} {$limit}");
271 316
    }
272 317
 
@@ -274,17 +319,18 @@  discard block
 block discarded – undo
274 319
     * @name:  update
275 320
     *
276 321
     */
277
-   function update($fields, $table, $where = "") {
322
+   function update($fields, $table, $where = "")
323
+   {
278 324
       global $modx;
279
-      if (!$table)
280
-         $modx->messageQuit("Empty \$table parameter in DBAPI::update().");
281
-      else {
325
+      if (!$table) {
326
+               $modx->messageQuit("Empty \$table parameter in DBAPI::update().");
327
+      } else {
282 328
          $table = $this->replaceFullTableName($table);
283 329
          if (is_array($fields)) {
284 330
 			 foreach ($fields as $key => $value) {
285
-				 if(is_null($value) || strtolower($value) === 'null'){
331
+				 if(is_null($value) || strtolower($value) === 'null') {
286 332
 					 $flds = 'NULL';
287
-				 }else{
333
+				 } else {
288 334
 					 $flds = "'" . $value . "'";
289 335
 				 }
290 336
 				 $fields[$key] = "`{$key}` = ".$flds;
@@ -292,7 +338,9 @@  discard block
 block discarded – undo
292 338
             $fields = implode(",", $fields);
293 339
          }
294 340
          $where = trim($where);
295
-         if($where!=='' && stripos($where, 'WHERE')!==0) $where = "WHERE {$where}";
341
+         if($where!=='' && stripos($where, 'WHERE')!==0) {
342
+             $where = "WHERE {$where}";
343
+         }
296 344
          return $this->query("UPDATE {$table} SET {$fields} {$where}");
297 345
       }
298 346
    }
@@ -301,11 +349,12 @@  discard block
 block discarded – undo
301 349
     * @name:  insert
302 350
     * @desc:  returns either last id inserted or the result from the query
303 351
     */
304
-   function insert($fields, $intotable, $fromfields = "*", $fromtable = "", $where = "", $limit = "") {
352
+   function insert($fields, $intotable, $fromfields = "*", $fromtable = "", $where = "", $limit = "")
353
+   {
305 354
       global $modx;
306
-      if (!$intotable)
307
-         $modx->messageQuit("Empty \$intotable parameters in DBAPI::insert().");
308
-      else {
355
+      if (!$intotable) {
356
+               $modx->messageQuit("Empty \$intotable parameters in DBAPI::insert().");
357
+      } else {
309 358
          $intotable = $this->replaceFullTableName($intotable);
310 359
          if (!is_array($fields)) {
311 360
             $this->query("INSERT INTO {$intotable} {$fields}");
@@ -319,8 +368,12 @@  discard block
 block discarded – undo
319 368
                   $fields = "(".implode(",", array_keys($fields)).")";
320 369
                   $where = trim($where);
321 370
                   $limit = trim($limit);
322
-                  if($where!=='' && stripos($where, 'WHERE')!==0) $where = "WHERE {$where}";
323
-                  if($limit!=='' && stripos($limit, 'LIMIT')!==0) $limit = "LIMIT {$limit}";
371
+                  if($where!=='' && stripos($where, 'WHERE')!==0) {
372
+                      $where = "WHERE {$where}";
373
+                  }
374
+                  if($limit!=='' && stripos($limit, 'LIMIT')!==0) {
375
+                      $limit = "LIMIT {$limit}";
376
+                  }
324 377
                   $rt = $this->query("INSERT INTO {$intotable} {$fields} SELECT {$fromfields} FROM {$fromtable} {$where} {$limit}");
325 378
                } else {
326 379
                   $ds = $this->select($fromfields, $fromtable, $where, '', $limit);
@@ -331,26 +384,37 @@  discard block
 block discarded – undo
331 384
                }
332 385
             }
333 386
          }
334
-         if (($lid = $this->getInsertId())===false) $modx->messageQuit("Couldn't get last insert key!");
387
+         if (($lid = $this->getInsertId())===false) {
388
+             $modx->messageQuit("Couldn't get last insert key!");
389
+         }
335 390
          return $lid;
336 391
       }
337 392
    }
338 393
    
339
-    function save($fields, $table, $where='') {
394
+    function save($fields, $table, $where='')
395
+    {
340 396
         
341
-        if($where === '')                                                  $mode = 'insert';
342
-        elseif($this->getRecordCount($this->select('*',$table,$where))==0) $mode = 'insert';
343
-        else                                                               $mode = 'update';
397
+        if($where === '') {
398
+            $mode = 'insert';
399
+        } elseif($this->getRecordCount($this->select('*',$table,$where))==0) {
400
+            $mode = 'insert';
401
+        } else {
402
+            $mode = 'update';
403
+        }
344 404
         
345
-        if($mode==='insert') return $this->insert($fields, $table);
346
-        else                 return $this->update($fields, $table, $where);
405
+        if($mode==='insert') {
406
+            return $this->insert($fields, $table);
407
+        } else {
408
+            return $this->update($fields, $table, $where);
409
+        }
347 410
     }
348 411
     
349 412
    /**
350 413
     * @name:  isResult
351 414
     *
352 415
     */
353
-   function isResult($rs) {
416
+   function isResult($rs)
417
+   {
354 418
       return is_resource($rs);
355 419
    }
356 420
 
@@ -358,7 +422,8 @@  discard block
 block discarded – undo
358 422
     * @name:  freeResult
359 423
     *
360 424
     */
361
-   function freeResult($rs) {
425
+   function freeResult($rs)
426
+   {
362 427
       mysql_free_result($rs);
363 428
    }
364 429
    
@@ -366,7 +431,8 @@  discard block
 block discarded – undo
366 431
     * @name:  numFields
367 432
     *
368 433
     */
369
-   function numFields($rs) {
434
+   function numFields($rs)
435
+   {
370 436
       return mysql_num_fields($rs);
371 437
    }
372 438
    
@@ -374,7 +440,8 @@  discard block
 block discarded – undo
374 440
     * @name:  fieldName
375 441
     *
376 442
     */
377
-   function fieldName($rs,$col=0) {
443
+   function fieldName($rs,$col=0)
444
+   {
378 445
       return mysql_field_name($rs,$col);
379 446
    }
380 447
    
@@ -382,7 +449,8 @@  discard block
 block discarded – undo
382 449
     * @name:  selectDb
383 450
     *
384 451
     */
385
-   function selectDb($name) {
452
+   function selectDb($name)
453
+   {
386 454
       mysql_select_db($name);
387 455
    }
388 456
    
@@ -391,8 +459,11 @@  discard block
 block discarded – undo
391 459
     * @name:  getInsertId
392 460
     *
393 461
     */
394
-   function getInsertId($conn=NULL) {
395
-      if( !is_resource($conn)) $conn =& $this->conn;
462
+   function getInsertId($conn=NULL)
463
+   {
464
+      if( !is_resource($conn)) {
465
+          $conn =& $this->conn;
466
+      }
396 467
       return mysql_insert_id($conn);
397 468
    }
398 469
 
@@ -400,8 +471,11 @@  discard block
 block discarded – undo
400 471
     * @name:  getAffectedRows
401 472
     *
402 473
     */
403
-   function getAffectedRows($conn=NULL) {
404
-      if (!is_resource($conn)) $conn =& $this->conn;
474
+   function getAffectedRows($conn=NULL)
475
+   {
476
+      if (!is_resource($conn)) {
477
+          $conn =& $this->conn;
478
+      }
405 479
       return mysql_affected_rows($conn);
406 480
    }
407 481
 
@@ -409,8 +483,11 @@  discard block
 block discarded – undo
409 483
     * @name:  getLastError
410 484
     *
411 485
     */
412
-   function getLastError($conn=NULL) {
413
-      if (!is_resource($conn)) $conn =& $this->conn;
486
+   function getLastError($conn=NULL)
487
+   {
488
+      if (!is_resource($conn)) {
489
+          $conn =& $this->conn;
490
+      }
414 491
       return mysql_error($conn);
415 492
    }
416 493
 
@@ -418,7 +495,8 @@  discard block
 block discarded – undo
418 495
     * @name:  getRecordCount
419 496
     *
420 497
     */
421
-   function getRecordCount($ds) {
498
+   function getRecordCount($ds)
499
+   {
422 500
       return (is_resource($ds)) ? mysql_num_rows($ds) : 0;
423 501
    }
424 502
 
@@ -428,18 +506,16 @@  discard block
 block discarded – undo
428 506
     * @param: $dsq - dataset
429 507
     *
430 508
     */
431
-   function getRow($ds, $mode = 'assoc') {
509
+   function getRow($ds, $mode = 'assoc')
510
+   {
432 511
       if (is_resource($ds)) {
433 512
          if ($mode == 'assoc') {
434 513
             return mysql_fetch_assoc($ds);
435
-         }
436
-         elseif ($mode == 'num') {
514
+         } elseif ($mode == 'num') {
437 515
             return mysql_fetch_row($ds);
438
-         }
439
-		 elseif ($mode == 'object') {
516
+         } elseif ($mode == 'object') {
440 517
             return mysql_fetch_object($ds);
441
-         }
442
-         elseif ($mode == 'both') {
518
+         } elseif ($mode == 'both') {
443 519
             return mysql_fetch_array($ds, MYSQL_BOTH);
444 520
          } else {
445 521
             global $modx;
@@ -453,9 +529,11 @@  discard block
 block discarded – undo
453 529
     * @desc:  returns an array of the values found on colun $name
454 530
     * @param: $dsq - dataset or query string
455 531
     */
456
-   function getColumn($name, $dsq) {
457
-      if (!is_resource($dsq))
458
-         $dsq = $this->query($dsq);
532
+   function getColumn($name, $dsq)
533
+   {
534
+      if (!is_resource($dsq)) {
535
+               $dsq = $this->query($dsq);
536
+      }
459 537
       if ($dsq) {
460 538
          $col = array ();
461 539
          while ($row = $this->getRow($dsq)) {
@@ -470,9 +548,11 @@  discard block
 block discarded – undo
470 548
     * @desc:  returns an array containing the column $name
471 549
     * @param: $dsq - dataset or query string
472 550
     */
473
-   function getColumnNames($dsq) {
474
-      if (!is_resource($dsq))
475
-         $dsq = $this->query($dsq);
551
+   function getColumnNames($dsq)
552
+   {
553
+      if (!is_resource($dsq)) {
554
+               $dsq = $this->query($dsq);
555
+      }
476 556
       if ($dsq) {
477 557
          $names = array ();
478 558
          $limit = mysql_num_fields($dsq);
@@ -488,9 +568,11 @@  discard block
 block discarded – undo
488 568
     * @desc:  returns the value from the first column in the set
489 569
     * @param: $dsq - dataset or query string
490 570
     */
491
-   function getValue($dsq) {
492
-      if (!is_resource($dsq))
493
-         $dsq = $this->query($dsq);
571
+   function getValue($dsq)
572
+   {
573
+      if (!is_resource($dsq)) {
574
+               $dsq = $this->query($dsq);
575
+      }
494 576
       if ($dsq) {
495 577
          $r = $this->getRow($dsq, "num");
496 578
          return $r[0];
@@ -503,7 +585,8 @@  discard block
 block discarded – undo
503 585
     *         table
504 586
     * @param: $table: the full name of the database table
505 587
     */
506
-   function getTableMetaData($table) {
588
+   function getTableMetaData($table)
589
+   {
507 590
       $metadata = false;
508 591
       if (!empty ($table)) {
509 592
          $sql = "SHOW FIELDS FROM $table";
@@ -525,7 +608,8 @@  discard block
 block discarded – undo
525 608
     * @param: $fieldType: the type of field to format the date for
526 609
     *         (in MySQL, you have DATE, TIME, YEAR, and DATETIME)
527 610
     */
528
-   function prepareDate($timestamp, $fieldType = 'DATETIME') {
611
+   function prepareDate($timestamp, $fieldType = 'DATETIME')
612
+   {
529 613
       $date = '';
530 614
       if (!$timestamp === false && $timestamp > 0) {
531 615
          switch ($fieldType) {
@@ -554,8 +638,11 @@  discard block
 block discarded – undo
554 638
    *          was passed
555 639
    * @param: $rs Recordset to be packaged into an array
556 640
    */
557
-	function makeArray($rs='',$index=false){
558
-		if (!$rs) return false;
641
+	function makeArray($rs='',$index=false)
642
+	{
643
+		if (!$rs) {
644
+		    return false;
645
+		}
559 646
 		$rsArray = array();
560 647
 		$iterator = 0;
561 648
 		while ($row = $this->getRow($rs)) {
@@ -572,7 +659,8 @@  discard block
 block discarded – undo
572 659
     *
573 660
     * @return string
574 661
     */
575
-   function getVersion() {
662
+   function getVersion()
663
+   {
576 664
        return mysql_get_server_info();
577 665
    }
578 666
    
@@ -583,20 +671,19 @@  discard block
 block discarded – undo
583 671
     * @param string $str
584 672
     * @return string 
585 673
     */
586
-   function replaceFullTableName($str,$force=null) {
674
+   function replaceFullTableName($str,$force=null)
675
+   {
587 676
        
588 677
        $str = trim($str);
589 678
        $dbase  = trim($this->config['dbase'],'`');
590 679
        $prefix = $this->config['table_prefix'];
591
-       if(!empty($force))
592
-       {
680
+       if(!empty($force)) {
593 681
            $result = "`{$dbase}`.`{$prefix}{$str}`";
594
-       }
595
-       elseif(strpos($str,'[+prefix+]')!==false)
596
-       {
682
+       } elseif(strpos($str,'[+prefix+]')!==false) {
597 683
            $result = preg_replace('@\[\+prefix\+\]([0-9a-zA-Z_]+)@', "`{$dbase}`.`{$prefix}$1`", $str);
684
+       } else {
685
+           $result = $str;
598 686
        }
599
-       else $result = $str;
600 687
        
601 688
        return $result;
602 689
    }
@@ -604,7 +691,9 @@  discard block
 block discarded – undo
604 691
    function optimize($table_name)
605 692
    {
606 693
        $rs = $this->query("OPTIMIZE TABLE {$table_name}");
607
-       if($rs) $rs = $this->query("ALTER TABLE {$table_name}");
694
+       if($rs) {
695
+           $rs = $this->query("ALTER TABLE {$table_name}");
696
+       }
608 697
        return $rs;
609 698
    }
610 699
    
@@ -614,23 +703,31 @@  discard block
 block discarded – undo
614 703
        return $rs;
615 704
    }
616 705
 
617
-  function dataSeek($result, $row_number) {
706
+  function dataSeek($result, $row_number)
707
+  {
618 708
     return mysql_data_seek($result, $row_number);
619 709
   }
620 710
   
621
-    function _getFieldsStringFromArray($fields=array()) {
711
+    function _getFieldsStringFromArray($fields=array())
712
+    {
622 713
         
623
-        if(empty($fields)) return '*';
714
+        if(empty($fields)) {
715
+            return '*';
716
+        }
624 717
         
625 718
         $_ = array();
626 719
         foreach($fields as $k=>$v) {
627
-            if($k!==$v) $_[] = "{$v} as {$k}";
628
-            else        $_[] = $v;
720
+            if($k!==$v) {
721
+                $_[] = "{$v} as {$k}";
722
+            } else {
723
+                $_[] = $v;
724
+            }
629 725
         }
630 726
         return join(',', $_);
631 727
     }
632 728
     
633
-    function _getFromStringFromArray($tables=array()) {
729
+    function _getFromStringFromArray($tables=array())
730
+    {
634 731
         $_ = array();
635 732
         foreach($tables as $k=>$v) {
636 733
             $_[] = $v;
Please login to merge, or discard this patch.
manager/includes/extenders/export.class.inc.php 1 patch
Braces   +81 added lines, -62 removed lines patch added patch discarded remove patch
@@ -15,14 +15,18 @@  discard block
 block discarded – undo
15 15
 	{
16 16
 		global $modx;
17 17
 		
18
-		if(!defined('MODX_BASE_PATH'))  return false;
18
+		if(!defined('MODX_BASE_PATH')) {
19
+		    return false;
20
+		}
19 21
 		$this->exportstart = $this->get_mtime();
20 22
 		$this->count = 0;
21 23
 		$this->setUrlMode();
22 24
 		$this->dirCheckCount = 0;
23 25
 		$this->generate_mode = 'crawl';
24 26
 		$this->targetDir = $modx->config['base_path'] . 'temp/export';
25
-		if(!isset($this->total)) $this->getTotal();
27
+		if(!isset($this->total)) {
28
+		    $this->getTotal();
29
+		}
26 30
 	}
27 31
 	
28 32
 	function setExportDir($dir)
@@ -44,8 +48,7 @@  discard block
 block discarded – undo
44 48
 	{
45 49
 		global $modx;
46 50
 		
47
-		if($modx->config['friendly_urls']==0)
48
-		{
51
+		if($modx->config['friendly_urls']==0) {
49 52
 			$modx->config['friendly_urls']  = 1;
50 53
 			$modx->config['use_alias_path'] = 1;
51 54
 			$modx->clearCache('full');
@@ -59,8 +62,7 @@  discard block
 block discarded – undo
59 62
 		$tbl_site_content = $modx->getFullTableName('site_content');
60 63
 		
61 64
 		$ignore_ids = array_filter(array_map('intval', explode(',', $ignore_ids)));
62
-		if(count($ignore_ids)>0)
63
-		{
65
+		if(count($ignore_ids)>0) {
64 66
 			$ignore_ids = "AND NOT id IN ('".implode("','", $ignore_ids)."')";
65 67
 		} else {
66 68
 			$ignore_ids = '';
@@ -77,27 +79,37 @@  discard block
 block discarded – undo
77 79
 	
78 80
 	function removeDirectoryAll($directory='')
79 81
 	{
80
-		if(empty($directory)) $directory = $this->targetDir;
82
+		if(empty($directory)) {
83
+		    $directory = $this->targetDir;
84
+		}
81 85
 		$directory = rtrim($directory,'/');
82 86
 		// if the path is not valid or is not a directory ...
83
-		if(empty($directory)) return false;
84
-		if(strpos($directory,MODX_BASE_PATH)===false) return FALSE;
87
+		if(empty($directory)) {
88
+		    return false;
89
+		}
90
+		if(strpos($directory,MODX_BASE_PATH)===false) {
91
+		    return FALSE;
92
+		}
85 93
 		
86
-		if(!is_dir($directory))          return FALSE;
87
-		elseif(!is_readable($directory)) return FALSE;
88
-		else
89
-		{
94
+		if(!is_dir($directory)) {
95
+		    return FALSE;
96
+		} elseif(!is_readable($directory)) {
97
+		    return FALSE;
98
+		} else {
90 99
 			$files = glob($directory . '/*');
91
-			if(!empty($files))
92
-			{
93
-    			foreach($files as $path)
94
-    			{
95
-    				if(is_dir($path)) $this->removeDirectoryAll($path);
96
-    				else              $rs = unlink($path);
100
+			if(!empty($files)) {
101
+    			foreach($files as $path) {
102
+    				if(is_dir($path)) {
103
+    				    $this->removeDirectoryAll($path);
104
+    				} else {
105
+    				    $rs = unlink($path);
106
+    				}
97 107
     			}
98 108
 			}
99 109
 		}
100
-		if($directory !== $this->targetDir) $rs = rmdir($directory);
110
+		if($directory !== $this->targetDir) {
111
+		    $rs = rmdir($directory);
112
+		}
101 113
 		
102 114
 		return $rs;
103 115
 	}
@@ -106,37 +118,43 @@  discard block
 block discarded – undo
106 118
 	{
107 119
 		global  $modx,$_lang;
108 120
 		$file_permission = octdec($modx->config['new_file_permissions']);
109
-		if($this->generate_mode==='direct')
110
-		{
121
+		if($this->generate_mode==='direct') {
111 122
 			$back_lang = $_lang;
112 123
 			$src = $modx->executeParser($docid);
113 124
 			
114 125
 			$_lang = $back_lang;
126
+		} else {
127
+		    $src = $this->curl_get_contents(MODX_SITE_URL . "index.php?id={$docid}");
115 128
 		}
116
-		else $src = $this->curl_get_contents(MODX_SITE_URL . "index.php?id={$docid}");
117 129
 		
118 130
 		
119
-		if($src !== false)
120
-		{
121
-			if($this->repl_before!==$this->repl_after) $src = str_replace($this->repl_before,$this->repl_after,$src);
131
+		if($src !== false) {
132
+			if($this->repl_before!==$this->repl_after) {
133
+			    $src = str_replace($this->repl_before,$this->repl_after,$src);
134
+			}
122 135
 			$result = file_put_contents($filepath,$src);
123
-			if($result!==false) @chmod($filepath, $file_permission);
136
+			if($result!==false) {
137
+			    @chmod($filepath, $file_permission);
138
+			}
124 139
 			
125
-			if($result !== false) return 'success';
126
-			else                  return 'failed_no_write';
140
+			if($result !== false) {
141
+			    return 'success';
142
+			} else {
143
+			    return 'failed_no_write';
144
+			}
145
+		} else {
146
+		    return 'failed_no_retrieve';
127 147
 		}
128
-		else                      return 'failed_no_retrieve';
129 148
 	}
130 149
 
131 150
 	function getFileName($docid, $alias='', $prefix, $suffix)
132 151
 	{
133 152
 		global $modx;
134 153
 		
135
-		if($alias==='') $filename = $prefix.$docid.$suffix;
136
-		else
137
-		{
138
-			if($modx->config['suffix_mode']==='1' && strpos($alias, '.')!==false)
139
-			{
154
+		if($alias==='') {
155
+		    $filename = $prefix.$docid.$suffix;
156
+		} else {
157
+			if($modx->config['suffix_mode']==='1' && strpos($alias, '.')!==false) {
140 158
 				$suffix = '';
141 159
 			}
142 160
 			$filename = $prefix.$alias.$suffix;
@@ -187,24 +205,20 @@  discard block
 block discarded – undo
187 205
 		$ph = array();
188 206
 		$ph['total']     = $this->total;
189 207
 		$folder_permission = octdec($modx->config['new_folder_permissions']);
190
-		while($row = $modx->db->getRow($rs))
191
-		{
208
+		while($row = $modx->db->getRow($rs)) {
192 209
 			$this->count++;
193 210
 			
194 211
 			$row['count']     = $this->count;
195 212
 			$row['url'] = $modx->makeUrl($row['id']);
196 213
 			
197
-			if (!$row['wasNull'])
198
-			{ // needs writing a document
214
+			if (!$row['wasNull']) {
215
+// needs writing a document
199 216
 				$docname = $this->getFileName($row['id'], $row['alias'], $prefix, $suffix);
200 217
 				$filename = $dirpath.$docname;
201
-				if (!is_file($filename))
202
-				{
203
-					if($row['published']==='1')
204
-					{
218
+				if (!is_file($filename)) {
219
+					if($row['published']==='1') {
205 220
 						$status = $this->makeFile($row['id'], $filename);
206
-						switch($status)
207
-						{
221
+						switch($status) {
208 222
 							case 'failed_no_write'   :
209 223
                                                             $row['status'] = $msg_failed_no_write;
210 224
                                                             break;
@@ -214,34 +228,38 @@  discard block
 block discarded – undo
214 228
 							default:
215 229
                                                             $row['status'] = $msg_success;
216 230
 						}
231
+					} else {
232
+					    $row['status'] = $msg_failed_no_retrieve;
217 233
 					}
218
-					else $row['status'] = $msg_failed_no_retrieve;
234
+				} else {
235
+				    $row['status'] = $msg_success_skip_doc;
219 236
 				}
220
-				else     $row['status'] = $msg_success_skip_doc;
221 237
 				$this->output[] = $this->parsePlaceholder($_lang['export_site_exporting_document'], $row);
222
-			}
223
-			else
224
-			{
238
+			} else {
225 239
 				$row['status'] = $msg_success_skip_dir;
226 240
 				$this->output[] = $this->parsePlaceholder($_lang['export_site_exporting_document'], $row);
227 241
 			}
228
-			if ($row['isfolder']==='1' && ($modx->config['suffix_mode']!=='1' || strpos($row['alias'],'.')===false))
229
-			{ // needs making a folder
242
+			if ($row['isfolder']==='1' && ($modx->config['suffix_mode']!=='1' || strpos($row['alias'],'.')===false)) {
243
+// needs making a folder
230 244
 				$end_dir = ($row['alias']!=='') ? $row['alias'] : $row['id'];
231 245
 				$dir_path = $dirpath . $end_dir;
232
-				if(strpos($dir_path,MODX_BASE_PATH)===false) return FALSE;
233
-				if (!is_dir($dir_path))
234
-				{
235
-					if (is_file($dir_path)) @unlink($dir_path);
246
+				if(strpos($dir_path,MODX_BASE_PATH)===false) {
247
+				    return FALSE;
248
+				}
249
+				if (!is_dir($dir_path)) {
250
+					if (is_file($dir_path)) {
251
+					    @unlink($dir_path);
252
+					}
236 253
 					mkdir($dir_path);
237 254
 					@chmod($dir_path, $folder_permission);
238 255
 					
239 256
 				}
240 257
 				
241 258
 				
242
-				if($modx->config['make_folders']==='1' && $row['published']==='1')
243
-				{
244
-					if(is_file($filename)) rename($filename,$dir_path . '/index.html');
259
+				if($modx->config['make_folders']==='1' && $row['published']==='1') {
260
+					if(is_file($filename)) {
261
+					    rename($filename,$dir_path . '/index.html');
262
+					}
245 263
 				}
246 264
 				$this->targetDir = $dir_path;
247 265
 				$this->run($row['id']);
@@ -252,7 +270,9 @@  discard block
 block discarded – undo
252 270
 	
253 271
     function curl_get_contents($url, $timeout = 30 )
254 272
     {
255
-    	if(!function_exists('curl_init')) return @file_get_contents($url);
273
+    	if(!function_exists('curl_init')) {
274
+    	    return @file_get_contents($url);
275
+    	}
256 276
 
257 277
         $ch = curl_init();
258 278
         curl_setopt($ch, CURLOPT_URL, $url);
@@ -269,8 +289,7 @@  discard block
 block discarded – undo
269 289
 
270 290
     function parsePlaceholder($tpl,$ph=array())
271 291
     {
272
-    	foreach($ph as $k=>$v)
273
-    	{
292
+    	foreach($ph as $k=>$v) {
274 293
     		$k = "[+{$k}+]";
275 294
     		$tpl = str_replace($k,$v,$tpl);
276 295
     	}
Please login to merge, or discard this patch.
manager/includes/extenders/ex_dbapi.inc.php 1 patch
Braces   +5 added lines, -3 removed lines patch added patch discarded remove patch
@@ -7,11 +7,13 @@
 block discarded – undo
7 7
 
8 8
 global $database_type;
9 9
 
10
-if (empty($database_type)) $database_type = 'mysql';
10
+if (empty($database_type)) {
11
+    $database_type = 'mysql';
12
+}
11 13
 
12
-if (!include_once MODX_MANAGER_PATH . 'includes/extenders/dbapi.' . $database_type . '.class.inc.php'){
14
+if (!include_once MODX_MANAGER_PATH . 'includes/extenders/dbapi.' . $database_type . '.class.inc.php') {
13 15
     return false;
14
-}else{
16
+} else {
15 17
     $this->db= new DBAPI;
16 18
     return true;
17 19
 }
Please login to merge, or discard this patch.
manager/includes/extenders/manager.api.class.inc.php 1 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.
manager/includes/extenders/phpass.class.inc.php 1 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.