@@ -5,9 +5,9 @@ |
||
5 | 5 | * Time: 14:16 |
6 | 6 | */ |
7 | 7 | |
8 | -if (!include_once MODX_MANAGER_PATH . 'includes/extenders/manager.api.class.inc.php'){ |
|
8 | +if (!include_once MODX_MANAGER_PATH.'includes/extenders/manager.api.class.inc.php') { |
|
9 | 9 | return false; |
10 | -}else{ |
|
11 | - $this->manager= new ManagerAPI; |
|
10 | +} else { |
|
11 | + $this->manager = new ManagerAPI; |
|
12 | 12 | return true; |
13 | 13 | } |
14 | 14 | \ No newline at end of file |
@@ -1,16 +1,16 @@ |
||
1 | 1 | <?php |
2 | 2 | $pattern = '/<img[\s\n]+.*src=[\s\n]*"([^"]+\.(jpg|jpeg|png|gif))"[^>]+>/i'; |
3 | -preg_match_all($pattern , $value , $images); |
|
4 | -if($opt==='') |
|
3 | +preg_match_all($pattern, $value, $images); |
|
4 | +if ($opt === '') |
|
5 | 5 | { |
6 | - if($images[1][0]) return $images[1][0]; |
|
6 | + if ($images[1][0]) return $images[1][0]; |
|
7 | 7 | else return ''; |
8 | 8 | } |
9 | 9 | else |
10 | 10 | { |
11 | - foreach($images[0] as $i=>$image) |
|
11 | + foreach ($images[0] as $i=>$image) |
|
12 | 12 | { |
13 | - if(strpos($image,$opt)!==false) return $images[1][$i]; |
|
13 | + if (strpos($image, $opt) !== false) return $images[1][$i]; |
|
14 | 14 | } |
15 | 15 | } |
16 | 16 |
@@ -1,2 +1,2 @@ |
||
1 | 1 | <?php |
2 | -return preg_replace_callback("~(\b\w+\b)~",function($m) use($wrapat) {return wordwrap($m[1],$wrapat,' ',1);},$value); |
|
2 | +return preg_replace_callback("~(\b\w+\b)~", function($m) use($wrapat) {return wordwrap($m[1], $wrapat, ' ', 1); },$value); |
@@ -1,21 +1,21 @@ |
||
1 | 1 | <?php |
2 | 2 | $text = $modx->filter->parseDocumentSource($value); |
3 | -$text = str_replace(array("\r\n","\r"),"\n",$text); |
|
3 | +$text = str_replace(array("\r\n", "\r"), "\n", $text); |
|
4 | 4 | |
5 | 5 | $blockElms = 'br,table,tbody,tr,td,th,thead,tfoot,caption,colgroup,div'; |
6 | 6 | $blockElms .= ',dl,dd,dt,ul,ol,li,pre,select,option,form,map,area,blockquote'; |
7 | 7 | $blockElms .= ',address,math,style,input,p,h1,h2,h3,h4,h5,h6,hr,object,param,embed'; |
8 | 8 | $blockElms .= ',noframes,noscript,section,article,aside,hgroup,footer,address,code'; |
9 | 9 | $blockElms = explode(',', $blockElms); |
10 | -$lines = explode("\n",$text); |
|
10 | +$lines = explode("\n", $text); |
|
11 | 11 | $c = count($lines); |
12 | -foreach($lines as $i=>$line) |
|
12 | +foreach ($lines as $i=>$line) |
|
13 | 13 | { |
14 | 14 | $line = rtrim($line); |
15 | - if($i===$c-1) break; |
|
16 | - foreach($blockElms as $block) |
|
15 | + if ($i === $c - 1) break; |
|
16 | + foreach ($blockElms as $block) |
|
17 | 17 | { |
18 | - if(preg_match("@</?{$block}" . '[^>]*>$@',$line)) |
|
18 | + if (preg_match("@</?{$block}".'[^>]*>$@', $line)) |
|
19 | 19 | continue 2; |
20 | 20 | } |
21 | 21 | $lines[$i] = "{$line}<br />"; |
@@ -1,43 +1,43 @@ |
||
1 | 1 | <?php |
2 | -if(strpos($opt,',')) list($limit,$delim) = explode(',', $opt); |
|
3 | -elseif(preg_match('/^[1-9][0-9]*$/',$opt)) {$limit=$opt;$delim='';} |
|
4 | -else {$limit=124;$delim='';} |
|
2 | +if (strpos($opt, ',')) list($limit, $delim) = explode(',', $opt); |
|
3 | +elseif (preg_match('/^[1-9][0-9]*$/', $opt)) {$limit = $opt; $delim = ''; } |
|
4 | +else {$limit = 124; $delim = ''; } |
|
5 | 5 | |
6 | -if($delim==='') $delim = $modx->config['manager_language']==='japanese-utf8' ? '。' : '.'; |
|
6 | +if ($delim === '') $delim = $modx->config['manager_language'] === 'japanese-utf8' ? '。' : '.'; |
|
7 | 7 | $limit = intval($limit); |
8 | 8 | |
9 | 9 | $content = $modx->filter->parseDocumentSource($value); |
10 | 10 | |
11 | 11 | $content = strip_tags($content); |
12 | 12 | |
13 | -$content = str_replace(array("\r\n","\r","\n","\t",' '),' ',$content); |
|
14 | -if(preg_match('/\s+/',$content)) |
|
15 | - $content = preg_replace('/\s+/',' ',$content); |
|
13 | +$content = str_replace(array("\r\n", "\r", "\n", "\t", ' '), ' ', $content); |
|
14 | +if (preg_match('/\s+/', $content)) |
|
15 | + $content = preg_replace('/\s+/', ' ', $content); |
|
16 | 16 | $content = trim($content); |
17 | 17 | |
18 | 18 | $pos = $modx->filter->strpos($content, $delim); |
19 | 19 | |
20 | -if($pos!==false && $pos<$limit) { |
|
20 | +if ($pos !== false && $pos < $limit) { |
|
21 | 21 | $_ = explode($delim, $content); |
22 | 22 | $text = ''; |
23 | - foreach($_ as $v) { |
|
24 | - if($limit <= $modx->filter->strlen($text.$v.$delim)) break; |
|
23 | + foreach ($_ as $v) { |
|
24 | + if ($limit <= $modx->filter->strlen($text.$v.$delim)) break; |
|
25 | 25 | $text .= $v.$delim; |
26 | 26 | } |
27 | - if($text) $content = $text; |
|
27 | + if ($text) $content = $text; |
|
28 | 28 | } |
29 | 29 | |
30 | -if($limit<$modx->filter->strlen($content) && strpos($content,' ')!==false) { |
|
30 | +if ($limit < $modx->filter->strlen($content) && strpos($content, ' ') !== false) { |
|
31 | 31 | $_ = explode(' ', $content); |
32 | 32 | $text = ''; |
33 | - foreach($_ as $v) { |
|
34 | - if($limit <= $modx->filter->strlen($text.$v.' ')) break; |
|
35 | - $text .= $v . ' '; |
|
33 | + foreach ($_ as $v) { |
|
34 | + if ($limit <= $modx->filter->strlen($text.$v.' ')) break; |
|
35 | + $text .= $v.' '; |
|
36 | 36 | } |
37 | - if($text!=='') $content = $text; |
|
37 | + if ($text !== '') $content = $text; |
|
38 | 38 | } |
39 | 39 | |
40 | -if($limit < $modx->filter->strlen($content)) $content = $modx->filter->substr($content, 0, $limit); |
|
41 | -if($modx->filter->substr($content,-1)==$delim) $content = rtrim($content,$delim) . $delim; |
|
40 | +if ($limit < $modx->filter->strlen($content)) $content = $modx->filter->substr($content, 0, $limit); |
|
41 | +if ($modx->filter->substr($content, -1) == $delim) $content = rtrim($content, $delim).$delim; |
|
42 | 42 | |
43 | 43 | return $content; |
@@ -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(' ', $_); |