@@ -1,25 +1,25 @@ discard block |
||
1 | 1 | <?php |
2 | -class DBAPI { |
|
2 | +class DBAPI{ |
|
3 | 3 | var $conn; |
4 | 4 | var $config; |
5 | 5 | var $lastQuery; |
6 | 6 | var $isConnected; |
7 | 7 | |
8 | - function __construct($host='', $dbase='', $uid='', $pwd='', $pre=NULL, $charset='', $connection_method='SET CHARACTER SET') { |
|
8 | + function __construct($host = '', $dbase = '', $uid = '', $pwd = '', $pre = NULL, $charset = '', $connection_method = 'SET CHARACTER SET'){ |
|
9 | 9 | $this->config['host'] = $host ? $host : $GLOBALS['database_server']; |
10 | 10 | $this->config['dbase'] = $dbase ? $dbase : $GLOBALS['dbase']; |
11 | 11 | $this->config['user'] = $uid ? $uid : $GLOBALS['database_user']; |
12 | 12 | $this->config['pass'] = $pwd ? $pwd : $GLOBALS['database_password']; |
13 | 13 | $this->config['charset'] = $charset ? $charset : $GLOBALS['database_connection_charset']; |
14 | - $this->config['connection_method'] = $this->_dbconnectionmethod = (isset($GLOBALS['database_connection_method']) ? $GLOBALS['database_connection_method'] : $connection_method); |
|
14 | + $this->config['connection_method'] = $this->_dbconnectionmethod = (isset($GLOBALS['database_connection_method']) ? $GLOBALS['database_connection_method'] : $connection_method); |
|
15 | 15 | $this->config['table_prefix'] = ($pre !== NULL) ? $pre : $GLOBALS['table_prefix']; |
16 | 16 | } |
17 | 17 | |
18 | - function connect($host = '', $dbase = '', $uid = '', $pwd = '', $tmp = 0) { |
|
18 | + function connect($host = '', $dbase = '', $uid = '', $pwd = '', $tmp = 0){ |
|
19 | 19 | global $modx; |
20 | - $uid = $uid ? $uid : $this->config['user']; |
|
21 | - $pwd = $pwd ? $pwd : $this->config['pass']; |
|
22 | - $host = $host ? $host : $this->config['host']; |
|
20 | + $uid = $uid ? $uid : $this->config['user']; |
|
21 | + $pwd = $pwd ? $pwd : $this->config['pass']; |
|
22 | + $host = $host ? $host : $this->config['host']; |
|
23 | 23 | $dbase = $dbase ? $dbase : $this->config['dbase']; |
24 | 24 | $dbase = trim($dbase, '`'); // remove the `` chars |
25 | 25 | $charset = $this->config['charset']; |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | $ua = $modx->htmlspecialchars($_SERVER['HTTP_USER_AGENT']); |
38 | 38 | $referer = $modx->htmlspecialchars($_SERVER['HTTP_REFERER']); |
39 | 39 | $modx->sendmail(array( |
40 | - 'subject' => 'Missing to create the database connection! from ' . $modx->config['site_name'], |
|
40 | + 'subject' => 'Missing to create the database connection! from '.$modx->config['site_name'], |
|
41 | 41 | 'body' => "{$logtitle}\n{$request_uri}\n{$ua}\n{$referer}", |
42 | 42 | 'type' => 'text' |
43 | 43 | )); |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | sleep(1); |
47 | 47 | $safe_count++; |
48 | 48 | } |
49 | - } while (!$this->conn && $safe_count<3); |
|
49 | + } while (!$this->conn && $safe_count < 3); |
|
50 | 50 | if (!$this->conn) { |
51 | 51 | $modx->messageQuit("Failed to create the database connection!"); |
52 | 52 | exit; |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | $tend = $modx->getMicroTime(); |
56 | 56 | $totaltime = $tend - $tstart; |
57 | 57 | if ($modx->dumpSQL) { |
58 | - $modx->queryCode .= "<fieldset style='text-align:left'><legend>Database connection</legend>" . sprintf("Database connection was created in %2.4f s", $totaltime) . "</fieldset><br />"; |
|
58 | + $modx->queryCode .= "<fieldset style='text-align:left'><legend>Database connection</legend>".sprintf("Database connection was created in %2.4f s", $totaltime)."</fieldset><br />"; |
|
59 | 59 | } |
60 | 60 | $this->conn->set_charset($this->config['charset']); |
61 | 61 | $this->isConnected = true; |
@@ -63,15 +63,15 @@ discard block |
||
63 | 63 | } |
64 | 64 | } |
65 | 65 | |
66 | - function disconnect() { |
|
66 | + function disconnect(){ |
|
67 | 67 | $this->conn->close(); |
68 | 68 | $this->conn = null; |
69 | 69 | $this->isConnected = false; |
70 | 70 | } |
71 | 71 | |
72 | - function escape($s, $safecount=0) { |
|
72 | + function escape($s, $safecount = 0){ |
|
73 | 73 | $safecount++; |
74 | - if (1000<$safecount) exit("Too many loops '{$safecount}'"); |
|
74 | + if (1000 < $safecount) exit("Too many loops '{$safecount}'"); |
|
75 | 75 | if (empty ($this->conn) || !is_object($this->conn)) { |
76 | 76 | $this->connect(); |
77 | 77 | } |
@@ -89,17 +89,17 @@ discard block |
||
89 | 89 | return $s; |
90 | 90 | } |
91 | 91 | |
92 | - function query($sql,$watchError=true) { |
|
92 | + function query($sql, $watchError = true){ |
|
93 | 93 | global $modx; |
94 | 94 | if (empty ($this->conn) || !is_object($this->conn)) { |
95 | 95 | $this->connect(); |
96 | 96 | } |
97 | 97 | $tstart = $modx->getMicroTime(); |
98 | - if(is_array($sql)) $sql = join("\n", $sql); |
|
98 | + if (is_array($sql)) $sql = join("\n", $sql); |
|
99 | 99 | $this->lastQuery = $sql; |
100 | 100 | if (!($result = $this->conn->query($sql))) { |
101 | - if(!$watchError) return; |
|
102 | - switch(mysqli_errno($this->conn)) { |
|
101 | + if (!$watchError) return; |
|
102 | + switch (mysqli_errno($this->conn)) { |
|
103 | 103 | case 1054: |
104 | 104 | case 1060: |
105 | 105 | case 1061: |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | case 1091: |
108 | 108 | break; |
109 | 109 | default: |
110 | - $modx->messageQuit('Execution of a query to the database failed - ' . $this->getLastError(), $sql); |
|
110 | + $modx->messageQuit('Execution of a query to the database failed - '.$this->getLastError(), $sql); |
|
111 | 111 | } |
112 | 112 | } else { |
113 | 113 | $tend = $modx->getMicroTime(); |
@@ -119,14 +119,14 @@ discard block |
||
119 | 119 | $debug_path = array(); |
120 | 120 | foreach ($debug as $line) $debug_path[] = $line['function']; |
121 | 121 | $debug_path = implode(' > ', array_reverse($debug_path)); |
122 | - $modx->queryCode .= "<fieldset style='text-align:left'><legend>Query " . ($modx->executedQueries + 1) . " - " . sprintf("%2.2f ms", $totaltime*1000) . "</legend>"; |
|
123 | - $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>'; |
|
129 | - $modx->queryCode .= 'Functions Path => ' . $debug_path . '<br>'; |
|
122 | + $modx->queryCode .= "<fieldset style='text-align:left'><legend>Query ".($modx->executedQueries + 1)." - ".sprintf("%2.2f ms", $totaltime * 1000)."</legend>"; |
|
123 | + $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>'; |
|
129 | + $modx->queryCode .= 'Functions Path => '.$debug_path.'<br>'; |
|
130 | 130 | $modx->queryCode .= "</fieldset><br />"; |
131 | 131 | } |
132 | 132 | $modx->executedQueries = $modx->executedQueries + 1; |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | } |
135 | 135 | } |
136 | 136 | |
137 | - function delete($from, $where='', $orderby='', $limit = '') { |
|
137 | + function delete($from, $where = '', $orderby = '', $limit = ''){ |
|
138 | 138 | global $modx; |
139 | 139 | if (!$from) { |
140 | 140 | $modx->messageQuit("Empty \$from parameters in DBAPI::delete()."); |
@@ -143,19 +143,19 @@ discard block |
||
143 | 143 | $where = trim($where); |
144 | 144 | $orderby = trim($orderby); |
145 | 145 | $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}"; |
|
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}"; |
|
149 | 149 | return $this->query("DELETE FROM {$from} {$where} {$orderby} {$limit}"); |
150 | 150 | } |
151 | 151 | } |
152 | 152 | |
153 | - function select($fields = "*", $from = "", $where = "", $orderby = "", $limit = "") { |
|
153 | + function select($fields = "*", $from = "", $where = "", $orderby = "", $limit = ""){ |
|
154 | 154 | global $modx; |
155 | 155 | |
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); |
|
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); |
|
159 | 159 | |
160 | 160 | if (!$from) { |
161 | 161 | $modx->messageQuit("Empty \$from parameters in DBAPI::select()."); |
@@ -167,13 +167,13 @@ discard block |
||
167 | 167 | $where = trim($where); |
168 | 168 | $orderby = trim($orderby); |
169 | 169 | $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}"; |
|
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}"; |
|
173 | 173 | return $this->query("SELECT {$fields} FROM {$from} {$where} {$orderby} {$limit}"); |
174 | 174 | } |
175 | 175 | |
176 | - function update($fields, $table, $where = "") { |
|
176 | + function update($fields, $table, $where = ""){ |
|
177 | 177 | global $modx; |
178 | 178 | if (!$table) { |
179 | 179 | $modx->messageQuit("Empty \$table parameter in DBAPI::update()."); |
@@ -181,22 +181,22 @@ discard block |
||
181 | 181 | $table = $this->replaceFullTableName($table); |
182 | 182 | if (is_array($fields)) { |
183 | 183 | foreach ($fields as $key => $value) { |
184 | - if(is_null($value) || strtolower($value) === 'null'){ |
|
184 | + if (is_null($value) || strtolower($value) === 'null') { |
|
185 | 185 | $flds = 'NULL'; |
186 | - }else{ |
|
187 | - $flds = "'" . $value . "'"; |
|
186 | + } else { |
|
187 | + $flds = "'".$value."'"; |
|
188 | 188 | } |
189 | 189 | $fields[$key] = "`{$key}` = ".$flds; |
190 | 190 | } |
191 | 191 | $fields = implode(",", $fields); |
192 | 192 | } |
193 | 193 | $where = trim($where); |
194 | - if($where!=='' && stripos($where, 'WHERE')!==0) $where = "WHERE {$where}"; |
|
194 | + if ($where !== '' && stripos($where, 'WHERE') !== 0) $where = "WHERE {$where}"; |
|
195 | 195 | return $this->query("UPDATE {$table} SET {$fields} {$where}"); |
196 | 196 | } |
197 | 197 | } |
198 | 198 | |
199 | - function insert($fields, $intotable, $fromfields = "*", $fromtable = "", $where = "", $limit = "") { |
|
199 | + function insert($fields, $intotable, $fromfields = "*", $fromtable = "", $where = "", $limit = ""){ |
|
200 | 200 | global $modx; |
201 | 201 | if (!$intotable) { |
202 | 202 | $modx->messageQuit("Empty \$intotable parameters in DBAPI::insert()."); |
@@ -213,68 +213,68 @@ discard block |
||
213 | 213 | $fields = "(".implode(",", array_keys($fields)).")"; |
214 | 214 | $where = trim($where); |
215 | 215 | $limit = trim($limit); |
216 | - if($where!=='' && stripos($where, 'WHERE')!==0) $where = "WHERE {$where}"; |
|
217 | - if($limit!=='' && stripos($limit, 'LIMIT')!==0) $limit = "LIMIT {$limit}"; |
|
216 | + if ($where !== '' && stripos($where, 'WHERE') !== 0) $where = "WHERE {$where}"; |
|
217 | + if ($limit !== '' && stripos($limit, 'LIMIT') !== 0) $limit = "LIMIT {$limit}"; |
|
218 | 218 | $rt = $this->query("INSERT INTO {$intotable} {$fields} SELECT {$fromfields} FROM {$fromtable} {$where} {$limit}"); |
219 | 219 | } |
220 | 220 | } |
221 | - if (($lid = $this->getInsertId())===false) $modx->messageQuit("Couldn't get last insert key!"); |
|
221 | + if (($lid = $this->getInsertId()) === false) $modx->messageQuit("Couldn't get last insert key!"); |
|
222 | 222 | return $lid; |
223 | 223 | } |
224 | 224 | } |
225 | 225 | |
226 | - function save($fields, $table, $where='') { // This is similar to "replace into table". |
|
226 | + function save($fields, $table, $where = ''){ // This is similar to "replace into table". |
|
227 | 227 | |
228 | - if($where === '') $mode = 'insert'; |
|
229 | - elseif($this->getRecordCount($this->select('*',$table,$where))==0) $mode = 'insert'; |
|
228 | + if ($where === '') $mode = 'insert'; |
|
229 | + elseif ($this->getRecordCount($this->select('*', $table, $where)) == 0) $mode = 'insert'; |
|
230 | 230 | else $mode = 'update'; |
231 | 231 | |
232 | - if($mode==='insert') return $this->insert($fields, $table); |
|
232 | + if ($mode === 'insert') return $this->insert($fields, $table); |
|
233 | 233 | else return $this->update($fields, $table, $where); |
234 | 234 | } |
235 | 235 | |
236 | - function isResult($rs) { |
|
236 | + function isResult($rs){ |
|
237 | 237 | return is_object($rs); |
238 | 238 | } |
239 | 239 | |
240 | - function freeResult($rs) { |
|
240 | + function freeResult($rs){ |
|
241 | 241 | $rs->free_result(); |
242 | 242 | } |
243 | 243 | |
244 | - function numFields($rs) { |
|
244 | + function numFields($rs){ |
|
245 | 245 | return $rs->field_count; |
246 | 246 | } |
247 | 247 | |
248 | - function fieldName($rs,$col=0) { |
|
248 | + function fieldName($rs, $col = 0){ |
|
249 | 249 | $field = $rs->fetch_field_direct($col); |
250 | 250 | return $field->name; |
251 | 251 | } |
252 | 252 | |
253 | - function selectDb($name) { |
|
253 | + function selectDb($name){ |
|
254 | 254 | $this->conn->select_db($name); |
255 | 255 | } |
256 | 256 | |
257 | 257 | |
258 | - function getInsertId($conn=NULL) { |
|
259 | - if (!is_object($conn)) $conn =& $this->conn; |
|
258 | + function getInsertId($conn = NULL){ |
|
259 | + if (!is_object($conn)) $conn = & $this->conn; |
|
260 | 260 | return $conn->insert_id; |
261 | 261 | } |
262 | 262 | |
263 | - function getAffectedRows($conn=NULL) { |
|
264 | - if (!is_object($conn)) $conn =& $this->conn; |
|
263 | + function getAffectedRows($conn = NULL){ |
|
264 | + if (!is_object($conn)) $conn = & $this->conn; |
|
265 | 265 | return $conn->affected_rows; |
266 | 266 | } |
267 | 267 | |
268 | - function getLastError($conn=NULL) { |
|
269 | - if (!is_object($conn)) $conn =& $this->conn; |
|
268 | + function getLastError($conn = NULL){ |
|
269 | + if (!is_object($conn)) $conn = & $this->conn; |
|
270 | 270 | return $conn->error; |
271 | 271 | } |
272 | 272 | |
273 | - function getRecordCount($ds) { |
|
273 | + function getRecordCount($ds){ |
|
274 | 274 | return (is_object($ds)) ? $ds->num_rows : 0; |
275 | 275 | } |
276 | 276 | |
277 | - function getRow($ds, $mode = 'assoc') { |
|
277 | + function getRow($ds, $mode = 'assoc'){ |
|
278 | 278 | if (is_object($ds)) { |
279 | 279 | if ($mode == 'assoc') { |
280 | 280 | return $ds->fetch_assoc(); |
@@ -291,12 +291,12 @@ discard block |
||
291 | 291 | } |
292 | 292 | } |
293 | 293 | |
294 | - function getColumn($name, $dsq) { |
|
294 | + function getColumn($name, $dsq){ |
|
295 | 295 | if (!is_object($dsq)) { |
296 | 296 | $dsq = $this->query($dsq); |
297 | 297 | } |
298 | 298 | if ($dsq) { |
299 | - $col = array (); |
|
299 | + $col = array(); |
|
300 | 300 | while ($row = $this->getRow($dsq)) { |
301 | 301 | $col[] = $row[$name]; |
302 | 302 | } |
@@ -304,12 +304,12 @@ discard block |
||
304 | 304 | } |
305 | 305 | } |
306 | 306 | |
307 | - function getColumnNames($dsq) { |
|
307 | + function getColumnNames($dsq){ |
|
308 | 308 | if (!is_object($dsq)) { |
309 | 309 | $dsq = $this->query($dsq); |
310 | 310 | } |
311 | 311 | if ($dsq) { |
312 | - $names = array (); |
|
312 | + $names = array(); |
|
313 | 313 | $limit = $this->numFields($dsq); |
314 | 314 | for ($i = 0; $i < $limit; $i++) { |
315 | 315 | $names[] = $this->fieldName($dsq, $i); |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | } |
319 | 319 | } |
320 | 320 | |
321 | - function getValue($dsq) { |
|
321 | + function getValue($dsq){ |
|
322 | 322 | if (!is_object($dsq)) { |
323 | 323 | $dsq = $this->query($dsq); |
324 | 324 | } |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | } |
329 | 329 | } |
330 | 330 | |
331 | - function getTableMetaData($table) { |
|
331 | + function getTableMetaData($table){ |
|
332 | 332 | $metadata = false; |
333 | 333 | if (!empty ($table)) { |
334 | 334 | $sql = "SHOW FIELDS FROM $table"; |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | return $metadata; |
343 | 343 | } |
344 | 344 | |
345 | - function prepareDate($timestamp, $fieldType = 'DATETIME') { |
|
345 | + function prepareDate($timestamp, $fieldType = 'DATETIME'){ |
|
346 | 346 | $date = ''; |
347 | 347 | if (!$timestamp === false && $timestamp > 0) { |
348 | 348 | switch ($fieldType) { |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | return $date; |
364 | 364 | } |
365 | 365 | |
366 | - function makeArray($rs='',$index=false){ |
|
366 | + function makeArray($rs = '', $index = false){ |
|
367 | 367 | if (!$rs) return false; |
368 | 368 | $rsArray = array(); |
369 | 369 | $iterator = 0; |
@@ -375,17 +375,17 @@ discard block |
||
375 | 375 | return $rsArray; |
376 | 376 | } |
377 | 377 | |
378 | - function getVersion() { |
|
378 | + function getVersion(){ |
|
379 | 379 | return $this->conn->server_info; |
380 | 380 | } |
381 | 381 | |
382 | - function replaceFullTableName($str,$force=null) { |
|
382 | + function replaceFullTableName($str, $force = null){ |
|
383 | 383 | $str = trim($str); |
384 | - $dbase = trim($this->config['dbase'],'`'); |
|
384 | + $dbase = trim($this->config['dbase'], '`'); |
|
385 | 385 | $prefix = $this->config['table_prefix']; |
386 | 386 | if (!empty($force)) { |
387 | 387 | $result = "`{$dbase}`.`{$prefix}{$str}`"; |
388 | - } elseif (strpos($str,'[+prefix+]')!==false) { |
|
388 | + } elseif (strpos($str, '[+prefix+]') !== false) { |
|
389 | 389 | $result = preg_replace('@\[\+prefix\+\]([0-9a-zA-Z_]+)@', "`{$dbase}`.`{$prefix}$1`", $str); |
390 | 390 | } else { |
391 | 391 | $result = $str; |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | return $result; |
394 | 394 | } |
395 | 395 | |
396 | - function optimize($table_name) { |
|
396 | + function optimize($table_name){ |
|
397 | 397 | $rs = $this->query("OPTIMIZE TABLE {$table_name}"); |
398 | 398 | if ($rs) { |
399 | 399 | $rs = $this->query("ALTER TABLE {$table_name}"); |
@@ -401,30 +401,30 @@ discard block |
||
401 | 401 | return $rs; |
402 | 402 | } |
403 | 403 | |
404 | - function truncate($table_name) { |
|
404 | + function truncate($table_name){ |
|
405 | 405 | $rs = $this->query("TRUNCATE {$table_name}"); |
406 | 406 | return $rs; |
407 | 407 | } |
408 | 408 | |
409 | - function dataSeek($result, $row_number) { |
|
409 | + function dataSeek($result, $row_number){ |
|
410 | 410 | return $result->data_seek($row_number); |
411 | 411 | } |
412 | 412 | |
413 | - function _getFieldsStringFromArray($fields=array()) { |
|
413 | + function _getFieldsStringFromArray($fields = array()){ |
|
414 | 414 | |
415 | - if(empty($fields)) return '*'; |
|
415 | + if (empty($fields)) return '*'; |
|
416 | 416 | |
417 | 417 | $_ = array(); |
418 | - foreach($fields as $k=>$v) { |
|
419 | - if($k!==$v) $_[] = "{$v} as {$k}"; |
|
418 | + foreach ($fields as $k=>$v) { |
|
419 | + if ($k !== $v) $_[] = "{$v} as {$k}"; |
|
420 | 420 | else $_[] = $v; |
421 | 421 | } |
422 | 422 | return join(',', $_); |
423 | 423 | } |
424 | 424 | |
425 | - function _getFromStringFromArray($tables=array()) { |
|
425 | + function _getFromStringFromArray($tables = array()){ |
|
426 | 426 | $_ = array(); |
427 | - foreach($tables as $k=>$v) { |
|
427 | + foreach ($tables as $k=>$v) { |
|
428 | 428 | $_[] = $v; |
429 | 429 | } |
430 | 430 | return join(' ', $_); |
@@ -5,7 +5,7 @@ |
||
5 | 5 | * Time: 14:24 |
6 | 6 | */ |
7 | 7 | |
8 | -if(include_once(MODX_MANAGER_PATH . 'includes/extenders/export.class.inc.php')) |
|
8 | +if (include_once(MODX_MANAGER_PATH.'includes/extenders/export.class.inc.php')) |
|
9 | 9 | { |
10 | 10 | $this->export = new EXPORT_SITE; |
11 | 11 | return true; |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -class DBAPI { |
|
8 | +class DBAPI{ |
|
9 | 9 | |
10 | 10 | var $conn; |
11 | 11 | var $config; |
@@ -16,13 +16,13 @@ discard block |
||
16 | 16 | * @name: DBAPI |
17 | 17 | * |
18 | 18 | */ |
19 | - function __construct($host='',$dbase='', $uid='',$pwd='',$pre=NULL,$charset='',$connection_method='SET CHARACTER SET') { |
|
19 | + function __construct($host = '', $dbase = '', $uid = '', $pwd = '', $pre = NULL, $charset = '', $connection_method = 'SET CHARACTER SET'){ |
|
20 | 20 | $this->config['host'] = $host ? $host : $GLOBALS['database_server']; |
21 | 21 | $this->config['dbase'] = $dbase ? $dbase : $GLOBALS['dbase']; |
22 | 22 | $this->config['user'] = $uid ? $uid : $GLOBALS['database_user']; |
23 | 23 | $this->config['pass'] = $pwd ? $pwd : $GLOBALS['database_password']; |
24 | 24 | $this->config['charset'] = $charset ? $charset : $GLOBALS['database_connection_charset']; |
25 | - $this->config['connection_method'] = $this->_dbconnectionmethod = (isset($GLOBALS['database_connection_method']) ? $GLOBALS['database_connection_method'] : $connection_method); |
|
25 | + $this->config['connection_method'] = $this->_dbconnectionmethod = (isset($GLOBALS['database_connection_method']) ? $GLOBALS['database_connection_method'] : $connection_method); |
|
26 | 26 | $this->config['table_prefix'] = ($pre !== NULL) ? $pre : $GLOBALS['table_prefix']; |
27 | 27 | $this->initDataTypes(); |
28 | 28 | } |
@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | * @desc: called in the constructor to set up arrays containing the types |
33 | 33 | * of database fields that can be used with specific PHP types |
34 | 34 | */ |
35 | - function initDataTypes() { |
|
36 | - $this->dataTypes['numeric'] = array ( |
|
35 | + function initDataTypes(){ |
|
36 | + $this->dataTypes['numeric'] = array( |
|
37 | 37 | 'INT', |
38 | 38 | 'INTEGER', |
39 | 39 | 'TINYINT', |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | 'BIGINT', |
50 | 50 | 'BIT' |
51 | 51 | ); |
52 | - $this->dataTypes['string'] = array ( |
|
52 | + $this->dataTypes['string'] = array( |
|
53 | 53 | 'CHAR', |
54 | 54 | 'VARCHAR', |
55 | 55 | 'BINARY', |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | 'ENUM', |
66 | 66 | 'SET' |
67 | 67 | ); |
68 | - $this->dataTypes['date'] = array ( |
|
68 | + $this->dataTypes['date'] = array( |
|
69 | 69 | 'DATE', |
70 | 70 | 'DATETIME', |
71 | 71 | 'TIMESTAMP', |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * @name: connect |
79 | 79 | * |
80 | 80 | */ |
81 | - function connect($host = '', $dbase = '', $uid = '', $pwd = '', $persist = 0) { |
|
81 | + function connect($host = '', $dbase = '', $uid = '', $pwd = '', $persist = 0){ |
|
82 | 82 | global $modx; |
83 | 83 | $uid = $uid ? $uid : $this->config['user']; |
84 | 84 | $pwd = $pwd ? $pwd : $this->config['pass']; |
@@ -88,16 +88,16 @@ discard block |
||
88 | 88 | $connection_method = $this->config['connection_method']; |
89 | 89 | $tstart = $modx->getMicroTime(); |
90 | 90 | $safe_count = 0; |
91 | - while(!$this->conn && $safe_count<3) |
|
91 | + while (!$this->conn && $safe_count < 3) |
|
92 | 92 | { |
93 | - if($persist!=0) $this->conn = mysql_pconnect($host, $uid, $pwd); |
|
93 | + if ($persist != 0) $this->conn = mysql_pconnect($host, $uid, $pwd); |
|
94 | 94 | else $this->conn = mysql_connect($host, $uid, $pwd, true); |
95 | 95 | |
96 | - if(!$this->conn) |
|
96 | + if (!$this->conn) |
|
97 | 97 | { |
98 | - if(isset($modx->config['send_errormail']) && $modx->config['send_errormail'] !== '0') |
|
98 | + if (isset($modx->config['send_errormail']) && $modx->config['send_errormail'] !== '0') |
|
99 | 99 | { |
100 | - if($modx->config['send_errormail'] <= 2) |
|
100 | + if ($modx->config['send_errormail'] <= 2) |
|
101 | 101 | { |
102 | 102 | $logtitle = 'Failed to create the database connection!'; |
103 | 103 | $request_uri = $modx->htmlspecialchars($_SERVER['REQUEST_URI']); |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | $referer = $modx->htmlspecialchars($_SERVER['HTTP_REFERER']); |
106 | 106 | |
107 | 107 | $modx->sendmail(array( |
108 | - 'subject' => 'Missing to create the database connection! from ' . $modx->config['site_name'], |
|
108 | + 'subject' => 'Missing to create the database connection! from '.$modx->config['site_name'], |
|
109 | 109 | 'body' => "{$logtitle}\n{$request_uri}\n{$ua}\n{$referer}", |
110 | 110 | 'type' => 'text') |
111 | 111 | ); |
@@ -119,16 +119,16 @@ discard block |
||
119 | 119 | $modx->messageQuit("Failed to create the database connection!"); |
120 | 120 | exit; |
121 | 121 | } else { |
122 | - $dbase = trim($dbase,'`'); // remove the `` chars |
|
122 | + $dbase = trim($dbase, '`'); // remove the `` chars |
|
123 | 123 | if (!@ mysql_select_db($dbase, $this->conn)) { |
124 | - $modx->messageQuit("Failed to select the database '" . $dbase . "'!"); |
|
124 | + $modx->messageQuit("Failed to select the database '".$dbase."'!"); |
|
125 | 125 | exit; |
126 | 126 | } |
127 | 127 | @mysql_query("{$connection_method} {$charset}", $this->conn); |
128 | 128 | $tend = $modx->getMicroTime(); |
129 | 129 | $totaltime = $tend - $tstart; |
130 | 130 | if ($modx->dumpSQL) { |
131 | - $modx->queryCode .= "<fieldset style='text-align:left'><legend>Database connection</legend>" . sprintf("Database connection was created in %2.4f s", $totaltime) . "</fieldset><br />"; |
|
131 | + $modx->queryCode .= "<fieldset style='text-align:left'><legend>Database connection</legend>".sprintf("Database connection was created in %2.4f s", $totaltime)."</fieldset><br />"; |
|
132 | 132 | } |
133 | 133 | if (function_exists('mysql_set_charset')) { |
134 | 134 | mysql_set_charset($this->config['charset']); |
@@ -146,26 +146,26 @@ discard block |
||
146 | 146 | * @name: disconnect |
147 | 147 | * |
148 | 148 | */ |
149 | - function disconnect() { |
|
149 | + function disconnect(){ |
|
150 | 150 | @ mysql_close($this->conn); |
151 | 151 | $this->conn = null; |
152 | 152 | $this->isConnected = false; |
153 | 153 | } |
154 | 154 | |
155 | - function escape($s, $safecount=0) { |
|
155 | + function escape($s, $safecount = 0){ |
|
156 | 156 | |
157 | 157 | $safecount++; |
158 | - if(1000<$safecount) exit("Too many loops '{$safecount}'"); |
|
158 | + if (1000 < $safecount) exit("Too many loops '{$safecount}'"); |
|
159 | 159 | |
160 | 160 | if (empty ($this->conn) || !is_resource($this->conn)) { |
161 | 161 | $this->connect(); |
162 | 162 | } |
163 | 163 | |
164 | - if(is_array($s)) { |
|
165 | - if(count($s) === 0) $s = ''; |
|
164 | + if (is_array($s)) { |
|
165 | + if (count($s) === 0) $s = ''; |
|
166 | 166 | else { |
167 | - foreach($s as $i=>$v) { |
|
168 | - $s[$i] = $this->escape($v,$safecount); |
|
167 | + foreach ($s as $i=>$v) { |
|
168 | + $s[$i] = $this->escape($v, $safecount); |
|
169 | 169 | } |
170 | 170 | } |
171 | 171 | } |
@@ -178,17 +178,17 @@ discard block |
||
178 | 178 | * @desc: Mainly for internal use. |
179 | 179 | * Developers should use select, update, insert, delete where possible |
180 | 180 | */ |
181 | - function query($sql,$watchError=true) { |
|
181 | + function query($sql, $watchError = true){ |
|
182 | 182 | global $modx; |
183 | 183 | if (empty ($this->conn) || !is_resource($this->conn)) { |
184 | 184 | $this->connect(); |
185 | 185 | } |
186 | 186 | $tstart = $modx->getMicroTime(); |
187 | - if(is_array($sql)) $sql = join("\n", $sql); |
|
187 | + if (is_array($sql)) $sql = join("\n", $sql); |
|
188 | 188 | $this->lastQuery = $sql; |
189 | 189 | if (!$result = @ mysql_query($sql, $this->conn)) { |
190 | - if(!$watchError) return; |
|
191 | - switch(mysql_errno()) { |
|
190 | + if (!$watchError) return; |
|
191 | + switch (mysql_errno()) { |
|
192 | 192 | case 1054: |
193 | 193 | case 1060: |
194 | 194 | case 1061: |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | case 1091: |
197 | 197 | break; |
198 | 198 | default: |
199 | - $modx->messageQuit('Execution of a query to the database failed - ' . $this->getLastError(), $sql); |
|
199 | + $modx->messageQuit('Execution of a query to the database failed - '.$this->getLastError(), $sql); |
|
200 | 200 | } |
201 | 201 | } else { |
202 | 202 | $tend = $modx->getMicroTime(); |
@@ -207,15 +207,15 @@ discard block |
||
207 | 207 | array_shift($debug); |
208 | 208 | $debug_path = array(); |
209 | 209 | foreach ($debug as $line) $debug_path[] = $line['function']; |
210 | - $debug_path = implode(' > ',array_reverse($debug_path)); |
|
211 | - $modx->queryCode .= "<fieldset style='text-align:left'><legend>Query " . ($modx->executedQueries + 1) . " - " . sprintf("%2.2f ms", $totaltime*1000) . "</legend>"; |
|
212 | - $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>'; |
|
218 | - $modx->queryCode .= 'Functions Path => ' . $debug_path . '<br>'; |
|
210 | + $debug_path = implode(' > ', array_reverse($debug_path)); |
|
211 | + $modx->queryCode .= "<fieldset style='text-align:left'><legend>Query ".($modx->executedQueries + 1)." - ".sprintf("%2.2f ms", $totaltime * 1000)."</legend>"; |
|
212 | + $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>'; |
|
218 | + $modx->queryCode .= 'Functions Path => '.$debug_path.'<br>'; |
|
219 | 219 | $modx->queryCode .= "</fieldset><br />"; |
220 | 220 | } |
221 | 221 | $modx->executedQueries = $modx->executedQueries + 1; |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | * @name: delete |
228 | 228 | * |
229 | 229 | */ |
230 | - function delete($from, $where='', $orderby='', $limit = '') { |
|
230 | + function delete($from, $where = '', $orderby = '', $limit = ''){ |
|
231 | 231 | global $modx; |
232 | 232 | if (!$from) |
233 | 233 | $modx->messageQuit("Empty \$from parameters in DBAPI::delete()."); |
@@ -236,9 +236,9 @@ discard block |
||
236 | 236 | $where = trim($where); |
237 | 237 | $orderby = trim($orderby); |
238 | 238 | $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}"; |
|
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}"; |
|
242 | 242 | return $this->query("DELETE FROM {$from} {$where} {$orderby} {$limit}"); |
243 | 243 | } |
244 | 244 | } |
@@ -247,12 +247,12 @@ discard block |
||
247 | 247 | * @name: select |
248 | 248 | * |
249 | 249 | */ |
250 | - function select($fields = "*", $from = "", $where = "", $orderby = "", $limit = "") { |
|
250 | + function select($fields = "*", $from = "", $where = "", $orderby = "", $limit = ""){ |
|
251 | 251 | global $modx; |
252 | 252 | |
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); |
|
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); |
|
256 | 256 | |
257 | 257 | if (!$from) { |
258 | 258 | $modx->messageQuit("Empty \$from parameters in DBAPI::select()."); |
@@ -264,9 +264,9 @@ discard block |
||
264 | 264 | $where = trim($where); |
265 | 265 | $orderby = trim($orderby); |
266 | 266 | $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}"; |
|
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}"; |
|
270 | 270 | return $this->query("SELECT {$fields} FROM {$from} {$where} {$orderby} {$limit}"); |
271 | 271 | } |
272 | 272 | |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | * @name: update |
275 | 275 | * |
276 | 276 | */ |
277 | - function update($fields, $table, $where = "") { |
|
277 | + function update($fields, $table, $where = ""){ |
|
278 | 278 | global $modx; |
279 | 279 | if (!$table) |
280 | 280 | $modx->messageQuit("Empty \$table parameter in DBAPI::update()."); |
@@ -282,17 +282,17 @@ discard block |
||
282 | 282 | $table = $this->replaceFullTableName($table); |
283 | 283 | if (is_array($fields)) { |
284 | 284 | foreach ($fields as $key => $value) { |
285 | - if(is_null($value) || strtolower($value) === 'null'){ |
|
285 | + if (is_null($value) || strtolower($value) === 'null') { |
|
286 | 286 | $flds = 'NULL'; |
287 | - }else{ |
|
288 | - $flds = "'" . $value . "'"; |
|
287 | + } else { |
|
288 | + $flds = "'".$value."'"; |
|
289 | 289 | } |
290 | 290 | $fields[$key] = "`{$key}` = ".$flds; |
291 | 291 | } |
292 | 292 | $fields = implode(",", $fields); |
293 | 293 | } |
294 | 294 | $where = trim($where); |
295 | - if($where!=='' && stripos($where, 'WHERE')!==0) $where = "WHERE {$where}"; |
|
295 | + if ($where !== '' && stripos($where, 'WHERE') !== 0) $where = "WHERE {$where}"; |
|
296 | 296 | return $this->query("UPDATE {$table} SET {$fields} {$where}"); |
297 | 297 | } |
298 | 298 | } |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | * @name: insert |
302 | 302 | * @desc: returns either last id inserted or the result from the query |
303 | 303 | */ |
304 | - function insert($fields, $intotable, $fromfields = "*", $fromtable = "", $where = "", $limit = "") { |
|
304 | + function insert($fields, $intotable, $fromfields = "*", $fromtable = "", $where = "", $limit = ""){ |
|
305 | 305 | global $modx; |
306 | 306 | if (!$intotable) |
307 | 307 | $modx->messageQuit("Empty \$intotable parameters in DBAPI::insert()."); |
@@ -314,13 +314,13 @@ discard block |
||
314 | 314 | $fields = "(`".implode("`, `", array_keys($fields))."`) VALUES('".implode("', '", array_values($fields))."')"; |
315 | 315 | $rt = $this->query("INSERT INTO {$intotable} {$fields}"); |
316 | 316 | } else { |
317 | - if (version_compare($this->getVersion(),"4.0.14")>=0) { |
|
317 | + if (version_compare($this->getVersion(), "4.0.14") >= 0) { |
|
318 | 318 | $fromtable = $this->replaceFullTableName($fromtable); |
319 | 319 | $fields = "(".implode(",", array_keys($fields)).")"; |
320 | 320 | $where = trim($where); |
321 | 321 | $limit = trim($limit); |
322 | - if($where!=='' && stripos($where, 'WHERE')!==0) $where = "WHERE {$where}"; |
|
323 | - if($limit!=='' && stripos($limit, 'LIMIT')!==0) $limit = "LIMIT {$limit}"; |
|
322 | + if ($where !== '' && stripos($where, 'WHERE') !== 0) $where = "WHERE {$where}"; |
|
323 | + if ($limit !== '' && stripos($limit, 'LIMIT') !== 0) $limit = "LIMIT {$limit}"; |
|
324 | 324 | $rt = $this->query("INSERT INTO {$intotable} {$fields} SELECT {$fromfields} FROM {$fromtable} {$where} {$limit}"); |
325 | 325 | } else { |
326 | 326 | $ds = $this->select($fromfields, $fromtable, $where, '', $limit); |
@@ -331,18 +331,18 @@ discard block |
||
331 | 331 | } |
332 | 332 | } |
333 | 333 | } |
334 | - if (($lid = $this->getInsertId())===false) $modx->messageQuit("Couldn't get last insert key!"); |
|
334 | + if (($lid = $this->getInsertId()) === false) $modx->messageQuit("Couldn't get last insert key!"); |
|
335 | 335 | return $lid; |
336 | 336 | } |
337 | 337 | } |
338 | 338 | |
339 | - function save($fields, $table, $where='') { |
|
339 | + function save($fields, $table, $where = ''){ |
|
340 | 340 | |
341 | - if($where === '') $mode = 'insert'; |
|
342 | - elseif($this->getRecordCount($this->select('*',$table,$where))==0) $mode = 'insert'; |
|
341 | + if ($where === '') $mode = 'insert'; |
|
342 | + elseif ($this->getRecordCount($this->select('*', $table, $where)) == 0) $mode = 'insert'; |
|
343 | 343 | else $mode = 'update'; |
344 | 344 | |
345 | - if($mode==='insert') return $this->insert($fields, $table); |
|
345 | + if ($mode === 'insert') return $this->insert($fields, $table); |
|
346 | 346 | else return $this->update($fields, $table, $where); |
347 | 347 | } |
348 | 348 | |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | * @name: isResult |
351 | 351 | * |
352 | 352 | */ |
353 | - function isResult($rs) { |
|
353 | + function isResult($rs){ |
|
354 | 354 | return is_resource($rs); |
355 | 355 | } |
356 | 356 | |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | * @name: freeResult |
359 | 359 | * |
360 | 360 | */ |
361 | - function freeResult($rs) { |
|
361 | + function freeResult($rs){ |
|
362 | 362 | mysql_free_result($rs); |
363 | 363 | } |
364 | 364 | |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | * @name: numFields |
367 | 367 | * |
368 | 368 | */ |
369 | - function numFields($rs) { |
|
369 | + function numFields($rs){ |
|
370 | 370 | return mysql_num_fields($rs); |
371 | 371 | } |
372 | 372 | |
@@ -374,15 +374,15 @@ discard block |
||
374 | 374 | * @name: fieldName |
375 | 375 | * |
376 | 376 | */ |
377 | - function fieldName($rs,$col=0) { |
|
378 | - return mysql_field_name($rs,$col); |
|
377 | + function fieldName($rs, $col = 0){ |
|
378 | + return mysql_field_name($rs, $col); |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | /** |
382 | 382 | * @name: selectDb |
383 | 383 | * |
384 | 384 | */ |
385 | - function selectDb($name) { |
|
385 | + function selectDb($name){ |
|
386 | 386 | mysql_select_db($name); |
387 | 387 | } |
388 | 388 | |
@@ -391,8 +391,8 @@ discard block |
||
391 | 391 | * @name: getInsertId |
392 | 392 | * |
393 | 393 | */ |
394 | - function getInsertId($conn=NULL) { |
|
395 | - if( !is_resource($conn)) $conn =& $this->conn; |
|
394 | + function getInsertId($conn = NULL){ |
|
395 | + if (!is_resource($conn)) $conn = & $this->conn; |
|
396 | 396 | return mysql_insert_id($conn); |
397 | 397 | } |
398 | 398 | |
@@ -400,8 +400,8 @@ discard block |
||
400 | 400 | * @name: getAffectedRows |
401 | 401 | * |
402 | 402 | */ |
403 | - function getAffectedRows($conn=NULL) { |
|
404 | - if (!is_resource($conn)) $conn =& $this->conn; |
|
403 | + function getAffectedRows($conn = NULL){ |
|
404 | + if (!is_resource($conn)) $conn = & $this->conn; |
|
405 | 405 | return mysql_affected_rows($conn); |
406 | 406 | } |
407 | 407 | |
@@ -409,8 +409,8 @@ discard block |
||
409 | 409 | * @name: getLastError |
410 | 410 | * |
411 | 411 | */ |
412 | - function getLastError($conn=NULL) { |
|
413 | - if (!is_resource($conn)) $conn =& $this->conn; |
|
412 | + function getLastError($conn = NULL){ |
|
413 | + if (!is_resource($conn)) $conn = & $this->conn; |
|
414 | 414 | return mysql_error($conn); |
415 | 415 | } |
416 | 416 | |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | * @name: getRecordCount |
419 | 419 | * |
420 | 420 | */ |
421 | - function getRecordCount($ds) { |
|
421 | + function getRecordCount($ds){ |
|
422 | 422 | return (is_resource($ds)) ? mysql_num_rows($ds) : 0; |
423 | 423 | } |
424 | 424 | |
@@ -428,7 +428,7 @@ discard block |
||
428 | 428 | * @param: $dsq - dataset |
429 | 429 | * |
430 | 430 | */ |
431 | - function getRow($ds, $mode = 'assoc') { |
|
431 | + function getRow($ds, $mode = 'assoc'){ |
|
432 | 432 | if (is_resource($ds)) { |
433 | 433 | if ($mode == 'assoc') { |
434 | 434 | return mysql_fetch_assoc($ds); |
@@ -453,11 +453,11 @@ discard block |
||
453 | 453 | * @desc: returns an array of the values found on colun $name |
454 | 454 | * @param: $dsq - dataset or query string |
455 | 455 | */ |
456 | - function getColumn($name, $dsq) { |
|
456 | + function getColumn($name, $dsq){ |
|
457 | 457 | if (!is_resource($dsq)) |
458 | 458 | $dsq = $this->query($dsq); |
459 | 459 | if ($dsq) { |
460 | - $col = array (); |
|
460 | + $col = array(); |
|
461 | 461 | while ($row = $this->getRow($dsq)) { |
462 | 462 | $col[] = $row[$name]; |
463 | 463 | } |
@@ -470,11 +470,11 @@ discard block |
||
470 | 470 | * @desc: returns an array containing the column $name |
471 | 471 | * @param: $dsq - dataset or query string |
472 | 472 | */ |
473 | - function getColumnNames($dsq) { |
|
473 | + function getColumnNames($dsq){ |
|
474 | 474 | if (!is_resource($dsq)) |
475 | 475 | $dsq = $this->query($dsq); |
476 | 476 | if ($dsq) { |
477 | - $names = array (); |
|
477 | + $names = array(); |
|
478 | 478 | $limit = mysql_num_fields($dsq); |
479 | 479 | for ($i = 0; $i < $limit; $i++) { |
480 | 480 | $names[] = mysql_field_name($dsq, $i); |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | * @desc: returns the value from the first column in the set |
489 | 489 | * @param: $dsq - dataset or query string |
490 | 490 | */ |
491 | - function getValue($dsq) { |
|
491 | + function getValue($dsq){ |
|
492 | 492 | if (!is_resource($dsq)) |
493 | 493 | $dsq = $this->query($dsq); |
494 | 494 | if ($dsq) { |
@@ -503,7 +503,7 @@ discard block |
||
503 | 503 | * table |
504 | 504 | * @param: $table: the full name of the database table |
505 | 505 | */ |
506 | - function getTableMetaData($table) { |
|
506 | + function getTableMetaData($table){ |
|
507 | 507 | $metadata = false; |
508 | 508 | if (!empty ($table)) { |
509 | 509 | $sql = "SHOW FIELDS FROM $table"; |
@@ -525,7 +525,7 @@ discard block |
||
525 | 525 | * @param: $fieldType: the type of field to format the date for |
526 | 526 | * (in MySQL, you have DATE, TIME, YEAR, and DATETIME) |
527 | 527 | */ |
528 | - function prepareDate($timestamp, $fieldType = 'DATETIME') { |
|
528 | + function prepareDate($timestamp, $fieldType = 'DATETIME'){ |
|
529 | 529 | $date = ''; |
530 | 530 | if (!$timestamp === false && $timestamp > 0) { |
531 | 531 | switch ($fieldType) { |
@@ -554,7 +554,7 @@ discard block |
||
554 | 554 | * was passed |
555 | 555 | * @param: $rs Recordset to be packaged into an array |
556 | 556 | */ |
557 | - function makeArray($rs='',$index=false){ |
|
557 | + function makeArray($rs = '', $index = false){ |
|
558 | 558 | if (!$rs) return false; |
559 | 559 | $rsArray = array(); |
560 | 560 | $iterator = 0; |
@@ -572,7 +572,7 @@ discard block |
||
572 | 572 | * |
573 | 573 | * @return string |
574 | 574 | */ |
575 | - function getVersion() { |
|
575 | + function getVersion(){ |
|
576 | 576 | return mysql_get_server_info(); |
577 | 577 | } |
578 | 578 | |
@@ -583,16 +583,16 @@ discard block |
||
583 | 583 | * @param string $str |
584 | 584 | * @return string |
585 | 585 | */ |
586 | - function replaceFullTableName($str,$force=null) { |
|
586 | + function replaceFullTableName($str, $force = null){ |
|
587 | 587 | |
588 | 588 | $str = trim($str); |
589 | - $dbase = trim($this->config['dbase'],'`'); |
|
589 | + $dbase = trim($this->config['dbase'], '`'); |
|
590 | 590 | $prefix = $this->config['table_prefix']; |
591 | - if(!empty($force)) |
|
591 | + if (!empty($force)) |
|
592 | 592 | { |
593 | 593 | $result = "`{$dbase}`.`{$prefix}{$str}`"; |
594 | 594 | } |
595 | - elseif(strpos($str,'[+prefix+]')!==false) |
|
595 | + elseif (strpos($str, '[+prefix+]') !== false) |
|
596 | 596 | { |
597 | 597 | $result = preg_replace('@\[\+prefix\+\]([0-9a-zA-Z_]+)@', "`{$dbase}`.`{$prefix}$1`", $str); |
598 | 598 | } |
@@ -604,7 +604,7 @@ discard block |
||
604 | 604 | function optimize($table_name) |
605 | 605 | { |
606 | 606 | $rs = $this->query("OPTIMIZE TABLE {$table_name}"); |
607 | - if($rs) $rs = $this->query("ALTER TABLE {$table_name}"); |
|
607 | + if ($rs) $rs = $this->query("ALTER TABLE {$table_name}"); |
|
608 | 608 | return $rs; |
609 | 609 | } |
610 | 610 | |
@@ -614,25 +614,25 @@ discard block |
||
614 | 614 | return $rs; |
615 | 615 | } |
616 | 616 | |
617 | - function dataSeek($result, $row_number) { |
|
617 | + function dataSeek($result, $row_number){ |
|
618 | 618 | return mysql_data_seek($result, $row_number); |
619 | 619 | } |
620 | 620 | |
621 | - function _getFieldsStringFromArray($fields=array()) { |
|
621 | + function _getFieldsStringFromArray($fields = array()){ |
|
622 | 622 | |
623 | - if(empty($fields)) return '*'; |
|
623 | + if (empty($fields)) return '*'; |
|
624 | 624 | |
625 | 625 | $_ = array(); |
626 | - foreach($fields as $k=>$v) { |
|
627 | - if($k!==$v) $_[] = "{$v} as {$k}"; |
|
626 | + foreach ($fields as $k=>$v) { |
|
627 | + if ($k !== $v) $_[] = "{$v} as {$k}"; |
|
628 | 628 | else $_[] = $v; |
629 | 629 | } |
630 | 630 | return join(',', $_); |
631 | 631 | } |
632 | 632 | |
633 | - function _getFromStringFromArray($tables=array()) { |
|
633 | + function _getFromStringFromArray($tables = array()){ |
|
634 | 634 | $_ = array(); |
635 | - foreach($tables as $k=>$v) { |
|
635 | + foreach ($tables as $k=>$v) { |
|
636 | 636 | $_[] = $v; |
637 | 637 | } |
638 | 638 | return join(' ', $_); |
@@ -15,19 +15,19 @@ discard block |
||
15 | 15 | { |
16 | 16 | global $modx; |
17 | 17 | |
18 | - if(!defined('MODX_BASE_PATH')) return false; |
|
18 | + if (!defined('MODX_BASE_PATH')) return false; |
|
19 | 19 | $this->exportstart = $this->get_mtime(); |
20 | 20 | $this->count = 0; |
21 | 21 | $this->setUrlMode(); |
22 | 22 | $this->dirCheckCount = 0; |
23 | 23 | $this->generate_mode = 'crawl'; |
24 | - $this->targetDir = $modx->config['base_path'] . 'temp/export'; |
|
25 | - if(!isset($this->total)) $this->getTotal(); |
|
24 | + $this->targetDir = $modx->config['base_path'].'temp/export'; |
|
25 | + if (!isset($this->total)) $this->getTotal(); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | function setExportDir($dir) |
29 | 29 | { |
30 | - $dir = str_replace('\\','/',$dir); |
|
30 | + $dir = str_replace('\\', '/', $dir); |
|
31 | 31 | $dir = rtrim($dir, '/'); |
32 | 32 | $this->targetDir = $dir; |
33 | 33 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | { |
45 | 45 | global $modx; |
46 | 46 | |
47 | - if($modx->config['friendly_urls']==0) |
|
47 | + if ($modx->config['friendly_urls'] == 0) |
|
48 | 48 | { |
49 | 49 | $modx->config['friendly_urls'] = 1; |
50 | 50 | $modx->config['use_alias_path'] = 1; |
@@ -53,13 +53,13 @@ discard block |
||
53 | 53 | $modx->config['make_folders'] = '1'; |
54 | 54 | } |
55 | 55 | |
56 | - function getTotal($ignore_ids='', $noncache='0') |
|
56 | + function getTotal($ignore_ids = '', $noncache = '0') |
|
57 | 57 | { |
58 | 58 | global $modx; |
59 | 59 | $tbl_site_content = $modx->getFullTableName('site_content'); |
60 | 60 | |
61 | 61 | $ignore_ids = array_filter(array_map('intval', explode(',', $ignore_ids))); |
62 | - if(count($ignore_ids)>0) |
|
62 | + if (count($ignore_ids) > 0) |
|
63 | 63 | { |
64 | 64 | $ignore_ids = "AND NOT id IN ('".implode("','", $ignore_ids)."')"; |
65 | 65 | } else { |
@@ -70,72 +70,72 @@ discard block |
||
70 | 70 | |
71 | 71 | $noncache = ($noncache == 1) ? '' : 'AND cacheable=1'; |
72 | 72 | $where = "deleted=0 AND ((published=1 AND type='document') OR (isfolder=1)) {$noncache} {$ignore_ids}"; |
73 | - $rs = $modx->db->select('count(id)',$tbl_site_content,$where); |
|
73 | + $rs = $modx->db->select('count(id)', $tbl_site_content, $where); |
|
74 | 74 | $this->total = $modx->db->getValue($rs); |
75 | 75 | return $this->total; |
76 | 76 | } |
77 | 77 | |
78 | - function removeDirectoryAll($directory='') |
|
78 | + function removeDirectoryAll($directory = '') |
|
79 | 79 | { |
80 | - if(empty($directory)) $directory = $this->targetDir; |
|
81 | - $directory = rtrim($directory,'/'); |
|
80 | + if (empty($directory)) $directory = $this->targetDir; |
|
81 | + $directory = rtrim($directory, '/'); |
|
82 | 82 | // 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; |
|
83 | + if (empty($directory)) return false; |
|
84 | + if (strpos($directory, MODX_BASE_PATH) === false) return FALSE; |
|
85 | 85 | |
86 | - if(!is_dir($directory)) return FALSE; |
|
87 | - elseif(!is_readable($directory)) return FALSE; |
|
86 | + if (!is_dir($directory)) return FALSE; |
|
87 | + elseif (!is_readable($directory)) return FALSE; |
|
88 | 88 | else |
89 | 89 | { |
90 | - $files = glob($directory . '/*'); |
|
91 | - if(!empty($files)) |
|
90 | + $files = glob($directory.'/*'); |
|
91 | + if (!empty($files)) |
|
92 | 92 | { |
93 | - foreach($files as $path) |
|
93 | + foreach ($files as $path) |
|
94 | 94 | { |
95 | - if(is_dir($path)) $this->removeDirectoryAll($path); |
|
95 | + if (is_dir($path)) $this->removeDirectoryAll($path); |
|
96 | 96 | else $rs = unlink($path); |
97 | 97 | } |
98 | 98 | } |
99 | 99 | } |
100 | - if($directory !== $this->targetDir) $rs = rmdir($directory); |
|
100 | + if ($directory !== $this->targetDir) $rs = rmdir($directory); |
|
101 | 101 | |
102 | 102 | return $rs; |
103 | 103 | } |
104 | 104 | |
105 | 105 | function makeFile($docid, $filepath) |
106 | 106 | { |
107 | - global $modx,$_lang; |
|
107 | + global $modx, $_lang; |
|
108 | 108 | $file_permission = octdec($modx->config['new_file_permissions']); |
109 | - if($this->generate_mode==='direct') |
|
109 | + if ($this->generate_mode === 'direct') |
|
110 | 110 | { |
111 | 111 | $back_lang = $_lang; |
112 | 112 | $src = $modx->executeParser($docid); |
113 | 113 | |
114 | 114 | $_lang = $back_lang; |
115 | 115 | } |
116 | - else $src = $this->curl_get_contents(MODX_SITE_URL . "index.php?id={$docid}"); |
|
116 | + else $src = $this->curl_get_contents(MODX_SITE_URL."index.php?id={$docid}"); |
|
117 | 117 | |
118 | 118 | |
119 | - if($src !== false) |
|
119 | + if ($src !== false) |
|
120 | 120 | { |
121 | - if($this->repl_before!==$this->repl_after) $src = str_replace($this->repl_before,$this->repl_after,$src); |
|
122 | - $result = file_put_contents($filepath,$src); |
|
123 | - if($result!==false) @chmod($filepath, $file_permission); |
|
121 | + if ($this->repl_before !== $this->repl_after) $src = str_replace($this->repl_before, $this->repl_after, $src); |
|
122 | + $result = file_put_contents($filepath, $src); |
|
123 | + if ($result !== false) @chmod($filepath, $file_permission); |
|
124 | 124 | |
125 | - if($result !== false) return 'success'; |
|
125 | + if ($result !== false) return 'success'; |
|
126 | 126 | else return 'failed_no_write'; |
127 | 127 | } |
128 | 128 | else return 'failed_no_retrieve'; |
129 | 129 | } |
130 | 130 | |
131 | - function getFileName($docid, $alias='', $prefix, $suffix) |
|
131 | + function getFileName($docid, $alias = '', $prefix, $suffix) |
|
132 | 132 | { |
133 | 133 | global $modx; |
134 | 134 | |
135 | - if($alias==='') $filename = $prefix.$docid.$suffix; |
|
135 | + if ($alias === '') $filename = $prefix.$docid.$suffix; |
|
136 | 136 | else |
137 | 137 | { |
138 | - if($modx->config['suffix_mode']==='1' && strpos($alias, '.')!==false) |
|
138 | + if ($modx->config['suffix_mode'] === '1' && strpos($alias, '.') !== false) |
|
139 | 139 | { |
140 | 140 | $suffix = ''; |
141 | 141 | } |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | return $filename; |
145 | 145 | } |
146 | 146 | |
147 | - function run($parent=0) |
|
147 | + function run($parent = 0) |
|
148 | 148 | { |
149 | 149 | global $_lang; |
150 | 150 | global $modx; |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | $tbl_site_content = $modx->getFullTableName('site_content'); |
153 | 153 | |
154 | 154 | $ignore_ids = $this->ignore_ids; |
155 | - $dirpath = $this->targetDir . '/'; |
|
155 | + $dirpath = $this->targetDir.'/'; |
|
156 | 156 | |
157 | 157 | $prefix = $modx->config['friendly_url_prefix']; |
158 | 158 | $suffix = $modx->config['friendly_url_suffix']; |
@@ -162,36 +162,36 @@ discard block |
||
162 | 162 | |
163 | 163 | $ph['status'] = 'fail'; |
164 | 164 | $ph['msg1'] = $_lang['export_site_failed']; |
165 | - $ph['msg2'] = $_lang["export_site_failed_no_write"] . ' - ' . $dirpath; |
|
166 | - $msg_failed_no_write = $this->parsePlaceholder($tpl,$ph); |
|
165 | + $ph['msg2'] = $_lang["export_site_failed_no_write"].' - '.$dirpath; |
|
166 | + $msg_failed_no_write = $this->parsePlaceholder($tpl, $ph); |
|
167 | 167 | |
168 | 168 | $ph['msg2'] = $_lang["export_site_failed_no_retrieve"]; |
169 | - $msg_failed_no_retrieve = $this->parsePlaceholder($tpl,$ph); |
|
169 | + $msg_failed_no_retrieve = $this->parsePlaceholder($tpl, $ph); |
|
170 | 170 | |
171 | 171 | $ph['status'] = 'success'; |
172 | 172 | $ph['msg1'] = $_lang['export_site_success']; |
173 | 173 | $ph['msg2'] = ''; |
174 | - $msg_success = $this->parsePlaceholder($tpl,$ph); |
|
174 | + $msg_success = $this->parsePlaceholder($tpl, $ph); |
|
175 | 175 | |
176 | 176 | $ph['msg2'] = $_lang['export_site_success_skip_doc']; |
177 | - $msg_success_skip_doc = $this->parsePlaceholder($tpl,$ph); |
|
177 | + $msg_success_skip_doc = $this->parsePlaceholder($tpl, $ph); |
|
178 | 178 | |
179 | 179 | $ph['msg2'] = $_lang['export_site_success_skip_dir']; |
180 | - $msg_success_skip_dir = $this->parsePlaceholder($tpl,$ph); |
|
180 | + $msg_success_skip_dir = $this->parsePlaceholder($tpl, $ph); |
|
181 | 181 | |
182 | 182 | $fields = "id, alias, pagetitle, isfolder, (content = '' AND template = 0) AS wasNull, published"; |
183 | - $noncache = $_POST['includenoncache']==1 ? '' : 'AND cacheable=1'; |
|
183 | + $noncache = $_POST['includenoncache'] == 1 ? '' : 'AND cacheable=1'; |
|
184 | 184 | $where = "parent = '{$parent}' AND deleted=0 AND ((published=1 AND type='document') OR (isfolder=1)) {$noncache} {$ignore_ids}"; |
185 | - $rs = $modx->db->select($fields,$tbl_site_content,$where); |
|
185 | + $rs = $modx->db->select($fields, $tbl_site_content, $where); |
|
186 | 186 | |
187 | 187 | $ph = array(); |
188 | - $ph['total'] = $this->total; |
|
188 | + $ph['total'] = $this->total; |
|
189 | 189 | $folder_permission = octdec($modx->config['new_folder_permissions']); |
190 | - while($row = $modx->db->getRow($rs)) |
|
190 | + while ($row = $modx->db->getRow($rs)) |
|
191 | 191 | { |
192 | 192 | $this->count++; |
193 | 193 | |
194 | - $row['count'] = $this->count; |
|
194 | + $row['count'] = $this->count; |
|
195 | 195 | $row['url'] = $modx->makeUrl($row['id']); |
196 | 196 | |
197 | 197 | if (!$row['wasNull']) |
@@ -200,10 +200,10 @@ discard block |
||
200 | 200 | $filename = $dirpath.$docname; |
201 | 201 | if (!is_file($filename)) |
202 | 202 | { |
203 | - if($row['published']==='1') |
|
203 | + if ($row['published'] === '1') |
|
204 | 204 | { |
205 | 205 | $status = $this->makeFile($row['id'], $filename); |
206 | - switch($status) |
|
206 | + switch ($status) |
|
207 | 207 | { |
208 | 208 | case 'failed_no_write' : |
209 | 209 | $row['status'] = $msg_failed_no_write; |
@@ -225,11 +225,11 @@ discard block |
||
225 | 225 | $row['status'] = $msg_success_skip_dir; |
226 | 226 | $this->output[] = $this->parsePlaceholder($_lang['export_site_exporting_document'], $row); |
227 | 227 | } |
228 | - if ($row['isfolder']==='1' && ($modx->config['suffix_mode']!=='1' || strpos($row['alias'],'.')===false)) |
|
228 | + if ($row['isfolder'] === '1' && ($modx->config['suffix_mode'] !== '1' || strpos($row['alias'], '.') === false)) |
|
229 | 229 | { // needs making a folder |
230 | - $end_dir = ($row['alias']!=='') ? $row['alias'] : $row['id']; |
|
231 | - $dir_path = $dirpath . $end_dir; |
|
232 | - if(strpos($dir_path,MODX_BASE_PATH)===false) return FALSE; |
|
230 | + $end_dir = ($row['alias'] !== '') ? $row['alias'] : $row['id']; |
|
231 | + $dir_path = $dirpath.$end_dir; |
|
232 | + if (strpos($dir_path, MODX_BASE_PATH) === false) return FALSE; |
|
233 | 233 | if (!is_dir($dir_path)) |
234 | 234 | { |
235 | 235 | if (is_file($dir_path)) @unlink($dir_path); |
@@ -239,9 +239,9 @@ discard block |
||
239 | 239 | } |
240 | 240 | |
241 | 241 | |
242 | - if($modx->config['make_folders']==='1' && $row['published']==='1') |
|
242 | + if ($modx->config['make_folders'] === '1' && $row['published'] === '1') |
|
243 | 243 | { |
244 | - if(is_file($filename)) rename($filename,$dir_path . '/index.html'); |
|
244 | + if (is_file($filename)) rename($filename, $dir_path.'/index.html'); |
|
245 | 245 | } |
246 | 246 | $this->targetDir = $dir_path; |
247 | 247 | $this->run($row['id']); |
@@ -250,16 +250,16 @@ discard block |
||
250 | 250 | return implode("\n", $this->output); |
251 | 251 | } |
252 | 252 | |
253 | - function curl_get_contents($url, $timeout = 30 ) |
|
253 | + function curl_get_contents($url, $timeout = 30) |
|
254 | 254 | { |
255 | - if(!function_exists('curl_init')) return @file_get_contents($url); |
|
255 | + if (!function_exists('curl_init')) return @file_get_contents($url); |
|
256 | 256 | |
257 | 257 | $ch = curl_init(); |
258 | 258 | curl_setopt($ch, CURLOPT_URL, $url); |
259 | - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // 0 = DO NOT VERIFY AUTHENTICITY OF SSL-CERT |
|
260 | - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // 2 = CERT MUST INDICATE BEING CONNECTED TO RIGHT SERVER |
|
259 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // 0 = DO NOT VERIFY AUTHENTICITY OF SSL-CERT |
|
260 | + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // 2 = CERT MUST INDICATE BEING CONNECTED TO RIGHT SERVER |
|
261 | 261 | curl_setopt($ch, CURLOPT_HEADER, false); |
262 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true ); |
|
262 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
263 | 263 | curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
264 | 264 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
265 | 265 | $result = curl_exec($ch); |
@@ -267,12 +267,12 @@ discard block |
||
267 | 267 | return $result; |
268 | 268 | } |
269 | 269 | |
270 | - function parsePlaceholder($tpl,$ph=array()) |
|
270 | + function parsePlaceholder($tpl, $ph = array()) |
|
271 | 271 | { |
272 | - foreach($ph as $k=>$v) |
|
272 | + foreach ($ph as $k=>$v) |
|
273 | 273 | { |
274 | 274 | $k = "[+{$k}+]"; |
275 | - $tpl = str_replace($k,$v,$tpl); |
|
275 | + $tpl = str_replace($k, $v, $tpl); |
|
276 | 276 | } |
277 | 277 | return $tpl; |
278 | 278 | } |
@@ -9,9 +9,9 @@ |
||
9 | 9 | |
10 | 10 | if (empty($database_type)) $database_type = 'mysql'; |
11 | 11 | |
12 | -if (!include_once MODX_MANAGER_PATH . 'includes/extenders/dbapi.' . $database_type . '.class.inc.php'){ |
|
12 | +if (!include_once MODX_MANAGER_PATH.'includes/extenders/dbapi.'.$database_type.'.class.inc.php') { |
|
13 | 13 | return false; |
14 | -}else{ |
|
15 | - $this->db= new DBAPI; |
|
14 | +} else { |
|
15 | + $this->db = new DBAPI; |
|
16 | 16 | return true; |
17 | 17 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * |
9 | 9 | * @author Jason Coward <[email protected]> (MODX) |
10 | 10 | */ |
11 | -class MakeTable { |
|
11 | +class MakeTable{ |
|
12 | 12 | var $actionField; |
13 | 13 | var $cellAction; |
14 | 14 | var $linkAction; |
@@ -31,26 +31,26 @@ discard block |
||
31 | 31 | var $columnWidths; |
32 | 32 | var $selectedValues; |
33 | 33 | |
34 | - function __construct() { |
|
35 | - $this->fieldHeaders= array(); |
|
36 | - $this->excludeFields= array(); |
|
37 | - $this->actionField= ''; |
|
38 | - $this->cellAction= ''; |
|
39 | - $this->linkAction= ''; |
|
40 | - $this->tableWidth= ''; |
|
41 | - $this->tableClass= ''; |
|
42 | - $this->rowHeaderClass= ''; |
|
43 | - $this->columnHeaderClass= ''; |
|
44 | - $this->rowRegularClass= ''; |
|
45 | - $this->rowAlternateClass= 'alt'; |
|
46 | - $this->formName= 'tableForm'; |
|
47 | - $this->formAction= '[~[*id*]~]'; |
|
48 | - $this->formElementName= ''; |
|
49 | - $this->formElementType= ''; |
|
50 | - $this->rowAlternatingScheme= 'EVEN'; |
|
51 | - $this->allOption= 0; |
|
52 | - $this->selectedValues= array(); |
|
53 | - $this->extra= ''; |
|
34 | + function __construct(){ |
|
35 | + $this->fieldHeaders = array(); |
|
36 | + $this->excludeFields = array(); |
|
37 | + $this->actionField = ''; |
|
38 | + $this->cellAction = ''; |
|
39 | + $this->linkAction = ''; |
|
40 | + $this->tableWidth = ''; |
|
41 | + $this->tableClass = ''; |
|
42 | + $this->rowHeaderClass = ''; |
|
43 | + $this->columnHeaderClass = ''; |
|
44 | + $this->rowRegularClass = ''; |
|
45 | + $this->rowAlternateClass = 'alt'; |
|
46 | + $this->formName = 'tableForm'; |
|
47 | + $this->formAction = '[~[*id*]~]'; |
|
48 | + $this->formElementName = ''; |
|
49 | + $this->formElementType = ''; |
|
50 | + $this->rowAlternatingScheme = 'EVEN'; |
|
51 | + $this->allOption = 0; |
|
52 | + $this->selectedValues = array(); |
|
53 | + $this->extra = ''; |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
@@ -58,8 +58,8 @@ discard block |
||
58 | 58 | * |
59 | 59 | * @param $value A URL to execute when table cells are clicked. |
60 | 60 | */ |
61 | - function setCellAction($value) { |
|
62 | - $this->cellAction= $this->prepareLink($value); |
|
61 | + function setCellAction($value){ |
|
62 | + $this->cellAction = $this->prepareLink($value); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -67,8 +67,8 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @param $value A URL to execute when text within table cells are clicked. |
69 | 69 | */ |
70 | - function setLinkAction($value) { |
|
71 | - $this->linkAction= $this->prepareLink($value); |
|
70 | + function setLinkAction($value){ |
|
71 | + $this->linkAction = $this->prepareLink($value); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | * |
77 | 77 | * @param $value A valid width attribute for the HTML TABLE tag |
78 | 78 | */ |
79 | - function setTableWidth($value) { |
|
80 | - $this->tableWidth= $value; |
|
79 | + function setTableWidth($value){ |
|
80 | + $this->tableWidth = $value; |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | * |
86 | 86 | * @param $value A class for the main HTML TABLE. |
87 | 87 | */ |
88 | - function setTableClass($value) { |
|
89 | - $this->tableClass= $value; |
|
88 | + function setTableClass($value){ |
|
89 | + $this->tableClass = $value; |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -94,8 +94,8 @@ discard block |
||
94 | 94 | * |
95 | 95 | * @param $value A class for the main HTML TABLE. |
96 | 96 | */ |
97 | - function setTableID($value) { |
|
98 | - $this->tableID= $value; |
|
97 | + function setTableID($value){ |
|
98 | + $this->tableID = $value; |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -103,8 +103,8 @@ discard block |
||
103 | 103 | * |
104 | 104 | * @param $value A class for the table header row. |
105 | 105 | */ |
106 | - function setRowHeaderClass($value) { |
|
107 | - $this->rowHeaderClass= $value; |
|
106 | + function setRowHeaderClass($value){ |
|
107 | + $this->rowHeaderClass = $value; |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -112,8 +112,8 @@ discard block |
||
112 | 112 | * |
113 | 113 | * @param $value A class for the table header row. |
114 | 114 | */ |
115 | - function setThHeaderClass($value) { |
|
116 | - $this->thClass= $value; |
|
115 | + function setThHeaderClass($value){ |
|
116 | + $this->thClass = $value; |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -121,8 +121,8 @@ discard block |
||
121 | 121 | * |
122 | 122 | * @param $value A class for the column header row. |
123 | 123 | */ |
124 | - function setColumnHeaderClass($value) { |
|
125 | - $this->columnHeaderClass= $value; |
|
124 | + function setColumnHeaderClass($value){ |
|
125 | + $this->columnHeaderClass = $value; |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -130,8 +130,8 @@ discard block |
||
130 | 130 | * |
131 | 131 | * @param $value A class for regular table rows. |
132 | 132 | */ |
133 | - function setRowRegularClass($value) { |
|
134 | - $this->rowRegularClass= $value; |
|
133 | + function setRowRegularClass($value){ |
|
134 | + $this->rowRegularClass = $value; |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | * |
140 | 140 | * @param $value A class for alternate table rows. |
141 | 141 | */ |
142 | - function setRowAlternateClass($value) { |
|
143 | - $this->rowAlternateClass= $value; |
|
142 | + function setRowAlternateClass($value){ |
|
143 | + $this->rowAlternateClass = $value; |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -148,8 +148,8 @@ discard block |
||
148 | 148 | * |
149 | 149 | * @param $value Indicates the INPUT form element type attribute. |
150 | 150 | */ |
151 | - function setFormElementType($value) { |
|
152 | - $this->formElementType= $value; |
|
151 | + function setFormElementType($value){ |
|
152 | + $this->formElementType = $value; |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -157,8 +157,8 @@ discard block |
||
157 | 157 | * |
158 | 158 | * @param $value Indicates the INPUT form element name attribute. |
159 | 159 | */ |
160 | - function setFormElementName($value) { |
|
161 | - $this->formElementName= $value; |
|
160 | + function setFormElementName($value){ |
|
161 | + $this->formElementName = $value; |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -167,8 +167,8 @@ discard block |
||
167 | 167 | * |
168 | 168 | * @param $value Indicates the FORM name attribute. |
169 | 169 | */ |
170 | - function setFormName($value) { |
|
171 | - $this->formName= $value; |
|
170 | + function setFormName($value){ |
|
171 | + $this->formName = $value; |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -176,8 +176,8 @@ discard block |
||
176 | 176 | * |
177 | 177 | * @param $value Indicates the FORM action attribute. |
178 | 178 | */ |
179 | - function setFormAction($value) { |
|
180 | - $this->formAction= $value; |
|
179 | + function setFormAction($value){ |
|
180 | + $this->formAction = $value; |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -185,8 +185,8 @@ discard block |
||
185 | 185 | * |
186 | 186 | * @param $value An Array of field keys to exclude from the table. |
187 | 187 | */ |
188 | - function setExcludeFields($value) { |
|
189 | - $this->excludeFields= $value; |
|
188 | + function setExcludeFields($value){ |
|
189 | + $this->excludeFields = $value; |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -194,8 +194,8 @@ discard block |
||
194 | 194 | * |
195 | 195 | * @param $value 'ODD' or 'EVEN' to indicate the alternate row scheme. |
196 | 196 | */ |
197 | - function setRowAlternatingScheme($value) { |
|
198 | - $this->rowAlternatingScheme= $value; |
|
197 | + function setRowAlternatingScheme($value){ |
|
198 | + $this->rowAlternatingScheme = $value; |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
@@ -204,8 +204,8 @@ discard block |
||
204 | 204 | * |
205 | 205 | * @param $value The key of the field to add as a query string parameter. |
206 | 206 | */ |
207 | - function setActionFieldName($value) { |
|
208 | - $this->actionField= $value; |
|
207 | + function setActionFieldName($value){ |
|
208 | + $this->actionField = $value; |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
@@ -214,8 +214,8 @@ discard block |
||
214 | 214 | * @param $value An Array of column widths in the order of the keys in the |
215 | 215 | * source table array. |
216 | 216 | */ |
217 | - function setColumnWidths($widthArray) { |
|
218 | - $this->columnWidths= $widthArray; |
|
217 | + function setColumnWidths($widthArray){ |
|
218 | + $this->columnWidths = $widthArray; |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -223,8 +223,8 @@ discard block |
||
223 | 223 | * |
224 | 224 | * @param $value Indicates the INPUT form element type attribute. |
225 | 225 | */ |
226 | - function setSelectedValues($valueArray) { |
|
227 | - $this->selectedValues= $valueArray; |
|
226 | + function setSelectedValues($valueArray){ |
|
227 | + $this->selectedValues = $valueArray; |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | /** |
@@ -233,8 +233,8 @@ discard block |
||
233 | 233 | * |
234 | 234 | * @param $value A string of additional content. |
235 | 235 | */ |
236 | - function setExtra($value) { |
|
237 | - $this->extra= $value; |
|
236 | + function setExtra($value){ |
|
237 | + $this->extra = $value; |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
@@ -242,10 +242,10 @@ discard block |
||
242 | 242 | * |
243 | 243 | * @param $columnPosition The index of the column to get the width for. |
244 | 244 | */ |
245 | - function getColumnWidth($columnPosition) { |
|
246 | - $currentWidth= ''; |
|
245 | + function getColumnWidth($columnPosition){ |
|
246 | + $currentWidth = ''; |
|
247 | 247 | if (is_array($this->columnWidths)) { |
248 | - $currentWidth= $this->columnWidths[$columnPosition] ? ' width="'.$this->columnWidths[$columnPosition].'" ' : ''; |
|
248 | + $currentWidth = $this->columnWidths[$columnPosition] ? ' width="'.$this->columnWidths[$columnPosition].'" ' : ''; |
|
249 | 249 | } |
250 | 250 | return $currentWidth; |
251 | 251 | } |
@@ -255,19 +255,19 @@ discard block |
||
255 | 255 | * |
256 | 256 | * @param $value The position of the current row being rendered. |
257 | 257 | */ |
258 | - function determineRowClass($position) { |
|
258 | + function determineRowClass($position){ |
|
259 | 259 | switch ($this->rowAlternatingScheme) { |
260 | 260 | case 'ODD' : |
261 | - $modRemainder= 1; |
|
261 | + $modRemainder = 1; |
|
262 | 262 | break; |
263 | 263 | case 'EVEN' : |
264 | - $modRemainder= 0; |
|
264 | + $modRemainder = 0; |
|
265 | 265 | break; |
266 | 266 | } |
267 | 267 | if ($position % 2 == $modRemainder) { |
268 | - $currentClass= $this->rowRegularClass; |
|
268 | + $currentClass = $this->rowRegularClass; |
|
269 | 269 | } else { |
270 | - $currentClass= $this->rowAlternateClass; |
|
270 | + $currentClass = $this->rowAlternateClass; |
|
271 | 271 | } |
272 | 272 | return ' class="'.$currentClass.'"'; |
273 | 273 | } |
@@ -278,9 +278,9 @@ discard block |
||
278 | 278 | * |
279 | 279 | * @param $value Indicates the INPUT form element type attribute. |
280 | 280 | */ |
281 | - function getCellAction($currentActionFieldValue) { |
|
281 | + function getCellAction($currentActionFieldValue){ |
|
282 | 282 | if ($this->cellAction) { |
283 | - $cellAction= ' onClick="javascript:window.location=\''.$this->cellAction.$this->actionField.'='.urlencode($currentActionFieldValue).'\'" '; |
|
283 | + $cellAction = ' onClick="javascript:window.location=\''.$this->cellAction.$this->actionField.'='.urlencode($currentActionFieldValue).'\'" '; |
|
284 | 284 | } |
285 | 285 | return $cellAction; |
286 | 286 | } |
@@ -291,10 +291,10 @@ discard block |
||
291 | 291 | * @param $currentActionFieldValue The value to be applied to the link action. |
292 | 292 | * @param $value The value of the cell. |
293 | 293 | */ |
294 | - function createCellText($currentActionFieldValue, $value) { |
|
294 | + function createCellText($currentActionFieldValue, $value){ |
|
295 | 295 | $cell .= $value; |
296 | 296 | if ($this->linkAction) { |
297 | - $cell= '<a href="'.$this->linkAction.$this->actionField.'='.urlencode($currentActionFieldValue).'">'.$cell.'</a>'; |
|
297 | + $cell = '<a href="'.$this->linkAction.$this->actionField.'='.urlencode($currentActionFieldValue).'">'.$cell.'</a>'; |
|
298 | 298 | } |
299 | 299 | return $cell; |
300 | 300 | } |
@@ -303,8 +303,8 @@ discard block |
||
303 | 303 | * Sets an option to generate a check all link when checkbox is indicated |
304 | 304 | * as the table formElementType. |
305 | 305 | */ |
306 | - function setAllOption() { |
|
307 | - $this->allOption= 1; |
|
306 | + function setAllOption(){ |
|
307 | + $this->allOption = 1; |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | /** |
@@ -312,11 +312,11 @@ discard block |
||
312 | 312 | * |
313 | 313 | * @param $value Indicates the INPUT form element type attribute. |
314 | 314 | */ |
315 | - function prepareLink($link) { |
|
315 | + function prepareLink($link){ |
|
316 | 316 | if (strstr($link, '?')) { |
317 | - $end= '&'; |
|
317 | + $end = '&'; |
|
318 | 318 | } else { |
319 | - $end= '?'; |
|
319 | + $end = '?'; |
|
320 | 320 | } |
321 | 321 | return $link.$end; |
322 | 322 | } |
@@ -331,20 +331,20 @@ discard block |
||
331 | 331 | * the $fieldsArray where the values represent the alt heading content |
332 | 332 | * for each column. |
333 | 333 | */ |
334 | - function create($fieldsArray, $fieldHeadersArray=array(),$linkpage="") { |
|
334 | + function create($fieldsArray, $fieldHeadersArray = array(), $linkpage = ""){ |
|
335 | 335 | global $_lang; |
336 | 336 | if (is_array($fieldsArray)) { |
337 | - $i= 0; |
|
337 | + $i = 0; |
|
338 | 338 | foreach ($fieldsArray as $fieldName => $fieldValue) { |
339 | 339 | $table .= "\t<tr".$this->determineRowClass($i).">\n"; |
340 | - $currentActionFieldValue= $fieldValue[$this->actionField]; |
|
340 | + $currentActionFieldValue = $fieldValue[$this->actionField]; |
|
341 | 341 | if (is_array($this->selectedValues)) { |
342 | - $isChecked= array_search($currentActionFieldValue, $this->selectedValues)===false? 0 : 1; |
|
342 | + $isChecked = array_search($currentActionFieldValue, $this->selectedValues) === false ? 0 : 1; |
|
343 | 343 | } else { |
344 | - $isChecked= false; |
|
344 | + $isChecked = false; |
|
345 | 345 | } |
346 | 346 | $table .= $this->addFormField($currentActionFieldValue, $isChecked); |
347 | - $colPosition= 0; |
|
347 | + $colPosition = 0; |
|
348 | 348 | foreach ($fieldValue as $key => $value) { |
349 | 349 | if (!in_array($key, $this->excludeFields)) { |
350 | 350 | $table .= "\t\t<td".$this->getCellAction($currentActionFieldValue).">"; |
@@ -352,20 +352,20 @@ discard block |
||
352 | 352 | $table .= "</td>\n"; |
353 | 353 | if ($i == 0) { |
354 | 354 | if (empty ($header) && $this->formElementType) { |
355 | - $header .= "\t\t<th style=\"width:32px\" ".($this->thClass ? 'class="'.$this->thClass.'"' : '').">". ($this->allOption ? '<a href="javascript:clickAll()">all</a>' : '')."</th>\n"; |
|
355 | + $header .= "\t\t<th style=\"width:32px\" ".($this->thClass ? 'class="'.$this->thClass.'"' : '').">".($this->allOption ? '<a href="javascript:clickAll()">all</a>' : '')."</th>\n"; |
|
356 | 356 | } |
357 | - $headerText= array_key_exists($key, $fieldHeadersArray)? $fieldHeadersArray[$key]: $key; |
|
357 | + $headerText = array_key_exists($key, $fieldHeadersArray) ? $fieldHeadersArray[$key] : $key; |
|
358 | 358 | $header .= "\t\t<th".$this->getColumnWidth($colPosition).($this->thClass ? ' class="'.$this->thClass.'" ' : '').">".$headerText."</th>\n"; |
359 | 359 | } |
360 | - $colPosition ++; |
|
360 | + $colPosition++; |
|
361 | 361 | } |
362 | 362 | } |
363 | - $i ++; |
|
363 | + $i++; |
|
364 | 364 | $table .= "\t</tr>\n"; |
365 | 365 | } |
366 | - $table= "\n".'<table'. ($this->tableWidth ? ' width="'.$this->tableWidth.'"' : ''). ($this->tableClass ? ' class="'.$this->tableClass.'"' : ''). ($this->tableID ? ' id="'.$this->tableID.'"' : '').">\n". ($header ? "\t<thead>\n\t<tr class=\"".$this->rowHeaderClass."\">\n".$header."\t</tr>\n\t</thead>\n" : '').$table."</table>\n"; |
|
366 | + $table = "\n".'<table'.($this->tableWidth ? ' width="'.$this->tableWidth.'"' : '').($this->tableClass ? ' class="'.$this->tableClass.'"' : '').($this->tableID ? ' id="'.$this->tableID.'"' : '').">\n".($header ? "\t<thead>\n\t<tr class=\"".$this->rowHeaderClass."\">\n".$header."\t</tr>\n\t</thead>\n" : '').$table."</table>\n"; |
|
367 | 367 | if ($this->formElementType) { |
368 | - $table= "\n".'<form id="'.$this->formName.'" name="'.$this->formName.'" action="'.$this->formAction.'" method="POST">'.$table; |
|
368 | + $table = "\n".'<form id="'.$this->formName.'" name="'.$this->formName.'" action="'.$this->formAction.'" method="POST">'.$table; |
|
369 | 369 | } |
370 | 370 | if (strlen($this->pageNav) > 1) {//changed to display the pagination if exists. |
371 | 371 | /* commented this part because of cookie |
@@ -400,9 +400,9 @@ discard block |
||
400 | 400 | } |
401 | 401 | if ($this->formElementType) { |
402 | 402 | if ($this->extra) { |
403 | - $table.= "\n".$this->extra."\n"; |
|
403 | + $table .= "\n".$this->extra."\n"; |
|
404 | 404 | } |
405 | - $table.= "\n".'</form>'."\n"; |
|
405 | + $table .= "\n".'</form>'."\n"; |
|
406 | 406 | } |
407 | 407 | return $table; |
408 | 408 | } |
@@ -414,36 +414,36 @@ discard block |
||
414 | 414 | * @param $numRecords The number of records to show per page. |
415 | 415 | * @param $qs An optional query string to be appended to the paging links |
416 | 416 | */ |
417 | - function createPagingNavigation($numRecords, $qs='') { |
|
417 | + function createPagingNavigation($numRecords, $qs = ''){ |
|
418 | 418 | global $_lang; |
419 | - $currentPage= (is_numeric($_GET['page']) ? $_GET['page'] : 1); |
|
420 | - $numPages= ceil($numRecords / MAX_DISPLAY_RECORDS_NUM); |
|
419 | + $currentPage = (is_numeric($_GET['page']) ? $_GET['page'] : 1); |
|
420 | + $numPages = ceil($numRecords / MAX_DISPLAY_RECORDS_NUM); |
|
421 | 421 | if ($numPages > 1) { |
422 | - $currentURL= empty($qs)? '': '?'.$qs; |
|
422 | + $currentURL = empty($qs) ? '' : '?'.$qs; |
|
423 | 423 | if ($currentPage > 6) { |
424 | 424 | $nav .= $this->createPageLink($currentURL, 1, $_lang["pagination_table_first"]); |
425 | 425 | } |
426 | 426 | if ($currentPage != 1) { |
427 | - $nav .= $this->createPageLink($currentURL, $currentPage -1, '<<'); |
|
427 | + $nav .= $this->createPageLink($currentURL, $currentPage - 1, '<<'); |
|
428 | 428 | } |
429 | - $offset= -4 + ($currentPage < 5 ? (5 - $currentPage) : 0); |
|
430 | - $i= 1; |
|
429 | + $offset = -4 + ($currentPage < 5 ? (5 - $currentPage) : 0); |
|
430 | + $i = 1; |
|
431 | 431 | while ($i < 10 && ($currentPage + $offset <= $numPages)) { |
432 | 432 | if ($currentPage == $currentPage + $offset) |
433 | 433 | $nav .= $this->createPageLink($currentURL, $currentPage + $offset, $currentPage + $offset, true); |
434 | 434 | else |
435 | 435 | $nav .= $this->createPageLink($currentURL, $currentPage + $offset, $currentPage + $offset); |
436 | - $i ++; |
|
437 | - $offset ++; |
|
436 | + $i++; |
|
437 | + $offset++; |
|
438 | 438 | } |
439 | 439 | if ($currentPage < $numPages) { |
440 | - $nav .= $this->createPageLink($currentURL, $currentPage +1, '>>'); |
|
440 | + $nav .= $this->createPageLink($currentURL, $currentPage + 1, '>>'); |
|
441 | 441 | } |
442 | 442 | if ($currentPage != $numPages) { |
443 | 443 | $nav .= $this->createPageLink($currentURL, $numPages, $_lang["pagination_table_last"]); |
444 | 444 | } |
445 | 445 | } |
446 | - $this->pageNav= ' '.$nav; |
|
446 | + $this->pageNav = ' '.$nav; |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
@@ -455,13 +455,13 @@ discard block |
||
455 | 455 | * @param $currentPage Indicates if the link is to the current page. |
456 | 456 | * @param $qs And optional query string to be appended to the link. |
457 | 457 | */ |
458 | - function createPageLink($link='', $pageNum, $displayText, $currentPage=false, $qs='') { |
|
458 | + function createPageLink($link = '', $pageNum, $displayText, $currentPage = false, $qs = ''){ |
|
459 | 459 | global $modx; |
460 | - $orderBy= !empty($_GET['orderby'])? '&orderby=' . $_GET['orderby']: ''; |
|
461 | - $orderDir= !empty($_GET['orderdir'])? '&orderdir=' . $_GET['orderdir']: ''; |
|
462 | - if (!empty($qs)) $qs= "?$qs"; |
|
463 | - $link= empty($link)? $modx->makeUrl($modx->documentIdentifier, $modx->documentObject['alias'], $qs . "page=$pageNum$orderBy$orderDir"): $this->prepareLink($link) . "page=$pageNum"; |
|
464 | - $nav .= '<li'.($currentPage? ' class="currentPage"': '').'><a'.($currentPage? ' class="currentPage"': '').' href="'.$link.'">'.$displayText.'</a></li>'."\n"; |
|
460 | + $orderBy = !empty($_GET['orderby']) ? '&orderby='.$_GET['orderby'] : ''; |
|
461 | + $orderDir = !empty($_GET['orderdir']) ? '&orderdir='.$_GET['orderdir'] : ''; |
|
462 | + if (!empty($qs)) $qs = "?$qs"; |
|
463 | + $link = empty($link) ? $modx->makeUrl($modx->documentIdentifier, $modx->documentObject['alias'], $qs."page=$pageNum$orderBy$orderDir") : $this->prepareLink($link)."page=$pageNum"; |
|
464 | + $nav .= '<li'.($currentPage ? ' class="currentPage"' : '').'><a'.($currentPage ? ' class="currentPage"' : '').' href="'.$link.'">'.$displayText.'</a></li>'."\n"; |
|
465 | 465 | return $nav; |
466 | 466 | } |
467 | 467 | |
@@ -472,10 +472,10 @@ discard block |
||
472 | 472 | * @param $isChecked Indicates if the checked attribute should apply to the |
473 | 473 | * element. |
474 | 474 | */ |
475 | - function addFormField($value, $isChecked) { |
|
475 | + function addFormField($value, $isChecked){ |
|
476 | 476 | if ($this->formElementType) { |
477 | - $checked= $isChecked? "checked ": ""; |
|
478 | - $field= "\t\t".'<td><input type="'.$this->formElementType.'" name="'. ($this->formElementName ? $this->formElementName : $value).'" value="'.$value.'" '.$checked.'/></td>'."\n"; |
|
477 | + $checked = $isChecked ? "checked " : ""; |
|
478 | + $field = "\t\t".'<td><input type="'.$this->formElementType.'" name="'.($this->formElementName ? $this->formElementName : $value).'" value="'.$value.'" '.$checked.'/></td>'."\n"; |
|
479 | 479 | } |
480 | 480 | return $field; |
481 | 481 | } |
@@ -484,9 +484,9 @@ discard block |
||
484 | 484 | * Generates the proper LIMIT clause for queries to retrieve paged results in |
485 | 485 | * a MakeTable $fieldsArray. |
486 | 486 | */ |
487 | - function handlePaging() { |
|
488 | - $offset= (is_numeric($_GET['page']) && $_GET['page'] > 0) ? $_GET['page'] - 1 : 0; |
|
489 | - $limitClause= ' LIMIT '. ($offset * MAX_DISPLAY_RECORDS_NUM).', '.MAX_DISPLAY_RECORDS_NUM; |
|
487 | + function handlePaging(){ |
|
488 | + $offset = (is_numeric($_GET['page']) && $_GET['page'] > 0) ? $_GET['page'] - 1 : 0; |
|
489 | + $limitClause = ' LIMIT '.($offset * MAX_DISPLAY_RECORDS_NUM).', '.MAX_DISPLAY_RECORDS_NUM; |
|
490 | 490 | return $limitClause; |
491 | 491 | } |
492 | 492 | |
@@ -496,12 +496,12 @@ discard block |
||
496 | 496 | * |
497 | 497 | * @param $natural_order If true, the results are returned in natural order. |
498 | 498 | */ |
499 | - function handleSorting($natural_order=false) { |
|
500 | - $orderByClause= ''; |
|
499 | + function handleSorting($natural_order = false){ |
|
500 | + $orderByClause = ''; |
|
501 | 501 | if (!$natural_order) { |
502 | - $orderby= !empty($_GET['orderby'])? $_GET['orderby']: "id"; |
|
503 | - $orderdir= !empty($_GET['orderdir'])? $_GET['orderdir']: "DESC"; |
|
504 | - $orderbyClause= !empty($orderby)? ' ORDER BY ' . $orderby . ' ' . $orderdir . ' ': ""; |
|
502 | + $orderby = !empty($_GET['orderby']) ? $_GET['orderby'] : "id"; |
|
503 | + $orderdir = !empty($_GET['orderdir']) ? $_GET['orderdir'] : "DESC"; |
|
504 | + $orderbyClause = !empty($orderby) ? ' ORDER BY '.$orderby.' '.$orderdir.' ' : ""; |
|
505 | 505 | } |
506 | 506 | return $orderbyClause; |
507 | 507 | } |
@@ -514,15 +514,15 @@ discard block |
||
514 | 514 | * @param $text The text for the link (e.g. table column header). |
515 | 515 | * @param $qs An optional query string to append to the order by link. |
516 | 516 | */ |
517 | - function prepareOrderByLink($key, $text, $qs='') { |
|
517 | + function prepareOrderByLink($key, $text, $qs = ''){ |
|
518 | 518 | global $modx; |
519 | 519 | if (!empty($_GET['orderdir'])) { |
520 | - $orderDir= strtolower($_GET['orderdir'])=='desc'? '&orderdir=asc': '&orderdir=desc'; |
|
520 | + $orderDir = strtolower($_GET['orderdir']) == 'desc' ? '&orderdir=asc' : '&orderdir=desc'; |
|
521 | 521 | } else { |
522 | - $orderDir= '&orderdir=asc'; |
|
522 | + $orderDir = '&orderdir=asc'; |
|
523 | 523 | } |
524 | 524 | if (!empty($qs)) { |
525 | - if (!strrpos($qs, '&')==strlen($qs)-1) $qs.= '&'; |
|
525 | + if (!strrpos($qs, '&') == strlen($qs) - 1) $qs .= '&'; |
|
526 | 526 | } |
527 | 527 | return '<a href="[~'.$modx->documentIdentifier.'~]?'.$qs.'orderby='.$key.$orderDir.'">'.$text.'</a>'; |
528 | 528 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | global $_PAGE; // page view state object. Usage $_PAGE['vs']['propertyname'] = $value; |
9 | 9 | |
10 | 10 | // Content manager wrapper class |
11 | -class ManagerAPI { |
|
11 | +class ManagerAPI{ |
|
12 | 12 | |
13 | 13 | var $action; // action directive |
14 | 14 | |
@@ -17,27 +17,27 @@ discard block |
||
17 | 17 | $this->action = $action; // set action directive |
18 | 18 | } |
19 | 19 | |
20 | - function initPageViewState($id=0){ |
|
20 | + function initPageViewState($id = 0){ |
|
21 | 21 | global $_PAGE; |
22 | 22 | $vsid = isset($_SESSION["mgrPageViewSID"]) ? $_SESSION["mgrPageViewSID"] : ''; |
23 | - if($vsid!=$this->action) { |
|
23 | + if ($vsid != $this->action) { |
|
24 | 24 | $_SESSION["mgrPageViewSDATA"] = array(); // new view state |
25 | - $_SESSION["mgrPageViewSID"] = $id>0 ? $id:$this->action; // set id |
|
25 | + $_SESSION["mgrPageViewSID"] = $id > 0 ? $id : $this->action; // set id |
|
26 | 26 | } |
27 | 27 | $_PAGE['vs'] = &$_SESSION["mgrPageViewSDATA"]; // restore viewstate |
28 | 28 | } |
29 | 29 | |
30 | 30 | // save page view state - not really necessary, |
31 | - function savePageViewState($id=0){ |
|
31 | + function savePageViewState($id = 0){ |
|
32 | 32 | global $_PAGE; |
33 | 33 | $_SESSION["mgrPageViewSDATA"] = $_PAGE['vs']; |
34 | - $_SESSION["mgrPageViewSID"] = $id>0 ? $id:$this->action; |
|
34 | + $_SESSION["mgrPageViewSID"] = $id > 0 ? $id : $this->action; |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | // check for saved form |
38 | - function hasFormValues() { |
|
39 | - if(isset($_SESSION["mgrFormValueId"])) { |
|
40 | - if($this->action==$_SESSION["mgrFormValueId"]) { |
|
38 | + function hasFormValues(){ |
|
39 | + if (isset($_SESSION["mgrFormValueId"])) { |
|
40 | + if ($this->action == $_SESSION["mgrFormValueId"]) { |
|
41 | 41 | return true; |
42 | 42 | } |
43 | 43 | else { |
@@ -47,19 +47,19 @@ discard block |
||
47 | 47 | return false; |
48 | 48 | } |
49 | 49 | // saved form post from $_POST |
50 | - function saveFormValues($id=0){ |
|
50 | + function saveFormValues($id = 0){ |
|
51 | 51 | $_SESSION["mgrFormValues"] = $_POST; |
52 | - $_SESSION["mgrFormValueId"] = $id>0 ? $id:$this->action; |
|
52 | + $_SESSION["mgrFormValueId"] = $id > 0 ? $id : $this->action; |
|
53 | 53 | } |
54 | 54 | // load saved form values into $_POST |
55 | 55 | function loadFormValues(){ |
56 | 56 | |
57 | - if(!$this->hasFormValues()) return false; |
|
57 | + if (!$this->hasFormValues()) return false; |
|
58 | 58 | |
59 | 59 | $p = $_SESSION["mgrFormValues"]; |
60 | 60 | $this->clearSavedFormValues(); |
61 | - foreach($p as $k=>$v) { |
|
62 | - $_POST[$k]=$v; |
|
61 | + foreach ($p as $k=>$v) { |
|
62 | + $_POST[$k] = $v; |
|
63 | 63 | } |
64 | 64 | return true; |
65 | 65 | } |
@@ -69,50 +69,50 @@ discard block |
||
69 | 69 | unset($_SESSION["mgrFormValueId"]); |
70 | 70 | } |
71 | 71 | |
72 | - function getHashType($db_value='') { // md5 | v1 | phpass |
|
73 | - $c = substr($db_value,0,1); |
|
74 | - if($c==='$') return 'phpass'; |
|
75 | - elseif(strlen($db_value)===32) return 'md5'; |
|
76 | - elseif($c!=='$' && strpos($db_value,'>')!==false) return 'v1'; |
|
72 | + function getHashType($db_value = ''){ // md5 | v1 | phpass |
|
73 | + $c = substr($db_value, 0, 1); |
|
74 | + if ($c === '$') return 'phpass'; |
|
75 | + elseif (strlen($db_value) === 32) return 'md5'; |
|
76 | + elseif ($c !== '$' && strpos($db_value, '>') !== false) return 'v1'; |
|
77 | 77 | else return 'unknown'; |
78 | 78 | } |
79 | 79 | |
80 | - function genV1Hash($password, $seed='1') |
|
80 | + function genV1Hash($password, $seed = '1') |
|
81 | 81 | { // $seed is user_id basically |
82 | 82 | global $modx; |
83 | 83 | |
84 | - if(isset($modx->config['pwd_hash_algo']) && !empty($modx->config['pwd_hash_algo'])) |
|
84 | + if (isset($modx->config['pwd_hash_algo']) && !empty($modx->config['pwd_hash_algo'])) |
|
85 | 85 | $algorithm = $modx->config['pwd_hash_algo']; |
86 | 86 | else $algorithm = 'UNCRYPT'; |
87 | 87 | |
88 | - $salt = md5($password . $seed); |
|
88 | + $salt = md5($password.$seed); |
|
89 | 89 | |
90 | - switch($algorithm) |
|
90 | + switch ($algorithm) |
|
91 | 91 | { |
92 | 92 | case 'BLOWFISH_Y': |
93 | - $salt = '$2y$07$' . substr($salt,0,22); |
|
93 | + $salt = '$2y$07$'.substr($salt, 0, 22); |
|
94 | 94 | break; |
95 | 95 | case 'BLOWFISH_A': |
96 | - $salt = '$2a$07$' . substr($salt,0,22); |
|
96 | + $salt = '$2a$07$'.substr($salt, 0, 22); |
|
97 | 97 | break; |
98 | 98 | case 'SHA512': |
99 | - $salt = '$6$' . substr($salt,0,16); |
|
99 | + $salt = '$6$'.substr($salt, 0, 16); |
|
100 | 100 | break; |
101 | 101 | case 'SHA256': |
102 | - $salt = '$5$' . substr($salt,0,16); |
|
102 | + $salt = '$5$'.substr($salt, 0, 16); |
|
103 | 103 | break; |
104 | 104 | case 'MD5': |
105 | - $salt = '$1$' . substr($salt,0,8); |
|
105 | + $salt = '$1$'.substr($salt, 0, 8); |
|
106 | 106 | break; |
107 | 107 | } |
108 | 108 | |
109 | - if($algorithm!=='UNCRYPT') |
|
109 | + if ($algorithm !== 'UNCRYPT') |
|
110 | 110 | { |
111 | - $password = sha1($password) . crypt($password,$salt); |
|
111 | + $password = sha1($password).crypt($password, $salt); |
|
112 | 112 | } |
113 | 113 | else $password = sha1($salt.$password); |
114 | 114 | |
115 | - $result = strtolower($algorithm) . '>' . md5($salt.$password) . substr(md5($salt),0,8); |
|
115 | + $result = strtolower($algorithm).'>'.md5($salt.$password).substr(md5($salt), 0, 8); |
|
116 | 116 | |
117 | 117 | return $result; |
118 | 118 | } |
@@ -121,18 +121,18 @@ discard block |
||
121 | 121 | { |
122 | 122 | global $modx; |
123 | 123 | $tbl_manager_users = $modx->getFullTableName('manager_users'); |
124 | - $rs = $modx->db->select('password',$tbl_manager_users,"id='{$uid}'"); |
|
124 | + $rs = $modx->db->select('password', $tbl_manager_users, "id='{$uid}'"); |
|
125 | 125 | $password = $modx->db->getValue($rs); |
126 | 126 | |
127 | - if(strpos($password,'>')===false) $algo = 'NOSALT'; |
|
127 | + if (strpos($password, '>') === false) $algo = 'NOSALT'; |
|
128 | 128 | else |
129 | 129 | { |
130 | - $algo = substr($password,0,strpos($password,'>')); |
|
130 | + $algo = substr($password, 0, strpos($password, '>')); |
|
131 | 131 | } |
132 | 132 | return strtoupper($algo); |
133 | 133 | } |
134 | 134 | |
135 | - function checkHashAlgorithm($algorithm='') |
|
135 | + function checkHashAlgorithm($algorithm = '') |
|
136 | 136 | { |
137 | 137 | $result = false; |
138 | 138 | if (!empty($algorithm)) |
@@ -165,54 +165,54 @@ discard block |
||
165 | 165 | return $result; |
166 | 166 | } |
167 | 167 | |
168 | - function getSystemChecksum($check_files) { |
|
168 | + function getSystemChecksum($check_files){ |
|
169 | 169 | $_ = array(); |
170 | 170 | $check_files = trim($check_files); |
171 | 171 | $check_files = explode("\n", $check_files); |
172 | - foreach($check_files as $file) { |
|
172 | + foreach ($check_files as $file) { |
|
173 | 173 | $file = trim($file); |
174 | - $file = MODX_BASE_PATH . $file; |
|
175 | - if(!is_file($file)) continue; |
|
176 | - $_[$file]= md5_file($file); |
|
174 | + $file = MODX_BASE_PATH.$file; |
|
175 | + if (!is_file($file)) continue; |
|
176 | + $_[$file] = md5_file($file); |
|
177 | 177 | } |
178 | 178 | return serialize($_); |
179 | 179 | } |
180 | 180 | |
181 | - function getModifiedSystemFilesList($check_files, $checksum) { |
|
181 | + function getModifiedSystemFilesList($check_files, $checksum){ |
|
182 | 182 | $_ = array(); |
183 | 183 | $check_files = trim($check_files); |
184 | 184 | $check_files = explode("\n", $check_files); |
185 | 185 | $checksum = unserialize($checksum); |
186 | - foreach($check_files as $file) { |
|
186 | + foreach ($check_files as $file) { |
|
187 | 187 | $file = trim($file); |
188 | - $filePath = MODX_BASE_PATH . $file; |
|
189 | - if(!is_file($filePath)) continue; |
|
190 | - if(md5_file($filePath) != $checksum[$filePath]) $_[] = $file; |
|
188 | + $filePath = MODX_BASE_PATH.$file; |
|
189 | + if (!is_file($filePath)) continue; |
|
190 | + if (md5_file($filePath) != $checksum[$filePath]) $_[] = $file; |
|
191 | 191 | } |
192 | 192 | return $_; |
193 | 193 | } |
194 | 194 | |
195 | - function setSystemChecksum($checksum) { |
|
195 | + function setSystemChecksum($checksum){ |
|
196 | 196 | global $modx; |
197 | 197 | $tbl_system_settings = $modx->getFullTableName('system_settings'); |
198 | - $sql = "REPLACE INTO {$tbl_system_settings} (setting_name, setting_value) VALUES ('sys_files_checksum','" . $modx->db->escape($checksum) . "')"; |
|
198 | + $sql = "REPLACE INTO {$tbl_system_settings} (setting_name, setting_value) VALUES ('sys_files_checksum','".$modx->db->escape($checksum)."')"; |
|
199 | 199 | $modx->db->query($sql); |
200 | 200 | } |
201 | 201 | |
202 | - function checkSystemChecksum() { |
|
202 | + function checkSystemChecksum(){ |
|
203 | 203 | global $modx; |
204 | 204 | |
205 | - if(!isset($modx->config['check_files_onlogin']) || empty($modx->config['check_files_onlogin'])) return '0'; |
|
205 | + if (!isset($modx->config['check_files_onlogin']) || empty($modx->config['check_files_onlogin'])) return '0'; |
|
206 | 206 | |
207 | 207 | $current = $this->getSystemChecksum($modx->config['check_files_onlogin']); |
208 | - if(empty($current)) return '0'; |
|
208 | + if (empty($current)) return '0'; |
|
209 | 209 | |
210 | - if(!isset($modx->config['sys_files_checksum']) || empty($modx->config['sys_files_checksum'])) |
|
210 | + if (!isset($modx->config['sys_files_checksum']) || empty($modx->config['sys_files_checksum'])) |
|
211 | 211 | { |
212 | 212 | $this->setSystemChecksum($current); |
213 | 213 | return '0'; |
214 | 214 | } |
215 | - if($current===$modx->config['sys_files_checksum']) $result = '0'; |
|
215 | + if ($current === $modx->config['sys_files_checksum']) $result = '0'; |
|
216 | 216 | else { |
217 | 217 | $result = $this->getModifiedSystemFilesList($modx->config['check_files_onlogin'], $modx->config['sys_files_checksum']); |
218 | 218 | } |
@@ -220,28 +220,28 @@ discard block |
||
220 | 220 | return $result; |
221 | 221 | } |
222 | 222 | |
223 | - function getLastUserSetting($key=false) { |
|
223 | + function getLastUserSetting($key = false){ |
|
224 | 224 | global $modx; |
225 | 225 | |
226 | 226 | $rs = $modx->db->select('*', $modx->getFullTableName('user_settings'), "user = '{$_SESSION['mgrInternalKey']}'"); |
227 | 227 | |
228 | - $usersettings = array (); |
|
228 | + $usersettings = array(); |
|
229 | 229 | while ($row = $modx->db->getRow($rs)) { |
230 | - if(substr($row['setting_name'], 0, 6) == '_LAST_') { |
|
230 | + if (substr($row['setting_name'], 0, 6) == '_LAST_') { |
|
231 | 231 | $name = substr($row['setting_name'], 6); |
232 | 232 | $usersettings[$name] = $row['setting_value']; |
233 | 233 | } |
234 | 234 | } |
235 | 235 | |
236 | - if(!$key) return $usersettings; |
|
236 | + if (!$key) return $usersettings; |
|
237 | 237 | else return isset($usersettings[$key]) ? $usersettings[$key] : NULL; |
238 | 238 | } |
239 | 239 | |
240 | - function saveLastUserSetting($settings, $val='') { |
|
240 | + function saveLastUserSetting($settings, $val = ''){ |
|
241 | 241 | global $modx; |
242 | 242 | |
243 | - if(!empty($settings)) { |
|
244 | - if(!is_array($settings)) $settings = array($settings=>$val); |
|
243 | + if (!empty($settings)) { |
|
244 | + if (!is_array($settings)) $settings = array($settings=>$val); |
|
245 | 245 | |
246 | 246 | foreach ($settings as $key => $val) { |
247 | 247 | $f = array(); |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | } |
257 | 257 | } |
258 | 258 | |
259 | - function loadDatePicker($path) { |
|
259 | + function loadDatePicker($path){ |
|
260 | 260 | global $modx; |
261 | 261 | include_once($path); |
262 | 262 | $dp = new DATEPICKER(); |
@@ -24,13 +24,13 @@ discard block |
||
24 | 24 | // Obviously, since this code is in the public domain, the above are not |
25 | 25 | // requirements (there can be none), but merely suggestions. |
26 | 26 | // |
27 | -class PasswordHash { |
|
27 | +class PasswordHash{ |
|
28 | 28 | var $itoa64; |
29 | 29 | var $iteration_count_log2; |
30 | 30 | var $portable_hashes; |
31 | 31 | var $random_state; |
32 | 32 | |
33 | - function __construct($iteration_count_log2=8, $portable_hashes=true) |
|
33 | + function __construct($iteration_count_log2 = 8, $portable_hashes = true) |
|
34 | 34 | { |
35 | 35 | $this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
36 | 36 | |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | |
41 | 41 | $this->portable_hashes = $portable_hashes; |
42 | 42 | |
43 | - $this->random_state = microtime() . uniqid(mt_rand(), TRUE); |
|
43 | + $this->random_state = microtime().uniqid(mt_rand(), TRUE); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | function get_random_bytes($count) |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | $output = ''; |
57 | 57 | for ($i = 0; $i < $count; $i += 16) { |
58 | 58 | $this->random_state = |
59 | - md5(microtime() . $this->random_state); |
|
59 | + md5(microtime().$this->random_state); |
|
60 | 60 | $output .= |
61 | 61 | pack('H*', md5($this->random_state)); |
62 | 62 | } |
@@ -126,9 +126,9 @@ discard block |
||
126 | 126 | // consequently in lower iteration counts and hashes that are |
127 | 127 | // quicker to crack (by non-PHP code). |
128 | 128 | |
129 | - $hash = md5($salt . $password, TRUE); |
|
129 | + $hash = md5($salt.$password, TRUE); |
|
130 | 130 | do { |
131 | - $hash = md5($hash . $password, TRUE); |
|
131 | + $hash = md5($hash.$password, TRUE); |
|
132 | 132 | } while (--$count); |
133 | 133 | |
134 | 134 | $output = substr($setting, 0, 12); |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | |
199 | 199 | function HashPassword($password) |
200 | 200 | { |
201 | - if ( strlen( $password ) > 4096 ) { |
|
201 | + if (strlen($password) > 4096) { |
|
202 | 202 | return '*'; |
203 | 203 | } |
204 | 204 | |
@@ -237,14 +237,14 @@ discard block |
||
237 | 237 | |
238 | 238 | function CheckPassword($password, $stored_hash) |
239 | 239 | { |
240 | - if ( strlen( $password ) > 4096 ) { |
|
240 | + if (strlen($password) > 4096) { |
|
241 | 241 | return false; |
242 | 242 | } |
243 | 243 | |
244 | 244 | $hash = $this->crypt_private($password, $stored_hash); |
245 | - if (substr($hash,0,1) === '*') |
|
245 | + if (substr($hash, 0, 1) === '*') |
|
246 | 246 | $hash = crypt($password, $stored_hash); |
247 | 247 | |
248 | - return ($hash===$stored_hash) ? true : false; |
|
248 | + return ($hash === $stored_hash) ? true : false; |
|
249 | 249 | } |
250 | 250 | } |
@@ -6,17 +6,17 @@ |
||
6 | 6 | { |
7 | 7 | } |
8 | 8 | |
9 | - function htmlspecialchars($str='', $flags = ENT_COMPAT, $encode='') |
|
9 | + function htmlspecialchars($str = '', $flags = ENT_COMPAT, $encode = '') |
|
10 | 10 | { |
11 | 11 | global $modx; |
12 | 12 | |
13 | - if($str=='') return ''; |
|
13 | + if ($str == '') return ''; |
|
14 | 14 | |
15 | - if($encode=='') $encode = $modx->config['modx_charset']; |
|
15 | + if ($encode == '') $encode = $modx->config['modx_charset']; |
|
16 | 16 | |
17 | 17 | $ent_str = htmlspecialchars($str, $flags, $encode); |
18 | 18 | |
19 | - if(!empty($str) && empty($ent_str)) |
|
19 | + if (!empty($str) && empty($ent_str)) |
|
20 | 20 | { |
21 | 21 | $detect_order = implode(',', mb_detect_order()); |
22 | 22 | $ent_str = mb_convert_encoding($str, $encode, $detect_order); |