@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | $this->save = function($content = null) { |
38 | 38 | return $this->document->saveHtml($content); |
39 | 39 | }; |
40 | - $this->document->loadHtml('<' . '?xml encoding="UTF-8">' .$doc, LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED); |
|
40 | + $this->document->loadHtml('<'.'?xml encoding="UTF-8">'.$doc, LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED); |
|
41 | 41 | |
42 | 42 | if (strpos($doc, '<!') !== 0) { |
43 | 43 | $templateNode = $this->document->getElementsByTagName('template')[0]; |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | //Either return a whole DomDocument or return the output HTML |
89 | 89 | if ($document) return $this->document; |
90 | 90 | |
91 | - $output = ($this->document->doctype) ? ($this->save)($this->document->doctype) . "\n" : ''; |
|
91 | + $output = ($this->document->doctype) ? ($this->save)($this->document->doctype)."\n" : ''; |
|
92 | 92 | |
93 | 93 | if ($this->document->documentElement->tagName !== 'template') $output .= ($this->save)($this->document->documentElement); |
94 | 94 | else $output = $this->printDocument(); |
@@ -66,7 +66,9 @@ discard block |
||
66 | 66 | /** Loops through all assigned hooks, runs the Xpath query and calls the hook */ |
67 | 67 | private function processHooks() { |
68 | 68 | foreach ($this->hooks as list($query, $hook)) { |
69 | - foreach ($this->xpath->query($query) as $element) $hook->run($element); |
|
69 | + foreach ($this->xpath->query($query) as $element) { |
|
70 | + $hook->run($element); |
|
71 | + } |
|
70 | 72 | } |
71 | 73 | $this->hooks = []; |
72 | 74 | } |
@@ -74,7 +76,9 @@ discard block |
||
74 | 76 | /** Prints out the current DomDocument as HTML */ |
75 | 77 | private function printDocument() { |
76 | 78 | $output = ''; |
77 | - foreach ($this->document->documentElement->childNodes as $node) $output .= ($this->save)($node); |
|
79 | + foreach ($this->document->documentElement->childNodes as $node) { |
|
80 | + $output .= ($this->save)($node); |
|
81 | + } |
|
78 | 82 | return $output; |
79 | 83 | } |
80 | 84 | |
@@ -86,12 +90,17 @@ discard block |
||
86 | 90 | //Generate the document by taking only the childnodes of the template, ignoring the <template> and </template> tags |
87 | 91 | //TODO: Is there a faster way of doing this without string manipulation on the output or this loop through childnodes? |
88 | 92 | //Either return a whole DomDocument or return the output HTML |
89 | - if ($document) return $this->document; |
|
93 | + if ($document) { |
|
94 | + return $this->document; |
|
95 | + } |
|
90 | 96 | |
91 | 97 | $output = ($this->document->doctype) ? ($this->save)($this->document->doctype) . "\n" : ''; |
92 | 98 | |
93 | - if ($this->document->documentElement->tagName !== 'template') $output .= ($this->save)($this->document->documentElement); |
|
94 | - else $output = $this->printDocument(); |
|
99 | + if ($this->document->documentElement->tagName !== 'template') { |
|
100 | + $output .= ($this->save)($this->document->documentElement); |
|
101 | + } else { |
|
102 | + $output = $this->printDocument(); |
|
103 | + } |
|
95 | 104 | |
96 | 105 | //repair empty tags. Browsers break on <script /> and <div /> so can't avoid LIBXML_NOEMPTYTAG but they also break on <base></base> so repair them |
97 | 106 | $output = str_replace(['></img>', '></br>', '></meta>', '></base>', '></link>', '></hr>', '></input>'], ' />', $output); |