| 1 |
<?php |
| 2 |
|
| 3 |
namespace WindPressDeps\enshrined\svgSanitize; |
| 4 |
|
| 5 |
class Helper |
| 6 |
{ |
| 7 |
/** |
| 8 |
* @param \DOMElement $element |
| 9 |
* @return string|null |
| 10 |
*/ |
| 11 |
public static function getElementHref(\DOMElement $element) |
| 12 |
{ |
| 13 |
if ($element->hasAttribute('href')) { |
| 14 |
return $element->getAttribute('href'); |
| 15 |
} |
| 16 |
if ($element->hasAttributeNS('http://www.w3.org/1999/xlink', 'href')) { |
| 17 |
return $element->getAttributeNS('http://www.w3.org/1999/xlink', 'href'); |
| 18 |
} |
| 19 |
return null; |
| 20 |
} |
| 21 |
/** |
| 22 |
* @param string $href |
| 23 |
* @return string|null |
| 24 |
*/ |
| 25 |
public static function extractIdReferenceFromHref($href) |
| 26 |
{ |
| 27 |
if (!is_string($href) || strpos($href, '#') !== 0) { |
| 28 |
return null; |
| 29 |
} |
| 30 |
return substr($href, 1); |
| 31 |
} |
| 32 |
/** |
| 33 |
* @param \DOMElement $needle |
| 34 |
* @param \DOMElement $haystack |
| 35 |
* @return bool |
| 36 |
*/ |
| 37 |
public static function isElementContainedIn(\DOMElement $needle, \DOMElement $haystack) |
| 38 |
{ |
| 39 |
if ($needle === $haystack) { |
| 40 |
return \true; |
| 41 |
} |
| 42 |
foreach ($haystack->childNodes as $childNode) { |
| 43 |
if (!$childNode instanceof \DOMElement) { |
| 44 |
continue; |
| 45 |
} |
| 46 |
if (self::isElementContainedIn($needle, $childNode)) { |
| 47 |
return \true; |
| 48 |
} |
| 49 |
} |
| 50 |
return \false; |
| 51 |
} |
| 52 |
} |
| 53 |
|