1<?php 2 3class ValueContentItem { 4 function ValueContentItem() { 5 } 6 7 function parse($string) { 8 $subclasses = array('ValueContentItemString', 9 'ValueContentItemUri', 10 'ValueContentItemCounter', 11 'ValueContentItemAttr', 12 'ValueContentItemOpenQuote', 13 'ValueContentItemCloseQuote', 14 'ValueContentItemNoOpenQuote', 15 'ValueContentItemNoCloseQuote'); 16 17 foreach ($subclasses as $subclass) { 18 $result = call_user_func(array($subclass, 'parse'), $string); 19 $rest = $result['rest']; 20 $item =& $result['item']; 21 22 if (!is_null($item)) { 23 return array('item' => &$item, 24 'rest' => $rest); 25 }; 26 }; 27 28 $null = null; 29 return array('item' => &$null, 30 'rest' => $string); 31 } 32 33 function render(&$counters) { 34 // abstract 35 } 36} 37 38class ValueContentItemString extends ValueContentItem { 39 var $_value; 40 41 function ValueContentItemString() { 42 $this->ValueContentItem(); 43 } 44 45 function ©() { 46 $copy =& new ValueContentItemString(); 47 $copy->set_value($this->get_value()); 48 return $copy; 49 } 50 51 function get_value() { 52 return $this->_value; 53 } 54 55 function parse($string) { 56 list($value, $rest) = CSS::parse_string($string); 57 if (!is_null($value)) { 58 $item =& new ValueContentItemString(); 59 $item->set_value(substr($value, 1, strlen($value)-2)); 60 return array('item' => &$item, 61 'rest' => $rest); 62 }; 63 64 $null = null; 65 return array('item' => &$null, 'rest' => $string); 66 } 67 68 function render(&$counters) { 69 return css_process_escapes($this->_value); 70 } 71 72 function set_value($value) { 73 $this->_value = $value; 74 } 75} 76 77class ValueContentItemUri extends ValueContentItem { 78 var $_value; 79 80 function ValueContentItemUri() { 81 $this->ValueContentItem(); 82 } 83 84 function ©() { 85 $copy =& new ValueContentItemUri(); 86 return $copy; 87 } 88 89 function parse($string) { 90 $null = null; 91 return array('item' => &$null, 'rest' => $string); 92 } 93 94 function render(&$counters) { 95 return ''; 96 } 97} 98 99class ValueContentItemCounter extends ValueContentItem { 100 var $_name; 101 102 function ValueContentItemCounter() { 103 $this->ValueContentItem(); 104 } 105 106 function ©() { 107 $copy =& new ValueContentItemCounter(); 108 $copy->set_name($this->get_name()); 109 return $copy; 110 } 111 112 function get_name() { 113 return $this->_name; 114 } 115 116 function parse($string) { 117 if (preg_match('/^\s*counter\(('.CSS_IDENT_REGEXP.')\)\s*(.*)$/', $string, $matches)) { 118 $value = $matches[1]; 119 $rest = $matches[2]; 120 121 $item =& new ValueContentItemCounter(); 122 $item->set_name($value); 123 return array('item' => &$item, 124 'rest' => $rest); 125 }; 126 127 $null = null; 128 return array('item' => &$null, 'rest' => $string); 129 } 130 131 function render(&$counters) { 132 $counter =& $counters->get($this->get_name()); 133 if (is_null($counter)) { 134 return ''; 135 }; 136 137 return $counter->get(); 138 } 139 140 function set_name($value) { 141 $this->_name = $value; 142 } 143} 144 145class ValueContentItemAttr extends ValueContentItem { 146 function ValueContentItemAttr() { 147 $this->ValueContentItem(); 148 } 149 150 function ©() { 151 $copy =& new ValueContentItemAttr(); 152 return $copy; 153 } 154 155 function parse($string) { 156 $null = null; 157 return array('item' => &$null, 'rest' => $string); 158 } 159 160 function render(&$counters) { 161 return ''; 162 } 163} 164 165class ValueContentItemOpenQuote extends ValueContentItem { 166 function ValueContentItemOpenQuote() { 167 $this->ValueContentItem(); 168 } 169 170 function ©() { 171 $copy =& new ValueContentItemOpenQuote(); 172 return $copy; 173 } 174 175 function parse($string) { 176 $null = null; 177 return array('item' => &$null, 'rest' => $string); 178 } 179 180 function render(&$counters) { 181 return ''; 182 } 183} 184 185class ValueContentItemCloseQuote extends ValueContentItem { 186 function ValueContentItemCloseQuote() { 187 $this->ValueContentItem(); 188 } 189 190 function ©() { 191 $copy =& new ValueContentItemCloseQuote(); 192 return $copy; 193 } 194 195 function parse($string) { 196 $null = null; 197 return array('item' => &$null, 'rest' => $string); 198 } 199 200 function render(&$counters) { 201 return ''; 202 } 203} 204 205class ValueContentItemNoOpenQuote extends ValueContentItem { 206 function ValueContentItemNoOpenQuote() { 207 $this->ValueContentItem(); 208 } 209 210 function ©() { 211 $copy =& new ValueContentItemNoOpenQuote(); 212 return $copy; 213 } 214 215 function parse($string) { 216 $null = null; 217 return array('item' => &$null, 'rest' => $string); 218 } 219 220 function render(&$counters) { 221 return ''; 222 } 223} 224 225class ValueContentItemNoCloseQuote extends ValueContentItem { 226 function ValueContentItemNoCloseQuote() { 227 $this->ValueContentItem(); 228 } 229 230 function ©() { 231 $copy =& new ValueContentItemNoCloseQuote(); 232 return $copy; 233 } 234 235 function parse($string) { 236 $null = null; 237 return array('item' => &$null, 'rest' => $string); 238 } 239 240 function render(&$counters) { 241 return ''; 242 } 243} 244 245?>