20 private $pixelRatio = 1.0;
21 private $minScale =
false;
22 private $iniScale =
false;
23 private $maxScale =
false;
25 private $width =
false;
26 private $userScalable =
"no";
27 private $deviceWidth = 320;
28 private $deviceHeight = 480;
29 private $screenCategory =
"NORMAL";
31 private $largeScreenSupport =
true;
32 private $isWebRtcSupported =
false;
33 private $isBXScriptSupported =
false;
35 private function __construct()
39 $this->
setDeviceWidth($_COOKIE[
"MOBILE_RESOLUTION_WIDTH"] ??
null);
41 $this->setPixelratio($_COOKIE[
"MOBILE_SCALE"] ??
null);
42 $this->screenCategory = $_COOKIE[
"MOBILE_SCREEN_CATEGORY"] ??
null;
44 if (!empty($_COOKIE[
"PG_VERSION"]))
46 self::$pgVersion = $_COOKIE[
"PG_VERSION"];
49 self::$isDev = (isset($_COOKIE[
"MOBILE_DEV"]) && $_COOKIE[
"MOBILE_DEV"] ==
"Y");
50 $this->device = $_COOKIE[
"MOBILE_DEVICE"] ??
null;
51 if (!empty($_COOKIE[
"IS_WEBRTC_SUPPORTED"]) && $_COOKIE[
"IS_WEBRTC_SUPPORTED"] ==
"Y")
55 if (!empty($_COOKIE[
"IS_BXSCRIPT_SUPPORTED"]) && $_COOKIE[
"IS_BXSCRIPT_SUPPORTED"] ==
"Y")
71 if (array_key_exists(
"MOBILE_DEVICE", $_COOKIE))
73 $deviceDetectSource = $_COOKIE[
"MOBILE_DEVICE"];
77 $deviceDetectSource = mb_strtolower(
Context::getCurrent()->getServer()->
get(
"HTTP_USER_AGENT"));
80 if (mb_strrpos(ToUpper($deviceDetectSource),
"IPHONE") > 0 || mb_strrpos(ToUpper($deviceDetectSource),
"IPAD") > 0)
82 self::$platform =
"ios";
84 elseif (mb_strrpos(ToUpper($deviceDetectSource),
"ANDROID") > 0 || mb_strrpos(ToUpper($deviceDetectSource),
"ANDROID") === 0)
86 self::$platform =
"android";
89 $userAgent = \Bitrix\Main\Context::getCurrent()->getServer()->get(
"HTTP_USER_AGENT");
90 if (!empty($_COOKIE[
"MOBILE_SYSTEM_VERSION"]))
92 self::$systemVersion = $_COOKIE[
"MOBILE_SYSTEM_VERSION"];
97 preg_match(
"/iOS\s(\d+\.\d+)/i",$userAgent, $pregMatch);
98 if(count($pregMatch) == 2)
99 self::$systemVersion = floatval($pregMatch[1]);
102 if (array_key_exists(
"emulate_platform", $_REQUEST))
104 self::$platform = $_REQUEST[
"emulate_platform"];
107 if ($mobileTZ = $APPLICATION->get_cookie(
"TZ",
"MOBILE")) {
108 $tz = $APPLICATION->get_cookie(
"TZ");
109 if ($tz != $mobileTZ) {
110 $cookie = new \Bitrix\Main\Web\Cookie(
"TZ", $mobileTZ, time() + 60 * 60 * 24 * 30 * 12);
111 \Bitrix\Main\Context::getCurrent()->getResponse()->addCookie($cookie);
116 if (array_key_exists(
"MOBILE_API_VERSION", $_COOKIE))
118 self::$apiVersion = $_COOKIE[
"MOBILE_API_VERSION"];
120 elseif ($APPLICATION->get_cookie(
"MOBILE_APP_VERSION"))
122 self::$apiVersion = $APPLICATION->get_cookie(
"MOBILE_APP_VERSION");
124 elseif (array_key_exists(
"api_version", $_REQUEST))
126 self::$apiVersion = $_REQUEST[
"api_version"];
130 preg_match(
"/(?<=BitrixMobile\/Version=).*\d/i",$userAgent, $pregMatch);
132 if(count($pregMatch) == 1)
134 self::$apiVersion = $pregMatch[0];
138 self::$apiVersion = intval(self::$apiVersion);
154 $this->isBXScriptSupported = $isBXScriptSupported;
163 return $this->device;
173 return $this->pixelRatio;
183 $this->pixelRatio = $pixelRatio;
193 return ($isBackground ===
"true");
209 if (self::$isAlreadyInit)
214 header(
"BX-Cordova-Version: " . self::$supportedCordovaVersion);
218 AddEventHandler(
"main",
"OnBeforeEndBufferContent", Array(__CLASS__,
"initScripts"));
219 AddEventHandler(
"main",
"OnEpilog", Array($this,
"onMobileInit"));
220 self::$isAlreadyInit =
true;
228 if (is_null(self::$instance))
230 self::$instance =
new Mobile();
241 global $APPLICATION, $USER;
244 \CJSCore::Init(
"db");
245 $jsVarsFormat = <<<JSCODE
246 <script type=
"text/javascript">
247 (window.BX||top.BX).message({
'USER_ID':
'%s'});
248 var appVersion =
"%s";
250 var mobileSiteDir =
"%s";
255 $APPLICATION->AddHeadString(
256 sprintf($jsVarsFormat,
263 if (self::$platform ==
"android")
269 $androidJS = <<<JSCODE
270 <script type=
"text/javascript">
271 console.log(
"bxdata://success");
275 $APPLICATION->AddHeadString($androidJS,
false,
true);
277 $userAgent = \Bitrix\Main\Context::getCurrent()->getServer()->get(
"HTTP_USER_AGENT");
278 if(mb_strpos($userAgent,
"WKWebView/BitrixMobile") ===
false)
280 $pgJsFile =
"/bitrix/js/mobileapp/__deviceload__/cordova.js?mod=1";
281 $APPLICATION->AddHeadString(
"<script type='text/javascript' src='$pgJsFile'></script>",
false,
true);
285 $APPLICATION->AddHeadString(
"<script type=\"text/javascript\" src=\"" . \CUtil::GetAdditionalFileURL(
"/bitrix/js/mobileapp/bitrix_mobile.js") .
"\"></script>",
false,
true);
286 $APPLICATION->AddHeadString(
"<script type=\"text/javascript\" src=\"" . \CUtil::GetAdditionalFileURL(
"/bitrix/js/mobileapp/mobile_lib.js") .
"\"></script>",
false,
true);
289 if (self::$platform ==
"android")
291 $APPLICATION->AddHeadString(
"<script type=\"text/javascript\">app.bindloadPageBlank();</script>",
false,
false);
294 if (!array_key_exists(
"doNotUseViewPort", $_REQUEST))
299 \Bitrix\Main\UI\Extension::load([
309 return $this->isBXScriptSupported;
324 $width = $this->getDevicewidth();
327 if ($this->largeScreenSupport ==
true)
343 $viewPortMeta =
"<meta id=\"bx_mobile_viewport\" name=\"viewport\" content=\"#content_value#\">";
344 if ($this->getIniscale())
346 $contentAttributes[] =
"initial-scale=" . $this->getIniscale();
348 if ($this->getMaxscale())
350 $contentAttributes[] =
"maximum-scale=" . $this->getMaxscale();
352 if ($this->getMinscale())
354 $contentAttributes[] =
"minimum-scale=" . $this->getMinscale();
360 $contentAttributes[] =
"width=" . $this->
getWidth();
362 elseif ($this->getIniscale())
364 $contentAttributes[] =
"width=" . ($width / $this->getIniscale());
369 $contentAttributes[] =
"width=device-width";
374 $contentAttributes[] =
"viewport-fit=cover";
376 return str_replace(
"#content_value#", implode(
", ", $contentAttributes), $viewPortMeta);
386 return $this->deviceWidth;
396 $this->deviceWidth = $deviceWidth;
410 $width = $this->getDevicewidth();
412 $viewPortMeta =
"<meta id=\"bx_mobile_viewport\" name=\"viewport\" content=\"#content_value#\">";
413 $contentAttributes = Array(
414 "width=" . ($width / $this->scale),
417 $content = implode(
", ", $contentAttributes);
419 return str_replace(
"#content_value#", $content, $viewPortMeta);
429 return $this->screenCategory;
439 $this->screenCategory = $screenCategory;
447 return "<meta id=\"bx_mobile_viewport\" name=\"viewport\" content=\"user-scalable=no width=device-width target-densitydpi=" . $this->
getTargetDpi() .
"\">";
457 $targetDpi =
"medium-dpi";
465 $targetDpi =
"medium-dpi";
468 $targetDpi =
"low-dpi";
471 $targetDpi =
"low-dpi";
474 $targetDpi =
"medium-dpi";
477 $targetDpi =
"medium-dpi";
491 return $this->iniScale;
501 $this->iniScale = $iniScale;
511 return $this->maxScale;
521 $this->maxScale = $maxScale;
531 return $this->minScale;
541 $this->minScale = $minScale;
558 $this->width = $width;
576 return $this->userScalable;
585 $this->userScalable = ($userScalable ===
false ?
"no" :
"yes");
609 return (defined(
"BX_UTF") ? $s : Encoding::convertEncoding($s,
'UTF-8', SITE_CHARSET));
614 if (!defined(
"MOBILE_INIT_EVENT_SKIP"))
616 $db_events = getModuleEvents(
"mobileapp",
"OnMobileInit");
617 while ($arEvent = $db_events->Fetch())
619 ExecuteModuleEventEx($arEvent);
656 return $this->isWebRtcSupported;
686 return $this->deviceHeight;
696 $this->deviceHeight = $deviceHeight;
706 return $this->largeScreenSupport;
716 $this->largeScreenSupport = $largeScreenSupport;
737 $this->scale = $scale;
749 private function __clone()
$GLOBALS['____1444769544']