mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-07-30 19:00:10 +02:00
Refactor AttrTransform_Lang slightly by changing input output from token to attribute.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@163 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -5,24 +5,18 @@ require_once 'HTMLPurifier/AttrTransform.php';
|
||||
class HTMLPurifier_AttrTransform_Lang extends HTMLPurifier_AttrTransform
|
||||
{
|
||||
|
||||
function transform($token) {
|
||||
function transform($attr) {
|
||||
|
||||
$lang = isset($token->attributes['lang']) ?
|
||||
$token->attributes['lang'] : false;
|
||||
$xml_lang = isset($token->attributes['xml:lang']) ?
|
||||
$token->attributes['xml:lang'] : false;
|
||||
|
||||
if ($lang === false && $xml_lang == false) return $token;
|
||||
|
||||
$new_token = $token->copy();
|
||||
$lang = isset($attr['lang']) ? $attr['lang'] : false;
|
||||
$xml_lang = isset($attr['xml:lang']) ? $attr['xml:lang'] : false;
|
||||
|
||||
if ($lang !== false && $xml_lang === false) {
|
||||
$new_token->attributes['xml:lang'] = $lang;
|
||||
$attr['xml:lang'] = $lang;
|
||||
} elseif ($xml_lang !== false) {
|
||||
$new_token->attributes['lang'] = $xml_lang;
|
||||
$attr['lang'] = $xml_lang;
|
||||
}
|
||||
|
||||
return $new_token;
|
||||
return $attr;
|
||||
|
||||
}
|
||||
|
||||
|
@@ -31,13 +31,13 @@ class HTMLPurifier_Strategy_ValidateAttributes extends HTMLPurifier_Strategy
|
||||
// DEFINITION CALL
|
||||
$defs = $this->definition->info[$token->name]->attr;
|
||||
|
||||
$attr = $token->attributes;
|
||||
|
||||
// DEFINITION CALL
|
||||
foreach ($this->definition->info_attr_transform as $transformer) {
|
||||
$token = $transformer->transform($token);
|
||||
$attr = $transformer->transform($attr);
|
||||
}
|
||||
|
||||
$attr = $token->attributes;
|
||||
$changed = false;
|
||||
foreach ($attr as $attr_key => $value) {
|
||||
|
||||
// call the definition
|
||||
@@ -55,20 +55,19 @@ class HTMLPurifier_Strategy_ValidateAttributes extends HTMLPurifier_Strategy
|
||||
|
||||
// put the results into effect
|
||||
if ($result === false || $result === null) {
|
||||
$changed = true;
|
||||
unset($attr[$attr_key]);
|
||||
} elseif (is_string($result)) {
|
||||
// simple substitution
|
||||
$changed = true;
|
||||
$attr[$attr_key] = $result;
|
||||
}
|
||||
// we'd also want slightly more complicated substitution,
|
||||
// although we're not sure how colliding attributes would
|
||||
// resolve
|
||||
}
|
||||
if ($changed) {
|
||||
$tokens[$key]->attributes = $attr;
|
||||
}
|
||||
|
||||
// commit changes
|
||||
// could interfere with flyweight implementation
|
||||
$tokens[$key]->attributes = $attr;
|
||||
}
|
||||
return $tokens;
|
||||
}
|
||||
|
Reference in New Issue
Block a user