[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/libraries/htmlpurifier/library/HTMLPurifier/ -> ElementDef.php (source)

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


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1