diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier.autoload.php b/htdocs/lib/htmlpurifier/HTMLPurifier.autoload.php
index 62da5b60d426bc9fcba974061fce36d6ca2a5f19..c3ea67e8145c5ce0e37324cc5582b6b0da462813 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier.autoload.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier.autoload.php
@@ -14,7 +14,8 @@ if (function_exists('spl_autoload_register') && function_exists('spl_autoload_un
spl_autoload_register('__autoload');
}
} elseif (!function_exists('__autoload')) {
- function __autoload($class) {
+ function __autoload($class)
+ {
return HTMLPurifier_Bootstrap::autoload($class);
}
}
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier.composer.php b/htdocs/lib/htmlpurifier/HTMLPurifier.composer.php
new file mode 100644
index 0000000000000000000000000000000000000000..6706f4e397d547cdb449ab446e8f81f9157bcfd6
--- /dev/null
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier.composer.php
@@ -0,0 +1,4 @@
+set('HTML.AllowedElements', $allowed_elements);
$config->set('HTML.AllowedAttributes', $allowed_attributes);
- $allowed_schemes = array();
if ($allowed_protocols !== null) {
$config->set('URI.AllowedSchemes', $allowed_protocols);
}
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier.php b/htdocs/lib/htmlpurifier/HTMLPurifier.php
index e599e1c0c9b56710f7f988b2269557eaf9e26d0d..6f654fde5a3b8e51e9e9cdd8440f86434165e2d3 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier.php
@@ -19,7 +19,7 @@
*/
/*
- HTML Purifier 4.4.0 - Standards Compliant HTML Filtering
+ HTML Purifier 4.6.0 - Standards Compliant HTML Filtering
Copyright (C) 2006-2008 Edward Z. Yang
This library is free software; you can redistribute it and/or
@@ -54,66 +54,97 @@
class HTMLPurifier
{
- /** Version of HTML Purifier */
- public $version = '4.4.0';
+ /**
+ * Version of HTML Purifier.
+ * @type string
+ */
+ public $version = '4.6.0';
- /** Constant with version of HTML Purifier */
- const VERSION = '4.4.0';
+ /**
+ * Constant with version of HTML Purifier.
+ */
+ const VERSION = '4.6.0';
- /** Global configuration object */
+ /**
+ * Global configuration object.
+ * @type HTMLPurifier_Config
+ */
public $config;
- /** Array of extra HTMLPurifier_Filter objects to run on HTML, for backwards compatibility */
+ /**
+ * Array of extra filter objects to run on HTML,
+ * for backwards compatibility.
+ * @type HTMLPurifier_Filter[]
+ */
private $filters = array();
- /** Single instance of HTML Purifier */
+ /**
+ * Single instance of HTML Purifier.
+ * @type HTMLPurifier
+ */
private static $instance;
- protected $strategy, $generator;
+ /**
+ * @type HTMLPurifier_Strategy_Core
+ */
+ protected $strategy;
+
+ /**
+ * @type HTMLPurifier_Generator
+ */
+ protected $generator;
/**
- * Resultant HTMLPurifier_Context of last run purification. Is an array
- * of contexts if the last called method was purifyArray().
+ * Resultant context of last run purification.
+ * Is an array of contexts if the last called method was purifyArray().
+ * @type HTMLPurifier_Context
*/
public $context;
/**
* Initializes the purifier.
- * @param $config Optional HTMLPurifier_Config object for all instances of
- * the purifier, if omitted, a default configuration is
- * supplied (which can be overridden on a per-use basis).
+ *
+ * @param HTMLPurifier_Config $config Optional HTMLPurifier_Config object
+ * for all instances of the purifier, if omitted, a default
+ * configuration is supplied (which can be overridden on a
+ * per-use basis).
* The parameter can also be any type that
* HTMLPurifier_Config::create() supports.
*/
- public function __construct($config = null) {
-
+ public function __construct($config = null)
+ {
$this->config = HTMLPurifier_Config::create($config);
-
- $this->strategy = new HTMLPurifier_Strategy_Core();
-
+ $this->strategy = new HTMLPurifier_Strategy_Core();
}
/**
* Adds a filter to process the output. First come first serve
- * @param $filter HTMLPurifier_Filter object
+ *
+ * @param HTMLPurifier_Filter $filter HTMLPurifier_Filter object
*/
- public function addFilter($filter) {
- trigger_error('HTMLPurifier->addFilter() is deprecated, use configuration directives in the Filter namespace or Filter.Custom', E_USER_WARNING);
+ public function addFilter($filter)
+ {
+ trigger_error(
+ 'HTMLPurifier->addFilter() is deprecated, use configuration directives' .
+ ' in the Filter namespace or Filter.Custom',
+ E_USER_WARNING
+ );
$this->filters[] = $filter;
}
/**
* Filters an HTML snippet/document to be XSS-free and standards-compliant.
*
- * @param $html String of HTML to purify
- * @param $config HTMLPurifier_Config object for this operation, if omitted,
- * defaults to the config object specified during this
+ * @param string $html String of HTML to purify
+ * @param HTMLPurifier_Config $config Config object for this operation,
+ * if omitted, defaults to the config object specified during this
* object's construction. The parameter can also be any type
* that HTMLPurifier_Config::create() supports.
- * @return Purified HTML
+ *
+ * @return string Purified HTML
*/
- public function purify($html, $config = null) {
-
+ public function purify($html, $config = null)
+ {
// :TODO: make the config merge in, instead of replace
$config = $config ? HTMLPurifier_Config::create($config) : $this->config;
@@ -151,8 +182,12 @@ class HTMLPurifier
unset($filter_flags['Custom']);
$filters = array();
foreach ($filter_flags as $filter => $flag) {
- if (!$flag) continue;
- if (strpos($filter, '.') !== false) continue;
+ if (!$flag) {
+ continue;
+ }
+ if (strpos($filter, '.') !== false) {
+ continue;
+ }
$class = "HTMLPurifier_Filter_$filter";
$filters[] = new $class;
}
@@ -175,9 +210,12 @@ class HTMLPurifier
// list of un-purified tokens
$lexer->tokenizeHTML(
// un-purified HTML
- $html, $config, $context
+ $html,
+ $config,
+ $context
),
- $config, $context
+ $config,
+ $context
)
);
@@ -192,11 +230,15 @@ class HTMLPurifier
/**
* Filters an array of HTML snippets
- * @param $config Optional HTMLPurifier_Config object for this operation.
+ *
+ * @param string[] $array_of_html Array of html snippets
+ * @param HTMLPurifier_Config $config Optional config object for this operation.
* See HTMLPurifier::purify() for more details.
- * @return Array of purified HTML
+ *
+ * @return string[] Array of purified HTML
*/
- public function purifyArray($array_of_html, $config = null) {
+ public function purifyArray($array_of_html, $config = null)
+ {
$context_array = array();
foreach ($array_of_html as $key => $html) {
$array_of_html[$key] = $this->purify($html, $config);
@@ -208,11 +250,16 @@ class HTMLPurifier
/**
* Singleton for enforcing just one HTML Purifier in your system
- * @param $prototype Optional prototype HTMLPurifier instance to
- * overload singleton with, or HTMLPurifier_Config
- * instance to configure the generated version with.
+ *
+ * @param HTMLPurifier|HTMLPurifier_Config $prototype Optional prototype
+ * HTMLPurifier instance to overload singleton with,
+ * or HTMLPurifier_Config instance to configure the
+ * generated version with.
+ *
+ * @return HTMLPurifier
*/
- public static function instance($prototype = null) {
+ public static function instance($prototype = null)
+ {
if (!self::$instance || $prototype) {
if ($prototype instanceof HTMLPurifier) {
self::$instance = $prototype;
@@ -226,12 +273,20 @@ class HTMLPurifier
}
/**
+ * Singleton for enforcing just one HTML Purifier in your system
+ *
+ * @param HTMLPurifier|HTMLPurifier_Config $prototype Optional prototype
+ * HTMLPurifier instance to overload singleton with,
+ * or HTMLPurifier_Config instance to configure the
+ * generated version with.
+ *
+ * @return HTMLPurifier
* @note Backwards compatibility, see instance()
*/
- public static function getInstance($prototype = null) {
+ public static function getInstance($prototype = null)
+ {
return HTMLPurifier::instance($prototype);
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier.safe-includes.php b/htdocs/lib/htmlpurifier/HTMLPurifier.safe-includes.php
index d49b196c429ea75d4bd2a1237fc2d3adb0a9fea3..9dea6d1ed55d9f8c69b5a968c62c5f701e5887e4 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier.safe-includes.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier.safe-includes.php
@@ -13,6 +13,7 @@
$__dir = dirname(__FILE__);
require_once $__dir . '/HTMLPurifier.php';
+require_once $__dir . '/HTMLPurifier/Arborize.php';
require_once $__dir . '/HTMLPurifier/AttrCollections.php';
require_once $__dir . '/HTMLPurifier/AttrDef.php';
require_once $__dir . '/HTMLPurifier/AttrTransform.php';
@@ -48,9 +49,11 @@ require_once $__dir . '/HTMLPurifier/Language.php';
require_once $__dir . '/HTMLPurifier/LanguageFactory.php';
require_once $__dir . '/HTMLPurifier/Length.php';
require_once $__dir . '/HTMLPurifier/Lexer.php';
+require_once $__dir . '/HTMLPurifier/Node.php';
require_once $__dir . '/HTMLPurifier/PercentEncoder.php';
require_once $__dir . '/HTMLPurifier/PropertyList.php';
require_once $__dir . '/HTMLPurifier/PropertyListIterator.php';
+require_once $__dir . '/HTMLPurifier/Queue.php';
require_once $__dir . '/HTMLPurifier/Strategy.php';
require_once $__dir . '/HTMLPurifier/StringHash.php';
require_once $__dir . '/HTMLPurifier/StringHashParser.php';
@@ -66,6 +69,7 @@ require_once $__dir . '/HTMLPurifier/URISchemeRegistry.php';
require_once $__dir . '/HTMLPurifier/UnitConverter.php';
require_once $__dir . '/HTMLPurifier/VarParser.php';
require_once $__dir . '/HTMLPurifier/VarParserException.php';
+require_once $__dir . '/HTMLPurifier/Zipper.php';
require_once $__dir . '/HTMLPurifier/AttrDef/CSS.php';
require_once $__dir . '/HTMLPurifier/AttrDef/Clone.php';
require_once $__dir . '/HTMLPurifier/AttrDef/Enum.php';
@@ -159,6 +163,7 @@ require_once $__dir . '/HTMLPurifier/HTMLModule/Proprietary.php';
require_once $__dir . '/HTMLPurifier/HTMLModule/Ruby.php';
require_once $__dir . '/HTMLPurifier/HTMLModule/SafeEmbed.php';
require_once $__dir . '/HTMLPurifier/HTMLModule/SafeObject.php';
+require_once $__dir . '/HTMLPurifier/HTMLModule/SafeScripting.php';
require_once $__dir . '/HTMLPurifier/HTMLModule/Scripting.php';
require_once $__dir . '/HTMLPurifier/HTMLModule/StyleAttribute.php';
require_once $__dir . '/HTMLPurifier/HTMLModule/Tables.php';
@@ -182,6 +187,9 @@ require_once $__dir . '/HTMLPurifier/Injector/RemoveSpansWithoutAttributes.php';
require_once $__dir . '/HTMLPurifier/Injector/SafeObject.php';
require_once $__dir . '/HTMLPurifier/Lexer/DOMLex.php';
require_once $__dir . '/HTMLPurifier/Lexer/DirectLex.php';
+require_once $__dir . '/HTMLPurifier/Node/Comment.php';
+require_once $__dir . '/HTMLPurifier/Node/Element.php';
+require_once $__dir . '/HTMLPurifier/Node/Text.php';
require_once $__dir . '/HTMLPurifier/Strategy/Composite.php';
require_once $__dir . '/HTMLPurifier/Strategy/Core.php';
require_once $__dir . '/HTMLPurifier/Strategy/FixNesting.php';
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/Arborize.php b/htdocs/lib/htmlpurifier/HTMLPurifier/Arborize.php
new file mode 100644
index 0000000000000000000000000000000000000000..9e6617be5de4bc6416d44ff53137dd2320f10ce0
--- /dev/null
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/Arborize.php
@@ -0,0 +1,71 @@
+getHTMLDefinition();
+ $parent = new HTMLPurifier_Token_Start($definition->info_parent);
+ $stack = array($parent->toNode());
+ foreach ($tokens as $token) {
+ $token->skip = null; // [MUT]
+ $token->carryover = null; // [MUT]
+ if ($token instanceof HTMLPurifier_Token_End) {
+ $token->start = null; // [MUT]
+ $r = array_pop($stack);
+ assert($r->name === $token->name);
+ assert(empty($token->attr));
+ $r->endCol = $token->col;
+ $r->endLine = $token->line;
+ $r->endArmor = $token->armor;
+ continue;
+ }
+ $node = $token->toNode();
+ $stack[count($stack)-1]->children[] = $node;
+ if ($token instanceof HTMLPurifier_Token_Start) {
+ $stack[] = $node;
+ }
+ }
+ assert(count($stack) == 1);
+ return $stack[0];
+ }
+
+ public static function flatten($node, $config, $context) {
+ $level = 0;
+ $nodes = array($level => new HTMLPurifier_Queue(array($node)));
+ $closingTokens = array();
+ $tokens = array();
+ do {
+ while (!$nodes[$level]->isEmpty()) {
+ $node = $nodes[$level]->shift(); // FIFO
+ list($start, $end) = $node->toTokenPair();
+ if ($level > 0) {
+ $tokens[] = $start;
+ }
+ if ($end !== NULL) {
+ $closingTokens[$level][] = $end;
+ }
+ if ($node instanceof HTMLPurifier_Node_Element) {
+ $level++;
+ $nodes[$level] = new HTMLPurifier_Queue();
+ foreach ($node->children as $childNode) {
+ $nodes[$level]->push($childNode);
+ }
+ }
+ }
+ $level--;
+ if ($level && isset($closingTokens[$level])) {
+ while ($token = array_pop($closingTokens[$level])) {
+ $tokens[] = $token;
+ }
+ }
+ } while ($level > 0);
+ return $tokens;
+ }
+}
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrCollections.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrCollections.php
index 555b86d0428d7e3770ea58d1745d80d0bd2f73cf..4f6c2e39a2ed49356859391e114becae2ce54b38 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrCollections.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrCollections.php
@@ -8,7 +8,8 @@ class HTMLPurifier_AttrCollections
{
/**
- * Associative array of attribute collections, indexed by name
+ * Associative array of attribute collections, indexed by name.
+ * @type array
*/
public $info = array();
@@ -16,10 +17,11 @@ class HTMLPurifier_AttrCollections
* Performs all expansions on internal data for use by other inclusions
* It also collects all attribute collection extensions from
* modules
- * @param $attr_types HTMLPurifier_AttrTypes instance
- * @param $modules Hash array of HTMLPurifier_HTMLModule members
+ * @param HTMLPurifier_AttrTypes $attr_types HTMLPurifier_AttrTypes instance
+ * @param HTMLPurifier_HTMLModule[] $modules Hash array of HTMLPurifier_HTMLModule members
*/
- public function __construct($attr_types, $modules) {
+ public function __construct($attr_types, $modules)
+ {
// load extensions from the modules
foreach ($modules as $module) {
foreach ($module->attr_collections as $coll_i => $coll) {
@@ -30,7 +32,9 @@ class HTMLPurifier_AttrCollections
if ($attr_i === 0 && isset($this->info[$coll_i][$attr_i])) {
// merge in includes
$this->info[$coll_i][$attr_i] = array_merge(
- $this->info[$coll_i][$attr_i], $attr);
+ $this->info[$coll_i][$attr_i],
+ $attr
+ );
continue;
}
$this->info[$coll_i][$attr_i] = $attr;
@@ -49,20 +53,29 @@ class HTMLPurifier_AttrCollections
/**
* Takes a reference to an attribute associative array and performs
* all inclusions specified by the zero index.
- * @param &$attr Reference to attribute array
+ * @param array &$attr Reference to attribute array
*/
- public function performInclusions(&$attr) {
- if (!isset($attr[0])) return;
+ public function performInclusions(&$attr)
+ {
+ if (!isset($attr[0])) {
+ return;
+ }
$merge = $attr[0];
$seen = array(); // recursion guard
// loop through all the inclusions
for ($i = 0; isset($merge[$i]); $i++) {
- if (isset($seen[$merge[$i]])) continue;
+ if (isset($seen[$merge[$i]])) {
+ continue;
+ }
$seen[$merge[$i]] = true;
// foreach attribute of the inclusion, copy it over
- if (!isset($this->info[$merge[$i]])) continue;
+ if (!isset($this->info[$merge[$i]])) {
+ continue;
+ }
foreach ($this->info[$merge[$i]] as $key => $value) {
- if (isset($attr[$key])) continue; // also catches more inclusions
+ if (isset($attr[$key])) {
+ continue;
+ } // also catches more inclusions
$attr[$key] = $value;
}
if (isset($this->info[$merge[$i]][0])) {
@@ -76,20 +89,24 @@ class HTMLPurifier_AttrCollections
/**
* Expands all string identifiers in an attribute array by replacing
* them with the appropriate values inside HTMLPurifier_AttrTypes
- * @param &$attr Reference to attribute array
- * @param $attr_types HTMLPurifier_AttrTypes instance
+ * @param array &$attr Reference to attribute array
+ * @param HTMLPurifier_AttrTypes $attr_types HTMLPurifier_AttrTypes instance
*/
- public function expandIdentifiers(&$attr, $attr_types) {
-
+ public function expandIdentifiers(&$attr, $attr_types)
+ {
// because foreach will process new elements we add, make sure we
// skip duplicates
$processed = array();
foreach ($attr as $def_i => $def) {
// skip inclusions
- if ($def_i === 0) continue;
+ if ($def_i === 0) {
+ continue;
+ }
- if (isset($processed[$def_i])) continue;
+ if (isset($processed[$def_i])) {
+ continue;
+ }
// determine whether or not attribute is required
if ($required = (strpos($def_i, '*') !== false)) {
@@ -120,9 +137,7 @@ class HTMLPurifier_AttrCollections
unset($attr[$def_i]);
}
}
-
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef.php
index b2e4f36c5df40bdd12c93930c06c93a964aa5101..5ac06522b9eb7dca361042f9c4801371d2d5250c 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef.php
@@ -14,23 +14,25 @@ abstract class HTMLPurifier_AttrDef
{
/**
- * Tells us whether or not an HTML attribute is minimized. Has no
- * meaning in other contexts.
+ * Tells us whether or not an HTML attribute is minimized.
+ * Has no meaning in other contexts.
+ * @type bool
*/
public $minimized = false;
/**
- * Tells us whether or not an HTML attribute is required. Has no
- * meaning in other contexts
+ * Tells us whether or not an HTML attribute is required.
+ * Has no meaning in other contexts
+ * @type bool
*/
public $required = false;
/**
* Validates and cleans passed string according to a definition.
*
- * @param $string String to be validated and cleaned.
- * @param $config Mandatory HTMLPurifier_Config object.
- * @param $context Mandatory HTMLPurifier_AttrContext object.
+ * @param string $string String to be validated and cleaned.
+ * @param HTMLPurifier_Config $config Mandatory HTMLPurifier_Config object.
+ * @param HTMLPurifier_Context $context Mandatory HTMLPurifier_Context object.
*/
abstract public function validate($string, $config, $context);
@@ -55,7 +57,8 @@ abstract class HTMLPurifier_AttrDef
* parsing XML, thus, this behavior may still be correct. We
* assume that newlines have been normalized.
*/
- public function parseCDATA($string) {
+ public function parseCDATA($string)
+ {
$string = trim($string);
$string = str_replace(array("\n", "\t", "\r"), ' ', $string);
return $string;
@@ -63,10 +66,11 @@ abstract class HTMLPurifier_AttrDef
/**
* Factory method for creating this class from a string.
- * @param $string String construction info
- * @return Created AttrDef object corresponding to $string
+ * @param string $string String construction info
+ * @return HTMLPurifier_AttrDef Created AttrDef object corresponding to $string
*/
- public function make($string) {
+ public function make($string)
+ {
// default implementation, return a flyweight of this object.
// If $string has an effect on the returned object (i.e. you
// need to overload this method), it is best
@@ -77,16 +81,20 @@ abstract class HTMLPurifier_AttrDef
/**
* Removes spaces from rgb(0, 0, 0) so that shorthand CSS properties work
* properly. THIS IS A HACK!
+ * @param string $string a CSS colour definition
+ * @return string
*/
- protected function mungeRgb($string) {
+ protected function mungeRgb($string)
+ {
return preg_replace('/rgb\((\d+)\s*,\s*(\d+)\s*,\s*(\d+)\)/', 'rgb(\1,\2,\3)', $string);
}
/**
- * Parses a possibly escaped CSS string and returns the "pure"
+ * Parses a possibly escaped CSS string and returns the "pure"
* version of it.
*/
- protected function expandCSSEscape($string) {
+ protected function expandCSSEscape($string)
+ {
// flexibly parse it
$ret = '';
for ($i = 0, $c = strlen($string); $i < $c; $i++) {
@@ -99,25 +107,32 @@ abstract class HTMLPurifier_AttrDef
if (ctype_xdigit($string[$i])) {
$code = $string[$i];
for ($a = 1, $i++; $i < $c && $a < 6; $i++, $a++) {
- if (!ctype_xdigit($string[$i])) break;
+ if (!ctype_xdigit($string[$i])) {
+ break;
+ }
$code .= $string[$i];
}
// We have to be extremely careful when adding
// new characters, to make sure we're not breaking
// the encoding.
$char = HTMLPurifier_Encoder::unichr(hexdec($code));
- if (HTMLPurifier_Encoder::cleanUTF8($char) === '') continue;
+ if (HTMLPurifier_Encoder::cleanUTF8($char) === '') {
+ continue;
+ }
$ret .= $char;
- if ($i < $c && trim($string[$i]) !== '') $i--;
+ if ($i < $c && trim($string[$i]) !== '') {
+ $i--;
+ }
+ continue;
+ }
+ if ($string[$i] === "\n") {
continue;
}
- if ($string[$i] === "\n") continue;
}
$ret .= $string[$i];
}
return $ret;
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS.php
index 953e70675556b1074fcf18e946605b46efbd3052..02c1641fb2a14abb2165996d35eec77b1b9347e1 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS.php
@@ -14,8 +14,14 @@
class HTMLPurifier_AttrDef_CSS extends HTMLPurifier_AttrDef
{
- public function validate($css, $config, $context) {
-
+ /**
+ * @param string $css
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($css, $config, $context)
+ {
$css = $this->parseCDATA($css);
$definition = $config->getCSSDefinition();
@@ -36,34 +42,47 @@ class HTMLPurifier_AttrDef_CSS extends HTMLPurifier_AttrDef
$context->register('CurrentCSSProperty', $property);
foreach ($declarations as $declaration) {
- if (!$declaration) continue;
- if (!strpos($declaration, ':')) continue;
+ if (!$declaration) {
+ continue;
+ }
+ if (!strpos($declaration, ':')) {
+ continue;
+ }
list($property, $value) = explode(':', $declaration, 2);
$property = trim($property);
- $value = trim($value);
+ $value = trim($value);
$ok = false;
do {
if (isset($definition->info[$property])) {
$ok = true;
break;
}
- if (ctype_lower($property)) break;
+ if (ctype_lower($property)) {
+ break;
+ }
$property = strtolower($property);
if (isset($definition->info[$property])) {
$ok = true;
break;
}
- } while(0);
- if (!$ok) continue;
+ } while (0);
+ if (!$ok) {
+ continue;
+ }
// inefficient call, since the validator will do this again
if (strtolower(trim($value)) !== 'inherit') {
// inherit works for everything (but only on the base property)
$result = $definition->info[$property]->validate(
- $value, $config, $context );
+ $value,
+ $config,
+ $context
+ );
} else {
$result = 'inherit';
}
- if ($result === false) continue;
+ if ($result === false) {
+ continue;
+ }
$propvalues[$property] = $result;
}
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/AlphaValue.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/AlphaValue.php
index 292c040d4bd525f708add43159301302eb717ff1..af2b83dff83acea6624243bcad98187355c2c209 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/AlphaValue.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/AlphaValue.php
@@ -3,19 +3,32 @@
class HTMLPurifier_AttrDef_CSS_AlphaValue extends HTMLPurifier_AttrDef_CSS_Number
{
- public function __construct() {
+ public function __construct()
+ {
parent::__construct(false); // opacity is non-negative, but we will clamp it
}
- public function validate($number, $config, $context) {
+ /**
+ * @param string $number
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return string
+ */
+ 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';
+ 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
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Background.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Background.php
index 3a3d20cd6a7cb830204d2b1f8cfce3f05a5f8a9c..7f1ea3b0f1debcbf497b5e284b3bf3b96bb39ccf 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Background.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Background.php
@@ -9,11 +9,16 @@ class HTMLPurifier_AttrDef_CSS_Background extends HTMLPurifier_AttrDef
/**
* Local copy of component validators.
+ * @type HTMLPurifier_AttrDef[]
* @note See HTMLPurifier_AttrDef_Font::$info for a similar impl.
*/
protected $info;
- public function __construct($config) {
+ /**
+ * @param HTMLPurifier_Config $config
+ */
+ public function __construct($config)
+ {
$def = $config->getCSSDefinition();
$this->info['background-color'] = $def->info['background-color'];
$this->info['background-image'] = $def->info['background-image'];
@@ -22,40 +27,55 @@ class HTMLPurifier_AttrDef_CSS_Background extends HTMLPurifier_AttrDef
$this->info['background-position'] = $def->info['background-position'];
}
- public function validate($string, $config, $context) {
-
+ /**
+ * @param string $string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($string, $config, $context)
+ {
// regular pre-processing
$string = $this->parseCDATA($string);
- if ($string === '') return false;
+ if ($string === '') {
+ return false;
+ }
// munge rgb() decl if necessary
$string = $this->mungeRgb($string);
// assumes URI doesn't have spaces in it
- $bits = explode(' ', strtolower($string)); // bits to process
+ $bits = explode(' ', $string); // bits to process
$caught = array();
- $caught['color'] = false;
- $caught['image'] = false;
- $caught['repeat'] = false;
+ $caught['color'] = false;
+ $caught['image'] = false;
+ $caught['repeat'] = false;
$caught['attachment'] = false;
$caught['position'] = false;
$i = 0; // number of catches
- $none = false;
foreach ($bits as $bit) {
- if ($bit === '') continue;
+ if ($bit === '') {
+ continue;
+ }
foreach ($caught as $key => $status) {
if ($key != 'position') {
- if ($status !== false) continue;
+ if ($status !== false) {
+ continue;
+ }
$r = $this->info['background-' . $key]->validate($bit, $config, $context);
} else {
$r = $bit;
}
- if ($r === false) continue;
+ if ($r === false) {
+ continue;
+ }
if ($key == 'position') {
- if ($caught[$key] === false) $caught[$key] = '';
+ if ($caught[$key] === false) {
+ $caught[$key] = '';
+ }
$caught[$key] .= $r . ' ';
} else {
$caught[$key] = $r;
@@ -65,7 +85,9 @@ class HTMLPurifier_AttrDef_CSS_Background extends HTMLPurifier_AttrDef
}
}
- if (!$i) return false;
+ if (!$i) {
+ return false;
+ }
if ($caught['position'] !== false) {
$caught['position'] = $this->info['background-position']->
validate($caught['position'], $config, $context);
@@ -73,15 +95,17 @@ class HTMLPurifier_AttrDef_CSS_Background extends HTMLPurifier_AttrDef
$ret = array();
foreach ($caught as $value) {
- if ($value === false) continue;
+ if ($value === false) {
+ continue;
+ }
$ret[] = $value;
}
- if (empty($ret)) return false;
+ if (empty($ret)) {
+ return false;
+ }
return implode(' ', $ret);
-
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/BackgroundPosition.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/BackgroundPosition.php
index fae82eaec8093db4c2de72db706110c58f7cb97c..4580ef5a91e48e817ff01896ec490330aa2bda9b 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/BackgroundPosition.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/BackgroundPosition.php
@@ -44,15 +44,30 @@
class HTMLPurifier_AttrDef_CSS_BackgroundPosition extends HTMLPurifier_AttrDef
{
+ /**
+ * @type HTMLPurifier_AttrDef_CSS_Length
+ */
protected $length;
+
+ /**
+ * @type HTMLPurifier_AttrDef_CSS_Percentage
+ */
protected $percentage;
- public function __construct() {
- $this->length = new HTMLPurifier_AttrDef_CSS_Length();
+ public function __construct()
+ {
+ $this->length = new HTMLPurifier_AttrDef_CSS_Length();
$this->percentage = new HTMLPurifier_AttrDef_CSS_Percentage();
}
- public function validate($string, $config, $context) {
+ /**
+ * @param string $string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($string, $config, $context)
+ {
$string = $this->parseCDATA($string);
$bits = explode(' ', $string);
@@ -74,7 +89,9 @@ class HTMLPurifier_AttrDef_CSS_BackgroundPosition extends HTMLPurifier_AttrDef
);
foreach ($bits as $bit) {
- if ($bit === '') continue;
+ if ($bit === '') {
+ continue;
+ }
// test for keyword
$lbit = ctype_lower($bit) ? $bit : strtolower($bit);
@@ -104,30 +121,37 @@ class HTMLPurifier_AttrDef_CSS_BackgroundPosition extends HTMLPurifier_AttrDef
$measures[] = $r;
$i++;
}
-
}
- if (!$i) return false; // no valid values were caught
+ if (!$i) {
+ return false;
+ } // no valid values were caught
$ret = array();
// first keyword
- if ($keywords['h']) $ret[] = $keywords['h'];
- elseif ($keywords['ch']) {
+ if ($keywords['h']) {
+ $ret[] = $keywords['h'];
+ } elseif ($keywords['ch']) {
$ret[] = $keywords['ch'];
$keywords['cv'] = false; // prevent re-use: center = center center
+ } elseif (count($measures)) {
+ $ret[] = array_shift($measures);
}
- elseif (count($measures)) $ret[] = array_shift($measures);
- if ($keywords['v']) $ret[] = $keywords['v'];
- elseif ($keywords['cv']) $ret[] = $keywords['cv'];
- elseif (count($measures)) $ret[] = array_shift($measures);
+ if ($keywords['v']) {
+ $ret[] = $keywords['v'];
+ } elseif ($keywords['cv']) {
+ $ret[] = $keywords['cv'];
+ } elseif (count($measures)) {
+ $ret[] = array_shift($measures);
+ }
- if (empty($ret)) return false;
+ if (empty($ret)) {
+ return false;
+ }
return implode(' ', $ret);
-
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Border.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Border.php
index 42a1d1b4ae36290be99d29a24d7ee2c67a01abdc..16243ba1ed274d6a767e903a0327b8a88319bc05 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Border.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Border.php
@@ -8,17 +8,29 @@ class HTMLPurifier_AttrDef_CSS_Border extends HTMLPurifier_AttrDef
/**
* Local copy of properties this property is shorthand for.
+ * @type HTMLPurifier_AttrDef[]
*/
protected $info = array();
- public function __construct($config) {
+ /**
+ * @param HTMLPurifier_Config $config
+ */
+ public function __construct($config)
+ {
$def = $config->getCSSDefinition();
$this->info['border-width'] = $def->info['border-width'];
$this->info['border-style'] = $def->info['border-style'];
$this->info['border-top-color'] = $def->info['border-top-color'];
}
- public function validate($string, $config, $context) {
+ /**
+ * @param string $string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($string, $config, $context)
+ {
$string = $this->parseCDATA($string);
$string = $this->mungeRgb($string);
$bits = explode(' ', $string);
@@ -26,7 +38,9 @@ class HTMLPurifier_AttrDef_CSS_Border extends HTMLPurifier_AttrDef
$ret = ''; // return value
foreach ($bits as $bit) {
foreach ($this->info as $propname => $validator) {
- if (isset($done[$propname])) continue;
+ if (isset($done[$propname])) {
+ continue;
+ }
$r = $validator->validate($bit, $config, $context);
if ($r !== false) {
$ret .= $r . ' ';
@@ -37,7 +51,6 @@ class HTMLPurifier_AttrDef_CSS_Border extends HTMLPurifier_AttrDef
}
return rtrim($ret);
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Color.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Color.php
index 07f95a6719149ca6919d8143c80ead8f24bd54aa..16d2a6b98c1e8ba09907d8025eae5c8364f85c5d 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Color.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Color.php
@@ -6,29 +6,47 @@
class HTMLPurifier_AttrDef_CSS_Color extends HTMLPurifier_AttrDef
{
- public function validate($color, $config, $context) {
-
+ /**
+ * @param string $color
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($color, $config, $context)
+ {
static $colors = null;
- if ($colors === null) $colors = $config->get('Core.ColorKeywords');
+ if ($colors === null) {
+ $colors = $config->get('Core.ColorKeywords');
+ }
$color = trim($color);
- if ($color === '') return false;
+ if ($color === '') {
+ return false;
+ }
$lower = strtolower($color);
- if (isset($colors[$lower])) return $colors[$lower];
+ if (isset($colors[$lower])) {
+ return $colors[$lower];
+ }
if (strpos($color, 'rgb(') !== false) {
// rgb literal handling
$length = strlen($color);
- if (strpos($color, ')') !== $length - 1) return false;
+ if (strpos($color, ')') !== $length - 1) {
+ return false;
+ }
$triad = substr($color, 4, $length - 4 - 1);
$parts = explode(',', $triad);
- if (count($parts) !== 3) return false;
+ if (count($parts) !== 3) {
+ return false;
+ }
$type = false; // to ensure that they're all the same type
$new_parts = array();
foreach ($parts as $part) {
$part = trim($part);
- if ($part === '') return false;
+ if ($part === '') {
+ return false;
+ }
$length = strlen($part);
if ($part[$length - 1] === '%') {
// handle percents
@@ -37,9 +55,13 @@ class HTMLPurifier_AttrDef_CSS_Color extends HTMLPurifier_AttrDef
} elseif ($type !== 'percentage') {
return false;
}
- $num = (float) substr($part, 0, $length - 1);
- if ($num < 0) $num = 0;
- if ($num > 100) $num = 100;
+ $num = (float)substr($part, 0, $length - 1);
+ if ($num < 0) {
+ $num = 0;
+ }
+ if ($num > 100) {
+ $num = 100;
+ }
$new_parts[] = "$num%";
} else {
// handle integers
@@ -48,10 +70,14 @@ class HTMLPurifier_AttrDef_CSS_Color extends HTMLPurifier_AttrDef
} elseif ($type !== 'integer') {
return false;
}
- $num = (int) $part;
- if ($num < 0) $num = 0;
- if ($num > 255) $num = 255;
- $new_parts[] = (string) $num;
+ $num = (int)$part;
+ if ($num < 0) {
+ $num = 0;
+ }
+ if ($num > 255) {
+ $num = 255;
+ }
+ $new_parts[] = (string)$num;
}
}
$new_triad = implode(',', $new_parts);
@@ -65,14 +91,15 @@ class HTMLPurifier_AttrDef_CSS_Color extends HTMLPurifier_AttrDef
$color = '#' . $color;
}
$length = strlen($hex);
- if ($length !== 3 && $length !== 6) return false;
- if (!ctype_xdigit($hex)) return false;
+ if ($length !== 3 && $length !== 6) {
+ return false;
+ }
+ if (!ctype_xdigit($hex)) {
+ return false;
+ }
}
-
return $color;
-
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Composite.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Composite.php
index de1289cba8af47101e3ae09e0fc92de2fd061f95..9c1750554f51a9b67ac6bedf4702bf41076bf27f 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Composite.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Composite.php
@@ -13,26 +13,36 @@ class HTMLPurifier_AttrDef_CSS_Composite extends HTMLPurifier_AttrDef
{
/**
- * List of HTMLPurifier_AttrDef objects that may process strings
+ * List of objects that may process strings.
+ * @type HTMLPurifier_AttrDef[]
* @todo Make protected
*/
public $defs;
/**
- * @param $defs List of HTMLPurifier_AttrDef objects
+ * @param HTMLPurifier_AttrDef[] $defs List of HTMLPurifier_AttrDef objects
*/
- public function __construct($defs) {
+ public function __construct($defs)
+ {
$this->defs = $defs;
}
- public function validate($string, $config, $context) {
+ /**
+ * @param string $string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($string, $config, $context)
+ {
foreach ($this->defs as $i => $def) {
$result = $this->defs[$i]->validate($string, $config, $context);
- if ($result !== false) return $result;
+ if ($result !== false) {
+ return $result;
+ }
}
return false;
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/DenyElementDecorator.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/DenyElementDecorator.php
index 6599c5b2ddcee7afbfb9935027b2559e22845e05..9d77cc9aafbf44f8c43969662ca51a5f90d1ed8c 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/DenyElementDecorator.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/DenyElementDecorator.php
@@ -5,22 +5,38 @@
*/
class HTMLPurifier_AttrDef_CSS_DenyElementDecorator extends HTMLPurifier_AttrDef
{
- public $def, $element;
+ /**
+ * @type HTMLPurifier_AttrDef
+ */
+ public $def;
+ /**
+ * @type string
+ */
+ public $element;
/**
- * @param $def Definition to wrap
- * @param $element Element to deny
+ * @param HTMLPurifier_AttrDef $def Definition to wrap
+ * @param string $element Element to deny
*/
- public function __construct($def, $element) {
+ public function __construct($def, $element)
+ {
$this->def = $def;
$this->element = $element;
}
+
/**
* Checks if CurrentToken is set and equal to $this->element
+ * @param string $string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
*/
- public function validate($string, $config, $context) {
+ public function validate($string, $config, $context)
+ {
$token = $context->get('CurrentToken', true);
- if ($token && $token->name == $this->element) return false;
+ if ($token && $token->name == $this->element) {
+ return false;
+ }
return $this->def->validate($string, $config, $context);
}
}
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Filter.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Filter.php
index 147894b8619719ada179523f30371b871292d2b7..bde4c3301f60447899232cfed4ee2f61378d3337 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Filter.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Filter.php
@@ -7,23 +7,37 @@
*/
class HTMLPurifier_AttrDef_CSS_Filter extends HTMLPurifier_AttrDef
{
-
+ /**
+ * @type HTMLPurifier_AttrDef_Integer
+ */
protected $intValidator;
- public function __construct() {
+ public function __construct()
+ {
$this->intValidator = new HTMLPurifier_AttrDef_Integer();
}
- public function validate($value, $config, $context) {
+ /**
+ * @param string $value
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($value, $config, $context)
+ {
$value = $this->parseCDATA($value);
- if ($value === 'none') return $value;
+ if ($value === 'none') {
+ return $value;
+ }
// if we looped this we could support multiple filters
$function_length = strcspn($value, '(');
$function = trim(substr($value, 0, $function_length));
if ($function !== 'alpha' &&
$function !== 'Alpha' &&
$function !== 'progid:DXImageTransform.Microsoft.Alpha'
- ) return false;
+ ) {
+ return false;
+ }
$cursor = $function_length + 1;
$parameters_length = strcspn($value, ')', $cursor);
$parameters = substr($value, $cursor, $parameters_length);
@@ -32,15 +46,25 @@ class HTMLPurifier_AttrDef_CSS_Filter extends HTMLPurifier_AttrDef
$lookup = array();
foreach ($params as $param) {
list($key, $value) = explode('=', $param);
- $key = trim($key);
+ $key = trim($key);
$value = trim($value);
- if (isset($lookup[$key])) continue;
- if ($key !== 'opacity') continue;
+ if (isset($lookup[$key])) {
+ continue;
+ }
+ if ($key !== 'opacity') {
+ continue;
+ }
$value = $this->intValidator->validate($value, $config, $context);
- if ($value === false) continue;
- $int = (int) $value;
- if ($int > 100) $value = '100';
- if ($int < 0) $value = '0';
+ if ($value === false) {
+ continue;
+ }
+ $int = (int)$value;
+ if ($int > 100) {
+ $value = '100';
+ }
+ if ($int < 0) {
+ $value = '0';
+ }
$ret_params[] = "$key=$value";
$lookup[$key] = true;
}
@@ -48,7 +72,6 @@ class HTMLPurifier_AttrDef_CSS_Filter extends HTMLPurifier_AttrDef
$ret_function = "$function($ret_parameters)";
return $ret_function;
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Font.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Font.php
index 699ee0b7012a6d1a5d951d7598ab528247b579b8..579b97ef1ca60344af77774e14beb7dc612384aa 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Font.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Font.php
@@ -7,8 +7,8 @@ class HTMLPurifier_AttrDef_CSS_Font extends HTMLPurifier_AttrDef
{
/**
- * Local copy of component validators.
- *
+ * Local copy of validators
+ * @type HTMLPurifier_AttrDef[]
* @note If we moved specific CSS property definitions to their own
* classes instead of having them be assembled at run time by
* CSSDefinition, this wouldn't be necessary. We'd instantiate
@@ -16,18 +16,28 @@ class HTMLPurifier_AttrDef_CSS_Font extends HTMLPurifier_AttrDef
*/
protected $info = array();
- public function __construct($config) {
+ /**
+ * @param HTMLPurifier_Config $config
+ */
+ public function __construct($config)
+ {
$def = $config->getCSSDefinition();
- $this->info['font-style'] = $def->info['font-style'];
+ $this->info['font-style'] = $def->info['font-style'];
$this->info['font-variant'] = $def->info['font-variant'];
- $this->info['font-weight'] = $def->info['font-weight'];
- $this->info['font-size'] = $def->info['font-size'];
- $this->info['line-height'] = $def->info['line-height'];
- $this->info['font-family'] = $def->info['font-family'];
+ $this->info['font-weight'] = $def->info['font-weight'];
+ $this->info['font-size'] = $def->info['font-size'];
+ $this->info['line-height'] = $def->info['line-height'];
+ $this->info['font-family'] = $def->info['font-family'];
}
- public function validate($string, $config, $context) {
-
+ /**
+ * @param string $string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($string, $config, $context)
+ {
static $system_fonts = array(
'caption' => true,
'icon' => true,
@@ -39,7 +49,9 @@ class HTMLPurifier_AttrDef_CSS_Font extends HTMLPurifier_AttrDef
// regular pre-processing
$string = $this->parseCDATA($string);
- if ($string === '') return false;
+ if ($string === '') {
+ return false;
+ }
// check if it's one of the keywords
$lowercase_string = strtolower($string);
@@ -54,15 +66,20 @@ class HTMLPurifier_AttrDef_CSS_Font extends HTMLPurifier_AttrDef
$final = ''; // output
for ($i = 0, $size = count($bits); $i < $size; $i++) {
- if ($bits[$i] === '') continue;
+ if ($bits[$i] === '') {
+ continue;
+ }
switch ($stage) {
-
- // attempting to catch font-style, font-variant or font-weight
- case 0:
+ case 0: // attempting to catch font-style, font-variant or font-weight
foreach ($stage_1 as $validator_name) {
- if (isset($caught[$validator_name])) continue;
+ if (isset($caught[$validator_name])) {
+ continue;
+ }
$r = $this->info[$validator_name]->validate(
- $bits[$i], $config, $context);
+ $bits[$i],
+ $config,
+ $context
+ );
if ($r !== false) {
$final .= $r . ' ';
$caught[$validator_name] = true;
@@ -70,15 +87,17 @@ class HTMLPurifier_AttrDef_CSS_Font extends HTMLPurifier_AttrDef
}
}
// all three caught, continue on
- if (count($caught) >= 3) $stage = 1;
- if ($r !== false) break;
-
- // attempting to catch font-size and perhaps line-height
- case 1:
+ if (count($caught) >= 3) {
+ $stage = 1;
+ }
+ if ($r !== false) {
+ break;
+ }
+ case 1: // attempting to catch font-size and perhaps line-height
$found_slash = false;
if (strpos($bits[$i], '/') !== false) {
list($font_size, $line_height) =
- explode('/', $bits[$i]);
+ explode('/', $bits[$i]);
if ($line_height === '') {
// ooh, there's a space after the slash!
$line_height = false;
@@ -89,14 +108,19 @@ class HTMLPurifier_AttrDef_CSS_Font extends HTMLPurifier_AttrDef
$line_height = false;
}
$r = $this->info['font-size']->validate(
- $font_size, $config, $context);
+ $font_size,
+ $config,
+ $context
+ );
if ($r !== false) {
$final .= $r;
// attempt to catch line-height
if ($line_height === false) {
// we need to scroll forward
for ($j = $i + 1; $j < $size; $j++) {
- if ($bits[$j] === '') continue;
+ if ($bits[$j] === '') {
+ continue;
+ }
if ($bits[$j] === '/') {
if ($found_slash) {
return false;
@@ -116,7 +140,10 @@ class HTMLPurifier_AttrDef_CSS_Font extends HTMLPurifier_AttrDef
if ($found_slash) {
$i = $j;
$r = $this->info['line-height']->validate(
- $line_height, $config, $context);
+ $line_height,
+ $config,
+ $context
+ );
if ($r !== false) {
$final .= '/' . $r;
}
@@ -126,13 +153,14 @@ class HTMLPurifier_AttrDef_CSS_Font extends HTMLPurifier_AttrDef
break;
}
return false;
-
- // attempting to catch font-family
- case 2:
+ case 2: // attempting to catch font-family
$font_family =
implode(' ', array_slice($bits, $i, $size - $i));
$r = $this->info['font-family']->validate(
- $font_family, $config, $context);
+ $font_family,
+ $config,
+ $context
+ );
if ($r !== false) {
$final .= $r . ' ';
// processing completed successfully
@@ -143,7 +171,6 @@ class HTMLPurifier_AttrDef_CSS_Font extends HTMLPurifier_AttrDef
}
return false;
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/FontFamily.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/FontFamily.php
index 0d9a4e12c24deea636e1af5a403cfb054eceb692..74e24c8816ec91404b5cf9a29b1330057f18768c 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/FontFamily.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/FontFamily.php
@@ -8,11 +8,18 @@ class HTMLPurifier_AttrDef_CSS_FontFamily extends HTMLPurifier_AttrDef
protected $mask = null;
- public function __construct() {
- $this->mask = '- ';
- for ($c = 'a'; $c <= 'z'; $c++) $this->mask .= $c;
- for ($c = 'A'; $c <= 'Z'; $c++) $this->mask .= $c;
- for ($c = '0'; $c <= '9'; $c++) $this->mask .= $c; // cast-y, but should be fine
+ public function __construct()
+ {
+ $this->mask = '_- ';
+ for ($c = 'a'; $c <= 'z'; $c++) {
+ $this->mask .= $c;
+ }
+ for ($c = 'A'; $c <= 'Z'; $c++) {
+ $this->mask .= $c;
+ }
+ for ($c = '0'; $c <= '9'; $c++) {
+ $this->mask .= $c;
+ } // cast-y, but should be fine
// special bytes used by UTF-8
for ($i = 0x80; $i <= 0xFF; $i++) {
// We don't bother excluding invalid bytes in this range,
@@ -39,7 +46,14 @@ class HTMLPurifier_AttrDef_CSS_FontFamily extends HTMLPurifier_AttrDef
// possible optimization: invert the mask.
}
- public function validate($string, $config, $context) {
+ /**
+ * @param string $string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($string, $config, $context)
+ {
static $generic_names = array(
'serif' => true,
'sans-serif' => true,
@@ -52,9 +66,11 @@ class HTMLPurifier_AttrDef_CSS_FontFamily extends HTMLPurifier_AttrDef
// assume that no font names contain commas in them
$fonts = explode(',', $string);
$final = '';
- foreach($fonts as $font) {
+ foreach ($fonts as $font) {
$font = trim($font);
- if ($font === '') continue;
+ if ($font === '') {
+ continue;
+ }
// match a generic name
if (isset($generic_names[$font])) {
if ($allowed_fonts === null || isset($allowed_fonts[$font])) {
@@ -65,9 +81,13 @@ class HTMLPurifier_AttrDef_CSS_FontFamily extends HTMLPurifier_AttrDef
// match a quoted name
if ($font[0] === '"' || $font[0] === "'") {
$length = strlen($font);
- if ($length <= 2) continue;
+ if ($length <= 2) {
+ continue;
+ }
$quote = $font[0];
- if ($font[$length - 1] !== $quote) continue;
+ if ($font[$length - 1] !== $quote) {
+ continue;
+ }
$font = substr($font, 1, $length - 2);
}
@@ -165,7 +185,7 @@ class HTMLPurifier_AttrDef_CSS_FontFamily extends HTMLPurifier_AttrDef
// extensive research, we may feel comfortable with dropping
// it down to edgy.
- // Edgy: alphanumeric, spaces, dashes and Unicode. Use of
+ // Edgy: alphanumeric, spaces, dashes, underscores and Unicode. Use of
// str(c)spn assumes that the string was already well formed
// Unicode (which of course it is).
if (strspn($font, $this->mask) !== strlen($font)) {
@@ -188,7 +208,9 @@ class HTMLPurifier_AttrDef_CSS_FontFamily extends HTMLPurifier_AttrDef
$final .= "'$font', ";
}
$final = rtrim($final, ', ');
- if ($final === '') return false;
+ if ($final === '') {
+ return false;
+ }
return $final;
}
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Ident.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Ident.php
index 779794a0b3d2735c844d391680c61d1a68f84885..973002c17f064c42cdfaa47dcd12f9cf27edc0f2 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Ident.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Ident.php
@@ -6,19 +6,27 @@
class HTMLPurifier_AttrDef_CSS_Ident extends HTMLPurifier_AttrDef
{
- public function validate($string, $config, $context) {
-
+ /**
+ * @param string $string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($string, $config, $context)
+ {
$string = trim($string);
// early abort: '' and '0' (strings that convert to false) are invalid
- if (!$string) return false;
+ if (!$string) {
+ return false;
+ }
$pattern = '/^(-?[A-Za-z_][A-Za-z_\-0-9]*)$/';
- if (!preg_match($pattern, $string)) return false;
+ if (!preg_match($pattern, $string)) {
+ return false;
+ }
return $string;
-
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/ImportantDecorator.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/ImportantDecorator.php
index 4e6b35e5a0dffd031b35963945e71d6dee00ca41..ffc989fe807b6ba6af4fcb031b18bcb21f9c8f0a 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/ImportantDecorator.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/ImportantDecorator.php
@@ -5,20 +5,34 @@
*/
class HTMLPurifier_AttrDef_CSS_ImportantDecorator extends HTMLPurifier_AttrDef
{
- public $def, $allow;
+ /**
+ * @type HTMLPurifier_AttrDef
+ */
+ public $def;
+ /**
+ * @type bool
+ */
+ public $allow;
/**
- * @param $def Definition to wrap
- * @param $allow Whether or not to allow !important
+ * @param HTMLPurifier_AttrDef $def Definition to wrap
+ * @param bool $allow Whether or not to allow !important
*/
- public function __construct($def, $allow = false) {
+ public function __construct($def, $allow = false)
+ {
$this->def = $def;
$this->allow = $allow;
}
+
/**
* Intercepts and removes !important if necessary
+ * @param string $string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
*/
- public function validate($string, $config, $context) {
+ public function validate($string, $config, $context)
+ {
// test for ! and important tokens
$string = trim($string);
$is_important = false;
@@ -32,7 +46,9 @@ class HTMLPurifier_AttrDef_CSS_ImportantDecorator extends HTMLPurifier_AttrDef
}
}
$string = $this->def->validate($string, $config, $context);
- if ($this->allow && $is_important) $string .= ' !important';
+ if ($this->allow && $is_important) {
+ $string .= ' !important';
+ }
return $string;
}
}
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Length.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Length.php
index a07ec58135c05525b6a66489574ef2463993d161..f12453a04a74b21e44d7954fe504a96dba85ba7e 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Length.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Length.php
@@ -6,42 +6,72 @@
class HTMLPurifier_AttrDef_CSS_Length extends HTMLPurifier_AttrDef
{
- protected $min, $max;
+ /**
+ * @type HTMLPurifier_Length|string
+ */
+ protected $min;
/**
- * @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.
+ * @type HTMLPurifier_Length|string
*/
- public function __construct($min = null, $max = null) {
+ protected $max;
+
+ /**
+ * @param HTMLPurifier_Length|string $min Minimum length, or null for no bound. String is also acceptable.
+ * @param HTMLPurifier_Length|string $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) {
+ /**
+ * @param string $string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ 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;
+ 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 (!$length->isValid()) {
+ return false;
+ }
if ($this->min) {
$c = $length->compareTo($this->min);
- if ($c === false) return false;
- if ($c < 0) return false;
+ 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;
+ if ($c === false) {
+ return false;
+ }
+ if ($c > 0) {
+ return false;
+ }
}
-
return $length->toString();
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/ListStyle.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/ListStyle.php
index 4406868c08b0b2d1e497ac4c1cd9694ca996a6b5..e74d42654e292e7f988ba1531590347feaa9dd28 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/ListStyle.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/ListStyle.php
@@ -8,46 +8,72 @@ class HTMLPurifier_AttrDef_CSS_ListStyle extends HTMLPurifier_AttrDef
{
/**
- * Local copy of component validators.
+ * Local copy of validators.
+ * @type HTMLPurifier_AttrDef[]
* @note See HTMLPurifier_AttrDef_CSS_Font::$info for a similar impl.
*/
protected $info;
- public function __construct($config) {
+ /**
+ * @param HTMLPurifier_Config $config
+ */
+ public function __construct($config)
+ {
$def = $config->getCSSDefinition();
- $this->info['list-style-type'] = $def->info['list-style-type'];
+ $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) {
-
+ /**
+ * @param string $string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($string, $config, $context)
+ {
// regular pre-processing
$string = $this->parseCDATA($string);
- if ($string === '') return false;
+ 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['type'] = false;
$caught['position'] = false;
- $caught['image'] = false;
+ $caught['image'] = false;
$i = 0; // number of catches
$none = false;
foreach ($bits as $bit) {
- if ($i >= 3) return; // optimization bit
- if ($bit === '') continue;
+ if ($i >= 3) {
+ return;
+ } // optimization bit
+ if ($bit === '') {
+ continue;
+ }
foreach ($caught as $key => $status) {
- if ($status !== false) continue;
+ if ($status !== false) {
+ continue;
+ }
$r = $this->info['list-style-' . $key]->validate($bit, $config, $context);
- if ($r === false) continue;
+ if ($r === false) {
+ continue;
+ }
if ($r === 'none') {
- if ($none) continue;
- else $none = true;
- if ($key == 'image') continue;
+ if ($none) {
+ continue;
+ } else {
+ $none = true;
+ }
+ if ($key == 'image') {
+ continue;
+ }
}
$caught[$key] = $r;
$i++;
@@ -55,24 +81,32 @@ class HTMLPurifier_AttrDef_CSS_ListStyle extends HTMLPurifier_AttrDef
}
}
- if (!$i) return false;
+ if (!$i) {
+ return false;
+ }
$ret = array();
// construct type
- if ($caught['type']) $ret[] = $caught['type'];
+ if ($caught['type']) {
+ $ret[] = $caught['type'];
+ }
// construct image
- if ($caught['image']) $ret[] = $caught['image'];
+ if ($caught['image']) {
+ $ret[] = $caught['image'];
+ }
// construct position
- if ($caught['position']) $ret[] = $caught['position'];
+ if ($caught['position']) {
+ $ret[] = $caught['position'];
+ }
- if (empty($ret)) return false;
+ if (empty($ret)) {
+ return false;
+ }
return implode(' ', $ret);
-
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Multiple.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Multiple.php
index 4d62a40d7fc6a6abb3a834e3f80139deb39a8ada..9f266cdd153859abbfaccfc5daf9a9133062e5bc 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Multiple.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Multiple.php
@@ -13,9 +13,9 @@
*/
class HTMLPurifier_AttrDef_CSS_Multiple extends HTMLPurifier_AttrDef
{
-
/**
* Instance of component definition to defer validation to.
+ * @type HTMLPurifier_AttrDef
* @todo Make protected
*/
public $single;
@@ -27,32 +27,45 @@ class HTMLPurifier_AttrDef_CSS_Multiple extends HTMLPurifier_AttrDef
public $max;
/**
- * @param $single HTMLPurifier_AttrDef to multiply
- * @param $max Max number of values allowed (usually four)
+ * @param HTMLPurifier_AttrDef $single HTMLPurifier_AttrDef to multiply
+ * @param int $max Max number of values allowed (usually four)
*/
- public function __construct($single, $max = 4) {
+ public function __construct($single, $max = 4)
+ {
$this->single = $single;
$this->max = $max;
}
- public function validate($string, $config, $context) {
+ /**
+ * @param string $string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($string, $config, $context)
+ {
$string = $this->parseCDATA($string);
- if ($string === '') return false;
+ if ($string === '') {
+ return false;
+ }
$parts = explode(' ', $string); // parseCDATA replaced \r, \t and \n
$length = count($parts);
$final = '';
for ($i = 0, $num = 0; $i < $length && $num < $this->max; $i++) {
- if (ctype_space($parts[$i])) continue;
+ if (ctype_space($parts[$i])) {
+ continue;
+ }
$result = $this->single->validate($parts[$i], $config, $context);
if ($result !== false) {
$final .= $result . ' ';
$num++;
}
}
- if ($final === '') return false;
+ if ($final === '') {
+ return false;
+ }
return rtrim($final);
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Number.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Number.php
index 3f99e12ec26f8a35cb79b942a74a20021c1b0007..8edc159e7240df3d9f36521cbfff32d1b5c719e7 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Number.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Number.php
@@ -7,32 +7,44 @@ class HTMLPurifier_AttrDef_CSS_Number extends HTMLPurifier_AttrDef
{
/**
- * Bool indicating whether or not only positive values allowed.
+ * Indicates whether or not only positive values are allowed.
+ * @type bool
*/
protected $non_negative = false;
/**
- * @param $non_negative Bool indicating whether negatives are forbidden
+ * @param bool $non_negative indicates whether negatives are forbidden
*/
- public function __construct($non_negative = false) {
+ public function __construct($non_negative = false)
+ {
$this->non_negative = $non_negative;
}
/**
+ * @param string $number
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return string|bool
* @warning Some contexts do not pass $config, $context. These
* variables should not be used without checking HTMLPurifier_Length
*/
- public function validate($number, $config, $context) {
-
+ public function validate($number, $config, $context)
+ {
$number = $this->parseCDATA($number);
- if ($number === '') return false;
- if ($number === '0') return '0';
+ if ($number === '') {
+ return false;
+ }
+ if ($number === '0') {
+ return '0';
+ }
$sign = '';
switch ($number[0]) {
case '-':
- if ($this->non_negative) return false;
+ if ($this->non_negative) {
+ return false;
+ }
$sign = '-';
case '+':
$number = substr($number, 1);
@@ -44,14 +56,20 @@ class HTMLPurifier_AttrDef_CSS_Number extends HTMLPurifier_AttrDef
}
// Period is the only non-numeric character allowed
- if (strpos($number, '.') === false) return false;
+ if (strpos($number, '.') === false) {
+ return false;
+ }
list($left, $right) = explode('.', $number, 2);
- if ($left === '' && $right === '') return false;
- if ($left !== '' && !ctype_digit($left)) return false;
+ if ($left === '' && $right === '') {
+ return false;
+ }
+ if ($left !== '' && !ctype_digit($left)) {
+ return false;
+ }
- $left = ltrim($left, '0');
+ $left = ltrim($left, '0');
$right = rtrim($right, '0');
if ($right === '') {
@@ -59,11 +77,8 @@ class HTMLPurifier_AttrDef_CSS_Number extends HTMLPurifier_AttrDef
} elseif (!ctype_digit($right)) {
return false;
}
-
return $sign . $left . '.' . $right;
-
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Percentage.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Percentage.php
index c34b8fc3c392b90fa09652d6af38742937948c41..f0f25c50a87a33ba54b79222433d024ebd97f600 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Percentage.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/Percentage.php
@@ -7,34 +7,48 @@ class HTMLPurifier_AttrDef_CSS_Percentage extends HTMLPurifier_AttrDef
{
/**
- * Instance of HTMLPurifier_AttrDef_CSS_Number to defer number validation
+ * Instance to defer number validation to.
+ * @type HTMLPurifier_AttrDef_CSS_Number
*/
protected $number_def;
/**
- * @param Bool indicating whether to forbid negative values
+ * @param bool $non_negative Whether to forbid negative values
*/
- public function __construct($non_negative = false) {
+ public function __construct($non_negative = false)
+ {
$this->number_def = new HTMLPurifier_AttrDef_CSS_Number($non_negative);
}
- public function validate($string, $config, $context) {
-
+ /**
+ * @param string $string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($string, $config, $context)
+ {
$string = $this->parseCDATA($string);
- if ($string === '') return false;
+ if ($string === '') {
+ return false;
+ }
$length = strlen($string);
- if ($length === 1) return false;
- if ($string[$length - 1] !== '%') return false;
+ 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;
+ if ($number === false) {
+ return false;
+ }
return "$number%";
-
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/TextDecoration.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/TextDecoration.php
index 772c922d80bde9e3ca6f24db8ebef6b20132adf5..5fd4b7f7b41d15ea747bef25007c4fb7bf2d827e 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/TextDecoration.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/TextDecoration.php
@@ -8,8 +8,14 @@
class HTMLPurifier_AttrDef_CSS_TextDecoration extends HTMLPurifier_AttrDef
{
- public function validate($string, $config, $context) {
-
+ /**
+ * @param string $string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($string, $config, $context)
+ {
static $allowed_values = array(
'line-through' => true,
'overline' => true,
@@ -18,7 +24,9 @@ class HTMLPurifier_AttrDef_CSS_TextDecoration extends HTMLPurifier_AttrDef
$string = strtolower($this->parseCDATA($string));
- if ($string === 'none') return $string;
+ if ($string === 'none') {
+ return $string;
+ }
$parts = explode(' ', $string);
$final = '';
@@ -28,11 +36,11 @@ class HTMLPurifier_AttrDef_CSS_TextDecoration extends HTMLPurifier_AttrDef
}
}
$final = rtrim($final);
- if ($final === '') return false;
+ if ($final === '') {
+ return false;
+ }
return $final;
-
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/URI.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/URI.php
index c2f767e573cf20374e048501e967de6b4774b7a7..f9434230e21a3de557a9edb2af4a752a0ab659dc 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/URI.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/CSS/URI.php
@@ -12,25 +12,39 @@
class HTMLPurifier_AttrDef_CSS_URI extends HTMLPurifier_AttrDef_URI
{
- public function __construct() {
+ public function __construct()
+ {
parent::__construct(true); // always embedded
}
- public function validate($uri_string, $config, $context) {
+ /**
+ * @param string $uri_string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($uri_string, $config, $context)
+ {
// parse the URI out of the string and then pass it onto
// the parent object
$uri_string = $this->parseCDATA($uri_string);
- if (strpos($uri_string, 'url(') !== 0) return false;
+ if (strpos($uri_string, 'url(') !== 0) {
+ return false;
+ }
$uri_string = substr($uri_string, 4);
$new_length = strlen($uri_string) - 1;
- if ($uri_string[$new_length] != ')') return false;
+ if ($uri_string[$new_length] != ')') {
+ return false;
+ }
$uri = trim(substr($uri_string, 0, $new_length));
if (!empty($uri) && ($uri[0] == "'" || $uri[0] == '"')) {
$quote = $uri[0];
$new_length = strlen($uri) - 1;
- if ($uri[$new_length] !== $quote) return false;
+ if ($uri[$new_length] !== $quote) {
+ return false;
+ }
$uri = substr($uri, 1, $new_length - 1);
}
@@ -38,7 +52,9 @@ class HTMLPurifier_AttrDef_CSS_URI extends HTMLPurifier_AttrDef_URI
$result = parent::validate($uri, $config, $context);
- if ($result === false) return false;
+ if ($result === false) {
+ return false;
+ }
// extra sanity check; should have been done by URI
$result = str_replace(array('"', "\\", "\n", "\x0c", "\r"), "", $result);
@@ -51,11 +67,8 @@ class HTMLPurifier_AttrDef_CSS_URI extends HTMLPurifier_AttrDef_URI
// an innerHTML cycle, so a very unlucky query parameter could
// then change the meaning of the URL. Unfortunately, there's
// not much we can do about that...
-
return "url(\"$result\")";
-
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/Clone.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/Clone.php
index ce68dbd546916a04a61ba6450fb988556d93468e..6698a00c019b5028b64a8d13f346ec988b521605 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/Clone.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/Clone.php
@@ -7,22 +7,38 @@
class HTMLPurifier_AttrDef_Clone extends HTMLPurifier_AttrDef
{
/**
- * What we're cloning
+ * What we're cloning.
+ * @type HTMLPurifier_AttrDef
*/
protected $clone;
- public function __construct($clone) {
+ /**
+ * @param HTMLPurifier_AttrDef $clone
+ */
+ public function __construct($clone)
+ {
$this->clone = $clone;
}
- public function validate($v, $config, $context) {
+ /**
+ * @param string $v
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($v, $config, $context)
+ {
return $this->clone->validate($v, $config, $context);
}
- public function make($string) {
+ /**
+ * @param string $string
+ * @return HTMLPurifier_AttrDef
+ */
+ public function make($string)
+ {
return clone $this->clone;
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/Enum.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/Enum.php
index 5d603ebcc67d51ddad1eb47010d702b157f7fa85..8abda7f6e2a55e12c25b14507e3966c05096ebe5 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/Enum.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/Enum.php
@@ -12,9 +12,10 @@ class HTMLPurifier_AttrDef_Enum extends HTMLPurifier_AttrDef
/**
* Lookup table of valid values.
+ * @type array
* @todo Make protected
*/
- public $valid_values = array();
+ public $valid_values = array();
/**
* Bool indicating whether or not enumeration is case sensitive.
@@ -23,17 +24,23 @@ class HTMLPurifier_AttrDef_Enum extends HTMLPurifier_AttrDef
protected $case_sensitive = false; // values according to W3C spec
/**
- * @param $valid_values List of valid values
- * @param $case_sensitive Bool indicating whether or not case sensitive
+ * @param array $valid_values List of valid values
+ * @param bool $case_sensitive Whether or not case sensitive
*/
- public function __construct(
- $valid_values = array(), $case_sensitive = false
- ) {
+ public function __construct($valid_values = array(), $case_sensitive = false)
+ {
$this->valid_values = array_flip($valid_values);
$this->case_sensitive = $case_sensitive;
}
- public function validate($string, $config, $context) {
+ /**
+ * @param string $string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($string, $config, $context)
+ {
$string = trim($string);
if (!$this->case_sensitive) {
// we may want to do full case-insensitive libraries
@@ -45,11 +52,13 @@ class HTMLPurifier_AttrDef_Enum extends HTMLPurifier_AttrDef
}
/**
- * @param $string In form of comma-delimited list of case-insensitive
+ * @param string $string In form of comma-delimited list of case-insensitive
* valid values. Example: "foo,bar,baz". Prepend "s:" to make
* case sensitive
+ * @return HTMLPurifier_AttrDef_Enum
*/
- public function make($string) {
+ public function make($string)
+ {
if (strlen($string) > 2 && $string[0] == 's' && $string[1] == ':') {
$string = substr($string, 2);
$sensitive = true;
@@ -59,7 +68,6 @@ class HTMLPurifier_AttrDef_Enum extends HTMLPurifier_AttrDef
$values = explode(',', $string);
return new HTMLPurifier_AttrDef_Enum($values, $sensitive);
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/Bool.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/Bool.php
index e06987eb8dbaf10b64b024495ed992fd83e96b35..036a240e14b16842518ff07c7722366061c025a2 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/Bool.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/Bool.php
@@ -6,23 +6,46 @@
class HTMLPurifier_AttrDef_HTML_Bool extends HTMLPurifier_AttrDef
{
+ /**
+ * @type bool
+ */
protected $name;
+
+ /**
+ * @type bool
+ */
public $minimized = true;
- public function __construct($name = false) {$this->name = $name;}
+ /**
+ * @param bool $name
+ */
+ public function __construct($name = false)
+ {
+ $this->name = $name;
+ }
- public function validate($string, $config, $context) {
- if (empty($string)) return false;
+ /**
+ * @param string $string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($string, $config, $context)
+ {
+ if (empty($string)) {
+ return false;
+ }
return $this->name;
}
/**
- * @param $string Name of attribute
+ * @param string $string Name of attribute
+ * @return HTMLPurifier_AttrDef_HTML_Bool
*/
- public function make($string) {
+ public function make($string)
+ {
return new HTMLPurifier_AttrDef_HTML_Bool($string);
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/Class.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/Class.php
index 370068d9757755a7396ac165220a094002b9569e..d5013488fc5e72cdc34002594deb36512b8ac59e 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/Class.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/Class.php
@@ -5,7 +5,14 @@
*/
class HTMLPurifier_AttrDef_HTML_Class extends HTMLPurifier_AttrDef_HTML_Nmtokens
{
- protected function split($string, $config, $context) {
+ /**
+ * @param string $string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ protected function split($string, $config, $context)
+ {
// really, this twiddle should be lazy loaded
$name = $config->getDefinition('HTML')->doctype->name;
if ($name == "XHTML 1.1" || $name == "XHTML 2.0") {
@@ -14,13 +21,20 @@ class HTMLPurifier_AttrDef_HTML_Class extends HTMLPurifier_AttrDef_HTML_Nmtokens
return preg_split('/\s+/', $string);
}
}
- protected function filter($tokens, $config, $context) {
+
+ /**
+ * @param array $tokens
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return array
+ */
+ protected function filter($tokens, $config, $context)
+ {
$allowed = $config->get('Attr.AllowedClasses');
$forbidden = $config->get('Attr.ForbiddenClasses');
$ret = array();
foreach ($tokens as $token) {
- if (
- ($allowed === null || isset($allowed[$token])) &&
+ if (($allowed === null || isset($allowed[$token])) &&
!isset($forbidden[$token]) &&
// We need this O(n) check because of PHP's array
// implementation that casts -0 to 0.
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/Color.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/Color.php
index 00d865723b39905ba41008a4d22a7c1ac0a31d0c..946ebb7820140f8c01bb28edad9e629d420c5dac 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/Color.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/Color.php
@@ -6,27 +6,46 @@
class HTMLPurifier_AttrDef_HTML_Color extends HTMLPurifier_AttrDef
{
- public function validate($string, $config, $context) {
-
+ /**
+ * @param string $string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($string, $config, $context)
+ {
static $colors = null;
- if ($colors === null) $colors = $config->get('Core.ColorKeywords');
+ if ($colors === null) {
+ $colors = $config->get('Core.ColorKeywords');
+ }
$string = trim($string);
- if (empty($string)) return false;
- if (isset($colors[strtolower($string)])) return $colors[$string];
- if ($string[0] === '#') $hex = substr($string, 1);
- else $hex = $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];
-
+ 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
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/FrameTarget.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/FrameTarget.php
index ae6ea7c01d55c257c4d93acbc2c5468baaaaa01f..d79ba12b3f8e6672cffbbcea012b43ec1c96e090 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/FrameTarget.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/FrameTarget.php
@@ -6,16 +6,33 @@
class HTMLPurifier_AttrDef_HTML_FrameTarget extends HTMLPurifier_AttrDef_Enum
{
+ /**
+ * @type array
+ */
public $valid_values = false; // uninitialized value
+
+ /**
+ * @type bool
+ */
protected $case_sensitive = false;
- public function __construct() {}
+ public function __construct()
+ {
+ }
- public function validate($string, $config, $context) {
- if ($this->valid_values === false) $this->valid_values = $config->get('Attr.AllowedFrameTargets');
+ /**
+ * @param string $string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ 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
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/ID.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/ID.php
index 0015fa1ebb641ced02f23ac154cda994a5e5d557..3d86efb44c33808da7caaae3fff5a9cfff08ab33 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/ID.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/ID.php
@@ -18,34 +18,56 @@ class HTMLPurifier_AttrDef_HTML_ID extends HTMLPurifier_AttrDef
/**
* Determines whether or not we're validating an ID in a CSS
* selector context.
+ * @type bool
*/
protected $selector;
- public function __construct($selector = false) {
+ /**
+ * @param bool $selector
+ */
+ public function __construct($selector = false)
+ {
$this->selector = $selector;
}
- public function validate($id, $config, $context) {
-
- if (!$this->selector && !$config->get('Attr.EnableID')) return false;
+ /**
+ * @param string $id
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($id, $config, $context)
+ {
+ if (!$this->selector && !$config->get('Attr.EnableID')) {
+ return false;
+ }
$id = trim($id); // trim it first
- if ($id === '') return false;
+ if ($id === '') {
+ return false;
+ }
$prefix = $config->get('Attr.IDPrefix');
if ($prefix !== '') {
$prefix .= $config->get('Attr.IDPrefixLocal');
// prevent re-appending the prefix
- if (strpos($id, $prefix) !== 0) $id = $prefix . $id;
+ if (strpos($id, $prefix) !== 0) {
+ $id = $prefix . $id;
+ }
} elseif ($config->get('Attr.IDPrefixLocal') !== '') {
- trigger_error('%Attr.IDPrefixLocal cannot be used unless '.
- '%Attr.IDPrefix is set', E_USER_WARNING);
+ trigger_error(
+ '%Attr.IDPrefixLocal cannot be used unless ' .
+ '%Attr.IDPrefix is set',
+ E_USER_WARNING
+ );
}
if (!$this->selector) {
$id_accumulator =& $context->get('IDAccumulator');
- if (isset($id_accumulator->ids[$id])) return false;
+ if (isset($id_accumulator->ids[$id])) {
+ return false;
+ }
}
// we purposely avoid using regex, hopefully this is faster
@@ -53,11 +75,14 @@ class HTMLPurifier_AttrDef_HTML_ID extends HTMLPurifier_AttrDef
if (ctype_alpha($id)) {
$result = true;
} else {
- if (!ctype_alpha(@$id[0])) return false;
- $trim = trim( // primitive style of regexps, I suppose
+ if (!ctype_alpha(@$id[0])) {
+ return false;
+ }
+ // primitive style of regexps, I suppose
+ $trim = trim(
$id,
'A..Za..z0..9:-._'
- );
+ );
$result = ($trim === '');
}
@@ -66,15 +91,15 @@ class HTMLPurifier_AttrDef_HTML_ID extends HTMLPurifier_AttrDef
return false;
}
- if (!$this->selector && $result) $id_accumulator->add($id);
+ if (!$this->selector && $result) {
+ $id_accumulator->add($id);
+ }
// if no change was made to the ID, return the result
// else, return the new id if stripping whitespace made it
// valid, or return false.
return $result ? $id : false;
-
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/Length.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/Length.php
index a242f9c238ea2108e059598eac16f8b6e5bf6eb0..1c4006fbbdac3616f4150f09a3ee78cc092e30ff 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/Length.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/Length.php
@@ -10,32 +10,47 @@
class HTMLPurifier_AttrDef_HTML_Length extends HTMLPurifier_AttrDef_HTML_Pixels
{
- public function validate($string, $config, $context) {
-
+ /**
+ * @param string $string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($string, $config, $context)
+ {
$string = trim($string);
- if ($string === '') return false;
+ if ($string === '') {
+ return false;
+ }
$parent_result = parent::validate($string, $config, $context);
- if ($parent_result !== false) return $parent_result;
+ if ($parent_result !== false) {
+ return $parent_result;
+ }
$length = strlen($string);
$last_char = $string[$length - 1];
- if ($last_char !== '%') return false;
+ if ($last_char !== '%') {
+ return false;
+ }
$points = substr($string, 0, $length - 1);
- if (!is_numeric($points)) return false;
-
- $points = (int) $points;
+ if (!is_numeric($points)) {
+ return false;
+ }
- if ($points < 0) return '0%';
- if ($points > 100) return '100%';
-
- return ((string) $points) . '%';
+ $points = (int)$points;
+ if ($points < 0) {
+ return '0%';
+ }
+ if ($points > 100) {
+ return '100%';
+ }
+ return ((string)$points) . '%';
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/LinkTypes.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/LinkTypes.php
index 76d25ed088ace93cf386867f74491e5b3cf73477..63fa04c15c0040fb6df332d067c2a38a8b1342b1 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/LinkTypes.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/LinkTypes.php
@@ -9,26 +9,44 @@
class HTMLPurifier_AttrDef_HTML_LinkTypes extends HTMLPurifier_AttrDef
{
- /** Name config attribute to pull. */
+ /**
+ * Name config attribute to pull.
+ * @type string
+ */
protected $name;
- public function __construct($name) {
+ /**
+ * @param string $name
+ */
+ public function __construct($name)
+ {
$configLookup = array(
'rel' => 'AllowedRel',
'rev' => 'AllowedRev'
);
if (!isset($configLookup[$name])) {
- trigger_error('Unrecognized attribute name for link '.
- 'relationship.', E_USER_ERROR);
+ trigger_error(
+ 'Unrecognized attribute name for link ' .
+ 'relationship.',
+ E_USER_ERROR
+ );
return;
}
$this->name = $configLookup[$name];
}
- public function validate($string, $config, $context) {
-
+ /**
+ * @param string $string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($string, $config, $context)
+ {
$allowed = $config->get('Attr.' . $this->name);
- if (empty($allowed)) return false;
+ if (empty($allowed)) {
+ return false;
+ }
$string = $this->parseCDATA($string);
$parts = explode(' ', $string);
@@ -37,17 +55,18 @@ class HTMLPurifier_AttrDef_HTML_LinkTypes extends HTMLPurifier_AttrDef
$ret_lookup = array();
foreach ($parts as $part) {
$part = strtolower(trim($part));
- if (!isset($allowed[$part])) continue;
+ if (!isset($allowed[$part])) {
+ continue;
+ }
$ret_lookup[$part] = true;
}
- if (empty($ret_lookup)) return false;
+ if (empty($ret_lookup)) {
+ return false;
+ }
$string = implode(' ', array_keys($ret_lookup));
-
return $string;
-
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/MultiLength.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/MultiLength.php
index c72fc76e4d99fab93084d1912753c9d07b64b239..bbb20f2f8021a353c4b99ca937728bdb8a9c1ebb 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/MultiLength.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/MultiLength.php
@@ -9,33 +9,52 @@
class HTMLPurifier_AttrDef_HTML_MultiLength extends HTMLPurifier_AttrDef_HTML_Length
{
- public function validate($string, $config, $context) {
-
+ /**
+ * @param string $string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($string, $config, $context)
+ {
$string = trim($string);
- if ($string === '') return false;
+ if ($string === '') {
+ return false;
+ }
$parent_result = parent::validate($string, $config, $context);
- if ($parent_result !== false) return $parent_result;
+ if ($parent_result !== false) {
+ return $parent_result;
+ }
$length = strlen($string);
$last_char = $string[$length - 1];
- if ($last_char !== '*') return false;
+ 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) . '*';
-
+ 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
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/Nmtokens.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/Nmtokens.php
index aa34120bd289543d1b7adbd4f42f8b2ab51f973e..f79683b4fc3660d74390b52973a7cc882aa7b630 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/Nmtokens.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/Nmtokens.php
@@ -6,24 +6,38 @@
class HTMLPurifier_AttrDef_HTML_Nmtokens extends HTMLPurifier_AttrDef
{
- public function validate($string, $config, $context) {
-
+ /**
+ * @param string $string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($string, $config, $context)
+ {
$string = trim($string);
// early abort: '' and '0' (strings that convert to false) are invalid
- if (!$string) return false;
+ if (!$string) {
+ return false;
+ }
$tokens = $this->split($string, $config, $context);
$tokens = $this->filter($tokens, $config, $context);
- if (empty($tokens)) return false;
+ if (empty($tokens)) {
+ return false;
+ }
return implode(' ', $tokens);
-
}
/**
* Splits a space separated list of tokens into its constituent parts.
+ * @param string $string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return array
*/
- protected function split($string, $config, $context) {
+ protected function split($string, $config, $context)
+ {
// OPTIMIZABLE!
// do the preg_match, capture all subpatterns for reformulation
@@ -31,9 +45,9 @@ class HTMLPurifier_AttrDef_HTML_Nmtokens extends HTMLPurifier_AttrDef
// escaping because I don't know how to do that with regexps
// and plus it would complicate optimization efforts (you never
// see that anyway).
- $pattern = '/(?:(?<=\s)|\A)'. // look behind for space or string start
- '((?:--|-?[A-Za-z_])[A-Za-z_\-0-9]*)'.
- '(?:(?=\s)|\z)/'; // look ahead for space or string end
+ $pattern = '/(?:(?<=\s)|\A)' . // look behind for space or string start
+ '((?:--|-?[A-Za-z_])[A-Za-z_\-0-9]*)' .
+ '(?:(?=\s)|\z)/'; // look ahead for space or string end
preg_match_all($pattern, $string, $matches);
return $matches[1];
}
@@ -42,11 +56,15 @@ class HTMLPurifier_AttrDef_HTML_Nmtokens extends HTMLPurifier_AttrDef
* Template method for removing certain tokens based on arbitrary criteria.
* @note If we wanted to be really functional, we'd do an array_filter
* with a callback. But... we're not.
+ * @param array $tokens
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return array
*/
- protected function filter($tokens, $config, $context) {
+ protected function filter($tokens, $config, $context)
+ {
return $tokens;
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/Pixels.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/Pixels.php
index 4cb2c1b8579b51cd22ccd140e6f6880fc2627faf..a1d019e095b62ad3186a847f60f716a9eb10f868 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/Pixels.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/HTML/Pixels.php
@@ -6,43 +6,71 @@
class HTMLPurifier_AttrDef_HTML_Pixels extends HTMLPurifier_AttrDef
{
+ /**
+ * @type int
+ */
protected $max;
- public function __construct($max = null) {
+ /**
+ * @param int $max
+ */
+ public function __construct($max = null)
+ {
$this->max = $max;
}
- public function validate($string, $config, $context) {
-
+ /**
+ * @param string $string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($string, $config, $context)
+ {
$string = trim($string);
- if ($string === '0') return $string;
- if ($string === '') return false;
+ 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 (!is_numeric($string)) {
+ return false;
+ }
+ $int = (int)$string;
- if ($int < 0) return '0';
+ if ($int < 0) {
+ return '0';
+ }
// upper-bound value, extremely high values can
// crash operating systems, see
// 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;
-
+ 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;
+ /**
+ * @param string $string
+ * @return HTMLPurifier_AttrDef
+ */
+ 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
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/Integer.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/Integer.php
index d59738d2a2b772d876cc0529e52b14a2ac680198..400e707d2f5b4449aa49cf957919b0581fd0c6e1 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/Integer.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/Integer.php
@@ -11,17 +11,20 @@ class HTMLPurifier_AttrDef_Integer extends HTMLPurifier_AttrDef
{
/**
- * Bool indicating whether or not negative values are allowed
+ * Whether or not negative values are allowed.
+ * @type bool
*/
protected $negative = true;
/**
- * Bool indicating whether or not zero is allowed
+ * Whether or not zero is allowed.
+ * @type bool
*/
protected $zero = true;
/**
- * Bool indicating whether or not positive values are allowed
+ * Whether or not positive values are allowed.
+ * @type bool
*/
protected $positive = true;
@@ -30,44 +33,59 @@ class HTMLPurifier_AttrDef_Integer extends HTMLPurifier_AttrDef
* @param $zero Bool indicating whether or not zero is allowed
* @param $positive Bool indicating whether or not positive values are allowed
*/
- public function __construct(
- $negative = true, $zero = true, $positive = true
- ) {
+ public function __construct($negative = true, $zero = true, $positive = true)
+ {
$this->negative = $negative;
- $this->zero = $zero;
+ $this->zero = $zero;
$this->positive = $positive;
}
- public function validate($integer, $config, $context) {
-
+ /**
+ * @param string $integer
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($integer, $config, $context)
+ {
$integer = $this->parseCDATA($integer);
- if ($integer === '') return false;
+ if ($integer === '') {
+ return false;
+ }
// we could possibly simply typecast it to integer, but there are
// certain fringe cases that must not return an integer.
// clip leading sign
- if ( $this->negative && $integer[0] === '-' ) {
+ if ($this->negative && $integer[0] === '-') {
$digits = substr($integer, 1);
- if ($digits === '0') $integer = '0'; // rm minus sign for zero
- } elseif( $this->positive && $integer[0] === '+' ) {
+ if ($digits === '0') {
+ $integer = '0';
+ } // rm minus sign for zero
+ } elseif ($this->positive && $integer[0] === '+') {
$digits = $integer = substr($integer, 1); // rm unnecessary plus
} else {
$digits = $integer;
}
// test if it's numeric
- if (!ctype_digit($digits)) return false;
+ if (!ctype_digit($digits)) {
+ return false;
+ }
// perform scope tests
- if (!$this->zero && $integer == 0) return false;
- if (!$this->positive && $integer > 0) return false;
- if (!$this->negative && $integer < 0) return false;
+ if (!$this->zero && $integer == 0) {
+ return false;
+ }
+ if (!$this->positive && $integer > 0) {
+ return false;
+ }
+ if (!$this->negative && $integer < 0) {
+ return false;
+ }
return $integer;
-
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/Lang.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/Lang.php
index 10e6da56db190fdf4c2e28b0da8aa36d3172e04e..2a55cea642e8ad58e58be034af9e041c458ee6b2 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/Lang.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/Lang.php
@@ -7,15 +7,25 @@
class HTMLPurifier_AttrDef_Lang extends HTMLPurifier_AttrDef
{
- public function validate($string, $config, $context) {
-
+ /**
+ * @param string $string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($string, $config, $context)
+ {
$string = trim($string);
- if (!$string) return false;
+ if (!$string) {
+ return false;
+ }
$subtags = explode('-', $string);
$num_subtags = count($subtags);
- if ($num_subtags == 0) return false; // sanity check
+ if ($num_subtags == 0) { // sanity check
+ return false;
+ }
// process primary subtag : $subtags[0]
$length = strlen($subtags[0]);
@@ -23,15 +33,15 @@ class HTMLPurifier_AttrDef_Lang extends HTMLPurifier_AttrDef
case 0:
return false;
case 1:
- if (! ($subtags[0] == 'x' || $subtags[0] == 'i') ) {
+ if (!($subtags[0] == 'x' || $subtags[0] == 'i')) {
return false;
}
break;
case 2:
case 3:
- if (! ctype_alpha($subtags[0]) ) {
+ if (!ctype_alpha($subtags[0])) {
return false;
- } elseif (! ctype_lower($subtags[0]) ) {
+ } elseif (!ctype_lower($subtags[0])) {
$subtags[0] = strtolower($subtags[0]);
}
break;
@@ -40,17 +50,23 @@ class HTMLPurifier_AttrDef_Lang extends HTMLPurifier_AttrDef
}
$new_string = $subtags[0];
- if ($num_subtags == 1) return $new_string;
+ if ($num_subtags == 1) {
+ return $new_string;
+ }
// process second subtag : $subtags[1]
$length = strlen($subtags[1]);
if ($length == 0 || ($length == 1 && $subtags[1] != 'x') || $length > 8 || !ctype_alnum($subtags[1])) {
return $new_string;
}
- if (!ctype_lower($subtags[1])) $subtags[1] = strtolower($subtags[1]);
+ if (!ctype_lower($subtags[1])) {
+ $subtags[1] = strtolower($subtags[1]);
+ }
$new_string .= '-' . $subtags[1];
- if ($num_subtags == 2) return $new_string;
+ if ($num_subtags == 2) {
+ return $new_string;
+ }
// process all other subtags, index 2 and up
for ($i = 2; $i < $num_subtags; $i++) {
@@ -63,11 +79,8 @@ class HTMLPurifier_AttrDef_Lang extends HTMLPurifier_AttrDef
}
$new_string .= '-' . $subtags[$i];
}
-
return $new_string;
-
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/Switch.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/Switch.php
index c9e3ed193e77d0cbeac150d02105b81173eb37c0..c7eb3199a4a2c1c51220d1b440b62940b50f7ebe 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/Switch.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/Switch.php
@@ -6,21 +6,41 @@
class HTMLPurifier_AttrDef_Switch
{
+ /**
+ * @type string
+ */
protected $tag;
- protected $withTag, $withoutTag;
+
+ /**
+ * @type HTMLPurifier_AttrDef
+ */
+ protected $withTag;
+
+ /**
+ * @type HTMLPurifier_AttrDef
+ */
+ protected $withoutTag;
/**
* @param string $tag Tag name to switch upon
* @param HTMLPurifier_AttrDef $with_tag Call if token matches tag
* @param HTMLPurifier_AttrDef $without_tag Call if token doesn't match, or there is no token
*/
- public function __construct($tag, $with_tag, $without_tag) {
+ public function __construct($tag, $with_tag, $without_tag)
+ {
$this->tag = $tag;
$this->withTag = $with_tag;
$this->withoutTag = $without_tag;
}
- public function validate($string, $config, $context) {
+ /**
+ * @param string $string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($string, $config, $context)
+ {
$token = $context->get('CurrentToken', true);
if (!$token || $token->name !== $this->tag) {
return $this->withoutTag->validate($string, $config, $context);
@@ -28,7 +48,6 @@ class HTMLPurifier_AttrDef_Switch
return $this->withTag->validate($string, $config, $context);
}
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/Text.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/Text.php
index c6216cc531d4b351799ea7b9764d88f578c9c26a..4553a4ea9b6ce9f4e238c088bb5c7853c332cd6a 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/Text.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/Text.php
@@ -6,10 +6,16 @@
class HTMLPurifier_AttrDef_Text extends HTMLPurifier_AttrDef
{
- public function validate($string, $config, $context) {
+ /**
+ * @param string $string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($string, $config, $context)
+ {
return $this->parseCDATA($string);
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/URI.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/URI.php
index c2b6846712ba38a9abe3efc2e3aae0ab852e5877..c1cd89772c2604880f6e88132c71a1f7859ff5b6 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/URI.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/URI.php
@@ -7,31 +7,54 @@
class HTMLPurifier_AttrDef_URI extends HTMLPurifier_AttrDef
{
+ /**
+ * @type HTMLPurifier_URIParser
+ */
protected $parser;
+
+ /**
+ * @type bool
+ */
protected $embedsResource;
/**
- * @param $embeds_resource_resource Does the URI here result in an extra HTTP request?
+ * @param bool $embeds_resource Does the URI here result in an extra HTTP request?
*/
- public function __construct($embeds_resource = false) {
+ public function __construct($embeds_resource = false)
+ {
$this->parser = new HTMLPurifier_URIParser();
- $this->embedsResource = (bool) $embeds_resource;
+ $this->embedsResource = (bool)$embeds_resource;
}
- public function make($string) {
+ /**
+ * @param string $string
+ * @return HTMLPurifier_AttrDef_URI
+ */
+ public function make($string)
+ {
$embeds = ($string === 'embedded');
return new HTMLPurifier_AttrDef_URI($embeds);
}
- public function validate($uri, $config, $context) {
-
- if ($config->get('URI.Disable')) return false;
+ /**
+ * @param string $uri
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($uri, $config, $context)
+ {
+ if ($config->get('URI.Disable')) {
+ return false;
+ }
$uri = $this->parseCDATA($uri);
// parse the URI
$uri = $this->parser->parse($uri);
- if ($uri === false) return false;
+ if ($uri === false) {
+ return false;
+ }
// add embedded flag to context for validators
$context->register('EmbeddedURI', $this->embedsResource);
@@ -41,23 +64,35 @@ class HTMLPurifier_AttrDef_URI extends HTMLPurifier_AttrDef
// generic validation
$result = $uri->validate($config, $context);
- if (!$result) break;
+ if (!$result) {
+ break;
+ }
// chained filtering
$uri_def = $config->getDefinition('URI');
$result = $uri_def->filter($uri, $config, $context);
- if (!$result) break;
+ if (!$result) {
+ break;
+ }
// scheme-specific validation
$scheme_obj = $uri->getSchemeObj($config, $context);
- if (!$scheme_obj) break;
- if ($this->embedsResource && !$scheme_obj->browsable) break;
+ if (!$scheme_obj) {
+ break;
+ }
+ if ($this->embedsResource && !$scheme_obj->browsable) {
+ break;
+ }
$result = $scheme_obj->validate($uri, $config, $context);
- if (!$result) break;
+ if (!$result) {
+ break;
+ }
// Post chained filtering
$result = $uri_def->postFilter($uri, $config, $context);
- if (!$result) break;
+ if (!$result) {
+ break;
+ }
// survived gauntlet
$ok = true;
@@ -65,13 +100,12 @@ class HTMLPurifier_AttrDef_URI extends HTMLPurifier_AttrDef
} while (false);
$context->destroy('EmbeddedURI');
- if (!$ok) return false;
-
+ if (!$ok) {
+ return false;
+ }
// back to string
return $uri->toString();
-
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/URI/Email.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/URI/Email.php
index bfee9d166c82ee6c0df47636afa4ea0948e8ba09..daf32b7643b7c02fd0c1950d0db45a560e3c415a 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/URI/Email.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/URI/Email.php
@@ -5,8 +5,11 @@ abstract class HTMLPurifier_AttrDef_URI_Email extends HTMLPurifier_AttrDef
/**
* Unpacks a mailbox into its display-name and address
+ * @param string $string
+ * @return mixed
*/
- function unpack($string) {
+ public function unpack($string)
+ {
// needs to be implemented
}
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/URI/Email/SimpleCheck.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/URI/Email/SimpleCheck.php
index 94c715ab43258b923f89f300a853438ccce2da49..52c0d5968308209fd33743c01ca9ddfb12c77a68 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/URI/Email/SimpleCheck.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/URI/Email/SimpleCheck.php
@@ -7,15 +7,23 @@
class HTMLPurifier_AttrDef_URI_Email_SimpleCheck extends HTMLPurifier_AttrDef_URI_Email
{
- public function validate($string, $config, $context) {
+ /**
+ * @param string $string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($string, $config, $context)
+ {
// no support for named mailboxes i.e. "Bob "
// that needs more percent encoding to be done
- if ($string == '') return false;
+ if ($string == '') {
+ return false;
+ }
$string = trim($string);
$result = preg_match('/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i', $string);
return $result ? $string : false;
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/URI/Host.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/URI/Host.php
index 125decb2df4b1a25b2b068339225e85a58618e7c..e7df800b1eb8e78cc8241678d201e398b693c837 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/URI/Host.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/URI/Host.php
@@ -7,21 +7,31 @@ class HTMLPurifier_AttrDef_URI_Host extends HTMLPurifier_AttrDef
{
/**
- * Instance of HTMLPurifier_AttrDef_URI_IPv4 sub-validator
+ * IPv4 sub-validator.
+ * @type HTMLPurifier_AttrDef_URI_IPv4
*/
protected $ipv4;
/**
- * Instance of HTMLPurifier_AttrDef_URI_IPv6 sub-validator
+ * IPv6 sub-validator.
+ * @type HTMLPurifier_AttrDef_URI_IPv6
*/
protected $ipv6;
- public function __construct() {
+ public function __construct()
+ {
$this->ipv4 = new HTMLPurifier_AttrDef_URI_IPv4();
$this->ipv6 = new HTMLPurifier_AttrDef_URI_IPv6();
}
- public function validate($string, $config, $context) {
+ /**
+ * @param string $string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($string, $config, $context)
+ {
$length = strlen($string);
// empty hostname is OK; it's usually semantically equivalent:
// the default host as defined by a URI scheme is used:
@@ -29,32 +39,51 @@ class HTMLPurifier_AttrDef_URI_Host extends HTMLPurifier_AttrDef
// If the URI scheme defines a default for host, then that
// default applies when the host subcomponent is undefined
// or when the registered name is empty (zero length).
- if ($string === '') return '';
- if ($length > 1 && $string[0] === '[' && $string[$length-1] === ']') {
+ if ($string === '') {
+ return '';
+ }
+ if ($length > 1 && $string[0] === '[' && $string[$length - 1] === ']') {
//IPv6
$ip = substr($string, 1, $length - 2);
$valid = $this->ipv6->validate($ip, $config, $context);
- if ($valid === false) return false;
- return '['. $valid . ']';
+ if ($valid === false) {
+ return false;
+ }
+ return '[' . $valid . ']';
}
// need to do checks on unusual encodings too
$ipv4 = $this->ipv4->validate($string, $config, $context);
- if ($ipv4 !== false) return $ipv4;
+ if ($ipv4 !== false) {
+ return $ipv4;
+ }
// A regular domain name.
// This doesn't match I18N domain names, but we don't have proper IRI support,
// so force users to insert Punycode.
+ // There is not a good sense in which underscores should be
+ // allowed, since it's technically not! (And if you go as
+ // far to allow everything as specified by the DNS spec...
+ // well, that's literally everything, modulo some space limits
+ // for the components and the overall name (which, by the way,
+ // we are NOT checking!). So we (arbitrarily) decide this:
+ // let's allow underscores wherever we would have allowed
+ // hyphens, if they are enabled. This is a pretty good match
+ // for browser behavior, for example, a large number of browsers
+ // cannot handle foo_.example.com, but foo_bar.example.com is
+ // fairly well supported.
+ $underscore = $config->get('Core.AllowHostnameUnderscore') ? '_' : '';
+
// The productions describing this are:
$a = '[a-z]'; // alpha
$an = '[a-z0-9]'; // alphanum
- $and = '[a-z0-9-]'; // alphanum | "-"
+ $and = "[a-z0-9-$underscore]"; // alphanum | "-"
// domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum
- $domainlabel = "$an($and*$an)?";
+ $domainlabel = "$an($and*$an)?";
// toplabel = alpha | alpha *( alphanum | "-" ) alphanum
- $toplabel = "$a($and*$an)?";
+ $toplabel = "$a($and*$an)?";
// hostname = *( domainlabel "." ) toplabel [ "." ]
if (preg_match("/^($domainlabel\.)*$toplabel\.?$/i", $string)) {
return $string;
@@ -92,10 +121,8 @@ class HTMLPurifier_AttrDef_URI_Host extends HTMLPurifier_AttrDef
// XXX error reporting
}
}
-
return false;
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/URI/IPv4.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/URI/IPv4.php
index ec4cf591b82b7d4bcd054d8556707a83a410568e..30ac16c9e73bd952ed5e65a0951fca9ee9d72aa9 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/URI/IPv4.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/URI/IPv4.php
@@ -8,32 +8,38 @@ class HTMLPurifier_AttrDef_URI_IPv4 extends HTMLPurifier_AttrDef
{
/**
- * IPv4 regex, protected so that IPv6 can reuse it
+ * IPv4 regex, protected so that IPv6 can reuse it.
+ * @type string
*/
protected $ip4;
- public function validate($aIP, $config, $context) {
-
- if (!$this->ip4) $this->_loadRegex();
-
- if (preg_match('#^' . $this->ip4 . '$#s', $aIP))
- {
- return $aIP;
+ /**
+ * @param string $aIP
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ public function validate($aIP, $config, $context)
+ {
+ if (!$this->ip4) {
+ $this->_loadRegex();
}
+ if (preg_match('#^' . $this->ip4 . '$#s', $aIP)) {
+ return $aIP;
+ }
return false;
-
}
/**
* Lazy load function to prevent regex from being stuffed in
* cache.
*/
- protected function _loadRegex() {
+ protected function _loadRegex()
+ {
$oct = '(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])'; // 0-255
$this->ip4 = "(?:{$oct}\\.{$oct}\\.{$oct}\\.{$oct})";
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/URI/IPv6.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/URI/IPv6.php
index 9454e9be50eb96970d1eed77a61fd4976ff60911..f243793eeb888f63ec5b1995198867ec3d2f801d 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/URI/IPv6.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrDef/URI/IPv6.php
@@ -9,91 +9,81 @@
class HTMLPurifier_AttrDef_URI_IPv6 extends HTMLPurifier_AttrDef_URI_IPv4
{
- public function validate($aIP, $config, $context) {
-
- if (!$this->ip4) $this->_loadRegex();
+ /**
+ * @param string $aIP
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+ 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
+ $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;
- }
+ 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);
+ 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)
- {
+ 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;
- }
- 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');
- }
+ 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]);
+ 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;
+ 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;
- }
+ 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
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform.php
index e61d3e01b6d55f3f83b42d2e3d82a21f83492c52..b428331f154b85bfa19c41a0aa178183bba81cb6 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform.php
@@ -20,37 +20,41 @@ abstract class HTMLPurifier_AttrTransform
/**
* Abstract: makes changes to the attributes dependent on multiple values.
*
- * @param $attr Assoc array of attributes, usually from
+ * @param array $attr Assoc array of attributes, usually from
* HTMLPurifier_Token_Tag::$attr
- * @param $config Mandatory HTMLPurifier_Config object.
- * @param $context Mandatory HTMLPurifier_Context object
- * @returns Processed attribute array.
+ * @param HTMLPurifier_Config $config Mandatory HTMLPurifier_Config object.
+ * @param HTMLPurifier_Context $context Mandatory HTMLPurifier_Context object
+ * @return array Processed attribute array.
*/
abstract public function transform($attr, $config, $context);
/**
* Prepends CSS properties to the style attribute, creating the
* attribute if it doesn't exist.
- * @param $attr Attribute array to process (passed by reference)
- * @param $css CSS to prepend
+ * @param array &$attr Attribute array to process (passed by reference)
+ * @param string $css CSS to prepend
*/
- public function prependCSS(&$attr, $css) {
+ public function prependCSS(&$attr, $css)
+ {
$attr['style'] = isset($attr['style']) ? $attr['style'] : '';
$attr['style'] = $css . $attr['style'];
}
/**
* Retrieves and removes an attribute
- * @param $attr Attribute array to process (passed by reference)
- * @param $key Key of attribute to confiscate
+ * @param array &$attr Attribute array to process (passed by reference)
+ * @param mixed $key Key of attribute to confiscate
+ * @return mixed
*/
- public function confiscateAttr(&$attr, $key) {
- if (!isset($attr[$key])) return null;
+ public function confiscateAttr(&$attr, $key)
+ {
+ if (!isset($attr[$key])) {
+ return null;
+ }
$value = $attr[$key];
unset($attr[$key]);
return $value;
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Background.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Background.php
index 0e1ff24a3ed8ed6758118ba293f40d5783150f1c..2f72869a5e38d8fe8401e7f358aab57e080bdc7f 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Background.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Background.php
@@ -3,21 +3,26 @@
/**
* Pre-transform that changes proprietary background attribute to CSS.
*/
-class HTMLPurifier_AttrTransform_Background extends HTMLPurifier_AttrTransform {
-
- public function transform($attr, $config, $context) {
-
- if (!isset($attr['background'])) return $attr;
+class HTMLPurifier_AttrTransform_Background extends HTMLPurifier_AttrTransform
+{
+ /**
+ * @param array $attr
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return array
+ */
+ public function transform($attr, $config, $context)
+ {
+ if (!isset($attr['background'])) {
+ return $attr;
+ }
$background = $this->confiscateAttr($attr, 'background');
// some validation should happen here
$this->prependCSS($attr, "background-image:url($background);");
-
return $attr;
-
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/BdoDir.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/BdoDir.php
index 4d1a05665e46e35e8be54465d61afcada111cedb..d66c04a5b8950ba96d6a60e4af9678956cae032d 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/BdoDir.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/BdoDir.php
@@ -8,12 +8,20 @@
class HTMLPurifier_AttrTransform_BdoDir extends HTMLPurifier_AttrTransform
{
- public function transform($attr, $config, $context) {
- if (isset($attr['dir'])) return $attr;
+ /**
+ * @param array $attr
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return array
+ */
+ public function transform($attr, $config, $context)
+ {
+ if (isset($attr['dir'])) {
+ return $attr;
+ }
$attr['dir'] = $config->get('Attr.DefaultTextDir');
return $attr;
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/BgColor.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/BgColor.php
index ad3916bb9676a482104027657545a8a8e616c177..0f51fd2cecdfee65a702e8bef855b01fe948aa73 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/BgColor.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/BgColor.php
@@ -3,21 +3,26 @@
/**
* Pre-transform that changes deprecated bgcolor attribute to CSS.
*/
-class HTMLPurifier_AttrTransform_BgColor extends HTMLPurifier_AttrTransform {
-
- public function transform($attr, $config, $context) {
-
- if (!isset($attr['bgcolor'])) return $attr;
+class HTMLPurifier_AttrTransform_BgColor extends HTMLPurifier_AttrTransform
+{
+ /**
+ * @param array $attr
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return array
+ */
+ public function transform($attr, $config, $context)
+ {
+ if (!isset($attr['bgcolor'])) {
+ return $attr;
+ }
$bgcolor = $this->confiscateAttr($attr, 'bgcolor');
// some validation should happen here
$this->prependCSS($attr, "background-color:$bgcolor;");
-
return $attr;
-
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/BoolToCSS.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/BoolToCSS.php
index 51159b67157de07846eb9f0b9af3486817ab5d69..f25cd01955f85a5d3851016f8a35d569a7bb3459 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/BoolToCSS.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/BoolToCSS.php
@@ -3,34 +3,45 @@
/**
* Pre-transform that changes converts a boolean attribute to fixed CSS
*/
-class HTMLPurifier_AttrTransform_BoolToCSS extends HTMLPurifier_AttrTransform {
-
+class HTMLPurifier_AttrTransform_BoolToCSS extends HTMLPurifier_AttrTransform
+{
/**
- * Name of boolean attribute that is trigger
+ * Name of boolean attribute that is trigger.
+ * @type string
*/
protected $attr;
/**
- * CSS declarations to add to style, needs trailing semicolon
+ * CSS declarations to add to style, needs trailing semicolon.
+ * @type string
*/
protected $css;
/**
- * @param $attr string attribute name to convert from
- * @param $css string CSS declarations to add to style (needs semicolon)
+ * @param string $attr attribute name to convert from
+ * @param string $css CSS declarations to add to style (needs semicolon)
*/
- public function __construct($attr, $css) {
+ public function __construct($attr, $css)
+ {
$this->attr = $attr;
- $this->css = $css;
+ $this->css = $css;
}
- public function transform($attr, $config, $context) {
- if (!isset($attr[$this->attr])) return $attr;
+ /**
+ * @param array $attr
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return array
+ */
+ 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
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Border.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Border.php
index 476b0b079b11074ce4e26f5ba163ed9849b7a161..057dc017fade0b665c37cbfd0b2d30318490713c 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Border.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Border.php
@@ -3,16 +3,24 @@
/**
* Pre-transform that changes deprecated border attribute to CSS.
*/
-class HTMLPurifier_AttrTransform_Border extends HTMLPurifier_AttrTransform {
-
- public function transform($attr, $config, $context) {
- if (!isset($attr['border'])) return $attr;
+class HTMLPurifier_AttrTransform_Border extends HTMLPurifier_AttrTransform
+{
+ /**
+ * @param array $attr
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return array
+ */
+ public function transform($attr, $config, $context)
+ {
+ if (!isset($attr['border'])) {
+ return $attr;
+ }
$border_width = $this->confiscateAttr($attr, 'border');
// some validation should happen here
$this->prependCSS($attr, "border:{$border_width}px solid;");
return $attr;
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/EnumToCSS.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/EnumToCSS.php
index 2a5b4514ab430df6d01a7e1b0bcbb3e26ac9baa5..7ccd0e3fb7cf5b99458371df76ac78d0d77ef4b0 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/EnumToCSS.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/EnumToCSS.php
@@ -4,55 +4,65 @@
* Generic pre-transform that converts an attribute with a fixed number of
* values (enumerated) to CSS.
*/
-class HTMLPurifier_AttrTransform_EnumToCSS extends HTMLPurifier_AttrTransform {
-
+class HTMLPurifier_AttrTransform_EnumToCSS extends HTMLPurifier_AttrTransform
+{
/**
- * Name of attribute to transform from
+ * Name of attribute to transform from.
+ * @type string
*/
protected $attr;
/**
- * Lookup array of attribute values to CSS
+ * Lookup array of attribute values to CSS.
+ * @type array
*/
protected $enumToCSS = array();
/**
- * Case sensitivity of the matching
+ * Case sensitivity of the matching.
+ * @type bool
* @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
+ * @param string $attr Attribute name to transform from
+ * @param array $enum_to_css Lookup array of attribute values to CSS
+ * @param bool $case_sensitive Case sensitivity indicator, default false
*/
- public function __construct($attr, $enum_to_css, $case_sensitive = false) {
+ public function __construct($attr, $enum_to_css, $case_sensitive = false)
+ {
$this->attr = $attr;
$this->enumToCSS = $enum_to_css;
- $this->caseSensitive = (bool) $case_sensitive;
+ $this->caseSensitive = (bool)$case_sensitive;
}
- public function transform($attr, $config, $context) {
-
- if (!isset($attr[$this->attr])) return $attr;
+ /**
+ * @param array $attr
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return array
+ */
+ 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 (!$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
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/ImgRequired.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/ImgRequired.php
index 7f0e4b7a59fbf5babd4203be3b195477d3790635..7df6cb3e1b4dc678ff736d7fac4dbf107fdac92e 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/ImgRequired.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/ImgRequired.php
@@ -11,11 +11,19 @@
class HTMLPurifier_AttrTransform_ImgRequired extends HTMLPurifier_AttrTransform
{
- public function transform($attr, $config, $context) {
-
+ /**
+ * @param array $attr
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return array
+ */
+ public function transform($attr, $config, $context)
+ {
$src = true;
if (!isset($attr['src'])) {
- if ($config->get('Core.RemoveInvalidImg')) return $attr;
+ if ($config->get('Core.RemoveInvalidImg')) {
+ return $attr;
+ }
$attr['src'] = $config->get('Attr.DefaultInvalidImage');
$src = false;
}
@@ -25,7 +33,7 @@ class HTMLPurifier_AttrTransform_ImgRequired extends HTMLPurifier_AttrTransform
$alt = $config->get('Attr.DefaultImageAlt');
if ($alt === null) {
// truncate if the alt is too long
- $attr['alt'] = substr(basename($attr['src']),0,40);
+ $attr['alt'] = substr(basename($attr['src']), 0, 40);
} else {
$attr['alt'] = $alt;
}
@@ -33,11 +41,8 @@ class HTMLPurifier_AttrTransform_ImgRequired extends HTMLPurifier_AttrTransform
$attr['alt'] = $config->get('Attr.DefaultInvalidImageAlt');
}
}
-
return $attr;
-
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/ImgSpace.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/ImgSpace.php
index fd84c10c3618fb4642282ae307cf731e9e042490..350b3358fcb673f96ac59353d6b2582615954310 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/ImgSpace.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/ImgSpace.php
@@ -3,42 +3,59 @@
/**
* Pre-transform that changes deprecated hspace and vspace attributes to CSS
*/
-class HTMLPurifier_AttrTransform_ImgSpace extends HTMLPurifier_AttrTransform {
-
+class HTMLPurifier_AttrTransform_ImgSpace extends HTMLPurifier_AttrTransform
+{
+ /**
+ * @type string
+ */
protected $attr;
+
+ /**
+ * @type array
+ */
protected $css = array(
'hspace' => array('left', 'right'),
'vspace' => array('top', 'bottom')
);
- public function __construct($attr) {
+ /**
+ * @param string $attr
+ */
+ public function __construct($attr)
+ {
$this->attr = $attr;
if (!isset($this->css[$attr])) {
trigger_error(htmlspecialchars($attr) . ' is not valid space attribute');
}
}
- public function transform($attr, $config, $context) {
-
- if (!isset($attr[$this->attr])) return $attr;
+ /**
+ * @param array $attr
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return array
+ */
+ public function transform($attr, $config, $context)
+ {
+ if (!isset($attr[$this->attr])) {
+ return $attr;
+ }
$width = $this->confiscateAttr($attr, $this->attr);
// some validation could happen here
- if (!isset($this->css[$this->attr])) return $attr;
+ if (!isset($this->css[$this->attr])) {
+ return $attr;
+ }
$style = '';
foreach ($this->css[$this->attr] as $suffix) {
$property = "margin-$suffix";
$style .= "$property:{$width}px;";
}
-
$this->prependCSS($attr, $style);
-
return $attr;
-
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Input.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Input.php
index 16829552d14d2a82502661ad530186a8c9e21cc9..3ab47ed8c985161e4f965c81d149d99e6fff5dd4 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Input.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Input.php
@@ -4,17 +4,31 @@
* Performs miscellaneous cross attribute validation and filtering for
* input elements. This is meant to be a post-transform.
*/
-class HTMLPurifier_AttrTransform_Input extends HTMLPurifier_AttrTransform {
-
+class HTMLPurifier_AttrTransform_Input extends HTMLPurifier_AttrTransform
+{
+ /**
+ * @type HTMLPurifier_AttrDef_HTML_Pixels
+ */
protected $pixels;
- public function __construct() {
+ public function __construct()
+ {
$this->pixels = new HTMLPurifier_AttrDef_HTML_Pixels();
}
- public function transform($attr, $config, $context) {
- if (!isset($attr['type'])) $t = 'text';
- else $t = strtolower($attr['type']);
+ /**
+ * @param array $attr
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return array
+ */
+ public function transform($attr, $config, $context)
+ {
+ if (!isset($attr['type'])) {
+ $t = 'text';
+ } else {
+ $t = strtolower($attr['type']);
+ }
if (isset($attr['checked']) && $t !== 'radio' && $t !== 'checkbox') {
unset($attr['checked']);
}
@@ -23,8 +37,11 @@ class HTMLPurifier_AttrTransform_Input extends HTMLPurifier_AttrTransform {
}
if (isset($attr['size']) && $t !== 'text' && $t !== 'password') {
$result = $this->pixels->validate($attr['size'], $config, $context);
- if ($result === false) unset($attr['size']);
- else $attr['size'] = $result;
+ if ($result === false) {
+ unset($attr['size']);
+ } else {
+ $attr['size'] = $result;
+ }
}
if (isset($attr['src']) && $t !== 'image') {
unset($attr['src']);
@@ -34,7 +51,6 @@ class HTMLPurifier_AttrTransform_Input extends HTMLPurifier_AttrTransform {
}
return $attr;
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Lang.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Lang.php
index 5869e7f82037c5a38b9ea55789735181e4980160..5b0aff0e4095d0e3fb0b237183ff68cbcd41d7f0 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Lang.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Lang.php
@@ -8,9 +8,15 @@
class HTMLPurifier_AttrTransform_Lang extends HTMLPurifier_AttrTransform
{
- public function transform($attr, $config, $context) {
-
- $lang = isset($attr['lang']) ? $attr['lang'] : false;
+ /**
+ * @param array $attr
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return array
+ */
+ public function transform($attr, $config, $context)
+ {
+ $lang = isset($attr['lang']) ? $attr['lang'] : false;
$xml_lang = isset($attr['xml:lang']) ? $attr['xml:lang'] : false;
if ($lang !== false && $xml_lang === false) {
@@ -18,11 +24,8 @@ class HTMLPurifier_AttrTransform_Lang extends HTMLPurifier_AttrTransform
} elseif ($xml_lang !== false) {
$attr['lang'] = $xml_lang;
}
-
return $attr;
-
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Length.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Length.php
index ea2f30473d6d14a7e77cff3a16f0fcd80712e3b5..853f33549bc042cde6736d925a34aceb7a619ad1 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Length.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Length.php
@@ -6,22 +6,40 @@
class HTMLPurifier_AttrTransform_Length extends HTMLPurifier_AttrTransform
{
+ /**
+ * @type string
+ */
protected $name;
+
+ /**
+ * @type string
+ */
protected $cssName;
- public function __construct($name, $css_name = null) {
+ 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;
+ /**
+ * @param array $attr
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return array
+ */
+ 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';
+ if (ctype_digit($length)) {
+ $length .= 'px';
+ }
$this->prependCSS($attr, $this->cssName . ":$length;");
return $attr;
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Name.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Name.php
index 15315bc7353a4ef8801a53671654b2a3dde1d4b1..63cce6837a54b7f3849d5104bdeb25195ae4c3b6 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Name.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Name.php
@@ -6,16 +6,28 @@
class HTMLPurifier_AttrTransform_Name extends HTMLPurifier_AttrTransform
{
- public function transform($attr, $config, $context) {
+ /**
+ * @param array $attr
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return array
+ */
+ 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;
+ 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;
+ if (isset($attr['id'])) {
+ return $attr;
+ }
$attr['id'] = $id;
return $attr;
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/NameSync.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/NameSync.php
index a95638c140e724774ce5217576d33f097dd92787..36079b786ffe381d92384200622b02f546b0cc70 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/NameSync.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/NameSync.php
@@ -8,20 +8,34 @@
class HTMLPurifier_AttrTransform_NameSync extends HTMLPurifier_AttrTransform
{
- public function __construct() {
+ public function __construct()
+ {
$this->idDef = new HTMLPurifier_AttrDef_HTML_ID();
}
- public function transform($attr, $config, $context) {
- if (!isset($attr['name'])) return $attr;
+ /**
+ * @param array $attr
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return array
+ */
+ public function transform($attr, $config, $context)
+ {
+ if (!isset($attr['name'])) {
+ return $attr;
+ }
$name = $attr['name'];
- if (isset($attr['id']) && $attr['id'] === $name) return $attr;
+ 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;
+ if ($result === false) {
+ unset($attr['name']);
+ } else {
+ $attr['name'] = $result;
+ }
return $attr;
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Nofollow.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Nofollow.php
index f7fb1209b3be74ddbd3e03f7bcec85a35abe0646..1057ebee1b142f8bc5aadcc5e33d5dc81c0be6a5 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Nofollow.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Nofollow.php
@@ -8,14 +8,24 @@
*/
class HTMLPurifier_AttrTransform_Nofollow extends HTMLPurifier_AttrTransform
{
+ /**
+ * @type HTMLPurifier_URIParser
+ */
private $parser;
- public function __construct() {
+ public function __construct()
+ {
$this->parser = new HTMLPurifier_URIParser();
}
- public function transform($attr, $config, $context) {
-
+ /**
+ * @param array $attr
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return array
+ */
+ public function transform($attr, $config, $context)
+ {
if (!isset($attr['href'])) {
return $attr;
}
@@ -26,7 +36,7 @@ class HTMLPurifier_AttrTransform_Nofollow extends HTMLPurifier_AttrTransform
if ($scheme->browsable && !$url->isLocal($config, $context)) {
if (isset($attr['rel'])) {
- $rels = explode(' ', $attr);
+ $rels = explode(' ', $attr['rel']);
if (!in_array('nofollow', $rels)) {
$rels[] = 'nofollow';
}
@@ -35,11 +45,8 @@ class HTMLPurifier_AttrTransform_Nofollow extends HTMLPurifier_AttrTransform
$attr['rel'] = 'nofollow';
}
}
-
return $attr;
-
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/SafeEmbed.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/SafeEmbed.php
index 4da449981fbd4b8f23992e317309ee46baaa347c..231c81a3f0adf878f77b24e7efe6437a990259aa 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/SafeEmbed.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/SafeEmbed.php
@@ -2,9 +2,19 @@
class HTMLPurifier_AttrTransform_SafeEmbed extends HTMLPurifier_AttrTransform
{
+ /**
+ * @type string
+ */
public $name = "SafeEmbed";
- public function transform($attr, $config, $context) {
+ /**
+ * @param array $attr
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return array
+ */
+ public function transform($attr, $config, $context)
+ {
$attr['allowscriptaccess'] = 'never';
$attr['allownetworking'] = 'internal';
$attr['type'] = 'application/x-shockwave-flash';
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/SafeObject.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/SafeObject.php
index 1ed74898bae41dbe0102ff8065a355fd016227a7..d1f3a4d2ed17805b1143e086b5d27398a41dca55 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/SafeObject.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/SafeObject.php
@@ -5,10 +5,22 @@
*/
class HTMLPurifier_AttrTransform_SafeObject extends HTMLPurifier_AttrTransform
{
+ /**
+ * @type string
+ */
public $name = "SafeObject";
- function transform($attr, $config, $context) {
- if (!isset($attr['type'])) $attr['type'] = 'application/x-shockwave-flash';
+ /**
+ * @param array $attr
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return array
+ */
+ public function transform($attr, $config, $context)
+ {
+ if (!isset($attr['type'])) {
+ $attr['type'] = 'application/x-shockwave-flash';
+ }
return $attr;
}
}
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/SafeParam.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/SafeParam.php
index bd86a745544cc5013c57ed9953d32658c99a212c..1143b4b49301e6e58669a4aacc27908f4ad1f311 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/SafeParam.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/SafeParam.php
@@ -14,15 +14,30 @@
*/
class HTMLPurifier_AttrTransform_SafeParam extends HTMLPurifier_AttrTransform
{
+ /**
+ * @type string
+ */
public $name = "SafeParam";
+
+ /**
+ * @type HTMLPurifier_AttrDef_URI
+ */
private $uri;
- public function __construct() {
+ public function __construct()
+ {
$this->uri = new HTMLPurifier_AttrDef_URI(true); // embedded
$this->wmode = new HTMLPurifier_AttrDef_Enum(array('window', 'opaque', 'transparent'));
}
- public function transform($attr, $config, $context) {
+ /**
+ * @param array $attr
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return array
+ */
+ public function transform($attr, $config, $context)
+ {
// If we add support for other objects, we'll need to alter the
// transforms.
switch ($attr['name']) {
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/ScriptRequired.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/ScriptRequired.php
index 4499050a22ac7fbb0012459ecbd04fe615560f47..b7057bbf8ed284515c7a6435a3f2f7d45355e818 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/ScriptRequired.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/ScriptRequired.php
@@ -5,7 +5,14 @@
*/
class HTMLPurifier_AttrTransform_ScriptRequired extends HTMLPurifier_AttrTransform
{
- public function transform($attr, $config, $context) {
+ /**
+ * @param array $attr
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return array
+ */
+ public function transform($attr, $config, $context)
+ {
if (!isset($attr['type'])) {
$attr['type'] = 'text/javascript';
}
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/TargetBlank.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/TargetBlank.php
index a6502c749285427af23f537d3f0a2993bd3e6db0..dd63ea89cb605f537780af59e1287d5edd5bfd5c 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/TargetBlank.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/TargetBlank.php
@@ -9,14 +9,24 @@
*/
class HTMLPurifier_AttrTransform_TargetBlank extends HTMLPurifier_AttrTransform
{
+ /**
+ * @type HTMLPurifier_URIParser
+ */
private $parser;
- public function __construct() {
+ public function __construct()
+ {
$this->parser = new HTMLPurifier_URIParser();
}
- public function transform($attr, $config, $context) {
-
+ /**
+ * @param array $attr
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return array
+ */
+ public function transform($attr, $config, $context)
+ {
if (!isset($attr['href'])) {
return $attr;
}
@@ -26,13 +36,10 @@ class HTMLPurifier_AttrTransform_TargetBlank extends HTMLPurifier_AttrTransform
$scheme = $url->getSchemeObj($config, $context);
if ($scheme->browsable && !$url->isBenign($config, $context)) {
- $attr['target'] = 'blank';
+ $attr['target'] = '_blank';
}
-
return $attr;
-
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Textarea.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Textarea.php
index 81ac3488ba87520621ec1a42131a9cc0131f2027..6a9f33a0c8a261fa6967b0581049eb2ea05ab49c 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Textarea.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/Textarea.php
@@ -5,14 +5,23 @@
*/
class HTMLPurifier_AttrTransform_Textarea extends HTMLPurifier_AttrTransform
{
-
- public function transform($attr, $config, $context) {
+ /**
+ * @param array $attr
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return array
+ */
+ public function transform($attr, $config, $context)
+ {
// Calculated from Firefox
- if (!isset($attr['cols'])) $attr['cols'] = '22';
- if (!isset($attr['rows'])) $attr['rows'] = '3';
+ if (!isset($attr['cols'])) {
+ $attr['cols'] = '22';
+ }
+ if (!isset($attr['rows'])) {
+ $attr['rows'] = '3';
+ }
return $attr;
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTypes.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTypes.php
index 6f985ff934750f0c5d068e991228748e8bf3ce93..3b70520b6ad99cdc5069ae863f9463b277f9112a 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTypes.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrTypes.php
@@ -6,7 +6,8 @@
class HTMLPurifier_AttrTypes
{
/**
- * Lookup array of attribute string identifiers to concrete implementations
+ * Lookup array of attribute string identifiers to concrete implementations.
+ * @type HTMLPurifier_AttrDef[]
*/
protected $info = array();
@@ -14,7 +15,8 @@ class HTMLPurifier_AttrTypes
* Constructs the info array, supplying default implementations for attribute
* types.
*/
- public function __construct() {
+ public function __construct()
+ {
// XXX This is kind of poor, since we don't actually /clone/
// instances; instead, we use the supplied make() attribute. So,
// the underlying class must know how to deal with arguments.
@@ -54,36 +56,39 @@ class HTMLPurifier_AttrTypes
$this->info['Number'] = new HTMLPurifier_AttrDef_Integer(false, false, true);
}
- private static function makeEnum($in) {
+ private static function makeEnum($in)
+ {
return new HTMLPurifier_AttrDef_Clone(new HTMLPurifier_AttrDef_Enum(explode(',', $in)));
}
/**
* Retrieves a type
- * @param $type String type name
- * @return Object AttrDef for type
+ * @param string $type String type name
+ * @return HTMLPurifier_AttrDef Object AttrDef for type
*/
- public function get($type) {
-
+ public function get($type)
+ {
// determine if there is any extra info tacked on
- if (strpos($type, '#') !== false) list($type, $string) = explode('#', $type, 2);
- else $string = '';
+ if (strpos($type, '#') !== false) {
+ list($type, $string) = explode('#', $type, 2);
+ } else {
+ $string = '';
+ }
if (!isset($this->info[$type])) {
trigger_error('Cannot retrieve undefined attribute type ' . $type, E_USER_ERROR);
return;
}
-
return $this->info[$type]->make($string);
-
}
/**
* Sets a new implementation for a type
- * @param $type String type name
- * @param $impl Object AttrDef for type
+ * @param string $type String type name
+ * @param HTMLPurifier_AttrDef $impl Object AttrDef for type
*/
- public function set($type, $impl) {
+ public function set($type, $impl)
+ {
$this->info[$type] = $impl;
}
}
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrValidator.php b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrValidator.php
index 829a0f8f225e5f56125c2daafc8ad835d694065a..f97dc93eddb5dabd6a84baffc0c0582f4585235b 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/AttrValidator.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/AttrValidator.php
@@ -9,17 +9,14 @@ class HTMLPurifier_AttrValidator
{
/**
- * Validates the attributes of a token, returning a modified token
+ * Validates the attributes of a token, mutating it as necessary.
* that has valid tokens
- * @param $token Reference to token to validate. We require a reference
- * because the operation this class performs on the token are
- * not atomic, so the context CurrentToken to be updated
- * throughout
- * @param $config Instance of HTMLPurifier_Config
- * @param $context Instance of HTMLPurifier_Context
+ * @param HTMLPurifier_Token $token Token to validate.
+ * @param HTMLPurifier_Config $config Instance of HTMLPurifier_Config
+ * @param HTMLPurifier_Context $context Instance of HTMLPurifier_Context
*/
- public function validateToken(&$token, &$config, $context) {
-
+ public function validateToken($token, $config, $context)
+ {
$definition = $config->getHTMLDefinition();
$e =& $context->get('ErrorCollector', true);
@@ -32,12 +29,15 @@ class HTMLPurifier_AttrValidator
// initialize CurrentToken if necessary
$current_token =& $context->get('CurrentToken', true);
- if (!$current_token) $context->register('CurrentToken', $token);
+ if (!$current_token) {
+ $context->register('CurrentToken', $token);
+ }
- if (
- !$token instanceof HTMLPurifier_Token_Start &&
+ if (!$token instanceof HTMLPurifier_Token_Start &&
!$token instanceof HTMLPurifier_Token_Empty
- ) return $token;
+ ) {
+ return;
+ }
// create alias to global definition array, see also $defs
// DEFINITION CALL
@@ -51,7 +51,9 @@ class HTMLPurifier_AttrValidator
foreach ($definition->info_attr_transform_pre as $transform) {
$attr = $transform->transform($o = $attr, $config, $context);
if ($e) {
- if ($attr != $o) $e->send(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
+ if ($attr != $o) {
+ $e->send(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
+ }
}
}
@@ -60,7 +62,9 @@ class HTMLPurifier_AttrValidator
foreach ($definition->info[$token->name]->attr_transform_pre as $transform) {
$attr = $transform->transform($o = $attr, $config, $context);
if ($e) {
- if ($attr != $o) $e->send(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
+ if ($attr != $o) {
+ $e->send(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
+ }
}
}
@@ -77,7 +81,7 @@ class HTMLPurifier_AttrValidator
foreach ($attr as $attr_key => $value) {
// call the definition
- if ( isset($defs[$attr_key]) ) {
+ if (isset($defs[$attr_key])) {
// there is a local definition defined
if ($defs[$attr_key] === false) {
// We've explicitly been told not to allow this element.
@@ -89,15 +93,19 @@ class HTMLPurifier_AttrValidator
} else {
// validate according to the element's definition
$result = $defs[$attr_key]->validate(
- $value, $config, $context
- );
+ $value,
+ $config,
+ $context
+ );
}
- } elseif ( isset($d_defs[$attr_key]) ) {
+ } elseif (isset($d_defs[$attr_key])) {
// there is a global definition defined, validate according
// to the global definition
$result = $d_defs[$attr_key]->validate(
- $value, $config, $context
- );
+ $value,
+ $config,
+ $context
+ );
} else {
// system never heard of the attribute? DELETE!
$result = false;
@@ -107,7 +115,9 @@ class HTMLPurifier_AttrValidator
if ($result === false || $result === null) {
// this is a generic error message that should replaced
// with more specific ones when possible
- if ($e) $e->send(E_ERROR, 'AttrValidator: Attribute removed');
+ if ($e) {
+ $e->send(E_ERROR, 'AttrValidator: Attribute removed');
+ }
// remove the attribute
unset($attr[$attr_key]);
@@ -137,7 +147,9 @@ class HTMLPurifier_AttrValidator
foreach ($definition->info_attr_transform_post as $transform) {
$attr = $transform->transform($o = $attr, $config, $context);
if ($e) {
- if ($attr != $o) $e->send(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
+ if ($attr != $o) {
+ $e->send(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
+ }
}
}
@@ -145,14 +157,18 @@ class HTMLPurifier_AttrValidator
foreach ($definition->info[$token->name]->attr_transform_post as $transform) {
$attr = $transform->transform($o = $attr, $config, $context);
if ($e) {
- if ($attr != $o) $e->send(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
+ if ($attr != $o) {
+ $e->send(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
+ }
}
}
$token->attr = $attr;
// destroy CurrentToken if we made it ourselves
- if (!$current_token) $context->destroy('CurrentToken');
+ if (!$current_token) {
+ $context->destroy('CurrentToken');
+ }
}
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/Bootstrap.php b/htdocs/lib/htmlpurifier/HTMLPurifier/Bootstrap.php
index 607c5b1880e6cd0bb9761b32b4fa13f3aef90aa9..707122bb296040a4d33d9cdb27a677cd5e90d217 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/Bootstrap.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/Bootstrap.php
@@ -32,11 +32,15 @@ class HTMLPurifier_Bootstrap
/**
* Autoload function for HTML Purifier
- * @param $class Class to load
+ * @param string $class Class to load
+ * @return bool
*/
- public static function autoload($class) {
+ public static function autoload($class)
+ {
$file = HTMLPurifier_Bootstrap::getPath($class);
- if (!$file) return false;
+ if (!$file) {
+ return false;
+ }
// Technically speaking, it should be ok and more efficient to
// just do 'require', but Antonio Parraga reports that with
// Zend extensions such as Zend debugger and APC, this invariant
@@ -48,9 +52,14 @@ class HTMLPurifier_Bootstrap
/**
* Returns the path for a specific class.
+ * @param string $class Class path to get
+ * @return string
*/
- public static function getPath($class) {
- if (strncmp('HTMLPurifier', $class, 12) !== 0) return false;
+ public static function getPath($class)
+ {
+ if (strncmp('HTMLPurifier', $class, 12) !== 0) {
+ return false;
+ }
// Custom implementations
if (strncmp('HTMLPurifier_Language_', $class, 22) === 0) {
$code = str_replace('_', '-', substr($class, 22));
@@ -58,47 +67,58 @@ class HTMLPurifier_Bootstrap
} else {
$file = str_replace('_', '/', $class) . '.php';
}
- if (!file_exists(HTMLPURIFIER_PREFIX . '/' . $file)) return false;
+ if (!file_exists(HTMLPURIFIER_PREFIX . '/' . $file)) {
+ return false;
+ }
return $file;
}
/**
* "Pre-registers" our autoloader on the SPL stack.
*/
- public static function registerAutoload() {
+ public static function registerAutoload()
+ {
$autoload = array('HTMLPurifier_Bootstrap', 'autoload');
- if ( ($funcs = spl_autoload_functions()) === false ) {
+ if (($funcs = spl_autoload_functions()) === false) {
spl_autoload_register($autoload);
} elseif (function_exists('spl_autoload_unregister')) {
- $buggy = version_compare(PHP_VERSION, '5.2.11', '<');
- $compat = version_compare(PHP_VERSION, '5.1.2', '<=') &&
- version_compare(PHP_VERSION, '5.1.0', '>=');
- foreach ($funcs as $func) {
- if ($buggy && is_array($func)) {
- // :TRICKY: There are some compatibility issues and some
- // places where we need to error out
- $reflector = new ReflectionMethod($func[0], $func[1]);
- if (!$reflector->isStatic()) {
- throw new Exception('
- HTML Purifier autoloader registrar is not compatible
- with non-static object methods due to PHP Bug #44144;
- Please do not use HTMLPurifier.autoload.php (or any
- file that includes this file); instead, place the code:
- spl_autoload_register(array(\'HTMLPurifier_Bootstrap\', \'autoload\'))
- after your own autoloaders.
- ');
+ if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
+ // prepend flag exists, no need for shenanigans
+ spl_autoload_register($autoload, true, true);
+ } else {
+ $buggy = version_compare(PHP_VERSION, '5.2.11', '<');
+ $compat = version_compare(PHP_VERSION, '5.1.2', '<=') &&
+ version_compare(PHP_VERSION, '5.1.0', '>=');
+ foreach ($funcs as $func) {
+ if ($buggy && is_array($func)) {
+ // :TRICKY: There are some compatibility issues and some
+ // places where we need to error out
+ $reflector = new ReflectionMethod($func[0], $func[1]);
+ if (!$reflector->isStatic()) {
+ throw new Exception(
+ 'HTML Purifier autoloader registrar is not compatible
+ with non-static object methods due to PHP Bug #44144;
+ Please do not use HTMLPurifier.autoload.php (or any
+ file that includes this file); instead, place the code:
+ spl_autoload_register(array(\'HTMLPurifier_Bootstrap\', \'autoload\'))
+ after your own autoloaders.'
+ );
+ }
+ // Suprisingly, spl_autoload_register supports the
+ // Class::staticMethod callback format, although call_user_func doesn't
+ if ($compat) {
+ $func = implode('::', $func);
+ }
}
- // Suprisingly, spl_autoload_register supports the
- // Class::staticMethod callback format, although call_user_func doesn't
- if ($compat) $func = implode('::', $func);
+ spl_autoload_unregister($func);
+ }
+ spl_autoload_register($autoload);
+ foreach ($funcs as $func) {
+ spl_autoload_register($func);
}
- spl_autoload_unregister($func);
}
- spl_autoload_register($autoload);
- foreach ($funcs as $func) spl_autoload_register($func);
}
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/CSSDefinition.php b/htdocs/lib/htmlpurifier/HTMLPurifier/CSSDefinition.php
index 91619f5d38a33beeb8b4994de987c41d2635d698..0acdee2d96e3038edfa1258099a953722941c4aa 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/CSSDefinition.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/CSSDefinition.php
@@ -11,35 +11,59 @@ class HTMLPurifier_CSSDefinition extends HTMLPurifier_Definition
/**
* Assoc array of attribute name to definition object.
+ * @type HTMLPurifier_AttrDef[]
*/
public $info = array();
/**
* Constructs the info array. The meat of this class.
+ * @param HTMLPurifier_Config $config
*/
- protected function doSetup($config) {
-
+ protected function doSetup($config)
+ {
$this->info['text-align'] = new HTMLPurifier_AttrDef_Enum(
- array('left', 'right', 'center', 'justify'), false);
+ 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-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);
+ array('none', 'left', 'right', 'both'),
+ false
+ );
$this->info['float'] = new HTMLPurifier_AttrDef_Enum(
- array('none', 'left', 'right'), false);
+ array('none', 'left', 'right'),
+ false
+ );
$this->info['font-style'] = new HTMLPurifier_AttrDef_Enum(
- array('normal', 'italic', 'oblique'), false);
+ array('normal', 'italic', 'oblique'),
+ false
+ );
$this->info['font-variant'] = new HTMLPurifier_AttrDef_Enum(
- array('normal', 'small-caps'), false);
+ array('normal', 'small-caps'),
+ false
+ );
$uri_or_none = new HTMLPurifier_AttrDef_CSS_Composite(
array(
@@ -49,16 +73,31 @@ class HTMLPurifier_CSSDefinition extends HTMLPurifier_Definition
);
$this->info['list-style-position'] = new HTMLPurifier_AttrDef_Enum(
- array('inside', 'outside'), false);
+ 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);
+ 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);
+ array('capitalize', 'uppercase', 'lowercase', 'none'),
+ false
+ );
$this->info['color'] = new HTMLPurifier_AttrDef_CSS_Color();
$this->info['background-image'] = $uri_or_none;
@@ -71,104 +110,137 @@ class HTMLPurifier_CSSDefinition extends HTMLPurifier_Definition
$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['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-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)
- ));
+ $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-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-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()
- ));
+ $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'))
- ));
+ $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
- );
+ $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();
@@ -176,8 +248,23 @@ class HTMLPurifier_CSSDefinition extends HTMLPurifier_Definition
// 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);
+ 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
@@ -190,26 +277,44 @@ class HTMLPurifier_CSSDefinition extends HTMLPurifier_Definition
$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['border-collapse'] = new HTMLPurifier_AttrDef_Enum(
+ array('collapse', 'separate')
+ );
- $this->info['caption-side'] = new HTMLPurifier_AttrDef_Enum(array(
- 'top', 'bottom'));
+ $this->info['caption-side'] = new HTMLPurifier_AttrDef_Enum(
+ array('top', 'bottom')
+ );
- $this->info['table-layout'] = new HTMLPurifier_AttrDef_Enum(array(
- 'auto', 'fixed'));
+ $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['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);
- // partial support
- $this->info['white-space'] = new HTMLPurifier_AttrDef_Enum(array('nowrap'));
+ // 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);
@@ -232,71 +337,119 @@ class HTMLPurifier_CSSDefinition extends HTMLPurifier_Definition
$this->setupConfigStuff($config);
}
- protected function doSetupProprietary($config) {
+ /**
+ * @param HTMLPurifier_Config $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();
+ $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();
+ $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-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'
- ));
+ /**
+ * @param HTMLPurifier_Config $config
+ */
+ 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'
- ));
+ /**
+ * @param HTMLPurifier_Config $config
+ */
+ 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')),
- ));
+ $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.
+ * @param HTMLPurifier_Config $config
* @todo Refactor duplicate elements into common class (probably using
* composition, not inheritance).
*/
- protected function setupConfigStuff($config) {
-
+ protected function setupConfigStuff($config)
+ {
// setup allowed elements
- $support = "(for information on implementing this, see the ".
- "support forums) ";
+ $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]);
+ if (!isset($allowed_properties[$name])) {
+ unset($this->info[$name]);
+ }
unset($allowed_properties[$name]);
}
// emit errors
@@ -315,7 +468,6 @@ class HTMLPurifier_CSSDefinition extends HTMLPurifier_Definition
}
}
}
-
}
}
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef.php b/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef.php
index c5d5216dab2d2c29b3b1d6be417a550dbf5b2345..8eb17b82e15107db8eb8c8a4446a96fb361ab970 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef.php
@@ -1,48 +1,52 @@
elements;
}
/**
* Validates nodes according to definition and returns modification.
*
- * @param $tokens_of_children Array of HTMLPurifier_Token
- * @param $config HTMLPurifier_Config object
- * @param $context HTMLPurifier_Context object
- * @return bool true to leave nodes as is
- * @return bool false to remove parent node
- * @return array of replacement child tokens
+ * @param HTMLPurifier_Node[] $children Array of HTMLPurifier_Node
+ * @param HTMLPurifier_Config $config HTMLPurifier_Config object
+ * @param HTMLPurifier_Context $context HTMLPurifier_Context object
+ * @return bool|array true to leave nodes as is, false to remove parent node, array of replacement children
*/
- abstract public function validateChildren($tokens_of_children, $config, $context);
+ abstract public function validateChildren($children, $config, $context);
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/Chameleon.php b/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/Chameleon.php
index 15c364ee33c53bc36a0fddeb77bbb2eae0903d84..7439be26b644d80fdce002890cb87a2228b11997 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/Chameleon.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/Chameleon.php
@@ -14,33 +14,52 @@ class HTMLPurifier_ChildDef_Chameleon extends HTMLPurifier_ChildDef
/**
* Instance of the definition object to use when inline. Usually stricter.
+ * @type HTMLPurifier_ChildDef_Optional
*/
public $inline;
/**
* Instance of the definition object to use when block.
+ * @type HTMLPurifier_ChildDef_Optional
*/
public $block;
+ /**
+ * @type string
+ */
public $type = 'chameleon';
/**
- * @param $inline List of elements to allow when inline.
- * @param $block List of elements to allow when block.
+ * @param array $inline List of elements to allow when inline.
+ * @param array $block List of elements to allow when block.
*/
- public function __construct($inline, $block) {
+ public function __construct($inline, $block)
+ {
$this->inline = new HTMLPurifier_ChildDef_Optional($inline);
- $this->block = new HTMLPurifier_ChildDef_Optional($block);
+ $this->block = new HTMLPurifier_ChildDef_Optional($block);
$this->elements = $this->block->elements;
}
- public function validateChildren($tokens_of_children, $config, $context) {
+ /**
+ * @param HTMLPurifier_Node[] $children
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool
+ */
+ public function validateChildren($children, $config, $context)
+ {
if ($context->get('IsInline') === false) {
return $this->block->validateChildren(
- $tokens_of_children, $config, $context);
+ $children,
+ $config,
+ $context
+ );
} else {
return $this->inline->validateChildren(
- $tokens_of_children, $config, $context);
+ $children,
+ $config,
+ $context
+ );
}
}
}
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/Custom.php b/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/Custom.php
index b68047b4b55f9f6e3564f06e11b038c6a154fe94..128132e96d8be42828baeb8d801fc9afe3725d66 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/Custom.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/Custom.php
@@ -8,28 +8,42 @@
*/
class HTMLPurifier_ChildDef_Custom extends HTMLPurifier_ChildDef
{
+ /**
+ * @type string
+ */
public $type = 'custom';
+
+ /**
+ * @type bool
+ */
public $allow_empty = false;
+
/**
- * Allowed child pattern as defined by the DTD
+ * Allowed child pattern as defined by the DTD.
+ * @type string
*/
public $dtd_regex;
+
/**
- * PCRE regex derived from $dtd_regex
- * @private
+ * PCRE regex derived from $dtd_regex.
+ * @type string
*/
private $_pcre_regex;
+
/**
* @param $dtd_regex Allowed child pattern from the DTD
*/
- public function __construct($dtd_regex) {
+ public function __construct($dtd_regex)
+ {
$this->dtd_regex = $dtd_regex;
$this->_compileRegex();
}
+
/**
* Compiles the PCRE regex from a DTD regex ($dtd_regex to $_pcre_regex)
*/
- protected function _compileRegex() {
+ protected function _compileRegex()
+ {
$raw = str_replace(' ', '', $this->dtd_regex);
if ($raw{0} != '(') {
$raw = "($raw)";
@@ -57,33 +71,31 @@ class HTMLPurifier_ChildDef_Custom extends HTMLPurifier_ChildDef
$this->_pcre_regex = $reg;
}
- public function validateChildren($tokens_of_children, $config, $context) {
+
+ /**
+ * @param HTMLPurifier_Node[] $children
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool
+ */
+ public function validateChildren($children, $config, $context)
+ {
$list_of_children = '';
$nesting = 0; // depth into the nest
- foreach ($tokens_of_children as $token) {
- if (!empty($token->is_whitespace)) continue;
-
- $is_child = ($nesting == 0); // direct
-
- if ($token instanceof HTMLPurifier_Token_Start) {
- $nesting++;
- } elseif ($token instanceof HTMLPurifier_Token_End) {
- $nesting--;
- }
-
- if ($is_child) {
- $list_of_children .= $token->name . ',';
+ foreach ($children as $node) {
+ if (!empty($node->is_whitespace)) {
+ continue;
}
+ $list_of_children .= $node->name . ',';
}
// add leading comma to deal with stray comma declarations
$list_of_children = ',' . rtrim($list_of_children, ',');
$okay =
preg_match(
- '/^,?'.$this->_pcre_regex.'$/',
+ '/^,?' . $this->_pcre_regex . '$/',
$list_of_children
);
-
- return (bool) $okay;
+ return (bool)$okay;
}
}
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/Empty.php b/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/Empty.php
index 13171f6651dc87ff98353d66454162cdf6392574..a8a6cbdd2c41f62b986cbd9812c02f138515bccd 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/Empty.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/Empty.php
@@ -9,10 +9,28 @@
*/
class HTMLPurifier_ChildDef_Empty extends HTMLPurifier_ChildDef
{
+ /**
+ * @type bool
+ */
public $allow_empty = true;
+
+ /**
+ * @type string
+ */
public $type = 'empty';
- public function __construct() {}
- public function validateChildren($tokens_of_children, $config, $context) {
+
+ public function __construct()
+ {
+ }
+
+ /**
+ * @param HTMLPurifier_Node[] $children
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return array
+ */
+ public function validateChildren($children, $config, $context)
+ {
return array();
}
}
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/List.php b/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/List.php
index cdaa2893a7e2d534d56ba26ccaeea95b70d84cf1..891b9f6f5bb0832d81392ac9d8283a76656a4c0e 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/List.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/List.php
@@ -2,117 +2,83 @@
/**
* Definition for list containers ul and ol.
+ *
+ * What does this do? The big thing is to handle ol/ul at the top
+ * level of list nodes, which should be handled specially by /folding/
+ * them into the previous list node. We generally shouldn't ever
+ * see other disallowed elements, because the autoclose behavior
+ * in MakeWellFormed handles it.
*/
class HTMLPurifier_ChildDef_List extends HTMLPurifier_ChildDef
{
+ /**
+ * @type string
+ */
public $type = 'list';
+ /**
+ * @type array
+ */
// 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) {
+
+ /**
+ * @param array $children
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return array
+ */
+ public function validateChildren($children, $config, $context)
+ {
// Flag for subclasses
$this->whitespace = false;
// if there are no tokens, delete parent node
- if (empty($tokens_of_children)) return false;
+ if (empty($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;
+ $current_li = false;
- foreach ($tokens_of_children as $token) {
- if (!empty($token->is_whitespace)) {
- $result[] = $token;
+ foreach ($children as $node) {
+ if (!empty($node->is_whitespace)) {
+ $result[] = $node;
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 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;
+ if ($node->name === 'li') {
+ // good
+ $current_li = $node;
+ $result[] = $node;
+ } else {
+ // we want to tuck this into the previous li
+ // Invariant: we expect the node to be ol/ul
+ // ToDo: Make this more robust in the case of not ol/ul
+ // by distinguishing between existing li and li created
+ // to handle non-list elements; non-list elements should
+ // not be appended to an existing li; only li created
+ // for non-list. This distinction is not currently made.
+ if ($current_li === false) {
+ $current_li = new HTMLPurifier_Node_Element('li');
+ $result[] = $current_li;
}
+ $current_li->children[] = $node;
+ $current_li->empty = false; // XXX fascinating! Check for this error elsewhere ToDo
}
- $result[] = $token;
}
- if ($need_close_li) {
- $result[] = new HTMLPurifier_Token_End('li');
+ if (empty($result)) {
+ return false;
}
- if (empty($result)) return false;
if ($all_whitespace) {
return false;
}
- if ($tokens_of_children == $result) return true;
return $result;
}
}
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/Optional.php b/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/Optional.php
index 32bcb9898eac9ea6fff386e1617ad332b5c19971..b9468063b1aa26626dc7d3d6518eb6703eb1676f 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/Optional.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/Optional.php
@@ -9,15 +9,34 @@
*/
class HTMLPurifier_ChildDef_Optional extends HTMLPurifier_ChildDef_Required
{
+ /**
+ * @type bool
+ */
public $allow_empty = true;
+
+ /**
+ * @type string
+ */
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
+
+ /**
+ * @param array $children
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return array
+ */
+ public function validateChildren($children, $config, $context)
+ {
+ $result = parent::validateChildren($children, $config, $context);
+ // we assume that $children is not modified
if ($result === false) {
- if (empty($tokens_of_children)) return true;
- elseif ($this->whitespace) return $tokens_of_children;
- else return array();
+ if (empty($children)) {
+ return true;
+ } elseif ($this->whitespace) {
+ return $children;
+ } else {
+ return array();
+ }
}
return $result;
}
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/Required.php b/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/Required.php
index 4889f249b8629fc71460f344e4fa8deb30d1d22f..0d1c8f5f397d8241a057a128429c8a7966e04b69 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/Required.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/Required.php
@@ -7,17 +7,21 @@ class HTMLPurifier_ChildDef_Required extends HTMLPurifier_ChildDef
{
/**
* Lookup table of allowed elements.
- * @public
+ * @type array
*/
public $elements = array();
+
/**
* Whether or not the last passed node was all whitespace.
+ * @type bool
*/
protected $whitespace = false;
+
/**
- * @param $elements List of allowed element names (lowercase).
+ * @param array|string $elements List of allowed element names (lowercase).
*/
- public function __construct($elements) {
+ public function __construct($elements)
+ {
if (is_string($elements)) {
$elements = str_replace(' ', '', $elements);
$elements = explode('|', $elements);
@@ -27,29 +31,43 @@ class HTMLPurifier_ChildDef_Required extends HTMLPurifier_ChildDef
$elements = array_flip($elements);
foreach ($elements as $i => $x) {
$elements[$i] = true;
- if (empty($i)) unset($elements[$i]); // remove blank
+ if (empty($i)) {
+ unset($elements[$i]);
+ } // remove blank
}
}
$this->elements = $elements;
}
+
+ /**
+ * @type bool
+ */
public $allow_empty = false;
+
+ /**
+ * @type string
+ */
public $type = 'required';
- public function validateChildren($tokens_of_children, $config, $context) {
+
+ /**
+ * @param array $children
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return array
+ */
+ public function validateChildren($children, $config, $context)
+ {
// Flag for subclasses
$this->whitespace = false;
// if there are no tokens, delete parent node
- if (empty($tokens_of_children)) return false;
+ if (empty($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
@@ -58,58 +76,41 @@ class HTMLPurifier_ChildDef_Required extends HTMLPurifier_ChildDef
// 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;
+ $stack = array_reverse($children);
+ while (!empty($stack)) {
+ $node = array_pop($stack);
+ if (!empty($node->is_whitespace)) {
+ $result[] = $node;
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)
- );
+ if (!isset($this->elements[$node->name])) {
+ // special case text
+ // XXX One of these ought to be redundant or something
+ if ($pcdata_allowed && $node instanceof HTMLPurifier_Node_Text) {
+ $result[] = $node;
+ continue;
+ }
+ // spill the child contents in
+ // ToDo: Make configurable
+ if ($node instanceof HTMLPurifier_Node_Element) {
+ for ($i = count($node->children) - 1; $i >= 0; $i--) {
+ $stack[] = $node->children[$i];
}
continue;
}
+ 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
- }
+ $result[] = $node;
+ }
+ if (empty($result)) {
+ return false;
}
- if (empty($result)) return false;
if ($all_whitespace) {
$this->whitespace = true;
return false;
}
- if ($tokens_of_children == $result) return true;
return $result;
}
}
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/StrictBlockquote.php b/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/StrictBlockquote.php
index dfae8a6e5e1d28f81b7484bcf81d941e4bf6dfab..3270a46e1bf9a060dc0d8c0f446e3fa06c74ce39 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/StrictBlockquote.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/StrictBlockquote.php
@@ -5,75 +5,97 @@
*/
class HTMLPurifier_ChildDef_StrictBlockquote extends HTMLPurifier_ChildDef_Required
{
+ /**
+ * @type array
+ */
protected $real_elements;
+
+ /**
+ * @type array
+ */
protected $fake_elements;
+
+ /**
+ * @type bool
+ */
public $allow_empty = true;
+
+ /**
+ * @type string
+ */
public $type = 'strictblockquote';
+
+ /**
+ * @type bool
+ */
protected $init = false;
/**
+ * @param HTMLPurifier_Config $config
+ * @return array
* @note We don't want MakeWellFormed to auto-close inline elements since
* they might be allowed.
*/
- public function getAllowedElements($config) {
+ public function getAllowedElements($config)
+ {
$this->init($config);
return $this->fake_elements;
}
- public function validateChildren($tokens_of_children, $config, $context) {
-
+ /**
+ * @param array $children
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return array
+ */
+ public function validateChildren($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);
+ $result = parent::validateChildren($children, $config, $context);
$this->elements = $this->real_elements;
- if ($result === false) return array();
- if ($result === true) $result = $tokens_of_children;
+ if ($result === false) {
+ return array();
+ }
+ if ($result === true) {
+ $result = $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;
+ $block_wrap_name = $def->info_block_wrapper;
+ $block_wrap = false;
$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;
- }
+ foreach ($result as $node) {
+ if ($block_wrap === false) {
+ if (($node instanceof HTMLPurifier_Node_Text && !$node->is_whitespace) ||
+ ($node instanceof HTMLPurifier_Node_Element && !isset($this->elements[$node->name]))) {
+ $block_wrap = new HTMLPurifier_Node_Element($def->info_block_wrapper);
+ $ret[] = $block_wrap;
}
} 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;
- }
- }
+ if ($node instanceof HTMLPurifier_Node_Element && isset($this->elements[$node->name])) {
+ $block_wrap = false;
+
}
}
- $ret[] = $token;
- if ($token instanceof HTMLPurifier_Token_Start) $depth++;
- if ($token instanceof HTMLPurifier_Token_End) $depth--;
+ if ($block_wrap) {
+ $block_wrap->children[] = $node;
+ } else {
+ $ret[] = $node;
+ }
}
- if ($is_inline) $ret[] = $block_wrap_end;
return $ret;
}
- private function init($config) {
+ /**
+ * @param HTMLPurifier_Config $config
+ */
+ private function init($config)
+ {
if (!$this->init) {
$def = $config->getHTMLDefinition();
// allow all inline elements
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/Table.php b/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/Table.php
index 9a93421a1a3e2dbdcb4720ecc5a7482e5032205c..3e4a0f21824fadf752c06ec6a0fa90be393c90bb 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/Table.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/ChildDef/Table.php
@@ -31,195 +31,192 @@
*/
class HTMLPurifier_ChildDef_Table extends HTMLPurifier_ChildDef
{
+ /**
+ * @type bool
+ */
public $allow_empty = false;
+
+ /**
+ * @type string
+ */
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;
+ /**
+ * @type array
+ */
+ public $elements = array(
+ 'tr' => true,
+ 'tbody' => true,
+ 'thead' => true,
+ 'tfoot' => true,
+ 'caption' => true,
+ 'colgroup' => true,
+ 'col' => true
+ );
+
+ public function __construct()
+ {
+ }
+
+ /**
+ * @param array $children
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return array
+ */
+ public function validateChildren($children, $config, $context)
+ {
+ if (empty($children)) {
+ return false;
+ }
// only one of these elements is allowed in a table
$caption = false;
- $thead = false;
- $tfoot = false;
+ $thead = false;
+ $tfoot = false;
+
+ // whitespace
+ $initial_ws = array();
+ $after_caption_ws = array();
+ $after_thead_ws = array();
+ $after_tfoot_ws = array();
// as many of these as you want
- $cols = array();
+ $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
//
s with a
.
- foreach ($tokens_of_children as $token) {
- $is_child = ($nesting == 0);
+ $ws_accum =& $initial_ws;
- if ($token === false) {
- // terminating sequence started
- } elseif ($token instanceof HTMLPurifier_Token_Start) {
- $nesting++;
- } elseif ($token instanceof HTMLPurifier_Token_End) {
- $nesting--;
+ foreach ($children as $node) {
+ if ($node instanceof HTMLPurifier_Node_Comment) {
+ $ws_accum[] = $node;
+ continue;
}
-
- // 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 to
- // the top. Ever. (Our scheme will float the
- // first to the top.) So maybe
- // s that are not first should be
- // turned into ? 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;
+ switch ($node->name) {
+ case 'tbody':
+ $tbody_mode = true;
+ // fall through
+ case 'tr':
+ $content[] = $node;
+ $ws_accum =& $content;
+ break;
+ case 'caption':
+ // there can only be one caption!
+ if ($caption !== false) break;
+ $caption = $node;
+ $ws_accum =& $after_caption_ws;
+ break;
+ case 'thead':
+ $tbody_mode = true;
+ // XXX This breaks rendering properties with
+ // Firefox, which never floats a to
+ // the top. Ever. (Our scheme will float the
+ // first to the top.) So maybe
+ // s that are not first should be
+ // turned into ? Very tricky, indeed.
+ if ($thead === false) {
+ $thead = $node;
+ $ws_accum =& $after_thead_ws;
} else {
- // add the node to the collection
- $collection[] = $token;
+ // 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.
+ $node->name = 'tbody';
+ $content[] = $node;
+ $ws_accum =& $content;
}
- }
-
- // 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;
+ break;
+ case 'tfoot':
+ // see above for some aveats
+ $tbody_mode = true;
+ if ($tfoot === false) {
+ $tfoot = $node;
+ $ws_accum =& $after_tfoot_ws;
+ } else {
+ $node->name = 'tbody';
+ $content[] = $node;
+ $ws_accum =& $content;
}
- 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;
+ break;
+ case 'colgroup':
+ case 'col':
+ $cols[] = $node;
+ $ws_accum =& $cols;
+ break;
+ case '#PCDATA':
+ // How is whitespace handled? We treat is as sticky to
+ // the *end* of the previous element. So all of the
+ // nonsense we have worked on is to keep things
+ // together.
+ if (!empty($node->is_whitespace)) {
+ $ws_accum[] = $node;
}
+ break;
}
}
- if (empty($content)) return false;
+ 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);
+ $ret = $initial_ws;
+ if ($caption !== false) {
+ $ret[] = $caption;
+ $ret = array_merge($ret, $after_caption_ws);
+ }
+ if ($cols !== false) {
+ $ret = array_merge($ret, $cols);
+ }
+ if ($thead !== false) {
+ $ret[] = $thead;
+ $ret = array_merge($ret, $after_thead_ws);
+ }
+ if ($tfoot !== false) {
+ $ret[] = $tfoot;
+ $ret = array_merge($ret, $after_tfoot_ws);
+ }
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;
+ // we have to shuffle tr into tbody
+ $current_tr_tbody = null;
+
+ foreach($content as $node) {
+ switch ($node->name) {
+ case 'tbody':
+ $current_tr_tbody = null;
+ $ret[] = $node;
+ break;
+ case 'tr':
+ if ($current_tr_tbody === null) {
+ $current_tr_tbody = new HTMLPurifier_Node_Element('tbody');
+ $ret[] = $current_tr_tbody;
}
- } // iterator variable carries over
- if ($t->name === 'tr') {
- if ($inside_tbody) {
- $ret = array_merge($ret, $token_array);
+ $current_tr_tbody->children[] = $node;
+ break;
+ case '#PCDATA':
+ assert($node->is_whitespace);
+ if ($current_tr_tbody === null) {
+ $ret[] = $node;
} else {
- $ret[] = new HTMLPurifier_Token_Start('tbody');
- $ret = array_merge($ret, $token_array);
- $inside_tbody = true;
+ $current_tr_tbody->children[] = $node;
}
- } 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);
+ break;
}
}
- if ($inside_tbody) {
- $ret[] = new HTMLPurifier_Token_End('tbody');
- }
} else {
- foreach ($content as $token_array) {
- // invariant: everything in here is
s
- $ret = array_merge($ret, $token_array);
- }
+ $ret = array_merge($ret, $content);
}
- 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;
+ return $ret;
}
}
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/Config.php b/htdocs/lib/htmlpurifier/HTMLPurifier/Config.php
index 554980f2225a0384e632853bf33f15590340a74f..7ada59b949822c048ad9477540d21a00d18d984d 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/Config.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/Config.php
@@ -19,78 +19,92 @@ class HTMLPurifier_Config
/**
* HTML Purifier's version
+ * @type string
*/
- public $version = '4.4.0';
+ public $version = '4.6.0';
/**
- * Bool indicator whether or not to automatically finalize
- * the object if a read operation is done
+ * Whether or not to automatically finalize
+ * the object if a read operation is done.
+ * @type bool
*/
public $autoFinalize = true;
// protected member variables
/**
- * Namespace indexed array of serials for specific namespaces (see
- * getSerial() for more info).
+ * Namespace indexed array of serials for specific namespaces.
+ * @see getSerial() for more info.
+ * @type string[]
*/
protected $serials = array();
/**
- * Serial for entire configuration object
+ * Serial for entire configuration object.
+ * @type string
*/
protected $serial;
/**
- * Parser for variables
+ * Parser for variables.
+ * @type HTMLPurifier_VarParser_Flexible
*/
protected $parser = null;
/**
- * Reference HTMLPurifier_ConfigSchema for value checking
+ * Reference HTMLPurifier_ConfigSchema for value checking.
+ * @type HTMLPurifier_ConfigSchema
* @note This is public for introspective purposes. Please don't
* abuse!
*/
public $def;
/**
- * Indexed array of definitions
+ * Indexed array of definitions.
+ * @type HTMLPurifier_Definition[]
*/
protected $definitions;
/**
- * Bool indicator whether or not config is finalized
+ * Whether or not config is finalized.
+ * @type bool
*/
protected $finalized = false;
/**
* Property list containing configuration directives.
+ * @type array
*/
protected $plist;
/**
- * Whether or not a set is taking place due to an
- * alias lookup.
+ * Whether or not a set is taking place due to an alias lookup.
+ * @type bool
*/
private $aliasMode;
/**
- * Set to false if you do not want line and file numbers in errors
+ * Set to false if you do not want line and file numbers in errors.
* (useful when unit testing). This will also compress some errors
* and exceptions.
+ * @type bool
*/
public $chatty = true;
/**
* Current lock; only gets to this namespace are allowed.
+ * @type string
*/
private $lock;
/**
- * @param $definition HTMLPurifier_ConfigSchema that defines what directives
- * are allowed.
+ * Constructor
+ * @param HTMLPurifier_ConfigSchema $definition ConfigSchema that defines
+ * what directives are allowed.
+ * @param HTMLPurifier_PropertyList $parent
*/
- public function __construct($definition, $parent = null) {
+ public function __construct($definition, $parent = null)
+ {
$parent = $parent ? $parent : $definition->defaultPlist;
$this->plist = new HTMLPurifier_PropertyList($parent);
$this->def = $definition; // keep a copy around for checking
@@ -103,10 +117,11 @@ class HTMLPurifier_Config
* object. Can be: a HTMLPurifier_Config() object,
* an array of directives based on loadArray(),
* or a string filename of an ini file.
- * @param HTMLPurifier_ConfigSchema Schema object
- * @return Configured HTMLPurifier_Config object
+ * @param HTMLPurifier_ConfigSchema $schema Schema object
+ * @return HTMLPurifier_Config Configured object
*/
- public static function create($config, $schema = null) {
+ public static function create($config, $schema = null)
+ {
if ($config instanceof HTMLPurifier_Config) {
// pass-through
return $config;
@@ -116,57 +131,79 @@ class HTMLPurifier_Config
} else {
$ret = new HTMLPurifier_Config($schema);
}
- if (is_string($config)) $ret->loadIni($config);
- elseif (is_array($config)) $ret->loadArray($config);
+ if (is_string($config)) {
+ $ret->loadIni($config);
+ } elseif (is_array($config)) $ret->loadArray($config);
return $ret;
}
/**
* Creates a new config object that inherits from a previous one.
- * @param HTMLPurifier_Config $config Configuration object to inherit
- * from.
+ * @param HTMLPurifier_Config $config Configuration object to inherit from.
* @return HTMLPurifier_Config object with $config as its parent.
*/
- public static function inherit(HTMLPurifier_Config $config) {
+ public static function inherit(HTMLPurifier_Config $config)
+ {
return new HTMLPurifier_Config($config->def, $config->plist);
}
/**
* Convenience constructor that creates a default configuration object.
- * @return Default HTMLPurifier_Config object.
+ * @return HTMLPurifier_Config default object.
*/
- public static function createDefault() {
+ public static function createDefault()
+ {
$definition = HTMLPurifier_ConfigSchema::instance();
$config = new HTMLPurifier_Config($definition);
return $config;
}
/**
- * Retreives a value from the configuration.
- * @param $key String key
+ * Retrieves a value from the configuration.
+ *
+ * @param string $key String key
+ * @param mixed $a
+ *
+ * @return mixed
*/
- public function get($key, $a = null) {
+ public function get($key, $a = null)
+ {
if ($a !== null) {
- $this->triggerError("Using deprecated API: use \$config->get('$key.$a') instead", E_USER_WARNING);
+ $this->triggerError(
+ "Using deprecated API: use \$config->get('$key.$a') instead",
+ E_USER_WARNING
+ );
$key = "$key.$a";
}
- if (!$this->finalized) $this->autoFinalize();
+ if (!$this->finalized) {
+ $this->autoFinalize();
+ }
if (!isset($this->def->info[$key])) {
// can't add % due to SimpleTest bug
- $this->triggerError('Cannot retrieve value of undefined directive ' . htmlspecialchars($key),
- E_USER_WARNING);
+ $this->triggerError(
+ 'Cannot retrieve value of undefined directive ' . htmlspecialchars($key),
+ E_USER_WARNING
+ );
return;
}
if (isset($this->def->info[$key]->isAlias)) {
$d = $this->def->info[$key];
- $this->triggerError('Cannot get value from aliased directive, use real name ' . $d->key,
- E_USER_ERROR);
+ $this->triggerError(
+ 'Cannot get value from aliased directive, use real name ' . $d->key,
+ E_USER_ERROR
+ );
return;
}
if ($this->lock) {
list($ns) = explode('.', $key);
if ($ns !== $this->lock) {
- $this->triggerError('Cannot get value of namespace ' . $ns . ' when lock for ' . $this->lock . ' is active, this probably indicates a Definition setup method is accessing directives that are not within its namespace', E_USER_ERROR);
+ $this->triggerError(
+ 'Cannot get value of namespace ' . $ns . ' when lock for ' .
+ $this->lock .
+ ' is active, this probably indicates a Definition setup method ' .
+ 'is accessing directives that are not within its namespace',
+ E_USER_ERROR
+ );
return;
}
}
@@ -174,53 +211,73 @@ class HTMLPurifier_Config
}
/**
- * Retreives an array of directives to values from a given namespace
- * @param $namespace String namespace
+ * Retrieves an array of directives to values from a given namespace
+ *
+ * @param string $namespace String namespace
+ *
+ * @return array
*/
- public function getBatch($namespace) {
- if (!$this->finalized) $this->autoFinalize();
+ public function getBatch($namespace)
+ {
+ if (!$this->finalized) {
+ $this->autoFinalize();
+ }
$full = $this->getAll();
if (!isset($full[$namespace])) {
- $this->triggerError('Cannot retrieve undefined namespace ' . htmlspecialchars($namespace),
- E_USER_WARNING);
+ $this->triggerError(
+ 'Cannot retrieve undefined namespace ' .
+ htmlspecialchars($namespace),
+ E_USER_WARNING
+ );
return;
}
return $full[$namespace];
}
/**
- * Returns a md5 signature of a segment of the configuration object
+ * Returns a SHA-1 signature of a segment of the configuration object
* that uniquely identifies that particular configuration
+ *
+ * @param string $namespace Namespace to get serial for
+ *
+ * @return string
* @note Revision is handled specially and is removed from the batch
* before processing!
- * @param $namespace Namespace to get serial for
*/
- public function getBatchSerial($namespace) {
+ public function getBatchSerial($namespace)
+ {
if (empty($this->serials[$namespace])) {
$batch = $this->getBatch($namespace);
unset($batch['DefinitionRev']);
- $this->serials[$namespace] = md5(serialize($batch));
+ $this->serials[$namespace] = sha1(serialize($batch));
}
return $this->serials[$namespace];
}
/**
- * Returns a md5 signature for the entire configuration object
+ * Returns a SHA-1 signature for the entire configuration object
* that uniquely identifies that particular configuration
+ *
+ * @return string
*/
- public function getSerial() {
+ public function getSerial()
+ {
if (empty($this->serial)) {
- $this->serial = md5(serialize($this->getAll()));
+ $this->serial = sha1(serialize($this->getAll()));
}
return $this->serial;
}
/**
* Retrieves all directives, organized by namespace
+ *
* @warning This is a pretty inefficient function, avoid if you can
*/
- public function getAll() {
- if (!$this->finalized) $this->autoFinalize();
+ public function getAll()
+ {
+ if (!$this->finalized) {
+ $this->autoFinalize();
+ }
$ret = array();
foreach ($this->plist->squash() as $name => $value) {
list($ns, $key) = explode('.', $name, 2);
@@ -231,10 +288,13 @@ class HTMLPurifier_Config
/**
* Sets a value to configuration.
- * @param $key String key
- * @param $value Mixed value
+ *
+ * @param string $key key
+ * @param mixed $value value
+ * @param mixed $a
*/
- public function set($key, $value, $a = null) {
+ public function set($key, $value, $a = null)
+ {
if (strpos($key, '.') === false) {
$namespace = $key;
$directive = $value;
@@ -244,18 +304,25 @@ class HTMLPurifier_Config
} else {
list($namespace) = explode('.', $key);
}
- if ($this->isFinalized('Cannot set directive after finalization')) return;
+ if ($this->isFinalized('Cannot set directive after finalization')) {
+ return;
+ }
if (!isset($this->def->info[$key])) {
- $this->triggerError('Cannot set undefined directive ' . htmlspecialchars($key) . ' to value',
- E_USER_WARNING);
+ $this->triggerError(
+ 'Cannot set undefined directive ' . htmlspecialchars($key) . ' to value',
+ E_USER_WARNING
+ );
return;
}
$def = $this->def->info[$key];
if (isset($def->isAlias)) {
if ($this->aliasMode) {
- $this->triggerError('Double-aliases not allowed, please fix '.
- 'ConfigSchema bug with' . $key, E_USER_ERROR);
+ $this->triggerError(
+ 'Double-aliases not allowed, please fix '.
+ 'ConfigSchema bug with' . $key,
+ E_USER_ERROR
+ );
return;
}
$this->aliasMode = true;
@@ -279,7 +346,11 @@ class HTMLPurifier_Config
try {
$value = $this->parser->parse($value, $type, $allow_null);
} catch (HTMLPurifier_VarParserException $e) {
- $this->triggerError('Value for ' . $key . ' is of invalid type, should be ' . HTMLPurifier_VarParser::getTypeName($type), E_USER_WARNING);
+ $this->triggerError(
+ 'Value for ' . $key . ' is of invalid type, should be ' .
+ HTMLPurifier_VarParser::getTypeName($type),
+ E_USER_WARNING
+ );
return;
}
if (is_string($value) && is_object($def)) {
@@ -289,8 +360,11 @@ class HTMLPurifier_Config
}
// check to see if the value is allowed
if (isset($def->allowed) && !isset($def->allowed[$value])) {
- $this->triggerError('Value not supported, valid values are: ' .
- $this->_listify($def->allowed), E_USER_WARNING);
+ $this->triggerError(
+ 'Value not supported, valid values are: ' .
+ $this->_listify($def->allowed),
+ E_USER_WARNING
+ );
return;
}
}
@@ -308,63 +382,83 @@ class HTMLPurifier_Config
/**
* Convenience function for error reporting
+ *
+ * @param array $lookup
+ *
+ * @return string
*/
- private function _listify($lookup) {
+ private function _listify($lookup)
+ {
$list = array();
- foreach ($lookup as $name => $b) $list[] = $name;
+ foreach ($lookup as $name => $b) {
+ $list[] = $name;
+ }
return implode(', ', $list);
}
/**
* Retrieves object reference to the HTML definition.
- * @param $raw Return a copy that has not been setup yet. Must be
+ *
+ * @param bool $raw Return a copy that has not been setup yet. Must be
* called before it's been setup, otherwise won't work.
- * @param $optimized If true, this method may return null, to
+ * @param bool $optimized If true, this method may return null, to
* indicate that a cached version of the modified
* definition object is available and no further edits
* are necessary. Consider using
* maybeGetRawHTMLDefinition, which is more explicitly
* named, instead.
+ *
+ * @return HTMLPurifier_HTMLDefinition
*/
- public function getHTMLDefinition($raw = false, $optimized = false) {
+ public function getHTMLDefinition($raw = false, $optimized = false)
+ {
return $this->getDefinition('HTML', $raw, $optimized);
}
/**
* Retrieves object reference to the CSS definition
- * @param $raw Return a copy that has not been setup yet. Must be
+ *
+ * @param bool $raw Return a copy that has not been setup yet. Must be
* called before it's been setup, otherwise won't work.
- * @param $optimized If true, this method may return null, to
+ * @param bool $optimized If true, this method may return null, to
* indicate that a cached version of the modified
* definition object is available and no further edits
* are necessary. Consider using
* maybeGetRawCSSDefinition, which is more explicitly
* named, instead.
+ *
+ * @return HTMLPurifier_CSSDefinition
*/
- public function getCSSDefinition($raw = false, $optimized = false) {
+ public function getCSSDefinition($raw = false, $optimized = false)
+ {
return $this->getDefinition('CSS', $raw, $optimized);
}
/**
* Retrieves object reference to the URI definition
- * @param $raw Return a copy that has not been setup yet. Must be
+ *
+ * @param bool $raw Return a copy that has not been setup yet. Must be
* called before it's been setup, otherwise won't work.
- * @param $optimized If true, this method may return null, to
+ * @param bool $optimized If true, this method may return null, to
* indicate that a cached version of the modified
* definition object is available and no further edits
* are necessary. Consider using
* maybeGetRawURIDefinition, which is more explicitly
* named, instead.
+ *
+ * @return HTMLPurifier_URIDefinition
*/
- public function getURIDefinition($raw = false, $optimized = false) {
+ public function getURIDefinition($raw = false, $optimized = false)
+ {
return $this->getDefinition('URI', $raw, $optimized);
}
/**
* Retrieves a definition
- * @param $type Type of definition: HTML, CSS, etc
- * @param $raw Whether or not definition should be returned raw
- * @param $optimized Only has an effect when $raw is true. Whether
+ *
+ * @param string $type Type of definition: HTML, CSS, etc
+ * @param bool $raw Whether or not definition should be returned raw
+ * @param bool $optimized Only has an effect when $raw is true. Whether
* or not to return null if the result is already present in
* the cache. This is off by default for backwards
* compatibility reasons, but you need to do things this
@@ -372,12 +466,18 @@ class HTMLPurifier_Config
* Check out enduser-customize.html for more details.
* We probably won't ever change this default, as much as the
* maybe semantics is the "right thing to do."
+ *
+ * @throws HTMLPurifier_Exception
+ * @return HTMLPurifier_Definition
*/
- public function getDefinition($type, $raw = false, $optimized = false) {
+ public function getDefinition($type, $raw = false, $optimized = false)
+ {
if ($optimized && !$raw) {
throw new HTMLPurifier_Exception("Cannot set optimized = true when raw = false");
}
- if (!$this->finalized) $this->autoFinalize();
+ if (!$this->finalized) {
+ $this->autoFinalize();
+ }
// temporarily suspend locks, so we can handle recursive definition calls
$lock = $this->lock;
$this->lock = null;
@@ -395,7 +495,9 @@ class HTMLPurifier_Config
return $def;
} else {
$def->setup($this);
- if ($def->optimized) $cache->add($def, $this);
+ if ($def->optimized) {
+ $cache->add($def, $this);
+ }
return $def;
}
}
@@ -424,23 +526,36 @@ class HTMLPurifier_Config
if ($optimized) {
if (is_null($this->get($type . '.DefinitionID'))) {
// fatally error out if definition ID not set
- throw new HTMLPurifier_Exception("Cannot retrieve raw version without specifying %$type.DefinitionID");
+ throw new HTMLPurifier_Exception(
+ "Cannot retrieve raw version without specifying %$type.DefinitionID"
+ );
}
}
if (!empty($this->definitions[$type])) {
$def = $this->definitions[$type];
if ($def->setup && !$optimized) {
- $extra = $this->chatty ? " (try moving this code block earlier in your initialization)" : "";
- throw new HTMLPurifier_Exception("Cannot retrieve raw definition after it has already been setup" . $extra);
+ $extra = $this->chatty ?
+ " (try moving this code block earlier in your initialization)" :
+ "";
+ throw new HTMLPurifier_Exception(
+ "Cannot retrieve raw definition after it has already been setup" .
+ $extra
+ );
}
if ($def->optimized === null) {
$extra = $this->chatty ? " (try flushing your cache)" : "";
- throw new HTMLPurifier_Exception("Optimization status of definition is unknown" . $extra);
+ throw new HTMLPurifier_Exception(
+ "Optimization status of definition is unknown" . $extra
+ );
}
if ($def->optimized !== $optimized) {
$msg = $optimized ? "optimized" : "unoptimized";
- $extra = $this->chatty ? " (this backtrace is for the first inconsistent call, which was for a $msg raw definition)" : "";
- throw new HTMLPurifier_Exception("Inconsistent use of optimized and unoptimized raw definition retrievals" . $extra);
+ $extra = $this->chatty ?
+ " (this backtrace is for the first inconsistent call, which was for a $msg raw definition)"
+ : "";
+ throw new HTMLPurifier_Exception(
+ "Inconsistent use of optimized and unoptimized raw definition retrievals" . $extra
+ );
}
}
// check if definition was in memory
@@ -473,9 +588,22 @@ class HTMLPurifier_Config
if (!$optimized) {
if (!is_null($this->get($type . '.DefinitionID'))) {
if ($this->chatty) {
- $this->triggerError("Due to a documentation error in previous version of HTML Purifier, your definitions are not being cached. If this is OK, you can remove the %$type.DefinitionRev and %$type.DefinitionID declaration. Otherwise, modify your code to use maybeGetRawDefinition, and test if the returned value is null before making any edits (if it is null, that means that a cached version is available, and no raw operations are necessary). See Customize for more details", E_USER_WARNING);
+ $this->triggerError(
+ 'Due to a documentation error in previous version of HTML Purifier, your ' .
+ 'definitions are not being cached. If this is OK, you can remove the ' .
+ '%$type.DefinitionRev and %$type.DefinitionID declaration. Otherwise, ' .
+ 'modify your code to use maybeGetRawDefinition, and test if the returned ' .
+ 'value is null before making any edits (if it is null, that means that a ' .
+ 'cached version is available, and no raw operations are necessary). See ' .
+ '' .
+ 'Customize for more details',
+ E_USER_WARNING
+ );
} else {
- $this->triggerError("Useless DefinitionID declaration", E_USER_WARNING);
+ $this->triggerError(
+ "Useless DefinitionID declaration",
+ E_USER_WARNING
+ );
}
}
}
@@ -487,7 +615,16 @@ class HTMLPurifier_Config
throw new HTMLPurifier_Exception("The impossible happened!");
}
- private function initDefinition($type) {
+ /**
+ * Initialise definition
+ *
+ * @param string $type What type of definition to create
+ *
+ * @return HTMLPurifier_CSSDefinition|HTMLPurifier_HTMLDefinition|HTMLPurifier_URIDefinition
+ * @throws HTMLPurifier_Exception
+ */
+ private function initDefinition($type)
+ {
// quick checks failed, let's create the object
if ($type == 'HTML') {
$def = new HTMLPurifier_HTMLDefinition();
@@ -496,35 +633,45 @@ class HTMLPurifier_Config
} elseif ($type == 'URI') {
$def = new HTMLPurifier_URIDefinition();
} else {
- throw new HTMLPurifier_Exception("Definition of $type type not supported");
+ throw new HTMLPurifier_Exception(
+ "Definition of $type type not supported"
+ );
}
$this->definitions[$type] = $def;
return $def;
}
- public function maybeGetRawDefinition($name) {
+ public function maybeGetRawDefinition($name)
+ {
return $this->getDefinition($name, true, true);
}
- public function maybeGetRawHTMLDefinition() {
+ public function maybeGetRawHTMLDefinition()
+ {
return $this->getDefinition('HTML', true, true);
}
- public function maybeGetRawCSSDefinition() {
+ public function maybeGetRawCSSDefinition()
+ {
return $this->getDefinition('CSS', true, true);
}
- public function maybeGetRawURIDefinition() {
+ public function maybeGetRawURIDefinition()
+ {
return $this->getDefinition('URI', true, true);
}
/**
* Loads configuration values from an array with the following structure:
* Namespace.Directive => Value
- * @param $config_array Configuration associative array
+ *
+ * @param array $config_array Configuration associative array
*/
- public function loadArray($config_array) {
- if ($this->isFinalized('Cannot load directives after finalization')) return;
+ public function loadArray($config_array)
+ {
+ if ($this->isFinalized('Cannot load directives after finalization')) {
+ return;
+ }
foreach ($config_array as $key => $value) {
$key = str_replace('_', '.', $key);
if (strpos($key, '.') !== false) {
@@ -532,8 +679,8 @@ class HTMLPurifier_Config
} else {
$namespace = $key;
$namespace_values = $value;
- foreach ($namespace_values as $directive => $value) {
- $this->set($namespace .'.'. $directive, $value);
+ foreach ($namespace_values as $directive => $value2) {
+ $this->set($namespace .'.'. $directive, $value2);
}
}
}
@@ -543,40 +690,55 @@ class HTMLPurifier_Config
* Returns a list of array(namespace, directive) for all directives
* that are allowed in a web-form context as per an allowed
* namespaces/directives list.
- * @param $allowed List of allowed namespaces/directives
- */
- public static function getAllowedDirectivesForForm($allowed, $schema = null) {
+ *
+ * @param array $allowed List of allowed namespaces/directives
+ * @param HTMLPurifier_ConfigSchema $schema Schema to use, if not global copy
+ *
+ * @return array
+ */
+ public static function getAllowedDirectivesForForm($allowed, $schema = null)
+ {
if (!$schema) {
$schema = HTMLPurifier_ConfigSchema::instance();
}
if ($allowed !== true) {
- if (is_string($allowed)) $allowed = array($allowed);
- $allowed_ns = array();
- $allowed_directives = array();
- $blacklisted_directives = array();
- foreach ($allowed as $ns_or_directive) {
- if (strpos($ns_or_directive, '.') !== false) {
- // directive
- if ($ns_or_directive[0] == '-') {
- $blacklisted_directives[substr($ns_or_directive, 1)] = true;
- } else {
- $allowed_directives[$ns_or_directive] = true;
- }
- } else {
- // namespace
- $allowed_ns[$ns_or_directive] = true;
- }
- }
+ if (is_string($allowed)) {
+ $allowed = array($allowed);
+ }
+ $allowed_ns = array();
+ $allowed_directives = array();
+ $blacklisted_directives = array();
+ foreach ($allowed as $ns_or_directive) {
+ if (strpos($ns_or_directive, '.') !== false) {
+ // directive
+ if ($ns_or_directive[0] == '-') {
+ $blacklisted_directives[substr($ns_or_directive, 1)] = true;
+ } else {
+ $allowed_directives[$ns_or_directive] = true;
+ }
+ } else {
+ // namespace
+ $allowed_ns[$ns_or_directive] = true;
+ }
+ }
}
$ret = array();
foreach ($schema->info as $key => $def) {
list($ns, $directive) = explode('.', $key, 2);
if ($allowed !== true) {
- if (isset($blacklisted_directives["$ns.$directive"])) continue;
- if (!isset($allowed_directives["$ns.$directive"]) && !isset($allowed_ns[$ns])) continue;
+ if (isset($blacklisted_directives["$ns.$directive"])) {
+ continue;
+ }
+ if (!isset($allowed_directives["$ns.$directive"]) && !isset($allowed_ns[$ns])) {
+ continue;
+ }
+ }
+ if (isset($def->isAlias)) {
+ continue;
+ }
+ if ($directive == 'DefinitionID' || $directive == 'DefinitionRev') {
+ continue;
}
- if (isset($def->isAlias)) continue;
- if ($directive == 'DefinitionID' || $directive == 'DefinitionRev') continue;
$ret[] = array($ns, $directive);
}
return $ret;
@@ -585,13 +747,17 @@ class HTMLPurifier_Config
/**
* Loads configuration values from $_GET/$_POST that were posted
* via ConfigForm
- * @param $array $_GET or $_POST array to import
- * @param $index Index/name that the config variables are in
- * @param $allowed List of allowed namespaces/directives
- * @param $mq_fix Boolean whether or not to enable magic quotes fix
- * @param $schema Instance of HTMLPurifier_ConfigSchema to use, if not global copy
- */
- public static function loadArrayFromForm($array, $index = false, $allowed = true, $mq_fix = true, $schema = null) {
+ *
+ * @param array $array $_GET or $_POST array to import
+ * @param string|bool $index Index/name that the config variables are in
+ * @param array|bool $allowed List of allowed namespaces/directives
+ * @param bool $mq_fix Boolean whether or not to enable magic quotes fix
+ * @param HTMLPurifier_ConfigSchema $schema Schema to use, if not global copy
+ *
+ * @return mixed
+ */
+ public static function loadArrayFromForm($array, $index = false, $allowed = true, $mq_fix = true, $schema = null)
+ {
$ret = HTMLPurifier_Config::prepareArrayFromForm($array, $index, $allowed, $mq_fix, $schema);
$config = HTMLPurifier_Config::create($ret, $schema);
return $config;
@@ -599,9 +765,14 @@ class HTMLPurifier_Config
/**
* Merges in configuration values from $_GET/$_POST to object. NOT STATIC.
- * @note Same parameters as loadArrayFromForm
- */
- public function mergeArrayFromForm($array, $index = false, $allowed = true, $mq_fix = true) {
+ *
+ * @param array $array $_GET or $_POST array to import
+ * @param string|bool $index Index/name that the config variables are in
+ * @param array|bool $allowed List of allowed namespaces/directives
+ * @param bool $mq_fix Boolean whether or not to enable magic quotes fix
+ */
+ public function mergeArrayFromForm($array, $index = false, $allowed = true, $mq_fix = true)
+ {
$ret = HTMLPurifier_Config::prepareArrayFromForm($array, $index, $allowed, $mq_fix, $this->def);
$this->loadArray($ret);
}
@@ -609,9 +780,20 @@ class HTMLPurifier_Config
/**
* Prepares an array from a form into something usable for the more
* strict parts of HTMLPurifier_Config
- */
- public static function prepareArrayFromForm($array, $index = false, $allowed = true, $mq_fix = true, $schema = null) {
- if ($index !== false) $array = (isset($array[$index]) && is_array($array[$index])) ? $array[$index] : array();
+ *
+ * @param array $array $_GET or $_POST array to import
+ * @param string|bool $index Index/name that the config variables are in
+ * @param array|bool $allowed List of allowed namespaces/directives
+ * @param bool $mq_fix Boolean whether or not to enable magic quotes fix
+ * @param HTMLPurifier_ConfigSchema $schema Schema to use, if not global copy
+ *
+ * @return array
+ */
+ public static function prepareArrayFromForm($array, $index = false, $allowed = true, $mq_fix = true, $schema = null)
+ {
+ if ($index !== false) {
+ $array = (isset($array[$index]) && is_array($array[$index])) ? $array[$index] : array();
+ }
$mq = $mq_fix && function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc();
$allowed = HTMLPurifier_Config::getAllowedDirectivesForForm($allowed, $schema);
@@ -623,7 +805,9 @@ class HTMLPurifier_Config
$ret[$ns][$directive] = null;
continue;
}
- if (!isset($array[$skey])) continue;
+ if (!isset($array[$skey])) {
+ continue;
+ }
$value = $mq ? stripslashes($array[$skey]) : $array[$skey];
$ret[$ns][$directive] = $value;
}
@@ -632,19 +816,27 @@ class HTMLPurifier_Config
/**
* Loads configuration values from an ini file
- * @param $filename Name of ini file
+ *
+ * @param string $filename Name of ini file
*/
- public function loadIni($filename) {
- if ($this->isFinalized('Cannot load directives after finalization')) return;
+ public function loadIni($filename)
+ {
+ if ($this->isFinalized('Cannot load directives after finalization')) {
+ return;
+ }
$array = parse_ini_file($filename, true);
$this->loadArray($array);
}
/**
* Checks whether or not the configuration object is finalized.
- * @param $error String error message, or false for no error
+ *
+ * @param string|bool $error String error message, or false for no error
+ *
+ * @return bool
*/
- public function isFinalized($error = false) {
+ public function isFinalized($error = false)
+ {
if ($this->finalized && $error) {
$this->triggerError($error, E_USER_ERROR);
}
@@ -655,7 +847,8 @@ class HTMLPurifier_Config
* Finalizes configuration only if auto finalize is on and not
* already finalized
*/
- public function autoFinalize() {
+ public function autoFinalize()
+ {
if ($this->autoFinalize) {
$this->finalize();
} else {
@@ -666,7 +859,8 @@ class HTMLPurifier_Config
/**
* Finalizes a configuration object, prohibiting further change
*/
- public function finalize() {
+ public function finalize()
+ {
$this->finalized = true;
$this->parser = null;
}
@@ -674,14 +868,19 @@ class HTMLPurifier_Config
/**
* Produces a nicely formatted error message by supplying the
* stack frame information OUTSIDE of HTMLPurifier_Config.
+ *
+ * @param string $msg An error message
+ * @param int $no An error number
*/
- protected function triggerError($msg, $no) {
+ protected function triggerError($msg, $no)
+ {
// determine previous stack frame
$extra = '';
if ($this->chatty) {
$trace = debug_backtrace();
// zip(tail(trace), trace) -- but PHP is not Haskell har har
for ($i = 0, $c = count($trace); $i < $c - 1; $i++) {
+ // XXX this is not correct on some versions of HTML Purifier
if ($trace[$i + 1]['class'] === 'HTMLPurifier_Config') {
continue;
}
@@ -696,8 +895,11 @@ class HTMLPurifier_Config
/**
* Returns a serialized form of the configuration object that can
* be reconstituted.
+ *
+ * @return string
*/
- public function serialize() {
+ public function serialize()
+ {
$this->getDefinition('HTML');
$this->getDefinition('CSS');
$this->getDefinition('URI');
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema.php b/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema.php
index fadf7a5890ff760342c42d71eda10c9b66563038..bfbb0f92f5d5376d33c46712da67010daf0739e2 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema.php
@@ -3,21 +3,24 @@
/**
* Configuration definition, defines directives and their defaults.
*/
-class HTMLPurifier_ConfigSchema {
-
+class HTMLPurifier_ConfigSchema
+{
/**
* Defaults of the directives and namespaces.
+ * @type array
* @note This shares the exact same structure as HTMLPurifier_Config::$conf
*/
public $defaults = array();
/**
* The default property list. Do not edit this property list.
+ * @type array
*/
public $defaultPlist;
/**
- * Definition of the directives. The structure of this is:
+ * Definition of the directives.
+ * The structure of this is:
*
* array(
* 'Namespace' => array(
@@ -44,22 +47,27 @@ class HTMLPurifier_ConfigSchema {
* This class is friendly with HTMLPurifier_Config. If you need introspection
* about the schema, you're better of using the ConfigSchema_Interchange,
* which uses more memory but has much richer information.
+ * @type array
*/
public $info = array();
/**
* Application-wide singleton
+ * @type HTMLPurifier_ConfigSchema
*/
- static protected $singleton;
+ protected static $singleton;
- public function __construct() {
+ public function __construct()
+ {
$this->defaultPlist = new HTMLPurifier_PropertyList();
}
/**
* Unserializes the default ConfigSchema.
+ * @return HTMLPurifier_ConfigSchema
*/
- public static function makeFromSerial() {
+ public static function makeFromSerial()
+ {
$contents = file_get_contents(HTMLPURIFIER_PREFIX . '/HTMLPurifier/ConfigSchema/schema.ser');
$r = unserialize($contents);
if (!$r) {
@@ -71,8 +79,11 @@ class HTMLPurifier_ConfigSchema {
/**
* Retrieves an instance of the application-wide configuration definition.
+ * @param HTMLPurifier_ConfigSchema $prototype
+ * @return HTMLPurifier_ConfigSchema
*/
- public static function instance($prototype = null) {
+ public static function instance($prototype = null)
+ {
if ($prototype !== null) {
HTMLPurifier_ConfigSchema::$singleton = $prototype;
} elseif (HTMLPurifier_ConfigSchema::$singleton === null || $prototype === true) {
@@ -86,17 +97,19 @@ class HTMLPurifier_ConfigSchema {
* @warning Will fail of directive's namespace is defined.
* @warning This method's signature is slightly different from the legacy
* define() static method! Beware!
- * @param $namespace Namespace the directive is in
- * @param $name Key of directive
- * @param $default Default value of directive
- * @param $type Allowed type of the directive. See
+ * @param string $key Name of directive
+ * @param mixed $default Default value of directive
+ * @param string $type Allowed type of the directive. See
* HTMLPurifier_DirectiveDef::$type for allowed values
- * @param $allow_null Whether or not to allow null values
+ * @param bool $allow_null Whether or not to allow null values
*/
- public function add($key, $default, $type, $allow_null) {
+ public function add($key, $default, $type, $allow_null)
+ {
$obj = new stdclass();
$obj->type = is_int($type) ? $type : HTMLPurifier_VarParser::$types[$type];
- if ($allow_null) $obj->allow_null = true;
+ if ($allow_null) {
+ $obj->allow_null = true;
+ }
$this->info[$key] = $obj;
$this->defaults[$key] = $default;
$this->defaultPlist->set($key, $default);
@@ -107,11 +120,11 @@ class HTMLPurifier_ConfigSchema {
*
* Directive value aliases are convenient for developers because it lets
* them set a directive to several values and get the same result.
- * @param $namespace Directive's namespace
- * @param $name Name of Directive
- * @param $aliases Hash of aliased values to the real alias
+ * @param string $key Name of Directive
+ * @param array $aliases Hash of aliased values to the real alias
*/
- public function addValueAliases($key, $aliases) {
+ public function addValueAliases($key, $aliases)
+ {
if (!isset($this->info[$key]->aliases)) {
$this->info[$key]->aliases = array();
}
@@ -124,22 +137,21 @@ class HTMLPurifier_ConfigSchema {
* Defines a set of allowed values for a directive.
* @warning This is slightly different from the corresponding static
* method definition.
- * @param $namespace Namespace of directive
- * @param $name Name of directive
- * @param $allowed Lookup array of allowed values
+ * @param string $key Name of directive
+ * @param array $allowed Lookup array of allowed values
*/
- public function addAllowedValues($key, $allowed) {
+ public function addAllowedValues($key, $allowed)
+ {
$this->info[$key]->allowed = $allowed;
}
/**
* Defines a directive alias for backwards compatibility
- * @param $namespace
- * @param $name Directive that will be aliased
- * @param $new_namespace
- * @param $new_name Directive that the alias will be to
+ * @param string $key Directive that will be aliased
+ * @param string $new_key Directive that the alias will be to
*/
- public function addAlias($key, $new_key) {
+ public function addAlias($key, $new_key)
+ {
$obj = new stdclass;
$obj->key = $new_key;
$obj->isAlias = true;
@@ -149,7 +161,8 @@ class HTMLPurifier_ConfigSchema {
/**
* Replaces any stdclass that only has the type property with type integer.
*/
- public function postProcess() {
+ public function postProcess()
+ {
foreach ($this->info as $key => $v) {
if (count((array) $v) == 1) {
$this->info[$key] = $v->type;
@@ -158,7 +171,6 @@ class HTMLPurifier_ConfigSchema {
}
}
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/Builder/ConfigSchema.php b/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/Builder/ConfigSchema.php
index c05668a7060398c870e25b19debe75325de84323..d5906cd46dd39ab0343b53cb2a5356f1bbaa39cd 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/Builder/ConfigSchema.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/Builder/ConfigSchema.php
@@ -7,7 +7,12 @@
class HTMLPurifier_ConfigSchema_Builder_ConfigSchema
{
- public function build($interchange) {
+ /**
+ * @param HTMLPurifier_ConfigSchema_Interchange $interchange
+ * @return HTMLPurifier_ConfigSchema
+ */
+ public function build($interchange)
+ {
$schema = new HTMLPurifier_ConfigSchema();
foreach ($interchange->directives as $d) {
$schema->add(
@@ -38,7 +43,6 @@ class HTMLPurifier_ConfigSchema_Builder_ConfigSchema
$schema->postProcess();
return $schema;
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/Builder/Xml.php b/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/Builder/Xml.php
index 244561a3726dc8581ca4e13351f22a261dae29c1..5fa56f7ddb631646eafac30c5039bdc72b8b768a 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/Builder/Xml.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/Builder/Xml.php
@@ -7,10 +7,21 @@
class HTMLPurifier_ConfigSchema_Builder_Xml extends XMLWriter
{
+ /**
+ * @type HTMLPurifier_ConfigSchema_Interchange
+ */
protected $interchange;
+
+ /**
+ * @type string
+ */
private $namespace;
- protected function writeHTMLDiv($html) {
+ /**
+ * @param string $html
+ */
+ protected function writeHTMLDiv($html)
+ {
$this->startElement('div');
$purifier = HTMLPurifier::getInstance();
@@ -21,12 +32,23 @@ class HTMLPurifier_ConfigSchema_Builder_Xml extends XMLWriter
$this->endElement(); // div
}
- protected function export($var) {
- if ($var === array()) return 'array()';
+ /**
+ * @param mixed $var
+ * @return string
+ */
+ protected function export($var)
+ {
+ if ($var === array()) {
+ return 'array()';
+ }
return var_export($var, true);
}
- public function build($interchange) {
+ /**
+ * @param HTMLPurifier_ConfigSchema_Interchange $interchange
+ */
+ public function build($interchange)
+ {
// global access, only use as last resort
$this->interchange = $interchange;
@@ -39,19 +61,26 @@ class HTMLPurifier_ConfigSchema_Builder_Xml extends XMLWriter
$this->buildDirective($directive);
}
- if ($this->namespace) $this->endElement(); // namespace
+ if ($this->namespace) {
+ $this->endElement();
+ } // namespace
$this->endElement(); // configdoc
$this->flush();
}
- public function buildDirective($directive) {
-
+ /**
+ * @param HTMLPurifier_ConfigSchema_Interchange_Directive $directive
+ */
+ public function buildDirective($directive)
+ {
// Kludge, although I suppose having a notion of a "root namespace"
// certainly makes things look nicer when documentation is built.
// Depends on things being sorted.
if (!$this->namespace || $this->namespace !== $directive->id->getRootNamespace()) {
- if ($this->namespace) $this->endElement(); // namespace
+ if ($this->namespace) {
+ $this->endElement();
+ } // namespace
$this->namespace = $directive->id->getRootNamespace();
$this->startElement('namespace');
$this->writeAttribute('id', $this->namespace);
@@ -64,43 +93,52 @@ class HTMLPurifier_ConfigSchema_Builder_Xml extends XMLWriter
$this->writeElement('name', $directive->id->getDirective());
$this->startElement('aliases');
- foreach ($directive->aliases as $alias) $this->writeElement('alias', $alias->toString());
+ foreach ($directive->aliases as $alias) {
+ $this->writeElement('alias', $alias->toString());
+ }
$this->endElement(); // aliases
$this->startElement('constraints');
- if ($directive->version) $this->writeElement('version', $directive->version);
- $this->startElement('type');
- if ($directive->typeAllowsNull) $this->writeAttribute('allow-null', 'yes');
- $this->text($directive->type);
- $this->endElement(); // type
- if ($directive->allowed) {
- $this->startElement('allowed');
- foreach ($directive->allowed as $value => $x) $this->writeElement('value', $value);
- $this->endElement(); // allowed
+ if ($directive->version) {
+ $this->writeElement('version', $directive->version);
+ }
+ $this->startElement('type');
+ if ($directive->typeAllowsNull) {
+ $this->writeAttribute('allow-null', 'yes');
+ }
+ $this->text($directive->type);
+ $this->endElement(); // type
+ if ($directive->allowed) {
+ $this->startElement('allowed');
+ foreach ($directive->allowed as $value => $x) {
+ $this->writeElement('value', $value);
}
- $this->writeElement('default', $this->export($directive->default));
- $this->writeAttribute('xml:space', 'preserve');
- if ($directive->external) {
- $this->startElement('external');
- foreach ($directive->external as $project) $this->writeElement('project', $project);
- $this->endElement();
+ $this->endElement(); // allowed
+ }
+ $this->writeElement('default', $this->export($directive->default));
+ $this->writeAttribute('xml:space', 'preserve');
+ if ($directive->external) {
+ $this->startElement('external');
+ foreach ($directive->external as $project) {
+ $this->writeElement('project', $project);
}
+ $this->endElement();
+ }
$this->endElement(); // constraints
if ($directive->deprecatedVersion) {
$this->startElement('deprecated');
- $this->writeElement('version', $directive->deprecatedVersion);
- $this->writeElement('use', $directive->deprecatedUse->toString());
+ $this->writeElement('version', $directive->deprecatedVersion);
+ $this->writeElement('use', $directive->deprecatedUse->toString());
$this->endElement(); // deprecated
}
$this->startElement('description');
- $this->writeHTMLDiv($directive->description);
+ $this->writeHTMLDiv($directive->description);
$this->endElement(); // description
$this->endElement(); // directive
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/Interchange.php b/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/Interchange.php
index 91a5aa7303f0582dc55cd351d36fe241162ce786..0e08ae8fe7aab91891dc9d3005c0013ef237c823 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/Interchange.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/Interchange.php
@@ -10,18 +10,23 @@ class HTMLPurifier_ConfigSchema_Interchange
/**
* Name of the application this schema is describing.
+ * @type string
*/
public $name;
/**
* Array of Directive ID => array(directive info)
+ * @type HTMLPurifier_ConfigSchema_Interchange_Directive[]
*/
public $directives = array();
/**
* Adds a directive array to $directives
+ * @param HTMLPurifier_ConfigSchema_Interchange_Directive $directive
+ * @throws HTMLPurifier_ConfigSchema_Exception
*/
- public function addDirective($directive) {
+ public function addDirective($directive)
+ {
if (isset($this->directives[$i = $directive->id->toString()])) {
throw new HTMLPurifier_ConfigSchema_Exception("Cannot redefine directive '$i'");
}
@@ -32,11 +37,11 @@ class HTMLPurifier_ConfigSchema_Interchange
* Convenience function to perform standard validation. Throws exception
* on failed validation.
*/
- public function validate() {
+ public function validate()
+ {
$validator = new HTMLPurifier_ConfigSchema_Validator();
return $validator->validate($this);
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/Interchange/Directive.php b/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/Interchange/Directive.php
index ac8be0d9707d5f33b9012a40641411f25b0b5d2d..127a39a673e6ccabf2073180cc3f9aede1330061 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/Interchange/Directive.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/Interchange/Directive.php
@@ -7,71 +7,83 @@ class HTMLPurifier_ConfigSchema_Interchange_Directive
{
/**
- * ID of directive, instance of HTMLPurifier_ConfigSchema_Interchange_Id.
+ * ID of directive.
+ * @type HTMLPurifier_ConfigSchema_Interchange_Id
*/
public $id;
/**
- * String type, e.g. 'integer' or 'istring'.
+ * Type, e.g. 'integer' or 'istring'.
+ * @type string
*/
public $type;
/**
* Default value, e.g. 3 or 'DefaultVal'.
+ * @type mixed
*/
public $default;
/**
* HTML description.
+ * @type string
*/
public $description;
/**
- * Boolean whether or not null is allowed as a value.
+ * Whether or not null is allowed as a value.
+ * @type bool
*/
public $typeAllowsNull = false;
/**
- * Lookup table of allowed scalar values, e.g. array('allowed' => true).
+ * Lookup table of allowed scalar values.
+ * e.g. array('allowed' => true).
* Null if all values are allowed.
+ * @type array
*/
public $allowed;
/**
- * List of aliases for the directive,
+ * List of aliases for the directive.
* e.g. array(new HTMLPurifier_ConfigSchema_Interchange_Id('Ns', 'Dir'))).
+ * @type HTMLPurifier_ConfigSchema_Interchange_Id[]
*/
public $aliases = array();
/**
* Hash of value aliases, e.g. array('alt' => 'real'). Null if value
* aliasing is disabled (necessary for non-scalar types).
+ * @type array
*/
public $valueAliases;
/**
* Version of HTML Purifier the directive was introduced, e.g. '1.3.1'.
* Null if the directive has always existed.
+ * @type string
*/
public $version;
/**
- * ID of directive that supercedes this old directive, is an instance
- * of HTMLPurifier_ConfigSchema_Interchange_Id. Null if not deprecated.
+ * ID of directive that supercedes this old directive.
+ * Null if not deprecated.
+ * @type HTMLPurifier_ConfigSchema_Interchange_Id
*/
public $deprecatedUse;
/**
* Version of HTML Purifier this directive was deprecated. Null if not
* deprecated.
+ * @type string
*/
public $deprecatedVersion;
/**
* List of external projects this directive depends on, e.g. array('CSSTidy').
+ * @type array
*/
public $external = array();
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/Interchange/Id.php b/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/Interchange/Id.php
index b9b3c6f5cfbdd0819a34579e857f2e724dcb4edc..126f09d957c0406d07cd803328d89d5cc2356c38 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/Interchange/Id.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/Interchange/Id.php
@@ -6,32 +6,53 @@
class HTMLPurifier_ConfigSchema_Interchange_Id
{
+ /**
+ * @type string
+ */
public $key;
- public function __construct($key) {
+ /**
+ * @param string $key
+ */
+ public function __construct($key)
+ {
$this->key = $key;
}
/**
+ * @return string
* @warning This is NOT magic, to ensure that people don't abuse SPL and
* cause problems for PHP 5.0 support.
*/
- public function toString() {
+ public function toString()
+ {
return $this->key;
}
- public function getRootNamespace() {
+ /**
+ * @return string
+ */
+ public function getRootNamespace()
+ {
return substr($this->key, 0, strpos($this->key, "."));
}
- public function getDirective() {
+ /**
+ * @return string
+ */
+ public function getDirective()
+ {
return substr($this->key, strpos($this->key, ".") + 1);
}
- public static function make($id) {
+ /**
+ * @param string $id
+ * @return HTMLPurifier_ConfigSchema_Interchange_Id
+ */
+ public static function make($id)
+ {
return new HTMLPurifier_ConfigSchema_Interchange_Id($id);
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/InterchangeBuilder.php b/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/InterchangeBuilder.php
index 785b72ce8e93d151465f293b351a4c9455c0e1d4..655e6dd1b929495be8e3c1bf7b6b9f925e97996f 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/InterchangeBuilder.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/InterchangeBuilder.php
@@ -5,21 +5,39 @@ class HTMLPurifier_ConfigSchema_InterchangeBuilder
/**
* Used for processing DEFAULT, nothing else.
+ * @type HTMLPurifier_VarParser
*/
protected $varParser;
- public function __construct($varParser = null) {
+ /**
+ * @param HTMLPurifier_VarParser $varParser
+ */
+ public function __construct($varParser = null)
+ {
$this->varParser = $varParser ? $varParser : new HTMLPurifier_VarParser_Native();
}
- public static function buildFromDirectory($dir = null) {
- $builder = new HTMLPurifier_ConfigSchema_InterchangeBuilder();
+ /**
+ * @param string $dir
+ * @return HTMLPurifier_ConfigSchema_Interchange
+ */
+ public static function buildFromDirectory($dir = null)
+ {
+ $builder = new HTMLPurifier_ConfigSchema_InterchangeBuilder();
$interchange = new HTMLPurifier_ConfigSchema_Interchange();
return $builder->buildDir($interchange, $dir);
}
- public function buildDir($interchange, $dir = null) {
- if (!$dir) $dir = HTMLPURIFIER_PREFIX . '/HTMLPurifier/ConfigSchema/schema';
+ /**
+ * @param HTMLPurifier_ConfigSchema_Interchange $interchange
+ * @param string $dir
+ * @return HTMLPurifier_ConfigSchema_Interchange
+ */
+ public function buildDir($interchange, $dir = null)
+ {
+ if (!$dir) {
+ $dir = HTMLPURIFIER_PREFIX . '/HTMLPurifier/ConfigSchema/schema';
+ }
if (file_exists($dir . '/info.ini')) {
$info = parse_ini_file($dir . '/info.ini');
$interchange->name = $info['name'];
@@ -39,24 +57,30 @@ class HTMLPurifier_ConfigSchema_InterchangeBuilder
foreach ($files as $file) {
$this->buildFile($interchange, $dir . '/' . $file);
}
-
return $interchange;
}
- public function buildFile($interchange, $file) {
+ /**
+ * @param HTMLPurifier_ConfigSchema_Interchange $interchange
+ * @param string $file
+ */
+ public function buildFile($interchange, $file)
+ {
$parser = new HTMLPurifier_StringHashParser();
$this->build(
$interchange,
- new HTMLPurifier_StringHash( $parser->parseFile($file) )
+ new HTMLPurifier_StringHash($parser->parseFile($file))
);
}
/**
* Builds an interchange object based on a hash.
- * @param $interchange HTMLPurifier_ConfigSchema_Interchange object to build
- * @param $hash HTMLPurifier_ConfigSchema_StringHash source data
+ * @param HTMLPurifier_ConfigSchema_Interchange $interchange HTMLPurifier_ConfigSchema_Interchange object to build
+ * @param HTMLPurifier_StringHash $hash source data
+ * @throws HTMLPurifier_ConfigSchema_Exception
*/
- public function build($interchange, $hash) {
+ public function build($interchange, $hash)
+ {
if (!$hash instanceof HTMLPurifier_StringHash) {
$hash = new HTMLPurifier_StringHash($hash);
}
@@ -75,7 +99,13 @@ class HTMLPurifier_ConfigSchema_InterchangeBuilder
$this->_findUnused($hash);
}
- public function buildDirective($interchange, $hash) {
+ /**
+ * @param HTMLPurifier_ConfigSchema_Interchange $interchange
+ * @param HTMLPurifier_StringHash $hash
+ * @throws HTMLPurifier_ConfigSchema_Exception
+ */
+ public function buildDirective($interchange, $hash)
+ {
$directive = new HTMLPurifier_ConfigSchema_Interchange_Directive();
// These are required elements:
@@ -84,7 +114,9 @@ class HTMLPurifier_ConfigSchema_InterchangeBuilder
if (isset($hash['TYPE'])) {
$type = explode('/', $hash->offsetGet('TYPE'));
- if (isset($type[1])) $directive->typeAllowsNull = true;
+ if (isset($type[1])) {
+ $directive->typeAllowsNull = true;
+ }
$directive->type = $type[0];
} else {
throw new HTMLPurifier_ConfigSchema_Exception("TYPE in directive hash '$id' not defined");
@@ -92,7 +124,11 @@ class HTMLPurifier_ConfigSchema_InterchangeBuilder
if (isset($hash['DEFAULT'])) {
try {
- $directive->default = $this->varParser->parse($hash->offsetGet('DEFAULT'), $directive->type, $directive->typeAllowsNull);
+ $directive->default = $this->varParser->parse(
+ $hash->offsetGet('DEFAULT'),
+ $directive->type,
+ $directive->typeAllowsNull
+ );
} catch (HTMLPurifier_VarParserException $e) {
throw new HTMLPurifier_ConfigSchema_Exception($e->getMessage() . " in DEFAULT in directive hash '$id'");
}
@@ -139,34 +175,45 @@ class HTMLPurifier_ConfigSchema_InterchangeBuilder
/**
* Evaluates an array PHP code string without array() wrapper
+ * @param string $contents
*/
- protected function evalArray($contents) {
- return eval('return array('. $contents .');');
+ protected function evalArray($contents)
+ {
+ return eval('return array(' . $contents . ');');
}
/**
* Converts an array list into a lookup array.
+ * @param array $array
+ * @return array
*/
- protected function lookup($array) {
+ protected function lookup($array)
+ {
$ret = array();
- foreach ($array as $val) $ret[$val] = true;
+ foreach ($array as $val) {
+ $ret[$val] = true;
+ }
return $ret;
}
/**
* Convenience function that creates an HTMLPurifier_ConfigSchema_Interchange_Id
* object based on a string Id.
+ * @param string $id
+ * @return HTMLPurifier_ConfigSchema_Interchange_Id
*/
- protected function id($id) {
+ protected function id($id)
+ {
return HTMLPurifier_ConfigSchema_Interchange_Id::make($id);
}
/**
* Triggers errors for any unused keys passed in the hash; such keys
* may indicate typos, missing values, etc.
- * @param $hash Instance of ConfigSchema_StringHash to check.
+ * @param HTMLPurifier_StringHash $hash Hash to check.
*/
- protected function _findUnused($hash) {
+ protected function _findUnused($hash)
+ {
$accessed = $hash->getAccessed();
foreach ($hash as $k => $v) {
if (!isset($accessed[$k])) {
@@ -174,7 +221,6 @@ class HTMLPurifier_ConfigSchema_InterchangeBuilder
}
}
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/Validator.php b/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/Validator.php
index f374f6a02259f8fae5303d3f794c74b5b6461a99..fb31277889f3a91ce2220f9b1d1d905a0381d8f1 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/Validator.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/Validator.php
@@ -12,36 +12,48 @@ class HTMLPurifier_ConfigSchema_Validator
{
/**
- * Easy to access global objects.
+ * @type HTMLPurifier_ConfigSchema_Interchange
*/
- protected $interchange, $aliases;
+ protected $interchange;
+
+ /**
+ * @type array
+ */
+ protected $aliases;
/**
* Context-stack to provide easy to read error messages.
+ * @type array
*/
protected $context = array();
/**
- * HTMLPurifier_VarParser to test default's type.
+ * to test default's type.
+ * @type HTMLPurifier_VarParser
*/
protected $parser;
- public function __construct() {
+ public function __construct()
+ {
$this->parser = new HTMLPurifier_VarParser();
}
/**
- * Validates a fully-formed interchange object. Throws an
- * HTMLPurifier_ConfigSchema_Exception if there's a problem.
+ * Validates a fully-formed interchange object.
+ * @param HTMLPurifier_ConfigSchema_Interchange $interchange
+ * @return bool
*/
- public function validate($interchange) {
+ public function validate($interchange)
+ {
$this->interchange = $interchange;
$this->aliases = array();
// PHP is a bit lax with integer <=> string conversions in
// arrays, so we don't use the identical !== comparison
foreach ($interchange->directives as $i => $directive) {
$id = $directive->id->toString();
- if ($i != $id) $this->error(false, "Integrity violation: key '$i' does not match internal id '$id'");
+ if ($i != $id) {
+ $this->error(false, "Integrity violation: key '$i' does not match internal id '$id'");
+ }
$this->validateDirective($directive);
}
return true;
@@ -49,8 +61,10 @@ class HTMLPurifier_ConfigSchema_Validator
/**
* Validates a HTMLPurifier_ConfigSchema_Interchange_Id object.
+ * @param HTMLPurifier_ConfigSchema_Interchange_Id $id
*/
- public function validateId($id) {
+ public function validateId($id)
+ {
$id_string = $id->toString();
$this->context[] = "id '$id_string'";
if (!$id instanceof HTMLPurifier_ConfigSchema_Interchange_Id) {
@@ -67,8 +81,10 @@ class HTMLPurifier_ConfigSchema_Validator
/**
* Validates a HTMLPurifier_ConfigSchema_Interchange_Directive object.
+ * @param HTMLPurifier_ConfigSchema_Interchange_Directive $d
*/
- public function validateDirective($d) {
+ public function validateDirective($d)
+ {
$id = $d->id->toString();
$this->context[] = "directive '$id'";
$this->validateId($d->id);
@@ -108,9 +124,13 @@ class HTMLPurifier_ConfigSchema_Validator
/**
* Extra validation if $allowed member variable of
* HTMLPurifier_ConfigSchema_Interchange_Directive is defined.
+ * @param HTMLPurifier_ConfigSchema_Interchange_Directive $d
*/
- public function validateDirectiveAllowed($d) {
- if (is_null($d->allowed)) return;
+ public function validateDirectiveAllowed($d)
+ {
+ if (is_null($d->allowed)) {
+ return;
+ }
$this->with($d, 'allowed')
->assertNotEmpty()
->assertIsLookup(); // handled by InterchangeBuilder
@@ -119,7 +139,9 @@ class HTMLPurifier_ConfigSchema_Validator
}
$this->context[] = 'allowed';
foreach ($d->allowed as $val => $x) {
- if (!is_string($val)) $this->error("value $val", 'must be a string');
+ if (!is_string($val)) {
+ $this->error("value $val", 'must be a string');
+ }
}
array_pop($this->context);
}
@@ -127,15 +149,23 @@ class HTMLPurifier_ConfigSchema_Validator
/**
* Extra validation if $valueAliases member variable of
* HTMLPurifier_ConfigSchema_Interchange_Directive is defined.
+ * @param HTMLPurifier_ConfigSchema_Interchange_Directive $d
*/
- public function validateDirectiveValueAliases($d) {
- if (is_null($d->valueAliases)) return;
+ public function validateDirectiveValueAliases($d)
+ {
+ if (is_null($d->valueAliases)) {
+ return;
+ }
$this->with($d, 'valueAliases')
->assertIsArray(); // handled by InterchangeBuilder
$this->context[] = 'valueAliases';
foreach ($d->valueAliases as $alias => $real) {
- if (!is_string($alias)) $this->error("alias $alias", 'must be a string');
- if (!is_string($real)) $this->error("alias target $real from alias '$alias'", 'must be a string');
+ if (!is_string($alias)) {
+ $this->error("alias $alias", 'must be a string');
+ }
+ if (!is_string($real)) {
+ $this->error("alias target $real from alias '$alias'", 'must be a string');
+ }
if ($alias === $real) {
$this->error("alias '$alias'", "must not be an alias to itself");
}
@@ -155,8 +185,10 @@ class HTMLPurifier_ConfigSchema_Validator
/**
* Extra validation if $aliases member variable of
* HTMLPurifier_ConfigSchema_Interchange_Directive is defined.
+ * @param HTMLPurifier_ConfigSchema_Interchange_Directive $d
*/
- public function validateDirectiveAliases($d) {
+ public function validateDirectiveAliases($d)
+ {
$this->with($d, 'aliases')
->assertIsArray(); // handled by InterchangeBuilder
$this->context[] = 'aliases';
@@ -180,27 +212,37 @@ class HTMLPurifier_ConfigSchema_Validator
/**
* Convenience function for generating HTMLPurifier_ConfigSchema_ValidatorAtom
* for validating simple member variables of objects.
+ * @param $obj
+ * @param $member
+ * @return HTMLPurifier_ConfigSchema_ValidatorAtom
*/
- protected function with($obj, $member) {
+ protected function with($obj, $member)
+ {
return new HTMLPurifier_ConfigSchema_ValidatorAtom($this->getFormattedContext(), $obj, $member);
}
/**
* Emits an error, providing helpful context.
+ * @throws HTMLPurifier_ConfigSchema_Exception
*/
- protected function error($target, $msg) {
- if ($target !== false) $prefix = ucfirst($target) . ' in ' . $this->getFormattedContext();
- else $prefix = ucfirst($this->getFormattedContext());
+ protected function error($target, $msg)
+ {
+ if ($target !== false) {
+ $prefix = ucfirst($target) . ' in ' . $this->getFormattedContext();
+ } else {
+ $prefix = ucfirst($this->getFormattedContext());
+ }
throw new HTMLPurifier_ConfigSchema_Exception(trim($prefix . ' ' . $msg));
}
/**
* Returns a formatted context string.
+ * @return string
*/
- protected function getFormattedContext() {
+ protected function getFormattedContext()
+ {
return implode(' in ', array_reverse($this->context));
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/ValidatorAtom.php b/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/ValidatorAtom.php
index b95aea18cc72f04f6675b92d66d62c8a67efe8f5..c9aa3644af74bdf66c9078f103d4a05569e5cf1f 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/ValidatorAtom.php
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/ValidatorAtom.php
@@ -8,59 +8,123 @@
*/
class HTMLPurifier_ConfigSchema_ValidatorAtom
{
+ /**
+ * @type string
+ */
+ protected $context;
- protected $context, $obj, $member, $contents;
+ /**
+ * @type object
+ */
+ protected $obj;
- public function __construct($context, $obj, $member) {
- $this->context = $context;
- $this->obj = $obj;
- $this->member = $member;
- $this->contents =& $obj->$member;
+ /**
+ * @type string
+ */
+ protected $member;
+
+ /**
+ * @type mixed
+ */
+ protected $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 HTMLPurifier_ConfigSchema_ValidatorAtom
+ */
+ 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 HTMLPurifier_ConfigSchema_ValidatorAtom
+ */
+ 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 HTMLPurifier_ConfigSchema_ValidatorAtom
+ */
+ 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 HTMLPurifier_ConfigSchema_ValidatorAtom
+ */
+ public function assertNotNull()
+ {
+ if ($this->contents === null) {
+ $this->error('must not be null');
+ }
return $this;
}
- public function assertAlnum() {
+ /**
+ * @return HTMLPurifier_ConfigSchema_ValidatorAtom
+ */
+ public function assertAlnum()
+ {
$this->assertIsString();
- if (!ctype_alnum($this->contents)) $this->error('must be alphanumeric');
+ 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 HTMLPurifier_ConfigSchema_ValidatorAtom
+ */
+ public function assertNotEmpty()
+ {
+ if (empty($this->contents)) {
+ $this->error('must not be empty');
+ }
return $this;
}
- public function assertIsLookup() {
+ /**
+ * @return HTMLPurifier_ConfigSchema_ValidatorAtom
+ */
+ public function assertIsLookup()
+ {
$this->assertIsArray();
foreach ($this->contents as $v) {
- if ($v !== true) $this->error('must be a lookup array');
+ if ($v !== true) {
+ $this->error('must be a lookup array');
+ }
}
return $this;
}
- protected function error($msg) {
+ /**
+ * @param string $msg
+ * @throws HTMLPurifier_ConfigSchema_Exception
+ */
+ protected function error($msg)
+ {
throw new HTMLPurifier_ConfigSchema_Exception(ucfirst($this->member) . ' in ' . $this->context . ' ' . $msg);
}
-
}
// vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/schema.ser b/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/schema.ser
index b106bcf798a893df8b98c41068b5fc014d4af770..22ea32185db63b19d525f509ebe431f593e92271 100644
Binary files a/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/schema.ser and b/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/schema.ser differ
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.AllowHostnameUnderscore.txt b/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.AllowHostnameUnderscore.txt
new file mode 100644
index 0000000000000000000000000000000000000000..2c910cc7de87555320ccbfea157cf2e6e0a45d5b
--- /dev/null
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.AllowHostnameUnderscore.txt
@@ -0,0 +1,16 @@
+Core.AllowHostnameUnderscore
+TYPE: bool
+VERSION: 4.6.0
+DEFAULT: false
+--DESCRIPTION--
+
+ By RFC 1123, underscores are not permitted in host names.
+ (This is in contrast to the specification for DNS, RFC
+ 2181, which allows underscores.)
+ However, most browsers do the right thing when faced with
+ an underscore in the host name, and so some poorly written
+ websites are written with the expectation this should work.
+ Setting this parameter to true relaxes our allowed character
+ check so that underscores are permitted.
+
+ This directive disables SGML-style exclusions, e.g. the exclusion of
+ <object> in any descendant of a
+ <pre> tag. Disabling excludes will allow some
+ invalid documents to pass through HTML Purifier, but HTML Purifier
+ will also be less likely to accidentally remove large documents during
+ processing.
+
+--# vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.EscapeInvalidChildren.txt b/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.EscapeInvalidChildren.txt
index 4d5b5055cd31d2f611125f8a0c52aec91ed79eb2..a3881be75cf4b93e584a86214f138b5653c66626 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.EscapeInvalidChildren.txt
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/schema/Core.EscapeInvalidChildren.txt
@@ -2,9 +2,11 @@ Core.EscapeInvalidChildren
TYPE: bool
DEFAULT: false
--DESCRIPTION--
-When true, a child is found that is not allowed in the context of the
+
Warning: this configuration option is no longer does anything as of 4.6.0.
+
+
When true, a child is found that is not allowed in the context of the
parent element will be transformed into text as if it were ASCII. When
false, that element and all internal tags will be dropped, though text will
be preserved. There is no option for dropping the element but preserving
-child nodes.
+child nodes.
+ Whether or not to permit script tags to external scripts in documents.
+ Inline scripting is not allowed, and the script must match an explicit whitelist.
+
+--# vim: et sw=4 sts=4
diff --git a/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.MungeSecretKey.txt b/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.MungeSecretKey.txt
index 0d00f62ea8a41daf20a83e2ce54170035604e200..1e17c1d461c2d6086c0eabf68487e9130762edd6 100644
--- a/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.MungeSecretKey.txt
+++ b/htdocs/lib/htmlpurifier/HTMLPurifier/ConfigSchema/schema/URI.MungeSecretKey.txt
@@ -11,7 +11,7 @@ DEFAULT: NULL
to check if a URI has passed through HTML Purifier with this line:
-