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-08-04 03:13:04 +00:00
|
|
|
require_once 'HTMLPurifier/AttrDef/Class.php';
|
|
|
|
require_once 'HTMLPurifier/AttrDef/Text.php';
|
2006-08-05 02:56:57 +00:00
|
|
|
require_once 'HTMLPurifier/AttrDef/Lang.php';
|
2006-08-06 01:03:48 +00:00
|
|
|
require_once 'HTMLPurifier/AttrDef/Pixels.php';
|
2006-08-06 01:30:54 +00:00
|
|
|
require_once 'HTMLPurifier/AttrDef/Length.php';
|
2006-08-06 01:41:18 +00:00
|
|
|
require_once 'HTMLPurifier/AttrDef/MultiLength.php';
|
2006-08-20 21:47:15 +00:00
|
|
|
require_once 'HTMLPurifier/AttrDef/Integer.php';
|
2006-08-12 19:22:57 +00:00
|
|
|
require_once 'HTMLPurifier/AttrDef/URI.php';
|
2006-08-14 00:27:15 +00:00
|
|
|
require_once 'HTMLPurifier/AttrDef/CSS.php';
|
2006-08-05 02:56:57 +00:00
|
|
|
require_once 'HTMLPurifier/AttrTransform.php';
|
|
|
|
require_once 'HTMLPurifier/AttrTransform/Lang.php';
|
|
|
|
require_once 'HTMLPurifier/AttrTransform/TextAlign.php';
|
2006-08-14 23:11:28 +00:00
|
|
|
require_once 'HTMLPurifier/AttrTransform/BdoDir.php';
|
|
|
|
require_once 'HTMLPurifier/AttrTransform/ImgRequired.php';
|
2006-07-23 00:11:03 +00:00
|
|
|
require_once 'HTMLPurifier/ChildDef.php';
|
2006-11-22 18:55:15 +00:00
|
|
|
require_once 'HTMLPurifier/ChildDef/Chameleon.php';
|
|
|
|
require_once 'HTMLPurifier/ChildDef/Empty.php';
|
|
|
|
require_once 'HTMLPurifier/ChildDef/Required.php';
|
|
|
|
require_once 'HTMLPurifier/ChildDef/Optional.php';
|
|
|
|
require_once 'HTMLPurifier/ChildDef/Table.php';
|
2006-11-23 03:23:35 +00:00
|
|
|
require_once 'HTMLPurifier/ChildDef/StrictBlockquote.php';
|
2006-07-23 00:11:03 +00:00
|
|
|
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-11-17 01:05:41 +00:00
|
|
|
HTMLPurifier_ConfigSchema::define(
|
|
|
|
'HTML', 'EnableAttrID', false, 'bool',
|
|
|
|
'Allows the ID attribute in HTML. This is disabled by default '.
|
|
|
|
'due to the fact that without proper configuration user input can '.
|
|
|
|
'easily break the validation of a webpage by specifying an ID that is '.
|
|
|
|
'already on the surrounding HTML. If you don\'t mind throwing caution to '.
|
|
|
|
'the wind, enable this directive, but I strongly recommend you also '.
|
|
|
|
'consider blacklisting IDs you use (%Attr.IDBlacklist) or prefixing all '.
|
|
|
|
'user supplied IDs (%Attr.IDPrefix). This directive has been available '.
|
|
|
|
'since 1.2.0, and when set to true reverts to the behavior of pre-1.2.0 '.
|
|
|
|
'versions.'
|
|
|
|
);
|
|
|
|
|
2006-11-22 18:17:39 +00:00
|
|
|
HTMLPurifier_ConfigSchema::define(
|
|
|
|
'HTML', 'Strict', false, 'bool',
|
|
|
|
'Determines whether or not to use Transitional (loose) or Strict rulesets.'
|
|
|
|
);
|
|
|
|
|
2006-11-23 03:23:35 +00:00
|
|
|
HTMLPurifier_ConfigSchema::define(
|
|
|
|
'HTML', 'BlockWrapper', 'p', 'string',
|
|
|
|
'String name of element to wrap inline elements that are inside a block '.
|
|
|
|
'context. This only occurs in the children of blockquote in strict mode. '.
|
|
|
|
'Example: by default value, <code><blockquote>Foo</blockquote></code> '.
|
|
|
|
'would become <code><blockquote><p>Foo</p></blockquote></code>. The '.
|
|
|
|
'<code><p></code> tags can be replaced '.
|
|
|
|
'with whatever you desire, as long as it is a block level element.'
|
|
|
|
);
|
|
|
|
|
|
|
|
HTMLPurifier_ConfigSchema::define(
|
|
|
|
'HTML', 'Parent', 'div', 'string',
|
|
|
|
'String name of element that HTML fragment passed to library will be '.
|
|
|
|
'inserted in. An interesting variation would be using span as the '.
|
|
|
|
'parent element, meaning that only inline tags would be allowed.'
|
|
|
|
);
|
|
|
|
|
2006-11-23 13:51:19 +00:00
|
|
|
HTMLPurifier_ConfigSchema::define(
|
|
|
|
'HTML', 'AllowedElements', null, 'lookup/null',
|
|
|
|
'If HTML Purifier\'s tag set is unsatisfactory for your needs, you '.
|
|
|
|
'can overload it with your own list of tags to allow. Note that this '.
|
|
|
|
'method is subtractive: it does its job by taking away from HTML Purifier '.
|
|
|
|
'usual feature set, so you cannot add a tag that HTML Purifier never '.
|
|
|
|
'supported in the first place (like embed). If you change this, you '.
|
|
|
|
'probably also want to change %HTML.AllowedAttributes. '.
|
|
|
|
'<strong>Warning:</strong> If another directive conflicts with the '.
|
|
|
|
'elements here, <em>that</em> directive will win and override.'
|
|
|
|
);
|
|
|
|
|
|
|
|
HTMLPurifier_ConfigSchema::define(
|
|
|
|
'HTML', 'AllowedAttributes', null, 'lookup/null',
|
|
|
|
'IF HTML Purifier\'s attribute set is unsatisfactory, overload it! '.
|
|
|
|
'The syntax is \'tag.attr\' or \'*.attr\' for the global attributes '.
|
|
|
|
'(style, id, class, dir, lang, xml:lang).'.
|
|
|
|
'<strong>Warning:</strong> If another directive conflicts with the '.
|
|
|
|
'elements here, <em>that</em> directive will win and override. For '.
|
|
|
|
'example, %HTML.EnableAttrID will take precedence over *.id in this '.
|
|
|
|
'directive. You must set that directive to true before you can use '.
|
|
|
|
'IDs at all.'
|
|
|
|
);
|
|
|
|
|
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.
|
|
|
|
*
|
2006-08-20 20:59:13 +00:00
|
|
|
* For optimization, the definition generation may be moved to
|
|
|
|
* a maintenance script and stipulate that definition be created
|
2006-07-30 22:57:54 +00:00
|
|
|
* 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-08-14 21:22:49 +00:00
|
|
|
class HTMLPurifier_HTMLDefinition
|
2006-07-23 00:11:03 +00:00
|
|
|
{
|
|
|
|
|
2006-08-20 20:59:13 +00:00
|
|
|
/**
|
|
|
|
* Associative array of element names to HTMLPurifier_ElementDef
|
|
|
|
* @public
|
|
|
|
*/
|
2006-07-23 00:11:03 +00:00
|
|
|
var $info = array();
|
2006-07-30 22:57:54 +00:00
|
|
|
|
2006-08-20 20:59:13 +00:00
|
|
|
/**
|
|
|
|
* Associative array of global attribute name to attribute definition.
|
|
|
|
* @public
|
|
|
|
*/
|
2006-07-30 19:11:18 +00:00
|
|
|
var $info_global_attr = array();
|
2006-07-23 00:11:03 +00:00
|
|
|
|
2006-08-20 20:59:13 +00:00
|
|
|
/**
|
|
|
|
* String name of parent element HTML will be going into.
|
|
|
|
* @public
|
|
|
|
*/
|
2006-07-30 22:57:54 +00:00
|
|
|
var $info_parent = 'div';
|
|
|
|
|
2006-11-23 13:51:19 +00:00
|
|
|
/**
|
|
|
|
* Definition for parent element, allows parent element to be a
|
|
|
|
* tag that's not allowed inside the HTML fragment.
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
var $info_parent_def;
|
|
|
|
|
2006-11-23 03:23:35 +00:00
|
|
|
/**
|
|
|
|
* String name of element used to wrap inline elements in block context
|
|
|
|
* @note This is rarely used except for BLOCKQUOTEs in strict mode
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
var $info_block_wrapper = 'p';
|
|
|
|
|
2006-08-20 20:59:13 +00:00
|
|
|
/**
|
|
|
|
* Associative array of deprecated tag name to HTMLPurifier_TagTransform
|
|
|
|
* @public
|
|
|
|
*/
|
2006-08-02 02:24:03 +00:00
|
|
|
var $info_tag_transform = array();
|
|
|
|
|
2006-08-20 20:59:13 +00:00
|
|
|
/**
|
|
|
|
* List of HTMLPurifier_AttrTransform to be performed before validation.
|
|
|
|
* @public
|
|
|
|
*/
|
2006-08-14 23:11:28 +00:00
|
|
|
var $info_attr_transform_pre = array();
|
2006-08-20 20:59:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* List of HTMLPurifier_AttrTransform to be performed after validation/
|
|
|
|
* @public
|
|
|
|
*/
|
2006-08-14 23:11:28 +00:00
|
|
|
var $info_attr_transform_post = array();
|
2006-08-05 01:50:13 +00:00
|
|
|
|
2006-11-23 03:23:35 +00:00
|
|
|
/**
|
|
|
|
* Lookup table of flow elements
|
|
|
|
*/
|
|
|
|
var $info_flow_elements = array();
|
|
|
|
|
2006-08-20 20:59:13 +00:00
|
|
|
/**
|
|
|
|
* Initializes the definition, the meat of the class.
|
|
|
|
*/
|
2006-08-31 20:33:07 +00:00
|
|
|
function setup($config) {
|
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',
|
2006-11-22 18:17:39 +00:00
|
|
|
'q', 'sub', 'tt', 'sup', 'i', 'b', 'big', 'small',
|
|
|
|
'bdo', 'span', 'dt', 'p', 'h1', 'h2', 'h3', 'h4',
|
2006-07-30 19:11:18 +00:00
|
|
|
'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
|
|
|
);
|
|
|
|
|
2006-11-22 18:17:39 +00:00
|
|
|
if (!$config->get('HTML', 'Strict')) {
|
|
|
|
$allowed_tags[] = 'u';
|
|
|
|
$allowed_tags[] = 's';
|
|
|
|
$allowed_tags[] = 'strike';
|
|
|
|
}
|
|
|
|
|
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-09-22 02:47:41 +00:00
|
|
|
// entities: prefixed with e_ and _ replaces . from DTD
|
|
|
|
// double underlines are entities we made up
|
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()
|
|
|
|
|
2006-09-22 02:47:41 +00:00
|
|
|
// todo: determine whether or not having allowed children
|
|
|
|
// that aren't allowed globally affects security (it shouldn't)
|
|
|
|
// if above works out, extend children definitions to include all
|
|
|
|
// possible elements (allowed elements will dictate which ones
|
|
|
|
// get dropped
|
|
|
|
|
2006-07-23 00:11:03 +00:00
|
|
|
$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_misc_inline = 'ins | del';
|
|
|
|
$e_misc = "$e_misc_inline";
|
2006-11-23 03:23:35 +00:00
|
|
|
$e_inline = "a | $e_special | $e_fontstyle | $e_phrase";
|
2006-08-20 20:59:13 +00:00
|
|
|
// pseudo-property we created for convenience, see later on
|
2006-08-03 01:03:23 +00:00
|
|
|
$e__inline = "#PCDATA | $e_inline | $e_misc_inline";
|
2006-07-23 00:11:03 +00:00
|
|
|
// note the casing
|
2006-08-03 01:03:23 +00:00
|
|
|
$e_Inline = new HTMLPurifier_ChildDef_Optional($e__inline);
|
2006-07-23 00:11:03 +00:00
|
|
|
$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";
|
2006-11-22 18:17:39 +00:00
|
|
|
$e_Block = new HTMLPurifier_ChildDef_Optional($e_block);
|
2006-08-03 01:03:23 +00:00
|
|
|
$e__flow = "#PCDATA | $e_block | $e_inline | $e_misc";
|
|
|
|
$e_Flow = new HTMLPurifier_ChildDef_Optional($e__flow);
|
2006-09-22 02:47:41 +00:00
|
|
|
$e_a_content = new HTMLPurifier_ChildDef_Optional("#PCDATA".
|
2006-11-23 03:23:35 +00:00
|
|
|
" | $e_special | $e_fontstyle | $e_phrase | $e_misc_inline");
|
2006-07-23 00:11:03 +00:00
|
|
|
$e_pre_content = new HTMLPurifier_ChildDef_Optional("#PCDATA | a".
|
|
|
|
" | $e_special_basic | $e_fontstyle_basic | $e_phrase_basic".
|
2006-11-23 03:23:35 +00:00
|
|
|
" | $e_misc_inline");
|
2006-09-22 02:47:41 +00:00
|
|
|
$e_form_content = new HTMLPurifier_ChildDef_Optional('');//unused
|
|
|
|
$e_form_button_content = new HTMLPurifier_ChildDef_Optional('');//unused
|
2006-07-23 00:11:03 +00:00
|
|
|
|
2006-07-30 19:11:18 +00:00
|
|
|
$this->info['ins']->child =
|
2006-09-22 02:47:41 +00:00
|
|
|
$this->info['del']->child =
|
|
|
|
new HTMLPurifier_ChildDef_Chameleon($e__inline, $e__flow);
|
2006-08-03 01:03:23 +00:00
|
|
|
|
2006-07-30 19:11:18 +00:00
|
|
|
$this->info['dd']->child =
|
|
|
|
$this->info['li']->child =
|
|
|
|
$this->info['div']->child = $e_Flow;
|
|
|
|
|
2006-11-22 18:17:39 +00:00
|
|
|
if ($config->get('HTML', 'Strict')) {
|
2006-11-23 03:23:35 +00:00
|
|
|
$this->info['blockquote']->child = new HTMLPurifier_ChildDef_StrictBlockquote();
|
2006-11-22 18:17:39 +00:00
|
|
|
} else {
|
|
|
|
$this->info['blockquote']->child = $e_Flow;
|
|
|
|
}
|
|
|
|
|
2006-08-14 01:24:01 +00:00
|
|
|
$this->info['caption']->child =
|
2006-07-30 19:11:18 +00:00
|
|
|
$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-11-22 18:17:39 +00:00
|
|
|
if ($config->get('HTML', 'Strict')) {
|
2006-11-22 18:19:44 +00:00
|
|
|
$this->info['address']->child = $e_Inline;
|
2006-11-22 18:17:39 +00:00
|
|
|
} else {
|
|
|
|
$this->info['address']->child =
|
|
|
|
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-09-15 01:52:22 +00:00
|
|
|
$this->info['table']->child = new HTMLPurifier_ChildDef_Table();
|
2006-07-31 00:15:01 +00:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2006-08-03 01:03:23 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// info[]->type : defines the type of the element (block or inline)
|
|
|
|
|
2006-09-22 02:47:41 +00:00
|
|
|
// reuses $e_Inline and $e_Block
|
2006-11-04 05:03:53 +00:00
|
|
|
foreach ($e_Inline->elements as $name => $bool) {
|
2006-11-23 03:23:35 +00:00
|
|
|
if ($name == '#PCDATA') continue;
|
2006-08-03 01:03:23 +00:00
|
|
|
$this->info[$name]->type = 'inline';
|
|
|
|
}
|
|
|
|
|
2006-11-04 05:03:53 +00:00
|
|
|
foreach ($e_Block->elements as $name => $bool) {
|
2006-08-03 01:03:23 +00:00
|
|
|
$this->info[$name]->type = 'block';
|
|
|
|
}
|
|
|
|
|
2006-11-23 03:23:35 +00:00
|
|
|
foreach ($e_Flow->elements as $name => $bool) {
|
|
|
|
$this->info_flow_elements[$name] = true;
|
|
|
|
}
|
|
|
|
|
2006-08-03 01:18:57 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// info[]->excludes : defines elements that aren't allowed in here
|
|
|
|
|
|
|
|
// make sure you test using isset() and not !empty()
|
|
|
|
|
|
|
|
$this->info['a']->excludes = array('a' => true);
|
|
|
|
$this->info['pre']->excludes = array_flip(array('img', 'big', 'small',
|
2006-09-22 02:47:41 +00:00
|
|
|
// technically useless, but good to be indepth
|
2006-08-03 01:18:57 +00:00
|
|
|
'object', 'applet', 'font', 'basefont'));
|
|
|
|
|
2006-07-31 00:15:01 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// info[]->attr : defines allowed attributes for elements
|
|
|
|
|
2006-07-30 18:37:42 +00:00
|
|
|
// this doesn't include REQUIRED declarations, those are handled
|
2006-08-04 00:11:54 +00:00
|
|
|
// by the transform classes. It will, however, do simple and slightly
|
|
|
|
// complex attribute value substitution
|
2006-07-30 18:37:42 +00:00
|
|
|
|
2006-09-22 02:47:41 +00:00
|
|
|
// the question of varying allowed attributes is more entangling.
|
|
|
|
|
2006-08-05 22:14:19 +00:00
|
|
|
$e_Text = new HTMLPurifier_AttrDef_Text();
|
|
|
|
|
2006-08-04 00:11:54 +00:00
|
|
|
// attrs, included in almost every single one except for a few,
|
|
|
|
// which manually override these in their local definitions
|
2006-07-30 19:11:18 +00:00
|
|
|
$this->info_global_attr = array(
|
2006-07-30 18:37:42 +00:00
|
|
|
// core attrs
|
2006-08-04 02:48:20 +00:00
|
|
|
'class' => new HTMLPurifier_AttrDef_Class(),
|
2006-08-05 22:14:19 +00:00
|
|
|
'title' => $e_Text,
|
2006-08-12 20:22:09 +00:00
|
|
|
'style' => new HTMLPurifier_AttrDef_CSS(),
|
2006-07-30 18:37:42 +00:00
|
|
|
// i18n
|
2006-08-05 01:50:13 +00:00
|
|
|
'dir' => new HTMLPurifier_AttrDef_Enum(array('ltr','rtl'), false),
|
|
|
|
'lang' => new HTMLPurifier_AttrDef_Lang(),
|
|
|
|
'xml:lang' => new HTMLPurifier_AttrDef_Lang(),
|
|
|
|
);
|
|
|
|
|
2006-11-17 01:05:41 +00:00
|
|
|
if ($config->get('HTML', 'EnableAttrID')) {
|
|
|
|
$this->info_global_attr['id'] = new HTMLPurifier_AttrDef_ID();
|
|
|
|
}
|
|
|
|
|
2006-08-05 01:50:13 +00:00
|
|
|
// required attribute stipulation handled in attribute transformation
|
2006-08-05 22:14:19 +00:00
|
|
|
$this->info['bdo']->attr = array(); // nothing else
|
|
|
|
|
|
|
|
$this->info['br']->attr['dir'] = false;
|
|
|
|
$this->info['br']->attr['lang'] = false;
|
|
|
|
$this->info['br']->attr['xml:lang'] = false;
|
|
|
|
|
|
|
|
$this->info['td']->attr['abbr'] = $e_Text;
|
|
|
|
$this->info['th']->attr['abbr'] = $e_Text;
|
|
|
|
|
2006-08-06 01:30:54 +00:00
|
|
|
$this->setAttrForTableElements('align', new HTMLPurifier_AttrDef_Enum(
|
|
|
|
array('left', 'center', 'right', 'justify', 'char'), false));
|
|
|
|
|
|
|
|
$this->setAttrForTableElements('valign', new HTMLPurifier_AttrDef_Enum(
|
|
|
|
array('top', 'middle', 'bottom', 'baseline'), false));
|
2006-08-05 22:14:19 +00:00
|
|
|
|
|
|
|
$this->info['img']->attr['alt'] = $e_Text;
|
|
|
|
|
2006-08-06 01:30:54 +00:00
|
|
|
$e_TFrame = new HTMLPurifier_AttrDef_Enum(array('void', 'above',
|
|
|
|
'below', 'hsides', 'lhs', 'rhs', 'vsides', 'box', 'border'), false);
|
2006-08-05 22:14:19 +00:00
|
|
|
$this->info['table']->attr['frame'] = $e_TFrame;
|
2006-08-06 01:30:54 +00:00
|
|
|
|
|
|
|
$e_TRules = new HTMLPurifier_AttrDef_Enum(array('none', 'groups',
|
|
|
|
'rows', 'cols', 'all'), false);
|
2006-08-05 22:14:19 +00:00
|
|
|
$this->info['table']->attr['rules'] = $e_TRules;
|
2006-08-06 01:30:54 +00:00
|
|
|
|
2006-08-05 22:14:19 +00:00
|
|
|
$this->info['table']->attr['summary'] = $e_Text;
|
2006-07-30 15:29:22 +00:00
|
|
|
|
2006-09-22 02:47:41 +00:00
|
|
|
$this->info['table']->attr['border'] =
|
|
|
|
new HTMLPurifier_AttrDef_Pixels();
|
2006-08-06 01:03:48 +00:00
|
|
|
|
2006-08-06 01:30:54 +00:00
|
|
|
$e_Length = new HTMLPurifier_AttrDef_Length();
|
2006-08-06 03:58:48 +00:00
|
|
|
$this->info['table']->attr['cellpadding'] =
|
|
|
|
$this->info['table']->attr['cellspacing'] =
|
|
|
|
$this->info['table']->attr['width'] =
|
|
|
|
$this->info['img']->attr['height'] =
|
2006-08-06 01:30:54 +00:00
|
|
|
$this->info['img']->attr['width'] = $e_Length;
|
2006-08-06 03:58:48 +00:00
|
|
|
$this->setAttrForTableElements('charoff', $e_Length);
|
2006-08-06 01:30:54 +00:00
|
|
|
|
2006-08-06 01:41:18 +00:00
|
|
|
$e_MultiLength = new HTMLPurifier_AttrDef_MultiLength();
|
2006-08-06 03:58:48 +00:00
|
|
|
$this->info['col']->attr['width'] =
|
2006-08-06 01:41:18 +00:00
|
|
|
$this->info['colgroup']->attr['width'] = $e_MultiLength;
|
|
|
|
|
2006-08-25 02:48:49 +00:00
|
|
|
$e__NumberSpan = new HTMLPurifier_AttrDef_Integer(false, false, true);
|
2006-08-06 03:58:48 +00:00
|
|
|
$this->info['colgroup']->attr['span'] =
|
|
|
|
$this->info['col']->attr['span'] =
|
|
|
|
$this->info['td']->attr['rowspan'] =
|
|
|
|
$this->info['th']->attr['rowspan'] =
|
|
|
|
$this->info['td']->attr['colspan'] =
|
|
|
|
$this->info['th']->attr['colspan'] = $e__NumberSpan;
|
|
|
|
|
2006-08-12 19:22:57 +00:00
|
|
|
$e_URI = new HTMLPurifier_AttrDef_URI();
|
|
|
|
$this->info['a']->attr['href'] =
|
|
|
|
$this->info['img']->attr['longdesc'] =
|
|
|
|
$this->info['del']->attr['cite'] =
|
|
|
|
$this->info['ins']->attr['cite'] =
|
|
|
|
$this->info['blockquote']->attr['cite'] =
|
|
|
|
$this->info['q']->attr['cite'] = $e_URI;
|
2006-08-06 03:58:48 +00:00
|
|
|
|
2006-11-17 23:09:10 +00:00
|
|
|
// URI that causes HTTP request
|
|
|
|
$this->info['img']->attr['src'] = new HTMLPurifier_AttrDef_URI(true);
|
|
|
|
|
2006-07-31 00:15:01 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
2006-09-22 02:47:41 +00:00
|
|
|
// info_tag_transform : transformations of tags
|
2006-07-31 00:15:01 +00:00
|
|
|
|
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
|
|
|
|
|
2006-09-22 02:47:41 +00:00
|
|
|
// todo: determine whether or not SGML-like modeling based on
|
|
|
|
// mandatory/optional end tags would be a better policy
|
|
|
|
|
2006-08-03 01:18:57 +00:00
|
|
|
// make sure you test using isset() not !empty()
|
|
|
|
|
2006-07-31 00:15:01 +00:00
|
|
|
// 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
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
2006-08-14 23:11:28 +00:00
|
|
|
// info[]->attr_transform_* : attribute transformations in elements
|
|
|
|
// pre is applied before any validation is done, post is done after
|
2006-08-05 02:56:57 +00:00
|
|
|
|
2006-08-14 23:11:28 +00:00
|
|
|
$this->info['h1']->attr_transform_pre[] =
|
|
|
|
$this->info['h2']->attr_transform_pre[] =
|
|
|
|
$this->info['h3']->attr_transform_pre[] =
|
|
|
|
$this->info['h4']->attr_transform_pre[] =
|
|
|
|
$this->info['h5']->attr_transform_pre[] =
|
|
|
|
$this->info['h6']->attr_transform_pre[] =
|
|
|
|
$this->info['p'] ->attr_transform_pre[] =
|
|
|
|
new HTMLPurifier_AttrTransform_TextAlign();
|
|
|
|
|
|
|
|
$this->info['bdo']->attr_transform_post[] =
|
|
|
|
new HTMLPurifier_AttrTransform_BdoDir();
|
|
|
|
|
|
|
|
$this->info['img']->attr_transform_post[] =
|
|
|
|
new HTMLPurifier_AttrTransform_ImgRequired();
|
2006-07-31 00:15:01 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
2006-08-14 23:11:28 +00:00
|
|
|
// info_attr_transform_* : global attribute transformation that is
|
2006-08-05 01:50:13 +00:00
|
|
|
// unconditionally called. Good for transformations that have complex
|
|
|
|
// start conditions
|
2006-08-14 23:11:28 +00:00
|
|
|
// pre is applied before any validation is done, post is done after
|
2006-07-31 00:15:01 +00:00
|
|
|
|
2006-08-14 23:11:28 +00:00
|
|
|
$this->info_attr_transform_post[] = new HTMLPurifier_AttrTransform_Lang();
|
2006-07-31 00:15:01 +00:00
|
|
|
|
2006-11-08 00:11:10 +00:00
|
|
|
// protect against stdclasses floating around
|
|
|
|
foreach ($this->info as $key => $obj) {
|
|
|
|
if (is_a($obj, 'stdclass')) {
|
|
|
|
unset($this->info[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-23 03:23:35 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// info_block_wrapper : wraps inline elements in block context
|
|
|
|
|
|
|
|
$block_wrapper = $config->get('HTML', 'BlockWrapper');
|
|
|
|
if (isset($e_Block->elements[$block_wrapper])) {
|
|
|
|
$this->info_block_wrapper = $block_wrapper;
|
|
|
|
} else {
|
|
|
|
trigger_error('Cannot use non-block element as block wrapper.',
|
|
|
|
E_USER_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// info_parent : parent element of the HTML fragment
|
|
|
|
|
|
|
|
$parent = $config->get('HTML', 'Parent');
|
|
|
|
if (isset($this->info[$parent])) {
|
|
|
|
$this->info_parent = $parent;
|
|
|
|
} else {
|
|
|
|
trigger_error('Cannot use unrecognized element as parent.',
|
|
|
|
E_USER_ERROR);
|
|
|
|
}
|
2006-11-23 13:51:19 +00:00
|
|
|
$this->info_parent_def = $this->info[$this->info_parent];
|
2006-11-23 03:23:35 +00:00
|
|
|
|
2006-11-23 13:51:19 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// %HTML.Allowed(Elements|Attributes) : cut non-allowed elements
|
|
|
|
$allowed_elements = $config->get('HTML', 'AllowedElements');
|
|
|
|
if (is_array($allowed_elements)) {
|
|
|
|
// $allowed_elements[$this->info_parent] = true; // allow parent element
|
|
|
|
foreach ($this->info as $name => $d) {
|
|
|
|
if(!isset($allowed_elements[$name])) unset($this->info[$name]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$allowed_attributes = $config->get('HTML', 'AllowedAttributes');
|
|
|
|
if (is_array($allowed_attributes)) {
|
|
|
|
foreach ($this->info_global_attr as $attr => $info) {
|
|
|
|
if (!isset($allowed_attributes["*.$attr"])) {
|
|
|
|
unset($this->info_global_attr[$attr]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach ($this->info as $tag => $info) {
|
|
|
|
foreach ($info->attr as $attr => $attr_info) {
|
|
|
|
if (!isset($allowed_attributes["$tag.$attr"])) {
|
|
|
|
unset($this->info[$tag]->attr[$attr]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-07-23 00:11:03 +00:00
|
|
|
}
|
|
|
|
|
2006-08-06 01:30:54 +00:00
|
|
|
function setAttrForTableElements($attr, $def) {
|
|
|
|
$this->info['col']->attr[$attr] =
|
|
|
|
$this->info['colgroup']->attr[$attr] =
|
|
|
|
$this->info['tbody']->attr[$attr] =
|
|
|
|
$this->info['td']->attr[$attr] =
|
|
|
|
$this->info['tfoot']->attr[$attr] =
|
|
|
|
$this->info['th']->attr[$attr] =
|
|
|
|
$this->info['thead']->attr[$attr] =
|
|
|
|
$this->info['tr']->attr[$attr] = $def;
|
|
|
|
}
|
|
|
|
|
2006-07-23 00:11:03 +00:00
|
|
|
}
|
|
|
|
|
2006-08-20 20:59:13 +00:00
|
|
|
/**
|
|
|
|
* Structure that stores an element definition.
|
|
|
|
*/
|
2006-07-23 00:11:03 +00:00
|
|
|
class HTMLPurifier_ElementDef
|
|
|
|
{
|
|
|
|
|
2006-08-20 20:59:13 +00:00
|
|
|
/**
|
|
|
|
* Associative array of attribute name to HTMLPurifier_AttrDef
|
|
|
|
* @public
|
|
|
|
*/
|
2006-07-30 19:11:18 +00:00
|
|
|
var $attr = array();
|
2006-08-20 20:59:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* List of tag's HTMLPurifier_AttrTransform to be done before validation
|
|
|
|
* @public
|
|
|
|
*/
|
2006-08-14 23:11:28 +00:00
|
|
|
var $attr_transform_pre = array();
|
2006-08-20 20:59:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* List of tag's HTMLPurifier_AttrTransform to be done after validation
|
|
|
|
* @public
|
|
|
|
*/
|
2006-08-14 23:11:28 +00:00
|
|
|
var $attr_transform_post = array();
|
2006-08-20 20:59:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Lookup table of tags that close this tag.
|
|
|
|
* @public
|
|
|
|
*/
|
2006-07-31 00:15:01 +00:00
|
|
|
var $auto_close = array();
|
2006-08-20 20:59:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* HTMLPurifier_ChildDef of this tag.
|
|
|
|
* @public
|
|
|
|
*/
|
2006-07-31 00:15:01 +00:00
|
|
|
var $child;
|
2006-08-20 20:59:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Type of the tag: inline or block or unknown?
|
|
|
|
* @public
|
|
|
|
*/
|
2006-08-03 01:03:23 +00:00
|
|
|
var $type = 'unknown';
|
2006-08-20 20:59:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Lookup table of tags excluded from all descendants of this tag.
|
|
|
|
* @public
|
|
|
|
*/
|
2006-08-03 01:18:57 +00:00
|
|
|
var $excludes = array();
|
2006-07-23 00:11:03 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-04-16 03:00:05 +00:00
|
|
|
?>
|