Skip to content

Commit ab7a359

Browse files
authored
Merge pull request #32 from dmstr/dev/html-purifier-filter-validator
Added HTMLPurifierFilterValidator
2 parents 51051af + 46ddded commit ab7a359

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
4+
namespace dmstr\jsoneditor;
5+
6+
7+
use yii\helpers\HtmlPurifier;
8+
use yii\helpers\Json;
9+
use yii\validators\FilterValidator;
10+
11+
class HTMLPurifierFilterValidator extends FilterValidator
12+
{
13+
public function init () {
14+
$this->filter = function ($value) {
15+
$array = is_array($value) ? $value : Json::decode($value);
16+
17+
array_walk_recursive($array, function (&$value) {
18+
if (is_string($value)) {
19+
$value = HtmlPurifier::process($value);
20+
}
21+
});
22+
23+
return is_array($value) ? $array : Json::encode($array);
24+
};
25+
26+
parent::init();
27+
}
28+
}

0 commit comments

Comments
 (0)