Source for file Background.php

Documentation is available at Background.php

  1. <?php
  2.  
  3. /**
  4.  * Validates shorthand CSS property background.
  5.  * @warning Does not support url tokens that have internal spaces.
  6.  */
  7. {
  8.     
  9.     /**
  10.      * Local copy of component validators.
  11.      * @note See HTMLPurifier_AttrDef_Font::$info for a similar impl.
  12.      */
  13.     protected $info;
  14.     
  15.     public function __construct($config{
  16.         $def $config->getCSSDefinition();
  17.         $this->info['background-color'$def->info['background-color'];
  18.         $this->info['background-image'$def->info['background-image'];
  19.         $this->info['background-repeat'$def->info['background-repeat'];
  20.         $this->info['background-attachment'$def->info['background-attachment'];
  21.         $this->info['background-position'$def->info['background-position'];
  22.     }
  23.     
  24.     public function validate($string$config$context{
  25.         
  26.         // regular pre-processing
  27.         $string $this->parseCDATA($string);
  28.         if ($string === ''return false;
  29.         
  30.         // munge rgb() decl if necessary
  31.         $string $this->mungeRgb($string);
  32.         
  33.         // assumes URI doesn't have spaces in it
  34.         $bits explode(' 'strtolower($string))// bits to process
  35.         
  36.         $caught array();
  37.         $caught['color']    false;
  38.         $caught['image']    false;
  39.         $caught['repeat']   false;
  40.         $caught['attachment'false;
  41.         $caught['position'false;
  42.         
  43.         $i 0// number of catches
  44.         $none false;
  45.         
  46.         foreach ($bits as $bit{
  47.             if ($bit === ''continue;
  48.             foreach ($caught as $key => $status{
  49.                 if ($key != 'position'{
  50.                     if ($status !== falsecontinue;
  51.                     $r $this->info['background-' $key]->validate($bit$config$context);
  52.                 else {
  53.                     $r $bit;
  54.                 }
  55.                 if ($r === falsecontinue;
  56.                 if ($key == 'position'{
  57.                     if ($caught[$key=== false$caught[$key'';
  58.                     $caught[$key.= $r ' ';
  59.                 else {
  60.                     $caught[$key$r;
  61.                 }
  62.                 $i++;
  63.                 break;
  64.             }
  65.         }
  66.         
  67.         if (!$ireturn false;
  68.         if ($caught['position'!== false{
  69.             $caught['position'$this->info['background-position']->
  70.                 validate($caught['position']$config$context);
  71.         }
  72.         
  73.         $ret array();
  74.         foreach ($caught as $value{
  75.             if ($value === falsecontinue;
  76.             $ret[$value;
  77.         }
  78.         
  79.         if (empty($ret)) return false;
  80.         return implode(' '$ret);
  81.         
  82.     }
  83.     
  84. }

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