@@ -4,18 +4,18 @@ discard block |
||
4 | 4 | // @version 1.0 |
5 | 5 | // @copyright 2008 by Chlorel for XNova |
6 | 6 | |
7 | -if(SN_IN_FLEET !== true) { |
|
7 | +if (SN_IN_FLEET !== true) { |
|
8 | 8 | $debug->error("Attempt to call FLEET page mode {$mode} directly - not from fleet.php", 'Forbidden', 403); |
9 | 9 | } |
10 | 10 | |
11 | 11 | $template = gettemplate('fleet1', true); |
12 | 12 | |
13 | 13 | $ships = sys_get_param('ships', array()); |
14 | -if(!is_array($ships)) { |
|
14 | +if (!is_array($ships)) { |
|
15 | 15 | $ships = array(); |
16 | 16 | } |
17 | 17 | |
18 | -foreach(array(PT_PLANET, PT_DEBRIS, PT_MOON) as $possible_planet_type_id) { |
|
18 | +foreach (array(PT_PLANET, PT_DEBRIS, PT_MOON) as $possible_planet_type_id) { |
|
19 | 19 | $template->assign_block_vars('possible_planet_type_id', array( |
20 | 20 | 'ID' => $possible_planet_type_id, |
21 | 21 | 'NAME' => $lang['sys_planet_type_sh'][$possible_planet_type_id], |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | 'START_NAME' => $planetrow['name'], |
29 | 29 | ); |
30 | 30 | |
31 | -if(!empty($TargetPlanet)) { |
|
31 | +if (!empty($TargetPlanet)) { |
|
32 | 32 | $template_route += array( |
33 | 33 | 'END_TYPE_TEXT_SH' => $lang['sys_planet_type_sh'][$TargetPlanet['planet_type']], |
34 | 34 | 'END_COORDS' => uni_render_coordinates($TargetPlanet), |
@@ -39,10 +39,10 @@ discard block |
||
39 | 39 | $template->assign_block_vars('fleets', $template_route); |
40 | 40 | |
41 | 41 | $sn_groups_fleet = sn_get_groups('fleet'); |
42 | -foreach($ships as $ship_id => $ship_count) { |
|
43 | - if(in_array($ship_id, $sn_groups_fleet) && $ship_count) { |
|
42 | +foreach ($ships as $ship_id => $ship_count) { |
|
43 | + if (in_array($ship_id, $sn_groups_fleet) && $ship_count) { |
|
44 | 44 | $ship_info = get_unit_param($ship_id); |
45 | - if($ship_count > mrc_get_level($user, $planetrow, $ship_id, false, true)) { |
|
45 | + if ($ship_count > mrc_get_level($user, $planetrow, $ship_id, false, true)) { |
|
46 | 46 | $page .= $lang['fl_noenought']; |
47 | 47 | } else { |
48 | 48 | $fleet['fleetarray'][$ship_id] = $ship_count; |
@@ -61,13 +61,13 @@ discard block |
||
61 | 61 | } |
62 | 62 | } |
63 | 63 | |
64 | -if(empty($fleet['fleetarray'])) { |
|
64 | +if (empty($fleet['fleetarray'])) { |
|
65 | 65 | message($lang['fl_err_no_ships'], $lang['fl_error'], 'fleet' . DOT_PHP_EX, 5); |
66 | 66 | } |
67 | 67 | |
68 | 68 | // Building list of shortcuts |
69 | 69 | $query = doquery("SELECT * FROM {{notes}} WHERE `owner` = {$user['id']} AND `galaxy` <> 0 AND `system` <> 0 AND `planet` <> 0 ORDER BY `priority` DESC, `galaxy`, `system`, `planet`, `planet_type`;"); |
70 | -while($shortcut = db_fetch($query)) { |
|
70 | +while ($shortcut = db_fetch($query)) { |
|
71 | 71 | $template->assign_block_vars('shortcut', array( |
72 | 72 | 'NAME' => $shortcut['title'], |
73 | 73 | 'GALAXY' => $shortcut['galaxy'], |
@@ -81,10 +81,10 @@ discard block |
||
81 | 81 | } |
82 | 82 | |
83 | 83 | // Building list of own planets & moons |
84 | -$colonies = db_planet_list_sorted ( $user ); |
|
85 | -if(count($colonies) > 1) { |
|
84 | +$colonies = db_planet_list_sorted($user); |
|
85 | +if (count($colonies) > 1) { |
|
86 | 86 | // while($row = db_fetch($colonies)) |
87 | - foreach($colonies as $row) { |
|
87 | + foreach ($colonies as $row) { |
|
88 | 88 | $template->assign_block_vars('colonies', array( |
89 | 89 | 'NAME' => $row['name'], |
90 | 90 | 'GALAXY' => $row['galaxy'], |
@@ -99,9 +99,9 @@ discard block |
||
99 | 99 | //ACS Start |
100 | 100 | //Need to look for acs attacks. |
101 | 101 | $aks_madnessred = doquery('SELECT * FROM {{aks}};'); |
102 | -while($row = db_fetch($aks_madnessred)) { |
|
102 | +while ($row = db_fetch($aks_madnessred)) { |
|
103 | 103 | $members = explode(',', $row['eingeladen']); |
104 | - foreach($members as $a => $b) { |
|
104 | + foreach ($members as $a => $b) { |
|
105 | 105 | if ($b == $user['id']) { |
106 | 106 | $template->assign_block_vars('acss', array( |
107 | 107 | 'ID' => $row['id'], |
@@ -27,9 +27,9 @@ discard block |
||
27 | 27 | print($round); |
28 | 28 | print('<table border=1>'); |
29 | 29 | print('<tr align="left">'); |
30 | - foreach($header as $key => $value) |
|
30 | + foreach ($header as $key => $value) |
|
31 | 31 | { |
32 | - if(is_array($value)) |
|
32 | + if (is_array($value)) |
|
33 | 33 | { |
34 | 34 | continue; |
35 | 35 | } |
@@ -61,9 +61,9 @@ discard block |
||
61 | 61 | ); |
62 | 62 | |
63 | 63 | print('<tr align="right">'); |
64 | - foreach($debug_unit_crossfire_result as $key => $value) |
|
64 | + foreach ($debug_unit_crossfire_result as $key => $value) |
|
65 | 65 | { |
66 | - if(is_array($value)) |
|
66 | + if (is_array($value)) |
|
67 | 67 | { |
68 | 68 | continue; |
69 | 69 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | 'START_NAME' => $planetrow['name'], |
28 | 28 | ); |
29 | 29 | |
30 | - if(!empty($TargetPlanet)) { |
|
30 | + if (!empty($TargetPlanet)) { |
|
31 | 31 | $template_route += array( |
32 | 32 | 'END_TYPE_TEXT_SH' => $lang['sys_planet_type_sh'][$TargetPlanet['planet_type']], |
33 | 33 | 'END_COORDS' => uni_render_coordinates($TargetPlanet), |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | $template->assign_block_vars('fleets', $template_route); |
39 | 39 | |
40 | 40 | $sn_groups_fleet = sn_get_groups('fleet'); |
41 | - foreach($fleetarray as $ship_id => $ship_count) { |
|
42 | - if(in_array($ship_id, $sn_groups_fleet) && $ship_count) { |
|
41 | + foreach ($fleetarray as $ship_id => $ship_count) { |
|
42 | + if (in_array($ship_id, $sn_groups_fleet) && $ship_count) { |
|
43 | 43 | // $ship_base_data = get_ship_data($ship_id, $user); |
44 | 44 | $template->assign_block_vars('fleets.ships', array( |
45 | 45 | 'ID' => $ship_id, |
@@ -57,11 +57,10 @@ discard block |
||
57 | 57 | $fleet_capacity += get_unit_param($Ship, P_CAPACITY) * $Count; |
58 | 58 | } |
59 | 59 | |
60 | - $max_duration = $target_mission == MT_EXPLORE ? get_player_max_expedition_duration($user) : |
|
61 | - (isset($missiontype[MT_HOLD]) ? 12 : 0); |
|
62 | - if($max_duration) { |
|
60 | + $max_duration = $target_mission == MT_EXPLORE ? get_player_max_expedition_duration($user) : (isset($missiontype[MT_HOLD]) ? 12 : 0); |
|
61 | + if ($max_duration) { |
|
63 | 62 | $config_game_speed_expedition = ($target_mission == MT_EXPLORE && $config->game_speed_expedition ? $config->game_speed_expedition : 1); |
64 | - for($i = 1; $i <= $max_duration; $i++) { |
|
63 | + for ($i = 1; $i <= $max_duration; $i++) { |
|
65 | 64 | $template->assign_block_vars('duration', array( |
66 | 65 | 'ID' => $i, |
67 | 66 | 'TIME' => pretty_time(ceil($i * 3600 / $config_game_speed_expedition)), |
@@ -80,7 +79,7 @@ discard block |
||
80 | 79 | // $TableTitle = uni_render_planet_full($planetrow) . ' => ' . uni_render_planet_full($temp); |
81 | 80 | |
82 | 81 | $sn_group_resources = sn_get_groups('resources'); |
83 | - for($i = 0; $i<3; $i++) { |
|
82 | + for ($i = 0; $i < 3; $i++) { |
|
84 | 83 | $amount = $planetrow[$sn_group_resources[$i]] - ($i == 2 ? $consumption : 0); |
85 | 84 | $template->assign_block_vars('resources', array( |
86 | 85 | 'ID' => $i, |
@@ -90,7 +89,7 @@ discard block |
||
90 | 89 | )); |
91 | 90 | } |
92 | 91 | |
93 | - if($sn_module['unit_captain']->manifest['active'] && ($captain = $sn_module['unit_captain']->unit_captain_get($planetrow['id'])) && $captain['unit_location_type'] == LOC_PLANET) { |
|
92 | + if ($sn_module['unit_captain']->manifest['active'] && ($captain = $sn_module['unit_captain']->unit_captain_get($planetrow['id'])) && $captain['unit_location_type'] == LOC_PLANET) { |
|
94 | 93 | $template->assign_vars(array( |
95 | 94 | 'CAPTAIN_ID' => $captain['unit_id'], |
96 | 95 | 'CAPTAIN_LEVEL' => $captain['captain_level'], |
@@ -111,9 +110,9 @@ discard block |
||
111 | 110 | // 'TableTitle' => $TableTitle, |
112 | 111 | |
113 | 112 | 'speedallsmin' => sys_get_param_float('speedallsmin'), |
114 | - 'speed' => sys_get_param_int('speed') , |
|
113 | + 'speed' => sys_get_param_int('speed'), |
|
115 | 114 | |
116 | - 'fleet_group' => sys_get_param_id('fleet_group') , |
|
115 | + 'fleet_group' => sys_get_param_id('fleet_group'), |
|
117 | 116 | 'acs_target_mr' => sys_get_param_str('acs_target_mr'), |
118 | 117 | |
119 | 118 | 'MAX_DURATION' => $max_duration, |
@@ -18,10 +18,10 @@ discard block |
||
18 | 18 | function sn_eco_build($que_type, &$auser, &$planet) { |
19 | 19 | global $lang, $config, $template_result; |
20 | 20 | |
21 | - if($ally_id = sys_get_param_id('ally_id')) { |
|
21 | + if ($ally_id = sys_get_param_id('ally_id')) { |
|
22 | 22 | define('SN_IN_ALLY', true); |
23 | 23 | $ranks = ally_get_ranks($auser['ally']); |
24 | - if($ranks[$auser['ally_rank_id']]['admin'] || $auser['ally']['ally_owner'] == $auser['id']) { |
|
24 | + if ($ranks[$auser['ally_rank_id']]['admin'] || $auser['ally']['ally_owner'] == $auser['id']) { |
|
25 | 25 | $user = &$auser['ally']['player']; |
26 | 26 | $planet = array( |
27 | 27 | 'metal' => $user['metal'], |
@@ -31,11 +31,11 @@ discard block |
||
31 | 31 | } |
32 | 32 | } |
33 | 33 | |
34 | - if(!$user) { |
|
34 | + if (!$user) { |
|
35 | 35 | $user = &$auser; |
36 | 36 | } |
37 | 37 | |
38 | - switch($action = sys_get_param_escaped('action')) { |
|
38 | + switch ($action = sys_get_param_escaped('action')) { |
|
39 | 39 | case 'create': // Add unit to que for build |
40 | 40 | case 'create_autoconvert': // Add unit to que for build |
41 | 41 | case 'destroy': // Add unit to que for remove |
@@ -52,23 +52,23 @@ discard block |
||
52 | 52 | |
53 | 53 | $group_missile = sn_get_groups('missile'); |
54 | 54 | $silo_capacity_free = 0; |
55 | - if($que_type == QUE_STRUCTURES) { |
|
55 | + if ($que_type == QUE_STRUCTURES) { |
|
56 | 56 | $build_unit_list = sn_get_groups('build_allow'); |
57 | 57 | $build_unit_list = $build_unit_list[$planet['planet_type']]; |
58 | 58 | $artifact_id = ART_NANO_BUILDER; |
59 | 59 | $page_header = $lang['tech'][UNIT_STRUCTURES]; |
60 | - } elseif($que_type == QUE_RESEARCH) { |
|
61 | - if(!mrc_get_level($user, $planet, STRUC_LABORATORY)) { |
|
60 | + } elseif ($que_type == QUE_RESEARCH) { |
|
61 | + if (!mrc_get_level($user, $planet, STRUC_LABORATORY)) { |
|
62 | 62 | message($lang['no_laboratory'], $lang['tech'][UNIT_TECHNOLOGIES]); |
63 | 63 | } |
64 | 64 | |
65 | - if(eco_unit_busy($user, $planet, UNIT_TECHNOLOGIES)) { |
|
65 | + if (eco_unit_busy($user, $planet, UNIT_TECHNOLOGIES)) { |
|
66 | 66 | message($lang['eco_bld_msg_err_laboratory_upgrading'], $lang['tech'][UNIT_TECHNOLOGIES]); |
67 | 67 | } |
68 | 68 | $build_unit_list = sn_get_groups('tech'); |
69 | 69 | $artifact_id = ART_HEURISTIC_CHIP; |
70 | 70 | $page_header = $lang['tech'][UNIT_TECHNOLOGIES] . ($user['user_as_ally'] ? " {$lang['sys_of_ally']} {$user['username']}" : ''); |
71 | - } elseif($que_type == QUE_MERCENARY) { |
|
71 | + } elseif ($que_type == QUE_MERCENARY) { |
|
72 | 72 | // if(!mrc_get_level($user, $planet, STRUC_LABORATORY)) { |
73 | 73 | // message($lang['no_laboratory'], $lang['tech'][UNIT_TECHNOLOGIES]); |
74 | 74 | // } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | $artifact_id = 0; |
81 | 81 | $page_header = $lang['tech'][UNIT_MERCENARIES] . ($user['user_as_ally'] ? " {$lang['sys_of_ally']} {$user['username']}" : ''); |
82 | 82 | } else { |
83 | - if(mrc_get_level($user, $planet, STRUC_FACTORY_HANGAR) == 0) { |
|
83 | + if (mrc_get_level($user, $planet, STRUC_FACTORY_HANGAR) == 0) { |
|
84 | 84 | message($lang['need_hangar'], $lang['tech'][STRUC_FACTORY_HANGAR]); |
85 | 85 | } |
86 | 86 | |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | $artifact_id = 0; |
90 | 90 | |
91 | 91 | $silo_capacity_free = mrc_get_level($user, $planet, STRUC_SILO) * get_unit_param(STRUC_SILO, P_CAPACITY); |
92 | - foreach($group_missile as $unit_id) { |
|
92 | + foreach ($group_missile as $unit_id) { |
|
93 | 93 | $silo_capacity_free -= (mrc_get_level($user, $planet, $unit_id, false, true) + (isset($in_que[$unit_id]) && $in_que[$unit_id] ? $in_que[$unit_id] : 0)) * get_unit_param($unit_id, P_UNIT_SIZE); |
94 | 94 | } |
95 | 95 | $silo_capacity_free = max(0, $silo_capacity_free); |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | */ |
107 | 107 | |
108 | 108 | $template = gettemplate('buildings_builds', true); |
109 | - if(!empty($operation_result)) { |
|
109 | + if (!empty($operation_result)) { |
|
110 | 110 | $template_result['.']['result'][] = $operation_result; |
111 | 111 | } |
112 | 112 | |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | |
137 | 137 | $record_index = 0; |
138 | 138 | |
139 | - foreach($build_unit_list as $unit_id) { |
|
139 | + foreach ($build_unit_list as $unit_id) { |
|
140 | 140 | $level_base = mrc_get_level($user, $planet, $unit_id, false, true); |
141 | 141 | $level_effective = mrc_get_level($user, $planet, $unit_id); |
142 | 142 | $level_in_que = $in_que[$unit_id]; |
@@ -159,12 +159,12 @@ discard block |
||
159 | 159 | $can_build = $unit_info[P_MAX_STACK] ? max(0, $unit_info[P_MAX_STACK] - $level_in_que - $level_effective) : $build_data['CAN'][BUILD_CREATE]; |
160 | 160 | // Restricting $can_build by free silo capacity |
161 | 161 | $can_build = ($unit_is_missile = in_array($unit_id, $group_missile)) ? min($can_build, floor($silo_capacity_free / $unit_info[P_UNIT_SIZE])) : $can_build; |
162 | - if(!$can_build) { |
|
163 | - if(!$build_data['CAN'][BUILD_CREATE]) { |
|
162 | + if (!$can_build) { |
|
163 | + if (!$build_data['CAN'][BUILD_CREATE]) { |
|
164 | 164 | $build_data['RESULT'][BUILD_CREATE] = BUILD_NO_RESOURCES; |
165 | - } elseif($unit_is_missile && $silo_capacity_free < $unit_info[P_UNIT_SIZE]) { |
|
165 | + } elseif ($unit_is_missile && $silo_capacity_free < $unit_info[P_UNIT_SIZE]) { |
|
166 | 166 | $build_data['RESULT'][BUILD_CREATE] = BUILD_SILO_FULL; |
167 | - } elseif($unit_info[P_MAX_STACK]) { |
|
167 | + } elseif ($unit_info[P_MAX_STACK]) { |
|
168 | 168 | $build_data['RESULT'][BUILD_CREATE] = BUILD_MAX_REACHED; |
169 | 169 | } |
170 | 170 | } |
@@ -231,14 +231,14 @@ discard block |
||
231 | 231 | 'MAP_IS_RESOURCE' => !empty($unit_info[P_UNIT_PRODUCTION]), |
232 | 232 | ); |
233 | 233 | |
234 | - if($unit_stackable) { |
|
234 | + if ($unit_stackable) { |
|
235 | 235 | $level_production_base = array( |
236 | 236 | 'ACTUAL_SHIELD' => pretty_number(mrc_modify_value($user, false, array(MRC_ADMIRAL, TECH_SHIELD), $unit_info['shield'])), |
237 | 237 | 'ACTUAL_ARMOR' => pretty_number(mrc_modify_value($user, false, array(MRC_ADMIRAL, TECH_ARMOR), $unit_info['armor'])), |
238 | 238 | 'ACTUAL_WEAPON' => pretty_number(mrc_modify_value($user, false, array(MRC_ADMIRAL, TECH_WEAPON), $unit_info['attack'])), |
239 | 239 | ); |
240 | 240 | |
241 | - if($unit_info[P_UNIT_TYPE] == UNIT_SHIPS) { |
|
241 | + if ($unit_info[P_UNIT_TYPE] == UNIT_SHIPS) { |
|
242 | 242 | $ship_data = get_ship_data($unit_id, $user); |
243 | 243 | |
244 | 244 | $level_production_base += array( |
@@ -248,9 +248,9 @@ discard block |
||
248 | 248 | ); |
249 | 249 | } |
250 | 250 | |
251 | - if($unit_info[P_UNIT_PRODUCTION]) { |
|
252 | - foreach($unit_info[P_UNIT_PRODUCTION] as $resource_id => $resource_calc) { |
|
253 | - if($resource_income = |
|
251 | + if ($unit_info[P_UNIT_PRODUCTION]) { |
|
252 | + foreach ($unit_info[P_UNIT_PRODUCTION] as $resource_id => $resource_calc) { |
|
253 | + if ($resource_income = |
|
254 | 254 | floor(mrc_modify_value($user, $planet, $sn_modifiers_resource, $resource_calc(1, 10, $user, $planet) |
255 | 255 | * ($resource_id == RES_ENERGY ? $config_resource_multiplier_plain : $config_resource_multiplier) |
256 | 256 | * (isset($density_info[$resource_id]) ? $density_info[$resource_id] : 1))) |
@@ -260,11 +260,11 @@ discard block |
||
260 | 260 | } |
261 | 261 | } |
262 | 262 | $production['.']['resource'][] = $level_production_base; |
263 | - } elseif($unit_info[P_UNIT_PRODUCTION]) { |
|
263 | + } elseif ($unit_info[P_UNIT_PRODUCTION]) { |
|
264 | 264 | $level_production_base = array(); |
265 | 265 | $element_level_start = $level_effective + $in_que[$unit_id]; |
266 | - foreach($unit_info[P_UNIT_PRODUCTION] as $resource_id => $resource_calc) { |
|
267 | - if($resource_income = |
|
266 | + foreach ($unit_info[P_UNIT_PRODUCTION] as $resource_id => $resource_calc) { |
|
267 | + if ($resource_income = |
|
268 | 268 | floor(mrc_modify_value($user, $planet, $sn_modifiers_resource, $resource_calc($element_level_start, 10, $user, $planet) |
269 | 269 | * ($resource_id == RES_ENERGY ? $config_resource_multiplier_plain : $config_resource_multiplier) |
270 | 270 | * (isset($density_info[$resource_id]) ? $density_info[$resource_id] : 1))) |
@@ -274,10 +274,10 @@ discard block |
||
274 | 274 | } |
275 | 275 | |
276 | 276 | $level_start = $level_base_and_que > 1 ? $level_effective + $level_in_que - 1 : 1; |
277 | - for($i = 0; $i < 6; $i++) { |
|
277 | + for ($i = 0; $i < 6; $i++) { |
|
278 | 278 | $level_production = array('LEVEL' => $level_start + $i); |
279 | - foreach($unit_info[P_UNIT_PRODUCTION] as $resource_id => $resource_calc) { |
|
280 | - if( |
|
279 | + foreach ($unit_info[P_UNIT_PRODUCTION] as $resource_id => $resource_calc) { |
|
280 | + if ( |
|
281 | 281 | $resource_income = floor(mrc_modify_value($user, $planet, $sn_modifiers_resource, $resource_calc($level_start + $i, 10, $user, $planet) |
282 | 282 | * ($resource_id == RES_ENERGY ? $config_resource_multiplier_plain : $config_resource_multiplier) |
283 | 283 | * (isset($density_info[$resource_id]) ? $density_info[$resource_id] : 1))) |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | } |
289 | 289 | $production['.']['resource'][] = $level_production; |
290 | 290 | } |
291 | - } elseif($unit_id == TECH_ASTROTECH) { |
|
291 | + } elseif ($unit_id == TECH_ASTROTECH) { |
|
292 | 292 | $element_level_start = $level_effective + $in_que[$unit_id]; |
293 | 293 | $level_production_base = array( |
294 | 294 | UNIT_PLAYER_EXPEDITIONS_MAX => get_player_max_expeditons($user, $element_level_start), |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | ); |
297 | 297 | |
298 | 298 | $level_start = $level_base_and_que > 1 ? $level_effective + $level_in_que - 1 : 1; |
299 | - for($i = 0; $i < 6; $i++) { |
|
299 | + for ($i = 0; $i < 6; $i++) { |
|
300 | 300 | $level_production = array('LEVEL' => $level_start + $i); |
301 | 301 | $level_production['R' . UNIT_PLAYER_EXPEDITIONS_MAX] = get_player_max_expeditons($user, $level_start + $i); |
302 | 302 | $level_production['D' . UNIT_PLAYER_EXPEDITIONS_MAX] = $level_production['R' . UNIT_PLAYER_EXPEDITIONS_MAX] - $level_production_base[UNIT_PLAYER_EXPEDITIONS_MAX]; |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | $template_result['.']['production'][] = $production; |
318 | 318 | } |
319 | 319 | |
320 | - foreach($lang['player_option_building_sort'] as $sort_id => $sort_text) { |
|
320 | + foreach ($lang['player_option_building_sort'] as $sort_id => $sort_text) { |
|
321 | 321 | $template->assign_block_vars('sort_values', array( |
322 | 322 | 'VALUE' => $sort_id, |
323 | 323 | 'TEXT' => $sort_text, |
@@ -326,8 +326,8 @@ discard block |
||
326 | 326 | |
327 | 327 | $sort_option = classSupernova::$user_options[array(PLAYER_OPTION_BUILDING_SORT, $que_type)]; |
328 | 328 | $sort_option_inverse = classSupernova::$user_options[array(PLAYER_OPTION_BUILDING_SORT_INVERSE, $que_type)]; |
329 | - if($sort_option || $sort_option_inverse != PLAYER_OPTION_SORT_ORDER_PLAIN) { |
|
330 | - switch($sort_option) { |
|
329 | + if ($sort_option || $sort_option_inverse != PLAYER_OPTION_SORT_ORDER_PLAIN) { |
|
330 | + switch ($sort_option) { |
|
331 | 331 | case PLAYER_OPTION_SORT_NAME: |
332 | 332 | $sort_option_field = 'NAME'; |
333 | 333 | break; |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | break; |
343 | 343 | } |
344 | 344 | $sort_option_inverse_closure = $sort_option_inverse ? -1 : 1; |
345 | - usort($template_result['.']['production'], function ($a, $b) use ($sort_option_field, $sort_option_inverse_closure) { |
|
345 | + usort($template_result['.']['production'], function($a, $b) use ($sort_option_field, $sort_option_inverse_closure) { |
|
346 | 346 | return $a[$sort_option_field] < $b[$sort_option_field] ? -1 * $sort_option_inverse_closure : ( |
347 | 347 | $a[$sort_option_field] > $b[$sort_option_field] ? 1 * $sort_option_inverse_closure : 0 |
348 | 348 | ); |
@@ -9,28 +9,28 @@ discard block |
||
9 | 9 | $avatar_filename = $fullsize_filename = SN_ROOT_PHYSICAL . 'images/avatar/' . $prefix . '_' . $subject_id; |
10 | 10 | $avatar_filename .= '.png'; |
11 | 11 | $fullsize_filename .= '_full.png'; |
12 | - if(sys_get_param_int('avatar_remove')) |
|
12 | + if (sys_get_param_int('avatar_remove')) |
|
13 | 13 | { |
14 | - if(file_exists($avatar_filename) && !unlink($avatar_filename)) |
|
14 | + if (file_exists($avatar_filename) && !unlink($avatar_filename)) |
|
15 | 15 | { |
16 | 16 | throw new Exception($lang['opt_msg_avatar_error_delete'], ERR_ERROR); |
17 | 17 | } |
18 | 18 | $avatar_field = 0; |
19 | 19 | throw new Exception($lang['opt_msg_avatar_removed'], ERR_NONE); |
20 | 20 | } |
21 | - elseif($_FILES['avatar']['size']) |
|
21 | + elseif ($_FILES['avatar']['size']) |
|
22 | 22 | { |
23 | - if(!in_array($_FILES['avatar']['type'], array('image/gif', 'image/jpeg', 'image/jpg', 'image/pjpeg', 'image/png')) || $_FILES['avatar']['size'] > 204800) |
|
23 | + if (!in_array($_FILES['avatar']['type'], array('image/gif', 'image/jpeg', 'image/jpg', 'image/pjpeg', 'image/png')) || $_FILES['avatar']['size'] > 204800) |
|
24 | 24 | { |
25 | 25 | throw new Exception($lang['opt_msg_avatar_error_unsupported'], ERR_WARNING); |
26 | 26 | } |
27 | 27 | |
28 | - if($_FILES['avatar']['error']) |
|
28 | + if ($_FILES['avatar']['error']) |
|
29 | 29 | { |
30 | 30 | throw new Exception(sprintf($lang['opt_msg_avatar_error_upload'], $_FILES['avatar']['error']), ERR_ERROR); |
31 | 31 | } |
32 | 32 | |
33 | - if(!($avatar_image = imagecreatefromstring(file_get_contents($_FILES['avatar']['tmp_name'])))) |
|
33 | + if (!($avatar_image = imagecreatefromstring(file_get_contents($_FILES['avatar']['tmp_name'])))) |
|
34 | 34 | { |
35 | 35 | throw new Exception($lang['opt_msg_avatar_error_unsupported'], ERR_WARNING); |
36 | 36 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | $avatar_size = getimagesize($_FILES['avatar']['tmp_name']); |
39 | 39 | $avatar_max_width = $config-> avatar_max_width; |
40 | 40 | $avatar_max_height = $config-> avatar_max_height; |
41 | - if($avatar_size[0] > $avatar_max_width || $avatar_size[1] > $avatar_max_height) |
|
41 | + if ($avatar_size[0] > $avatar_max_width || $avatar_size[1] > $avatar_max_height) |
|
42 | 42 | { |
43 | 43 | $aspect_ratio = min($avatar_max_width / $avatar_size[0], $avatar_max_height / $avatar_size[1]); |
44 | 44 | $avatar_image_new = imagecreatetruecolor($avatar_size[0] * $aspect_ratio, $avatar_size[0] * $aspect_ratio); |
@@ -47,12 +47,12 @@ discard block |
||
47 | 47 | $avatar_image = $avatar_image_new; |
48 | 48 | } |
49 | 49 | |
50 | - if(file_exists($avatar_filename) && !unlink($avatar_filename)) |
|
50 | + if (file_exists($avatar_filename) && !unlink($avatar_filename)) |
|
51 | 51 | { |
52 | 52 | throw new Exception($lang['opt_msg_avatar_error_delete'], ERR_ERROR); |
53 | 53 | } |
54 | 54 | |
55 | - if(!imagepng($avatar_image, $avatar_filename, 9)) |
|
55 | + if (!imagepng($avatar_image, $avatar_filename, 9)) |
|
56 | 56 | { |
57 | 57 | throw new Exception($lang['opt_msg_avatar_error_writing'], ERR_ERROR); |
58 | 58 | } |
@@ -17,8 +17,7 @@ discard block |
||
17 | 17 | } |
18 | 18 | $avatar_field = 0; |
19 | 19 | throw new Exception($lang['opt_msg_avatar_removed'], ERR_NONE); |
20 | - } |
|
21 | - elseif($_FILES['avatar']['size']) |
|
20 | + } elseif($_FILES['avatar']['size']) |
|
22 | 21 | { |
23 | 22 | if(!in_array($_FILES['avatar']['type'], array('image/gif', 'image/jpeg', 'image/jpg', 'image/pjpeg', 'image/png')) || $_FILES['avatar']['size'] > 204800) |
24 | 23 | { |
@@ -61,8 +60,7 @@ discard block |
||
61 | 60 | imagedestroy($avatar_image); |
62 | 61 | throw new Exception($lang['opt_msg_avatar_uploaded'], ERR_NONE); |
63 | 62 | } |
64 | - } |
|
65 | - catch (Exception $e) |
|
63 | + } catch (Exception $e) |
|
66 | 64 | { |
67 | 65 | return array( |
68 | 66 | 'STATUS' => in_array($e->getCode(), array(ERR_NONE, ERR_WARNING, ERR_ERROR)) ? $e->getCode() : ERR_ERROR, |
@@ -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 $config, $sys_stop_log_hit, $is_watching; |
169 | 169 | |
170 | - if($sys_stop_log_hit || !$config->game_counter) { |
|
170 | + if ($sys_stop_log_hit || !$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; |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | !is_array($offset) ? $offset = array($offset) : false; |
39 | 39 | |
40 | 40 | $current_leaf = $this->__get(reset($offset)); |
41 | - while(($leaf_index = next($offset)) !== false) { |
|
42 | - if(!isset($current_leaf) || !is_array($current_leaf) || !isset($current_leaf[$leaf_index])) { |
|
41 | + while (($leaf_index = next($offset)) !== false) { |
|
42 | + if (!isset($current_leaf) || !is_array($current_leaf) || !isset($current_leaf[$leaf_index])) { |
|
43 | 43 | unset($current_leaf); |
44 | 44 | break; |
45 | 45 | } |
@@ -64,9 +64,9 @@ discard block |
||
64 | 64 | |
65 | 65 | !is_array($offset) ? $offset = array($offset) : false; |
66 | 66 | |
67 | - if($this->offsetExists($offset)) { |
|
67 | + if ($this->offsetExists($offset)) { |
|
68 | 68 | $result = $this->__get(reset($offset)); |
69 | - while(($leaf_index = next($offset)) !== false) { |
|
69 | + while (($leaf_index = next($offset)) !== false) { |
|
70 | 70 | $result = $result[$leaf_index]; |
71 | 71 | } |
72 | 72 | } |
@@ -91,12 +91,12 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function offsetSet($offset, $value = null) { |
93 | 93 | // Если нет никакого индекса - значит нечего записывать |
94 | - if(!isset($offset) || (is_array($offset) && empty($offset))) { |
|
94 | + if (!isset($offset) || (is_array($offset) && empty($offset))) { |
|
95 | 95 | return; |
96 | 96 | } |
97 | 97 | |
98 | 98 | // Если в массиве индекса только один элемент - значит это просто индекс |
99 | - if(is_array($offset) && count($offset) == 1) { |
|
99 | + if (is_array($offset) && count($offset) == 1) { |
|
100 | 100 | // Разворачиваем его в индекс |
101 | 101 | $offset = array(reset($offset) => $value); |
102 | 102 | unset($value); |
@@ -104,20 +104,20 @@ discard block |
||
104 | 104 | } |
105 | 105 | |
106 | 106 | // Адресация многомерного массива через массив индексов в $option |
107 | - if(is_array($offset) && isset($value)) { |
|
107 | + if (is_array($offset) && isset($value)) { |
|
108 | 108 | // TODO - а не переделать ли это всё на __isset() ?? |
109 | 109 | //pdump($offset, '$offset'); |
110 | 110 | //pdump($value, '$value'); |
111 | 111 | // Вытаскиваем корневой элемент |
112 | 112 | $root = $this->__get(reset($offset)); |
113 | 113 | $current_leaf = &$root; |
114 | - while(($leaf_index = next($offset)) !== false) { |
|
114 | + while (($leaf_index = next($offset)) !== false) { |
|
115 | 115 | !is_array($current_leaf[$leaf_index]) ? $current_leaf[$leaf_index] = array() : false; |
116 | 116 | $current_leaf = &$current_leaf[$leaf_index]; |
117 | 117 | } |
118 | 118 | //pdump($current_leaf, '$current_leaf'); |
119 | 119 | //pdump($value, '$value'); |
120 | - if($current_leaf != $value) { |
|
120 | + if ($current_leaf != $value) { |
|
121 | 121 | $current_leaf = $value; |
122 | 122 | //pdump(reset($offset), 'reset($offset)'); |
123 | 123 | //pdump($root, '$root'); |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | // Пакетная запись из массива ключ -> значение |
129 | 129 | !is_array($offset) ? $offset = array($offset => $value) : false; |
130 | 130 | |
131 | - foreach($offset as $key => $value) { |
|
131 | + foreach ($offset as $key => $value) { |
|
132 | 132 | $this->__get($key) !== $value ? $this->__set($key, $value) : false; |
133 | 133 | } |
134 | 134 | } |
@@ -149,13 +149,13 @@ discard block |
||
149 | 149 | */ |
150 | 150 | public function offsetUnset($offset) { |
151 | 151 | // Если нет никакого индекса - значит нечего записывать |
152 | - if(!isset($offset) || (is_array($offset) && empty($offset))) { |
|
152 | + if (!isset($offset) || (is_array($offset) && empty($offset))) { |
|
153 | 153 | return; |
154 | 154 | } |
155 | 155 | |
156 | 156 | !is_array($offset) ? $offset = array($offset) : false; |
157 | 157 | |
158 | - if($this->offsetExists($offset)) { |
|
158 | + if ($this->offsetExists($offset)) { |
|
159 | 159 | //pdump($offset); |
160 | 160 | // Перематываем массив в конец |
161 | 161 | $key_to_delete = end($offset); |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | //pdump($key_to_delete, '$key_to_delete'); |
164 | 164 | $parent_offset = $offset; |
165 | 165 | array_pop($parent_offset); |
166 | - if(!count($parent_offset)) { |
|
166 | + if (!count($parent_offset)) { |
|
167 | 167 | // В массиве был один элемент - мы удаляем в корне. Просто удаляем элемент |
168 | 168 | $this->__unset($key_to_delete); |
169 | 169 | } else { |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | protected static $is_init = false; |
20 | 20 | |
21 | 21 | protected static function init() { |
22 | - if(!empty(static::$db)) { |
|
22 | + if (!empty(static::$db)) { |
|
23 | 23 | return; |
24 | 24 | } |
25 | 25 | static::$db = classSupernova::$db; |
@@ -66,12 +66,12 @@ discard block |
||
66 | 66 | $provider_id_safe = intval($provider_id_unsafe); |
67 | 67 | !is_array($account_list) ? $account_list = array($account_list) : false; |
68 | 68 | |
69 | - foreach($account_list as $provider_account_id_unsafe) { |
|
69 | + foreach ($account_list as $provider_account_id_unsafe) { |
|
70 | 70 | $provider_account_id_safe = intval($provider_account_id_unsafe); |
71 | 71 | |
72 | 72 | // TODO - Здесь могут отсутствовать аккаунты - проверять провайдером |
73 | 73 | $query = static::$db->doquery("SELECT `user_id` FROM {{account_translate}} WHERE `provider_id` = {$provider_id_safe} AND `provider_account_id` = {$provider_account_id_safe} FOR UPDATE"); |
74 | - while($row = static::$db->db_fetch($query)) { |
|
74 | + while ($row = static::$db->db_fetch($query)) { |
|
75 | 75 | $account_translation[$row['user_id']][$provider_id_unsafe][$provider_account_id_unsafe] = true; |
76 | 76 | } |
77 | 77 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | "SELECT * FROM {{account_translate}} WHERE `user_id` = {$user_id_safe} " . |
92 | 92 | ($provider_id_unsafe ? "AND `provider_id` = {$provider_id_safe} " : '') . |
93 | 93 | "ORDER BY `timestamp` FOR UPDATE"); |
94 | - while($row = static::$db->db_fetch($query)) { |
|
94 | + while ($row = static::$db->db_fetch($query)) { |
|
95 | 95 | $account_translation[$row['user_id']][$row['provider_id']][$row['provider_account_id']] = $row; |
96 | 96 | } |
97 | 97 |
@@ -202,14 +202,18 @@ discard block |
||
202 | 202 | // Перепаковывает массив на заданную глубину, убирая поля с null |
203 | 203 | public static function array_repack(&$array, $level = 0) { |
204 | 204 | // TODO $lock_table не нужна тут |
205 | - if(!is_array($array)) return; |
|
205 | + if(!is_array($array)) { |
|
206 | + return; |
|
207 | + } |
|
206 | 208 | |
207 | 209 | foreach($array as $key => &$value) { |
208 | 210 | if($value === null) { |
209 | 211 | unset($array[$key]); |
210 | 212 | } elseif($level > 0 && is_array($value)) { |
211 | 213 | static::array_repack($value, $level - 1); |
212 | - if(empty($value)) unset($array[$key]); |
|
214 | + if(empty($value)) { |
|
215 | + unset($array[$key]); |
|
216 | + } |
|
213 | 217 | } |
214 | 218 | } |
215 | 219 | } |
@@ -218,7 +222,9 @@ discard block |
||
218 | 222 | // TODO Вынести в отдельный объект |
219 | 223 | public static function cache_repack($location_type, $record_id = 0) { |
220 | 224 | // Если есть $user_id - проверяем, а надо ли перепаковывать? |
221 | - if($record_id && isset(static::$data[$location_type][$record_id]) && static::$data[$location_type][$record_id] !== null) return; |
|
225 | + if($record_id && isset(static::$data[$location_type][$record_id]) && static::$data[$location_type][$record_id] !== null) { |
|
226 | + return; |
|
227 | + } |
|
222 | 228 | |
223 | 229 | static::array_repack(static::$data[$location_type]); |
224 | 230 | static::array_repack(static::$locator[$location_type], 3); // TODO У каждого типа локации - своя глубина!!!! Но можно и глубже ??? |
@@ -263,7 +269,9 @@ discard block |
||
263 | 269 | */ |
264 | 270 | public static function cache_set($location_type, $record_id, $record, $force_overwrite = false, $skip_lock = false) { |
265 | 271 | // нет идентификатора - выход |
266 | - if(!($record_id = $record[static::$location_info[$location_type][P_ID]])) return; |
|
272 | + if(!($record_id = $record[static::$location_info[$location_type][P_ID]])) { |
|
273 | + return; |
|
274 | + } |
|
267 | 275 | |
268 | 276 | $in_transaction = static::db_transaction_check(false); |
269 | 277 | if( |
@@ -297,8 +305,9 @@ discard block |
||
297 | 305 | return static::$locks[$location_type][$record_id] = true; // Не всегда - от результата |
298 | 306 | } |
299 | 307 | public static function cache_lock_unset($location_type, $record_id) { |
300 | - if(isset(static::$locks[$location_type][$record_id])) |
|
301 | - unset(static::$locks[$location_type][$record_id]); |
|
308 | + if(isset(static::$locks[$location_type][$record_id])) { |
|
309 | + unset(static::$locks[$location_type][$record_id]); |
|
310 | + } |
|
302 | 311 | return true; // Не всегда - от результата |
303 | 312 | } |
304 | 313 | public static function cache_lock_unset_all() { |
@@ -471,8 +480,9 @@ discard block |
||
471 | 480 | //pdump($q, 'Запрос блокировки'); |
472 | 481 | while($row = db_fetch($query)) { |
473 | 482 | // Исключаем из списка родительских ИД уже заблокированные записи |
474 | - if(!static::cache_lock_get($owner_location_type, $row['parent_id'])) |
|
475 | - $parent_id_list[$row['parent_id']] = $row['parent_id']; |
|
483 | + if(!static::cache_lock_get($owner_location_type, $row['parent_id'])) { |
|
484 | + $parent_id_list[$row['parent_id']] = $row['parent_id']; |
|
485 | + } |
|
476 | 486 | } |
477 | 487 | //pdump($parent_id_list, 'Выбраны родители'); |
478 | 488 | // Если все-таки какие-то записи еще не заблокированы - вынимаем текущие версии из базы |
@@ -506,7 +516,9 @@ discard block |
||
506 | 516 | if(is_array($query_cache)) { |
507 | 517 | foreach($query_cache as $key => $value) { |
508 | 518 | $result[$key] = $value; |
509 | - if($fetch) break; |
|
519 | + if($fetch) { |
|
520 | + break; |
|
521 | + } |
|
510 | 522 | } |
511 | 523 | } |
512 | 524 | return $fetch ? (is_array($result) ? reset($result) : false) : $result; |
@@ -515,12 +527,15 @@ discard block |
||
515 | 527 | |
516 | 528 | public static function db_upd_record_by_id($location_type, $record_id, $set) { |
517 | 529 | //if(!($record_id = intval($record_id)) || !($set = trim($set))) return false; |
518 | - if(!($record_id = idval($record_id)) || !($set = trim($set))) return false; |
|
530 | + if(!($record_id = idval($record_id)) || !($set = trim($set))) { |
|
531 | + return false; |
|
532 | + } |
|
519 | 533 | |
520 | 534 | $location_info = &static::$location_info[$location_type]; |
521 | 535 | $id_field = $location_info[P_ID]; |
522 | 536 | $table_name = $location_info[P_TABLE_NAME]; |
523 | - if($result = static::db_query($q = "UPDATE {{{$table_name}}} SET {$set} WHERE `{$id_field}` = {$record_id}")) // TODO Как-то вернуть может быть LIMIT 1 ? |
|
537 | + if($result = static::db_query($q = "UPDATE {{{$table_name}}} SET {$set} WHERE `{$id_field}` = {$record_id}")) { |
|
538 | + // TODO Как-то вернуть может быть LIMIT 1 ? |
|
524 | 539 | { |
525 | 540 | if(static::$db->db_affected_rows()) { |
526 | 541 | // Обновляем данные только если ряд был затронут |
@@ -528,6 +543,7 @@ discard block |
||
528 | 543 | |
529 | 544 | // Тут именно так, а не cache_unset - что бы в кэшах автоматически обновилась запись. Будет нужно на будущее |
530 | 545 | static::$data[$location_type][$record_id] = null; |
546 | + } |
|
531 | 547 | // Вытаскиваем обновленную запись |
532 | 548 | static::db_get_record_by_id($location_type, $record_id); |
533 | 549 | static::cache_clear($location_type, false); // Мягкий сброс - только $queries |
@@ -537,7 +553,9 @@ discard block |
||
537 | 553 | return $result; |
538 | 554 | } |
539 | 555 | public static function db_upd_record_list($location_type, $condition, $set) { |
540 | - if(!($set = trim($set))) return false; |
|
556 | + if(!($set = trim($set))) { |
|
557 | + return false; |
|
558 | + } |
|
541 | 559 | |
542 | 560 | $condition = trim($condition); |
543 | 561 | $table_name = static::$location_info[$location_type][P_TABLE_NAME]; |
@@ -560,9 +578,11 @@ discard block |
||
560 | 578 | $set = trim($set); |
561 | 579 | $table_name = static::$location_info[$location_type][P_TABLE_NAME]; |
562 | 580 | if($result = static::db_query("INSERT INTO `{{{$table_name}}}` SET {$set}")) { |
563 | - if(static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
581 | + if(static::$db->db_affected_rows()) { |
|
582 | + // Обновляем данные только если ряд был затронут |
|
564 | 583 | { |
565 | 584 | $record_id = db_insert_id(); |
585 | + } |
|
566 | 586 | // Вытаскиваем запись целиком, потому что в $set могли быть "данные по умолчанию" |
567 | 587 | $result = static::db_get_record_by_id($location_type, $record_id); |
568 | 588 | // Очищаем второстепенные кэши - потому что вставленная запись могла повлиять на результаты запросов или локация или еще чего |
@@ -600,24 +620,30 @@ discard block |
||
600 | 620 | public static function db_del_record_by_id($location_type, $safe_record_id) |
601 | 621 | { |
602 | 622 | // if(!($safe_record_id = intval($safe_record_id))) return false; |
603 | - if(!($safe_record_id = idval($safe_record_id))) return false; |
|
623 | + if(!($safe_record_id = idval($safe_record_id))) { |
|
624 | + return false; |
|
625 | + } |
|
604 | 626 | |
605 | 627 | $location_info = &static::$location_info[$location_type]; |
606 | 628 | $id_field = $location_info[P_ID]; |
607 | 629 | $table_name = $location_info[P_TABLE_NAME]; |
608 | 630 | if($result = static::db_query("DELETE FROM `{{{$table_name}}}` WHERE `{$id_field}` = {$safe_record_id}")) |
609 | 631 | { |
610 | - if(static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
632 | + if(static::$db->db_affected_rows()) { |
|
633 | + // Обновляем данные только если ряд был затронут |
|
611 | 634 | { |
612 | 635 | static::cache_unset($location_type, $safe_record_id); |
613 | 636 | } |
637 | + } |
|
614 | 638 | } |
615 | 639 | |
616 | 640 | return $result; |
617 | 641 | } |
618 | 642 | public static function db_del_record_list($location_type, $condition) |
619 | 643 | { |
620 | - if(!($condition = trim($condition))) return false; |
|
644 | + if(!($condition = trim($condition))) { |
|
645 | + return false; |
|
646 | + } |
|
621 | 647 | |
622 | 648 | $location_info = &static::$location_info[$location_type]; |
623 | 649 | $table_name = $location_info[P_TABLE_NAME]; |
@@ -626,12 +652,14 @@ discard block |
||
626 | 652 | |
627 | 653 | if($result = static::db_query("DELETE FROM `{{{$table_name}}}` WHERE {$condition}")) |
628 | 654 | { |
629 | - if(static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
655 | + if(static::$db->db_affected_rows()) { |
|
656 | + // Обновляем данные только если ряд был затронут |
|
630 | 657 | { |
631 | 658 | // Обнуление кэша, потому что непонятно, что поменялось |
632 | 659 | // TODO - когда будет структурированный $condition можно будет делать только cache_unset по нужным записям |
633 | 660 | static::cache_clear($location_type); |
634 | 661 | } |
662 | + } |
|
635 | 663 | } |
636 | 664 | |
637 | 665 | return $result; |
@@ -673,11 +701,13 @@ discard block |
||
673 | 701 | public static function db_get_user_by_username($username_unsafe, $for_update = false, $fields = '*', $player = null, $like = false) |
674 | 702 | { |
675 | 703 | // TODO Проверить, кстати - а везде ли нужно выбирать юзеров или где-то все-таки ищутся Альянсы ? |
676 | - if(!($username_unsafe = trim($username_unsafe))) return false; |
|
704 | + if(!($username_unsafe = trim($username_unsafe))) { |
|
705 | + return false; |
|
706 | + } |
|
677 | 707 | |
678 | 708 | $user = null; |
679 | - if(is_array(static::$data[LOC_USER])) |
|
680 | - foreach(static::$data[LOC_USER] as $user_id => $user_data) |
|
709 | + if(is_array(static::$data[LOC_USER])) { |
|
710 | + foreach(static::$data[LOC_USER] as $user_id => $user_data) |
|
681 | 711 | { |
682 | 712 | if(is_array($user_data) && isset($user_data['username'])) |
683 | 713 | { |
@@ -687,6 +717,7 @@ discard block |
||
687 | 717 | { |
688 | 718 | // $user_as_ally = intval($user_data['user_as_ally']); |
689 | 719 | $user_as_ally = idval($user_data['user_as_ally']); |
720 | + } |
|
690 | 721 | if($player === null || ($player === true && !$user_as_ally) || ($player === false && $user_as_ally)) |
691 | 722 | { |
692 | 723 | $user = $user_data; |
@@ -714,7 +745,9 @@ discard block |
||
714 | 745 | } |
715 | 746 | // UNUSED |
716 | 747 | public static function db_get_user_by_email($email_unsafe, $use_both = false, $for_update = false, $fields = '*') { |
717 | - if(!($email_unsafe = strtolower(trim($email_unsafe)))) return false; |
|
748 | + if(!($email_unsafe = strtolower(trim($email_unsafe)))) { |
|
749 | + return false; |
|
750 | + } |
|
718 | 751 | |
719 | 752 | $user = null; |
720 | 753 | // TODO переделать на индексы |
@@ -794,7 +827,9 @@ discard block |
||
794 | 827 | public static function db_get_unit_list_by_location($user_id = 0, $location_type, $location_id) |
795 | 828 | { |
796 | 829 | //if(!($location_type = intval($location_type)) || !($location_id = intval($location_id))) return false; |
797 | - if(!($location_type = idval($location_type)) || !($location_id = idval($location_id))) return false; |
|
830 | + if(!($location_type = idval($location_type)) || !($location_id = idval($location_id))) { |
|
831 | + return false; |
|
832 | + } |
|
798 | 833 | |
799 | 834 | $query_cache = &static::$locator[LOC_UNIT][$location_type][$location_id]; |
800 | 835 | if(!isset($query_cache)) |
@@ -861,15 +896,18 @@ discard block |
||
861 | 896 | $query = array(); |
862 | 897 | |
863 | 898 | // if($user_id = intval($user_id)) |
864 | - if($user_id = idval($user_id)) |
|
865 | - $query[] = "`que_player_id` = {$user_id}"; |
|
899 | + if($user_id = idval($user_id)) { |
|
900 | + $query[] = "`que_player_id` = {$user_id}"; |
|
901 | + } |
|
866 | 902 | |
867 | - if($que_type == QUE_RESEARCH || $planet_id === null) |
|
868 | - $query[] = "`que_planet_id` IS NULL"; |
|
869 | - elseif($planet_id) |
|
870 | - $query[] = "(`que_planet_id` = {$planet_id}" . ($que_type ? '' : ' OR que_planet_id IS NULL') . ")"; |
|
871 | - if($que_type) |
|
872 | - $query[] = "`que_type` = {$que_type}"; |
|
903 | + if($que_type == QUE_RESEARCH || $planet_id === null) { |
|
904 | + $query[] = "`que_planet_id` IS NULL"; |
|
905 | + } elseif($planet_id) { |
|
906 | + $query[] = "(`que_planet_id` = {$planet_id}" . ($que_type ? '' : ' OR que_planet_id IS NULL') . ")"; |
|
907 | + } |
|
908 | + if($que_type) { |
|
909 | + $query[] = "`que_type` = {$que_type}"; |
|
910 | + } |
|
873 | 911 | |
874 | 912 | /* |
875 | 913 | $sql = ''; |
@@ -990,8 +1028,7 @@ discard block |
||
990 | 1028 | ), |
991 | 1029 | ), |
992 | 1030 | ); |
993 | - } |
|
994 | - else |
|
1031 | + } else |
|
995 | 1032 | { |
996 | 1033 | $db_changeset = array( |
997 | 1034 | 'action' => SQL_OP_INSERT, |
@@ -1133,7 +1170,9 @@ discard block |
||
1133 | 1170 | |
1134 | 1171 | public static function db_changeset_apply($db_changeset, $flush_delayed = false) { |
1135 | 1172 | $result = true; |
1136 | - if(!is_array($db_changeset) || empty($db_changeset)) return $result; |
|
1173 | + if(!is_array($db_changeset) || empty($db_changeset)) { |
|
1174 | + return $result; |
|
1175 | + } |
|
1137 | 1176 | |
1138 | 1177 | foreach($db_changeset as $table_name => &$table_data) { |
1139 | 1178 | // TODO - delayed changeset |
@@ -1147,8 +1186,13 @@ discard block |
||
1147 | 1186 | foreach($table_data as $record_id => &$conditions) { |
1148 | 1187 | static::db_changeset_condition_compile($conditions, $table_name); |
1149 | 1188 | |
1150 | - if($conditions['action'] != SQL_OP_DELETE && !$conditions[P_FIELDS_STR]) continue; |
|
1151 | - if($conditions['action'] == SQL_OP_DELETE && !$conditions[P_WHERE_STR]) continue; // Защита от случайного удаления всех данных в таблице |
|
1189 | + if($conditions['action'] != SQL_OP_DELETE && !$conditions[P_FIELDS_STR]) { |
|
1190 | + continue; |
|
1191 | + } |
|
1192 | + if($conditions['action'] == SQL_OP_DELETE && !$conditions[P_WHERE_STR]) { |
|
1193 | + continue; |
|
1194 | + } |
|
1195 | + // Защита от случайного удаления всех данных в таблице |
|
1152 | 1196 | |
1153 | 1197 | if($conditions[P_LOCATION] != LOC_NONE) { |
1154 | 1198 | //die('spec ops supernova.php line 928 Добавить работу с кэшем юнитов итд'); |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | * <p>null - транзакция НЕ должна быть запущена</p> |
324 | 324 | * <p>true - транзакция должна быть запущена - для совместимости с $for_update</p> |
325 | 325 | * <p>false - всё равно - для совместимости с $for_update</p> |
326 | - * @return bool Текущий статус транзакции |
|
326 | + * @return null|boolean Текущий статус транзакции |
|
327 | 327 | */ |
328 | 328 | public static function db_transaction_check($status = null) { |
329 | 329 | $error_msg = false; |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | /** |
400 | 400 | * Блокирует указанные таблицу/список таблиц |
401 | 401 | * |
402 | - * @param string|array $tables Таблица/список таблиц для блокировки. Названия таблиц - без префиксов |
|
402 | + * @param string $tables Таблица/список таблиц для блокировки. Названия таблиц - без префиксов |
|
403 | 403 | * <p>string - название таблицы для блокировки</p> |
404 | 404 | * <p>array - массив, где ключ - имя таблицы, а значение - условия блокировки элементов</p> |
405 | 405 | */ |
@@ -587,6 +587,9 @@ discard block |
||
587 | 587 | return $result; |
588 | 588 | } |
589 | 589 | |
590 | + /** |
|
591 | + * @param integer $location_type |
|
592 | + */ |
|
590 | 593 | public static function db_ins_field_set($location_type, $field_set, $serialize = false) { |
591 | 594 | // TODO multiinsert |
592 | 595 | !sn_db_field_set_is_safe($field_set) ? $field_set = sn_db_field_set_make_safe($field_set, $serialize) : false; |
@@ -809,7 +812,7 @@ discard block |
||
809 | 812 | * @param $location_type |
810 | 813 | * @param $location_id |
811 | 814 | * |
812 | - * @return array|bool |
|
815 | + * @return boolean |
|
813 | 816 | */ |
814 | 817 | public static function db_get_unit_list_by_location($user_id = 0, $location_type, $location_id) |
815 | 818 | { |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | |
192 | 192 | |
193 | 193 | public static function log_file($message, $spaces = 0) { |
194 | - if(self::$debug) { |
|
194 | + if (self::$debug) { |
|
195 | 195 | self::$debug->log_file($message, $spaces); |
196 | 196 | } |
197 | 197 | } |
@@ -202,14 +202,14 @@ discard block |
||
202 | 202 | // Перепаковывает массив на заданную глубину, убирая поля с null |
203 | 203 | public static function array_repack(&$array, $level = 0) { |
204 | 204 | // TODO $lock_table не нужна тут |
205 | - if(!is_array($array)) return; |
|
205 | + if (!is_array($array)) return; |
|
206 | 206 | |
207 | - foreach($array as $key => &$value) { |
|
208 | - if($value === null) { |
|
207 | + foreach ($array as $key => &$value) { |
|
208 | + if ($value === null) { |
|
209 | 209 | unset($array[$key]); |
210 | - } elseif($level > 0 && is_array($value)) { |
|
210 | + } elseif ($level > 0 && is_array($value)) { |
|
211 | 211 | static::array_repack($value, $level - 1); |
212 | - if(empty($value)) unset($array[$key]); |
|
212 | + if (empty($value)) unset($array[$key]); |
|
213 | 213 | } |
214 | 214 | } |
215 | 215 | } |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | // TODO Вынести в отдельный объект |
219 | 219 | public static function cache_repack($location_type, $record_id = 0) { |
220 | 220 | // Если есть $user_id - проверяем, а надо ли перепаковывать? |
221 | - if($record_id && isset(static::$data[$location_type][$record_id]) && static::$data[$location_type][$record_id] !== null) return; |
|
221 | + if ($record_id && isset(static::$data[$location_type][$record_id]) && static::$data[$location_type][$record_id] !== null) return; |
|
222 | 222 | |
223 | 223 | static::array_repack(static::$data[$location_type]); |
224 | 224 | static::array_repack(static::$locator[$location_type], 3); // TODO У каждого типа локации - своя глубина!!!! Но можно и глубже ??? |
@@ -226,9 +226,9 @@ discard block |
||
226 | 226 | } |
227 | 227 | public static function cache_clear($location_type, $hard = true) { |
228 | 228 | //print("<br />CACHE CLEAR {$cache_id} " . ($hard ? 'HARD' : 'SOFT') . "<br />"); |
229 | - if($hard && !empty(static::$data[$location_type])) { |
|
229 | + if ($hard && !empty(static::$data[$location_type])) { |
|
230 | 230 | // Здесь нельзя делать unset - надо записывать NULL, что бы это отразилось на зависимых записях |
231 | - array_walk(static::$data[$location_type], function(&$item){$item = null;}); |
|
231 | + array_walk(static::$data[$location_type], function(&$item) {$item = null; }); |
|
232 | 232 | } |
233 | 233 | static::$locator[$location_type] = array(); |
234 | 234 | static::$queries[$location_type] = array(); |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | } |
237 | 237 | public static function cache_clear_all($hard = true) { |
238 | 238 | //print('<br />CACHE CLEAR ALL<br />'); |
239 | - if($hard) { |
|
239 | + if ($hard) { |
|
240 | 240 | static::$data = array(); |
241 | 241 | static::cache_lock_unset_all(); |
242 | 242 | } |
@@ -263,10 +263,10 @@ discard block |
||
263 | 263 | */ |
264 | 264 | public static function cache_set($location_type, $record_id, $record, $force_overwrite = false, $skip_lock = false) { |
265 | 265 | // нет идентификатора - выход |
266 | - if(!($record_id = $record[static::$location_info[$location_type][P_ID]])) return; |
|
266 | + if (!($record_id = $record[static::$location_info[$location_type][P_ID]])) return; |
|
267 | 267 | |
268 | 268 | $in_transaction = static::db_transaction_check(false); |
269 | - if( |
|
269 | + if ( |
|
270 | 270 | $force_overwrite |
271 | 271 | || |
272 | 272 | // Не заменяются заблокированные записи во время транзакции |
@@ -276,14 +276,14 @@ discard block |
||
276 | 276 | !static::cache_isset($location_type, $record_id) |
277 | 277 | ) { |
278 | 278 | static::$data[$location_type][$record_id] = $record; |
279 | - if($in_transaction && !$skip_lock) { |
|
279 | + if ($in_transaction && !$skip_lock) { |
|
280 | 280 | static::cache_lock_set($location_type, $record_id); |
281 | 281 | } |
282 | 282 | } |
283 | 283 | } |
284 | 284 | public static function cache_unset($cache_id, $safe_record_id) { |
285 | 285 | // $record_id должен быть проверен заранее ! |
286 | - if(isset(static::$data[$cache_id][$safe_record_id]) && static::$data[$cache_id][$safe_record_id] !== null) { |
|
286 | + if (isset(static::$data[$cache_id][$safe_record_id]) && static::$data[$cache_id][$safe_record_id] !== null) { |
|
287 | 287 | // Выставляем запись в null |
288 | 288 | static::$data[$cache_id][$safe_record_id] = null; |
289 | 289 | // Очищаем кэш мягко - что бы удалить очистить связанные данные - кэш локаций и кэш запоросов и всё, что потребуется впредь |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | return static::$locks[$location_type][$record_id] = true; // Не всегда - от результата |
298 | 298 | } |
299 | 299 | public static function cache_lock_unset($location_type, $record_id) { |
300 | - if(isset(static::$locks[$location_type][$record_id])) |
|
300 | + if (isset(static::$locks[$location_type][$record_id])) |
|
301 | 301 | unset(static::$locks[$location_type][$record_id]); |
302 | 302 | return true; // Не всегда - от результата |
303 | 303 | } |
@@ -327,13 +327,13 @@ discard block |
||
327 | 327 | */ |
328 | 328 | public static function db_transaction_check($status = null) { |
329 | 329 | $error_msg = false; |
330 | - if($status && !static::$db_in_transaction) { |
|
330 | + if ($status && !static::$db_in_transaction) { |
|
331 | 331 | $error_msg = 'No transaction started for current operation'; |
332 | - } elseif($status === null && static::$db_in_transaction) { |
|
332 | + } elseif ($status === null && static::$db_in_transaction) { |
|
333 | 333 | $error_msg = 'Transaction is already started'; |
334 | 334 | } |
335 | 335 | |
336 | - if($error_msg) { |
|
336 | + if ($error_msg) { |
|
337 | 337 | // TODO - Убрать позже |
338 | 338 | print('<h1>СООБЩИТЕ ЭТО АДМИНУ: sn_db_transaction_check() - ' . $error_msg . '</h1>'); |
339 | 339 | $backtrace = debug_backtrace(); |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | static::$transaction_id++; |
355 | 355 | doquery('START TRANSACTION'); |
356 | 356 | |
357 | - if($config->db_manual_lock_enabled) { |
|
357 | + if ($config->db_manual_lock_enabled) { |
|
358 | 358 | $config->db_loadItem('var_db_manually_locked'); |
359 | 359 | $config->db_saveItem('var_db_manually_locked', SN_TIME_SQL); |
360 | 360 | } |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | public static function db_transaction_commit() { |
370 | 370 | static::db_transaction_check(true); |
371 | 371 | |
372 | - if(!empty(static::$delayed_changset)) { |
|
372 | + if (!empty(static::$delayed_changset)) { |
|
373 | 373 | static::db_changeset_apply(static::$delayed_changset, true); |
374 | 374 | // pdump(static::$delayed_changset); |
375 | 375 | } |
@@ -384,7 +384,7 @@ discard block |
||
384 | 384 | } |
385 | 385 | public static function db_transaction_rollback() { |
386 | 386 | // static::db_transaction_check(true); // TODO - вообще-то тут тоже надо проверять есть ли транзакция |
387 | - if(!empty(static::$delayed_changset)) { |
|
387 | + if (!empty(static::$delayed_changset)) { |
|
388 | 388 | static::db_changeset_revert(); |
389 | 389 | } |
390 | 390 | static::$delayed_changset = array(); |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | */ |
406 | 406 | public static function db_lock_tables($tables) { |
407 | 407 | $tables = is_array($tables) ? $tables : array($tables => ''); |
408 | - foreach($tables as $table_name => $condition) { |
|
408 | + foreach ($tables as $table_name => $condition) { |
|
409 | 409 | self::$db->doquery("SELECT 1 FROM {{{$table_name}}}" . ($condition ? ' WHERE ' . $condition : '')); |
410 | 410 | } |
411 | 411 | } |
@@ -446,17 +446,17 @@ discard block |
||
446 | 446 | //pdump($filter, 'Выбираем ' . $location_type); |
447 | 447 | $query_cache = &static::$queries[$location_type][$filter]; |
448 | 448 | |
449 | - if(!isset($query_cache) || $query_cache === null) { |
|
449 | + if (!isset($query_cache) || $query_cache === null) { |
|
450 | 450 | // pdump($filter, 'Кэш пустой, начинаем возню'); |
451 | 451 | $location_info = &static::$location_info[$location_type]; |
452 | 452 | $id_field = $location_info[P_ID]; |
453 | 453 | $query_cache = array(); |
454 | 454 | |
455 | - if(static::db_transaction_check(false)) { |
|
455 | + if (static::db_transaction_check(false)) { |
|
456 | 456 | //pdump($filter, 'Транзакция - блокируем ' . $location_type); |
457 | 457 | // Проходим по всем родителям данной записи |
458 | 458 | // foreach($location_info[P_OWNER_INFO] as $owner_location_type => $owner_data) |
459 | - foreach($location_info[P_OWNER_INFO] as $owner_data) { |
|
459 | + foreach ($location_info[P_OWNER_INFO] as $owner_data) { |
|
460 | 460 | $owner_location_type = $owner_data[P_LOCATION]; |
461 | 461 | //pdump($filter, 'Транзакция - блокируем родителя ' . $owner_location_type); |
462 | 462 | $parent_id_list = array(); |
@@ -469,14 +469,14 @@ discard block |
||
469 | 469 | ($fetch ? ' LIMIT 1' : ''), false, true); |
470 | 470 | |
471 | 471 | //pdump($q, 'Запрос блокировки'); |
472 | - while($row = db_fetch($query)) { |
|
472 | + while ($row = db_fetch($query)) { |
|
473 | 473 | // Исключаем из списка родительских ИД уже заблокированные записи |
474 | - if(!static::cache_lock_get($owner_location_type, $row['parent_id'])) |
|
474 | + if (!static::cache_lock_get($owner_location_type, $row['parent_id'])) |
|
475 | 475 | $parent_id_list[$row['parent_id']] = $row['parent_id']; |
476 | 476 | } |
477 | 477 | //pdump($parent_id_list, 'Выбраны родители'); |
478 | 478 | // Если все-таки какие-то записи еще не заблокированы - вынимаем текущие версии из базы |
479 | - if($indexes_str = implode(',', $parent_id_list)) { |
|
479 | + if ($indexes_str = implode(',', $parent_id_list)) { |
|
480 | 480 | //pdump($indexes_str, '$indexes_str'); |
481 | 481 | $parent_id_field = static::$location_info[$owner_location_type][P_ID]; |
482 | 482 | static::db_get_record_list($owner_location_type, |
@@ -491,7 +491,7 @@ discard block |
||
491 | 491 | "SELECT * FROM {{{$location_info[P_TABLE_NAME]}}}" . |
492 | 492 | (($filter = trim($filter)) ? " WHERE {$filter}" : '') |
493 | 493 | ); |
494 | - while($row = db_fetch($query)) { |
|
494 | + while ($row = db_fetch($query)) { |
|
495 | 495 | // static::db_get_record_by_id($location_type, $row[$id_field]); |
496 | 496 | static::cache_set($location_type, $row[$id_field], $row); |
497 | 497 | $query_cache[$row[$id_field]] = &static::$data[$location_type][$row[$id_field]]; |
@@ -499,14 +499,14 @@ discard block |
||
499 | 499 | } |
500 | 500 | } |
501 | 501 | |
502 | - if($no_return) { |
|
502 | + if ($no_return) { |
|
503 | 503 | return true; |
504 | 504 | } else { |
505 | 505 | $result = false; |
506 | - if(is_array($query_cache)) { |
|
507 | - foreach($query_cache as $key => $value) { |
|
506 | + if (is_array($query_cache)) { |
|
507 | + foreach ($query_cache as $key => $value) { |
|
508 | 508 | $result[$key] = $value; |
509 | - if($fetch) break; |
|
509 | + if ($fetch) break; |
|
510 | 510 | } |
511 | 511 | } |
512 | 512 | return $fetch ? (is_array($result) ? reset($result) : false) : $result; |
@@ -522,14 +522,14 @@ discard block |
||
522 | 522 | */ |
523 | 523 | public static function db_upd_record_by_id($location_type, $record_id, $set) { |
524 | 524 | //if(!($record_id = intval($record_id)) || !($set = trim($set))) return false; |
525 | - if(!($record_id = idval($record_id)) || !($set = trim($set))) return false; |
|
525 | + if (!($record_id = idval($record_id)) || !($set = trim($set))) return false; |
|
526 | 526 | |
527 | 527 | $location_info = &static::$location_info[$location_type]; |
528 | 528 | $id_field = $location_info[P_ID]; |
529 | 529 | $table_name = $location_info[P_TABLE_NAME]; |
530 | - if($result = static::db_query($q = "UPDATE {{{$table_name}}} SET {$set} WHERE `{$id_field}` = {$record_id}")) // TODO Как-то вернуть может быть LIMIT 1 ? |
|
530 | + if ($result = static::db_query($q = "UPDATE {{{$table_name}}} SET {$set} WHERE `{$id_field}` = {$record_id}")) // TODO Как-то вернуть может быть LIMIT 1 ? |
|
531 | 531 | { |
532 | - if(static::$db->db_affected_rows()) { |
|
532 | + if (static::$db->db_affected_rows()) { |
|
533 | 533 | // Обновляем данные только если ряд был затронут |
534 | 534 | // TODO - переделать под работу со структурированными $set |
535 | 535 | |
@@ -544,16 +544,16 @@ discard block |
||
544 | 544 | return $result; |
545 | 545 | } |
546 | 546 | public static function db_upd_record_list($location_type, $condition, $set) { |
547 | - if(!($set = trim($set))) return false; |
|
547 | + if (!($set = trim($set))) return false; |
|
548 | 548 | |
549 | 549 | $condition = trim($condition); |
550 | 550 | $table_name = static::$location_info[$location_type][P_TABLE_NAME]; |
551 | 551 | |
552 | 552 | //static::db_get_record_list($location_type, $condition, false, true); |
553 | 553 | |
554 | - if($result = static::db_query("UPDATE {{{$table_name}}} SET " . $set . ($condition ? ' WHERE ' . $condition : ''))) { |
|
554 | + if ($result = static::db_query("UPDATE {{{$table_name}}} SET " . $set . ($condition ? ' WHERE ' . $condition : ''))) { |
|
555 | 555 | |
556 | - if(static::$db->db_affected_rows()) { // Обновляем данные только если ряд был затронут |
|
556 | + if (static::$db->db_affected_rows()) { // Обновляем данные только если ряд был затронут |
|
557 | 557 | // Поскольку нам неизвестно, что и как обновилось - сбрасываем кэш этого типа полностью |
558 | 558 | // TODO - когда будет структурированный $condition и $set - перепаковывать данные |
559 | 559 | static::cache_clear($location_type, true); |
@@ -572,8 +572,8 @@ discard block |
||
572 | 572 | public static function db_ins_record($location_type, $set) { |
573 | 573 | $set = trim($set); |
574 | 574 | $table_name = static::$location_info[$location_type][P_TABLE_NAME]; |
575 | - if($result = static::db_query("INSERT INTO `{{{$table_name}}}` SET {$set}")) { |
|
576 | - if(static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
575 | + if ($result = static::db_query("INSERT INTO `{{{$table_name}}}` SET {$set}")) { |
|
576 | + if (static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
577 | 577 | { |
578 | 578 | $record_id = db_insert_id(); |
579 | 579 | // Вытаскиваем запись целиком, потому что в $set могли быть "данные по умолчанию" |
@@ -595,8 +595,8 @@ discard block |
||
595 | 595 | $fields = implode(',', array_keys($field_set)); |
596 | 596 | |
597 | 597 | $table_name = static::$location_info[$location_type][P_TABLE_NAME]; |
598 | - if($result = static::db_query("INSERT INTO `{{{$table_name}}}` ($fields) VALUES ($values);")) { |
|
599 | - if(static::$db->db_affected_rows()) { |
|
598 | + if ($result = static::db_query("INSERT INTO `{{{$table_name}}}` ($fields) VALUES ($values);")) { |
|
599 | + if (static::$db->db_affected_rows()) { |
|
600 | 600 | // Обновляем данные только если ряд был затронут |
601 | 601 | $record_id = db_insert_id(); |
602 | 602 | // Вытаскиваем запись целиком, потому что в $set могли быть "данные по умолчанию" |
@@ -613,14 +613,14 @@ discard block |
||
613 | 613 | public static function db_del_record_by_id($location_type, $safe_record_id) |
614 | 614 | { |
615 | 615 | // if(!($safe_record_id = intval($safe_record_id))) return false; |
616 | - if(!($safe_record_id = idval($safe_record_id))) return false; |
|
616 | + if (!($safe_record_id = idval($safe_record_id))) return false; |
|
617 | 617 | |
618 | 618 | $location_info = &static::$location_info[$location_type]; |
619 | 619 | $id_field = $location_info[P_ID]; |
620 | 620 | $table_name = $location_info[P_TABLE_NAME]; |
621 | - if($result = static::db_query("DELETE FROM `{{{$table_name}}}` WHERE `{$id_field}` = {$safe_record_id}")) |
|
621 | + if ($result = static::db_query("DELETE FROM `{{{$table_name}}}` WHERE `{$id_field}` = {$safe_record_id}")) |
|
622 | 622 | { |
623 | - if(static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
623 | + if (static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
624 | 624 | { |
625 | 625 | static::cache_unset($location_type, $safe_record_id); |
626 | 626 | } |
@@ -630,16 +630,16 @@ discard block |
||
630 | 630 | } |
631 | 631 | public static function db_del_record_list($location_type, $condition) |
632 | 632 | { |
633 | - if(!($condition = trim($condition))) return false; |
|
633 | + if (!($condition = trim($condition))) return false; |
|
634 | 634 | |
635 | 635 | $location_info = &static::$location_info[$location_type]; |
636 | 636 | $table_name = $location_info[P_TABLE_NAME]; |
637 | 637 | |
638 | 638 | //static::db_get_record_list($location_type, $condition, false, true); |
639 | 639 | |
640 | - if($result = static::db_query("DELETE FROM `{{{$table_name}}}` WHERE {$condition}")) |
|
640 | + if ($result = static::db_query("DELETE FROM `{{{$table_name}}}` WHERE {$condition}")) |
|
641 | 641 | { |
642 | - if(static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
642 | + if (static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут |
|
643 | 643 | { |
644 | 644 | // Обнуление кэша, потому что непонятно, что поменялось |
645 | 645 | // TODO - когда будет структурированный $condition можно будет делать только cache_unset по нужным записям |
@@ -686,21 +686,21 @@ discard block |
||
686 | 686 | public static function db_get_user_by_username($username_unsafe, $for_update = false, $fields = '*', $player = null, $like = false) |
687 | 687 | { |
688 | 688 | // TODO Проверить, кстати - а везде ли нужно выбирать юзеров или где-то все-таки ищутся Альянсы ? |
689 | - if(!($username_unsafe = trim($username_unsafe))) return false; |
|
689 | + if (!($username_unsafe = trim($username_unsafe))) return false; |
|
690 | 690 | |
691 | 691 | $user = null; |
692 | - if(is_array(static::$data[LOC_USER])) |
|
693 | - foreach(static::$data[LOC_USER] as $user_id => $user_data) |
|
692 | + if (is_array(static::$data[LOC_USER])) |
|
693 | + foreach (static::$data[LOC_USER] as $user_id => $user_data) |
|
694 | 694 | { |
695 | - if(is_array($user_data) && isset($user_data['username'])) |
|
695 | + if (is_array($user_data) && isset($user_data['username'])) |
|
696 | 696 | { |
697 | 697 | // проверяем поле |
698 | 698 | // TODO Возможно есть смысл всегда искать по strtolower - но может игрок захочет переименоваться с другим регистром? Проверить! |
699 | - if((!$like && $user_data['username'] == $username_unsafe) || ($like && strtolower($user_data['username']) == strtolower($username_unsafe))) |
|
699 | + if ((!$like && $user_data['username'] == $username_unsafe) || ($like && strtolower($user_data['username']) == strtolower($username_unsafe))) |
|
700 | 700 | { |
701 | 701 | // $user_as_ally = intval($user_data['user_as_ally']); |
702 | 702 | $user_as_ally = idval($user_data['user_as_ally']); |
703 | - if($player === null || ($player === true && !$user_as_ally) || ($player === false && $user_as_ally)) |
|
703 | + if ($player === null || ($player === true && !$user_as_ally) || ($player === false && $user_as_ally)) |
|
704 | 704 | { |
705 | 705 | $user = $user_data; |
706 | 706 | break; |
@@ -709,7 +709,7 @@ discard block |
||
709 | 709 | } |
710 | 710 | } |
711 | 711 | |
712 | - if($user === null) |
|
712 | + if ($user === null) |
|
713 | 713 | { |
714 | 714 | // Вытаскиваем запись |
715 | 715 | $username_safe = db_escape($like ? strtolower($username_unsafe) : $username_unsafe); // тут на самом деле strtolower() лишняя, но пусть будет |
@@ -718,7 +718,7 @@ discard block |
||
718 | 718 | // self::db_get_record_list(LOC_USER, "`username` " . ($like ? 'LIKE' : '='). " '{$username_safe}'"); |
719 | 719 | |
720 | 720 | $user = static::db_query( |
721 | - "SELECT * FROM {{users}} WHERE `username` " . ($like ? 'LIKE' : '='). " '{$username_safe}'" |
|
721 | + "SELECT * FROM {{users}} WHERE `username` " . ($like ? 'LIKE' : '=') . " '{$username_safe}'" |
|
722 | 722 | , true); |
723 | 723 | static::cache_set(LOC_USER, $user['id'], $user); // В кэш-юзер так же заполнять индексы |
724 | 724 | } |
@@ -727,15 +727,15 @@ discard block |
||
727 | 727 | } |
728 | 728 | // UNUSED |
729 | 729 | public static function db_get_user_by_email($email_unsafe, $use_both = false, $for_update = false, $fields = '*') { |
730 | - if(!($email_unsafe = strtolower(trim($email_unsafe)))) return false; |
|
730 | + if (!($email_unsafe = strtolower(trim($email_unsafe)))) return false; |
|
731 | 731 | |
732 | 732 | $user = null; |
733 | 733 | // TODO переделать на индексы |
734 | - if(is_array(static::$data[LOC_USER])) { |
|
735 | - foreach(static::$data[LOC_USER] as $user_id => $user_data) { |
|
736 | - if(is_array($user_data) && isset($user_data['email_2'])) { |
|
734 | + if (is_array(static::$data[LOC_USER])) { |
|
735 | + foreach (static::$data[LOC_USER] as $user_id => $user_data) { |
|
736 | + if (is_array($user_data) && isset($user_data['email_2'])) { |
|
737 | 737 | // проверяем поле |
738 | - if(strtolower($user_data['email_2']) == $email_unsafe || ($use_both && strtolower($user_data['email']) == $email_unsafe)) { |
|
738 | + if (strtolower($user_data['email_2']) == $email_unsafe || ($use_both && strtolower($user_data['email']) == $email_unsafe)) { |
|
739 | 739 | $user = $user_data; |
740 | 740 | break; |
741 | 741 | } |
@@ -743,7 +743,7 @@ discard block |
||
743 | 743 | } |
744 | 744 | } |
745 | 745 | |
746 | - if($user === null) { |
|
746 | + if ($user === null) { |
|
747 | 747 | // Вытаскиваем запись |
748 | 748 | $email_safe = db_escape($email_unsafe); |
749 | 749 | $user = static::db_query( |
@@ -761,7 +761,7 @@ discard block |
||
761 | 761 | $user = null; |
762 | 762 | // TODO переделать на индексы |
763 | 763 | |
764 | - if($user === null && !empty($where_safe)) { |
|
764 | + if ($user === null && !empty($where_safe)) { |
|
765 | 765 | // Вытаскиваем запись |
766 | 766 | $user = static::db_query("SELECT * FROM {{users}} WHERE {$where_safe}", true); |
767 | 767 | |
@@ -796,7 +796,7 @@ discard block |
||
796 | 796 | { |
797 | 797 | // TODO запихивать в $data[LOC_LOCATION][$location_type][$location_id] |
798 | 798 | $unit = static::db_get_record_by_id(LOC_UNIT, $unit_id, $for_update, $fields); |
799 | - if(is_array($unit)) |
|
799 | + if (is_array($unit)) |
|
800 | 800 | { |
801 | 801 | static::$locator[LOC_UNIT][$unit['unit_location_type']][$unit['unit_location_id']][$unit['unit_snid']] = &static::$data[LOC_UNIT][$unit_id]; |
802 | 802 | } |
@@ -814,15 +814,15 @@ discard block |
||
814 | 814 | public static function db_get_unit_list_by_location($user_id = 0, $location_type, $location_id) |
815 | 815 | { |
816 | 816 | //if(!($location_type = intval($location_type)) || !($location_id = intval($location_id))) return false; |
817 | - if(!($location_type = idval($location_type)) || !($location_id = idval($location_id))) return false; |
|
817 | + if (!($location_type = idval($location_type)) || !($location_id = idval($location_id))) return false; |
|
818 | 818 | |
819 | 819 | $query_cache = &static::$locator[LOC_UNIT][$location_type][$location_id]; |
820 | - if(!isset($query_cache)) |
|
820 | + if (!isset($query_cache)) |
|
821 | 821 | { |
822 | 822 | $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()); |
823 | - if(is_array($got_data)) |
|
823 | + if (is_array($got_data)) |
|
824 | 824 | { |
825 | - foreach($got_data as $unit_id => $unit_data) |
|
825 | + foreach ($got_data as $unit_id => $unit_data) |
|
826 | 826 | { |
827 | 827 | // static::$data[LOC_LOCATION][$location_type][$location_id][$unit_data['unit_snid']] = &static::$data[LOC_UNIT][$unit_id]; |
828 | 828 | $query_cache[$unit_data['unit_snid']] = &static::$data[LOC_UNIT][$unit_id]; |
@@ -831,8 +831,8 @@ discard block |
||
831 | 831 | } |
832 | 832 | |
833 | 833 | $result = false; |
834 | - if(is_array($query_cache)) { |
|
835 | - foreach($query_cache as $key => $value) { |
|
834 | + if (is_array($query_cache)) { |
|
835 | + foreach ($query_cache as $key => $value) { |
|
836 | 836 | $result[$key] = $value; |
837 | 837 | } |
838 | 838 | } |
@@ -870,7 +870,7 @@ discard block |
||
870 | 870 | */ |
871 | 871 | public static function db_que_list_by_type_location($user_id, $planet_id = null, $que_type = false, $for_update = false) |
872 | 872 | { |
873 | - if(!$user_id) |
|
873 | + if (!$user_id) |
|
874 | 874 | { |
875 | 875 | pdump(debug_backtrace()); |
876 | 876 | die('No user_id for que_get_que()'); |
@@ -881,14 +881,14 @@ discard block |
||
881 | 881 | $query = array(); |
882 | 882 | |
883 | 883 | // if($user_id = intval($user_id)) |
884 | - if($user_id = idval($user_id)) |
|
884 | + if ($user_id = idval($user_id)) |
|
885 | 885 | $query[] = "`que_player_id` = {$user_id}"; |
886 | 886 | |
887 | - if($que_type == QUE_RESEARCH || $planet_id === null) |
|
887 | + if ($que_type == QUE_RESEARCH || $planet_id === null) |
|
888 | 888 | $query[] = "`que_planet_id` IS NULL"; |
889 | - elseif($planet_id) |
|
889 | + elseif ($planet_id) |
|
890 | 890 | $query[] = "(`que_planet_id` = {$planet_id}" . ($que_type ? '' : ' OR que_planet_id IS NULL') . ")"; |
891 | - if($que_type) |
|
891 | + if ($que_type) |
|
892 | 892 | $query[] = "`que_type` = {$que_type}"; |
893 | 893 | |
894 | 894 | /* |
@@ -957,14 +957,14 @@ discard block |
||
957 | 957 | |
958 | 958 | public static function db_changeset_prepare_unit($unit_id, $unit_value, $user, $planet_id = null) |
959 | 959 | { |
960 | - if(!is_array($user)) |
|
960 | + if (!is_array($user)) |
|
961 | 961 | { |
962 | 962 | // TODO - remove later |
963 | 963 | print('<h1>СООБЩИТЕ ЭТО АДМИНУ: sn_db_unit_changeset_prepare() - USER is not ARRAY</h1>'); |
964 | 964 | pdump(debug_backtrace()); |
965 | 965 | die('USER is not ARRAY'); |
966 | 966 | } |
967 | - if(!isset($user['id']) || !$user['id']) |
|
967 | + if (!isset($user['id']) || !$user['id']) |
|
968 | 968 | { |
969 | 969 | // TODO - remove later |
970 | 970 | print('<h1>СООБЩИТЕ ЭТО АДМИНУ: sn_db_unit_changeset_prepare() - USER[id] пустой</h1>'); |
@@ -980,7 +980,7 @@ discard block |
||
980 | 980 | |
981 | 981 | $db_changeset = array(); |
982 | 982 | $temp = db_unit_by_location($user['id'], $unit_location, $location_id, $unit_id, true, 'unit_id'); |
983 | - if($temp['unit_id']) |
|
983 | + if ($temp['unit_id']) |
|
984 | 984 | { |
985 | 985 | $db_changeset = array( |
986 | 986 | 'action' => SQL_OP_UPDATE, |
@@ -1055,9 +1055,9 @@ discard block |
||
1055 | 1055 | } |
1056 | 1056 | |
1057 | 1057 | public function db_changeset_condition_compile(&$conditions, &$table_name = '') { |
1058 | - if(!$conditions[P_LOCATION] || $conditions[P_LOCATION] == LOC_NONE) { |
|
1058 | + if (!$conditions[P_LOCATION] || $conditions[P_LOCATION] == LOC_NONE) { |
|
1059 | 1059 | $conditions[P_LOCATION] = LOC_NONE; |
1060 | - switch($table_name) { |
|
1060 | + switch ($table_name) { |
|
1061 | 1061 | case 'users': |
1062 | 1062 | case LOC_USER: |
1063 | 1063 | $conditions[P_TABLE_NAME] = $table_name = 'users'; |
@@ -1079,18 +1079,18 @@ discard block |
||
1079 | 1079 | } |
1080 | 1080 | |
1081 | 1081 | $conditions[P_FIELDS_STR] = ''; |
1082 | - if($conditions['fields']) { |
|
1082 | + if ($conditions['fields']) { |
|
1083 | 1083 | $fields = array(); |
1084 | - foreach($conditions['fields'] as $field_name => $field_data) { |
|
1084 | + foreach ($conditions['fields'] as $field_name => $field_data) { |
|
1085 | 1085 | $condition = "`{$field_name}` = "; |
1086 | 1086 | $value = ''; |
1087 | - if($field_data['delta']) { |
|
1087 | + if ($field_data['delta']) { |
|
1088 | 1088 | $value = "`{$field_name}`" . ($field_data['delta'] >= 0 ? '+' : '') . $field_data['delta']; |
1089 | - } elseif($field_data['set']) { |
|
1090 | - $value = (is_string($field_data['set']) ? "'{$field_data['set']}'": $field_data['set']); |
|
1089 | + } elseif ($field_data['set']) { |
|
1090 | + $value = (is_string($field_data['set']) ? "'{$field_data['set']}'" : $field_data['set']); |
|
1091 | 1091 | } |
1092 | 1092 | |
1093 | - if($value) { |
|
1093 | + if ($value) { |
|
1094 | 1094 | $fields[] = $condition . $value; |
1095 | 1095 | } |
1096 | 1096 | } |
@@ -1098,16 +1098,14 @@ discard block |
||
1098 | 1098 | } |
1099 | 1099 | |
1100 | 1100 | $conditions[P_WHERE_STR] = ''; |
1101 | - if(!empty($conditions['where'])) { |
|
1102 | - if($conditions[P_VERSION] == 1) { |
|
1101 | + if (!empty($conditions['where'])) { |
|
1102 | + if ($conditions[P_VERSION] == 1) { |
|
1103 | 1103 | $the_conditions = array(); |
1104 | - foreach($conditions['where'] as $field_id => $field_value) { |
|
1104 | + foreach ($conditions['where'] as $field_id => $field_value) { |
|
1105 | 1105 | // Простое условие - $field_id = $field_value |
1106 | - if(is_string($field_id)) { |
|
1106 | + if (is_string($field_id)) { |
|
1107 | 1107 | $field_value = |
1108 | - $field_value === null ? 'NULL' : |
|
1109 | - (is_string($field_value) ? "'" . db_escape($field_value) . "'" : |
|
1110 | - (is_bool($field_value) ? intval($field_value) : $field_value)); |
|
1108 | + $field_value === null ? 'NULL' : (is_string($field_value) ? "'" . db_escape($field_value) . "'" : (is_bool($field_value) ? intval($field_value) : $field_value)); |
|
1111 | 1109 | $the_conditions[] = "`{$field_id}` = {$field_value}"; |
1112 | 1110 | } else { |
1113 | 1111 | die('Неподдерживаемый тип условия'); |
@@ -1124,7 +1122,7 @@ discard block |
||
1124 | 1122 | $conditions[P_WHERE_STR] = implode(' AND ', $the_conditions); |
1125 | 1123 | } |
1126 | 1124 | |
1127 | - switch($conditions['action']) { |
|
1125 | + switch ($conditions['action']) { |
|
1128 | 1126 | case SQL_OP_DELETE: $conditions[P_ACTION_STR] = ("DELETE FROM {{{$table_name}}}"); break; |
1129 | 1127 | case SQL_OP_UPDATE: $conditions[P_ACTION_STR] = ("UPDATE {{{$table_name}}} SET"); break; |
1130 | 1128 | case SQL_OP_INSERT: $conditions[P_ACTION_STR] = ("INSERT INTO {{{$table_name}}} SET"); break; |
@@ -1137,9 +1135,9 @@ discard block |
||
1137 | 1135 | |
1138 | 1136 | public static function db_changeset_apply($db_changeset, $flush_delayed = false) { |
1139 | 1137 | $result = true; |
1140 | - if(!is_array($db_changeset) || empty($db_changeset)) return $result; |
|
1138 | + if (!is_array($db_changeset) || empty($db_changeset)) return $result; |
|
1141 | 1139 | |
1142 | - foreach($db_changeset as $table_name => &$table_data) { |
|
1140 | + foreach ($db_changeset as $table_name => &$table_data) { |
|
1143 | 1141 | // TODO - delayed changeset |
1144 | 1142 | /* |
1145 | 1143 | if(static::db_transaction_check(false) && !$flush_delayed && ($table_name == 'users' || $table_name == 'planets' || $table_name == 'unit')) |
@@ -1148,15 +1146,15 @@ discard block |
||
1148 | 1146 | continue; |
1149 | 1147 | } |
1150 | 1148 | */ |
1151 | - foreach($table_data as $record_id => &$conditions) { |
|
1149 | + foreach ($table_data as $record_id => &$conditions) { |
|
1152 | 1150 | static::db_changeset_condition_compile($conditions, $table_name); |
1153 | 1151 | |
1154 | - if($conditions['action'] != SQL_OP_DELETE && !$conditions[P_FIELDS_STR]) continue; |
|
1155 | - if($conditions['action'] == SQL_OP_DELETE && !$conditions[P_WHERE_STR]) continue; // Защита от случайного удаления всех данных в таблице |
|
1152 | + if ($conditions['action'] != SQL_OP_DELETE && !$conditions[P_FIELDS_STR]) continue; |
|
1153 | + if ($conditions['action'] == SQL_OP_DELETE && !$conditions[P_WHERE_STR]) continue; // Защита от случайного удаления всех данных в таблице |
|
1156 | 1154 | |
1157 | - if($conditions[P_LOCATION] != LOC_NONE) { |
|
1155 | + if ($conditions[P_LOCATION] != LOC_NONE) { |
|
1158 | 1156 | //die('spec ops supernova.php line 928 Добавить работу с кэшем юнитов итд'); |
1159 | - switch($conditions['action']) |
|
1157 | + switch ($conditions['action']) |
|
1160 | 1158 | { |
1161 | 1159 | case SQL_OP_DELETE: $result = self::db_del_record_list($conditions[P_LOCATION], $conditions[P_WHERE_STR]) && $result; break; |
1162 | 1160 | case SQL_OP_UPDATE: $result = self::db_upd_record_list($conditions[P_LOCATION], $conditions[P_WHERE_STR], $conditions[P_FIELDS_STR]) && $result; break; |
@@ -1237,16 +1235,16 @@ discard block |
||
1237 | 1235 | } |
1238 | 1236 | |
1239 | 1237 | |
1240 | - public static function init_0_prepare () { |
|
1238 | + public static function init_0_prepare() { |
|
1241 | 1239 | // Отключаем magic_quotes |
1242 | 1240 | ini_get('magic_quotes_sybase') ? die('SN is incompatible with \'magic_quotes_sybase\' turned on. Disable it in php.ini or .htaccess...') : false; |
1243 | - if(@get_magic_quotes_gpc()) { |
|
1241 | + if (@get_magic_quotes_gpc()) { |
|
1244 | 1242 | $gpcr = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST); |
1245 | - array_walk_recursive($gpcr, function (&$value, $key) { |
|
1243 | + array_walk_recursive($gpcr, function(&$value, $key) { |
|
1246 | 1244 | $value = stripslashes($value); |
1247 | 1245 | }); |
1248 | 1246 | } |
1249 | - if(function_exists('set_magic_quotes_runtime')) { |
|
1247 | + if (function_exists('set_magic_quotes_runtime')) { |
|
1250 | 1248 | @set_magic_quotes_runtime(0); |
1251 | 1249 | @ini_set('magic_quotes_runtime', 0); |
1252 | 1250 | @ini_set('magic_quotes_sybase', 0); |
@@ -1324,7 +1322,7 @@ discard block |
||
1324 | 1322 | } |
1325 | 1323 | |
1326 | 1324 | public static function init_debug_state() { |
1327 | - if($_SERVER['SERVER_NAME'] == 'localhost' && !defined('BE_DEBUG')) { |
|
1325 | + if ($_SERVER['SERVER_NAME'] == 'localhost' && !defined('BE_DEBUG')) { |
|
1328 | 1326 | define('BE_DEBUG', true); |
1329 | 1327 | } |
1330 | 1328 | // define('DEBUG_SQL_ONLINE', true); // Полный дамп запросов в рил-тайме. Подойдет любое значение |
@@ -1336,7 +1334,7 @@ discard block |
||
1336 | 1334 | defined('DEBUG_SQL_ERROR') && !defined('DEBUG_SQL_COMMENT') ? define('DEBUG_SQL_COMMENT', true) : false; |
1337 | 1335 | defined('DEBUG_SQL_COMMENT_LONG') && !defined('DEBUG_SQL_COMMENT') ? define('DEBUG_SQL_COMMENT', true) : false; |
1338 | 1336 | |
1339 | - if(defined('BE_DEBUG') || static::$config->debug) { |
|
1337 | + if (defined('BE_DEBUG') || static::$config->debug) { |
|
1340 | 1338 | @define('BE_DEBUG', true); |
1341 | 1339 | @ini_set('display_errors', 1); |
1342 | 1340 | @error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED); |