Class humhub\models\UrlOembed

Inheritancehumhub\models\UrlOembed » yii\db\ActiveRecord

UrlOembed records hold already loaded oembed previews.

This class is used to fetch and save oembed results by means of the preload() and getOEmbed() methods.

preload() can be used to preload oembed results for a given text string.

getOEmbed() can be used to fetch a single oembed record for a given Url.

All successfull results of preload() or getOEmbed() will be cached and saved in the url_oembed table.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$allowed_types array Allowed oembed types humhub\models\UrlOembed
$maxUrlFetchLimit integer Maximum amount of remote fetch calls per request humhub\models\UrlOembed
$maxUrlLoadLimit integer Maximum amount of local db fetch calls per request humhub\models\UrlOembed

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$cache array Internal request cache humhub\models\UrlOembed
$client humhub\libs\UrlOembedClient humhub\models\UrlOembed
$urlsFetched integer Counter for remote fetch calls humhub\models\UrlOembed
$urlsLoaded integer Counter for local db fetch calls humhub\models\UrlOembed

Public Methods

Hide inherited methods

MethodDescriptionDefined By
attributeLabels() humhub\models\UrlOembed
flush() Flushes internal caches and fetch counters humhub\models\UrlOembed
getClient() Returns the UrlOembedClient responsible for fetching OEmbed results. humhub\models\UrlOembed
getOEmbed() Returns a OEmbed html string for a given $url or null in the following cases: humhub\models\UrlOembed
getProviderByUrl() humhub\models\UrlOembed
getProviderUrl() Returns the OEmbed API Url if exists humhub\models\UrlOembed
getProviders() Returns all available OEmbed providers humhub\models\UrlOembed
hasOEmbedSupport() Checks if a given URL Supports OEmbed humhub\models\UrlOembed
preload() Parses the given $text string for urls an saves new loaded OEmbed instances for. humhub\models\UrlOembed
rules() humhub\models\UrlOembed
setClient() Sets the UrlOembedClient responsible for fetching OEmbed results. humhub\models\UrlOembed
setProviders() Saves an array of available OEmbed providers humhub\models\UrlOembed
tableName() humhub\models\UrlOembed

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
buildHtmlPreview() Builds the oembed preview html result in case the given $data array is valid. humhub\models\UrlOembed
fetchUrl() Executes the remote fetch call in case the [$maxUrlFetchLimit] is not reached. humhub\models\UrlOembed
findExistingOembed() Checks if there is an existing UrlOembed record for the given $url. humhub\models\UrlOembed
loadUrl() Fetches the oembed result for a given $url and saves an UrlOembed record to the database. humhub\models\UrlOembed
validateOembedResponse() Validates the given $data array. humhub\models\UrlOembed

Constants

Hide inherited constants

ConstantValueDescriptionDefined By
FETCH 'fetch' humhub\models\UrlOembed

Property Details

$allowed_types public static property

Allowed oembed types

public static array $allowed_types = ['video''rich''photo']
$cache protected static property

Internal request cache

protected static array $cache = []
$client protected static property
protected static humhub\libs\UrlOembedClient $client null
$maxUrlFetchLimit public static property

Maximum amount of remote fetch calls per request

public static integer $maxUrlFetchLimit 5
$maxUrlLoadLimit public static property

Maximum amount of local db fetch calls per request

public static integer $maxUrlLoadLimit 100
$urlsFetched protected static property

Counter for remote fetch calls

protected static integer $urlsFetched 0
$urlsLoaded protected static property

Counter for local db fetch calls

protected static integer $urlsLoaded 0

Method Details

attributeLabels() public method

public void attributeLabels ( )
buildHtmlPreview() protected static method

Builds the oembed preview html result in case the given $data array is valid.

protected static string|null buildHtmlPreview ( $url, $data null )
$url
$data []|null
fetchUrl() protected static method

Executes the remote fetch call in case the [$maxUrlFetchLimit] is not reached.

protected static array|null fetchUrl ( $url )
$url string
throws humhub\libs\RestrictedCallException
findExistingOembed() protected static method

Checks if there is an existing UrlOembed record for the given $url.

Note: Results will be cached for this request if an record was found.

protected static humhub\models\UrlOembed|null findExistingOembed ( $url )
$url
throws humhub\libs\RestrictedCallException
flush() public static method

Flushes internal caches and fetch counters

public static void flush ( )
getClient() public static method

Returns the UrlOembedClient responsible for fetching OEmbed results.

public static humhub\libs\UrlOembedClient getClient ( )
getOEmbed() public static method

Returns a OEmbed html string for a given $url or null in the following cases:

  • There is no OEmbed provider available for the given url
  • The OEmbed provider does not return a valid response
  • A fetch counter restriction exceeded
public static string|null getOEmbed ( $url )
$url string
getProviderByUrl() public static method

public static mixed|null getProviderByUrl ( $url )
$url
getProviderUrl() public method

Returns the OEmbed API Url if exists

public string|null getProviderUrl ( )
getProviders() public static method

Returns all available OEmbed providers

public static array getProviders ( )
hasOEmbedSupport() public static method

Checks if a given URL Supports OEmbed

public static boolean hasOEmbedSupport ( $url )
$url string
loadUrl() protected static method

Fetches the oembed result for a given $url and saves an UrlOembed record to the database.

A Remote fetch for new urls is only executed in case there is a related provider for the given url configured.

protected static string|null loadUrl ( $url, $customProviderUrl '' )
$url string
$customProviderUrl string
preload() public static method

Parses the given $text string for urls an saves new loaded OEmbed instances for.

This method will only execute a remote fetch call if:

  • There was a provider found for the given url
  • The same url has not been fetched before
  • The max fetch counters are not exceeded
public static void preload ( $text )
$text string
rules() public method

public void rules ( )
setClient() public static method

Sets the UrlOembedClient responsible for fetching OEmbed results.

public static void setClient ( $client null )
$client null
setProviders() public static method

Saves an array of available OEmbed providers

public static void setProviders ( $providers )
$providers array
tableName() public static method

public static void tableName ( )
validateOembedResponse() protected static method

Validates the given $data array.

protected static boolean validateOembedResponse ( $data null )
$data []|null