Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/accelera.../includes/vendor/tool/Dom
File: Element.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace AmpProject\Dom;
[2] Fix | Delete
[3] Fix | Delete
use AmpProject\Attribute;
[4] Fix | Delete
use AmpProject\Exception\MaxCssByteCountExceeded;
[5] Fix | Delete
use AmpProject\Optimizer\CssRule;
[6] Fix | Delete
use DOMAttr;
[7] Fix | Delete
use DOMElement;
[8] Fix | Delete
use DOMException;
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* Abstract away some convenience logic for handling DOMElement objects.
[12] Fix | Delete
*
[13] Fix | Delete
* @property Document $ownerDocument The ownerDocument for these elements should always be a Dom\Document.
[14] Fix | Delete
* @property int $inlineStyleByteCount Number of bytes that are consumed by the inline style attribute.
[15] Fix | Delete
*
[16] Fix | Delete
* @package ampproject/amp-toolbox
[17] Fix | Delete
*/
[18] Fix | Delete
final class Element extends DOMElement
[19] Fix | Delete
{
[20] Fix | Delete
[21] Fix | Delete
/**
[22] Fix | Delete
* Regular expression pattern to match events and actions within an 'on' attribute.
[23] Fix | Delete
*
[24] Fix | Delete
* @var string
[25] Fix | Delete
*/
[26] Fix | Delete
const AMP_EVENT_ACTIONS_REGEX_PATTERN = '/((?<event>[^:;]+):(?<actions>(?:[^;,\(]+(?:\([^\)]+\))?,?)+))+?/';
[27] Fix | Delete
[28] Fix | Delete
/**
[29] Fix | Delete
* Regular expression pattern to match individual actions within an event.
[30] Fix | Delete
*
[31] Fix | Delete
* @var string
[32] Fix | Delete
*/
[33] Fix | Delete
const AMP_ACTION_REGEX_PATTERN = '/(?<action>[^(),\s]+(?:\([^\)]+\))?)+/';
[34] Fix | Delete
[35] Fix | Delete
/**
[36] Fix | Delete
* Error message to use when the __get() is triggered for an unknown property.
[37] Fix | Delete
*
[38] Fix | Delete
* @var string
[39] Fix | Delete
*/
[40] Fix | Delete
const PROPERTY_GETTER_ERROR_MESSAGE = 'Undefined property: AmpProject\\Dom\\Element::';
[41] Fix | Delete
[42] Fix | Delete
/**
[43] Fix | Delete
* Add CSS styles to the element as an inline style attribute.
[44] Fix | Delete
*
[45] Fix | Delete
* @param string $style CSS style(s) to add to the inline style attribute.
[46] Fix | Delete
* @return DOMAttr|false The new or modified DOMAttr or false if an error occurred.
[47] Fix | Delete
* @throws MaxCssByteCountExceeded If the allowed max byte count is exceeded.
[48] Fix | Delete
*/
[49] Fix | Delete
public function addInlineStyle($style)
[50] Fix | Delete
{
[51] Fix | Delete
$style = trim($style, CssRule::CSS_TRIM_CHARACTERS);
[52] Fix | Delete
[53] Fix | Delete
$existingStyle = (string)trim($this->getAttribute(Attribute::STYLE));
[54] Fix | Delete
if (!empty($existingStyle)) {
[55] Fix | Delete
$existingStyle = rtrim($existingStyle, ';') . ';';
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
$newStyle = $existingStyle . $style;
[59] Fix | Delete
[60] Fix | Delete
return $this->setAttribute(Attribute::STYLE, $newStyle);
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
/**
[64] Fix | Delete
* Sets or modifies an attribute.
[65] Fix | Delete
*
[66] Fix | Delete
* @link https://php.net/manual/en/domelement.setattribute.php
[67] Fix | Delete
* @param string $name The name of the attribute.
[68] Fix | Delete
* @param string $value The value of the attribute.
[69] Fix | Delete
* @return DOMAttr|false The new or modified DOMAttr or false if an error occurred.
[70] Fix | Delete
* @throws MaxCssByteCountExceeded If the allowed max byte count is exceeded.
[71] Fix | Delete
*/
[72] Fix | Delete
public function setAttribute($name, $value)
[73] Fix | Delete
{
[74] Fix | Delete
if (
[75] Fix | Delete
$name === Attribute::STYLE
[76] Fix | Delete
&& $this->ownerDocument->isCssMaxByteCountEnforced()
[77] Fix | Delete
) {
[78] Fix | Delete
$newByteCount = strlen($value);
[79] Fix | Delete
[80] Fix | Delete
if ($this->ownerDocument->getRemainingCustomCssSpace() < ($newByteCount - $this->inlineStyleByteCount)) {
[81] Fix | Delete
throw MaxCssByteCountExceeded::forInlineStyle($this, $value);
[82] Fix | Delete
}
[83] Fix | Delete
[84] Fix | Delete
$this->ownerDocument->addInlineStyleByteCount($newByteCount - $this->inlineStyleByteCount);
[85] Fix | Delete
[86] Fix | Delete
$this->inlineStyleByteCount = $newByteCount;
[87] Fix | Delete
return parent::setAttribute(Attribute::STYLE, $value);
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
return parent::setAttribute($name, $value);
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
/**
[94] Fix | Delete
* Adds a boolean attribute without value.
[95] Fix | Delete
*
[96] Fix | Delete
* @param string $name The name of the attribute.
[97] Fix | Delete
* @return DOMAttr|false The new or modified DOMAttr or false if an error occurred.
[98] Fix | Delete
* @throws MaxCssByteCountExceeded If the allowed max byte count is exceeded.
[99] Fix | Delete
*/
[100] Fix | Delete
public function addBooleanAttribute($name)
[101] Fix | Delete
{
[102] Fix | Delete
$attribute = new DOMAttr($name);
[103] Fix | Delete
$result = $this->setAttributeNode($attribute);
[104] Fix | Delete
[105] Fix | Delete
if (!$result instanceof DOMAttr) {
[106] Fix | Delete
return false;
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
return $result;
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
/**
[113] Fix | Delete
* Copy one or more attributes from this element to another element.
[114] Fix | Delete
*
[115] Fix | Delete
* @param array|string $attributes Attribute name or array of attribute names to copy.
[116] Fix | Delete
* @param Element $target Target Dom\Element to copy the attributes to.
[117] Fix | Delete
* @param string $defaultSeparator Default separator to use for multiple values if the attribute is not known.
[118] Fix | Delete
*/
[119] Fix | Delete
public function copyAttributes($attributes, Element $target, $defaultSeparator = ',')
[120] Fix | Delete
{
[121] Fix | Delete
foreach ((array) $attributes as $attribute) {
[122] Fix | Delete
if ($this->hasAttribute($attribute)) {
[123] Fix | Delete
$values = $this->getAttribute($attribute);
[124] Fix | Delete
if ($target->hasAttribute($attribute)) {
[125] Fix | Delete
switch ($attribute) {
[126] Fix | Delete
case Attribute::ON:
[127] Fix | Delete
$values = self::mergeAmpActions($target->getAttribute($attribute), $values);
[128] Fix | Delete
break;
[129] Fix | Delete
case Attribute::CLASS_:
[130] Fix | Delete
$values = $target->getAttribute($attribute) . ' ' . $values;
[131] Fix | Delete
break;
[132] Fix | Delete
default:
[133] Fix | Delete
$values = $target->getAttribute($attribute) . $defaultSeparator . $values;
[134] Fix | Delete
}
[135] Fix | Delete
}
[136] Fix | Delete
$target->setAttribute($attribute, $values);
[137] Fix | Delete
}
[138] Fix | Delete
}
[139] Fix | Delete
}
[140] Fix | Delete
[141] Fix | Delete
/**
[142] Fix | Delete
* Register an AMP action to an event.
[143] Fix | Delete
*
[144] Fix | Delete
* If the element already contains one or more events or actions, the method
[145] Fix | Delete
* will assemble them in a smart way.
[146] Fix | Delete
*
[147] Fix | Delete
* @param string $event Event to trigger the action on.
[148] Fix | Delete
* @param string $action Action to add.
[149] Fix | Delete
*/
[150] Fix | Delete
public function addAmpAction($event, $action)
[151] Fix | Delete
{
[152] Fix | Delete
$eventActionString = "{$event}:{$action}";
[153] Fix | Delete
[154] Fix | Delete
if (! $this->hasAttribute(Attribute::ON)) {
[155] Fix | Delete
// There's no "on" attribute yet, so just add it and be done.
[156] Fix | Delete
$this->setAttribute(Attribute::ON, $eventActionString);
[157] Fix | Delete
return;
[158] Fix | Delete
}
[159] Fix | Delete
[160] Fix | Delete
$this->setAttribute(
[161] Fix | Delete
Attribute::ON,
[162] Fix | Delete
self::mergeAmpActions(
[163] Fix | Delete
$this->getAttribute(Attribute::ON),
[164] Fix | Delete
$eventActionString
[165] Fix | Delete
)
[166] Fix | Delete
);
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
/**
[170] Fix | Delete
* Merge two sets of AMP events & actions.
[171] Fix | Delete
*
[172] Fix | Delete
* @param string $first First event/action string.
[173] Fix | Delete
* @param string $second First event/action string.
[174] Fix | Delete
* @return string Merged event/action string.
[175] Fix | Delete
*/
[176] Fix | Delete
public static function mergeAmpActions($first, $second)
[177] Fix | Delete
{
[178] Fix | Delete
$events = [];
[179] Fix | Delete
foreach ([$first, $second] as $eventActionString) {
[180] Fix | Delete
$matches = [];
[181] Fix | Delete
$results = preg_match_all(self::AMP_EVENT_ACTIONS_REGEX_PATTERN, $eventActionString, $matches);
[182] Fix | Delete
[183] Fix | Delete
if (! $results || ! isset($matches['event'])) {
[184] Fix | Delete
continue;
[185] Fix | Delete
}
[186] Fix | Delete
[187] Fix | Delete
foreach ($matches['event'] as $index => $event) {
[188] Fix | Delete
$events[$event][] = $matches['actions'][ $index ];
[189] Fix | Delete
}
[190] Fix | Delete
}
[191] Fix | Delete
[192] Fix | Delete
$valueStrings = [];
[193] Fix | Delete
foreach ($events as $event => $actionStringsArray) {
[194] Fix | Delete
$actionsArray = [];
[195] Fix | Delete
array_walk(
[196] Fix | Delete
$actionStringsArray,
[197] Fix | Delete
static function ($actions) use (&$actionsArray) {
[198] Fix | Delete
$matches = [];
[199] Fix | Delete
$results = preg_match_all(self::AMP_ACTION_REGEX_PATTERN, $actions, $matches);
[200] Fix | Delete
[201] Fix | Delete
if (! $results || ! isset($matches['action'])) {
[202] Fix | Delete
$actionsArray[] = $actions;
[203] Fix | Delete
return;
[204] Fix | Delete
}
[205] Fix | Delete
[206] Fix | Delete
$actionsArray = array_merge($actionsArray, $matches['action']);
[207] Fix | Delete
}
[208] Fix | Delete
);
[209] Fix | Delete
[210] Fix | Delete
$actions = implode(',', array_unique(array_filter($actionsArray)));
[211] Fix | Delete
$valueStrings[] = "{$event}:{$actions}";
[212] Fix | Delete
}
[213] Fix | Delete
[214] Fix | Delete
return implode(';', $valueStrings);
[215] Fix | Delete
}
[216] Fix | Delete
[217] Fix | Delete
/**
[218] Fix | Delete
* Extract this element's HTML attributes and return as an associative array.
[219] Fix | Delete
*
[220] Fix | Delete
* @return string[] The attributes for the passed node, or an empty array if it has no attributes.
[221] Fix | Delete
*/
[222] Fix | Delete
public function getAttributesAsAssocArray()
[223] Fix | Delete
{
[224] Fix | Delete
$attributes = [];
[225] Fix | Delete
if (! $this->hasAttributes()) {
[226] Fix | Delete
return $attributes;
[227] Fix | Delete
}
[228] Fix | Delete
[229] Fix | Delete
foreach ($this->attributes as $attribute) {
[230] Fix | Delete
$attributes[ $attribute->nodeName ] = $attribute->nodeValue;
[231] Fix | Delete
}
[232] Fix | Delete
[233] Fix | Delete
return $attributes;
[234] Fix | Delete
}
[235] Fix | Delete
[236] Fix | Delete
/**
[237] Fix | Delete
* Add one or more HTML element attributes to this element.
[238] Fix | Delete
*
[239] Fix | Delete
* @param string[] $attributes One or more attributes for the node's HTML element.
[240] Fix | Delete
*/
[241] Fix | Delete
public function setAttributes($attributes)
[242] Fix | Delete
{
[243] Fix | Delete
foreach ($attributes as $name => $value) {
[244] Fix | Delete
try {
[245] Fix | Delete
$this->setAttribute($name, $value);
[246] Fix | Delete
} catch (DOMException $e) {
[247] Fix | Delete
/*
[248] Fix | Delete
* Catch a "Invalid Character Error" when libxml is able to parse attributes with invalid characters,
[249] Fix | Delete
* but it throws error when attempting to set them via DOM methods. For example, '...this' can be parsed
[250] Fix | Delete
* as an attribute but it will throw an exception when attempting to setAttribute().
[251] Fix | Delete
*/
[252] Fix | Delete
continue;
[253] Fix | Delete
}
[254] Fix | Delete
}
[255] Fix | Delete
}
[256] Fix | Delete
[257] Fix | Delete
/**
[258] Fix | Delete
* Magic getter to implement lazily-created, cached properties for the element.
[259] Fix | Delete
*
[260] Fix | Delete
* @param string $name Name of the property to get.
[261] Fix | Delete
* @return mixed Value of the property, or null if unknown property was requested.
[262] Fix | Delete
*/
[263] Fix | Delete
public function __get($name)
[264] Fix | Delete
{
[265] Fix | Delete
switch ($name) {
[266] Fix | Delete
case 'inlineStyleByteCount':
[267] Fix | Delete
if (!isset($this->inlineStyleByteCount)) {
[268] Fix | Delete
$this->inlineStyleByteCount = strlen((string)$this->getAttribute(Attribute::STYLE));
[269] Fix | Delete
}
[270] Fix | Delete
[271] Fix | Delete
return $this->inlineStyleByteCount;
[272] Fix | Delete
}
[273] Fix | Delete
[274] Fix | Delete
// Mimic regular PHP behavior for missing notices.
[275] Fix | Delete
trigger_error(self::PROPERTY_GETTER_ERROR_MESSAGE . $name, E_USER_NOTICE);
[276] Fix | Delete
[277] Fix | Delete
return null;
[278] Fix | Delete
}
[279] Fix | Delete
}
[280] Fix | Delete
[281] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function