mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-07-31 19:30:21 +02:00
[2.0.1] Revamp error collector scheme: we now have custom mocks and an exchange of responsibilities
- Fix oversight in AutoParagraph dealing with armor. - Order errors with no line number last - Language object now needs $config and $context objects to do parameterized objects - Auto-close notice added - Token constructors accept line numbers git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1245 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -27,36 +27,35 @@ class HTMLPurifier_ErrorCollector
|
||||
* @param $msg string Error message text
|
||||
*/
|
||||
function send($severity, $msg, $args = array()) {
|
||||
if (func_num_args() == 2) {
|
||||
$msg = $this->locale->getMessage($msg);
|
||||
} else {
|
||||
// setup one-based array if necessary
|
||||
if (!is_array($args)) {
|
||||
$args = func_get_args();
|
||||
array_shift($args);
|
||||
unset($args[0]);
|
||||
}
|
||||
$msg = $this->locale->formatMessage($msg, $args);
|
||||
|
||||
if (!is_array($args)) {
|
||||
$args = func_get_args();
|
||||
array_shift($args);
|
||||
unset($args[0]);
|
||||
}
|
||||
|
||||
$token = $this->context->get('CurrentToken', true);
|
||||
$line = $token ? $token->line : $this->context->get('CurrentLine', true);
|
||||
$attr = $this->context->get('CurrentAttr', true);
|
||||
// perform special substitutions
|
||||
// Currently defined: $CurrentToken.Name, $CurrentToken.Serialized,
|
||||
// $CurrentAttr.Name, $CurrentAttr.Value
|
||||
if (strpos($msg, '$') !== false) {
|
||||
$subst = array();
|
||||
if (!is_null($token)) {
|
||||
if (isset($token->name)) $subst['$CurrentToken.Name'] = $token->name;
|
||||
$subst['$CurrentToken.Serialized'] = $this->generator->generateFromToken($token);
|
||||
}
|
||||
if (!is_null($attr)) {
|
||||
$subst['$CurrentAttr.Name'] = $attr;
|
||||
if (isset($token->attr[$attr])) $subst['$CurrentAttr.Value'] = $token->attr[$attr];
|
||||
}
|
||||
if (!empty($subst)) $msg = strtr($msg, $subst);
|
||||
|
||||
// perform special substitutions, also add custom parameters
|
||||
$subst = array();
|
||||
if (!is_null($token)) {
|
||||
$args['CurrentToken'] = $token;
|
||||
}
|
||||
if (!is_null($attr)) {
|
||||
$subst['$CurrentAttr.Name'] = $attr;
|
||||
if (isset($token->attr[$attr])) $subst['$CurrentAttr.Value'] = $token->attr[$attr];
|
||||
}
|
||||
|
||||
if (empty($args)) {
|
||||
$msg = $this->locale->getMessage($msg);
|
||||
} else {
|
||||
$msg = $this->locale->formatMessage($msg, $args);
|
||||
}
|
||||
|
||||
if (!empty($subst)) $msg = strtr($msg, $subst);
|
||||
|
||||
$this->errors[] = array($line, $severity, $msg);
|
||||
}
|
||||
|
||||
@@ -74,8 +73,6 @@ class HTMLPurifier_ErrorCollector
|
||||
* @param $config Configuration array, vital for HTML output nature
|
||||
*/
|
||||
function getHTMLFormatted($config) {
|
||||
$generator = new HTMLPurifier_Generator();
|
||||
$generator->generateFromTokens(array(), $config, $this->context); // initialize
|
||||
$ret = array();
|
||||
|
||||
$errors = $this->errors;
|
||||
@@ -83,20 +80,22 @@ class HTMLPurifier_ErrorCollector
|
||||
// sort error array by line
|
||||
// line numbers are enabled if they aren't explicitly disabled
|
||||
if ($config->get('Core', 'MaintainLineNumbers') !== false) {
|
||||
$lines = array();
|
||||
$has_line = array();
|
||||
$lines = array();
|
||||
$original_order = array();
|
||||
foreach ($errors as $i => $error) {
|
||||
$has_line[] = (int) (bool) $error[0];
|
||||
$lines[] = $error[0];
|
||||
$original_order[] = $i;
|
||||
}
|
||||
array_multisort($lines, SORT_ASC, $original_order, SORT_ASC, $errors);
|
||||
array_multisort($has_line, SORT_DESC, $lines, SORT_ASC, $original_order, SORT_ASC, $errors);
|
||||
}
|
||||
|
||||
foreach ($errors as $error) {
|
||||
list($line, $severity, $msg) = $error;
|
||||
$string = '';
|
||||
$string .= $this->locale->getErrorName($severity) . ': ';
|
||||
$string .= $generator->escape($msg);
|
||||
$string .= $this->generator->escape($msg);
|
||||
if ($line) {
|
||||
// have javascript link generation that causes
|
||||
// textarea to skip to the specified line
|
||||
|
Reference in New Issue
Block a user