@@ -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 />"; |
@@ -9,14 +9,15 @@ |
||
9 | 9 | $blockElms = explode(',', $blockElms); |
10 | 10 | $lines = explode("\n",$text); |
11 | 11 | $c = count($lines); |
12 | -foreach($lines as $i=>$line) |
|
13 | -{ |
|
12 | +foreach($lines as $i=>$line) { |
|
14 | 13 | $line = rtrim($line); |
15 | - if($i===$c-1) break; |
|
16 | - foreach($blockElms as $block) |
|
17 | - { |
|
18 | - if(preg_match("@</?{$block}" . '[^>]*>$@',$line)) |
|
19 | - continue 2; |
|
14 | + if($i===$c-1) { |
|
15 | + break; |
|
16 | + } |
|
17 | + foreach($blockElms as $block) { |
|
18 | + if(preg_match("@</?{$block}" . '[^>]*>$@',$line)) { |
|
19 | + continue 2; |
|
20 | + } |
|
20 | 21 | } |
21 | 22 | $lines[$i] = "{$line}<br />"; |
22 | 23 | } |
@@ -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; |
@@ -1,9 +1,11 @@ discard block |
||
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,',')) { |
|
3 | + list($limit,$delim) = explode(',', $opt); |
|
4 | +} elseif(preg_match('/^[1-9][0-9]*$/',$opt)) {$limit=$opt;$delim='';} else {$limit=124;$delim='';} |
|
5 | 5 | |
6 | -if($delim==='') $delim = $modx->config['manager_language']==='japanese-utf8' ? '。' : '.'; |
|
6 | +if($delim==='') { |
|
7 | + $delim = $modx->config['manager_language']==='japanese-utf8' ? '。' : '.'; |
|
8 | +} |
|
7 | 9 | $limit = intval($limit); |
8 | 10 | |
9 | 11 | $content = $modx->filter->parseDocumentSource($value); |
@@ -11,8 +13,9 @@ discard block |
||
11 | 13 | $content = strip_tags($content); |
12 | 14 | |
13 | 15 | $content = str_replace(array("\r\n","\r","\n","\t",' '),' ',$content); |
14 | -if(preg_match('/\s+/',$content)) |
|
16 | +if(preg_match('/\s+/',$content)) { |
|
15 | 17 | $content = preg_replace('/\s+/',' ',$content); |
18 | +} |
|
16 | 19 | $content = trim($content); |
17 | 20 | |
18 | 21 | $pos = $modx->filter->strpos($content, $delim); |
@@ -21,23 +24,35 @@ discard block |
||
21 | 24 | $_ = explode($delim, $content); |
22 | 25 | $text = ''; |
23 | 26 | foreach($_ as $v) { |
24 | - if($limit <= $modx->filter->strlen($text.$v.$delim)) break; |
|
27 | + if($limit <= $modx->filter->strlen($text.$v.$delim)) { |
|
28 | + break; |
|
29 | + } |
|
25 | 30 | $text .= $v.$delim; |
26 | 31 | } |
27 | - if($text) $content = $text; |
|
28 | -} |
|
32 | + if($text) { |
|
33 | + $content = $text; |
|
34 | + } |
|
35 | + } |
|
29 | 36 | |
30 | 37 | if($limit<$modx->filter->strlen($content) && strpos($content,' ')!==false) { |
31 | 38 | $_ = explode(' ', $content); |
32 | 39 | $text = ''; |
33 | 40 | foreach($_ as $v) { |
34 | - if($limit <= $modx->filter->strlen($text.$v.' ')) break; |
|
41 | + if($limit <= $modx->filter->strlen($text.$v.' ')) { |
|
42 | + break; |
|
43 | + } |
|
35 | 44 | $text .= $v . ' '; |
36 | 45 | } |
37 | - if($text!=='') $content = $text; |
|
38 | -} |
|
46 | + if($text!=='') { |
|
47 | + $content = $text; |
|
48 | + } |
|
49 | + } |
|
39 | 50 | |
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; |
|
51 | +if($limit < $modx->filter->strlen($content)) { |
|
52 | + $content = $modx->filter->substr($content, 0, $limit); |
|
53 | +} |
|
54 | +if($modx->filter->substr($content,-1)==$delim) { |
|
55 | + $content = rtrim($content,$delim) . $delim; |
|
56 | +} |
|
42 | 57 | |
43 | 58 | 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,11 +5,14 @@ discard block |
||
5 | 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)) { |
|
9 | + return 0; |
|
10 | +} |
|
9 | 11 | |
10 | 12 | // Creates an array with all webgroups the user id is in |
11 | -if (isset($modx->filter->cache['mo'][$userID])) $grpNames = $modx->filter->cache['mo'][$userID]; |
|
12 | -else { |
|
13 | +if (isset($modx->filter->cache['mo'][$userID])) { |
|
14 | + $grpNames = $modx->filter->cache['mo'][$userID]; |
|
15 | +} else { |
|
13 | 16 | $from = sprintf("[+prefix+]webgroup_names wgn INNER JOIN [+prefix+]web_groups wg ON wg.webgroup=wgn.id AND wg.webuser='%s'",$userID); |
14 | 17 | $rs = $modx->db->select('wgn.name',$from); |
15 | 18 | $modx->filter->cache['mo'][$userID] = $grpNames = $modx->db->getColumn('name',$rs); |
@@ -17,8 +20,10 @@ discard block |
||
17 | 20 | |
18 | 21 | // Check if a supplied group matches a webgroup from the array we just created |
19 | 22 | foreach($groupNames as $k=>$v) { |
20 | - if(in_array(trim($v),$grpNames)) return 1; |
|
21 | -} |
|
23 | + if(in_array(trim($v),$grpNames)) { |
|
24 | + return 1; |
|
25 | + } |
|
26 | + } |
|
22 | 27 | |
23 | 28 | // If we get here the above logic did not find a match, so return false |
24 | 29 | return 0; |
@@ -19,60 +19,60 @@ |
||
19 | 19 | </head><body> |
20 | 20 | "; |
21 | 21 | if($is_error) { |
22 | - $parsedMessageString .= "<h3 style='color:red;background:#e0e0e0;padding:2px;'> MODX Parse Error </h3> |
|
22 | + $parsedMessageString .= "<h3 style='color:red;background:#e0e0e0;padding:2px;'> MODX Parse Error </h3> |
|
23 | 23 | <table border='0' cellpadding='1' cellspacing='0'> |
24 | 24 | <tr><td colspan='3'>MODX encountered the following error while attempting to parse the requested resource:</td></tr> |
25 | 25 | <tr><td colspan='3'><b style='color:red;'>« $msg »</b></td></tr>"; |
26 | 26 | } else { |
27 | - $parsedMessageString .= "<h3 style='color:#003399; background:#eeeeee;padding:2px;'> MODX Debug/ stop message </h3> |
|
27 | + $parsedMessageString .= "<h3 style='color:#003399; background:#eeeeee;padding:2px;'> MODX Debug/ stop message </h3> |
|
28 | 28 | <table border='0' cellpadding='1' cellspacing='0'> |
29 | 29 | <tr><td colspan='3'>The MODX parser recieved the following debug/ stop message:</td></tr> |
30 | 30 | <tr><td colspan='3'><b style='color:#003399;'>« $msg »</b></td></tr>"; |
31 | 31 | } |
32 | 32 | |
33 | 33 | if(!empty($query)) { |
34 | - $parsedMessageString .= "<tr><td colspan='3'><hr size='1' width='98%' style='color:#e0e0e0'/><b style='color:#999;font-size: 9px;border-left:1px solid #c0c0c0; margin-left:10px;'> SQL: <span id='sqlHolder'>$query</span></b><hr size='1' width='98%' style='color:#e0e0e0'/> |
|
34 | + $parsedMessageString .= "<tr><td colspan='3'><hr size='1' width='98%' style='color:#e0e0e0'/><b style='color:#999;font-size: 9px;border-left:1px solid #c0c0c0; margin-left:10px;'> SQL: <span id='sqlHolder'>$query</span></b><hr size='1' width='98%' style='color:#e0e0e0'/> |
|
35 | 35 | <a href='javascript:copyToClip();' style='color:#821517;font-size: 9px; text-decoration: none'>[Copy SQL to ClipBoard]</a><textarea id='holdtext' style='display:none;'></textarea></td></tr>"; |
36 | 36 | } |
37 | 37 | |
38 | 38 | if($text!='') { |
39 | 39 | |
40 | - $errortype = array ( |
|
41 | - E_ERROR => "Error", |
|
42 | - E_WARNING => "Warning", |
|
43 | - E_PARSE => "Parsing Error", |
|
44 | - E_NOTICE => "Notice", |
|
45 | - E_CORE_ERROR => "Core Error", |
|
46 | - E_CORE_WARNING => "Core Warning", |
|
47 | - E_COMPILE_ERROR => "Compile Error", |
|
48 | - E_COMPILE_WARNING => "Compile Warning", |
|
49 | - E_USER_ERROR => "User Error", |
|
50 | - E_USER_WARNING => "User Warning", |
|
51 | - E_USER_NOTICE => "User Notice", |
|
52 | - ); |
|
40 | + $errortype = array ( |
|
41 | + E_ERROR => "Error", |
|
42 | + E_WARNING => "Warning", |
|
43 | + E_PARSE => "Parsing Error", |
|
44 | + E_NOTICE => "Notice", |
|
45 | + E_CORE_ERROR => "Core Error", |
|
46 | + E_CORE_WARNING => "Core Warning", |
|
47 | + E_COMPILE_ERROR => "Compile Error", |
|
48 | + E_COMPILE_WARNING => "Compile Warning", |
|
49 | + E_USER_ERROR => "User Error", |
|
50 | + E_USER_WARNING => "User Warning", |
|
51 | + E_USER_NOTICE => "User Notice", |
|
52 | + ); |
|
53 | 53 | |
54 | - $parsedMessageString .= "<tr><td> </td></tr><tr><td colspan='3'><b>PHP error debug</b></td></tr>"; |
|
54 | + $parsedMessageString .= "<tr><td> </td></tr><tr><td colspan='3'><b>PHP error debug</b></td></tr>"; |
|
55 | 55 | |
56 | - $parsedMessageString .= "<tr><td valign='top'> Error: </td>"; |
|
57 | - $parsedMessageString .= "<td colspan='2'>$text</td><td> </td>"; |
|
58 | - $parsedMessageString .= "</tr>"; |
|
56 | + $parsedMessageString .= "<tr><td valign='top'> Error: </td>"; |
|
57 | + $parsedMessageString .= "<td colspan='2'>$text</td><td> </td>"; |
|
58 | + $parsedMessageString .= "</tr>"; |
|
59 | 59 | |
60 | - $parsedMessageString .= "<tr><td valign='top'> Error type/ Nr.: </td>"; |
|
61 | - $parsedMessageString .= "<td colspan='2'>".$errortype[$nr]." - $nr</b></td><td> </td>"; |
|
62 | - $parsedMessageString .= "</tr>"; |
|
60 | + $parsedMessageString .= "<tr><td valign='top'> Error type/ Nr.: </td>"; |
|
61 | + $parsedMessageString .= "<td colspan='2'>".$errortype[$nr]." - $nr</b></td><td> </td>"; |
|
62 | + $parsedMessageString .= "</tr>"; |
|
63 | 63 | |
64 | - $parsedMessageString .= "<tr><td> File: </td>"; |
|
65 | - $parsedMessageString .= "<td colspan='2'>$file</td><td> </td>"; |
|
66 | - $parsedMessageString .= "</tr>"; |
|
64 | + $parsedMessageString .= "<tr><td> File: </td>"; |
|
65 | + $parsedMessageString .= "<td colspan='2'>$file</td><td> </td>"; |
|
66 | + $parsedMessageString .= "</tr>"; |
|
67 | 67 | |
68 | - $parsedMessageString .= "<tr><td> Line: </td>"; |
|
69 | - $parsedMessageString .= "<td colspan='2'>$line</td><td> </td>"; |
|
70 | - $parsedMessageString .= "</tr>"; |
|
71 | - if($source!='') { |
|
72 | - $parsedMessageString .= "<tr><td valign='top'> Line $line source: </td>"; |
|
73 | - $parsedMessageString .= "<td colspan='2'>$source</td><td> </td>"; |
|
74 | - $parsedMessageString .= "</tr>"; |
|
75 | - } |
|
68 | + $parsedMessageString .= "<tr><td> Line: </td>"; |
|
69 | + $parsedMessageString .= "<td colspan='2'>$line</td><td> </td>"; |
|
70 | + $parsedMessageString .= "</tr>"; |
|
71 | + if($source!='') { |
|
72 | + $parsedMessageString .= "<tr><td valign='top'> Line $line source: </td>"; |
|
73 | + $parsedMessageString .= "<td colspan='2'>$source</td><td> </td>"; |
|
74 | + $parsedMessageString .= "</tr>"; |
|
75 | + } |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | $parsedMessageString .= "<tr><td> </td></tr><tr><td colspan='3'><b>Parser timing</b></td></tr>"; |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Message Quit Template |
4 | 4 | * |
5 | 5 | */ |
6 | -if(( ! defined('IN_MANAGER_MODE') || IN_MANAGER_MODE !== true) && IN_PARSER_MODE!="true") { |
|
6 | +if ((!defined('IN_MANAGER_MODE') || IN_MANAGER_MODE !== true) && IN_PARSER_MODE != "true") { |
|
7 | 7 | die("<b>INCLUDE ACCESS ERROR</b><br /><br />Direct access to this file prohibited."); |
8 | 8 | } |
9 | 9 | |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | </script> |
21 | 21 | </head><body> |
22 | 22 | "; |
23 | -if($is_error) { |
|
23 | +if ($is_error) { |
|
24 | 24 | $parsedMessageString .= "<h3 style='color:red;background:#e0e0e0;padding:2px;'> MODX Parse Error </h3> |
25 | 25 | <table border='0' cellpadding='1' cellspacing='0'> |
26 | 26 | <tr><td colspan='3'>MODX encountered the following error while attempting to parse the requested resource:</td></tr> |
@@ -32,14 +32,14 @@ discard block |
||
32 | 32 | <tr><td colspan='3'><b style='color:#003399;'>« $msg »</b></td></tr>"; |
33 | 33 | } |
34 | 34 | |
35 | -if(!empty($query)) { |
|
35 | +if (!empty($query)) { |
|
36 | 36 | $parsedMessageString .= "<tr><td colspan='3'><hr size='1' width='98%' style='color:#e0e0e0'/><b style='color:#999;font-size: 9px;border-left:1px solid #c0c0c0; margin-left:10px;'> SQL: <span id='sqlHolder'>$query</span></b><hr size='1' width='98%' style='color:#e0e0e0'/> |
37 | 37 | <a href='javascript:copyToClip();' style='color:#821517;font-size: 9px; text-decoration: none'>[Copy SQL to ClipBoard]</a><textarea id='holdtext' style='display:none;'></textarea></td></tr>"; |
38 | 38 | } |
39 | 39 | |
40 | -if($text!='') { |
|
40 | +if ($text != '') { |
|
41 | 41 | |
42 | - $errortype = array ( |
|
42 | + $errortype = array( |
|
43 | 43 | E_ERROR => "Error", |
44 | 44 | E_WARNING => "Warning", |
45 | 45 | E_PARSE => "Parsing Error", |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | $parsedMessageString .= "<tr><td> Line: </td>"; |
71 | 71 | $parsedMessageString .= "<td colspan='2'>$line</td><td> </td>"; |
72 | 72 | $parsedMessageString .= "</tr>"; |
73 | - if($source!='') { |
|
73 | + if ($source != '') { |
|
74 | 74 | $parsedMessageString .= "<tr><td valign='top'> Line $line source: </td>"; |
75 | 75 | $parsedMessageString .= "<td colspan='2'>$source</td><td> </td>"; |
76 | 76 | $parsedMessageString .= "</tr>"; |
@@ -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: 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 |
@@ -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 |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | function getUserData() { |
41 | 41 | $client['ip'] = $_SERVER['REMOTE_ADDR']; |
42 | 42 | $client['ua'] = $_SERVER['HTTP_USER_AGENT']; |
43 | - return $client; |
|
43 | + return $client; |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | # Returns true, install or interact when inside manager |
@@ -60,12 +60,12 @@ discard block |
||
60 | 60 | |
61 | 61 | // deprecated |
62 | 62 | function putChunk($chunkName) { // alias name >.< |
63 | - global $modx; |
|
63 | + global $modx; |
|
64 | 64 | return $modx->getChunk($chunkName); |
65 | 65 | } |
66 | 66 | |
67 | 67 | function getDocGroups() { |
68 | - global $modx; |
|
68 | + global $modx; |
|
69 | 69 | return $modx->getUserDocGroups(); |
70 | 70 | } // deprecated |
71 | 71 | |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | } // deprecated |
75 | 75 | |
76 | 76 | function userLoggedIn() { |
77 | - global $modx; |
|
77 | + global $modx; |
|
78 | 78 | $userdetails= array (); |
79 | 79 | if ($modx->isFrontend() && isset ($_SESSION['webValidated'])) { |
80 | 80 | // web user |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | |
99 | 99 | function getFormVars($method= "", $prefix= "", $trim= "", $REQUEST_METHOD) { |
100 | 100 | // function to retrieve form results into an associative array |
101 | - global $modx; |
|
101 | + global $modx; |
|
102 | 102 | $results= array (); |
103 | 103 | $method= strtoupper($method); |
104 | 104 | if ($method == "") |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | * @param string $url URL to redirect to |
131 | 131 | */ |
132 | 132 | function webAlert($msg, $url= "") { |
133 | - global $modx; |
|
133 | + global $modx; |
|
134 | 134 | $msg= addslashes($modx->db->escape($msg)); |
135 | 135 | if (substr(strtolower($url), 0, 11) == "javascript:") { |
136 | 136 | $act= "__WebAlert();"; |
@@ -1,43 +1,43 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | $this->old = new OldFunctions(); |
3 | -class OldFunctions { |
|
3 | +class OldFunctions{ |
|
4 | 4 | |
5 | - function dbConnect() {global $modx; $modx->db->connect();$modx->rs = $modx->db->conn;} |
|
6 | - function dbQuery($sql) {global $modx;return $modx->db->query($sql);} |
|
7 | - function recordCount($rs) {global $modx;return $modx->db->getRecordCount($rs);} |
|
8 | - function fetchRow($rs,$mode='assoc') {global $modx;return $modx->db->getRow($rs, $mode);} |
|
9 | - function affectedRows($rs) {global $modx;return $modx->db->getAffectedRows($rs);} |
|
10 | - function insertId($rs) {global $modx;return $modx->db->getInsertId($rs);} |
|
11 | - function dbClose() {global $modx; $modx->db->disconnect();} |
|
5 | + function dbConnect(){global $modx; $modx->db->connect(); $modx->rs = $modx->db->conn; } |
|
6 | + function dbQuery($sql){global $modx; return $modx->db->query($sql); } |
|
7 | + function recordCount($rs){global $modx; return $modx->db->getRecordCount($rs); } |
|
8 | + function fetchRow($rs, $mode = 'assoc'){global $modx; return $modx->db->getRow($rs, $mode); } |
|
9 | + function affectedRows($rs){global $modx; return $modx->db->getAffectedRows($rs); } |
|
10 | + function insertId($rs){global $modx; return $modx->db->getInsertId($rs); } |
|
11 | + function dbClose(){global $modx; $modx->db->disconnect(); } |
|
12 | 12 | |
13 | - function makeList($array, $ulroot= 'root', $ulprefix= 'sub_', $type= '', $ordered= false, $tablevel= 0) { |
|
13 | + function makeList($array, $ulroot = 'root', $ulprefix = 'sub_', $type = '', $ordered = false, $tablevel = 0){ |
|
14 | 14 | // first find out whether the value passed is an array |
15 | 15 | if (!is_array($array)) { |
16 | 16 | return "<ul><li>Bad list</li></ul>"; |
17 | 17 | } |
18 | 18 | if (!empty ($type)) { |
19 | - $typestr= " style='list-style-type: $type'"; |
|
19 | + $typestr = " style='list-style-type: $type'"; |
|
20 | 20 | } else { |
21 | - $typestr= ""; |
|
21 | + $typestr = ""; |
|
22 | 22 | } |
23 | - $tabs= ""; |
|
24 | - for ($i= 0; $i < $tablevel; $i++) { |
|
23 | + $tabs = ""; |
|
24 | + for ($i = 0; $i < $tablevel; $i++) { |
|
25 | 25 | $tabs .= "\t"; |
26 | 26 | } |
27 | - $listhtml= $ordered == true ? $tabs . "<ol class='$ulroot'$typestr>\n" : $tabs . "<ul class='$ulroot'$typestr>\n"; |
|
27 | + $listhtml = $ordered == true ? $tabs."<ol class='$ulroot'$typestr>\n" : $tabs."<ul class='$ulroot'$typestr>\n"; |
|
28 | 28 | foreach ($array as $key => $value) { |
29 | 29 | if (is_array($value)) { |
30 | - $listhtml .= $tabs . "\t<li>" . $key . "\n" . $this->makeList($value, $ulprefix . $ulroot, $ulprefix, $type, $ordered, $tablevel +2) . $tabs . "\t</li>\n"; |
|
30 | + $listhtml .= $tabs."\t<li>".$key."\n".$this->makeList($value, $ulprefix.$ulroot, $ulprefix, $type, $ordered, $tablevel + 2).$tabs."\t</li>\n"; |
|
31 | 31 | } else { |
32 | - $listhtml .= $tabs . "\t<li>" . $value . "</li>\n"; |
|
32 | + $listhtml .= $tabs."\t<li>".$value."</li>\n"; |
|
33 | 33 | } |
34 | 34 | } |
35 | - $listhtml .= $ordered == true ? $tabs . "</ol>\n" : $tabs . "</ul>\n"; |
|
35 | + $listhtml .= $ordered == true ? $tabs."</ol>\n" : $tabs."</ul>\n"; |
|
36 | 36 | return $listhtml; |
37 | 37 | } |
38 | 38 | |
39 | 39 | |
40 | - function getUserData() { |
|
40 | + function getUserData(){ |
|
41 | 41 | $client['ip'] = $_SERVER['REMOTE_ADDR']; |
42 | 42 | $client['ua'] = $_SERVER['HTTP_USER_AGENT']; |
43 | 43 | return $client; |
@@ -45,80 +45,80 @@ discard block |
||
45 | 45 | |
46 | 46 | # Returns true, install or interact when inside manager |
47 | 47 | // deprecated |
48 | - function insideManager() { |
|
49 | - $m= false; |
|
50 | - if( defined('IN_MANAGER_MODE') && IN_MANAGER_MODE === true) { |
|
51 | - $m= true; |
|
48 | + function insideManager(){ |
|
49 | + $m = false; |
|
50 | + if (defined('IN_MANAGER_MODE') && IN_MANAGER_MODE === true) { |
|
51 | + $m = true; |
|
52 | 52 | if (defined('SNIPPET_INTERACTIVE_MODE') && SNIPPET_INTERACTIVE_MODE == 'true') |
53 | - $m= "interact"; |
|
53 | + $m = "interact"; |
|
54 | 54 | else |
55 | 55 | if (defined('SNIPPET_INSTALL_MODE') && SNIPPET_INSTALL_MODE == 'true') |
56 | - $m= "install"; |
|
56 | + $m = "install"; |
|
57 | 57 | } |
58 | 58 | return $m; |
59 | 59 | } |
60 | 60 | |
61 | 61 | // deprecated |
62 | - function putChunk($chunkName) { // alias name >.< |
|
62 | + function putChunk($chunkName){ // alias name >.< |
|
63 | 63 | global $modx; |
64 | 64 | return $modx->getChunk($chunkName); |
65 | 65 | } |
66 | 66 | |
67 | - function getDocGroups() { |
|
67 | + function getDocGroups(){ |
|
68 | 68 | global $modx; |
69 | 69 | return $modx->getUserDocGroups(); |
70 | 70 | } // deprecated |
71 | 71 | |
72 | - function changePassword($o, $n) { |
|
72 | + function changePassword($o, $n){ |
|
73 | 73 | return changeWebUserPassword($o, $n); |
74 | 74 | } // deprecated |
75 | 75 | |
76 | - function userLoggedIn() { |
|
76 | + function userLoggedIn(){ |
|
77 | 77 | global $modx; |
78 | - $userdetails= array (); |
|
78 | + $userdetails = array(); |
|
79 | 79 | if ($modx->isFrontend() && isset ($_SESSION['webValidated'])) { |
80 | 80 | // web user |
81 | - $userdetails['loggedIn']= true; |
|
82 | - $userdetails['id']= $_SESSION['webInternalKey']; |
|
83 | - $userdetails['username']= $_SESSION['webShortname']; |
|
84 | - $userdetails['usertype']= 'web'; // added by Raymond |
|
81 | + $userdetails['loggedIn'] = true; |
|
82 | + $userdetails['id'] = $_SESSION['webInternalKey']; |
|
83 | + $userdetails['username'] = $_SESSION['webShortname']; |
|
84 | + $userdetails['usertype'] = 'web'; // added by Raymond |
|
85 | 85 | return $userdetails; |
86 | 86 | } else |
87 | 87 | if ($modx->isBackend() && isset ($_SESSION['mgrValidated'])) { |
88 | 88 | // manager user |
89 | - $userdetails['loggedIn']= true; |
|
90 | - $userdetails['id']= $_SESSION['mgrInternalKey']; |
|
91 | - $userdetails['username']= $_SESSION['mgrShortname']; |
|
92 | - $userdetails['usertype']= 'manager'; // added by Raymond |
|
89 | + $userdetails['loggedIn'] = true; |
|
90 | + $userdetails['id'] = $_SESSION['mgrInternalKey']; |
|
91 | + $userdetails['username'] = $_SESSION['mgrShortname']; |
|
92 | + $userdetails['usertype'] = 'manager'; // added by Raymond |
|
93 | 93 | return $userdetails; |
94 | 94 | } else { |
95 | 95 | return false; |
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
99 | - function getFormVars($method= "", $prefix= "", $trim= "", $REQUEST_METHOD) { |
|
99 | + function getFormVars($method = "", $prefix = "", $trim = "", $REQUEST_METHOD){ |
|
100 | 100 | // function to retrieve form results into an associative array |
101 | 101 | global $modx; |
102 | - $results= array (); |
|
103 | - $method= strtoupper($method); |
|
102 | + $results = array(); |
|
103 | + $method = strtoupper($method); |
|
104 | 104 | if ($method == "") |
105 | - $method= $REQUEST_METHOD; |
|
105 | + $method = $REQUEST_METHOD; |
|
106 | 106 | if ($method == "POST") |
107 | - $method= & $_POST; |
|
108 | - elseif ($method == "GET") $method= & $_GET; |
|
107 | + $method = & $_POST; |
|
108 | + elseif ($method == "GET") $method = & $_GET; |
|
109 | 109 | else |
110 | 110 | return false; |
111 | 111 | reset($method); |
112 | 112 | foreach ($method as $key => $value) { |
113 | 113 | if (($prefix != "") && (substr($key, 0, strlen($prefix)) == $prefix)) { |
114 | 114 | if ($trim) { |
115 | - $pieces= explode($prefix, $key, 2); |
|
116 | - $key= $pieces[1]; |
|
117 | - $results[$key]= $value; |
|
115 | + $pieces = explode($prefix, $key, 2); |
|
116 | + $key = $pieces[1]; |
|
117 | + $results[$key] = $value; |
|
118 | 118 | } else |
119 | - $results[$key]= $value; |
|
119 | + $results[$key] = $value; |
|
120 | 120 | } |
121 | - elseif ($prefix == "") $results[$key]= $value; |
|
121 | + elseif ($prefix == "") $results[$key] = $value; |
|
122 | 122 | } |
123 | 123 | return $results; |
124 | 124 | } |
@@ -129,16 +129,16 @@ discard block |
||
129 | 129 | * @param string $msg Message to show |
130 | 130 | * @param string $url URL to redirect to |
131 | 131 | */ |
132 | - function webAlert($msg, $url= "") { |
|
132 | + function webAlert($msg, $url = ""){ |
|
133 | 133 | global $modx; |
134 | - $msg= addslashes($modx->db->escape($msg)); |
|
134 | + $msg = addslashes($modx->db->escape($msg)); |
|
135 | 135 | if (substr(strtolower($url), 0, 11) == "javascript:") { |
136 | - $act= "__WebAlert();"; |
|
137 | - $fnc= "function __WebAlert(){" . substr($url, 11) . "};"; |
|
136 | + $act = "__WebAlert();"; |
|
137 | + $fnc = "function __WebAlert(){".substr($url, 11)."};"; |
|
138 | 138 | } else { |
139 | - $act= ($url ? "window.location.href='" . addslashes($url) . "';" : ""); |
|
139 | + $act = ($url ? "window.location.href='".addslashes($url)."';" : ""); |
|
140 | 140 | } |
141 | - $html= "<script>$fnc window.setTimeout(\"alert('$msg');$act\",100);</script>"; |
|
141 | + $html = "<script>$fnc window.setTimeout(\"alert('$msg');$act\",100);</script>"; |
|
142 | 142 | if ($modx->isFrontend()) |
143 | 143 | $modx->regClientScript($html); |
144 | 144 | else { |
@@ -1,16 +1,32 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | $this->old = new OldFunctions(); |
3 | -class OldFunctions { |
|
3 | +class OldFunctions |
|
4 | +{ |
|
4 | 5 | |
5 | - function dbConnect() {global $modx; $modx->db->connect();$modx->rs = $modx->db->conn;} |
|
6 | - function dbQuery($sql) {global $modx;return $modx->db->query($sql);} |
|
7 | - function recordCount($rs) {global $modx;return $modx->db->getRecordCount($rs);} |
|
8 | - function fetchRow($rs,$mode='assoc') {global $modx;return $modx->db->getRow($rs, $mode);} |
|
9 | - function affectedRows($rs) {global $modx;return $modx->db->getAffectedRows($rs);} |
|
10 | - function insertId($rs) {global $modx;return $modx->db->getInsertId($rs);} |
|
11 | - function dbClose() {global $modx; $modx->db->disconnect();} |
|
6 | + function dbConnect() |
|
7 | + { |
|
8 | +global $modx; $modx->db->connect();$modx->rs = $modx->db->conn;} |
|
9 | + function dbQuery($sql) |
|
10 | + { |
|
11 | +global $modx;return $modx->db->query($sql);} |
|
12 | + function recordCount($rs) |
|
13 | + { |
|
14 | +global $modx;return $modx->db->getRecordCount($rs);} |
|
15 | + function fetchRow($rs,$mode='assoc') |
|
16 | + { |
|
17 | +global $modx;return $modx->db->getRow($rs, $mode);} |
|
18 | + function affectedRows($rs) |
|
19 | + { |
|
20 | +global $modx;return $modx->db->getAffectedRows($rs);} |
|
21 | + function insertId($rs) |
|
22 | + { |
|
23 | +global $modx;return $modx->db->getInsertId($rs);} |
|
24 | + function dbClose() |
|
25 | + { |
|
26 | +global $modx; $modx->db->disconnect();} |
|
12 | 27 | |
13 | - function makeList($array, $ulroot= 'root', $ulprefix= 'sub_', $type= '', $ordered= false, $tablevel= 0) { |
|
28 | + function makeList($array, $ulroot= 'root', $ulprefix= 'sub_', $type= '', $ordered= false, $tablevel= 0) |
|
29 | + { |
|
14 | 30 | // first find out whether the value passed is an array |
15 | 31 | if (!is_array($array)) { |
16 | 32 | return "<ul><li>Bad list</li></ul>"; |
@@ -37,7 +53,8 @@ discard block |
||
37 | 53 | } |
38 | 54 | |
39 | 55 | |
40 | - function getUserData() { |
|
56 | + function getUserData() |
|
57 | + { |
|
41 | 58 | $client['ip'] = $_SERVER['REMOTE_ADDR']; |
42 | 59 | $client['ua'] = $_SERVER['HTTP_USER_AGENT']; |
43 | 60 | return $client; |
@@ -45,35 +62,42 @@ discard block |
||
45 | 62 | |
46 | 63 | # Returns true, install or interact when inside manager |
47 | 64 | // deprecated |
48 | - function insideManager() { |
|
65 | + function insideManager() |
|
66 | + { |
|
49 | 67 | $m= false; |
50 | 68 | if( defined('IN_MANAGER_MODE') && IN_MANAGER_MODE === true) { |
51 | 69 | $m= true; |
52 | - if (defined('SNIPPET_INTERACTIVE_MODE') && SNIPPET_INTERACTIVE_MODE == 'true') |
|
53 | - $m= "interact"; |
|
54 | - else |
|
55 | - if (defined('SNIPPET_INSTALL_MODE') && SNIPPET_INSTALL_MODE == 'true') |
|
56 | - $m= "install"; |
|
70 | + if (defined('SNIPPET_INTERACTIVE_MODE') && SNIPPET_INTERACTIVE_MODE == 'true') { |
|
71 | + $m= "interact"; |
|
72 | + } else |
|
73 | + if (defined('SNIPPET_INSTALL_MODE') && SNIPPET_INSTALL_MODE == 'true') { |
|
74 | + $m= "install"; |
|
75 | + } |
|
57 | 76 | } |
58 | 77 | return $m; |
59 | 78 | } |
60 | 79 | |
61 | 80 | // deprecated |
62 | - function putChunk($chunkName) { // alias name >.< |
|
81 | + function putChunk($chunkName) |
|
82 | + { |
|
83 | +// alias name >.< |
|
63 | 84 | global $modx; |
64 | 85 | return $modx->getChunk($chunkName); |
65 | 86 | } |
66 | 87 | |
67 | - function getDocGroups() { |
|
88 | + function getDocGroups() |
|
89 | + { |
|
68 | 90 | global $modx; |
69 | 91 | return $modx->getUserDocGroups(); |
70 | 92 | } // deprecated |
71 | 93 | |
72 | - function changePassword($o, $n) { |
|
94 | + function changePassword($o, $n) |
|
95 | + { |
|
73 | 96 | return changeWebUserPassword($o, $n); |
74 | 97 | } // deprecated |
75 | 98 | |
76 | - function userLoggedIn() { |
|
99 | + function userLoggedIn() |
|
100 | + { |
|
77 | 101 | global $modx; |
78 | 102 | $userdetails= array (); |
79 | 103 | if ($modx->isFrontend() && isset ($_SESSION['webValidated'])) { |
@@ -96,18 +120,22 @@ discard block |
||
96 | 120 | } |
97 | 121 | } |
98 | 122 | |
99 | - function getFormVars($method= "", $prefix= "", $trim= "", $REQUEST_METHOD) { |
|
123 | + function getFormVars($method= "", $prefix= "", $trim= "", $REQUEST_METHOD) |
|
124 | + { |
|
100 | 125 | // function to retrieve form results into an associative array |
101 | 126 | global $modx; |
102 | 127 | $results= array (); |
103 | 128 | $method= strtoupper($method); |
104 | - if ($method == "") |
|
105 | - $method= $REQUEST_METHOD; |
|
106 | - if ($method == "POST") |
|
107 | - $method= & $_POST; |
|
108 | - elseif ($method == "GET") $method= & $_GET; |
|
109 | - else |
|
110 | - return false; |
|
129 | + if ($method == "") { |
|
130 | + $method= $REQUEST_METHOD; |
|
131 | + } |
|
132 | + if ($method == "POST") { |
|
133 | + $method= & $_POST; |
|
134 | + } elseif ($method == "GET") { |
|
135 | + $method= & $_GET; |
|
136 | + } else { |
|
137 | + return false; |
|
138 | + } |
|
111 | 139 | reset($method); |
112 | 140 | foreach ($method as $key => $value) { |
113 | 141 | if (($prefix != "") && (substr($key, 0, strlen($prefix)) == $prefix)) { |
@@ -115,10 +143,12 @@ discard block |
||
115 | 143 | $pieces= explode($prefix, $key, 2); |
116 | 144 | $key= $pieces[1]; |
117 | 145 | $results[$key]= $value; |
118 | - } else |
|
119 | - $results[$key]= $value; |
|
146 | + } else { |
|
147 | + $results[$key]= $value; |
|
148 | + } |
|
149 | + } elseif ($prefix == "") { |
|
150 | + $results[$key]= $value; |
|
120 | 151 | } |
121 | - elseif ($prefix == "") $results[$key]= $value; |
|
122 | 152 | } |
123 | 153 | return $results; |
124 | 154 | } |
@@ -129,7 +159,8 @@ discard block |
||
129 | 159 | * @param string $msg Message to show |
130 | 160 | * @param string $url URL to redirect to |
131 | 161 | */ |
132 | - function webAlert($msg, $url= "") { |
|
162 | + function webAlert($msg, $url= "") |
|
163 | + { |
|
133 | 164 | global $modx; |
134 | 165 | $msg= addslashes($modx->db->escape($msg)); |
135 | 166 | if (substr(strtolower($url), 0, 11) == "javascript:") { |
@@ -139,9 +170,9 @@ discard block |
||
139 | 170 | $act= ($url ? "window.location.href='" . addslashes($url) . "';" : ""); |
140 | 171 | } |
141 | 172 | $html= "<script>$fnc window.setTimeout(\"alert('$msg');$act\",100);</script>"; |
142 | - if ($modx->isFrontend()) |
|
143 | - $modx->regClientScript($html); |
|
144 | - else { |
|
173 | + if ($modx->isFrontend()) { |
|
174 | + $modx->regClientScript($html); |
|
175 | + } else { |
|
145 | 176 | echo $html; |
146 | 177 | } |
147 | 178 | } |
@@ -1,104 +1,104 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | class DBAPI { |
3 | - var $conn; |
|
4 | - var $config; |
|
5 | - var $lastQuery; |
|
6 | - var $isConnected; |
|
3 | + var $conn; |
|
4 | + var $config; |
|
5 | + var $lastQuery; |
|
6 | + var $isConnected; |
|
7 | 7 | |
8 | - function __construct($host='', $dbase='', $uid='', $pwd='', $pre=NULL, $charset='', $connection_method='SET CHARACTER SET') { |
|
9 | - $this->config['host'] = $host ? $host : $GLOBALS['database_server']; |
|
10 | - $this->config['dbase'] = $dbase ? $dbase : $GLOBALS['dbase']; |
|
11 | - $this->config['user'] = $uid ? $uid : $GLOBALS['database_user']; |
|
12 | - $this->config['pass'] = $pwd ? $pwd : $GLOBALS['database_password']; |
|
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); |
|
15 | - $this->config['table_prefix'] = ($pre !== NULL) ? $pre : $GLOBALS['table_prefix']; |
|
16 | - } |
|
8 | + function __construct($host='', $dbase='', $uid='', $pwd='', $pre=NULL, $charset='', $connection_method='SET CHARACTER SET') { |
|
9 | + $this->config['host'] = $host ? $host : $GLOBALS['database_server']; |
|
10 | + $this->config['dbase'] = $dbase ? $dbase : $GLOBALS['dbase']; |
|
11 | + $this->config['user'] = $uid ? $uid : $GLOBALS['database_user']; |
|
12 | + $this->config['pass'] = $pwd ? $pwd : $GLOBALS['database_password']; |
|
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); |
|
15 | + $this->config['table_prefix'] = ($pre !== NULL) ? $pre : $GLOBALS['table_prefix']; |
|
16 | + } |
|
17 | 17 | |
18 | - function connect($host = '', $dbase = '', $uid = '', $pwd = '', $tmp = 0) { |
|
19 | - global $modx; |
|
20 | - $uid = $uid ? $uid : $this->config['user']; |
|
21 | - $pwd = $pwd ? $pwd : $this->config['pass']; |
|
22 | - $host = $host ? $host : $this->config['host']; |
|
23 | - $dbase = $dbase ? $dbase : $this->config['dbase']; |
|
24 | - $dbase = trim($dbase, '`'); // remove the `` chars |
|
25 | - $charset = $this->config['charset']; |
|
26 | - $connection_method = $this->config['connection_method']; |
|
27 | - $tstart = $modx->getMicroTime(); |
|
28 | - $safe_count = 0; |
|
29 | - do { |
|
30 | - $this->conn = new mysqli($host, $uid, $pwd, $dbase); |
|
31 | - if ($this->conn->connect_error) { |
|
32 | - $this->conn = null; |
|
33 | - if (isset($modx->config['send_errormail']) && $modx->config['send_errormail'] !== '0') { |
|
34 | - if ($modx->config['send_errormail'] <= 2) { |
|
35 | - $logtitle = 'Failed to create the database connection!'; |
|
36 | - $request_uri = $modx->htmlspecialchars($_SERVER['REQUEST_URI']); |
|
37 | - $ua = $modx->htmlspecialchars($_SERVER['HTTP_USER_AGENT']); |
|
38 | - $referer = $modx->htmlspecialchars($_SERVER['HTTP_REFERER']); |
|
39 | - $modx->sendmail(array( |
|
40 | - 'subject' => 'Missing to create the database connection! from ' . $modx->config['site_name'], |
|
41 | - 'body' => "{$logtitle}\n{$request_uri}\n{$ua}\n{$referer}", |
|
42 | - 'type' => 'text' |
|
43 | - )); |
|
44 | - } |
|
45 | - } |
|
46 | - sleep(1); |
|
47 | - $safe_count++; |
|
48 | - } |
|
49 | - } while (!$this->conn && $safe_count<3); |
|
50 | - if (!$this->conn) { |
|
51 | - $modx->messageQuit("Failed to create the database connection!"); |
|
52 | - exit; |
|
53 | - } else { |
|
54 | - $this->conn->query("{$connection_method} {$charset}"); |
|
55 | - $tend = $modx->getMicroTime(); |
|
56 | - $totaltime = $tend - $tstart; |
|
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 />"; |
|
59 | - } |
|
60 | - $this->conn->set_charset($this->config['charset']); |
|
61 | - $this->isConnected = true; |
|
62 | - $modx->queryTime += $totaltime; |
|
63 | - } |
|
64 | - } |
|
18 | + function connect($host = '', $dbase = '', $uid = '', $pwd = '', $tmp = 0) { |
|
19 | + global $modx; |
|
20 | + $uid = $uid ? $uid : $this->config['user']; |
|
21 | + $pwd = $pwd ? $pwd : $this->config['pass']; |
|
22 | + $host = $host ? $host : $this->config['host']; |
|
23 | + $dbase = $dbase ? $dbase : $this->config['dbase']; |
|
24 | + $dbase = trim($dbase, '`'); // remove the `` chars |
|
25 | + $charset = $this->config['charset']; |
|
26 | + $connection_method = $this->config['connection_method']; |
|
27 | + $tstart = $modx->getMicroTime(); |
|
28 | + $safe_count = 0; |
|
29 | + do { |
|
30 | + $this->conn = new mysqli($host, $uid, $pwd, $dbase); |
|
31 | + if ($this->conn->connect_error) { |
|
32 | + $this->conn = null; |
|
33 | + if (isset($modx->config['send_errormail']) && $modx->config['send_errormail'] !== '0') { |
|
34 | + if ($modx->config['send_errormail'] <= 2) { |
|
35 | + $logtitle = 'Failed to create the database connection!'; |
|
36 | + $request_uri = $modx->htmlspecialchars($_SERVER['REQUEST_URI']); |
|
37 | + $ua = $modx->htmlspecialchars($_SERVER['HTTP_USER_AGENT']); |
|
38 | + $referer = $modx->htmlspecialchars($_SERVER['HTTP_REFERER']); |
|
39 | + $modx->sendmail(array( |
|
40 | + 'subject' => 'Missing to create the database connection! from ' . $modx->config['site_name'], |
|
41 | + 'body' => "{$logtitle}\n{$request_uri}\n{$ua}\n{$referer}", |
|
42 | + 'type' => 'text' |
|
43 | + )); |
|
44 | + } |
|
45 | + } |
|
46 | + sleep(1); |
|
47 | + $safe_count++; |
|
48 | + } |
|
49 | + } while (!$this->conn && $safe_count<3); |
|
50 | + if (!$this->conn) { |
|
51 | + $modx->messageQuit("Failed to create the database connection!"); |
|
52 | + exit; |
|
53 | + } else { |
|
54 | + $this->conn->query("{$connection_method} {$charset}"); |
|
55 | + $tend = $modx->getMicroTime(); |
|
56 | + $totaltime = $tend - $tstart; |
|
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 />"; |
|
59 | + } |
|
60 | + $this->conn->set_charset($this->config['charset']); |
|
61 | + $this->isConnected = true; |
|
62 | + $modx->queryTime += $totaltime; |
|
63 | + } |
|
64 | + } |
|
65 | 65 | |
66 | - function disconnect() { |
|
67 | - $this->conn->close(); |
|
68 | - $this->conn = null; |
|
69 | - $this->isConnected = false; |
|
70 | - } |
|
66 | + function disconnect() { |
|
67 | + $this->conn->close(); |
|
68 | + $this->conn = null; |
|
69 | + $this->isConnected = false; |
|
70 | + } |
|
71 | 71 | |
72 | - function escape($s, $safecount=0) { |
|
73 | - $safecount++; |
|
74 | - if (1000<$safecount) exit("Too many loops '{$safecount}'"); |
|
75 | - if (empty ($this->conn) || !is_object($this->conn)) { |
|
76 | - $this->connect(); |
|
77 | - } |
|
78 | - if (is_array($s)) { |
|
79 | - if (count($s) === 0) { |
|
80 | - $s = ''; |
|
81 | - } else { |
|
82 | - foreach ($s as $i=>$v) { |
|
83 | - $s[$i] = $this->escape($v, $safecount); |
|
84 | - } |
|
85 | - } |
|
86 | - } else { |
|
87 | - $s = $this->conn->escape_string($s); |
|
88 | - } |
|
89 | - return $s; |
|
90 | - } |
|
72 | + function escape($s, $safecount=0) { |
|
73 | + $safecount++; |
|
74 | + if (1000<$safecount) exit("Too many loops '{$safecount}'"); |
|
75 | + if (empty ($this->conn) || !is_object($this->conn)) { |
|
76 | + $this->connect(); |
|
77 | + } |
|
78 | + if (is_array($s)) { |
|
79 | + if (count($s) === 0) { |
|
80 | + $s = ''; |
|
81 | + } else { |
|
82 | + foreach ($s as $i=>$v) { |
|
83 | + $s[$i] = $this->escape($v, $safecount); |
|
84 | + } |
|
85 | + } |
|
86 | + } else { |
|
87 | + $s = $this->conn->escape_string($s); |
|
88 | + } |
|
89 | + return $s; |
|
90 | + } |
|
91 | 91 | |
92 | - function query($sql,$watchError=true) { |
|
93 | - global $modx; |
|
94 | - if (empty ($this->conn) || !is_object($this->conn)) { |
|
95 | - $this->connect(); |
|
96 | - } |
|
97 | - $tstart = $modx->getMicroTime(); |
|
98 | - if(is_array($sql)) $sql = join("\n", $sql); |
|
99 | - $this->lastQuery = $sql; |
|
100 | - if (!($result = $this->conn->query($sql))) { |
|
101 | - if(!$watchError) return; |
|
92 | + function query($sql,$watchError=true) { |
|
93 | + global $modx; |
|
94 | + if (empty ($this->conn) || !is_object($this->conn)) { |
|
95 | + $this->connect(); |
|
96 | + } |
|
97 | + $tstart = $modx->getMicroTime(); |
|
98 | + if(is_array($sql)) $sql = join("\n", $sql); |
|
99 | + $this->lastQuery = $sql; |
|
100 | + if (!($result = $this->conn->query($sql))) { |
|
101 | + if(!$watchError) return; |
|
102 | 102 | switch(mysqli_errno($this->conn)) { |
103 | 103 | case 1054: |
104 | 104 | case 1060: |
@@ -109,119 +109,119 @@ discard block |
||
109 | 109 | default: |
110 | 110 | $modx->messageQuit('Execution of a query to the database failed - ' . $this->getLastError(), $sql); |
111 | 111 | } |
112 | - } else { |
|
113 | - $tend = $modx->getMicroTime(); |
|
114 | - $totaltime = $tend - $tstart; |
|
115 | - $modx->queryTime = $modx->queryTime + $totaltime; |
|
116 | - if ($modx->dumpSQL) { |
|
117 | - $debug = debug_backtrace(); |
|
118 | - array_shift($debug); |
|
119 | - $debug_path = array(); |
|
120 | - foreach ($debug as $line) $debug_path[] = $line['function']; |
|
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>'; |
|
130 | - $modx->queryCode .= "</fieldset><br />"; |
|
131 | - } |
|
132 | - $modx->executedQueries = $modx->executedQueries + 1; |
|
133 | - return $result; |
|
134 | - } |
|
135 | - } |
|
112 | + } else { |
|
113 | + $tend = $modx->getMicroTime(); |
|
114 | + $totaltime = $tend - $tstart; |
|
115 | + $modx->queryTime = $modx->queryTime + $totaltime; |
|
116 | + if ($modx->dumpSQL) { |
|
117 | + $debug = debug_backtrace(); |
|
118 | + array_shift($debug); |
|
119 | + $debug_path = array(); |
|
120 | + foreach ($debug as $line) $debug_path[] = $line['function']; |
|
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>'; |
|
130 | + $modx->queryCode .= "</fieldset><br />"; |
|
131 | + } |
|
132 | + $modx->executedQueries = $modx->executedQueries + 1; |
|
133 | + return $result; |
|
134 | + } |
|
135 | + } |
|
136 | 136 | |
137 | - function delete($from, $where='', $orderby='', $limit = '') { |
|
138 | - global $modx; |
|
139 | - if (!$from) { |
|
140 | - $modx->messageQuit("Empty \$from parameters in DBAPI::delete()."); |
|
141 | - } else { |
|
142 | - $from = $this->replaceFullTableName($from); |
|
143 | - $where = trim($where); |
|
144 | - $orderby = trim($orderby); |
|
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}"; |
|
149 | - return $this->query("DELETE FROM {$from} {$where} {$orderby} {$limit}"); |
|
150 | - } |
|
151 | - } |
|
137 | + function delete($from, $where='', $orderby='', $limit = '') { |
|
138 | + global $modx; |
|
139 | + if (!$from) { |
|
140 | + $modx->messageQuit("Empty \$from parameters in DBAPI::delete()."); |
|
141 | + } else { |
|
142 | + $from = $this->replaceFullTableName($from); |
|
143 | + $where = trim($where); |
|
144 | + $orderby = trim($orderby); |
|
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}"; |
|
149 | + return $this->query("DELETE FROM {$from} {$where} {$orderby} {$limit}"); |
|
150 | + } |
|
151 | + } |
|
152 | 152 | |
153 | - function select($fields = "*", $from = "", $where = "", $orderby = "", $limit = "") { |
|
154 | - global $modx; |
|
153 | + function select($fields = "*", $from = "", $where = "", $orderby = "", $limit = "") { |
|
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 | - if (!$from) { |
|
161 | - $modx->messageQuit("Empty \$from parameters in DBAPI::select()."); |
|
162 | - exit; |
|
163 | - } |
|
160 | + if (!$from) { |
|
161 | + $modx->messageQuit("Empty \$from parameters in DBAPI::select()."); |
|
162 | + exit; |
|
163 | + } |
|
164 | 164 | |
165 | - $fields = $this->replaceFullTableName($fields); |
|
166 | - $from = $this->replaceFullTableName($from); |
|
165 | + $fields = $this->replaceFullTableName($fields); |
|
166 | + $from = $this->replaceFullTableName($from); |
|
167 | 167 | $where = trim($where); |
168 | 168 | $orderby = trim($orderby); |
169 | 169 | $limit = trim($limit); |
170 | 170 | if($where!=='' && stripos($where,'WHERE')!==0) $where = "WHERE {$where}"; |
171 | 171 | if($orderby!=='' && stripos($orderby,'ORDER')!==0) $orderby = "ORDER BY {$orderby}"; |
172 | 172 | if($limit!=='' && stripos($limit,'LIMIT')!==0) $limit = "LIMIT {$limit}"; |
173 | - return $this->query("SELECT {$fields} FROM {$from} {$where} {$orderby} {$limit}"); |
|
174 | - } |
|
173 | + return $this->query("SELECT {$fields} FROM {$from} {$where} {$orderby} {$limit}"); |
|
174 | + } |
|
175 | 175 | |
176 | - function update($fields, $table, $where = "") { |
|
177 | - global $modx; |
|
178 | - if (!$table) { |
|
179 | - $modx->messageQuit("Empty \$table parameter in DBAPI::update()."); |
|
180 | - } else { |
|
181 | - $table = $this->replaceFullTableName($table); |
|
182 | - if (is_array($fields)) { |
|
183 | - foreach ($fields as $key => $value) { |
|
184 | - if(is_null($value) || strtolower($value) === 'null'){ |
|
185 | - $flds = 'NULL'; |
|
186 | - }else{ |
|
187 | - $flds = "'" . $value . "'"; |
|
188 | - } |
|
189 | - $fields[$key] = "`{$key}` = ".$flds; |
|
190 | - } |
|
191 | - $fields = implode(",", $fields); |
|
192 | - } |
|
193 | - $where = trim($where); |
|
194 | - if($where!=='' && stripos($where, 'WHERE')!==0) $where = "WHERE {$where}"; |
|
195 | - return $this->query("UPDATE {$table} SET {$fields} {$where}"); |
|
196 | - } |
|
197 | - } |
|
176 | + function update($fields, $table, $where = "") { |
|
177 | + global $modx; |
|
178 | + if (!$table) { |
|
179 | + $modx->messageQuit("Empty \$table parameter in DBAPI::update()."); |
|
180 | + } else { |
|
181 | + $table = $this->replaceFullTableName($table); |
|
182 | + if (is_array($fields)) { |
|
183 | + foreach ($fields as $key => $value) { |
|
184 | + if(is_null($value) || strtolower($value) === 'null'){ |
|
185 | + $flds = 'NULL'; |
|
186 | + }else{ |
|
187 | + $flds = "'" . $value . "'"; |
|
188 | + } |
|
189 | + $fields[$key] = "`{$key}` = ".$flds; |
|
190 | + } |
|
191 | + $fields = implode(",", $fields); |
|
192 | + } |
|
193 | + $where = trim($where); |
|
194 | + if($where!=='' && stripos($where, 'WHERE')!==0) $where = "WHERE {$where}"; |
|
195 | + return $this->query("UPDATE {$table} SET {$fields} {$where}"); |
|
196 | + } |
|
197 | + } |
|
198 | 198 | |
199 | - function insert($fields, $intotable, $fromfields = "*", $fromtable = "", $where = "", $limit = "") { |
|
200 | - global $modx; |
|
201 | - if (!$intotable) { |
|
202 | - $modx->messageQuit("Empty \$intotable parameters in DBAPI::insert()."); |
|
203 | - } else { |
|
204 | - $intotable = $this->replaceFullTableName($intotable); |
|
205 | - if (!is_array($fields)) { |
|
206 | - $this->query("INSERT INTO {$intotable} {$fields}"); |
|
207 | - } else { |
|
208 | - if (empty($fromtable)) { |
|
209 | - $fields = "(`".implode("`, `", array_keys($fields))."`) VALUES('".implode("', '", array_values($fields))."')"; |
|
210 | - $rt = $this->query("INSERT INTO {$intotable} {$fields}"); |
|
211 | - } else { |
|
212 | - $fromtable = $this->replaceFullTableName($fromtable); |
|
213 | - $fields = "(".implode(",", array_keys($fields)).")"; |
|
214 | - $where = trim($where); |
|
215 | - $limit = trim($limit); |
|
216 | - if($where!=='' && stripos($where, 'WHERE')!==0) $where = "WHERE {$where}"; |
|
217 | - if($limit!=='' && stripos($limit, 'LIMIT')!==0) $limit = "LIMIT {$limit}"; |
|
218 | - $rt = $this->query("INSERT INTO {$intotable} {$fields} SELECT {$fromfields} FROM {$fromtable} {$where} {$limit}"); |
|
219 | - } |
|
220 | - } |
|
221 | - if (($lid = $this->getInsertId())===false) $modx->messageQuit("Couldn't get last insert key!"); |
|
222 | - return $lid; |
|
223 | - } |
|
224 | - } |
|
199 | + function insert($fields, $intotable, $fromfields = "*", $fromtable = "", $where = "", $limit = "") { |
|
200 | + global $modx; |
|
201 | + if (!$intotable) { |
|
202 | + $modx->messageQuit("Empty \$intotable parameters in DBAPI::insert()."); |
|
203 | + } else { |
|
204 | + $intotable = $this->replaceFullTableName($intotable); |
|
205 | + if (!is_array($fields)) { |
|
206 | + $this->query("INSERT INTO {$intotable} {$fields}"); |
|
207 | + } else { |
|
208 | + if (empty($fromtable)) { |
|
209 | + $fields = "(`".implode("`, `", array_keys($fields))."`) VALUES('".implode("', '", array_values($fields))."')"; |
|
210 | + $rt = $this->query("INSERT INTO {$intotable} {$fields}"); |
|
211 | + } else { |
|
212 | + $fromtable = $this->replaceFullTableName($fromtable); |
|
213 | + $fields = "(".implode(",", array_keys($fields)).")"; |
|
214 | + $where = trim($where); |
|
215 | + $limit = trim($limit); |
|
216 | + if($where!=='' && stripos($where, 'WHERE')!==0) $where = "WHERE {$where}"; |
|
217 | + if($limit!=='' && stripos($limit, 'LIMIT')!==0) $limit = "LIMIT {$limit}"; |
|
218 | + $rt = $this->query("INSERT INTO {$intotable} {$fields} SELECT {$fromfields} FROM {$fromtable} {$where} {$limit}"); |
|
219 | + } |
|
220 | + } |
|
221 | + if (($lid = $this->getInsertId())===false) $modx->messageQuit("Couldn't get last insert key!"); |
|
222 | + return $lid; |
|
223 | + } |
|
224 | + } |
|
225 | 225 | |
226 | 226 | function save($fields, $table, $where='') { // This is similar to "replace into table". |
227 | 227 | |
@@ -233,182 +233,182 @@ discard block |
||
233 | 233 | else return $this->update($fields, $table, $where); |
234 | 234 | } |
235 | 235 | |
236 | - function isResult($rs) { |
|
237 | - return is_object($rs); |
|
238 | - } |
|
236 | + function isResult($rs) { |
|
237 | + return is_object($rs); |
|
238 | + } |
|
239 | 239 | |
240 | - function freeResult($rs) { |
|
241 | - $rs->free_result(); |
|
242 | - } |
|
240 | + function freeResult($rs) { |
|
241 | + $rs->free_result(); |
|
242 | + } |
|
243 | 243 | |
244 | - function numFields($rs) { |
|
245 | - return $rs->field_count; |
|
246 | - } |
|
244 | + function numFields($rs) { |
|
245 | + return $rs->field_count; |
|
246 | + } |
|
247 | 247 | |
248 | - function fieldName($rs,$col=0) { |
|
249 | - $field = $rs->fetch_field_direct($col); |
|
250 | - return $field->name; |
|
251 | - } |
|
248 | + function fieldName($rs,$col=0) { |
|
249 | + $field = $rs->fetch_field_direct($col); |
|
250 | + return $field->name; |
|
251 | + } |
|
252 | 252 | |
253 | - function selectDb($name) { |
|
254 | - $this->conn->select_db($name); |
|
255 | - } |
|
253 | + function selectDb($name) { |
|
254 | + $this->conn->select_db($name); |
|
255 | + } |
|
256 | 256 | |
257 | 257 | |
258 | - function getInsertId($conn=NULL) { |
|
259 | - if (!is_object($conn)) $conn =& $this->conn; |
|
260 | - return $conn->insert_id; |
|
261 | - } |
|
258 | + function getInsertId($conn=NULL) { |
|
259 | + if (!is_object($conn)) $conn =& $this->conn; |
|
260 | + return $conn->insert_id; |
|
261 | + } |
|
262 | 262 | |
263 | - function getAffectedRows($conn=NULL) { |
|
264 | - if (!is_object($conn)) $conn =& $this->conn; |
|
265 | - return $conn->affected_rows; |
|
266 | - } |
|
263 | + function getAffectedRows($conn=NULL) { |
|
264 | + if (!is_object($conn)) $conn =& $this->conn; |
|
265 | + return $conn->affected_rows; |
|
266 | + } |
|
267 | 267 | |
268 | - function getLastError($conn=NULL) { |
|
269 | - if (!is_object($conn)) $conn =& $this->conn; |
|
270 | - return $conn->error; |
|
271 | - } |
|
268 | + function getLastError($conn=NULL) { |
|
269 | + if (!is_object($conn)) $conn =& $this->conn; |
|
270 | + return $conn->error; |
|
271 | + } |
|
272 | 272 | |
273 | - function getRecordCount($ds) { |
|
274 | - return (is_object($ds)) ? $ds->num_rows : 0; |
|
275 | - } |
|
273 | + function getRecordCount($ds) { |
|
274 | + return (is_object($ds)) ? $ds->num_rows : 0; |
|
275 | + } |
|
276 | 276 | |
277 | - function getRow($ds, $mode = 'assoc') { |
|
278 | - if (is_object($ds)) { |
|
279 | - if ($mode == 'assoc') { |
|
280 | - return $ds->fetch_assoc(); |
|
281 | - } elseif ($mode == 'num') { |
|
282 | - return $ds->fetch_row(); |
|
283 | - } elseif ($mode == 'object') { |
|
284 | - return $ds->fetch_object(); |
|
285 | - } elseif ($mode == 'both') { |
|
286 | - return $ds->fetch_array(MYSQLI_BOTH); |
|
287 | - } else { |
|
288 | - global $modx; |
|
289 | - $modx->messageQuit("Unknown get type ($mode) specified for fetchRow - must be empty, 'assoc', 'num' or 'both'."); |
|
290 | - } |
|
291 | - } |
|
292 | - } |
|
277 | + function getRow($ds, $mode = 'assoc') { |
|
278 | + if (is_object($ds)) { |
|
279 | + if ($mode == 'assoc') { |
|
280 | + return $ds->fetch_assoc(); |
|
281 | + } elseif ($mode == 'num') { |
|
282 | + return $ds->fetch_row(); |
|
283 | + } elseif ($mode == 'object') { |
|
284 | + return $ds->fetch_object(); |
|
285 | + } elseif ($mode == 'both') { |
|
286 | + return $ds->fetch_array(MYSQLI_BOTH); |
|
287 | + } else { |
|
288 | + global $modx; |
|
289 | + $modx->messageQuit("Unknown get type ($mode) specified for fetchRow - must be empty, 'assoc', 'num' or 'both'."); |
|
290 | + } |
|
291 | + } |
|
292 | + } |
|
293 | 293 | |
294 | - function getColumn($name, $dsq) { |
|
295 | - if (!is_object($dsq)) { |
|
296 | - $dsq = $this->query($dsq); |
|
297 | - } |
|
298 | - if ($dsq) { |
|
299 | - $col = array (); |
|
300 | - while ($row = $this->getRow($dsq)) { |
|
301 | - $col[] = $row[$name]; |
|
302 | - } |
|
303 | - return $col; |
|
304 | - } |
|
305 | - } |
|
294 | + function getColumn($name, $dsq) { |
|
295 | + if (!is_object($dsq)) { |
|
296 | + $dsq = $this->query($dsq); |
|
297 | + } |
|
298 | + if ($dsq) { |
|
299 | + $col = array (); |
|
300 | + while ($row = $this->getRow($dsq)) { |
|
301 | + $col[] = $row[$name]; |
|
302 | + } |
|
303 | + return $col; |
|
304 | + } |
|
305 | + } |
|
306 | 306 | |
307 | - function getColumnNames($dsq) { |
|
308 | - if (!is_object($dsq)) { |
|
309 | - $dsq = $this->query($dsq); |
|
310 | - } |
|
311 | - if ($dsq) { |
|
312 | - $names = array (); |
|
313 | - $limit = $this->numFields($dsq); |
|
314 | - for ($i = 0; $i < $limit; $i++) { |
|
315 | - $names[] = $this->fieldName($dsq, $i); |
|
316 | - } |
|
317 | - return $names; |
|
318 | - } |
|
319 | - } |
|
307 | + function getColumnNames($dsq) { |
|
308 | + if (!is_object($dsq)) { |
|
309 | + $dsq = $this->query($dsq); |
|
310 | + } |
|
311 | + if ($dsq) { |
|
312 | + $names = array (); |
|
313 | + $limit = $this->numFields($dsq); |
|
314 | + for ($i = 0; $i < $limit; $i++) { |
|
315 | + $names[] = $this->fieldName($dsq, $i); |
|
316 | + } |
|
317 | + return $names; |
|
318 | + } |
|
319 | + } |
|
320 | 320 | |
321 | - function getValue($dsq) { |
|
322 | - if (!is_object($dsq)) { |
|
323 | - $dsq = $this->query($dsq); |
|
324 | - } |
|
325 | - if ($dsq) { |
|
326 | - $r = $this->getRow($dsq, "num"); |
|
327 | - return $r[0]; |
|
328 | - } |
|
329 | - } |
|
321 | + function getValue($dsq) { |
|
322 | + if (!is_object($dsq)) { |
|
323 | + $dsq = $this->query($dsq); |
|
324 | + } |
|
325 | + if ($dsq) { |
|
326 | + $r = $this->getRow($dsq, "num"); |
|
327 | + return $r[0]; |
|
328 | + } |
|
329 | + } |
|
330 | 330 | |
331 | - function getTableMetaData($table) { |
|
332 | - $metadata = false; |
|
333 | - if (!empty ($table)) { |
|
334 | - $sql = "SHOW FIELDS FROM $table"; |
|
335 | - if ($ds = $this->query($sql)) { |
|
336 | - while ($row = $this->getRow($ds)) { |
|
337 | - $fieldName = $row['Field']; |
|
338 | - $metadata[$fieldName] = $row; |
|
339 | - } |
|
340 | - } |
|
341 | - } |
|
342 | - return $metadata; |
|
343 | - } |
|
331 | + function getTableMetaData($table) { |
|
332 | + $metadata = false; |
|
333 | + if (!empty ($table)) { |
|
334 | + $sql = "SHOW FIELDS FROM $table"; |
|
335 | + if ($ds = $this->query($sql)) { |
|
336 | + while ($row = $this->getRow($ds)) { |
|
337 | + $fieldName = $row['Field']; |
|
338 | + $metadata[$fieldName] = $row; |
|
339 | + } |
|
340 | + } |
|
341 | + } |
|
342 | + return $metadata; |
|
343 | + } |
|
344 | 344 | |
345 | - function prepareDate($timestamp, $fieldType = 'DATETIME') { |
|
346 | - $date = ''; |
|
347 | - if (!$timestamp === false && $timestamp > 0) { |
|
348 | - switch ($fieldType) { |
|
349 | - case 'DATE' : |
|
350 | - $date = date('Y-m-d', $timestamp); |
|
351 | - break; |
|
352 | - case 'TIME' : |
|
353 | - $date = date('H:i:s', $timestamp); |
|
354 | - break; |
|
355 | - case 'YEAR' : |
|
356 | - $date = date('Y', $timestamp); |
|
357 | - break; |
|
358 | - default : |
|
359 | - $date = date('Y-m-d H:i:s', $timestamp); |
|
360 | - break; |
|
361 | - } |
|
362 | - } |
|
363 | - return $date; |
|
364 | - } |
|
345 | + function prepareDate($timestamp, $fieldType = 'DATETIME') { |
|
346 | + $date = ''; |
|
347 | + if (!$timestamp === false && $timestamp > 0) { |
|
348 | + switch ($fieldType) { |
|
349 | + case 'DATE' : |
|
350 | + $date = date('Y-m-d', $timestamp); |
|
351 | + break; |
|
352 | + case 'TIME' : |
|
353 | + $date = date('H:i:s', $timestamp); |
|
354 | + break; |
|
355 | + case 'YEAR' : |
|
356 | + $date = date('Y', $timestamp); |
|
357 | + break; |
|
358 | + default : |
|
359 | + $date = date('Y-m-d H:i:s', $timestamp); |
|
360 | + break; |
|
361 | + } |
|
362 | + } |
|
363 | + return $date; |
|
364 | + } |
|
365 | 365 | |
366 | - function makeArray($rs='',$index=false){ |
|
367 | - if (!$rs) return false; |
|
368 | - $rsArray = array(); |
|
369 | - $iterator = 0; |
|
370 | - while ($row = $this->getRow($rs)) { |
|
371 | - $returnIndex = $index !== false && isset($row[$index]) ? $row[$index] : $iterator; |
|
372 | - $rsArray[$returnIndex] = $row; |
|
373 | - $iterator++; |
|
374 | - } |
|
375 | - return $rsArray; |
|
376 | - } |
|
366 | + function makeArray($rs='',$index=false){ |
|
367 | + if (!$rs) return false; |
|
368 | + $rsArray = array(); |
|
369 | + $iterator = 0; |
|
370 | + while ($row = $this->getRow($rs)) { |
|
371 | + $returnIndex = $index !== false && isset($row[$index]) ? $row[$index] : $iterator; |
|
372 | + $rsArray[$returnIndex] = $row; |
|
373 | + $iterator++; |
|
374 | + } |
|
375 | + return $rsArray; |
|
376 | + } |
|
377 | 377 | |
378 | - function getVersion() { |
|
379 | - return $this->conn->server_info; |
|
380 | - } |
|
378 | + function getVersion() { |
|
379 | + return $this->conn->server_info; |
|
380 | + } |
|
381 | 381 | |
382 | - function replaceFullTableName($str,$force=null) { |
|
383 | - $str = trim($str); |
|
384 | - $dbase = trim($this->config['dbase'],'`'); |
|
385 | - $prefix = $this->config['table_prefix']; |
|
386 | - if (!empty($force)) { |
|
387 | - $result = "`{$dbase}`.`{$prefix}{$str}`"; |
|
388 | - } elseif (strpos($str,'[+prefix+]')!==false) { |
|
389 | - $result = preg_replace('@\[\+prefix\+\]([0-9a-zA-Z_]+)@', "`{$dbase}`.`{$prefix}$1`", $str); |
|
390 | - } else { |
|
391 | - $result = $str; |
|
392 | - } |
|
393 | - return $result; |
|
394 | - } |
|
382 | + function replaceFullTableName($str,$force=null) { |
|
383 | + $str = trim($str); |
|
384 | + $dbase = trim($this->config['dbase'],'`'); |
|
385 | + $prefix = $this->config['table_prefix']; |
|
386 | + if (!empty($force)) { |
|
387 | + $result = "`{$dbase}`.`{$prefix}{$str}`"; |
|
388 | + } elseif (strpos($str,'[+prefix+]')!==false) { |
|
389 | + $result = preg_replace('@\[\+prefix\+\]([0-9a-zA-Z_]+)@', "`{$dbase}`.`{$prefix}$1`", $str); |
|
390 | + } else { |
|
391 | + $result = $str; |
|
392 | + } |
|
393 | + return $result; |
|
394 | + } |
|
395 | 395 | |
396 | - function optimize($table_name) { |
|
397 | - $rs = $this->query("OPTIMIZE TABLE {$table_name}"); |
|
398 | - if ($rs) { |
|
399 | - $rs = $this->query("ALTER TABLE {$table_name}"); |
|
400 | - } |
|
401 | - return $rs; |
|
402 | - } |
|
396 | + function optimize($table_name) { |
|
397 | + $rs = $this->query("OPTIMIZE TABLE {$table_name}"); |
|
398 | + if ($rs) { |
|
399 | + $rs = $this->query("ALTER TABLE {$table_name}"); |
|
400 | + } |
|
401 | + return $rs; |
|
402 | + } |
|
403 | 403 | |
404 | - function truncate($table_name) { |
|
405 | - $rs = $this->query("TRUNCATE {$table_name}"); |
|
406 | - return $rs; |
|
407 | - } |
|
404 | + function truncate($table_name) { |
|
405 | + $rs = $this->query("TRUNCATE {$table_name}"); |
|
406 | + return $rs; |
|
407 | + } |
|
408 | 408 | |
409 | - function dataSeek($result, $row_number) { |
|
410 | - return $result->data_seek($row_number); |
|
411 | - } |
|
409 | + function dataSeek($result, $row_number) { |
|
410 | + return $result->data_seek($row_number); |
|
411 | + } |
|
412 | 412 | |
413 | 413 | function _getFieldsStringFromArray($fields=array()) { |
414 | 414 |
@@ -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(' ', $_); |
@@ -1,11 +1,13 @@ discard block |
||
1 | 1 | <?php |
2 | -class DBAPI { |
|
2 | +class DBAPI |
|
3 | +{ |
|
3 | 4 | var $conn; |
4 | 5 | var $config; |
5 | 6 | var $lastQuery; |
6 | 7 | var $isConnected; |
7 | 8 | |
8 | - function __construct($host='', $dbase='', $uid='', $pwd='', $pre=NULL, $charset='', $connection_method='SET CHARACTER SET') { |
|
9 | + function __construct($host='', $dbase='', $uid='', $pwd='', $pre=NULL, $charset='', $connection_method='SET CHARACTER SET') |
|
10 | + { |
|
9 | 11 | $this->config['host'] = $host ? $host : $GLOBALS['database_server']; |
10 | 12 | $this->config['dbase'] = $dbase ? $dbase : $GLOBALS['dbase']; |
11 | 13 | $this->config['user'] = $uid ? $uid : $GLOBALS['database_user']; |
@@ -15,7 +17,8 @@ discard block |
||
15 | 17 | $this->config['table_prefix'] = ($pre !== NULL) ? $pre : $GLOBALS['table_prefix']; |
16 | 18 | } |
17 | 19 | |
18 | - function connect($host = '', $dbase = '', $uid = '', $pwd = '', $tmp = 0) { |
|
20 | + function connect($host = '', $dbase = '', $uid = '', $pwd = '', $tmp = 0) |
|
21 | + { |
|
19 | 22 | global $modx; |
20 | 23 | $uid = $uid ? $uid : $this->config['user']; |
21 | 24 | $pwd = $pwd ? $pwd : $this->config['pass']; |
@@ -63,15 +66,19 @@ discard block |
||
63 | 66 | } |
64 | 67 | } |
65 | 68 | |
66 | - function disconnect() { |
|
69 | + function disconnect() |
|
70 | + { |
|
67 | 71 | $this->conn->close(); |
68 | 72 | $this->conn = null; |
69 | 73 | $this->isConnected = false; |
70 | 74 | } |
71 | 75 | |
72 | - function escape($s, $safecount=0) { |
|
76 | + function escape($s, $safecount=0) |
|
77 | + { |
|
73 | 78 | $safecount++; |
74 | - if (1000<$safecount) exit("Too many loops '{$safecount}'"); |
|
79 | + if (1000<$safecount) { |
|
80 | + exit("Too many loops '{$safecount}'"); |
|
81 | + } |
|
75 | 82 | if (empty ($this->conn) || !is_object($this->conn)) { |
76 | 83 | $this->connect(); |
77 | 84 | } |
@@ -89,16 +96,21 @@ discard block |
||
89 | 96 | return $s; |
90 | 97 | } |
91 | 98 | |
92 | - function query($sql,$watchError=true) { |
|
99 | + function query($sql,$watchError=true) |
|
100 | + { |
|
93 | 101 | global $modx; |
94 | 102 | if (empty ($this->conn) || !is_object($this->conn)) { |
95 | 103 | $this->connect(); |
96 | 104 | } |
97 | 105 | $tstart = $modx->getMicroTime(); |
98 | - if(is_array($sql)) $sql = join("\n", $sql); |
|
106 | + if(is_array($sql)) { |
|
107 | + $sql = join("\n", $sql); |
|
108 | + } |
|
99 | 109 | $this->lastQuery = $sql; |
100 | 110 | if (!($result = $this->conn->query($sql))) { |
101 | - if(!$watchError) return; |
|
111 | + if(!$watchError) { |
|
112 | + return; |
|
113 | + } |
|
102 | 114 | switch(mysqli_errno($this->conn)) { |
103 | 115 | case 1054: |
104 | 116 | case 1060: |
@@ -117,15 +129,26 @@ discard block |
||
117 | 129 | $debug = debug_backtrace(); |
118 | 130 | array_shift($debug); |
119 | 131 | $debug_path = array(); |
120 | - foreach ($debug as $line) $debug_path[] = $line['function']; |
|
132 | + foreach ($debug as $line) { |
|
133 | + $debug_path[] = $line['function']; |
|
134 | + } |
|
121 | 135 | $debug_path = implode(' > ', array_reverse($debug_path)); |
122 | 136 | $modx->queryCode .= "<fieldset style='text-align:left'><legend>Query " . ($modx->executedQueries + 1) . " - " . sprintf("%2.2f ms", $totaltime*1000) . "</legend>"; |
123 | 137 | $modx->queryCode .= $sql . '<br><br>'; |
124 | - if ($modx->event->name) $modx->queryCode .= 'Current Event => ' . $modx->event->name . '<br>'; |
|
125 | - if ($modx->event->activePlugin) $modx->queryCode .= 'Current Plugin => ' . $modx->event->activePlugin . '<br>'; |
|
126 | - if ($modx->currentSnippet) $modx->queryCode .= 'Current Snippet => ' . $modx->currentSnippet . '<br>'; |
|
127 | - if (stripos($sql, 'select')===0) $modx->queryCode .= 'Record Count => ' . $this->getRecordCount($result) . '<br>'; |
|
128 | - else $modx->queryCode .= 'Affected Rows => ' . $this->getAffectedRows() . '<br>'; |
|
138 | + if ($modx->event->name) { |
|
139 | + $modx->queryCode .= 'Current Event => ' . $modx->event->name . '<br>'; |
|
140 | + } |
|
141 | + if ($modx->event->activePlugin) { |
|
142 | + $modx->queryCode .= 'Current Plugin => ' . $modx->event->activePlugin . '<br>'; |
|
143 | + } |
|
144 | + if ($modx->currentSnippet) { |
|
145 | + $modx->queryCode .= 'Current Snippet => ' . $modx->currentSnippet . '<br>'; |
|
146 | + } |
|
147 | + if (stripos($sql, 'select')===0) { |
|
148 | + $modx->queryCode .= 'Record Count => ' . $this->getRecordCount($result) . '<br>'; |
|
149 | + } else { |
|
150 | + $modx->queryCode .= 'Affected Rows => ' . $this->getAffectedRows() . '<br>'; |
|
151 | + } |
|
129 | 152 | $modx->queryCode .= 'Functions Path => ' . $debug_path . '<br>'; |
130 | 153 | $modx->queryCode .= "</fieldset><br />"; |
131 | 154 | } |
@@ -134,7 +157,8 @@ discard block |
||
134 | 157 | } |
135 | 158 | } |
136 | 159 | |
137 | - function delete($from, $where='', $orderby='', $limit = '') { |
|
160 | + function delete($from, $where='', $orderby='', $limit = '') |
|
161 | + { |
|
138 | 162 | global $modx; |
139 | 163 | if (!$from) { |
140 | 164 | $modx->messageQuit("Empty \$from parameters in DBAPI::delete()."); |
@@ -143,19 +167,32 @@ discard block |
||
143 | 167 | $where = trim($where); |
144 | 168 | $orderby = trim($orderby); |
145 | 169 | $limit = trim($limit); |
146 | - if($where!=='' && stripos($where, 'WHERE')!==0) $where = "WHERE {$where}"; |
|
147 | - if($orderby!== '' && stripos($orderby,'ORDER BY')!==0) $orderby = "ORDER BY {$orderby}"; |
|
148 | - if($limit!== '' && stripos($limit, 'LIMIT')!==0) $limit = "LIMIT {$limit}"; |
|
170 | + if($where!=='' && stripos($where, 'WHERE')!==0) { |
|
171 | + $where = "WHERE {$where}"; |
|
172 | + } |
|
173 | + if($orderby!== '' && stripos($orderby,'ORDER BY')!==0) { |
|
174 | + $orderby = "ORDER BY {$orderby}"; |
|
175 | + } |
|
176 | + if($limit!== '' && stripos($limit, 'LIMIT')!==0) { |
|
177 | + $limit = "LIMIT {$limit}"; |
|
178 | + } |
|
149 | 179 | return $this->query("DELETE FROM {$from} {$where} {$orderby} {$limit}"); |
150 | 180 | } |
151 | 181 | } |
152 | 182 | |
153 | - function select($fields = "*", $from = "", $where = "", $orderby = "", $limit = "") { |
|
183 | + function select($fields = "*", $from = "", $where = "", $orderby = "", $limit = "") |
|
184 | + { |
|
154 | 185 | global $modx; |
155 | 186 | |
156 | - if(is_array($fields)) $fields = $this->_getFieldsStringFromArray($fields); |
|
157 | - if(is_array($from)) $from = $this->_getFromStringFromArray($from); |
|
158 | - if(is_array($where)) $where = join(' ', $where); |
|
187 | + if(is_array($fields)) { |
|
188 | + $fields = $this->_getFieldsStringFromArray($fields); |
|
189 | + } |
|
190 | + if(is_array($from)) { |
|
191 | + $from = $this->_getFromStringFromArray($from); |
|
192 | + } |
|
193 | + if(is_array($where)) { |
|
194 | + $where = join(' ', $where); |
|
195 | + } |
|
159 | 196 | |
160 | 197 | if (!$from) { |
161 | 198 | $modx->messageQuit("Empty \$from parameters in DBAPI::select()."); |
@@ -167,13 +204,20 @@ discard block |
||
167 | 204 | $where = trim($where); |
168 | 205 | $orderby = trim($orderby); |
169 | 206 | $limit = trim($limit); |
170 | - if($where!=='' && stripos($where,'WHERE')!==0) $where = "WHERE {$where}"; |
|
171 | - if($orderby!=='' && stripos($orderby,'ORDER')!==0) $orderby = "ORDER BY {$orderby}"; |
|
172 | - if($limit!=='' && stripos($limit,'LIMIT')!==0) $limit = "LIMIT {$limit}"; |
|
207 | + if($where!=='' && stripos($where,'WHERE')!==0) { |
|
208 | + $where = "WHERE {$where}"; |
|
209 | + } |
|
210 | + if($orderby!=='' && stripos($orderby,'ORDER')!==0) { |
|
211 | + $orderby = "ORDER BY {$orderby}"; |
|
212 | + } |
|
213 | + if($limit!=='' && stripos($limit,'LIMIT')!==0) { |
|
214 | + $limit = "LIMIT {$limit}"; |
|
215 | + } |
|
173 | 216 | return $this->query("SELECT {$fields} FROM {$from} {$where} {$orderby} {$limit}"); |
174 | 217 | } |
175 | 218 | |
176 | - function update($fields, $table, $where = "") { |
|
219 | + function update($fields, $table, $where = "") |
|
220 | + { |
|
177 | 221 | global $modx; |
178 | 222 | if (!$table) { |
179 | 223 | $modx->messageQuit("Empty \$table parameter in DBAPI::update()."); |
@@ -181,9 +225,9 @@ discard block |
||
181 | 225 | $table = $this->replaceFullTableName($table); |
182 | 226 | if (is_array($fields)) { |
183 | 227 | foreach ($fields as $key => $value) { |
184 | - if(is_null($value) || strtolower($value) === 'null'){ |
|
228 | + if(is_null($value) || strtolower($value) === 'null') { |
|
185 | 229 | $flds = 'NULL'; |
186 | - }else{ |
|
230 | + } else { |
|
187 | 231 | $flds = "'" . $value . "'"; |
188 | 232 | } |
189 | 233 | $fields[$key] = "`{$key}` = ".$flds; |
@@ -191,12 +235,15 @@ discard block |
||
191 | 235 | $fields = implode(",", $fields); |
192 | 236 | } |
193 | 237 | $where = trim($where); |
194 | - if($where!=='' && stripos($where, 'WHERE')!==0) $where = "WHERE {$where}"; |
|
238 | + if($where!=='' && stripos($where, 'WHERE')!==0) { |
|
239 | + $where = "WHERE {$where}"; |
|
240 | + } |
|
195 | 241 | return $this->query("UPDATE {$table} SET {$fields} {$where}"); |
196 | 242 | } |
197 | 243 | } |
198 | 244 | |
199 | - function insert($fields, $intotable, $fromfields = "*", $fromtable = "", $where = "", $limit = "") { |
|
245 | + function insert($fields, $intotable, $fromfields = "*", $fromtable = "", $where = "", $limit = "") |
|
246 | + { |
|
200 | 247 | global $modx; |
201 | 248 | if (!$intotable) { |
202 | 249 | $modx->messageQuit("Empty \$intotable parameters in DBAPI::insert()."); |
@@ -213,68 +260,99 @@ discard block |
||
213 | 260 | $fields = "(".implode(",", array_keys($fields)).")"; |
214 | 261 | $where = trim($where); |
215 | 262 | $limit = trim($limit); |
216 | - if($where!=='' && stripos($where, 'WHERE')!==0) $where = "WHERE {$where}"; |
|
217 | - if($limit!=='' && stripos($limit, 'LIMIT')!==0) $limit = "LIMIT {$limit}"; |
|
263 | + if($where!=='' && stripos($where, 'WHERE')!==0) { |
|
264 | + $where = "WHERE {$where}"; |
|
265 | + } |
|
266 | + if($limit!=='' && stripos($limit, 'LIMIT')!==0) { |
|
267 | + $limit = "LIMIT {$limit}"; |
|
268 | + } |
|
218 | 269 | $rt = $this->query("INSERT INTO {$intotable} {$fields} SELECT {$fromfields} FROM {$fromtable} {$where} {$limit}"); |
219 | 270 | } |
220 | 271 | } |
221 | - if (($lid = $this->getInsertId())===false) $modx->messageQuit("Couldn't get last insert key!"); |
|
272 | + if (($lid = $this->getInsertId())===false) { |
|
273 | + $modx->messageQuit("Couldn't get last insert key!"); |
|
274 | + } |
|
222 | 275 | return $lid; |
223 | 276 | } |
224 | 277 | } |
225 | 278 | |
226 | - function save($fields, $table, $where='') { // This is similar to "replace into table". |
|
279 | + function save($fields, $table, $where='') |
|
280 | + { |
|
281 | +// This is similar to "replace into table". |
|
227 | 282 | |
228 | - if($where === '') $mode = 'insert'; |
|
229 | - elseif($this->getRecordCount($this->select('*',$table,$where))==0) $mode = 'insert'; |
|
230 | - else $mode = 'update'; |
|
283 | + if($where === '') { |
|
284 | + $mode = 'insert'; |
|
285 | + } elseif($this->getRecordCount($this->select('*',$table,$where))==0) { |
|
286 | + $mode = 'insert'; |
|
287 | + } else { |
|
288 | + $mode = 'update'; |
|
289 | + } |
|
231 | 290 | |
232 | - if($mode==='insert') return $this->insert($fields, $table); |
|
233 | - else return $this->update($fields, $table, $where); |
|
291 | + if($mode==='insert') { |
|
292 | + return $this->insert($fields, $table); |
|
293 | + } else { |
|
294 | + return $this->update($fields, $table, $where); |
|
295 | + } |
|
234 | 296 | } |
235 | 297 | |
236 | - function isResult($rs) { |
|
298 | + function isResult($rs) |
|
299 | + { |
|
237 | 300 | return is_object($rs); |
238 | 301 | } |
239 | 302 | |
240 | - function freeResult($rs) { |
|
303 | + function freeResult($rs) |
|
304 | + { |
|
241 | 305 | $rs->free_result(); |
242 | 306 | } |
243 | 307 | |
244 | - function numFields($rs) { |
|
308 | + function numFields($rs) |
|
309 | + { |
|
245 | 310 | return $rs->field_count; |
246 | 311 | } |
247 | 312 | |
248 | - function fieldName($rs,$col=0) { |
|
313 | + function fieldName($rs,$col=0) |
|
314 | + { |
|
249 | 315 | $field = $rs->fetch_field_direct($col); |
250 | 316 | return $field->name; |
251 | 317 | } |
252 | 318 | |
253 | - function selectDb($name) { |
|
319 | + function selectDb($name) |
|
320 | + { |
|
254 | 321 | $this->conn->select_db($name); |
255 | 322 | } |
256 | 323 | |
257 | 324 | |
258 | - function getInsertId($conn=NULL) { |
|
259 | - if (!is_object($conn)) $conn =& $this->conn; |
|
325 | + function getInsertId($conn=NULL) |
|
326 | + { |
|
327 | + if (!is_object($conn)) { |
|
328 | + $conn =& $this->conn; |
|
329 | + } |
|
260 | 330 | return $conn->insert_id; |
261 | 331 | } |
262 | 332 | |
263 | - function getAffectedRows($conn=NULL) { |
|
264 | - if (!is_object($conn)) $conn =& $this->conn; |
|
333 | + function getAffectedRows($conn=NULL) |
|
334 | + { |
|
335 | + if (!is_object($conn)) { |
|
336 | + $conn =& $this->conn; |
|
337 | + } |
|
265 | 338 | return $conn->affected_rows; |
266 | 339 | } |
267 | 340 | |
268 | - function getLastError($conn=NULL) { |
|
269 | - if (!is_object($conn)) $conn =& $this->conn; |
|
341 | + function getLastError($conn=NULL) |
|
342 | + { |
|
343 | + if (!is_object($conn)) { |
|
344 | + $conn =& $this->conn; |
|
345 | + } |
|
270 | 346 | return $conn->error; |
271 | 347 | } |
272 | 348 | |
273 | - function getRecordCount($ds) { |
|
349 | + function getRecordCount($ds) |
|
350 | + { |
|
274 | 351 | return (is_object($ds)) ? $ds->num_rows : 0; |
275 | 352 | } |
276 | 353 | |
277 | - function getRow($ds, $mode = 'assoc') { |
|
354 | + function getRow($ds, $mode = 'assoc') |
|
355 | + { |
|
278 | 356 | if (is_object($ds)) { |
279 | 357 | if ($mode == 'assoc') { |
280 | 358 | return $ds->fetch_assoc(); |
@@ -291,7 +369,8 @@ discard block |
||
291 | 369 | } |
292 | 370 | } |
293 | 371 | |
294 | - function getColumn($name, $dsq) { |
|
372 | + function getColumn($name, $dsq) |
|
373 | + { |
|
295 | 374 | if (!is_object($dsq)) { |
296 | 375 | $dsq = $this->query($dsq); |
297 | 376 | } |
@@ -304,7 +383,8 @@ discard block |
||
304 | 383 | } |
305 | 384 | } |
306 | 385 | |
307 | - function getColumnNames($dsq) { |
|
386 | + function getColumnNames($dsq) |
|
387 | + { |
|
308 | 388 | if (!is_object($dsq)) { |
309 | 389 | $dsq = $this->query($dsq); |
310 | 390 | } |
@@ -318,7 +398,8 @@ discard block |
||
318 | 398 | } |
319 | 399 | } |
320 | 400 | |
321 | - function getValue($dsq) { |
|
401 | + function getValue($dsq) |
|
402 | + { |
|
322 | 403 | if (!is_object($dsq)) { |
323 | 404 | $dsq = $this->query($dsq); |
324 | 405 | } |
@@ -328,7 +409,8 @@ discard block |
||
328 | 409 | } |
329 | 410 | } |
330 | 411 | |
331 | - function getTableMetaData($table) { |
|
412 | + function getTableMetaData($table) |
|
413 | + { |
|
332 | 414 | $metadata = false; |
333 | 415 | if (!empty ($table)) { |
334 | 416 | $sql = "SHOW FIELDS FROM $table"; |
@@ -342,7 +424,8 @@ discard block |
||
342 | 424 | return $metadata; |
343 | 425 | } |
344 | 426 | |
345 | - function prepareDate($timestamp, $fieldType = 'DATETIME') { |
|
427 | + function prepareDate($timestamp, $fieldType = 'DATETIME') |
|
428 | + { |
|
346 | 429 | $date = ''; |
347 | 430 | if (!$timestamp === false && $timestamp > 0) { |
348 | 431 | switch ($fieldType) { |
@@ -363,8 +446,11 @@ discard block |
||
363 | 446 | return $date; |
364 | 447 | } |
365 | 448 | |
366 | - function makeArray($rs='',$index=false){ |
|
367 | - if (!$rs) return false; |
|
449 | + function makeArray($rs='',$index=false) |
|
450 | + { |
|
451 | + if (!$rs) { |
|
452 | + return false; |
|
453 | + } |
|
368 | 454 | $rsArray = array(); |
369 | 455 | $iterator = 0; |
370 | 456 | while ($row = $this->getRow($rs)) { |
@@ -375,11 +461,13 @@ discard block |
||
375 | 461 | return $rsArray; |
376 | 462 | } |
377 | 463 | |
378 | - function getVersion() { |
|
464 | + function getVersion() |
|
465 | + { |
|
379 | 466 | return $this->conn->server_info; |
380 | 467 | } |
381 | 468 | |
382 | - function replaceFullTableName($str,$force=null) { |
|
469 | + function replaceFullTableName($str,$force=null) |
|
470 | + { |
|
383 | 471 | $str = trim($str); |
384 | 472 | $dbase = trim($this->config['dbase'],'`'); |
385 | 473 | $prefix = $this->config['table_prefix']; |
@@ -393,7 +481,8 @@ discard block |
||
393 | 481 | return $result; |
394 | 482 | } |
395 | 483 | |
396 | - function optimize($table_name) { |
|
484 | + function optimize($table_name) |
|
485 | + { |
|
397 | 486 | $rs = $this->query("OPTIMIZE TABLE {$table_name}"); |
398 | 487 | if ($rs) { |
399 | 488 | $rs = $this->query("ALTER TABLE {$table_name}"); |
@@ -401,28 +490,37 @@ discard block |
||
401 | 490 | return $rs; |
402 | 491 | } |
403 | 492 | |
404 | - function truncate($table_name) { |
|
493 | + function truncate($table_name) |
|
494 | + { |
|
405 | 495 | $rs = $this->query("TRUNCATE {$table_name}"); |
406 | 496 | return $rs; |
407 | 497 | } |
408 | 498 | |
409 | - function dataSeek($result, $row_number) { |
|
499 | + function dataSeek($result, $row_number) |
|
500 | + { |
|
410 | 501 | return $result->data_seek($row_number); |
411 | 502 | } |
412 | 503 | |
413 | - function _getFieldsStringFromArray($fields=array()) { |
|
504 | + function _getFieldsStringFromArray($fields=array()) |
|
505 | + { |
|
414 | 506 | |
415 | - if(empty($fields)) return '*'; |
|
507 | + if(empty($fields)) { |
|
508 | + return '*'; |
|
509 | + } |
|
416 | 510 | |
417 | 511 | $_ = array(); |
418 | 512 | foreach($fields as $k=>$v) { |
419 | - if($k!==$v) $_[] = "{$v} as {$k}"; |
|
420 | - else $_[] = $v; |
|
513 | + if($k!==$v) { |
|
514 | + $_[] = "{$v} as {$k}"; |
|
515 | + } else { |
|
516 | + $_[] = $v; |
|
517 | + } |
|
421 | 518 | } |
422 | 519 | return join(',', $_); |
423 | 520 | } |
424 | 521 | |
425 | - function _getFromStringFromArray($tables=array()) { |
|
522 | + function _getFromStringFromArray($tables=array()) |
|
523 | + { |
|
426 | 524 | $_ = array(); |
427 | 525 | foreach($tables as $k=>$v) { |
428 | 526 | $_[] = $v; |
@@ -5,14 +5,14 @@ discard block |
||
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 | 14 | $this->config['connection_method'] = $this->_dbconnectionmethod = (isset($GLOBALS['database_connection_method']) ? $GLOBALS['database_connection_method'] : $connection_method); |
15 | - $this->config['table_prefix'] = ($pre !== NULL) ? $pre : $GLOBALS['table_prefix']; |
|
15 | + $this->config['table_prefix'] = ($pre !== null) ? $pre : $GLOBALS['table_prefix']; |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | function connect($host = '', $dbase = '', $uid = '', $pwd = '', $tmp = 0) { |
@@ -143,9 +143,9 @@ 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}"; |
|
146 | + if($where!=='' && stripos($where, 'WHERE')!==0) $where = "where {$where}"; |
|
147 | 147 | if($orderby!== '' && stripos($orderby,'ORDER BY')!==0) $orderby = "ORDER BY {$orderby}"; |
148 | - if($limit!== '' && stripos($limit, 'LIMIT')!==0) $limit = "LIMIT {$limit}"; |
|
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 | } |
@@ -167,10 +167,10 @@ 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}"; |
|
170 | + if($where!=='' && stripos($where,'WHERE')!==0) $where = "where {$where}"; |
|
171 | 171 | if($orderby!=='' && stripos($orderby,'ORDER')!==0) $orderby = "ORDER BY {$orderby}"; |
172 | - if($limit!=='' && stripos($limit,'LIMIT')!==0) $limit = "LIMIT {$limit}"; |
|
173 | - return $this->query("SELECT {$fields} FROM {$from} {$where} {$orderby} {$limit}"); |
|
172 | + if($limit!=='' && stripos($limit,'LIMIT')!==0) $limit = "limit {$limit}"; |
|
173 | + return $this->query("select {$fields} FROM {$from} {$where} {$orderby} {$limit}"); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | function update($fields, $table, $where = "") { |
@@ -191,8 +191,8 @@ discard block |
||
191 | 191 | $fields = implode(",", $fields); |
192 | 192 | } |
193 | 193 | $where = trim($where); |
194 | - if($where!=='' && stripos($where, 'WHERE')!==0) $where = "WHERE {$where}"; |
|
195 | - return $this->query("UPDATE {$table} SET {$fields} {$where}"); |
|
194 | + if($where!=='' && stripos($where, 'WHERE')!==0) $where = "where {$where}"; |
|
195 | + return $this->query("update {$table} SET {$fields} {$where}"); |
|
196 | 196 | } |
197 | 197 | } |
198 | 198 | |
@@ -213,8 +213,8 @@ 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 | } |
@@ -255,17 +255,17 @@ discard block |
||
255 | 255 | } |
256 | 256 | |
257 | 257 | |
258 | - function getInsertId($conn=NULL) { |
|
258 | + function getInsertId($conn=null) { |
|
259 | 259 | if (!is_object($conn)) $conn =& $this->conn; |
260 | 260 | return $conn->insert_id; |
261 | 261 | } |
262 | 262 | |
263 | - function getAffectedRows($conn=NULL) { |
|
263 | + function getAffectedRows($conn=null) { |
|
264 | 264 | if (!is_object($conn)) $conn =& $this->conn; |
265 | 265 | return $conn->affected_rows; |
266 | 266 | } |
267 | 267 | |
268 | - function getLastError($conn=NULL) { |
|
268 | + function getLastError($conn=null) { |
|
269 | 269 | if (!is_object($conn)) $conn =& $this->conn; |
270 | 270 | return $conn->error; |
271 | 271 | } |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | } |
403 | 403 | |
404 | 404 | function truncate($table_name) { |
405 | - $rs = $this->query("TRUNCATE {$table_name}"); |
|
405 | + $rs = $this->query("truncate {$table_name}"); |
|
406 | 406 | return $rs; |
407 | 407 | } |
408 | 408 |
@@ -291,6 +291,9 @@ discard block |
||
291 | 291 | } |
292 | 292 | } |
293 | 293 | |
294 | + /** |
|
295 | + * @param string $name |
|
296 | + */ |
|
294 | 297 | function getColumn($name, $dsq) { |
295 | 298 | if (!is_object($dsq)) { |
296 | 299 | $dsq = $this->query($dsq); |
@@ -375,6 +378,9 @@ discard block |
||
375 | 378 | return $rsArray; |
376 | 379 | } |
377 | 380 | |
381 | + /** |
|
382 | + * @return string |
|
383 | + */ |
|
378 | 384 | function getVersion() { |
379 | 385 | return $this->conn->server_info; |
380 | 386 | } |
@@ -393,6 +399,9 @@ discard block |
||
393 | 399 | return $result; |
394 | 400 | } |
395 | 401 | |
402 | + /** |
|
403 | + * @param string $table_name |
|
404 | + */ |
|
396 | 405 | function optimize($table_name) { |
397 | 406 | $rs = $this->query("OPTIMIZE TABLE {$table_name}"); |
398 | 407 | if ($rs) { |
@@ -410,6 +419,9 @@ discard block |
||
410 | 419 | return $result->data_seek($row_number); |
411 | 420 | } |
412 | 421 | |
422 | + /** |
|
423 | + * @return string |
|
424 | + */ |
|
413 | 425 | function _getFieldsStringFromArray($fields=array()) { |
414 | 426 | |
415 | 427 | if(empty($fields)) return '*'; |
@@ -422,6 +434,9 @@ discard block |
||
422 | 434 | return join(',', $_); |
423 | 435 | } |
424 | 436 | |
437 | + /** |
|
438 | + * @return string |
|
439 | + */ |
|
425 | 440 | function _getFromStringFromArray($tables=array()) { |
426 | 441 | $_ = array(); |
427 | 442 | foreach($tables as $k=>$v) { |