1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-04 21:57:51 +02:00

Fixes #4291 Workaround for servers with very old versions of LibXML. eg. 2.7.6

This commit is contained in:
Cameron
2020-12-13 12:19:42 -08:00
parent 39691620ae
commit d5a1e77ca1
2 changed files with 17 additions and 12 deletions

View File

@@ -3937,7 +3937,6 @@ class e_parser
*/ */
function init() function init()
{ {
$this->domObj = new DOMDocument('1.0', 'utf-8');
if(defined('FONTAWESOME')) if(defined('FONTAWESOME'))
{ {
@@ -5547,12 +5546,7 @@ return;
$html = '<body>'.$html.'</body>'; $html = '<body>'.$html.'</body>';
} }
$this->domObj = $doc = new DOMDocument('1.0', 'utf-8');
if(!is_object($this->domObj))
{
$this->init();
}
if($this->scriptAccess === false) if($this->scriptAccess === false)
{ {
@@ -5564,16 +5558,22 @@ return;
$this->grantScriptAccess(); $this->grantScriptAccess();
} }
// Set it up for processing. // Set it up for processing.
$doc = $this->domObj;
libxml_use_internal_errors(true); libxml_use_internal_errors(true);
if(function_exists('mb_convert_encoding')) if(function_exists('mb_convert_encoding'))
{ {
$html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8"); $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8");
} }
@$doc->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); // $fragment = $doc->createDocumentFragment();
// $fragment->appendXML($html);
// $doc->appendChild($fragment);
// $doc->encoding = 'utf-8';
$opts = defined('LIBXML_HTML_NOIMPLIED') ? LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD : 0;
$doc->loadHTML($html, $opts);
$this->nodesToConvert = array(); // required. $this->nodesToConvert = array(); // required.
$this->nodesToDelete = array(); // required. $this->nodesToDelete = array(); // required.
@@ -5758,7 +5758,7 @@ return;
$cleaned = str_replace("__E_PARSER_CLEAN_HTML_CURLY_OPEN__","{", $cleaned); $cleaned = str_replace("__E_PARSER_CLEAN_HTML_CURLY_OPEN__","{", $cleaned);
$cleaned = str_replace("__E_PARSER_CLEAN_HTML_CURLY_CLOSED__","}", $cleaned); $cleaned = str_replace("__E_PARSER_CLEAN_HTML_CURLY_CLOSED__","}", $cleaned);
$cleaned = str_replace(array('<body>','</body>'),'', $cleaned); // filter out tags. $cleaned = str_replace(array('<body>','</body>','<html>','</html>'),'', $cleaned); // filter out tags.
return trim($cleaned); return trim($cleaned);
} }

View File

@@ -439,6 +439,11 @@ while(&#036;row = &#036;sql-&gt;fetch())
'expected' => "<pre>/* &#123;THEME_PREF: code=header_width&amp;default=container&#125; */</pre>", 'expected' => "<pre>/* &#123;THEME_PREF: code=header_width&amp;default=container&#125; */</pre>",
), ),
30 => array(
'html' => "<hr />",
'expected' => "<hr>",
),
); );
foreach($tests as $k=>$var) foreach($tests as $k=>$var)