ILIAS  release_4-4 Revision
HTMLPurifier_Config Class Reference

Configuration object that triggers customizable behavior. More...

+ Collaboration diagram for HTMLPurifier_Config:

Public Member Functions

 __construct ($definition, $parent=null)
 
 get ($key, $a=null)
 Retreives a value from the configuration. More...
 
 getBatch ($namespace)
 Retreives an array of directives to values from a given namespace. More...
 
 getBatchSerial ($namespace)
 Returns a SHA-1 signature of a segment of the configuration object that uniquely identifies that particular configuration. More...
 
 getSerial ()
 Returns a SHA-1 signature for the entire configuration object that uniquely identifies that particular configuration. More...
 
 getAll ()
 Retrieves all directives, organized by namespace. More...
 
 set ($key, $value, $a=null)
 Sets a value to configuration. More...
 
 getHTMLDefinition ($raw=false, $optimized=false)
 Retrieves object reference to the HTML definition. More...
 
 getCSSDefinition ($raw=false, $optimized=false)
 Retrieves object reference to the CSS definition. More...
 
 getURIDefinition ($raw=false, $optimized=false)
 Retrieves object reference to the URI definition. More...
 
 getDefinition ($type, $raw=false, $optimized=false)
 Retrieves a definition. More...
 
 maybeGetRawDefinition ($name)
 
 maybeGetRawHTMLDefinition ()
 
 maybeGetRawCSSDefinition ()
 
 maybeGetRawURIDefinition ()
 
 loadArray ($config_array)
 Loads configuration values from an array with the following structure: Namespace.Directive => Value. More...
 
 mergeArrayFromForm ($array, $index=false, $allowed=true, $mq_fix=true)
 Merges in configuration values from $_GET/$_POST to object. More...
 
 loadIni ($filename)
 Loads configuration values from an ini file. More...
 
 isFinalized ($error=false)
 Checks whether or not the configuration object is finalized. More...
 
 autoFinalize ()
 Finalizes configuration only if auto finalize is on and not already finalized. More...
 
 finalize ()
 Finalizes a configuration object, prohibiting further change. More...
 
 serialize ()
 Returns a serialized form of the configuration object that can be reconstituted. More...
 

Static Public Member Functions

static create ($config, $schema=null)
 Convenience constructor that creates a config object based on a mixed var. More...
 
static inherit (HTMLPurifier_Config $config)
 Creates a new config object that inherits from a previous one. More...
 
static createDefault ()
 Convenience constructor that creates a default configuration object. More...
 
static getAllowedDirectivesForForm ($allowed, $schema=null)
 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. More...
 
static loadArrayFromForm ($array, $index=false, $allowed=true, $mq_fix=true, $schema=null)
 Loads configuration values from $_GET/$_POST that were posted via ConfigForm. More...
 
static prepareArrayFromForm ($array, $index=false, $allowed=true, $mq_fix=true, $schema=null)
 Prepares an array from a form into something usable for the more strict parts of HTMLPurifier_Config. More...
 

Data Fields

 $version = '4.5.0'
 HTML Purifier's version. More...
 
 $autoFinalize = true
 Bool indicator whether or not to automatically finalize the object if a read operation is done. More...
 
 $def
 Reference HTMLPurifier_ConfigSchema for value checking. More...
 
 $chatty = true
 Set to false if you do not want line and file numbers in errors (useful when unit testing). More...
 

Protected Member Functions

 triggerError ($msg, $no)
 Produces a nicely formatted error message by supplying the stack frame information OUTSIDE of HTMLPurifier_Config. More...
 

Protected Attributes

 $serials = array()
 Namespace indexed array of serials for specific namespaces (see getSerial() for more info). More...
 
 $serial
 Serial for entire configuration object. More...
 
 $parser = null
 Parser for variables. More...
 
 $definitions
 Indexed array of definitions. More...
 
 $finalized = false
 Bool indicator whether or not config is finalized. More...
 
 $plist
 Property list containing configuration directives. More...
 

Private Member Functions

 _listify ($lookup)
 Convenience function for error reporting. More...
 
 initDefinition ($type)
 

Private Attributes

 $aliasMode
 Whether or not a set is taking place due to an alias lookup. More...
 
 $lock
 Current lock; only gets to this namespace are allowed. More...
 

Detailed Description

Configuration object that triggers customizable behavior.

Warning
This class is strongly defined: that means that the class will fail if an undefined directive is retrieved or set.
Note
Many classes that could (although many times don't) use the configuration object make it a mandatory parameter. This is because a configuration object should always be forwarded, otherwise, you run the risk of missing a parameter and then being stumped when a configuration directive doesn't work.
Todo:
Reconsider some of the public member variables

Definition at line 17 of file Config.php.

Constructor & Destructor Documentation

◆ __construct()

HTMLPurifier_Config::__construct (   $definition,
  $parent = null 
)
Parameters
$definitionHTMLPurifier_ConfigSchema that defines what directives are allowed.

Definition at line 93 of file Config.php.

93  {
94  $parent = $parent ? $parent : $definition->defaultPlist;
95  $this->plist = new HTMLPurifier_PropertyList($parent);
96  $this->def = $definition; // keep a copy around for checking
97  $this->parser = new HTMLPurifier_VarParser_Flexible();
98  }
Performs safe variable parsing based on types which can be used by users.
Definition: Flexible.php:8
Generic property list implementation.
Definition: PropertyList.php:6

Member Function Documentation

◆ _listify()

HTMLPurifier_Config::_listify (   $lookup)
private

Convenience function for error reporting.

Definition at line 312 of file Config.php.

Referenced by set().

312  {
313  $list = array();
314  foreach ($lookup as $name => $b) $list[] = $name;
315  return implode(', ', $list);
316  }
+ Here is the caller graph for this function:

◆ autoFinalize()

HTMLPurifier_Config::autoFinalize ( )

Finalizes configuration only if auto finalize is on and not already finalized.

Definition at line 658 of file Config.php.

References finalize().

Referenced by get(), getAll(), getBatch(), and getDefinition().

658  {
659  if ($this->autoFinalize) {
660  $this->finalize();
661  } else {
662  $this->plist->squash(true);
663  }
664  }
autoFinalize()
Finalizes configuration only if auto finalize is on and not already finalized.
Definition: Config.php:658
finalize()
Finalizes a configuration object, prohibiting further change.
Definition: Config.php:669
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ create()

static HTMLPurifier_Config::create (   $config,
  $schema = null 
)
static

Convenience constructor that creates a config object based on a mixed var.

Parameters
mixed$configVariable that defines the state of the config object. Can be: a HTMLPurifier_Config() object, an array of directives based on loadArray(), or a string filename of an ini file.
HTMLPurifier_ConfigSchemaSchema object
Returns
Configured HTMLPurifier_Config object

Definition at line 109 of file Config.php.

References $ret, and createDefault().

Referenced by HTMLPurifier\__construct(), loadArrayFromForm(), and HTMLPurifier\purify().

109  {
110  if ($config instanceof HTMLPurifier_Config) {
111  // pass-through
112  return $config;
113  }
114  if (!$schema) {
116  } else {
117  $ret = new HTMLPurifier_Config($schema);
118  }
119  if (is_string($config)) $ret->loadIni($config);
120  elseif (is_array($config)) $ret->loadArray($config);
121  return $ret;
122  }
static createDefault()
Convenience constructor that creates a default configuration object.
Definition: Config.php:138
Configuration object that triggers customizable behavior.
Definition: Config.php:17
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createDefault()

static HTMLPurifier_Config::createDefault ( )
static

Convenience constructor that creates a default configuration object.

Returns
Default HTMLPurifier_Config object.

Definition at line 138 of file Config.php.

References HTMLPurifier_ConfigSchema\instance().

Referenced by create(), ilAssHtmlUserSolutionPurifier\getPurifierConfigInstance(), ilHtmlForumPostPurifier\getPurifierConfigInstance(), HTMLPurifier_URISchemeRegistry\getScheme(), and kses().

138  {
139  $definition = HTMLPurifier_ConfigSchema::instance();
140  $config = new HTMLPurifier_Config($definition);
141  return $config;
142  }
Configuration object that triggers customizable behavior.
Definition: Config.php:17
static instance($prototype=null)
Retrieves an instance of the application-wide configuration definition.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ finalize()

HTMLPurifier_Config::finalize ( )

Finalizes a configuration object, prohibiting further change.

Definition at line 669 of file Config.php.

Referenced by autoFinalize().

669  {
670  $this->finalized = true;
671  $this->parser = null;
672  }
+ Here is the caller graph for this function:

◆ get()

HTMLPurifier_Config::get (   $key,
  $a = null 
)

Retreives a value from the configuration.

Parameters
$keyString key

Definition at line 148 of file Config.php.

References $d, autoFinalize(), and triggerError().

148  {
149  if ($a !== null) {
150  $this->triggerError("Using deprecated API: use \$config->get('$key.$a') instead", E_USER_WARNING);
151  $key = "$key.$a";
152  }
153  if (!$this->finalized) $this->autoFinalize();
154  if (!isset($this->def->info[$key])) {
155  // can't add % due to SimpleTest bug
156  $this->triggerError('Cannot retrieve value of undefined directive ' . htmlspecialchars($key),
157  E_USER_WARNING);
158  return;
159  }
160  if (isset($this->def->info[$key]->isAlias)) {
161  $d = $this->def->info[$key];
162  $this->triggerError('Cannot get value from aliased directive, use real name ' . $d->key,
163  E_USER_ERROR);
164  return;
165  }
166  if ($this->lock) {
167  list($ns) = explode('.', $key);
168  if ($ns !== $this->lock) {
169  $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);
170  return;
171  }
172  }
173  return $this->plist->get($key);
174  }
autoFinalize()
Finalizes configuration only if auto finalize is on and not already finalized.
Definition: Config.php:658
triggerError($msg, $no)
Produces a nicely formatted error message by supplying the stack frame information OUTSIDE of HTMLPur...
Definition: Config.php:678
+ Here is the call graph for this function:

◆ getAll()

HTMLPurifier_Config::getAll ( )

Retrieves all directives, organized by namespace.

Warning
This is a pretty inefficient function, avoid if you can

Definition at line 222 of file Config.php.

References $ret, and autoFinalize().

Referenced by getBatch(), and getSerial().

222  {
223  if (!$this->finalized) $this->autoFinalize();
224  $ret = array();
225  foreach ($this->plist->squash() as $name => $value) {
226  list($ns, $key) = explode('.', $name, 2);
227  $ret[$ns][$key] = $value;
228  }
229  return $ret;
230  }
autoFinalize()
Finalizes configuration only if auto finalize is on and not already finalized.
Definition: Config.php:658
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAllowedDirectivesForForm()

static HTMLPurifier_Config::getAllowedDirectivesForForm (   $allowed,
  $schema = null 
)
static

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.

Parameters
$allowedList of allowed namespaces/directives

Definition at line 548 of file Config.php.

References $def, $ret, and HTMLPurifier_ConfigSchema\instance().

Referenced by prepareArrayFromForm(), and HTMLPurifier_Printer_ConfigForm\render().

548  {
549  if (!$schema) {
551  }
552  if ($allowed !== true) {
553  if (is_string($allowed)) $allowed = array($allowed);
554  $allowed_ns = array();
555  $allowed_directives = array();
556  $blacklisted_directives = array();
557  foreach ($allowed as $ns_or_directive) {
558  if (strpos($ns_or_directive, '.') !== false) {
559  // directive
560  if ($ns_or_directive[0] == '-') {
561  $blacklisted_directives[substr($ns_or_directive, 1)] = true;
562  } else {
563  $allowed_directives[$ns_or_directive] = true;
564  }
565  } else {
566  // namespace
567  $allowed_ns[$ns_or_directive] = true;
568  }
569  }
570  }
571  $ret = array();
572  foreach ($schema->info as $key => $def) {
573  list($ns, $directive) = explode('.', $key, 2);
574  if ($allowed !== true) {
575  if (isset($blacklisted_directives["$ns.$directive"])) continue;
576  if (!isset($allowed_directives["$ns.$directive"]) && !isset($allowed_ns[$ns])) continue;
577  }
578  if (isset($def->isAlias)) continue;
579  if ($directive == 'DefinitionID' || $directive == 'DefinitionRev') continue;
580  $ret[] = array($ns, $directive);
581  }
582  return $ret;
583  }
$def
Reference HTMLPurifier_ConfigSchema for value checking.
Definition: Config.php:54
static instance($prototype=null)
Retrieves an instance of the application-wide configuration definition.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getBatch()

HTMLPurifier_Config::getBatch (   $namespace)

Retreives an array of directives to values from a given namespace.

Parameters
$namespaceString namespace

Definition at line 180 of file Config.php.

References $namespace, autoFinalize(), getAll(), and triggerError().

Referenced by getBatchSerial().

180  {
181  if (!$this->finalized) $this->autoFinalize();
182  $full = $this->getAll();
183  if (!isset($full[$namespace])) {
184  $this->triggerError('Cannot retrieve undefined namespace ' . htmlspecialchars($namespace),
185  E_USER_WARNING);
186  return;
187  }
188  return $full[$namespace];
189  }
if($err=$client->getError()) $namespace
autoFinalize()
Finalizes configuration only if auto finalize is on and not already finalized.
Definition: Config.php:658
triggerError($msg, $no)
Produces a nicely formatted error message by supplying the stack frame information OUTSIDE of HTMLPur...
Definition: Config.php:678
getAll()
Retrieves all directives, organized by namespace.
Definition: Config.php:222
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getBatchSerial()

HTMLPurifier_Config::getBatchSerial (   $namespace)

Returns a SHA-1 signature of a segment of the configuration object that uniquely identifies that particular configuration.

Note
Revision is handled specially and is removed from the batch before processing!
Parameters
$namespaceNamespace to get serial for

Definition at line 198 of file Config.php.

References $namespace, getBatch(), and serialize().

198  {
199  if (empty($this->serials[$namespace])) {
200  $batch = $this->getBatch($namespace);
201  unset($batch['DefinitionRev']);
202  $this->serials[$namespace] = sha1(serialize($batch));
203  }
204  return $this->serials[$namespace];
205  }
if($err=$client->getError()) $namespace
getBatch($namespace)
Retreives an array of directives to values from a given namespace.
Definition: Config.php:180
serialize()
Returns a serialized form of the configuration object that can be reconstituted.
Definition: Config.php:701
+ Here is the call graph for this function:

◆ getCSSDefinition()

HTMLPurifier_Config::getCSSDefinition (   $raw = false,
  $optimized = false 
)

Retrieves object reference to the CSS definition.

Parameters
$rawReturn a copy that has not been setup yet. Must be called before it's been setup, otherwise won't work.
$optimizedIf 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.

Definition at line 344 of file Config.php.

References getDefinition().

344  {
345  return $this->getDefinition('CSS', $raw, $optimized);
346  }
getDefinition($type, $raw=false, $optimized=false)
Retrieves a definition.
Definition: Config.php:376
+ Here is the call graph for this function:

◆ getDefinition()

HTMLPurifier_Config::getDefinition (   $type,
  $raw = false,
  $optimized = false 
)

Retrieves a definition.

Parameters
$typeType of definition: HTML, CSS, etc
$rawWhether or not definition should be returned raw
$optimizedOnly 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 way in order to ensure that caching is done properly. 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."

Definition at line 376 of file Config.php.

References $def, $lock, autoFinalize(), initDefinition(), HTMLPurifier_DefinitionCacheFactory\instance(), and triggerError().

Referenced by getCSSDefinition(), getHTMLDefinition(), getURIDefinition(), maybeGetRawCSSDefinition(), maybeGetRawDefinition(), maybeGetRawHTMLDefinition(), maybeGetRawURIDefinition(), and serialize().

376  {
377  if ($optimized && !$raw) {
378  throw new HTMLPurifier_Exception("Cannot set optimized = true when raw = false");
379  }
380  if (!$this->finalized) $this->autoFinalize();
381  // temporarily suspend locks, so we can handle recursive definition calls
382  $lock = $this->lock;
383  $this->lock = null;
385  $cache = $factory->create($type, $this);
386  $this->lock = $lock;
387  if (!$raw) {
388  // full definition
389  // ---------------
390  // check if definition is in memory
391  if (!empty($this->definitions[$type])) {
392  $def = $this->definitions[$type];
393  // check if the definition is setup
394  if ($def->setup) {
395  return $def;
396  } else {
397  $def->setup($this);
398  if ($def->optimized) $cache->add($def, $this);
399  return $def;
400  }
401  }
402  // check if definition is in cache
403  $def = $cache->get($this);
404  if ($def) {
405  // definition in cache, save to memory and return it
406  $this->definitions[$type] = $def;
407  return $def;
408  }
409  // initialize it
410  $def = $this->initDefinition($type);
411  // set it up
412  $this->lock = $type;
413  $def->setup($this);
414  $this->lock = null;
415  // save in cache
416  $cache->add($def, $this);
417  // return it
418  return $def;
419  } else {
420  // raw definition
421  // --------------
422  // check preconditions
423  $def = null;
424  if ($optimized) {
425  if (is_null($this->get($type . '.DefinitionID'))) {
426  // fatally error out if definition ID not set
427  throw new HTMLPurifier_Exception("Cannot retrieve raw version without specifying %$type.DefinitionID");
428  }
429  }
430  if (!empty($this->definitions[$type])) {
431  $def = $this->definitions[$type];
432  if ($def->setup && !$optimized) {
433  $extra = $this->chatty ? " (try moving this code block earlier in your initialization)" : "";
434  throw new HTMLPurifier_Exception("Cannot retrieve raw definition after it has already been setup" . $extra);
435  }
436  if ($def->optimized === null) {
437  $extra = $this->chatty ? " (try flushing your cache)" : "";
438  throw new HTMLPurifier_Exception("Optimization status of definition is unknown" . $extra);
439  }
440  if ($def->optimized !== $optimized) {
441  $msg = $optimized ? "optimized" : "unoptimized";
442  $extra = $this->chatty ? " (this backtrace is for the first inconsistent call, which was for a $msg raw definition)" : "";
443  throw new HTMLPurifier_Exception("Inconsistent use of optimized and unoptimized raw definition retrievals" . $extra);
444  }
445  }
446  // check if definition was in memory
447  if ($def) {
448  if ($def->setup) {
449  // invariant: $optimized === true (checked above)
450  return null;
451  } else {
452  return $def;
453  }
454  }
455  // if optimized, check if definition was in cache
456  // (because we do the memory check first, this formulation
457  // is prone to cache slamming, but I think
458  // guaranteeing that either /all/ of the raw
459  // setup code or /none/ of it is run is more important.)
460  if ($optimized) {
461  // This code path only gets run once; once we put
462  // something in $definitions (which is guaranteed by the
463  // trailing code), we always short-circuit above.
464  $def = $cache->get($this);
465  if ($def) {
466  // save the full definition for later, but don't
467  // return it yet
468  $this->definitions[$type] = $def;
469  return null;
470  }
471  }
472  // check invariants for creation
473  if (!$optimized) {
474  if (!is_null($this->get($type . '.DefinitionID'))) {
475  if ($this->chatty) {
476  $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 <a href='http://htmlpurifier.org/docs/enduser-customize.html#optimized'>Customize</a> for more details", E_USER_WARNING);
477  } else {
478  $this->triggerError("Useless DefinitionID declaration", E_USER_WARNING);
479  }
480  }
481  }
482  // initialize it
483  $def = $this->initDefinition($type);
484  $def->optimized = $optimized;
485  return $def;
486  }
487  throw new HTMLPurifier_Exception("The impossible happened!");
488  }
$lock
Current lock; only gets to this namespace are allowed.
Definition: Config.php:87
static instance($prototype=null)
Retrieves an instance of global definition cache factory.
autoFinalize()
Finalizes configuration only if auto finalize is on and not already finalized.
Definition: Config.php:658
$def
Reference HTMLPurifier_ConfigSchema for value checking.
Definition: Config.php:54
triggerError($msg, $no)
Produces a nicely formatted error message by supplying the stack frame information OUTSIDE of HTMLPur...
Definition: Config.php:678
initDefinition($type)
Definition: Config.php:490
Global exception class for HTML Purifier; any exceptions we throw are from here.
Definition: Exception.php:7
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getHTMLDefinition()

HTMLPurifier_Config::getHTMLDefinition (   $raw = false,
  $optimized = false 
)

Retrieves object reference to the HTML definition.

Parameters
$rawReturn a copy that has not been setup yet. Must be called before it's been setup, otherwise won't work.
$optimizedIf 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.

Definition at line 329 of file Config.php.

References getDefinition().

329  {
330  return $this->getDefinition('HTML', $raw, $optimized);
331  }
getDefinition($type, $raw=false, $optimized=false)
Retrieves a definition.
Definition: Config.php:376
+ Here is the call graph for this function:

◆ getSerial()

HTMLPurifier_Config::getSerial ( )

Returns a SHA-1 signature for the entire configuration object that uniquely identifies that particular configuration.

Definition at line 211 of file Config.php.

References $serial, getAll(), and serialize().

211  {
212  if (empty($this->serial)) {
213  $this->serial = sha1(serialize($this->getAll()));
214  }
215  return $this->serial;
216  }
$serial
Serial for entire configuration object.
Definition: Config.php:42
getAll()
Retrieves all directives, organized by namespace.
Definition: Config.php:222
serialize()
Returns a serialized form of the configuration object that can be reconstituted.
Definition: Config.php:701
+ Here is the call graph for this function:

◆ getURIDefinition()

HTMLPurifier_Config::getURIDefinition (   $raw = false,
  $optimized = false 
)

Retrieves object reference to the URI definition.

Parameters
$rawReturn a copy that has not been setup yet. Must be called before it's been setup, otherwise won't work.
$optimizedIf 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.

Definition at line 359 of file Config.php.

References getDefinition().

359  {
360  return $this->getDefinition('URI', $raw, $optimized);
361  }
getDefinition($type, $raw=false, $optimized=false)
Retrieves a definition.
Definition: Config.php:376
+ Here is the call graph for this function:

◆ inherit()

static HTMLPurifier_Config::inherit ( HTMLPurifier_Config  $config)
static

Creates a new config object that inherits from a previous one.

Parameters
HTMLPurifier_Config$configConfiguration object to inherit from.
Returns
HTMLPurifier_Config object with $config as its parent.

Definition at line 130 of file Config.php.

130  {
131  return new HTMLPurifier_Config($config->def, $config->plist);
132  }
Configuration object that triggers customizable behavior.
Definition: Config.php:17

◆ initDefinition()

HTMLPurifier_Config::initDefinition (   $type)
private

Definition at line 490 of file Config.php.

References $def.

Referenced by getDefinition().

490  {
491  // quick checks failed, let's create the object
492  if ($type == 'HTML') {
494  } elseif ($type == 'CSS') {
496  } elseif ($type == 'URI') {
498  } else {
499  throw new HTMLPurifier_Exception("Definition of $type type not supported");
500  }
501  $this->definitions[$type] = $def;
502  return $def;
503  }
Definition of the purified HTML that describes allowed children, attributes, and many other things...
$def
Reference HTMLPurifier_ConfigSchema for value checking.
Definition: Config.php:54
Global exception class for HTML Purifier; any exceptions we throw are from here.
Definition: Exception.php:7
Defines allowed CSS attributes and what their values are.
+ Here is the caller graph for this function:

◆ isFinalized()

HTMLPurifier_Config::isFinalized (   $error = false)

Checks whether or not the configuration object is finalized.

Parameters
$errorString error message, or false for no error

Definition at line 647 of file Config.php.

References $finalized, and triggerError().

Referenced by loadArray(), loadIni(), and set().

647  {
648  if ($this->finalized && $error) {
649  $this->triggerError($error, E_USER_ERROR);
650  }
651  return $this->finalized;
652  }
$finalized
Bool indicator whether or not config is finalized.
Definition: Config.php:64
triggerError($msg, $no)
Produces a nicely formatted error message by supplying the stack frame information OUTSIDE of HTMLPur...
Definition: Config.php:678
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadArray()

HTMLPurifier_Config::loadArray (   $config_array)

Loads configuration values from an array with the following structure: Namespace.Directive => Value.

Parameters
$config_arrayConfiguration associative array

Definition at line 526 of file Config.php.

References $namespace, and isFinalized().

Referenced by loadIni(), and mergeArrayFromForm().

526  {
527  if ($this->isFinalized('Cannot load directives after finalization')) return;
528  foreach ($config_array as $key => $value) {
529  $key = str_replace('_', '.', $key);
530  if (strpos($key, '.') !== false) {
531  $this->set($key, $value);
532  } else {
533  $namespace = $key;
534  $namespace_values = $value;
535  foreach ($namespace_values as $directive => $value) {
536  $this->set($namespace .'.'. $directive, $value);
537  }
538  }
539  }
540  }
if($err=$client->getError()) $namespace
isFinalized($error=false)
Checks whether or not the configuration object is finalized.
Definition: Config.php:647
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadArrayFromForm()

static HTMLPurifier_Config::loadArrayFromForm (   $array,
  $index = false,
  $allowed = true,
  $mq_fix = true,
  $schema = null 
)
static

Loads configuration values from $_GET/$_POST that were posted via ConfigForm.

Parameters
$array$_GET or $_POST array to import
$indexIndex/name that the config variables are in
$allowedList of allowed namespaces/directives
$mq_fixBoolean whether or not to enable magic quotes fix
$schemaInstance of HTMLPurifier_ConfigSchema to use, if not global copy

Definition at line 594 of file Config.php.

References $ret, create(), and prepareArrayFromForm().

594  {
595  $ret = HTMLPurifier_Config::prepareArrayFromForm($array, $index, $allowed, $mq_fix, $schema);
596  $config = HTMLPurifier_Config::create($ret, $schema);
597  return $config;
598  }
static prepareArrayFromForm($array, $index=false, $allowed=true, $mq_fix=true, $schema=null)
Prepares an array from a form into something usable for the more strict parts of HTMLPurifier_Config...
Definition: Config.php:613
static create($config, $schema=null)
Convenience constructor that creates a config object based on a mixed var.
Definition: Config.php:109
+ Here is the call graph for this function:

◆ loadIni()

HTMLPurifier_Config::loadIni (   $filename)

Loads configuration values from an ini file.

Parameters
$filenameName of ini file

Definition at line 637 of file Config.php.

References $filename, isFinalized(), and loadArray().

637  {
638  if ($this->isFinalized('Cannot load directives after finalization')) return;
639  $array = parse_ini_file($filename, true);
640  $this->loadArray($array);
641  }
isFinalized($error=false)
Checks whether or not the configuration object is finalized.
Definition: Config.php:647
loadArray($config_array)
Loads configuration values from an array with the following structure: Namespace.Directive => Value...
Definition: Config.php:526
$filename
Definition: buildRTE.php:89
+ Here is the call graph for this function:

◆ maybeGetRawCSSDefinition()

HTMLPurifier_Config::maybeGetRawCSSDefinition ( )

Definition at line 513 of file Config.php.

References getDefinition().

513  {
514  return $this->getDefinition('CSS', true, true);
515  }
getDefinition($type, $raw=false, $optimized=false)
Retrieves a definition.
Definition: Config.php:376
+ Here is the call graph for this function:

◆ maybeGetRawDefinition()

HTMLPurifier_Config::maybeGetRawDefinition (   $name)

Definition at line 505 of file Config.php.

References getDefinition().

505  {
506  return $this->getDefinition($name, true, true);
507  }
getDefinition($type, $raw=false, $optimized=false)
Retrieves a definition.
Definition: Config.php:376
+ Here is the call graph for this function:

◆ maybeGetRawHTMLDefinition()

HTMLPurifier_Config::maybeGetRawHTMLDefinition ( )

Definition at line 509 of file Config.php.

References getDefinition().

509  {
510  return $this->getDefinition('HTML', true, true);
511  }
getDefinition($type, $raw=false, $optimized=false)
Retrieves a definition.
Definition: Config.php:376
+ Here is the call graph for this function:

◆ maybeGetRawURIDefinition()

HTMLPurifier_Config::maybeGetRawURIDefinition ( )

Definition at line 517 of file Config.php.

References getDefinition().

517  {
518  return $this->getDefinition('URI', true, true);
519  }
getDefinition($type, $raw=false, $optimized=false)
Retrieves a definition.
Definition: Config.php:376
+ Here is the call graph for this function:

◆ mergeArrayFromForm()

HTMLPurifier_Config::mergeArrayFromForm (   $array,
  $index = false,
  $allowed = true,
  $mq_fix = true 
)

Merges in configuration values from $_GET/$_POST to object.

NOT STATIC.

Note
Same parameters as loadArrayFromForm

Definition at line 604 of file Config.php.

References $ret, loadArray(), and prepareArrayFromForm().

604  {
605  $ret = HTMLPurifier_Config::prepareArrayFromForm($array, $index, $allowed, $mq_fix, $this->def);
606  $this->loadArray($ret);
607  }
static prepareArrayFromForm($array, $index=false, $allowed=true, $mq_fix=true, $schema=null)
Prepares an array from a form into something usable for the more strict parts of HTMLPurifier_Config...
Definition: Config.php:613
loadArray($config_array)
Loads configuration values from an array with the following structure: Namespace.Directive => Value...
Definition: Config.php:526
+ Here is the call graph for this function:

◆ prepareArrayFromForm()

static HTMLPurifier_Config::prepareArrayFromForm (   $array,
  $index = false,
  $allowed = true,
  $mq_fix = true,
  $schema = null 
)
static

Prepares an array from a form into something usable for the more strict parts of HTMLPurifier_Config.

Definition at line 613 of file Config.php.

References $ret, and getAllowedDirectivesForForm().

Referenced by loadArrayFromForm(), and mergeArrayFromForm().

613  {
614  if ($index !== false) $array = (isset($array[$index]) && is_array($array[$index])) ? $array[$index] : array();
615  $mq = $mq_fix && function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc();
616 
617  $allowed = HTMLPurifier_Config::getAllowedDirectivesForForm($allowed, $schema);
618  $ret = array();
619  foreach ($allowed as $key) {
620  list($ns, $directive) = $key;
621  $skey = "$ns.$directive";
622  if (!empty($array["Null_$skey"])) {
623  $ret[$ns][$directive] = null;
624  continue;
625  }
626  if (!isset($array[$skey])) continue;
627  $value = $mq ? stripslashes($array[$skey]) : $array[$skey];
628  $ret[$ns][$directive] = $value;
629  }
630  return $ret;
631  }
static getAllowedDirectivesForForm($allowed, $schema=null)
Returns a list of array(namespace, directive) for all directives that are allowed in a web-form conte...
Definition: Config.php:548
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serialize()

HTMLPurifier_Config::serialize ( )

Returns a serialized form of the configuration object that can be reconstituted.

Definition at line 701 of file Config.php.

References getDefinition().

Referenced by getBatchSerial(), and getSerial().

701  {
702  $this->getDefinition('HTML');
703  $this->getDefinition('CSS');
704  $this->getDefinition('URI');
705  return serialize($this);
706  }
getDefinition($type, $raw=false, $optimized=false)
Retrieves a definition.
Definition: Config.php:376
serialize()
Returns a serialized form of the configuration object that can be reconstituted.
Definition: Config.php:701
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set()

HTMLPurifier_Config::set (   $key,
  $value,
  $a = null 
)

Sets a value to configuration.

Parameters
$keyString key
$valueMixed value

Definition at line 237 of file Config.php.

References $def, $namespace, _listify(), HTMLPurifier_VarParser\getTypeName(), isFinalized(), and triggerError().

237  {
238  if (strpos($key, '.') === false) {
239  $namespace = $key;
240  $directive = $value;
241  $value = $a;
242  $key = "$key.$directive";
243  $this->triggerError("Using deprecated API: use \$config->set('$key', ...) instead", E_USER_NOTICE);
244  } else {
245  list($namespace) = explode('.', $key);
246  }
247  if ($this->isFinalized('Cannot set directive after finalization')) return;
248  if (!isset($this->def->info[$key])) {
249  $this->triggerError('Cannot set undefined directive ' . htmlspecialchars($key) . ' to value',
250  E_USER_WARNING);
251  return;
252  }
253  $def = $this->def->info[$key];
254 
255  if (isset($def->isAlias)) {
256  if ($this->aliasMode) {
257  $this->triggerError('Double-aliases not allowed, please fix '.
258  'ConfigSchema bug with' . $key, E_USER_ERROR);
259  return;
260  }
261  $this->aliasMode = true;
262  $this->set($def->key, $value);
263  $this->aliasMode = false;
264  $this->triggerError("$key is an alias, preferred directive name is {$def->key}", E_USER_NOTICE);
265  return;
266  }
267 
268  // Raw type might be negative when using the fully optimized form
269  // of stdclass, which indicates allow_null == true
270  $rtype = is_int($def) ? $def : $def->type;
271  if ($rtype < 0) {
272  $type = -$rtype;
273  $allow_null = true;
274  } else {
275  $type = $rtype;
276  $allow_null = isset($def->allow_null);
277  }
278 
279  try {
280  $value = $this->parser->parse($value, $type, $allow_null);
281  } catch (HTMLPurifier_VarParserException $e) {
282  $this->triggerError('Value for ' . $key . ' is of invalid type, should be ' . HTMLPurifier_VarParser::getTypeName($type), E_USER_WARNING);
283  return;
284  }
285  if (is_string($value) && is_object($def)) {
286  // resolve value alias if defined
287  if (isset($def->aliases[$value])) {
288  $value = $def->aliases[$value];
289  }
290  // check to see if the value is allowed
291  if (isset($def->allowed) && !isset($def->allowed[$value])) {
292  $this->triggerError('Value not supported, valid values are: ' .
293  $this->_listify($def->allowed), E_USER_WARNING);
294  return;
295  }
296  }
297  $this->plist->set($key, $value);
298 
299  // reset definitions if the directives they depend on changed
300  // this is a very costly process, so it's discouraged
301  // with finalization
302  if ($namespace == 'HTML' || $namespace == 'CSS' || $namespace == 'URI') {
303  $this->definitions[$namespace] = null;
304  }
305 
306  $this->serials[$namespace] = false;
307  }
if($err=$client->getError()) $namespace
isFinalized($error=false)
Checks whether or not the configuration object is finalized.
Definition: Config.php:647
Exception type for HTMLPurifier_VarParser.
_listify($lookup)
Convenience function for error reporting.
Definition: Config.php:312
$def
Reference HTMLPurifier_ConfigSchema for value checking.
Definition: Config.php:54
triggerError($msg, $no)
Produces a nicely formatted error message by supplying the stack frame information OUTSIDE of HTMLPur...
Definition: Config.php:678
static getTypeName($type)
Definition: VarParser.php:142
+ Here is the call graph for this function:

◆ triggerError()

HTMLPurifier_Config::triggerError (   $msg,
  $no 
)
protected

Produces a nicely formatted error message by supplying the stack frame information OUTSIDE of HTMLPurifier_Config.

Definition at line 678 of file Config.php.

Referenced by get(), getBatch(), getDefinition(), isFinalized(), and set().

678  {
679  // determine previous stack frame
680  $extra = '';
681  if ($this->chatty) {
682  $trace = debug_backtrace();
683  // zip(tail(trace), trace) -- but PHP is not Haskell har har
684  for ($i = 0, $c = count($trace); $i < $c - 1; $i++) {
685  // XXX this is not correct on some versions of HTML Purifier
686  if ($trace[$i + 1]['class'] === 'HTMLPurifier_Config') {
687  continue;
688  }
689  $frame = $trace[$i];
690  $extra = " invoked on line {$frame['line']} in file {$frame['file']}";
691  break;
692  }
693  }
694  trigger_error($msg . $extra, $no);
695  }
+ Here is the caller graph for this function:

Field Documentation

◆ $aliasMode

HTMLPurifier_Config::$aliasMode
private

Whether or not a set is taking place due to an alias lookup.

Definition at line 75 of file Config.php.

◆ $autoFinalize

HTMLPurifier_Config::$autoFinalize = true

Bool indicator whether or not to automatically finalize the object if a read operation is done.

Definition at line 29 of file Config.php.

◆ $chatty

HTMLPurifier_Config::$chatty = true

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.

Definition at line 82 of file Config.php.

◆ $def

HTMLPurifier_Config::$def

Reference HTMLPurifier_ConfigSchema for value checking.

Note
This is public for introspective purposes. Please don't abuse!

Definition at line 54 of file Config.php.

Referenced by getAllowedDirectivesForForm(), getDefinition(), initDefinition(), and set().

◆ $definitions

HTMLPurifier_Config::$definitions
protected

Indexed array of definitions.

Definition at line 59 of file Config.php.

◆ $finalized

HTMLPurifier_Config::$finalized = false
protected

Bool indicator whether or not config is finalized.

Definition at line 64 of file Config.php.

Referenced by isFinalized().

◆ $lock

HTMLPurifier_Config::$lock
private

Current lock; only gets to this namespace are allowed.

Definition at line 87 of file Config.php.

Referenced by getDefinition().

◆ $parser

HTMLPurifier_Config::$parser = null
protected

Parser for variables.

Definition at line 47 of file Config.php.

◆ $plist

HTMLPurifier_Config::$plist
protected

Property list containing configuration directives.

Definition at line 69 of file Config.php.

◆ $serial

HTMLPurifier_Config::$serial
protected

Serial for entire configuration object.

Definition at line 42 of file Config.php.

Referenced by getSerial().

◆ $serials

HTMLPurifier_Config::$serials = array()
protected

Namespace indexed array of serials for specific namespaces (see getSerial() for more info).

Definition at line 37 of file Config.php.

◆ $version

HTMLPurifier_Config::$version = '4.5.0'

HTML Purifier's version.

Definition at line 23 of file Config.php.


The documentation for this class was generated from the following file: