1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
site.php
См. документацию.
1<?php
2namespace Bitrix\Landing\Restriction;
3
4use Bitrix\Bitrix24\Feature;
5use Bitrix\Bitrix24\PhoneVerify;
6use Bitrix\Landing\Manager;
7use Bitrix\Main\Config\Option;
8use Bitrix\Main\Entity;
9use Bitrix\Landing\Domain;
10use Bitrix\Landing\Rights;
11use Bitrix\Landing\Site as SiteCore;
12use Bitrix\Main\Loader;
13use Bitrix\Main\Type\DateTime;
14
15class Site
16{
21
25 private const LIMIT_BY_TEMPLATES_MINIMAL = [
26 'store-chats' => 1,
27 ];
28
32 private const OVER_LIMIT_TEMPLATES = [
33 'store-chats'
34 ];
35
39 private const NEW_STORE_CODE = 'store_v3';
40
47 private static function checkLimitByTemplates(array $filter, int $limit): bool
48 {
49 $sites = [];
50 $currentSiteId = null;
51 $currentSiteTemplate = null;
52
53 if (isset($filter['!ID']))
54 {
55 $currentSiteId = $filter['!ID'];
56 }
57
58 // get all sites (active) and group by templates
59 $res = SiteCore::getList([
60 'select' => [
61 'ID', 'XML_ID', 'TPL_CODE'
62 ],
63 'filter' => $filter
64 ]);
65 while ($row = $res->fetch())
66 {
67 $sites[] = $row;
68 }
69
70 // current site
71 if ($currentSiteId)
72 {
73 $res = SiteCore::getList([
74 'select' => [
75 'ID', 'XML_ID', 'TPL_CODE'
76 ],
77 'filter' => [
78 'CHECK_PERMISSIONS' => 'N',
79 'ID' => $currentSiteId
80 ]
81 ]);
82 if ($row = $res->fetch())
83 {
84 $sites[] = $row;
85 }
86 }
87
88 // calc templates
89 $templates = [];
90 $templatesCount = 0;
91 $templatesLimits = self::LIMIT_BY_TEMPLATES_MINIMAL;
92 // $templatesLimits['%'] = max($limit, 1);
93 $limit = max($limit, 1);
94 foreach ($sites as $row)
95 {
96 if (!$row['TPL_CODE'])
97 {
98 if (mb_strpos($row['XML_ID'], '|') !== false)
99 {
100 [, $row['TPL_CODE']] = explode('|', $row['XML_ID']);
101 }
102 }
103
104 // store-chat-dark === store-chat-light === store-chat
105 foreach ($templatesLimits as $code => $cnt)
106 {
107 if (strpos($row['TPL_CODE'], $code) === 0)
108 {
109 $row['TPL_CODE'] = $code;
110 break;
111 }
112 }
113
114 if ($currentSiteId && $currentSiteId === $row['ID'])
115 {
116 $currentSiteTemplate = $row['TPL_CODE'];
117 }
118
119 if (!($templates[$row['TPL_CODE']] ?? null))
120 {
121 $templates[$row['TPL_CODE']] = 0;
122 }
123 $templates[$row['TPL_CODE']]++;
124
125 if (!in_array($row['TPL_CODE'], self::OVER_LIMIT_TEMPLATES, true))
126 {
127 $templatesCount++;
128 }
129 }
130
131 // special limit for store v3
132 if (
133 $currentSiteTemplate
134 && $currentSiteTemplate === self::NEW_STORE_CODE
135 && self::isNew2021Tariff()
136 )
137 {
138 \CBitrixComponent::includeComponentClass('bitrix:landing.site_master');
139 $optionName = \LandingSiteMasterComponent::getShopInstallCountOptionName($currentSiteTemplate);
140 if ((int)Manager::getOption($optionName, 0) <= 1)
141 {
142 $limit++;
143 }
144 }
145
146 // calc limits
147 if (
148 $currentSiteTemplate
149 && in_array($row['TPL_CODE'], self::OVER_LIMIT_TEMPLATES, true)
150 )
151 {
152 return true;
153 }
154
155 if ($templates)
156 {
157 foreach ($templatesLimits as $code => $templateLimit)
158 {
159 if (
160 isset($templates[$code])
161 && $templates[$code] > $templateLimit
162 )
163 {
164 return false;
165 }
166 }
167 }
168
169 if ($limit < $templatesCount)
170 {
171 return false;
172 }
173
174 return true;
175 }
176
177 protected static function isNew2021Tariff(): bool
178 {
179 if (!Loader::includeModule('bitrix24'))
180 {
181 return false;
182 }
183
184 return in_array(
185 \CBitrix24::getLicenseType(),
186 ['basic', 'std', 'pro']
187 );
188 }
189
196 public static function isCreatingAllowed(string $code, array $params): bool
197 {
198 if (!Loader::includeModule('bitrix24'))
199 {
200 return true;
201 }
202
203 if (
204 $params['action_type'] === 'publication'
207 )
208 {
209 if (!isset($params['filter']['!ID']))
210 {
211 return false;
212 }
213
214 $siteId = $params['filter']['!ID'];
215 $site = SiteCore::getList([
216 'select' => ['ID' , 'DATE_CREATE'],
217 'filter' => ['ID' => $siteId],
218 ])->fetch();
219 $dateWhenClosedFree = DateTime::createFromTimestamp('1646238000'); //02.03.2022 16:20:00
220 if ($site['DATE_CREATE']->getTimestamp() >= $dateWhenClosedFree->getTimestamp())
221 {
222 return false;
223 }
224 }
225
226 $optPrefix = 'landing_site_';
227 $optSuffix = ($params['action_type'] == 'publication') ? '_publication' : '';
228 $variableCode = $optPrefix . strtolower($params['type']) . $optSuffix;
229 $limit = (int) Feature::getVariable($variableCode);
230
231 if ($limit)
232 {
233 $filter = [
234 'CHECK_PERMISSIONS' => 'N',
235 '=TYPE' => $params['type'],
236 '=SPECIAL' => 'N'
237 ];
238
239 if ($params['action_type'] == 'publication')
240 {
241 $filter['=ACTIVE'] = 'Y';
242 }
243
244 if (
245 isset($params['filter']) &&
246 is_array($params['filter'])
247 )
248 {
249 $filter = array_merge(
250 $filter,
251 $params['filter']
252 );
253 }
254
255 if ($params['action_type'] === 'publication' && $params['type'] === 'STORE')
256 {
257 return self::checkLimitByTemplates($filter, $limit);
258 }
259
260 $check = SiteCore::getList([
261 'select' => [
262 'CNT' => new Entity\ExpressionField('CNT', 'COUNT(*)')
263 ],
264 'filter' => $filter,
265 'group' => []
266 ])->fetch();
267 if ($check && $check['CNT'] >= $limit)
268 {
269 return false;
270 }
271 }
272
273 return true;
274 }
275
282 public static function isFreeDomainAllowed(string $code, array $params): bool
283 {
284 // free domain is available in cloud version only
285 if (!Loader::includeModule('bitrix24'))
286 {
287 return false;
288 }
289
290 $availableCount = Feature::getVariable(
291 'landing_free_domain'
292 );
293 if ($availableCount === null)
294 {
295 return false;
296 }
297 if (($params['trueOnNotNull'] ?? false))
298 {
299 return true;
300 }
301 if ($availableCount > 0)
302 {
303 $check = Domain::getList([
304 'select' => [
305 'CNT' => new Entity\ExpressionField('CNT', 'COUNT(*)')
306 ],
307 'filter' => [
308 '!PROVIDER' => null
309 ],
310 'group' => []
311 ])->fetch();
312 if ($check && $check['CNT'] >= $availableCount)
313 {
314 return false;
315 }
316 }
317 return true;
318 }
319
326 public static function manageFreeDomains(bool $setActive, int $executeAfterSeconds = 0): void
327 {
328 $methodName = __CLASS__ . '::' . __FUNCTION__ . '(' . ($setActive ? 'true' : 'false') . ');';
329
330 if ($executeAfterSeconds > 0)
331 {
332 $dateTime = new DateTime();
333 \CAgent::addAgent(
334 $methodName,
335 'landing', 'N', 0, '', 'Y',
336 $dateTime->add('+' . $executeAfterSeconds . ' seconds')
337 );
338 return;
339 }
340 if ($setActive)
341 {
342 \CAgent::removeAgent($methodName, 'landing');
343 }
344
346 $res = SiteCore::getList([
347 'select' => [
348 'ID',
349 'ACTIVE',
350 'DOMAIN_ID'
351 ],
352 'filter' => [
353 '=DOMAIN.ACTIVE' => $setActive ? 'N' : 'Y',
354 '!DOMAIN.PROVIDER' => null
355 ]
356 ]);
357 while ($site = $res->fetch())
358 {
359 if ($site['ACTIVE'] === ($setActive ? 'N' : 'Y'))
360 {
361 SiteCore::update($site['ID'], [
362 'ACTIVE' => $setActive ? 'Y' : 'N'
363 ])->isSuccess();
364 }
365 Domain::update($site['DOMAIN_ID'], [
366 'ACTIVE' => $setActive ? 'Y' : 'N'
367 ])->isSuccess();
368 }
370 }
371
376 public static function getFreeDomainSuspendedTime(): int
377 {
378 $tariffTtl = 0;
379 $resetFreeTime = Manager::getOption('reset_to_free_time');
380 if ($resetFreeTime)
381 {
382 $tariffTtl = $resetFreeTime + self::FREE_DOMAIN_GRACE_DAYS * 86400;
383 }
384
385 return $tariffTtl;
386 }
387
392 public static function isExportAllowed(): bool
393 {
394 if (Loader::includeModule('bitrix24'))
395 {
396 return Feature::isFeatureEnabled('landing_allow_export');
397 }
398
399 return true;
400 }
401
406 public static function isTermsFooterShow(): bool
407 {
408 if (Loader::includeModule('bitrix24'))
409 {
410 return !Feature::isFeatureEnabled('landing_hide_terms_footer');
411 }
412
413 return false;
414 }
415
421 public static function isEmailConfirmed(int $siteId): bool
422 {
423 static $checkedSites = [];
424
425 if (array_key_exists($siteId, $checkedSites))
426 {
427 return $checkedSites[$siteId];
428 }
429
430 $checkedSites[$siteId] = true;
431
432 if (Loader::includeModule('bitrix24'))
433 {
434 if (!\CBitrix24::isEmailConfirmed())
435 {
436 $checkedSites[$siteId] = false;
437 }
438 }
439
440 return $checkedSites[$siteId];
441 }
442
448 public static function isPhoneConfirmed(int $siteId): bool
449 {
450 static $checkedSites = [];
451
452 if (array_key_exists($siteId, $checkedSites))
453 {
454 return $checkedSites[$siteId];
455 }
456
457 $checkedSites[$siteId] = true;
458
459 if (Loader::includeModule('bitrix24'))
460 {
461 $checkedSites[$siteId] = (new PhoneVerify('landing_site', $siteId))->isVerified();
462 }
463
464 return $checkedSites[$siteId];
465 }
466
467 public static function unpublishByScannerLockPortal(): bool
468 {
470 $sites = SiteCore::getList([
471 'select' => [
472 'ID'
473 ],
474 'filter' => [
475 'ACTIVE' => 'Y',
476 'DELETED' => 'N'
477 ],
478 'order' => [
479 'ID' => 'ASC'
480 ]
481 ]);
482 $ids = [];
483 while ($site = $sites->fetch())
484 {
485 $res = SiteCore::unpublic($site['ID']);
486 if ($res->isSuccess())
487 {
488 $ids[] = $site['ID'];
489 }
490 }
491 $stringIds = implode(',', $ids);
492 Option::set('landing', 'unpublished_ids', $stringIds);
494
495 return true;
496 }
497
498 public static function publishByLicenseChange(): void
499 {
500 \Bitrix\Main\Update\Stepper::bindClass('Bitrix\Landing\Update\Site\Publish', 'landing', 10);
501 }
502
503 public static function checkLimitsByLicenseChange(): void
504 {
506 $sites = SiteCore::getList([
507 'select' => [
508 'ID', 'DATE_CREATE'
509 ],
510 'filter' => [
511 'ACTIVE' => 'Y',
512 'DELETED' => 'N'
513 ],
514 'order' => [
515 'DATE_CREATE' => 'DESC'
516 ]
517 ]);
518 while ($site = $sites->fetch())
519 {
520 $params = [
521 'filter' => [
522 '!ID' => $site['ID'],
523 ],
524 'type' => 'PAGE',
525 'action_type' => 'publication',
526 ];
527 if (!self::isCreatingAllowed('limit_sites_number', $params))
528 {
529 SiteCore::unpublic($site['ID']);
530 }
531 }
533 }
534}
static getOption($code, $default=null)
Определения manager.php:160
static isFreePublicAllowed()
Определения manager.php:1298
static licenseIsFreeSite(string $type)
Определения manager.php:1288
static isCreatingAllowed(string $code, array $params)
Определения site.php:196
static publishByLicenseChange()
Определения site.php:498
static isTermsFooterShow()
Определения site.php:406
static isEmailConfirmed(int $siteId)
Определения site.php:421
static getFreeDomainSuspendedTime()
Определения site.php:376
static unpublishByScannerLockPortal()
Определения site.php:467
const FREE_DOMAIN_GRACE_DAYS
Определения site.php:20
static manageFreeDomains(bool $setActive, int $executeAfterSeconds=0)
Определения site.php:326
static checkLimitsByLicenseChange()
Определения site.php:503
static isExportAllowed()
Определения site.php:392
static isFreeDomainAllowed(string $code, array $params)
Определения site.php:282
static isNew2021Tariff()
Определения site.php:177
static isPhoneConfirmed(int $siteId)
Определения site.php:448
static setGlobalOn()
Определения rights.php:116
static setGlobalOff()
Определения rights.php:107
$sites
Определения clear_component_cache.php:15
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$filter
Определения iblock_catalog_list.php:54
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$siteId
Определения ajax.php:8
Определения cookies.php:2
Определения ufield.php:9
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$optionName
Определения options.php:1735
$site
Определения yandex_run.php:614