• Модуль: landing
  • Путь к файлу: ~/bitrix/modules/landing/lib/manager.php
  • Класс: BitrixLandingManager
  • Вызов: Manager::createPublicationPath
static function createPublicationPath(string $basePath, string $siteId = null): void
{
	static $paths = [];

	if (!in_array($basePath, $paths))
	{
		$paths[] = $basePath;

		if (mb_substr($basePath, 0, 1) != '/')
		{
			$basePath = '/' . $basePath;
		}
		if (mb_substr($basePath, -1) != '/')
		{
			$basePath = $basePath . '/';
		}

		$docRoot = '';
		$subDirSite = '';
		$basePathOriginal = $basePath;

		// gets current doc root or gets from the site
		if ($siteId)
		{
			if ($smnSite = self::getMainSiteById($siteId))
			{
				if ($smnSite['DOC_ROOT'])
				{
					$docRoot = $smnSite['DOC_ROOT'] . $smnSite['DIR'];
				}
				else
				{
					$docRoot = self::getDocRoot() . $smnSite['DIR'];
				}
				$subDirSite = rtrim($smnSite['DIR'], '/');
			}
			$docRoot = rtrim($docRoot, '/');
		}
		if (!$docRoot)
		{
			$docRoot = self::getDocRoot();
		}
		$basePath = $docRoot . $basePath;

		// create path
		if (checkDirPath($basePath))
		{
			if (!file_exists($basePath . 'index.php'))
			{
				rewriteFile(
					$basePath . 'index.php',
					file_get_contents(
						self::getDocRoot() .
						'/bitrix/modules/landing/install/pub/site/index.php'
					)
				);
			}
		}
		// and add template rules for main
		if ($siteId)
		{
			$fields = array(
				'SORT' => 0,
				'SITE_ID' => $siteId,
				'CONDITION' => 'CSite::inDir('' . $subDirSite . $basePathOriginal . '')',
				'TEMPLATE' => self::getTemplateId($siteId)
			);
			$check = BitrixMainSiteTemplateTable::getList(array(
				 'filter' => array(
					 '=SITE_ID' => $fields['SITE_ID'],
					 '=CONDITION' => $fields['CONDITION'],
					 '=TEMPLATE' => $fields['TEMPLATE']
				 )
			 ))->fetch();
			if (!$check)
			{
				BitrixMainSiteTemplateTable::add(
					$fields
				);
				BitrixMainUrlRewriter::add(
					$siteId,
					array(
						'ID' => 'bitrix:landing.pub',
						'PATH' => $subDirSite. $basePathOriginal . 'index.php',
						'CONDITION' => '#^' . $subDirSite. $basePathOriginal . '#'
					)
				);
				self::getCacheManager()->clean('b_site_template');
			}
		}
	}
}