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

Commit a289e9a

Browse files
authored
Merge pull request #36 from burzum/4.0
4.0
2 parents 2960837 + 9aaa4bf commit a289e9a

File tree

5 files changed

+33
-16
lines changed

5 files changed

+33
-16
lines changed

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
"require": {
1616
"php": "^7.2",
1717
"cakephp/cakephp": "^4.0",
18-
"ezyang/htmlpurifier": "*",
19-
"cakephp/cakephp-codesniffer": "^3.0"
18+
"ezyang/htmlpurifier": "*"
2019
},
2120
"require-dev": {
21+
"cakephp/cakephp-codesniffer": "~4.2.0",
2222
"phpunit/phpunit": "~8.5.0"
2323
},
2424
"autoload": {

docs/Configuration.md

+11-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@
44

55
Important: Before you start declaring a configuration you should lookup how HTML Purifier can be configured. http://htmlpurifier.org/docs
66

7+
In `src/Application.php` add:
8+
```php
9+
$this->addPlugin('Burzum/HtmlPurifier');
10+
```
11+
712
In `config/boostrap.php` you can either set the purifier config as an array or pass a native config object.
813

914
The array style would look like this:
1015

1116
```php
12-
Purifier::config('ConfigName', array(
17+
Purifier::config('ConfigName', [
1318
'HTML.AllowedElements' => 'a, em, blockquote, p, strong, pre, code, span,ul,ol,li,img',
1419
'HTML.AllowedAttributes' => 'a.href, a.title, img.src, img.alt'
15-
)
20+
]
1621
);
1722
```
1823

@@ -48,16 +53,18 @@ or clean some dirty HTML directly by calling
4853
Purifier::clean($markup, 'ConfigName');
4954
```
5055

56+
*Remember to add `use Burzum\HtmlPurifier\Lib\Purifier;` when ussing `Purifier` class*
57+
5158
For some automatization you can also use the Behavior or Helper.
5259

5360
## Caching ###
5461

5562
It is recommended to change the path of the purifier libs cache to your `tmp` folder. For example:
5663

5764
```php
58-
Purifier::config('ConfigName', array(
65+
Purifier::config('ConfigName', [
5966
'Cache.SerializerPath' => ROOT . DS . 'tmp' . DS . 'purifier',
60-
)
67+
]
6168
);
6269
```
6370

docs/Installation.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Installation
2+
3+
## Installation with composer (CakePHP 4)
4+
5+
```bash
6+
composer require burzum/cakephp-html-purifier:4.0.x-dev
7+
```

docs/Usage.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ Set a config you want to use and the fields you want to sanitize.
66

77
```php
88
public $actsAs = array(
9-
'Burzum/HtmlPurifier.HtmlPurifier' => array(
10-
'config' => 'ConfigName',
11-
'fields' => array(
9+
'Burzum/HtmlPurifier.HtmlPurifier' => [
10+
'purifierConfig' => 'ConfigName',
11+
'fields' => [
1212
'body', 'excerpt'
13-
)
14-
)
13+
]
14+
]
1515
);
1616
```
1717

src/Shell/PurifierShell.php

+8-5
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
*/
99
namespace Burzum\HtmlPurifier\Shell;
1010

11+
use Cake\Console\ConsoleOptionParser;
1112
use Cake\Console\Shell;
1213
use Cake\ORM\Locator\TableLocator;
1314
use Cake\ORM\Table;
15+
use Cake\Datasource\EntityInterface;
1416

1517
/**
1618
* PurifierShell
@@ -31,7 +33,7 @@ public function main()
3133
/**
3234
* Gets the table from the shell args.
3335
*
34-
* @return \Cake\ORM\Table;
36+
* @return \Cake\ORM\Table
3537
*/
3638
protected function _getTable()
3739
{
@@ -67,7 +69,7 @@ protected function _getFields(Table $table)
6769
/**
6870
* Loads the purifier behavior for the given table if not already attached.
6971
*
70-
* @param \Cake\ORM\Table $table Table object.
72+
* @param \Cake\ORM\Table $table Table object.
7173
* @param array Set of fields to sanitize
7274
* @return void
7375
*/
@@ -100,7 +102,7 @@ public function purify()
100102
}
101103
$total = $query->all()->count();
102104

103-
$this->info(__d('Burzum/HtmlPurifier', 'Sanitizing fields `{0}` in table `{1}`', implode(',', $fields), $table->table()));
105+
$this->info(__d('Burzum/HtmlPurifier', 'Sanitizing fields `{0}` in table `{1}`', implode(',', $fields), $table->getTable()));
104106

105107
$this->helper('progress')->output(
106108
[
@@ -142,7 +144,7 @@ protected function _process(Table $table, $chunkCount, $chunkSize, $fields)
142144
->select($fields)
143145
->offset($chunkCount)
144146
->limit($chunkSize)
145-
->orderDesc($table->aliasField($table->primarygetPrimaryKey()))
147+
->orderDesc($table->aliasField($table->getPrimaryKey()))
146148
->all();
147149

148150
if (empty($results)) {
@@ -151,6 +153,7 @@ protected function _process(Table $table, $chunkCount, $chunkSize, $fields)
151153

152154
foreach ($results as $result) {
153155
try {
156+
$table->patchEntity($result, $result->toArray());
154157
$table->save($result);
155158
$chunkCount++;
156159
} catch (\Exception $e) {
@@ -162,7 +165,7 @@ protected function _process(Table $table, $chunkCount, $chunkSize, $fields)
162165
/**
163166
* {@inheritDoc}
164167
*/
165-
public function getOptionParser()
168+
public function getOptionParser(): ConsoleOptionParser
166169
{
167170
$parser = parent::getOptionParser();
168171

0 commit comments

Comments
 (0)