mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-04 13:18:00 +02:00
[3.1.0] More PHP4->PHP5 conversions, notably reference removal of most methods that return objects
- Removed HTMLPurifier_Error - Documentation updates - Removed more copy() methods in favor of clone - HTMLPurifier::getInstance() to HTMLPurifier::instance() - Fix InterchangeBuilder to use HTMLPURIFIER_PREFIX git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1689 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -70,9 +70,10 @@ abstract class HTMLPurifier_AttrDef
|
||||
* @return Created AttrDef object corresponding to $string
|
||||
*/
|
||||
public function make($string) {
|
||||
// default implementation, return flyweight of this object
|
||||
// if overloaded, it is *necessary* for you to clone the
|
||||
// object (usually by instantiating a new copy) and return that
|
||||
// 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
|
||||
// to clone or instantiate new copies. (Instantiation is safer.)
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@@ -42,7 +42,7 @@ class HTMLPurifier_AttrDef_URI extends HTMLPurifier_AttrDef
|
||||
if (!$result) break;
|
||||
|
||||
// chained filtering
|
||||
$uri_def =& $config->getDefinition('URI');
|
||||
$uri_def = $config->getDefinition('URI');
|
||||
$result = $uri_def->filter($uri, $config, $context);
|
||||
if (!$result) break;
|
||||
|
||||
|
@@ -3,7 +3,7 @@
|
||||
/**
|
||||
* Defines allowed child nodes and validates tokens against it.
|
||||
*/
|
||||
class HTMLPurifier_ChildDef
|
||||
abstract class HTMLPurifier_ChildDef
|
||||
{
|
||||
/**
|
||||
* Type of child definition, usually right-most part of class name lowercase.
|
||||
@@ -34,9 +34,7 @@ class HTMLPurifier_ChildDef
|
||||
* @return bool false to remove parent node
|
||||
* @return array of replacement child tokens
|
||||
*/
|
||||
public function validateChildren($tokens_of_children, $config, $context) {
|
||||
trigger_error('Call to abstract function', E_USER_ERROR);
|
||||
}
|
||||
abstract public function validateChildren($tokens_of_children, $config, $context);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -107,7 +107,7 @@ class HTMLPurifier_Config
|
||||
* @return Default HTMLPurifier_Config object.
|
||||
*/
|
||||
public static function createDefault() {
|
||||
$definition =& HTMLPurifier_ConfigSchema::instance();
|
||||
$definition = HTMLPurifier_ConfigSchema::instance();
|
||||
$config = new HTMLPurifier_Config($definition);
|
||||
return $config;
|
||||
}
|
||||
@@ -254,21 +254,21 @@ class HTMLPurifier_Config
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves reference to the HTML definition.
|
||||
* Retrieves object reference to the HTML definition.
|
||||
* @param $raw Return a copy that has not been setup yet. Must be
|
||||
* called before it's been setup, otherwise won't work.
|
||||
*/
|
||||
public function &getHTMLDefinition($raw = false) {
|
||||
$def =& $this->getDefinition('HTML', $raw);
|
||||
return $def; // prevent PHP 4.4.0 from complaining
|
||||
public function getHTMLDefinition($raw = false) {
|
||||
return $this->getDefinition('HTML', $raw);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves reference to the CSS definition
|
||||
* Retrieves object reference to the CSS definition
|
||||
* @param $raw Return a copy that has not been setup yet. Must be
|
||||
* called before it's been setup, otherwise won't work.
|
||||
*/
|
||||
public function &getCSSDefinition($raw = false) {
|
||||
$def =& $this->getDefinition('CSS', $raw);
|
||||
return $def;
|
||||
public function getCSSDefinition($raw = false) {
|
||||
return $this->getDefinition('CSS', $raw);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -276,7 +276,7 @@ class HTMLPurifier_Config
|
||||
* @param $type Type of definition: HTML, CSS, etc
|
||||
* @param $raw Whether or not definition should be returned raw
|
||||
*/
|
||||
public function &getDefinition($type, $raw = false) {
|
||||
public function getDefinition($type, $raw = false) {
|
||||
if (!$this->finalized && $this->autoFinalize) $this->finalize();
|
||||
$factory = HTMLPurifier_DefinitionCacheFactory::instance();
|
||||
$cache = $factory->create($type, $this);
|
||||
@@ -310,17 +310,13 @@ class HTMLPurifier_Config
|
||||
} elseif ($type == 'URI') {
|
||||
$this->definitions[$type] = new HTMLPurifier_URIDefinition();
|
||||
} else {
|
||||
trigger_error("Definition of $type type not supported");
|
||||
$false = false;
|
||||
return $false;
|
||||
throw new HTMLPurifier_Exception("Definition of $type type not supported");
|
||||
}
|
||||
// quick abort if raw
|
||||
if ($raw) {
|
||||
if (is_null($this->get($type, 'DefinitionID'))) {
|
||||
// fatally error out if definition ID not set
|
||||
trigger_error("Cannot retrieve raw version without specifying %$type.DefinitionID", E_USER_ERROR);
|
||||
$false = new HTMLPurifier_Error();
|
||||
return $false;
|
||||
throw new HTMLPurifier_Exception("Cannot retrieve raw version without specifying %$type.DefinitionID");
|
||||
}
|
||||
return $this->definitions[$type];
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@
|
||||
/**
|
||||
* Base class for configuration entity
|
||||
*/
|
||||
class HTMLPurifier_ConfigDef {
|
||||
abstract class HTMLPurifier_ConfigDef {
|
||||
public $class = false;
|
||||
}
|
||||
|
||||
|
@@ -40,7 +40,7 @@ class HTMLPurifier_ConfigSchema {
|
||||
/**
|
||||
* Retrieves an instance of the application-wide configuration definition.
|
||||
*/
|
||||
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) {
|
||||
@@ -104,9 +104,8 @@ class HTMLPurifier_ConfigSchema {
|
||||
* @param $allowed Lookup array of allowed values
|
||||
*/
|
||||
public function addAllowedValues($namespace, $name, $allowed) {
|
||||
$directive =& $this->info[$namespace][$name];
|
||||
$type = $directive->type;
|
||||
$directive->allowed = $allowed;
|
||||
$type = $this->info[$namespace][$name]->type;
|
||||
$this->info[$namespace][$name]->allowed = $allowed;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,21 +129,21 @@ class HTMLPurifier_ConfigSchema {
|
||||
$type = $type_values[0];
|
||||
$modifier = isset($type_values[1]) ? $type_values[1] : false;
|
||||
$allow_null = ($modifier === 'null');
|
||||
$def =& HTMLPurifier_ConfigSchema::instance();
|
||||
$def = HTMLPurifier_ConfigSchema::instance();
|
||||
$def->add($namespace, $name, $default, $type, $allow_null);
|
||||
}
|
||||
|
||||
/** @see HTMLPurifier_ConfigSchema->addNamespace() */
|
||||
public static function defineNamespace($namespace, $description) {
|
||||
HTMLPurifier_ConfigSchema::deprecated(__METHOD__);
|
||||
$def =& HTMLPurifier_ConfigSchema::instance();
|
||||
$def = HTMLPurifier_ConfigSchema::instance();
|
||||
$def->addNamespace($namespace);
|
||||
}
|
||||
|
||||
/** @see HTMLPurifier_ConfigSchema->addValueAliases() */
|
||||
public static function defineValueAliases($namespace, $name, $aliases) {
|
||||
HTMLPurifier_ConfigSchema::deprecated(__METHOD__);
|
||||
$def =& HTMLPurifier_ConfigSchema::instance();
|
||||
$def = HTMLPurifier_ConfigSchema::instance();
|
||||
$def->addValueAliases($namespace, $name, $aliases);
|
||||
}
|
||||
|
||||
@@ -155,14 +154,14 @@ class HTMLPurifier_ConfigSchema {
|
||||
foreach ($allowed_values as $value) {
|
||||
$allowed[$value] = true;
|
||||
}
|
||||
$def =& HTMLPurifier_ConfigSchema::instance();
|
||||
$def = HTMLPurifier_ConfigSchema::instance();
|
||||
$def->addAllowedValues($namespace, $name, $allowed);
|
||||
}
|
||||
|
||||
/** @see HTMLPurifier_ConfigSchema->addAlias() */
|
||||
public static function defineAlias($namespace, $name, $new_namespace, $new_name) {
|
||||
HTMLPurifier_ConfigSchema::deprecated(__METHOD__);
|
||||
$def =& HTMLPurifier_ConfigSchema::instance();
|
||||
$def = HTMLPurifier_ConfigSchema::instance();
|
||||
$def->addAlias($namespace, $name, $new_namespace, $new_name);
|
||||
}
|
||||
|
||||
|
@@ -17,7 +17,7 @@ class HTMLPurifier_ConfigSchema_InterchangeBuilder
|
||||
$builder = new HTMLPurifier_ConfigSchema_InterchangeBuilder();
|
||||
$interchange = new HTMLPurifier_ConfigSchema_Interchange();
|
||||
|
||||
if (!$dir) $dir = dirname(__FILE__) . '/schema/';
|
||||
if (!$dir) $dir = HTMLPURIFIER_PREFIX . '/HTMLPurifier/ConfigSchema/schema/';
|
||||
$info = parse_ini_file($dir . 'info.ini');
|
||||
$interchange->name = $info['name'];
|
||||
|
||||
|
@@ -4,6 +4,8 @@
|
||||
* Registry object that contains information about the current context.
|
||||
* @warning Is a bit buggy when variables are set to null: it thinks
|
||||
* they don't exist! So use false instead, please.
|
||||
* @note Since the variables Context deals with may not be objects,
|
||||
* references are very important here! Do not remove!
|
||||
*/
|
||||
class HTMLPurifier_Context
|
||||
{
|
||||
@@ -16,7 +18,7 @@ class HTMLPurifier_Context
|
||||
/**
|
||||
* Registers a variable into the context.
|
||||
* @param $name String name
|
||||
* @param $ref Variable to be registered
|
||||
* @param $ref Reference to variable to be registered
|
||||
*/
|
||||
public function register($name, &$ref) {
|
||||
if (isset($this->_storage[$name])) {
|
||||
|
@@ -20,7 +20,7 @@ class HTMLPurifier_DefinitionCacheFactory
|
||||
/**
|
||||
* Retrieves an instance of global definition cache factory.
|
||||
*/
|
||||
public static function &instance($prototype = null) {
|
||||
public static function instance($prototype = null) {
|
||||
static $instance;
|
||||
if ($prototype !== null) {
|
||||
$instance = $prototype;
|
||||
@@ -45,7 +45,7 @@ class HTMLPurifier_DefinitionCacheFactory
|
||||
* @param $name Name of definitions handled by cache
|
||||
* @param $config Instance of HTMLPurifier_Config
|
||||
*/
|
||||
public function &create($type, $config) {
|
||||
public function create($type, $config) {
|
||||
$method = $config->get('Cache', 'DefinitionImpl');
|
||||
if ($method === null) {
|
||||
$null = new HTMLPurifier_DefinitionCache_Null($type);
|
||||
|
@@ -21,9 +21,9 @@ class HTMLPurifier_DoctypeRegistry
|
||||
* @param $modules Modules doctype will load
|
||||
* @param $modules_for_modes Modules doctype will load for certain modes
|
||||
* @param $aliases Alias names for doctype
|
||||
* @return Reference to registered doctype (usable for further editing)
|
||||
* @return Editable registered doctype
|
||||
*/
|
||||
public function ®ister($doctype, $xml = true, $modules = array(),
|
||||
public function register($doctype, $xml = true, $modules = array(),
|
||||
$tidy_modules = array(), $aliases = array(), $dtd_public = null, $dtd_system = null
|
||||
) {
|
||||
if (!is_array($modules)) $modules = array($modules);
|
||||
@@ -34,7 +34,7 @@ class HTMLPurifier_DoctypeRegistry
|
||||
$doctype, $xml, $modules, $tidy_modules, $aliases, $dtd_public, $dtd_system
|
||||
);
|
||||
}
|
||||
$this->doctypes[$doctype->name] =& $doctype;
|
||||
$this->doctypes[$doctype->name] = $doctype;
|
||||
$name = $doctype->name;
|
||||
// hookup aliases
|
||||
foreach ($doctype->aliases as $alias) {
|
||||
@@ -51,9 +51,9 @@ class HTMLPurifier_DoctypeRegistry
|
||||
* @note This function resolves aliases
|
||||
* @note When possible, use the more fully-featured make()
|
||||
* @param $doctype Name of doctype
|
||||
* @return Reference to doctype object
|
||||
* @return Editable doctype object
|
||||
*/
|
||||
public function &get($doctype) {
|
||||
public function get($doctype) {
|
||||
if (isset($this->aliases[$doctype])) $doctype = $this->aliases[$doctype];
|
||||
if (!isset($this->doctypes[$doctype])) {
|
||||
trigger_error('Doctype ' . htmlspecialchars($doctype) . ' does not exist', E_USER_ERROR);
|
||||
|
@@ -281,9 +281,15 @@ class HTMLPurifier_Encoder
|
||||
$encoding = $config->get('Core', 'Encoding');
|
||||
if ($encoding === 'utf-8') return $str;
|
||||
if ($iconv && !$config->get('Test', 'ForceNoIconv')) {
|
||||
return @iconv($encoding, 'utf-8//IGNORE', $str);
|
||||
set_error_handler(array('HTMLPurifier_Encoder', 'muteErrorHandler'));
|
||||
$str = iconv($encoding, 'utf-8//IGNORE', $str);
|
||||
restore_error_handler();
|
||||
return $str;
|
||||
} elseif ($encoding === 'iso-8859-1') {
|
||||
return @utf8_encode($str);
|
||||
set_error_handler(array('HTMLPurifier_Encoder', 'muteErrorHandler'));
|
||||
$str = utf8_encode($str);
|
||||
restore_error_handler();
|
||||
return $str;
|
||||
}
|
||||
trigger_error('Encoding not supported', E_USER_ERROR);
|
||||
}
|
||||
@@ -302,9 +308,15 @@ class HTMLPurifier_Encoder
|
||||
$str = HTMLPurifier_Encoder::convertToASCIIDumbLossless($str);
|
||||
}
|
||||
if ($iconv && !$config->get('Test', 'ForceNoIconv')) {
|
||||
return @iconv('utf-8', $encoding . '//IGNORE', $str);
|
||||
set_error_handler(array('HTMLPurifier_Encoder', 'muteErrorHandler'));
|
||||
$str = iconv('utf-8', $encoding . '//IGNORE', $str);
|
||||
restore_error_handler();
|
||||
return $str;
|
||||
} elseif ($encoding === 'iso-8859-1') {
|
||||
return @utf8_decode($str);
|
||||
set_error_handler(array('HTMLPurifier_Encoder', 'muteErrorHandler'));
|
||||
$str = utf8_decode($str);
|
||||
restore_error_handler();
|
||||
return $str;
|
||||
}
|
||||
trigger_error('Encoding not supported', E_USER_ERROR);
|
||||
}
|
||||
|
@@ -1,7 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Return object from functions that signifies error when null doesn't cut it
|
||||
*/
|
||||
class HTMLPurifier_Error {}
|
||||
|
@@ -15,7 +15,7 @@ class HTMLPurifier_ErrorCollector
|
||||
public function __construct($context) {
|
||||
$this->locale =& $context->get('Locale');
|
||||
$this->generator =& $context->get('Generator');
|
||||
$this->context =& $context;
|
||||
$this->context = $context;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -12,19 +12,16 @@ class HTMLPurifier_Generator
|
||||
|
||||
/**
|
||||
* Bool cache of %HTML.XHTML
|
||||
* @private
|
||||
*/
|
||||
private $_xhtml = true;
|
||||
|
||||
/**
|
||||
* Bool cache of %Output.CommentScriptContents
|
||||
* @private
|
||||
*/
|
||||
private $_scriptFix = false;
|
||||
|
||||
/**
|
||||
* Cache of HTMLDefinition
|
||||
* @private
|
||||
*/
|
||||
private $_def;
|
||||
|
||||
|
@@ -95,11 +95,11 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
|
||||
* HTMLPurifier_AttrTypes for details
|
||||
*/
|
||||
public function addAttribute($element_name, $attr_name, $def) {
|
||||
$module =& $this->getAnonymousModule();
|
||||
$module = $this->getAnonymousModule();
|
||||
if (!isset($module->info[$element_name])) {
|
||||
$element =& $module->addBlankElement($element_name);
|
||||
$element = $module->addBlankElement($element_name);
|
||||
} else {
|
||||
$element =& $module->info[$element_name];
|
||||
$element = $module->info[$element_name];
|
||||
}
|
||||
$element->attr[$attr_name] = $def;
|
||||
}
|
||||
@@ -109,11 +109,11 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
|
||||
* @note See HTMLPurifier_HTMLModule::addElement for detailed
|
||||
* parameter and return value descriptions.
|
||||
*/
|
||||
public function &addElement($element_name, $type, $contents, $attr_collections, $attributes) {
|
||||
$module =& $this->getAnonymousModule();
|
||||
public function addElement($element_name, $type, $contents, $attr_collections, $attributes) {
|
||||
$module = $this->getAnonymousModule();
|
||||
// assume that if the user is calling this, the element
|
||||
// is safe. This may not be a good idea
|
||||
$element =& $module->addElement($element_name, $type, $contents, $attr_collections, $attributes);
|
||||
$element = $module->addElement($element_name, $type, $contents, $attr_collections, $attributes);
|
||||
return $element;
|
||||
}
|
||||
|
||||
@@ -123,9 +123,9 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
|
||||
* @note See HTMLPurifier_HTMLModule::addBlankElement for detailed
|
||||
* parameter and return value descriptions.
|
||||
*/
|
||||
public function &addBlankElement($element_name) {
|
||||
$module =& $this->getAnonymousModule();
|
||||
$element =& $module->addBlankElement($element_name);
|
||||
public function addBlankElement($element_name) {
|
||||
$module = $this->getAnonymousModule();
|
||||
$element = $module->addBlankElement($element_name);
|
||||
return $element;
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
|
||||
* bust out advanced features without having to make your own
|
||||
* module.
|
||||
*/
|
||||
public function &getAnonymousModule() {
|
||||
public function getAnonymousModule() {
|
||||
if (!$this->_anonModule) {
|
||||
$this->_anonModule = new HTMLPurifier_HTMLModule();
|
||||
$this->_anonModule->name = 'Anonymous';
|
||||
|
@@ -116,10 +116,10 @@ class HTMLPurifier_HTMLModule
|
||||
* element?
|
||||
* @param $attr What unique attributes does the element define?
|
||||
* @note See ElementDef for in-depth descriptions of these parameters.
|
||||
* @return Reference to created element definition object, so you
|
||||
* @return Created element definition object, so you
|
||||
* can set advanced parameters
|
||||
*/
|
||||
public function &addElement($element, $type, $contents, $attr_includes = array(), $attr = array()) {
|
||||
public function addElement($element, $type, $contents, $attr_includes = array(), $attr = array()) {
|
||||
$this->elements[] = $element;
|
||||
// parse content_model
|
||||
list($content_model_type, $content_model) = $this->parseContents($contents);
|
||||
@@ -140,9 +140,9 @@ class HTMLPurifier_HTMLModule
|
||||
* Convenience function that creates a totally blank, non-standalone
|
||||
* element.
|
||||
* @param $element Name of element to create
|
||||
* @return Reference to created element
|
||||
* @return Created element
|
||||
*/
|
||||
public function &addBlankElement($element) {
|
||||
public function addBlankElement($element) {
|
||||
if (!isset($this->info[$element])) {
|
||||
$this->elements[] = $element;
|
||||
$this->info[$element] = new HTMLPurifier_ElementDef();
|
||||
|
@@ -13,7 +13,7 @@ class HTMLPurifier_HTMLModule_Bdo extends HTMLPurifier_HTMLModule
|
||||
);
|
||||
|
||||
public function __construct() {
|
||||
$bdo =& $this->addElement(
|
||||
$bdo = $this->addElement(
|
||||
'bdo', 'Inline', 'Inline', array('Core', 'Lang'),
|
||||
array(
|
||||
'dir' => 'Enum#ltr,rtl', // required
|
||||
|
@@ -9,7 +9,7 @@ class HTMLPurifier_HTMLModule_Hypertext extends HTMLPurifier_HTMLModule
|
||||
public $name = 'Hypertext';
|
||||
|
||||
public function __construct() {
|
||||
$a =& $this->addElement(
|
||||
$a = $this->addElement(
|
||||
'a', 'Inline', 'Inline', 'Common',
|
||||
array(
|
||||
// 'accesskey' => 'Character',
|
||||
|
@@ -11,7 +11,7 @@ class HTMLPurifier_HTMLModule_Image extends HTMLPurifier_HTMLModule
|
||||
public $name = 'Image';
|
||||
|
||||
public function __construct() {
|
||||
$img =& $this->addElement(
|
||||
$img = $this->addElement(
|
||||
'img', 'Inline', 'Empty', 'Common',
|
||||
array(
|
||||
'alt*' => 'Text',
|
||||
|
@@ -49,40 +49,40 @@ class HTMLPurifier_HTMLModule_Legacy extends HTMLPurifier_HTMLModule
|
||||
|
||||
$align = 'Enum#left,right,center,justify';
|
||||
|
||||
$address =& $this->addBlankElement('address');
|
||||
$address = $this->addBlankElement('address');
|
||||
$address->content_model = 'Inline | #PCDATA | p';
|
||||
$address->content_model_type = 'optional';
|
||||
$address->child = false;
|
||||
|
||||
$blockquote =& $this->addBlankElement('blockquote');
|
||||
$blockquote = $this->addBlankElement('blockquote');
|
||||
$blockquote->content_model = 'Flow | #PCDATA';
|
||||
$blockquote->content_model_type = 'optional';
|
||||
$blockquote->child = false;
|
||||
|
||||
$br =& $this->addBlankElement('br');
|
||||
$br = $this->addBlankElement('br');
|
||||
$br->attr['clear'] = 'Enum#left,all,right,none';
|
||||
|
||||
$caption =& $this->addBlankElement('caption');
|
||||
$caption = $this->addBlankElement('caption');
|
||||
$caption->attr['align'] = 'Enum#top,bottom,left,right';
|
||||
|
||||
$div =& $this->addBlankElement('div');
|
||||
$div = $this->addBlankElement('div');
|
||||
$div->attr['align'] = $align;
|
||||
|
||||
$dl =& $this->addBlankElement('dl');
|
||||
$dl = $this->addBlankElement('dl');
|
||||
$dl->attr['compact'] = 'Bool#compact';
|
||||
|
||||
for ($i = 1; $i <= 6; $i++) {
|
||||
$h =& $this->addBlankElement("h$i");
|
||||
$h = $this->addBlankElement("h$i");
|
||||
$h->attr['align'] = $align;
|
||||
}
|
||||
|
||||
$hr =& $this->addBlankElement('hr');
|
||||
$hr = $this->addBlankElement('hr');
|
||||
$hr->attr['align'] = $align;
|
||||
$hr->attr['noshade'] = 'Bool#noshade';
|
||||
$hr->attr['size'] = 'Pixels';
|
||||
$hr->attr['width'] = 'Length';
|
||||
|
||||
$img =& $this->addBlankElement('img');
|
||||
$img = $this->addBlankElement('img');
|
||||
$img->attr['align'] = 'Enum#top,middle,bottom,left,right';
|
||||
$img->attr['border'] = 'Pixels';
|
||||
$img->attr['hspace'] = 'Pixels';
|
||||
@@ -90,43 +90,43 @@ class HTMLPurifier_HTMLModule_Legacy extends HTMLPurifier_HTMLModule
|
||||
|
||||
// figure out this integer business
|
||||
|
||||
$li =& $this->addBlankElement('li');
|
||||
$li = $this->addBlankElement('li');
|
||||
$li->attr['value'] = new HTMLPurifier_AttrDef_Integer();
|
||||
$li->attr['type'] = 'Enum#s:1,i,I,a,A,disc,square,circle';
|
||||
|
||||
$ol =& $this->addBlankElement('ol');
|
||||
$ol = $this->addBlankElement('ol');
|
||||
$ol->attr['compact'] = 'Bool#compact';
|
||||
$ol->attr['start'] = new HTMLPurifier_AttrDef_Integer();
|
||||
$ol->attr['type'] = 'Enum#s:1,i,I,a,A';
|
||||
|
||||
$p =& $this->addBlankElement('p');
|
||||
$p = $this->addBlankElement('p');
|
||||
$p->attr['align'] = $align;
|
||||
|
||||
$pre =& $this->addBlankElement('pre');
|
||||
$pre = $this->addBlankElement('pre');
|
||||
$pre->attr['width'] = 'Number';
|
||||
|
||||
// script omitted
|
||||
|
||||
$table =& $this->addBlankElement('table');
|
||||
$table = $this->addBlankElement('table');
|
||||
$table->attr['align'] = 'Enum#left,center,right';
|
||||
$table->attr['bgcolor'] = 'Color';
|
||||
|
||||
$tr =& $this->addBlankElement('tr');
|
||||
$tr = $this->addBlankElement('tr');
|
||||
$tr->attr['bgcolor'] = 'Color';
|
||||
|
||||
$th =& $this->addBlankElement('th');
|
||||
$th = $this->addBlankElement('th');
|
||||
$th->attr['bgcolor'] = 'Color';
|
||||
$th->attr['height'] = 'Length';
|
||||
$th->attr['nowrap'] = 'Bool#nowrap';
|
||||
$th->attr['width'] = 'Length';
|
||||
|
||||
$td =& $this->addBlankElement('td');
|
||||
$td = $this->addBlankElement('td');
|
||||
$td->attr['bgcolor'] = 'Color';
|
||||
$td->attr['height'] = 'Length';
|
||||
$td->attr['nowrap'] = 'Bool#nowrap';
|
||||
$td->attr['width'] = 'Length';
|
||||
|
||||
$ul =& $this->addBlankElement('ul');
|
||||
$ul = $this->addBlankElement('ul');
|
||||
$ul->attr['compact'] = 'Bool#compact';
|
||||
$ul->attr['type'] = 'Enum#square,disc,circle';
|
||||
|
||||
|
@@ -15,9 +15,9 @@ class HTMLPurifier_HTMLModule_Ruby extends HTMLPurifier_HTMLModule
|
||||
'Common');
|
||||
$this->addElement('rbc', false, 'Required: rb', 'Common');
|
||||
$this->addElement('rtc', false, 'Required: rt', 'Common');
|
||||
$rb =& $this->addElement('rb', false, 'Inline', 'Common');
|
||||
$rb = $this->addElement('rb', false, 'Inline', 'Common');
|
||||
$rb->excludes = array('ruby' => true);
|
||||
$rt =& $this->addElement('rt', false, 'Inline', 'Common', array('rbspan' => 'Number'));
|
||||
$rt = $this->addElement('rt', false, 'Inline', 'Common', array('rbspan' => 'Number'));
|
||||
$rt->excludes = array('ruby' => true);
|
||||
$this->addElement('rp', false, 'Optional: #PCDATA', 'Common');
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@ class HTMLPurifier_HTMLModule_Target extends HTMLPurifier_HTMLModule
|
||||
public function __construct() {
|
||||
$elements = array('a');
|
||||
foreach ($elements as $name) {
|
||||
$e =& $this->addBlankElement($name);
|
||||
$e = $this->addBlankElement($name);
|
||||
$e->attr = array(
|
||||
'target' => new HTMLPurifier_AttrDef_HTML_FrameTarget()
|
||||
);
|
||||
|
@@ -42,7 +42,7 @@ class HTMLPurifier_HTMLModule_Text extends HTMLPurifier_HTMLModule
|
||||
// Block Phrasal --------------------------------------------------
|
||||
$this->addElement('address', 'Block', 'Inline', 'Common');
|
||||
$this->addElement('blockquote', 'Block', 'Optional: Heading | Block | List', 'Common', array('cite' => 'URI') );
|
||||
$pre =& $this->addElement('pre', 'Block', 'Inline', 'Common');
|
||||
$pre = $this->addElement('pre', 'Block', 'Inline', 'Common');
|
||||
$pre->excludes = $this->makeLookup(
|
||||
'img', 'big', 'small', 'object', 'applet', 'font', 'basefont' );
|
||||
$this->addElement('h1', 'Heading', 'Inline', 'Common');
|
||||
|
@@ -128,14 +128,16 @@ class HTMLPurifier_HTMLModule_Tidy extends HTMLPurifier_HTMLModule
|
||||
if (isset($params['element'])) {
|
||||
$element = $params['element'];
|
||||
if (empty($this->info[$element])) {
|
||||
$e =& $this->addBlankElement($element);
|
||||
$e = $this->addBlankElement($element);
|
||||
} else {
|
||||
$e =& $this->info[$element];
|
||||
$e = $this->info[$element];
|
||||
}
|
||||
} else {
|
||||
$type = "info_$type";
|
||||
$e =& $this;
|
||||
$e = $this;
|
||||
}
|
||||
// PHP does some weird parsing when I do
|
||||
// $e->$type[$attr], so I have to assign a ref.
|
||||
$f =& $e->$type;
|
||||
$f[$attr] = $fix;
|
||||
break;
|
||||
@@ -146,9 +148,9 @@ class HTMLPurifier_HTMLModule_Tidy extends HTMLPurifier_HTMLModule
|
||||
case 'content_model_type':
|
||||
$element = $params['element'];
|
||||
if (empty($this->info[$element])) {
|
||||
$e =& $this->addBlankElement($element);
|
||||
$e = $this->addBlankElement($element);
|
||||
} else {
|
||||
$e =& $this->info[$element];
|
||||
$e = $this->info[$element];
|
||||
}
|
||||
$e->$type = $fix;
|
||||
break;
|
||||
|
@@ -1,5 +1,9 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Represents a language and defines localizable string formatting and
|
||||
* other functions, as well as the localized messages for HTML Purifier.
|
||||
*/
|
||||
class HTMLPurifier_Language
|
||||
{
|
||||
|
||||
@@ -36,7 +40,7 @@ class HTMLPurifier_Language
|
||||
|
||||
public function __construct($config, $context) {
|
||||
$this->config = $config;
|
||||
$this->context =& $context;
|
||||
$this->context = $context;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,7 +126,7 @@ class HTMLPurifier_Language
|
||||
// could be introduced for all types of tokens. This
|
||||
// may need to be factored out into a dedicated class
|
||||
if (!empty($value->attr)) {
|
||||
$stripped_token = $value->copy();
|
||||
$stripped_token = clone $value;
|
||||
$stripped_token->attr = array();
|
||||
$subst['$'.$i.'.Compact'] = $generator->generateFromToken($stripped_token);
|
||||
}
|
||||
|
@@ -53,7 +53,7 @@ class HTMLPurifier_LanguageFactory
|
||||
* @param $prototype Optional prototype to overload sole instance with,
|
||||
* or bool true to reset to default factory.
|
||||
*/
|
||||
public static function &instance($prototype = null) {
|
||||
public static function instance($prototype = null) {
|
||||
static $instance = null;
|
||||
if ($prototype !== null) {
|
||||
$instance = $prototype;
|
||||
|
@@ -11,7 +11,8 @@
|
||||
*
|
||||
* A lexer is HTML-oriented: it might work with XML, but it's not
|
||||
* recommended, as we adhere to a subset of the specification for optimization
|
||||
* reasons.
|
||||
* reasons. This might change in the future. Also, most tokenizers are not
|
||||
* expected to handle DTDs or PIs.
|
||||
*
|
||||
* This class should not be directly instantiated, but you may use create() to
|
||||
* retrieve a default copy of the lexer. Being a supertype, this class
|
||||
@@ -20,7 +21,8 @@
|
||||
*
|
||||
* @note The unit tests will instantiate this class for testing purposes, as
|
||||
* many of the utility functions require a class to be instantiated.
|
||||
* Be careful when porting this class to PHP 5.
|
||||
* This means that, even though this class is not runnable, it will
|
||||
* not be declared abstract.
|
||||
*
|
||||
* @par
|
||||
*
|
||||
@@ -28,18 +30,14 @@
|
||||
* We use tokens rather than create a DOM representation because DOM would:
|
||||
*
|
||||
* @par
|
||||
* -# Require more processing power to create,
|
||||
* -# Require recursion to iterate,
|
||||
* -# Must be compatible with PHP 5's DOM (otherwise duplication),
|
||||
* -# Has the entire document structure (html and body not needed), and
|
||||
* -# Has unknown readability improvement.
|
||||
* -# Require more processing and memory to create,
|
||||
* -# Is not streamable, and
|
||||
* -# Has the entire document structure (html and body not needed).
|
||||
*
|
||||
* @par
|
||||
* What the last item means is that the functions for manipulating tokens are
|
||||
* already fairly compact, and when well-commented, more abstraction may not
|
||||
* be needed.
|
||||
*
|
||||
* @see HTMLPurifier_Token
|
||||
* However, DOM is helpful in that it makes it easy to move around nodes
|
||||
* without a lot of lookaheads to see when a tag is closed. This is a
|
||||
* limitation of the token system and some workarounds would be nice.
|
||||
*/
|
||||
class HTMLPurifier_Lexer
|
||||
{
|
||||
@@ -49,22 +47,16 @@ class HTMLPurifier_Lexer
|
||||
/**
|
||||
* Retrieves or sets the default Lexer as a Prototype Factory.
|
||||
*
|
||||
* Depending on what PHP version you are running, the abstract base
|
||||
* Lexer class will determine which concrete Lexer is best for you:
|
||||
* HTMLPurifier_Lexer_DirectLex for PHP 4, and HTMLPurifier_Lexer_DOMLex
|
||||
* for PHP 5 and beyond. This general rule has a few exceptions to it
|
||||
* involving special features that only DirectLex implements.
|
||||
* By default HTMLPurifier_Lexer_DOMLex will be returned. There are
|
||||
* a few exceptions involving special features that only DirectLex
|
||||
* implements.
|
||||
*
|
||||
* @note The behavior of this class has changed, rather than accepting
|
||||
* a prototype object, it now accepts a configuration object.
|
||||
* To specify your own prototype, set %Core.LexerImpl to it.
|
||||
* This change in behavior de-singletonizes the lexer object.
|
||||
*
|
||||
* @note In PHP4, it is possible to call this factory method from
|
||||
* subclasses, such usage is not recommended and not
|
||||
* forwards-compatible.
|
||||
*
|
||||
* @param $prototype Optional prototype lexer or configuration object
|
||||
* @param $config Instance of HTMLPurifier_Config
|
||||
* @return Concrete lexer.
|
||||
*/
|
||||
public static function create($config) {
|
||||
@@ -96,8 +88,9 @@ class HTMLPurifier_Lexer
|
||||
break;
|
||||
}
|
||||
|
||||
if (version_compare(PHP_VERSION, "5", ">=") && // check for PHP5
|
||||
class_exists('DOMDocument')) { // check for DOM support
|
||||
if (class_exists('DOMDocument')) {
|
||||
// check for DOM support, because, surprisingly enough,
|
||||
// it's *not* part of the core!
|
||||
$lexer = 'DOMLex';
|
||||
} else {
|
||||
$lexer = 'DirectLex';
|
||||
|
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
// OUT OF DATE, NEEDS UPDATING!
|
||||
// USE XMLWRITER!
|
||||
|
||||
class HTMLPurifier_Printer
|
||||
{
|
||||
|
@@ -37,7 +37,7 @@ class HTMLPurifier_TagTransform_Font extends HTMLPurifier_TagTransform
|
||||
public function transform($tag, $config, $context) {
|
||||
|
||||
if ($tag instanceof HTMLPurifier_Token_End) {
|
||||
$new_tag = $tag->copy();
|
||||
$new_tag = clone $tag;
|
||||
$new_tag->name = $this->transform_to;
|
||||
return $new_tag;
|
||||
}
|
||||
@@ -81,7 +81,7 @@ class HTMLPurifier_TagTransform_Font extends HTMLPurifier_TagTransform
|
||||
$prepend_style;
|
||||
}
|
||||
|
||||
$new_tag = $tag->copy();
|
||||
$new_tag = clone $tag;
|
||||
$new_tag->name = $this->transform_to;
|
||||
$new_tag->attr = $attr;
|
||||
|
||||
|
@@ -20,7 +20,7 @@ class HTMLPurifier_TagTransform_Simple extends HTMLPurifier_TagTransform
|
||||
}
|
||||
|
||||
public function transform($tag, $config, $context) {
|
||||
$new_tag = $tag->copy();
|
||||
$new_tag = clone $tag;
|
||||
$new_tag->name = $this->transform_to;
|
||||
if (!is_null($this->style) &&
|
||||
($new_tag instanceof HTMLPurifier_Token_Start || $new_tag instanceof HTMLPurifier_Token_Empty)
|
||||
|
@@ -14,14 +14,6 @@ class HTMLPurifier_Token {
|
||||
*/
|
||||
public $armor = array();
|
||||
|
||||
/**
|
||||
* Copies the tag into a new one (clone substitute).
|
||||
* @return Copied token
|
||||
*/
|
||||
public function copy() {
|
||||
return unserialize(serialize($this));
|
||||
}
|
||||
|
||||
public function __get($n) {
|
||||
if ($n === 'type') {
|
||||
trigger_error('Deprecated type property called; use instanceof', E_USER_NOTICE);
|
||||
|
@@ -1,15 +1,15 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Factory for token generation (PHP 5 only).
|
||||
* Factory for token generation.
|
||||
*
|
||||
* @note Doing some benchmarking indicates that the new operator is much
|
||||
* slower than the clone operator (even discounting the cost of the
|
||||
* constructor). This class is for that optimization. We may want to
|
||||
* consider porting this to PHP 4 by virtue of the fact it makes the code
|
||||
* easier to read. Other then that, there's not much point as we don't
|
||||
* constructor). This class is for that optimization.
|
||||
* Other then that, there's not much point as we don't
|
||||
* maintain parallel HTMLPurifier_Token hierarchies (the main reason why
|
||||
* you'd want to use an abstract factory).
|
||||
* @todo Port DirectLex to use this
|
||||
*/
|
||||
class HTMLPurifier_TokenFactory
|
||||
{
|
||||
|
@@ -26,7 +26,7 @@ abstract class HTMLPurifier_URIFilter
|
||||
|
||||
/**
|
||||
* Filter a URI object
|
||||
* @param &$uri Reference to URI object
|
||||
* @param $uri Reference to URI object variable
|
||||
* @param $config Instance of HTMLPurifier_Config
|
||||
* @param $context Instance of HTMLPurifier_Context
|
||||
* @return bool Whether or not to continue processing: false indicates
|
||||
|
Reference in New Issue
Block a user