• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/classes/general/iblock.php
  • Класс: CAllIBlock
  • Вызов: CAllIBlock::ReplaceDetailUrl
static function ReplaceDetailUrl($url, $arr, $server_name = false, $arrType = false)
{
	$url = (string)$url;

	if ($server_name)
	{
		$url = str_replace('#LANG#', (string)($arr['LANG_DIR'] ?? ''), $url);
		if (
			(defined('ADMIN_SECTION') && ADMIN_SECTION === true)
			|| !defined('BX_STARTED')
		)
		{
			static $cache = array();
			if (isset($arr['LID']))
			{
				if (!isset($cache[$arr['LID']]))
				{
					$db_lang = CLang::GetByID($arr['LID']);
					$arLang = $db_lang->Fetch();
					if (!empty($arLang))
					{
						$arLang['DIR'] = (string)$arLang['DIR'];
						$arLang['SERVER_NAME'] = (string)$arLang['SERVER_NAME'];
					}
					$cache[$arr['LID']] = $arLang;
				}
				$arLang = $cache[$arr['LID']];
				if (!empty($arLang))
				{
					$url = str_replace(
						[
							'#SITE_DIR#',
							'#SERVER_NAME#',
						],
						[
							$arLang['DIR'],
							$arLang['SERVER_NAME'],
						],
						$url
					);
				}
			}
		}
		else
		{
			$url = str_replace(
				[
					'#SITE_DIR#',
					'#SERVER_NAME#',
				],
				[
					SITE_DIR,
					SITE_SERVER_NAME,
				],
				$url
			);
		}
	}

	$id = (int)($arr['ID'] ?? 0);
	$preparedId = $id > 0 ? $id : '';

	static $arSearch = [
		/*Thees come from GetNext*/
		'#SITE_DIR#',
		'#ID#',
		'#CODE#',
		'#EXTERNAL_ID#',
		'#IBLOCK_TYPE_ID#',
		'#IBLOCK_ID#',
		'#IBLOCK_CODE#',
		'#IBLOCK_EXTERNAL_ID#',
		/*And thees was born during components 2 development*/
		'#ELEMENT_ID#',
		'#ELEMENT_CODE#',
		'#SECTION_ID#',
		'#SECTION_CODE#',
		'#SECTION_CODE_PATH#',
	];
	$iblockId = (int)($arr['IBLOCK_ID'] ?? 0);
	$preparedCode = rawurlencode(
		(string)($arr['~CODE'] ?? ($arr['CODE'] ?? ''))
	);
	$iblockSectionId = (int)($arr['IBLOCK_SECTION_ID'] ?? 0);
	$arReplace = [
		(string)($arr['LANG_DIR'] ?? ''),
		$preparedId,
		$preparedCode,
		rawurlencode(
			(string)($arr['~EXTERNAL_ID'] ?? ($arr['EXTERNAL_ID'] ?? ''))
		),
		rawurlencode(
			(string)($arr['~IBLOCK_TYPE_ID'] ?? ($arr['IBLOCK_TYPE_ID'] ?? ''))
		),
		($iblockId > 0 ? $iblockId : ''),
		rawurlencode(
			(string)($arr['~IBLOCK_CODE'] ?? ($arr['IBLOCK_CODE'] ?? ''))
		),
		rawurlencode(
			(string)($arr['~IBLOCK_EXTERNAL_ID'] ?? ($arr['IBLOCK_EXTERNAL_ID'] ?? ''))
		),
	];

	if ($arrType === "E")
	{
		if (strpos($url, '#PRODUCT_URL#') !== false)
		{
			$url = str_replace(
				'#PRODUCT_URL#',
				self::getProductUrlValue($arr, $server_name),
				$url
			);
		}

		$arReplace[] = $preparedId;
		$arReplace[] = rawurlencode(
			(string)($arr['~CODE'] ?? ($arr['CODE'] ?? ''))
		);

		#Deal with symbol codes
		$SECTION_CODE = '';
		$SECTION_CODE_PATH = '';
		if ($iblockSectionId > 0)
		{
			if (strpos($url, '#SECTION_CODE#') !== false)
			{
				$SECTION_CODE = CIBlockSection::getSectionCode($iblockSectionId);
			}

			if (strpos($url, '#SECTION_CODE_PATH#') !== false)
			{
				$SECTION_CODE_PATH = CIBlockSection::getSectionCodePath($iblockSectionId);
			}
		}

		$arReplace[] = $iblockSectionId > 0 ? $iblockSectionId: '';
		$arReplace[] = $SECTION_CODE;
		$arReplace[] = $SECTION_CODE_PATH;
	}
	elseif ($arrType === "S")
	{
		$SECTION_CODE_PATH = '';
		if (
			$id > 0
			&& strpos($url, '#SECTION_CODE_PATH#') !== false
		)
		{
			$SECTION_CODE_PATH = CIBlockSection::getSectionCodePath($id);
		}
		$arReplace[] = '';
		$arReplace[] = '';
		$arReplace[] = $preparedId;
		$arReplace[] = $preparedCode;
		$arReplace[] = $SECTION_CODE_PATH;
	}
	else
	{
		$elementId = (int)($arr['ELEMENT_ID'] ?? 0);
		$preparedElementId = $elementId > 0 ? $elementId : '';
		$arReplace[] = $preparedElementId;
		$arReplace[] = rawurlencode((string)($arr['~ELEMENT_CODE'] ?? ($arr['ELEMENT_CODE'] ?? '')));
		$arReplace[] = $iblockSectionId > 0 ? $iblockSectionId : '';
		$arReplace[] = rawurlencode((string)($arr['~SECTION_CODE'] ?? ($arr['SECTION_CODE'] ?? '')));
		$arReplace[] = '';
	}

	$url = str_replace($arSearch, $arReplace, $url);

	return preg_replace("'(?