ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilHtmlPurifierComposite Class Reference

Composite for nesting multiple purifiers. More...

+ Inheritance diagram for ilHtmlPurifierComposite:
+ Collaboration diagram for ilHtmlPurifierComposite:

Public Member Functions

 addPurifier (ilHtmlPurifierInterface $purifier)
 Adds a node to composite. More...
 
 removePurifier (ilHtmlPurifierInterface $purifier)
 Removes a node from composite. More...
 
 purify (string $html)
 Filters an HTML snippet/document to be XSS-free and standards-compliant. More...
 
 purifyArray (array $htmlCollection)
 Filters an array of HTML snippets/documents to be XSS-free and standards-compliant. More...
 

Protected Attributes

array $purifiers = []
 

Detailed Description

Composite for nesting multiple purifiers.

Author
Michael Jansen mjans.nosp@m.en@d.nosp@m.ataba.nosp@m.y.de

Definition at line 25 of file class.ilHtmlPurifierComposite.php.

Member Function Documentation

◆ addPurifier()

ilHtmlPurifierComposite::addPurifier ( ilHtmlPurifierInterface  $purifier)

Adds a node to composite.

Parameters
ilHtmlPurifierInterface$purifierInstance of ilHtmlPurifierInterface
Returns
bool True if instance could be added, otherwise false

Definition at line 35 of file class.ilHtmlPurifierComposite.php.

35  : bool
36  {
37  if (false === in_array($purifier, $this->purifiers, true)) {
38  $this->purifiers[] = $purifier;
39  return true;
40  }
41 
42  return false;
43  }

◆ purify()

ilHtmlPurifierComposite::purify ( string  $html)

Filters an HTML snippet/document to be XSS-free and standards-compliant.

Parameters
string$html
Returns
string

Implements ilHtmlPurifierInterface.

Definition at line 61 of file class.ilHtmlPurifierComposite.php.

61  : string
62  {
63  foreach ($this->purifiers as $purifier) {
64  $html = $purifier->purify($html);
65  }
66 
67  return $html;
68  }

◆ purifyArray()

ilHtmlPurifierComposite::purifyArray ( array  $htmlCollection)

Filters an array of HTML snippets/documents to be XSS-free and standards-compliant.

Parameters
string[]$htmlCollection
Returns
string[]
Exceptions
InvalidArgumentExceptionIf one of the arrays element is not of tpye string

Implements ilHtmlPurifierInterface.

Definition at line 70 of file class.ilHtmlPurifierComposite.php.

References ILIAS\LTI\ToolProvider\$key.

70  : array
71  {
72  foreach ($htmlCollection as $key => $html) {
73  if (!is_string($html)) {
74  throw new InvalidArgumentException(sprintf(
75  'The element on index %s is not of type string: %s',
76  $key,
77  print_r($html, true)
78  ));
79  }
80  }
81 
82  foreach ($htmlCollection as $key => $html) {
83  foreach ($this->purifiers as $purifier) {
84  $html = $purifier->purify($html);
85  }
86 
87  $htmlCollection[$key] = $html;
88  }
89 
90  return $htmlCollection;
91  }
string $key
Consumer key/client ID value.
Definition: System.php:193

◆ removePurifier()

ilHtmlPurifierComposite::removePurifier ( ilHtmlPurifierInterface  $purifier)

Removes a node from composite.

Parameters
ilHtmlPurifierInterface$purifierInstance of ilHtmlPurifierInterface
Returns
bool True if instance could be removed, otherwise false

Definition at line 50 of file class.ilHtmlPurifierComposite.php.

References ILIAS\LTI\ToolProvider\$key.

50  : bool
51  {
52  $key = array_search($purifier, $this->purifiers, true);
53  if (false === $key) {
54  return false;
55  }
56  unset($this->purifiers[$key]);
57 
58  return true;
59  }
string $key
Consumer key/client ID value.
Definition: System.php:193

Field Documentation

◆ $purifiers

array ilHtmlPurifierComposite::$purifiers = []
protected

Definition at line 28 of file class.ilHtmlPurifierComposite.php.


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