@@ -1,8 +1,11 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | $userid = intval($value); |
| 3 | 3 | if (!isset($modx->filter->cache['ui'][$userid])) { |
| 4 | - if ($userid < 0) $user = $modx->getWebUserInfo(abs($userid)); |
|
| 5 | - else $user = $modx->getUserInfo($userid); |
|
| 4 | + if ($userid < 0) { |
|
| 5 | + $user = $modx->getWebUserInfo(abs($userid)); |
|
| 6 | + } else { |
|
| 7 | + $user = $modx->getUserInfo($userid); |
|
| 8 | + } |
|
| 6 | 9 | $modx->filter->cache['ui'][$userid] = $user; |
| 7 | 10 | } else { |
| 8 | 11 | $user = $modx->filter->cache['ui'][$userid]; |
@@ -1,16 +1,17 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | $pattern = '/<img[\s\n]+.*src=[\s\n]*"([^"]+\.(jpg|jpeg|png|gif))"[^>]+>/i'; |
| 3 | 3 | preg_match_all($pattern , $value , $images); |
| 4 | -if($opt==='') |
|
| 5 | -{ |
|
| 6 | - if($images[1][0]) return $images[1][0]; |
|
| 7 | - else return ''; |
|
| 8 | -} |
|
| 9 | -else |
|
| 10 | -{ |
|
| 11 | - foreach($images[0] as $i=>$image) |
|
| 12 | - { |
|
| 13 | - if(strpos($image,$opt)!==false) return $images[1][$i]; |
|
| 4 | +if($opt==='') { |
|
| 5 | + if($images[1][0]) { |
|
| 6 | + return $images[1][0]; |
|
| 7 | + } else { |
|
| 8 | + return ''; |
|
| 9 | + } |
|
| 10 | + } else { |
|
| 11 | + foreach($images[0] as $i=>$image) { |
|
| 12 | + if(strpos($image,$opt)!==false) { |
|
| 13 | + return $images[1][$i]; |
|
| 14 | + } |
|
| 14 | 15 | } |
| 15 | 16 | } |
| 16 | 17 | |
@@ -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,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; |
@@ -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; |
@@ -5,13 +5,13 @@ |
||
| 5 | 5 | * Time: 12:25 |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -if (isset($this->phpcompat) && is_object($this->phpcompat)){ |
|
| 8 | +if (isset($this->phpcompat) && is_object($this->phpcompat)) { |
|
| 9 | 9 | return true; |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | -if (!include_once(MODX_MANAGER_PATH . 'includes/extenders/phpcompat.class.inc.php')){ |
|
| 12 | +if (!include_once(MODX_MANAGER_PATH . 'includes/extenders/phpcompat.class.inc.php')) { |
|
| 13 | 13 | return false; |
| 14 | -}else{ |
|
| 14 | +} else { |
|
| 15 | 15 | $this->phpcompat = new PHPCOMPAT; |
| 16 | 16 | return true; |
| 17 | 17 | } |
@@ -5,13 +5,13 @@ |
||
| 5 | 5 | * Time: 19:14 |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -if (isset($this->phpass) && is_object($this->phpass)){ |
|
| 8 | +if (isset($this->phpass) && is_object($this->phpass)) { |
|
| 9 | 9 | return true; |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | -if (!include_once(MODX_MANAGER_PATH . 'includes/extenders/phpass.class.inc.php')){ |
|
| 12 | +if (!include_once(MODX_MANAGER_PATH . 'includes/extenders/phpass.class.inc.php')) { |
|
| 13 | 13 | return false; |
| 14 | -}else{ |
|
| 14 | +} else { |
|
| 15 | 15 | $this->phpass = new PasswordHash; |
| 16 | 16 | return true; |
| 17 | 17 | } |
| 18 | 18 | \ No newline at end of file |
@@ -1,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,8 +5,7 @@ |
||
| 5 | 5 | * Time: 14:24 |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -if(include_once(MODX_MANAGER_PATH . 'includes/extenders/export.class.inc.php')) |
|
| 9 | -{ |
|
| 8 | +if(include_once(MODX_MANAGER_PATH . 'includes/extenders/export.class.inc.php')) { |
|
| 10 | 9 | $this->export = new EXPORT_SITE; |
| 11 | 10 | return true; |
| 12 | 11 | } else { |