ILIAS  release_4-4 Revision
HTMLPurifier_ErrorCollector Class Reference

Error collection class that enables HTML Purifier to report HTML problems back to the user. More...

+ Collaboration diagram for HTMLPurifier_ErrorCollector:

Public Member Functions

 __construct ($context)
 
 send ($severity, $msg)
 Sends an error message to the collector for later use. More...
 
 getRaw ()
 Retrieves raw error data for custom formatter to use. More...
 
 getHTMLFormatted ($config, $errors=null)
 Default HTML formatting implementation for error messages. More...
 

Data Fields

const LINENO = 0
 Identifiers for the returned error array. More...
 
const SEVERITY = 1
 
const MESSAGE = 2
 
const CHILDREN = 3
 

Protected Attributes

 $errors
 
 $_current
 
 $_stacks = array(array())
 
 $locale
 
 $generator
 
 $context
 
 $lines = array()
 

Private Member Functions

 _renderStruct (&$ret, $struct, $line=null, $col=null)
 

Detailed Description

Error collection class that enables HTML Purifier to report HTML problems back to the user.

Definition at line 7 of file ErrorCollector.php.

Constructor & Destructor Documentation

◆ __construct()

HTMLPurifier_ErrorCollector::__construct (   $context)

Definition at line 28 of file ErrorCollector.php.

References $context.

28  {
29  $this->locale =& $context->get('Locale');
30  $this->context = $context;
31  $this->_current =& $this->_stacks[0];
32  $this->errors =& $this->_stacks[0];
33  }

Member Function Documentation

◆ _renderStruct()

HTMLPurifier_ErrorCollector::_renderStruct ( $ret,
  $struct,
  $line = null,
  $col = null 
)
private

Definition at line 171 of file ErrorCollector.php.

References $context, and $ret.

Referenced by getHTMLFormatted().

171  {
172  $stack = array($struct);
173  $context_stack = array(array());
174  while ($current = array_pop($stack)) {
175  $context = array_pop($context_stack);
176  foreach ($current->errors as $error) {
177  list($severity, $msg) = $error;
178  $string = '';
179  $string .= '<div>';
180  // W3C uses an icon to indicate the severity of the error.
181  $error = $this->locale->getErrorName($severity);
182  $string .= "<span class=\"error e$severity\"><strong>$error</strong></span> ";
183  if (!is_null($line) && !is_null($col)) {
184  $string .= "<em class=\"location\">Line $line, Column $col: </em> ";
185  } else {
186  $string .= '<em class="location">End of Document: </em> ';
187  }
188  $string .= '<strong class="description">' . $this->generator->escape($msg) . '</strong> ';
189  $string .= '</div>';
190  // Here, have a marker for the character on the column appropriate.
191  // Be sure to clip extremely long lines.
192  //$string .= '<pre>';
193  //$string .= '';
194  //$string .= '</pre>';
195  $ret[] = $string;
196  }
197  foreach ($current->children as $type => $array) {
198  $context[] = $current;
199  $stack = array_merge($stack, array_reverse($array, true));
200  for ($i = count($array); $i > 0; $i--) {
201  $context_stack[] = $context;
202  }
203  }
204  }
205  }
+ Here is the caller graph for this function:

◆ getHTMLFormatted()

HTMLPurifier_ErrorCollector::getHTMLFormatted (   $config,
  $errors = null 
)

Default HTML formatting implementation for error messages.

Parameters
$configConfiguration array, vital for HTML output nature
$errorsErrors array to display; used for recursion.

Definition at line 144 of file ErrorCollector.php.

References $errors, $ret, and _renderStruct().

144  {
145  $ret = array();
146 
147  $this->generator = new HTMLPurifier_Generator($config, $this->context);
148  if ($errors === null) $errors = $this->errors;
149 
150  // 'At line' message needs to be removed
151 
152  // generation code for new structure goes here. It needs to be recursive.
153  foreach ($this->lines as $line => $col_array) {
154  if ($line == -1) continue;
155  foreach ($col_array as $col => $struct) {
156  $this->_renderStruct($ret, $struct, $line, $col);
157  }
158  }
159  if (isset($this->lines[-1])) {
160  $this->_renderStruct($ret, $this->lines[-1]);
161  }
162 
163  if (empty($errors)) {
164  return '<p>' . $this->locale->getMessage('ErrorCollector: No errors') . '</p>';
165  } else {
166  return '<ul><li>' . implode('</li><li>', $ret) . '</li></ul>';
167  }
168 
169  }
Generates HTML from tokens.
Definition: Generator.php:10
_renderStruct(&$ret, $struct, $line=null, $col=null)
+ Here is the call graph for this function:

◆ getRaw()

HTMLPurifier_ErrorCollector::getRaw ( )

Retrieves raw error data for custom formatter to use.

Parameters
Listof arrays in format of array(line of error, error severity, error message, recursive sub-errors array)

Definition at line 135 of file ErrorCollector.php.

References $errors.

135  {
136  return $this->errors;
137  }

◆ send()

HTMLPurifier_ErrorCollector::send (   $severity,
  $msg 
)

Sends an error message to the collector for later use.

Parameters
$severityint Error severity, PHP error style (don't use E_USER_)
$msgstring Error message text
$subst1string First substitution for $msg
$subst2string ...

Definition at line 42 of file ErrorCollector.php.

References HTMLPurifier_ErrorStruct\ATTR, HTMLPurifier_ErrorStruct\CSSPROP, and HTMLPurifier_ErrorStruct\TOKEN.

42  {
43 
44  $args = array();
45  if (func_num_args() > 2) {
46  $args = func_get_args();
47  array_shift($args);
48  unset($args[0]);
49  }
50 
51  $token = $this->context->get('CurrentToken', true);
52  $line = $token ? $token->line : $this->context->get('CurrentLine', true);
53  $col = $token ? $token->col : $this->context->get('CurrentCol', true);
54  $attr = $this->context->get('CurrentAttr', true);
55 
56  // perform special substitutions, also add custom parameters
57  $subst = array();
58  if (!is_null($token)) {
59  $args['CurrentToken'] = $token;
60  }
61  if (!is_null($attr)) {
62  $subst['$CurrentAttr.Name'] = $attr;
63  if (isset($token->attr[$attr])) $subst['$CurrentAttr.Value'] = $token->attr[$attr];
64  }
65 
66  if (empty($args)) {
67  $msg = $this->locale->getMessage($msg);
68  } else {
69  $msg = $this->locale->formatMessage($msg, $args);
70  }
71 
72  if (!empty($subst)) $msg = strtr($msg, $subst);
73 
74  // (numerically indexed)
75  $error = array(
76  self::LINENO => $line,
77  self::SEVERITY => $severity,
78  self::MESSAGE => $msg,
79  self::CHILDREN => array()
80  );
81  $this->_current[] = $error;
82 
83 
84  // NEW CODE BELOW ...
85 
86  $struct = null;
87  // Top-level errors are either:
88  // TOKEN type, if $value is set appropriately, or
89  // "syntax" type, if $value is null
90  $new_struct = new HTMLPurifier_ErrorStruct();
91  $new_struct->type = HTMLPurifier_ErrorStruct::TOKEN;
92  if ($token) $new_struct->value = clone $token;
93  if (is_int($line) && is_int($col)) {
94  if (isset($this->lines[$line][$col])) {
95  $struct = $this->lines[$line][$col];
96  } else {
97  $struct = $this->lines[$line][$col] = $new_struct;
98  }
99  // These ksorts may present a performance problem
100  ksort($this->lines[$line], SORT_NUMERIC);
101  } else {
102  if (isset($this->lines[-1])) {
103  $struct = $this->lines[-1];
104  } else {
105  $struct = $this->lines[-1] = $new_struct;
106  }
107  }
108  ksort($this->lines, SORT_NUMERIC);
109 
110  // Now, check if we need to operate on a lower structure
111  if (!empty($attr)) {
112  $struct = $struct->getChild(HTMLPurifier_ErrorStruct::ATTR, $attr);
113  if (!$struct->value) {
114  $struct->value = array($attr, 'PUT VALUE HERE');
115  }
116  }
117  if (!empty($cssprop)) {
118  $struct = $struct->getChild(HTMLPurifier_ErrorStruct::CSSPROP, $cssprop);
119  if (!$struct->value) {
120  // if we tokenize CSS this might be a little more difficult to do
121  $struct->value = array($cssprop, 'PUT VALUE HERE');
122  }
123  }
124 
125  // Ok, structs are all setup, now time to register the error
126  $struct->addError($severity, $msg);
127  }
Records errors for particular segments of an HTML document such as tokens, attributes or CSS properti...
Definition: ErrorStruct.php:9
const TOKEN
Possible values for $children first-key.
Definition: ErrorStruct.php:16

Field Documentation

◆ $_current

HTMLPurifier_ErrorCollector::$_current
protected

Definition at line 20 of file ErrorCollector.php.

◆ $_stacks

HTMLPurifier_ErrorCollector::$_stacks = array(array())
protected

Definition at line 21 of file ErrorCollector.php.

◆ $context

HTMLPurifier_ErrorCollector::$context
protected

Definition at line 24 of file ErrorCollector.php.

Referenced by __construct(), and _renderStruct().

◆ $errors

HTMLPurifier_ErrorCollector::$errors
protected

Definition at line 19 of file ErrorCollector.php.

Referenced by getHTMLFormatted(), and getRaw().

◆ $generator

HTMLPurifier_ErrorCollector::$generator
protected

Definition at line 23 of file ErrorCollector.php.

◆ $lines

HTMLPurifier_ErrorCollector::$lines = array()
protected

Definition at line 26 of file ErrorCollector.php.

◆ $locale

HTMLPurifier_ErrorCollector::$locale
protected

Definition at line 22 of file ErrorCollector.php.

◆ CHILDREN

const HTMLPurifier_ErrorCollector::CHILDREN = 3

Definition at line 17 of file ErrorCollector.php.

◆ LINENO

const HTMLPurifier_ErrorCollector::LINENO = 0

Identifiers for the returned error array.

These are purposely numeric so list() can be used.

Definition at line 14 of file ErrorCollector.php.

◆ MESSAGE

const HTMLPurifier_ErrorCollector::MESSAGE = 2

Definition at line 16 of file ErrorCollector.php.

◆ SEVERITY

const HTMLPurifier_ErrorCollector::SEVERITY = 1

Definition at line 15 of file ErrorCollector.php.


The documentation for this class was generated from the following file: