• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/lib/component/tools.php
  • Класс: BitrixIblockComponentTools
  • Вызов: Tools::getFieldImageData
static function getFieldImageData(array &$item, array $keys, $entity, $ipropertyKey = 'IPROPERTY_VALUES')
{
	if (empty($item) || empty($keys))
		return;

	$entity = (string)$entity;
	$ipropertyKey = (string)$ipropertyKey;
	foreach ($keys as $fieldName)
	{
		if (!array_key_exists($fieldName, $item) || is_array($item[$fieldName]))
			continue;
		$imageData = false;
		$imageId = (int)$item[$fieldName];
		if ($imageId > 0)
			$imageData = CFile::getFileArray($imageId);
		unset($imageId);
		if (is_array($imageData))
		{
			if (isset($imageData['SAFE_SRC']))
			{
				$imageData['UNSAFE_SRC'] = $imageData['SRC'];
				$imageData['SRC'] = $imageData['SAFE_SRC'];
			}
			else
			{
				if (!preg_match(self::WEB_PROTOCOL_MASK, $imageData['SRC']))
				{
					$imageData['UNSAFE_SRC'] = $imageData['SRC'];
					$imageData['SAFE_SRC'] = MainWebUri::urnEncode($imageData['SRC'], 'UTF-8');
					$imageData['SRC'] = $imageData['SAFE_SRC'];
				}
			}
			$imageData['ALT'] = '';
			$imageData['TITLE'] = '';
			if ($ipropertyKey != '' && isset($item[$ipropertyKey]) && is_array($item[$ipropertyKey]))
			{
				$entityPrefix = $entity.'_'.$fieldName;
				if (isset($item[$ipropertyKey][$entityPrefix.'_FILE_ALT']))
					$imageData['ALT'] = $item[$ipropertyKey][$entityPrefix.'_FILE_ALT'];
				if (isset($item[$ipropertyKey][$entityPrefix.'_FILE_TITLE']))
					$imageData['TITLE'] = $item[$ipropertyKey][$entityPrefix.'_FILE_TITLE'];
				unset($entityPrefix);
			}
			if ($imageData['ALT'] == '' && isset($item['NAME']))
				$imageData['ALT'] = $item['NAME'];
			if ($imageData['TITLE'] == '' && isset($item['NAME']))
				$imageData['TITLE'] = $item['NAME'];
		}
		$item[$fieldName] = $imageData;
		unset($imageData);
	}
	unset($fieldName);
}