PageRenderTime 44ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/vjCommentPlugin/lib/tools/htmlpurifier/library/HTMLPurifier/Injector/RemoveSpansWithoutAttributes.php

https://bitbucket.org/Kudlaty/360kdw
PHP | 60 lines | 37 code | 11 blank | 12 comment | 7 complexity | 29da73b24cb7b03d0bd80d105e56401a MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /**
  3. * Injector that removes spans with no attributes
  4. */
  5. class HTMLPurifier_Injector_RemoveSpansWithoutAttributes extends HTMLPurifier_Injector
  6. {
  7. public $name = 'RemoveSpansWithoutAttributes';
  8. public $needed = array('span');
  9. private $attrValidator;
  10. /**
  11. * Used by AttrValidator
  12. */
  13. private $config;
  14. private $context;
  15. public function prepare($config, $context) {
  16. $this->attrValidator = new HTMLPurifier_AttrValidator();
  17. $this->config = $config;
  18. $this->context = $context;
  19. return parent::prepare($config, $context);
  20. }
  21. public function handleElement(&$token) {
  22. if ($token->name !== 'span' || !$token instanceof HTMLPurifier_Token_Start) {
  23. return;
  24. }
  25. // We need to validate the attributes now since this doesn't normally
  26. // happen until after MakeWellFormed. If all the attributes are removed
  27. // the span needs to be removed too.
  28. $this->attrValidator->validateToken($token, $this->config, $this->context);
  29. $token->armor['ValidateAttributes'] = true;
  30. if (!empty($token->attr)) {
  31. return;
  32. }
  33. $nesting = 0;
  34. $spanContentTokens = array();
  35. while ($this->forwardUntilEndToken($i, $current, $nesting)) {}
  36. if ($current instanceof HTMLPurifier_Token_End && $current->name === 'span') {
  37. // Mark closing span tag for deletion
  38. $current->markForDeletion = true;
  39. // Delete open span tag
  40. $token = false;
  41. }
  42. }
  43. public function handleEnd(&$token) {
  44. if ($token->markForDeletion) {
  45. $token = false;
  46. }
  47. }
  48. }
  49. // vim: et sw=4 sts=4