@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | $user_auth_level = isset($user['authlevel']) ? $user['authlevel'] : AUTH_LEVEL_ANONYMOUS; |
37 | 37 | |
38 | 38 | $mode = sys_get_param_int('mode'); |
39 | - switch($mode) { |
|
39 | + switch ($mode) { |
|
40 | 40 | case CHAT_MODE_ALLY: |
41 | 41 | $template_result['ALLY'] = intval($user['ally_id']); |
42 | 42 | $page_title = classLocale::$lang['chat_ally']; |
@@ -49,12 +49,12 @@ discard block |
||
49 | 49 | } |
50 | 50 | |
51 | 51 | $template_result['.']['smiles'] = array(); |
52 | - foreach($supernova->design['smiles'] as $auth_level => $replaces) { |
|
53 | - if($auth_level > $user_auth_level) { |
|
52 | + foreach ($supernova->design['smiles'] as $auth_level => $replaces) { |
|
53 | + if ($auth_level > $user_auth_level) { |
|
54 | 54 | continue; |
55 | 55 | } |
56 | 56 | |
57 | - foreach($replaces as $bbcode => $filename) { |
|
57 | + foreach ($replaces as $bbcode => $filename) { |
|
58 | 58 | $template_result['.']['smiles'][] = array( |
59 | 59 | 'BBCODE' => $bbcode, |
60 | 60 | 'FILENAME' => $filename, |
@@ -77,11 +77,11 @@ discard block |
||
77 | 77 | define('IN_AJAX', true); |
78 | 78 | $skip_fleet_update = true; |
79 | 79 | |
80 | - if(classSupernova::$config->_MODE != CACHER_NO_CACHE && classSupernova::$config->chat_timeout && SN_TIME_MICRO - classSupernova::$config->array_get('users', $user['id'], 'chat_last_activity') > classSupernova::$config->chat_timeout) { |
|
80 | + if (classSupernova::$config->_MODE != CACHER_NO_CACHE && classSupernova::$config->chat_timeout && SN_TIME_MICRO - classSupernova::$config->array_get('users', $user['id'], 'chat_last_activity') > classSupernova::$config->chat_timeout) { |
|
81 | 81 | die(); |
82 | 82 | } |
83 | 83 | |
84 | - if(($message = sys_get_param_str('message')) && $user['username']) { |
|
84 | + if (($message = sys_get_param_str('message')) && $user['username']) { |
|
85 | 85 | $ally_id = sys_get_param('ally') && $user['ally_id'] ? $user['ally_id'] : 0; |
86 | 86 | $nick = db_escape(player_nick_compact(player_nick_render_current_to_array($user, array('color' => true, 'icons' => true, 'ally' => !$ally_id)))); |
87 | 87 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | $skip_fleet_update = true; |
104 | 104 | |
105 | 105 | $history = sys_get_param_str('history'); |
106 | - if(!$history) { |
|
106 | + if (!$history) { |
|
107 | 107 | classSupernova::$config->array_set('users', $user['id'], 'chat_last_refresh', SN_TIME_MICRO); |
108 | 108 | } |
109 | 109 | |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | $last_message = ''; |
112 | 112 | $alliance = 0; |
113 | 113 | $template_result['.']['chat'] = array(); |
114 | - if(!$history && classSupernova::$config->_MODE != CACHER_NO_CACHE && classSupernova::$config->chat_timeout && SN_TIME_MICRO - classSupernova::$config->array_get('users', $user['id'], 'chat_last_activity') > classSupernova::$config->chat_timeout) { |
|
114 | + if (!$history && classSupernova::$config->_MODE != CACHER_NO_CACHE && classSupernova::$config->chat_timeout && SN_TIME_MICRO - classSupernova::$config->array_get('users', $user['id'], 'chat_last_activity') > classSupernova::$config->chat_timeout) { |
|
115 | 115 | $result['disable'] = true; |
116 | 116 | $template_result['.']['chat'][] = array( |
117 | 117 | 'TIME' => date(FMT_DATE_TIME, htmlentities(SN_CLIENT_TIME_LOCAL, ENT_QUOTES, 'utf-8')), |
@@ -124,11 +124,11 @@ discard block |
||
124 | 124 | |
125 | 125 | $where_add = ''; |
126 | 126 | $last_message = 0; |
127 | - if($history) { |
|
127 | + if ($history) { |
|
128 | 128 | $rows = db_chat_message_count_by_ally($alliance); |
129 | 129 | $page_count = ceil($rows['CNT'] / $page_limit); |
130 | 130 | |
131 | - for($i = 0; $i < $page_count; $i++) { |
|
131 | + for ($i = 0; $i < $page_count; $i++) { |
|
132 | 132 | $template_result['.']['page'][] = array( |
133 | 133 | 'NUMBER' => $i |
134 | 134 | ); |
@@ -142,12 +142,12 @@ discard block |
||
142 | 142 | |
143 | 143 | $start_row = $page * $page_limit; |
144 | 144 | $query = db_chat_message_get_page($alliance, $where_add, $start_row, $page_limit); |
145 | - while($chat_row = db_fetch($query)) { |
|
145 | + while ($chat_row = db_fetch($query)) { |
|
146 | 146 | // Little magik here - to retain HTML codes from DB and stripping HTML codes from nick |
147 | 147 | $chat_row['user'] = player_nick_render_to_html($chat_row['user']); |
148 | 148 | $nick_stripped = htmlentities(strip_tags($chat_row['user']), ENT_QUOTES, 'utf-8'); |
149 | 149 | $nick = str_replace(strip_tags($chat_row['user']), $nick_stripped, $chat_row['user']); |
150 | - if(!$history) { |
|
150 | + if (!$history) { |
|
151 | 151 | $nick = "<span style=\"cursor: pointer;\" onclick=\"addSmiley('({$nick_stripped})');\">{$nick}</span>"; |
152 | 152 | } |
153 | 153 | |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | $template = gettemplate('chat_messages', $template); |
173 | 173 | $template->assign_recursive($template_result); |
174 | 174 | |
175 | - if($history) { |
|
175 | + if ($history) { |
|
176 | 176 | display($template, "{$classLocale['chat_history']} - {$classLocale[$alliance ? 'chat_ally' : 'chat_common']}", true, '', false, true); |
177 | 177 | } else { |
178 | 178 | $result['last_message'] = $last_message; |
@@ -14,24 +14,24 @@ discard block |
||
14 | 14 | function sn_function_call($func_name, $func_arg = array()) { |
15 | 15 | // All data in classSupernova::$functions should be normalized to valid 'callable' state: '<function_name>'|array('<object_name>', '<method_name>') |
16 | 16 | |
17 | - if(is_array(classSupernova::$functions[$func_name]) && !is_callable(classSupernova::$functions[$func_name])) { |
|
17 | + if (is_array(classSupernova::$functions[$func_name]) && !is_callable(classSupernova::$functions[$func_name])) { |
|
18 | 18 | // Chain-callable functions should be made as following: |
19 | 19 | // 1. Never use incomplete calls with parameters "by default" |
20 | 20 | // 2. Reserve last parameter for cumulative result |
21 | 21 | // 3. Use same format for original value and cumulative result (if there is original value) |
22 | 22 | // 4. Honor cumulative result |
23 | 23 | // 5. Return cumulative result |
24 | - foreach(classSupernova::$functions[$func_name] as $func_chain_name) { |
|
24 | + foreach (classSupernova::$functions[$func_name] as $func_chain_name) { |
|
25 | 25 | // По идее - это уже тут не нужно, потому что оно все должно быть callable к этому моменту |
26 | 26 | // Но для старых модулей... |
27 | - if(is_callable($func_chain_name)) { |
|
27 | + if (is_callable($func_chain_name)) { |
|
28 | 28 | $result = call_user_func_array($func_chain_name, $func_arg); |
29 | 29 | } |
30 | 30 | } |
31 | 31 | } else { |
32 | 32 | // TODO: This is left for backward compatibility. Appropriate code should be rewrote! |
33 | 33 | $func_name = isset(classSupernova::$functions[$func_name]) && is_callable(classSupernova::$functions[$func_name]) ? classSupernova::$functions[$func_name] : ('sn_' . $func_name); |
34 | - if(is_callable($func_name)) { |
|
34 | + if (is_callable($func_name)) { |
|
35 | 35 | $result = call_user_func_array($func_name, $func_arg); |
36 | 36 | } |
37 | 37 | } |
@@ -46,9 +46,9 @@ discard block |
||
46 | 46 | * @param string $page_name - имя страницы, для которого должен был быть выполнен хук |
47 | 47 | */ |
48 | 48 | function execute_hooks(&$hook_list, &$template, $hook_type = null, $page_name = null) { |
49 | - if(!empty($hook_list)) { |
|
50 | - foreach($hook_list as $hook) { |
|
51 | - if(is_callable($hook_call = (is_string($hook) ? $hook : (is_array($hook) ? $hook['callable'] : $hook->callable)))) { |
|
49 | + if (!empty($hook_list)) { |
|
50 | + foreach ($hook_list as $hook) { |
|
51 | + if (is_callable($hook_call = (is_string($hook) ? $hook : (is_array($hook) ? $hook['callable'] : $hook->callable)))) { |
|
52 | 52 | $template = call_user_func($hook_call, $template, $hook_type, $page_name); |
53 | 53 | } |
54 | 54 | } |
@@ -138,9 +138,9 @@ discard block |
||
138 | 138 | |
139 | 139 | function pretty_number($n, $floor = true, $color = false, $limit = false, $style = null) { |
140 | 140 | $n = floatval($n); |
141 | - if(is_int($floor)) { |
|
141 | + if (is_int($floor)) { |
|
142 | 142 | $n = round($n, $floor); // , PHP_ROUND_HALF_DOWN |
143 | - } elseif($floor === true) { |
|
143 | + } elseif ($floor === true) { |
|
144 | 144 | $n = floor($n); |
145 | 145 | $floor = 0; |
146 | 146 | } else { |
@@ -150,14 +150,14 @@ discard block |
||
150 | 150 | $ret = $n; |
151 | 151 | |
152 | 152 | $suffix = ''; |
153 | - if($limit) { |
|
154 | - if($ret > 0) { |
|
155 | - while($ret > $limit) { |
|
153 | + if ($limit) { |
|
154 | + if ($ret > 0) { |
|
155 | + while ($ret > $limit) { |
|
156 | 156 | $suffix .= 'k'; |
157 | 157 | $ret = round($ret / 1000); |
158 | 158 | } |
159 | 159 | } else { |
160 | - while($ret < -$limit) { |
|
160 | + while ($ret < -$limit) { |
|
161 | 161 | $suffix .= 'k'; |
162 | 162 | $ret = round($ret / 1000); |
163 | 163 | } |
@@ -167,16 +167,16 @@ discard block |
||
167 | 167 | $ret = number_format($ret, $floor, ',', '.'); |
168 | 168 | $ret .= $suffix; |
169 | 169 | |
170 | - if($color !== false) { |
|
171 | - if($color === true) { |
|
170 | + if ($color !== false) { |
|
171 | + if ($color === true) { |
|
172 | 172 | $class = $n == 0 ? 'zero' : ($n > 0 ? 'positive' : 'negative'); |
173 | - } elseif($color >= 0) { |
|
173 | + } elseif ($color >= 0) { |
|
174 | 174 | $class = $n == $color ? 'zero' : ($n < $color ? 'positive' : 'negative'); |
175 | 175 | } else { |
176 | 176 | $class = ($n == -$color) ? 'zero' : ($n < -$color ? 'negative' : 'positive'); |
177 | 177 | } |
178 | 178 | |
179 | - if(!isset($style)) { |
|
179 | + if (!isset($style)) { |
|
180 | 180 | $ret = "<span class='{$class}'>{$ret}</span>"; |
181 | 181 | } else { |
182 | 182 | $ret = $style ? $ret = $class : $ret = array('text' => $ret, 'class' => $class); |
@@ -301,11 +301,11 @@ discard block |
||
301 | 301 | |
302 | 302 | function sys_get_param_phone($param_name, $default = '') { |
303 | 303 | $phone_raw = sys_get_param_str_unsafe($param_name, $default = ''); |
304 | - if($phone_raw) { |
|
304 | + if ($phone_raw) { |
|
305 | 305 | $phone = $phone_raw[0] == '+' ? '+' : ''; |
306 | - for($i = 0; $i < strlen($phone_raw); $i++) { |
|
306 | + for ($i = 0; $i < strlen($phone_raw); $i++) { |
|
307 | 307 | $ord = ord($phone_raw[$i]); |
308 | - if($ord >= 48 && $ord <= 57) { |
|
308 | + if ($ord >= 48 && $ord <= 57) { |
|
309 | 309 | $phone .= $phone_raw[$i]; |
310 | 310 | } |
311 | 311 | } |
@@ -322,14 +322,14 @@ discard block |
||
322 | 322 | } |
323 | 323 | |
324 | 324 | function CheckAbandonPlanetState(&$planet) { |
325 | - if($planet['destruyed'] && $planet['destruyed'] <= SN_TIME_NOW) { |
|
325 | + if ($planet['destruyed'] && $planet['destruyed'] <= SN_TIME_NOW) { |
|
326 | 326 | db_planet_delete_by_id($planet['id']); |
327 | 327 | } |
328 | 328 | } |
329 | 329 | |
330 | 330 | function eco_get_total_cost($unit_id, $unit_level) { |
331 | 331 | static $rate, $sn_group_resources_all, $sn_group_resources_loot; |
332 | - if(!$rate) { |
|
332 | + if (!$rate) { |
|
333 | 333 | $sn_group_resources_all = sn_get_groups('resources_all'); |
334 | 334 | $sn_group_resources_loot = sn_get_groups('resources_loot'); |
335 | 335 | |
@@ -339,19 +339,19 @@ discard block |
||
339 | 339 | } |
340 | 340 | |
341 | 341 | $unit_cost_data = get_unit_param($unit_id, 'cost'); |
342 | - if(!is_array($unit_cost_data)) { |
|
342 | + if (!is_array($unit_cost_data)) { |
|
343 | 343 | return array('total' => 0); |
344 | 344 | } |
345 | 345 | $factor = isset($unit_cost_data['factor']) ? $unit_cost_data['factor'] : 1; |
346 | 346 | $cost_array = array(BUILD_CREATE => array(), 'total' => 0); |
347 | 347 | $unit_level = $unit_level > 0 ? $unit_level : 0; |
348 | - foreach($unit_cost_data as $resource_id => $resource_amount) { |
|
349 | - if(!in_array($resource_id, $sn_group_resources_all)) { |
|
348 | + foreach ($unit_cost_data as $resource_id => $resource_amount) { |
|
349 | + if (!in_array($resource_id, $sn_group_resources_all)) { |
|
350 | 350 | continue; |
351 | 351 | } |
352 | 352 | // $cost_array[BUILD_CREATE][$resource_id] = $resource_amount * ($factor == 1 ? $unit_level : ((pow($factor, $unit_level) - $factor) / ($factor - 1))); |
353 | 353 | $cost_array[BUILD_CREATE][$resource_id] = round($resource_amount * ($factor == 1 ? $unit_level : ((1 - pow($factor, $unit_level)) / (1 - $factor)))); |
354 | - if(in_array($resource_id, $sn_group_resources_loot)) { |
|
354 | + if (in_array($resource_id, $sn_group_resources_loot)) { |
|
355 | 355 | $cost_array['total'] += $cost_array[BUILD_CREATE][$resource_id] * $rate[$resource_id]; |
356 | 356 | } |
357 | 357 | } |
@@ -435,19 +435,19 @@ discard block |
||
435 | 435 | $mercenary_level = 0; |
436 | 436 | $unit_db_name = pname_resource_name($unit_id); |
437 | 437 | |
438 | - if(in_array($unit_id, sn_get_groups(array('plans', 'mercenaries', 'tech', 'artifacts')))) { |
|
438 | + if (in_array($unit_id, sn_get_groups(array('plans', 'mercenaries', 'tech', 'artifacts')))) { |
|
439 | 439 | $unit = classSupernova::db_get_unit_by_location($user['id'], LOC_USER, $user['id'], $unit_id); |
440 | 440 | $mercenary_level = is_array($unit) && $unit['unit_level'] ? $unit['unit_level'] : 0; |
441 | - } elseif(in_array($unit_id, sn_get_groups(array('structures', 'fleet', 'defense')))) { |
|
441 | + } elseif (in_array($unit_id, sn_get_groups(array('structures', 'fleet', 'defense')))) { |
|
442 | 442 | $unit = classSupernova::db_get_unit_by_location(is_array($user) ? $user['id'] : $planet['id_owner'], LOC_PLANET, $planet['id'], $unit_id); |
443 | 443 | $mercenary_level = is_array($unit) && $unit['unit_level'] ? $unit['unit_level'] : 0; |
444 | - } elseif(in_array($unit_id, sn_get_groups('governors'))) { |
|
444 | + } elseif (in_array($unit_id, sn_get_groups('governors'))) { |
|
445 | 445 | $mercenary_level = $unit_id == $planet['PLANET_GOVERNOR_ID'] ? $planet['PLANET_GOVERNOR_LEVEL'] : 0; |
446 | - } elseif($unit_id == RES_DARK_MATTER) { |
|
446 | + } elseif ($unit_id == RES_DARK_MATTER) { |
|
447 | 447 | $mercenary_level = $user[$unit_db_name] + ($plain || $user['user_as_ally'] ? 0 : classSupernova::$auth->account->account_metamatter); |
448 | - } elseif($unit_id == RES_METAMATTER) { |
|
448 | + } elseif ($unit_id == RES_METAMATTER) { |
|
449 | 449 | $mercenary_level = classSupernova::$auth->account->account_metamatter; //$user[$unit_db_name]; |
450 | - } elseif(in_array($unit_id, sn_get_groups(array('resources_loot'))) || $unit_id == UNIT_SECTOR) { |
|
450 | + } elseif (in_array($unit_id, sn_get_groups(array('resources_loot'))) || $unit_id == UNIT_SECTOR) { |
|
451 | 451 | $mercenary_level = !empty($planet) ? $planet[$unit_db_name] : $user[$unit_db_name]; |
452 | 452 | } |
453 | 453 | |
@@ -457,19 +457,19 @@ discard block |
||
457 | 457 | function mrc_modify_value(&$user, $planet = array(), $mercenaries, $value) { return sn_function_call(__FUNCTION__, array(&$user, $planet, $mercenaries, $value)); } |
458 | 458 | |
459 | 459 | function sn_mrc_modify_value(&$user, $planet = array(), $mercenaries, $value, $base_value = null) { |
460 | - if(!is_array($mercenaries)) { |
|
460 | + if (!is_array($mercenaries)) { |
|
461 | 461 | $mercenaries = array($mercenaries); |
462 | 462 | } |
463 | 463 | |
464 | 464 | $base_value = isset($base_value) ? $base_value : $value; |
465 | 465 | |
466 | - foreach($mercenaries as $mercenary_id) { |
|
466 | + foreach ($mercenaries as $mercenary_id) { |
|
467 | 467 | $mercenary_level = mrc_get_level($user, $planet, $mercenary_id); |
468 | 468 | |
469 | 469 | $mercenary = get_unit_param($mercenary_id); |
470 | 470 | $mercenary_bonus = $mercenary['bonus']; |
471 | 471 | |
472 | - switch($mercenary['bonus_type']) { |
|
472 | + switch ($mercenary['bonus_type']) { |
|
473 | 473 | case BONUS_PERCENT_CUMULATIVE: |
474 | 474 | $value *= 1 + $mercenary_level * $mercenary_bonus / 100; |
475 | 475 | break; |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | $allowed_length = strlen($allowed_chars); |
501 | 501 | |
502 | 502 | $random_string = ''; |
503 | - for($i = 0; $i < $length; $i++) { |
|
503 | + for ($i = 0; $i < $length; $i++) { |
|
504 | 504 | $random_string .= $allowed_chars[mt_rand(0, $allowed_length - 1)]; |
505 | 505 | } |
506 | 506 | |
@@ -520,12 +520,12 @@ discard block |
||
520 | 520 | |
521 | 521 | $options = ''; |
522 | 522 | $option_list = array(); |
523 | - foreach($user_option_list as $option_group_id => $option_group) { |
|
523 | + foreach ($user_option_list as $option_group_id => $option_group) { |
|
524 | 524 | $option_list[$option_group_id] = array(); |
525 | - foreach($option_group as $option_name => $option_value) { |
|
526 | - if(!isset($user[$option_name])) { |
|
525 | + foreach ($option_group as $option_name => $option_value) { |
|
526 | + if (!isset($user[$option_name])) { |
|
527 | 527 | $user[$option_name] = $option_value; |
528 | - } elseif($user[$option_name] == '') { |
|
528 | + } elseif ($user[$option_name] == '') { |
|
529 | 529 | $user[$option_name] = 0; |
530 | 530 | } |
531 | 531 | $options .= "{$option_name}^{$user[$option_name]}|"; |
@@ -545,16 +545,16 @@ discard block |
||
545 | 545 | $option_list = array(); |
546 | 546 | $option_string_list = explode('|', $user['options']); |
547 | 547 | |
548 | - foreach($option_string_list as $option_string) { |
|
548 | + foreach ($option_string_list as $option_string) { |
|
549 | 549 | list($option_name, $option_value) = explode('^', $option_string); |
550 | 550 | $option_list[$option_name] = $option_value; |
551 | 551 | } |
552 | 552 | |
553 | 553 | $final_list = array(); |
554 | - foreach($user_option_list as $option_group_id => $option_group) { |
|
554 | + foreach ($user_option_list as $option_group_id => $option_group) { |
|
555 | 555 | $final_list[$option_group_id] = array(); |
556 | - foreach($option_group as $option_name => $option_value) { |
|
557 | - if(!isset($option_list[$option_name])) { |
|
556 | + foreach ($option_group as $option_name => $option_value) { |
|
557 | + if (!isset($option_list[$option_name])) { |
|
558 | 558 | $option_list[$option_name] = $option_value; |
559 | 559 | } |
560 | 560 | $user[$option_name] = $final_list[$option_group_id][$option_name] = $option_list[$option_name]; |
@@ -568,12 +568,12 @@ discard block |
||
568 | 568 | |
569 | 569 | function sys_unit_str2arr($fleet_string) { |
570 | 570 | $fleet_array = array(); |
571 | - if(!empty($fleet_string)) { |
|
571 | + if (!empty($fleet_string)) { |
|
572 | 572 | $arrTemp = explode(';', $fleet_string); |
573 | - foreach($arrTemp as $temp) { |
|
574 | - if($temp) { |
|
573 | + foreach ($arrTemp as $temp) { |
|
574 | + if ($temp) { |
|
575 | 575 | $temp = explode(',', $temp); |
576 | - if(!empty($temp[0]) && !empty($temp[1])) { |
|
576 | + if (!empty($temp[0]) && !empty($temp[1])) { |
|
577 | 577 | $fleet_array[$temp[0]] += $temp[1]; |
578 | 578 | } |
579 | 579 | } |
@@ -585,13 +585,13 @@ discard block |
||
585 | 585 | |
586 | 586 | function sys_unit_arr2str($unit_list) { |
587 | 587 | $fleet_string = array(); |
588 | - if(isset($unit_list)) { |
|
589 | - if(!is_array($unit_list)) { |
|
588 | + if (isset($unit_list)) { |
|
589 | + if (!is_array($unit_list)) { |
|
590 | 590 | $unit_list = array($unit_list => 1); |
591 | 591 | } |
592 | 592 | |
593 | - foreach($unit_list as $unit_id => $unit_count) { |
|
594 | - if($unit_id && $unit_count) { |
|
593 | + foreach ($unit_list as $unit_id => $unit_count) { |
|
594 | + if ($unit_id && $unit_count) { |
|
595 | 595 | $fleet_string[] = "{$unit_id},{$unit_count}"; |
596 | 596 | } |
597 | 597 | } |
@@ -617,7 +617,7 @@ discard block |
||
617 | 617 | $body = str_replace("\r\n", "\n", $body); |
618 | 618 | $body = str_replace("\n", "\r\n", $body); |
619 | 619 | |
620 | - if($html) { |
|
620 | + if ($html) { |
|
621 | 621 | $body = '<html><head><base href="' . SN_ROOT_VIRTUAL . '"></head><body>' . nl2br($body) . '</body></html>'; |
622 | 622 | } |
623 | 623 | |
@@ -661,21 +661,21 @@ discard block |
||
661 | 661 | } |
662 | 662 | |
663 | 663 | function sn_ali_fill_user_ally(&$user) { |
664 | - if(!$user['ally_id']) { |
|
664 | + if (!$user['ally_id']) { |
|
665 | 665 | return; |
666 | 666 | } |
667 | 667 | |
668 | - if(!isset($user['ally'])) { |
|
668 | + if (!isset($user['ally'])) { |
|
669 | 669 | $user['ally'] = db_ally_get_by_id($user['ally_id']); |
670 | 670 | } |
671 | 671 | |
672 | - if(!isset($user['ally']['player'])) { |
|
672 | + if (!isset($user['ally']['player'])) { |
|
673 | 673 | $user['ally']['player'] = db_user_by_id($user['ally']['ally_user_id'], true, '*', false); |
674 | 674 | } |
675 | 675 | } |
676 | 676 | |
677 | 677 | function sn_get_url_contents($url) { |
678 | - if(function_exists('curl_init')) { |
|
678 | + if (function_exists('curl_init')) { |
|
679 | 679 | $crl = curl_init(); |
680 | 680 | $timeout = 5; |
681 | 681 | curl_setopt($crl, CURLOPT_URL, $url); |
@@ -710,10 +710,10 @@ discard block |
||
710 | 710 | |
711 | 711 | function get_ship_data($ship_id, $user) { |
712 | 712 | $ship_data = array(); |
713 | - if(in_array($ship_id, sn_get_groups(array('fleet', 'missile')))) { |
|
714 | - foreach(get_unit_param($ship_id, 'engine') as $engine_info) { |
|
713 | + if (in_array($ship_id, sn_get_groups(array('fleet', 'missile')))) { |
|
714 | + foreach (get_unit_param($ship_id, 'engine') as $engine_info) { |
|
715 | 715 | $tech_level = intval(mrc_get_level($user, null, $engine_info['tech'])); |
716 | - if(empty($ship_data) || $tech_level >= $engine_info['min_level']) { |
|
716 | + if (empty($ship_data) || $tech_level >= $engine_info['min_level']) { |
|
717 | 717 | $ship_data = $engine_info; |
718 | 718 | $ship_data['tech_level'] = $tech_level; |
719 | 719 | } |
@@ -725,7 +725,7 @@ discard block |
||
725 | 725 | return $ship_data; |
726 | 726 | } |
727 | 727 | |
728 | -if(!function_exists('strptime')) { |
|
728 | +if (!function_exists('strptime')) { |
|
729 | 729 | function strptime($date, $format) { |
730 | 730 | $masks = array( |
731 | 731 | '%d' => '(?P<d>[0-9]{2})', |
@@ -738,12 +738,12 @@ discard block |
||
738 | 738 | ); |
739 | 739 | |
740 | 740 | $rexep = "#" . strtr(preg_quote($format), $masks) . "#"; |
741 | - if(preg_match($rexep, $date, $out)) { |
|
741 | + if (preg_match($rexep, $date, $out)) { |
|
742 | 742 | $ret = array( |
743 | - "tm_sec" => (int)$out['S'], |
|
744 | - "tm_min" => (int)$out['M'], |
|
745 | - "tm_hour" => (int)$out['H'], |
|
746 | - "tm_mday" => (int)$out['d'], |
|
743 | + "tm_sec" => (int) $out['S'], |
|
744 | + "tm_min" => (int) $out['M'], |
|
745 | + "tm_hour" => (int) $out['H'], |
|
746 | + "tm_mday" => (int) $out['d'], |
|
747 | 747 | "tm_mon" => $out['m'] ? $out['m'] - 1 : 0, |
748 | 748 | "tm_year" => $out['Y'] > 1900 ? $out['Y'] - 1900 : 0, |
749 | 749 | ); |
@@ -758,7 +758,7 @@ discard block |
||
758 | 758 | function sn_sys_sector_buy($redirect = 'overview.php') { |
759 | 759 | global $user, $planetrow; |
760 | 760 | |
761 | - if(!sys_get_param_str('sector_buy') || $planetrow['planet_type'] != PT_PLANET) { |
|
761 | + if (!sys_get_param_str('sector_buy') || $planetrow['planet_type'] != PT_PLANET) { |
|
762 | 762 | return; |
763 | 763 | } |
764 | 764 | |
@@ -771,9 +771,9 @@ discard block |
||
771 | 771 | // $planetrow = $planetrow['planet']; |
772 | 772 | $sector_cost = eco_get_build_data($user, $planetrow, UNIT_SECTOR, mrc_get_level($user, $planetrow, UNIT_SECTOR), true); |
773 | 773 | $sector_cost = $sector_cost[BUILD_CREATE][RES_DARK_MATTER]; |
774 | - if($sector_cost <= mrc_get_level($user, null, RES_DARK_MATTER)) { |
|
774 | + if ($sector_cost <= mrc_get_level($user, null, RES_DARK_MATTER)) { |
|
775 | 775 | $planet_name_text = uni_render_planet($planetrow); |
776 | - if(rpg_points_change($user['id'], RPG_SECTOR, -$sector_cost, sprintf(classLocale::$lang['sys_sector_purchase_log'], |
|
776 | + if (rpg_points_change($user['id'], RPG_SECTOR, -$sector_cost, sprintf(classLocale::$lang['sys_sector_purchase_log'], |
|
777 | 777 | $user['username'], $user['id'], $planet_name_text, classLocale::$lang['sys_planet_type'][$planetrow['planet_type']], $planetrow['id'], $sector_cost) |
778 | 778 | )) { |
779 | 779 | $sector_db_name = pname_resource_name(UNIT_SECTOR); |
@@ -788,30 +788,30 @@ discard block |
||
788 | 788 | } |
789 | 789 | |
790 | 790 | function sn_sys_handler_add(&$functions, $handler_list, $class_module_name = '', $sub_type = '') { |
791 | - if(isset($handler_list) && is_array($handler_list) && !empty($handler_list)) { |
|
792 | - foreach($handler_list as $function_name => $function_data) { |
|
793 | - if(is_string($function_data)) { |
|
791 | + if (isset($handler_list) && is_array($handler_list) && !empty($handler_list)) { |
|
792 | + foreach ($handler_list as $function_name => $function_data) { |
|
793 | + if (is_string($function_data)) { |
|
794 | 794 | $override_with = &$function_data; |
795 | - } elseif(isset($function_data['callable'])) { |
|
795 | + } elseif (isset($function_data['callable'])) { |
|
796 | 796 | $override_with = &$function_data['callable']; |
797 | 797 | } |
798 | 798 | |
799 | 799 | $overwrite = $override_with[0] == '*'; |
800 | - if($overwrite) { |
|
800 | + if ($overwrite) { |
|
801 | 801 | $override_with = substr($override_with, 1); |
802 | 802 | } |
803 | 803 | |
804 | - if(($point_position = strpos($override_with, '.')) === false && $class_module_name) { |
|
804 | + if (($point_position = strpos($override_with, '.')) === false && $class_module_name) { |
|
805 | 805 | $override_with = array($class_module_name, $override_with); |
806 | - } elseif($point_position == 0) { |
|
806 | + } elseif ($point_position == 0) { |
|
807 | 807 | $override_with = substr($override_with, 1); |
808 | - } elseif($point_position > 0) { |
|
808 | + } elseif ($point_position > 0) { |
|
809 | 809 | $override_with = array(substr($override_with, 0, $point_position), substr($override_with, $point_position + 1)); |
810 | 810 | } |
811 | 811 | |
812 | - if($overwrite) { |
|
812 | + if ($overwrite) { |
|
813 | 813 | $functions[$function_name] = array(); |
814 | - } elseif(!isset($functions[$function_name])) { |
|
814 | + } elseif (!isset($functions[$function_name])) { |
|
815 | 815 | $functions[$function_name] = array(); |
816 | 816 | $sn_function_name = 'sn_' . $function_name . ($sub_type ? '_' . $sub_type : ''); |
817 | 817 | $functions[$function_name][] = $sn_function_name; |
@@ -827,15 +827,15 @@ discard block |
||
827 | 827 | function player_nick_render_to_html($result, $options = false) { |
828 | 828 | // TODO - обрабатывать разные случаи: $user, $render_nick_array, $string |
829 | 829 | |
830 | - if(is_string($result) && strpos($result, ':{i:')) { |
|
830 | + if (is_string($result) && strpos($result, ':{i:')) { |
|
831 | 831 | $result = player_nick_uncompact($result); |
832 | 832 | } |
833 | 833 | |
834 | - if(is_array($result)) { |
|
835 | - if(isset($result['id'])) { |
|
834 | + if (is_array($result)) { |
|
835 | + if (isset($result['id'])) { |
|
836 | 836 | $result = player_nick_render_current_to_array($result, $options); |
837 | 837 | } |
838 | - if(!isset($result[NICK_HTML])) { |
|
838 | + if (!isset($result[NICK_HTML])) { |
|
839 | 839 | $result = player_nick_render_array_to_html($result); |
840 | 840 | } |
841 | 841 | unset($result[NICK_HTML]); |
@@ -858,7 +858,7 @@ discard block |
||
858 | 858 | try { |
859 | 859 | $result = unserialize($nick_string); |
860 | 860 | // ksort($result); // Всегда ksort-ый в player_nick_compact() |
861 | - } catch(exception $e) { |
|
861 | + } catch (exception $e) { |
|
862 | 862 | $result = strpos($nick_string, ':{i:') ? null : $nick_string; // fallback if it is already string - for old chat strings, for example |
863 | 863 | } |
864 | 864 | |
@@ -871,20 +871,20 @@ discard block |
||
871 | 871 | global $user; |
872 | 872 | |
873 | 873 | // ALL STRING ARE UNSAFE!!! |
874 | - if(isset($nick_array[NICK_BIRTHSDAY])) { |
|
874 | + if (isset($nick_array[NICK_BIRTHSDAY])) { |
|
875 | 875 | $result[NICK_BIRTHSDAY] = '<img src="design/images/birthday.png" />'; |
876 | 876 | } |
877 | 877 | |
878 | - if(isset($nick_array[NICK_VACATION])) { |
|
878 | + if (isset($nick_array[NICK_VACATION])) { |
|
879 | 879 | $result[NICK_VACATION] = '<img src="design/images/icon_vacation.png" />'; |
880 | 880 | } |
881 | 881 | |
882 | - if(isset($nick_array[NICK_GENDER])) { |
|
882 | + if (isset($nick_array[NICK_GENDER])) { |
|
883 | 883 | $result[NICK_GENDER] = '<img src="' . ($user['dpath'] ? $user['dpath'] : DEFAULT_SKINPATH) . 'images/gender_' . $nick_array[NICK_GENDER] . '.png" />'; |
884 | 884 | } |
885 | 885 | |
886 | - if(isset($nick_array[NICK_AUTH_LEVEL]) || isset($nick_array[NICK_PREMIUM])) { |
|
887 | - switch($nick_array[NICK_AUTH_LEVEL]) { |
|
886 | + if (isset($nick_array[NICK_AUTH_LEVEL]) || isset($nick_array[NICK_PREMIUM])) { |
|
887 | + switch ($nick_array[NICK_AUTH_LEVEL]) { |
|
888 | 888 | case 4: |
889 | 889 | $highlight = classSupernova::$config->chat_highlight_developer; |
890 | 890 | break; |
@@ -905,20 +905,20 @@ discard block |
||
905 | 905 | $highlight = isset($nick_array[NICK_PREMIUM]) ? classSupernova::$config->chat_highlight_premium : ''; |
906 | 906 | } |
907 | 907 | |
908 | - if($highlight) { |
|
908 | + if ($highlight) { |
|
909 | 909 | list($result[NICK_HIGHLIGHT], $result[NICK_HIGHLIGHT_END]) = explode('$1', $highlight); |
910 | 910 | } |
911 | 911 | // $result = preg_replace("#(.+)#", $highlight, $result); |
912 | 912 | } |
913 | 913 | |
914 | - if(isset($nick_array[NICK_CLASS])) { |
|
914 | + if (isset($nick_array[NICK_CLASS])) { |
|
915 | 915 | $result[NICK_CLASS] = '<span ' . $nick_array[NICK_CLASS] . '>'; |
916 | 916 | $result[NICK_CLASS_END] = '</span>'; |
917 | 917 | } |
918 | 918 | |
919 | 919 | $result[NICK_NICK] = sys_safe_output($nick_array[NICK_NICK]); |
920 | 920 | |
921 | - if(isset($nick_array[NICK_ALLY])) { |
|
921 | + if (isset($nick_array[NICK_ALLY])) { |
|
922 | 922 | $result[NICK_ALLY] = '[' . sys_safe_output($nick_array[NICK_ALLY]) . ']'; |
923 | 923 | } |
924 | 924 | |
@@ -942,32 +942,32 @@ discard block |
||
942 | 942 | */ |
943 | 943 | |
944 | 944 | |
945 | - if($render_user['user_birthday'] && ($options === true || isset($options['icons']) || isset($options['birthday'])) && (date('Y', SN_TIME_NOW) . date('-m-d', strtotime($render_user['user_birthday'])) == date('Y-m-d', SN_TIME_NOW))) { |
|
945 | + if ($render_user['user_birthday'] && ($options === true || isset($options['icons']) || isset($options['birthday'])) && (date('Y', SN_TIME_NOW) . date('-m-d', strtotime($render_user['user_birthday'])) == date('Y-m-d', SN_TIME_NOW))) { |
|
946 | 946 | $result[NICK_BIRTHSDAY] = ''; |
947 | 947 | } |
948 | 948 | |
949 | - if($options === true || (isset($options['icons']) && $options['icons']) || (isset($options['gender']) && $options['gender'])) { |
|
949 | + if ($options === true || (isset($options['icons']) && $options['icons']) || (isset($options['gender']) && $options['gender'])) { |
|
950 | 950 | $result[NICK_GENDER] = $render_user['gender'] == GENDER_UNKNOWN ? 'unknown' : ($render_user['gender'] == GENDER_FEMALE ? 'female' : 'male'); |
951 | 951 | } |
952 | 952 | |
953 | - if(($options === true || (isset($options['icons']) && $options['icons']) || (isset($options['vacancy']) && $options['vacancy'])) && $render_user['vacation']) { |
|
953 | + if (($options === true || (isset($options['icons']) && $options['icons']) || (isset($options['vacancy']) && $options['vacancy'])) && $render_user['vacation']) { |
|
954 | 954 | $result[NICK_VACATION] = $render_user['vacation']; |
955 | 955 | } |
956 | 956 | |
957 | - if($options === true || (isset($options['color']) && $options['color'])) { |
|
958 | - if($user_auth_level = $render_user['authlevel']) { |
|
957 | + if ($options === true || (isset($options['color']) && $options['color'])) { |
|
958 | + if ($user_auth_level = $render_user['authlevel']) { |
|
959 | 959 | $result[NICK_AUTH_LEVEL] = $user_auth_level; |
960 | 960 | } |
961 | - if($user_premium = mrc_get_level($render_user, null, UNIT_PREMIUM)) { |
|
961 | + if ($user_premium = mrc_get_level($render_user, null, UNIT_PREMIUM)) { |
|
962 | 962 | $result[NICK_PREMIUM] = $user_premium; |
963 | 963 | } |
964 | 964 | } |
965 | 965 | |
966 | - if((isset($options['class']) && $options['class'])) { |
|
966 | + if ((isset($options['class']) && $options['class'])) { |
|
967 | 967 | $result[NICK_CLASS] = (isset($result_options[NICK_CLASS]) ? ' ' . $result_options[NICK_CLASS] : '') . $options['class']; |
968 | 968 | } |
969 | 969 | |
970 | - if($render_user['ally_tag'] && ($options === true || (isset($options['ally']) && $options['ally']))) { |
|
970 | + if ($render_user['ally_tag'] && ($options === true || (isset($options['ally']) && $options['ally']))) { |
|
971 | 971 | $result[NICK_ALLY] = $render_user['ally_tag']; |
972 | 972 | } |
973 | 973 | |
@@ -983,25 +983,25 @@ discard block |
||
983 | 983 | |
984 | 984 | $user_skip_list = array(); |
985 | 985 | |
986 | - if(classSupernova::$config->stats_hide_admins) { |
|
986 | + if (classSupernova::$config->stats_hide_admins) { |
|
987 | 987 | $user_skip_list[] = '`authlevel` > 0'; |
988 | 988 | } |
989 | 989 | |
990 | - if(classSupernova::$config->stats_hide_player_list) { |
|
990 | + if (classSupernova::$config->stats_hide_player_list) { |
|
991 | 991 | $temp = explode(',', classSupernova::$config->stats_hide_player_list); |
992 | - foreach($temp as $user_id) { |
|
992 | + foreach ($temp as $user_id) { |
|
993 | 993 | $user_id = floatval($user_id); |
994 | - if($user_id) { |
|
994 | + if ($user_id) { |
|
995 | 995 | $user_skip_list[] = '`id` = ' . $user_id; |
996 | 996 | } |
997 | 997 | } |
998 | 998 | } |
999 | 999 | |
1000 | - if(!empty($user_skip_list)) { |
|
1000 | + if (!empty($user_skip_list)) { |
|
1001 | 1001 | $user_skip_list = implode(' OR ', $user_skip_list); |
1002 | 1002 | $user_skip_query = db_user_list($user_skip_list); |
1003 | - if(!empty($user_skip_query)) { |
|
1004 | - foreach($user_skip_query as $user_skip_row) { |
|
1003 | + if (!empty($user_skip_query)) { |
|
1004 | + foreach ($user_skip_query as $user_skip_row) { |
|
1005 | 1005 | $result[$user_skip_row['id']] = $user_skip_row['id']; |
1006 | 1006 | } |
1007 | 1007 | } |
@@ -1032,7 +1032,7 @@ discard block |
||
1032 | 1032 | |
1033 | 1033 | function sn_sn_get_groups($groups, &$result) { |
1034 | 1034 | $result = is_array($result) ? $result : array(); |
1035 | - foreach($groups = is_array($groups) ? $groups : array($groups) as $group_name) { |
|
1035 | + foreach ($groups = is_array($groups) ? $groups : array($groups) as $group_name) { |
|
1036 | 1036 | $result += is_array($a_group = get_unit_param(UNIT_GROUP, $group_name)) ? $a_group : array(); |
1037 | 1037 | } |
1038 | 1038 | |
@@ -1058,8 +1058,8 @@ discard block |
||
1058 | 1058 | $sn_data_unit = get_unit_param($unit_id); |
1059 | 1059 | |
1060 | 1060 | $result = is_array($result) ? $result : array(); |
1061 | - if($sn_data_unit[$field] && !($sn_data_unit[P_UNIT_TYPE] == UNIT_MERCENARIES && classSupernova::$config->empire_mercenary_temporary)) { |
|
1062 | - foreach($sn_data_unit[$field] as $require_id => $require_level) { |
|
1061 | + if ($sn_data_unit[$field] && !($sn_data_unit[P_UNIT_TYPE] == UNIT_MERCENARIES && classSupernova::$config->empire_mercenary_temporary)) { |
|
1062 | + foreach ($sn_data_unit[$field] as $require_id => $require_level) { |
|
1063 | 1063 | $level_got = mrc_get_level($user, $planetrow, $require_id); |
1064 | 1064 | $level_basic = mrc_get_level($user, $planetrow, $require_id, false, true); |
1065 | 1065 | $result[] = array( |
@@ -1083,16 +1083,16 @@ discard block |
||
1083 | 1083 | |
1084 | 1084 | $ranks = array(); |
1085 | 1085 | |
1086 | - if($ally['ranklist']) { |
|
1086 | + if ($ally['ranklist']) { |
|
1087 | 1087 | $str_ranks = explode(';', $ally['ranklist']); |
1088 | - foreach($str_ranks as $str_rank) { |
|
1089 | - if(!$str_rank) { |
|
1088 | + foreach ($str_ranks as $str_rank) { |
|
1089 | + if (!$str_rank) { |
|
1090 | 1090 | continue; |
1091 | 1091 | } |
1092 | 1092 | |
1093 | 1093 | $tmp = explode(',', $str_rank); |
1094 | 1094 | $rank_id = count($ranks); |
1095 | - foreach($ally_rights as $key => $value) { |
|
1095 | + foreach ($ally_rights as $key => $value) { |
|
1096 | 1096 | $ranks[$rank_id][$value] = $tmp[$key]; |
1097 | 1097 | } |
1098 | 1098 | } |
@@ -1108,8 +1108,8 @@ discard block |
||
1108 | 1108 | } |
1109 | 1109 | |
1110 | 1110 | function array_merge_recursive_numeric($array1, $array2) { |
1111 | - if(!empty($array2) && is_array($array2)) { |
|
1112 | - foreach($array2 as $key => $value) { |
|
1111 | + if (!empty($array2) && is_array($array2)) { |
|
1112 | + foreach ($array2 as $key => $value) { |
|
1113 | 1113 | // if(!isset($array1[$key]) || !is_array($array1[$key])) { |
1114 | 1114 | // $array1[$key] = $value; |
1115 | 1115 | // } else { |
@@ -1124,7 +1124,7 @@ discard block |
||
1124 | 1124 | |
1125 | 1125 | function sn_sys_array_cumulative_sum(&$array) { |
1126 | 1126 | $accum = 0; |
1127 | - foreach($array as &$value) { |
|
1127 | + foreach ($array as &$value) { |
|
1128 | 1128 | $accum += $value; |
1129 | 1129 | $value = $accum; |
1130 | 1130 | } |
@@ -1134,7 +1134,7 @@ discard block |
||
1134 | 1134 | $sn_data_density = sn_get_groups('planet_density'); |
1135 | 1135 | $density_price_chart = array(); |
1136 | 1136 | |
1137 | - foreach($sn_data_density as $density_id => $density_data) { |
|
1137 | + foreach ($sn_data_density as $density_id => $density_data) { |
|
1138 | 1138 | // Отсекаем записи с RARITY = 0 - служебные записи и супер-ядра |
1139 | 1139 | $density_data[UNIT_PLANET_DENSITY_RARITY] ? $density_price_chart[$density_id] = $density_data[UNIT_PLANET_DENSITY_RARITY] : false; |
1140 | 1140 | } |
@@ -1142,7 +1142,7 @@ discard block |
||
1142 | 1142 | |
1143 | 1143 | $total_rarity = array_sum($density_price_chart); |
1144 | 1144 | |
1145 | - foreach($density_price_chart as &$density_data) { |
|
1145 | + foreach ($density_price_chart as &$density_data) { |
|
1146 | 1146 | $density_data = ceil($total_rarity / $density_data * $planet_row['field_max'] * PLANET_DENSITY_TO_DARK_MATTER_RATE); |
1147 | 1147 | } |
1148 | 1148 | |
@@ -1150,16 +1150,16 @@ discard block |
||
1150 | 1150 | } |
1151 | 1151 | |
1152 | 1152 | function sn_sys_planet_core_transmute(&$user, &$planetrow) { |
1153 | - if(!sys_get_param_str('transmute')) { |
|
1153 | + if (!sys_get_param_str('transmute')) { |
|
1154 | 1154 | return array(); |
1155 | 1155 | } |
1156 | 1156 | |
1157 | 1157 | try { |
1158 | - if($planetrow['planet_type'] != PT_PLANET) { |
|
1158 | + if ($planetrow['planet_type'] != PT_PLANET) { |
|
1159 | 1159 | throw new exception(classLocale::$lang['ov_core_err_not_a_planet'], ERR_ERROR); |
1160 | 1160 | } |
1161 | 1161 | |
1162 | - if($planetrow['density_index'] == ($new_density_index = sys_get_param_id('density_type'))) { |
|
1162 | + if ($planetrow['density_index'] == ($new_density_index = sys_get_param_id('density_type'))) { |
|
1163 | 1163 | throw new exception(classLocale::$lang['ov_core_err_same_density'], ERR_WARNING); |
1164 | 1164 | } |
1165 | 1165 | |
@@ -1173,7 +1173,7 @@ discard block |
||
1173 | 1173 | $planet_density_index = $planetrow['density_index']; |
1174 | 1174 | |
1175 | 1175 | $density_price_chart = planet_density_price_chart($planetrow); |
1176 | - if(!isset($density_price_chart[$new_density_index])) { |
|
1176 | + if (!isset($density_price_chart[$new_density_index])) { |
|
1177 | 1177 | // Hack attempt |
1178 | 1178 | throw new exception(classLocale::$lang['ov_core_err_denisty_type_wrong'], ERR_ERROR); |
1179 | 1179 | } |
@@ -1182,13 +1182,13 @@ discard block |
||
1182 | 1182 | // $transmute_cost = get_unit_param(UNIT_PLANET_DENSITY, 'cost'); |
1183 | 1183 | // $transmute_cost = $transmute_cost[RES_DARK_MATTER] * $density_price_chart[$new_density_index]; |
1184 | 1184 | $transmute_cost = $density_price_chart[$new_density_index]; |
1185 | - if($user_dark_matter < $transmute_cost) { |
|
1185 | + if ($user_dark_matter < $transmute_cost) { |
|
1186 | 1186 | throw new exception(classLocale::$lang['ov_core_err_no_dark_matter'], ERR_ERROR); |
1187 | 1187 | } |
1188 | 1188 | |
1189 | 1189 | $sn_data_planet_density = sn_get_groups('planet_density'); |
1190 | - foreach($sn_data_planet_density as $key => $value) { |
|
1191 | - if($key == $new_density_index) { |
|
1190 | + foreach ($sn_data_planet_density as $key => $value) { |
|
1191 | + if ($key == $new_density_index) { |
|
1192 | 1192 | break; |
1193 | 1193 | } |
1194 | 1194 | $prev_density_index = $key; |
@@ -1219,7 +1219,7 @@ discard block |
||
1219 | 1219 | 'STATUS' => ERR_NONE, |
1220 | 1220 | 'MESSAGE' => sprintf(classLocale::$lang['ov_core_err_none'], classLocale::$lang['uni_planet_density_types'][$planet_density_index], classLocale::$lang['uni_planet_density_types'][$new_density_index], $new_density), |
1221 | 1221 | ); |
1222 | - } catch(exception $e) { |
|
1222 | + } catch (exception $e) { |
|
1223 | 1223 | sn_db_transaction_rollback(); |
1224 | 1224 | $result = array( |
1225 | 1225 | 'STATUS' => $e->getCode(), |
@@ -1232,8 +1232,8 @@ discard block |
||
1232 | 1232 | |
1233 | 1233 | function sn_module_get_active_count($group = '*') { |
1234 | 1234 | $active_modules = 0; |
1235 | - if(isset(sn_module::$sn_module_list[$group]) && is_array(sn_module::$sn_module_list[$group])) { |
|
1236 | - foreach(sn_module::$sn_module_list[$group] as $payment_module) { |
|
1235 | + if (isset(sn_module::$sn_module_list[$group]) && is_array(sn_module::$sn_module_list[$group])) { |
|
1236 | + foreach (sn_module::$sn_module_list[$group] as $payment_module) { |
|
1237 | 1237 | $active_modules += $payment_module->manifest['active']; |
1238 | 1238 | } |
1239 | 1239 | } |
@@ -1244,7 +1244,7 @@ discard block |
||
1244 | 1244 | function get_resource_exchange() { |
1245 | 1245 | static $rates; |
1246 | 1246 | |
1247 | - if(!$rates) { |
|
1247 | + if (!$rates) { |
|
1248 | 1248 | $rates = array( |
1249 | 1249 | RES_METAL => 'rpg_exchange_metal', |
1250 | 1250 | RES_CRYSTAL => 'rpg_exchange_crystal', |
@@ -1252,7 +1252,7 @@ discard block |
||
1252 | 1252 | RES_DARK_MATTER => 'rpg_exchange_darkMatter', |
1253 | 1253 | ); |
1254 | 1254 | |
1255 | - foreach($rates as &$rate) { |
|
1255 | + foreach ($rates as &$rate) { |
|
1256 | 1256 | $rate = classSupernova::$config->$rate; |
1257 | 1257 | } |
1258 | 1258 | } |
@@ -1263,12 +1263,12 @@ discard block |
||
1263 | 1263 | function get_unit_cost_in(&$cost, $in_resource = RES_METAL) { |
1264 | 1264 | static $rates; |
1265 | 1265 | |
1266 | - if(!$rates) { |
|
1266 | + if (!$rates) { |
|
1267 | 1267 | $rates = get_resource_exchange(); |
1268 | 1268 | } |
1269 | 1269 | |
1270 | 1270 | $metal_cost = 0; |
1271 | - foreach($cost as $resource_id => $resource_value) { |
|
1271 | + foreach ($cost as $resource_id => $resource_value) { |
|
1272 | 1272 | $metal_cost += $rates[$resource_id] * $resource_value; |
1273 | 1273 | } |
1274 | 1274 | |
@@ -1278,8 +1278,8 @@ discard block |
||
1278 | 1278 | function get_player_max_expeditons(&$user, $astrotech = -1) { return sn_function_call(__FUNCTION__, array(&$user, $astrotech, &$result)); } |
1279 | 1279 | |
1280 | 1280 | function sn_get_player_max_expeditons(&$user, $astrotech = -1, &$result = 0) { |
1281 | - if($astrotech == -1) { |
|
1282 | - if(!isset($user[UNIT_PLAYER_EXPEDITIONS_MAX])) { |
|
1281 | + if ($astrotech == -1) { |
|
1282 | + if (!isset($user[UNIT_PLAYER_EXPEDITIONS_MAX])) { |
|
1283 | 1283 | $astrotech = mrc_get_level($user, null, TECH_ASTROTECH); |
1284 | 1284 | $user[UNIT_PLAYER_EXPEDITIONS_MAX] = $astrotech >= 1 ? floor(sqrt($astrotech - 1)) : 0; |
1285 | 1285 | } |
@@ -1295,8 +1295,8 @@ discard block |
||
1295 | 1295 | } |
1296 | 1296 | |
1297 | 1297 | function get_player_max_colonies(&$user, $astrotech = -1) { |
1298 | - if($astrotech == -1) { |
|
1299 | - if(!isset($user[UNIT_PLAYER_COLONIES_MAX])) { |
|
1298 | + if ($astrotech == -1) { |
|
1299 | + if (!isset($user[UNIT_PLAYER_COLONIES_MAX])) { |
|
1300 | 1300 | |
1301 | 1301 | $expeditions = get_player_max_expeditons($user); |
1302 | 1302 | $astrotech = mrc_get_level($user, null, TECH_ASTROTECH); |
@@ -1341,10 +1341,10 @@ discard block |
||
1341 | 1341 | |
1342 | 1342 | // pdump($powerup_unit, '$powerup_unit'); |
1343 | 1343 | $level_current = $term_original = $time_left = 0; |
1344 | - if($is_upgrade) { |
|
1344 | + if ($is_upgrade) { |
|
1345 | 1345 | $time_finish = strtotime($powerup_unit['unit_time_finish']); |
1346 | 1346 | $time_left = max(0, $time_finish - SN_TIME_NOW); |
1347 | - if($time_left > 0) { |
|
1347 | + if ($time_left > 0) { |
|
1348 | 1348 | $term_original = $time_finish - strtotime($powerup_unit['unit_time_start']); |
1349 | 1349 | $level_current = $powerup_unit['unit_level']; |
1350 | 1350 | } |
@@ -1352,22 +1352,22 @@ discard block |
||
1352 | 1352 | |
1353 | 1353 | $level_max = $level_max > $powerup_data[P_MAX_STACK] ? $level_max : $powerup_data[P_MAX_STACK]; |
1354 | 1354 | $original_cost = 0; |
1355 | - for($i = 1; $i <= $level_max; $i++) { |
|
1355 | + for ($i = 1; $i <= $level_max; $i++) { |
|
1356 | 1356 | $base_cost = eco_get_total_cost($powerup_id, $i); |
1357 | 1357 | $base_cost = $base_cost[BUILD_CREATE][RES_DARK_MATTER]; |
1358 | - foreach($sn_powerup_buy_discounts as $period => $discount) { |
|
1358 | + foreach ($sn_powerup_buy_discounts as $period => $discount) { |
|
1359 | 1359 | $upgrade_price = floor($base_cost * $discount * $period / PERIOD_MONTH); |
1360 | 1360 | $result[$i][$period] = $upgrade_price; |
1361 | 1361 | $original_cost = $is_upgrade && $i == $level_current && $period <= $term_original ? $upgrade_price : $original_cost; |
1362 | 1362 | } |
1363 | 1363 | } |
1364 | 1364 | |
1365 | - if($is_upgrade && $time_left) { |
|
1365 | + if ($is_upgrade && $time_left) { |
|
1366 | 1366 | $term_original = round($term_original / PERIOD_DAY); |
1367 | 1367 | $time_left = min(floor($time_left / PERIOD_DAY), $term_original); |
1368 | 1368 | $cost_left = $term_original > 0 ? ceil($time_left / $term_original * $original_cost) : 0; |
1369 | 1369 | |
1370 | - array_walk_recursive($result, function (&$value) use ($cost_left) { |
|
1370 | + array_walk_recursive($result, function(&$value) use ($cost_left) { |
|
1371 | 1371 | $value -= $cost_left; |
1372 | 1372 | }); |
1373 | 1373 | } |
@@ -1423,7 +1423,7 @@ discard block |
||
1423 | 1423 | |
1424 | 1424 | function print_rr($var, $capture = false) { |
1425 | 1425 | $print = '<pre>' . htmlspecialchars(print_r($var, true)) . '</pre>'; |
1426 | - if($capture) { |
|
1426 | + if ($capture) { |
|
1427 | 1427 | return $print; |
1428 | 1428 | } else { |
1429 | 1429 | print($print); |
@@ -2,19 +2,19 @@ discard block |
||
2 | 2 | |
3 | 3 | $classLocale = classLocale::$lang; |
4 | 4 | |
5 | -if(classSupernova::$config->server_updater_check_auto && classSupernova::$config->server_updater_check_last + classSupernova::$config->server_updater_check_period <= SN_TIME_NOW) { |
|
5 | +if (classSupernova::$config->server_updater_check_auto && classSupernova::$config->server_updater_check_last + classSupernova::$config->server_updater_check_period <= SN_TIME_NOW) { |
|
6 | 6 | include(SN_ROOT_PHYSICAL . 'ajax_version_check' . DOT_PHP_EX); |
7 | 7 | } |
8 | 8 | |
9 | -if(classSupernova::$config->user_birthday_gift && SN_TIME_NOW - classSupernova::$config->user_birthday_celebrate > PERIOD_DAY) { |
|
9 | +if (classSupernova::$config->user_birthday_gift && SN_TIME_NOW - classSupernova::$config->user_birthday_celebrate > PERIOD_DAY) { |
|
10 | 10 | require_once(SN_ROOT_PHYSICAL . "includes/includes/user_birthday_celebrate" . DOT_PHP_EX); |
11 | 11 | sn_user_birthday_celebrate(); |
12 | 12 | } |
13 | 13 | |
14 | -if(!classSupernova::$config->var_online_user_count || classSupernova::$config->var_online_user_time + 30 < SN_TIME_NOW) { |
|
14 | +if (!classSupernova::$config->var_online_user_count || classSupernova::$config->var_online_user_time + 30 < SN_TIME_NOW) { |
|
15 | 15 | classSupernova::$config->db_saveItem('var_online_user_count', db_user_count(true)); |
16 | 16 | classSupernova::$config->db_saveItem('var_online_user_time', SN_TIME_NOW); |
17 | - if(classSupernova::$config->server_log_online) { |
|
17 | + if (classSupernova::$config->server_log_online) { |
|
18 | 18 | db_log_online_insert(); |
19 | 19 | } |
20 | 20 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | $template_result[F_ACCOUNT_IS_AUTHORIZED] = $sys_user_logged_in = !empty($user) && isset($user['id']) && $user['id']; |
42 | 42 | //pdump($template_result[F_ACCOUNT_IS_AUTHORIZED]);die(); |
43 | 43 | |
44 | -if(!empty($user['id'])) { |
|
44 | +if (!empty($user['id'])) { |
|
45 | 45 | classSupernova::$user_options->user_change($user['id']); |
46 | 46 | } |
47 | 47 | |
@@ -54,15 +54,15 @@ discard block |
||
54 | 54 | : false |
55 | 55 | ); |
56 | 56 | |
57 | -if($template_result[F_LOGIN_STATUS] == LOGIN_ERROR_USERNAME_RESTRICTED_CHARACTERS) { |
|
58 | - $prohibited_characters = array_map(function ($value) { |
|
57 | +if ($template_result[F_LOGIN_STATUS] == LOGIN_ERROR_USERNAME_RESTRICTED_CHARACTERS) { |
|
58 | + $prohibited_characters = array_map(function($value) { |
|
59 | 59 | return "'" . htmlentities($value, ENT_QUOTES, 'UTF-8') . "'"; |
60 | 60 | }, str_split(LOGIN_REGISTER_CHARACTERS_PROHIBITED)); |
61 | 61 | $template_result[F_LOGIN_MESSAGE] .= implode(', ', $prohibited_characters); |
62 | 62 | } |
63 | 63 | |
64 | 64 | |
65 | -if(defined('DEBUG_AUTH') && DEBUG_AUTH && !defined('IN_AJAX')) { |
|
65 | +if (defined('DEBUG_AUTH') && DEBUG_AUTH && !defined('IN_AJAX')) { |
|
66 | 66 | pdump("Отключи отладку перед продакшном!"); |
67 | 67 | } |
68 | 68 | |
@@ -76,17 +76,17 @@ discard block |
||
76 | 76 | ? define('INSTALL_MODE', GAME_DISABLE_INSTALL) |
77 | 77 | : false; |
78 | 78 | |
79 | -if($template_result[F_GAME_DISABLE] = classSupernova::$config->game_disable) { |
|
79 | +if ($template_result[F_GAME_DISABLE] = classSupernova::$config->game_disable) { |
|
80 | 80 | $template_result[F_GAME_DISABLE_REASON] = sys_bbcodeParse( |
81 | 81 | classSupernova::$config->game_disable == GAME_DISABLE_REASON |
82 | 82 | ? classSupernova::$config->game_disable_reason |
83 | 83 | : classLocale::$lang['sys_game_disable_reason'][classSupernova::$config->game_disable] |
84 | 84 | ); |
85 | - if(defined('IN_API')) { |
|
85 | + if (defined('IN_API')) { |
|
86 | 86 | return; |
87 | 87 | } |
88 | 88 | |
89 | - if( |
|
89 | + if ( |
|
90 | 90 | ($user['authlevel'] < 1 || !(defined('IN_ADMIN') && IN_ADMIN)) |
91 | 91 | && |
92 | 92 | !(defined('INSTALL_MODE') && defined('LOGIN_LOGOUT')) |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | |
101 | 101 | // TODO ban |
102 | 102 | // TODO $skip_ban_check |
103 | -if($template_result[F_BANNED_STATUS] && !$skip_ban_check) { |
|
104 | - if(defined('IN_API')) { |
|
103 | +if ($template_result[F_BANNED_STATUS] && !$skip_ban_check) { |
|
104 | + if (defined('IN_API')) { |
|
105 | 105 | return; |
106 | 106 | } |
107 | 107 | |
@@ -119,13 +119,13 @@ discard block |
||
119 | 119 | // pdump($allow_anonymous, '$allow_anonymous'); |
120 | 120 | // pdump($sys_user_logged_in, '$sys_user_logged_in'); |
121 | 121 | |
122 | -if($sys_user_logged_in && INITIAL_PAGE == 'login') { |
|
122 | +if ($sys_user_logged_in && INITIAL_PAGE == 'login') { |
|
123 | 123 | sys_redirect(SN_ROOT_VIRTUAL . 'overview.php'); |
124 | -} elseif($account_logged_in && !$sys_user_logged_in) { // empty(core_auth::$user['id']) |
|
124 | +} elseif ($account_logged_in && !$sys_user_logged_in) { // empty(core_auth::$user['id']) |
|
125 | 125 | // pdump($sn_page_name); |
126 | 126 | // pdump(INITIAL_PAGE); |
127 | 127 | // die('{Тут должна быть ваша реклама. Точнее - ввод имени игрока}'); |
128 | -} elseif(!$allow_anonymous && !$sys_user_logged_in) { |
|
128 | +} elseif (!$allow_anonymous && !$sys_user_logged_in) { |
|
129 | 129 | // sn_setcookie(SN_COOKIE, '', time() - PERIOD_WEEK, SN_ROOT_RELATIVE); |
130 | 130 | sys_redirect(SN_ROOT_VIRTUAL . 'login.php'); |
131 | 131 | } |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | |
147 | 147 | global $skip_fleet_update; |
148 | 148 | $skip_fleet_update = $skip_fleet_update || $supernova->options['fleet_update_skip'] || defined('IN_ADMIN'); |
149 | -if( |
|
149 | +if ( |
|
150 | 150 | !$skip_fleet_update |
151 | 151 | && !(defined('IN_AJAX') && IN_AJAX === true) |
152 | 152 | && SN_TIME_NOW - strtotime(classSupernova::$config->fleet_update_last) > classSupernova::$config->fleet_update_interval |
@@ -79,8 +79,8 @@ discard block |
||
79 | 79 | $this->reset(); |
80 | 80 | $this->db = is_object($db) ? $db : classSupernova::$db; |
81 | 81 | |
82 | - foreach($this->table_check as $table_name) { |
|
83 | - if(empty($this->db->table_list[$table_name])) { |
|
82 | + foreach ($this->table_check as $table_name) { |
|
83 | + if (empty($this->db->table_list[$table_name])) { |
|
84 | 84 | die('Если вы видите это сообщение первый раз после обновления релиза - просто перегрузите страницу.<br /> |
85 | 85 | В противном случае - сообщите Администрации сервера об ошибке.<br/> |
86 | 86 | Не хватает таблицы для работы системы авторизации: ' . $table_name); |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | */ |
105 | 105 | // OK v4.6 |
106 | 106 | public function password_change($old_password_unsafe, $new_password_unsafe, $salt_unsafe = null) { |
107 | - if(!$this->password_check($old_password_unsafe)) { |
|
107 | + if (!$this->password_check($old_password_unsafe)) { |
|
108 | 108 | return false; |
109 | 109 | } |
110 | 110 | |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | // OK v4.5 |
126 | 126 | public function assign_from_db_row($row) { |
127 | 127 | $this->reset(); |
128 | - if(empty($row) || !is_array($row)) { |
|
128 | + if (empty($row) || !is_array($row)) { |
|
129 | 129 | return false; |
130 | 130 | } |
131 | 131 | $this->account_id = $row['account_id']; |
@@ -242,11 +242,11 @@ discard block |
||
242 | 242 | `account_email` = LOWER('{$email_safe}'), |
243 | 243 | `account_language` = '{$language_safe}'" |
244 | 244 | ); |
245 | - if(!$result) { |
|
245 | + if (!$result) { |
|
246 | 246 | throw new Exception(REGISTER_ERROR_ACCOUNT_CREATE, ERR_ERROR); |
247 | 247 | } |
248 | 248 | |
249 | - if(!($account_id = $this->db->db_insert_id())) { |
|
249 | + if (!($account_id = $this->db->db_insert_id())) { |
|
250 | 250 | throw new Exception(REGISTER_ERROR_ACCOUNT_CREATE, ERR_ERROR); |
251 | 251 | } |
252 | 252 | |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | WHERE `account_id` = '{$account_id_safe}'" |
277 | 277 | ) ? true : false; |
278 | 278 | |
279 | - if($result) { |
|
279 | + if ($result) { |
|
280 | 280 | $result = $this->db_get_by_id($this->account_id); |
281 | 281 | } |
282 | 282 | |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | public function metamatter_change($change_type, $metamatter, $comment = '', $already_changed = false) { |
364 | 364 | global $debug, $mm_change_legit; |
365 | 365 | |
366 | - if(!$this->is_exists || !($metamatter = round(floatval($metamatter)))) { |
|
366 | + if (!$this->is_exists || !($metamatter = round(floatval($metamatter)))) { |
|
367 | 367 | $debug->error('Ошибка при попытке манипуляции с ММ'); |
368 | 368 | |
369 | 369 | return false; |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | |
374 | 374 | $mm_change_legit = true; |
375 | 375 | // $sn_data_metamatter_db_name = pname_resource_name(RES_METAMATTER); |
376 | - if($already_changed) { |
|
376 | + if ($already_changed) { |
|
377 | 377 | $metamatter_total_delta = 0; |
378 | 378 | $result = -1; |
379 | 379 | } else { |
@@ -387,13 +387,13 @@ discard block |
||
387 | 387 | ($metamatter_total_delta ? ", `account_immortal` = IF(`account_metamatter_total` + '{$metamatter_total_delta}' >= {$classConfig->player_metamatter_immortal}, NOW(), `account_immortal`), `account_metamatter_total` = `account_metamatter_total` + '{$metamatter_total_delta}'" : '') . |
388 | 388 | " WHERE `account_id` = {$account_id_safe}" |
389 | 389 | ); |
390 | - if(!$result) { |
|
390 | + if (!$result) { |
|
391 | 391 | $debug->error("Error adjusting Metamatter for player ID {$this->account_id} (Player Not Found?) with {$metamatter}. Reason: {$comment}", 'Metamatter Change', 402); |
392 | 392 | } |
393 | 393 | $result = classSupernova::$db->db_affected_rows(); |
394 | 394 | } |
395 | 395 | |
396 | - if(empty(core_auth::$user['id'])) { |
|
396 | + if (empty(core_auth::$user['id'])) { |
|
397 | 397 | $user_list = PlayerToAccountTranslate::db_translate_get_users_from_account_list(core_auth::$main_provider->provider_id, $this->account_id); |
398 | 398 | reset($user_list); |
399 | 399 | $user_id_unsafe = key($user_list); |
@@ -402,30 +402,30 @@ discard block |
||
402 | 402 | } |
403 | 403 | $user_id_safe = $this->db->db_escape($user_id_unsafe); |
404 | 404 | |
405 | - if(!$result) { |
|
405 | + if (!$result) { |
|
406 | 406 | $debug->error("Error adjusting Metamatter for player ID {$this->account_id} (Player Not Found?) with {$metamatter}. Reason: {$comment}", 'Metamatter Change', 402); |
407 | 407 | } |
408 | 408 | |
409 | - if(!$already_changed) { |
|
409 | + if (!$already_changed) { |
|
410 | 410 | $this->account_metamatter += $metamatter; |
411 | 411 | $this->account_metamatter_total += $metamatter_total_delta; |
412 | 412 | } |
413 | 413 | |
414 | - if(is_array($comment)) { |
|
414 | + if (is_array($comment)) { |
|
415 | 415 | $comment = call_user_func_array('sprintf', $comment); |
416 | 416 | } |
417 | 417 | |
418 | 418 | $result = $this->db_mm_log_insert($comment, $change_type, $metamatter, $user_id_unsafe); |
419 | 419 | |
420 | - if($metamatter > 0 && !empty($user_id_safe)) { |
|
420 | + if ($metamatter > 0 && !empty($user_id_safe)) { |
|
421 | 421 | $old_referral = db_referral_get_by_id($user_id_safe); |
422 | - if($old_referral['id']) { |
|
422 | + if ($old_referral['id']) { |
|
423 | 423 | $dark_matter_from_metamatter = $metamatter * AFFILIATE_MM_TO_REFERRAL_DM; |
424 | 424 | db_referral_update_dm($user_id_safe, $dark_matter_from_metamatter); |
425 | 425 | $new_referral = db_referral_get_by_id($user_id_safe); |
426 | 426 | |
427 | 427 | $partner_bonus = floor($new_referral['dark_matter'] / classSupernova::$config->rpg_bonus_divisor) - ($old_referral['dark_matter'] >= classSupernova::$config->rpg_bonus_minimum ? floor($old_referral['dark_matter'] / classSupernova::$config->rpg_bonus_divisor) : 0); |
428 | - if($partner_bonus > 0 && $new_referral['dark_matter'] >= classSupernova::$config->rpg_bonus_minimum) { |
|
428 | + if ($partner_bonus > 0 && $new_referral['dark_matter'] >= classSupernova::$config->rpg_bonus_minimum) { |
|
429 | 429 | rpg_points_change($new_referral['id_partner'], RPG_REFERRAL_BOUGHT_MM, $partner_bonus, "Incoming MM From Referral ID {$user_id_safe}"); |
430 | 430 | } |
431 | 431 | } |
@@ -76,23 +76,23 @@ discard block |
||
76 | 76 | function sn_db_connect($external_db_settings = null) { |
77 | 77 | $this->db_disconnect(); |
78 | 78 | |
79 | - if(!empty($external_db_settings) && is_array($external_db_settings)) { |
|
79 | + if (!empty($external_db_settings) && is_array($external_db_settings)) { |
|
80 | 80 | $this->dbsettings = $external_db_settings; |
81 | 81 | } |
82 | 82 | |
83 | - if(empty($this->dbsettings)) { |
|
83 | + if (empty($this->dbsettings)) { |
|
84 | 84 | $this->load_db_settings(); |
85 | 85 | } |
86 | 86 | |
87 | 87 | // TODO - фатальные (?) ошибки на каждом шагу. Хотя - скорее Эксепшны |
88 | - if(!empty($this->dbsettings)) { |
|
88 | + if (!empty($this->dbsettings)) { |
|
89 | 89 | $driver_name = empty($this->dbsettings['sn_driver']) ? 'db_mysql_v5' : $this->dbsettings['sn_driver']; |
90 | 90 | $this->driver = new $driver_name(); |
91 | 91 | $this->db_prefix = $this->dbsettings['prefix']; |
92 | 92 | |
93 | 93 | $this->connected = $this->connected || $this->driver_connect(); |
94 | 94 | |
95 | - if($this->connected) { |
|
95 | + if ($this->connected) { |
|
96 | 96 | $this->table_list = $this->db_get_table_list(); |
97 | 97 | // TODO Проверка на пустоту |
98 | 98 | } |
@@ -106,11 +106,11 @@ discard block |
||
106 | 106 | function driver_connect() { |
107 | 107 | global $debug; |
108 | 108 | |
109 | - if(!is_object($this->driver)) { |
|
109 | + if (!is_object($this->driver)) { |
|
110 | 110 | $debug->error_fatal('DB Error - No driver for MySQL found!'); |
111 | 111 | } |
112 | 112 | |
113 | - if(!method_exists($this->driver, 'mysql_connect')) { |
|
113 | + if (!method_exists($this->driver, 'mysql_connect')) { |
|
114 | 114 | $debug->error_fatal('DB Error - WRONG MySQL driver!'); |
115 | 115 | } |
116 | 116 | |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | } |
119 | 119 | |
120 | 120 | function db_disconnect() { |
121 | - if($this->connected) { |
|
121 | + if ($this->connected) { |
|
122 | 122 | $this->connected = !$this->driver_disconnect(); |
123 | 123 | $this->connected = false; |
124 | 124 | } |
@@ -129,11 +129,11 @@ discard block |
||
129 | 129 | function doquery($query, $table = '', $fetch = false, $skip_query_check = false) { |
130 | 130 | global $numqueries, $debug; |
131 | 131 | |
132 | - if(!is_string($table)) { |
|
132 | + if (!is_string($table)) { |
|
133 | 133 | $fetch = $table; |
134 | 134 | } |
135 | 135 | |
136 | - if(!$this->connected) { |
|
136 | + if (!$this->connected) { |
|
137 | 137 | $this->sn_db_connect(); |
138 | 138 | } |
139 | 139 | |
@@ -142,30 +142,30 @@ discard block |
||
142 | 142 | !$skip_query_check ? $this->security_query_check_bad_words($query) : false; |
143 | 143 | |
144 | 144 | $sql = $query; |
145 | - if(strpos($sql, '{{') !== false) { |
|
146 | - foreach($this->table_list as $tableName) { |
|
145 | + if (strpos($sql, '{{') !== false) { |
|
146 | + foreach ($this->table_list as $tableName) { |
|
147 | 147 | $sql = str_replace("{{{$tableName}}}", $this->db_prefix . $tableName, $sql); |
148 | 148 | } |
149 | 149 | } |
150 | 150 | |
151 | - if(classSupernova::$config->debug) { |
|
151 | + if (classSupernova::$config->debug) { |
|
152 | 152 | $numqueries++; |
153 | 153 | $arr = debug_backtrace(); |
154 | - $file = end(explode('/',$arr[0]['file'])); |
|
154 | + $file = end(explode('/', $arr[0]['file'])); |
|
155 | 155 | $line = $arr[0]['line']; |
156 | 156 | $debug->add("<tr><th>Query $numqueries: </th><th>$query</th><th>$file($line)</th><th>$table</th><th>$fetch</th></tr>"); |
157 | 157 | } |
158 | 158 | |
159 | - if(defined('DEBUG_SQL_COMMENT')) { |
|
159 | + if (defined('DEBUG_SQL_COMMENT')) { |
|
160 | 160 | $backtrace = debug_backtrace(); |
161 | 161 | $sql_comment = $debug->compact_backtrace($backtrace, defined('DEBUG_SQL_COMMENT_LONG')); |
162 | 162 | |
163 | 163 | $sql_commented = '/* ' . implode("<br />", $sql_comment) . '<br /> */ ' . preg_replace("/\s+/", ' ', $sql); |
164 | - if(defined('DEBUG_SQL_ONLINE')) { |
|
164 | + if (defined('DEBUG_SQL_ONLINE')) { |
|
165 | 165 | $debug->warning($sql_commented, 'SQL Debug', LOG_DEBUG_SQL); |
166 | 166 | } |
167 | 167 | |
168 | - if(defined('DEBUG_SQL_ERROR')) { |
|
168 | + if (defined('DEBUG_SQL_ERROR')) { |
|
169 | 169 | array_unshift($sql_comment, preg_replace("/\s+/", ' ', $sql)); |
170 | 170 | $debug->add_to_array($sql_comment); |
171 | 171 | // $debug->add_to_array($sql_comment . preg_replace("/\s+/", ' ', $sql)); |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | $sql = $sql_commented; |
174 | 174 | } |
175 | 175 | |
176 | - $sqlquery = $this->db_sql_query($sql) or $debug->error(db_error()."<br />$sql<br />",'SQL Error'); |
|
176 | + $sqlquery = $this->db_sql_query($sql) or $debug->error(db_error() . "<br />$sql<br />", 'SQL Error'); |
|
177 | 177 | |
178 | 178 | return $fetch ? $this->db_fetch($sqlquery) : $sqlquery; |
179 | 179 | } |
@@ -183,16 +183,16 @@ discard block |
||
183 | 183 | // TODO Заменить это на новый логгер |
184 | 184 | global $is_watching, $user, $debug; |
185 | 185 | |
186 | - if(!$is_watching && classSupernova::$config->game_watchlist_array && in_array($user['id'], classSupernova::$config->game_watchlist_array)) |
|
186 | + if (!$is_watching && classSupernova::$config->game_watchlist_array && in_array($user['id'], classSupernova::$config->game_watchlist_array)) |
|
187 | 187 | { |
188 | - if(!preg_match('/^(select|commit|rollback|start transaction)/i', $query)) { |
|
188 | + if (!preg_match('/^(select|commit|rollback|start transaction)/i', $query)) { |
|
189 | 189 | $is_watching = true; |
190 | 190 | $msg = "\$query = \"{$query}\"\n\r"; |
191 | - if(!empty($_POST)) { |
|
192 | - $msg .= "\n\r" . dump($_POST,'$_POST'); |
|
191 | + if (!empty($_POST)) { |
|
192 | + $msg .= "\n\r" . dump($_POST, '$_POST'); |
|
193 | 193 | } |
194 | - if(!empty($_GET)) { |
|
195 | - $msg .= "\n\r" . dump($_GET,'$_GET'); |
|
194 | + if (!empty($_GET)) { |
|
195 | + $msg .= "\n\r" . dump($_GET, '$_GET'); |
|
196 | 196 | } |
197 | 197 | $debug->warning($msg, "Watching user {$user['id']}", 399, array('base_dump' => true)); |
198 | 198 | $is_watching = false; |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | function security_query_check_bad_words($query) { |
205 | 205 | global $user, $dm_change_legit, $mm_change_legit; |
206 | 206 | |
207 | - switch(true) { |
|
207 | + switch (true) { |
|
208 | 208 | case stripos($query, 'RUNCATE TABL') != false: |
209 | 209 | case stripos($query, 'ROP TABL') != false: |
210 | 210 | case stripos($query, 'ENAME TABL') != false: |
@@ -215,33 +215,33 @@ discard block |
||
215 | 215 | case stripos($query, 'RPG_POINTS') != false && stripos(trim($query), 'UPDATE ') === 0 && !$dm_change_legit: |
216 | 216 | case stripos($query, 'METAMATTER') != false && stripos(trim($query), 'UPDATE ') === 0 && !$mm_change_legit: |
217 | 217 | case stripos($query, 'AUTHLEVEL') != false && $user['authlevel'] < 3 && stripos($query, 'SELECT') !== 0: |
218 | - $report = "Hacking attempt (".date("d.m.Y H:i:s")." - [".time()."]):\n"; |
|
218 | + $report = "Hacking attempt (" . date("d.m.Y H:i:s") . " - [" . time() . "]):\n"; |
|
219 | 219 | $report .= ">Database Inforamation\n"; |
220 | - $report .= "\tID - ".$user['id']."\n"; |
|
221 | - $report .= "\tUser - ".$user['username']."\n"; |
|
222 | - $report .= "\tAuth level - ".$user['authlevel']."\n"; |
|
223 | - $report .= "\tAdmin Notes - ".$user['adminNotes']."\n"; |
|
224 | - $report .= "\tCurrent Planet - ".$user['current_planet']."\n"; |
|
225 | - $report .= "\tUser IP - ".$user['user_lastip']."\n"; |
|
226 | - $report .= "\tUser IP at Reg - ".$user['ip_at_reg']."\n"; |
|
227 | - $report .= "\tUser Agent- ".$_SERVER['HTTP_USER_AGENT']."\n"; |
|
228 | - $report .= "\tCurrent Page - ".$user['current_page']."\n"; |
|
229 | - $report .= "\tRegister Time - ".$user['register_time']."\n"; |
|
220 | + $report .= "\tID - " . $user['id'] . "\n"; |
|
221 | + $report .= "\tUser - " . $user['username'] . "\n"; |
|
222 | + $report .= "\tAuth level - " . $user['authlevel'] . "\n"; |
|
223 | + $report .= "\tAdmin Notes - " . $user['adminNotes'] . "\n"; |
|
224 | + $report .= "\tCurrent Planet - " . $user['current_planet'] . "\n"; |
|
225 | + $report .= "\tUser IP - " . $user['user_lastip'] . "\n"; |
|
226 | + $report .= "\tUser IP at Reg - " . $user['ip_at_reg'] . "\n"; |
|
227 | + $report .= "\tUser Agent- " . $_SERVER['HTTP_USER_AGENT'] . "\n"; |
|
228 | + $report .= "\tCurrent Page - " . $user['current_page'] . "\n"; |
|
229 | + $report .= "\tRegister Time - " . $user['register_time'] . "\n"; |
|
230 | 230 | $report .= "\n"; |
231 | 231 | |
232 | 232 | $report .= ">Query Information\n"; |
233 | - $report .= "\tQuery - ".$query."\n"; |
|
233 | + $report .= "\tQuery - " . $query . "\n"; |
|
234 | 234 | $report .= "\n"; |
235 | 235 | |
236 | 236 | $report .= ">\$_SERVER Information\n"; |
237 | - $report .= "\tIP - ".$_SERVER['REMOTE_ADDR']."\n"; |
|
238 | - $report .= "\tHost Name - ".$_SERVER['HTTP_HOST']."\n"; |
|
239 | - $report .= "\tUser Agent - ".$_SERVER['HTTP_USER_AGENT']."\n"; |
|
240 | - $report .= "\tRequest Method - ".$_SERVER['REQUEST_METHOD']."\n"; |
|
241 | - $report .= "\tCame From - ".$_SERVER['HTTP_REFERER']."\n"; |
|
242 | - $report .= "\tPage is - ".$_SERVER['SCRIPT_NAME']."\n"; |
|
243 | - $report .= "\tUses Port - ".$_SERVER['REMOTE_PORT']."\n"; |
|
244 | - $report .= "\tServer Protocol - ".$_SERVER['SERVER_PROTOCOL']."\n"; |
|
237 | + $report .= "\tIP - " . $_SERVER['REMOTE_ADDR'] . "\n"; |
|
238 | + $report .= "\tHost Name - " . $_SERVER['HTTP_HOST'] . "\n"; |
|
239 | + $report .= "\tUser Agent - " . $_SERVER['HTTP_USER_AGENT'] . "\n"; |
|
240 | + $report .= "\tRequest Method - " . $_SERVER['REQUEST_METHOD'] . "\n"; |
|
241 | + $report .= "\tCame From - " . $_SERVER['HTTP_REFERER'] . "\n"; |
|
242 | + $report .= "\tPage is - " . $_SERVER['SCRIPT_NAME'] . "\n"; |
|
243 | + $report .= "\tUses Port - " . $_SERVER['REMOTE_PORT'] . "\n"; |
|
244 | + $report .= "\tServer Protocol - " . $_SERVER['SERVER_PROTOCOL'] . "\n"; |
|
245 | 245 | |
246 | 246 | $report .= "\n--------------------------------------------------------------------------------------------------\n"; |
247 | 247 | |
@@ -261,11 +261,11 @@ discard block |
||
261 | 261 | $prefix_length = strlen($this->db_prefix); |
262 | 262 | |
263 | 263 | $tl = array(); |
264 | - while($row = $this->db_fetch($query)) { |
|
265 | - foreach($row as $table_name) { |
|
266 | - if(strpos($table_name, $this->db_prefix) === 0) { |
|
264 | + while ($row = $this->db_fetch($query)) { |
|
265 | + foreach ($row as $table_name) { |
|
266 | + if (strpos($table_name, $this->db_prefix) === 0) { |
|
267 | 267 | $table_name = substr($table_name, $prefix_length); |
268 | - } elseif($prefixed_only) { |
|
268 | + } elseif ($prefixed_only) { |
|
269 | 269 | continue; |
270 | 270 | } |
271 | 271 | // $table_name = str_replace($db_prefix, '', $table_name); |
@@ -199,18 +199,18 @@ discard block |
||
199 | 199 | // TODO Хотя тут может получится вечный цикл - ПОДУМАТЬ |
200 | 200 | // TODO Тут же можно пробовать провести попытку слияния аккаунтов - хотя это и очень небезопасно |
201 | 201 | |
202 | - if(sys_get_param('login_player_register_logout')) { |
|
202 | + if (sys_get_param('login_player_register_logout')) { |
|
203 | 203 | $this->logout(); |
204 | 204 | } |
205 | 205 | |
206 | 206 | $original_suggest = ''; |
207 | 207 | // Смотрим - есть ли у нас данные от пользователя |
208 | - if(($player_name_submitted = sys_get_param('submit_player_name'))) { |
|
208 | + if (($player_name_submitted = sys_get_param('submit_player_name'))) { |
|
209 | 209 | // Попытка регистрации нового игрока из данных, введенных пользователем |
210 | 210 | $this->player_suggested_name = sys_get_param_str_unsafe('player_suggested_name'); |
211 | 211 | } else { |
212 | - foreach($this->providers_authorised as $provider) { |
|
213 | - if($this->player_suggested_name = $provider->player_name_suggest()) { // OK 4.5 |
|
212 | + foreach ($this->providers_authorised as $provider) { |
|
213 | + if ($this->player_suggested_name = $provider->player_name_suggest()) { // OK 4.5 |
|
214 | 214 | $original_suggest = $provider->player_name_suggest(); |
215 | 215 | break; |
216 | 216 | } |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | } |
219 | 219 | |
220 | 220 | // Если у нас провайдеры не дают имени и пользователь не дал свой вариант - это у нас первый логин в игру |
221 | - if(!$this->player_suggested_name) { |
|
221 | + if (!$this->player_suggested_name) { |
|
222 | 222 | $max_user_id = db_player_get_max_id(); // 4.5 |
223 | 223 | // TODO - предлагать имя игрока по локали |
224 | 224 | |
@@ -227,15 +227,15 @@ discard block |
||
227 | 227 | sn_db_transaction_rollback(); |
228 | 228 | $this->player_suggested_name = 'Emperor ' . mt_rand($max_user_id + 1, $max_user_id + 1000); |
229 | 229 | sn_db_transaction_start(); |
230 | - } while(db_player_name_exists($this->player_suggested_name)); |
|
230 | + } while (db_player_name_exists($this->player_suggested_name)); |
|
231 | 231 | |
232 | 232 | } |
233 | 233 | |
234 | - if($player_name_submitted) { |
|
234 | + if ($player_name_submitted) { |
|
235 | 235 | $this->register_player_db_create($this->player_suggested_name); // OK 4.5 |
236 | - if($this->register_status == LOGIN_SUCCESS) { |
|
236 | + if ($this->register_status == LOGIN_SUCCESS) { |
|
237 | 237 | sys_redirect(SN_ROOT_VIRTUAL . 'overview.php'); |
238 | - } elseif($this->register_status == REGISTER_ERROR_PLAYER_NAME_EXISTS && $original_suggest == $this->player_suggested_name) { |
|
238 | + } elseif ($this->register_status == REGISTER_ERROR_PLAYER_NAME_EXISTS && $original_suggest == $this->player_suggested_name) { |
|
239 | 239 | // self::$player_suggested_name .= ' ' . $this->account->account_id; |
240 | 240 | } |
241 | 241 | // if(self::$login_status != LOGIN_SUCCESS) { |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | : false |
260 | 260 | ); |
261 | 261 | |
262 | - if($this->register_status == LOGIN_ERROR_USERNAME_RESTRICTED_CHARACTERS) { |
|
262 | + if ($this->register_status == LOGIN_ERROR_USERNAME_RESTRICTED_CHARACTERS) { |
|
263 | 263 | $prohibited_characters = array_map(function($value) { |
264 | 264 | return "'" . htmlentities($value, ENT_QUOTES, 'UTF-8') . "'"; |
265 | 265 | }, str_split(LOGIN_REGISTER_CHARACTERS_PROHIBITED)); |
@@ -289,27 +289,27 @@ discard block |
||
289 | 289 | * @param null $result |
290 | 290 | */ |
291 | 291 | public function login() { |
292 | - if(empty(sn_module::$sn_module_list['auth'])) { |
|
292 | + if (empty(sn_module::$sn_module_list['auth'])) { |
|
293 | 293 | die('{Не обнаружено ни одного провайдера авторизации в core_auth::login()!}'); |
294 | 294 | } |
295 | 295 | |
296 | 296 | !empty($_POST) ? self::flog(dump($_POST, '$_POST')) : false; |
297 | 297 | !empty($_GET) ? self::flog(dump($_GET, '$_GET')) : false; |
298 | - !empty($_COOKIE) ? self::flog(dump($_COOKIE,'$_COOKIE')) : false; |
|
298 | + !empty($_COOKIE) ? self::flog(dump($_COOKIE, '$_COOKIE')) : false; |
|
299 | 299 | |
300 | 300 | $this->auth_reset(); // OK v4.5 |
301 | 301 | |
302 | 302 | $this->providers = array(); |
303 | - foreach(sn_module::$sn_module_list['auth'] as $module_name => $module) { |
|
303 | + foreach (sn_module::$sn_module_list['auth'] as $module_name => $module) { |
|
304 | 304 | $this->providers[$module->provider_id] = $module; |
305 | 305 | } |
306 | 306 | |
307 | 307 | // $this->providers = array_reverse($this->providers, true); // НИНАДА! СН-аккаунт должен всегда авторизироваться первым! |
308 | 308 | |
309 | - foreach($this->providers as $provider_id => $provider) { |
|
309 | + foreach ($this->providers as $provider_id => $provider) { |
|
310 | 310 | $login_status = $provider->login(); // OK v4.5 |
311 | 311 | self::flog(($provider->manifest['name'] . '->' . 'login_try - ') . (empty($provider->account->account_id) ? classLocale::$lang['sys_login_messages'][$provider->account_login_status] : dump($provider))); |
312 | - if($login_status == LOGIN_SUCCESS && is_object($provider->account) && $provider->account instanceof Account && $provider->account->account_id) { |
|
312 | + if ($login_status == LOGIN_SUCCESS && is_object($provider->account) && $provider->account instanceof Account && $provider->account->account_id) { |
|
313 | 313 | $this->providers_authorised[$provider_id] = &$this->providers[$provider_id]; |
314 | 314 | |
315 | 315 | $this->user_id_to_provider = array_replace_recursive( |
@@ -317,15 +317,15 @@ discard block |
||
317 | 317 | // static::db_translate_get_users_from_account_list($provider_id, $provider->account->account_id) // OK 4.5 |
318 | 318 | PlayerToAccountTranslate::db_translate_get_users_from_account_list($provider_id, $provider->account->account_id) // OK 4.5 |
319 | 319 | ); |
320 | - } elseif($login_status != LOGIN_UNDEFINED) { |
|
320 | + } elseif ($login_status != LOGIN_UNDEFINED) { |
|
321 | 321 | $this->provider_error_list[$provider_id] = $login_status; |
322 | 322 | } |
323 | 323 | } |
324 | 324 | |
325 | - if(empty($this->providers_authorised)) { |
|
325 | + if (empty($this->providers_authorised)) { |
|
326 | 326 | // Ни один аккаунт не авторизирован |
327 | 327 | // Проверяем - есть ли у нас ошибки в аккаунтах? |
328 | - if(!empty($this->provider_error_list)) { |
|
328 | + if (!empty($this->provider_error_list)) { |
|
329 | 329 | // Если есть - выводим их |
330 | 330 | self::$login_status = reset($this->provider_error_list); |
331 | 331 | } |
@@ -340,12 +340,12 @@ discard block |
||
340 | 340 | // В self::$accessible_user_row_list - список доступных игроков для данных аккаунтов с соответствующими записями из таблицы `users` |
341 | 341 | |
342 | 342 | // Остались ли у нас в списке доступные игроки? |
343 | - if(empty($this->accessible_user_row_list)) { |
|
343 | + if (empty($this->accessible_user_row_list)) { |
|
344 | 344 | // Нет ни одного игрока ни на одном авторизированном аккаунте |
345 | 345 | // Надо регать нового игрока |
346 | 346 | |
347 | 347 | // Сейчас происходит процесс регистрации игрока? |
348 | - if(!$this->is_player_register) { |
|
348 | + if (!$this->is_player_register) { |
|
349 | 349 | // Нет - отправляем на процесс регистрации |
350 | 350 | $partner_id = sys_get_param_int('id_ref', sys_get_param_int('partner_id')); |
351 | 351 | sys_redirect(SN_ROOT_VIRTUAL . 'index.php?page=player_register&player_register=1' . ($partner_id ? '&id_ref=' . $partner_id : '')); |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | // Да, есть доступные игроки, которые так же прописаны в базе |
355 | 355 | $this->get_active_user(); // 4.5 |
356 | 356 | |
357 | - if($this->is_impersonating = !empty($_COOKIE[SN_COOKIE_U_I]) ? $_COOKIE[SN_COOKIE_U_I] : 0) { |
|
357 | + if ($this->is_impersonating = !empty($_COOKIE[SN_COOKIE_U_I]) ? $_COOKIE[SN_COOKIE_U_I] : 0) { |
|
358 | 358 | $a_user = db_user_by_id($this->is_impersonating); |
359 | 359 | $this->impersonator_username = $a_user['username']; |
360 | 360 | } |
@@ -362,9 +362,9 @@ discard block |
||
362 | 362 | |
363 | 363 | //Прописываем текущего игрока на все авторизированные аккаунты |
364 | 364 | // TODO - ИЛИ ВСЕХ ИГРОКОВ?? |
365 | - if(empty($this->is_impersonating)) { |
|
366 | - foreach($this->providers_authorised as $provider_id => $provider) { |
|
367 | - if(empty($this->user_id_to_provider[self::$user['id']][$provider_id])) { |
|
365 | + if (empty($this->is_impersonating)) { |
|
366 | + foreach ($this->providers_authorised as $provider_id => $provider) { |
|
367 | + if (empty($this->user_id_to_provider[self::$user['id']][$provider_id])) { |
|
368 | 368 | // self::db_translate_register_user($provider_id, $provider->account->account_id, self::$user['id']); |
369 | 369 | PlayerToAccountTranslate::db_translate_register_user($provider_id, $provider->account->account_id, self::$user['id']); |
370 | 370 | $this->user_id_to_provider[self::$user['id']][$provider_id][$provider->account->account_id] = true; |
@@ -374,9 +374,9 @@ discard block |
||
374 | 374 | } |
375 | 375 | } |
376 | 376 | |
377 | - if(empty(self::$user['id'])) { |
|
377 | + if (empty(self::$user['id'])) { |
|
378 | 378 | self::cookie_set(''); // OK 4.5 |
379 | - } elseif(self::$user['id'] != $_COOKIE[SN_COOKIE_U]) { |
|
379 | + } elseif (self::$user['id'] != $_COOKIE[SN_COOKIE_U]) { |
|
380 | 380 | self::cookie_set(self::$user['id']); // OK 4.5 |
381 | 381 | } |
382 | 382 | |
@@ -395,21 +395,21 @@ discard block |
||
395 | 395 | */ |
396 | 396 | // OK v4.7 |
397 | 397 | public function logout($redirect = true) { |
398 | - if(!empty($_COOKIE[SN_COOKIE_U_I])) { |
|
398 | + if (!empty($_COOKIE[SN_COOKIE_U_I])) { |
|
399 | 399 | self::cookie_set($_COOKIE[SN_COOKIE_U_I]); |
400 | 400 | self::cookie_set(0, true); |
401 | 401 | self::$main_provider->logout(); |
402 | 402 | } else { |
403 | - foreach($this->providers as $provider_name => $provider) { |
|
403 | + foreach ($this->providers as $provider_name => $provider) { |
|
404 | 404 | $provider->logout(); |
405 | 405 | } |
406 | 406 | |
407 | 407 | self::cookie_set(0); |
408 | 408 | } |
409 | 409 | |
410 | - if($redirect === true) { |
|
410 | + if ($redirect === true) { |
|
411 | 411 | sys_redirect(SN_ROOT_RELATIVE . (empty($_COOKIE[SN_COOKIE_U]) ? 'login.php' : 'admin/overview.php')); |
412 | - } elseif($redirect !== false) { |
|
412 | + } elseif ($redirect !== false) { |
|
413 | 413 | sys_redirect($redirect); |
414 | 414 | } |
415 | 415 | } |
@@ -420,15 +420,15 @@ discard block |
||
420 | 420 | * @param $user_selected |
421 | 421 | */ |
422 | 422 | public function impersonate($user_selected) { |
423 | - if($_COOKIE[SN_COOKIE_U_I]) { |
|
423 | + if ($_COOKIE[SN_COOKIE_U_I]) { |
|
424 | 424 | die('You already impersonating someone. Go back to living other\'s life! Or clear your cookies and try again'); // TODO: Log it |
425 | 425 | } |
426 | 426 | |
427 | - if($this->auth_level_max_local < AUTH_LEVEL_ADMINISTRATOR) { |
|
427 | + if ($this->auth_level_max_local < AUTH_LEVEL_ADMINISTRATOR) { |
|
428 | 428 | die('You can\'t impersonate - too low level'); // TODO: Log it |
429 | 429 | } |
430 | 430 | |
431 | - if($this->auth_level_max_local <= $user_selected['authlevel']) { |
|
431 | + if ($this->auth_level_max_local <= $user_selected['authlevel']) { |
|
432 | 432 | die('You can\'t impersonate this account - level is greater or equal to yours'); // TODO: Log it |
433 | 433 | } |
434 | 434 | |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | $account_translate = reset($account_translate[$user_selected['id']][self::$main_provider->provider_id]); |
437 | 437 | $account_to_impersonate = new Account(self::$main_provider->db); |
438 | 438 | $account_to_impersonate->db_get_by_id($account_translate['provider_account_id']); |
439 | - if(!$account_to_impersonate->is_exists) { |
|
439 | + if (!$account_to_impersonate->is_exists) { |
|
440 | 440 | die('Какая-то ошибка - не могу найти аккаунт для имперсонации'); // TODO: Log it |
441 | 441 | } |
442 | 442 | self::$main_provider->impersonate($account_to_impersonate); |
@@ -462,12 +462,12 @@ discard block |
||
462 | 462 | public function password_check($password_unsafe) { |
463 | 463 | $result = false; |
464 | 464 | |
465 | - if(empty($this->providers_authorised)) { |
|
465 | + if (empty($this->providers_authorised)) { |
|
466 | 466 | // TODO - такого быть не может! |
467 | 467 | self::flog("password_check: Не найдено ни одного авторизированного провайдера в self::\$providers_authorised", true); |
468 | 468 | } else { |
469 | - foreach($this->providers_authorised as $provider_id => $provider) { |
|
470 | - if($provider->is_feature_supported(AUTH_FEATURE_HAS_PASSWORD)) { |
|
469 | + foreach ($this->providers_authorised as $provider_id => $provider) { |
|
470 | + if ($provider->is_feature_supported(AUTH_FEATURE_HAS_PASSWORD)) { |
|
471 | 471 | $result = $result || $provider->password_check($password_unsafe); |
472 | 472 | } |
473 | 473 | } |
@@ -486,7 +486,7 @@ discard block |
||
486 | 486 | */ |
487 | 487 | // OK v4.6 |
488 | 488 | public function password_change($old_password_unsafe, $new_password_unsafe) { |
489 | - if(empty($this->providers_authorised)) { |
|
489 | + if (empty($this->providers_authorised)) { |
|
490 | 490 | // TODO - такого быть не может! |
491 | 491 | self::flog("Не найдено ни одного авторизированного провайдера в self::\$providers_authorised", true); |
492 | 492 | return false; |
@@ -499,8 +499,8 @@ discard block |
||
499 | 499 | $salt_unsafe = self::password_salt_generate(); |
500 | 500 | |
501 | 501 | $providers_changed_password = array(); |
502 | - foreach($this->providers_authorised as $provider_id => $provider) { |
|
503 | - if( |
|
502 | + foreach ($this->providers_authorised as $provider_id => $provider) { |
|
503 | + if ( |
|
504 | 504 | !$provider->is_feature_supported(AUTH_FEATURE_PASSWORD_CHANGE) |
505 | 505 | || !$provider->password_change($old_password_unsafe, $new_password_unsafe, $salt_unsafe) |
506 | 506 | ) { |
@@ -512,7 +512,7 @@ discard block |
||
512 | 512 | $account_translation = PlayerToAccountTranslate::db_translate_get_users_from_account_list($provider_id, $provider->account->account_id); |
513 | 513 | |
514 | 514 | // Рассылаем уведомления о смене пароля в ЛС |
515 | - foreach($account_translation as $user_id => $provider_info) { |
|
515 | + foreach ($account_translation as $user_id => $provider_info) { |
|
516 | 516 | // TODO - УКазывать тип аккаунта, на котором сменён пароль |
517 | 517 | msg_send_simple_message($user_id, 0, SN_TIME_NOW, MSG_TYPE_ADMIN, |
518 | 518 | classLocale::$lang['sys_administration'], classLocale::$lang['sys_login_register_message_title'], |
@@ -559,7 +559,7 @@ discard block |
||
559 | 559 | sn_db_transaction_start(); |
560 | 560 | // Проверить наличие такого имени в истории имён |
561 | 561 | |
562 | - if(db_player_name_exists($player_name_unsafe)) { |
|
562 | + if (db_player_name_exists($player_name_unsafe)) { |
|
563 | 563 | throw new Exception(REGISTER_ERROR_PLAYER_NAME_EXISTS, ERR_ERROR); |
564 | 564 | } |
565 | 565 | |
@@ -567,11 +567,11 @@ discard block |
||
567 | 567 | $player_language = ''; |
568 | 568 | $player_email = ''; |
569 | 569 | // TODO - порнография - работа должна происходить над списком аккаунтов, а не только на одном аккаунте... |
570 | - foreach($this->providers_authorised as $provider) { |
|
571 | - if(!$player_language && $provider->account->account_language) { |
|
570 | + foreach ($this->providers_authorised as $provider) { |
|
571 | + if (!$player_language && $provider->account->account_language) { |
|
572 | 572 | $player_language = $provider->account->account_language; |
573 | 573 | } |
574 | - if(!$player_email && $provider->account->account_email) { |
|
574 | + if (!$player_email && $provider->account->account_email) { |
|
575 | 575 | $player_email = $provider->account->account_email; |
576 | 576 | } |
577 | 577 | } |
@@ -587,7 +587,7 @@ discard block |
||
587 | 587 | )); |
588 | 588 | // Зарегестрировать на него аккаунты из self::$accounts_authorised |
589 | 589 | $a_user = self::$user; |
590 | - foreach($this->providers_authorised as $provider) { |
|
590 | + foreach ($this->providers_authorised as $provider) { |
|
591 | 591 | // TODO - порнография. Должен быть отдельный класс трансляторов - в т.ч. и кэширующий транслятор |
592 | 592 | // TODO - ну и работа должна происходить над списком аккаунтов, а не только на одном аккаунте... |
593 | 593 | // self::db_translate_register_user($provider->provider_id, $provider->account->account_id, $a_user['id']); |
@@ -599,7 +599,7 @@ discard block |
||
599 | 599 | |
600 | 600 | sn_db_transaction_commit(); |
601 | 601 | $this->register_status = LOGIN_SUCCESS; |
602 | - } catch(Exception $e) { |
|
602 | + } catch (Exception $e) { |
|
603 | 603 | sn_db_transaction_rollback(); |
604 | 604 | |
605 | 605 | // Если старое имя занято |
@@ -618,10 +618,10 @@ discard block |
||
618 | 618 | // Пробиваем все ИД игроков по базе - есть ли вообще такие записи |
619 | 619 | // Вообще-то это не особо нужно - у нас по определению стоят констраинты |
620 | 620 | // Зато так мы узнаем максимальный authlevel, проверим права имперсонейта и вытащим все записи юзеров |
621 | - foreach($this->user_id_to_provider as $user_id => $cork) { |
|
621 | + foreach ($this->user_id_to_provider as $user_id => $cork) { |
|
622 | 622 | $user = db_user_by_id($user_id); |
623 | 623 | // Если записи игрока в БД не существует? |
624 | - if(empty($user['id'])) { |
|
624 | + if (empty($user['id'])) { |
|
625 | 625 | // Удаляем этого и переходим к следующему |
626 | 626 | unset($this->user_id_to_provider[$user_id]); |
627 | 627 | // Де-регистрируем игрока из таблицы трансляции игроков |
@@ -642,7 +642,7 @@ discard block |
||
642 | 642 | // OK v4.5 |
643 | 643 | protected function get_active_user() { |
644 | 644 | // Проверяем куку "текущего игрока" из браузера |
645 | - if( |
|
645 | + if ( |
|
646 | 646 | // Кука не пустая |
647 | 647 | ($_COOKIE[SN_COOKIE_U] = trim($_COOKIE[SN_COOKIE_U])) && !empty($_COOKIE[SN_COOKIE_U]) |
648 | 648 | // И в куке находится ID |
@@ -667,7 +667,7 @@ discard block |
||
667 | 667 | } |
668 | 668 | |
669 | 669 | // В куке нет валидного ИД записи игрока, доступной с текущих аккаунтов |
670 | - if(empty(self::$user['id'])) { |
|
670 | + if (empty(self::$user['id'])) { |
|
671 | 671 | // Берем первого из доступных |
672 | 672 | // TODO - default_user |
673 | 673 | self::$user = reset($this->accessible_user_row_list); |
@@ -689,7 +689,7 @@ discard block |
||
689 | 689 | |
690 | 690 | $result = array(); |
691 | 691 | |
692 | - if($user_id && empty($this->is_impersonating)) { |
|
692 | + if ($user_id && empty($this->is_impersonating)) { |
|
693 | 693 | // self::db_counter_insert(); |
694 | 694 | self::$device->db_counter_insert($user_id); |
695 | 695 | |
@@ -697,12 +697,12 @@ discard block |
||
697 | 697 | |
698 | 698 | sys_user_options_unpack($user); |
699 | 699 | |
700 | - if($user['banaday'] && $user['banaday'] <= SN_TIME_NOW) { |
|
700 | + if ($user['banaday'] && $user['banaday'] <= SN_TIME_NOW) { |
|
701 | 701 | $user['banaday'] = 0; |
702 | 702 | $user['vacation'] = SN_TIME_NOW; |
703 | 703 | } |
704 | 704 | |
705 | - $user['user_lastip'] = self::$device->ip_v4_string;// $ip['ip']; |
|
705 | + $user['user_lastip'] = self::$device->ip_v4_string; // $ip['ip']; |
|
706 | 706 | $user['user_proxy'] = self::$device->ip_v4_proxy_chain; //$ip['proxy_chain']; |
707 | 707 | |
708 | 708 | $result[F_BANNED_STATUS] = $user['banaday']; |
@@ -716,9 +716,9 @@ discard block |
||
716 | 716 | ); |
717 | 717 | } |
718 | 718 | |
719 | - if($extra = classSupernova::$config->security_ban_extra) { |
|
719 | + if ($extra = classSupernova::$config->security_ban_extra) { |
|
720 | 720 | $extra = explode(',', $extra); |
721 | - array_walk($extra,'trim'); |
|
721 | + array_walk($extra, 'trim'); |
|
722 | 722 | in_array(self::$device->device_id, $extra) and die(); |
723 | 723 | } |
724 | 724 | |
@@ -754,21 +754,21 @@ discard block |
||
754 | 754 | protected function register_player_name_validate($player_name_unsafe) { |
755 | 755 | // TODO - переделать под RAW-строки |
756 | 756 | // Если имя игрока пустое - NO GO! |
757 | - if(trim($player_name_unsafe) == '') { |
|
757 | + if (trim($player_name_unsafe) == '') { |
|
758 | 758 | throw new Exception(REGISTER_ERROR_PLAYER_NAME_EMPTY, ERR_ERROR); |
759 | 759 | } |
760 | 760 | // Проверяем, что бы в начале и конце не было пустых символов |
761 | - if($player_name_unsafe != trim($player_name_unsafe)) { |
|
761 | + if ($player_name_unsafe != trim($player_name_unsafe)) { |
|
762 | 762 | throw new Exception(REGISTER_ERROR_PLAYER_NAME_TRIMMED, ERR_ERROR); |
763 | 763 | } |
764 | 764 | // Если логин имеет запрещенные символы - NO GO! |
765 | - if(strpbrk($player_name_unsafe, LOGIN_REGISTER_CHARACTERS_PROHIBITED)) { |
|
765 | + if (strpbrk($player_name_unsafe, LOGIN_REGISTER_CHARACTERS_PROHIBITED)) { |
|
766 | 766 | // TODO - выдавать в сообщение об ошибке список запрещенных символов |
767 | 767 | // TODO - заранее извещать игрока, какие символы являются запрещенными |
768 | 768 | throw new Exception(REGISTER_ERROR_PLAYER_NAME_RESTRICTED_CHARACTERS, ERR_ERROR); |
769 | 769 | } |
770 | 770 | // Если логин меньше минимальной длины - NO GO! |
771 | - if(strlen($player_name_unsafe) < LOGIN_LENGTH_MIN) { |
|
771 | + if (strlen($player_name_unsafe) < LOGIN_LENGTH_MIN) { |
|
772 | 772 | // TODO - выдавать в сообщение об ошибке минимальную длину имени игрока |
773 | 773 | // TODO - заранее извещать игрока, какая минимальная и максимальная длина имени |
774 | 774 | throw new Exception(REGISTER_ERROR_PLAYER_NAME_SHORT, ERR_ERROR); |
@@ -826,7 +826,7 @@ discard block |
||
826 | 826 | } |
827 | 827 | |
828 | 828 | protected static function flog($message, $die = false) { |
829 | - if(!defined('DEBUG_AUTH') || !DEBUG_AUTH) { |
|
829 | + if (!defined('DEBUG_AUTH') || !DEBUG_AUTH) { |
|
830 | 830 | return; |
831 | 831 | } |
832 | 832 | list($called, $caller) = debug_backtrace(false); |
@@ -839,7 +839,7 @@ discard block |
||
839 | 839 | $_SERVER['SERVER_NAME'] == 'localhost' ? print("<div class='debug'>$message - $caller_name\r\n</div>") : false; |
840 | 840 | |
841 | 841 | classSupernova::log_file("$message - $caller_name"); |
842 | - if($die) { |
|
842 | + if ($die) { |
|
843 | 843 | // pdump($caller); |
844 | 844 | // pdump(debug_backtrace(false)); |
845 | 845 | $die && die("<div class='negative'>СТОП! Функция {$caller_name} при вызове в " . get_called_class() . " (располагается в " . get_class() . "). СООБЩИТЕ АДМИНИСТРАЦИИ!</div>"); |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | */ |
31 | 31 | public function debris_add_resource($resource_id, $resource_amount) { |
32 | 32 | // В обломках может быть только металл или кристалл |
33 | - if($resource_id != RES_METAL && $resource_id != RES_CRYSTAL) { |
|
33 | + if ($resource_id != RES_METAL && $resource_id != RES_CRYSTAL) { |
|
34 | 34 | return; |
35 | 35 | } |
36 | 36 | $this->debris[$resource_id] += $resource_amount; |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * @param bool $is_simulator |
42 | 42 | */ |
43 | 43 | public function add_wrecks(array $wreckage, $is_simulator) { |
44 | - foreach($wreckage as $resource_id => $resource_amount) { |
|
44 | + foreach ($wreckage as $resource_id => $resource_amount) { |
|
45 | 45 | $this->debris_add_resource($resource_id, floor($resource_amount * |
46 | 46 | ($is_simulator |
47 | 47 | ? UBE_SHIP_WRECKS_TO_DEBRIS_AVG |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * @param bool $is_simulator |
58 | 58 | */ |
59 | 59 | public function add_cargo_drop(array $dropped_resources, $is_simulator) { |
60 | - foreach($dropped_resources as $resource_id => $resource_amount) { |
|
60 | + foreach ($dropped_resources as $resource_id => $resource_amount) { |
|
61 | 61 | $this->debris_add_resource($resource_id, floor($resource_amount * |
62 | 62 | ($is_simulator |
63 | 63 | ? UBE_CARGO_DROPPED_TO_DEBRIS_AVG |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * @param $moon_debris_left_part |
97 | 97 | */ |
98 | 98 | public function debris_adjust_proportional($moon_debris_left_part) { |
99 | - foreach($this->debris as $resource_id => &$resource_amount) { |
|
99 | + foreach ($this->debris as $resource_id => &$resource_amount) { |
|
100 | 100 | $resource_amount = floor($resource_amount * $moon_debris_left_part); |
101 | 101 | } |
102 | 102 | } |
@@ -117,9 +117,9 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public function report_generate_sql() { |
119 | 119 | return " |
120 | - `ube_report_debris_metal` = " . (float)$this->debris_get_resource(RES_METAL) . ", |
|
121 | - `ube_report_debris_crystal` = " . (float)$this->debris_get_resource(RES_CRYSTAL) . ", |
|
122 | - `ube_report_debris_total_in_metal` = " . (float)$this->debris_in_metal() . ", "; |
|
120 | + `ube_report_debris_metal` = " . (float) $this->debris_get_resource(RES_METAL) . ", |
|
121 | + `ube_report_debris_crystal` = " . (float) $this->debris_get_resource(RES_CRYSTAL) . ", |
|
122 | + `ube_report_debris_total_in_metal` = " . (float) $this->debris_in_metal() . ", "; |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -89,15 +89,15 @@ discard block |
||
89 | 89 | // Инфа об устройстве и браузере - общая для всех |
90 | 90 | sn_db_transaction_start(); |
91 | 91 | $this->device_cypher = $_COOKIE[SN_COOKIE_D]; |
92 | - if($this->device_cypher) { |
|
92 | + if ($this->device_cypher) { |
|
93 | 93 | $cypher_safe = db_escape($this->device_cypher); |
94 | 94 | $device_id = doquery("SELECT `device_id` FROM {{security_device}} WHERE `device_cypher` = '{$cypher_safe}' LIMIT 1 FOR UPDATE", true); |
95 | - if(!empty($device_id['device_id'])) { |
|
95 | + if (!empty($device_id['device_id'])) { |
|
96 | 96 | $this->device_id = $device_id['device_id']; |
97 | 97 | } |
98 | 98 | } |
99 | 99 | |
100 | - if($this->device_id <= 0) { |
|
100 | + if ($this->device_id <= 0) { |
|
101 | 101 | do { |
102 | 102 | $cypher_safe = db_escape($this->device_cypher = sys_random_string()); |
103 | 103 | $row = doquery("SELECT `device_id` FROM {{security_device}} WHERE `device_cypher` = '{$cypher_safe}' LIMIT 1 FOR UPDATE", true); |
@@ -118,10 +118,10 @@ discard block |
||
118 | 118 | $this->page_address_id = db_get_set_unique_id_value($this->page_address, 'url_id', 'security_url', 'url_string'); |
119 | 119 | sn_db_transaction_commit(); |
120 | 120 | |
121 | - if($this->write_full_url) { |
|
121 | + if ($this->write_full_url) { |
|
122 | 122 | sn_db_transaction_start(); |
123 | 123 | $this->page_url = substr($_SERVER['REQUEST_URI'], strlen(SN_ROOT_RELATIVE)); |
124 | - if(strpos($_SERVER['REQUEST_URI'], '/simulator.php') === 0) { |
|
124 | + if (strpos($_SERVER['REQUEST_URI'], '/simulator.php') === 0) { |
|
125 | 125 | $this->page_url = '/simulator.php'; |
126 | 126 | } |
127 | 127 | $this->page_url_id = db_get_set_unique_id_value($this->page_url, 'url_id', 'security_url', 'url_string'); |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | */ |
145 | 145 | public function db_security_entry_insert($user_id_unsafe) { |
146 | 146 | // TODO $user_id = !empty(self::$user['id']) ? self::$user['id'] : 'NULL'; |
147 | - if(empty($user_id_unsafe)) { |
|
147 | + if (empty($user_id_unsafe)) { |
|
148 | 148 | // self::flog('Нет ИД пользователя'); |
149 | 149 | return true; |
150 | 150 | } |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | public function db_counter_insert($user_id_unsafe) { |
168 | 168 | global $sys_stop_log_hit, $is_watching; |
169 | 169 | |
170 | - if($sys_stop_log_hit || !classSupernova::$config->game_counter) { |
|
170 | + if ($sys_stop_log_hit || !classSupernova::$config->game_counter) { |
|
171 | 171 | return; |
172 | 172 | } |
173 | 173 | |
@@ -183,14 +183,14 @@ discard block |
||
183 | 183 | // $this->ip_v4_int . ", '{$proxy_safe}', " . $this->page_address_id . ", " . $this->page_url_id . ");"); |
184 | 184 | doquery( |
185 | 185 | "INSERT INTO {{counter}} SET |
186 | - `visit_time` = '" . SN_TIME_SQL. "', |
|
186 | + `visit_time` = '" . SN_TIME_SQL . "', |
|
187 | 187 | `user_id` = {$user_id_safe}, |
188 | 188 | `device_id` = {$this->device_id}, |
189 | 189 | `browser_id` = {$this->browser_id}, |
190 | 190 | `user_ip` = {$this->ip_v4_int}, |
191 | 191 | `user_proxy` = '{$proxy_safe}', |
192 | 192 | `page_url_id` = {$this->page_address_id}" . |
193 | - ($this->write_full_url ? ", `plain_url_id` = {$this->page_url_id}" : '' ). |
|
193 | + ($this->write_full_url ? ", `plain_url_id` = {$this->page_url_id}" : '') . |
|
194 | 194 | ";"); |
195 | 195 | |
196 | 196 | $is_watching = false; |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | |
203 | 203 | |
204 | 204 | public static function log_file($message, $spaces = 0) { |
205 | - if(self::$debug) { |
|
205 | + if (self::$debug) { |
|
206 | 206 | self::$debug->log_file($message, $spaces); |
207 | 207 | } |
208 | 208 | } |
@@ -214,16 +214,16 @@ discard block |
||
214 | 214 | // Перепаковывает массив на заданную глубину, убирая поля с null |
215 | 215 | public static function array_repack(&$array, $level = 0) { |
216 | 216 | // TODO $lock_table не нужна тут |
217 | - if(!is_array($array)) { |
|
217 | + if (!is_array($array)) { |
|
218 | 218 | return; |
219 | 219 | } |
220 | 220 | |
221 | - foreach($array as $key => &$value) { |
|
222 | - if($value === null) { |
|
221 | + foreach ($array as $key => &$value) { |
|
222 | + if ($value === null) { |
|
223 | 223 | unset($array[$key]); |
224 | - } elseif($level > 0 && is_array($value)) { |
|
224 | + } elseif ($level > 0 && is_array($value)) { |
|
225 | 225 | static::array_repack($value, $level - 1); |
226 | - if(empty($value)) { |
|
226 | + if (empty($value)) { |
|
227 | 227 | unset($array[$key]); |
228 | 228 | } |
229 | 229 | } |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | // TODO Вынести в отдельный объект |
235 | 235 | public static function cache_repack($location_type, $record_id = 0) { |
236 | 236 | // Если есть $user_id - проверяем, а надо ли перепаковывать? |
237 | - if($record_id && isset(static::$data[$location_type][$record_id]) && static::$data[$location_type][$record_id] !== null) { |
|
237 | + if ($record_id && isset(static::$data[$location_type][$record_id]) && static::$data[$location_type][$record_id] !== null) { |
|
238 | 238 | return; |
239 | 239 | } |
240 | 240 | |
@@ -245,9 +245,9 @@ discard block |
||
245 | 245 | |
246 | 246 | public static function cache_clear($location_type, $hard = true) { |
247 | 247 | //print("<br />CACHE CLEAR {$cache_id} " . ($hard ? 'HARD' : 'SOFT') . "<br />"); |
248 | - if($hard && !empty(static::$data[$location_type])) { |
|
248 | + if ($hard && !empty(static::$data[$location_type])) { |
|
249 | 249 | // Здесь нельзя делать unset - надо записывать NULL, что бы это отразилось на зависимых записях |
250 | - array_walk(static::$data[$location_type], function (&$item) { $item = null; }); |
|
250 | + array_walk(static::$data[$location_type], function(&$item) { $item = null; }); |
|
251 | 251 | } |
252 | 252 | static::$locator[$location_type] = array(); |
253 | 253 | static::$queries[$location_type] = array(); |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | |
257 | 257 | public static function cache_clear_all($hard = true) { |
258 | 258 | //print('<br />CACHE CLEAR ALL<br />'); |
259 | - if($hard) { |
|
259 | + if ($hard) { |
|
260 | 260 | static::$data = array(); |
261 | 261 | static::cache_lock_unset_all(); |
262 | 262 | } |
@@ -285,12 +285,12 @@ discard block |
||
285 | 285 | */ |
286 | 286 | public static function cache_set($location_type, $record_id, $record, $force_overwrite = false, $skip_lock = false) { |
287 | 287 | // нет идентификатора - выход |
288 | - if(!($record_id = $record[static::$location_info[$location_type][P_ID]])) { |
|
288 | + if (!($record_id = $record[static::$location_info[$location_type][P_ID]])) { |
|
289 | 289 | return; |
290 | 290 | } |
291 | 291 | |
292 | 292 | $in_transaction = static::db_transaction_check(false); |
293 | - if( |
|
293 | + if ( |
|
294 | 294 | $force_overwrite |
295 | 295 | || |
296 | 296 | // Не заменяются заблокированные записи во время транзакции |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | !static::cache_isset($location_type, $record_id) |
301 | 301 | ) { |
302 | 302 | static::$data[$location_type][$record_id] = $record; |
303 | - if($in_transaction && !$skip_lock) { |
|
303 | + if ($in_transaction && !$skip_lock) { |
|
304 | 304 | static::cache_lock_set($location_type, $record_id); |
305 | 305 | } |
306 | 306 | } |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | |
309 | 309 | public static function cache_unset($cache_id, $safe_record_id) { |
310 | 310 | // $record_id должен быть проверен заранее ! |
311 | - if(isset(static::$data[$cache_id][$safe_record_id]) && static::$data[$cache_id][$safe_record_id] !== null) { |
|
311 | + if (isset(static::$data[$cache_id][$safe_record_id]) && static::$data[$cache_id][$safe_record_id] !== null) { |
|
312 | 312 | // Выставляем запись в null |
313 | 313 | static::$data[$cache_id][$safe_record_id] = null; |
314 | 314 | // Очищаем кэш мягко - что бы удалить очистить связанные данные - кэш локаций и кэш запоросов и всё, что потребуется впредь |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | } |
326 | 326 | |
327 | 327 | public static function cache_lock_unset($location_type, $record_id) { |
328 | - if(isset(static::$locks[$location_type][$record_id])) { |
|
328 | + if (isset(static::$locks[$location_type][$record_id])) { |
|
329 | 329 | unset(static::$locks[$location_type][$record_id]); |
330 | 330 | } |
331 | 331 | |
@@ -359,13 +359,13 @@ discard block |
||
359 | 359 | */ |
360 | 360 | public static function db_transaction_check($status = null) { |
361 | 361 | $error_msg = false; |
362 | - if($status && !static::$db_in_transaction) { |
|
362 | + if ($status && !static::$db_in_transaction) { |
|
363 | 363 | $error_msg = 'No transaction started for current operation'; |
364 | - } elseif($status === null && static::$db_in_transaction) { |
|
364 | + } elseif ($status === null && static::$db_in_transaction) { |
|
365 | 365 | $error_msg = 'Transaction is already started'; |
366 | 366 | } |
367 | 367 | |
368 | - if($error_msg) { |
|
368 | + if ($error_msg) { |
|
369 | 369 | // TODO - Убрать позже |
370 | 370 | print('<h1>СООБЩИТЕ ЭТО АДМИНУ: sn_db_transaction_check() - ' . $error_msg . '</h1>'); |
371 | 371 | $backtrace = debug_backtrace(); |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | static::$transaction_id++; |
386 | 386 | doquery('START TRANSACTION'); |
387 | 387 | |
388 | - if(classSupernova::$config->db_manual_lock_enabled) { |
|
388 | + if (classSupernova::$config->db_manual_lock_enabled) { |
|
389 | 389 | classSupernova::$config->db_loadItem('var_db_manually_locked'); |
390 | 390 | classSupernova::$config->db_saveItem('var_db_manually_locked', SN_TIME_SQL); |
391 | 391 | } |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | public static function db_transaction_commit() { |
403 | 403 | static::db_transaction_check(true); |
404 | 404 | |
405 | - if(!empty(static::$delayed_changset)) { |
|
405 | + if (!empty(static::$delayed_changset)) { |
|
406 | 406 | static::db_changeset_apply(static::$delayed_changset, true); |
407 | 407 | // pdump(static::$delayed_changset); |
408 | 408 | } |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | |
419 | 419 | public static function db_transaction_rollback() { |
420 | 420 | // static::db_transaction_check(true); // TODO - вообще-то тут тоже надо проверять есть ли транзакция |
421 | - if(!empty(static::$delayed_changset)) { |
|
421 | + if (!empty(static::$delayed_changset)) { |
|
422 | 422 | static::db_changeset_revert(); |
423 | 423 | } |
424 | 424 | static::$delayed_changset = array(); |
@@ -441,7 +441,7 @@ discard block |
||
441 | 441 | */ |
442 | 442 | public static function db_lock_tables($tables) { |
443 | 443 | $tables = is_array($tables) ? $tables : array($tables => ''); |
444 | - foreach($tables as $table_name => $condition) { |
|
444 | + foreach ($tables as $table_name => $condition) { |
|
445 | 445 | self::$db->doquery("SELECT 1 FROM {{{$table_name}}}" . ($condition ? ' WHERE ' . $condition : '')); |
446 | 446 | } |
447 | 447 | } |
@@ -484,17 +484,17 @@ discard block |
||
484 | 484 | //pdump($filter, 'Выбираем ' . $location_type); |
485 | 485 | $query_cache = &static::$queries[$location_type][$filter]; |
486 | 486 | |
487 | - if(!isset($query_cache) || $query_cache === null) { |
|
487 | + if (!isset($query_cache) || $query_cache === null) { |
|
488 | 488 | // pdump($filter, 'Кэш пустой, начинаем возню'); |
489 | 489 | $location_info = &static::$location_info[$location_type]; |
490 | 490 | $id_field = $location_info[P_ID]; |
491 | 491 | $query_cache = array(); |
492 | 492 | |
493 | - if(static::db_transaction_check(false)) { |
|
493 | + if (static::db_transaction_check(false)) { |
|
494 | 494 | //pdump($filter, 'Транзакция - блокируем ' . $location_type); |
495 | 495 | // Проходим по всем родителям данной записи |
496 | 496 | // foreach($location_info[P_OWNER_INFO] as $owner_location_type => $owner_data) |
497 | - foreach($location_info[P_OWNER_INFO] as $owner_data) { |
|
497 | + foreach ($location_info[P_OWNER_INFO] as $owner_data) { |
|
498 | 498 | $owner_location_type = $owner_data[P_LOCATION]; |
499 | 499 | //pdump($filter, 'Транзакция - блокируем родителя ' . $owner_location_type); |
500 | 500 | $parent_id_list = array(); |
@@ -507,15 +507,15 @@ discard block |
||
507 | 507 | ($fetch ? ' LIMIT 1' : ''), false, true); |
508 | 508 | |
509 | 509 | //pdump($q, 'Запрос блокировки'); |
510 | - while($row = db_fetch($query)) { |
|
510 | + while ($row = db_fetch($query)) { |
|
511 | 511 | // Исключаем из списка родительских ИД уже заблокированные записи |
512 | - if(!static::cache_lock_get($owner_location_type, $row['parent_id'])) { |
|
512 | + if (!static::cache_lock_get($owner_location_type, $row['parent_id'])) { |
|
513 | 513 | $parent_id_list[$row['parent_id']] = $row['parent_id']; |
514 | 514 | } |
515 | 515 | } |
516 | 516 | //pdump($parent_id_list, 'Выбраны родители'); |
517 | 517 | // Если все-таки какие-то записи еще не заблокированы - вынимаем текущие версии из базы |
518 | - if($indexes_str = implode(',', $parent_id_list)) { |
|
518 | + if ($indexes_str = implode(',', $parent_id_list)) { |
|
519 | 519 | //pdump($indexes_str, '$indexes_str'); |
520 | 520 | $parent_id_field = static::$location_info[$owner_location_type][P_ID]; |
521 | 521 | static::db_get_record_list($owner_location_type, |
@@ -530,7 +530,7 @@ discard block |
||
530 | 530 | "SELECT * FROM {{{$location_info[P_TABLE_NAME]}}}" . |
531 | 531 | (($filter = trim($filter)) ? " WHERE {$filter}" : '') |
532 | 532 | ); |
533 | - while($row = db_fetch($query)) { |
|
533 | + while ($row = db_fetch($query)) { |
|
534 | 534 | // static::db_get_record_by_id($location_type, $row[$id_field]); |
535 | 535 | static::cache_set($location_type, $row[$id_field], $row); |
536 | 536 | $query_cache[$row[$id_field]] = &static::$data[$location_type][$row[$id_field]]; |
@@ -538,14 +538,14 @@ discard block |
||
538 | 538 | } |
539 | 539 | } |
540 | 540 | |
541 | - if($no_return) { |
|
541 | + if ($no_return) { |
|
542 | 542 | return true; |
543 | 543 | } else { |
544 | 544 | $result = false; |
545 | - if(is_array($query_cache)) { |
|
546 | - foreach($query_cache as $key => $value) { |
|
545 | + if (is_array($query_cache)) { |
|
546 | + foreach ($query_cache as $key => $value) { |
|
547 | 547 | $result[$key] = $value; |
548 | - if($fetch) { |
|
548 | + if ($fetch) { |
|
549 | 549 | break; |
550 | 550 | } |
551 | 551 | } |
@@ -564,16 +564,16 @@ discard block |
||
564 | 564 | */ |
565 | 565 | public static function db_upd_record_by_id($location_type, $record_id, $set) { |
566 | 566 | //if(!($record_id = intval($record_id)) || !($set = trim($set))) return false; |
567 | - if(!($record_id = idval($record_id)) || !($set = trim($set))) { |
|
567 | + if (!($record_id = idval($record_id)) || !($set = trim($set))) { |
|
568 | 568 | return false; |
569 | 569 | } |
570 | 570 | |
571 | 571 | $location_info = &static::$location_info[$location_type]; |
572 | 572 | $id_field = $location_info[P_ID]; |
573 | 573 | $table_name = $location_info[P_TABLE_NAME]; |
574 | - if($result = static::db_query($q = "UPDATE {{{$table_name}}} SET {$set} WHERE `{$id_field}` = {$record_id}")) // TODO Как-то вернуть может быть LIMIT 1 ? |
|
574 | + if ($result = static::db_query($q = "UPDATE {{{$table_name}}} SET {$set} WHERE `{$id_field}` = {$record_id}")) // TODO Как-то вернуть может быть LIMIT 1 ? |
|
575 | 575 | { |
576 | - if(static::$db->db_affected_rows()) { |
|
576 | + if (static::$db->db_affected_rows()) { |
|
577 | 577 | // Обновляем данные только если ряд был затронут |
578 | 578 | // TODO - переделать под работу со структурированными $set |
579 | 579 | |
@@ -589,7 +589,7 @@ discard block |
||
589 | 589 | } |
590 | 590 | |
591 | 591 | public static function db_upd_record_list($location_type, $condition, $set) { |
592 | - if(!($set = trim($set))) { |
|
592 | + if (!($set = trim($set))) { |
|
593 | 593 | return false; |
594 | 594 | } |
595 | 595 | |
@@ -598,9 +598,9 @@ discard block |
||
598 | 598 | |
599 | 599 | //static::db_get_record_list($location_type, $condition, false, true); |
600 | 600 | |
601 | - if($result = static::db_query("UPDATE {{{$table_name}}} SET " . $set . ($condition ? ' WHERE ' . $condition : ''))) { |
|
601 | + if ($result = static::db_query("UPDATE {{{$table_name}}} SET " . $set . ($condition ? ' WHERE ' . $condition : ''))) { |
|
602 | 602 | |
603 | - if(static::$db->db_affected_rows()) { // Обновляем данные только если ряд был затронут |
|
603 | + if (static::$db->db_affected_rows()) { // Обновляем данные только если ряд был затронут |
|
604 | 604 | // Поскольку нам неизвестно, что и как обновилось - сбрасываем кэш этого типа полностью |
605 | 605 | // TODO - когда будет структурированный $condition и $set - перепаковывать данные |
606 | 606 | static::cache_clear($location_type, true); |
@@ -619,8 +619,8 @@ discard block |
||
619 | 619 | public static function db_ins_record($location_type, $set) { |
620 | 620 | $set = trim($set); |
621 | 621 | $table_name = static::$location_info[$location_type][P_TABLE_NAME]; |
622 | - if($result = static::db_query("INSERT INTO `{{{$table_name}}}` SET {$set}")) { |
|
623 | - if(static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
622 | + if ($result = static::db_query("INSERT INTO `{{{$table_name}}}` SET {$set}")) { |
|
623 | + if (static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
624 | 624 | { |
625 | 625 | $record_id = db_insert_id(); |
626 | 626 | // Вытаскиваем запись целиком, потому что в $set могли быть "данные по умолчанию" |
@@ -642,8 +642,8 @@ discard block |
||
642 | 642 | $fields = implode(',', array_keys($field_set)); |
643 | 643 | |
644 | 644 | $table_name = static::$location_info[$location_type][P_TABLE_NAME]; |
645 | - if($result = static::db_query("INSERT INTO `{{{$table_name}}}` ($fields) VALUES ($values);")) { |
|
646 | - if(static::$db->db_affected_rows()) { |
|
645 | + if ($result = static::db_query("INSERT INTO `{{{$table_name}}}` ($fields) VALUES ($values);")) { |
|
646 | + if (static::$db->db_affected_rows()) { |
|
647 | 647 | // Обновляем данные только если ряд был затронут |
648 | 648 | $record_id = db_insert_id(); |
649 | 649 | // Вытаскиваем запись целиком, потому что в $set могли быть "данные по умолчанию" |
@@ -659,15 +659,15 @@ discard block |
||
659 | 659 | |
660 | 660 | public static function db_del_record_by_id($location_type, $safe_record_id) { |
661 | 661 | // if(!($safe_record_id = intval($safe_record_id))) return false; |
662 | - if(!($safe_record_id = idval($safe_record_id))) { |
|
662 | + if (!($safe_record_id = idval($safe_record_id))) { |
|
663 | 663 | return false; |
664 | 664 | } |
665 | 665 | |
666 | 666 | $location_info = &static::$location_info[$location_type]; |
667 | 667 | $id_field = $location_info[P_ID]; |
668 | 668 | $table_name = $location_info[P_TABLE_NAME]; |
669 | - if($result = static::db_query("DELETE FROM `{{{$table_name}}}` WHERE `{$id_field}` = {$safe_record_id}")) { |
|
670 | - if(static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
669 | + if ($result = static::db_query("DELETE FROM `{{{$table_name}}}` WHERE `{$id_field}` = {$safe_record_id}")) { |
|
670 | + if (static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
671 | 671 | { |
672 | 672 | static::cache_unset($location_type, $safe_record_id); |
673 | 673 | } |
@@ -677,7 +677,7 @@ discard block |
||
677 | 677 | } |
678 | 678 | |
679 | 679 | public static function db_del_record_list($location_type, $condition) { |
680 | - if(!($condition = trim($condition))) { |
|
680 | + if (!($condition = trim($condition))) { |
|
681 | 681 | return false; |
682 | 682 | } |
683 | 683 | |
@@ -686,8 +686,8 @@ discard block |
||
686 | 686 | |
687 | 687 | //static::db_get_record_list($location_type, $condition, false, true); |
688 | 688 | |
689 | - if($result = static::db_query("DELETE FROM `{{{$table_name}}}` WHERE {$condition}")) { |
|
690 | - if(static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
689 | + if ($result = static::db_query("DELETE FROM `{{{$table_name}}}` WHERE {$condition}")) { |
|
690 | + if (static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
691 | 691 | { |
692 | 692 | // Обнуление кэша, потому что непонятно, что поменялось |
693 | 693 | // TODO - когда будет структурированный $condition можно будет делать только cache_unset по нужным записям |
@@ -734,20 +734,20 @@ discard block |
||
734 | 734 | |
735 | 735 | public static function db_get_user_by_username($username_unsafe, $for_update = false, $fields = '*', $player = null, $like = false) { |
736 | 736 | // TODO Проверить, кстати - а везде ли нужно выбирать юзеров или где-то все-таки ищутся Альянсы ? |
737 | - if(!($username_unsafe = trim($username_unsafe))) { |
|
737 | + if (!($username_unsafe = trim($username_unsafe))) { |
|
738 | 738 | return false; |
739 | 739 | } |
740 | 740 | |
741 | 741 | $user = null; |
742 | - if(is_array(static::$data[LOC_USER])) { |
|
743 | - foreach(static::$data[LOC_USER] as $user_id => $user_data) { |
|
744 | - if(is_array($user_data) && isset($user_data['username'])) { |
|
742 | + if (is_array(static::$data[LOC_USER])) { |
|
743 | + foreach (static::$data[LOC_USER] as $user_id => $user_data) { |
|
744 | + if (is_array($user_data) && isset($user_data['username'])) { |
|
745 | 745 | // проверяем поле |
746 | 746 | // TODO Возможно есть смысл всегда искать по strtolower - но может игрок захочет переименоваться с другим регистром? Проверить! |
747 | - if((!$like && $user_data['username'] == $username_unsafe) || ($like && strtolower($user_data['username']) == strtolower($username_unsafe))) { |
|
747 | + if ((!$like && $user_data['username'] == $username_unsafe) || ($like && strtolower($user_data['username']) == strtolower($username_unsafe))) { |
|
748 | 748 | // $user_as_ally = intval($user_data['user_as_ally']); |
749 | 749 | $user_as_ally = idval($user_data['user_as_ally']); |
750 | - if($player === null || ($player === true && !$user_as_ally) || ($player === false && $user_as_ally)) { |
|
750 | + if ($player === null || ($player === true && !$user_as_ally) || ($player === false && $user_as_ally)) { |
|
751 | 751 | $user = $user_data; |
752 | 752 | break; |
753 | 753 | } |
@@ -756,7 +756,7 @@ discard block |
||
756 | 756 | } |
757 | 757 | } |
758 | 758 | |
759 | - if($user === null) { |
|
759 | + if ($user === null) { |
|
760 | 760 | // Вытаскиваем запись |
761 | 761 | $username_safe = db_escape($like ? strtolower($username_unsafe) : $username_unsafe); // тут на самом деле strtolower() лишняя, но пусть будет |
762 | 762 | |
@@ -774,17 +774,17 @@ discard block |
||
774 | 774 | |
775 | 775 | // UNUSED |
776 | 776 | public static function db_get_user_by_email($email_unsafe, $use_both = false, $for_update = false, $fields = '*') { |
777 | - if(!($email_unsafe = strtolower(trim($email_unsafe)))) { |
|
777 | + if (!($email_unsafe = strtolower(trim($email_unsafe)))) { |
|
778 | 778 | return false; |
779 | 779 | } |
780 | 780 | |
781 | 781 | $user = null; |
782 | 782 | // TODO переделать на индексы |
783 | - if(is_array(static::$data[LOC_USER])) { |
|
784 | - foreach(static::$data[LOC_USER] as $user_id => $user_data) { |
|
785 | - if(is_array($user_data) && isset($user_data['email_2'])) { |
|
783 | + if (is_array(static::$data[LOC_USER])) { |
|
784 | + foreach (static::$data[LOC_USER] as $user_id => $user_data) { |
|
785 | + if (is_array($user_data) && isset($user_data['email_2'])) { |
|
786 | 786 | // проверяем поле |
787 | - if(strtolower($user_data['email_2']) == $email_unsafe || ($use_both && strtolower($user_data['email']) == $email_unsafe)) { |
|
787 | + if (strtolower($user_data['email_2']) == $email_unsafe || ($use_both && strtolower($user_data['email']) == $email_unsafe)) { |
|
788 | 788 | $user = $user_data; |
789 | 789 | break; |
790 | 790 | } |
@@ -792,7 +792,7 @@ discard block |
||
792 | 792 | } |
793 | 793 | } |
794 | 794 | |
795 | - if($user === null) { |
|
795 | + if ($user === null) { |
|
796 | 796 | // Вытаскиваем запись |
797 | 797 | $email_safe = db_escape($email_unsafe); |
798 | 798 | $user = static::db_query( |
@@ -811,7 +811,7 @@ discard block |
||
811 | 811 | $user = null; |
812 | 812 | // TODO переделать на индексы |
813 | 813 | |
814 | - if($user === null && !empty($where_safe)) { |
|
814 | + if ($user === null && !empty($where_safe)) { |
|
815 | 815 | // Вытаскиваем запись |
816 | 816 | $user = static::db_query("SELECT * FROM {{users}} WHERE {$where_safe}", true); |
817 | 817 | |
@@ -833,7 +833,7 @@ discard block |
||
833 | 833 | public static function db_get_unit_by_id($unit_id, $for_update = false, $fields = '*') { |
834 | 834 | // TODO запихивать в $data[LOC_LOCATION][$location_type][$location_id] |
835 | 835 | $unit = static::db_get_record_by_id(LOC_UNIT, $unit_id, $for_update, $fields); |
836 | - if(is_array($unit)) { |
|
836 | + if (is_array($unit)) { |
|
837 | 837 | static::$locator[LOC_UNIT][$unit['unit_location_type']][$unit['unit_location_id']][$unit['unit_snid']] = &static::$data[LOC_UNIT][$unit_id]; |
838 | 838 | } |
839 | 839 | |
@@ -849,15 +849,15 @@ discard block |
||
849 | 849 | */ |
850 | 850 | public static function db_get_unit_list_by_location($user_id = 0, $location_type, $location_id) { |
851 | 851 | //if(!($location_type = intval($location_type)) || !($location_id = intval($location_id))) return false; |
852 | - if(!($location_type = idval($location_type)) || !($location_id = idval($location_id))) { |
|
852 | + if (!($location_type = idval($location_type)) || !($location_id = idval($location_id))) { |
|
853 | 853 | return false; |
854 | 854 | } |
855 | 855 | |
856 | 856 | $query_cache = &static::$locator[LOC_UNIT][$location_type][$location_id]; |
857 | - if(!isset($query_cache)) { |
|
857 | + if (!isset($query_cache)) { |
|
858 | 858 | $got_data = static::db_get_record_list(LOC_UNIT, "unit_location_type = {$location_type} AND unit_location_id = {$location_id} AND " . static::db_unit_time_restrictions()); |
859 | - if(is_array($got_data)) { |
|
860 | - foreach($got_data as $unit_id => $unit_data) { |
|
859 | + if (is_array($got_data)) { |
|
860 | + foreach ($got_data as $unit_id => $unit_data) { |
|
861 | 861 | // static::$data[LOC_LOCATION][$location_type][$location_id][$unit_data['unit_snid']] = &static::$data[LOC_UNIT][$unit_id]; |
862 | 862 | $query_cache[$unit_data['unit_snid']] = &static::$data[LOC_UNIT][$unit_id]; |
863 | 863 | } |
@@ -865,8 +865,8 @@ discard block |
||
865 | 865 | } |
866 | 866 | |
867 | 867 | $result = false; |
868 | - if(is_array($query_cache)) { |
|
869 | - foreach($query_cache as $key => $value) { |
|
868 | + if (is_array($query_cache)) { |
|
869 | + foreach ($query_cache as $key => $value) { |
|
870 | 870 | $result[$key] = $value; |
871 | 871 | } |
872 | 872 | } |
@@ -901,7 +901,7 @@ discard block |
||
901 | 901 | * |
902 | 902 | */ |
903 | 903 | public static function db_que_list_by_type_location($user_id, $planet_id = null, $que_type = false, $for_update = false) { |
904 | - if(!$user_id) { |
|
904 | + if (!$user_id) { |
|
905 | 905 | pdump(debug_backtrace()); |
906 | 906 | die('No user_id for que_get_que()'); |
907 | 907 | } |
@@ -911,16 +911,16 @@ discard block |
||
911 | 911 | $query = array(); |
912 | 912 | |
913 | 913 | // if($user_id = intval($user_id)) |
914 | - if($user_id = idval($user_id)) { |
|
914 | + if ($user_id = idval($user_id)) { |
|
915 | 915 | $query[] = "`que_player_id` = {$user_id}"; |
916 | 916 | } |
917 | 917 | |
918 | - if($que_type == QUE_RESEARCH || $planet_id === null) { |
|
918 | + if ($que_type == QUE_RESEARCH || $planet_id === null) { |
|
919 | 919 | $query[] = "`que_planet_id` IS NULL"; |
920 | - } elseif($planet_id) { |
|
920 | + } elseif ($planet_id) { |
|
921 | 921 | $query[] = "(`que_planet_id` = {$planet_id}" . ($que_type ? '' : ' OR que_planet_id IS NULL') . ")"; |
922 | 922 | } |
923 | - if($que_type) { |
|
923 | + if ($que_type) { |
|
924 | 924 | $query[] = "`que_type` = {$que_type}"; |
925 | 925 | } |
926 | 926 | |
@@ -953,13 +953,13 @@ discard block |
||
953 | 953 | |
954 | 954 | |
955 | 955 | public static function db_changeset_prepare_unit($unit_id, $unit_value, $user, $planet_id = null) { |
956 | - if(!is_array($user)) { |
|
956 | + if (!is_array($user)) { |
|
957 | 957 | // TODO - remove later |
958 | 958 | print('<h1>СООБЩИТЕ ЭТО АДМИНУ: sn_db_unit_changeset_prepare() - USER is not ARRAY</h1>'); |
959 | 959 | pdump(debug_backtrace()); |
960 | 960 | die('USER is not ARRAY'); |
961 | 961 | } |
962 | - if(!isset($user['id']) || !$user['id']) { |
|
962 | + if (!isset($user['id']) || !$user['id']) { |
|
963 | 963 | // TODO - remove later |
964 | 964 | print('<h1>СООБЩИТЕ ЭТО АДМИНУ: sn_db_unit_changeset_prepare() - USER[id] пустой</h1>'); |
965 | 965 | pdump($user); |
@@ -974,7 +974,7 @@ discard block |
||
974 | 974 | |
975 | 975 | $db_changeset = array(); |
976 | 976 | $temp = db_unit_by_location($user['id'], $unit_location, $location_id, $unit_id, true, 'unit_id'); |
977 | - if($temp['unit_id']) { |
|
977 | + if ($temp['unit_id']) { |
|
978 | 978 | $db_changeset = array( |
979 | 979 | 'action' => SQL_OP_UPDATE, |
980 | 980 | P_VERSION => 1, |
@@ -1043,9 +1043,9 @@ discard block |
||
1043 | 1043 | } |
1044 | 1044 | |
1045 | 1045 | public function db_changeset_condition_compile(&$conditions, &$table_name = '') { |
1046 | - if(!$conditions[P_LOCATION] || $conditions[P_LOCATION] == LOC_NONE) { |
|
1046 | + if (!$conditions[P_LOCATION] || $conditions[P_LOCATION] == LOC_NONE) { |
|
1047 | 1047 | $conditions[P_LOCATION] = LOC_NONE; |
1048 | - switch($table_name) { |
|
1048 | + switch ($table_name) { |
|
1049 | 1049 | case 'users': |
1050 | 1050 | case LOC_USER: |
1051 | 1051 | $conditions[P_TABLE_NAME] = $table_name = 'users'; |
@@ -1067,18 +1067,18 @@ discard block |
||
1067 | 1067 | } |
1068 | 1068 | |
1069 | 1069 | $conditions[P_FIELDS_STR] = ''; |
1070 | - if($conditions['fields']) { |
|
1070 | + if ($conditions['fields']) { |
|
1071 | 1071 | $fields = array(); |
1072 | - foreach($conditions['fields'] as $field_name => $field_data) { |
|
1072 | + foreach ($conditions['fields'] as $field_name => $field_data) { |
|
1073 | 1073 | $condition = "`{$field_name}` = "; |
1074 | 1074 | $value = ''; |
1075 | - if($field_data['delta']) { |
|
1075 | + if ($field_data['delta']) { |
|
1076 | 1076 | $value = "`{$field_name}`" . ($field_data['delta'] >= 0 ? '+' : '') . $field_data['delta']; |
1077 | - } elseif($field_data['set']) { |
|
1077 | + } elseif ($field_data['set']) { |
|
1078 | 1078 | $value = (is_string($field_data['set']) ? "'{$field_data['set']}'" : $field_data['set']); |
1079 | 1079 | } |
1080 | 1080 | |
1081 | - if($value) { |
|
1081 | + if ($value) { |
|
1082 | 1082 | $fields[] = $condition . $value; |
1083 | 1083 | } |
1084 | 1084 | } |
@@ -1086,16 +1086,14 @@ discard block |
||
1086 | 1086 | } |
1087 | 1087 | |
1088 | 1088 | $conditions[P_WHERE_STR] = ''; |
1089 | - if(!empty($conditions['where'])) { |
|
1090 | - if($conditions[P_VERSION] == 1) { |
|
1089 | + if (!empty($conditions['where'])) { |
|
1090 | + if ($conditions[P_VERSION] == 1) { |
|
1091 | 1091 | $the_conditions = array(); |
1092 | - foreach($conditions['where'] as $field_id => $field_value) { |
|
1092 | + foreach ($conditions['where'] as $field_id => $field_value) { |
|
1093 | 1093 | // Простое условие - $field_id = $field_value |
1094 | - if(is_string($field_id)) { |
|
1094 | + if (is_string($field_id)) { |
|
1095 | 1095 | $field_value = |
1096 | - $field_value === null ? 'NULL' : |
|
1097 | - (is_string($field_value) ? "'" . db_escape($field_value) . "'" : |
|
1098 | - (is_bool($field_value) ? intval($field_value) : $field_value)); |
|
1096 | + $field_value === null ? 'NULL' : (is_string($field_value) ? "'" . db_escape($field_value) . "'" : (is_bool($field_value) ? intval($field_value) : $field_value)); |
|
1099 | 1097 | $the_conditions[] = "`{$field_id}` = {$field_value}"; |
1100 | 1098 | } else { |
1101 | 1099 | die('Неподдерживаемый тип условия'); |
@@ -1112,7 +1110,7 @@ discard block |
||
1112 | 1110 | $conditions[P_WHERE_STR] = implode(' AND ', $the_conditions); |
1113 | 1111 | } |
1114 | 1112 | |
1115 | - switch($conditions['action']) { |
|
1113 | + switch ($conditions['action']) { |
|
1116 | 1114 | case SQL_OP_DELETE: |
1117 | 1115 | $conditions[P_ACTION_STR] = ("DELETE FROM {{{$table_name}}}"); |
1118 | 1116 | break; |
@@ -1132,11 +1130,11 @@ discard block |
||
1132 | 1130 | |
1133 | 1131 | public static function db_changeset_apply($db_changeset, $flush_delayed = false) { |
1134 | 1132 | $result = true; |
1135 | - if(!is_array($db_changeset) || empty($db_changeset)) { |
|
1133 | + if (!is_array($db_changeset) || empty($db_changeset)) { |
|
1136 | 1134 | return $result; |
1137 | 1135 | } |
1138 | 1136 | |
1139 | - foreach($db_changeset as $table_name => &$table_data) { |
|
1137 | + foreach ($db_changeset as $table_name => &$table_data) { |
|
1140 | 1138 | // TODO - delayed changeset |
1141 | 1139 | /* |
1142 | 1140 | if(static::db_transaction_check(false) && !$flush_delayed && ($table_name == 'users' || $table_name == 'planets' || $table_name == 'unit')) |
@@ -1145,19 +1143,19 @@ discard block |
||
1145 | 1143 | continue; |
1146 | 1144 | } |
1147 | 1145 | */ |
1148 | - foreach($table_data as $record_id => &$conditions) { |
|
1146 | + foreach ($table_data as $record_id => &$conditions) { |
|
1149 | 1147 | static::db_changeset_condition_compile($conditions, $table_name); |
1150 | 1148 | |
1151 | - if($conditions['action'] != SQL_OP_DELETE && !$conditions[P_FIELDS_STR]) { |
|
1149 | + if ($conditions['action'] != SQL_OP_DELETE && !$conditions[P_FIELDS_STR]) { |
|
1152 | 1150 | continue; |
1153 | 1151 | } |
1154 | - if($conditions['action'] == SQL_OP_DELETE && !$conditions[P_WHERE_STR]) { |
|
1152 | + if ($conditions['action'] == SQL_OP_DELETE && !$conditions[P_WHERE_STR]) { |
|
1155 | 1153 | continue; |
1156 | 1154 | } // Защита от случайного удаления всех данных в таблице |
1157 | 1155 | |
1158 | - if($conditions[P_LOCATION] != LOC_NONE) { |
|
1156 | + if ($conditions[P_LOCATION] != LOC_NONE) { |
|
1159 | 1157 | //die('spec ops supernova.php line 928 Добавить работу с кэшем юнитов итд'); |
1160 | - switch($conditions['action']) { |
|
1158 | + switch ($conditions['action']) { |
|
1161 | 1159 | case SQL_OP_DELETE: |
1162 | 1160 | $result = self::db_del_record_list($conditions[P_LOCATION], $conditions[P_WHERE_STR]) && $result; |
1163 | 1161 | break; |
@@ -1239,13 +1237,13 @@ discard block |
||
1239 | 1237 | public static function init_0_prepare() { |
1240 | 1238 | // Отключаем magic_quotes |
1241 | 1239 | ini_get('magic_quotes_sybase') ? die('SN is incompatible with \'magic_quotes_sybase\' turned on. Disable it in php.ini or .htaccess...') : false; |
1242 | - if(@get_magic_quotes_gpc()) { |
|
1240 | + if (@get_magic_quotes_gpc()) { |
|
1243 | 1241 | $gpcr = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST); |
1244 | - array_walk_recursive($gpcr, function (&$value, $key) { |
|
1242 | + array_walk_recursive($gpcr, function(&$value, $key) { |
|
1245 | 1243 | $value = stripslashes($value); |
1246 | 1244 | }); |
1247 | 1245 | } |
1248 | - if(function_exists('set_magic_quotes_runtime')) { |
|
1246 | + if (function_exists('set_magic_quotes_runtime')) { |
|
1249 | 1247 | @set_magic_quotes_runtime(0); |
1250 | 1248 | @ini_set('magic_quotes_runtime', 0); |
1251 | 1249 | @ini_set('magic_quotes_sybase', 0); |
@@ -1317,7 +1315,7 @@ discard block |
||
1317 | 1315 | } |
1318 | 1316 | |
1319 | 1317 | public static function init_debug_state() { |
1320 | - if($_SERVER['SERVER_NAME'] == 'localhost' && !defined('BE_DEBUG')) { |
|
1318 | + if ($_SERVER['SERVER_NAME'] == 'localhost' && !defined('BE_DEBUG')) { |
|
1321 | 1319 | define('BE_DEBUG', true); |
1322 | 1320 | } |
1323 | 1321 | // define('DEBUG_SQL_ONLINE', true); // Полный дамп запросов в рил-тайме. Подойдет любое значение |
@@ -1329,7 +1327,7 @@ discard block |
||
1329 | 1327 | defined('DEBUG_SQL_ERROR') && !defined('DEBUG_SQL_COMMENT') ? define('DEBUG_SQL_COMMENT', true) : false; |
1330 | 1328 | defined('DEBUG_SQL_COMMENT_LONG') && !defined('DEBUG_SQL_COMMENT') ? define('DEBUG_SQL_COMMENT', true) : false; |
1331 | 1329 | |
1332 | - if(defined('BE_DEBUG') || static::$config->debug) { |
|
1330 | + if (defined('BE_DEBUG') || static::$config->debug) { |
|
1333 | 1331 | @define('BE_DEBUG', true); |
1334 | 1332 | @ini_set('display_errors', 1); |
1335 | 1333 | @error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED); |