[BUGFIX] Unused TDParams in ColumnsContentObject()
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / TypoScript / Parser / TypoScriptParser.php
1 <?php
2 namespace TYPO3\CMS\Core\TypoScript\Parser;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29 use TYPO3\CMS\Core\Utility\GeneralUtility;
30 use \TYPO3\CMS\Core\Utility\PathUtility;
31
32 /**
33 * The TypoScript parser
34 *
35 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
36 */
37 class TypoScriptParser {
38
39 // If set, then key names cannot contain characters other than [:alnum:]_\.-
40 /**
41 * @todo Define visibility
42 */
43 public $strict = 1;
44
45 // Internal
46 // TypoScript hierarchy being build during parsing.
47 /**
48 * @todo Define visibility
49 */
50 public $setup = array();
51
52 // Raw data, the input string exploded by LF
53 /**
54 * @todo Define visibility
55 */
56 public $raw;
57
58 // Pointer to entry in raw data array
59 /**
60 * @todo Define visibility
61 */
62 public $rawP;
63
64 // Holding the value of the last comment
65 /**
66 * @todo Define visibility
67 */
68 public $lastComment = '';
69
70 // Internally set, used as internal flag to create a multi-line comment (one of those like /*... */)
71 /**
72 * @todo Define visibility
73 */
74 public $commentSet = 0;
75
76 // Internally set, when multiline value is accumulated
77 /**
78 * @todo Define visibility
79 */
80 public $multiLineEnabled = 0;
81
82 // Internally set, when multiline value is accumulated
83 /**
84 * @todo Define visibility
85 */
86 public $multiLineObject = '';
87
88 // Internally set, when multiline value is accumulated
89 /**
90 * @todo Define visibility
91 */
92 public $multiLineValue = array();
93
94 // Internally set, when in brace. Counter.
95 /**
96 * @todo Define visibility
97 */
98 public $inBrace = 0;
99
100 // 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.
101 /**
102 * @todo Define visibility
103 */
104 public $lastConditionTrue = 1;
105
106 // Tracking all conditions found
107 /**
108 * @todo Define visibility
109 */
110 public $sections = array();
111
112 // Tracking all matching conditions found
113 /**
114 * @todo Define visibility
115 */
116 public $sectionsMatch = array();
117
118 // If set, then syntax highlight mode is on; Call the function syntaxHighlight() to use this function
119 /**
120 * @todo Define visibility
121 */
122 public $syntaxHighLight = 0;
123
124 // Syntax highlight data is accumulated in this array. Used by syntaxHighlight_print() to construct the output.
125 /**
126 * @todo Define visibility
127 */
128 public $highLightData = array();
129
130 // Syntax highlight data keeping track of the curly brace level for each line
131 /**
132 * @todo Define visibility
133 */
134 public $highLightData_bracelevel = array();
135
136 // Debugging, analysis:
137 // DO NOT register the comments. This is default for the ordinary sitetemplate!
138 /**
139 * @todo Define visibility
140 */
141 public $regComments = 0;
142
143 // DO NOT register the linenumbers. This is default for the ordinary sitetemplate!
144 /**
145 * @todo Define visibility
146 */
147 public $regLinenumbers = 0;
148
149 // Error accumulation array.
150 /**
151 * @todo Define visibility
152 */
153 public $errors = array();
154
155 // Used for the error messages line number reporting. Set externally.
156 /**
157 * @todo Define visibility
158 */
159 public $lineNumberOffset = 0;
160
161 // Line for break point.
162 /**
163 * @todo Define visibility
164 */
165 public $breakPointLN = 0;
166
167 /**
168 * @todo Define visibility
169 */
170 public $highLightStyles = array(
171 'prespace' => array('<span class="ts-prespace">', '</span>'),
172 // Space before any content on a line
173 'objstr_postspace' => array('<span class="ts-objstr_postspace">', '</span>'),
174 // Space after the object string on a line
175 'operator_postspace' => array('<span class="ts-operator_postspace">', '</span>'),
176 // Space after the operator on a line
177 'operator' => array('<span class="ts-operator">', '</span>'),
178 // The operator char
179 'value' => array('<span class="ts-value">', '</span>'),
180 // The value of a line
181 'objstr' => array('<span class="ts-objstr">', '</span>'),
182 // The object string of a line
183 'value_copy' => array('<span class="ts-value_copy">', '</span>'),
184 // The value when the copy syntax (<) is used; that means the object reference
185 'value_unset' => array('<span class="ts-value_unset">', '</span>'),
186 // The value when an object is unset. Should not exist.
187 'ignored' => array('<span class="ts-ignored">', '</span>'),
188 // The "rest" of a line which will be ignored.
189 'default' => array('<span class="ts-default">', '</span>'),
190 // The default style if none other is applied.
191 'comment' => array('<span class="ts-comment">', '</span>'),
192 // Comment lines
193 'condition' => array('<span class="ts-condition">', '</span>'),
194 // Conditions
195 'error' => array('<span class="ts-error">', '</span>'),
196 // Error messages
197 'linenum' => array('<span class="ts-linenum">', '</span>')
198 );
199
200 // Additional attributes for the <span> tags for a blockmode line
201 /**
202 * @todo Define visibility
203 */
204 public $highLightBlockStyles = '';
205
206 // The hex-HTML color for the blockmode
207 /**
208 * @todo Define visibility
209 */
210 public $highLightBlockStyles_basecolor = '#cccccc';
211
212 //Instance of parentObject, used by \TYPO3\CMS\Core\TypoScript\ExtendedTemplateService
213 public $parentObject;
214
215 /**
216 * Start parsing the input TypoScript text piece. The result is stored in $this->setup
217 *
218 * @param string $string The TypoScript text
219 * @param object|string $matchObj If is object, then this is used to match conditions found in the TypoScript code. If matchObj not specified, then no conditions will work! (Except [GLOBAL])
220 *
221 * @return void
222 * @todo Define visibility
223 */
224 public function parse($string, $matchObj = '') {
225 $this->raw = explode(LF, $string);
226 $this->rawP = 0;
227 $pre = '[GLOBAL]';
228 while ($pre) {
229 if ($this->breakPointLN && $pre === '[_BREAK]') {
230 $this->error('Breakpoint at ' . ($this->lineNumberOffset + $this->rawP - 2) . ': Line content was "' . $this->raw[($this->rawP - 2)] . '"', 1);
231 break;
232 }
233 $preUppercase = strtoupper($pre);
234 if ($pre{0} === '[' &&
235 ($preUppercase === '[GLOBAL]' ||
236 $preUppercase === '[END]' ||
237 !$this->lastConditionTrue && $preUppercase === '[ELSE]')
238 ) {
239 $pre = trim($this->parseSub($this->setup));
240 $this->lastConditionTrue = 1;
241 } else {
242 // We're in a specific section. Therefore we log this section
243 $specificSection = $preUppercase !== '[ELSE]';
244 if ($specificSection) {
245 $this->sections[md5($pre)] = $pre;
246 }
247 if (is_object($matchObj) && $matchObj->match($pre) || $this->syntaxHighLight) {
248 if ($specificSection) {
249 $this->sectionsMatch[md5($pre)] = $pre;
250 }
251 $pre = trim($this->parseSub($this->setup));
252 $this->lastConditionTrue = 1;
253 } else {
254 $pre = $this->nextDivider();
255 $this->lastConditionTrue = 0;
256 }
257 }
258 }
259 if ($this->inBrace) {
260 $this->error('Line ' . ($this->lineNumberOffset + $this->rawP - 1) . ': The script is short of ' . $this->inBrace . ' end brace(s)', 1);
261 }
262 if ($this->multiLineEnabled) {
263 $this->error('Line ' . ($this->lineNumberOffset + $this->rawP - 1) . ': A multiline value section is not ended with a parenthesis!', 1);
264 }
265 $this->lineNumberOffset += count($this->raw) + 1;
266 }
267
268 /**
269 * 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.
270 *
271 * @return string The condition value
272 * @see parse()
273 * @todo Define visibility
274 */
275 public function nextDivider() {
276 while (isset($this->raw[$this->rawP])) {
277 $line = trim($this->raw[$this->rawP]);
278 $this->rawP++;
279 if ($line && $line{0} === '[') {
280 return $line;
281 }
282 }
283 }
284
285 /**
286 * Parsing the $this->raw TypoScript lines from pointer, $this->rawP
287 *
288 * @param array $setup Reference to the setup array in which to accumulate the values.
289 * @return string|NULL Returns the string of the condition found, the exit signal or possible nothing (if it completed parsing with no interruptions)
290 * @todo Define visibility
291 */
292 public function parseSub(array &$setup) {
293 while (isset($this->raw[$this->rawP])) {
294 $line = ltrim($this->raw[$this->rawP]);
295 $lineP = $this->rawP;
296 $this->rawP++;
297 if ($this->syntaxHighLight) {
298 $this->regHighLight('prespace', $lineP, strlen($line));
299 }
300 // Breakpoint?
301 // By adding 1 we get that line processed
302 if ($this->breakPointLN && $this->lineNumberOffset + $this->rawP - 1 === $this->breakPointLN + 1) {
303 return '[_BREAK]';
304 }
305 // Set comment flag?
306 if (!$this->multiLineEnabled && strpos($line, '/*') === 0) {
307 $this->commentSet = 1;
308 }
309 // If $this->multiLineEnabled we will go and get the line values here because we know, the first if() will be TRUE.
310 if (!$this->commentSet && ($line || $this->multiLineEnabled)) {
311 // If multiline is enabled. Escape by ')'
312 if ($this->multiLineEnabled) {
313 // Multiline ends...
314 if ($line{0} === ')') {
315 if ($this->syntaxHighLight) {
316 $this->regHighLight('operator', $lineP, strlen($line) - 1);
317 }
318 // Disable multiline
319 $this->multiLineEnabled = 0;
320 $theValue = implode($this->multiLineValue, LF);
321 if (strpos($this->multiLineObject, '.') !== FALSE) {
322 // Set the value deeper.
323 $this->setVal($this->multiLineObject, $setup, array($theValue));
324 } else {
325 // Set value regularly
326 $setup[$this->multiLineObject] = $theValue;
327 if ($this->lastComment && $this->regComments) {
328 $setup[$this->multiLineObject . '..'] .= $this->lastComment;
329 }
330 if ($this->regLinenumbers) {
331 $setup[$this->multiLineObject . '.ln..'][] = $this->lineNumberOffset + $this->rawP - 1;
332 }
333 }
334 } else {
335 if ($this->syntaxHighLight) {
336 $this->regHighLight('value', $lineP);
337 }
338 $this->multiLineValue[] = $this->raw[$this->rawP - 1];
339 }
340 } elseif ($this->inBrace === 0 && $line{0} === '[') {
341 // Beginning of condition (only on level zero compared to brace-levels
342 if ($this->syntaxHighLight) {
343 $this->regHighLight('condition', $lineP);
344 }
345 return $line;
346 } else {
347 // Return if GLOBAL condition is set - no matter what.
348 if ($line{0} === '[' && stripos($line, '[GLOBAL]') !== FALSE) {
349 if ($this->syntaxHighLight) {
350 $this->regHighLight('condition', $lineP);
351 }
352 $this->error('Line ' . ($this->lineNumberOffset + $this->rawP - 1) . ': On return to [GLOBAL] scope, the script was short of ' . $this->inBrace . ' end brace(s)', 1);
353 $this->inBrace = 0;
354 return $line;
355 } elseif ($line{0} !== '}' && $line{0} !== '#' && $line{0} !== '/') {
356 // If not brace-end or comment
357 // Find object name string until we meet an operator
358 $varL = strcspn($line, TAB . ' {=<>:(');
359 // also remove tabs after the object string name
360 $objStrName = substr($line, 0, $varL);
361 if ($this->syntaxHighLight) {
362 $this->regHighLight('objstr', $lineP, strlen(substr($line, $varL)));
363 }
364 if ($objStrName !== '') {
365 $r = array();
366 if ($this->strict && preg_match('/[^[:alnum:]_\\\\\\.-]/i', $objStrName, $r)) {
367 $this->error('Line ' . ($this->lineNumberOffset + $this->rawP - 1) . ': Object Name String, "' . htmlspecialchars($objStrName) . '" contains invalid character "' . $r[0] . '". Must be alphanumeric or one of: "_-\\."');
368 } else {
369 $line = ltrim(substr($line, $varL));
370 if ($this->syntaxHighLight) {
371 $this->regHighLight('objstr_postspace', $lineP, strlen($line));
372 if ($line !== '') {
373 $this->regHighLight('operator', $lineP, strlen($line) - 1);
374 $this->regHighLight('operator_postspace', $lineP, strlen(ltrim(substr($line, 1))));
375 }
376 }
377 if ($line === '') {
378 $this->error('Line ' . ($this->lineNumberOffset + $this->rawP - 1) . ': Object Name String, "' . htmlspecialchars($objStrName) . '" was not followed by any operator, =<>({');
379 } else {
380 // Checking for special TSparser properties (to change TS values at parsetime)
381 $match = array();
382 if ($line{0} === ':' && preg_match('/^:=\\s*([^\\(]+)\\s*\\((.*)\\).*/', $line, $match)) {
383 $tsFunc = $match[1];
384 $tsFuncArg = $match[2];
385 list($currentValue) = $this->getVal($objStrName, $setup);
386 $tsFuncArg = str_replace(array('\\\\', '\\n', '\\t'), array('\\', LF, TAB), $tsFuncArg);
387 $newValue = $this->executeValueModifier($tsFunc, $tsFuncArg, $currentValue);
388 if (isset($newValue)) {
389 $line = '= ' . $newValue;
390 }
391 }
392 switch ($line{0}) {
393 case '=':
394 if ($this->syntaxHighLight) {
395 $this->regHighLight('value', $lineP, strlen(ltrim(substr($line, 1))) - strlen(trim(substr($line, 1))));
396 }
397 if (strpos($objStrName, '.') !== FALSE) {
398 $value = array();
399 $value[0] = trim(substr($line, 1));
400 $this->setVal($objStrName, $setup, $value);
401 } else {
402 $setup[$objStrName] = trim(substr($line, 1));
403 if ($this->lastComment && $this->regComments) {
404 // Setting comment..
405 $setup[$objStrName . '..'] .= $this->lastComment;
406 }
407 if ($this->regLinenumbers) {
408 $setup[$objStrName . '.ln..'][] = $this->lineNumberOffset + $this->rawP - 1;
409 }
410 }
411 break;
412 case '{':
413 $this->inBrace++;
414 if (strpos($objStrName, '.') !== FALSE) {
415 $exitSig = $this->rollParseSub($objStrName, $setup);
416 if ($exitSig) {
417 return $exitSig;
418 }
419 } else {
420 if (!isset($setup[($objStrName . '.')])) {
421 $setup[$objStrName . '.'] = array();
422 }
423 $exitSig = $this->parseSub($setup[$objStrName . '.']);
424 if ($exitSig) {
425 return $exitSig;
426 }
427 }
428 break;
429 case '(':
430 $this->multiLineObject = $objStrName;
431 $this->multiLineEnabled = 1;
432 $this->multiLineValue = array();
433 break;
434 case '<':
435 if ($this->syntaxHighLight) {
436 $this->regHighLight('value_copy', $lineP, strlen(ltrim(substr($line, 1))) - strlen(trim(substr($line, 1))));
437 }
438 $theVal = trim(substr($line, 1));
439 if ($theVal{0} === '.') {
440 $res = $this->getVal(substr($theVal, 1), $setup);
441 } else {
442 $res = $this->getVal($theVal, $this->setup);
443 }
444 $this->setVal($objStrName, $setup, unserialize(serialize($res)), 1);
445 // unserialize(serialize(...)) may look stupid but is needed because of some reference issues. See Kaspers reply to "[TYPO3-core] good question" from December 15 2005.
446 break;
447 case '>':
448 if ($this->syntaxHighLight) {
449 $this->regHighLight('value_unset', $lineP, strlen(ltrim(substr($line, 1))) - strlen(trim(substr($line, 1))));
450 }
451 $this->setVal($objStrName, $setup, 'UNSET');
452 break;
453 default:
454 $this->error('Line ' . ($this->lineNumberOffset + $this->rawP - 1) . ': Object Name String, "' . htmlspecialchars($objStrName) . '" was not followed by any operator, =<>({');
455 }
456 }
457 }
458 $this->lastComment = '';
459 }
460 } elseif ($line{0} === '}') {
461 $this->inBrace--;
462 $this->lastComment = '';
463 if ($this->syntaxHighLight) {
464 $this->regHighLight('operator', $lineP, strlen($line) - 1);
465 }
466 if ($this->inBrace < 0) {
467 $this->error('Line ' . ($this->lineNumberOffset + $this->rawP - 1) . ': An end brace is in excess.', 1);
468 $this->inBrace = 0;
469 } else {
470 break;
471 }
472 } else {
473 if ($this->syntaxHighLight) {
474 $this->regHighLight('comment', $lineP);
475 }
476 // Comment. The comments are concatenated in this temporary string:
477 if ($this->regComments) {
478 $this->lastComment .= rtrim($line) . LF;
479 }
480 }
481 }
482 }
483 // Unset comment
484 if ($this->commentSet) {
485 if ($this->syntaxHighLight) {
486 $this->regHighLight('comment', $lineP);
487 }
488 if (strpos($line, '*/') === 0) {
489 $this->commentSet = 0;
490 }
491 }
492 }
493 }
494
495 /**
496 * Executes operator functions, called from TypoScript
497 * example: page.10.value := appendString(!)
498 *
499 * @param string $modifierName TypoScript function called
500 * @param string $modifierArgument Function arguments; In case of multiple arguments, the method must split on its own
501 * @param string $currentValue Current TypoScript value
502 * @return string Modification result
503 */
504 protected function executeValueModifier($modifierName, $modifierArgument = NULL, $currentValue = NULL) {
505 $newValue = NULL;
506 switch ($modifierName) {
507 case 'prependString':
508 $newValue = $modifierArgument . $currentValue;
509 break;
510 case 'appendString':
511 $newValue = $currentValue . $modifierArgument;
512 break;
513 case 'removeString':
514 $newValue = str_replace($modifierArgument, '', $currentValue);
515 break;
516 case 'replaceString':
517 list($fromStr, $toStr) = explode('|', $modifierArgument, 2);
518 $newValue = str_replace($fromStr, $toStr, $currentValue);
519 break;
520 case 'addToList':
521 $newValue = ((string)$currentValue !== '' ? $currentValue . ',' : '') . trim($modifierArgument);
522 break;
523 case 'removeFromList':
524 $existingElements = GeneralUtility::trimExplode(',', $currentValue);
525 $removeElements = GeneralUtility::trimExplode(',', $modifierArgument);
526 if (count($removeElements)) {
527 $newValue = implode(',', array_diff($existingElements, $removeElements));
528 }
529 break;
530 case 'uniqueList':
531 $elements = GeneralUtility::trimExplode(',', $currentValue);
532 $newValue = implode(',', array_unique($elements));
533 break;
534 case 'reverseList':
535 $elements = GeneralUtility::trimExplode(',', $currentValue);
536 $newValue = implode(',', array_reverse($elements));
537 break;
538 case 'sortList':
539 $elements = GeneralUtility::trimExplode(',', $currentValue);
540 $arguments = GeneralUtility::trimExplode(',', $modifierArgument);
541 $arguments = array_map('strtolower', $arguments);
542 $sort_flags = SORT_REGULAR;
543 if (in_array('numeric', $arguments)) {
544 $sort_flags = SORT_NUMERIC;
545 }
546 sort($elements, $sort_flags);
547 if (in_array('descending', $arguments)) {
548 $elements = array_reverse($elements);
549 }
550 $newValue = implode(',', $elements);
551 break;
552 default:
553 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsparser.php']['preParseFunc'][$modifierName])) {
554 $hookMethod = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsparser.php']['preParseFunc'][$modifierName];
555 $params = array('currentValue' => $currentValue, 'functionArgument' => $modifierArgument);
556 $fakeThis = FALSE;
557 $newValue = GeneralUtility::callUserFunction($hookMethod, $params, $fakeThis);
558 } else {
559 GeneralUtility::sysLog(
560 'Missing function definition for ' . $modifierName . ' on TypoScript',
561 'Core',
562 GeneralUtility::SYSLOG_SEVERITY_WARNING
563 );
564 }
565 }
566 return $newValue;
567 }
568
569 /**
570 * 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
571 *
572 * @param string $string The object sub-path, eg "thisprop.another_prot
573 * @param array $setup The local setup array from the function calling this function
574 * @return string Returns the exitSignal
575 * @see parseSub()
576 * @todo Define visibility
577 */
578 public function rollParseSub($string, array &$setup) {
579 if ((string) $string === '') {
580 return '';
581 }
582
583 $key = strstr($string, '.', TRUE);
584 if ($key === FALSE) {
585 $key = $string . '.';
586 if (!isset($setup[$key])) {
587 $setup[$key] = array();
588 }
589 $exitSig = $this->parseSub($setup[$key]);
590 if ($exitSig) {
591 return $exitSig;
592 }
593 } else {
594 $key .= '.';
595 if (!isset($setup[$key])) {
596 $setup[$key] = array();
597 }
598 $exitSig = $this->rollParseSub(substr($string, strlen($key)), $setup[$key]);
599 if ($exitSig) {
600 return $exitSig;
601 }
602 }
603 }
604
605 /**
606 * Get a value/property pair for an object path in TypoScript, eg. "myobject.myvalue.mysubproperty". Here: Used by the "copy" operator, <
607 *
608 * @param string $string Object path for which to get the value
609 * @param array $setup Global setup code if $string points to a global object path. But if string is prefixed with "." then its the local setup array.
610 * @return array An array with keys 0/1 being value/property respectively
611 * @todo Define visibility
612 */
613 public function getVal($string, array $setup) {
614 if ((string) $string === '') {
615 return array();
616 }
617
618 $key = strstr($string, '.', TRUE);
619 if ($key === FALSE) {
620 $retArr = array();
621 if (isset($setup[$string])) {
622 $retArr[0] = $setup[$string];
623 }
624 if (isset($setup[$string . '.'])) {
625 $retArr[1] = $setup[$string . '.'];
626 }
627 return $retArr;
628 } else {
629 $key .= '.';
630 if ($setup[$key]) {
631 return $this->getVal(substr($string, strlen($key)), $setup[$key]);
632 }
633 }
634 }
635
636 /**
637 * Setting a value/property of an object string in the setup array.
638 *
639 * @param string $string The object sub-path, eg "thisprop.another_prot
640 * @param array $setup The local setup array from the function calling this function.
641 * @param array|string $value 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)
642 * @param boolean $wipeOut If set, then both value and property is wiped out when a copy is made of another value.
643 * @return void
644 * @todo Define visibility
645 */
646 public function setVal($string, array &$setup, $value, $wipeOut = FALSE) {
647 if ((string) $string === '') {
648 return;
649 }
650
651 $key = strstr($string, '.', TRUE);
652 if ($key === FALSE) {
653 if ($value === 'UNSET') {
654 unset($setup[$string]);
655 unset($setup[$string . '.']);
656 if ($this->regLinenumbers) {
657 $setup[$string . '.ln..'][] = ($this->lineNumberOffset + $this->rawP - 1) . '>';
658 }
659 } else {
660 $lnRegisDone = 0;
661 if ($wipeOut && $this->strict) {
662 unset($setup[$string]);
663 unset($setup[$string . '.']);
664 if ($this->regLinenumbers) {
665 $setup[$string . '.ln..'][] = ($this->lineNumberOffset + $this->rawP - 1) . '<';
666 $lnRegisDone = 1;
667 }
668 }
669 if (isset($value[0])) {
670 $setup[$string] = $value[0];
671 }
672 if (isset($value[1])) {
673 $setup[$string . '.'] = $value[1];
674 }
675 if ($this->lastComment && $this->regComments) {
676 $setup[$string . '..'] .= $this->lastComment;
677 }
678 if ($this->regLinenumbers && !$lnRegisDone) {
679 $setup[$string . '.ln..'][] = $this->lineNumberOffset + $this->rawP - 1;
680 }
681 }
682 } else {
683 $key .= '.';
684 if (!isset($setup[$key])) {
685 $setup[$key] = array();
686 }
687 $this->setVal(substr($string, strlen($key)), $setup[$key], $value);
688 }
689 }
690
691 /**
692 * Stacks errors/messages from the TypoScript parser into an internal array, $this->error
693 * 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.
694 *
695 * @param string $err The error message string
696 * @param integer $num The error severity (in the scale of $GLOBALS['TT']->setTSlogMessage: Approx: 2=warning, 1=info, 0=nothing, 3=fatal.)
697 * @return void
698 * @todo Define visibility
699 */
700 public function error($err, $num = 2) {
701 if (is_object($GLOBALS['TT'])) {
702 $GLOBALS['TT']->setTSlogMessage($err, $num);
703 }
704 $this->errors[] = array($err, $num, $this->rawP - 1, $this->lineNumberOffset);
705 }
706
707 /**
708 * Checks the input string (un-parsed TypoScript) for include-commands ("<INCLUDE_TYPOSCRIPT: ....")
709 * Use: \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::checkIncludeLines()
710 *
711 * @param string $string Unparsed TypoScript
712 * @param integer $cycle_counter Counter for detecting endless loops
713 * @param boolean $returnFiles When set an array containing the resulting typoscript and all included files will get returned
714 * @param string $parentFilenameOrPath The parent file (with absolute path) or path for relative includes
715 * @return string Complete TypoScript with includes added.
716 * @static
717 */
718 static public function checkIncludeLines($string, $cycle_counter = 1, $returnFiles = FALSE, $parentFilenameOrPath = '') {
719 $includedFiles = array();
720 if ($cycle_counter > 100) {
721 GeneralUtility::sysLog('It appears like TypoScript code is looping over itself. Check your templates for "&lt;INCLUDE_TYPOSCRIPT: ..." tags', 'Core', GeneralUtility::SYSLOG_SEVERITY_WARNING);
722 if ($returnFiles) {
723 return array(
724 'typoscript' => '',
725 'files' => $includedFiles
726 );
727 }
728 return '
729 ###
730 ### ERROR: Recursion!
731 ###
732 ';
733 }
734
735 // If no tags found, no need to do slower preg_split
736 if (strpos($string, '<INCLUDE_TYPOSCRIPT:') !== FALSE) {
737 $splitRegEx = '/\r?\n\s*<INCLUDE_TYPOSCRIPT:\s*(?i)source\s*=\s*"((?i)file|dir):\s*([^"]*)"(.*)>[\ \t]*/';
738 $parts = preg_split($splitRegEx, LF . $string . LF, -1, PREG_SPLIT_DELIM_CAPTURE);
739 // First text part goes through
740 $newString = $parts[0] . LF;
741 $partCount = count($parts);
742 for ($i = 1; $i + 3 < $partCount; $i += 4) {
743 // $parts[$i] contains 'FILE' or 'DIR'
744 // $parts[$i+1] contains relative file or directory path to be included
745 // $parts[$i+2] optional properties of the INCLUDE statement
746 // $parts[$i+3] next part of the typoscript string (part in between include-tags)
747 $includeType = $parts[$i];
748 $filename = $parts[$i + 1];
749 $originalFilename = $filename;
750 $optionalProperties = $parts[$i + 2];
751 $tsContentsTillNextInclude = $parts[$i + 3];
752
753 // Resolve a possible relative paths if a parent file is given
754 if ($parentFilenameOrPath !== '' && GeneralUtility::isFirstPartOfStr($filename, '.')) {
755 $filename = PathUtility::getAbsolutePathOfRelativeReferencedFileOrPath($parentFilenameOrPath, $filename);
756 }
757
758 // There must be a line-break char after - not sure why this check is necessary, kept it for being 100% backwards compatible
759 // An empty string is also ok (means that the next line is also a valid include_typoscript tag)
760 if (!preg_match('/(^\\s*\\r?\\n|^$)/', $tsContentsTillNextInclude)) {
761 $newString .= self::typoscriptIncludeError('Invalid characters after <INCLUDE_TYPOSCRIPT: source="' . $includeType . ':' . $filename . '">-tag (rest of line must be empty).');
762 } elseif (strpos('..', $filename) !== FALSE) {
763 $newString .= self::typoscriptIncludeError('Invalid filepath "' . $filename . '" (containing "..").');
764 } else {
765 switch (strtolower($includeType)) {
766 case 'file':
767 self::includeFile($originalFilename, $cycle_counter, $returnFiles, $newString, $includedFiles, $optionalProperties, $parentFilenameOrPath);
768 break;
769 case 'dir':
770 self::includeDirectory($originalFilename, $cycle_counter, $returnFiles, $newString, $includedFiles, $optionalProperties, $parentFilenameOrPath);
771 break;
772 default:
773 $newString .= self::typoscriptIncludeError('No valid option for INCLUDE_TYPOSCRIPT source property (valid options are FILE or DIR)');
774 }
775 }
776 // Prepend next normal (not file) part to output string
777 $newString .= $tsContentsTillNextInclude . LF;
778
779 // load default TypoScript for content rendering templates like
780 // css_styled_content if those have been included through f.e.
781 // <INCLUDE_TYPOSCRIPT: source="FILE:EXT:css_styled_content/static/setup.txt">
782 $filePointer = strtolower($filename);
783 if (GeneralUtility::isFirstPartOfStr($filePointer, 'ext:')) {
784 $filePointerPathParts = explode('/', substr($filePointer, 4));
785
786 // remove file part, determine whether to load setup or constants
787 list($includeType, ) = explode('.', array_pop($filePointerPathParts));
788
789 if (in_array($includeType, array('setup', 'constants'))) {
790 // adapt extension key to required format (no underscores)
791 $filePointerPathParts[0] = str_replace('_', '', $filePointerPathParts[0]);
792
793 // load default TypoScript
794 $defaultTypoScriptKey = implode('/', $filePointerPathParts) . '/';
795 if (isset($GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_' . $includeType . '.'][$defaultTypoScriptKey])) {
796 $newString .= $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_' . $includeType . '.'][$defaultTypoScriptKey];
797 }
798 }
799 }
800
801 }
802 // Not the first/last linebreak char.
803 $string = substr($newString, 1, -1);
804 }
805 // When all included files should get returned, simply return an compound array containing
806 // the TypoScript with all "includes" processed and the files which got included
807 if ($returnFiles) {
808 return array(
809 'typoscript' => $string,
810 'files' => $includedFiles
811 );
812 }
813 return $string;
814 }
815
816 /**
817 * Include file $filename. Contents of the file will be prepended to &$newstring, filename to &$includedFiles
818 * Further include_typoscript tags in the contents are processed recursively
819 *
820 * @param string $filename Relative path to the typoscript file to be included
821 * @param integer $cycle_counter Counter for detecting endless loops
822 * @param boolean $returnFiles When set, filenames of included files will be prepended to the array &$includedFiles
823 * @param string &$newString The output string to which the content of the file will be prepended (referenced
824 * @param array &$includedFiles Array to which the filenames of included files will be prepended (referenced)
825 * @param string $optionalProperties
826 * @param string $parentFilenameOrPath The parent file (with absolute path) or path for relative includes
827 * @static
828 */
829 public static function includeFile($filename, $cycle_counter = 1, $returnFiles = FALSE, &$newString = '', array &$includedFiles = array(), $optionalProperties = '', $parentFilenameOrPath = '') {
830 // Resolve a possible relative paths if a parent file is given
831 if ($parentFilenameOrPath !== '' && GeneralUtility::isFirstPartOfStr($filename, '.')) {
832 $absfilename = PathUtility::getAbsolutePathOfRelativeReferencedFileOrPath($parentFilenameOrPath, $filename);
833 } else {
834 $absfilename = $filename;
835 }
836 $absfilename = GeneralUtility::getFileAbsFileName($absfilename);
837
838 $newString .= LF . '### <INCLUDE_TYPOSCRIPT: source="FILE:' . $filename . '"' . $optionalProperties . '> BEGIN:' . LF;
839 if ((string)$filename !== '') {
840 // Must exist and must not contain '..' and must be relative
841 // Check for allowed files
842 if (!GeneralUtility::verifyFilenameAgainstDenyPattern($absfilename)) {
843 $newString .= self::typoscriptIncludeError('File "' . $filename . '" was not included since it is not allowed due to fileDenyPattern.');
844 } elseif (!@file_exists($absfilename)) {
845 $newString .= self::typoscriptIncludeError('File "' . $filename . '" was not was not found.');
846 } else {
847 $includedFiles[] = $absfilename;
848 // check for includes in included text
849 $included_text = self::checkIncludeLines(GeneralUtility::getUrl($absfilename), $cycle_counter + 1, $returnFiles, $absfilename);
850 // If the method also has to return all included files, merge currently included
851 // files with files included by recursively calling itself
852 if ($returnFiles && is_array($included_text)) {
853 $includedFiles = array_merge($includedFiles, $included_text['files']);
854 $included_text = $included_text['typoscript'];
855 }
856 $newString .= $included_text . LF;
857 }
858 }
859 $newString .= '### <INCLUDE_TYPOSCRIPT: source="FILE:' . $filename . '"' . $optionalProperties . '> END:' . LF . LF;
860 }
861
862 /**
863 * Include all files with matching Typoscript extensions in directory $dirPath. Contents of the files are
864 * prepended to &$newstring, filename to &$includedFiles.
865 * Order of the directory items to be processed: files first, then directories, both in alphabetical order.
866 * Further include_typoscript tags in the contents of the files are processed recursively.
867 *
868 * @param string $dirPath Relative path to the directory to be included
869 * @param integer $cycle_counter Counter for detecting endless loops
870 * @param boolean $returnFiles When set, filenames of included files will be prepended to the array &$includedFiles
871 * @param string &$newString The output string to which the content of the file will be prepended (referenced)
872 * @param array &$includedFiles Array to which the filenames of included files will be prepended (referenced)
873 * @param string $optionalProperties
874 * @param string $parentFilenameOrPath The parent file (with absolute path) or path for relative includes
875 * @static
876 */
877 protected static function includeDirectory($dirPath, $cycle_counter = 1, $returnFiles = FALSE, &$newString = '', array &$includedFiles = array(), $optionalProperties = '', $parentFilenameOrPath = '') {
878 // Extract the value of the property extensions="..."
879 $matches = preg_split('#(?i)extensions\s*=\s*"([^"]*)"(\s*|>)#', $optionalProperties, 2, PREG_SPLIT_DELIM_CAPTURE);
880 if (count($matches) > 1) {
881 $includedFileExtensions = $matches[1];
882 } else {
883 $includedFileExtensions = '';
884 }
885
886 // Resolve a possible relative paths if a parent file is given
887 if ($parentFilenameOrPath !== '' && GeneralUtility::isFirstPartOfStr($dirPath, '.')) {
888 $absDirPath = PathUtility::getAbsolutePathOfRelativeReferencedFileOrPath($parentFilenameOrPath, $dirPath);
889 } else {
890 $absDirPath = $dirPath;
891 }
892 $absDirPath = rtrim(GeneralUtility::getFileAbsFileName($absDirPath), '/') . '/';
893
894 $newString .= LF . '### <INCLUDE_TYPOSCRIPT: source="DIR:' . $dirPath . '"' . $optionalProperties . '> BEGIN:' . LF;
895 // Get alphabetically sorted file index in array
896 $fileIndex = GeneralUtility::getAllFilesAndFoldersInPath(array(), $absDirPath, $includedFileExtensions);
897 // Prepend file contents to $newString
898 $prefixLenght = strlen(PATH_site);
899 foreach ($fileIndex as $absFileRef) {
900 $relFileRef = substr($absFileRef, $prefixLenght);
901 self::includeFile($relFileRef, $cycle_counter, $returnFiles, $newString, $includedFiles, '', $absDirPath);
902 }
903 $newString .= '### <INCLUDE_TYPOSCRIPT: source="DIR:' . $dirPath . '"' . $optionalProperties . '> END:' . LF . LF;
904 }
905
906 /**
907 * Process errors in INCLUDE_TYPOSCRIPT tags
908 * Errors are logged in sysLog and printed in the concatenated Typoscript result (as can be seen in Template Analyzer)
909 *
910 * @param string $error Text of the error message
911 * @return string The error message encapsulated in comments
912 * @static
913 */
914 protected static function typoscriptIncludeError($error) {
915 GeneralUtility::sysLog($error, 'Core', 2);
916 return "\n###\n### ERROR: " . $error . "\n###\n\n";
917 }
918
919 /**
920 * Parses the string in each value of the input array for include-commands
921 *
922 * @param array $array Array with TypoScript in each value
923 * @return array Same array but where the values has been parsed for include-commands
924 */
925 static public function checkIncludeLines_array(array $array) {
926 foreach ($array as $k => $v) {
927 $array[$k] = self::checkIncludeLines($array[$k]);
928 }
929 return $array;
930 }
931
932 /**
933 * Search for commented INCLUDE_TYPOSCRIPT statements
934 * and save the content between the BEGIN and the END line to the specified file
935 *
936 * @param string $string Template content
937 * @param integer $cycle_counter Counter for detecting endless loops
938 * @param array $extractedFileNames
939 * @param string $parentFilenameOrPath
940 *
941 * @throws \RuntimeException
942 * @throws \UnexpectedValueException
943 * @return string Template content with uncommented include statements
944 */
945 static public function extractIncludes($string, $cycle_counter = 1, array $extractedFileNames = array(), $parentFilenameOrPath = '') {
946 if ($cycle_counter > 10) {
947 GeneralUtility::sysLog('It appears like TypoScript code is looping over itself. Check your templates for "&lt;INCLUDE_TYPOSCRIPT: ..." tags', 'Core', GeneralUtility::SYSLOG_SEVERITY_WARNING);
948 return '
949 ###
950 ### ERROR: Recursion!
951 ###
952 ';
953 }
954 $expectedEndTag = '';
955 $fileContent = array();
956 $restContent = array();
957 $fileName = NULL;
958 $inIncludePart = FALSE;
959 $lines = preg_split("/\r\n|\n|\r/", $string);
960 $skipNextLineIfEmpty = FALSE;
961 $openingCommentedIncludeStatement = NULL;
962 $optionalProperties = '';
963 foreach ($lines as $line) {
964 // \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::checkIncludeLines inserts
965 // an additional empty line, remove this again
966 if ($skipNextLineIfEmpty) {
967 if (trim($line) === '') {
968 continue;
969 }
970 $skipNextLineIfEmpty = FALSE;
971 }
972
973 // Outside commented include statements
974 if (!$inIncludePart) {
975 // Search for beginning commented include statements
976 if (preg_match('/###\\s*<INCLUDE_TYPOSCRIPT:\\s*source\\s*=\\s*"\\s*((?i)file|dir)\\s*:\\s*([^"]*)"(.*)>\\s*BEGIN/i', $line, $matches)) {
977 // Found a commented include statement
978
979 // Save this line in case there is no ending tag
980 $openingCommentedIncludeStatement = trim($line);
981 $openingCommentedIncludeStatement = preg_replace('/\\s*### Warning: .*###\\s*/', '', $openingCommentedIncludeStatement);
982
983 // type of match: FILE or DIR
984 $inIncludePart = strtoupper($matches[1]);
985 $fileName = $matches[2];
986 $optionalProperties = $matches[3];
987
988 $expectedEndTag = '### <INCLUDE_TYPOSCRIPT: source="' . $inIncludePart . ':' . $fileName . '"' . $optionalProperties . '> END';
989 // Strip all whitespace characters to make comparision safer
990 $expectedEndTag = strtolower(preg_replace('/\s/', '', $expectedEndTag));
991 } else {
992 // If this is not a beginning commented include statement this line goes into the rest content
993 $restContent[] = $line;
994 }
995 //if (is_array($matches)) GeneralUtility::devLog('matches', 'TypoScriptParser', 0, $matches);
996 } else {
997 // Inside commented include statements
998 // Search for the matching ending commented include statement
999 $strippedLine = preg_replace('/\s/', '', $line);
1000 if (stripos($strippedLine, $expectedEndTag) !== FALSE) {
1001 // Found the matching ending include statement
1002 $fileContentString = implode(PHP_EOL, $fileContent);
1003
1004 // Write the content to the file
1005
1006 // Resolve a possible relative paths if a parent file is given
1007 if ($parentFilenameOrPath !== '' && GeneralUtility::isFirstPartOfStr($fileName, '.')) {
1008 $realFileName = PathUtility::getAbsolutePathOfRelativeReferencedFileOrPath($parentFilenameOrPath, $fileName);
1009 } else {
1010 $realFileName = $fileName;
1011 }
1012 $realFileName = GeneralUtility::getFileAbsFileName($realFileName);
1013
1014 if ($inIncludePart === 'FILE') {
1015 // Some file checks
1016 if (!GeneralUtility::verifyFilenameAgainstDenyPattern($realFileName)) {
1017 throw new \UnexpectedValueException(sprintf('File "%s" was not included since it is not allowed due to fileDenyPattern.', $fileName), 1382651858);
1018 }
1019 if (empty($realFileName)) {
1020 throw new \UnexpectedValueException(sprintf('"%s" is not a valid file location.', $fileName), 1294586441);
1021 }
1022 if (!is_writable($realFileName)) {
1023 throw new \RuntimeException(sprintf('"%s" is not writable.', $fileName), 1294586442);
1024 }
1025 if (in_array($realFileName, $extractedFileNames)) {
1026 throw new \RuntimeException(sprintf('Recursive/multiple inclusion of file "%s"', $realFileName), 1294586443);
1027 }
1028 $extractedFileNames[] = $realFileName;
1029
1030 // Recursive call to detected nested commented include statements
1031 $fileContentString = self::extractIncludes($fileContentString, $cycle_counter + 1, $extractedFileNames, $realFileName);
1032
1033 // Write the content to the file
1034 if (!GeneralUtility::writeFile($realFileName, $fileContentString)) {
1035 throw new \RuntimeException(sprintf('Could not write file "%s"', $realFileName), 1294586444);
1036 }
1037 // Insert reference to the file in the rest content
1038 $restContent[] = '<INCLUDE_TYPOSCRIPT: source="FILE:' . $fileName . '"' . $optionalProperties . '>';
1039 } else {
1040 // must be DIR
1041
1042 // Some file checks
1043 if (empty($realFileName)) {
1044 throw new \UnexpectedValueException(sprintf('"%s" is not a valid location.', $fileName), 1366493602);
1045 }
1046 if (!is_dir($realFileName)) {
1047 throw new \RuntimeException(sprintf('"%s" is not a directory.', $fileName), 1366493603);
1048 }
1049 if (in_array($realFileName, $extractedFileNames)) {
1050 throw new \RuntimeException(sprintf('Recursive/multiple inclusion of directory "%s"', $realFileName), 1366493604);
1051 }
1052 $extractedFileNames[] = $realFileName;
1053
1054 // Recursive call to detected nested commented include statements
1055 self::extractIncludes($fileContentString, $cycle_counter + 1, $extractedFileNames, $realFileName);
1056
1057 // just drop content between tags since it should usually just contain individual files from that dir
1058
1059 // Insert reference to the dir in the rest content
1060 $restContent[] = '<INCLUDE_TYPOSCRIPT: source="DIR:' . $fileName . '"' . $optionalProperties . '>';
1061 }
1062
1063 // Reset variables (preparing for the next commented include statement)
1064 $fileContent = array();
1065 $fileName = NULL;
1066 $inIncludePart = FALSE;
1067 $openingCommentedIncludeStatement = NULL;
1068 // \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::checkIncludeLines inserts
1069 // an additional empty line, remove this again
1070 $skipNextLineIfEmpty = TRUE;
1071 } else {
1072 // If this is not a ending commented include statement this line goes into the file content
1073 $fileContent[] = $line;
1074 }
1075 }
1076 }
1077 // If we're still inside commented include statements copy the lines back to the rest content
1078 if ($inIncludePart) {
1079 $restContent[] = $openingCommentedIncludeStatement . ' ### Warning: Corresponding end line missing! ###';
1080 $restContent = array_merge($restContent, $fileContent);
1081 }
1082 $restContentString = implode(PHP_EOL, $restContent);
1083 return $restContentString;
1084 }
1085
1086 /**
1087 * Processes the string in each value of the input array with extractIncludes
1088 *
1089 * @param array $array Array with TypoScript in each value
1090 * @return array Same array but where the values has been processed with extractIncludes
1091 */
1092 static public function extractIncludes_array(array $array) {
1093 foreach ($array as $k => $v) {
1094 $array[$k] = self::extractIncludes($array[$k]);
1095 }
1096 return $array;
1097 }
1098
1099 /**********************************
1100 *
1101 * Syntax highlighting
1102 *
1103 *********************************/
1104 /**
1105 * Syntax highlight a TypoScript text
1106 * Will parse the content. Remember, the internal setup array may contain invalid parsed content since conditions are ignored!
1107 *
1108 * @param string $string The TypoScript text
1109 * @param mixed $lineNum If blank, linenumbers are NOT printed. If array then the first key is the linenumber offset to add to the internal counter.
1110 * @param boolean $highlightBlockMode 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.
1111 * @return string HTML code for the syntax highlighted string
1112 * @todo Define visibility
1113 */
1114 public function doSyntaxHighlight($string, $lineNum = '', $highlightBlockMode = FALSE) {
1115 $this->syntaxHighLight = 1;
1116 $this->highLightData = array();
1117 $this->error = array();
1118 // This is done in order to prevent empty <span>..</span> sections around CR content. Should not do anything but help lessen the amount of HTML code.
1119 $string = str_replace(CR, '', $string);
1120 $this->parse($string);
1121 return $this->syntaxHighlight_print($lineNum, $highlightBlockMode);
1122 }
1123
1124 /**
1125 * Registers a part of a TypoScript line for syntax highlighting.
1126 *
1127 * @param string $code Key from the internal array $this->highLightStyles
1128 * @param integer $pointer Pointer to the line in $this->raw which this is about
1129 * @param integer $strlen The number of chars LEFT on this line before the end is reached.
1130 * @return void
1131 * @access private
1132 * @see parse()
1133 * @todo Define visibility
1134 */
1135 public function regHighLight($code, $pointer, $strlen = -1) {
1136 if ($strlen === -1) {
1137 $this->highLightData[$pointer] = array(array($code, 0));
1138 } else {
1139 $this->highLightData[$pointer][] = array($code, $strlen);
1140 }
1141 $this->highLightData_bracelevel[$pointer] = $this->inBrace;
1142 }
1143
1144 /**
1145 * Formatting the TypoScript code in $this->raw based on the data collected by $this->regHighLight in $this->highLightData
1146 *
1147 * @param mixed $lineNumDat If blank, linenumbers are NOT printed. If array then the first key is the linenumber offset to add to the internal counter.
1148 * @param boolean $highlightBlockMode 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.
1149 * @return string HTML content
1150 * @access private
1151 * @see doSyntaxHighlight()
1152 * @todo Define visibility
1153 */
1154 public function syntaxHighlight_print($lineNumDat, $highlightBlockMode) {
1155 // Registers all error messages in relation to their linenumber
1156 $errA = array();
1157 foreach ($this->errors as $err) {
1158 $errA[$err[2]][] = $err[0];
1159 }
1160 // Generates the syntax highlighted output:
1161 $lines = array();
1162 foreach ($this->raw as $rawP => $value) {
1163 $start = 0;
1164 $strlen = strlen($value);
1165 $lineC = '';
1166 if (is_array($this->highLightData[$rawP])) {
1167 foreach ($this->highLightData[$rawP] as $set) {
1168 $len = $strlen - $start - $set[1];
1169 if ($len > 0) {
1170 $part = substr($value, $start, $len);
1171 $start += $len;
1172 $st = $this->highLightStyles[isset($this->highLightStyles[$set[0]]) ? $set[0] : 'default'];
1173 if (!$highlightBlockMode || $set[0] !== 'prespace') {
1174 $lineC .= $st[0] . htmlspecialchars($part) . $st[1];
1175 }
1176 } elseif ($len < 0) {
1177 debug(array($len, $value, $rawP));
1178 }
1179 }
1180 } else {
1181 debug(array($value));
1182 }
1183 if (strlen(substr($value, $start))) {
1184 $lineC .= $this->highLightStyles['ignored'][0] . htmlspecialchars(substr($value, $start)) . $this->highLightStyles['ignored'][1];
1185 }
1186 if ($errA[$rawP]) {
1187 $lineC .= $this->highLightStyles['error'][0] . '<strong> - ERROR:</strong> ' . htmlspecialchars(implode(';', $errA[$rawP])) . $this->highLightStyles['error'][1];
1188 }
1189 if ($highlightBlockMode && $this->highLightData_bracelevel[$rawP]) {
1190 $lineC = str_pad('', $this->highLightData_bracelevel[$rawP] * 2, ' ', STR_PAD_LEFT) . '<span style="' . $this->highLightBlockStyles . ($this->highLightBlockStyles_basecolor ? 'background-color: ' . GeneralUtility::modifyHTMLColorAll($this->highLightBlockStyles_basecolor, -$this->highLightData_bracelevel[$rawP] * 16) : '') . '">' . ($lineC !== '' ? $lineC : '&nbsp;') . '</span>';
1191 }
1192 if (is_array($lineNumDat)) {
1193 $lineNum = $rawP + $lineNumDat[0];
1194 if ($this->parentObject instanceof \TYPO3\CMS\Core\TypoScript\ExtendedTemplateService) {
1195 $lineNum = $this->parentObject->ext_lnBreakPointWrap($lineNum, $lineNum);
1196 }
1197 $lineC = $this->highLightStyles['linenum'][0] . str_pad($lineNum, 4, ' ', STR_PAD_LEFT) . ':' . $this->highLightStyles['linenum'][1] . ' ' . $lineC;
1198 }
1199 $lines[] = $lineC;
1200 }
1201 return '<pre class="ts-hl">' . implode(LF, $lines) . '</pre>';
1202 }
1203
1204 }