mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-07-13 02:36:19 +02:00
Release 1.6.1, merged in 931 to HEAD.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/branches/strict@1026 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@ -12,7 +12,6 @@ class HTMLPurifier_HTMLModule_Bdo extends HTMLPurifier_HTMLModule
|
||||
|
||||
var $name = 'Bdo';
|
||||
var $elements = array('bdo');
|
||||
var $info = array();
|
||||
var $content_sets = array('Inline' => 'bdo');
|
||||
var $attr_collections = array(
|
||||
'I18N' => array('dir' => false)
|
||||
|
@ -12,7 +12,6 @@ class HTMLPurifier_HTMLModule_Edit extends HTMLPurifier_HTMLModule
|
||||
|
||||
var $name = 'Edit';
|
||||
var $elements = array('del', 'ins');
|
||||
var $info = array();
|
||||
var $content_sets = array('Inline' => 'del | ins');
|
||||
|
||||
function HTMLPurifier_HTMLModule_Edit() {
|
||||
|
@ -11,7 +11,6 @@ class HTMLPurifier_HTMLModule_Hypertext extends HTMLPurifier_HTMLModule
|
||||
|
||||
var $name = 'Hypertext';
|
||||
var $elements = array('a');
|
||||
var $info = array();
|
||||
var $content_sets = array('Inline' => 'a');
|
||||
|
||||
function HTMLPurifier_HTMLModule_Hypertext() {
|
||||
|
@ -15,7 +15,6 @@ class HTMLPurifier_HTMLModule_Image extends HTMLPurifier_HTMLModule
|
||||
|
||||
var $name = 'Image';
|
||||
var $elements = array('img');
|
||||
var $info = array();
|
||||
var $content_sets = array('Inline' => 'img');
|
||||
|
||||
function HTMLPurifier_HTMLModule_Image() {
|
||||
|
@ -10,7 +10,7 @@ class HTMLPurifier_HTMLModule_List extends HTMLPurifier_HTMLModule
|
||||
|
||||
var $name = 'List';
|
||||
var $elements = array('dl', 'dt', 'dd', 'ol', 'ul', 'li');
|
||||
var $info = array();
|
||||
|
||||
// According to the abstract schema, the List content set is a fully formed
|
||||
// one or more expr, but it invariably occurs in an optional declaration
|
||||
// so we're not going to do that subtlety. It might cause trouble
|
||||
|
@ -17,7 +17,6 @@ class HTMLPurifier_HTMLModule_Presentation extends HTMLPurifier_HTMLModule
|
||||
|
||||
var $name = 'Presentation';
|
||||
var $elements = array('b', 'big', 'hr', 'i', 'small', 'sub', 'sup', 'tt');
|
||||
var $info = array();
|
||||
var $content_sets = array(
|
||||
'Block' => 'hr',
|
||||
'Inline' => 'b | big | i | small | sub | sup | tt'
|
||||
|
67
library/HTMLPurifier/HTMLModule/Scripting.php
Normal file
67
library/HTMLPurifier/HTMLModule/Scripting.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
WARNING: THIS MODULE IS EXTREMELY DANGEROUS AS IT ENABLES INLINE SCRIPTING
|
||||
INSIDE HTML PURIFIER DOCUMENTS. USE ONLY WITH TRUSTED USER INPUT!!!
|
||||
|
||||
Usage:
|
||||
|
||||
require_once 'HTMLPurifier/HTMLModule/Scripting.php';
|
||||
$def =& $config->getHTMLDefinition(true); // get the raw version
|
||||
$def->manager->addModule('Scripting');
|
||||
|
||||
This must come before any other calls to getHTMLDefinition()
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements required attribute stipulation for <script>
|
||||
*/
|
||||
class HTMLPurifier_AttrTransform_ScriptRequired extends HTMLPurifier_AttrTransform
|
||||
{
|
||||
function transform($attr, $config, &$context) {
|
||||
if (!isset($attr['type'])) {
|
||||
$attr['type'] = 'text/javascript';
|
||||
}
|
||||
return $attr;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* XHTML 1.1 Scripting module, defines elements that are used to contain
|
||||
* information pertaining to executable scripts or the lack of support
|
||||
* for executable scripts.
|
||||
* @note This module does not contain inline scripting elements
|
||||
*/
|
||||
class HTMLPurifier_HTMLModule_Scripting extends HTMLPurifier_HTMLModule
|
||||
{
|
||||
var $name = 'Scripting';
|
||||
var $elements = array('script', 'noscript');
|
||||
var $content_sets = array('Block' => 'script | noscript', 'Inline' => 'script | noscript');
|
||||
|
||||
function HTMLPurifier_HTMLModule_Scripting() {
|
||||
// TODO: create custom child-definition for noscript that
|
||||
// auto-wraps stray #PCDATA in a similar manner to
|
||||
// blockquote's custom definition (we would use it but
|
||||
// blockquote's contents are optional while noscript's contents
|
||||
// are required)
|
||||
foreach ($this->elements as $element) {
|
||||
$this->info[$element] = new HTMLPurifier_ElementDef();
|
||||
}
|
||||
$this->info['noscript']->attr = array( 0 => array('Common') );
|
||||
$this->info['noscript']->content_model = 'Heading | List | Block';
|
||||
$this->info['noscript']->content_model_type = 'required';
|
||||
$this->info['script']->attr = array(
|
||||
'defer' => new HTMLPurifier_AttrDef_Enum(array('defer')),
|
||||
'src' => new HTMLPurifier_AttrDef_URI(true),
|
||||
'type' => new HTMLPurifier_AttrDef_Enum(array('text/javascript'))
|
||||
);
|
||||
$this->info['script']->content_model = '#PCDATA';
|
||||
$this->info['script']->content_model_type = 'optional';
|
||||
$this->info['script']->attr_transform_post['type'] =
|
||||
new HTMLPurifier_AttrTransform_ScriptRequired();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -12,7 +12,6 @@ class HTMLPurifier_HTMLModule_Tables extends HTMLPurifier_HTMLModule
|
||||
var $name = 'Tables';
|
||||
var $elements = array('caption', 'table', 'td', 'th', 'tr', 'col',
|
||||
'colgroup', 'tbody', 'thead', 'tfoot');
|
||||
var $info = array();
|
||||
var $content_sets = array('Block' => 'table');
|
||||
|
||||
function HTMLPurifier_HTMLModule_Tables() {
|
||||
|
26
library/HTMLPurifier/HTMLModule/Target.php
Normal file
26
library/HTMLPurifier/HTMLModule/Target.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
require_once 'HTMLPurifier/AttrDef/HTML/FrameTarget.php';
|
||||
|
||||
/**
|
||||
* XHTML 1.1 Target Module, defines target attribute in link elements.
|
||||
*/
|
||||
class HTMLPurifier_HTMLModule_Target extends HTMLPurifier_HTMLModule
|
||||
{
|
||||
|
||||
var $name = 'Target';
|
||||
var $elements = array('a');
|
||||
|
||||
function HTMLPurifier_HTMLModule_Target() {
|
||||
foreach ($this->elements as $e) {
|
||||
$this->info[$e] = new HTMLPurifier_ElementDef();
|
||||
$this->info[$e]->standalone = false;
|
||||
$this->info[$e]->attr = array(
|
||||
'target' => new HTMLPurifier_AttrDef_HTML_FrameTarget()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -22,8 +22,6 @@ class HTMLPurifier_HTMLModule_Text extends HTMLPurifier_HTMLModule
|
||||
'h4', 'h5', 'h6', 'kbd', 'p', 'pre', 'q', 'samp', 'span', 'strong',
|
||||
'var');
|
||||
|
||||
var $info = array();
|
||||
|
||||
var $content_sets = array(
|
||||
'Heading' => 'h1 | h2 | h3 | h4 | h5 | h6',
|
||||
'Block' => 'address | blockquote | div | p | pre',
|
||||
|
@ -7,11 +7,13 @@ require_once 'HTMLPurifier/TagTransform/Center.php';
|
||||
require_once 'HTMLPurifier/TagTransform/Font.php';
|
||||
|
||||
require_once 'HTMLPurifier/AttrTransform/Lang.php';
|
||||
require_once 'HTMLPurifier/AttrTransform/TextAlign.php';
|
||||
require_once 'HTMLPurifier/AttrTransform/BgColor.php';
|
||||
require_once 'HTMLPurifier/AttrTransform/BoolToCSS.php';
|
||||
require_once 'HTMLPurifier/AttrTransform/Border.php';
|
||||
require_once 'HTMLPurifier/AttrTransform/Name.php';
|
||||
require_once 'HTMLPurifier/AttrTransform/Length.php';
|
||||
require_once 'HTMLPurifier/AttrTransform/ImgSpace.php';
|
||||
require_once 'HTMLPurifier/AttrTransform/EnumToCSS.php';
|
||||
|
||||
/**
|
||||
* Proprietary module that transforms deprecated elements into Strict
|
||||
@ -25,7 +27,8 @@ class HTMLPurifier_HTMLModule_TransformToStrict extends HTMLPurifier_HTMLModule
|
||||
|
||||
// we're actually modifying these elements, not defining them
|
||||
var $elements = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p',
|
||||
'blockquote', 'table', 'td', 'th', 'tr', 'img', 'a', 'hr');
|
||||
'blockquote', 'table', 'td', 'th', 'tr', 'img', 'a', 'hr', 'br',
|
||||
'caption', 'ul', 'ol', 'li');
|
||||
|
||||
var $info_tag_transform = array(
|
||||
// placeholders, see constructor for definitions
|
||||
@ -47,6 +50,13 @@ class HTMLPurifier_HTMLModule_TransformToStrict extends HTMLPurifier_HTMLModule
|
||||
|
||||
function HTMLPurifier_HTMLModule_TransformToStrict() {
|
||||
|
||||
// behavior with transformations when there's another CSS property
|
||||
// working on it is interesting: the CSS will *always* override
|
||||
// the deprecated attribute, whereas an inline CSS declaration will
|
||||
// override the corresponding declaration in, say, an external
|
||||
// stylesheet. This behavior won't affect most people, but it
|
||||
// does represent an operational difference we CANNOT fix.
|
||||
|
||||
// deprecated tag transforms
|
||||
$this->info_tag_transform['font'] = new HTMLPurifier_TagTransform_Font();
|
||||
$this->info_tag_transform['menu'] = new HTMLPurifier_TagTransform_Simple('ul');
|
||||
@ -59,6 +69,11 @@ class HTMLPurifier_HTMLModule_TransformToStrict extends HTMLPurifier_HTMLModule
|
||||
}
|
||||
|
||||
// deprecated attribute transforms
|
||||
|
||||
// align battery
|
||||
$align_lookup = array();
|
||||
$align_values = array('left', 'right', 'center', 'justify');
|
||||
foreach ($align_values as $v) $align_lookup[$v] = "text-align:$v;";
|
||||
$this->info['h1']->attr_transform_pre['align'] =
|
||||
$this->info['h2']->attr_transform_pre['align'] =
|
||||
$this->info['h3']->attr_transform_pre['align'] =
|
||||
@ -66,7 +81,7 @@ class HTMLPurifier_HTMLModule_TransformToStrict extends HTMLPurifier_HTMLModule
|
||||
$this->info['h5']->attr_transform_pre['align'] =
|
||||
$this->info['h6']->attr_transform_pre['align'] =
|
||||
$this->info['p'] ->attr_transform_pre['align'] =
|
||||
new HTMLPurifier_AttrTransform_TextAlign();
|
||||
new HTMLPurifier_AttrTransform_EnumToCSS('align', $align_lookup);
|
||||
|
||||
// xml:lang <=> lang mirroring, implement in TransformToStrict,
|
||||
// this is overridden in TransformToXHTML11
|
||||
@ -92,9 +107,86 @@ class HTMLPurifier_HTMLModule_TransformToStrict extends HTMLPurifier_HTMLModule
|
||||
$this->info['th']->attr_transform_pre['width'] =
|
||||
$this->info['hr']->attr_transform_pre['width'] = new HTMLPurifier_AttrTransform_Length('width');
|
||||
|
||||
$this->info['td']->attr_transform_pre['nowrap'] =
|
||||
$this->info['th']->attr_transform_pre['nowrap'] = new HTMLPurifier_AttrTransform_BoolToCSS('nowrap', 'white-space:nowrap;');
|
||||
|
||||
$this->info['td']->attr_transform_pre['height'] =
|
||||
$this->info['th']->attr_transform_pre['height'] = new HTMLPurifier_AttrTransform_Length('height');
|
||||
|
||||
$this->info['img']->attr_transform_pre['hspace'] = new HTMLPurifier_AttrTransform_ImgSpace('hspace');
|
||||
$this->info['img']->attr_transform_pre['vspace'] = new HTMLPurifier_AttrTransform_ImgSpace('vspace');
|
||||
|
||||
$this->info['hr']->attr_transform_pre['size'] = new HTMLPurifier_AttrTransform_Length('size', 'height');
|
||||
|
||||
// this transformation is not precise but often good enough.
|
||||
// different browsers use different styles to designate noshade
|
||||
$this->info['hr']->attr_transform_pre['noshade'] = new HTMLPurifier_AttrTransform_BoolToCSS('noshade', 'color:#808080;background-color:#808080;border: 0;');
|
||||
|
||||
$this->info['br']->attr_transform_pre['clear'] =
|
||||
new HTMLPurifier_AttrTransform_EnumToCSS('clear', array(
|
||||
'left' => 'clear:left;',
|
||||
'right' => 'clear:right;',
|
||||
'all' => 'clear:both;',
|
||||
'none' => 'clear:none;',
|
||||
));
|
||||
|
||||
// this is a slightly unreasonable attribute
|
||||
$this->info['caption']->attr_transform_pre['align'] =
|
||||
new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
|
||||
// we're following IE's behavior, not Firefox's, due
|
||||
// to the fact that no one supports caption-side:right,
|
||||
// W3C included (with CSS 2.1)
|
||||
'left' => 'text-align:left;',
|
||||
'right' => 'text-align:right;',
|
||||
'top' => 'caption-side:top;',
|
||||
'bottom' => 'caption-side:bottom;' // not supported by IE
|
||||
));
|
||||
|
||||
$this->info['table']->attr_transform_pre['align'] =
|
||||
new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
|
||||
'left' => 'float:left;',
|
||||
'center' => 'margin-left:auto;margin-right:auto;',
|
||||
'right' => 'float:right;'
|
||||
));
|
||||
|
||||
$this->info['img']->attr_transform_pre['align'] =
|
||||
new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
|
||||
'left' => 'float:left;',
|
||||
'right' => 'float:right;',
|
||||
'top' => 'vertical-align:top;',
|
||||
'middle' => 'vertical-align:middle;',
|
||||
'bottom' => 'vertical-align:baseline;',
|
||||
));
|
||||
|
||||
$this->info['hr']->attr_transform_pre['align'] =
|
||||
new HTMLPurifier_AttrTransform_EnumToCSS('align', array(
|
||||
'left' => 'margin-left:0;margin-right:auto;text-align:left;',
|
||||
'center' => 'margin-left:auto;margin-right:auto;text-align:center;',
|
||||
'right' => 'margin-left:auto;margin-right:0;text-align:right;'
|
||||
));
|
||||
|
||||
$ul_types = array(
|
||||
'disc' => 'list-style-type:disc;',
|
||||
'square' => 'list-style-type:square;',
|
||||
'circle' => 'list-style-type:circle;'
|
||||
);
|
||||
$ol_types = array(
|
||||
'1' => 'list-style-type:decimal;',
|
||||
'i' => 'list-style-type:lower-roman;',
|
||||
'I' => 'list-style-type:upper-roman;',
|
||||
'a' => 'list-style-type:lower-alpha;',
|
||||
'A' => 'list-style-type:upper-alpha;'
|
||||
);
|
||||
$li_types = $ul_types + $ol_types;
|
||||
|
||||
$this->info['ul']->attr_transform_pre['type'] =
|
||||
new HTMLPurifier_AttrTransform_EnumToCSS('type', $ul_types);
|
||||
$this->info['ol']->attr_transform_pre['type'] =
|
||||
new HTMLPurifier_AttrTransform_EnumToCSS('type', $ol_types, true);
|
||||
$this->info['li']->attr_transform_pre['type'] =
|
||||
new HTMLPurifier_AttrTransform_EnumToCSS('type', $li_types, true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
var $defines_child_def = true;
|
||||
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
require_once 'HTMLPurifier/AttrTransform/Lang.php';
|
||||
|
||||
/**
|
||||
* Proprietary module that transforms XHTML 1.0 deprecated aspects into
|
||||
* XHTML 1.1 compliant ones, when possible. For maximum effectiveness,
|
||||
@ -25,6 +27,10 @@ class HTMLPurifier_HTMLModule_TransformToXHTML11 extends HTMLPurifier_HTMLModule
|
||||
'lang' => false // remove it
|
||||
);
|
||||
|
||||
function HTMLPurifier_HTMLModule_TransformToXHTML11() {
|
||||
$this->info_attr_transform_pre['lang'] = new HTMLPurifier_AttrTransform_Lang();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user