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