UrlPreview
Table of Contents
Constants
- FILE_RANGE = 1023
- IFRAME_MAX_HEIGHT = 340
- IFRAME_MAX_WIDTH = 640
- MAX_DESCRIPTION = 500
- MAX_FILE_SIZE = 1048576
- SIGN_SALT = 'url_preview'
- USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36 (Bitrix link preview)'
Methods
- checkDynamicPreviewAccess() : bool
- Returns true if current user has read access to the content behind internal url.
- fetchVideoMetaData() : array<string|int, mixed>|false
- Returns video metaData for $url if its host is trusted.
- getCurrentUserId() : int
- Returns id of currently logged user.
- getDynamicPreview() : string|false
- Returns HTML code for the dynamic (internal url) preview.
- getImAttach() : CIMMessageParamAttach|false
- Returns attach for the IM message with the requested internal entity content.
- getImRich() : RichData|false
- getInnerFrameUrl() : bool|string
- Returns inner frame url to embed third parties html video players.
- getMetadataAndHtmlByIds() : array<string|int, mixed>|false
- Returns stored metadata for array of IDs
- getMetadataAndHtmlByUrl() : array<string|int, mixed>|false
- If url is remote - returns metadata for this url. If url is local - checks current user access to the entity behind the url, and returns html preview for this entity.
- getMetadataByIds() : mixed
- getMetadataByUrl() : array<string|int, mixed>|false
- Returns associated metadata for the specified URL
- isEnabled() : bool
- Checks if UrlPreview is enabled in module option
- isHostTrusted() : bool
- Returns true if host of $uri is in $trustedHosts list.
- isIpAddressPrivate() : bool
- isUrlCached() : bool
- Checks if metadata for the provided url is already fetched and cached.
- reserveIdForUrl() : int
- Creates temporary record for url
- resolveTemporaryMetadata() : array<string|int, mixed>|false
- Fetches and stores metadata for temporary record, created by UrlPreview::reserveIdForUrl. If metadata could not be fetched, deletes record.
- setMetadataImage() : bool
- Sets main image url for the metadata with given id.
- showEdit() : string
- Returns html code for url preview edit form
- showView() : string
- Returns html code for url preview
- sign() : string
- Signs value using UrlPreview salt
Constants
FILE_RANGE
public
int
FILE_RANGE
= 1023
Range to read picture size
IFRAME_MAX_HEIGHT
public
mixed
IFRAME_MAX_HEIGHT
= 340
IFRAME_MAX_WIDTH
public
mixed
IFRAME_MAX_WIDTH
= 640
MAX_DESCRIPTION
public
int
MAX_DESCRIPTION
= 500
Maximum allowed length of the description.
MAX_FILE_SIZE
public
int
MAX_FILE_SIZE
= 1048576
Maximum allowed picture size
SIGN_SALT
public
mixed
SIGN_SALT
= 'url_preview'
USER_AGENT
public
mixed
USER_AGENT
= 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36 (Bitrix link preview)'
Methods
checkDynamicPreviewAccess()
Returns true if current user has read access to the content behind internal url.
public
static checkDynamicPreviewAccess(string $url[, mixed $userId = 0 ]) : bool
Parameters
- $url : string
-
URL of the internal document.
- $userId : mixed = 0
Tags
Return values
bool —True if current user has read access to the main entity of the document, or false otherwise.
fetchVideoMetaData()
Returns video metaData for $url if its host is trusted.
public
static fetchVideoMetaData(string $url) : array<string|int, mixed>|false
Parameters
- $url : string
Return values
array<string|int, mixed>|falsegetCurrentUserId()
Returns id of currently logged user.
public
static getCurrentUserId() : int
Return values
int —User's id.
getDynamicPreview()
Returns HTML code for the dynamic (internal url) preview.
public
static getDynamicPreview(string $url[, bool $checkAccess = true ][, mixed $userId = 0 ]) : string|false
Parameters
- $url : string
-
URL of the internal document.
- $checkAccess : bool = true
-
Should method check current user's access to the entity, or not.
- $userId : mixed = 0
Tags
Return values
string|false —HTML code of the preview, or false if case of any errors (including access denied)/
getImAttach()
Returns attach for the IM message with the requested internal entity content.
public
static getImAttach(string $url[, bool $checkAccess = true ][, mixed $userId = 0 ]) : CIMMessageParamAttach|false
Parameters
- $url : string
-
URL of the internal document.
- $checkAccess : bool = true
-
Should method check current user's access to the entity, or not.
- $userId : mixed = 0
Tags
Return values
CIMMessageParamAttach|falsegetImRich()
public
static getImRich(mixed $url[, bool $checkAccess = true ][, int $userId = 0 ]) : RichData|false
Parameters
- $url : mixed
- $checkAccess : bool = true
- $userId : int = 0
Return values
RichData|falsegetInnerFrameUrl()
Returns inner frame url to embed third parties html video players.
public
static getInnerFrameUrl(int $id[, string $provider = '' ]) : bool|string
Parameters
- $id : int
- $provider : string = ''
Return values
bool|stringgetMetadataAndHtmlByIds()
Returns stored metadata for array of IDs
public
static getMetadataAndHtmlByIds(array<string|int, mixed> $ids[, bool $checkAccess = true ][, mixed $userId = 0 ]) : array<string|int, mixed>|false
Parameters
- $ids : array<string|int, mixed>
-
Array of record's IDs.
- $checkAccess : bool = true
-
Should method check current user's access to the internal entities, or not.
- $userId : mixed = 0
Tags
Return values
array<string|int, mixed>|false —Array with provided IDs as the keys.
getMetadataAndHtmlByUrl()
If url is remote - returns metadata for this url. If url is local - checks current user access to the entity behind the url, and returns html preview for this entity.
public
static getMetadataAndHtmlByUrl(string $url[, bool $addIfNew = true ][, mixed $reuseExistingMetadata = true ]) : array<string|int, mixed>|false
Parameters
- $url : string
-
Document's URL.
- $addIfNew : bool = true
-
Should method fetch and store metadata for the document, if it is not found in database.
- $reuseExistingMetadata : mixed = true
Tags
Return values
array<string|int, mixed>|false —Metadata for the document, or false if metadata could not be fetched/parsed.
getMetadataByIds()
public
static getMetadataByIds(array<string|int, mixed> $ids) : mixed
Parameters
- $ids : array<string|int, mixed>
getMetadataByUrl()
Returns associated metadata for the specified URL
public
static getMetadataByUrl(string $url[, bool $addIfNew = true ][, bool $reuseExistingMetadata = true ]) : array<string|int, mixed>|false
Parameters
- $url : string
-
URL.
- $addIfNew : bool = true
-
Should metadata be fetched and saved, if not found in database.
- $reuseExistingMetadata : bool = true
-
Allow reading of the cached metadata.
Return values
array<string|int, mixed>|false —Metadata for the URL if found, or false otherwise.
isEnabled()
Checks if UrlPreview is enabled in module option
public
static isEnabled() : bool
Return values
bool —True if UrlPreview is enabled in module options.
isHostTrusted()
Returns true if host of $uri is in $trustedHosts list.
public
static isHostTrusted(Uri $uri) : bool
Parameters
- $uri : Uri
Return values
boolisIpAddressPrivate()
public
static isIpAddressPrivate(string $ipAddress) : bool
Will be removed.
Parameters
- $ipAddress : string
Return values
boolisUrlCached()
Checks if metadata for the provided url is already fetched and cached.
public
static isUrlCached(string $url) : bool
Parameters
- $url : string
-
Document's URL.
Return values
bool —True if metadata for the url is located in database, false otherwise.
reserveIdForUrl()
Creates temporary record for url
public
static reserveIdForUrl(string $url) : int
Parameters
- $url : string
-
URL for which temporary record should be created.
Return values
int —Temporary record's id.
resolveTemporaryMetadata()
Fetches and stores metadata for temporary record, created by UrlPreview::reserveIdForUrl. If metadata could not be fetched, deletes record.
public
static resolveTemporaryMetadata(int $id[, bool $checkAccess = true ][, mixed $userId = 0 ]) : array<string|int, mixed>|false
Parameters
- $id : int
-
Metadata record's id.
- $checkAccess : bool = true
-
Should method check current user's access to the entity, or not.
- $userId : mixed = 0
Tags
Return values
array<string|int, mixed>|false —Metadata if fetched, false otherwise.
setMetadataImage()
Sets main image url for the metadata with given id.
public
static setMetadataImage(int $id, string $imageUrl) : bool
Parameters
- $id : int
-
ID of the metadata to set image url.
- $imageUrl : string
-
Url of the image.
Tags
Return values
bool —Returns true in case of successful update, or false otherwise.
showEdit()
Returns html code for url preview edit form
public
static showEdit(array<string|int, mixed> $userField, array<string|int, mixed> $userFieldParams) : string
Parameters
- $userField : array<string|int, mixed>
-
Userfield's value.
- $userFieldParams : array<string|int, mixed>
-
Userfield's parameters.
Return values
string —HTML code for the preview.
showView()
Returns html code for url preview
public
static showView(array<string|int, mixed> $userField, array<string|int, mixed> $userFieldParams, string &$cacheTag[, bool $edit = false ]) : string
Parameters
- $userField : array<string|int, mixed>
-
Userfield's value.
- $userFieldParams : array<string|int, mixed>
-
Userfield's parameters.
- $cacheTag : string
-
Cache tag for returned preview (out param).
- $edit : bool = false
-
Show method build preview for editing the userfield.
Return values
string —HTML code for the preview.
sign()
Signs value using UrlPreview salt
public
static sign(string $id) : string
Parameters
- $id : string
-
Unsigned value.
Tags
Return values
string —Signed value.