/
HTMLClean.php
49 lines (37 loc) · 1.21 KB
/
HTMLClean.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace MicroweberPackages\Helper;
class HTMLClean
{
public function cleanArray($array) {
if (is_array($array)) {
$cleanedArray = [];
foreach ($array as $key=>$value) {
if (is_array($value)) {
$cleanedArray[$key] = $this->cleanArray($value);
} else {
$cleanedArray[$key] = $this->clean($value);
}
}
return $cleanedArray;
}
}
public function clean($html) {
$antiXss = new \voku\helper\AntiXSS();
$html = $antiXss->xss_clean($html);
$path = storage_path() . '/html_purifier';
if (!is_dir($path)) {
mkdir_recursive($path);
}
$config = \HTMLPurifier_Config::createDefault();
if ($path) {
$config->set('Cache.SerializerPath', $path);
}
$config->set('URI.DisableExternal', true);
$config->set('URI.DisableExternalResources', true);
// $config->set('URI.DisableResources', true);
$config->set('URI.Host', site_hostname());
$purifier = new \HTMLPurifier($config);
$html = $purifier->purify($html);
return $html;
}
}