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(mb_strtoupper($deviceDetectSource),
"IPHONE") > 0 || mb_strrpos(mb_strtoupper($deviceDetectSource),
"IPAD") > 0)
82 self::$platform =
"ios";
84 elseif (mb_strrpos(mb_strtoupper($deviceDetectSource),
"ANDROID") > 0 || mb_strrpos(mb_strtoupper($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")) {
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"];
122 self::$apiVersion =
$APPLICATION->get_cookie(
"MOBILE_APP_VERSION");
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;
192 $isBackground = Context::getCurrent()->getServer()->get(
"HTTP_BX_MOBILE_BACKGROUND");
193 return ($isBackground ===
"true");
209 if (self::$isAlreadyInit)
214 header(
"BX-Cordova-Version: " . self::$supportedCordovaVersion);
215 $GLOBALS[
"BITRIX_PLATFORM"] = self::$platform;
216 $GLOBALS[
"BITRIX_API_VERSION"] = self::$apiVersion;
218 AddEventHandler(
"main",
"OnBeforeEndBufferContent", Array(__CLASS__,
"initScripts"));
220 self::$isAlreadyInit =
true;
228 if (is_null(self::$instance))
230 self::$instance =
new Mobile();
233 return self::$instance;
245 $jsVarsFormat = <<<JSCODE
247 (window.BX||
top.BX).message({
'USER_ID':
'%s'});
248 var appVersion =
"%s";
250 var mobileSiteDir =
"%s";
256 sprintf($jsVarsFormat,
263 if (self::$platform ==
"android")
269 $androidJS = <<<JSCODE
271 console.log(
"bxdata://success");
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 src='$pgJsFile'></script>",
false,
true);
285 $APPLICATION->AddHeadString(
"<script src=\"" . \CUtil::GetAdditionalFileURL(
"/bitrix/js/mobileapp/bitrix_mobile.js") .
"\"></script>",
false,
true);
286 $APPLICATION->AddHeadString(
"<script src=\"" . \CUtil::GetAdditionalFileURL(
"/bitrix/js/mobileapp/mobile_lib.js") .
"\"></script>",
false,
true);
289 if (self::$platform ==
"android")
291 $APPLICATION->AddHeadString(
"<script>app.bindloadPageBlank();</script>",
false,
false);
294 if (!array_key_exists(
"doNotUseViewPort",
$_REQUEST))
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;
567 return self::$platform;
576 return $this->userScalable;
585 $this->userScalable = ($userScalable ===
false ?
"no" :
"yes");
616 if (!defined(
"MOBILE_INIT_EVENT_SKIP"))
618 $db_events = getModuleEvents(
"mobileapp",
"OnMobileInit");
619 while ($arEvent = $db_events->Fetch())
633 return self::$apiVersion;
642 return self::$pgVersion;
650 return (
float) self::$systemVersion;
658 return $this->isWebRtcSupported;
688 return $this->deviceHeight;
698 $this->deviceHeight = $deviceHeight;
708 return $this->largeScreenSupport;
718 $this->largeScreenSupport = $largeScreenSupport;
739 $this->scale = $scale;
751 private function __clone()
const SITE_DIR(!defined('LANG'))
$GLOBALS['____1690880296']
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)