Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
manager.php
1<?php
2namespace Bitrix\Landing;
3
4use \Bitrix\Main\Localization\Loc;
5use \Bitrix\Main\Config\Option;
6use \Bitrix\Main\Application;
7use \Bitrix\Main\Loader;
8use \Bitrix\Main\ModuleManager;
9use \Bitrix\Landing\Assets;
10
11Loc::loadMessages(__FILE__);
12
14{
20
25 const PUBLICATION_PATH = '/pub/site/';
27
31 const BUY_LICENSE_PATH = '/bitrix/tools/landing/ajax.php?redirect=upgrade';
32
36 const FEATURE_CREATE_SITE = 'create_site';
37 const FEATURE_CREATE_PAGE = 'create_page';
38 const FEATURE_CUSTOM_DOMAIN = 'custom_domain';
39 const FEATURE_ENABLE_ALL_HOOKS = 'enable_all_hooks';
40 const FEATURE_PUBLICATION_SITE = 'publication_site';
41 const FEATURE_PUBLICATION_PAGE = 'publication_page';
42 const FEATURE_PERMISSIONS_AVAILABLE = 'permissions_available';
43 const FEATURE_DYNAMIC_BLOCK = 'dynamic_block';
44 const FEATURE_FREE_DOMAIN = 'free_domain';
45 const FEATURE_ALLOW_EXPORT = 'allow_export';
46 const FEATURE_ALLOW_VIEW_PAGE = 'allow_view_page';
47
52 protected static $forceB24disable = false;
53
58 protected static $tmpFeatures = [];
59
65 private static $themeTypoId = '';
66
71 public static function getApplication()
72 {
73 return $GLOBALS['APPLICATION'];
74 }
75
80 public static function getUserInstance()
81 {
82 return $GLOBALS['USER'];
83 }
84
89 public static function getCacheManager()
90 {
91 return $GLOBALS['CACHE_MANAGER'];
92 }
93
98 public static function getUfManager()
99 {
100 return $GLOBALS['USER_FIELD_MANAGER'];
101 }
102
107 public static function getUserId(): int
108 {
109 $user = self::getUserInstance();
110 if ($user instanceof \CUser)
111 {
112 return (int)$user->getId();
113 }
114 return 0;
115 }
116
121 public static function getUserFullName()
122 {
123 $user = self::getUserInstance();
124 if ($user instanceof \CUser)
125 {
126 return $user->getFullName();
127 }
128 return '';
129 }
130
135 public static function isAdmin()
136 {
137 $user = self::getUserInstance();
138
139 if (!($user instanceof \CUser))
140 {
141 return false;
142 }
143
144 if (ModuleManager::isModuleInstalled('bitrix24'))
145 {
146 return $user->canDoOperation('bitrix24_config');
147 }
148 else
149 {
150 return $user->isAdmin();
151 }
152 }
153
160 public static function getOption($code, $default = null)
161 {
162 return Option::get('landing', $code, $default);
163 }
164
171 public static function setOption($code, $value)
172 {
173 Option::set('landing', $code, $value);
174 }
175
180 public static function getDocRoot()
181 {
182 static $docRoot = null;
183
184 if ($docRoot === null)
185 {
186 $context = Application::getInstance()->getContext();
187 $server = $context->getServer();
188 $docRoot = $server->getDocumentRoot();
189 }
190
191 return $docRoot;
192 }
193
198 public static function getCurDir()
199 {
200 return Application::getInstance()->getContext()
201 ->getRequest()
202 ->getRequestedPageDirectory();
203 }
204
211 public static function setPageTitle($title, $single = false)
212 {
213 static $application = null;
214 static $disable = false;
215
216 if ($application === null)
217 {
218 $application = self::getApplication();
219 }
220
221 if ($title && !$disable)
222 {
223 $application->setTitle($title);
224 $application->setPageProperty('title', $title);
225 if ($single)
226 {
227 $disable = true;
228 }
229 }
230 }
231
237 protected static function getMainSiteById(string $siteId)
238 {
239 static $sites = [];
240
241 if (!array_key_exists($siteId, $sites))
242 {
243 $sites[$siteId] = \Bitrix\Main\SiteTable::getById($siteId)->fetch();
244 }
245
246 return $sites[$siteId];
247 }
248
255 protected static function createPublicationPath(string $basePath, string $siteId = null): void
256 {
257 static $paths = [];
258
259 if (!in_array($basePath, $paths))
260 {
261 $paths[] = $basePath;
262
263 if (mb_substr($basePath, 0, 1) != '/')
264 {
265 $basePath = '/' . $basePath;
266 }
267 if (mb_substr($basePath, -1) != '/')
268 {
269 $basePath = $basePath . '/';
270 }
271
272 $docRoot = '';
273 $subDirSite = '';
274 $basePathOriginal = $basePath;
275
276 // gets current doc root or gets from the site
277 if ($siteId)
278 {
279 if ($smnSite = self::getMainSiteById($siteId))
280 {
281 if ($smnSite['DOC_ROOT'])
282 {
283 $docRoot = $smnSite['DOC_ROOT'] . $smnSite['DIR'];
284 }
285 else
286 {
287 $docRoot = self::getDocRoot() . $smnSite['DIR'];
288 }
289 $subDirSite = rtrim($smnSite['DIR'], '/');
290 }
291 $docRoot = rtrim($docRoot, '/');
292 }
293 if (!$docRoot)
294 {
295 $docRoot = self::getDocRoot();
296 }
297 $basePath = $docRoot . $basePath;
298
299 // create path
300 if (\checkDirPath($basePath))
301 {
302 if (!file_exists($basePath . 'index.php'))
303 {
304 \rewriteFile(
305 $basePath . 'index.php',
306 file_get_contents(
307 self::getDocRoot() .
308 '/bitrix/modules/landing/install/pub/site/index.php'
309 )
310 );
311 }
312 }
313 // and add template rules for main
314 if ($siteId)
315 {
316 $fields = array(
317 'SORT' => 0,
318 'SITE_ID' => $siteId,
319 'CONDITION' => 'CSite::inDir(\'' . $subDirSite . $basePathOriginal . '\')',
320 'TEMPLATE' => self::getTemplateId($siteId)
321 );
322 $check = \Bitrix\Main\SiteTemplateTable::getList(array(
323 'filter' => array(
324 '=SITE_ID' => $fields['SITE_ID'],
325 '=CONDITION' => $fields['CONDITION'],
326 '=TEMPLATE' => $fields['TEMPLATE']
327 )
328 ))->fetch();
329 if (!$check)
330 {
331 \Bitrix\Main\SiteTemplateTable::add(
332 $fields
333 );
334 \Bitrix\Main\UrlRewriter::add(
335 $siteId,
336 array(
337 'ID' => 'bitrix:landing.pub',
338 'PATH' => $subDirSite. $basePathOriginal . 'index.php',
339 'CONDITION' => '#^' . $subDirSite. $basePathOriginal . '#'
340 )
341 );
342 self::getCacheManager()->clean('b_site_template');
343 }
344 }
345 }
346 }
347
353 protected static function getSmnSiteDir(?string $siteId): string
354 {
355 static $sites = [];
356
357 if (!$siteId)
358 {
359 $siteId = SITE_ID;
360 }
361
362 if (!isset($sites[$siteId]))
363 {
364 $sites[$siteId] = '';
365 if ($smnSite = self::getMainSiteById($siteId))
366 {
367 $sites[$siteId] = rtrim($smnSite['DIR'], '/');
368 }
369 }
370
371 return $sites[$siteId];
372 }
373
378 public static function getPublicationPathConst()
379 {
380 if (defined('LANDING_PUBLICATION_PATH_CONST'))
381 {
382 return LANDING_PUBLICATION_PATH_CONST;
383 }
384 return self::isB24()
385 ? self::PUBLICATION_PATH
386 : self::PUBLICATION_PATH_SITEMAN;
387 }
388
396 public static function getPublicationPath($siteCode = null, $siteId = null, $createPubPath = false)
397 {
398 $tyePublicationPath = Site\Type::getPublicationPath();
399
400 $basePath = $tyePublicationPath;
401 if ($basePath === null)
402 {
403 $basePath = self::getOption(
404 'pub_path_' . (!isset($siteId) ? (self::getMainSiteId()) : $siteId),
405 self::getPublicationPathConst()
406 );
407 }
408 $subDir = self::getSmnSiteDir($siteId);
409 if ($siteCode === null)
410 {
411 if (
412 $createPubPath &&
413 ModuleManager::isModuleInstalled('bitrix24')
414 )
415 {
416 $createPubPath = false;
417 }
418 if ($createPubPath && $siteId)
419 {
420 self::createPublicationPath(
421 $basePath,
422 $siteId
423 );
424 }
425 return $subDir . $basePath;
426 }
427 else
428 {
429 return $subDir . str_replace(
430 '#id#',
431 $siteCode,
432 $basePath . '#id#/'
433 );
434 }
435 }
436
437 public static function isAutoPublicationEnabled(): bool
438 {
439 return
440 Site\Type::isPublicScope()
441 && \CUserOptions::getOption('landing', 'auto_publication', 'Y') === 'Y'
442 ;
443 }
444
452 public static function setPageClass($marker, $class)
453 {
454 self::setPageView($marker, $class);
455 }
456
465 public static function setPageView(string $marker, string $content, bool $skipTrim = false): void
466 {
467 if (!$skipTrim)
468 {
469 $content = trim($content);
470 }
471
472 if ($content)
473 {
474 $application = self::getApplication();
475 $existContent = $application->getPageProperty($marker);
476 $application->setPageProperty(
477 $marker,
478 $existContent . ($existContent != '' ? ' ' : '') . $content
479 );
480 }
481 }
482
488 public static function clearPageView($marker): void
489 {
490 self::getApplication()->setPageProperty($marker, '');
491 }
492
498 public static function getPageView($marker)
499 {
500 return self::getApplication()->getPageProperty($marker);
501 }
502
508 public static function getTemplateId($siteId = null)
509 {
510 static $tplId = [];
511
512 if (!isset($tplId[$siteId]))
513 {
514 if ($siteId)
515 {
516 $tplId[$siteId] = self::getOption('site_template_id_' . $siteId);
517 }
518 if (!$tplId[$siteId])
519 {
520 $tplId[$siteId] = self::getOption('site_template_id', 'landing24');
521 }
522 }
523
524 return $tplId[$siteId];
525 }
526
532 public static function isTemplateIdSystem($templateId)
533 {
534 return $templateId === 'landing24';
535 }
536
541 public static function getMainSiteId()
542 {
543 return defined('SMN_SITE_ID') ? SMN_SITE_ID : SITE_ID;
544 }
545
551 public static function getRandomString(int $length): string
552 {
553 return mb_strtolower(\Bitrix\Main\Security\Random::getStringByCharsets($length, 'abcdefghijklmnopqrstuvwxyz'));
554 }
555
562 public static function setThemeTypoId($themeTypoId)
563 {
564 self::$themeTypoId = $themeTypoId;
565 }
566
572 public static function initAssets($lid = 0)
573 {
574 $assets = Assets\Manager::getInstance();
575 $assets->setOutput($lid);
576 }
577
585 public static function savePicture($file, $ext = false, $params = array())
586 {
587 // local file
588 if (!is_array($file) && mb_substr($file, 0, 1) == '/')
589 {
590 $file = \CFile::makeFileArray($file);
591 }
592 // url of picture
593 else if (!is_array($file))
594 {
595 $httpClient = new \Bitrix\Main\Web\HttpClient();
596 $httpClient->setPrivateIp(false);
597 $httpClient->setTimeout(5);
598 $httpClient->setStreamTimeout(5);
599 $urlComponents = parse_url($file);
600
601 // detect tmp file name
602 if ($urlComponents && $urlComponents['path'] != '')
603 {
604 $tempPath = \CFile::getTempName('', bx_basename(urldecode($urlComponents['path'])));
605 }
606 else
607 {
608 $tempPath = \CFile::getTempName('', bx_basename(urldecode($file)));
609 }
610 if ($ext !== false && in_array($ext, explode(',', \CFile::getImageExtensions())))
611 {
612 if (mb_substr($tempPath, -3) != $ext)
613 {
614 $tempPath = $tempPath . '.' . $ext;
615 }
616 }
617
618 // download and save
619 if ($httpClient->download($file, $tempPath))
620 {
621 $fileName = $httpClient->getHeaders()->getFilename();
622 $file = \CFile::makeFileArray($tempPath);
623 if ($file && $fileName)
624 {
625 $file['name'] = $fileName;
626 }
627 }
628 }
629
630 // base64
631 elseif (
632 is_array($file) &&
633 isset($file[0]) &&
634 isset($file[1])
635 )
636 {
637 $fileParts = explode('.', $file[0]);
638 $ext = array_pop($fileParts);
639 $tempPath = \CFile::getTempName(
640 '',
641 \CUtil::translit(
642 implode('', $fileParts),
643 'ru'
644 ) . '.' . $ext
645 );
646 $fileIO = new \Bitrix\Main\IO\File(
647 $tempPath
648 );
649 $fileIO->putContents(
650 base64_decode($file[1])
651 );
652 $file = \CFile::makeFileArray($tempPath);
653 }
654
655 $isSvg = false;
656 $isImage = \CFile::checkImageFile($file, 0, 0, 0, array('IMAGE')) === null;
657
658 if (!$isImage && (Manager::getOption('allow_svg_content') === 'Y'))
659 {
660 $extension = \getFileExtension(mb_strtolower($file['name']));
661 if ($extension === 'svg')
662 {
663 $isSvg = true;
664 }
665 }
666
667 // post array or file from prev. steps
668 if ($isImage || $isSvg)
669 {
670 // resize if needed
671 if (
672 $isImage &&
673 isset($params['width']) &&
674 isset($params['height'])
675 )
676 {
677 \CFile::resizeImage(
678 $file,
679 $params,
680 isset($params['resize_type'])
681 ? intval($params['resize_type'])
682 : BX_RESIZE_IMAGE_PROPORTIONAL);
683 }
684 // if duplicate change size little (bug #167903)
685 if ($isImage && self::isDuplicateExistsInAnotherModule($file['tmp_name'], $file['size']))
686 {
687 [$width, $height] = getimagesize($file['tmp_name']) ?: [0, 0];
688 if ($width && $height)
689 {
690 \CFile::resizeImage($file, ['width' => $width-1, 'height' => $height-1]);
691 }
692 }
693 // save
694 $module = 'landing';
695 $file['name'] = File::transliterateFileName($file['name']);
696 $file['name'] = File::sanitizeFileName($file['name']);
697 $file['MODULE_ID'] = $module;
698 $file = \CFile::saveFile($file, $module);
699 if ($file)
700 {
701 $file = \CFile::getFileArray($file);
702 }
703 if ($file)
704 {
705 $file['SRC'] = str_replace(
706 '%',
707 '%25',
708 $file['SRC']
709 );
710 return $file;
711 }
712 }
713
714 return false;
715 }
716
723 private static function isDuplicateExistsInAnotherModule(string $filePath, int $size): bool
724 {
725 $hash = self::calculateHash($filePath, $size);
726 if (!$hash)
727 {
728 return false;
729 }
730
731 $original = \CFile::findDuplicate($size, $hash);
732 if ($original === null)
733 {
734 return false;
735 }
736
737 // we allow duplicate only within from current module
738 return $original->getFile()->getModuleId() !== 'landing';
739 }
740
748 private static function calculateHash(string $filePath, int $size): string
749 {
750 $hash = '';
751
752 if ($size > 0 && Option::get('main', 'control_file_duplicates', 'N') === 'Y')
753 {
754 $maxSize = (int)Option::get('main', 'duplicates_max_size', '100') * 1024 * 1024; //Mbytes
755 if ($size <= $maxSize || $maxSize === 0)
756 {
757 $hash = hash_file('md5', $filePath);
758 }
759 }
760
761 return $hash;
762 }
763
769 public static function enableFeatureTmp($feature)
770 {
771 self::$tmpFeatures[$feature] = true;
772 }
773
779 public static function disableFeatureTmp($feature)
780 {
781 if (isset(self::$tmpFeatures[$feature]))
782 {
783 unset(self::$tmpFeatures[$feature]);
784 }
785 }
786
791 public static function disableAllFeaturesTmp()
792 {
793 self::$tmpFeatures = [];
794 }
795
802 public static function checkMultiFeature(array $features, array $params = [])
803 {
804 $features = array_unique($features);
805
806 foreach ($features as $feature)
807 {
808 if (is_string($feature))
809 {
810 $check = self::checkFeature($feature, $params);
811 if (!$check)
812 {
813 return false;
814 }
815 }
816 else
817 {
818 return false;
819 }
820 }
821
822 return true;
823 }
824
831 public static function checkFeature(string $feature, array $params = array()): bool
832 {
833 // temporary set features
834 if (
835 isset(self::$tmpFeatures[$feature]) &&
836 self::$tmpFeatures[$feature]
837 )
838 {
839 return true;
840 }
841 if (!isset($params['type']) || !$params['type'])
842 {
843 $params['type'] = 'PAGE';
844 }
845
846 if (
847 $feature == self::FEATURE_CREATE_SITE ||
848 $feature == self::FEATURE_PUBLICATION_SITE
849 )
850 {
851 $params['action_type'] = ($feature == self::FEATURE_CREATE_SITE)
852 ? 'create' : 'publication';
853 return Restriction\Manager::isAllowed(
854 'limit_sites_number',
855 $params,
856 $feature
857 );
858 }
859 else if (
860 $feature == self::FEATURE_CREATE_PAGE ||
861 $feature == self::FEATURE_PUBLICATION_PAGE
862 )
863 {
864 $params['action_type'] = ($feature == self::FEATURE_CREATE_PAGE)
865 ? 'create' : 'publication';
866 return Restriction\Manager::isAllowed(
867 'limit_sites_number_page',
868 $params,
869 $feature
870 );
871 }
872 elseif ($feature == self::FEATURE_ENABLE_ALL_HOOKS)
873 {
874 if (isset($params['hook']))
875 {
876 return Restriction\Hook::isHookAllowed($params['hook']);
877 }
878 return true;
879 }
880 elseif ($feature == self::FEATURE_PERMISSIONS_AVAILABLE)
881 {
882 return Restriction\Manager::isAllowed(
883 'limit_sites_access_permissions'
884 );
885 }
886 elseif ($feature == self::FEATURE_DYNAMIC_BLOCK)
887 {
888 return Restriction\Manager::isAllowed(
889 'limit_sites_dynamic_blocks',
890 $params
891 );
892 }
893 elseif ($feature == self::FEATURE_FREE_DOMAIN)
894 {
895 return Restriction\Manager::isAllowed(
896 'limit_free_domen'
897 );
898 }
899 elseif ($feature == self::FEATURE_ALLOW_EXPORT)
900 {
901 return Restriction\Manager::isAllowed(
902 'limit_sites_transfer'
903 );
904 }
905 elseif ($feature == self::FEATURE_ALLOW_VIEW_PAGE)
906 {
907 return Restriction\Manager::isAllowed(
908 'limit_knowledge_base_number_page_view',
909 $params
910 );
911 }
912 // for backward compatibility
913 elseif ($feature == self::FEATURE_CUSTOM_DOMAIN)
914 {
915 return true;
916 }
917
918 return false;
919 }
920
925 public static function getZone()
926 {
927 static $zone = null;
928
929 if ($zone !== null)
930 {
931 return $zone;
932 }
933
934 $request = Application::getInstance()->getContext()->getRequest();
935 if ($request->get('user_lang'))
936 {
937 $zone = $request->get('user_lang');
938 }
939 else if (Loader::includeModule('bitrix24'))
940 {
941 $zone = \CBitrix24::getPortalZone();
942 }
943 if (!isset($zone) || !$zone)
944 {
945 $zone = Application::getInstance()->getContext()->getLanguage();
946 }
947
948 return $zone;
949 }
950
955 public static function getLangISO(): string
956 {
957 $transform = [
958 'br' => 'pt-BR',
959 'la' => 'es',
960 'sc' => 'zh-Hans',
961 'tc' => 'zh-Hant',
962 'vn' => 'vi',
963 'ua' => 'uk',
964 'in' => 'hi',
965 ];
966
967 return $transform[LANGUAGE_ID] ?? LANGUAGE_ID;
968 }
969
975 public static function availableOnlyForZone(string $zone): bool
976 {
977 static $available = null;
978
979 if ($available !== null)
980 {
981 return $available;
982 }
983
984 $available = true;
985
986 if ($zone === 'ru')
987 {
988 if (!in_array(self::getZone(), ['ru', 'by', 'kz']))
989 {
990 $available = false;
991 }
992 }
993
994 return $available;
995 }
996
1002 public static function getMarketCollectionId(string $type): int
1003 {
1004 $zone = self::getZone();
1005 switch ($type)
1006 {
1007 case 'form_minisite':
1008 $minisites = [
1009 'ru' => 18108954,
1010 'by' => 18108962,
1011 'kz' => 18108964,
1012 'en' => 18108970,
1013 ];
1014
1015 return $minisites[$zone] ?? $minisites['en'];
1016
1017 default:
1018 return 0;
1019 }
1020 }
1021
1026 public static function isHttps()
1027 {
1028 static $isHttps = null;
1029
1030 if ($isHttps === null)
1031 {
1032 $context = Application::getInstance()->getContext();
1033 $isHttps = $context->getRequest()->isHttps();
1034 }
1035
1036 return $isHttps;
1037 }
1038
1043 public static function getHttpHost()
1044 {
1045 static $host = null;
1046
1047 if ($host === null)
1048 {
1049 $context = Application::getInstance()->getContext();
1050 $host = $context->getServer()->getHttpHost();
1051
1052 // strip port
1053 if (mb_strpos($host, ':') !== false)
1054 {
1055 [$host] = explode(':', $host);
1056 }
1057 }
1058
1059 return $host;
1060 }
1061
1067 public static function getUrlFromFile($file)
1068 {
1069 if (
1070 mb_substr($file, 0, 1) == '/' &&
1071 mb_substr($file, 0, 2) != '//' &&
1072 self::getHttpHost()
1073 )
1074 {
1075 return '//' .
1076 self::getHttpHost() .
1077 $file;
1078 }
1079 else
1080 {
1081 return $file;
1082 }
1083 }
1084
1089 public static function isB24(): bool
1090 {
1091 static $return = null;
1092
1093 if (self::$forceB24disable === true)
1094 {
1095 return false;
1096 }
1097
1098 if ($return === null)
1099 {
1100 if (
1101 defined('LANDING_DISABLE_B24_MODE') &&
1102 LANDING_DISABLE_B24_MODE === true
1103 )
1104 {
1105 $return = false;
1106 }
1107 else
1108 {
1109 $return = ModuleManager::isModuleInstalled('bitrix24') ||
1110 ModuleManager::isModuleInstalled('crm') ||
1111 ModuleManager::isModuleInstalled('intranet');
1112 }
1113 }
1114
1115 return $return;
1116 }
1117
1118
1123 public static function isB24Connector(): bool
1124 {
1125 static $return = null;
1126
1127 if ($return === null)
1128 {
1129 $return =
1130 !self::isB24()
1131 && Loader::includeModule('b24connector')
1132 && Loader::includeModule('socialservices');
1133 }
1134
1135 return $return;
1136 }
1137
1143 public static function forceB24disable($flag)
1144 {
1145 self::$forceB24disable = $flag === true;
1146 }
1147
1152 public static function isExtendedSMN()
1153 {
1154 static $option = null;
1155
1156 if ($option === null)
1157 {
1158 $option = self::getOption('smn_extended', 'N') == 'Y';
1159 }
1160
1161 return $option;
1162 }
1163
1168 public static function isStoreEnabled()
1169 {
1170 return ModuleManager::isModuleInstalled('sale') &&
1171 ModuleManager::isModuleInstalled('catalog') &&
1172 ModuleManager::isModuleInstalled('iblock');
1173 }
1174
1180 public static function getRestPath(): string
1181 {
1182 return '';
1183 }
1184
1189 public static function isCloudDisable()
1190 {
1191 return defined('LANDING_DISABLE_CLOUD') &&
1192 LANDING_DISABLE_CLOUD === true;
1193 }
1194
1195
1200 public static function getVersion()
1201 {
1202 static $arModuleVersion = null;
1203
1204 if ($arModuleVersion === null)
1205 {
1206 $arModuleVersion = [];
1207 include self::getDocRoot() . '/bitrix/modules/landing/install/version.php';
1208 }
1209
1210 return isset($arModuleVersion['VERSION']) ? $arModuleVersion['VERSION'] : null;
1211 }
1212
1217 public static function licenseIsValid()
1218 {
1219 $finishDate = Option::get('main', '~support_finish_date');
1220 $finishDate = \makeTimestamp($finishDate, 'YYYY-MM-DD');
1221 if ($finishDate < time())
1222 {
1223 return false;
1224 }
1225 return true;
1226 }
1227
1233 public static function licenseIsFreeSite(string $type): bool
1234 {
1235 return
1236 $type !== 'KNOWLEDGE'
1237 && $type !== 'STORE'
1238 && (!\CBitrix24::isLicensePaid() || \CBitrix24::getLicenseType() === 'alive')
1239 && !\CBitrix24::IsNfrLicense()
1240 ;
1241 }
1242
1243 public static function isFreePublicAllowed(): bool
1244 {
1245 return in_array(self::getZone(), ['ru', 'by', 'kz', 'es', 'la', 'mx', 'co', 'br', 'in', 'hi']);
1246 }
1247
1255 public static function sanitize($value, &$bad = false, $splitter = ' ')
1256 {
1257 static $sanitizer = null;
1258
1259 if (!is_bool($bad))
1260 {
1261 $bad = false;
1262 }
1263
1264 if ($sanitizer === null)
1265 {
1266 $sanitizer = false;
1267 if (Loader::includeModule('security'))
1268 {
1269 $sanitizer = new \Bitrix\Security\Filter\Auditor\Xss(
1270 $splitter
1271 );
1272 }
1273 }
1274
1275 if ($sanitizer)
1276 {
1277 // bad value exists
1278 if (is_array($value))
1279 {
1280 foreach ($value as &$val)
1281 {
1282 $val = self::sanitize($val, $bad, $splitter);
1283 }
1284 unset($val);
1285 }
1286 else if ($sanitizer->process($value))
1287 {
1288 $bad = true;
1289 $value = $sanitizer->getFilteredValue();
1290 $value = str_replace(
1291 [' bxstyle="', '<sv g ', '<?', '?>', '<fo rm '],
1292 [' style="', '<svg ', '< ?', '? >', '<form '],
1293 $value
1294 );
1295 }
1296 else
1297 {
1298 $value = str_replace(
1299 [' bxstyle="', '<sv g ', '<?', '?>', '<fo rm '],
1300 [' style="', '<svg ', '< ?', '? >', '<form '],
1301 $value
1302 );
1303 }
1304 }
1305
1306 return $value;
1307 }
1308
1313 public static function getDeletedLT()
1314 {
1315 $deletedDays = (int) Manager::getOption('deleted_lifetime_days', 30);
1316 $deletedDays = max(1, $deletedDays);
1317 return $deletedDays;
1318 }
1319
1324 public static function getExternalSiteController()
1325 {
1326 static $class = '';
1327
1328 if (!$class)
1329 {
1330 if (class_exists('\LandingSiteController'))
1331 {
1332 $class = '\LandingSiteController';
1333 }
1334 else if (
1335 Loader::includeModule('bitrix24') &&
1336 class_exists('\Bitrix\Bitrix24\SiteController')
1337 )
1338 {
1339 $class = '\Bitrix\Bitrix24\SiteController';
1340 }
1341 else if (class_exists('\Bitrix\Landing\External\Site24'))
1342 {
1343 $class = '\Bitrix\Landing\External\Site24';
1344 }
1345 }
1346
1347 return $class;
1348 }
1349
1354 public static function resetToFree()
1355 {
1356 self::clearCache();
1357 self::setOption('html_disabled', 'Y');
1358 self::setOption('reset_to_free_time', time());
1359 Restriction\Site::manageFreeDomains(false, Restriction\Site::FREE_DOMAIN_GRACE_DAYS * 86400);
1360 }
1361
1367 public static function onBitrix24LicenseChange(string $licenseType): void
1368 {
1369 self::setOption('reset_to_free_time', 0);
1370 Restriction\Site::manageFreeDomains(true, 5);
1371 }
1372
1377 public static function clearCache(): void
1378 {
1379 // for clear cache in cloud
1380 if (!self::isB24())
1381 {
1382 return;
1383 }
1384 $res = Site::getList([
1385 'select' => [
1386 'ID',
1387 ],
1388 'filter' => [
1389 'ACTIVE' => 'Y',
1390 ],
1391 ]);
1392 while ($row = $res->fetch())
1393 {
1394 Site::update($row['ID'], []);
1395 }
1396 }
1397
1402 public static function clearCacheForSite(int $siteId): void
1403 {
1404 if (!self::isB24())
1405 {
1406 return;
1407 }
1408
1409 Site::update($siteId, []);
1410 }
1415 public static function clearCacheForLanding(int $lid): void
1416 {
1417 if (!self::isB24())
1418 {
1419 return;
1420 }
1421 $res = Landing::getList([
1422 'select' => [
1423 'SITE_ID',
1424 ],
1425 'filter' => [
1426 'ACTIVE' => 'Y',
1427 'DELETED' => 'N',
1428 'ID' => $lid,
1429 ],
1430 ]);
1431 if ($row = $res->fetch())
1432 {
1433 Site::update($row['SITE_ID'], []);
1434 }
1435 }
1436
1442 public static function checkRepositoryVersion()
1443 {
1444 }
1445
1450 public static function getThemes()
1451 {
1452 }
1453
1458 public static function getThemesTypo()
1459 {
1460 }
1461
1466 public static function setThemeId()
1467 {
1468 }
1469
1474 public static function getThemeId()
1475 {
1476 }
1477
1482 public static function setTheme()
1483 {
1484 }
1485}
static getUserInstance()
Definition manager.php:80
static getOption($code, $default=null)
Definition manager.php:160
const FEATURE_PERMISSIONS_AVAILABLE
Definition manager.php:42
static onBitrix24LicenseChange(string $licenseType)
Definition manager.php:1367
static setOption($code, $value)
Definition manager.php:171
const FEATURE_ALLOW_VIEW_PAGE
Definition manager.php:46
static getApplication()
Definition manager.php:71
static createPublicationPath(string $basePath, string $siteId=null)
Definition manager.php:255
static getCacheManager()
Definition manager.php:89
static getMainSiteById(string $siteId)
Definition manager.php:237
static isFreePublicAllowed()
Definition manager.php:1243
const FEATURE_PUBLICATION_PAGE
Definition manager.php:41
static setPageTitle($title, $single=false)
Definition manager.php:211
static forceB24disable($flag)
Definition manager.php:1143
static licenseIsFreeSite(string $type)
Definition manager.php:1233
static clearCacheForSite(int $siteId)
Definition manager.php:1402
static sanitize($value, &$bad=false, $splitter=' ')
Definition manager.php:1255
static checkRepositoryVersion()
Definition manager.php:1442
static getExternalSiteController()
Definition manager.php:1324
const FEATURE_PUBLICATION_SITE
Definition manager.php:40
const PUBLICATION_PATH_SITEMAN
Definition manager.php:26
static clearCacheForLanding(int $lid)
Definition manager.php:1415
const FEATURE_ENABLE_ALL_HOOKS
Definition manager.php:39
static loadMessages($file)
Definition loc.php:64
static getList(array $parameters=array())
$GLOBALS['____1979065141']
Definition mutator.php:1