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;
65 private static $themeTypoId =
'';
100 return $GLOBALS[
'USER_FIELD_MANAGER'];
109 $user = self::getUserInstance();
110 if ($user instanceof \CUser)
112 return (
int)$user->getId();
123 $user = self::getUserInstance();
124 if ($user instanceof \CUser)
126 return $user->getFullName();
137 $user = self::getUserInstance();
139 if (!($user instanceof \CUser))
144 if (ModuleManager::isModuleInstalled(
'bitrix24'))
146 return $user->canDoOperation(
'bitrix24_config');
150 return $user->isAdmin();
160 public static function getOption($code, $default =
null)
162 return Option::get(
'landing', $code, $default);
173 Option::set(
'landing', $code, $value);
182 static $docRoot =
null;
184 if ($docRoot ===
null)
187 $server = $context->getServer();
188 $docRoot = $server->getDocumentRoot();
202 ->getRequestedPageDirectory();
213 static $application =
null;
214 static $disable =
false;
216 if ($application ===
null)
218 $application = self::getApplication();
221 if ($title && !$disable)
223 $application->setTitle($title);
224 $application->setPageProperty(
'title', $title);
241 if (!array_key_exists($siteId, $sites))
243 $sites[$siteId] = \Bitrix\Main\SiteTable::getById($siteId)->fetch();
246 return $sites[$siteId];
259 if (!in_array($basePath, $paths))
261 $paths[] = $basePath;
263 if (mb_substr($basePath, 0, 1) !=
'/')
265 $basePath =
'/' . $basePath;
267 if (mb_substr($basePath, -1) !=
'/')
269 $basePath = $basePath .
'/';
274 $basePathOriginal = $basePath;
279 if ($smnSite = self::getMainSiteById($siteId))
281 if ($smnSite[
'DOC_ROOT'])
283 $docRoot = $smnSite[
'DOC_ROOT'] . $smnSite[
'DIR'];
287 $docRoot = self::getDocRoot() . $smnSite[
'DIR'];
289 $subDirSite = rtrim($smnSite[
'DIR'],
'/');
291 $docRoot = rtrim($docRoot,
'/');
295 $docRoot = self::getDocRoot();
297 $basePath = $docRoot . $basePath;
300 if (\checkDirPath($basePath))
302 if (!file_exists($basePath .
'index.php'))
305 $basePath .
'index.php',
308 '/bitrix/modules/landing/install/pub/site/index.php'
318 'SITE_ID' => $siteId,
319 'CONDITION' =>
'CSite::inDir(\'' . $subDirSite . $basePathOriginal .
'\')
',
320 'TEMPLATE
' => self::getTemplateId($siteId)
322 $check = \Bitrix\Main\SiteTemplateTable::getList(array(
324 '=SITE_ID
' => $fields['SITE_ID
'],
325 '=CONDITION
' => $fields['CONDITION
'],
326 '=TEMPLATE
' => $fields['TEMPLATE
']
331 \Bitrix\Main\SiteTemplateTable::add(
334 \Bitrix\Main\UrlRewriter::add(
337 'ID
' => 'bitrix:landing.pub
',
338 'PATH
' => $subDirSite. $basePathOriginal . 'index.php
',
339 'CONDITION
' => '#^
' . $subDirSite. $basePathOriginal . '#
'
342 self::getCacheManager()->clean('b_site_template
');
353 protected static function getSmnSiteDir(?string $siteId): string
362 if (!isset($sites[$siteId]))
364 $sites[$siteId] = '
';
365 if ($smnSite = self::getMainSiteById($siteId))
367 $sites[$siteId] = rtrim($smnSite['DIR
'], '/
');
371 return $sites[$siteId];
378 public static function getPublicationPathConst()
380 if (defined('LANDING_PUBLICATION_PATH_CONST
'))
382 return LANDING_PUBLICATION_PATH_CONST;
385 ? self::PUBLICATION_PATH
386 : self::PUBLICATION_PATH_SITEMAN;
396 public static function getPublicationPath($siteCode = null, $siteId = null, $createPubPath = false)
398 $tyePublicationPath = Site\Type::getPublicationPath();
400 $basePath = $tyePublicationPath;
401 if ($basePath === null)
403 $basePath = self::getOption(
404 'pub_path_
' . (!isset($siteId) ? (self::getMainSiteId()) : $siteId),
405 self::getPublicationPathConst()
408 $subDir = self::getSmnSiteDir($siteId);
409 if ($siteCode === null)
413 ModuleManager::isModuleInstalled('bitrix24
')
416 $createPubPath = false;
418 if ($createPubPath && $siteId)
420 self::createPublicationPath(
425 return $subDir . $basePath;
429 return $subDir . str_replace(
437 public static function isAutoPublicationEnabled(): bool
440 Site\Type::isPublicScope()
441 && \CUserOptions::getOption('landing
', 'auto_publication
', 'Y
') === 'Y
'
452 public static function setPageClass($marker, $class)
454 self::setPageView($marker, $class);
465 public static function setPageView(string $marker, string $content, bool $skipTrim = false): void
469 $content = trim($content);
474 $application = self::getApplication();
475 $existContent = $application->getPageProperty($marker);
476 $application->setPageProperty(
478 $existContent . ($existContent != '
' ? ' ' : '') . $content
488 public static function clearPageView($marker): void
490 self::getApplication()->setPageProperty($marker, '
');
498 public static function getPageView($marker)
500 return self::getApplication()->getPageProperty($marker);
508 public static function getTemplateId($siteId = null)
512 if (!isset($tplId[$siteId]))
516 $tplId[$siteId] = self::getOption('site_template_id_
' . $siteId);
518 if (!$tplId[$siteId])
520 $tplId[$siteId] = self::getOption('site_template_id
', 'landing24
');
524 return $tplId[$siteId];
532 public static function isTemplateIdSystem($templateId)
534 return $templateId === 'landing24
';
541 public static function getMainSiteId()
543 return defined('SMN_SITE_ID
') ? SMN_SITE_ID : SITE_ID;
551 public static function getRandomString(int $length): string
553 return mb_strtolower(\Bitrix\Main\Security\Random::getStringByCharsets($length, 'abcdefghijklmnopqrstuvwxyz
'));
562 public static function setThemeTypoId($themeTypoId)
564 self::$themeTypoId = $themeTypoId;
572 public static function initAssets($lid = 0)
574 $assets = Assets\Manager::getInstance();
575 $assets->setOutput($lid);
585 public static function savePicture($file, $ext = false, $params = array())
588 if (!is_array($file) && mb_substr($file, 0, 1) == '/
')
590 $file = \CFile::makeFileArray($file);
593 else if (!is_array($file))
595 $httpClient = new \Bitrix\Main\Web\HttpClient();
596 $httpClient->setPrivateIp(false);
597 $httpClient->setTimeout(5);
598 $httpClient->setStreamTimeout(5);
599 $urlComponents = parse_url($file);
601 // detect tmp file name
602 if ($urlComponents && $urlComponents['path
'] != '')
604 $tempPath = \CFile::getTempName('', bx_basename(urldecode($urlComponents['path
'])));
608 $tempPath = \CFile::getTempName('', bx_basename(urldecode($file)));
610 if ($ext !== false && in_array($ext, explode(',
', \CFile::getImageExtensions())))
612 if (mb_substr($tempPath, -3) != $ext)
614 $tempPath = $tempPath . '.
' . $ext;
619 if ($httpClient->download($file, $tempPath))
621 $fileName = $httpClient->getHeaders()->getFilename();
622 $file = \CFile::makeFileArray($tempPath);
623 if ($file && $fileName)
625 $file['name
'] = $fileName;
637 $fileParts = explode('.
', $file[0]);
638 $ext = array_pop($fileParts);
639 $tempPath = \CFile::getTempName(
642 implode('', $fileParts),
646 $fileIO = new \Bitrix\Main\IO\File(
649 $fileIO->putContents(
650 base64_decode($file[1])
652 $file = \CFile::makeFileArray($tempPath);
656 $isImage = \CFile::checkImageFile($file, 0, 0, 0, array('IMAGE
')) === null;
658 if (!$isImage && (Manager::getOption('allow_svg_content
') === 'Y
'))
660 $extension = \getFileExtension(mb_strtolower($file['name
']));
661 if ($extension === 'svg
')
667 // post array or file from prev. steps
668 if ($isImage || $isSvg)
673 isset($params['width
']) &&
674 isset($params['height
'])
680 isset($params['resize_type
'])
681 ? intval($params['resize_type
'])
682 : BX_RESIZE_IMAGE_PROPORTIONAL);
684 // if duplicate change size little (bug #167903)
685 if ($isImage && self::isDuplicateExistsInAnotherModule($file['tmp_name
'], $file['size
']))
687 [$width, $height] = getimagesize($file['tmp_name
']) ?: [0, 0];
688 if ($width && $height)
690 \CFile::resizeImage($file, ['width
' => $width-1, 'height
' => $height-1]);
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);
701 $file = \CFile::getFileArray($file);
705 $file['SRC
'] = str_replace(
723 private static function isDuplicateExistsInAnotherModule(string $filePath, int $size): bool
725 $hash = self::calculateHash($filePath, $size);
731 $original = \CFile::findDuplicate($size, $hash);
732 if ($original === null)
737 // we allow duplicate only within from current module
738 return $original->getFile()->getModuleId() !== 'landing
';
748 private static function calculateHash(string $filePath, int $size): string
752 if ($size > 0 && Option::get('main
', 'control_file_duplicates
', 'N
') === 'Y
')
754 $maxSize = (int)Option::get('main
', 'duplicates_max_size
', '100
') * 1024 * 1024; //Mbytes
755 if ($size <= $maxSize || $maxSize === 0)
757 $hash = hash_file('md5
', $filePath);
769 public static function enableFeatureTmp($feature)
771 self::$tmpFeatures[$feature] = true;
779 public static function disableFeatureTmp($feature)
781 if (isset(self::$tmpFeatures[$feature]))
783 unset(self::$tmpFeatures[$feature]);
791 public static function disableAllFeaturesTmp()
793 self::$tmpFeatures = [];
802 public static function checkMultiFeature(array $features, array $params = [])
804 $features = array_unique($features);
806 foreach ($features as $feature)
808 if (is_string($feature))
810 $check = self::checkFeature($feature, $params);
831 public static function checkFeature(string $feature, array $params = array()): bool
833 // temporary set features
835 isset(self::$tmpFeatures[$feature]) &&
836 self::$tmpFeatures[$feature]
841 if (!isset($params['type
']) || !$params['type
'])
843 $params['type
'] = 'PAGE
';
847 $feature == self::FEATURE_CREATE_SITE ||
848 $feature == self::FEATURE_PUBLICATION_SITE
851 $params['action_type
'] = ($feature == self::FEATURE_CREATE_SITE)
852 ? 'create
' : 'publication
';
853 return Restriction\Manager::isAllowed(
854 'limit_sites_number
',
860 $feature == self::FEATURE_CREATE_PAGE ||
861 $feature == self::FEATURE_PUBLICATION_PAGE
864 $params['action_type
'] = ($feature == self::FEATURE_CREATE_PAGE)
865 ? 'create
' : 'publication
';
866 return Restriction\Manager::isAllowed(
867 'limit_sites_number_page
',
872 elseif ($feature == self::FEATURE_ENABLE_ALL_HOOKS)
874 if (isset($params['hook
']))
876 return Restriction\Hook::isHookAllowed($params['hook
']);
880 elseif ($feature == self::FEATURE_PERMISSIONS_AVAILABLE)
882 return Restriction\Manager::isAllowed(
883 'limit_sites_access_permissions
'
886 elseif ($feature == self::FEATURE_DYNAMIC_BLOCK)
888 return Restriction\Manager::isAllowed(
889 'limit_sites_dynamic_blocks
',
893 elseif ($feature == self::FEATURE_FREE_DOMAIN)
895 return Restriction\Manager::isAllowed(
899 elseif ($feature == self::FEATURE_ALLOW_EXPORT)
901 return Restriction\Manager::isAllowed(
902 'limit_sites_transfer
'
905 elseif ($feature == self::FEATURE_ALLOW_VIEW_PAGE)
907 return Restriction\Manager::isAllowed(
908 'limit_knowledge_base_number_page_view
',
912 // for backward compatibility
913 elseif ($feature == self::FEATURE_CUSTOM_DOMAIN)
925 public static function getZone()
934 $request = Application::getInstance()->getContext()->getRequest();
935 if ($request->get('user_lang
'))
937 $zone = $request->get('user_lang
');
939 else if (Loader::includeModule('bitrix24
'))
941 $zone = \CBitrix24::getPortalZone();
943 if (!isset($zone) || !$zone)
945 $zone = Application::getInstance()->getContext()->getLanguage();
955 public static function getLangISO(): string
967 return $transform[LANGUAGE_ID] ?? LANGUAGE_ID;
975 public static function availableOnlyForZone(string $zone): bool
977 static $available = null;
979 if ($available !== null)
988 if (!in_array(self::getZone(), ['ru
', 'by
', 'kz
']))
1002 public static function getMarketCollectionId(string $type): int
1004 $zone = self::getZone();
1007 case 'form_minisite
':
1015 return $minisites[$zone] ?? $minisites['en
'];
1026 public static function isHttps()
1028 static $isHttps = null;
1030 if ($isHttps === null)
1032 $context = Application::getInstance()->getContext();
1033 $isHttps = $context->getRequest()->isHttps();
1043 public static function getHttpHost()
1045 static $host = null;
1049 $context = Application::getInstance()->getContext();
1050 $host = $context->getServer()->getHttpHost();
1053 if (mb_strpos($host, ':
') !== false)
1055 [$host] = explode(':
', $host);
1067 public static function getUrlFromFile($file)
1070 mb_substr($file, 0, 1) == '/
' &&
1071 mb_substr($file, 0, 2) != '
1076 self::getHttpHost() .
1091 static $return =
null;
1093 if (self::$forceB24disable ===
true)
1098 if ($return ===
null)
1101 defined(
'LANDING_DISABLE_B24_MODE') &&
1102 LANDING_DISABLE_B24_MODE ===
true
1109 $return = ModuleManager::isModuleInstalled(
'bitrix24') ||
1110 ModuleManager::isModuleInstalled(
'crm') ||
1111 ModuleManager::isModuleInstalled(
'intranet');
1125 static $return =
null;
1127 if ($return ===
null)
1131 && Loader::includeModule(
'b24connector')
1132 && Loader::includeModule(
'socialservices');
1145 self::$forceB24disable = $flag ===
true;
1154 static $option =
null;
1156 if ($option ===
null)
1158 $option = self::getOption(
'smn_extended',
'N') ==
'Y';
1170 return ModuleManager::isModuleInstalled(
'sale') &&
1171 ModuleManager::isModuleInstalled(
'catalog') &&
1172 ModuleManager::isModuleInstalled(
'iblock');
1191 return defined(
'LANDING_DISABLE_CLOUD') &&
1192 LANDING_DISABLE_CLOUD ===
true;
1202 static $arModuleVersion =
null;
1204 if ($arModuleVersion ===
null)
1206 $arModuleVersion = [];
1207 include self::getDocRoot() .
'/bitrix/modules/landing/install/version.php';
1210 return isset($arModuleVersion[
'VERSION']) ? $arModuleVersion[
'VERSION'] :
null;
1219 $finishDate = Option::get(
'main',
'~support_finish_date');
1220 $finishDate = \makeTimestamp($finishDate,
'YYYY-MM-DD');
1221 if ($finishDate < time())
1236 $type !==
'KNOWLEDGE'
1237 && $type !==
'STORE'
1238 && (!\CBitrix24::isLicensePaid() || \CBitrix24::getLicenseType() ===
'alive')
1239 && !\CBitrix24::IsNfrLicense()
1245 return in_array(self::getZone(), [
'ru',
'by',
'kz',
'es',
'la',
'mx',
'co',
'br',
'in',
'hi']);
1255 public static function sanitize($value, &$bad =
false, $splitter =
' ')
1257 static $sanitizer =
null;
1264 if ($sanitizer ===
null)
1267 if (Loader::includeModule(
'security'))
1269 $sanitizer = new \Bitrix\Security\Filter\Auditor\Xss(
1278 if (is_array($value))
1280 foreach ($value as &$val)
1282 $val = self::sanitize($val, $bad, $splitter);
1286 else if ($sanitizer->process($value))
1289 $value = $sanitizer->getFilteredValue();
1290 $value = str_replace(
1291 [
' bxstyle="',
'<sv g ',
'<?',
'?>',
'<fo rm '],
1292 [
' style="',
'<svg ',
'< ?',
'? >',
'<form '],
1298 $value = str_replace(
1299 [
' bxstyle="',
'<sv g ',
'<?',
'?>',
'<fo rm '],
1300 [
' style="',
'<svg ',
'< ?',
'? >',
'<form '],
1316 $deletedDays = max(1, $deletedDays);
1317 return $deletedDays;
1330 if (class_exists(
'\LandingSiteController'))
1332 $class =
'\LandingSiteController';
1335 Loader::includeModule(
'bitrix24') &&
1336 class_exists(
'\Bitrix\Bitrix24\SiteController')
1339 $class =
'\Bitrix\Bitrix24\SiteController';
1341 else if (class_exists(
'\Bitrix\Landing\External\Site24'))
1343 $class =
'\Bitrix\Landing\External\Site24';
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);
1369 self::setOption(
'reset_to_free_time', 0);
1370 Restriction\Site::manageFreeDomains(
true, 5);
1384 $res = Site::getList([
1392 while ($row = $res->fetch())
1394 Site::update($row[
'ID'], []);
1409 Site::update($siteId, []);
1431 if ($row = $res->fetch())
1433 Site::update($row[
'SITE_ID'], []);
static getOption($code, $default=null)
const FEATURE_PERMISSIONS_AVAILABLE
static onBitrix24LicenseChange(string $licenseType)
static setOption($code, $value)
const FEATURE_ALLOW_VIEW_PAGE
const USER_AGREEMENT_VERSION
static createPublicationPath(string $basePath, string $siteId=null)
const FEATURE_ALLOW_EXPORT
const FEATURE_DYNAMIC_BLOCK
static getMainSiteById(string $siteId)
const FEATURE_CREATE_PAGE
const FEATURE_CREATE_SITE
static isFreePublicAllowed()
const FEATURE_PUBLICATION_PAGE
static setPageTitle($title, $single=false)
static forceB24disable($flag)
static licenseIsFreeSite(string $type)
static clearCacheForSite(int $siteId)
static sanitize($value, &$bad=false, $splitter=' ')
const FEATURE_CUSTOM_DOMAIN
static checkRepositoryVersion()
const FEATURE_FREE_DOMAIN
static getExternalSiteController()
const FEATURE_PUBLICATION_SITE
const PUBLICATION_PATH_SITEMAN
static clearCacheForLanding(int $lid)
const FEATURE_ENABLE_ALL_HOOKS
static loadMessages($file)
static getList(array $parameters=array())
$GLOBALS['____1979065141']