Only changes to function indexes, comments and stripping of trailing whitespace in...
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_tsparser.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2004 Kasper Skaarhoj (kasper@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Contains the TypoScript parser class
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
32 *
33 * @author Kasper Skaarhoj <kasper@typo3.com>
34 */
35 /**
36 * [CLASS/FUNCTION INDEX of SCRIPT]
37 *
38 *
39 *
40 * 80: class t3lib_TSparser
41 * 132: function parse($string,$matchObj='')
42 * 169: function nextDivider()
43 * 185: function parseSub(&$setup)
44 * 331: function rollParseSub($string,&$setup)
45 * 355: function getVal($string,$setup)
46 * 381: function setVal($string,&$setup,$value,$wipeOut=0)
47 * 416: function error($err,$num=2)
48 * 428: function checkIncludeLines($string)
49 * 472: function checkIncludeLines_array($array)
50 *
51 * SECTION: Syntax highlighting
52 * 515: function doSyntaxHighlight($string,$lineNum='',$highlightBlockMode=0)
53 * 536: function regHighLight($code,$pointer,$strlen=-1)
54 * 554: function syntaxHighlight_print($lineNumDat,$highlightBlockMode)
55 *
56 * TOTAL FUNCTIONS: 12
57 * (This index is automatically created/updated by the extension "extdeveval")
58 *
59 */
60
61
62
63
64
65
66
67
68
69
70
71
72 /**
73 * The TypoScript parser
74 *
75 * @author Kasper Skaarhoj <kasper@typo3.com>
76 * @package TYPO3
77 * @subpackage t3lib
78 * @see t3lib_tstemplate, t3lib_matchcondition, t3lib_BEfunc::getPagesTSconfig(), t3lib_userAuthGroup::fetchGroupData(), t3lib_TStemplate::generateConfig()
79 */
80 class t3lib_TSparser {
81 var $strict = 1; // If set, then key names cannot contain characters other than [:alnum:]_\.-
82
83 // Internal
84 var $setup = Array(); // TypoScript hierarchy being build during parsing.
85 var $raw; // raw data, the input string exploded by chr(10)
86 var $rawP; // pointer to entry in raw data array
87 var $lastComment=''; // Holding the value of the last comment
88 var $commentSet=0; // Internally set, used as internal flag to create a multi-line comment (one of those like /*... */)
89 var $multiLineEnabled=0; // Internally set, when multiline value is accumulated
90 var $multiLineObject=''; // Internally set, when multiline value is accumulated
91 var $multiLineValue=array(); // Internally set, when multiline value is accumulated
92 var $inBrace = 0; // Internally set, when in brace. Counter.
93 var $lastConditionTrue = 1; // For each condition this flag is set, if the condition is true, else it's cleared. Then it's used by the [ELSE] condition to determine if the next part should be parsed.
94 var $sections=array(); // Tracking all conditions found
95 var $sectionsMatch=array(); // Tracking all matching conditions found
96 var $syntaxHighLight = 0; // If set, then syntax highlight mode is on; Call the function syntaxHighlight() to use this function
97 var $highLightData=array(); // Syntax highlight data is accumulated in this array. Used by syntaxHighlight_print() to construct the output.
98 var $highLightData_bracelevel = array(); // Syntax highlight data keeping track of the curly brace level for each line
99
100 // Debugging, analysis:
101 var $regComments = 0; // DO NOT register the comments. This is default for the ordinary sitetemplate!
102 var $errors=array(); // Error accumulation array.
103 var $lineNumberOffset=0; // Used for the error messages line number reporting. Set externally.
104 var $breakPointLN=0; // Line for break point.
105 var $highLightStyles=array(
106 'prespace' => array('<span class="ts-prespace">','</span>'), // Space before any content on a line
107 'objstr_postspace' => array('<span class="ts-objstr_postspace">','</span>'), // Space after the object string on a line
108 'operator_postspace' => array('<span class="ts-operator_postspace">','</span>'), // Space after the operator on a line
109 'operator' => array('<span class="ts-operator">','</span>'), // The operator char
110 'value' => array('<span class="ts-value">','</span>'), // The value of a line
111 'objstr' => array('<span class="ts-objstr">','</span>'), // The object string of a line
112 'value_copy' => array('<span class="ts-value_copy">','</span>'), // The value when the copy syntax (<) is used; that means the object reference
113 'value_unset' => array('<span class="ts-value_unset">','</span>'), // The value when an object is unset. Should not exist.
114 'ignored' => array('<span class="ts-ignored">','</span>'), // The "rest" of a line which will be ignored.
115 'default' => array('<span class="ts-default">','</span>'), // The default style if none other is applied.
116 'comment' => array('<span class="ts-comment">','</span>'), // Comment lines
117 'condition' => array('<span class="ts-condition">','</span>'), // Conditions
118 'error' => array('<span class="ts-error">','</span>'), // Error messages
119 'linenum' => array('<span class="ts-linenum">','</span>'), // Line numbers
120 );
121 var $highLightBlockStyles = ''; // Additional attributes for the <span> tags for a blockmode line
122 var $highLightBlockStyles_basecolor = '#cccccc'; // The hex-HTML color for the blockmode
123
124
125 /**
126 * Start parsing the input TypoScript text piece. The result is stored in $this->setup
127 *
128 * @param string The TypoScript text
129 * @param object If is object (instance of t3lib_matchcondition), then this is used to match conditions found in the TypoScript code. If matchObj not specified, then no conditions will work! (Except [GLOBAL])
130 * @return void
131 */
132 function parse($string,$matchObj='') {
133 $this->raw = explode(chr(10),$string);
134 $this->rawP = 0;
135
136 $pre = '[GLOBAL]';
137 while($pre) {
138 if ($this->breakPointLN && $pre=='[_BREAK]') {
139 $this->error('Breakpoint at '.($this->lineNumberOffset+$this->rawP-2).': Line content was "'.$this->raw[$this->rawP-2].'"',1);
140 break;
141 }
142
143 if (strtoupper($pre)=='[GLOBAL]' || strtoupper($pre)=='[END]' || (!$this->lastConditionTrue && strtoupper($pre)=='[ELSE]')) {
144 $pre = trim($this->parseSub($this->setup));
145 $this->lastConditionTrue=1;
146 } else {
147 if (strtoupper($pre)!='[ELSE]') {$this->sections[md5($pre)]=$pre;} // we're in a specific section. Therefore we log this section
148 if ((is_object($matchObj) && $matchObj->match($pre)) || $this->syntaxHighLight) {
149 if (strtoupper($pre)!='[ELSE]') {$this->sectionsMatch[md5($pre)]=$pre;}
150 $pre = trim($this->parseSub($this->setup));
151 $this->lastConditionTrue=1;
152 } else {
153 $pre = trim($this->nextDivider());
154 $this->lastConditionTrue=0;
155 }
156 }
157 }
158 if ($this->inBrace) {$this->error('Line '.($this->lineNumberOffset+$this->rawP-1).': The script is short of '.$this->inBrace.' end brace(s)',1); }
159 if ($this->multiLineEnabled) {$this->error('Line '.($this->lineNumberOffset+$this->rawP-1).': A multiline value section is not ended with a parenthesis!',1); }
160 $this->lineNumberOffset+=count($this->raw)+1;
161 }
162
163 /**
164 * Will search for the next condition. When found it will return the line content (the condition value) and have advanced the internal $this->rawP pointer to point to the next line after the condition.
165 *
166 * @return string The condition value
167 * @see parse()
168 */
169 function nextDivider() {
170 while (isset($this->raw[$this->rawP])) {
171 $line = ltrim($this->raw[$this->rawP]);
172 $this->rawP++;
173 if ($line && substr($line,0,1)=='[') {
174 return $line;
175 }
176 }
177 }
178
179 /**
180 * Parsing the $this->raw TypoScript lines from pointer, $this->rawP
181 *
182 * @param array Reference to the setup array in which to accumulate the values.
183 * @return string Returns the string of the condition found, the exit signal or possible nothing (if it completed parsing with no interruptions)
184 */
185 function parseSub(&$setup) {
186 while (isset($this->raw[$this->rawP])) {
187 $line = ltrim($this->raw[$this->rawP]);
188 $lineP = $this->rawP;
189 $this->rawP++;
190 if ($this->syntaxHighLight) $this->regHighLight("prespace",$lineP,strlen($line));
191
192 // Breakpoint?
193 if ($this->breakPointLN && ($this->lineNumberOffset+$this->rawP-1)==($this->breakPointLN+1)) { // by adding 1 we get that line processed
194 return '[_BREAK]';
195 }
196
197 // Set comment flag?
198 if (!$this->multiLineEnabled && substr($line,0,2)=='/*') {
199 $this->commentSet=1;
200 }
201
202 if (!$this->commentSet && ($line || $this->multiLineEnabled)) { // If $this->multiLineEnabled we will go and get the line values here because we know, the first if() will be true.
203 if ($this->multiLineEnabled) { // If multiline is enabled. Escape by ')'
204 if (substr($line,0,1)==')') { // Multiline ends...
205 if ($this->syntaxHighLight) $this->regHighLight("operator",$lineP,strlen($line)-1);
206 $this->multiLineEnabled=0; // Disable multiline
207 $theValue = implode($this->multiLineValue,chr(10));
208 if (strstr($this->multiLineObject,'.')) {
209 $this->setVal($this->multiLineObject,$setup,array($theValue)); // Set the value deeper.
210 } else {
211 $setup[$this->multiLineObject] = $theValue; // Set value regularly
212 if ($this->lastComment && $this->regComments) {
213 $setup[$this->multiLineObject.'..'].=$this->lastComment;
214 }
215 }
216 } else{
217 if ($this->syntaxHighLight) $this->regHighLight("value",$lineP);
218 $this->multiLineValue[]=$this->raw[($this->rawP-1)];
219 }
220 } elseif ($this->inBrace==0 && substr($line,0,1)=='[') { // Beginning of condition (only on level zero compared to brace-levels
221 if ($this->syntaxHighLight) $this->regHighLight("condition",$lineP);
222 return $line;
223 } else {
224 if (substr($line,0,1)=='[' && strtoupper(trim($line))=='[GLOBAL]') { // Return if GLOBAL condition is set - no matter what.
225 if ($this->syntaxHighLight) $this->regHighLight("condition",$lineP);
226 $this->error('Line '.($this->lineNumberOffset+$this->rawP-1).': On return to [GLOBAL] scope, the script was short of '.$this->inBrace.' end brace(s)',1);
227 $this->inBrace=0;
228 return $line;
229 } elseif (strcspn($line,'}#/')!=0) { // If not brace-end or comment
230 $varL = strcspn($line,' {=<>('); // Find object name string until we meet an operator VER2: Added '>'!!
231 $objStrName=trim(substr($line,0,$varL));
232 if ($this->syntaxHighLight) $this->regHighLight("objstr",$lineP,strlen(substr($line,$varL)));
233 if ($objStrName) {
234 if ($this->strict && eregi('[^[:alnum:]_\.-]',$objStrName,$r)) {
235 $this->error('Line '.($this->lineNumberOffset+$this->rawP-1).': Object Name String, "'.htmlspecialchars($objStrName).'" contains invalid character "'.$r[0].'". Must be alphanumeric or one of: "_-."');
236 } else {
237 $line = ltrim(substr($line,$varL));
238 if ($this->syntaxHighLight) {
239 $this->regHighLight("objstr_postspace", $lineP, strlen($line));
240 if (strlen($line)>0) {
241 $this->regHighLight("operator", $lineP, strlen($line)-1);
242 $this->regHighLight("operator_postspace", $lineP, strlen(ltrim(substr($line,1))));
243 }
244 }
245 switch(substr($line,0,1)) {
246 case '=':
247 if ($this->syntaxHighLight) $this->regHighLight("value", $lineP, strlen(ltrim(substr($line,1)))-strlen(trim(substr($line,1))));
248 if (strstr($objStrName,'.')) {
249 $value = Array();
250 $value[0] = trim(substr($line,1));
251 $this->setVal($objStrName,$setup,$value);
252 } else {
253 $setup[$objStrName] = trim(substr($line,1));
254 if ($this->lastComment && $this->regComments) { // Setting comment..
255 $setup[$objStrName.'..'].=$this->lastComment;
256 }
257 }
258 break;
259 case '{':
260 $this->inBrace++;
261 if (strstr($objStrName,'.')) {
262 $exitSig=$this->rollParseSub($objStrName,$setup);
263 if ($exitSig) return $exitSig;
264 } else {
265 if (!isset($setup[$objStrName.'.'])) {$setup[$objStrName.'.'] = Array();}
266 $exitSig=$this->parseSub($setup[$objStrName.'.']);
267 if ($exitSig) return $exitSig;
268 }
269 break;
270 case '(':
271 $this->multiLineObject = $objStrName;
272 $this->multiLineEnabled=1;
273 $this->multiLineValue=array();
274 break;
275 case '<':
276 if ($this->syntaxHighLight) $this->regHighLight("value_copy", $lineP, strlen(ltrim(substr($line,1)))-strlen(trim(substr($line,1))));
277 $theVal = trim(substr($line,1));
278 if (substr($theVal,0,1)=='.') {
279 $res = $this->getVal(substr($theVal,1),$setup);
280 } else {
281 $res = $this->getVal($theVal,$this->setup);
282 }
283 $this->setVal($objStrName,$setup,unserialize(serialize($res)),1);
284 break;
285 case '>':
286 if ($this->syntaxHighLight) $this->regHighLight("value_unset", $lineP, strlen(ltrim(substr($line,1)))-strlen(trim(substr($line,1))));
287 $this->setVal($objStrName,$setup,'UNSET');
288 break;
289 default:
290 $this->error('Line '.($this->lineNumberOffset+$this->rawP-1).': Object Name String, "'.htmlspecialchars($objStrName).'" was not preceeded by any operator, =<>({');
291 break;
292 }
293 }
294 $this->lastComment='';
295 }
296 } elseif (substr($line,0,1)=='}') {
297 $this->inBrace--;
298 $this->lastComment='';
299 if ($this->syntaxHighLight) $this->regHighLight("operator", $lineP, strlen($line)-1);
300 if ($this->inBrace<0) {
301 $this->error('Line '.($this->lineNumberOffset+$this->rawP-1).': An end brace is in excess.',1);
302 $this->inBrace=0;
303 } else {
304 break;
305 }
306 } else {
307 if ($this->syntaxHighLight) $this->regHighLight("comment", $lineP);
308
309 // Comment. The comments are concatenated in this temporary string:
310 if ($this->regComments) $this->lastComment.= trim($line).chr(10);
311 }
312 }
313 }
314
315 // Unset comment
316 if ($this->commentSet) {
317 if ($this->syntaxHighLight) $this->regHighLight("comment", $lineP);
318 if (substr($line,0,2)=='*/') $this->commentSet=0;
319 }
320 }
321 }
322
323 /**
324 * Parsing of TypoScript keys inside a curly brace where the key is composite of at least two keys, thus having to recursively call itself to get the value
325 *
326 * @param string The object sub-path, eg "thisprop.another_prot"
327 * @param array The local setup array from the function calling this function
328 * @return string Returns the exitSignal
329 * @see parseSub()
330 */
331 function rollParseSub($string,&$setup) {
332 if ((string)$string!='') {
333 $keyLen = strcspn($string,'.');
334 if ($keyLen==strlen($string)) {
335 $key = $string.'.';
336 if (!isset($setup[$key])){$setup[$key]=Array();}
337 $exitSig=$this->parseSub($setup[$key]);
338 if ($exitSig) return $exitSig;
339 } else {
340 $key = substr($string,0,$keyLen).'.';
341 if (!isset($setup[$key])){$setup[$key]=Array();}
342 $exitSig=$this->rollParseSub(substr($string,$keyLen+1),$setup[$key]);
343 if ($exitSig) return $exitSig;
344 }
345 }
346 }
347
348 /**
349 * Get a value/property pair for an object path in TypoScript, eg. "myobject.myvalue.mysubproperty". Here: Used by the "copy" operator, <
350 *
351 * @param string Object path for which to get the value
352 * @param array Global setup code if $string points to a global object path. But if string is prefixed with "." then its the local setup array.
353 * @return array An array with keys 0/1 being value/property respectively
354 */
355 function getVal($string,$setup) {
356 if ((string)$string!='') {
357 $keyLen = strcspn($string,'.');
358 if ($keyLen==strlen($string)) {
359 $retArr=array(); // Added 6/6/03. Shouldn't hurt
360 if (isset($setup[$string])) {$retArr[0]=$setup[$string]; }
361 if (isset($setup[$string.'.'])) {$retArr[1]=$setup[$string.'.']; }
362 return $retArr;
363 } else {
364 $key = substr($string,0,$keyLen).'.';
365 if ($setup[$key]) {
366 return $this->getVal(substr($string,$keyLen+1),$setup[$key]);
367 }
368 }
369 }
370 }
371
372 /**
373 * Setting a value/property of an object string in the setup array.
374 *
375 * @param string The object sub-path, eg "thisprop.another_prot"
376 * @param array The local setup array from the function calling this function.
377 * @param array The value/property pair array to set. If only one of them is set, then the other is not touched (unless $wipeOut is set, which it is when copies are made which must include both value and property)
378 * @param boolean If set, then both value and property is wiped out when a copy is made of another value.
379 * @return void
380 */
381 function setVal($string,&$setup,$value,$wipeOut=0) {
382 if ((string)$string!='') {
383 $keyLen = strcspn($string,'.');
384 if ($keyLen==strlen($string)) {
385 if ($value=='UNSET') {
386 unset($setup[$string]);
387 unset($setup[$string.'.']);
388 } else {
389 if ($wipeOut && $this->strict) {
390 if ((isset($setup[$string]) && !isset($value[0])) || (isset($setup[$string.'.']) && !isset($value[1]))) {$this->error('Line '.($this->lineNumberOffset+$this->rawP-1).': Object copied in this line "'.trim($this->raw[($this->rawP-1)]).'" would leave either the value or properties untouched in TypoScript Version 1. Please check that this is not a problem for you.',1);}
391 unset($setup[$string]);
392 unset($setup[$string.'.']);
393 }
394 if (isset($value[0])) {$setup[$string] = $value[0];}
395 if (isset($value[1])) {$setup[$string.'.'] = $value[1];}
396 if ($this->lastComment && $this->regComments) {
397 $setup[$string.'..'].=$this->lastComment;
398 }
399 }
400 } else {
401 $key = substr($string,0,$keyLen).'.';
402 if (!isset($setup[$key])){$setup[$key]=Array();}
403 $this->setVal(substr($string,$keyLen+1),$setup[$key],$value);
404 }
405 }
406 }
407
408 /**
409 * Stacks errors/messages from the TypoScript parser into an internal array, $this->error
410 * If "TT" is a global object (as it is in the frontend when backend users are logged in) the message will be registered here as well.
411 *
412 * @param string The error message string
413 * @param integer The error severity (in the scale of $GLOBALS['TT']->setTSlogMessage: Approx: 2=warning, 1=info, 0=nothing, 3=fatal.)
414 * @return void
415 */
416 function error($err,$num=2) {
417 if (is_object($GLOBALS['TT'])) $GLOBALS['TT']->setTSlogMessage($err,$num);
418 $this->errors[]=array($err,$num,$this->rawP-1,$this->lineNumberOffset);
419 }
420
421 /**
422 * Checks the input string (un-parsed TypoScript) for include-commands ("<INCLUDE_TYPOSCRIPT: ....")
423 * Use: t3lib_TSparser::checkIncludeLines()
424 *
425 * @param string Unparsed TypoScript
426 * @return string Complete TypoScript with includes added.
427 */
428 function checkIncludeLines($string) {
429 $splitStr='<INCLUDE_TYPOSCRIPT:';
430 if (strstr($string,$splitStr)) {
431 $newString='';
432 $allParts = explode($splitStr,chr(10).$string.chr(10)); // adds line break char before/after
433 reset($allParts);
434 while(list($c,$v)=each($allParts)) {
435 if (!$c) { // first goes through
436 $newString.=$v;
437 } elseif (ereg("\r?\n[ ]*$",$allParts[$c-1])) { // There must be a line-break char before.
438 $subparts=explode('>',$v,2);
439 if (ereg("^[ ]*\r?\n",$subparts[1])) { // There must be a line-break char after
440 // SO, the include was positively recognized:
441 $newString.='### '.$splitStr.$subparts[0].'> BEGIN:'.chr(10);
442 $params = t3lib_div::get_tag_attributes($subparts[0]);
443 if ($params['source']) {
444 $sourceParts = explode(':',$params['source'],2);
445 switch(strtolower(trim($sourceParts[0]))) {
446 case 'file':
447 $filename = t3lib_div::getFileAbsFileName(trim($sourceParts[1]));
448 if (strcmp($filename,'')) { // Must exist and must not contain '..' and must be relative
449 if (@is_file($filename) && filesize($filename)<100000) { // Max. 100 KB include files!
450 $newString.=t3lib_div::getUrl($filename).chr(10);
451 }
452 }
453 break;
454 }
455 }
456 $newString.='### '.$splitStr.$subparts[0].'> END:'.chr(10);
457 $newString.=$subparts[1];
458 } else $newString.=$splitStr.$v;
459 } else $newString.=$splitStr.$v;
460 }
461 $string=substr($newString,1,-1); // not the first/last linebreak char.
462 }
463 return $string;
464 }
465
466 /**
467 * Parses the string in each value of the input array for include-commands
468 *
469 * @param array Array with TypoScript in each value
470 * @return array Same array but where the values has been parsed for include-commands
471 */
472 function checkIncludeLines_array($array) {
473 reset($array);
474 while(list($k)=each($array)) {
475 $array[$k]=t3lib_TSparser::checkIncludeLines($array[$k]);
476 }
477 return $array;
478 }
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500 /**********************************
501 *
502 * Syntax highlighting
503 *
504 *********************************/
505
506 /**
507 * Syntax highlight a TypoScript text
508 * Will parse the content. Remember, the internal setup array may contain INvalid parsed content since conditions are ignored!
509 *
510 * @param string The TypoScript text
511 * @param mixed If blank, linenumbers are NOT printed. If array then the first key is the linenumber offset to add to the internal counter.
512 * @param boolean If set, then the highlighted output will be formatted in blocks based on the brace levels. prespace will be ignored and empty lines represented with a single no-break-space.
513 * @return string HTML code for the syntax highlighted string
514 */
515 function doSyntaxHighlight($string,$lineNum='',$highlightBlockMode=0) {
516 $this->syntaxHighLight=1;
517 $this->highLightData=array();
518 $this->error=array();
519 $string = str_replace(chr(13),'',$string); // This is done in order to prevent empty <span>..</span> sections around chr(13) content. Should not do anything but help lessen the amount of HTML code.
520
521 $this->parse($string);
522
523 return $this->syntaxHighlight_print($lineNum,$highlightBlockMode);
524 }
525
526 /**
527 * Registers a part of a TypoScript line for syntax highlighting.
528 *
529 * @param string Key from the internal array $this->highLightStyles
530 * @param integer Pointer to the line in $this->raw which this is about
531 * @param integer The number of chars LEFT on this line before the end is reached.
532 * @return void
533 * @access private
534 * @see parse()
535 */
536 function regHighLight($code,$pointer,$strlen=-1) {
537 if ($strlen==-1) {
538 $this->highLightData[$pointer] = array(array($code,0));
539 } else {
540 $this->highLightData[$pointer][] = array($code,$strlen);
541 }
542 $this->highLightData_bracelevel[$pointer] = $this->inBrace;
543 }
544
545 /**
546 * Formatting the TypoScript code in $this->raw based on the data collected by $this->regHighLight in $this->highLightData
547 *
548 * @param mixed If blank, linenumbers are NOT printed. If array then the first key is the linenumber offset to add to the internal counter.
549 * @param boolean If set, then the highlighted output will be formatted in blocks based on the brace levels. prespace will be ignored and empty lines represented with a single no-break-space.
550 * @return string HTML content
551 * @access private
552 * @see doSyntaxHighlight()
553 */
554 function syntaxHighlight_print($lineNumDat,$highlightBlockMode) {
555 // Registers all error messages in relation to their linenumber
556 $errA=array();
557 foreach($this->errors as $err) {
558 $errA[$err[2]][]=$err[0];
559 }
560 // Generates the syntax highlighted output:
561 $lines=array();
562 foreach($this->raw as $rawP => $value) {
563 $start=0;
564 $strlen=strlen($value);
565 $lineC='';
566
567 if (is_array($this->highLightData[$rawP])) {
568 foreach($this->highLightData[$rawP] as $set) {
569 $len = $strlen-$start-$set[1];
570 if ($len > 0) {
571 $part = substr($value,$start,$len);
572 $start+=$len;
573 $st = $this->highLightStyles[(isset($this->highLightStyles[$set[0]])?$set[0]:'default')];
574 if (!$highlightBlockMode || $set[0]!='prespace') $lineC.=$st[0].htmlspecialchars($part).$st[1];
575 }elseif ($len < 0) debug(array($len,$value,$rawP));
576 }
577 } else debug(array($value));
578
579 if (strlen(substr($value,$start))) $lineC.=$this->highLightStyles['ignored'][0].htmlspecialchars(substr($value,$start)).$this->highLightStyles['ignored'][1];
580
581 if ($errA[$rawP]) {
582 $lineC.=$this->highLightStyles['error'][0].'<strong> - ERROR:</strong> '.htmlspecialchars(implode(';',$errA[$rawP])).$this->highLightStyles['error'][1];
583 }
584
585 if ($highlightBlockMode && $this->highLightData_bracelevel[$rawP]) {
586 $lineC = str_pad('',$this->highLightData_bracelevel[$rawP]*2,' ',STR_PAD_LEFT).'<span style="'.$this->highLightBlockStyles.($this->highLightBlockStyles_basecolor?'background-color: '.t3lib_div::modifyHTMLColorAll($this->highLightBlockStyles_basecolor,-$this->highLightData_bracelevel[$rawP]*16):'').'">'.(strcmp($lineC,'')?$lineC:'&nbsp;').'</span>';
587 }
588
589 if (is_array($lineNumDat)) {
590 $lineNum = $rawP+$lineNumDat[0];
591 $lineC = $this->highLightStyles['linenum'][0].str_pad($lineNum,4,' ',STR_PAD_LEFT).':'.$this->highLightStyles['linenum'][1].' '.$lineC;
592 }
593
594
595 $lines[] = $lineC;
596 }
597
598 return '<pre class="ts-hl">'.implode(chr(10),$lines).'</pre>';
599 }
600 }
601
602
603 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsparser.php']) {
604 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsparser.php']);
605 }
606 ?>