PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 1.17
Independent Analytics – WordPress Analytics Plugin v1.17
2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / vendor / masterminds / html5 / src / HTML5 / Serializer / Traverser.php
independent-analytics / vendor / masterminds / html5 / src / HTML5 / Serializer Last commit date
HTML5Entities.php 3 years ago OutputRules.php 3 years ago RulesInterface.php 3 years ago Traverser.php 3 years ago
Traverser.php
124 lines
1 <?php
2
3 namespace IAWP\Masterminds\HTML5\Serializer;
4
5 /**
6 * Traverser for walking a DOM tree.
7 *
8 * This is a concrete traverser designed to convert a DOM tree into an
9 * HTML5 document. It is not intended to be a generic DOMTreeWalker
10 * implementation.
11 *
12 * @see http://www.w3.org/TR/2012/CR-html5-20121217/syntax.html#serializing-html-fragments
13 */
14 class Traverser
15 {
16 /**
17 * Namespaces that should be treated as "local" to HTML5.
18 */
19 protected static $local_ns = array('http://www.w3.org/1999/xhtml' => 'html', 'http://www.w3.org/1998/Math/MathML' => 'math', 'http://www.w3.org/2000/svg' => 'svg');
20 protected $dom;
21 protected $options;
22 protected $encode = \false;
23 protected $rules;
24 protected $out;
25 /**
26 * Create a traverser.
27 *
28 * @param \DOMNode|\DOMNodeList $dom The document or node to traverse.
29 * @param resource $out A stream that allows writing. The traverser will output into this
30 * stream.
31 * @param array $options An array of options for the traverser as key/value pairs. These include:
32 * - encode_entities: A bool to specify if full encding should happen for all named
33 * charachter references. Defaults to false which escapes &'<>".
34 * - output_rules: The path to the class handling the output rules.
35 */
36 public function __construct($dom, $out, RulesInterface $rules, $options = array())
37 {
38 $this->dom = $dom;
39 $this->out = $out;
40 $this->rules = $rules;
41 $this->options = $options;
42 $this->rules->setTraverser($this);
43 }
44 /**
45 * Tell the traverser to walk the DOM.
46 *
47 * @return resource $out Returns the output stream.
48 */
49 public function walk()
50 {
51 if ($this->dom instanceof \DOMDocument) {
52 $this->rules->document($this->dom);
53 } elseif ($this->dom instanceof \DOMDocumentFragment) {
54 // Document fragments are a special case. Only the children need to
55 // be serialized.
56 if ($this->dom->hasChildNodes()) {
57 $this->children($this->dom->childNodes);
58 }
59 } elseif ($this->dom instanceof \DOMNodeList) {
60 // If this is a NodeList of DOMDocuments this will not work.
61 $this->children($this->dom);
62 } else {
63 $this->node($this->dom);
64 }
65 return $this->out;
66 }
67 /**
68 * Process a node in the DOM.
69 *
70 * @param mixed $node A node implementing \DOMNode.
71 */
72 public function node($node)
73 {
74 // A listing of types is at http://php.net/manual/en/dom.constants.php
75 switch ($node->nodeType) {
76 case \XML_ELEMENT_NODE:
77 $this->rules->element($node);
78 break;
79 case \XML_TEXT_NODE:
80 $this->rules->text($node);
81 break;
82 case \XML_CDATA_SECTION_NODE:
83 $this->rules->cdata($node);
84 break;
85 case \XML_PI_NODE:
86 $this->rules->processorInstruction($node);
87 break;
88 case \XML_COMMENT_NODE:
89 $this->rules->comment($node);
90 break;
91 // Currently we don't support embedding DTDs.
92 default:
93 //print '<!-- Skipped -->';
94 break;
95 }
96 }
97 /**
98 * Walk through all the nodes on a node list.
99 *
100 * @param \DOMNodeList $nl A list of child elements to walk through.
101 */
102 public function children($nl)
103 {
104 foreach ($nl as $node) {
105 $this->node($node);
106 }
107 }
108 /**
109 * Is an element local?
110 *
111 * @param mixed $ele An element that implement \DOMNode.
112 *
113 * @return bool true if local and false otherwise.
114 */
115 public function isLocalElement($ele)
116 {
117 $uri = $ele->namespaceURI;
118 if (empty($uri)) {
119 return \false;
120 }
121 return isset(static::$local_ns[$uri]);
122 }
123 }
124