ValidateAttributes.php 1.0 KB

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