2008-01-27 19:59:12 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Takes an array of keys to strings, probably generated by
|
2008-02-24 06:19:28 +00:00
|
|
|
* HTMLPurifier_ConfigSchema_StringHashParser
|
2008-01-27 19:59:12 +00:00
|
|
|
*/
|
2008-02-24 06:19:28 +00:00
|
|
|
class HTMLPurifier_ConfigSchema_StringHashAdapter
|
2008-01-27 19:59:12 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Takes a string hash and calls the appropriate functions in $schema
|
|
|
|
* based on its values.
|
|
|
|
*/
|
|
|
|
public function adapt($hash, $schema) {
|
2008-02-05 01:54:20 +00:00
|
|
|
|
2008-02-24 06:19:28 +00:00
|
|
|
if (! $hash instanceof HTMLPurifier_ConfigSchema_StringHash) {
|
|
|
|
$hash = new HTMLPurifier_ConfigSchema_StringHash($hash);
|
2008-02-05 21:04:00 +00:00
|
|
|
}
|
|
|
|
|
2008-02-05 01:54:20 +00:00
|
|
|
if (!isset($hash['ID'])) {
|
|
|
|
trigger_error('Missing key ID in string hash');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check namespace:
|
|
|
|
if (strpos($hash['ID'], '.') === false) {
|
|
|
|
// This will cause problems if we decide to support nested
|
|
|
|
// namespaces, but for now it's ok.
|
2008-02-07 18:02:18 +00:00
|
|
|
$schema->addNamespace($hash->offsetGet('ID'), $hash->offsetGet('DESCRIPTION'));
|
2008-02-05 21:04:00 +00:00
|
|
|
$this->_findUnused($hash);
|
2008-02-05 01:54:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-07 18:02:18 +00:00
|
|
|
list($ns, $directive) = explode('.', $hash->offsetGet('ID'), 2);
|
2008-02-05 01:54:20 +00:00
|
|
|
|
2008-02-07 17:41:40 +00:00
|
|
|
if (isset($hash['TYPE'], $hash['DEFAULT'], $hash['DESCRIPTION'])) {
|
2008-02-07 18:02:18 +00:00
|
|
|
$type = $hash->offsetGet('TYPE');
|
|
|
|
$raw_default = $hash->offsetGet('DEFAULT');
|
2008-02-05 01:54:20 +00:00
|
|
|
$default = eval("return $raw_default;");
|
2008-02-07 18:02:18 +00:00
|
|
|
$description = $hash->offsetGet('DESCRIPTION');
|
2008-02-05 01:54:20 +00:00
|
|
|
$schema->add($ns, $directive, $default, $type, $description);
|
|
|
|
}
|
|
|
|
|
2008-02-05 21:04:00 +00:00
|
|
|
if (isset($hash['ALLOWED'])) {
|
2008-02-07 18:02:18 +00:00
|
|
|
$raw_allowed = $hash->offsetGet('ALLOWED');
|
2008-02-05 21:04:00 +00:00
|
|
|
$allowed = eval("return array($raw_allowed);");
|
|
|
|
$schema->addAllowedValues($ns, $directive, $allowed);
|
|
|
|
}
|
|
|
|
|
2008-02-07 17:41:40 +00:00
|
|
|
// This must be after ALLOWED
|
|
|
|
if (isset($hash['VALUE-ALIASES'])) {
|
2008-02-07 18:02:18 +00:00
|
|
|
$raw_value_aliases = $hash->offsetGet('VALUE-ALIASES');
|
2008-02-07 17:41:40 +00:00
|
|
|
$value_aliases = eval("return array($raw_value_aliases);");
|
|
|
|
$schema->addValueAliases($ns, $directive, $value_aliases);
|
|
|
|
}
|
|
|
|
|
2008-02-05 21:04:00 +00:00
|
|
|
if (isset($hash['ALIASES'])) {
|
2008-02-10 20:34:39 +00:00
|
|
|
$raw_aliases = trim($hash->offsetGet('ALIASES'));
|
2008-02-05 21:04:00 +00:00
|
|
|
$aliases = preg_split('/\s*,\s*/', $raw_aliases);
|
|
|
|
foreach ($aliases as $alias) {
|
2008-02-07 17:41:40 +00:00
|
|
|
list($alias_ns, $alias_directive) = explode('.', $alias, 2);
|
|
|
|
$schema->addAlias($alias_ns, $alias_directive, $ns, $directive);
|
2008-02-05 21:04:00 +00:00
|
|
|
}
|
|
|
|
}
|
2008-02-05 01:54:20 +00:00
|
|
|
|
2008-02-10 20:34:39 +00:00
|
|
|
// We don't use these yet, but there being used
|
|
|
|
if (isset($hash['VERSION'])) $hash->offsetGet('VERSION');
|
|
|
|
if (isset($hash['DEPRECATED-USE'])) $hash->offsetGet('DEPRECATED-USE');
|
|
|
|
if (isset($hash['DEPRECATED-VERSION'])) $hash->offsetGet('DEPRECATED-VERSION');
|
|
|
|
|
2008-02-05 21:04:00 +00:00
|
|
|
$this->_findUnused($hash);
|
2008-02-05 01:54:20 +00:00
|
|
|
|
2008-01-27 19:59:12 +00:00
|
|
|
}
|
|
|
|
|
2008-02-05 21:04:00 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
protected function _findUnused($hash) {
|
|
|
|
$accessed = $hash->getAccessed();
|
|
|
|
foreach ($hash as $k => $v) {
|
|
|
|
if (!isset($accessed[$k])) {
|
|
|
|
trigger_error("String hash key '$k' not used by adapter", E_USER_NOTICE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-27 19:59:12 +00:00
|
|
|
}
|