1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-07-31 19:30:21 +02:00

[1.6.1] Refactor AttrTransform to reduce duplication.

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1016 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang
2007-05-05 02:25:55 +00:00
parent bbea02f55c
commit 0426985c81
11 changed files with 84 additions and 47 deletions

View File

@@ -12,12 +12,10 @@ extends HTMLPurifier_AttrTransform {
if (!isset($attr['bgcolor'])) return $attr;
$bgcolor = $attr['bgcolor'];
unset($attr['bgcolor']);
$bgcolor = $this->confiscateAttr($attr, 'bgcolor');
// some validation should happen here
$attr['style'] = isset($attr['style']) ? $attr['style'] : '';
$attr['style'] = "background-color:$bgcolor;" . $attr['style'];
$this->prependCSS($attr, "background-color:$bgcolor;");
return $attr;

View File

@@ -28,13 +28,10 @@ extends HTMLPurifier_AttrTransform {
}
function transform($attr, $config, &$context) {
if (!isset($attr[$this->attr])) return $attr;
unset($attr[$this->attr]);
if (!isset($attr['style'])) $attr['style'] = '';
$attr['style'] = $this->css . $attr['style'];
$this->prependCSS($attr, $this->css);
return $attr;
}
}

View File

@@ -5,22 +5,14 @@ require_once 'HTMLPurifier/AttrTransform.php';
/**
* Pre-transform that changes deprecated border attribute to CSS.
*/
class HTMLPurifier_AttrTransform_Border
extends HTMLPurifier_AttrTransform {
class HTMLPurifier_AttrTransform_Border extends HTMLPurifier_AttrTransform {
function transform($attr, $config, &$context) {
if (!isset($attr['border'])) return $attr;
$border_width = $attr['border'];
unset($attr['border']);
$border_width = $this->confiscateAttr($attr, 'border');
// some validation should happen here
$attr['style'] = isset($attr['style']) ? $attr['style'] : '';
$attr['style'] = "border:{$border_width}px solid;" . $attr['style'];
$this->prependCSS($attr, "border:{$border_width}px solid;");
return $attr;
}
}

View File

@@ -25,21 +25,18 @@ extends HTMLPurifier_AttrTransform {
if (!isset($attr[$this->attr])) return $attr;
$width = $attr[$this->attr];
unset($attr[$this->attr]);
$width = $this->confiscateAttr($attr, $this->attr);
// some validation could happen here
if (!isset($this->css[$this->attr])) return $attr;
$attr['style'] = isset($attr['style']) ? $attr['style'] : '';
$style = '';
foreach ($this->css[$this->attr] as $suffix) {
$property = "margin-$suffix";
$style .= "$property:{$width}px;";
}
$attr['style'] = $style . $attr['style'];
$this->prependCSS($attr, $style);
return $attr;

View File

@@ -18,13 +18,9 @@ class HTMLPurifier_AttrTransform_Length extends HTMLPurifier_AttrTransform
function transform($attr, $config, &$context) {
if (!isset($attr[$this->name])) return $attr;
$length = $attr[$this->name];
unset($attr[$this->name]);
$length = $this->confiscateAttr($attr, $this->name);
if(ctype_digit($length)) $length .= 'px';
$attr['style'] = isset($attr['style']) ? $attr['style'] : '';
$attr['style'] = $this->cssName . ":$length;" . $attr['style'];
$this->prependCSS($attr, $this->cssName . ":$length;");
return $attr;
}

View File

@@ -9,21 +9,11 @@ class HTMLPurifier_AttrTransform_Name extends HTMLPurifier_AttrTransform
{
function transform($attr, $config, &$context) {
if (!isset($attr['name'])) return $attr;
$name = $attr['name'];
unset($attr['name']);
if (isset($attr['id'])) {
// ID already set, discard name
return $attr;
}
$attr['id'] = $name;
$id = $this->confiscateAttr($attr, 'name');
if ( isset($attr['id'])) return $attr;
$attr['id'] = $id;
return $attr;
}
}

View File

@@ -12,8 +12,8 @@ extends HTMLPurifier_AttrTransform {
if (!isset($attr['align'])) return $attr;
$align = strtolower(trim($attr['align']));
unset($attr['align']);
$align = $this->confiscateAttr($attr, 'align');
$align = strtolower(trim($align));
$values = array('left' => 1,
'right' => 1,
@@ -24,8 +24,7 @@ extends HTMLPurifier_AttrTransform {
return $attr;
}
$attr['style'] = isset($attr['style']) ? $attr['style'] : '';
$attr['style'] = "text-align:$align;" . $attr['style'];
$this->prependCSS($attr, "text-align:$align;");
return $attr;