2007-02-04 00:07:52 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once 'HTMLPurifier/HTMLDefinition.php';
|
|
|
|
|
|
|
|
require_once 'HTMLPurifier/AttrTypes.php';
|
|
|
|
require_once 'HTMLPurifier/AttrCollection.php';
|
2007-02-04 01:52:13 +00:00
|
|
|
|
2007-02-04 00:07:52 +00:00
|
|
|
require_once 'HTMLPurifier/HTMLModule.php';
|
|
|
|
require_once 'HTMLPurifier/HTMLModule/Text.php';
|
2007-02-04 01:01:27 +00:00
|
|
|
require_once 'HTMLPurifier/HTMLModule/Hypertext.php';
|
2007-02-04 01:52:13 +00:00
|
|
|
require_once 'HTMLPurifier/HTMLModule/List.php';
|
2007-02-04 00:07:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Next-generation HTML definition that will supplant HTMLPurifier_HTMLDefinition
|
|
|
|
*/
|
|
|
|
class HTMLPurifier_XHTMLDefinition extends HTMLPurifier_HTMLDefinition
|
|
|
|
{
|
|
|
|
|
|
|
|
var $modules = array();
|
|
|
|
var $attr_types;
|
|
|
|
var $attr_collection;
|
2007-02-04 03:53:57 +00:00
|
|
|
var $content_sets;
|
2007-02-04 00:07:52 +00:00
|
|
|
|
2007-02-04 03:53:57 +00:00
|
|
|
function HTMLPurifier_XHTMLDefinition($config) {
|
2007-02-04 00:07:52 +00:00
|
|
|
|
|
|
|
$this->modules['Text'] = new HTMLPurifier_HTMLModule_Text();
|
2007-02-04 01:01:27 +00:00
|
|
|
$this->modules['Hypertext'] = new HTMLPurifier_HTMLModule_Hypertext();
|
2007-02-04 01:52:13 +00:00
|
|
|
$this->modules['List'] = new HTMLPurifier_HTMLModule_List();
|
2007-02-04 00:07:52 +00:00
|
|
|
|
|
|
|
$this->attr_types = new HTMLPurifier_AttrTypes();
|
|
|
|
$this->attr_collection = new HTMLPurifier_AttrCollection();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function setup($config) {
|
|
|
|
|
|
|
|
// perform attribute collection substitutions
|
|
|
|
$this->attr_collection->setup($this->attr_types, $this->modules);
|
|
|
|
|
|
|
|
// populate content_sets based on module hints
|
|
|
|
$content_sets = array();
|
|
|
|
foreach ($this->modules as $module_i => $module) {
|
|
|
|
foreach ($module->content_sets as $key => $value) {
|
|
|
|
if (isset($content_sets[$key])) {
|
|
|
|
// add it into the existing content set
|
|
|
|
$content_sets[$key] = $content_sets[$key] . ' | ' . $value;
|
|
|
|
} else {
|
|
|
|
$content_sets[$key] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-02-04 03:53:57 +00:00
|
|
|
|
2007-02-04 00:07:52 +00:00
|
|
|
// perform content_set expansions
|
|
|
|
foreach ($content_sets as $i => $set) {
|
|
|
|
// only performed once, so infinite recursion is not
|
|
|
|
// a problem, you'll just have a stray $Set lying around
|
|
|
|
// at the end
|
|
|
|
$content_sets[$i] =
|
|
|
|
str_replace(
|
|
|
|
array_keys($content_sets),
|
|
|
|
array_values($content_sets),
|
|
|
|
$set);
|
|
|
|
}
|
2007-02-04 03:53:57 +00:00
|
|
|
// define convenient variables
|
2007-02-04 00:07:52 +00:00
|
|
|
$content_sets_keys = array_keys($content_sets);
|
|
|
|
$content_sets_values = array_values($content_sets);
|
2007-02-04 03:53:57 +00:00
|
|
|
foreach ($content_sets as $name => $set) {
|
|
|
|
$this->content_sets[$name] = $this->convertToLookup($set);
|
|
|
|
}
|
2007-02-04 00:07:52 +00:00
|
|
|
|
|
|
|
foreach ($this->modules as $module_i => $module) {
|
2007-02-04 03:53:57 +00:00
|
|
|
foreach ($module->info as $name => $def) {
|
|
|
|
$def =& $this->modules[$module_i]->info[$name];
|
2007-02-04 00:07:52 +00:00
|
|
|
|
|
|
|
// attribute value expansions
|
2007-02-04 03:53:57 +00:00
|
|
|
$this->attr_collection->performInclusions($def->attr);
|
2007-02-04 01:01:27 +00:00
|
|
|
$this->attr_collection->expandStringIdentifiers(
|
2007-02-04 03:53:57 +00:00
|
|
|
$def->attr, $this->attr_types);
|
2007-02-04 00:07:52 +00:00
|
|
|
|
|
|
|
// perform content model expansions
|
2007-02-04 03:53:57 +00:00
|
|
|
$content_model = $def->content_model;
|
2007-02-04 00:07:52 +00:00
|
|
|
if (is_string($content_model)) {
|
2007-02-04 03:53:57 +00:00
|
|
|
if (strpos($content_model, 'Inline') !== false) {
|
|
|
|
$def->descendants_are_inline = true;
|
|
|
|
}
|
|
|
|
$def->content_model = str_replace(
|
2007-02-04 00:07:52 +00:00
|
|
|
$content_sets_keys, $content_sets_values, $content_model);
|
|
|
|
}
|
|
|
|
|
2007-02-04 01:01:27 +00:00
|
|
|
// get child def from content model
|
2007-02-04 03:53:57 +00:00
|
|
|
$def->child = $this->getChildDef($def);
|
2007-02-04 01:01:27 +00:00
|
|
|
|
2007-02-04 00:07:52 +00:00
|
|
|
// setup info
|
2007-02-04 03:53:57 +00:00
|
|
|
$this->info[$name] = $def;
|
|
|
|
if ($this->info_parent == $name) {
|
|
|
|
$this->info_parent_def = $this->info[$name];
|
2007-02-04 00:07:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-02-04 03:53:57 +00:00
|
|
|
function getChildDef($def) {
|
|
|
|
$value = $def->content_model;
|
|
|
|
$type = $def->content_model_type;
|
2007-02-04 00:07:52 +00:00
|
|
|
switch ($type) {
|
|
|
|
case 'required':
|
|
|
|
return new HTMLPurifier_ChildDef_Required($value);
|
|
|
|
case 'optional':
|
|
|
|
return new HTMLPurifier_ChildDef_Optional($value);
|
|
|
|
case 'empty':
|
|
|
|
return new HTMLPurifier_ChildDef_Empty();
|
|
|
|
case 'strictblockquote':
|
2007-02-04 03:53:57 +00:00
|
|
|
return new HTMLPurifier_ChildDef_StrictBlockquote($value);
|
2007-02-04 00:07:52 +00:00
|
|
|
case 'table':
|
|
|
|
return new HTMLPurifier_ChildDef_Table();
|
|
|
|
case 'chameleon':
|
|
|
|
return new HTMLPurifier_ChildDef_Chameleon($value[0], $value[1]);
|
|
|
|
case 'custom':
|
|
|
|
return new HTMLPurifier_ChildDef_Custom($value);
|
|
|
|
}
|
2007-02-04 01:52:13 +00:00
|
|
|
if ($value) return new HTMLPurifier_ChildDef_Optional($value);
|
2007-02-04 00:07:52 +00:00
|
|
|
return HTMLPurifier_ChildDef_Empty();
|
|
|
|
}
|
|
|
|
|
2007-02-04 03:53:57 +00:00
|
|
|
function convertToLookup($string) {
|
|
|
|
$array = explode('|', str_replace(' ', '', $string));
|
|
|
|
foreach ($array as $i => $k) {
|
|
|
|
$array[$i] = true;
|
|
|
|
}
|
|
|
|
return $array;
|
|
|
|
}
|
|
|
|
|
2007-02-04 00:07:52 +00:00
|
|
|
}
|
|
|
|
|
2007-02-04 03:53:57 +00:00
|
|
|
?>
|