mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-01-05 14:11:52 +00:00
[1.7.0] Make AttrDef classes more friendly to serialization by not storing final static data in member variables
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1074 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
7481d349d3
commit
f1ec05afd0
@ -8,11 +8,9 @@ require_once 'HTMLPurifier/AttrDef.php';
|
|||||||
class HTMLPurifier_AttrDef_CSS_Color extends HTMLPurifier_AttrDef
|
class HTMLPurifier_AttrDef_CSS_Color extends HTMLPurifier_AttrDef
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
function validate($color, $config, &$context) {
|
||||||
* Color keyword lookup table.
|
|
||||||
* @todo Extend it to include all usually allowed colors.
|
static $colors = array(
|
||||||
*/
|
|
||||||
var $colors = array(
|
|
||||||
'maroon' => '#800000',
|
'maroon' => '#800000',
|
||||||
'red' => '#F00',
|
'red' => '#F00',
|
||||||
'orange' => '#FFA500',
|
'orange' => '#FFA500',
|
||||||
@ -32,13 +30,11 @@ class HTMLPurifier_AttrDef_CSS_Color extends HTMLPurifier_AttrDef
|
|||||||
'gray' => '#808080'
|
'gray' => '#808080'
|
||||||
);
|
);
|
||||||
|
|
||||||
function validate($color, $config, &$context) {
|
|
||||||
|
|
||||||
$color = trim($color);
|
$color = trim($color);
|
||||||
if (!$color) return false;
|
if (!$color) return false;
|
||||||
|
|
||||||
$lower = strtolower($color);
|
$lower = strtolower($color);
|
||||||
if (isset($this->colors[$lower])) return $this->colors[$lower];
|
if (isset($colors[$lower])) return $colors[$lower];
|
||||||
|
|
||||||
if ($color[0] === '#') {
|
if ($color[0] === '#') {
|
||||||
// hexadecimal handling
|
// hexadecimal handling
|
||||||
|
@ -18,18 +18,6 @@ class HTMLPurifier_AttrDef_CSS_Font extends HTMLPurifier_AttrDef
|
|||||||
*/
|
*/
|
||||||
var $info = array();
|
var $info = array();
|
||||||
|
|
||||||
/**
|
|
||||||
* System font keywords.
|
|
||||||
*/
|
|
||||||
var $system_fonts = array(
|
|
||||||
'caption' => true,
|
|
||||||
'icon' => true,
|
|
||||||
'menu' => true,
|
|
||||||
'message-box' => true,
|
|
||||||
'small-caption' => true,
|
|
||||||
'status-bar' => true
|
|
||||||
);
|
|
||||||
|
|
||||||
function HTMLPurifier_AttrDef_CSS_Font($config) {
|
function HTMLPurifier_AttrDef_CSS_Font($config) {
|
||||||
$def = $config->getCSSDefinition();
|
$def = $config->getCSSDefinition();
|
||||||
$this->info['font-style'] = $def->info['font-style'];
|
$this->info['font-style'] = $def->info['font-style'];
|
||||||
@ -42,13 +30,22 @@ class HTMLPurifier_AttrDef_CSS_Font extends HTMLPurifier_AttrDef
|
|||||||
|
|
||||||
function validate($string, $config, &$context) {
|
function validate($string, $config, &$context) {
|
||||||
|
|
||||||
|
static $system_fonts = array(
|
||||||
|
'caption' => true,
|
||||||
|
'icon' => true,
|
||||||
|
'menu' => true,
|
||||||
|
'message-box' => true,
|
||||||
|
'small-caption' => true,
|
||||||
|
'status-bar' => true
|
||||||
|
);
|
||||||
|
|
||||||
// regular pre-processing
|
// regular pre-processing
|
||||||
$string = $this->parseCDATA($string);
|
$string = $this->parseCDATA($string);
|
||||||
if ($string === '') return false;
|
if ($string === '') return false;
|
||||||
|
|
||||||
// check if it's one of the keywords
|
// check if it's one of the keywords
|
||||||
$lowercase_string = strtolower($string);
|
$lowercase_string = strtolower($string);
|
||||||
if (isset($this->system_fonts[$lowercase_string])) {
|
if (isset($system_fonts[$lowercase_string])) {
|
||||||
return $lowercase_string;
|
return $lowercase_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,11 +10,8 @@ require_once 'HTMLPurifier/AttrDef.php';
|
|||||||
class HTMLPurifier_AttrDef_CSS_FontFamily extends HTMLPurifier_AttrDef
|
class HTMLPurifier_AttrDef_CSS_FontFamily extends HTMLPurifier_AttrDef
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
function validate($string, $config, &$context) {
|
||||||
* Generic font family keywords.
|
static $generic_names = array(
|
||||||
* @protected
|
|
||||||
*/
|
|
||||||
var $generic_names = array(
|
|
||||||
'serif' => true,
|
'serif' => true,
|
||||||
'sans-serif' => true,
|
'sans-serif' => true,
|
||||||
'monospace' => true,
|
'monospace' => true,
|
||||||
@ -22,7 +19,6 @@ class HTMLPurifier_AttrDef_CSS_FontFamily extends HTMLPurifier_AttrDef
|
|||||||
'cursive' => true
|
'cursive' => true
|
||||||
);
|
);
|
||||||
|
|
||||||
function validate($string, $config, &$context) {
|
|
||||||
$string = $this->parseCDATA($string);
|
$string = $this->parseCDATA($string);
|
||||||
// assume that no font names contain commas in them
|
// assume that no font names contain commas in them
|
||||||
$fonts = explode(',', $string);
|
$fonts = explode(',', $string);
|
||||||
@ -31,7 +27,7 @@ class HTMLPurifier_AttrDef_CSS_FontFamily extends HTMLPurifier_AttrDef
|
|||||||
$font = trim($font);
|
$font = trim($font);
|
||||||
if ($font === '') continue;
|
if ($font === '') continue;
|
||||||
// match a generic name
|
// match a generic name
|
||||||
if (isset($this->generic_names[$font])) {
|
if (isset($generic_names[$font])) {
|
||||||
$final .= $font . ', ';
|
$final .= $font . ', ';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -10,23 +10,19 @@ require_once 'HTMLPurifier/AttrDef.php';
|
|||||||
class HTMLPurifier_AttrDef_CSS_TextDecoration extends HTMLPurifier_AttrDef
|
class HTMLPurifier_AttrDef_CSS_TextDecoration extends HTMLPurifier_AttrDef
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
function validate($string, $config, &$context) {
|
||||||
* Lookup table of allowed values.
|
|
||||||
* @protected
|
static $allowed_values = array(
|
||||||
*/
|
|
||||||
var $allowed_values = array(
|
|
||||||
'line-through' => true,
|
'line-through' => true,
|
||||||
'overline' => true,
|
'overline' => true,
|
||||||
'underline' => true
|
'underline' => true
|
||||||
);
|
);
|
||||||
|
|
||||||
function validate($string, $config, &$context) {
|
|
||||||
|
|
||||||
$string = strtolower($this->parseCDATA($string));
|
$string = strtolower($this->parseCDATA($string));
|
||||||
$parts = explode(' ', $string);
|
$parts = explode(' ', $string);
|
||||||
$final = '';
|
$final = '';
|
||||||
foreach ($parts as $part) {
|
foreach ($parts as $part) {
|
||||||
if (isset($this->allowed_values[$part])) {
|
if (isset($allowed_values[$part])) {
|
||||||
$final .= $part . ' ';
|
$final .= $part . ' ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,22 +26,20 @@ HTMLPurifier_ConfigSchema::define(
|
|||||||
class HTMLPurifier_AttrDef_HTML_LinkTypes extends HTMLPurifier_AttrDef
|
class HTMLPurifier_AttrDef_HTML_LinkTypes extends HTMLPurifier_AttrDef
|
||||||
{
|
{
|
||||||
|
|
||||||
/** Lookup array of attribute names to configuration name */
|
|
||||||
var $configLookup = array(
|
|
||||||
'rel' => 'AllowedRel',
|
|
||||||
'rev' => 'AllowedRev'
|
|
||||||
);
|
|
||||||
|
|
||||||
/** Name config attribute to pull. */
|
/** Name config attribute to pull. */
|
||||||
var $name;
|
var $name;
|
||||||
|
|
||||||
function HTMLPurifier_AttrDef_HTML_LinkTypes($name) {
|
function HTMLPurifier_AttrDef_HTML_LinkTypes($name) {
|
||||||
if (!isset($this->configLookup[$name])) {
|
$configLookup = array(
|
||||||
|
'rel' => 'AllowedRel',
|
||||||
|
'rev' => 'AllowedRev'
|
||||||
|
);
|
||||||
|
if (!isset($configLookup[$name])) {
|
||||||
trigger_error('Unrecognized attribute name for link '.
|
trigger_error('Unrecognized attribute name for link '.
|
||||||
'relationship.', E_USER_ERROR);
|
'relationship.', E_USER_ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->name = $this->configLookup[$name];
|
$this->name = $configLookup[$name];
|
||||||
}
|
}
|
||||||
|
|
||||||
function validate($string, $config, &$context) {
|
function validate($string, $config, &$context) {
|
||||||
|
@ -93,7 +93,6 @@ class HTMLPurifier_AttrDef_URI extends HTMLPurifier_AttrDef
|
|||||||
{
|
{
|
||||||
|
|
||||||
var $host;
|
var $host;
|
||||||
var $PercentEncoder;
|
|
||||||
var $embeds_resource;
|
var $embeds_resource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -101,12 +100,14 @@ class HTMLPurifier_AttrDef_URI extends HTMLPurifier_AttrDef
|
|||||||
*/
|
*/
|
||||||
function HTMLPurifier_AttrDef_URI($embeds_resource = false) {
|
function HTMLPurifier_AttrDef_URI($embeds_resource = false) {
|
||||||
$this->host = new HTMLPurifier_AttrDef_URI_Host();
|
$this->host = new HTMLPurifier_AttrDef_URI_Host();
|
||||||
$this->PercentEncoder = new HTMLPurifier_PercentEncoder();
|
|
||||||
$this->embeds_resource = (bool) $embeds_resource;
|
$this->embeds_resource = (bool) $embeds_resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
function validate($uri, $config, &$context) {
|
function validate($uri, $config, &$context) {
|
||||||
|
|
||||||
|
static $PercentEncoder = null;
|
||||||
|
if ($PercentEncoder === null) $PercentEncoder = new HTMLPurifier_PercentEncoder();
|
||||||
|
|
||||||
// We'll write stack-based parsers later, for now, use regexps to
|
// We'll write stack-based parsers later, for now, use regexps to
|
||||||
// get things working as fast as possible (irony)
|
// get things working as fast as possible (irony)
|
||||||
|
|
||||||
@ -116,7 +117,7 @@ class HTMLPurifier_AttrDef_URI extends HTMLPurifier_AttrDef
|
|||||||
$uri = $this->parseCDATA($uri);
|
$uri = $this->parseCDATA($uri);
|
||||||
|
|
||||||
// fix up percent-encoding
|
// fix up percent-encoding
|
||||||
$uri = $this->PercentEncoder->normalize($uri);
|
$uri = $PercentEncoder->normalize($uri);
|
||||||
|
|
||||||
// while it would be nice to use parse_url(), that's specifically
|
// while it would be nice to use parse_url(), that's specifically
|
||||||
// for HTTP and thus won't work for our generic URI parsing
|
// for HTTP and thus won't work for our generic URI parsing
|
||||||
|
Loading…
Reference in New Issue
Block a user