friendica/vendor/ezyang/htmlpurifier/library/HTMLPurifier/Strategy/ValidateAttributes.php

46 lines
1.2 KiB
PHP
Raw Normal View History

2010-09-09 03:14:17 +00:00
<?php
/**
* Validate all attributes in the tokens.
*/
class HTMLPurifier_Strategy_ValidateAttributes extends HTMLPurifier_Strategy
{
2016-02-09 10:06:17 +00:00
/**
* @param HTMLPurifier_Token[] $tokens
* @param HTMLPurifier_Config $config
* @param HTMLPurifier_Context $context
* @return HTMLPurifier_Token[]
*/
public function execute($tokens, $config, $context)
{
2010-09-09 03:14:17 +00:00
// setup validator
$validator = new HTMLPurifier_AttrValidator();
$token = false;
$context->register('CurrentToken', $token);
foreach ($tokens as $key => $token) {
// only process tokens that have attributes,
// namely start and empty tags
2016-02-09 10:06:17 +00:00
if (!$token instanceof HTMLPurifier_Token_Start && !$token instanceof HTMLPurifier_Token_Empty) {
continue;
}
2010-09-09 03:14:17 +00:00
// skip tokens that are armored
2016-02-09 10:06:17 +00:00
if (!empty($token->armor['ValidateAttributes'])) {
continue;
}
2010-09-09 03:14:17 +00:00
// note that we have no facilities here for removing tokens
$validator->validateToken($token, $config, $context);
}
$context->destroy('CurrentToken');
return $tokens;
}
}
// vim: et sw=4 sts=4