Documentation TYPO3 par Ameos

class.t3lib_tsparser.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2006 Kasper Skaarhoj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00080 class t3lib_TSparser {
00081         var $strict = 1;                                // If set, then key names cannot contain characters other than [:alnum:]_\.-
00082 
00083                 // Internal
00084         var $setup = Array();                   // TypoScript hierarchy being build during parsing.
00085         var $raw;                                               // raw data, the input string exploded by chr(10)
00086         var $rawP;                                              // pointer to entry in raw data array
00087         var $lastComment='';                    // Holding the value of the last comment
00088         var $commentSet=0;                              // Internally set, used as internal flag to create a multi-line comment (one of those like /*... */)
00089         var $multiLineEnabled=0;                // Internally set, when multiline value is accumulated
00090         var $multiLineObject='';                // Internally set, when multiline value is accumulated
00091         var $multiLineValue=array();    // Internally set, when multiline value is accumulated
00092         var $inBrace = 0;                               // Internally set, when in brace. Counter.
00093         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.
00094         var $sections=array();                  // Tracking all conditions found
00095         var $sectionsMatch=array();             // Tracking all matching conditions found
00096         var $syntaxHighLight = 0;               // If set, then syntax highlight mode is on; Call the function syntaxHighlight() to use this function
00097         var $highLightData=array();             // Syntax highlight data is accumulated in this array. Used by syntaxHighlight_print() to construct the output.
00098         var $highLightData_bracelevel = array();        // Syntax highlight data keeping track of the curly brace level for each line
00099 
00100                 // Debugging, analysis:
00101         var $regComments = 0;                   // DO NOT register the comments. This is default for the ordinary sitetemplate!
00102         var $regLinenumbers = 0;                // DO NOT register the linenumbers. This is default for the ordinary sitetemplate!
00103         var $errors=array();                    // Error accumulation array.
00104         var $lineNumberOffset=0;                // Used for the error messages line number reporting. Set externally.
00105         var $breakPointLN=0;                    // Line for break point.
00106         var $highLightStyles=array(
00107                 'prespace'                      => array('<span class="ts-prespace">','</span>'),       // Space before any content on a line
00108                 'objstr_postspace'      => array('<span class="ts-objstr_postspace">','</span>'),       // Space after the object string on a line
00109                 'operator_postspace' => array('<span class="ts-operator_postspace">','</span>'),        // Space after the operator on a line
00110                 'operator'                      => array('<span class="ts-operator">','</span>'),       // The operator char
00111                 'value'                         => array('<span class="ts-value">','</span>'),  // The value of a line
00112                 'objstr'                        => array('<span class="ts-objstr">','</span>'), // The object string of a line
00113                 'value_copy'            => array('<span class="ts-value_copy">','</span>'),     // The value when the copy syntax (<) is used; that means the object reference
00114                 'value_unset'           => array('<span class="ts-value_unset">','</span>'),    // The value when an object is unset. Should not exist.
00115                 'ignored'                       => array('<span class="ts-ignored">','</span>'),        // The "rest" of a line which will be ignored.
00116                 'default'                       => array('<span class="ts-default">','</span>'),        // The default style if none other is applied.
00117                 'comment'                       => array('<span class="ts-comment">','</span>'),        // Comment lines
00118                 'condition'                     => array('<span class="ts-condition">','</span>'),      // Conditions
00119                 'error'                         => array('<span class="ts-error">','</span>'),  // Error messages
00120                 'linenum'                       => array('<span class="ts-linenum">','</span>'),        // Line numbers
00121         );
00122         var $highLightBlockStyles = '';         // Additional attributes for the <span> tags for a blockmode line
00123         var $highLightBlockStyles_basecolor = '#cccccc';                // The hex-HTML color for the blockmode
00124 
00125 
00133         function parse($string,$matchObj='')    {
00134                 $this->raw = explode(chr(10),$string);
00135                 $this->rawP = 0;
00136                 $pre = '[GLOBAL]';
00137                 while($pre)     {
00138                         if ($this->breakPointLN && $pre=='[_BREAK]')    {
00139                                 $this->error('Breakpoint at '.($this->lineNumberOffset+$this->rawP-2).': Line content was "'.$this->raw[$this->rawP-2].'"',1);
00140                                 break;
00141                         }
00142 
00143                         if (strtoupper($pre)=='[GLOBAL]' || strtoupper($pre)=='[END]' || (!$this->lastConditionTrue && strtoupper($pre)=='[ELSE]'))     {
00144                                 $pre = trim($this->parseSub($this->setup));
00145                                 $this->lastConditionTrue=1;
00146                         } else {
00147                                 if (strtoupper($pre)!='[ELSE]') {$this->sections[md5($pre)]=$pre;}      // we're in a specific section. Therefore we log this section
00148                                 if ((is_object($matchObj) && $matchObj->match($pre)) || $this->syntaxHighLight) {
00149                                         if (strtoupper($pre)!='[ELSE]') {$this->sectionsMatch[md5($pre)]=$pre;}
00150                                         $pre = trim($this->parseSub($this->setup));
00151                                         $this->lastConditionTrue=1;
00152                                 } else {
00153                                         $pre = trim($this->nextDivider());
00154                                         $this->lastConditionTrue=0;
00155                                 }
00156                         }
00157                 }
00158                 if ($this->inBrace)     {$this->error('Line '.($this->lineNumberOffset+$this->rawP-1).': The script is short of '.$this->inBrace.' end brace(s)',1);    }
00159                 if ($this->multiLineEnabled)    {$this->error('Line '.($this->lineNumberOffset+$this->rawP-1).': A multiline value section is not ended with a parenthesis!',1);        }
00160                 $this->lineNumberOffset+=count($this->raw)+1;
00161         }
00162 
00169         function nextDivider()  {
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         }
00178 
00185         function parseSub(&$setup)      {
00186                 global $TYPO3_CONF_VARS;
00187 
00188                 while (isset($this->raw[$this->rawP]))  {
00189                         $line = ltrim($this->raw[$this->rawP]);
00190                         $lineP = $this->rawP;
00191                         $this->rawP++;
00192                         if ($this->syntaxHighLight)     $this->regHighLight("prespace",$lineP,strlen($line));
00193 
00194                                 // Breakpoint?
00195                         if ($this->breakPointLN && ($this->lineNumberOffset+$this->rawP-1)==($this->breakPointLN+1))    {       // by adding 1 we get that line processed
00196                                 return '[_BREAK]';
00197                         }
00198 
00199                                 // Set comment flag?
00200                         if (!$this->multiLineEnabled && substr($line,0,2)=='/*')        {
00201                                 $this->commentSet=1;
00202                         }
00203 
00204                         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.
00205                                 if ($this->multiLineEnabled) {  // If multiline is enabled. Escape by ')'
00206                                         if (substr($line,0,1)==')')     {       // Multiline ends...
00207                                                 if ($this->syntaxHighLight)     $this->regHighLight("operator",$lineP,strlen($line)-1);
00208                                                 $this->multiLineEnabled=0;      // Disable multiline
00209                                                 $theValue = implode($this->multiLineValue,chr(10));
00210                                                 if (strstr($this->multiLineObject,'.')) {
00211                                                         $this->setVal($this->multiLineObject,$setup,array($theValue));  // Set the value deeper.
00212                                                 } else {
00213                                                         $setup[$this->multiLineObject] = $theValue;     // Set value regularly
00214                                                         if ($this->lastComment && $this->regComments)   {
00215                                                                 $setup[$this->multiLineObject.'..'].=$this->lastComment;
00216                                                         }
00217                                                         if ($this->regLinenumbers)      {
00218                                                                 $setup[$this->multiLineObject.'.ln..'][]=($this->lineNumberOffset+$this->rawP-1);
00219                                                         }
00220                                                 }
00221                                         } else {
00222                                                 if ($this->syntaxHighLight)     $this->regHighLight("value",$lineP);
00223                                                 $this->multiLineValue[]=$this->raw[($this->rawP-1)];
00224                                         }
00225                                 } elseif ($this->inBrace==0 && substr($line,0,1)=='[')  {       // Beginning of condition (only on level zero compared to brace-levels
00226                                         if ($this->syntaxHighLight)     $this->regHighLight("condition",$lineP);
00227                                         return $line;
00228                                 } else {
00229                                         if (substr($line,0,1)=='[' && strtoupper(trim($line))=='[GLOBAL]')      {               // Return if GLOBAL condition is set - no matter what.
00230                                                 if ($this->syntaxHighLight)     $this->regHighLight("condition",$lineP);
00231                                                 $this->error('Line '.($this->lineNumberOffset+$this->rawP-1).': On return to [GLOBAL] scope, the script was short of '.$this->inBrace.' end brace(s)',1);
00232                                                 $this->inBrace=0;
00233                                                 return $line;
00234                                         } elseif (strcspn($line,'}#/')!=0)      {       // If not brace-end or comment
00235                                                 $varL = strcspn($line,' {=<>:(');       // Find object name string until we meet an operator
00236                                                 $objStrName=trim(substr($line,0,$varL));
00237                                                 if ($this->syntaxHighLight)     $this->regHighLight("objstr",$lineP,strlen(substr($line,$varL)));
00238                                                 if (strlen($objStrName)) {
00239                                                         $r = array();
00240                                                         if ($this->strict && preg_match('/[^[:alnum:]_\.-]/i',$objStrName,$r))  {
00241                                                                 $this->error('Line '.($this->lineNumberOffset+$this->rawP-1).': Object Name String, "'.htmlspecialchars($objStrName).'" contains invalid character "'.$r[0].'". Must be alphanumeric or one of: "_-."');
00242                                                         } else {
00243                                                                 $line = ltrim(substr($line,$varL));
00244                                                                 if ($this->syntaxHighLight)     {
00245                                                                         $this->regHighLight("objstr_postspace", $lineP, strlen($line));
00246                                                                         if (strlen($line)>0)    {
00247                                                                                 $this->regHighLight("operator", $lineP, strlen($line)-1);
00248                                                                                 $this->regHighLight("operator_postspace", $lineP, strlen(ltrim(substr($line,1))));
00249                                                                         }
00250                                                                 }
00251 
00252                                                                         // Checking for special TSparser properties (to change TS values at parsetime)
00253                                                                 $match = array();
00254                                                                 if (preg_match('/^:=([^\(]+)\((.+)\).*/', $line, $match))       {
00255                                                                         $tsFunc = trim($match[1]);
00256                                                                         $tsFuncArg = $match[2];
00257                                                                         list ($currentValue) = $this->getVal($objStrName,$setup);
00258 
00259                                                                         switch ($tsFunc)        {
00260                                                                                 case 'prependString':
00261                                                                                         $newValue = $tsFuncArg . $currentValue;
00262                                                                                 break;
00263                                                                                 case 'appendString':
00264                                                                                         $newValue = $currentValue . $tsFuncArg;
00265                                                                                 break;
00266                                                                                 case 'removeString':
00267                                                                                         $newValue = str_replace($tsFuncArg, '', $currentValue);
00268                                                                                 break;
00269                                                                                 case 'replaceString':
00270                                                                                         list($fromStr,$toStr) = explode('|', $tsFuncArg, 2);
00271                                                                                         $newValue = str_replace($fromStr, $toStr, $currentValue);
00272                                                                                 break;
00273                                                                                 case 'addToList':
00274                                                                                         $newValue = (strcmp('',$currentValue) ? $currentValue.',' : '') . trim($tsFuncArg);
00275                                                                                 break;
00276                                                                                 case 'removeFromList':
00277                                                                                         $existingElements = t3lib_div::trimExplode(',',$currentValue);
00278                                                                                         $removeElements = t3lib_div::trimExplode(',',$tsFuncArg);
00279                                                                                         if (count($removeElements))     {
00280                                                                                                 $newValue = implode(',', array_diff($existingElements, $removeElements));
00281                                                                                         }
00282                                                                                 break;
00283                                                                                 default:
00284                                                                                         if (isset($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tsparser.php']['preParseFunc'][$tsFunc]))   {
00285                                                                                                 $hookMethod = $TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tsparser.php']['preParseFunc'][$tsFunc];
00286                                                                                                 $params = array('currentValue'=>$currentValue, 'functionArgument'=>$tsFuncArg);
00287                                                                                                 $fakeThis = FALSE;
00288                                                                                                 $newValue = t3lib_div::callUserFunction($hookMethod,$params,$fakeThis);
00289                                                                                         } else {
00290                                                                                                 t3lib_div::sysLog('Missing function definition for '.$tsFunc.' on TypoScript line '.$lineP,'Core',2);
00291                                                                                         }
00292                                                                         }
00293 
00294                                                                         if (isset($newValue))   {
00295                                                                                 $line = '= '.$newValue;
00296                                                                         }
00297                                                                 }
00298 
00299                                                                 switch(substr($line,0,1))       {
00300                                                                         case '=':
00301                                                                                 if ($this->syntaxHighLight)     $this->regHighLight('value', $lineP, strlen(ltrim(substr($line,1)))-strlen(trim(substr($line,1))));
00302 
00303                                                                                 if (strstr($objStrName,'.'))    {
00304                                                                                         $value = Array();
00305                                                                                         $value[0] = trim(substr($line,1));
00306                                                                                         $this->setVal($objStrName,$setup,$value);
00307                                                                                 } else {
00308                                                                                         $setup[$objStrName] = trim(substr($line,1));
00309                                                                                         if ($this->lastComment && $this->regComments)   {       // Setting comment..
00310                                                                                                 $setup[$objStrName.'..'].=$this->lastComment;
00311                                                                                         }
00312                                                                                         if ($this->regLinenumbers)      {
00313                                                                                                 $setup[$objStrName.'.ln..'][]=($this->lineNumberOffset+$this->rawP-1);
00314                                                                                         }
00315                                                                                 }
00316                                                                         break;
00317                                                                         case '{':
00318                                                                                 $this->inBrace++;
00319                                                                                 if (strstr($objStrName,'.'))    {
00320                                                                                         $exitSig=$this->rollParseSub($objStrName,$setup);
00321                                                                                         if ($exitSig)   return $exitSig;
00322                                                                                 } else {
00323                                                                                         if (!isset($setup[$objStrName.'.'])) {$setup[$objStrName.'.'] = Array();}
00324                                                                                         $exitSig=$this->parseSub($setup[$objStrName.'.']);
00325                                                                                         if ($exitSig)   return $exitSig;
00326                                                                                 }
00327                                                                         break;
00328                                                                         case '(':
00329                                                                                 $this->multiLineObject = $objStrName;
00330                                                                                 $this->multiLineEnabled=1;
00331                                                                                 $this->multiLineValue=array();
00332                                                                         break;
00333                                                                         case '<':
00334                                                                                 if ($this->syntaxHighLight)     $this->regHighLight("value_copy", $lineP, strlen(ltrim(substr($line,1)))-strlen(trim(substr($line,1))));
00335                                                                                 $theVal = trim(substr($line,1));
00336                                                                                 if (substr($theVal,0,1)=='.') {
00337                                                                                         $res = $this->getVal(substr($theVal,1),$setup);
00338                                                                                 } else {
00339                                                                                         $res = $this->getVal($theVal,$this->setup);
00340                                                                                 }
00341                                                                                 $this->setVal($objStrName,$setup,unserialize(serialize($res)),1);       // 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.
00342                                                                         break;
00343                                                                         case '>':
00344                                                                                 if ($this->syntaxHighLight)     $this->regHighLight("value_unset", $lineP, strlen(ltrim(substr($line,1)))-strlen(trim(substr($line,1))));
00345                                                                                 $this->setVal($objStrName,$setup,'UNSET');
00346                                                                         break;
00347                                                                         default:
00348                                                                                 $this->error('Line '.($this->lineNumberOffset+$this->rawP-1).': Object Name String, "'.htmlspecialchars($objStrName).'" was not preceeded by any operator, =<>({');
00349                                                                         break;
00350                                                                 }
00351                                                         }
00352                                                         $this->lastComment='';
00353                                                 }
00354                                         } elseif (substr($line,0,1)=='}')       {
00355                                                 $this->inBrace--;
00356                                                 $this->lastComment='';
00357                                                 if ($this->syntaxHighLight)     $this->regHighLight("operator", $lineP, strlen($line)-1);
00358                                                 if ($this->inBrace<0)   {
00359                                                         $this->error('Line '.($this->lineNumberOffset+$this->rawP-1).': An end brace is in excess.',1);
00360                                                         $this->inBrace=0;
00361                                                 } else {
00362                                                         break;
00363                                                 }
00364                                         } else {
00365                                                 if ($this->syntaxHighLight)     $this->regHighLight("comment",  $lineP);
00366 
00367                                                         // Comment. The comments are concatenated in this temporary string:
00368                                                 if ($this->regComments) $this->lastComment.= trim($line).chr(10);
00369                                         }
00370                                 }
00371                         }
00372 
00373                                 // Unset comment
00374                         if ($this->commentSet)  {
00375                                 if ($this->syntaxHighLight)     $this->regHighLight("comment",  $lineP);
00376                                 if (substr($line,0,2)=='*/')    $this->commentSet=0;
00377                         }
00378                 }
00379         }
00380 
00389         function rollParseSub($string,&$setup)  {
00390                 if ((string)$string!='')        {
00391                         $keyLen = strcspn($string,'.');
00392                         if ($keyLen==strlen($string))   {
00393                                 $key = $string.'.';
00394                                 if (!isset($setup[$key])){$setup[$key]=Array();}
00395                                 $exitSig=$this->parseSub($setup[$key]);
00396                                 if ($exitSig)   return $exitSig;
00397                         } else {
00398                                 $key = substr($string,0,$keyLen).'.';
00399                                 if (!isset($setup[$key])){$setup[$key]=Array();}
00400                                 $exitSig=$this->rollParseSub(substr($string,$keyLen+1),$setup[$key]);
00401                                 if ($exitSig)   return $exitSig;
00402                         }
00403                 }
00404         }
00405 
00413         function getVal($string,$setup) {
00414                 if ((string)$string!='')        {
00415                         $keyLen = strcspn($string,'.');
00416                         if ($keyLen==strlen($string))   {
00417                                 $retArr=array();        // Added 6/6/03. Shouldn't hurt
00418                                 if (isset($setup[$string]))     {$retArr[0]=$setup[$string];    }
00419                                 if (isset($setup[$string.'.'])) {$retArr[1]=$setup[$string.'.'];        }
00420                                 return $retArr;
00421                         } else {
00422                                 $key = substr($string,0,$keyLen).'.';
00423                                 if ($setup[$key])       {
00424                                         return $this->getVal(substr($string,$keyLen+1),$setup[$key]);
00425                                 }
00426                         }
00427                 }
00428         }
00429 
00439         function setVal($string,&$setup,$value,$wipeOut=0)      {
00440                 if ((string)$string!='')        {
00441                         $keyLen = strcspn($string,'.');
00442                         if ($keyLen==strlen($string))   {
00443                                 if ($value=='UNSET')    {
00444                                         unset($setup[$string]);
00445                                         unset($setup[$string.'.']);
00446                                         if ($this->regLinenumbers)      {
00447                                                 $setup[$string.'.ln..'][]=($this->lineNumberOffset+$this->rawP-1).'>';
00448                                         }
00449                                 } else {
00450                                         $lnRegisDone=0;
00451                                         if ($wipeOut && $this->strict)  {
00452                                                 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);}
00453                                                 unset($setup[$string]);
00454                                                 unset($setup[$string.'.']);
00455                                                 if ($this->regLinenumbers)      {
00456                                                         $setup[$string.'.ln..'][]=($this->lineNumberOffset+$this->rawP-1).'<';
00457                                                         $lnRegisDone=1;
00458                                                 }
00459                                         }
00460                                         if (isset($value[0])) {$setup[$string] = $value[0];}
00461                                         if (isset($value[1])) {$setup[$string.'.'] = $value[1];}
00462                                         if ($this->lastComment && $this->regComments)   {
00463                                                 $setup[$string.'..'].=$this->lastComment;
00464                                         }
00465                                         if ($this->regLinenumbers && !$lnRegisDone)     {
00466                                                 $setup[$string.'.ln..'][]=($this->lineNumberOffset+$this->rawP-1);
00467                                         }
00468                                 }
00469                         } else {
00470                                 $key = substr($string,0,$keyLen).'.';
00471                                 if (!isset($setup[$key])){$setup[$key]=Array();}
00472                                 $this->setVal(substr($string,$keyLen+1),$setup[$key],$value);
00473                         }
00474                 }
00475         }
00476 
00485         function error($err,$num=2)     {
00486                 if (is_object($GLOBALS['TT']))  $GLOBALS['TT']->setTSlogMessage($err,$num);
00487                 $this->errors[]=array($err,$num,$this->rawP-1,$this->lineNumberOffset);
00488         }
00489 
00497         function checkIncludeLines($string)     {
00498                 $splitStr='<INCLUDE_TYPOSCRIPT:';
00499                 if (strstr($string,$splitStr))  {
00500                         $newString='';
00501                         $allParts = explode($splitStr,chr(10).$string.chr(10)); // adds line break char before/after
00502                         reset($allParts);
00503                         while(list($c,$v)=each($allParts))      {
00504                                 if (!$c)        {        // first goes through
00505                                         $newString.=$v;
00506                                 } elseif (preg_match('/\r?\n\s*$/',$allParts[$c-1]))    {       // There must be a line-break char before.
00507                                         $subparts=explode('>',$v,2);
00508                                         if (preg_match('/^\s*\r?\n/',$subparts[1]))     {       // There must be a line-break char after
00509                                                         // SO, the include was positively recognized:
00510                                                 $newString.='### '.$splitStr.$subparts[0].'> BEGIN:'.chr(10);
00511                                                 $params = t3lib_div::get_tag_attributes($subparts[0]);
00512                                                 if ($params['source'])  {
00513                                                         $sourceParts = explode(':',$params['source'],2);
00514                                                         switch(strtolower(trim($sourceParts[0])))       {
00515                                                                 case 'file':
00516                                                                         $filename = t3lib_div::getFileAbsFileName(trim($sourceParts[1]));
00517                                                                         if (strcmp($filename,''))       {       // Must exist and must not contain '..' and must be relative
00518                                                                                 if (@is_file($filename) && filesize($filename)<100000)  {       // Max. 100 KB include files!
00519                                                                                         $newString.=t3lib_div::getUrl($filename).chr(10);
00520                                                                                 }
00521                                                                         }
00522                                                                 break;
00523                                                         }
00524                                                 }
00525                                                 $newString.='### '.$splitStr.$subparts[0].'> END:'.chr(10);
00526                                                 $newString.=$subparts[1];
00527                                         } else $newString.=$splitStr.$v;
00528                                 } else $newString.=$splitStr.$v;
00529                         }
00530                         $string=substr($newString,1,-1);        // not the first/last linebreak char.
00531                 }
00532                 return $string;
00533         }
00534 
00541         function checkIncludeLines_array($array)        {
00542                 reset($array);
00543                 while(list($k)=each($array))    {
00544                         $array[$k]=t3lib_TSparser::checkIncludeLines($array[$k]);
00545                 }
00546                 return $array;
00547         }
00548 
00549 
00550 
00551 
00552 
00553 
00554 
00555 
00556 
00557 
00558 
00559 
00560 
00561 
00562 
00563 
00564 
00565 
00566 
00567 
00568 
00569         /**********************************
00570          *
00571          * Syntax highlighting
00572          *
00573          *********************************/
00574 
00584         function doSyntaxHighlight($string,$lineNum='',$highlightBlockMode=0)   {
00585                 $this->syntaxHighLight=1;
00586                 $this->highLightData=array();
00587                 $this->error=array();
00588                 $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.
00589 
00590                 $this->parse($string);
00591 
00592                 return $this->syntaxHighlight_print($lineNum,$highlightBlockMode);
00593         }
00594 
00605         function regHighLight($code,$pointer,$strlen=-1)        {
00606                 if ($strlen==-1)        {
00607                         $this->highLightData[$pointer] = array(array($code,0));
00608                 } else {
00609                         $this->highLightData[$pointer][] = array($code,$strlen);
00610                 }
00611                 $this->highLightData_bracelevel[$pointer] = $this->inBrace;
00612         }
00613 
00623         function syntaxHighlight_print($lineNumDat,$highlightBlockMode) {
00624                         // Registers all error messages in relation to their linenumber
00625                 $errA=array();
00626                 foreach($this->errors as $err)  {
00627                         $errA[$err[2]][]=$err[0];
00628                 }
00629                         // Generates the syntax highlighted output:
00630                 $lines=array();
00631                 foreach($this->raw as $rawP => $value)  {
00632                         $start=0;
00633                         $strlen=strlen($value);
00634                         $lineC='';
00635 
00636                         if (is_array($this->highLightData[$rawP]))      {
00637                                 foreach($this->highLightData[$rawP] as $set)    {
00638                                         $len = $strlen-$start-$set[1];
00639                                         if ($len > 0)   {
00640                                                 $part = substr($value,$start,$len);
00641                                                 $start+=$len;
00642                                                 $st = $this->highLightStyles[(isset($this->highLightStyles[$set[0]])?$set[0]:'default')];
00643                                                 if (!$highlightBlockMode || $set[0]!='prespace')                        $lineC.=$st[0].htmlspecialchars($part).$st[1];
00644                                         }elseif ($len < 0) debug(array($len,$value,$rawP));
00645                                 }
00646                         } else debug(array($value));
00647 
00648                         if (strlen(substr($value,$start)))      $lineC.=$this->highLightStyles['ignored'][0].htmlspecialchars(substr($value,$start)).$this->highLightStyles['ignored'][1];
00649 
00650                         if ($errA[$rawP])       {
00651                                 $lineC.=$this->highLightStyles['error'][0].'<strong> - ERROR:</strong> '.htmlspecialchars(implode(';',$errA[$rawP])).$this->highLightStyles['error'][1];
00652                         }
00653 
00654                         if ($highlightBlockMode && $this->highLightData_bracelevel[$rawP])      {
00655                                 $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>';
00656                         }
00657 
00658                         if (is_array($lineNumDat))      {
00659                                 $lineNum = $rawP+$lineNumDat[0];
00660                                 $lineC = $this->highLightStyles['linenum'][0].str_pad($lineNum,4,' ',STR_PAD_LEFT).':'.$this->highLightStyles['linenum'][1].' '.$lineC;
00661                         }
00662 
00663 
00664                         $lines[] = $lineC;
00665                 }
00666 
00667                 return '<pre class="ts-hl">'.implode(chr(10),$lines).'</pre>';
00668         }
00669 }
00670 
00671 
00672 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsparser.php'])  {
00673         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsparser.php']);
00674 }
00675 ?>


Généré par L'expert TYPO3 avec  doxygen 1.4.6