• Модуль: disk
  • Путь к файлу: ~/bitrix/modules/disk/lib/uf/fileusertype.php
  • Класс: BitrixDiskUfFileUserType
  • Вызов: FileUserType::getPublicViewHTML
static function getPublicViewHTML($userField, $id, $params = "", $settings = array(), $matches = null)
{
	$userFieldManager = Driver::getInstance()->getUserFieldManager();
	$res = (is_array($matches) && is_string($matches[0]) ? $matches[0] : '');
	[$type, $realValue] = self::detectType($id);

	if ($type == self::TYPE_NEW_OBJECT || (is_array($matches) && $matches[1] == "DOCUMENT ID"))
	{
		$userFieldManager->loadBatchAttachedObject($userField["VALUE"]);

		$originalId = $id;
		$id = false;
		foreach ($userField["VALUE"] as $attachedObjectId)
		{
			if (!$userFieldManager->isLoadedAttachedObject($attachedObjectId))
			{
				continue;
			}

			$fileObject = $userFieldManager->getAttachedObjectById($attachedObjectId)->getFile();
			if (!$fileObject)
			{
				continue;
			}
			if ($type === self::TYPE_NEW_OBJECT && $fileObject->getId() == $realValue)
			{
				$id = $attachedObjectId;
				break;
			}
			elseif ($matches[1] === "DOCUMENT ID" && $fileObject->getXmlId() == $originalId)
			{
				$id = $attachedObjectId;
				break;
			}
		}
	}

	if ($id > 0)
	{
		$userField["VALUE"] = array_intersect($userField["VALUE"], array($id));
		$maxSize = array();
		if (is_array($settings) && !empty($settings) && array_key_exists("imageWidth", $settings) && array_key_exists("imageHeight", $settings))
			$maxSize = array("width" => $settings["imageWidth"], "height" => $settings["imageHeight"]);
		$size = array();
		if ($params != '' && is_string($params) && preg_match_all("/(width|height)=(d+)/is", $params, $matches))
			$size = array_combine($matches[1], $matches[2]);
		ob_start();

		$newParams = $settings + array(
			"arUserField" => $userField,
			"INLINE" => "Y",
			"LAZYLOAD" => (isset($settings["LAZYLOAD"]) && $settings["LAZYLOAD"] == "Y" ? "Y" : "N"),
			"MAX_SIZE" => $maxSize,
			"SIZE" => array($id => $size),
			"TEMPLATE" => $settings["TEMPLATE"]
		);

		$newResult = array("VALUE" => array($id));
		if ($newParams['INLINE'] === 'Y')
		{
			if (
				isset($newParams['TEMPLATE'])
				&& $newParams['TEMPLATE'] === 'mobile'
			)
			{
				$newParams['MOBILE'] = 'Y';
			}

			$userFieldManager->showInlineView(
				$newParams,
				$newResult,
				null
			);
		}
		else
		{
			$userFieldManager->showView(
				$newParams,
				$newResult,
				null
			);
		}
		$res = ob_get_clean();
	}
	return $res;
}