@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | /** |
163 | 163 | * @param string $query |
164 | 164 | * |
165 | - * @return mixed|string |
|
165 | + * @return string |
|
166 | 166 | */ |
167 | 167 | public function replaceTablePlaceholders($query) { |
168 | 168 | $sql = $query; |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
179 | - * @param $query |
|
179 | + * @param string $query |
|
180 | 180 | */ |
181 | 181 | protected function logQuery($query) { |
182 | 182 | if (!classSupernova::$config->debug) { |
@@ -306,10 +306,16 @@ discard block |
||
306 | 306 | } |
307 | 307 | |
308 | 308 | |
309 | + /** |
|
310 | + * @param string $query |
|
311 | + */ |
|
309 | 312 | public function doInsertComplex($query) { |
310 | 313 | return $this->doExecute($query); |
311 | 314 | } |
312 | 315 | |
316 | + /** |
|
317 | + * @param integer $replace |
|
318 | + */ |
|
313 | 319 | protected function doSet($table, $fieldsAndValues, $replace = DB_INSERT_PLAIN) { |
314 | 320 | $tableSafe = $this->db_escape($table); |
315 | 321 | $safeFieldsAndValues = implode(',', $this->safeFieldsEqualValues($fieldsAndValues)); |
@@ -342,6 +348,9 @@ discard block |
||
342 | 348 | return $this->doSet($table, $fieldsAndValues, $replace); |
343 | 349 | } |
344 | 350 | |
351 | + /** |
|
352 | + * @param string $table |
|
353 | + */ |
|
345 | 354 | public function doReplaceSet($table, $fieldsAndValues) { |
346 | 355 | return $this->doSet($table, $fieldsAndValues, DB_INSERT_REPLACE); |
347 | 356 | } |
@@ -376,7 +385,7 @@ discard block |
||
376 | 385 | * Values should be passed as-is |
377 | 386 | * |
378 | 387 | * @param string $table |
379 | - * @param array $fields |
|
388 | + * @param string[] $fields |
|
380 | 389 | * @param string[] $values |
381 | 390 | * |
382 | 391 | * @return array|bool|mysqli_result|null |
@@ -411,7 +420,7 @@ discard block |
||
411 | 420 | * Self-contained - means no params used |
412 | 421 | * Such queries usually used to make large amount of in-base calculations |
413 | 422 | * |
414 | - * @param $query |
|
423 | + * @param string $query |
|
415 | 424 | * |
416 | 425 | * @return array|bool|mysqli_result|null |
417 | 426 | */ |
@@ -419,6 +428,9 @@ discard block |
||
419 | 428 | return $this->doExecute($query); |
420 | 429 | } |
421 | 430 | |
431 | + /** |
|
432 | + * @param boolean $isOneRecord |
|
433 | + */ |
|
422 | 434 | protected function doUpdateWhere($table, $fieldsSet, $fieldsAdjust = array(), $where = array(), $isOneRecord = DB_RECORDS_ALL) { |
423 | 435 | $tableSafe = $this->db_escape($table); |
424 | 436 | |
@@ -442,18 +454,30 @@ discard block |
||
442 | 454 | return $this->doExecute($query); |
443 | 455 | } |
444 | 456 | |
457 | + /** |
|
458 | + * @param string $table |
|
459 | + */ |
|
445 | 460 | public function doUpdateRowSet($table, $fieldsAndValues, $where) { |
446 | 461 | return $this->doUpdateWhere($table, $fieldsAndValues, array(), $where, DB_RECORD_ONE); |
447 | 462 | } |
448 | 463 | |
464 | + /** |
|
465 | + * @param string $table |
|
466 | + */ |
|
449 | 467 | public function doUpdateTableSet($table, $fieldsAndValues, $where = array()) { |
450 | 468 | return $this->doUpdateWhere($table, $fieldsAndValues, array(), $where, DB_RECORDS_ALL); |
451 | 469 | } |
452 | 470 | |
471 | + /** |
|
472 | + * @param string $table |
|
473 | + */ |
|
453 | 474 | public function doUpdateRowAdjust($table, $fieldsSet, $fieldsAdjust, $where) { |
454 | 475 | return $this->doUpdateWhere($table, $fieldsSet, $fieldsAdjust, $where, DB_RECORD_ONE); |
455 | 476 | } |
456 | 477 | |
478 | + /** |
|
479 | + * @param string $table |
|
480 | + */ |
|
457 | 481 | public function doUpdateTableAdjust($table, $fieldsSet, $fieldsAdjust, $where) { |
458 | 482 | return $this->doUpdateWhere($table, $fieldsSet, $fieldsAdjust, $where, DB_RECORDS_ALL); |
459 | 483 | } |
@@ -526,7 +550,7 @@ discard block |
||
526 | 550 | * |
527 | 551 | * Usually used for mallformed $where conditions |
528 | 552 | * |
529 | - * @param $table |
|
553 | + * @param string $table |
|
530 | 554 | * @param $where |
531 | 555 | * |
532 | 556 | * @return array|bool|mysqli_result|null |
@@ -693,6 +717,10 @@ discard block |
||
693 | 717 | } |
694 | 718 | |
695 | 719 | // TODO Заменить это на новый логгер |
720 | + |
|
721 | + /** |
|
722 | + * @param string $query |
|
723 | + */ |
|
696 | 724 | protected function security_watch_user_queries($query) { |
697 | 725 | global $user; |
698 | 726 | |
@@ -716,6 +744,9 @@ discard block |
||
716 | 744 | } |
717 | 745 | |
718 | 746 | |
747 | + /** |
|
748 | + * @param string $query |
|
749 | + */ |
|
719 | 750 | public function security_query_check_bad_words($query) { |
720 | 751 | if ($this->skipQueryCheck) { |
721 | 752 | return; |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | public function load_db_settings($configFile = '') { |
97 | 97 | $dbsettings = array(); |
98 | 98 | |
99 | - empty($configFile) ? $configFile = SN_ROOT_PHYSICAL . "config" . DOT_PHP_EX : false; |
|
99 | + empty($configFile) ? $configFile = SN_ROOT_PHYSICAL."config".DOT_PHP_EX : false; |
|
100 | 100 | |
101 | 101 | require $configFile; |
102 | 102 | |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | } |
117 | 117 | |
118 | 118 | if (empty($this->dbsettings)) { |
119 | - $this->load_db_settings(SN_ROOT_PHYSICAL . "config" . DOT_PHP_EX); |
|
119 | + $this->load_db_settings(SN_ROOT_PHYSICAL."config".DOT_PHP_EX); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | // TODO - фатальные (?) ошибки на каждом шагу. Хотя - скорее Эксепшны |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | $sql = $query; |
169 | 169 | if (strpos($sql, '{{') !== false) { |
170 | 170 | foreach ($this->table_list as $tableName) { |
171 | - $sql = str_replace("{{{$tableName}}}", $this->db_prefix . $tableName, $sql); |
|
171 | + $sql = str_replace("{{{$tableName}}}", $this->db_prefix.$tableName, $sql); |
|
172 | 172 | } |
173 | 173 | } |
174 | 174 | |
@@ -241,12 +241,12 @@ discard block |
||
241 | 241 | |
242 | 242 | $queryResult = null; |
243 | 243 | try { |
244 | - $queryResult = $this->db_sql_query($stringQuery . DbSqlHelper::quoteComment($queryTrace)); |
|
244 | + $queryResult = $this->db_sql_query($stringQuery.DbSqlHelper::quoteComment($queryTrace)); |
|
245 | 245 | if (!$queryResult) { |
246 | 246 | throw new Exception(); |
247 | 247 | } |
248 | 248 | } catch (Exception $e) { |
249 | - classSupernova::$debug->error($this->db_error() . "<br />{$query}<br />", 'SQL Error'); |
|
249 | + classSupernova::$debug->error($this->db_error()."<br />{$query}<br />", 'SQL Error'); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | return $queryResult; |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | $safeFieldsAndValues = implode(',', $this->safeFieldsEqualValues($fieldsAndValues)); |
316 | 316 | // $command = $replace == DB_INSERT_REPLACE ? 'REPLACE' : 'INSERT'; |
317 | 317 | // $command .= $replace == DB_INSERT_IGNORE ? ' IGNORE' : ''; |
318 | - switch($replace) { |
|
318 | + switch ($replace) { |
|
319 | 319 | case DB_INSERT_IGNORE: |
320 | 320 | $command = 'INSERT IGNORE'; |
321 | 321 | break; |
@@ -424,10 +424,10 @@ discard block |
||
424 | 424 | |
425 | 425 | $safeFields = array(); |
426 | 426 | // Adjusts overwritten by Sets |
427 | - if($safeAdjust = implode(',', $this->safeFieldsAdjust($fieldsAdjust))) { |
|
427 | + if ($safeAdjust = implode(',', $this->safeFieldsAdjust($fieldsAdjust))) { |
|
428 | 428 | $safeFields[] = &$safeAdjust; |
429 | 429 | } |
430 | - if($safeFieldsEqualValues = implode(',', $this->safeFieldsEqualValues($fieldsSet))) { |
|
430 | + if ($safeFieldsEqualValues = implode(',', $this->safeFieldsEqualValues($fieldsSet))) { |
|
431 | 431 | $safeFields[] = &$safeFieldsEqualValues; |
432 | 432 | } |
433 | 433 | $safeFieldsString = implode(',', $safeFields); |
@@ -538,7 +538,7 @@ discard block |
||
538 | 538 | |
539 | 539 | |
540 | 540 | protected function castAsDbValue($value) { |
541 | - switch(gettype($value)) { |
|
541 | + switch (gettype($value)) { |
|
542 | 542 | case TYPE_INTEGER: |
543 | 543 | case TYPE_DOUBLE: |
544 | 544 | // do nothing |
@@ -561,7 +561,7 @@ discard block |
||
561 | 561 | case TYPE_EMPTY: |
562 | 562 | // No-type defaults to string |
563 | 563 | default: |
564 | - $value = "'" . $this->db_escape((string)$value) . "'"; |
|
564 | + $value = "'".$this->db_escape((string) $value)."'"; |
|
565 | 565 | break; |
566 | 566 | } |
567 | 567 | |
@@ -589,7 +589,7 @@ discard block |
||
589 | 589 | if (is_int($fieldName)) { |
590 | 590 | $result[$fieldName] = $fieldValue; |
591 | 591 | } else { |
592 | - $result[$fieldName] = "`{$fieldName}` = " . $this->castAsDbValue($fieldValue); |
|
592 | + $result[$fieldName] = "`{$fieldName}` = ".$this->castAsDbValue($fieldValue); |
|
593 | 593 | } |
594 | 594 | } |
595 | 595 | |
@@ -618,7 +618,7 @@ discard block |
||
618 | 618 | if (is_int($fieldName)) { |
619 | 619 | $result[$fieldName] = $fieldValue; |
620 | 620 | } else { |
621 | - $result[$fieldName] = "`{$fieldName}` = `{$fieldName}` + (" . $this->castAsDbValue($fieldValue) . ")"; |
|
621 | + $result[$fieldName] = "`{$fieldName}` = `{$fieldName}` + (".$this->castAsDbValue($fieldValue).")"; |
|
622 | 622 | } |
623 | 623 | } |
624 | 624 | |
@@ -649,7 +649,7 @@ discard block |
||
649 | 649 | } |
650 | 650 | |
651 | 651 | foreach ($fields as $key => $value) { |
652 | - $result[$key] = "`" . $this->db_escape($value) . "`"; |
|
652 | + $result[$key] = "`".$this->db_escape($value)."`"; |
|
653 | 653 | } |
654 | 654 | |
655 | 655 | return $result; |
@@ -705,10 +705,10 @@ discard block |
||
705 | 705 | $this->isWatching = true; |
706 | 706 | $msg = "\$query = \"{$query}\"\n\r"; |
707 | 707 | if (!empty($_POST)) { |
708 | - $msg .= "\n\r" . dump($_POST, '$_POST'); |
|
708 | + $msg .= "\n\r".dump($_POST, '$_POST'); |
|
709 | 709 | } |
710 | 710 | if (!empty($_GET)) { |
711 | - $msg .= "\n\r" . dump($_GET, '$_GET'); |
|
711 | + $msg .= "\n\r".dump($_GET, '$_GET'); |
|
712 | 712 | } |
713 | 713 | classSupernova::$debug->warning($msg, "Watching user {$user['id']}", 399, array('base_dump' => true)); |
714 | 714 | $this->isWatching = false; |
@@ -723,7 +723,7 @@ discard block |
||
723 | 723 | |
724 | 724 | global $user, $dm_change_legit, $mm_change_legit; |
725 | 725 | |
726 | - switch(true) { |
|
726 | + switch (true) { |
|
727 | 727 | case stripos($query, 'RUNCATE TABL') != false: |
728 | 728 | case stripos($query, 'ROP TABL') != false: |
729 | 729 | case stripos($query, 'ENAME TABL') != false: |
@@ -734,37 +734,37 @@ discard block |
||
734 | 734 | case stripos($query, 'RPG_POINTS') != false && stripos(trim($query), 'UPDATE ') === 0 && !$dm_change_legit: |
735 | 735 | case stripos($query, 'METAMATTER') != false && stripos(trim($query), 'UPDATE ') === 0 && !$mm_change_legit: |
736 | 736 | case stripos($query, 'AUTHLEVEL') != false && $user['authlevel'] < 3 && stripos($query, 'SELECT') !== 0: |
737 | - $report = "Hacking attempt (" . date("d.m.Y H:i:s") . " - [" . time() . "]):\n"; |
|
737 | + $report = "Hacking attempt (".date("d.m.Y H:i:s")." - [".time()."]):\n"; |
|
738 | 738 | $report .= ">Database Inforamation\n"; |
739 | - $report .= "\tID - " . $user['id'] . "\n"; |
|
740 | - $report .= "\tUser - " . $user['username'] . "\n"; |
|
741 | - $report .= "\tAuth level - " . $user['authlevel'] . "\n"; |
|
742 | - $report .= "\tAdmin Notes - " . $user['adminNotes'] . "\n"; |
|
743 | - $report .= "\tCurrent Planet - " . $user['current_planet'] . "\n"; |
|
744 | - $report .= "\tUser IP - " . $user['user_lastip'] . "\n"; |
|
745 | - $report .= "\tUser IP at Reg - " . $user['ip_at_reg'] . "\n"; |
|
746 | - $report .= "\tUser Agent- " . $_SERVER['HTTP_USER_AGENT'] . "\n"; |
|
747 | - $report .= "\tCurrent Page - " . $user['current_page'] . "\n"; |
|
748 | - $report .= "\tRegister Time - " . $user['register_time'] . "\n"; |
|
739 | + $report .= "\tID - ".$user['id']."\n"; |
|
740 | + $report .= "\tUser - ".$user['username']."\n"; |
|
741 | + $report .= "\tAuth level - ".$user['authlevel']."\n"; |
|
742 | + $report .= "\tAdmin Notes - ".$user['adminNotes']."\n"; |
|
743 | + $report .= "\tCurrent Planet - ".$user['current_planet']."\n"; |
|
744 | + $report .= "\tUser IP - ".$user['user_lastip']."\n"; |
|
745 | + $report .= "\tUser IP at Reg - ".$user['ip_at_reg']."\n"; |
|
746 | + $report .= "\tUser Agent- ".$_SERVER['HTTP_USER_AGENT']."\n"; |
|
747 | + $report .= "\tCurrent Page - ".$user['current_page']."\n"; |
|
748 | + $report .= "\tRegister Time - ".$user['register_time']."\n"; |
|
749 | 749 | $report .= "\n"; |
750 | 750 | |
751 | 751 | $report .= ">Query Information\n"; |
752 | - $report .= "\tQuery - " . $query . "\n"; |
|
752 | + $report .= "\tQuery - ".$query."\n"; |
|
753 | 753 | $report .= "\n"; |
754 | 754 | |
755 | 755 | $report .= ">\$_SERVER Information\n"; |
756 | - $report .= "\tIP - " . $_SERVER['REMOTE_ADDR'] . "\n"; |
|
757 | - $report .= "\tHost Name - " . $_SERVER['HTTP_HOST'] . "\n"; |
|
758 | - $report .= "\tUser Agent - " . $_SERVER['HTTP_USER_AGENT'] . "\n"; |
|
759 | - $report .= "\tRequest Method - " . $_SERVER['REQUEST_METHOD'] . "\n"; |
|
760 | - $report .= "\tCame From - " . $_SERVER['HTTP_REFERER'] . "\n"; |
|
761 | - $report .= "\tPage is - " . $_SERVER['SCRIPT_NAME'] . "\n"; |
|
762 | - $report .= "\tUses Port - " . $_SERVER['REMOTE_PORT'] . "\n"; |
|
763 | - $report .= "\tServer Protocol - " . $_SERVER['SERVER_PROTOCOL'] . "\n"; |
|
756 | + $report .= "\tIP - ".$_SERVER['REMOTE_ADDR']."\n"; |
|
757 | + $report .= "\tHost Name - ".$_SERVER['HTTP_HOST']."\n"; |
|
758 | + $report .= "\tUser Agent - ".$_SERVER['HTTP_USER_AGENT']."\n"; |
|
759 | + $report .= "\tRequest Method - ".$_SERVER['REQUEST_METHOD']."\n"; |
|
760 | + $report .= "\tCame From - ".$_SERVER['HTTP_REFERER']."\n"; |
|
761 | + $report .= "\tPage is - ".$_SERVER['SCRIPT_NAME']."\n"; |
|
762 | + $report .= "\tUses Port - ".$_SERVER['REMOTE_PORT']."\n"; |
|
763 | + $report .= "\tServer Protocol - ".$_SERVER['SERVER_PROTOCOL']."\n"; |
|
764 | 764 | |
765 | 765 | $report .= "\n--------------------------------------------------------------------------------------------------\n"; |
766 | 766 | |
767 | - $fp = fopen(SN_ROOT_PHYSICAL . 'badqrys.txt', 'a'); |
|
767 | + $fp = fopen(SN_ROOT_PHYSICAL.'badqrys.txt', 'a'); |
|
768 | 768 | fwrite($fp, $report); |
769 | 769 | fclose($fp); |
770 | 770 | |
@@ -785,7 +785,7 @@ discard block |
||
785 | 785 | $prefix_length = strlen($this->db_prefix); |
786 | 786 | |
787 | 787 | $tl = array(); |
788 | - while($row = $this->db_fetch($query)) { |
|
788 | + while ($row = $this->db_fetch($query)) { |
|
789 | 789 | foreach ($row as $table_name) { |
790 | 790 | if (strpos($table_name, $this->db_prefix) === 0) { |
791 | 791 | $table_name = substr($table_name, $prefix_length); |
@@ -916,7 +916,7 @@ discard block |
||
916 | 916 | if (is_bool($query)) { |
917 | 917 | throw new Exception('Result of SHOW STATUS command is boolean - which should never happen. Connection to DB is lost?'); |
918 | 918 | } |
919 | - while($row = db_fetch($query)) { |
|
919 | + while ($row = db_fetch($query)) { |
|
920 | 920 | $result[$row['Variable_name']] = $row['Value']; |
921 | 921 | } |
922 | 922 |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * @param db_mysql|null $db |
87 | 87 | */ |
88 | 88 | public static function setDb($db = null) { |
89 | - if(empty($db) || !($db instanceof db_mysql)) { |
|
89 | + if (empty($db) || !($db instanceof db_mysql)) { |
|
90 | 90 | $db = null; |
91 | 91 | } |
92 | 92 | static::$db = !empty($db) || !class_exists('classSupernova', false) ? $db : classSupernova::$db; |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | public function dbLoad($dbId, $lockSkip = false) { |
150 | 150 | $dbId = idval($dbId); |
151 | 151 | if ($dbId <= 0) { |
152 | - classSupernova::$debug->error(get_called_class() . '::' . __METHOD__ . ' $dbId not positive = ' . $dbId); |
|
152 | + classSupernova::$debug->error(get_called_class().'::'.__METHOD__.' $dbId not positive = '.$dbId); |
|
153 | 153 | |
154 | 154 | return; |
155 | 155 | } |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | $this->dbGetLockById($this->_dbId); |
162 | 162 | } |
163 | 163 | |
164 | - $db_row = classSupernova::$db->doSelectFetch("SELECT * FROM `{{" . static::$_table . "}}` WHERE `" . static::$_dbIdFieldName . "` = " . $this->_dbId . " LIMIT 1 FOR UPDATE;"); |
|
164 | + $db_row = classSupernova::$db->doSelectFetch("SELECT * FROM `{{".static::$_table."}}` WHERE `".static::$_dbIdFieldName."` = ".$this->_dbId." LIMIT 1 FOR UPDATE;"); |
|
165 | 165 | if (empty($db_row)) { |
166 | 166 | return; |
167 | 167 | } |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | if ($this->isNew()) { |
194 | 194 | // No DB_ID - new unit |
195 | 195 | if ($this->isEmpty()) { |
196 | - classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - object is empty on ' . get_called_class() . '::dbSave'); |
|
196 | + classSupernova::$debug->error(__FILE__.':'.__LINE__.' - object is empty on '.get_called_class().'::dbSave'); |
|
197 | 197 | } |
198 | 198 | $this->dbInsert(); |
199 | 199 | } else { |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | $this->dbDelete(); |
203 | 203 | } else { |
204 | 204 | if (!sn_db_transaction_check(false)) { |
205 | - classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - transaction should always be started on ' . get_called_class() . '::dbUpdate'); |
|
205 | + classSupernova::$debug->error(__FILE__.':'.__LINE__.' - transaction should always be started on '.get_called_class().'::dbUpdate'); |
|
206 | 206 | } |
207 | 207 | $this->dbUpdate(); |
208 | 208 | } |
@@ -230,13 +230,13 @@ discard block |
||
230 | 230 | // TODO - protected |
231 | 231 | public function dbInsert() { |
232 | 232 | if (!$this->isNew()) { |
233 | - classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - record db_id is not empty on ' . get_called_class() . '::dbInsert'); |
|
233 | + classSupernova::$debug->error(__FILE__.':'.__LINE__.' - record db_id is not empty on '.get_called_class().'::dbInsert'); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | $fieldSet = $this->dbMakeFieldSet(false); |
237 | 237 | |
238 | 238 | if (!static::$db->doInsertSet(static::$_table, $fieldSet)) { |
239 | - classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - error saving record ' . get_called_class() . '::dbInsert'); |
|
239 | + classSupernova::$debug->error(__FILE__.':'.__LINE__.' - error saving record '.get_called_class().'::dbInsert'); |
|
240 | 240 | } |
241 | 241 | $this->_dbId = static::$db->db_insert_id(); |
242 | 242 | |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | public function dbUpdate() { |
251 | 251 | // TODO - Update |
252 | 252 | if ($this->isNew()) { |
253 | - classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - unit db_id is empty on dbUpdate'); |
|
253 | + classSupernova::$debug->error(__FILE__.':'.__LINE__.' - unit db_id is empty on dbUpdate'); |
|
254 | 254 | } |
255 | 255 | $this->db_field_update($this->dbMakeFieldUpdate()); |
256 | 256 | } |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | // TODO - protected |
262 | 262 | public function dbDelete() { |
263 | 263 | if ($this->isNew()) { |
264 | - classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - unit db_id is empty on dbDelete'); |
|
264 | + classSupernova::$debug->error(__FILE__.':'.__LINE__.' - unit db_id is empty on dbDelete'); |
|
265 | 265 | } |
266 | 266 | classSupernova::$gc->db->doDeleteRowWhere(static::$_table, array(static::$_dbIdFieldName => $this->_dbId)); |
267 | 267 | $this->_dbId = 0; |
@@ -447,7 +447,7 @@ discard block |
||
447 | 447 | } |
448 | 448 | } |
449 | 449 | |
450 | - if(empty($set)) { |
|
450 | + if (empty($set)) { |
|
451 | 451 | $theResult = true; |
452 | 452 | } else { |
453 | 453 | $theResult = classSupernova::$db->doUpdateRowAdjust( |
@@ -72,12 +72,12 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public static function db_ally_insert($ally_name_unsafe, $ally_tag_unsafe, $userId) { |
74 | 74 | $ally = classSupernova::$db->doInsertSet(TABLE_ALLIANCE, array( |
75 | - 'ally_name' => (string)$ally_name_unsafe, |
|
76 | - 'ally_tag' => (string)$ally_tag_unsafe, |
|
75 | + 'ally_name' => (string) $ally_name_unsafe, |
|
76 | + 'ally_tag' => (string) $ally_tag_unsafe, |
|
77 | 77 | 'ally_owner' => $userId, |
78 | - 'ally_owner_range' => (string)classLocale::$lang['ali_leaderRank'], |
|
79 | - 'ally_members' => (int)1, |
|
80 | - 'ranklist' => (string)(classLocale::$lang['ali_defaultRankName'] . ",0,0,0,0,0"), |
|
78 | + 'ally_owner_range' => (string) classLocale::$lang['ali_leaderRank'], |
|
79 | + 'ally_members' => (int) 1, |
|
80 | + 'ranklist' => (string) (classLocale::$lang['ali_defaultRankName'].",0,0,0,0,0"), |
|
81 | 81 | 'ally_register_time' => SN_TIME_NOW, |
82 | 82 | )); |
83 | 83 | |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | * @param $ally |
162 | 162 | */ |
163 | 163 | public static function db_ally_update_by_changeset($ally_changeset, $ally) { |
164 | - classSupernova::$db->doUpdateComplex("UPDATE {{alliance}} SET " . implode(',', $ally_changeset) . " WHERE `id`='{$ally['id']}' LIMIT 1;"); |
|
164 | + classSupernova::$db->doUpdateComplex("UPDATE {{alliance}} SET ".implode(',', $ally_changeset)." WHERE `id`='{$ally['id']}' LIMIT 1;"); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | ->where('`user_as_ally` IS NULL') |
24 | 24 | ->orderBy(array('`id` DESC')); |
25 | 25 | |
26 | - return (string)$query->selectValue(); |
|
26 | + return (string) $query->selectValue(); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -48,15 +48,15 @@ discard block |
||
48 | 48 | static::buildDBQ() |
49 | 49 | ->field('id') |
50 | 50 | ->where("`user_as_ally` IS NULL") |
51 | - ->where("`user_bot` = " . USER_BOT_PLAYER) |
|
51 | + ->where("`user_bot` = ".USER_BOT_PLAYER) |
|
52 | 52 | ->setForUpdate(); |
53 | 53 | |
54 | 54 | return $query->selectIterator(); |
55 | 55 | } |
56 | 56 | |
57 | 57 | public static function db_user_lock_with_target_owner_and_acs($user, $planet = array()) { |
58 | - $query = "SELECT 1 FROM `{{users}}` WHERE `id` = " . idval($user['id']) . |
|
59 | - (!empty($planet['id_owner']) ? ' OR `id` = ' . idval($planet['id_owner']) : '') |
|
58 | + $query = "SELECT 1 FROM `{{users}}` WHERE `id` = ".idval($user['id']). |
|
59 | + (!empty($planet['id_owner']) ? ' OR `id` = '.idval($planet['id_owner']) : '') |
|
60 | 60 | . " FOR UPDATE"; |
61 | 61 | |
62 | 62 | static::getDb()->doSelect($query); |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | FROM `{{users}}` |
74 | 74 | WHERE |
75 | 75 | `user_as_ally` IS NULL" . |
76 | - ($online ? ' AND `onlinetime` > ' . (SN_TIME_NOW - classSupernova::$config->game_users_online_timeout) : '') |
|
76 | + ($online ? ' AND `onlinetime` > '.(SN_TIME_NOW - classSupernova::$config->game_users_online_timeout) : '') |
|
77 | 77 | )); |
78 | 78 | } |
79 | 79 | |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | ->fieldCount('r.id', 'referral_count') |
96 | 96 | ->fieldSingleFunction('sum', 'r.dark_matter', 'referral_dm') |
97 | 97 | ->join('LEFT JOIN {{referrals}} as r on r.id_partner = u.id') |
98 | - ->where($online ? "`onlinetime` >= " . intval(SN_TIME_NOW - classSupernova::$config->game_users_online_timeout) : 'user_as_ally IS NULL') |
|
98 | + ->where($online ? "`onlinetime` >= ".intval(SN_TIME_NOW - classSupernova::$config->game_users_online_timeout) : 'user_as_ally IS NULL') |
|
99 | 99 | ->groupBy('u.id') |
100 | 100 | ->orderBy("user_as_ally, {$sort} ASC"); |
101 | 101 | |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | ->where('(`user_birthday_celebrated` IS NULL OR DATE_ADD(`user_birthday_celebrated`, INTERVAL 1 YEAR) < CURRENT_DATE)') |
114 | 114 | ->where('`user_as_ally` IS NULL') |
115 | 115 | ->having('`days_after_birthday` >= 0') |
116 | - ->having('`days_after_birthday` < ' . intval($config_user_birthday_range)) |
|
116 | + ->having('`days_after_birthday` < '.intval($config_user_birthday_range)) |
|
117 | 117 | ->setForUpdate(); |
118 | 118 | |
119 | 119 | $result = $query->selectIterator(); |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | $username_safe = db_escape($like ? strtolower($username_unsafe) : $username_unsafe); // тут на самом деле strtolower() лишняя, но пусть будет |
218 | 218 | |
219 | 219 | $user = classSupernova::$db->doSelectFetch( |
220 | - "SELECT * FROM {{users}} WHERE `username` " . ($like ? 'LIKE' : '=') . " '{$username_safe}'" |
|
220 | + "SELECT * FROM {{users}} WHERE `username` ".($like ? 'LIKE' : '=')." '{$username_safe}'" |
|
221 | 221 | . " FOR UPDATE" |
222 | 222 | ); |
223 | 223 | classSupernova::$gc->snCache->cache_set(LOC_USER, $user); // В кэш-юзер так же заполнять индексы |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | |
268 | 268 | |
269 | 269 | public static function db_user_list_set_mass_mail(&$owners_list, $set) { |
270 | - return classSupernova::$gc->cacheOperator->db_upd_record_list(LOC_USER, $set, !empty($owners_list) ? '`id` IN (' . implode(',', $owners_list) . ');' : ''); |
|
270 | + return classSupernova::$gc->cacheOperator->db_upd_record_list(LOC_USER, $set, !empty($owners_list) ? '`id` IN ('.implode(',', $owners_list).');' : ''); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | public static function db_user_list_set_by_ally_and_rank($ally_id, $ally_rank_id, $set) { |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | * @param array $playerArray |
283 | 283 | */ |
284 | 284 | public static function renderNameAndCoordinates($playerArray) { |
285 | - return "{$playerArray['username']} " . uni_render_coordinates($playerArray); |
|
285 | + return "{$playerArray['username']} ".uni_render_coordinates($playerArray); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | /** |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | foreach ($playerRowFieldChanges as $resourceId => $value) { |
314 | 314 | $fields[pname_resource_name($resourceId)] = $value; |
315 | 315 | } |
316 | - if(!empty($fields)) { |
|
316 | + if (!empty($fields)) { |
|
317 | 317 | classSupernova::$gc->db->doUpdateRowAdjust( |
318 | 318 | TABLE_USERS, |
319 | 319 | array(), |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if((!defined('SN_IN_MARKET') || SN_IN_MARKET !== true) && (!defined('SN_IN_ALLY') || SN_IN_ALLY !== true)) { |
|
3 | +if ((!defined('SN_IN_MARKET') || SN_IN_MARKET !== true) && (!defined('SN_IN_ALLY') || SN_IN_ALLY !== true)) { |
|
4 | 4 | classSupernova::$debug->error("Attempt to call market page mode {$mode} directly - not from market.php", 'Forbidden', 403); |
5 | 5 | } |
6 | 6 | |
@@ -26,11 +26,11 @@ discard block |
||
26 | 26 | |
27 | 27 | // $dm_db_name = pname_resource_name(RES_DARK_MATTER); |
28 | 28 | $exchangeTo = in_array($exchangeTo = sys_get_param_int('exchangeTo'), sn_get_groups('resources_trader')) ? $exchangeTo : 0; |
29 | - if($exchangeTo && is_array($tradeList = $_POST['spend'])) { |
|
29 | + if ($exchangeTo && is_array($tradeList = $_POST['spend'])) { |
|
30 | 30 | $value = 0; |
31 | 31 | |
32 | 32 | sn_db_transaction_start(); |
33 | - if($planetrow['id_owner']) { |
|
33 | + if ($planetrow['id_owner']) { |
|
34 | 34 | $global_data = sys_o_get_updated($user, $planetrow, SN_TIME_NOW); |
35 | 35 | $planetrow = $global_data['planet']; |
36 | 36 | } |
@@ -40,26 +40,26 @@ discard block |
||
40 | 40 | } |
41 | 41 | |
42 | 42 | $fields = array(); |
43 | - foreach(sn_get_groups('resources_trader') as $resource_id) { |
|
43 | + foreach (sn_get_groups('resources_trader') as $resource_id) { |
|
44 | 44 | $amount = floatval($tradeList[$resource_id]); |
45 | - if($amount < 0) { |
|
45 | + if ($amount < 0) { |
|
46 | 46 | classSupernova::$debug->error('Trying to supply negative resource amount on Black Market Page', 'Hack Attempt', 305); |
47 | 47 | } |
48 | 48 | |
49 | - if($resource_id == RES_DARK_MATTER && $exchangeTo == RES_DARK_MATTER) { |
|
49 | + if ($resource_id == RES_DARK_MATTER && $exchangeTo == RES_DARK_MATTER) { |
|
50 | 50 | continue; |
51 | 51 | } |
52 | 52 | |
53 | 53 | $sign = '+'; |
54 | - if($exchangeTo == RES_DARK_MATTER) { |
|
54 | + if ($exchangeTo == RES_DARK_MATTER) { |
|
55 | 55 | $amount = floor($tradeList[RES_DARK_MATTER] / 3 * $rates[RES_DARK_MATTER] / $rates[$resource_id]); |
56 | 56 | $value += $amount; |
57 | 57 | } else { |
58 | 58 | $value += floor($amount * $rates[$resource_id] / $rates[$exchangeTo]); |
59 | - if($resource_id == RES_DARK_MATTER) { |
|
59 | + if ($resource_id == RES_DARK_MATTER) { |
|
60 | 60 | $amount = 0; |
61 | 61 | } else { |
62 | - if(mrc_get_level($user, $planetrow, $resource_id, true) < $amount) { |
|
62 | + if (mrc_get_level($user, $planetrow, $resource_id, true) < $amount) { |
|
63 | 63 | $intError = MARKET_NO_RESOURCES; |
64 | 64 | break; |
65 | 65 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | } |
69 | 69 | } |
70 | 70 | |
71 | - if($amount) { |
|
71 | + if ($amount) { |
|
72 | 72 | $fields[pname_resource_name($resource_id)] = "{$sign} {$amount}"; |
73 | 73 | } |
74 | 74 | } |
@@ -78,8 +78,8 @@ discard block |
||
78 | 78 | $intError = $value <= 0 ? MARKET_ZERO_DEAL : $intError; |
79 | 79 | $intError = mrc_get_level($user, null, RES_DARK_MATTER) < $operation_cost ? MARKET_NO_DM : $intError; |
80 | 80 | |
81 | - if($intError == MARKET_DEAL) { |
|
82 | - if($exchangeTo != RES_DARK_MATTER) { |
|
81 | + if ($intError == MARKET_DEAL) { |
|
82 | + if ($exchangeTo != RES_DARK_MATTER) { |
|
83 | 83 | $amountExchangeTo = floor($value); |
84 | 84 | $fields[pname_resource_name($exchangeTo)] = $amountExchangeTo; |
85 | 85 | } |
@@ -115,8 +115,8 @@ discard block |
||
115 | 115 | 'EXCHANGE_TO_RESOURCE_ID' => $exchangeTo, |
116 | 116 | )); |
117 | 117 | |
118 | - foreach(sn_get_groups('resources_trader') as $resource_id) { |
|
119 | - if($resource_id == RES_DARK_MATTER) { |
|
118 | + foreach (sn_get_groups('resources_trader') as $resource_id) { |
|
119 | + if ($resource_id == RES_DARK_MATTER) { |
|
120 | 120 | $amount = floor(mrc_get_level($user, null, RES_DARK_MATTER) - classSupernova::$config->rpg_cost_trader); |
121 | 121 | } else { |
122 | 122 | $amount = floor(mrc_get_level($user, $planetrow, $resource_id)); |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if(!defined('SN_IN_ALLY') || SN_IN_ALLY !== true) { |
|
3 | +if (!defined('SN_IN_ALLY') || SN_IN_ALLY !== true) { |
|
4 | 4 | classSupernova::$debug->error("Attempt to call ALLIANCE page mode {$mode} directly - not from alliance.php", 'Forbidden', 403); |
5 | 5 | } |
6 | 6 | |
@@ -8,16 +8,16 @@ discard block |
||
8 | 8 | message(classLocale::$lang['Denied_access'], classLocale::$lang['requests_admin']); |
9 | 9 | } |
10 | 10 | |
11 | -if($d = sys_get_param_id('d')) { |
|
11 | +if ($d = sys_get_param_id('d')) { |
|
12 | 12 | DBStaticAlly::db_ally_request_deny($d); |
13 | 13 | } |
14 | 14 | |
15 | 15 | $id_user = sys_get_param_id('id_user'); |
16 | 16 | |
17 | -if($id_user) { |
|
17 | +if ($id_user) { |
|
18 | 18 | $ally_name_safe = db_escape($ally['ally_name']); |
19 | 19 | $ally_tag_safe = db_escape($ally['ally_tag']); |
20 | - DBStaticUser::db_user_set_by_id($id_user, "`ally_id` = '{$ally['id']}', `ally_name` = '{$ally_name_safe}', `ally_tag` = '{$ally_tag_safe}', `ally_register_time` = " . SN_TIME_NOW . ", `ally_rank_id` = 0"); |
|
20 | + DBStaticUser::db_user_set_by_id($id_user, "`ally_id` = '{$ally['id']}', `ally_name` = '{$ally_name_safe}', `ally_tag` = '{$ally_tag_safe}', `ally_register_time` = ".SN_TIME_NOW.", `ally_rank_id` = 0"); |
|
21 | 21 | classSupernova::$db->doUpdateRowAdjust( |
22 | 22 | TABLE_ALLIANCE, |
23 | 23 | array(), |