Completed
Push — work-fleets ( 125b09...7aaf68 )
by SuperNova.WS
06:43
created
includes/classes/auth_local.php 2 patches
Doc Comments   +7 added lines patch added patch discarded remove patch
@@ -209,6 +209,10 @@  discard block
 block discarded – undo
209 209
    * @return array|bool|resource
210 210
    */
211 211
   // OK v4.5
212
+
213
+  /**
214
+   * @param string $salt_unsafe
215
+   */
212 216
   public function password_change($old_password_unsafe, $new_password_unsafe, $salt_unsafe = null) {
213 217
     $result = parent::password_change($old_password_unsafe, $new_password_unsafe, $salt_unsafe);
214 218
     if($result) {
@@ -218,6 +222,9 @@  discard block
 block discarded – undo
218 222
     return $result;
219 223
   }
220 224
 
225
+  /**
226
+   * @param Account $account_to_impersonate
227
+   */
221 228
   public function impersonate($account_to_impersonate) {
222 229
     $this->cookie_set($account_to_impersonate);
223 230
   }
Please login to merge, or discard this patch.
Spacing   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -93,12 +93,12 @@  discard block
 block discarded – undo
93 93
     $this->prepare();
94 94
 
95 95
     $this->manifest['active'] = false;
96
-    if(!empty($this->config) && is_array($this->config['db'])) {
96
+    if (!empty($this->config) && is_array($this->config['db'])) {
97 97
       // БД, отличная от стандартной
98 98
       $this->db = new db_mysql();
99 99
 
100 100
       $this->db->sn_db_connect($this->config['db']);
101
-      if($this->manifest['active'] = $this->db->connected) {
101
+      if ($this->manifest['active'] = $this->db->connected) {
102 102
         $this->provider_id = ACCOUNT_PROVIDER_CENTRAL;
103 103
 
104 104
         $this->domain = $this->config['domain'];
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
     }
113 113
 
114 114
     // Fallback to local DB
115
-    if(!$this->manifest['active']) {
115
+    if (!$this->manifest['active']) {
116 116
       $this->db = classSupernova::$db;
117 117
 
118 118
       $this->provider_id = ACCOUNT_PROVIDER_LOCAL;
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
       $this->manifest['active'] = true;
126 126
     }
127 127
 
128
-    $this->cookie_name_impersonate = $this->cookie_name . AUTH_COOKIE_IMPERSONATE_SUFFIX;
128
+    $this->cookie_name_impersonate = $this->cookie_name.AUTH_COOKIE_IMPERSONATE_SUFFIX;
129 129
 
130 130
     $this->account = new Account($this->db);
131 131
     $this->confirmation = new Confirmation($this->db);
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
   // OK v4.5
167 167
   public function password_change($old_password_unsafe, $new_password_unsafe, $salt_unsafe = null) {
168 168
     $result = parent::password_change($old_password_unsafe, $new_password_unsafe, $salt_unsafe);
169
-    if($result) {
169
+    if ($result) {
170 170
       $this->cookie_set();
171 171
     }
172 172
 
@@ -194,12 +194,12 @@  discard block
 block discarded – undo
194 194
    */
195 195
   // OK v4.6
196 196
   protected function password_reset_send_code() {
197
-    if(!$this->is_password_reset) {
197
+    if (!$this->is_password_reset) {
198 198
       return $this->account_login_status;
199 199
     }
200 200
 
201 201
     // Проверяем поддержку сброса пароля
202
-    if(!$this->is_feature_supported(AUTH_FEATURE_PASSWORD_RESET)) {
202
+    if (!$this->is_feature_supported(AUTH_FEATURE_PASSWORD_RESET)) {
203 203
       return $this->account_login_status;
204 204
     }
205 205
 
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
       unset($this->account);
210 210
       $this->account = new Account($this->db);
211 211
 
212
-      if(!$this->account->db_get_by_email($email_unsafe)) {
212
+      if (!$this->account->db_get_by_email($email_unsafe)) {
213 213
         throw new Exception(PASSWORD_RESTORE_ERROR_EMAIL_NOT_EXISTS, ERR_ERROR);
214 214
         // return $this->account_login_status;
215 215
       }
@@ -219,14 +219,14 @@  discard block
 block discarded – undo
219 219
 
220 220
       // TODO - Проверять уровень доступа аккаунта!
221 221
       // Аккаунты с АУТЛЕВЕЛ больше 0 - НЕ СБРАСЫВАЮТ ПАРОЛИ!
222
-      foreach($user_list as $user_id => $user_data) {
223
-        if($user_data['authlevel'] > AUTH_LEVEL_REGISTERED) {
222
+      foreach ($user_list as $user_id => $user_data) {
223
+        if ($user_data['authlevel'] > AUTH_LEVEL_REGISTERED) {
224 224
           throw new Exception(PASSWORD_RESTORE_ERROR_ADMIN_ACCOUNT, ERR_ERROR);
225 225
         }
226 226
       }
227 227
 
228 228
       $confirmation = $this->confirmation->db_confirmation_get_latest_by_type_and_email(CONFIRM_PASSWORD_RESET, $email_unsafe); // OK 4.5
229
-      if(isset($confirmation['create_time']) && SN_TIME_NOW - strtotime($confirmation['create_time']) < PERIOD_MINUTE_10) {
229
+      if (isset($confirmation['create_time']) && SN_TIME_NOW - strtotime($confirmation['create_time']) < PERIOD_MINUTE_10) {
230 230
         throw new Exception(PASSWORD_RESTORE_ERROR_TOO_OFTEN, ERR_ERROR);
231 231
       }
232 232
 
@@ -239,11 +239,11 @@  discard block
 block discarded – undo
239 239
 
240 240
       @$result = mymail($email_unsafe,
241 241
         sprintf(classLocale::$lang['log_lost_email_title'], classSupernova::$config->game_name),
242
-        sprintf(classLocale::$lang['log_lost_email_code'], SN_ROOT_VIRTUAL . 'login.php', $confirm_code_unsafe, date(FMT_DATE_TIME, SN_TIME_NOW + AUTH_PASSWORD_RESET_CONFIRMATION_EXPIRE), classSupernova::$config->game_name)
242
+        sprintf(classLocale::$lang['log_lost_email_code'], SN_ROOT_VIRTUAL.'login.php', $confirm_code_unsafe, date(FMT_DATE_TIME, SN_TIME_NOW + AUTH_PASSWORD_RESET_CONFIRMATION_EXPIRE), classSupernova::$config->game_name)
243 243
       );
244 244
 
245 245
       $result = $result ? PASSWORD_RESTORE_SUCCESS_CODE_SENT : PASSWORD_RESTORE_ERROR_SENDING;
246
-    } catch(Exception $e) {
246
+    } catch (Exception $e) {
247 247
       sn_db_transaction_rollback();
248 248
       $result = $e->getMessage();
249 249
     }
@@ -256,46 +256,46 @@  discard block
 block discarded – undo
256 256
    * @return int|string
257 257
    */
258 258
   protected function password_reset_confirm() {
259
-    if(!$this->is_password_reset_confirm) {
259
+    if (!$this->is_password_reset_confirm) {
260 260
       return $this->account_login_status;
261 261
     }
262 262
 
263
-    if($this->account_login_status != LOGIN_UNDEFINED) {
263
+    if ($this->account_login_status != LOGIN_UNDEFINED) {
264 264
       return $this->account_login_status;
265 265
     }
266 266
 
267 267
     // Проверяем поддержку сброса пароля
268
-    if(!$this->is_feature_supported(AUTH_FEATURE_PASSWORD_RESET)) {
268
+    if (!$this->is_feature_supported(AUTH_FEATURE_PASSWORD_RESET)) {
269 269
       return $this->account_login_status;
270 270
     }
271 271
 
272 272
     try {
273 273
       $code_unsafe = sys_get_param_str_unsafe('password_reset_code');
274
-      if(empty($code_unsafe)) {
274
+      if (empty($code_unsafe)) {
275 275
         throw new Exception(PASSWORD_RESTORE_ERROR_CODE_EMPTY, ERR_ERROR);
276 276
       }
277 277
 
278 278
       sn_db_transaction_start();
279 279
       $confirmation = $this->confirmation->db_confirmation_get_by_type_and_code(CONFIRM_PASSWORD_RESET, $code_unsafe); // OK 4.5
280 280
 
281
-      if(empty($confirmation)) {
281
+      if (empty($confirmation)) {
282 282
         throw new Exception(PASSWORD_RESTORE_ERROR_CODE_WRONG, ERR_ERROR);
283 283
       }
284 284
 
285
-      if(SN_TIME_NOW - strtotime($confirmation['create_time']) > AUTH_PASSWORD_RESET_CONFIRMATION_EXPIRE) {
285
+      if (SN_TIME_NOW - strtotime($confirmation['create_time']) > AUTH_PASSWORD_RESET_CONFIRMATION_EXPIRE) {
286 286
         throw new Exception(PASSWORD_RESTORE_ERROR_CODE_TOO_OLD, ERR_ERROR);
287 287
       }
288 288
 
289 289
       unset($this->account);
290 290
       $this->account = new Account($this->db);
291 291
 
292
-      if(!$this->account->db_get_by_email($confirmation['email'])) {
292
+      if (!$this->account->db_get_by_email($confirmation['email'])) {
293 293
         throw new Exception(PASSWORD_RESTORE_ERROR_CODE_OK_BUT_NO_ACCOUNT_FOR_EMAIL, ERR_ERROR);
294 294
       }
295 295
 
296 296
       $new_password_unsafe = $this->make_random_password();
297 297
       $salt_unsafe = $this->password_salt_generate();
298
-      if(!$this->account->db_set_password($new_password_unsafe, $salt_unsafe)) {
298
+      if (!$this->account->db_set_password($new_password_unsafe, $salt_unsafe)) {
299 299
         // Ошибка смены пароля
300 300
         throw new Exception(AUTH_ERROR_INTERNAL_PASSWORD_CHANGE_ON_RESTORE, ERR_ERROR);
301 301
       }
@@ -305,14 +305,14 @@  discard block
 block discarded – undo
305 305
       $this->cookie_set();
306 306
       $this->login_cookie();
307 307
 
308
-      if($this->account_login_status == LOGIN_SUCCESS) {
308
+      if ($this->account_login_status == LOGIN_SUCCESS) {
309 309
         // TODO - НЕ ОБЯЗАТЕЛЬНО ОТПРАВЛЯТЬ ЧЕРЕЗ ЕМЕЙЛ! ЕСЛИ ЭТО ФЕЙСБУЧЕК ИЛИ ВКШЕЧКА - МОЖНО ЧЕРЕЗ ЛС ПИСАТЬ!!
310 310
         $message_header = sprintf(classLocale::$lang['log_lost_email_title'], classSupernova::$config->game_name);
311 311
         $message = sprintf(classLocale::$lang['log_lost_email_pass'], classSupernova::$config->game_name, $this->account->account_name, $new_password_unsafe);
312 312
         @$operation_result = mymail($confirmation['email'], $message_header, htmlspecialchars($message));
313 313
 
314 314
         $users_translated = PlayerToAccountTranslate::db_translate_get_users_from_account_list($this->provider_id, $this->account->account_id); // OK 4.5
315
-        if(!empty($users_translated)) {
315
+        if (!empty($users_translated)) {
316 316
           // Отправляем в лички письмо о сбросе пароля
317 317
 
318 318
           // ПО ОПРЕДЕЛЕНИЮ в $users_translated только
@@ -321,9 +321,9 @@  discard block
 block discarded – undo
321 321
           //    - игроки, привязанные только к этим аккаунтам
322 322
           // Значит им всем сразу скопом можно отправлять сообщения
323 323
           $message = sprintf(classLocale::$lang['sys_password_reset_message_body'], $new_password_unsafe);
324
-          $message = sys_bbcodeParse($message) . '<br><br>';
324
+          $message = sys_bbcodeParse($message).'<br><br>';
325 325
 
326
-          foreach($users_translated as $user_id => $providers_list) {
326
+          foreach ($users_translated as $user_id => $providers_list) {
327 327
             msg_send_simple_message($user_id, 0, SN_TIME_NOW, MSG_TYPE_ADMIN, classLocale::$lang['sys_administration'], classLocale::$lang['sys_login_register_message_title'], $message);
328 328
           }
329 329
         } else {
@@ -375,10 +375,10 @@  discard block
 block discarded – undo
375 375
   // OK v4.5
376 376
   protected function register() {
377 377
     // TODO РЕГИСТРАЦИЯ ВСЕГДА ДОЛЖНА ЛОГИНИТЬ ПОЛЬЗОВАТЕЛЯ!
378
-    $this->flog('Регистрация: начинаем. Провайдер ' . $this->provider_id);
378
+    $this->flog('Регистрация: начинаем. Провайдер '.$this->provider_id);
379 379
 
380 380
     try {
381
-      if(!$this->is_register) {
381
+      if (!$this->is_register) {
382 382
         $this->flog('Регистрация: не выставлен флаг регистрации - пропускаем');
383 383
         throw new Exception(LOGIN_UNDEFINED, ERR_ERROR);
384 384
       }
@@ -388,8 +388,8 @@  discard block
 block discarded – undo
388 388
       sn_db_transaction_start();
389 389
 
390 390
       $this->account->db_get_by_name_or_email($this->input_login_unsafe, $this->input_email_unsafe);
391
-      if($this->account->is_exists) {
392
-        if($this->account->account_email == $this->input_email_unsafe) {
391
+      if ($this->account->is_exists) {
392
+        if ($this->account->account_email == $this->input_email_unsafe) {
393 393
           throw new Exception(REGISTER_ERROR_EMAIL_EXISTS, ERR_ERROR);
394 394
         } else {
395 395
           throw new Exception(REGISTER_ERROR_ACCOUNT_NAME_EXISTS, ERR_ERROR);
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
       // А вот это пока не нужно. Трансляцией аккаунтов в юзеров и созданием новых юзеров для новозашедших аккаунтов занимается Auth
412 412
       // $this->register_account();
413 413
       sn_db_transaction_commit();
414
-    } catch(Exception $e) {
414
+    } catch (Exception $e) {
415 415
       sn_db_transaction_rollback();
416 416
       $this->account_login_status == LOGIN_UNDEFINED ? $this->account_login_status = $e->getMessage() : false;
417 417
     }
@@ -427,19 +427,19 @@  discard block
 block discarded – undo
427 427
    */
428 428
   // OK v4.5
429 429
   protected function login_cookie() {
430
-    if($this->account_login_status != LOGIN_UNDEFINED) {
430
+    if ($this->account_login_status != LOGIN_UNDEFINED) {
431 431
       return $this->account_login_status;
432 432
     }
433 433
 
434 434
     // Пытаемся войти по куке
435
-    if(!empty($_COOKIE[$this->cookie_name])) {
436
-      if(count(explode("/%/", $_COOKIE[$this->cookie_name])) < 4) {
435
+    if (!empty($_COOKIE[$this->cookie_name])) {
436
+      if (count(explode("/%/", $_COOKIE[$this->cookie_name])) < 4) {
437 437
         list($account_id_unsafe, $cookie_password_hash_salted, $user_remember_me) = explode(AUTH_COOKIE_DELIMETER, $_COOKIE[$this->cookie_name]);
438 438
       } else {
439 439
         list($account_id_unsafe, $user_name, $cookie_password_hash_salted, $user_remember_me) = explode("/%/", $_COOKIE[$this->cookie_name]);
440 440
       }
441 441
 
442
-      if(
442
+      if (
443 443
         $this->account->db_get_by_id($account_id_unsafe)
444 444
         && ($this->password_encode_for_cookie($this->account->account_password) == $cookie_password_hash_salted)
445 445
       ) {
@@ -448,7 +448,7 @@  discard block
 block discarded – undo
448 448
       }
449 449
     }
450 450
 
451
-    if($this->account_login_status != LOGIN_SUCCESS) {
451
+    if ($this->account_login_status != LOGIN_SUCCESS) {
452 452
       // Невалидная кука - чистим
453 453
       $this->cookie_clear();
454 454
     }
@@ -466,29 +466,29 @@  discard block
 block discarded – undo
466 466
   protected function login_username() {
467 467
     // TODO - Логин по старым именам
468 468
     try {
469
-      if(!$this->is_login) {
469
+      if (!$this->is_login) {
470 470
         $this->flog('Логин: не выставлен флаг входа в игру - это не логин');
471 471
         throw new Exception(LOGIN_UNDEFINED, ERR_ERROR);
472 472
       }
473 473
 
474 474
       // TODO Пустое имя аккаунта
475
-      if(!$this->input_login_unsafe) {
475
+      if (!$this->input_login_unsafe) {
476 476
         throw new Exception(LOGIN_UNDEFINED, ERR_ERROR);
477 477
       }
478 478
 
479 479
       $this->login_validate_input();
480 480
 
481
-      if(!$this->account->db_get_by_name($this->input_login_unsafe) && !$this->account->db_get_by_email($this->input_login_unsafe)) {
481
+      if (!$this->account->db_get_by_name($this->input_login_unsafe) && !$this->account->db_get_by_email($this->input_login_unsafe)) {
482 482
         throw new Exception(LOGIN_ERROR_USERNAME, ERR_ERROR);
483 483
       }
484 484
 
485
-      if(!$this->account->password_check($this->input_login_password_raw)) {
485
+      if (!$this->account->password_check($this->input_login_password_raw)) {
486 486
         throw new Exception(LOGIN_ERROR_PASSWORD, ERR_ERROR);
487 487
       }
488 488
 
489 489
       $this->cookie_set();
490 490
       $this->account_login_status = LOGIN_SUCCESS;
491
-    } catch(Exception $e) {
491
+    } catch (Exception $e) {
492 492
       $this->account_login_status == LOGIN_UNDEFINED ? $this->account_login_status = $e->getMessage() : false;
493 493
     }
494 494
 
@@ -510,18 +510,18 @@  discard block
 block discarded – undo
510 510
   protected function cookie_set($account_to_impersonate = null) {
511 511
     $this_account = is_object($account_to_impersonate) ? $account_to_impersonate : $this->account;
512 512
 
513
-    if(!is_object($this_account) || !$this_account->is_exists) {
513
+    if (!is_object($this_account) || !$this_account->is_exists) {
514 514
       throw new Exception(LOGIN_ERROR_NO_ACCOUNT_FOR_COOKIE_SET, ERR_ERROR);
515 515
     }
516 516
 
517
-    if(is_object($account_to_impersonate) && $account_to_impersonate->is_exists) {
517
+    if (is_object($account_to_impersonate) && $account_to_impersonate->is_exists) {
518 518
       sn_setcookie($this->cookie_name_impersonate, $_COOKIE[$this->cookie_name], SN_TIME_NOW + PERIOD_YEAR, $this->sn_root_path, $this->domain);
519 519
     }
520 520
 
521 521
     $expire_time = $this->remember_me ? SN_TIME_NOW + PERIOD_YEAR : 0;
522 522
 
523 523
     $password_encoded = $this->password_encode_for_cookie($this_account->account_password);
524
-    $cookie = $this_account->account_id . AUTH_COOKIE_DELIMETER . $password_encoded . AUTH_COOKIE_DELIMETER . $this->remember_me;
524
+    $cookie = $this_account->account_id.AUTH_COOKIE_DELIMETER.$password_encoded.AUTH_COOKIE_DELIMETER.$this->remember_me;
525 525
     $this->flog("cookie_set() - Устанавливаем куку {$cookie}");
526 526
     return sn_setcookie($this->cookie_name, $cookie, $expire_time, $this->sn_root_path, $this->domain);
527 527
   }
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
   // OK v4.1
533 533
   protected function cookie_clear() {
534 534
     // Автоматически вообще-то - если установлена кука имперсонатора - то чистим обычную, а куку имперсонатора - копируем в неё
535
-    if(!empty($_COOKIE[$this->cookie_name_impersonate])) {
535
+    if (!empty($_COOKIE[$this->cookie_name_impersonate])) {
536 536
       sn_setcookie($this->cookie_name, $_COOKIE[$this->cookie_name_impersonate], SN_TIME_NOW + PERIOD_YEAR, $this->sn_root_path, $this->domain);
537 537
       sn_setcookie($this->cookie_name_impersonate, '', SN_TIME_NOW - PERIOD_WEEK, $this->sn_root_path, $this->domain);
538 538
     } else {
@@ -551,10 +551,10 @@  discard block
 block discarded – undo
551 551
   protected function login_validate_input() {
552 552
     // Проверяем, что бы в начале и конце не было пустых символов
553 553
     // TODO - при копировании Эксель -> Опера - в конце образуются пустые места. Это не должно быть проблемой! Вынести проверку пароля в регистрацию!
554
-    if($this->input_login_password_raw != trim($this->input_login_password_raw)) {
554
+    if ($this->input_login_password_raw != trim($this->input_login_password_raw)) {
555 555
       throw new Exception(LOGIN_ERROR_PASSWORD_TRIMMED, ERR_ERROR);
556 556
     }
557
-    if(!$this->input_login_password_raw) {
557
+    if (!$this->input_login_password_raw) {
558 558
       throw new Exception(LOGIN_ERROR_PASSWORD_EMPTY, ERR_ERROR);
559 559
     }
560 560
   }
@@ -570,37 +570,37 @@  discard block
 block discarded – undo
570 570
     $this->login_validate_input();
571 571
 
572 572
     // Если нет имени пользователя - NO GO!
573
-    if(!$this->input_login_unsafe) {
573
+    if (!$this->input_login_unsafe) {
574 574
       throw new Exception(LOGIN_ERROR_USERNAME_EMPTY, ERR_ERROR);
575 575
     }
576 576
     // Если логин имеет запрещенные символы - NO GO!
577
-    if(strpbrk($this->input_login_unsafe, LOGIN_REGISTER_CHARACTERS_PROHIBITED)) {
577
+    if (strpbrk($this->input_login_unsafe, LOGIN_REGISTER_CHARACTERS_PROHIBITED)) {
578 578
       throw new Exception(LOGIN_ERROR_USERNAME_RESTRICTED_CHARACTERS, ERR_ERROR);
579 579
     }
580 580
     // Если логин меньше минимальной длины - NO GO!
581
-    if(strlen($this->input_login_unsafe) < LOGIN_LENGTH_MIN) {
581
+    if (strlen($this->input_login_unsafe) < LOGIN_LENGTH_MIN) {
582 582
       throw new Exception(REGISTER_ERROR_USERNAME_SHORT, ERR_ERROR);
583 583
     }
584 584
     // Если пароль меньше минимальной длины - NO GO!
585
-    if(strlen($this->input_login_password_raw) < PASSWORD_LENGTH_MIN) {
585
+    if (strlen($this->input_login_password_raw) < PASSWORD_LENGTH_MIN) {
586 586
       throw new Exception(REGISTER_ERROR_PASSWORD_INSECURE, ERR_ERROR);
587 587
     }
588 588
     // Если пароль имеет пробельные символы в начале или конце - NO GO!
589
-    if($this->input_login_password_raw != trim($this->input_login_password_raw)) {
589
+    if ($this->input_login_password_raw != trim($this->input_login_password_raw)) {
590 590
       throw new Exception(LOGIN_ERROR_PASSWORD_TRIMMED, ERR_ERROR);
591 591
     }
592 592
     // Если пароль не совпадает с подтверждением - NO GO! То, что у пароля нет пробельных символов в начале/конце - мы уже проверили выше
593 593
     //Если они есть у повтора - значит пароль и повтор не совпадут
594
-    if($this->input_login_password_raw <> $this->input_login_password_raw_repeat) {
594
+    if ($this->input_login_password_raw <> $this->input_login_password_raw_repeat) {
595 595
       throw new Exception(REGISTER_ERROR_PASSWORD_DIFFERENT, ERR_ERROR);
596 596
     }
597 597
     // Если нет емейла - NO GO!
598 598
     // TODO - регистрация без емейла
599
-    if(!$this->input_email_unsafe) {
599
+    if (!$this->input_email_unsafe) {
600 600
       throw new Exception(REGISTER_ERROR_EMAIL_EMPTY, ERR_ERROR);
601 601
     }
602 602
     // Если емейл не является емейлом - NO GO!
603
-    if(!is_email($this->input_email_unsafe)) {
603
+    if (!is_email($this->input_email_unsafe)) {
604 604
       throw new Exception(REGISTER_ERROR_EMAIL_WRONG, ERR_ERROR);
605 605
     }
606 606
   }
@@ -609,7 +609,7 @@  discard block
 block discarded – undo
609 609
 
610 610
   // OK v4
611 611
   protected function password_encode_for_cookie($password) {
612
-    return md5("{$password}--" . $this->secret_word);
612
+    return md5("{$password}--".$this->secret_word);
613 613
   }
614 614
   // OK v4
615 615
   protected function password_encode($password, $salt) {
@@ -629,22 +629,22 @@  discard block
 block discarded – undo
629 629
     return core_auth::make_random_password();
630 630
   }
631 631
   protected function flog($message, $die = false) {
632
-    if(!defined('DEBUG_AUTH') || !DEBUG_AUTH) {
632
+    if (!defined('DEBUG_AUTH') || !DEBUG_AUTH) {
633 633
       return;
634 634
     }
635 635
     list($called, $caller) = debug_backtrace(false);
636 636
 
637 637
     $caller_name =
638
-      ((get_called_class()) ? get_called_class() : (!empty($caller['class']) ? $caller['class'] : '')) .
639
-      (!empty($caller['type']) ? $caller['type'] : '') .
640
-      (!empty($caller['function']) ? $caller['function'] : '') .
641
-      (!empty($called['line']) ? ':' . $called['line'] : '');
638
+      ((get_called_class()) ? get_called_class() : (!empty($caller['class']) ? $caller['class'] : '')).
639
+      (!empty($caller['type']) ? $caller['type'] : '').
640
+      (!empty($caller['function']) ? $caller['function'] : '').
641
+      (!empty($called['line']) ? ':'.$called['line'] : '');
642 642
 
643 643
     $_SERVER['SERVER_NAME'] == 'localhost' ? print("<div class='debug'>$message - $caller_name\r\n</div>") : false;
644 644
 
645 645
     classSupernova::log_file("$message - $caller_name");
646
-    if($die) {
647
-      $die && die("<div class='negative'>СТОП! Функция {$caller_name} при вызове в " . get_called_class() . " (располагается в " . get_class() . "). СООБЩИТЕ АДМИНИСТРАЦИИ!</div>");
646
+    if ($die) {
647
+      $die && die("<div class='negative'>СТОП! Функция {$caller_name} при вызове в ".get_called_class()." (располагается в ".get_class()."). СООБЩИТЕ АДМИНИСТРАЦИИ!</div>");
648 648
     }
649 649
   }
650 650
 
Please login to merge, or discard this patch.
includes/classes/Confirmation.php 2 patches
Doc Comments   +19 added lines patch added patch discarded remove patch
@@ -18,6 +18,11 @@  discard block
 block discarded – undo
18 18
 
19 19
   // TODO - НЕ ОБЯЗАТЕЛЬНО ОТПРАВЛЯТЬ ЧЕРЕЗ ЕМЕЙЛ! ЕСЛИ ЭТО ФЕЙСБУЧЕК ИЛИ ВКШЕЧКА - МОЖНО ЧЕРЕЗ ЛС ПИСАТЬ!!
20 20
   // TODO - OK 4.6
21
+
22
+  /**
23
+   * @param integer $confirmation_type_safe
24
+   * @param string $email_unsafe
25
+   */
21 26
   public function db_confirmation_get_latest_by_type_and_email($confirmation_type_safe, $email_unsafe) {
22 27
     $email_safe = $this->db->db_escape($email_unsafe);
23 28
 
@@ -26,12 +31,21 @@  discard block
 block discarded – undo
26 31
           `type` = {$confirmation_type_safe} AND `email` = '{$email_safe}' ORDER BY create_time DESC LIMIT 1;", true);
27 32
   }
28 33
   // TODO - OK 4.6
34
+
35
+  /**
36
+   * @param integer $confirmation_type_safe
37
+   */
29 38
   public function db_confirmation_delete_by_type_and_email($confirmation_type_safe, $email_unsafe) {
30 39
     $email_safe = $this->db->db_escape($email_unsafe);
31 40
 
32 41
     return $this->db->doquery("DELETE FROM {{confirmations}} WHERE `type` = {$confirmation_type_safe} AND `email` = '{$email_safe}'");
33 42
   }
34 43
   // TODO - OK 4.6
44
+
45
+  /**
46
+   * @param integer $confirmation_type_safe
47
+   * @param string $email_unsafe
48
+   */
35 49
   public function db_confirmation_get_unique_code_by_type_and_email($confirmation_type_safe, $email_unsafe) {
36 50
     $email_safe = $this->db->db_escape($email_unsafe);
37 51
 
@@ -50,6 +64,11 @@  discard block
 block discarded – undo
50 64
     return $confirm_code_unsafe;
51 65
   }
52 66
   // TODO - OK 4.6
67
+
68
+  /**
69
+   * @param integer $confirmation_type_safe
70
+   * @param string $confirmation_code_unsafe
71
+   */
53 72
   public function db_confirmation_get_by_type_and_code($confirmation_type_safe, $confirmation_code_unsafe) {
54 73
     $confirmation_code_safe = $this->db->db_escape($confirmation_code_unsafe);
55 74
 
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@
 block discarded – undo
41 41
       // $query = static::$db->doquery("SELECT `id` FROM {{confirmations}} WHERE `code` = '{$confirm_code_safe}' AND `type` = {$confirmation_type_safe} FOR UPDATE", true);
42 42
       // Тип не нужен для проверки - код подтверждения должен быть уникален от слова "совсем"
43 43
       $query = $this->db->doquery("SELECT `id` FROM {{confirmations}} WHERE `code` = '{$confirm_code_safe}' FOR UPDATE", true);
44
-    } while($query);
44
+    } while ($query);
45 45
 
46 46
     $this->db->doquery(
47 47
       "REPLACE INTO {{confirmations}}
Please login to merge, or discard this patch.
includes/classes/db_mysql_v4.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -55,6 +55,9 @@
 block discarded – undo
55 55
     return true;
56 56
   }
57 57
 
58
+  /**
59
+   * @param string $query_string
60
+   */
58 61
   function mysql_query($query_string) {
59 62
     return mysql_query($query_string, $this->link);
60 63
   }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@
 block discarded – undo
52 52
     !mysql_select_db($settings['name'])
53 53
       ? classSupernova::$debug->error_fatal('DB error - cannot find DB on server', $this->mysql_error())
54 54
       : false;
55
-    !$this->mysql_query('SET SESSION TRANSACTION ISOLATION LEVEL ' . self::DB_MYSQL_TRANSACTION_REPEATABLE_READ . ';')
55
+    !$this->mysql_query('SET SESSION TRANSACTION ISOLATION LEVEL '.self::DB_MYSQL_TRANSACTION_REPEATABLE_READ.';')
56 56
       ? classSupernova::$debug->error_fatal('DB error - cannot set desired isolation level', $this->mysql_error())
57 57
       : false;
58 58
 
Please login to merge, or discard this patch.
includes/classes/sn_module_payment.php 2 patches
Doc Comments   +7 added lines, -1 removed lines patch added patch discarded remove patch
@@ -702,7 +702,7 @@  discard block
 block discarded – undo
702 702
    * Рассчёт бонуса ММ
703 703
    *
704 704
    * @param            $dark_matter
705
-   * @param bool|true  $direct
705
+   * @param boolean  $direct
706 706
    * @param bool|false $return_bonus
707 707
    *
708 708
    * @return float|int
@@ -738,6 +738,12 @@  discard block
 block discarded – undo
738 738
 
739 739
   // Дополнительная ре-трансляция адреса, если в каком-то случае платежная система ожидает нелогичный ответ
740 740
   // Пример: иксолла при неправильно заданном пользователе в ордере ожидает НЕПРАВИЛЬНЫЙ_ОРДЕР, а не НЕПРАВИЛЬНЫЙ_ПОЛЬЗОВАТЕЛЬ
741
+
742
+  /**
743
+   * @param integer $error_code
744
+   *
745
+   * @return integer|null
746
+   */
741 747
   function retranslate_error($error_code, $options = array()) {
742 748
     return isset($options['retranslate_error'][$error_code]) ? $options['retranslate_error'][$error_code] : $error_code;
743 749
   }
Please login to merge, or discard this patch.
Spacing   +70 added lines, -70 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 $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 = classSupernova::$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
   }
@@ -500,26 +500,26 @@  discard block
 block discarded – undo
500 500
    * @throws Exception
501 501
    */
502 502
   protected function payment_request_process($options = array()) {
503
-    if(!$this->manifest['active']) {
503
+    if (!$this->manifest['active']) {
504 504
       throw new Exception(classLocale::$lang['pay_msg_module_disabled'], SN_MODULE_DISABLED);
505 505
     }
506 506
 
507 507
     // Если есть payment_id - загружаем под него данные
508
-    if(!empty($this->payment_params['payment_id'])) {
508
+    if (!empty($this->payment_params['payment_id'])) {
509 509
       $this->request_payment_id = sys_get_param_id($this->payment_params['payment_id']);
510
-      if(!$this->request_payment_id) {
510
+      if (!$this->request_payment_id) {
511 511
         throw new Exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_INTERNAL_ID_WRONG);
512 512
       }
513 513
 
514
-      if(!$this->db_get_by_id($this->request_payment_id)) {
514
+      if (!$this->db_get_by_id($this->request_payment_id)) {
515 515
         throw new Exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_INTERNAL_ID_WRONG);
516 516
       }
517 517
 
518 518
       // Проверяем - был ли этот платеж обработан?
519 519
       // TODO - Статусы бывают разные. Нужен спецфлаг payment_processed
520
-      if($this->payment_status != PAYMENT_STATUS_NONE) {
520
+      if ($this->payment_status != PAYMENT_STATUS_NONE) {
521 521
         sn_db_transaction_rollback();
522
-        sys_redirect(SN_ROOT_VIRTUAL . 'metamatter.php?payment_id=' . $this->payment_id);
522
+        sys_redirect(SN_ROOT_VIRTUAL.'metamatter.php?payment_id='.$this->payment_id);
523 523
         die();
524 524
       }
525 525
     }
@@ -527,89 +527,89 @@  discard block
 block discarded – undo
527 527
     // Пытаемся получить из запроса ИД аккаунта
528 528
     $request_account_id = !empty($this->payment_params['account_id']) ? sys_get_param_id($this->payment_params['account_id']) : 0;
529 529
     // Если в запросе нет ИД аккаунта - пытаемся использовать payment_account_id
530
-    if(empty($request_account_id) && !empty($this->payment_account_id)) {
530
+    if (empty($request_account_id) && !empty($this->payment_account_id)) {
531 531
       $request_account_id = $this->payment_account_id;
532 532
     }
533 533
     // Если теперь у нас нету ИД аккаунта ни в запросе, ни в записи таблицы - можно паниковать
534
-    if(empty($request_account_id)) {
534
+    if (empty($request_account_id)) {
535 535
       // TODO - аккаунт
536 536
       throw new Exception(classLocale::$lang['pay_msg_request_user_invalid'], $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options));
537 537
     }
538 538
     // Если нет записи в таблице - тогда берем payment_account_id из запроса
539
-    if(empty($this->payment_account_id)) {
539
+    if (empty($this->payment_account_id)) {
540 540
       $this->payment_account_id = $request_account_id;
541 541
     }
542 542
     // Если у нас отличаются ИД аккаунта в запросе и ИД аккаунта в записи - тоже можно паниковать
543
-    if($this->payment_account_id != $request_account_id) {
543
+    if ($this->payment_account_id != $request_account_id) {
544 544
       // TODO - Поменять сообщение об ошибке
545 545
       throw new Exception(classLocale::$lang['pay_msg_request_user_invalid'], $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options));
546 546
     }
547 547
     // Проверяем существование аккаунта с данным ИД
548
-    if(!$this->account->db_get_by_id($this->payment_account_id)) {
549
-      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));
548
+    if (!$this->account->db_get_by_id($this->payment_account_id)) {
549
+      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));
550 550
     }
551 551
 
552 552
     // TODO Проверка на сервер_ид - как бы и не нужна, наверное?
553
-    if(!empty($this->payment_params['server_id'])) {
553
+    if (!empty($this->payment_params['server_id'])) {
554 554
       $this->request_server_id = sys_get_param_str($this->payment_params['server_id']);
555
-      if(SN_ROOT_VIRTUAL != $this->request_server_id) {
556
-        throw new Exception(classLocale::$lang['pay_msg_request_server_wrong'] . " {$this->request_server_id} вместо " . SN_ROOT_VIRTUAL, SN_PAYMENT_REQUEST_SERVER_WRONG);
555
+      if (SN_ROOT_VIRTUAL != $this->request_server_id) {
556
+        throw new Exception(classLocale::$lang['pay_msg_request_server_wrong']." {$this->request_server_id} вместо ".SN_ROOT_VIRTUAL, SN_PAYMENT_REQUEST_SERVER_WRONG);
557 557
       }
558 558
     }
559 559
 
560 560
     // Сверка количества оплаченной ММ с учётом бонусов
561
-    if(!empty($this->payment_params['payment_dark_matter_gained'])) {
561
+    if (!empty($this->payment_params['payment_dark_matter_gained'])) {
562 562
       $request_mm_amount = sys_get_param_id($this->payment_params['payment_dark_matter_gained']);
563
-      if($request_mm_amount != $this->payment_dark_matter_gained && $this->is_loaded) {
564
-        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);
563
+      if ($request_mm_amount != $this->payment_dark_matter_gained && $this->is_loaded) {
564
+        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);
565 565
       }
566 566
       empty($this->payment_dark_matter_gained) ? $this->payment_dark_matter_gained = $request_mm_amount : false;
567 567
     }
568
-    if(empty($this->payment_dark_matter_paid)) {
568
+    if (empty($this->payment_dark_matter_paid)) {
569 569
       // TODO - обратный расчёт из gained
570 570
     }
571 571
 
572 572
     // Проверка наличия внешнего ИД платежа
573
-    if(!empty($this->payment_params['payment_external_id'])) {
573
+    if (!empty($this->payment_params['payment_external_id'])) {
574 574
       $request_payment_external_id = sys_get_param_id($this->payment_params['payment_external_id']);
575
-      if(empty($request_payment_external_id)) {
575
+      if (empty($request_payment_external_id)) {
576 576
         throw new exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_EXTERNAL_ID_WRONG);
577
-      } elseif(!empty($this->payment_external_id) && $this->payment_external_id != $request_payment_external_id) {
577
+      } elseif (!empty($this->payment_external_id) && $this->payment_external_id != $request_payment_external_id) {
578 578
         // TODO - Может быть поменять сообщение
579 579
         throw new exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_EXTERNAL_ID_WRONG);
580 580
       }
581 581
       $this->payment_external_id = $request_payment_external_id;
582 582
     }
583 583
     // Сверка суммы, запрошенной СН к оплате
584
-    if(!empty($this->payment_params['payment_external_money'])) {
584
+    if (!empty($this->payment_params['payment_external_money'])) {
585 585
       $request_money_out = sys_get_param_float($this->payment_params['payment_external_money']);
586
-      if($request_money_out != $this->payment_external_amount && $this->is_loaded) {
587
-        throw new Exception(classLocale::$lang['pay_msg_request_payment_amount_invalid'] . " пришло {$request_money_out} денег вместо {$this->payment_external_amount} денег", SN_PAYMENT_REQUEST_CURRENCY_AMOUNT_INVALID);
586
+      if ($request_money_out != $this->payment_external_amount && $this->is_loaded) {
587
+        throw new Exception(classLocale::$lang['pay_msg_request_payment_amount_invalid']." пришло {$request_money_out} денег вместо {$this->payment_external_amount} денег", SN_PAYMENT_REQUEST_CURRENCY_AMOUNT_INVALID);
588 588
       }
589 589
       empty($this->payment_external_amount) ? $this->payment_external_amount = $request_money_out : false;
590 590
     }
591 591
     // Заполняем поле валюты платёжной системы
592
-    if(!empty($this->payment_params['payment_external_currency'])) {
592
+    if (!empty($this->payment_params['payment_external_currency'])) {
593 593
       $this->payment_external_currency = sys_get_param_str($this->payment_params['payment_external_currency']);
594
-      if(empty($this->payment_external_currency)) {
594
+      if (empty($this->payment_external_currency)) {
595 595
         // TODO - поменять сообщение
596
-        throw new Exception(classLocale::$lang['pay_msg_request_payment_amount_invalid'] . " {$this->payment_external_currency}", SN_PAYMENT_REQUEST_CURRENCY_AMOUNT_INVALID);
596
+        throw new Exception(classLocale::$lang['pay_msg_request_payment_amount_invalid']." {$this->payment_external_currency}", SN_PAYMENT_REQUEST_CURRENCY_AMOUNT_INVALID);
597 597
       }
598 598
     }
599
-    if(empty($this->payment_external_currency)) {
599
+    if (empty($this->payment_external_currency)) {
600 600
       $this->payment_external_currency = $this->config['currency'];
601 601
     }
602 602
 
603 603
     // Заполнение внутренней суммы и валюты из внешних данных
604
-    if(empty($this->payment_currency)) {
604
+    if (empty($this->payment_currency)) {
605 605
       $this->payment_currency = classSupernova::$config->payment_currency_default;
606 606
     }
607
-    if(empty($this->payment_amount) && !empty($this->payment_external_currency)) {
607
+    if (empty($this->payment_amount) && !empty($this->payment_external_currency)) {
608 608
       $this->payment_amount = self::currency_convert($this->payment_external_amount, $this->payment_external_currency, $this->payment_currency);
609 609
     }
610 610
 
611 611
     // TODO - Тестовый режим
612
-    if(!empty($this->payment_params['test'])) {
612
+    if (!empty($this->payment_params['test'])) {
613 613
       $this->payment_test = $this->config['test'] || sys_get_param_int($this->payment_params['test']);
614 614
     }
615 615
 
@@ -636,21 +636,21 @@  discard block
 block discarded – undo
636 636
     sn_db_transaction_start();
637 637
     try {
638 638
       $response = $this->payment_request_process();
639
-    } catch(Exception $e) {
639
+    } catch (Exception $e) {
640 640
       $response['result'] = $e->getCode();
641 641
       $response['message'] = $e->getMessage();
642 642
     }
643 643
 
644
-    if($response['result'] == SN_PAYMENT_REQUEST_OK) {
644
+    if ($response['result'] == SN_PAYMENT_REQUEST_OK) {
645 645
       sn_db_transaction_commit();
646
-      classSupernova::$debug->warning('Результат операции: код ' . $response['result'] . ' сообщение "' . $response['message'] . '"', 'Успешный платёж', LOG_INFO_PAYMENT);
646
+      classSupernova::$debug->warning('Результат операции: код '.$response['result'].' сообщение "'.$response['message'].'"', 'Успешный платёж', LOG_INFO_PAYMENT);
647 647
     } else {
648 648
       sn_db_transaction_rollback();
649
-      classSupernova::$debug->warning('Результат операции: код ' . $response['result'] . ' сообщение "' . $response['message'] . '"', 'Ошибка платежа', LOG_INFO_PAYMENT, true);
649
+      classSupernova::$debug->warning('Результат операции: код '.$response['result'].' сообщение "'.$response['message'].'"', 'Ошибка платежа', LOG_INFO_PAYMENT, true);
650 650
     }
651 651
 
652 652
     // Переводим код результата из СН в код платежной системы
653
-    if(is_array($this->result_translations) && !empty($this->result_translations)) {
653
+    if (is_array($this->result_translations) && !empty($this->result_translations)) {
654 654
       $response['result'] = isset($this->result_translations[$response['result']]) ? $this->result_translations[$response['result']] : $this->result_translations[SN_PAYMENT_REQUEST_UNDEFINED_ERROR];
655 655
     }
656 656
 
@@ -673,7 +673,7 @@  discard block
 block discarded – undo
673 673
     $currency_from = strtolower($currency_from);
674 674
     $currency_to = strtolower($currency_to);
675 675
 
676
-    if($currency_from != $currency_to) {
676
+    if ($currency_from != $currency_to) {
677 677
       $exchange_from = get_exchange_rate($currency_from);
678 678
       $exchange_to = get_exchange_rate($currency_to);
679 679
 
@@ -697,10 +697,10 @@  discard block
 block discarded – undo
697 697
   public static function bonus_calculate($dark_matter, $direct = true, $return_bonus = false) {
698 698
     $bonus = 0;
699 699
     $dark_matter_new = $dark_matter;
700
-    if(!empty(self::$bonus_table) && $dark_matter >= self::$bonus_table[0]) {
701
-      if($direct) {
702
-        foreach(self::$bonus_table as $dm_for_bonus => $multiplier) {
703
-          if($dm_for_bonus <= $dark_matter) {
700
+    if (!empty(self::$bonus_table) && $dark_matter >= self::$bonus_table[0]) {
701
+      if ($direct) {
702
+        foreach (self::$bonus_table as $dm_for_bonus => $multiplier) {
703
+          if ($dm_for_bonus <= $dark_matter) {
704 704
             $dark_matter_new = $dark_matter * (1 + $multiplier);
705 705
             $bonus = $multiplier;
706 706
           } else {
@@ -708,9 +708,9 @@  discard block
 block discarded – undo
708 708
           }
709 709
         }
710 710
       } else {
711
-        foreach(self::$bonus_table as $dm_for_bonus => $multiplier) {
711
+        foreach (self::$bonus_table as $dm_for_bonus => $multiplier) {
712 712
           $temp = $dm_for_bonus * (1 + $multiplier);
713
-          if($dark_matter >= $temp) {
713
+          if ($dark_matter >= $temp) {
714 714
             $dark_matter_new = round($dark_matter / (1 + $multiplier));
715 715
             $bonus = $multiplier;
716 716
           } else {
@@ -764,30 +764,30 @@  discard block
 block discarded – undo
764 764
     );
765 765
 
766 766
     $replace = false;
767
-    if($this->payment_id) {
767
+    if ($this->payment_id) {
768 768
       $payment['payment_id'] = $this->payment_id;
769 769
       $replace = true;
770 770
     }
771 771
 
772 772
     $query = array();
773
-    foreach($payment as $key => $value) {
774
-      $value = is_string($value) ? '"' . db_escape($value) . '"' : $value;
773
+    foreach ($payment as $key => $value) {
774
+      $value = is_string($value) ? '"'.db_escape($value).'"' : $value;
775 775
       $query[] = "`{$key}` = {$value}";
776 776
     }
777 777
 
778
-    $this->db->doquery(($replace ? 'REPLACE' : 'INSERT') . ' INTO `{{payment}}` SET ' . implode(',', $query) . ';');
778
+    $this->db->doquery(($replace ? 'REPLACE' : 'INSERT').' INTO `{{payment}}` SET '.implode(',', $query).';');
779 779
 
780 780
     return $this->db_get_by_id($this->db->db_insert_id());
781 781
   }
782 782
 
783 783
 
784 784
   function payment_adjust_mm_new() {
785
-    if(!$this->payment_test) {
785
+    if (!$this->payment_test) {
786 786
       // Not a test payment. Adding DM to account
787 787
       $this->account = new Account($this->db);
788 788
       $this->account->db_get_by_id($this->payment_account_id);
789 789
       $result = $this->account->metamatter_change(RPG_PURCHASE, $this->payment_dark_matter_gained, $this->payment_comment);
790
-      if(!$result) {
790
+      if (!$result) {
791 791
         throw new Exception('Ошибка начисления ММ', SN_METAMATTER_ERROR_ADJUST);
792 792
       }
793 793
     }
@@ -796,25 +796,25 @@  discard block
 block discarded – undo
796 796
   function payment_cancel(&$payment) {
797 797
     die('{НЕ РАБОТАЕТ! СООБЩИТЕ АДМИНИСТРАЦИИ!}');
798 798
 
799
-    if(!isset($payment['payment_status'])) {
799
+    if (!isset($payment['payment_status'])) {
800 800
       throw new exception(classLocale::$lang['pay_msg_request_payment_not_found'], SN_PAYMENT_REQUEST_ORDER_NOT_FOUND);
801 801
     }
802 802
 
803
-    if($payment['payment_status'] == PAYMENT_STATUS_COMPLETE) {
804
-      $safe_comment = db_escape($payment['payment_comment'] = classLocale::$lang['pay_msg_request_payment_cancelled'] .' ' . $payment['payment_comment']);
803
+    if ($payment['payment_status'] == PAYMENT_STATUS_COMPLETE) {
804
+      $safe_comment = db_escape($payment['payment_comment'] = classLocale::$lang['pay_msg_request_payment_cancelled'].' '.$payment['payment_comment']);
805 805
 
806
-      if(!$payment['payment_test']) {
806
+      if (!$payment['payment_test']) {
807 807
         $result = $this->account->metamatter_change(RPG_PURCHASE_CANCEL, -$payment['payment_dark_matter_gained'], $payment['payment_comment']);
808
-        if(!$result) {
808
+        if (!$result) {
809 809
           throw new exception('Ошибка начисления ММ', SN_METAMATTER_ERROR_ADJUST);
810 810
         }
811 811
       }
812 812
       $payment['payment_status'] = PAYMENT_STATUS_CANCELED;
813 813
       db_payment_update($payment, $safe_comment);
814 814
       throw new exception(classLocale::$lang['pay_msg_request_payment_cancel_complete'], SN_PAYMENT_REQUEST_OK);
815
-    } elseif($payment['payment_status'] == PAYMENT_STATUS_CANCELED) {
815
+    } elseif ($payment['payment_status'] == PAYMENT_STATUS_CANCELED) {
816 816
       throw new exception(classLocale::$lang['pay_msg_request_payment_cancelled_already'], SN_PAYMENT_REQUEST_OK);
817
-    } elseif($payment['payment_status'] == PAYMENT_STATUS_NONE) {
817
+    } elseif ($payment['payment_status'] == PAYMENT_STATUS_NONE) {
818 818
       throw new exception(classLocale::$lang['pay_msg_request_payment_cancel_not_complete'], SN_PAYMENT_REQUEST_PAYMENT_NOT_COMPLETE);
819 819
     }
820 820
   }
@@ -828,8 +828,8 @@  discard block
 block discarded – undo
828 828
 
829 829
   protected function db_complete_payment() {
830 830
     // TODO - поле payment_processed
831
-    if($this->payment_status == PAYMENT_STATUS_NONE) {
832
-      if(!defined('PAYMENT_EXPIRE_TIME') || PAYMENT_EXPIRE_TIME == 0 || empty($this->payment_date) || strtotime($this->payment_date) + PAYMENT_EXPIRE_TIME <= SN_TIME_NOW) {
831
+    if ($this->payment_status == PAYMENT_STATUS_NONE) {
832
+      if (!defined('PAYMENT_EXPIRE_TIME') || PAYMENT_EXPIRE_TIME == 0 || empty($this->payment_date) || strtotime($this->payment_date) + PAYMENT_EXPIRE_TIME <= SN_TIME_NOW) {
833 833
         $this->payment_adjust_mm_new();
834 834
         $this->payment_status = PAYMENT_STATUS_COMPLETE;
835 835
       } else {
@@ -876,7 +876,7 @@  discard block
 block discarded – undo
876 876
   protected function db_assign_payment($payment = null) {
877 877
     $this->payment_reset();
878 878
 
879
-    if(is_array($payment) && isset($payment['payment_id'])) {
879
+    if (is_array($payment) && isset($payment['payment_id'])) {
880 880
       $this->payment_id = $payment['payment_id'];
881 881
       $this->payment_status = $payment['payment_status'];
882 882
       $this->payment_date = $payment['payment_date'];
@@ -918,11 +918,11 @@  discard block
 block discarded – undo
918 918
   protected function generate_description() {
919 919
     // TODO - системная локализация
920 920
     $this->description_generated = array(
921
-      PAYMENT_DESCRIPTION_100 => substr("{$this->payment_dark_matter_gained} ММ аккаунт [{$this->account->account_name}] ID {$this->account->account_id} на " . SN_ROOT_VIRTUAL, 0, 100),
922
-      PAYMENT_DESCRIPTION_250 => substr("Оплата {$this->payment_dark_matter_gained} ММ для аккаунта [{$this->payment_user_name}] ID {$this->payment_user_id} на сервере " . SN_ROOT_VIRTUAL, 0, 250),
923
-      PAYMENT_DESCRIPTION_MAX => ($this->payment_test ? "ТЕСТОВЫЙ ПЛАТЕЖ! " : '') .
924
-        "Платеж от аккаунта '{$this->payment_account_name}' ID {$this->payment_account_id} игрока '{$this->payment_user_name}' ID {$this->payment_user_id} на сервере " . SN_ROOT_VIRTUAL .
925
-        " сумма {$this->payment_amount} {$this->payment_currency} за {$this->payment_dark_matter_paid} ММ (начислено {$this->payment_dark_matter_gained} ММ)" .
921
+      PAYMENT_DESCRIPTION_100 => substr("{$this->payment_dark_matter_gained} ММ аккаунт [{$this->account->account_name}] ID {$this->account->account_id} на ".SN_ROOT_VIRTUAL, 0, 100),
922
+      PAYMENT_DESCRIPTION_250 => substr("Оплата {$this->payment_dark_matter_gained} ММ для аккаунта [{$this->payment_user_name}] ID {$this->payment_user_id} на сервере ".SN_ROOT_VIRTUAL, 0, 250),
923
+      PAYMENT_DESCRIPTION_MAX => ($this->payment_test ? "ТЕСТОВЫЙ ПЛАТЕЖ! " : '').
924
+        "Платеж от аккаунта '{$this->payment_account_name}' ID {$this->payment_account_id} игрока '{$this->payment_user_name}' ID {$this->payment_user_id} на сервере ".SN_ROOT_VIRTUAL.
925
+        " сумма {$this->payment_amount} {$this->payment_currency} за {$this->payment_dark_matter_paid} ММ (начислено {$this->payment_dark_matter_gained} ММ)".
926 926
         " через '{$this->manifest['name']}' сумма {$this->payment_external_amount} {$this->payment_external_currency}",
927 927
     );
928 928
   }
Please login to merge, or discard this patch.
includes/classes/template.php 4 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -103,6 +103,7 @@
 block discarded – undo
103 103
   /**
104 104
   * Set custom template location (able to use directory outside of phpBB)
105 105
   * @access public
106
+  * @param string $template_path
106 107
   */
107 108
   function set_custom_template($template_path, $template_name, $fallback_template_path = false)
108 109
   {
Please login to merge, or discard this patch.
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -25,11 +25,11 @@  discard block
 block discarded – undo
25 25
 class template
26 26
 {
27 27
   /** variable that holds all the data we'll be substituting into
28
-  * the compiled templates. Takes form:
29
-  * --> $this->_tpldata[block][iteration#][child][iteration#][child2][iteration#][variablename] == value
30
-  * if it's a root-level variable, it'll be like this:
31
-  * --> $this->_tpldata[.][0][varname] == value
32
-  */
28
+   * the compiled templates. Takes form:
29
+   * --> $this->_tpldata[block][iteration#][child][iteration#][child2][iteration#][variablename] == value
30
+   * if it's a root-level variable, it'll be like this:
31
+   * --> $this->_tpldata[.][0][varname] == value
32
+   */
33 33
   var $_tpldata = array('.' => array(0 => array()));
34 34
   var $_rootref;
35 35
 //  var $_block_counter = array();
@@ -60,9 +60,9 @@  discard block
 block discarded – undo
60 60
   var $parsed = false;
61 61
 
62 62
   /**
63
-  * Set template location
64
-  * @access public
65
-  */
63
+   * Set template location
64
+   * @access public
65
+   */
66 66
   function set_template()
67 67
   {
68 68
     global $phpbb_root_path, $user;
@@ -101,9 +101,9 @@  discard block
 block discarded – undo
101 101
   }
102 102
 
103 103
   /**
104
-  * Set custom template location (able to use directory outside of phpBB)
105
-  * @access public
106
-  */
104
+   * Set custom template location (able to use directory outside of phpBB)
105
+   * @access public
106
+   */
107 107
   function set_custom_template($template_path, $template_name, $fallback_template_path = false)
108 108
   {
109 109
     global $phpbb_root_path, $user;
@@ -142,10 +142,10 @@  discard block
 block discarded – undo
142 142
   }
143 143
 
144 144
   /**
145
-  * Sets the template filenames for handles. $filename_array
146
-  * should be a hash of handle => filename pairs.
147
-  * @access public
148
-  */
145
+   * Sets the template filenames for handles. $filename_array
146
+   * should be a hash of handle => filename pairs.
147
+   * @access public
148
+   */
149 149
   function set_filenames($filename_array)
150 150
   {
151 151
     if (!is_array($filename_array))
@@ -172,9 +172,9 @@  discard block
 block discarded – undo
172 172
   }
173 173
 
174 174
   /**
175
-  * Destroy template data set
176
-  * @access public
177
-  */
175
+   * Destroy template data set
176
+   * @access public
177
+   */
178 178
   function destroy()
179 179
   {
180 180
     $this->_tpldata = array('.' => array(0 => array()));
@@ -182,9 +182,9 @@  discard block
 block discarded – undo
182 182
   }
183 183
 
184 184
   /**
185
-  * Reset/empty complete block
186
-  * @access public
187
-  */
185
+   * Reset/empty complete block
186
+   * @access public
187
+   */
188 188
   function destroy_block_vars($blockname)
189 189
   {
190 190
     if (strpos($blockname, '.') !== false)
@@ -212,9 +212,9 @@  discard block
 block discarded – undo
212 212
   }
213 213
 
214 214
   /**
215
-  * Display handle
216
-  * @access public
217
-  */
215
+   * Display handle
216
+   * @access public
217
+   */
218 218
   function display($handle, $include_once = true)
219 219
   {
220 220
     global $user, $phpbb_hook, $lang, $config;
@@ -248,9 +248,9 @@  discard block
 block discarded – undo
248 248
   }
249 249
 
250 250
   /**
251
-  * Display the handle and assign the output to a template variable or return the compiled result.
252
-  * @access public
253
-  */
251
+   * Display the handle and assign the output to a template variable or return the compiled result.
252
+   * @access public
253
+   */
254 254
   function assign_display($handle, $template_var = '', $return_content = true, $include_once = false)
255 255
   {
256 256
     ob_start();
@@ -268,9 +268,9 @@  discard block
 block discarded – undo
268 268
   }
269 269
 
270 270
   /**
271
-  * Load a compiled template if possible, if not, recompile it
272
-  * @access private
273
-  */
271
+   * Load a compiled template if possible, if not, recompile it
272
+   * @access private
273
+   */
274 274
   function _tpl_load(&$handle)
275 275
   {
276 276
     global $user, $config;
@@ -453,9 +453,9 @@  discard block
 block discarded – undo
453 453
   }
454 454
 
455 455
   /**
456
-  * Assign key variable pairs from an array
457
-  * @access public
458
-  */
456
+   * Assign key variable pairs from an array
457
+   * @access public
458
+   */
459 459
   function assign_vars($vararray)
460 460
   {
461 461
     foreach ($vararray as $key => $val)
@@ -467,9 +467,9 @@  discard block
 block discarded – undo
467 467
   }
468 468
 
469 469
   /**
470
-  * Assign a single variable to a single key
471
-  * @access public
472
-  */
470
+   * Assign a single variable to a single key
471
+   * @access public
472
+   */
473 473
   function assign_var($varname, $varval)
474 474
   {
475 475
     $this->_rootref[$varname] = $varval;
@@ -478,9 +478,9 @@  discard block
 block discarded – undo
478 478
   }
479 479
 
480 480
   /**
481
-  * Assign key variable pairs from an array to a specified block
482
-  * @access public
483
-  */
481
+   * Assign key variable pairs from an array to a specified block
482
+   * @access public
483
+   */
484 484
   function assign_block_vars($blockname, $vararray)
485 485
   {
486 486
     if (strpos($blockname, '.') !== false)
@@ -545,33 +545,33 @@  discard block
 block discarded – undo
545 545
   }
546 546
 
547 547
   /**
548
-  * Change already assigned key variable pair (one-dimensional - single loop entry)
549
-  *
550
-  * An example of how to use this function:
551
-  * {@example alter_block_array.php}
552
-  *
553
-  * @param  string  $blockname  the blockname, for example 'loop'
554
-  * @param  array $vararray the var array to insert/add or merge
555
-  * @param  mixed $key    Key to search for
556
-  *
557
-  * array: KEY => VALUE [the key/value pair to search for within the loop to determine the correct position]
558
-  *
559
-  * int: Position [the position to change or insert at directly given]
560
-  *
561
-  * If key is false the position is set to 0
562
-  * If key is true the position is set to the last entry
563
-  *
564
-  * @param  string  $mode   Mode to execute (valid modes are 'insert' and 'change')
565
-  *
566
-  * If insert, the vararray is inserted at the given position (position counting from zero).
567
-  * If change, the current block gets merged with the vararray (resulting in new key/value pairs be added and existing keys be replaced by the new value).
568
-  *
569
-  * Since counting begins by zero, inserting at the last position will result in this array: array(vararray, last positioned array)
570
-  * and inserting at position 1 will result in this array: array(first positioned array, vararray, following vars)
571
-  *
572
-  * @return bool false on error, true on success
573
-  * @access public
574
-  */
548
+   * Change already assigned key variable pair (one-dimensional - single loop entry)
549
+   *
550
+   * An example of how to use this function:
551
+   * {@example alter_block_array.php}
552
+   *
553
+   * @param  string  $blockname  the blockname, for example 'loop'
554
+   * @param  array $vararray the var array to insert/add or merge
555
+   * @param  mixed $key    Key to search for
556
+   *
557
+   * array: KEY => VALUE [the key/value pair to search for within the loop to determine the correct position]
558
+   *
559
+   * int: Position [the position to change or insert at directly given]
560
+   *
561
+   * If key is false the position is set to 0
562
+   * If key is true the position is set to the last entry
563
+   *
564
+   * @param  string  $mode   Mode to execute (valid modes are 'insert' and 'change')
565
+   *
566
+   * If insert, the vararray is inserted at the given position (position counting from zero).
567
+   * If change, the current block gets merged with the vararray (resulting in new key/value pairs be added and existing keys be replaced by the new value).
568
+   *
569
+   * Since counting begins by zero, inserting at the last position will result in this array: array(vararray, last positioned array)
570
+   * and inserting at position 1 will result in this array: array(first positioned array, vararray, following vars)
571
+   *
572
+   * @return bool false on error, true on success
573
+   * @access public
574
+   */
575 575
   function alter_block_array($blockname, $vararray, $key = false, $mode = 'insert')
576 576
   {
577 577
     if (strpos($blockname, '.') !== false)
@@ -655,9 +655,9 @@  discard block
 block discarded – undo
655 655
   }
656 656
 
657 657
   /**
658
-  * Include a separate template
659
-  * @access private
660
-  */
658
+   * Include a separate template
659
+   * @access private
660
+   */
661 661
   function _tpl_include($filename, $include = true)
662 662
   {
663 663
     global $lang, $config;
@@ -686,9 +686,9 @@  discard block
 block discarded – undo
686 686
   }
687 687
 
688 688
   /**
689
-  * Include a php-file
690
-  * @access private
691
-  */
689
+   * Include a php-file
690
+   * @access private
691
+   */
692 692
   function _php_include($filename)
693 693
   {
694 694
     global $phpbb_root_path;
@@ -705,9 +705,9 @@  discard block
 block discarded – undo
705 705
   }
706 706
 
707 707
   /**
708
-  * Assign key variable pairs from an array with block support
709
-  * @access public
710
-  */
708
+   * Assign key variable pairs from an array with block support
709
+   * @access public
710
+   */
711 711
   function assign_recursive($values, $name = '')
712 712
   {
713 713
     if(isset($values['.']))
Please login to merge, or discard this patch.
Braces   +13 added lines, -26 removed lines patch added patch discarded remove patch
@@ -83,8 +83,7 @@  discard block
 block discarded – undo
83 83
       {
84 84
         $this->inherit_root = $phpbb_root_path . 'styles/' . $user->theme['template_inherit_path'] . '/template';
85 85
       }
86
-    }
87
-    else
86
+    } else
88 87
     {
89 88
       trigger_error('Template path could not be found: styles/' . $user->theme['template_path'] . '/template', E_USER_ERROR);
90 89
     }
@@ -120,8 +119,7 @@  discard block
 block discarded – undo
120 119
 
121 120
       $this->inherit_root = $fallback_template_path;
122 121
       $this->orig_tpl_inherits_id = true;
123
-    }
124
-    else
122
+    } else
125 123
     {
126 124
       $this->orig_tpl_inherits_id = false;
127 125
     }
@@ -195,8 +193,7 @@  discard block
 block discarded – undo
195 193
       }
196 194
 
197 195
       unset($str[$blocks[$blockcount]]);
198
-    }
199
-    else
196
+    } else
200 197
     {
201 198
       // Top-level block.
202 199
       unset($this->_tpldata[$blockname]);
@@ -232,8 +229,7 @@  discard block
 block discarded – undo
232 229
     if ($filename = $this->_tpl_load($handle))
233 230
     {
234 231
       ($include_once) ? include_once($filename) : include($filename);
235
-    }
236
-    else
232
+    } else
237 233
     {
238 234
       eval(' ?>' . $this->compiled_code[$handle] . '<?php ');
239 235
     }
@@ -287,8 +283,7 @@  discard block
 block discarded – undo
287 283
     if (!file_exists($filename) || @filesize($filename) === 0)
288 284
     {
289 285
       $recompile = true;
290
-    }
291
-    else if (classSupernova::$config->load_tplcompile)
286
+    } else if (classSupernova::$config->load_tplcompile)
292 287
     {
293 288
       // No way around it: we need to check inheritance here
294 289
       if ($user->theme['template_inherits_id'] && !file_exists($this->files[$handle]))
@@ -376,15 +371,13 @@  discard block
 block discarded – undo
376 371
               $this->files[$row['template_filename']] = $file;
377 372
               $this->files_inherit[$row['template_filename']] = $file;
378 373
               $this->files_template[$row['template_filename']] = $user->theme['template_inherits_id'];
379
-            }
380
-            else if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'])
374
+            } else if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'])
381 375
             {
382 376
               // Ok, we have a situation. There is a file in the subtemplate, but nothing in the DB. We have to fix that.
383 377
               $force_reload = true;
384 378
               $this->files_template[$row['template_filename']] = $user->theme['template_inherits_id'];
385 379
             }
386
-          }
387
-          else
380
+          } else
388 381
           {
389 382
             $this->files_template[$row['template_filename']] = $user->theme['template_id'];
390 383
           }
@@ -394,8 +387,7 @@  discard block
 block discarded – undo
394 387
             if ($row['template_filename'] == $this->filename[$handle])
395 388
             {
396 389
               $compile->_tpl_load_file($handle, true);
397
-            }
398
-            else
390
+            } else
399 391
             {
400 392
               $this->files[$row['template_filename']] = $file;
401 393
               $this->filename[$row['template_filename']] = $row['template_filename'];
@@ -410,8 +402,7 @@  discard block
 block discarded – undo
410 402
           {
411 403
             $this->compiled_code[$handle] = $compile->compile(trim($row['template_data']));
412 404
             $compile->compile_write($handle, $this->compiled_code[$handle]);
413
-          }
414
-          else
405
+          } else
415 406
           {
416 407
             // Only bother compiling if it doesn't already exist
417 408
             if (!file_exists($this->cachepath . str_replace('/', '.', $row['template_filename']) . DOT_PHP_EX))
@@ -422,8 +413,7 @@  discard block
 block discarded – undo
422 413
             }
423 414
           }
424 415
         }
425
-      }
426
-      else
416
+      } else
427 417
       {
428 418
         $file = $this->root . '/' . $row['template_filename'];
429 419
 
@@ -511,8 +501,7 @@  discard block
 block discarded – undo
511 501
       // We're adding a new iteration to this block with the given
512 502
       // variable assignments.
513 503
       $str[$blocks[$blockcount]][] = $vararray;
514
-    }
515
-    else
504
+    } else
516 505
     {
517 506
       // Top-level block.
518 507
       $s_row_count = (isset($this->_tpldata[$blockname])) ? sizeof($this->_tpldata[$blockname]) : 0;
@@ -612,8 +601,7 @@  discard block
 block discarded – undo
612 601
         $key = sizeof($this->_tpldata[$blockname]);
613 602
         unset($this->_tpldata[$blockname][($key - 1)]['S_LAST_ROW']);
614 603
         $vararray['S_LAST_ROW'] = true;
615
-      }
616
-      else if ($key === 0)
604
+      } else if ($key === 0)
617 605
       {
618 606
         unset($this->_tpldata[$blockname][0]['S_FIRST_ROW']);
619 607
         $vararray['S_FIRST_ROW'] = true;
@@ -711,8 +699,7 @@  discard block
 block discarded – undo
711 699
     if(!$name)
712 700
     {
713 701
       $this->assign_vars($values);
714
-    }
715
-    else
702
+    } else
716 703
     {
717 704
       $this->assign_block_vars($name, $values);
718 705
     }
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -61,10 +61,10 @@  discard block
 block discarded – undo
61 61
   {
62 62
     global $phpbb_root_path, $user;
63 63
 
64
-    if (file_exists($phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template'))
64
+    if (file_exists($phpbb_root_path.'styles/'.$user->theme['template_path'].'/template'))
65 65
     {
66
-      $this->root = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template';
67
-      $this->cachepath = $phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $user->theme['template_path']) . '_';
66
+      $this->root = $phpbb_root_path.'styles/'.$user->theme['template_path'].'/template';
67
+      $this->cachepath = $phpbb_root_path.'cache/tpl_'.str_replace('_', '-', $user->theme['template_path']).'_';
68 68
 
69 69
       if ($this->orig_tpl_storedb === null)
70 70
       {
@@ -81,12 +81,12 @@  discard block
 block discarded – undo
81 81
 
82 82
       if ($user->theme['template_inherits_id'])
83 83
       {
84
-        $this->inherit_root = $phpbb_root_path . 'styles/' . $user->theme['template_inherit_path'] . '/template';
84
+        $this->inherit_root = $phpbb_root_path.'styles/'.$user->theme['template_inherit_path'].'/template';
85 85
       }
86 86
     }
87 87
     else
88 88
     {
89
-      trigger_error('Template path could not be found: styles/' . $user->theme['template_path'] . '/template', E_USER_ERROR);
89
+      trigger_error('Template path could not be found: styles/'.$user->theme['template_path'].'/template', E_USER_ERROR);
90 90
     }
91 91
 
92 92
     $this->_rootref = &$this->_tpldata['.'][0];
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
     }
110 110
 
111 111
     $this->root = $template_path;
112
-    $this->cachepath = $phpbb_root_path . 'cache/ctpl_' . str_replace('_', '-', $template_name) . '_';
112
+    $this->cachepath = $phpbb_root_path.'cache/ctpl_'.str_replace('_', '-', $template_name).'_';
113 113
 
114 114
     if ($fallback_template_path !== false)
115 115
     {
@@ -154,11 +154,11 @@  discard block
 block discarded – undo
154 154
       }
155 155
 
156 156
       $this->filename[$handle] = $filename;
157
-      $this->files[$handle] = $this->root . '/' . $filename;
157
+      $this->files[$handle] = $this->root.'/'.$filename;
158 158
 
159 159
       if ($this->inherit_root)
160 160
       {
161
-        $this->files_inherit[$handle] = $this->inherit_root . '/' . $filename;
161
+        $this->files_inherit[$handle] = $this->inherit_root.'/'.$filename;
162 162
       }
163 163
     }
164 164
 
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
     }
236 236
     else
237 237
     {
238
-      eval(' ?>' . $this->compiled_code[$handle] . '<?php ');
238
+      eval(' ?>'.$this->compiled_code[$handle].'<?php ');
239 239
     }
240 240
 
241 241
     return true;
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
     //$user->theme['template_storedb'] = $this->orig_tpl_storedb;
281 281
     //$user->theme['template_inherits_id'] = $this->orig_tpl_inherits_id;
282 282
 
283
-    $filename = $this->cachepath . str_replace('/', '.', $this->filename[$handle]) . DOT_PHP_EX;
283
+    $filename = $this->cachepath.str_replace('/', '.', $this->filename[$handle]).DOT_PHP_EX;
284 284
     //$this->files_template[$handle] = (isset($user->theme['template_id'])) ? $user->theme['template_id'] : 0;
285 285
 
286 286
     $recompile = false;
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 
310 310
     if (!class_exists('template_compile'))
311 311
     {
312
-      include($phpbb_root_path . 'includes/functions_template' . DOT_PHP_EX);
312
+      include($phpbb_root_path.'includes/functions_template'.DOT_PHP_EX);
313 313
     }
314 314
 
315 315
     // Inheritance - we point to another template file for this one. Equality is also used for store_db
@@ -348,10 +348,10 @@  discard block
 block discarded – undo
348 348
       foreach ($ids as $id)
349 349
       {
350 350
         $sql = 'SELECT *
351
-        FROM ' . STYLES_TEMPLATE_DATA_TABLE . '
352
-        WHERE template_id = ' . $id . "
353
-          AND (template_filename = '" . $db->sql_escape($this->filename[$handle]) . "'
354
-            OR template_included " . $db->sql_like_expression($db->any_char . $this->filename[$handle] . ':' . $db->any_char) . ')';
351
+        FROM ' . STYLES_TEMPLATE_DATA_TABLE.'
352
+        WHERE template_id = ' . $id."
353
+          AND (template_filename = '" . $db->sql_escape($this->filename[$handle])."'
354
+            OR template_included " . $db->sql_like_expression($db->any_char.$this->filename[$handle].':'.$db->any_char).')';
355 355
 
356 356
         $result = $db->sql_query($sql);
357 357
         while ($row = $db->sql_fetchrow($result))
@@ -365,14 +365,14 @@  discard block
 block discarded – undo
365 365
       {
366 366
         foreach ($rows as $row)
367 367
         {
368
-          $file = $this->root . '/' . $row['template_filename'];
368
+          $file = $this->root.'/'.$row['template_filename'];
369 369
           $force_reload = false;
370 370
           if ($row['template_id'] != $user->theme['template_id'])
371 371
           {
372 372
             // make sure that we are not overlooking a file not in the db yet
373 373
             if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'] && !file_exists($file))
374 374
             {
375
-              $file = $this->inherit_root . '/' . $row['template_filename'];
375
+              $file = $this->inherit_root.'/'.$row['template_filename'];
376 376
               $this->files[$row['template_filename']] = $file;
377 377
               $this->files_inherit[$row['template_filename']] = $file;
378 378
               $this->files_template[$row['template_filename']] = $user->theme['template_inherits_id'];
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
           else
415 415
           {
416 416
             // Only bother compiling if it doesn't already exist
417
-            if (!file_exists($this->cachepath . str_replace('/', '.', $row['template_filename']) . DOT_PHP_EX))
417
+            if (!file_exists($this->cachepath.str_replace('/', '.', $row['template_filename']).DOT_PHP_EX))
418 418
             {
419 419
               $this->filename[$row['template_filename']] = $row['template_filename'];
420 420
               $compile->compile_write($row['template_filename'], $compile->compile(trim($row['template_data'])));
@@ -425,11 +425,11 @@  discard block
 block discarded – undo
425 425
       }
426 426
       else
427 427
       {
428
-        $file = $this->root . '/' . $row['template_filename'];
428
+        $file = $this->root.'/'.$row['template_filename'];
429 429
 
430 430
         if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'] && !file_exists($file))
431 431
         {
432
-          $file = $this->inherit_root . '/' . $row['template_filename'];
432
+          $file = $this->inherit_root.'/'.$row['template_filename'];
433 433
           $this->files[$row['template_filename']] = $file;
434 434
           $this->files_inherit[$row['template_filename']] = $file;
435 435
           $this->files_template[$row['template_filename']] = $user->theme['template_inherits_id'];
@@ -622,7 +622,7 @@  discard block
 block discarded – undo
622 622
       // Re-position template blocks
623 623
       for ($i = sizeof($this->_tpldata[$blockname]); $i > $key; $i--)
624 624
       {
625
-        $this->_tpldata[$blockname][$i] = $this->_tpldata[$blockname][$i-1];
625
+        $this->_tpldata[$blockname][$i] = $this->_tpldata[$blockname][$i - 1];
626 626
         $this->_tpldata[$blockname][$i]['S_ROW_COUNT'] = $i;
627 627
       }
628 628
 
@@ -656,10 +656,10 @@  discard block
 block discarded – undo
656 656
   {
657 657
     $handle = $filename;
658 658
     $this->filename[$handle] = $filename;
659
-    $this->files[$handle] = $this->root . '/' . $filename;
659
+    $this->files[$handle] = $this->root.'/'.$filename;
660 660
     if ($this->inherit_root)
661 661
     {
662
-      $this->files_inherit[$handle] = $this->inherit_root . '/' . $filename;
662
+      $this->files_inherit[$handle] = $this->inherit_root.'/'.$filename;
663 663
     }
664 664
 
665 665
     $filename = $this->_tpl_load($handle);
@@ -673,7 +673,7 @@  discard block
 block discarded – undo
673 673
         include($filename);
674 674
         return;
675 675
       }
676
-      eval(' ?>' . $this->compiled_code[$handle] . '<?php ');
676
+      eval(' ?>'.$this->compiled_code[$handle].'<?php ');
677 677
     }
678 678
   }
679 679
 
@@ -685,12 +685,12 @@  discard block
 block discarded – undo
685 685
   {
686 686
     global $phpbb_root_path;
687 687
 
688
-    $file = $phpbb_root_path . $filename;
688
+    $file = $phpbb_root_path.$filename;
689 689
 
690 690
     if (!file_exists($file))
691 691
     {
692 692
       // trigger_error cannot be used here, as the output already started
693
-      echo 'template->_php_include(): File ' . htmlspecialchars($file) . ' does not exist or is empty';
693
+      echo 'template->_php_include(): File '.htmlspecialchars($file).' does not exist or is empty';
694 694
       return;
695 695
     }
696 696
     include($file);
@@ -702,13 +702,13 @@  discard block
 block discarded – undo
702 702
   */
703 703
   function assign_recursive($values, $name = '')
704 704
   {
705
-    if(isset($values['.']))
705
+    if (isset($values['.']))
706 706
     {
707 707
       $values_extra = $values['.'];
708 708
       unset($values['.']);
709 709
     }
710 710
 
711
-    if(!$name)
711
+    if (!$name)
712 712
     {
713 713
       $this->assign_vars($values);
714 714
     }
@@ -717,12 +717,12 @@  discard block
 block discarded – undo
717 717
       $this->assign_block_vars($name, $values);
718 718
     }
719 719
 
720
-    if(isset($values_extra))
720
+    if (isset($values_extra))
721 721
     {
722
-      foreach($values_extra as $sub_array_name => $sub_array)
722
+      foreach ($values_extra as $sub_array_name => $sub_array)
723 723
       {
724
-        $new_name = $name . ($name ? '.' : '') . $sub_array_name;
725
-        foreach($sub_array as $sub_element)
724
+        $new_name = $name.($name ? '.' : '').$sub_array_name;
725
+        foreach ($sub_array as $sub_element)
726 726
         {
727 727
           $this->assign_recursive($sub_element, $new_name);
728 728
         }
Please login to merge, or discard this patch.
includes/db.php 2 patches
Doc Comments   +8 added lines, -5 removed lines patch added patch discarded remove patch
@@ -11,6 +11,9 @@  discard block
 block discarded – undo
11 11
 
12 12
 require_once('db/db_queries.php');
13 13
 
14
+/**
15
+ * @param string $tablename
16
+ */
14 17
 function db_change_units_perform($query, $tablename, $object_id) {
15 18
   $query = implode(',', $query);
16 19
   if($query && $object_id) {
@@ -63,6 +66,9 @@  discard block
 block discarded – undo
63 66
   db_change_units_perform($query[LOC_USER], 'users', $user['id']);
64 67
   db_change_units_perform($query[LOC_PLANET], 'planets', $planet['id']);
65 68
 }
69
+/**
70
+ * @param string $table
71
+ */
66 72
 function sn_db_perform($table, $values, $type = 'insert', $options = false) {
67 73
   $mass_perform = false;
68 74
 
@@ -171,11 +177,8 @@  discard block
 block discarded – undo
171 177
 /**
172 178
  * Функция проверяет статус транзакции
173 179
  *
174
- * @param null|true|false $status Должна ли быть запущена транзакция в момент проверки
175
- *   <p>null - транзакция НЕ должна быть запущена</p>
176
- *   <p>true - транзакция должна быть запущена - для совместимости с $for_update</p>
177
- *   <p>false - всё равно - для совместимости с $for_update</p>
178
- * @return bool Текущий статус транзакции
180
+ * @param boolean $transaction_should_be_started
181
+ * @return null|boolean Текущий статус транзакции
179 182
  */
180 183
 function sn_db_transaction_check($transaction_should_be_started = null) {
181 184
   return classSupernova::db_transaction_check($transaction_should_be_started);
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 
12 12
 function db_change_units_perform($query, $tablename, $object_id) {
13 13
   $query = implode(',', $query);
14
-  if($query && $object_id) {
14
+  if ($query && $object_id) {
15 15
     return classSupernova::db_upd_record_by_id($tablename == 'users' ? LOC_USER : LOC_PLANET, $object_id, $query);
16 16
     // return doquery("UPDATE {{{$tablename}}} SET {$query} WHERE `id` = '{$object_id}' LIMIT 1;");
17 17
   }
@@ -28,15 +28,15 @@  discard block
 block discarded – undo
28 28
 
29 29
   $group = sn_get_groups('resources_loot');
30 30
 
31
-  foreach($unit_list as $unit_id => $unit_amount) {
32
-    if(!in_array($unit_id, $group)) {
31
+  foreach ($unit_list as $unit_id => $unit_amount) {
32
+    if (!in_array($unit_id, $group)) {
33 33
       // TODO - remove later
34 34
       print('<h1>СООБЩИТЕ ЭТО АДМИНУ: db_change_units() вызван для не-ресурсов!</h1>');
35 35
       pdump(debug_backtrace());
36 36
       die('db_change_units() вызван для не-ресурсов!');
37 37
     }
38 38
 
39
-    if(!$unit_amount) {
39
+    if (!$unit_amount) {
40 40
       continue;
41 41
     }
42 42
 
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
     $unit_location = sys_get_unit_location($user, $planet, $unit_id);
46 46
 
47 47
     // Changing value in object
48
-    switch($unit_location) {
48
+    switch ($unit_location) {
49 49
       case LOC_USER:
50 50
         $user[$unit_db_name] += $unit_amount;
51 51
         break;
@@ -67,30 +67,30 @@  discard block
 block discarded – undo
67 67
   $field_set = '';
68 68
   $value_set = '';
69 69
 
70
-  switch($type) {
70
+  switch ($type) {
71 71
     case 'delete':
72 72
       $query = 'DELETE FROM';
73 73
       break;
74 74
 
75 75
     case 'insert':
76 76
       $query = 'INSERT INTO';
77
-      if(isset($options['__multi'])) {
77
+      if (isset($options['__multi'])) {
78 78
         // Here we generate mass-insert set
79 79
         break;
80 80
       }
81 81
     case 'update':
82
-      if(!$query) {
82
+      if (!$query) {
83 83
         $query = 'UPDATE';
84 84
       }
85 85
 
86
-      foreach($values as $field => &$value) {
86
+      foreach ($values as $field => &$value) {
87 87
         $value_type = gettype($value);
88 88
         if ($value_type == 'string') {
89
-          $value = "'" . db_escape($value) . "'";
89
+          $value = "'".db_escape($value)."'";
90 90
         }
91 91
         $value = "`{$field}` = {$value}";
92 92
       }
93
-      $field_set = 'SET ' . implode(', ', $values);
93
+      $field_set = 'SET '.implode(', ', $values);
94 94
       break;
95 95
 
96 96
   };
@@ -111,12 +111,12 @@  discard block
 block discarded – undo
111 111
   $field_set['__IS_SAFE'] = true;
112 112
 }
113 113
 function sn_db_field_set_make_safe($field_set, $serialize = false) {
114
-  if(!is_array($field_set)) {
114
+  if (!is_array($field_set)) {
115 115
     die('$field_set is not an array!');
116 116
   }
117 117
 
118 118
   $result = array();
119
-  foreach($field_set as $field => $value) {
119
+  foreach ($field_set as $field => $value) {
120 120
     $field = db_escape(trim($field));
121 121
     switch (true) {
122 122
       case is_int($value):
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
         $serialize ? $value = serialize($value) : die('$value is object or array with no $serialize');
133 133
 
134 134
       case is_string($value):
135
-        $value = '"' . db_escape($value) . '"';
135
+        $value = '"'.db_escape($value).'"';
136 136
         break;
137 137
 
138 138
       case is_null($value):
Please login to merge, or discard this patch.
includes/functions/eco_get_build_data.php 1 patch
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -10,6 +10,7 @@  discard block
 block discarded – undo
10 10
  *
11 11
  * 1.0 - copyright (c) 2010 by Gorlum for http://supernova.ws
12 12
  * @version 1.0
13
+ * @param integer $lab_require
13 14
  */
14 15
 function eco_get_lab_max_effective_level(&$user, $lab_require)
15 16
 {
@@ -193,6 +194,9 @@  discard block
 block discarded – undo
193 194
   return $result;
194 195
 }
195 196
 
197
+/**
198
+ * @param integer[] $unit_list
199
+ */
196 200
 function eco_is_builds_in_que($planet_que, $unit_list)
197 201
 {
198 202
   $eco_is_builds_in_que = false;
Please login to merge, or discard this patch.
includes/functions/eco_queue.php 2 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -55,6 +55,9 @@  discard block
 block discarded – undo
55 55
 }
56 56
 
57 57
 
58
+/**
59
+ * @param integer $build_mode
60
+ */
58 61
 function que_build($user, $planet, $build_mode = BUILD_CREATE, $redirect = true) {
59 62
   global $lang, $config;
60 63
 
@@ -378,6 +381,9 @@  discard block
 block discarded – undo
378 381
   return classSupernova::db_que_list_by_type_location($user_id, $planet_id, $que_type, $for_update);
379 382
 }
380 383
 
384
+/**
385
+ * @param integer $unit_id
386
+ */
381 387
 function que_add_unit($unit_id, $user = array(), $planet = array(), $build_data, $unit_level = 0, $unit_amount = 1, $build_mode = BUILD_CREATE) {
382 388
   // TODO Унифицировать проверки
383 389
 
Please login to merge, or discard this patch.
Spacing   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -2,8 +2,8 @@  discard block
 block discarded – undo
2 2
 
3 3
 function que_get_unit_que($unit_id) {
4 4
   $que_type = false;
5
-  foreach(sn_get_groups('ques') as $que_id => $que_data) {
6
-    if(in_array($unit_id, $que_data['unit_list'])) {
5
+  foreach (sn_get_groups('ques') as $que_id => $que_data) {
6
+    if (in_array($unit_id, $que_data['unit_list'])) {
7 7
       $que_type = $que_id;
8 8
       break;
9 9
     }
@@ -14,14 +14,14 @@  discard block
 block discarded – undo
14 14
 
15 15
 
16 16
 function que_get_max_que_length($user, $planet, $que_id, $que_data = null) {
17
-  if(empty($que_data)) {
17
+  if (empty($que_data)) {
18 18
     $que_data = sn_get_groups('ques');
19 19
     $que_data = $que_data[$que_id];
20 20
   }
21 21
 
22 22
 
23 23
   $que_length = 1;
24
-  switch($que_id) {
24
+  switch ($que_id) {
25 25
     case QUE_RESEARCH:
26 26
       $que_length = classSupernova::$config->server_que_length_research + mrc_get_level($user, null, UNIT_PREMIUM); // TODO - вынести в модуль
27 27
     break;
@@ -35,8 +35,8 @@  discard block
 block discarded – undo
35 35
 
36 36
 function eco_que_str2arr($que_str) {
37 37
   $que_arr = explode(';', $que_str);
38
-  foreach($que_arr as $que_index => &$que_item) {
39
-    if($que_item) {
38
+  foreach ($que_arr as $que_index => &$que_item) {
39
+    if ($que_item) {
40 40
       $que_item = explode(',', $que_item);
41 41
     } else {
42 42
       unset($que_arr[$que_index]);
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 }
48 48
 
49 49
 function eco_que_arr2str($que_arr) {
50
-  foreach($que_arr as &$que_item) {
50
+  foreach ($que_arr as &$que_item) {
51 51
     $que_item = implode(',', $que_item);
52 52
   }
53 53
 
@@ -59,14 +59,14 @@  discard block
 block discarded – undo
59 59
   $classLocale = classLocale::$lang;
60 60
 
61 61
   $is_autoconvert = false;
62
-  if($build_mode == BUILD_AUTOCONVERT || sys_get_param_int('auto_convert')) {
62
+  if ($build_mode == BUILD_AUTOCONVERT || sys_get_param_int('auto_convert')) {
63 63
     $build_mode = BUILD_CREATE;
64 64
     $is_autoconvert = true;
65 65
   }
66 66
 
67 67
   $unit_amount_qued = 0;
68 68
   try {
69
-    if(!$user['id']) {
69
+    if (!$user['id']) {
70 70
       throw new exception('{Нет идентификатора пользователя - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION
71 71
     }
72 72
 
@@ -77,16 +77,16 @@  discard block
 block discarded – undo
77 77
       foreach($unit_list as $unit_id => $unit_amount) if($unit_amount) break;
78 78
     }
79 79
     */
80
-    if(!$unit_id) {
80
+    if (!$unit_id) {
81 81
       throw new exception('{Нет идентификатора юнита - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION
82 82
     }
83 83
 
84 84
     $que_id = que_get_unit_que($unit_id);
85
-    if(!$que_id) {
85
+    if (!$que_id) {
86 86
       throw new exception('{Неправильный тип очереди - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION
87 87
     }
88 88
 
89
-    if($build_mode == BUILD_DESTROY && $que_id != QUE_STRUCTURES) {
89
+    if ($build_mode == BUILD_DESTROY && $que_id != QUE_STRUCTURES) {
90 90
       throw new exception('{Уничтожать можно только здания на планете}', ERR_ERROR); // TODO EXCEPTION
91 91
     }
92 92
 
@@ -94,12 +94,12 @@  discard block
 block discarded – undo
94 94
     $que_data = $que_data[$que_id];
95 95
 
96 96
     // TODO Переделать под подочереди
97
-    if($que_id == QUE_STRUCTURES) {
97
+    if ($que_id == QUE_STRUCTURES) {
98 98
       $sn_groups_build_allow = sn_get_groups('build_allow');
99 99
       $que_data['unit_list'] = $sn_groups_build_allow[$planet['planet_type']];
100 100
 
101
-      if(!isset($que_data['unit_list'][$unit_id])) {
102
-        throw new exception('{Это здание нельзя строить на ' . ($planet['planet_type'] == PT_PLANET ? 'планете' : 'луне'), ERR_ERROR); // TODO EXCEPTION
101
+      if (!isset($que_data['unit_list'][$unit_id])) {
102
+        throw new exception('{Это здание нельзя строить на '.($planet['planet_type'] == PT_PLANET ? 'планете' : 'луне'), ERR_ERROR); // TODO EXCEPTION
103 103
       }
104 104
     }
105 105
     /*
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
     // Это нужно, что бы заблокировать пользователя и работу с очередями
120 120
     $user = DBStaticUser::db_user_by_id($user['id']);
121 121
     // Это нужно, что бы заблокировать планету от списания ресурсов
122
-    if(isset($planet['id']) && $planet['id']) {
122
+    if (isset($planet['id']) && $planet['id']) {
123 123
       $planet = DBStaticPlanet::db_planet_by_id($planet['id'], true);
124 124
     } else {
125 125
       $planet['id'] = 0;
@@ -131,12 +131,12 @@  discard block
 block discarded – undo
131 131
     $in_que = &$que['in_que'][$que_id][$user['id']][$planet_id];
132 132
     $que_max_length = que_get_max_que_length($user, $planet, $que_id, $que_data);
133 133
     // TODO Добавить вызовы функций проверок текущей и максимальной длин очередей
134
-    if(count($in_que) >= $que_max_length) {
134
+    if (count($in_que) >= $que_max_length) {
135 135
       throw new exception('{Все слоты очереди заняты}', ERR_ERROR); // TODO EXCEPTION
136 136
     }
137 137
 
138 138
     // TODO Отдельно посмотреть на уничтожение зданий - что бы можно было уничтожать их без планов
139
-    switch(eco_can_build_unit($user, $planet, $unit_id)) {
139
+    switch (eco_can_build_unit($user, $planet, $unit_id)) {
140 140
       case BUILD_ALLOWED:
141 141
       break;
142 142
       case BUILD_UNIT_BUSY:
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
       break; // TODO EXCEPTION eco_bld_msg_err_laboratory_upgrading
145 145
       // case BUILD_REQUIRE_NOT_MEET:
146 146
       default:
147
-        if($build_mode == BUILD_CREATE) {
147
+        if ($build_mode == BUILD_CREATE) {
148 148
           throw new exception('{Требования не удовлетворены}', ERR_ERROR);
149 149
         }
150 150
       break; // TODO EXCEPTION eco_bld_msg_err_requirements_not_meet
@@ -154,14 +154,14 @@  discard block
 block discarded – undo
154 154
     $unit_amount_qued = $unit_amount;
155 155
     $units_qued = isset($in_que[$unit_id]) ? $in_que[$unit_id] : 0;
156 156
     $unit_level = mrc_get_level($user, $planet, $unit_id, true, true) + $units_qued;
157
-    if($unit_max = get_unit_param($unit_id, P_MAX_STACK)) {
158
-      if($unit_level >= $unit_max) {
157
+    if ($unit_max = get_unit_param($unit_id, P_MAX_STACK)) {
158
+      if ($unit_level >= $unit_max) {
159 159
         throw new exception('{Максимальное количество юнитов данного типа уже достигнуто или будет достигнуто по окончанию очереди}', ERR_ERROR); // TODO EXCEPTION
160 160
       }
161 161
       $unit_amount = max(0, min($unit_amount, $unit_max - $unit_level));
162 162
     }
163 163
 
164
-    if($unit_amount < 1) {
164
+    if ($unit_amount < 1) {
165 165
       throw new exception('{Неправильное количество юнитов - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION
166 166
     }
167 167
 
@@ -170,21 +170,21 @@  discard block
 block discarded – undo
170 170
     //  {
171 171
     //    die('Unit busy'); // TODO EXCEPTION
172 172
     //  }
173
-    if(get_unit_param($unit_id, P_STACKABLE)) {
173
+    if (get_unit_param($unit_id, P_STACKABLE)) {
174 174
       // TODO Поле 'max_Lot_size' для ограничения размера стэка в очереди - то ли в юниты, то ли в очередь
175
-      if(in_array($unit_id, $group_missile = sn_get_groups(GROUP_STR_MISSILES))) {
175
+      if (in_array($unit_id, $group_missile = sn_get_groups(GROUP_STR_MISSILES))) {
176 176
         // TODO Поле 'container' - указывает на родительску структуру, в которой хранится данный юнит и по вместительности которой нужно применять размер юнита
177 177
         $used_silo = 0;
178
-        foreach($group_missile as $missile_id) {
178
+        foreach ($group_missile as $missile_id) {
179 179
           $missile_qued = isset($in_que[$missile_id]) ? $in_que[$missile_id] : 0;
180 180
           $used_silo += (mrc_get_level($user, $planet, $missile_id, true, true) + $missile_qued) * get_unit_param($missile_id, P_UNIT_SIZE);
181 181
         }
182 182
         $free_silo = mrc_get_level($user, $planet, STRUC_SILO) * get_unit_param(STRUC_SILO, P_CAPACITY) - $used_silo;
183
-        if($free_silo <= 0) {
183
+        if ($free_silo <= 0) {
184 184
           throw new exception('{Ракетная шахта уже заполнена или будет заполнена по окончанию очереди}', ERR_ERROR); // TODO EXCEPTION
185 185
         }
186 186
         $unit_size = get_unit_param($unit_id, P_UNIT_SIZE);
187
-        if($free_silo < $unit_size) {
187
+        if ($free_silo < $unit_size) {
188 188
           throw new exception("{В ракетной шахте нет места для {$classLocale['tech'][$unit_id]}}", ERR_ERROR); // TODO EXCEPTION
189 189
         }
190 190
         $unit_amount = max(0, min($unit_amount, floor($free_silo / $unit_size)));
@@ -192,10 +192,10 @@  discard block
 block discarded – undo
192 192
       $unit_level = $new_unit_level = 0;
193 193
     } else {
194 194
       $unit_amount = 1;
195
-      if($que_id == QUE_STRUCTURES) {
195
+      if ($que_id == QUE_STRUCTURES) {
196 196
         // if($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $que['sectors'][$planet['id']] <= 0)
197 197
         $sectors_qued = is_array($in_que) ? array_sum($in_que) : 0;
198
-        if($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $sectors_qued <= 0) {
198
+        if ($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $sectors_qued <= 0) {
199 199
           throw new exception('{Не хватает секторов на планете}', ERR_ERROR); // TODO EXCEPTION
200 200
         }
201 201
         // И что это я такое написал? Зачем?
@@ -212,10 +212,10 @@  discard block
 block discarded – undo
212 212
 
213 213
     $exchange = array();
214 214
     $market_get_autoconvert_cost = market_get_autoconvert_cost();
215
-    if($is_autoconvert && $build_data[BUILD_AUTOCONVERT]) {
215
+    if ($is_autoconvert && $build_data[BUILD_AUTOCONVERT]) {
216 216
       $dark_matter = mrc_get_level($user, null, RES_DARK_MATTER);
217
-      if(mrc_get_level($user, null, RES_DARK_MATTER) < $market_get_autoconvert_cost) {
218
-        throw new exception("{Нет хватает " . ($market_get_autoconvert_cost - $dark_matter) . "ТМ на постройки с автоконвертацией ресурсов}", ERR_ERROR); // TODO EXCEPTION
217
+      if (mrc_get_level($user, null, RES_DARK_MATTER) < $market_get_autoconvert_cost) {
218
+        throw new exception("{Нет хватает ".($market_get_autoconvert_cost - $dark_matter)."ТМ на постройки с автоконвертацией ресурсов}", ERR_ERROR); // TODO EXCEPTION
219 219
       }
220 220
 
221 221
       !get_unit_param($unit_id, P_STACKABLE) ? $unit_amount = 1 : false;
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
       $resource_exchange_rates = array();
225 225
       $resource_diff = array();
226 226
       $all_positive = true;
227
-      foreach($resources_loot as $resource_id) {
227
+      foreach ($resources_loot as $resource_id) {
228 228
         $resource_db_name = pname_resource_name($resource_id);
229 229
         $resource_got[$resource_id] = floor(mrc_get_level($user, $planet, $resource_id));
230 230
         $resource_exchange_rates[$resource_id] = classSupernova::$config->__get("rpg_exchange_{$resource_db_name}");
@@ -232,15 +232,15 @@  discard block
 block discarded – undo
232 232
         $all_positive = $all_positive && ($resource_diff[$resource_id] > 0);
233 233
       }
234 234
       // Нужна автоконвертация
235
-      if($all_positive) {
235
+      if ($all_positive) {
236 236
         $is_autoconvert = false;
237 237
       } else {
238
-        foreach($resource_diff as $resource_diff_id => &$resource_diff_amount) {
239
-          if($resource_diff_amount >= 0) {
238
+        foreach ($resource_diff as $resource_diff_id => &$resource_diff_amount) {
239
+          if ($resource_diff_amount >= 0) {
240 240
             continue;
241 241
           }
242
-          foreach($resource_diff as $resource_got_id => &$resource_got_amount) {
243
-            if($resource_got_amount <= 0) {
242
+          foreach ($resource_diff as $resource_got_id => &$resource_got_amount) {
243
+            if ($resource_got_amount <= 0) {
244 244
               continue;
245 245
             }
246 246
             $current_exchange = $resource_exchange_rates[$resource_got_id] / $resource_exchange_rates[$resource_diff_id];
@@ -256,14 +256,14 @@  discard block
 block discarded – undo
256 256
         }
257 257
 
258 258
         $is_autoconvert_ok = true;
259
-        foreach($resource_diff as $resource_diff_amount2) {
260
-          if($resource_diff_amount2 < 0) {
259
+        foreach ($resource_diff as $resource_diff_amount2) {
260
+          if ($resource_diff_amount2 < 0) {
261 261
             $is_autoconvert_ok = false;
262 262
             break;
263 263
           }
264 264
         }
265 265
 
266
-        if($is_autoconvert_ok) {
266
+        if ($is_autoconvert_ok) {
267 267
           $build_data['RESULT'][$build_mode] = BUILD_ALLOWED;
268 268
           $build_data['CAN'][$build_mode] = $unit_amount;
269 269
         } else {
@@ -272,19 +272,19 @@  discard block
 block discarded – undo
272 272
       }
273 273
     }
274 274
     $unit_amount = min($build_data['CAN'][$build_mode], $unit_amount);
275
-    if($unit_amount <= 0) {
275
+    if ($unit_amount <= 0) {
276 276
       throw new exception('{Не хватает ресурсов}', ERR_ERROR); // TODO EXCEPTION
277 277
     }
278 278
 
279
-    if($new_unit_level < 0) {
279
+    if ($new_unit_level < 0) {
280 280
       throw new exception('{Нельзя уничтожить больше юнитов, чем есть}', ERR_ERROR); // TODO EXCEPTION
281 281
     }
282 282
 
283
-    if($build_data['RESULT'][$build_mode] != BUILD_ALLOWED) {
283
+    if ($build_data['RESULT'][$build_mode] != BUILD_ALLOWED) {
284 284
       throw new exception('{Строительство блокировано}', ERR_ERROR); // TODO EXCEPTION
285 285
     }
286 286
 
287
-    if($is_autoconvert) {
287
+    if ($is_autoconvert) {
288 288
       ksort($exchange);
289 289
       ksort($resource_got);
290 290
       db_change_units($user, $planet, array(
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
     }
300 300
 
301 301
     $unit_amount_qued = 0;
302
-    while($unit_amount > 0 && count($que['ques'][$que_id][$user['id']][$planet_id]) < $que_max_length) {
302
+    while ($unit_amount > 0 && count($que['ques'][$que_id][$user['id']][$planet_id]) < $que_max_length) {
303 303
       $place = min($unit_amount, MAX_FLEET_OR_DEFS_PER_ROW);
304 304
       que_add_unit($unit_id, $user, $planet, $build_data, $new_unit_level, $place, $build_mode);
305 305
       $unit_amount -= $place;
@@ -309,8 +309,8 @@  discard block
 block discarded – undo
309 309
 
310 310
     sn_db_transaction_commit();
311 311
 
312
-    if($redirect) {
313
-      sys_redirect("{$_SERVER['PHP_SELF']}?mode=" . sys_get_param_str('mode') . "&ally_id=" . sys_get_param_id('ally_id'));
312
+    if ($redirect) {
313
+      sys_redirect("{$_SERVER['PHP_SELF']}?mode=".sys_get_param_str('mode')."&ally_id=".sys_get_param_id('ally_id'));
314 314
       die();
315 315
     }
316 316
 
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
       'STATUS'  => ERR_NONE,
319 319
       'MESSAGE' => '{Строительство начато}',
320 320
     );
321
-  } catch(exception $e) {
321
+  } catch (exception $e) {
322 322
     sn_db_transaction_rollback();
323 323
     $operation_result = array(
324 324
       'STATUS'  => in_array($e->getCode(), array(ERR_NONE, ERR_WARNING, ERR_ERROR)) ? $e->getCode() : ERR_ERROR,
@@ -326,8 +326,8 @@  discard block
 block discarded – undo
326 326
     );
327 327
   }
328 328
 
329
-  if(!empty($operation_result['MESSAGE'])) {
330
-    $operation_result['MESSAGE'] .= ' ' . ($unit_amount_qued ? $unit_amount_qued : $unit_amount) . 'x[' . classLocale::$lang['tech'][$unit_id] . ']';
329
+  if (!empty($operation_result['MESSAGE'])) {
330
+    $operation_result['MESSAGE'] .= ' '.($unit_amount_qued ? $unit_amount_qued : $unit_amount).'x['.classLocale::$lang['tech'][$unit_id].']';
331 331
   }
332 332
 
333 333
   return $operation_result;
@@ -337,11 +337,11 @@  discard block
 block discarded – undo
337 337
 function que_recalculate($old_que) {
338 338
   $new_que = array();
339 339
 
340
-  if(!is_array($old_que['items'])) {
340
+  if (!is_array($old_que['items'])) {
341 341
     return $new_que;
342 342
   }
343
-  foreach($old_que['items'] as $row) {
344
-    if(!isset($row) || !$row || $row['que_unit_amount'] <= 0) {
343
+  foreach ($old_que['items'] as $row) {
344
+    if (!isset($row) || !$row || $row['que_unit_amount'] <= 0) {
345 345
       continue;
346 346
     }
347 347
 
@@ -352,9 +352,9 @@  discard block
 block discarded – undo
352 352
 
353 353
     $last_id = count($new_que['items']) - 1;
354 354
 
355
-    if($row['que_planet_id']) {
355
+    if ($row['que_planet_id']) {
356 356
       $new_que['planets'][$row['que_planet_id']][$row['que_type']][] = &$new_que['items'][$last_id];
357
-    } elseif($row['que_type'] == QUE_RESEARCH) {
357
+    } elseif ($row['que_type'] == QUE_RESEARCH) {
358 358
       $new_que['players'][$row['que_player_id']][$row['que_type']][] = &$new_que['items'][$last_id];
359 359
     }
360 360
     $new_que['ques'][$row['que_type']][$row['que_player_id']][intval($row['que_planet_id'])][] = &$new_que['items'][$last_id];
@@ -389,9 +389,9 @@  discard block
 block discarded – undo
389 389
   $que_type = que_get_unit_que($unit_id);
390 390
   $planet_id_origin = $planet['id'] ? $planet['id'] : 'NULL';
391 391
   $planet_id = $que_type == QUE_RESEARCH ? 'NULL' : $planet_id_origin;
392
-  if(is_numeric($planet_id)) {
392
+  if (is_numeric($planet_id)) {
393 393
     DBStaticPlanet::db_planet_set_by_id($planet_id, "`que_processed` = UNIX_TIMESTAMP(NOW())");
394
-  } elseif(is_numeric($user['id'])) {
394
+  } elseif (is_numeric($user['id'])) {
395 395
     DBStaticUser::db_user_set_by_id($user['id'], '`que_processed` = UNIX_TIMESTAMP(NOW())');
396 396
   }
397 397
 
@@ -421,17 +421,17 @@  discard block
 block discarded – undo
421 421
   $planet['id'] = $planet['id'] && $que_type !== QUE_RESEARCH ? $planet['id'] : 0;
422 422
   $global_que = que_get($user['id'], $planet['id'], $que_type, true);
423 423
 
424
-  if(!empty($global_que['ques'][$que_type][$user['id']][$planet['id']])) {
424
+  if (!empty($global_que['ques'][$que_type][$user['id']][$planet['id']])) {
425 425
     $que = array_reverse($global_que['ques'][$que_type][$user['id']][$planet['id']]);
426 426
 
427
-    foreach($que as $que_item) {
427
+    foreach ($que as $que_item) {
428 428
       DBStaticQue::db_que_delete_by_id($que_item['que_id']);
429 429
 
430
-      if($que_item['que_planet_id_origin']) {
430
+      if ($que_item['que_planet_id_origin']) {
431 431
         $planet['id'] = $que_item['que_planet_id_origin'];
432 432
       }
433 433
 
434
-      if(!isset($planets_locked[$planet['id']])) {
434
+      if (!isset($planets_locked[$planet['id']])) {
435 435
         $planets_locked[$planet['id']] = $planet['id'] ? DBStaticPlanet::db_planet_by_id($planet['id'], true) : $planet;
436 436
       }
437 437
 
@@ -443,14 +443,14 @@  discard block
 block discarded – undo
443 443
         RES_DEUTERIUM => $build_data[RES_DEUTERIUM] * $que_item['que_unit_amount'],
444 444
       ));
445 445
 
446
-      if(!$clear) {
446
+      if (!$clear) {
447 447
         break;
448 448
       }
449 449
     }
450 450
 
451
-    if(is_numeric($planet['id'])) {
451
+    if (is_numeric($planet['id'])) {
452 452
       DBStaticPlanet::db_planet_set_by_id($planet['id'], "`que_processed` = UNIX_TIMESTAMP(NOW())");
453
-    } elseif(is_numeric($user['id'])) {
453
+    } elseif (is_numeric($user['id'])) {
454 454
       DBStaticUser::db_user_set_by_id($user['id'], '`que_processed` = UNIX_TIMESTAMP(NOW())');
455 455
     }
456 456
 
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
     sn_db_transaction_rollback();
460 460
   }
461 461
 //die();
462
-  header("Location: {$_SERVER['PHP_SELF']}?mode={$que_type}" . "&ally_id=" . sys_get_param_id('ally_id'));
462
+  header("Location: {$_SERVER['PHP_SELF']}?mode={$que_type}"."&ally_id=".sys_get_param_id('ally_id'));
463 463
 }
464 464
 
465 465
 
@@ -498,21 +498,21 @@  discard block
 block discarded – undo
498 498
   // TODO: Переделать для $que_type === false
499 499
   $planet['id'] = $planet['id'] ? $planet['id'] : 0;
500 500
 
501
-  if(!is_array($que)) {
501
+  if (!is_array($que)) {
502 502
     $que = que_get($user['id'], $planet['id'], $que_type);
503 503
   }
504 504
 
505
-  if(is_array($que) && isset($que['items'])) {
505
+  if (is_array($que) && isset($que['items'])) {
506 506
     $que = $que['ques'][$que_type][$user['id']][$planet['id']];
507 507
   }
508 508
 
509
-  if($que) {
510
-    foreach($que as $que_element) {
509
+  if ($que) {
510
+    foreach ($que as $que_element) {
511 511
       $template->assign_block_vars('que', que_tpl_parse_element($que_element, $short_names));
512 512
     }
513 513
   }
514 514
 
515
-  if($que_type == QUE_RESEARCH) {
515
+  if ($que_type == QUE_RESEARCH) {
516 516
   }
517 517
 }
518 518
 
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
   $user = DBStaticUser::db_user_by_id($user['id'], true);
539 539
 
540 540
   $time_left[$user['id']][0] = max(0, $on_time - $user['que_processed']);
541
-  if($planet === null && !$time_left[$user['id']][0]) {
541
+  if ($planet === null && !$time_left[$user['id']][0]) {
542 542
     // TODO
543 543
     return $que;
544 544
   }
@@ -547,12 +547,12 @@  discard block
 block discarded – undo
547 547
   $que_type_id = $planet === null ? QUE_RESEARCH : false;
548 548
   $planet = intval(is_array($planet) ? $planet['id'] : $planet); // В $planet у нас теперь только её ID или шаблон null/0/false
549 549
   $que = que_get($user['id'], $planet, $que_type_id, true);
550
-  if(empty($que['items'])) {
550
+  if (empty($que['items'])) {
551 551
     return $que;
552 552
   }
553 553
 
554 554
   $planet_list = array();
555
-  if($planet !== null) {
555
+  if ($planet !== null) {
556 556
     // Если нужно изменять данные на планетах - блокируем планеты и получаем данные о них
557 557
     // TODO - от них не надо ничего, кроме ID и que_processed
558 558
     $planet_row = DBStaticPlanet::db_planet_list_by_user_or_planet($user['id'], $planet);
@@ -561,21 +561,21 @@  discard block
 block discarded – undo
561 561
   }
562 562
 
563 563
   // Теперь в $time_left лежит время обсчета всех очередей по каждой из планеты
564
-  if(array_sum($time_left[$user['id']]) == 0) {
564
+  if (array_sum($time_left[$user['id']]) == 0) {
565 565
     return $que;
566 566
   }
567 567
 
568 568
   $db_changeset = array();
569 569
   $unit_changes = array();
570
-  foreach($que['items'] as &$que_item) {
570
+  foreach ($que['items'] as &$que_item) {
571 571
     $que_player_id = &$que_item['que_player_id'];
572 572
     $que_planet_id = intval($que_item['que_planet_id']);
573 573
 
574 574
     $que_time_left = &$que['time_left'][$que_player_id][$que_planet_id][$que_item['que_type']];
575
-    if(!isset($que_time_left)) {
575
+    if (!isset($que_time_left)) {
576 576
       $que_time_left = $time_left[$que_player_id][$que_planet_id];
577 577
     }
578
-    if($que_time_left <= 0 || $que_item['que_unit_amount'] <= 0) {
578
+    if ($que_time_left <= 0 || $que_item['que_unit_amount'] <= 0) {
579 579
       continue;
580 580
     }
581 581
     // Дальше мы идем, если только осталось время в очереди И юниты к постройке
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
     // Теперь работаем с остатком времени на юните. Оно не может быть равно или меньше нуля
589 589
 
590 590
     // Если времени в очереди осталось не меньше, чем время текущего юнита - значит мы достроили юнит
591
-    if($que_time_left >= $que_item['que_time_left']) {
591
+    if ($que_time_left >= $que_item['que_time_left']) {
592 592
       // Увеличиваем количество отстроенных юнитов
593 593
       $unit_processed++;
594 594
       // Вычитаем из времени очереди потраченное на постройку время
@@ -601,12 +601,12 @@  discard block
 block discarded – undo
601 601
     $que_item['que_unit_amount'] -= $unit_processed;
602 602
 
603 603
     // Если еще остались юниты - значит ВСЁ оставшееся время приходится на достройку следующего юнита
604
-    if($que_item['que_unit_amount'] > 0) {
604
+    if ($que_item['que_unit_amount'] > 0) {
605 605
       $que_item['que_time_left'] = $que_item['que_time_left'] - $que_time_left;
606 606
       $que_time_left = 0;
607 607
     }
608 608
 
609
-    if($que_item['que_unit_amount'] <= 0) {
609
+    if ($que_item['que_unit_amount'] <= 0) {
610 610
       $db_changeset['que'][] = array(
611 611
         'action'  => SQL_OP_DELETE,
612 612
         P_VERSION => 1,
@@ -632,14 +632,14 @@  discard block
 block discarded – undo
632 632
       );
633 633
     }
634 634
 
635
-    if($unit_processed) {
635
+    if ($unit_processed) {
636 636
       $unit_processed_delta = $unit_processed * ($que_item['que_unit_mode'] == BUILD_CREATE ? 1 : -1);
637 637
       $unit_changes[$que_player_id][$que_planet_id][$que_item['que_unit_id']] += $unit_processed_delta;
638 638
     }
639 639
   }
640 640
 
641
-  foreach($time_left as $player_id => $planet_data) {
642
-    foreach($planet_data as $planet_id => $time_on_planet) {
641
+  foreach ($time_left as $player_id => $planet_data) {
642
+    foreach ($planet_data as $planet_id => $time_on_planet) {
643 643
       $table = $planet_id ? 'planets' : 'users';
644 644
       $id = $planet_id ? $planet_id : $player_id;
645 645
       $db_changeset[$table][] = array(
@@ -655,8 +655,8 @@  discard block
 block discarded – undo
655 655
         ),
656 656
       );
657 657
 
658
-      if(is_array($unit_changes[$player_id][$planet_id])) {
659
-        foreach($unit_changes[$player_id][$planet_id] as $unit_id => $unit_amount) {
658
+      if (is_array($unit_changes[$player_id][$planet_id])) {
659
+        foreach ($unit_changes[$player_id][$planet_id] as $unit_id => $unit_amount) {
660 660
           $db_changeset['unit'][] = sn_db_unit_changeset_prepare($unit_id, $unit_amount, $user, $planet_id ? $planet_id : null);
661 661
         }
662 662
       }
@@ -666,38 +666,38 @@  discard block
 block discarded – undo
666 666
   $que = que_recalculate($que);
667 667
 
668 668
   // TODO: Re-enable quests for Alliances
669
-  if(!empty($unit_changes) && !$user['user_as_ally']) {
669
+  if (!empty($unit_changes) && !$user['user_as_ally']) {
670 670
     $quest_list = qst_get_quests($user['id']);
671 671
     $quest_triggers = qst_active_triggers($quest_list);
672 672
     $quest_rewards = array();
673 673
 
674 674
 
675 675
     $xp_incoming = array();
676
-    foreach($unit_changes as $user_id => $planet_changes) {
677
-      foreach($planet_changes as $planet_id => $changes) {
676
+    foreach ($unit_changes as $user_id => $planet_changes) {
677
+      foreach ($planet_changes as $planet_id => $changes) {
678 678
         $planet_this = $planet_id ? classSupernova::db_get_record_by_id(LOC_PLANET, $planet_id) : array();
679
-        foreach($changes as $unit_id => $unit_value) {
679
+        foreach ($changes as $unit_id => $unit_value) {
680 680
           $que_id = que_get_unit_que($unit_id);
681 681
           $unit_level_new = mrc_get_level($user, $planet_this, $unit_id, false, true) + $unit_value;
682
-          if($que_id == QUE_STRUCTURES || $que_id == QUE_RESEARCH) {
682
+          if ($que_id == QUE_STRUCTURES || $que_id == QUE_RESEARCH) {
683 683
             $build_data = eco_get_build_data($user, $planet_this, $unit_id, $unit_level_new - 1);
684 684
             $build_data = $build_data[BUILD_CREATE];
685
-            foreach(sn_get_groups('resources_loot') as $resource_id) {
685
+            foreach (sn_get_groups('resources_loot') as $resource_id) {
686 686
               $xp_incoming[$que_id] += $build_data[$resource_id]; // TODO - добавить конверсию рейтов обмена
687 687
             }
688 688
           }
689 689
 
690
-          if(is_array($quest_triggers)) {
690
+          if (is_array($quest_triggers)) {
691 691
             // TODO: Check mutiply condition quests
692 692
             $quest_trigger_list = array_keys($quest_triggers, $unit_id);
693
-            if(is_array($quest_trigger_list)) {
694
-              foreach($quest_trigger_list as $quest_id) {
693
+            if (is_array($quest_trigger_list)) {
694
+              foreach ($quest_trigger_list as $quest_id) {
695 695
                 $quest_unit_level = $unit_level_new;
696
-                if(get_unit_param($unit_id, P_UNIT_TYPE) == UNIT_SHIPS) {
696
+                if (get_unit_param($unit_id, P_UNIT_TYPE) == UNIT_SHIPS) {
697 697
                   $quest_unit_level = DBStaticUnit::db_unit_count_by_user_and_type_and_snid($user_id, 0, $unit_id);
698 698
                   $quest_unit_level = $quest_unit_level[$unit_id]['qty'];
699 699
                 }
700
-                if($quest_list[$quest_id]['quest_status_status'] != QUEST_STATUS_COMPLETE && $quest_list[$quest_id]['quest_unit_amount'] <= $quest_unit_level) {
700
+                if ($quest_list[$quest_id]['quest_status_status'] != QUEST_STATUS_COMPLETE && $quest_list[$quest_id]['quest_unit_amount'] <= $quest_unit_level) {
701 701
                   $quest_rewards[$quest_id][$user_id][$planet_id] = $quest_list[$quest_id]['quest_rewards_list'];
702 702
                   $quest_list[$quest_id]['quest_status_status'] = QUEST_STATUS_COMPLETE;
703 703
                 }
@@ -710,7 +710,7 @@  discard block
 block discarded – undo
710 710
     // TODO: Изменить начисление награды за квесты на ту планету, на которой происходил ресеч
711 711
     qst_reward($user, $quest_rewards, $quest_list);
712 712
 
713
-    foreach($xp_incoming as $que_id => $xp) {
713
+    foreach ($xp_incoming as $que_id => $xp) {
714 714
       rpg_level_up($user, $que_id == QUE_RESEARCH ? RPG_TECH : RPG_STRUCTURE, $xp / 1000);
715 715
     }
716 716
   }
Please login to merge, or discard this patch.
includes/functions/sys_user.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -141,6 +141,9 @@
 block discarded – undo
141 141
   ");
142 142
 }
143 143
 
144
+/**
145
+ * @param string $email_unsafe
146
+ */
144 147
 function player_create($username_unsafe, $email_unsafe, $options) {
145 148
   sn_db_transaction_check(true);
146 149
 
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  */
8 8
 
9 9
 function sys_user_vacation($user) {
10
-  if(sys_get_param_str('vacation') == 'leave') {
10
+  if (sys_get_param_str('vacation') == 'leave') {
11 11
     if ($user['vacation'] < SN_TIME_NOW) {
12 12
       $user['vacation'] = 0;
13 13
       $user['vacation_next'] = SN_TIME_NOW + classSupernova::$config->player_vacation_timeout;
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
     }
16 16
   }
17 17
 
18
-  if($user['vacation']) {
18
+  if ($user['vacation']) {
19 19
     // sn_sys_logout(false, true);
20 20
     // core_auth::logout(false, true);
21 21
 
@@ -45,33 +45,33 @@  discard block
 block discarded – undo
45 45
   // TODO: Full rewrite
46 46
   sn_db_transaction_start();
47 47
   $TheUser = DBStaticUser::db_user_by_id($UserID);
48
-  if ( $TheUser['ally_id'] != 0 ) {
49
-    $TheAlly = doquery ( "SELECT * FROM `{{alliance}}` WHERE `id` = '" . $TheUser['ally_id'] . "';", '', true );
48
+  if ($TheUser['ally_id'] != 0) {
49
+    $TheAlly = doquery("SELECT * FROM `{{alliance}}` WHERE `id` = '".$TheUser['ally_id']."';", '', true);
50 50
     $TheAlly['ally_members'] -= 1;
51
-    if ( $TheAlly['ally_members'] > 0 ) {
52
-      doquery ( "UPDATE `{{alliance}}` SET `ally_members` = '" . $TheAlly['ally_members'] . "' WHERE `id` = '" . $TheAlly['id'] . "';");
51
+    if ($TheAlly['ally_members'] > 0) {
52
+      doquery("UPDATE `{{alliance}}` SET `ally_members` = '".$TheAlly['ally_members']."' WHERE `id` = '".$TheAlly['id']."';");
53 53
     } else {
54
-      doquery ( "DELETE FROM `{{alliance}}` WHERE `id` = '" . $TheAlly['id'] . "';");
55
-      doquery ( "DELETE FROM `{{statpoints}}` WHERE `stat_type` = '2' AND `id_owner` = '" . $TheAlly['id'] . "';");
54
+      doquery("DELETE FROM `{{alliance}}` WHERE `id` = '".$TheAlly['id']."';");
55
+      doquery("DELETE FROM `{{statpoints}}` WHERE `stat_type` = '2' AND `id_owner` = '".$TheAlly['id']."';");
56 56
     }
57 57
   }
58
-  doquery ( "DELETE FROM `{{statpoints}}` WHERE `stat_type` = '1' AND `id_owner` = '" . $UserID . "';");
58
+  doquery("DELETE FROM `{{statpoints}}` WHERE `stat_type` = '1' AND `id_owner` = '".$UserID."';");
59 59
 
60 60
   db_planet_list_delete_by_owner($UserID);
61 61
 
62
-  doquery ( "DELETE FROM `{{messages}}` WHERE `message_sender` = '" . $UserID . "';");
63
-  doquery ( "DELETE FROM `{{messages}}` WHERE `message_owner` = '" . $UserID . "';");
64
-  doquery ( "DELETE FROM `{{notes}}` WHERE `owner` = '" . $UserID . "';");
62
+  doquery("DELETE FROM `{{messages}}` WHERE `message_sender` = '".$UserID."';");
63
+  doquery("DELETE FROM `{{messages}}` WHERE `message_owner` = '".$UserID."';");
64
+  doquery("DELETE FROM `{{notes}}` WHERE `owner` = '".$UserID."';");
65 65
   FleetList::db_fleet_list_delete_by_owner($UserID);
66 66
 //  doquery ( "DELETE FROM `{{rw}}` WHERE `id_owner1` = '" . $UserID . "';");
67 67
 //  doquery ( "DELETE FROM `{{rw}}` WHERE `id_owner2` = '" . $UserID . "';");
68
-  doquery ( "DELETE FROM `{{buddy}}` WHERE `BUDDY_SENDER_ID` = '" . $UserID . "';");
69
-  doquery ( "DELETE FROM `{{buddy}}` WHERE `BUDDY_OWNER_ID` = '" . $UserID . "';");
70
-  doquery ( "DELETE FROM `{{annonce}}` WHERE `user` = '" . $UserID . "';");
68
+  doquery("DELETE FROM `{{buddy}}` WHERE `BUDDY_SENDER_ID` = '".$UserID."';");
69
+  doquery("DELETE FROM `{{buddy}}` WHERE `BUDDY_OWNER_ID` = '".$UserID."';");
70
+  doquery("DELETE FROM `{{annonce}}` WHERE `user` = '".$UserID."';");
71 71
 
72 72
 
73 73
   classSupernova::db_del_record_by_id(LOC_USER, $UserID);
74
-  doquery ( "DELETE FROM `{{referrals}}` WHERE (`id` = '{$UserID}') OR (`id_partner` = '{$UserID}');");
74
+  doquery("DELETE FROM `{{referrals}}` WHERE (`id` = '{$UserID}') OR (`id_partner` = '{$UserID}');");
75 75
   classSupernova::$config->db_saveItem('users_amount', classSupernova::$config->db_loadItem('users_amount') - 1);
76 76
   sn_db_transaction_commit();
77 77
 }
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
   $ban_current = DBStaticUser::db_user_by_id($banned['id'], false, 'banaday');
88 88
   $ban_until = ($ban_current['banaday'] ? $ban_current['banaday'] : SN_TIME_NOW) + $term;
89 89
 
90
-  DBStaticUser::db_user_set_by_id($banned['id'], "`banaday` = {$ban_until} " . ($is_vacation ? ", `vacation` = '{$ban_until}' " : ''));
90
+  DBStaticUser::db_user_set_by_id($banned['id'], "`banaday` = {$ban_until} ".($is_vacation ? ", `vacation` = '{$ban_until}' " : ''));
91 91
 
92 92
   $banned['username'] = db_escape($banned['username']);
93 93
   $banner['username'] = db_escape($banner['username']);
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
  * @param string $reason
106 106
  */
107 107
 function sys_admin_player_ban_unset($banner, $banned, $reason = '') {
108
-  DBStaticUser::db_user_set_by_id($banned['id'], "`banaday` = 0, `vacation` = " . SN_TIME_NOW . "");
108
+  DBStaticUser::db_user_set_by_id($banned['id'], "`banaday` = 0, `vacation` = ".SN_TIME_NOW."");
109 109
 
110 110
   $banned['username'] = db_escape($banned['username']);
111 111
   $banner['username'] = db_escape($banner['username']);
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 
135 135
     'total_points' => $options['total_points'] = empty($options['total_points']) ? 0 : $options['total_points'],
136 136
 
137
-    'options' => (empty($options['options']) ? $player_options_string : $options['options']) . (empty($options['options_extra']) ? '' : $options['options_extra']),
137
+    'options' => (empty($options['options']) ? $player_options_string : $options['options']).(empty($options['options_extra']) ? '' : $options['options_extra']),
138 138
 
139 139
     'galaxy' => $options['galaxy'] = intval($options['galaxy'] ? $options['galaxy'] : 0),
140 140
     'system' => $options['system'] = intval($options['system'] ? $options['system'] : 0),
@@ -145,28 +145,28 @@  discard block
 block discarded – undo
145 145
   !empty($options['password_encoded_unsafe']) ? $field_set['password'] = $options['password_encoded_unsafe'] : false;
146 146
 
147 147
   $user_new = classSupernova::db_ins_field_set(LOC_USER, $field_set);
148
-  if(!($options['galaxy'] && $options['system'] && $options['planet'])) {
148
+  if (!($options['galaxy'] && $options['system'] && $options['planet'])) {
149 149
     $options['galaxy'] = classSupernova::$config->LastSettedGalaxyPos;
150 150
     $options['system'] = classSupernova::$config->LastSettedSystemPos;
151
-    $segment_size = floor(Vector::$knownPlanets/ 3);
151
+    $segment_size = floor(Vector::$knownPlanets / 3);
152 152
     $segment = floor(classSupernova::$config->LastSettedPlanetPos / $segment_size);
153 153
     $segment++;
154 154
     $options['planet'] = mt_rand(1 + $segment * $segment_size, ($segment + 1) * $segment_size);
155 155
 
156 156
     // $new_planet_id = 0;
157
-    while(true) {
158
-      if($options['planet'] > Vector::$knownPlanets) {
157
+    while (true) {
158
+      if ($options['planet'] > Vector::$knownPlanets) {
159 159
         $options['planet'] = mt_rand(0, $segment_size - 1) + 1;
160 160
         $options['system']++;
161 161
       }
162
-      if($options['system'] > Vector::$knownSystems) {
162
+      if ($options['system'] > Vector::$knownSystems) {
163 163
         $options['system'] = 1;
164 164
         $options['galaxy']++;
165 165
       }
166
-      $options['galaxy'] > Vector::$knownGalaxies? $options['galaxy'] = 1 : false;
166
+      $options['galaxy'] > Vector::$knownGalaxies ? $options['galaxy'] = 1 : false;
167 167
 
168 168
       $galaxy_row = db_planet_by_gspt($options['galaxy'], $options['system'], $options['planet'], PT_PLANET, true, 'id');
169
-      if(!$galaxy_row['id']) {
169
+      if (!$galaxy_row['id']) {
170 170
         classSupernova::$config->db_saveItem(array(
171 171
           'LastSettedGalaxyPos' => $options['galaxy'],
172 172
           'LastSettedSystemPos' => $options['system'],
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
   $username_safe = db_escape($username_unsafe);
190 190
   db_player_name_history_replace($user_new, $username_safe);
191 191
 
192
-  if(!empty($options['partner_id']) && ($referral_row = DBStaticUser::db_user_by_id($options['partner_id'], true))) {
192
+  if (!empty($options['partner_id']) && ($referral_row = DBStaticUser::db_user_by_id($options['partner_id'], true))) {
193 193
     db_referral_insert($options, $user_new);
194 194
   }
195 195
 
Please login to merge, or discard this patch.