Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
manager.php
1<?php
3
4use \Bitrix\Main\Localization\Loc;
5
6Loc::loadMessages(__FILE__);
7
8class Manager
9{
13 const MAP = [
14 'limit_sites_google_analytics' => [
15 'check_callback' => [
16 '\Bitrix\Landing\Restriction\Hook', 'isAllowed'
17 ]
18 ],
19 'limit_sites_powered_by' => [
20 'check_callback' => [
21 '\Bitrix\Landing\Restriction\Hook', 'isAllowed'
22 ]
23 ],
24 'limit_sites_html_js' => [
25 'check_callback' => [
26 '\Bitrix\Landing\Restriction\Hook', 'isAllowed'
27 ]
28 ],
29 'limit_sites_change_color_palette' => [
30 'check_callback' => [
31 '\Bitrix\Landing\Restriction\Hook', 'isAllowed'
32 ]
33 ],
34 'limit_sites_access_permissions' => [
35 'check_callback' => [
36 '\Bitrix\Landing\Restriction\Rights', 'isAllowed'
37 ]
38 ],
39 'limit_sites_transfer' => [
40 'check_callback' => [
41 '\Bitrix\Landing\Restriction\Site', 'isExportAllowed'
42 ]
43 ],
44 'limit_free_domen' => [
45 'check_callback' => [
46 '\Bitrix\Landing\Restriction\Site', 'isFreeDomainAllowed'
47 ]
48 ],
49 'limit_sites_number' => [
50 'check_callback' => [
51 '\Bitrix\Landing\Restriction\Site', 'isCreatingAllowed'
52 ],
53 'scope_alias' => [
54 'knowledge' => 'limit_knowledge_base_number_page',
55 'group' => 'limit_knowledge_base_number_page'
56 ]
57 ],
58 'limit_sites_number_page' => [
59 'check_callback' => [
60 '\Bitrix\Landing\Restriction\Landing', 'isCreatingAllowed'
61 ],
62 'scope_alias' => [
63 'knowledge' => 'limit_knowledge_base_number_page',
64 'group' => 'limit_knowledge_base_number_page'
65 ]
66 ],
67 'limit_knowledge_base_number_page' => [
68 'check_callback' => [
69 '\Bitrix\Landing\Restriction\Site', 'isCreatingAllowed'
70 ]
71 ],
72 'limit_knowledge_base_number_page_view' => [
73 'check_callback' => [
74 '\Bitrix\Landing\Restriction\Knowledge', 'isViewAllowed'
75 ]
76 ],
77 'limit_sites_dynamic_blocks' => [
78 'check_callback' => [
79 '\Bitrix\Landing\Restriction\Block', 'isDynamicEnabled'
80 ]
81 ],
82 'limit_crm_superblock' => [
83 'check_callback' => [
84 '\Bitrix\Landing\Restriction\Block', 'isDesignerAllowed'
85 ]
86 ],
87 'limit_crm_free_knowledge_base_project' => [
88 'check_callback' => [
89 '\Bitrix\Landing\Restriction\Knowledge', 'isAllowedInGroup'
90 ]
91 ],
92 'limit_crm_forms_templates' => [
93 'check_callback' => [
94 '\Bitrix\Landing\Restriction\Form', 'isMinisitesAllowed'
95 ]
96 ],
97 ];
98
103 protected static $tmpFeatures = [];
104
110 protected static function getMapItem(string $code): ?array
111 {
112 static $scopeId = null;
113
114 if (isset(self::MAP[$code]))
115 {
116 if ($scopeId === null)
117 {
118 $scopeId = strtolower(\Bitrix\Landing\Site\Type::getCurrentScopeId());
119 }
120 $item = self::MAP[$code];
121 $item['code'] = $item['scope_alias'][$scopeId] ?? $code;
122 return $item;
123 }
124 return null;
125 }
126
132 public static function getActionCode(string $code): ?string
133 {
134 if ($mapItem = self::getMapItem($code))
135 {
136 return 'top.BX.UI.InfoHelper.show("' . $mapItem['code'] . '");';
137 }
138 return null;
139 }
140
145 protected static function includeInformerComponent(): void
146 {
147 static $included = false;
148
149 if (!$included)
150 {
151 $included = true;
152 if (SITE_TEMPLATE_ID != 'bitrix24')
153 {
154 \Bitrix\Landing\Manager::getApplication()
155 ->includeComponent('bitrix:ui.info.helper', '', []);
156 }
157 }
158 }
159
166 public static function getLockIcon(?string $code, array $nodes = []): ?string
167 {
168 if ($mapItem = self::getMapItem($code))
169 {
170 self::includeInformerComponent();
171 $idCode = 'landing-tariff-' . \randString(5);
172 $nodes[] = $idCode;
173 $script = '
174 <script>
175 BX.ready(function()
176 {
177 var nodes = ' . \CUtil::phpToJSObject($nodes) . ';
178 for (var i = 0, c = nodes.length; i < c; i++)
179 {
180 BX.bind(BX(nodes[i]), "click", function(e)
181 {
182 ' . self::getActionCode($code) . '
183 BX.PreventDefault(e);
184 });
185 }
186 });
187 </script>
188 ';
189 return $script . '<span class="tariff-lock" id="' . $idCode . '"></span>';
190 }
191 return null;
192 }
193
198 public static function getSystemErrorMessage($code): ?string
199 {
200 if ($mapItem = self::getMapItem($code))
201 {
202 return Loc::getMessage('LANDING_' . strtoupper($mapItem['code']));
203 }
204 return Loc::getMessage('LANDING_' . strtoupper($code));
205 }
206
214 public static function isAllowed(string $code, array $params = [], string $cacheSalt = ''): bool
215 {
216 static $cache = [];
217 if (
218 isset(self::$tmpFeatures[$code]) &&
219 self::$tmpFeatures[$code]
220 )
221 {
222 return true;
223 }
224
225 $cacheCode = $code . ($cacheSalt ? '_' : '') . $cacheSalt;
226
227 if (array_key_exists($cacheCode, $cache))
228 {
229 return $cache[$cacheCode];
230 }
231
232 if ($mapItem = self::getMapItem($code))
233 {
234 $cache[$cacheCode] = call_user_func_array($mapItem['check_callback'], [$mapItem['code'], $params]);
235 return $cache[$cacheCode];
236 }
237
238 return true;
239 }
240
246 public static function enableFeatureTmp($feature)
247 {
248 self::$tmpFeatures[$feature] = true;
249 }
250
256 public static function disableFeatureTmp($feature)
257 {
258 if (isset(self::$tmpFeatures[$feature]))
259 {
260 unset(self::$tmpFeatures[$feature]);
261 }
262 }
263
268 public static function disableAllFeaturesTmp()
269 {
270 self::$tmpFeatures = [];
271 }
272}
static getLockIcon(?string $code, array $nodes=[])
Definition manager.php:166
static enableFeatureTmp($feature)
Definition manager.php:246
static isAllowed(string $code, array $params=[], string $cacheSalt='')
Definition manager.php:214
static getActionCode(string $code)
Definition manager.php:132
static disableFeatureTmp($feature)
Definition manager.php:256
static getMapItem(string $code)
Definition manager.php:110
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29