Source for file AttrCollections.php

Documentation is available at AttrCollections.php

  1. <?php
  2.  
  3. /**
  4.  * Defines common attribute collections that modules reference
  5.  */
  6.  
  7. {
  8.     
  9.     /**
  10.      * Associative array of attribute collections, indexed by name
  11.      */
  12.     public $info = array();
  13.     
  14.     /**
  15.      * Performs all expansions on internal data for use by other inclusions
  16.      * It also collects all attribute collection extensions from
  17.      * modules
  18.      * @param $attr_types HTMLPurifier_AttrTypes instance
  19.      * @param $modules Hash array of HTMLPurifier_HTMLModule members
  20.      */
  21.     public function __construct($attr_types$modules{
  22.         // load extensions from the modules
  23.         foreach ($modules as $module{
  24.             foreach ($module->attr_collections as $coll_i => $coll{
  25.                 if (!isset($this->info[$coll_i])) {
  26.                     $this->info[$coll_iarray();
  27.                 }
  28.                 foreach ($coll as $attr_i => $attr{
  29.                     if ($attr_i === && isset($this->info[$coll_i][$attr_i])) {
  30.                         // merge in includes
  31.                         $this->info[$coll_i][$attr_iarray_merge(
  32.                             $this->info[$coll_i][$attr_i]$attr);
  33.                         continue;
  34.                     }
  35.                     $this->info[$coll_i][$attr_i$attr;
  36.                 }
  37.             }
  38.         }
  39.         // perform internal expansions and inclusions
  40.         foreach ($this->info as $name => $attr{
  41.             // merge attribute collections that include others
  42.             $this->performInclusions($this->info[$name]);
  43.             // replace string identifiers with actual attribute objects
  44.             $this->expandIdentifiers($this->info[$name]$attr_types);
  45.         }
  46.     }
  47.     
  48.     /**
  49.      * Takes a reference to an attribute associative array and performs
  50.      * all inclusions specified by the zero index.
  51.      * @param &$attr Reference to attribute array
  52.      */
  53.     public function performInclusions(&$attr{
  54.         if (!isset($attr[0])) return;
  55.         $merge $attr[0];
  56.         $seen  array()// recursion guard
  57.         // loop through all the inclusions
  58.         for ($i 0isset($merge[$i])$i++{
  59.             if (isset($seen[$merge[$i]])) continue;
  60.             $seen[$merge[$i]] true;
  61.             // foreach attribute of the inclusion, copy it over
  62.             if (!isset($this->info[$merge[$i]])) continue;
  63.             foreach ($this->info[$merge[$i]] as $key => $value{
  64.                 if (isset($attr[$key])) continue// also catches more inclusions
  65.                 $attr[$key$value;
  66.             }
  67.             if (isset($this->info[$merge[$i]][0])) {
  68.                 // recursion
  69.                 $merge array_merge($merge$this->info[$merge[$i]][0]);
  70.             }
  71.         }
  72.         unset($attr[0]);
  73.     }
  74.     
  75.     /**
  76.      * Expands all string identifiers in an attribute array by replacing
  77.      * them with the appropriate values inside HTMLPurifier_AttrTypes
  78.      * @param &$attr Reference to attribute array
  79.      * @param $attr_types HTMLPurifier_AttrTypes instance
  80.      */
  81.     public function expandIdentifiers(&$attr$attr_types{
  82.         
  83.         // because foreach will process new elements we add, make sure we
  84.         // skip duplicates
  85.         $processed array();
  86.         
  87.         foreach ($attr as $def_i => $def{
  88.             // skip inclusions
  89.             if ($def_i === 0continue;
  90.             
  91.             if (isset($processed[$def_i])) continue;
  92.             
  93.             // determine whether or not attribute is required
  94.             if ($required (strpos($def_i'*'!== false)) {
  95.                 // rename the definition
  96.                 unset($attr[$def_i]);
  97.                 $def_i trim($def_i'*');
  98.                 $attr[$def_i$def;
  99.             }
  100.             
  101.             $processed[$def_itrue;
  102.             
  103.             // if we've already got a literal object, move on
  104.             if (is_object($def)) {
  105.                 // preserve previous required
  106.                 $attr[$def_i]->required ($required || $attr[$def_i]->required);
  107.                 continue;
  108.             }
  109.             
  110.             if ($def === false{
  111.                 unset($attr[$def_i]);
  112.                 continue;
  113.             }
  114.             
  115.             if ($t $attr_types->get($def)) {
  116.                 $attr[$def_i$t;
  117.                 $attr[$def_i]->required $required;
  118.             else {
  119.                 unset($attr[$def_i]);
  120.             }
  121.         }
  122.         
  123.     }
  124.     
  125. }

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