mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-11-09 23:28:42 +00:00
[1.7.0] Eliminated modes in favor for special-case "Tidy" modules
- Add $xml property to Doctype, make more serialize friendly in preparation for stuffing into Config object - Add FIXME markers for areas of further development, code is hooked so this is easy - Document what the new Tidy classes will be git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1065 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
2d035483dd
commit
a5136b65e4
@ -18,23 +18,27 @@ class HTMLPurifier_Doctype
|
|||||||
var $modules = array();
|
var $modules = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Associative array of mode names to lists of modules; these are
|
* List of modules to use for tidying up code
|
||||||
* the modules added into the standard list if a particular mode
|
|
||||||
* is enabled, such as lenient or correctional.
|
|
||||||
*/
|
*/
|
||||||
var $modulesForModes = array();
|
var $tidyModules = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the language derived from XML (i.e. XHTML)?
|
||||||
|
*/
|
||||||
|
var $xml = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of aliases for this doctype
|
* List of aliases for this doctype
|
||||||
*/
|
*/
|
||||||
var $aliases = array();
|
var $aliases = array();
|
||||||
|
|
||||||
function HTMLPurifier_Doctype($name = null, $modules = array(),
|
function HTMLPurifier_Doctype($name = null, $xml = true, $modules = array(),
|
||||||
$modules_for_modes = array(), $aliases = array()
|
$tidyModules = array(), $aliases = array()
|
||||||
) {
|
) {
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
|
$this->xml = $xml;
|
||||||
$this->modules = $modules;
|
$this->modules = $modules;
|
||||||
$this->modulesForModes = $modules_for_modes;
|
$this->tidyModules = $tidyModules;
|
||||||
$this->aliases = $aliases;
|
$this->aliases = $aliases;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +47,7 @@ class HTMLPurifier_Doctype
|
|||||||
*/
|
*/
|
||||||
function copy() {
|
function copy() {
|
||||||
return new HTMLPurifier_Doctype(
|
return new HTMLPurifier_Doctype(
|
||||||
$this->name, $this->modules, $this->modulesForModes, $this->aliases
|
$this->name, $this->xml, $this->modules, $this->tidyModules, $this->aliases
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,14 +27,15 @@ class HTMLPurifier_DoctypeRegistry
|
|||||||
* @param $aliases Alias names for doctype
|
* @param $aliases Alias names for doctype
|
||||||
* @return Reference to registered doctype (usable for further editing)
|
* @return Reference to registered doctype (usable for further editing)
|
||||||
*/
|
*/
|
||||||
function ®ister($doctype, $modules = array(),
|
function ®ister($doctype, $xml = true, $modules = array(),
|
||||||
$modules_for_modes = array(), $aliases = array()
|
$tidy_modules = array(), $aliases = array()
|
||||||
) {
|
) {
|
||||||
if (!is_array($modules)) $modules = array($modules);
|
if (!is_array($modules)) $modules = array($modules);
|
||||||
|
if (!is_array($tidy_modules)) $tidy_modules = array($tidy_modules);
|
||||||
if (!is_array($aliases)) $aliases = array($aliases);
|
if (!is_array($aliases)) $aliases = array($aliases);
|
||||||
if (!is_object($doctype)) {
|
if (!is_object($doctype)) {
|
||||||
$doctype = new HTMLPurifier_Doctype(
|
$doctype = new HTMLPurifier_Doctype(
|
||||||
$doctype, $modules, $modules_for_modes, $aliases
|
$doctype, $xml, $modules, $tidy_modules, $aliases
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$this->doctypes[$doctype->name] =& $doctype;
|
$this->doctypes[$doctype->name] =& $doctype;
|
||||||
@ -68,15 +69,16 @@ class HTMLPurifier_DoctypeRegistry
|
|||||||
/**
|
/**
|
||||||
* Creates a doctype based on a configuration object,
|
* Creates a doctype based on a configuration object,
|
||||||
* will perform initialization on the doctype
|
* will perform initialization on the doctype
|
||||||
|
* @note Use this function to get a copy of doctype that config
|
||||||
|
* can hold on to (this is necessary in order to tell
|
||||||
|
* Generator whether or not the current document is XML
|
||||||
|
* based or not).
|
||||||
*/
|
*/
|
||||||
function make($config) {
|
function make($config) {
|
||||||
$original_doctype = $this->get($this->getDoctypeFromConfig($config));
|
$original_doctype = $this->get($this->getDoctypeFromConfig($config));
|
||||||
$doctype = $original_doctype->copy();
|
$doctype = $original_doctype->copy();
|
||||||
// initialization goes here
|
// FIXME!!! Set $doctype into $config so others can use it,
|
||||||
foreach ($doctype->modulesForModes as $mode => $mode_modules) {
|
// you might need to use two copies
|
||||||
// TODO: test if $mode is active
|
|
||||||
$doctype->modules = array_merge($doctype->modules, $mode_modules);
|
|
||||||
}
|
|
||||||
return $doctype;
|
return $doctype;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,33 +115,38 @@ class HTMLPurifier_HTMLModuleManager
|
|||||||
$transitional = array('Legacy', 'Target');
|
$transitional = array('Legacy', 'Target');
|
||||||
|
|
||||||
$this->doctypes->register(
|
$this->doctypes->register(
|
||||||
'HTML 4.01 Transitional',
|
'HTML 4.01 Transitional', false,
|
||||||
array_merge($common, $transitional),
|
array_merge($common, $transitional),
|
||||||
array('correctional' => array('TransformToStrict'))
|
array('TransformToStrict')
|
||||||
|
// Tidy: Transitional
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->doctypes->register(
|
$this->doctypes->register(
|
||||||
'XHTML 1.0 Transitional',
|
'HTML 4.01 Strict', false,
|
||||||
|
array_merge($common),
|
||||||
|
array('TransformToStrict')
|
||||||
|
// Tidy: Strict
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->doctypes->register(
|
||||||
|
'XHTML 1.0 Transitional', true,
|
||||||
array_merge($common, $transitional),
|
array_merge($common, $transitional),
|
||||||
array('correctional' => array('TransformToStrict'))
|
array('TransformToStrict')
|
||||||
|
// Tidy: Transitional, XHTML
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->doctypes->register(
|
$this->doctypes->register(
|
||||||
'HTML 4.01 Strict',
|
'XHTML 1.0 Strict', true,
|
||||||
array_merge($common),
|
array_merge($common),
|
||||||
array('lenient' => array('TransformToStrict'))
|
array('TransformToStrict')
|
||||||
|
// Tidy: Strict, XHTML
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->doctypes->register(
|
$this->doctypes->register(
|
||||||
'XHTML 1.0 Strict',
|
'XHTML 1.1', true,
|
||||||
array_merge($common),
|
array_merge($common),
|
||||||
array('lenient' => array('TransformToStrict'))
|
array('TransformToStrict', 'TransformToXHTML11')
|
||||||
);
|
// Tidy: Strict, XHTML1_1
|
||||||
|
|
||||||
$this->doctypes->register(
|
|
||||||
'XHTML 1.1',
|
|
||||||
array_merge($common),
|
|
||||||
array('lenient' => array('TransformToStrict', 'TransformToXHTML11'))
|
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -247,15 +252,12 @@ class HTMLPurifier_HTMLModuleManager
|
|||||||
$modules = array_merge($modules, $this->userModules);
|
$modules = array_merge($modules, $this->userModules);
|
||||||
|
|
||||||
foreach ($modules as $module) {
|
foreach ($modules as $module) {
|
||||||
if (is_object($module)) {
|
$this->processModule($module);
|
||||||
$this->registeredModules[$module->name] = $module;
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
if (!isset($this->registeredModules[$module])) {
|
|
||||||
$this->registerModule($module);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
$this->modules[$module] = $this->registeredModules[$module];
|
foreach ($doctype->tidyModules as $module) {
|
||||||
|
$this->processModule($module);
|
||||||
|
// FIXME!!! initialize the tidy modules here
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup lookup table based on all valid modules
|
// setup lookup table based on all valid modules
|
||||||
@ -284,6 +286,17 @@ class HTMLPurifier_HTMLModuleManager
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes a module and adds it to the active module collection,
|
||||||
|
* registering it if necessary.
|
||||||
|
*/
|
||||||
|
function processModule($module) {
|
||||||
|
if (!isset($this->registeredModules[$module]) || is_object($module)) {
|
||||||
|
$this->registerModule($module);
|
||||||
|
}
|
||||||
|
$this->modules[$module] = $this->registeredModules[$module];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves merged element definitions.
|
* Retrieves merged element definitions.
|
||||||
* @return Array of HTMLPurifier_ElementDef
|
* @return Array of HTMLPurifier_ElementDef
|
||||||
|
@ -11,23 +11,22 @@ class HTMLPurifier_DoctypeRegistryTest extends UnitTestCase
|
|||||||
|
|
||||||
$d =& $registry->register(
|
$d =& $registry->register(
|
||||||
$name = 'XHTML 1.0 Transitional',
|
$name = 'XHTML 1.0 Transitional',
|
||||||
|
$xml = true,
|
||||||
$modules = array('module-one', 'module-two'),
|
$modules = array('module-one', 'module-two'),
|
||||||
$modulesForModes = array(
|
$tidyModules = array('lenient-module'),
|
||||||
'lenient' => array('lenient-module'),
|
|
||||||
),
|
|
||||||
$aliases = array('X10T')
|
$aliases = array('X10T')
|
||||||
);
|
);
|
||||||
|
|
||||||
$d2 = new HTMLPurifier_Doctype($name, $modules, $modulesForModes, $aliases);
|
$d2 = new HTMLPurifier_Doctype($name, $xml, $modules, $tidyModules, $aliases);
|
||||||
|
|
||||||
$this->assertIdentical($d, $d2);
|
$this->assertIdentical($d, $d2);
|
||||||
$this->assertReference($d, $registry->get('XHTML 1.0 Transitional'));
|
$this->assertReference($d, $registry->get('XHTML 1.0 Transitional'));
|
||||||
|
|
||||||
// test shorthand
|
// test shorthand
|
||||||
$d =& $registry->register(
|
$d =& $registry->register(
|
||||||
$name = 'XHTML 1.0 Strict', 'module', array(), 'X10S'
|
$name = 'XHTML 1.0 Strict', true, 'module', 'Tidy', 'X10S'
|
||||||
);
|
);
|
||||||
$d2 = new HTMLPurifier_Doctype($name, array('module'), array(), array('X10S'));
|
$d2 = new HTMLPurifier_Doctype($name, true, array('module'), array('Tidy'), array('X10S'));
|
||||||
|
|
||||||
$this->assertIdentical($d, $d2);
|
$this->assertIdentical($d, $d2);
|
||||||
|
|
||||||
@ -52,22 +51,22 @@ class HTMLPurifier_DoctypeRegistryTest extends UnitTestCase
|
|||||||
|
|
||||||
$registry = new HTMLPurifier_DoctypeRegistry();
|
$registry = new HTMLPurifier_DoctypeRegistry();
|
||||||
|
|
||||||
$d1 =& $registry->register('Doc1', array(), array(), array('1'));
|
$d1 =& $registry->register('Doc1', true, array(), array(), array('1'));
|
||||||
|
|
||||||
$this->assertReference($d1, $registry->get('Doc1'));
|
$this->assertReference($d1, $registry->get('Doc1'));
|
||||||
$this->assertReference($d1, $registry->get('1'));
|
$this->assertReference($d1, $registry->get('1'));
|
||||||
|
|
||||||
$d2 =& $registry->register('Doc2', array(), array(), array('2'));
|
$d2 =& $registry->register('Doc2', true, array(), array(), array('2'));
|
||||||
|
|
||||||
$this->assertReference($d2, $registry->get('Doc2'));
|
$this->assertReference($d2, $registry->get('Doc2'));
|
||||||
$this->assertReference($d2, $registry->get('2'));
|
$this->assertReference($d2, $registry->get('2'));
|
||||||
|
|
||||||
$d3 =& $registry->register('1', array(), array(), array());
|
$d3 =& $registry->register('1', true, array(), array(), array());
|
||||||
|
|
||||||
// literal name overrides alias
|
// literal name overrides alias
|
||||||
$this->assertReference($d3, $registry->get('1'));
|
$this->assertReference($d3, $registry->get('1'));
|
||||||
|
|
||||||
$d4 =& $registry->register('One', array(), array(), array('1'));
|
$d4 =& $registry->register('One', true, array(), array(), array('1'));
|
||||||
|
|
||||||
$this->assertReference($d4, $registry->get('One'));
|
$this->assertReference($d4, $registry->get('One'));
|
||||||
// still it overrides
|
// still it overrides
|
||||||
|
Loading…
Reference in New Issue
Block a user