mirror of
https://github.com/e107inc/e107.git
synced 2025-08-05 06:07:32 +02:00
Fixes #4291 Workaround for servers with very old versions of LibXML. eg. 2.7.6
This commit is contained in:
@@ -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.
|
||||||
@@ -5745,7 +5745,7 @@ return;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
$cleaned = $doc->saveHTML($doc->documentElement); // $doc->documentElement fixes utf-8/entities issue. @see http://stackoverflow.com/questions/8218230/php-domdocument-loadhtml-not-encoding-utf-8-correctly
|
$cleaned = $doc->saveHTML($doc->documentElement); // $doc->documentElement fixes utf-8/entities issue. @see http://stackoverflow.com/questions/8218230/php-domdocument-loadhtml-not-encoding-utf-8-correctly
|
||||||
// Workaround for https://bugs.php.net/bug.php?id=76285
|
// Workaround for https://bugs.php.net/bug.php?id=76285
|
||||||
// Part 2 of 2
|
// Part 2 of 2
|
||||||
$cleaned = str_replace("\n", "", $cleaned);
|
$cleaned = str_replace("\n", "", $cleaned);
|
||||||
$cleaned = str_replace("__E_PARSER_CLEAN_HTML_LINE_BREAK__", "\n", $cleaned);
|
$cleaned = str_replace("__E_PARSER_CLEAN_HTML_LINE_BREAK__", "\n", $cleaned);
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
@@ -439,6 +439,11 @@ while($row = $sql->fetch())
|
|||||||
'expected' => "<pre>/* {THEME_PREF: code=header_width&default=container} */</pre>",
|
'expected' => "<pre>/* {THEME_PREF: code=header_width&default=container} */</pre>",
|
||||||
),
|
),
|
||||||
|
|
||||||
|
30 => array(
|
||||||
|
'html' => "<hr />",
|
||||||
|
'expected' => "<hr>",
|
||||||
|
),
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach($tests as $k=>$var)
|
foreach($tests as $k=>$var)
|
||||||
|
Reference in New Issue
Block a user