Skip to content
This repository was archived by the owner on Mar 5, 2022. It is now read-only.

Commit 69f98a1

Browse files
author
Florian Krämer
committed
Working on the 3.0 version
1 parent 30da811 commit 69f98a1

File tree

6 files changed

+45
-50
lines changed

6 files changed

+45
-50
lines changed

Config/bootstrap.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

docs/Installation.md

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
Installation
2-
------------
2+
============
33

4-
Clone the code into your apps plugin folder
4+
Using Composer
5+
--------------
56

6-
git clone git@github.com:burzum/cakephp-html-purifier.git app/Plugin/HtmlPurifier
7+
Installing the plugin via [Composer](https://getcomposer.org/) is very simple, just run this in your project folder:
78

8-
or add it as submodule
9-
10-
git submodule add git@github.com:burzum/cakephp-html-purifier.git app/Plugin/HtmlPurifier
11-
12-
In your config/bootstrap.php add
13-
14-
```php
15-
Plugin::load('Burzum/HtmlPurifier', ['bootstrap' => true]);
9+
```sh
10+
composer require burzum/cakephp-html-purifier:3.0.*@dev
1611
```

src/Lib/Purifier.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
2-
namespace Burzum\HtmlPurifier\Lib;
3-
42
/**
53
* Purifier
64
*
75
* @author Florian Krämer
86
* @copyright 2012 - 2015 Florian Krämer
97
* @license MIT
108
*/
9+
namespace Burzum\HtmlPurifier\Lib;
10+
1111
class Purifier {
1212

1313
/**
@@ -39,11 +39,12 @@ public static function &getInstance()
3939
}
4040

4141
/**
42-
* Config
42+
* Gets and sets purifier configuration sets.
4343
*
4444
* @param string $configName
4545
* @param string $config
4646
* @throws \InvalidArgumentException
47+
* @return \HTMLPurifier
4748
*/
4849
public static function config($configName, $config = null)
4950
{

src/Lib/PurifierTrait.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
<?php
2+
/**
3+
* Purifier
4+
*
5+
* @author Florian Krämer
6+
* @copyright 2012 - 2015 Florian Krämer
7+
* @license MIT
8+
*/
29
namespace Burzum\HtmlPurifier\Lib;
310

411
trait PurifierTrait {
@@ -13,4 +20,15 @@ public function purifyHtml($markup, $config = '')
1320
{
1421
return Purifier::clean($markup, $config);
1522
}
23+
24+
/**
25+
* Gets a HtmlPurifier instance based on a configuration name.
26+
*
27+
* @param string $config
28+
* @return \HtmlPurifier
29+
*/
30+
public function getHtmlPurifier($config = 'default')
31+
{
32+
return Purifier::config($config);
33+
}
1634
}

src/Model/Behavior/HtmlPurifierBehavior.php

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
<?php
2+
/**
3+
* Purifier
4+
*
5+
* @author Florian Krämer
6+
* @copyright 2012 - 2015 Florian Krämer
7+
* @license MIT
8+
*/
29
namespace App\Model\Behavior;
310

411
use ArrayObject;
512
use Burzum\HtmlPurifier\Lib\PurifierTrait;
6-
use Cake\Core\Configure;
713
use Cake\Event\Event;
814
use Cake\ORM\Behavior;
9-
use HTMLPurifier;
10-
use HTMLPurifier_Config;
1115

1216
class HtmlPurifierBehavior extends Behavior {
1317

@@ -41,27 +45,13 @@ class HtmlPurifierBehavior extends Behavior {
4145
*/
4246
public function beforeMarshal(Event $event, ArrayObject $data, ArrayObject $options)
4347
{
44-
foreach ($this->config('fields') as $field) {
45-
if (isset($data[$field])) {
48+
foreach ($this->config('fields') as $key => $field) {
49+
if (is_int($key) && isset($data[$field])) {
4650
$data[$field] = $this->purifyHtml($data[$field], $this->config('purifierConfig'));
4751
}
52+
if (is_string($key) && is_string($field)) {
53+
$data[$key] = $this->purifyHtml($data[$key], $this->config($field));
54+
}
4855
}
4956
}
50-
51-
public function purifier($config = null)
52-
{
53-
// if (is_string($config)) {
54-
// $config = (array)Configure::read('HtmlPurifier.' . $config);
55-
// }
56-
// if (!is_array($config)) {
57-
// throw new \InvalidArgumentException('Invalid purifier config value passed!');
58-
// }
59-
// $hash = md5(serialize($config));
60-
// if (!empty($this->_purifier[$hash])) {
61-
// return $this->_purifier[$hash];
62-
// }
63-
// $config = \HTMLPurifier_Config::create($config);
64-
// $this->_purifier[$hash] = new \HTMLPurifier($config);
65-
// return $this->_purifier[$hash];
66-
}
6757
}

src/View/Helper/HtmlPurifierHelper.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<?php
2-
namespace Burzum\HtmlPurifier\View\Helper;
3-
4-
use Burzum\HtmlPurifier\Lib\Purifier;
5-
use Cake\View\Helper;
6-
72
/**
83
* HtmlPurifierHelper
94
*
105
* @author Florian Krämer
116
* @copyright 2012 - 2015 Florian Krämer
127
* @license MIT
138
*/
9+
namespace Burzum\HtmlPurifier\View\Helper;
10+
11+
use Burzum\HtmlPurifier\Lib\Purifier;
12+
use Cake\View\Helper;
13+
1414
class HtmlPurifierHelper extends Helper {
1515

1616
/**

0 commit comments

Comments
 (0)