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

Commit ae2a2ff

Browse files
author
Florian Krämer
committed
Merge branch '2.0'
2 parents 6fb4fe0 + b444051 commit ae2a2ff

15 files changed

+560
-184
lines changed

.editorconfig

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
; This file is for unifying the coding style for different editors and IDEs.
2+
; More information at http://editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
indent_style = spaces
8+
end_of_line = lf
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
charset = utf-8
12+
13+
[*.js]
14+
indent_style = tabs
15+
indent_size = 4
16+
17+
[*.css]
18+
indent_style = tabs
19+
indent_size = 4
20+
21+
[*.bat]
22+
indent_style = tabs
23+
indent_size = 4
24+
end_of_line = crlf
25+
26+
[*.yml]
27+
indent_style = tabs
28+
indent_size = 4

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
CakePHP HTML Purifier Plugin
22
----------------------------
33

4-
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.txt)
5-
[![Build Status](https://img.shields.io/travis/burzum/cakephp-html-purifier/master.svg?style=flat-square)](https://travis-ci.org/burzum/cakephp-html-purifier)
4+
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.txt)
5+
[![Build Status](https://img.shields.io/travis/burzum/cakephp-html-purifier/master.svg?style=flat-square)](https://travis-ci.org/burzum/cakephp-html-purifier)
66
[![Build Status](https://img.shields.io/coveralls/burzum/cakephp-html-purifier/master.svg?style=flat-square)](https://coveralls.io/r/burzum/cakephp-html-purifier)
77

8-
This is a CakePHP wrapper for the HTML Purifier lib. http://htmlpurifier.org/
8+
This is a CakePHP wrapper for [the HTML Purifier lib](http://htmlpurifier.org/).
99

1010
HTML Purifier is a standards-compliant HTML filter library written in PHP. HTML Purifier will not only remove all malicious code (better known as XSS) with a thoroughly audited, secure yet permissive whitelist, it will also make sure your documents are standards compliant, something only achievable with a comprehensive knowledge of W3C's specifications.
1111

12-
The plugin includes a Helper, Behavior and a Shell to clean your markup wherever you like, in the view or in Model::beforeMarshall().
12+
The plugin includes a trait, a view helper, a behavior and a shell to clean your markup wherever you like, in the view or in the model layer or clean any table and field using the shell.
1313

1414
---
1515

@@ -43,6 +43,6 @@ Please feel free to contribute to the plugin with new issues, requests, unit tes
4343
License
4444
-------
4545

46-
Copyright 2013 - 2015 Florian Krämer
46+
Copyright 2012 - 2016 Florian Krämer
4747

4848
Licensed under the [MIT](http://www.opensource.org/licenses/mit-license.php) License. Redistributions of the source code included in this repository must retain the copyright notice found in each file.

docs/Configuration.md

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Configuration
2+
3+
## Purifier Filter Configuration
4+
5+
Important: Before you start declaring a configuration you should lookup how HTML Purifier can be configured. http://htmlpurifier.org/docs
6+
7+
In `config/boostrap.php` you can either set the purifier config as an array or pass a native config object.
8+
9+
The array style would look like this:
10+
11+
```php
12+
Purifier::config('ConfigName', array(
13+
'HTML.AllowedElements' => 'a, em, blockquote, p, strong, pre, code, span,ul,ol,li,img',
14+
'HTML.AllowedAttributes' => 'a.href, a.title, img.src, img.alt'
15+
)
16+
);
17+
```
18+
19+
The plugin will construct a HTML Purifier config from that and instantiate the purifier.
20+
21+
A pure HTML Purifier config might look like this one:
22+
23+
```php
24+
$config = HTMLPurifier_Config::createDefault();
25+
$config->set('HTML.AllowedElements', 'a, em, blockquote, p, strong, pre, code, span,ul,ol,li,img');
26+
$config->set('HTML.AllowedAttributes', 'a.href, a.title, img.src, img.alt');
27+
$config->set('HTML.AllowedAttributes', "*.style");
28+
$config->set('CSS.AllowedProperties', 'text-decoration');
29+
$config->set('HTML.TidyLevel', 'heavy');
30+
$config->set('HTML.Doctype', 'XHTML 1.0 Transitional');
31+
```
32+
33+
Simply assign it to a config:
34+
35+
```php
36+
Purifier::config('ConfigName', $config);
37+
```
38+
39+
Now that you have a configured instance of HTML Purifier ready you can use it directly and get you an instance of the purifier
40+
41+
```php
42+
Purifier::config('ConfigName');
43+
```
44+
45+
or clean some dirty HTML directly by calling
46+
47+
```php
48+
Purifier::clean($markup, 'ConfigName');
49+
```
50+
51+
For some automatization you can also use the Behavior or Helper.
52+
53+
## Caching ###
54+
55+
It is recommended to change the path of the purifier libs cache to your `tmp` folder. For example:
56+
57+
```php
58+
Purifier::config('ConfigName', array(
59+
'Cache.SerializerPath' => ROOT . DS . 'tmp' . DS . 'purifier',
60+
)
61+
);
62+
```
63+
64+
See this page as well [http://htmlpurifier.org/live/configdoc/plain.html#Cache](http://htmlpurifier.org/live/configdoc/plain.html#Cache).

docs/Home.md

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
Home
2-
====
1+
CakePHP HTML Purifier Plugin
2+
----------------------------
33

4-
The **Html Purifier** plugin
4+
This is a CakePHP wrapper for [the HTML Purifier lib](http://htmlpurifier.org/).
55

6-
Documentation
7-
-------------
6+
HTML Purifier is a standards-compliant HTML filter library written in PHP. HTML Purifier will not only remove all malicious code (better known as XSS) with a thoroughly audited, secure yet permissive whitelist, it will also make sure your documents are standards compliant, something only achievable with a comprehensive knowledge of W3C's specifications.
87

9-
* [Installation](Documentation/Installation.md)
10-
* [Configuration](Documentation/Configuration.md)
11-
* [If you use APC](Documentation/If-you-use-APC.md)
8+
The plugin includes a trait, a view helper, a behavior and a shell to clean your markup wherever you like, in the view or in the model layer or clean any table and field using the shell.
129

10+
* [Installation](Installation.md)
11+
* [Configuration](Configuration.md)
12+
* [Read this if you are using APC](If-you-are-using-APC.md)
13+
* [Usage](Usage.md)
14+
15+
License
16+
-------
17+
18+
Copyright 2012 - 2016 Florian Krämer
19+
20+
Licensed under the [MIT](http://www.opensource.org/licenses/mit-license.php) License. Redistributions of the source code included in this repository must retain the copyright notice found in each file.

docs/If-you-are-using-APC.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# If you are using APC ...
2+
3+
...and get this error message
4+
5+
Fatal error: Cannot override final method HTMLPurifier_VarParser::parse()
6+
7+
you can fix this by adding
8+
9+
```php
10+
Configure::write('HtmlPurifier.standalone', true);
11+
```
12+
13+
to your bootstrap.php *before* you load this plugin.
14+
15+
This line will use a compacted one file version of Html Purifier. This is an official and know issue and workaround, see http://htmlpurifier.org/phorum/read.php?3,4099,6680.

docs/Usage.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Usage
2+
3+
## The Behavior
4+
5+
Set a config you want to use and the fields you want to sanitize.
6+
7+
```php
8+
public $actsAs = array(
9+
'Burzum/HtmlPurifier.HtmlPurifier' => array(
10+
'config' => 'ConfigName',
11+
'fields' => array(
12+
'body', 'excerpt'
13+
)
14+
)
15+
);
16+
```
17+
18+
## The Helper
19+
20+
In your controller load the helper and set a default config if you want.
21+
22+
```php
23+
public $helpers = array(
24+
'Burzum/HtmlPurifier.HtmlPurifier' => array(
25+
'config' => 'ConfigName'
26+
)
27+
);
28+
```
29+
30+
In the views you can then use the helper like this:
31+
32+
```php
33+
$this->HtmlPurifier->clean($markup, 'ConfigName');
34+
```
35+
36+
## The Shell
37+
38+
Using the shell is very easy and self-explaining:
39+
40+
```sh
41+
cake purify <table> <fields>
42+
```
43+
44+
You can specify a purifier config to use as well:
45+
46+
```sh
47+
cake purify <table> <fields> --config myconfig
48+
```
49+
50+
## The Trait
51+
52+
Where ever you need the purifier you can simply add it to your class by using the [PurifierTrait](../src/Lib/PurifierTrait.php).
53+
54+
[See the official php documentation](http://php.net/manual/en/language.oop5.traits.php) for traits if you don't know how to use it.

src/Lib/Purifier.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Purifier
44
*
55
* @author Florian Krämer
6-
* @copyright 2012 - 2015 Florian Krämer
6+
* @copyright 2012 - 2016 Florian Krämer
77
* @license MIT
88
*/
99
namespace Burzum\HtmlPurifier\Lib;
@@ -77,7 +77,7 @@ public static function config($configName, $config = null)
7777
* @param string $configName
7878
* @return HTMLPurifier
7979
*/
80-
public static function getPurifierInstance($configName = null)
80+
public static function getPurifierInstance($configName = 'default')
8181
{
8282
$_this = Purifier::getInstance();
8383

@@ -97,7 +97,7 @@ public static function getPurifierInstance($configName = null)
9797
* @param string $markup
9898
* @param string $configName
9999
*/
100-
public static function clean($markup, $configName = null)
100+
public static function clean($markup, $configName = 'default')
101101
{
102102
$_this = Purifier::getInstance();
103103

src/Lib/PurifierTrait.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Purifier
44
*
55
* @author Florian Krämer
6-
* @copyright 2012 - 2015 Florian Krämer
6+
* @copyright 2012 - 2016 Florian Krämer
77
* @license MIT
88
*/
99
namespace Burzum\HtmlPurifier\Lib;
@@ -16,7 +16,7 @@ trait PurifierTrait {
1616
* @param string $markup
1717
* @param string $config
1818
*/
19-
public function purifyHtml($markup, $config = '')
19+
public function purifyHtml($markup, $config = 'default')
2020
{
2121
return Purifier::clean($markup, $config);
2222
}

src/Model/Behavior/HtmlPurifierBehavior.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Purifier
44
*
55
* @author Florian Krämer
6-
* @copyright 2012 - 2015 Florian Krämer
6+
* @copyright 2012 - 2016 Florian Krämer
77
* @license MIT
88
*/
99
namespace Burzum\HtmlPurifier\Model\Behavior;

0 commit comments

Comments
 (0)