Source for file ElementDef.php

Documentation is available at ElementDef.php

  1. <?php
  2.  
  3. /**
  4.  * Structure that stores an HTML element definition. Used by
  5.  * HTMLPurifier_HTMLDefinition and HTMLPurifier_HTMLModule.
  6.  * @note This class is inspected by HTMLPurifier_Printer_HTMLDefinition.
  7.  *        Please update that class too.
  8.  */
  9. {
  10.     
  11.     /**
  12.      * Does the definition work by itself, or is it created solely
  13.      * for the purpose of merging into another definition?
  14.      */
  15.     public $standalone = true;
  16.     
  17.     /**
  18.      * Associative array of attribute name to HTMLPurifier_AttrDef
  19.      * @note Before being processed by HTMLPurifier_AttrCollections
  20.      *        when modules are finalized during
  21.      *        HTMLPurifier_HTMLDefinition->setup(), this array may also
  22.      *        contain an array at index 0 that indicates which attribute
  23.      *        collections to load into the full array. It may also
  24.      *        contain string indentifiers in lieu of HTMLPurifier_AttrDef,
  25.      *        see HTMLPurifier_AttrTypes on how they are expanded during
  26.      *        HTMLPurifier_HTMLDefinition->setup() processing.
  27.      */
  28.     public $attr = array();
  29.     
  30.     /**
  31.      * Indexed list of tag's HTMLPurifier_AttrTransform to be done before validation
  32.      */
  33.     public $attr_transform_pre = array();
  34.     
  35.     /**
  36.      * Indexed list of tag's HTMLPurifier_AttrTransform to be done after validation
  37.      */
  38.     public $attr_transform_post = array();
  39.     
  40.     /**
  41.      * HTMLPurifier_ChildDef of this tag.
  42.      */
  43.     public $child;
  44.     
  45.     /**
  46.      * Abstract string representation of internal ChildDef rules. See
  47.      * HTMLPurifier_ContentSets for how this is parsed and then transformed
  48.      * into an HTMLPurifier_ChildDef.
  49.      * @warning This is a temporary variable that is not available after
  50.      *       being processed by HTMLDefinition
  51.      */
  52.     public $content_model;
  53.     
  54.     /**
  55.      * Value of $child->type, used to determine which ChildDef to use,
  56.      * used in combination with $content_model.
  57.      * @warning This must be lowercase
  58.      * @warning This is a temporary variable that is not available after
  59.      *       being processed by HTMLDefinition
  60.      */
  61.     public $content_model_type;
  62.     
  63.     
  64.     
  65.     /**
  66.      * Does the element have a content model (#PCDATA | Inline)*? This
  67.      * is important for chameleon ins and del processing in
  68.      * HTMLPurifier_ChildDef_Chameleon. Dynamically set: modules don't
  69.      * have to worry about this one.
  70.      */
  71.     public $descendants_are_inline = false;
  72.     
  73.     /**
  74.      * List of the names of required attributes this element has. Dynamically
  75.      * populated by HTMLPurifier_HTMLDefinition::getElement
  76.      */
  77.     public $required_attr = array();
  78.     
  79.     /**
  80.      * Lookup table of tags excluded from all descendants of this tag.
  81.      * @note SGML permits exclusions for all descendants, but this is
  82.      *        not possible with DTDs or XML Schemas. W3C has elected to
  83.      *        use complicated compositions of content_models to simulate
  84.      *        exclusion for children, but we go the simpler, SGML-style
  85.      *        route of flat-out exclusions, which correctly apply to
  86.      *        all descendants and not just children. Note that the XHTML
  87.      *        Modularization Abstract Modules are blithely unaware of such
  88.      *        distinctions.
  89.      */
  90.     public $excludes = array();
  91.     
  92.     /**
  93.      * Low-level factory constructor for creating new standalone element defs
  94.      */
  95.     public static function create($content_model$content_model_type$attr{
  96.         $def new HTMLPurifier_ElementDef();
  97.         $def->content_model $content_model;
  98.         $def->content_model_type $content_model_type;
  99.         $def->attr $attr;
  100.         return $def;
  101.     }
  102.     
  103.     /**
  104.      * Merges the values of another element definition into this one.
  105.      * Values from the new element def take precedence if a value is
  106.      * not mergeable.
  107.      */
  108.     public function mergeIn($def{
  109.         
  110.         // later keys takes precedence
  111.         foreach($def->attr as $k => $v{
  112.             if ($k === 0{
  113.                 // merge in the includes
  114.                 // sorry, no way to override an include
  115.                 foreach ($v as $v2{
  116.                     $this->attr[0][$v2;
  117.                 }
  118.                 continue;
  119.             }
  120.             if ($v === false{
  121.                 if (isset($this->attr[$k])) unset($this->attr[$k]);
  122.                 continue;
  123.             }
  124.             $this->attr[$k$v;
  125.         }
  126.         $this->_mergeAssocArray($this->attr_transform_pre$def->attr_transform_pre);
  127.         $this->_mergeAssocArray($this->attr_transform_post$def->attr_transform_post);
  128.         $this->_mergeAssocArray($this->excludes$def->excludes);
  129.         
  130.         if(!empty($def->content_model)) {
  131.             $this->content_model .= ' | ' $def->content_model;
  132.             $this->child = false;
  133.         }
  134.         if(!empty($def->content_model_type)) {
  135.             $this->content_model_type = $def->content_model_type;
  136.             $this->child = false;
  137.         }
  138.         if(!is_null($def->child)) $this->child = $def->child;
  139.         if($def->descendants_are_inline$this->descendants_are_inline = $def->descendants_are_inline;
  140.         
  141.     }
  142.     
  143.     /**
  144.      * Merges one array into another, removes values which equal false
  145.      * @param $a1 Array by reference that is merged into
  146.      * @param $a2 Array that merges into $a1
  147.      */
  148.     private function _mergeAssocArray(&$a1$a2{
  149.         foreach ($a2 as $k => $v{
  150.             if ($v === false{
  151.                 if (isset($a1[$k])) unset($a1[$k]);
  152.                 continue;
  153.             }
  154.             $a1[$k$v;
  155.         }
  156.     }
  157.     
  158. }

Documentation generated on Thu, 19 Jun 2008 18:49:06 -0400 by phpDocumentor 1.4.2