93 $parent = $parent ? $parent : $definition->defaultPlist;
95 $this->def = $definition;
116 $ret =
new HTMLPurifier_Config($schema);
147 public function get($key, $a = null) {
149 $this->
triggerError(
"Using deprecated API: use \$config->get('$key.$a') instead", E_USER_WARNING);
153 if (!isset($this->def->info[$key])) {
155 $this->
triggerError(
'Cannot retrieve value of undefined directive ' . htmlspecialchars($key),
159 if (isset($this->def->info[$key]->isAlias)) {
160 $d = $this->def->info[$key];
161 $this->
triggerError(
'Cannot get value from aliased directive, use real name ' .
$d->key,
166 list($ns) = explode(
'.', $key);
167 if ($ns !== $this->lock) {
168 $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);
172 return $this->plist->get($key);
183 $this->
triggerError(
'Cannot retrieve undefined namespace ' . htmlspecialchars($namespace),
199 $batch = $this->
getBatch($namespace);
200 unset($batch[
'DefinitionRev']);
211 if (empty($this->serial)) {
224 foreach ($this->plist->squash() as
$name => $value) {
225 list($ns, $key) = explode(
'.', $name, 2);
226 $ret[$ns][$key] = $value;
236 public function set($key, $value, $a = null) {
237 if (strpos($key,
'.') ===
false) {
241 $key =
"$key.$directive";
242 $this->
triggerError(
"Using deprecated API: use \$config->set('$key', ...) instead", E_USER_NOTICE);
246 if ($this->
isFinalized(
'Cannot set directive after finalization'))
return;
247 if (!isset($this->def->info[$key])) {
248 $this->
triggerError(
'Cannot set undefined directive ' . htmlspecialchars($key) .
' to value',
252 $def = $this->def->info[$key];
254 if (isset(
$def->isAlias)) {
255 if ($this->aliasMode) {
256 $this->
triggerError(
'Double-aliases not allowed, please fix '.
257 'ConfigSchema bug with' . $key, E_USER_ERROR);
260 $this->aliasMode =
true;
261 $this->
set(
$def->key, $value);
262 $this->aliasMode =
false;
263 $this->
triggerError(
"$key is an alias, preferred directive name is {$def->key}", E_USER_NOTICE);
275 $allow_null = isset(
$def->allow_null);
279 $value = $this->parser->parse($value,
$type, $allow_null);
284 if (is_string($value) && is_object(
$def)) {
286 if (isset(
$def->aliases[$value])) {
287 $value =
$def->aliases[$value];
290 if (isset(
$def->allowed) && !isset(
$def->allowed[$value])) {
291 $this->
triggerError(
'Value not supported, valid values are: ' .
296 $this->plist->set($key, $value);
313 foreach ($lookup as
$name => $b) $list[] =
$name;
314 return implode(
', ', $list);
346 $cache = $factory->create(
$type, $this);
350 if (!empty($this->definitions[
$type])) {
351 if (!$this->definitions[$type]->setup) {
352 $this->definitions[
$type]->setup($this);
353 $cache->set($this->definitions[$type], $this);
355 return $this->definitions[
$type];
358 $this->definitions[
$type] = $cache->get($this);
359 if ($this->definitions[$type]) {
361 return $this->definitions[
$type];
364 !empty($this->definitions[
$type]) &&
365 !$this->definitions[$type]->setup
368 return $this->definitions[
$type];
371 if ($type ==
'HTML') {
373 } elseif ($type ==
'CSS') {
375 } elseif ($type ==
'URI') {
382 if (is_null($this->
get($type .
'.DefinitionID'))) {
386 return $this->definitions[
$type];
390 $this->definitions[
$type]->setup($this);
393 $cache->set($this->definitions[$type], $this);
394 return $this->definitions[
$type];
403 if ($this->
isFinalized(
'Cannot load directives after finalization'))
return;
404 foreach ($config_array as $key => $value) {
405 $key = str_replace(
'_',
'.', $key);
406 if (strpos($key,
'.') !==
false) {
407 $this->
set($key, $value);
410 $namespace_values = $value;
411 foreach ($namespace_values as $directive => $value) {
412 $this->
set(
$namespace .
'.'. $directive, $value);
428 if ($allowed !==
true) {
429 if (is_string($allowed)) $allowed = array($allowed);
430 $allowed_ns = array();
431 $allowed_directives = array();
432 $blacklisted_directives = array();
433 foreach ($allowed as $ns_or_directive) {
434 if (strpos($ns_or_directive,
'.') !==
false) {
436 if ($ns_or_directive[0] ==
'-') {
437 $blacklisted_directives[substr($ns_or_directive, 1)] =
true;
439 $allowed_directives[$ns_or_directive] =
true;
443 $allowed_ns[$ns_or_directive] =
true;
448 foreach ($schema->info as $key =>
$def) {
449 list($ns, $directive) = explode(
'.', $key, 2);
450 if ($allowed !==
true) {
451 if (isset($blacklisted_directives[
"$ns.$directive"]))
continue;
452 if (!isset($allowed_directives[
"$ns.$directive"]) && !isset($allowed_ns[$ns]))
continue;
454 if (isset(
$def->isAlias))
continue;
455 if ($directive ==
'DefinitionID' || $directive ==
'DefinitionRev')
continue;
456 $ret[] = array($ns, $directive);
470 public static function loadArrayFromForm($array, $index =
false, $allowed =
true, $mq_fix =
true, $schema = null) {
489 public static function prepareArrayFromForm($array, $index =
false, $allowed =
true, $mq_fix =
true, $schema = null) {
490 if ($index !==
false) $array = (isset($array[$index]) && is_array($array[$index])) ? $array[$index] : array();
491 $mq = $mq_fix && function_exists(
'get_magic_quotes_gpc') && get_magic_quotes_gpc();
495 foreach ($allowed as $key) {
496 list($ns, $directive) = $key;
497 $skey =
"$ns.$directive";
498 if (!empty($array[
"Null_$skey"])) {
499 $ret[$ns][$directive] = null;
502 if (!isset($array[$skey]))
continue;
503 $value = $mq ? stripslashes($array[$skey]) : $array[$skey];
504 $ret[$ns][$directive] = $value;
514 if ($this->
isFinalized(
'Cannot load directives after finalization'))
return;
515 $array = parse_ini_file(
$filename,
true);
524 if ($this->finalized &&
$error) {
538 $this->plist->squash(
true);
546 $this->finalized =
true;
547 unset($this->parser);
557 $backtrace = debug_backtrace();
558 if ($this->chatty && isset($backtrace[1])) {
559 $frame = $backtrace[1];
560 $extra =
" on line {$frame['line']} in file {$frame['file']}";
564 trigger_error($msg . $extra, $no);