PHPIDS
Current file: /home/mario/workspace/php-ids.org/trunk/lib/IDS/vendors/htmlpurifier/HTMLPurifier/AttrDef/CSS/Background.php
Legend: executed not executed dead code

  Coverage
  Classes Methods Lines
Total
100.00 %100.00%
100.00% 1 / 1
0.00 %0.00%
0.00% 0 / 2
2.33 %2.33%
2.33% 1 / 43
 
HTMLPurifier_AttrDef_CSS_Background
100.00 %100.00%
100.00% 1 / 1
0.00 %0.00%
0.00% 0 / 2
2.33 %2.33%
2.33% 1 / 43
 public function __construct($config)
0.00 %0.00%
0.00% 0 / 1
100.00 %100.00%
100.00% 0 / 0
 public function validate($string, $config, $context)
0.00 %0.00%
0.00% 0 / 1
0.00 %0.00%
0.00% 0 / 42


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

Generated by PHPUnit 3.3.1 and Xdebug 2.0.2 at Thu Sep 25 18:42:10 CEST 2008.