Skip to content

Commit

Permalink
FIX ShortcodeParser#parse in < PHP 5.3.6 where saveHTML doesnt take arg
Browse files Browse the repository at this point in the history
  • Loading branch information
Hamish Friedlander committed Feb 19, 2013
1 parent cbef44b commit 76fdb2a
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions parsers/ShortcodeParser.php
Expand Up @@ -481,6 +481,25 @@ function($no, $str){
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.
*
Expand Down Expand Up @@ -511,9 +530,7 @@ public function parse($content) {
}
}

$res = '';
$container = $bases->item(0)->parentNode;
$doc = $container->ownerDocument;
$doc = $bases->item(0)->ownerDocument;

$xp = new DOMXPath($doc);

Expand Down Expand Up @@ -550,9 +567,7 @@ public function parse($content) {
$this->replaceMarkerWithContent($shortcode, $tag);
}

foreach($container->childNodes as $child) $res .= $doc->saveHTML($child);

return $res;
return $this->saveHTML($doc);
}


Expand Down

0 comments on commit 76fdb2a

Please sign in to comment.