@@ -236,17 +236,20 @@ |
||
| 236 | 236 | * @return boolean|\Users\User |
| 237 | 237 | */ |
| 238 | 238 | public function get($idn, $ltype = 'id') { |
| 239 | - if (!$idn) |
|
| 240 | - return false; |
|
| 239 | + if (!$idn) { |
|
| 240 | + return false; |
|
| 241 | + } |
|
| 241 | 242 | |
| 242 | - if (is_numeric($idn) && $ltype != 'login') |
|
| 243 | - $user = Users\User::get($idn, 'id'); |
|
| 244 | - elseif ($ltype == 'login') |
|
| 245 | - $user = Users\User::get($idn, 'login'); |
|
| 246 | - else |
|
| 247 | - $user = Users\User::get($idn, 'mail'); |
|
| 248 | - if (!$user) |
|
| 249 | - return []; |
|
| 243 | + if (is_numeric($idn) && $ltype != 'login') { |
|
| 244 | + $user = Users\User::get($idn, 'id'); |
|
| 245 | + } elseif ($ltype == 'login') { |
|
| 246 | + $user = Users\User::get($idn, 'login'); |
|
| 247 | + } else { |
|
| 248 | + $user = Users\User::get($idn, 'mail'); |
|
| 249 | + } |
|
| 250 | + if (!$user) { |
|
| 251 | + return []; |
|
| 252 | + } |
|
| 250 | 253 | |
| 251 | 254 | return $user; |
| 252 | 255 | } |
@@ -8,7 +8,7 @@ |
||
| 8 | 8 | if (!empty($alias)) { |
| 9 | 9 | $slider = Sliders\Slider::get($alias, 'alias'); |
| 10 | 10 | } |
| 11 | -if(empty($slider)){ |
|
| 11 | +if(empty($slider)) { |
|
| 12 | 12 | echo 'Slider not found'; |
| 13 | 13 | return; |
| 14 | 14 | } |
@@ -35,8 +35,11 @@ |
||
| 35 | 35 | $contents = curl_exec($c); |
| 36 | 36 | curl_close($c); |
| 37 | 37 | |
| 38 | - if ($contents) return $contents; |
|
| 39 | - else return FALSE; |
|
| 38 | + if ($contents) { |
|
| 39 | + return $contents; |
|
| 40 | + } else { |
|
| 41 | + return FALSE; |
|
| 42 | + } |
|
| 40 | 43 | } |
| 41 | 44 | |
| 42 | 45 | static function deliveryTime($cart) { |
@@ -37,7 +37,7 @@ |
||
| 37 | 37 | if (!empty($options['attributes'])) { |
| 38 | 38 | $attributes = array_merge($attributes, $options['attributes']); |
| 39 | 39 | } |
| 40 | -if(!empty($attributes['onchange'])){ |
|
| 40 | +if(!empty($attributes['onchange'])) { |
|
| 41 | 41 | unset($attributes['onchange']); |
| 42 | 42 | } |
| 43 | 43 | echo Html::el('input', $attributes, '', null); |
@@ -13,11 +13,9 @@ |
||
| 13 | 13 | |
| 14 | 14 | use Exchange1c\Exchange; |
| 15 | 15 | |
| 16 | -class Info extends \Exchange1c\Mode |
|
| 17 | -{ |
|
| 16 | +class Info extends \Exchange1c\Mode { |
|
| 18 | 17 | |
| 19 | - public function process() |
|
| 20 | - { |
|
| 18 | + public function process() { |
|
| 21 | 19 | echo "version=2.03"; |
| 22 | 20 | $this->end(); |
| 23 | 21 | } |
@@ -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; |
@@ -56,8 +56,7 @@ |
||
| 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 | ?> |
@@ -52,13 +52,17 @@ 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') { |
|
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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( |
@@ -70,7 +70,9 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 | |