Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / lib / htmlpurifier / HTMLPurifier / AttrDef / CSS / ListStyle.php
blob2d2ed12da68756d4f89e8a969d1b04048764e51b
1 <?php
3 require_once 'HTMLPurifier/AttrDef.php';
5 /**
6 * Validates shorthand CSS property list-style.
7 * @warning Does not support url tokens that have internal spaces.
8 */
9 class HTMLPurifier_AttrDef_CSS_ListStyle extends HTMLPurifier_AttrDef
12 /**
13 * Local copy of component validators.
14 * @note See HTMLPurifier_AttrDef_CSS_Font::$info for a similar impl.
16 var $info;
18 function HTMLPurifier_AttrDef_CSS_ListStyle($config) {
19 $def = $config->getCSSDefinition();
20 $this->info['list-style-type'] = $def->info['list-style-type'];
21 $this->info['list-style-position'] = $def->info['list-style-position'];
22 $this->info['list-style-image'] = $def->info['list-style-image'];
25 function validate($string, $config, &$context) {
27 // regular pre-processing
28 $string = $this->parseCDATA($string);
29 if ($string === '') return false;
31 // assumes URI doesn't have spaces in it
32 $bits = explode(' ', strtolower($string)); // bits to process
34 $caught = array();
35 $caught['type'] = false;
36 $caught['position'] = false;
37 $caught['image'] = false;
39 $i = 0; // number of catches
40 $none = false;
42 foreach ($bits as $bit) {
43 if ($i >= 3) return; // optimization bit
44 if ($bit === '') continue;
45 foreach ($caught as $key => $status) {
46 if ($status !== false) continue;
47 $r = $this->info['list-style-' . $key]->validate($bit, $config, $context);
48 if ($r === false) continue;
49 if ($r === 'none') {
50 if ($none) continue;
51 else $none = true;
52 if ($key == 'image') continue;
54 $caught[$key] = $r;
55 $i++;
56 break;
60 if (!$i) return false;
62 $ret = array();
64 // construct type
65 if ($caught['type']) $ret[] = $caught['type'];
67 // construct image
68 if ($caught['image']) $ret[] = $caught['image'];
70 // construct position
71 if ($caught['position']) $ret[] = $caught['position'];
73 if (empty($ret)) return false;
74 return implode(' ', $ret);