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

New methods added to parser: addAllowedTag() and addAllowedAttribute() to use with the cleanHtml() method.

This commit is contained in:
Cameron
2015-04-16 15:23:21 -07:00
parent 7bdb2ef48f
commit 0e41e6e7a3

View File

@@ -2676,7 +2676,27 @@ class e_parser
$this->domObj = new DOMDocument(); $this->domObj = new DOMDocument();
} }
/** /**
* Add Allowed Tags.
* @param string
*/
public function addAllowedTag($tag)
{
$this->allowedTags[] = $tag;
}
/**
* @param $tag - html tag.
* @param $attArray - array of attributes. eg. array('style', 'id', 'class') etc.
*/
public function addAllowedAttribute($tag, $attArray)
{
$this->allowedAttributes[$tag] = (array) $attArray;
}
/**
* Set Allowed Tags. * Set Allowed Tags.
* @param $array * @param $array
*/ */
@@ -3443,7 +3463,8 @@ return;
$html = str_replace(' ', '@nbsp;', $html); // prevent replacement of   with spaces. $html = str_replace(' ', '@nbsp;', $html); // prevent replacement of   with spaces.
if(preg_match("/<body/i",$html)!==true) // HTML Fragment
if(strpos($html, "<body")===false) // HTML Fragment
{ {
$html = '<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html><html><head><meta charset="utf-8"></head><body>'.$html.'</body></html>'; $html = '<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html><html><head><meta charset="utf-8"></head><body>'.$html.'</body></html>';
} }
@@ -3471,6 +3492,7 @@ return;
// Set it up for processing. // Set it up for processing.
// libxml_use_internal_errors(true); // hides errors.
$doc = $this->domObj; $doc = $this->domObj;
@$doc->loadHTML($html); @$doc->loadHTML($html);