function test_mergeIn() { $def1 = new HTMLPurifier_ElementDef(); $def2 = new HTMLPurifier_ElementDef(); $def3 = new HTMLPurifier_ElementDef(); $old = 1; $new = 2; $overloaded_old = 3; $overloaded_new = 4; $removed = 5; $def1->standalone = true; $def1->attr = array(0 => array('old-include'), 'old-attr' => $old, 'overloaded-attr' => $overloaded_old, 'removed-attr' => $removed); $def1->attr_transform_pre = $def1->attr_transform_post = array('old-transform' => $old, 'overloaded-transform' => $overloaded_old, 'removed-transform' => $removed); $def1->child = $overloaded_old; $def1->content_model = 'old'; $def1->content_model_type = $overloaded_old; $def1->descendants_are_inline = false; $def1->excludes = array('old' => true, 'removed-old' => true); $def2->standalone = false; $def2->attr = array(0 => array('new-include'), 'new-attr' => $new, 'overloaded-attr' => $overloaded_new, 'removed-attr' => false); $def2->attr_transform_pre = $def2->attr_transform_post = array('new-transform' => $new, 'overloaded-transform' => $overloaded_new, 'removed-transform' => false); $def2->child = $new; $def2->content_model = '#SUPER | new'; $def2->content_model_type = $overloaded_new; $def2->descendants_are_inline = true; $def2->excludes = array('new' => true, 'removed-old' => false); $def1->mergeIn($def2); $def1->mergeIn($def3); // empty, has no effect $this->assertIdentical($def1->standalone, true); $this->assertIdentical($def1->attr, array(0 => array('old-include', 'new-include'), 'old-attr' => $old, 'overloaded-attr' => $overloaded_new, 'new-attr' => $new)); $this->assertIdentical($def1->attr_transform_pre, $def1->attr_transform_post); $this->assertIdentical($def1->attr_transform_pre, array('old-transform' => $old, 'overloaded-transform' => $overloaded_new, 'new-transform' => $new)); $this->assertIdentical($def1->child, $new); $this->assertIdentical($def1->content_model, 'old | new'); $this->assertIdentical($def1->content_model_type, $overloaded_new); $this->assertIdentical($def1->descendants_are_inline, true); $this->assertIdentical($def1->excludes, array('old' => true, 'new' => true)); }
/** * Convenience function that sets up a new element * * @param $element Name of element to add * @param $type What content set should element be registered to? * Set as false to skip this step. * @param $contents Allowed children in form of: * "$content_model_type: $content_model" * @param $attr_includes What attribute collections to register to * element? * @param $attr What unique attributes does the element define? * * @note See ElementDef for in-depth descriptions of these parameters. * @return Created element definition object, so you * can set advanced parameters */ public function addElement($element, $type, $contents, $attr_includes = array(), $attr = array()) { $this->elements[] = $element; // parse content_model list($content_model_type, $content_model) = $this->parseContents($contents); // merge in attribute inclusions $this->mergeInAttrIncludes($attr, $attr_includes); // add element to content sets if ($type) { $this->addElementToContentSet($element, $type); } // create element $this->info[$element] = HTMLPurifier_ElementDef::create($content_model, $content_model_type, $attr); // literal object $contents means direct child manipulation if (!is_string($contents)) { $this->info[$element]->child = $contents; } return $this->info[$element]; }
public function setup($config) { $newObject = HTMLPurifier_ElementDef::create(null, null, array('type' => 'Enum#application/x-shockwave-flash,image/svg+xml', 'width' => 'Length#1280', 'height' => 'Length#1920')); parent::setup($config); $object =& $this->info['object']; $object->mergeIn($newObject); $param =& $this->info['param']; $param->attr_transform_post[count($param->attr_transform_post) - 1] = new OC_HTMLPurifier_AttrTransform_SafeParam(); unset($this->info_injector[count($this->info_injector) - 1]); $this->info_injector[] = new OC_HTMLPurifier_Injector_SafeObject(); }
public function addElement($element, $type, $contents, $attr_includes = array(), $attr = array()) { $this->elements[] = $element; list($content_model_type, $content_model) = $this->parseContents($contents); $this->mergeInAttrIncludes($attr, $attr_includes); if ($type) { $this->addElementToContentSet($element, $type); } $this->info[$element] = HTMLPurifier_ElementDef::create($content_model, $content_model_type, $attr); if (!is_string($contents)) { $this->info[$element]->child = $contents; } return $this->info[$element]; }