SharedAtLeastOne
extends AbstractPlugin
in package
This plugin registers a prefix for rules (not applied to selector syntax rules!) that allows to merge required IDs across all registered blockers and uses the "at least one" logic to block the content (uses `consent-condition="or"`). Example:
Hubspot uses an initiator script to load multiple services dynamically (Hubspot Chat, Hubspot Forms, etc.):
<script src="https://js.hs-scripts.com/111111.js?integration=WordPress&ver=11.3.21" defer></script>
This script uses document.createElement("script") to load the services and adds them to the DOM. For every content blocker we
block the respective dynamically loaded script with client-side: rules. But we also need to make sure that the
initiator script is loaded as soon as one of the services is requested and should be loaded:
Hubspot Chat:
- Rule #1
shared_at_least_one:*.hs-scripts.com* - Rule #2
client-side:*hubspot.com/livechat-public* - Connected to service "Hubspot Chat"
Hubspot Forms:
- Rule #1
shared_at_least_one:*.hs-scripts.com* - Rule #2
client-side:*.hsforms.net/forms/* - Connected to service "Hubspot Forms"
Without this plugin: The first matching blocker "wins" the race and uses the blockables' required IDs without processing
the other blockable rules. In this example, the <script is associated to the service "Hubspot Chat" only. Therefore, when accepting
the consent for "Hubspot Forms" but not the consent for "Hubspot Chat", the Hubspot Forms service will not be loaded as the
<script is still blocked. Technically: <script consent-required="hubspot-chat" ....
With this plugin: All blockers will merge their required IDs and use the "at least one" logic to block the content.
In this example, the <script is associated to both services "Hubspot Chat" and "Hubspot Forms". Therefore, when accepting
the consent for "Hubspot Forms" but not the consent for "Hubspot Chat", the Hubspot Forms service will be loaded as the
<script is not blocked. Technically: <script consent-required="hubspot-chat,hubspot-forms" consent-condition="or" ....
Tags
Table of Contents
Constants
- PREFIX = 'shared_at_least_one:'
Properties
- $currentlyRunning : mixed
- $headlessContentBlocker : mixed
Methods
- __construct() : mixed
- C'tor.
- afterSetup() : mixed
- The content blocker got setup completely.
- beforeMatch() : mixed
- Called before a match got found.
- beforeSetBlockedInResult() : bool
- Allows to add an additional check before a blockable and expression gets added to a `BlockedResult`.
- blockableStringExpression() : string
- Allows to modify the passed string expression to a blockable.
- blockedMatch() : mixed
- Called after a match got blocked.
- checkResult() : BlockedResult
- Called after a match got found and the matcher decided, if it should be blocked or not.
- getHeadlessContentBlocker() : mixed
- Getter.
- init() : mixed
- Initialize your plugin add e.g. new visual parent definitions.
- 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.
- iterateBlockablesInString() : mixed
- See `AbstractPlugin`.
- keepAlwaysAttributes() : array<string|int, string>
- Keep attributes for a specific match.
- modifyBlockables() : array<string|int, AbstractBlockable>
- Modify the blockables array before it gets registered.
- 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`.
- 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.
Constants
PREFIX
public
mixed
PREFIX
= 'shared_at_least_one:'
Properties
$currentlyRunning
private
mixed
$currentlyRunning
= false
$headlessContentBlocker
private
mixed
$headlessContentBlocker
Methods
__construct()
C'tor.
public
final __construct(HeadlessContentBlocker $headlessContentBlocker) : mixed
Parameters
- $headlessContentBlocker : HeadlessContentBlocker
afterSetup()
The content blocker got setup completely.
public
afterSetup() : mixed
Tags
beforeMatch()
Called before a match got found.
public
beforeMatch(AbstractMatcher $matcher, AbstractMatch $match) : mixed
Parameters
- $matcher : AbstractMatcher
- $match : AbstractMatch
Tags
beforeSetBlockedInResult()
Allows to add an additional check before a blockable and expression gets added to a `BlockedResult`.
public
beforeSetBlockedInResult(BlockedResult $result, AbstractBlockable $blockable, string $expression, AbstractMatcher $matcher) : bool
Parameters
- $result : BlockedResult
- $blockable : AbstractBlockable
- $expression : string
- $matcher : AbstractMatcher
Tags
Return values
boolblockableStringExpression()
Allows to modify the passed string expression to a blockable.
public
blockableStringExpression(string $expression, AbstractBlockable $blockable) : string
Parameters
- $expression : string
- $blockable : AbstractBlockable
Tags
Return values
stringblockedMatch()
Called after a match got blocked.
public
blockedMatch(BlockedResult $result, AbstractMatcher $matcher, AbstractMatch $match) : mixed
Parameters
- $result : BlockedResult
- $matcher : AbstractMatcher
- $match : AbstractMatch
Tags
checkResult()
Called after a match got found and the matcher decided, if it should be blocked or not.
public
checkResult(BlockedResult $result, AbstractMatcher $matcher, AbstractMatch $match) : BlockedResult
Parameters
- $result : BlockedResult
- $matcher : AbstractMatcher
- $match : AbstractMatch
Tags
Return values
BlockedResultgetHeadlessContentBlocker()
Getter.
public
final getHeadlessContentBlocker() : mixed
init()
Initialize your plugin add e.g. new visual parent definitions.
public
init() : mixed
inlineStyleBlockRule()
Decide if a URL in a CSS rule should be blocked.
public
inlineStyleBlockRule(BlockedResult $result, string $url, StyleInlineMatcher|StyleInlineAttributeMatcher $matcher, StyleInlineMatch|StyleInlineAttributeMatch $match) : bool
Parameters
- $result : BlockedResult
- $url : string
- $matcher : StyleInlineMatcher|StyleInlineAttributeMatcher
- $match : StyleInlineMatch|StyleInlineAttributeMatch
Tags
Return values
boolinlineStyleModifyDocuments()
Allows to modify blocked CSS documents.
public
inlineStyleModifyDocuments(Document $document, Document $extractedDocument, StyleInlineMatcher|StyleInlineAttributeMatcher $matcher, StyleInlineMatch|StyleInlineAttributeMatch $match) : bool
Parameters
- $document : Document
- $extractedDocument : Document
- $matcher : StyleInlineMatcher|StyleInlineAttributeMatcher
- $match : StyleInlineMatch|StyleInlineAttributeMatch
Tags
Return values
boolinlineStyleShouldBeExtracted()
Do not extract blocked rules of a CSS inline script to a second document.
public
inlineStyleShouldBeExtracted(bool $extract, StyleInlineMatcher|StyleInlineAttributeMatcher $matcher, StyleInlineMatch|StyleInlineAttributeMatch $match) : bool
Parameters
- $extract : bool
- $matcher : StyleInlineMatcher|StyleInlineAttributeMatcher
- $match : StyleInlineMatch|StyleInlineAttributeMatch
Tags
Return values
booliterateBlockablesInString()
See `AbstractPlugin`.
public
iterateBlockablesInString(AbstractMatcher $matcher, BlockedResult $result, string $string, bool $useContainsRegularExpression, bool $multilineRegexp, array<string|int, string> $useRegularExpressionFromMap, array<string|int, AbstractBlockable> $useBlockables, bool $allowMultiple) : mixed
Parameters
- $matcher : AbstractMatcher
- $result : BlockedResult
- $string : string
- $useContainsRegularExpression : bool
- $multilineRegexp : bool
- $useRegularExpressionFromMap : array<string|int, string>
- $useBlockables : array<string|int, AbstractBlockable>
- $allowMultiple : bool
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
Tags
Return values
array<string|int, string>modifyBlockables()
Modify the blockables array before it gets registered.
public
modifyBlockables(array<string|int, AbstractBlockable> $blockables) : array<string|int, AbstractBlockable>
Parameters
- $blockables : array<string|int, AbstractBlockable>
Tags
Return values
array<string|int, AbstractBlockable>modifyHtmlAfterProcessing()
Allows to modify the HTML after the content blocker has done its job.
public
modifyHtmlAfterProcessing(string $html) : mixed
Parameters
- $html : string
Tags
notBlockedMatch()
Called after a match got not blocked. Opposite of `blockedMatch`.
public
notBlockedMatch(BlockedResult $result, AbstractMatcher $matcher, AbstractMatch $match) : mixed
Parameters
- $result : BlockedResult
- $matcher : AbstractMatcher
- $match : AbstractMatch
Tags
setup()
Before the content blocker gets setup.
public
setup() : mixed
Tags
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
Tags
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