- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/lib/urlpreview/urlpreview.php
- Класс: BitrixMainUrlPreviewUrlPreview
- Вызов: UrlPreview::showView
static function showView($userField, $userFieldParams, &$cacheTag, $edit = false)
{
global $APPLICATION;
$edit = !!$edit;
$cacheTag = '';
if (!static::isEnabled())
{
return null;
}
$metadataId = (int)$userField['VALUE'][0];
$metadata = false;
if ($metadataId > 0)
{
$metadata = UrlMetadataTable::getById($metadataId)->fetch();
if (isset($metadata['TYPE']) && $metadata['TYPE'] == UrlMetadataTable::TYPE_TEMPORARY)
{
$metadata = static::resolveTemporaryMetadata($metadata['ID']);
}
}
if (is_array($metadata))
{
$fullUrl = static::unfoldShortLink($metadata['URL']);
if ($metadata['TYPE'] == UrlMetadataTable::TYPE_DYNAMIC)
{
$routeRecord = Router::dispatch(new Uri($fullUrl));
if (isset($routeRecord['MODULE']) && Loader::includeModule($routeRecord['MODULE']))
{
$className = $routeRecord['CLASS'];
$routeRecord['PARAMETERS']['URL'] = $metadata['URL'];
$parameters = $routeRecord['PARAMETERS'];
if ($edit && (!method_exists($className, 'checkUserReadAccess') || !$className::checkUserReadAccess($parameters, static::getCurrentUserId())))
{
return null;
}
if (method_exists($className, 'buildPreview'))
{
$metadata['HANDLER'] = $routeRecord;
$metadata['HANDLER']['BUILD_METHOD'] = 'buildPreview';
}
if (method_exists($className, 'getCacheTag'))
{
$cacheTag = $className::getCacheTag();
}
}
elseif (!$edit)
{
return null;
}
}
}
elseif (!$edit)
{
return null;
}
ob_start();
$APPLICATION->IncludeComponent(
'bitrix:main.urlpreview',
'',
array(
'USER_FIELD' => $userField,
'METADATA' => is_array($metadata) ? $metadata : [],
'PARAMS' => $userFieldParams,
'EDIT' => ($edit ? 'Y' : 'N'),
'CHECK_ACCESS' => ($edit ? 'Y' : 'N'),
)
);
return ob_get_clean();
}