\DevOwl\HeadlessContentBlocker\plugins\imagePreviewImagePreview

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!

Summary

Methods
Properties
Constants
__construct()
afterSetup()
init()
modifyHtmlAfterProcessing()
beforeMatch()
blockedMatch()
notBlockedMatch()
checkResult()
keepAlwaysAttributes()
skipInlineScriptVariableAssignment()
inlineStyleShouldBeExtracted()
inlineStyleModifyDocuments()
inlineStyleBlockRule()
visualParent()
blockableStringExpression()
getHeadlessContentBlocker()
getWriteJson()
fetchMetadata()
setCache()
getCache()
No public properties found
HTML_ATTRIBUTE_TO_FETCH_URL_FROM
HTML_ATTRIBUTE_TO_FETCH_URL_FROM_ALTERNATIVE
SKIP_EMBED_URL_EXTENSIONS
findUrlForSpecialMatch()
isValidEmbedUrl()
No protected properties found
N/A
No private methods found
$headlessContentBlocker
$attributesToCheckForUrl
$htmlHeadThumbnailParser
$cache
N/A

Constants

HTML_ATTRIBUTE_TO_FETCH_URL_FROM

HTML_ATTRIBUTE_TO_FETCH_URL_FROM ='hcb-fetch-image-from'

HTML_ATTRIBUTE_TO_FETCH_URL_FROM_ALTERNATIVE

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

SKIP_EMBED_URL_EXTENSIONS

SKIP_EMBED_URL_EXTENSIONS =array('js', 'css', 'zip', 'pdf')

Properties

$headlessContentBlocker

$headlessContentBlocker :

Type

$attributesToCheckForUrl

$attributesToCheckForUrl :array<mixed,string>

A list of possible link attributes.

Type

array<mixed,string>

Methods

afterSetup()

afterSetup()

The content blocker got setup completely.

init()

init()

Init.

modifyHtmlAfterProcessing()

modifyHtmlAfterProcessing(string  $html)

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

Parameters

string $html

checkResult()

checkResult(\DevOwl\HeadlessContentBlocker\BlockedResult  $result,\DevOwl\HeadlessContentBlocker\matcher\AbstractMatcher  $matcher,\DevOwl\FastHtmlTag\finder\match\AbstractMatch  $match): \DevOwl\HeadlessContentBlocker\BlockedResult

Special case: Read attribute of the original embed URL if it got passed via a custom attribute.

Parameters

\DevOwl\HeadlessContentBlocker\BlockedResult $result
\DevOwl\HeadlessContentBlocker\matcher\AbstractMatcher $matcher
\DevOwl\FastHtmlTag\finder\match\AbstractMatch $match

Returns

\DevOwl\HeadlessContentBlocker\BlockedResult

inlineStyleShouldBeExtracted()

inlineStyleShouldBeExtracted(boolean  $extract,\DevOwl\HeadlessContentBlocker\matcher\StyleInlineMatcher|\DevOwl\HeadlessContentBlocker\matcher\StyleInlineAttributeMatcher  $matcher,\DevOwl\FastHtmlTag\finder\match\StyleInlineMatch|\DevOwl\HeadlessContentBlocker\finder\match\StyleInlineAttributeMatch  $match): boolean

Do not extract blocked rules of a CSS inline script to a second document.

Parameters

boolean $extract
\DevOwl\HeadlessContentBlocker\matcher\StyleInlineMatcher|\DevOwl\HeadlessContentBlocker\matcher\StyleInlineAttributeMatcher $matcher
\DevOwl\FastHtmlTag\finder\match\StyleInlineMatch|\DevOwl\HeadlessContentBlocker\finder\match\StyleInlineAttributeMatch $match

Returns

boolean

inlineStyleModifyDocuments()

inlineStyleModifyDocuments(\Sabberworm\CSS\CSSList\Document  $document,\Sabberworm\CSS\CSSList\Document  $extractedDocument,\DevOwl\HeadlessContentBlocker\matcher\StyleInlineMatcher|\DevOwl\HeadlessContentBlocker\matcher\StyleInlineAttributeMatcher  $matcher,\DevOwl\FastHtmlTag\finder\match\StyleInlineMatch|\DevOwl\HeadlessContentBlocker\finder\match\StyleInlineAttributeMatch  $match): boolean

Allows to modify blocked CSS documents.

Parameters

\Sabberworm\CSS\CSSList\Document $document
\Sabberworm\CSS\CSSList\Document $extractedDocument
\DevOwl\HeadlessContentBlocker\matcher\StyleInlineMatcher|\DevOwl\HeadlessContentBlocker\matcher\StyleInlineAttributeMatcher $matcher
\DevOwl\FastHtmlTag\finder\match\StyleInlineMatch|\DevOwl\HeadlessContentBlocker\finder\match\StyleInlineAttributeMatch $match

Returns

boolean

inlineStyleBlockRule()

inlineStyleBlockRule(\DevOwl\HeadlessContentBlocker\BlockedResult  $result,string  $url,\DevOwl\HeadlessContentBlocker\matcher\StyleInlineMatcher|\DevOwl\HeadlessContentBlocker\matcher\StyleInlineAttributeMatcher  $matcher,\DevOwl\FastHtmlTag\finder\match\StyleInlineMatch|\DevOwl\HeadlessContentBlocker\finder\match\StyleInlineAttributeMatch  $match): boolean

Decide if a URL in a CSS rule should be blocked.

Parameters

\DevOwl\HeadlessContentBlocker\BlockedResult $result
string $url
\DevOwl\HeadlessContentBlocker\matcher\StyleInlineMatcher|\DevOwl\HeadlessContentBlocker\matcher\StyleInlineAttributeMatcher $matcher
\DevOwl\FastHtmlTag\finder\match\StyleInlineMatch|\DevOwl\HeadlessContentBlocker\finder\match\StyleInlineAttributeMatch $match

Returns

boolean

visualParent()

visualParent(boolean|string|\DevOwl\HeadlessContentBlocker\number  $visualParent,\DevOwl\HeadlessContentBlocker\matcher\AbstractMatcher  $matcher,\DevOwl\FastHtmlTag\finder\match\AbstractMatch  $match): boolean|string|\DevOwl\HeadlessContentBlocker\number

Set a visual parent for a specific match.

Parameters

boolean|string|\DevOwl\HeadlessContentBlocker\number $visualParent
\DevOwl\HeadlessContentBlocker\matcher\AbstractMatcher $matcher
\DevOwl\FastHtmlTag\finder\match\AbstractMatch $match

Returns

boolean|string|\DevOwl\HeadlessContentBlocker\number

blockableStringExpression()

blockableStringExpression(string  $expression,\DevOwl\HeadlessContentBlocker\AbstractBlockable  $blockable): string

Allows to modify the passed string expression to a blockable.

Parameters

string $expression
\DevOwl\HeadlessContentBlocker\AbstractBlockable $blockable

Returns

string

getHeadlessContentBlocker()

getHeadlessContentBlocker()

Getter.

fetchMetadata()

fetchMetadata(array<mixed,\DevOwl\HeadlessContentBlocker\plugins\imagePreview\Thumbnail>  $thumbnails)

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.

Mechanism:

  1. Cache
  2. Oembed
  3. HTML Head Parser and extract thumbnail URL from known meta tags

Parameters

array<mixed,\DevOwl\HeadlessContentBlocker\plugins\imagePreview\Thumbnail> $thumbnails

Key needs to be the embed URL

getCache()

getCache()

Getter.

isValidEmbedUrl()

isValidEmbedUrl(string  $embedUrl,boolean  $respectSpecialCases = true)

Check if a given embed URL is valid.

Parameters

string $embedUrl
boolean $respectSpecialCases