• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/urlpreview/parser/common.php
  • Класс: BitrixMainUrlPreviewParserCommon
  • Вызов: Common::handle
public function handle(HtmlDocument $document)
{
	if($document->getTitle() == '')
	{
		$document->setTitle($this->getTitle($document));
	}

	if($document->getDescription() == '')
	{
		$document->setDescription($document->getMetaContent('description'));
	}

	$this->imgElements = $document->extractElementAttributes('img');
	if($document->getImage() == '')
	{
		$image = $this->getImage($document);
		if($image <> '')
		{
			$document->setImage($image);
		}
		else
		{
			$imageCandidates = $this->getImageCandidates();
			if(count($imageCandidates) === 1)
			{
				$document->setImage($imageCandidates[0]);
			}
			else if(count($imageCandidates) > 1)
			{
				$document->setExtraField('IMAGES', $imageCandidates);
			}
		}
	}
	if($document->getExtraField('VIDEO') == '')
	{
		preg_match_all("//mis", $document->getHtml(), $videoTags);
		foreach($videoTags[0] as $videoTag)
		{
			$videoInfo = $this->getVideoInfo($videoTag);
			if(!empty($videoInfo))
			{
				$document->setExtraField('VIDEO', $videoInfo['src']);
				$document->setExtraField('VIDEO_TYPE', $videoInfo['type']);
				$document->setExtraField('VIDEO_WIDTH', $videoInfo['width']);
				$document->setExtraField('VIDEO_HEIGHT', $videoInfo['height']);
			}
		}
	}
}