Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
userlocation.php
1<?php
2
4
7
13final class UserLocation
14{
18 public static function getPoint(): Point
19 {
20 return self::getPointByPortalRegion();
21 }
22
26 private static function getPointByPortalRegion(): Point
27 {
28 $region = self::getCurrentRegion();
29
30 $map = [
31 'ru' => [55.751244, 37.618423],
32 'eu' => [50.85045, 4.34878],
33 'de' => [52.520008, 13.404954],
34 'fr' => [48.864716, 2.349014],
35 'it' => [41.902782, 12.496366],
36 'pl' => [52.237049, 21.017532],
37 'ua' => [50.431759, 30.517023],
38 'by' => [53.893009, 27.567444],
39 'kz' => [43.238949, 76.889709],
40 'in' => [28.644800, 77.216721],
41 'tr' => [39.925533, 32.866287],
42 'id' => [-6.200000, 106.816666],
43 'cn' => [39.916668, 116.383331],
44 'vn' => [21.028511, 105.804817],
45 'jp' => [35.652832, 139.839478],
46 'com' => [47.751076, -120.740135],
47 'es' => [19.432608, -99.133209],
48 'br' => [-15.793889, -47.882778],
49 ];
50
51 $coordinates = $map[$region] ?? [51.509865, -0.118092];
52
53 return (new Point($coordinates[0], $coordinates[1]));
54 }
55
59 private static function getCurrentRegion(): string
60 {
61 $result = null;
62
63 if (Loader::includeModule('bitrix24'))
64 {
65 $licensePrefix = \CBitrix24::getLicensePrefix();
66 if ($licensePrefix !== false)
67 {
68 $result = (string)$licensePrefix;
69 }
70 }
71 elseif (Loader::includeModule('intranet'))
72 {
73 $result = (string)\CIntranetUtils::getPortalZone();
74 }
75 elseif (defined('LANGUAGE_ID'))
76 {
77 $result = LANGUAGE_ID;
78 }
79
80 if (!$result)
81 {
82 $result = 'en';
83 }
84
85 return $result;
86 }
87}