2006-07-23 00:11:03 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once 'HTMLPurifier/AttrDef.php';
|
2006-07-30 18:37:42 +00:00
|
|
|
require_once 'HTMLPurifier/AttrDef/Enum.php';
|
|
|
|
require_once 'HTMLPurifier/AttrDef/ID.php';
|
2006-07-23 00:11:03 +00:00
|
|
|
require_once 'HTMLPurifier/ChildDef.php';
|
|
|
|
require_once 'HTMLPurifier/Generator.php';
|
|
|
|
require_once 'HTMLPurifier/Token.php';
|
2006-08-02 02:24:03 +00:00
|
|
|
require_once 'HTMLPurifier/TagTransform.php';
|
2006-07-23 00:11:03 +00:00
|
|
|
|
2006-07-30 22:57:54 +00:00
|
|
|
/**
|
|
|
|
* Defines the purified HTML type with large amounts of objects.
|
|
|
|
*
|
|
|
|
* The main function of this object is its $info array, which is an
|
|
|
|
* associative array of all the child and attribute definitions for
|
|
|
|
* each allowed element. It also contains special use information (always
|
|
|
|
* prefixed by info) for intelligent tag closing and global attributes.
|
|
|
|
*
|
|
|
|
* Planned improvements include attribute transformation objects as well as
|
|
|
|
* migration of auto-tag-closing from HTMLPurifier_Strategy_MakeWellFormed
|
|
|
|
* (these can likely just be extensions of ElementDef).
|
|
|
|
*
|
|
|
|
* After development drops off, the definition generation will be moved to
|
|
|
|
* a maintenance script and we will stipulate that definition be created
|
|
|
|
* by a factory method that unserializes a serialized version of Definition.
|
|
|
|
* Customization would entail copying the maintenance script, making the
|
|
|
|
* necessary changes, generating the serialized object, and then hooking it
|
|
|
|
* in via the factory method. We would also offer a LiveDefinition for
|
|
|
|
* automatic recompilation, suggesting that we would have a DefinitionGenerator.
|
|
|
|
*/
|
|
|
|
|
2006-07-23 00:11:03 +00:00
|
|
|
class HTMLPurifier_Definition
|
|
|
|
{
|
|
|
|
|
|
|
|
var $info = array();
|
2006-07-30 22:57:54 +00:00
|
|
|
|
|
|
|
// used solely by HTMLPurifier_Strategy_ValidateAttributes
|
2006-07-30 19:11:18 +00:00
|
|
|
var $info_global_attr = array();
|
2006-07-23 00:11:03 +00:00
|
|
|
|
2006-07-30 22:57:54 +00:00
|
|
|
// used solely by HTMLPurifier_Strategy_FixNesting
|
|
|
|
var $info_parent = 'div';
|
|
|
|
|
2006-08-02 02:24:03 +00:00
|
|
|
// used solely by HTMLPurifier_Strategy_RemoveForeignElements
|
|
|
|
var $info_tag_transform = array();
|
|
|
|
|
2006-07-24 02:49:37 +00:00
|
|
|
function instance() {
|
|
|
|
static $instance = null;
|
|
|
|
if (!$instance) {
|
|
|
|
$instance = new HTMLPurifier_Definition();
|
2006-07-24 11:35:46 +00:00
|
|
|
$instance->setup();
|
2006-07-24 02:49:37 +00:00
|
|
|
}
|
|
|
|
return $instance;
|
|
|
|
}
|
|
|
|
|
2006-07-24 11:35:46 +00:00
|
|
|
function HTMLPurifier_Definition() {}
|
2006-07-23 00:11:03 +00:00
|
|
|
|
2006-07-24 11:35:46 +00:00
|
|
|
function setup() {
|
2006-07-31 00:15:01 +00:00
|
|
|
|
2006-07-23 00:11:03 +00:00
|
|
|
// emulates the structure of the DTD
|
2006-07-31 00:15:01 +00:00
|
|
|
// these are condensed, however, with bad stuff taken out
|
|
|
|
// screening process was done by hand
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// info[] : initializes the definition objects
|
|
|
|
|
|
|
|
// if you attempt to define rules later on for a tag not in this array
|
|
|
|
// PHP will create an stdclass
|
2006-07-23 00:11:03 +00:00
|
|
|
|
2006-07-30 19:11:18 +00:00
|
|
|
$allowed_tags =
|
|
|
|
array(
|
|
|
|
'ins', 'del', 'blockquote', 'dd', 'li', 'div', 'em', 'strong',
|
|
|
|
'dfn', 'code', 'samp', 'kbd', 'var', 'cite', 'abbr', 'acronym',
|
|
|
|
'q', 'sub', 'tt', 'sup', 'i', 'b', 'big', 'small', 'u', 's',
|
|
|
|
'strike', 'bdo', 'span', 'dt', 'p', 'h1', 'h2', 'h3', 'h4',
|
|
|
|
'h5', 'h6', 'ol', 'ul', 'dl', 'address', 'img', 'br', 'hr',
|
2006-07-31 00:15:01 +00:00
|
|
|
'pre', 'a', 'table', 'caption', 'thead', 'tfoot', 'tbody',
|
|
|
|
'colgroup', 'col', 'td', 'th', 'tr'
|
2006-07-30 19:11:18 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($allowed_tags as $tag) {
|
|
|
|
$this->info[$tag] = new HTMLPurifier_ElementDef();
|
|
|
|
}
|
|
|
|
|
2006-07-31 00:15:01 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// info[]->child : defines allowed children for elements
|
|
|
|
|
2006-07-23 00:11:03 +00:00
|
|
|
// entities: prefixed with e_ and _ replaces .
|
2006-07-31 00:15:01 +00:00
|
|
|
|
2006-07-23 00:11:03 +00:00
|
|
|
// we don't use an array because that complicates interpolation
|
|
|
|
// strings are used instead of arrays because if you use arrays,
|
|
|
|
// you have to do some hideous manipulation with array_merge()
|
|
|
|
|
|
|
|
$e_special_extra = 'img';
|
|
|
|
$e_special_basic = 'br | span | bdo';
|
|
|
|
$e_special = "$e_special_basic | $e_special_extra";
|
|
|
|
$e_fontstyle_extra = 'big | small';
|
|
|
|
$e_fontstyle_basic = 'tt | i | b | u | s | strike';
|
|
|
|
$e_fontstyle = "$e_fontstyle_basic | $e_fontstyle_extra";
|
|
|
|
$e_phrase_extra = 'sub | sup';
|
|
|
|
$e_phrase_basic = 'em | strong | dfn | code | q | samp | kbd | var'.
|
|
|
|
' | cite | abbr | acronym';
|
|
|
|
$e_phrase = "$e_phrase_basic | $e_phrase_extra";
|
|
|
|
$e_inline_forms = ''; // humor the dtd
|
|
|
|
$e_misc_inline = 'ins | del';
|
|
|
|
$e_misc = "$e_misc_inline";
|
|
|
|
$e_inline = "a | $e_special | $e_fontstyle | $e_phrase".
|
|
|
|
" | $e_inline_forms";
|
|
|
|
// note the casing
|
|
|
|
$e_Inline = new HTMLPurifier_ChildDef_Optional("#PCDATA | $e_inline".
|
|
|
|
" | $e_misc_inline");
|
|
|
|
$e_heading = 'h1|h2|h3|h4|h5|h6';
|
|
|
|
$e_lists = 'ul | ol | dl';
|
|
|
|
$e_blocktext = 'pre | hr | blockquote | address';
|
|
|
|
$e_block = "p | $e_heading | div | $e_lists | $e_blocktext | table";
|
|
|
|
$e_Flow = new HTMLPurifier_ChildDef_Optional("#PCDATA | $e_block".
|
|
|
|
" | $e_inline | $e_misc");
|
|
|
|
$e_a_content = new HTMLPurifier_ChildDef_Optional("#PCDATA | $e_special".
|
|
|
|
" | $e_fontstyle | $e_phrase | $e_inline_forms | $e_misc_inline");
|
|
|
|
$e_pre_content = new HTMLPurifier_ChildDef_Optional("#PCDATA | a".
|
|
|
|
" | $e_special_basic | $e_fontstyle_basic | $e_phrase_basic".
|
|
|
|
" | $e_inline_forms | $e_misc_inline");
|
|
|
|
$e_form_content = new HTMLPurifier_ChildDef_Optional(''); //unused
|
|
|
|
$e_form_button_content = new HTMLPurifier_ChildDef_Optional(''); // unused
|
|
|
|
|
2006-07-30 19:11:18 +00:00
|
|
|
$this->info['ins']->child =
|
|
|
|
$this->info['del']->child =
|
2006-07-31 00:15:01 +00:00
|
|
|
$this->info['blockquote']->child=
|
2006-07-30 19:11:18 +00:00
|
|
|
$this->info['dd']->child =
|
|
|
|
$this->info['li']->child =
|
|
|
|
$this->info['div']->child = $e_Flow;
|
|
|
|
|
|
|
|
$this->info['em']->child =
|
2006-07-31 00:15:01 +00:00
|
|
|
$this->info['strong']->child =
|
2006-07-30 19:11:18 +00:00
|
|
|
$this->info['dfn']->child =
|
|
|
|
$this->info['code']->child =
|
|
|
|
$this->info['samp']->child =
|
|
|
|
$this->info['kbd']->child =
|
|
|
|
$this->info['var']->child =
|
|
|
|
$this->info['cite']->child =
|
|
|
|
$this->info['abbr']->child =
|
2006-07-31 00:15:01 +00:00
|
|
|
$this->info['acronym']->child =
|
2006-07-30 19:11:18 +00:00
|
|
|
$this->info['q']->child =
|
|
|
|
$this->info['sub']->child =
|
|
|
|
$this->info['tt']->child =
|
|
|
|
$this->info['sup']->child =
|
|
|
|
$this->info['i']->child =
|
|
|
|
$this->info['b']->child =
|
|
|
|
$this->info['big']->child =
|
2006-07-31 00:15:01 +00:00
|
|
|
$this->info['small']->child=
|
2006-07-30 19:11:18 +00:00
|
|
|
$this->info['u']->child =
|
|
|
|
$this->info['s']->child =
|
2006-07-31 00:15:01 +00:00
|
|
|
$this->info['strike']->child =
|
2006-07-30 19:11:18 +00:00
|
|
|
$this->info['bdo']->child =
|
|
|
|
$this->info['span']->child =
|
|
|
|
$this->info['dt']->child =
|
|
|
|
$this->info['p']->child =
|
|
|
|
$this->info['h1']->child =
|
|
|
|
$this->info['h2']->child =
|
|
|
|
$this->info['h3']->child =
|
|
|
|
$this->info['h4']->child =
|
|
|
|
$this->info['h5']->child =
|
|
|
|
$this->info['h6']->child = $e_Inline;
|
|
|
|
|
2006-07-31 00:15:01 +00:00
|
|
|
// the only three required definitions, besides custom table code
|
2006-07-30 19:11:18 +00:00
|
|
|
$this->info['ol']->child =
|
|
|
|
$this->info['ul']->child = new HTMLPurifier_ChildDef_Required('li');
|
|
|
|
|
|
|
|
$this->info['dl']->child = new HTMLPurifier_ChildDef_Required('dt|dd');
|
2006-07-31 00:15:01 +00:00
|
|
|
|
2006-07-30 19:11:18 +00:00
|
|
|
$this->info['address']->child =
|
2006-07-30 00:54:38 +00:00
|
|
|
new HTMLPurifier_ChildDef_Optional("#PCDATA | p | $e_inline".
|
|
|
|
" | $e_misc_inline");
|
2006-07-23 00:11:03 +00:00
|
|
|
|
2006-07-30 19:11:18 +00:00
|
|
|
$this->info['img']->child =
|
|
|
|
$this->info['br']->child =
|
|
|
|
$this->info['hr']->child = new HTMLPurifier_ChildDef_Empty();
|
2006-07-23 00:11:03 +00:00
|
|
|
|
2006-07-30 19:11:18 +00:00
|
|
|
$this->info['pre']->child = $e_pre_content;
|
2006-07-30 00:54:38 +00:00
|
|
|
|
2006-07-30 19:11:18 +00:00
|
|
|
$this->info['a']->child = $e_a_content;
|
2006-07-23 00:11:03 +00:00
|
|
|
|
2006-07-31 03:04:57 +00:00
|
|
|
$this->info['table']->child = new HTMLPurifier_ChildDef_Custom(
|
2006-07-31 00:15:01 +00:00
|
|
|
'(caption?, (col*|colgroup*), thead?, tfoot?, (tbody+|tr+))');
|
|
|
|
|
|
|
|
// not a real entity, watch the double underscore
|
|
|
|
$e__row = new HTMLPurifier_ChildDef_Required('tr');
|
|
|
|
$this->info['thead']->child = $e__row;
|
|
|
|
$this->info['tfoot']->child = $e__row;
|
|
|
|
$this->info['tbody']->child = $e__row;
|
|
|
|
$this->info['colgroup']->child = new HTMLPurifier_ChildDef_Optional('col');
|
|
|
|
$this->info['col']->child = new HTMLPurifier_ChildDef_Empty();
|
|
|
|
$this->info['tr']->child = new HTMLPurifier_ChildDef_Required('th | td');
|
|
|
|
$this->info['th']->child = $e_Flow;
|
|
|
|
$this->info['td']->child = $e_Flow;
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// info[]->attr : defines allowed attributes for elements
|
|
|
|
|
2006-07-30 18:37:42 +00:00
|
|
|
// this doesn't include REQUIRED declarations, those are handled
|
|
|
|
// by the transform classes
|
|
|
|
|
|
|
|
// attrs, included in almost every single one except for a few
|
2006-07-30 19:11:18 +00:00
|
|
|
$this->info_global_attr = array(
|
2006-07-30 18:37:42 +00:00
|
|
|
// core attrs
|
|
|
|
'id' => new HTMLPurifier_AttrDef_ID(),
|
|
|
|
// i18n
|
|
|
|
'dir' => new HTMLPurifier_AttrDef_Enum(array('ltr','rtl'), false),
|
|
|
|
);
|
2006-07-30 15:29:22 +00:00
|
|
|
|
2006-07-31 00:15:01 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// UNIMP : info_tag_transform : transformations of tags
|
|
|
|
|
2006-08-03 00:14:10 +00:00
|
|
|
$this->info_tag_transform['font'] = new HTMLPurifier_TagTransform_Font();
|
2006-08-02 02:24:03 +00:00
|
|
|
$this->info_tag_transform['menu'] = new HTMLPurifier_TagTransform_Simple('ul');
|
|
|
|
$this->info_tag_transform['dir'] = new HTMLPurifier_TagTransform_Simple('ul');
|
|
|
|
$this->info_tag_transform['center'] = new HTMLPurifier_TagTransform_Center();
|
|
|
|
|
2006-07-31 00:15:01 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// info[]->auto_close : tags that automatically close another
|
|
|
|
|
|
|
|
// these are all block elements: blocks aren't allowed in P
|
|
|
|
$this->info['p']->auto_close = array_flip(array(
|
|
|
|
'address', 'blockquote', 'dd', 'dir', 'div', 'dl', 'dt',
|
|
|
|
'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'ol', 'p', 'pre',
|
|
|
|
'table', 'ul'
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->info['li']->auto_close = array('li' => true);
|
|
|
|
|
|
|
|
// we need TABLE and heading mismatch code
|
|
|
|
// we may need to make this more flexible for heading mismatch,
|
|
|
|
// or we can just create another info
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// UNIMP : info[]->attr_transform : attribute transformations in elements
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// UNIMP : info_attr_transform : global attribute transform (for xml:lang)
|
|
|
|
|
|
|
|
// this might have bad implications for performance
|
|
|
|
|
2006-07-23 00:11:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class HTMLPurifier_ElementDef
|
|
|
|
{
|
|
|
|
|
2006-07-30 19:11:18 +00:00
|
|
|
var $attr = array();
|
2006-07-31 00:15:01 +00:00
|
|
|
var $auto_close = array();
|
|
|
|
var $child;
|
2006-07-23 00:11:03 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-04-16 03:00:05 +00:00
|
|
|
?>
|