Test Failed
Branch trunk (d809b8)
by SuperNova.WS
05:48
created
classes/sn_module_payment.php 1 patch
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
   public function compile_request($request) {
451 451
     global $config, $lang, $user;
452 452
 
453
-    if(!(classSupernova::$auth->account instanceof Account)) {
453
+    if (!(classSupernova::$auth->account instanceof Account)) {
454 454
       // TODO - throw new Exception($lang['pay_msg_mm_request_amount_invalid'], SN_PAYMENT_REQUEST_ERROR_UNIT_AMOUNT);
455 455
     }
456 456
     $this->account = classSupernova::$auth->account;
@@ -471,15 +471,15 @@  discard block
 block discarded – undo
471 471
     $this->payment_currency = $config->payment_currency_default;
472 472
     $this->payment_amount = self::currency_convert($this->payment_dark_matter_paid, 'MM_', $this->payment_currency);
473 473
 
474
-    if(empty($this->payment_external_currency) && !empty($this->config['currency'])) {
474
+    if (empty($this->payment_external_currency) && !empty($this->config['currency'])) {
475 475
       $this->payment_external_currency = $this->config['currency'];
476 476
     }
477
-    if(empty($this->payment_external_currency)) {
477
+    if (empty($this->payment_external_currency)) {
478 478
       throw new Exception($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($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($lang['pay_msg_request_error_db_payment_create'], SN_PAYMENT_REQUEST_DB_ERROR_PAYMENT_CREATE);
493 493
     }
494 494
   }
@@ -503,24 +503,24 @@  discard block
 block discarded – undo
503 503
   protected function payment_request_process($options = array()) {
504 504
     global $lang, $config;
505 505
 
506
-    if(!$this->manifest['active']) {
506
+    if (!$this->manifest['active']) {
507 507
       throw new Exception($lang['pay_msg_module_disabled'], SN_MODULE_DISABLED);
508 508
     }
509 509
 
510 510
     // Если есть payment_id - загружаем под него данные
511
-    if(!empty($this->payment_params['payment_id'])) {
511
+    if (!empty($this->payment_params['payment_id'])) {
512 512
       $this->request_payment_id = sys_get_param_id($this->payment_params['payment_id']);
513
-      if(!$this->request_payment_id) {
513
+      if (!$this->request_payment_id) {
514 514
         throw new Exception($lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_INTERNAL_ID_WRONG);
515 515
       }
516 516
 
517
-      if(!$this->db_get_by_id($this->request_payment_id)) {
517
+      if (!$this->db_get_by_id($this->request_payment_id)) {
518 518
         throw new Exception($lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_INTERNAL_ID_WRONG);
519 519
       }
520 520
 
521 521
       // Проверяем - был ли этот платеж обработан?
522 522
       // TODO - Статусы бывают разные. Нужен спецфлаг payment_processed
523
-      if($this->payment_status != PAYMENT_STATUS_NONE) {
523
+      if ($this->payment_status != PAYMENT_STATUS_NONE) {
524 524
         sn_db_transaction_rollback();
525 525
         sys_redirect(SN_ROOT_VIRTUAL . 'metamatter.php?payment_id=' . $this->payment_id);
526 526
         die();
@@ -530,89 +530,89 @@  discard block
 block discarded – undo
530 530
     // Пытаемся получить из запроса ИД аккаунта
531 531
     $request_account_id = !empty($this->payment_params['account_id']) ? sys_get_param_id($this->payment_params['account_id']) : 0;
532 532
     // Если в запросе нет ИД аккаунта - пытаемся использовать payment_account_id
533
-    if(empty($request_account_id) && !empty($this->payment_account_id)) {
533
+    if (empty($request_account_id) && !empty($this->payment_account_id)) {
534 534
       $request_account_id = $this->payment_account_id;
535 535
     }
536 536
     // Если теперь у нас нету ИД аккаунта ни в запросе, ни в записи таблицы - можно паниковать
537
-    if(empty($request_account_id)) {
537
+    if (empty($request_account_id)) {
538 538
       // TODO - аккаунт
539 539
       throw new Exception($lang['pay_msg_request_user_invalid'], $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options));
540 540
     }
541 541
     // Если нет записи в таблице - тогда берем payment_account_id из запроса
542
-    if(empty($this->payment_account_id)) {
542
+    if (empty($this->payment_account_id)) {
543 543
       $this->payment_account_id = $request_account_id;
544 544
     }
545 545
     // Если у нас отличаются ИД аккаунта в запросе и ИД аккаунта в записи - тоже можно паниковать
546
-    if($this->payment_account_id != $request_account_id) {
546
+    if ($this->payment_account_id != $request_account_id) {
547 547
       // TODO - Поменять сообщение об ошибке
548 548
       throw new Exception($lang['pay_msg_request_user_invalid'], $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options));
549 549
     }
550 550
     // Проверяем существование аккаунта с данным ИД
551
-    if(!$this->account->db_get_by_id($this->payment_account_id)) {
551
+    if (!$this->account->db_get_by_id($this->payment_account_id)) {
552 552
       throw new Exception($lang['pay_msg_request_user_invalid'] . ' ID ' . $this->payment_account_id, $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options));
553 553
     }
554 554
 
555 555
     // TODO Проверка на сервер_ид - как бы и не нужна, наверное?
556
-    if(!empty($this->payment_params['server_id'])) {
556
+    if (!empty($this->payment_params['server_id'])) {
557 557
       $this->request_server_id = sys_get_param_str($this->payment_params['server_id']);
558
-      if(SN_ROOT_VIRTUAL != $this->request_server_id) {
558
+      if (SN_ROOT_VIRTUAL != $this->request_server_id) {
559 559
         throw new Exception($lang['pay_msg_request_server_wrong'] . " {$this->request_server_id} вместо " . SN_ROOT_VIRTUAL, SN_PAYMENT_REQUEST_SERVER_WRONG);
560 560
       }
561 561
     }
562 562
 
563 563
     // Сверка количества оплаченной ММ с учётом бонусов
564
-    if(!empty($this->payment_params['payment_dark_matter_gained'])) {
564
+    if (!empty($this->payment_params['payment_dark_matter_gained'])) {
565 565
       $request_mm_amount = sys_get_param_id($this->payment_params['payment_dark_matter_gained']);
566
-      if($request_mm_amount != $this->payment_dark_matter_gained && $this->is_loaded) {
566
+      if ($request_mm_amount != $this->payment_dark_matter_gained && $this->is_loaded) {
567 567
         throw new Exception($lang['pay_msg_mm_request_amount_invalid'] . " пришло {$request_mm_amount} ММ вместо {$this->payment_dark_matter_gained} ММ", SN_PAYMENT_REQUEST_MM_AMOUNT_INVALID);
568 568
       }
569 569
       empty($this->payment_dark_matter_gained) ? $this->payment_dark_matter_gained = $request_mm_amount : false;
570 570
     }
571
-    if(empty($this->payment_dark_matter_paid)) {
571
+    if (empty($this->payment_dark_matter_paid)) {
572 572
       // TODO - обратный расчёт из gained
573 573
     }
574 574
 
575 575
     // Проверка наличия внешнего ИД платежа
576
-    if(!empty($this->payment_params['payment_external_id'])) {
576
+    if (!empty($this->payment_params['payment_external_id'])) {
577 577
       $request_payment_external_id = sys_get_param_id($this->payment_params['payment_external_id']);
578
-      if(empty($request_payment_external_id)) {
578
+      if (empty($request_payment_external_id)) {
579 579
         throw new exception($lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_EXTERNAL_ID_WRONG);
580
-      } elseif(!empty($this->payment_external_id) && $this->payment_external_id != $request_payment_external_id) {
580
+      } elseif (!empty($this->payment_external_id) && $this->payment_external_id != $request_payment_external_id) {
581 581
         // TODO - Может быть поменять сообщение
582 582
         throw new exception($lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_EXTERNAL_ID_WRONG);
583 583
       }
584 584
       $this->payment_external_id = $request_payment_external_id;
585 585
     }
586 586
     // Сверка суммы, запрошенной СН к оплате
587
-    if(!empty($this->payment_params['payment_external_money'])) {
587
+    if (!empty($this->payment_params['payment_external_money'])) {
588 588
       $request_money_out = sys_get_param_float($this->payment_params['payment_external_money']);
589
-      if($request_money_out != $this->payment_external_amount && $this->is_loaded) {
589
+      if ($request_money_out != $this->payment_external_amount && $this->is_loaded) {
590 590
         throw new Exception($lang['pay_msg_request_payment_amount_invalid'] . " пришло {$request_money_out} денег вместо {$this->payment_external_amount} денег", SN_PAYMENT_REQUEST_CURRENCY_AMOUNT_INVALID);
591 591
       }
592 592
       empty($this->payment_external_amount) ? $this->payment_external_amount = $request_money_out : false;
593 593
     }
594 594
     // Заполняем поле валюты платёжной системы
595
-    if(!empty($this->payment_params['payment_external_currency'])) {
595
+    if (!empty($this->payment_params['payment_external_currency'])) {
596 596
       $this->payment_external_currency = sys_get_param_str($this->payment_params['payment_external_currency']);
597
-      if(empty($this->payment_external_currency)) {
597
+      if (empty($this->payment_external_currency)) {
598 598
         // TODO - поменять сообщение
599 599
         throw new Exception($lang['pay_msg_request_payment_amount_invalid'] . " {$this->payment_external_currency}", SN_PAYMENT_REQUEST_CURRENCY_AMOUNT_INVALID);
600 600
       }
601 601
     }
602
-    if(empty($this->payment_external_currency)) {
602
+    if (empty($this->payment_external_currency)) {
603 603
       $this->payment_external_currency = $this->config['currency'];
604 604
     }
605 605
 
606 606
     // Заполнение внутренней суммы и валюты из внешних данных
607
-    if(empty($this->payment_currency)) {
607
+    if (empty($this->payment_currency)) {
608 608
       $this->payment_currency = $config->payment_currency_default;
609 609
     }
610
-    if(empty($this->payment_amount) && !empty($this->payment_external_currency)) {
610
+    if (empty($this->payment_amount) && !empty($this->payment_external_currency)) {
611 611
       $this->payment_amount = self::currency_convert($this->payment_external_amount, $this->payment_external_currency, $this->payment_currency);
612 612
     }
613 613
 
614 614
     // TODO - Тестовый режим
615
-    if(!empty($this->payment_params['test'])) {
615
+    if (!empty($this->payment_params['test'])) {
616 616
       $this->payment_test = $this->config['test'] || sys_get_param_int($this->payment_params['test']);
617 617
     }
618 618
 
@@ -641,12 +641,12 @@  discard block
 block discarded – undo
641 641
     sn_db_transaction_start();
642 642
     try {
643 643
       $response = $this->payment_request_process();
644
-    } catch(Exception $e) {
644
+    } catch (Exception $e) {
645 645
       $response['result'] = $e->getCode();
646 646
       $response['message'] = $e->getMessage();
647 647
     }
648 648
 
649
-    if($response['result'] == SN_PAYMENT_REQUEST_OK) {
649
+    if ($response['result'] == SN_PAYMENT_REQUEST_OK) {
650 650
       sn_db_transaction_commit();
651 651
       $debug->warning('Результат операции: код ' . $response['result'] . ' сообщение "' . $response['message'] . '"', 'Успешный платёж', LOG_INFO_PAYMENT);
652 652
     } else {
@@ -655,7 +655,7 @@  discard block
 block discarded – undo
655 655
     }
656 656
 
657 657
     // Переводим код результата из СН в код платежной системы
658
-    if(is_array($this->result_translations) && !empty($this->result_translations)) {
658
+    if (is_array($this->result_translations) && !empty($this->result_translations)) {
659 659
       $response['result'] = isset($this->result_translations[$response['result']]) ? $this->result_translations[$response['result']] : $this->result_translations[SN_PAYMENT_REQUEST_UNDEFINED_ERROR];
660 660
     }
661 661
 
@@ -680,7 +680,7 @@  discard block
 block discarded – undo
680 680
     $currency_from = strtolower($currency_from);
681 681
     $currency_to = strtolower($currency_to);
682 682
 
683
-    if($currency_from != $currency_to) {
683
+    if ($currency_from != $currency_to) {
684 684
 //      $config_currency_from_name = 'payment_currency_exchange_' . $currency_from;
685 685
 //      $config_currency_to_name = 'payment_currency_exchange_' . $currency_to;
686 686
 
@@ -710,10 +710,10 @@  discard block
 block discarded – undo
710 710
   public static function bonus_calculate($dark_matter, $direct = true, $return_bonus = false) {
711 711
     $bonus = 0;
712 712
     $dark_matter_new = $dark_matter;
713
-    if(!empty(self::$bonus_table) && $dark_matter >= self::$bonus_table[0]) {
714
-      if($direct) {
715
-        foreach(self::$bonus_table as $dm_for_bonus => $multiplier) {
716
-          if($dm_for_bonus <= $dark_matter) {
713
+    if (!empty(self::$bonus_table) && $dark_matter >= self::$bonus_table[0]) {
714
+      if ($direct) {
715
+        foreach (self::$bonus_table as $dm_for_bonus => $multiplier) {
716
+          if ($dm_for_bonus <= $dark_matter) {
717 717
             $dark_matter_new = $dark_matter * (1 + $multiplier);
718 718
             $bonus = $multiplier;
719 719
           } else {
@@ -721,9 +721,9 @@  discard block
 block discarded – undo
721 721
           }
722 722
         }
723 723
       } else {
724
-        foreach(self::$bonus_table as $dm_for_bonus => $multiplier) {
724
+        foreach (self::$bonus_table as $dm_for_bonus => $multiplier) {
725 725
           $temp = $dm_for_bonus * (1 + $multiplier);
726
-          if($dark_matter >= $temp) {
726
+          if ($dark_matter >= $temp) {
727 727
             $dark_matter_new = round($dark_matter / (1 + $multiplier));
728 728
             $bonus = $multiplier;
729 729
           } else {
@@ -779,13 +779,13 @@  discard block
 block discarded – undo
779 779
     );
780 780
 
781 781
     $replace = false;
782
-    if($this->payment_id) {
782
+    if ($this->payment_id) {
783 783
       $payment['payment_id'] = $this->payment_id;
784 784
       $replace = true;
785 785
     }
786 786
 
787 787
     $query = array();
788
-    foreach($payment as $key => $value) {
788
+    foreach ($payment as $key => $value) {
789 789
       $value = is_string($value) ? '"' . db_escape($value) . '"' : $value;
790 790
       $query[] = "`{$key}` = {$value}";
791 791
     }
@@ -797,12 +797,12 @@  discard block
 block discarded – undo
797 797
 
798 798
 
799 799
   function payment_adjust_mm_new() {
800
-    if(!$this->payment_test) {
800
+    if (!$this->payment_test) {
801 801
       // Not a test payment. Adding DM to account
802 802
       $this->account = new Account($this->db);
803 803
       $this->account->db_get_by_id($this->payment_account_id);
804 804
       $result = $this->account->metamatter_change(RPG_PURCHASE, $this->payment_dark_matter_gained, $this->payment_comment);
805
-      if(!$result) {
805
+      if (!$result) {
806 806
         throw new Exception('Ошибка начисления ММ', SN_METAMATTER_ERROR_ADJUST);
807 807
       }
808 808
     }
@@ -812,25 +812,25 @@  discard block
 block discarded – undo
812 812
     die('{НЕ РАБОТАЕТ! СООБЩИТЕ АДМИНИСТРАЦИИ!}');
813 813
     global $lang;
814 814
 
815
-    if(!isset($payment['payment_status'])) {
815
+    if (!isset($payment['payment_status'])) {
816 816
       throw new exception($lang['pay_msg_request_payment_not_found'], SN_PAYMENT_REQUEST_ORDER_NOT_FOUND);
817 817
     }
818 818
 
819
-    if($payment['payment_status'] == PAYMENT_STATUS_COMPLETE) {
820
-      $safe_comment = db_escape($payment['payment_comment'] = $lang['pay_msg_request_payment_cancelled'] .' ' . $payment['payment_comment']);
819
+    if ($payment['payment_status'] == PAYMENT_STATUS_COMPLETE) {
820
+      $safe_comment = db_escape($payment['payment_comment'] = $lang['pay_msg_request_payment_cancelled'] . ' ' . $payment['payment_comment']);
821 821
 
822
-      if(!$payment['payment_test']) {
822
+      if (!$payment['payment_test']) {
823 823
         $result = $this->account->metamatter_change(RPG_PURCHASE_CANCEL, -$payment['payment_dark_matter_gained'], $payment['payment_comment']);
824
-        if(!$result) {
824
+        if (!$result) {
825 825
           throw new exception('Ошибка начисления ММ', SN_METAMATTER_ERROR_ADJUST);
826 826
         }
827 827
       }
828 828
       $payment['payment_status'] = PAYMENT_STATUS_CANCELED;
829 829
       doquery("UPDATE {{payment}} SET payment_status = {$payment['payment_status']}, payment_comment = '{$safe_comment}' WHERE payment_id = {$payment['payment_id']};");
830 830
       throw new exception($lang['pay_msg_request_payment_cancel_complete'], SN_PAYMENT_REQUEST_OK);
831
-    } elseif($payment['payment_status'] == PAYMENT_STATUS_CANCELED) {
831
+    } elseif ($payment['payment_status'] == PAYMENT_STATUS_CANCELED) {
832 832
       throw new exception($lang['pay_msg_request_payment_cancelled_already'], SN_PAYMENT_REQUEST_OK);
833
-    } elseif($payment['payment_status'] == PAYMENT_STATUS_NONE) {
833
+    } elseif ($payment['payment_status'] == PAYMENT_STATUS_NONE) {
834 834
       throw new exception($lang['pay_msg_request_payment_cancel_not_complete'], SN_PAYMENT_REQUEST_PAYMENT_NOT_COMPLETE);
835 835
     }
836 836
   }
@@ -844,8 +844,8 @@  discard block
 block discarded – undo
844 844
 
845 845
   protected function db_complete_payment() {
846 846
     // TODO - поле payment_processed
847
-    if($this->payment_status == PAYMENT_STATUS_NONE) {
848
-      if(!defined('PAYMENT_EXPIRE_TIME') || PAYMENT_EXPIRE_TIME == 0 || empty($this->payment_date) || strtotime($this->payment_date) + PAYMENT_EXPIRE_TIME <= SN_TIME_NOW) {
847
+    if ($this->payment_status == PAYMENT_STATUS_NONE) {
848
+      if (!defined('PAYMENT_EXPIRE_TIME') || PAYMENT_EXPIRE_TIME == 0 || empty($this->payment_date) || strtotime($this->payment_date) + PAYMENT_EXPIRE_TIME <= SN_TIME_NOW) {
849 849
         $this->payment_adjust_mm_new();
850 850
         $this->payment_status = PAYMENT_STATUS_COMPLETE;
851 851
       } else {
@@ -892,7 +892,7 @@  discard block
 block discarded – undo
892 892
   protected function db_assign_payment($payment = null) {
893 893
     $this->payment_reset();
894 894
 
895
-    if(is_array($payment) && isset($payment['payment_id'])) {
895
+    if (is_array($payment) && isset($payment['payment_id'])) {
896 896
       $this->payment_id = $payment['payment_id'];
897 897
       $this->payment_status = $payment['payment_status'];
898 898
       $this->payment_date = $payment['payment_date'];
Please login to merge, or discard this patch.
classes/template_compile.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -142,9 +142,9 @@  discard block
 block discarded – undo
142 142
 
143 143
     preg_match_all('#<!-- INCLUDE (\{\$?[A-Z0-9\-_]+\}|[a-zA-Z0-9\_\-\+\./]+) -->#', $code, $matches);
144 144
     $include_blocks = $matches[1];
145
-    if($include_blocks)
145
+    if ($include_blocks)
146 146
     {
147
-      foreach($include_blocks as &$included_file)
147
+      foreach ($include_blocks as &$included_file)
148 148
       {
149 149
         $included_file .= '.tpl.html';
150 150
       }
@@ -453,8 +453,8 @@  discard block
 block discarded – undo
453 453
 
454 454
     $tag_template_php .= 'for ($_' . $tag_args . '_i = ' . $loop_start . '; $_' . $tag_args . '_i < ' . $loop_end . '; ++$_' . $tag_args . '_i){';
455 455
 //    $tag_template_php .= '$this->_block_counter["'. $tag_args . '"] = $_' . $tag_args . '_i;';
456
-    $tag_template_php .= '$_'. $tag_args . '_val = &' . $varref . '[$_'. $tag_args. '_i];';
457
-    $tag_template_php .= '$this->_block_value["'. $tag_args . '"] = &' . $varref . '[$_'. $tag_args. '_i];';
456
+    $tag_template_php .= '$_' . $tag_args . '_val = &' . $varref . '[$_' . $tag_args . '_i];';
457
+    $tag_template_php .= '$this->_block_value["' . $tag_args . '"] = &' . $varref . '[$_' . $tag_args . '_i];';
458 458
 
459 459
     return $tag_template_php;
460 460
   }
@@ -558,10 +558,10 @@  discard block
 block discarded – undo
558 558
         break;
559 559
 
560 560
         case 'is':
561
-          $is_arg_start = ($tokens[$i-1] == ')') ? array_pop($is_arg_stack) : $i-1;
561
+          $is_arg_start = ($tokens[$i - 1] == ')') ? array_pop($is_arg_stack) : $i - 1;
562 562
           $is_arg = implode(' ', array_slice($tokens, $is_arg_start, $i - $is_arg_start));
563 563
 
564
-          $new_tokens = $this->_parse_is_expr($is_arg, array_slice($tokens, $i+1));
564
+          $new_tokens = $this->_parse_is_expr($is_arg, array_slice($tokens, $i + 1));
565 565
 
566 566
           array_splice($tokens, $is_arg_start, sizeof($tokens), $new_tokens);
567 567
 
@@ -821,11 +821,11 @@  discard block
 block discarded – undo
821 821
     }
822 822
     else if ($include_last_iterator)
823 823
     {
824
-      return '$_'. $blocks[$blockcount] . '_val';
824
+      return '$_' . $blocks[$blockcount] . '_val';
825 825
     }
826 826
     else
827 827
     {
828
-      return '$_'. $blocks[$blockcount - 1] . '_val[\''. $blocks[$blockcount]. '\']';
828
+      return '$_' . $blocks[$blockcount - 1] . '_val[\'' . $blocks[$blockcount] . '\']';
829 829
     }
830 830
   }
831 831
 
@@ -842,7 +842,7 @@  discard block
 block discarded – undo
842 842
     if ($fp = @fopen($filename, 'wb'))
843 843
     {
844 844
       @flock($fp, LOCK_EX);
845
-      @fwrite ($fp, $data);
845
+      @fwrite($fp, $data);
846 846
       @flock($fp, LOCK_UN);
847 847
       @fclose($fp);
848 848
 
@@ -862,7 +862,7 @@  discard block
 block discarded – undo
862 862
   {
863 863
     global $config;
864 864
 
865
-    if(!$config->tpl_minifier)
865
+    if (!$config->tpl_minifier)
866 866
     {
867 867
       return $html;
868 868
     }
@@ -874,14 +874,14 @@  discard block
 block discarded – undo
874 874
     //$html = preg_replace('/[\r\n\t]+/', ' ', $html);
875 875
     $html = preg_replace('/>[\s]*</', '><', $html); // Strip spacechars between tags
876 876
     $html = preg_replace('/[\s]+/', ' ', $html); // Replace several spacechars with one space
877
-    if(!empty($pre[0]))
877
+    if (!empty($pre[0]))
878 878
     {
879
-      foreach($pre[0] as $tag)
879
+      foreach ($pre[0] as $tag)
880 880
       {
881 881
         $tag = preg_replace('/^\ *\/\/[^\<]*?$/m', ' ', $tag); // Strips comments - except those that contains HTML comment inside
882 882
         $tag = preg_replace('/[\ \t]{2,}/', ' ', $tag); // Replace several spaces by one
883 883
         $tag = preg_replace('/\s{2,}/', "\r\n", $tag); // Replace several linefeeds by one
884
-        $html = preg_replace('/#pre#/', $tag, $html,1);
884
+        $html = preg_replace('/#pre#/', $tag, $html, 1);
885 885
       }
886 886
     }
887 887
 
Please login to merge, or discard this patch.
classes/userOptions.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -122,8 +122,8 @@  discard block
 block discarded – undo
122 122
 
123 123
     $update_cache = false;
124 124
 
125
-    if(!empty($this->to_write)) {
126
-      foreach($this->to_write as $key => $cork) {
125
+    if (!empty($this->to_write)) {
126
+      foreach ($this->to_write as $key => $cork) {
127 127
         $value = is_array($this->data[$key]) ? serialize($this->data[$key]) : $this->data[$key]; // Сериализация для массивов при сохранении в БД
128 128
         $this->to_write[$key] = "({$this->user_id}, '" . db_escape($key) . "', '" . db_escape($value) . "')";
129 129
       }
@@ -134,18 +134,18 @@  discard block
 block discarded – undo
134 134
       $update_cache = true;
135 135
     }
136 136
 
137
-    if(!empty($this->to_delete)) {
138
-      foreach($this->to_delete as $key => &$value) {
139
-        $value = is_string($key) ? "'". db_escape($key) . "'" : $key;
137
+    if (!empty($this->to_delete)) {
138
+      foreach ($this->to_delete as $key => &$value) {
139
+        $value = is_string($key) ? "'" . db_escape($key) . "'" : $key;
140 140
       }
141 141
 
142
-      doquery("DELETE FROM {{player_options}} WHERE `player_id` = {$this->user_id} AND `option_id` IN (". implode(',', $this->to_delete) . ") ");
142
+      doquery("DELETE FROM {{player_options}} WHERE `player_id` = {$this->user_id} AND `option_id` IN (" . implode(',', $this->to_delete) . ") ");
143 143
 
144 144
       $this->to_delete = array();
145 145
       $update_cache = true;
146 146
     }
147 147
 
148
-    if($update_cache) {
148
+    if ($update_cache) {
149 149
       global $sn_cache;
150 150
 
151 151
       $field_name = $this->cached_name();
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
   protected function load() {
173 173
     global $sn_cache;
174 174
 
175
-    if($this->loaded) {
175
+    if ($this->loaded) {
176 176
       return;
177 177
     }
178 178
 
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
     $this->to_write = array();
181 181
     $this->to_delete = array();
182 182
 
183
-    if(!$this->user_id) {
183
+    if (!$this->user_id) {
184 184
       $this->loaded = true;
185 185
       return;
186 186
     }
@@ -188,13 +188,13 @@  discard block
 block discarded – undo
188 188
     $field_name = $this->cached_name();
189 189
     $a_data = $sn_cache->$field_name;
190 190
 
191
-    if(!empty($a_data)) {
191
+    if (!empty($a_data)) {
192 192
       $this->data = array_replace_recursive($this->data, $a_data);
193 193
       return;
194 194
     }
195 195
 
196 196
     $query = doquery("SELECT * FROM `{{player_options}}` WHERE `player_id` = {$this->user_id} FOR UPDATE");
197
-    while($row = db_fetch($query)) {
197
+    while ($row = db_fetch($query)) {
198 198
       // $this->data[$row['option_id']] = $row['value'];
199 199
       $this->data[$row['option_id']] = is_string($row['value']) && ($temp = unserialize($row['value'])) !== false ? $temp : $row['value']; // Десериализация
200 200
     }
Please login to merge, or discard this patch.
classes/RequestInfo.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -89,15 +89,15 @@  discard block
 block discarded – undo
89 89
     // Инфа об устройстве и браузере - общая для всех
90 90
     sn_db_transaction_start();
91 91
     $this->device_cypher = $_COOKIE[SN_COOKIE_D];
92
-    if($this->device_cypher) {
92
+    if ($this->device_cypher) {
93 93
       $cypher_safe = db_escape($this->device_cypher);
94 94
       $device_id = doquery("SELECT `device_id` FROM {{security_device}} WHERE `device_cypher` = '{$cypher_safe}' LIMIT 1 FOR UPDATE", true);
95
-      if(!empty($device_id['device_id'])) {
95
+      if (!empty($device_id['device_id'])) {
96 96
         $this->device_id = $device_id['device_id'];
97 97
       }
98 98
     }
99 99
 
100
-    if($this->device_id <= 0) {
100
+    if ($this->device_id <= 0) {
101 101
       do {
102 102
         $cypher_safe = db_escape($this->device_cypher = sys_random_string());
103 103
         $row = doquery("SELECT `device_id` FROM {{security_device}} WHERE `device_cypher` = '{$cypher_safe}' LIMIT 1 FOR UPDATE", true);
@@ -118,10 +118,10 @@  discard block
 block discarded – undo
118 118
     $this->page_address_id = db_get_set_unique_id_value($this->page_address, 'url_id', 'security_url', 'url_string');
119 119
     sn_db_transaction_commit();
120 120
 
121
-    if($this->write_full_url) {
121
+    if ($this->write_full_url) {
122 122
       sn_db_transaction_start();
123 123
       $this->page_url = substr($_SERVER['REQUEST_URI'], strlen(SN_ROOT_RELATIVE));
124
-      if(strpos($_SERVER['REQUEST_URI'], '/simulator.php') === 0) {
124
+      if (strpos($_SERVER['REQUEST_URI'], '/simulator.php') === 0) {
125 125
         $this->page_url = '/simulator.php';
126 126
       }
127 127
       $this->page_url_id = db_get_set_unique_id_value($this->page_url, 'url_id', 'security_url', 'url_string');
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
    */
145 145
   public function db_security_entry_insert($user_id_unsafe) {
146 146
     // TODO $user_id = !empty(self::$user['id']) ? self::$user['id'] : 'NULL';
147
-    if(empty($user_id_unsafe)) {
147
+    if (empty($user_id_unsafe)) {
148 148
       // self::flog('Нет ИД пользователя');
149 149
       return true;
150 150
     }
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
   public function db_counter_insert($user_id_unsafe) {
168 168
     global $config, $sys_stop_log_hit, $is_watching;
169 169
 
170
-    if($sys_stop_log_hit || !$config->game_counter) {
170
+    if ($sys_stop_log_hit || !$config->game_counter) {
171 171
       return;
172 172
     }
173 173
 
@@ -183,14 +183,14 @@  discard block
 block discarded – undo
183 183
 //      $this->ip_v4_int . ", '{$proxy_safe}', " . $this->page_address_id . ", " . $this->page_url_id . ");");
184 184
     doquery(
185 185
       "INSERT INTO {{counter}} SET
186
-        `visit_time` = '" . SN_TIME_SQL. "',
186
+        `visit_time` = '" . SN_TIME_SQL . "',
187 187
         `user_id` = {$user_id_safe},
188 188
         `device_id` = {$this->device_id},
189 189
         `browser_id` = {$this->browser_id},
190 190
         `user_ip` = {$this->ip_v4_int},
191 191
         `user_proxy` = '{$proxy_safe}',
192 192
         `page_url_id` = {$this->page_address_id}" .
193
-        ($this->write_full_url ? ", `plain_url_id` = {$this->page_url_id}" : '' ).
193
+        ($this->write_full_url ? ", `plain_url_id` = {$this->page_url_id}" : '') .
194 194
       ";");
195 195
 
196 196
     $is_watching = false;
Please login to merge, or discard this patch.
classes/db_mysql_v4.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -30,17 +30,17 @@  discard block
 block discarded – undo
30 30
 
31 31
     static $need_keys = array('server', 'user', 'pass', 'name', 'prefix');
32 32
 
33
-    if($this->connected) {
33
+    if ($this->connected) {
34 34
       return true;
35 35
     }
36 36
 
37
-    if(empty($settings) || !is_array($settings) || array_intersect($need_keys, array_keys($settings)) != $need_keys) {
37
+    if (empty($settings) || !is_array($settings) || array_intersect($need_keys, array_keys($settings)) != $need_keys) {
38 38
       $debug->error_fatal('There is missconfiguration in your config.php. Check it again', $this->mysql_error());
39 39
     }
40 40
 
41 41
     // TODO !!!!!! DEBUG -> error!!!!
42 42
     @$this->link = mysql_connect($settings['server'], $settings['user'], $settings['pass']);
43
-    if(!is_resource($this->link)) {
43
+    if (!is_resource($this->link)) {
44 44
       $debug->error_fatal('DB Error - cannot connect to server', $this->mysql_error());
45 45
     }
46 46
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
     return mysql_real_escape_string($unescaped_string, $this->link);
69 69
   }
70 70
   function mysql_close_link() {
71
-    if($this->connected) {
71
+    if ($this->connected) {
72 72
       $this->connected = false;
73 73
       mysql_close($this->link);
74 74
       unset($this->link);
Please login to merge, or discard this patch.
classes/core_auth.php 1 patch
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -205,18 +205,18 @@  discard block
 block discarded – undo
205 205
     // TODO Хотя тут может получится вечный цикл - ПОДУМАТЬ
206 206
     // TODO Тут же можно пробовать провести попытку слияния аккаунтов - хотя это и очень небезопасно
207 207
 
208
-    if(sys_get_param('login_player_register_logout')) {
208
+    if (sys_get_param('login_player_register_logout')) {
209 209
       $this->logout();
210 210
     }
211 211
 
212 212
     $original_suggest = '';
213 213
     // Смотрим - есть ли у нас данные от пользователя
214
-    if(($player_name_submitted = sys_get_param('submit_player_name'))) {
214
+    if (($player_name_submitted = sys_get_param('submit_player_name'))) {
215 215
       // Попытка регистрации нового игрока из данных, введенных пользователем
216 216
       $this->player_suggested_name = sys_get_param_str_unsafe('player_suggested_name');
217 217
     } else {
218
-      foreach($this->providers_authorised as $provider) {
219
-        if($this->player_suggested_name = $provider->player_name_suggest()) { // OK 4.5
218
+      foreach ($this->providers_authorised as $provider) {
219
+        if ($this->player_suggested_name = $provider->player_name_suggest()) { // OK 4.5
220 220
           $original_suggest = $provider->player_name_suggest();
221 221
           break;
222 222
         }
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
     }
225 225
 
226 226
     // Если у нас провайдеры не дают имени и пользователь не дал свой вариант - это у нас первый логин в игру
227
-    if(!$this->player_suggested_name) {
227
+    if (!$this->player_suggested_name) {
228 228
       $max_user_id = db_player_get_max_id(); // 4.5
229 229
       // TODO - предлагать имя игрока по локали
230 230
 
@@ -233,15 +233,15 @@  discard block
 block discarded – undo
233 233
         sn_db_transaction_rollback();
234 234
         $this->player_suggested_name = 'Emperor ' . mt_rand($max_user_id + 1, $max_user_id + 1000);
235 235
         sn_db_transaction_start();
236
-      } while(db_player_name_exists($this->player_suggested_name));
236
+      } while (db_player_name_exists($this->player_suggested_name));
237 237
 
238 238
     }
239 239
 
240
-    if($player_name_submitted) {
240
+    if ($player_name_submitted) {
241 241
       $this->register_player_db_create($this->player_suggested_name); // OK 4.5
242
-      if($this->register_status == LOGIN_SUCCESS) {
242
+      if ($this->register_status == LOGIN_SUCCESS) {
243 243
         sys_redirect(SN_ROOT_VIRTUAL . 'overview.php');
244
-      } elseif($this->register_status == REGISTER_ERROR_PLAYER_NAME_EXISTS && $original_suggest == $this->player_suggested_name) {
244
+      } elseif ($this->register_status == REGISTER_ERROR_PLAYER_NAME_EXISTS && $original_suggest == $this->player_suggested_name) {
245 245
         // self::$player_suggested_name .= ' ' . $this->account->account_id;
246 246
       }
247 247
 //      if(self::$login_status != LOGIN_SUCCESS) {
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
         : false
266 266
       );
267 267
 
268
-    if($this->register_status == LOGIN_ERROR_USERNAME_RESTRICTED_CHARACTERS) {
268
+    if ($this->register_status == LOGIN_ERROR_USERNAME_RESTRICTED_CHARACTERS) {
269 269
       $prohibited_characters = array_map(function($value) {
270 270
         return "'" . htmlentities($value, ENT_QUOTES, 'UTF-8') . "'";
271 271
       }, str_split(LOGIN_REGISTER_CHARACTERS_PROHIBITED));
@@ -297,27 +297,27 @@  discard block
 block discarded – undo
297 297
     global $sn_module_list, $lang;
298 298
 
299 299
     // !self::$is_init ? self::init() : false;
300
-    if(empty($sn_module_list['auth'])) {
300
+    if (empty($sn_module_list['auth'])) {
301 301
       die('{Не обнаружено ни одного провайдера авторизации в core_auth::login()!}');
302 302
     }
303 303
 
304 304
     !empty($_POST) ? self::flog(dump($_POST, '$_POST')) : false;
305 305
     !empty($_GET) ? self::flog(dump($_GET, '$_GET')) : false;
306
-    !empty($_COOKIE) ? self::flog(dump($_COOKIE,'$_COOKIE')) : false;
306
+    !empty($_COOKIE) ? self::flog(dump($_COOKIE, '$_COOKIE')) : false;
307 307
 
308 308
     $this->auth_reset(); // OK v4.5
309 309
 
310 310
     $this->providers = array();
311
-    foreach($sn_module_list['auth'] as $module_name => $module) {
311
+    foreach ($sn_module_list['auth'] as $module_name => $module) {
312 312
       $this->providers[$module->provider_id] = $module;
313 313
     }
314 314
 
315 315
     // $this->providers = array_reverse($this->providers, true); // НИНАДА! СН-аккаунт должен всегда авторизироваться первым!
316 316
 //pdump($this->providers);
317
-    foreach($this->providers as $provider_id => $provider) {
317
+    foreach ($this->providers as $provider_id => $provider) {
318 318
       $login_status = $provider->login(); // OK v4.5
319 319
       self::flog(($provider->manifest['name'] . '->' . 'login_try - ') . (empty($provider->account->account_id) ? $lang['sys_login_messages'][$provider->account_login_status] : dump($provider)));
320
-      if($login_status == LOGIN_SUCCESS && is_object($provider->account) && $provider->account instanceof Account && $provider->account->account_id) {
320
+      if ($login_status == LOGIN_SUCCESS && is_object($provider->account) && $provider->account instanceof Account && $provider->account->account_id) {
321 321
         $this->providers_authorised[$provider_id] = &$this->providers[$provider_id];
322 322
 
323 323
         $this->user_id_to_provider = array_replace_recursive(
@@ -325,20 +325,20 @@  discard block
 block discarded – undo
325 325
           // static::db_translate_get_users_from_account_list($provider_id, $provider->account->account_id) // OK 4.5
326 326
           PlayerToAccountTranslate::db_translate_get_users_from_account_list($provider_id, $provider->account->account_id) // OK 4.5
327 327
         );
328
-      } elseif($login_status != LOGIN_UNDEFINED) {
328
+      } elseif ($login_status != LOGIN_UNDEFINED) {
329 329
         $this->provider_error_list[$provider_id] = $login_status;
330 330
       }
331 331
     }
332 332
 
333
-    if(empty($this->providers_authorised)) {
333
+    if (empty($this->providers_authorised)) {
334 334
       // Ни один аккаунт не авторизирован
335 335
       // Проверяем - есть ли у нас ошибки в аккаунтах?
336
-      if(!empty($this->provider_error_list)) {
336
+      if (!empty($this->provider_error_list)) {
337 337
         // Если есть - выводим их
338 338
         self::$login_status = reset($this->provider_error_list);
339 339
         $providerError = $this->providers[key($this->provider_error_list)]->account_login_message;
340 340
 
341
-        if(!empty($providerError)) {
341
+        if (!empty($providerError)) {
342 342
           self::$login_message = $providerError;
343 343
         }
344 344
       }
@@ -353,12 +353,12 @@  discard block
 block discarded – undo
353 353
       // В self::$accessible_user_row_list - список доступных игроков для данных аккаунтов с соответствующими записями из таблицы `users`
354 354
 
355 355
       // Остались ли у нас в списке доступные игроки?
356
-      if(empty($this->accessible_user_row_list)) {
356
+      if (empty($this->accessible_user_row_list)) {
357 357
         // Нет ни одного игрока ни на одном авторизированном аккаунте
358 358
         // Надо регать нового игрока
359 359
 
360 360
         // Сейчас происходит процесс регистрации игрока?
361
-        if(!$this->is_player_register) {
361
+        if (!$this->is_player_register) {
362 362
           // Нет - отправляем на процесс регистрации
363 363
           $partner_id = sys_get_param_int('id_ref', sys_get_param_int('partner_id'));
364 364
           sys_redirect(SN_ROOT_VIRTUAL . 'index.php?page=player_register&player_register=1' . ($partner_id ? '&id_ref=' . $partner_id : ''));
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
         // Да, есть доступные игроки, которые так же прописаны в базе
368 368
         $this->get_active_user(); // 4.5
369 369
 
370
-        if($this->is_impersonating = !empty($_COOKIE[SN_COOKIE_U_I]) ? $_COOKIE[SN_COOKIE_U_I] : 0) {
370
+        if ($this->is_impersonating = !empty($_COOKIE[SN_COOKIE_U_I]) ? $_COOKIE[SN_COOKIE_U_I] : 0) {
371 371
           $a_user = db_user_by_id($this->is_impersonating);
372 372
           $this->impersonator_username = $a_user['username'];
373 373
         }
@@ -375,9 +375,9 @@  discard block
 block discarded – undo
375 375
 
376 376
         //Прописываем текущего игрока на все авторизированные аккаунты
377 377
         // TODO - ИЛИ ВСЕХ ИГРОКОВ??
378
-        if(empty($this->is_impersonating)) {
379
-          foreach($this->providers_authorised as $provider_id => $provider) {
380
-            if(empty($this->user_id_to_provider[self::$user['id']][$provider_id])) {
378
+        if (empty($this->is_impersonating)) {
379
+          foreach ($this->providers_authorised as $provider_id => $provider) {
380
+            if (empty($this->user_id_to_provider[self::$user['id']][$provider_id])) {
381 381
               // self::db_translate_register_user($provider_id, $provider->account->account_id, self::$user['id']);
382 382
               PlayerToAccountTranslate::db_translate_register_user($provider_id, $provider->account->account_id, self::$user['id']);
383 383
               $this->user_id_to_provider[self::$user['id']][$provider_id][$provider->account->account_id] = true;
@@ -387,9 +387,9 @@  discard block
 block discarded – undo
387 387
       }
388 388
     }
389 389
 
390
-    if(empty(self::$user['id'])) {
390
+    if (empty(self::$user['id'])) {
391 391
       self::cookie_set(''); // OK 4.5
392
-    } elseif(self::$user['id'] != $_COOKIE[SN_COOKIE_U]) {
392
+    } elseif (self::$user['id'] != $_COOKIE[SN_COOKIE_U]) {
393 393
       self::cookie_set(self::$user['id']); // OK 4.5
394 394
     }
395 395
 
@@ -408,21 +408,21 @@  discard block
 block discarded – undo
408 408
    */
409 409
   // OK v4.7
410 410
   public function logout($redirect = true) {
411
-    if(!empty($_COOKIE[SN_COOKIE_U_I])) {
411
+    if (!empty($_COOKIE[SN_COOKIE_U_I])) {
412 412
       self::cookie_set($_COOKIE[SN_COOKIE_U_I]);
413 413
       self::cookie_set(0, true);
414 414
       self::$main_provider->logout();
415 415
     } else {
416
-      foreach($this->providers as $provider_name => $provider) {
416
+      foreach ($this->providers as $provider_name => $provider) {
417 417
         $provider->logout();
418 418
       }
419 419
 
420 420
       self::cookie_set(0);
421 421
     }
422 422
 
423
-    if($redirect === true) {
423
+    if ($redirect === true) {
424 424
       sys_redirect(SN_ROOT_RELATIVE . (empty($_COOKIE[SN_COOKIE_U]) ? 'login.php' : 'admin/overview.php'));
425
-    } elseif($redirect !== false) {
425
+    } elseif ($redirect !== false) {
426 426
       sys_redirect($redirect);
427 427
     }
428 428
   }
@@ -433,15 +433,15 @@  discard block
 block discarded – undo
433 433
    * @param $user_selected
434 434
    */
435 435
   public function impersonate($user_selected) {
436
-    if($_COOKIE[SN_COOKIE_U_I]) {
436
+    if ($_COOKIE[SN_COOKIE_U_I]) {
437 437
       die('You already impersonating someone. Go back to living other\'s life! Or clear your cookies and try again'); // TODO: Log it
438 438
     }
439 439
 
440
-    if($this->auth_level_max_local < AUTH_LEVEL_ADMINISTRATOR) {
440
+    if ($this->auth_level_max_local < AUTH_LEVEL_ADMINISTRATOR) {
441 441
       die('You can\'t impersonate - too low level'); // TODO: Log it
442 442
     }
443 443
 
444
-    if($this->auth_level_max_local <= $user_selected['authlevel']) {
444
+    if ($this->auth_level_max_local <= $user_selected['authlevel']) {
445 445
       die('You can\'t impersonate this account - level is greater or equal to yours'); // TODO: Log it
446 446
     }
447 447
 
@@ -449,7 +449,7 @@  discard block
 block discarded – undo
449 449
     $account_translate = reset($account_translate[$user_selected['id']][self::$main_provider->provider_id]);
450 450
     $account_to_impersonate = new Account(self::$main_provider->db);
451 451
     $account_to_impersonate->db_get_by_id($account_translate['provider_account_id']);
452
-    if(!$account_to_impersonate->is_exists) {
452
+    if (!$account_to_impersonate->is_exists) {
453 453
       die('Какая-то ошибка - не могу найти аккаунт для имперсонации'); // TODO: Log it
454 454
     }
455 455
     self::$main_provider->impersonate($account_to_impersonate);
@@ -475,12 +475,12 @@  discard block
 block discarded – undo
475 475
   public function password_check($password_unsafe) {
476 476
     $result = false;
477 477
 
478
-    if(empty($this->providers_authorised)) {
478
+    if (empty($this->providers_authorised)) {
479 479
       // TODO - такого быть не может!
480 480
       self::flog("password_check: Не найдено ни одного авторизированного провайдера в self::\$providers_authorised", true);
481 481
     } else {
482
-      foreach($this->providers_authorised as $provider_id => $provider) {
483
-        if($provider->is_feature_supported(AUTH_FEATURE_HAS_PASSWORD)) {
482
+      foreach ($this->providers_authorised as $provider_id => $provider) {
483
+        if ($provider->is_feature_supported(AUTH_FEATURE_HAS_PASSWORD)) {
484 484
           $result = $result || $provider->password_check($password_unsafe);
485 485
         }
486 486
       }
@@ -501,7 +501,7 @@  discard block
 block discarded – undo
501 501
   public function password_change($old_password_unsafe, $new_password_unsafe) {
502 502
     global $lang;
503 503
 
504
-    if(empty($this->providers_authorised)) {
504
+    if (empty($this->providers_authorised)) {
505 505
       // TODO - такого быть не может!
506 506
       self::flog("Не найдено ни одного авторизированного провайдера в self::\$providers_authorised", true);
507 507
       return false;
@@ -514,8 +514,8 @@  discard block
 block discarded – undo
514 514
     $salt_unsafe = self::password_salt_generate();
515 515
 
516 516
     $providers_changed_password = array();
517
-    foreach($this->providers_authorised as $provider_id => $provider) {
518
-      if(
517
+    foreach ($this->providers_authorised as $provider_id => $provider) {
518
+      if (
519 519
         !$provider->is_feature_supported(AUTH_FEATURE_PASSWORD_CHANGE)
520 520
         || !$provider->password_change($old_password_unsafe, $new_password_unsafe, $salt_unsafe)
521 521
       ) {
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
       $account_translation = PlayerToAccountTranslate::db_translate_get_users_from_account_list($provider_id, $provider->account->account_id);
528 528
 
529 529
       // Рассылаем уведомления о смене пароля в ЛС
530
-      foreach($account_translation as $user_id => $provider_info) {
530
+      foreach ($account_translation as $user_id => $provider_info) {
531 531
         // TODO - УКазывать тип аккаунта, на котором сменён пароль
532 532
         msg_send_simple_message($user_id, 0, SN_TIME_NOW, MSG_TYPE_ADMIN,
533 533
           $lang['sys_administration'], $lang['sys_login_register_message_title'],
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
       sn_db_transaction_start();
575 575
       // Проверить наличие такого имени в истории имён
576 576
 
577
-      if(db_player_name_exists($player_name_unsafe)) {
577
+      if (db_player_name_exists($player_name_unsafe)) {
578 578
         throw new Exception(REGISTER_ERROR_PLAYER_NAME_EXISTS, ERR_ERROR);
579 579
       }
580 580
 
@@ -582,11 +582,11 @@  discard block
 block discarded – undo
582 582
       $player_language = '';
583 583
       $player_email = '';
584 584
       // TODO - порнография - работа должна происходить над списком аккаунтов, а не только на одном аккаунте...
585
-      foreach($this->providers_authorised as $provider) {
586
-        if(!$player_language && $provider->account->account_language) {
585
+      foreach ($this->providers_authorised as $provider) {
586
+        if (!$player_language && $provider->account->account_language) {
587 587
           $player_language = $provider->account->account_language;
588 588
         }
589
-        if(!$player_email && $provider->account->account_email) {
589
+        if (!$player_email && $provider->account->account_email) {
590 590
           $player_email = $provider->account->account_email;
591 591
         }
592 592
       }
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
       ));
603 603
       // Зарегестрировать на него аккаунты из self::$accounts_authorised
604 604
       $a_user = self::$user;
605
-      foreach($this->providers_authorised as $provider) {
605
+      foreach ($this->providers_authorised as $provider) {
606 606
         // TODO - порнография. Должен быть отдельный класс трансляторов - в т.ч. и кэширующий транслятор
607 607
         // TODO - ну и работа должна происходить над списком аккаунтов, а не только на одном аккаунте...
608 608
         // self::db_translate_register_user($provider->provider_id, $provider->account->account_id, $a_user['id']);
@@ -614,7 +614,7 @@  discard block
 block discarded – undo
614 614
 
615 615
       sn_db_transaction_commit();
616 616
       $this->register_status = LOGIN_SUCCESS;
617
-    } catch(Exception $e) {
617
+    } catch (Exception $e) {
618 618
       sn_db_transaction_rollback();
619 619
 
620 620
       // Если старое имя занято
@@ -633,10 +633,10 @@  discard block
 block discarded – undo
633 633
     // Пробиваем все ИД игроков по базе - есть ли вообще такие записи
634 634
     // Вообще-то это не особо нужно - у нас по определению стоят констраинты
635 635
     // Зато так мы узнаем максимальный authlevel, проверим права имперсонейта и вытащим все записи юзеров
636
-    foreach($this->user_id_to_provider as $user_id => $cork) {
636
+    foreach ($this->user_id_to_provider as $user_id => $cork) {
637 637
       $user = db_user_by_id($user_id);
638 638
       // Если записи игрока в БД не существует?
639
-      if(empty($user['id'])) {
639
+      if (empty($user['id'])) {
640 640
         // Удаляем этого и переходим к следующему
641 641
         unset($this->user_id_to_provider[$user_id]);
642 642
         // Де-регистрируем игрока из таблицы трансляции игроков
@@ -657,7 +657,7 @@  discard block
 block discarded – undo
657 657
   // OK v4.5
658 658
   protected function get_active_user() {
659 659
     // Проверяем куку "текущего игрока" из браузера
660
-    if(
660
+    if (
661 661
       // Кука не пустая
662 662
       ($_COOKIE[SN_COOKIE_U] = trim($_COOKIE[SN_COOKIE_U])) && !empty($_COOKIE[SN_COOKIE_U])
663 663
       // И в куке находится ID
@@ -682,7 +682,7 @@  discard block
 block discarded – undo
682 682
     }
683 683
 
684 684
     // В куке нет валидного ИД записи игрока, доступной с текущих аккаунтов
685
-    if(empty(self::$user['id'])) {
685
+    if (empty(self::$user['id'])) {
686 686
       // Берем первого из доступных
687 687
       // TODO - default_user
688 688
       self::$user = reset($this->accessible_user_row_list);
@@ -706,7 +706,7 @@  discard block
 block discarded – undo
706 706
 
707 707
     $result = array();
708 708
 
709
-    if($user_id && empty($this->is_impersonating)) {
709
+    if ($user_id && empty($this->is_impersonating)) {
710 710
       // self::db_counter_insert();
711 711
       self::$device->db_counter_insert($user_id);
712 712
 
@@ -714,12 +714,12 @@  discard block
 block discarded – undo
714 714
 
715 715
       sys_user_options_unpack($user);
716 716
 
717
-      if($user['banaday'] && $user['banaday'] <= SN_TIME_NOW) {
717
+      if ($user['banaday'] && $user['banaday'] <= SN_TIME_NOW) {
718 718
         $user['banaday'] = 0;
719 719
         $user['vacation'] = SN_TIME_NOW;
720 720
       }
721 721
 
722
-      $user['user_lastip'] = self::$device->ip_v4_string;// $ip['ip'];
722
+      $user['user_lastip'] = self::$device->ip_v4_string; // $ip['ip'];
723 723
       $user['user_proxy'] = self::$device->ip_v4_proxy_chain; //$ip['proxy_chain'];
724 724
 
725 725
       $result[F_BANNED_STATUS] = $user['banaday'];
@@ -733,13 +733,13 @@  discard block
 block discarded – undo
733 733
       );
734 734
     }
735 735
 
736
-    if($extra = $config->security_ban_extra) {
736
+    if ($extra = $config->security_ban_extra) {
737 737
       $extra = explode(',', $extra);
738
-      array_walk($extra,'trim');
738
+      array_walk($extra, 'trim');
739 739
       in_array(self::$device->device_id, $extra) and die();
740 740
     }
741 741
 
742
-    if(self::$login_message) {
742
+    if (self::$login_message) {
743 743
       $result[F_LOGIN_MESSAGE] = self::$login_message;
744 744
     }
745 745
 
@@ -775,21 +775,21 @@  discard block
 block discarded – undo
775 775
   protected function register_player_name_validate($player_name_unsafe) {
776 776
     // TODO - переделать под RAW-строки
777 777
     // Если имя игрока пустое - NO GO!
778
-    if(trim($player_name_unsafe) == '') {
778
+    if (trim($player_name_unsafe) == '') {
779 779
       throw new Exception(REGISTER_ERROR_PLAYER_NAME_EMPTY, ERR_ERROR);
780 780
     }
781 781
     // Проверяем, что бы в начале и конце не было пустых символов
782
-    if($player_name_unsafe != trim($player_name_unsafe)) {
782
+    if ($player_name_unsafe != trim($player_name_unsafe)) {
783 783
       throw new Exception(REGISTER_ERROR_PLAYER_NAME_TRIMMED, ERR_ERROR);
784 784
     }
785 785
     // Если логин имеет запрещенные символы - NO GO!
786
-    if(strpbrk($player_name_unsafe, LOGIN_REGISTER_CHARACTERS_PROHIBITED)) {
786
+    if (strpbrk($player_name_unsafe, LOGIN_REGISTER_CHARACTERS_PROHIBITED)) {
787 787
       // TODO - выдавать в сообщение об ошибке список запрещенных символов
788 788
       // TODO - заранее извещать игрока, какие символы являются запрещенными
789 789
       throw new Exception(REGISTER_ERROR_PLAYER_NAME_RESTRICTED_CHARACTERS, ERR_ERROR);
790 790
     }
791 791
     // Если логин меньше минимальной длины - NO GO!
792
-    if(strlen($player_name_unsafe) < LOGIN_LENGTH_MIN) {
792
+    if (strlen($player_name_unsafe) < LOGIN_LENGTH_MIN) {
793 793
       // TODO - выдавать в сообщение об ошибке минимальную длину имени игрока
794 794
       // TODO - заранее извещать игрока, какая минимальная и максимальная длина имени
795 795
       throw new Exception(REGISTER_ERROR_PLAYER_NAME_SHORT, ERR_ERROR);
@@ -847,7 +847,7 @@  discard block
 block discarded – undo
847 847
   }
848 848
 
849 849
   protected static function flog($message, $die = false) {
850
-    if(!defined('DEBUG_AUTH') || !DEBUG_AUTH) {
850
+    if (!defined('DEBUG_AUTH') || !DEBUG_AUTH) {
851 851
       return;
852 852
     }
853 853
     list($called, $caller) = debug_backtrace(false);
@@ -860,7 +860,7 @@  discard block
 block discarded – undo
860 860
     $_SERVER['SERVER_NAME'] == 'localhost' ? print("<div class='debug'>$message - $caller_name\r\n</div>") : false;
861 861
 
862 862
     classSupernova::log_file("$message - $caller_name");
863
-    if($die) {
863
+    if ($die) {
864 864
       $die && die("<div class='negative'>СТОП! Функция {$caller_name} при вызове в " . get_called_class() . " (располагается в " . get_class() . "). СООБЩИТЕ АДМИНИСТРАЦИИ!</div>");
865 865
     }
866 866
   }
Please login to merge, or discard this patch.
notes.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -15,34 +15,34 @@  discard block
 block discarded – undo
15 15
 $template = gettemplate('notes', true);
16 16
 
17 17
 $result = array();
18
-if(($result_message = sys_get_param_str('MESSAGE')) && isset($lang[$result_message])) {
18
+if (($result_message = sys_get_param_str('MESSAGE')) && isset($lang[$result_message])) {
19 19
   $result[] = array('STATUS' => sys_get_param_int('STATUS'), 'MESSAGE' => $lang[$result_message]);
20 20
 }
21 21
 
22 22
 $note_id_edit = sys_get_param_id('note_id_edit');
23
-if(sys_get_param('note_delete')) {
23
+if (sys_get_param('note_delete')) {
24 24
   try {
25 25
     $not = '';
26 26
     $query_where = '';
27
-    switch(sys_get_param_str('note_delete_range')) {
27
+    switch (sys_get_param_str('note_delete_range')) {
28 28
       case 'all':
29 29
       break;
30 30
 
31 31
       case 'marked_not':
32 32
         $not = 'NOT';
33 33
       case 'marked':
34
-        if(!is_array($notes_marked = sys_get_param('note'))) {
34
+        if (!is_array($notes_marked = sys_get_param('note'))) {
35 35
           throw new exception('note_err_none_selected', ERR_WARNING);
36 36
         }
37 37
 
38 38
         $notes_marked_filtered = array();
39
-        foreach($notes_marked as $note_id => $note_select) {
40
-          if($note_select == 'on' && $note_id = idval($note_id)) {
39
+        foreach ($notes_marked as $note_id => $note_select) {
40
+          if ($note_select == 'on' && $note_id = idval($note_id)) {
41 41
             $notes_marked_filtered[] = $note_id;
42 42
           }
43 43
         }
44 44
 
45
-        if(empty($notes_marked_filtered)) {
45
+        if (empty($notes_marked_filtered)) {
46 46
           throw new exception('note_err_none_selected', ERR_WARNING);
47 47
         }
48 48
 
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
     doquery("DELETE FROM {{notes}} WHERE `owner` = {$user['id']} {$query_where};");
60 60
     sn_db_transaction_commit();
61 61
     throw new exception($note_id_edit ? 'note_err_none_changed' : 'note_err_none_added', ERR_NONE);
62
-  } catch(exception $e) {
62
+  } catch (exception $e) {
63 63
     $note_id_edit = 0;
64 64
     sn_db_transaction_rollback();
65 65
     $result[] = array(
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
       'MESSAGE' => $lang[$e->getMessage()],
68 68
     );
69 69
   }
70
-} elseif(($note_title = sys_get_param_str('note_title')) || ($note_text = sys_get_param_str('note_text'))) {
70
+} elseif (($note_title = sys_get_param_str('note_title')) || ($note_text = sys_get_param_str('note_text'))) {
71 71
   $note_title == db_escape($lang['note_new_title']) ? $note_title = '' : false;
72 72
   ($note_text = sys_get_param_str('note_text')) == db_escape($lang['note_new_text']) ? $note_text = '' : false;
73 73
 
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
     $note_system = max(0, min(sys_get_param_id('note_system'), classSupernova::$config->game_maxSystem));
77 77
     $note_planet = max(0, min(sys_get_param_id('note_planet'), classSupernova::$config->game_maxPlanet + 1));
78 78
 
79
-    if(!$note_text && !$note_title && !$note_galaxy && !$note_system && !$note_planet) {
79
+    if (!$note_text && !$note_title && !$note_galaxy && !$note_system && !$note_planet) {
80 80
       throw new exception('note_err_note_empty', ERR_WARNING);
81 81
     }
82 82
 
@@ -85,15 +85,15 @@  discard block
 block discarded – undo
85 85
     $note_sticky = intval(sys_get_param_id('note_sticky')) ? 1 : 0;
86 86
 
87 87
     sn_db_transaction_start();
88
-    if($note_id_edit) {
88
+    if ($note_id_edit) {
89 89
       $check_note_id = doquery("SELECT `id`, `owner` FROM {{notes}} WHERE `id` = {$note_id_edit} LIMIT 1 FOR UPDATE", true);
90
-      if(!$check_note_id) {
90
+      if (!$check_note_id) {
91 91
         throw new exception('note_err_note_not_found', ERR_ERROR);
92 92
       }
93 93
     }
94 94
 
95
-    if($note_id_edit) {
96
-      if($check_note_id['owner'] != $user['id']) {
95
+    if ($note_id_edit) {
96
+      if ($check_note_id['owner'] != $user['id']) {
97 97
         throw new exception('note_err_owner_wrong', ERR_ERROR);
98 98
       }
99 99
 
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
     sn_db_transaction_commit();
109 109
     sys_redirect('notes.php?STATUS=' . ERR_NONE . '&MESSAGE=' . ($note_id_edit ? 'note_err_none_changed' : 'note_err_none_added'));
110 110
 //    throw new exception($note_id_edit ? 'note_err_none_changed' : 'note_err_none_added', ERR_NONE);
111
-  } catch(exception $e) {
111
+  } catch (exception $e) {
112 112
     $note_id_edit = 0;
113 113
     sn_db_transaction_rollback();
114 114
     $result[] = array(
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
   }
119 119
 }
120 120
 
121
-if(!$note_id_edit) {
121
+if (!$note_id_edit) {
122 122
   note_assign($template, array(
123 123
     'id' => 0,
124 124
     'time' => SN_TIME_NOW,
@@ -131,13 +131,13 @@  discard block
 block discarded – undo
131 131
 
132 132
 $note_exist = false;
133 133
 $notes_query = doquery("SELECT * FROM {{notes}} WHERE owner={$user['id']} ORDER BY priority DESC, galaxy ASC, system ASC, planet ASC, planet_type ASC, `time` DESC");
134
-while($note_row = db_fetch($notes_query)) {
134
+while ($note_row = db_fetch($notes_query)) {
135 135
   note_assign($template, $note_row);
136 136
   $note_exist = $note_exist || $note_row['id'] == $note_id_edit;
137 137
 }
138 138
 $note_id_edit = $note_exist ? $note_id_edit : 0;
139 139
 
140
-foreach($note_priority_classes as $note_priority_id => $note_priority_class) {
140
+foreach ($note_priority_classes as $note_priority_id => $note_priority_class) {
141 141
   $template->assign_block_vars('note_priority', array(
142 142
     'ID' => $note_priority_id,
143 143
     'CLASS' => $note_priority_classes[$note_priority_id],
@@ -145,14 +145,14 @@  discard block
 block discarded – undo
145 145
   ));
146 146
 }
147 147
 
148
-foreach($lang['sys_planet_type'] as $planet_type_id => $planet_type_string) {
148
+foreach ($lang['sys_planet_type'] as $planet_type_id => $planet_type_string) {
149 149
   $template->assign_block_vars('planet_type', array(
150 150
     'ID' => $planet_type_id,
151 151
     'TEXT' => $planet_type_string,
152 152
   ));
153 153
 }
154 154
 
155
-foreach($result as $result_data) {
155
+foreach ($result as $result_data) {
156 156
   $template->assign_block_vars('result', $result_data);
157 157
 }
158 158
 
Please login to merge, or discard this patch.
includes/db/db_queries.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 
104 104
 function db_unit_records_sum($unit_id, $user_skip_list_unit)
105 105
 {
106
-  return doquery (
106
+  return doquery(
107 107
     "SELECT unit_player_id, username, sum(unit_level) as unit_level
108 108
           FROM {{unit}} JOIN {{users}} AS u ON u.id = unit_player_id
109 109
           WHERE unit_player_id != 0 AND unit_snid = {$unit_id} {$user_skip_list_unit}
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 
116 116
 function db_unit_records_plain($unit_id, $user_skip_list_unit)
117 117
 {
118
-  return doquery (
118
+  return doquery(
119 119
     "SELECT unit_player_id, username, unit_level
120 120
           FROM {{unit}} JOIN {{users}} AS u ON u.id = unit_player_id
121 121
           WHERE unit_player_id != 0 AND unit_snid = {$unit_id} {$user_skip_list_unit}
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 }
126 126
 
127 127
 function db_stat_list_statistic($who, $is_common_stat, $Rank, $start, $source = false) {
128
-  if(!$source) {
128
+  if (!$source) {
129 129
     $source = array(
130 130
       'statpoints' => 'statpoints',
131 131
       'users' => 'users',
@@ -146,8 +146,8 @@  discard block
 block discarded – undo
146 146
     );
147 147
   }
148 148
 
149
-  if($who == 1) {
150
-    if($is_common_stat) { // , UNIX_TIMESTAMP(CONCAT(YEAR(CURRENT_DATE), DATE_FORMAT(`user_birthday`, '-%m-%d'))) AS `nearest_birthday`
149
+  if ($who == 1) {
150
+    if ($is_common_stat) { // , UNIX_TIMESTAMP(CONCAT(YEAR(CURRENT_DATE), DATE_FORMAT(`user_birthday`, '-%m-%d'))) AS `nearest_birthday`
151 151
       $query_str =
152 152
         "SELECT
153 153
       @rownum:=@rownum+1 rownum, subject.{$source['id']} as `id`, sp.{$Rank}_rank as rank, sp.{$Rank}_old_rank as rank_old, sp.{$Rank}_points as points, subject.{$source['username']} as `name`, subject.*
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
     ORDER BY
162 162
       sp.`{$Rank}_rank`, subject.{$source['id']}
163 163
     LIMIT
164
-      ". $start .",100;";
164
+      " . $start . ",100;";
165 165
     } else { // , UNIX_TIMESTAMP(CONCAT(YEAR(CURRENT_DATE), DATE_FORMAT(`user_birthday`, '-%m-%d'))) AS `nearest_birthday`
166 166
       $query_str =
167 167
         "SELECT
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
     ORDER BY
175 175
       subject.{$Rank} DESC, subject.{$source['id']}
176 176
     LIMIT
177
-      ". $start .",100;";
177
+      " . $start . ",100;";
178 178
     }
179 179
   } else {
180 180
     // TODO
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
   ORDER BY
192 192
     sp.`{$Rank}_rank`, subject.id
193 193
   LIMIT
194
-    ". $start .",100;";
194
+    " . $start . ",100;";
195 195
   }
196 196
 
197 197
   return doquery($query_str);
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
 function db_get_set_unique_id_value($current_value_unsafe, $db_id_field_name, $db_table_name, $db_value_field_name) {
278 278
   $current_value_safe = db_escape($current_value_unsafe);
279 279
   $value_id = doquery("SELECT `{$db_id_field_name}` AS id_field FROM {{{$db_table_name}}} WHERE `{$db_value_field_name}` = '{$current_value_safe}' LIMIT 1 FOR UPDATE", true);
280
-  if(!isset($value_id['id_field']) || !$value_id['id_field']) {
280
+  if (!isset($value_id['id_field']) || !$value_id['id_field']) {
281 281
     doquery("INSERT INTO {{{$db_table_name}}} (`{$db_value_field_name}`) VALUES ('{$current_value_safe}');");
282 282
     $variable_id = db_insert_id();
283 283
   } else {
Please login to merge, or discard this patch.
includes/db/db_helpers.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -27,19 +27,19 @@  discard block
 block discarded – undo
27 27
  */
28 28
 function db_set_make_safe_string($set, $delta = false) {
29 29
   $set_safe = array();
30
-  foreach($set as $field => $value) {
31
-    if(empty($field)) {
30
+  foreach ($set as $field => $value) {
31
+    if (empty($field)) {
32 32
       continue;
33 33
     }
34 34
 
35 35
     $field = '`' . db_escape($field) . '`';
36 36
     $new_value = $value;
37
-    if($value === null) {
37
+    if ($value === null) {
38 38
       $new_value = 'NULL';
39
-    } elseif(is_string($value) && (string)($new_value = floatval($value)) != (string)$value) {
39
+    } elseif (is_string($value) && (string) ($new_value = floatval($value)) != (string) $value) {
40 40
       // non-float
41 41
       $new_value = '"' . db_escape($value) . '"';
42
-    } elseif($delta) {
42
+    } elseif ($delta) {
43 43
       // float and DELTA-set
44 44
       $new_value = "{$field} + ({$new_value})";
45 45
     }
@@ -59,8 +59,8 @@  discard block
 block discarded – undo
59 59
  */
60 60
 function missile_list_convert_to_fleet(&$missile_db_list, &$fleet_db_list) {
61 61
   // Missile attack
62
-  foreach($missile_db_list as $irak) {
63
-    if($irak['fleet_end_time'] >= SN_TIME_NOW) {
62
+  foreach ($missile_db_list as $irak) {
63
+    if ($irak['fleet_end_time'] >= SN_TIME_NOW) {
64 64
       $irak['fleet_start_type'] = PT_PLANET;
65 65
       $planet_start = DBStaticPlanet::db_planet_by_vector($irak, 'fleet_start_', false, 'name');
66 66
       $irak['fleet_id'] = -$irak['id'];
Please login to merge, or discard this patch.