|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00007 class HTMLPurifier_AttrDef_CSS_Background extends HTMLPurifier_AttrDef 00008 { 00009 00014 protected $info; 00015 00016 public function __construct($config) { 00017 $def = $config->getCSSDefinition(); 00018 $this->info['background-color'] = $def->info['background-color']; 00019 $this->info['background-image'] = $def->info['background-image']; 00020 $this->info['background-repeat'] = $def->info['background-repeat']; 00021 $this->info['background-attachment'] = $def->info['background-attachment']; 00022 $this->info['background-position'] = $def->info['background-position']; 00023 } 00024 00025 public function validate($string, $config, $context) { 00026 00027 // regular pre-processing 00028 $string = $this->parseCDATA($string); 00029 if ($string === '') return false; 00030 00031 // munge rgb() decl if necessary 00032 $string = $this->mungeRgb($string); 00033 00034 // assumes URI doesn't have spaces in it 00035 $bits = explode(' ', strtolower($string)); // bits to process 00036 00037 $caught = array(); 00038 $caught['color'] = false; 00039 $caught['image'] = false; 00040 $caught['repeat'] = false; 00041 $caught['attachment'] = false; 00042 $caught['position'] = false; 00043 00044 $i = 0; // number of catches 00045 $none = false; 00046 00047 foreach ($bits as $bit) { 00048 if ($bit === '') continue; 00049 foreach ($caught as $key => $status) { 00050 if ($key != 'position') { 00051 if ($status !== false) continue; 00052 $r = $this->info['background-' . $key]->validate($bit, $config, $context); 00053 } else { 00054 $r = $bit; 00055 } 00056 if ($r === false) continue; 00057 if ($key == 'position') { 00058 if ($caught[$key] === false) $caught[$key] = ''; 00059 $caught[$key] .= $r . ' '; 00060 } else { 00061 $caught[$key] = $r; 00062 } 00063 $i++; 00064 break; 00065 } 00066 } 00067 00068 if (!$i) return false; 00069 if ($caught['position'] !== false) { 00070 $caught['position'] = $this->info['background-position']-> 00071 validate($caught['position'], $config, $context); 00072 } 00073 00074 $ret = array(); 00075 foreach ($caught as $value) { 00076 if ($value === false) continue; 00077 $ret[] = $value; 00078 } 00079 00080 if (empty($ret)) return false; 00081 return implode(' ', $ret); 00082 00083 } 00084 00085 } 00086 00087 // vim: et sw=4 sts=4