@ -5,10 +5,33 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!class_exists('HTMLPurifier_URIFilter_NoExternalImages')) {
|
||||||
|
class HTMLPurifier_URIFilter_NoExternalImages extends HTMLPurifier_URIFilter {
|
||||||
|
public $name = 'NoExternalImages';
|
||||||
|
public function filter(&$uri, $c, $context) {
|
||||||
|
global $config;
|
||||||
|
$ct = $context->get('CurrentToken');
|
||||||
|
|
||||||
|
if (!$ct || $ct->name !== 'img') return true;
|
||||||
|
|
||||||
|
if (!isset($uri->host) && !isset($uri->scheme)) return true;
|
||||||
|
|
||||||
|
if (!in_array($uri->scheme . '://' . $uri->host . '/', $config['allowed_offsite_urls'])) {
|
||||||
|
error('No off-site links in board announcement images.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!function_exists('purify')){
|
if (!function_exists('purify')){
|
||||||
function purify($s){
|
function purify($s){
|
||||||
$config = HTMLPurifier_Config::createDefault();
|
$c = HTMLPurifier_Config::createDefault();
|
||||||
$purifier = new HTMLPurifier($config);
|
$c->set('HTML.Allowed', 'a[href],p,br,li,ol,ul,strong,em,u,h2,b,i,tt,div,img[src|alt]');
|
||||||
|
$uri = $c->getDefinition('URI');
|
||||||
|
$uri->addFilter(new HTMLPurifier_URIFilter_NoExternalImages(), $c);
|
||||||
|
$purifier = new HTMLPurifier($c);
|
||||||
$clean_html = $purifier->purify($s);
|
$clean_html = $purifier->purify($s);
|
||||||
return $clean_html;
|
return $clean_html;
|
||||||
}
|
}
|
||||||
@ -80,6 +103,7 @@
|
|||||||
$config['mod']['move'] = GLOBALVOLUNTEER;
|
$config['mod']['move'] = GLOBALVOLUNTEER;
|
||||||
$config['mod']['shadow_capcode'] = 'Global Volunteer';
|
$config['mod']['shadow_capcode'] = 'Global Volunteer';
|
||||||
|
|
||||||
|
|
||||||
$config['mod']['custom_pages']['/tags/(\%b)'] = function ($b) {
|
$config['mod']['custom_pages']['/tags/(\%b)'] = function ($b) {
|
||||||
global $board, $config;
|
global $board, $config;
|
||||||
|
|
||||||
@ -409,7 +433,6 @@ FLAGS;
|
|||||||
error("Could not open board!");
|
error("Could not open board!");
|
||||||
|
|
||||||
$possible_languages = array_diff(scandir('inc/locale/'), array('..', '.', '.tx', 'README.md'));
|
$possible_languages = array_diff(scandir('inc/locale/'), array('..', '.', '.tx', 'README.md'));
|
||||||
$allowed_urls = array('https://i.imgur.com/', 'https://media.8ch.net/', 'https://media.8chan.co/', 'https://a.pomf.se/', 'https://fonts.googleapis.com/', 'https://fonts.gstatic.com/', 'https://jp.8ch.net/');
|
|
||||||
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||||
$title = $_POST['title'];
|
$title = $_POST['title'];
|
||||||
@ -546,16 +569,14 @@ EOT;
|
|||||||
// Clean up our CSS...no more expression() or off-site URLs.
|
// Clean up our CSS...no more expression() or off-site URLs.
|
||||||
$clean_css = preg_replace('/expression\s*\(/', '', $_POST['css']);
|
$clean_css = preg_replace('/expression\s*\(/', '', $_POST['css']);
|
||||||
|
|
||||||
$match_urls = '((?:(?:https?:)?\/\/|ftp:\/\/|irc:\/\/)[^\s<>()"]+?(?:\([^\s<>()"]*?\)[^\s<>()"]*?)*)((?:\s|<|>|"|\.|\]|!|\?|,|&\#44;|")*(?:[\s<>()"]|$))';
|
|
||||||
|
|
||||||
$matched = array();
|
$matched = array();
|
||||||
|
|
||||||
preg_match_all("#$match_urls#im", $clean_css, $matched);
|
preg_match_all("#{$config['link_regex']}#im", $clean_css, $matched);
|
||||||
|
|
||||||
if (isset($matched[0])) {
|
if (isset($matched[0])) {
|
||||||
foreach ($matched[0] as $match) {
|
foreach ($matched[0] as $match) {
|
||||||
$match_okay = false;
|
$match_okay = false;
|
||||||
foreach ($allowed_urls as $allowed_url) {
|
foreach ($config['allowed_offsite_urls'] as $allowed_url) {
|
||||||
if (strpos($match, $allowed_url) !== false && strpos($match, '#') === false) {
|
if (strpos($match, $allowed_url) !== false && strpos($match, '#') === false) {
|
||||||
$match_okay = true;
|
$match_okay = true;
|
||||||
}
|
}
|
||||||
@ -633,5 +654,5 @@ EOT;
|
|||||||
cache::delete('all_boards');
|
cache::delete('all_boards');
|
||||||
}
|
}
|
||||||
|
|
||||||
mod_page(_('Board configuration'), 'mod/settings.html', array('board'=>$board, 'rules'=>prettify_textarea($rules), 'css'=>prettify_textarea($css), 'token'=>make_secure_link_token('settings/'.$board['uri']), 'languages'=>$possible_languages,'allowed_urls'=>$allowed_urls));
|
mod_page(_('Board configuration'), 'mod/settings.html', array('board'=>$board, 'rules'=>prettify_textarea($rules), 'css'=>prettify_textarea($css), 'token'=>make_secure_link_token('settings/'.$board['uri']), 'languages'=>$possible_languages,'allowed_urls'=>$config['allowed_offsite_urls']));
|
||||||
};
|
};
|
||||||
|
@ -1696,6 +1696,12 @@
|
|||||||
// is the absolute maximum, because MySQL cannot handle table names greater than 64 characters.
|
// is the absolute maximum, because MySQL cannot handle table names greater than 64 characters.
|
||||||
$config['board_regex'] = '[0-9a-zA-Z\+$_\x{0080}-\x{FFFF}]{1,58}';
|
$config['board_regex'] = '[0-9a-zA-Z\+$_\x{0080}-\x{FFFF}]{1,58}';
|
||||||
|
|
||||||
|
// Regex for matching links.
|
||||||
|
$config['link_regex'] = '((?:(?:https?:)?\/\/|ftp:\/\/|irc:\/\/)[^\s<>()"]+?(?:\([^\s<>()"]*?\)[^\s<>()"]*?)*)((?:\s|<|>|"|\.|\]|!|\?|,|&\#44;|")*(?:[\s<>()"]|$))';
|
||||||
|
|
||||||
|
// Allowed URLs in ?/settings
|
||||||
|
$config['allowed_offsite_urls'] = array('https://i.imgur.com/', 'https://media.8ch.net/', 'https://media.8chan.co/', 'https://a.pomf.se/', 'https://fonts.googleapis.com/', 'https://fonts.gstatic.com/');
|
||||||
|
|
||||||
// Use read.php?
|
// Use read.php?
|
||||||
// read.php is a file that dynamically displays pages to users instead of the build on demand system in use in Tinyboard since 2010.
|
// read.php is a file that dynamically displays pages to users instead of the build on demand system in use in Tinyboard since 2010.
|
||||||
//
|
//
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
* You can copy values from config.php (defaults) and paste them here.
|
* You can copy values from config.php (defaults) and paste them here.
|
||||||
*/
|
*/
|
||||||
require_once "lib/htmlpurifier-4.5.0/library/HTMLPurifier.auto.php";
|
require_once "lib/htmlpurifier-4.6.0/library/HTMLPurifier.auto.php";
|
||||||
require_once "8chan-functions.php";
|
require_once "8chan-functions.php";
|
||||||
|
|
||||||
// Note - you may want to change some of these in secrets.php instead of here
|
// Note - you may want to change some of these in secrets.php instead of here
|
||||||
|
@ -1 +0,0 @@
|
|||||||
4.5.0
|
|
@ -1,6 +0,0 @@
|
|||||||
HTML Purifier 4.5.0 is a minor bugfix and feature release, containing an
|
|
||||||
accumulation of changes over a year. CSS support has been extended to
|
|
||||||
support display:inline-block, white-space, underscores in font families,
|
|
||||||
page-break-* CSS3 properties (when proprietary is enabled.) We now use
|
|
||||||
SHA-1 to identify cached definitions, and the semantics of stacked
|
|
||||||
attribute transforms has changed slightly.
|
|
@ -1,21 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
class HTMLPurifier_AttrDef_CSS_AlphaValue extends HTMLPurifier_AttrDef_CSS_Number
|
|
||||||
{
|
|
||||||
|
|
||||||
public function __construct() {
|
|
||||||
parent::__construct(false); // opacity is non-negative, but we will clamp it
|
|
||||||
}
|
|
||||||
|
|
||||||
public function validate($number, $config, $context) {
|
|
||||||
$result = parent::validate($number, $config, $context);
|
|
||||||
if ($result === false) return $result;
|
|
||||||
$float = (float) $result;
|
|
||||||
if ($float < 0.0) $result = '0';
|
|
||||||
if ($float > 1.0) $result = '1';
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,28 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Decorator which enables CSS properties to be disabled for specific elements.
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_AttrDef_CSS_DenyElementDecorator extends HTMLPurifier_AttrDef
|
|
||||||
{
|
|
||||||
public $def, $element;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $def Definition to wrap
|
|
||||||
* @param $element Element to deny
|
|
||||||
*/
|
|
||||||
public function __construct($def, $element) {
|
|
||||||
$this->def = $def;
|
|
||||||
$this->element = $element;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Checks if CurrentToken is set and equal to $this->element
|
|
||||||
*/
|
|
||||||
public function validate($string, $config, $context) {
|
|
||||||
$token = $context->get('CurrentToken', true);
|
|
||||||
if ($token && $token->name == $this->element) return false;
|
|
||||||
return $this->def->validate($string, $config, $context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,24 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validates based on {ident} CSS grammar production
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_AttrDef_CSS_Ident extends HTMLPurifier_AttrDef
|
|
||||||
{
|
|
||||||
|
|
||||||
public function validate($string, $config, $context) {
|
|
||||||
|
|
||||||
$string = trim($string);
|
|
||||||
|
|
||||||
// early abort: '' and '0' (strings that convert to false) are invalid
|
|
||||||
if (!$string) return false;
|
|
||||||
|
|
||||||
$pattern = '/^(-?[A-Za-z_][A-Za-z_\-0-9]*)$/';
|
|
||||||
if (!preg_match($pattern, $string)) return false;
|
|
||||||
return $string;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,47 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a Length as defined by CSS.
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_AttrDef_CSS_Length extends HTMLPurifier_AttrDef
|
|
||||||
{
|
|
||||||
|
|
||||||
protected $min, $max;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param HTMLPurifier_Length $max Minimum length, or null for no bound. String is also acceptable.
|
|
||||||
* @param HTMLPurifier_Length $max Maximum length, or null for no bound. String is also acceptable.
|
|
||||||
*/
|
|
||||||
public function __construct($min = null, $max = null) {
|
|
||||||
$this->min = $min !== null ? HTMLPurifier_Length::make($min) : null;
|
|
||||||
$this->max = $max !== null ? HTMLPurifier_Length::make($max) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function validate($string, $config, $context) {
|
|
||||||
$string = $this->parseCDATA($string);
|
|
||||||
|
|
||||||
// Optimizations
|
|
||||||
if ($string === '') return false;
|
|
||||||
if ($string === '0') return '0';
|
|
||||||
if (strlen($string) === 1) return false;
|
|
||||||
|
|
||||||
$length = HTMLPurifier_Length::make($string);
|
|
||||||
if (!$length->isValid()) return false;
|
|
||||||
|
|
||||||
if ($this->min) {
|
|
||||||
$c = $length->compareTo($this->min);
|
|
||||||
if ($c === false) return false;
|
|
||||||
if ($c < 0) return false;
|
|
||||||
}
|
|
||||||
if ($this->max) {
|
|
||||||
$c = $length->compareTo($this->max);
|
|
||||||
if ($c === false) return false;
|
|
||||||
if ($c > 0) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $length->toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,78 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validates shorthand CSS property list-style.
|
|
||||||
* @warning Does not support url tokens that have internal spaces.
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_AttrDef_CSS_ListStyle extends HTMLPurifier_AttrDef
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Local copy of component validators.
|
|
||||||
* @note See HTMLPurifier_AttrDef_CSS_Font::$info for a similar impl.
|
|
||||||
*/
|
|
||||||
protected $info;
|
|
||||||
|
|
||||||
public function __construct($config) {
|
|
||||||
$def = $config->getCSSDefinition();
|
|
||||||
$this->info['list-style-type'] = $def->info['list-style-type'];
|
|
||||||
$this->info['list-style-position'] = $def->info['list-style-position'];
|
|
||||||
$this->info['list-style-image'] = $def->info['list-style-image'];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function validate($string, $config, $context) {
|
|
||||||
|
|
||||||
// regular pre-processing
|
|
||||||
$string = $this->parseCDATA($string);
|
|
||||||
if ($string === '') return false;
|
|
||||||
|
|
||||||
// assumes URI doesn't have spaces in it
|
|
||||||
$bits = explode(' ', strtolower($string)); // bits to process
|
|
||||||
|
|
||||||
$caught = array();
|
|
||||||
$caught['type'] = false;
|
|
||||||
$caught['position'] = false;
|
|
||||||
$caught['image'] = false;
|
|
||||||
|
|
||||||
$i = 0; // number of catches
|
|
||||||
$none = false;
|
|
||||||
|
|
||||||
foreach ($bits as $bit) {
|
|
||||||
if ($i >= 3) return; // optimization bit
|
|
||||||
if ($bit === '') continue;
|
|
||||||
foreach ($caught as $key => $status) {
|
|
||||||
if ($status !== false) continue;
|
|
||||||
$r = $this->info['list-style-' . $key]->validate($bit, $config, $context);
|
|
||||||
if ($r === false) continue;
|
|
||||||
if ($r === 'none') {
|
|
||||||
if ($none) continue;
|
|
||||||
else $none = true;
|
|
||||||
if ($key == 'image') continue;
|
|
||||||
}
|
|
||||||
$caught[$key] = $r;
|
|
||||||
$i++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$i) return false;
|
|
||||||
|
|
||||||
$ret = array();
|
|
||||||
|
|
||||||
// construct type
|
|
||||||
if ($caught['type']) $ret[] = $caught['type'];
|
|
||||||
|
|
||||||
// construct image
|
|
||||||
if ($caught['image']) $ret[] = $caught['image'];
|
|
||||||
|
|
||||||
// construct position
|
|
||||||
if ($caught['position']) $ret[] = $caught['position'];
|
|
||||||
|
|
||||||
if (empty($ret)) return false;
|
|
||||||
return implode(' ', $ret);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,40 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validates a Percentage as defined by the CSS spec.
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_AttrDef_CSS_Percentage extends HTMLPurifier_AttrDef
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instance of HTMLPurifier_AttrDef_CSS_Number to defer number validation
|
|
||||||
*/
|
|
||||||
protected $number_def;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Bool indicating whether to forbid negative values
|
|
||||||
*/
|
|
||||||
public function __construct($non_negative = false) {
|
|
||||||
$this->number_def = new HTMLPurifier_AttrDef_CSS_Number($non_negative);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function validate($string, $config, $context) {
|
|
||||||
|
|
||||||
$string = $this->parseCDATA($string);
|
|
||||||
|
|
||||||
if ($string === '') return false;
|
|
||||||
$length = strlen($string);
|
|
||||||
if ($length === 1) return false;
|
|
||||||
if ($string[$length - 1] !== '%') return false;
|
|
||||||
|
|
||||||
$number = substr($string, 0, $length - 1);
|
|
||||||
$number = $this->number_def->validate($number, $config, $context);
|
|
||||||
|
|
||||||
if ($number === false) return false;
|
|
||||||
return "$number%";
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,28 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Dummy AttrDef that mimics another AttrDef, BUT it generates clones
|
|
||||||
* with make.
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_AttrDef_Clone extends HTMLPurifier_AttrDef
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* What we're cloning
|
|
||||||
*/
|
|
||||||
protected $clone;
|
|
||||||
|
|
||||||
public function __construct($clone) {
|
|
||||||
$this->clone = $clone;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function validate($v, $config, $context) {
|
|
||||||
return $this->clone->validate($v, $config, $context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function make($string) {
|
|
||||||
return clone $this->clone;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,28 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validates a boolean attribute
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_AttrDef_HTML_Bool extends HTMLPurifier_AttrDef
|
|
||||||
{
|
|
||||||
|
|
||||||
protected $name;
|
|
||||||
public $minimized = true;
|
|
||||||
|
|
||||||
public function __construct($name = false) {$this->name = $name;}
|
|
||||||
|
|
||||||
public function validate($string, $config, $context) {
|
|
||||||
if (empty($string)) return false;
|
|
||||||
return $this->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $string Name of attribute
|
|
||||||
*/
|
|
||||||
public function make($string) {
|
|
||||||
return new HTMLPurifier_AttrDef_HTML_Bool($string);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,33 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validates a color according to the HTML spec.
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_AttrDef_HTML_Color extends HTMLPurifier_AttrDef
|
|
||||||
{
|
|
||||||
|
|
||||||
public function validate($string, $config, $context) {
|
|
||||||
|
|
||||||
static $colors = null;
|
|
||||||
if ($colors === null) $colors = $config->get('Core.ColorKeywords');
|
|
||||||
|
|
||||||
$string = trim($string);
|
|
||||||
|
|
||||||
if (empty($string)) return false;
|
|
||||||
$lower = strtolower($string);
|
|
||||||
if (isset($colors[$lower])) return $colors[$lower];
|
|
||||||
if ($string[0] === '#') $hex = substr($string, 1);
|
|
||||||
else $hex = $string;
|
|
||||||
|
|
||||||
$length = strlen($hex);
|
|
||||||
if ($length !== 3 && $length !== 6) return false;
|
|
||||||
if (!ctype_xdigit($hex)) return false;
|
|
||||||
if ($length === 3) $hex = $hex[0].$hex[0].$hex[1].$hex[1].$hex[2].$hex[2];
|
|
||||||
|
|
||||||
return "#$hex";
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,21 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Special-case enum attribute definition that lazy loads allowed frame targets
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_AttrDef_HTML_FrameTarget extends HTMLPurifier_AttrDef_Enum
|
|
||||||
{
|
|
||||||
|
|
||||||
public $valid_values = false; // uninitialized value
|
|
||||||
protected $case_sensitive = false;
|
|
||||||
|
|
||||||
public function __construct() {}
|
|
||||||
|
|
||||||
public function validate($string, $config, $context) {
|
|
||||||
if ($this->valid_values === false) $this->valid_values = $config->get('Attr.AllowedFrameTargets');
|
|
||||||
return parent::validate($string, $config, $context);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,41 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validates the HTML type length (not to be confused with CSS's length).
|
|
||||||
*
|
|
||||||
* This accepts integer pixels or percentages as lengths for certain
|
|
||||||
* HTML attributes.
|
|
||||||
*/
|
|
||||||
|
|
||||||
class HTMLPurifier_AttrDef_HTML_Length extends HTMLPurifier_AttrDef_HTML_Pixels
|
|
||||||
{
|
|
||||||
|
|
||||||
public function validate($string, $config, $context) {
|
|
||||||
|
|
||||||
$string = trim($string);
|
|
||||||
if ($string === '') return false;
|
|
||||||
|
|
||||||
$parent_result = parent::validate($string, $config, $context);
|
|
||||||
if ($parent_result !== false) return $parent_result;
|
|
||||||
|
|
||||||
$length = strlen($string);
|
|
||||||
$last_char = $string[$length - 1];
|
|
||||||
|
|
||||||
if ($last_char !== '%') return false;
|
|
||||||
|
|
||||||
$points = substr($string, 0, $length - 1);
|
|
||||||
|
|
||||||
if (!is_numeric($points)) return false;
|
|
||||||
|
|
||||||
$points = (int) $points;
|
|
||||||
|
|
||||||
if ($points < 0) return '0%';
|
|
||||||
if ($points > 100) return '100%';
|
|
||||||
|
|
||||||
return ((string) $points) . '%';
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,41 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validates a MultiLength as defined by the HTML spec.
|
|
||||||
*
|
|
||||||
* A multilength is either a integer (pixel count), a percentage, or
|
|
||||||
* a relative number.
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_AttrDef_HTML_MultiLength extends HTMLPurifier_AttrDef_HTML_Length
|
|
||||||
{
|
|
||||||
|
|
||||||
public function validate($string, $config, $context) {
|
|
||||||
|
|
||||||
$string = trim($string);
|
|
||||||
if ($string === '') return false;
|
|
||||||
|
|
||||||
$parent_result = parent::validate($string, $config, $context);
|
|
||||||
if ($parent_result !== false) return $parent_result;
|
|
||||||
|
|
||||||
$length = strlen($string);
|
|
||||||
$last_char = $string[$length - 1];
|
|
||||||
|
|
||||||
if ($last_char !== '*') return false;
|
|
||||||
|
|
||||||
$int = substr($string, 0, $length - 1);
|
|
||||||
|
|
||||||
if ($int == '') return '*';
|
|
||||||
if (!is_numeric($int)) return false;
|
|
||||||
|
|
||||||
$int = (int) $int;
|
|
||||||
|
|
||||||
if ($int < 0) return false;
|
|
||||||
if ($int == 0) return '0';
|
|
||||||
if ($int == 1) return '*';
|
|
||||||
return ((string) $int) . '*';
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,48 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validates an integer representation of pixels according to the HTML spec.
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_AttrDef_HTML_Pixels extends HTMLPurifier_AttrDef
|
|
||||||
{
|
|
||||||
|
|
||||||
protected $max;
|
|
||||||
|
|
||||||
public function __construct($max = null) {
|
|
||||||
$this->max = $max;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function validate($string, $config, $context) {
|
|
||||||
|
|
||||||
$string = trim($string);
|
|
||||||
if ($string === '0') return $string;
|
|
||||||
if ($string === '') return false;
|
|
||||||
$length = strlen($string);
|
|
||||||
if (substr($string, $length - 2) == 'px') {
|
|
||||||
$string = substr($string, 0, $length - 2);
|
|
||||||
}
|
|
||||||
if (!is_numeric($string)) return false;
|
|
||||||
$int = (int) $string;
|
|
||||||
|
|
||||||
if ($int < 0) return '0';
|
|
||||||
|
|
||||||
// upper-bound value, extremely high values can
|
|
||||||
// crash operating systems, see <http://ha.ckers.org/imagecrash.html>
|
|
||||||
// WARNING, above link WILL crash you if you're using Windows
|
|
||||||
|
|
||||||
if ($this->max !== null && $int > $this->max) return (string) $this->max;
|
|
||||||
|
|
||||||
return (string) $int;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function make($string) {
|
|
||||||
if ($string === '') $max = null;
|
|
||||||
else $max = (int) $string;
|
|
||||||
$class = get_class($this);
|
|
||||||
return new $class($max);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,15 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validates arbitrary text according to the HTML spec.
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_AttrDef_Text extends HTMLPurifier_AttrDef
|
|
||||||
{
|
|
||||||
|
|
||||||
public function validate($string, $config, $context) {
|
|
||||||
return $this->parseCDATA($string);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,99 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validates an IPv6 address.
|
|
||||||
* @author Feyd @ forums.devnetwork.net (public domain)
|
|
||||||
* @note This function requires brackets to have been removed from address
|
|
||||||
* in URI.
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_AttrDef_URI_IPv6 extends HTMLPurifier_AttrDef_URI_IPv4
|
|
||||||
{
|
|
||||||
|
|
||||||
public function validate($aIP, $config, $context) {
|
|
||||||
|
|
||||||
if (!$this->ip4) $this->_loadRegex();
|
|
||||||
|
|
||||||
$original = $aIP;
|
|
||||||
|
|
||||||
$hex = '[0-9a-fA-F]';
|
|
||||||
$blk = '(?:' . $hex . '{1,4})';
|
|
||||||
$pre = '(?:/(?:12[0-8]|1[0-1][0-9]|[1-9][0-9]|[0-9]))'; // /0 - /128
|
|
||||||
|
|
||||||
// prefix check
|
|
||||||
if (strpos($aIP, '/') !== false)
|
|
||||||
{
|
|
||||||
if (preg_match('#' . $pre . '$#s', $aIP, $find))
|
|
||||||
{
|
|
||||||
$aIP = substr($aIP, 0, 0-strlen($find[0]));
|
|
||||||
unset($find);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// IPv4-compatiblity check
|
|
||||||
if (preg_match('#(?<=:'.')' . $this->ip4 . '$#s', $aIP, $find))
|
|
||||||
{
|
|
||||||
$aIP = substr($aIP, 0, 0-strlen($find[0]));
|
|
||||||
$ip = explode('.', $find[0]);
|
|
||||||
$ip = array_map('dechex', $ip);
|
|
||||||
$aIP .= $ip[0] . $ip[1] . ':' . $ip[2] . $ip[3];
|
|
||||||
unset($find, $ip);
|
|
||||||
}
|
|
||||||
|
|
||||||
// compression check
|
|
||||||
$aIP = explode('::', $aIP);
|
|
||||||
$c = count($aIP);
|
|
||||||
if ($c > 2)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
elseif ($c == 2)
|
|
||||||
{
|
|
||||||
list($first, $second) = $aIP;
|
|
||||||
$first = explode(':', $first);
|
|
||||||
$second = explode(':', $second);
|
|
||||||
|
|
||||||
if (count($first) + count($second) > 8)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
while(count($first) < 8)
|
|
||||||
{
|
|
||||||
array_push($first, '0');
|
|
||||||
}
|
|
||||||
|
|
||||||
array_splice($first, 8 - count($second), 8, $second);
|
|
||||||
$aIP = $first;
|
|
||||||
unset($first,$second);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$aIP = explode(':', $aIP[0]);
|
|
||||||
}
|
|
||||||
$c = count($aIP);
|
|
||||||
|
|
||||||
if ($c != 8)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// All the pieces should be 16-bit hex strings. Are they?
|
|
||||||
foreach ($aIP as $piece)
|
|
||||||
{
|
|
||||||
if (!preg_match('#^[0-9a-fA-F]{4}$#s', sprintf('%04s', $piece)))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $original;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,36 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pre-transform that changes converts a boolean attribute to fixed CSS
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_AttrTransform_BoolToCSS extends HTMLPurifier_AttrTransform {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Name of boolean attribute that is trigger
|
|
||||||
*/
|
|
||||||
protected $attr;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* CSS declarations to add to style, needs trailing semicolon
|
|
||||||
*/
|
|
||||||
protected $css;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $attr string attribute name to convert from
|
|
||||||
* @param $css string CSS declarations to add to style (needs semicolon)
|
|
||||||
*/
|
|
||||||
public function __construct($attr, $css) {
|
|
||||||
$this->attr = $attr;
|
|
||||||
$this->css = $css;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function transform($attr, $config, $context) {
|
|
||||||
if (!isset($attr[$this->attr])) return $attr;
|
|
||||||
unset($attr[$this->attr]);
|
|
||||||
$this->prependCSS($attr, $this->css);
|
|
||||||
return $attr;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,58 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generic pre-transform that converts an attribute with a fixed number of
|
|
||||||
* values (enumerated) to CSS.
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_AttrTransform_EnumToCSS extends HTMLPurifier_AttrTransform {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Name of attribute to transform from
|
|
||||||
*/
|
|
||||||
protected $attr;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Lookup array of attribute values to CSS
|
|
||||||
*/
|
|
||||||
protected $enumToCSS = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Case sensitivity of the matching
|
|
||||||
* @warning Currently can only be guaranteed to work with ASCII
|
|
||||||
* values.
|
|
||||||
*/
|
|
||||||
protected $caseSensitive = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $attr String attribute name to transform from
|
|
||||||
* @param $enumToCSS Lookup array of attribute values to CSS
|
|
||||||
* @param $case_sensitive Boolean case sensitivity indicator, default false
|
|
||||||
*/
|
|
||||||
public function __construct($attr, $enum_to_css, $case_sensitive = false) {
|
|
||||||
$this->attr = $attr;
|
|
||||||
$this->enumToCSS = $enum_to_css;
|
|
||||||
$this->caseSensitive = (bool) $case_sensitive;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function transform($attr, $config, $context) {
|
|
||||||
|
|
||||||
if (!isset($attr[$this->attr])) return $attr;
|
|
||||||
|
|
||||||
$value = trim($attr[$this->attr]);
|
|
||||||
unset($attr[$this->attr]);
|
|
||||||
|
|
||||||
if (!$this->caseSensitive) $value = strtolower($value);
|
|
||||||
|
|
||||||
if (!isset($this->enumToCSS[$value])) {
|
|
||||||
return $attr;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->prependCSS($attr, $this->enumToCSS[$value]);
|
|
||||||
|
|
||||||
return $attr;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,27 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class for handling width/height length attribute transformations to CSS
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_AttrTransform_Length extends HTMLPurifier_AttrTransform
|
|
||||||
{
|
|
||||||
|
|
||||||
protected $name;
|
|
||||||
protected $cssName;
|
|
||||||
|
|
||||||
public function __construct($name, $css_name = null) {
|
|
||||||
$this->name = $name;
|
|
||||||
$this->cssName = $css_name ? $css_name : $name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function transform($attr, $config, $context) {
|
|
||||||
if (!isset($attr[$this->name])) return $attr;
|
|
||||||
$length = $this->confiscateAttr($attr, $this->name);
|
|
||||||
if(ctype_digit($length)) $length .= 'px';
|
|
||||||
$this->prependCSS($attr, $this->cssName . ":$length;");
|
|
||||||
return $attr;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,21 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pre-transform that changes deprecated name attribute to ID if necessary
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_AttrTransform_Name extends HTMLPurifier_AttrTransform
|
|
||||||
{
|
|
||||||
|
|
||||||
public function transform($attr, $config, $context) {
|
|
||||||
// Abort early if we're using relaxed definition of name
|
|
||||||
if ($config->get('HTML.Attr.Name.UseCDATA')) return $attr;
|
|
||||||
if (!isset($attr['name'])) return $attr;
|
|
||||||
$id = $this->confiscateAttr($attr, 'name');
|
|
||||||
if ( isset($attr['id'])) return $attr;
|
|
||||||
$attr['id'] = $id;
|
|
||||||
return $attr;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,27 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Post-transform that performs validation to the name attribute; if
|
|
||||||
* it is present with an equivalent id attribute, it is passed through;
|
|
||||||
* otherwise validation is performed.
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_AttrTransform_NameSync extends HTMLPurifier_AttrTransform
|
|
||||||
{
|
|
||||||
|
|
||||||
public function __construct() {
|
|
||||||
$this->idDef = new HTMLPurifier_AttrDef_HTML_ID();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function transform($attr, $config, $context) {
|
|
||||||
if (!isset($attr['name'])) return $attr;
|
|
||||||
$name = $attr['name'];
|
|
||||||
if (isset($attr['id']) && $attr['id'] === $name) return $attr;
|
|
||||||
$result = $this->idDef->validate($name, $config, $context);
|
|
||||||
if ($result === false) unset($attr['name']);
|
|
||||||
else $attr['name'] = $result;
|
|
||||||
return $attr;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes default type for all objects. Currently only supports flash.
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_AttrTransform_SafeObject extends HTMLPurifier_AttrTransform
|
|
||||||
{
|
|
||||||
public $name = "SafeObject";
|
|
||||||
|
|
||||||
function transform($attr, $config, $context) {
|
|
||||||
if (!isset($attr['type'])) $attr['type'] = 'application/x-shockwave-flash';
|
|
||||||
return $attr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets height/width defaults for <textarea>
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_AttrTransform_Textarea extends HTMLPurifier_AttrTransform
|
|
||||||
{
|
|
||||||
|
|
||||||
public function transform($attr, $config, $context) {
|
|
||||||
// Calculated from Firefox
|
|
||||||
if (!isset($attr['cols'])) $attr['cols'] = '22';
|
|
||||||
if (!isset($attr['rows'])) $attr['rows'] = '3';
|
|
||||||
return $attr;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,328 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Defines allowed CSS attributes and what their values are.
|
|
||||||
* @see HTMLPurifier_HTMLDefinition
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_CSSDefinition extends HTMLPurifier_Definition
|
|
||||||
{
|
|
||||||
|
|
||||||
public $type = 'CSS';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Assoc array of attribute name to definition object.
|
|
||||||
*/
|
|
||||||
public $info = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs the info array. The meat of this class.
|
|
||||||
*/
|
|
||||||
protected function doSetup($config) {
|
|
||||||
|
|
||||||
$this->info['text-align'] = new HTMLPurifier_AttrDef_Enum(
|
|
||||||
array('left', 'right', 'center', 'justify'), false);
|
|
||||||
|
|
||||||
$border_style =
|
|
||||||
$this->info['border-bottom-style'] =
|
|
||||||
$this->info['border-right-style'] =
|
|
||||||
$this->info['border-left-style'] =
|
|
||||||
$this->info['border-top-style'] = new HTMLPurifier_AttrDef_Enum(
|
|
||||||
array('none', 'hidden', 'dotted', 'dashed', 'solid', 'double',
|
|
||||||
'groove', 'ridge', 'inset', 'outset'), false);
|
|
||||||
|
|
||||||
$this->info['border-style'] = new HTMLPurifier_AttrDef_CSS_Multiple($border_style);
|
|
||||||
|
|
||||||
$this->info['clear'] = new HTMLPurifier_AttrDef_Enum(
|
|
||||||
array('none', 'left', 'right', 'both'), false);
|
|
||||||
$this->info['float'] = new HTMLPurifier_AttrDef_Enum(
|
|
||||||
array('none', 'left', 'right'), false);
|
|
||||||
$this->info['font-style'] = new HTMLPurifier_AttrDef_Enum(
|
|
||||||
array('normal', 'italic', 'oblique'), false);
|
|
||||||
$this->info['font-variant'] = new HTMLPurifier_AttrDef_Enum(
|
|
||||||
array('normal', 'small-caps'), false);
|
|
||||||
|
|
||||||
$uri_or_none = new HTMLPurifier_AttrDef_CSS_Composite(
|
|
||||||
array(
|
|
||||||
new HTMLPurifier_AttrDef_Enum(array('none')),
|
|
||||||
new HTMLPurifier_AttrDef_CSS_URI()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->info['list-style-position'] = new HTMLPurifier_AttrDef_Enum(
|
|
||||||
array('inside', 'outside'), false);
|
|
||||||
$this->info['list-style-type'] = new HTMLPurifier_AttrDef_Enum(
|
|
||||||
array('disc', 'circle', 'square', 'decimal', 'lower-roman',
|
|
||||||
'upper-roman', 'lower-alpha', 'upper-alpha', 'none'), false);
|
|
||||||
$this->info['list-style-image'] = $uri_or_none;
|
|
||||||
|
|
||||||
$this->info['list-style'] = new HTMLPurifier_AttrDef_CSS_ListStyle($config);
|
|
||||||
|
|
||||||
$this->info['text-transform'] = new HTMLPurifier_AttrDef_Enum(
|
|
||||||
array('capitalize', 'uppercase', 'lowercase', 'none'), false);
|
|
||||||
$this->info['color'] = new HTMLPurifier_AttrDef_CSS_Color();
|
|
||||||
|
|
||||||
$this->info['background-image'] = $uri_or_none;
|
|
||||||
$this->info['background-repeat'] = new HTMLPurifier_AttrDef_Enum(
|
|
||||||
array('repeat', 'repeat-x', 'repeat-y', 'no-repeat')
|
|
||||||
);
|
|
||||||
$this->info['background-attachment'] = new HTMLPurifier_AttrDef_Enum(
|
|
||||||
array('scroll', 'fixed')
|
|
||||||
);
|
|
||||||
$this->info['background-position'] = new HTMLPurifier_AttrDef_CSS_BackgroundPosition();
|
|
||||||
|
|
||||||
$border_color =
|
|
||||||
$this->info['border-top-color'] =
|
|
||||||
$this->info['border-bottom-color'] =
|
|
||||||
$this->info['border-left-color'] =
|
|
||||||
$this->info['border-right-color'] =
|
|
||||||
$this->info['background-color'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
|
|
||||||
new HTMLPurifier_AttrDef_Enum(array('transparent')),
|
|
||||||
new HTMLPurifier_AttrDef_CSS_Color()
|
|
||||||
));
|
|
||||||
|
|
||||||
$this->info['background'] = new HTMLPurifier_AttrDef_CSS_Background($config);
|
|
||||||
|
|
||||||
$this->info['border-color'] = new HTMLPurifier_AttrDef_CSS_Multiple($border_color);
|
|
||||||
|
|
||||||
$border_width =
|
|
||||||
$this->info['border-top-width'] =
|
|
||||||
$this->info['border-bottom-width'] =
|
|
||||||
$this->info['border-left-width'] =
|
|
||||||
$this->info['border-right-width'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
|
|
||||||
new HTMLPurifier_AttrDef_Enum(array('thin', 'medium', 'thick')),
|
|
||||||
new HTMLPurifier_AttrDef_CSS_Length('0') //disallow negative
|
|
||||||
));
|
|
||||||
|
|
||||||
$this->info['border-width'] = new HTMLPurifier_AttrDef_CSS_Multiple($border_width);
|
|
||||||
|
|
||||||
$this->info['letter-spacing'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
|
|
||||||
new HTMLPurifier_AttrDef_Enum(array('normal')),
|
|
||||||
new HTMLPurifier_AttrDef_CSS_Length()
|
|
||||||
));
|
|
||||||
|
|
||||||
$this->info['word-spacing'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
|
|
||||||
new HTMLPurifier_AttrDef_Enum(array('normal')),
|
|
||||||
new HTMLPurifier_AttrDef_CSS_Length()
|
|
||||||
));
|
|
||||||
|
|
||||||
$this->info['font-size'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
|
|
||||||
new HTMLPurifier_AttrDef_Enum(array('xx-small', 'x-small',
|
|
||||||
'small', 'medium', 'large', 'x-large', 'xx-large',
|
|
||||||
'larger', 'smaller')),
|
|
||||||
new HTMLPurifier_AttrDef_CSS_Percentage(),
|
|
||||||
new HTMLPurifier_AttrDef_CSS_Length()
|
|
||||||
));
|
|
||||||
|
|
||||||
$this->info['line-height'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
|
|
||||||
new HTMLPurifier_AttrDef_Enum(array('normal')),
|
|
||||||
new HTMLPurifier_AttrDef_CSS_Number(true), // no negatives
|
|
||||||
new HTMLPurifier_AttrDef_CSS_Length('0'),
|
|
||||||
new HTMLPurifier_AttrDef_CSS_Percentage(true)
|
|
||||||
));
|
|
||||||
|
|
||||||
$margin =
|
|
||||||
$this->info['margin-top'] =
|
|
||||||
$this->info['margin-bottom'] =
|
|
||||||
$this->info['margin-left'] =
|
|
||||||
$this->info['margin-right'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
|
|
||||||
new HTMLPurifier_AttrDef_CSS_Length(),
|
|
||||||
new HTMLPurifier_AttrDef_CSS_Percentage(),
|
|
||||||
new HTMLPurifier_AttrDef_Enum(array('auto'))
|
|
||||||
));
|
|
||||||
|
|
||||||
$this->info['margin'] = new HTMLPurifier_AttrDef_CSS_Multiple($margin);
|
|
||||||
|
|
||||||
// non-negative
|
|
||||||
$padding =
|
|
||||||
$this->info['padding-top'] =
|
|
||||||
$this->info['padding-bottom'] =
|
|
||||||
$this->info['padding-left'] =
|
|
||||||
$this->info['padding-right'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
|
|
||||||
new HTMLPurifier_AttrDef_CSS_Length('0'),
|
|
||||||
new HTMLPurifier_AttrDef_CSS_Percentage(true)
|
|
||||||
));
|
|
||||||
|
|
||||||
$this->info['padding'] = new HTMLPurifier_AttrDef_CSS_Multiple($padding);
|
|
||||||
|
|
||||||
$this->info['text-indent'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
|
|
||||||
new HTMLPurifier_AttrDef_CSS_Length(),
|
|
||||||
new HTMLPurifier_AttrDef_CSS_Percentage()
|
|
||||||
));
|
|
||||||
|
|
||||||
$trusted_wh = new HTMLPurifier_AttrDef_CSS_Composite(array(
|
|
||||||
new HTMLPurifier_AttrDef_CSS_Length('0'),
|
|
||||||
new HTMLPurifier_AttrDef_CSS_Percentage(true),
|
|
||||||
new HTMLPurifier_AttrDef_Enum(array('auto'))
|
|
||||||
));
|
|
||||||
$max = $config->get('CSS.MaxImgLength');
|
|
||||||
|
|
||||||
$this->info['width'] =
|
|
||||||
$this->info['height'] =
|
|
||||||
$max === null ?
|
|
||||||
$trusted_wh :
|
|
||||||
new HTMLPurifier_AttrDef_Switch('img',
|
|
||||||
// For img tags:
|
|
||||||
new HTMLPurifier_AttrDef_CSS_Composite(array(
|
|
||||||
new HTMLPurifier_AttrDef_CSS_Length('0', $max),
|
|
||||||
new HTMLPurifier_AttrDef_Enum(array('auto'))
|
|
||||||
)),
|
|
||||||
// For everyone else:
|
|
||||||
$trusted_wh
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->info['text-decoration'] = new HTMLPurifier_AttrDef_CSS_TextDecoration();
|
|
||||||
|
|
||||||
$this->info['font-family'] = new HTMLPurifier_AttrDef_CSS_FontFamily();
|
|
||||||
|
|
||||||
// this could use specialized code
|
|
||||||
$this->info['font-weight'] = new HTMLPurifier_AttrDef_Enum(
|
|
||||||
array('normal', 'bold', 'bolder', 'lighter', '100', '200', '300',
|
|
||||||
'400', '500', '600', '700', '800', '900'), false);
|
|
||||||
|
|
||||||
// MUST be called after other font properties, as it references
|
|
||||||
// a CSSDefinition object
|
|
||||||
$this->info['font'] = new HTMLPurifier_AttrDef_CSS_Font($config);
|
|
||||||
|
|
||||||
// same here
|
|
||||||
$this->info['border'] =
|
|
||||||
$this->info['border-bottom'] =
|
|
||||||
$this->info['border-top'] =
|
|
||||||
$this->info['border-left'] =
|
|
||||||
$this->info['border-right'] = new HTMLPurifier_AttrDef_CSS_Border($config);
|
|
||||||
|
|
||||||
$this->info['border-collapse'] = new HTMLPurifier_AttrDef_Enum(array(
|
|
||||||
'collapse', 'separate'));
|
|
||||||
|
|
||||||
$this->info['caption-side'] = new HTMLPurifier_AttrDef_Enum(array(
|
|
||||||
'top', 'bottom'));
|
|
||||||
|
|
||||||
$this->info['table-layout'] = new HTMLPurifier_AttrDef_Enum(array(
|
|
||||||
'auto', 'fixed'));
|
|
||||||
|
|
||||||
$this->info['vertical-align'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
|
|
||||||
new HTMLPurifier_AttrDef_Enum(array('baseline', 'sub', 'super',
|
|
||||||
'top', 'text-top', 'middle', 'bottom', 'text-bottom')),
|
|
||||||
new HTMLPurifier_AttrDef_CSS_Length(),
|
|
||||||
new HTMLPurifier_AttrDef_CSS_Percentage()
|
|
||||||
));
|
|
||||||
|
|
||||||
$this->info['border-spacing'] = new HTMLPurifier_AttrDef_CSS_Multiple(new HTMLPurifier_AttrDef_CSS_Length(), 2);
|
|
||||||
|
|
||||||
// These CSS properties don't work on many browsers, but we live
|
|
||||||
// in THE FUTURE!
|
|
||||||
$this->info['white-space'] = new HTMLPurifier_AttrDef_Enum(array('nowrap', 'normal', 'pre', 'pre-wrap', 'pre-line'));
|
|
||||||
|
|
||||||
if ($config->get('CSS.Proprietary')) {
|
|
||||||
$this->doSetupProprietary($config);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($config->get('CSS.AllowTricky')) {
|
|
||||||
$this->doSetupTricky($config);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($config->get('CSS.Trusted')) {
|
|
||||||
$this->doSetupTrusted($config);
|
|
||||||
}
|
|
||||||
|
|
||||||
$allow_important = $config->get('CSS.AllowImportant');
|
|
||||||
// wrap all attr-defs with decorator that handles !important
|
|
||||||
foreach ($this->info as $k => $v) {
|
|
||||||
$this->info[$k] = new HTMLPurifier_AttrDef_CSS_ImportantDecorator($v, $allow_important);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->setupConfigStuff($config);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function doSetupProprietary($config) {
|
|
||||||
// Internet Explorer only scrollbar colors
|
|
||||||
$this->info['scrollbar-arrow-color'] = new HTMLPurifier_AttrDef_CSS_Color();
|
|
||||||
$this->info['scrollbar-base-color'] = new HTMLPurifier_AttrDef_CSS_Color();
|
|
||||||
$this->info['scrollbar-darkshadow-color'] = new HTMLPurifier_AttrDef_CSS_Color();
|
|
||||||
$this->info['scrollbar-face-color'] = new HTMLPurifier_AttrDef_CSS_Color();
|
|
||||||
$this->info['scrollbar-highlight-color'] = new HTMLPurifier_AttrDef_CSS_Color();
|
|
||||||
$this->info['scrollbar-shadow-color'] = new HTMLPurifier_AttrDef_CSS_Color();
|
|
||||||
|
|
||||||
// technically not proprietary, but CSS3, and no one supports it
|
|
||||||
$this->info['opacity'] = new HTMLPurifier_AttrDef_CSS_AlphaValue();
|
|
||||||
$this->info['-moz-opacity'] = new HTMLPurifier_AttrDef_CSS_AlphaValue();
|
|
||||||
$this->info['-khtml-opacity'] = new HTMLPurifier_AttrDef_CSS_AlphaValue();
|
|
||||||
|
|
||||||
// only opacity, for now
|
|
||||||
$this->info['filter'] = new HTMLPurifier_AttrDef_CSS_Filter();
|
|
||||||
|
|
||||||
// more CSS3
|
|
||||||
$this->info['page-break-after'] =
|
|
||||||
$this->info['page-break-before'] = new HTMLPurifier_AttrDef_Enum(array('auto','always','avoid','left','right'));
|
|
||||||
$this->info['page-break-inside'] = new HTMLPurifier_AttrDef_Enum(array('auto','avoid'));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function doSetupTricky($config) {
|
|
||||||
$this->info['display'] = new HTMLPurifier_AttrDef_Enum(array(
|
|
||||||
'inline', 'block', 'list-item', 'run-in', 'compact',
|
|
||||||
'marker', 'table', 'inline-block', 'inline-table', 'table-row-group',
|
|
||||||
'table-header-group', 'table-footer-group', 'table-row',
|
|
||||||
'table-column-group', 'table-column', 'table-cell', 'table-caption', 'none'
|
|
||||||
));
|
|
||||||
$this->info['visibility'] = new HTMLPurifier_AttrDef_Enum(array(
|
|
||||||
'visible', 'hidden', 'collapse'
|
|
||||||
));
|
|
||||||
$this->info['overflow'] = new HTMLPurifier_AttrDef_Enum(array('visible', 'hidden', 'auto', 'scroll'));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function doSetupTrusted($config) {
|
|
||||||
$this->info['position'] = new HTMLPurifier_AttrDef_Enum(array(
|
|
||||||
'static', 'relative', 'absolute', 'fixed'
|
|
||||||
));
|
|
||||||
$this->info['top'] =
|
|
||||||
$this->info['left'] =
|
|
||||||
$this->info['right'] =
|
|
||||||
$this->info['bottom'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
|
|
||||||
new HTMLPurifier_AttrDef_CSS_Length(),
|
|
||||||
new HTMLPurifier_AttrDef_CSS_Percentage(),
|
|
||||||
new HTMLPurifier_AttrDef_Enum(array('auto')),
|
|
||||||
));
|
|
||||||
$this->info['z-index'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
|
|
||||||
new HTMLPurifier_AttrDef_Integer(),
|
|
||||||
new HTMLPurifier_AttrDef_Enum(array('auto')),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs extra config-based processing. Based off of
|
|
||||||
* HTMLPurifier_HTMLDefinition.
|
|
||||||
* @todo Refactor duplicate elements into common class (probably using
|
|
||||||
* composition, not inheritance).
|
|
||||||
*/
|
|
||||||
protected function setupConfigStuff($config) {
|
|
||||||
|
|
||||||
// setup allowed elements
|
|
||||||
$support = "(for information on implementing this, see the ".
|
|
||||||
"support forums) ";
|
|
||||||
$allowed_properties = $config->get('CSS.AllowedProperties');
|
|
||||||
if ($allowed_properties !== null) {
|
|
||||||
foreach ($this->info as $name => $d) {
|
|
||||||
if(!isset($allowed_properties[$name])) unset($this->info[$name]);
|
|
||||||
unset($allowed_properties[$name]);
|
|
||||||
}
|
|
||||||
// emit errors
|
|
||||||
foreach ($allowed_properties as $name => $d) {
|
|
||||||
// :TODO: Is this htmlspecialchars() call really necessary?
|
|
||||||
$name = htmlspecialchars($name);
|
|
||||||
trigger_error("Style attribute '$name' is not supported $support", E_USER_WARNING);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$forbidden_properties = $config->get('CSS.ForbiddenProperties');
|
|
||||||
if ($forbidden_properties !== null) {
|
|
||||||
foreach ($this->info as $name => $d) {
|
|
||||||
if (isset($forbidden_properties[$name])) {
|
|
||||||
unset($this->info[$name]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,120 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Definition for list containers ul and ol.
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_ChildDef_List extends HTMLPurifier_ChildDef
|
|
||||||
{
|
|
||||||
public $type = 'list';
|
|
||||||
// lying a little bit, so that we can handle ul and ol ourselves
|
|
||||||
// XXX: This whole business with 'wrap' is all a bit unsatisfactory
|
|
||||||
public $elements = array('li' => true, 'ul' => true, 'ol' => true);
|
|
||||||
public function validateChildren($tokens_of_children, $config, $context) {
|
|
||||||
// Flag for subclasses
|
|
||||||
$this->whitespace = false;
|
|
||||||
|
|
||||||
// if there are no tokens, delete parent node
|
|
||||||
if (empty($tokens_of_children)) return false;
|
|
||||||
|
|
||||||
// the new set of children
|
|
||||||
$result = array();
|
|
||||||
|
|
||||||
// current depth into the nest
|
|
||||||
$nesting = 0;
|
|
||||||
|
|
||||||
// a little sanity check to make sure it's not ALL whitespace
|
|
||||||
$all_whitespace = true;
|
|
||||||
|
|
||||||
$seen_li = false;
|
|
||||||
$need_close_li = false;
|
|
||||||
|
|
||||||
foreach ($tokens_of_children as $token) {
|
|
||||||
if (!empty($token->is_whitespace)) {
|
|
||||||
$result[] = $token;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$all_whitespace = false; // phew, we're not talking about whitespace
|
|
||||||
|
|
||||||
if ($nesting == 1 && $need_close_li) {
|
|
||||||
$result[] = new HTMLPurifier_Token_End('li');
|
|
||||||
$nesting--;
|
|
||||||
$need_close_li = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$is_child = ($nesting == 0);
|
|
||||||
|
|
||||||
if ($token instanceof HTMLPurifier_Token_Start) {
|
|
||||||
$nesting++;
|
|
||||||
} elseif ($token instanceof HTMLPurifier_Token_End) {
|
|
||||||
$nesting--;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($is_child) {
|
|
||||||
if ($token->name === 'li') {
|
|
||||||
// good
|
|
||||||
$seen_li = true;
|
|
||||||
} elseif ($token->name === 'ul' || $token->name === 'ol') {
|
|
||||||
// we want to tuck this into the previous li
|
|
||||||
$need_close_li = true;
|
|
||||||
$nesting++;
|
|
||||||
if (!$seen_li) {
|
|
||||||
// create a new li element
|
|
||||||
$result[] = new HTMLPurifier_Token_Start('li');
|
|
||||||
} else {
|
|
||||||
// backtrack until </li> found
|
|
||||||
while(true) {
|
|
||||||
$t = array_pop($result);
|
|
||||||
if ($t instanceof HTMLPurifier_Token_End) {
|
|
||||||
// XXX actually, these invariants could very plausibly be violated
|
|
||||||
// if we are doing silly things with modifying the set of allowed elements.
|
|
||||||
// FORTUNATELY, it doesn't make a difference, since the allowed
|
|
||||||
// elements are hard-coded here!
|
|
||||||
if ($t->name !== 'li') {
|
|
||||||
trigger_error("Only li present invariant violated in List ChildDef", E_USER_ERROR);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
} elseif ($t instanceof HTMLPurifier_Token_Empty) { // bleagh
|
|
||||||
if ($t->name !== 'li') {
|
|
||||||
trigger_error("Only li present invariant violated in List ChildDef", E_USER_ERROR);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// XXX this should have a helper for it...
|
|
||||||
$result[] = new HTMLPurifier_Token_Start('li', $t->attr, $t->line, $t->col, $t->armor);
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
if (!$t->is_whitespace) {
|
|
||||||
trigger_error("Only whitespace present invariant violated in List ChildDef", E_USER_ERROR);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// start wrapping (this doesn't precisely mimic
|
|
||||||
// browser behavior, but what browsers do is kind of
|
|
||||||
// hard to mimic in a standards compliant way
|
|
||||||
// XXX Actually, this has no impact in practice,
|
|
||||||
// because this gets handled earlier. Arguably,
|
|
||||||
// we should rip out all of that processing
|
|
||||||
$result[] = new HTMLPurifier_Token_Start('li');
|
|
||||||
$nesting++;
|
|
||||||
$seen_li = true;
|
|
||||||
$need_close_li = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$result[] = $token;
|
|
||||||
}
|
|
||||||
if ($need_close_li) {
|
|
||||||
$result[] = new HTMLPurifier_Token_End('li');
|
|
||||||
}
|
|
||||||
if (empty($result)) return false;
|
|
||||||
if ($all_whitespace) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if ($tokens_of_children == $result) return true;
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,26 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Definition that allows a set of elements, and allows no children.
|
|
||||||
* @note This is a hack to reuse code from HTMLPurifier_ChildDef_Required,
|
|
||||||
* really, one shouldn't inherit from the other. Only altered behavior
|
|
||||||
* is to overload a returned false with an array. Thus, it will never
|
|
||||||
* return false.
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_ChildDef_Optional extends HTMLPurifier_ChildDef_Required
|
|
||||||
{
|
|
||||||
public $allow_empty = true;
|
|
||||||
public $type = 'optional';
|
|
||||||
public function validateChildren($tokens_of_children, $config, $context) {
|
|
||||||
$result = parent::validateChildren($tokens_of_children, $config, $context);
|
|
||||||
// we assume that $tokens_of_children is not modified
|
|
||||||
if ($result === false) {
|
|
||||||
if (empty($tokens_of_children)) return true;
|
|
||||||
elseif ($this->whitespace) return $tokens_of_children;
|
|
||||||
else return array();
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,117 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Definition that allows a set of elements, but disallows empty children.
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_ChildDef_Required extends HTMLPurifier_ChildDef
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Lookup table of allowed elements.
|
|
||||||
* @public
|
|
||||||
*/
|
|
||||||
public $elements = array();
|
|
||||||
/**
|
|
||||||
* Whether or not the last passed node was all whitespace.
|
|
||||||
*/
|
|
||||||
protected $whitespace = false;
|
|
||||||
/**
|
|
||||||
* @param $elements List of allowed element names (lowercase).
|
|
||||||
*/
|
|
||||||
public function __construct($elements) {
|
|
||||||
if (is_string($elements)) {
|
|
||||||
$elements = str_replace(' ', '', $elements);
|
|
||||||
$elements = explode('|', $elements);
|
|
||||||
}
|
|
||||||
$keys = array_keys($elements);
|
|
||||||
if ($keys == array_keys($keys)) {
|
|
||||||
$elements = array_flip($elements);
|
|
||||||
foreach ($elements as $i => $x) {
|
|
||||||
$elements[$i] = true;
|
|
||||||
if (empty($i)) unset($elements[$i]); // remove blank
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$this->elements = $elements;
|
|
||||||
}
|
|
||||||
public $allow_empty = false;
|
|
||||||
public $type = 'required';
|
|
||||||
public function validateChildren($tokens_of_children, $config, $context) {
|
|
||||||
// Flag for subclasses
|
|
||||||
$this->whitespace = false;
|
|
||||||
|
|
||||||
// if there are no tokens, delete parent node
|
|
||||||
if (empty($tokens_of_children)) return false;
|
|
||||||
|
|
||||||
// the new set of children
|
|
||||||
$result = array();
|
|
||||||
|
|
||||||
// current depth into the nest
|
|
||||||
$nesting = 0;
|
|
||||||
|
|
||||||
// whether or not we're deleting a node
|
|
||||||
$is_deleting = false;
|
|
||||||
|
|
||||||
// whether or not parsed character data is allowed
|
|
||||||
// this controls whether or not we silently drop a tag
|
|
||||||
// or generate escaped HTML from it
|
|
||||||
$pcdata_allowed = isset($this->elements['#PCDATA']);
|
|
||||||
|
|
||||||
// a little sanity check to make sure it's not ALL whitespace
|
|
||||||
$all_whitespace = true;
|
|
||||||
|
|
||||||
// some configuration
|
|
||||||
$escape_invalid_children = $config->get('Core.EscapeInvalidChildren');
|
|
||||||
|
|
||||||
// generator
|
|
||||||
$gen = new HTMLPurifier_Generator($config, $context);
|
|
||||||
|
|
||||||
foreach ($tokens_of_children as $token) {
|
|
||||||
if (!empty($token->is_whitespace)) {
|
|
||||||
$result[] = $token;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$all_whitespace = false; // phew, we're not talking about whitespace
|
|
||||||
|
|
||||||
$is_child = ($nesting == 0);
|
|
||||||
|
|
||||||
if ($token instanceof HTMLPurifier_Token_Start) {
|
|
||||||
$nesting++;
|
|
||||||
} elseif ($token instanceof HTMLPurifier_Token_End) {
|
|
||||||
$nesting--;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($is_child) {
|
|
||||||
$is_deleting = false;
|
|
||||||
if (!isset($this->elements[$token->name])) {
|
|
||||||
$is_deleting = true;
|
|
||||||
if ($pcdata_allowed && $token instanceof HTMLPurifier_Token_Text) {
|
|
||||||
$result[] = $token;
|
|
||||||
} elseif ($pcdata_allowed && $escape_invalid_children) {
|
|
||||||
$result[] = new HTMLPurifier_Token_Text(
|
|
||||||
$gen->generateFromToken($token)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!$is_deleting || ($pcdata_allowed && $token instanceof HTMLPurifier_Token_Text)) {
|
|
||||||
$result[] = $token;
|
|
||||||
} elseif ($pcdata_allowed && $escape_invalid_children) {
|
|
||||||
$result[] =
|
|
||||||
new HTMLPurifier_Token_Text(
|
|
||||||
$gen->generateFromToken($token)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
// drop silently
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (empty($result)) return false;
|
|
||||||
if ($all_whitespace) {
|
|
||||||
$this->whitespace = true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if ($tokens_of_children == $result) return true;
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,88 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Takes the contents of blockquote when in strict and reformats for validation.
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_ChildDef_StrictBlockquote extends HTMLPurifier_ChildDef_Required
|
|
||||||
{
|
|
||||||
protected $real_elements;
|
|
||||||
protected $fake_elements;
|
|
||||||
public $allow_empty = true;
|
|
||||||
public $type = 'strictblockquote';
|
|
||||||
protected $init = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @note We don't want MakeWellFormed to auto-close inline elements since
|
|
||||||
* they might be allowed.
|
|
||||||
*/
|
|
||||||
public function getAllowedElements($config) {
|
|
||||||
$this->init($config);
|
|
||||||
return $this->fake_elements;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function validateChildren($tokens_of_children, $config, $context) {
|
|
||||||
|
|
||||||
$this->init($config);
|
|
||||||
|
|
||||||
// trick the parent class into thinking it allows more
|
|
||||||
$this->elements = $this->fake_elements;
|
|
||||||
$result = parent::validateChildren($tokens_of_children, $config, $context);
|
|
||||||
$this->elements = $this->real_elements;
|
|
||||||
|
|
||||||
if ($result === false) return array();
|
|
||||||
if ($result === true) $result = $tokens_of_children;
|
|
||||||
|
|
||||||
$def = $config->getHTMLDefinition();
|
|
||||||
$block_wrap_start = new HTMLPurifier_Token_Start($def->info_block_wrapper);
|
|
||||||
$block_wrap_end = new HTMLPurifier_Token_End( $def->info_block_wrapper);
|
|
||||||
$is_inline = false;
|
|
||||||
$depth = 0;
|
|
||||||
$ret = array();
|
|
||||||
|
|
||||||
// assuming that there are no comment tokens
|
|
||||||
foreach ($result as $i => $token) {
|
|
||||||
$token = $result[$i];
|
|
||||||
// ifs are nested for readability
|
|
||||||
if (!$is_inline) {
|
|
||||||
if (!$depth) {
|
|
||||||
if (
|
|
||||||
($token instanceof HTMLPurifier_Token_Text && !$token->is_whitespace) ||
|
|
||||||
(!$token instanceof HTMLPurifier_Token_Text && !isset($this->elements[$token->name]))
|
|
||||||
) {
|
|
||||||
$is_inline = true;
|
|
||||||
$ret[] = $block_wrap_start;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!$depth) {
|
|
||||||
// starting tokens have been inline text / empty
|
|
||||||
if ($token instanceof HTMLPurifier_Token_Start || $token instanceof HTMLPurifier_Token_Empty) {
|
|
||||||
if (isset($this->elements[$token->name])) {
|
|
||||||
// ended
|
|
||||||
$ret[] = $block_wrap_end;
|
|
||||||
$is_inline = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$ret[] = $token;
|
|
||||||
if ($token instanceof HTMLPurifier_Token_Start) $depth++;
|
|
||||||
if ($token instanceof HTMLPurifier_Token_End) $depth--;
|
|
||||||
}
|
|
||||||
if ($is_inline) $ret[] = $block_wrap_end;
|
|
||||||
return $ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function init($config) {
|
|
||||||
if (!$this->init) {
|
|
||||||
$def = $config->getHTMLDefinition();
|
|
||||||
// allow all inline elements
|
|
||||||
$this->real_elements = $this->elements;
|
|
||||||
$this->fake_elements = $def->info_content_sets['Flow'];
|
|
||||||
$this->fake_elements['#PCDATA'] = true;
|
|
||||||
$this->init = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,227 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Definition for tables. The general idea is to extract out all of the
|
|
||||||
* essential bits, and then reconstruct it later.
|
|
||||||
*
|
|
||||||
* This is a bit confusing, because the DTDs and the W3C
|
|
||||||
* validators seem to disagree on the appropriate definition. The
|
|
||||||
* DTD claims:
|
|
||||||
*
|
|
||||||
* (CAPTION?, (COL*|COLGROUP*), THEAD?, TFOOT?, TBODY+)
|
|
||||||
*
|
|
||||||
* But actually, the HTML4 spec then has this to say:
|
|
||||||
*
|
|
||||||
* The TBODY start tag is always required except when the table
|
|
||||||
* contains only one table body and no table head or foot sections.
|
|
||||||
* The TBODY end tag may always be safely omitted.
|
|
||||||
*
|
|
||||||
* So the DTD is kind of wrong. The validator is, unfortunately, kind
|
|
||||||
* of on crack.
|
|
||||||
*
|
|
||||||
* The definition changed again in XHTML1.1; and in my opinion, this
|
|
||||||
* formulation makes the most sense.
|
|
||||||
*
|
|
||||||
* caption?, ( col* | colgroup* ), (( thead?, tfoot?, tbody+ ) | ( tr+ ))
|
|
||||||
*
|
|
||||||
* Essentially, we have two modes: thead/tfoot/tbody mode, and tr mode.
|
|
||||||
* If we encounter a thead, tfoot or tbody, we are placed in the former
|
|
||||||
* mode, and we *must* wrap any stray tr segments with a tbody. But if
|
|
||||||
* we don't run into any of them, just have tr tags is OK.
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_ChildDef_Table extends HTMLPurifier_ChildDef
|
|
||||||
{
|
|
||||||
public $allow_empty = false;
|
|
||||||
public $type = 'table';
|
|
||||||
public $elements = array('tr' => true, 'tbody' => true, 'thead' => true,
|
|
||||||
'tfoot' => true, 'caption' => true, 'colgroup' => true, 'col' => true);
|
|
||||||
public function __construct() {}
|
|
||||||
public function validateChildren($tokens_of_children, $config, $context) {
|
|
||||||
if (empty($tokens_of_children)) return false;
|
|
||||||
|
|
||||||
// this ensures that the loop gets run one last time before closing
|
|
||||||
// up. It's a little bit of a hack, but it works! Just make sure you
|
|
||||||
// get rid of the token later.
|
|
||||||
$tokens_of_children[] = false;
|
|
||||||
|
|
||||||
// only one of these elements is allowed in a table
|
|
||||||
$caption = false;
|
|
||||||
$thead = false;
|
|
||||||
$tfoot = false;
|
|
||||||
|
|
||||||
// as many of these as you want
|
|
||||||
$cols = array();
|
|
||||||
$content = array();
|
|
||||||
|
|
||||||
$nesting = 0; // current depth so we can determine nodes
|
|
||||||
$is_collecting = false; // are we globbing together tokens to package
|
|
||||||
// into one of the collectors?
|
|
||||||
$collection = array(); // collected nodes
|
|
||||||
$tag_index = 0; // the first node might be whitespace,
|
|
||||||
// so this tells us where the start tag is
|
|
||||||
$tbody_mode = false; // if true, then we need to wrap any stray
|
|
||||||
// <tr>s with a <tbody>.
|
|
||||||
|
|
||||||
foreach ($tokens_of_children as $token) {
|
|
||||||
$is_child = ($nesting == 0);
|
|
||||||
|
|
||||||
if ($token === false) {
|
|
||||||
// terminating sequence started
|
|
||||||
} elseif ($token instanceof HTMLPurifier_Token_Start) {
|
|
||||||
$nesting++;
|
|
||||||
} elseif ($token instanceof HTMLPurifier_Token_End) {
|
|
||||||
$nesting--;
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle node collection
|
|
||||||
if ($is_collecting) {
|
|
||||||
if ($is_child) {
|
|
||||||
// okay, let's stash the tokens away
|
|
||||||
// first token tells us the type of the collection
|
|
||||||
switch ($collection[$tag_index]->name) {
|
|
||||||
case 'tbody':
|
|
||||||
$tbody_mode = true;
|
|
||||||
case 'tr':
|
|
||||||
$content[] = $collection;
|
|
||||||
break;
|
|
||||||
case 'caption':
|
|
||||||
if ($caption !== false) break;
|
|
||||||
$caption = $collection;
|
|
||||||
break;
|
|
||||||
case 'thead':
|
|
||||||
case 'tfoot':
|
|
||||||
$tbody_mode = true;
|
|
||||||
// XXX This breaks rendering properties with
|
|
||||||
// Firefox, which never floats a <thead> to
|
|
||||||
// the top. Ever. (Our scheme will float the
|
|
||||||
// first <thead> to the top.) So maybe
|
|
||||||
// <thead>s that are not first should be
|
|
||||||
// turned into <tbody>? Very tricky, indeed.
|
|
||||||
|
|
||||||
// access the appropriate variable, $thead or $tfoot
|
|
||||||
$var = $collection[$tag_index]->name;
|
|
||||||
if ($$var === false) {
|
|
||||||
$$var = $collection;
|
|
||||||
} else {
|
|
||||||
// Oops, there's a second one! What
|
|
||||||
// should we do? Current behavior is to
|
|
||||||
// transmutate the first and last entries into
|
|
||||||
// tbody tags, and then put into content.
|
|
||||||
// Maybe a better idea is to *attach
|
|
||||||
// it* to the existing thead or tfoot?
|
|
||||||
// We don't do this, because Firefox
|
|
||||||
// doesn't float an extra tfoot to the
|
|
||||||
// bottom like it does for the first one.
|
|
||||||
$collection[$tag_index]->name = 'tbody';
|
|
||||||
$collection[count($collection)-1]->name = 'tbody';
|
|
||||||
$content[] = $collection;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'colgroup':
|
|
||||||
$cols[] = $collection;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
$collection = array();
|
|
||||||
$is_collecting = false;
|
|
||||||
$tag_index = 0;
|
|
||||||
} else {
|
|
||||||
// add the node to the collection
|
|
||||||
$collection[] = $token;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// terminate
|
|
||||||
if ($token === false) break;
|
|
||||||
|
|
||||||
if ($is_child) {
|
|
||||||
// determine what we're dealing with
|
|
||||||
if ($token->name == 'col') {
|
|
||||||
// the only empty tag in the possie, we can handle it
|
|
||||||
// immediately
|
|
||||||
$cols[] = array_merge($collection, array($token));
|
|
||||||
$collection = array();
|
|
||||||
$tag_index = 0;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
switch($token->name) {
|
|
||||||
case 'caption':
|
|
||||||
case 'colgroup':
|
|
||||||
case 'thead':
|
|
||||||
case 'tfoot':
|
|
||||||
case 'tbody':
|
|
||||||
case 'tr':
|
|
||||||
$is_collecting = true;
|
|
||||||
$collection[] = $token;
|
|
||||||
continue;
|
|
||||||
default:
|
|
||||||
if (!empty($token->is_whitespace)) {
|
|
||||||
$collection[] = $token;
|
|
||||||
$tag_index++;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($content)) return false;
|
|
||||||
|
|
||||||
$ret = array();
|
|
||||||
if ($caption !== false) $ret = array_merge($ret, $caption);
|
|
||||||
if ($cols !== false) foreach ($cols as $token_array) $ret = array_merge($ret, $token_array);
|
|
||||||
if ($thead !== false) $ret = array_merge($ret, $thead);
|
|
||||||
if ($tfoot !== false) $ret = array_merge($ret, $tfoot);
|
|
||||||
|
|
||||||
if ($tbody_mode) {
|
|
||||||
// a little tricky, since the start of the collection may be
|
|
||||||
// whitespace
|
|
||||||
$inside_tbody = false;
|
|
||||||
foreach ($content as $token_array) {
|
|
||||||
// find the starting token
|
|
||||||
foreach ($token_array as $t) {
|
|
||||||
if ($t->name === 'tr' || $t->name === 'tbody') {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} // iterator variable carries over
|
|
||||||
if ($t->name === 'tr') {
|
|
||||||
if ($inside_tbody) {
|
|
||||||
$ret = array_merge($ret, $token_array);
|
|
||||||
} else {
|
|
||||||
$ret[] = new HTMLPurifier_Token_Start('tbody');
|
|
||||||
$ret = array_merge($ret, $token_array);
|
|
||||||
$inside_tbody = true;
|
|
||||||
}
|
|
||||||
} elseif ($t->name === 'tbody') {
|
|
||||||
if ($inside_tbody) {
|
|
||||||
$ret[] = new HTMLPurifier_Token_End('tbody');
|
|
||||||
$inside_tbody = false;
|
|
||||||
$ret = array_merge($ret, $token_array);
|
|
||||||
} else {
|
|
||||||
$ret = array_merge($ret, $token_array);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
trigger_error("tr/tbody in content invariant failed in Table ChildDef", E_USER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($inside_tbody) {
|
|
||||||
$ret[] = new HTMLPurifier_Token_End('tbody');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
foreach ($content as $token_array) {
|
|
||||||
// invariant: everything in here is <tr>s
|
|
||||||
$ret = array_merge($ret, $token_array);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($collection) && $is_collecting == false){
|
|
||||||
// grab the trailing space
|
|
||||||
$ret = array_merge($ret, $collection);
|
|
||||||
}
|
|
||||||
|
|
||||||
array_pop($tokens_of_children); // remove phantom token
|
|
||||||
|
|
||||||
return ($ret === $tokens_of_children) ? true : $ret;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,66 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fluent interface for validating the contents of member variables.
|
|
||||||
* This should be immutable. See HTMLPurifier_ConfigSchema_Validator for
|
|
||||||
* use-cases. We name this an 'atom' because it's ONLY for validations that
|
|
||||||
* are independent and usually scalar.
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_ConfigSchema_ValidatorAtom
|
|
||||||
{
|
|
||||||
|
|
||||||
protected $context, $obj, $member, $contents;
|
|
||||||
|
|
||||||
public function __construct($context, $obj, $member) {
|
|
||||||
$this->context = $context;
|
|
||||||
$this->obj = $obj;
|
|
||||||
$this->member = $member;
|
|
||||||
$this->contents =& $obj->$member;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function assertIsString() {
|
|
||||||
if (!is_string($this->contents)) $this->error('must be a string');
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function assertIsBool() {
|
|
||||||
if (!is_bool($this->contents)) $this->error('must be a boolean');
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function assertIsArray() {
|
|
||||||
if (!is_array($this->contents)) $this->error('must be an array');
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function assertNotNull() {
|
|
||||||
if ($this->contents === null) $this->error('must not be null');
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function assertAlnum() {
|
|
||||||
$this->assertIsString();
|
|
||||||
if (!ctype_alnum($this->contents)) $this->error('must be alphanumeric');
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function assertNotEmpty() {
|
|
||||||
if (empty($this->contents)) $this->error('must not be empty');
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function assertIsLookup() {
|
|
||||||
$this->assertIsArray();
|
|
||||||
foreach ($this->contents as $v) {
|
|
||||||
if ($v !== true) $this->error('must be a lookup array');
|
|
||||||
}
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function error($msg) {
|
|
||||||
throw new HTMLPurifier_ConfigSchema_Exception(ucfirst($this->member) . ' in ' . $this->context . ' ' . $msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,82 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registry object that contains information about the current context.
|
|
||||||
* @warning Is a bit buggy when variables are set to null: it thinks
|
|
||||||
* they don't exist! So use false instead, please.
|
|
||||||
* @note Since the variables Context deals with may not be objects,
|
|
||||||
* references are very important here! Do not remove!
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_Context
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Private array that stores the references.
|
|
||||||
*/
|
|
||||||
private $_storage = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a variable into the context.
|
|
||||||
* @param $name String name
|
|
||||||
* @param $ref Reference to variable to be registered
|
|
||||||
*/
|
|
||||||
public function register($name, &$ref) {
|
|
||||||
if (isset($this->_storage[$name])) {
|
|
||||||
trigger_error("Name $name produces collision, cannot re-register",
|
|
||||||
E_USER_ERROR);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$this->_storage[$name] =& $ref;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves a variable reference from the context.
|
|
||||||
* @param $name String name
|
|
||||||
* @param $ignore_error Boolean whether or not to ignore error
|
|
||||||
*/
|
|
||||||
public function &get($name, $ignore_error = false) {
|
|
||||||
if (!isset($this->_storage[$name])) {
|
|
||||||
if (!$ignore_error) {
|
|
||||||
trigger_error("Attempted to retrieve non-existent variable $name",
|
|
||||||
E_USER_ERROR);
|
|
||||||
}
|
|
||||||
$var = null; // so we can return by reference
|
|
||||||
return $var;
|
|
||||||
}
|
|
||||||
return $this->_storage[$name];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destorys a variable in the context.
|
|
||||||
* @param $name String name
|
|
||||||
*/
|
|
||||||
public function destroy($name) {
|
|
||||||
if (!isset($this->_storage[$name])) {
|
|
||||||
trigger_error("Attempted to destroy non-existent variable $name",
|
|
||||||
E_USER_ERROR);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
unset($this->_storage[$name]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether or not the variable exists.
|
|
||||||
* @param $name String name
|
|
||||||
*/
|
|
||||||
public function exists($name) {
|
|
||||||
return isset($this->_storage[$name]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads a series of variables from an associative array
|
|
||||||
* @param $context_array Assoc array of variables to load
|
|
||||||
*/
|
|
||||||
public function loadArray($context_array) {
|
|
||||||
foreach ($context_array as $key => $discard) {
|
|
||||||
$this->register($key, $context_array[$key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,62 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
class HTMLPurifier_DefinitionCache_Decorator extends HTMLPurifier_DefinitionCache
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cache object we are decorating
|
|
||||||
*/
|
|
||||||
public $cache;
|
|
||||||
|
|
||||||
public function __construct() {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Lazy decorator function
|
|
||||||
* @param $cache Reference to cache object to decorate
|
|
||||||
*/
|
|
||||||
public function decorate(&$cache) {
|
|
||||||
$decorator = $this->copy();
|
|
||||||
// reference is necessary for mocks in PHP 4
|
|
||||||
$decorator->cache =& $cache;
|
|
||||||
$decorator->type = $cache->type;
|
|
||||||
return $decorator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cross-compatible clone substitute
|
|
||||||
*/
|
|
||||||
public function copy() {
|
|
||||||
return new HTMLPurifier_DefinitionCache_Decorator();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function add($def, $config) {
|
|
||||||
return $this->cache->add($def, $config);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function set($def, $config) {
|
|
||||||
return $this->cache->set($def, $config);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function replace($def, $config) {
|
|
||||||
return $this->cache->replace($def, $config);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get($config) {
|
|
||||||
return $this->cache->get($config);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function remove($config) {
|
|
||||||
return $this->cache->remove($config);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function flush($config) {
|
|
||||||
return $this->cache->flush($config);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function cleanup($config) {
|
|
||||||
return $this->cache->cleanup($config);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,43 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Definition cache decorator class that cleans up the cache
|
|
||||||
* whenever there is a cache miss.
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_DefinitionCache_Decorator_Cleanup extends
|
|
||||||
HTMLPurifier_DefinitionCache_Decorator
|
|
||||||
{
|
|
||||||
|
|
||||||
public $name = 'Cleanup';
|
|
||||||
|
|
||||||
public function copy() {
|
|
||||||
return new HTMLPurifier_DefinitionCache_Decorator_Cleanup();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function add($def, $config) {
|
|
||||||
$status = parent::add($def, $config);
|
|
||||||
if (!$status) parent::cleanup($config);
|
|
||||||
return $status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function set($def, $config) {
|
|
||||||
$status = parent::set($def, $config);
|
|
||||||
if (!$status) parent::cleanup($config);
|
|
||||||
return $status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function replace($def, $config) {
|
|
||||||
$status = parent::replace($def, $config);
|
|
||||||
if (!$status) parent::cleanup($config);
|
|
||||||
return $status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get($config) {
|
|
||||||
$ret = parent::get($config);
|
|
||||||
if (!$ret) parent::cleanup($config);
|
|
||||||
return $ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,46 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Definition cache decorator class that saves all cache retrievals
|
|
||||||
* to PHP's memory; good for unit tests or circumstances where
|
|
||||||
* there are lots of configuration objects floating around.
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_DefinitionCache_Decorator_Memory extends
|
|
||||||
HTMLPurifier_DefinitionCache_Decorator
|
|
||||||
{
|
|
||||||
|
|
||||||
protected $definitions;
|
|
||||||
public $name = 'Memory';
|
|
||||||
|
|
||||||
public function copy() {
|
|
||||||
return new HTMLPurifier_DefinitionCache_Decorator_Memory();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function add($def, $config) {
|
|
||||||
$status = parent::add($def, $config);
|
|
||||||
if ($status) $this->definitions[$this->generateKey($config)] = $def;
|
|
||||||
return $status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function set($def, $config) {
|
|
||||||
$status = parent::set($def, $config);
|
|
||||||
if ($status) $this->definitions[$this->generateKey($config)] = $def;
|
|
||||||
return $status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function replace($def, $config) {
|
|
||||||
$status = parent::replace($def, $config);
|
|
||||||
if ($status) $this->definitions[$this->generateKey($config)] = $def;
|
|
||||||
return $status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get($config) {
|
|
||||||
$key = $this->generateKey($config);
|
|
||||||
if (isset($this->definitions[$key])) return $this->definitions[$key];
|
|
||||||
$this->definitions[$key] = parent::get($config);
|
|
||||||
return $this->definitions[$key];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,47 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
require_once 'HTMLPurifier/DefinitionCache/Decorator.php';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Definition cache decorator template.
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_DefinitionCache_Decorator_Template extends
|
|
||||||
HTMLPurifier_DefinitionCache_Decorator
|
|
||||||
{
|
|
||||||
|
|
||||||
var $name = 'Template'; // replace this
|
|
||||||
|
|
||||||
function copy() {
|
|
||||||
// replace class name with yours
|
|
||||||
return new HTMLPurifier_DefinitionCache_Decorator_Template();
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove methods you don't need
|
|
||||||
|
|
||||||
function add($def, $config) {
|
|
||||||
return parent::add($def, $config);
|
|
||||||
}
|
|
||||||
|
|
||||||
function set($def, $config) {
|
|
||||||
return parent::set($def, $config);
|
|
||||||
}
|
|
||||||
|
|
||||||
function replace($def, $config) {
|
|
||||||
return parent::replace($def, $config);
|
|
||||||
}
|
|
||||||
|
|
||||||
function get($config) {
|
|
||||||
return parent::get($config);
|
|
||||||
}
|
|
||||||
|
|
||||||
function flush() {
|
|
||||||
return parent::flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
function cleanup($config) {
|
|
||||||
return parent::cleanup($config);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,39 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Null cache object to use when no caching is on.
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_DefinitionCache_Null extends HTMLPurifier_DefinitionCache
|
|
||||||
{
|
|
||||||
|
|
||||||
public function add($def, $config) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function set($def, $config) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function replace($def, $config) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function remove($config) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get($config) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function flush($config) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function cleanup($config) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,39 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
class HTMLPurifier_Filter_YouTube extends HTMLPurifier_Filter
|
|
||||||
{
|
|
||||||
|
|
||||||
public $name = 'YouTube';
|
|
||||||
|
|
||||||
public function preFilter($html, $config, $context) {
|
|
||||||
$pre_regex = '#<object[^>]+>.+?'.
|
|
||||||
'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?</object>#s';
|
|
||||||
$pre_replace = '<span class="youtube-embed">\1</span>';
|
|
||||||
return preg_replace($pre_regex, $pre_replace, $html);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function postFilter($html, $config, $context) {
|
|
||||||
$post_regex = '#<span class="youtube-embed">((?:v|cp)/[A-Za-z0-9\-_=]+)</span>#';
|
|
||||||
return preg_replace_callback($post_regex, array($this, 'postFilterCallback'), $html);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function armorUrl($url) {
|
|
||||||
return str_replace('--', '--', $url);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function postFilterCallback($matches) {
|
|
||||||
$url = $this->armorUrl($matches[1]);
|
|
||||||
return '<object width="425" height="350" type="application/x-shockwave-flash" '.
|
|
||||||
'data="http://www.youtube.com/'.$url.'">'.
|
|
||||||
'<param name="movie" value="http://www.youtube.com/'.$url.'"></param>'.
|
|
||||||
'<!--[if IE]>'.
|
|
||||||
'<embed src="http://www.youtube.com/'.$url.'"'.
|
|
||||||
'type="application/x-shockwave-flash"'.
|
|
||||||
'wmode="transparent" width="425" height="350" />'.
|
|
||||||
'<![endif]-->'.
|
|
||||||
'</object>';
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,119 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* XHTML 1.1 Forms module, defines all form-related elements found in HTML 4.
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_HTMLModule_Forms extends HTMLPurifier_HTMLModule
|
|
||||||
{
|
|
||||||
public $name = 'Forms';
|
|
||||||
public $safe = false;
|
|
||||||
|
|
||||||
public $content_sets = array(
|
|
||||||
'Block' => 'Form',
|
|
||||||
'Inline' => 'Formctrl',
|
|
||||||
);
|
|
||||||
|
|
||||||
public function setup($config) {
|
|
||||||
$form = $this->addElement('form', 'Form',
|
|
||||||
'Required: Heading | List | Block | fieldset', 'Common', array(
|
|
||||||
'accept' => 'ContentTypes',
|
|
||||||
'accept-charset' => 'Charsets',
|
|
||||||
'action*' => 'URI',
|
|
||||||
'method' => 'Enum#get,post',
|
|
||||||
// really ContentType, but these two are the only ones used today
|
|
||||||
'enctype' => 'Enum#application/x-www-form-urlencoded,multipart/form-data',
|
|
||||||
));
|
|
||||||
$form->excludes = array('form' => true);
|
|
||||||
|
|
||||||
$input = $this->addElement('input', 'Formctrl', 'Empty', 'Common', array(
|
|
||||||
'accept' => 'ContentTypes',
|
|
||||||
'accesskey' => 'Character',
|
|
||||||
'alt' => 'Text',
|
|
||||||
'checked' => 'Bool#checked',
|
|
||||||
'disabled' => 'Bool#disabled',
|
|
||||||
'maxlength' => 'Number',
|
|
||||||
'name' => 'CDATA',
|
|
||||||
'readonly' => 'Bool#readonly',
|
|
||||||
'size' => 'Number',
|
|
||||||
'src' => 'URI#embedded',
|
|
||||||
'tabindex' => 'Number',
|
|
||||||
'type' => 'Enum#text,password,checkbox,button,radio,submit,reset,file,hidden,image',
|
|
||||||
'value' => 'CDATA',
|
|
||||||
));
|
|
||||||
$input->attr_transform_post[] = new HTMLPurifier_AttrTransform_Input();
|
|
||||||
|
|
||||||
$this->addElement('select', 'Formctrl', 'Required: optgroup | option', 'Common', array(
|
|
||||||
'disabled' => 'Bool#disabled',
|
|
||||||
'multiple' => 'Bool#multiple',
|
|
||||||
'name' => 'CDATA',
|
|
||||||
'size' => 'Number',
|
|
||||||
'tabindex' => 'Number',
|
|
||||||
));
|
|
||||||
|
|
||||||
$this->addElement('option', false, 'Optional: #PCDATA', 'Common', array(
|
|
||||||
'disabled' => 'Bool#disabled',
|
|
||||||
'label' => 'Text',
|
|
||||||
'selected' => 'Bool#selected',
|
|
||||||
'value' => 'CDATA',
|
|
||||||
));
|
|
||||||
// It's illegal for there to be more than one selected, but not
|
|
||||||
// be multiple. Also, no selected means undefined behavior. This might
|
|
||||||
// be difficult to implement; perhaps an injector, or a context variable.
|
|
||||||
|
|
||||||
$textarea = $this->addElement('textarea', 'Formctrl', 'Optional: #PCDATA', 'Common', array(
|
|
||||||
'accesskey' => 'Character',
|
|
||||||
'cols*' => 'Number',
|
|
||||||
'disabled' => 'Bool#disabled',
|
|
||||||
'name' => 'CDATA',
|
|
||||||
'readonly' => 'Bool#readonly',
|
|
||||||
'rows*' => 'Number',
|
|
||||||
'tabindex' => 'Number',
|
|
||||||
));
|
|
||||||
$textarea->attr_transform_pre[] = new HTMLPurifier_AttrTransform_Textarea();
|
|
||||||
|
|
||||||
$button = $this->addElement('button', 'Formctrl', 'Optional: #PCDATA | Heading | List | Block | Inline', 'Common', array(
|
|
||||||
'accesskey' => 'Character',
|
|
||||||
'disabled' => 'Bool#disabled',
|
|
||||||
'name' => 'CDATA',
|
|
||||||
'tabindex' => 'Number',
|
|
||||||
'type' => 'Enum#button,submit,reset',
|
|
||||||
'value' => 'CDATA',
|
|
||||||
));
|
|
||||||
|
|
||||||
// For exclusions, ideally we'd specify content sets, not literal elements
|
|
||||||
$button->excludes = $this->makeLookup(
|
|
||||||
'form', 'fieldset', // Form
|
|
||||||
'input', 'select', 'textarea', 'label', 'button', // Formctrl
|
|
||||||
'a', // as per HTML 4.01 spec, this is omitted by modularization
|
|
||||||
'isindex', 'iframe' // legacy items
|
|
||||||
);
|
|
||||||
|
|
||||||
// Extra exclusion: img usemap="" is not permitted within this element.
|
|
||||||
// We'll omit this for now, since we don't have any good way of
|
|
||||||
// indicating it yet.
|
|
||||||
|
|
||||||
// This is HIGHLY user-unfriendly; we need a custom child-def for this
|
|
||||||
$this->addElement('fieldset', 'Form', 'Custom: (#WS?,legend,(Flow|#PCDATA)*)', 'Common');
|
|
||||||
|
|
||||||
$label = $this->addElement('label', 'Formctrl', 'Optional: #PCDATA | Inline', 'Common', array(
|
|
||||||
'accesskey' => 'Character',
|
|
||||||
// 'for' => 'IDREF', // IDREF not implemented, cannot allow
|
|
||||||
));
|
|
||||||
$label->excludes = array('label' => true);
|
|
||||||
|
|
||||||
$this->addElement('legend', false, 'Optional: #PCDATA | Inline', 'Common', array(
|
|
||||||
'accesskey' => 'Character',
|
|
||||||
));
|
|
||||||
|
|
||||||
$this->addElement('optgroup', false, 'Required: option', 'Common', array(
|
|
||||||
'disabled' => 'Bool#disabled',
|
|
||||||
'label*' => 'Text',
|
|
||||||
));
|
|
||||||
|
|
||||||
// Don't forget an injector for <isindex>. This one's a little complex
|
|
||||||
// because it maps to multiple elements.
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,21 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
class HTMLPurifier_HTMLModule_Tidy_Strict extends HTMLPurifier_HTMLModule_Tidy_XHTMLAndHTML4
|
|
||||||
{
|
|
||||||
public $name = 'Tidy_Strict';
|
|
||||||
public $defaultLevel = 'light';
|
|
||||||
|
|
||||||
public function makeFixes() {
|
|
||||||
$r = parent::makeFixes();
|
|
||||||
$r['blockquote#content_model_type'] = 'strictblockquote';
|
|
||||||
return $r;
|
|
||||||
}
|
|
||||||
|
|
||||||
public $defines_child_def = true;
|
|
||||||
public function getChildDef($def) {
|
|
||||||
if ($def->content_model_type != 'strictblockquote') return parent::getChildDef($def);
|
|
||||||
return new HTMLPurifier_ChildDef_StrictBlockquote($def->content_model);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,54 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
class HTMLPurifier_Injector_RemoveEmpty extends HTMLPurifier_Injector
|
|
||||||
{
|
|
||||||
|
|
||||||
private $context, $config, $attrValidator, $removeNbsp, $removeNbspExceptions;
|
|
||||||
|
|
||||||
// TODO: make me configurable
|
|
||||||
private $_exclude = array('colgroup' => 1, 'th' => 1, 'td' => 1, 'iframe' => 1);
|
|
||||||
|
|
||||||
public function prepare($config, $context) {
|
|
||||||
parent::prepare($config, $context);
|
|
||||||
$this->config = $config;
|
|
||||||
$this->context = $context;
|
|
||||||
$this->removeNbsp = $config->get('AutoFormat.RemoveEmpty.RemoveNbsp');
|
|
||||||
$this->removeNbspExceptions = $config->get('AutoFormat.RemoveEmpty.RemoveNbsp.Exceptions');
|
|
||||||
$this->attrValidator = new HTMLPurifier_AttrValidator();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function handleElement(&$token) {
|
|
||||||
if (!$token instanceof HTMLPurifier_Token_Start) return;
|
|
||||||
$next = false;
|
|
||||||
for ($i = $this->inputIndex + 1, $c = count($this->inputTokens); $i < $c; $i++) {
|
|
||||||
$next = $this->inputTokens[$i];
|
|
||||||
if ($next instanceof HTMLPurifier_Token_Text) {
|
|
||||||
if ($next->is_whitespace) continue;
|
|
||||||
if ($this->removeNbsp && !isset($this->removeNbspExceptions[$token->name])) {
|
|
||||||
$plain = str_replace("\xC2\xA0", "", $next->data);
|
|
||||||
$isWsOrNbsp = $plain === '' || ctype_space($plain);
|
|
||||||
if ($isWsOrNbsp) continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (!$next || ($next instanceof HTMLPurifier_Token_End && $next->name == $token->name)) {
|
|
||||||
if (isset($this->_exclude[$token->name])) return;
|
|
||||||
$this->attrValidator->validateToken($token, $this->config, $this->context);
|
|
||||||
$token->armor['ValidateAttributes'] = true;
|
|
||||||
if (isset($token->attr['id']) || isset($token->attr['name'])) return;
|
|
||||||
$token = $i - $this->inputIndex + 1;
|
|
||||||
for ($b = $this->inputIndex - 1; $b > 0; $b--) {
|
|
||||||
$prev = $this->inputTokens[$b];
|
|
||||||
if ($prev instanceof HTMLPurifier_Token_Text && $prev->is_whitespace) continue;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// This is safe because we removed the token that triggered this.
|
|
||||||
$this->rewind($b - 1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,63 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
$fallback = false;
|
|
||||||
|
|
||||||
$messages = array(
|
|
||||||
|
|
||||||
'HTMLPurifier' => 'HTML Purifier',
|
|
||||||
|
|
||||||
// for unit testing purposes
|
|
||||||
'LanguageFactoryTest: Pizza' => 'Pizza',
|
|
||||||
'LanguageTest: List' => '$1',
|
|
||||||
'LanguageTest: Hash' => '$1.Keys; $1.Values',
|
|
||||||
|
|
||||||
'Item separator' => ', ',
|
|
||||||
'Item separator last' => ' and ', // non-Harvard style
|
|
||||||
|
|
||||||
'ErrorCollector: No errors' => 'No errors detected. However, because error reporting is still incomplete, there may have been errors that the error collector was not notified of; please inspect the output HTML carefully.',
|
|
||||||
'ErrorCollector: At line' => ' at line $line',
|
|
||||||
'ErrorCollector: Incidental errors' => 'Incidental errors',
|
|
||||||
|
|
||||||
'Lexer: Unclosed comment' => 'Unclosed comment',
|
|
||||||
'Lexer: Unescaped lt' => 'Unescaped less-than sign (<) should be <',
|
|
||||||
'Lexer: Missing gt' => 'Missing greater-than sign (>), previous less-than sign (<) should be escaped',
|
|
||||||
'Lexer: Missing attribute key' => 'Attribute declaration has no key',
|
|
||||||
'Lexer: Missing end quote' => 'Attribute declaration has no end quote',
|
|
||||||
'Lexer: Extracted body' => 'Removed document metadata tags',
|
|
||||||
|
|
||||||
'Strategy_RemoveForeignElements: Tag transform' => '<$1> element transformed into $CurrentToken.Serialized',
|
|
||||||
'Strategy_RemoveForeignElements: Missing required attribute' => '$CurrentToken.Compact element missing required attribute $1',
|
|
||||||
'Strategy_RemoveForeignElements: Foreign element to text' => 'Unrecognized $CurrentToken.Serialized tag converted to text',
|
|
||||||
'Strategy_RemoveForeignElements: Foreign element removed' => 'Unrecognized $CurrentToken.Serialized tag removed',
|
|
||||||
'Strategy_RemoveForeignElements: Comment removed' => 'Comment containing "$CurrentToken.Data" removed',
|
|
||||||
'Strategy_RemoveForeignElements: Foreign meta element removed' => 'Unrecognized $CurrentToken.Serialized meta tag and all descendants removed',
|
|
||||||
'Strategy_RemoveForeignElements: Token removed to end' => 'Tags and text starting from $1 element where removed to end',
|
|
||||||
'Strategy_RemoveForeignElements: Trailing hyphen in comment removed' => 'Trailing hyphen(s) in comment removed',
|
|
||||||
'Strategy_RemoveForeignElements: Hyphens in comment collapsed' => 'Double hyphens in comments are not allowed, and were collapsed into single hyphens',
|
|
||||||
|
|
||||||
'Strategy_MakeWellFormed: Unnecessary end tag removed' => 'Unnecessary $CurrentToken.Serialized tag removed',
|
|
||||||
'Strategy_MakeWellFormed: Unnecessary end tag to text' => 'Unnecessary $CurrentToken.Serialized tag converted to text',
|
|
||||||
'Strategy_MakeWellFormed: Tag auto closed' => '$1.Compact started on line $1.Line auto-closed by $CurrentToken.Compact',
|
|
||||||
'Strategy_MakeWellFormed: Tag carryover' => '$1.Compact started on line $1.Line auto-continued into $CurrentToken.Compact',
|
|
||||||
'Strategy_MakeWellFormed: Stray end tag removed' => 'Stray $CurrentToken.Serialized tag removed',
|
|
||||||
'Strategy_MakeWellFormed: Stray end tag to text' => 'Stray $CurrentToken.Serialized tag converted to text',
|
|
||||||
'Strategy_MakeWellFormed: Tag closed by element end' => '$1.Compact tag started on line $1.Line closed by end of $CurrentToken.Serialized',
|
|
||||||
'Strategy_MakeWellFormed: Tag closed by document end' => '$1.Compact tag started on line $1.Line closed by end of document',
|
|
||||||
|
|
||||||
'Strategy_FixNesting: Node removed' => '$CurrentToken.Compact node removed',
|
|
||||||
'Strategy_FixNesting: Node excluded' => '$CurrentToken.Compact node removed due to descendant exclusion by ancestor element',
|
|
||||||
'Strategy_FixNesting: Node reorganized' => 'Contents of $CurrentToken.Compact node reorganized to enforce its content model',
|
|
||||||
'Strategy_FixNesting: Node contents removed' => 'Contents of $CurrentToken.Compact node removed',
|
|
||||||
|
|
||||||
'AttrValidator: Attributes transformed' => 'Attributes on $CurrentToken.Compact transformed from $1.Keys to $2.Keys',
|
|
||||||
'AttrValidator: Attribute removed' => '$CurrentAttr.Name attribute on $CurrentToken.Compact removed',
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
$errorNames = array(
|
|
||||||
E_ERROR => 'Error',
|
|
||||||
E_WARNING => 'Warning',
|
|
||||||
E_NOTICE => 'Notice'
|
|
||||||
);
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,346 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Takes a well formed list of tokens and fixes their nesting.
|
|
||||||
*
|
|
||||||
* HTML elements dictate which elements are allowed to be their children,
|
|
||||||
* for example, you can't have a p tag in a span tag. Other elements have
|
|
||||||
* much more rigorous definitions: tables, for instance, require a specific
|
|
||||||
* order for their elements. There are also constraints not expressible by
|
|
||||||
* document type definitions, such as the chameleon nature of ins/del
|
|
||||||
* tags and global child exclusions.
|
|
||||||
*
|
|
||||||
* The first major objective of this strategy is to iterate through all the
|
|
||||||
* nodes (not tokens) of the list of tokens and determine whether or not
|
|
||||||
* their children conform to the element's definition. If they do not, the
|
|
||||||
* child definition may optionally supply an amended list of elements that
|
|
||||||
* is valid or require that the entire node be deleted (and the previous
|
|
||||||
* node rescanned).
|
|
||||||
*
|
|
||||||
* The second objective is to ensure that explicitly excluded elements of
|
|
||||||
* an element do not appear in its children. Code that accomplishes this
|
|
||||||
* task is pervasive through the strategy, though the two are distinct tasks
|
|
||||||
* and could, theoretically, be seperated (although it's not recommended).
|
|
||||||
*
|
|
||||||
* @note Whether or not unrecognized children are silently dropped or
|
|
||||||
* translated into text depends on the child definitions.
|
|
||||||
*
|
|
||||||
* @todo Enable nodes to be bubbled out of the structure.
|
|
||||||
*
|
|
||||||
* @warning This algorithm (though it may be hard to see) proceeds from
|
|
||||||
* a top-down fashion. Thus, parents are processed before
|
|
||||||
* children. This is easy to implement and has a nice effiency
|
|
||||||
* benefit, in that if a node is removed, we never waste any
|
|
||||||
* time processing it, but it also means that if a child
|
|
||||||
* changes in a non-encapsulated way (e.g. it is removed), we
|
|
||||||
* need to go back and reprocess the parent to see if those
|
|
||||||
* changes resulted in problems for the parent. See
|
|
||||||
* [BACKTRACK] for an example of this. In the current
|
|
||||||
* implementation, this backtracking can only be triggered when
|
|
||||||
* a node is removed and if that node was the sole node, the
|
|
||||||
* parent would need to be removed. As such, it is easy to see
|
|
||||||
* that backtracking only incurs constant overhead. If more
|
|
||||||
* sophisticated backtracking is implemented, care must be
|
|
||||||
* taken to avoid nontermination or exponential blowup.
|
|
||||||
*/
|
|
||||||
|
|
||||||
class HTMLPurifier_Strategy_FixNesting extends HTMLPurifier_Strategy
|
|
||||||
{
|
|
||||||
|
|
||||||
public function execute($tokens, $config, $context) {
|
|
||||||
//####################################################################//
|
|
||||||
// Pre-processing
|
|
||||||
|
|
||||||
// get a copy of the HTML definition
|
|
||||||
$definition = $config->getHTMLDefinition();
|
|
||||||
|
|
||||||
$excludes_enabled = !$config->get('Core.DisableExcludes');
|
|
||||||
|
|
||||||
// insert implicit "parent" node, will be removed at end.
|
|
||||||
// DEFINITION CALL
|
|
||||||
$parent_name = $definition->info_parent;
|
|
||||||
array_unshift($tokens, new HTMLPurifier_Token_Start($parent_name));
|
|
||||||
$tokens[] = new HTMLPurifier_Token_End($parent_name);
|
|
||||||
|
|
||||||
// setup the context variable 'IsInline', for chameleon processing
|
|
||||||
// is 'false' when we are not inline, 'true' when it must always
|
|
||||||
// be inline, and an integer when it is inline for a certain
|
|
||||||
// branch of the document tree
|
|
||||||
$is_inline = $definition->info_parent_def->descendants_are_inline;
|
|
||||||
$context->register('IsInline', $is_inline);
|
|
||||||
|
|
||||||
// setup error collector
|
|
||||||
$e =& $context->get('ErrorCollector', true);
|
|
||||||
|
|
||||||
//####################################################################//
|
|
||||||
// Loop initialization
|
|
||||||
|
|
||||||
// stack that contains the indexes of all parents,
|
|
||||||
// $stack[count($stack)-1] being the current parent
|
|
||||||
$stack = array();
|
|
||||||
|
|
||||||
// stack that contains all elements that are excluded
|
|
||||||
// it is organized by parent elements, similar to $stack,
|
|
||||||
// but it is only populated when an element with exclusions is
|
|
||||||
// processed, i.e. there won't be empty exclusions.
|
|
||||||
$exclude_stack = array();
|
|
||||||
|
|
||||||
// variable that contains the start token while we are processing
|
|
||||||
// nodes. This enables error reporting to do its job
|
|
||||||
$start_token = false;
|
|
||||||
$context->register('CurrentToken', $start_token);
|
|
||||||
|
|
||||||
//####################################################################//
|
|
||||||
// Loop
|
|
||||||
|
|
||||||
// iterate through all start nodes. Determining the start node
|
|
||||||
// is complicated so it has been omitted from the loop construct
|
|
||||||
for ($i = 0, $size = count($tokens) ; $i < $size; ) {
|
|
||||||
|
|
||||||
//################################################################//
|
|
||||||
// Gather information on children
|
|
||||||
|
|
||||||
// child token accumulator
|
|
||||||
$child_tokens = array();
|
|
||||||
|
|
||||||
// scroll to the end of this node, report number, and collect
|
|
||||||
// all children
|
|
||||||
for ($j = $i, $depth = 0; ; $j++) {
|
|
||||||
if ($tokens[$j] instanceof HTMLPurifier_Token_Start) {
|
|
||||||
$depth++;
|
|
||||||
// skip token assignment on first iteration, this is the
|
|
||||||
// token we currently are on
|
|
||||||
if ($depth == 1) continue;
|
|
||||||
} elseif ($tokens[$j] instanceof HTMLPurifier_Token_End) {
|
|
||||||
$depth--;
|
|
||||||
// skip token assignment on last iteration, this is the
|
|
||||||
// end token of the token we're currently on
|
|
||||||
if ($depth == 0) break;
|
|
||||||
}
|
|
||||||
$child_tokens[] = $tokens[$j];
|
|
||||||
}
|
|
||||||
|
|
||||||
// $i is index of start token
|
|
||||||
// $j is index of end token
|
|
||||||
|
|
||||||
$start_token = $tokens[$i]; // to make token available via CurrentToken
|
|
||||||
|
|
||||||
//################################################################//
|
|
||||||
// Gather information on parent
|
|
||||||
|
|
||||||
// calculate parent information
|
|
||||||
if ($count = count($stack)) {
|
|
||||||
$parent_index = $stack[$count-1];
|
|
||||||
$parent_name = $tokens[$parent_index]->name;
|
|
||||||
if ($parent_index == 0) {
|
|
||||||
$parent_def = $definition->info_parent_def;
|
|
||||||
} else {
|
|
||||||
$parent_def = $definition->info[$parent_name];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// processing as if the parent were the "root" node
|
|
||||||
// unknown info, it won't be used anyway, in the future,
|
|
||||||
// we may want to enforce one element only (this is
|
|
||||||
// necessary for HTML Purifier to clean entire documents
|
|
||||||
$parent_index = $parent_name = $parent_def = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// calculate context
|
|
||||||
if ($is_inline === false) {
|
|
||||||
// check if conditions make it inline
|
|
||||||
if (!empty($parent_def) && $parent_def->descendants_are_inline) {
|
|
||||||
$is_inline = $count - 1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// check if we're out of inline
|
|
||||||
if ($count === $is_inline) {
|
|
||||||
$is_inline = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//################################################################//
|
|
||||||
// Determine whether element is explicitly excluded SGML-style
|
|
||||||
|
|
||||||
// determine whether or not element is excluded by checking all
|
|
||||||
// parent exclusions. The array should not be very large, two
|
|
||||||
// elements at most.
|
|
||||||
$excluded = false;
|
|
||||||
if (!empty($exclude_stack) && $excludes_enabled) {
|
|
||||||
foreach ($exclude_stack as $lookup) {
|
|
||||||
if (isset($lookup[$tokens[$i]->name])) {
|
|
||||||
$excluded = true;
|
|
||||||
// no need to continue processing
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//################################################################//
|
|
||||||
// Perform child validation
|
|
||||||
|
|
||||||
if ($excluded) {
|
|
||||||
// there is an exclusion, remove the entire node
|
|
||||||
$result = false;
|
|
||||||
$excludes = array(); // not used, but good to initialize anyway
|
|
||||||
} else {
|
|
||||||
// DEFINITION CALL
|
|
||||||
if ($i === 0) {
|
|
||||||
// special processing for the first node
|
|
||||||
$def = $definition->info_parent_def;
|
|
||||||
} else {
|
|
||||||
$def = $definition->info[$tokens[$i]->name];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($def->child)) {
|
|
||||||
// have DTD child def validate children
|
|
||||||
$result = $def->child->validateChildren(
|
|
||||||
$child_tokens, $config, $context);
|
|
||||||
} else {
|
|
||||||
// weird, no child definition, get rid of everything
|
|
||||||
$result = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// determine whether or not this element has any exclusions
|
|
||||||
$excludes = $def->excludes;
|
|
||||||
}
|
|
||||||
|
|
||||||
// $result is now a bool or array
|
|
||||||
|
|
||||||
//################################################################//
|
|
||||||
// Process result by interpreting $result
|
|
||||||
|
|
||||||
if ($result === true || $child_tokens === $result) {
|
|
||||||
// leave the node as is
|
|
||||||
|
|
||||||
// register start token as a parental node start
|
|
||||||
$stack[] = $i;
|
|
||||||
|
|
||||||
// register exclusions if there are any
|
|
||||||
if (!empty($excludes)) $exclude_stack[] = $excludes;
|
|
||||||
|
|
||||||
// move cursor to next possible start node
|
|
||||||
$i++;
|
|
||||||
|
|
||||||
} elseif($result === false) {
|
|
||||||
// remove entire node
|
|
||||||
|
|
||||||
if ($e) {
|
|
||||||
if ($excluded) {
|
|
||||||
$e->send(E_ERROR, 'Strategy_FixNesting: Node excluded');
|
|
||||||
} else {
|
|
||||||
$e->send(E_ERROR, 'Strategy_FixNesting: Node removed');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// calculate length of inner tokens and current tokens
|
|
||||||
$length = $j - $i + 1;
|
|
||||||
|
|
||||||
// perform removal
|
|
||||||
array_splice($tokens, $i, $length);
|
|
||||||
|
|
||||||
// update size
|
|
||||||
$size -= $length;
|
|
||||||
|
|
||||||
// there is no start token to register,
|
|
||||||
// current node is now the next possible start node
|
|
||||||
// unless it turns out that we need to do a double-check
|
|
||||||
|
|
||||||
// this is a rought heuristic that covers 100% of HTML's
|
|
||||||
// cases and 99% of all other cases. A child definition
|
|
||||||
// that would be tricked by this would be something like:
|
|
||||||
// ( | a b c) where it's all or nothing. Fortunately,
|
|
||||||
// our current implementation claims that that case would
|
|
||||||
// not allow empty, even if it did
|
|
||||||
if (!$parent_def->child->allow_empty) {
|
|
||||||
// we need to do a double-check [BACKTRACK]
|
|
||||||
$i = $parent_index;
|
|
||||||
array_pop($stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
// PROJECTED OPTIMIZATION: Process all children elements before
|
|
||||||
// reprocessing parent node.
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// replace node with $result
|
|
||||||
|
|
||||||
// calculate length of inner tokens
|
|
||||||
$length = $j - $i - 1;
|
|
||||||
|
|
||||||
if ($e) {
|
|
||||||
if (empty($result) && $length) {
|
|
||||||
$e->send(E_ERROR, 'Strategy_FixNesting: Node contents removed');
|
|
||||||
} else {
|
|
||||||
$e->send(E_WARNING, 'Strategy_FixNesting: Node reorganized');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// perform replacement
|
|
||||||
array_splice($tokens, $i + 1, $length, $result);
|
|
||||||
|
|
||||||
// update size
|
|
||||||
$size -= $length;
|
|
||||||
$size += count($result);
|
|
||||||
|
|
||||||
// register start token as a parental node start
|
|
||||||
$stack[] = $i;
|
|
||||||
|
|
||||||
// register exclusions if there are any
|
|
||||||
if (!empty($excludes)) $exclude_stack[] = $excludes;
|
|
||||||
|
|
||||||
// move cursor to next possible start node
|
|
||||||
$i++;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//################################################################//
|
|
||||||
// Scroll to next start node
|
|
||||||
|
|
||||||
// We assume, at this point, that $i is the index of the token
|
|
||||||
// that is the first possible new start point for a node.
|
|
||||||
|
|
||||||
// Test if the token indeed is a start tag, if not, move forward
|
|
||||||
// and test again.
|
|
||||||
$size = count($tokens);
|
|
||||||
while ($i < $size and !$tokens[$i] instanceof HTMLPurifier_Token_Start) {
|
|
||||||
if ($tokens[$i] instanceof HTMLPurifier_Token_End) {
|
|
||||||
// pop a token index off the stack if we ended a node
|
|
||||||
array_pop($stack);
|
|
||||||
// pop an exclusion lookup off exclusion stack if
|
|
||||||
// we ended node and that node had exclusions
|
|
||||||
if ($i == 0 || $i == $size - 1) {
|
|
||||||
// use specialized var if it's the super-parent
|
|
||||||
$s_excludes = $definition->info_parent_def->excludes;
|
|
||||||
} else {
|
|
||||||
$s_excludes = $definition->info[$tokens[$i]->name]->excludes;
|
|
||||||
}
|
|
||||||
if ($s_excludes) {
|
|
||||||
array_pop($exclude_stack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//####################################################################//
|
|
||||||
// Post-processing
|
|
||||||
|
|
||||||
// remove implicit parent tokens at the beginning and end
|
|
||||||
array_shift($tokens);
|
|
||||||
array_pop($tokens);
|
|
||||||
|
|
||||||
// remove context variables
|
|
||||||
$context->destroy('IsInline');
|
|
||||||
$context->destroy('CurrentToken');
|
|
||||||
|
|
||||||
//####################################################################//
|
|
||||||
// Return
|
|
||||||
|
|
||||||
return $tokens;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,57 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Abstract base token class that all others inherit from.
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_Token {
|
|
||||||
public $line; /**< Line number node was on in source document. Null if unknown. */
|
|
||||||
public $col; /**< Column of line node was on in source document. Null if unknown. */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Lookup array of processing that this token is exempt from.
|
|
||||||
* Currently, valid values are "ValidateAttributes" and
|
|
||||||
* "MakeWellFormed_TagClosedError"
|
|
||||||
*/
|
|
||||||
public $armor = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used during MakeWellFormed.
|
|
||||||
*/
|
|
||||||
public $skip;
|
|
||||||
public $rewind;
|
|
||||||
public $carryover;
|
|
||||||
|
|
||||||
public function __get($n) {
|
|
||||||
if ($n === 'type') {
|
|
||||||
trigger_error('Deprecated type property called; use instanceof', E_USER_NOTICE);
|
|
||||||
switch (get_class($this)) {
|
|
||||||
case 'HTMLPurifier_Token_Start': return 'start';
|
|
||||||
case 'HTMLPurifier_Token_Empty': return 'empty';
|
|
||||||
case 'HTMLPurifier_Token_End': return 'end';
|
|
||||||
case 'HTMLPurifier_Token_Text': return 'text';
|
|
||||||
case 'HTMLPurifier_Token_Comment': return 'comment';
|
|
||||||
default: return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the position of the token in the source document.
|
|
||||||
*/
|
|
||||||
public function position($l = null, $c = null) {
|
|
||||||
$this->line = $l;
|
|
||||||
$this->col = $c;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convenience function for DirectLex settings line/col position.
|
|
||||||
*/
|
|
||||||
public function rawPosition($l, $c) {
|
|
||||||
if ($c === -1) $l++;
|
|
||||||
$this->line = $l;
|
|
||||||
$this->col = $c;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,22 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Concrete comment token class. Generally will be ignored.
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_Token_Comment extends HTMLPurifier_Token
|
|
||||||
{
|
|
||||||
public $data; /**< Character data within comment. */
|
|
||||||
public $is_whitespace = true;
|
|
||||||
/**
|
|
||||||
* Transparent constructor.
|
|
||||||
*
|
|
||||||
* @param $data String comment data.
|
|
||||||
*/
|
|
||||||
public function __construct($data, $line = null, $col = null) {
|
|
||||||
$this->data = $data;
|
|
||||||
$this->line = $line;
|
|
||||||
$this->col = $col;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,94 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Factory for token generation.
|
|
||||||
*
|
|
||||||
* @note Doing some benchmarking indicates that the new operator is much
|
|
||||||
* slower than the clone operator (even discounting the cost of the
|
|
||||||
* constructor). This class is for that optimization.
|
|
||||||
* Other then that, there's not much point as we don't
|
|
||||||
* maintain parallel HTMLPurifier_Token hierarchies (the main reason why
|
|
||||||
* you'd want to use an abstract factory).
|
|
||||||
* @todo Port DirectLex to use this
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_TokenFactory
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prototypes that will be cloned.
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
// p stands for prototype
|
|
||||||
private $p_start, $p_end, $p_empty, $p_text, $p_comment;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates blank prototypes for cloning.
|
|
||||||
*/
|
|
||||||
public function __construct() {
|
|
||||||
$this->p_start = new HTMLPurifier_Token_Start('', array());
|
|
||||||
$this->p_end = new HTMLPurifier_Token_End('');
|
|
||||||
$this->p_empty = new HTMLPurifier_Token_Empty('', array());
|
|
||||||
$this->p_text = new HTMLPurifier_Token_Text('');
|
|
||||||
$this->p_comment= new HTMLPurifier_Token_Comment('');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a HTMLPurifier_Token_Start.
|
|
||||||
* @param $name Tag name
|
|
||||||
* @param $attr Associative array of attributes
|
|
||||||
* @return Generated HTMLPurifier_Token_Start
|
|
||||||
*/
|
|
||||||
public function createStart($name, $attr = array()) {
|
|
||||||
$p = clone $this->p_start;
|
|
||||||
$p->__construct($name, $attr);
|
|
||||||
return $p;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a HTMLPurifier_Token_End.
|
|
||||||
* @param $name Tag name
|
|
||||||
* @return Generated HTMLPurifier_Token_End
|
|
||||||
*/
|
|
||||||
public function createEnd($name) {
|
|
||||||
$p = clone $this->p_end;
|
|
||||||
$p->__construct($name);
|
|
||||||
return $p;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a HTMLPurifier_Token_Empty.
|
|
||||||
* @param $name Tag name
|
|
||||||
* @param $attr Associative array of attributes
|
|
||||||
* @return Generated HTMLPurifier_Token_Empty
|
|
||||||
*/
|
|
||||||
public function createEmpty($name, $attr = array()) {
|
|
||||||
$p = clone $this->p_empty;
|
|
||||||
$p->__construct($name, $attr);
|
|
||||||
return $p;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a HTMLPurifier_Token_Text.
|
|
||||||
* @param $data Data of text token
|
|
||||||
* @return Generated HTMLPurifier_Token_Text
|
|
||||||
*/
|
|
||||||
public function createText($data) {
|
|
||||||
$p = clone $this->p_text;
|
|
||||||
$p->__construct($data);
|
|
||||||
return $p;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a HTMLPurifier_Token_Comment.
|
|
||||||
* @param $data Data of comment token
|
|
||||||
* @return Generated HTMLPurifier_Token_Comment
|
|
||||||
*/
|
|
||||||
public function createComment($data) {
|
|
||||||
$p = clone $this->p_comment;
|
|
||||||
$p->__construct($data);
|
|
||||||
return $p;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,23 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
class HTMLPurifier_URIFilter_DisableExternal extends HTMLPurifier_URIFilter
|
|
||||||
{
|
|
||||||
public $name = 'DisableExternal';
|
|
||||||
protected $ourHostParts = false;
|
|
||||||
public function prepare($config) {
|
|
||||||
$our_host = $config->getDefinition('URI')->host;
|
|
||||||
if ($our_host !== null) $this->ourHostParts = array_reverse(explode('.', $our_host));
|
|
||||||
}
|
|
||||||
public function filter(&$uri, $config, $context) {
|
|
||||||
if (is_null($uri->host)) return true;
|
|
||||||
if ($this->ourHostParts === false) return false;
|
|
||||||
$host_parts = array_reverse(explode('.', $uri->host));
|
|
||||||
foreach ($this->ourHostParts as $i => $x) {
|
|
||||||
if (!isset($host_parts[$i])) return false;
|
|
||||||
if ($host_parts[$i] != $this->ourHostParts[$i]) return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,12 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
class HTMLPurifier_URIFilter_DisableExternalResources extends HTMLPurifier_URIFilter_DisableExternal
|
|
||||||
{
|
|
||||||
public $name = 'DisableExternalResources';
|
|
||||||
public function filter(&$uri, $config, $context) {
|
|
||||||
if (!$context->get('EmbeddedURI', true)) return true;
|
|
||||||
return parent::filter($uri, $config, $context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,11 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
class HTMLPurifier_URIFilter_DisableResources extends HTMLPurifier_URIFilter
|
|
||||||
{
|
|
||||||
public $name = 'DisableResources';
|
|
||||||
public function filter(&$uri, $config, $context) {
|
|
||||||
return !$context->get('EmbeddedURI', true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,53 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
class HTMLPurifier_URIFilter_Munge extends HTMLPurifier_URIFilter
|
|
||||||
{
|
|
||||||
public $name = 'Munge';
|
|
||||||
public $post = true;
|
|
||||||
private $target, $parser, $doEmbed, $secretKey;
|
|
||||||
|
|
||||||
protected $replace = array();
|
|
||||||
|
|
||||||
public function prepare($config) {
|
|
||||||
$this->target = $config->get('URI.' . $this->name);
|
|
||||||
$this->parser = new HTMLPurifier_URIParser();
|
|
||||||
$this->doEmbed = $config->get('URI.MungeResources');
|
|
||||||
$this->secretKey = $config->get('URI.MungeSecretKey');
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
public function filter(&$uri, $config, $context) {
|
|
||||||
if ($context->get('EmbeddedURI', true) && !$this->doEmbed) return true;
|
|
||||||
|
|
||||||
$scheme_obj = $uri->getSchemeObj($config, $context);
|
|
||||||
if (!$scheme_obj) return true; // ignore unknown schemes, maybe another postfilter did it
|
|
||||||
if (!$scheme_obj->browsable) return true; // ignore non-browseable schemes, since we can't munge those in a reasonable way
|
|
||||||
if ($uri->isBenign($config, $context)) return true; // don't redirect if a benign URL
|
|
||||||
|
|
||||||
$this->makeReplace($uri, $config, $context);
|
|
||||||
$this->replace = array_map('rawurlencode', $this->replace);
|
|
||||||
|
|
||||||
$new_uri = strtr($this->target, $this->replace);
|
|
||||||
$new_uri = $this->parser->parse($new_uri);
|
|
||||||
// don't redirect if the target host is the same as the
|
|
||||||
// starting host
|
|
||||||
if ($uri->host === $new_uri->host) return true;
|
|
||||||
$uri = $new_uri; // overwrite
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function makeReplace($uri, $config, $context) {
|
|
||||||
$string = $uri->toString();
|
|
||||||
// always available
|
|
||||||
$this->replace['%s'] = $string;
|
|
||||||
$this->replace['%r'] = $context->get('EmbeddedURI', true);
|
|
||||||
$token = $context->get('CurrentToken', true);
|
|
||||||
$this->replace['%n'] = $token ? $token->name : null;
|
|
||||||
$this->replace['%m'] = $context->get('CurrentAttr', true);
|
|
||||||
$this->replace['%p'] = $context->get('CurrentCSSProperty', true);
|
|
||||||
// not always available
|
|
||||||
if ($this->secretKey) $this->replace['%t'] = sha1($this->secretKey . ':' . $string);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,35 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implements safety checks for safe iframes.
|
|
||||||
*
|
|
||||||
* @warning This filter is *critical* for ensuring that %HTML.SafeIframe
|
|
||||||
* works safely.
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_URIFilter_SafeIframe extends HTMLPurifier_URIFilter
|
|
||||||
{
|
|
||||||
public $name = 'SafeIframe';
|
|
||||||
public $always_load = true;
|
|
||||||
protected $regexp = NULL;
|
|
||||||
// XXX: The not so good bit about how this is all setup now is we
|
|
||||||
// can't check HTML.SafeIframe in the 'prepare' step: we have to
|
|
||||||
// defer till the actual filtering.
|
|
||||||
public function prepare($config) {
|
|
||||||
$this->regexp = $config->get('URI.SafeIframeRegexp');
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
public function filter(&$uri, $config, $context) {
|
|
||||||
// check if filter not applicable
|
|
||||||
if (!$config->get('HTML.SafeIframe')) return true;
|
|
||||||
// check if the filter should actually trigger
|
|
||||||
if (!$context->get('EmbeddedURI', true)) return true;
|
|
||||||
$token = $context->get('CurrentToken', true);
|
|
||||||
if (!($token && $token->name == 'iframe')) return true;
|
|
||||||
// check if we actually have some whitelists enabled
|
|
||||||
if ($this->regexp === null) return false;
|
|
||||||
// actually check the whitelists
|
|
||||||
return preg_match($this->regexp, $uri->toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,32 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validates file as defined by RFC 1630 and RFC 1738.
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_URIScheme_file extends HTMLPurifier_URIScheme {
|
|
||||||
|
|
||||||
// Generally file:// URLs are not accessible from most
|
|
||||||
// machines, so placing them as an img src is incorrect.
|
|
||||||
public $browsable = false;
|
|
||||||
|
|
||||||
// Basically the *only* URI scheme for which this is true, since
|
|
||||||
// accessing files on the local machine is very common. In fact,
|
|
||||||
// browsers on some operating systems don't understand the
|
|
||||||
// authority, though I hear it is used on Windows to refer to
|
|
||||||
// network shares.
|
|
||||||
public $may_omit_host = true;
|
|
||||||
|
|
||||||
public function doValidate(&$uri, $config, $context) {
|
|
||||||
// Authentication method is not supported
|
|
||||||
$uri->userinfo = null;
|
|
||||||
// file:// makes no provisions for accessing the resource
|
|
||||||
$uri->port = null;
|
|
||||||
// While it seems to work on Firefox, the querystring has
|
|
||||||
// no possible effect and is thus stripped.
|
|
||||||
$uri->query = null;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,22 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validates news (Usenet) as defined by generic RFC 1738
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_URIScheme_news extends HTMLPurifier_URIScheme {
|
|
||||||
|
|
||||||
public $browsable = false;
|
|
||||||
public $may_omit_host = true;
|
|
||||||
|
|
||||||
public function doValidate(&$uri, $config, $context) {
|
|
||||||
$uri->userinfo = null;
|
|
||||||
$uri->host = null;
|
|
||||||
$uri->port = null;
|
|
||||||
$uri->query = null;
|
|
||||||
// typecode check needed on path
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,19 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validates nntp (Network News Transfer Protocol) as defined by generic RFC 1738
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_URIScheme_nntp extends HTMLPurifier_URIScheme {
|
|
||||||
|
|
||||||
public $default_port = 119;
|
|
||||||
public $browsable = false;
|
|
||||||
|
|
||||||
public function doValidate(&$uri, $config, $context) {
|
|
||||||
$uri->userinfo = null;
|
|
||||||
$uri->query = null;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,154 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses string representations into their corresponding native PHP
|
|
||||||
* variable type. The base implementation does a simple type-check.
|
|
||||||
*/
|
|
||||||
class HTMLPurifier_VarParser
|
|
||||||
{
|
|
||||||
|
|
||||||
const STRING = 1;
|
|
||||||
const ISTRING = 2;
|
|
||||||
const TEXT = 3;
|
|
||||||
const ITEXT = 4;
|
|
||||||
const INT = 5;
|
|
||||||
const FLOAT = 6;
|
|
||||||
const BOOL = 7;
|
|
||||||
const LOOKUP = 8;
|
|
||||||
const ALIST = 9;
|
|
||||||
const HASH = 10;
|
|
||||||
const MIXED = 11;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Lookup table of allowed types. Mainly for backwards compatibility, but
|
|
||||||
* also convenient for transforming string type names to the integer constants.
|
|
||||||
*/
|
|
||||||
static public $types = array(
|
|
||||||
'string' => self::STRING,
|
|
||||||
'istring' => self::ISTRING,
|
|
||||||
'text' => self::TEXT,
|
|
||||||
'itext' => self::ITEXT,
|
|
||||||
'int' => self::INT,
|
|
||||||
'float' => self::FLOAT,
|
|
||||||
'bool' => self::BOOL,
|
|
||||||
'lookup' => self::LOOKUP,
|
|
||||||
'list' => self::ALIST,
|
|
||||||
'hash' => self::HASH,
|
|
||||||
'mixed' => self::MIXED
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Lookup table of types that are string, and can have aliases or
|
|
||||||
* allowed value lists.
|
|
||||||
*/
|
|
||||||
static public $stringTypes = array(
|
|
||||||
self::STRING => true,
|
|
||||||
self::ISTRING => true,
|
|
||||||
self::TEXT => true,
|
|
||||||
self::ITEXT => true,
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate a variable according to type. Throws
|
|
||||||
* HTMLPurifier_VarParserException if invalid.
|
|
||||||
* It may return NULL as a valid type if $allow_null is true.
|
|
||||||
*
|
|
||||||
* @param $var Variable to validate
|
|
||||||
* @param $type Type of variable, see HTMLPurifier_VarParser->types
|
|
||||||
* @param $allow_null Whether or not to permit null as a value
|
|
||||||
* @return Validated and type-coerced variable
|
|
||||||
*/
|
|
||||||
final public function parse($var, $type, $allow_null = false) {
|
|
||||||
if (is_string($type)) {
|
|
||||||
if (!isset(HTMLPurifier_VarParser::$types[$type])) {
|
|
||||||
throw new HTMLPurifier_VarParserException("Invalid type '$type'");
|
|
||||||
} else {
|
|
||||||
$type = HTMLPurifier_VarParser::$types[$type];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$var = $this->parseImplementation($var, $type, $allow_null);
|
|
||||||
if ($allow_null && $var === null) return null;
|
|
||||||
// These are basic checks, to make sure nothing horribly wrong
|
|
||||||
// happened in our implementations.
|
|
||||||
switch ($type) {
|
|
||||||
case (self::STRING):
|
|
||||||
case (self::ISTRING):
|
|
||||||
case (self::TEXT):
|
|
||||||
case (self::ITEXT):
|
|
||||||
if (!is_string($var)) break;
|
|
||||||
if ($type == self::ISTRING || $type == self::ITEXT) $var = strtolower($var);
|
|
||||||
return $var;
|
|
||||||
case (self::INT):
|
|
||||||
if (!is_int($var)) break;
|
|
||||||
return $var;
|
|
||||||
case (self::FLOAT):
|
|
||||||
if (!is_float($var)) break;
|
|
||||||
return $var;
|
|
||||||
case (self::BOOL):
|
|
||||||
if (!is_bool($var)) break;
|
|
||||||
return $var;
|
|
||||||
case (self::LOOKUP):
|
|
||||||
case (self::ALIST):
|
|
||||||
case (self::HASH):
|
|
||||||
if (!is_array($var)) break;
|
|
||||||
if ($type === self::LOOKUP) {
|
|
||||||
foreach ($var as $k) if ($k !== true) $this->error('Lookup table contains value other than true');
|
|
||||||
} elseif ($type === self::ALIST) {
|
|
||||||
$keys = array_keys($var);
|
|
||||||
if (array_keys($keys) !== $keys) $this->error('Indices for list are not uniform');
|
|
||||||
}
|
|
||||||
return $var;
|
|
||||||
case (self::MIXED):
|
|
||||||
return $var;
|
|
||||||
default:
|
|
||||||
$this->errorInconsistent(get_class($this), $type);
|
|
||||||
}
|
|
||||||
$this->errorGeneric($var, $type);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Actually implements the parsing. Base implementation is to not
|
|
||||||
* do anything to $var. Subclasses should overload this!
|
|
||||||
*/
|
|
||||||
protected function parseImplementation($var, $type, $allow_null) {
|
|
||||||
return $var;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Throws an exception.
|
|
||||||
*/
|
|
||||||
protected function error($msg) {
|
|
||||||
throw new HTMLPurifier_VarParserException($msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Throws an inconsistency exception.
|
|
||||||
* @note This should not ever be called. It would be called if we
|
|
||||||
* extend the allowed values of HTMLPurifier_VarParser without
|
|
||||||
* updating subclasses.
|
|
||||||
*/
|
|
||||||
protected function errorInconsistent($class, $type) {
|
|
||||||
throw new HTMLPurifier_Exception("Inconsistency in $class: ".HTMLPurifier_VarParser::getTypeName($type)." not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generic error for if a type didn't work.
|
|
||||||
*/
|
|
||||||
protected function errorGeneric($var, $type) {
|
|
||||||
$vtype = gettype($var);
|
|
||||||
$this->error("Expected type ".HTMLPurifier_VarParser::getTypeName($type).", got $vtype");
|
|
||||||
}
|
|
||||||
|
|
||||||
static public function getTypeName($type) {
|
|
||||||
static $lookup;
|
|
||||||
if (!$lookup) {
|
|
||||||
// Lazy load the alternative lookup table
|
|
||||||
$lookup = array_flip(HTMLPurifier_VarParser::$types);
|
|
||||||
}
|
|
||||||
if (!isset($lookup[$type])) return 'unknown';
|
|
||||||
return $lookup[$type];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// vim: et sw=4 sts=4
|
|
@ -1,5 +0,0 @@
|
|||||||
--HTML--
|
|
||||||
<ul><li>Sublist 1</li><ul><li>Bullet</li></ul></ul>
|
|
||||||
--EXPECT--
|
|
||||||
<ul><li>Sublist 1<ul><li>Bullet</li></ul></li></ul>
|
|
||||||
--# vim: et sw=4 sts=4
|
|
@ -1,11 +0,0 @@
|
|||||||
--INI--
|
|
||||||
URI.Munge = "/redirect?s=%s&t=%t&r=%r&n=%n&m=%m&p=%p"
|
|
||||||
URI.MungeSecretKey = "foo"
|
|
||||||
URI.MungeResources = true
|
|
||||||
--HTML--
|
|
||||||
<a href="http://example.com">Link</a>
|
|
||||||
<img src="http://example.com" style="background-image:url(http://example.com);" alt="example.com" />
|
|
||||||
--EXPECT--
|
|
||||||
<a href="/redirect?s=http%3A%2F%2Fexample.com&t=c15354f3953dfec262c55b1403067e0d045a3059&r=&n=a&m=href&p=">Link</a>
|
|
||||||
<img src="/redirect?s=http%3A%2F%2Fexample.com&t=c15354f3953dfec262c55b1403067e0d045a3059&r=1&n=img&m=src&p=" style="background-image:url("/redirect?s=http%3A%2F%2Fexample.com&t=c15354f3953dfec262c55b1403067e0d045a3059&r=1&n=img&m=style&p=background-image");" alt="example.com" />
|
|
||||||
--# vim: et sw=4 sts=4
|
|
@ -22,3 +22,7 @@ docs/doxygen*
|
|||||||
/*.php
|
/*.php
|
||||||
vendor
|
vendor
|
||||||
composer.lock
|
composer.lock
|
||||||
|
*.rej
|
||||||
|
*.orig
|
||||||
|
*.bak
|
||||||
|
core
|
@ -31,7 +31,7 @@ PROJECT_NAME = HTMLPurifier
|
|||||||
# This could be handy for archiving the generated documentation or
|
# This could be handy for archiving the generated documentation or
|
||||||
# if some version control system is used.
|
# if some version control system is used.
|
||||||
|
|
||||||
PROJECT_NUMBER = 4.5.0
|
PROJECT_NUMBER = 4.6.0
|
||||||
|
|
||||||
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
|
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
|
||||||
# base path where the generated documentation will be put.
|
# base path where the generated documentation will be put.
|
@ -1,4 +1,4 @@
|
|||||||
4 - Minor feature enhancements
|
9 - Major security fixes
|
||||||
|
|
||||||
[ Appendix A: Release focus IDs ]
|
[ Appendix A: Release focus IDs ]
|
||||||
0 - N/A
|
0 - N/A
|
@ -9,6 +9,28 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
|
|||||||
. Internal change
|
. Internal change
|
||||||
==========================
|
==========================
|
||||||
|
|
||||||
|
4.6.0, released 2013-11-30
|
||||||
|
# Secure URI munge hashing algorithm has changed to hash_hmac("sha256", $url, $secret).
|
||||||
|
Please update any verification scripts you may have.
|
||||||
|
# URI parsing algorithm was made more strict, so only prefixes which
|
||||||
|
looks like schemes will actually be schemes. Thanks
|
||||||
|
Michael Gusev <mgusev@sugarcrm.com> for fixing.
|
||||||
|
# %Core.EscapeInvalidChildren is no longer supported, and no longer does
|
||||||
|
anything.
|
||||||
|
! New directive %Core.AllowHostnameUnderscore which allows underscores
|
||||||
|
in hostnames.
|
||||||
|
- Eliminate quadratic behavior in DOMLex by using a proper queue.
|
||||||
|
Thanks Ole Laursen for noticing this.
|
||||||
|
- Rewritten MakeWellFormed/FixNesting implementation eliminates quadratic
|
||||||
|
behavior in the rest of the purificaiton pipeline. Thanks Chedburn
|
||||||
|
Networks for sponsoring this work.
|
||||||
|
- Made Linkify URL parser a bit less permissive, so that non-breaking
|
||||||
|
spaces and commas are not included as part of URL. Thanks nAS for fixing.
|
||||||
|
- Fix some bad interactions with %HTML.Allowed and injectors. Thanks
|
||||||
|
David Hirtz for reporting.
|
||||||
|
- Fix infinite loop in DirectLex. Thanks Ashar Javed (@soaj1664ashar)
|
||||||
|
for reporting.
|
||||||
|
|
||||||
4.5.0, released 2013-02-17
|
4.5.0, released 2013-02-17
|
||||||
# Fix bug where stacked attribute transforms clobber each other;
|
# Fix bug where stacked attribute transforms clobber each other;
|
||||||
this also means it's no longer possible to override attribute
|
this also means it's no longer possible to override attribute
|
||||||
@ -20,10 +42,10 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
|
|||||||
! Permit underscores in font families
|
! Permit underscores in font families
|
||||||
! Support for page-break-* CSS3 properties when proprietary properties
|
! Support for page-break-* CSS3 properties when proprietary properties
|
||||||
are enabled.
|
are enabled.
|
||||||
! New directive %Core.EnableExcludes; can be set to 'false' to turn off
|
! New directive %Core.DisableExcludes; can be set to 'true' to turn off
|
||||||
SGML excludes checking. If HTML Purifier is removing too much text
|
SGML excludes checking. If HTML Purifier is removing too much text
|
||||||
and you don't care about full standards compliance, try setting this to
|
and you don't care about full standards compliance, try setting this to
|
||||||
'false'.
|
'true'.
|
||||||
- Use prepend for SPL autoloading on PHP 5.3 and later.
|
- Use prepend for SPL autoloading on PHP 5.3 and later.
|
||||||
- Fix bug with nofollow transform when pre-existing rel exists.
|
- Fix bug with nofollow transform when pre-existing rel exists.
|
||||||
- Fix bug where background:url() always gets lower-cased
|
- Fix bug where background:url() always gets lower-cased
|
1
inc/lib/htmlpurifier-4.6.0/VERSION
Normal file
@ -0,0 +1 @@
|
|||||||
|
4.6.0
|
5
inc/lib/htmlpurifier-4.6.0/WHATSNEW
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
HTML Purifier 4.6.0 is a major security release, fixing numerous bad
|
||||||
|
quadratic asymptotics in HTML Purifier's core algorithms. Most users will
|
||||||
|
see a decent speedup on large inputs, although small inputs may take
|
||||||
|
longer. Additionally, the secure URI munging algorithm has changed to
|
||||||
|
do a proper HMAC. There are some other miscellaneous bugfixes as well.
|
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.4 KiB |
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
Before Width: | Height: | Size: 382 B After Width: | Height: | Size: 382 B |
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.6 KiB |
Before Width: | Height: | Size: 615 B After Width: | Height: | Size: 615 B |
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.6 KiB |
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 9.8 KiB After Width: | Height: | Size: 9.8 KiB |
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 5.2 KiB |
Before Width: | Height: | Size: 297 B After Width: | Height: | Size: 297 B |
@ -23,15 +23,16 @@ if (version_compare(PHP_VERSION, '5', '>=')) {
|
|||||||
class RowTimer extends Benchmark_Timer
|
class RowTimer extends Benchmark_Timer
|
||||||
{
|
{
|
||||||
|
|
||||||
var $name;
|
public $name;
|
||||||
|
|
||||||
function RowTimer($name, $auto = false) {
|
public function RowTimer($name, $auto = false)
|
||||||
|
{
|
||||||
$this->name = htmlentities($name);
|
$this->name = htmlentities($name);
|
||||||
$this->Benchmark_Timer($auto);
|
$this->Benchmark_Timer($auto);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getOutput() {
|
public function getOutput()
|
||||||
|
{
|
||||||
$total = $this->TimeElapsed();
|
$total = $this->TimeElapsed();
|
||||||
$result = $this->getProfiling();
|
$result = $this->getProfiling();
|
||||||
$dashes = '';
|
$dashes = '';
|
||||||
@ -68,7 +69,8 @@ class RowTimer extends Benchmark_Timer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function print_lexers() {
|
function print_lexers()
|
||||||
|
{
|
||||||
global $LEXERS;
|
global $LEXERS;
|
||||||
$first = true;
|
$first = true;
|
||||||
foreach ($LEXERS as $key => $value) {
|
foreach ($LEXERS as $key => $value) {
|
||||||
@ -78,7 +80,8 @@ function print_lexers() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function do_benchmark($name, $document) {
|
function do_benchmark($name, $document)
|
||||||
|
{
|
||||||
global $LEXERS, $RUNS;
|
global $LEXERS, $RUNS;
|
||||||
|
|
||||||
$config = HTMLPurifier_Config::createDefault();
|
$config = HTMLPurifier_Config::createDefault();
|