1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-02 12:48:26 +02:00

Fix for shortcodes within <code> and <pre> tags.

This commit is contained in:
Cameron
2016-03-01 13:29:50 -08:00
parent 168aa846f1
commit 13d8254674

View File

@@ -529,7 +529,6 @@ class e_parse extends e_parser
$data = str_replace(array('%7B','%7D'),array('{','}'),$data); // fix for {e_XXX} paths.
// $data = urldecode($data); //XXX Commented out : NO LONGER REQUIRED. symptom of cleaning the HTML - urlencodes src attributes containing { and } .eg. {e_BASE}
}
@@ -3012,6 +3011,7 @@ class e_parser
protected $removedList = array();
protected $nodesToDelete = array();
protected $nodesToConvert = array();
protected $nodesToDisableSC = array();
protected $pathList = array();
protected $allowedAttributes = array(
'default' => array('id', 'style', 'class'),
@@ -3939,6 +3939,9 @@ TMPL;
echo "</div>";
echo "<h3>DB -> bbarea</h3>";
echo e107::getForm()->bbarea('name',$tp->toForm($dbText));
}
echo "<h3>toDB() &gg; toHtml()</h3>";
@@ -3971,6 +3974,9 @@ TMPL;
echo "<h3>Nodes to Convert</h3>";
print_a($this->nodesToConvert);
echo "<h3>Nodes to Disable SC</h3>";
print_a($this->nodesToDisableSC);
}
similar_text($text, html_entity_decode( $toForm, ENT_COMPAT, 'UTF-8'),$perc);
@@ -4182,9 +4188,7 @@ return;
// echo "<br />Path = ".$path;
// $tag = strval(basename($path));
$tag = preg_replace('/([a-z0-9\[\]\/]*)?\/([\w]*)(\[(\d)*\])?$/i', "$2", $path);
if(!in_array($tag, $this->allowedTags))
{
if(strpos($path,'/code/') !== false || strpos($path,'/pre/') !== false) // treat as html.
{
$this->pathList[] = $path;
@@ -4192,6 +4196,16 @@ return;
continue;
}
if(substr($path,-4) == '/pre' || substr($path,-5) == '/code')
{
$this->pathList[] = $path;
$this->nodesToDisableSC[] = $node;
}
$tag = preg_replace('/([a-z0-9\[\]\/]*)?\/([\w]*)(\[(\d)*\])?$/i', "$2", $path);
if(!in_array($tag, $this->allowedTags))
{
$this->removedList['tags'][] = $tag;
$this->nodesToDelete[] = $node;
continue;
@@ -4249,6 +4263,19 @@ return;
$node->parentNode->removeChild($node);
}
// Disable Shortcodes in pre/code
foreach($this->nodesToDisableSC as $node)
{
// $value = $node->C14N();
$value = $node->nodeValue;
// $value = str_replace("&#xD;","",$value);
$value = str_replace('{','{{{',$value); // temporarily change {e_XXX} to {{{e_XXX}}}
$value = str_replace('}','}}}',$value); // temporarily change {e_XXX} to {{{e_XXX}}}
$node->nodeValue = $value;
}
// Convert <code> and <pre> Tags to Htmlentities.
foreach($this->nodesToConvert as $node)
{
@@ -4274,9 +4301,13 @@ return;
$node->nodeValue = $value;
}
$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 = str_replace ('@nbsp;', '&nbsp;', $cleaned); // prevent replacement of &nbsp; with spaces. - convert back.
$cleaned = str_replace('@nbsp;', '&nbsp;', $cleaned); // prevent replacement of &nbsp; with spaces. - convert back.
$cleaned = str_replace('{{{','&#123;', $cleaned); // convert shortcode temporary triple-curly braces back to entities.
$cleaned = str_replace('}}}','&#125;', $cleaned); // convert shortcode temporary triple-curly braces back to entities.
$cleaned = str_replace(array('<body>','</body>','<html>','</html>','<!DOCTYPE html>','<meta charset="UTF-8">','<?xml version="1.0" encoding="utf-8"?>'),'',$cleaned); // filter out tags.