2namespace Bitrix\Landing;
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;
11Loc::loadMessages(__FILE__);
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();
162 return Option::get(
'landing',
$code, $default);
173 Option::set(
'landing',
$code, $value);
186 $context = Application::getInstance()->getContext();
188 $docRoot = $server->getDocumentRoot();
200 return Application::getInstance()->getContext()
202 ->getRequestedPageDirectory();
214 static $disable =
false;
285 if ($smnSite = self::getMainSiteById(
$siteId))
287 if ($smnSite[
'DOC_ROOT'])
289 $docRoot = $smnSite[
'DOC_ROOT'] . $smnSite[
'DIR'];
293 $docRoot = self::getDocRoot() . $smnSite[
'DIR'];
295 $subDirSite = rtrim($smnSite[
'DIR'],
'/');
308 if (!file_exists(
$basePath .
'index.php'))
314 '/bitrix/modules/landing/install/pub/site/index.php'
325 'CONDITION' =>
'CSite::inDir(\'' . $subDirSite . $basePathOriginal .
'\')
',
326 'TEMPLATE
' => self::getTemplateId($siteId),
328 $check = \Bitrix\Main\SiteTemplateTable::getList(array(
331 '=CONDITION
' => $fields['CONDITION
'],
332 '=TEMPLATE
' => $fields['TEMPLATE
'],
337 \Bitrix\Main\SiteTemplateTable::add(
340 \Bitrix\Main\UrlRewriter::add(
344 'PATH
' => $subDirSite. $basePathOriginal . 'index.php
',
345 'CONDITION
' => '#^
' . $subDirSite. $basePathOriginal . '#
',
358 protected static function getSmnSiteDir(?string $siteId): string
367 if (!isset($sites[$siteId]))
369 $sites[$siteId] = '
';
370 if ($smnSite = self::getMainSiteById($siteId))
372 $sites[$siteId] = rtrim($smnSite['DIR
'], '/
');
376 return $sites[$siteId];
383 public static function getPublicationPathConst()
385 if (defined('LANDING_PUBLICATION_PATH_CONST
'))
387 return LANDING_PUBLICATION_PATH_CONST;
390 ? self::PUBLICATION_PATH
391 : self::PUBLICATION_PATH_SITEMAN;
401 public static function getPublicationPath($siteCode = null, $siteId = null, $createPubPath = false)
403 $typePublicationPath = Site\Type::getPublicationPath();
405 $basePath = $typePublicationPath;
406 if ($basePath === null)
408 $basePath = self::getOption(
409 'pub_path_
' . (!isset($siteId) ? (self::getMainSiteId()) : $siteId),
410 self::getPublicationPathConst()
413 $subDir = self::getSmnSiteDir($siteId);
414 if ($siteCode === null)
418 ModuleManager::isModuleInstalled('bitrix24
')
421 $createPubPath = false;
423 if ($createPubPath && $siteId)
425 self::createPublicationPath(
430 return $subDir . $basePath;
434 return $subDir . str_replace(
442 public static function isAutoPublicationEnabled(): bool
445 Site\Type::isPublicScope()
446 && \CUserOptions::getOption('landing', 'auto_publication
', 'Y
') === 'Y
'
457 public static function setPageClass($marker, $class)
459 self::setPageView($marker, $class);
470 public static function setPageView(string $marker, string $content, bool $skipTrim = false): void
474 $content = trim($content);
479 $application = self::getApplication();
480 $existContent = $application->getPageProperty($marker);
481 $application->setPageProperty(
483 $existContent . ($existContent != '
' ? ' ' : '') . $content
493 public static function clearPageView($marker): void
495 self::getApplication()->setPageProperty($marker, '
');
503 public static function getPageView($marker)
505 return self::getApplication()->getPageProperty($marker);
513 public static function getTemplateId($siteId = null)
517 if (!isset($tplId[$siteId]))
521 $tplId[$siteId] = self::getOption('site_template_id_
' . $siteId);
523 if (!$tplId[$siteId])
525 $tplId[$siteId] = self::getOption('site_template_id
', 'landing24
');
529 return $tplId[$siteId];
537 public static function isTemplateIdSystem($templateId)
539 return $templateId === 'landing24
';
546 public static function getMainSiteId()
548 return defined('SMN_SITE_ID
') ? SMN_SITE_ID : SITE_ID;
556 public static function getRandomString(int $length): string
558 return mb_strtolower(\Bitrix\Main\Security\Random::getStringByCharsets($length, 'abcdefghijklmnopqrstuvwxyz
'));
567 public static function setThemeTypoId($themeTypoId)
569 self::$themeTypoId = $themeTypoId;
577 public static function initAssets($lid = 0)
579 $assets = Assets\Manager::getInstance();
580 $assets->setOutput($lid);
590 public static function savePicture($file, $ext = false, $params = array())
593 if (!is_array($file) && mb_substr($file, 0, 1) == '/
')
595 $file = \CFile::makeFileArray($file);
598 else if (!is_array($file))
600 $httpClient = new \Bitrix\Main\Web\HttpClient();
601 $httpClient->setPrivateIp(false);
602 $httpClient->setTimeout(5);
603 $httpClient->setStreamTimeout(5);
604 $urlComponents = parse_url($file);
606 // detect tmp file name
607 if ($urlComponents && $urlComponents['path'] != '')
609 $tempPath = \CFile::getTempName('', bx_basename(urldecode($urlComponents['path'])));
613 $tempPath = \CFile::getTempName('', bx_basename(urldecode($file)));
615 if ($ext !== false && in_array($ext, explode(',
', \CFile::getImageExtensions())))
617 if (mb_substr($tempPath, -3) != $ext)
619 $tempPath = $tempPath . '.
' . $ext;
624 if ($httpClient->download($file, $tempPath))
626 $fileName = $httpClient->getHeaders()->getFilename();
627 $file = \CFile::makeFileArray($tempPath);
628 if ($file && $fileName)
630 $file['name
'] = $fileName;
642 $fileParts = explode('.
', $file[0]);
643 $ext = array_pop($fileParts);
644 $tempPath = \CFile::getTempName(
647 implode('', $fileParts),
651 $fileIO = new \Bitrix\Main\IO\File(
654 $fileIO->putContents(
655 base64_decode($file[1])
657 $file = \CFile::makeFileArray($tempPath);
661 $isImage = \CFile::checkImageFile($file, 0, 0, 0, array('IMAGE
')) === null;
663 if (!$isImage && (Manager::getOption('allow_svg_content
') === 'Y
'))
665 $extension = \getFileExtension(mb_strtolower($file['name
']));
666 if ($extension === 'svg
')
672 // post array or file from prev. steps
673 if ($isImage || $isSvg)
678 isset($params['width']) &&
685 isset($params['resize_type
'])
686 ? intval($params['resize_type
'])
687 : BX_RESIZE_IMAGE_PROPORTIONAL);
689 // if duplicate change size little (bug #167903)
690 if ($isImage && self::isDuplicateExistsInAnotherModule($file['tmp_name
'], $file['size']))
692 [$width, $height] = getimagesize($file['tmp_name
']) ?: [0, 0];
693 if ($width && $height)
695 \CFile::resizeImage($file, ['width' => $width-1, 'height' => $height-1]);
700 $file['name
'] = File::transliterateFileName($file['name
']);
701 $file['name
'] = File::sanitizeFileName($file['name
']);
702 $file['MODULE_ID
'] = $module;
703 $file = \CFile::saveFile($file, $module);
706 $file = \CFile::getFileArray($file);
710 $file['SRC
'] = str_replace(
728 private static function isDuplicateExistsInAnotherModule(string $filePath, int $size): bool
730 $hash = self::calculateHash($filePath, $size);
736 $original = \CFile::findDuplicate($size, $hash);
737 if ($original === null)
742 // we allow duplicate only within from current module
743 return $original->getFile()->getModuleId() !== '
landing';
753 private static function calculateHash(string $filePath, int $size): string
757 if ($size > 0 && Option::get('main
', 'control_file_duplicates
', 'N
') === 'Y
')
759 $maxSize = (int)Option::get('main
', 'duplicates_max_size
', '100
') * 1024 * 1024; //Mbytes
760 if ($size <= $maxSize || $maxSize === 0)
762 $hash = hash_file('md5
', $filePath);
774 public static function enableFeatureTmp($feature)
776 self::$tmpFeatures[$feature] = true;
784 public static function disableFeatureTmp($feature)
786 if (isset(self::$tmpFeatures[$feature]))
788 unset(self::$tmpFeatures[$feature]);
796 public static function disableAllFeaturesTmp()
798 self::$tmpFeatures = [];
807 public static function checkMultiFeature(array $features, array $params = [])
809 $features = array_unique($features);
811 foreach ($features as $feature)
813 if (is_string($feature))
815 $check = self::checkFeature($feature, $params);
836 public static function checkFeature(string $feature, array $params = array()): bool
838 // temporary set features
840 isset(self::$tmpFeatures[$feature]) &&
841 self::$tmpFeatures[$feature]
846 if (!isset($params['type
']) || !$params['type
'])
848 $params['type
'] = 'PAGE
';
852 $feature == self::FEATURE_CREATE_SITE ||
853 $feature == self::FEATURE_PUBLICATION_SITE
856 $params['action_type
'] = ($feature == self::FEATURE_CREATE_SITE)
857 ? 'create
' : 'publication
';
858 return Restriction\Manager::isAllowed(
859 'limit_sites_number
',
865 $feature == self::FEATURE_CREATE_PAGE ||
866 $feature == self::FEATURE_PUBLICATION_PAGE
869 $params['action_type
'] = ($feature == self::FEATURE_CREATE_PAGE)
870 ? 'create
' : 'publication
';
871 return Restriction\Manager::isAllowed(
872 'limit_sites_number_page
',
877 elseif ($feature == self::FEATURE_ENABLE_ALL_HOOKS)
879 if (isset($params['hook
']))
881 return Restriction\Hook::isHookAllowed($params['hook
']);
885 elseif ($feature == self::FEATURE_PERMISSIONS_AVAILABLE)
887 return Restriction\Manager::isAllowed(
888 'limit_sites_access_permissions
'
891 elseif ($feature == self::FEATURE_DYNAMIC_BLOCK)
893 return Restriction\Manager::isAllowed(
894 'limit_sites_dynamic_blocks
',
898 elseif ($feature == self::FEATURE_FREE_DOMAIN)
900 return Restriction\Manager::isAllowed(
904 elseif ($feature == self::FEATURE_ALLOW_EXPORT)
906 return Restriction\Manager::isAllowed(
907 'limit_sites_transfer
'
910 elseif ($feature == self::FEATURE_ALLOW_VIEW_PAGE)
912 return Restriction\Manager::isAllowed(
913 'limit_knowledge_base_number_page_view
',
917 // for backward compatibility
918 elseif ($feature == self::FEATURE_CUSTOM_DOMAIN)
930 public static function getZone()
939 $request = Application::getInstance()->getContext()->getRequest();
940 if ($request->get('user_lang
'))
942 $zone = $request->get('user_lang
');
944 else if (Loader::includeModule('bitrix24
'))
946 $zone = \CBitrix24::getPortalZone();
948 if (!isset($zone) || !$zone)
950 $zone = Application::getInstance()->getContext()->getLanguage();
960 public static function getLangISO(): string
972 return $transform[LANGUAGE_ID] ?? LANGUAGE_ID;
980 public static function availableOnlyForZone(string $zone): bool
982 static $available = null;
984 if ($available !== null)
993 if (!in_array(self::getZone(), ['ru
', 'by
', 'kz
', 'uz
']))
1007 public static function getMarketCollectionId(string $type): int
1009 $zone = self::getZone();
1012 case 'form_minisite
':
1021 return $minisites[$zone] ?? $minisites['en
'];
1032 public static function isHttps()
1034 static $isHttps = null;
1036 if ($isHttps === null)
1038 $context = Application::getInstance()->getContext();
1039 $isHttps = $context->getRequest()->isHttps();
1049 public static function isAjaxRequest(): bool
1051 return Application::getInstance()->getContext()->getRequest()->isAjaxRequest();
1058 public static function getHttpHost()
1060 static $host = null;
1064 $context = Application::getInstance()->getContext();
1065 $host = $context->getServer()->getHttpHost();
1068 if (mb_strpos($host, ':
') !== false)
1070 [$host] = explode(':
', $host);
1082 public static function getUrlFromFile($file)
1085 mb_substr($file, 0, 1) == '/
' &&
1086 mb_substr($file, 0, 2) != '
1091 self::getHttpHost() .
1107 if (!defined(
'LANDING_PREVIEW_URL'))
1109 define(
'LANDING_PREVIEW_URL', self::getRegionPreviewDomain());
1112 return LANDING_PREVIEW_URL;
1122 if (!defined(
'LANDING_PREVIEW_WEBHOOK'))
1124 $host = self::getRegionPreviewDomain();
1125 define(
'LANDING_PREVIEW_WEBHOOK',
$host .
'/rest/1/gvsn3ngrn7vb4t1m/');
1128 return LANDING_PREVIEW_WEBHOOK;
1137 static $return =
null;
1139 if (self::$forceB24disable ===
true)
1144 if ($return ===
null)
1147 defined(
'LANDING_DISABLE_B24_MODE') &&
1148 LANDING_DISABLE_B24_MODE ===
true
1155 $return = ModuleManager::isModuleInstalled(
'bitrix24') ||
1156 ModuleManager::isModuleInstalled(
'crm') ||
1157 ModuleManager::isModuleInstalled(
'intranet');
1170 return self::isB24() && ModuleManager::isModuleInstalled(
'bitrix24');
1180 static $return =
null;
1182 if ($return ===
null)
1186 && Loader::includeModule(
'b24connector')
1187 && Loader::includeModule(
'socialservices');
1200 self::$forceB24disable = $flag ===
true;
1213 $option = self::getOption(
'smn_extended',
'N') ==
'Y';
1225 return ModuleManager::isModuleInstalled(
'sale') &&
1226 ModuleManager::isModuleInstalled(
'catalog') &&
1227 ModuleManager::isModuleInstalled(
'iblock');
1246 return defined(
'LANDING_DISABLE_CLOUD') &&
1247 LANDING_DISABLE_CLOUD ===
true;
1257 static $arModuleVersion =
null;
1259 if ($arModuleVersion ===
null)
1261 $arModuleVersion = [];
1262 include self::getDocRoot() .
'/bitrix/modules/landing/install/version.php';
1265 return isset($arModuleVersion[
'VERSION']) ? $arModuleVersion[
'VERSION'] :
null;
1274 $finishDate = Option::get(
'main',
'~support_finish_date');
1275 $finishDate = \makeTimestamp($finishDate,
'YYYY-MM-DD');
1276 if ($finishDate < time())
1291 $type !==
'KNOWLEDGE'
1292 &&
$type !==
'STORE'
1293 && (!\CBitrix24::isLicensePaid() || \CBitrix24::getLicenseType() ===
'alive')
1294 && !\CBitrix24::IsNfrLicense()
1300 return in_array(self::getZone(), [
'ru',
'by',
'kz',
'uz',
'es',
'la',
'mx',
'co',
'br',
'in',
'hi']);
1310 public static function sanitize($value, &$bad =
false, $splitter =
' ')
1312 static $sanitizer =
null;
1319 if ($sanitizer ===
null)
1322 if (Loader::includeModule(
'security'))
1324 $sanitizer = new \Bitrix\Security\Filter\Auditor\Xss(
1333 if (is_array($value))
1335 foreach ($value as &
$val)
1337 $val = self::sanitize(
$val, $bad, $splitter);
1341 else if ($sanitizer->process($value))
1344 $value = $sanitizer->getFilteredValue();
1345 $value = str_replace(
1346 [
' bxstyle="',
'<sv g ',
'<?',
'?>',
'<fo rm '],
1347 [
' style="',
'<svg ',
'< ?',
'? >',
'<form '],
1353 $value = str_replace(
1354 [
' bxstyle="',
'<sv g ',
'<?',
'?>',
'<fo rm '],
1355 [
' style="',
'<svg ',
'< ?',
'? >',
'<form '],
1371 $deletedDays = max(1, $deletedDays);
1372 return $deletedDays;
1385 if (class_exists(
'\LandingSiteController'))
1387 $class =
'\LandingSiteController';
1390 Loader::includeModule(
'bitrix24') &&
1391 class_exists(
'\Bitrix\Bitrix24\SiteController')
1394 $class =
'\Bitrix\Bitrix24\SiteController';
1396 else if (class_exists(
'\Bitrix\Landing\External\Site24'))
1398 $class =
'\Bitrix\Landing\External\Site24';
1412 self::setOption(
'html_disabled',
'Y');
1413 self::setOption(
'reset_to_free_time', time());
1425 self::setOption(
'reset_to_free_time', 0);
1442 $res = Site::getList([
1450 while ($row =
$res->fetch())
1452 Site::update($row[
'ID'], []);
1489 if ($row =
$res->fetch())
1491 Site::update($row[
'SITE_ID'], []);
1549 private static function getRegionPreviewDomain(): string
1551 $region = Application::getInstance()->getLicense()->getRegion();
1553 if (in_array(
$region, [
'ru',
'by',
'kz',
'uz'],
true))
1555 return 'https://preview.bitrix24.tech';
1559 return 'https://preview.bitrix24.site';
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 getPreviewWebhook()
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 publishByLicenseChange()
static manageFreeDomains(bool $setActive, int $executeAfterSeconds=0)
static checkLimitsByLicenseChange()
static getList(array $parameters=array())
hidden PROPERTY[<?=$propertyIndex?>][CODE]<?=htmlspecialcharsEx( $propertyCode)?> height
bx popup label bx width30 PAGE_NEW_MENU_NAME text width
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
$GLOBALS['____1690880296']