2006-08-11 20:23:41 +00:00
|
|
|
<?php
|
|
|
|
|
2006-08-19 23:06:59 +00:00
|
|
|
/**
|
|
|
|
* Configuration definition, defines directives and their defaults.
|
|
|
|
* @todo Build documentation generation capabilities.
|
|
|
|
*/
|
2006-08-11 20:23:41 +00:00
|
|
|
class HTMLPurifier_ConfigDef {
|
|
|
|
|
2006-08-19 23:06:59 +00:00
|
|
|
/**
|
|
|
|
* Currently defined directives (and namespaces).
|
|
|
|
* @note This shares the exact same structure as HTMLPurifier_Config::$conf
|
|
|
|
*/
|
2006-08-11 20:23:41 +00:00
|
|
|
var $info = array();
|
|
|
|
|
2006-08-19 23:06:59 +00:00
|
|
|
/**
|
|
|
|
* Initializes the default namespaces.
|
|
|
|
*/
|
2006-08-11 20:23:41 +00:00
|
|
|
function initialize() {
|
|
|
|
$this->defineNamespace('Core', 'Core features that are always available.');
|
|
|
|
$this->defineNamespace('Attr', 'Features regarding attribute validation.');
|
2006-08-12 03:35:05 +00:00
|
|
|
$this->defineNamespace('URI', 'Features regarding Uniform Resource Identifiers.');
|
2006-08-11 20:23:41 +00:00
|
|
|
}
|
|
|
|
|
2006-08-19 23:06:59 +00:00
|
|
|
/**
|
|
|
|
* Retrieves an instance of the application-wide configuration definition.
|
|
|
|
*/
|
2006-08-11 20:23:41 +00:00
|
|
|
function &instance($prototype = null) {
|
|
|
|
static $instance;
|
|
|
|
if ($prototype !== null) {
|
|
|
|
$instance = $prototype;
|
|
|
|
} elseif ($instance === null || $prototype === true) {
|
|
|
|
$instance = new HTMLPurifier_ConfigDef();
|
|
|
|
$instance->initialize();
|
|
|
|
}
|
|
|
|
return $instance;
|
|
|
|
}
|
|
|
|
|
2006-08-19 23:06:59 +00:00
|
|
|
/**
|
|
|
|
* Defines a directive for configuration
|
|
|
|
* @warning Will fail of directive's namespace is defined
|
|
|
|
* @todo Collect information on description and allow redefinition
|
|
|
|
* so that multiple files can register a dependency on a
|
|
|
|
* configuration directive.
|
|
|
|
* @param $namespace Namespace the directive is in
|
|
|
|
* @param $name Key of directive
|
|
|
|
* @param $default Default value of directive
|
|
|
|
* @param $description Description of directive for documentation
|
|
|
|
*/
|
2006-08-11 20:23:41 +00:00
|
|
|
function define($namespace, $name, $default, $description) {
|
|
|
|
$def =& HTMLPurifier_ConfigDef::instance();
|
|
|
|
if (!isset($def->info[$namespace])) {
|
|
|
|
trigger_error('Cannot define directive for undefined namespace',
|
|
|
|
E_USER_ERROR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (isset($def->info[$namespace][$name])) {
|
2006-08-12 03:56:27 +00:00
|
|
|
// this behavior is at risk of change
|
2006-08-11 20:23:41 +00:00
|
|
|
trigger_error('Cannot redefine directive', E_USER_ERROR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$def->info[$namespace][$name] = $default;
|
|
|
|
}
|
|
|
|
|
2006-08-19 23:06:59 +00:00
|
|
|
/**
|
|
|
|
* Defines a namespace for directives to be put into.
|
|
|
|
* @param $namespace Namespace's name
|
|
|
|
* @param $description Description of the namespace
|
|
|
|
*/
|
2006-08-11 20:23:41 +00:00
|
|
|
function defineNamespace($namespace, $description) {
|
|
|
|
$def =& HTMLPurifier_ConfigDef::instance();
|
|
|
|
if (isset($def->info[$namespace])) {
|
|
|
|
trigger_error('Cannot redefine namespace', E_USER_ERROR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$def->info[$namespace] = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|