Skip to content

Commit 49ece35

Browse files
committed
Fixed issue with aditional body tags and DOMDocument Warning
1 parent d2ce78c commit 49ece35

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

Block/Post/AbstractPost.php

+14-4
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,22 @@ public function getShorContent()
103103

104104
if ($p = mb_strpos($content, $pageBraker)) {
105105
$content = mb_substr($content, 0, $p);
106+
try {
107+
libxml_use_internal_errors(true);
108+
$dom = new \DOMDocument();
109+
$dom->loadHTML('<?xml encoding="UTF-8">' . $content);
110+
$body = $dom->getElementsByTagName('body');
111+
if ( $body && $body->length > 0 ) {
112+
$body = $body->item(0);
113+
$_content = new \DOMDocument;
114+
foreach ($body->childNodes as $child){
115+
$_content->appendChild($_content->importNode($child, true));
116+
}
117+
$content = $_content->saveHTML();
118+
}
119+
} catch (\Exception $e) {}
106120
}
107121

108-
$dom = new \DOMDocument();
109-
$dom->loadHTML('<?xml encoding="UTF-8">' . $content);
110-
$content = $dom->saveHTML();
111-
112122
return $content;
113123
}
114124

Block/Widget/Recent.php

+17-7
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,29 @@ public function getCategory()
131131
*/
132132
public function getShorContent($post)
133133
{
134-
$content = $post->getContent();
134+
$content = $this->_filterProvider->getPageFilter()->filter(
135+
$post->getContent()
136+
);
135137
$pageBraker = '<!-- pagebreak -->';
136138

137139
if ($p = mb_strpos($content, $pageBraker)) {
138140
$content = mb_substr($content, 0, $p);
141+
try {
142+
libxml_use_internal_errors(true);
143+
$dom = new \DOMDocument();
144+
$dom->loadHTML('<?xml encoding="UTF-8">' . $content);
145+
$body = $dom->getElementsByTagName('body');
146+
if ( $body && $body->length > 0 ) {
147+
$body = $body->item(0);
148+
$_content = new \DOMDocument;
149+
foreach ($body->childNodes as $child){
150+
$_content->appendChild($_content->importNode($child, true));
151+
}
152+
$content = $_content->saveHTML();
153+
}
154+
} catch (\Exception $e) {}
139155
}
140156

141-
$content = $this->_filterProvider->getPageFilter()->filter($content);
142-
143-
$dom = new \DOMDocument();
144-
$dom->loadHTML('<?xml encoding="UTF-8">' . $content);
145-
$content = $dom->saveHTML();
146-
147157
return $content;
148158
}
149159
}

0 commit comments

Comments
 (0)