MDL-22537 new html purifier backported to stable, unfortunately PHP5 only
This commit is contained in:
@@ -1,37 +1,35 @@
|
||||
<?php
|
||||
|
||||
require_once 'HTMLPurifier/Printer.php';
|
||||
|
||||
class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Instance of HTMLPurifier_HTMLDefinition, for easy access
|
||||
*/
|
||||
var $def;
|
||||
|
||||
function render($config) {
|
||||
protected $def;
|
||||
|
||||
public function render($config) {
|
||||
$ret = '';
|
||||
$this->config =& $config;
|
||||
|
||||
|
||||
$this->def = $config->getHTMLDefinition();
|
||||
|
||||
|
||||
$ret .= $this->start('div', array('class' => 'HTMLPurifier_Printer'));
|
||||
|
||||
|
||||
$ret .= $this->renderDoctype();
|
||||
$ret .= $this->renderEnvironment();
|
||||
$ret .= $this->renderContentSets();
|
||||
$ret .= $this->renderInfo();
|
||||
|
||||
|
||||
$ret .= $this->end('div');
|
||||
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Renders the Doctype table
|
||||
*/
|
||||
function renderDoctype() {
|
||||
protected function renderDoctype() {
|
||||
$doctype = $this->def->doctype;
|
||||
$ret = '';
|
||||
$ret .= $this->start('table');
|
||||
@@ -43,28 +41,28 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
|
||||
$ret .= $this->end('table');
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Renders environment table, which is miscellaneous info
|
||||
*/
|
||||
function renderEnvironment() {
|
||||
protected function renderEnvironment() {
|
||||
$def = $this->def;
|
||||
|
||||
|
||||
$ret = '';
|
||||
|
||||
|
||||
$ret .= $this->start('table');
|
||||
$ret .= $this->element('caption', 'Environment');
|
||||
|
||||
|
||||
$ret .= $this->row('Parent of fragment', $def->info_parent);
|
||||
$ret .= $this->renderChildren($def->info_parent_def->child);
|
||||
$ret .= $this->row('Block wrap name', $def->info_block_wrapper);
|
||||
|
||||
|
||||
$ret .= $this->start('tr');
|
||||
$ret .= $this->element('th', 'Global attributes');
|
||||
$ret .= $this->element('td', $this->listifyAttr($def->info_global_attr),0,0);
|
||||
$ret .= $this->end('tr');
|
||||
|
||||
|
||||
$ret .= $this->start('tr');
|
||||
$ret .= $this->element('th', 'Tag transforms');
|
||||
$list = array();
|
||||
@@ -74,25 +72,25 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
|
||||
}
|
||||
$ret .= $this->element('td', $this->listify($list));
|
||||
$ret .= $this->end('tr');
|
||||
|
||||
|
||||
$ret .= $this->start('tr');
|
||||
$ret .= $this->element('th', 'Pre-AttrTransform');
|
||||
$ret .= $this->element('td', $this->listifyObjectList($def->info_attr_transform_pre));
|
||||
$ret .= $this->end('tr');
|
||||
|
||||
|
||||
$ret .= $this->start('tr');
|
||||
$ret .= $this->element('th', 'Post-AttrTransform');
|
||||
$ret .= $this->element('td', $this->listifyObjectList($def->info_attr_transform_post));
|
||||
$ret .= $this->end('tr');
|
||||
|
||||
|
||||
$ret .= $this->end('table');
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Renders the Content Sets table
|
||||
*/
|
||||
function renderContentSets() {
|
||||
protected function renderContentSets() {
|
||||
$ret = '';
|
||||
$ret .= $this->start('table');
|
||||
$ret .= $this->element('caption', 'Content Sets');
|
||||
@@ -105,11 +103,11 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
|
||||
$ret .= $this->end('table');
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Renders the Elements ($info) table
|
||||
*/
|
||||
function renderInfo() {
|
||||
protected function renderInfo() {
|
||||
$ret = '';
|
||||
$ret .= $this->start('table');
|
||||
$ret .= $this->element('caption', 'Elements ($info)');
|
||||
@@ -120,7 +118,7 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
|
||||
$ret .= $this->end('tr');
|
||||
foreach ($this->def->info as $name => $def) {
|
||||
$ret .= $this->start('tr');
|
||||
$ret .= $this->element('th', "<$name>" . ($def->safe ? '' : ' (unsafe)'), array('class'=>'heavy' . ($def->safe ? '' : ' unsafe'), 'colspan' => 2));
|
||||
$ret .= $this->element('th', "<$name>", array('class'=>'heavy', 'colspan' => 2));
|
||||
$ret .= $this->end('tr');
|
||||
$ret .= $this->start('tr');
|
||||
$ret .= $this->element('th', 'Inline content');
|
||||
@@ -154,22 +152,22 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
|
||||
$ret .= $this->element('th', 'Allowed attributes');
|
||||
$ret .= $this->element('td',$this->listifyAttr($def->attr), array(), 0);
|
||||
$ret .= $this->end('tr');
|
||||
|
||||
|
||||
if (!empty($def->required_attr)) {
|
||||
$ret .= $this->row('Required attributes', $this->listify($def->required_attr));
|
||||
}
|
||||
|
||||
|
||||
$ret .= $this->renderChildren($def->child);
|
||||
}
|
||||
$ret .= $this->end('table');
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Renders a row describing the allowed children of an element
|
||||
* @param $def HTMLPurifier_ChildDef of pertinent element
|
||||
*/
|
||||
function renderChildren($def) {
|
||||
protected function renderChildren($def) {
|
||||
$context = new HTMLPurifier_Context();
|
||||
$ret = '';
|
||||
$ret .= $this->start('tr');
|
||||
@@ -190,9 +188,9 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
|
||||
'tfoot', 'tbody', 'tr'));
|
||||
}
|
||||
$ret .= $this->element('th', 'Allowed children', $attr);
|
||||
|
||||
|
||||
if ($def->type == 'chameleon') {
|
||||
|
||||
|
||||
$ret .= $this->element('td',
|
||||
'<em>Block</em>: ' .
|
||||
$this->escape($this->listifyTagLookup($def->block->elements)),0,0);
|
||||
@@ -201,12 +199,12 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
|
||||
$ret .= $this->element('td',
|
||||
'<em>Inline</em>: ' .
|
||||
$this->escape($this->listifyTagLookup($def->inline->elements)),0,0);
|
||||
|
||||
|
||||
} elseif ($def->type == 'custom') {
|
||||
|
||||
|
||||
$ret .= $this->element('td', '<em>'.ucfirst($def->type).'</em>: ' .
|
||||
$def->dtd_regex);
|
||||
|
||||
|
||||
} else {
|
||||
$ret .= $this->element('td',
|
||||
'<em>'.ucfirst($def->type).'</em>: ' .
|
||||
@@ -215,12 +213,12 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
|
||||
$ret .= $this->end('tr');
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Listifies a tag lookup table.
|
||||
* @param $array Tag lookup array in form of array('tagname' => true)
|
||||
*/
|
||||
function listifyTagLookup($array) {
|
||||
protected function listifyTagLookup($array) {
|
||||
ksort($array);
|
||||
$list = array();
|
||||
foreach ($array as $name => $discard) {
|
||||
@@ -229,13 +227,13 @@ 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) {
|
||||
protected function listifyObjectList($array) {
|
||||
ksort($array);
|
||||
$list = array();
|
||||
foreach ($array as $discard => $obj) {
|
||||
@@ -243,12 +241,12 @@ 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) {
|
||||
protected function listifyAttr($array) {
|
||||
ksort($array);
|
||||
$list = array();
|
||||
foreach ($array as $name => $obj) {
|
||||
@@ -257,17 +255,18 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
|
||||
}
|
||||
return $this->listify($list);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a heavy header row
|
||||
*/
|
||||
function heavyHeader($text, $num = 1) {
|
||||
protected function heavyHeader($text, $num = 1) {
|
||||
$ret = '';
|
||||
$ret .= $this->start('tr');
|
||||
$ret .= $this->element('th', $text, array('colspan' => $num, 'class' => 'heavy'));
|
||||
$ret .= $this->end('tr');
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
||||
|
||||
Reference in New Issue
Block a user