Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
mobile.php
1<?php
3
4use \Bitrix\Landing\Manager;
5use \Bitrix\Main\Localization\Loc;
6use \Bitrix\Main\Web\Json;
7use \Bitrix\MobileApp\Janative;
8use \Bitrix\Mobile\Auth;
9
10Loc::loadMessages(__FILE__);
11
12class Mobile
13{
18 protected static $isMobileHit = false;
19
25 public static function onMobileMenuStructureBuilt($menu): array
26 {
27 if (!isset($menu[0]['items']) || !is_array($menu[0]['items']))
28 {
29 return $menu;
30 }
31
32 if (\Bitrix\Landing\Site\Type::isEnabled('knowledge'))
33 {
34 $menu[0]['items'][] = self::getKnowledgeMenu();
35 }
36
37 //$menu[0]['items'][] = self::getLandingMenu();
38
39 return $menu;
40 }
41
46 private static function getKnowledgeMenu(): array
47 {
48 $componentId = 'knowledge.list';
49 $componentVersion = Janative\Manager::getComponentVersion(
50 $componentId
51 );
52
53 return [
54 'sort' => 100,
55 'title' => Loc::getMessage('LANDING_CONNECTOR_MB_MENU_TITLE'),
56 'imageUrl' => '/bitrix/images/landing/mobile/knowledge.png?4',
57 'color' => '#e597ba',
58 'params' => [
59 'onclick' => <<<JS
60 ComponentHelper.openList({
61 name: '{$componentId}',
62 object: 'list',
63 version: '{$componentVersion}',
64 widgetParams: {title: this.title, useSearch:true}
65 });
66JS
67 ]
68 ];
69 }
70
75 private static function getLandingMenu(): array
76 {
77 $version = time();
78 $title = Loc::getMessage('LANDING_CONNECTOR_MB_LANDINGS_MENU_TITLE');
79 $titleTabPage = Loc::getMessage('LANDING_CONNECTOR_MB_LANDINGS_TAB_PAGE');
80 $titleTabStore = Loc::getMessage('LANDING_CONNECTOR_MB_LANDINGS_TAB_STORE');
81
82 return [
83 'sort' => 200,
84 'title' => $title,
85 'imageUrl' => '/bitrix/images/landing/mobile/knowledge.png',
86 'color' => '#e597ba',
87 'params' => [
88 'onclick' => <<<JS
89 PageManager.openComponent('JSStackComponent', {
90 rootWidget: {
91 name: 'tabs',
92 settings: {
93 objectName: 'layoutWidget',
94 title: '{$title}',
95 tabs: {
96 items: [
97 {
98 title: '{$titleTabPage}',
99 component: {
100 name: 'JSStackComponent',
101 scriptPath: '/mobileapp/jn/landing.list/?type=page&version={$version}',
102 params: { type: 'page' },
103 rootWidget: {
104 name: 'layout',
105 settings: {
106 objectName: 'layoutWidget',
107 title: '{$title}',
108 },
109 },
110 }
111 },
112 {
113 title: '{$titleTabStore}',
114 component: {
115 name: 'JSStackComponent',
116 scriptPath: '/mobileapp/jn/landing.list/?type=store&version={$version}',
117 params: { type: 'store' },
118 rootWidget: {
119 name: 'layout',
120 settings: {
121 objectName: 'layoutWidget',
122 title: '{$title}',
123 },
124 },
125 }
126 },
127 ]
128 }
129 },
130 },
131 },
132 );
133JS
134 ]
135 ];
136 }
137
142 public static function forceMobile()
143 {
144 self::$isMobileHit = true;
145 }
146
151 public static function isMobileHit(): bool
152 {
153 static $mobileHit = null;
154
155 if (self::$isMobileHit)
156 {
157 return true;
158 }
159
160 if ($mobileHit === null)
161 {
162 $mobileHit = \Bitrix\Main\ModuleManager::isModuleInstalled('intranet')
163 && mb_strpos(Manager::getCurDir(), SITE_DIR . 'mobile/') === 0;
164 }
165
166 return $mobileHit;
167 }
168
173 public static function prologMobileHit()
174 {
175 if (self::isMobileHit())
176 {
177 if (
178 \Bitrix\Main\Loader::includeModule('mobile') &&
179 \Bitrix\Main\Loader::includeModule('mobileapp')
180 )
181 {
182 if (!defined('SKIP_MOBILEAPP_INIT'))
183 {
184 \CMobile::init();
185 if (!Manager::getUserId())
186 {
187 Manager::getApplication()->restartBuffer();
188 Auth::setNotAuthorizedHeaders();
189 echo Json::encode(Auth::getNotAuthorizedResponse());
190 die();
191 }
192 }
193 }
194 else
195 {
196 die();
197 }
198 }
199 }
200}
static onMobileMenuStructureBuilt($menu)
Definition mobile.php:25
static getApplication()
Definition manager.php:71
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29