@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | /** |
| 125 | 125 | * @param string $query |
| 126 | 126 | * |
| 127 | - * @return mixed|string |
|
| 127 | + * @return string |
|
| 128 | 128 | */ |
| 129 | 129 | public function replaceTablePlaceholders($query) { |
| 130 | 130 | $sql = $query; |
@@ -138,8 +138,8 @@ discard block |
||
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
| 141 | - * @param $query |
|
| 142 | - * @param $fetch |
|
| 141 | + * @param string $query |
|
| 142 | + * @param boolean $fetch |
|
| 143 | 143 | */ |
| 144 | 144 | protected function logQuery($query, $fetch) { |
| 145 | 145 | if (!classSupernova::$config->debug) { |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | /** |
| 181 | 181 | * @param string|DbSqlStatement $statement |
| 182 | 182 | * |
| 183 | - * @return array|bool|mysqli_result|null |
|
| 183 | + * @return mysqli_result |
|
| 184 | 184 | */ |
| 185 | 185 | public function execOld($statement) { |
| 186 | 186 | return $this->doquery($statement); |
@@ -361,6 +361,10 @@ discard block |
||
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | // TODO Заменить это на новый логгер |
| 364 | + |
|
| 365 | + /** |
|
| 366 | + * @param string $query |
|
| 367 | + */ |
|
| 364 | 368 | protected function security_watch_user_queries($query) { |
| 365 | 369 | global $user; |
| 366 | 370 | |
@@ -384,6 +388,9 @@ discard block |
||
| 384 | 388 | } |
| 385 | 389 | |
| 386 | 390 | |
| 391 | + /** |
|
| 392 | + * @param string $query |
|
| 393 | + */ |
|
| 387 | 394 | public function security_query_check_bad_words($query, $skip_query_check = false) { |
| 388 | 395 | if ($skip_query_check) { |
| 389 | 396 | return; |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | public function load_db_settings() { |
| 66 | 66 | $dbsettings = array(); |
| 67 | 67 | |
| 68 | - require(SN_ROOT_PHYSICAL . "config" . DOT_PHP_EX); |
|
| 68 | + require(SN_ROOT_PHYSICAL."config".DOT_PHP_EX); |
|
| 69 | 69 | |
| 70 | 70 | $this->dbsettings = $dbsettings; |
| 71 | 71 | } |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | $sql = $query; |
| 131 | 131 | if (strpos($sql, '{{') !== false) { |
| 132 | 132 | foreach ($this->table_list as $tableName) { |
| 133 | - $sql = str_replace("{{{$tableName}}}", $this->db_prefix . $tableName, $sql); |
|
| 133 | + $sql = str_replace("{{{$tableName}}}", $this->db_prefix.$tableName, $sql); |
|
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | $arr = debug_backtrace(); |
| 151 | 151 | $file = end(explode('/', $arr[0]['file'])); |
| 152 | 152 | $line = $arr[0]['line']; |
| 153 | - classSupernova::$debug->add("<tr><th>Query {$this->queryCount}: </th><th>$query</th><th>{$file} @ {$line}</th><th> </th><th> " . ($fetch ? '+' : ' ') . " </th></tr>"); |
|
| 153 | + classSupernova::$debug->add("<tr><th>Query {$this->queryCount}: </th><th>$query</th><th>{$file} @ {$line}</th><th> </th><th> ".($fetch ? '+' : ' ')." </th></tr>"); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | |
@@ -239,13 +239,13 @@ discard block |
||
| 239 | 239 | ->execute() |
| 240 | 240 | ->getResult(); |
| 241 | 241 | } else { |
| 242 | - $queryResult = $this->db_sql_query($stringQuery . DbSqlHelper::quoteComment($queryTrace)); |
|
| 242 | + $queryResult = $this->db_sql_query($stringQuery.DbSqlHelper::quoteComment($queryTrace)); |
|
| 243 | 243 | } |
| 244 | 244 | if (!$queryResult) { |
| 245 | 245 | throw new Exception(); |
| 246 | 246 | } |
| 247 | 247 | } catch (Exception $e) { |
| 248 | - classSupernova::$debug->error($this->db_error() . "<br />{$query}<br />", 'SQL Error'); |
|
| 248 | + classSupernova::$debug->error($this->db_error()."<br />{$query}<br />", 'SQL Error'); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | if ($fetch) { |
@@ -293,13 +293,13 @@ discard block |
||
| 293 | 293 | ->storeResult() |
| 294 | 294 | ->getIterator(); |
| 295 | 295 | } else { |
| 296 | - $queryResult = $this->db_sql_query($stringQuery . DbSqlHelper::quoteComment($queryTrace)); |
|
| 296 | + $queryResult = $this->db_sql_query($stringQuery.DbSqlHelper::quoteComment($queryTrace)); |
|
| 297 | 297 | |
| 298 | 298 | if (!$queryResult) { |
| 299 | 299 | throw new Exception(); |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | - if($queryResult instanceof mysqli_result) { |
|
| 302 | + if ($queryResult instanceof mysqli_result) { |
|
| 303 | 303 | $result = new DbMysqliResultIterator($queryResult); |
| 304 | 304 | } else { |
| 305 | 305 | $result = $queryResult; |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | } catch (Exception $e) { |
| 311 | - classSupernova::$debug->error($this->db_error() . "<br />{$query}<br />", 'SQL Error'); |
|
| 311 | + classSupernova::$debug->error($this->db_error()."<br />{$query}<br />", 'SQL Error'); |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | return $result; |
@@ -373,10 +373,10 @@ discard block |
||
| 373 | 373 | $this->isWatching = true; |
| 374 | 374 | $msg = "\$query = \"{$query}\"\n\r"; |
| 375 | 375 | if (!empty($_POST)) { |
| 376 | - $msg .= "\n\r" . dump($_POST, '$_POST'); |
|
| 376 | + $msg .= "\n\r".dump($_POST, '$_POST'); |
|
| 377 | 377 | } |
| 378 | 378 | if (!empty($_GET)) { |
| 379 | - $msg .= "\n\r" . dump($_GET, '$_GET'); |
|
| 379 | + $msg .= "\n\r".dump($_GET, '$_GET'); |
|
| 380 | 380 | } |
| 381 | 381 | classSupernova::$debug->warning($msg, "Watching user {$user['id']}", 399, array('base_dump' => true)); |
| 382 | 382 | $this->isWatching = false; |
@@ -391,7 +391,7 @@ discard block |
||
| 391 | 391 | |
| 392 | 392 | global $user, $dm_change_legit, $mm_change_legit; |
| 393 | 393 | |
| 394 | - switch(true) { |
|
| 394 | + switch (true) { |
|
| 395 | 395 | case stripos($query, 'RUNCATE TABL') != false: |
| 396 | 396 | case stripos($query, 'ROP TABL') != false: |
| 397 | 397 | case stripos($query, 'ENAME TABL') != false: |
@@ -402,37 +402,37 @@ discard block |
||
| 402 | 402 | case stripos($query, 'RPG_POINTS') != false && stripos(trim($query), 'UPDATE ') === 0 && !$dm_change_legit: |
| 403 | 403 | case stripos($query, 'METAMATTER') != false && stripos(trim($query), 'UPDATE ') === 0 && !$mm_change_legit: |
| 404 | 404 | case stripos($query, 'AUTHLEVEL') != false && $user['authlevel'] < 3 && stripos($query, 'SELECT') !== 0: |
| 405 | - $report = "Hacking attempt (" . date("d.m.Y H:i:s") . " - [" . time() . "]):\n"; |
|
| 405 | + $report = "Hacking attempt (".date("d.m.Y H:i:s")." - [".time()."]):\n"; |
|
| 406 | 406 | $report .= ">Database Inforamation\n"; |
| 407 | - $report .= "\tID - " . $user['id'] . "\n"; |
|
| 408 | - $report .= "\tUser - " . $user['username'] . "\n"; |
|
| 409 | - $report .= "\tAuth level - " . $user['authlevel'] . "\n"; |
|
| 410 | - $report .= "\tAdmin Notes - " . $user['adminNotes'] . "\n"; |
|
| 411 | - $report .= "\tCurrent Planet - " . $user['current_planet'] . "\n"; |
|
| 412 | - $report .= "\tUser IP - " . $user['user_lastip'] . "\n"; |
|
| 413 | - $report .= "\tUser IP at Reg - " . $user['ip_at_reg'] . "\n"; |
|
| 414 | - $report .= "\tUser Agent- " . $_SERVER['HTTP_USER_AGENT'] . "\n"; |
|
| 415 | - $report .= "\tCurrent Page - " . $user['current_page'] . "\n"; |
|
| 416 | - $report .= "\tRegister Time - " . $user['register_time'] . "\n"; |
|
| 407 | + $report .= "\tID - ".$user['id']."\n"; |
|
| 408 | + $report .= "\tUser - ".$user['username']."\n"; |
|
| 409 | + $report .= "\tAuth level - ".$user['authlevel']."\n"; |
|
| 410 | + $report .= "\tAdmin Notes - ".$user['adminNotes']."\n"; |
|
| 411 | + $report .= "\tCurrent Planet - ".$user['current_planet']."\n"; |
|
| 412 | + $report .= "\tUser IP - ".$user['user_lastip']."\n"; |
|
| 413 | + $report .= "\tUser IP at Reg - ".$user['ip_at_reg']."\n"; |
|
| 414 | + $report .= "\tUser Agent- ".$_SERVER['HTTP_USER_AGENT']."\n"; |
|
| 415 | + $report .= "\tCurrent Page - ".$user['current_page']."\n"; |
|
| 416 | + $report .= "\tRegister Time - ".$user['register_time']."\n"; |
|
| 417 | 417 | $report .= "\n"; |
| 418 | 418 | |
| 419 | 419 | $report .= ">Query Information\n"; |
| 420 | - $report .= "\tQuery - " . $query . "\n"; |
|
| 420 | + $report .= "\tQuery - ".$query."\n"; |
|
| 421 | 421 | $report .= "\n"; |
| 422 | 422 | |
| 423 | 423 | $report .= ">\$_SERVER Information\n"; |
| 424 | - $report .= "\tIP - " . $_SERVER['REMOTE_ADDR'] . "\n"; |
|
| 425 | - $report .= "\tHost Name - " . $_SERVER['HTTP_HOST'] . "\n"; |
|
| 426 | - $report .= "\tUser Agent - " . $_SERVER['HTTP_USER_AGENT'] . "\n"; |
|
| 427 | - $report .= "\tRequest Method - " . $_SERVER['REQUEST_METHOD'] . "\n"; |
|
| 428 | - $report .= "\tCame From - " . $_SERVER['HTTP_REFERER'] . "\n"; |
|
| 429 | - $report .= "\tPage is - " . $_SERVER['SCRIPT_NAME'] . "\n"; |
|
| 430 | - $report .= "\tUses Port - " . $_SERVER['REMOTE_PORT'] . "\n"; |
|
| 431 | - $report .= "\tServer Protocol - " . $_SERVER['SERVER_PROTOCOL'] . "\n"; |
|
| 424 | + $report .= "\tIP - ".$_SERVER['REMOTE_ADDR']."\n"; |
|
| 425 | + $report .= "\tHost Name - ".$_SERVER['HTTP_HOST']."\n"; |
|
| 426 | + $report .= "\tUser Agent - ".$_SERVER['HTTP_USER_AGENT']."\n"; |
|
| 427 | + $report .= "\tRequest Method - ".$_SERVER['REQUEST_METHOD']."\n"; |
|
| 428 | + $report .= "\tCame From - ".$_SERVER['HTTP_REFERER']."\n"; |
|
| 429 | + $report .= "\tPage is - ".$_SERVER['SCRIPT_NAME']."\n"; |
|
| 430 | + $report .= "\tUses Port - ".$_SERVER['REMOTE_PORT']."\n"; |
|
| 431 | + $report .= "\tServer Protocol - ".$_SERVER['SERVER_PROTOCOL']."\n"; |
|
| 432 | 432 | |
| 433 | 433 | $report .= "\n--------------------------------------------------------------------------------------------------\n"; |
| 434 | 434 | |
| 435 | - $fp = fopen(SN_ROOT_PHYSICAL . 'badqrys.txt', 'a'); |
|
| 435 | + $fp = fopen(SN_ROOT_PHYSICAL.'badqrys.txt', 'a'); |
|
| 436 | 436 | fwrite($fp, $report); |
| 437 | 437 | fclose($fp); |
| 438 | 438 | |
@@ -453,7 +453,7 @@ discard block |
||
| 453 | 453 | $prefix_length = strlen($this->db_prefix); |
| 454 | 454 | |
| 455 | 455 | $tl = array(); |
| 456 | - while($row = $this->db_fetch($query)) { |
|
| 456 | + while ($row = $this->db_fetch($query)) { |
|
| 457 | 457 | foreach ($row as $table_name) { |
| 458 | 458 | if (strpos($table_name, $this->db_prefix) === 0) { |
| 459 | 459 | $table_name = substr($table_name, $prefix_length); |
@@ -584,7 +584,7 @@ discard block |
||
| 584 | 584 | if (is_bool($query)) { |
| 585 | 585 | throw new Exception('Result of SHOW STATUS command is boolean - which should never happen. Connection to DB is lost?'); |
| 586 | 586 | } |
| 587 | - while($row = db_fetch($query)) { |
|
| 587 | + while ($row = db_fetch($query)) { |
|
| 588 | 588 | $result[$row['Variable_name']] = $row['Value']; |
| 589 | 589 | } |
| 590 | 590 | |
@@ -100,6 +100,9 @@ discard block |
||
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | |
| 103 | + /** |
|
| 104 | + * @param string $query |
|
| 105 | + */ |
|
| 103 | 106 | public function setQuery($query) { |
| 104 | 107 | $this->query = $query; |
| 105 | 108 | |
@@ -113,6 +116,9 @@ discard block |
||
| 113 | 116 | } |
| 114 | 117 | } |
| 115 | 118 | |
| 119 | + /** |
|
| 120 | + * @param string $comment |
|
| 121 | + */ |
|
| 116 | 122 | protected function commentAdd($comment) { |
| 117 | 123 | if (empty($this->values[static::COMMENT_PLACEHOLDER])) { |
| 118 | 124 | $this->query .= static::COMMENT_PLACEHOLDER; |
@@ -243,12 +249,15 @@ discard block |
||
| 243 | 249 | return $this; |
| 244 | 250 | } |
| 245 | 251 | |
| 252 | + /** |
|
| 253 | + * @return mysqli_result |
|
| 254 | + */ |
|
| 246 | 255 | public function getResult() { |
| 247 | 256 | return $this->statement->get_result(); |
| 248 | 257 | } |
| 249 | 258 | |
| 250 | 259 | /** |
| 251 | - * @return bool|mysqli_result |
|
| 260 | + * @return DBMysqliStatementIterator |
|
| 252 | 261 | */ |
| 253 | 262 | public function getIterator() { |
| 254 | 263 | return new DBMysqliStatementIterator($this->statement); |
@@ -12,10 +12,10 @@ discard block |
||
| 12 | 12 | define('INSIDE', true); |
| 13 | 13 | define('INSTALL', false); |
| 14 | 14 | define('IN_ADMIN', true); |
| 15 | -require('../common.' . substr(strrchr(__FILE__, '.'), 1)); |
|
| 15 | +require('../common.'.substr(strrchr(__FILE__, '.'), 1)); |
|
| 16 | 16 | |
| 17 | 17 | global $user; |
| 18 | -if($user['authlevel'] < 3) { |
|
| 18 | +if ($user['authlevel'] < 3) { |
|
| 19 | 19 | AdminMessage(classLocale::$lang['adm_err_denied']); |
| 20 | 20 | } |
| 21 | 21 | |
@@ -39,10 +39,10 @@ discard block |
||
| 39 | 39 | $sort = sys_get_param_int('sort', SORT_ID); |
| 40 | 40 | $sort = $sort_fields[$sort] ? $sort : SORT_ID; |
| 41 | 41 | |
| 42 | -if(($action = sys_get_param_int('action')) && ($user_id = sys_get_param_id('uid'))) { |
|
| 42 | +if (($action = sys_get_param_int('action')) && ($user_id = sys_get_param_id('uid'))) { |
|
| 43 | 43 | $user_selected = DBStaticUser::db_user_by_id($user_id, false, 'id, username, authlevel'); |
| 44 | - if($user_selected['authlevel'] < $user['authlevel'] && $user['authlevel'] >= 3) { |
|
| 45 | - switch($action) { |
|
| 44 | + if ($user_selected['authlevel'] < $user['authlevel'] && $user['authlevel'] >= 3) { |
|
| 45 | + switch ($action) { |
|
| 46 | 46 | case ACTION_DELETE: |
| 47 | 47 | DeleteSelectedUser($user_id); |
| 48 | 48 | sys_redirect("{$_SERVER['SCRIPT_NAME']}?sort={$sort}"); |
@@ -62,19 +62,19 @@ discard block |
||
| 62 | 62 | $template = gettemplate('admin/userlist', true); |
| 63 | 63 | |
| 64 | 64 | $multi_ip = array(); |
| 65 | -foreach(DBStaticUser::db_user_list_admin_multiaccounts() as $ip) { |
|
| 65 | +foreach (DBStaticUser::db_user_list_admin_multiaccounts() as $ip) { |
|
| 66 | 66 | $multi_ip[$ip['user_lastip']] = $ip['ip_count']; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | $geoip = geoip_status(); |
| 70 | 70 | |
| 71 | -foreach(DBStaticUser::db_user_list_admin_sorted($sort_fields[$sort], $is_players_online_page) as $user_row ) { |
|
| 72 | - if($user_row['banaday']) { |
|
| 71 | +foreach (DBStaticUser::db_user_list_admin_sorted($sort_fields[$sort], $is_players_online_page) as $user_row) { |
|
| 72 | + if ($user_row['banaday']) { |
|
| 73 | 73 | $ban_details = db_ban_list_get_details($user_row); |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | $geoip_info = $geoip ? geoip_ip_info(ip2longu($user_row['user_lastip'])) : array(); |
| 77 | - foreach($geoip_info as $key => $value) { |
|
| 77 | + foreach ($geoip_info as $key => $value) { |
|
| 78 | 78 | $geoip_info[strtoupper($key)] = $value; |
| 79 | 79 | unset($geoip_info[$key]); |
| 80 | 80 | } |
@@ -30,10 +30,10 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | defined('INSIDE') || die(); |
| 32 | 32 | |
| 33 | -if(php_sapi_name() == "cli") { |
|
| 33 | +if (php_sapi_name() == "cli") { |
|
| 34 | 34 | // In cli-mode |
| 35 | 35 | define('__DEBUG_CRLF', "\r\n"); |
| 36 | - define('__DEBUG_LINE', '-------------------------------------------------' . __DEBUG_CRLF); |
|
| 36 | + define('__DEBUG_LINE', '-------------------------------------------------'.__DEBUG_CRLF); |
|
| 37 | 37 | } else { |
| 38 | 38 | // Not in cli-mode |
| 39 | 39 | define('__DEBUG_CRLF', '<br />'); |
@@ -50,17 +50,17 @@ discard block |
||
| 50 | 50 | function log_file($message, $ident_change = 0) { |
| 51 | 51 | static $ident = 0; |
| 52 | 52 | |
| 53 | - if(!defined('SN_DEBUG_LOG')) { |
|
| 53 | + if (!defined('SN_DEBUG_LOG')) { |
|
| 54 | 54 | return; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - if($this->log_file_handler === null) { |
|
| 58 | - $this->log_file_handler = @fopen(SN_ROOT_PHYSICAL . '/.logs/supernova.log', 'a+'); |
|
| 57 | + if ($this->log_file_handler === null) { |
|
| 58 | + $this->log_file_handler = @fopen(SN_ROOT_PHYSICAL.'/.logs/supernova.log', 'a+'); |
|
| 59 | 59 | @fwrite($this->log_file_handler, "\r\n\r\n"); |
| 60 | 60 | } |
| 61 | 61 | $ident_change < 0 ? $ident += $ident_change * 2 : false; |
| 62 | - if($this->log_file_handler) { |
|
| 63 | - @fwrite($this->log_file_handler, date(FMT_DATE_TIME_SQL, time()) . str_repeat(' ', $ident + 1) . $message . "\r\n"); |
|
| 62 | + if ($this->log_file_handler) { |
|
| 63 | + @fwrite($this->log_file_handler, date(FMT_DATE_TIME_SQL, time()).str_repeat(' ', $ident + 1).$message."\r\n"); |
|
| 64 | 64 | } |
| 65 | 65 | $ident_change > 0 ? $ident += $ident_change * 2 : false; |
| 66 | 66 | } |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | function echo_log() { |
| 83 | - echo '<br><table><tr><td class=k colspan=4><a href="' . SN_ROOT_PHYSICAL . "admin/settings.php\">Debug Log</a>:</td></tr>{$this->log}</table>"; |
|
| 83 | + echo '<br><table><tr><td class=k colspan=4><a href="'.SN_ROOT_PHYSICAL."admin/settings.php\">Debug Log</a>:</td></tr>{$this->log}</table>"; |
|
| 84 | 84 | die(); |
| 85 | 85 | } |
| 86 | 86 | |
@@ -90,25 +90,25 @@ discard block |
||
| 90 | 90 | $result = array(); |
| 91 | 91 | $transaction_id = classSupernova::db_transaction_check(false) ? classSupernova::$transaction_id : classSupernova::$transaction_id++; |
| 92 | 92 | $result[] = "tID {$transaction_id}"; |
| 93 | - foreach($backtrace as $a_trace) { |
|
| 94 | - if(in_array($a_trace['function'], $exclude_functions)) { |
|
| 93 | + foreach ($backtrace as $a_trace) { |
|
| 94 | + if (in_array($a_trace['function'], $exclude_functions)) { |
|
| 95 | 95 | continue; |
| 96 | 96 | } |
| 97 | 97 | $function = |
| 98 | 98 | ($a_trace['type'] |
| 99 | 99 | ? ($a_trace['type'] == '->' |
| 100 | - ? "({$a_trace['class']})" . get_class($a_trace['object']) |
|
| 100 | + ? "({$a_trace['class']})".get_class($a_trace['object']) |
|
| 101 | 101 | : $a_trace['class'] |
| 102 | - ) . $a_trace['type'] |
|
| 102 | + ).$a_trace['type'] |
|
| 103 | 103 | : '' |
| 104 | - ) . $a_trace['function'] . '()'; |
|
| 104 | + ).$a_trace['function'].'()'; |
|
| 105 | 105 | |
| 106 | 106 | $file = str_replace(SN_ROOT_PHYSICAL, '', str_replace('\\', '/', $a_trace['file'])); |
| 107 | 107 | |
| 108 | 108 | // $result[] = "{$function} ({$a_trace['line']})'{$file}'"; |
| 109 | 109 | $result[] = "{$function} - '{$file}' Line {$a_trace['line']}"; |
| 110 | 110 | |
| 111 | - if(!$long_comment) { |
|
| 111 | + if (!$long_comment) { |
|
| 112 | 112 | break; |
| 113 | 113 | } |
| 114 | 114 | } |
@@ -122,26 +122,26 @@ discard block |
||
| 122 | 122 | function dump($dump = false, $force_base = false, $deadlock = false) { |
| 123 | 123 | global $user, $planetrow; |
| 124 | 124 | |
| 125 | - if($dump === false) { |
|
| 125 | + if ($dump === false) { |
|
| 126 | 126 | return; |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | $error_backtrace = array(); |
| 130 | 130 | $base_dump = false; |
| 131 | 131 | |
| 132 | - if($force_base === true) { |
|
| 132 | + if ($force_base === true) { |
|
| 133 | 133 | $base_dump = true; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - if($dump === true) { |
|
| 136 | + if ($dump === true) { |
|
| 137 | 137 | $base_dump = true; |
| 138 | 138 | } else { |
| 139 | - if(!is_array($dump)) { |
|
| 139 | + if (!is_array($dump)) { |
|
| 140 | 140 | $dump = array('var' => $dump); |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - foreach($dump as $dump_var_name => $dump_var) { |
|
| 144 | - if($dump_var_name == 'base_dump') { |
|
| 143 | + foreach ($dump as $dump_var_name => $dump_var) { |
|
| 144 | + if ($dump_var_name == 'base_dump') { |
|
| 145 | 145 | $base_dump = $dump_var; |
| 146 | 146 | } else { |
| 147 | 147 | $error_backtrace[$dump_var_name] = $dump_var; |
@@ -149,22 +149,21 @@ discard block |
||
| 149 | 149 | } |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - if($deadlock && ($q = db_fetch(classSupernova::$db->mysql_get_innodb_status()))) { |
|
| 152 | + if ($deadlock && ($q = db_fetch(classSupernova::$db->mysql_get_innodb_status()))) { |
|
| 153 | 153 | $error_backtrace['deadlock'] = explode("\n", $q['Status']); |
| 154 | 154 | $error_backtrace['locks'] = classSupernova::$locks; |
| 155 | 155 | $error_backtrace['cSN_data'] = classSupernova::$data; |
| 156 | - foreach($error_backtrace['cSN_data'] as &$location) { |
|
| 157 | - foreach($location as $location_id => &$location_data) { |
|
| 158 | - $location_data = isset($location_data['username']) ? $location_data['username'] : |
|
| 159 | - (isset($location_data['name']) ? $location_data['name'] : $location_id); |
|
| 156 | + foreach ($error_backtrace['cSN_data'] as &$location) { |
|
| 157 | + foreach ($location as $location_id => &$location_data) { |
|
| 158 | + $location_data = isset($location_data['username']) ? $location_data['username'] : (isset($location_data['name']) ? $location_data['name'] : $location_id); |
|
| 160 | 159 | } |
| 161 | 160 | } |
| 162 | 161 | $error_backtrace['cSN_queries'] = classSupernova::$queries; |
| 163 | 162 | } |
| 164 | 163 | |
| 165 | - if($base_dump) { |
|
| 166 | - if(is_array($this->log_array) && count($this->log_array) > 0) { |
|
| 167 | - foreach($this->log_array as $log) { |
|
| 164 | + if ($base_dump) { |
|
| 165 | + if (is_array($this->log_array) && count($this->log_array) > 0) { |
|
| 166 | + foreach ($this->log_array as $log) { |
|
| 168 | 167 | $error_backtrace['queries'][] = $log; |
| 169 | 168 | } |
| 170 | 169 | } |
@@ -193,14 +192,14 @@ discard block |
||
| 193 | 192 | function error($message = 'There is a error on page', $title = 'Internal Error', $error_code = 500, $dump = true) { |
| 194 | 193 | global $sys_stop_log_hit, $sys_log_disabled, $user; |
| 195 | 194 | |
| 196 | - if(empty(classSupernova::$db->connected)) { |
|
| 195 | + if (empty(classSupernova::$db->connected)) { |
|
| 197 | 196 | // TODO - писать ошибку в файл |
| 198 | 197 | die('SQL server currently unavailable. Please contact Administration...'); |
| 199 | 198 | } |
| 200 | 199 | |
| 201 | 200 | sn_db_transaction_rollback(); |
| 202 | 201 | |
| 203 | - if(classSupernova::$config->debug == 1) { |
|
| 202 | + if (classSupernova::$config->debug == 1) { |
|
| 204 | 203 | echo "<h2>{$title}</h2><br><font color=red>{$message}</font><br><hr>"; |
| 205 | 204 | echo "<table>{$this->log}</table>"; |
| 206 | 205 | } |
@@ -212,16 +211,16 @@ discard block |
||
| 212 | 211 | |
| 213 | 212 | $userId = empty($user['id']) ? 0 : $user['id']; |
| 214 | 213 | |
| 215 | - if(!$sys_log_disabled) { |
|
| 214 | + if (!$sys_log_disabled) { |
|
| 216 | 215 | $query = "INSERT INTO `{{logs}}` SET |
| 217 | - `log_time` = '" . time() . "', `log_code` = '" . db_escape($error_code) . "', `log_sender` = '" . db_escape($userId) . "', |
|
| 218 | - `log_username` = '" . db_escape($user['user_name']) . "', `log_title` = '" . db_escape($title) . "', `log_text` = '" . db_escape($message) . "', |
|
| 219 | - `log_page` = '" . db_escape(strpos($_SERVER['SCRIPT_NAME'], SN_ROOT_RELATIVE) === false ? $_SERVER['SCRIPT_NAME'] : substr($_SERVER['SCRIPT_NAME'], strlen(SN_ROOT_RELATIVE))) . "'" . |
|
| 216 | + `log_time` = '" . time()."', `log_code` = '".db_escape($error_code)."', `log_sender` = '".db_escape($userId)."', |
|
| 217 | + `log_username` = '" . db_escape($user['user_name'])."', `log_title` = '".db_escape($title)."', `log_text` = '".db_escape($message)."', |
|
| 218 | + `log_page` = '" . db_escape(strpos($_SERVER['SCRIPT_NAME'], SN_ROOT_RELATIVE) === false ? $_SERVER['SCRIPT_NAME'] : substr($_SERVER['SCRIPT_NAME'], strlen(SN_ROOT_RELATIVE)))."'". |
|
| 220 | 219 | // ($error_backtrace ? ", `log_dump` = '" . db_escape(serialize($error_backtrace)) . "'" : '') . ";"; |
| 221 | - ", `log_dump` = '" . ($error_backtrace ? db_escape(serialize($error_backtrace)) : '') . "'" . ";"; |
|
| 222 | - doquery($query, '', false, true) or die($fatal_error . db_error()); |
|
| 220 | + ", `log_dump` = '".($error_backtrace ? db_escape(serialize($error_backtrace)) : '')."'".";"; |
|
| 221 | + doquery($query, '', false, true) or die($fatal_error.db_error()); |
|
| 223 | 222 | |
| 224 | - $message = "Пожалуйста, свяжитесь с админом, если ошибка повторится. Ошибка №: <b>" . db_insert_id() . "</b>"; |
|
| 223 | + $message = "Пожалуйста, свяжитесь с админом, если ошибка повторится. Ошибка №: <b>".db_insert_id()."</b>"; |
|
| 225 | 224 | |
| 226 | 225 | $sys_stop_log_hit = true; |
| 227 | 226 | $sys_log_disabled = true; |
@@ -231,7 +230,7 @@ discard block |
||
| 231 | 230 | ob_start(); |
| 232 | 231 | print("<hr>User ID {$user['id']} raised error code {$error_code} titled '{$title}' with text '{$error_text}' on page {$_SERVER['SCRIPT_NAME']}"); |
| 233 | 232 | |
| 234 | - foreach($error_backtrace as $name => $value) { |
|
| 233 | + foreach ($error_backtrace as $name => $value) { |
|
| 235 | 234 | print(__DEBUG_LINE); |
| 236 | 235 | pdump($value, $name); |
| 237 | 236 | } |
@@ -243,7 +242,7 @@ discard block |
||
| 243 | 242 | function warning($message, $title = 'System Message', $log_code = 300, $dump = false) { |
| 244 | 243 | global $user, $sys_log_disabled; |
| 245 | 244 | |
| 246 | - if(empty(classSupernova::$db->connected)) { |
|
| 245 | + if (empty(classSupernova::$db->connected)) { |
|
| 247 | 246 | // TODO - писать ошибку в файл |
| 248 | 247 | die('SQL server currently unavailable. Please contact Administration...'); |
| 249 | 248 | } |
@@ -252,12 +251,12 @@ discard block |
||
| 252 | 251 | |
| 253 | 252 | $userId = empty($user['id']) ? 0 : $user['id']; |
| 254 | 253 | |
| 255 | - if(!$sys_log_disabled) { |
|
| 254 | + if (!$sys_log_disabled) { |
|
| 256 | 255 | $query = "INSERT INTO `{{logs}}` SET |
| 257 | - `log_time` = '" . time() . "', `log_code` = '" . db_escape($log_code) . "', `log_sender` = '" . db_escape($userId) . "', |
|
| 258 | - `log_username` = '" . db_escape($user['user_name']) . "', `log_title` = '" . db_escape($title) . "', `log_text` = '" . db_escape($message) . "', |
|
| 259 | - `log_page` = '" . db_escape(strpos($_SERVER['SCRIPT_NAME'], SN_ROOT_RELATIVE) === false ? $_SERVER['SCRIPT_NAME'] : substr($_SERVER['SCRIPT_NAME'], strlen(SN_ROOT_RELATIVE))) . "'" . |
|
| 260 | - ", `log_dump` = '" . ($error_backtrace ? db_escape(serialize($error_backtrace)) : '') . "'" . ";"; |
|
| 256 | + `log_time` = '" . time()."', `log_code` = '".db_escape($log_code)."', `log_sender` = '".db_escape($userId)."', |
|
| 257 | + `log_username` = '" . db_escape($user['user_name'])."', `log_title` = '".db_escape($title)."', `log_text` = '".db_escape($message)."', |
|
| 258 | + `log_page` = '" . db_escape(strpos($_SERVER['SCRIPT_NAME'], SN_ROOT_RELATIVE) === false ? $_SERVER['SCRIPT_NAME'] : substr($_SERVER['SCRIPT_NAME'], strlen(SN_ROOT_RELATIVE)))."'". |
|
| 259 | + ", `log_dump` = '".($error_backtrace ? db_escape(serialize($error_backtrace)) : '')."'".";"; |
|
| 261 | 260 | doquery($query, '', false, true); |
| 262 | 261 | } else { |
| 263 | 262 | // // TODO Здесь надо писать в файло |
@@ -270,11 +269,11 @@ discard block |
||
| 270 | 269 | // Dump variables nicer then var_dump() |
| 271 | 270 | |
| 272 | 271 | function dump($value, $varname = null, $level = 0, $dumper = '') { |
| 273 | - if(isset($varname)) { |
|
| 272 | + if (isset($varname)) { |
|
| 274 | 273 | $varname .= " = "; |
| 275 | 274 | } |
| 276 | 275 | |
| 277 | - if($level == -1) { |
|
| 276 | + if ($level == -1) { |
|
| 278 | 277 | $trans[' '] = '∴'; |
| 279 | 278 | $trans["\t"] = '⇒'; |
| 280 | 279 | $trans["\n"] = '¶;'; |
@@ -283,31 +282,31 @@ discard block |
||
| 283 | 282 | |
| 284 | 283 | return strtr(htmlspecialchars($value), $trans); |
| 285 | 284 | } |
| 286 | - if($level == 0) { |
|
| 285 | + if ($level == 0) { |
|
| 287 | 286 | // $dumper = '<pre>' . mt_rand(10, 99) . '|' . $varname; |
| 288 | - $dumper = mt_rand(10, 99) . '|' . $varname; |
|
| 287 | + $dumper = mt_rand(10, 99).'|'.$varname; |
|
| 289 | 288 | } |
| 290 | 289 | |
| 291 | 290 | $type = gettype($value); |
| 292 | 291 | $dumper .= $type; |
| 293 | 292 | |
| 294 | - if($type == 'string') { |
|
| 295 | - $dumper .= '(' . strlen($value) . ')'; |
|
| 293 | + if ($type == 'string') { |
|
| 294 | + $dumper .= '('.strlen($value).')'; |
|
| 296 | 295 | $value = dump($value, '', -1); |
| 297 | - } elseif($type == 'boolean') { |
|
| 296 | + } elseif ($type == 'boolean') { |
|
| 298 | 297 | $value = ($value ? 'true' : 'false'); |
| 299 | - } elseif($type == 'object') { |
|
| 298 | + } elseif ($type == 'object') { |
|
| 300 | 299 | $props = get_class_vars(get_class($value)); |
| 301 | - $dumper .= '(' . count($props) . ') <u>' . get_class($value) . '</u>'; |
|
| 302 | - foreach($props as $key => $val) { |
|
| 303 | - $dumper .= "\n" . str_repeat("\t", $level + 1) . $key . ' => '; |
|
| 300 | + $dumper .= '('.count($props).') <u>'.get_class($value).'</u>'; |
|
| 301 | + foreach ($props as $key => $val) { |
|
| 302 | + $dumper .= "\n".str_repeat("\t", $level + 1).$key.' => '; |
|
| 304 | 303 | $dumper .= dump($value->$key, '', $level + 1); |
| 305 | 304 | } |
| 306 | 305 | $value = ''; |
| 307 | - } elseif($type == 'array') { |
|
| 308 | - $dumper .= '(' . count($value) . ')'; |
|
| 309 | - foreach($value as $key => $val) { |
|
| 310 | - $dumper .= "\n" . str_repeat("\t", $level + 1) . dump($key, '', -1) . ' => '; |
|
| 306 | + } elseif ($type == 'array') { |
|
| 307 | + $dumper .= '('.count($value).')'; |
|
| 308 | + foreach ($value as $key => $val) { |
|
| 309 | + $dumper .= "\n".str_repeat("\t", $level + 1).dump($key, '', -1).' => '; |
|
| 311 | 310 | $dumper .= dump($val, '', $level + 1); |
| 312 | 311 | } |
| 313 | 312 | $value = ''; |
@@ -326,24 +325,24 @@ discard block |
||
| 326 | 325 | // $backtrace = $backtrace[1]; |
| 327 | 326 | |
| 328 | 327 | $caller = ''; |
| 329 | - if(defined('SN_DEBUG_PDUMP_CALLER') && SN_DEBUG_PDUMP_CALLER) { |
|
| 330 | - $caller = (!empty($backtrace[1]['class']) ? $backtrace[1]['class'] : '') . |
|
| 331 | - (!empty($backtrace[1]['type']) ? $backtrace[1]['type'] : '') . |
|
| 332 | - $backtrace[1]['function'] . |
|
| 328 | + if (defined('SN_DEBUG_PDUMP_CALLER') && SN_DEBUG_PDUMP_CALLER) { |
|
| 329 | + $caller = (!empty($backtrace[1]['class']) ? $backtrace[1]['class'] : ''). |
|
| 330 | + (!empty($backtrace[1]['type']) ? $backtrace[1]['type'] : ''). |
|
| 331 | + $backtrace[1]['function']. |
|
| 333 | 332 | (!empty($backtrace[0]['file']) |
| 334 | 333 | ? ( |
| 335 | - ' (' . substr($backtrace[0]['file'], SN_ROOT_PHYSICAL_STR_LEN) . |
|
| 336 | - (!empty($backtrace[0]['line']) ? ':' . $backtrace[0]['line'] : '') . |
|
| 334 | + ' ('.substr($backtrace[0]['file'], SN_ROOT_PHYSICAL_STR_LEN). |
|
| 335 | + (!empty($backtrace[0]['line']) ? ':'.$backtrace[0]['line'] : ''). |
|
| 337 | 336 | ')' |
| 338 | 337 | ) |
| 339 | 338 | : '' |
| 340 | 339 | ); |
| 341 | - $caller = "\r\n" . $caller; |
|
| 340 | + $caller = "\r\n".$caller; |
|
| 342 | 341 | } |
| 343 | 342 | |
| 344 | - print('<pre style="text-align: left; background-color: #111111; color: #0A0; font-family: Courier, monospace !important; padding: 1em 0; font-weight: 800; font-size: 14px;">' . |
|
| 345 | - dump($value, $varname) . |
|
| 346 | - $caller . |
|
| 343 | + print('<pre style="text-align: left; background-color: #111111; color: #0A0; font-family: Courier, monospace !important; padding: 1em 0; font-weight: 800; font-size: 14px;">'. |
|
| 344 | + dump($value, $varname). |
|
| 345 | + $caller. |
|
| 347 | 346 | '</pre>' |
| 348 | 347 | ); |
| 349 | 348 | } |
@@ -353,24 +352,24 @@ discard block |
||
| 353 | 352 | } |
| 354 | 353 | |
| 355 | 354 | function pr($prePrint = false) { |
| 356 | - if($prePrint) { |
|
| 355 | + if ($prePrint) { |
|
| 357 | 356 | print(__DEBUG_CRLF); |
| 358 | 357 | } |
| 359 | - print(mt_rand() . __DEBUG_CRLF); |
|
| 358 | + print(mt_rand().__DEBUG_CRLF); |
|
| 360 | 359 | } |
| 361 | 360 | |
| 362 | 361 | function pc($prePrint = false) { |
| 363 | 362 | global $_PRINT_COUNT_VALUE; |
| 364 | 363 | $_PRINT_COUNT_VALUE++; |
| 365 | 364 | |
| 366 | - if($prePrint) { |
|
| 365 | + if ($prePrint) { |
|
| 367 | 366 | print(__DEBUG_CRLF); |
| 368 | 367 | } |
| 369 | - print($_PRINT_COUNT_VALUE . __DEBUG_CRLF); |
|
| 368 | + print($_PRINT_COUNT_VALUE.__DEBUG_CRLF); |
|
| 370 | 369 | } |
| 371 | 370 | |
| 372 | 371 | function prep($message) { |
| 373 | - print('<pre>' . $message . '</pre>'); |
|
| 372 | + print('<pre>'.$message.'</pre>'); |
|
| 374 | 373 | } |
| 375 | 374 | |
| 376 | 375 | function backtrace_no_arg() { |
@@ -393,5 +392,5 @@ discard block |
||
| 393 | 392 | */ |
| 394 | 393 | function pdie($message = '') { |
| 395 | 394 | $backtrace = debug_backtrace(); |
| 396 | - die(__DEBUG_LINE . ($message ? $message . ' @ ' : '') . $backtrace[0]['file'] . ':' . $backtrace[0]['line']); |
|
| 395 | + die(__DEBUG_LINE.($message ? $message.' @ ' : '').$backtrace[0]['file'].':'.$backtrace[0]['line']); |
|
| 397 | 396 | } |
@@ -62,14 +62,14 @@ |
||
| 62 | 62 | $this->currentRow = $this->fetchArray(); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - protected function fetchArray () { |
|
| 65 | + protected function fetchArray() { |
|
| 66 | 66 | $data = mysqli_stmt_result_metadata($this->stmt); |
| 67 | 67 | $fields = array(); |
| 68 | 68 | $out = array(); |
| 69 | 69 | |
| 70 | 70 | $fields[0] = &$this->stmt; |
| 71 | 71 | |
| 72 | - while($field = mysqli_fetch_field($data)) { |
|
| 72 | + while ($field = mysqli_fetch_field($data)) { |
|
| 73 | 73 | $fields[] = &$out[$field->name]; |
| 74 | 74 | } |
| 75 | 75 | |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | * @return array|null |
| 98 | 98 | */ |
| 99 | 99 | public static function getRecordById($recordId, $fieldList = '*', $forUpdate = false) { |
| 100 | - return static::getRecord(array(static::$_idField . '=' . $recordId), $fieldList, $forUpdate); |
|
| 100 | + return static::getRecord(array(static::$_idField.'='.$recordId), $fieldList, $forUpdate); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | /** |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | * @return array|bool|mysqli_result|null |
| 107 | 107 | */ |
| 108 | 108 | protected static function execute($statement) { |
| 109 | - return static::$dbStatic->execOld((string)$statement); |
|
| 109 | + return static::$dbStatic->execOld((string) $statement); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | $query = static::execute( |
| 135 | 135 | static::buildSelectAll() |
| 136 | 136 | ->fields(static::$_idField) |
| 137 | - ->where(array("`" . static::$_idField . "` IN (" . implode(',', $idList) . ")")) |
|
| 137 | + ->where(array("`".static::$_idField."` IN (".implode(',', $idList).")")) |
|
| 138 | 138 | ); |
| 139 | 139 | } |
| 140 | 140 | |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | $result = array(); |
| 155 | 155 | if (!empty($idList)) { |
| 156 | 156 | $query = static::queryExistsIdInList($idList); |
| 157 | - while($row = db_fetch($query)) { |
|
| 157 | + while ($row = db_fetch($query)) { |
|
| 158 | 158 | $result[] = $row[static::$_idField]; |
| 159 | 159 | } |
| 160 | 160 | } |