mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-11-14 01:08:41 +00:00
Add Hypertext module.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@708 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
f6b50d4bfd
commit
43b157cf4d
@ -22,7 +22,7 @@ class HTMLPurifier_AttrCollection
|
|||||||
'lang' => false, // see constructor
|
'lang' => false, // see constructor
|
||||||
),
|
),
|
||||||
'Events' => array(),
|
'Events' => array(),
|
||||||
'Style' => array(),
|
'Style' => array(), // specifically empty
|
||||||
'Common' => array(
|
'Common' => array(
|
||||||
0 => array('Core', 'Events', 'I18N', 'Style')
|
0 => array('Core', 'Events', 'I18N', 'Style')
|
||||||
)
|
)
|
||||||
@ -36,25 +36,12 @@ class HTMLPurifier_AttrCollection
|
|||||||
|
|
||||||
function setup($attr_types, $modules) {
|
function setup($attr_types, $modules) {
|
||||||
$info =& $this->info;
|
$info =& $this->info;
|
||||||
|
|
||||||
// replace string identifiers with actual attribute objects
|
|
||||||
foreach ($info as $collection_i => $collection) {
|
|
||||||
foreach ($collection as $attr_i => $attr) {
|
|
||||||
if ($attr_i === 0) continue;
|
|
||||||
if (!is_string($attr)) continue;
|
|
||||||
if (isset($attr_types->info[$attr])) {
|
|
||||||
$info[$collection_i][$attr_i] = $attr_types->info[$attr];
|
|
||||||
} else {
|
|
||||||
unset($info[$collection_i][$attr_i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// merge attribute collections that include others
|
|
||||||
foreach ($info as $name => $attr) {
|
foreach ($info as $name => $attr) {
|
||||||
|
// merge attribute collections that include others
|
||||||
$this->performInclusions($info[$name]);
|
$this->performInclusions($info[$name]);
|
||||||
|
// replace string identifiers with actual attribute objects
|
||||||
|
$this->expandStringIdentifiers($info[$name], $attr_types);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function performInclusions(&$attr) {
|
function performInclusions(&$attr) {
|
||||||
@ -75,6 +62,18 @@ class HTMLPurifier_AttrCollection
|
|||||||
unset($attr[0]);
|
unset($attr[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function expandStringIdentifiers(&$attr, $attr_types) {
|
||||||
|
foreach ($attr as $def_i => $def) {
|
||||||
|
if ($def_i === 0) continue;
|
||||||
|
if (!is_string($def)) continue;
|
||||||
|
if (isset($attr_types->info[$def])) {
|
||||||
|
$attr[$def_i] = $attr_types->info[$def];
|
||||||
|
} else {
|
||||||
|
unset($attr[$def_i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
@ -3,6 +3,7 @@
|
|||||||
require_once 'HTMLPurifier/AttrDef/Nmtokens.php';
|
require_once 'HTMLPurifier/AttrDef/Nmtokens.php';
|
||||||
require_once 'HTMLPurifier/AttrDef/Text.php';
|
require_once 'HTMLPurifier/AttrDef/Text.php';
|
||||||
require_once 'HTMLPurifier/AttrDef/ID.php';
|
require_once 'HTMLPurifier/AttrDef/ID.php';
|
||||||
|
require_once 'HTMLPurifier/AttrDef/URI.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides lookup array of attribute types to HTMLPurifier_AttrDef objects
|
* Provides lookup array of attribute types to HTMLPurifier_AttrDef objects
|
||||||
|
@ -641,6 +641,9 @@ class HTMLPurifier_ElementDef
|
|||||||
*/
|
*/
|
||||||
var $child;
|
var $child;
|
||||||
|
|
||||||
|
var $content_model;
|
||||||
|
var $content_model_type = 'optional';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type of the tag: inline or block or unknown?
|
* Type of the tag: inline or block or unknown?
|
||||||
* @public
|
* @public
|
||||||
|
@ -17,11 +17,4 @@ class HTMLPurifier_HTMLModule
|
|||||||
var $content_sets = array();
|
var $content_sets = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
class HTMLPurifier_HTMLModuleElement
|
|
||||||
{
|
|
||||||
var $attr = array();
|
|
||||||
var $content_model;
|
|
||||||
var $content_model_type = 'optional';
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
?>
|
34
library/HTMLPurifier/HTMLModule/Hypertext.php
Normal file
34
library/HTMLPurifier/HTMLModule/Hypertext.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTMLPurifier/HTMLModule.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* XHTML 1.1 Hypertext Module, defines hypertext links.
|
||||||
|
*/
|
||||||
|
class HTMLPurifier_HTMLModule_Hypertext extends HTMLPurifier_HTMLModule
|
||||||
|
{
|
||||||
|
|
||||||
|
var $elements = array('a');
|
||||||
|
var $info = array();
|
||||||
|
var $content_sets = array('Inline' => 'a');
|
||||||
|
|
||||||
|
function HTMLPurifier_HTMLModule_Hypertext() {
|
||||||
|
$this->info['a'] = new HTMLPurifier_ElementDef();
|
||||||
|
$this->info['a']->attr = array(
|
||||||
|
0 => array('Common'),
|
||||||
|
// 'accesskey' => 'Character',
|
||||||
|
// 'charset' => 'Charset',
|
||||||
|
'href' => 'URI',
|
||||||
|
//'hreflang' => 'LanguageCode',
|
||||||
|
//'rel' => 'LinkTypes',
|
||||||
|
//'rev' => 'LinkTypes',
|
||||||
|
//'tabindex' => 'Number',
|
||||||
|
//'type' => 'ContentType',
|
||||||
|
);
|
||||||
|
$this->info['a']->content_model = '#PCDATA | Inline';
|
||||||
|
$this->info['a']->excludes = array('a' => true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -24,7 +24,7 @@ class HTMLPurifier_HTMLModule_Text extends HTMLPurifier_HTMLModule
|
|||||||
|
|
||||||
function HTMLPurifier_HTMLModule_Text() {
|
function HTMLPurifier_HTMLModule_Text() {
|
||||||
foreach ($this->elements as $element) {
|
foreach ($this->elements as $element) {
|
||||||
$this->info[$element] = new HTMLPurifier_HTMLModuleElement();
|
$this->info[$element] = new HTMLPurifier_ElementDef();
|
||||||
// attributes
|
// attributes
|
||||||
if ($element == 'br') {
|
if ($element == 'br') {
|
||||||
$this->info[$element]->attr = array(0 => array('Core'));
|
$this->info[$element]->attr = array(0 => array('Core'));
|
||||||
|
@ -6,6 +6,7 @@ require_once 'HTMLPurifier/AttrTypes.php';
|
|||||||
require_once 'HTMLPurifier/AttrCollection.php';
|
require_once 'HTMLPurifier/AttrCollection.php';
|
||||||
require_once 'HTMLPurifier/HTMLModule.php';
|
require_once 'HTMLPurifier/HTMLModule.php';
|
||||||
require_once 'HTMLPurifier/HTMLModule/Text.php';
|
require_once 'HTMLPurifier/HTMLModule/Text.php';
|
||||||
|
require_once 'HTMLPurifier/HTMLModule/Hypertext.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Next-generation HTML definition that will supplant HTMLPurifier_HTMLDefinition
|
* Next-generation HTML definition that will supplant HTMLPurifier_HTMLDefinition
|
||||||
@ -20,6 +21,7 @@ class HTMLPurifier_XHTMLDefinition extends HTMLPurifier_HTMLDefinition
|
|||||||
function initialize($config) {
|
function initialize($config) {
|
||||||
|
|
||||||
$this->modules['Text'] = new HTMLPurifier_HTMLModule_Text();
|
$this->modules['Text'] = new HTMLPurifier_HTMLModule_Text();
|
||||||
|
$this->modules['Hypertext'] = new HTMLPurifier_HTMLModule_Hypertext();
|
||||||
|
|
||||||
$this->attr_types = new HTMLPurifier_AttrTypes();
|
$this->attr_types = new HTMLPurifier_AttrTypes();
|
||||||
$this->attr_collection = new HTMLPurifier_AttrCollection();
|
$this->attr_collection = new HTMLPurifier_AttrCollection();
|
||||||
@ -63,6 +65,8 @@ class HTMLPurifier_XHTMLDefinition extends HTMLPurifier_HTMLDefinition
|
|||||||
|
|
||||||
// attribute value expansions
|
// attribute value expansions
|
||||||
$this->attr_collection->performInclusions($element->attr);
|
$this->attr_collection->performInclusions($element->attr);
|
||||||
|
$this->attr_collection->expandStringIdentifiers(
|
||||||
|
$element->attr, $this->attr_types);
|
||||||
|
|
||||||
// perform content model expansions
|
// perform content model expansions
|
||||||
$content_model = $element->content_model;
|
$content_model = $element->content_model;
|
||||||
@ -71,14 +75,14 @@ class HTMLPurifier_XHTMLDefinition extends HTMLPurifier_HTMLDefinition
|
|||||||
$content_sets_keys, $content_sets_values, $content_model);
|
$content_sets_keys, $content_sets_values, $content_model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get child def from content model
|
||||||
|
$element->child = $this->getChildDef($element);
|
||||||
|
|
||||||
// setup info
|
// setup info
|
||||||
$this->info[$element_i] = new HTMLPurifier_ElementDef();
|
$this->info[$element_i] = $element;
|
||||||
$this->info[$element_i]->attr = $element->attr;
|
|
||||||
$this->info[$element_i]->child = $this->getChildDef($element);
|
|
||||||
if ($this->info_parent == $element_i) {
|
if ($this->info_parent == $element_i) {
|
||||||
$this->info_parent_def = $this->info[$element_i];
|
$this->info_parent_def = $this->info[$element_i];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user