Documentation

ImagePreview extends AbstractPlugin
in package

Detects, if there could be created an image preview for a given URL, downloads it and appends it as a custom attribute to the blocked HTML tag so the visual content blocker could create something cool.

  • You need to pass a setCache to the plugin instance, otherwise the mechanism does not track any URLs. The purpose of the headless content blocker is to block external URLs, and we do not want to use an external URL as image preview!
  • Your AbstractBlockable needs to implement ImagePreviewBlockable interface to determine if thumbnails should be loaded for the blocked content!

Table of Contents

Constants

HTML_ATTRIBUTE_TO_FETCH_URL_FROM  = 'hcb-fetch-image-from'
HTML_ATTRIBUTE_TO_FETCH_URL_FROM_ALTERNATIVE  = 'hcb-fetch-image-from-alt'
SKIP_EMBED_URL_EXTENSIONS  = ['js', 'css', 'zip', 'pdf']

Properties

$attributesToCheckForUrl  : array<string|int, string>
A list of possible link attributes.
$cache  : ImagePreviewCache
ImagePreviewCache.
$headlessContentBlocker  : mixed
$htmlHeadThumbnailParser  : HtmlHeadThumbnailParser
HtmlHeadThumbnailParser.
$revertAttributesToCachedUrl  : array<string|int, string>
See `addRevertAttribute`.

Methods

__construct()  : mixed
C'tor.
addRevertAttribute()  : mixed
A list of selector syntax strings which should be reverted to the cached URL for all transformed attributes.
afterSetup()  : mixed
The content blocker got setup completely.
beforeMatch()  : mixed
Called before a match got found.
blockableStringExpression()  : string
Allows to modify the passed string expression to a blockable.
blockedMatch()  : mixed
See `AbstractPlugin`.
checkResult()  : BlockedResult
Special case: Read attribute of the original embed URL if it got passed via a custom attribute.
fetchMetadata()  : mixed
Use multiple mechanism to extract a thumbnail from any URL. It returns an map of URL => thumbnail, and if a thumbnail got not found it is no longer part of the returned map.
getCache()  : mixed
Getter.
getHeadlessContentBlocker()  : mixed
Getter.
getWriteJson()  : mixed
Create the result for the HTML attribute which our unblocker can consume.
init()  : mixed
Init.
inlineStyleBlockRule()  : bool
Decide if a URL in a CSS rule should be blocked.
inlineStyleModifyDocuments()  : bool
Allows to modify blocked CSS documents.
inlineStyleShouldBeExtracted()  : bool
Do not extract blocked rules of a CSS inline script to a second document.
keepAlwaysAttributes()  : array<string|int, string>
Keep attributes for a specific match.
modifyHtmlAfterProcessing()  : mixed
Allows to modify the HTML after the content blocker has done its job.
notBlockedMatch()  : mixed
Called after a match got not blocked. Opposite of `blockedMatch`.
revertTransformAttributeOnMatch()  : mixed
When a match with `consent-thumbnail is found, revert the transformation of the attribute.
setCache()  : mixed
Setter.
setup()  : mixed
Before the content blocker gets setup.
skipInlineScriptVariableAssignment()  : array<string|int, string>
Skip inline script by variable name.
visualParent()  : bool|string|number
Set a visual parent for a specific match.
findUrlForSpecialMatch()  : mixed
Find an embed URL for a special match.
isValidEmbedUrl()  : mixed
Check if a given embed URL is valid.
revertTransformAttribute()  : mixed
Revert the transformation of a URL attribute when we have found a thumbnail and it is cached.

Constants

HTML_ATTRIBUTE_TO_FETCH_URL_FROM

public mixed HTML_ATTRIBUTE_TO_FETCH_URL_FROM = 'hcb-fetch-image-from'

HTML_ATTRIBUTE_TO_FETCH_URL_FROM_ALTERNATIVE

public mixed HTML_ATTRIBUTE_TO_FETCH_URL_FROM_ALTERNATIVE = 'hcb-fetch-image-from-alt'

SKIP_EMBED_URL_EXTENSIONS

public mixed SKIP_EMBED_URL_EXTENSIONS = ['js', 'css', 'zip', 'pdf']

Properties

$attributesToCheckForUrl

A list of possible link attributes.

private array<string|int, string> $attributesToCheckForUrl = []

$revertAttributesToCachedUrl

See `addRevertAttribute`.

private array<string|int, string> $revertAttributesToCachedUrl = []

Methods

addRevertAttribute()

A list of selector syntax strings which should be reverted to the cached URL for all transformed attributes.

public addRevertAttribute(string $selectorSyntax) : mixed

E.g. div[class*="et_pb_video_slider_item_"] will revert e.g. consent-original-data-image back to data-image with the cached URL.

Parameters
$selectorSyntax : string

afterSetup()

The content blocker got setup completely.

public afterSetup() : mixed

blockableStringExpression()

Allows to modify the passed string expression to a blockable.

public blockableStringExpression(string $expression, AbstractBlockable $blockable) : string
Parameters
$expression : string
$blockable : AbstractBlockable
Return values
string

fetchMetadata()

Use multiple mechanism to extract a thumbnail from any URL. It returns an map of URL => thumbnail, and if a thumbnail got not found it is no longer part of the returned map.

public fetchMetadata(array<string|int, Thumbnail&$thumbnails) : mixed

Mechanism:

  1. Cache
  2. Oembed
  3. HTML Head Parser and extract thumbnail URL from known meta tags
Parameters
$thumbnails : array<string|int, Thumbnail>

Key needs to be the embed URL

getCache()

Getter.

public getCache() : mixed
Tags
codeCoverageIgnore

getHeadlessContentBlocker()

Getter.

public final getHeadlessContentBlocker() : mixed
Tags
codeCoverageIgnore

getWriteJson()

Create the result for the HTML attribute which our unblocker can consume.

public getWriteJson(Thumbnail $thumbnail) : mixed
Parameters
$thumbnail : Thumbnail

keepAlwaysAttributes()

Keep attributes for a specific match.

public keepAlwaysAttributes(array<string|int, string> $keepAttributes, AbstractMatcher $matcher, AbstractMatch $match) : array<string|int, string>
Parameters
$keepAttributes : array<string|int, string>
$matcher : AbstractMatcher
$match : AbstractMatch
Return values
array<string|int, string>

modifyHtmlAfterProcessing()

Allows to modify the HTML after the content blocker has done its job.

public modifyHtmlAfterProcessing(string $html) : mixed
Parameters
$html : string

revertTransformAttributeOnMatch()

When a match with `consent-thumbnail is found, revert the transformation of the attribute.

public revertTransformAttributeOnMatch(AbstractMatch $match) : mixed
Parameters
$match : AbstractMatch

setup()

Before the content blocker gets setup.

public setup() : mixed

skipInlineScriptVariableAssignment()

Skip inline script by variable name.

public skipInlineScriptVariableAssignment(array<string|int, string> $names, ScriptInlineMatcher $matcher, ScriptInlineMatch $match) : array<string|int, string>
Parameters
$names : array<string|int, string>
$matcher : ScriptInlineMatcher
$match : ScriptInlineMatch
Return values
array<string|int, string>

visualParent()

Set a visual parent for a specific match.

public visualParent(bool|string|number $visualParent, AbstractMatcher $matcher, AbstractMatch $match) : bool|string|number
Parameters
$visualParent : bool|string|number
$matcher : AbstractMatcher
$match : AbstractMatch
Return values
bool|string|number

findUrlForSpecialMatch()

Find an embed URL for a special match.

protected findUrlForSpecialMatch(AbstractMatch $match) : mixed
Parameters
$match : AbstractMatch

isValidEmbedUrl()

Check if a given embed URL is valid.

protected isValidEmbedUrl(string $embedUrl[, bool $respectSpecialCases = true ]) : mixed
Parameters
$embedUrl : string
$respectSpecialCases : bool = true

revertTransformAttribute()

Revert the transformation of a URL attribute when we have found a thumbnail and it is cached.

protected revertTransformAttribute(string $html) : mixed
Parameters
$html : string

        
On this page

Search results