• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/classes/general/iblockresult.php
  • Класс: CIBlockResult
  • Вызов: CIBlockResult::GetNext
function GetNext($bTextHtmlAuto=true, $use_tilda=true)
{
	static $arSectionPathCache = array();

	$res = parent::GetNext($bTextHtmlAuto, $use_tilda);
	if($res)
	{
		//Handle List URL for Element, Section or IBlock
		if($this->strListUrl)
			$TEMPLATE = $this->strListUrl;
		elseif(array_key_exists("~LIST_PAGE_URL", $res))
			$TEMPLATE = $res["~LIST_PAGE_URL"];
		elseif(!$use_tilda && array_key_exists("LIST_PAGE_URL", $res))
			$TEMPLATE = $res["LIST_PAGE_URL"];
		else
			$TEMPLATE = "";

		if($TEMPLATE)
		{
			$res_tmp = $res;
			if((intval(($res["IBLOCK_ID"] ?? 0)) <= 0) && (intval($res["ID"]) > 0))
			{
				$res_tmp["IBLOCK_ID"] = $res["ID"];
				$res_tmp["IBLOCK_CODE"] = $res["CODE"];
				$res_tmp["IBLOCK_EXTERNAL_ID"] = $res["EXTERNAL_ID"];
				if($use_tilda)
				{
					$res_tmp["~IBLOCK_ID"] = $res["~ID"];
					$res_tmp["~IBLOCK_CODE"] = $res["~CODE"];
					$res_tmp["~IBLOCK_EXTERNAL_ID"] = $res["~EXTERNAL_ID"];
				}
			}

			if($use_tilda)
			{
				$res["~LIST_PAGE_URL"] = CIBlock::ReplaceDetailUrl($TEMPLATE, $res_tmp, true, false);
				$res["LIST_PAGE_URL"] = htmlspecialcharsbx($res["~LIST_PAGE_URL"]);
			}
			else
			{
				$res["LIST_PAGE_URL"] = CIBlock::ReplaceDetailUrl($TEMPLATE, $res_tmp, true, false);
			}
		}

		//If this is Element or Section then process it's detail and section URLs
		if(($res["IBLOCK_ID"] ?? '') <> '')
		{

			if(array_key_exists("GLOBAL_ACTIVE", $res))
			{
				$type = "S";
			}
			else
			{
				$type = "E";
			}

			if($this->strDetailUrl)
			{
				$TEMPLATE = $this->strDetailUrl;
			}
			elseif(array_key_exists("~DETAIL_PAGE_URL", $res))
			{
				$TEMPLATE = $res["~DETAIL_PAGE_URL"];
			}
			elseif(!$use_tilda && array_key_exists("DETAIL_PAGE_URL", $res))
			{
				$TEMPLATE = $res["DETAIL_PAGE_URL"];
			}
			else
			{
				$TEMPLATE = "";
			}

			if($TEMPLATE)
			{
				if($this->arSectionContext)
				{
					$TEMPLATE = str_replace("#SECTION_ID#", $this->arSectionContext["ID"], $TEMPLATE);
					$TEMPLATE = str_replace("#SECTION_CODE#", $this->arSectionContext["CODE"], $TEMPLATE);
					if(
						$this->arSectionContext["ID"] > 0
						&& $this->arSectionContext["IBLOCK_ID"] > 0
						&& mb_strpos($TEMPLATE, "#SECTION_CODE_PATH#") !== false
					)
					{
						if(!isset($arSectionPathCache[$this->arSectionContext["ID"]]))
						{
							$rs = CIBlockSection::GetNavChain(
								$this->arSectionContext["IBLOCK_ID"],
								$this->arSectionContext["ID"],
								array("ID", "IBLOCK_SECTION_ID", "CODE"),
								true
							);
							if (!empty($rs))
							{
								$arSectionPathCache[$this->arSectionContext["ID"]] = '';
								foreach ($rs as $a)
								{
									$arSectionPathCache[$this->arSectionContext["ID"]] .= rawurlencode($a["CODE"])."/";
								}
								unset($a);
							}
							unset($rs);
						}
						if(isset($arSectionPathCache[$this->arSectionContext["ID"]]))
						{
							$SECTION_CODE_PATH = rtrim($arSectionPathCache[$this->arSectionContext["ID"]], "/");
						}
						else
						{
							$SECTION_CODE_PATH = "";
						}
						$TEMPLATE = str_replace("#SECTION_CODE_PATH#", $SECTION_CODE_PATH, $TEMPLATE);
					}
				}

				if($use_tilda)
				{
					$res["~DETAIL_PAGE_URL"] = CIBlock::ReplaceDetailUrl($TEMPLATE, $res, true, $type);
					$res["DETAIL_PAGE_URL"] = htmlspecialcharsbx($res["~DETAIL_PAGE_URL"]);
				}
				else
				{
					$res["DETAIL_PAGE_URL"] = CIBlock::ReplaceDetailUrl($TEMPLATE, $res, true, $type);
				}
			}

			if($this->strSectionUrl)
			{
				$TEMPLATE = $this->strSectionUrl;
			}
			elseif(array_key_exists("~SECTION_PAGE_URL", $res))
			{
				$TEMPLATE = $res["~SECTION_PAGE_URL"];
			}
			elseif(!$use_tilda && array_key_exists("SECTION_PAGE_URL", $res))
			{
				$TEMPLATE = $res["SECTION_PAGE_URL"];
			}
			else
			{
				$TEMPLATE = "";
			}

			if($TEMPLATE)
			{
				if($use_tilda)
				{
					$res["~SECTION_PAGE_URL"] = CIBlock::ReplaceSectionUrl($TEMPLATE, $res, true, $type);
					$res["SECTION_PAGE_URL"] = htmlspecialcharsbx($res["~SECTION_PAGE_URL"]);
				}
				else
				{
					$res["SECTION_PAGE_URL"] = CIBlock::ReplaceSectionUrl($TEMPLATE, $res, true, $type);
				}
			}
		}

		if(array_key_exists("~CANONICAL_PAGE_URL", $res))
			$TEMPLATE = $res["~CANONICAL_PAGE_URL"];
		elseif(!$use_tilda && array_key_exists("CANONICAL_PAGE_URL", $res))
			$TEMPLATE = $res["CANONICAL_PAGE_URL"];
		else
			$TEMPLATE = "";

		if($TEMPLATE)
		{
			if($use_tilda)
			{
				$res["~CANONICAL_PAGE_URL"] = CIBlock::ReplaceDetailUrl($TEMPLATE, $res, true, "E");
				$res["CANONICAL_PAGE_URL"] = htmlspecialcharsbx($res["~CANONICAL_PAGE_URL"]);
			}
			else
			{
				$res["CANONICAL_PAGE_URL"] = CIBlock::ReplaceDetailUrl($TEMPLATE, $res, true, "E");
			}
		}
	}
	return $res;
}