mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-03-11 17:18:44 +00:00
De-singleton-ized (HTML|CSS)Definition, tying them to the configuration and making them more amenable to changes.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@350 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
90279eaee2
commit
14aeafcf22
1
NEWS
1
NEWS
@ -8,6 +8,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
|
|||||||
- Shorthand CSS properties implemented: font, border, background, list-style
|
- Shorthand CSS properties implemented: font, border, background, list-style
|
||||||
- Basic color keywords translated into hexadecimal values
|
- Basic color keywords translated into hexadecimal values
|
||||||
- Table CSS properties implemented
|
- Table CSS properties implemented
|
||||||
|
- (HTML|CSS)Definition de-singleton-ized
|
||||||
|
|
||||||
1.0.0beta, released 2006-08-16
|
1.0.0beta, released 2006-08-16
|
||||||
- First public release, most functionality implemented. Notable omissions are:
|
- First public release, most functionality implemented. Notable omissions are:
|
||||||
|
1
TODO
1
TODO
@ -8,7 +8,6 @@ Ongoing
|
|||||||
1.0 release
|
1.0 release
|
||||||
- Lossy alternate character encoding support (characters not in the encoding
|
- Lossy alternate character encoding support (characters not in the encoding
|
||||||
will get silently dropped).
|
will get silently dropped).
|
||||||
- Revise (HTML|CSS)Definition and Config relationship (groundwork for 2.0)
|
|
||||||
|
|
||||||
1.1 release
|
1.1 release
|
||||||
- Directive documentation generation
|
- Directive documentation generation
|
||||||
|
@ -13,8 +13,8 @@ class HTMLPurifier_AttrDef_Border extends HTMLPurifier_AttrDef
|
|||||||
*/
|
*/
|
||||||
var $info = array();
|
var $info = array();
|
||||||
|
|
||||||
function HTMLPurifier_AttrDef_Border() {
|
function HTMLPurifier_AttrDef_Border($config) {
|
||||||
$def = HTMLPurifier_CSSDefinition::instance();
|
$def = $config->getCSSDefinition();
|
||||||
$this->info['border-width'] = $def->info['border-width'];
|
$this->info['border-width'] = $def->info['border-width'];
|
||||||
$this->info['border-style'] = $def->info['border-style'];
|
$this->info['border-style'] = $def->info['border-style'];
|
||||||
$this->info['border-top-color'] = $def->info['border-top-color'];
|
$this->info['border-top-color'] = $def->info['border-top-color'];
|
||||||
|
@ -16,7 +16,7 @@ class HTMLPurifier_AttrDef_CSS extends HTMLPurifier_AttrDef
|
|||||||
|
|
||||||
$css = $this->parseCDATA($css);
|
$css = $this->parseCDATA($css);
|
||||||
|
|
||||||
$definition = HTMLPurifier_CSSDefinition::instance();
|
$definition = $config->getCSSDefinition();
|
||||||
|
|
||||||
// we're going to break the spec and explode by semicolons.
|
// we're going to break the spec and explode by semicolons.
|
||||||
// This is because semicolon rarely appears in escaped form
|
// This is because semicolon rarely appears in escaped form
|
||||||
|
@ -30,8 +30,8 @@ class HTMLPurifier_AttrDef_Font extends HTMLPurifier_AttrDef
|
|||||||
'status-bar' => true
|
'status-bar' => true
|
||||||
);
|
);
|
||||||
|
|
||||||
function HTMLPurifier_AttrDef_Font() {
|
function HTMLPurifier_AttrDef_Font($config) {
|
||||||
$def = HTMLPurifier_CSSDefinition::instance();
|
$def = $config->getCSSDefinition();
|
||||||
$this->info['font-style'] = $def->info['font-style'];
|
$this->info['font-style'] = $def->info['font-style'];
|
||||||
$this->info['font-variant'] = $def->info['font-variant'];
|
$this->info['font-variant'] = $def->info['font-variant'];
|
||||||
$this->info['font-weight'] = $def->info['font-weight'];
|
$this->info['font-weight'] = $def->info['font-weight'];
|
||||||
|
@ -16,8 +16,8 @@ class HTMLPurifier_AttrDef_ListStyle extends HTMLPurifier_AttrDef
|
|||||||
*/
|
*/
|
||||||
var $info;
|
var $info;
|
||||||
|
|
||||||
function HTMLPurifier_AttrDef_ListStyle() {
|
function HTMLPurifier_AttrDef_ListStyle($config) {
|
||||||
$def = HTMLPurifier_CSSDefinition::instance();
|
$def = $config->getCSSDefinition();
|
||||||
$this->info['list-style-type'] = $def->info['list-style-type'];
|
$this->info['list-style-type'] = $def->info['list-style-type'];
|
||||||
$this->info['list-style-position'] = $def->info['list-style-position'];
|
$this->info['list-style-position'] = $def->info['list-style-position'];
|
||||||
}
|
}
|
||||||
|
@ -24,27 +24,10 @@ class HTMLPurifier_CSSDefinition
|
|||||||
*/
|
*/
|
||||||
var $info = array();
|
var $info = array();
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns sole instance of this definition.
|
|
||||||
* @param $prototype Optional prototype you may pass in to overload
|
|
||||||
* the sole instance. Good for replacing an instance of
|
|
||||||
* the object with your own, custom object.
|
|
||||||
*/
|
|
||||||
function &instance($prototype = null) {
|
|
||||||
static $instance = null;
|
|
||||||
if ($prototype) {
|
|
||||||
$instance = $prototype;
|
|
||||||
} elseif (!$instance) {
|
|
||||||
$instance = new HTMLPurifier_CSSDefinition();
|
|
||||||
$instance->setup();
|
|
||||||
}
|
|
||||||
return $instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs the info array. The meat of this class.
|
* Constructs the info array. The meat of this class.
|
||||||
*/
|
*/
|
||||||
function setup() {
|
function setup($config) {
|
||||||
|
|
||||||
$this->info['text-align'] = new HTMLPurifier_AttrDef_Enum(
|
$this->info['text-align'] = new HTMLPurifier_AttrDef_Enum(
|
||||||
array('left', 'right', 'center', 'justify'), false);
|
array('left', 'right', 'center', 'justify'), false);
|
||||||
@ -74,7 +57,7 @@ class HTMLPurifier_CSSDefinition
|
|||||||
array('disc', 'circle', 'square', 'decimal', 'lower-roman',
|
array('disc', 'circle', 'square', 'decimal', 'lower-roman',
|
||||||
'upper-roman', 'lower-alpha', 'upper-alpha'), false);
|
'upper-roman', 'lower-alpha', 'upper-alpha'), false);
|
||||||
|
|
||||||
$this->info['list-style'] = new HTMLPurifier_AttrDef_ListStyle();
|
$this->info['list-style'] = new HTMLPurifier_AttrDef_ListStyle($config);
|
||||||
|
|
||||||
$this->info['text-transform'] = new HTMLPurifier_AttrDef_Enum(
|
$this->info['text-transform'] = new HTMLPurifier_AttrDef_Enum(
|
||||||
array('capitalize', 'uppercase', 'lowercase', 'none'), false);
|
array('capitalize', 'uppercase', 'lowercase', 'none'), false);
|
||||||
@ -183,14 +166,14 @@ class HTMLPurifier_CSSDefinition
|
|||||||
|
|
||||||
// MUST be called after other font properties, as it references
|
// MUST be called after other font properties, as it references
|
||||||
// a CSSDefinition object
|
// a CSSDefinition object
|
||||||
$this->info['font'] = new HTMLPurifier_AttrDef_Font();
|
$this->info['font'] = new HTMLPurifier_AttrDef_Font($config);
|
||||||
|
|
||||||
// same here
|
// same here
|
||||||
$this->info['border'] =
|
$this->info['border'] =
|
||||||
$this->info['border-bottom'] =
|
$this->info['border-bottom'] =
|
||||||
$this->info['border-top'] =
|
$this->info['border-top'] =
|
||||||
$this->info['border-left'] =
|
$this->info['border-left'] =
|
||||||
$this->info['border-right'] = new HTMLPurifier_AttrDef_Border();
|
$this->info['border-right'] = new HTMLPurifier_AttrDef_Border($config);
|
||||||
|
|
||||||
$this->info['border-collapse'] = new HTMLPurifier_AttrDef_Enum(array(
|
$this->info['border-collapse'] = new HTMLPurifier_AttrDef_Enum(array(
|
||||||
'collapse', 'seperate'));
|
'collapse', 'seperate'));
|
||||||
|
@ -25,6 +25,16 @@ class HTMLPurifier_Config
|
|||||||
*/
|
*/
|
||||||
var $def;
|
var $def;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instance of HTMLPurifier_HTMLDefinition
|
||||||
|
*/
|
||||||
|
var $html_definition;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instance of HTMLPurifier_CSSDefinition
|
||||||
|
*/
|
||||||
|
var $css_definition;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $definition HTMLPurifier_ConfigDef that defines what directives
|
* @param $definition HTMLPurifier_ConfigDef that defines what directives
|
||||||
* are allowed.
|
* are allowed.
|
||||||
@ -92,6 +102,28 @@ class HTMLPurifier_Config
|
|||||||
$this->conf[$namespace][$key] = $value;
|
$this->conf[$namespace][$key] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a copy of the HTML definition.
|
||||||
|
*/
|
||||||
|
function getHTMLDefinition() {
|
||||||
|
if ($this->html_definition === null) {
|
||||||
|
$this->html_definition = new HTMLPurifier_HTMLDefinition();
|
||||||
|
$this->html_definition->setup($this);
|
||||||
|
}
|
||||||
|
return $this->html_definition;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a copy of the CSS definition
|
||||||
|
*/
|
||||||
|
function getCSSDefinition() {
|
||||||
|
if ($this->css_definition === null) {
|
||||||
|
$this->css_definition = new HTMLPurifier_CSSDefinition();
|
||||||
|
$this->css_definition->setup($this);
|
||||||
|
}
|
||||||
|
return $this->css_definition;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
@ -26,15 +26,15 @@ class HTMLPurifier_ConfigDef {
|
|||||||
* Lookup table of allowed types.
|
* Lookup table of allowed types.
|
||||||
*/
|
*/
|
||||||
var $types = array(
|
var $types = array(
|
||||||
'string' => true,
|
'string' => true,
|
||||||
'istring' => true,
|
'istring' => true,
|
||||||
'int' => true,
|
'int' => true,
|
||||||
'float' => true,
|
'float' => true,
|
||||||
'bool' => true,
|
'bool' => true,
|
||||||
'lookup' => true,
|
'lookup' => true,
|
||||||
'list' => true,
|
'list' => true,
|
||||||
'hash' => true,
|
'hash' => true,
|
||||||
'mixed' => true
|
'mixed' => true
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,6 +44,8 @@ class HTMLPurifier_ConfigDef {
|
|||||||
$this->defineNamespace('Core', 'Core features that are always available.');
|
$this->defineNamespace('Core', 'Core features that are always available.');
|
||||||
$this->defineNamespace('Attr', 'Features regarding attribute validation.');
|
$this->defineNamespace('Attr', 'Features regarding attribute validation.');
|
||||||
$this->defineNamespace('URI', 'Features regarding Uniform Resource Identifiers.');
|
$this->defineNamespace('URI', 'Features regarding Uniform Resource Identifiers.');
|
||||||
|
$this->defineNamespace('HTML', 'Configuration regarding allowed HTML.');
|
||||||
|
$this->defineNamespace('CSS', 'Configuration regarding allowed CSS.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,29 +78,10 @@ class HTMLPurifier_HTMLDefinition
|
|||||||
*/
|
*/
|
||||||
var $info_attr_transform_post = array();
|
var $info_attr_transform_post = array();
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve sole instance of definition object.
|
|
||||||
* @param $prototype Optional prototype to overload instance with.
|
|
||||||
* @warning Prototype is not passed by reference, so in order to get
|
|
||||||
* a copy of the real one, you'll have to destroy your copy
|
|
||||||
* and use instance() to get it. We strongly recommend modifying
|
|
||||||
* the default returned definition instead.
|
|
||||||
*/
|
|
||||||
function &instance($prototype = null) {
|
|
||||||
static $instance = null;
|
|
||||||
if ($prototype) {
|
|
||||||
$instance = $prototype;
|
|
||||||
} elseif (!$instance) {
|
|
||||||
$instance = new HTMLPurifier_HTMLDefinition();
|
|
||||||
$instance->setup();
|
|
||||||
}
|
|
||||||
return $instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the definition, the meat of the class.
|
* Initializes the definition, the meat of the class.
|
||||||
*/
|
*/
|
||||||
function setup() {
|
function setup($config) {
|
||||||
|
|
||||||
// emulates the structure of the DTD
|
// emulates the structure of the DTD
|
||||||
// these are condensed, however, with bad stuff taken out
|
// these are condensed, however, with bad stuff taken out
|
||||||
|
@ -34,21 +34,18 @@ require_once 'HTMLPurifier/HTMLDefinition.php';
|
|||||||
class HTMLPurifier_Strategy_FixNesting extends HTMLPurifier_Strategy
|
class HTMLPurifier_Strategy_FixNesting extends HTMLPurifier_Strategy
|
||||||
{
|
{
|
||||||
|
|
||||||
var $definition;
|
|
||||||
|
|
||||||
function HTMLPurifier_Strategy_FixNesting() {
|
|
||||||
$this->definition = HTMLPurifier_HTMLDefinition::instance();
|
|
||||||
}
|
|
||||||
|
|
||||||
function execute($tokens, $config) {
|
function execute($tokens, $config) {
|
||||||
|
|
||||||
//####################################################################//
|
//####################################################################//
|
||||||
// Pre-processing
|
// Pre-processing
|
||||||
|
|
||||||
|
// get a copy of the HTML definition
|
||||||
|
$definition = $config->getHTMLDefinition();
|
||||||
|
|
||||||
// insert implicit "parent" node, will be removed at end.
|
// insert implicit "parent" node, will be removed at end.
|
||||||
// ! we might want to move this to configuration
|
// ! we might want to move this to configuration
|
||||||
// DEFINITION CALL
|
// DEFINITION CALL
|
||||||
$parent_name = $this->definition->info_parent;
|
$parent_name = $definition->info_parent;
|
||||||
array_unshift($tokens, new HTMLPurifier_Token_Start($parent_name));
|
array_unshift($tokens, new HTMLPurifier_Token_Start($parent_name));
|
||||||
$tokens[] = new HTMLPurifier_Token_End($parent_name);
|
$tokens[] = new HTMLPurifier_Token_End($parent_name);
|
||||||
|
|
||||||
@ -104,7 +101,7 @@ class HTMLPurifier_Strategy_FixNesting extends HTMLPurifier_Strategy
|
|||||||
if ($count = count($stack)) {
|
if ($count = count($stack)) {
|
||||||
$parent_index = $stack[$count-1];
|
$parent_index = $stack[$count-1];
|
||||||
$parent_name = $tokens[$parent_index]->name;
|
$parent_name = $tokens[$parent_index]->name;
|
||||||
$parent_def = $this->definition->info[$parent_name];
|
$parent_def = $definition->info[$parent_name];
|
||||||
} else {
|
} else {
|
||||||
// unknown info, it won't be used anyway
|
// unknown info, it won't be used anyway
|
||||||
$parent_index = $parent_name = $parent_def = null;
|
$parent_index = $parent_name = $parent_def = null;
|
||||||
@ -143,7 +140,7 @@ class HTMLPurifier_Strategy_FixNesting extends HTMLPurifier_Strategy
|
|||||||
$result = false;
|
$result = false;
|
||||||
} else {
|
} else {
|
||||||
// DEFINITION CALL
|
// DEFINITION CALL
|
||||||
$def = $this->definition->info[$tokens[$i]->name];
|
$def = $definition->info[$tokens[$i]->name];
|
||||||
$child_def = $def->child;
|
$child_def = $def->child;
|
||||||
|
|
||||||
// have DTD child def validate children
|
// have DTD child def validate children
|
||||||
@ -233,7 +230,7 @@ class HTMLPurifier_Strategy_FixNesting extends HTMLPurifier_Strategy
|
|||||||
array_pop($stack);
|
array_pop($stack);
|
||||||
// pop an exclusion lookup off exclusion stack if
|
// pop an exclusion lookup off exclusion stack if
|
||||||
// we ended node and that node had exclusions
|
// we ended node and that node had exclusions
|
||||||
if ($this->definition->info[$tokens[$i]->name]->excludes) {
|
if ($definition->info[$tokens[$i]->name]->excludes) {
|
||||||
array_pop($exclude_stack);
|
array_pop($exclude_stack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,15 +10,9 @@ require_once 'HTMLPurifier/Generator.php';
|
|||||||
class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy
|
class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy
|
||||||
{
|
{
|
||||||
|
|
||||||
var $generator;
|
|
||||||
var $definition;
|
|
||||||
|
|
||||||
function HTMLPurifier_Strategy_MakeWellFormed() {
|
|
||||||
$this->generator = new HTMLPurifier_Generator();
|
|
||||||
$this->definition = HTMLPurifier_HTMLDefinition::instance();
|
|
||||||
}
|
|
||||||
|
|
||||||
function execute($tokens, $config) {
|
function execute($tokens, $config) {
|
||||||
|
$definition = $config->getHTMLDefinition();
|
||||||
|
$generator = new HTMLPurifier_Generator();
|
||||||
$result = array();
|
$result = array();
|
||||||
$current_nesting = array();
|
$current_nesting = array();
|
||||||
$escape_invalid_tags = $config->get('Core', 'EscapeInvalidTags');
|
$escape_invalid_tags = $config->get('Core', 'EscapeInvalidTags');
|
||||||
@ -29,7 +23,7 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DEFINITION CALL
|
// DEFINITION CALL
|
||||||
$info = $this->definition->info[$token->name]->child;
|
$info = $definition->info[$token->name]->child;
|
||||||
|
|
||||||
// test if it claims to be a start tag but is empty
|
// test if it claims to be a start tag but is empty
|
||||||
if ($info->type == 'empty' &&
|
if ($info->type == 'empty' &&
|
||||||
@ -66,7 +60,7 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy
|
|||||||
|
|
||||||
$parent = array_pop($current_nesting);
|
$parent = array_pop($current_nesting);
|
||||||
$parent_name = $parent->name;
|
$parent_name = $parent->name;
|
||||||
$parent_info = $this->definition->info[$parent_name];
|
$parent_info = $definition->info[$parent_name];
|
||||||
|
|
||||||
if (isset($parent_info->auto_close[$token->name])) {
|
if (isset($parent_info->auto_close[$token->name])) {
|
||||||
$result[] = new HTMLPurifier_Token_End($parent_name);
|
$result[] = new HTMLPurifier_Token_End($parent_name);
|
||||||
@ -92,7 +86,7 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy
|
|||||||
if (empty($current_nesting)) {
|
if (empty($current_nesting)) {
|
||||||
if ($escape_invalid_tags) {
|
if ($escape_invalid_tags) {
|
||||||
$result[] = new HTMLPurifier_Token_Text(
|
$result[] = new HTMLPurifier_Token_Text(
|
||||||
$this->generator->generateFromToken($token, $config)
|
$generator->generateFromToken($token, $config)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@ -129,7 +123,7 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy
|
|||||||
if ($skipped_tags === false) {
|
if ($skipped_tags === false) {
|
||||||
if ($escape_invalid_tags) {
|
if ($escape_invalid_tags) {
|
||||||
$result[] = new HTMLPurifier_Token_Text(
|
$result[] = new HTMLPurifier_Token_Text(
|
||||||
$this->generator->generateFromToken($token, $config)
|
$generator->generateFromToken($token, $config)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
@ -16,35 +16,28 @@ require_once 'HTMLPurifier/TagTransform.php';
|
|||||||
class HTMLPurifier_Strategy_RemoveForeignElements extends HTMLPurifier_Strategy
|
class HTMLPurifier_Strategy_RemoveForeignElements extends HTMLPurifier_Strategy
|
||||||
{
|
{
|
||||||
|
|
||||||
var $generator;
|
|
||||||
var $definition;
|
|
||||||
|
|
||||||
function HTMLPurifier_Strategy_RemoveForeignElements() {
|
|
||||||
$this->generator = new HTMLPurifier_Generator();
|
|
||||||
$this->definition = HTMLPurifier_HTMLDefinition::instance();
|
|
||||||
}
|
|
||||||
|
|
||||||
function execute($tokens, $config) {
|
function execute($tokens, $config) {
|
||||||
|
$definition = $config->getHTMLDefinition();
|
||||||
|
$generator = new HTMLPurifier_Generator();
|
||||||
$result = array();
|
$result = array();
|
||||||
$escape_invalid_tags = $config->get('Core', 'EscapeInvalidTags');
|
$escape_invalid_tags = $config->get('Core', 'EscapeInvalidTags');
|
||||||
foreach($tokens as $token) {
|
foreach($tokens as $token) {
|
||||||
if (!empty( $token->is_tag )) {
|
if (!empty( $token->is_tag )) {
|
||||||
// DEFINITION CALL
|
// DEFINITION CALL
|
||||||
if (isset($this->definition->info[$token->name])) {
|
if (isset($definition->info[$token->name])) {
|
||||||
// leave untouched
|
// leave untouched
|
||||||
} elseif (
|
} elseif (
|
||||||
isset($this->definition->info_tag_transform[$token->name])
|
isset($definition->info_tag_transform[$token->name])
|
||||||
) {
|
) {
|
||||||
// there is a transformation for this tag
|
// there is a transformation for this tag
|
||||||
// DEFINITION CALL
|
// DEFINITION CALL
|
||||||
$token = $this->
|
$token = $definition->
|
||||||
definition->
|
info_tag_transform[$token->name]->
|
||||||
info_tag_transform[$token->name]->
|
transform($token);
|
||||||
transform($token);
|
|
||||||
} elseif ($escape_invalid_tags) {
|
} elseif ($escape_invalid_tags) {
|
||||||
// invalid tag, generate HTML and insert in
|
// invalid tag, generate HTML and insert in
|
||||||
$token = new HTMLPurifier_Token_Text(
|
$token = new HTMLPurifier_Token_Text(
|
||||||
$this->generator->generateFromToken($token, $config)
|
$generator->generateFromToken($token, $config)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
|
@ -17,14 +17,10 @@ HTMLPurifier_ConfigDef::define(
|
|||||||
class HTMLPurifier_Strategy_ValidateAttributes extends HTMLPurifier_Strategy
|
class HTMLPurifier_Strategy_ValidateAttributes extends HTMLPurifier_Strategy
|
||||||
{
|
{
|
||||||
|
|
||||||
var $definition;
|
|
||||||
|
|
||||||
function HTMLPurifier_Strategy_ValidateAttributes() {
|
|
||||||
$this->definition = HTMLPurifier_HTMLDefinition::instance();
|
|
||||||
}
|
|
||||||
|
|
||||||
function execute($tokens, $config) {
|
function execute($tokens, $config) {
|
||||||
|
|
||||||
|
$definition = $config->getHTMLDefinition();
|
||||||
|
|
||||||
// setup StrategyContext
|
// setup StrategyContext
|
||||||
$context = new HTMLPurifier_AttrContext();
|
$context = new HTMLPurifier_AttrContext();
|
||||||
|
|
||||||
@ -36,7 +32,7 @@ class HTMLPurifier_Strategy_ValidateAttributes extends HTMLPurifier_Strategy
|
|||||||
|
|
||||||
// create alias to global definition array, see also $defs
|
// create alias to global definition array, see also $defs
|
||||||
// DEFINITION CALL
|
// DEFINITION CALL
|
||||||
$d_defs = $this->definition->info_global_attr;
|
$d_defs = $definition->info_global_attr;
|
||||||
|
|
||||||
foreach ($tokens as $key => $token) {
|
foreach ($tokens as $key => $token) {
|
||||||
|
|
||||||
@ -50,14 +46,14 @@ class HTMLPurifier_Strategy_ValidateAttributes extends HTMLPurifier_Strategy
|
|||||||
// do global transformations (pre)
|
// do global transformations (pre)
|
||||||
// ex. <ELEMENT lang="fr"> to <ELEMENT lang="fr" xml:lang="fr">
|
// ex. <ELEMENT lang="fr"> to <ELEMENT lang="fr" xml:lang="fr">
|
||||||
// DEFINITION CALL
|
// DEFINITION CALL
|
||||||
foreach ($this->definition->info_attr_transform_pre as $transform) {
|
foreach ($definition->info_attr_transform_pre as $transform) {
|
||||||
$attr = $transform->transform($attr, $config);
|
$attr = $transform->transform($attr, $config);
|
||||||
}
|
}
|
||||||
|
|
||||||
// do local transformations only applicable to this element (pre)
|
// do local transformations only applicable to this element (pre)
|
||||||
// ex. <p align="right"> to <p style="text-align:right;">
|
// ex. <p align="right"> to <p style="text-align:right;">
|
||||||
// DEFINITION CALL
|
// DEFINITION CALL
|
||||||
foreach ($this->definition->info[$token->name]->attr_transform_pre
|
foreach ($definition->info[$token->name]->attr_transform_pre
|
||||||
as $transform
|
as $transform
|
||||||
) {
|
) {
|
||||||
$attr = $transform->transform($attr, $config);
|
$attr = $transform->transform($attr, $config);
|
||||||
@ -66,7 +62,7 @@ class HTMLPurifier_Strategy_ValidateAttributes extends HTMLPurifier_Strategy
|
|||||||
// create alias to this element's attribute definition array, see
|
// create alias to this element's attribute definition array, see
|
||||||
// also $d_defs (global attribute definition array)
|
// also $d_defs (global attribute definition array)
|
||||||
// DEFINITION CALL
|
// DEFINITION CALL
|
||||||
$defs = $this->definition->info[$token->name]->attr;
|
$defs = $definition->info[$token->name]->attr;
|
||||||
|
|
||||||
// iterate through all the attribute keypairs
|
// iterate through all the attribute keypairs
|
||||||
// Watch out for name collisions: $key has previously been used
|
// Watch out for name collisions: $key has previously been used
|
||||||
@ -116,10 +112,10 @@ class HTMLPurifier_Strategy_ValidateAttributes extends HTMLPurifier_Strategy
|
|||||||
}
|
}
|
||||||
|
|
||||||
// post transforms
|
// post transforms
|
||||||
foreach ($this->definition->info_attr_transform_post as $transform) {
|
foreach ($definition->info_attr_transform_post as $transform) {
|
||||||
$attr = $transform->transform($attr, $config);
|
$attr = $transform->transform($attr, $config);
|
||||||
}
|
}
|
||||||
foreach ($this->definition->info[$token->name]->attr_transform_post as $transform) {
|
foreach ($definition->info[$token->name]->attr_transform_post as $transform) {
|
||||||
$attr = $transform->transform($attr, $config);
|
$attr = $transform->transform($attr, $config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ class HTMLPurifier_AttrDef_BorderTest extends HTMLPurifier_AttrDef_PixelsTest
|
|||||||
|
|
||||||
function test() {
|
function test() {
|
||||||
|
|
||||||
$this->def = new HTMLPurifier_AttrDef_Border();
|
$this->def = new HTMLPurifier_AttrDef_Border(HTMLPurifier_Config::createDefault());
|
||||||
|
|
||||||
$this->assertDef('thick solid red', 'thick solid #F00');
|
$this->assertDef('thick solid red', 'thick solid #F00');
|
||||||
$this->assertDef('thick solid');
|
$this->assertDef('thick solid');
|
||||||
|
@ -8,7 +8,7 @@ class HTMLPurifier_AttrDef_FontTest extends HTMLPurifier_AttrDefHarness
|
|||||||
|
|
||||||
function test() {
|
function test() {
|
||||||
|
|
||||||
$this->def = new HTMLPurifier_AttrDef_Font();
|
$this->def = new HTMLPurifier_AttrDef_Font(HTMLPurifier_Config::createDefault());
|
||||||
|
|
||||||
// hodgepodge of usage cases from W3C spec, but " -> '
|
// hodgepodge of usage cases from W3C spec, but " -> '
|
||||||
$this->assertDef('12px/14px sans-serif');
|
$this->assertDef('12px/14px sans-serif');
|
||||||
|
@ -8,7 +8,7 @@ class HTMLPurifier_AttrDef_ListStyleTest extends HTMLPurifier_AttrDefHarness
|
|||||||
|
|
||||||
function test() {
|
function test() {
|
||||||
|
|
||||||
$this->def = new HTMLPurifier_AttrDef_ListStyle();
|
$this->def = new HTMLPurifier_AttrDef_ListStyle(HTMLPurifier_Config::createDefault());
|
||||||
|
|
||||||
$this->assertDef('lower-alpha');
|
$this->assertDef('lower-alpha');
|
||||||
$this->assertDef('upper-roman inside');
|
$this->assertDef('upper-roman inside');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user