@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | function geometry_progression_sum($n, $b1, $q) { |
4 | - return $q != 1 ? ($b1 * (pow($q, $n) - 1)/($q - 1)) : ($n * $b1); |
|
4 | + return $q != 1 ? ($b1 * (pow($q, $n) - 1) / ($q - 1)) : ($n * $b1); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | function sn_floor($value) |
@@ -43,8 +43,8 @@ discard block |
||
43 | 43 | * |
44 | 44 | * @return float|int |
45 | 45 | */ |
46 | -function sn_rand_gauss_range($range_start, $range_end, $round = true, $strict = 4, $cut_extreme = false) { |
|
47 | - if($cut_extreme) { |
|
46 | +function sn_rand_gauss_range($range_start, $range_end, $round = true, $strict = 4, $cut_extreme = false) { |
|
47 | + if ($cut_extreme) { |
|
48 | 48 | $range_start--; |
49 | 49 | $range_end++; |
50 | 50 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | { |
61 | 61 | $args = func_get_args(); |
62 | 62 | |
63 | - switch(func_num_args()) |
|
63 | + switch (func_num_args()) |
|
64 | 64 | { |
65 | 65 | case 0: |
66 | 66 | // trigger_error('median() requires at least one parameter',E_USER_WARNING); |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | // fallthrough |
73 | 73 | |
74 | 74 | default: |
75 | - if(!is_array($args)) |
|
75 | + if (!is_array($args)) |
|
76 | 76 | { |
77 | 77 | // trigger_error('median() requires a list of numbers to operate on or an array of numbers', E_USER_NOTICE); |
78 | 78 | return false; |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | $n = count($args); |
84 | 84 | $h = intval($n / 2); |
85 | 85 | |
86 | - if($n % 2 == 0) |
|
86 | + if ($n % 2 == 0) |
|
87 | 87 | { |
88 | - $median = ($args[$h] + $args[$h-1]) / 2; |
|
88 | + $median = ($args[$h] + $args[$h - 1]) / 2; |
|
89 | 89 | } |
90 | 90 | else |
91 | 91 | { |
@@ -103,49 +103,49 @@ discard block |
||
103 | 103 | } |
104 | 104 | function linear_calc(&$linear, $from = 0, $logProcess = false) |
105 | 105 | { |
106 | - for($i = $from; $i < count($linear); $i++) |
|
106 | + for ($i = $from; $i < count($linear); $i++) |
|
107 | 107 | { |
108 | 108 | $eq = &$linear[$i]; |
109 | - for($j = count($eq) - 1; $j >= $from; $j--) |
|
109 | + for ($j = count($eq) - 1; $j >= $from; $j--) |
|
110 | 110 | { |
111 | 111 | $eq[$j] /= $eq[$from]; |
112 | 112 | } |
113 | 113 | } |
114 | - if($logProcess) pdump($linear, 'Нормализовано по х' . $from); |
|
114 | + if ($logProcess) pdump($linear, 'Нормализовано по х'.$from); |
|
115 | 115 | |
116 | - for($i = $from + 1; $i < count($linear); $i++) |
|
116 | + for ($i = $from + 1; $i < count($linear); $i++) |
|
117 | 117 | { |
118 | 118 | $eq = &$linear[$i]; |
119 | - for($j = count($eq) - 1; $j >= $from; $j--) |
|
119 | + for ($j = count($eq) - 1; $j >= $from; $j--) |
|
120 | 120 | { |
121 | 121 | $eq[$j] -= $linear[$from][$j]; |
122 | 122 | } |
123 | 123 | } |
124 | - if($logProcess) pdump($linear, 'Подставили х' . $from); |
|
124 | + if ($logProcess) pdump($linear, 'Подставили х'.$from); |
|
125 | 125 | |
126 | - if($from < count($linear) - 1) |
|
126 | + if ($from < count($linear) - 1) |
|
127 | 127 | { |
128 | 128 | linear_calc($linear, $from + 1, $logProcess); |
129 | 129 | } |
130 | 130 | |
131 | - if($from) |
|
131 | + if ($from) |
|
132 | 132 | { |
133 | - for($i = 0; $i < $from; $i++) |
|
133 | + for ($i = 0; $i < $from; $i++) |
|
134 | 134 | { |
135 | 135 | $eq = &$linear[$i]; |
136 | - for($j = count($eq) - 1; $j >= $from; $j--) |
|
136 | + for ($j = count($eq) - 1; $j >= $from; $j--) |
|
137 | 137 | { |
138 | 138 | $eq[$j] = $eq[$j] - $eq[$from] * $linear[$from][$j]; |
139 | 139 | } |
140 | 140 | } |
141 | - if($logProcess) pdump($linear, 'Подставили обратно х' . $from); |
|
141 | + if ($logProcess) pdump($linear, 'Подставили обратно х'.$from); |
|
142 | 142 | } |
143 | 143 | else |
144 | 144 | { |
145 | - if($logProcess) pdump($linear, 'Результат' . $from); |
|
146 | - foreach($linear as $index => &$eq) |
|
145 | + if ($logProcess) pdump($linear, 'Результат'.$from); |
|
146 | + foreach ($linear as $index => &$eq) |
|
147 | 147 | { |
148 | - pdump($eq[count($linear)], 'x' . $index); |
|
148 | + pdump($eq[count($linear)], 'x'.$index); |
|
149 | 149 | } |
150 | 150 | } |
151 | 151 | } |
@@ -86,8 +86,7 @@ discard block |
||
86 | 86 | if($n % 2 == 0) |
87 | 87 | { |
88 | 88 | $median = ($args[$h] + $args[$h-1]) / 2; |
89 | - } |
|
90 | - else |
|
89 | + } else |
|
91 | 90 | { |
92 | 91 | $median = $args[$h]; |
93 | 92 | } |
@@ -111,7 +110,9 @@ discard block |
||
111 | 110 | $eq[$j] /= $eq[$from]; |
112 | 111 | } |
113 | 112 | } |
114 | - if($logProcess) pdump($linear, 'Нормализовано по х' . $from); |
|
113 | + if($logProcess) { |
|
114 | + pdump($linear, 'Нормализовано по х' . $from); |
|
115 | + } |
|
115 | 116 | |
116 | 117 | for($i = $from + 1; $i < count($linear); $i++) |
117 | 118 | { |
@@ -121,7 +122,9 @@ discard block |
||
121 | 122 | $eq[$j] -= $linear[$from][$j]; |
122 | 123 | } |
123 | 124 | } |
124 | - if($logProcess) pdump($linear, 'Подставили х' . $from); |
|
125 | + if($logProcess) { |
|
126 | + pdump($linear, 'Подставили х' . $from); |
|
127 | + } |
|
125 | 128 | |
126 | 129 | if($from < count($linear) - 1) |
127 | 130 | { |
@@ -138,11 +141,14 @@ discard block |
||
138 | 141 | $eq[$j] = $eq[$j] - $eq[$from] * $linear[$from][$j]; |
139 | 142 | } |
140 | 143 | } |
141 | - if($logProcess) pdump($linear, 'Подставили обратно х' . $from); |
|
142 | - } |
|
143 | - else |
|
144 | + if($logProcess) { |
|
145 | + pdump($linear, 'Подставили обратно х' . $from); |
|
146 | + } |
|
147 | + } else |
|
144 | 148 | { |
145 | - if($logProcess) pdump($linear, 'Результат' . $from); |
|
149 | + if($logProcess) { |
|
150 | + pdump($linear, 'Результат' . $from); |
|
151 | + } |
|
146 | 152 | foreach($linear as $index => &$eq) |
147 | 153 | { |
148 | 154 | pdump($eq[count($linear)], 'x' . $index); |
@@ -37,7 +37,7 @@ |
||
37 | 37 | /** |
38 | 38 | * @param float $range_start - Начало диапазона |
39 | 39 | * @param float $range_end - Конец диапазона |
40 | - * @param bool|int $round - До скольки знаков округлять результат. False - не округлять, True - округлять до целого, 1 - округлять до десятков, 2 - до сотен итд |
|
40 | + * @param boolean $round - До скольки знаков округлять результат. False - не округлять, True - округлять до целого, 1 - округлять до десятков, 2 - до сотен итд |
|
41 | 41 | * @param int $strict - В сколько сигм надо уложить результат |
42 | 42 | * @param bool|false $cut_extreme - надо ли обрезать крайние значения. Например, при $strict = 2 их слишком много |
43 | 43 | * |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | $this->players->db_load_player_by_id($player_id, UBE_PLAYER_IS_DEFENDER); |
148 | 148 | |
149 | 149 | $player_db_row = $this->players[$player_id]->getDbRow(); |
150 | - if($fortifier_level = mrc_get_level($player_db_row, $this->combatMission->dst_planet, MRC_FORTIFIER)) { |
|
150 | + if ($fortifier_level = mrc_get_level($player_db_row, $this->combatMission->dst_planet, MRC_FORTIFIER)) { |
|
151 | 151 | $this->planet_bonus->add_unit_by_snid(MRC_FORTIFIER, $fortifier_level); |
152 | 152 | } |
153 | 153 | |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | $this->rounds[0] = new UBERound(0); |
180 | 180 | $this->rounds[0]->make_snapshot($this->fleet_list); |
181 | 181 | |
182 | - for($round = 1; $round <= 10; $round++) { |
|
182 | + for ($round = 1; $round <= 10; $round++) { |
|
183 | 183 | // Проводим раунд |
184 | 184 | defined('DEBUG_UBE') ? print("Round {$round}<br>") : false; |
185 | 185 | |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | |
193 | 193 | // Анализируем итоги текущего раунда и готовим данные для следующего |
194 | 194 | $this->combat_result = $this->fleet_list->ubeAnalyzeFleetOutcome($round); |
195 | - if($this->combat_result != UBE_COMBAT_RESULT_DRAW) { |
|
195 | + if ($this->combat_result != UBE_COMBAT_RESULT_DRAW) { |
|
196 | 196 | break; |
197 | 197 | } |
198 | 198 | |
@@ -221,11 +221,11 @@ discard block |
||
221 | 221 | // Генерируем результат боя |
222 | 222 | $this->fleet_list->ube_analyze_fleets($this->is_simulator, $this->debris, $this->resource_exchange_rates); |
223 | 223 | |
224 | - if(!$this->is_ube_loaded) { |
|
224 | + if (!$this->is_ube_loaded) { |
|
225 | 225 | $this->moon_calculator->calculate_moon($this); |
226 | 226 | |
227 | 227 | // Лутаем ресурсы - если аттакер выиграл |
228 | - if($this->combat_result == UBE_COMBAT_RESULT_WIN) { |
|
228 | + if ($this->combat_result == UBE_COMBAT_RESULT_WIN) { |
|
229 | 229 | $this->sn_ube_combat_analyze_loot(); |
230 | 230 | } |
231 | 231 | } |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | RES_DEUTERIUM => 0, |
246 | 246 | ); |
247 | 247 | |
248 | - if( |
|
248 | + if ( |
|
249 | 249 | (($planet_resource_total = $this->fleet_list[0]->get_resources_amount()) > 0) |
250 | 250 | && |
251 | 251 | (($total_capacity = $this->fleet_list->ube_get_capacity_attackers()) > 0) |
@@ -257,9 +257,9 @@ discard block |
||
257 | 257 | $planet_lootable_percent = $planet_lootable / $planet_resource_total; |
258 | 258 | |
259 | 259 | // Вычисляем сколько ресурсов вывезено |
260 | - foreach($this->fleet_list->_container as $fleet_id => $fleet) { |
|
260 | + foreach ($this->fleet_list->_container as $fleet_id => $fleet) { |
|
261 | 261 | $looted_in_metal = 0; |
262 | - foreach($this->fleet_list[0]->resource_list as $resource_id => $resource_amount) { |
|
262 | + foreach ($this->fleet_list[0]->resource_list as $resource_id => $resource_amount) { |
|
263 | 263 | // Вычисляем какой процент общей емкости трюмов атакующих будет задействован |
264 | 264 | $fleet_lootable_percent = $fleet->fleet_capacity / $total_capacity; |
265 | 265 | $looted = floor($resource_amount * $planet_lootable_percent * $fleet_lootable_percent); |
@@ -325,16 +325,16 @@ discard block |
||
325 | 325 | $destination_user_id = $this->fleet_list[0]->owner_id; |
326 | 326 | |
327 | 327 | // Обновляем поле обломков на планете |
328 | - if(!$this->is_admin_in_combat && $this->debris->debris_total() > 0) { |
|
328 | + if (!$this->is_admin_in_combat && $this->debris->debris_total() > 0) { |
|
329 | 329 | db_planet_set_by_gspt($this->ube_planet_info[PLANET_GALAXY], $this->ube_planet_info[PLANET_SYSTEM], $this->ube_planet_info[PLANET_PLANET], PT_PLANET, |
330 | - "`debris_metal` = `debris_metal` + " . $this->debris->debris_get_resource(RES_METAL) . ", `debris_crystal` = `debris_crystal` + " . $this->debris->debris_get_resource(RES_CRYSTAL) |
|
330 | + "`debris_metal` = `debris_metal` + ".$this->debris->debris_get_resource(RES_METAL).", `debris_crystal` = `debris_crystal` + ".$this->debris->debris_get_resource(RES_CRYSTAL) |
|
331 | 331 | ); |
332 | 332 | } |
333 | 333 | |
334 | - foreach($this->fleet_list->_container as $fleet_id => $UBEFleet) { |
|
334 | + foreach ($this->fleet_list->_container as $fleet_id => $UBEFleet) { |
|
335 | 335 | $ship_count_lost = $UBEFleet->unit_list->unitCountLost(); |
336 | 336 | |
337 | - if($fleet_id) { |
|
337 | + if ($fleet_id) { |
|
338 | 338 | // Флот |
339 | 339 | $UBEFleet->db_save_combat_result_fleet($this->is_small_fleet_recce, $this->moon_calculator->get_reapers_status()); |
340 | 340 | } else { |
@@ -342,19 +342,19 @@ discard block |
||
342 | 342 | |
343 | 343 | // Сохраняем изменения ресурсов - если они есть |
344 | 344 | $resource_delta = $UBEFleet->ube_combat_result_calculate_resources(); |
345 | - if(!empty($resource_delta)) { |
|
345 | + if (!empty($resource_delta)) { |
|
346 | 346 | $temp = array(); |
347 | - foreach($resource_delta as $resource_id => $resource_amount) { |
|
347 | + foreach ($resource_delta as $resource_id => $resource_amount) { |
|
348 | 348 | $resource_db_name = pname_resource_name($resource_id); |
349 | 349 | $temp[] = "`{$resource_db_name}` = `{$resource_db_name}` + ({$resource_amount})"; |
350 | 350 | } |
351 | 351 | db_planet_set_by_id($this->ube_planet_info[PLANET_ID], implode(',', $temp)); |
352 | 352 | } |
353 | 353 | |
354 | - if($ship_count_lost) { |
|
354 | + if ($ship_count_lost) { |
|
355 | 355 | $db_changeset = array(); |
356 | 356 | $planet_row_cache = $this->players[$destination_user_id]->getDbRow(); |
357 | - foreach($UBEFleet->unit_list->_container as $UBEUnit) { |
|
357 | + foreach ($UBEFleet->unit_list->_container as $UBEUnit) { |
|
358 | 358 | $db_changeset['unit'][] = sn_db_unit_changeset_prepare($UBEUnit->unitId, -$UBEUnit->units_lost, $planet_row_cache, $this->ube_planet_info[PLANET_ID]); |
359 | 359 | } |
360 | 360 | db_changeset_apply($db_changeset); |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | // TODO: Связать сабы с флотами констраинтами ON DELETE SET NULL |
366 | 366 | // Для САБов |
367 | 367 | $fleet_group_id_list = $this->fleet_list->ube_get_groups(); |
368 | - if(!empty($fleet_group_id_list)) { |
|
368 | + if (!empty($fleet_group_id_list)) { |
|
369 | 369 | $fleet_group_id_list = implode(',', $fleet_group_id_list); |
370 | 370 | db_acs_delete_by_list($fleet_group_id_list); |
371 | 371 | } |
@@ -374,19 +374,19 @@ discard block |
||
374 | 374 | |
375 | 375 | $bashing_list = array(); |
376 | 376 | $players_sides = $this->players->get_player_sides(); |
377 | - foreach($players_sides as $player_id => $player_side) { |
|
378 | - if($player_side != UBE_PLAYER_IS_ATTACKER) { |
|
377 | + foreach ($players_sides as $player_id => $player_side) { |
|
378 | + if ($player_side != UBE_PLAYER_IS_ATTACKER) { |
|
379 | 379 | continue; |
380 | 380 | } |
381 | - if($this->moon_calculator->get_status() != UBE_MOON_DESTROY_SUCCESS) { |
|
381 | + if ($this->moon_calculator->get_status() != UBE_MOON_DESTROY_SUCCESS) { |
|
382 | 382 | $bashing_list[] = "({$player_id}, {$this->ube_planet_info[PLANET_ID]}, {$this->combat_timestamp})"; |
383 | 383 | } |
384 | - if($this->mission_type_id == MT_ATTACK && $this->is_defender_active_player) { |
|
384 | + if ($this->mission_type_id == MT_ATTACK && $this->is_defender_active_player) { |
|
385 | 385 | $str_loose_or_win = $this->combat_result == UBE_COMBAT_RESULT_WIN ? 'raidswin' : 'raidsloose'; |
386 | 386 | db_user_set_by_id($player_id, "`xpraid` = `xpraid` + 1, `raids` = `raids` + 1, `{$str_loose_or_win}` = `{$str_loose_or_win}` + 1"); |
387 | 387 | } |
388 | 388 | } |
389 | - if(!empty($bashing_list)) { |
|
389 | + if (!empty($bashing_list)) { |
|
390 | 390 | $bashing_list = implode(',', $bashing_list); |
391 | 391 | db_bashing_insert($bashing_list); |
392 | 392 | } |
@@ -413,20 +413,19 @@ discard block |
||
413 | 413 | $planet_info[PLANET_SYSTEM], |
414 | 414 | $planet_info[PLANET_PLANET], |
415 | 415 | htmlentities($planet_info[PLANET_NAME], ENT_COMPAT, 'UTF-8'), |
416 | - classLocale::$lang[$this->combat_result == UBE_COMBAT_RESULT_WIN ? 'ube_report_info_outcome_win' : |
|
417 | - ($this->combat_result == UBE_COMBAT_RESULT_DRAW ? 'ube_report_info_outcome_draw' : 'ube_report_info_outcome_loss')] |
|
416 | + classLocale::$lang[$this->combat_result == UBE_COMBAT_RESULT_WIN ? 'ube_report_info_outcome_win' : ($this->combat_result == UBE_COMBAT_RESULT_DRAW ? 'ube_report_info_outcome_draw' : 'ube_report_info_outcome_loss')] |
|
418 | 417 | ); |
419 | 418 | |
420 | 419 | $text_defender = ''; |
421 | 420 | $debris = $this->debris->get_debris(); |
422 | - foreach($debris as $resource_id => $resource_amount) { |
|
423 | - if($resource_id == RES_DEUTERIUM) { |
|
421 | + foreach ($debris as $resource_id => $resource_amount) { |
|
422 | + if ($resource_id == RES_DEUTERIUM) { |
|
424 | 423 | continue; |
425 | 424 | } |
426 | 425 | |
427 | - $text_defender .= "{$classLocale['tech'][$resource_id]}: " . pretty_number($resource_amount) . '<br />'; |
|
426 | + $text_defender .= "{$classLocale['tech'][$resource_id]}: ".pretty_number($resource_amount).'<br />'; |
|
428 | 427 | } |
429 | - if($text_defender) { |
|
428 | + if ($text_defender) { |
|
430 | 429 | $text_defender = "{$classLocale['ube_report_msg_body_debris']}{$text_defender}<br />"; |
431 | 430 | } |
432 | 431 | |
@@ -436,8 +435,8 @@ discard block |
||
436 | 435 | |
437 | 436 | // TODO: Оптимизировать отсылку сообщений - отсылать пакетами |
438 | 437 | $player_sides = $this->players->get_player_sides(); |
439 | - foreach($player_sides as $player_id => $player_side) { |
|
440 | - $message = $text_common . ($this->is_small_fleet_recce && ($player_side == UBE_PLAYER_IS_ATTACKER) ? classLocale::$lang['ube_report_msg_body_sfr'] : $text_defender); |
|
438 | + foreach ($player_sides as $player_id => $player_side) { |
|
439 | + $message = $text_common.($this->is_small_fleet_recce && ($player_side == UBE_PLAYER_IS_ATTACKER) ? classLocale::$lang['ube_report_msg_body_sfr'] : $text_defender); |
|
441 | 440 | msg_send_simple_message($player_id, '', $this->combat_timestamp, MSG_TYPE_COMBAT, classLocale::$lang['sys_mess_tower'], classLocale::$lang['sys_mess_attack_report'], $message); |
442 | 441 | } |
443 | 442 | |
@@ -473,11 +472,11 @@ discard block |
||
473 | 472 | $player_id = $player_id == -1 ? $this->players->count() : $player_id; |
474 | 473 | $fleet_id = $player_id; // FOR SIMULATOR! |
475 | 474 | |
476 | - if(empty($this->players[$player_id])) { |
|
475 | + if (empty($this->players[$player_id])) { |
|
477 | 476 | $this->players[$player_id] = new UBEPlayer(); |
478 | 477 | } |
479 | 478 | |
480 | - foreach($side_info as $fleet_data) { |
|
479 | + foreach ($side_info as $fleet_data) { |
|
481 | 480 | $this->players[$player_id]->name = $player_id; |
482 | 481 | $this->players[$player_id]->setSide($attacker); |
483 | 482 | |
@@ -485,32 +484,32 @@ discard block |
||
485 | 484 | $this->fleet_list[$fleet_id] = $objFleet; |
486 | 485 | |
487 | 486 | $this->fleet_list[$fleet_id]->owner_id = $player_id; |
488 | - foreach($fleet_data as $unit_id => $unit_count) { |
|
489 | - if(!$unit_count) { |
|
487 | + foreach ($fleet_data as $unit_id => $unit_count) { |
|
488 | + if (!$unit_count) { |
|
490 | 489 | continue; |
491 | 490 | } |
492 | 491 | |
493 | 492 | $unit_type = get_unit_param($unit_id, P_UNIT_TYPE); |
494 | 493 | |
495 | - if($unit_type == UNIT_SHIPS || $unit_type == UNIT_DEFENCE) { |
|
494 | + if ($unit_type == UNIT_SHIPS || $unit_type == UNIT_DEFENCE) { |
|
496 | 495 | $this->fleet_list[$fleet_id]->unit_list->unitAdjustCount($unit_id, $unit_count); |
497 | - } elseif($unit_type == UNIT_RESOURCES) { |
|
496 | + } elseif ($unit_type == UNIT_RESOURCES) { |
|
498 | 497 | $this->fleet_list[$fleet_id]->resource_list[$unit_id] = $unit_count; |
499 | - } elseif($unit_type == UNIT_TECHNOLOGIES) { |
|
500 | - if($unit_id == TECH_WEAPON) { |
|
498 | + } elseif ($unit_type == UNIT_TECHNOLOGIES) { |
|
499 | + if ($unit_id == TECH_WEAPON) { |
|
501 | 500 | $this->players[$player_id]->player_bonus->add_unit_by_snid(TECH_WEAPON, $unit_count); |
502 | - } elseif($unit_id == TECH_SHIELD) { |
|
501 | + } elseif ($unit_id == TECH_SHIELD) { |
|
503 | 502 | $this->players[$player_id]->player_bonus->add_unit_by_snid(TECH_SHIELD, $unit_count); |
504 | - } elseif($unit_id == TECH_ARMOR) { |
|
503 | + } elseif ($unit_id == TECH_ARMOR) { |
|
505 | 504 | $this->players[$player_id]->player_bonus->add_unit_by_snid(TECH_ARMOR, $unit_count); |
506 | 505 | } |
507 | - } elseif($unit_type == UNIT_GOVERNORS) { |
|
508 | - if($unit_id == MRC_FORTIFIER) { |
|
506 | + } elseif ($unit_type == UNIT_GOVERNORS) { |
|
507 | + if ($unit_id == MRC_FORTIFIER) { |
|
509 | 508 | // Фортифаер даёт бонус ко всему |
510 | 509 | $this->planet_bonus->add_unit_by_snid(MRC_FORTIFIER, $unit_count); |
511 | 510 | } |
512 | - } elseif($unit_type == UNIT_MERCENARIES) { |
|
513 | - if($unit_id == MRC_ADMIRAL) { |
|
511 | + } elseif ($unit_type == UNIT_MERCENARIES) { |
|
512 | + if ($unit_id == MRC_ADMIRAL) { |
|
514 | 513 | $this->players[$player_id]->player_bonus->add_unit_by_snid(MRC_ADMIRAL, $unit_count); |
515 | 514 | } |
516 | 515 | } |
@@ -565,7 +564,7 @@ discard block |
||
565 | 564 | |
566 | 565 | $ube->sn_ube_message_send(); |
567 | 566 | |
568 | - defined('DEBUG_UBE') ? die('DIE at ' . __FILE__ . ' ' . __LINE__) : false; |
|
567 | + defined('DEBUG_UBE') ? die('DIE at '.__FILE__.' '.__LINE__) : false; |
|
569 | 568 | |
570 | 569 | return false; |
571 | 570 | } |
@@ -580,7 +579,7 @@ discard block |
||
580 | 579 | |
581 | 580 | $ube_report = new UBEReport(); |
582 | 581 | $ube = $ube_report->sn_ube_report_load(sys_get_param_str('cypher')); |
583 | - if($ube != UBE_REPORT_NOT_FOUND) { |
|
582 | + if ($ube != UBE_REPORT_NOT_FOUND) { |
|
584 | 583 | $ube_report->sn_ube_report_generate($ube, $template_result); |
585 | 584 | |
586 | 585 | $template = gettemplate('ube_combat_report', $template); |
@@ -608,9 +607,9 @@ discard block |
||
608 | 607 | $ube->sn_ube_combat(); |
609 | 608 | $ube_report = new UBEReport(); |
610 | 609 | |
611 | - if(sys_get_param_str('reload')) { |
|
610 | + if (sys_get_param_str('reload')) { |
|
612 | 611 | $ube_new = $ube_report->sn_ube_report_load($ube->get_cypher()); // $combat_data = sn_ube_report_load($combat_data[UBE_REPORT_CYPHER]); |
613 | - if($ube_new != UBE_REPORT_NOT_FOUND && is_object($ube_new)) { |
|
612 | + if ($ube_new != UBE_REPORT_NOT_FOUND && is_object($ube_new)) { |
|
614 | 613 | $ube = $ube_new; |
615 | 614 | } |
616 | 615 | } |
@@ -658,7 +657,7 @@ discard block |
||
658 | 657 | $this->debris->load_from_report_row($report_row); |
659 | 658 | |
660 | 659 | $query = doquery("SELECT * FROM {{ube_report_player}} WHERE `ube_report_id` = {$report_row['ube_report_id']}"); |
661 | - while($player_row = db_fetch($query)) { |
|
660 | + while ($player_row = db_fetch($query)) { |
|
662 | 661 | $this->players->init_player_from_report_info($player_row); |
663 | 662 | } |
664 | 663 |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | * Преобразовывает данные симулятора в данные для расчета боя |
460 | 460 | * |
461 | 461 | * @param $side_info |
462 | - * @param $attacker |
|
462 | + * @param boolean $attacker |
|
463 | 463 | * @param int $player_id |
464 | 464 | * |
465 | 465 | */ |
@@ -521,7 +521,7 @@ discard block |
||
521 | 521 | } |
522 | 522 | |
523 | 523 | /** |
524 | - * @return int |
|
524 | + * @return double |
|
525 | 525 | */ |
526 | 526 | public function get_time_spent() { |
527 | 527 | return $this->time_spent; |
@@ -564,7 +564,7 @@ discard block |
||
564 | 564 | } |
565 | 565 | |
566 | 566 | /** |
567 | - * @param $template |
|
567 | + * @param null|template $template |
|
568 | 568 | * |
569 | 569 | * @return template |
570 | 570 | */ |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * @version 41a6.49 |
12 | 12 | */ |
13 | 13 | public static function unit_dump_header() { |
14 | - if(!defined('DEBUG_UBE')) { |
|
14 | + if (!defined('DEBUG_UBE')) { |
|
15 | 15 | return; |
16 | 16 | } |
17 | 17 | |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @version 41a6.49 |
49 | 49 | */ |
50 | 50 | public static function unit_dump(UBEUnit $unit, $desc = '', UBEUnit $before = null) { |
51 | - if(!defined('DEBUG_UBE')) { |
|
51 | + if (!defined('DEBUG_UBE')) { |
|
52 | 52 | return; |
53 | 53 | } |
54 | 54 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | // print("<td>" . $this->units_lost . "</td>"); |
76 | 76 | // print("<td>" . $this->units_restored . "</td>"); |
77 | 77 | // print("<td>" . $this->capacity . "</td>"); |
78 | - print("<td>" . round($unit->share_of_side_armor, 4) . "</td>"); |
|
78 | + print("<td>".round($unit->share_of_side_armor, 4)."</td>"); |
|
79 | 79 | print('</tr>'); |
80 | 80 | } |
81 | 81 | |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * @version 41a6.49 |
87 | 87 | */ |
88 | 88 | public static function unit_dump_footer() { |
89 | - if(!defined('DEBUG_UBE')) { |
|
89 | + if (!defined('DEBUG_UBE')) { |
|
90 | 90 | return; |
91 | 91 | } |
92 | 92 | |
@@ -101,16 +101,16 @@ discard block |
||
101 | 101 | * @return UBEUnit |
102 | 102 | */ |
103 | 103 | public static function unit_dump_defender(UBEUnit $attacking_unit_pool, UBEUnit $defending_unit_pool, $defending_fleet_id) { |
104 | - if(!defined('DEBUG_UBE')) { |
|
104 | + if (!defined('DEBUG_UBE')) { |
|
105 | 105 | return null; |
106 | 106 | } |
107 | 107 | |
108 | 108 | $classLocale = classLocale::$lang; |
109 | 109 | |
110 | - print("[{$attacking_unit_pool->unitId}]{$classLocale['tech'][$attacking_unit_pool->unitId]}" . |
|
111 | - ' attacks ' . |
|
112 | - $defending_fleet_id . '@' . "[{$defending_unit_pool->unitId}]{$classLocale['tech'][$defending_unit_pool->unitId]}" . |
|
113 | - ' with ' . pretty_number($defending_unit_pool->attack_income) . |
|
110 | + print("[{$attacking_unit_pool->unitId}]{$classLocale['tech'][$attacking_unit_pool->unitId]}". |
|
111 | + ' attacks '. |
|
112 | + $defending_fleet_id.'@'."[{$defending_unit_pool->unitId}]{$classLocale['tech'][$defending_unit_pool->unitId]}". |
|
113 | + ' with '.pretty_number($defending_unit_pool->attack_income). |
|
114 | 114 | '<br>' |
115 | 115 | ); |
116 | 116 | $before = clone $defending_unit_pool; |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | * @version 41a6.49 |
128 | 128 | */ |
129 | 129 | public static function unit_dump_delta(UBEUnit $unit, $field, UBEUnit $before = null) { |
130 | - if(!defined('DEBUG_UBE')) { |
|
130 | + if (!defined('DEBUG_UBE')) { |
|
131 | 131 | return; |
132 | 132 | } |
133 | 133 | |
@@ -136,8 +136,8 @@ discard block |
||
136 | 136 | print(pretty_number($unit->$field)); |
137 | 137 | print("</td>"); |
138 | 138 | print("<td>"); |
139 | - if(!empty($before)) { |
|
140 | - print('' . pretty_number($unit->$field - $before->$field) . ''); |
|
139 | + if (!empty($before)) { |
|
140 | + print(''.pretty_number($unit->$field - $before->$field).''); |
|
141 | 141 | } |
142 | 142 | print("</td>"); |
143 | 143 | } |
@@ -52,7 +52,7 @@ |
||
52 | 52 | !mysql_select_db($settings['name']) |
53 | 53 | ? classSupernova::$debug->error_fatal('DB error - cannot find DB on server', $this->mysql_error()) |
54 | 54 | : false; |
55 | - !$this->mysql_query('SET SESSION TRANSACTION ISOLATION LEVEL ' . self::DB_MYSQL_TRANSACTION_REPEATABLE_READ . ';') |
|
55 | + !$this->mysql_query('SET SESSION TRANSACTION ISOLATION LEVEL '.self::DB_MYSQL_TRANSACTION_REPEATABLE_READ.';') |
|
56 | 56 | ? classSupernova::$debug->error_fatal('DB error - cannot set desired isolation level', $this->mysql_error()) |
57 | 57 | : false; |
58 | 58 |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | public static function _init($group_name = '') { |
27 | 27 | parent::_init($group_name); |
28 | 28 | |
29 | - foreach(static::$_group_unit_id_list as $resource_id) { |
|
29 | + foreach (static::$_group_unit_id_list as $resource_id) { |
|
30 | 30 | static::$_group_pnames[$resource_id] = pname_resource_name($resource_id); |
31 | 31 | } |
32 | 32 | |
@@ -48,13 +48,13 @@ discard block |
||
48 | 48 | |
49 | 49 | !is_array($resource_array) ? $resource_array = array() : false; |
50 | 50 | |
51 | - foreach($resource_array as $resource_id => $resource_actual_delta) { |
|
52 | - if(!$resource_actual_delta) { |
|
51 | + foreach ($resource_array as $resource_id => $resource_actual_delta) { |
|
52 | + if (!$resource_actual_delta) { |
|
53 | 53 | // No delta - no changes |
54 | 54 | continue; |
55 | 55 | } |
56 | 56 | |
57 | - $result[$prefix . static::$_group_pnames[$resource_id]] = $resource_actual_delta; |
|
57 | + $result[$prefix.static::$_group_pnames[$resource_id]] = $resource_actual_delta; |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | return $result; |
@@ -39,19 +39,19 @@ |
||
39 | 39 | |
40 | 40 | @$this->link = mysqli_connect($settings['server'], $settings['user'], $settings['pass'], $settings['name']); |
41 | 41 | if (!is_object($this->link) || $this->link->connect_error) { |
42 | - classSupernova::$debug->error_fatal('DB Error - cannot connect to server error #' . $this->link->connect_errno, $this->link->connect_error); |
|
42 | + classSupernova::$debug->error_fatal('DB Error - cannot connect to server error #'.$this->link->connect_errno, $this->link->connect_error); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | |
46 | 46 | !$this->mysql_query("/*!40101 SET NAMES 'utf8' */") |
47 | - ? classSupernova::$debug->error_fatal('DB error - cannot set names 1 error #' . $this->link->errno, $this->link->error) |
|
47 | + ? classSupernova::$debug->error_fatal('DB error - cannot set names 1 error #'.$this->link->errno, $this->link->error) |
|
48 | 48 | : false; |
49 | 49 | !$this->mysql_query("SET NAMES 'utf8';") |
50 | - ? classSupernova::$debug->error_fatal('DB error - cannot set names 2 error #' . $this->link->errno, $this->link->error) |
|
50 | + ? classSupernova::$debug->error_fatal('DB error - cannot set names 2 error #'.$this->link->errno, $this->link->error) |
|
51 | 51 | : false; |
52 | 52 | |
53 | - !$this->mysql_query('SET SESSION TRANSACTION ISOLATION LEVEL ' . self::DB_MYSQL_TRANSACTION_REPEATABLE_READ . ';') |
|
54 | - ? classSupernova::$debug->error_fatal('DB error - cannot set desired isolation level error #' . $this->link->errno, $this->link->error) |
|
53 | + !$this->mysql_query('SET SESSION TRANSACTION ISOLATION LEVEL '.self::DB_MYSQL_TRANSACTION_REPEATABLE_READ.';') |
|
54 | + ? classSupernova::$debug->error_fatal('DB error - cannot set desired isolation level error #'.$this->link->errno, $this->link->error) |
|
55 | 55 | : false; |
56 | 56 | |
57 | 57 | $this->connected = true; |
@@ -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 | } |
@@ -88,10 +88,10 @@ discard block |
||
88 | 88 | $account_translation = array(); |
89 | 89 | |
90 | 90 | $query = static::$db->doquery( |
91 | - "SELECT * FROM {{account_translate}} WHERE `user_id` = {$user_id_safe} " . |
|
92 | - ($provider_id_unsafe ? "AND `provider_id` = {$provider_id_safe} " : '') . |
|
91 | + "SELECT * FROM {{account_translate}} WHERE `user_id` = {$user_id_safe} ". |
|
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 |
@@ -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 $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 | classSupernova::$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 { |
@@ -383,17 +383,17 @@ discard block |
||
383 | 383 | $result = $this->db->doquery( |
384 | 384 | "UPDATE {{account}} |
385 | 385 | SET |
386 | - `account_metamatter` = `account_metamatter` + '{$metamatter}'" . |
|
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}'" : '') . |
|
386 | + `account_metamatter` = `account_metamatter` + '{$metamatter}'". |
|
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 | classSupernova::$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 | classSupernova::$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 | } |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | * Инициализация харнилища скинов |
153 | 153 | */ |
154 | 154 | protected static function init() { |
155 | - if(static::$is_init) { |
|
155 | + if (static::$is_init) { |
|
156 | 156 | return; |
157 | 157 | } |
158 | 158 | |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | |
166 | 166 | // Загружены ли уже данные по текущему скину? |
167 | 167 | //pdump(static::$skin_list[$ini_path], 'static'); |
168 | - if(empty(static::$skin_list[$skin_path])) { |
|
168 | + if (empty(static::$skin_list[$skin_path])) { |
|
169 | 169 | // Прогружаем текущий скин |
170 | 170 | static::$skin_list[$skin_path] = new skin($skin_path); |
171 | 171 | static::$active = static::$skin_list[$skin_path]; |
@@ -191,9 +191,9 @@ discard block |
||
191 | 191 | strpos($skin_path, 'skins/') !== false ? $skin_path = substr($skin_path, 6) : false; |
192 | 192 | strpos($skin_path, '/') !== false ? $skin_path = str_replace('/', '', $skin_path) : false; |
193 | 193 | |
194 | - $this->root_http_relative = 'skins/' . $skin_path . '/'; // Пока стоит base="" в body SN_ROOT_VIRTUAL - не нужен |
|
194 | + $this->root_http_relative = 'skins/'.$skin_path.'/'; // Пока стоит base="" в body SN_ROOT_VIRTUAL - не нужен |
|
195 | 195 | // $this->root_http = SN_ROOT_VIRTUAL . 'skins/' . $skin_path . '/'; // Всегда абсолютный путь от корня сайта |
196 | - $this->root_physical_absolute = SN_ROOT_PHYSICAL . 'skins/' . $skin_path . '/'; |
|
196 | + $this->root_physical_absolute = SN_ROOT_PHYSICAL.'skins/'.$skin_path.'/'; |
|
197 | 197 | $this->name = $skin_path; |
198 | 198 | // pdump($this->root_folder); |
199 | 199 | // Искать скин среди пользовательских - когда будет конструктор скинов |
@@ -201,22 +201,22 @@ discard block |
||
201 | 201 | |
202 | 202 | $this->is_ini_present = false; |
203 | 203 | // Проверка на корректность и существование пути |
204 | - if(is_file($this->root_physical_absolute . 'skin.ini')) { |
|
204 | + if (is_file($this->root_physical_absolute.'skin.ini')) { |
|
205 | 205 | // Пытаемся распарсить файл |
206 | 206 | |
207 | 207 | // По секциям? images и config? Что бы не копировать конфигурацию? Или просто unset(__inherit) а затем заново записать |
208 | - $this->config = parse_ini_file($this->root_physical_absolute . 'skin.ini'); |
|
209 | - if(!empty($this->config)) { |
|
208 | + $this->config = parse_ini_file($this->root_physical_absolute.'skin.ini'); |
|
209 | + if (!empty($this->config)) { |
|
210 | 210 | |
211 | 211 | $this->is_ini_present = true; |
212 | 212 | |
213 | - if(!empty($this->config['_inherit'])) { |
|
213 | + if (!empty($this->config['_inherit'])) { |
|
214 | 214 | // Если скин наследует себя... |
215 | - if($this->config['_inherit'] == $skin_path) { |
|
215 | + if ($this->config['_inherit'] == $skin_path) { |
|
216 | 216 | // TODO - определять более сложные случаи циклических ссылок в _inherit |
217 | 217 | die('">circular skin inheritance!'); |
218 | 218 | } |
219 | - if(empty(static::$skin_list[$this->config['_inherit']])) { |
|
219 | + if (empty(static::$skin_list[$this->config['_inherit']])) { |
|
220 | 220 | static::$skin_list[$this->config['_inherit']] = new skin($this->config['_inherit']); |
221 | 221 | } |
222 | 222 | $this->parent = static::$skin_list[$this->config['_inherit']]; |
@@ -232,15 +232,15 @@ discard block |
||
232 | 232 | } |
233 | 233 | |
234 | 234 | // Пытаемся скомпилировать _no_image заранее |
235 | - if(!empty($this->config[SKIN_IMAGE_MISSED_FIELD])) { |
|
235 | + if (!empty($this->config[SKIN_IMAGE_MISSED_FIELD])) { |
|
236 | 236 | $this->container[SKIN_IMAGE_MISSED_FIELD] = $this->compile_try_path(SKIN_IMAGE_MISSED_FIELD, $this->config[SKIN_IMAGE_MISSED_FIELD]); |
237 | 237 | } |
238 | 238 | |
239 | 239 | // Если нет заглушки |
240 | - if(empty($this->container[SKIN_IMAGE_MISSED_FIELD])) { |
|
240 | + if (empty($this->container[SKIN_IMAGE_MISSED_FIELD])) { |
|
241 | 241 | $this->container[SKIN_IMAGE_MISSED_FIELD] = empty($this->parent) |
242 | 242 | // Если нет парента - берем хардкод |
243 | - ? $this->container[SKIN_IMAGE_MISSED_FIELD] = SN_ROOT_VIRTUAL . SKIN_IMAGE_MISSED_FILE_PATH |
|
243 | + ? $this->container[SKIN_IMAGE_MISSED_FIELD] = SN_ROOT_VIRTUAL.SKIN_IMAGE_MISSED_FILE_PATH |
|
244 | 244 | // Если есть парент - берем у парента. У предков всегда всё есть |
245 | 245 | : $this->parent->compile_image(SKIN_IMAGE_MISSED_FIELD, null); |
246 | 246 | } |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | $image_tag = $this->image_tag_parse($image_tag, $template); |
268 | 268 | |
269 | 269 | // Проверяем наличие ключа RIT в хранилища. В нём не может быть несуществующих файлов по построению |
270 | - if(!empty($this->container[$image_tag[SKIN_IMAGE_TAG_RESOLVED]])) { |
|
270 | + if (!empty($this->container[$image_tag[SKIN_IMAGE_TAG_RESOLVED]])) { |
|
271 | 271 | return $this->container[$image_tag[SKIN_IMAGE_TAG_RESOLVED]]; |
272 | 272 | } |
273 | 273 | |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | // Нет - image ID не является путём к файлу. Пора обратиться к предкам за помощью... |
286 | 286 | // Пытаемся вытащить путь из родителя и применить к нему свои параметры |
287 | 287 | // Тащим по ID изображения, а не по ТЭГУ - мало ли что там делает с путём родитель и как преобразовывает его в строку? |
288 | - if(empty($this->container[$image_id]) && !empty($this->parent)) { |
|
288 | + if (empty($this->container[$image_id]) && !empty($this->parent)) { |
|
289 | 289 | $this->container[$image_id] = $this->parent->compile_image($image_id, $template); |
290 | 290 | |
291 | 291 | // Если у родителя нет картинки - он вернет пустую строку. Тогда нам надо использовать заглушку - свою или родительскую |
@@ -306,18 +306,18 @@ discard block |
||
306 | 306 | protected function image_tag_parse($image_tag, $template) { |
307 | 307 | $image_tag_ptl_resolved = $image_tag; |
308 | 308 | // Есть переменные из темплейта ? |
309 | - if(strpos($image_tag_ptl_resolved, '[') !== false && is_object($template)) { |
|
309 | + if (strpos($image_tag_ptl_resolved, '[') !== false && is_object($template)) { |
|
310 | 310 | // Что бы лишний раз не запускать регексп |
311 | 311 | // TODO - многоуровневые вложения ?! Надо ли и где их можно применить |
312 | 312 | preg_match_all('#(\[.+?\])#', $image_tag_ptl_resolved, $matches); |
313 | - foreach($matches[0] as &$match) { |
|
313 | + foreach ($matches[0] as &$match) { |
|
314 | 314 | $var_name = str_replace(array('[', ']'), '', $match); |
315 | - if(strpos($var_name, '.') !== false) { |
|
315 | + if (strpos($var_name, '.') !== false) { |
|
316 | 316 | // Вложенная переменная темплейта - на текущем уровне |
317 | 317 | // TODO Вложенная переменная из корня через "!" |
318 | 318 | list($block_name, $block_var) = explode('.', $var_name); |
319 | 319 | isset($template->_block_value[$block_name][$block_var]) ? $image_tag_ptl_resolved = str_replace($match, $template->_block_value[$block_name][$block_var], $image_tag_ptl_resolved) : false; |
320 | - } elseif(strpos($var_name, '$') !== false) { |
|
320 | + } elseif (strpos($var_name, '$') !== false) { |
|
321 | 321 | // Корневой DEFINE |
322 | 322 | $define_name = substr($var_name, 1); |
323 | 323 | isset($template->_tpldata['DEFINE']['.'][$define_name]) ? $image_tag_ptl_resolved = str_replace($match, $template->_tpldata['DEFINE']['.'][$define_name], $image_tag_ptl_resolved) : false; |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | } |
329 | 329 | } |
330 | 330 | |
331 | - if(strpos($image_tag_ptl_resolved, '|') !== false) { |
|
331 | + if (strpos($image_tag_ptl_resolved, '|') !== false) { |
|
332 | 332 | $params = explode('|', $image_tag_ptl_resolved); |
333 | 333 | $image_id = $params[0]; |
334 | 334 | unset($params[0]); |
@@ -358,9 +358,9 @@ discard block |
||
358 | 358 | protected function compile_try_path($image_id, $file_path) { |
359 | 359 | // Если первый символ пути '/' - значит это путь от HTTP-корня |
360 | 360 | // Откусываем его и пользуем остальное |
361 | - $relative_path = strpos($file_path, '/') !== 0 ? $this->root_http_relative . $file_path : substr($file_path, 1); |
|
361 | + $relative_path = strpos($file_path, '/') !== 0 ? $this->root_http_relative.$file_path : substr($file_path, 1); |
|
362 | 362 | |
363 | - return is_file(SN_ROOT_PHYSICAL . $relative_path) ? $this->container[$image_id] = SN_ROOT_VIRTUAL . $relative_path : ''; |
|
363 | + return is_file(SN_ROOT_PHYSICAL.$relative_path) ? $this->container[$image_id] = SN_ROOT_VIRTUAL.$relative_path : ''; |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | |
@@ -392,13 +392,13 @@ discard block |
||
392 | 392 | $image_string = $this->container[$image_tag]; |
393 | 393 | |
394 | 394 | // Нет параметров - просто возвращаем значение по $image_name из контейнера |
395 | - if(!empty($params) && is_array($params)) { |
|
395 | + if (!empty($params) && is_array($params)) { |
|
396 | 396 | // Здесь автоматически произойдёт упорядочивание параметров |
397 | 397 | |
398 | 398 | // Параметр 'html' - выводить изображение в виде HTML-тэга |
399 | - if(in_array('html', $params)) { |
|
400 | - $image_tag = $image_tag . '|html'; |
|
401 | - $image_string = '<img src="' . $image_string . '" />'; |
|
399 | + if (in_array('html', $params)) { |
|
400 | + $image_tag = $image_tag.'|html'; |
|
401 | + $image_string = '<img src="'.$image_string.'" />'; |
|
402 | 402 | $this->container[$image_tag] = $image_string; |
403 | 403 | } |
404 | 404 | } |