Completed
Push — work-fleets ( 6257a1...22b5bc )
by SuperNova.WS
06:47
created
includes/classes/V2PropertyContainer.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
     if (is_callable($callable)) {
53 53
       $this->accessors[$type][$varName] = $callable;
54 54
     } else {
55
-      throw new Exception('Error assigning callable in ' . get_called_class() . '! Callable typed [' . $type . '] is not a callable or not accessible in the scope');
55
+      throw new Exception('Error assigning callable in '.get_called_class().'! Callable typed ['.$type.'] is not a callable or not accessible in the scope');
56 56
     }
57 57
   }
58 58
 
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
   }
74 74
 
75 75
   public function importRow($row) {
76
-    if(empty($row)) {
76
+    if (empty($row)) {
77 77
       return;
78 78
     }
79 79
 
Please login to merge, or discard this patch.
includes/classes/V2Unit/V2UnitModel.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -78,12 +78,12 @@  discard block
 block discarded – undo
78 78
     $that = $this;
79 79
 
80 80
     $this->_container->assignAccessor('type', P_CONTAINER_GETTER,
81
-      function () use ($that) {
81
+      function() use ($that) {
82 82
         return $that->type;
83 83
       }
84 84
     );
85 85
     $this->_container->assignAccessor('type', P_CONTAINER_SETTER,
86
-      function ($value) use ($that) {
86
+      function($value) use ($that) {
87 87
         $that->type = $value;
88 88
         $array = get_unit_param($value);
89 89
         $that->unitInfo = $array;
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
     $propertyName = 'timeStart';
100 100
     $fieldName = self::$_properties[$propertyName][P_DB_FIELD];
101 101
     $this->_container->assignAccessor($propertyName, P_CONTAINER_IMPORTER,
102
-      function (&$row) use ($that, $fieldName) {
102
+      function(&$row) use ($that, $fieldName) {
103 103
         if (isset($row[$fieldName])) {
104 104
           $dateTime = new \DateTime($row[$fieldName]);
105 105
         } else {
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
       }
110 110
     );
111 111
     $this->_container->assignAccessor($propertyName, P_CONTAINER_EXPORTER,
112
-      function (&$row) use ($that, $fieldName) {
112
+      function(&$row) use ($that, $fieldName) {
113 113
         $dateTime = $that->timeStart;
114 114
         if ($dateTime instanceof \DateTime) {
115 115
           $row[$fieldName] = $dateTime->format(FMT_DATE_TIME_SQL);
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
     $propertyName = 'timeFinish';
123 123
     $fieldName = self::$_properties[$propertyName][P_DB_FIELD];
124 124
     $this->_container->assignAccessor($propertyName, P_CONTAINER_IMPORTER,
125
-      function (&$row) use ($that, $fieldName) {
125
+      function(&$row) use ($that, $fieldName) {
126 126
         if (isset($row[$fieldName])) {
127 127
           $dateTime = new \DateTime($row[$fieldName]);
128 128
         } else {
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
       }
133 133
     );
134 134
     $this->_container->assignAccessor($propertyName, P_CONTAINER_EXPORTER,
135
-      function (&$row) use ($that, $fieldName) {
135
+      function(&$row) use ($that, $fieldName) {
136 136
         $dateTime = $that->timeFinish;
137 137
         if ($dateTime instanceof \DateTime) {
138 138
           $row[$fieldName] = $dateTime->format(FMT_DATE_TIME_SQL);
Please login to merge, or discard this patch.
includes/classes/Buddy/BuddyView.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -27,14 +27,14 @@
 block discarded – undo
27 27
     $cBuddy->new_request_text_unsafe = sys_get_param_str_unsafe('request_text');
28 28
     $cBuddy->playerArray = $user;
29 29
 
30
-    $cBuddy->playerId = function (BuddyRoutingParams $cBuddy) {
30
+    $cBuddy->playerId = function(BuddyRoutingParams $cBuddy) {
31 31
       return $cBuddy->playerArray['id'];
32 32
     };
33
-    $cBuddy->playerName = function (BuddyRoutingParams $cBuddy) {
33
+    $cBuddy->playerName = function(BuddyRoutingParams $cBuddy) {
34 34
       return $cBuddy->playerArray['username'];
35 35
     };
36
-    $cBuddy->playerNameAndCoordinates = function (BuddyRoutingParams $cBuddy) {
37
-      return "{$cBuddy->playerArray['username']} " . uni_render_coordinates($cBuddy->playerArray);
36
+    $cBuddy->playerNameAndCoordinates = function(BuddyRoutingParams $cBuddy) {
37
+      return "{$cBuddy->playerArray['username']} ".uni_render_coordinates($cBuddy->playerArray);
38 38
     };
39 39
 
40 40
     $result = array();
Please login to merge, or discard this patch.
includes/classes/DBStaticFleetMissile.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@
 block discarded – undo
23 23
    * @return array|bool|mysqli_result|null
24 24
    */
25 25
   public static function db_missile_list_by_arrival() {
26
-    $iraks = classSupernova::$db->doSelect("SELECT * FROM `{{iraks}}` WHERE `fleet_end_time` <= " . SN_TIME_NOW . " FOR UPDATE;");
26
+    $iraks = classSupernova::$db->doSelect("SELECT * FROM `{{iraks}}` WHERE `fleet_end_time` <= ".SN_TIME_NOW." FOR UPDATE;");
27 27
 
28 28
     return $iraks;
29 29
   }
Please login to merge, or discard this patch.
includes/functions/qst_quest.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
     $template->assign_vars($quest_templatized);
180 180
     if (!empty($quest_templatized['quest_rewards_list'])) {
181 181
       foreach ($quest_templatized['quest_rewards_list'] as $quest_reward) {
182
-        $template->assign_block_vars(($block_name ? $block_name . '.' : '') . 'quest_rewards_list', $quest_reward);
182
+        $template->assign_block_vars(($block_name ? $block_name.'.' : '').'quest_rewards_list', $quest_reward);
183 183
       }
184 184
     }
185 185
   }
@@ -248,10 +248,10 @@  discard block
 block discarded – undo
248 248
 
249 249
         $comment_reward = array();
250 250
         foreach ($reward_list as $unit_id => $unit_amount) {
251
-          $comment_reward[] = $unit_amount . ' ' . classLocale::$lang['tech'][$unit_id];
251
+          $comment_reward[] = $unit_amount.' '.classLocale::$lang['tech'][$unit_id];
252 252
           $total_rewards[$user_id][$planet_id][$unit_id] += $unit_amount;
253 253
         }
254
-        $comment .= " {$classLocale['qst_msg_your_reward']} " . implode(',', $comment_reward);
254
+        $comment .= " {$classLocale['qst_msg_your_reward']} ".implode(',', $comment_reward);
255 255
 
256 256
         DBStaticMessages::msg_send_simple_message($user['id'], 0, SN_TIME_NOW, MSG_TYPE_ADMIN, classLocale::$lang['msg_from_admin'], classLocale::$lang['qst_msg_complete_subject'], $comment);
257 257
 
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 
290 290
         if (!empty($resourcesChange)) {
291 291
           $planet_id = $planet_id == 0 && isset($user_row['id_planet']) ? $user_row['id_planet'] : $planet_id;
292
-          if($planet_id) {
292
+          if ($planet_id) {
293 293
             // update planet
294 294
             DBStaticPlanet::db_planet_update_resources($resourcesChange, $planet_id);
295 295
           } else {
Please login to merge, or discard this patch.
includes/functions/eco_queue.php 1 patch
Spacing   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -2,8 +2,8 @@  discard block
 block discarded – undo
2 2
 
3 3
 function que_get_unit_que($unit_id) {
4 4
   $que_type = false;
5
-  foreach(sn_get_groups('ques') as $que_id => $que_data) {
6
-    if(in_array($unit_id, $que_data['unit_list'])) {
5
+  foreach (sn_get_groups('ques') as $que_id => $que_data) {
6
+    if (in_array($unit_id, $que_data['unit_list'])) {
7 7
       $que_type = $que_id;
8 8
       break;
9 9
     }
@@ -14,14 +14,14 @@  discard block
 block discarded – undo
14 14
 
15 15
 
16 16
 function que_get_max_que_length($user, $planet, $que_id, $que_data = null) {
17
-  if(empty($que_data)) {
17
+  if (empty($que_data)) {
18 18
     $que_data = sn_get_groups('ques');
19 19
     $que_data = $que_data[$que_id];
20 20
   }
21 21
 
22 22
 
23 23
   $que_length = 1;
24
-  switch($que_id) {
24
+  switch ($que_id) {
25 25
     case QUE_RESEARCH:
26 26
       $que_length = classSupernova::$config->server_que_length_research + mrc_get_level($user, null, UNIT_PREMIUM); // TODO - вынести в модуль
27 27
     break;
@@ -35,8 +35,8 @@  discard block
 block discarded – undo
35 35
 
36 36
 function eco_que_str2arr($que_str) {
37 37
   $que_arr = explode(';', $que_str);
38
-  foreach($que_arr as $que_index => &$que_item) {
39
-    if($que_item) {
38
+  foreach ($que_arr as $que_index => &$que_item) {
39
+    if ($que_item) {
40 40
       $que_item = explode(',', $que_item);
41 41
     } else {
42 42
       unset($que_arr[$que_index]);
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 }
48 48
 
49 49
 function eco_que_arr2str($que_arr) {
50
-  foreach($que_arr as &$que_item) {
50
+  foreach ($que_arr as &$que_item) {
51 51
     $que_item = implode(',', $que_item);
52 52
   }
53 53
 
@@ -59,14 +59,14 @@  discard block
 block discarded – undo
59 59
   $classLocale = classLocale::$lang;
60 60
 
61 61
   $is_autoconvert = false;
62
-  if($build_mode == BUILD_AUTOCONVERT || sys_get_param_int('auto_convert')) {
62
+  if ($build_mode == BUILD_AUTOCONVERT || sys_get_param_int('auto_convert')) {
63 63
     $build_mode = BUILD_CREATE;
64 64
     $is_autoconvert = true;
65 65
   }
66 66
 
67 67
   $unit_amount_qued = 0;
68 68
   try {
69
-    if(!$user['id']) {
69
+    if (!$user['id']) {
70 70
       throw new exception('{Нет идентификатора пользователя - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION
71 71
     }
72 72
 
@@ -77,16 +77,16 @@  discard block
 block discarded – undo
77 77
       foreach($unit_list as $unit_id => $unit_amount) if($unit_amount) break;
78 78
     }
79 79
     */
80
-    if(!$unit_id) {
80
+    if (!$unit_id) {
81 81
       throw new exception('{Нет идентификатора юнита - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION
82 82
     }
83 83
 
84 84
     $que_id = que_get_unit_que($unit_id);
85
-    if(!$que_id) {
85
+    if (!$que_id) {
86 86
       throw new exception('{Неправильный тип очереди - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION
87 87
     }
88 88
 
89
-    if($build_mode == BUILD_DESTROY && $que_id != QUE_STRUCTURES) {
89
+    if ($build_mode == BUILD_DESTROY && $que_id != QUE_STRUCTURES) {
90 90
       throw new exception('{Уничтожать можно только здания на планете}', ERR_ERROR); // TODO EXCEPTION
91 91
     }
92 92
 
@@ -94,12 +94,12 @@  discard block
 block discarded – undo
94 94
     $que_data = $que_data[$que_id];
95 95
 
96 96
     // TODO Переделать под подочереди
97
-    if($que_id == QUE_STRUCTURES) {
97
+    if ($que_id == QUE_STRUCTURES) {
98 98
       $sn_groups_build_allow = sn_get_groups('build_allow');
99 99
       $que_data['unit_list'] = $sn_groups_build_allow[$planet['planet_type']];
100 100
 
101
-      if(!isset($que_data['unit_list'][$unit_id])) {
102
-        throw new exception('{Это здание нельзя строить на ' . ($planet['planet_type'] == PT_PLANET ? 'планете' : 'луне'), ERR_ERROR); // TODO EXCEPTION
101
+      if (!isset($que_data['unit_list'][$unit_id])) {
102
+        throw new exception('{Это здание нельзя строить на '.($planet['planet_type'] == PT_PLANET ? 'планете' : 'луне'), ERR_ERROR); // TODO EXCEPTION
103 103
       }
104 104
     }
105 105
     /*
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
     // Это нужно, что бы заблокировать пользователя и работу с очередями
120 120
     $user = DBStaticUser::db_user_by_id($user['id']);
121 121
     // Это нужно, что бы заблокировать планету от списания ресурсов
122
-    if(isset($planet['id']) && $planet['id']) {
122
+    if (isset($planet['id']) && $planet['id']) {
123 123
       $planet = DBStaticPlanet::db_planet_by_id($planet['id'], true);
124 124
     } else {
125 125
       $planet['id'] = 0;
@@ -131,12 +131,12 @@  discard block
 block discarded – undo
131 131
     $in_que = &$que['in_que'][$que_id][$user['id']][$planet_id];
132 132
     $que_max_length = que_get_max_que_length($user, $planet, $que_id, $que_data);
133 133
     // TODO Добавить вызовы функций проверок текущей и максимальной длин очередей
134
-    if(count($in_que) >= $que_max_length) {
134
+    if (count($in_que) >= $que_max_length) {
135 135
       throw new exception('{Все слоты очереди заняты}', ERR_ERROR); // TODO EXCEPTION
136 136
     }
137 137
 
138 138
     // TODO Отдельно посмотреть на уничтожение зданий - что бы можно было уничтожать их без планов
139
-    switch(eco_can_build_unit($user, $planet, $unit_id)) {
139
+    switch (eco_can_build_unit($user, $planet, $unit_id)) {
140 140
       case BUILD_ALLOWED:
141 141
       break;
142 142
       case BUILD_UNIT_BUSY:
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
       break; // TODO EXCEPTION eco_bld_msg_err_laboratory_upgrading
145 145
       // case BUILD_REQUIRE_NOT_MEET:
146 146
       default:
147
-        if($build_mode == BUILD_CREATE) {
147
+        if ($build_mode == BUILD_CREATE) {
148 148
           throw new exception('{Требования не удовлетворены}', ERR_ERROR);
149 149
         }
150 150
       break; // TODO EXCEPTION eco_bld_msg_err_requirements_not_meet
@@ -154,14 +154,14 @@  discard block
 block discarded – undo
154 154
     $unit_amount_qued = $unit_amount;
155 155
     $units_qued = isset($in_que[$unit_id]) ? $in_que[$unit_id] : 0;
156 156
     $unit_level = mrc_get_level($user, $planet, $unit_id, true, true) + $units_qued;
157
-    if($unit_max = get_unit_param($unit_id, P_MAX_STACK)) {
158
-      if($unit_level >= $unit_max) {
157
+    if ($unit_max = get_unit_param($unit_id, P_MAX_STACK)) {
158
+      if ($unit_level >= $unit_max) {
159 159
         throw new exception('{Максимальное количество юнитов данного типа уже достигнуто или будет достигнуто по окончанию очереди}', ERR_ERROR); // TODO EXCEPTION
160 160
       }
161 161
       $unit_amount = max(0, min($unit_amount, $unit_max - $unit_level));
162 162
     }
163 163
 
164
-    if($unit_amount < 1) {
164
+    if ($unit_amount < 1) {
165 165
       throw new exception('{Неправильное количество юнитов - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION
166 166
     }
167 167
 
@@ -170,21 +170,21 @@  discard block
 block discarded – undo
170 170
     //  {
171 171
     //    die('Unit busy'); // TODO EXCEPTION
172 172
     //  }
173
-    if(get_unit_param($unit_id, P_STACKABLE)) {
173
+    if (get_unit_param($unit_id, P_STACKABLE)) {
174 174
       // TODO Поле 'max_Lot_size' для ограничения размера стэка в очереди - то ли в юниты, то ли в очередь
175
-      if(in_array($unit_id, $group_missile = sn_get_groups(GROUP_STR_MISSILES))) {
175
+      if (in_array($unit_id, $group_missile = sn_get_groups(GROUP_STR_MISSILES))) {
176 176
         // TODO Поле 'container' - указывает на родительску структуру, в которой хранится данный юнит и по вместительности которой нужно применять размер юнита
177 177
         $used_silo = 0;
178
-        foreach($group_missile as $missile_id) {
178
+        foreach ($group_missile as $missile_id) {
179 179
           $missile_qued = isset($in_que[$missile_id]) ? $in_que[$missile_id] : 0;
180 180
           $used_silo += (mrc_get_level($user, $planet, $missile_id, true, true) + $missile_qued) * get_unit_param($missile_id, P_UNIT_SIZE);
181 181
         }
182 182
         $free_silo = mrc_get_level($user, $planet, STRUC_SILO) * get_unit_param(STRUC_SILO, P_CAPACITY) - $used_silo;
183
-        if($free_silo <= 0) {
183
+        if ($free_silo <= 0) {
184 184
           throw new exception('{Ракетная шахта уже заполнена или будет заполнена по окончанию очереди}', ERR_ERROR); // TODO EXCEPTION
185 185
         }
186 186
         $unit_size = get_unit_param($unit_id, P_UNIT_SIZE);
187
-        if($free_silo < $unit_size) {
187
+        if ($free_silo < $unit_size) {
188 188
           throw new exception("{В ракетной шахте нет места для {$classLocale['tech'][$unit_id]}}", ERR_ERROR); // TODO EXCEPTION
189 189
         }
190 190
         $unit_amount = max(0, min($unit_amount, floor($free_silo / $unit_size)));
@@ -192,10 +192,10 @@  discard block
 block discarded – undo
192 192
       $unit_level = $new_unit_level = 0;
193 193
     } else {
194 194
       $unit_amount = 1;
195
-      if($que_id == QUE_STRUCTURES) {
195
+      if ($que_id == QUE_STRUCTURES) {
196 196
         // if($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $que['sectors'][$planet['id']] <= 0)
197 197
         $sectors_qued = is_array($in_que) ? array_sum($in_que) : 0;
198
-        if($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $sectors_qued <= 0) {
198
+        if ($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $sectors_qued <= 0) {
199 199
           throw new exception('{Не хватает секторов на планете}', ERR_ERROR); // TODO EXCEPTION
200 200
         }
201 201
         // И что это я такое написал? Зачем?
@@ -212,10 +212,10 @@  discard block
 block discarded – undo
212 212
 
213 213
     $exchange = array();
214 214
     $market_get_autoconvert_cost = market_get_autoconvert_cost();
215
-    if($is_autoconvert && $build_data[BUILD_AUTOCONVERT]) {
215
+    if ($is_autoconvert && $build_data[BUILD_AUTOCONVERT]) {
216 216
       $dark_matter = mrc_get_level($user, null, RES_DARK_MATTER);
217
-      if(mrc_get_level($user, null, RES_DARK_MATTER) < $market_get_autoconvert_cost) {
218
-        throw new exception("{Нет хватает " . ($market_get_autoconvert_cost - $dark_matter) . "ТМ на постройки с автоконвертацией ресурсов}", ERR_ERROR); // TODO EXCEPTION
217
+      if (mrc_get_level($user, null, RES_DARK_MATTER) < $market_get_autoconvert_cost) {
218
+        throw new exception("{Нет хватает ".($market_get_autoconvert_cost - $dark_matter)."ТМ на постройки с автоконвертацией ресурсов}", ERR_ERROR); // TODO EXCEPTION
219 219
       }
220 220
 
221 221
       !get_unit_param($unit_id, P_STACKABLE) ? $unit_amount = 1 : false;
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
       $resource_exchange_rates = array();
225 225
       $resource_diff = array();
226 226
       $all_positive = true;
227
-      foreach($resources_loot as $resource_id) {
227
+      foreach ($resources_loot as $resource_id) {
228 228
         $resource_db_name = pname_resource_name($resource_id);
229 229
         $resource_got[$resource_id] = floor(mrc_get_level($user, $planet, $resource_id));
230 230
         $resource_exchange_rates[$resource_id] = classSupernova::$config->__get("rpg_exchange_{$resource_db_name}");
@@ -232,15 +232,15 @@  discard block
 block discarded – undo
232 232
         $all_positive = $all_positive && ($resource_diff[$resource_id] > 0);
233 233
       }
234 234
       // Нужна автоконвертация
235
-      if($all_positive) {
235
+      if ($all_positive) {
236 236
         $is_autoconvert = false;
237 237
       } else {
238
-        foreach($resource_diff as $resource_diff_id => &$resource_diff_amount) {
239
-          if($resource_diff_amount >= 0) {
238
+        foreach ($resource_diff as $resource_diff_id => &$resource_diff_amount) {
239
+          if ($resource_diff_amount >= 0) {
240 240
             continue;
241 241
           }
242
-          foreach($resource_diff as $resource_got_id => &$resource_got_amount) {
243
-            if($resource_got_amount <= 0) {
242
+          foreach ($resource_diff as $resource_got_id => &$resource_got_amount) {
243
+            if ($resource_got_amount <= 0) {
244 244
               continue;
245 245
             }
246 246
             $current_exchange = $resource_exchange_rates[$resource_got_id] / $resource_exchange_rates[$resource_diff_id];
@@ -256,14 +256,14 @@  discard block
 block discarded – undo
256 256
         }
257 257
 
258 258
         $is_autoconvert_ok = true;
259
-        foreach($resource_diff as $resource_diff_amount2) {
260
-          if($resource_diff_amount2 < 0) {
259
+        foreach ($resource_diff as $resource_diff_amount2) {
260
+          if ($resource_diff_amount2 < 0) {
261 261
             $is_autoconvert_ok = false;
262 262
             break;
263 263
           }
264 264
         }
265 265
 
266
-        if($is_autoconvert_ok) {
266
+        if ($is_autoconvert_ok) {
267 267
           $build_data['RESULT'][$build_mode] = BUILD_ALLOWED;
268 268
           $build_data['CAN'][$build_mode] = $unit_amount;
269 269
         } else {
@@ -272,19 +272,19 @@  discard block
 block discarded – undo
272 272
       }
273 273
     }
274 274
     $unit_amount = min($build_data['CAN'][$build_mode], $unit_amount);
275
-    if($unit_amount <= 0) {
275
+    if ($unit_amount <= 0) {
276 276
       throw new exception('{Не хватает ресурсов}', ERR_ERROR); // TODO EXCEPTION
277 277
     }
278 278
 
279
-    if($new_unit_level < 0) {
279
+    if ($new_unit_level < 0) {
280 280
       throw new exception('{Нельзя уничтожить больше юнитов, чем есть}', ERR_ERROR); // TODO EXCEPTION
281 281
     }
282 282
 
283
-    if($build_data['RESULT'][$build_mode] != BUILD_ALLOWED) {
283
+    if ($build_data['RESULT'][$build_mode] != BUILD_ALLOWED) {
284 284
       throw new exception('{Строительство блокировано}', ERR_ERROR); // TODO EXCEPTION
285 285
     }
286 286
 
287
-    if($is_autoconvert) {
287
+    if ($is_autoconvert) {
288 288
       ksort($exchange);
289 289
       ksort($resource_got);
290 290
       db_change_units($user, $planet, array(
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
     }
300 300
 
301 301
     $unit_amount_qued = 0;
302
-    while($unit_amount > 0 && count($que['ques'][$que_id][$user['id']][$planet_id]) < $que_max_length) {
302
+    while ($unit_amount > 0 && count($que['ques'][$que_id][$user['id']][$planet_id]) < $que_max_length) {
303 303
       $place = min($unit_amount, MAX_FLEET_OR_DEFS_PER_ROW);
304 304
       que_add_unit($unit_id, $user, $planet, $build_data, $new_unit_level, $place, $build_mode);
305 305
       $unit_amount -= $place;
@@ -309,8 +309,8 @@  discard block
 block discarded – undo
309 309
 
310 310
     sn_db_transaction_commit();
311 311
 
312
-    if($redirect) {
313
-      sys_redirect("{$_SERVER['PHP_SELF']}?mode=" . sys_get_param_str('mode') . "&ally_id=" . sys_get_param_id('ally_id'));
312
+    if ($redirect) {
313
+      sys_redirect("{$_SERVER['PHP_SELF']}?mode=".sys_get_param_str('mode')."&ally_id=".sys_get_param_id('ally_id'));
314 314
       die();
315 315
     }
316 316
 
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
       'STATUS'  => ERR_NONE,
319 319
       'MESSAGE' => '{Строительство начато}',
320 320
     );
321
-  } catch(exception $e) {
321
+  } catch (exception $e) {
322 322
     sn_db_transaction_rollback();
323 323
     $operation_result = array(
324 324
       'STATUS'  => in_array($e->getCode(), array(ERR_NONE, ERR_WARNING, ERR_ERROR)) ? $e->getCode() : ERR_ERROR,
@@ -326,8 +326,8 @@  discard block
 block discarded – undo
326 326
     );
327 327
   }
328 328
 
329
-  if(!empty($operation_result['MESSAGE'])) {
330
-    $operation_result['MESSAGE'] .= ' ' . ($unit_amount_qued ? $unit_amount_qued : $unit_amount) . 'x[' . classLocale::$lang['tech'][$unit_id] . ']';
329
+  if (!empty($operation_result['MESSAGE'])) {
330
+    $operation_result['MESSAGE'] .= ' '.($unit_amount_qued ? $unit_amount_qued : $unit_amount).'x['.classLocale::$lang['tech'][$unit_id].']';
331 331
   }
332 332
 
333 333
   return $operation_result;
@@ -337,11 +337,11 @@  discard block
 block discarded – undo
337 337
 function que_recalculate($old_que) {
338 338
   $new_que = array();
339 339
 
340
-  if(!is_array($old_que['items'])) {
340
+  if (!is_array($old_que['items'])) {
341 341
     return $new_que;
342 342
   }
343
-  foreach($old_que['items'] as $row) {
344
-    if(!isset($row) || !$row || $row['que_unit_amount'] <= 0) {
343
+  foreach ($old_que['items'] as $row) {
344
+    if (!isset($row) || !$row || $row['que_unit_amount'] <= 0) {
345 345
       continue;
346 346
     }
347 347
 
@@ -352,9 +352,9 @@  discard block
 block discarded – undo
352 352
 
353 353
     $last_id = count($new_que['items']) - 1;
354 354
 
355
-    if($row['que_planet_id']) {
355
+    if ($row['que_planet_id']) {
356 356
       $new_que['planets'][$row['que_planet_id']][$row['que_type']][] = &$new_que['items'][$last_id];
357
-    } elseif($row['que_type'] == QUE_RESEARCH) {
357
+    } elseif ($row['que_type'] == QUE_RESEARCH) {
358 358
       $new_que['players'][$row['que_player_id']][$row['que_type']][] = &$new_que['items'][$last_id];
359 359
     }
360 360
     $new_que['ques'][$row['que_type']][$row['que_player_id']][intval($row['que_planet_id'])][] = &$new_que['items'][$last_id];
@@ -389,9 +389,9 @@  discard block
 block discarded – undo
389 389
   $que_type = que_get_unit_que($unit_id);
390 390
   $planet_id_origin = $planet['id'] ? $planet['id'] : 'NULL';
391 391
   $planet_id = $que_type == QUE_RESEARCH ? 'NULL' : $planet_id_origin;
392
-  if(is_numeric($planet_id)) {
392
+  if (is_numeric($planet_id)) {
393 393
     DBStaticPlanet::db_planet_update_set_by_id($planet_id, "`que_processed` = UNIX_TIMESTAMP(NOW())");
394
-  } elseif(is_numeric($user['id'])) {
394
+  } elseif (is_numeric($user['id'])) {
395 395
     DBStaticUser::db_user_set_by_id($user['id'], '`que_processed` = UNIX_TIMESTAMP(NOW())');
396 396
   }
397 397
 
@@ -421,17 +421,17 @@  discard block
 block discarded – undo
421 421
   $planet['id'] = $planet['id'] && $que_type !== QUE_RESEARCH ? $planet['id'] : 0;
422 422
   $global_que = que_get($user['id'], $planet['id'], $que_type, true);
423 423
 
424
-  if(!empty($global_que['ques'][$que_type][$user['id']][$planet['id']])) {
424
+  if (!empty($global_que['ques'][$que_type][$user['id']][$planet['id']])) {
425 425
     $que = array_reverse($global_que['ques'][$que_type][$user['id']][$planet['id']]);
426 426
 
427
-    foreach($que as $que_item) {
427
+    foreach ($que as $que_item) {
428 428
       DBStaticQue::db_que_delete_by_id($que_item['que_id']);
429 429
 
430
-      if($que_item['que_planet_id_origin']) {
430
+      if ($que_item['que_planet_id_origin']) {
431 431
         $planet['id'] = $que_item['que_planet_id_origin'];
432 432
       }
433 433
 
434
-      if(!isset($planets_locked[$planet['id']])) {
434
+      if (!isset($planets_locked[$planet['id']])) {
435 435
         $planets_locked[$planet['id']] = $planet['id'] ? DBStaticPlanet::db_planet_by_id($planet['id'], true) : $planet;
436 436
       }
437 437
 
@@ -443,14 +443,14 @@  discard block
 block discarded – undo
443 443
         RES_DEUTERIUM => $build_data[RES_DEUTERIUM] * $que_item['que_unit_amount'],
444 444
       ));
445 445
 
446
-      if(!$clear) {
446
+      if (!$clear) {
447 447
         break;
448 448
       }
449 449
     }
450 450
 
451
-    if(is_numeric($planet['id'])) {
451
+    if (is_numeric($planet['id'])) {
452 452
       DBStaticPlanet::db_planet_update_set_by_id($planet['id'], "`que_processed` = UNIX_TIMESTAMP(NOW())");
453
-    } elseif(is_numeric($user['id'])) {
453
+    } elseif (is_numeric($user['id'])) {
454 454
       DBStaticUser::db_user_set_by_id($user['id'], '`que_processed` = UNIX_TIMESTAMP(NOW())');
455 455
     }
456 456
 
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
     sn_db_transaction_rollback();
460 460
   }
461 461
 //die();
462
-  header("Location: {$_SERVER['PHP_SELF']}?mode={$que_type}" . "&ally_id=" . sys_get_param_id('ally_id'));
462
+  header("Location: {$_SERVER['PHP_SELF']}?mode={$que_type}"."&ally_id=".sys_get_param_id('ally_id'));
463 463
 }
464 464
 
465 465
 
@@ -498,21 +498,21 @@  discard block
 block discarded – undo
498 498
   // TODO: Переделать для $que_type === false
499 499
   $planet['id'] = $planet['id'] ? $planet['id'] : 0;
500 500
 
501
-  if(!is_array($que)) {
501
+  if (!is_array($que)) {
502 502
     $que = que_get($user['id'], $planet['id'], $que_type);
503 503
   }
504 504
 
505
-  if(is_array($que) && isset($que['items'])) {
505
+  if (is_array($que) && isset($que['items'])) {
506 506
     $que = $que['ques'][$que_type][$user['id']][$planet['id']];
507 507
   }
508 508
 
509
-  if($que) {
510
-    foreach($que as $que_element) {
509
+  if ($que) {
510
+    foreach ($que as $que_element) {
511 511
       $template->assign_block_vars('que', que_tpl_parse_element($que_element, $short_names));
512 512
     }
513 513
   }
514 514
 
515
-  if($que_type == QUE_RESEARCH) {
515
+  if ($que_type == QUE_RESEARCH) {
516 516
   }
517 517
 }
518 518
 
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
   $user = DBStaticUser::db_user_by_id($user['id'], true);
539 539
 
540 540
   $time_left[$user['id']][0] = max(0, $on_time - $user['que_processed']);
541
-  if($planet === null && !$time_left[$user['id']][0]) {
541
+  if ($planet === null && !$time_left[$user['id']][0]) {
542 542
     // TODO
543 543
     return $que;
544 544
   }
@@ -547,12 +547,12 @@  discard block
 block discarded – undo
547 547
   $que_type_id = $planet === null ? QUE_RESEARCH : false;
548 548
   $planet = intval(is_array($planet) ? $planet['id'] : $planet); // В $planet у нас теперь только её ID или шаблон null/0/false
549 549
   $que = que_get($user['id'], $planet, $que_type_id, true);
550
-  if(empty($que['items'])) {
550
+  if (empty($que['items'])) {
551 551
     return $que;
552 552
   }
553 553
 
554 554
   $planet_list = array();
555
-  if($planet !== null) {
555
+  if ($planet !== null) {
556 556
     // Если нужно изменять данные на планетах - блокируем планеты и получаем данные о них
557 557
     // TODO - от них не надо ничего, кроме ID и que_processed
558 558
     $planet_row = DBStaticPlanet::db_planet_list_by_user_or_planet($user['id'], $planet);
@@ -561,20 +561,20 @@  discard block
 block discarded – undo
561 561
   }
562 562
 
563 563
   // Теперь в $time_left лежит время обсчета всех очередей по каждой из планеты
564
-  if(array_sum($time_left[$user['id']]) == 0) {
564
+  if (array_sum($time_left[$user['id']]) == 0) {
565 565
     return $que;
566 566
   }
567 567
 
568 568
   $unit_changes = array();
569
-  foreach($que['items'] as &$que_item) {
569
+  foreach ($que['items'] as &$que_item) {
570 570
     $que_player_id = &$que_item['que_player_id'];
571 571
     $que_planet_id = intval($que_item['que_planet_id']);
572 572
 
573 573
     $que_time_left = &$que['time_left'][$que_player_id][$que_planet_id][$que_item['que_type']];
574
-    if(!isset($que_time_left)) {
574
+    if (!isset($que_time_left)) {
575 575
       $que_time_left = $time_left[$que_player_id][$que_planet_id];
576 576
     }
577
-    if($que_time_left <= 0 || $que_item['que_unit_amount'] <= 0) {
577
+    if ($que_time_left <= 0 || $que_item['que_unit_amount'] <= 0) {
578 578
       continue;
579 579
     }
580 580
     // Дальше мы идем, если только осталось время в очереди И юниты к постройке
@@ -587,7 +587,7 @@  discard block
 block discarded – undo
587 587
     // Теперь работаем с остатком времени на юните. Оно не может быть равно или меньше нуля
588 588
 
589 589
     // Если времени в очереди осталось не меньше, чем время текущего юнита - значит мы достроили юнит
590
-    if($que_time_left >= $que_item['que_time_left']) {
590
+    if ($que_time_left >= $que_item['que_time_left']) {
591 591
       // Увеличиваем количество отстроенных юнитов
592 592
       $unit_processed++;
593 593
       // Вычитаем из времени очереди потраченное на постройку время
@@ -600,12 +600,12 @@  discard block
 block discarded – undo
600 600
     $que_item['que_unit_amount'] -= $unit_processed;
601 601
 
602 602
     // Если еще остались юниты - значит ВСЁ оставшееся время приходится на достройку следующего юнита
603
-    if($que_item['que_unit_amount'] > 0) {
603
+    if ($que_item['que_unit_amount'] > 0) {
604 604
       $que_item['que_time_left'] = $que_item['que_time_left'] - $que_time_left;
605 605
       $que_time_left = 0;
606 606
     }
607 607
 
608
-    if($que_item['que_unit_amount'] <= 0) {
608
+    if ($que_item['que_unit_amount'] <= 0) {
609 609
       DBStaticQue::db_que_delete_by_id($que_item['que_id']);
610 610
     } else {
611 611
       classSupernova::db_upd_record_list(
@@ -615,15 +615,15 @@  discard block
 block discarded – undo
615 615
       );
616 616
     }
617 617
 
618
-    if($unit_processed) {
618
+    if ($unit_processed) {
619 619
       $unit_processed_delta = $unit_processed * ($que_item['que_unit_mode'] == BUILD_CREATE ? 1 : -1);
620 620
       $unit_changes[$que_player_id][$que_planet_id][$que_item['que_unit_id']] += $unit_processed_delta;
621 621
     }
622 622
   }
623 623
 
624
-  foreach($time_left as $player_id => $planet_data) {
625
-    foreach($planet_data as $planet_id => $time_on_planet) {
626
-      if($planet_id) {
624
+  foreach ($time_left as $player_id => $planet_data) {
625
+    foreach ($planet_data as $planet_id => $time_on_planet) {
626
+      if ($planet_id) {
627 627
         // update planet
628 628
         classSupernova::db_upd_record_list(LOC_PLANET, "`que_processed` = {$on_time}", "id = {$planet_id}");
629 629
       } else {
@@ -631,8 +631,8 @@  discard block
 block discarded – undo
631 631
         classSupernova::db_upd_record_list(LOC_USER, "`que_processed` = {$on_time}", "id = {$player_id}");
632 632
       }
633 633
 
634
-      if(is_array($unit_changes[$player_id][$planet_id])) {
635
-        foreach($unit_changes[$player_id][$planet_id] as $unit_id => $unit_amount) {
634
+      if (is_array($unit_changes[$player_id][$planet_id])) {
635
+        foreach ($unit_changes[$player_id][$planet_id] as $unit_id => $unit_amount) {
636 636
           DBStaticUnit::dbUpdateOrInsertUnit($unit_id, $unit_amount, $user, $planet_id ? $planet_id : null);
637 637
         }
638 638
       }
@@ -642,38 +642,38 @@  discard block
 block discarded – undo
642 642
   $que = que_recalculate($que);
643 643
 
644 644
   // TODO: Re-enable quests for Alliances
645
-  if(!empty($unit_changes) && !$user['user_as_ally']) {
645
+  if (!empty($unit_changes) && !$user['user_as_ally']) {
646 646
     $quest_list = qst_get_quests($user['id']);
647 647
     $quest_triggers = qst_active_triggers($quest_list);
648 648
     $quest_rewards = array();
649 649
 
650 650
 
651 651
     $xp_incoming = array();
652
-    foreach($unit_changes as $user_id => $planet_changes) {
653
-      foreach($planet_changes as $planet_id => $changes) {
652
+    foreach ($unit_changes as $user_id => $planet_changes) {
653
+      foreach ($planet_changes as $planet_id => $changes) {
654 654
         $planet_this = $planet_id ? classSupernova::db_get_record_by_id(LOC_PLANET, $planet_id) : array();
655
-        foreach($changes as $unit_id => $unit_value) {
655
+        foreach ($changes as $unit_id => $unit_value) {
656 656
           $que_id = que_get_unit_que($unit_id);
657 657
           $unit_level_new = mrc_get_level($user, $planet_this, $unit_id, false, true) + $unit_value;
658
-          if($que_id == QUE_STRUCTURES || $que_id == QUE_RESEARCH) {
658
+          if ($que_id == QUE_STRUCTURES || $que_id == QUE_RESEARCH) {
659 659
             $build_data = eco_get_build_data($user, $planet_this, $unit_id, $unit_level_new - 1);
660 660
             $build_data = $build_data[BUILD_CREATE];
661
-            foreach(sn_get_groups('resources_loot') as $resource_id) {
661
+            foreach (sn_get_groups('resources_loot') as $resource_id) {
662 662
               $xp_incoming[$que_id] += $build_data[$resource_id]; // TODO - добавить конверсию рейтов обмена
663 663
             }
664 664
           }
665 665
 
666
-          if(is_array($quest_triggers)) {
666
+          if (is_array($quest_triggers)) {
667 667
             // TODO: Check mutiply condition quests
668 668
             $quest_trigger_list = array_keys($quest_triggers, $unit_id);
669
-            if(is_array($quest_trigger_list)) {
670
-              foreach($quest_trigger_list as $quest_id) {
669
+            if (is_array($quest_trigger_list)) {
670
+              foreach ($quest_trigger_list as $quest_id) {
671 671
                 $quest_unit_level = $unit_level_new;
672
-                if(get_unit_param($unit_id, P_UNIT_TYPE) == UNIT_SHIPS) {
672
+                if (get_unit_param($unit_id, P_UNIT_TYPE) == UNIT_SHIPS) {
673 673
                   $quest_unit_level = DBStaticUnit::db_unit_count_by_user_and_type_and_snid($user_id, 0, $unit_id);
674 674
                   $quest_unit_level = $quest_unit_level[$unit_id]['qty'];
675 675
                 }
676
-                if($quest_list[$quest_id]['quest_status_status'] != QUEST_STATUS_COMPLETE && $quest_list[$quest_id]['quest_unit_amount'] <= $quest_unit_level) {
676
+                if ($quest_list[$quest_id]['quest_status_status'] != QUEST_STATUS_COMPLETE && $quest_list[$quest_id]['quest_unit_amount'] <= $quest_unit_level) {
677 677
                   $quest_rewards[$quest_id][$user_id][$planet_id] = $quest_list[$quest_id]['quest_rewards_list'];
678 678
                   $quest_list[$quest_id]['quest_status_status'] = QUEST_STATUS_COMPLETE;
679 679
                 }
@@ -686,7 +686,7 @@  discard block
 block discarded – undo
686 686
     // TODO: Изменить начисление награды за квесты на ту планету, на которой происходил ресеч
687 687
     qst_reward($user, $quest_rewards, $quest_list);
688 688
 
689
-    foreach($xp_incoming as $que_id => $xp) {
689
+    foreach ($xp_incoming as $que_id => $xp) {
690 690
       rpg_level_up($user, $que_id == QUE_RESEARCH ? RPG_TECH : RPG_STRUCTURE, $xp / 1000);
691 691
     }
692 692
   }
Please login to merge, or discard this patch.
includes/classes/DBStaticQue.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@
 block discarded – undo
38 38
     if ($que_type == QUE_RESEARCH || $planet_id === null) {
39 39
       $query[] = "`que_planet_id` IS NULL";
40 40
     } elseif ($planet_id) {
41
-      $query[] = "(`que_planet_id` = {$planet_id}" . ($que_type ? '' : ' OR que_planet_id IS NULL') . ")";
41
+      $query[] = "(`que_planet_id` = {$planet_id}".($que_type ? '' : ' OR que_planet_id IS NULL').")";
42 42
     }
43 43
     if ($que_type) {
44 44
       $query[] = "`que_type` = {$que_type}";
Please login to merge, or discard this patch.
includes/classes/classSupernova.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
     ini_get('magic_quotes_sybase') ? die('SN is incompatible with \'magic_quotes_sybase\' turned on. Disable it in php.ini or .htaccess...') : false;
204 204
     if (@get_magic_quotes_gpc()) {
205 205
       $gpcr = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
206
-      array_walk_recursive($gpcr, function (&$value, $key) {
206
+      array_walk_recursive($gpcr, function(&$value, $key) {
207 207
         $value = stripslashes($value);
208 208
       });
209 209
     }
@@ -219,43 +219,43 @@  discard block
 block discarded – undo
219 219
     $gc = static::$gc;
220 220
 
221 221
     // Default db
222
-    $gc->db = function ($c) {
222
+    $gc->db = function($c) {
223 223
       $db = new db_mysql($c);
224 224
       $db->sn_db_connect();
225 225
 
226 226
       return $db;
227 227
     };
228 228
 
229
-    $gc->debug = function ($c) {
229
+    $gc->debug = function($c) {
230 230
       return new debug();
231 231
     };
232 232
 
233
-    $gc->cache = function ($c) {
233
+    $gc->cache = function($c) {
234 234
       return new classCache(classSupernova::$cache_prefix);
235 235
     };
236 236
 
237
-    $gc->config = function ($c) {
237
+    $gc->config = function($c) {
238 238
       return new classConfig(classSupernova::$cache_prefix);
239 239
     };
240 240
 
241
-    $gc->localePlayer = function (GlobalContainer $c) {
241
+    $gc->localePlayer = function(GlobalContainer $c) {
242 242
       return new classLocale($c->config->server_locale_log_usage);
243 243
     };
244 244
 
245
-    $gc->dbRowOperator = function ($c) {
245
+    $gc->dbRowOperator = function($c) {
246 246
       return new DbRowDirectOperator($c);
247 247
     };
248 248
 
249 249
     $gc->buddyClass = 'Buddy\BuddyModel';
250
-    $gc->buddy = $gc->factory(function (GlobalContainer $c) {
250
+    $gc->buddy = $gc->factory(function(GlobalContainer $c) {
251 251
       return new $c->buddyClass($c);
252 252
     });
253 253
 
254
-    $gc->query = $gc->factory(function (GlobalContainer $c) {
254
+    $gc->query = $gc->factory(function(GlobalContainer $c) {
255 255
       return new DbQueryConstructor($c->db);
256 256
     });
257 257
 
258
-    $gc->unit = $gc->factory(function (GlobalContainer $c) {
258
+    $gc->unit = $gc->factory(function(GlobalContainer $c) {
259 259
       return new \V2Unit\V2UnitModel($c);
260 260
     });
261 261
 
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
   public static function init_3_load_config_file() {
269 269
     $dbsettings = array();
270 270
 
271
-    require(SN_ROOT_PHYSICAL . "config" . DOT_PHP_EX);
271
+    require(SN_ROOT_PHYSICAL."config".DOT_PHP_EX);
272 272
     self::$cache_prefix = !empty($dbsettings['cache_prefix']) ? $dbsettings['cache_prefix'] : $dbsettings['prefix'];
273 273
     self::$db_name = $dbsettings['name'];
274 274
     self::$sn_secret_word = $dbsettings['secretword'];
Please login to merge, or discard this patch.
includes/classes/classLocale.php 1 patch
Spacing   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -35,13 +35,13 @@  discard block
 block discarded – undo
35 35
 
36 36
     $this->container = array();
37 37
 
38
-    if(classSupernova::$cache->_MODE != CACHER_NO_CACHE && !classSupernova::$config->locale_cache_disable) {
38
+    if (classSupernova::$cache->_MODE != CACHER_NO_CACHE && !classSupernova::$config->locale_cache_disable) {
39 39
       $this->cache = classSupernova::$cache;
40 40
       classSupernova::log_file('locale.__constructor: Cache is present');
41 41
 //$this->cache->unset_by_prefix($this->cache_prefix); // TODO - remove? 'cause debug!
42 42
     }
43 43
 
44
-    if($enable_stat_usage && empty($this->stat_usage)) {
44
+    if ($enable_stat_usage && empty($this->stat_usage)) {
45 45
       $this->enable_stat_usage = $enable_stat_usage;
46 46
       $this->usage_stat_load();
47 47
       // TODO shutdown function
@@ -67,18 +67,18 @@  discard block
 block discarded – undo
67 67
     unset($fallback[$this->active]);
68 68
 
69 69
     // Проходим по оставшимся локалям
70
-    foreach($fallback as $try_language) {
70
+    foreach ($fallback as $try_language) {
71 71
       // Если нет такой строки - пытаемся вытащить из кэша
72
-      if(!isset($this->container[$try_language][$offset]) && $this->cache) {
73
-        $this->container[$try_language][$offset] = $this->cache->__get($this->cache_prefix . $try_language . '_' . $offset);
72
+      if (!isset($this->container[$try_language][$offset]) && $this->cache) {
73
+        $this->container[$try_language][$offset] = $this->cache->__get($this->cache_prefix.$try_language.'_'.$offset);
74 74
 // Записываем результат работы кэша
75 75
 $locale_cache_statistic['queries']++;
76 76
 isset($this->container[$try_language][$offset]) ? $locale_cache_statistic['hits']++ : $locale_cache_statistic['misses']++;
77
-!isset($this->container[$try_language][$offset]) ? $locale_cache_statistic['missed_str'][] = $this->cache_prefix . $try_language . '_' . $offset : false;
77
+!isset($this->container[$try_language][$offset]) ? $locale_cache_statistic['missed_str'][] = $this->cache_prefix.$try_language.'_'.$offset : false;
78 78
       }
79 79
 
80 80
       // Если мы как-то где-то нашли строку...
81
-      if(isset($this->container[$try_language][$offset])) {
81
+      if (isset($this->container[$try_language][$offset])) {
82 82
         // ...значит она получена в результате фоллбэка и записываем её в кэш и контейнер
83 83
         $this[$offset] = $this->container[$try_language][$offset];
84 84
         $locale_cache_statistic['fallbacks']++;
@@ -94,16 +94,16 @@  discard block
 block discarded – undo
94 94
       $this->container[$this->active][] = $value;
95 95
     } else {
96 96
       $this->container[$this->active][$offset] = $value;
97
-      if($this->cache) {
98
-        $this->cache->__set($this->cache_prefix_lang . $offset, $value);
97
+      if ($this->cache) {
98
+        $this->cache->__set($this->cache_prefix_lang.$offset, $value);
99 99
       }
100 100
     }
101 101
   }
102 102
   public function offsetExists($offset) {
103 103
     // Шорткат если у нас уже есть строка в памяти PHP
104
-    if(!isset($this->container[$this->active][$offset])) {
104
+    if (!isset($this->container[$this->active][$offset])) {
105 105
 //        pdump($this->cache_prefix_lang . $offset);
106
-      if(!$this->cache || !($this->container[$this->active][$offset] = $this->cache->__get($this->cache_prefix_lang . $offset))) {
106
+      if (!$this->cache || !($this->container[$this->active][$offset] = $this->cache->__get($this->cache_prefix_lang.$offset))) {
107 107
 //        pdump($this->cache_prefix_lang . $offset);
108 108
         // Если нету такой строки - делаем фоллбэк
109 109
         $this->locale_string_fallback($offset);
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
   }
120 120
   public function offsetGet($offset) {
121 121
     $value = $this->offsetExists($offset) ? $this->container[$this->active][$offset] : null;
122
-    if($this->enable_stat_usage) {
122
+    if ($this->enable_stat_usage) {
123 123
       $this->usage_stat_log($offset, $value);
124 124
     }
125 125
     return $value;
@@ -134,23 +134,23 @@  discard block
 block discarded – undo
134 134
 
135 135
 
136 136
   public function usage_stat_load() {
137
-    $this->stat_usage = classSupernova::$cache->lng_stat_usage  = array(); // TODO for debug
138
-    if(empty($this->stat_usage)) {
137
+    $this->stat_usage = classSupernova::$cache->lng_stat_usage = array(); // TODO for debug
138
+    if (empty($this->stat_usage)) {
139 139
       $query = classSupernova::$db->doSelect("SELECT * FROM `{{lng_usage_stat}}`");
140
-      while($row = db_fetch($query)) {
141
-        $this->stat_usage[$row['lang_code'] . ':' . $row['string_id'] . ':' . $row['file'] . ':' . $row['line']] = $row['is_empty'];
140
+      while ($row = db_fetch($query)) {
141
+        $this->stat_usage[$row['lang_code'].':'.$row['string_id'].':'.$row['file'].':'.$row['line']] = $row['is_empty'];
142 142
       }
143 143
     }
144 144
   }
145 145
   public function usage_stat_save() {
146
-    if(!empty($this->stat_usage_new)) {
146
+    if (!empty($this->stat_usage_new)) {
147 147
       classSupernova::$cache->lng_stat_usage = $this->stat_usage;
148 148
       classSupernova::$db->doSelect("SELECT 1 FROM `{{lng_usage_stat}}` LIMIT 1");
149
-      foreach($this->stat_usage_new as &$value) {
150
-        foreach($value as &$value2) {
151
-          $value2 = '"' . db_escape($value2) . '"';
149
+      foreach ($this->stat_usage_new as &$value) {
150
+        foreach ($value as &$value2) {
151
+          $value2 = '"'.db_escape($value2).'"';
152 152
         }
153
-        $value = '(' . implode(',', $value) .')';
153
+        $value = '('.implode(',', $value).')';
154 154
       }
155 155
       classSupernova::$gc->db->doReplaceValuesDeprecated(
156 156
         'lng_usage_stat',
@@ -173,8 +173,8 @@  discard block
 block discarded – undo
173 173
 
174 174
     $file = str_replace('\\', '/', substr($trace[1]['file'], strlen(SN_ROOT_PHYSICAL) - 1));
175 175
 
176
-    $string_id = $this->active . ':' . $offset . ':' . $file . ':' . $trace[1]['line'];
177
-    if(!isset($this->stat_usage[$string_id]) || $this->stat_usage[$string_id] != empty($value)) {
176
+    $string_id = $this->active.':'.$offset.':'.$file.':'.$trace[1]['line'];
177
+    if (!isset($this->stat_usage[$string_id]) || $this->stat_usage[$string_id] != empty($value)) {
178 178
       $this->stat_usage[$string_id] = empty($value);
179 179
       $this->stat_usage_new[] = array(
180 180
         'lang_code' => $this->active,
@@ -182,14 +182,14 @@  discard block
 block discarded – undo
182 182
         'file' => $file,
183 183
         'line' => $trace[1]['line'],
184 184
         'is_empty' => intval(empty($value)),
185
-        'locale' => '' . $value,
185
+        'locale' => ''.$value,
186 186
       );
187 187
     }
188 188
   }
189 189
 
190 190
 
191 191
   protected function lng_try_filepath($path, $file_path_relative) {
192
-    $file_path = SN_ROOT_PHYSICAL . ($path && file_exists(SN_ROOT_PHYSICAL . $path . $file_path_relative) ? $path : '') . $file_path_relative;
192
+    $file_path = SN_ROOT_PHYSICAL.($path && file_exists(SN_ROOT_PHYSICAL.$path.$file_path_relative) ? $path : '').$file_path_relative;
193 193
     return file_exists($file_path) ? $file_path : false;
194 194
   }
195 195
 
@@ -211,14 +211,14 @@  discard block
 block discarded – undo
211 211
 
212 212
     classSupernova::log_file("locale.include: Loading data from domain '{$filename}'", 1);
213 213
 
214
-    $cache_file_key = $this->cache_prefix_lang . '__' . $filename;
214
+    $cache_file_key = $this->cache_prefix_lang.'__'.$filename;
215 215
 
216 216
     // Подключен ли внешний кэш?
217
-    if($this->cache) {
217
+    if ($this->cache) {
218 218
       // Загружен ли уже данный файл?
219 219
       $cache_file_status = $this->cache->__get($cache_file_key);
220
-      classSupernova::log_file("locale.include: Cache - '{$filename}' has key '{$cache_file_key}' and is " . ($cache_file_status ? 'already loaded - EXIT' : 'EMPTY'), $cache_file_status ? -1 : 0);
221
-      if($cache_file_status) {
220
+      classSupernova::log_file("locale.include: Cache - '{$filename}' has key '{$cache_file_key}' and is ".($cache_file_status ? 'already loaded - EXIT' : 'EMPTY'), $cache_file_status ? -1 : 0);
221
+      if ($cache_file_status) {
222 222
         // Если да - повторять загрузку нет смысла
223 223
         return null;
224 224
       }
@@ -232,47 +232,47 @@  discard block
 block discarded – undo
232 232
     $this->make_fallback($language);
233 233
 
234 234
     $file_path = '';
235
-    foreach($this->fallback as $lang_try) {
236
-      if(!$lang_try /* || isset($language_tried[$lang_try]) */) {
235
+    foreach ($this->fallback as $lang_try) {
236
+      if (!$lang_try /* || isset($language_tried[$lang_try]) */) {
237 237
         continue;
238 238
       }
239 239
 
240
-      if($file_path = $this->lng_try_filepath($path, "language/{$lang_try}/{$filename_ext}")) {
240
+      if ($file_path = $this->lng_try_filepath($path, "language/{$lang_try}/{$filename_ext}")) {
241 241
         break;
242 242
       }
243 243
 
244
-      if($file_path = $this->lng_try_filepath($path, "language/{$filename}_{$lang_try}{$ext}")) {
244
+      if ($file_path = $this->lng_try_filepath($path, "language/{$filename}_{$lang_try}{$ext}")) {
245 245
         break;
246 246
       }
247 247
 
248 248
       $file_path = '';
249 249
     }
250 250
 
251
-    if($file_path) {
251
+    if ($file_path) {
252 252
       $a_lang_array = array();
253 253
       include($file_path);
254 254
 
255
-      if(!empty($a_lang_array)) {
255
+      if (!empty($a_lang_array)) {
256 256
         $this->merge($a_lang_array);
257 257
 
258 258
         // Загрузка данных из файла в кэш
259
-        if($this->cache) {
259
+        if ($this->cache) {
260 260
           classSupernova::log_file("Locale: loading '{$filename}' into cache");
261
-          foreach($a_lang_array as $key => $value) {
262
-            $value_cache_key = $this->cache_prefix_lang . $key;
263
-            if($this->cache->__isset($value_cache_key)) {
264
-              if(is_array($value)) {
261
+          foreach ($a_lang_array as $key => $value) {
262
+            $value_cache_key = $this->cache_prefix_lang.$key;
263
+            if ($this->cache->__isset($value_cache_key)) {
264
+              if (is_array($value)) {
265 265
                 $alt_value = $this->cache->__get($value_cache_key);
266 266
                 $value = array_replace_recursive($alt_value, $value);
267 267
                 // pdump($alt_value, $alt_value);
268 268
               }
269 269
             }
270
-            $this->cache->__set($this->cache_prefix_lang . $key, $value);
270
+            $this->cache->__set($this->cache_prefix_lang.$key, $value);
271 271
           }
272 272
         }
273 273
       }
274 274
 
275
-      if($this->cache) {
275
+      if ($this->cache) {
276 276
         $this->cache->__set($cache_file_key, true);
277 277
       }
278 278
 
@@ -285,14 +285,14 @@  discard block
 block discarded – undo
285 285
   }
286 286
 
287 287
   public function lng_load_i18n($i18n) {
288
-    if(!isset($i18n)) {
288
+    if (!isset($i18n)) {
289 289
       return;
290 290
     }
291 291
 
292
-    foreach($i18n as $i18n_data) {
293
-      if(is_string($i18n_data)) {
292
+    foreach ($i18n as $i18n_data) {
293
+      if (is_string($i18n_data)) {
294 294
         $this->lng_include($i18n_data);
295
-      } elseif(is_array($i18n_data)) {
295
+      } elseif (is_array($i18n_data)) {
296 296
         $this->lng_include($i18n_data['file'], $i18n_data['path']);
297 297
       }
298 298
     }
@@ -310,27 +310,27 @@  discard block
 block discarded – undo
310 310
 
311 311
     classSupernova::log_file("locale.switch: Trying to switch language to '{$language_new}'");
312 312
 
313
-    if($language_new == $this->active) {
313
+    if ($language_new == $this->active) {
314 314
       classSupernova::log_file("locale.switch: New language '{$language_new}' is equal to current language '{$this->active}' - EXIT", -1);
315 315
       return false;
316 316
     }
317 317
 
318 318
     $this->active = $language = $language_new;
319
-    $this->cache_prefix_lang = $this->cache_prefix . $this->active . '_';
319
+    $this->cache_prefix_lang = $this->cache_prefix.$this->active.'_';
320 320
 
321 321
     $this['LANG_INFO'] = $this->lng_get_info($this->active);
322 322
     $this->make_fallback($this->active);
323 323
 
324
-    if($this->cache) {
325
-      $cache_lang_init_status = $this->cache->__get($this->cache_prefix_lang . '__INIT');
326
-      classSupernova::log_file("locale.switch: Cache for '{$this->active}' prefixed '{$this->cache_prefix_lang}' is " . ($cache_lang_init_status ? 'already loaded. Doing nothing - EXIT' : 'EMPTY'), $cache_lang_init_status ? -1 : 0);
327
-      if($cache_lang_init_status) {
324
+    if ($this->cache) {
325
+      $cache_lang_init_status = $this->cache->__get($this->cache_prefix_lang.'__INIT');
326
+      classSupernova::log_file("locale.switch: Cache for '{$this->active}' prefixed '{$this->cache_prefix_lang}' is ".($cache_lang_init_status ? 'already loaded. Doing nothing - EXIT' : 'EMPTY'), $cache_lang_init_status ? -1 : 0);
327
+      if ($cache_lang_init_status) {
328 328
         return false;
329 329
       }
330 330
 
331 331
       // Чистим текущие локализации из кэша. Достаточно почистить только флаги инициализации языкового кэша и загрузки файлов - они начинаются с '__'
332 332
       classSupernova::log_file("locale.switch: Cache - invalidating data");
333
-      $this->cache->unset_by_prefix($this->cache_prefix_lang . '__');
333
+      $this->cache->unset_by_prefix($this->cache_prefix_lang.'__');
334 334
     }
335 335
 
336 336
     $this->lng_include('system');
@@ -340,9 +340,9 @@  discard block
 block discarded – undo
340 340
     // Loading global language files
341 341
     $this->lng_load_i18n(classSupernova::$sn_mvc['i18n']['']);
342 342
 
343
-    if($this->cache) {
344
-      classSupernova::log_file("locale.switch: Cache - setting flag " . $this->cache_prefix_lang . '__INIT');
345
-      $this->cache->__set($this->cache_prefix_lang . '__INIT', true);
343
+    if ($this->cache) {
344
+      classSupernova::log_file("locale.switch: Cache - setting flag ".$this->cache_prefix_lang.'__INIT');
345
+      $this->cache->__set($this->cache_prefix_lang.'__INIT', true);
346 346
     }
347 347
 
348 348
     classSupernova::log_file("locale.switch: Complete - EXIT");
@@ -352,9 +352,9 @@  discard block
 block discarded – undo
352 352
 
353 353
 
354 354
   public function lng_get_info($entry) {
355
-    $file_name = SN_ROOT_PHYSICAL . 'language/' . $entry . '/language.mo.php';
355
+    $file_name = SN_ROOT_PHYSICAL.'language/'.$entry.'/language.mo.php';
356 356
     $lang_info = array();
357
-    if(file_exists($file_name)) {
357
+    if (file_exists($file_name)) {
358 358
       include($file_name);
359 359
     }
360 360
 
@@ -362,15 +362,15 @@  discard block
 block discarded – undo
362 362
   }
363 363
 
364 364
   public function lng_get_list() {
365
-    if(empty($this->lang_list)) {
365
+    if (empty($this->lang_list)) {
366 366
       $this->lang_list = array();
367 367
 
368
-      $path = SN_ROOT_PHYSICAL . 'language/';
368
+      $path = SN_ROOT_PHYSICAL.'language/';
369 369
       $dir = dir($path);
370
-      while(false !== ($entry = $dir->read())) {
371
-        if(is_dir($path . $entry) && $entry[0] != '.') {
370
+      while (false !== ($entry = $dir->read())) {
371
+        if (is_dir($path.$entry) && $entry[0] != '.') {
372 372
           $lang_info = $this->lng_get_info($entry);
373
-          if($lang_info['LANG_NAME_ISO2'] == $entry) {
373
+          if ($lang_info['LANG_NAME_ISO2'] == $entry) {
374 374
             $this->lang_list[$lang_info['LANG_NAME_ISO2']] = $lang_info;
375 375
           }
376 376
         }
Please login to merge, or discard this patch.