FIX ShortcodeParser#parse in < PHP 5.3.6 where saveHTML doesnt take arg

This commit is contained in:
Hamish Friedlander 2013-02-20 10:56:52 +13:00
parent cbef44b8d6
commit 76fdb2a2d6

View File

@ -481,6 +481,25 @@ class ShortcodeParser {
return $bases; return $bases;
} }
protected function saveHTML($doc) {
if (version_compare(PHP_VERSION, '5.3.6', '>=')){
$res = '';
foreach($doc->firstChild->childNodes as $child) $res .= $doc->saveHTML($child);
}
else {
$res = preg_replace(
array(
'/^(.*?)<html>/is',
'/<\/html>(.*?)$/is',
),
'',
$doc->saveHTML()
);
}
return $res;
}
/** /**
* Parse a string, and replace any registered shortcodes within it with the result of the mapped callback. * Parse a string, and replace any registered shortcodes within it with the result of the mapped callback.
* *
@ -511,9 +530,7 @@ class ShortcodeParser {
} }
} }
$res = ''; $doc = $bases->item(0)->ownerDocument;
$container = $bases->item(0)->parentNode;
$doc = $container->ownerDocument;
$xp = new DOMXPath($doc); $xp = new DOMXPath($doc);
@ -550,9 +567,7 @@ class ShortcodeParser {
$this->replaceMarkerWithContent($shortcode, $tag); $this->replaceMarkerWithContent($shortcode, $tag);
} }
foreach($container->childNodes as $child) $res .= $doc->saveHTML($child); return $this->saveHTML($doc);
return $res;
} }