Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ValidateAttributes.php 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * Validate all attributes in the tokens.
  4. */
  5. class HTMLPurifier_Strategy_ValidateAttributes extends HTMLPurifier_Strategy
  6. {
  7. /**
  8. * @param HTMLPurifier_Token[] $tokens
  9. * @param HTMLPurifier_Config $config
  10. * @param HTMLPurifier_Context $context
  11. * @return HTMLPurifier_Token[]
  12. */
  13. public function execute($tokens, $config, $context)
  14. {
  15. // setup validator
  16. $validator = new HTMLPurifier_AttrValidator();
  17. $token = false;
  18. $context->register('CurrentToken', $token);
  19. foreach ($tokens as $key => $token) {
  20. // only process tokens that have attributes,
  21. // namely start and empty tags
  22. if (!$token instanceof HTMLPurifier_Token_Start && !$token instanceof HTMLPurifier_Token_Empty) {
  23. continue;
  24. }
  25. // skip tokens that are armored
  26. if (!empty($token->armor['ValidateAttributes'])) {
  27. continue;
  28. }
  29. // note that we have no facilities here for removing tokens
  30. $validator->validateToken($token, $config, $context);
  31. }
  32. $context->destroy('CurrentToken');
  33. return $tokens;
  34. }
  35. }
  36. // vim: et sw=4 sts=4