@@ -55,7 +55,7 @@ |
||
| 55 | 55 | if ($document) return $this->document; |
| 56 | 56 | |
| 57 | 57 | |
| 58 | - $output = ($this->document->doctype) ? $this->document->saveXml($this->document->doctype) . "\n" : ''; |
|
| 58 | + $output = ($this->document->doctype) ? $this->document->saveXml($this->document->doctype)."\n" : ''; |
|
| 59 | 59 | |
| 60 | 60 | if ($this->document->documentElement->tagName !== 'template') $output .= $this->document->saveXml($this->document->documentElement, LIBXML_NOEMPTYTAG); |
| 61 | 61 | else $output = $this->printDocument($this->document); |
@@ -33,14 +33,18 @@ discard block |
||
| 33 | 33 | /** Loops through all assigned hooks, runs the Xpath query and calls the hook */ |
| 34 | 34 | private function processHooks() { |
| 35 | 35 | foreach ($this->hooks as list($query, $hook)) { |
| 36 | - foreach ($this->xpath->query($query) as $element) $hook->run($element); |
|
| 36 | + foreach ($this->xpath->query($query) as $element) { |
|
| 37 | + $hook->run($element); |
|
| 38 | + } |
|
| 37 | 39 | } |
| 38 | 40 | } |
| 39 | 41 | |
| 40 | 42 | /** Prints out the current DomDocument as HTML */ |
| 41 | 43 | private function printDocument(\DomDocument $doc) { |
| 42 | 44 | $output = ''; |
| 43 | - foreach ($doc->documentElement->childNodes as $node) $output .= $doc->saveXML($node, LIBXML_NOEMPTYTAG); |
|
| 45 | + foreach ($doc->documentElement->childNodes as $node) { |
|
| 46 | + $output .= $doc->saveXML($node, LIBXML_NOEMPTYTAG); |
|
| 47 | + } |
|
| 44 | 48 | return $output; |
| 45 | 49 | } |
| 46 | 50 | |
@@ -52,13 +56,18 @@ discard block |
||
| 52 | 56 | //Generate the document by taking only the childnodes of the template, ignoring the <template> and </template> tags |
| 53 | 57 | //TODO: Is there a faster way of doing this without string manipulation on the output or this loop through childnodes? |
| 54 | 58 | //Either return a whole DomDocument or return the output HTML |
| 55 | - if ($document) return $this->document; |
|
| 59 | + if ($document) { |
|
| 60 | + return $this->document; |
|
| 61 | + } |
|
| 56 | 62 | |
| 57 | 63 | |
| 58 | 64 | $output = ($this->document->doctype) ? $this->document->saveXml($this->document->doctype) . "\n" : ''; |
| 59 | 65 | |
| 60 | - if ($this->document->documentElement->tagName !== 'template') $output .= $this->document->saveXml($this->document->documentElement, LIBXML_NOEMPTYTAG); |
|
| 61 | - else $output = $this->printDocument($this->document); |
|
| 66 | + if ($this->document->documentElement->tagName !== 'template') { |
|
| 67 | + $output .= $this->document->saveXml($this->document->documentElement, LIBXML_NOEMPTYTAG); |
|
| 68 | + } else { |
|
| 69 | + $output = $this->printDocument($this->document); |
|
| 70 | + } |
|
| 62 | 71 | |
| 63 | 72 | //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 |
| 64 | 73 | $output = str_replace(['></img>', '></br>', '></meta>', '></base>', '></link>', '></hr>', '></input>'], ' />', $output); |