0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-11-09 23:28:42 +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:
Edward Z. Yang 2007-02-04 01:01:27 +00:00
parent f6b50d4bfd
commit 43b157cf4d
7 changed files with 63 additions and 29 deletions

View File

@ -22,7 +22,7 @@ class HTMLPurifier_AttrCollection
'lang' => false, // see constructor
),
'Events' => array(),
'Style' => array(),
'Style' => array(), // specifically empty
'Common' => array(
0 => array('Core', 'Events', 'I18N', 'Style')
)
@ -36,25 +36,12 @@ class HTMLPurifier_AttrCollection
function setup($attr_types, $modules) {
$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) {
// merge attribute collections that include others
$this->performInclusions($info[$name]);
// replace string identifiers with actual attribute objects
$this->expandStringIdentifiers($info[$name], $attr_types);
}
}
function performInclusions(&$attr) {
@ -75,6 +62,18 @@ class HTMLPurifier_AttrCollection
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]);
}
}
}
}
?>

View File

@ -3,6 +3,7 @@
require_once 'HTMLPurifier/AttrDef/Nmtokens.php';
require_once 'HTMLPurifier/AttrDef/Text.php';
require_once 'HTMLPurifier/AttrDef/ID.php';
require_once 'HTMLPurifier/AttrDef/URI.php';
/**
* Provides lookup array of attribute types to HTMLPurifier_AttrDef objects

View File

@ -641,6 +641,9 @@ class HTMLPurifier_ElementDef
*/
var $child;
var $content_model;
var $content_model_type = 'optional';
/**
* Type of the tag: inline or block or unknown?
* @public

View File

@ -17,11 +17,4 @@ class HTMLPurifier_HTMLModule
var $content_sets = array();
}
class HTMLPurifier_HTMLModuleElement
{
var $attr = array();
var $content_model;
var $content_model_type = 'optional';
}
?>

View 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);
}
}
?>

View File

@ -24,7 +24,7 @@ class HTMLPurifier_HTMLModule_Text extends HTMLPurifier_HTMLModule
function HTMLPurifier_HTMLModule_Text() {
foreach ($this->elements as $element) {
$this->info[$element] = new HTMLPurifier_HTMLModuleElement();
$this->info[$element] = new HTMLPurifier_ElementDef();
// attributes
if ($element == 'br') {
$this->info[$element]->attr = array(0 => array('Core'));

View File

@ -6,6 +6,7 @@ require_once 'HTMLPurifier/AttrTypes.php';
require_once 'HTMLPurifier/AttrCollection.php';
require_once 'HTMLPurifier/HTMLModule.php';
require_once 'HTMLPurifier/HTMLModule/Text.php';
require_once 'HTMLPurifier/HTMLModule/Hypertext.php';
/**
* Next-generation HTML definition that will supplant HTMLPurifier_HTMLDefinition
@ -20,6 +21,7 @@ class HTMLPurifier_XHTMLDefinition extends HTMLPurifier_HTMLDefinition
function initialize($config) {
$this->modules['Text'] = new HTMLPurifier_HTMLModule_Text();
$this->modules['Hypertext'] = new HTMLPurifier_HTMLModule_Hypertext();
$this->attr_types = new HTMLPurifier_AttrTypes();
$this->attr_collection = new HTMLPurifier_AttrCollection();
@ -63,6 +65,8 @@ class HTMLPurifier_XHTMLDefinition extends HTMLPurifier_HTMLDefinition
// attribute value expansions
$this->attr_collection->performInclusions($element->attr);
$this->attr_collection->expandStringIdentifiers(
$element->attr, $this->attr_types);
// perform content model expansions
$content_model = $element->content_model;
@ -71,14 +75,14 @@ class HTMLPurifier_XHTMLDefinition extends HTMLPurifier_HTMLDefinition
$content_sets_keys, $content_sets_values, $content_model);
}
// get child def from content model
$element->child = $this->getChildDef($element);
// setup info
$this->info[$element_i] = new HTMLPurifier_ElementDef();
$this->info[$element_i]->attr = $element->attr;
$this->info[$element_i]->child = $this->getChildDef($element);
$this->info[$element_i] = $element;
if ($this->info_parent == $element_i) {
$this->info_parent_def = $this->info[$element_i];
}
}
}