2007-06-18 03:05:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once 'HTMLPurifier/Generator.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Error collection class that enables HTML Purifier to report HTML
|
|
|
|
* problems back to the user
|
|
|
|
*/
|
|
|
|
class HTMLPurifier_ErrorCollector
|
|
|
|
{
|
|
|
|
|
|
|
|
var $errors = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends an error message to the collector for later use
|
|
|
|
* @param string Error message text
|
2007-06-24 23:20:35 +00:00
|
|
|
* @param int Error severity, PHP error style (don't use E_USER_)
|
2007-06-18 03:05:18 +00:00
|
|
|
* @param HTMLPurifier_Token Token that caused error
|
|
|
|
* @param array Tokens surrounding the offending token above, use true as placeholder
|
|
|
|
*/
|
2007-06-24 23:20:35 +00:00
|
|
|
function send($msg, $severity, $token, $context_tokens = array(true)) {
|
|
|
|
$this->errors[] = array($msg, $severity, $token, $context_tokens);
|
2007-06-18 03:05:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves raw error data for custom formatter to use
|
|
|
|
* @param List of arrays in format of array(Error message text,
|
|
|
|
* token that caused error, tokens surrounding token)
|
|
|
|
*/
|
|
|
|
function getRaw() {
|
|
|
|
return $this->errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default HTML formatting implementation for error messages
|
|
|
|
* @param $config Configuration array, vital for HTML output nature
|
|
|
|
*/
|
2007-06-24 23:20:35 +00:00
|
|
|
function getHTMLFormatted($config, &$context) {
|
2007-06-18 03:05:18 +00:00
|
|
|
$generator = new HTMLPurifier_Generator();
|
|
|
|
$generator->generateFromTokens(array(), $config, $context); // initialize
|
|
|
|
$ret = array();
|
|
|
|
|
|
|
|
$errors = $this->errors;
|
2007-06-24 23:20:35 +00:00
|
|
|
$locale = $context->get('Locale');
|
2007-06-18 03:05:18 +00:00
|
|
|
|
|
|
|
// sort error array by line
|
|
|
|
if ($config->get('Core', 'MaintainLineNumbers')) {
|
|
|
|
$lines = array();
|
2007-06-24 23:20:35 +00:00
|
|
|
foreach ($errors as $error) $lines[] = $error[2]->line;
|
2007-06-18 03:05:18 +00:00
|
|
|
array_multisort($lines, SORT_ASC, $errors);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($errors as $error) {
|
2007-06-24 23:20:35 +00:00
|
|
|
list($msg, $severity, $token, $context_tokens) = $error;
|
|
|
|
$string = '';
|
|
|
|
$string .= $locale->getErrorName($severity) . ': ';
|
|
|
|
$string .= $generator->escape($msg);
|
|
|
|
if (!empty($token->line)) {
|
|
|
|
$string .= ' at line ' . $token->line;
|
2007-06-18 03:05:18 +00:00
|
|
|
}
|
|
|
|
$string .= ' (<code>';
|
2007-06-24 23:20:35 +00:00
|
|
|
foreach ($context_tokens as $context_token) {
|
|
|
|
if ($context_token !== true) {
|
|
|
|
$string .= $generator->escape($generator->generateFromToken($context_token));
|
2007-06-18 03:05:18 +00:00
|
|
|
} else {
|
2007-06-24 23:20:35 +00:00
|
|
|
$string .= '<strong>' . $generator->escape($generator->generateFromToken($token)) . '</strong>';
|
2007-06-18 03:05:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$string .= '</code>)';
|
|
|
|
$ret[] = $string;
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|