Documentation

HeadlessContentBlocker extends FastHtmlTag
in package

Initialize a new headless content blocker.

Table of Contents

Constants

TAG_ATTRIBUTE_MAP_LINKABLE  = 'linkable'
The tag-attribute map for the usual links like `script[src],link[href],iframe[href]`.

Properties

$afterSetupCallbacks  : mixed
$allowMultipleBlockerResults  : mixed
$beforeMatchCallbacks  : mixed
$blockables  : array<string|int, AbstractBlockable>
List of blocked elements.
$blockablesToHostsCache  : mixed
$blockableStringExpressionCallback  : mixed
$blockedMatchCallbacks  : mixed
$checkResultCallbacks  : mixed
$finderToMatcher  : mixed
$inlineStyleBlockRuleByCallback  : mixed
$inlineStyleDummyUrlPath  : mixed
$inlineStyleModifyDocumentsByCallback  : mixed
$inlineStyleShouldBeExtractedByCallback  : mixed
$isSetup  : mixed
$keepAlwaysAttributes  : mixed
$keepAlwaysAttributesByCallback  : mixed
$keepAlwaysAttributesIfClass  : mixed
$notBlockedMatchCallbacks  : mixed
$plugins  : array<string|int, array<string|int, AbstractPlugin>>
List of registered plugins pointing to their object instance.
$replaceAlwaysAttributes  : mixed
$rerunExceptions  : array<string|int, RerunOnMatchException>
See `processMatch`.
$selectorSyntaxMap  : array<string|int, string>
Selector syntax map.
$setupCallbacks  : mixed
$skipInlineScriptVariableAssignments  : mixed
$skipInlineScriptVariableAssignmentsByCallback  : mixed
$tagAttributeMap  : mixed
$visualParentCallback  : mixed
$visualParentIfClass  : mixed

Methods

__construct()  : mixed
C'tor.
addAfterSetupCallback()  : mixed
Add a callable after the content blocker got setup.
addBeforeMatchCallback()  : mixed
Add a callable before a match got found (this does not mean that the match is blocked!).
addBlockables()  : mixed
Add a blockable item. In general, this are the URLs and elements you want to block.
addBlockableStringExpressionCallback()  : mixed
Allows to modify the passed string expression to a blockable.
addBlockedMatchCallback()  : mixed
Add a callable after a blocked match got found so you can alter the match again. Parameters: `BlockedResult $result, AbstractMatcher $matcher, AbstractMatch $match`.
addCheckResultCallback()  : mixed
Add a callable after a match got found and the matcher decided if it should be blocked or not.
addInlineStyleBlockRuleCallback()  : mixed
Add a callable after a blocked inline CSS rule got found, and we need to decide to block it or not.
addInlineStyleModifyDocumentsCallback()  : mixed
Add a callable after a blocked inline style got found, parsed and you can modify the `Document` instance.
addInlineStyleShouldBeExtractedCallback()  : mixed
Add a callable after a blocked inline style got found and skip creation of a second document with blocked URLs.
addKeepAlwaysAttributes()  : mixed
In some cases we need to keep the attributes as original instead of prefix it with `consent-original-`.
addKeepAlwaysAttributesCallback()  : mixed
Add a callable after a match got found and the matcher decided if it should be blocked or not.
addKeepAlwaysAttributesIfClass()  : mixed
See `addKeepAlwaysAttributes`, but consider the keep only if the found match has a given class.
addNotBlockedMatchCallback()  : mixed
Add a callable after a blocked match got not found, but a match. Parameters: `BlockedResult $result, AbstractMatcher $matcher, AbstractMatch $match`.
addPlugin()  : mixed
Register a complete plugin to this headless content blocker.
addReplaceAlwaysAttributes()  : mixed
A set of HTML tags => attribute names which should always prefix with `consent-original-`.
addSelectorSyntaxMap()  : mixed
Respect additional selector-syntax as blockable candiates. Keep in mind that this selector-syntax does not automatically block the defined attribute. Instead, you need to create a custom plugin / callback for `checkResult`.
addSetupCallback()  : mixed
Add a callable before the content blocker gets setup.
addSkipInlineScriptVariableAssignments()  : mixed
Do not block inline scripts starting with `var $variableName =`.
addSkipInlineScriptVariableAssignmentsCallback()  : mixed
Add a callable after a match got found and skip a script by custom variable name.
addTagAttributeMap()  : mixed
Respect additional tags and attributes for a given map. For example, there is the `self::TAG_ATTRIBUTE_MAP_LINKABLE` map which respects known linkable tags like `script[src],link[href],iframe[href]`.
addVisualParentCallback()  : mixed
Decide a visual parent for an individual match.
addVisualParentIfClass()  : mixed
See `Constants::HTML_ATTRIBUTE_VISUAL_PARENT` for more details about this mechanism.
blockablesToHosts()  : mixed
Create an expression => regular expression cache for all available URLs in available blockables.
getBlockableById()  : mixed
Get blockable by blocker ID.
getBlockableRulesStartingWith()  : array<string|int, array<string|int, mixed>>
Get blockable rules starting with a given string. This does only work for non-Selector-Syntax expressions.
getBlockables()  : mixed
Getter.
getFinderToMatcher()  : mixed
Getter.
getInlineStyleDummyUrlPath()  : mixed
Getter.
getKeepAlwaysAttributes()  : mixed
Getter.
getKeepAlwaysAttributesIfClass()  : mixed
Getter.
getPlugins()  : mixed
Getter.
getPluginsByClassName()  : mixed
Getter.
getReplaceAlwaysAttributes()  : mixed
Getter.
getSelectorSyntaxMap()  : mixed
Getter.
getSkipInlineScriptVariableAssignments()  : mixed
Getter.
getTagAttributeMap()  : mixed
Getter.
getVisualParentIfClass()  : mixed
Getter.
isAllowMultipleBlockerResults()  : mixed
Getter.
runBlockableStringExpressionCallback()  : mixed
Run registered blockable string expression callbacks.
runCheckResultCallback()  : BlockedResult
Run registered check-result callbacks.
runInlineStyleBlockRuleCallback()  : BlockedResult
Run registered check-result callbacks.
runInlineStyleModifyDocumentsCallback()  : mixed
Run registered callbacks to not extract blocked CSS rules to a second document.
runInlineStyleShouldBeExtractedByCallback()  : bool
Run registered callbacks to not extract blocked CSS rules to a second document.
runKeepAlwaysAttributesCallback()  : array<string|int, string>
Run registered keep-always-attributes callbacks.
runSkipInlineScriptVariableAssignmentsCallback()  : array<string|int, string>
Run registered skip-inline-names callbacks.
runVisualParentCallback()  : mixed
Run registered check-result callbacks.
setAllowMultipleBlockerResults()  : mixed
If you pass `true`, the generated `BlockedResult` will contain multiple results and will not break after the first found blockable to block.
setBlockables()  : mixed
Set blockable items. In general, this are the URLs and elements you want to block.
setInlineStyleDummyUrlPath()  : mixed
When blocking CSS inline styles, we replace URLs with dummy URLs and we cannot rely on data-uri's as we need to pass parameters, too.
setup()  : mixed
Setup the content blocker mechanism. You need to use this before you `modifyAny/modifyHtml` your content!
init()  : mixed
Add a callback which should throw an `Exception` when the content blocker is not setup.
processMatch()  : mixed
A match got found from one of our finders. Run plugins and hooks.
runAfterSetupCallback()  : mixed
Run registered after-setup callbacks.
runBeforeMatchCallback()  : mixed
Run registered before-match callbacks.
runBlockedMatchCallback()  : mixed
Run registered blocked-match callbacks.
runNotBlockedMatchCallback()  : mixed
Run registered not-blocked-match callbacks.
runSetupCallback()  : mixed
Run registered setup callbacks.

Constants

TAG_ATTRIBUTE_MAP_LINKABLE

The tag-attribute map for the usual links like `script[src],link[href],iframe[href]`.

public mixed TAG_ATTRIBUTE_MAP_LINKABLE = 'linkable'

Properties

$inlineStyleShouldBeExtractedByCallback

private mixed $inlineStyleShouldBeExtractedByCallback = []

$replaceAlwaysAttributes

private mixed $replaceAlwaysAttributes = ['iframe' => ['sandbox'], 'script' => ['type'], 'style' => ['type']]

$selectorSyntaxMap

Selector syntax map.

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

$skipInlineScriptVariableAssignmentsByCallback

private mixed $skipInlineScriptVariableAssignmentsByCallback = []

$tagAttributeMap

private mixed $tagAttributeMap = [self::TAG_ATTRIBUTE_MAP_LINKABLE => ['tags' => ['script', 'link', 'iframe', 'embed', 'img'], 'attr' => ['href', 'data-src', 'src']]]

Methods

addAfterSetupCallback()

Add a callable after the content blocker got setup.

public addAfterSetupCallback(callable $callback) : mixed
Parameters
$callback : callable

addBeforeMatchCallback()

Add a callable before a match got found (this does not mean that the match is blocked!).

public addBeforeMatchCallback(callable $callback) : mixed

Parameters: AbstractMatcher $matcher, AbstractMatch $match.

Parameters
$callback : callable

addBlockableStringExpressionCallback()

Allows to modify the passed string expression to a blockable.

public addBlockableStringExpressionCallback(callable $callback) : mixed

Parameters: string $expression, Blockable $blockable. This function needs to return a string!

Parameters
$callback : callable

addBlockedMatchCallback()

Add a callable after a blocked match got found so you can alter the match again. Parameters: `BlockedResult $result, AbstractMatcher $matcher, AbstractMatch $match`.

public addBlockedMatchCallback(callable $callback) : mixed
Parameters
$callback : callable

addCheckResultCallback()

Add a callable after a match got found and the matcher decided if it should be blocked or not.

public addCheckResultCallback(callable $callback) : mixed

Parameters: BlockedResult $result, AbstractMatcher $matcher, AbstractMatch $match. This function needs to return a BlockedResult instance.

Parameters
$callback : callable

addInlineStyleBlockRuleCallback()

Add a callable after a blocked inline CSS rule got found, and we need to decide to block it or not.

public addInlineStyleBlockRuleCallback(callable $callback) : mixed

Parameters: BlockedResult $extract, string $url, StyleInlineMatcher $matcher, StyleInlineMatch $match.

Parameters
$callback : callable

addInlineStyleModifyDocumentsCallback()

Add a callable after a blocked inline style got found, parsed and you can modify the `Document` instance.

public addInlineStyleModifyDocumentsCallback(callable $callback) : mixed

Parameters: boolean $extract, StyleInlineMatcher $matcher, StyleInlineMatch $match.

Parameters
$callback : callable

addInlineStyleShouldBeExtractedCallback()

Add a callable after a blocked inline style got found and skip creation of a second document with blocked URLs.

public addInlineStyleShouldBeExtractedCallback(callable $callback) : mixed

Parameters: boolean $extract, StyleInlineMatcher $matcher, StyleInlineMatch $match. This function needs to return a boolean array!

Parameters
$callback : callable

addKeepAlwaysAttributes()

In some cases we need to keep the attributes as original instead of prefix it with `consent-original-`.

public addKeepAlwaysAttributes(array<string|int, string> $attributes) : mixed

Keep in mind, that no external data should be loaded if the attribute is set!

Parameters
$attributes : array<string|int, string>

addKeepAlwaysAttributesCallback()

Add a callable after a match got found and the matcher decided if it should be blocked or not.

public addKeepAlwaysAttributesCallback(callable $callback) : mixed

Parameters: string[] $keepAttributes, AbstractMatcher $matcher, AbstractMatch $match. This function needs to return a string[] array!

Parameters
$callback : callable

addKeepAlwaysAttributesIfClass()

See `addKeepAlwaysAttributes`, but consider the keep only if the found match has a given class.

public addKeepAlwaysAttributesIfClass(array<string|int, array<string|int, string>> $classToAttributesMap) : mixed
Parameters
$classToAttributesMap : array<string|int, array<string|int, string>>

addNotBlockedMatchCallback()

Add a callable after a blocked match got not found, but a match. Parameters: `BlockedResult $result, AbstractMatcher $matcher, AbstractMatch $match`.

public addNotBlockedMatchCallback(callable $callback) : mixed
Parameters
$callback : callable

addPlugin()

Register a complete plugin to this headless content blocker.

public addPlugin(string $pluginName) : mixed
Parameters
$pluginName : string

The class name of the plugin (extended from AbstractPlugin)

addReplaceAlwaysAttributes()

A set of HTML tags => attribute names which should always prefix with `consent-original-`.

public addReplaceAlwaysAttributes(array<string|int, array<string|int, string>> $tagToAttributesMap) : mixed
Parameters
$tagToAttributesMap : array<string|int, array<string|int, string>>

addSelectorSyntaxMap()

Respect additional selector-syntax as blockable candiates. Keep in mind that this selector-syntax does not automatically block the defined attribute. Instead, you need to create a custom plugin / callback for `checkResult`.

public addSelectorSyntaxMap(array<string|int, string> $selectorSyntax) : mixed
Parameters
$selectorSyntax : array<string|int, string>

addSetupCallback()

Add a callable before the content blocker gets setup.

public addSetupCallback(callable $callback) : mixed
Parameters
$callback : callable

addSkipInlineScriptVariableAssignments()

Do not block inline scripts starting with `var $variableName =`.

public addSkipInlineScriptVariableAssignments(array<string|int, string> $names) : mixed
Parameters
$names : array<string|int, string>

addSkipInlineScriptVariableAssignmentsCallback()

Add a callable after a match got found and skip a script by custom variable name.

public addSkipInlineScriptVariableAssignmentsCallback(callable $callback) : mixed

Parameters: string[] $variableNames, ScriptInlineMatcher $matcher, ScriptInlineMatch $match. This function needs to return a string[] array!

Parameters
$callback : callable

addTagAttributeMap()

Respect additional tags and attributes for a given map. For example, there is the `self::TAG_ATTRIBUTE_MAP_LINKABLE` map which respects known linkable tags like `script[src],link[href],iframe[href]`.

public addTagAttributeMap(array<string|int, string> $tags[, array<string|int, string> $attributes = [] ][, string $mapName = self::TAG_ATTRIBUTE_MAP_LINKABLE ]) : mixed
Parameters
$tags : array<string|int, string>

Additional tags to consider for the passed map

$attributes : array<string|int, string> = []

Additional tags to consider for the passed map

$mapName : string = self::TAG_ATTRIBUTE_MAP_LINKABLE

Default is self::TAG_ATTRIBUTE_MAP_LINKABLE

addVisualParentCallback()

Decide a visual parent for an individual match.

public addVisualParentCallback(callable $callback) : mixed

Parameters: boolean|string|number $useVisualParent, AbstractMatcher $matcher, AbstractMatch $match. This function needs to return a boolean|string|number array!

Parameters
$callback : callable

addVisualParentIfClass()

See `Constants::HTML_ATTRIBUTE_VISUAL_PARENT` for more details about this mechanism.

public addVisualParentIfClass(array<string|int, array<string|int, string>> $classToVisualParent) : mixed
Parameters
$classToVisualParent : array<string|int, array<string|int, string>>

blockablesToHosts()

Create an expression => regular expression cache for all available URLs in available blockables.

public blockablesToHosts([bool $contains = true ][, array<string|int, AbstractBlockable$useBlockables = null ]) : mixed
Parameters
$contains : bool = true
$useBlockables : array<string|int, AbstractBlockable> = null

getBlockableById()

Get blockable by blocker ID.

public getBlockableById(int $id) : mixed
Parameters
$id : int

getBlockableRulesStartingWith()

Get blockable rules starting with a given string. This does only work for non-Selector-Syntax expressions.

public getBlockableRulesStartingWith(string $prefix[, bool $onlyExpressions = false ][, array<string|int, AbstractBlockable$blockables = null ]) : array<string|int, array<string|int, mixed>>

Example: avf_exclude_assets:avia_google_maps_api_script -> search by avf_exclude_assets: and it will return an array with [['expression' => 'avia_google_maps_api_script', 'blockable' => AbstractBlockable instance]].

Parameters
$prefix : string
$onlyExpressions : bool = false
$blockables : array<string|int, AbstractBlockable> = null
Return values
array<string|int, array<string|int, mixed>>

getInlineStyleDummyUrlPath()

Getter.

public getInlineStyleDummyUrlPath() : mixed
Tags
codeCoverageIgnore

getKeepAlwaysAttributes()

Getter.

public getKeepAlwaysAttributes() : mixed
Tags
codeCoverageIgnore

getKeepAlwaysAttributesIfClass()

Getter.

public getKeepAlwaysAttributesIfClass() : mixed
Tags
codeCoverageIgnore

getPluginsByClassName()

Getter.

public getPluginsByClassName(string $className) : mixed
Parameters
$className : string
Tags
codeCoverageIgnore

getReplaceAlwaysAttributes()

Getter.

public getReplaceAlwaysAttributes() : mixed
Tags
codeCoverageIgnore

getSkipInlineScriptVariableAssignments()

Getter.

public getSkipInlineScriptVariableAssignments() : mixed
Tags
codeCoverageIgnore

getVisualParentIfClass()

Getter.

public getVisualParentIfClass() : mixed
Tags
codeCoverageIgnore

isAllowMultipleBlockerResults()

Getter.

public isAllowMultipleBlockerResults() : mixed
Tags
codeCoverageIgnore

runInlineStyleModifyDocumentsCallback()

Run registered callbacks to not extract blocked CSS rules to a second document.

public runInlineStyleModifyDocumentsCallback(Document $document, Document $extractedDocument, StyleInlineMatcher $matcher, StyleInlineMatch $match) : mixed
Parameters
$document : Document
$extractedDocument : Document
$matcher : StyleInlineMatcher
$match : StyleInlineMatch

runInlineStyleShouldBeExtractedByCallback()

Run registered callbacks to not extract blocked CSS rules to a second document.

public runInlineStyleShouldBeExtractedByCallback(bool $extract, StyleInlineMatcher $matcher, StyleInlineMatch $match) : bool
Parameters
$extract : bool
$matcher : StyleInlineMatcher
$match : StyleInlineMatch
Return values
bool

runKeepAlwaysAttributesCallback()

Run registered keep-always-attributes callbacks.

public runKeepAlwaysAttributesCallback(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>

runSkipInlineScriptVariableAssignmentsCallback()

Run registered skip-inline-names callbacks.

public runSkipInlineScriptVariableAssignmentsCallback(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>

runVisualParentCallback()

Run registered check-result callbacks.

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

setAllowMultipleBlockerResults()

If you pass `true`, the generated `BlockedResult` will contain multiple results and will not break after the first found blockable to block.

public setAllowMultipleBlockerResults(bool $status) : mixed
Parameters
$status : bool
Tags
codeCoverageIgnore

setInlineStyleDummyUrlPath()

When blocking CSS inline styles, we replace URLs with dummy URLs and we cannot rely on data-uri's as we need to pass parameters, too.

public setInlineStyleDummyUrlPath(string $urlPath) : mixed

Default: https://assets.devowl.io/packages/devowl-wp/headless-content-blocker/

In the folder there need to exist the following two files: dummy.css, dummy.png.

Parameters
$urlPath : string

setup()

Setup the content blocker mechanism. You need to use this before you `modifyAny/modifyHtml` your content!

public setup() : mixed

init()

Add a callback which should throw an `Exception` when the content blocker is not setup.

protected init() : mixed

runAfterSetupCallback()

Run registered after-setup callbacks.

protected runAfterSetupCallback() : mixed

        
On this page

Search results