2006-07-30 18:37:42 +00:00
|
|
|
<?php
|
|
|
|
|
2006-08-07 19:22:26 +00:00
|
|
|
/**
|
|
|
|
* Validate all attributes in the tokens.
|
|
|
|
*/
|
|
|
|
|
2006-07-30 18:37:42 +00:00
|
|
|
class HTMLPurifier_Strategy_ValidateAttributes extends HTMLPurifier_Strategy
|
|
|
|
{
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-01-05 00:10:43 +00:00
|
|
|
public function execute($tokens, $config, $context) {
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-06-20 21:39:28 +00:00
|
|
|
// setup validator
|
|
|
|
$validator = new HTMLPurifier_AttrValidator();
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-06-27 02:03:15 +00:00
|
|
|
$token = false;
|
|
|
|
$context->register('CurrentToken', $token);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-07-30 18:37:42 +00:00
|
|
|
foreach ($tokens as $key => $token) {
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-08-07 19:22:26 +00:00
|
|
|
// only process tokens that have attributes,
|
|
|
|
// namely start and empty tags
|
2008-01-19 20:23:01 +00:00
|
|
|
if (!$token instanceof HTMLPurifier_Token_Start && !$token instanceof HTMLPurifier_Token_Empty) continue;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-06-20 21:39:28 +00:00
|
|
|
// skip tokens that are armored
|
|
|
|
if (!empty($token->armor['ValidateAttributes'])) continue;
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-06-27 02:03:15 +00:00
|
|
|
// note that we have no facilities here for removing tokens
|
|
|
|
$validator->validateToken($token, $config, $context);
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-06-27 13:20:02 +00:00
|
|
|
$tokens[$key] = $token; // for PHP 4
|
2006-07-30 18:37:42 +00:00
|
|
|
}
|
2007-08-02 22:44:42 +00:00
|
|
|
$context->destroy('CurrentToken');
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-07-30 18:37:42 +00:00
|
|
|
return $tokens;
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-07-30 18:37:42 +00:00
|
|
|
}
|
|
|
|
|
2008-12-06 09:24:59 +00:00
|
|
|
// vim: et sw=4 sts=4
|