ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
ListStyle.php
Go to the documentation of this file.
1 <?php
2 
8 {
9 
14  protected $info;
15 
16  public function __construct($config) {
17  $def = $config->getCSSDefinition();
18  $this->info['list-style-type'] = $def->info['list-style-type'];
19  $this->info['list-style-position'] = $def->info['list-style-position'];
20  $this->info['list-style-image'] = $def->info['list-style-image'];
21  }
22 
23  public function validate($string, $config, $context) {
24 
25  // regular pre-processing
26  $string = $this->parseCDATA($string);
27  if ($string === '') return false;
28 
29  // assumes URI doesn't have spaces in it
30  $bits = explode(' ', strtolower($string)); // bits to process
31 
32  $caught = array();
33  $caught['type'] = false;
34  $caught['position'] = false;
35  $caught['image'] = false;
36 
37  $i = 0; // number of catches
38  $none = false;
39 
40  foreach ($bits as $bit) {
41  if ($i >= 3) return; // optimization bit
42  if ($bit === '') continue;
43  foreach ($caught as $key => $status) {
44  if ($status !== false) continue;
45  $r = $this->info['list-style-' . $key]->validate($bit, $config, $context);
46  if ($r === false) continue;
47  if ($r === 'none') {
48  if ($none) continue;
49  else $none = true;
50  if ($key == 'image') continue;
51  }
52  $caught[$key] = $r;
53  $i++;
54  break;
55  }
56  }
57 
58  if (!$i) return false;
59 
60  $ret = array();
61 
62  // construct type
63  if ($caught['type']) $ret[] = $caught['type'];
64 
65  // construct image
66  if ($caught['image']) $ret[] = $caught['image'];
67 
68  // construct position
69  if ($caught['position']) $ret[] = $caught['position'];
70 
71  if (empty($ret)) return false;
72  return implode(' ', $ret);
73 
74  }
75 
76 }
77 
78 // vim: et sw=4 sts=4