2007-05-05 15:48:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once 'HTMLPurifier/AttrTransform.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generic pre-transform that converts an attribute with a fixed number of
|
|
|
|
* values (enumerated) to CSS.
|
|
|
|
*/
|
|
|
|
class HTMLPurifier_AttrTransform_EnumToCSS extends HTMLPurifier_AttrTransform {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Name of attribute to transform from
|
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
protected $attr;
|
2007-05-05 15:48:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Lookup array of attribute values to CSS
|
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
protected $enumToCSS = array();
|
2007-05-05 15:48:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Case sensitivity of the matching
|
|
|
|
* @warning Currently can only be guaranteed to work with ASCII
|
|
|
|
* values.
|
|
|
|
*/
|
2007-11-25 02:24:39 +00:00
|
|
|
protected $caseSensitive = false;
|
2007-05-05 15:48:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $attr String attribute name to transform from
|
|
|
|
* @param $enumToCSS Lookup array of attribute values to CSS
|
|
|
|
* @param $case_sensitive Boolean case sensitivity indicator, default false
|
|
|
|
*/
|
2007-11-29 04:29:51 +00:00
|
|
|
public function __construct($attr, $enum_to_css, $case_sensitive = false) {
|
2007-05-05 15:48:41 +00:00
|
|
|
$this->attr = $attr;
|
|
|
|
$this->enumToCSS = $enum_to_css;
|
|
|
|
$this->caseSensitive = (bool) $case_sensitive;
|
|
|
|
}
|
|
|
|
|
2008-01-05 00:10:43 +00:00
|
|
|
public function transform($attr, $config, $context) {
|
2007-05-05 15:48:41 +00:00
|
|
|
|
|
|
|
if (!isset($attr[$this->attr])) return $attr;
|
|
|
|
|
|
|
|
$value = trim($attr[$this->attr]);
|
|
|
|
unset($attr[$this->attr]);
|
|
|
|
|
|
|
|
if (!$this->caseSensitive) $value = strtolower($value);
|
|
|
|
|
|
|
|
if (!isset($this->enumToCSS[$value])) {
|
|
|
|
return $attr;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->prependCSS($attr, $this->enumToCSS[$value]);
|
|
|
|
|
|
|
|
return $attr;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|