• Модуль: landing
  • Путь к файлу: ~/bitrix/modules/landing/lib/landing/urlpreview.php
  • Класс: BitrixLandingLandingUrlPreview
  • Вызов: UrlPreview::getPreview
static function getPreview(int $landingId): array
{
	static $cached = [];

	if (array_key_exists($landingId, $cached))
	{
		return $cached[$landingId];
	}

	$result = [];

	$res = Landing::getList([
		'select' => [
			'ID',
			'TITLE',
			'SITE_TYPE' => 'SITE.TYPE'
		],
		'filter' => [
			'ID' => $landingId
		]
	]);
	if ($row = $res->fetch())
	{
		$landing = Landing::createInstance(0);
		$row['URL'] = $landing->getPublicUrl($landingId);
		$row['DESCRIPTION'] = '';
		$row['PICTURE'] = '';

		// gets title and description with hight priority
		$hookData = Hook::getForLandingRow($row['ID']);
		if (isset($hookData['METAOG']['TITLE']))
		{
			$row['TITLE'] = $hookData['METAOG']['TITLE'];
			if (isset($hookData['METAOG']['DESCRIPTION']))
			{
				$row['DESCRIPTION'] = $hookData['METAOG']['DESCRIPTION'];
			}
		}
		else if (isset($hookData['METAMAIN']['TITLE']))
		{
			$row['TITLE'] = $hookData['METAMAIN']['TITLE'];
			if (isset($hookData['METAMAIN']['DESCRIPTION']))
			{
				$row['DESCRIPTION'] = $hookData['METAMAIN']['DESCRIPTION'];
			}
		}
		if (isset($hookData['METAOG']['IMAGE']))
		{
			$row['PICTURE'] = $hookData['METAOG']['IMAGE'];
			if (intval($row['PICTURE']) > 0)
			{
				$row['PICTURE'] = File::getFilePath($row['PICTURE']);
			}
		}

		$result = $row;
	}

	$cached[$landingId] = $result;

	return $cached[$landingId];
}