From d4949327efa15b492cab1bef3fe074290a328a17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 21 Feb 2014 15:43:14 +0100 Subject: [add] HTML Purifier added to clean code --- .../HTMLPurifier/Injector/RemoveEmpty.php | 101 +++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 inc/3rdparty/htmlpurifier/HTMLPurifier/Injector/RemoveEmpty.php (limited to 'inc/3rdparty/htmlpurifier/HTMLPurifier/Injector/RemoveEmpty.php') diff --git a/inc/3rdparty/htmlpurifier/HTMLPurifier/Injector/RemoveEmpty.php b/inc/3rdparty/htmlpurifier/HTMLPurifier/Injector/RemoveEmpty.php new file mode 100644 index 00000000..55669d1c --- /dev/null +++ b/inc/3rdparty/htmlpurifier/HTMLPurifier/Injector/RemoveEmpty.php @@ -0,0 +1,101 @@ + 1, 'th' => 1, 'td' => 1, 'iframe' => 1); + + /** + * @param HTMLPurifier_Config $config + * @param HTMLPurifier_Context $context + * @return void + */ + public function prepare($config, $context) + { + parent::prepare($config, $context); + $this->config = $config; + $this->context = $context; + $this->removeNbsp = $config->get('AutoFormat.RemoveEmpty.RemoveNbsp'); + $this->removeNbspExceptions = $config->get('AutoFormat.RemoveEmpty.RemoveNbsp.Exceptions'); + $this->attrValidator = new HTMLPurifier_AttrValidator(); + } + + /** + * @param HTMLPurifier_Token $token + */ + public function handleElement(&$token) + { + if (!$token instanceof HTMLPurifier_Token_Start) { + return; + } + $next = false; + $deleted = 1; // the current tag + for ($i = count($this->inputZipper->back) - 1; $i >= 0; $i--, $deleted++) { + $next = $this->inputZipper->back[$i]; + if ($next instanceof HTMLPurifier_Token_Text) { + if ($next->is_whitespace) { + continue; + } + if ($this->removeNbsp && !isset($this->removeNbspExceptions[$token->name])) { + $plain = str_replace("\xC2\xA0", "", $next->data); + $isWsOrNbsp = $plain === '' || ctype_space($plain); + if ($isWsOrNbsp) { + continue; + } + } + } + break; + } + if (!$next || ($next instanceof HTMLPurifier_Token_End && $next->name == $token->name)) { + if (isset($this->_exclude[$token->name])) { + return; + } + $this->attrValidator->validateToken($token, $this->config, $this->context); + $token->armor['ValidateAttributes'] = true; + if (isset($token->attr['id']) || isset($token->attr['name'])) { + return; + } + $token = $deleted + 1; + for ($b = 0, $c = count($this->inputZipper->front); $b < $c; $b++) { + $prev = $this->inputZipper->front[$b]; + if ($prev instanceof HTMLPurifier_Token_Text && $prev->is_whitespace) { + continue; + } + break; + } + // This is safe because we removed the token that triggered this. + $this->rewindOffset($b+$deleted); + return; + } + } +} + +// vim: et sw=4 sts=4 -- cgit v1.2.3