1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-06 14:46:56 +02:00

Additional fix for shortcodes in pre and code tags.

This commit is contained in:
Cameron
2016-03-01 17:50:53 -08:00
parent 13d8254674
commit 8b83eeb914
2 changed files with 41 additions and 19 deletions

View File

@@ -2204,7 +2204,8 @@ class e_admin_controller
session_write_close(); session_write_close();
// do redirect // do redirect
header('Location: '.$url); e107::redirect($url);
// header('Location: '.$url);
exit; exit;
} }

View File

@@ -3939,8 +3939,7 @@ TMPL;
echo "</div>"; echo "</div>";
echo "<h3>DB -> bbarea</h3>";
echo e107::getForm()->bbarea('name',$tp->toForm($dbText));
} }
@@ -3959,6 +3958,10 @@ TMPL;
echo $toFormRender; echo $toFormRender;
echo "<h3>toDB &gg; bbarea</h3>";
echo e107::getForm()->bbarea('name',$toForm);
if(!empty($advanced)) if(!empty($advanced))
{ {
@@ -4167,7 +4170,9 @@ return;
{ {
$html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8"); $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8");
} }
@$doc->loadHTML($html); @$doc->loadHTML($html);
// $doc->encoding = 'UTF-8'; // $doc->encoding = 'UTF-8';
// $doc->resolveExternals = true; // $doc->resolveExternals = true;
@@ -4189,18 +4194,14 @@ return;
// $tag = strval(basename($path)); // $tag = strval(basename($path));
if(strpos($path,'/code/') !== false || strpos($path,'/pre/') !== false) // treat as html. if(strpos($path,'/code') !== false || strpos($path,'/pre') !== false) // treat as html.
{ {
$this->pathList[] = $path; $this->pathList[] = $path;
$this->nodesToConvert[] = $node->parentNode; // $node; // $this->nodesToConvert[] = $node->parentNode; // $node;
$this->nodesToDisableSC[] = $node;
continue; 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); $tag = preg_replace('/([a-z0-9\[\]\/]*)?\/([\w]*)(\[(\d)*\])?$/i', "$2", $path);
if(!in_array($tag, $this->allowedTags)) if(!in_array($tag, $this->allowedTags))
@@ -4264,25 +4265,44 @@ return;
} }
// Disable Shortcodes in pre/code // Disable Shortcodes in pre/code
foreach($this->nodesToDisableSC as $node) foreach($this->nodesToDisableSC as $node)
{ {
// $value = $node->C14N(); $value = $node->C14N();
$value = $node->nodeValue; $value = str_replace("&#xD;","\r",$value);
// $value = str_replace("&#xD;","",$value);
if($node->nodeName == 'pre')
{
$value = preg_replace('/^<pre[^>]*>/','',$value);
$value = str_replace("</pre>", "", $value);
}
if($node->nodeName == 'code')
{
$value = preg_replace('/^<code[^>]*>/','',$value);
$value = str_replace("</code>", "", $value);
}
$value = str_replace('{','{{{',$value); // temporarily change {e_XXX} to {{{e_XXX}}} $value = str_replace('{','{{{',$value); // temporarily change {e_XXX} to {{{e_XXX}}}
$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;
// $value = htmlentities(htmlentities($value)); // Crashes apache.
$node->nodeValue = $value; // Crashes apache sometimes FIXME! .
} }
// Convert <code> and <pre> Tags to Htmlentities. // Convert <code> and <pre> Tags to Htmlentities.
/* TODO XXX Still necessary? Perhaps using bbcodes only?
foreach($this->nodesToConvert as $node) foreach($this->nodesToConvert as $node)
{ {
$value = $node->C14N(); $value = $node->C14N();
$value = str_replace("&#xD;","",$value); $value = str_replace("&#xD;","",$value);
// print_a("WOWOWO");
if($node->nodeName == 'pre') if($node->nodeName == 'pre')
{ {
$value = substr($value,5); $value = substr($value,5);
@@ -4300,12 +4320,13 @@ return;
$value = htmlentities(htmlentities($value)); // Needed $value = htmlentities(htmlentities($value)); // Needed
$node->nodeValue = $value; $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 = $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('{{{','&#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('}}}','&#125;', $cleaned); // convert shortcode temporary triple-curly braces back to entities.