@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | * |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -class DBAPI { |
|
| 8 | +class DBAPI{ |
|
| 9 | 9 | |
| 10 | 10 | var $conn; |
| 11 | 11 | var $config; |
@@ -16,13 +16,13 @@ discard block |
||
| 16 | 16 | * @name: DBAPI |
| 17 | 17 | * |
| 18 | 18 | */ |
| 19 | - function __construct($host='',$dbase='', $uid='',$pwd='',$pre=NULL,$charset='',$connection_method='SET CHARACTER SET') { |
|
| 19 | + function __construct($host = '', $dbase = '', $uid = '', $pwd = '', $pre = NULL, $charset = '', $connection_method = 'SET CHARACTER SET'){ |
|
| 20 | 20 | $this->config['host'] = $host ? $host : $GLOBALS['database_server']; |
| 21 | 21 | $this->config['dbase'] = $dbase ? $dbase : $GLOBALS['dbase']; |
| 22 | 22 | $this->config['user'] = $uid ? $uid : $GLOBALS['database_user']; |
| 23 | 23 | $this->config['pass'] = $pwd ? $pwd : $GLOBALS['database_password']; |
| 24 | 24 | $this->config['charset'] = $charset ? $charset : $GLOBALS['database_connection_charset']; |
| 25 | - $this->config['connection_method'] = $this->_dbconnectionmethod = (isset($GLOBALS['database_connection_method']) ? $GLOBALS['database_connection_method'] : $connection_method); |
|
| 25 | + $this->config['connection_method'] = $this->_dbconnectionmethod = (isset($GLOBALS['database_connection_method']) ? $GLOBALS['database_connection_method'] : $connection_method); |
|
| 26 | 26 | $this->config['table_prefix'] = ($pre !== NULL) ? $pre : $GLOBALS['table_prefix']; |
| 27 | 27 | $this->initDataTypes(); |
| 28 | 28 | } |
@@ -32,8 +32,8 @@ discard block |
||
| 32 | 32 | * @desc: called in the constructor to set up arrays containing the types |
| 33 | 33 | * of database fields that can be used with specific PHP types |
| 34 | 34 | */ |
| 35 | - function initDataTypes() { |
|
| 36 | - $this->dataTypes['numeric'] = array ( |
|
| 35 | + function initDataTypes(){ |
|
| 36 | + $this->dataTypes['numeric'] = array( |
|
| 37 | 37 | 'INT', |
| 38 | 38 | 'INTEGER', |
| 39 | 39 | 'TINYINT', |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | 'BIGINT', |
| 50 | 50 | 'BIT' |
| 51 | 51 | ); |
| 52 | - $this->dataTypes['string'] = array ( |
|
| 52 | + $this->dataTypes['string'] = array( |
|
| 53 | 53 | 'CHAR', |
| 54 | 54 | 'VARCHAR', |
| 55 | 55 | 'BINARY', |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | 'ENUM', |
| 66 | 66 | 'SET' |
| 67 | 67 | ); |
| 68 | - $this->dataTypes['date'] = array ( |
|
| 68 | + $this->dataTypes['date'] = array( |
|
| 69 | 69 | 'DATE', |
| 70 | 70 | 'DATETIME', |
| 71 | 71 | 'TIMESTAMP', |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | * @name: connect |
| 79 | 79 | * |
| 80 | 80 | */ |
| 81 | - function connect($host = '', $dbase = '', $uid = '', $pwd = '', $persist = 0) { |
|
| 81 | + function connect($host = '', $dbase = '', $uid = '', $pwd = '', $persist = 0){ |
|
| 82 | 82 | global $modx; |
| 83 | 83 | $uid = $uid ? $uid : $this->config['user']; |
| 84 | 84 | $pwd = $pwd ? $pwd : $this->config['pass']; |
@@ -88,16 +88,16 @@ discard block |
||
| 88 | 88 | $connection_method = $this->config['connection_method']; |
| 89 | 89 | $tstart = $modx->getMicroTime(); |
| 90 | 90 | $safe_count = 0; |
| 91 | - while(!$this->conn && $safe_count<3) |
|
| 91 | + while (!$this->conn && $safe_count < 3) |
|
| 92 | 92 | { |
| 93 | - if($persist!=0) $this->conn = mysql_pconnect($host, $uid, $pwd); |
|
| 93 | + if ($persist != 0) $this->conn = mysql_pconnect($host, $uid, $pwd); |
|
| 94 | 94 | else $this->conn = mysql_connect($host, $uid, $pwd, true); |
| 95 | 95 | |
| 96 | - if(!$this->conn) |
|
| 96 | + if (!$this->conn) |
|
| 97 | 97 | { |
| 98 | - if(isset($modx->config['send_errormail']) && $modx->config['send_errormail'] !== '0') |
|
| 98 | + if (isset($modx->config['send_errormail']) && $modx->config['send_errormail'] !== '0') |
|
| 99 | 99 | { |
| 100 | - if($modx->config['send_errormail'] <= 2) |
|
| 100 | + if ($modx->config['send_errormail'] <= 2) |
|
| 101 | 101 | { |
| 102 | 102 | $logtitle = 'Failed to create the database connection!'; |
| 103 | 103 | $request_uri = $modx->htmlspecialchars($_SERVER['REQUEST_URI']); |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | $referer = $modx->htmlspecialchars($_SERVER['HTTP_REFERER']); |
| 106 | 106 | |
| 107 | 107 | $modx->sendmail(array( |
| 108 | - 'subject' => 'Missing to create the database connection! from ' . $modx->config['site_name'], |
|
| 108 | + 'subject' => 'Missing to create the database connection! from '.$modx->config['site_name'], |
|
| 109 | 109 | 'body' => "{$logtitle}\n{$request_uri}\n{$ua}\n{$referer}", |
| 110 | 110 | 'type' => 'text') |
| 111 | 111 | ); |
@@ -119,16 +119,16 @@ discard block |
||
| 119 | 119 | $modx->messageQuit("Failed to create the database connection!"); |
| 120 | 120 | exit; |
| 121 | 121 | } else { |
| 122 | - $dbase = trim($dbase,'`'); // remove the `` chars |
|
| 122 | + $dbase = trim($dbase, '`'); // remove the `` chars |
|
| 123 | 123 | if (!@ mysql_select_db($dbase, $this->conn)) { |
| 124 | - $modx->messageQuit("Failed to select the database '" . $dbase . "'!"); |
|
| 124 | + $modx->messageQuit("Failed to select the database '".$dbase."'!"); |
|
| 125 | 125 | exit; |
| 126 | 126 | } |
| 127 | 127 | @mysql_query("{$connection_method} {$charset}", $this->conn); |
| 128 | 128 | $tend = $modx->getMicroTime(); |
| 129 | 129 | $totaltime = $tend - $tstart; |
| 130 | 130 | if ($modx->dumpSQL) { |
| 131 | - $modx->queryCode .= "<fieldset style='text-align:left'><legend>Database connection</legend>" . sprintf("Database connection was created in %2.4f s", $totaltime) . "</fieldset><br />"; |
|
| 131 | + $modx->queryCode .= "<fieldset style='text-align:left'><legend>Database connection</legend>".sprintf("Database connection was created in %2.4f s", $totaltime)."</fieldset><br />"; |
|
| 132 | 132 | } |
| 133 | 133 | if (function_exists('mysql_set_charset')) { |
| 134 | 134 | mysql_set_charset($this->config['charset']); |
@@ -146,26 +146,26 @@ discard block |
||
| 146 | 146 | * @name: disconnect |
| 147 | 147 | * |
| 148 | 148 | */ |
| 149 | - function disconnect() { |
|
| 149 | + function disconnect(){ |
|
| 150 | 150 | @ mysql_close($this->conn); |
| 151 | 151 | $this->conn = null; |
| 152 | 152 | $this->isConnected = false; |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - function escape($s, $safecount=0) { |
|
| 155 | + function escape($s, $safecount = 0){ |
|
| 156 | 156 | |
| 157 | 157 | $safecount++; |
| 158 | - if(1000<$safecount) exit("Too many loops '{$safecount}'"); |
|
| 158 | + if (1000 < $safecount) exit("Too many loops '{$safecount}'"); |
|
| 159 | 159 | |
| 160 | 160 | if (empty ($this->conn) || !is_resource($this->conn)) { |
| 161 | 161 | $this->connect(); |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - if(is_array($s)) { |
|
| 165 | - if(count($s) === 0) $s = ''; |
|
| 164 | + if (is_array($s)) { |
|
| 165 | + if (count($s) === 0) $s = ''; |
|
| 166 | 166 | else { |
| 167 | - foreach($s as $i=>$v) { |
|
| 168 | - $s[$i] = $this->escape($v,$safecount); |
|
| 167 | + foreach ($s as $i=>$v) { |
|
| 168 | + $s[$i] = $this->escape($v, $safecount); |
|
| 169 | 169 | } |
| 170 | 170 | } |
| 171 | 171 | } |
@@ -178,17 +178,17 @@ discard block |
||
| 178 | 178 | * @desc: Mainly for internal use. |
| 179 | 179 | * Developers should use select, update, insert, delete where possible |
| 180 | 180 | */ |
| 181 | - function query($sql,$watchError=true) { |
|
| 181 | + function query($sql, $watchError = true){ |
|
| 182 | 182 | global $modx; |
| 183 | 183 | if (empty ($this->conn) || !is_resource($this->conn)) { |
| 184 | 184 | $this->connect(); |
| 185 | 185 | } |
| 186 | 186 | $tstart = $modx->getMicroTime(); |
| 187 | - if(is_array($sql)) $sql = join("\n", $sql); |
|
| 187 | + if (is_array($sql)) $sql = join("\n", $sql); |
|
| 188 | 188 | $this->lastQuery = $sql; |
| 189 | 189 | if (!$result = @ mysql_query($sql, $this->conn)) { |
| 190 | - if(!$watchError) return; |
|
| 191 | - switch(mysql_errno()) { |
|
| 190 | + if (!$watchError) return; |
|
| 191 | + switch (mysql_errno()) { |
|
| 192 | 192 | case 1054: |
| 193 | 193 | case 1060: |
| 194 | 194 | case 1061: |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | case 1091: |
| 197 | 197 | break; |
| 198 | 198 | default: |
| 199 | - $modx->messageQuit('Execution of a query to the database failed - ' . $this->getLastError(), $sql); |
|
| 199 | + $modx->messageQuit('Execution of a query to the database failed - '.$this->getLastError(), $sql); |
|
| 200 | 200 | } |
| 201 | 201 | } else { |
| 202 | 202 | $tend = $modx->getMicroTime(); |
@@ -207,15 +207,15 @@ discard block |
||
| 207 | 207 | array_shift($debug); |
| 208 | 208 | $debug_path = array(); |
| 209 | 209 | foreach ($debug as $line) $debug_path[] = $line['function']; |
| 210 | - $debug_path = implode(' > ',array_reverse($debug_path)); |
|
| 211 | - $modx->queryCode .= "<fieldset style='text-align:left'><legend>Query " . ($modx->executedQueries + 1) . " - " . sprintf("%2.2f ms", $totaltime*1000) . "</legend>"; |
|
| 212 | - $modx->queryCode .= $sql . '<br><br>'; |
|
| 213 | - if ($modx->event->name) $modx->queryCode .= 'Current Event => ' . $modx->event->name . '<br>'; |
|
| 214 | - if ($modx->event->activePlugin) $modx->queryCode .= 'Current Plugin => ' . $modx->event->activePlugin . '<br>'; |
|
| 215 | - if ($modx->currentSnippet) $modx->queryCode .= 'Current Snippet => ' . $modx->currentSnippet . '<br>'; |
|
| 216 | - if (stripos($sql, 'select')===0) $modx->queryCode .= 'Record Count => ' . $this->getRecordCount($result) . '<br>'; |
|
| 217 | - else $modx->queryCode .= 'Affected Rows => ' . $this->getAffectedRows() . '<br>'; |
|
| 218 | - $modx->queryCode .= 'Functions Path => ' . $debug_path . '<br>'; |
|
| 210 | + $debug_path = implode(' > ', array_reverse($debug_path)); |
|
| 211 | + $modx->queryCode .= "<fieldset style='text-align:left'><legend>Query ".($modx->executedQueries + 1)." - ".sprintf("%2.2f ms", $totaltime * 1000)."</legend>"; |
|
| 212 | + $modx->queryCode .= $sql.'<br><br>'; |
|
| 213 | + if ($modx->event->name) $modx->queryCode .= 'Current Event => '.$modx->event->name.'<br>'; |
|
| 214 | + if ($modx->event->activePlugin) $modx->queryCode .= 'Current Plugin => '.$modx->event->activePlugin.'<br>'; |
|
| 215 | + if ($modx->currentSnippet) $modx->queryCode .= 'Current Snippet => '.$modx->currentSnippet.'<br>'; |
|
| 216 | + if (stripos($sql, 'select') === 0) $modx->queryCode .= 'Record Count => '.$this->getRecordCount($result).'<br>'; |
|
| 217 | + else $modx->queryCode .= 'Affected Rows => '.$this->getAffectedRows().'<br>'; |
|
| 218 | + $modx->queryCode .= 'Functions Path => '.$debug_path.'<br>'; |
|
| 219 | 219 | $modx->queryCode .= "</fieldset><br />"; |
| 220 | 220 | } |
| 221 | 221 | $modx->executedQueries = $modx->executedQueries + 1; |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | * @name: delete |
| 228 | 228 | * |
| 229 | 229 | */ |
| 230 | - function delete($from, $where='', $orderby='', $limit = '') { |
|
| 230 | + function delete($from, $where = '', $orderby = '', $limit = ''){ |
|
| 231 | 231 | global $modx; |
| 232 | 232 | if (!$from) |
| 233 | 233 | $modx->messageQuit("Empty \$from parameters in DBAPI::delete()."); |
@@ -236,9 +236,9 @@ discard block |
||
| 236 | 236 | $where = trim($where); |
| 237 | 237 | $orderby = trim($orderby); |
| 238 | 238 | $limit = trim($limit); |
| 239 | - if($where!=='' && stripos($where, 'WHERE')!==0) $where = "WHERE {$where}"; |
|
| 240 | - if($orderby!=='' && stripos($orderby, 'ORDER BY')!==0) $orderby = "ORDER BY {$orderby}"; |
|
| 241 | - if($limit!=='' && stripos($limit, 'LIMIT')!==0) $limit = "LIMIT {$limit}"; |
|
| 239 | + if ($where !== '' && stripos($where, 'WHERE') !== 0) $where = "WHERE {$where}"; |
|
| 240 | + if ($orderby !== '' && stripos($orderby, 'ORDER BY') !== 0) $orderby = "ORDER BY {$orderby}"; |
|
| 241 | + if ($limit !== '' && stripos($limit, 'LIMIT') !== 0) $limit = "LIMIT {$limit}"; |
|
| 242 | 242 | return $this->query("DELETE FROM {$from} {$where} {$orderby} {$limit}"); |
| 243 | 243 | } |
| 244 | 244 | } |
@@ -247,12 +247,12 @@ discard block |
||
| 247 | 247 | * @name: select |
| 248 | 248 | * |
| 249 | 249 | */ |
| 250 | - function select($fields = "*", $from = "", $where = "", $orderby = "", $limit = "") { |
|
| 250 | + function select($fields = "*", $from = "", $where = "", $orderby = "", $limit = ""){ |
|
| 251 | 251 | global $modx; |
| 252 | 252 | |
| 253 | - if(is_array($fields)) $fields = $this->_getFieldsStringFromArray($fields); |
|
| 254 | - if(is_array($from)) $from = $this->_getFromStringFromArray($from); |
|
| 255 | - if(is_array($where)) $where = join(' ', $where); |
|
| 253 | + if (is_array($fields)) $fields = $this->_getFieldsStringFromArray($fields); |
|
| 254 | + if (is_array($from)) $from = $this->_getFromStringFromArray($from); |
|
| 255 | + if (is_array($where)) $where = join(' ', $where); |
|
| 256 | 256 | |
| 257 | 257 | if (!$from) { |
| 258 | 258 | $modx->messageQuit("Empty \$from parameters in DBAPI::select()."); |
@@ -264,9 +264,9 @@ discard block |
||
| 264 | 264 | $where = trim($where); |
| 265 | 265 | $orderby = trim($orderby); |
| 266 | 266 | $limit = trim($limit); |
| 267 | - if($where!=='' && stripos($where,'WHERE')!==0) $where = "WHERE {$where}"; |
|
| 268 | - if($orderby!=='' && stripos($orderby,'ORDER')!==0) $orderby = "ORDER BY {$orderby}"; |
|
| 269 | - if($limit!=='' && stripos($limit,'LIMIT')!==0) $limit = "LIMIT {$limit}"; |
|
| 267 | + if ($where !== '' && stripos($where, 'WHERE') !== 0) $where = "WHERE {$where}"; |
|
| 268 | + if ($orderby !== '' && stripos($orderby, 'ORDER') !== 0) $orderby = "ORDER BY {$orderby}"; |
|
| 269 | + if ($limit !== '' && stripos($limit, 'LIMIT') !== 0) $limit = "LIMIT {$limit}"; |
|
| 270 | 270 | return $this->query("SELECT {$fields} FROM {$from} {$where} {$orderby} {$limit}"); |
| 271 | 271 | } |
| 272 | 272 | |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | * @name: update |
| 275 | 275 | * |
| 276 | 276 | */ |
| 277 | - function update($fields, $table, $where = "") { |
|
| 277 | + function update($fields, $table, $where = ""){ |
|
| 278 | 278 | global $modx; |
| 279 | 279 | if (!$table) |
| 280 | 280 | $modx->messageQuit("Empty \$table parameter in DBAPI::update()."); |
@@ -282,17 +282,17 @@ discard block |
||
| 282 | 282 | $table = $this->replaceFullTableName($table); |
| 283 | 283 | if (is_array($fields)) { |
| 284 | 284 | foreach ($fields as $key => $value) { |
| 285 | - if(is_null($value) || strtolower($value) === 'null'){ |
|
| 285 | + if (is_null($value) || strtolower($value) === 'null') { |
|
| 286 | 286 | $flds = 'NULL'; |
| 287 | - }else{ |
|
| 288 | - $flds = "'" . $value . "'"; |
|
| 287 | + } else { |
|
| 288 | + $flds = "'".$value."'"; |
|
| 289 | 289 | } |
| 290 | 290 | $fields[$key] = "`{$key}` = ".$flds; |
| 291 | 291 | } |
| 292 | 292 | $fields = implode(",", $fields); |
| 293 | 293 | } |
| 294 | 294 | $where = trim($where); |
| 295 | - if($where!=='' && stripos($where, 'WHERE')!==0) $where = "WHERE {$where}"; |
|
| 295 | + if ($where !== '' && stripos($where, 'WHERE') !== 0) $where = "WHERE {$where}"; |
|
| 296 | 296 | return $this->query("UPDATE {$table} SET {$fields} {$where}"); |
| 297 | 297 | } |
| 298 | 298 | } |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | * @name: insert |
| 302 | 302 | * @desc: returns either last id inserted or the result from the query |
| 303 | 303 | */ |
| 304 | - function insert($fields, $intotable, $fromfields = "*", $fromtable = "", $where = "", $limit = "") { |
|
| 304 | + function insert($fields, $intotable, $fromfields = "*", $fromtable = "", $where = "", $limit = ""){ |
|
| 305 | 305 | global $modx; |
| 306 | 306 | if (!$intotable) |
| 307 | 307 | $modx->messageQuit("Empty \$intotable parameters in DBAPI::insert()."); |
@@ -314,13 +314,13 @@ discard block |
||
| 314 | 314 | $fields = "(`".implode("`, `", array_keys($fields))."`) VALUES('".implode("', '", array_values($fields))."')"; |
| 315 | 315 | $rt = $this->query("INSERT INTO {$intotable} {$fields}"); |
| 316 | 316 | } else { |
| 317 | - if (version_compare($this->getVersion(),"4.0.14")>=0) { |
|
| 317 | + if (version_compare($this->getVersion(), "4.0.14") >= 0) { |
|
| 318 | 318 | $fromtable = $this->replaceFullTableName($fromtable); |
| 319 | 319 | $fields = "(".implode(",", array_keys($fields)).")"; |
| 320 | 320 | $where = trim($where); |
| 321 | 321 | $limit = trim($limit); |
| 322 | - if($where!=='' && stripos($where, 'WHERE')!==0) $where = "WHERE {$where}"; |
|
| 323 | - if($limit!=='' && stripos($limit, 'LIMIT')!==0) $limit = "LIMIT {$limit}"; |
|
| 322 | + if ($where !== '' && stripos($where, 'WHERE') !== 0) $where = "WHERE {$where}"; |
|
| 323 | + if ($limit !== '' && stripos($limit, 'LIMIT') !== 0) $limit = "LIMIT {$limit}"; |
|
| 324 | 324 | $rt = $this->query("INSERT INTO {$intotable} {$fields} SELECT {$fromfields} FROM {$fromtable} {$where} {$limit}"); |
| 325 | 325 | } else { |
| 326 | 326 | $ds = $this->select($fromfields, $fromtable, $where, '', $limit); |
@@ -331,18 +331,18 @@ discard block |
||
| 331 | 331 | } |
| 332 | 332 | } |
| 333 | 333 | } |
| 334 | - if (($lid = $this->getInsertId())===false) $modx->messageQuit("Couldn't get last insert key!"); |
|
| 334 | + if (($lid = $this->getInsertId()) === false) $modx->messageQuit("Couldn't get last insert key!"); |
|
| 335 | 335 | return $lid; |
| 336 | 336 | } |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | - function save($fields, $table, $where='') { |
|
| 339 | + function save($fields, $table, $where = ''){ |
|
| 340 | 340 | |
| 341 | - if($where === '') $mode = 'insert'; |
|
| 342 | - elseif($this->getRecordCount($this->select('*',$table,$where))==0) $mode = 'insert'; |
|
| 341 | + if ($where === '') $mode = 'insert'; |
|
| 342 | + elseif ($this->getRecordCount($this->select('*', $table, $where)) == 0) $mode = 'insert'; |
|
| 343 | 343 | else $mode = 'update'; |
| 344 | 344 | |
| 345 | - if($mode==='insert') return $this->insert($fields, $table); |
|
| 345 | + if ($mode === 'insert') return $this->insert($fields, $table); |
|
| 346 | 346 | else return $this->update($fields, $table, $where); |
| 347 | 347 | } |
| 348 | 348 | |
@@ -350,7 +350,7 @@ discard block |
||
| 350 | 350 | * @name: isResult |
| 351 | 351 | * |
| 352 | 352 | */ |
| 353 | - function isResult($rs) { |
|
| 353 | + function isResult($rs){ |
|
| 354 | 354 | return is_resource($rs); |
| 355 | 355 | } |
| 356 | 356 | |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | * @name: freeResult |
| 359 | 359 | * |
| 360 | 360 | */ |
| 361 | - function freeResult($rs) { |
|
| 361 | + function freeResult($rs){ |
|
| 362 | 362 | mysql_free_result($rs); |
| 363 | 363 | } |
| 364 | 364 | |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | * @name: numFields |
| 367 | 367 | * |
| 368 | 368 | */ |
| 369 | - function numFields($rs) { |
|
| 369 | + function numFields($rs){ |
|
| 370 | 370 | return mysql_num_fields($rs); |
| 371 | 371 | } |
| 372 | 372 | |
@@ -374,15 +374,15 @@ discard block |
||
| 374 | 374 | * @name: fieldName |
| 375 | 375 | * |
| 376 | 376 | */ |
| 377 | - function fieldName($rs,$col=0) { |
|
| 378 | - return mysql_field_name($rs,$col); |
|
| 377 | + function fieldName($rs, $col = 0){ |
|
| 378 | + return mysql_field_name($rs, $col); |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | /** |
| 382 | 382 | * @name: selectDb |
| 383 | 383 | * |
| 384 | 384 | */ |
| 385 | - function selectDb($name) { |
|
| 385 | + function selectDb($name){ |
|
| 386 | 386 | mysql_select_db($name); |
| 387 | 387 | } |
| 388 | 388 | |
@@ -391,8 +391,8 @@ discard block |
||
| 391 | 391 | * @name: getInsertId |
| 392 | 392 | * |
| 393 | 393 | */ |
| 394 | - function getInsertId($conn=NULL) { |
|
| 395 | - if( !is_resource($conn)) $conn =& $this->conn; |
|
| 394 | + function getInsertId($conn = NULL){ |
|
| 395 | + if (!is_resource($conn)) $conn = & $this->conn; |
|
| 396 | 396 | return mysql_insert_id($conn); |
| 397 | 397 | } |
| 398 | 398 | |
@@ -400,8 +400,8 @@ discard block |
||
| 400 | 400 | * @name: getAffectedRows |
| 401 | 401 | * |
| 402 | 402 | */ |
| 403 | - function getAffectedRows($conn=NULL) { |
|
| 404 | - if (!is_resource($conn)) $conn =& $this->conn; |
|
| 403 | + function getAffectedRows($conn = NULL){ |
|
| 404 | + if (!is_resource($conn)) $conn = & $this->conn; |
|
| 405 | 405 | return mysql_affected_rows($conn); |
| 406 | 406 | } |
| 407 | 407 | |
@@ -409,8 +409,8 @@ discard block |
||
| 409 | 409 | * @name: getLastError |
| 410 | 410 | * |
| 411 | 411 | */ |
| 412 | - function getLastError($conn=NULL) { |
|
| 413 | - if (!is_resource($conn)) $conn =& $this->conn; |
|
| 412 | + function getLastError($conn = NULL){ |
|
| 413 | + if (!is_resource($conn)) $conn = & $this->conn; |
|
| 414 | 414 | return mysql_error($conn); |
| 415 | 415 | } |
| 416 | 416 | |
@@ -418,7 +418,7 @@ discard block |
||
| 418 | 418 | * @name: getRecordCount |
| 419 | 419 | * |
| 420 | 420 | */ |
| 421 | - function getRecordCount($ds) { |
|
| 421 | + function getRecordCount($ds){ |
|
| 422 | 422 | return (is_resource($ds)) ? mysql_num_rows($ds) : 0; |
| 423 | 423 | } |
| 424 | 424 | |
@@ -428,7 +428,7 @@ discard block |
||
| 428 | 428 | * @param: $dsq - dataset |
| 429 | 429 | * |
| 430 | 430 | */ |
| 431 | - function getRow($ds, $mode = 'assoc') { |
|
| 431 | + function getRow($ds, $mode = 'assoc'){ |
|
| 432 | 432 | if (is_resource($ds)) { |
| 433 | 433 | if ($mode == 'assoc') { |
| 434 | 434 | return mysql_fetch_assoc($ds); |
@@ -453,11 +453,11 @@ discard block |
||
| 453 | 453 | * @desc: returns an array of the values found on colun $name |
| 454 | 454 | * @param: $dsq - dataset or query string |
| 455 | 455 | */ |
| 456 | - function getColumn($name, $dsq) { |
|
| 456 | + function getColumn($name, $dsq){ |
|
| 457 | 457 | if (!is_resource($dsq)) |
| 458 | 458 | $dsq = $this->query($dsq); |
| 459 | 459 | if ($dsq) { |
| 460 | - $col = array (); |
|
| 460 | + $col = array(); |
|
| 461 | 461 | while ($row = $this->getRow($dsq)) { |
| 462 | 462 | $col[] = $row[$name]; |
| 463 | 463 | } |
@@ -470,11 +470,11 @@ discard block |
||
| 470 | 470 | * @desc: returns an array containing the column $name |
| 471 | 471 | * @param: $dsq - dataset or query string |
| 472 | 472 | */ |
| 473 | - function getColumnNames($dsq) { |
|
| 473 | + function getColumnNames($dsq){ |
|
| 474 | 474 | if (!is_resource($dsq)) |
| 475 | 475 | $dsq = $this->query($dsq); |
| 476 | 476 | if ($dsq) { |
| 477 | - $names = array (); |
|
| 477 | + $names = array(); |
|
| 478 | 478 | $limit = mysql_num_fields($dsq); |
| 479 | 479 | for ($i = 0; $i < $limit; $i++) { |
| 480 | 480 | $names[] = mysql_field_name($dsq, $i); |
@@ -488,7 +488,7 @@ discard block |
||
| 488 | 488 | * @desc: returns the value from the first column in the set |
| 489 | 489 | * @param: $dsq - dataset or query string |
| 490 | 490 | */ |
| 491 | - function getValue($dsq) { |
|
| 491 | + function getValue($dsq){ |
|
| 492 | 492 | if (!is_resource($dsq)) |
| 493 | 493 | $dsq = $this->query($dsq); |
| 494 | 494 | if ($dsq) { |
@@ -503,7 +503,7 @@ discard block |
||
| 503 | 503 | * table |
| 504 | 504 | * @param: $table: the full name of the database table |
| 505 | 505 | */ |
| 506 | - function getTableMetaData($table) { |
|
| 506 | + function getTableMetaData($table){ |
|
| 507 | 507 | $metadata = false; |
| 508 | 508 | if (!empty ($table)) { |
| 509 | 509 | $sql = "SHOW FIELDS FROM $table"; |
@@ -525,7 +525,7 @@ discard block |
||
| 525 | 525 | * @param: $fieldType: the type of field to format the date for |
| 526 | 526 | * (in MySQL, you have DATE, TIME, YEAR, and DATETIME) |
| 527 | 527 | */ |
| 528 | - function prepareDate($timestamp, $fieldType = 'DATETIME') { |
|
| 528 | + function prepareDate($timestamp, $fieldType = 'DATETIME'){ |
|
| 529 | 529 | $date = ''; |
| 530 | 530 | if (!$timestamp === false && $timestamp > 0) { |
| 531 | 531 | switch ($fieldType) { |
@@ -554,7 +554,7 @@ discard block |
||
| 554 | 554 | * was passed |
| 555 | 555 | * @param: $rs Recordset to be packaged into an array |
| 556 | 556 | */ |
| 557 | - function makeArray($rs='',$index=false){ |
|
| 557 | + function makeArray($rs = '', $index = false){ |
|
| 558 | 558 | if (!$rs) return false; |
| 559 | 559 | $rsArray = array(); |
| 560 | 560 | $iterator = 0; |
@@ -572,7 +572,7 @@ discard block |
||
| 572 | 572 | * |
| 573 | 573 | * @return string |
| 574 | 574 | */ |
| 575 | - function getVersion() { |
|
| 575 | + function getVersion(){ |
|
| 576 | 576 | return mysql_get_server_info(); |
| 577 | 577 | } |
| 578 | 578 | |
@@ -583,16 +583,16 @@ discard block |
||
| 583 | 583 | * @param string $str |
| 584 | 584 | * @return string |
| 585 | 585 | */ |
| 586 | - function replaceFullTableName($str,$force=null) { |
|
| 586 | + function replaceFullTableName($str, $force = null){ |
|
| 587 | 587 | |
| 588 | 588 | $str = trim($str); |
| 589 | - $dbase = trim($this->config['dbase'],'`'); |
|
| 589 | + $dbase = trim($this->config['dbase'], '`'); |
|
| 590 | 590 | $prefix = $this->config['table_prefix']; |
| 591 | - if(!empty($force)) |
|
| 591 | + if (!empty($force)) |
|
| 592 | 592 | { |
| 593 | 593 | $result = "`{$dbase}`.`{$prefix}{$str}`"; |
| 594 | 594 | } |
| 595 | - elseif(strpos($str,'[+prefix+]')!==false) |
|
| 595 | + elseif (strpos($str, '[+prefix+]') !== false) |
|
| 596 | 596 | { |
| 597 | 597 | $result = preg_replace('@\[\+prefix\+\]([0-9a-zA-Z_]+)@', "`{$dbase}`.`{$prefix}$1`", $str); |
| 598 | 598 | } |
@@ -604,7 +604,7 @@ discard block |
||
| 604 | 604 | function optimize($table_name) |
| 605 | 605 | { |
| 606 | 606 | $rs = $this->query("OPTIMIZE TABLE {$table_name}"); |
| 607 | - if($rs) $rs = $this->query("ALTER TABLE {$table_name}"); |
|
| 607 | + if ($rs) $rs = $this->query("ALTER TABLE {$table_name}"); |
|
| 608 | 608 | return $rs; |
| 609 | 609 | } |
| 610 | 610 | |
@@ -614,25 +614,25 @@ discard block |
||
| 614 | 614 | return $rs; |
| 615 | 615 | } |
| 616 | 616 | |
| 617 | - function dataSeek($result, $row_number) { |
|
| 617 | + function dataSeek($result, $row_number){ |
|
| 618 | 618 | return mysql_data_seek($result, $row_number); |
| 619 | 619 | } |
| 620 | 620 | |
| 621 | - function _getFieldsStringFromArray($fields=array()) { |
|
| 621 | + function _getFieldsStringFromArray($fields = array()){ |
|
| 622 | 622 | |
| 623 | - if(empty($fields)) return '*'; |
|
| 623 | + if (empty($fields)) return '*'; |
|
| 624 | 624 | |
| 625 | 625 | $_ = array(); |
| 626 | - foreach($fields as $k=>$v) { |
|
| 627 | - if($k!==$v) $_[] = "{$v} as {$k}"; |
|
| 626 | + foreach ($fields as $k=>$v) { |
|
| 627 | + if ($k !== $v) $_[] = "{$v} as {$k}"; |
|
| 628 | 628 | else $_[] = $v; |
| 629 | 629 | } |
| 630 | 630 | return join(',', $_); |
| 631 | 631 | } |
| 632 | 632 | |
| 633 | - function _getFromStringFromArray($tables=array()) { |
|
| 633 | + function _getFromStringFromArray($tables = array()){ |
|
| 634 | 634 | $_ = array(); |
| 635 | - foreach($tables as $k=>$v) { |
|
| 635 | + foreach ($tables as $k=>$v) { |
|
| 636 | 636 | $_[] = $v; |
| 637 | 637 | } |
| 638 | 638 | return join(' ', $_); |
@@ -15,19 +15,19 @@ discard block |
||
| 15 | 15 | { |
| 16 | 16 | global $modx; |
| 17 | 17 | |
| 18 | - if(!defined('MODX_BASE_PATH')) return false; |
|
| 18 | + if (!defined('MODX_BASE_PATH')) return false; |
|
| 19 | 19 | $this->exportstart = $this->get_mtime(); |
| 20 | 20 | $this->count = 0; |
| 21 | 21 | $this->setUrlMode(); |
| 22 | 22 | $this->dirCheckCount = 0; |
| 23 | 23 | $this->generate_mode = 'crawl'; |
| 24 | - $this->targetDir = $modx->config['base_path'] . 'temp/export'; |
|
| 25 | - if(!isset($this->total)) $this->getTotal(); |
|
| 24 | + $this->targetDir = $modx->config['base_path'].'temp/export'; |
|
| 25 | + if (!isset($this->total)) $this->getTotal(); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | function setExportDir($dir) |
| 29 | 29 | { |
| 30 | - $dir = str_replace('\\','/',$dir); |
|
| 30 | + $dir = str_replace('\\', '/', $dir); |
|
| 31 | 31 | $dir = rtrim($dir, '/'); |
| 32 | 32 | $this->targetDir = $dir; |
| 33 | 33 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | { |
| 45 | 45 | global $modx; |
| 46 | 46 | |
| 47 | - if($modx->config['friendly_urls']==0) |
|
| 47 | + if ($modx->config['friendly_urls'] == 0) |
|
| 48 | 48 | { |
| 49 | 49 | $modx->config['friendly_urls'] = 1; |
| 50 | 50 | $modx->config['use_alias_path'] = 1; |
@@ -53,13 +53,13 @@ discard block |
||
| 53 | 53 | $modx->config['make_folders'] = '1'; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - function getTotal($ignore_ids='', $noncache='0') |
|
| 56 | + function getTotal($ignore_ids = '', $noncache = '0') |
|
| 57 | 57 | { |
| 58 | 58 | global $modx; |
| 59 | 59 | $tbl_site_content = $modx->getFullTableName('site_content'); |
| 60 | 60 | |
| 61 | 61 | $ignore_ids = array_filter(array_map('intval', explode(',', $ignore_ids))); |
| 62 | - if(count($ignore_ids)>0) |
|
| 62 | + if (count($ignore_ids) > 0) |
|
| 63 | 63 | { |
| 64 | 64 | $ignore_ids = "AND NOT id IN ('".implode("','", $ignore_ids)."')"; |
| 65 | 65 | } else { |
@@ -70,72 +70,72 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | $noncache = ($noncache == 1) ? '' : 'AND cacheable=1'; |
| 72 | 72 | $where = "deleted=0 AND ((published=1 AND type='document') OR (isfolder=1)) {$noncache} {$ignore_ids}"; |
| 73 | - $rs = $modx->db->select('count(id)',$tbl_site_content,$where); |
|
| 73 | + $rs = $modx->db->select('count(id)', $tbl_site_content, $where); |
|
| 74 | 74 | $this->total = $modx->db->getValue($rs); |
| 75 | 75 | return $this->total; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - function removeDirectoryAll($directory='') |
|
| 78 | + function removeDirectoryAll($directory = '') |
|
| 79 | 79 | { |
| 80 | - if(empty($directory)) $directory = $this->targetDir; |
|
| 81 | - $directory = rtrim($directory,'/'); |
|
| 80 | + if (empty($directory)) $directory = $this->targetDir; |
|
| 81 | + $directory = rtrim($directory, '/'); |
|
| 82 | 82 | // if the path is not valid or is not a directory ... |
| 83 | - if(empty($directory)) return false; |
|
| 84 | - if(strpos($directory,MODX_BASE_PATH)===false) return FALSE; |
|
| 83 | + if (empty($directory)) return false; |
|
| 84 | + if (strpos($directory, MODX_BASE_PATH) === false) return FALSE; |
|
| 85 | 85 | |
| 86 | - if(!is_dir($directory)) return FALSE; |
|
| 87 | - elseif(!is_readable($directory)) return FALSE; |
|
| 86 | + if (!is_dir($directory)) return FALSE; |
|
| 87 | + elseif (!is_readable($directory)) return FALSE; |
|
| 88 | 88 | else |
| 89 | 89 | { |
| 90 | - $files = glob($directory . '/*'); |
|
| 91 | - if(!empty($files)) |
|
| 90 | + $files = glob($directory.'/*'); |
|
| 91 | + if (!empty($files)) |
|
| 92 | 92 | { |
| 93 | - foreach($files as $path) |
|
| 93 | + foreach ($files as $path) |
|
| 94 | 94 | { |
| 95 | - if(is_dir($path)) $this->removeDirectoryAll($path); |
|
| 95 | + if (is_dir($path)) $this->removeDirectoryAll($path); |
|
| 96 | 96 | else $rs = unlink($path); |
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | - if($directory !== $this->targetDir) $rs = rmdir($directory); |
|
| 100 | + if ($directory !== $this->targetDir) $rs = rmdir($directory); |
|
| 101 | 101 | |
| 102 | 102 | return $rs; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | function makeFile($docid, $filepath) |
| 106 | 106 | { |
| 107 | - global $modx,$_lang; |
|
| 107 | + global $modx, $_lang; |
|
| 108 | 108 | $file_permission = octdec($modx->config['new_file_permissions']); |
| 109 | - if($this->generate_mode==='direct') |
|
| 109 | + if ($this->generate_mode === 'direct') |
|
| 110 | 110 | { |
| 111 | 111 | $back_lang = $_lang; |
| 112 | 112 | $src = $modx->executeParser($docid); |
| 113 | 113 | |
| 114 | 114 | $_lang = $back_lang; |
| 115 | 115 | } |
| 116 | - else $src = $this->curl_get_contents(MODX_SITE_URL . "index.php?id={$docid}"); |
|
| 116 | + else $src = $this->curl_get_contents(MODX_SITE_URL."index.php?id={$docid}"); |
|
| 117 | 117 | |
| 118 | 118 | |
| 119 | - if($src !== false) |
|
| 119 | + if ($src !== false) |
|
| 120 | 120 | { |
| 121 | - if($this->repl_before!==$this->repl_after) $src = str_replace($this->repl_before,$this->repl_after,$src); |
|
| 122 | - $result = file_put_contents($filepath,$src); |
|
| 123 | - if($result!==false) @chmod($filepath, $file_permission); |
|
| 121 | + if ($this->repl_before !== $this->repl_after) $src = str_replace($this->repl_before, $this->repl_after, $src); |
|
| 122 | + $result = file_put_contents($filepath, $src); |
|
| 123 | + if ($result !== false) @chmod($filepath, $file_permission); |
|
| 124 | 124 | |
| 125 | - if($result !== false) return 'success'; |
|
| 125 | + if ($result !== false) return 'success'; |
|
| 126 | 126 | else return 'failed_no_write'; |
| 127 | 127 | } |
| 128 | 128 | else return 'failed_no_retrieve'; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - function getFileName($docid, $alias='', $prefix, $suffix) |
|
| 131 | + function getFileName($docid, $alias = '', $prefix, $suffix) |
|
| 132 | 132 | { |
| 133 | 133 | global $modx; |
| 134 | 134 | |
| 135 | - if($alias==='') $filename = $prefix.$docid.$suffix; |
|
| 135 | + if ($alias === '') $filename = $prefix.$docid.$suffix; |
|
| 136 | 136 | else |
| 137 | 137 | { |
| 138 | - if($modx->config['suffix_mode']==='1' && strpos($alias, '.')!==false) |
|
| 138 | + if ($modx->config['suffix_mode'] === '1' && strpos($alias, '.') !== false) |
|
| 139 | 139 | { |
| 140 | 140 | $suffix = ''; |
| 141 | 141 | } |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | return $filename; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - function run($parent=0) |
|
| 147 | + function run($parent = 0) |
|
| 148 | 148 | { |
| 149 | 149 | global $_lang; |
| 150 | 150 | global $modx; |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | $tbl_site_content = $modx->getFullTableName('site_content'); |
| 153 | 153 | |
| 154 | 154 | $ignore_ids = $this->ignore_ids; |
| 155 | - $dirpath = $this->targetDir . '/'; |
|
| 155 | + $dirpath = $this->targetDir.'/'; |
|
| 156 | 156 | |
| 157 | 157 | $prefix = $modx->config['friendly_url_prefix']; |
| 158 | 158 | $suffix = $modx->config['friendly_url_suffix']; |
@@ -162,36 +162,36 @@ discard block |
||
| 162 | 162 | |
| 163 | 163 | $ph['status'] = 'fail'; |
| 164 | 164 | $ph['msg1'] = $_lang['export_site_failed']; |
| 165 | - $ph['msg2'] = $_lang["export_site_failed_no_write"] . ' - ' . $dirpath; |
|
| 166 | - $msg_failed_no_write = $this->parsePlaceholder($tpl,$ph); |
|
| 165 | + $ph['msg2'] = $_lang["export_site_failed_no_write"].' - '.$dirpath; |
|
| 166 | + $msg_failed_no_write = $this->parsePlaceholder($tpl, $ph); |
|
| 167 | 167 | |
| 168 | 168 | $ph['msg2'] = $_lang["export_site_failed_no_retrieve"]; |
| 169 | - $msg_failed_no_retrieve = $this->parsePlaceholder($tpl,$ph); |
|
| 169 | + $msg_failed_no_retrieve = $this->parsePlaceholder($tpl, $ph); |
|
| 170 | 170 | |
| 171 | 171 | $ph['status'] = 'success'; |
| 172 | 172 | $ph['msg1'] = $_lang['export_site_success']; |
| 173 | 173 | $ph['msg2'] = ''; |
| 174 | - $msg_success = $this->parsePlaceholder($tpl,$ph); |
|
| 174 | + $msg_success = $this->parsePlaceholder($tpl, $ph); |
|
| 175 | 175 | |
| 176 | 176 | $ph['msg2'] = $_lang['export_site_success_skip_doc']; |
| 177 | - $msg_success_skip_doc = $this->parsePlaceholder($tpl,$ph); |
|
| 177 | + $msg_success_skip_doc = $this->parsePlaceholder($tpl, $ph); |
|
| 178 | 178 | |
| 179 | 179 | $ph['msg2'] = $_lang['export_site_success_skip_dir']; |
| 180 | - $msg_success_skip_dir = $this->parsePlaceholder($tpl,$ph); |
|
| 180 | + $msg_success_skip_dir = $this->parsePlaceholder($tpl, $ph); |
|
| 181 | 181 | |
| 182 | 182 | $fields = "id, alias, pagetitle, isfolder, (content = '' AND template = 0) AS wasNull, published"; |
| 183 | - $noncache = $_POST['includenoncache']==1 ? '' : 'AND cacheable=1'; |
|
| 183 | + $noncache = $_POST['includenoncache'] == 1 ? '' : 'AND cacheable=1'; |
|
| 184 | 184 | $where = "parent = '{$parent}' AND deleted=0 AND ((published=1 AND type='document') OR (isfolder=1)) {$noncache} {$ignore_ids}"; |
| 185 | - $rs = $modx->db->select($fields,$tbl_site_content,$where); |
|
| 185 | + $rs = $modx->db->select($fields, $tbl_site_content, $where); |
|
| 186 | 186 | |
| 187 | 187 | $ph = array(); |
| 188 | - $ph['total'] = $this->total; |
|
| 188 | + $ph['total'] = $this->total; |
|
| 189 | 189 | $folder_permission = octdec($modx->config['new_folder_permissions']); |
| 190 | - while($row = $modx->db->getRow($rs)) |
|
| 190 | + while ($row = $modx->db->getRow($rs)) |
|
| 191 | 191 | { |
| 192 | 192 | $this->count++; |
| 193 | 193 | |
| 194 | - $row['count'] = $this->count; |
|
| 194 | + $row['count'] = $this->count; |
|
| 195 | 195 | $row['url'] = $modx->makeUrl($row['id']); |
| 196 | 196 | |
| 197 | 197 | if (!$row['wasNull']) |
@@ -200,10 +200,10 @@ discard block |
||
| 200 | 200 | $filename = $dirpath.$docname; |
| 201 | 201 | if (!is_file($filename)) |
| 202 | 202 | { |
| 203 | - if($row['published']==='1') |
|
| 203 | + if ($row['published'] === '1') |
|
| 204 | 204 | { |
| 205 | 205 | $status = $this->makeFile($row['id'], $filename); |
| 206 | - switch($status) |
|
| 206 | + switch ($status) |
|
| 207 | 207 | { |
| 208 | 208 | case 'failed_no_write' : |
| 209 | 209 | $row['status'] = $msg_failed_no_write; |
@@ -225,11 +225,11 @@ discard block |
||
| 225 | 225 | $row['status'] = $msg_success_skip_dir; |
| 226 | 226 | $this->output[] = $this->parsePlaceholder($_lang['export_site_exporting_document'], $row); |
| 227 | 227 | } |
| 228 | - if ($row['isfolder']==='1' && ($modx->config['suffix_mode']!=='1' || strpos($row['alias'],'.')===false)) |
|
| 228 | + if ($row['isfolder'] === '1' && ($modx->config['suffix_mode'] !== '1' || strpos($row['alias'], '.') === false)) |
|
| 229 | 229 | { // needs making a folder |
| 230 | - $end_dir = ($row['alias']!=='') ? $row['alias'] : $row['id']; |
|
| 231 | - $dir_path = $dirpath . $end_dir; |
|
| 232 | - if(strpos($dir_path,MODX_BASE_PATH)===false) return FALSE; |
|
| 230 | + $end_dir = ($row['alias'] !== '') ? $row['alias'] : $row['id']; |
|
| 231 | + $dir_path = $dirpath.$end_dir; |
|
| 232 | + if (strpos($dir_path, MODX_BASE_PATH) === false) return FALSE; |
|
| 233 | 233 | if (!is_dir($dir_path)) |
| 234 | 234 | { |
| 235 | 235 | if (is_file($dir_path)) @unlink($dir_path); |
@@ -239,9 +239,9 @@ discard block |
||
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | |
| 242 | - if($modx->config['make_folders']==='1' && $row['published']==='1') |
|
| 242 | + if ($modx->config['make_folders'] === '1' && $row['published'] === '1') |
|
| 243 | 243 | { |
| 244 | - if(is_file($filename)) rename($filename,$dir_path . '/index.html'); |
|
| 244 | + if (is_file($filename)) rename($filename, $dir_path.'/index.html'); |
|
| 245 | 245 | } |
| 246 | 246 | $this->targetDir = $dir_path; |
| 247 | 247 | $this->run($row['id']); |
@@ -250,16 +250,16 @@ discard block |
||
| 250 | 250 | return implode("\n", $this->output); |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | - function curl_get_contents($url, $timeout = 30 ) |
|
| 253 | + function curl_get_contents($url, $timeout = 30) |
|
| 254 | 254 | { |
| 255 | - if(!function_exists('curl_init')) return @file_get_contents($url); |
|
| 255 | + if (!function_exists('curl_init')) return @file_get_contents($url); |
|
| 256 | 256 | |
| 257 | 257 | $ch = curl_init(); |
| 258 | 258 | curl_setopt($ch, CURLOPT_URL, $url); |
| 259 | - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // 0 = DO NOT VERIFY AUTHENTICITY OF SSL-CERT |
|
| 260 | - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // 2 = CERT MUST INDICATE BEING CONNECTED TO RIGHT SERVER |
|
| 259 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // 0 = DO NOT VERIFY AUTHENTICITY OF SSL-CERT |
|
| 260 | + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // 2 = CERT MUST INDICATE BEING CONNECTED TO RIGHT SERVER |
|
| 261 | 261 | curl_setopt($ch, CURLOPT_HEADER, false); |
| 262 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true ); |
|
| 262 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 263 | 263 | curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
| 264 | 264 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
| 265 | 265 | $result = curl_exec($ch); |
@@ -267,12 +267,12 @@ discard block |
||
| 267 | 267 | return $result; |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - function parsePlaceholder($tpl,$ph=array()) |
|
| 270 | + function parsePlaceholder($tpl, $ph = array()) |
|
| 271 | 271 | { |
| 272 | - foreach($ph as $k=>$v) |
|
| 272 | + foreach ($ph as $k=>$v) |
|
| 273 | 273 | { |
| 274 | 274 | $k = "[+{$k}+]"; |
| 275 | - $tpl = str_replace($k,$v,$tpl); |
|
| 275 | + $tpl = str_replace($k, $v, $tpl); |
|
| 276 | 276 | } |
| 277 | 277 | return $tpl; |
| 278 | 278 | } |
@@ -9,9 +9,9 @@ |
||
| 9 | 9 | |
| 10 | 10 | if (empty($database_type)) $database_type = 'mysql'; |
| 11 | 11 | |
| 12 | -if (!include_once MODX_MANAGER_PATH . 'includes/extenders/dbapi.' . $database_type . '.class.inc.php'){ |
|
| 12 | +if (!include_once MODX_MANAGER_PATH.'includes/extenders/dbapi.'.$database_type.'.class.inc.php') { |
|
| 13 | 13 | return false; |
| 14 | -}else{ |
|
| 15 | - $this->db= new DBAPI; |
|
| 14 | +} else { |
|
| 15 | + $this->db = new DBAPI; |
|
| 16 | 16 | return true; |
| 17 | 17 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | global $_PAGE; // page view state object. Usage $_PAGE['vs']['propertyname'] = $value; |
| 9 | 9 | |
| 10 | 10 | // Content manager wrapper class |
| 11 | -class ManagerAPI { |
|
| 11 | +class ManagerAPI{ |
|
| 12 | 12 | |
| 13 | 13 | var $action; // action directive |
| 14 | 14 | |
@@ -17,27 +17,27 @@ discard block |
||
| 17 | 17 | $this->action = $action; // set action directive |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - function initPageViewState($id=0){ |
|
| 20 | + function initPageViewState($id = 0){ |
|
| 21 | 21 | global $_PAGE; |
| 22 | 22 | $vsid = isset($_SESSION["mgrPageViewSID"]) ? $_SESSION["mgrPageViewSID"] : ''; |
| 23 | - if($vsid!=$this->action) { |
|
| 23 | + if ($vsid != $this->action) { |
|
| 24 | 24 | $_SESSION["mgrPageViewSDATA"] = array(); // new view state |
| 25 | - $_SESSION["mgrPageViewSID"] = $id>0 ? $id:$this->action; // set id |
|
| 25 | + $_SESSION["mgrPageViewSID"] = $id > 0 ? $id : $this->action; // set id |
|
| 26 | 26 | } |
| 27 | 27 | $_PAGE['vs'] = &$_SESSION["mgrPageViewSDATA"]; // restore viewstate |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | // save page view state - not really necessary, |
| 31 | - function savePageViewState($id=0){ |
|
| 31 | + function savePageViewState($id = 0){ |
|
| 32 | 32 | global $_PAGE; |
| 33 | 33 | $_SESSION["mgrPageViewSDATA"] = $_PAGE['vs']; |
| 34 | - $_SESSION["mgrPageViewSID"] = $id>0 ? $id:$this->action; |
|
| 34 | + $_SESSION["mgrPageViewSID"] = $id > 0 ? $id : $this->action; |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | // check for saved form |
| 38 | - function hasFormValues() { |
|
| 39 | - if(isset($_SESSION["mgrFormValueId"])) { |
|
| 40 | - if($this->action==$_SESSION["mgrFormValueId"]) { |
|
| 38 | + function hasFormValues(){ |
|
| 39 | + if (isset($_SESSION["mgrFormValueId"])) { |
|
| 40 | + if ($this->action == $_SESSION["mgrFormValueId"]) { |
|
| 41 | 41 | return true; |
| 42 | 42 | } |
| 43 | 43 | else { |
@@ -47,19 +47,19 @@ discard block |
||
| 47 | 47 | return false; |
| 48 | 48 | } |
| 49 | 49 | // saved form post from $_POST |
| 50 | - function saveFormValues($id=0){ |
|
| 50 | + function saveFormValues($id = 0){ |
|
| 51 | 51 | $_SESSION["mgrFormValues"] = $_POST; |
| 52 | - $_SESSION["mgrFormValueId"] = $id>0 ? $id:$this->action; |
|
| 52 | + $_SESSION["mgrFormValueId"] = $id > 0 ? $id : $this->action; |
|
| 53 | 53 | } |
| 54 | 54 | // load saved form values into $_POST |
| 55 | 55 | function loadFormValues(){ |
| 56 | 56 | |
| 57 | - if(!$this->hasFormValues()) return false; |
|
| 57 | + if (!$this->hasFormValues()) return false; |
|
| 58 | 58 | |
| 59 | 59 | $p = $_SESSION["mgrFormValues"]; |
| 60 | 60 | $this->clearSavedFormValues(); |
| 61 | - foreach($p as $k=>$v) { |
|
| 62 | - $_POST[$k]=$v; |
|
| 61 | + foreach ($p as $k=>$v) { |
|
| 62 | + $_POST[$k] = $v; |
|
| 63 | 63 | } |
| 64 | 64 | return true; |
| 65 | 65 | } |
@@ -69,50 +69,50 @@ discard block |
||
| 69 | 69 | unset($_SESSION["mgrFormValueId"]); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - function getHashType($db_value='') { // md5 | v1 | phpass |
|
| 73 | - $c = substr($db_value,0,1); |
|
| 74 | - if($c==='$') return 'phpass'; |
|
| 75 | - elseif(strlen($db_value)===32) return 'md5'; |
|
| 76 | - elseif($c!=='$' && strpos($db_value,'>')!==false) return 'v1'; |
|
| 72 | + function getHashType($db_value = ''){ // md5 | v1 | phpass |
|
| 73 | + $c = substr($db_value, 0, 1); |
|
| 74 | + if ($c === '$') return 'phpass'; |
|
| 75 | + elseif (strlen($db_value) === 32) return 'md5'; |
|
| 76 | + elseif ($c !== '$' && strpos($db_value, '>') !== false) return 'v1'; |
|
| 77 | 77 | else return 'unknown'; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - function genV1Hash($password, $seed='1') |
|
| 80 | + function genV1Hash($password, $seed = '1') |
|
| 81 | 81 | { // $seed is user_id basically |
| 82 | 82 | global $modx; |
| 83 | 83 | |
| 84 | - if(isset($modx->config['pwd_hash_algo']) && !empty($modx->config['pwd_hash_algo'])) |
|
| 84 | + if (isset($modx->config['pwd_hash_algo']) && !empty($modx->config['pwd_hash_algo'])) |
|
| 85 | 85 | $algorithm = $modx->config['pwd_hash_algo']; |
| 86 | 86 | else $algorithm = 'UNCRYPT'; |
| 87 | 87 | |
| 88 | - $salt = md5($password . $seed); |
|
| 88 | + $salt = md5($password.$seed); |
|
| 89 | 89 | |
| 90 | - switch($algorithm) |
|
| 90 | + switch ($algorithm) |
|
| 91 | 91 | { |
| 92 | 92 | case 'BLOWFISH_Y': |
| 93 | - $salt = '$2y$07$' . substr($salt,0,22); |
|
| 93 | + $salt = '$2y$07$'.substr($salt, 0, 22); |
|
| 94 | 94 | break; |
| 95 | 95 | case 'BLOWFISH_A': |
| 96 | - $salt = '$2a$07$' . substr($salt,0,22); |
|
| 96 | + $salt = '$2a$07$'.substr($salt, 0, 22); |
|
| 97 | 97 | break; |
| 98 | 98 | case 'SHA512': |
| 99 | - $salt = '$6$' . substr($salt,0,16); |
|
| 99 | + $salt = '$6$'.substr($salt, 0, 16); |
|
| 100 | 100 | break; |
| 101 | 101 | case 'SHA256': |
| 102 | - $salt = '$5$' . substr($salt,0,16); |
|
| 102 | + $salt = '$5$'.substr($salt, 0, 16); |
|
| 103 | 103 | break; |
| 104 | 104 | case 'MD5': |
| 105 | - $salt = '$1$' . substr($salt,0,8); |
|
| 105 | + $salt = '$1$'.substr($salt, 0, 8); |
|
| 106 | 106 | break; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - if($algorithm!=='UNCRYPT') |
|
| 109 | + if ($algorithm !== 'UNCRYPT') |
|
| 110 | 110 | { |
| 111 | - $password = sha1($password) . crypt($password,$salt); |
|
| 111 | + $password = sha1($password).crypt($password, $salt); |
|
| 112 | 112 | } |
| 113 | 113 | else $password = sha1($salt.$password); |
| 114 | 114 | |
| 115 | - $result = strtolower($algorithm) . '>' . md5($salt.$password) . substr(md5($salt),0,8); |
|
| 115 | + $result = strtolower($algorithm).'>'.md5($salt.$password).substr(md5($salt), 0, 8); |
|
| 116 | 116 | |
| 117 | 117 | return $result; |
| 118 | 118 | } |
@@ -121,18 +121,18 @@ discard block |
||
| 121 | 121 | { |
| 122 | 122 | global $modx; |
| 123 | 123 | $tbl_manager_users = $modx->getFullTableName('manager_users'); |
| 124 | - $rs = $modx->db->select('password',$tbl_manager_users,"id='{$uid}'"); |
|
| 124 | + $rs = $modx->db->select('password', $tbl_manager_users, "id='{$uid}'"); |
|
| 125 | 125 | $password = $modx->db->getValue($rs); |
| 126 | 126 | |
| 127 | - if(strpos($password,'>')===false) $algo = 'NOSALT'; |
|
| 127 | + if (strpos($password, '>') === false) $algo = 'NOSALT'; |
|
| 128 | 128 | else |
| 129 | 129 | { |
| 130 | - $algo = substr($password,0,strpos($password,'>')); |
|
| 130 | + $algo = substr($password, 0, strpos($password, '>')); |
|
| 131 | 131 | } |
| 132 | 132 | return strtoupper($algo); |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - function checkHashAlgorithm($algorithm='') |
|
| 135 | + function checkHashAlgorithm($algorithm = '') |
|
| 136 | 136 | { |
| 137 | 137 | $result = false; |
| 138 | 138 | if (!empty($algorithm)) |
@@ -165,54 +165,54 @@ discard block |
||
| 165 | 165 | return $result; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - function getSystemChecksum($check_files) { |
|
| 168 | + function getSystemChecksum($check_files){ |
|
| 169 | 169 | $_ = array(); |
| 170 | 170 | $check_files = trim($check_files); |
| 171 | 171 | $check_files = explode("\n", $check_files); |
| 172 | - foreach($check_files as $file) { |
|
| 172 | + foreach ($check_files as $file) { |
|
| 173 | 173 | $file = trim($file); |
| 174 | - $file = MODX_BASE_PATH . $file; |
|
| 175 | - if(!is_file($file)) continue; |
|
| 176 | - $_[$file]= md5_file($file); |
|
| 174 | + $file = MODX_BASE_PATH.$file; |
|
| 175 | + if (!is_file($file)) continue; |
|
| 176 | + $_[$file] = md5_file($file); |
|
| 177 | 177 | } |
| 178 | 178 | return serialize($_); |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | - function getModifiedSystemFilesList($check_files, $checksum) { |
|
| 181 | + function getModifiedSystemFilesList($check_files, $checksum){ |
|
| 182 | 182 | $_ = array(); |
| 183 | 183 | $check_files = trim($check_files); |
| 184 | 184 | $check_files = explode("\n", $check_files); |
| 185 | 185 | $checksum = unserialize($checksum); |
| 186 | - foreach($check_files as $file) { |
|
| 186 | + foreach ($check_files as $file) { |
|
| 187 | 187 | $file = trim($file); |
| 188 | - $filePath = MODX_BASE_PATH . $file; |
|
| 189 | - if(!is_file($filePath)) continue; |
|
| 190 | - if(md5_file($filePath) != $checksum[$filePath]) $_[] = $file; |
|
| 188 | + $filePath = MODX_BASE_PATH.$file; |
|
| 189 | + if (!is_file($filePath)) continue; |
|
| 190 | + if (md5_file($filePath) != $checksum[$filePath]) $_[] = $file; |
|
| 191 | 191 | } |
| 192 | 192 | return $_; |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - function setSystemChecksum($checksum) { |
|
| 195 | + function setSystemChecksum($checksum){ |
|
| 196 | 196 | global $modx; |
| 197 | 197 | $tbl_system_settings = $modx->getFullTableName('system_settings'); |
| 198 | - $sql = "REPLACE INTO {$tbl_system_settings} (setting_name, setting_value) VALUES ('sys_files_checksum','" . $modx->db->escape($checksum) . "')"; |
|
| 198 | + $sql = "REPLACE INTO {$tbl_system_settings} (setting_name, setting_value) VALUES ('sys_files_checksum','".$modx->db->escape($checksum)."')"; |
|
| 199 | 199 | $modx->db->query($sql); |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | - function checkSystemChecksum() { |
|
| 202 | + function checkSystemChecksum(){ |
|
| 203 | 203 | global $modx; |
| 204 | 204 | |
| 205 | - if(!isset($modx->config['check_files_onlogin']) || empty($modx->config['check_files_onlogin'])) return '0'; |
|
| 205 | + if (!isset($modx->config['check_files_onlogin']) || empty($modx->config['check_files_onlogin'])) return '0'; |
|
| 206 | 206 | |
| 207 | 207 | $current = $this->getSystemChecksum($modx->config['check_files_onlogin']); |
| 208 | - if(empty($current)) return '0'; |
|
| 208 | + if (empty($current)) return '0'; |
|
| 209 | 209 | |
| 210 | - if(!isset($modx->config['sys_files_checksum']) || empty($modx->config['sys_files_checksum'])) |
|
| 210 | + if (!isset($modx->config['sys_files_checksum']) || empty($modx->config['sys_files_checksum'])) |
|
| 211 | 211 | { |
| 212 | 212 | $this->setSystemChecksum($current); |
| 213 | 213 | return '0'; |
| 214 | 214 | } |
| 215 | - if($current===$modx->config['sys_files_checksum']) $result = '0'; |
|
| 215 | + if ($current === $modx->config['sys_files_checksum']) $result = '0'; |
|
| 216 | 216 | else { |
| 217 | 217 | $result = $this->getModifiedSystemFilesList($modx->config['check_files_onlogin'], $modx->config['sys_files_checksum']); |
| 218 | 218 | } |
@@ -220,28 +220,28 @@ discard block |
||
| 220 | 220 | return $result; |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - function getLastUserSetting($key=false) { |
|
| 223 | + function getLastUserSetting($key = false){ |
|
| 224 | 224 | global $modx; |
| 225 | 225 | |
| 226 | 226 | $rs = $modx->db->select('*', $modx->getFullTableName('user_settings'), "user = '{$_SESSION['mgrInternalKey']}'"); |
| 227 | 227 | |
| 228 | - $usersettings = array (); |
|
| 228 | + $usersettings = array(); |
|
| 229 | 229 | while ($row = $modx->db->getRow($rs)) { |
| 230 | - if(substr($row['setting_name'], 0, 6) == '_LAST_') { |
|
| 230 | + if (substr($row['setting_name'], 0, 6) == '_LAST_') { |
|
| 231 | 231 | $name = substr($row['setting_name'], 6); |
| 232 | 232 | $usersettings[$name] = $row['setting_value']; |
| 233 | 233 | } |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - if(!$key) return $usersettings; |
|
| 236 | + if (!$key) return $usersettings; |
|
| 237 | 237 | else return isset($usersettings[$key]) ? $usersettings[$key] : NULL; |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - function saveLastUserSetting($settings, $val='') { |
|
| 240 | + function saveLastUserSetting($settings, $val = ''){ |
|
| 241 | 241 | global $modx; |
| 242 | 242 | |
| 243 | - if(!empty($settings)) { |
|
| 244 | - if(!is_array($settings)) $settings = array($settings=>$val); |
|
| 243 | + if (!empty($settings)) { |
|
| 244 | + if (!is_array($settings)) $settings = array($settings=>$val); |
|
| 245 | 245 | |
| 246 | 246 | foreach ($settings as $key => $val) { |
| 247 | 247 | $f = array(); |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | } |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - function loadDatePicker($path) { |
|
| 259 | + function loadDatePicker($path){ |
|
| 260 | 260 | global $modx; |
| 261 | 261 | include_once($path); |
| 262 | 262 | $dp = new DATEPICKER(); |
@@ -24,13 +24,13 @@ discard block |
||
| 24 | 24 | // Obviously, since this code is in the public domain, the above are not |
| 25 | 25 | // requirements (there can be none), but merely suggestions. |
| 26 | 26 | // |
| 27 | -class PasswordHash { |
|
| 27 | +class PasswordHash{ |
|
| 28 | 28 | var $itoa64; |
| 29 | 29 | var $iteration_count_log2; |
| 30 | 30 | var $portable_hashes; |
| 31 | 31 | var $random_state; |
| 32 | 32 | |
| 33 | - function __construct($iteration_count_log2=8, $portable_hashes=true) |
|
| 33 | + function __construct($iteration_count_log2 = 8, $portable_hashes = true) |
|
| 34 | 34 | { |
| 35 | 35 | $this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
| 36 | 36 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | $this->portable_hashes = $portable_hashes; |
| 42 | 42 | |
| 43 | - $this->random_state = microtime() . uniqid(mt_rand(), TRUE); |
|
| 43 | + $this->random_state = microtime().uniqid(mt_rand(), TRUE); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | function get_random_bytes($count) |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | $output = ''; |
| 57 | 57 | for ($i = 0; $i < $count; $i += 16) { |
| 58 | 58 | $this->random_state = |
| 59 | - md5(microtime() . $this->random_state); |
|
| 59 | + md5(microtime().$this->random_state); |
|
| 60 | 60 | $output .= |
| 61 | 61 | pack('H*', md5($this->random_state)); |
| 62 | 62 | } |
@@ -126,9 +126,9 @@ discard block |
||
| 126 | 126 | // consequently in lower iteration counts and hashes that are |
| 127 | 127 | // quicker to crack (by non-PHP code). |
| 128 | 128 | |
| 129 | - $hash = md5($salt . $password, TRUE); |
|
| 129 | + $hash = md5($salt.$password, TRUE); |
|
| 130 | 130 | do { |
| 131 | - $hash = md5($hash . $password, TRUE); |
|
| 131 | + $hash = md5($hash.$password, TRUE); |
|
| 132 | 132 | } while (--$count); |
| 133 | 133 | |
| 134 | 134 | $output = substr($setting, 0, 12); |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | |
| 199 | 199 | function HashPassword($password) |
| 200 | 200 | { |
| 201 | - if ( strlen( $password ) > 4096 ) { |
|
| 201 | + if (strlen($password) > 4096) { |
|
| 202 | 202 | return '*'; |
| 203 | 203 | } |
| 204 | 204 | |
@@ -237,14 +237,14 @@ discard block |
||
| 237 | 237 | |
| 238 | 238 | function CheckPassword($password, $stored_hash) |
| 239 | 239 | { |
| 240 | - if ( strlen( $password ) > 4096 ) { |
|
| 240 | + if (strlen($password) > 4096) { |
|
| 241 | 241 | return false; |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | $hash = $this->crypt_private($password, $stored_hash); |
| 245 | - if (substr($hash,0,1) === '*') |
|
| 245 | + if (substr($hash, 0, 1) === '*') |
|
| 246 | 246 | $hash = crypt($password, $stored_hash); |
| 247 | 247 | |
| 248 | - return ($hash===$stored_hash) ? true : false; |
|
| 248 | + return ($hash === $stored_hash) ? true : false; |
|
| 249 | 249 | } |
| 250 | 250 | } |
@@ -6,17 +6,17 @@ |
||
| 6 | 6 | { |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | - function htmlspecialchars($str='', $flags = ENT_COMPAT, $encode='') |
|
| 9 | + function htmlspecialchars($str = '', $flags = ENT_COMPAT, $encode = '') |
|
| 10 | 10 | { |
| 11 | 11 | global $modx; |
| 12 | 12 | |
| 13 | - if($str=='') return ''; |
|
| 13 | + if ($str == '') return ''; |
|
| 14 | 14 | |
| 15 | - if($encode=='') $encode = $modx->config['modx_charset']; |
|
| 15 | + if ($encode == '') $encode = $modx->config['modx_charset']; |
|
| 16 | 16 | |
| 17 | 17 | $ent_str = htmlspecialchars($str, $flags, $encode); |
| 18 | 18 | |
| 19 | - if(!empty($str) && empty($ent_str)) |
|
| 19 | + if (!empty($str) && empty($ent_str)) |
|
| 20 | 20 | { |
| 21 | 21 | $detect_order = implode(',', mb_detect_order()); |
| 22 | 22 | $ent_str = mb_convert_encoding($str, $encode, $detect_order); |
@@ -1,8 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if(!defined('MODX_CORE_PATH')) define('MODX_CORE_PATH', MODX_MANAGER_PATH.'includes/'); |
|
| 3 | +if (!defined('MODX_CORE_PATH')) define('MODX_CORE_PATH', MODX_MANAGER_PATH.'includes/'); |
|
| 4 | 4 | |
| 5 | -class MODIFIERS { |
|
| 5 | +class MODIFIERS{ |
|
| 6 | 6 | |
| 7 | 7 | var $placeholders = array(); |
| 8 | 8 | var $vars = array(); |
@@ -24,14 +24,14 @@ discard block |
||
| 24 | 24 | $this->condModifiers = '=,is,eq,equals,ne,neq,notequals,isnot,isnt,not,%,isempty,isnotempty,isntempty,>=,gte,eg,gte,greaterthan,>,gt,isgreaterthan,isgt,lowerthan,<,lt,<=,lte,islte,islowerthan,islt,el,find,in,inarray,in_array,fnmatch,wcard,wcard_match,wildcard,wildcard_match,is_file,is_dir,file_exists,is_readable,is_writable,is_image,regex,preg,preg_match,memberof,mo,isinrole,ir'; |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - function phxFilter($key,$value,$modifiers) |
|
| 27 | + function phxFilter($key, $value, $modifiers) |
|
| 28 | 28 | { |
| 29 | 29 | global $modx; |
| 30 | - if(substr($modifiers,0,3)!=='id(') $value = $this->parseDocumentSource($value); |
|
| 30 | + if (substr($modifiers, 0, 3) !== 'id(') $value = $this->parseDocumentSource($value); |
|
| 31 | 31 | $this->srcValue = $value; |
| 32 | 32 | $modifiers = trim($modifiers); |
| 33 | - $modifiers = ':'.trim($modifiers,':'); |
|
| 34 | - $modifiers = str_replace(array("\r\n","\r"), "\n", $modifiers); |
|
| 33 | + $modifiers = ':'.trim($modifiers, ':'); |
|
| 34 | + $modifiers = str_replace(array("\r\n", "\r"), "\n", $modifiers); |
|
| 35 | 35 | $modifiers = $this->splitEachModifiers($modifiers); |
| 36 | 36 | |
| 37 | 37 | $this->placeholders = array(); |
@@ -39,117 +39,117 @@ discard block |
||
| 39 | 39 | $this->placeholders['dummy'] = ''; |
| 40 | 40 | $this->condition = array(); |
| 41 | 41 | $this->vars = array(); |
| 42 | - $this->vars['name'] = & $key; |
|
| 43 | - $value = $this->parsePhx($key,$value,$modifiers); |
|
| 42 | + $this->vars['name'] = & $key; |
|
| 43 | + $value = $this->parsePhx($key, $value, $modifiers); |
|
| 44 | 44 | $this->vars = array(); |
| 45 | 45 | return $value; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - function _getDelim($mode,$modifiers) { |
|
| 49 | - $c = substr($modifiers,0,1); |
|
| 50 | - if(!in_array($c, array('"', "'", '`')) ) return false; |
|
| 48 | + function _getDelim($mode, $modifiers){ |
|
| 49 | + $c = substr($modifiers, 0, 1); |
|
| 50 | + if (!in_array($c, array('"', "'", '`'))) return false; |
|
| 51 | 51 | |
| 52 | - $modifiers = substr($modifiers,1); |
|
| 53 | - $closure = $mode=='(' ? "{$c})" : $c; |
|
| 54 | - if(strpos($modifiers, $closure)===false) return false; |
|
| 52 | + $modifiers = substr($modifiers, 1); |
|
| 53 | + $closure = $mode == '(' ? "{$c})" : $c; |
|
| 54 | + if (strpos($modifiers, $closure) === false) return false; |
|
| 55 | 55 | |
| 56 | 56 | return $c; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - function _getOpt($mode,$delim,$modifiers) { |
|
| 60 | - if($delim) { |
|
| 61 | - if($mode=='(') return substr($modifiers,1,strpos($modifiers, $delim . ')' )-1); |
|
| 59 | + function _getOpt($mode, $delim, $modifiers){ |
|
| 60 | + if ($delim) { |
|
| 61 | + if ($mode == '(') return substr($modifiers, 1, strpos($modifiers, $delim.')') - 1); |
|
| 62 | 62 | |
| 63 | - return substr($modifiers,1,strpos($modifiers,$delim,1)-1); |
|
| 63 | + return substr($modifiers, 1, strpos($modifiers, $delim, 1) - 1); |
|
| 64 | 64 | } |
| 65 | 65 | else { |
| 66 | - if($mode=='(') return substr($modifiers,0,strpos($modifiers, ')') ); |
|
| 66 | + if ($mode == '(') return substr($modifiers, 0, strpos($modifiers, ')')); |
|
| 67 | 67 | |
| 68 | 68 | $chars = str_split($modifiers); |
| 69 | - $opt=''; |
|
| 70 | - foreach($chars as $c) { |
|
| 71 | - if($c==':' || $c==')') break; |
|
| 72 | - $opt .=$c; |
|
| 69 | + $opt = ''; |
|
| 70 | + foreach ($chars as $c) { |
|
| 71 | + if ($c == ':' || $c == ')') break; |
|
| 72 | + $opt .= $c; |
|
| 73 | 73 | } |
| 74 | 74 | return $opt; |
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | - function _getRemainModifiers($mode,$delim,$modifiers) { |
|
| 78 | - if($delim) { |
|
| 79 | - if($mode=='(') |
|
| 80 | - return $this->_fetchContent($modifiers, $delim . ')'); |
|
| 77 | + function _getRemainModifiers($mode, $delim, $modifiers){ |
|
| 78 | + if ($delim) { |
|
| 79 | + if ($mode == '(') |
|
| 80 | + return $this->_fetchContent($modifiers, $delim.')'); |
|
| 81 | 81 | else { |
| 82 | 82 | $modifiers = trim($modifiers); |
| 83 | - $modifiers = substr($modifiers,1); |
|
| 83 | + $modifiers = substr($modifiers, 1); |
|
| 84 | 84 | return $this->_fetchContent($modifiers, $delim); |
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | else { |
| 88 | - if($mode=='(') return $this->_fetchContent($modifiers, ')'); |
|
| 88 | + if ($mode == '(') return $this->_fetchContent($modifiers, ')'); |
|
| 89 | 89 | $chars = str_split($modifiers); |
| 90 | - foreach($chars as $c) { |
|
| 91 | - if($c==':') return $modifiers; |
|
| 92 | - else $modifiers = substr($modifiers,1); |
|
| 90 | + foreach ($chars as $c) { |
|
| 91 | + if ($c == ':') return $modifiers; |
|
| 92 | + else $modifiers = substr($modifiers, 1); |
|
| 93 | 93 | } |
| 94 | 94 | return $modifiers; |
| 95 | 95 | } |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - function _fetchContent($string,$delim) { |
|
| 98 | + function _fetchContent($string, $delim){ |
|
| 99 | 99 | $len = strlen($delim); |
| 100 | 100 | $string = $this->parseDocumentSource($string); |
| 101 | - return substr($string,strpos($string, $delim)+$len); |
|
| 101 | + return substr($string, strpos($string, $delim) + $len); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - function splitEachModifiers($modifiers) { |
|
| 104 | + function splitEachModifiers($modifiers){ |
|
| 105 | 105 | global $modx; |
| 106 | 106 | |
| 107 | 107 | $cmd = ''; |
| 108 | 108 | $bt = ''; |
| 109 | - while($bt!==$modifiers) { |
|
| 109 | + while ($bt !== $modifiers) { |
|
| 110 | 110 | $bt = $modifiers; |
| 111 | - $c = substr($modifiers,0,1); |
|
| 112 | - $modifiers = substr($modifiers,1); |
|
| 111 | + $c = substr($modifiers, 0, 1); |
|
| 112 | + $modifiers = substr($modifiers, 1); |
|
| 113 | 113 | |
| 114 | - if($c===':' && preg_match('@^(!?[<>=]{1,2})@', $modifiers, $match)) { // :=, :!=, :<=, :>=, :!<=, :!>= |
|
| 115 | - $c = substr($modifiers,strlen($match[1]),1); |
|
| 114 | + if ($c === ':' && preg_match('@^(!?[<>=]{1,2})@', $modifiers, $match)) { // :=, :!=, :<=, :>=, :!<=, :!>= |
|
| 115 | + $c = substr($modifiers, strlen($match[1]), 1); |
|
| 116 | 116 | $debuginfo = "#i=0 #c=[{$c}] #m=[{$modifiers}]"; |
| 117 | - if($c==='(') $modifiers = substr($modifiers,strlen($match[1])+1); |
|
| 118 | - else $modifiers = substr($modifiers,strlen($match[1])); |
|
| 117 | + if ($c === '(') $modifiers = substr($modifiers, strlen($match[1]) + 1); |
|
| 118 | + else $modifiers = substr($modifiers, strlen($match[1])); |
|
| 119 | 119 | |
| 120 | - $delim = $this->_getDelim($c,$modifiers); |
|
| 121 | - $opt = $this->_getOpt($c,$delim,$modifiers); |
|
| 122 | - $modifiers = trim($this->_getRemainModifiers($c,$delim,$modifiers)); |
|
| 120 | + $delim = $this->_getDelim($c, $modifiers); |
|
| 121 | + $opt = $this->_getOpt($c, $delim, $modifiers); |
|
| 122 | + $modifiers = trim($this->_getRemainModifiers($c, $delim, $modifiers)); |
|
| 123 | 123 | |
| 124 | - $result[]=array('cmd'=>trim($match[1]),'opt'=>$opt,'debuginfo'=>$debuginfo); |
|
| 124 | + $result[] = array('cmd'=>trim($match[1]), 'opt'=>$opt, 'debuginfo'=>$debuginfo); |
|
| 125 | 125 | $cmd = ''; |
| 126 | 126 | } |
| 127 | - elseif(in_array($c,array('+','-','*','/')) && preg_match('@^[0-9]+@', $modifiers, $match)) { // :+3, :-3, :*3 ... |
|
| 128 | - $modifiers = substr($modifiers,strlen($match[0])); |
|
| 129 | - $result[]=array('cmd'=>'math','opt'=>'%s'.$c.$match[0]); |
|
| 127 | + elseif (in_array($c, array('+', '-', '*', '/')) && preg_match('@^[0-9]+@', $modifiers, $match)) { // :+3, :-3, :*3 ... |
|
| 128 | + $modifiers = substr($modifiers, strlen($match[0])); |
|
| 129 | + $result[] = array('cmd'=>'math', 'opt'=>'%s'.$c.$match[0]); |
|
| 130 | 130 | $cmd = ''; |
| 131 | 131 | } |
| 132 | - elseif($c==='(' || $c==='=') { |
|
| 132 | + elseif ($c === '(' || $c === '=') { |
|
| 133 | 133 | $modifiers = $m1 = trim($modifiers); |
| 134 | - $delim = $this->_getDelim($c,$modifiers); |
|
| 135 | - $opt = $this->_getOpt($c,$delim,$modifiers); |
|
| 136 | - $modifiers = trim($this->_getRemainModifiers($c,$delim,$modifiers)); |
|
| 134 | + $delim = $this->_getDelim($c, $modifiers); |
|
| 135 | + $opt = $this->_getOpt($c, $delim, $modifiers); |
|
| 136 | + $modifiers = trim($this->_getRemainModifiers($c, $delim, $modifiers)); |
|
| 137 | 137 | $debuginfo = "#i=1 #c=[{$c}] #delim=[{$delim}] #m1=[{$m1}] remainMdf=[{$modifiers}]"; |
| 138 | 138 | |
| 139 | - $result[]=array('cmd'=>trim($cmd),'opt'=>$opt,'debuginfo'=>$debuginfo); |
|
| 139 | + $result[] = array('cmd'=>trim($cmd), 'opt'=>$opt, 'debuginfo'=>$debuginfo); |
|
| 140 | 140 | |
| 141 | 141 | $cmd = ''; |
| 142 | 142 | } |
| 143 | - elseif($c==':') { |
|
| 143 | + elseif ($c == ':') { |
|
| 144 | 144 | $debuginfo = "#i=2 #c=[{$c}] #m=[{$modifiers}]"; |
| 145 | - if($cmd!=='') $result[]=array('cmd'=>trim($cmd),'opt'=>'','debuginfo'=>$debuginfo); |
|
| 145 | + if ($cmd !== '') $result[] = array('cmd'=>trim($cmd), 'opt'=>'', 'debuginfo'=>$debuginfo); |
|
| 146 | 146 | |
| 147 | 147 | $cmd = ''; |
| 148 | 148 | } |
| 149 | - elseif(trim($modifiers)=='' && trim($cmd)!=='') { |
|
| 149 | + elseif (trim($modifiers) == '' && trim($cmd) !== '') { |
|
| 150 | 150 | $debuginfo = "#i=3 #c=[{$c}] #m=[{$modifiers}]"; |
| 151 | 151 | $cmd .= $c; |
| 152 | - $result[]=array('cmd'=>trim($cmd),'opt'=>'','debuginfo'=>$debuginfo); |
|
| 152 | + $result[] = array('cmd'=>trim($cmd), 'opt'=>'', 'debuginfo'=>$debuginfo); |
|
| 153 | 153 | |
| 154 | 154 | break; |
| 155 | 155 | } |
@@ -158,64 +158,64 @@ discard block |
||
| 158 | 158 | } |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - if(empty($result)) return array(); |
|
| 161 | + if (empty($result)) return array(); |
|
| 162 | 162 | |
| 163 | - foreach($result as $i=>$a) |
|
| 163 | + foreach ($result as $i=>$a) |
|
| 164 | 164 | { |
| 165 | 165 | $a['opt'] = $this->parseDocumentSource($a['opt']); |
| 166 | - $result[$i]['opt'] = $modx->mergePlaceholderContent($a['opt'],$this->placeholders); |
|
| 166 | + $result[$i]['opt'] = $modx->mergePlaceholderContent($a['opt'], $this->placeholders); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | return $result; |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - function parsePhx($key,$value,$modifiers) |
|
| 172 | + function parsePhx($key, $value, $modifiers) |
|
| 173 | 173 | { |
| 174 | 174 | global $modx; |
| 175 | - $cacheKey = md5(sprintf('parsePhx#%s#%s#%s',$key,$value,print_r($modifiers,true))); |
|
| 176 | - if(isset($this->tmpCache[$cacheKey])) return $this->tmpCache[$cacheKey]; |
|
| 177 | - if(empty($modifiers)) return ''; |
|
| 175 | + $cacheKey = md5(sprintf('parsePhx#%s#%s#%s', $key, $value, print_r($modifiers, true))); |
|
| 176 | + if (isset($this->tmpCache[$cacheKey])) return $this->tmpCache[$cacheKey]; |
|
| 177 | + if (empty($modifiers)) return ''; |
|
| 178 | 178 | |
| 179 | - foreach($modifiers as $m) |
|
| 179 | + foreach ($modifiers as $m) |
|
| 180 | 180 | { |
| 181 | 181 | $lastKey = strtolower($m['cmd']); |
| 182 | 182 | } |
| 183 | - $_ = explode(',',$this->condModifiers); |
|
| 184 | - if(in_array($lastKey,$_)) |
|
| 183 | + $_ = explode(',', $this->condModifiers); |
|
| 184 | + if (in_array($lastKey, $_)) |
|
| 185 | 185 | { |
| 186 | - $modifiers[] = array('cmd'=>'then','opt'=>'1'); |
|
| 187 | - $modifiers[] = array('cmd'=>'else','opt'=>'0'); |
|
| 186 | + $modifiers[] = array('cmd'=>'then', 'opt'=>'1'); |
|
| 187 | + $modifiers[] = array('cmd'=>'else', 'opt'=>'0'); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - foreach($modifiers as $i=>$a) |
|
| 190 | + foreach ($modifiers as $i=>$a) |
|
| 191 | 191 | { |
| 192 | - $value = $this->Filter($key,$value, $a['cmd'], $a['opt']); |
|
| 192 | + $value = $this->Filter($key, $value, $a['cmd'], $a['opt']); |
|
| 193 | 193 | } |
| 194 | 194 | $this->tmpCache[$cacheKey] = $value; |
| 195 | 195 | return $value; |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | // Parser: modifier detection and eXtended processing if needed |
| 199 | - function Filter($key, $value, $cmd, $opt='') |
|
| 199 | + function Filter($key, $value, $cmd, $opt = '') |
|
| 200 | 200 | { |
| 201 | 201 | global $modx; |
| 202 | 202 | |
| 203 | - if($key==='documentObject') $value = $modx->documentIdentifier; |
|
| 203 | + if ($key === 'documentObject') $value = $modx->documentIdentifier; |
|
| 204 | 204 | $cmd = $this->parseDocumentSource($cmd); |
| 205 | - if(preg_match('@^[1-9][/0-9]*$@',$cmd)) |
|
| 205 | + if (preg_match('@^[1-9][/0-9]*$@', $cmd)) |
|
| 206 | 206 | { |
| 207 | - if(strpos($cmd,'/')!==false) |
|
| 208 | - $cmd = $this->substr($cmd,strrpos($cmd,'/')+1); |
|
| 207 | + if (strpos($cmd, '/') !== false) |
|
| 208 | + $cmd = $this->substr($cmd, strrpos($cmd, '/') + 1); |
|
| 209 | 209 | $opt = $cmd; |
| 210 | 210 | $cmd = 'id'; |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | - if(isset($modx->snippetCache["phx:{$cmd}"])) $this->elmName = "phx:{$cmd}"; |
|
| 214 | - elseif(isset($modx->chunkCache["phx:{$cmd}"])) $this->elmName = "phx:{$cmd}"; |
|
| 213 | + if (isset($modx->snippetCache["phx:{$cmd}"])) $this->elmName = "phx:{$cmd}"; |
|
| 214 | + elseif (isset($modx->chunkCache["phx:{$cmd}"])) $this->elmName = "phx:{$cmd}"; |
|
| 215 | 215 | else $this->elmName = ''; |
| 216 | 216 | |
| 217 | 217 | $cmd = strtolower($cmd); |
| 218 | - if($this->elmName!=='') |
|
| 218 | + if ($this->elmName !== '') |
|
| 219 | 219 | $value = $this->getValueFromElement($key, $value, $cmd, $opt); |
| 220 | 220 | else |
| 221 | 221 | $value = $this->getValueFromPreset($key, $value, $cmd, $opt); |
@@ -225,12 +225,12 @@ discard block |
||
| 225 | 225 | return $value; |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | - function isEmpty($cmd,$value) |
|
| 228 | + function isEmpty($cmd, $value) |
|
| 229 | 229 | { |
| 230 | - if($value!=='') return false; |
|
| 230 | + if ($value !== '') return false; |
|
| 231 | 231 | |
| 232 | - $_ = explode(',', $this->condModifiers . ',_default,default,if,input,or,and,show,this,select,switch,then,else,id,ifempty,smart_desc,smart_description,summary'); |
|
| 233 | - if(in_array($cmd,$_)) return false; |
|
| 232 | + $_ = explode(',', $this->condModifiers.',_default,default,if,input,or,and,show,this,select,switch,then,else,id,ifempty,smart_desc,smart_description,summary'); |
|
| 233 | + if (in_array($cmd, $_)) return false; |
|
| 234 | 234 | else return true; |
| 235 | 235 | } |
| 236 | 236 | |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | { |
| 239 | 239 | global $modx; |
| 240 | 240 | |
| 241 | - if($this->isEmpty($cmd,$value)) return ''; |
|
| 241 | + if ($this->isEmpty($cmd, $value)) return ''; |
|
| 242 | 242 | |
| 243 | 243 | $this->key = $key; |
| 244 | 244 | $this->value = $value; |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | ##### Conditional Modifiers |
| 250 | 250 | case 'input': |
| 251 | 251 | case 'if': |
| 252 | - if(!$opt) return $value; |
|
| 252 | + if (!$opt) return $value; |
|
| 253 | 253 | return $opt; |
| 254 | 254 | case '=': |
| 255 | 255 | case 'eq': |
@@ -262,9 +262,9 @@ discard block |
||
| 262 | 262 | case 'isnot': |
| 263 | 263 | case 'isnt': |
| 264 | 264 | case 'not': |
| 265 | - $this->condition[] = intval($value != $opt);break; |
|
| 265 | + $this->condition[] = intval($value != $opt); break; |
|
| 266 | 266 | case '%': |
| 267 | - $this->condition[] = intval($value%$opt==0);break; |
|
| 267 | + $this->condition[] = intval($value % $opt == 0); break; |
|
| 268 | 268 | case 'isempty': |
| 269 | 269 | $this->condition[] = intval(empty($value)); break; |
| 270 | 270 | case 'isntempty': |
@@ -274,57 +274,57 @@ discard block |
||
| 274 | 274 | case 'gte': |
| 275 | 275 | case 'eg': |
| 276 | 276 | case 'isgte': |
| 277 | - $this->condition[] = intval($value >= $opt);break; |
|
| 277 | + $this->condition[] = intval($value >= $opt); break; |
|
| 278 | 278 | case '<=': |
| 279 | 279 | case 'lte': |
| 280 | 280 | case 'el': |
| 281 | 281 | case 'islte': |
| 282 | - $this->condition[] = intval($value <= $opt);break; |
|
| 282 | + $this->condition[] = intval($value <= $opt); break; |
|
| 283 | 283 | case '>': |
| 284 | 284 | case 'gt': |
| 285 | 285 | case 'greaterthan': |
| 286 | 286 | case 'isgreaterthan': |
| 287 | 287 | case 'isgt': |
| 288 | - $this->condition[] = intval($value > $opt);break; |
|
| 288 | + $this->condition[] = intval($value > $opt); break; |
|
| 289 | 289 | case '<': |
| 290 | 290 | case 'lt': |
| 291 | 291 | case 'lowerthan': |
| 292 | 292 | case 'islowerthan': |
| 293 | 293 | case 'islt': |
| 294 | - $this->condition[] = intval($value < $opt);break; |
|
| 294 | + $this->condition[] = intval($value < $opt); break; |
|
| 295 | 295 | case 'find': |
| 296 | - $this->condition[] = intval(strpos($value, $opt)!==false);break; |
|
| 296 | + $this->condition[] = intval(strpos($value, $opt) !== false); break; |
|
| 297 | 297 | case 'inarray': |
| 298 | 298 | case 'in_array': |
| 299 | 299 | case 'in': |
| 300 | 300 | $opt = explode(',', $opt); |
| 301 | - $this->condition[] = intval(in_array($value, $opt)!==false);break; |
|
| 301 | + $this->condition[] = intval(in_array($value, $opt) !== false); break; |
|
| 302 | 302 | case 'wildcard_match': |
| 303 | 303 | case 'wcard_match': |
| 304 | 304 | case 'wildcard': |
| 305 | 305 | case 'wcard': |
| 306 | 306 | case 'fnmatch': |
| 307 | - $this->condition[] = intval(fnmatch($opt, $value)!==false);break; |
|
| 307 | + $this->condition[] = intval(fnmatch($opt, $value) !== false); break; |
|
| 308 | 308 | case 'is_file': |
| 309 | 309 | case 'is_dir': |
| 310 | 310 | case 'file_exists': |
| 311 | 311 | case 'is_readable': |
| 312 | 312 | case 'is_writable': |
| 313 | - if(!$opt) $path = $value; |
|
| 313 | + if (!$opt) $path = $value; |
|
| 314 | 314 | else $path = $opt; |
| 315 | - if(strpos($path,MODX_MANAGER_PATH)!==false) exit('Can not read core path'); |
|
| 316 | - if(strpos($path,$modx->config['base_path'])===false) $path = ltrim($path,'/'); |
|
| 317 | - $this->condition[] = intval($cmd($path)!==false);break; |
|
| 315 | + if (strpos($path, MODX_MANAGER_PATH) !== false) exit('Can not read core path'); |
|
| 316 | + if (strpos($path, $modx->config['base_path']) === false) $path = ltrim($path, '/'); |
|
| 317 | + $this->condition[] = intval($cmd($path) !== false); break; |
|
| 318 | 318 | case 'is_image': |
| 319 | - if(!$opt) $path = $value; |
|
| 319 | + if (!$opt) $path = $value; |
|
| 320 | 320 | else $path = $opt; |
| 321 | - if(!is_file($path)) {$this->condition[]='0';break;} |
|
| 321 | + if (!is_file($path)) {$this->condition[] = '0'; break; } |
|
| 322 | 322 | $_ = getimagesize($path); |
| 323 | - $this->condition[] = intval($_[0]);break; |
|
| 323 | + $this->condition[] = intval($_[0]); break; |
|
| 324 | 324 | case 'regex': |
| 325 | 325 | case 'preg': |
| 326 | 326 | case 'preg_match': |
| 327 | - $this->condition[] = intval(preg_match($opt,$value));break; |
|
| 327 | + $this->condition[] = intval(preg_match($opt, $value)); break; |
|
| 328 | 328 | case 'isinrole': |
| 329 | 329 | case 'ir': |
| 330 | 330 | case 'memberof': |
@@ -333,50 +333,50 @@ discard block |
||
| 333 | 333 | $this->condition[] = $this->includeMdfFile('memberof'); |
| 334 | 334 | break; |
| 335 | 335 | case 'or': |
| 336 | - $this->condition[] = '||';break; |
|
| 336 | + $this->condition[] = '||'; break; |
|
| 337 | 337 | case 'and': |
| 338 | - $this->condition[] = '&&';break; |
|
| 338 | + $this->condition[] = '&&'; break; |
|
| 339 | 339 | case 'show': |
| 340 | 340 | case 'this': |
| 341 | - $conditional = join(' ',$this->condition); |
|
| 341 | + $conditional = join(' ', $this->condition); |
|
| 342 | 342 | $isvalid = intval(eval("return ({$conditional});")); |
| 343 | 343 | if ($isvalid) return $this->srcValue; |
| 344 | 344 | return NULL; |
| 345 | 345 | case 'then': |
| 346 | - $conditional = join(' ',$this->condition); |
|
| 346 | + $conditional = join(' ', $this->condition); |
|
| 347 | 347 | $isvalid = intval(eval("return ({$conditional});")); |
| 348 | 348 | if ($isvalid) return $opt; |
| 349 | 349 | return null; |
| 350 | 350 | case 'else': |
| 351 | - $conditional = join(' ',$this->condition); |
|
| 351 | + $conditional = join(' ', $this->condition); |
|
| 352 | 352 | $isvalid = intval(eval("return ({$conditional});")); |
| 353 | 353 | if (!$isvalid) return $opt; |
| 354 | 354 | break; |
| 355 | 355 | case 'select': |
| 356 | 356 | case 'switch': |
| 357 | - $raw = explode('&',$opt); |
|
| 357 | + $raw = explode('&', $opt); |
|
| 358 | 358 | $map = array(); |
| 359 | 359 | $c = count($raw); |
| 360 | - for($m=0; $m<$c; $m++) { |
|
| 361 | - $mi = explode('=',$raw[$m],2); |
|
| 360 | + for ($m = 0; $m < $c; $m++) { |
|
| 361 | + $mi = explode('=', $raw[$m], 2); |
|
| 362 | 362 | $map[$mi[0]] = $mi[1]; |
| 363 | 363 | } |
| 364 | - if(isset($map[$value])) return $map[$value]; |
|
| 364 | + if (isset($map[$value])) return $map[$value]; |
|
| 365 | 365 | else return ''; |
| 366 | 366 | ##### End of Conditional Modifiers |
| 367 | 367 | |
| 368 | 368 | ##### Encode / Decode / Hash / Escape |
| 369 | 369 | case 'htmlent': |
| 370 | 370 | case 'htmlentities': |
| 371 | - return htmlentities($value,ENT_QUOTES,$modx->config['modx_charset']); |
|
| 371 | + return htmlentities($value, ENT_QUOTES, $modx->config['modx_charset']); |
|
| 372 | 372 | case 'html_entity_decode': |
| 373 | 373 | case 'decode_html': |
| 374 | 374 | case 'html_decode': |
| 375 | - return html_entity_decode($value,ENT_QUOTES,$modx->config['modx_charset']); |
|
| 375 | + return html_entity_decode($value, ENT_QUOTES, $modx->config['modx_charset']); |
|
| 376 | 376 | case 'esc': |
| 377 | 377 | case 'escape': |
| 378 | 378 | $value = preg_replace('/&(#[0-9]+|[a-z]+);/i', '&$1;', htmlspecialchars($value, ENT_QUOTES, $modx->config['modx_charset'])); |
| 379 | - return str_replace(array('[', ']', '`'),array('[', ']', '`'),$value); |
|
| 379 | + return str_replace(array('[', ']', '`'), array('[', ']', '`'), $value); |
|
| 380 | 380 | case 'sql_escape': |
| 381 | 381 | case 'encode_js': |
| 382 | 382 | return $modx->db->escape($value); |
@@ -386,39 +386,39 @@ discard block |
||
| 386 | 386 | case 'html_encode': |
| 387 | 387 | return preg_replace('/&(#[0-9]+|[a-z]+);/i', '&$1;', htmlspecialchars($value, ENT_QUOTES, $modx->config['modx_charset'])); |
| 388 | 388 | case 'spam_protect': |
| 389 | - return str_replace(array('@','.'),array('@','.'),$value); |
|
| 389 | + return str_replace(array('@', '.'), array('@', '.'), $value); |
|
| 390 | 390 | case 'strip': |
| 391 | - if($opt==='') $opt = ' '; |
|
| 391 | + if ($opt === '') $opt = ' '; |
|
| 392 | 392 | return preg_replace('/[\n\r\t\s]+/', $opt, $value); |
| 393 | 393 | case 'strip_linefeeds': |
| 394 | - return str_replace(array("\n","\r"), '', $value); |
|
| 394 | + return str_replace(array("\n", "\r"), '', $value); |
|
| 395 | 395 | case 'notags': |
| 396 | 396 | case 'strip_tags': |
| 397 | 397 | case 'remove_html': |
| 398 | - if($opt!=='') |
|
| 398 | + if ($opt !== '') |
|
| 399 | 399 | { |
| 400 | 400 | $param = array(); |
| 401 | - foreach(explode(',',$opt) as $v) |
|
| 401 | + foreach (explode(',', $opt) as $v) |
|
| 402 | 402 | { |
| 403 | - $v = trim($v,'</> '); |
|
| 403 | + $v = trim($v, '</> '); |
|
| 404 | 404 | $param[] = "<{$v}>"; |
| 405 | 405 | } |
| 406 | - $params = join(',',$param); |
|
| 406 | + $params = join(',', $param); |
|
| 407 | 407 | } |
| 408 | 408 | else $params = ''; |
| 409 | - if(!strpos($params,'<br>')===false) { |
|
| 410 | - $value = preg_replace('@(<br[ /]*>)\n@','$1',$value); |
|
| 411 | - $value = preg_replace('@<br[ /]*>@',"\n",$value); |
|
| 409 | + if (!strpos($params, '<br>') === false) { |
|
| 410 | + $value = preg_replace('@(<br[ /]*>)\n@', '$1', $value); |
|
| 411 | + $value = preg_replace('@<br[ /]*>@', "\n", $value); |
|
| 412 | 412 | } |
| 413 | - return $this->strip_tags($value,$params); |
|
| 413 | + return $this->strip_tags($value, $params); |
|
| 414 | 414 | case 'urlencode': |
| 415 | 415 | case 'url_encode': |
| 416 | 416 | case 'encode_url': |
| 417 | 417 | return urlencode($value); |
| 418 | 418 | case 'base64_decode': |
| 419 | - if($opt!=='false') $opt = true; |
|
| 419 | + if ($opt !== 'false') $opt = true; |
|
| 420 | 420 | else $opt = false; |
| 421 | - return base64_decode($value,$opt); |
|
| 421 | + return base64_decode($value, $opt); |
|
| 422 | 422 | case 'encode_sha1': $cmd = 'sha1'; |
| 423 | 423 | case 'addslashes': |
| 424 | 424 | case 'urldecode': |
@@ -442,18 +442,18 @@ discard block |
||
| 442 | 442 | case 'upper_case': |
| 443 | 443 | return $this->strtoupper($value); |
| 444 | 444 | case 'capitalize': |
| 445 | - $_ = explode(' ',$value); |
|
| 446 | - foreach($_ as $i=>$v) |
|
| 445 | + $_ = explode(' ', $value); |
|
| 446 | + foreach ($_ as $i=>$v) |
|
| 447 | 447 | { |
| 448 | 448 | $_[$i] = ucfirst($v); |
| 449 | 449 | } |
| 450 | - return join(' ',$_); |
|
| 450 | + return join(' ', $_); |
|
| 451 | 451 | case 'zenhan': |
| 452 | - if(empty($opt)) $opt='VKas'; |
|
| 453 | - return mb_convert_kana($value,$opt,$modx->config['modx_charset']); |
|
| 452 | + if (empty($opt)) $opt = 'VKas'; |
|
| 453 | + return mb_convert_kana($value, $opt, $modx->config['modx_charset']); |
|
| 454 | 454 | case 'hanzen': |
| 455 | - if(empty($opt)) $opt='VKAS'; |
|
| 456 | - return mb_convert_kana($value,$opt,$modx->config['modx_charset']); |
|
| 455 | + if (empty($opt)) $opt = 'VKAS'; |
|
| 456 | + return mb_convert_kana($value, $opt, $modx->config['modx_charset']); |
|
| 457 | 457 | case 'str_shuffle': |
| 458 | 458 | case 'shuffle': |
| 459 | 459 | return $this->str_shuffle($value); |
@@ -467,7 +467,7 @@ discard block |
||
| 467 | 467 | return $this->strlen($value); |
| 468 | 468 | case 'count_words': |
| 469 | 469 | $value = trim($value); |
| 470 | - return count(preg_split('/\s+/',$value)); |
|
| 470 | + return count(preg_split('/\s+/', $value)); |
|
| 471 | 471 | case 'str_word_count': |
| 472 | 472 | case 'word_count': |
| 473 | 473 | case 'wordcount': |
@@ -475,55 +475,55 @@ discard block |
||
| 475 | 475 | case 'count_paragraphs': |
| 476 | 476 | $value = trim($value); |
| 477 | 477 | $value = preg_replace('/\r/', '', $value); |
| 478 | - return count(preg_split('/\n+/',$value)); |
|
| 478 | + return count(preg_split('/\n+/', $value)); |
|
| 479 | 479 | case 'strpos': |
| 480 | - if($opt!=0&&empty($opt)) return $value; |
|
| 481 | - return $this->strpos($value,$opt); |
|
| 480 | + if ($opt != 0 && empty($opt)) return $value; |
|
| 481 | + return $this->strpos($value, $opt); |
|
| 482 | 482 | case 'wordwrap': |
| 483 | 483 | // default: 70 |
| 484 | 484 | $wrapat = intval($opt) ? intval($opt) : 70; |
| 485 | 485 | if (version_compare(PHP_VERSION, '5.3.0') >= 0) return $this->includeMdfFile('wordwrap'); |
| 486 | - else return preg_replace("@(\b\w+\b)@e","wordwrap('\\1',\$wrapat,' ',1)",$value); |
|
| 486 | + else return preg_replace("@(\b\w+\b)@e", "wordwrap('\\1',\$wrapat,' ',1)", $value); |
|
| 487 | 487 | case 'wrap_text': |
| 488 | - $width = preg_match('/^[1-9][0-9]*$/',$opt) ? $opt : 70; |
|
| 489 | - if($modx->config['manager_language']==='japanese-utf8') { |
|
| 488 | + $width = preg_match('/^[1-9][0-9]*$/', $opt) ? $opt : 70; |
|
| 489 | + if ($modx->config['manager_language'] === 'japanese-utf8') { |
|
| 490 | 490 | $chunk = array(); |
| 491 | - $bt=''; |
|
| 492 | - while($bt!=$value) { |
|
| 491 | + $bt = ''; |
|
| 492 | + while ($bt != $value) { |
|
| 493 | 493 | $bt = $value; |
| 494 | - if($this->strlen($value)<$width) { |
|
| 494 | + if ($this->strlen($value) < $width) { |
|
| 495 | 495 | $chunk[] = $value; |
| 496 | 496 | break; |
| 497 | 497 | } |
| 498 | - $chunk[] = $this->substr($value,0,$width); |
|
| 499 | - $value = $this->substr($value,$width); |
|
| 498 | + $chunk[] = $this->substr($value, 0, $width); |
|
| 499 | + $value = $this->substr($value, $width); |
|
| 500 | 500 | } |
| 501 | - return join("\n",$chunk); |
|
| 501 | + return join("\n", $chunk); |
|
| 502 | 502 | } |
| 503 | 503 | else |
| 504 | - return wordwrap($value,$width,"\n",true); |
|
| 504 | + return wordwrap($value, $width, "\n", true); |
|
| 505 | 505 | case 'substr': |
| 506 | - if(empty($opt)) break; |
|
| 507 | - if(strpos($opt,',')!==false) { |
|
| 508 | - list($b,$e) = explode(',',$opt,2); |
|
| 509 | - return $this->substr($value,$b,(int)$e); |
|
| 506 | + if (empty($opt)) break; |
|
| 507 | + if (strpos($opt, ',') !== false) { |
|
| 508 | + list($b, $e) = explode(',', $opt, 2); |
|
| 509 | + return $this->substr($value, $b, (int) $e); |
|
| 510 | 510 | } |
| 511 | - else return $this->substr($value,$opt); |
|
| 511 | + else return $this->substr($value, $opt); |
|
| 512 | 512 | case 'limit': |
| 513 | 513 | case 'trim_to': // http://www.movabletype.jp/documentation/appendices/modifiers/trim_to.html |
| 514 | - if(strpos($opt,'+')!==false) |
|
| 515 | - list($len,$str) = explode('+',$opt,2); |
|
| 514 | + if (strpos($opt, '+') !== false) |
|
| 515 | + list($len, $str) = explode('+', $opt, 2); |
|
| 516 | 516 | else { |
| 517 | 517 | $len = $opt; |
| 518 | 518 | $str = ''; |
| 519 | 519 | } |
| 520 | - if($len==='') $len = 100; |
|
| 521 | - if(abs($len) > $this->strlen($value)) $str =''; |
|
| 522 | - if(preg_match('/^[1-9][0-9]*$/',$len)) { |
|
| 523 | - return $this->substr($value,0,$len) . $str; |
|
| 520 | + if ($len === '') $len = 100; |
|
| 521 | + if (abs($len) > $this->strlen($value)) $str = ''; |
|
| 522 | + if (preg_match('/^[1-9][0-9]*$/', $len)) { |
|
| 523 | + return $this->substr($value, 0, $len).$str; |
|
| 524 | 524 | } |
| 525 | - elseif(preg_match('/^\-[1-9][0-9]*$/',$len)) { |
|
| 526 | - return $str . $this->substr($value,$len); |
|
| 525 | + elseif (preg_match('/^\-[1-9][0-9]*$/', $len)) { |
|
| 526 | + return $str.$this->substr($value, $len); |
|
| 527 | 527 | } |
| 528 | 528 | break; |
| 529 | 529 | case 'summary': |
@@ -532,81 +532,81 @@ discard block |
||
| 532 | 532 | return $this->includeMdfFile('summary'); |
| 533 | 533 | case 'replace': |
| 534 | 534 | case 'str_replace': |
| 535 | - if(empty($opt) || strpos($opt,',')===false) break; |
|
| 536 | - if (substr_count($opt, ',') ==1) $delim = ','; |
|
| 537 | - elseif(substr_count($opt, '|') ==1) $delim = '|'; |
|
| 538 | - elseif(substr_count($opt, '=>')==1) $delim = '=>'; |
|
| 539 | - elseif(substr_count($opt, '/') ==1) $delim = '/'; |
|
| 535 | + if (empty($opt) || strpos($opt, ',') === false) break; |
|
| 536 | + if (substr_count($opt, ',') == 1) $delim = ','; |
|
| 537 | + elseif (substr_count($opt, '|') == 1) $delim = '|'; |
|
| 538 | + elseif (substr_count($opt, '=>') == 1) $delim = '=>'; |
|
| 539 | + elseif (substr_count($opt, '/') == 1) $delim = '/'; |
|
| 540 | 540 | else break; |
| 541 | - list($s,$r) = explode($delim,$opt); |
|
| 542 | - if($value!=='') return str_replace($s,$r,$value); |
|
| 541 | + list($s, $r) = explode($delim, $opt); |
|
| 542 | + if ($value !== '') return str_replace($s, $r, $value); |
|
| 543 | 543 | break; |
| 544 | 544 | case 'replace_to': |
| 545 | 545 | case 'tpl': |
| 546 | - if($value!=='') return str_replace(array('[+value+]','[+output+]','{value}','%s'),$value,$opt); |
|
| 546 | + if ($value !== '') return str_replace(array('[+value+]', '[+output+]', '{value}', '%s'), $value, $opt); |
|
| 547 | 547 | break; |
| 548 | 548 | case 'eachtpl': |
| 549 | - $value = explode('||',$value); |
|
| 549 | + $value = explode('||', $value); |
|
| 550 | 550 | $_ = array(); |
| 551 | - foreach($value as $v) { |
|
| 552 | - $_[] = str_replace(array('[+value+]','[+output+]','{value}','%s'),$v,$opt); |
|
| 551 | + foreach ($value as $v) { |
|
| 552 | + $_[] = str_replace(array('[+value+]', '[+output+]', '{value}', '%s'), $v, $opt); |
|
| 553 | 553 | } |
| 554 | 554 | return join("\n", $_); |
| 555 | 555 | case 'array_pop': |
| 556 | 556 | case 'array_shift': |
| 557 | - if(strpos($value,'||')!==false) $delim = '||'; |
|
| 557 | + if (strpos($value, '||') !== false) $delim = '||'; |
|
| 558 | 558 | else $delim = ','; |
| 559 | - return $cmd(explode($delim,$value)); |
|
| 559 | + return $cmd(explode($delim, $value)); |
|
| 560 | 560 | case 'preg_replace': |
| 561 | 561 | case 'regex_replace': |
| 562 | - if(empty($opt) || strpos($opt,',')===false) break; |
|
| 563 | - list($s,$r) = explode(',',$opt,2); |
|
| 564 | - if($value!=='') return preg_replace($s,$r,$value); |
|
| 562 | + if (empty($opt) || strpos($opt, ',') === false) break; |
|
| 563 | + list($s, $r) = explode(',', $opt, 2); |
|
| 564 | + if ($value !== '') return preg_replace($s, $r, $value); |
|
| 565 | 565 | break; |
| 566 | 566 | case 'cat': |
| 567 | 567 | case 'concatenate': |
| 568 | 568 | case '.': |
| 569 | - if($value!=='') return $value . $opt; |
|
| 569 | + if ($value !== '') return $value.$opt; |
|
| 570 | 570 | break; |
| 571 | 571 | case 'sprintf': |
| 572 | 572 | case 'string_format': |
| 573 | - if($value!=='') return sprintf($opt,$value); |
|
| 573 | + if ($value !== '') return sprintf($opt, $value); |
|
| 574 | 574 | break; |
| 575 | 575 | case 'number_format': |
| 576 | - if($opt=='') $opt = 0; |
|
| 577 | - return number_format($value,$opt); |
|
| 576 | + if ($opt == '') $opt = 0; |
|
| 577 | + return number_format($value, $opt); |
|
| 578 | 578 | case 'money_format': |
| 579 | - setlocale(LC_MONETARY,setlocale(LC_TIME,0)); |
|
| 580 | - if($value!=='') return money_format($opt,(double)$value); |
|
| 579 | + setlocale(LC_MONETARY, setlocale(LC_TIME, 0)); |
|
| 580 | + if ($value !== '') return money_format($opt, (double) $value); |
|
| 581 | 581 | break; |
| 582 | 582 | case 'tobool': |
| 583 | 583 | return boolval($value); |
| 584 | 584 | case 'nl2lf': |
| 585 | - if($value!=='') return str_replace(array("\r\n","\n", "\r"), '\n', $value); |
|
| 585 | + if ($value !== '') return str_replace(array("\r\n", "\n", "\r"), '\n', $value); |
|
| 586 | 586 | break; |
| 587 | 587 | case 'br2nl': |
| 588 | 588 | return preg_replace('@<br[\s/]*>@i', "\n", $value); |
| 589 | 589 | case 'nl2br': |
| 590 | 590 | if (version_compare(PHP_VERSION, '5.3.0', '<')) |
| 591 | 591 | return nl2br($value); |
| 592 | - if($opt!=='') |
|
| 592 | + if ($opt !== '') |
|
| 593 | 593 | { |
| 594 | 594 | $opt = trim($opt); |
| 595 | 595 | $opt = strtolower($opt); |
| 596 | - if($opt==='false') $opt = false; |
|
| 597 | - elseif($opt==='0') $opt = false; |
|
| 596 | + if ($opt === 'false') $opt = false; |
|
| 597 | + elseif ($opt === '0') $opt = false; |
|
| 598 | 598 | else $opt = true; |
| 599 | 599 | } |
| 600 | - elseif(isset($modx->config['mce_element_format'])&&$modx->config['mce_element_format']==='html') |
|
| 600 | + elseif (isset($modx->config['mce_element_format']) && $modx->config['mce_element_format'] === 'html') |
|
| 601 | 601 | $opt = false; |
| 602 | 602 | else $opt = true; |
| 603 | - return nl2br($value,$opt); |
|
| 603 | + return nl2br($value, $opt); |
|
| 604 | 604 | case 'ltrim': |
| 605 | 605 | case 'rtrim': |
| 606 | 606 | case 'trim': // ref http://mblo.info/modifiers/custom-modifiers/rtrim_opt.html |
| 607 | - if($opt==='') |
|
| 607 | + if ($opt === '') |
|
| 608 | 608 | return $cmd($value); |
| 609 | - else return $cmd($value,$opt); |
|
| 609 | + else return $cmd($value, $opt); |
|
| 610 | 610 | // These are all straight wrappers for PHP functions |
| 611 | 611 | case 'ucfirst': |
| 612 | 612 | case 'lcfirst': |
@@ -617,16 +617,16 @@ discard block |
||
| 617 | 617 | case 'strftime': |
| 618 | 618 | case 'date': |
| 619 | 619 | case 'dateformat': |
| 620 | - if(empty($opt)) $opt = $modx->toDateFormat(null, 'formatOnly'); |
|
| 621 | - if(!preg_match('@^[0-9]+$@',$value)) $value = strtotime($value); |
|
| 622 | - if(strpos($opt,'%')!==false) |
|
| 623 | - return strftime($opt,0+$value); |
|
| 620 | + if (empty($opt)) $opt = $modx->toDateFormat(null, 'formatOnly'); |
|
| 621 | + if (!preg_match('@^[0-9]+$@', $value)) $value = strtotime($value); |
|
| 622 | + if (strpos($opt, '%') !== false) |
|
| 623 | + return strftime($opt, 0 + $value); |
|
| 624 | 624 | else |
| 625 | - return date($opt,0+$value); |
|
| 625 | + return date($opt, 0 + $value); |
|
| 626 | 626 | case 'time': |
| 627 | - if(empty($opt)) $opt = '%H:%M'; |
|
| 628 | - if(!preg_match('@^[0-9]+$@',$value)) $value = strtotime($value); |
|
| 629 | - return strftime($opt,0+$value); |
|
| 627 | + if (empty($opt)) $opt = '%H:%M'; |
|
| 628 | + if (!preg_match('@^[0-9]+$@', $value)) $value = strtotime($value); |
|
| 629 | + return strftime($opt, 0 + $value); |
|
| 630 | 630 | case 'strtotime': |
| 631 | 631 | return strtotime($value); |
| 632 | 632 | ##### mathematical function |
@@ -635,40 +635,40 @@ discard block |
||
| 635 | 635 | case 'tofloat': |
| 636 | 636 | return floatval($value); |
| 637 | 637 | case 'round': |
| 638 | - if(!$opt) $opt = 0; |
|
| 639 | - return $cmd($value,$opt); |
|
| 638 | + if (!$opt) $opt = 0; |
|
| 639 | + return $cmd($value, $opt); |
|
| 640 | 640 | case 'max': |
| 641 | 641 | case 'min': |
| 642 | - return $cmd(explode(',',$value)); |
|
| 642 | + return $cmd(explode(',', $value)); |
|
| 643 | 643 | case 'floor': |
| 644 | 644 | case 'ceil': |
| 645 | 645 | case 'abs': |
| 646 | 646 | return $cmd($value); |
| 647 | 647 | case 'math': |
| 648 | 648 | case 'calc': |
| 649 | - $value = (int)$value; |
|
| 650 | - if(empty($value)) $value = '0'; |
|
| 651 | - $filter = str_replace(array('[+value+]','[+output+]','{value}','%s'),'?',$opt); |
|
| 652 | - $filter = preg_replace('@([a-zA-Z\n\r\t\s])@','',$filter); |
|
| 653 | - if(strpos($filter,'?')===false) $filter = "?{$filter}"; |
|
| 654 | - $filter = str_replace('?',$value,$filter); |
|
| 649 | + $value = (int) $value; |
|
| 650 | + if (empty($value)) $value = '0'; |
|
| 651 | + $filter = str_replace(array('[+value+]', '[+output+]', '{value}', '%s'), '?', $opt); |
|
| 652 | + $filter = preg_replace('@([a-zA-Z\n\r\t\s])@', '', $filter); |
|
| 653 | + if (strpos($filter, '?') === false) $filter = "?{$filter}"; |
|
| 654 | + $filter = str_replace('?', $value, $filter); |
|
| 655 | 655 | return eval("return {$filter};"); |
| 656 | 656 | case 'count': |
| 657 | - if($value=='') return 0; |
|
| 658 | - $value = explode(',',$value); |
|
| 657 | + if ($value == '') return 0; |
|
| 658 | + $value = explode(',', $value); |
|
| 659 | 659 | return count($value); |
| 660 | 660 | case 'sort': |
| 661 | 661 | case 'rsort': |
| 662 | - if(strpos($value,"\n")!==false) $delim="\n"; |
|
| 662 | + if (strpos($value, "\n") !== false) $delim = "\n"; |
|
| 663 | 663 | else $delim = ','; |
| 664 | - $swap = explode($delim,$value); |
|
| 665 | - if(!$opt) $opt = SORT_REGULAR; |
|
| 664 | + $swap = explode($delim, $value); |
|
| 665 | + if (!$opt) $opt = SORT_REGULAR; |
|
| 666 | 666 | else $opt = constant($opt); |
| 667 | - $cmd($swap,$opt); |
|
| 668 | - return join($delim,$swap); |
|
| 667 | + $cmd($swap, $opt); |
|
| 668 | + return join($delim, $swap); |
|
| 669 | 669 | ##### Resource fields |
| 670 | 670 | case 'id': |
| 671 | - if($opt) return $this->getDocumentObject($opt,$key); |
|
| 671 | + if ($opt) return $this->getDocumentObject($opt, $key); |
|
| 672 | 672 | break; |
| 673 | 673 | case 'type': |
| 674 | 674 | case 'contenttype': |
@@ -705,36 +705,36 @@ discard block |
||
| 705 | 705 | case 'privatemgr': |
| 706 | 706 | case 'content_dispo': |
| 707 | 707 | case 'hidemenu': |
| 708 | - if($cmd==='contenttype') $cmd = 'contentType'; |
|
| 709 | - return $this->getDocumentObject($value,$cmd); |
|
| 708 | + if ($cmd === 'contenttype') $cmd = 'contentType'; |
|
| 709 | + return $this->getDocumentObject($value, $cmd); |
|
| 710 | 710 | case 'title': |
| 711 | - $pagetitle = $this->getDocumentObject($value,'pagetitle'); |
|
| 712 | - $longtitle = $this->getDocumentObject($value,'longtitle'); |
|
| 711 | + $pagetitle = $this->getDocumentObject($value, 'pagetitle'); |
|
| 712 | + $longtitle = $this->getDocumentObject($value, 'longtitle'); |
|
| 713 | 713 | return $longtitle ? $longtitle : $pagetitle; |
| 714 | 714 | case 'shorttitle': |
| 715 | - $pagetitle = $this->getDocumentObject($value,'pagetitle'); |
|
| 716 | - $menutitle = $this->getDocumentObject($value,'menutitle'); |
|
| 715 | + $pagetitle = $this->getDocumentObject($value, 'pagetitle'); |
|
| 716 | + $menutitle = $this->getDocumentObject($value, 'menutitle'); |
|
| 717 | 717 | return $menutitle ? $menutitle : $pagetitle; |
| 718 | 718 | case 'templatename': |
| 719 | - $rs = $modx->db->select('templatename','[+prefix+]site_templates',"id='{$value}'"); |
|
| 719 | + $rs = $modx->db->select('templatename', '[+prefix+]site_templates', "id='{$value}'"); |
|
| 720 | 720 | $templateName = $modx->db->getValue($rs); |
| 721 | 721 | return !$templateName ? '(blank)' : $templateName; |
| 722 | 722 | case 'getfield': |
| 723 | - if(!$opt) $opt = 'content'; |
|
| 724 | - return $modx->getField($opt,$value); |
|
| 723 | + if (!$opt) $opt = 'content'; |
|
| 724 | + return $modx->getField($opt, $value); |
|
| 725 | 725 | case 'children': |
| 726 | 726 | case 'childids': |
| 727 | - if($value=='') $value = 0; // 値がない場合はルートと見なす |
|
| 727 | + if ($value == '') $value = 0; // 値がない場合はルートと見なす |
|
| 728 | 728 | $published = 1; |
| 729 | - if($opt=='') $opt = 'page'; |
|
| 730 | - $_ = explode(',',$opt); |
|
| 729 | + if ($opt == '') $opt = 'page'; |
|
| 730 | + $_ = explode(',', $opt); |
|
| 731 | 731 | $where = array(); |
| 732 | - foreach($_ as $opt) { |
|
| 733 | - switch(trim($opt)) { |
|
| 732 | + foreach ($_ as $opt) { |
|
| 733 | + switch (trim($opt)) { |
|
| 734 | 734 | case 'page'; case '!folder'; case '!isfolder': $where[] = 'sc.isfolder=0'; break; |
| 735 | 735 | case 'folder'; case 'isfolder': $where[] = 'sc.isfolder=1'; break; |
| 736 | - case 'menu'; case 'show_menu': $where[] = 'sc.hidemenu=0'; break; |
|
| 737 | - case '!menu'; case '!show_menu': $where[] = 'sc.hidemenu=1'; break; |
|
| 736 | + case 'menu'; case 'show_menu': $where[] = 'sc.hidemenu=0'; break; |
|
| 737 | + case '!menu'; case '!show_menu': $where[] = 'sc.hidemenu=1'; break; |
|
| 738 | 738 | case 'published': $published = 1; break; |
| 739 | 739 | case '!published': $published = 0; break; |
| 740 | 740 | } |
@@ -742,69 +742,69 @@ discard block |
||
| 742 | 742 | $where = join(' AND ', $where); |
| 743 | 743 | $children = $modx->getDocumentChildren($value, $published, '0', 'id', $where); |
| 744 | 744 | $result = array(); |
| 745 | - foreach((array)$children as $child){ |
|
| 745 | + foreach ((array) $children as $child) { |
|
| 746 | 746 | $result[] = $child['id']; |
| 747 | 747 | } |
| 748 | 748 | return join(',', $result); |
| 749 | 749 | case 'fullurl': |
| 750 | - if(!is_numeric($value)) return $value; |
|
| 750 | + if (!is_numeric($value)) return $value; |
|
| 751 | 751 | return $modx->makeUrl($value); |
| 752 | 752 | case 'makeurl': |
| 753 | - if(!is_numeric($value)) return $value; |
|
| 754 | - if(!$opt) $opt = 'full'; |
|
| 755 | - return $modx->makeUrl($value,'','',$opt); |
|
| 753 | + if (!is_numeric($value)) return $value; |
|
| 754 | + if (!$opt) $opt = 'full'; |
|
| 755 | + return $modx->makeUrl($value, '', '', $opt); |
|
| 756 | 756 | |
| 757 | 757 | ##### File system |
| 758 | 758 | case 'getimageinfo': |
| 759 | 759 | case 'imageinfo': |
| 760 | - if(!is_file($value)) return ''; |
|
| 760 | + if (!is_file($value)) return ''; |
|
| 761 | 761 | $_ = getimagesize($value); |
| 762 | - if(!$_[0]) return ''; |
|
| 762 | + if (!$_[0]) return ''; |
|
| 763 | 763 | $info['width'] = $_[0]; |
| 764 | 764 | $info['height'] = $_[1]; |
| 765 | - if ($_[0] > $_[1]) $info['aspect'] = 'landscape'; |
|
| 766 | - elseif($_[0] < $_[1]) $info['aspect'] = 'portrait'; |
|
| 765 | + if ($_[0] > $_[1]) $info['aspect'] = 'landscape'; |
|
| 766 | + elseif ($_[0] < $_[1]) $info['aspect'] = 'portrait'; |
|
| 767 | 767 | else $info['aspect'] = 'square'; |
| 768 | - switch($_[2]) { |
|
| 768 | + switch ($_[2]) { |
|
| 769 | 769 | case IMAGETYPE_GIF : $info['type'] = 'gif'; break; |
| 770 | 770 | case IMAGETYPE_JPEG : $info['type'] = 'jpg'; break; |
| 771 | 771 | case IMAGETYPE_PNG : $info['type'] = 'png'; break; |
| 772 | 772 | default : $info['type'] = 'unknown'; |
| 773 | 773 | } |
| 774 | 774 | $info['attrib'] = $_[3]; |
| 775 | - switch($opt) { |
|
| 775 | + switch ($opt) { |
|
| 776 | 776 | case 'width' : return $info['width']; |
| 777 | 777 | case 'height': return $info['height']; |
| 778 | 778 | case 'aspect': return $info['aspect']; |
| 779 | 779 | case 'type' : return $info['type']; |
| 780 | 780 | case 'attrib': return $info['attrib']; |
| 781 | - default : return print_r($info,true); |
|
| 781 | + default : return print_r($info, true); |
|
| 782 | 782 | } |
| 783 | 783 | |
| 784 | 784 | case 'file_get_contents': |
| 785 | 785 | case 'readfile': |
| 786 | - if(!is_file($value)) return $value; |
|
| 786 | + if (!is_file($value)) return $value; |
|
| 787 | 787 | $value = realpath($value); |
| 788 | - if(strpos($value,MODX_MANAGER_PATH)!==false) exit('Can not read core file'); |
|
| 789 | - $ext = strtolower(substr($value,-4)); |
|
| 790 | - if($ext==='.php') exit('Can not read php file'); |
|
| 791 | - if($ext==='.cgi') exit('Can not read cgi file'); |
|
| 788 | + if (strpos($value, MODX_MANAGER_PATH) !== false) exit('Can not read core file'); |
|
| 789 | + $ext = strtolower(substr($value, -4)); |
|
| 790 | + if ($ext === '.php') exit('Can not read php file'); |
|
| 791 | + if ($ext === '.cgi') exit('Can not read cgi file'); |
|
| 792 | 792 | return file_get_contents($value); |
| 793 | 793 | case 'filesize': |
| 794 | - if($value == '') return ''; |
|
| 794 | + if ($value == '') return ''; |
|
| 795 | 795 | $filename = $value; |
| 796 | 796 | |
| 797 | 797 | $site_url = $modx->config['site_url']; |
| 798 | - if(strpos($filename,$site_url) === 0) |
|
| 799 | - $filename = substr($filename,0,strlen($site_url)); |
|
| 800 | - $filename = trim($filename,'/'); |
|
| 798 | + if (strpos($filename, $site_url) === 0) |
|
| 799 | + $filename = substr($filename, 0, strlen($site_url)); |
|
| 800 | + $filename = trim($filename, '/'); |
|
| 801 | 801 | |
| 802 | - $opt = trim($opt,'/'); |
|
| 803 | - if($opt!=='') $opt .= '/'; |
|
| 802 | + $opt = trim($opt, '/'); |
|
| 803 | + if ($opt !== '') $opt .= '/'; |
|
| 804 | 804 | |
| 805 | 805 | $filename = MODX_BASE_PATH.$opt.$filename; |
| 806 | 806 | |
| 807 | - if(is_file($filename)){ |
|
| 807 | + if (is_file($filename)) { |
|
| 808 | 808 | clearstatcache(); |
| 809 | 809 | $size = filesize($filename); |
| 810 | 810 | return $size; |
@@ -837,10 +837,10 @@ discard block |
||
| 837 | 837 | $this->opt = $cmd; |
| 838 | 838 | return $this->includeMdfFile('moduser'); |
| 839 | 839 | case 'userinfo': |
| 840 | - if(empty($opt)) $this->opt = 'username'; |
|
| 840 | + if (empty($opt)) $this->opt = 'username'; |
|
| 841 | 841 | return $this->includeMdfFile('moduser'); |
| 842 | 842 | case 'webuserinfo': |
| 843 | - if(empty($opt)) $this->opt = 'username'; |
|
| 843 | + if (empty($opt)) $this->opt = 'username'; |
|
| 844 | 844 | $this->value = -$value; |
| 845 | 845 | return $this->includeMdfFile('moduser'); |
| 846 | 846 | ##### Special functions |
@@ -851,28 +851,28 @@ discard block |
||
| 851 | 851 | case 'ifnotempty': |
| 852 | 852 | if (!empty($value)) return $opt; break; |
| 853 | 853 | case 'datagrid': |
| 854 | - include_once(MODX_CORE_PATH . 'controls/datagrid.class.php'); |
|
| 854 | + include_once(MODX_CORE_PATH.'controls/datagrid.class.php'); |
|
| 855 | 855 | $grd = new DataGrid(); |
| 856 | 856 | $grd->ds = trim($value); |
| 857 | 857 | $grd->itemStyle = ''; |
| 858 | 858 | $grd->altItemStyle = ''; |
| 859 | - $pos = strpos($value,"\n"); |
|
| 860 | - if($pos) $_ = substr($value,0,$pos); |
|
| 859 | + $pos = strpos($value, "\n"); |
|
| 860 | + if ($pos) $_ = substr($value, 0, $pos); |
|
| 861 | 861 | else $_ = $pos; |
| 862 | - $grd->cdelim = strpos($_,"\t")!==false ? 'tab' : ','; |
|
| 862 | + $grd->cdelim = strpos($_, "\t") !== false ? 'tab' : ','; |
|
| 863 | 863 | return $grd->render(); |
| 864 | 864 | case 'rotate': |
| 865 | 865 | case 'evenodd': |
| 866 | - if(strpos($opt,',')===false) $opt = 'odd,even'; |
|
| 866 | + if (strpos($opt, ',') === false) $opt = 'odd,even'; |
|
| 867 | 867 | $_ = explode(',', $opt); |
| 868 | 868 | $c = count($_); |
| 869 | 869 | $i = $value + $c; |
| 870 | 870 | $i = $i % $c; |
| 871 | 871 | return $_[$i]; |
| 872 | 872 | case 'takeval': |
| 873 | - $arr = explode(",",$opt); |
|
| 873 | + $arr = explode(",", $opt); |
|
| 874 | 874 | $idx = $value; |
| 875 | - if(!is_numeric($idx)) return $value; |
|
| 875 | + if (!is_numeric($idx)) return $value; |
|
| 876 | 876 | return $arr[$idx]; |
| 877 | 877 | case 'getimage': |
| 878 | 878 | return $this->includeMdfFile('getimage'); |
@@ -880,17 +880,17 @@ discard block |
||
| 880 | 880 | return $modx->nicesize($value); |
| 881 | 881 | case 'googlemap': |
| 882 | 882 | case 'googlemaps': |
| 883 | - if(empty($opt)) $opt = 'border:none;width:500px;height:350px;'; |
|
| 883 | + if (empty($opt)) $opt = 'border:none;width:500px;height:350px;'; |
|
| 884 | 884 | $tpl = '<iframe style="[+style+]" src="https://maps.google.co.jp/maps?ll=[+value+]&output=embed&z=15"></iframe>'; |
| 885 | 885 | $ph['style'] = $opt; |
| 886 | 886 | $ph['value'] = $value; |
| 887 | - return $modx->parseText($tpl,$ph); |
|
| 887 | + return $modx->parseText($tpl, $ph); |
|
| 888 | 888 | case 'youtube': |
| 889 | 889 | case 'youtube16x9': |
| 890 | - if(empty($opt)) $opt = 560; |
|
| 891 | - $h = round($opt*0.5625); |
|
| 890 | + if (empty($opt)) $opt = 560; |
|
| 891 | + $h = round($opt * 0.5625); |
|
| 892 | 892 | $tpl = '<iframe width="%s" height="%s" src="https://www.youtube.com/embed/%s" frameborder="0" allowfullscreen></iframe>'; |
| 893 | - return sprintf($tpl,$opt,$h,$value); |
|
| 893 | + return sprintf($tpl, $opt, $h, $value); |
|
| 894 | 894 | //case 'youtube4x3':%s*0.75+25 |
| 895 | 895 | case 'setvar': |
| 896 | 896 | $modx->placeholders[$opt] = $value; |
@@ -920,7 +920,7 @@ discard block |
||
| 920 | 920 | return $value; |
| 921 | 921 | } |
| 922 | 922 | |
| 923 | - function includeMdfFile($cmd) { |
|
| 923 | + function includeMdfFile($cmd){ |
|
| 924 | 924 | global $modx; |
| 925 | 925 | $key = $this->key; |
| 926 | 926 | $value = $this->value; |
@@ -931,54 +931,54 @@ discard block |
||
| 931 | 931 | function getValueFromElement($key, $value, $cmd, $opt) |
| 932 | 932 | { |
| 933 | 933 | global $modx; |
| 934 | - if( isset($modx->snippetCache[$this->elmName]) ) |
|
| 934 | + if (isset($modx->snippetCache[$this->elmName])) |
|
| 935 | 935 | { |
| 936 | 936 | $php = $modx->snippetCache[$this->elmName]; |
| 937 | 937 | } |
| 938 | 938 | else |
| 939 | 939 | { |
| 940 | 940 | $esc_elmName = $modx->db->escape($this->elmName); |
| 941 | - $result = $modx->db->select('snippet','[+prefix+]site_snippets',"name='{$esc_elmName}'"); |
|
| 941 | + $result = $modx->db->select('snippet', '[+prefix+]site_snippets', "name='{$esc_elmName}'"); |
|
| 942 | 942 | $total = $modx->db->getRecordCount($result); |
| 943 | - if($total == 1) |
|
| 943 | + if ($total == 1) |
|
| 944 | 944 | { |
| 945 | 945 | $row = $modx->db->getRow($result); |
| 946 | 946 | $php = $row['snippet']; |
| 947 | 947 | } |
| 948 | - elseif($total == 0) |
|
| 948 | + elseif ($total == 0) |
|
| 949 | 949 | { |
| 950 | 950 | $assets_path = MODX_BASE_PATH.'assets/'; |
| 951 | - if(is_file($assets_path."modifiers/mdf_{$cmd}.inc.php")) |
|
| 951 | + if (is_file($assets_path."modifiers/mdf_{$cmd}.inc.php")) |
|
| 952 | 952 | $modifiers_path = $assets_path."modifiers/mdf_{$cmd}.inc.php"; |
| 953 | - elseif(is_file($assets_path."plugins/phx/modifiers/{$cmd}.phx.php")) |
|
| 953 | + elseif (is_file($assets_path."plugins/phx/modifiers/{$cmd}.phx.php")) |
|
| 954 | 954 | $modifiers_path = $assets_path."plugins/phx/modifiers/{$cmd}.phx.php"; |
| 955 | - elseif(is_file(MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php")) |
|
| 955 | + elseif (is_file(MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php")) |
|
| 956 | 956 | $modifiers_path = MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php"; |
| 957 | 957 | else $modifiers_path = false; |
| 958 | 958 | |
| 959 | - if($modifiers_path) { |
|
| 959 | + if ($modifiers_path) { |
|
| 960 | 960 | $php = @file_get_contents($modifiers_path); |
| 961 | 961 | $php = trim($php); |
| 962 | - if(substr($php,0,5)==='<?php') $php = substr($php,6); |
|
| 963 | - if(substr($php,0,2)==='<?') $php = substr($php,3); |
|
| 964 | - if(substr($php,-2)==='?>') $php = substr($php,0,-2); |
|
| 965 | - if($this->elmName!=='') |
|
| 962 | + if (substr($php, 0, 5) === '<?php') $php = substr($php, 6); |
|
| 963 | + if (substr($php, 0, 2) === '<?') $php = substr($php, 3); |
|
| 964 | + if (substr($php, -2) === '?>') $php = substr($php, 0, -2); |
|
| 965 | + if ($this->elmName !== '') |
|
| 966 | 966 | $modx->snippetCache[$this->elmName.'Props'] = ''; |
| 967 | 967 | } |
| 968 | 968 | else |
| 969 | 969 | $php = false; |
| 970 | 970 | } |
| 971 | 971 | else $php = false; |
| 972 | - if($this->elmName!=='') $modx->snippetCache[$this->elmName]= $php; |
|
| 972 | + if ($this->elmName !== '') $modx->snippetCache[$this->elmName] = $php; |
|
| 973 | 973 | } |
| 974 | - if($php==='') $php=false; |
|
| 974 | + if ($php === '') $php = false; |
|
| 975 | 975 | |
| 976 | - if($php===false) $html = $modx->getChunk($this->elmName); |
|
| 976 | + if ($php === false) $html = $modx->getChunk($this->elmName); |
|
| 977 | 977 | else $html = false; |
| 978 | 978 | |
| 979 | 979 | $self = '[+output+]'; |
| 980 | 980 | |
| 981 | - if($php !== false) |
|
| 981 | + if ($php !== false) |
|
| 982 | 982 | { |
| 983 | 983 | ob_start(); |
| 984 | 984 | $options = $opt; |
@@ -991,71 +991,71 @@ discard block |
||
| 991 | 991 | $this->vars['options'] = & $opt; |
| 992 | 992 | $custom = eval($php); |
| 993 | 993 | $msg = ob_get_contents(); |
| 994 | - if($value===$this->bt) $value = $msg . $custom; |
|
| 994 | + if ($value === $this->bt) $value = $msg.$custom; |
|
| 995 | 995 | ob_end_clean(); |
| 996 | 996 | } |
| 997 | - elseif($html!==false && isset($value) && $value!=='') |
|
| 997 | + elseif ($html !== false && isset($value) && $value !== '') |
|
| 998 | 998 | { |
| 999 | - $html = str_replace(array($self,'[+value+]'), $value, $html); |
|
| 1000 | - $value = str_replace(array('[+options+]','[+param+]'), $opt, $html); |
|
| 999 | + $html = str_replace(array($self, '[+value+]'), $value, $html); |
|
| 1000 | + $value = str_replace(array('[+options+]', '[+param+]'), $opt, $html); |
|
| 1001 | 1001 | } |
| 1002 | 1002 | else return false; |
| 1003 | 1003 | |
| 1004 | - if($php===false && $html===false && $value!=='' |
|
| 1005 | - && (strpos($cmd,'[+value+]')!==false || strpos($cmd,$self)!==false)) |
|
| 1004 | + if ($php === false && $html === false && $value !== '' |
|
| 1005 | + && (strpos($cmd, '[+value+]') !== false || strpos($cmd, $self) !== false)) |
|
| 1006 | 1006 | { |
| 1007 | - $value = str_replace(array('[+value+]',$self),$value,$cmd); |
|
| 1007 | + $value = str_replace(array('[+value+]', $self), $value, $cmd); |
|
| 1008 | 1008 | } |
| 1009 | 1009 | return $value; |
| 1010 | 1010 | } |
| 1011 | 1011 | |
| 1012 | - function parseDocumentSource($content='') |
|
| 1012 | + function parseDocumentSource($content = '') |
|
| 1013 | 1013 | { |
| 1014 | 1014 | global $modx; |
| 1015 | 1015 | |
| 1016 | - if(strpos($content,'[')===false && strpos($content,'{')===false) return $content; |
|
| 1016 | + if (strpos($content, '[') === false && strpos($content, '{') === false) return $content; |
|
| 1017 | 1017 | |
| 1018 | - if(!$modx->maxParserPasses) $modx->maxParserPasses = 10; |
|
| 1019 | - $bt=''; |
|
| 1020 | - $i=0; |
|
| 1021 | - while($bt!==$content) |
|
| 1018 | + if (!$modx->maxParserPasses) $modx->maxParserPasses = 10; |
|
| 1019 | + $bt = ''; |
|
| 1020 | + $i = 0; |
|
| 1021 | + while ($bt !== $content) |
|
| 1022 | 1022 | { |
| 1023 | 1023 | $bt = $content; |
| 1024 | - if(strpos($content,'[*')!==false && $modx->documentIdentifier) |
|
| 1024 | + if (strpos($content, '[*') !== false && $modx->documentIdentifier) |
|
| 1025 | 1025 | $content = $modx->mergeDocumentContent($content); |
| 1026 | - if(strpos($content,'[(')!==false) $content = $modx->mergeSettingsContent($content); |
|
| 1027 | - if(strpos($content,'{{')!==false) $content = $modx->mergeChunkContent($content); |
|
| 1028 | - if(strpos($content,'[!')!==false) $content = str_replace(array('[!','!]'),array('[[',']]'),$content); |
|
| 1029 | - if(strpos($content,'[[')!==false) $content = $modx->evalSnippets($content); |
|
| 1026 | + if (strpos($content, '[(') !== false) $content = $modx->mergeSettingsContent($content); |
|
| 1027 | + if (strpos($content, '{{') !== false) $content = $modx->mergeChunkContent($content); |
|
| 1028 | + if (strpos($content, '[!') !== false) $content = str_replace(array('[!', '!]'), array('[[', ']]'), $content); |
|
| 1029 | + if (strpos($content, '[[') !== false) $content = $modx->evalSnippets($content); |
|
| 1030 | 1030 | |
| 1031 | - if($content===$bt) break; |
|
| 1032 | - if($modx->maxParserPasses < $i) break; |
|
| 1031 | + if ($content === $bt) break; |
|
| 1032 | + if ($modx->maxParserPasses < $i) break; |
|
| 1033 | 1033 | $i++; |
| 1034 | 1034 | } |
| 1035 | 1035 | return $content; |
| 1036 | 1036 | } |
| 1037 | 1037 | |
| 1038 | - function getDocumentObject($target='',$field='pagetitle') |
|
| 1038 | + function getDocumentObject($target = '', $field = 'pagetitle') |
|
| 1039 | 1039 | { |
| 1040 | 1040 | global $modx; |
| 1041 | 1041 | |
| 1042 | 1042 | $target = trim($target); |
| 1043 | - if(empty($target)) $target = $modx->config['site_start']; |
|
| 1044 | - if(preg_match('@^[1-9][0-9]*$@',$target)) $method='id'; |
|
| 1043 | + if (empty($target)) $target = $modx->config['site_start']; |
|
| 1044 | + if (preg_match('@^[1-9][0-9]*$@', $target)) $method = 'id'; |
|
| 1045 | 1045 | else $method = 'alias'; |
| 1046 | 1046 | |
| 1047 | - if(!isset($this->documentObject[$target])) |
|
| 1047 | + if (!isset($this->documentObject[$target])) |
|
| 1048 | 1048 | { |
| 1049 | - $this->documentObject[$target] = $modx->getDocumentObject($method,$target,'direct'); |
|
| 1049 | + $this->documentObject[$target] = $modx->getDocumentObject($method, $target, 'direct'); |
|
| 1050 | 1050 | } |
| 1051 | 1051 | |
| 1052 | - if($this->documentObject[$target]['publishedon']==='0') |
|
| 1052 | + if ($this->documentObject[$target]['publishedon'] === '0') |
|
| 1053 | 1053 | return ''; |
| 1054 | - elseif(isset($this->documentObject[$target][$field])) |
|
| 1054 | + elseif (isset($this->documentObject[$target][$field])) |
|
| 1055 | 1055 | { |
| 1056 | - if(is_array($this->documentObject[$target][$field])) |
|
| 1056 | + if (is_array($this->documentObject[$target][$field])) |
|
| 1057 | 1057 | { |
| 1058 | - $a = $modx->getTemplateVarOutput($field,$target); |
|
| 1058 | + $a = $modx->getTemplateVarOutput($field, $target); |
|
| 1059 | 1059 | $this->documentObject[$target][$field] = $a[$field]; |
| 1060 | 1060 | } |
| 1061 | 1061 | } |
@@ -1064,8 +1064,8 @@ discard block |
||
| 1064 | 1064 | return $this->documentObject[$target][$field]; |
| 1065 | 1065 | } |
| 1066 | 1066 | |
| 1067 | - function setPlaceholders($value = '', $key = '', $path = '') { |
|
| 1068 | - if($path!=='') $key = "{$path}.{$key}"; |
|
| 1067 | + function setPlaceholders($value = '', $key = '', $path = ''){ |
|
| 1068 | + if ($path !== '') $key = "{$path}.{$key}"; |
|
| 1069 | 1069 | if (is_array($value)) { |
| 1070 | 1070 | foreach ($value as $subkey => $subval) { |
| 1071 | 1071 | $this->setPlaceholders($subval, $subkey, $key); |
@@ -1075,77 +1075,77 @@ discard block |
||
| 1075 | 1075 | } |
| 1076 | 1076 | |
| 1077 | 1077 | // Sets a placeholder variable which can only be access by Modifiers |
| 1078 | - function setModifiersVariable($key, $value) { |
|
| 1078 | + function setModifiersVariable($key, $value){ |
|
| 1079 | 1079 | if ($key != 'phx' && $key != 'dummy') $this->placeholders[$key] = $value; |
| 1080 | 1080 | } |
| 1081 | 1081 | |
| 1082 | 1082 | //mbstring |
| 1083 | - function substr($str, $s, $l = null) { |
|
| 1083 | + function substr($str, $s, $l = null){ |
|
| 1084 | 1084 | global $modx; |
| 1085 | - if(is_null($l)) $l = $this->strlen($str); |
|
| 1085 | + if (is_null($l)) $l = $this->strlen($str); |
|
| 1086 | 1086 | if (function_exists('mb_substr')) |
| 1087 | 1087 | { |
| 1088 | - if(strpos($str,"\r")!==false) |
|
| 1089 | - $str = str_replace(array("\r\n","\r"), "\n", $str); |
|
| 1088 | + if (strpos($str, "\r") !== false) |
|
| 1089 | + $str = str_replace(array("\r\n", "\r"), "\n", $str); |
|
| 1090 | 1090 | return mb_substr($str, $s, $l, $modx->config['modx_charset']); |
| 1091 | 1091 | } |
| 1092 | 1092 | return substr($str, $s, $l); |
| 1093 | 1093 | } |
| 1094 | - function strpos($haystack,$needle,$offset=0) { |
|
| 1094 | + function strpos($haystack, $needle, $offset = 0){ |
|
| 1095 | 1095 | global $modx; |
| 1096 | - if (function_exists('mb_strpos')) return mb_strpos($haystack,$needle,$offset,$modx->config['modx_charset']); |
|
| 1097 | - return strpos($haystack,$needle,$offset); |
|
| 1096 | + if (function_exists('mb_strpos')) return mb_strpos($haystack, $needle, $offset, $modx->config['modx_charset']); |
|
| 1097 | + return strpos($haystack, $needle, $offset); |
|
| 1098 | 1098 | } |
| 1099 | - function strlen($str) { |
|
| 1099 | + function strlen($str){ |
|
| 1100 | 1100 | global $modx; |
| 1101 | - if (function_exists('mb_strlen')) return mb_strlen(str_replace("\r\n", "\n", $str),$modx->config['modx_charset']); |
|
| 1101 | + if (function_exists('mb_strlen')) return mb_strlen(str_replace("\r\n", "\n", $str), $modx->config['modx_charset']); |
|
| 1102 | 1102 | return strlen($str); |
| 1103 | 1103 | } |
| 1104 | - function strtolower($str) { |
|
| 1104 | + function strtolower($str){ |
|
| 1105 | 1105 | if (function_exists('mb_strtolower')) return mb_strtolower($str); |
| 1106 | 1106 | return strtolower($str); |
| 1107 | 1107 | } |
| 1108 | - function strtoupper($str) { |
|
| 1108 | + function strtoupper($str){ |
|
| 1109 | 1109 | if (function_exists('mb_strtoupper')) return mb_strtoupper($str); |
| 1110 | 1110 | return strtoupper($str); |
| 1111 | 1111 | } |
| 1112 | - function ucfirst($str) { |
|
| 1112 | + function ucfirst($str){ |
|
| 1113 | 1113 | if (function_exists('mb_strtoupper')) |
| 1114 | 1114 | return mb_strtoupper($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str)); |
| 1115 | 1115 | return ucfirst($str); |
| 1116 | 1116 | } |
| 1117 | - function lcfirst($str) { |
|
| 1117 | + function lcfirst($str){ |
|
| 1118 | 1118 | if (function_exists('mb_strtolower')) |
| 1119 | 1119 | return mb_strtolower($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str)); |
| 1120 | 1120 | return lcfirst($str); |
| 1121 | 1121 | } |
| 1122 | - function ucwords($str) { |
|
| 1122 | + function ucwords($str){ |
|
| 1123 | 1123 | if (function_exists('mb_convert_case')) |
| 1124 | 1124 | return mb_convert_case($str, MB_CASE_TITLE); |
| 1125 | 1125 | return ucwords($str); |
| 1126 | 1126 | } |
| 1127 | - function strrev($str) { |
|
| 1127 | + function strrev($str){ |
|
| 1128 | 1128 | preg_match_all('/./us', $str, $ar); |
| 1129 | 1129 | return join(array_reverse($ar[0])); |
| 1130 | 1130 | } |
| 1131 | - function str_shuffle($str) { |
|
| 1131 | + function str_shuffle($str){ |
|
| 1132 | 1132 | preg_match_all('/./us', $str, $ar); |
| 1133 | 1133 | shuffle($ar[0]); |
| 1134 | 1134 | return join($ar[0]); |
| 1135 | 1135 | } |
| 1136 | - function str_word_count($str) { |
|
| 1137 | - return count(preg_split('~[^\p{L}\p{N}\']+~u',$str)); |
|
| 1136 | + function str_word_count($str){ |
|
| 1137 | + return count(preg_split('~[^\p{L}\p{N}\']+~u', $str)); |
|
| 1138 | 1138 | } |
| 1139 | - function strip_tags($value,$params='') { |
|
| 1139 | + function strip_tags($value, $params = ''){ |
|
| 1140 | 1140 | global $modx; |
| 1141 | 1141 | |
| 1142 | - if(stripos($params,'style')===false && stripos($value,'</style>')!==false) { |
|
| 1142 | + if (stripos($params, 'style') === false && stripos($value, '</style>') !== false) { |
|
| 1143 | 1143 | $value = preg_replace('@<style.*?>.*?</style>@is', '', $value); |
| 1144 | 1144 | } |
| 1145 | - if(stripos($params,'script')===false && stripos($value,'</script>')!==false) { |
|
| 1145 | + if (stripos($params, 'script') === false && stripos($value, '</script>') !== false) { |
|
| 1146 | 1146 | $value = preg_replace('@<script.*?>.*?</script>@is', '', $value); |
| 1147 | 1147 | } |
| 1148 | 1148 | |
| 1149 | - return trim(strip_tags($value,$params)); |
|
| 1149 | + return trim(strip_tags($value, $params)); |
|
| 1150 | 1150 | } |
| 1151 | 1151 | } |
@@ -6,9 +6,9 @@ |
||
| 6 | 6 | * Time: 14:17 |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -if (!include_once(MODX_MANAGER_PATH . 'includes/extenders/modxmailer.class.inc.php')){ |
|
| 9 | +if (!include_once(MODX_MANAGER_PATH.'includes/extenders/modxmailer.class.inc.php')) { |
|
| 10 | 10 | return false; |
| 11 | -}else{ |
|
| 11 | +} else { |
|
| 12 | 12 | $this->mail = new MODxMailer; |
| 13 | 13 | $this->mail->init($this); |
| 14 | 14 | return true; |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if( ! function_exists('f_owc')){ |
|
| 2 | +if (!function_exists('f_owc')) { |
|
| 3 | 3 | /** |
| 4 | 4 | * @param $path |
| 5 | 5 | * @param $data |
@@ -12,30 +12,30 @@ discard block |
||
| 12 | 12 | fwrite($hnd, $data); |
| 13 | 13 | fclose($hnd); |
| 14 | 14 | |
| 15 | - if(null !== $mode) chmod($path, $mode); |
|
| 16 | - }catch(Exception $e){ |
|
| 15 | + if (null !== $mode) chmod($path, $mode); |
|
| 16 | + } catch (Exception $e) { |
|
| 17 | 17 | // Nothing, this is NOT normal |
| 18 | 18 | unset($e); |
| 19 | 19 | } |
| 20 | 20 | } |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | -$installMode = isset($_POST['installmode']) ? (int)$_POST['installmode'] : 0; |
|
| 24 | -if( ! isset($_lang)) $_lang = array(); |
|
| 23 | +$installMode = isset($_POST['installmode']) ? (int) $_POST['installmode'] : 0; |
|
| 24 | +if (!isset($_lang)) $_lang = array(); |
|
| 25 | 25 | |
| 26 | 26 | echo '<div class="stepcontainer"> |
| 27 | 27 | <ul class="progressbar"> |
| 28 | - <li class="visited">' . $_lang['choose_language'] . '</li> |
|
| 29 | - <li class="visited">' . $_lang['installation_mode'] . '</li> |
|
| 30 | - <li class="visited">' . $_lang['optional_items'] . '</li> |
|
| 31 | - <li class="active">' . $_lang['preinstall_validation'] . '</li> |
|
| 32 | - <li>' . $_lang['install_results'] . '</li> |
|
| 28 | + <li class="visited">' . $_lang['choose_language'].'</li> |
|
| 29 | + <li class="visited">' . $_lang['installation_mode'].'</li> |
|
| 30 | + <li class="visited">' . $_lang['optional_items'].'</li> |
|
| 31 | + <li class="active">' . $_lang['preinstall_validation'].'</li> |
|
| 32 | + <li>' . $_lang['install_results'].'</li> |
|
| 33 | 33 | </ul> |
| 34 | 34 | <div class="clearleft"></div> |
| 35 | 35 | </div>'; |
| 36 | 36 | |
| 37 | -echo '<h2>' . $_lang['preinstall_validation'] . '</h2>'; |
|
| 38 | -echo '<h3>' . $_lang['summary_setup_check'] . '</h3>'; |
|
| 37 | +echo '<h2>'.$_lang['preinstall_validation'].'</h2>'; |
|
| 38 | +echo '<h3>'.$_lang['summary_setup_check'].'</h3>'; |
|
| 39 | 39 | |
| 40 | 40 | $errors = 0; |
| 41 | 41 | |
@@ -43,73 +43,73 @@ discard block |
||
| 43 | 43 | // check PHP version |
| 44 | 44 | define('PHP_MIN_VERSION', '5.4.0'); |
| 45 | 45 | $phpMinVersion = PHP_MIN_VERSION; // Maybe not necessary. For backward compatibility |
| 46 | -echo '<p>' . $_lang['checking_php_version']; |
|
| 46 | +echo '<p>'.$_lang['checking_php_version']; |
|
| 47 | 47 | // -1 if left is less, 0 if equal, +1 if left is higher |
| 48 | 48 | if (version_compare(phpversion(), PHP_MIN_VERSION) < 0) { |
| 49 | 49 | $errors++; |
| 50 | - $tmp = $_lang['you_running_php'] . phpversion() . str_replace('[+min_version+]', PHP_MIN_VERSION, $_lang["modx_requires_php"]); |
|
| 51 | - echo '<span class="notok">' . $_lang['failed'] . '</span>' . $tmp . '</p>'; |
|
| 50 | + $tmp = $_lang['you_running_php'].phpversion().str_replace('[+min_version+]', PHP_MIN_VERSION, $_lang["modx_requires_php"]); |
|
| 51 | + echo '<span class="notok">'.$_lang['failed'].'</span>'.$tmp.'</p>'; |
|
| 52 | 52 | } else { |
| 53 | - echo '<span class="ok">' . $_lang['ok'] . '</span></p>'; |
|
| 53 | + echo '<span class="ok">'.$_lang['ok'].'</span></p>'; |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | |
| 57 | 57 | // check if iconv is available |
| 58 | -echo '<p>' . $_lang['checking_iconv']; |
|
| 58 | +echo '<p>'.$_lang['checking_iconv']; |
|
| 59 | 59 | $iconv = (int) function_exists('iconv'); |
| 60 | -if ($iconv == '0'){ |
|
| 61 | - echo '<span class="notok">' . $_lang['failed'].'</span></p><p><strong>'.$_lang['checking_iconv_note'].'</strong></p>'; |
|
| 60 | +if ($iconv == '0') { |
|
| 61 | + echo '<span class="notok">'.$_lang['failed'].'</span></p><p><strong>'.$_lang['checking_iconv_note'].'</strong></p>'; |
|
| 62 | 62 | $errors++; |
| 63 | 63 | } else { |
| 64 | - echo '<span class="ok">' . $_lang['ok'] . '</span></p>'; |
|
| 64 | + echo '<span class="ok">'.$_lang['ok'].'</span></p>'; |
|
| 65 | 65 | } |
| 66 | 66 | // check sessions |
| 67 | -echo '<p>' . $_lang['checking_sessions']; |
|
| 67 | +echo '<p>'.$_lang['checking_sessions']; |
|
| 68 | 68 | if ($_SESSION['test'] != 1) { |
| 69 | - echo '<span class="notok">' . $_lang['failed']. '</span></p>'; |
|
| 69 | + echo '<span class="notok">'.$_lang['failed'].'</span></p>'; |
|
| 70 | 70 | $errors++; |
| 71 | 71 | } else { |
| 72 | - echo '<span class="ok">' . $_lang['ok'] . '</span></p>'; |
|
| 72 | + echo '<span class="ok">'.$_lang['ok'].'</span></p>'; |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | |
| 76 | 76 | // check directories |
| 77 | 77 | // cache exists? |
| 78 | -echo '<p>' . $_lang['checking_if_cache_exist']; |
|
| 78 | +echo '<p>'.$_lang['checking_if_cache_exist']; |
|
| 79 | 79 | if (!file_exists("../assets/cache") || !file_exists("../assets/cache/rss")) { |
| 80 | - echo '<span class="notok">' . $_lang['failed'] . '</span></p>'; |
|
| 80 | + echo '<span class="notok">'.$_lang['failed'].'</span></p>'; |
|
| 81 | 81 | $errors++; |
| 82 | 82 | } else { |
| 83 | - echo '<span class="ok">' . $_lang['ok'] . '</span></p>'; |
|
| 83 | + echo '<span class="ok">'.$_lang['ok'].'</span></p>'; |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | |
| 87 | 87 | // cache writable? |
| 88 | -echo '<p>' . $_lang['checking_if_cache_writable']; |
|
| 88 | +echo '<p>'.$_lang['checking_if_cache_writable']; |
|
| 89 | 89 | if (!is_writable("../assets/cache")) { |
| 90 | 90 | $errors++; |
| 91 | - echo '<span class="notok">' . $_lang['failed'] . '</span></p>'; |
|
| 91 | + echo '<span class="notok">'.$_lang['failed'].'</span></p>'; |
|
| 92 | 92 | } else { |
| 93 | - echo '<span class="ok">' . $_lang['ok'] . '</span></p>'; |
|
| 93 | + echo '<span class="ok">'.$_lang['ok'].'</span></p>'; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | |
| 97 | 97 | // cache files writable? |
| 98 | -echo '<p>' . $_lang['checking_if_cache_file_writable']; |
|
| 98 | +echo '<p>'.$_lang['checking_if_cache_file_writable']; |
|
| 99 | 99 | $tmp = "../assets/cache/siteCache.idx.php"; |
| 100 | -if ( ! file_exists($tmp)) { |
|
| 100 | +if (!file_exists($tmp)) { |
|
| 101 | 101 | f_owc($tmp, "<?php //EVO site cache file ?>"); |
| 102 | 102 | } |
| 103 | -if ( ! is_writable($tmp)) { |
|
| 103 | +if (!is_writable($tmp)) { |
|
| 104 | 104 | $errors++; |
| 105 | - echo '<span class="notok">' . $_lang['failed'] . '</span></p>'; |
|
| 105 | + echo '<span class="notok">'.$_lang['failed'].'</span></p>'; |
|
| 106 | 106 | } else { |
| 107 | 107 | echo '<span class="ok">'.$_lang['ok'].'</span></p>'; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | |
| 111 | 111 | echo '<p>'.$_lang['checking_if_cache_file2_writable']; |
| 112 | -if ( ! is_writable("../assets/cache/sitePublishing.idx.php")) { |
|
| 112 | +if (!is_writable("../assets/cache/sitePublishing.idx.php")) { |
|
| 113 | 113 | $errors++; |
| 114 | 114 | echo '<span class="notok">'.$_lang['failed'].'</span></p>'; |
| 115 | 115 | } else { |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | |
| 120 | 120 | // File Browser directories exists? |
| 121 | 121 | echo '<p>'.$_lang['checking_if_images_exist']; |
| 122 | -switch(true){ |
|
| 122 | +switch (true) { |
|
| 123 | 123 | case !file_exists("../assets/images"): |
| 124 | 124 | case !file_exists("../assets/files"): |
| 125 | 125 | case !file_exists("../assets/backup"): |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | |
| 135 | 135 | // File Browser directories writable? |
| 136 | 136 | echo '<p>'.$_lang['checking_if_images_writable']; |
| 137 | -switch(true){ |
|
| 137 | +switch (true) { |
|
| 138 | 138 | case !is_writable("../assets/images"): |
| 139 | 139 | case !is_writable("../assets/files"): |
| 140 | 140 | case !is_writable("../assets/backup"): |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | $database_charset = substr($database_collation, 0, strpos($database_collation, '_') - 1); |
| 195 | 195 | $database_connection_charset = $_POST['database_connection_charset']; |
| 196 | 196 | $database_connection_method = $_POST['database_connection_method']; |
| 197 | - $dbase = '`' . $_POST['database_name'] . '`'; |
|
| 197 | + $dbase = '`'.$_POST['database_name'].'`'; |
|
| 198 | 198 | $table_prefix = $_POST['tableprefix']; |
| 199 | 199 | } |
| 200 | 200 | echo '<p>'.$_lang['creating_database_connection']; |
@@ -234,54 +234,54 @@ discard block |
||
| 234 | 234 | |
| 235 | 235 | // check table prefix |
| 236 | 236 | if ($conn && $installMode == 0) { |
| 237 | - echo '<p>' . $_lang['checking_table_prefix'] . $table_prefix . '`: '; |
|
| 238 | - if ($rs= mysqli_query($conn, "SELECT COUNT(*) FROM $dbase.`" . $table_prefix . "site_content`")) { |
|
| 239 | - echo '<span class="notok">' . $_lang['failed'] . '</span></b>' . $_lang['table_prefix_already_inuse'] . '</p>'; |
|
| 237 | + echo '<p>'.$_lang['checking_table_prefix'].$table_prefix.'`: '; |
|
| 238 | + if ($rs = mysqli_query($conn, "SELECT COUNT(*) FROM $dbase.`".$table_prefix."site_content`")) { |
|
| 239 | + echo '<span class="notok">'.$_lang['failed'].'</span></b>'.$_lang['table_prefix_already_inuse'].'</p>'; |
|
| 240 | 240 | $errors++; |
| 241 | - echo "<p>" . $_lang['table_prefix_already_inuse_note'] . '</p>'; |
|
| 241 | + echo "<p>".$_lang['table_prefix_already_inuse_note'].'</p>'; |
|
| 242 | 242 | } else { |
| 243 | - echo '<span class="ok">' . $_lang['ok'] . '</span></p>'; |
|
| 243 | + echo '<span class="ok">'.$_lang['ok'].'</span></p>'; |
|
| 244 | 244 | } |
| 245 | 245 | } elseif ($conn && $installMode == 2) { |
| 246 | - echo '<p>' . $_lang['checking_table_prefix'] . $table_prefix . '`: '; |
|
| 247 | - if (!$rs = mysqli_query($conn, "SELECT COUNT(*) FROM $dbase.`" . $table_prefix . "site_content`")) { |
|
| 248 | - echo '<span class="notok">' . $_lang['failed'] . '</span></b>' . $_lang['table_prefix_not_exist'] . '</p>'; |
|
| 246 | + echo '<p>'.$_lang['checking_table_prefix'].$table_prefix.'`: '; |
|
| 247 | + if (!$rs = mysqli_query($conn, "SELECT COUNT(*) FROM $dbase.`".$table_prefix."site_content`")) { |
|
| 248 | + echo '<span class="notok">'.$_lang['failed'].'</span></b>'.$_lang['table_prefix_not_exist'].'</p>'; |
|
| 249 | 249 | $errors++; |
| 250 | - echo '<p>' . $_lang['table_prefix_not_exist_note'] . '</p>'; |
|
| 250 | + echo '<p>'.$_lang['table_prefix_not_exist_note'].'</p>'; |
|
| 251 | 251 | } else { |
| 252 | - echo '<span class="ok">' . $_lang['ok'] . '</span></p>'; |
|
| 252 | + echo '<span class="ok">'.$_lang['ok'].'</span></p>'; |
|
| 253 | 253 | } |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | // check mysql version |
| 257 | 257 | if ($conn) { |
| 258 | - echo '<p>' . $_lang['checking_mysql_version']; |
|
| 259 | - if ( version_compare(mysqli_get_server_info($conn), '5.0.51', '=') ) { |
|
| 260 | - echo '<span class="notok">' . $_lang['warning'] . '</span></b> <strong>' . $_lang['mysql_5051'] . '</strong></p>'; |
|
| 261 | - echo '<p><span class="notok">' . $_lang['mysql_5051_warning'] . '</span></p>'; |
|
| 258 | + echo '<p>'.$_lang['checking_mysql_version']; |
|
| 259 | + if (version_compare(mysqli_get_server_info($conn), '5.0.51', '=')) { |
|
| 260 | + echo '<span class="notok">'.$_lang['warning'].'</span></b> <strong>'.$_lang['mysql_5051'].'</strong></p>'; |
|
| 261 | + echo '<p><span class="notok">'.$_lang['mysql_5051_warning'].'</span></p>'; |
|
| 262 | 262 | } else { |
| 263 | - echo '<span class="ok">' . $_lang['ok'] . '</span> <strong>' . $_lang['mysql_version_is'] . mysqli_get_server_info($conn) . '</strong></p>'; |
|
| 263 | + echo '<span class="ok">'.$_lang['ok'].'</span> <strong>'.$_lang['mysql_version_is'].mysqli_get_server_info($conn).'</strong></p>'; |
|
| 264 | 264 | } |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | // check for strict mode |
| 268 | 268 | if ($conn) { |
| 269 | - echo '<p>'. $_lang['checking_mysql_strict_mode']; |
|
| 269 | + echo '<p>'.$_lang['checking_mysql_strict_mode']; |
|
| 270 | 270 | $mysqlmode = mysqli_query($conn, "SELECT @@global.sql_mode"); |
| 271 | - if (mysqli_num_rows($mysqlmode) > 0){ |
|
| 271 | + if (mysqli_num_rows($mysqlmode) > 0) { |
|
| 272 | 272 | $modes = mysqli_fetch_array($mysqlmode, MYSQLI_NUM); |
| 273 | 273 | //$modes = array("STRICT_TRANS_TABLES"); // for testing |
| 274 | 274 | // print_r($modes); |
| 275 | 275 | foreach ($modes as $mode) { |
| 276 | 276 | if (stristr($mode, "STRICT_TRANS_TABLES") !== false || stristr($mode, "STRICT_ALL_TABLES") !== false) { |
| 277 | - echo '<span class="notok">' . $_lang['warning'] . '</span></b> <strong> ' . $_lang['strict_mode'] . '</strong></p>'; |
|
| 278 | - echo '<p><span class="notok">' . $_lang['strict_mode_error'] . '</span></p>'; |
|
| 277 | + echo '<span class="notok">'.$_lang['warning'].'</span></b> <strong> '.$_lang['strict_mode'].'</strong></p>'; |
|
| 278 | + echo '<p><span class="notok">'.$_lang['strict_mode_error'].'</span></p>'; |
|
| 279 | 279 | } else { |
| 280 | - echo '<span class="ok">' . $_lang['ok'] . '</span></p>'; |
|
| 280 | + echo '<span class="ok">'.$_lang['ok'].'</span></p>'; |
|
| 281 | 281 | } |
| 282 | 282 | } |
| 283 | 283 | } else { |
| 284 | - echo '<span class="ok">' . $_lang['ok'] . '</span></p>'; |
|
| 284 | + echo '<span class="ok">'.$_lang['ok'].'</span></p>'; |
|
| 285 | 285 | } |
| 286 | 286 | } |
| 287 | 287 | // Version and strict mode check end |
@@ -297,18 +297,18 @@ discard block |
||
| 297 | 297 | f_owc("../assets/cache/installProc.inc.php", '<?php $installStartTime = '.time().'; ?>'); |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | -if($installMode > 0 && $_POST['installdata'] == "1") { |
|
| 301 | - echo '<p class="notes"><strong>' . $_lang['sample_web_site'] . ':</strong> ' . $_lang['sample_web_site_note'] . '</p>'; |
|
| 300 | +if ($installMode > 0 && $_POST['installdata'] == "1") { |
|
| 301 | + echo '<p class="notes"><strong>'.$_lang['sample_web_site'].':</strong> '.$_lang['sample_web_site_note'].'</p>'; |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | if ($errors > 0) { |
| 305 | 305 | echo '<p>'; |
| 306 | - echo $_lang['setup_cannot_continue'] . ' '; |
|
| 306 | + echo $_lang['setup_cannot_continue'].' '; |
|
| 307 | 307 | |
| 308 | - if($errors > 1){ |
|
| 309 | - echo $errors . " " . $_lang['errors'] . $_lang['please_correct_errors'] . $_lang['and_try_again_plural']; |
|
| 310 | - }else{ |
|
| 311 | - echo $_lang['error'] . $_lang['please_correct_error'] . $_lang['and_try_again']; |
|
| 308 | + if ($errors > 1) { |
|
| 309 | + echo $errors." ".$_lang['errors'].$_lang['please_correct_errors'].$_lang['and_try_again_plural']; |
|
| 310 | + } else { |
|
| 311 | + echo $_lang['error'].$_lang['please_correct_error'].$_lang['and_try_again']; |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | echo $_lang['visit_forum']; |
@@ -317,10 +317,10 @@ discard block |
||
| 317 | 317 | |
| 318 | 318 | echo '<p> </p>'; |
| 319 | 319 | |
| 320 | -$nextAction= $errors > 0 ? 'summary' : 'install'; |
|
| 321 | -$nextButton= $errors > 0 ? $_lang['retry'] : $_lang['install']; |
|
| 322 | -$nextVisibility= $errors > 0 || isset($_POST['chkagree']) ? 'visible' : 'hidden'; |
|
| 323 | -$agreeToggle= $errors > 0 ? '' : ' onclick="if(document.getElementById(\'chkagree\').checked){document.getElementById(\'nextbutton\').style.visibility=\'visible\';}else{document.getElementById(\'nextbutton\').style.visibility=\'hidden\';}"'; |
|
| 320 | +$nextAction = $errors > 0 ? 'summary' : 'install'; |
|
| 321 | +$nextButton = $errors > 0 ? $_lang['retry'] : $_lang['install']; |
|
| 322 | +$nextVisibility = $errors > 0 || isset($_POST['chkagree']) ? 'visible' : 'hidden'; |
|
| 323 | +$agreeToggle = $errors > 0 ? '' : ' onclick="if(document.getElementById(\'chkagree\').checked){document.getElementById(\'nextbutton\').style.visibility=\'visible\';}else{document.getElementById(\'nextbutton\').style.visibility=\'hidden\';}"'; |
|
| 324 | 324 | ?> |
| 325 | 325 | <form name="install" id="install_form" action="index.php?action=<?php echo $nextAction ?>" method="post"> |
| 326 | 326 | <div> |
@@ -342,32 +342,32 @@ discard block |
||
| 342 | 342 | |
| 343 | 343 | <input type="hidden" value="<?php echo $_POST['installdata'] ?>" name="installdata" /> |
| 344 | 344 | <?php |
| 345 | - $templates = isset ($_POST['template']) ? $_POST['template'] : array (); |
|
| 345 | + $templates = isset ($_POST['template']) ? $_POST['template'] : array(); |
|
| 346 | 346 | foreach ($templates as $i => $template) echo '<input type="hidden" name="template[]" value="'.$template.'" />'; |
| 347 | 347 | |
| 348 | - $tvs = isset ($_POST['tv']) ? $_POST['tv'] : array (); |
|
| 348 | + $tvs = isset ($_POST['tv']) ? $_POST['tv'] : array(); |
|
| 349 | 349 | foreach ($tvs as $i => $tv) echo '<input type="hidden" name="tv[]" value="'.$tv.'" />'; |
| 350 | 350 | |
| 351 | - $chunks = isset ($_POST['chunk']) ? $_POST['chunk'] : array (); |
|
| 351 | + $chunks = isset ($_POST['chunk']) ? $_POST['chunk'] : array(); |
|
| 352 | 352 | foreach ($chunks as $i => $chunk) echo '<input type="hidden" name="chunk[]" value="'.$chunk.'" />'; |
| 353 | 353 | |
| 354 | - $snippets = isset ($_POST['snippet']) ? $_POST['snippet'] : array (); |
|
| 354 | + $snippets = isset ($_POST['snippet']) ? $_POST['snippet'] : array(); |
|
| 355 | 355 | foreach ($snippets as $i => $snippet) echo '<input type="hidden" name="snippet[]" value="'.$snippet.'" />'; |
| 356 | 356 | |
| 357 | - $plugins = isset ($_POST['plugin']) ? $_POST['plugin'] : array (); |
|
| 357 | + $plugins = isset ($_POST['plugin']) ? $_POST['plugin'] : array(); |
|
| 358 | 358 | foreach ($plugins as $i => $plugin) echo '<input type="hidden" name="plugin[]" value="'.$plugin.'" />'; |
| 359 | 359 | |
| 360 | - $modules = isset ($_POST['module']) ? $_POST['module'] : array (); |
|
| 360 | + $modules = isset ($_POST['module']) ? $_POST['module'] : array(); |
|
| 361 | 361 | foreach ($modules as $i => $module) echo '<input type="hidden" name="module[]" value="'.$module.'" />'; |
| 362 | 362 | ?> |
| 363 | 363 | </div> |
| 364 | 364 | |
| 365 | -<h2><?php echo $_lang['agree_to_terms'];?></h2> |
|
| 365 | +<h2><?php echo $_lang['agree_to_terms']; ?></h2> |
|
| 366 | 366 | <p> |
| 367 | -<input type="checkbox" value="1" id="chkagree" name="chkagree" style="line-height:18px" <?php echo isset($_POST['chkagree']) ? 'checked="checked" ':""; ?><?php echo $agreeToggle;?>/><label for="chkagree" style="display:inline;float:none;line-height:18px;"> <?php echo $_lang['iagree_box']?> </label> |
|
| 367 | +<input type="checkbox" value="1" id="chkagree" name="chkagree" style="line-height:18px" <?php echo isset($_POST['chkagree']) ? 'checked="checked" ' : ""; ?><?php echo $agreeToggle; ?>/><label for="chkagree" style="display:inline;float:none;line-height:18px;"> <?php echo $_lang['iagree_box']?> </label> |
|
| 368 | 368 | </p> |
| 369 | 369 | <p class="buttonlinks"> |
| 370 | 370 | <a href="javascript:document.getElementById('install_form').action='index.php?action=options&language=<?php echo $install_language?>';document.getElementById('install_form').submit();" class="prev" title="<?php echo $_lang['btnback_value']?>"><span><?php echo $_lang['btnback_value']?></span></a> |
| 371 | - <a id="nextbutton" href="javascript:document.getElementById('install_form').submit();" title="<?php echo $nextButton ?>" style="visibility:<?php echo $nextVisibility;?>"><span><?php echo $nextButton ?></span></a> |
|
| 371 | + <a id="nextbutton" href="javascript:document.getElementById('install_form').submit();" title="<?php echo $nextButton ?>" style="visibility:<?php echo $nextVisibility; ?>"><span><?php echo $nextButton ?></span></a> |
|
| 372 | 372 | </p> |
| 373 | 373 | </form> |