Completed
Push — work-fleets ( aedb07...3b3d1f )
by SuperNova.WS
05:31
created
includes/classes/module.php 1 patch
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
     require SN_ROOT_PHYSICAL . 'config.php';
77 77
 
78 78
     $module_config_array = get_class($this) . '_config';
79
-    if(!empty($$module_config_array) && is_array($$module_config_array)) {
79
+    if (!empty($$module_config_array) && is_array($$module_config_array)) {
80 80
       $this->config = $$module_config_array;
81 81
 
82 82
       return true;
@@ -94,15 +94,15 @@  discard block
 block discarded – undo
94 94
 
95 95
     // TODO: Load configuration from DB. Manifest setting
96 96
     // Trying to load configuration from file
97
-    if(!$config_exists = $this->loadModuleRootConfig()) {
97
+    if (!$config_exists = $this->loadModuleRootConfig()) {
98 98
       // Конфигурация может лежать в config_path в манифеста или в корне модуля
99
-      if(isset($this->manifest['config_path']) && file_exists($config_filename = $this->manifest['config_path'] . '/config.php')) {
99
+      if (isset($this->manifest['config_path']) && file_exists($config_filename = $this->manifest['config_path'] . '/config.php')) {
100 100
         $config_exists = true;
101
-      } elseif(file_exists($config_filename = dirname($filename) . '/config.php')) {
101
+      } elseif (file_exists($config_filename = dirname($filename) . '/config.php')) {
102 102
         $config_exists = true;
103 103
       }
104 104
 
105
-      if($config_exists) {
105
+      if ($config_exists) {
106 106
         include($config_filename);
107 107
         $module_config_array = $class_module_name . '_config';
108 108
         $this->config = $$module_config_array;
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 
120 120
     // Checking module status - is it installed and active
121 121
     $this->check_status();
122
-    if(!$this->manifest['active']) {
122
+    if (!$this->manifest['active']) {
123 123
       return;
124 124
     }
125 125
 
@@ -139,11 +139,11 @@  discard block
 block discarded – undo
139 139
 
140 140
   protected function setSystemConstants() {
141 141
     // Setting constants - if any
142
-    if(empty($this->manifest['constants']) || !is_array($this->manifest['constants'])) {
142
+    if (empty($this->manifest['constants']) || !is_array($this->manifest['constants'])) {
143 143
       return;
144 144
     }
145 145
 
146
-    foreach($this->manifest['constants'] as $constant_name => $constant_value) {
146
+    foreach ($this->manifest['constants'] as $constant_name => $constant_value) {
147 147
       defined($constant_name) || define($constant_name, $constant_value);
148 148
     }
149 149
   }
@@ -155,48 +155,48 @@  discard block
 block discarded – undo
155 155
     // New values from module variables will overwrite previous values (for root variables) and array elements with corresponding indexes (for arrays)
156 156
     // Constants as array indexes are honored - it's make valid such declarations as 'sn_data[ques][QUE_STRUCTURES]'
157 157
     $this->manifest['vars'] = $this->__assign_vars();
158
-    if(empty($this->manifest['vars']) || !is_array($this->manifest['vars'])) {
158
+    if (empty($this->manifest['vars']) || !is_array($this->manifest['vars'])) {
159 159
       return;
160 160
     }
161 161
 
162 162
     $vars_assigned = array();
163
-    foreach($this->manifest['vars'] as $var_name => $var_value) {
163
+    foreach ($this->manifest['vars'] as $var_name => $var_value) {
164 164
       $sub_vars = explode('[', str_replace(']', '', $var_name));
165 165
       $var_name = $sub_vars[0];
166 166
 
167
-      if(!isset($vars_assigned[$var_name])) {
167
+      if (!isset($vars_assigned[$var_name])) {
168 168
         $vars_assigned[$var_name] = true;
169 169
         global $$var_name;
170 170
       }
171 171
 
172 172
       $pointer = &$$var_name;
173
-      if(($n = count($sub_vars)) > 1) {
174
-        for($i = 1; $i < $n; $i++) {
175
-          if(defined($sub_vars[$i])) {
173
+      if (($n = count($sub_vars)) > 1) {
174
+        for ($i = 1; $i < $n; $i++) {
175
+          if (defined($sub_vars[$i])) {
176 176
             $sub_vars[$i] = constant($sub_vars[$i]);
177 177
           }
178 178
 
179
-          if(!isset($pointer[$sub_vars[$i]]) && $i != $n) {
179
+          if (!isset($pointer[$sub_vars[$i]]) && $i != $n) {
180 180
             $pointer[$sub_vars[$i]] = array();
181 181
           }
182 182
           $pointer = &$pointer[$sub_vars[$i]];
183 183
         }
184 184
       }
185 185
 
186
-      if(!isset($pointer) || !is_array($pointer)) {
186
+      if (!isset($pointer) || !is_array($pointer)) {
187 187
         $pointer = $var_value;
188
-      } elseif(is_array($$var_name)) {
188
+      } elseif (is_array($$var_name)) {
189 189
         $pointer = array_merge_recursive_numeric($pointer, $var_value);
190 190
       }
191 191
     }
192 192
   }
193 193
 
194 194
   protected function mergeMenu(&$sn_menu_extra, &$menu_patch) {
195
-    if(!is_array($menu_patch)) {
195
+    if (!is_array($menu_patch)) {
196 196
       return;
197 197
     }
198 198
 
199
-    foreach($menu_patch as $menu_item_name => $menu_item_data) {
199
+    foreach ($menu_patch as $menu_item_name => $menu_item_data) {
200 200
       $sn_menu_extra[$menu_item_name] = $menu_item_data;
201 201
     }
202 202
   }
@@ -205,34 +205,34 @@  discard block
 block discarded – undo
205 205
     // Overriding function if any
206 206
     sn_sys_handler_add(classSupernova::$functions, $this->manifest['functions'], $this);
207 207
 
208
-    foreach(classSupernova::$sn_mvc as $handler_type => &$handler_data) {
208
+    foreach (classSupernova::$sn_mvc as $handler_type => &$handler_data) {
209 209
       sn_sys_handler_add($handler_data, $this->manifest['mvc'][$handler_type], $this, $handler_type);
210 210
     }
211 211
   }
212 212
 
213 213
   protected function mergeNavbarButton() {
214
-    if(empty($this->manifest['navbar_prefix_button']) || !is_array($this->manifest['navbar_prefix_button'])) {
214
+    if (empty($this->manifest['navbar_prefix_button']) || !is_array($this->manifest['navbar_prefix_button'])) {
215 215
       return;
216 216
     }
217 217
 
218
-    foreach($this->manifest['navbar_prefix_button'] as $button_image => $button_url_relative) {
218
+    foreach ($this->manifest['navbar_prefix_button'] as $button_image => $button_url_relative) {
219 219
       classSupernova::$sn_mvc['navbar_prefix_button'][$button_image] = $button_url_relative;
220 220
     }
221 221
   }
222 222
 
223 223
   protected function mergeI18N() {
224 224
     $arrayName = 'i18n';
225
-    if(empty($this->manifest[$arrayName]) || !is_array($this->manifest[$arrayName])) {
225
+    if (empty($this->manifest[$arrayName]) || !is_array($this->manifest[$arrayName])) {
226 226
       return;
227 227
     }
228 228
 
229
-    foreach($this->manifest[$arrayName] as $pageName => &$contentList) {
230
-      foreach($contentList as &$i18n_file_data) {
231
-        if(is_array($i18n_file_data) && !$i18n_file_data['path']) {
229
+    foreach ($this->manifest[$arrayName] as $pageName => &$contentList) {
230
+      foreach ($contentList as &$i18n_file_data) {
231
+        if (is_array($i18n_file_data) && !$i18n_file_data['path']) {
232 232
           $i18n_file_data['path'] = $this->manifest['root_relative'];
233 233
         }
234 234
       }
235
-      if(!isset(classSupernova::$sn_mvc[$arrayName][$pageName])) {
235
+      if (!isset(classSupernova::$sn_mvc[$arrayName][$pageName])) {
236 236
         classSupernova::$sn_mvc[$arrayName][$pageName] = array();
237 237
       }
238 238
       classSupernova::$sn_mvc[$arrayName][$pageName] += $contentList;
@@ -240,13 +240,13 @@  discard block
 block discarded – undo
240 240
   }
241 241
 
242 242
   protected function mergeArraySpecial($arrayName) {
243
-    if(empty($this->manifest[$arrayName]) || !is_array($this->manifest[$arrayName])) {
243
+    if (empty($this->manifest[$arrayName]) || !is_array($this->manifest[$arrayName])) {
244 244
       return;
245 245
     }
246 246
 
247
-    foreach($this->manifest[$arrayName] as $pageName => &$contentList) {
247
+    foreach ($this->manifest[$arrayName] as $pageName => &$contentList) {
248 248
       !isset(classSupernova::$sn_mvc[$arrayName][$pageName]) ? classSupernova::$sn_mvc[$arrayName][$pageName] = array() : false;
249
-      foreach($contentList as $contentName => &$content) {
249
+      foreach ($contentList as $contentName => &$content) {
250 250
         classSupernova::$sn_mvc[$arrayName][$pageName][$contentName] = $content;
251 251
       }
252 252
     }
Please login to merge, or discard this patch.
includes/classes/core_auth.php 1 patch
Spacing   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -199,18 +199,18 @@  discard block
 block discarded – undo
199 199
     // TODO Хотя тут может получится вечный цикл - ПОДУМАТЬ
200 200
     // TODO Тут же можно пробовать провести попытку слияния аккаунтов - хотя это и очень небезопасно
201 201
 
202
-    if(sys_get_param('login_player_register_logout')) {
202
+    if (sys_get_param('login_player_register_logout')) {
203 203
       $this->logout();
204 204
     }
205 205
 
206 206
     $original_suggest = '';
207 207
     // Смотрим - есть ли у нас данные от пользователя
208
-    if(($player_name_submitted = sys_get_param('submit_player_name'))) {
208
+    if (($player_name_submitted = sys_get_param('submit_player_name'))) {
209 209
       // Попытка регистрации нового игрока из данных, введенных пользователем
210 210
       $this->player_suggested_name = sys_get_param_str_unsafe('player_suggested_name');
211 211
     } else {
212
-      foreach($this->providers_authorised as $provider) {
213
-        if($this->player_suggested_name = $provider->player_name_suggest()) { // OK 4.5
212
+      foreach ($this->providers_authorised as $provider) {
213
+        if ($this->player_suggested_name = $provider->player_name_suggest()) { // OK 4.5
214 214
           $original_suggest = $provider->player_name_suggest();
215 215
           break;
216 216
         }
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
     }
219 219
 
220 220
     // Если у нас провайдеры не дают имени и пользователь не дал свой вариант - это у нас первый логин в игру
221
-    if(!$this->player_suggested_name) {
221
+    if (!$this->player_suggested_name) {
222 222
       $max_user_id = db_player_get_max_id(); // 4.5
223 223
       // TODO - предлагать имя игрока по локали
224 224
 
@@ -227,15 +227,15 @@  discard block
 block discarded – undo
227 227
         sn_db_transaction_rollback();
228 228
         $this->player_suggested_name = 'Emperor ' . mt_rand($max_user_id + 1, $max_user_id + 1000);
229 229
         sn_db_transaction_start();
230
-      } while(db_player_name_exists($this->player_suggested_name));
230
+      } while (db_player_name_exists($this->player_suggested_name));
231 231
 
232 232
     }
233 233
 
234
-    if($player_name_submitted) {
234
+    if ($player_name_submitted) {
235 235
       $this->register_player_db_create($this->player_suggested_name); // OK 4.5
236
-      if($this->register_status == LOGIN_SUCCESS) {
236
+      if ($this->register_status == LOGIN_SUCCESS) {
237 237
         sys_redirect(SN_ROOT_VIRTUAL . 'overview.php');
238
-      } elseif($this->register_status == REGISTER_ERROR_PLAYER_NAME_EXISTS && $original_suggest == $this->player_suggested_name) {
238
+      } elseif ($this->register_status == REGISTER_ERROR_PLAYER_NAME_EXISTS && $original_suggest == $this->player_suggested_name) {
239 239
         // self::$player_suggested_name .= ' ' . $this->account->account_id;
240 240
       }
241 241
 //      if(self::$login_status != LOGIN_SUCCESS) {
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
         : false
260 260
       );
261 261
 
262
-    if($this->register_status == LOGIN_ERROR_USERNAME_RESTRICTED_CHARACTERS) {
262
+    if ($this->register_status == LOGIN_ERROR_USERNAME_RESTRICTED_CHARACTERS) {
263 263
       $prohibited_characters = array_map(function($value) {
264 264
         return "'" . htmlentities($value, ENT_QUOTES, 'UTF-8') . "'";
265 265
       }, str_split(LOGIN_REGISTER_CHARACTERS_PROHIBITED));
@@ -293,27 +293,27 @@  discard block
 block discarded – undo
293 293
     global $lang;
294 294
 
295 295
     // !self::$is_init ? self::init() : false;
296
-    if(empty(sn_module::$sn_module_list['auth'])) {
296
+    if (empty(sn_module::$sn_module_list['auth'])) {
297 297
       die('{Не обнаружено ни одного провайдера авторизации в core_auth::login()!}');
298 298
     }
299 299
 
300 300
     !empty($_POST) ? self::flog(dump($_POST, '$_POST')) : false;
301 301
     !empty($_GET) ? self::flog(dump($_GET, '$_GET')) : false;
302
-    !empty($_COOKIE) ? self::flog(dump($_COOKIE,'$_COOKIE')) : false;
302
+    !empty($_COOKIE) ? self::flog(dump($_COOKIE, '$_COOKIE')) : false;
303 303
 
304 304
     $this->auth_reset(); // OK v4.5
305 305
 
306 306
     $this->providers = array();
307
-    foreach(sn_module::$sn_module_list['auth'] as $module_name => $module) {
307
+    foreach (sn_module::$sn_module_list['auth'] as $module_name => $module) {
308 308
       $this->providers[$module->provider_id] = $module;
309 309
     }
310 310
 
311 311
     // $this->providers = array_reverse($this->providers, true); // НИНАДА! СН-аккаунт должен всегда авторизироваться первым!
312 312
 
313
-    foreach($this->providers as $provider_id => $provider) {
313
+    foreach ($this->providers as $provider_id => $provider) {
314 314
       $login_status = $provider->login(); // OK v4.5
315 315
       self::flog(($provider->manifest['name'] . '->' . 'login_try - ') . (empty($provider->account->account_id) ? $lang['sys_login_messages'][$provider->account_login_status] : dump($provider)));
316
-      if($login_status == LOGIN_SUCCESS && is_object($provider->account) && $provider->account instanceof Account && $provider->account->account_id) {
316
+      if ($login_status == LOGIN_SUCCESS && is_object($provider->account) && $provider->account instanceof Account && $provider->account->account_id) {
317 317
         $this->providers_authorised[$provider_id] = &$this->providers[$provider_id];
318 318
 
319 319
         $this->user_id_to_provider = array_replace_recursive(
@@ -321,15 +321,15 @@  discard block
 block discarded – undo
321 321
           // static::db_translate_get_users_from_account_list($provider_id, $provider->account->account_id) // OK 4.5
322 322
           PlayerToAccountTranslate::db_translate_get_users_from_account_list($provider_id, $provider->account->account_id) // OK 4.5
323 323
         );
324
-      } elseif($login_status != LOGIN_UNDEFINED) {
324
+      } elseif ($login_status != LOGIN_UNDEFINED) {
325 325
         $this->provider_error_list[$provider_id] = $login_status;
326 326
       }
327 327
     }
328 328
 
329
-    if(empty($this->providers_authorised)) {
329
+    if (empty($this->providers_authorised)) {
330 330
       // Ни один аккаунт не авторизирован
331 331
       // Проверяем - есть ли у нас ошибки в аккаунтах?
332
-      if(!empty($this->provider_error_list)) {
332
+      if (!empty($this->provider_error_list)) {
333 333
         // Если есть - выводим их
334 334
         self::$login_status = reset($this->provider_error_list);
335 335
       }
@@ -344,12 +344,12 @@  discard block
 block discarded – undo
344 344
       // В self::$accessible_user_row_list - список доступных игроков для данных аккаунтов с соответствующими записями из таблицы `users`
345 345
 
346 346
       // Остались ли у нас в списке доступные игроки?
347
-      if(empty($this->accessible_user_row_list)) {
347
+      if (empty($this->accessible_user_row_list)) {
348 348
         // Нет ни одного игрока ни на одном авторизированном аккаунте
349 349
         // Надо регать нового игрока
350 350
 
351 351
         // Сейчас происходит процесс регистрации игрока?
352
-        if(!$this->is_player_register) {
352
+        if (!$this->is_player_register) {
353 353
           // Нет - отправляем на процесс регистрации
354 354
           $partner_id = sys_get_param_int('id_ref', sys_get_param_int('partner_id'));
355 355
           sys_redirect(SN_ROOT_VIRTUAL . 'index.php?page=player_register&player_register=1' . ($partner_id ? '&id_ref=' . $partner_id : ''));
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
         // Да, есть доступные игроки, которые так же прописаны в базе
359 359
         $this->get_active_user(); // 4.5
360 360
 
361
-        if($this->is_impersonating = !empty($_COOKIE[SN_COOKIE_U_I]) ? $_COOKIE[SN_COOKIE_U_I] : 0) {
361
+        if ($this->is_impersonating = !empty($_COOKIE[SN_COOKIE_U_I]) ? $_COOKIE[SN_COOKIE_U_I] : 0) {
362 362
           $a_user = db_user_by_id($this->is_impersonating);
363 363
           $this->impersonator_username = $a_user['username'];
364 364
         }
@@ -366,9 +366,9 @@  discard block
 block discarded – undo
366 366
 
367 367
         //Прописываем текущего игрока на все авторизированные аккаунты
368 368
         // TODO - ИЛИ ВСЕХ ИГРОКОВ??
369
-        if(empty($this->is_impersonating)) {
370
-          foreach($this->providers_authorised as $provider_id => $provider) {
371
-            if(empty($this->user_id_to_provider[self::$user['id']][$provider_id])) {
369
+        if (empty($this->is_impersonating)) {
370
+          foreach ($this->providers_authorised as $provider_id => $provider) {
371
+            if (empty($this->user_id_to_provider[self::$user['id']][$provider_id])) {
372 372
               // self::db_translate_register_user($provider_id, $provider->account->account_id, self::$user['id']);
373 373
               PlayerToAccountTranslate::db_translate_register_user($provider_id, $provider->account->account_id, self::$user['id']);
374 374
               $this->user_id_to_provider[self::$user['id']][$provider_id][$provider->account->account_id] = true;
@@ -378,9 +378,9 @@  discard block
 block discarded – undo
378 378
       }
379 379
     }
380 380
 
381
-    if(empty(self::$user['id'])) {
381
+    if (empty(self::$user['id'])) {
382 382
       self::cookie_set(''); // OK 4.5
383
-    } elseif(self::$user['id'] != $_COOKIE[SN_COOKIE_U]) {
383
+    } elseif (self::$user['id'] != $_COOKIE[SN_COOKIE_U]) {
384 384
       self::cookie_set(self::$user['id']); // OK 4.5
385 385
     }
386 386
 
@@ -399,21 +399,21 @@  discard block
 block discarded – undo
399 399
    */
400 400
   // OK v4.7
401 401
   public function logout($redirect = true) {
402
-    if(!empty($_COOKIE[SN_COOKIE_U_I])) {
402
+    if (!empty($_COOKIE[SN_COOKIE_U_I])) {
403 403
       self::cookie_set($_COOKIE[SN_COOKIE_U_I]);
404 404
       self::cookie_set(0, true);
405 405
       self::$main_provider->logout();
406 406
     } else {
407
-      foreach($this->providers as $provider_name => $provider) {
407
+      foreach ($this->providers as $provider_name => $provider) {
408 408
         $provider->logout();
409 409
       }
410 410
 
411 411
       self::cookie_set(0);
412 412
     }
413 413
 
414
-    if($redirect === true) {
414
+    if ($redirect === true) {
415 415
       sys_redirect(SN_ROOT_RELATIVE . (empty($_COOKIE[SN_COOKIE_U]) ? 'login.php' : 'admin/overview.php'));
416
-    } elseif($redirect !== false) {
416
+    } elseif ($redirect !== false) {
417 417
       sys_redirect($redirect);
418 418
     }
419 419
   }
@@ -424,15 +424,15 @@  discard block
 block discarded – undo
424 424
    * @param $user_selected
425 425
    */
426 426
   public function impersonate($user_selected) {
427
-    if($_COOKIE[SN_COOKIE_U_I]) {
427
+    if ($_COOKIE[SN_COOKIE_U_I]) {
428 428
       die('You already impersonating someone. Go back to living other\'s life! Or clear your cookies and try again'); // TODO: Log it
429 429
     }
430 430
 
431
-    if($this->auth_level_max_local < AUTH_LEVEL_ADMINISTRATOR) {
431
+    if ($this->auth_level_max_local < AUTH_LEVEL_ADMINISTRATOR) {
432 432
       die('You can\'t impersonate - too low level'); // TODO: Log it
433 433
     }
434 434
 
435
-    if($this->auth_level_max_local <= $user_selected['authlevel']) {
435
+    if ($this->auth_level_max_local <= $user_selected['authlevel']) {
436 436
       die('You can\'t impersonate this account - level is greater or equal to yours'); // TODO: Log it
437 437
     }
438 438
 
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
     $account_translate = reset($account_translate[$user_selected['id']][self::$main_provider->provider_id]);
441 441
     $account_to_impersonate = new Account(self::$main_provider->db);
442 442
     $account_to_impersonate->db_get_by_id($account_translate['provider_account_id']);
443
-    if(!$account_to_impersonate->is_exists) {
443
+    if (!$account_to_impersonate->is_exists) {
444 444
       die('Какая-то ошибка - не могу найти аккаунт для имперсонации'); // TODO: Log it
445 445
     }
446 446
     self::$main_provider->impersonate($account_to_impersonate);
@@ -466,12 +466,12 @@  discard block
 block discarded – undo
466 466
   public function password_check($password_unsafe) {
467 467
     $result = false;
468 468
 
469
-    if(empty($this->providers_authorised)) {
469
+    if (empty($this->providers_authorised)) {
470 470
       // TODO - такого быть не может!
471 471
       self::flog("password_check: Не найдено ни одного авторизированного провайдера в self::\$providers_authorised", true);
472 472
     } else {
473
-      foreach($this->providers_authorised as $provider_id => $provider) {
474
-        if($provider->is_feature_supported(AUTH_FEATURE_HAS_PASSWORD)) {
473
+      foreach ($this->providers_authorised as $provider_id => $provider) {
474
+        if ($provider->is_feature_supported(AUTH_FEATURE_HAS_PASSWORD)) {
475 475
           $result = $result || $provider->password_check($password_unsafe);
476 476
         }
477 477
       }
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
   public function password_change($old_password_unsafe, $new_password_unsafe) {
493 493
     global $lang;
494 494
 
495
-    if(empty($this->providers_authorised)) {
495
+    if (empty($this->providers_authorised)) {
496 496
       // TODO - такого быть не может!
497 497
       self::flog("Не найдено ни одного авторизированного провайдера в self::\$providers_authorised", true);
498 498
       return false;
@@ -505,8 +505,8 @@  discard block
 block discarded – undo
505 505
     $salt_unsafe = self::password_salt_generate();
506 506
 
507 507
     $providers_changed_password = array();
508
-    foreach($this->providers_authorised as $provider_id => $provider) {
509
-      if(
508
+    foreach ($this->providers_authorised as $provider_id => $provider) {
509
+      if (
510 510
         !$provider->is_feature_supported(AUTH_FEATURE_PASSWORD_CHANGE)
511 511
         || !$provider->password_change($old_password_unsafe, $new_password_unsafe, $salt_unsafe)
512 512
       ) {
@@ -518,7 +518,7 @@  discard block
 block discarded – undo
518 518
       $account_translation = PlayerToAccountTranslate::db_translate_get_users_from_account_list($provider_id, $provider->account->account_id);
519 519
 
520 520
       // Рассылаем уведомления о смене пароля в ЛС
521
-      foreach($account_translation as $user_id => $provider_info) {
521
+      foreach ($account_translation as $user_id => $provider_info) {
522 522
         // TODO - УКазывать тип аккаунта, на котором сменён пароль
523 523
         msg_send_simple_message($user_id, 0, SN_TIME_NOW, MSG_TYPE_ADMIN,
524 524
           $lang['sys_administration'], $lang['sys_login_register_message_title'],
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
       sn_db_transaction_start();
566 566
       // Проверить наличие такого имени в истории имён
567 567
 
568
-      if(db_player_name_exists($player_name_unsafe)) {
568
+      if (db_player_name_exists($player_name_unsafe)) {
569 569
         throw new Exception(REGISTER_ERROR_PLAYER_NAME_EXISTS, ERR_ERROR);
570 570
       }
571 571
 
@@ -573,11 +573,11 @@  discard block
 block discarded – undo
573 573
       $player_language = '';
574 574
       $player_email = '';
575 575
       // TODO - порнография - работа должна происходить над списком аккаунтов, а не только на одном аккаунте...
576
-      foreach($this->providers_authorised as $provider) {
577
-        if(!$player_language && $provider->account->account_language) {
576
+      foreach ($this->providers_authorised as $provider) {
577
+        if (!$player_language && $provider->account->account_language) {
578 578
           $player_language = $provider->account->account_language;
579 579
         }
580
-        if(!$player_email && $provider->account->account_email) {
580
+        if (!$player_email && $provider->account->account_email) {
581 581
           $player_email = $provider->account->account_email;
582 582
         }
583 583
       }
@@ -593,7 +593,7 @@  discard block
 block discarded – undo
593 593
       ));
594 594
       // Зарегестрировать на него аккаунты из self::$accounts_authorised
595 595
       $a_user = self::$user;
596
-      foreach($this->providers_authorised as $provider) {
596
+      foreach ($this->providers_authorised as $provider) {
597 597
         // TODO - порнография. Должен быть отдельный класс трансляторов - в т.ч. и кэширующий транслятор
598 598
         // TODO - ну и работа должна происходить над списком аккаунтов, а не только на одном аккаунте...
599 599
         // self::db_translate_register_user($provider->provider_id, $provider->account->account_id, $a_user['id']);
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
 
606 606
       sn_db_transaction_commit();
607 607
       $this->register_status = LOGIN_SUCCESS;
608
-    } catch(Exception $e) {
608
+    } catch (Exception $e) {
609 609
       sn_db_transaction_rollback();
610 610
 
611 611
       // Если старое имя занято
@@ -624,10 +624,10 @@  discard block
 block discarded – undo
624 624
     // Пробиваем все ИД игроков по базе - есть ли вообще такие записи
625 625
     // Вообще-то это не особо нужно - у нас по определению стоят констраинты
626 626
     // Зато так мы узнаем максимальный authlevel, проверим права имперсонейта и вытащим все записи юзеров
627
-    foreach($this->user_id_to_provider as $user_id => $cork) {
627
+    foreach ($this->user_id_to_provider as $user_id => $cork) {
628 628
       $user = db_user_by_id($user_id);
629 629
       // Если записи игрока в БД не существует?
630
-      if(empty($user['id'])) {
630
+      if (empty($user['id'])) {
631 631
         // Удаляем этого и переходим к следующему
632 632
         unset($this->user_id_to_provider[$user_id]);
633 633
         // Де-регистрируем игрока из таблицы трансляции игроков
@@ -648,7 +648,7 @@  discard block
 block discarded – undo
648 648
   // OK v4.5
649 649
   protected function get_active_user() {
650 650
     // Проверяем куку "текущего игрока" из браузера
651
-    if(
651
+    if (
652 652
       // Кука не пустая
653 653
       ($_COOKIE[SN_COOKIE_U] = trim($_COOKIE[SN_COOKIE_U])) && !empty($_COOKIE[SN_COOKIE_U])
654 654
       // И в куке находится ID
@@ -673,7 +673,7 @@  discard block
 block discarded – undo
673 673
     }
674 674
 
675 675
     // В куке нет валидного ИД записи игрока, доступной с текущих аккаунтов
676
-    if(empty(self::$user['id'])) {
676
+    if (empty(self::$user['id'])) {
677 677
       // Берем первого из доступных
678 678
       // TODO - default_user
679 679
       self::$user = reset($this->accessible_user_row_list);
@@ -697,7 +697,7 @@  discard block
 block discarded – undo
697 697
 
698 698
     $result = array();
699 699
 
700
-    if($user_id && empty($this->is_impersonating)) {
700
+    if ($user_id && empty($this->is_impersonating)) {
701 701
       // self::db_counter_insert();
702 702
       self::$device->db_counter_insert($user_id);
703 703
 
@@ -705,12 +705,12 @@  discard block
 block discarded – undo
705 705
 
706 706
       sys_user_options_unpack($user);
707 707
 
708
-      if($user['banaday'] && $user['banaday'] <= SN_TIME_NOW) {
708
+      if ($user['banaday'] && $user['banaday'] <= SN_TIME_NOW) {
709 709
         $user['banaday'] = 0;
710 710
         $user['vacation'] = SN_TIME_NOW;
711 711
       }
712 712
 
713
-      $user['user_lastip'] = self::$device->ip_v4_string;// $ip['ip'];
713
+      $user['user_lastip'] = self::$device->ip_v4_string; // $ip['ip'];
714 714
       $user['user_proxy'] = self::$device->ip_v4_proxy_chain; //$ip['proxy_chain'];
715 715
 
716 716
       $result[F_BANNED_STATUS] = $user['banaday'];
@@ -724,9 +724,9 @@  discard block
 block discarded – undo
724 724
       );
725 725
     }
726 726
 
727
-    if($extra = $config->security_ban_extra) {
727
+    if ($extra = $config->security_ban_extra) {
728 728
       $extra = explode(',', $extra);
729
-      array_walk($extra,'trim');
729
+      array_walk($extra, 'trim');
730 730
       in_array(self::$device->device_id, $extra) and die();
731 731
     }
732 732
 
@@ -762,21 +762,21 @@  discard block
 block discarded – undo
762 762
   protected function register_player_name_validate($player_name_unsafe) {
763 763
     // TODO - переделать под RAW-строки
764 764
     // Если имя игрока пустое - NO GO!
765
-    if(trim($player_name_unsafe) == '') {
765
+    if (trim($player_name_unsafe) == '') {
766 766
       throw new Exception(REGISTER_ERROR_PLAYER_NAME_EMPTY, ERR_ERROR);
767 767
     }
768 768
     // Проверяем, что бы в начале и конце не было пустых символов
769
-    if($player_name_unsafe != trim($player_name_unsafe)) {
769
+    if ($player_name_unsafe != trim($player_name_unsafe)) {
770 770
       throw new Exception(REGISTER_ERROR_PLAYER_NAME_TRIMMED, ERR_ERROR);
771 771
     }
772 772
     // Если логин имеет запрещенные символы - NO GO!
773
-    if(strpbrk($player_name_unsafe, LOGIN_REGISTER_CHARACTERS_PROHIBITED)) {
773
+    if (strpbrk($player_name_unsafe, LOGIN_REGISTER_CHARACTERS_PROHIBITED)) {
774 774
       // TODO - выдавать в сообщение об ошибке список запрещенных символов
775 775
       // TODO - заранее извещать игрока, какие символы являются запрещенными
776 776
       throw new Exception(REGISTER_ERROR_PLAYER_NAME_RESTRICTED_CHARACTERS, ERR_ERROR);
777 777
     }
778 778
     // Если логин меньше минимальной длины - NO GO!
779
-    if(strlen($player_name_unsafe) < LOGIN_LENGTH_MIN) {
779
+    if (strlen($player_name_unsafe) < LOGIN_LENGTH_MIN) {
780 780
       // TODO - выдавать в сообщение об ошибке минимальную длину имени игрока
781 781
       // TODO - заранее извещать игрока, какая минимальная и максимальная длина имени
782 782
       throw new Exception(REGISTER_ERROR_PLAYER_NAME_SHORT, ERR_ERROR);
@@ -834,7 +834,7 @@  discard block
 block discarded – undo
834 834
   }
835 835
 
836 836
   protected static function flog($message, $die = false) {
837
-    if(!defined('DEBUG_AUTH') || !DEBUG_AUTH) {
837
+    if (!defined('DEBUG_AUTH') || !DEBUG_AUTH) {
838 838
       return;
839 839
     }
840 840
     list($called, $caller) = debug_backtrace(false);
@@ -847,7 +847,7 @@  discard block
 block discarded – undo
847 847
     $_SERVER['SERVER_NAME'] == 'localhost' ? print("<div class='debug'>$message - $caller_name\r\n</div>") : false;
848 848
 
849 849
     classSupernova::log_file("$message - $caller_name");
850
-    if($die) {
850
+    if ($die) {
851 851
       // pdump($caller);
852 852
       // pdump(debug_backtrace(false));
853 853
       $die && die("<div class='negative'>СТОП! Функция {$caller_name} при вызове в " . get_called_class() . " (располагается в " . get_class() . "). СООБЩИТЕ АДМИНИСТРАЦИИ!</div>");
Please login to merge, or discard this patch.
includes/init.php 1 patch
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 // Защита от двойного инита
4
-if(defined('INIT')) {
4
+if (defined('INIT')) {
5 5
   return;
6 6
 }
7 7
 
@@ -20,8 +20,8 @@  discard block
 block discarded – undo
20 20
 version_compare(PHP_VERSION, '5.3.2') < 0 ? die('FATAL ERROR: SuperNova REQUIRE PHP version > 5.3.2') : false;
21 21
 
22 22
 // Бенчмарк
23
-register_shutdown_function(function () {
24
-  if(defined('IN_AJAX')) {
23
+register_shutdown_function(function() {
24
+  if (defined('IN_AJAX')) {
25 25
     return;
26 26
   }
27 27
 
@@ -31,11 +31,11 @@  discard block
 block discarded – undo
31 31
     (!empty($locale_cache_statistic['misses']) ? ', LOCALE MISSED' : '') .
32 32
     (class_exists('classSupernova') && is_object(classSupernova::$db) ? ', DB time: ' . classSupernova::$db->time_mysql_total . 'ms' : '') .
33 33
     '</div>');
34
-  if($user['authlevel'] >= 2 && file_exists(SN_ROOT_PHYSICAL . 'badqrys.txt') && @filesize(SN_ROOT_PHYSICAL . 'badqrys.txt') > 0) {
34
+  if ($user['authlevel'] >= 2 && file_exists(SN_ROOT_PHYSICAL . 'badqrys.txt') && @filesize(SN_ROOT_PHYSICAL . 'badqrys.txt') > 0) {
35 35
     echo '<a href="badqrys.txt" target="_blank" style="color:red">', 'HACK ALERT!', '</a>';
36 36
   }
37 37
 
38
-  if(!empty($locale_cache_statistic['misses'])) {
38
+  if (!empty($locale_cache_statistic['misses'])) {
39 39
     print('<!--');
40 40
     pdump($locale_cache_statistic);
41 41
     print('-->');
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 
56 56
 define('SN_TIME_NOW_GMT_STRING', gmdate(DATE_ATOM, SN_TIME_NOW));
57 57
 
58
-if(strpos(strtolower($_SERVER['SERVER_NAME']), 'google.') !== false) {
58
+if (strpos(strtolower($_SERVER['SERVER_NAME']), 'google.') !== false) {
59 59
   define('SN_GOOGLE', true);
60 60
 }
61 61
 
@@ -105,14 +105,14 @@  discard block
 block discarded – undo
105 105
 $debug = new debug();
106 106
 classSupernova::debug_set_handler($debug);
107 107
 
108
-spl_autoload_register(function ($class) {
109
-  if(file_exists(SN_ROOT_PHYSICAL . 'includes/classes/' . $class . '.php')) {
108
+spl_autoload_register(function($class) {
109
+  if (file_exists(SN_ROOT_PHYSICAL . 'includes/classes/' . $class . '.php')) {
110 110
     require_once SN_ROOT_PHYSICAL . 'includes/classes/' . $class . '.php';
111 111
   }
112 112
 });
113 113
 
114
-spl_autoload_register(function ($class) {
115
-  if(file_exists(SN_ROOT_PHYSICAL . 'includes/classes/UBE/' . $class . '.php')) {
114
+spl_autoload_register(function($class) {
115
+  if (file_exists(SN_ROOT_PHYSICAL . 'includes/classes/UBE/' . $class . '.php')) {
116 116
     require_once SN_ROOT_PHYSICAL . 'includes/classes/UBE/' . $class . '.php';
117 117
   }
118 118
 });
@@ -177,10 +177,10 @@  discard block
 block discarded – undo
177 177
 
178 178
 sn_sys_load_php_files(SN_ROOT_PHYSICAL . "includes/functions/", PHP_EX);
179 179
 
180
-spl_autoload_register(function ($class) {
181
-  if(file_exists('includes/classes/' . $class . '.php')) {
180
+spl_autoload_register(function($class) {
181
+  if (file_exists('includes/classes/' . $class . '.php')) {
182 182
     require_once 'includes/classes/' . $class . '.php';
183
-  } elseif(file_exists('includes/classes/UBE/' . $class . '.php')) {
183
+  } elseif (file_exists('includes/classes/UBE/' . $class . '.php')) {
184 184
     require_once 'includes/classes/UBE/' . $class . '.php';
185 185
   } else {
186 186
 //    die("Can't find {$class} class");
@@ -214,9 +214,9 @@  discard block
 block discarded – undo
214 214
 // Но нужно, пока у нас есть не MVC-страницы
215 215
 $sn_page_data = $sn_data['pages'][$sn_page_name];
216 216
 $sn_page_name_file = 'includes/pages/' . $sn_page_data['filename'] . DOT_PHP_EX;
217
-if($sn_page_name && isset($sn_page_data) && file_exists($sn_page_name_file)) {
217
+if ($sn_page_name && isset($sn_page_data) && file_exists($sn_page_name_file)) {
218 218
   require_once($sn_page_name_file);
219
-  if(is_array($sn_page_data['options'])) {
219
+  if (is_array($sn_page_data['options'])) {
220 220
     $supernova->options = array_merge($supernova->options, $sn_page_data['options']);
221 221
   }
222 222
 }
@@ -231,10 +231,10 @@  discard block
 block discarded – undo
231 231
 $load_order = array();
232 232
 $sn_req = array();
233 233
 
234
-foreach(sn_module::$sn_module as $loaded_module_name => $module_data) {
234
+foreach (sn_module::$sn_module as $loaded_module_name => $module_data) {
235 235
   $load_order[$loaded_module_name] = isset($module_data->manifest['load_order']) && !empty($module_data->manifest['load_order']) ? $module_data->manifest['load_order'] : 100000;
236
-  if(isset($module_data->manifest['require']) && !empty($module_data->manifest['require'])) {
237
-    foreach($module_data->manifest['require'] as $require_name) {
236
+  if (isset($module_data->manifest['require']) && !empty($module_data->manifest['require'])) {
237
+    foreach ($module_data->manifest['require'] as $require_name) {
238 238
       $sn_req[$loaded_module_name][$require_name] = 0;
239 239
     }
240 240
   }
@@ -247,10 +247,10 @@  discard block
 block discarded – undo
247 247
 do {
248 248
   $prev_order = $load_order;
249 249
 
250
-  foreach($sn_req as $loaded_module_name => &$req_data) {
250
+  foreach ($sn_req as $loaded_module_name => &$req_data) {
251 251
     $level = 1;
252
-    foreach($req_data as $req_name => &$req_level) {
253
-      if($load_order[$req_name] == -1 || !isset($load_order[$req_name])) {
252
+    foreach ($req_data as $req_name => &$req_level) {
253
+      if ($load_order[$req_name] == -1 || !isset($load_order[$req_name])) {
254 254
         $level = $req_level = -1;
255 255
         break;
256 256
       } else {
@@ -258,20 +258,20 @@  discard block
 block discarded – undo
258 258
       }
259 259
       $req_level = $load_order[$req_name];
260 260
     }
261
-    if($level > $load_order[$loaded_module_name] || $level == -1) {
261
+    if ($level > $load_order[$loaded_module_name] || $level == -1) {
262 262
       $load_order[$loaded_module_name] = $level;
263 263
     }
264 264
   }
265
-} while($prev_order != $load_order);
265
+} while ($prev_order != $load_order);
266 266
 
267 267
 asort($load_order);
268 268
 
269 269
 // Инициализируем модули
270 270
 // По нормальным делам это должна быть загрузка модулей и лишь затем инициализация - что бы минимизировать размер процесса в памяти
271
-foreach($load_order as $loaded_module_name => $load_order_order) {
272
-  if($load_order_order >= 0) {
271
+foreach ($load_order as $loaded_module_name => $load_order_order) {
272
+  if ($load_order_order >= 0) {
273 273
     sn_module::$sn_module[$loaded_module_name]->check_status();
274
-    if(!sn_module::$sn_module[$loaded_module_name]->manifest['active']) {
274
+    if (!sn_module::$sn_module[$loaded_module_name]->manifest['active']) {
275 275
       unset(sn_module::$sn_module[$loaded_module_name]);
276 276
       continue;
277 277
     }
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
 unset($sn_req);
289 289
 
290 290
 // А теперь проверяем - поддерживают ли у нас загруженный код такую страницу
291
-if(!isset($sn_data['pages'][$sn_page_name])) {
291
+if (!isset($sn_data['pages'][$sn_page_name])) {
292 292
   $sn_page_name = '';
293 293
 }
294 294
 
@@ -296,6 +296,6 @@  discard block
 block discarded – undo
296 296
 $lang = new classLocale($config->server_locale_log_usage);
297 297
 $lang->lng_switch(sys_get_param_str('lang'));
298 298
 
299
-if(!defined('DEBUG_INIT_SKIP_SECONDARY') || DEBUG_INIT_SKIP_SECONDARY !== true) {
299
+if (!defined('DEBUG_INIT_SKIP_SECONDARY') || DEBUG_INIT_SKIP_SECONDARY !== true) {
300 300
   require_once "init_secondary.php";
301 301
 }
Please login to merge, or discard this patch.
includes/template.php 1 patch
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 function gettemplatename($u_dpath) {
11 11
   static $template_names = array();
12 12
 
13
-  if(!isset($template_names[$u_dpath])) {
13
+  if (!isset($template_names[$u_dpath])) {
14 14
     $template_names[$u_dpath] = file_exists(SN_ROOT_PHYSICAL . $u_dpath . 'tmpl.ini') ? sys_file_read(SN_ROOT_PHYSICAL . $u_dpath . 'tmpl.ini') : TEMPLATE_NAME;
15 15
   }
16 16
 
@@ -52,12 +52,12 @@  discard block
 block discarded – undo
52 52
  * @param $sn_menu_extra
53 53
  */
54 54
 function tpl_menu_merge_extra(&$sn_menu, &$sn_menu_extra) {
55
-  if(empty($sn_menu) || empty($sn_menu_extra)) {
55
+  if (empty($sn_menu) || empty($sn_menu_extra)) {
56 56
     return;
57 57
   }
58 58
 
59
-  foreach($sn_menu_extra as $menu_item_id => $menu_item) {
60
-    if(empty($menu_item['LOCATION'])) {
59
+  foreach ($sn_menu_extra as $menu_item_id => $menu_item) {
60
+    if (empty($menu_item['LOCATION'])) {
61 61
       $sn_menu[$menu_item_id] = $menu_item;
62 62
       continue;
63 63
     }
@@ -66,16 +66,16 @@  discard block
 block discarded – undo
66 66
     unset($menu_item['LOCATION']);
67 67
 
68 68
     $is_positioned = $item_location[0];
69
-    if($is_positioned == '+' || $is_positioned == '-') {
69
+    if ($is_positioned == '+' || $is_positioned == '-') {
70 70
       $item_location = substr($item_location, 1);
71 71
     } else {
72 72
       $is_positioned = '';
73 73
     }
74 74
 
75
-    if($item_location) {
75
+    if ($item_location) {
76 76
       $menu_keys = array_keys($sn_menu);
77 77
       $insert_position = array_search($item_location, $menu_keys);
78
-      if($insert_position === false) {
78
+      if ($insert_position === false) {
79 79
         $insert_position = count($sn_menu) - 1;
80 80
         $is_positioned = '+';
81 81
         $item_location = '';
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
     $spliced = array_splice($sn_menu, $insert_position, count($sn_menu) - $insert_position);
89 89
     $sn_menu[$menu_item_id] = $menu_item;
90 90
 
91
-    if(!$is_positioned && $item_location) {
91
+    if (!$is_positioned && $item_location) {
92 92
       unset($spliced[$item_location]);
93 93
     }
94 94
     $sn_menu = array_merge($sn_menu, $spliced);
@@ -104,24 +104,24 @@  discard block
 block discarded – undo
104 104
 function tpl_menu_assign_to_template(&$sn_menu, &$template) {
105 105
   global $lang;
106 106
 
107
-  if(empty($sn_menu) || !is_array($sn_menu)) {
107
+  if (empty($sn_menu) || !is_array($sn_menu)) {
108 108
     return;
109 109
   }
110 110
 
111
-  foreach($sn_menu as $menu_item_id => $menu_item) {
112
-    if(!$menu_item) {
111
+  foreach ($sn_menu as $menu_item_id => $menu_item) {
112
+    if (!$menu_item) {
113 113
       continue;
114 114
     }
115 115
 
116
-    if(is_string($menu_item_id)) {
116
+    if (is_string($menu_item_id)) {
117 117
       $menu_item['ID'] = $menu_item_id;
118 118
     }
119 119
 
120
-    if($menu_item['TYPE'] == 'lang') {
120
+    if ($menu_item['TYPE'] == 'lang') {
121 121
       $lang_string = &$lang;
122
-      if(preg_match('#(\w+)(?:\[(\w+)\])?(?:\[(\w+)\])?(?:\[(\w+)\])?(?:\[(\w+)\])?#', $menu_item['ITEM'], $matches) && count($matches) > 1) {
123
-        for($i = 1; $i < count($matches); $i++) {
124
-          if(defined($matches[$i])) {
122
+      if (preg_match('#(\w+)(?:\[(\w+)\])?(?:\[(\w+)\])?(?:\[(\w+)\])?(?:\[(\w+)\])?#', $menu_item['ITEM'], $matches) && count($matches) > 1) {
123
+        for ($i = 1; $i < count($matches); $i++) {
124
+          if (defined($matches[$i])) {
125 125
             $matches[$i] = constant($matches[$i]);
126 126
           }
127 127
           $lang_string = &$lang_string[$matches[$i]];
@@ -133,8 +133,8 @@  discard block
 block discarded – undo
133 133
     $menu_item['ALT'] = htmlentities($menu_item['ALT']);
134 134
     $menu_item['TITLE'] = htmlentities($menu_item['TITLE']);
135 135
 
136
-    if(!empty($menu_item['ICON'])) {
137
-      if(is_string($menu_item['ICON'])) {
136
+    if (!empty($menu_item['ICON'])) {
137
+      if (is_string($menu_item['ICON'])) {
138 138
         $menu_item['ICON_PATH'] = $menu_item['ICON'];
139 139
       } else {
140 140
         $menu_item['ICON'] = $menu_item_id;
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
     'MENU_START_HIDE'     => !empty($_COOKIE[SN_COOKIE . '_menu_hidden']) || defined('SN_GOOGLE'),
165 165
   ));
166 166
 
167
-  if(isset($template_result['MENU_CUSTOMIZE'])) {
167
+  if (isset($template_result['MENU_CUSTOMIZE'])) {
168 168
     $template->assign_vars(array(
169 169
       'PLAYER_OPTION_MENU_SHOW_ON_BUTTON'   => classSupernova::$user_options[PLAYER_OPTION_MENU_SHOW_ON_BUTTON],
170 170
       'PLAYER_OPTION_MENU_HIDE_ON_BUTTON'   => classSupernova::$user_options[PLAYER_OPTION_MENU_HIDE_ON_BUTTON],
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
     ));
179 179
   }
180 180
 
181
-  if(defined('IN_ADMIN') && IN_ADMIN === true && !empty($user['authlevel']) && $user['authlevel'] > 0) {
181
+  if (defined('IN_ADMIN') && IN_ADMIN === true && !empty($user['authlevel']) && $user['authlevel'] > 0) {
182 182
     tpl_menu_merge_extra($sn_menu_admin, $sn_menu_admin_extra);
183 183
     tpl_menu_assign_to_template($sn_menu_admin, $template);
184 184
   } else {
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
   $in_admin = defined('IN_ADMIN') && IN_ADMIN === true;
219 219
   $is_login = defined('LOGIN_LOGOUT') && LOGIN_LOGOUT === true;
220 220
 
221
-  if(is_object($page)) {
221
+  if (is_object($page)) {
222 222
     isset($page->_rootref['MENU']) ? $isDisplayMenu = $page->_rootref['MENU'] : false;
223 223
     isset($page->_rootref['NAVBAR']) ? $isDisplayTopNav = $page->_rootref['NAVBAR'] : false;
224 224
 
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
     !isset($page->_rootref['PAGE_HEADER']) && $title ? $page->assign_var('PAGE_HEADER', $title) : false;
227 227
   }
228 228
 
229
-  if(empty($user['id']) || !is_numeric($user['id'])) {
229
+  if (empty($user['id']) || !is_numeric($user['id'])) {
230 230
     $isDisplayMenu = false;
231 231
     $isDisplayTopNav = false;
232 232
   }
@@ -238,10 +238,10 @@  discard block
 block discarded – undo
238 238
   $user_time_measured_unix = intval(isset($user_time_diff[PLAYER_OPTION_TIME_DIFF_MEASURE_TIME]) ? strtotime($user_time_diff[PLAYER_OPTION_TIME_DIFF_MEASURE_TIME]) : 0);
239 239
 
240 240
   $font_size = !empty($_COOKIE[SN_COOKIE_F]) ? $_COOKIE[SN_COOKIE_F] : classSupernova::$user_options[PLAYER_OPTION_BASE_FONT_SIZE];
241
-  if(strpos($font_size, '%') !== false) {
241
+  if (strpos($font_size, '%') !== false) {
242 242
     // Размер шрифта в процентах
243 243
     $font_size = min(max(floatval($font_size), FONT_SIZE_PERCENT_MIN), FONT_SIZE_PERCENT_MAX) . '%';
244
-  } elseif(strpos($font_size, 'px') !== false) {
244
+  } elseif (strpos($font_size, 'px') !== false) {
245 245
     // Размер шрифта в пикселях
246 246
     $font_size = min(max(floatval($font_size), FONT_SIZE_PIXELS_MIN), FONT_SIZE_PIXELS_MAX) . 'px';
247 247
   } else {
@@ -253,10 +253,10 @@  discard block
 block discarded – undo
253 253
 
254 254
   $template = gettemplate('_global_header', true);
255 255
 
256
-  if(!empty(classSupernova::$sn_mvc['javascript'])) {
257
-    foreach(classSupernova::$sn_mvc['javascript'] as $page_name => $script_list) {
258
-      if(empty($page_name) || $page_name == $sn_page_name) {
259
-        foreach($script_list as $filename => $content) {
256
+  if (!empty(classSupernova::$sn_mvc['javascript'])) {
257
+    foreach (classSupernova::$sn_mvc['javascript'] as $page_name => $script_list) {
258
+      if (empty($page_name) || $page_name == $sn_page_name) {
259
+        foreach ($script_list as $filename => $content) {
260 260
           $template_result['.']['javascript'][] = array(
261 261
             'FILE'    => $filename,
262 262
             'CONTENT' => $content,
@@ -282,9 +282,9 @@  discard block
 block discarded – undo
282 282
   classSupernova::$sn_mvc['css'][''] = array_merge($standard_css, classSupernova::$sn_mvc['css']['']);
283 283
 
284 284
 
285
-  foreach(classSupernova::$sn_mvc['css'] as $page_name => $script_list) {
286
-    if(empty($page_name) || $page_name == $sn_page_name) {
287
-      foreach($script_list as $filename => $content) {
285
+  foreach (classSupernova::$sn_mvc['css'] as $page_name => $script_list) {
286
+    if (empty($page_name) || $page_name == $sn_page_name) {
287
+      foreach ($script_list as $filename => $content) {
288 288
         $template_result['.']['css'][] = array(
289 289
           'FILE'    => $filename,
290 290
           'CONTENT' => $content,
@@ -331,12 +331,12 @@  discard block
 block discarded – undo
331 331
   $template->assign_recursive($template_result);
332 332
   displayP(parsetemplate($template));
333 333
 
334
-  if(($isDisplayMenu || $in_admin) && !isset($_COOKIE['menu_disable'])) {
334
+  if (($isDisplayMenu || $in_admin) && !isset($_COOKIE['menu_disable'])) {
335 335
     // $AdminPage = $AdminPage ? $user['authlevel'] : 0;
336 336
     displayP(parsetemplate(tpl_render_menu()));
337 337
   }
338 338
 
339
-  if($isDisplayTopNav && !$in_admin) {
339
+  if ($isDisplayTopNav && !$in_admin) {
340 340
     displayP(parsetemplate(tpl_render_topnav($user, $planetrow)));
341 341
   }
342 342
 
@@ -344,8 +344,8 @@  discard block
 block discarded – undo
344 344
 
345 345
   !is_array($page) ? $page = array($page) : false;
346 346
   $result_added = false;
347
-  foreach($page as $page_item) {
348
-    if(!$result_added && is_object($page_item) && isset($page_item->_tpldata['result'])) {
347
+  foreach ($page as $page_item) {
348
+    if (!$result_added && is_object($page_item) && isset($page_item->_tpldata['result'])) {
349 349
       $page_item = gettemplate('_result_message', $page_item);
350 350
       $temp = $page_item->files['_result_message'];
351 351
       unset($page_item->files['_result_message']);
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
   ));
369 369
   displayP(parsetemplate($template));
370 370
 
371
-  $user['authlevel'] >= 3 && $config->debug ? $debug->echo_log() : false;;
371
+  $user['authlevel'] >= 3 && $config->debug ? $debug->echo_log() : false; ;
372 372
 
373 373
   sn_db_disconnect();
374 374
 
@@ -406,7 +406,7 @@  discard block
 block discarded – undo
406 406
  * @param string         $type
407 407
  */
408 408
 function tpl_topnav_event_build(&$template, $FleetList, $type = 'fleet') {
409
-  if(empty($FleetList)) {
409
+  if (empty($FleetList)) {
410 410
     return;
411 411
   }
412 412
 
@@ -415,19 +415,19 @@  discard block
 block discarded – undo
415 415
   $fleet_event_count = 0;
416 416
   $fleet_flying_sorter = array();
417 417
   $fleet_flying_events = array();
418
-  foreach($FleetList->_container as $objFleet) {
418
+  foreach ($FleetList->_container as $objFleet) {
419 419
     $will_return = true;
420
-    if(!$objFleet->isReturning()) {
420
+    if (!$objFleet->isReturning()) {
421 421
       // cut fleets on Hold and Expedition
422
-      if($objFleet->time_arrive_to_target >= SN_TIME_NOW) {
422
+      if ($objFleet->time_arrive_to_target >= SN_TIME_NOW) {
423 423
         $objFleet->mission_type == MT_RELOCATE ? $will_return = false : false;
424 424
         tpl_topnav_event_build_helper($objFleet->time_arrive_to_target, EVENT_FLEET_ARRIVE, $lang['sys_event_arrive'], $objFleet->target_coordinates_typed(), !$will_return, $objFleet, $fleet_flying_sorter, $fleet_flying_events, $fleet_event_count);
425 425
       }
426
-      if($objFleet->time_mission_job_complete) {
426
+      if ($objFleet->time_mission_job_complete) {
427 427
         tpl_topnav_event_build_helper($objFleet->time_mission_job_complete, EVENT_FLEET_STAY, $lang['sys_event_stay'], $objFleet->target_coordinates_typed(), false, $objFleet, $fleet_flying_sorter, $fleet_flying_events, $fleet_event_count);
428 428
       }
429 429
     }
430
-    if($will_return) {
430
+    if ($will_return) {
431 431
       tpl_topnav_event_build_helper($objFleet->time_return_to_source, EVENT_FLEET_RETURN, $lang['sys_event_return'], $objFleet->launch_coordinates_typed(), true, $objFleet, $fleet_flying_sorter, $fleet_flying_events, $fleet_event_count);
432 432
     }
433 433
   }
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
   asort($fleet_flying_sorter);
436 436
 
437 437
   $fleet_flying_count = $FleetList->count();
438
-  foreach($fleet_flying_sorter as $fleet_event_id => $fleet_time) {
438
+  foreach ($fleet_flying_sorter as $fleet_event_id => $fleet_time) {
439 439
     $fleet_event = &$fleet_flying_events[$fleet_event_id];
440 440
     $template->assign_block_vars("flying_{$type}s", array(
441 441
       'TIME' => max(0, $fleet_time - SN_TIME_NOW),
@@ -463,7 +463,7 @@  discard block
 block discarded – undo
463 463
 function sn_tpl_render_topnav(&$user, $planetrow) {
464 464
   global $lang, $config, $template_result;
465 465
 
466
-  if(!is_array($user)) {
466
+  if (!is_array($user)) {
467 467
     return '';
468 468
   }
469 469
 
@@ -484,8 +484,8 @@  discard block
 block discarded – undo
484 484
 
485 485
   $ThisUsersPlanets = db_planet_list_sorted($user);
486 486
   // while ($CurPlanet = db_fetch($ThisUsersPlanets))
487
-  foreach($ThisUsersPlanets as $CurPlanet) {
488
-    if($CurPlanet['destruyed']) {
487
+  foreach ($ThisUsersPlanets as $CurPlanet) {
488
+    if ($CurPlanet['destruyed']) {
489 489
       continue;
490 490
     }
491 491
 
@@ -509,8 +509,8 @@  discard block
 block discarded – undo
509 509
    */
510 510
   $fleet_flying_list = array();
511 511
   $fleet_flying_list[0] = FleetList::dbGetFleetListByOwnerId($user['id']);
512
-  foreach($fleet_flying_list[0]->_container as $fleet_id => $objFleet) {
513
-    if(empty($fleet_flying_list[$objFleet->mission_type])) {
512
+  foreach ($fleet_flying_list[0]->_container as $fleet_id => $objFleet) {
513
+    if (empty($fleet_flying_list[$objFleet->mission_type])) {
514 514
       $fleet_flying_list[$objFleet->mission_type] = new FleetList();
515 515
     }
516 516
     $fleet_flying_list[$objFleet->mission_type][$fleet_id] = $objFleet;
@@ -522,8 +522,8 @@  discard block
 block discarded – undo
522 522
   que_tpl_parse($template, QUE_RESEARCH, $user, array(), null, !classSupernova::$user_options[PLAYER_OPTION_NAVBAR_RESEARCH_WIDE]);
523 523
   que_tpl_parse($template, SUBQUE_FLEET, $user, $planetrow, null, true);
524 524
 
525
-  if(!empty(classSupernova::$sn_mvc['navbar_prefix_button']) && is_array(classSupernova::$sn_mvc['navbar_prefix_button'])) {
526
-    foreach(classSupernova::$sn_mvc['navbar_prefix_button'] as $navbar_button_image => $navbar_button_url) {
525
+  if (!empty(classSupernova::$sn_mvc['navbar_prefix_button']) && is_array(classSupernova::$sn_mvc['navbar_prefix_button'])) {
526
+    foreach (classSupernova::$sn_mvc['navbar_prefix_button'] as $navbar_button_image => $navbar_button_url) {
527 527
       $template->assign_block_vars('navbar_prefix_button', array(
528 528
         'IMAGE'        => $navbar_button_image,
529 529
         'URL_RELATIVE' => $navbar_button_url,
@@ -537,13 +537,13 @@  discard block
 block discarded – undo
537 537
   $time_now_parsed = getdate(SN_TIME_NOW);
538 538
   $time_local_parsed = getdate(defined('SN_CLIENT_TIME_LOCAL') ? SN_CLIENT_TIME_LOCAL : SN_TIME_NOW);
539 539
 
540
-  if($config->game_news_overview) {
540
+  if ($config->game_news_overview) {
541 541
     $user_last_read_safe = intval($user['news_lastread']);
542 542
     nws_render($template, "WHERE UNIX_TIMESTAMP(`tsTimeStamp`) >= {$user_last_read_safe}", $config->game_news_overview);
543 543
   }
544 544
 
545 545
   $notes_query = db_note_list_by_owner($user['id'], true);
546
-  while($note_row = db_fetch($notes_query)) {
546
+  while ($note_row = db_fetch($notes_query)) {
547 547
     note_assign($template, $note_row);
548 548
   }
549 549
 
@@ -554,7 +554,7 @@  discard block
 block discarded – undo
554 554
     'QUE_ID'   => QUE_RESEARCH,
555 555
     'QUE_HTML' => 'topnav',
556 556
 
557
-    'RESEARCH_ONGOING' => (boolean)$user['que'],
557
+    'RESEARCH_ONGOING' => (boolean) $user['que'],
558 558
 
559 559
     'TIME_TEXT'       => sprintf($str_date_format, $time_now_parsed['year'], $lang['months'][$time_now_parsed['mon']], $time_now_parsed['mday'],
560 560
       $time_now_parsed['hours'], $time_now_parsed['minutes'], $time_now_parsed['seconds']
@@ -631,7 +631,7 @@  discard block
 block discarded – undo
631 631
     'QUE_STRUCTURES' => QUE_STRUCTURES,
632 632
   ));
633 633
 
634
-  if((defined('SN_RENDER_NAVBAR_PLANET') && SN_RENDER_NAVBAR_PLANET === true) || ($user['option_list'][OPT_INTERFACE]['opt_int_navbar_resource_force'] && SN_RENDER_NAVBAR_PLANET !== false)) {
634
+  if ((defined('SN_RENDER_NAVBAR_PLANET') && SN_RENDER_NAVBAR_PLANET === true) || ($user['option_list'][OPT_INTERFACE]['opt_int_navbar_resource_force'] && SN_RENDER_NAVBAR_PLANET !== false)) {
635 635
     tpl_set_resource_info($template, $planetrow);
636 636
     $template->assign_vars(array(
637 637
       'SN_RENDER_NAVBAR_PLANET' => true,
@@ -646,12 +646,12 @@  discard block
 block discarded – undo
646 646
  * @param template|string $template
647 647
  */
648 648
 function displayP($template) {
649
-  if(is_object($template)) {
650
-    if(empty($template->parsed)) {
649
+  if (is_object($template)) {
650
+    if (empty($template->parsed)) {
651 651
       parsetemplate($template);
652 652
     }
653 653
 
654
-    foreach($template->files as $section => $filename) {
654
+    foreach ($template->files as $section => $filename) {
655 655
       $template->display($section);
656 656
     }
657 657
   } else {
@@ -666,11 +666,11 @@  discard block
 block discarded – undo
666 666
  * @return mixed
667 667
  */
668 668
 function parsetemplate($template, $array = false) {
669
-  if(is_object($template)) {
669
+  if (is_object($template)) {
670 670
     global $user;
671 671
 
672
-    if(!empty($array) && is_array($array)) {
673
-      foreach($array as $key => $data) {
672
+    if (!empty($array) && is_array($array)) {
673
+      foreach ($array as $key => $data) {
674 674
         $template->assign_var($key, $data);
675 675
       }
676 676
     }
@@ -711,7 +711,7 @@  discard block
 block discarded – undo
711 711
 
712 712
   $template_ex = '.tpl.html';
713 713
 
714
-  if($template === false) {
714
+  if ($template === false) {
715 715
     return sys_file_read(TEMPLATE_DIR . '/' . $files . $template_ex);
716 716
   }
717 717
 
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
   !empty(classSupernova::$sn_mvc['i18n']['']) ? lng_load_i18n(classSupernova::$sn_mvc['i18n']['']) : false;
732 732
   $sn_page_name ? lng_load_i18n(classSupernova::$sn_mvc['i18n'][$sn_page_name]) : false;
733 733
 
734
-  foreach($files as &$filename) {
734
+  foreach ($files as &$filename) {
735 735
     $filename = $filename . $template_ex;
736 736
   }
737 737
 
@@ -756,13 +756,13 @@  discard block
 block discarded – undo
756 756
     'LANG'     => $language ? $language : '',
757 757
     'referral' => $id_ref ? '&id_ref=' . $id_ref : '',
758 758
 
759
-    'REQUEST_PARAMS' => !empty($url_params) ? '?' . implode('&', $url_params) : '',// "?lang={$language}" . ($id_ref ? "&id_ref={$id_ref}" : ''),
759
+    'REQUEST_PARAMS' => !empty($url_params) ? '?' . implode('&', $url_params) : '', // "?lang={$language}" . ($id_ref ? "&id_ref={$id_ref}" : ''),
760 760
     'FILENAME'       => basename($_SERVER['PHP_SELF']),
761 761
   ));
762 762
 
763
-  foreach(lng_get_list() as $lng_id => $lng_data) {
764
-    if(isset($lng_data['LANG_VARIANTS']) && is_array($lng_data['LANG_VARIANTS'])) {
765
-      foreach($lng_data['LANG_VARIANTS'] as $lang_variant) {
763
+  foreach (lng_get_list() as $lng_id => $lng_data) {
764
+    if (isset($lng_data['LANG_VARIANTS']) && is_array($lng_data['LANG_VARIANTS'])) {
765
+      foreach ($lng_data['LANG_VARIANTS'] as $lang_variant) {
766 766
         $lng_data1 = $lng_data;
767 767
         $lng_data1 = array_merge($lng_data1, $lang_variant);
768 768
         $template->assign_block_vars('language', $lng_data1);
@@ -785,8 +785,8 @@  discard block
 block discarded – undo
785 785
   $que = $que['ques'][$que_type][$planet['id_owner']][$planet['id']];
786 786
 
787 787
   $que_length = 0;
788
-  if(!empty($que)) {
789
-    foreach($que as $que_item) {
788
+  if (!empty($que)) {
789
+    foreach ($que as $que_item) {
790 790
       $template->assign_block_vars('que', que_tpl_parse_element($que_item));
791 791
     }
792 792
     $que_length = count($que);
@@ -803,7 +803,7 @@  discard block
 block discarded – undo
803 803
 function tpl_planet_density_info(&$template, &$density_price_chart, $user_dark_matter) {
804 804
   global $lang;
805 805
 
806
-  foreach($density_price_chart as $density_price_index => &$density_price_data) {
806
+  foreach ($density_price_chart as $density_price_index => &$density_price_data) {
807 807
     $density_cost = $density_price_data;
808 808
     $density_number_style = pretty_number($density_cost, true, $user_dark_matter, false, false);
809 809
 
@@ -827,7 +827,7 @@  discard block
 block discarded – undo
827 827
 function tpl_assign_select(&$template, $name, $values) {
828 828
   !is_array($values) ? $values = array($values => $values) : false;
829 829
 
830
-  foreach($values as $key => $value) {
830
+  foreach ($values as $key => $value) {
831 831
     $template->assign_block_vars($name, array(
832 832
       'KEY'   => htmlentities($key, ENT_COMPAT, 'UTF-8'),
833 833
       'VALUE' => htmlentities($value, ENT_COMPAT, 'UTF-8'),
Please login to merge, or discard this patch.
phalanx.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -18,17 +18,17 @@  discard block
 block discarded – undo
18 18
 
19 19
 $sensorLevel = mrc_get_level($user, $planetrow, STRUC_MOON_PHALANX);
20 20
 if (!intval($sensorLevel)) {
21
-  message (classLocale::$lang['phalanx_nosensoravailable'], classLocale::$lang['tech'][STRUC_MOON_PHALANX], '', 3);
21
+  message(classLocale::$lang['phalanx_nosensoravailable'], classLocale::$lang['tech'][STRUC_MOON_PHALANX], '', 3);
22 22
 }
23 23
 
24 24
 if ($planetrow['planet_type'] != PT_MOON) {
25
-  message (classLocale::$lang['phalanx_onlyformoons'], classLocale::$lang['tech'][STRUC_MOON_PHALANX], '', 3);
25
+  message(classLocale::$lang['phalanx_onlyformoons'], classLocale::$lang['tech'][STRUC_MOON_PHALANX], '', 3);
26 26
 }
27 27
 
28 28
 $scan_galaxy  = sys_get_param_int('galaxy');
29 29
 $scan_system  = sys_get_param_int('system');
30 30
 $scan_planet  = sys_get_param_int('planet');
31
-$scan_planet_type  = 1; // sys_get_param_int('planettype');
31
+$scan_planet_type = 1; // sys_get_param_int('planettype');
32 32
 $id = sys_get_param_id('id');
33 33
 
34 34
 $source_galaxy = $planetrow['galaxy'];
@@ -38,9 +38,9 @@  discard block
 block discarded – undo
38 38
 $sensorRange = GetPhalanxRange($sensorLevel);
39 39
 
40 40
 $system_distance = abs($source_system - $scan_system);
41
-if($system_distance > $sensorRange || $scan_galaxy != $source_galaxy)
41
+if ($system_distance > $sensorRange || $scan_galaxy != $source_galaxy)
42 42
 {
43
-  message (classLocale::$lang['phalanx_rangeerror'], classLocale::$lang['tech'][STRUC_MOON_PHALANX], '', 3);
43
+  message(classLocale::$lang['phalanx_rangeerror'], classLocale::$lang['tech'][STRUC_MOON_PHALANX], '', 3);
44 44
 }
45 45
 
46 46
 $cost = $sensorLevel * 1000;
@@ -51,14 +51,14 @@  discard block
 block discarded – undo
51 51
 }
52 52
 
53 53
 $planet_scanned = db_planet_by_gspt($scan_galaxy, $scan_system, $scan_planet, $scan_planet_type);
54
-if(!$planet_scanned['id'])
54
+if (!$planet_scanned['id'])
55 55
 {
56 56
   message(classLocale::$lang['phalanx_planet_not_exists'], classLocale::$lang['tech'][STRUC_MOON_PHALANX], '', 3);
57 57
 }
58 58
 
59
-if($planet_scanned['destruyed'])
59
+if ($planet_scanned['destruyed'])
60 60
 {
61
-  message (classLocale::$lang['phalanx_planet_destroyed'], classLocale::$lang['tech'][STRUC_MOON_PHALANX], '', 3);
61
+  message(classLocale::$lang['phalanx_planet_destroyed'], classLocale::$lang['tech'][STRUC_MOON_PHALANX], '', 3);
62 62
 }
63 63
 
64 64
 db_planet_set_by_id($user['current_planet'], "deuterium = deuterium - {$cost}");
Please login to merge, or discard this patch.
includes/classes/sn_module_payment.php 1 patch
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
   public function compile_request($request) {
451 451
     global $config, $user;
452 452
 
453
-    if(!(classSupernova::$auth->account instanceof Account)) {
453
+    if (!(classSupernova::$auth->account instanceof Account)) {
454 454
       // TODO - throw new Exception($lang['pay_msg_mm_request_amount_invalid'], SN_PAYMENT_REQUEST_ERROR_UNIT_AMOUNT);
455 455
     }
456 456
     $this->account = classSupernova::$auth->account;
@@ -471,15 +471,15 @@  discard block
 block discarded – undo
471 471
     $this->payment_currency = $config->payment_currency_default;
472 472
     $this->payment_amount = self::currency_convert($this->payment_dark_matter_paid, 'MM_', $this->payment_currency);
473 473
 
474
-    if(empty($this->payment_external_currency) && !empty($this->config['currency'])) {
474
+    if (empty($this->payment_external_currency) && !empty($this->config['currency'])) {
475 475
       $this->payment_external_currency = $this->config['currency'];
476 476
     }
477
-    if(empty($this->payment_external_currency)) {
477
+    if (empty($this->payment_external_currency)) {
478 478
       throw new Exception(classLocale::$lang['pay_error_internal_no_external_currency_set'], SN_PAYMENT_ERROR_INTERNAL_NO_EXTERNAL_CURRENCY_SET);
479 479
     }
480 480
 
481 481
     $this->payment_external_amount = self::currency_convert($this->payment_dark_matter_paid, 'MM_', $this->payment_external_currency);
482
-    if($this->payment_external_amount < 0.01) {
482
+    if ($this->payment_external_amount < 0.01) {
483 483
       throw new Exception(classLocale::$lang['pay_msg_mm_request_amount_invalid'], SN_PAYMENT_REQUEST_ERROR_UNIT_AMOUNT);
484 484
     }
485 485
 
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
     $this->generate_description();
489 489
 
490 490
     $this->db_insert();
491
-    if(!$this->is_exists) {
491
+    if (!$this->is_exists) {
492 492
       throw new Exception(classLocale::$lang['pay_msg_request_error_db_payment_create'], SN_PAYMENT_REQUEST_DB_ERROR_PAYMENT_CREATE);
493 493
     }
494 494
   }
@@ -503,24 +503,24 @@  discard block
 block discarded – undo
503 503
   protected function payment_request_process($options = array()) {
504 504
     global $lang, $config;
505 505
 
506
-    if(!$this->manifest['active']) {
506
+    if (!$this->manifest['active']) {
507 507
       throw new Exception(classLocale::$lang['pay_msg_module_disabled'], SN_MODULE_DISABLED);
508 508
     }
509 509
 
510 510
     // Если есть payment_id - загружаем под него данные
511
-    if(!empty($this->payment_params['payment_id'])) {
511
+    if (!empty($this->payment_params['payment_id'])) {
512 512
       $this->request_payment_id = sys_get_param_id($this->payment_params['payment_id']);
513
-      if(!$this->request_payment_id) {
513
+      if (!$this->request_payment_id) {
514 514
         throw new Exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_INTERNAL_ID_WRONG);
515 515
       }
516 516
 
517
-      if(!$this->db_get_by_id($this->request_payment_id)) {
517
+      if (!$this->db_get_by_id($this->request_payment_id)) {
518 518
         throw new Exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_INTERNAL_ID_WRONG);
519 519
       }
520 520
 
521 521
       // Проверяем - был ли этот платеж обработан?
522 522
       // TODO - Статусы бывают разные. Нужен спецфлаг payment_processed
523
-      if($this->payment_status != PAYMENT_STATUS_NONE) {
523
+      if ($this->payment_status != PAYMENT_STATUS_NONE) {
524 524
         sn_db_transaction_rollback();
525 525
         sys_redirect(SN_ROOT_VIRTUAL . 'metamatter.php?payment_id=' . $this->payment_id);
526 526
         die();
@@ -530,89 +530,89 @@  discard block
 block discarded – undo
530 530
     // Пытаемся получить из запроса ИД аккаунта
531 531
     $request_account_id = !empty($this->payment_params['account_id']) ? sys_get_param_id($this->payment_params['account_id']) : 0;
532 532
     // Если в запросе нет ИД аккаунта - пытаемся использовать payment_account_id
533
-    if(empty($request_account_id) && !empty($this->payment_account_id)) {
533
+    if (empty($request_account_id) && !empty($this->payment_account_id)) {
534 534
       $request_account_id = $this->payment_account_id;
535 535
     }
536 536
     // Если теперь у нас нету ИД аккаунта ни в запросе, ни в записи таблицы - можно паниковать
537
-    if(empty($request_account_id)) {
537
+    if (empty($request_account_id)) {
538 538
       // TODO - аккаунт
539 539
       throw new Exception(classLocale::$lang['pay_msg_request_user_invalid'], $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options));
540 540
     }
541 541
     // Если нет записи в таблице - тогда берем payment_account_id из запроса
542
-    if(empty($this->payment_account_id)) {
542
+    if (empty($this->payment_account_id)) {
543 543
       $this->payment_account_id = $request_account_id;
544 544
     }
545 545
     // Если у нас отличаются ИД аккаунта в запросе и ИД аккаунта в записи - тоже можно паниковать
546
-    if($this->payment_account_id != $request_account_id) {
546
+    if ($this->payment_account_id != $request_account_id) {
547 547
       // TODO - Поменять сообщение об ошибке
548 548
       throw new Exception(classLocale::$lang['pay_msg_request_user_invalid'], $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options));
549 549
     }
550 550
     // Проверяем существование аккаунта с данным ИД
551
-    if(!$this->account->db_get_by_id($this->payment_account_id)) {
551
+    if (!$this->account->db_get_by_id($this->payment_account_id)) {
552 552
       throw new Exception(classLocale::$lang['pay_msg_request_user_invalid'] . ' ID ' . $this->payment_account_id, $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options));
553 553
     }
554 554
 
555 555
     // TODO Проверка на сервер_ид - как бы и не нужна, наверное?
556
-    if(!empty($this->payment_params['server_id'])) {
556
+    if (!empty($this->payment_params['server_id'])) {
557 557
       $this->request_server_id = sys_get_param_str($this->payment_params['server_id']);
558
-      if(SN_ROOT_VIRTUAL != $this->request_server_id) {
558
+      if (SN_ROOT_VIRTUAL != $this->request_server_id) {
559 559
         throw new Exception(classLocale::$lang['pay_msg_request_server_wrong'] . " {$this->request_server_id} вместо " . SN_ROOT_VIRTUAL, SN_PAYMENT_REQUEST_SERVER_WRONG);
560 560
       }
561 561
     }
562 562
 
563 563
     // Сверка количества оплаченной ММ с учётом бонусов
564
-    if(!empty($this->payment_params['payment_dark_matter_gained'])) {
564
+    if (!empty($this->payment_params['payment_dark_matter_gained'])) {
565 565
       $request_mm_amount = sys_get_param_id($this->payment_params['payment_dark_matter_gained']);
566
-      if($request_mm_amount != $this->payment_dark_matter_gained && $this->is_loaded) {
566
+      if ($request_mm_amount != $this->payment_dark_matter_gained && $this->is_loaded) {
567 567
         throw new Exception(classLocale::$lang['pay_msg_mm_request_amount_invalid'] . " пришло {$request_mm_amount} ММ вместо {$this->payment_dark_matter_gained} ММ", SN_PAYMENT_REQUEST_MM_AMOUNT_INVALID);
568 568
       }
569 569
       empty($this->payment_dark_matter_gained) ? $this->payment_dark_matter_gained = $request_mm_amount : false;
570 570
     }
571
-    if(empty($this->payment_dark_matter_paid)) {
571
+    if (empty($this->payment_dark_matter_paid)) {
572 572
       // TODO - обратный расчёт из gained
573 573
     }
574 574
 
575 575
     // Проверка наличия внешнего ИД платежа
576
-    if(!empty($this->payment_params['payment_external_id'])) {
576
+    if (!empty($this->payment_params['payment_external_id'])) {
577 577
       $request_payment_external_id = sys_get_param_id($this->payment_params['payment_external_id']);
578
-      if(empty($request_payment_external_id)) {
578
+      if (empty($request_payment_external_id)) {
579 579
         throw new exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_EXTERNAL_ID_WRONG);
580
-      } elseif(!empty($this->payment_external_id) && $this->payment_external_id != $request_payment_external_id) {
580
+      } elseif (!empty($this->payment_external_id) && $this->payment_external_id != $request_payment_external_id) {
581 581
         // TODO - Может быть поменять сообщение
582 582
         throw new exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_EXTERNAL_ID_WRONG);
583 583
       }
584 584
       $this->payment_external_id = $request_payment_external_id;
585 585
     }
586 586
     // Сверка суммы, запрошенной СН к оплате
587
-    if(!empty($this->payment_params['payment_external_money'])) {
587
+    if (!empty($this->payment_params['payment_external_money'])) {
588 588
       $request_money_out = sys_get_param_float($this->payment_params['payment_external_money']);
589
-      if($request_money_out != $this->payment_external_amount && $this->is_loaded) {
589
+      if ($request_money_out != $this->payment_external_amount && $this->is_loaded) {
590 590
         throw new Exception(classLocale::$lang['pay_msg_request_payment_amount_invalid'] . " пришло {$request_money_out} денег вместо {$this->payment_external_amount} денег", SN_PAYMENT_REQUEST_CURRENCY_AMOUNT_INVALID);
591 591
       }
592 592
       empty($this->payment_external_amount) ? $this->payment_external_amount = $request_money_out : false;
593 593
     }
594 594
     // Заполняем поле валюты платёжной системы
595
-    if(!empty($this->payment_params['payment_external_currency'])) {
595
+    if (!empty($this->payment_params['payment_external_currency'])) {
596 596
       $this->payment_external_currency = sys_get_param_str($this->payment_params['payment_external_currency']);
597
-      if(empty($this->payment_external_currency)) {
597
+      if (empty($this->payment_external_currency)) {
598 598
         // TODO - поменять сообщение
599 599
         throw new Exception(classLocale::$lang['pay_msg_request_payment_amount_invalid'] . " {$this->payment_external_currency}", SN_PAYMENT_REQUEST_CURRENCY_AMOUNT_INVALID);
600 600
       }
601 601
     }
602
-    if(empty($this->payment_external_currency)) {
602
+    if (empty($this->payment_external_currency)) {
603 603
       $this->payment_external_currency = $this->config['currency'];
604 604
     }
605 605
 
606 606
     // Заполнение внутренней суммы и валюты из внешних данных
607
-    if(empty($this->payment_currency)) {
607
+    if (empty($this->payment_currency)) {
608 608
       $this->payment_currency = $config->payment_currency_default;
609 609
     }
610
-    if(empty($this->payment_amount) && !empty($this->payment_external_currency)) {
610
+    if (empty($this->payment_amount) && !empty($this->payment_external_currency)) {
611 611
       $this->payment_amount = self::currency_convert($this->payment_external_amount, $this->payment_external_currency, $this->payment_currency);
612 612
     }
613 613
 
614 614
     // TODO - Тестовый режим
615
-    if(!empty($this->payment_params['test'])) {
615
+    if (!empty($this->payment_params['test'])) {
616 616
       $this->payment_test = $this->config['test'] || sys_get_param_int($this->payment_params['test']);
617 617
     }
618 618
 
@@ -641,12 +641,12 @@  discard block
 block discarded – undo
641 641
     sn_db_transaction_start();
642 642
     try {
643 643
       $response = $this->payment_request_process();
644
-    } catch(Exception $e) {
644
+    } catch (Exception $e) {
645 645
       $response['result'] = $e->getCode();
646 646
       $response['message'] = $e->getMessage();
647 647
     }
648 648
 
649
-    if($response['result'] == SN_PAYMENT_REQUEST_OK) {
649
+    if ($response['result'] == SN_PAYMENT_REQUEST_OK) {
650 650
       sn_db_transaction_commit();
651 651
       $debug->warning('Результат операции: код ' . $response['result'] . ' сообщение "' . $response['message'] . '"', 'Успешный платёж', LOG_INFO_PAYMENT);
652 652
     } else {
@@ -655,7 +655,7 @@  discard block
 block discarded – undo
655 655
     }
656 656
 
657 657
     // Переводим код результата из СН в код платежной системы
658
-    if(is_array($this->result_translations) && !empty($this->result_translations)) {
658
+    if (is_array($this->result_translations) && !empty($this->result_translations)) {
659 659
       $response['result'] = isset($this->result_translations[$response['result']]) ? $this->result_translations[$response['result']] : $this->result_translations[SN_PAYMENT_REQUEST_UNDEFINED_ERROR];
660 660
     }
661 661
 
@@ -680,7 +680,7 @@  discard block
 block discarded – undo
680 680
     $currency_from = strtolower($currency_from);
681 681
     $currency_to = strtolower($currency_to);
682 682
 
683
-    if($currency_from != $currency_to) {
683
+    if ($currency_from != $currency_to) {
684 684
 //      $config_currency_from_name = 'payment_currency_exchange_' . $currency_from;
685 685
 //      $config_currency_to_name = 'payment_currency_exchange_' . $currency_to;
686 686
 
@@ -710,10 +710,10 @@  discard block
 block discarded – undo
710 710
   public static function bonus_calculate($dark_matter, $direct = true, $return_bonus = false) {
711 711
     $bonus = 0;
712 712
     $dark_matter_new = $dark_matter;
713
-    if(!empty(self::$bonus_table) && $dark_matter >= self::$bonus_table[0]) {
714
-      if($direct) {
715
-        foreach(self::$bonus_table as $dm_for_bonus => $multiplier) {
716
-          if($dm_for_bonus <= $dark_matter) {
713
+    if (!empty(self::$bonus_table) && $dark_matter >= self::$bonus_table[0]) {
714
+      if ($direct) {
715
+        foreach (self::$bonus_table as $dm_for_bonus => $multiplier) {
716
+          if ($dm_for_bonus <= $dark_matter) {
717 717
             $dark_matter_new = $dark_matter * (1 + $multiplier);
718 718
             $bonus = $multiplier;
719 719
           } else {
@@ -721,9 +721,9 @@  discard block
 block discarded – undo
721 721
           }
722 722
         }
723 723
       } else {
724
-        foreach(self::$bonus_table as $dm_for_bonus => $multiplier) {
724
+        foreach (self::$bonus_table as $dm_for_bonus => $multiplier) {
725 725
           $temp = $dm_for_bonus * (1 + $multiplier);
726
-          if($dark_matter >= $temp) {
726
+          if ($dark_matter >= $temp) {
727 727
             $dark_matter_new = round($dark_matter / (1 + $multiplier));
728 728
             $bonus = $multiplier;
729 729
           } else {
@@ -779,13 +779,13 @@  discard block
 block discarded – undo
779 779
     );
780 780
 
781 781
     $replace = false;
782
-    if($this->payment_id) {
782
+    if ($this->payment_id) {
783 783
       $payment['payment_id'] = $this->payment_id;
784 784
       $replace = true;
785 785
     }
786 786
 
787 787
     $query = array();
788
-    foreach($payment as $key => $value) {
788
+    foreach ($payment as $key => $value) {
789 789
       $value = is_string($value) ? '"' . db_escape($value) . '"' : $value;
790 790
       $query[] = "`{$key}` = {$value}";
791 791
     }
@@ -797,12 +797,12 @@  discard block
 block discarded – undo
797 797
 
798 798
 
799 799
   function payment_adjust_mm_new() {
800
-    if(!$this->payment_test) {
800
+    if (!$this->payment_test) {
801 801
       // Not a test payment. Adding DM to account
802 802
       $this->account = new Account($this->db);
803 803
       $this->account->db_get_by_id($this->payment_account_id);
804 804
       $result = $this->account->metamatter_change(RPG_PURCHASE, $this->payment_dark_matter_gained, $this->payment_comment);
805
-      if(!$result) {
805
+      if (!$result) {
806 806
         throw new Exception('Ошибка начисления ММ', SN_METAMATTER_ERROR_ADJUST);
807 807
       }
808 808
     }
@@ -812,25 +812,25 @@  discard block
 block discarded – undo
812 812
     die('{НЕ РАБОТАЕТ! СООБЩИТЕ АДМИНИСТРАЦИИ!}');
813 813
     global $lang;
814 814
 
815
-    if(!isset($payment['payment_status'])) {
815
+    if (!isset($payment['payment_status'])) {
816 816
       throw new exception(classLocale::$lang['pay_msg_request_payment_not_found'], SN_PAYMENT_REQUEST_ORDER_NOT_FOUND);
817 817
     }
818 818
 
819
-    if($payment['payment_status'] == PAYMENT_STATUS_COMPLETE) {
820
-      $safe_comment = db_escape($payment['payment_comment'] = classLocale::$lang['pay_msg_request_payment_cancelled'] .' ' . $payment['payment_comment']);
819
+    if ($payment['payment_status'] == PAYMENT_STATUS_COMPLETE) {
820
+      $safe_comment = db_escape($payment['payment_comment'] = classLocale::$lang['pay_msg_request_payment_cancelled'] . ' ' . $payment['payment_comment']);
821 821
 
822
-      if(!$payment['payment_test']) {
822
+      if (!$payment['payment_test']) {
823 823
         $result = $this->account->metamatter_change(RPG_PURCHASE_CANCEL, -$payment['payment_dark_matter_gained'], $payment['payment_comment']);
824
-        if(!$result) {
824
+        if (!$result) {
825 825
           throw new exception('Ошибка начисления ММ', SN_METAMATTER_ERROR_ADJUST);
826 826
         }
827 827
       }
828 828
       $payment['payment_status'] = PAYMENT_STATUS_CANCELED;
829 829
       db_payment_update($payment, $safe_comment);
830 830
       throw new exception(classLocale::$lang['pay_msg_request_payment_cancel_complete'], SN_PAYMENT_REQUEST_OK);
831
-    } elseif($payment['payment_status'] == PAYMENT_STATUS_CANCELED) {
831
+    } elseif ($payment['payment_status'] == PAYMENT_STATUS_CANCELED) {
832 832
       throw new exception(classLocale::$lang['pay_msg_request_payment_cancelled_already'], SN_PAYMENT_REQUEST_OK);
833
-    } elseif($payment['payment_status'] == PAYMENT_STATUS_NONE) {
833
+    } elseif ($payment['payment_status'] == PAYMENT_STATUS_NONE) {
834 834
       throw new exception(classLocale::$lang['pay_msg_request_payment_cancel_not_complete'], SN_PAYMENT_REQUEST_PAYMENT_NOT_COMPLETE);
835 835
     }
836 836
   }
@@ -844,8 +844,8 @@  discard block
 block discarded – undo
844 844
 
845 845
   protected function db_complete_payment() {
846 846
     // TODO - поле payment_processed
847
-    if($this->payment_status == PAYMENT_STATUS_NONE) {
848
-      if(!defined('PAYMENT_EXPIRE_TIME') || PAYMENT_EXPIRE_TIME == 0 || empty($this->payment_date) || strtotime($this->payment_date) + PAYMENT_EXPIRE_TIME <= SN_TIME_NOW) {
847
+    if ($this->payment_status == PAYMENT_STATUS_NONE) {
848
+      if (!defined('PAYMENT_EXPIRE_TIME') || PAYMENT_EXPIRE_TIME == 0 || empty($this->payment_date) || strtotime($this->payment_date) + PAYMENT_EXPIRE_TIME <= SN_TIME_NOW) {
849 849
         $this->payment_adjust_mm_new();
850 850
         $this->payment_status = PAYMENT_STATUS_COMPLETE;
851 851
       } else {
@@ -892,7 +892,7 @@  discard block
 block discarded – undo
892 892
   protected function db_assign_payment($payment = null) {
893 893
     $this->payment_reset();
894 894
 
895
-    if(is_array($payment) && isset($payment['payment_id'])) {
895
+    if (is_array($payment) && isset($payment['payment_id'])) {
896 896
       $this->payment_id = $payment['payment_id'];
897 897
       $this->payment_status = $payment['payment_status'];
898 898
       $this->payment_date = $payment['payment_date'];
Please login to merge, or discard this patch.
includes/classes/supernova.php 1 patch
Spacing   +103 added lines, -105 removed lines patch added patch discarded remove patch
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 
203 203
 
204 204
   public static function log_file($message, $spaces = 0) {
205
-    if(self::$debug) {
205
+    if (self::$debug) {
206 206
       self::$debug->log_file($message, $spaces);
207 207
     }
208 208
   }
@@ -214,16 +214,16 @@  discard block
 block discarded – undo
214 214
   // Перепаковывает массив на заданную глубину, убирая поля с null
215 215
   public static function array_repack(&$array, $level = 0) {
216 216
     // TODO $lock_table не нужна тут
217
-    if(!is_array($array)) {
217
+    if (!is_array($array)) {
218 218
       return;
219 219
     }
220 220
 
221
-    foreach($array as $key => &$value) {
222
-      if($value === null) {
221
+    foreach ($array as $key => &$value) {
222
+      if ($value === null) {
223 223
         unset($array[$key]);
224
-      } elseif($level > 0 && is_array($value)) {
224
+      } elseif ($level > 0 && is_array($value)) {
225 225
         static::array_repack($value, $level - 1);
226
-        if(empty($value)) {
226
+        if (empty($value)) {
227 227
           unset($array[$key]);
228 228
         }
229 229
       }
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
   // TODO Вынести в отдельный объект
235 235
   public static function cache_repack($location_type, $record_id = 0) {
236 236
     // Если есть $user_id - проверяем, а надо ли перепаковывать?
237
-    if($record_id && isset(static::$data[$location_type][$record_id]) && static::$data[$location_type][$record_id] !== null) {
237
+    if ($record_id && isset(static::$data[$location_type][$record_id]) && static::$data[$location_type][$record_id] !== null) {
238 238
       return;
239 239
     }
240 240
 
@@ -245,9 +245,9 @@  discard block
 block discarded – undo
245 245
 
246 246
   public static function cache_clear($location_type, $hard = true) {
247 247
     //print("<br />CACHE CLEAR {$cache_id} " . ($hard ? 'HARD' : 'SOFT') . "<br />");
248
-    if($hard && !empty(static::$data[$location_type])) {
248
+    if ($hard && !empty(static::$data[$location_type])) {
249 249
       // Здесь нельзя делать unset - надо записывать NULL, что бы это отразилось на зависимых записях
250
-      array_walk(static::$data[$location_type], function (&$item) { $item = null; });
250
+      array_walk(static::$data[$location_type], function(&$item) { $item = null; });
251 251
     }
252 252
     static::$locator[$location_type] = array();
253 253
     static::$queries[$location_type] = array();
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
 
257 257
   public static function cache_clear_all($hard = true) {
258 258
     //print('<br />CACHE CLEAR ALL<br />');
259
-    if($hard) {
259
+    if ($hard) {
260 260
       static::$data = array();
261 261
       static::cache_lock_unset_all();
262 262
     }
@@ -285,12 +285,12 @@  discard block
 block discarded – undo
285 285
   */
286 286
   public static function cache_set($location_type, $record_id, $record, $force_overwrite = false, $skip_lock = false) {
287 287
     // нет идентификатора - выход
288
-    if(!($record_id = $record[static::$location_info[$location_type][P_ID]])) {
288
+    if (!($record_id = $record[static::$location_info[$location_type][P_ID]])) {
289 289
       return;
290 290
     }
291 291
 
292 292
     $in_transaction = static::db_transaction_check(false);
293
-    if(
293
+    if (
294 294
       $force_overwrite
295 295
       ||
296 296
       // Не заменяются заблокированные записи во время транзакции
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
       !static::cache_isset($location_type, $record_id)
301 301
     ) {
302 302
       static::$data[$location_type][$record_id] = $record;
303
-      if($in_transaction && !$skip_lock) {
303
+      if ($in_transaction && !$skip_lock) {
304 304
         static::cache_lock_set($location_type, $record_id);
305 305
       }
306 306
     }
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
 
309 309
   public static function cache_unset($cache_id, $safe_record_id) {
310 310
     // $record_id должен быть проверен заранее !
311
-    if(isset(static::$data[$cache_id][$safe_record_id]) && static::$data[$cache_id][$safe_record_id] !== null) {
311
+    if (isset(static::$data[$cache_id][$safe_record_id]) && static::$data[$cache_id][$safe_record_id] !== null) {
312 312
       // Выставляем запись в null
313 313
       static::$data[$cache_id][$safe_record_id] = null;
314 314
       // Очищаем кэш мягко - что бы удалить очистить связанные данные - кэш локаций и кэш запоросов и всё, что потребуется впредь
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
   }
326 326
 
327 327
   public static function cache_lock_unset($location_type, $record_id) {
328
-    if(isset(static::$locks[$location_type][$record_id])) {
328
+    if (isset(static::$locks[$location_type][$record_id])) {
329 329
       unset(static::$locks[$location_type][$record_id]);
330 330
     }
331 331
 
@@ -359,13 +359,13 @@  discard block
 block discarded – undo
359 359
    */
360 360
   public static function db_transaction_check($status = null) {
361 361
     $error_msg = false;
362
-    if($status && !static::$db_in_transaction) {
362
+    if ($status && !static::$db_in_transaction) {
363 363
       $error_msg = 'No transaction started for current operation';
364
-    } elseif($status === null && static::$db_in_transaction) {
364
+    } elseif ($status === null && static::$db_in_transaction) {
365 365
       $error_msg = 'Transaction is already started';
366 366
     }
367 367
 
368
-    if($error_msg) {
368
+    if ($error_msg) {
369 369
       // TODO - Убрать позже
370 370
       print('<h1>СООБЩИТЕ ЭТО АДМИНУ: sn_db_transaction_check() - ' . $error_msg . '</h1>');
371 371
       $backtrace = debug_backtrace();
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
387 387
     static::$transaction_id++;
388 388
     doquery('START TRANSACTION');
389 389
 
390
-    if($config->db_manual_lock_enabled) {
390
+    if ($config->db_manual_lock_enabled) {
391 391
       $config->db_loadItem('var_db_manually_locked');
392 392
       $config->db_saveItem('var_db_manually_locked', SN_TIME_SQL);
393 393
     }
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
   public static function db_transaction_commit() {
405 405
     static::db_transaction_check(true);
406 406
 
407
-    if(!empty(static::$delayed_changset)) {
407
+    if (!empty(static::$delayed_changset)) {
408 408
       static::db_changeset_apply(static::$delayed_changset, true);
409 409
       // pdump(static::$delayed_changset);
410 410
     }
@@ -420,7 +420,7 @@  discard block
 block discarded – undo
420 420
 
421 421
   public static function db_transaction_rollback() {
422 422
     // static::db_transaction_check(true); // TODO - вообще-то тут тоже надо проверять есть ли транзакция
423
-    if(!empty(static::$delayed_changset)) {
423
+    if (!empty(static::$delayed_changset)) {
424 424
       static::db_changeset_revert();
425 425
     }
426 426
     static::$delayed_changset = array();
@@ -443,7 +443,7 @@  discard block
 block discarded – undo
443 443
    */
444 444
   public static function db_lock_tables($tables) {
445 445
     $tables = is_array($tables) ? $tables : array($tables => '');
446
-    foreach($tables as $table_name => $condition) {
446
+    foreach ($tables as $table_name => $condition) {
447 447
       self::$db->doquery("SELECT 1 FROM {{{$table_name}}}" . ($condition ? ' WHERE ' . $condition : ''));
448 448
     }
449 449
   }
@@ -486,17 +486,17 @@  discard block
 block discarded – undo
486 486
     //pdump($filter, 'Выбираем ' . $location_type);
487 487
     $query_cache = &static::$queries[$location_type][$filter];
488 488
 
489
-    if(!isset($query_cache) || $query_cache === null) {
489
+    if (!isset($query_cache) || $query_cache === null) {
490 490
       // pdump($filter, 'Кэш пустой, начинаем возню');
491 491
       $location_info = &static::$location_info[$location_type];
492 492
       $id_field = $location_info[P_ID];
493 493
       $query_cache = array();
494 494
 
495
-      if(static::db_transaction_check(false)) {
495
+      if (static::db_transaction_check(false)) {
496 496
         //pdump($filter, 'Транзакция - блокируем ' . $location_type);
497 497
         // Проходим по всем родителям данной записи
498 498
         // foreach($location_info[P_OWNER_INFO] as $owner_location_type => $owner_data)
499
-        foreach($location_info[P_OWNER_INFO] as $owner_data) {
499
+        foreach ($location_info[P_OWNER_INFO] as $owner_data) {
500 500
           $owner_location_type = $owner_data[P_LOCATION];
501 501
           //pdump($filter, 'Транзакция - блокируем родителя ' . $owner_location_type);
502 502
           $parent_id_list = array();
@@ -509,15 +509,15 @@  discard block
 block discarded – undo
509 509
             ($fetch ? ' LIMIT 1' : ''), false, true);
510 510
 
511 511
           //pdump($q, 'Запрос блокировки');
512
-          while($row = db_fetch($query)) {
512
+          while ($row = db_fetch($query)) {
513 513
             // Исключаем из списка родительских ИД уже заблокированные записи
514
-            if(!static::cache_lock_get($owner_location_type, $row['parent_id'])) {
514
+            if (!static::cache_lock_get($owner_location_type, $row['parent_id'])) {
515 515
               $parent_id_list[$row['parent_id']] = $row['parent_id'];
516 516
             }
517 517
           }
518 518
           //pdump($parent_id_list, 'Выбраны родители');
519 519
           // Если все-таки какие-то записи еще не заблокированы - вынимаем текущие версии из базы
520
-          if($indexes_str = implode(',', $parent_id_list)) {
520
+          if ($indexes_str = implode(',', $parent_id_list)) {
521 521
             //pdump($indexes_str, '$indexes_str');
522 522
             $parent_id_field = static::$location_info[$owner_location_type][P_ID];
523 523
             static::db_get_record_list($owner_location_type,
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
         "SELECT * FROM {{{$location_info[P_TABLE_NAME]}}}" .
533 533
         (($filter = trim($filter)) ? " WHERE {$filter}" : '')
534 534
       );
535
-      while($row = db_fetch($query)) {
535
+      while ($row = db_fetch($query)) {
536 536
         // static::db_get_record_by_id($location_type, $row[$id_field]);
537 537
         static::cache_set($location_type, $row[$id_field], $row);
538 538
         $query_cache[$row[$id_field]] = &static::$data[$location_type][$row[$id_field]];
@@ -540,14 +540,14 @@  discard block
 block discarded – undo
540 540
       }
541 541
     }
542 542
 
543
-    if($no_return) {
543
+    if ($no_return) {
544 544
       return true;
545 545
     } else {
546 546
       $result = false;
547
-      if(is_array($query_cache)) {
548
-        foreach($query_cache as $key => $value) {
547
+      if (is_array($query_cache)) {
548
+        foreach ($query_cache as $key => $value) {
549 549
           $result[$key] = $value;
550
-          if($fetch) {
550
+          if ($fetch) {
551 551
             break;
552 552
           }
553 553
         }
@@ -566,16 +566,16 @@  discard block
 block discarded – undo
566 566
    */
567 567
   public static function db_upd_record_by_id($location_type, $record_id, $set) {
568 568
     //if(!($record_id = intval($record_id)) || !($set = trim($set))) return false;
569
-    if(!($record_id = idval($record_id)) || !($set = trim($set))) {
569
+    if (!($record_id = idval($record_id)) || !($set = trim($set))) {
570 570
       return false;
571 571
     }
572 572
 
573 573
     $location_info = &static::$location_info[$location_type];
574 574
     $id_field = $location_info[P_ID];
575 575
     $table_name = $location_info[P_TABLE_NAME];
576
-    if($result = static::db_query($q = "UPDATE {{{$table_name}}} SET {$set} WHERE `{$id_field}` = {$record_id}")) // TODO Как-то вернуть может быть LIMIT 1 ?
576
+    if ($result = static::db_query($q = "UPDATE {{{$table_name}}} SET {$set} WHERE `{$id_field}` = {$record_id}")) // TODO Как-то вернуть может быть LIMIT 1 ?
577 577
     {
578
-      if(static::$db->db_affected_rows()) {
578
+      if (static::$db->db_affected_rows()) {
579 579
         // Обновляем данные только если ряд был затронут
580 580
         // TODO - переделать под работу со структурированными $set
581 581
 
@@ -591,7 +591,7 @@  discard block
 block discarded – undo
591 591
   }
592 592
 
593 593
   public static function db_upd_record_list($location_type, $condition, $set) {
594
-    if(!($set = trim($set))) {
594
+    if (!($set = trim($set))) {
595 595
       return false;
596 596
     }
597 597
 
@@ -600,9 +600,9 @@  discard block
 block discarded – undo
600 600
 
601 601
 //static::db_get_record_list($location_type, $condition, false, true);
602 602
 
603
-    if($result = static::db_query("UPDATE {{{$table_name}}} SET " . $set . ($condition ? ' WHERE ' . $condition : ''))) {
603
+    if ($result = static::db_query("UPDATE {{{$table_name}}} SET " . $set . ($condition ? ' WHERE ' . $condition : ''))) {
604 604
 
605
-      if(static::$db->db_affected_rows()) { // Обновляем данные только если ряд был затронут
605
+      if (static::$db->db_affected_rows()) { // Обновляем данные только если ряд был затронут
606 606
         // Поскольку нам неизвестно, что и как обновилось - сбрасываем кэш этого типа полностью
607 607
         // TODO - когда будет структурированный $condition и $set - перепаковывать данные
608 608
         static::cache_clear($location_type, true);
@@ -621,8 +621,8 @@  discard block
 block discarded – undo
621 621
   public static function db_ins_record($location_type, $set) {
622 622
     $set = trim($set);
623 623
     $table_name = static::$location_info[$location_type][P_TABLE_NAME];
624
-    if($result = static::db_query("INSERT INTO `{{{$table_name}}}` SET {$set}")) {
625
-      if(static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут
624
+    if ($result = static::db_query("INSERT INTO `{{{$table_name}}}` SET {$set}")) {
625
+      if (static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут
626 626
       {
627 627
         $record_id = db_insert_id();
628 628
         // Вытаскиваем запись целиком, потому что в $set могли быть "данные по умолчанию"
@@ -644,8 +644,8 @@  discard block
 block discarded – undo
644 644
     $fields = implode(',', array_keys($field_set));
645 645
 
646 646
     $table_name = static::$location_info[$location_type][P_TABLE_NAME];
647
-    if($result = static::db_query("INSERT INTO `{{{$table_name}}}` ($fields) VALUES ($values);")) {
648
-      if(static::$db->db_affected_rows()) {
647
+    if ($result = static::db_query("INSERT INTO `{{{$table_name}}}` ($fields) VALUES ($values);")) {
648
+      if (static::$db->db_affected_rows()) {
649 649
         // Обновляем данные только если ряд был затронут
650 650
         $record_id = db_insert_id();
651 651
         // Вытаскиваем запись целиком, потому что в $set могли быть "данные по умолчанию"
@@ -661,15 +661,15 @@  discard block
 block discarded – undo
661 661
 
662 662
   public static function db_del_record_by_id($location_type, $safe_record_id) {
663 663
     // if(!($safe_record_id = intval($safe_record_id))) return false;
664
-    if(!($safe_record_id = idval($safe_record_id))) {
664
+    if (!($safe_record_id = idval($safe_record_id))) {
665 665
       return false;
666 666
     }
667 667
 
668 668
     $location_info = &static::$location_info[$location_type];
669 669
     $id_field = $location_info[P_ID];
670 670
     $table_name = $location_info[P_TABLE_NAME];
671
-    if($result = static::db_query("DELETE FROM `{{{$table_name}}}` WHERE `{$id_field}` = {$safe_record_id}")) {
672
-      if(static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут
671
+    if ($result = static::db_query("DELETE FROM `{{{$table_name}}}` WHERE `{$id_field}` = {$safe_record_id}")) {
672
+      if (static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут
673 673
       {
674 674
         static::cache_unset($location_type, $safe_record_id);
675 675
       }
@@ -679,7 +679,7 @@  discard block
 block discarded – undo
679 679
   }
680 680
 
681 681
   public static function db_del_record_list($location_type, $condition) {
682
-    if(!($condition = trim($condition))) {
682
+    if (!($condition = trim($condition))) {
683 683
       return false;
684 684
     }
685 685
 
@@ -688,8 +688,8 @@  discard block
 block discarded – undo
688 688
 
689 689
 //static::db_get_record_list($location_type, $condition, false, true);
690 690
 
691
-    if($result = static::db_query("DELETE FROM `{{{$table_name}}}` WHERE {$condition}")) {
692
-      if(static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут
691
+    if ($result = static::db_query("DELETE FROM `{{{$table_name}}}` WHERE {$condition}")) {
692
+      if (static::$db->db_affected_rows()) // Обновляем данные только если ряд был затронут
693 693
       {
694 694
         // Обнуление кэша, потому что непонятно, что поменялось
695 695
         // TODO - когда будет структурированный $condition можно будет делать только cache_unset по нужным записям
@@ -736,20 +736,20 @@  discard block
 block discarded – undo
736 736
 
737 737
   public static function db_get_user_by_username($username_unsafe, $for_update = false, $fields = '*', $player = null, $like = false) {
738 738
     // TODO Проверить, кстати - а везде ли нужно выбирать юзеров или где-то все-таки ищутся Альянсы ?
739
-    if(!($username_unsafe = trim($username_unsafe))) {
739
+    if (!($username_unsafe = trim($username_unsafe))) {
740 740
       return false;
741 741
     }
742 742
 
743 743
     $user = null;
744
-    if(is_array(static::$data[LOC_USER])) {
745
-      foreach(static::$data[LOC_USER] as $user_id => $user_data) {
746
-        if(is_array($user_data) && isset($user_data['username'])) {
744
+    if (is_array(static::$data[LOC_USER])) {
745
+      foreach (static::$data[LOC_USER] as $user_id => $user_data) {
746
+        if (is_array($user_data) && isset($user_data['username'])) {
747 747
           // проверяем поле
748 748
           // TODO Возможно есть смысл всегда искать по strtolower - но может игрок захочет переименоваться с другим регистром? Проверить!
749
-          if((!$like && $user_data['username'] == $username_unsafe) || ($like && strtolower($user_data['username']) == strtolower($username_unsafe))) {
749
+          if ((!$like && $user_data['username'] == $username_unsafe) || ($like && strtolower($user_data['username']) == strtolower($username_unsafe))) {
750 750
             // $user_as_ally = intval($user_data['user_as_ally']);
751 751
             $user_as_ally = idval($user_data['user_as_ally']);
752
-            if($player === null || ($player === true && !$user_as_ally) || ($player === false && $user_as_ally)) {
752
+            if ($player === null || ($player === true && !$user_as_ally) || ($player === false && $user_as_ally)) {
753 753
               $user = $user_data;
754 754
               break;
755 755
             }
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
       }
759 759
     }
760 760
 
761
-    if($user === null) {
761
+    if ($user === null) {
762 762
       // Вытаскиваем запись
763 763
       $username_safe = db_escape($like ? strtolower($username_unsafe) : $username_unsafe); // тут на самом деле strtolower() лишняя, но пусть будет
764 764
 
@@ -776,17 +776,17 @@  discard block
 block discarded – undo
776 776
 
777 777
   // UNUSED
778 778
   public static function db_get_user_by_email($email_unsafe, $use_both = false, $for_update = false, $fields = '*') {
779
-    if(!($email_unsafe = strtolower(trim($email_unsafe)))) {
779
+    if (!($email_unsafe = strtolower(trim($email_unsafe)))) {
780 780
       return false;
781 781
     }
782 782
 
783 783
     $user = null;
784 784
     // TODO переделать на индексы
785
-    if(is_array(static::$data[LOC_USER])) {
786
-      foreach(static::$data[LOC_USER] as $user_id => $user_data) {
787
-        if(is_array($user_data) && isset($user_data['email_2'])) {
785
+    if (is_array(static::$data[LOC_USER])) {
786
+      foreach (static::$data[LOC_USER] as $user_id => $user_data) {
787
+        if (is_array($user_data) && isset($user_data['email_2'])) {
788 788
           // проверяем поле
789
-          if(strtolower($user_data['email_2']) == $email_unsafe || ($use_both && strtolower($user_data['email']) == $email_unsafe)) {
789
+          if (strtolower($user_data['email_2']) == $email_unsafe || ($use_both && strtolower($user_data['email']) == $email_unsafe)) {
790 790
             $user = $user_data;
791 791
             break;
792 792
           }
@@ -794,7 +794,7 @@  discard block
 block discarded – undo
794 794
       }
795 795
     }
796 796
 
797
-    if($user === null) {
797
+    if ($user === null) {
798 798
       // Вытаскиваем запись
799 799
       $email_safe = db_escape($email_unsafe);
800 800
       $user = static::db_query(
@@ -813,7 +813,7 @@  discard block
 block discarded – undo
813 813
     $user = null;
814 814
     // TODO переделать на индексы
815 815
 
816
-    if($user === null && !empty($where_safe)) {
816
+    if ($user === null && !empty($where_safe)) {
817 817
       // Вытаскиваем запись
818 818
       $user = static::db_query("SELECT * FROM {{users}} WHERE {$where_safe}", true);
819 819
 
@@ -835,7 +835,7 @@  discard block
 block discarded – undo
835 835
   public static function db_get_unit_by_id($unit_id, $for_update = false, $fields = '*') {
836 836
     // TODO запихивать в $data[LOC_LOCATION][$location_type][$location_id]
837 837
     $unit = static::db_get_record_by_id(LOC_UNIT, $unit_id, $for_update, $fields);
838
-    if(is_array($unit)) {
838
+    if (is_array($unit)) {
839 839
       static::$locator[LOC_UNIT][$unit['unit_location_type']][$unit['unit_location_id']][$unit['unit_snid']] = &static::$data[LOC_UNIT][$unit_id];
840 840
     }
841 841
 
@@ -851,15 +851,15 @@  discard block
 block discarded – undo
851 851
    */
852 852
   public static function db_get_unit_list_by_location($user_id = 0, $location_type, $location_id) {
853 853
     //if(!($location_type = intval($location_type)) || !($location_id = intval($location_id))) return false;
854
-    if(!($location_type = idval($location_type)) || !($location_id = idval($location_id))) {
854
+    if (!($location_type = idval($location_type)) || !($location_id = idval($location_id))) {
855 855
       return false;
856 856
     }
857 857
 
858 858
     $query_cache = &static::$locator[LOC_UNIT][$location_type][$location_id];
859
-    if(!isset($query_cache)) {
859
+    if (!isset($query_cache)) {
860 860
       $got_data = static::db_get_record_list(LOC_UNIT, "unit_location_type = {$location_type} AND unit_location_id = {$location_id} AND " . static::db_unit_time_restrictions());
861
-      if(is_array($got_data)) {
862
-        foreach($got_data as $unit_id => $unit_data) {
861
+      if (is_array($got_data)) {
862
+        foreach ($got_data as $unit_id => $unit_data) {
863 863
           // static::$data[LOC_LOCATION][$location_type][$location_id][$unit_data['unit_snid']] = &static::$data[LOC_UNIT][$unit_id];
864 864
           $query_cache[$unit_data['unit_snid']] = &static::$data[LOC_UNIT][$unit_id];
865 865
         }
@@ -867,8 +867,8 @@  discard block
 block discarded – undo
867 867
     }
868 868
 
869 869
     $result = false;
870
-    if(is_array($query_cache)) {
871
-      foreach($query_cache as $key => $value) {
870
+    if (is_array($query_cache)) {
871
+      foreach ($query_cache as $key => $value) {
872 872
         $result[$key] = $value;
873 873
       }
874 874
     }
@@ -903,7 +903,7 @@  discard block
 block discarded – undo
903 903
    *
904 904
    */
905 905
   public static function db_que_list_by_type_location($user_id, $planet_id = null, $que_type = false, $for_update = false) {
906
-    if(!$user_id) {
906
+    if (!$user_id) {
907 907
       pdump(debug_backtrace());
908 908
       die('No user_id for que_get_que()');
909 909
     }
@@ -913,16 +913,16 @@  discard block
 block discarded – undo
913 913
     $query = array();
914 914
 
915 915
     // if($user_id = intval($user_id))
916
-    if($user_id = idval($user_id)) {
916
+    if ($user_id = idval($user_id)) {
917 917
       $query[] = "`que_player_id` = {$user_id}";
918 918
     }
919 919
 
920
-    if($que_type == QUE_RESEARCH || $planet_id === null) {
920
+    if ($que_type == QUE_RESEARCH || $planet_id === null) {
921 921
       $query[] = "`que_planet_id` IS NULL";
922
-    } elseif($planet_id) {
922
+    } elseif ($planet_id) {
923 923
       $query[] = "(`que_planet_id` = {$planet_id}" . ($que_type ? '' : ' OR que_planet_id IS NULL') . ")";
924 924
     }
925
-    if($que_type) {
925
+    if ($que_type) {
926 926
       $query[] = "`que_type` = {$que_type}";
927 927
     }
928 928
 
@@ -955,13 +955,13 @@  discard block
 block discarded – undo
955 955
 
956 956
 
957 957
   public static function db_changeset_prepare_unit($unit_id, $unit_value, $user, $planet_id = null) {
958
-    if(!is_array($user)) {
958
+    if (!is_array($user)) {
959 959
       // TODO - remove later
960 960
       print('<h1>СООБЩИТЕ ЭТО АДМИНУ: sn_db_unit_changeset_prepare() - USER is not ARRAY</h1>');
961 961
       pdump(debug_backtrace());
962 962
       die('USER is not ARRAY');
963 963
     }
964
-    if(!isset($user['id']) || !$user['id']) {
964
+    if (!isset($user['id']) || !$user['id']) {
965 965
       // TODO - remove later
966 966
       print('<h1>СООБЩИТЕ ЭТО АДМИНУ: sn_db_unit_changeset_prepare() - USER[id] пустой</h1>');
967 967
       pdump($user);
@@ -976,7 +976,7 @@  discard block
 block discarded – undo
976 976
 
977 977
     $db_changeset = array();
978 978
     $temp = db_unit_by_location($user['id'], $unit_location, $location_id, $unit_id, true, 'unit_id');
979
-    if($temp['unit_id']) {
979
+    if ($temp['unit_id']) {
980 980
       $db_changeset = array(
981 981
         'action'  => SQL_OP_UPDATE,
982 982
         P_VERSION => 1,
@@ -1045,9 +1045,9 @@  discard block
 block discarded – undo
1045 1045
   }
1046 1046
 
1047 1047
   public function db_changeset_condition_compile(&$conditions, &$table_name = '') {
1048
-    if(!$conditions[P_LOCATION] || $conditions[P_LOCATION] == LOC_NONE) {
1048
+    if (!$conditions[P_LOCATION] || $conditions[P_LOCATION] == LOC_NONE) {
1049 1049
       $conditions[P_LOCATION] = LOC_NONE;
1050
-      switch($table_name) {
1050
+      switch ($table_name) {
1051 1051
         case 'users':
1052 1052
         case LOC_USER:
1053 1053
           $conditions[P_TABLE_NAME] = $table_name = 'users';
@@ -1069,18 +1069,18 @@  discard block
 block discarded – undo
1069 1069
     }
1070 1070
 
1071 1071
     $conditions[P_FIELDS_STR] = '';
1072
-    if($conditions['fields']) {
1072
+    if ($conditions['fields']) {
1073 1073
       $fields = array();
1074
-      foreach($conditions['fields'] as $field_name => $field_data) {
1074
+      foreach ($conditions['fields'] as $field_name => $field_data) {
1075 1075
         $condition = "`{$field_name}` = ";
1076 1076
         $value = '';
1077
-        if($field_data['delta']) {
1077
+        if ($field_data['delta']) {
1078 1078
           $value = "`{$field_name}`" . ($field_data['delta'] >= 0 ? '+' : '') . $field_data['delta'];
1079
-        } elseif($field_data['set']) {
1079
+        } elseif ($field_data['set']) {
1080 1080
           $value = (is_string($field_data['set']) ? "'{$field_data['set']}'" : $field_data['set']);
1081 1081
         }
1082 1082
 
1083
-        if($value) {
1083
+        if ($value) {
1084 1084
           $fields[] = $condition . $value;
1085 1085
         }
1086 1086
       }
@@ -1088,16 +1088,14 @@  discard block
 block discarded – undo
1088 1088
     }
1089 1089
 
1090 1090
     $conditions[P_WHERE_STR] = '';
1091
-    if(!empty($conditions['where'])) {
1092
-      if($conditions[P_VERSION] == 1) {
1091
+    if (!empty($conditions['where'])) {
1092
+      if ($conditions[P_VERSION] == 1) {
1093 1093
         $the_conditions = array();
1094
-        foreach($conditions['where'] as $field_id => $field_value) {
1094
+        foreach ($conditions['where'] as $field_id => $field_value) {
1095 1095
           // Простое условие - $field_id = $field_value
1096
-          if(is_string($field_id)) {
1096
+          if (is_string($field_id)) {
1097 1097
             $field_value =
1098
-              $field_value === null ? 'NULL' :
1099
-                (is_string($field_value) ? "'" . db_escape($field_value) . "'" :
1100
-                  (is_bool($field_value) ? intval($field_value) : $field_value));
1098
+              $field_value === null ? 'NULL' : (is_string($field_value) ? "'" . db_escape($field_value) . "'" : (is_bool($field_value) ? intval($field_value) : $field_value));
1101 1099
             $the_conditions[] = "`{$field_id}` = {$field_value}";
1102 1100
           } else {
1103 1101
             die('Неподдерживаемый тип условия');
@@ -1114,7 +1112,7 @@  discard block
 block discarded – undo
1114 1112
       $conditions[P_WHERE_STR] = implode(' AND ', $the_conditions);
1115 1113
     }
1116 1114
 
1117
-    switch($conditions['action']) {
1115
+    switch ($conditions['action']) {
1118 1116
       case SQL_OP_DELETE:
1119 1117
         $conditions[P_ACTION_STR] = ("DELETE FROM {{{$table_name}}}");
1120 1118
       break;
@@ -1134,11 +1132,11 @@  discard block
 block discarded – undo
1134 1132
 
1135 1133
   public static function db_changeset_apply($db_changeset, $flush_delayed = false) {
1136 1134
     $result = true;
1137
-    if(!is_array($db_changeset) || empty($db_changeset)) {
1135
+    if (!is_array($db_changeset) || empty($db_changeset)) {
1138 1136
       return $result;
1139 1137
     }
1140 1138
 
1141
-    foreach($db_changeset as $table_name => &$table_data) {
1139
+    foreach ($db_changeset as $table_name => &$table_data) {
1142 1140
       // TODO - delayed changeset
1143 1141
       /*
1144 1142
       if(static::db_transaction_check(false) && !$flush_delayed && ($table_name == 'users' || $table_name == 'planets' || $table_name == 'unit'))
@@ -1147,19 +1145,19 @@  discard block
 block discarded – undo
1147 1145
         continue;
1148 1146
       }
1149 1147
       */
1150
-      foreach($table_data as $record_id => &$conditions) {
1148
+      foreach ($table_data as $record_id => &$conditions) {
1151 1149
         static::db_changeset_condition_compile($conditions, $table_name);
1152 1150
 
1153
-        if($conditions['action'] != SQL_OP_DELETE && !$conditions[P_FIELDS_STR]) {
1151
+        if ($conditions['action'] != SQL_OP_DELETE && !$conditions[P_FIELDS_STR]) {
1154 1152
           continue;
1155 1153
         }
1156
-        if($conditions['action'] == SQL_OP_DELETE && !$conditions[P_WHERE_STR]) {
1154
+        if ($conditions['action'] == SQL_OP_DELETE && !$conditions[P_WHERE_STR]) {
1157 1155
           continue;
1158 1156
         } // Защита от случайного удаления всех данных в таблице
1159 1157
 
1160
-        if($conditions[P_LOCATION] != LOC_NONE) {
1158
+        if ($conditions[P_LOCATION] != LOC_NONE) {
1161 1159
           //die('spec ops supernova.php line 928 Добавить работу с кэшем юнитов итд');
1162
-          switch($conditions['action']) {
1160
+          switch ($conditions['action']) {
1163 1161
             case SQL_OP_DELETE:
1164 1162
               $result = self::db_del_record_list($conditions[P_LOCATION], $conditions[P_WHERE_STR]) && $result;
1165 1163
             break;
@@ -1241,13 +1239,13 @@  discard block
 block discarded – undo
1241 1239
   public static function init_0_prepare() {
1242 1240
     // Отключаем magic_quotes
1243 1241
     ini_get('magic_quotes_sybase') ? die('SN is incompatible with \'magic_quotes_sybase\' turned on. Disable it in php.ini or .htaccess...') : false;
1244
-    if(@get_magic_quotes_gpc()) {
1242
+    if (@get_magic_quotes_gpc()) {
1245 1243
       $gpcr = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
1246
-      array_walk_recursive($gpcr, function (&$value, $key) {
1244
+      array_walk_recursive($gpcr, function(&$value, $key) {
1247 1245
         $value = stripslashes($value);
1248 1246
       });
1249 1247
     }
1250
-    if(function_exists('set_magic_quotes_runtime')) {
1248
+    if (function_exists('set_magic_quotes_runtime')) {
1251 1249
       @set_magic_quotes_runtime(0);
1252 1250
       @ini_set('magic_quotes_runtime', 0);
1253 1251
       @ini_set('magic_quotes_sybase', 0);
@@ -1325,7 +1323,7 @@  discard block
 block discarded – undo
1325 1323
   }
1326 1324
 
1327 1325
   public static function init_debug_state() {
1328
-    if($_SERVER['SERVER_NAME'] == 'localhost' && !defined('BE_DEBUG')) {
1326
+    if ($_SERVER['SERVER_NAME'] == 'localhost' && !defined('BE_DEBUG')) {
1329 1327
       define('BE_DEBUG', true);
1330 1328
     }
1331 1329
 // define('DEBUG_SQL_ONLINE', true); // Полный дамп запросов в рил-тайме. Подойдет любое значение
@@ -1337,7 +1335,7 @@  discard block
 block discarded – undo
1337 1335
     defined('DEBUG_SQL_ERROR') && !defined('DEBUG_SQL_COMMENT') ? define('DEBUG_SQL_COMMENT', true) : false;
1338 1336
     defined('DEBUG_SQL_COMMENT_LONG') && !defined('DEBUG_SQL_COMMENT') ? define('DEBUG_SQL_COMMENT', true) : false;
1339 1337
 
1340
-    if(defined('BE_DEBUG') || static::$config->debug) {
1338
+    if (defined('BE_DEBUG') || static::$config->debug) {
1341 1339
       @define('BE_DEBUG', true);
1342 1340
       @ini_set('display_errors', 1);
1343 1341
       @error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
Please login to merge, or discard this patch.
admin/settings.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -8,18 +8,18 @@  discard block
 block discarded – undo
8 8
  * @copyright 2008 by ??????? for XNova
9 9
  */
10 10
 
11
-define('INSIDE'  , true);
12
-define('INSTALL' , false);
11
+define('INSIDE', true);
12
+define('INSTALL', false);
13 13
 define('IN_ADMIN', true);
14 14
 require('../common.' . substr(strrchr(__FILE__, '.'), 1));
15 15
 
16
-if($user['authlevel'] < 3) {
16
+if ($user['authlevel'] < 3) {
17 17
   AdminMessage(classLocale::$lang['adm_err_denied']);
18 18
 }
19 19
 
20 20
 $template = gettemplate('admin/settings', true);
21 21
 
22
-if(sys_get_param('save')) {
22
+if (sys_get_param('save')) {
23 23
   $config->game_name               = sys_get_param_str_unsafe('game_name');
24 24
   $config->game_mode               = sys_get_param_int('game_mode');
25 25
   $config->game_speed              = sys_get_param_float('game_speed', 1);
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
   $config->url_faq                 = sys_get_param_str_unsafe('url_faq');
30 30
   $config->url_forum               = sys_get_param_str_unsafe('url_forum');
31 31
   $config->url_rules               = sys_get_param_str_unsafe('url_rules');
32
-  $config->url_purchase_metamatter         = sys_get_param_str_unsafe('url_purchase_metamatter');
32
+  $config->url_purchase_metamatter = sys_get_param_str_unsafe('url_purchase_metamatter');
33 33
   $config->game_disable            = sys_get_param_int('game_disable');
34 34
   $config->game_disable_reason     = sys_get_param_str_unsafe('game_disable_reason');
35 35
   $config->server_updater_check_auto = sys_get_param_int('server_updater_check_auto');
@@ -96,8 +96,8 @@  discard block
 block discarded – undo
96 96
   $config->stats_schedule          = sys_get_param_str('stats_schedule');
97 97
 
98 98
   $config->empire_mercenary_base_period = sys_get_param_int('empire_mercenary_base_period');
99
-  if($config->empire_mercenary_temporary != sys_get_param_int('empire_mercenary_temporary')) {
100
-    if($config->empire_mercenary_temporary) {
99
+  if ($config->empire_mercenary_temporary != sys_get_param_int('empire_mercenary_temporary')) {
100
+    if ($config->empire_mercenary_temporary) {
101 101
       db_unit_list_admin_delete_mercenaries_finished();
102 102
     } else {
103 103
       db_unit_list_admin_set_mercenaries_expire_time($config->empire_mercenary_base_period);
@@ -140,21 +140,21 @@  discard block
 block discarded – undo
140 140
 //  'STATS_SCHEDULE' => $config->stats_hide_player_list,
141 141
 ));
142 142
 
143
-foreach(classLocale::$lang['sys_game_disable_reason'] as $id => $name) {
143
+foreach (classLocale::$lang['sys_game_disable_reason'] as $id => $name) {
144 144
   $template->assign_block_vars('sys_game_disable_reason', array(
145 145
     'ID'   => $id,
146 146
     'NAME' => $name,
147 147
   ));
148 148
 }
149 149
 
150
-foreach(classLocale::$lang['sys_game_mode'] as $mode_id => $mode_name) {
150
+foreach (classLocale::$lang['sys_game_mode'] as $mode_id => $mode_name) {
151 151
   $template->assign_block_vars('game_modes', array(
152 152
     'ID'   => $mode_id,
153 153
     'NAME' => $mode_name,
154 154
   ));
155 155
 }
156 156
 
157
-foreach(classLocale::$lang['adm_opt_ver_response'] as $ver_id => $ver_response) {
157
+foreach (classLocale::$lang['adm_opt_ver_response'] as $ver_id => $ver_response) {
158 158
   $template->assign_block_vars('ver_response', array(
159 159
     'ID'   => $ver_id,
160 160
     'NAME' => js_safe_string($ver_response),
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 }
163 163
 
164 164
 $lang_list = lng_get_list();
165
-foreach($lang_list as $lang_id => $lang_data) {
165
+foreach ($lang_list as $lang_id => $lang_data) {
166 166
   $template->assign_block_vars('game_languages', array(
167 167
     'ID'   => $lang_id,
168 168
     'NAME' => "{$lang_data['LANG_NAME_NATIVE']} ({$lang_data['LANG_NAME_ENGLISH']})",
Please login to merge, or discard this patch.
admin/adm_planet_list.php 1 patch
Spacing   +5 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-define('INSIDE'  , true);
4
-define('INSTALL' , false);
3
+define('INSIDE', true);
4
+define('INSTALL', false);
5 5
 define('IN_ADMIN', true);
6 6
 
7 7
 require('../common.' . substr(strrchr(__FILE__, '.'), 1));
@@ -9,12 +9,12 @@  discard block
 block discarded – undo
9 9
 global $config, $lang, $user;
10 10
 
11 11
 // if($user['authlevel'] < 1)
12
-if($user['authlevel'] < 3) {
12
+if ($user['authlevel'] < 3) {
13 13
   AdminMessage(classLocale::$lang['adm_err_denied']);
14 14
 }
15 15
 
16 16
 $planet_active = sys_get_param_int('planet_active');
17
-if(!$planet_active) {
17
+if (!$planet_active) {
18 18
   $planet_type = sys_get_param_int('planet_type', 1);
19 19
   $planet_type = $planet_type == 3 ? 3 : 1;
20 20
 } else {
@@ -43,8 +43,7 @@  discard block
 block discarded – undo
43 43
 
44 44
 $page_title =
45 45
   classLocale::$lang['adm_planet_list_title'] . ': ' .
46
-  ($planet_active ? classLocale::$lang['adm_planet_active'] :
47
-    ($planet_type ? ($planet_type == 3 ? classLocale::$lang['sys_moons'] : classLocale::$lang['sys_planets']) : '')
46
+  ($planet_active ? classLocale::$lang['adm_planet_active'] : ($planet_type ? ($planet_type == 3 ? classLocale::$lang['sys_moons'] : classLocale::$lang['sys_planets']) : '')
48 47
   );
49 48
 $template->assign_vars(array(
50 49
   'PAGE_TITLE' => $page_title,
Please login to merge, or discard this patch.