• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/classes/mysql/iblockrss.php
  • Класс: CIBlockRSS
  • Вызов: CIBlockRSS::GetRSSText
static function GetRSSText($arIBLOCK, $LIMIT_NUM = false, $LIMIT_DAY = false, $yandex = false)
{
	global $DB;

	$strRes = "";

	$protocol = BitrixMainContext::getCurrent()->getRequest()->isHttps() ? 'https://' : 'http://';

	$serverName = "";

	if (isset($arIBLOCK["SERVER_NAME"]) && $arIBLOCK["SERVER_NAME"] <> '')
		$serverName = $arIBLOCK["SERVER_NAME"];

	if ($serverName == '' && !isset($arIBLOCK["SERVER_NAME"]))
	{
		$dbSite = CSite::GetList('', '', array("LID" => $arIBLOCK["LID"]));
		if ($arSite = $dbSite->Fetch())
			$serverName = $arSite["SERVER_NAME"];
	}

	if ($serverName == '')
	{
		if (defined("SITE_SERVER_NAME") && SITE_SERVER_NAME <> '')
			$serverName = SITE_SERVER_NAME;
		else
			$serverName = COption::GetOptionString("main", "server_name", "www.bitrixsoft.com");
	}

	$strRes .= "n";
	$strRes .= "".htmlspecialcharsbx($arIBLOCK["NAME"])."n";
	$strRes .= "".$protocol.htmlspecialcharsbx($serverName)."n";
	$strRes .= "".htmlspecialcharsbx($arIBLOCK["DESCRIPTION"])."n";
	$strRes .= "".date("r")."n";
	$strRes .= "".$arIBLOCK["RSS_TTL"]."n";

	$db_img_arr = CFile::GetFileArray($arIBLOCK["PICTURE"]);
	if ($db_img_arr)
	{
		if(mb_substr($db_img_arr["SRC"], 0, 1) == "/")
			$strImage = $protocol.$serverName.$db_img_arr["SRC"];
		else
			$strImage = $db_img_arr["SRC"];

		if ($yandex)
		{
			$strRes .= "".htmlspecialcharsbx($strImage)."n";
			$squareSize = min($db_img_arr["WIDTH"], $db_img_arr["HEIGHT"]);
			if ($squareSize > 0)
			{
				$squarePicture = CFile::ResizeImageGet(
					$db_img_arr,
					array("width" => $squareSize, "height" => $squareSize),
					BX_RESIZE_IMAGE_EXACT
				);
				if ($squarePicture)
				{
					if(mb_substr($squarePicture["src"], 0, 1) == "/")
						$squareImage = $protocol.$serverName.$squarePicture["src"];
					else
						$squareImage = $squarePicture["src"];
					$strRes .= "".htmlspecialcharsbx($squareImage)."n";
				}
			}
		}
		else
		{
			$strRes .= "n";
			$strRes .= "".htmlspecialcharsbx($arIBLOCK["NAME"])."n";
			$strRes .= "".htmlspecialcharsbx($strImage)."n";
			$strRes .= "".$protocol.htmlspecialcharsbx($serverName)."n";
			$strRes .= "".$db_img_arr["WIDTH"]."n";
			$strRes .= "".$db_img_arr["HEIGHT"]."n";
			$strRes .= "n";
		}
	}

	$arNodes = array();
	$db_res = $DB->Query("SELECT NODE, NODE_VALUE FROM b_iblock_rss WHERE IBLOCK_ID = ".intval($arIBLOCK["ID"]));
	while ($db_res_arr = $db_res->Fetch())
	{
		$arNodes[$db_res_arr["NODE"]] = $db_res_arr["NODE_VALUE"];
	}

	$formatActiveDates = CPageOption::GetOptionString("iblock", "FORMAT_ACTIVE_DATES", "-");
	CPageOption::SetOptionString("iblock", "FORMAT_ACTIVE_DATES", "FULL");

	$nav = $LIMIT_NUM > 0? array("nTopCount" => $LIMIT_NUM): false;

	$arFilter = array(
		"IBLOCK_ID" => $arIBLOCK["ID"],
		"ACTIVE_DATE" => "Y",
		"ACTIVE" => "Y",
	);
	if ($LIMIT_DAY !== false)
	{
		$date = new BitrixMainTypeDateTime();
		$date->add("- $LIMIT_DAY days");
		$arFilter["ACTIVE_FROM"] = $date->toString();
	}

	CTimeZone::Disable();
	$items = CIBlockElement::GetList(array("ACTIVE_FROM"=>"DESC", "SORT"=>"ASC", "ID"=>"DESC"), $arFilter, false, $nav);
	CTimeZone::Enable();

	CPageOption::SetOptionString("iblock", "FORMAT_ACTIVE_DATES", $formatActiveDates);

	while ($arItem = $items->GetNext())
	{
		$props = CIBlockElement::GetProperty($arIBLOCK["ID"], $arItem["ID"], "sort", "asc", Array("ACTIVE"=>"Y", "NON_EMPTY"=>"Y"));
		$arProps = Array();
		while ($arProp = $props->Fetch())
		{
			if ($arProp["CODE"] <> '')
				$arProps[$arProp["CODE"]] = Array("NAME"=>htmlspecialcharsbx($arProp["NAME"]), "VALUE"=>htmlspecialcharsex($arProp["VALUE"]));
			else
				$arProps[$arProp["ID"]] = Array("NAME"=>htmlspecialcharsbx($arProp["NAME"]), "VALUE"=>htmlspecialcharsex($arProp["VALUE"]));
		}

		$arLinkProp = $arProps["DOC_LINK"];

		$strRes .= "n";
		if ($arNodes["title"] <> '')
		{
			$strRes .= "".htmlspecialcharsbx(CIBlockRSS::ExtractProperties($arNodes["title"], $arProps, $arItem))."n";
		}
		else
		{
			$strRes .= "".htmlspecialcharsbx($arItem["~NAME"])."n";
		}
		if ($arNodes["link"] <> '')
		{
			$strRes .= "".CIBlockRSS::ExtractProperties($arNodes["link"], $arProps, $arItem)."n";
		}
		else
		{
			$strRes .= "".$protocol.htmlspecialcharsbx($serverName).(($arLinkProp["VALUE"]) ? $arLinkProp["VALUE"] : $arItem["DETAIL_PAGE_URL"])."n";
		}
		if ($arNodes["description"] <> '')
		{
			$strRes .= "".htmlspecialcharsbx(CIBlockRSS::ExtractProperties($arNodes["description"], $arProps, $arItem))."n";
		}
		else
		{
			$strRes .= "".(($arItem["PREVIEW_TEXT"] || $yandex) ? htmlspecialcharsbx($arItem["PREVIEW_TEXT"]) : htmlspecialcharsbx($arItem["DETAIL_TEXT"]))."n";
		}
		if ($arNodes["enclosure"] <> '')
		{
			$strRes .= "n";
		}
		else
		{
			$db_img_arr = CFile::GetFileArray($arItem["PREVIEW_PICTURE"]);
			if ($db_img_arr)
			{
				if(mb_substr($db_img_arr["SRC"], 0, 1) == "/")
					$strImage = $protocol.$serverName.$db_img_arr["SRC"];
				else
					$strImage = $db_img_arr["SRC"];

				$strRes .= "n";
			}
		}
		if ($arNodes["category"] <> '')
		{
			$strRes .= "".htmlspecialcharsbx(CIBlockRSS::ExtractProperties($arNodes["category"], $arProps, $arItem))."n";
		}
		else
		{
			$strPath = "";
			$nav = CIBlockSection::GetNavChain(
				$arIBLOCK["ID"],
				$arItem["IBLOCK_SECTION_ID"],
				[
					'ID',
					'NAME',
				],
				true
			);
			foreach ($nav as $ar_nav)
			{
				$strPath .= $ar_nav["NAME"]."/";
			}
			unset($ar_nav, $nav);
			if ($strPath !== '')
			{
				$strRes .= "".htmlspecialcharsbx($strPath)."n";
			}
		}
		if ($yandex)
		{
			$strRes .= "".htmlspecialcharsbx($arItem["DETAIL_TEXT"])."n";
		}
		if ($arNodes["pubDate"] <> '')
		{
			$strRes .= "".htmlspecialcharsbx(CIBlockRSS::ExtractProperties($arNodes["pubDate"], $arProps, $arItem))."n";
		}
		else
		{
			if ($arItem["ACTIVE_FROM"] <> '')
			{
				$strRes .= "".date("r", MkDateTime($DB->FormatDate($arItem["ACTIVE_FROM"], Clang::GetDateFormat("FULL"), "DD.MM.YYYY H:I:S"), "d.m.Y H:i:s"))."n";
			}
			else
			{
				$strRes .= "".date("r")."n";
			}
		}
		$strRes .= "n";
	}
	$strRes .= "n";
	return $strRes;
}