@@ -112,7 +112,7 @@ |
||
| 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; |
@@ -48,7 +48,7 @@ discard block |
||
| 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 |
||
| 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> |
@@ -10,9 +10,9 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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( |
@@ -48,7 +48,7 @@ |
||
| 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 |