@@ -2,22 +2,22 @@ |
||
2 | 2 | $userID = abs($modx->getLoginUserID('web')); |
3 | 3 | $modx->qs_hash = md5($modx->qs_hash."^{$userID}^"); |
4 | 4 | |
5 | -$groupNames = ($this->strlen($opt) > 0 ) ? explode(',',$opt) : array(); |
|
5 | +$groupNames = ($this->strlen($opt) > 0) ? explode(',', $opt) : array(); |
|
6 | 6 | |
7 | 7 | // if $groupNames is not an array return false |
8 | -if(!is_array($groupNames)) return 0; |
|
8 | +if (!is_array($groupNames)) return 0; |
|
9 | 9 | |
10 | 10 | // Creates an array with all webgroups the user id is in |
11 | 11 | if (isset($modx->filter->cache['mo'][$userID])) $grpNames = $modx->filter->cache['mo'][$userID]; |
12 | 12 | else { |
13 | - $from = sprintf("[+prefix+]webgroup_names wgn INNER JOIN [+prefix+]web_groups wg ON wg.webgroup=wgn.id AND wg.webuser='%s'",$userID); |
|
14 | - $rs = $modx->db->select('wgn.name',$from); |
|
15 | - $modx->filter->cache['mo'][$userID] = $grpNames = $modx->db->getColumn('name',$rs); |
|
13 | + $from = sprintf("[+prefix+]webgroup_names wgn INNER JOIN [+prefix+]web_groups wg ON wg.webgroup=wgn.id AND wg.webuser='%s'", $userID); |
|
14 | + $rs = $modx->db->select('wgn.name', $from); |
|
15 | + $modx->filter->cache['mo'][$userID] = $grpNames = $modx->db->getColumn('name', $rs); |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | // Check if a supplied group matches a webgroup from the array we just created |
19 | -foreach($groupNames as $k=>$v) { |
|
20 | - if(in_array(trim($v),$grpNames)) return 1; |
|
19 | +foreach ($groupNames as $k=>$v) { |
|
20 | + if (in_array(trim($v), $grpNames)) return 1; |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | // If we get here the above logic did not find a match, so return false |
@@ -5,13 +5,13 @@ |
||
5 | 5 | * Time: 12:25 |
6 | 6 | */ |
7 | 7 | |
8 | -if (isset($this->phpcompat) && is_object($this->phpcompat)){ |
|
8 | +if (isset($this->phpcompat) && is_object($this->phpcompat)) { |
|
9 | 9 | return true; |
10 | 10 | } |
11 | 11 | |
12 | -if (!include_once(MODX_MANAGER_PATH . 'includes/extenders/phpcompat.class.inc.php')){ |
|
12 | +if (!include_once(MODX_MANAGER_PATH.'includes/extenders/phpcompat.class.inc.php')) { |
|
13 | 13 | return false; |
14 | -}else{ |
|
14 | +} else { |
|
15 | 15 | $this->phpcompat = new PHPCOMPAT; |
16 | 16 | return true; |
17 | 17 | } |
@@ -5,13 +5,13 @@ |
||
5 | 5 | * Time: 19:14 |
6 | 6 | */ |
7 | 7 | |
8 | -if (isset($this->phpass) && is_object($this->phpass)){ |
|
8 | +if (isset($this->phpass) && is_object($this->phpass)) { |
|
9 | 9 | return true; |
10 | 10 | } |
11 | 11 | |
12 | -if (!include_once(MODX_MANAGER_PATH . 'includes/extenders/phpass.class.inc.php')){ |
|
12 | +if (!include_once(MODX_MANAGER_PATH.'includes/extenders/phpass.class.inc.php')) { |
|
13 | 13 | return false; |
14 | -}else{ |
|
14 | +} else { |
|
15 | 15 | $this->phpass = new PasswordHash; |
16 | 16 | return true; |
17 | 17 | } |
18 | 18 | \ No newline at end of file |
@@ -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 | 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(); |