0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-12-22 08:21:52 +00:00

Add HTMLPurifier_config->serialize()

Signed-off-by: Edward Z. Yang <edwardzyang@thewritingpot.com>
This commit is contained in:
Edward Z. Yang 2009-05-30 00:25:14 -04:00
parent 77b60a4206
commit 6e66dc9cad
5 changed files with 36 additions and 3 deletions

3
NEWS
View File

@ -40,6 +40,9 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
! You can now maintain your own configuration schema directories by
creating a config-schema.php file or passing an extra argument. Check
docs/dev-config-schema.html for more details.
! Added HTMLPurifier_Config->serialize() method, which lets you save away
your configuration in a compact serial file, which you can unserialize
and use directly without having to go through the overhead of setup.
- Fix bug where URIDefinition would not get cleared if it's directives got
changed.
- Fix fatal error in HTMLPurifier_Encoder on certain platforms (probably NetBSD 5.0)

3
TODO
View File

@ -20,9 +20,6 @@ afraid to cast your vote for the next feature to be implemented!
- Think about allowing explicit order of operations hooks for transforms
- Add "register" field to config schemas to eliminate dependence on
naming conventions
- Make it easy for people to cache their entire configuration (so that
they have one script they run to change configuration, and then a stub
loader to get that configuration)
- Add examples to everything (make built-in which also automatically
gives output)

View File

@ -564,6 +564,17 @@ class HTMLPurifier_Config
trigger_error($msg . $extra, $no);
}
/**
* Returns a serialized form of the configuration object that can
* be reconstituted.
*/
public function serialize() {
$this->getDefinition('HTML');
$this->getDefinition('CSS');
$this->getDefinition('URI');
return serialize($this);
}
}
// vim: et sw=4 sts=4

View File

@ -0,0 +1,15 @@
<?php
require_once 'common.php';
$config = HTMLPurifier_Config::createDefault();
$config->set('HTML.Doctype', 'HTML 4.01 Strict');
$config->set('HTML.Allowed', 'b,a[href],br');
$config->set('CSS.AllowTricky', true);
$config->set('URI.Disable', true);
$serial = $config->serialize();
$result = unserialize($serial);
$purifier = new HTMLPurifier($result);
echo htmlspecialchars($purifier->purify('<b>Bold</b><br><i><a href="http://google.com">no</a> formatting</i>'));

View File

@ -451,6 +451,13 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness
$this->assertIdentical($subconfig->get('Phantom.Latemasked'), 100);
}
function testSerialize() {
$config = HTMLPurifier_Config::createDefault();
$config->set('HTML.Allowed', 'a');
$config2 = unserialize($config->serialize());
$this->assertIdentical($config, $config2);
}
}
// vim: et sw=4 sts=4