0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-11-09 23:28:42 +00:00

[1.7.0] Modify addElement to return a reference to the created definition, shorten other HTMLModules accordingly.

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1046 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2007-05-12 20:44:47 +00:00
parent ed73fdd5b8
commit e0cf214c44
6 changed files with 22 additions and 16 deletions

View File

@ -137,9 +137,11 @@ class HTMLPurifier_HTMLModule
* element?
* @param $attr What unique attributes does the element define?
* @note See ElementDef for in-depth descriptions of these parameters.
* @return Reference to created element definition object, so you
* can set advanced parameters
* @protected
*/
function addElement($element, $safe, $type, $contents, $attr_includes, $attr = array()) {
function &addElement($element, $safe, $type, $contents, $attr_includes, $attr = array()) {
$this->elements[] = $element;
// parse content_model
list($content_model_type, $content_model) = $this->parseContents($contents);
@ -153,6 +155,7 @@ class HTMLPurifier_HTMLModule
);
// literal object $contents means direct child manipulation
if (!is_string($contents)) $this->info[$element]->child = $contents;
return $this->info[$element];
}
/**

View File

@ -17,7 +17,7 @@ class HTMLPurifier_HTMLModule_Bdo extends HTMLPurifier_HTMLModule
function HTMLPurifier_HTMLModule_Bdo() {
$dir = new HTMLPurifier_AttrDef_Enum(array('ltr','rtl'), false);
$this->addElement(
$bdo =& $this->addElement(
'bdo', true, 'Inline', 'Inline', array('Core', 'Lang'),
array(
'dir' => $dir, // required
@ -28,7 +28,8 @@ class HTMLPurifier_HTMLModule_Bdo extends HTMLPurifier_HTMLModule
// be managed with a global attribute transform)
)
);
$this->info['bdo']->attr_transform_post['required-dir'] = new HTMLPurifier_AttrTransform_BdoDir();
$bdo->attr_transform_post['required-dir'] = new HTMLPurifier_AttrTransform_BdoDir();
$this->attr_collections['I18N']['dir'] = $dir;
}

View File

@ -12,7 +12,7 @@ class HTMLPurifier_HTMLModule_Hypertext extends HTMLPurifier_HTMLModule
var $name = 'Hypertext';
function HTMLPurifier_HTMLModule_Hypertext() {
$this->addElement(
$a =& $this->addElement(
'a', true, 'Inline', 'Inline', 'Common',
array(
// 'accesskey' => 'Character',
@ -25,7 +25,7 @@ class HTMLPurifier_HTMLModule_Hypertext extends HTMLPurifier_HTMLModule
// 'type' => 'ContentType',
)
);
$this->info['a']->excludes = array('a' => true);
$a->excludes = array('a' => true);
}
}

View File

@ -18,7 +18,7 @@ class HTMLPurifier_HTMLModule_Image extends HTMLPurifier_HTMLModule
var $content_sets = array('Inline' => 'img');
function HTMLPurifier_HTMLModule_Image() {
$this->addElement(
$img =& $this->addElement(
'img', true, 'Inline', 'Empty', 'Common',
array(
'alt' => 'Text',
@ -28,7 +28,7 @@ class HTMLPurifier_HTMLModule_Image extends HTMLPurifier_HTMLModule
'width' => 'Length'
)
);
$this->info['img']->attr_transform_post[] =
$img->attr_transform_post[] =
new HTMLPurifier_AttrTransform_ImgRequired();
}

View File

@ -26,8 +26,8 @@ class HTMLPurifier_HTMLModule_List extends HTMLPurifier_HTMLModule
$this->addElement('ul', true, 'List', 'Required: li', 'Common');
$this->addElement('dl', true, 'List', 'Required: dt | dd', 'Common');
$this->addElement('li', true, false, 'Flow', 'Common');
$this->info['li']->auto_close = array('li' => true);
$li =& $this->addElement('li', true, false, 'Flow', 'Common');
$li->auto_close = array('li' => true);
$this->addElement('dd', true, false, 'Flow', 'Common');
$this->addElement('dt', true, false, 'Inline', 'Common');

View File

@ -21,7 +21,7 @@ class HTMLPurifier_HTMLModuleTest extends UnitTestCase
function test_addElement() {
$module = new HTMLPurifier_HTMLModule();
$module->addElement(
$def =& $module->addElement(
'a', true, 'Inline', 'Optional: #PCDATA', array('Common'),
array(
'href' => 'URI'
@ -29,19 +29,21 @@ class HTMLPurifier_HTMLModuleTest extends UnitTestCase
);
$module2 = new HTMLPurifier_HTMLModule();
$def = new HTMLPurifier_ElementDef();
$def->safe = true;
$def->content_model = '#PCDATA';
$def->content_model_type = 'optional';
$def->attr = array(
$def2 = new HTMLPurifier_ElementDef();
$def2->safe = true;
$def2->content_model = '#PCDATA';
$def2->content_model_type = 'optional';
$def2->attr = array(
'href' => 'URI',
0 => array('Common')
);
$module2->info['a'] = $def;
$module2->info['a'] = $def2;
$module2->elements = array('a');
$module2->content_sets['Inline'] = 'a';
$this->assertIdentical($module, $module2);
$this->assertIdentical($def, $def2);
$this->assertReference($def, $module->info['a']);
}