mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-01-17 14:08:15 +01:00
[1.4.0] Config object can now be instantiated from ini files. Also updated TODO.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@672 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
f7f6fed86a
commit
712d81ebea
1
NEWS
1
NEWS
@ -18,6 +18,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
|
|||||||
! Added %Core.EscapeNonASCIICharacters to workaround loss of Unicode
|
! Added %Core.EscapeNonASCIICharacters to workaround loss of Unicode
|
||||||
characters while %Core.Encoding is set to a non-UTF-8 encoding.
|
characters while %Core.Encoding is set to a non-UTF-8 encoding.
|
||||||
! Support for configuration directive aliases added
|
! Support for configuration directive aliases added
|
||||||
|
! Config object can now be instantiated from ini files
|
||||||
- Replaced version check with functionality check for DOM (thanks Stephen
|
- Replaced version check with functionality check for DOM (thanks Stephen
|
||||||
Khoo)
|
Khoo)
|
||||||
. Added smoketest 'all.php', which loads all other smoketests via frames
|
. Added smoketest 'all.php', which loads all other smoketests via frames
|
||||||
|
5
TODO
5
TODO
@ -10,8 +10,6 @@ TODO List
|
|||||||
1.4 release
|
1.4 release
|
||||||
# Add hooks for custom behavior (for instance, YouTube preservation)
|
# Add hooks for custom behavior (for instance, YouTube preservation)
|
||||||
- Aggressive caching
|
- Aggressive caching
|
||||||
- Upgrade SimpleTest testing code to newest version
|
|
||||||
? Rich set* methods and config file loaders for HTMLPurifier_Config
|
|
||||||
? Configuration profiles: sets of directives that get set with one func call
|
? Configuration profiles: sets of directives that get set with one func call
|
||||||
|
|
||||||
1.5 release
|
1.5 release
|
||||||
@ -69,6 +67,9 @@ Unknown release (on a scratch-an-itch basis)
|
|||||||
- Have 'lang' attribute be checked against official lists
|
- Have 'lang' attribute be checked against official lists
|
||||||
? Semi-lossy dumb alternate character encoding transformations, achieved by
|
? Semi-lossy dumb alternate character encoding transformations, achieved by
|
||||||
encoding all characters that have string entity equivalents
|
encoding all characters that have string entity equivalents
|
||||||
|
- Upgrade SimpleTest testing code to newest version
|
||||||
|
- Allow tags to be "armored", an internal flag that protects them
|
||||||
|
from validation and passes them out unharmed
|
||||||
|
|
||||||
Requested
|
Requested
|
||||||
? Native content compression, whitespace stripping (don't rely on Tidy, make
|
? Native content compression, whitespace stripping (don't rely on Tidy, make
|
||||||
|
@ -48,14 +48,16 @@ class HTMLPurifier_Config
|
|||||||
* Convenience constructor that creates a config object based on a mixed var
|
* Convenience constructor that creates a config object based on a mixed var
|
||||||
* @static
|
* @static
|
||||||
* @param mixed $config Variable that defines the state of the config
|
* @param mixed $config Variable that defines the state of the config
|
||||||
* object. Can be: a HTMLPurifier_Config() object or
|
* object. Can be: a HTMLPurifier_Config() object,
|
||||||
* an array of directives based on loadArray().
|
* an array of directives based on loadArray(),
|
||||||
|
* or a string filename of an ini file.
|
||||||
* @return Configured HTMLPurifier_Config object
|
* @return Configured HTMLPurifier_Config object
|
||||||
*/
|
*/
|
||||||
function create($config) {
|
function create($config) {
|
||||||
if (is_a($config, 'HTMLPurifier_Config')) return $config;
|
if (is_a($config, 'HTMLPurifier_Config')) return $config;
|
||||||
$ret = HTMLPurifier_Config::createDefault();
|
$ret = HTMLPurifier_Config::createDefault();
|
||||||
if (is_array($config)) $ret->loadArray($config);
|
if (is_string($config)) $ret->loadIni($config);
|
||||||
|
elseif (is_array($config)) $ret->loadArray($config);
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,6 +195,15 @@ class HTMLPurifier_Config
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads configuration values from an ini file
|
||||||
|
* @param $filename Name of ini file
|
||||||
|
*/
|
||||||
|
function loadIni($filename) {
|
||||||
|
$array = parse_ini_file($filename, true);
|
||||||
|
$this->loadArray($array);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
2
tests/HTMLPurifier/ConfigTest-create.ini
Normal file
2
tests/HTMLPurifier/ConfigTest-create.ini
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
[Cake]
|
||||||
|
Sprinkles = 42
|
4
tests/HTMLPurifier/ConfigTest-loadIni.ini
Normal file
4
tests/HTMLPurifier/ConfigTest-loadIni.ini
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
[Shortcut]
|
||||||
|
Copy = q
|
||||||
|
Cut = t
|
||||||
|
Paste = p
|
@ -199,6 +199,23 @@ class HTMLPurifier_ConfigTest extends UnitTestCase
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_loadIni() {
|
||||||
|
|
||||||
|
CS::defineNamespace('Shortcut', 'Keyboard shortcuts for commands');
|
||||||
|
CS::define('Shortcut', 'Copy', 'c', 'istring', 'Copy text');
|
||||||
|
CS::define('Shortcut', 'Paste', 'v', 'istring', 'Paste clipboard');
|
||||||
|
CS::define('Shortcut', 'Cut', 'x', 'istring', 'Cut text');
|
||||||
|
|
||||||
|
$config = HTMLPurifier_Config::createDefault();
|
||||||
|
|
||||||
|
$config->loadIni(dirname(__FILE__) . '/ConfigTest-loadIni.ini');
|
||||||
|
|
||||||
|
$this->assertIdentical($config->get('Shortcut', 'Copy'), 'q');
|
||||||
|
$this->assertIdentical($config->get('Shortcut', 'Paste'), 'p');
|
||||||
|
$this->assertIdentical($config->get('Shortcut', 'Cut'), 't');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
function test_getDefinition() {
|
function test_getDefinition() {
|
||||||
|
|
||||||
// we actually want to use the old copy, because the definition
|
// we actually want to use the old copy, because the definition
|
||||||
@ -274,6 +291,10 @@ class HTMLPurifier_ConfigTest extends UnitTestCase
|
|||||||
$created_config = HTMLPurifier_Config::create(array('Cake.Sprinkles' => 42));
|
$created_config = HTMLPurifier_Config::create(array('Cake.Sprinkles' => 42));
|
||||||
$this->assertEqual($config, $created_config);
|
$this->assertEqual($config, $created_config);
|
||||||
|
|
||||||
|
// test loadIni
|
||||||
|
$created_config = HTMLPurifier_Config::create(dirname(__FILE__) . '/ConfigTest-create.ini');
|
||||||
|
$this->assertEqual($config, $created_config);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user