Go to the source code of this file.
Namespaces | |
| namespace | TYPO3 |
Classes | |
| class | t3lib_TSparser |
Functions | |
| nextDivider () | |
| Will search for the next condition. | |
| parseSub (&$setup) | |
| Parsing the $this->raw TypoScript lines from pointer, $this->rawP. | |
| rollParseSub ($string, &$setup) | |
| 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. | |
| getVal ($string, $setup) | |
| Get a value/property pair for an object path in TypoScript, eg. | |
| setVal ($string, &$setup, $value, $wipeOut=0) | |
| Setting a value/property of an object string in the setup array. | |
| error ($err, $num=2) | |
| Stacks errors/messages from the TypoScript parser into an internal array, $this->error 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. | |
| checkIncludeLines ($string) | |
| Checks the input string (un-parsed TypoScript) for include-commands ("<INCLUDE_TYPOSCRIPT: ....") Use: t3lib_TSparser::checkIncludeLines(). | |
| checkIncludeLines_array ($array) | |
| Parses the string in each value of the input array for include-commands. | |
| doSyntaxHighlight ($string, $lineNum='', $highlightBlockMode=0) | |
| Syntax highlight a TypoScript text Will parse the content. | |
| regHighLight ($code, $pointer, $strlen=-1) | |
| Registers a part of a TypoScript line for syntax highlighting. | |
| syntaxHighlight_print ($lineNumDat, $highlightBlockMode) | |
| Formatting the TypoScript code in $this->raw based on the data collected by $this->regHighLight in $this->highLightData. | |
Variables | |
| $this | lineNumberOffset = count($this->raw)+1 |
|
|
Checks the input string (un-parsed TypoScript) for include-commands ("<INCLUDE_TYPOSCRIPT: ....") Use: t3lib_TSparser::checkIncludeLines().
Definition at line 445 of file class.t3lib_tsparser.php. Referenced by checkIncludeLines_array(). 00445 {
00446 $splitStr='<INCLUDE_TYPOSCRIPT:';
00447 if (strstr($string,$splitStr)) {
00448 $newString='';
00449 $allParts = explode($splitStr,chr(10).$string.chr(10)); // adds line break char before/after
00450 reset($allParts);
00451 while(list($c,$v)=each($allParts)) {
00452 if (!$c) { // first goes through
00453 $newString.=$v;
00454 } elseif (ereg("\r?\n[ ]*$",$allParts[$c-1])) { // There must be a line-break char before.
00455 $subparts=explode('>',$v,2);
00456 if (ereg("^[ ]*\r?\n",$subparts[1])) { // There must be a line-break char after
00457 // SO, the include was positively recognized:
00458 $newString.='### '.$splitStr.$subparts[0].'> BEGIN:'.chr(10);
00459 $params = t3lib_div::get_tag_attributes($subparts[0]);
00460 if ($params['source']) {
00461 $sourceParts = explode(':',$params['source'],2);
00462 switch(strtolower(trim($sourceParts[0]))) {
00463 case 'file':
00464 $filename = t3lib_div::getFileAbsFileName(trim($sourceParts[1]));
00465 if (strcmp($filename,'')) { // Must exist and must not contain '..' and must be relative
00466 if (@is_file($filename) && filesize($filename)<100000) { // Max. 100 KB include files!
00467 $newString.=t3lib_div::getUrl($filename).chr(10);
00468 }
00469 }
00470 break;
00471 }
00472 }
00473 $newString.='### '.$splitStr.$subparts[0].'> END:'.chr(10);
00474 $newString.=$subparts[1];
00475 } else $newString.=$splitStr.$v;
00476 } else $newString.=$splitStr.$v;
00477 }
00478 $string=substr($newString,1,-1); // not the first/last linebreak char.
00479 }
00480 return $string;
00481 }
|
|
|
Parses the string in each value of the input array for include-commands.
Definition at line 489 of file class.t3lib_tsparser.php. References checkIncludeLines(). Referenced by t3lib_userAuthGroup::fetchGroupData(), t3lib_BEfunc::getPagesTSconfig(), and tslib_feUserAuth::getUserTSconf(). 00489 {
00490 reset($array);
00491 while(list($k)=each($array)) {
00492 $array[$k]=t3lib_TSparser::checkIncludeLines($array[$k]);
00493 }
00494 return $array;
00495 }
|
|
||||||||||||||||
|
Syntax highlight a TypoScript text Will parse the content. Remember, the internal setup array may contain INvalid parsed content since conditions are ignored!
Definition at line 532 of file class.t3lib_tsparser.php. References error(), and syntaxHighlight_print(). 00532 {
00533 $this->syntaxHighLight=1;
00534 $this->highLightData=array();
00535 $this->error=array();
00536 $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.
00537
00538 $this->parse($string);
00539
00540 return $this->syntaxHighlight_print($lineNum,$highlightBlockMode);
00541 }
|
|
||||||||||||
|
||||||||||||
|
Get a value/property pair for an object path in TypoScript, eg. "myobject.myvalue.mysubproperty". Here: Used by the "copy" operator, <
Definition at line 361 of file class.t3lib_tsparser.php. References $key. 00361 {
00362 if ((string)$string!='') {
00363 $keyLen = strcspn($string,'.');
00364 if ($keyLen==strlen($string)) {
00365 $retArr=array(); // Added 6/6/03. Shouldn't hurt
00366 if (isset($setup[$string])) {$retArr[0]=$setup[$string]; }
00367 if (isset($setup[$string.'.'])) {$retArr[1]=$setup[$string.'.']; }
00368 return $retArr;
00369 } else {
00370 $key = substr($string,0,$keyLen).'.';
00371 if ($setup[$key]) {
00372 return $this->getVal(substr($string,$keyLen+1),$setup[$key]);
00373 }
00374 }
00375 }
00376 }
|
|
|
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.
Definition at line 169 of file class.t3lib_tsparser.php. 00169 {
00170 while (isset($this->raw[$this->rawP])) {
00171 $line = ltrim($this->raw[$this->rawP]);
00172 $this->rawP++;
00173 if ($line && substr($line,0,1)=='[') {
00174 return $line;
00175 }
00176 }
00177 }
|
|
|
Parsing the $this->raw TypoScript lines from pointer, $this->rawP.
Definition at line 185 of file class.t3lib_tsparser.php. References lineNumberOffset, and regHighLight(). Referenced by rollParseSub(). 00185 {
00186 while (isset($this->raw[$this->rawP])) {
00187 $line = ltrim($this->raw[$this->rawP]);
00188 $lineP = $this->rawP;
00189 $this->rawP++;
00190 if ($this->syntaxHighLight) $this->regHighLight("prespace",$lineP,strlen($line));
00191
00192 // Breakpoint?
00193 if ($this->breakPointLN && ($this->lineNumberOffset+$this->rawP-1)==($this->breakPointLN+1)) { // by adding 1 we get that line processed
00194 return '[_BREAK]';
00195 }
00196
00197 // Set comment flag?
00198 if (!$this->multiLineEnabled && substr($line,0,2)=='/*') {
00199 $this->commentSet=1;
00200 }
00201
00202 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.
00203 if ($this->multiLineEnabled) { // If multiline is enabled. Escape by ')'
00204 if (substr($line,0,1)==')') { // Multiline ends...
00205 if ($this->syntaxHighLight) $this->regHighLight("operator",$lineP,strlen($line)-1);
00206 $this->multiLineEnabled=0; // Disable multiline
00207 $theValue = implode($this->multiLineValue,chr(10));
00208 if (strstr($this->multiLineObject,'.')) {
00209 $this->setVal($this->multiLineObject,$setup,array($theValue)); // Set the value deeper.
00210 } else {
00211 $setup[$this->multiLineObject] = $theValue; // Set value regularly
00212 if ($this->lastComment && $this->regComments) {
00213 $setup[$this->multiLineObject.'..'].=$this->lastComment;
00214 }
00215 if ($this->regLinenumbers) {
00216 $setup[$this->multiLineObject.'.ln..'][]=($this->lineNumberOffset+$this->rawP-1);
00217 }
00218 }
00219 } else{
00220 if ($this->syntaxHighLight) $this->regHighLight("value",$lineP);
00221 $this->multiLineValue[]=$this->raw[($this->rawP-1)];
00222 }
00223 } elseif ($this->inBrace==0 && substr($line,0,1)=='[') { // Beginning of condition (only on level zero compared to brace-levels
00224 if ($this->syntaxHighLight) $this->regHighLight("condition",$lineP);
00225 return $line;
00226 } else {
00227 if (substr($line,0,1)=='[' && strtoupper(trim($line))=='[GLOBAL]') { // Return if GLOBAL condition is set - no matter what.
00228 if ($this->syntaxHighLight) $this->regHighLight("condition",$lineP);
00229 $this->error('Line '.($this->lineNumberOffset+$this->rawP-1).': On return to [GLOBAL] scope, the script was short of '.$this->inBrace.' end brace(s)',1);
00230 $this->inBrace=0;
00231 return $line;
00232 } elseif (strcspn($line,'}#/')!=0) { // If not brace-end or comment
00233 $varL = strcspn($line,' {=<>('); // Find object name string until we meet an operator VER2: Added '>'!!
00234 $objStrName=trim(substr($line,0,$varL));
00235 if ($this->syntaxHighLight) $this->regHighLight("objstr",$lineP,strlen(substr($line,$varL)));
00236 if ($objStrName) {
00237 if ($this->strict && eregi('[^[:alnum:]_\.-]',$objStrName,$r)) {
00238 $this->error('Line '.($this->lineNumberOffset+$this->rawP-1).': Object Name String, "'.htmlspecialchars($objStrName).'" contains invalid character "'.$r[0].'". Must be alphanumeric or one of: "_-."');
00239 } else {
00240 $line = ltrim(substr($line,$varL));
00241 if ($this->syntaxHighLight) {
00242 $this->regHighLight("objstr_postspace", $lineP, strlen($line));
00243 if (strlen($line)>0) {
00244 $this->regHighLight("operator", $lineP, strlen($line)-1);
00245 $this->regHighLight("operator_postspace", $lineP, strlen(ltrim(substr($line,1))));
00246 }
00247 }
00248 switch(substr($line,0,1)) {
00249 case '=':
00250 if ($this->syntaxHighLight) $this->regHighLight("value", $lineP, strlen(ltrim(substr($line,1)))-strlen(trim(substr($line,1))));
00251 if (strstr($objStrName,'.')) {
00252 $value = Array();
00253 $value[0] = trim(substr($line,1));
00254 $this->setVal($objStrName,$setup,$value);
00255 } else {
00256 $setup[$objStrName] = trim(substr($line,1));
00257 if ($this->lastComment && $this->regComments) { // Setting comment..
00258 $setup[$objStrName.'..'].=$this->lastComment;
00259 }
00260 if ($this->regLinenumbers) {
00261 $setup[$objStrName.'.ln..'][]=($this->lineNumberOffset+$this->rawP-1);
00262 }
00263 }
00264 break;
00265 case '{':
00266 $this->inBrace++;
00267 if (strstr($objStrName,'.')) {
00268 $exitSig=$this->rollParseSub($objStrName,$setup);
00269 if ($exitSig) return $exitSig;
00270 } else {
00271 if (!isset($setup[$objStrName.'.'])) {$setup[$objStrName.'.'] = Array();}
00272 $exitSig=$this->parseSub($setup[$objStrName.'.']);
00273 if ($exitSig) return $exitSig;
00274 }
00275 break;
00276 case '(':
00277 $this->multiLineObject = $objStrName;
00278 $this->multiLineEnabled=1;
00279 $this->multiLineValue=array();
00280 break;
00281 case '<':
00282 if ($this->syntaxHighLight) $this->regHighLight("value_copy", $lineP, strlen(ltrim(substr($line,1)))-strlen(trim(substr($line,1))));
00283 $theVal = trim(substr($line,1));
00284 if (substr($theVal,0,1)=='.') {
00285 $res = $this->getVal(substr($theVal,1),$setup);
00286 } else {
00287 $res = $this->getVal($theVal,$this->setup);
00288 }
00289 $this->setVal($objStrName,$setup,unserialize(serialize($res)),1);
00290 break;
00291 case '>':
00292 if ($this->syntaxHighLight) $this->regHighLight("value_unset", $lineP, strlen(ltrim(substr($line,1)))-strlen(trim(substr($line,1))));
00293 $this->setVal($objStrName,$setup,'UNSET');
00294 break;
00295 default:
00296 $this->error('Line '.($this->lineNumberOffset+$this->rawP-1).': Object Name String, "'.htmlspecialchars($objStrName).'" was not preceeded by any operator, =<>({');
00297 break;
00298 }
00299 }
00300 $this->lastComment='';
00301 }
00302 } elseif (substr($line,0,1)=='}') {
00303 $this->inBrace--;
00304 $this->lastComment='';
00305 if ($this->syntaxHighLight) $this->regHighLight("operator", $lineP, strlen($line)-1);
00306 if ($this->inBrace<0) {
00307 $this->error('Line '.($this->lineNumberOffset+$this->rawP-1).': An end brace is in excess.',1);
00308 $this->inBrace=0;
00309 } else {
00310 break;
00311 }
00312 } else {
00313 if ($this->syntaxHighLight) $this->regHighLight("comment", $lineP);
00314
00315 // Comment. The comments are concatenated in this temporary string:
00316 if ($this->regComments) $this->lastComment.= trim($line).chr(10);
00317 }
00318 }
00319 }
00320
00321 // Unset comment
00322 if ($this->commentSet) {
00323 if ($this->syntaxHighLight) $this->regHighLight("comment", $lineP);
00324 if (substr($line,0,2)=='*/') $this->commentSet=0;
00325 }
00326 }
|
|
||||||||||||||||
|
Registers a part of a TypoScript line for syntax highlighting.
Definition at line 553 of file class.t3lib_tsparser.php. Referenced by parseSub(). 00553 {
00554 if ($strlen==-1) {
00555 $this->highLightData[$pointer] = array(array($code,0));
00556 } else {
00557 $this->highLightData[$pointer][] = array($code,$strlen);
00558 }
00559 $this->highLightData_bracelevel[$pointer] = $this->inBrace;
00560 }
|
|
||||||||||||
|
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.
Definition at line 337 of file class.t3lib_tsparser.php. References $key, and parseSub(). 00337 {
00338 if ((string)$string!='') {
00339 $keyLen = strcspn($string,'.');
00340 if ($keyLen==strlen($string)) {
00341 $key = $string.'.';
00342 if (!isset($setup[$key])){$setup[$key]=Array();}
00343 $exitSig=$this->parseSub($setup[$key]);
00344 if ($exitSig) return $exitSig;
00345 } else {
00346 $key = substr($string,0,$keyLen).'.';
00347 if (!isset($setup[$key])){$setup[$key]=Array();}
00348 $exitSig=$this->rollParseSub(substr($string,$keyLen+1),$setup[$key]);
00349 if ($exitSig) return $exitSig;
00350 }
00351 }
00352 }
|
|
||||||||||||||||||||
|
Setting a value/property of an object string in the setup array.
Definition at line 387 of file class.t3lib_tsparser.php. References $key, error(), and lineNumberOffset. 00387 {
00388 if ((string)$string!='') {
00389 $keyLen = strcspn($string,'.');
00390 if ($keyLen==strlen($string)) {
00391 if ($value=='UNSET') {
00392 unset($setup[$string]);
00393 unset($setup[$string.'.']);
00394 if ($this->regLinenumbers) {
00395 $setup[$string.'.ln..'][]=($this->lineNumberOffset+$this->rawP-1).'>';
00396 }
00397 } else {
00398 $lnRegisDone=0;
00399 if ($wipeOut && $this->strict) {
00400 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);}
00401 unset($setup[$string]);
00402 unset($setup[$string.'.']);
00403 if ($this->regLinenumbers) {
00404 $setup[$string.'.ln..'][]=($this->lineNumberOffset+$this->rawP-1).'<';
00405 $lnRegisDone=1;
00406 }
00407 }
00408 if (isset($value[0])) {$setup[$string] = $value[0];}
00409 if (isset($value[1])) {$setup[$string.'.'] = $value[1];}
00410 if ($this->lastComment && $this->regComments) {
00411 $setup[$string.'..'].=$this->lastComment;
00412 }
00413 if ($this->regLinenumbers && !$lnRegisDone) {
00414 $setup[$string.'.ln..'][]=($this->lineNumberOffset+$this->rawP-1);
00415 }
00416 }
00417 } else {
00418 $key = substr($string,0,$keyLen).'.';
00419 if (!isset($setup[$key])){$setup[$key]=Array();}
00420 $this->setVal(substr($string,$keyLen+1),$setup[$key],$value);
00421 }
00422 }
00423 }
|
|
||||||||||||
|
Formatting the TypoScript code in $this->raw based on the data collected by $this->regHighLight in $this->highLightData.
Definition at line 571 of file class.t3lib_tsparser.php. References debug(), and error(). Referenced by doSyntaxHighlight(). 00571 {
00572 // Registers all error messages in relation to their linenumber
00573 $errA=array();
00574 foreach($this->errors as $err) {
00575 $errA[$err[2]][]=$err[0];
00576 }
00577 // Generates the syntax highlighted output:
00578 $lines=array();
00579 foreach($this->raw as $rawP => $value) {
00580 $start=0;
00581 $strlen=strlen($value);
00582 $lineC='';
00583
00584 if (is_array($this->highLightData[$rawP])) {
00585 foreach($this->highLightData[$rawP] as $set) {
00586 $len = $strlen-$start-$set[1];
00587 if ($len > 0) {
00588 $part = substr($value,$start,$len);
00589 $start+=$len;
00590 $st = $this->highLightStyles[(isset($this->highLightStyles[$set[0]])?$set[0]:'default')];
00591 if (!$highlightBlockMode || $set[0]!='prespace') $lineC.=$st[0].htmlspecialchars($part).$st[1];
00592 }elseif ($len < 0) debug(array($len,$value,$rawP));
00593 }
00594 } else debug(array($value));
00595
00596 if (strlen(substr($value,$start))) $lineC.=$this->highLightStyles['ignored'][0].htmlspecialchars(substr($value,$start)).$this->highLightStyles['ignored'][1];
00597
00598 if ($errA[$rawP]) {
00599 $lineC.=$this->highLightStyles['error'][0].'<strong> - ERROR:</strong> '.htmlspecialchars(implode(';',$errA[$rawP])).$this->highLightStyles['error'][1];
00600 }
00601
00602 if ($highlightBlockMode && $this->highLightData_bracelevel[$rawP]) {
00603 $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:' ').'</span>';
00604 }
00605
00606 if (is_array($lineNumDat)) {
00607 $lineNum = $rawP+$lineNumDat[0];
00608 $lineC = $this->highLightStyles['linenum'][0].str_pad($lineNum,4,' ',STR_PAD_LEFT).':'.$this->highLightStyles['linenum'][1].' '.$lineC;
00609 }
00610
00611
00612 $lines[] = $lineC;
00613 }
00614
00615 return '<pre class="ts-hl">'.implode(chr(10),$lines).'</pre>';
00616 }
|
|
|
Definition at line 160 of file class.t3lib_tsparser.php. Referenced by parseSub(), and setVal(). |
1.3.8-20040913