Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
extension.php
1<?php
2
4
6
13class Extension extends Base
14{
18 public function getTitle()
19 {
20 return Loc::getMessage('MAIN_SRV_GEOIP_EXT_TITLE');
21 }
22
26 public function getDescription()
27 {
28 return Loc::getMessage('MAIN_SRV_GEOIP_EXT_DESCRIPTION') . '<br>' . Loc::getMessage("main_srv_geoip_ext_unsupported");
29 }
30
35 public function getSupportedLanguages()
36 {
37 return array('en');
38 }
39
40 private function decode($text)
41 {
42 if(!is_string($text) && !is_array($text))
43 {
44 return $text;
45 }
46
47 return mb_convert_encoding($text, SITE_CHARSET, 'ISO-8859-1');
48 }
49
55 public function getDataResult($ip, $lang = ''): Result
56 {
57 $dataResult = new Result;
58 $geoData = new Data();
59 $geoData->lang = 'en';
60
61 if (self::isAvailableBaseCountry())
62 {
63 $geoData->countryCode = $this->decode(geoip_country_code_by_name($ip));
64 $geoData->countryName = $this->decode(geoip_country_name_by_name($ip));
65 }
66
67 if (self::isAvailableBaseCity())
68 {
69 $recordByName = $this->decode(geoip_record_by_name($ip));
70
71 if (isset($recordByName['country_code']) && isset($recordByName['region']))
72 {
73 $geoData->timezone = $this->decode(
74 geoip_time_zone_by_country_and_region(
75 $recordByName['country_code'],
76 $recordByName['region']
77 )
78 );
79 }
80
81 $geoData->countryCode = $recordByName['country_code'];
82 $geoData->countryName = $recordByName['country_name'];
83 $geoData->regionCode = $recordByName['region'];
84 $geoData->cityName = $recordByName['city'];
85 $geoData->zipCode = $recordByName['postal_code'];
86 $geoData->latitude = $recordByName['latitude'];
87 $geoData->longitude = $recordByName['longitude'];
88 }
89
90 if (self::isAvailableBaseOrganization())
91 {
92 $geoData->organizationName = $this->decode(geoip_org_by_name($ip));
93 }
94
95 if (self::isAvailableBaseIsp())
96 {
97 $geoData->ispName = $this->decode(geoip_isp_by_name($ip));
98 }
99
100 if (self::isAvailableBaseAsn())
101 {
102 $geoData->asn = $this->decode(geoip_asnum_by_name($ip));
103 }
104
105 $dataResult->setGeoData($geoData);
106 return $dataResult;
107 }
108
114 protected static function isAvailable()
115 {
116 return function_exists('geoip_db_avail');
117 }
118
124 protected static function isAvailableBaseCountry()
125 {
126 return self::isAvailable() && geoip_db_avail(GEOIP_COUNTRY_EDITION);
127 }
128
134 protected static function isAvailableBaseCity()
135 {
136 return self::isAvailable() && geoip_db_avail(GEOIP_CITY_EDITION_REV0);
137 }
138
144 protected static function isAvailableBaseOrganization()
145 {
146 return self::isAvailable() && geoip_db_avail(GEOIP_ORG_EDITION);
147 }
148
154 protected static function isAvailableBaseIsp()
155 {
156 return self::isAvailable() && geoip_db_avail(GEOIP_ISP_EDITION) && function_exists('geoip_isp_by_name');
157 }
158
164 protected static function isAvailableBaseAsn()
165 {
166 return self::isAvailable() && geoip_db_avail(GEOIP_ASNUM_EDITION) && function_exists('geoip_asnum_by_name');
167 }
168
173 public function isInstalled()
174 {
175 return self::isAvailable();
176 }
177
181 public function getConfigForAdmin()
182 {
183 return array(
184 array(
185 'TITLE' => Loc::getMessage('MAIN_SRV_GEOIP_EXT_NOT_REQ'),
186 'TYPE' => 'COLSPAN2'
187 ),
188 array(
189 'TITLE' => Loc::getMessage('MAIN_SRV_GEOIP_EXT_DB_AVIALABLE'),
190 'TYPE' => 'COLSPAN2',
191 'HEADING' => true
192 ),
193 array(
194 'TITLE' => Loc::getMessage('MAIN_SRV_GEOIP_EXT_DB_COUNTRY'),
195 'TYPE' => 'CHECKBOX',
196 'CHECKED' => self::isAvailableBaseCountry(),
197 'DISABLED' => true
198 ),
199 array(
200 'TITLE' => Loc::getMessage('MAIN_SRV_GEOIP_EXT_DB_CITY'),
201 'TYPE' => 'CHECKBOX',
202 'CHECKED' => self::isAvailableBaseCity(),
203 'DISABLED' => true
204 ),
205 array(
206 'TITLE' => Loc::getMessage('MAIN_SRV_GEOIP_EXT_DB_ORG'),
207 'TYPE' => 'CHECKBOX',
208 'CHECKED' => self::isAvailableBaseOrganization(),
209 'DISABLED' => true
210 ),
211 array(
212 'TITLE' => Loc::getMessage('MAIN_SRV_GEOIP_EXT_DB_ISP'),
213 'TYPE' => 'CHECKBOX',
214 'CHECKED' => self::isAvailableBaseIsp(),
215 'DISABLED' => true
216 ),
217 array(
218 'TITLE' => Loc::getMessage('MAIN_SRV_GEOIP_EXT_DB_ASN'),
219 'TYPE' => 'CHECKBOX',
220 'CHECKED' => self::isAvailableBaseAsn(),
221 'DISABLED' => true
222 )
223 );
224 }
225
229 public function getProvidingData()
230 {
231 $result = new ProvidingData();
232
233 if (self::isAvailableBaseCountry())
234 {
235 $result->countryCode = true;
236 $result->countryName = true;
237 }
238
239 if (self::isAvailableBaseCity())
240 {
241 $result->timezone = true;
242 $result->countryCode = true;
243 $result->countryName = true;
244 $result->regionCode = true;
245 $result->cityName = true;
246 $result->zipCode = true;
247 $result->latitude = true;
248 $result->longitude = true;
249 }
250
251 if (self::isAvailableBaseOrganization())
252 {
253 $result->organizationName = true;
254 }
255
256 if (self::isAvailableBaseIsp())
257 {
258 $result->ispName = true;
259 }
260
261 if (self::isAvailableBaseAsn())
262 {
263 $result->asn = true;
264 }
265
266 return $result;
267 }
268}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29