Completed
Pull Request — develop (#518)
by Agel_Nash
05:24
created
manager/includes/extenders/modxmailer.class.inc.php 1 patch
Braces   +12 added lines, -6 removed lines patch added patch discarded remove patch
@@ -276,14 +276,16 @@  discard block
 block discarded – undo
276 276
     /**
277 277
      * @return string
278 278
      */
279
-    public function getMIMEHeader() {
279
+    public function getMIMEHeader()
280
+    {
280 281
         return $this->MIMEHeader;
281 282
     }
282 283
 
283 284
     /**
284 285
      * @return string
285 286
      */
286
-    public function getMIMEBody() {
287
+    public function getMIMEBody()
288
+    {
287 289
         return $this->MIMEBody;
288 290
     }
289 291
 
@@ -292,7 +294,8 @@  discard block
 block discarded – undo
292 294
      * 
293 295
      * @return $this
294 296
      */
295
-    public function setMIMEHeader($header = '') {
297
+    public function setMIMEHeader($header = '')
298
+    {
296 299
         $this->MIMEHeader = $header;
297 300
 
298 301
         return $this;
@@ -303,7 +306,8 @@  discard block
 block discarded – undo
303 306
      * 
304 307
      * @return $this
305 308
      */
306
-    public function setMIMEBody($body = '') {
309
+    public function setMIMEBody($body = '')
310
+    {
307 311
         $this->MIMEBody = $body;
308 312
 
309 313
         return $this;
@@ -314,7 +318,8 @@  discard block
 block discarded – undo
314 318
      * 
315 319
      * @return $this
316 320
      */
317
-    public function setMailHeader($header = '') {
321
+    public function setMailHeader($header = '')
322
+    {
318 323
         $this->mailHeader = $header;
319 324
 
320 325
         return $this;
@@ -323,7 +328,8 @@  discard block
 block discarded – undo
323 328
     /**
324 329
      * @return string
325 330
      */
326
-    public function getMessageID() {
331
+    public function getMessageID()
332
+    {
327 333
         return trim($this->lastMessageID,'<>');
328 334
     }
329 335
 }
Please login to merge, or discard this patch.
manager/includes/extenders/ex_getUserData.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,7 @@
 block discarded – undo
1 1
 <?php
2
-if(IN_MANAGER_MODE!="true" && IN_PARSER_MODE!="true") die("<b>INCLUDE ACCESS ERROR</b><br /><br />Direct access to this file prohibited.");
2
+if(IN_MANAGER_MODE!="true" && IN_PARSER_MODE!="true") {
3
+    die("<b>INCLUDE ACCESS ERROR</b><br /><br />Direct access to this file prohibited.");
4
+}
3 5
 $tmpArray = array();
4 6
 $tmpArray['ip'] = $_SERVER['REMOTE_ADDR'];
5 7
 $tmpArray['ua'] = $_SERVER['HTTP_USER_AGENT'];
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/maketable.class.php 1 patch
Braces   +83 added lines, -42 removed lines patch added patch discarded remove patch
@@ -8,7 +8,8 @@  discard block
 block discarded – undo
8 8
  * 
9 9
  * @author Jason Coward <[email protected]> (MODX)
10 10
  */
11
-class MakeTable {
11
+class MakeTable
12
+{
12 13
 	var $actionField;
13 14
 	var $cellAction;
14 15
 	var $linkAction;
@@ -31,7 +32,8 @@  discard block
 block discarded – undo
31 32
 	var $columnWidths;
32 33
 	var $selectedValues;
33 34
 	
34
-	function __construct() {
35
+	function __construct()
36
+	{
35 37
 		$this->fieldHeaders= array();
36 38
 		$this->excludeFields= array();
37 39
 		$this->actionField= '';
@@ -58,7 +60,8 @@  discard block
 block discarded – undo
58 60
 	 * 
59 61
 	 * @param $value A URL to execute when table cells are clicked.
60 62
 	 */
61
-	function setCellAction($value) {
63
+	function setCellAction($value)
64
+	{
62 65
 		$this->cellAction= $this->prepareLink($value);
63 66
 	}
64 67
 	
@@ -67,7 +70,8 @@  discard block
 block discarded – undo
67 70
 	 * 
68 71
 	 * @param $value A URL to execute when text within table cells are clicked.
69 72
 	 */
70
-	function setLinkAction($value) {
73
+	function setLinkAction($value)
74
+	{
71 75
 		$this->linkAction= $this->prepareLink($value);
72 76
 	}
73 77
 	
@@ -76,7 +80,8 @@  discard block
 block discarded – undo
76 80
 	 * 
77 81
 	 * @param $value A valid width attribute for the HTML TABLE tag
78 82
 	 */
79
-	function setTableWidth($value) {
83
+	function setTableWidth($value)
84
+	{
80 85
 		$this->tableWidth= $value;
81 86
 	}
82 87
 	
@@ -85,7 +90,8 @@  discard block
 block discarded – undo
85 90
 	 * 
86 91
 	 * @param $value A class for the main HTML TABLE. 
87 92
 	 */
88
-	function setTableClass($value) {
93
+	function setTableClass($value)
94
+	{
89 95
 		$this->tableClass= $value;
90 96
 	}
91 97
 	
@@ -94,7 +100,8 @@  discard block
 block discarded – undo
94 100
 	 * 
95 101
 	 * @param $value A class for the main HTML TABLE. 
96 102
 	 */
97
-	function setTableID($value) {
103
+	function setTableID($value)
104
+	{
98 105
 		$this->tableID= $value;
99 106
 	}
100 107
 	
@@ -103,7 +110,8 @@  discard block
 block discarded – undo
103 110
 	 * 
104 111
 	 * @param $value A class for the table header row.
105 112
 	 */
106
-	function setRowHeaderClass($value) {
113
+	function setRowHeaderClass($value)
114
+	{
107 115
 		$this->rowHeaderClass= $value;
108 116
 	}
109 117
 	
@@ -112,7 +120,8 @@  discard block
 block discarded – undo
112 120
 	 * 
113 121
 	 * @param $value A class for the table header row.
114 122
 	 */
115
-	function setThHeaderClass($value) {
123
+	function setThHeaderClass($value)
124
+	{
116 125
 		$this->thClass= $value;
117 126
 	}
118 127
 	
@@ -121,7 +130,8 @@  discard block
 block discarded – undo
121 130
 	 * 
122 131
 	 * @param $value A class for the column header row.
123 132
 	 */
124
-	function setColumnHeaderClass($value) {
133
+	function setColumnHeaderClass($value)
134
+	{
125 135
 		$this->columnHeaderClass= $value;
126 136
 	}
127 137
 	
@@ -130,7 +140,8 @@  discard block
 block discarded – undo
130 140
 	 * 
131 141
 	 * @param $value A class for regular table rows.
132 142
 	 */
133
-	function setRowRegularClass($value) {
143
+	function setRowRegularClass($value)
144
+	{
134 145
 		$this->rowRegularClass= $value;
135 146
 	}
136 147
 	
@@ -139,7 +150,8 @@  discard block
 block discarded – undo
139 150
 	 * 
140 151
 	 * @param $value A class for alternate table rows.
141 152
 	 */	
142
-	function setRowAlternateClass($value) {
153
+	function setRowAlternateClass($value)
154
+	{
143 155
 		$this->rowAlternateClass= $value;
144 156
 	}
145 157
 	
@@ -148,7 +160,8 @@  discard block
 block discarded – undo
148 160
 	 * 
149 161
 	 * @param $value Indicates the INPUT form element type attribute.
150 162
 	 */
151
-	function setFormElementType($value) {
163
+	function setFormElementType($value)
164
+	{
152 165
 		$this->formElementType= $value;
153 166
 	}
154 167
 	
@@ -157,7 +170,8 @@  discard block
 block discarded – undo
157 170
 	 * 
158 171
 	 * @param $value Indicates the INPUT form element name attribute.
159 172
 	 */
160
-	function setFormElementName($value) {
173
+	function setFormElementName($value)
174
+	{
161 175
 		$this->formElementName= $value;
162 176
 	}
163 177
 	
@@ -167,7 +181,8 @@  discard block
 block discarded – undo
167 181
 	 * 
168 182
 	 * @param $value Indicates the FORM name attribute.
169 183
 	 */
170
-	function setFormName($value) {
184
+	function setFormName($value)
185
+	{
171 186
 		$this->formName= $value;
172 187
 	}
173 188
 	
@@ -176,7 +191,8 @@  discard block
 block discarded – undo
176 191
 	 * 
177 192
 	 * @param $value Indicates the FORM action attribute.
178 193
 	 */
179
-	function setFormAction($value) {
194
+	function setFormAction($value)
195
+	{
180 196
 		$this->formAction= $value;
181 197
 	}
182 198
 	
@@ -185,7 +201,8 @@  discard block
 block discarded – undo
185 201
 	 * 
186 202
 	 * @param $value An Array of field keys to exclude from the table.
187 203
 	 */
188
-	function setExcludeFields($value) {
204
+	function setExcludeFields($value)
205
+	{
189 206
 		$this->excludeFields= $value;
190 207
 	}
191 208
 
@@ -194,7 +211,8 @@  discard block
 block discarded – undo
194 211
 	 * 
195 212
 	 * @param $value 'ODD' or 'EVEN' to indicate the alternate row scheme.
196 213
 	 */
197
-	function setRowAlternatingScheme($value) {
214
+	function setRowAlternatingScheme($value)
215
+	{
198 216
 		$this->rowAlternatingScheme= $value;
199 217
 	}
200 218
 	
@@ -204,7 +222,8 @@  discard block
 block discarded – undo
204 222
 	 * 
205 223
 	 * @param $value The key of the field to add as a query string parameter.
206 224
 	 */
207
-	function setActionFieldName($value) {
225
+	function setActionFieldName($value)
226
+	{
208 227
 		$this->actionField= $value;
209 228
 	}
210 229
 	
@@ -214,7 +233,8 @@  discard block
 block discarded – undo
214 233
 	 * @param $value An Array of column widths in the order of the keys in the
215 234
 	 * 			source table array.
216 235
 	 */
217
-	function setColumnWidths($widthArray) {
236
+	function setColumnWidths($widthArray)
237
+	{
218 238
 		$this->columnWidths= $widthArray;
219 239
 	}
220 240
 	
@@ -223,7 +243,8 @@  discard block
 block discarded – undo
223 243
 	 * 
224 244
 	 * @param $value Indicates the INPUT form element type attribute.
225 245
 	 */
226
-	function setSelectedValues($valueArray) {
246
+	function setSelectedValues($valueArray)
247
+	{
227 248
 		$this->selectedValues= $valueArray;
228 249
 	}
229 250
 	
@@ -233,7 +254,8 @@  discard block
 block discarded – undo
233 254
 	 * 
234 255
 	 * @param $value A string of additional content.
235 256
 	 */
236
-	function setExtra($value) {
257
+	function setExtra($value)
258
+	{
237 259
 		$this->extra= $value;
238 260
 	}
239 261
 	
@@ -242,7 +264,8 @@  discard block
 block discarded – undo
242 264
 	 * 
243 265
 	 * @param $columnPosition The index of the column to get the width for.
244 266
 	 */
245
-	function getColumnWidth($columnPosition) {
267
+	function getColumnWidth($columnPosition)
268
+	{
246 269
 		$currentWidth= '';
247 270
 		if (is_array($this->columnWidths)) {
248 271
 			$currentWidth= $this->columnWidths[$columnPosition] ? ' width="'.$this->columnWidths[$columnPosition].'" ' : '';
@@ -255,7 +278,8 @@  discard block
 block discarded – undo
255 278
 	 * 
256 279
 	 * @param $value The position of the current row being rendered.
257 280
 	 */
258
-	function determineRowClass($position) {
281
+	function determineRowClass($position)
282
+	{
259 283
 		switch ($this->rowAlternatingScheme) {
260 284
 			case 'ODD' :
261 285
 				$modRemainder= 1;
@@ -278,7 +302,8 @@  discard block
 block discarded – undo
278 302
 	 * 
279 303
 	 * @param $value Indicates the INPUT form element type attribute.
280 304
 	 */
281
-	function getCellAction($currentActionFieldValue) {
305
+	function getCellAction($currentActionFieldValue)
306
+	{
282 307
 		if ($this->cellAction) {
283 308
 			$cellAction= ' onClick="javascript:window.location=\''.$this->cellAction.$this->actionField.'='.urlencode($currentActionFieldValue).'\'" ';
284 309
 		}
@@ -291,7 +316,8 @@  discard block
 block discarded – undo
291 316
 	 * @param $currentActionFieldValue The value to be applied to the link action.
292 317
 	 * @param $value The value of the cell.
293 318
 	 */
294
-	function createCellText($currentActionFieldValue, $value) {
319
+	function createCellText($currentActionFieldValue, $value)
320
+	{
295 321
 		$cell .= $value;
296 322
 		if ($this->linkAction) {
297 323
 			$cell= '<a href="'.$this->linkAction.$this->actionField.'='.urlencode($currentActionFieldValue).'">'.$cell.'</a>';
@@ -303,7 +329,8 @@  discard block
 block discarded – undo
303 329
 	 * Sets an option to generate a check all link when checkbox is indicated 
304 330
 	 * as the table formElementType.
305 331
 	 */
306
-	function setAllOption() {
332
+	function setAllOption()
333
+	{
307 334
 		$this->allOption= 1;
308 335
 	}
309 336
 	
@@ -312,7 +339,8 @@  discard block
 block discarded – undo
312 339
 	 * 
313 340
 	 * @param $value Indicates the INPUT form element type attribute.
314 341
 	 */
315
-	function prepareLink($link) {
342
+	function prepareLink($link)
343
+	{
316 344
 		if (strstr($link, '?')) {
317 345
 			$end= '&';
318 346
 		} else {
@@ -331,7 +359,8 @@  discard block
 block discarded – undo
331 359
 	 * the $fieldsArray where the values represent the alt heading content
332 360
 	 * for each column.
333 361
 	 */
334
-	function create($fieldsArray, $fieldHeadersArray=array(),$linkpage="") {
362
+	function create($fieldsArray, $fieldHeadersArray=array(),$linkpage="")
363
+	{
335 364
 	global $_lang;
336 365
 		if (is_array($fieldsArray)) {
337 366
 			$i= 0;
@@ -367,7 +396,8 @@  discard block
 block discarded – undo
367 396
 			if ($this->formElementType) {
368 397
 				$table= "\n".'<form id="'.$this->formName.'" name="'.$this->formName.'" action="'.$this->formAction.'" method="POST">'.$table;
369 398
 			}
370
-			if (strlen($this->pageNav) > 1) {//changed to display the pagination if exists.
399
+			if (strlen($this->pageNav) > 1) {
400
+//changed to display the pagination if exists.
371 401
 				/* commented this part because of cookie
372 402
 				$table .= '<div id="max-display-records" ><select style="display:inline" onchange="javascript:updatePageSize(this[this.selectedIndex].value);">';
373 403
 				$pageSizes= array (10, 25, 50, 100, 250);
@@ -414,7 +444,8 @@  discard block
 block discarded – undo
414 444
 	 * @param $numRecords The number of records to show per page.
415 445
 	 * @param $qs An optional query string to be appended to the paging links
416 446
 	 */
417
-	function createPagingNavigation($numRecords, $qs='') {
447
+	function createPagingNavigation($numRecords, $qs='')
448
+	{
418 449
 		global $_lang;
419 450
 		$currentPage= (is_numeric($_GET['page']) ? $_GET['page'] : 1);
420 451
 		$numPages= ceil($numRecords / MAX_DISPLAY_RECORDS_NUM);
@@ -429,10 +460,11 @@  discard block
 block discarded – undo
429 460
 			$offset= -4 + ($currentPage < 5 ? (5 - $currentPage) : 0);
430 461
 			$i= 1;
431 462
 			while ($i < 10 && ($currentPage + $offset <= $numPages)) {
432
-				if ($currentPage == $currentPage + $offset)
433
-					$nav .= $this->createPageLink($currentURL, $currentPage + $offset, $currentPage + $offset, true);
434
-				else
435
-					$nav .= $this->createPageLink($currentURL, $currentPage + $offset, $currentPage + $offset);
463
+				if ($currentPage == $currentPage + $offset) {
464
+									$nav .= $this->createPageLink($currentURL, $currentPage + $offset, $currentPage + $offset, true);
465
+				} else {
466
+									$nav .= $this->createPageLink($currentURL, $currentPage + $offset, $currentPage + $offset);
467
+				}
436 468
 				$i ++;
437 469
 				$offset ++;
438 470
 			}
@@ -455,11 +487,14 @@  discard block
 block discarded – undo
455 487
 	 * @param $currentPage Indicates if the link is to the current page.
456 488
 	 * @param $qs And optional query string to be appended to the link.
457 489
 	 */
458
-	function createPageLink($link='', $pageNum, $displayText, $currentPage=false, $qs='') {
490
+	function createPageLink($link='', $pageNum, $displayText, $currentPage=false, $qs='')
491
+	{
459 492
 		global $modx;
460 493
 		$orderBy= !empty($_GET['orderby'])? '&orderby=' . $_GET['orderby']: '';
461 494
 		$orderDir= !empty($_GET['orderdir'])? '&orderdir=' . $_GET['orderdir']: '';
462
-		if (!empty($qs)) $qs= "?$qs";
495
+		if (!empty($qs)) {
496
+		    $qs= "?$qs";
497
+		}
463 498
 		$link= empty($link)? $modx->makeUrl($modx->documentIdentifier, $modx->documentObject['alias'], $qs . "page=$pageNum$orderBy$orderDir"): $this->prepareLink($link) . "page=$pageNum";
464 499
 		$nav .= '<li'.($currentPage? ' class="currentPage"': '').'><a'.($currentPage? ' class="currentPage"': '').' href="'.$link.'">'.$displayText.'</a></li>'."\n";
465 500
 		return $nav;
@@ -472,7 +507,8 @@  discard block
 block discarded – undo
472 507
 	 * @param $isChecked Indicates if the checked attribute should apply to the 
473 508
 	 * element.
474 509
 	 */
475
-	function addFormField($value, $isChecked) {
510
+	function addFormField($value, $isChecked)
511
+	{
476 512
 		if ($this->formElementType) {
477 513
 			$checked= $isChecked? "checked ": "";
478 514
 			$field= "\t\t".'<td><input type="'.$this->formElementType.'" name="'. ($this->formElementName ? $this->formElementName : $value).'"  value="'.$value.'" '.$checked.'/></td>'."\n";
@@ -484,7 +520,8 @@  discard block
 block discarded – undo
484 520
 	 * Generates the proper LIMIT clause for queries to retrieve paged results in
485 521
 	 * a MakeTable $fieldsArray.
486 522
 	 */
487
-	function handlePaging() {
523
+	function handlePaging()
524
+	{
488 525
 		$offset= (is_numeric($_GET['page']) && $_GET['page'] > 0) ? $_GET['page'] - 1 : 0;
489 526
 		$limitClause= ' LIMIT '. ($offset * MAX_DISPLAY_RECORDS_NUM).', '.MAX_DISPLAY_RECORDS_NUM;
490 527
 		return $limitClause;
@@ -496,7 +533,8 @@  discard block
 block discarded – undo
496 533
 	 * 
497 534
 	 * @param $natural_order If true, the results are returned in natural order.
498 535
 	 */
499
-	function handleSorting($natural_order=false) {
536
+	function handleSorting($natural_order=false)
537
+	{
500 538
 		$orderByClause= '';
501 539
 		if (!$natural_order) {
502 540
 			$orderby= !empty($_GET['orderby'])? $_GET['orderby']: "id";
@@ -514,7 +552,8 @@  discard block
 block discarded – undo
514 552
 	 * @param $text The text for the link (e.g. table column header).
515 553
 	 * @param $qs An optional query string to append to the order by link.
516 554
 	 */
517
-	function prepareOrderByLink($key, $text, $qs='') {
555
+	function prepareOrderByLink($key, $text, $qs='')
556
+	{
518 557
 		global $modx;
519 558
 		if (!empty($_GET['orderdir'])) {
520 559
 			$orderDir= strtolower($_GET['orderdir'])=='desc'? '&orderdir=asc': '&orderdir=desc';
@@ -522,7 +561,9 @@  discard block
 block discarded – undo
522 561
 			$orderDir= '&orderdir=asc';
523 562
 		}
524 563
 		if (!empty($qs)) {
525
-			if (!strrpos($qs, '&')==strlen($qs)-1) $qs.= '&'; 
564
+			if (!strrpos($qs, '&')==strlen($qs)-1) {
565
+			    $qs.= '&';
566
+			}
526 567
 		}
527 568
 		return '<a href="[~'.$modx->documentIdentifier.'~]?'.$qs.'orderby='.$key.$orderDir.'">'.$text.'</a>';
528 569
 	}
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.