@@ -480,7 +480,7 @@ |
||
480 | 480 | /** |
481 | 481 | * Closing tag handler - called from HTMLSax |
482 | 482 | * |
483 | - * @param object $parsers HTML parser |
|
483 | + * @param object $parser HTML parser |
|
484 | 484 | * @param string $name tag name |
485 | 485 | * @return boolean |
486 | 486 | * @access private |
@@ -57,622 +57,622 @@ |
||
57 | 57 | */ |
58 | 58 | class TSafeHtmlParser |
59 | 59 | { |
60 | - /** |
|
61 | - * Storage for resulting HTML output |
|
62 | - * |
|
63 | - * @var string |
|
64 | - * @access private |
|
65 | - */ |
|
66 | - private $_xhtml = ''; |
|
67 | - |
|
68 | - /** |
|
69 | - * Array of counters for each tag |
|
70 | - * |
|
71 | - * @var array |
|
72 | - * @access private |
|
73 | - */ |
|
74 | - private $_counter = array(); |
|
75 | - |
|
76 | - /** |
|
77 | - * Stack of unclosed tags |
|
78 | - * |
|
79 | - * @var array |
|
80 | - * @access private |
|
81 | - */ |
|
82 | - private $_stack = array(); |
|
83 | - |
|
84 | - /** |
|
85 | - * Array of counters for tags that must be deleted with all content |
|
86 | - * |
|
87 | - * @var array |
|
88 | - * @access private |
|
89 | - */ |
|
90 | - private $_dcCounter = array(); |
|
91 | - |
|
92 | - /** |
|
93 | - * Stack of unclosed tags that must be deleted with all content |
|
94 | - * |
|
95 | - * @var array |
|
96 | - * @access private |
|
97 | - */ |
|
98 | - private $_dcStack = array(); |
|
99 | - |
|
100 | - /** |
|
101 | - * Stores level of list (ol/ul) nesting |
|
102 | - * |
|
103 | - * @var int |
|
104 | - * @access private |
|
105 | - */ |
|
106 | - private $_listScope = 0; |
|
107 | - |
|
108 | - /** |
|
109 | - * Stack of unclosed list tags |
|
110 | - * |
|
111 | - * @var array |
|
112 | - * @access private |
|
113 | - */ |
|
114 | - private $_liStack = array(); |
|
115 | - |
|
116 | - /** |
|
117 | - * Array of prepared regular expressions for protocols (schemas) matching |
|
118 | - * |
|
119 | - * @var array |
|
120 | - * @access private |
|
121 | - */ |
|
122 | - private $_protoRegexps = array(); |
|
123 | - |
|
124 | - /** |
|
125 | - * Array of prepared regular expressions for CSS matching |
|
126 | - * |
|
127 | - * @var array |
|
128 | - * @access private |
|
129 | - */ |
|
130 | - private $_cssRegexps = array(); |
|
131 | - |
|
132 | - /** |
|
133 | - * List of single tags ("<tag />") |
|
134 | - * |
|
135 | - * @var array |
|
136 | - * @access public |
|
137 | - */ |
|
138 | - public $singleTags = array('area', 'br', 'img', 'input', 'hr', 'wbr', ); |
|
139 | - |
|
140 | - /** |
|
141 | - * List of dangerous tags (such tags will be deleted) |
|
142 | - * |
|
143 | - * @var array |
|
144 | - * @access public |
|
145 | - */ |
|
146 | - public $deleteTags = array( |
|
147 | - 'applet', 'base', 'basefont', 'bgsound', 'blink', 'body', |
|
148 | - 'embed', 'frame', 'frameset', 'head', 'html', 'ilayer', |
|
149 | - 'iframe', 'layer', 'link', 'meta', 'object', 'style', |
|
150 | - 'title', 'script', |
|
151 | - ); |
|
152 | - |
|
153 | - /** |
|
154 | - * List of dangerous tags (such tags will be deleted, and all content |
|
155 | - * inside this tags will be also removed) |
|
156 | - * |
|
157 | - * @var array |
|
158 | - * @access public |
|
159 | - */ |
|
160 | - public $deleteTagsContent = array('script', 'style', 'title', 'xml', ); |
|
161 | - |
|
162 | - /** |
|
163 | - * Type of protocols filtering ('white' or 'black') |
|
164 | - * |
|
165 | - * @var string |
|
166 | - * @access public |
|
167 | - */ |
|
168 | - public $protocolFiltering = 'white'; |
|
169 | - |
|
170 | - /** |
|
171 | - * List of "dangerous" protocols (used for blacklist-filtering) |
|
172 | - * |
|
173 | - * @var array |
|
174 | - * @access public |
|
175 | - */ |
|
176 | - public $blackProtocols = array( |
|
177 | - 'about', 'chrome', 'data', 'disk', 'hcp', |
|
178 | - 'help', 'javascript', 'livescript', 'lynxcgi', 'lynxexec', |
|
179 | - 'ms-help', 'ms-its', 'mhtml', 'mocha', 'opera', |
|
180 | - 'res', 'resource', 'shell', 'vbscript', 'view-source', |
|
181 | - 'vnd.ms.radio', 'wysiwyg', |
|
182 | - ); |
|
183 | - |
|
184 | - /** |
|
185 | - * List of "safe" protocols (used for whitelist-filtering) |
|
186 | - * |
|
187 | - * @var array |
|
188 | - * @access public |
|
189 | - */ |
|
190 | - public $whiteProtocols = array( |
|
191 | - 'ed2k', 'file', 'ftp', 'gopher', 'http', 'https', |
|
192 | - 'irc', 'mailto', 'news', 'nntp', 'telnet', 'webcal', |
|
193 | - 'xmpp', 'callto', |
|
194 | - ); |
|
195 | - |
|
196 | - /** |
|
197 | - * List of attributes that can contain protocols |
|
198 | - * |
|
199 | - * @var array |
|
200 | - * @access public |
|
201 | - */ |
|
202 | - public $protocolAttributes = array( |
|
203 | - 'action', 'background', 'codebase', 'dynsrc', 'href', 'lowsrc', 'src', |
|
204 | - ); |
|
205 | - |
|
206 | - /** |
|
207 | - * List of dangerous CSS keywords |
|
208 | - * |
|
209 | - * Whole style="" attribute will be removed, if parser will find one of |
|
210 | - * these keywords |
|
211 | - * |
|
212 | - * @var array |
|
213 | - * @access public |
|
214 | - */ |
|
215 | - public $cssKeywords = array( |
|
216 | - 'absolute', 'behavior', 'behaviour', 'content', 'expression', |
|
217 | - 'fixed', 'include-source', 'moz-binding', |
|
218 | - ); |
|
219 | - |
|
220 | - /** |
|
221 | - * List of tags that can have no "closing tag" |
|
222 | - * |
|
223 | - * @var array |
|
224 | - * @access public |
|
225 | - * @deprecated XHTML does not allow such tags |
|
226 | - */ |
|
227 | - public $noClose = array(); |
|
228 | - |
|
229 | - /** |
|
230 | - * List of block-level tags that terminates paragraph |
|
231 | - * |
|
232 | - * Paragraph will be closed when this tags opened |
|
233 | - * |
|
234 | - * @var array |
|
235 | - * @access public |
|
236 | - */ |
|
237 | - public $closeParagraph = array( |
|
238 | - 'address', 'blockquote', 'center', 'dd', 'dir', 'div', |
|
239 | - 'dl', 'dt', 'h1', 'h2', 'h3', 'h4', |
|
240 | - 'h5', 'h6', 'hr', 'isindex', 'listing', 'marquee', |
|
241 | - 'menu', 'multicol', 'ol', 'p', 'plaintext', 'pre', |
|
242 | - 'table', 'ul', 'xmp', |
|
243 | - ); |
|
244 | - |
|
245 | - /** |
|
246 | - * List of table tags, all table tags outside a table will be removed |
|
247 | - * |
|
248 | - * @var array |
|
249 | - * @access public |
|
250 | - */ |
|
251 | - public $tableTags = array( |
|
252 | - 'caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th', |
|
253 | - 'thead', 'tr', |
|
254 | - ); |
|
255 | - |
|
256 | - /** |
|
257 | - * List of list tags |
|
258 | - * |
|
259 | - * @var array |
|
260 | - * @access public |
|
261 | - */ |
|
262 | - public $listTags = array('dir', 'menu', 'ol', 'ul', 'dl', ); |
|
263 | - |
|
264 | - /** |
|
265 | - * List of dangerous attributes |
|
266 | - * |
|
267 | - * @var array |
|
268 | - * @access public |
|
269 | - */ |
|
270 | - public $attributes = array('dynsrc'); |
|
271 | - //public $attributes = array('dynsrc', 'id', 'name', ); //id and name are dangerous? |
|
272 | - |
|
273 | - /** |
|
274 | - * List of allowed "namespaced" attributes |
|
275 | - * |
|
276 | - * @var array |
|
277 | - * @access public |
|
278 | - */ |
|
279 | - public $attributesNS = array('xml:lang', ); |
|
280 | - |
|
281 | - /** |
|
282 | - * Constructs class |
|
283 | - * |
|
284 | - * @access public |
|
285 | - */ |
|
286 | - public function __construct() |
|
287 | - { |
|
288 | - //making regular expressions based on Proto & CSS arrays |
|
289 | - foreach ($this->blackProtocols as $proto) { |
|
290 | - $preg = "/[\s\x01-\x1F]*"; |
|
291 | - for ($i=0; $i<strlen($proto); $i++) { |
|
292 | - $preg .= $proto{$i} . "[\s\x01-\x1F]*"; |
|
293 | - } |
|
294 | - $preg .= ":/i"; |
|
295 | - $this->_protoRegexps[] = $preg; |
|
296 | - } |
|
297 | - |
|
298 | - foreach ($this->cssKeywords as $css) { |
|
299 | - $this->_cssRegexps[] = '/' . $css . '/i'; |
|
300 | - } |
|
301 | - return true; |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * Handles the writing of attributes - called from $this->_openHandler() |
|
306 | - * |
|
307 | - * @param array $attrs array of attributes $name => $value |
|
308 | - * @return boolean |
|
309 | - * @access private |
|
310 | - */ |
|
311 | - private function _writeAttrs ($attrs) |
|
312 | - { |
|
313 | - if (is_array($attrs)) { |
|
314 | - foreach ($attrs as $name => $value) { |
|
315 | - |
|
316 | - $name = strtolower($name); |
|
317 | - |
|
318 | - if (strpos($name, 'on') === 0) { |
|
319 | - continue; |
|
320 | - } |
|
321 | - if (strpos($name, 'data') === 0) { |
|
322 | - continue; |
|
323 | - } |
|
324 | - if (in_array($name, $this->attributes)) { |
|
325 | - continue; |
|
326 | - } |
|
327 | - if (!preg_match("/^[a-z0-9]+$/i", $name)) { |
|
328 | - if (!in_array($name, $this->attributesNS)) |
|
329 | - { |
|
330 | - continue; |
|
331 | - } |
|
332 | - } |
|
333 | - |
|
334 | - if (($value === TRUE) || (is_null($value))) { |
|
335 | - $value = $name; |
|
336 | - } |
|
337 | - |
|
338 | - if ($name == 'style') { |
|
339 | - |
|
340 | - // removes insignificant backslahes |
|
341 | - $value = str_replace("\\", '', $value); |
|
342 | - |
|
343 | - // removes CSS comments |
|
344 | - while (1) |
|
345 | - { |
|
346 | - $_value = preg_replace("!/\*.*?\*/!s", '', $value); |
|
347 | - if ($_value == $value) break; |
|
348 | - $value = $_value; |
|
349 | - } |
|
350 | - |
|
351 | - // replace all & to & |
|
352 | - $value = str_replace('&', '&', $value); |
|
353 | - $value = str_replace('&', '&', $value); |
|
354 | - |
|
355 | - foreach ($this->_cssRegexps as $css) { |
|
356 | - if (preg_match($css, $value)) { |
|
357 | - continue 2; |
|
358 | - } |
|
359 | - } |
|
360 | - foreach ($this->_protoRegexps as $proto) { |
|
361 | - if (preg_match($proto, $value)) { |
|
362 | - continue 2; |
|
363 | - } |
|
364 | - } |
|
365 | - } |
|
366 | - |
|
367 | - $tempval = preg_replace_callback( |
|
368 | - '/&#(\d+);?/m', |
|
369 | - function ($matches) { |
|
370 | - return chr($matches[0]); |
|
371 | - }, |
|
372 | - $value |
|
373 | - ); //"' |
|
374 | - |
|
375 | - $tempval = preg_replace_callback( |
|
376 | - '/&#x([0-9a-f]+);?/mi', |
|
377 | - function ($matches) { |
|
378 | - return chr(hexdec($matches[0])); |
|
379 | - }, |
|
380 | - $tempval |
|
381 | - ); |
|
382 | - |
|
383 | - if ((in_array($name, $this->protocolAttributes)) && |
|
384 | - (strpos($tempval, ':') !== false)) |
|
385 | - { |
|
386 | - if ($this->protocolFiltering == 'black') { |
|
387 | - foreach ($this->_protoRegexps as $proto) { |
|
388 | - if (preg_match($proto, $tempval)) continue 2; |
|
389 | - } |
|
390 | - } else { |
|
391 | - $_tempval = explode(':', $tempval); |
|
392 | - $proto = $_tempval[0]; |
|
393 | - if (!in_array($proto, $this->whiteProtocols)) { |
|
394 | - continue; |
|
395 | - } |
|
396 | - } |
|
397 | - } |
|
398 | - |
|
399 | - $value = str_replace("\"", """, $value); |
|
400 | - $this->_xhtml .= ' ' . $name . '="' . $value . '"'; |
|
401 | - } |
|
402 | - } |
|
403 | - return true; |
|
404 | - } |
|
405 | - |
|
406 | - /** |
|
407 | - * Opening tag handler - called from HTMLSax |
|
408 | - * |
|
409 | - * @param object $parser HTML Parser |
|
410 | - * @param string $name tag name |
|
411 | - * @param array $attrs tag attributes |
|
412 | - * @return boolean |
|
413 | - * @access private |
|
414 | - */ |
|
415 | - public function _openHandler(&$parser, $name, $attrs) |
|
416 | - { |
|
417 | - $name = strtolower($name); |
|
418 | - |
|
419 | - if (in_array($name, $this->deleteTagsContent)) { |
|
420 | - array_push($this->_dcStack, $name); |
|
421 | - $this->_dcCounter[$name] = isset($this->_dcCounter[$name]) ? $this->_dcCounter[$name]+1 : 1; |
|
422 | - } |
|
423 | - if (count($this->_dcStack) != 0) { |
|
424 | - return true; |
|
425 | - } |
|
426 | - |
|
427 | - if (in_array($name, $this->deleteTags)) { |
|
428 | - return true; |
|
429 | - } |
|
430 | - |
|
431 | - if (!preg_match("/^[a-z0-9]+$/i", $name)) { |
|
432 | - if (preg_match("!(?:\@|://)!i", $name)) { |
|
433 | - $this->_xhtml .= '<' . $name . '>'; |
|
434 | - } |
|
435 | - return true; |
|
436 | - } |
|
437 | - |
|
438 | - if (in_array($name, $this->singleTags)) { |
|
439 | - $this->_xhtml .= '<' . $name; |
|
440 | - $this->_writeAttrs($attrs); |
|
441 | - $this->_xhtml .= ' />'; |
|
442 | - return true; |
|
443 | - } |
|
444 | - |
|
445 | - // TABLES: cannot open table elements when we are not inside table |
|
446 | - if ((isset($this->_counter['table'])) && ($this->_counter['table'] <= 0) |
|
447 | - && (in_array($name, $this->tableTags))) |
|
448 | - { |
|
449 | - return true; |
|
450 | - } |
|
451 | - |
|
452 | - // PARAGRAPHS: close paragraph when closeParagraph tags opening |
|
453 | - if ((in_array($name, $this->closeParagraph)) && (in_array('p', $this->_stack))) { |
|
454 | - $this->_closeHandler($parser, 'p'); |
|
455 | - } |
|
456 | - |
|
457 | - // LISTS: we should close <li> if <li> of the same level opening |
|
458 | - if ($name == 'li' && count($this->_liStack) && |
|
459 | - $this->_listScope == $this->_liStack[count($this->_liStack)-1]) |
|
460 | - { |
|
461 | - $this->_closeHandler($parser, 'li'); |
|
462 | - } |
|
463 | - |
|
464 | - // LISTS: we want to know on what nesting level of lists we are |
|
465 | - if (in_array($name, $this->listTags)) { |
|
466 | - $this->_listScope++; |
|
467 | - } |
|
468 | - if ($name == 'li') { |
|
469 | - array_push($this->_liStack, $this->_listScope); |
|
470 | - } |
|
471 | - |
|
472 | - $this->_xhtml .= '<' . $name; |
|
473 | - $this->_writeAttrs($attrs); |
|
474 | - $this->_xhtml .= '>'; |
|
475 | - array_push($this->_stack,$name); |
|
476 | - $this->_counter[$name] = isset($this->_counter[$name]) ? $this->_counter[$name]+1 : 1; |
|
477 | - return true; |
|
478 | - } |
|
479 | - |
|
480 | - /** |
|
481 | - * Closing tag handler - called from HTMLSax |
|
482 | - * |
|
483 | - * @param object $parsers HTML parser |
|
484 | - * @param string $name tag name |
|
485 | - * @return boolean |
|
486 | - * @access private |
|
487 | - */ |
|
488 | - public function _closeHandler(&$parser, $name) |
|
489 | - { |
|
490 | - |
|
491 | - $name = strtolower($name); |
|
492 | - |
|
493 | - if (isset($this->_dcCounter[$name]) && ($this->_dcCounter[$name] > 0) && |
|
494 | - (in_array($name, $this->deleteTagsContent))) |
|
495 | - { |
|
496 | - while ($name != ($tag = array_pop($this->_dcStack))) { |
|
497 | - $this->_dcCounter[$tag]--; |
|
498 | - } |
|
499 | - |
|
500 | - $this->_dcCounter[$name]--; |
|
501 | - } |
|
502 | - |
|
503 | - if (count($this->_dcStack) != 0) { |
|
504 | - return true; |
|
505 | - } |
|
506 | - |
|
507 | - if ((isset($this->_counter[$name])) && ($this->_counter[$name] > 0)) { |
|
508 | - while ($name != ($tag = array_pop($this->_stack))) { |
|
509 | - $this->_closeTag($tag); |
|
510 | - } |
|
511 | - |
|
512 | - $this->_closeTag($name); |
|
513 | - } |
|
514 | - return true; |
|
515 | - } |
|
516 | - |
|
517 | - /** |
|
518 | - * Closes tag |
|
519 | - * |
|
520 | - * @param string $tag tag name |
|
521 | - * @return boolean |
|
522 | - * @access private |
|
523 | - */ |
|
524 | - public function _closeTag($tag) |
|
525 | - { |
|
526 | - if (!in_array($tag, $this->noClose)) { |
|
527 | - $this->_xhtml .= '</' . $tag . '>'; |
|
528 | - } |
|
529 | - |
|
530 | - $this->_counter[$tag]--; |
|
531 | - |
|
532 | - if (in_array($tag, $this->listTags)) { |
|
533 | - $this->_listScope--; |
|
534 | - } |
|
535 | - |
|
536 | - if ($tag == 'li') { |
|
537 | - array_pop($this->_liStack); |
|
538 | - } |
|
539 | - return true; |
|
540 | - } |
|
541 | - |
|
542 | - /** |
|
543 | - * Character data handler - called from HTMLSax |
|
544 | - * |
|
545 | - * @param object $parser HTML parser |
|
546 | - * @param string $data textual data |
|
547 | - * @return boolean |
|
548 | - * @access private |
|
549 | - */ |
|
550 | - public function _dataHandler(&$parser, $data) |
|
551 | - { |
|
552 | - if (count($this->_dcStack) == 0) { |
|
553 | - $this->_xhtml .= $data; |
|
554 | - } |
|
555 | - return true; |
|
556 | - } |
|
557 | - |
|
558 | - /** |
|
559 | - * Escape handler - called from HTMLSax |
|
560 | - * |
|
561 | - * @param object $parser HTML parser |
|
562 | - * @param string $data comments or other type of data |
|
563 | - * @return boolean |
|
564 | - * @access private |
|
565 | - */ |
|
566 | - public function _escapeHandler(&$parser, $data) |
|
567 | - { |
|
568 | - return true; |
|
569 | - } |
|
570 | - |
|
571 | - /** |
|
572 | - * Returns the XHTML document |
|
573 | - * |
|
574 | - * @return string Processed (X)HTML document |
|
575 | - * @access public |
|
576 | - */ |
|
577 | - public function getXHTML () |
|
578 | - { |
|
579 | - while ($tag = array_pop($this->_stack)) { |
|
580 | - $this->_closeTag($tag); |
|
581 | - } |
|
582 | - |
|
583 | - return $this->_xhtml; |
|
584 | - } |
|
585 | - |
|
586 | - /** |
|
587 | - * Clears current document data |
|
588 | - * |
|
589 | - * @return boolean |
|
590 | - * @access public |
|
591 | - */ |
|
592 | - public function clear() |
|
593 | - { |
|
594 | - $this->_xhtml = ''; |
|
595 | - return true; |
|
596 | - } |
|
597 | - |
|
598 | - /** |
|
599 | - * Main parsing fuction |
|
600 | - * |
|
601 | - * @param string $doc HTML document for processing |
|
602 | - * @return string Processed (X)HTML document |
|
603 | - * @access public |
|
604 | - */ |
|
605 | - public function parse($doc, $isUTF7=false) |
|
606 | - { |
|
60 | + /** |
|
61 | + * Storage for resulting HTML output |
|
62 | + * |
|
63 | + * @var string |
|
64 | + * @access private |
|
65 | + */ |
|
66 | + private $_xhtml = ''; |
|
67 | + |
|
68 | + /** |
|
69 | + * Array of counters for each tag |
|
70 | + * |
|
71 | + * @var array |
|
72 | + * @access private |
|
73 | + */ |
|
74 | + private $_counter = array(); |
|
75 | + |
|
76 | + /** |
|
77 | + * Stack of unclosed tags |
|
78 | + * |
|
79 | + * @var array |
|
80 | + * @access private |
|
81 | + */ |
|
82 | + private $_stack = array(); |
|
83 | + |
|
84 | + /** |
|
85 | + * Array of counters for tags that must be deleted with all content |
|
86 | + * |
|
87 | + * @var array |
|
88 | + * @access private |
|
89 | + */ |
|
90 | + private $_dcCounter = array(); |
|
91 | + |
|
92 | + /** |
|
93 | + * Stack of unclosed tags that must be deleted with all content |
|
94 | + * |
|
95 | + * @var array |
|
96 | + * @access private |
|
97 | + */ |
|
98 | + private $_dcStack = array(); |
|
99 | + |
|
100 | + /** |
|
101 | + * Stores level of list (ol/ul) nesting |
|
102 | + * |
|
103 | + * @var int |
|
104 | + * @access private |
|
105 | + */ |
|
106 | + private $_listScope = 0; |
|
107 | + |
|
108 | + /** |
|
109 | + * Stack of unclosed list tags |
|
110 | + * |
|
111 | + * @var array |
|
112 | + * @access private |
|
113 | + */ |
|
114 | + private $_liStack = array(); |
|
115 | + |
|
116 | + /** |
|
117 | + * Array of prepared regular expressions for protocols (schemas) matching |
|
118 | + * |
|
119 | + * @var array |
|
120 | + * @access private |
|
121 | + */ |
|
122 | + private $_protoRegexps = array(); |
|
123 | + |
|
124 | + /** |
|
125 | + * Array of prepared regular expressions for CSS matching |
|
126 | + * |
|
127 | + * @var array |
|
128 | + * @access private |
|
129 | + */ |
|
130 | + private $_cssRegexps = array(); |
|
131 | + |
|
132 | + /** |
|
133 | + * List of single tags ("<tag />") |
|
134 | + * |
|
135 | + * @var array |
|
136 | + * @access public |
|
137 | + */ |
|
138 | + public $singleTags = array('area', 'br', 'img', 'input', 'hr', 'wbr', ); |
|
139 | + |
|
140 | + /** |
|
141 | + * List of dangerous tags (such tags will be deleted) |
|
142 | + * |
|
143 | + * @var array |
|
144 | + * @access public |
|
145 | + */ |
|
146 | + public $deleteTags = array( |
|
147 | + 'applet', 'base', 'basefont', 'bgsound', 'blink', 'body', |
|
148 | + 'embed', 'frame', 'frameset', 'head', 'html', 'ilayer', |
|
149 | + 'iframe', 'layer', 'link', 'meta', 'object', 'style', |
|
150 | + 'title', 'script', |
|
151 | + ); |
|
152 | + |
|
153 | + /** |
|
154 | + * List of dangerous tags (such tags will be deleted, and all content |
|
155 | + * inside this tags will be also removed) |
|
156 | + * |
|
157 | + * @var array |
|
158 | + * @access public |
|
159 | + */ |
|
160 | + public $deleteTagsContent = array('script', 'style', 'title', 'xml', ); |
|
161 | + |
|
162 | + /** |
|
163 | + * Type of protocols filtering ('white' or 'black') |
|
164 | + * |
|
165 | + * @var string |
|
166 | + * @access public |
|
167 | + */ |
|
168 | + public $protocolFiltering = 'white'; |
|
169 | + |
|
170 | + /** |
|
171 | + * List of "dangerous" protocols (used for blacklist-filtering) |
|
172 | + * |
|
173 | + * @var array |
|
174 | + * @access public |
|
175 | + */ |
|
176 | + public $blackProtocols = array( |
|
177 | + 'about', 'chrome', 'data', 'disk', 'hcp', |
|
178 | + 'help', 'javascript', 'livescript', 'lynxcgi', 'lynxexec', |
|
179 | + 'ms-help', 'ms-its', 'mhtml', 'mocha', 'opera', |
|
180 | + 'res', 'resource', 'shell', 'vbscript', 'view-source', |
|
181 | + 'vnd.ms.radio', 'wysiwyg', |
|
182 | + ); |
|
183 | + |
|
184 | + /** |
|
185 | + * List of "safe" protocols (used for whitelist-filtering) |
|
186 | + * |
|
187 | + * @var array |
|
188 | + * @access public |
|
189 | + */ |
|
190 | + public $whiteProtocols = array( |
|
191 | + 'ed2k', 'file', 'ftp', 'gopher', 'http', 'https', |
|
192 | + 'irc', 'mailto', 'news', 'nntp', 'telnet', 'webcal', |
|
193 | + 'xmpp', 'callto', |
|
194 | + ); |
|
195 | + |
|
196 | + /** |
|
197 | + * List of attributes that can contain protocols |
|
198 | + * |
|
199 | + * @var array |
|
200 | + * @access public |
|
201 | + */ |
|
202 | + public $protocolAttributes = array( |
|
203 | + 'action', 'background', 'codebase', 'dynsrc', 'href', 'lowsrc', 'src', |
|
204 | + ); |
|
205 | + |
|
206 | + /** |
|
207 | + * List of dangerous CSS keywords |
|
208 | + * |
|
209 | + * Whole style="" attribute will be removed, if parser will find one of |
|
210 | + * these keywords |
|
211 | + * |
|
212 | + * @var array |
|
213 | + * @access public |
|
214 | + */ |
|
215 | + public $cssKeywords = array( |
|
216 | + 'absolute', 'behavior', 'behaviour', 'content', 'expression', |
|
217 | + 'fixed', 'include-source', 'moz-binding', |
|
218 | + ); |
|
219 | + |
|
220 | + /** |
|
221 | + * List of tags that can have no "closing tag" |
|
222 | + * |
|
223 | + * @var array |
|
224 | + * @access public |
|
225 | + * @deprecated XHTML does not allow such tags |
|
226 | + */ |
|
227 | + public $noClose = array(); |
|
228 | + |
|
229 | + /** |
|
230 | + * List of block-level tags that terminates paragraph |
|
231 | + * |
|
232 | + * Paragraph will be closed when this tags opened |
|
233 | + * |
|
234 | + * @var array |
|
235 | + * @access public |
|
236 | + */ |
|
237 | + public $closeParagraph = array( |
|
238 | + 'address', 'blockquote', 'center', 'dd', 'dir', 'div', |
|
239 | + 'dl', 'dt', 'h1', 'h2', 'h3', 'h4', |
|
240 | + 'h5', 'h6', 'hr', 'isindex', 'listing', 'marquee', |
|
241 | + 'menu', 'multicol', 'ol', 'p', 'plaintext', 'pre', |
|
242 | + 'table', 'ul', 'xmp', |
|
243 | + ); |
|
244 | + |
|
245 | + /** |
|
246 | + * List of table tags, all table tags outside a table will be removed |
|
247 | + * |
|
248 | + * @var array |
|
249 | + * @access public |
|
250 | + */ |
|
251 | + public $tableTags = array( |
|
252 | + 'caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th', |
|
253 | + 'thead', 'tr', |
|
254 | + ); |
|
255 | + |
|
256 | + /** |
|
257 | + * List of list tags |
|
258 | + * |
|
259 | + * @var array |
|
260 | + * @access public |
|
261 | + */ |
|
262 | + public $listTags = array('dir', 'menu', 'ol', 'ul', 'dl', ); |
|
263 | + |
|
264 | + /** |
|
265 | + * List of dangerous attributes |
|
266 | + * |
|
267 | + * @var array |
|
268 | + * @access public |
|
269 | + */ |
|
270 | + public $attributes = array('dynsrc'); |
|
271 | + //public $attributes = array('dynsrc', 'id', 'name', ); //id and name are dangerous? |
|
272 | + |
|
273 | + /** |
|
274 | + * List of allowed "namespaced" attributes |
|
275 | + * |
|
276 | + * @var array |
|
277 | + * @access public |
|
278 | + */ |
|
279 | + public $attributesNS = array('xml:lang', ); |
|
280 | + |
|
281 | + /** |
|
282 | + * Constructs class |
|
283 | + * |
|
284 | + * @access public |
|
285 | + */ |
|
286 | + public function __construct() |
|
287 | + { |
|
288 | + //making regular expressions based on Proto & CSS arrays |
|
289 | + foreach ($this->blackProtocols as $proto) { |
|
290 | + $preg = "/[\s\x01-\x1F]*"; |
|
291 | + for ($i=0; $i<strlen($proto); $i++) { |
|
292 | + $preg .= $proto{$i} . "[\s\x01-\x1F]*"; |
|
293 | + } |
|
294 | + $preg .= ":/i"; |
|
295 | + $this->_protoRegexps[] = $preg; |
|
296 | + } |
|
297 | + |
|
298 | + foreach ($this->cssKeywords as $css) { |
|
299 | + $this->_cssRegexps[] = '/' . $css . '/i'; |
|
300 | + } |
|
301 | + return true; |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * Handles the writing of attributes - called from $this->_openHandler() |
|
306 | + * |
|
307 | + * @param array $attrs array of attributes $name => $value |
|
308 | + * @return boolean |
|
309 | + * @access private |
|
310 | + */ |
|
311 | + private function _writeAttrs ($attrs) |
|
312 | + { |
|
313 | + if (is_array($attrs)) { |
|
314 | + foreach ($attrs as $name => $value) { |
|
315 | + |
|
316 | + $name = strtolower($name); |
|
317 | + |
|
318 | + if (strpos($name, 'on') === 0) { |
|
319 | + continue; |
|
320 | + } |
|
321 | + if (strpos($name, 'data') === 0) { |
|
322 | + continue; |
|
323 | + } |
|
324 | + if (in_array($name, $this->attributes)) { |
|
325 | + continue; |
|
326 | + } |
|
327 | + if (!preg_match("/^[a-z0-9]+$/i", $name)) { |
|
328 | + if (!in_array($name, $this->attributesNS)) |
|
329 | + { |
|
330 | + continue; |
|
331 | + } |
|
332 | + } |
|
333 | + |
|
334 | + if (($value === TRUE) || (is_null($value))) { |
|
335 | + $value = $name; |
|
336 | + } |
|
337 | + |
|
338 | + if ($name == 'style') { |
|
339 | + |
|
340 | + // removes insignificant backslahes |
|
341 | + $value = str_replace("\\", '', $value); |
|
342 | + |
|
343 | + // removes CSS comments |
|
344 | + while (1) |
|
345 | + { |
|
346 | + $_value = preg_replace("!/\*.*?\*/!s", '', $value); |
|
347 | + if ($_value == $value) break; |
|
348 | + $value = $_value; |
|
349 | + } |
|
350 | + |
|
351 | + // replace all & to & |
|
352 | + $value = str_replace('&', '&', $value); |
|
353 | + $value = str_replace('&', '&', $value); |
|
354 | + |
|
355 | + foreach ($this->_cssRegexps as $css) { |
|
356 | + if (preg_match($css, $value)) { |
|
357 | + continue 2; |
|
358 | + } |
|
359 | + } |
|
360 | + foreach ($this->_protoRegexps as $proto) { |
|
361 | + if (preg_match($proto, $value)) { |
|
362 | + continue 2; |
|
363 | + } |
|
364 | + } |
|
365 | + } |
|
366 | + |
|
367 | + $tempval = preg_replace_callback( |
|
368 | + '/&#(\d+);?/m', |
|
369 | + function ($matches) { |
|
370 | + return chr($matches[0]); |
|
371 | + }, |
|
372 | + $value |
|
373 | + ); //"' |
|
374 | + |
|
375 | + $tempval = preg_replace_callback( |
|
376 | + '/&#x([0-9a-f]+);?/mi', |
|
377 | + function ($matches) { |
|
378 | + return chr(hexdec($matches[0])); |
|
379 | + }, |
|
380 | + $tempval |
|
381 | + ); |
|
382 | + |
|
383 | + if ((in_array($name, $this->protocolAttributes)) && |
|
384 | + (strpos($tempval, ':') !== false)) |
|
385 | + { |
|
386 | + if ($this->protocolFiltering == 'black') { |
|
387 | + foreach ($this->_protoRegexps as $proto) { |
|
388 | + if (preg_match($proto, $tempval)) continue 2; |
|
389 | + } |
|
390 | + } else { |
|
391 | + $_tempval = explode(':', $tempval); |
|
392 | + $proto = $_tempval[0]; |
|
393 | + if (!in_array($proto, $this->whiteProtocols)) { |
|
394 | + continue; |
|
395 | + } |
|
396 | + } |
|
397 | + } |
|
398 | + |
|
399 | + $value = str_replace("\"", """, $value); |
|
400 | + $this->_xhtml .= ' ' . $name . '="' . $value . '"'; |
|
401 | + } |
|
402 | + } |
|
403 | + return true; |
|
404 | + } |
|
405 | + |
|
406 | + /** |
|
407 | + * Opening tag handler - called from HTMLSax |
|
408 | + * |
|
409 | + * @param object $parser HTML Parser |
|
410 | + * @param string $name tag name |
|
411 | + * @param array $attrs tag attributes |
|
412 | + * @return boolean |
|
413 | + * @access private |
|
414 | + */ |
|
415 | + public function _openHandler(&$parser, $name, $attrs) |
|
416 | + { |
|
417 | + $name = strtolower($name); |
|
418 | + |
|
419 | + if (in_array($name, $this->deleteTagsContent)) { |
|
420 | + array_push($this->_dcStack, $name); |
|
421 | + $this->_dcCounter[$name] = isset($this->_dcCounter[$name]) ? $this->_dcCounter[$name]+1 : 1; |
|
422 | + } |
|
423 | + if (count($this->_dcStack) != 0) { |
|
424 | + return true; |
|
425 | + } |
|
426 | + |
|
427 | + if (in_array($name, $this->deleteTags)) { |
|
428 | + return true; |
|
429 | + } |
|
430 | + |
|
431 | + if (!preg_match("/^[a-z0-9]+$/i", $name)) { |
|
432 | + if (preg_match("!(?:\@|://)!i", $name)) { |
|
433 | + $this->_xhtml .= '<' . $name . '>'; |
|
434 | + } |
|
435 | + return true; |
|
436 | + } |
|
437 | + |
|
438 | + if (in_array($name, $this->singleTags)) { |
|
439 | + $this->_xhtml .= '<' . $name; |
|
440 | + $this->_writeAttrs($attrs); |
|
441 | + $this->_xhtml .= ' />'; |
|
442 | + return true; |
|
443 | + } |
|
444 | + |
|
445 | + // TABLES: cannot open table elements when we are not inside table |
|
446 | + if ((isset($this->_counter['table'])) && ($this->_counter['table'] <= 0) |
|
447 | + && (in_array($name, $this->tableTags))) |
|
448 | + { |
|
449 | + return true; |
|
450 | + } |
|
451 | + |
|
452 | + // PARAGRAPHS: close paragraph when closeParagraph tags opening |
|
453 | + if ((in_array($name, $this->closeParagraph)) && (in_array('p', $this->_stack))) { |
|
454 | + $this->_closeHandler($parser, 'p'); |
|
455 | + } |
|
456 | + |
|
457 | + // LISTS: we should close <li> if <li> of the same level opening |
|
458 | + if ($name == 'li' && count($this->_liStack) && |
|
459 | + $this->_listScope == $this->_liStack[count($this->_liStack)-1]) |
|
460 | + { |
|
461 | + $this->_closeHandler($parser, 'li'); |
|
462 | + } |
|
463 | + |
|
464 | + // LISTS: we want to know on what nesting level of lists we are |
|
465 | + if (in_array($name, $this->listTags)) { |
|
466 | + $this->_listScope++; |
|
467 | + } |
|
468 | + if ($name == 'li') { |
|
469 | + array_push($this->_liStack, $this->_listScope); |
|
470 | + } |
|
471 | + |
|
472 | + $this->_xhtml .= '<' . $name; |
|
473 | + $this->_writeAttrs($attrs); |
|
474 | + $this->_xhtml .= '>'; |
|
475 | + array_push($this->_stack,$name); |
|
476 | + $this->_counter[$name] = isset($this->_counter[$name]) ? $this->_counter[$name]+1 : 1; |
|
477 | + return true; |
|
478 | + } |
|
479 | + |
|
480 | + /** |
|
481 | + * Closing tag handler - called from HTMLSax |
|
482 | + * |
|
483 | + * @param object $parsers HTML parser |
|
484 | + * @param string $name tag name |
|
485 | + * @return boolean |
|
486 | + * @access private |
|
487 | + */ |
|
488 | + public function _closeHandler(&$parser, $name) |
|
489 | + { |
|
490 | + |
|
491 | + $name = strtolower($name); |
|
492 | + |
|
493 | + if (isset($this->_dcCounter[$name]) && ($this->_dcCounter[$name] > 0) && |
|
494 | + (in_array($name, $this->deleteTagsContent))) |
|
495 | + { |
|
496 | + while ($name != ($tag = array_pop($this->_dcStack))) { |
|
497 | + $this->_dcCounter[$tag]--; |
|
498 | + } |
|
499 | + |
|
500 | + $this->_dcCounter[$name]--; |
|
501 | + } |
|
502 | + |
|
503 | + if (count($this->_dcStack) != 0) { |
|
504 | + return true; |
|
505 | + } |
|
506 | + |
|
507 | + if ((isset($this->_counter[$name])) && ($this->_counter[$name] > 0)) { |
|
508 | + while ($name != ($tag = array_pop($this->_stack))) { |
|
509 | + $this->_closeTag($tag); |
|
510 | + } |
|
511 | + |
|
512 | + $this->_closeTag($name); |
|
513 | + } |
|
514 | + return true; |
|
515 | + } |
|
516 | + |
|
517 | + /** |
|
518 | + * Closes tag |
|
519 | + * |
|
520 | + * @param string $tag tag name |
|
521 | + * @return boolean |
|
522 | + * @access private |
|
523 | + */ |
|
524 | + public function _closeTag($tag) |
|
525 | + { |
|
526 | + if (!in_array($tag, $this->noClose)) { |
|
527 | + $this->_xhtml .= '</' . $tag . '>'; |
|
528 | + } |
|
529 | + |
|
530 | + $this->_counter[$tag]--; |
|
531 | + |
|
532 | + if (in_array($tag, $this->listTags)) { |
|
533 | + $this->_listScope--; |
|
534 | + } |
|
535 | + |
|
536 | + if ($tag == 'li') { |
|
537 | + array_pop($this->_liStack); |
|
538 | + } |
|
539 | + return true; |
|
540 | + } |
|
541 | + |
|
542 | + /** |
|
543 | + * Character data handler - called from HTMLSax |
|
544 | + * |
|
545 | + * @param object $parser HTML parser |
|
546 | + * @param string $data textual data |
|
547 | + * @return boolean |
|
548 | + * @access private |
|
549 | + */ |
|
550 | + public function _dataHandler(&$parser, $data) |
|
551 | + { |
|
552 | + if (count($this->_dcStack) == 0) { |
|
553 | + $this->_xhtml .= $data; |
|
554 | + } |
|
555 | + return true; |
|
556 | + } |
|
557 | + |
|
558 | + /** |
|
559 | + * Escape handler - called from HTMLSax |
|
560 | + * |
|
561 | + * @param object $parser HTML parser |
|
562 | + * @param string $data comments or other type of data |
|
563 | + * @return boolean |
|
564 | + * @access private |
|
565 | + */ |
|
566 | + public function _escapeHandler(&$parser, $data) |
|
567 | + { |
|
568 | + return true; |
|
569 | + } |
|
570 | + |
|
571 | + /** |
|
572 | + * Returns the XHTML document |
|
573 | + * |
|
574 | + * @return string Processed (X)HTML document |
|
575 | + * @access public |
|
576 | + */ |
|
577 | + public function getXHTML () |
|
578 | + { |
|
579 | + while ($tag = array_pop($this->_stack)) { |
|
580 | + $this->_closeTag($tag); |
|
581 | + } |
|
582 | + |
|
583 | + return $this->_xhtml; |
|
584 | + } |
|
585 | + |
|
586 | + /** |
|
587 | + * Clears current document data |
|
588 | + * |
|
589 | + * @return boolean |
|
590 | + * @access public |
|
591 | + */ |
|
592 | + public function clear() |
|
593 | + { |
|
594 | + $this->_xhtml = ''; |
|
595 | + return true; |
|
596 | + } |
|
597 | + |
|
598 | + /** |
|
599 | + * Main parsing fuction |
|
600 | + * |
|
601 | + * @param string $doc HTML document for processing |
|
602 | + * @return string Processed (X)HTML document |
|
603 | + * @access public |
|
604 | + */ |
|
605 | + public function parse($doc, $isUTF7=false) |
|
606 | + { |
|
607 | 607 | $this->clear(); |
608 | 608 | |
609 | - // Save all '<' symbols |
|
610 | - $doc = preg_replace("/<(?=[^a-zA-Z\/\!\?\%])/", '<', (string)$doc); |
|
611 | - |
|
612 | - // Web documents shouldn't contains \x00 symbol |
|
613 | - $doc = str_replace("\x00", '', $doc); |
|
614 | - |
|
615 | - // Opera6 bug workaround |
|
616 | - $doc = str_replace("\xC0\xBC", '<', $doc); |
|
617 | - |
|
618 | - // UTF-7 encoding ASCII decode |
|
619 | - if($isUTF7) |
|
620 | - $doc = $this->repackUTF7($doc); |
|
621 | - |
|
622 | - // Instantiate the parser |
|
623 | - $parser= new TSax3(); |
|
624 | - |
|
625 | - // Set up the parser |
|
626 | - $parser->set_object($this); |
|
627 | - |
|
628 | - $parser->set_element_handler('_openHandler','_closeHandler'); |
|
629 | - $parser->set_data_handler('_dataHandler'); |
|
630 | - $parser->set_escape_handler('_escapeHandler'); |
|
631 | - |
|
632 | - $parser->parse($doc); |
|
633 | - |
|
634 | - return $this->getXHTML(); |
|
635 | - |
|
636 | - } |
|
637 | - |
|
638 | - |
|
639 | - /** |
|
640 | - * UTF-7 decoding fuction |
|
641 | - * |
|
642 | - * @param string $str HTML document for recode ASCII part of UTF-7 back to ASCII |
|
643 | - * @return string Decoded document |
|
644 | - * @access private |
|
645 | - */ |
|
646 | - private function repackUTF7($str) |
|
647 | - { |
|
648 | - return preg_replace_callback('!\+([0-9a-zA-Z/]+)\-!', array($this, 'repackUTF7Callback'), $str); |
|
649 | - } |
|
650 | - |
|
651 | - /** |
|
652 | - * Additional UTF-7 decoding fuction |
|
653 | - * |
|
654 | - * @param string $str String for recode ASCII part of UTF-7 back to ASCII |
|
655 | - * @return string Recoded string |
|
656 | - * @access private |
|
657 | - */ |
|
658 | - private function repackUTF7Callback($str) |
|
659 | - { |
|
660 | - $str = base64_decode($str[1]); |
|
661 | - $str = preg_replace_callback('/^((?:\x00.)*)((?:[^\x00].)+)/', array($this, 'repackUTF7Back'), $str); |
|
662 | - return preg_replace('/\x00(.)/', '$1', $str); |
|
663 | - } |
|
664 | - |
|
665 | - /** |
|
666 | - * Additional UTF-7 encoding fuction |
|
667 | - * |
|
668 | - * @param string $str String for recode ASCII part of UTF-7 back to ASCII |
|
669 | - * @return string Recoded string |
|
670 | - * @access private |
|
671 | - */ |
|
672 | - private function repackUTF7Back($str) |
|
673 | - { |
|
674 | - return $str[1].'+'.rtrim(base64_encode($str[2]), '=').'-'; |
|
675 | - } |
|
609 | + // Save all '<' symbols |
|
610 | + $doc = preg_replace("/<(?=[^a-zA-Z\/\!\?\%])/", '<', (string)$doc); |
|
611 | + |
|
612 | + // Web documents shouldn't contains \x00 symbol |
|
613 | + $doc = str_replace("\x00", '', $doc); |
|
614 | + |
|
615 | + // Opera6 bug workaround |
|
616 | + $doc = str_replace("\xC0\xBC", '<', $doc); |
|
617 | + |
|
618 | + // UTF-7 encoding ASCII decode |
|
619 | + if($isUTF7) |
|
620 | + $doc = $this->repackUTF7($doc); |
|
621 | + |
|
622 | + // Instantiate the parser |
|
623 | + $parser= new TSax3(); |
|
624 | + |
|
625 | + // Set up the parser |
|
626 | + $parser->set_object($this); |
|
627 | + |
|
628 | + $parser->set_element_handler('_openHandler','_closeHandler'); |
|
629 | + $parser->set_data_handler('_dataHandler'); |
|
630 | + $parser->set_escape_handler('_escapeHandler'); |
|
631 | + |
|
632 | + $parser->parse($doc); |
|
633 | + |
|
634 | + return $this->getXHTML(); |
|
635 | + |
|
636 | + } |
|
637 | + |
|
638 | + |
|
639 | + /** |
|
640 | + * UTF-7 decoding fuction |
|
641 | + * |
|
642 | + * @param string $str HTML document for recode ASCII part of UTF-7 back to ASCII |
|
643 | + * @return string Decoded document |
|
644 | + * @access private |
|
645 | + */ |
|
646 | + private function repackUTF7($str) |
|
647 | + { |
|
648 | + return preg_replace_callback('!\+([0-9a-zA-Z/]+)\-!', array($this, 'repackUTF7Callback'), $str); |
|
649 | + } |
|
650 | + |
|
651 | + /** |
|
652 | + * Additional UTF-7 decoding fuction |
|
653 | + * |
|
654 | + * @param string $str String for recode ASCII part of UTF-7 back to ASCII |
|
655 | + * @return string Recoded string |
|
656 | + * @access private |
|
657 | + */ |
|
658 | + private function repackUTF7Callback($str) |
|
659 | + { |
|
660 | + $str = base64_decode($str[1]); |
|
661 | + $str = preg_replace_callback('/^((?:\x00.)*)((?:[^\x00].)+)/', array($this, 'repackUTF7Back'), $str); |
|
662 | + return preg_replace('/\x00(.)/', '$1', $str); |
|
663 | + } |
|
664 | + |
|
665 | + /** |
|
666 | + * Additional UTF-7 encoding fuction |
|
667 | + * |
|
668 | + * @param string $str String for recode ASCII part of UTF-7 back to ASCII |
|
669 | + * @return string Recoded string |
|
670 | + * @access private |
|
671 | + */ |
|
672 | + private function repackUTF7Back($str) |
|
673 | + { |
|
674 | + return $str[1].'+'.rtrim(base64_encode($str[2]), '=').'-'; |
|
675 | + } |
|
676 | 676 | } |
677 | 677 | |
678 | 678 | /* |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | * @var array |
136 | 136 | * @access public |
137 | 137 | */ |
138 | - public $singleTags = array('area', 'br', 'img', 'input', 'hr', 'wbr', ); |
|
138 | + public $singleTags = array('area', 'br', 'img', 'input', 'hr', 'wbr',); |
|
139 | 139 | |
140 | 140 | /** |
141 | 141 | * List of dangerous tags (such tags will be deleted) |
@@ -144,10 +144,10 @@ discard block |
||
144 | 144 | * @access public |
145 | 145 | */ |
146 | 146 | public $deleteTags = array( |
147 | - 'applet', 'base', 'basefont', 'bgsound', 'blink', 'body', |
|
148 | - 'embed', 'frame', 'frameset', 'head', 'html', 'ilayer', |
|
149 | - 'iframe', 'layer', 'link', 'meta', 'object', 'style', |
|
150 | - 'title', 'script', |
|
147 | + 'applet', 'base', 'basefont', 'bgsound', 'blink', 'body', |
|
148 | + 'embed', 'frame', 'frameset', 'head', 'html', 'ilayer', |
|
149 | + 'iframe', 'layer', 'link', 'meta', 'object', 'style', |
|
150 | + 'title', 'script', |
|
151 | 151 | ); |
152 | 152 | |
153 | 153 | /** |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | * @var array |
158 | 158 | * @access public |
159 | 159 | */ |
160 | - public $deleteTagsContent = array('script', 'style', 'title', 'xml', ); |
|
160 | + public $deleteTagsContent = array('script', 'style', 'title', 'xml',); |
|
161 | 161 | |
162 | 162 | /** |
163 | 163 | * Type of protocols filtering ('white' or 'black') |
@@ -174,11 +174,11 @@ discard block |
||
174 | 174 | * @access public |
175 | 175 | */ |
176 | 176 | public $blackProtocols = array( |
177 | - 'about', 'chrome', 'data', 'disk', 'hcp', |
|
178 | - 'help', 'javascript', 'livescript', 'lynxcgi', 'lynxexec', |
|
179 | - 'ms-help', 'ms-its', 'mhtml', 'mocha', 'opera', |
|
180 | - 'res', 'resource', 'shell', 'vbscript', 'view-source', |
|
181 | - 'vnd.ms.radio', 'wysiwyg', |
|
177 | + 'about', 'chrome', 'data', 'disk', 'hcp', |
|
178 | + 'help', 'javascript', 'livescript', 'lynxcgi', 'lynxexec', |
|
179 | + 'ms-help', 'ms-its', 'mhtml', 'mocha', 'opera', |
|
180 | + 'res', 'resource', 'shell', 'vbscript', 'view-source', |
|
181 | + 'vnd.ms.radio', 'wysiwyg', |
|
182 | 182 | ); |
183 | 183 | |
184 | 184 | /** |
@@ -188,9 +188,9 @@ discard block |
||
188 | 188 | * @access public |
189 | 189 | */ |
190 | 190 | public $whiteProtocols = array( |
191 | - 'ed2k', 'file', 'ftp', 'gopher', 'http', 'https', |
|
192 | - 'irc', 'mailto', 'news', 'nntp', 'telnet', 'webcal', |
|
193 | - 'xmpp', 'callto', |
|
191 | + 'ed2k', 'file', 'ftp', 'gopher', 'http', 'https', |
|
192 | + 'irc', 'mailto', 'news', 'nntp', 'telnet', 'webcal', |
|
193 | + 'xmpp', 'callto', |
|
194 | 194 | ); |
195 | 195 | |
196 | 196 | /** |
@@ -213,8 +213,8 @@ discard block |
||
213 | 213 | * @access public |
214 | 214 | */ |
215 | 215 | public $cssKeywords = array( |
216 | - 'absolute', 'behavior', 'behaviour', 'content', 'expression', |
|
217 | - 'fixed', 'include-source', 'moz-binding', |
|
216 | + 'absolute', 'behavior', 'behaviour', 'content', 'expression', |
|
217 | + 'fixed', 'include-source', 'moz-binding', |
|
218 | 218 | ); |
219 | 219 | |
220 | 220 | /** |
@@ -235,11 +235,11 @@ discard block |
||
235 | 235 | * @access public |
236 | 236 | */ |
237 | 237 | public $closeParagraph = array( |
238 | - 'address', 'blockquote', 'center', 'dd', 'dir', 'div', |
|
239 | - 'dl', 'dt', 'h1', 'h2', 'h3', 'h4', |
|
240 | - 'h5', 'h6', 'hr', 'isindex', 'listing', 'marquee', |
|
241 | - 'menu', 'multicol', 'ol', 'p', 'plaintext', 'pre', |
|
242 | - 'table', 'ul', 'xmp', |
|
238 | + 'address', 'blockquote', 'center', 'dd', 'dir', 'div', |
|
239 | + 'dl', 'dt', 'h1', 'h2', 'h3', 'h4', |
|
240 | + 'h5', 'h6', 'hr', 'isindex', 'listing', 'marquee', |
|
241 | + 'menu', 'multicol', 'ol', 'p', 'plaintext', 'pre', |
|
242 | + 'table', 'ul', 'xmp', |
|
243 | 243 | ); |
244 | 244 | |
245 | 245 | /** |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | */ |
251 | 251 | public $tableTags = array( |
252 | 252 | 'caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th', |
253 | - 'thead', 'tr', |
|
253 | + 'thead', 'tr', |
|
254 | 254 | ); |
255 | 255 | |
256 | 256 | /** |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | * @var array |
260 | 260 | * @access public |
261 | 261 | */ |
262 | - public $listTags = array('dir', 'menu', 'ol', 'ul', 'dl', ); |
|
262 | + public $listTags = array('dir', 'menu', 'ol', 'ul', 'dl',); |
|
263 | 263 | |
264 | 264 | /** |
265 | 265 | * List of dangerous attributes |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | * @var array |
277 | 277 | * @access public |
278 | 278 | */ |
279 | - public $attributesNS = array('xml:lang', ); |
|
279 | + public $attributesNS = array('xml:lang',); |
|
280 | 280 | |
281 | 281 | /** |
282 | 282 | * Constructs class |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | //making regular expressions based on Proto & CSS arrays |
289 | 289 | foreach ($this->blackProtocols as $proto) { |
290 | 290 | $preg = "/[\s\x01-\x1F]*"; |
291 | - for ($i=0; $i<strlen($proto); $i++) { |
|
291 | + for ($i = 0; $i < strlen($proto); $i++) { |
|
292 | 292 | $preg .= $proto{$i} . "[\s\x01-\x1F]*"; |
293 | 293 | } |
294 | 294 | $preg .= ":/i"; |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | * @return boolean |
309 | 309 | * @access private |
310 | 310 | */ |
311 | - private function _writeAttrs ($attrs) |
|
311 | + private function _writeAttrs($attrs) |
|
312 | 312 | { |
313 | 313 | if (is_array($attrs)) { |
314 | 314 | foreach ($attrs as $name => $value) { |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | |
367 | 367 | $tempval = preg_replace_callback( |
368 | 368 | '/&#(\d+);?/m', |
369 | - function ($matches) { |
|
369 | + function($matches) { |
|
370 | 370 | return chr($matches[0]); |
371 | 371 | }, |
372 | 372 | $value |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | |
375 | 375 | $tempval = preg_replace_callback( |
376 | 376 | '/&#x([0-9a-f]+);?/mi', |
377 | - function ($matches) { |
|
377 | + function($matches) { |
|
378 | 378 | return chr(hexdec($matches[0])); |
379 | 379 | }, |
380 | 380 | $tempval |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | |
419 | 419 | if (in_array($name, $this->deleteTagsContent)) { |
420 | 420 | array_push($this->_dcStack, $name); |
421 | - $this->_dcCounter[$name] = isset($this->_dcCounter[$name]) ? $this->_dcCounter[$name]+1 : 1; |
|
421 | + $this->_dcCounter[$name] = isset($this->_dcCounter[$name]) ? $this->_dcCounter[$name] + 1 : 1; |
|
422 | 422 | } |
423 | 423 | if (count($this->_dcStack) != 0) { |
424 | 424 | return true; |
@@ -456,7 +456,7 @@ discard block |
||
456 | 456 | |
457 | 457 | // LISTS: we should close <li> if <li> of the same level opening |
458 | 458 | if ($name == 'li' && count($this->_liStack) && |
459 | - $this->_listScope == $this->_liStack[count($this->_liStack)-1]) |
|
459 | + $this->_listScope == $this->_liStack[count($this->_liStack) - 1]) |
|
460 | 460 | { |
461 | 461 | $this->_closeHandler($parser, 'li'); |
462 | 462 | } |
@@ -472,8 +472,8 @@ discard block |
||
472 | 472 | $this->_xhtml .= '<' . $name; |
473 | 473 | $this->_writeAttrs($attrs); |
474 | 474 | $this->_xhtml .= '>'; |
475 | - array_push($this->_stack,$name); |
|
476 | - $this->_counter[$name] = isset($this->_counter[$name]) ? $this->_counter[$name]+1 : 1; |
|
475 | + array_push($this->_stack, $name); |
|
476 | + $this->_counter[$name] = isset($this->_counter[$name]) ? $this->_counter[$name] + 1 : 1; |
|
477 | 477 | return true; |
478 | 478 | } |
479 | 479 | |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | * @return string Processed (X)HTML document |
575 | 575 | * @access public |
576 | 576 | */ |
577 | - public function getXHTML () |
|
577 | + public function getXHTML() |
|
578 | 578 | { |
579 | 579 | while ($tag = array_pop($this->_stack)) { |
580 | 580 | $this->_closeTag($tag); |
@@ -602,12 +602,12 @@ discard block |
||
602 | 602 | * @return string Processed (X)HTML document |
603 | 603 | * @access public |
604 | 604 | */ |
605 | - public function parse($doc, $isUTF7=false) |
|
605 | + public function parse($doc, $isUTF7 = false) |
|
606 | 606 | { |
607 | 607 | $this->clear(); |
608 | 608 | |
609 | 609 | // Save all '<' symbols |
610 | - $doc = preg_replace("/<(?=[^a-zA-Z\/\!\?\%])/", '<', (string)$doc); |
|
610 | + $doc = preg_replace("/<(?=[^a-zA-Z\/\!\?\%])/", '<', (string) $doc); |
|
611 | 611 | |
612 | 612 | // Web documents shouldn't contains \x00 symbol |
613 | 613 | $doc = str_replace("\x00", '', $doc); |
@@ -616,16 +616,16 @@ discard block |
||
616 | 616 | $doc = str_replace("\xC0\xBC", '<', $doc); |
617 | 617 | |
618 | 618 | // UTF-7 encoding ASCII decode |
619 | - if($isUTF7) |
|
619 | + if ($isUTF7) |
|
620 | 620 | $doc = $this->repackUTF7($doc); |
621 | 621 | |
622 | 622 | // Instantiate the parser |
623 | - $parser= new TSax3(); |
|
623 | + $parser = new TSax3(); |
|
624 | 624 | |
625 | 625 | // Set up the parser |
626 | 626 | $parser->set_object($this); |
627 | 627 | |
628 | - $parser->set_element_handler('_openHandler','_closeHandler'); |
|
628 | + $parser->set_element_handler('_openHandler', '_closeHandler'); |
|
629 | 629 | $parser->set_data_handler('_dataHandler'); |
630 | 630 | $parser->set_escape_handler('_escapeHandler'); |
631 | 631 | |
@@ -671,7 +671,7 @@ discard block |
||
671 | 671 | */ |
672 | 672 | private function repackUTF7Back($str) |
673 | 673 | { |
674 | - return $str[1].'+'.rtrim(base64_encode($str[2]), '=').'-'; |
|
674 | + return $str[1] . '+' . rtrim(base64_encode($str[2]), '=') . '-'; |
|
675 | 675 | } |
676 | 676 | } |
677 | 677 |
@@ -344,7 +344,9 @@ discard block |
||
344 | 344 | while (1) |
345 | 345 | { |
346 | 346 | $_value = preg_replace("!/\*.*?\*/!s", '', $value); |
347 | - if ($_value == $value) break; |
|
347 | + if ($_value == $value) { |
|
348 | + break; |
|
349 | + } |
|
348 | 350 | $value = $_value; |
349 | 351 | } |
350 | 352 | |
@@ -385,7 +387,9 @@ discard block |
||
385 | 387 | { |
386 | 388 | if ($this->protocolFiltering == 'black') { |
387 | 389 | foreach ($this->_protoRegexps as $proto) { |
388 | - if (preg_match($proto, $tempval)) continue 2; |
|
390 | + if (preg_match($proto, $tempval)) { |
|
391 | + continue 2; |
|
392 | + } |
|
389 | 393 | } |
390 | 394 | } else { |
391 | 395 | $_tempval = explode(':', $tempval); |
@@ -616,8 +620,9 @@ discard block |
||
616 | 620 | $doc = str_replace("\xC0\xBC", '<', $doc); |
617 | 621 | |
618 | 622 | // UTF-7 encoding ASCII decode |
619 | - if($isUTF7) |
|
620 | - $doc = $this->repackUTF7($doc); |
|
623 | + if($isUTF7) { |
|
624 | + $doc = $this->repackUTF7($doc); |
|
625 | + } |
|
621 | 626 | |
622 | 627 | // Instantiate the parser |
623 | 628 | $parser= new TSax3(); |
@@ -151,7 +151,6 @@ discard block |
||
151 | 151 | * Called by subclssses' constructors to enable/disable |
152 | 152 | * optional highlighter rules |
153 | 153 | * |
154 | - * @param array $defines Conditional defines |
|
155 | 154 | * |
156 | 155 | * @access protected |
157 | 156 | */ |
@@ -232,6 +231,7 @@ discard block |
||
232 | 231 | * Helper function to find matching brackets |
233 | 232 | * |
234 | 233 | * @access private |
234 | + * @param string $str |
|
235 | 235 | */ |
236 | 236 | function _matchingBrackets($str) |
237 | 237 | { |
@@ -32,12 +32,12 @@ discard block |
||
32 | 32 | /** |
33 | 33 | * use numbered list |
34 | 34 | */ |
35 | - define ('HL_NUMBERS_LI' , 1); |
|
35 | + define('HL_NUMBERS_LI', 1); |
|
36 | 36 | /** |
37 | 37 | * Use 2-column table with line numbers in left column and code in right column. |
38 | 38 | * Forces $options['tag'] = HL_TAG_PRE |
39 | 39 | */ |
40 | - define ('HL_NUMBERS_TABLE' , 2); |
|
40 | + define('HL_NUMBERS_TABLE', 2); |
|
41 | 41 | /**#@-*/ |
42 | 42 | } |
43 | 43 | |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | /** |
47 | 47 | * for our purpose, it is infinity |
48 | 48 | */ |
49 | -define ('HL_INFINITY', 1000000000); |
|
49 | +define('HL_INFINITY', 1000000000); |
|
50 | 50 | |
51 | 51 | // }}} |
52 | 52 | |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | $defines = array(); |
164 | 164 | } |
165 | 165 | foreach ($this->_conditions as $name => $actions) { |
166 | - foreach($actions as $action) { |
|
166 | + foreach ($actions as $action) { |
|
167 | 167 | $present = in_array($name, $defines); |
168 | 168 | if (!$action[1]) { |
169 | 169 | $present = !$present; |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | public static function factory($lang, $options = array()) |
198 | 198 | { |
199 | 199 | $lang = strtoupper($lang); |
200 | - $langFile = dirname(__FILE__)."/Highlighter/$lang.php"; |
|
200 | + $langFile = dirname(__FILE__) . "/Highlighter/$lang.php"; |
|
201 | 201 | if (is_file($langFile)) |
202 | 202 | include_once $langFile; |
203 | 203 | else |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | } else { |
257 | 257 | $endpos = -1; |
258 | 258 | } |
259 | - preg_match ($this->_regs[$this->_state], $this->_str, $m, PREG_OFFSET_CAPTURE, $this->_pos); |
|
259 | + preg_match($this->_regs[$this->_state], $this->_str, $m, PREG_OFFSET_CAPTURE, $this->_pos); |
|
260 | 260 | $n = 1; |
261 | 261 | |
262 | 262 | |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | if (!isset($m[$n])) { |
265 | 265 | break; |
266 | 266 | } |
267 | - if ($m[$n][1]>-1 && ($endpos == -1 || $m[$n][1] < $endpos)) { |
|
267 | + if ($m[$n][1] > -1 && ($endpos == -1 || $m[$n][1] < $endpos)) { |
|
268 | 268 | if ($this->_states[$this->_state][$i] != -1) { |
269 | 269 | $this->_tokenStack[] = array($this->_delim[$this->_state][$i], $m[$n][0]); |
270 | 270 | } else { |
@@ -272,17 +272,17 @@ discard block |
||
272 | 272 | if (isset($this->_parts[$this->_state][$i])) { |
273 | 273 | $parts = array(); |
274 | 274 | $partpos = $m[$n][1]; |
275 | - for ($j=1; $j<=$count; $j++) { |
|
276 | - if ($m[$j+$n][1] < 0) { |
|
275 | + for ($j = 1; $j <= $count; $j++) { |
|
276 | + if ($m[$j + $n][1] < 0) { |
|
277 | 277 | continue; |
278 | 278 | } |
279 | 279 | if (isset($this->_parts[$this->_state][$i][$j])) { |
280 | - if ($m[$j+$n][1] > $partpos) { |
|
281 | - array_unshift($parts, array($inner, substr($this->_str, $partpos, $m[$j+$n][1]-$partpos))); |
|
280 | + if ($m[$j + $n][1] > $partpos) { |
|
281 | + array_unshift($parts, array($inner, substr($this->_str, $partpos, $m[$j + $n][1] - $partpos))); |
|
282 | 282 | } |
283 | - array_unshift($parts, array($this->_parts[$this->_state][$i][$j], $m[$j+$n][0])); |
|
283 | + array_unshift($parts, array($this->_parts[$this->_state][$i][$j], $m[$j + $n][0])); |
|
284 | 284 | } |
285 | - $partpos = $m[$j+$n][1] + strlen($m[$j+$n][0]); |
|
285 | + $partpos = $m[$j + $n][1] + strlen($m[$j + $n][0]); |
|
286 | 286 | } |
287 | 287 | if ($partpos < $m[$n][1] + strlen($m[$n][0])) { |
288 | 288 | array_unshift($parts, array($inner, substr($this->_str, $partpos, $m[$n][1] - $partpos + strlen($m[$n][0])))); |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | } |
303 | 303 | } |
304 | 304 | if ($m[$n][1] > $this->_pos) { |
305 | - $this->_tokenStack[] = array($this->_lastinner, substr($this->_str, $this->_pos, $m[$n][1]-$this->_pos)); |
|
305 | + $this->_tokenStack[] = array($this->_lastinner, substr($this->_str, $this->_pos, $m[$n][1] - $this->_pos)); |
|
306 | 306 | } |
307 | 307 | $this->_pos = $m[$n][1] + strlen($m[$n][0]); |
308 | 308 | if ($this->_states[$this->_state][$i] != -1) { |
@@ -313,13 +313,13 @@ discard block |
||
313 | 313 | $this->_state = $this->_states[$this->_state][$i]; |
314 | 314 | $this->_endpattern = $this->_end[$this->_state]; |
315 | 315 | if ($this->_subst[$l][$i]) { |
316 | - for ($k=0; $k<=$this->_counts[$l][$i]; $k++) { |
|
317 | - if (!isset($m[$i+$k])) { |
|
316 | + for ($k = 0; $k <= $this->_counts[$l][$i]; $k++) { |
|
317 | + if (!isset($m[$i + $k])) { |
|
318 | 318 | break; |
319 | 319 | } |
320 | - $quoted = preg_quote($m[$n+$k][0], '/'); |
|
321 | - $this->_endpattern = str_replace('%'.$k.'%', $quoted, $this->_endpattern); |
|
322 | - $this->_endpattern = str_replace('%b'.$k.'%', $this->_matchingBrackets($quoted), $this->_endpattern); |
|
320 | + $quoted = preg_quote($m[$n + $k][0], '/'); |
|
321 | + $this->_endpattern = str_replace('%' . $k . '%', $quoted, $this->_endpattern); |
|
322 | + $this->_endpattern = str_replace('%b' . $k . '%', $this->_matchingBrackets($quoted), $this->_endpattern); |
|
323 | 323 | } |
324 | 324 | } |
325 | 325 | } |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | if ($endpos > -1) { |
332 | 332 | $this->_tokenStack[] = array($this->_lastdelim, $endmatch); |
333 | 333 | if ($endpos > $this->_pos) { |
334 | - $this->_tokenStack[] = array($this->_lastinner, substr($this->_str, $this->_pos, $endpos-$this->_pos)); |
|
334 | + $this->_tokenStack[] = array($this->_lastinner, substr($this->_str, $this->_pos, $endpos - $this->_pos)); |
|
335 | 335 | } |
336 | 336 | list($this->_state, $this->_lastdelim, $this->_lastinner, $this->_endpattern) = array_pop($this->_stack); |
337 | 337 | $this->_pos = $endpos + strlen($endmatch); |
@@ -198,15 +198,17 @@ |
||
198 | 198 | { |
199 | 199 | $lang = strtoupper($lang); |
200 | 200 | $langFile = dirname(__FILE__)."/Highlighter/$lang.php"; |
201 | - if (is_file($langFile)) |
|
202 | - include_once $langFile; |
|
203 | - else |
|
204 | - return false; |
|
201 | + if (is_file($langFile)) { |
|
202 | + include_once $langFile; |
|
203 | + } else { |
|
204 | + return false; |
|
205 | + } |
|
205 | 206 | |
206 | 207 | $classname = 'Text_Highlighter_' . $lang; |
207 | 208 | |
208 | - if (!class_exists($classname)) |
|
209 | - return false; |
|
209 | + if (!class_exists($classname)) { |
|
210 | + return false; |
|
211 | + } |
|
210 | 212 | |
211 | 213 | return new $classname($options); |
212 | 214 | } |
@@ -25,20 +25,20 @@ discard block |
||
25 | 25 | // BC trick : define constants related to default |
26 | 26 | // renderer if needed |
27 | 27 | if (!defined('HL_NUMBERS_LI')) { |
28 | - /**#@+ |
|
28 | + /**#@+ |
|
29 | 29 | * Constant for use with $options['numbers'] |
30 | 30 | * @see Text_Highlighter_Renderer_Html::_init() |
31 | 31 | */ |
32 | - /** |
|
33 | - * use numbered list |
|
34 | - */ |
|
35 | - define ('HL_NUMBERS_LI' , 1); |
|
36 | - /** |
|
37 | - * Use 2-column table with line numbers in left column and code in right column. |
|
38 | - * Forces $options['tag'] = HL_TAG_PRE |
|
39 | - */ |
|
40 | - define ('HL_NUMBERS_TABLE' , 2); |
|
41 | - /**#@-*/ |
|
32 | + /** |
|
33 | + * use numbered list |
|
34 | + */ |
|
35 | + define ('HL_NUMBERS_LI' , 1); |
|
36 | + /** |
|
37 | + * Use 2-column table with line numbers in left column and code in right column. |
|
38 | + * Forces $options['tag'] = HL_TAG_PRE |
|
39 | + */ |
|
40 | + define ('HL_NUMBERS_TABLE' , 2); |
|
41 | + /**#@-*/ |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | // }}} |
@@ -92,295 +92,295 @@ discard block |
||
92 | 92 | |
93 | 93 | class Text_Highlighter |
94 | 94 | { |
95 | - // {{{ members |
|
96 | - |
|
97 | - /** |
|
98 | - * Syntax highlighting rules. |
|
99 | - * Auto-generated classes set this var |
|
100 | - * |
|
101 | - * @access protected |
|
102 | - * @see _init |
|
103 | - * @var array |
|
104 | - */ |
|
105 | - var $_syntax; |
|
106 | - |
|
107 | - /** |
|
108 | - * Renderer object. |
|
109 | - * |
|
110 | - * @access private |
|
111 | - * @var array |
|
112 | - */ |
|
113 | - var $_renderer; |
|
114 | - |
|
115 | - /** |
|
116 | - * Options. Keeped for BC |
|
117 | - * |
|
118 | - * @access protected |
|
119 | - * @var array |
|
120 | - */ |
|
121 | - var $_options = array(); |
|
122 | - |
|
123 | - /** |
|
124 | - * Conditionds |
|
125 | - * |
|
126 | - * @access protected |
|
127 | - * @var array |
|
128 | - */ |
|
129 | - var $_conditions = array(); |
|
130 | - |
|
131 | - /** |
|
132 | - * Disabled keywords |
|
133 | - * |
|
134 | - * @access protected |
|
135 | - * @var array |
|
136 | - */ |
|
137 | - var $_disabled = array(); |
|
138 | - |
|
139 | - /** |
|
140 | - * Language |
|
141 | - * |
|
142 | - * @access protected |
|
143 | - * @var string |
|
144 | - */ |
|
145 | - var $_language = ''; |
|
146 | - |
|
147 | - // }}} |
|
148 | - // {{{ _checkDefines |
|
149 | - |
|
150 | - /** |
|
151 | - * Called by subclssses' constructors to enable/disable |
|
152 | - * optional highlighter rules |
|
153 | - * |
|
154 | - * @param array $defines Conditional defines |
|
155 | - * |
|
156 | - * @access protected |
|
157 | - */ |
|
158 | - function _checkDefines() |
|
159 | - { |
|
160 | - if (isset($this->_options['defines'])) { |
|
161 | - $defines = $this->_options['defines']; |
|
162 | - } else { |
|
163 | - $defines = array(); |
|
164 | - } |
|
165 | - foreach ($this->_conditions as $name => $actions) { |
|
166 | - foreach($actions as $action) { |
|
167 | - $present = in_array($name, $defines); |
|
168 | - if (!$action[1]) { |
|
169 | - $present = !$present; |
|
170 | - } |
|
171 | - if ($present) { |
|
172 | - unset($this->_disabled[$action[0]]); |
|
173 | - } else { |
|
174 | - $this->_disabled[$action[0]] = true; |
|
175 | - } |
|
176 | - } |
|
177 | - } |
|
178 | - } |
|
179 | - |
|
180 | - // }}} |
|
181 | - // {{{ factory |
|
182 | - |
|
183 | - /** |
|
184 | - * Create a new Highlighter object for specified language |
|
185 | - * |
|
186 | - * @param string $lang language, for example "SQL" |
|
187 | - * @param array $options Rendering options. This |
|
188 | - * parameter is only keeped for BC reasons, use |
|
189 | - * {@link Text_Highlighter::setRenderer()} instead |
|
190 | - * |
|
191 | - * @return mixed a newly created Highlighter object, or |
|
192 | - * a PEAR error object on error |
|
193 | - * |
|
194 | - * @static |
|
195 | - * @access public |
|
196 | - */ |
|
197 | - public static function factory($lang, $options = array()) |
|
198 | - { |
|
199 | - $lang = strtoupper($lang); |
|
200 | - $langFile = dirname(__FILE__)."/Highlighter/$lang.php"; |
|
201 | - if (is_file($langFile)) |
|
202 | - include_once $langFile; |
|
203 | - else |
|
204 | - return false; |
|
205 | - |
|
206 | - $classname = 'Text_Highlighter_' . $lang; |
|
207 | - |
|
208 | - if (!class_exists($classname)) |
|
209 | - return false; |
|
95 | + // {{{ members |
|
96 | + |
|
97 | + /** |
|
98 | + * Syntax highlighting rules. |
|
99 | + * Auto-generated classes set this var |
|
100 | + * |
|
101 | + * @access protected |
|
102 | + * @see _init |
|
103 | + * @var array |
|
104 | + */ |
|
105 | + var $_syntax; |
|
106 | + |
|
107 | + /** |
|
108 | + * Renderer object. |
|
109 | + * |
|
110 | + * @access private |
|
111 | + * @var array |
|
112 | + */ |
|
113 | + var $_renderer; |
|
114 | + |
|
115 | + /** |
|
116 | + * Options. Keeped for BC |
|
117 | + * |
|
118 | + * @access protected |
|
119 | + * @var array |
|
120 | + */ |
|
121 | + var $_options = array(); |
|
122 | + |
|
123 | + /** |
|
124 | + * Conditionds |
|
125 | + * |
|
126 | + * @access protected |
|
127 | + * @var array |
|
128 | + */ |
|
129 | + var $_conditions = array(); |
|
130 | + |
|
131 | + /** |
|
132 | + * Disabled keywords |
|
133 | + * |
|
134 | + * @access protected |
|
135 | + * @var array |
|
136 | + */ |
|
137 | + var $_disabled = array(); |
|
138 | + |
|
139 | + /** |
|
140 | + * Language |
|
141 | + * |
|
142 | + * @access protected |
|
143 | + * @var string |
|
144 | + */ |
|
145 | + var $_language = ''; |
|
146 | + |
|
147 | + // }}} |
|
148 | + // {{{ _checkDefines |
|
149 | + |
|
150 | + /** |
|
151 | + * Called by subclssses' constructors to enable/disable |
|
152 | + * optional highlighter rules |
|
153 | + * |
|
154 | + * @param array $defines Conditional defines |
|
155 | + * |
|
156 | + * @access protected |
|
157 | + */ |
|
158 | + function _checkDefines() |
|
159 | + { |
|
160 | + if (isset($this->_options['defines'])) { |
|
161 | + $defines = $this->_options['defines']; |
|
162 | + } else { |
|
163 | + $defines = array(); |
|
164 | + } |
|
165 | + foreach ($this->_conditions as $name => $actions) { |
|
166 | + foreach($actions as $action) { |
|
167 | + $present = in_array($name, $defines); |
|
168 | + if (!$action[1]) { |
|
169 | + $present = !$present; |
|
170 | + } |
|
171 | + if ($present) { |
|
172 | + unset($this->_disabled[$action[0]]); |
|
173 | + } else { |
|
174 | + $this->_disabled[$action[0]] = true; |
|
175 | + } |
|
176 | + } |
|
177 | + } |
|
178 | + } |
|
179 | + |
|
180 | + // }}} |
|
181 | + // {{{ factory |
|
182 | + |
|
183 | + /** |
|
184 | + * Create a new Highlighter object for specified language |
|
185 | + * |
|
186 | + * @param string $lang language, for example "SQL" |
|
187 | + * @param array $options Rendering options. This |
|
188 | + * parameter is only keeped for BC reasons, use |
|
189 | + * {@link Text_Highlighter::setRenderer()} instead |
|
190 | + * |
|
191 | + * @return mixed a newly created Highlighter object, or |
|
192 | + * a PEAR error object on error |
|
193 | + * |
|
194 | + * @static |
|
195 | + * @access public |
|
196 | + */ |
|
197 | + public static function factory($lang, $options = array()) |
|
198 | + { |
|
199 | + $lang = strtoupper($lang); |
|
200 | + $langFile = dirname(__FILE__)."/Highlighter/$lang.php"; |
|
201 | + if (is_file($langFile)) |
|
202 | + include_once $langFile; |
|
203 | + else |
|
204 | + return false; |
|
205 | + |
|
206 | + $classname = 'Text_Highlighter_' . $lang; |
|
207 | + |
|
208 | + if (!class_exists($classname)) |
|
209 | + return false; |
|
210 | 210 | |
211 | 211 | return new $classname($options); |
212 | - } |
|
213 | - |
|
214 | - // }}} |
|
215 | - // {{{ setRenderer |
|
216 | - |
|
217 | - /** |
|
218 | - * Set renderer object |
|
219 | - * |
|
220 | - * @param object $renderer Text_Highlighter_Renderer |
|
221 | - * |
|
222 | - * @access public |
|
223 | - */ |
|
224 | - function setRenderer($renderer) |
|
225 | - { |
|
226 | - $this->_renderer = $renderer; |
|
227 | - } |
|
228 | - |
|
229 | - // }}} |
|
230 | - |
|
231 | - /** |
|
232 | - * Helper function to find matching brackets |
|
233 | - * |
|
234 | - * @access private |
|
235 | - */ |
|
236 | - function _matchingBrackets($str) |
|
237 | - { |
|
238 | - return strtr($str, '()<>[]{}', ')(><][}{'); |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - |
|
243 | - |
|
244 | - function _getToken() |
|
245 | - { |
|
246 | - if (!empty($this->_tokenStack)) { |
|
247 | - return array_pop($this->_tokenStack); |
|
248 | - } |
|
249 | - if ($this->_pos >= $this->_len) { |
|
250 | - return NULL; |
|
251 | - } |
|
252 | - |
|
253 | - if ($this->_state != -1 && preg_match($this->_endpattern, $this->_str, $m, PREG_OFFSET_CAPTURE, $this->_pos)) { |
|
254 | - $endpos = $m[0][1]; |
|
255 | - $endmatch = $m[0][0]; |
|
256 | - } else { |
|
257 | - $endpos = -1; |
|
258 | - } |
|
259 | - preg_match ($this->_regs[$this->_state], $this->_str, $m, PREG_OFFSET_CAPTURE, $this->_pos); |
|
260 | - $n = 1; |
|
261 | - |
|
262 | - |
|
263 | - foreach ($this->_counts[$this->_state] as $i=>$count) { |
|
264 | - if (!isset($m[$n])) { |
|
265 | - break; |
|
266 | - } |
|
267 | - if ($m[$n][1]>-1 && ($endpos == -1 || $m[$n][1] < $endpos)) { |
|
268 | - if ($this->_states[$this->_state][$i] != -1) { |
|
269 | - $this->_tokenStack[] = array($this->_delim[$this->_state][$i], $m[$n][0]); |
|
270 | - } else { |
|
271 | - $inner = $this->_inner[$this->_state][$i]; |
|
272 | - if (isset($this->_parts[$this->_state][$i])) { |
|
273 | - $parts = array(); |
|
274 | - $partpos = $m[$n][1]; |
|
275 | - for ($j=1; $j<=$count; $j++) { |
|
276 | - if ($m[$j+$n][1] < 0) { |
|
277 | - continue; |
|
278 | - } |
|
279 | - if (isset($this->_parts[$this->_state][$i][$j])) { |
|
280 | - if ($m[$j+$n][1] > $partpos) { |
|
281 | - array_unshift($parts, array($inner, substr($this->_str, $partpos, $m[$j+$n][1]-$partpos))); |
|
282 | - } |
|
283 | - array_unshift($parts, array($this->_parts[$this->_state][$i][$j], $m[$j+$n][0])); |
|
284 | - } |
|
285 | - $partpos = $m[$j+$n][1] + strlen($m[$j+$n][0]); |
|
286 | - } |
|
287 | - if ($partpos < $m[$n][1] + strlen($m[$n][0])) { |
|
288 | - array_unshift($parts, array($inner, substr($this->_str, $partpos, $m[$n][1] - $partpos + strlen($m[$n][0])))); |
|
289 | - } |
|
290 | - $this->_tokenStack = array_merge($this->_tokenStack, $parts); |
|
291 | - } else { |
|
292 | - foreach ($this->_keywords[$this->_state][$i] as $g => $re) { |
|
293 | - if (isset($this->_disabled[$g])) { |
|
294 | - continue; |
|
295 | - } |
|
296 | - if (preg_match($re, $m[$n][0])) { |
|
297 | - $inner = $this->_kwmap[$g]; |
|
298 | - break; |
|
299 | - } |
|
300 | - } |
|
301 | - $this->_tokenStack[] = array($inner, $m[$n][0]); |
|
302 | - } |
|
303 | - } |
|
304 | - if ($m[$n][1] > $this->_pos) { |
|
305 | - $this->_tokenStack[] = array($this->_lastinner, substr($this->_str, $this->_pos, $m[$n][1]-$this->_pos)); |
|
306 | - } |
|
307 | - $this->_pos = $m[$n][1] + strlen($m[$n][0]); |
|
308 | - if ($this->_states[$this->_state][$i] != -1) { |
|
309 | - $this->_stack[] = array($this->_state, $this->_lastdelim, $this->_lastinner, $this->_endpattern); |
|
310 | - $this->_lastinner = $this->_inner[$this->_state][$i]; |
|
311 | - $this->_lastdelim = $this->_delim[$this->_state][$i]; |
|
312 | - $l = $this->_state; |
|
313 | - $this->_state = $this->_states[$this->_state][$i]; |
|
314 | - $this->_endpattern = $this->_end[$this->_state]; |
|
315 | - if ($this->_subst[$l][$i]) { |
|
316 | - for ($k=0; $k<=$this->_counts[$l][$i]; $k++) { |
|
317 | - if (!isset($m[$i+$k])) { |
|
318 | - break; |
|
319 | - } |
|
320 | - $quoted = preg_quote($m[$n+$k][0], '/'); |
|
321 | - $this->_endpattern = str_replace('%'.$k.'%', $quoted, $this->_endpattern); |
|
322 | - $this->_endpattern = str_replace('%b'.$k.'%', $this->_matchingBrackets($quoted), $this->_endpattern); |
|
323 | - } |
|
324 | - } |
|
325 | - } |
|
326 | - return array_pop($this->_tokenStack); |
|
327 | - } |
|
328 | - $n += $count + 1; |
|
329 | - } |
|
330 | - |
|
331 | - if ($endpos > -1) { |
|
332 | - $this->_tokenStack[] = array($this->_lastdelim, $endmatch); |
|
333 | - if ($endpos > $this->_pos) { |
|
334 | - $this->_tokenStack[] = array($this->_lastinner, substr($this->_str, $this->_pos, $endpos-$this->_pos)); |
|
335 | - } |
|
336 | - list($this->_state, $this->_lastdelim, $this->_lastinner, $this->_endpattern) = array_pop($this->_stack); |
|
337 | - $this->_pos = $endpos + strlen($endmatch); |
|
338 | - return array_pop($this->_tokenStack); |
|
339 | - } |
|
340 | - $p = $this->_pos; |
|
341 | - $this->_pos = HL_INFINITY; |
|
342 | - return array($this->_lastinner, substr($this->_str, $p)); |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - |
|
347 | - |
|
348 | - // {{{ highlight |
|
349 | - |
|
350 | - /** |
|
351 | - * Highlights code |
|
352 | - * |
|
353 | - * @param string $str Code to highlight |
|
354 | - * @access public |
|
355 | - * @return string Highlighted text |
|
356 | - * |
|
357 | - */ |
|
358 | - |
|
359 | - function highlight($str) |
|
360 | - { |
|
361 | - if (!($this->_renderer)) { |
|
362 | - include_once('Text/Highlighter/Renderer/Html.php'); |
|
363 | - $this->_renderer = new Text_Highlighter_Renderer_Html($this->_options); |
|
364 | - } |
|
365 | - $this->_state = -1; |
|
366 | - $this->_pos = 0; |
|
367 | - $this->_stack = array(); |
|
368 | - $this->_tokenStack = array(); |
|
369 | - $this->_lastinner = $this->_defClass; |
|
370 | - $this->_lastdelim = $this->_defClass; |
|
371 | - $this->_endpattern = ''; |
|
372 | - $this->_renderer->reset(); |
|
373 | - $this->_renderer->setCurrentLanguage($this->_language); |
|
374 | - $this->_str = $this->_renderer->preprocess($str); |
|
375 | - $this->_len = strlen($this->_str); |
|
376 | - while ($token = $this->_getToken()) { |
|
377 | - $this->_renderer->acceptToken($token[0], $token[1]); |
|
378 | - } |
|
379 | - $this->_renderer->finalize(); |
|
380 | - return $this->_renderer->getOutput(); |
|
381 | - } |
|
382 | - |
|
383 | - // }}} |
|
212 | + } |
|
213 | + |
|
214 | + // }}} |
|
215 | + // {{{ setRenderer |
|
216 | + |
|
217 | + /** |
|
218 | + * Set renderer object |
|
219 | + * |
|
220 | + * @param object $renderer Text_Highlighter_Renderer |
|
221 | + * |
|
222 | + * @access public |
|
223 | + */ |
|
224 | + function setRenderer($renderer) |
|
225 | + { |
|
226 | + $this->_renderer = $renderer; |
|
227 | + } |
|
228 | + |
|
229 | + // }}} |
|
230 | + |
|
231 | + /** |
|
232 | + * Helper function to find matching brackets |
|
233 | + * |
|
234 | + * @access private |
|
235 | + */ |
|
236 | + function _matchingBrackets($str) |
|
237 | + { |
|
238 | + return strtr($str, '()<>[]{}', ')(><][}{'); |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + |
|
243 | + |
|
244 | + function _getToken() |
|
245 | + { |
|
246 | + if (!empty($this->_tokenStack)) { |
|
247 | + return array_pop($this->_tokenStack); |
|
248 | + } |
|
249 | + if ($this->_pos >= $this->_len) { |
|
250 | + return NULL; |
|
251 | + } |
|
252 | + |
|
253 | + if ($this->_state != -1 && preg_match($this->_endpattern, $this->_str, $m, PREG_OFFSET_CAPTURE, $this->_pos)) { |
|
254 | + $endpos = $m[0][1]; |
|
255 | + $endmatch = $m[0][0]; |
|
256 | + } else { |
|
257 | + $endpos = -1; |
|
258 | + } |
|
259 | + preg_match ($this->_regs[$this->_state], $this->_str, $m, PREG_OFFSET_CAPTURE, $this->_pos); |
|
260 | + $n = 1; |
|
261 | + |
|
262 | + |
|
263 | + foreach ($this->_counts[$this->_state] as $i=>$count) { |
|
264 | + if (!isset($m[$n])) { |
|
265 | + break; |
|
266 | + } |
|
267 | + if ($m[$n][1]>-1 && ($endpos == -1 || $m[$n][1] < $endpos)) { |
|
268 | + if ($this->_states[$this->_state][$i] != -1) { |
|
269 | + $this->_tokenStack[] = array($this->_delim[$this->_state][$i], $m[$n][0]); |
|
270 | + } else { |
|
271 | + $inner = $this->_inner[$this->_state][$i]; |
|
272 | + if (isset($this->_parts[$this->_state][$i])) { |
|
273 | + $parts = array(); |
|
274 | + $partpos = $m[$n][1]; |
|
275 | + for ($j=1; $j<=$count; $j++) { |
|
276 | + if ($m[$j+$n][1] < 0) { |
|
277 | + continue; |
|
278 | + } |
|
279 | + if (isset($this->_parts[$this->_state][$i][$j])) { |
|
280 | + if ($m[$j+$n][1] > $partpos) { |
|
281 | + array_unshift($parts, array($inner, substr($this->_str, $partpos, $m[$j+$n][1]-$partpos))); |
|
282 | + } |
|
283 | + array_unshift($parts, array($this->_parts[$this->_state][$i][$j], $m[$j+$n][0])); |
|
284 | + } |
|
285 | + $partpos = $m[$j+$n][1] + strlen($m[$j+$n][0]); |
|
286 | + } |
|
287 | + if ($partpos < $m[$n][1] + strlen($m[$n][0])) { |
|
288 | + array_unshift($parts, array($inner, substr($this->_str, $partpos, $m[$n][1] - $partpos + strlen($m[$n][0])))); |
|
289 | + } |
|
290 | + $this->_tokenStack = array_merge($this->_tokenStack, $parts); |
|
291 | + } else { |
|
292 | + foreach ($this->_keywords[$this->_state][$i] as $g => $re) { |
|
293 | + if (isset($this->_disabled[$g])) { |
|
294 | + continue; |
|
295 | + } |
|
296 | + if (preg_match($re, $m[$n][0])) { |
|
297 | + $inner = $this->_kwmap[$g]; |
|
298 | + break; |
|
299 | + } |
|
300 | + } |
|
301 | + $this->_tokenStack[] = array($inner, $m[$n][0]); |
|
302 | + } |
|
303 | + } |
|
304 | + if ($m[$n][1] > $this->_pos) { |
|
305 | + $this->_tokenStack[] = array($this->_lastinner, substr($this->_str, $this->_pos, $m[$n][1]-$this->_pos)); |
|
306 | + } |
|
307 | + $this->_pos = $m[$n][1] + strlen($m[$n][0]); |
|
308 | + if ($this->_states[$this->_state][$i] != -1) { |
|
309 | + $this->_stack[] = array($this->_state, $this->_lastdelim, $this->_lastinner, $this->_endpattern); |
|
310 | + $this->_lastinner = $this->_inner[$this->_state][$i]; |
|
311 | + $this->_lastdelim = $this->_delim[$this->_state][$i]; |
|
312 | + $l = $this->_state; |
|
313 | + $this->_state = $this->_states[$this->_state][$i]; |
|
314 | + $this->_endpattern = $this->_end[$this->_state]; |
|
315 | + if ($this->_subst[$l][$i]) { |
|
316 | + for ($k=0; $k<=$this->_counts[$l][$i]; $k++) { |
|
317 | + if (!isset($m[$i+$k])) { |
|
318 | + break; |
|
319 | + } |
|
320 | + $quoted = preg_quote($m[$n+$k][0], '/'); |
|
321 | + $this->_endpattern = str_replace('%'.$k.'%', $quoted, $this->_endpattern); |
|
322 | + $this->_endpattern = str_replace('%b'.$k.'%', $this->_matchingBrackets($quoted), $this->_endpattern); |
|
323 | + } |
|
324 | + } |
|
325 | + } |
|
326 | + return array_pop($this->_tokenStack); |
|
327 | + } |
|
328 | + $n += $count + 1; |
|
329 | + } |
|
330 | + |
|
331 | + if ($endpos > -1) { |
|
332 | + $this->_tokenStack[] = array($this->_lastdelim, $endmatch); |
|
333 | + if ($endpos > $this->_pos) { |
|
334 | + $this->_tokenStack[] = array($this->_lastinner, substr($this->_str, $this->_pos, $endpos-$this->_pos)); |
|
335 | + } |
|
336 | + list($this->_state, $this->_lastdelim, $this->_lastinner, $this->_endpattern) = array_pop($this->_stack); |
|
337 | + $this->_pos = $endpos + strlen($endmatch); |
|
338 | + return array_pop($this->_tokenStack); |
|
339 | + } |
|
340 | + $p = $this->_pos; |
|
341 | + $this->_pos = HL_INFINITY; |
|
342 | + return array($this->_lastinner, substr($this->_str, $p)); |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + |
|
347 | + |
|
348 | + // {{{ highlight |
|
349 | + |
|
350 | + /** |
|
351 | + * Highlights code |
|
352 | + * |
|
353 | + * @param string $str Code to highlight |
|
354 | + * @access public |
|
355 | + * @return string Highlighted text |
|
356 | + * |
|
357 | + */ |
|
358 | + |
|
359 | + function highlight($str) |
|
360 | + { |
|
361 | + if (!($this->_renderer)) { |
|
362 | + include_once('Text/Highlighter/Renderer/Html.php'); |
|
363 | + $this->_renderer = new Text_Highlighter_Renderer_Html($this->_options); |
|
364 | + } |
|
365 | + $this->_state = -1; |
|
366 | + $this->_pos = 0; |
|
367 | + $this->_stack = array(); |
|
368 | + $this->_tokenStack = array(); |
|
369 | + $this->_lastinner = $this->_defClass; |
|
370 | + $this->_lastdelim = $this->_defClass; |
|
371 | + $this->_endpattern = ''; |
|
372 | + $this->_renderer->reset(); |
|
373 | + $this->_renderer->setCurrentLanguage($this->_language); |
|
374 | + $this->_str = $this->_renderer->preprocess($str); |
|
375 | + $this->_len = strlen($this->_str); |
|
376 | + while ($token = $this->_getToken()) { |
|
377 | + $this->_renderer->acceptToken($token[0], $token[1]); |
|
378 | + } |
|
379 | + $this->_renderer->finalize(); |
|
380 | + return $this->_renderer->getOutput(); |
|
381 | + } |
|
382 | + |
|
383 | + // }}} |
|
384 | 384 | |
385 | 385 | } |
386 | 386 |
@@ -262,6 +262,7 @@ discard block |
||
262 | 262 | * Sets the input xml file to be parsed |
263 | 263 | * |
264 | 264 | * @param string Filename (full path) |
265 | + * @param string $file |
|
265 | 266 | * @return boolean |
266 | 267 | * @access public |
267 | 268 | */ |
@@ -768,7 +769,6 @@ discard block |
||
768 | 769 | * Add an error message |
769 | 770 | * |
770 | 771 | * @param integer $code Error code |
771 | - * @param mixed $message Error message or array with error message parameters |
|
772 | 772 | * @param integer $lineNo Source code line number |
773 | 773 | * @access private |
774 | 774 | */ |
@@ -67,949 +67,949 @@ discard block |
||
67 | 67 | |
68 | 68 | class Text_Highlighter_Generator extends XML_Parser |
69 | 69 | { |
70 | - // {{{ properties |
|
71 | - /** |
|
72 | - * Whether to do case folding. |
|
73 | - * We have to declare it here, because XML_Parser |
|
74 | - * sets case folding in constructor |
|
75 | - * |
|
76 | - * @var boolean |
|
77 | - */ |
|
78 | - var $folding = false; |
|
79 | - |
|
80 | - /** |
|
81 | - * Holds name of file with highlighting rules |
|
82 | - * |
|
83 | - * @var string |
|
84 | - * @access private |
|
85 | - */ |
|
86 | - var $_syntaxFile; |
|
87 | - |
|
88 | - /** |
|
89 | - * Current element being processed |
|
90 | - * |
|
91 | - * @var array |
|
92 | - * @access private |
|
93 | - */ |
|
94 | - var $_element; |
|
95 | - |
|
96 | - /** |
|
97 | - * List of regions |
|
98 | - * |
|
99 | - * @var array |
|
100 | - * @access private |
|
101 | - */ |
|
102 | - var $_regions = array(); |
|
103 | - |
|
104 | - /** |
|
105 | - * List of blocks |
|
106 | - * |
|
107 | - * @var array |
|
108 | - * @access private |
|
109 | - */ |
|
110 | - var $_blocks = array(); |
|
111 | - |
|
112 | - /** |
|
113 | - * List of keyword groups |
|
114 | - * |
|
115 | - * @var array |
|
116 | - * @access private |
|
117 | - */ |
|
118 | - var $_keywords = array(); |
|
119 | - |
|
120 | - /** |
|
121 | - * List of authors |
|
122 | - * |
|
123 | - * @var array |
|
124 | - * @access private |
|
125 | - */ |
|
126 | - var $_authors = array(); |
|
127 | - |
|
128 | - /** |
|
129 | - * Name of language |
|
130 | - * |
|
131 | - * @var string |
|
132 | - * @access public |
|
133 | - */ |
|
134 | - var $language = ''; |
|
135 | - |
|
136 | - /** |
|
137 | - * Generated code |
|
138 | - * |
|
139 | - * @var string |
|
140 | - * @access private |
|
141 | - */ |
|
142 | - var $_code = ''; |
|
143 | - |
|
144 | - /** |
|
145 | - * Default class |
|
146 | - * |
|
147 | - * @var string |
|
148 | - * @access private |
|
149 | - */ |
|
150 | - var $_defClass = 'default'; |
|
151 | - |
|
152 | - /** |
|
153 | - * Comment |
|
154 | - * |
|
155 | - * @var string |
|
156 | - * @access private |
|
157 | - */ |
|
158 | - var $_comment = ''; |
|
159 | - |
|
160 | - /** |
|
161 | - * Flag for comment processing |
|
162 | - * |
|
163 | - * @var boolean |
|
164 | - * @access private |
|
165 | - */ |
|
166 | - var $_inComment = false; |
|
167 | - |
|
168 | - /** |
|
169 | - * Sorting order of current block/region |
|
170 | - * |
|
171 | - * @var integer |
|
172 | - * @access private |
|
173 | - */ |
|
174 | - var $_blockOrder = 0; |
|
175 | - |
|
176 | - /** |
|
177 | - * Generation errors |
|
178 | - * |
|
179 | - * @var array |
|
180 | - * @access private |
|
181 | - */ |
|
182 | - var $_errors; |
|
183 | - |
|
184 | - // }}} |
|
185 | - // {{{ constructor |
|
186 | - |
|
187 | - /** |
|
188 | - * Constructor |
|
189 | - * |
|
190 | - * @param string $syntaxFile Name of XML file |
|
191 | - * with syntax highlighting rules |
|
192 | - * |
|
193 | - * @access public |
|
194 | - */ |
|
195 | - |
|
196 | - function __construct($syntaxFile = '') |
|
197 | - { |
|
198 | - XML_Parser::XML_Parser(null, 'func'); |
|
199 | - $this->_errors = array(); |
|
200 | - $this->_declareErrorMessages(); |
|
201 | - if ($syntaxFile) { |
|
202 | - $this->setInputFile($syntaxFile); |
|
203 | - } |
|
204 | - } |
|
205 | - |
|
206 | - // }}} |
|
207 | - // {{{ _formatError |
|
208 | - |
|
209 | - /** |
|
210 | - * Format error message |
|
211 | - * |
|
212 | - * @param int $code error code |
|
213 | - * @param string $params parameters |
|
214 | - * @param string $fileName file name |
|
215 | - * @param int $lineNo line number |
|
216 | - * @return array |
|
217 | - * @access public |
|
218 | - */ |
|
219 | - function _formatError($code, $params, $fileName, $lineNo) |
|
220 | - { |
|
221 | - $template = $this->_templates[$code]; |
|
222 | - $ret = call_user_func_array('sprintf', array_merge(array($template), $params)); |
|
223 | - if ($fileName) { |
|
224 | - $ret = '[' . $fileName . '] ' . $ret; |
|
225 | - } |
|
226 | - if ($lineNo) { |
|
227 | - $ret .= ' (line ' . $lineNo . ')'; |
|
228 | - } |
|
229 | - return $ret; |
|
230 | - } |
|
231 | - |
|
232 | - // }}} |
|
233 | - // {{{ declareErrorMessages |
|
234 | - |
|
235 | - /** |
|
236 | - * Set up error message templates |
|
237 | - * |
|
238 | - * @access private |
|
239 | - */ |
|
240 | - function _declareErrorMessages() |
|
241 | - { |
|
242 | - $this->_templates = array ( |
|
243 | - TEXT_HIGHLIGHTER_EMPTY_RE => 'Empty regular expression', |
|
244 | - TEXT_HIGHLIGHTER_INVALID_RE => 'Invalid regular expression : %s', |
|
245 | - TEXT_HIGHLIGHTER_EMPTY_OR_MISSING => 'Empty or missing %s', |
|
246 | - TEXT_HIGHLIGHTER_EMPTY => 'Empty %s', |
|
247 | - TEXT_HIGHLIGHTER_REGION_REGION => 'Region %s refers undefined region %s', |
|
248 | - TEXT_HIGHLIGHTER_REGION_BLOCK => 'Region %s refers undefined block %s', |
|
249 | - TEXT_HIGHLIGHTER_BLOCK_REGION => 'Block %s refers undefined region %s', |
|
250 | - TEXT_HIGHLIGHTER_KEYWORD_BLOCK => 'Keyword group %s refers undefined block %s', |
|
251 | - TEXT_HIGHLIGHTER_KEYWORD_INHERITS => 'Keyword group %s inherits undefined block %s', |
|
252 | - TEXT_HIGHLIGHTER_PARSE => '%s', |
|
253 | - TEXT_HIGHLIGHTER_FILE_WRITE => 'Error writing file %s', |
|
254 | - TEXT_HIGHLIGHTER_FILE_READ => '%s' |
|
255 | - ); |
|
256 | - } |
|
257 | - |
|
258 | - // }}} |
|
259 | - // {{{ setInputFile |
|
260 | - |
|
261 | - /** |
|
262 | - * Sets the input xml file to be parsed |
|
263 | - * |
|
264 | - * @param string Filename (full path) |
|
265 | - * @return boolean |
|
266 | - * @access public |
|
267 | - */ |
|
268 | - function setInputFile($file) |
|
269 | - { |
|
270 | - $this->_syntaxFile = $file; |
|
271 | - $ret = parent::setInputFile($file); |
|
272 | - if (PEAR::isError($ret)) { |
|
273 | - $this->_error(TEXT_HIGHLIGHTER_FILE_READ, $ret->message); |
|
274 | - return false; |
|
275 | - } |
|
276 | - return true; |
|
277 | - } |
|
278 | - |
|
279 | - // }}} |
|
280 | - // {{{ generate |
|
281 | - |
|
282 | - /** |
|
283 | - * Generates class code |
|
284 | - * |
|
285 | - * @access public |
|
286 | - */ |
|
287 | - |
|
288 | - function generate() |
|
289 | - { |
|
290 | - $this->_regions = array(); |
|
291 | - $this->_blocks = array(); |
|
292 | - $this->_keywords = array(); |
|
293 | - $this->language = ''; |
|
294 | - $this->_code = ''; |
|
295 | - $this->_defClass = 'default'; |
|
296 | - $this->_comment = ''; |
|
297 | - $this->_inComment = false; |
|
298 | - $this->_authors = array(); |
|
299 | - $this->_blockOrder = 0; |
|
300 | - $this->_errors = array(); |
|
301 | - |
|
302 | - $ret = $this->parse(); |
|
303 | - if (PEAR::isError($ret)) { |
|
304 | - $this->_error(TEXT_HIGHLIGHTER_PARSE, $ret->message); |
|
305 | - return false; |
|
306 | - } |
|
307 | - return true; |
|
308 | - } |
|
309 | - |
|
310 | - // }}} |
|
311 | - // {{{ getCode |
|
312 | - |
|
313 | - /** |
|
314 | - * Returns generated code as a string. |
|
315 | - * |
|
316 | - * @return string Generated code |
|
317 | - * @access public |
|
318 | - */ |
|
319 | - |
|
320 | - function getCode() |
|
321 | - { |
|
322 | - return $this->_code; |
|
323 | - } |
|
324 | - |
|
325 | - // }}} |
|
326 | - // {{{ saveCode |
|
327 | - |
|
328 | - /** |
|
329 | - * Saves generated class to file. Note that {@link Text_Highlighter::factory()} |
|
330 | - * assumes that filename is uppercase (SQL.php, DTD.php, etc), and file |
|
331 | - * is located in Text/Highlighter |
|
332 | - * |
|
333 | - * @param string $filename Name of file to write the code to |
|
334 | - * @return boolean true on success, false on failure |
|
335 | - * @access public |
|
336 | - */ |
|
337 | - |
|
338 | - function saveCode($filename) |
|
339 | - { |
|
340 | - $f = @fopen($filename, 'wb'); |
|
341 | - if (!$f) { |
|
342 | - $this->_error(TEXT_HIGHLIGHTER_FILE_WRITE, array('outfile'=>$filename)); |
|
343 | - return false; |
|
344 | - } |
|
345 | - fwrite ($f, $this->_code); |
|
346 | - fclose($f); |
|
347 | - return true; |
|
348 | - } |
|
349 | - |
|
350 | - // }}} |
|
351 | - // {{{ hasErrors |
|
352 | - |
|
353 | - /** |
|
354 | - * Reports if there were errors |
|
355 | - * |
|
356 | - * @return boolean |
|
357 | - * @access public |
|
358 | - */ |
|
359 | - |
|
360 | - function hasErrors() |
|
361 | - { |
|
362 | - return count($this->_errors) > 0; |
|
363 | - } |
|
364 | - |
|
365 | - // }}} |
|
366 | - // {{{ getErrors |
|
367 | - |
|
368 | - /** |
|
369 | - * Returns errors |
|
370 | - * |
|
371 | - * @return array |
|
372 | - * @access public |
|
373 | - */ |
|
374 | - |
|
375 | - function getErrors() |
|
376 | - { |
|
377 | - return $this->_errors; |
|
378 | - } |
|
379 | - |
|
380 | - // }}} |
|
381 | - // {{{ _sortBlocks |
|
382 | - |
|
383 | - /** |
|
384 | - * Sorts blocks |
|
385 | - * |
|
386 | - * @access private |
|
387 | - */ |
|
388 | - |
|
389 | - function _sortBlocks($b1, $b2) { |
|
390 | - return $b1['order'] - $b2['order']; |
|
391 | - } |
|
392 | - |
|
393 | - // }}} |
|
394 | - // {{{ _sortLookFor |
|
395 | - /** |
|
396 | - * Sort 'look for' list |
|
397 | - * @return int |
|
398 | - * @param string $b1 |
|
399 | - * @param string $b2 |
|
400 | - */ |
|
401 | - function _sortLookFor($b1, $b2) { |
|
402 | - $o1 = isset($this->_blocks[$b1]) ? $this->_blocks[$b1]['order'] : $this->_regions[$b1]['order']; |
|
403 | - $o2 = isset($this->_blocks[$b2]) ? $this->_blocks[$b2]['order'] : $this->_regions[$b2]['order']; |
|
404 | - return $o1 - $o2; |
|
405 | - } |
|
406 | - |
|
407 | - // }}} |
|
408 | - // {{{ _makeRE |
|
409 | - |
|
410 | - /** |
|
411 | - * Adds delimiters and modifiers to regular expression if necessary |
|
412 | - * |
|
413 | - * @param string $text Original RE |
|
414 | - * @return string Final RE |
|
415 | - * @access private |
|
416 | - */ |
|
417 | - function _makeRE($text, $case = false) |
|
418 | - { |
|
419 | - if (!strlen($text)) { |
|
420 | - $this->_error(TEXT_HIGHLIGHTER_EMPTY_RE); |
|
421 | - } |
|
422 | - if (!strlen($text) || $text{0} != '/') { |
|
423 | - $text = '/' . $text . '/'; |
|
424 | - } |
|
425 | - if (!$case) { |
|
426 | - $text .= 'i'; |
|
427 | - } |
|
428 | - $php_errormsg = ''; |
|
429 | - @preg_match($text, ''); |
|
430 | - if ($php_errormsg) { |
|
431 | - $this->_error(TEXT_HIGHLIGHTER_INVALID_RE, $php_errormsg); |
|
432 | - } |
|
433 | - preg_match ('#^/(.+)/(.*)$#', $text, $m); |
|
434 | - if (@$m[2]) { |
|
435 | - $text = '(?' . $m[2] . ')' . $m[1]; |
|
436 | - } else { |
|
437 | - $text = $m[1]; |
|
438 | - } |
|
439 | - return $text; |
|
440 | - } |
|
441 | - |
|
442 | - // }}} |
|
443 | - // {{{ _exportArray |
|
444 | - |
|
445 | - /** |
|
446 | - * Exports array as PHP code |
|
447 | - * |
|
448 | - * @param array $array |
|
449 | - * @return string Code |
|
450 | - * @access private |
|
451 | - */ |
|
452 | - function _exportArray($array) |
|
453 | - { |
|
454 | - $array = var_export($array, true); |
|
455 | - return trim(preg_replace('~^(\s*)~m',' \1\1',$array)); |
|
456 | - } |
|
457 | - |
|
458 | - // }}} |
|
459 | - // {{{ _countSubpatterns |
|
460 | - /** |
|
461 | - * Find number of capturing suppaterns in regular expression |
|
462 | - * @return int |
|
463 | - * @param string $re Regular expression (without delimiters) |
|
464 | - */ |
|
465 | - function _countSubpatterns($re) |
|
466 | - { |
|
467 | - preg_match_all('/' . $re . '/', '', $m); |
|
468 | - return count($m)-1; |
|
469 | - } |
|
470 | - |
|
471 | - // }}} |
|
472 | - |
|
473 | - /**#@+ |
|
70 | + // {{{ properties |
|
71 | + /** |
|
72 | + * Whether to do case folding. |
|
73 | + * We have to declare it here, because XML_Parser |
|
74 | + * sets case folding in constructor |
|
75 | + * |
|
76 | + * @var boolean |
|
77 | + */ |
|
78 | + var $folding = false; |
|
79 | + |
|
80 | + /** |
|
81 | + * Holds name of file with highlighting rules |
|
82 | + * |
|
83 | + * @var string |
|
84 | + * @access private |
|
85 | + */ |
|
86 | + var $_syntaxFile; |
|
87 | + |
|
88 | + /** |
|
89 | + * Current element being processed |
|
90 | + * |
|
91 | + * @var array |
|
92 | + * @access private |
|
93 | + */ |
|
94 | + var $_element; |
|
95 | + |
|
96 | + /** |
|
97 | + * List of regions |
|
98 | + * |
|
99 | + * @var array |
|
100 | + * @access private |
|
101 | + */ |
|
102 | + var $_regions = array(); |
|
103 | + |
|
104 | + /** |
|
105 | + * List of blocks |
|
106 | + * |
|
107 | + * @var array |
|
108 | + * @access private |
|
109 | + */ |
|
110 | + var $_blocks = array(); |
|
111 | + |
|
112 | + /** |
|
113 | + * List of keyword groups |
|
114 | + * |
|
115 | + * @var array |
|
116 | + * @access private |
|
117 | + */ |
|
118 | + var $_keywords = array(); |
|
119 | + |
|
120 | + /** |
|
121 | + * List of authors |
|
122 | + * |
|
123 | + * @var array |
|
124 | + * @access private |
|
125 | + */ |
|
126 | + var $_authors = array(); |
|
127 | + |
|
128 | + /** |
|
129 | + * Name of language |
|
130 | + * |
|
131 | + * @var string |
|
132 | + * @access public |
|
133 | + */ |
|
134 | + var $language = ''; |
|
135 | + |
|
136 | + /** |
|
137 | + * Generated code |
|
138 | + * |
|
139 | + * @var string |
|
140 | + * @access private |
|
141 | + */ |
|
142 | + var $_code = ''; |
|
143 | + |
|
144 | + /** |
|
145 | + * Default class |
|
146 | + * |
|
147 | + * @var string |
|
148 | + * @access private |
|
149 | + */ |
|
150 | + var $_defClass = 'default'; |
|
151 | + |
|
152 | + /** |
|
153 | + * Comment |
|
154 | + * |
|
155 | + * @var string |
|
156 | + * @access private |
|
157 | + */ |
|
158 | + var $_comment = ''; |
|
159 | + |
|
160 | + /** |
|
161 | + * Flag for comment processing |
|
162 | + * |
|
163 | + * @var boolean |
|
164 | + * @access private |
|
165 | + */ |
|
166 | + var $_inComment = false; |
|
167 | + |
|
168 | + /** |
|
169 | + * Sorting order of current block/region |
|
170 | + * |
|
171 | + * @var integer |
|
172 | + * @access private |
|
173 | + */ |
|
174 | + var $_blockOrder = 0; |
|
175 | + |
|
176 | + /** |
|
177 | + * Generation errors |
|
178 | + * |
|
179 | + * @var array |
|
180 | + * @access private |
|
181 | + */ |
|
182 | + var $_errors; |
|
183 | + |
|
184 | + // }}} |
|
185 | + // {{{ constructor |
|
186 | + |
|
187 | + /** |
|
188 | + * Constructor |
|
189 | + * |
|
190 | + * @param string $syntaxFile Name of XML file |
|
191 | + * with syntax highlighting rules |
|
192 | + * |
|
193 | + * @access public |
|
194 | + */ |
|
195 | + |
|
196 | + function __construct($syntaxFile = '') |
|
197 | + { |
|
198 | + XML_Parser::XML_Parser(null, 'func'); |
|
199 | + $this->_errors = array(); |
|
200 | + $this->_declareErrorMessages(); |
|
201 | + if ($syntaxFile) { |
|
202 | + $this->setInputFile($syntaxFile); |
|
203 | + } |
|
204 | + } |
|
205 | + |
|
206 | + // }}} |
|
207 | + // {{{ _formatError |
|
208 | + |
|
209 | + /** |
|
210 | + * Format error message |
|
211 | + * |
|
212 | + * @param int $code error code |
|
213 | + * @param string $params parameters |
|
214 | + * @param string $fileName file name |
|
215 | + * @param int $lineNo line number |
|
216 | + * @return array |
|
217 | + * @access public |
|
218 | + */ |
|
219 | + function _formatError($code, $params, $fileName, $lineNo) |
|
220 | + { |
|
221 | + $template = $this->_templates[$code]; |
|
222 | + $ret = call_user_func_array('sprintf', array_merge(array($template), $params)); |
|
223 | + if ($fileName) { |
|
224 | + $ret = '[' . $fileName . '] ' . $ret; |
|
225 | + } |
|
226 | + if ($lineNo) { |
|
227 | + $ret .= ' (line ' . $lineNo . ')'; |
|
228 | + } |
|
229 | + return $ret; |
|
230 | + } |
|
231 | + |
|
232 | + // }}} |
|
233 | + // {{{ declareErrorMessages |
|
234 | + |
|
235 | + /** |
|
236 | + * Set up error message templates |
|
237 | + * |
|
238 | + * @access private |
|
239 | + */ |
|
240 | + function _declareErrorMessages() |
|
241 | + { |
|
242 | + $this->_templates = array ( |
|
243 | + TEXT_HIGHLIGHTER_EMPTY_RE => 'Empty regular expression', |
|
244 | + TEXT_HIGHLIGHTER_INVALID_RE => 'Invalid regular expression : %s', |
|
245 | + TEXT_HIGHLIGHTER_EMPTY_OR_MISSING => 'Empty or missing %s', |
|
246 | + TEXT_HIGHLIGHTER_EMPTY => 'Empty %s', |
|
247 | + TEXT_HIGHLIGHTER_REGION_REGION => 'Region %s refers undefined region %s', |
|
248 | + TEXT_HIGHLIGHTER_REGION_BLOCK => 'Region %s refers undefined block %s', |
|
249 | + TEXT_HIGHLIGHTER_BLOCK_REGION => 'Block %s refers undefined region %s', |
|
250 | + TEXT_HIGHLIGHTER_KEYWORD_BLOCK => 'Keyword group %s refers undefined block %s', |
|
251 | + TEXT_HIGHLIGHTER_KEYWORD_INHERITS => 'Keyword group %s inherits undefined block %s', |
|
252 | + TEXT_HIGHLIGHTER_PARSE => '%s', |
|
253 | + TEXT_HIGHLIGHTER_FILE_WRITE => 'Error writing file %s', |
|
254 | + TEXT_HIGHLIGHTER_FILE_READ => '%s' |
|
255 | + ); |
|
256 | + } |
|
257 | + |
|
258 | + // }}} |
|
259 | + // {{{ setInputFile |
|
260 | + |
|
261 | + /** |
|
262 | + * Sets the input xml file to be parsed |
|
263 | + * |
|
264 | + * @param string Filename (full path) |
|
265 | + * @return boolean |
|
266 | + * @access public |
|
267 | + */ |
|
268 | + function setInputFile($file) |
|
269 | + { |
|
270 | + $this->_syntaxFile = $file; |
|
271 | + $ret = parent::setInputFile($file); |
|
272 | + if (PEAR::isError($ret)) { |
|
273 | + $this->_error(TEXT_HIGHLIGHTER_FILE_READ, $ret->message); |
|
274 | + return false; |
|
275 | + } |
|
276 | + return true; |
|
277 | + } |
|
278 | + |
|
279 | + // }}} |
|
280 | + // {{{ generate |
|
281 | + |
|
282 | + /** |
|
283 | + * Generates class code |
|
284 | + * |
|
285 | + * @access public |
|
286 | + */ |
|
287 | + |
|
288 | + function generate() |
|
289 | + { |
|
290 | + $this->_regions = array(); |
|
291 | + $this->_blocks = array(); |
|
292 | + $this->_keywords = array(); |
|
293 | + $this->language = ''; |
|
294 | + $this->_code = ''; |
|
295 | + $this->_defClass = 'default'; |
|
296 | + $this->_comment = ''; |
|
297 | + $this->_inComment = false; |
|
298 | + $this->_authors = array(); |
|
299 | + $this->_blockOrder = 0; |
|
300 | + $this->_errors = array(); |
|
301 | + |
|
302 | + $ret = $this->parse(); |
|
303 | + if (PEAR::isError($ret)) { |
|
304 | + $this->_error(TEXT_HIGHLIGHTER_PARSE, $ret->message); |
|
305 | + return false; |
|
306 | + } |
|
307 | + return true; |
|
308 | + } |
|
309 | + |
|
310 | + // }}} |
|
311 | + // {{{ getCode |
|
312 | + |
|
313 | + /** |
|
314 | + * Returns generated code as a string. |
|
315 | + * |
|
316 | + * @return string Generated code |
|
317 | + * @access public |
|
318 | + */ |
|
319 | + |
|
320 | + function getCode() |
|
321 | + { |
|
322 | + return $this->_code; |
|
323 | + } |
|
324 | + |
|
325 | + // }}} |
|
326 | + // {{{ saveCode |
|
327 | + |
|
328 | + /** |
|
329 | + * Saves generated class to file. Note that {@link Text_Highlighter::factory()} |
|
330 | + * assumes that filename is uppercase (SQL.php, DTD.php, etc), and file |
|
331 | + * is located in Text/Highlighter |
|
332 | + * |
|
333 | + * @param string $filename Name of file to write the code to |
|
334 | + * @return boolean true on success, false on failure |
|
335 | + * @access public |
|
336 | + */ |
|
337 | + |
|
338 | + function saveCode($filename) |
|
339 | + { |
|
340 | + $f = @fopen($filename, 'wb'); |
|
341 | + if (!$f) { |
|
342 | + $this->_error(TEXT_HIGHLIGHTER_FILE_WRITE, array('outfile'=>$filename)); |
|
343 | + return false; |
|
344 | + } |
|
345 | + fwrite ($f, $this->_code); |
|
346 | + fclose($f); |
|
347 | + return true; |
|
348 | + } |
|
349 | + |
|
350 | + // }}} |
|
351 | + // {{{ hasErrors |
|
352 | + |
|
353 | + /** |
|
354 | + * Reports if there were errors |
|
355 | + * |
|
356 | + * @return boolean |
|
357 | + * @access public |
|
358 | + */ |
|
359 | + |
|
360 | + function hasErrors() |
|
361 | + { |
|
362 | + return count($this->_errors) > 0; |
|
363 | + } |
|
364 | + |
|
365 | + // }}} |
|
366 | + // {{{ getErrors |
|
367 | + |
|
368 | + /** |
|
369 | + * Returns errors |
|
370 | + * |
|
371 | + * @return array |
|
372 | + * @access public |
|
373 | + */ |
|
374 | + |
|
375 | + function getErrors() |
|
376 | + { |
|
377 | + return $this->_errors; |
|
378 | + } |
|
379 | + |
|
380 | + // }}} |
|
381 | + // {{{ _sortBlocks |
|
382 | + |
|
383 | + /** |
|
384 | + * Sorts blocks |
|
385 | + * |
|
386 | + * @access private |
|
387 | + */ |
|
388 | + |
|
389 | + function _sortBlocks($b1, $b2) { |
|
390 | + return $b1['order'] - $b2['order']; |
|
391 | + } |
|
392 | + |
|
393 | + // }}} |
|
394 | + // {{{ _sortLookFor |
|
395 | + /** |
|
396 | + * Sort 'look for' list |
|
397 | + * @return int |
|
398 | + * @param string $b1 |
|
399 | + * @param string $b2 |
|
400 | + */ |
|
401 | + function _sortLookFor($b1, $b2) { |
|
402 | + $o1 = isset($this->_blocks[$b1]) ? $this->_blocks[$b1]['order'] : $this->_regions[$b1]['order']; |
|
403 | + $o2 = isset($this->_blocks[$b2]) ? $this->_blocks[$b2]['order'] : $this->_regions[$b2]['order']; |
|
404 | + return $o1 - $o2; |
|
405 | + } |
|
406 | + |
|
407 | + // }}} |
|
408 | + // {{{ _makeRE |
|
409 | + |
|
410 | + /** |
|
411 | + * Adds delimiters and modifiers to regular expression if necessary |
|
412 | + * |
|
413 | + * @param string $text Original RE |
|
414 | + * @return string Final RE |
|
415 | + * @access private |
|
416 | + */ |
|
417 | + function _makeRE($text, $case = false) |
|
418 | + { |
|
419 | + if (!strlen($text)) { |
|
420 | + $this->_error(TEXT_HIGHLIGHTER_EMPTY_RE); |
|
421 | + } |
|
422 | + if (!strlen($text) || $text{0} != '/') { |
|
423 | + $text = '/' . $text . '/'; |
|
424 | + } |
|
425 | + if (!$case) { |
|
426 | + $text .= 'i'; |
|
427 | + } |
|
428 | + $php_errormsg = ''; |
|
429 | + @preg_match($text, ''); |
|
430 | + if ($php_errormsg) { |
|
431 | + $this->_error(TEXT_HIGHLIGHTER_INVALID_RE, $php_errormsg); |
|
432 | + } |
|
433 | + preg_match ('#^/(.+)/(.*)$#', $text, $m); |
|
434 | + if (@$m[2]) { |
|
435 | + $text = '(?' . $m[2] . ')' . $m[1]; |
|
436 | + } else { |
|
437 | + $text = $m[1]; |
|
438 | + } |
|
439 | + return $text; |
|
440 | + } |
|
441 | + |
|
442 | + // }}} |
|
443 | + // {{{ _exportArray |
|
444 | + |
|
445 | + /** |
|
446 | + * Exports array as PHP code |
|
447 | + * |
|
448 | + * @param array $array |
|
449 | + * @return string Code |
|
450 | + * @access private |
|
451 | + */ |
|
452 | + function _exportArray($array) |
|
453 | + { |
|
454 | + $array = var_export($array, true); |
|
455 | + return trim(preg_replace('~^(\s*)~m',' \1\1',$array)); |
|
456 | + } |
|
457 | + |
|
458 | + // }}} |
|
459 | + // {{{ _countSubpatterns |
|
460 | + /** |
|
461 | + * Find number of capturing suppaterns in regular expression |
|
462 | + * @return int |
|
463 | + * @param string $re Regular expression (without delimiters) |
|
464 | + */ |
|
465 | + function _countSubpatterns($re) |
|
466 | + { |
|
467 | + preg_match_all('/' . $re . '/', '', $m); |
|
468 | + return count($m)-1; |
|
469 | + } |
|
470 | + |
|
471 | + // }}} |
|
472 | + |
|
473 | + /**#@+ |
|
474 | 474 | * @access private |
475 | 475 | * @param resource $xp XML parser resource |
476 | 476 | * @param string $elem XML element name |
477 | 477 | * @param array $attribs XML element attributes |
478 | 478 | */ |
479 | 479 | |
480 | - // {{{ xmltag_Default |
|
481 | - |
|
482 | - /** |
|
483 | - * start handler for <default> element |
|
484 | - */ |
|
485 | - function xmltag_Default($xp, $elem, $attribs) |
|
486 | - { |
|
487 | - $this->_aliasAttributes($attribs); |
|
488 | - if (!isset($attribs['innerGroup']) || $attribs['innerGroup'] === '') { |
|
489 | - $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'innerGroup'); |
|
490 | - } |
|
491 | - $this->_defClass = @$attribs['innerGroup']; |
|
492 | - } |
|
493 | - |
|
494 | - // }}} |
|
495 | - // {{{ xmltag_Region |
|
496 | - |
|
497 | - /** |
|
498 | - * start handler for <region> element |
|
499 | - */ |
|
500 | - function xmltag_Region($xp, $elem, $attribs) |
|
501 | - { |
|
502 | - $this->_aliasAttributes($attribs); |
|
503 | - if (!isset($attribs['name']) || $attribs['name'] === '') { |
|
504 | - $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'region name'); |
|
505 | - } |
|
506 | - if (!isset($attribs['innerGroup']) || $attribs['innerGroup'] === '') { |
|
507 | - $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'innerGroup'); |
|
508 | - } |
|
509 | - $this->_element = array('name' => $attribs['name']); |
|
510 | - $this->_element['line'] = xml_get_current_line_number($this->parser); |
|
511 | - if (isset($attribs['case'])) { |
|
512 | - $this->_element['case'] = $attribs['case'] == 'yes'; |
|
513 | - } else { |
|
514 | - $this->_element['case'] = $this->_case; |
|
515 | - } |
|
516 | - $this->_element['innerGroup'] = $attribs['innerGroup']; |
|
517 | - $this->_element['delimGroup'] = isset($attribs['delimGroup']) ? |
|
518 | - $attribs['delimGroup'] : |
|
519 | - $attribs['innerGroup']; |
|
520 | - $this->_element['start'] = $this->_makeRE(@$attribs['start'], $this->_element['case']); |
|
521 | - $this->_element['end'] = $this->_makeRE(@$attribs['end'], $this->_element['case']); |
|
522 | - $this->_element['contained'] = @$attribs['contained'] == 'yes'; |
|
523 | - $this->_element['never-contained'] = @$attribs['never-contained'] == 'yes'; |
|
524 | - $this->_element['remember'] = @$attribs['remember'] == 'yes'; |
|
525 | - if (isset($attribs['startBOL']) && $attribs['startBOL'] == 'yes') { |
|
526 | - $this->_element['startBOL'] = true; |
|
527 | - } |
|
528 | - if (isset($attribs['endBOL']) && $attribs['endBOL'] == 'yes') { |
|
529 | - $this->_element['endBOL'] = true; |
|
530 | - } |
|
531 | - if (isset($attribs['neverAfter'])) { |
|
532 | - $this->_element['neverafter'] = $this->_makeRE($attribs['neverAfter']); |
|
533 | - } |
|
534 | - } |
|
535 | - |
|
536 | - // }}} |
|
537 | - // {{{ xmltag_Block |
|
538 | - |
|
539 | - /** |
|
540 | - * start handler for <block> element |
|
541 | - */ |
|
542 | - function xmltag_Block($xp, $elem, $attribs) |
|
543 | - { |
|
544 | - $this->_aliasAttributes($attribs); |
|
545 | - if (!isset($attribs['name']) || $attribs['name'] === '') { |
|
546 | - $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'block name'); |
|
547 | - } |
|
548 | - if (isset($attribs['innerGroup']) && $attribs['innerGroup'] === '') { |
|
549 | - $this->_error(TEXT_HIGHLIGHTER_EMPTY, 'innerGroup'); |
|
550 | - } |
|
551 | - $this->_element = array('name' => $attribs['name']); |
|
552 | - $this->_element['line'] = xml_get_current_line_number($this->parser); |
|
553 | - if (isset($attribs['case'])) { |
|
554 | - $this->_element['case'] = $attribs['case'] == 'yes'; |
|
555 | - } else { |
|
556 | - $this->_element['case'] = $this->_case; |
|
557 | - } |
|
558 | - if (isset($attribs['innerGroup'])) { |
|
559 | - $this->_element['innerGroup'] = @$attribs['innerGroup']; |
|
560 | - } |
|
561 | - $this->_element['match'] = $this->_makeRE($attribs['match'], $this->_element['case']); |
|
562 | - $this->_element['contained'] = @$attribs['contained'] == 'yes'; |
|
563 | - $this->_element['multiline'] = @$attribs['multiline'] == 'yes'; |
|
564 | - if (isset($attribs['BOL']) && $attribs['BOL'] == 'yes') { |
|
565 | - $this->_element['BOL'] = true; |
|
566 | - } |
|
567 | - if (isset($attribs['neverAfter'])) { |
|
568 | - $this->_element['neverafter'] = $this->_makeRE($attribs['neverAfter']); |
|
569 | - } |
|
570 | - } |
|
571 | - |
|
572 | - // }}} |
|
573 | - // {{{ cdataHandler |
|
574 | - |
|
575 | - /** |
|
576 | - * Character data handler. Used for comment |
|
577 | - */ |
|
578 | - function cdataHandler($xp, $cdata) |
|
579 | - { |
|
580 | - if ($this->_inComment) { |
|
581 | - $this->_comment .= $cdata; |
|
582 | - } |
|
583 | - } |
|
584 | - |
|
585 | - // }}} |
|
586 | - // {{{ xmltag_Comment |
|
587 | - |
|
588 | - /** |
|
589 | - * start handler for <comment> element |
|
590 | - */ |
|
591 | - function xmltag_Comment($xp, $elem, $attribs) |
|
592 | - { |
|
593 | - $this->_comment = ''; |
|
594 | - $this->_inComment = true; |
|
595 | - } |
|
596 | - |
|
597 | - // }}} |
|
598 | - // {{{ xmltag_PartGroup |
|
599 | - |
|
600 | - /** |
|
601 | - * start handler for <partgroup> element |
|
602 | - */ |
|
603 | - function xmltag_PartGroup($xp, $elem, $attribs) |
|
604 | - { |
|
605 | - $this->_aliasAttributes($attribs); |
|
606 | - if (!isset($attribs['innerGroup']) || $attribs['innerGroup'] === '') { |
|
607 | - $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'innerGroup'); |
|
608 | - } |
|
609 | - $this->_element['partClass'][$attribs['index']] = @$attribs['innerGroup']; |
|
610 | - } |
|
611 | - |
|
612 | - // }}} |
|
613 | - // {{{ xmltag_PartClass |
|
614 | - |
|
615 | - /** |
|
616 | - * start handler for <partclass> element |
|
617 | - */ |
|
618 | - function xmltag_PartClass($xp, $elem, $attribs) |
|
619 | - { |
|
620 | - $this->xmltag_PartGroup($xp, $elem, $attribs); |
|
621 | - } |
|
622 | - |
|
623 | - // }}} |
|
624 | - // {{{ xmltag_Keywords |
|
625 | - |
|
626 | - /** |
|
627 | - * start handler for <keywords> element |
|
628 | - */ |
|
629 | - function xmltag_Keywords($xp, $elem, $attribs) |
|
630 | - { |
|
631 | - $this->_aliasAttributes($attribs); |
|
632 | - if (!isset($attribs['name']) || $attribs['name'] === '') { |
|
633 | - $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'keyword group name'); |
|
634 | - } |
|
635 | - if (!isset($attribs['innerGroup']) || $attribs['innerGroup'] === '') { |
|
636 | - $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'innerGroup'); |
|
637 | - } |
|
638 | - if (!isset($attribs['inherits']) || $attribs['inherits'] === '') { |
|
639 | - $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'inherits'); |
|
640 | - } |
|
641 | - $this->_element = array('name'=>@$attribs['name']); |
|
642 | - $this->_element['line'] = xml_get_current_line_number($this->parser); |
|
643 | - $this->_element['innerGroup'] = @$attribs['innerGroup']; |
|
644 | - if (isset($attribs['case'])) { |
|
645 | - $this->_element['case'] = $attribs['case'] == 'yes'; |
|
646 | - } else { |
|
647 | - $this->_element['case'] = $this->_case; |
|
648 | - } |
|
649 | - $this->_element['inherits'] = @$attribs['inherits']; |
|
650 | - if (isset($attribs['otherwise'])) { |
|
651 | - $this->_element['otherwise'] = $attribs['otherwise']; |
|
652 | - } |
|
653 | - if (isset($attribs['ifdef'])) { |
|
654 | - $this->_element['ifdef'] = $attribs['ifdef']; |
|
655 | - } |
|
656 | - if (isset($attribs['ifndef'])) { |
|
657 | - $this->_element['ifndef'] = $attribs['ifndef']; |
|
658 | - } |
|
659 | - } |
|
660 | - |
|
661 | - // }}} |
|
662 | - // {{{ xmltag_Keyword |
|
663 | - |
|
664 | - /** |
|
665 | - * start handler for <keyword> element |
|
666 | - */ |
|
667 | - function xmltag_Keyword($xp, $elem, $attribs) |
|
668 | - { |
|
669 | - if (!isset($attribs['match']) || $attribs['match'] === '') { |
|
670 | - $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'match'); |
|
671 | - } |
|
672 | - $keyword = @$attribs['match']; |
|
673 | - if (!$this->_element['case']) { |
|
674 | - $keyword = strtolower($keyword); |
|
675 | - } |
|
676 | - $this->_element['match'][$keyword] = true; |
|
677 | - } |
|
678 | - |
|
679 | - // }}} |
|
680 | - // {{{ xmltag_Contains |
|
681 | - |
|
682 | - /** |
|
683 | - * start handler for <contains> element |
|
684 | - */ |
|
685 | - function xmltag_Contains($xp, $elem, $attribs) |
|
686 | - { |
|
687 | - $this->_element['contains-all'] = @$attribs['all'] == 'yes'; |
|
688 | - if (isset($attribs['region'])) { |
|
689 | - $this->_element['contains']['region'][$attribs['region']] = |
|
690 | - xml_get_current_line_number($this->parser); |
|
691 | - } |
|
692 | - if (isset($attribs['block'])) { |
|
693 | - $this->_element['contains']['block'][$attribs['block']] = |
|
694 | - xml_get_current_line_number($this->parser); |
|
695 | - } |
|
696 | - } |
|
697 | - |
|
698 | - // }}} |
|
699 | - // {{{ xmltag_But |
|
700 | - |
|
701 | - /** |
|
702 | - * start handler for <but> element |
|
703 | - */ |
|
704 | - function xmltag_But($xp, $elem, $attribs) |
|
705 | - { |
|
706 | - if (isset($attribs['region'])) { |
|
707 | - $this->_element['not-contains']['region'][$attribs['region']] = true; |
|
708 | - } |
|
709 | - if (isset($attribs['block'])) { |
|
710 | - $this->_element['not-contains']['block'][$attribs['block']] = true; |
|
711 | - } |
|
712 | - } |
|
713 | - |
|
714 | - // }}} |
|
715 | - // {{{ xmltag_Onlyin |
|
716 | - |
|
717 | - /** |
|
718 | - * start handler for <onlyin> element |
|
719 | - */ |
|
720 | - function xmltag_Onlyin($xp, $elem, $attribs) |
|
721 | - { |
|
722 | - if (!isset($attribs['region']) || $attribs['region'] === '') { |
|
723 | - $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'region'); |
|
724 | - } |
|
725 | - $this->_element['onlyin'][$attribs['region']] = xml_get_current_line_number($this->parser); |
|
726 | - } |
|
727 | - |
|
728 | - // }}} |
|
729 | - // {{{ xmltag_Author |
|
730 | - |
|
731 | - /** |
|
732 | - * start handler for <author> element |
|
733 | - */ |
|
734 | - function xmltag_Author($xp, $elem, $attribs) |
|
735 | - { |
|
736 | - if (!isset($attribs['name']) || $attribs['name'] === '') { |
|
737 | - $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'author name'); |
|
738 | - } |
|
739 | - $this->_authors[] = array( |
|
740 | - 'name' => @$attribs['name'], |
|
741 | - 'email' => (string)@$attribs['email'] |
|
742 | - ); |
|
743 | - } |
|
744 | - |
|
745 | - // }}} |
|
746 | - // {{{ xmltag_Highlight |
|
747 | - |
|
748 | - /** |
|
749 | - * start handler for <highlight> element |
|
750 | - */ |
|
751 | - function xmltag_Highlight($xp, $elem, $attribs) |
|
752 | - { |
|
753 | - if (!isset($attribs['lang']) || $attribs['lang'] === '') { |
|
754 | - $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'language name'); |
|
755 | - } |
|
756 | - $this->_code = ''; |
|
757 | - $this->language = strtoupper(@$attribs['lang']); |
|
758 | - $this->_case = @$attribs['case'] == 'yes'; |
|
759 | - } |
|
760 | - |
|
761 | - // }}} |
|
762 | - |
|
763 | - /**#@-*/ |
|
764 | - |
|
765 | - // {{{ _error |
|
766 | - |
|
767 | - /** |
|
768 | - * Add an error message |
|
769 | - * |
|
770 | - * @param integer $code Error code |
|
771 | - * @param mixed $message Error message or array with error message parameters |
|
772 | - * @param integer $lineNo Source code line number |
|
773 | - * @access private |
|
774 | - */ |
|
775 | - function _error($code, $params = array(), $lineNo = 0) |
|
776 | - { |
|
777 | - if (!$lineNo && !empty($this->parser)) { |
|
778 | - $lineNo = xml_get_current_line_number($this->parser); |
|
779 | - } |
|
780 | - $this->_errors[] = $this->_formatError($code, $params, $this->_syntaxFile, $lineNo); |
|
781 | - } |
|
782 | - |
|
783 | - // }}} |
|
784 | - // {{{ _aliasAttributes |
|
785 | - |
|
786 | - /** |
|
787 | - * BC trick |
|
788 | - * |
|
789 | - * @param array $attrs attributes |
|
790 | - */ |
|
791 | - function _aliasAttributes(&$attrs) |
|
792 | - { |
|
793 | - if (isset($attrs['innerClass']) && !isset($attrs['innerGroup'])) { |
|
794 | - $attrs['innerGroup'] = $attrs['innerClass']; |
|
795 | - } |
|
796 | - if (isset($attrs['delimClass']) && !isset($attrs['delimGroup'])) { |
|
797 | - $attrs['delimGroup'] = $attrs['delimClass']; |
|
798 | - } |
|
799 | - if (isset($attrs['partClass']) && !isset($attrs['partGroup'])) { |
|
800 | - $attrs['partGroup'] = $attrs['partClass']; |
|
801 | - } |
|
802 | - } |
|
803 | - |
|
804 | - // }}} |
|
805 | - |
|
806 | - /**#@+ |
|
480 | + // {{{ xmltag_Default |
|
481 | + |
|
482 | + /** |
|
483 | + * start handler for <default> element |
|
484 | + */ |
|
485 | + function xmltag_Default($xp, $elem, $attribs) |
|
486 | + { |
|
487 | + $this->_aliasAttributes($attribs); |
|
488 | + if (!isset($attribs['innerGroup']) || $attribs['innerGroup'] === '') { |
|
489 | + $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'innerGroup'); |
|
490 | + } |
|
491 | + $this->_defClass = @$attribs['innerGroup']; |
|
492 | + } |
|
493 | + |
|
494 | + // }}} |
|
495 | + // {{{ xmltag_Region |
|
496 | + |
|
497 | + /** |
|
498 | + * start handler for <region> element |
|
499 | + */ |
|
500 | + function xmltag_Region($xp, $elem, $attribs) |
|
501 | + { |
|
502 | + $this->_aliasAttributes($attribs); |
|
503 | + if (!isset($attribs['name']) || $attribs['name'] === '') { |
|
504 | + $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'region name'); |
|
505 | + } |
|
506 | + if (!isset($attribs['innerGroup']) || $attribs['innerGroup'] === '') { |
|
507 | + $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'innerGroup'); |
|
508 | + } |
|
509 | + $this->_element = array('name' => $attribs['name']); |
|
510 | + $this->_element['line'] = xml_get_current_line_number($this->parser); |
|
511 | + if (isset($attribs['case'])) { |
|
512 | + $this->_element['case'] = $attribs['case'] == 'yes'; |
|
513 | + } else { |
|
514 | + $this->_element['case'] = $this->_case; |
|
515 | + } |
|
516 | + $this->_element['innerGroup'] = $attribs['innerGroup']; |
|
517 | + $this->_element['delimGroup'] = isset($attribs['delimGroup']) ? |
|
518 | + $attribs['delimGroup'] : |
|
519 | + $attribs['innerGroup']; |
|
520 | + $this->_element['start'] = $this->_makeRE(@$attribs['start'], $this->_element['case']); |
|
521 | + $this->_element['end'] = $this->_makeRE(@$attribs['end'], $this->_element['case']); |
|
522 | + $this->_element['contained'] = @$attribs['contained'] == 'yes'; |
|
523 | + $this->_element['never-contained'] = @$attribs['never-contained'] == 'yes'; |
|
524 | + $this->_element['remember'] = @$attribs['remember'] == 'yes'; |
|
525 | + if (isset($attribs['startBOL']) && $attribs['startBOL'] == 'yes') { |
|
526 | + $this->_element['startBOL'] = true; |
|
527 | + } |
|
528 | + if (isset($attribs['endBOL']) && $attribs['endBOL'] == 'yes') { |
|
529 | + $this->_element['endBOL'] = true; |
|
530 | + } |
|
531 | + if (isset($attribs['neverAfter'])) { |
|
532 | + $this->_element['neverafter'] = $this->_makeRE($attribs['neverAfter']); |
|
533 | + } |
|
534 | + } |
|
535 | + |
|
536 | + // }}} |
|
537 | + // {{{ xmltag_Block |
|
538 | + |
|
539 | + /** |
|
540 | + * start handler for <block> element |
|
541 | + */ |
|
542 | + function xmltag_Block($xp, $elem, $attribs) |
|
543 | + { |
|
544 | + $this->_aliasAttributes($attribs); |
|
545 | + if (!isset($attribs['name']) || $attribs['name'] === '') { |
|
546 | + $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'block name'); |
|
547 | + } |
|
548 | + if (isset($attribs['innerGroup']) && $attribs['innerGroup'] === '') { |
|
549 | + $this->_error(TEXT_HIGHLIGHTER_EMPTY, 'innerGroup'); |
|
550 | + } |
|
551 | + $this->_element = array('name' => $attribs['name']); |
|
552 | + $this->_element['line'] = xml_get_current_line_number($this->parser); |
|
553 | + if (isset($attribs['case'])) { |
|
554 | + $this->_element['case'] = $attribs['case'] == 'yes'; |
|
555 | + } else { |
|
556 | + $this->_element['case'] = $this->_case; |
|
557 | + } |
|
558 | + if (isset($attribs['innerGroup'])) { |
|
559 | + $this->_element['innerGroup'] = @$attribs['innerGroup']; |
|
560 | + } |
|
561 | + $this->_element['match'] = $this->_makeRE($attribs['match'], $this->_element['case']); |
|
562 | + $this->_element['contained'] = @$attribs['contained'] == 'yes'; |
|
563 | + $this->_element['multiline'] = @$attribs['multiline'] == 'yes'; |
|
564 | + if (isset($attribs['BOL']) && $attribs['BOL'] == 'yes') { |
|
565 | + $this->_element['BOL'] = true; |
|
566 | + } |
|
567 | + if (isset($attribs['neverAfter'])) { |
|
568 | + $this->_element['neverafter'] = $this->_makeRE($attribs['neverAfter']); |
|
569 | + } |
|
570 | + } |
|
571 | + |
|
572 | + // }}} |
|
573 | + // {{{ cdataHandler |
|
574 | + |
|
575 | + /** |
|
576 | + * Character data handler. Used for comment |
|
577 | + */ |
|
578 | + function cdataHandler($xp, $cdata) |
|
579 | + { |
|
580 | + if ($this->_inComment) { |
|
581 | + $this->_comment .= $cdata; |
|
582 | + } |
|
583 | + } |
|
584 | + |
|
585 | + // }}} |
|
586 | + // {{{ xmltag_Comment |
|
587 | + |
|
588 | + /** |
|
589 | + * start handler for <comment> element |
|
590 | + */ |
|
591 | + function xmltag_Comment($xp, $elem, $attribs) |
|
592 | + { |
|
593 | + $this->_comment = ''; |
|
594 | + $this->_inComment = true; |
|
595 | + } |
|
596 | + |
|
597 | + // }}} |
|
598 | + // {{{ xmltag_PartGroup |
|
599 | + |
|
600 | + /** |
|
601 | + * start handler for <partgroup> element |
|
602 | + */ |
|
603 | + function xmltag_PartGroup($xp, $elem, $attribs) |
|
604 | + { |
|
605 | + $this->_aliasAttributes($attribs); |
|
606 | + if (!isset($attribs['innerGroup']) || $attribs['innerGroup'] === '') { |
|
607 | + $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'innerGroup'); |
|
608 | + } |
|
609 | + $this->_element['partClass'][$attribs['index']] = @$attribs['innerGroup']; |
|
610 | + } |
|
611 | + |
|
612 | + // }}} |
|
613 | + // {{{ xmltag_PartClass |
|
614 | + |
|
615 | + /** |
|
616 | + * start handler for <partclass> element |
|
617 | + */ |
|
618 | + function xmltag_PartClass($xp, $elem, $attribs) |
|
619 | + { |
|
620 | + $this->xmltag_PartGroup($xp, $elem, $attribs); |
|
621 | + } |
|
622 | + |
|
623 | + // }}} |
|
624 | + // {{{ xmltag_Keywords |
|
625 | + |
|
626 | + /** |
|
627 | + * start handler for <keywords> element |
|
628 | + */ |
|
629 | + function xmltag_Keywords($xp, $elem, $attribs) |
|
630 | + { |
|
631 | + $this->_aliasAttributes($attribs); |
|
632 | + if (!isset($attribs['name']) || $attribs['name'] === '') { |
|
633 | + $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'keyword group name'); |
|
634 | + } |
|
635 | + if (!isset($attribs['innerGroup']) || $attribs['innerGroup'] === '') { |
|
636 | + $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'innerGroup'); |
|
637 | + } |
|
638 | + if (!isset($attribs['inherits']) || $attribs['inherits'] === '') { |
|
639 | + $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'inherits'); |
|
640 | + } |
|
641 | + $this->_element = array('name'=>@$attribs['name']); |
|
642 | + $this->_element['line'] = xml_get_current_line_number($this->parser); |
|
643 | + $this->_element['innerGroup'] = @$attribs['innerGroup']; |
|
644 | + if (isset($attribs['case'])) { |
|
645 | + $this->_element['case'] = $attribs['case'] == 'yes'; |
|
646 | + } else { |
|
647 | + $this->_element['case'] = $this->_case; |
|
648 | + } |
|
649 | + $this->_element['inherits'] = @$attribs['inherits']; |
|
650 | + if (isset($attribs['otherwise'])) { |
|
651 | + $this->_element['otherwise'] = $attribs['otherwise']; |
|
652 | + } |
|
653 | + if (isset($attribs['ifdef'])) { |
|
654 | + $this->_element['ifdef'] = $attribs['ifdef']; |
|
655 | + } |
|
656 | + if (isset($attribs['ifndef'])) { |
|
657 | + $this->_element['ifndef'] = $attribs['ifndef']; |
|
658 | + } |
|
659 | + } |
|
660 | + |
|
661 | + // }}} |
|
662 | + // {{{ xmltag_Keyword |
|
663 | + |
|
664 | + /** |
|
665 | + * start handler for <keyword> element |
|
666 | + */ |
|
667 | + function xmltag_Keyword($xp, $elem, $attribs) |
|
668 | + { |
|
669 | + if (!isset($attribs['match']) || $attribs['match'] === '') { |
|
670 | + $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'match'); |
|
671 | + } |
|
672 | + $keyword = @$attribs['match']; |
|
673 | + if (!$this->_element['case']) { |
|
674 | + $keyword = strtolower($keyword); |
|
675 | + } |
|
676 | + $this->_element['match'][$keyword] = true; |
|
677 | + } |
|
678 | + |
|
679 | + // }}} |
|
680 | + // {{{ xmltag_Contains |
|
681 | + |
|
682 | + /** |
|
683 | + * start handler for <contains> element |
|
684 | + */ |
|
685 | + function xmltag_Contains($xp, $elem, $attribs) |
|
686 | + { |
|
687 | + $this->_element['contains-all'] = @$attribs['all'] == 'yes'; |
|
688 | + if (isset($attribs['region'])) { |
|
689 | + $this->_element['contains']['region'][$attribs['region']] = |
|
690 | + xml_get_current_line_number($this->parser); |
|
691 | + } |
|
692 | + if (isset($attribs['block'])) { |
|
693 | + $this->_element['contains']['block'][$attribs['block']] = |
|
694 | + xml_get_current_line_number($this->parser); |
|
695 | + } |
|
696 | + } |
|
697 | + |
|
698 | + // }}} |
|
699 | + // {{{ xmltag_But |
|
700 | + |
|
701 | + /** |
|
702 | + * start handler for <but> element |
|
703 | + */ |
|
704 | + function xmltag_But($xp, $elem, $attribs) |
|
705 | + { |
|
706 | + if (isset($attribs['region'])) { |
|
707 | + $this->_element['not-contains']['region'][$attribs['region']] = true; |
|
708 | + } |
|
709 | + if (isset($attribs['block'])) { |
|
710 | + $this->_element['not-contains']['block'][$attribs['block']] = true; |
|
711 | + } |
|
712 | + } |
|
713 | + |
|
714 | + // }}} |
|
715 | + // {{{ xmltag_Onlyin |
|
716 | + |
|
717 | + /** |
|
718 | + * start handler for <onlyin> element |
|
719 | + */ |
|
720 | + function xmltag_Onlyin($xp, $elem, $attribs) |
|
721 | + { |
|
722 | + if (!isset($attribs['region']) || $attribs['region'] === '') { |
|
723 | + $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'region'); |
|
724 | + } |
|
725 | + $this->_element['onlyin'][$attribs['region']] = xml_get_current_line_number($this->parser); |
|
726 | + } |
|
727 | + |
|
728 | + // }}} |
|
729 | + // {{{ xmltag_Author |
|
730 | + |
|
731 | + /** |
|
732 | + * start handler for <author> element |
|
733 | + */ |
|
734 | + function xmltag_Author($xp, $elem, $attribs) |
|
735 | + { |
|
736 | + if (!isset($attribs['name']) || $attribs['name'] === '') { |
|
737 | + $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'author name'); |
|
738 | + } |
|
739 | + $this->_authors[] = array( |
|
740 | + 'name' => @$attribs['name'], |
|
741 | + 'email' => (string)@$attribs['email'] |
|
742 | + ); |
|
743 | + } |
|
744 | + |
|
745 | + // }}} |
|
746 | + // {{{ xmltag_Highlight |
|
747 | + |
|
748 | + /** |
|
749 | + * start handler for <highlight> element |
|
750 | + */ |
|
751 | + function xmltag_Highlight($xp, $elem, $attribs) |
|
752 | + { |
|
753 | + if (!isset($attribs['lang']) || $attribs['lang'] === '') { |
|
754 | + $this->_error(TEXT_HIGHLIGHTER_EMPTY_OR_MISSING, 'language name'); |
|
755 | + } |
|
756 | + $this->_code = ''; |
|
757 | + $this->language = strtoupper(@$attribs['lang']); |
|
758 | + $this->_case = @$attribs['case'] == 'yes'; |
|
759 | + } |
|
760 | + |
|
761 | + // }}} |
|
762 | + |
|
763 | + /**#@-*/ |
|
764 | + |
|
765 | + // {{{ _error |
|
766 | + |
|
767 | + /** |
|
768 | + * Add an error message |
|
769 | + * |
|
770 | + * @param integer $code Error code |
|
771 | + * @param mixed $message Error message or array with error message parameters |
|
772 | + * @param integer $lineNo Source code line number |
|
773 | + * @access private |
|
774 | + */ |
|
775 | + function _error($code, $params = array(), $lineNo = 0) |
|
776 | + { |
|
777 | + if (!$lineNo && !empty($this->parser)) { |
|
778 | + $lineNo = xml_get_current_line_number($this->parser); |
|
779 | + } |
|
780 | + $this->_errors[] = $this->_formatError($code, $params, $this->_syntaxFile, $lineNo); |
|
781 | + } |
|
782 | + |
|
783 | + // }}} |
|
784 | + // {{{ _aliasAttributes |
|
785 | + |
|
786 | + /** |
|
787 | + * BC trick |
|
788 | + * |
|
789 | + * @param array $attrs attributes |
|
790 | + */ |
|
791 | + function _aliasAttributes(&$attrs) |
|
792 | + { |
|
793 | + if (isset($attrs['innerClass']) && !isset($attrs['innerGroup'])) { |
|
794 | + $attrs['innerGroup'] = $attrs['innerClass']; |
|
795 | + } |
|
796 | + if (isset($attrs['delimClass']) && !isset($attrs['delimGroup'])) { |
|
797 | + $attrs['delimGroup'] = $attrs['delimClass']; |
|
798 | + } |
|
799 | + if (isset($attrs['partClass']) && !isset($attrs['partGroup'])) { |
|
800 | + $attrs['partGroup'] = $attrs['partClass']; |
|
801 | + } |
|
802 | + } |
|
803 | + |
|
804 | + // }}} |
|
805 | + |
|
806 | + /**#@+ |
|
807 | 807 | * @access private |
808 | 808 | * @param resource $xp XML parser resource |
809 | 809 | * @param string $elem XML element name |
810 | 810 | */ |
811 | 811 | |
812 | - // {{{ xmltag_Comment_ |
|
813 | - |
|
814 | - /** |
|
815 | - * end handler for <comment> element |
|
816 | - */ |
|
817 | - function xmltag_Comment_($xp, $elem) |
|
818 | - { |
|
819 | - $this->_inComment = false; |
|
820 | - } |
|
821 | - |
|
822 | - // }}} |
|
823 | - // {{{ xmltag_Region_ |
|
824 | - |
|
825 | - /** |
|
826 | - * end handler for <region> element |
|
827 | - */ |
|
828 | - function xmltag_Region_($xp, $elem) |
|
829 | - { |
|
830 | - $this->_element['type'] = 'region'; |
|
831 | - $this->_element['order'] = $this->_blockOrder ++; |
|
832 | - $this->_regions[$this->_element['name']] = $this->_element; |
|
833 | - } |
|
834 | - |
|
835 | - // }}} |
|
836 | - // {{{ xmltag_Keywords_ |
|
837 | - |
|
838 | - /** |
|
839 | - * end handler for <keywords> element |
|
840 | - */ |
|
841 | - function xmltag_Keywords_($xp, $elem) |
|
842 | - { |
|
843 | - $this->_keywords[$this->_element['name']] = $this->_element; |
|
844 | - } |
|
845 | - |
|
846 | - // }}} |
|
847 | - // {{{ xmltag_Block_ |
|
848 | - |
|
849 | - /** |
|
850 | - * end handler for <block> element |
|
851 | - */ |
|
852 | - function xmltag_Block_($xp, $elem) |
|
853 | - { |
|
854 | - $this->_element['type'] = 'block'; |
|
855 | - $this->_element['order'] = $this->_blockOrder ++; |
|
856 | - $this->_blocks[$this->_element['name']] = $this->_element; |
|
857 | - } |
|
858 | - |
|
859 | - // }}} |
|
860 | - // {{{ xmltag_Highlight_ |
|
861 | - |
|
862 | - /** |
|
863 | - * end handler for <highlight> element |
|
864 | - */ |
|
865 | - function xmltag_Highlight_($xp, $elem) |
|
866 | - { |
|
867 | - $conditions = array(); |
|
868 | - $toplevel = array(); |
|
869 | - foreach ($this->_blocks as $i => $current) { |
|
870 | - if (!$current['contained'] && !isset($current['onlyin'])) { |
|
871 | - $toplevel[] = $i; |
|
872 | - } |
|
873 | - foreach ((array)@$current['onlyin'] as $region => $lineNo) { |
|
874 | - if (!isset($this->_regions[$region])) { |
|
875 | - $this->_error(TEXT_HIGHLIGHTER_BLOCK_REGION, |
|
876 | - array( |
|
877 | - 'block' => $current['name'], |
|
878 | - 'region' => $region |
|
879 | - )); |
|
880 | - } |
|
881 | - } |
|
882 | - } |
|
883 | - foreach ($this->_regions as $i=>$current) { |
|
884 | - if (!$current['contained'] && !isset($current['onlyin'])) { |
|
885 | - $toplevel[] = $i; |
|
886 | - } |
|
887 | - foreach ((array)@$current['contains']['region'] as $region => $lineNo) { |
|
888 | - if (!isset($this->_regions[$region])) { |
|
889 | - $this->_error(TEXT_HIGHLIGHTER_REGION_REGION, |
|
890 | - array( |
|
891 | - 'region1' => $current['name'], |
|
892 | - 'region2' => $region |
|
893 | - )); |
|
894 | - } |
|
895 | - } |
|
896 | - foreach ((array)@$current['contains']['block'] as $region => $lineNo) { |
|
897 | - if (!isset($this->_blocks[$region])) { |
|
898 | - $this->_error(TEXT_HIGHLIGHTER_REGION_BLOCK, |
|
899 | - array( |
|
900 | - 'block' => $current['name'], |
|
901 | - 'region' => $region |
|
902 | - )); |
|
903 | - } |
|
904 | - } |
|
905 | - foreach ((array)@$current['onlyin'] as $region => $lineNo) { |
|
906 | - if (!isset($this->_regions[$region])) { |
|
907 | - $this->_error(TEXT_HIGHLIGHTER_REGION_REGION, |
|
908 | - array( |
|
909 | - 'region1' => $current['name'], |
|
910 | - 'region2' => $region |
|
911 | - )); |
|
912 | - } |
|
913 | - } |
|
914 | - foreach ($this->_regions as $j => $region) { |
|
915 | - if (isset($region['onlyin'])) { |
|
916 | - $suits = isset($region['onlyin'][$current['name']]); |
|
917 | - } elseif (isset($current['not-contains']['region'][$region['name']])) { |
|
918 | - $suits = false; |
|
919 | - } elseif (isset($current['contains']['region'][$region['name']])) { |
|
920 | - $suits = true; |
|
921 | - } else { |
|
922 | - $suits = @$current['contains-all'] && @!$region['never-contained']; |
|
923 | - } |
|
924 | - if ($suits) { |
|
925 | - $this->_regions[$i]['lookfor'][] = $j; |
|
926 | - } |
|
927 | - } |
|
928 | - foreach ($this->_blocks as $j=>$region) { |
|
929 | - if (isset($region['onlyin'])) { |
|
930 | - $suits = isset($region['onlyin'][$current['name']]); |
|
931 | - } elseif (isset($current['not-contains']['block'][$region['name']])) { |
|
932 | - $suits = false; |
|
933 | - } elseif (isset($current['contains']['block'][$region['name']])) { |
|
934 | - $suits = true; |
|
935 | - } else { |
|
936 | - $suits = @$current['contains-all'] && @!$region['never-contained']; |
|
937 | - } |
|
938 | - if ($suits) { |
|
939 | - $this->_regions[$i]['lookfor'][] = $j; |
|
940 | - } |
|
941 | - } |
|
942 | - } |
|
943 | - foreach ($this->_blocks as $i=>$current) { |
|
944 | - unset ($this->_blocks[$i]['never-contained']); |
|
945 | - unset ($this->_blocks[$i]['contained']); |
|
946 | - unset ($this->_blocks[$i]['contains-all']); |
|
947 | - unset ($this->_blocks[$i]['contains']); |
|
948 | - unset ($this->_blocks[$i]['onlyin']); |
|
949 | - unset ($this->_blocks[$i]['line']); |
|
950 | - } |
|
951 | - |
|
952 | - foreach ($this->_regions as $i=>$current) { |
|
953 | - unset ($this->_regions[$i]['never-contained']); |
|
954 | - unset ($this->_regions[$i]['contained']); |
|
955 | - unset ($this->_regions[$i]['contains-all']); |
|
956 | - unset ($this->_regions[$i]['contains']); |
|
957 | - unset ($this->_regions[$i]['onlyin']); |
|
958 | - unset ($this->_regions[$i]['line']); |
|
959 | - } |
|
960 | - |
|
961 | - foreach ($this->_keywords as $name => $keyword) { |
|
962 | - if (isset($keyword['ifdef'])) { |
|
963 | - $conditions[$keyword['ifdef']][] = array($name, true); |
|
964 | - } |
|
965 | - if (isset($keyword['ifndef'])) { |
|
966 | - $conditions[$keyword['ifndef']][] = array($name, false); |
|
967 | - } |
|
968 | - unset($this->_keywords[$name]['line']); |
|
969 | - if (!isset($this->_blocks[$keyword['inherits']])) { |
|
970 | - $this->_error(TEXT_HIGHLIGHTER_KEYWORD_INHERITS, |
|
971 | - array( |
|
972 | - 'keyword' => $keyword['name'], |
|
973 | - 'block' => $keyword['inherits'] |
|
974 | - )); |
|
975 | - } |
|
976 | - if (isset($keyword['otherwise']) && !isset($this->_blocks[$keyword['otherwise']]) ) { |
|
977 | - $this->_error(TEXT_HIGHLIGHTER_KEYWORD_BLOCK, |
|
978 | - array( |
|
979 | - 'keyword' => $keyword['name'], |
|
980 | - 'block' => $keyword['inherits'] |
|
981 | - )); |
|
982 | - } |
|
983 | - } |
|
984 | - |
|
985 | - $syntax=array( |
|
986 | - 'keywords' => $this->_keywords, |
|
987 | - 'blocks' => array_merge($this->_blocks, $this->_regions), |
|
988 | - 'toplevel' => $toplevel, |
|
989 | - ); |
|
990 | - uasort($syntax['blocks'], array(&$this, '_sortBlocks')); |
|
991 | - foreach ($syntax['blocks'] as $name => $block) { |
|
992 | - if ($block['type'] == 'block') { |
|
993 | - continue; |
|
994 | - } |
|
995 | - if (is_array(@$syntax['blocks'][$name]['lookfor'])) { |
|
996 | - usort($syntax['blocks'][$name]['lookfor'], array(&$this, '_sortLookFor')); |
|
997 | - } |
|
998 | - } |
|
999 | - usort($syntax['toplevel'], array(&$this, '_sortLookFor')); |
|
1000 | - $syntax['case'] = $this->_case; |
|
1001 | - $this->_code = <<<CODE |
|
812 | + // {{{ xmltag_Comment_ |
|
813 | + |
|
814 | + /** |
|
815 | + * end handler for <comment> element |
|
816 | + */ |
|
817 | + function xmltag_Comment_($xp, $elem) |
|
818 | + { |
|
819 | + $this->_inComment = false; |
|
820 | + } |
|
821 | + |
|
822 | + // }}} |
|
823 | + // {{{ xmltag_Region_ |
|
824 | + |
|
825 | + /** |
|
826 | + * end handler for <region> element |
|
827 | + */ |
|
828 | + function xmltag_Region_($xp, $elem) |
|
829 | + { |
|
830 | + $this->_element['type'] = 'region'; |
|
831 | + $this->_element['order'] = $this->_blockOrder ++; |
|
832 | + $this->_regions[$this->_element['name']] = $this->_element; |
|
833 | + } |
|
834 | + |
|
835 | + // }}} |
|
836 | + // {{{ xmltag_Keywords_ |
|
837 | + |
|
838 | + /** |
|
839 | + * end handler for <keywords> element |
|
840 | + */ |
|
841 | + function xmltag_Keywords_($xp, $elem) |
|
842 | + { |
|
843 | + $this->_keywords[$this->_element['name']] = $this->_element; |
|
844 | + } |
|
845 | + |
|
846 | + // }}} |
|
847 | + // {{{ xmltag_Block_ |
|
848 | + |
|
849 | + /** |
|
850 | + * end handler for <block> element |
|
851 | + */ |
|
852 | + function xmltag_Block_($xp, $elem) |
|
853 | + { |
|
854 | + $this->_element['type'] = 'block'; |
|
855 | + $this->_element['order'] = $this->_blockOrder ++; |
|
856 | + $this->_blocks[$this->_element['name']] = $this->_element; |
|
857 | + } |
|
858 | + |
|
859 | + // }}} |
|
860 | + // {{{ xmltag_Highlight_ |
|
861 | + |
|
862 | + /** |
|
863 | + * end handler for <highlight> element |
|
864 | + */ |
|
865 | + function xmltag_Highlight_($xp, $elem) |
|
866 | + { |
|
867 | + $conditions = array(); |
|
868 | + $toplevel = array(); |
|
869 | + foreach ($this->_blocks as $i => $current) { |
|
870 | + if (!$current['contained'] && !isset($current['onlyin'])) { |
|
871 | + $toplevel[] = $i; |
|
872 | + } |
|
873 | + foreach ((array)@$current['onlyin'] as $region => $lineNo) { |
|
874 | + if (!isset($this->_regions[$region])) { |
|
875 | + $this->_error(TEXT_HIGHLIGHTER_BLOCK_REGION, |
|
876 | + array( |
|
877 | + 'block' => $current['name'], |
|
878 | + 'region' => $region |
|
879 | + )); |
|
880 | + } |
|
881 | + } |
|
882 | + } |
|
883 | + foreach ($this->_regions as $i=>$current) { |
|
884 | + if (!$current['contained'] && !isset($current['onlyin'])) { |
|
885 | + $toplevel[] = $i; |
|
886 | + } |
|
887 | + foreach ((array)@$current['contains']['region'] as $region => $lineNo) { |
|
888 | + if (!isset($this->_regions[$region])) { |
|
889 | + $this->_error(TEXT_HIGHLIGHTER_REGION_REGION, |
|
890 | + array( |
|
891 | + 'region1' => $current['name'], |
|
892 | + 'region2' => $region |
|
893 | + )); |
|
894 | + } |
|
895 | + } |
|
896 | + foreach ((array)@$current['contains']['block'] as $region => $lineNo) { |
|
897 | + if (!isset($this->_blocks[$region])) { |
|
898 | + $this->_error(TEXT_HIGHLIGHTER_REGION_BLOCK, |
|
899 | + array( |
|
900 | + 'block' => $current['name'], |
|
901 | + 'region' => $region |
|
902 | + )); |
|
903 | + } |
|
904 | + } |
|
905 | + foreach ((array)@$current['onlyin'] as $region => $lineNo) { |
|
906 | + if (!isset($this->_regions[$region])) { |
|
907 | + $this->_error(TEXT_HIGHLIGHTER_REGION_REGION, |
|
908 | + array( |
|
909 | + 'region1' => $current['name'], |
|
910 | + 'region2' => $region |
|
911 | + )); |
|
912 | + } |
|
913 | + } |
|
914 | + foreach ($this->_regions as $j => $region) { |
|
915 | + if (isset($region['onlyin'])) { |
|
916 | + $suits = isset($region['onlyin'][$current['name']]); |
|
917 | + } elseif (isset($current['not-contains']['region'][$region['name']])) { |
|
918 | + $suits = false; |
|
919 | + } elseif (isset($current['contains']['region'][$region['name']])) { |
|
920 | + $suits = true; |
|
921 | + } else { |
|
922 | + $suits = @$current['contains-all'] && @!$region['never-contained']; |
|
923 | + } |
|
924 | + if ($suits) { |
|
925 | + $this->_regions[$i]['lookfor'][] = $j; |
|
926 | + } |
|
927 | + } |
|
928 | + foreach ($this->_blocks as $j=>$region) { |
|
929 | + if (isset($region['onlyin'])) { |
|
930 | + $suits = isset($region['onlyin'][$current['name']]); |
|
931 | + } elseif (isset($current['not-contains']['block'][$region['name']])) { |
|
932 | + $suits = false; |
|
933 | + } elseif (isset($current['contains']['block'][$region['name']])) { |
|
934 | + $suits = true; |
|
935 | + } else { |
|
936 | + $suits = @$current['contains-all'] && @!$region['never-contained']; |
|
937 | + } |
|
938 | + if ($suits) { |
|
939 | + $this->_regions[$i]['lookfor'][] = $j; |
|
940 | + } |
|
941 | + } |
|
942 | + } |
|
943 | + foreach ($this->_blocks as $i=>$current) { |
|
944 | + unset ($this->_blocks[$i]['never-contained']); |
|
945 | + unset ($this->_blocks[$i]['contained']); |
|
946 | + unset ($this->_blocks[$i]['contains-all']); |
|
947 | + unset ($this->_blocks[$i]['contains']); |
|
948 | + unset ($this->_blocks[$i]['onlyin']); |
|
949 | + unset ($this->_blocks[$i]['line']); |
|
950 | + } |
|
951 | + |
|
952 | + foreach ($this->_regions as $i=>$current) { |
|
953 | + unset ($this->_regions[$i]['never-contained']); |
|
954 | + unset ($this->_regions[$i]['contained']); |
|
955 | + unset ($this->_regions[$i]['contains-all']); |
|
956 | + unset ($this->_regions[$i]['contains']); |
|
957 | + unset ($this->_regions[$i]['onlyin']); |
|
958 | + unset ($this->_regions[$i]['line']); |
|
959 | + } |
|
960 | + |
|
961 | + foreach ($this->_keywords as $name => $keyword) { |
|
962 | + if (isset($keyword['ifdef'])) { |
|
963 | + $conditions[$keyword['ifdef']][] = array($name, true); |
|
964 | + } |
|
965 | + if (isset($keyword['ifndef'])) { |
|
966 | + $conditions[$keyword['ifndef']][] = array($name, false); |
|
967 | + } |
|
968 | + unset($this->_keywords[$name]['line']); |
|
969 | + if (!isset($this->_blocks[$keyword['inherits']])) { |
|
970 | + $this->_error(TEXT_HIGHLIGHTER_KEYWORD_INHERITS, |
|
971 | + array( |
|
972 | + 'keyword' => $keyword['name'], |
|
973 | + 'block' => $keyword['inherits'] |
|
974 | + )); |
|
975 | + } |
|
976 | + if (isset($keyword['otherwise']) && !isset($this->_blocks[$keyword['otherwise']]) ) { |
|
977 | + $this->_error(TEXT_HIGHLIGHTER_KEYWORD_BLOCK, |
|
978 | + array( |
|
979 | + 'keyword' => $keyword['name'], |
|
980 | + 'block' => $keyword['inherits'] |
|
981 | + )); |
|
982 | + } |
|
983 | + } |
|
984 | + |
|
985 | + $syntax=array( |
|
986 | + 'keywords' => $this->_keywords, |
|
987 | + 'blocks' => array_merge($this->_blocks, $this->_regions), |
|
988 | + 'toplevel' => $toplevel, |
|
989 | + ); |
|
990 | + uasort($syntax['blocks'], array(&$this, '_sortBlocks')); |
|
991 | + foreach ($syntax['blocks'] as $name => $block) { |
|
992 | + if ($block['type'] == 'block') { |
|
993 | + continue; |
|
994 | + } |
|
995 | + if (is_array(@$syntax['blocks'][$name]['lookfor'])) { |
|
996 | + usort($syntax['blocks'][$name]['lookfor'], array(&$this, '_sortLookFor')); |
|
997 | + } |
|
998 | + } |
|
999 | + usort($syntax['toplevel'], array(&$this, '_sortLookFor')); |
|
1000 | + $syntax['case'] = $this->_case; |
|
1001 | + $this->_code = <<<CODE |
|
1002 | 1002 | <?php |
1003 | 1003 | /** |
1004 | 1004 | * Auto-generated class. {$this->language} syntax highlighting |
1005 | 1005 | CODE; |
1006 | 1006 | |
1007 | - if ($this->_comment) { |
|
1008 | - $comment = preg_replace('~^~m',' * ',$this->_comment); |
|
1009 | - $this->_code .= "\n * \n" . $comment; |
|
1010 | - } |
|
1007 | + if ($this->_comment) { |
|
1008 | + $comment = preg_replace('~^~m',' * ',$this->_comment); |
|
1009 | + $this->_code .= "\n * \n" . $comment; |
|
1010 | + } |
|
1011 | 1011 | |
1012 | - $this->_code .= <<<CODE |
|
1012 | + $this->_code .= <<<CODE |
|
1013 | 1013 | |
1014 | 1014 | * |
1015 | 1015 | * PHP version 4 and 5 |
@@ -1029,15 +1029,15 @@ discard block |
||
1029 | 1029 | |
1030 | 1030 | CODE; |
1031 | 1031 | |
1032 | - foreach ($this->_authors as $author) { |
|
1033 | - $this->_code .= ' * @author ' . $author['name']; |
|
1034 | - if ($author['email']) { |
|
1035 | - $this->_code .= ' <' . $author['email'] . '>'; |
|
1036 | - } |
|
1037 | - $this->_code .= "\n"; |
|
1038 | - } |
|
1032 | + foreach ($this->_authors as $author) { |
|
1033 | + $this->_code .= ' * @author ' . $author['name']; |
|
1034 | + if ($author['email']) { |
|
1035 | + $this->_code .= ' <' . $author['email'] . '>'; |
|
1036 | + } |
|
1037 | + $this->_code .= "\n"; |
|
1038 | + } |
|
1039 | 1039 | |
1040 | - $this->_code .= <<<CODE |
|
1040 | + $this->_code .= <<<CODE |
|
1041 | 1041 | * |
1042 | 1042 | */ |
1043 | 1043 | |
@@ -1046,16 +1046,16 @@ discard block |
||
1046 | 1046 | * |
1047 | 1047 | |
1048 | 1048 | CODE; |
1049 | - foreach ($this->_authors as $author) { |
|
1050 | - $this->_code .= ' * @author ' . $author['name']; |
|
1051 | - if ($author['email']) { |
|
1052 | - $this->_code .= ' <' . $author['email']. '>'; |
|
1053 | - } |
|
1054 | - $this->_code .= "\n"; |
|
1055 | - } |
|
1049 | + foreach ($this->_authors as $author) { |
|
1050 | + $this->_code .= ' * @author ' . $author['name']; |
|
1051 | + if ($author['email']) { |
|
1052 | + $this->_code .= ' <' . $author['email']. '>'; |
|
1053 | + } |
|
1054 | + $this->_code .= "\n"; |
|
1055 | + } |
|
1056 | 1056 | |
1057 | 1057 | |
1058 | - $this->_code .= <<<CODE |
|
1058 | + $this->_code .= <<<CODE |
|
1059 | 1059 | * @category Text |
1060 | 1060 | * @package Text_Highlighter |
1061 | 1061 | * @copyright 2004-2006 Andrey Demenev |
@@ -1067,11 +1067,11 @@ discard block |
||
1067 | 1067 | { |
1068 | 1068 | |
1069 | 1069 | CODE; |
1070 | - $this->_code .= 'var $_language = \'' . strtolower($this->language) . "';\n\n"; |
|
1071 | - $array = var_export($syntax, true); |
|
1072 | - $array = trim(preg_replace('~^(\s*)~m',' \1\1',$array)); |
|
1073 | - // \$this->_syntax = $array; |
|
1074 | - $this->_code .= <<<CODE |
|
1070 | + $this->_code .= 'var $_language = \'' . strtolower($this->language) . "';\n\n"; |
|
1071 | + $array = var_export($syntax, true); |
|
1072 | + $array = trim(preg_replace('~^(\s*)~m',' \1\1',$array)); |
|
1073 | + // \$this->_syntax = $array; |
|
1074 | + $this->_code .= <<<CODE |
|
1075 | 1075 | |
1076 | 1076 | /** |
1077 | 1077 | * Constructor |
@@ -1083,154 +1083,154 @@ discard block |
||
1083 | 1083 | { |
1084 | 1084 | |
1085 | 1085 | CODE; |
1086 | - $this->_code .= <<<CODE |
|
1086 | + $this->_code .= <<<CODE |
|
1087 | 1087 | |
1088 | 1088 | \$this->_options = \$options; |
1089 | 1089 | CODE; |
1090 | - $states = array(); |
|
1091 | - $i = 0; |
|
1092 | - foreach ($syntax['blocks'] as $name => $block) { |
|
1093 | - if ($block['type'] == 'region') { |
|
1094 | - $states[$name] = $i++; |
|
1095 | - } |
|
1096 | - } |
|
1097 | - $regs = array(); |
|
1098 | - $counts = array(); |
|
1099 | - $delim = array(); |
|
1100 | - $inner = array(); |
|
1101 | - $end = array(); |
|
1102 | - $stat = array(); |
|
1103 | - $keywords = array(); |
|
1104 | - $parts = array(); |
|
1105 | - $kwmap = array(); |
|
1106 | - $subst = array(); |
|
1107 | - $re = array(); |
|
1108 | - $ce = array(); |
|
1109 | - $rd = array(); |
|
1110 | - $in = array(); |
|
1111 | - $st = array(); |
|
1112 | - $kw = array(); |
|
1113 | - $sb = array(); |
|
1114 | - foreach ($syntax['toplevel'] as $name) { |
|
1115 | - $block = $syntax['blocks'][$name]; |
|
1116 | - if ($block['type'] == 'block') { |
|
1117 | - $kwm = array(); |
|
1118 | - $re[] = '(' . $block['match'] . ')'; |
|
1119 | - $ce[] = $this->_countSubpatterns($block['match']); |
|
1120 | - $rd[] = ''; |
|
1121 | - $sb[] = false;; |
|
1122 | - $st[] = -1; |
|
1123 | - foreach ($syntax['keywords'] as $kwname => $kwgroup) { |
|
1124 | - if ($kwgroup['inherits'] != $name) { |
|
1125 | - continue; |
|
1126 | - } |
|
1127 | - $gre = implode('|', array_keys($kwgroup['match'])); |
|
1128 | - if (!$kwgroup['case']) { |
|
1129 | - $gre = '(?i)' . $gre; |
|
1130 | - } |
|
1131 | - $kwm[$kwname][] = $gre; |
|
1132 | - $kwmap[$kwname] = $kwgroup['innerGroup']; |
|
1133 | - } |
|
1134 | - foreach ($kwm as $g => $ma) { |
|
1135 | - $kwm[$g] = '/^(' . implode(')|(', $ma) . ')$/'; |
|
1136 | - } |
|
1137 | - $kw[] = $kwm; |
|
1138 | - } else { |
|
1139 | - $kw[] = -1; |
|
1140 | - $re[] = '(' . $block['start'] . ')'; |
|
1141 | - $ce[] = $this->_countSubpatterns($block['start']); |
|
1142 | - $rd[] = $block['delimGroup']; |
|
1143 | - $st[] = $states[$name]; |
|
1144 | - $sb[] = $block['remember']; |
|
1145 | - } |
|
1146 | - $in[] = $block['innerGroup']; |
|
1147 | - } |
|
1148 | - $re = implode('|', $re); |
|
1149 | - $regs[-1] = '/' . $re . '/'; |
|
1150 | - $counts[-1] = $ce; |
|
1151 | - $delim[-1] = $rd; |
|
1152 | - $inner[-1] = $in; |
|
1153 | - $stat[-1] = $st; |
|
1154 | - $keywords[-1] = $kw; |
|
1155 | - $subst[-1] = $sb; |
|
1156 | - |
|
1157 | - foreach ($syntax['blocks'] as $ablock) { |
|
1158 | - if ($ablock['type'] != 'region') { |
|
1159 | - continue; |
|
1160 | - } |
|
1161 | - $end[] = '/' . $ablock['end'] . '/'; |
|
1162 | - $re = array(); |
|
1163 | - $ce = array(); |
|
1164 | - $rd = array(); |
|
1165 | - $in = array(); |
|
1166 | - $st = array(); |
|
1167 | - $kw = array(); |
|
1168 | - $pc = array(); |
|
1169 | - $sb = array(); |
|
1170 | - foreach ((array)@$ablock['lookfor'] as $name) { |
|
1171 | - $block = $syntax['blocks'][$name]; |
|
1172 | - if (isset($block['partClass'])) { |
|
1173 | - $pc[] = $block['partClass']; |
|
1174 | - } else { |
|
1175 | - $pc[] = null; |
|
1176 | - } |
|
1177 | - if ($block['type'] == 'block') { |
|
1178 | - $kwm = array();; |
|
1179 | - $re[] = '(' . $block['match'] . ')'; |
|
1180 | - $ce[] = $this->_countSubpatterns($block['match']); |
|
1181 | - $rd[] = ''; |
|
1182 | - $sb[] = false; |
|
1183 | - $st[] = -1; |
|
1184 | - foreach ($syntax['keywords'] as $kwname => $kwgroup) { |
|
1185 | - if ($kwgroup['inherits'] != $name) { |
|
1186 | - continue; |
|
1187 | - } |
|
1188 | - $gre = implode('|', array_keys($kwgroup['match'])); |
|
1189 | - if (!$kwgroup['case']) { |
|
1190 | - $gre = '(?i)' . $gre; |
|
1191 | - } |
|
1192 | - $kwm[$kwname][] = $gre; |
|
1193 | - $kwmap[$kwname] = $kwgroup['innerGroup']; |
|
1194 | - } |
|
1195 | - foreach ($kwm as $g => $ma) { |
|
1196 | - $kwm[$g] = '/^(' . implode(')|(', $ma) . ')$/'; |
|
1197 | - } |
|
1198 | - $kw[] = $kwm; |
|
1199 | - } else { |
|
1200 | - $sb[] = $block['remember']; |
|
1201 | - $kw[] = -1; |
|
1202 | - $re[] = '(' . $block['start'] . ')'; |
|
1203 | - $ce[] = $this->_countSubpatterns($block['start']); |
|
1204 | - $rd[] = $block['delimGroup']; |
|
1205 | - $st[] = $states[$name]; |
|
1206 | - } |
|
1207 | - $in[] = $block['innerGroup']; |
|
1208 | - } |
|
1209 | - $re = implode('|', $re); |
|
1210 | - $regs[] = '/' . $re . '/'; |
|
1211 | - $counts[] = $ce; |
|
1212 | - $delim[] = $rd; |
|
1213 | - $inner[] = $in; |
|
1214 | - $stat[] = $st; |
|
1215 | - $keywords[] = $kw; |
|
1216 | - $parts[] = $pc; |
|
1217 | - $subst[] = $sb; |
|
1218 | - } |
|
1219 | - |
|
1220 | - |
|
1221 | - $this->_code .= "\n \$this->_regs = " . $this->_exportArray($regs); |
|
1222 | - $this->_code .= ";\n \$this->_counts = " .$this->_exportArray($counts); |
|
1223 | - $this->_code .= ";\n \$this->_delim = " .$this->_exportArray($delim); |
|
1224 | - $this->_code .= ";\n \$this->_inner = " .$this->_exportArray($inner); |
|
1225 | - $this->_code .= ";\n \$this->_end = " .$this->_exportArray($end); |
|
1226 | - $this->_code .= ";\n \$this->_states = " .$this->_exportArray($stat); |
|
1227 | - $this->_code .= ";\n \$this->_keywords = " .$this->_exportArray($keywords); |
|
1228 | - $this->_code .= ";\n \$this->_parts = " .$this->_exportArray($parts); |
|
1229 | - $this->_code .= ";\n \$this->_subst = " .$this->_exportArray($subst); |
|
1230 | - $this->_code .= ";\n \$this->_conditions = " .$this->_exportArray($conditions); |
|
1231 | - $this->_code .= ";\n \$this->_kwmap = " .$this->_exportArray($kwmap); |
|
1232 | - $this->_code .= ";\n \$this->_defClass = '" .$this->_defClass . '\''; |
|
1233 | - $this->_code .= <<<CODE |
|
1090 | + $states = array(); |
|
1091 | + $i = 0; |
|
1092 | + foreach ($syntax['blocks'] as $name => $block) { |
|
1093 | + if ($block['type'] == 'region') { |
|
1094 | + $states[$name] = $i++; |
|
1095 | + } |
|
1096 | + } |
|
1097 | + $regs = array(); |
|
1098 | + $counts = array(); |
|
1099 | + $delim = array(); |
|
1100 | + $inner = array(); |
|
1101 | + $end = array(); |
|
1102 | + $stat = array(); |
|
1103 | + $keywords = array(); |
|
1104 | + $parts = array(); |
|
1105 | + $kwmap = array(); |
|
1106 | + $subst = array(); |
|
1107 | + $re = array(); |
|
1108 | + $ce = array(); |
|
1109 | + $rd = array(); |
|
1110 | + $in = array(); |
|
1111 | + $st = array(); |
|
1112 | + $kw = array(); |
|
1113 | + $sb = array(); |
|
1114 | + foreach ($syntax['toplevel'] as $name) { |
|
1115 | + $block = $syntax['blocks'][$name]; |
|
1116 | + if ($block['type'] == 'block') { |
|
1117 | + $kwm = array(); |
|
1118 | + $re[] = '(' . $block['match'] . ')'; |
|
1119 | + $ce[] = $this->_countSubpatterns($block['match']); |
|
1120 | + $rd[] = ''; |
|
1121 | + $sb[] = false;; |
|
1122 | + $st[] = -1; |
|
1123 | + foreach ($syntax['keywords'] as $kwname => $kwgroup) { |
|
1124 | + if ($kwgroup['inherits'] != $name) { |
|
1125 | + continue; |
|
1126 | + } |
|
1127 | + $gre = implode('|', array_keys($kwgroup['match'])); |
|
1128 | + if (!$kwgroup['case']) { |
|
1129 | + $gre = '(?i)' . $gre; |
|
1130 | + } |
|
1131 | + $kwm[$kwname][] = $gre; |
|
1132 | + $kwmap[$kwname] = $kwgroup['innerGroup']; |
|
1133 | + } |
|
1134 | + foreach ($kwm as $g => $ma) { |
|
1135 | + $kwm[$g] = '/^(' . implode(')|(', $ma) . ')$/'; |
|
1136 | + } |
|
1137 | + $kw[] = $kwm; |
|
1138 | + } else { |
|
1139 | + $kw[] = -1; |
|
1140 | + $re[] = '(' . $block['start'] . ')'; |
|
1141 | + $ce[] = $this->_countSubpatterns($block['start']); |
|
1142 | + $rd[] = $block['delimGroup']; |
|
1143 | + $st[] = $states[$name]; |
|
1144 | + $sb[] = $block['remember']; |
|
1145 | + } |
|
1146 | + $in[] = $block['innerGroup']; |
|
1147 | + } |
|
1148 | + $re = implode('|', $re); |
|
1149 | + $regs[-1] = '/' . $re . '/'; |
|
1150 | + $counts[-1] = $ce; |
|
1151 | + $delim[-1] = $rd; |
|
1152 | + $inner[-1] = $in; |
|
1153 | + $stat[-1] = $st; |
|
1154 | + $keywords[-1] = $kw; |
|
1155 | + $subst[-1] = $sb; |
|
1156 | + |
|
1157 | + foreach ($syntax['blocks'] as $ablock) { |
|
1158 | + if ($ablock['type'] != 'region') { |
|
1159 | + continue; |
|
1160 | + } |
|
1161 | + $end[] = '/' . $ablock['end'] . '/'; |
|
1162 | + $re = array(); |
|
1163 | + $ce = array(); |
|
1164 | + $rd = array(); |
|
1165 | + $in = array(); |
|
1166 | + $st = array(); |
|
1167 | + $kw = array(); |
|
1168 | + $pc = array(); |
|
1169 | + $sb = array(); |
|
1170 | + foreach ((array)@$ablock['lookfor'] as $name) { |
|
1171 | + $block = $syntax['blocks'][$name]; |
|
1172 | + if (isset($block['partClass'])) { |
|
1173 | + $pc[] = $block['partClass']; |
|
1174 | + } else { |
|
1175 | + $pc[] = null; |
|
1176 | + } |
|
1177 | + if ($block['type'] == 'block') { |
|
1178 | + $kwm = array();; |
|
1179 | + $re[] = '(' . $block['match'] . ')'; |
|
1180 | + $ce[] = $this->_countSubpatterns($block['match']); |
|
1181 | + $rd[] = ''; |
|
1182 | + $sb[] = false; |
|
1183 | + $st[] = -1; |
|
1184 | + foreach ($syntax['keywords'] as $kwname => $kwgroup) { |
|
1185 | + if ($kwgroup['inherits'] != $name) { |
|
1186 | + continue; |
|
1187 | + } |
|
1188 | + $gre = implode('|', array_keys($kwgroup['match'])); |
|
1189 | + if (!$kwgroup['case']) { |
|
1190 | + $gre = '(?i)' . $gre; |
|
1191 | + } |
|
1192 | + $kwm[$kwname][] = $gre; |
|
1193 | + $kwmap[$kwname] = $kwgroup['innerGroup']; |
|
1194 | + } |
|
1195 | + foreach ($kwm as $g => $ma) { |
|
1196 | + $kwm[$g] = '/^(' . implode(')|(', $ma) . ')$/'; |
|
1197 | + } |
|
1198 | + $kw[] = $kwm; |
|
1199 | + } else { |
|
1200 | + $sb[] = $block['remember']; |
|
1201 | + $kw[] = -1; |
|
1202 | + $re[] = '(' . $block['start'] . ')'; |
|
1203 | + $ce[] = $this->_countSubpatterns($block['start']); |
|
1204 | + $rd[] = $block['delimGroup']; |
|
1205 | + $st[] = $states[$name]; |
|
1206 | + } |
|
1207 | + $in[] = $block['innerGroup']; |
|
1208 | + } |
|
1209 | + $re = implode('|', $re); |
|
1210 | + $regs[] = '/' . $re . '/'; |
|
1211 | + $counts[] = $ce; |
|
1212 | + $delim[] = $rd; |
|
1213 | + $inner[] = $in; |
|
1214 | + $stat[] = $st; |
|
1215 | + $keywords[] = $kw; |
|
1216 | + $parts[] = $pc; |
|
1217 | + $subst[] = $sb; |
|
1218 | + } |
|
1219 | + |
|
1220 | + |
|
1221 | + $this->_code .= "\n \$this->_regs = " . $this->_exportArray($regs); |
|
1222 | + $this->_code .= ";\n \$this->_counts = " .$this->_exportArray($counts); |
|
1223 | + $this->_code .= ";\n \$this->_delim = " .$this->_exportArray($delim); |
|
1224 | + $this->_code .= ";\n \$this->_inner = " .$this->_exportArray($inner); |
|
1225 | + $this->_code .= ";\n \$this->_end = " .$this->_exportArray($end); |
|
1226 | + $this->_code .= ";\n \$this->_states = " .$this->_exportArray($stat); |
|
1227 | + $this->_code .= ";\n \$this->_keywords = " .$this->_exportArray($keywords); |
|
1228 | + $this->_code .= ";\n \$this->_parts = " .$this->_exportArray($parts); |
|
1229 | + $this->_code .= ";\n \$this->_subst = " .$this->_exportArray($subst); |
|
1230 | + $this->_code .= ";\n \$this->_conditions = " .$this->_exportArray($conditions); |
|
1231 | + $this->_code .= ";\n \$this->_kwmap = " .$this->_exportArray($kwmap); |
|
1232 | + $this->_code .= ";\n \$this->_defClass = '" .$this->_defClass . '\''; |
|
1233 | + $this->_code .= <<<CODE |
|
1234 | 1234 | ; |
1235 | 1235 | \$this->_checkDefines(); |
1236 | 1236 | } |
@@ -27,18 +27,18 @@ discard block |
||
27 | 27 | |
28 | 28 | // {{{ error codes |
29 | 29 | |
30 | -define ('TEXT_HIGHLIGHTER_EMPTY_RE', 1); |
|
31 | -define ('TEXT_HIGHLIGHTER_INVALID_RE', 2); |
|
32 | -define ('TEXT_HIGHLIGHTER_EMPTY_OR_MISSING', 3); |
|
33 | -define ('TEXT_HIGHLIGHTER_EMPTY', 4); |
|
34 | -define ('TEXT_HIGHLIGHTER_REGION_REGION', 5); |
|
35 | -define ('TEXT_HIGHLIGHTER_REGION_BLOCK', 6); |
|
36 | -define ('TEXT_HIGHLIGHTER_BLOCK_REGION', 7); |
|
37 | -define ('TEXT_HIGHLIGHTER_KEYWORD_BLOCK', 8); |
|
38 | -define ('TEXT_HIGHLIGHTER_KEYWORD_INHERITS', 9); |
|
39 | -define ('TEXT_HIGHLIGHTER_PARSE', 10); |
|
40 | -define ('TEXT_HIGHLIGHTER_FILE_WRITE', 11); |
|
41 | -define ('TEXT_HIGHLIGHTER_FILE_READ', 12); |
|
30 | +define('TEXT_HIGHLIGHTER_EMPTY_RE', 1); |
|
31 | +define('TEXT_HIGHLIGHTER_INVALID_RE', 2); |
|
32 | +define('TEXT_HIGHLIGHTER_EMPTY_OR_MISSING', 3); |
|
33 | +define('TEXT_HIGHLIGHTER_EMPTY', 4); |
|
34 | +define('TEXT_HIGHLIGHTER_REGION_REGION', 5); |
|
35 | +define('TEXT_HIGHLIGHTER_REGION_BLOCK', 6); |
|
36 | +define('TEXT_HIGHLIGHTER_BLOCK_REGION', 7); |
|
37 | +define('TEXT_HIGHLIGHTER_KEYWORD_BLOCK', 8); |
|
38 | +define('TEXT_HIGHLIGHTER_KEYWORD_INHERITS', 9); |
|
39 | +define('TEXT_HIGHLIGHTER_PARSE', 10); |
|
40 | +define('TEXT_HIGHLIGHTER_FILE_WRITE', 11); |
|
41 | +define('TEXT_HIGHLIGHTER_FILE_READ', 12); |
|
42 | 42 | // }}} |
43 | 43 | |
44 | 44 | /** |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | */ |
240 | 240 | function _declareErrorMessages() |
241 | 241 | { |
242 | - $this->_templates = array ( |
|
242 | + $this->_templates = array( |
|
243 | 243 | TEXT_HIGHLIGHTER_EMPTY_RE => 'Empty regular expression', |
244 | 244 | TEXT_HIGHLIGHTER_INVALID_RE => 'Invalid regular expression : %s', |
245 | 245 | TEXT_HIGHLIGHTER_EMPTY_OR_MISSING => 'Empty or missing %s', |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | $this->_inComment = false; |
298 | 298 | $this->_authors = array(); |
299 | 299 | $this->_blockOrder = 0; |
300 | - $this->_errors = array(); |
|
300 | + $this->_errors = array(); |
|
301 | 301 | |
302 | 302 | $ret = $this->parse(); |
303 | 303 | if (PEAR::isError($ret)) { |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | $this->_error(TEXT_HIGHLIGHTER_FILE_WRITE, array('outfile'=>$filename)); |
343 | 343 | return false; |
344 | 344 | } |
345 | - fwrite ($f, $this->_code); |
|
345 | + fwrite($f, $this->_code); |
|
346 | 346 | fclose($f); |
347 | 347 | return true; |
348 | 348 | } |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | if ($php_errormsg) { |
431 | 431 | $this->_error(TEXT_HIGHLIGHTER_INVALID_RE, $php_errormsg); |
432 | 432 | } |
433 | - preg_match ('#^/(.+)/(.*)$#', $text, $m); |
|
433 | + preg_match('#^/(.+)/(.*)$#', $text, $m); |
|
434 | 434 | if (@$m[2]) { |
435 | 435 | $text = '(?' . $m[2] . ')' . $m[1]; |
436 | 436 | } else { |
@@ -452,7 +452,7 @@ discard block |
||
452 | 452 | function _exportArray($array) |
453 | 453 | { |
454 | 454 | $array = var_export($array, true); |
455 | - return trim(preg_replace('~^(\s*)~m',' \1\1',$array)); |
|
455 | + return trim(preg_replace('~^(\s*)~m', ' \1\1', $array)); |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | // }}} |
@@ -465,7 +465,7 @@ discard block |
||
465 | 465 | function _countSubpatterns($re) |
466 | 466 | { |
467 | 467 | preg_match_all('/' . $re . '/', '', $m); |
468 | - return count($m)-1; |
|
468 | + return count($m) - 1; |
|
469 | 469 | } |
470 | 470 | |
471 | 471 | // }}} |
@@ -515,8 +515,7 @@ discard block |
||
515 | 515 | } |
516 | 516 | $this->_element['innerGroup'] = $attribs['innerGroup']; |
517 | 517 | $this->_element['delimGroup'] = isset($attribs['delimGroup']) ? |
518 | - $attribs['delimGroup'] : |
|
519 | - $attribs['innerGroup']; |
|
518 | + $attribs['delimGroup'] : $attribs['innerGroup']; |
|
520 | 519 | $this->_element['start'] = $this->_makeRE(@$attribs['start'], $this->_element['case']); |
521 | 520 | $this->_element['end'] = $this->_makeRE(@$attribs['end'], $this->_element['case']); |
522 | 521 | $this->_element['contained'] = @$attribs['contained'] == 'yes'; |
@@ -738,7 +737,7 @@ discard block |
||
738 | 737 | } |
739 | 738 | $this->_authors[] = array( |
740 | 739 | 'name' => @$attribs['name'], |
741 | - 'email' => (string)@$attribs['email'] |
|
740 | + 'email' => (string) @$attribs['email'] |
|
742 | 741 | ); |
743 | 742 | } |
744 | 743 | |
@@ -828,7 +827,7 @@ discard block |
||
828 | 827 | function xmltag_Region_($xp, $elem) |
829 | 828 | { |
830 | 829 | $this->_element['type'] = 'region'; |
831 | - $this->_element['order'] = $this->_blockOrder ++; |
|
830 | + $this->_element['order'] = $this->_blockOrder++; |
|
832 | 831 | $this->_regions[$this->_element['name']] = $this->_element; |
833 | 832 | } |
834 | 833 | |
@@ -852,7 +851,7 @@ discard block |
||
852 | 851 | function xmltag_Block_($xp, $elem) |
853 | 852 | { |
854 | 853 | $this->_element['type'] = 'block'; |
855 | - $this->_element['order'] = $this->_blockOrder ++; |
|
854 | + $this->_element['order'] = $this->_blockOrder++; |
|
856 | 855 | $this->_blocks[$this->_element['name']] = $this->_element; |
857 | 856 | } |
858 | 857 | |
@@ -870,7 +869,7 @@ discard block |
||
870 | 869 | if (!$current['contained'] && !isset($current['onlyin'])) { |
871 | 870 | $toplevel[] = $i; |
872 | 871 | } |
873 | - foreach ((array)@$current['onlyin'] as $region => $lineNo) { |
|
872 | + foreach ((array) @$current['onlyin'] as $region => $lineNo) { |
|
874 | 873 | if (!isset($this->_regions[$region])) { |
875 | 874 | $this->_error(TEXT_HIGHLIGHTER_BLOCK_REGION, |
876 | 875 | array( |
@@ -884,7 +883,7 @@ discard block |
||
884 | 883 | if (!$current['contained'] && !isset($current['onlyin'])) { |
885 | 884 | $toplevel[] = $i; |
886 | 885 | } |
887 | - foreach ((array)@$current['contains']['region'] as $region => $lineNo) { |
|
886 | + foreach ((array) @$current['contains']['region'] as $region => $lineNo) { |
|
888 | 887 | if (!isset($this->_regions[$region])) { |
889 | 888 | $this->_error(TEXT_HIGHLIGHTER_REGION_REGION, |
890 | 889 | array( |
@@ -893,7 +892,7 @@ discard block |
||
893 | 892 | )); |
894 | 893 | } |
895 | 894 | } |
896 | - foreach ((array)@$current['contains']['block'] as $region => $lineNo) { |
|
895 | + foreach ((array) @$current['contains']['block'] as $region => $lineNo) { |
|
897 | 896 | if (!isset($this->_blocks[$region])) { |
898 | 897 | $this->_error(TEXT_HIGHLIGHTER_REGION_BLOCK, |
899 | 898 | array( |
@@ -902,7 +901,7 @@ discard block |
||
902 | 901 | )); |
903 | 902 | } |
904 | 903 | } |
905 | - foreach ((array)@$current['onlyin'] as $region => $lineNo) { |
|
904 | + foreach ((array) @$current['onlyin'] as $region => $lineNo) { |
|
906 | 905 | if (!isset($this->_regions[$region])) { |
907 | 906 | $this->_error(TEXT_HIGHLIGHTER_REGION_REGION, |
908 | 907 | array( |
@@ -973,7 +972,7 @@ discard block |
||
973 | 972 | 'block' => $keyword['inherits'] |
974 | 973 | )); |
975 | 974 | } |
976 | - if (isset($keyword['otherwise']) && !isset($this->_blocks[$keyword['otherwise']]) ) { |
|
975 | + if (isset($keyword['otherwise']) && !isset($this->_blocks[$keyword['otherwise']])) { |
|
977 | 976 | $this->_error(TEXT_HIGHLIGHTER_KEYWORD_BLOCK, |
978 | 977 | array( |
979 | 978 | 'keyword' => $keyword['name'], |
@@ -982,7 +981,7 @@ discard block |
||
982 | 981 | } |
983 | 982 | } |
984 | 983 | |
985 | - $syntax=array( |
|
984 | + $syntax = array( |
|
986 | 985 | 'keywords' => $this->_keywords, |
987 | 986 | 'blocks' => array_merge($this->_blocks, $this->_regions), |
988 | 987 | 'toplevel' => $toplevel, |
@@ -1005,7 +1004,7 @@ discard block |
||
1005 | 1004 | CODE; |
1006 | 1005 | |
1007 | 1006 | if ($this->_comment) { |
1008 | - $comment = preg_replace('~^~m',' * ',$this->_comment); |
|
1007 | + $comment = preg_replace('~^~m', ' * ', $this->_comment); |
|
1009 | 1008 | $this->_code .= "\n * \n" . $comment; |
1010 | 1009 | } |
1011 | 1010 | |
@@ -1049,7 +1048,7 @@ discard block |
||
1049 | 1048 | foreach ($this->_authors as $author) { |
1050 | 1049 | $this->_code .= ' * @author ' . $author['name']; |
1051 | 1050 | if ($author['email']) { |
1052 | - $this->_code .= ' <' . $author['email']. '>'; |
|
1051 | + $this->_code .= ' <' . $author['email'] . '>'; |
|
1053 | 1052 | } |
1054 | 1053 | $this->_code .= "\n"; |
1055 | 1054 | } |
@@ -1069,7 +1068,7 @@ discard block |
||
1069 | 1068 | CODE; |
1070 | 1069 | $this->_code .= 'var $_language = \'' . strtolower($this->language) . "';\n\n"; |
1071 | 1070 | $array = var_export($syntax, true); |
1072 | - $array = trim(preg_replace('~^(\s*)~m',' \1\1',$array)); |
|
1071 | + $array = trim(preg_replace('~^(\s*)~m', ' \1\1', $array)); |
|
1073 | 1072 | // \$this->_syntax = $array; |
1074 | 1073 | $this->_code .= <<<CODE |
1075 | 1074 | |
@@ -1118,7 +1117,7 @@ discard block |
||
1118 | 1117 | $re[] = '(' . $block['match'] . ')'; |
1119 | 1118 | $ce[] = $this->_countSubpatterns($block['match']); |
1120 | 1119 | $rd[] = ''; |
1121 | - $sb[] = false;; |
|
1120 | + $sb[] = false; ; |
|
1122 | 1121 | $st[] = -1; |
1123 | 1122 | foreach ($syntax['keywords'] as $kwname => $kwgroup) { |
1124 | 1123 | if ($kwgroup['inherits'] != $name) { |
@@ -1128,7 +1127,7 @@ discard block |
||
1128 | 1127 | if (!$kwgroup['case']) { |
1129 | 1128 | $gre = '(?i)' . $gre; |
1130 | 1129 | } |
1131 | - $kwm[$kwname][] = $gre; |
|
1130 | + $kwm[$kwname][] = $gre; |
|
1132 | 1131 | $kwmap[$kwname] = $kwgroup['innerGroup']; |
1133 | 1132 | } |
1134 | 1133 | foreach ($kwm as $g => $ma) { |
@@ -1167,7 +1166,7 @@ discard block |
||
1167 | 1166 | $kw = array(); |
1168 | 1167 | $pc = array(); |
1169 | 1168 | $sb = array(); |
1170 | - foreach ((array)@$ablock['lookfor'] as $name) { |
|
1169 | + foreach ((array) @$ablock['lookfor'] as $name) { |
|
1171 | 1170 | $block = $syntax['blocks'][$name]; |
1172 | 1171 | if (isset($block['partClass'])) { |
1173 | 1172 | $pc[] = $block['partClass']; |
@@ -1175,7 +1174,7 @@ discard block |
||
1175 | 1174 | $pc[] = null; |
1176 | 1175 | } |
1177 | 1176 | if ($block['type'] == 'block') { |
1178 | - $kwm = array();; |
|
1177 | + $kwm = array(); ; |
|
1179 | 1178 | $re[] = '(' . $block['match'] . ')'; |
1180 | 1179 | $ce[] = $this->_countSubpatterns($block['match']); |
1181 | 1180 | $rd[] = ''; |
@@ -1189,7 +1188,7 @@ discard block |
||
1189 | 1188 | if (!$kwgroup['case']) { |
1190 | 1189 | $gre = '(?i)' . $gre; |
1191 | 1190 | } |
1192 | - $kwm[$kwname][] = $gre; |
|
1191 | + $kwm[$kwname][] = $gre; |
|
1193 | 1192 | $kwmap[$kwname] = $kwgroup['innerGroup']; |
1194 | 1193 | } |
1195 | 1194 | foreach ($kwm as $g => $ma) { |
@@ -1219,17 +1218,17 @@ discard block |
||
1219 | 1218 | |
1220 | 1219 | |
1221 | 1220 | $this->_code .= "\n \$this->_regs = " . $this->_exportArray($regs); |
1222 | - $this->_code .= ";\n \$this->_counts = " .$this->_exportArray($counts); |
|
1223 | - $this->_code .= ";\n \$this->_delim = " .$this->_exportArray($delim); |
|
1224 | - $this->_code .= ";\n \$this->_inner = " .$this->_exportArray($inner); |
|
1225 | - $this->_code .= ";\n \$this->_end = " .$this->_exportArray($end); |
|
1226 | - $this->_code .= ";\n \$this->_states = " .$this->_exportArray($stat); |
|
1227 | - $this->_code .= ";\n \$this->_keywords = " .$this->_exportArray($keywords); |
|
1228 | - $this->_code .= ";\n \$this->_parts = " .$this->_exportArray($parts); |
|
1229 | - $this->_code .= ";\n \$this->_subst = " .$this->_exportArray($subst); |
|
1230 | - $this->_code .= ";\n \$this->_conditions = " .$this->_exportArray($conditions); |
|
1231 | - $this->_code .= ";\n \$this->_kwmap = " .$this->_exportArray($kwmap); |
|
1232 | - $this->_code .= ";\n \$this->_defClass = '" .$this->_defClass . '\''; |
|
1221 | + $this->_code .= ";\n \$this->_counts = " . $this->_exportArray($counts); |
|
1222 | + $this->_code .= ";\n \$this->_delim = " . $this->_exportArray($delim); |
|
1223 | + $this->_code .= ";\n \$this->_inner = " . $this->_exportArray($inner); |
|
1224 | + $this->_code .= ";\n \$this->_end = " . $this->_exportArray($end); |
|
1225 | + $this->_code .= ";\n \$this->_states = " . $this->_exportArray($stat); |
|
1226 | + $this->_code .= ";\n \$this->_keywords = " . $this->_exportArray($keywords); |
|
1227 | + $this->_code .= ";\n \$this->_parts = " . $this->_exportArray($parts); |
|
1228 | + $this->_code .= ";\n \$this->_subst = " . $this->_exportArray($subst); |
|
1229 | + $this->_code .= ";\n \$this->_conditions = " . $this->_exportArray($conditions); |
|
1230 | + $this->_code .= ";\n \$this->_kwmap = " . $this->_exportArray($kwmap); |
|
1231 | + $this->_code .= ";\n \$this->_defClass = '" . $this->_defClass . '\''; |
|
1233 | 1232 | $this->_code .= <<<CODE |
1234 | 1233 | ; |
1235 | 1234 | \$this->_checkDefines(); |
@@ -68,7 +68,6 @@ discard block |
||
68 | 68 | * |
69 | 69 | * @access public |
70 | 70 | * |
71 | - * @param array $options Rendering options. Renderer-specific. |
|
72 | 71 | */ |
73 | 72 | function reset() |
74 | 73 | { |
@@ -130,6 +129,7 @@ discard block |
||
130 | 129 | * Set current language |
131 | 130 | * |
132 | 131 | * @abstract |
132 | + * @param string $lang |
|
133 | 133 | * @return void |
134 | 134 | * @access public |
135 | 135 | * |
@@ -35,109 +35,109 @@ |
||
35 | 35 | |
36 | 36 | class Text_Highlighter_Renderer |
37 | 37 | { |
38 | - /** |
|
39 | - * Renderer options |
|
40 | - * |
|
41 | - * @var array |
|
42 | - * @access protected |
|
43 | - */ |
|
44 | - public $_options = array(); |
|
38 | + /** |
|
39 | + * Renderer options |
|
40 | + * |
|
41 | + * @var array |
|
42 | + * @access protected |
|
43 | + */ |
|
44 | + public $_options = array(); |
|
45 | 45 | |
46 | - /** |
|
47 | - * Current language |
|
48 | - * |
|
49 | - * @var string |
|
50 | - * @access protected |
|
51 | - */ |
|
52 | - public $_language = ''; |
|
46 | + /** |
|
47 | + * Current language |
|
48 | + * |
|
49 | + * @var string |
|
50 | + * @access protected |
|
51 | + */ |
|
52 | + public $_language = ''; |
|
53 | 53 | |
54 | - /** |
|
55 | - * Constructor |
|
56 | - * |
|
57 | - * @access public |
|
58 | - * |
|
59 | - * @param array $options Rendering options. Renderer-specific. |
|
60 | - */ |
|
61 | - function __construct($options = array()) |
|
62 | - { |
|
63 | - $this->_options = $options; |
|
64 | - } |
|
54 | + /** |
|
55 | + * Constructor |
|
56 | + * |
|
57 | + * @access public |
|
58 | + * |
|
59 | + * @param array $options Rendering options. Renderer-specific. |
|
60 | + */ |
|
61 | + function __construct($options = array()) |
|
62 | + { |
|
63 | + $this->_options = $options; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Resets renderer state |
|
68 | - * |
|
69 | - * @access public |
|
70 | - * |
|
71 | - * @param array $options Rendering options. Renderer-specific. |
|
72 | - */ |
|
73 | - function reset() |
|
74 | - { |
|
75 | - return; |
|
76 | - } |
|
66 | + /** |
|
67 | + * Resets renderer state |
|
68 | + * |
|
69 | + * @access public |
|
70 | + * |
|
71 | + * @param array $options Rendering options. Renderer-specific. |
|
72 | + */ |
|
73 | + function reset() |
|
74 | + { |
|
75 | + return; |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Preprocesses code |
|
80 | - * |
|
81 | - * @access public |
|
82 | - * |
|
83 | - * @param string $str Code to preprocess |
|
84 | - * @return string Preprocessed code |
|
85 | - */ |
|
86 | - function preprocess($str) |
|
87 | - { |
|
88 | - return $str; |
|
89 | - } |
|
78 | + /** |
|
79 | + * Preprocesses code |
|
80 | + * |
|
81 | + * @access public |
|
82 | + * |
|
83 | + * @param string $str Code to preprocess |
|
84 | + * @return string Preprocessed code |
|
85 | + */ |
|
86 | + function preprocess($str) |
|
87 | + { |
|
88 | + return $str; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * Accepts next token |
|
93 | - * |
|
94 | - * @abstract |
|
95 | - * @access public |
|
96 | - * |
|
97 | - * @param string $class Token class |
|
98 | - * @param string $content Token content |
|
99 | - */ |
|
100 | - function acceptToken($class, $content) |
|
101 | - { |
|
102 | - return; |
|
103 | - } |
|
91 | + /** |
|
92 | + * Accepts next token |
|
93 | + * |
|
94 | + * @abstract |
|
95 | + * @access public |
|
96 | + * |
|
97 | + * @param string $class Token class |
|
98 | + * @param string $content Token content |
|
99 | + */ |
|
100 | + function acceptToken($class, $content) |
|
101 | + { |
|
102 | + return; |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * Signals that no more tokens are available |
|
107 | - * |
|
108 | - * @access public |
|
109 | - * |
|
110 | - */ |
|
111 | - function finalize() |
|
112 | - { |
|
113 | - return; |
|
114 | - } |
|
105 | + /** |
|
106 | + * Signals that no more tokens are available |
|
107 | + * |
|
108 | + * @access public |
|
109 | + * |
|
110 | + */ |
|
111 | + function finalize() |
|
112 | + { |
|
113 | + return; |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * Get generated output |
|
118 | - * |
|
119 | - * @abstract |
|
120 | - * @return mixed Renderer-specific |
|
121 | - * @access public |
|
122 | - * |
|
123 | - */ |
|
124 | - function getOutput() |
|
125 | - { |
|
126 | - return; |
|
127 | - } |
|
116 | + /** |
|
117 | + * Get generated output |
|
118 | + * |
|
119 | + * @abstract |
|
120 | + * @return mixed Renderer-specific |
|
121 | + * @access public |
|
122 | + * |
|
123 | + */ |
|
124 | + function getOutput() |
|
125 | + { |
|
126 | + return; |
|
127 | + } |
|
128 | 128 | |
129 | - /** |
|
130 | - * Set current language |
|
131 | - * |
|
132 | - * @abstract |
|
133 | - * @return void |
|
134 | - * @access public |
|
135 | - * |
|
136 | - */ |
|
137 | - function setCurrentLanguage($lang) |
|
138 | - { |
|
139 | - $this->_language = $lang; |
|
140 | - } |
|
129 | + /** |
|
130 | + * Set current language |
|
131 | + * |
|
132 | + * @abstract |
|
133 | + * @return void |
|
134 | + * @access public |
|
135 | + * |
|
136 | + */ |
|
137 | + function setCurrentLanguage($lang) |
|
138 | + { |
|
139 | + $this->_language = $lang; |
|
140 | + } |
|
141 | 141 | |
142 | 142 | } |
143 | 143 |
@@ -59,7 +59,6 @@ |
||
59 | 59 | |
60 | 60 | /** |
61 | 61 | * Return the message as a DOM element |
62 | - * @param DOMDocument $wsdl The wsdl document the messages will be children of |
|
63 | 62 | */ |
64 | 63 | public function getMessageElement(DOMDocument $dom) |
65 | 64 | { |
@@ -1,19 +1,19 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * WsdlMessage file. |
|
4 | - * |
|
5 | - * This program is free software; you can redistribute it and/or modify |
|
6 | - * it under the terms of the BSD License. |
|
7 | - * |
|
8 | - * Copyright(c) 2005 by Marcus Nyeholt. All rights reserved. |
|
9 | - * |
|
10 | - * To contact the author write to {@link mailto:[email protected] Marcus Nyeholt} |
|
11 | - * This file is part of the PRADO framework from {@link http://www.xisc.com} |
|
12 | - * |
|
13 | - * @author Marcus Nyeholt <[email protected]> |
|
14 | - * @author Wei Zhuo <weizhuo[at]gmail[dot]com> |
|
15 | - * @package System.Web.Services.SOAP |
|
16 | - */ |
|
3 | + * WsdlMessage file. |
|
4 | + * |
|
5 | + * This program is free software; you can redistribute it and/or modify |
|
6 | + * it under the terms of the BSD License. |
|
7 | + * |
|
8 | + * Copyright(c) 2005 by Marcus Nyeholt. All rights reserved. |
|
9 | + * |
|
10 | + * To contact the author write to {@link mailto:[email protected] Marcus Nyeholt} |
|
11 | + * This file is part of the PRADO framework from {@link http://www.xisc.com} |
|
12 | + * |
|
13 | + * @author Marcus Nyeholt <[email protected]> |
|
14 | + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> |
|
15 | + * @package System.Web.Services.SOAP |
|
16 | + */ |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * Represents a WSDL message. This is bound to the portTypes |
@@ -98,6 +98,7 @@ discard block |
||
98 | 98 | |
99 | 99 | /** |
100 | 100 | * @param string a unique prefix for the keys of cached values |
101 | + * @param string $value |
|
101 | 102 | */ |
102 | 103 | public function setKeyPrefix($value) |
103 | 104 | { |
@@ -106,7 +107,7 @@ discard block |
||
106 | 107 | |
107 | 108 | /** |
108 | 109 | * @param string a key identifying a value to be cached |
109 | - * @return sring a key generated from the provided key which ensures the uniqueness across applications |
|
110 | + * @return string a key generated from the provided key which ensures the uniqueness across applications |
|
110 | 111 | */ |
111 | 112 | protected function generateUniqueKey($key) |
112 | 113 | { |
@@ -160,6 +161,8 @@ discard block |
||
160 | 161 | * @param mixed the value to be cached |
161 | 162 | * @param integer the number of seconds in which the cached value will expire. 0 means never expire. |
162 | 163 | * @param ICacheDependency dependency of the cached item. If the dependency changes, the item is labeled invalid. |
164 | + * @param string $id |
|
165 | + * @param string $value |
|
163 | 166 | * @return boolean true if the value is successfully stored into cache, false otherwise |
164 | 167 | */ |
165 | 168 | public function add($id,$value,$expire=0,$dependency=null) |
@@ -198,6 +201,7 @@ discard block |
||
198 | 201 | * in {@link get()} already. So only the implementation of data retrieval |
199 | 202 | * is needed. |
200 | 203 | * @param string a unique key identifying the cached value |
204 | + * @param string $key |
|
201 | 205 | * @return string the value stored in cache, false if the value is not in the cache or expired. |
202 | 206 | */ |
203 | 207 | abstract protected function getValue($key); |
@@ -212,6 +216,8 @@ discard block |
||
212 | 216 | * @param string the key identifying the value to be cached |
213 | 217 | * @param string the value to be cached |
214 | 218 | * @param integer the number of seconds in which the cached value will expire. 0 means never expire. |
219 | + * @param string $key |
|
220 | + * @param integer $expire |
|
215 | 221 | * @return boolean true if the value is successfully stored into cache, false otherwise |
216 | 222 | */ |
217 | 223 | abstract protected function setValue($key,$value,$expire); |
@@ -226,6 +232,8 @@ discard block |
||
226 | 232 | * @param string the key identifying the value to be cached |
227 | 233 | * @param string the value to be cached |
228 | 234 | * @param integer the number of seconds in which the cached value will expire. 0 means never expire. |
235 | + * @param string $key |
|
236 | + * @param integer $expire |
|
229 | 237 | * @return boolean true if the value is successfully stored into cache, false otherwise |
230 | 238 | */ |
231 | 239 | abstract protected function addValue($key,$value,$expire); |
@@ -234,6 +242,7 @@ discard block |
||
234 | 242 | * Deletes a value with the specified key from cache |
235 | 243 | * This method should be implemented by child classes to delete the data from actual cache storage. |
236 | 244 | * @param string the key of the value to be deleted |
245 | + * @param string $key |
|
237 | 246 | * @return boolean if no error happens during deletion |
238 | 247 | */ |
239 | 248 | abstract protected function deleteValue($key); |
@@ -409,6 +418,7 @@ discard block |
||
409 | 418 | /** |
410 | 419 | * Constructor. |
411 | 420 | * @param string the directory to be checked |
421 | + * @param string $directory |
|
412 | 422 | */ |
413 | 423 | public function __construct($directory) |
414 | 424 | { |
@@ -446,6 +456,7 @@ discard block |
||
446 | 456 | |
447 | 457 | /** |
448 | 458 | * @param boolean whether the subdirectories of the directory will also be checked. |
459 | + * @param boolean $value |
|
449 | 460 | */ |
450 | 461 | public function setRecursiveCheck($value) |
451 | 462 | { |
@@ -468,6 +479,7 @@ discard block |
||
468 | 479 | * @param int the depth of the subdirectories to be checked. |
469 | 480 | * If the value is less than 0, it means unlimited depth. |
470 | 481 | * If the value is 0, it means checking the files directly under the specified directory. |
482 | + * @param integer $value |
|
471 | 483 | */ |
472 | 484 | public function setRecursiveLevel($value) |
473 | 485 | { |
@@ -490,6 +502,7 @@ discard block |
||
490 | 502 | * By default, it always returns true, meaning the file should be checked. |
491 | 503 | * You may override this method to check only certain files. |
492 | 504 | * @param string the name of the file that may be checked for dependency. |
505 | + * @param string $fileName |
|
493 | 506 | * @return boolean whether this file should be checked. |
494 | 507 | */ |
495 | 508 | protected function validateFile($fileName) |
@@ -503,6 +516,7 @@ discard block |
||
503 | 516 | * By default, it always returns true, meaning the subdirectory should be checked. |
504 | 517 | * You may override this method to check only certain subdirectories. |
505 | 518 | * @param string the name of the subdirectory that may be checked for dependency. |
519 | + * @param string $directory |
|
506 | 520 | * @return boolean whether this subdirectory should be checked. |
507 | 521 | */ |
508 | 522 | protected function validateDirectory($directory) |
@@ -516,6 +530,7 @@ discard block |
||
516 | 530 | * {@link setRecursiveCheck RecursiveCheck} is set true. |
517 | 531 | * @param string the directory name |
518 | 532 | * @param int level of the recursion |
533 | + * @param string $directory |
|
519 | 534 | * @return array list of file modification time indexed by the file path |
520 | 535 | */ |
521 | 536 | protected function generateTimestamps($directory,$level=0) |
@@ -46,8 +46,8 @@ discard block |
||
46 | 46 | */ |
47 | 47 | abstract class TCache extends TModule implements ICache, ArrayAccess |
48 | 48 | { |
49 | - private $_prefix=null; |
|
50 | - private $_primary=true; |
|
49 | + private $_prefix = null; |
|
50 | + private $_primary = true; |
|
51 | 51 | |
52 | 52 | /** |
53 | 53 | * Initializes the cache module. |
@@ -57,14 +57,14 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function init($config) |
59 | 59 | { |
60 | - if($this->_prefix===null) |
|
61 | - $this->_prefix=$this->getApplication()->getUniqueID(); |
|
62 | - if($this->_primary) |
|
60 | + if ($this->_prefix === null) |
|
61 | + $this->_prefix = $this->getApplication()->getUniqueID(); |
|
62 | + if ($this->_primary) |
|
63 | 63 | { |
64 | - if($this->getApplication()->getCache()===null) |
|
64 | + if ($this->getApplication()->getCache() === null) |
|
65 | 65 | $this->getApplication()->setCache($this); |
66 | 66 | else |
67 | - throw new TConfigurationException('cache_primary_duplicated',get_class($this)); |
|
67 | + throw new TConfigurationException('cache_primary_duplicated', get_class($this)); |
|
68 | 68 | } |
69 | 69 | } |
70 | 70 | |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function setPrimaryCache($value) |
86 | 86 | { |
87 | - $this->_primary=TPropertyValue::ensureBoolean($value); |
|
87 | + $this->_primary = TPropertyValue::ensureBoolean($value); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | */ |
102 | 102 | public function setKeyPrefix($value) |
103 | 103 | { |
104 | - $this->_prefix=$value; |
|
104 | + $this->_prefix = $value; |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | */ |
111 | 111 | protected function generateUniqueKey($key) |
112 | 112 | { |
113 | - return md5($this->_prefix.$key); |
|
113 | + return md5($this->_prefix . $key); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
@@ -120,11 +120,11 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public function get($id) |
122 | 122 | { |
123 | - if(($data=$this->getValue($this->generateUniqueKey($id)))!==false) |
|
123 | + if (($data = $this->getValue($this->generateUniqueKey($id))) !== false) |
|
124 | 124 | { |
125 | - if(!is_array($data)) |
|
125 | + if (!is_array($data)) |
|
126 | 126 | return false; |
127 | - if(!($data[1] instanceof ICacheDependency) || !$data[1]->getHasChanged()) |
|
127 | + if (!($data[1] instanceof ICacheDependency) || !$data[1]->getHasChanged()) |
|
128 | 128 | return $data[0]; |
129 | 129 | } |
130 | 130 | return false; |
@@ -142,14 +142,14 @@ discard block |
||
142 | 142 | * @param ICacheDependency dependency of the cached item. If the dependency changes, the item is labeled invalid. |
143 | 143 | * @return boolean true if the value is successfully stored into cache, false otherwise |
144 | 144 | */ |
145 | - public function set($id,$value,$expire=0,$dependency=null) |
|
145 | + public function set($id, $value, $expire = 0, $dependency = null) |
|
146 | 146 | { |
147 | - if(empty($value) && $expire === 0) |
|
147 | + if (empty($value) && $expire === 0) |
|
148 | 148 | $this->delete($id); |
149 | 149 | else |
150 | 150 | { |
151 | - $data=array($value,$dependency); |
|
152 | - return $this->setValue($this->generateUniqueKey($id),$data,$expire); |
|
151 | + $data = array($value, $dependency); |
|
152 | + return $this->setValue($this->generateUniqueKey($id), $data, $expire); |
|
153 | 153 | } |
154 | 154 | } |
155 | 155 | |
@@ -162,12 +162,12 @@ discard block |
||
162 | 162 | * @param ICacheDependency dependency of the cached item. If the dependency changes, the item is labeled invalid. |
163 | 163 | * @return boolean true if the value is successfully stored into cache, false otherwise |
164 | 164 | */ |
165 | - public function add($id,$value,$expire=0,$dependency=null) |
|
165 | + public function add($id, $value, $expire = 0, $dependency = null) |
|
166 | 166 | { |
167 | - if(empty($value) && $expire === 0) |
|
167 | + if (empty($value) && $expire === 0) |
|
168 | 168 | return false; |
169 | - $data=array($value,$dependency); |
|
170 | - return $this->addValue($this->generateUniqueKey($id),$data,$expire); |
|
169 | + $data = array($value, $dependency); |
|
170 | + return $this->addValue($this->generateUniqueKey($id), $data, $expire); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | /** |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | * @param integer the number of seconds in which the cached value will expire. 0 means never expire. |
215 | 215 | * @return boolean true if the value is successfully stored into cache, false otherwise |
216 | 216 | */ |
217 | - abstract protected function setValue($key,$value,$expire); |
|
217 | + abstract protected function setValue($key, $value, $expire); |
|
218 | 218 | |
219 | 219 | /** |
220 | 220 | * Stores a value identified by a key into cache if the cache does not contain this key. |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | * @param integer the number of seconds in which the cached value will expire. 0 means never expire. |
229 | 229 | * @return boolean true if the value is successfully stored into cache, false otherwise |
230 | 230 | */ |
231 | - abstract protected function addValue($key,$value,$expire); |
|
231 | + abstract protected function addValue($key, $value, $expire); |
|
232 | 232 | |
233 | 233 | /** |
234 | 234 | * Deletes a value with the specified key from cache |
@@ -358,8 +358,8 @@ discard block |
||
358 | 358 | */ |
359 | 359 | public function setFileName($value) |
360 | 360 | { |
361 | - $this->_fileName=$value; |
|
362 | - $this->_timestamp=@filemtime($value); |
|
361 | + $this->_fileName = $value; |
|
362 | + $this->_timestamp = @filemtime($value); |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | /** |
@@ -377,7 +377,7 @@ discard block |
||
377 | 377 | */ |
378 | 378 | public function getHasChanged() |
379 | 379 | { |
380 | - return @filemtime($this->_fileName)!==$this->_timestamp; |
|
380 | + return @filemtime($this->_fileName) !== $this->_timestamp; |
|
381 | 381 | } |
382 | 382 | } |
383 | 383 | |
@@ -401,8 +401,8 @@ discard block |
||
401 | 401 | */ |
402 | 402 | class TDirectoryCacheDependency extends TCacheDependency |
403 | 403 | { |
404 | - private $_recursiveCheck=true; |
|
405 | - private $_recursiveLevel=-1; |
|
404 | + private $_recursiveCheck = true; |
|
405 | + private $_recursiveLevel = -1; |
|
406 | 406 | private $_timestamps; |
407 | 407 | private $_directory; |
408 | 408 | |
@@ -429,10 +429,10 @@ discard block |
||
429 | 429 | */ |
430 | 430 | public function setDirectory($directory) |
431 | 431 | { |
432 | - if(($path=realpath($directory))===false || !is_dir($path)) |
|
433 | - throw new TInvalidDataValueException('directorycachedependency_directory_invalid',$directory); |
|
434 | - $this->_directory=$path; |
|
435 | - $this->_timestamps=$this->generateTimestamps($path); |
|
432 | + if (($path = realpath($directory)) === false || !is_dir($path)) |
|
433 | + throw new TInvalidDataValueException('directorycachedependency_directory_invalid', $directory); |
|
434 | + $this->_directory = $path; |
|
435 | + $this->_timestamps = $this->generateTimestamps($path); |
|
436 | 436 | } |
437 | 437 | |
438 | 438 | /** |
@@ -449,7 +449,7 @@ discard block |
||
449 | 449 | */ |
450 | 450 | public function setRecursiveCheck($value) |
451 | 451 | { |
452 | - $this->_recursiveCheck=TPropertyValue::ensureBoolean($value); |
|
452 | + $this->_recursiveCheck = TPropertyValue::ensureBoolean($value); |
|
453 | 453 | } |
454 | 454 | |
455 | 455 | /** |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | */ |
472 | 472 | public function setRecursiveLevel($value) |
473 | 473 | { |
474 | - $this->_recursiveLevel=TPropertyValue::ensureInteger($value); |
|
474 | + $this->_recursiveLevel = TPropertyValue::ensureInteger($value); |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | /** |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | */ |
482 | 482 | public function getHasChanged() |
483 | 483 | { |
484 | - return $this->generateTimestamps($this->_directory)!=$this->_timestamps; |
|
484 | + return $this->generateTimestamps($this->_directory) != $this->_timestamps; |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | /** |
@@ -518,23 +518,23 @@ discard block |
||
518 | 518 | * @param int level of the recursion |
519 | 519 | * @return array list of file modification time indexed by the file path |
520 | 520 | */ |
521 | - protected function generateTimestamps($directory,$level=0) |
|
521 | + protected function generateTimestamps($directory, $level = 0) |
|
522 | 522 | { |
523 | - if(($dir=opendir($directory))===false) |
|
524 | - throw new TIOException('directorycachedependency_directory_invalid',$directory); |
|
525 | - $timestamps=array(); |
|
526 | - while(($file=readdir($dir))!==false) |
|
523 | + if (($dir = opendir($directory)) === false) |
|
524 | + throw new TIOException('directorycachedependency_directory_invalid', $directory); |
|
525 | + $timestamps = array(); |
|
526 | + while (($file = readdir($dir)) !== false) |
|
527 | 527 | { |
528 | - $path=$directory.DIRECTORY_SEPARATOR.$file; |
|
529 | - if($file==='.' || $file==='..') |
|
528 | + $path = $directory . DIRECTORY_SEPARATOR . $file; |
|
529 | + if ($file === '.' || $file === '..') |
|
530 | 530 | continue; |
531 | - else if(is_dir($path)) |
|
531 | + else if (is_dir($path)) |
|
532 | 532 | { |
533 | - if(($this->_recursiveLevel<0 || $level<$this->_recursiveLevel) && $this->validateDirectory($path)) |
|
534 | - $timestamps=array_merge($this->generateTimestamps($path,$level+1)); |
|
533 | + if (($this->_recursiveLevel < 0 || $level < $this->_recursiveLevel) && $this->validateDirectory($path)) |
|
534 | + $timestamps = array_merge($this->generateTimestamps($path, $level + 1)); |
|
535 | 535 | } |
536 | - else if($this->validateFile($path)) |
|
537 | - $timestamps[$path]=filemtime($path); |
|
536 | + else if ($this->validateFile($path)) |
|
537 | + $timestamps[$path] = filemtime($path); |
|
538 | 538 | } |
539 | 539 | closedir($dir); |
540 | 540 | return $timestamps; |
@@ -582,8 +582,8 @@ discard block |
||
582 | 582 | */ |
583 | 583 | public function setStateName($value) |
584 | 584 | { |
585 | - $this->_stateName=$value; |
|
586 | - $this->_stateValue=Prado::getApplication()->getGlobalState($value); |
|
585 | + $this->_stateName = $value; |
|
586 | + $this->_stateValue = Prado::getApplication()->getGlobalState($value); |
|
587 | 587 | } |
588 | 588 | |
589 | 589 | /** |
@@ -593,7 +593,7 @@ discard block |
||
593 | 593 | */ |
594 | 594 | public function getHasChanged() |
595 | 595 | { |
596 | - return $this->_stateValue!==Prado::getApplication()->getGlobalState($this->_stateName); |
|
596 | + return $this->_stateValue !== Prado::getApplication()->getGlobalState($this->_stateName); |
|
597 | 597 | } |
598 | 598 | } |
599 | 599 | |
@@ -616,15 +616,15 @@ discard block |
||
616 | 616 | */ |
617 | 617 | class TChainedCacheDependency extends TCacheDependency |
618 | 618 | { |
619 | - private $_dependencies=null; |
|
619 | + private $_dependencies = null; |
|
620 | 620 | |
621 | 621 | /** |
622 | 622 | * @return TCacheDependencyList list of dependency objects |
623 | 623 | */ |
624 | 624 | public function getDependencies() |
625 | 625 | { |
626 | - if($this->_dependencies===null) |
|
627 | - $this->_dependencies=new TCacheDependencyList; |
|
626 | + if ($this->_dependencies === null) |
|
627 | + $this->_dependencies = new TCacheDependencyList; |
|
628 | 628 | return $this->_dependencies; |
629 | 629 | } |
630 | 630 | |
@@ -636,10 +636,10 @@ discard block |
||
636 | 636 | */ |
637 | 637 | public function getHasChanged() |
638 | 638 | { |
639 | - if($this->_dependencies!==null) |
|
639 | + if ($this->_dependencies !== null) |
|
640 | 640 | { |
641 | - foreach($this->_dependencies as $dependency) |
|
642 | - if($dependency->getHasChanged()) |
|
641 | + foreach ($this->_dependencies as $dependency) |
|
642 | + if ($dependency->getHasChanged()) |
|
643 | 643 | return true; |
644 | 644 | } |
645 | 645 | return false; |
@@ -672,7 +672,7 @@ discard block |
||
672 | 672 | */ |
673 | 673 | public function getHasChanged() |
674 | 674 | { |
675 | - return Prado::getApplication()->getMode()!==TApplicationMode::Performance; |
|
675 | + return Prado::getApplication()->getMode() !== TApplicationMode::Performance; |
|
676 | 676 | } |
677 | 677 | } |
678 | 678 | |
@@ -699,10 +699,10 @@ discard block |
||
699 | 699 | * @param mixed new item |
700 | 700 | * @throws TInvalidDataTypeException if the item to be inserted is not a dependency instance |
701 | 701 | */ |
702 | - public function insertAt($index,$item) |
|
702 | + public function insertAt($index, $item) |
|
703 | 703 | { |
704 | - if($item instanceof ICacheDependency) |
|
705 | - parent::insertAt($index,$item); |
|
704 | + if ($item instanceof ICacheDependency) |
|
705 | + parent::insertAt($index, $item); |
|
706 | 706 | else |
707 | 707 | throw new TInvalidDataTypeException('cachedependencylist_cachedependency_required'); |
708 | 708 | } |
@@ -57,14 +57,16 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function init($config) |
59 | 59 | { |
60 | - if($this->_prefix===null) |
|
61 | - $this->_prefix=$this->getApplication()->getUniqueID(); |
|
60 | + if($this->_prefix===null) { |
|
61 | + $this->_prefix=$this->getApplication()->getUniqueID(); |
|
62 | + } |
|
62 | 63 | if($this->_primary) |
63 | 64 | { |
64 | - if($this->getApplication()->getCache()===null) |
|
65 | - $this->getApplication()->setCache($this); |
|
66 | - else |
|
67 | - throw new TConfigurationException('cache_primary_duplicated',get_class($this)); |
|
65 | + if($this->getApplication()->getCache()===null) { |
|
66 | + $this->getApplication()->setCache($this); |
|
67 | + } else { |
|
68 | + throw new TConfigurationException('cache_primary_duplicated',get_class($this)); |
|
69 | + } |
|
68 | 70 | } |
69 | 71 | } |
70 | 72 | |
@@ -122,10 +124,12 @@ discard block |
||
122 | 124 | { |
123 | 125 | if(($data=$this->getValue($this->generateUniqueKey($id)))!==false) |
124 | 126 | { |
125 | - if(!is_array($data)) |
|
126 | - return false; |
|
127 | - if(!($data[1] instanceof ICacheDependency) || !$data[1]->getHasChanged()) |
|
128 | - return $data[0]; |
|
127 | + if(!is_array($data)) { |
|
128 | + return false; |
|
129 | + } |
|
130 | + if(!($data[1] instanceof ICacheDependency) || !$data[1]->getHasChanged()) { |
|
131 | + return $data[0]; |
|
132 | + } |
|
129 | 133 | } |
130 | 134 | return false; |
131 | 135 | } |
@@ -144,9 +148,9 @@ discard block |
||
144 | 148 | */ |
145 | 149 | public function set($id,$value,$expire=0,$dependency=null) |
146 | 150 | { |
147 | - if(empty($value) && $expire === 0) |
|
148 | - $this->delete($id); |
|
149 | - else |
|
151 | + if(empty($value) && $expire === 0) { |
|
152 | + $this->delete($id); |
|
153 | + } else |
|
150 | 154 | { |
151 | 155 | $data=array($value,$dependency); |
152 | 156 | return $this->setValue($this->generateUniqueKey($id),$data,$expire); |
@@ -164,8 +168,9 @@ discard block |
||
164 | 168 | */ |
165 | 169 | public function add($id,$value,$expire=0,$dependency=null) |
166 | 170 | { |
167 | - if(empty($value) && $expire === 0) |
|
168 | - return false; |
|
171 | + if(empty($value) && $expire === 0) { |
|
172 | + return false; |
|
173 | + } |
|
169 | 174 | $data=array($value,$dependency); |
170 | 175 | return $this->addValue($this->generateUniqueKey($id),$data,$expire); |
171 | 176 | } |
@@ -429,8 +434,9 @@ discard block |
||
429 | 434 | */ |
430 | 435 | public function setDirectory($directory) |
431 | 436 | { |
432 | - if(($path=realpath($directory))===false || !is_dir($path)) |
|
433 | - throw new TInvalidDataValueException('directorycachedependency_directory_invalid',$directory); |
|
437 | + if(($path=realpath($directory))===false || !is_dir($path)) { |
|
438 | + throw new TInvalidDataValueException('directorycachedependency_directory_invalid',$directory); |
|
439 | + } |
|
434 | 440 | $this->_directory=$path; |
435 | 441 | $this->_timestamps=$this->generateTimestamps($path); |
436 | 442 | } |
@@ -520,21 +526,23 @@ discard block |
||
520 | 526 | */ |
521 | 527 | protected function generateTimestamps($directory,$level=0) |
522 | 528 | { |
523 | - if(($dir=opendir($directory))===false) |
|
524 | - throw new TIOException('directorycachedependency_directory_invalid',$directory); |
|
529 | + if(($dir=opendir($directory))===false) { |
|
530 | + throw new TIOException('directorycachedependency_directory_invalid',$directory); |
|
531 | + } |
|
525 | 532 | $timestamps=array(); |
526 | 533 | while(($file=readdir($dir))!==false) |
527 | 534 | { |
528 | 535 | $path=$directory.DIRECTORY_SEPARATOR.$file; |
529 | - if($file==='.' || $file==='..') |
|
530 | - continue; |
|
531 | - else if(is_dir($path)) |
|
536 | + if($file==='.' || $file==='..') { |
|
537 | + continue; |
|
538 | + } else if(is_dir($path)) |
|
532 | 539 | { |
533 | - if(($this->_recursiveLevel<0 || $level<$this->_recursiveLevel) && $this->validateDirectory($path)) |
|
534 | - $timestamps=array_merge($this->generateTimestamps($path,$level+1)); |
|
540 | + if(($this->_recursiveLevel<0 || $level<$this->_recursiveLevel) && $this->validateDirectory($path)) { |
|
541 | + $timestamps=array_merge($this->generateTimestamps($path,$level+1)); |
|
542 | + } |
|
543 | + } else if($this->validateFile($path)) { |
|
544 | + $timestamps[$path]=filemtime($path); |
|
535 | 545 | } |
536 | - else if($this->validateFile($path)) |
|
537 | - $timestamps[$path]=filemtime($path); |
|
538 | 546 | } |
539 | 547 | closedir($dir); |
540 | 548 | return $timestamps; |
@@ -623,8 +631,9 @@ discard block |
||
623 | 631 | */ |
624 | 632 | public function getDependencies() |
625 | 633 | { |
626 | - if($this->_dependencies===null) |
|
627 | - $this->_dependencies=new TCacheDependencyList; |
|
634 | + if($this->_dependencies===null) { |
|
635 | + $this->_dependencies=new TCacheDependencyList; |
|
636 | + } |
|
628 | 637 | return $this->_dependencies; |
629 | 638 | } |
630 | 639 | |
@@ -638,9 +647,10 @@ discard block |
||
638 | 647 | { |
639 | 648 | if($this->_dependencies!==null) |
640 | 649 | { |
641 | - foreach($this->_dependencies as $dependency) |
|
642 | - if($dependency->getHasChanged()) |
|
650 | + foreach($this->_dependencies as $dependency) { |
|
651 | + if($dependency->getHasChanged()) |
|
643 | 652 | return true; |
653 | + } |
|
644 | 654 | } |
645 | 655 | return false; |
646 | 656 | } |
@@ -701,10 +711,11 @@ discard block |
||
701 | 711 | */ |
702 | 712 | public function insertAt($index,$item) |
703 | 713 | { |
704 | - if($item instanceof ICacheDependency) |
|
705 | - parent::insertAt($index,$item); |
|
706 | - else |
|
707 | - throw new TInvalidDataTypeException('cachedependencylist_cachedependency_required'); |
|
714 | + if($item instanceof ICacheDependency) { |
|
715 | + parent::insertAt($index,$item); |
|
716 | + } else { |
|
717 | + throw new TInvalidDataTypeException('cachedependencylist_cachedependency_required'); |
|
718 | + } |
|
708 | 719 | } |
709 | 720 | } |
710 | 721 |
@@ -93,6 +93,7 @@ discard block |
||
93 | 93 | |
94 | 94 | /** |
95 | 95 | * @param boolean whether the keys are case-sensitive. |
96 | + * @param boolean $value |
|
96 | 97 | */ |
97 | 98 | public function setCaseSensitive($value) |
98 | 99 | { |
@@ -126,6 +127,7 @@ discard block |
||
126 | 127 | * Removes an item from the map by its key. |
127 | 128 | * This overrides the parent implementation by converting the key to lower case first if CaseSensitive is false. |
128 | 129 | * @param mixed the key of the item to be removed |
130 | + * @param string $key |
|
129 | 131 | * @return mixed the removed value, null if no such key exists. |
130 | 132 | */ |
131 | 133 | public function remove($key) |
@@ -149,6 +151,7 @@ discard block |
||
149 | 151 | * This method overrides parent implementation by returning true |
150 | 152 | * if the collection contains the named key. |
151 | 153 | * @param string the property name |
154 | + * @param string $name |
|
152 | 155 | * @return boolean whether the property is defined |
153 | 156 | */ |
154 | 157 | public function hasProperty($name) |
@@ -161,6 +164,7 @@ discard block |
||
161 | 164 | * This method overrides parent implementation by returning true |
162 | 165 | * if the collection contains the named key. |
163 | 166 | * @param string the property name |
167 | + * @param string $name |
|
164 | 168 | * @return boolean whether the property can be read |
165 | 169 | */ |
166 | 170 | public function canGetProperty($name) |
@@ -173,6 +177,7 @@ discard block |
||
173 | 177 | * This method overrides parent implementation by always returning true |
174 | 178 | * because you can always add a new value to the collection. |
175 | 179 | * @param string the property name |
180 | + * @param string $name |
|
176 | 181 | * @return boolean true |
177 | 182 | */ |
178 | 183 | public function canSetProperty($name) |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | */ |
43 | 43 | class TAttributeCollection extends TMap |
44 | 44 | { |
45 | - private $_caseSensitive=false; |
|
45 | + private $_caseSensitive = false; |
|
46 | 46 | |
47 | 47 | /** |
48 | 48 | * Returns an array with the names of all variables of this object that should NOT be serialized |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | protected function __getZappableSleepProps(&$exprops) |
54 | 54 | { |
55 | 55 | parent::__getZappableSleepProps($exprops); |
56 | - if ($this->_caseSensitive===false) |
|
56 | + if ($this->_caseSensitive === false) |
|
57 | 57 | $exprops[] = "\0TAttributeCollection\0_caseSensitive"; |
58 | 58 | } |
59 | 59 | |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | */ |
68 | 68 | public function __get($name) |
69 | 69 | { |
70 | - return $this->contains($name)?$this->itemAt($name):parent::__get($name); |
|
70 | + return $this->contains($name) ? $this->itemAt($name) : parent::__get($name); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -78,9 +78,9 @@ discard block |
||
78 | 78 | * @param mixed the property value or event handler |
79 | 79 | * @throws TInvalidOperationException If the property is not defined or read-only. |
80 | 80 | */ |
81 | - public function __set($name,$value) |
|
81 | + public function __set($name, $value) |
|
82 | 82 | { |
83 | - $this->add($name,$value); |
|
83 | + $this->add($name, $value); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | */ |
97 | 97 | public function setCaseSensitive($value) |
98 | 98 | { |
99 | - $this->_caseSensitive=TPropertyValue::ensureBoolean($value); |
|
99 | + $this->_caseSensitive = TPropertyValue::ensureBoolean($value); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | */ |
108 | 108 | public function itemAt($key) |
109 | 109 | { |
110 | - return parent::itemAt($this->_caseSensitive?$key:strtolower($key)); |
|
110 | + return parent::itemAt($this->_caseSensitive ? $key : strtolower($key)); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | |
@@ -117,9 +117,9 @@ discard block |
||
117 | 117 | * @param mixed key |
118 | 118 | * @param mixed value |
119 | 119 | */ |
120 | - public function add($key,$value) |
|
120 | + public function add($key, $value) |
|
121 | 121 | { |
122 | - parent::add($this->_caseSensitive?$key:strtolower($key),$value); |
|
122 | + parent::add($this->_caseSensitive ? $key : strtolower($key), $value); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | */ |
131 | 131 | public function remove($key) |
132 | 132 | { |
133 | - return parent::remove($this->_caseSensitive?$key:strtolower($key)); |
|
133 | + return parent::remove($this->_caseSensitive ? $key : strtolower($key)); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | */ |
142 | 142 | public function contains($key) |
143 | 143 | { |
144 | - return parent::contains($this->_caseSensitive?$key:strtolower($key)); |
|
144 | + return parent::contains($this->_caseSensitive ? $key : strtolower($key)); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
@@ -53,8 +53,9 @@ |
||
53 | 53 | protected function __getZappableSleepProps(&$exprops) |
54 | 54 | { |
55 | 55 | parent::__getZappableSleepProps($exprops); |
56 | - if ($this->_caseSensitive===false) |
|
57 | - $exprops[] = "\0TAttributeCollection\0_caseSensitive"; |
|
56 | + if ($this->_caseSensitive===false) { |
|
57 | + $exprops[] = "\0TAttributeCollection\0_caseSensitive"; |
|
58 | + } |
|
58 | 59 | } |
59 | 60 | |
60 | 61 | /** |
@@ -31,6 +31,7 @@ |
||
31 | 31 | /** |
32 | 32 | * Constructor. |
33 | 33 | * @param integer number of (virtual) items in the data source. |
34 | + * @param integer $count |
|
34 | 35 | */ |
35 | 36 | public function __construct($count) |
36 | 37 | { |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function __construct($count) |
36 | 36 | { |
37 | - $this->_count=$count; |
|
37 | + $this->_count = $count; |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -88,8 +88,8 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public function __construct($count) |
90 | 90 | { |
91 | - $this->_count=$count; |
|
92 | - $this->_index=0; |
|
91 | + $this->_count = $count; |
|
92 | + $this->_index = 0; |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function rewind() |
100 | 100 | { |
101 | - $this->_index=0; |
|
101 | + $this->_index = 0; |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | */ |
138 | 138 | public function valid() |
139 | 139 | { |
140 | - return $this->_index<$this->_count; |
|
140 | + return $this->_index < $this->_count; |
|
141 | 141 | } |
142 | 142 | } |
143 | 143 |
@@ -75,6 +75,7 @@ discard block |
||
75 | 75 | |
76 | 76 | /** |
77 | 77 | * @param boolean whether this list is read-only or not |
78 | + * @param boolean $value |
|
78 | 79 | */ |
79 | 80 | protected function setReadOnly($value) |
80 | 81 | { |
@@ -277,7 +278,7 @@ discard block |
||
277 | 278 | * Finds the base item. If found, the item is inserted after it. |
278 | 279 | * @param mixed the base item which comes before the second parameter when added to the list |
279 | 280 | * @param mixed the item |
280 | - * @return int the index where the item is inserted |
|
281 | + * @return double the index where the item is inserted |
|
281 | 282 | * @throws TInvalidDataValueException if the base item is not within this list |
282 | 283 | * @throws TInvalidOperationException if the list is read-only |
283 | 284 | * @since 3.2a |
@@ -369,6 +370,8 @@ discard block |
||
369 | 370 | * This method is required by the interface ArrayAccess. |
370 | 371 | * @param integer the offset to set item |
371 | 372 | * @param mixed the item value |
373 | + * @param null|integer $offset |
|
374 | + * @param integer $item |
|
372 | 375 | */ |
373 | 376 | public function offsetSet($offset,$item) |
374 | 377 | { |
@@ -385,6 +388,7 @@ discard block |
||
385 | 388 | * Unsets the item at the specified offset. |
386 | 389 | * This method is required by the interface ArrayAccess. |
387 | 390 | * @param integer the offset to unset item |
391 | + * @param integer $offset |
|
388 | 392 | */ |
389 | 393 | public function offsetUnset($offset) |
390 | 394 | { |
@@ -34,22 +34,22 @@ discard block |
||
34 | 34 | * @package System.Collections |
35 | 35 | * @since 3.0 |
36 | 36 | */ |
37 | -class TList extends TComponent implements IteratorAggregate,ArrayAccess,Countable |
|
37 | +class TList extends TComponent implements IteratorAggregate, ArrayAccess, Countable |
|
38 | 38 | { |
39 | 39 | /** |
40 | 40 | * internal data storage |
41 | 41 | * @var array |
42 | 42 | */ |
43 | - private $_d=array(); |
|
43 | + private $_d = array(); |
|
44 | 44 | /** |
45 | 45 | * number of items |
46 | 46 | * @var integer |
47 | 47 | */ |
48 | - private $_c=0; |
|
48 | + private $_c = 0; |
|
49 | 49 | /** |
50 | 50 | * @var boolean whether this list is read-only |
51 | 51 | */ |
52 | - private $_r=false; |
|
52 | + private $_r = false; |
|
53 | 53 | |
54 | 54 | /** |
55 | 55 | * Constructor. |
@@ -58,9 +58,9 @@ discard block |
||
58 | 58 | * @param boolean whether the list is read-only |
59 | 59 | * @throws TInvalidDataTypeException If data is not null and neither an array nor an iterator. |
60 | 60 | */ |
61 | - public function __construct($data=null,$readOnly=false) |
|
61 | + public function __construct($data = null, $readOnly = false) |
|
62 | 62 | { |
63 | - if($data!==null) |
|
63 | + if ($data !== null) |
|
64 | 64 | $this->copyFrom($data); |
65 | 65 | $this->setReadOnly($readOnly); |
66 | 66 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | */ |
79 | 79 | protected function setReadOnly($value) |
80 | 80 | { |
81 | - $this->_r=TPropertyValue::ensureBoolean($value); |
|
81 | + $this->_r = TPropertyValue::ensureBoolean($value); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public function getIterator() |
90 | 90 | { |
91 | - return new ArrayIterator( $this->_d ); |
|
91 | + return new ArrayIterator($this->_d); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -118,10 +118,10 @@ discard block |
||
118 | 118 | */ |
119 | 119 | public function itemAt($index) |
120 | 120 | { |
121 | - if($index>=0 && $index<$this->_c) |
|
121 | + if ($index >= 0 && $index < $this->_c) |
|
122 | 122 | return $this->_d[$index]; |
123 | 123 | else |
124 | - throw new TInvalidDataValueException('list_index_invalid',$index); |
|
124 | + throw new TInvalidDataValueException('list_index_invalid', $index); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | */ |
133 | 133 | public function add($item) |
134 | 134 | { |
135 | - $this->insertAt($this->_c,$item); |
|
136 | - return $this->_c-1; |
|
135 | + $this->insertAt($this->_c, $item); |
|
136 | + return $this->_c - 1; |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
@@ -145,22 +145,22 @@ discard block |
||
145 | 145 | * @throws TInvalidDataValueException If the index specified exceeds the bound |
146 | 146 | * @throws TInvalidOperationException if the list is read-only |
147 | 147 | */ |
148 | - public function insertAt($index,$item) |
|
148 | + public function insertAt($index, $item) |
|
149 | 149 | { |
150 | - if(!$this->_r) |
|
150 | + if (!$this->_r) |
|
151 | 151 | { |
152 | - if($index===$this->_c) |
|
153 | - $this->_d[$this->_c++]=$item; |
|
154 | - else if($index>=0 && $index<$this->_c) |
|
152 | + if ($index === $this->_c) |
|
153 | + $this->_d[$this->_c++] = $item; |
|
154 | + else if ($index >= 0 && $index < $this->_c) |
|
155 | 155 | { |
156 | - array_splice($this->_d,$index,0,array($item)); |
|
156 | + array_splice($this->_d, $index, 0, array($item)); |
|
157 | 157 | $this->_c++; |
158 | 158 | } |
159 | 159 | else |
160 | - throw new TInvalidDataValueException('list_index_invalid',$index); |
|
160 | + throw new TInvalidDataValueException('list_index_invalid', $index); |
|
161 | 161 | } |
162 | 162 | else |
163 | - throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
163 | + throw new TInvalidOperationException('list_readonly', get_class($this)); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
@@ -174,9 +174,9 @@ discard block |
||
174 | 174 | */ |
175 | 175 | public function remove($item) |
176 | 176 | { |
177 | - if(!$this->_r) |
|
177 | + if (!$this->_r) |
|
178 | 178 | { |
179 | - if(($index=$this->indexOf($item))>=0) |
|
179 | + if (($index = $this->indexOf($item)) >= 0) |
|
180 | 180 | { |
181 | 181 | $this->removeAt($index); |
182 | 182 | return $index; |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | throw new TInvalidDataValueException('list_item_inexistent'); |
186 | 186 | } |
187 | 187 | else |
188 | - throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
188 | + throw new TInvalidOperationException('list_readonly', get_class($this)); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
@@ -197,25 +197,25 @@ discard block |
||
197 | 197 | */ |
198 | 198 | public function removeAt($index) |
199 | 199 | { |
200 | - if(!$this->_r) |
|
200 | + if (!$this->_r) |
|
201 | 201 | { |
202 | - if($index>=0 && $index<$this->_c) |
|
202 | + if ($index >= 0 && $index < $this->_c) |
|
203 | 203 | { |
204 | 204 | $this->_c--; |
205 | - if($index===$this->_c) |
|
205 | + if ($index === $this->_c) |
|
206 | 206 | return array_pop($this->_d); |
207 | 207 | else |
208 | 208 | { |
209 | - $item=$this->_d[$index]; |
|
210 | - array_splice($this->_d,$index,1); |
|
209 | + $item = $this->_d[$index]; |
|
210 | + array_splice($this->_d, $index, 1); |
|
211 | 211 | return $item; |
212 | 212 | } |
213 | 213 | } |
214 | 214 | else |
215 | - throw new TInvalidDataValueException('list_index_invalid',$index); |
|
215 | + throw new TInvalidDataValueException('list_index_invalid', $index); |
|
216 | 216 | } |
217 | 217 | else |
218 | - throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
218 | + throw new TInvalidOperationException('list_readonly', get_class($this)); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | */ |
225 | 225 | public function clear() |
226 | 226 | { |
227 | - for($i=$this->_c-1;$i>=0;--$i) |
|
227 | + for ($i = $this->_c - 1; $i >= 0; --$i) |
|
228 | 228 | $this->removeAt($i); |
229 | 229 | } |
230 | 230 | |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | */ |
235 | 235 | public function contains($item) |
236 | 236 | { |
237 | - return $this->indexOf($item)>=0; |
|
237 | + return $this->indexOf($item) >= 0; |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | */ |
244 | 244 | public function indexOf($item) |
245 | 245 | { |
246 | - if(($index=array_search($item,$this->_d,true))===false) |
|
246 | + if (($index = array_search($item, $this->_d, true)) === false) |
|
247 | 247 | return -1; |
248 | 248 | else |
249 | 249 | return $index; |
@@ -260,9 +260,9 @@ discard block |
||
260 | 260 | */ |
261 | 261 | public function insertBefore($baseitem, $item) |
262 | 262 | { |
263 | - if(!$this->_r) |
|
263 | + if (!$this->_r) |
|
264 | 264 | { |
265 | - if(($index = $this->indexOf($baseitem)) == -1) |
|
265 | + if (($index = $this->indexOf($baseitem)) == -1) |
|
266 | 266 | throw new TInvalidDataValueException('list_item_inexistent'); |
267 | 267 | |
268 | 268 | $this->insertAt($index, $item); |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | return $index; |
271 | 271 | } |
272 | 272 | else |
273 | - throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
273 | + throw new TInvalidOperationException('list_readonly', get_class($this)); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | /** |
@@ -284,9 +284,9 @@ discard block |
||
284 | 284 | */ |
285 | 285 | public function insertAfter($baseitem, $item) |
286 | 286 | { |
287 | - if(!$this->_r) |
|
287 | + if (!$this->_r) |
|
288 | 288 | { |
289 | - if(($index = $this->indexOf($baseitem)) == -1) |
|
289 | + if (($index = $this->indexOf($baseitem)) == -1) |
|
290 | 290 | throw new TInvalidDataValueException('list_item_inexistent'); |
291 | 291 | |
292 | 292 | $this->insertAt($index + 1, $item); |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | return $index + 1; |
295 | 295 | } |
296 | 296 | else |
297 | - throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
297 | + throw new TInvalidOperationException('list_readonly', get_class($this)); |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | /** |
@@ -313,14 +313,14 @@ discard block |
||
313 | 313 | */ |
314 | 314 | public function copyFrom($data) |
315 | 315 | { |
316 | - if(is_array($data) || ($data instanceof Traversable)) |
|
316 | + if (is_array($data) || ($data instanceof Traversable)) |
|
317 | 317 | { |
318 | - if($this->_c>0) |
|
318 | + if ($this->_c > 0) |
|
319 | 319 | $this->clear(); |
320 | - foreach($data as $item) |
|
320 | + foreach ($data as $item) |
|
321 | 321 | $this->add($item); |
322 | 322 | } |
323 | - else if($data!==null) |
|
323 | + else if ($data !== null) |
|
324 | 324 | throw new TInvalidDataTypeException('list_data_not_iterable'); |
325 | 325 | } |
326 | 326 | |
@@ -332,12 +332,12 @@ discard block |
||
332 | 332 | */ |
333 | 333 | public function mergeWith($data) |
334 | 334 | { |
335 | - if(is_array($data) || ($data instanceof Traversable)) |
|
335 | + if (is_array($data) || ($data instanceof Traversable)) |
|
336 | 336 | { |
337 | - foreach($data as $item) |
|
337 | + foreach ($data as $item) |
|
338 | 338 | $this->add($item); |
339 | 339 | } |
340 | - else if($data!==null) |
|
340 | + else if ($data !== null) |
|
341 | 341 | throw new TInvalidDataTypeException('list_data_not_iterable'); |
342 | 342 | } |
343 | 343 | |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | */ |
350 | 350 | public function offsetExists($offset) |
351 | 351 | { |
352 | - return ($offset>=0 && $offset<$this->_c); |
|
352 | + return ($offset >= 0 && $offset < $this->_c); |
|
353 | 353 | } |
354 | 354 | |
355 | 355 | /** |
@@ -370,14 +370,14 @@ discard block |
||
370 | 370 | * @param integer the offset to set item |
371 | 371 | * @param mixed the item value |
372 | 372 | */ |
373 | - public function offsetSet($offset,$item) |
|
373 | + public function offsetSet($offset, $item) |
|
374 | 374 | { |
375 | - if($offset===null || $offset===$this->_c) |
|
376 | - $this->insertAt($this->_c,$item); |
|
375 | + if ($offset === null || $offset === $this->_c) |
|
376 | + $this->insertAt($this->_c, $item); |
|
377 | 377 | else |
378 | 378 | { |
379 | 379 | $this->removeAt($offset); |
380 | - $this->insertAt($offset,$item); |
|
380 | + $this->insertAt($offset, $item); |
|
381 | 381 | } |
382 | 382 | } |
383 | 383 | |
@@ -427,9 +427,9 @@ discard block |
||
427 | 427 | */ |
428 | 428 | public function __construct(&$data) |
429 | 429 | { |
430 | - $this->_d=&$data; |
|
431 | - $this->_i=0; |
|
432 | - $this->_c=count($this->_d); |
|
430 | + $this->_d = &$data; |
|
431 | + $this->_i = 0; |
|
432 | + $this->_c = count($this->_d); |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | /** |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | */ |
439 | 439 | public function rewind() |
440 | 440 | { |
441 | - $this->_i=0; |
|
441 | + $this->_i = 0; |
|
442 | 442 | } |
443 | 443 | |
444 | 444 | /** |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | */ |
478 | 478 | public function valid() |
479 | 479 | { |
480 | - return $this->_i<$this->_c; |
|
480 | + return $this->_i < $this->_c; |
|
481 | 481 | } |
482 | 482 | } |
483 | 483 |
@@ -60,8 +60,9 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function __construct($data=null,$readOnly=false) |
62 | 62 | { |
63 | - if($data!==null) |
|
64 | - $this->copyFrom($data); |
|
63 | + if($data!==null) { |
|
64 | + $this->copyFrom($data); |
|
65 | + } |
|
65 | 66 | $this->setReadOnly($readOnly); |
66 | 67 | } |
67 | 68 | |
@@ -118,10 +119,11 @@ discard block |
||
118 | 119 | */ |
119 | 120 | public function itemAt($index) |
120 | 121 | { |
121 | - if($index>=0 && $index<$this->_c) |
|
122 | - return $this->_d[$index]; |
|
123 | - else |
|
124 | - throw new TInvalidDataValueException('list_index_invalid',$index); |
|
122 | + if($index>=0 && $index<$this->_c) { |
|
123 | + return $this->_d[$index]; |
|
124 | + } else { |
|
125 | + throw new TInvalidDataValueException('list_index_invalid',$index); |
|
126 | + } |
|
125 | 127 | } |
126 | 128 | |
127 | 129 | /** |
@@ -149,18 +151,18 @@ discard block |
||
149 | 151 | { |
150 | 152 | if(!$this->_r) |
151 | 153 | { |
152 | - if($index===$this->_c) |
|
153 | - $this->_d[$this->_c++]=$item; |
|
154 | - else if($index>=0 && $index<$this->_c) |
|
154 | + if($index===$this->_c) { |
|
155 | + $this->_d[$this->_c++]=$item; |
|
156 | + } else if($index>=0 && $index<$this->_c) |
|
155 | 157 | { |
156 | 158 | array_splice($this->_d,$index,0,array($item)); |
157 | 159 | $this->_c++; |
160 | + } else { |
|
161 | + throw new TInvalidDataValueException('list_index_invalid',$index); |
|
158 | 162 | } |
159 | - else |
|
160 | - throw new TInvalidDataValueException('list_index_invalid',$index); |
|
163 | + } else { |
|
164 | + throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
161 | 165 | } |
162 | - else |
|
163 | - throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
164 | 166 | } |
165 | 167 | |
166 | 168 | /** |
@@ -180,12 +182,12 @@ discard block |
||
180 | 182 | { |
181 | 183 | $this->removeAt($index); |
182 | 184 | return $index; |
185 | + } else { |
|
186 | + throw new TInvalidDataValueException('list_item_inexistent'); |
|
183 | 187 | } |
184 | - else |
|
185 | - throw new TInvalidDataValueException('list_item_inexistent'); |
|
188 | + } else { |
|
189 | + throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
186 | 190 | } |
187 | - else |
|
188 | - throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
189 | 191 | } |
190 | 192 | |
191 | 193 | /** |
@@ -202,20 +204,20 @@ discard block |
||
202 | 204 | if($index>=0 && $index<$this->_c) |
203 | 205 | { |
204 | 206 | $this->_c--; |
205 | - if($index===$this->_c) |
|
206 | - return array_pop($this->_d); |
|
207 | - else |
|
207 | + if($index===$this->_c) { |
|
208 | + return array_pop($this->_d); |
|
209 | + } else |
|
208 | 210 | { |
209 | 211 | $item=$this->_d[$index]; |
210 | 212 | array_splice($this->_d,$index,1); |
211 | 213 | return $item; |
212 | 214 | } |
215 | + } else { |
|
216 | + throw new TInvalidDataValueException('list_index_invalid',$index); |
|
213 | 217 | } |
214 | - else |
|
215 | - throw new TInvalidDataValueException('list_index_invalid',$index); |
|
218 | + } else { |
|
219 | + throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
216 | 220 | } |
217 | - else |
|
218 | - throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
219 | 221 | } |
220 | 222 | |
221 | 223 | /** |
@@ -224,8 +226,9 @@ discard block |
||
224 | 226 | */ |
225 | 227 | public function clear() |
226 | 228 | { |
227 | - for($i=$this->_c-1;$i>=0;--$i) |
|
228 | - $this->removeAt($i); |
|
229 | + for($i=$this->_c-1;$i>=0;--$i) { |
|
230 | + $this->removeAt($i); |
|
231 | + } |
|
229 | 232 | } |
230 | 233 | |
231 | 234 | /** |
@@ -243,10 +246,11 @@ discard block |
||
243 | 246 | */ |
244 | 247 | public function indexOf($item) |
245 | 248 | { |
246 | - if(($index=array_search($item,$this->_d,true))===false) |
|
247 | - return -1; |
|
248 | - else |
|
249 | - return $index; |
|
249 | + if(($index=array_search($item,$this->_d,true))===false) { |
|
250 | + return -1; |
|
251 | + } else { |
|
252 | + return $index; |
|
253 | + } |
|
250 | 254 | } |
251 | 255 | |
252 | 256 | /** |
@@ -262,15 +266,16 @@ discard block |
||
262 | 266 | { |
263 | 267 | if(!$this->_r) |
264 | 268 | { |
265 | - if(($index = $this->indexOf($baseitem)) == -1) |
|
266 | - throw new TInvalidDataValueException('list_item_inexistent'); |
|
269 | + if(($index = $this->indexOf($baseitem)) == -1) { |
|
270 | + throw new TInvalidDataValueException('list_item_inexistent'); |
|
271 | + } |
|
267 | 272 | |
268 | 273 | $this->insertAt($index, $item); |
269 | 274 | |
270 | 275 | return $index; |
276 | + } else { |
|
277 | + throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
271 | 278 | } |
272 | - else |
|
273 | - throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
274 | 279 | } |
275 | 280 | |
276 | 281 | /** |
@@ -286,15 +291,16 @@ discard block |
||
286 | 291 | { |
287 | 292 | if(!$this->_r) |
288 | 293 | { |
289 | - if(($index = $this->indexOf($baseitem)) == -1) |
|
290 | - throw new TInvalidDataValueException('list_item_inexistent'); |
|
294 | + if(($index = $this->indexOf($baseitem)) == -1) { |
|
295 | + throw new TInvalidDataValueException('list_item_inexistent'); |
|
296 | + } |
|
291 | 297 | |
292 | 298 | $this->insertAt($index + 1, $item); |
293 | 299 | |
294 | 300 | return $index + 1; |
301 | + } else { |
|
302 | + throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
295 | 303 | } |
296 | - else |
|
297 | - throw new TInvalidOperationException('list_readonly',get_class($this)); |
|
298 | 304 | } |
299 | 305 | |
300 | 306 | /** |
@@ -315,13 +321,15 @@ discard block |
||
315 | 321 | { |
316 | 322 | if(is_array($data) || ($data instanceof Traversable)) |
317 | 323 | { |
318 | - if($this->_c>0) |
|
319 | - $this->clear(); |
|
320 | - foreach($data as $item) |
|
321 | - $this->add($item); |
|
324 | + if($this->_c>0) { |
|
325 | + $this->clear(); |
|
326 | + } |
|
327 | + foreach($data as $item) { |
|
328 | + $this->add($item); |
|
329 | + } |
|
330 | + } else if($data!==null) { |
|
331 | + throw new TInvalidDataTypeException('list_data_not_iterable'); |
|
322 | 332 | } |
323 | - else if($data!==null) |
|
324 | - throw new TInvalidDataTypeException('list_data_not_iterable'); |
|
325 | 333 | } |
326 | 334 | |
327 | 335 | /** |
@@ -334,11 +342,12 @@ discard block |
||
334 | 342 | { |
335 | 343 | if(is_array($data) || ($data instanceof Traversable)) |
336 | 344 | { |
337 | - foreach($data as $item) |
|
338 | - $this->add($item); |
|
345 | + foreach($data as $item) { |
|
346 | + $this->add($item); |
|
347 | + } |
|
348 | + } else if($data!==null) { |
|
349 | + throw new TInvalidDataTypeException('list_data_not_iterable'); |
|
339 | 350 | } |
340 | - else if($data!==null) |
|
341 | - throw new TInvalidDataTypeException('list_data_not_iterable'); |
|
342 | 351 | } |
343 | 352 | |
344 | 353 | /** |
@@ -372,9 +381,9 @@ discard block |
||
372 | 381 | */ |
373 | 382 | public function offsetSet($offset,$item) |
374 | 383 | { |
375 | - if($offset===null || $offset===$this->_c) |
|
376 | - $this->insertAt($this->_c,$item); |
|
377 | - else |
|
384 | + if($offset===null || $offset===$this->_c) { |
|
385 | + $this->insertAt($this->_c,$item); |
|
386 | + } else |
|
378 | 387 | { |
379 | 388 | $this->removeAt($offset); |
380 | 389 | $this->insertAt($offset,$item); |