1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
type.php
См. документацию.
1<?php
2namespace Bitrix\Landing\Site;
3
4use Bitrix\Landing\Role;
5use Bitrix\Landing\Site;
6use Bitrix\Main\Event;
7use Bitrix\SignSafe\Processing\Preview;
8
9class Type
10{
14 public const SCOPE_CODE_GROUP = 'GROUP';
15
19 public const SCOPE_CODE_KNOWLEDGE = 'KNOWLEDGE';
20
24 public const SCOPE_CODE_MAINPAGE = 'MAINPAGE';
25
29 public const PSEUDO_SCOPE_CODE_FORMS = 'crm_forms';
30
31 protected const SCOPES_NOT_PUBLIC = [
32 self::SCOPE_CODE_GROUP,
33 self::SCOPE_CODE_KNOWLEDGE,
34 self::SCOPE_CODE_MAINPAGE,
35 ];
36
41 protected static $currentScopeClass = null;
42
47 protected static $scopeInit = false;
48
54 protected static function getScopeClass($scope): ?string
55 {
56 $scope = trim($scope);
57 $class = __NAMESPACE__ . '\\Scope\\' . $scope;
58 if (class_exists($class))
59 {
60 return $class;
61 }
62
63 return null;
64 }
65
72 public static function getSiteSpecialType(string $siteCode): ?string
73 {
74 if (preg_match('#^/' . self::PSEUDO_SCOPE_CODE_FORMS . '\d*/$#', $siteCode))
75 {
76 return self::PSEUDO_SCOPE_CODE_FORMS;
77 }
78
79 return null;
80 }
81
88 public static function setScope($scope, array $params = []): void
89 {
90 if (!is_string($scope) || !$scope)
91 {
92 return;
93 }
94 // always clear previous scope
96 self::$scopeInit = false;
97 self::$currentScopeClass = self::getScopeClass($scope);
98 if (self::$currentScopeClass)
99 {
100 self::$scopeInit = true;
101 self::$currentScopeClass::init($params);
102 }
103 }
104
109 public static function clearScope(): void
110 {
111 self::$scopeInit = false;
112 self::$currentScopeClass = null;
113 }
114
120 public static function isPublicScope(?string $scope = null): bool
121 {
122 $scope = $scope ? mb_strtoupper($scope) : self::getCurrentScopeId();
123
124 return !in_array($scope, self::SCOPES_NOT_PUBLIC);
125 }
126
131 public static function getPublicationPath()
132 {
133 $path = null;
134 $scope = null;
135
136 if (self::$currentScopeClass !== null)
137 {
138 $path = self::$currentScopeClass::getPublicationPath();
139 $scope = self::$currentScopeClass::getCurrentScopeId();
140 }
141
142 // custom for Preview
143 $event = new Event('landing', 'onGetScopePublicationPath', [
144 'scope' => $scope,
145 'path' => $path
146 ]);
147 $event->send();
148 foreach ($event->getResults() as $result)
149 {
150 $path = $result->getModified()['path'] ?? $path;
151 }
152
153 return $path;
154 }
155
160 public static function getKeyCode()
161 {
162 if (self::$currentScopeClass !== null)
163 {
164 return self::$currentScopeClass::getKeyCode();
165 }
166
167 return 'ID';
168 }
169
174 public static function getDomainId()
175 {
176 if (self::$currentScopeClass !== null)
177 {
178 return self::$currentScopeClass::getDomainId();
179 }
180
181 return '';
182 }
183
188 public static function getCurrentScopeId()
189 {
190 if (self::$currentScopeClass !== null)
191 {
192 return self::$currentScopeClass::getCurrentScopeId();
193 }
194
195 return null;
196 }
197
203 public static function getFilterType($strict = false)
204 {
205 if (self::$currentScopeClass !== null)
206 {
207 return self::$currentScopeClass::getFilterType();
208 }
209
210 // compatibility, huh
211 return $strict ? null : ['PAGE', 'STORE', 'SMN'];
212 }
213
218 public static function getExcludedHooks(): array
219 {
220 if (self::$currentScopeClass !== null)
221 {
222 return self::$currentScopeClass::getExcludedHooks();
223 }
224
225 return [];
226 }
227
233 public static function isEnabled($code)
234 {
235 if (is_string($code))
236 {
237 $code = mb_strtoupper(trim($code));
238 $types = Site::getTypes();
239 if (array_key_exists($code, $types))
240 {
241 return true;
242 }
243 }
244
245 return false;
246 }
247
254 public static function getOperationsForSite(int $siteId): ?array
255 {
256 if (
257 self::$currentScopeClass !== null
258 && is_callable([self::$currentScopeClass, 'getOperationsForSite'])
259 )
260 {
261 return self::$currentScopeClass::getOperationsForSite($siteId);
262 }
263
264 return null;
265 }
266
272 public static function prepareBlockManifest(array $manifest): array
273 {
274 if (
275 self::$currentScopeClass !== null
276 && is_callable([self::$currentScopeClass, 'prepareBlockManifest'])
277 )
278 {
279 return self::$currentScopeClass::prepareBlockManifest($manifest);
280 }
281
282 return $manifest;
283 }
284}
$path
Определения access_edit.php:21
static setExpectedType($type)
Определения role.php:537
static getPublicationPath()
Определения type.php:131
static getSiteSpecialType(string $siteCode)
Определения type.php:72
static getOperationsForSite(int $siteId)
Определения type.php:254
static getExcludedHooks()
Определения type.php:218
static clearScope()
Определения type.php:109
const SCOPE_CODE_KNOWLEDGE
Определения type.php:19
static isEnabled($code)
Определения type.php:233
static setScope($scope, array $params=[])
Определения type.php:88
static getScopeClass($scope)
Определения type.php:54
static getKeyCode()
Определения type.php:160
const SCOPES_NOT_PUBLIC
Определения type.php:31
static isPublicScope(?string $scope=null)
Определения type.php:120
const SCOPE_CODE_MAINPAGE
Определения type.php:24
static $currentScopeClass
Определения type.php:41
static getFilterType($strict=false)
Определения type.php:203
const PSEUDO_SCOPE_CODE_FORMS
Определения type.php:29
static getDomainId()
Определения type.php:174
static $scopeInit
Определения type.php:47
const SCOPE_CODE_GROUP
Определения type.php:14
static getCurrentScopeId()
Определения type.php:188
static prepareBlockManifest(array $manifest)
Определения type.php:272
Определения event.php:5
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$siteId
Определения ajax.php:8
$event
Определения prolog_after.php:141
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799