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

Commit 1f10b3d

Browse files
author
Florian Krämer
committed
Merge branch '2.0' of git://github.com/burzum/cakephp-html-purifier into 2.0
# Conflicts: # README.md # docs/Home.md # docs/Usage.md
2 parents 57aab85 + bb48c51 commit 1f10b3d

File tree

6 files changed

+92
-15
lines changed

6 files changed

+92
-15
lines changed

composer.json

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
Installation
2-
============
1+
# Installation
32

4-
Using Composer
5-
--------------
3+
## Using Composer
64

75
Installing the plugin via [Composer](https://getcomposer.org/) is very simple, just run this in your project folder:
86

src/Lib/Purifier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public static function clean($markup, $configName = null)
102102
$_this = Purifier::getInstance();
103103

104104
if (!isset($_this->_configs[$configName])) {
105-
throw new \InvalidArgumentException(sprintf('Invalid configuration %s!', $configName));
105+
throw new \InvalidArgumentException(sprintf('Invalid HtmlPurifier configuration "%s"!', $configName));
106106
}
107107

108108
return $_this->getPurifierInstance($configName)->purify($markup);

src/View/Helper/HtmlPurifierHelper.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class HtmlPurifierHelper extends Helper {
1818
*
1919
* @var array
2020
*/
21-
public $_defaultConfig = [
22-
'config' => ''
23-
];
21+
public $_defaultConfig = [
22+
'config' => 'default'
23+
];
2424

2525
/**
2626
* Clean markup
@@ -29,10 +29,11 @@ class HtmlPurifierHelper extends Helper {
2929
* @param string $config
3030
* @return string
3131
*/
32-
public function clean($markup, $config = null) {
33-
if (empty($config) && !empty($this->_config['config'])) {
34-
$config = $this->settings['config'];
35-
}
36-
return Purifier::clean($markup, $config);
37-
}
32+
public function clean($markup, $config = null)
33+
{
34+
if (empty($config) && !empty($this->_config['config'])) {
35+
$config = $this->config('config');
36+
}
37+
return Purifier::clean($markup, $config);
38+
}
3839
}

0 commit comments

Comments
 (0)