mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-06 14:16:32 +02:00
[2.0.1] Implement haphazard error collection for AttrValidator.
- Error collector / Language can take arrays and listify them - AttrValidator takes token by reference - Formatted errors now have their severity <strong> - 100 test-cases! W00t! git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1250 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -78,6 +78,25 @@ class HTMLPurifier_Language
|
||||
return $this->errorNames[$int];
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an array list into a string readable representation
|
||||
*/
|
||||
function listify($array) {
|
||||
$sep = $this->getMessage('Item separator');
|
||||
$sep_last = $this->getMessage('Item separator last');
|
||||
$ret = '';
|
||||
for ($i = 0, $c = count($array); $i < $c; $i++) {
|
||||
if ($i == 0) {
|
||||
} elseif ($i + 1 < $c) {
|
||||
$ret .= $sep;
|
||||
} else {
|
||||
$ret .= $sep_last;
|
||||
}
|
||||
$ret .= $array[$i];
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a localised message with passed parameters
|
||||
* @param $key string identifier of message
|
||||
@@ -94,22 +113,35 @@ class HTMLPurifier_Language
|
||||
$generator = false;
|
||||
foreach ($args as $i => $value) {
|
||||
if (is_object($value)) {
|
||||
// complicated stuff
|
||||
if (!$generator) $generator = $this->context->get('Generator');
|
||||
// assuming it's a token
|
||||
if (isset($value->name)) $subst['$'.$i.'.Name'] = $value->name;
|
||||
if (isset($value->data)) $subst['$'.$i.'.Data'] = $value->data;
|
||||
$subst['$'.$i.'.Compact'] =
|
||||
$subst['$'.$i.'.Serialized'] = $generator->generateFromToken($value);
|
||||
// a more complex algorithm for compact representation
|
||||
// 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->attr = array();
|
||||
$subst['$'.$i.'.Compact'] = $generator->generateFromToken($stripped_token);
|
||||
if (is_a($value, 'HTMLPurifier_Token')) {
|
||||
// factor this out some time
|
||||
if (!$generator) $generator = $this->context->get('Generator');
|
||||
if (isset($value->name)) $subst['$'.$i.'.Name'] = $value->name;
|
||||
if (isset($value->data)) $subst['$'.$i.'.Data'] = $value->data;
|
||||
$subst['$'.$i.'.Compact'] =
|
||||
$subst['$'.$i.'.Serialized'] = $generator->generateFromToken($value);
|
||||
// a more complex algorithm for compact representation
|
||||
// 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->attr = array();
|
||||
$subst['$'.$i.'.Compact'] = $generator->generateFromToken($stripped_token);
|
||||
}
|
||||
$subst['$'.$i.'.Line'] = $value->line ? $value->line : 'unknown';
|
||||
}
|
||||
continue;
|
||||
} elseif (is_array($value)) {
|
||||
$keys = array_keys($value);
|
||||
if (array_keys($keys) === $keys) {
|
||||
// list
|
||||
$subst['$'.$i] = $this->listify($value);
|
||||
} else {
|
||||
// associative array
|
||||
// no $i implementation yet, sorry
|
||||
$subst['$'.$i.'.Keys'] = $this->listify($keys);
|
||||
$subst['$'.$i.'.Values'] = $this->listify(array_values($value));
|
||||
}
|
||||
$subst['$'.$i.'.Line'] = $value->line ? $value->line : 'unknown';
|
||||
continue;
|
||||
}
|
||||
$subst['$' . $i] = $value;
|
||||
|
Reference in New Issue
Block a user