1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-01-17 14:08:15 +01:00

[1.3.0] Add Printer_CSSDefinition.

- Added @public identifiers to properties that the Printers are using.
- Augmented Printer::getClass() to include meta-info about the object (contained inside parentheses). Currently supports: enum, composite and multiple.
- Remove all linebreaks from Printer output
- Document Printer_HTMLDefinition's methods.

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@581 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2006-11-25 05:05:32 +00:00
parent b63b0be21f
commit 9bbbb87ffa
6 changed files with 99 additions and 17 deletions

View File

@ -20,10 +20,9 @@ HTMLPurifier_ConfigSchema::define(
class HTMLPurifier_ChildDef
{
/**
* Type of child definition, usually right-most part of class name lowercase
*
* Used occasionally in terms of context. Possible values include
* custom, required, optional and empty.
* Type of child definition, usually right-most part of class name lowercase.
* Used occasionally in terms of context.
* @public
*/
var $type;
@ -32,12 +31,15 @@ class HTMLPurifier_ChildDef
*
* This is necessary for redundant checking when changes affecting
* a child node may cause a parent node to now be disallowed.
*
* @public
*/
var $allow_empty;
/**
* Validates nodes according to definition and returns modification.
*
* @public
* @param $tokens_of_children Array of HTMLPurifier_Token
* @param $config HTMLPurifier_Config object
* @param $context HTMLPurifier_Context object

View File

@ -16,10 +16,13 @@ class HTMLPurifier_ChildDef_Chameleon extends HTMLPurifier_ChildDef
/**
* Instance of the definition object to use when inline. Usually stricter.
* @public
*/
var $inline;
/**
* Instance of the definition object to use when block.
* @public
*/
var $block;

View File

@ -9,6 +9,7 @@ class HTMLPurifier_ChildDef_Required extends HTMLPurifier_ChildDef
{
/**
* Lookup table of allowed elements.
* @public
*/
var $elements = array();
/**

View File

@ -108,16 +108,40 @@ class HTMLPurifier_Printer
}
/**
* Retrieves the class of an object without prefixes
* Retrieves the class of an object without prefixes, as well as metadata
* @param $obj Object to determine class of
* @param $prefix Further prefix to remove
*/
function getClass($obj, $prefix = '') {
function getClass($obj, $sec_prefix = '') {
static $five = null;
if ($five === null) $five = version_compare(PHP_VERSION, '5', '>=');
$prefix = 'HTMLPurifier_' . $prefix;
$prefix = 'HTMLPurifier_' . $sec_prefix;
if (!$five) $prefix = strtolower($prefix);
return str_replace($prefix, '', get_class($obj));
$class = str_replace($prefix, '', get_class($obj));
$lclass = strtolower($class);
$class .= '(';
switch ($lclass) {
case 'enum':
$values = array();
foreach ($obj->valid_values as $value => $bool) {
$values[] = $value;
}
$class .= implode(', ', $values);
break;
case 'composite':
$values = array();
foreach ($obj->defs as $def) {
$values[] = $this->getClass($def, $sec_prefix);
}
$class .= implode(', ', $values);
break;
case 'multiple':
$class .= $this->getClass($obj->single, $sec_prefix) . ', ';
$class .= $obj->max;
break;
}
$class .= ')';
return $class;
}
}

View File

@ -1,9 +1,39 @@
<?php
class HTMLPurifier_Printer_CSSDefinition
require_once 'HTMLPurifier/Printer.php';
class HTMLPurifier_Printer_CSSDefinition extends HTMLPurifier_Printer
{
function render() {return '<p>To be implemented.</p>';}
var $def;
function render($config) {
$this->def = $config->getCSSDefinition();
$ret = '';
$ret .= $this->start('div', array('class' => 'HTMLPurifier_Printer'));
$ret .= $this->start('table');
$ret .= $this->element('caption', 'Properties ($info)');
$ret .= $this->start('thead');
$ret .= $this->start('tr');
$ret .= $this->element('th', 'Property', array('class' => 'heavy'));
$ret .= $this->element('th', 'Definition', array('class' => 'heavy', 'style' => 'width:auto;'));
$ret .= $this->end('tr');
$ret .= $this->end('thead');
ksort($this->def->info);
foreach ($this->def->info as $property => $obj) {
$name = $this->getClass($obj, 'AttrDef_');
$ret .= $this->row($property, $name);
}
$ret .= $this->end('table');
$ret .= $this->end('div');
return $ret;
}
}

View File

@ -17,12 +17,12 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
$def =& $this->def;
$ret .= $this->start('div', array('class' => 'HTMLPurifier_Printer'));
$ret .= $this->start('table') . "\n";
$ret .= $this->start('table');
$ret .= $this->element('caption', 'Environment');
$ret .= $this->row('Parent of fragment', $def->info_parent) . "\n";
$ret .= $this->row('Strict mode', $def->strict) . "\n";
if ($def->strict) $ret .= $this->row('Block wrap name', $def->info_block_wrapper) . "\n";
$ret .= $this->row('Parent of fragment', $def->info_parent);
$ret .= $this->row('Strict mode', $def->strict);
if ($def->strict) $ret .= $this->row('Block wrap name', $def->info_block_wrapper);
$ret .= $this->start('tr');
$ret .= $this->element('th', 'Global attributes');
@ -51,18 +51,23 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
$ret .= $this->element('td', $this->listifyObjectList($def->info_attr_transform_post));
$ret .= $this->end('tr');
$ret .= $this->end('table') . "\n";
$ret .= $this->end('table');
$ret .= $this->renderInfo();
$ret .= $this->renderInfo() . "\n";
$ret .= $this->end('div');
return $ret;
}
/**
* Renders the Elements ($info) table
*/
function renderInfo() {
$ret = '';
$ret .= $this->start('table') . "\n";
$ret .= $this->start('table');
$ret .= $this->element('caption', 'Elements ($info)');
ksort($this->def->info);
$ret .= $this->start('tr');
@ -114,6 +119,10 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
return $ret;
}
/**
* Renders a row describing the allowed children of an element
* @param $def HTMLPurifier_ChildDef of pertinent element
*/
function renderChildren($def) {
$context = new HTMLPurifier_Context();
$ret = '';
@ -153,6 +162,10 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
return $ret;
}
/**
* Listifies a tag lookup table.
* @param $array Tag lookup array in form of array('tagname' => true)
*/
function listifyTagLookup($array) {
$list = array();
foreach ($array as $name => $discard) {
@ -162,6 +175,11 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
return $this->listify($list);
}
/**
* Listifies a list of objects by retrieving class names and internal state
* @param $array List of objects
* @todo Also add information about internal state
*/
function listifyObjectList($array) {
$list = array();
foreach ($array as $discard => $obj) {
@ -170,6 +188,10 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
return $this->listify($list);
}
/**
* Listifies a hash of attributes to AttrDef classes
* @param $array Array hash in form of array('attrname' => HTMLPurifier_AttrDef)
*/
function listifyAttr($array) {
$list = array();
foreach ($array as $name => $obj) {