PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.2.2
Kirki – Freeform Page Builder, Website Builder & Customizer v6.2.2
6.2.5 6.2.4 6.2.3 6.2.2 6.2.1 6.2.0 6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / vendor / enshrined / svg-sanitize / src / data / XPath.php
kirki / vendor / enshrined / svg-sanitize / src / data Last commit date
AllowedAttributes.php 3 months ago AllowedTags.php 3 months ago AttributeInterface.php 3 months ago TagInterface.php 3 months ago XPath.php 3 months ago
XPath.php
65 lines
1 <?php
2 namespace enshrined\svgSanitize\data;
3
4 class XPath extends \DOMXPath
5 {
6 const DEFAULT_NAMESPACE_PREFIX = 'svg';
7
8 /**
9 * @var string
10 */
11 protected $defaultNamespaceURI;
12
13 public function __construct(\DOMDocument $doc)
14 {
15 parent::__construct($doc);
16 $this->handleDefaultNamespace();
17 }
18
19 /**
20 * @param string $nodeName
21 * @return string
22 */
23 public function createNodeName($nodeName)
24 {
25 if (empty($this->defaultNamespaceURI)) {
26 return $nodeName;
27 }
28 return self::DEFAULT_NAMESPACE_PREFIX . ':' . $nodeName;
29 }
30
31 protected function handleDefaultNamespace()
32 {
33 $rootElements = $this->getRootElements();
34
35 if (count($rootElements) !== 1) {
36 throw new \LogicException(
37 sprintf('Got %d svg elements, expected exactly one', count($rootElements)),
38 1570870568
39 );
40 }
41 $this->defaultNamespaceURI = (string)$rootElements[0]->namespaceURI;
42
43 if ($this->defaultNamespaceURI !== '') {
44 $this->registerNamespace(self::DEFAULT_NAMESPACE_PREFIX, $this->defaultNamespaceURI);
45 }
46 }
47
48 /**
49 * @return \DOMElement[]
50 */
51 protected function getRootElements()
52 {
53 $rootElements = [];
54 $elements = $this->document->getElementsByTagName('svg');
55 /** @var \DOMElement $element */
56 foreach ($elements as $element) {
57 if ($element->parentNode !== $this->document) {
58 continue;
59 }
60 $rootElements[] = $element;
61 }
62 return $rootElements;
63 }
64 }
65