2006-07-30 18:37:42 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once 'HTMLPurifier/Strategy.php';
|
2006-08-14 21:22:49 +00:00
|
|
|
require_once 'HTMLPurifier/HTMLDefinition.php';
|
2006-07-30 18:37:42 +00:00
|
|
|
require_once 'HTMLPurifier/IDAccumulator.php';
|
2006-08-11 20:23:41 +00:00
|
|
|
|
2007-06-20 21:39:28 +00:00
|
|
|
require_once 'HTMLPurifier/AttrValidator.php';
|
|
|
|
|
2006-09-16 22:36:58 +00:00
|
|
|
HTMLPurifier_ConfigSchema::define(
|
2006-08-27 18:49:16 +00:00
|
|
|
'Attr', 'IDBlacklist', array(), 'list',
|
2006-08-11 20:23:41 +00:00
|
|
|
'Array of IDs not allowed in the document.');
|
2006-07-30 18:37:42 +00:00
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
2006-10-01 20:47:07 +00:00
|
|
|
function execute($tokens, $config, &$context) {
|
2006-08-04 01:47:48 +00:00
|
|
|
|
2007-06-20 21:39:28 +00:00
|
|
|
// setup validator
|
|
|
|
$validator = new HTMLPurifier_AttrValidator();
|
2006-08-04 01:47:48 +00:00
|
|
|
|
2007-06-27 02:03:15 +00:00
|
|
|
$token = false;
|
|
|
|
$context->register('CurrentToken', $token);
|
|
|
|
|
2006-07-30 18:37:42 +00:00
|
|
|
foreach ($tokens as $key => $token) {
|
2006-07-30 19:11:18 +00:00
|
|
|
|
2006-08-07 19:22:26 +00:00
|
|
|
// only process tokens that have attributes,
|
|
|
|
// namely start and empty tags
|
|
|
|
if ($token->type !== 'start' && $token->type !== 'empty') continue;
|
2006-07-30 19:11:18 +00:00
|
|
|
|
2007-06-20 21:39:28 +00:00
|
|
|
// skip tokens that are armored
|
|
|
|
if (!empty($token->armor['ValidateAttributes'])) continue;
|
2006-08-07 19:22:26 +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);
|
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');
|
2006-10-01 21:55:13 +00:00
|
|
|
|
2006-07-30 18:37:42 +00:00
|
|
|
return $tokens;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|