Test Failed
Branch v5 (12d602)
by Alexey
04:51
created
system/Inji/Log.php 1 patch
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -89,6 +89,9 @@
 block discarded – undo
89 89
         App::$cur->log->forceView = $bool;
90 90
     }
91 91
 
92
+    /**
93
+     * @param integer $size
94
+     */
92 95
     public function convertSize($size) {
93 96
 
94 97
         if ($size < 1024) {
Please login to merge, or discard this patch.
system/modules/Migrations/objects/Parser/Object.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -112,7 +112,7 @@
 block discarded – undo
112 112
                     $deleteIf = json_decode($this->object->delete_empty, true);
113 113
                     foreach ($deleteIf['params'] as $paramId) {
114 114
                         if ($model->{$this->object->params[$paramId]->value} === '') {
115
-                            if($model->pk()){
115
+                            if ($model->pk()) {
116 116
                                 $model->delete();
117 117
                             }
118 118
                             return 0;
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -112,7 +112,7 @@
 block discarded – undo
112 112
                     $deleteIf = json_decode($this->object->delete_empty, true);
113 113
                     foreach ($deleteIf['params'] as $paramId) {
114 114
                         if ($model->{$this->object->params[$paramId]->value} === '') {
115
-                            if($model->pk()){
115
+                            if($model->pk()) {
116 116
                                 $model->delete();
117 117
                             }
118 118
                             return 0;
Please login to merge, or discard this patch.
system/modules/Ecommerce/widgets/formInputs/cdekChooser.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
                 </div>
49 49
                 <script>
50 50
                   inji.onLoad(function () {
51
-                    inji.Ui.customSelect.bind($('#<?=$id;?>'));
51
+                    inji.Ui.customSelect.bind($('#<?=$id; ?>'));
52 52
                   })
53 53
                 </script>
54 54
                 <?php
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
         }
59 59
     }
60 60
     else {
61
-        echo '<b>Заполните поле: '.$field->name.'</b>';
61
+        echo '<b>Заполните поле: ' . $field->name . '</b>';
62 62
     }
63 63
     ?>
64 64
 </div>
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -56,8 +56,7 @@
 block discarded – undo
56 56
                 echo '<b>Заполните поле: Город</b>';
57 57
             }
58 58
         }
59
-    }
60
-    else {
59
+    } else {
61 60
         echo '<b>Заполните поле: '.$field->name.'</b>';
62 61
     }
63 62
     ?>
Please login to merge, or discard this patch.
system/modules/Geography/objects/SxGeo.php 4 patches
Doc Comments   +12 added lines patch added patch discarded remove patch
@@ -92,6 +92,11 @@  discard block
 block discarded – undo
92 92
 		$this->info['cities_begin']  = $this->info['regions_begin'] + $info['region_size'];
93 93
 	}
94 94
 
95
+	/**
96
+	 * @param string $ipn
97
+	 * @param double $min
98
+	 * @param double $max
99
+	 */
95 100
 	protected function search_idx($ipn, $min, $max){
96 101
 		if($this->batch_mode){
97 102
 			while($max - $min > 8){
@@ -112,6 +117,10 @@  discard block
 block discarded – undo
112 117
 		return  $min;
113 118
 	}
114 119
 
120
+	/**
121
+	 * @param string $str
122
+	 * @param string $ipn
123
+	 */
115 124
 	protected function search_db($str, $ipn, $min, $max){
116 125
 		if($max - $min > 1) {
117 126
 			$ipn = substr($ipn, 1);
@@ -165,6 +174,9 @@  discard block
 block discarded – undo
165 174
 		}
166 175
 	}
167 176
 
177
+	/**
178
+	 * @param integer $type
179
+	 */
168 180
 	protected function readData($seek, $max, $type){
169 181
 		$raw = '';
170 182
 		if($seek && $max) {
Please login to merge, or discard this patch.
Indentation   +281 added lines, -281 removed lines patch added patch discarded remove patch
@@ -14,298 +14,298 @@
 block discarded – undo
14 14
 define ('SXGEO_MEMORY', 1);
15 15
 define ('SXGEO_BATCH',  2);
16 16
 class SxGeo {
17
-	protected $fh;
18
-	protected $ip1c;
19
-	protected $info;
20
-	protected $range;
21
-	protected $db_begin;
22
-	protected $b_idx_str;
23
-	protected $m_idx_str;
24
-	protected $b_idx_arr;
25
-	protected $m_idx_arr;
26
-	protected $m_idx_len;
27
-	protected $db_items;
28
-	protected $country_size;
29
-	protected $db;
30
-	protected $regions_db;
31
-	protected $cities_db;
17
+    protected $fh;
18
+    protected $ip1c;
19
+    protected $info;
20
+    protected $range;
21
+    protected $db_begin;
22
+    protected $b_idx_str;
23
+    protected $m_idx_str;
24
+    protected $b_idx_arr;
25
+    protected $m_idx_arr;
26
+    protected $m_idx_len;
27
+    protected $db_items;
28
+    protected $country_size;
29
+    protected $db;
30
+    protected $regions_db;
31
+    protected $cities_db;
32 32
 
33
-	public $id2iso = array(
34
-		'', 'AP', 'EU', 'AD', 'AE', 'AF', 'AG', 'AI', 'AL', 'AM', 'CW', 'AO', 'AQ', 'AR', 'AS', 'AT', 'AU',
35
-		'AW', 'AZ', 'BA', 'BB', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BM', 'BN', 'BO', 'BR', 'BS',
36
-		'BT', 'BV', 'BW', 'BY', 'BZ', 'CA', 'CC', 'CD', 'CF', 'CG', 'CH', 'CI', 'CK', 'CL', 'CM', 'CN',
37
-		'CO', 'CR', 'CU', 'CV', 'CX', 'CY', 'CZ', 'DE', 'DJ', 'DK', 'DM', 'DO', 'DZ', 'EC', 'EE', 'EG',
38
-		'EH', 'ER', 'ES', 'ET', 'FI', 'FJ', 'FK', 'FM', 'FO', 'FR', 'SX', 'GA', 'GB', 'GD', 'GE', 'GF',
39
-		'GH', 'GI', 'GL', 'GM', 'GN', 'GP', 'GQ', 'GR', 'GS', 'GT', 'GU', 'GW', 'GY', 'HK', 'HM', 'HN',
40
-		'HR', 'HT', 'HU', 'ID', 'IE', 'IL', 'IN', 'IO', 'IQ', 'IR', 'IS', 'IT', 'JM', 'JO', 'JP', 'KE',
41
-		'KG', 'KH', 'KI', 'KM', 'KN', 'KP', 'KR', 'KW', 'KY', 'KZ', 'LA', 'LB', 'LC', 'LI', 'LK', 'LR',
42
-		'LS', 'LT', 'LU', 'LV', 'LY', 'MA', 'MC', 'MD', 'MG', 'MH', 'MK', 'ML', 'MM', 'MN', 'MO', 'MP',
43
-		'MQ', 'MR', 'MS', 'MT', 'MU', 'MV', 'MW', 'MX', 'MY', 'MZ', 'NA', 'NC', 'NE', 'NF', 'NG', 'NI',
44
-		'NL', 'NO', 'NP', 'NR', 'NU', 'NZ', 'OM', 'PA', 'PE', 'PF', 'PG', 'PH', 'PK', 'PL', 'PM', 'PN',
45
-		'PR', 'PS', 'PT', 'PW', 'PY', 'QA', 'RE', 'RO', 'RU', 'RW', 'SA', 'SB', 'SC', 'SD', 'SE', 'SG',
46
-		'SH', 'SI', 'SJ', 'SK', 'SL', 'SM', 'SN', 'SO', 'SR', 'ST', 'SV', 'SY', 'SZ', 'TC', 'TD', 'TF',
47
-		'TG', 'TH', 'TJ', 'TK', 'TM', 'TN', 'TO', 'TL', 'TR', 'TT', 'TV', 'TW', 'TZ', 'UA', 'UG', 'UM',
48
-		'US', 'UY', 'UZ', 'VA', 'VC', 'VE', 'VG', 'VI', 'VN', 'VU', 'WF', 'WS', 'YE', 'YT', 'RS', 'ZA',
49
-		'ZM', 'ME', 'ZW', 'A1', 'XK', 'O1', 'AX', 'GG', 'IM', 'JE', 'BL', 'MF', 'BQ', 'SS'
50
-	);
33
+    public $id2iso = array(
34
+        '', 'AP', 'EU', 'AD', 'AE', 'AF', 'AG', 'AI', 'AL', 'AM', 'CW', 'AO', 'AQ', 'AR', 'AS', 'AT', 'AU',
35
+        'AW', 'AZ', 'BA', 'BB', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BM', 'BN', 'BO', 'BR', 'BS',
36
+        'BT', 'BV', 'BW', 'BY', 'BZ', 'CA', 'CC', 'CD', 'CF', 'CG', 'CH', 'CI', 'CK', 'CL', 'CM', 'CN',
37
+        'CO', 'CR', 'CU', 'CV', 'CX', 'CY', 'CZ', 'DE', 'DJ', 'DK', 'DM', 'DO', 'DZ', 'EC', 'EE', 'EG',
38
+        'EH', 'ER', 'ES', 'ET', 'FI', 'FJ', 'FK', 'FM', 'FO', 'FR', 'SX', 'GA', 'GB', 'GD', 'GE', 'GF',
39
+        'GH', 'GI', 'GL', 'GM', 'GN', 'GP', 'GQ', 'GR', 'GS', 'GT', 'GU', 'GW', 'GY', 'HK', 'HM', 'HN',
40
+        'HR', 'HT', 'HU', 'ID', 'IE', 'IL', 'IN', 'IO', 'IQ', 'IR', 'IS', 'IT', 'JM', 'JO', 'JP', 'KE',
41
+        'KG', 'KH', 'KI', 'KM', 'KN', 'KP', 'KR', 'KW', 'KY', 'KZ', 'LA', 'LB', 'LC', 'LI', 'LK', 'LR',
42
+        'LS', 'LT', 'LU', 'LV', 'LY', 'MA', 'MC', 'MD', 'MG', 'MH', 'MK', 'ML', 'MM', 'MN', 'MO', 'MP',
43
+        'MQ', 'MR', 'MS', 'MT', 'MU', 'MV', 'MW', 'MX', 'MY', 'MZ', 'NA', 'NC', 'NE', 'NF', 'NG', 'NI',
44
+        'NL', 'NO', 'NP', 'NR', 'NU', 'NZ', 'OM', 'PA', 'PE', 'PF', 'PG', 'PH', 'PK', 'PL', 'PM', 'PN',
45
+        'PR', 'PS', 'PT', 'PW', 'PY', 'QA', 'RE', 'RO', 'RU', 'RW', 'SA', 'SB', 'SC', 'SD', 'SE', 'SG',
46
+        'SH', 'SI', 'SJ', 'SK', 'SL', 'SM', 'SN', 'SO', 'SR', 'ST', 'SV', 'SY', 'SZ', 'TC', 'TD', 'TF',
47
+        'TG', 'TH', 'TJ', 'TK', 'TM', 'TN', 'TO', 'TL', 'TR', 'TT', 'TV', 'TW', 'TZ', 'UA', 'UG', 'UM',
48
+        'US', 'UY', 'UZ', 'VA', 'VC', 'VE', 'VG', 'VI', 'VN', 'VU', 'WF', 'WS', 'YE', 'YT', 'RS', 'ZA',
49
+        'ZM', 'ME', 'ZW', 'A1', 'XK', 'O1', 'AX', 'GG', 'IM', 'JE', 'BL', 'MF', 'BQ', 'SS'
50
+    );
51 51
 
52
-	public $batch_mode  = false;
53
-	public $memory_mode = false;
52
+    public $batch_mode  = false;
53
+    public $memory_mode = false;
54 54
 
55
-	public function __construct($db_file = 'SxGeo.dat', $type = SXGEO_FILE){
56
-		$this->fh = fopen($db_file, 'rb');
57
-		// Сначала убеждаемся, что есть файл базы данных
58
-		$header = fread($this->fh, 40); // В версии 2.2 заголовок увеличился на 8 байт
59
-		if(substr($header, 0, 3) != 'SxG') die("Can't open {$db_file}\n");
60
-		$info = unpack('Cver/Ntime/Ctype/Ccharset/Cb_idx_len/nm_idx_len/nrange/Ndb_items/Cid_len/nmax_region/nmax_city/Nregion_size/Ncity_size/nmax_country/Ncountry_size/npack_size', substr($header, 3));
61
-		if($info['b_idx_len'] * $info['m_idx_len'] * $info['range'] * $info['db_items'] * $info['time'] * $info['id_len'] == 0) die("Wrong file format {$db_file}\n");
62
-		$this->range       = $info['range'];
63
-		$this->b_idx_len   = $info['b_idx_len'];
64
-		$this->m_idx_len   = $info['m_idx_len'];
65
-		$this->db_items    = $info['db_items'];
66
-		$this->id_len      = $info['id_len'];
67
-		$this->block_len   = 3 + $this->id_len;
68
-		$this->max_region  = $info['max_region'];
69
-		$this->max_city    = $info['max_city'];
70
-		$this->max_country = $info['max_country'];
71
-		$this->country_size= $info['country_size'];
72
-		$this->batch_mode  = $type & SXGEO_BATCH;
73
-		$this->memory_mode = $type & SXGEO_MEMORY;
74
-		$this->pack        = $info['pack_size'] ? explode("\0", fread($this->fh, $info['pack_size'])) : '';
75
-		$this->b_idx_str   = fread($this->fh, $info['b_idx_len'] * 4);
76
-		$this->m_idx_str   = fread($this->fh, $info['m_idx_len'] * 4);
55
+    public function __construct($db_file = 'SxGeo.dat', $type = SXGEO_FILE){
56
+        $this->fh = fopen($db_file, 'rb');
57
+        // Сначала убеждаемся, что есть файл базы данных
58
+        $header = fread($this->fh, 40); // В версии 2.2 заголовок увеличился на 8 байт
59
+        if(substr($header, 0, 3) != 'SxG') die("Can't open {$db_file}\n");
60
+        $info = unpack('Cver/Ntime/Ctype/Ccharset/Cb_idx_len/nm_idx_len/nrange/Ndb_items/Cid_len/nmax_region/nmax_city/Nregion_size/Ncity_size/nmax_country/Ncountry_size/npack_size', substr($header, 3));
61
+        if($info['b_idx_len'] * $info['m_idx_len'] * $info['range'] * $info['db_items'] * $info['time'] * $info['id_len'] == 0) die("Wrong file format {$db_file}\n");
62
+        $this->range       = $info['range'];
63
+        $this->b_idx_len   = $info['b_idx_len'];
64
+        $this->m_idx_len   = $info['m_idx_len'];
65
+        $this->db_items    = $info['db_items'];
66
+        $this->id_len      = $info['id_len'];
67
+        $this->block_len   = 3 + $this->id_len;
68
+        $this->max_region  = $info['max_region'];
69
+        $this->max_city    = $info['max_city'];
70
+        $this->max_country = $info['max_country'];
71
+        $this->country_size= $info['country_size'];
72
+        $this->batch_mode  = $type & SXGEO_BATCH;
73
+        $this->memory_mode = $type & SXGEO_MEMORY;
74
+        $this->pack        = $info['pack_size'] ? explode("\0", fread($this->fh, $info['pack_size'])) : '';
75
+        $this->b_idx_str   = fread($this->fh, $info['b_idx_len'] * 4);
76
+        $this->m_idx_str   = fread($this->fh, $info['m_idx_len'] * 4);
77 77
 
78
-		$this->db_begin = ftell($this->fh);
79
-		if ($this->batch_mode) {
80
-			$this->b_idx_arr = array_values(unpack("N*", $this->b_idx_str)); // Быстрее в 5 раз, чем с циклом
81
-			unset ($this->b_idx_str);
82
-			$this->m_idx_arr = str_split($this->m_idx_str, 4); // Быстрее в 5 раз чем с циклом
83
-			unset ($this->m_idx_str);
84
-		}
85
-		if ($this->memory_mode) {
86
-			$this->db  = fread($this->fh, $this->db_items * $this->block_len);
87
-			$this->regions_db = $info['region_size'] > 0 ? fread($this->fh, $info['region_size']) : '';
88
-			$this->cities_db  = $info['city_size'] > 0 ? fread($this->fh, $info['city_size']) : '';
89
-		}
90
-		$this->info = $info;
91
-		$this->info['regions_begin'] = $this->db_begin + $this->db_items * $this->block_len;
92
-		$this->info['cities_begin']  = $this->info['regions_begin'] + $info['region_size'];
93
-	}
78
+        $this->db_begin = ftell($this->fh);
79
+        if ($this->batch_mode) {
80
+            $this->b_idx_arr = array_values(unpack("N*", $this->b_idx_str)); // Быстрее в 5 раз, чем с циклом
81
+            unset ($this->b_idx_str);
82
+            $this->m_idx_arr = str_split($this->m_idx_str, 4); // Быстрее в 5 раз чем с циклом
83
+            unset ($this->m_idx_str);
84
+        }
85
+        if ($this->memory_mode) {
86
+            $this->db  = fread($this->fh, $this->db_items * $this->block_len);
87
+            $this->regions_db = $info['region_size'] > 0 ? fread($this->fh, $info['region_size']) : '';
88
+            $this->cities_db  = $info['city_size'] > 0 ? fread($this->fh, $info['city_size']) : '';
89
+        }
90
+        $this->info = $info;
91
+        $this->info['regions_begin'] = $this->db_begin + $this->db_items * $this->block_len;
92
+        $this->info['cities_begin']  = $this->info['regions_begin'] + $info['region_size'];
93
+    }
94 94
 
95
-	protected function search_idx($ipn, $min, $max){
96
-		if($this->batch_mode){
97
-			while($max - $min > 8){
98
-				$offset = ($min + $max) >> 1;
99
-				if ($ipn > $this->m_idx_arr[$offset]) $min = $offset;
100
-				else $max = $offset;
101
-			}
102
-			while ($ipn > $this->m_idx_arr[$min] && $min++ < $max){};
103
-		}
104
-		else {
105
-			while($max - $min > 8){
106
-				$offset = ($min + $max) >> 1;
107
-				if ($ipn > substr($this->m_idx_str, $offset*4, 4)) $min = $offset;
108
-				else $max = $offset;
109
-			}
110
-			while ($ipn > substr($this->m_idx_str, $min*4, 4) && $min++ < $max){};
111
-		}
112
-		return  $min;
113
-	}
95
+    protected function search_idx($ipn, $min, $max){
96
+        if($this->batch_mode){
97
+            while($max - $min > 8){
98
+                $offset = ($min + $max) >> 1;
99
+                if ($ipn > $this->m_idx_arr[$offset]) $min = $offset;
100
+                else $max = $offset;
101
+            }
102
+            while ($ipn > $this->m_idx_arr[$min] && $min++ < $max){};
103
+        }
104
+        else {
105
+            while($max - $min > 8){
106
+                $offset = ($min + $max) >> 1;
107
+                if ($ipn > substr($this->m_idx_str, $offset*4, 4)) $min = $offset;
108
+                else $max = $offset;
109
+            }
110
+            while ($ipn > substr($this->m_idx_str, $min*4, 4) && $min++ < $max){};
111
+        }
112
+        return  $min;
113
+    }
114 114
 
115
-	protected function search_db($str, $ipn, $min, $max){
116
-		if($max - $min > 1) {
117
-			$ipn = substr($ipn, 1);
118
-			while($max - $min > 8){
119
-				$offset = ($min + $max) >> 1;
120
-				if ($ipn > substr($str, $offset * $this->block_len, 3)) $min = $offset;
121
-				else $max = $offset;
122
-			}
123
-			while ($ipn >= substr($str, $min * $this->block_len, 3) && ++$min < $max){};
124
-		}
125
-		else {
126
-			$min++;
127
-		}
128
-		return hexdec(bin2hex(substr($str, $min * $this->block_len - $this->id_len, $this->id_len)));
129
-	}
115
+    protected function search_db($str, $ipn, $min, $max){
116
+        if($max - $min > 1) {
117
+            $ipn = substr($ipn, 1);
118
+            while($max - $min > 8){
119
+                $offset = ($min + $max) >> 1;
120
+                if ($ipn > substr($str, $offset * $this->block_len, 3)) $min = $offset;
121
+                else $max = $offset;
122
+            }
123
+            while ($ipn >= substr($str, $min * $this->block_len, 3) && ++$min < $max){};
124
+        }
125
+        else {
126
+            $min++;
127
+        }
128
+        return hexdec(bin2hex(substr($str, $min * $this->block_len - $this->id_len, $this->id_len)));
129
+    }
130 130
 
131
-	public function get_num($ip){
132
-		$ip1n = (int)$ip; // Первый байт
133
-		if($ip1n == 0 || $ip1n == 10 || $ip1n == 127 || $ip1n >= $this->b_idx_len || false === ($ipn = ip2long($ip))) return false;
134
-		$ipn = pack('N', $ipn);
135
-		$this->ip1c = chr($ip1n);
136
-		// Находим блок данных в индексе первых байт
137
-		if ($this->batch_mode){
138
-			$blocks = array('min' => $this->b_idx_arr[$ip1n-1], 'max' => $this->b_idx_arr[$ip1n]);
139
-		}
140
-		else {
141
-			$blocks = unpack("Nmin/Nmax", substr($this->b_idx_str, ($ip1n - 1) * 4, 8));
142
-		}
143
-		if ($blocks['max'] - $blocks['min'] > $this->range){
144
-			// Ищем блок в основном индексе
145
-			$part = $this->search_idx($ipn, floor($blocks['min'] / $this->range), floor($blocks['max'] / $this->range)-1);
146
-			// Нашли номер блока в котором нужно искать IP, теперь находим нужный блок в БД
147
-			$min = $part > 0 ? $part * $this->range : 0;
148
-			$max = $part > $this->m_idx_len ? $this->db_items : ($part+1) * $this->range;
149
-			// Нужно проверить чтобы блок не выходил за пределы блока первого байта
150
-			if($min < $blocks['min']) $min = $blocks['min'];
151
-			if($max > $blocks['max']) $max = $blocks['max'];
152
-		}
153
-		else {
154
-			$min = $blocks['min'];
155
-			$max = $blocks['max'];
156
-		}
157
-		$len = $max - $min;
158
-		// Находим нужный диапазон в БД
159
-		if ($this->memory_mode) {
160
-			return $this->search_db($this->db, $ipn, $min, $max);
161
-		}
162
-		else {
163
-			fseek($this->fh, $this->db_begin + $min * $this->block_len);
164
-			return $this->search_db(fread($this->fh, $len * $this->block_len), $ipn, 0, $len);
165
-		}
166
-	}
131
+    public function get_num($ip){
132
+        $ip1n = (int)$ip; // Первый байт
133
+        if($ip1n == 0 || $ip1n == 10 || $ip1n == 127 || $ip1n >= $this->b_idx_len || false === ($ipn = ip2long($ip))) return false;
134
+        $ipn = pack('N', $ipn);
135
+        $this->ip1c = chr($ip1n);
136
+        // Находим блок данных в индексе первых байт
137
+        if ($this->batch_mode){
138
+            $blocks = array('min' => $this->b_idx_arr[$ip1n-1], 'max' => $this->b_idx_arr[$ip1n]);
139
+        }
140
+        else {
141
+            $blocks = unpack("Nmin/Nmax", substr($this->b_idx_str, ($ip1n - 1) * 4, 8));
142
+        }
143
+        if ($blocks['max'] - $blocks['min'] > $this->range){
144
+            // Ищем блок в основном индексе
145
+            $part = $this->search_idx($ipn, floor($blocks['min'] / $this->range), floor($blocks['max'] / $this->range)-1);
146
+            // Нашли номер блока в котором нужно искать IP, теперь находим нужный блок в БД
147
+            $min = $part > 0 ? $part * $this->range : 0;
148
+            $max = $part > $this->m_idx_len ? $this->db_items : ($part+1) * $this->range;
149
+            // Нужно проверить чтобы блок не выходил за пределы блока первого байта
150
+            if($min < $blocks['min']) $min = $blocks['min'];
151
+            if($max > $blocks['max']) $max = $blocks['max'];
152
+        }
153
+        else {
154
+            $min = $blocks['min'];
155
+            $max = $blocks['max'];
156
+        }
157
+        $len = $max - $min;
158
+        // Находим нужный диапазон в БД
159
+        if ($this->memory_mode) {
160
+            return $this->search_db($this->db, $ipn, $min, $max);
161
+        }
162
+        else {
163
+            fseek($this->fh, $this->db_begin + $min * $this->block_len);
164
+            return $this->search_db(fread($this->fh, $len * $this->block_len), $ipn, 0, $len);
165
+        }
166
+    }
167 167
 
168
-	protected function readData($seek, $max, $type){
169
-		$raw = '';
170
-		if($seek && $max) {
171
-			if ($this->memory_mode) {
172
-				$raw = substr($type == 1 ? $this->regions_db : $this->cities_db, $seek, $max);
173
-			} else {
174
-				fseek($this->fh, $this->info[$type == 1 ? 'regions_begin' : 'cities_begin'] + $seek);
175
-				$raw = fread($this->fh, $max);
176
-			}
177
-		}
178
-		return $this->unpack($this->pack[$type], $raw);
179
-	}
168
+    protected function readData($seek, $max, $type){
169
+        $raw = '';
170
+        if($seek && $max) {
171
+            if ($this->memory_mode) {
172
+                $raw = substr($type == 1 ? $this->regions_db : $this->cities_db, $seek, $max);
173
+            } else {
174
+                fseek($this->fh, $this->info[$type == 1 ? 'regions_begin' : 'cities_begin'] + $seek);
175
+                $raw = fread($this->fh, $max);
176
+            }
177
+        }
178
+        return $this->unpack($this->pack[$type], $raw);
179
+    }
180 180
 
181
-	protected function parseCity($seek, $full = false){
182
-		if(!$this->pack) return false;
183
-		$only_country = false;
184
-		if($seek < $this->country_size){
185
-			$country = $this->readData($seek, $this->max_country, 0);
186
-			$city = $this->unpack($this->pack[2]);
187
-			$city['lat'] = $country['lat'];
188
-			$city['lon'] = $country['lon'];
189
-			$only_country = true;
190
-		}
191
-		else {
192
-			$city = $this->readData($seek, $this->max_city, 2);
193
-			$country = array('id' => $city['country_id'], 'iso' => $this->id2iso[$city['country_id']]);
194
-			unset($city['country_id']);
195
-		}
196
-		if($full) {
197
-			$region = $this->readData($city['region_seek'], $this->max_region, 1);
198
-			if(!$only_country) $country = $this->readData($region['country_seek'], $this->max_country, 0);
199
-			unset($city['region_seek']);
200
-			unset($region['country_seek']);
201
-			return array('city' => $city, 'region' => $region, 'country' => $country);
202
-		}
203
-		else {
204
-			unset($city['region_seek']);
205
-			return array('city' => $city, 'country' => array('id' => $country['id'], 'iso' => $country['iso']));
206
-		}
207
-	}
181
+    protected function parseCity($seek, $full = false){
182
+        if(!$this->pack) return false;
183
+        $only_country = false;
184
+        if($seek < $this->country_size){
185
+            $country = $this->readData($seek, $this->max_country, 0);
186
+            $city = $this->unpack($this->pack[2]);
187
+            $city['lat'] = $country['lat'];
188
+            $city['lon'] = $country['lon'];
189
+            $only_country = true;
190
+        }
191
+        else {
192
+            $city = $this->readData($seek, $this->max_city, 2);
193
+            $country = array('id' => $city['country_id'], 'iso' => $this->id2iso[$city['country_id']]);
194
+            unset($city['country_id']);
195
+        }
196
+        if($full) {
197
+            $region = $this->readData($city['region_seek'], $this->max_region, 1);
198
+            if(!$only_country) $country = $this->readData($region['country_seek'], $this->max_country, 0);
199
+            unset($city['region_seek']);
200
+            unset($region['country_seek']);
201
+            return array('city' => $city, 'region' => $region, 'country' => $country);
202
+        }
203
+        else {
204
+            unset($city['region_seek']);
205
+            return array('city' => $city, 'country' => array('id' => $country['id'], 'iso' => $country['iso']));
206
+        }
207
+    }
208 208
 
209
-	protected function unpack($pack, $item = ''){
210
-		$unpacked = array();
211
-		$empty = empty($item);
212
-		$pack = explode('/', $pack);
213
-		$pos = 0;
214
-		foreach($pack AS $p){
215
-			list($type, $name) = explode(':', $p);
216
-			$type0 = $type{0};
217
-			if($empty) {
218
-				$unpacked[$name] = $type0 == 'b' || $type0 == 'c' ? '' : 0;
219
-				continue;
220
-			}
221
-			switch($type0){
222
-				case 't':
223
-				case 'T': $l = 1; break;
224
-				case 's':
225
-				case 'n':
226
-				case 'S': $l = 2; break;
227
-				case 'm':
228
-				case 'M': $l = 3; break;
229
-				case 'd': $l = 8; break;
230
-				case 'c': $l = (int)substr($type, 1); break;
231
-				case 'b': $l = strpos($item, "\0", $pos)-$pos; break;
232
-				default: $l = 4;
233
-			}
234
-			$val = substr($item, $pos, $l);
235
-			switch($type0){
236
-				case 't': $v = unpack('c', $val); break;
237
-				case 'T': $v = unpack('C', $val); break;
238
-				case 's': $v = unpack('s', $val); break;
239
-				case 'S': $v = unpack('S', $val); break;
240
-				case 'm': $v = unpack('l', $val . (ord($val{2}) >> 7 ? "\xff" : "\0")); break;
241
-				case 'M': $v = unpack('L', $val . "\0"); break;
242
-				case 'i': $v = unpack('l', $val); break;
243
-				case 'I': $v = unpack('L', $val); break;
244
-				case 'f': $v = unpack('f', $val); break;
245
-				case 'd': $v = unpack('d', $val); break;
209
+    protected function unpack($pack, $item = ''){
210
+        $unpacked = array();
211
+        $empty = empty($item);
212
+        $pack = explode('/', $pack);
213
+        $pos = 0;
214
+        foreach($pack AS $p){
215
+            list($type, $name) = explode(':', $p);
216
+            $type0 = $type{0};
217
+            if($empty) {
218
+                $unpacked[$name] = $type0 == 'b' || $type0 == 'c' ? '' : 0;
219
+                continue;
220
+            }
221
+            switch($type0){
222
+                case 't':
223
+                case 'T': $l = 1; break;
224
+                case 's':
225
+                case 'n':
226
+                case 'S': $l = 2; break;
227
+                case 'm':
228
+                case 'M': $l = 3; break;
229
+                case 'd': $l = 8; break;
230
+                case 'c': $l = (int)substr($type, 1); break;
231
+                case 'b': $l = strpos($item, "\0", $pos)-$pos; break;
232
+                default: $l = 4;
233
+            }
234
+            $val = substr($item, $pos, $l);
235
+            switch($type0){
236
+                case 't': $v = unpack('c', $val); break;
237
+                case 'T': $v = unpack('C', $val); break;
238
+                case 's': $v = unpack('s', $val); break;
239
+                case 'S': $v = unpack('S', $val); break;
240
+                case 'm': $v = unpack('l', $val . (ord($val{2}) >> 7 ? "\xff" : "\0")); break;
241
+                case 'M': $v = unpack('L', $val . "\0"); break;
242
+                case 'i': $v = unpack('l', $val); break;
243
+                case 'I': $v = unpack('L', $val); break;
244
+                case 'f': $v = unpack('f', $val); break;
245
+                case 'd': $v = unpack('d', $val); break;
246 246
 
247
-				case 'n': $v = current(unpack('s', $val)) / pow(10, $type{1}); break;
248
-				case 'N': $v = current(unpack('l', $val)) / pow(10, $type{1}); break;
247
+                case 'n': $v = current(unpack('s', $val)) / pow(10, $type{1}); break;
248
+                case 'N': $v = current(unpack('l', $val)) / pow(10, $type{1}); break;
249 249
 
250
-				case 'c': $v = rtrim($val, ' '); break;
251
-				case 'b': $v = $val; $l++; break;
252
-			}
253
-			$pos += $l;
254
-			$unpacked[$name] = is_array($v) ? current($v) : $v;
255
-		}
256
-		return $unpacked;
257
-	}
250
+                case 'c': $v = rtrim($val, ' '); break;
251
+                case 'b': $v = $val; $l++; break;
252
+            }
253
+            $pos += $l;
254
+            $unpacked[$name] = is_array($v) ? current($v) : $v;
255
+        }
256
+        return $unpacked;
257
+    }
258 258
 
259
-	public function get($ip){
260
-		return $this->max_city ? $this->getCity($ip) : $this->getCountry($ip);
261
-	}
262
-	public function getCountry($ip){
263
-		if($this->max_city) {
264
-			$tmp = $this->parseCity($this->get_num($ip));
265
-			return $tmp['country']['iso'];
266
-		}
267
-		else return $this->id2iso[$this->get_num($ip)];
268
-	}
269
-	public function getCountryId($ip){
270
-		if($this->max_city) {
271
-			$tmp = $this->parseCity($this->get_num($ip));
272
-			return $tmp['country']['id'];
273
-		}
274
-		else return $this->get_num($ip);
275
-	}
276
-	public function getCity($ip){
277
-		$seek = $this->get_num($ip);
278
-		return $seek ? $this->parseCity($seek) : false;
279
-	}
280
-	public function getCityFull($ip){
281
-		$seek = $this->get_num($ip);
282
-		return $seek ? $this->parseCity($seek, 1) : false;
283
-	}
284
-	public function about(){
285
-		$charset = array('utf-8', 'latin1', 'cp1251');
286
-		$types   = array('n/a', 'SxGeo Country', 'SxGeo City RU', 'SxGeo City EN', 'SxGeo City', 'SxGeo City Max RU', 'SxGeo City Max EN', 'SxGeo City Max');
287
-		return array(
288
-			'Created' => date('Y.m.d', $this->info['time']),
289
-			'Timestamp' => $this->info['time'],
290
-			'Charset' => $charset[$this->info['charset']],
291
-			'Type' => $types[$this->info['type']],
292
-			'Byte Index' => $this->b_idx_len,
293
-			'Main Index' => $this->m_idx_len,
294
-			'Blocks In Index Item' => $this->range,
295
-			'IP Blocks' => $this->db_items,
296
-			'Block Size' => $this->block_len,
297
-			'City' => array(
298
-				'Max Length' => $this->max_city,
299
-				'Total Size' => $this->info['city_size'],
300
-			),
301
-			'Region' => array(
302
-				'Max Length' => $this->max_region,
303
-				'Total Size' => $this->info['region_size'],
304
-			),
305
-			'Country' => array(
306
-				'Max Length' => $this->max_country,
307
-				'Total Size' => $this->info['country_size'],
308
-			),
309
-		);
310
-	}
259
+    public function get($ip){
260
+        return $this->max_city ? $this->getCity($ip) : $this->getCountry($ip);
261
+    }
262
+    public function getCountry($ip){
263
+        if($this->max_city) {
264
+            $tmp = $this->parseCity($this->get_num($ip));
265
+            return $tmp['country']['iso'];
266
+        }
267
+        else return $this->id2iso[$this->get_num($ip)];
268
+    }
269
+    public function getCountryId($ip){
270
+        if($this->max_city) {
271
+            $tmp = $this->parseCity($this->get_num($ip));
272
+            return $tmp['country']['id'];
273
+        }
274
+        else return $this->get_num($ip);
275
+    }
276
+    public function getCity($ip){
277
+        $seek = $this->get_num($ip);
278
+        return $seek ? $this->parseCity($seek) : false;
279
+    }
280
+    public function getCityFull($ip){
281
+        $seek = $this->get_num($ip);
282
+        return $seek ? $this->parseCity($seek, 1) : false;
283
+    }
284
+    public function about(){
285
+        $charset = array('utf-8', 'latin1', 'cp1251');
286
+        $types   = array('n/a', 'SxGeo Country', 'SxGeo City RU', 'SxGeo City EN', 'SxGeo City', 'SxGeo City Max RU', 'SxGeo City Max EN', 'SxGeo City Max');
287
+        return array(
288
+            'Created' => date('Y.m.d', $this->info['time']),
289
+            'Timestamp' => $this->info['time'],
290
+            'Charset' => $charset[$this->info['charset']],
291
+            'Type' => $types[$this->info['type']],
292
+            'Byte Index' => $this->b_idx_len,
293
+            'Main Index' => $this->m_idx_len,
294
+            'Blocks In Index Item' => $this->range,
295
+            'IP Blocks' => $this->db_items,
296
+            'Block Size' => $this->block_len,
297
+            'City' => array(
298
+                'Max Length' => $this->max_city,
299
+                'Total Size' => $this->info['city_size'],
300
+            ),
301
+            'Region' => array(
302
+                'Max Length' => $this->max_region,
303
+                'Total Size' => $this->info['region_size'],
304
+            ),
305
+            'Country' => array(
306
+                'Max Length' => $this->max_country,
307
+                'Total Size' => $this->info['country_size'],
308
+            ),
309
+        );
310
+    }
311 311
 }
312 312
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -10,9 +10,9 @@  discard block
 block discarded – undo
10 10
 |   http://sypex.net/bsd_license.txt                                        |
11 11
 \***************************************************************************/
12 12
 namespace Geography;
13
-define ('SXGEO_FILE', 0);
14
-define ('SXGEO_MEMORY', 1);
15
-define ('SXGEO_BATCH',  2);
13
+define('SXGEO_FILE', 0);
14
+define('SXGEO_MEMORY', 1);
15
+define('SXGEO_BATCH', 2);
16 16
 class SxGeo {
17 17
 	protected $fh;
18 18
 	protected $ip1c;
@@ -52,13 +52,13 @@  discard block
 block discarded – undo
52 52
 	public $batch_mode  = false;
53 53
 	public $memory_mode = false;
54 54
 
55
-	public function __construct($db_file = 'SxGeo.dat', $type = SXGEO_FILE){
55
+	public function __construct($db_file = 'SxGeo.dat', $type = SXGEO_FILE) {
56 56
 		$this->fh = fopen($db_file, 'rb');
57 57
 		// Сначала убеждаемся, что есть файл базы данных
58 58
 		$header = fread($this->fh, 40); // В версии 2.2 заголовок увеличился на 8 байт
59
-		if(substr($header, 0, 3) != 'SxG') die("Can't open {$db_file}\n");
59
+		if (substr($header, 0, 3) != 'SxG') die("Can't open {$db_file}\n");
60 60
 		$info = unpack('Cver/Ntime/Ctype/Ccharset/Cb_idx_len/nm_idx_len/nrange/Ndb_items/Cid_len/nmax_region/nmax_city/Nregion_size/Ncity_size/nmax_country/Ncountry_size/npack_size', substr($header, 3));
61
-		if($info['b_idx_len'] * $info['m_idx_len'] * $info['range'] * $info['db_items'] * $info['time'] * $info['id_len'] == 0) die("Wrong file format {$db_file}\n");
61
+		if ($info['b_idx_len'] * $info['m_idx_len'] * $info['range'] * $info['db_items'] * $info['time'] * $info['id_len'] == 0) die("Wrong file format {$db_file}\n");
62 62
 		$this->range       = $info['range'];
63 63
 		$this->b_idx_len   = $info['b_idx_len'];
64 64
 		$this->m_idx_len   = $info['m_idx_len'];
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 		$this->max_region  = $info['max_region'];
69 69
 		$this->max_city    = $info['max_city'];
70 70
 		$this->max_country = $info['max_country'];
71
-		$this->country_size= $info['country_size'];
71
+		$this->country_size = $info['country_size'];
72 72
 		$this->batch_mode  = $type & SXGEO_BATCH;
73 73
 		$this->memory_mode = $type & SXGEO_MEMORY;
74 74
 		$this->pack        = $info['pack_size'] ? explode("\0", fread($this->fh, $info['pack_size'])) : '';
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 			unset ($this->m_idx_str);
84 84
 		}
85 85
 		if ($this->memory_mode) {
86
-			$this->db  = fread($this->fh, $this->db_items * $this->block_len);
86
+			$this->db = fread($this->fh, $this->db_items * $this->block_len);
87 87
 			$this->regions_db = $info['region_size'] > 0 ? fread($this->fh, $info['region_size']) : '';
88 88
 			$this->cities_db  = $info['city_size'] > 0 ? fread($this->fh, $info['city_size']) : '';
89 89
 		}
@@ -92,35 +92,35 @@  discard block
 block discarded – undo
92 92
 		$this->info['cities_begin']  = $this->info['regions_begin'] + $info['region_size'];
93 93
 	}
94 94
 
95
-	protected function search_idx($ipn, $min, $max){
96
-		if($this->batch_mode){
97
-			while($max - $min > 8){
95
+	protected function search_idx($ipn, $min, $max) {
96
+		if ($this->batch_mode) {
97
+			while ($max - $min > 8) {
98 98
 				$offset = ($min + $max) >> 1;
99 99
 				if ($ipn > $this->m_idx_arr[$offset]) $min = $offset;
100 100
 				else $max = $offset;
101 101
 			}
102
-			while ($ipn > $this->m_idx_arr[$min] && $min++ < $max){};
102
+			while ($ipn > $this->m_idx_arr[$min] && $min++ < $max) {};
103 103
 		}
104 104
 		else {
105
-			while($max - $min > 8){
105
+			while ($max - $min > 8) {
106 106
 				$offset = ($min + $max) >> 1;
107
-				if ($ipn > substr($this->m_idx_str, $offset*4, 4)) $min = $offset;
107
+				if ($ipn > substr($this->m_idx_str, $offset * 4, 4)) $min = $offset;
108 108
 				else $max = $offset;
109 109
 			}
110
-			while ($ipn > substr($this->m_idx_str, $min*4, 4) && $min++ < $max){};
110
+			while ($ipn > substr($this->m_idx_str, $min * 4, 4) && $min++ < $max) {};
111 111
 		}
112 112
 		return  $min;
113 113
 	}
114 114
 
115
-	protected function search_db($str, $ipn, $min, $max){
116
-		if($max - $min > 1) {
115
+	protected function search_db($str, $ipn, $min, $max) {
116
+		if ($max - $min > 1) {
117 117
 			$ipn = substr($ipn, 1);
118
-			while($max - $min > 8){
118
+			while ($max - $min > 8) {
119 119
 				$offset = ($min + $max) >> 1;
120 120
 				if ($ipn > substr($str, $offset * $this->block_len, 3)) $min = $offset;
121 121
 				else $max = $offset;
122 122
 			}
123
-			while ($ipn >= substr($str, $min * $this->block_len, 3) && ++$min < $max){};
123
+			while ($ipn >= substr($str, $min * $this->block_len, 3) && ++$min < $max) {};
124 124
 		}
125 125
 		else {
126 126
 			$min++;
@@ -128,27 +128,27 @@  discard block
 block discarded – undo
128 128
 		return hexdec(bin2hex(substr($str, $min * $this->block_len - $this->id_len, $this->id_len)));
129 129
 	}
130 130
 
131
-	public function get_num($ip){
132
-		$ip1n = (int)$ip; // Первый байт
133
-		if($ip1n == 0 || $ip1n == 10 || $ip1n == 127 || $ip1n >= $this->b_idx_len || false === ($ipn = ip2long($ip))) return false;
131
+	public function get_num($ip) {
132
+		$ip1n = (int) $ip; // Первый байт
133
+		if ($ip1n == 0 || $ip1n == 10 || $ip1n == 127 || $ip1n >= $this->b_idx_len || false === ($ipn = ip2long($ip))) return false;
134 134
 		$ipn = pack('N', $ipn);
135 135
 		$this->ip1c = chr($ip1n);
136 136
 		// Находим блок данных в индексе первых байт
137
-		if ($this->batch_mode){
138
-			$blocks = array('min' => $this->b_idx_arr[$ip1n-1], 'max' => $this->b_idx_arr[$ip1n]);
137
+		if ($this->batch_mode) {
138
+			$blocks = array('min' => $this->b_idx_arr[$ip1n - 1], 'max' => $this->b_idx_arr[$ip1n]);
139 139
 		}
140 140
 		else {
141 141
 			$blocks = unpack("Nmin/Nmax", substr($this->b_idx_str, ($ip1n - 1) * 4, 8));
142 142
 		}
143
-		if ($blocks['max'] - $blocks['min'] > $this->range){
143
+		if ($blocks['max'] - $blocks['min'] > $this->range) {
144 144
 			// Ищем блок в основном индексе
145
-			$part = $this->search_idx($ipn, floor($blocks['min'] / $this->range), floor($blocks['max'] / $this->range)-1);
145
+			$part = $this->search_idx($ipn, floor($blocks['min'] / $this->range), floor($blocks['max'] / $this->range) - 1);
146 146
 			// Нашли номер блока в котором нужно искать IP, теперь находим нужный блок в БД
147 147
 			$min = $part > 0 ? $part * $this->range : 0;
148
-			$max = $part > $this->m_idx_len ? $this->db_items : ($part+1) * $this->range;
148
+			$max = $part > $this->m_idx_len ? $this->db_items : ($part + 1) * $this->range;
149 149
 			// Нужно проверить чтобы блок не выходил за пределы блока первого байта
150
-			if($min < $blocks['min']) $min = $blocks['min'];
151
-			if($max > $blocks['max']) $max = $blocks['max'];
150
+			if ($min < $blocks['min']) $min = $blocks['min'];
151
+			if ($max > $blocks['max']) $max = $blocks['max'];
152 152
 		}
153 153
 		else {
154 154
 			$min = $blocks['min'];
@@ -165,9 +165,9 @@  discard block
 block discarded – undo
165 165
 		}
166 166
 	}
167 167
 
168
-	protected function readData($seek, $max, $type){
168
+	protected function readData($seek, $max, $type) {
169 169
 		$raw = '';
170
-		if($seek && $max) {
170
+		if ($seek && $max) {
171 171
 			if ($this->memory_mode) {
172 172
 				$raw = substr($type == 1 ? $this->regions_db : $this->cities_db, $seek, $max);
173 173
 			} else {
@@ -178,10 +178,10 @@  discard block
 block discarded – undo
178 178
 		return $this->unpack($this->pack[$type], $raw);
179 179
 	}
180 180
 
181
-	protected function parseCity($seek, $full = false){
182
-		if(!$this->pack) return false;
181
+	protected function parseCity($seek, $full = false) {
182
+		if (!$this->pack) return false;
183 183
 		$only_country = false;
184
-		if($seek < $this->country_size){
184
+		if ($seek < $this->country_size) {
185 185
 			$country = $this->readData($seek, $this->max_country, 0);
186 186
 			$city = $this->unpack($this->pack[2]);
187 187
 			$city['lat'] = $country['lat'];
@@ -193,9 +193,9 @@  discard block
 block discarded – undo
193 193
 			$country = array('id' => $city['country_id'], 'iso' => $this->id2iso[$city['country_id']]);
194 194
 			unset($city['country_id']);
195 195
 		}
196
-		if($full) {
196
+		if ($full) {
197 197
 			$region = $this->readData($city['region_seek'], $this->max_region, 1);
198
-			if(!$only_country) $country = $this->readData($region['country_seek'], $this->max_country, 0);
198
+			if (!$only_country) $country = $this->readData($region['country_seek'], $this->max_country, 0);
199 199
 			unset($city['region_seek']);
200 200
 			unset($region['country_seek']);
201 201
 			return array('city' => $city, 'region' => $region, 'country' => $country);
@@ -206,19 +206,19 @@  discard block
 block discarded – undo
206 206
 		}
207 207
 	}
208 208
 
209
-	protected function unpack($pack, $item = ''){
209
+	protected function unpack($pack, $item = '') {
210 210
 		$unpacked = array();
211 211
 		$empty = empty($item);
212 212
 		$pack = explode('/', $pack);
213 213
 		$pos = 0;
214
-		foreach($pack AS $p){
214
+		foreach ($pack AS $p) {
215 215
 			list($type, $name) = explode(':', $p);
216 216
 			$type0 = $type{0};
217
-			if($empty) {
217
+			if ($empty) {
218 218
 				$unpacked[$name] = $type0 == 'b' || $type0 == 'c' ? '' : 0;
219 219
 				continue;
220 220
 			}
221
-			switch($type0){
221
+			switch ($type0) {
222 222
 				case 't':
223 223
 				case 'T': $l = 1; break;
224 224
 				case 's':
@@ -227,12 +227,12 @@  discard block
 block discarded – undo
227 227
 				case 'm':
228 228
 				case 'M': $l = 3; break;
229 229
 				case 'd': $l = 8; break;
230
-				case 'c': $l = (int)substr($type, 1); break;
231
-				case 'b': $l = strpos($item, "\0", $pos)-$pos; break;
230
+				case 'c': $l = (int) substr($type, 1); break;
231
+				case 'b': $l = strpos($item, "\0", $pos) - $pos; break;
232 232
 				default: $l = 4;
233 233
 			}
234 234
 			$val = substr($item, $pos, $l);
235
-			switch($type0){
235
+			switch ($type0) {
236 236
 				case 't': $v = unpack('c', $val); break;
237 237
 				case 'T': $v = unpack('C', $val); break;
238 238
 				case 's': $v = unpack('s', $val); break;
@@ -256,32 +256,32 @@  discard block
 block discarded – undo
256 256
 		return $unpacked;
257 257
 	}
258 258
 
259
-	public function get($ip){
259
+	public function get($ip) {
260 260
 		return $this->max_city ? $this->getCity($ip) : $this->getCountry($ip);
261 261
 	}
262
-	public function getCountry($ip){
263
-		if($this->max_city) {
262
+	public function getCountry($ip) {
263
+		if ($this->max_city) {
264 264
 			$tmp = $this->parseCity($this->get_num($ip));
265 265
 			return $tmp['country']['iso'];
266 266
 		}
267 267
 		else return $this->id2iso[$this->get_num($ip)];
268 268
 	}
269
-	public function getCountryId($ip){
270
-		if($this->max_city) {
269
+	public function getCountryId($ip) {
270
+		if ($this->max_city) {
271 271
 			$tmp = $this->parseCity($this->get_num($ip));
272 272
 			return $tmp['country']['id'];
273 273
 		}
274 274
 		else return $this->get_num($ip);
275 275
 	}
276
-	public function getCity($ip){
276
+	public function getCity($ip) {
277 277
 		$seek = $this->get_num($ip);
278 278
 		return $seek ? $this->parseCity($seek) : false;
279 279
 	}
280
-	public function getCityFull($ip){
280
+	public function getCityFull($ip) {
281 281
 		$seek = $this->get_num($ip);
282 282
 		return $seek ? $this->parseCity($seek, 1) : false;
283 283
 	}
284
-	public function about(){
284
+	public function about() {
285 285
 		$charset = array('utf-8', 'latin1', 'cp1251');
286 286
 		$types   = array('n/a', 'SxGeo Country', 'SxGeo City RU', 'SxGeo City EN', 'SxGeo City', 'SxGeo City Max RU', 'SxGeo City Max EN', 'SxGeo City Max');
287 287
 		return array(
Please login to merge, or discard this patch.
Braces   +70 added lines, -52 removed lines patch added patch discarded remove patch
@@ -52,13 +52,17 @@  discard block
 block discarded – undo
52 52
 	public $batch_mode  = false;
53 53
 	public $memory_mode = false;
54 54
 
55
-	public function __construct($db_file = 'SxGeo.dat', $type = SXGEO_FILE){
55
+	public function __construct($db_file = 'SxGeo.dat', $type = SXGEO_FILE) {
56 56
 		$this->fh = fopen($db_file, 'rb');
57 57
 		// Сначала убеждаемся, что есть файл базы данных
58 58
 		$header = fread($this->fh, 40); // В версии 2.2 заголовок увеличился на 8 байт
59
-		if(substr($header, 0, 3) != 'SxG') die("Can't open {$db_file}\n");
59
+		if(substr($header, 0, 3) != 'SxG') {
60
+		    die("Can't open {$db_file}\n");
61
+		}
60 62
 		$info = unpack('Cver/Ntime/Ctype/Ccharset/Cb_idx_len/nm_idx_len/nrange/Ndb_items/Cid_len/nmax_region/nmax_city/Nregion_size/Ncity_size/nmax_country/Ncountry_size/npack_size', substr($header, 3));
61
-		if($info['b_idx_len'] * $info['m_idx_len'] * $info['range'] * $info['db_items'] * $info['time'] * $info['id_len'] == 0) die("Wrong file format {$db_file}\n");
63
+		if($info['b_idx_len'] * $info['m_idx_len'] * $info['range'] * $info['db_items'] * $info['time'] * $info['id_len'] == 0) {
64
+		    die("Wrong file format {$db_file}\n");
65
+		}
62 66
 		$this->range       = $info['range'];
63 67
 		$this->b_idx_len   = $info['b_idx_len'];
64 68
 		$this->m_idx_len   = $info['m_idx_len'];
@@ -92,65 +96,76 @@  discard block
 block discarded – undo
92 96
 		$this->info['cities_begin']  = $this->info['regions_begin'] + $info['region_size'];
93 97
 	}
94 98
 
95
-	protected function search_idx($ipn, $min, $max){
96
-		if($this->batch_mode){
97
-			while($max - $min > 8){
99
+	protected function search_idx($ipn, $min, $max) {
100
+		if($this->batch_mode) {
101
+			while($max - $min > 8) {
98 102
 				$offset = ($min + $max) >> 1;
99
-				if ($ipn > $this->m_idx_arr[$offset]) $min = $offset;
100
-				else $max = $offset;
103
+				if ($ipn > $this->m_idx_arr[$offset]) {
104
+				    $min = $offset;
105
+				} else {
106
+				    $max = $offset;
107
+				}
101 108
 			}
102 109
 			while ($ipn > $this->m_idx_arr[$min] && $min++ < $max){};
103
-		}
104
-		else {
105
-			while($max - $min > 8){
110
+		} else {
111
+			while($max - $min > 8) {
106 112
 				$offset = ($min + $max) >> 1;
107
-				if ($ipn > substr($this->m_idx_str, $offset*4, 4)) $min = $offset;
108
-				else $max = $offset;
113
+				if ($ipn > substr($this->m_idx_str, $offset*4, 4)) {
114
+				    $min = $offset;
115
+				} else {
116
+				    $max = $offset;
117
+				}
109 118
 			}
110 119
 			while ($ipn > substr($this->m_idx_str, $min*4, 4) && $min++ < $max){};
111 120
 		}
112 121
 		return  $min;
113 122
 	}
114 123
 
115
-	protected function search_db($str, $ipn, $min, $max){
124
+	protected function search_db($str, $ipn, $min, $max) {
116 125
 		if($max - $min > 1) {
117 126
 			$ipn = substr($ipn, 1);
118
-			while($max - $min > 8){
127
+			while($max - $min > 8) {
119 128
 				$offset = ($min + $max) >> 1;
120
-				if ($ipn > substr($str, $offset * $this->block_len, 3)) $min = $offset;
121
-				else $max = $offset;
129
+				if ($ipn > substr($str, $offset * $this->block_len, 3)) {
130
+				    $min = $offset;
131
+				} else {
132
+				    $max = $offset;
133
+				}
122 134
 			}
123 135
 			while ($ipn >= substr($str, $min * $this->block_len, 3) && ++$min < $max){};
124
-		}
125
-		else {
136
+		} else {
126 137
 			$min++;
127 138
 		}
128 139
 		return hexdec(bin2hex(substr($str, $min * $this->block_len - $this->id_len, $this->id_len)));
129 140
 	}
130 141
 
131
-	public function get_num($ip){
142
+	public function get_num($ip) {
132 143
 		$ip1n = (int)$ip; // Первый байт
133
-		if($ip1n == 0 || $ip1n == 10 || $ip1n == 127 || $ip1n >= $this->b_idx_len || false === ($ipn = ip2long($ip))) return false;
144
+		if($ip1n == 0 || $ip1n == 10 || $ip1n == 127 || $ip1n >= $this->b_idx_len || false === ($ipn = ip2long($ip))) {
145
+		    return false;
146
+		}
134 147
 		$ipn = pack('N', $ipn);
135 148
 		$this->ip1c = chr($ip1n);
136 149
 		// Находим блок данных в индексе первых байт
137
-		if ($this->batch_mode){
150
+		if ($this->batch_mode) {
138 151
 			$blocks = array('min' => $this->b_idx_arr[$ip1n-1], 'max' => $this->b_idx_arr[$ip1n]);
139
-		}
140
-		else {
152
+		} else {
141 153
 			$blocks = unpack("Nmin/Nmax", substr($this->b_idx_str, ($ip1n - 1) * 4, 8));
142 154
 		}
143
-		if ($blocks['max'] - $blocks['min'] > $this->range){
155
+		if ($blocks['max'] - $blocks['min'] > $this->range) {
144 156
 			// Ищем блок в основном индексе
145 157
 			$part = $this->search_idx($ipn, floor($blocks['min'] / $this->range), floor($blocks['max'] / $this->range)-1);
146 158
 			// Нашли номер блока в котором нужно искать IP, теперь находим нужный блок в БД
147 159
 			$min = $part > 0 ? $part * $this->range : 0;
148 160
 			$max = $part > $this->m_idx_len ? $this->db_items : ($part+1) * $this->range;
149 161
 			// Нужно проверить чтобы блок не выходил за пределы блока первого байта
150
-			if($min < $blocks['min']) $min = $blocks['min'];
151
-			if($max > $blocks['max']) $max = $blocks['max'];
152
-		}
153
-		else {
162
+			if($min < $blocks['min']) {
163
+			    $min = $blocks['min'];
164
+			}
165
+			if($max > $blocks['max']) {
166
+			    $max = $blocks['max'];
167
+			}
168
+		} else {
154 169
 			$min = $blocks['min'];
155 170
 			$max = $blocks['max'];
156 171
 		}
@@ -158,14 +173,13 @@  discard block
 block discarded – undo
158 173
 		// Находим нужный диапазон в БД
159 174
 		if ($this->memory_mode) {
160 175
 			return $this->search_db($this->db, $ipn, $min, $max);
161
-		}
162
-		else {
176
+		} else {
163 177
 			fseek($this->fh, $this->db_begin + $min * $this->block_len);
164 178
 			return $this->search_db(fread($this->fh, $len * $this->block_len), $ipn, 0, $len);
165 179
 		}
166 180
 	}
167 181
 
168
-	protected function readData($seek, $max, $type){
182
+	protected function readData($seek, $max, $type) {
169 183
 		$raw = '';
170 184
 		if($seek && $max) {
171 185
 			if ($this->memory_mode) {
@@ -178,47 +192,49 @@  discard block
 block discarded – undo
178 192
 		return $this->unpack($this->pack[$type], $raw);
179 193
 	}
180 194
 
181
-	protected function parseCity($seek, $full = false){
182
-		if(!$this->pack) return false;
195
+	protected function parseCity($seek, $full = false) {
196
+		if(!$this->pack) {
197
+		    return false;
198
+		}
183 199
 		$only_country = false;
184
-		if($seek < $this->country_size){
200
+		if($seek < $this->country_size) {
185 201
 			$country = $this->readData($seek, $this->max_country, 0);
186 202
 			$city = $this->unpack($this->pack[2]);
187 203
 			$city['lat'] = $country['lat'];
188 204
 			$city['lon'] = $country['lon'];
189 205
 			$only_country = true;
190
-		}
191
-		else {
206
+		} else {
192 207
 			$city = $this->readData($seek, $this->max_city, 2);
193 208
 			$country = array('id' => $city['country_id'], 'iso' => $this->id2iso[$city['country_id']]);
194 209
 			unset($city['country_id']);
195 210
 		}
196 211
 		if($full) {
197 212
 			$region = $this->readData($city['region_seek'], $this->max_region, 1);
198
-			if(!$only_country) $country = $this->readData($region['country_seek'], $this->max_country, 0);
213
+			if(!$only_country) {
214
+			    $country = $this->readData($region['country_seek'], $this->max_country, 0);
215
+			}
199 216
 			unset($city['region_seek']);
200 217
 			unset($region['country_seek']);
201 218
 			return array('city' => $city, 'region' => $region, 'country' => $country);
202
-		}
203
-		else {
219
+		} else {
204 220
 			unset($city['region_seek']);
205 221
 			return array('city' => $city, 'country' => array('id' => $country['id'], 'iso' => $country['iso']));
206 222
 		}
207 223
 	}
208 224
 
209
-	protected function unpack($pack, $item = ''){
225
+	protected function unpack($pack, $item = '') {
210 226
 		$unpacked = array();
211 227
 		$empty = empty($item);
212 228
 		$pack = explode('/', $pack);
213 229
 		$pos = 0;
214
-		foreach($pack AS $p){
230
+		foreach($pack AS $p) {
215 231
 			list($type, $name) = explode(':', $p);
216 232
 			$type0 = $type{0};
217 233
 			if($empty) {
218 234
 				$unpacked[$name] = $type0 == 'b' || $type0 == 'c' ? '' : 0;
219 235
 				continue;
220 236
 			}
221
-			switch($type0){
237
+			switch($type0) {
222 238
 				case 't':
223 239
 				case 'T': $l = 1; break;
224 240
 				case 's':
@@ -232,7 +248,7 @@  discard block
 block discarded – undo
232 248
 				default: $l = 4;
233 249
 			}
234 250
 			$val = substr($item, $pos, $l);
235
-			switch($type0){
251
+			switch($type0) {
236 252
 				case 't': $v = unpack('c', $val); break;
237 253
 				case 'T': $v = unpack('C', $val); break;
238 254
 				case 's': $v = unpack('s', $val); break;
@@ -256,32 +272,34 @@  discard block
 block discarded – undo
256 272
 		return $unpacked;
257 273
 	}
258 274
 
259
-	public function get($ip){
275
+	public function get($ip) {
260 276
 		return $this->max_city ? $this->getCity($ip) : $this->getCountry($ip);
261 277
 	}
262
-	public function getCountry($ip){
278
+	public function getCountry($ip) {
263 279
 		if($this->max_city) {
264 280
 			$tmp = $this->parseCity($this->get_num($ip));
265 281
 			return $tmp['country']['iso'];
282
+		} else {
283
+		    return $this->id2iso[$this->get_num($ip)];
266 284
 		}
267
-		else return $this->id2iso[$this->get_num($ip)];
268 285
 	}
269
-	public function getCountryId($ip){
286
+	public function getCountryId($ip) {
270 287
 		if($this->max_city) {
271 288
 			$tmp = $this->parseCity($this->get_num($ip));
272 289
 			return $tmp['country']['id'];
290
+		} else {
291
+		    return $this->get_num($ip);
273 292
 		}
274
-		else return $this->get_num($ip);
275 293
 	}
276
-	public function getCity($ip){
294
+	public function getCity($ip) {
277 295
 		$seek = $this->get_num($ip);
278 296
 		return $seek ? $this->parseCity($seek) : false;
279 297
 	}
280
-	public function getCityFull($ip){
298
+	public function getCityFull($ip) {
281 299
 		$seek = $this->get_num($ip);
282 300
 		return $seek ? $this->parseCity($seek, 1) : false;
283 301
 	}
284
-	public function about(){
302
+	public function about() {
285 303
 		$charset = array('utf-8', 'latin1', 'cp1251');
286 304
 		$types   = array('n/a', 'SxGeo Country', 'SxGeo City RU', 'SxGeo City EN', 'SxGeo City', 'SxGeo City Max RU', 'SxGeo City Max EN', 'SxGeo City Max');
287 305
 		return array(
Please login to merge, or discard this patch.
system/modules/Geography/Geography.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@
 block discarded – undo
48 48
     public function updateDb() {
49 49
         // Обновление файла базы данных Sypex Geo
50 50
         // Настройки
51
-        $url = 'https://sypexgeo.net/files/SxGeoCity_utf8.zip';  // Путь к скачиваемому файлу
51
+        $url = 'https://sypexgeo.net/files/SxGeoCity_utf8.zip'; // Путь к скачиваемому файлу
52 52
         $dat_file_dir = App::$primary->path . $this->geographyDbDir; // Каталог в который сохранять dat-файл
53 53
         $last_updated_file = $dat_file_dir . '/SxGeo.upd'; // Файл в котором хранится дата последнего обновления
54 54
         $info = false; // Вывод сообщений о работе, true заменить на false после установки в cron
Please login to merge, or discard this patch.
Braces   +25 added lines, -10 removed lines patch added patch discarded remove patch
@@ -70,7 +70,9 @@  discard block
 block discarded – undo
70 70
         preg_match("/(Country|City|Max)/", pathinfo($url, PATHINFO_BASENAME), $m);
71 71
         $type = $m[1];
72 72
         $dat_file = $types[$type];
73
-        if ($info) echo "Скачиваем архив с сервера\n";
73
+        if ($info) {
74
+            echo "Скачиваем архив с сервера\n";
75
+        }
74 76
 
75 77
         $fp = fopen($dat_file_dir . '/SxGeoTmp.zip', 'wb');
76 78
         $ch = curl_init($url);
@@ -79,7 +81,9 @@  discard block
 block discarded – undo
79 81
             CURLOPT_HTTPHEADER => file_exists($last_updated_file) ? array("If-Modified-Since: " . file_get_contents($last_updated_file)) : array(),
80 82
         ));
81 83
         if (!curl_exec($ch)) {
82
-            if ($info) echo 'Ошибка при скачивании архива';
84
+            if ($info) {
85
+                echo 'Ошибка при скачивании архива';
86
+            }
83 87
             return;
84 88
         }
85 89
         $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
@@ -87,29 +91,40 @@  discard block
 block discarded – undo
87 91
         fclose($fp);
88 92
         if ($code == 304) {
89 93
             @unlink($dat_file_dir . '/SxGeoTmp.zip');
90
-            if ($info) echo "Архив не обновился, с момента предыдущего скачивания\n";
94
+            if ($info) {
95
+                echo "Архив не обновился, с момента предыдущего скачивания\n";
96
+            }
91 97
             return;
92 98
         }
93 99
 
94
-        if ($info) echo "Архив с сервера скачан\n";
95
-// Распаковываем архив
100
+        if ($info) {
101
+            echo "Архив с сервера скачан\n";
102
+        }
103
+        // Распаковываем архив
96 104
         $fp = fopen('zip://' . $dat_file_dir . '/SxGeoTmp.zip#' . $dat_file, 'rb');
97 105
         $fw = fopen($dat_file_dir . '/' . $dat_file, 'wb');
98 106
         if (!$fp) {
99
-            if ($info)
100
-                echo "Не получается открыть\n";
107
+            if ($info) {
108
+                            echo "Не получается открыть\n";
109
+            }
101 110
             return;
102 111
         }
103
-        if ($info) echo "Распаковываем архив\n";
112
+        if ($info) {
113
+            echo "Распаковываем архив\n";
114
+        }
104 115
         stream_copy_to_stream($fp, $fw);
105 116
         fclose($fp);
106 117
         fclose($fw);
107 118
         if (filesize($dat_file) == 0) {
108
-            if ($info) echo 'Ошибка при распаковке архива';
119
+            if ($info) {
120
+                echo 'Ошибка при распаковке архива';
121
+            }
109 122
         }
110 123
         @unlink($dat_file_dir . '/SxGeoTmp.zip');
111 124
         file_put_contents($last_updated_file, gmdate('D, d M Y H:i:s') . ' GMT');
112
-        if ($info) echo "Перемещен файл в {$dat_file_dir}/{$dat_file}\n";
125
+        if ($info) {
126
+            echo "Перемещен файл в {$dat_file_dir}/{$dat_file}\n";
127
+        }
113 128
 
114 129
     }
115 130
 
Please login to merge, or discard this patch.
system/modules/Ui/objects/ActiveForm/Input/Select.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@
 block discarded – undo
21 21
         $inputOptions = [
22 22
             'value' => $this->value(),
23 23
             'disabled' => $this->readOnly(),
24
-            'values' => \Ui\ActiveForm::getOptionsList($this->colParams, $this->activeFormParams, !empty($this->modelName) ? $this->modelName : $this->activeForm->modelName, $inputName,[],$this->activeForm->model)
24
+            'values' => \Ui\ActiveForm::getOptionsList($this->colParams, $this->activeFormParams, !empty($this->modelName) ? $this->modelName : $this->activeForm->modelName, $inputName, [], $this->activeForm->model)
25 25
         ];
26 26
         $modelName = '';
27 27
 
Please login to merge, or discard this patch.
system/modules/Ecommerce/appControllers/CartController.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -298,8 +298,8 @@
 block discarded – undo
298 298
         /**
299 299
          * @var \Ecommerce\Cart\Item[] $cartItems
300 300
          */
301
-        $cartItems =[];
302
-        foreach ($cart->cartItems as $cartItem){
301
+        $cartItems = [];
302
+        foreach ($cart->cartItems as $cartItem) {
303 303
             $cartItems[$cartItem->price->item_offer_id] = $cartItem;
304 304
         }
305 305
         if (!empty($this->ecommerce->config['cartAddToggle']) && isset($cartItems[$offer->id])) {
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -299,7 +299,7 @@
 block discarded – undo
299 299
          * @var \Ecommerce\Cart\Item[] $cartItems
300 300
          */
301 301
         $cartItems =[];
302
-        foreach ($cart->cartItems as $cartItem){
302
+        foreach ($cart->cartItems as $cartItem) {
303 303
             $cartItems[$cartItem->price->item_offer_id] = $cartItem;
304 304
         }
305 305
         if (!empty($this->ecommerce->config['cartAddToggle']) && isset($cartItems[$offer->id])) {
Please login to merge, or discard this patch.
system/modules/Daemon/Daemon.php 1 patch
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -92,6 +92,9 @@
 block discarded – undo
92 92
         return $path;
93 93
     }
94 94
 
95
+    /**
96
+     * @param string $item
97
+     */
95 98
     function unserialize($item) {
96 99
         try {
97 100
             return $this->serializer()->unserialize($item);
Please login to merge, or discard this patch.
system/modules/Ecommerce/appControllers/EcommerceController.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -310,7 +310,7 @@
 block discarded – undo
310 310
         if (!$item) {
311 311
             Tools::redirect('/ecommerce/', 'Такой товар не найден');
312 312
         }
313
-        if(!$item->isVisible()){
313
+        if (!$item->isVisible()) {
314 314
             Tools::redirect('/ecommerce/', 'Этот товар сейчас недоступен');
315 315
         }
316 316
         $active = $item->category_id;
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -310,7 +310,7 @@
 block discarded – undo
310 310
         if (!$item) {
311 311
             Tools::redirect('/ecommerce/', 'Такой товар не найден');
312 312
         }
313
-        if(!$item->isVisible()){
313
+        if(!$item->isVisible()) {
314 314
             Tools::redirect('/ecommerce/', 'Этот товар сейчас недоступен');
315 315
         }
316 316
         $active = $item->category_id;
Please login to merge, or discard this patch.