Completed
Push — work-fleets ( 77ad6e...489db6 )
by SuperNova.WS
06:17
created
includes/classes/sn_module_payment.php 1 patch
Spacing   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -448,7 +448,7 @@  discard block
 block discarded – undo
448 448
   public function compile_request($request) {
449 449
     global $user;
450 450
 
451
-    if(!(classSupernova::$auth->account instanceof Account)) {
451
+    if (!(classSupernova::$auth->account instanceof Account)) {
452 452
       // TODO - throw new Exception(lang['pay_msg_mm_request_amount_invalid'], SN_PAYMENT_REQUEST_ERROR_UNIT_AMOUNT);
453 453
     }
454 454
     $this->account = classSupernova::$auth->account;
@@ -469,15 +469,15 @@  discard block
 block discarded – undo
469 469
     $this->payment_currency = classSupernova::$config->payment_currency_default;
470 470
     $this->payment_amount = self::currency_convert($this->payment_dark_matter_paid, 'MM_', $this->payment_currency);
471 471
 
472
-    if(empty($this->payment_external_currency) && !empty($this->config['currency'])) {
472
+    if (empty($this->payment_external_currency) && !empty($this->config['currency'])) {
473 473
       $this->payment_external_currency = $this->config['currency'];
474 474
     }
475
-    if(empty($this->payment_external_currency)) {
475
+    if (empty($this->payment_external_currency)) {
476 476
       throw new Exception(classLocale::$lang['pay_error_internal_no_external_currency_set'], SN_PAYMENT_ERROR_INTERNAL_NO_EXTERNAL_CURRENCY_SET);
477 477
     }
478 478
 
479 479
     $this->payment_external_amount = self::currency_convert($this->payment_dark_matter_paid, 'MM_', $this->payment_external_currency);
480
-    if($this->payment_external_amount < 0.01) {
480
+    if ($this->payment_external_amount < 0.01) {
481 481
       throw new Exception(classLocale::$lang['pay_msg_mm_request_amount_invalid'], SN_PAYMENT_REQUEST_ERROR_UNIT_AMOUNT);
482 482
     }
483 483
 
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
     $this->generate_description();
487 487
 
488 488
     $this->db_insert();
489
-    if(!$this->is_exists) {
489
+    if (!$this->is_exists) {
490 490
       throw new Exception(classLocale::$lang['pay_msg_request_error_db_payment_create'], SN_PAYMENT_REQUEST_DB_ERROR_PAYMENT_CREATE);
491 491
     }
492 492
   }
@@ -498,26 +498,26 @@  discard block
 block discarded – undo
498 498
    * @throws Exception
499 499
    */
500 500
   protected function payment_request_process($options = array()) {
501
-    if(!$this->manifest['active']) {
501
+    if (!$this->manifest['active']) {
502 502
       throw new Exception(classLocale::$lang['pay_msg_module_disabled'], SN_MODULE_DISABLED);
503 503
     }
504 504
 
505 505
     // Если есть payment_id - загружаем под него данные
506
-    if(!empty($this->payment_params['payment_id'])) {
506
+    if (!empty($this->payment_params['payment_id'])) {
507 507
       $this->request_payment_id = sys_get_param_id($this->payment_params['payment_id']);
508
-      if(!$this->request_payment_id) {
508
+      if (!$this->request_payment_id) {
509 509
         throw new Exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_INTERNAL_ID_WRONG);
510 510
       }
511 511
 
512
-      if(!$this->db_get_by_id($this->request_payment_id)) {
512
+      if (!$this->db_get_by_id($this->request_payment_id)) {
513 513
         throw new Exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_INTERNAL_ID_WRONG);
514 514
       }
515 515
 
516 516
       // Проверяем - был ли этот платеж обработан?
517 517
       // TODO - Статусы бывают разные. Нужен спецфлаг payment_processed
518
-      if($this->payment_status != PAYMENT_STATUS_NONE) {
518
+      if ($this->payment_status != PAYMENT_STATUS_NONE) {
519 519
         sn_db_transaction_rollback();
520
-        sys_redirect(SN_ROOT_VIRTUAL . 'metamatter.php?payment_id=' . $this->payment_id);
520
+        sys_redirect(SN_ROOT_VIRTUAL.'metamatter.php?payment_id='.$this->payment_id);
521 521
         die();
522 522
       }
523 523
     }
@@ -525,89 +525,89 @@  discard block
 block discarded – undo
525 525
     // Пытаемся получить из запроса ИД аккаунта
526 526
     $request_account_id = !empty($this->payment_params['account_id']) ? sys_get_param_id($this->payment_params['account_id']) : 0;
527 527
     // Если в запросе нет ИД аккаунта - пытаемся использовать payment_account_id
528
-    if(empty($request_account_id) && !empty($this->payment_account_id)) {
528
+    if (empty($request_account_id) && !empty($this->payment_account_id)) {
529 529
       $request_account_id = $this->payment_account_id;
530 530
     }
531 531
     // Если теперь у нас нету ИД аккаунта ни в запросе, ни в записи таблицы - можно паниковать
532
-    if(empty($request_account_id)) {
532
+    if (empty($request_account_id)) {
533 533
       // TODO - аккаунт
534 534
       throw new Exception(classLocale::$lang['pay_msg_request_user_invalid'], $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options));
535 535
     }
536 536
     // Если нет записи в таблице - тогда берем payment_account_id из запроса
537
-    if(empty($this->payment_account_id)) {
537
+    if (empty($this->payment_account_id)) {
538 538
       $this->payment_account_id = $request_account_id;
539 539
     }
540 540
     // Если у нас отличаются ИД аккаунта в запросе и ИД аккаунта в записи - тоже можно паниковать
541
-    if($this->payment_account_id != $request_account_id) {
541
+    if ($this->payment_account_id != $request_account_id) {
542 542
       // TODO - Поменять сообщение об ошибке
543 543
       throw new Exception(classLocale::$lang['pay_msg_request_user_invalid'], $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options));
544 544
     }
545 545
     // Проверяем существование аккаунта с данным ИД
546
-    if(!$this->account->db_get_by_id($this->payment_account_id)) {
547
-      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));
546
+    if (!$this->account->db_get_by_id($this->payment_account_id)) {
547
+      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 548
     }
549 549
 
550 550
     // TODO Проверка на сервер_ид - как бы и не нужна, наверное?
551
-    if(!empty($this->payment_params['server_id'])) {
551
+    if (!empty($this->payment_params['server_id'])) {
552 552
       $this->request_server_id = sys_get_param_str($this->payment_params['server_id']);
553
-      if(SN_ROOT_VIRTUAL != $this->request_server_id) {
554
-        throw new Exception(classLocale::$lang['pay_msg_request_server_wrong'] . " {$this->request_server_id} вместо " . SN_ROOT_VIRTUAL, SN_PAYMENT_REQUEST_SERVER_WRONG);
553
+      if (SN_ROOT_VIRTUAL != $this->request_server_id) {
554
+        throw new Exception(classLocale::$lang['pay_msg_request_server_wrong']." {$this->request_server_id} вместо ".SN_ROOT_VIRTUAL, SN_PAYMENT_REQUEST_SERVER_WRONG);
555 555
       }
556 556
     }
557 557
 
558 558
     // Сверка количества оплаченной ММ с учётом бонусов
559
-    if(!empty($this->payment_params['payment_dark_matter_gained'])) {
559
+    if (!empty($this->payment_params['payment_dark_matter_gained'])) {
560 560
       $request_mm_amount = sys_get_param_id($this->payment_params['payment_dark_matter_gained']);
561
-      if($request_mm_amount != $this->payment_dark_matter_gained && $this->is_loaded) {
562
-        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);
561
+      if ($request_mm_amount != $this->payment_dark_matter_gained && $this->is_loaded) {
562
+        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 563
       }
564 564
       empty($this->payment_dark_matter_gained) ? $this->payment_dark_matter_gained = $request_mm_amount : false;
565 565
     }
566
-    if(empty($this->payment_dark_matter_paid)) {
566
+    if (empty($this->payment_dark_matter_paid)) {
567 567
       // TODO - обратный расчёт из gained
568 568
     }
569 569
 
570 570
     // Проверка наличия внешнего ИД платежа
571
-    if(!empty($this->payment_params['payment_external_id'])) {
571
+    if (!empty($this->payment_params['payment_external_id'])) {
572 572
       $request_payment_external_id = sys_get_param_id($this->payment_params['payment_external_id']);
573
-      if(empty($request_payment_external_id)) {
573
+      if (empty($request_payment_external_id)) {
574 574
         throw new exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_EXTERNAL_ID_WRONG);
575
-      } elseif(!empty($this->payment_external_id) && $this->payment_external_id != $request_payment_external_id) {
575
+      } elseif (!empty($this->payment_external_id) && $this->payment_external_id != $request_payment_external_id) {
576 576
         // TODO - Может быть поменять сообщение
577 577
         throw new exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_EXTERNAL_ID_WRONG);
578 578
       }
579 579
       $this->payment_external_id = $request_payment_external_id;
580 580
     }
581 581
     // Сверка суммы, запрошенной СН к оплате
582
-    if(!empty($this->payment_params['payment_external_money'])) {
582
+    if (!empty($this->payment_params['payment_external_money'])) {
583 583
       $request_money_out = sys_get_param_float($this->payment_params['payment_external_money']);
584
-      if($request_money_out != $this->payment_external_amount && $this->is_loaded) {
585
-        throw new Exception(classLocale::$lang['pay_msg_request_payment_amount_invalid'] . " пришло {$request_money_out} денег вместо {$this->payment_external_amount} денег", SN_PAYMENT_REQUEST_CURRENCY_AMOUNT_INVALID);
584
+      if ($request_money_out != $this->payment_external_amount && $this->is_loaded) {
585
+        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 586
       }
587 587
       empty($this->payment_external_amount) ? $this->payment_external_amount = $request_money_out : false;
588 588
     }
589 589
     // Заполняем поле валюты платёжной системы
590
-    if(!empty($this->payment_params['payment_external_currency'])) {
590
+    if (!empty($this->payment_params['payment_external_currency'])) {
591 591
       $this->payment_external_currency = sys_get_param_str($this->payment_params['payment_external_currency']);
592
-      if(empty($this->payment_external_currency)) {
592
+      if (empty($this->payment_external_currency)) {
593 593
         // TODO - поменять сообщение
594
-        throw new Exception(classLocale::$lang['pay_msg_request_payment_amount_invalid'] . " {$this->payment_external_currency}", SN_PAYMENT_REQUEST_CURRENCY_AMOUNT_INVALID);
594
+        throw new Exception(classLocale::$lang['pay_msg_request_payment_amount_invalid']." {$this->payment_external_currency}", SN_PAYMENT_REQUEST_CURRENCY_AMOUNT_INVALID);
595 595
       }
596 596
     }
597
-    if(empty($this->payment_external_currency)) {
597
+    if (empty($this->payment_external_currency)) {
598 598
       $this->payment_external_currency = $this->config['currency'];
599 599
     }
600 600
 
601 601
     // Заполнение внутренней суммы и валюты из внешних данных
602
-    if(empty($this->payment_currency)) {
602
+    if (empty($this->payment_currency)) {
603 603
       $this->payment_currency = classSupernova::$config->payment_currency_default;
604 604
     }
605
-    if(empty($this->payment_amount) && !empty($this->payment_external_currency)) {
605
+    if (empty($this->payment_amount) && !empty($this->payment_external_currency)) {
606 606
       $this->payment_amount = self::currency_convert($this->payment_external_amount, $this->payment_external_currency, $this->payment_currency);
607 607
     }
608 608
 
609 609
     // TODO - Тестовый режим
610
-    if(!empty($this->payment_params['test'])) {
610
+    if (!empty($this->payment_params['test'])) {
611 611
       $this->payment_test = $this->config['test'] || sys_get_param_int($this->payment_params['test']);
612 612
     }
613 613
 
@@ -634,21 +634,21 @@  discard block
 block discarded – undo
634 634
     sn_db_transaction_start();
635 635
     try {
636 636
       $response = $this->payment_request_process();
637
-    } catch(Exception $e) {
637
+    } catch (Exception $e) {
638 638
       $response['result'] = $e->getCode();
639 639
       $response['message'] = $e->getMessage();
640 640
     }
641 641
 
642
-    if($response['result'] == SN_PAYMENT_REQUEST_OK) {
642
+    if ($response['result'] == SN_PAYMENT_REQUEST_OK) {
643 643
       sn_db_transaction_commit();
644
-      classSupernova::$debug->warning('Результат операции: код ' . $response['result'] . ' сообщение "' . $response['message'] . '"', 'Успешный платёж', LOG_INFO_PAYMENT);
644
+      classSupernova::$debug->warning('Результат операции: код '.$response['result'].' сообщение "'.$response['message'].'"', 'Успешный платёж', LOG_INFO_PAYMENT);
645 645
     } else {
646 646
       sn_db_transaction_rollback();
647
-      classSupernova::$debug->warning('Результат операции: код ' . $response['result'] . ' сообщение "' . $response['message'] . '"', 'Ошибка платежа', LOG_INFO_PAYMENT, true);
647
+      classSupernova::$debug->warning('Результат операции: код '.$response['result'].' сообщение "'.$response['message'].'"', 'Ошибка платежа', LOG_INFO_PAYMENT, true);
648 648
     }
649 649
 
650 650
     // Переводим код результата из СН в код платежной системы
651
-    if(is_array($this->result_translations) && !empty($this->result_translations)) {
651
+    if (is_array($this->result_translations) && !empty($this->result_translations)) {
652 652
       $response['result'] = isset($this->result_translations[$response['result']]) ? $this->result_translations[$response['result']] : $this->result_translations[SN_PAYMENT_REQUEST_UNDEFINED_ERROR];
653 653
     }
654 654
 
@@ -671,7 +671,7 @@  discard block
 block discarded – undo
671 671
     $currency_from = strtolower($currency_from);
672 672
     $currency_to = strtolower($currency_to);
673 673
 
674
-    if($currency_from != $currency_to) {
674
+    if ($currency_from != $currency_to) {
675 675
       $exchange_from = get_exchange_rate($currency_from);
676 676
       $exchange_to = get_exchange_rate($currency_to);
677 677
 
@@ -695,10 +695,10 @@  discard block
 block discarded – undo
695 695
   public static function bonus_calculate($dark_matter, $direct = true, $return_bonus = false) {
696 696
     $bonus = 0;
697 697
     $dark_matter_new = $dark_matter;
698
-    if(!empty(self::$bonus_table) && $dark_matter >= self::$bonus_table[0]) {
699
-      if($direct) {
700
-        foreach(self::$bonus_table as $dm_for_bonus => $multiplier) {
701
-          if($dm_for_bonus <= $dark_matter) {
698
+    if (!empty(self::$bonus_table) && $dark_matter >= self::$bonus_table[0]) {
699
+      if ($direct) {
700
+        foreach (self::$bonus_table as $dm_for_bonus => $multiplier) {
701
+          if ($dm_for_bonus <= $dark_matter) {
702 702
             $dark_matter_new = $dark_matter * (1 + $multiplier);
703 703
             $bonus = $multiplier;
704 704
           } else {
@@ -706,9 +706,9 @@  discard block
 block discarded – undo
706 706
           }
707 707
         }
708 708
       } else {
709
-        foreach(self::$bonus_table as $dm_for_bonus => $multiplier) {
709
+        foreach (self::$bonus_table as $dm_for_bonus => $multiplier) {
710 710
           $temp = $dm_for_bonus * (1 + $multiplier);
711
-          if($dark_matter >= $temp) {
711
+          if ($dark_matter >= $temp) {
712 712
             $dark_matter_new = round($dark_matter / (1 + $multiplier));
713 713
             $bonus = $multiplier;
714 714
           } else {
@@ -762,22 +762,22 @@  discard block
 block discarded – undo
762 762
     );
763 763
 
764 764
     $replace = false;
765
-    if($this->payment_id) {
765
+    if ($this->payment_id) {
766 766
       $payment['payment_id'] = $this->payment_id;
767 767
       $replace = true;
768 768
     }
769 769
 
770 770
     $query = array();
771
-    foreach($payment as $key => $value) {
772
-      $value = is_string($value) ? '"' . db_escape($value) . '"' : $value;
771
+    foreach ($payment as $key => $value) {
772
+      $value = is_string($value) ? '"'.db_escape($value).'"' : $value;
773 773
       $query[] = "`{$key}` = {$value}";
774 774
     }
775 775
 
776
-    $longQuery = ' INTO `{{payment}}` SET ' . implode(',', $query) . ';';
777
-    if($replace) {
778
-      $this->db->doReplace('REPLACE' . $longQuery);
776
+    $longQuery = ' INTO `{{payment}}` SET '.implode(',', $query).';';
777
+    if ($replace) {
778
+      $this->db->doReplace('REPLACE'.$longQuery);
779 779
     } else {
780
-      $this->db->doInsert('INSERT' . $longQuery);
780
+      $this->db->doInsert('INSERT'.$longQuery);
781 781
     }
782 782
 
783 783
     return $this->db_get_by_id($this->db->db_insert_id());
@@ -785,12 +785,12 @@  discard block
 block discarded – undo
785 785
 
786 786
 
787 787
   public function payment_adjust_mm_new() {
788
-    if(!$this->payment_test) {
788
+    if (!$this->payment_test) {
789 789
       // Not a test payment. Adding DM to account
790 790
       $this->account = new Account($this->db);
791 791
       $this->account->db_get_by_id($this->payment_account_id);
792 792
       $result = $this->account->metamatter_change(RPG_PURCHASE, $this->payment_dark_matter_gained, $this->payment_comment);
793
-      if(!$result) {
793
+      if (!$result) {
794 794
         throw new Exception('Ошибка начисления ММ', SN_METAMATTER_ERROR_ADJUST);
795 795
       }
796 796
     }
@@ -799,25 +799,25 @@  discard block
 block discarded – undo
799 799
   public function payment_cancel(&$payment) {
800 800
     die('{НЕ РАБОТАЕТ! СООБЩИТЕ АДМИНИСТРАЦИИ!}');
801 801
 
802
-    if(!isset($payment['payment_status'])) {
802
+    if (!isset($payment['payment_status'])) {
803 803
       throw new exception(classLocale::$lang['pay_msg_request_payment_not_found'], SN_PAYMENT_REQUEST_ORDER_NOT_FOUND);
804 804
     }
805 805
 
806
-    if($payment['payment_status'] == PAYMENT_STATUS_COMPLETE) {
807
-      $safe_comment = db_escape($payment['payment_comment'] = classLocale::$lang['pay_msg_request_payment_cancelled'] .' ' . $payment['payment_comment']);
806
+    if ($payment['payment_status'] == PAYMENT_STATUS_COMPLETE) {
807
+      $safe_comment = db_escape($payment['payment_comment'] = classLocale::$lang['pay_msg_request_payment_cancelled'].' '.$payment['payment_comment']);
808 808
 
809
-      if(!$payment['payment_test']) {
809
+      if (!$payment['payment_test']) {
810 810
         $result = $this->account->metamatter_change(RPG_PURCHASE_CANCEL, -$payment['payment_dark_matter_gained'], $payment['payment_comment']);
811
-        if(!$result) {
811
+        if (!$result) {
812 812
           throw new exception('Ошибка начисления ММ', SN_METAMATTER_ERROR_ADJUST);
813 813
         }
814 814
       }
815 815
       $payment['payment_status'] = PAYMENT_STATUS_CANCELED;
816 816
       db_payment_update($payment, $safe_comment);
817 817
       throw new exception(classLocale::$lang['pay_msg_request_payment_cancel_complete'], SN_PAYMENT_REQUEST_OK);
818
-    } elseif($payment['payment_status'] == PAYMENT_STATUS_CANCELED) {
818
+    } elseif ($payment['payment_status'] == PAYMENT_STATUS_CANCELED) {
819 819
       throw new exception(classLocale::$lang['pay_msg_request_payment_cancelled_already'], SN_PAYMENT_REQUEST_OK);
820
-    } elseif($payment['payment_status'] == PAYMENT_STATUS_NONE) {
820
+    } elseif ($payment['payment_status'] == PAYMENT_STATUS_NONE) {
821 821
       throw new exception(classLocale::$lang['pay_msg_request_payment_cancel_not_complete'], SN_PAYMENT_REQUEST_PAYMENT_NOT_COMPLETE);
822 822
     }
823 823
   }
@@ -840,8 +840,8 @@  discard block
 block discarded – undo
840 840
 
841 841
   protected function db_complete_payment() {
842 842
     // TODO - поле payment_processed
843
-    if($this->payment_status == PAYMENT_STATUS_NONE) {
844
-      if(!defined('PAYMENT_EXPIRE_TIME') || PAYMENT_EXPIRE_TIME == 0 || empty($this->payment_date) || strtotime($this->payment_date) + PAYMENT_EXPIRE_TIME <= SN_TIME_NOW) {
843
+    if ($this->payment_status == PAYMENT_STATUS_NONE) {
844
+      if (!defined('PAYMENT_EXPIRE_TIME') || PAYMENT_EXPIRE_TIME == 0 || empty($this->payment_date) || strtotime($this->payment_date) + PAYMENT_EXPIRE_TIME <= SN_TIME_NOW) {
845 845
         $this->payment_adjust_mm_new();
846 846
         $this->payment_status = PAYMENT_STATUS_COMPLETE;
847 847
       } else {
@@ -888,7 +888,7 @@  discard block
 block discarded – undo
888 888
   protected function db_assign_payment($payment = null) {
889 889
     $this->payment_reset();
890 890
 
891
-    if(is_array($payment) && isset($payment['payment_id'])) {
891
+    if (is_array($payment) && isset($payment['payment_id'])) {
892 892
       $this->payment_id = $payment['payment_id'];
893 893
       $this->payment_status = $payment['payment_status'];
894 894
       $this->payment_date = $payment['payment_date'];
@@ -930,11 +930,11 @@  discard block
 block discarded – undo
930 930
   protected function generate_description() {
931 931
     // TODO - системная локализация
932 932
     $this->description_generated = array(
933
-      PAYMENT_DESCRIPTION_100 => substr("{$this->payment_dark_matter_gained} ММ аккаунт [{$this->account->account_name}] ID {$this->account->account_id} на " . SN_ROOT_VIRTUAL, 0, 100),
934
-      PAYMENT_DESCRIPTION_250 => substr("Оплата {$this->payment_dark_matter_gained} ММ для аккаунта [{$this->payment_user_name}] ID {$this->payment_user_id} на сервере " . SN_ROOT_VIRTUAL, 0, 250),
935
-      PAYMENT_DESCRIPTION_MAX => ($this->payment_test ? "ТЕСТОВЫЙ ПЛАТЕЖ! " : '') .
936
-        "Платеж от аккаунта '{$this->payment_account_name}' ID {$this->payment_account_id} игрока '{$this->payment_user_name}' ID {$this->payment_user_id} на сервере " . SN_ROOT_VIRTUAL .
937
-        " сумма {$this->payment_amount} {$this->payment_currency} за {$this->payment_dark_matter_paid} ММ (начислено {$this->payment_dark_matter_gained} ММ)" .
933
+      PAYMENT_DESCRIPTION_100 => substr("{$this->payment_dark_matter_gained} ММ аккаунт [{$this->account->account_name}] ID {$this->account->account_id} на ".SN_ROOT_VIRTUAL, 0, 100),
934
+      PAYMENT_DESCRIPTION_250 => substr("Оплата {$this->payment_dark_matter_gained} ММ для аккаунта [{$this->payment_user_name}] ID {$this->payment_user_id} на сервере ".SN_ROOT_VIRTUAL, 0, 250),
935
+      PAYMENT_DESCRIPTION_MAX => ($this->payment_test ? "ТЕСТОВЫЙ ПЛАТЕЖ! " : '').
936
+        "Платеж от аккаунта '{$this->payment_account_name}' ID {$this->payment_account_id} игрока '{$this->payment_user_name}' ID {$this->payment_user_id} на сервере ".SN_ROOT_VIRTUAL.
937
+        " сумма {$this->payment_amount} {$this->payment_currency} за {$this->payment_dark_matter_paid} ММ (начислено {$this->payment_dark_matter_gained} ММ)".
938 938
         " через '{$this->manifest['name']}' сумма {$this->payment_external_amount} {$this->payment_external_currency}",
939 939
     );
940 940
   }
Please login to merge, or discard this patch.
includes/classes/DBStaticNote.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
    * @param $note_id_edit
37 37
    */
38 38
   public static function db_note_update_by_id($note_priority, $note_title, $note_text, $note_galaxy, $note_system, $note_planet, $note_planet_type, $note_sticky, $note_id_edit) {
39
-    classSupernova::$db->doUpdate("UPDATE {{notes}} SET `time` = " . SN_TIME_NOW . ", `priority` = {$note_priority}, `title` = '{$note_title}', `text` = '{$note_text}',
39
+    classSupernova::$db->doUpdate("UPDATE {{notes}} SET `time` = ".SN_TIME_NOW.", `priority` = {$note_priority}, `title` = '{$note_title}', `text` = '{$note_text}',
40 40
         `galaxy` = {$note_galaxy}, `system` = {$note_system}, `planet` = {$note_planet}, `planet_type` = {$note_planet_type}, `sticky` = {$note_sticky}
41 41
         WHERE `id` = {$note_id_edit} LIMIT 1;");
42 42
   }
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
    * @param $note_sticky
54 54
    */
55 55
   public static function db_note_insert($user, $note_priority, $note_title, $note_text, $note_galaxy, $note_system, $note_planet, $note_planet_type, $note_sticky) {
56
-    classSupernova::$db->doInsert("INSERT INTO {{notes}} SET `owner` = {$user['id']}, `time` = " . SN_TIME_NOW . ", `priority` = {$note_priority}, `title` = '{$note_title}', `text` = '{$note_text}',
56
+    classSupernova::$db->doInsert("INSERT INTO {{notes}} SET `owner` = {$user['id']}, `time` = ".SN_TIME_NOW.", `priority` = {$note_priority}, `title` = '{$note_title}', `text` = '{$note_text}',
57 57
         `galaxy` = {$note_galaxy}, `system` = {$note_system}, `planet` = {$note_planet}, `planet_type` = {$note_planet_type}, `sticky` = {$note_sticky};");
58 58
   }
59 59
 
Please login to merge, or discard this patch.
includes/classes/DBAL/DbTransaction.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 
52 52
     if (!empty($error_msg)) {
53 53
       // TODO - Убрать позже
54
-      print('<h1>СООБЩИТЕ ЭТО АДМИНУ: sn_db_transaction_check() - ' . $error_msg . '</h1>');
54
+      print('<h1>СООБЩИТЕ ЭТО АДМИНУ: sn_db_transaction_check() - '.$error_msg.'</h1>');
55 55
       $backtrace = debug_backtrace();
56 56
       array_shift($backtrace);
57 57
       pdump($backtrace);
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
   public function start($level = '') {
65 65
     $this->check(null);
66 66
 
67
-    $level ? $this->db->doExecute('SET TRANSACTION ISOLATION LEVEL ' . $level) : false;
67
+    $level ? $this->db->doExecute('SET TRANSACTION ISOLATION LEVEL '.$level) : false;
68 68
 
69 69
     $this->transaction_id++;
70 70
     $this->db->doExecute('START TRANSACTION');
Please login to merge, or discard this patch.
includes/classes/DbRowDirectOperator.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
       ->setIdField($entity->getIdFieldName())
19 19
       ->field('*')
20 20
       ->from($entity->getTableName())
21
-      ->where($entity->getIdFieldName() . ' = "' . $entity->dbId . '"');
21
+      ->where($entity->getIdFieldName().' = "'.$entity->dbId.'"');
22 22
 
23 23
     return $stmt->selectRow();
24 24
   }
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
   public function deleteById($entity) {
30 30
     $db = $entity->getDbStatic();
31 31
 
32
-    $db->doDelete("DELETE FROM `{{" . $entity->getTableName() . "}}` WHERE `{$entity->getIdFieldName()}` = '{$entity->dbId}' LIMIT 1;");
32
+    $db->doDelete("DELETE FROM `{{".$entity->getTableName()."}}` WHERE `{$entity->getIdFieldName()}` = '{$entity->dbId}' LIMIT 1;");
33 33
 
34 34
     return $db->db_affected_rows();
35 35
   }
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
     $query = array();
44 44
     foreach ($entity->exportRowWithoutId() as $fieldName => $fieldValue) {
45 45
       // TODO: MORE type detection
46
-      if(!is_numeric($fieldValue)) {
47
-        $fieldValue = "'" . $db->db_escape($fieldValue) . "'";
46
+      if (!is_numeric($fieldValue)) {
47
+        $fieldValue = "'".$db->db_escape($fieldValue)."'";
48 48
       }
49 49
       $query[] = "`{$fieldName}` = {$fieldValue}";
50 50
     }
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
       return 0;
56 56
     }
57 57
 
58
-    $db->doInsert("INSERT INTO `{{" . $entity->getTableName() . "}}` SET " . $query);
58
+    $db->doInsert("INSERT INTO `{{".$entity->getTableName()."}}` SET ".$query);
59 59
 
60 60
     // TODO Exceptiion if db_insert_id() is empty
61 61
     return $entity->dbId = $db->db_insert_id();
Please login to merge, or discard this patch.
includes/classes/DBRow.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
    * @param db_mysql|null $db
87 87
    */
88 88
   public static function setDb($db = null) {
89
-    if(empty($db) || !($db instanceof db_mysql)) {
89
+    if (empty($db) || !($db instanceof db_mysql)) {
90 90
       $db = null;
91 91
     }
92 92
     static::$db = !empty($db) || !class_exists('classSupernova', false) ? $db : classSupernova::$db;
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
   public function dbLoad($dbId, $lockSkip = false) {
150 150
     $dbId = idval($dbId);
151 151
     if ($dbId <= 0) {
152
-      classSupernova::$debug->error(get_called_class() . '::' . __METHOD__ . ' $dbId not positive = ' . $dbId);
152
+      classSupernova::$debug->error(get_called_class().'::'.__METHOD__.' $dbId not positive = '.$dbId);
153 153
 
154 154
       return;
155 155
     }
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
       $this->dbGetLockById($this->_dbId);
162 162
     }
163 163
 
164
-    $db_row = classSupernova::$db->doSelectFetch("SELECT * FROM `{{" . static::$_table . "}}` WHERE `" . static::$_dbIdFieldName . "` = " . $this->_dbId . " LIMIT 1 FOR UPDATE;");
164
+    $db_row = classSupernova::$db->doSelectFetch("SELECT * FROM `{{".static::$_table."}}` WHERE `".static::$_dbIdFieldName."` = ".$this->_dbId." LIMIT 1 FOR UPDATE;");
165 165
     if (empty($db_row)) {
166 166
       return;
167 167
     }
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
     if ($this->isNew()) {
194 194
       // No DB_ID - new unit
195 195
       if ($this->isEmpty()) {
196
-        classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - object is empty on ' . get_called_class() . '::dbSave');
196
+        classSupernova::$debug->error(__FILE__.':'.__LINE__.' - object is empty on '.get_called_class().'::dbSave');
197 197
       }
198 198
       $this->dbInsert();
199 199
     } else {
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
         $this->dbDelete();
203 203
       } else {
204 204
         if (!sn_db_transaction_check(false)) {
205
-          classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - transaction should always be started on ' . get_called_class() . '::dbUpdate');
205
+          classSupernova::$debug->error(__FILE__.':'.__LINE__.' - transaction should always be started on '.get_called_class().'::dbUpdate');
206 206
         }
207 207
         $this->dbUpdate();
208 208
       }
@@ -230,12 +230,12 @@  discard block
 block discarded – undo
230 230
   // TODO - protected
231 231
   public function dbInsert() {
232 232
     if (!$this->isNew()) {
233
-      classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - record db_id is not empty on ' . get_called_class() . '::dbInsert');
233
+      classSupernova::$debug->error(__FILE__.':'.__LINE__.' - record db_id is not empty on '.get_called_class().'::dbInsert');
234 234
     }
235 235
     $this->_dbId = $this->db_field_set_create($this->dbMakeFieldSet());
236 236
 
237 237
     if (empty($this->_dbId)) {
238
-      classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - error saving record ' . get_called_class() . '::dbInsert');
238
+      classSupernova::$debug->error(__FILE__.':'.__LINE__.' - error saving record '.get_called_class().'::dbInsert');
239 239
     }
240 240
 
241 241
     return $this->_dbId;
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
   public function dbUpdate() {
249 249
     // TODO - Update
250 250
     if ($this->isNew()) {
251
-      classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - unit db_id is empty on dbUpdate');
251
+      classSupernova::$debug->error(__FILE__.':'.__LINE__.' - unit db_id is empty on dbUpdate');
252 252
     }
253 253
     $this->db_field_update($this->dbMakeFieldSet(true));
254 254
   }
@@ -259,9 +259,9 @@  discard block
 block discarded – undo
259 259
   // TODO - protected
260 260
   public function dbDelete() {
261 261
     if ($this->isNew()) {
262
-      classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - unit db_id is empty on dbDelete');
262
+      classSupernova::$debug->error(__FILE__.':'.__LINE__.' - unit db_id is empty on dbDelete');
263 263
     }
264
-    classSupernova::$db->doDelete("DELETE FROM `{{" . static::$_table . "}}` WHERE `" . static::$_dbIdFieldName . "` = " . $this->_dbId);
264
+    classSupernova::$db->doDelete("DELETE FROM `{{".static::$_table."}}` WHERE `".static::$_dbIdFieldName."` = ".$this->_dbId);
265 265
     $this->_dbId = 0;
266 266
     // Обо всём остальном должен позаботиться контейнер
267 267
   }
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
     $fields = implode(',', array_keys($field_set));
415 415
 
416 416
     $result = 0;
417
-    if (classSupernova::$db->doInsert("INSERT INTO `{{" . static::$_table . "}}` ({$fields}) VALUES ({$values});")) {
417
+    if (classSupernova::$db->doInsert("INSERT INTO `{{".static::$_table."}}` ({$fields}) VALUES ({$values});")) {
418 418
       $result = classSupernova::$db->db_insert_id();
419 419
     }
420 420
 
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
 
451 451
     return empty($set_string)
452 452
       ? true
453
-      : classSupernova::$db->doUpdate("UPDATE `{{" . static::$_table . "}}` SET {$set_string} WHERE `" . static::$_dbIdFieldName . "` = " . $this->_dbId);
453
+      : classSupernova::$db->doUpdate("UPDATE `{{".static::$_table."}}` SET {$set_string} WHERE `".static::$_dbIdFieldName."` = ".$this->_dbId);
454 454
   }
455 455
 
456 456
 }
Please login to merge, or discard this patch.
includes/classes/DBStaticAlly.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -66,9 +66,9 @@  discard block
 block discarded – undo
66 66
     `ally_name` = '{$ally_name}',
67 67
     `ally_tag` = '{$ally_tag}',
68 68
     `ally_owner` = '{$user['id']}',
69
-    `ally_owner_range` = '" . classLocale::$lang['ali_leaderRank'] . "',
69
+    `ally_owner_range` = '".classLocale::$lang['ali_leaderRank']."',
70 70
     `ally_members` = 1,
71
-    `ranklist` = '" . classLocale::$lang['ali_defaultRankName'] . ",0,0,0,0,0',
71
+    `ranklist` = '" . classLocale::$lang['ali_defaultRankName'].",0,0,0,0,0',
72 72
     `ally_register_time`= " . SN_TIME_NOW
73 73
     );
74 74
 
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
    * @param $POST_text
90 90
    */
91 91
   public static function db_ally_request_insert($user, $id_ally, $POST_text) {
92
-    classSupernova::$db->doInsert("INSERT INTO {{alliance_requests}} SET `id_user` = {$user['id']}, `id_ally`='{$id_ally}', request_text ='{$POST_text}', request_time=" . SN_TIME_NOW . ";");
92
+    classSupernova::$db->doInsert("INSERT INTO {{alliance_requests}} SET `id_user` = {$user['id']}, `id_ally`='{$id_ally}', request_text ='{$POST_text}', request_time=".SN_TIME_NOW.";");
93 93
   }
94 94
 
95 95
   /**
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
    * @param $ally
140 140
    */
141 141
   public static function db_ally_update_by_changeset($ally_changeset, $ally) {
142
-    classSupernova::$db->doUpdate("UPDATE {{alliance}} SET " . implode(',', $ally_changeset) . " WHERE `id`='{$ally['id']}' LIMIT 1;");
142
+    classSupernova::$db->doUpdate("UPDATE {{alliance}} SET ".implode(',', $ally_changeset)." WHERE `id`='{$ally['id']}' LIMIT 1;");
143 143
   }
144 144
 
145 145
   /**
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
    * @param $d
251 251
    */
252 252
   public static function db_ally_request_deny($d) {
253
-    classSupernova::$db->doUpdate("UPDATE {{alliance_requests}} SET `request_denied` = 1, `request_text` = '" . classLocale::$lang['ali_req_deny_reason'] . "' WHERE `id_user`= {$d} LIMIT 1;");
253
+    classSupernova::$db->doUpdate("UPDATE {{alliance_requests}} SET `request_denied` = 1, `request_text` = '".classLocale::$lang['ali_req_deny_reason']."' WHERE `id_user`= {$d} LIMIT 1;");
254 254
   }
255 255
 
256 256
   /**
Please login to merge, or discard this patch.
includes/classes/DBStaticChat.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
       JOIN {{users}} AS u ON u.id = cp.chat_player_player_id
13 13
     WHERE
14 14
       `chat_player_refresh_last` >= '{$sql_date}'
15
-      AND (`banaday` IS NULL OR `banaday` <= " . SN_TIME_NOW . ")
15
+      AND (`banaday` IS NULL OR `banaday` <= ".SN_TIME_NOW.")
16 16
       {$ally_add}
17 17
     ORDER BY authlevel DESC, `username`");
18 18
   }
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
           `user` = '{$nick}',
36 36
           `ally_id` = '{$ally_id}',
37 37
           `message` = '{$message}',
38
-          `timestamp` = " . SN_TIME_NOW . ",
38
+          `timestamp` = ".SN_TIME_NOW.",
39 39
           `chat_message_sender_name` = '{$chat_message_sender_name}',
40 40
           `chat_message_recipient_id` = {$chat_message_recipient_id},
41 41
           `chat_message_recipient_name` = '{$chat_message_recipient_name}'"
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
    * @param $user
142 142
    */
143 143
   public static function db_chat_player_update($user) {
144
-    classSupernova::$db->doUpdate("UPDATE {{chat_player}} SET `chat_player_refresh_last` = " . SN_TIME_NOW . " WHERE `chat_player_player_id` = {$user['id']} LIMIT 1;");
144
+    classSupernova::$db->doUpdate("UPDATE {{chat_player}} SET `chat_player_refresh_last` = ".SN_TIME_NOW." WHERE `chat_player_player_id` = {$user['id']} LIMIT 1;");
145 145
   }
146 146
 
147 147
 
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
    * @param $user
213 213
    */
214 214
   public static function db_chat_player_update_activity($user) {
215
-    classSupernova::$db->doUpdate("UPDATE {{chat_player}} SET `chat_player_activity` = '" . classSupernova::$db->db_escape(SN_TIME_SQL) . "' WHERE `chat_player_player_id` = {$user['id']} LIMIT 1");
215
+    classSupernova::$db->doUpdate("UPDATE {{chat_player}} SET `chat_player_activity` = '".classSupernova::$db->db_escape(SN_TIME_SQL)."' WHERE `chat_player_player_id` = {$user['id']} LIMIT 1");
216 216
   }
217 217
 
218 218
 }
219 219
\ No newline at end of file
Please login to merge, or discard this patch.
includes/classes/DBStaticFleetMissile.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@
 block discarded – undo
23 23
    * @return array|bool|mysqli_result|null
24 24
    */
25 25
   public static function db_missile_list_by_arrival() {
26
-    $iraks = classSupernova::$db->doSelect("SELECT * FROM `{{iraks}}` WHERE `fleet_end_time` <= " . SN_TIME_NOW . " FOR UPDATE;");
26
+    $iraks = classSupernova::$db->doSelect("SELECT * FROM `{{iraks}}` WHERE `fleet_end_time` <= ".SN_TIME_NOW." FOR UPDATE;");
27 27
 
28 28
     return $iraks;
29 29
   }
Please login to merge, or discard this patch.
includes/classes/classLocale.php 1 patch
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -35,13 +35,13 @@  discard block
 block discarded – undo
35 35
 
36 36
     $this->container = array();
37 37
 
38
-    if(classSupernova::$cache->_MODE != CACHER_NO_CACHE && !classSupernova::$config->locale_cache_disable) {
38
+    if (classSupernova::$cache->_MODE != CACHER_NO_CACHE && !classSupernova::$config->locale_cache_disable) {
39 39
       $this->cache = classSupernova::$cache;
40 40
       classSupernova::log_file('locale.__constructor: Cache is present');
41 41
 //$this->cache->unset_by_prefix($this->cache_prefix); // TODO - remove? 'cause debug!
42 42
     }
43 43
 
44
-    if($enable_stat_usage && empty($this->stat_usage)) {
44
+    if ($enable_stat_usage && empty($this->stat_usage)) {
45 45
       $this->enable_stat_usage = $enable_stat_usage;
46 46
       $this->usage_stat_load();
47 47
       // TODO shutdown function
@@ -67,18 +67,18 @@  discard block
 block discarded – undo
67 67
     unset($fallback[$this->active]);
68 68
 
69 69
     // Проходим по оставшимся локалям
70
-    foreach($fallback as $try_language) {
70
+    foreach ($fallback as $try_language) {
71 71
       // Если нет такой строки - пытаемся вытащить из кэша
72
-      if(!isset($this->container[$try_language][$offset]) && $this->cache) {
73
-        $this->container[$try_language][$offset] = $this->cache->__get($this->cache_prefix . $try_language . '_' . $offset);
72
+      if (!isset($this->container[$try_language][$offset]) && $this->cache) {
73
+        $this->container[$try_language][$offset] = $this->cache->__get($this->cache_prefix.$try_language.'_'.$offset);
74 74
 // Записываем результат работы кэша
75 75
 $locale_cache_statistic['queries']++;
76 76
 isset($this->container[$try_language][$offset]) ? $locale_cache_statistic['hits']++ : $locale_cache_statistic['misses']++;
77
-!isset($this->container[$try_language][$offset]) ? $locale_cache_statistic['missed_str'][] = $this->cache_prefix . $try_language . '_' . $offset : false;
77
+!isset($this->container[$try_language][$offset]) ? $locale_cache_statistic['missed_str'][] = $this->cache_prefix.$try_language.'_'.$offset : false;
78 78
       }
79 79
 
80 80
       // Если мы как-то где-то нашли строку...
81
-      if(isset($this->container[$try_language][$offset])) {
81
+      if (isset($this->container[$try_language][$offset])) {
82 82
         // ...значит она получена в результате фоллбэка и записываем её в кэш и контейнер
83 83
         $this[$offset] = $this->container[$try_language][$offset];
84 84
         $locale_cache_statistic['fallbacks']++;
@@ -94,16 +94,16 @@  discard block
 block discarded – undo
94 94
       $this->container[$this->active][] = $value;
95 95
     } else {
96 96
       $this->container[$this->active][$offset] = $value;
97
-      if($this->cache) {
98
-        $this->cache->__set($this->cache_prefix_lang . $offset, $value);
97
+      if ($this->cache) {
98
+        $this->cache->__set($this->cache_prefix_lang.$offset, $value);
99 99
       }
100 100
     }
101 101
   }
102 102
   public function offsetExists($offset) {
103 103
     // Шорткат если у нас уже есть строка в памяти PHP
104
-    if(!isset($this->container[$this->active][$offset])) {
104
+    if (!isset($this->container[$this->active][$offset])) {
105 105
 //        pdump($this->cache_prefix_lang . $offset);
106
-      if(!$this->cache || !($this->container[$this->active][$offset] = $this->cache->__get($this->cache_prefix_lang . $offset))) {
106
+      if (!$this->cache || !($this->container[$this->active][$offset] = $this->cache->__get($this->cache_prefix_lang.$offset))) {
107 107
 //        pdump($this->cache_prefix_lang . $offset);
108 108
         // Если нету такой строки - делаем фоллбэк
109 109
         $this->locale_string_fallback($offset);
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
   }
120 120
   public function offsetGet($offset) {
121 121
     $value = $this->offsetExists($offset) ? $this->container[$this->active][$offset] : null;
122
-    if($this->enable_stat_usage) {
122
+    if ($this->enable_stat_usage) {
123 123
       $this->usage_stat_log($offset, $value);
124 124
     }
125 125
     return $value;
@@ -134,25 +134,25 @@  discard block
 block discarded – undo
134 134
 
135 135
 
136 136
   public function usage_stat_load() {
137
-    $this->stat_usage = classSupernova::$cache->lng_stat_usage  = array(); // TODO for debug
138
-    if(empty($this->stat_usage)) {
137
+    $this->stat_usage = classSupernova::$cache->lng_stat_usage = array(); // TODO for debug
138
+    if (empty($this->stat_usage)) {
139 139
       $query = classSupernova::$db->doSelect("SELECT * FROM `{{lng_usage_stat}}`");
140
-      while($row = db_fetch($query)) {
141
-        $this->stat_usage[$row['lang_code'] . ':' . $row['string_id'] . ':' . $row['file'] . ':' . $row['line']] = $row['is_empty'];
140
+      while ($row = db_fetch($query)) {
141
+        $this->stat_usage[$row['lang_code'].':'.$row['string_id'].':'.$row['file'].':'.$row['line']] = $row['is_empty'];
142 142
       }
143 143
     }
144 144
   }
145 145
   public function usage_stat_save() {
146
-    if(!empty($this->stat_usage_new)) {
146
+    if (!empty($this->stat_usage_new)) {
147 147
       classSupernova::$cache->lng_stat_usage = $this->stat_usage;
148 148
       classSupernova::$db->doSelect("SELECT 1 FROM `{{lng_usage_stat}}` LIMIT 1");
149
-      foreach($this->stat_usage_new as &$value) {
150
-        foreach($value as &$value2) {
151
-          $value2 = '"' . db_escape($value2) . '"';
149
+      foreach ($this->stat_usage_new as &$value) {
150
+        foreach ($value as &$value2) {
151
+          $value2 = '"'.db_escape($value2).'"';
152 152
         }
153
-        $value = '(' . implode(',', $value) .')';
153
+        $value = '('.implode(',', $value).')';
154 154
       }
155
-      classSupernova::$db->doReplace("REPLACE INTO `{{lng_usage_stat}}` (lang_code,string_id,`file`,line,is_empty,locale) VALUES " . implode(',', $this->stat_usage_new));
155
+      classSupernova::$db->doReplace("REPLACE INTO `{{lng_usage_stat}}` (lang_code,string_id,`file`,line,is_empty,locale) VALUES ".implode(',', $this->stat_usage_new));
156 156
     }
157 157
   }
158 158
   public function usage_stat_log(&$offset, &$value) {
@@ -162,8 +162,8 @@  discard block
 block discarded – undo
162 162
 
163 163
     $file = str_replace('\\', '/', substr($trace[1]['file'], strlen(SN_ROOT_PHYSICAL) - 1));
164 164
 
165
-    $string_id = $this->active . ':' . $offset . ':' . $file . ':' . $trace[1]['line'];
166
-    if(!isset($this->stat_usage[$string_id]) || $this->stat_usage[$string_id] != empty($value)) {
165
+    $string_id = $this->active.':'.$offset.':'.$file.':'.$trace[1]['line'];
166
+    if (!isset($this->stat_usage[$string_id]) || $this->stat_usage[$string_id] != empty($value)) {
167 167
       $this->stat_usage[$string_id] = empty($value);
168 168
       $this->stat_usage_new[] = array(
169 169
         'lang_code' => $this->active,
@@ -171,14 +171,14 @@  discard block
 block discarded – undo
171 171
         'file' => $file,
172 172
         'line' => $trace[1]['line'],
173 173
         'is_empty' => intval(empty($value)),
174
-        'locale' => '' . $value,
174
+        'locale' => ''.$value,
175 175
       );
176 176
     }
177 177
   }
178 178
 
179 179
 
180 180
   protected function lng_try_filepath($path, $file_path_relative) {
181
-    $file_path = SN_ROOT_PHYSICAL . ($path && file_exists(SN_ROOT_PHYSICAL . $path . $file_path_relative) ? $path : '') . $file_path_relative;
181
+    $file_path = SN_ROOT_PHYSICAL.($path && file_exists(SN_ROOT_PHYSICAL.$path.$file_path_relative) ? $path : '').$file_path_relative;
182 182
     return file_exists($file_path) ? $file_path : false;
183 183
   }
184 184
 
@@ -200,14 +200,14 @@  discard block
 block discarded – undo
200 200
 
201 201
     classSupernova::log_file("locale.include: Loading data from domain '{$filename}'", 1);
202 202
 
203
-    $cache_file_key = $this->cache_prefix_lang . '__' . $filename;
203
+    $cache_file_key = $this->cache_prefix_lang.'__'.$filename;
204 204
 
205 205
     // Подключен ли внешний кэш?
206
-    if($this->cache) {
206
+    if ($this->cache) {
207 207
       // Загружен ли уже данный файл?
208 208
       $cache_file_status = $this->cache->__get($cache_file_key);
209
-      classSupernova::log_file("locale.include: Cache - '{$filename}' has key '{$cache_file_key}' and is " . ($cache_file_status ? 'already loaded - EXIT' : 'EMPTY'), $cache_file_status ? -1 : 0);
210
-      if($cache_file_status) {
209
+      classSupernova::log_file("locale.include: Cache - '{$filename}' has key '{$cache_file_key}' and is ".($cache_file_status ? 'already loaded - EXIT' : 'EMPTY'), $cache_file_status ? -1 : 0);
210
+      if ($cache_file_status) {
211 211
         // Если да - повторять загрузку нет смысла
212 212
         return null;
213 213
       }
@@ -221,47 +221,47 @@  discard block
 block discarded – undo
221 221
     $this->make_fallback($language);
222 222
 
223 223
     $file_path = '';
224
-    foreach($this->fallback as $lang_try) {
225
-      if(!$lang_try /* || isset($language_tried[$lang_try]) */) {
224
+    foreach ($this->fallback as $lang_try) {
225
+      if (!$lang_try /* || isset($language_tried[$lang_try]) */) {
226 226
         continue;
227 227
       }
228 228
 
229
-      if($file_path = $this->lng_try_filepath($path, "language/{$lang_try}/{$filename_ext}")) {
229
+      if ($file_path = $this->lng_try_filepath($path, "language/{$lang_try}/{$filename_ext}")) {
230 230
         break;
231 231
       }
232 232
 
233
-      if($file_path = $this->lng_try_filepath($path, "language/{$filename}_{$lang_try}{$ext}")) {
233
+      if ($file_path = $this->lng_try_filepath($path, "language/{$filename}_{$lang_try}{$ext}")) {
234 234
         break;
235 235
       }
236 236
 
237 237
       $file_path = '';
238 238
     }
239 239
 
240
-    if($file_path) {
240
+    if ($file_path) {
241 241
       $a_lang_array = array();
242 242
       include($file_path);
243 243
 
244
-      if(!empty($a_lang_array)) {
244
+      if (!empty($a_lang_array)) {
245 245
         $this->merge($a_lang_array);
246 246
 
247 247
         // Загрузка данных из файла в кэш
248
-        if($this->cache) {
248
+        if ($this->cache) {
249 249
           classSupernova::log_file("Locale: loading '{$filename}' into cache");
250
-          foreach($a_lang_array as $key => $value) {
251
-            $value_cache_key = $this->cache_prefix_lang . $key;
252
-            if($this->cache->__isset($value_cache_key)) {
253
-              if(is_array($value)) {
250
+          foreach ($a_lang_array as $key => $value) {
251
+            $value_cache_key = $this->cache_prefix_lang.$key;
252
+            if ($this->cache->__isset($value_cache_key)) {
253
+              if (is_array($value)) {
254 254
                 $alt_value = $this->cache->__get($value_cache_key);
255 255
                 $value = array_replace_recursive($alt_value, $value);
256 256
                 // pdump($alt_value, $alt_value);
257 257
               }
258 258
             }
259
-            $this->cache->__set($this->cache_prefix_lang . $key, $value);
259
+            $this->cache->__set($this->cache_prefix_lang.$key, $value);
260 260
           }
261 261
         }
262 262
       }
263 263
 
264
-      if($this->cache) {
264
+      if ($this->cache) {
265 265
         $this->cache->__set($cache_file_key, true);
266 266
       }
267 267
 
@@ -274,14 +274,14 @@  discard block
 block discarded – undo
274 274
   }
275 275
 
276 276
   public function lng_load_i18n($i18n) {
277
-    if(!isset($i18n)) {
277
+    if (!isset($i18n)) {
278 278
       return;
279 279
     }
280 280
 
281
-    foreach($i18n as $i18n_data) {
282
-      if(is_string($i18n_data)) {
281
+    foreach ($i18n as $i18n_data) {
282
+      if (is_string($i18n_data)) {
283 283
         $this->lng_include($i18n_data);
284
-      } elseif(is_array($i18n_data)) {
284
+      } elseif (is_array($i18n_data)) {
285 285
         $this->lng_include($i18n_data['file'], $i18n_data['path']);
286 286
       }
287 287
     }
@@ -299,27 +299,27 @@  discard block
 block discarded – undo
299 299
 
300 300
     classSupernova::log_file("locale.switch: Trying to switch language to '{$language_new}'");
301 301
 
302
-    if($language_new == $this->active) {
302
+    if ($language_new == $this->active) {
303 303
       classSupernova::log_file("locale.switch: New language '{$language_new}' is equal to current language '{$this->active}' - EXIT", -1);
304 304
       return false;
305 305
     }
306 306
 
307 307
     $this->active = $language = $language_new;
308
-    $this->cache_prefix_lang = $this->cache_prefix . $this->active . '_';
308
+    $this->cache_prefix_lang = $this->cache_prefix.$this->active.'_';
309 309
 
310 310
     $this['LANG_INFO'] = $this->lng_get_info($this->active);
311 311
     $this->make_fallback($this->active);
312 312
 
313
-    if($this->cache) {
314
-      $cache_lang_init_status = $this->cache->__get($this->cache_prefix_lang . '__INIT');
315
-      classSupernova::log_file("locale.switch: Cache for '{$this->active}' prefixed '{$this->cache_prefix_lang}' is " . ($cache_lang_init_status ? 'already loaded. Doing nothing - EXIT' : 'EMPTY'), $cache_lang_init_status ? -1 : 0);
316
-      if($cache_lang_init_status) {
313
+    if ($this->cache) {
314
+      $cache_lang_init_status = $this->cache->__get($this->cache_prefix_lang.'__INIT');
315
+      classSupernova::log_file("locale.switch: Cache for '{$this->active}' prefixed '{$this->cache_prefix_lang}' is ".($cache_lang_init_status ? 'already loaded. Doing nothing - EXIT' : 'EMPTY'), $cache_lang_init_status ? -1 : 0);
316
+      if ($cache_lang_init_status) {
317 317
         return false;
318 318
       }
319 319
 
320 320
       // Чистим текущие локализации из кэша. Достаточно почистить только флаги инициализации языкового кэша и загрузки файлов - они начинаются с '__'
321 321
       classSupernova::log_file("locale.switch: Cache - invalidating data");
322
-      $this->cache->unset_by_prefix($this->cache_prefix_lang . '__');
322
+      $this->cache->unset_by_prefix($this->cache_prefix_lang.'__');
323 323
     }
324 324
 
325 325
     $this->lng_include('system');
@@ -329,9 +329,9 @@  discard block
 block discarded – undo
329 329
     // Loading global language files
330 330
     $this->lng_load_i18n(classSupernova::$sn_mvc['i18n']['']);
331 331
 
332
-    if($this->cache) {
333
-      classSupernova::log_file("locale.switch: Cache - setting flag " . $this->cache_prefix_lang . '__INIT');
334
-      $this->cache->__set($this->cache_prefix_lang . '__INIT', true);
332
+    if ($this->cache) {
333
+      classSupernova::log_file("locale.switch: Cache - setting flag ".$this->cache_prefix_lang.'__INIT');
334
+      $this->cache->__set($this->cache_prefix_lang.'__INIT', true);
335 335
     }
336 336
 
337 337
     classSupernova::log_file("locale.switch: Complete - EXIT");
@@ -341,9 +341,9 @@  discard block
 block discarded – undo
341 341
 
342 342
 
343 343
   public function lng_get_info($entry) {
344
-    $file_name = SN_ROOT_PHYSICAL . 'language/' . $entry . '/language.mo.php';
344
+    $file_name = SN_ROOT_PHYSICAL.'language/'.$entry.'/language.mo.php';
345 345
     $lang_info = array();
346
-    if(file_exists($file_name)) {
346
+    if (file_exists($file_name)) {
347 347
       include($file_name);
348 348
     }
349 349
 
@@ -351,15 +351,15 @@  discard block
 block discarded – undo
351 351
   }
352 352
 
353 353
   public function lng_get_list() {
354
-    if(empty($this->lang_list)) {
354
+    if (empty($this->lang_list)) {
355 355
       $this->lang_list = array();
356 356
 
357
-      $path = SN_ROOT_PHYSICAL . 'language/';
357
+      $path = SN_ROOT_PHYSICAL.'language/';
358 358
       $dir = dir($path);
359
-      while(false !== ($entry = $dir->read())) {
360
-        if(is_dir($path . $entry) && $entry[0] != '.') {
359
+      while (false !== ($entry = $dir->read())) {
360
+        if (is_dir($path.$entry) && $entry[0] != '.') {
361 361
           $lang_info = $this->lng_get_info($entry);
362
-          if($lang_info['LANG_NAME_ISO2'] == $entry) {
362
+          if ($lang_info['LANG_NAME_ISO2'] == $entry) {
363 363
             $this->lang_list[$lang_info['LANG_NAME_ISO2']] = $lang_info;
364 364
           }
365 365
         }
Please login to merge, or discard this patch.