ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilHtmlPurifierAbstractLibWrapper.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
9{
11 protected $purifier;
12
16 public function __construct()
17 {
18 $this->setPurifier(
19 new HTMLPurifier($this->getPurifierConfigInstance())
20 );
21 }
22
26 final public function purify(string $html) : string
27 {
28 return $this->purifier->purify($html);
29 }
30
34 final public function purifyArray(array $htmlCollection) : array
35 {
36 return $this->purifier->purifyArray($htmlCollection);
37 }
38
42 abstract protected function getPurifierConfigInstance() : HTMLPurifier_Config;
43
48 protected function setPurifier(HTMLPurifier $purifier) : self
49 {
50 $this->purifier = $purifier;
51 return $this;
52 }
53
57 protected function getPurifier() : HTMLPurifier
58 {
59 return $this->purifier;
60 }
61
65 final public static function _getCacheDirectory() : string
66 {
67 if (!file_exists(ilUtil::getDataDir() . '/HTMLPurifier') ||
68 !is_dir(ilUtil::getDataDir() . '/HTMLPurifier')) {
69 ilUtil::makeDirParents(ilUtil::getDataDir() . '/HTMLPurifier');
70 }
71
72 return ilUtil::getDataDir() . '/HTMLPurifier';
73 }
74
80 final protected function removeUnsupportedElements(array $elements) : array
81 {
82 $supportedElements = array();
83
84 $notSupportedTags = array(
85 'rp',
86 'rt',
87 'rb',
88 'rtc',
89 'rbc',
90 'ruby',
91 'u',
92 'strike',
93 'param',
94 'object'
95 );
96
97 foreach ($elements as $element) {
98 if (!in_array($element, $notSupportedTags)) {
99 $supportedElements[] = $element;
100 }
101 }
102
103 return $supportedElements;
104 }
105
110 protected function makeElementListTinyMceCompliant(array $elements) : array
111 {
112 // Bugfix #5945: Necessary because TinyMCE does not use the "u"
113 // html element but <span style="text-decoration: underline">E</span>
114
115 if (in_array('u', $elements) && !in_array('span', $elements)) {
116 $elements[] = 'span';
117 }
118
119 return $elements;
120 }
121}
An exception for terminatinating execution or to throw for unit testing.
Abstract class wrapping the HTMLPurifier instance.
removeUnsupportedElements(array $elements)
Removes all unsupported elements.
__construct()
ilHtmlPurifierAbstractLibWrapper constructor.
static getDataDir()
get data directory (outside webspace)
static makeDirParents($a_dir)
Create a new directory and all parent directories.
Interface for html sanitizing functionality.