00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00083 require_once (PATH_t3lib.'class.t3lib_tsparser.php');
00084 require_once (PATH_t3lib.'class.t3lib_matchcondition.php');
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00109 class t3lib_TStemplate {
00110
00111
00112 var $tt_track = 1;
00113 var $forceTemplateParsing=0;
00114
00115
00116 var $matchAlternative=array();
00117 var $matchAll=0;
00118 var $parseEditorCfgField=0;
00119 var $backend_info = 0;
00120 var $getFileName_backPath='';
00121
00122
00123 var $ext_constants_BRP=0;
00124 var $ext_config_BRP=0;
00125 var $ext_editorcfg_BRP=0;
00126 var $ext_regLinenumbers=false;
00127 var $ext_regComments=false;
00128
00129
00130 var $uplPath = 'uploads/tf/';
00131 var $tempPath = 'typo3temp/';
00132 var $menuclasses = 'gmenu,tmenu,imgmenu,jsmenu';
00133
00134
00135 var $whereClause = '';
00136 var $debug = 0;
00137 var $allowedPaths = array();
00138 var $currentPageData = '';
00139 var $simulationHiddenOrTime=0;
00140
00141 var $loaded = 0;
00142 var $setup = Array(
00143 'styles.' => Array (
00144 'insertContent' => 'CONTENT',
00145 'insertContent.' => Array (
00146 'table' => 'tt_content',
00147 'select.' => Array (
00148 'orderBy' => 'sorting',
00149 'where' => 'colPos=0',
00150 'languageField' => 'sys_language_uid'
00151 )
00152 )
00153 ),
00154 'config.' => Array (
00155 'extTarget' => '_top',
00156 'stat' => 1,
00157 'stat_typeNumList' => '0,1'
00158 )
00159 );
00160 var $flatSetup = Array (
00161 );
00162 var $const = Array (
00163 '_clear' => '<img src="clear.gif" width="1" height="1" alt="" />',
00164 '_blackBorderWrap' => '<table border="0" bgcolor="black" cellspacing="0" cellpadding="1"><tr><td> | </td></tr></table>',
00165 '_tableWrap' => '<table border="0" cellspacing="0" cellpadding="0"> | </table>',
00166 '_tableWrap_DEBUG' => '<table border="1" cellspacing="0" cellpadding="0"> | </table>',
00167 '_stdFrameParams' => 'frameborder="no" marginheight="0" marginwidth="0" noresize="noresize"',
00168 '_stdFramesetParams' => 'border="0" framespacing="0" frameborder="no"'
00169 );
00170
00171
00172
00173 var $config = array();
00174 var $constants = array();
00175 var $editorcfg = array();
00176
00177 var $hierarchyInfo = array();
00178 var $hierarchyInfoToRoot = array();
00179 var $nextLevel=0;
00180 var $rootId;
00181 var $rootLine;
00182 var $absoluteRootLine;
00183 var $outermostRootlineIndexWithTemplate=0;
00184 var $rowSum;
00185 var $resources='';
00186 var $sitetitle='';
00187 var $sections;
00188 var $sectionsMatch;
00189
00190
00191 var $clearList_const=array();
00192 var $clearList_setup=array();
00193 var $clearList_editorcfg=array();
00194 var $parserErrors=array();
00195 var $setup_constants = array();
00196
00197
00198 var $fileCache = Array();
00199 var $frames = Array();
00200 var $MPmap = '';
00201
00202
00203
00204
00212 function init() {
00213
00214
00215 $this->whereClause='AND deleted=0 ';
00216 if (!$GLOBALS['TSFE']->showHiddenRecords) {
00217 $this->whereClause.='AND hidden=0 ';
00218 }
00219 if ($GLOBALS['TSFE']->showHiddenRecords || $GLOBALS['SIM_EXEC_TIME']!=$GLOBALS['EXEC_TIME']) {
00220 $this->simulationHiddenOrTime=1;
00221 }
00222 $this->whereClause.= 'AND (starttime<='.$GLOBALS['SIM_EXEC_TIME'].') AND (endtime=0 OR endtime>'.$GLOBALS['SIM_EXEC_TIME'].')';
00223 if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib']) {
00224 $this->menuclasses='tmenu,jsmenu,gmenu';
00225 }
00226
00227
00228 $this->allowedPaths = Array ('media/','fileadmin/','uploads/','typo3temp/','t3lib/fonts/',TYPO3_mainDir.'ext/',TYPO3_mainDir.'sysext/','typo3conf/ext/');
00229 if ($GLOBALS['TYPO3_CONF_VARS']['FE']['addAllowedPaths']) {
00230 $pathArr = t3lib_div::trimExplode(',',$GLOBALS['TYPO3_CONF_VARS']['FE']['addAllowedPaths'],1);
00231 while(list(,$p)=each($pathArr)) {
00232
00233 $this->allowedPaths[] = $p;
00234 }
00235 }
00236 }
00237
00250 function getCurrentPageData() {
00251 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('content', 'cache_pagesection', 'page_id='.intval($GLOBALS['TSFE']->id).' AND mpvar_hash='.t3lib_div::md5int($GLOBALS['TSFE']->MP));
00252 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00253 $this->currentPageData = unserialize($row['content']);
00254 } else {
00255 $this->currentPageData = 'none';
00256 }
00257 return $this->currentPageData;
00258 }
00259
00267 function matching($cc) {
00268 if (is_array($cc['all'])) {
00269 reset($cc['all']);
00270 $matchObj = t3lib_div::makeInstance('t3lib_matchCondition');
00271 $matchObj->altRootLine=$cc['rootLine'];
00272 while(list($key,$pre)=each($cc['all'])) {
00273 if ($matchObj->match($pre)) {
00274 $sectionsMatch[$key]=$pre;
00275 }
00276 }
00277 $cc['match']=$sectionsMatch;
00278 }
00279 return $cc;
00280 }
00281
00291 function start($theRootLine) {
00292 if (is_array($theRootLine)) {
00293 $setupData='';
00294 $cc=Array();
00295 $hash='';
00296 $this->runThroughTemplates($theRootLine);
00297
00298
00299 if (!$this->currentPageData && !$GLOBALS['TSFE']->no_cache) {
00300 $this->getCurrentPageData();
00301 }
00302
00303
00304
00305
00306 if (is_array($this->currentPageData) &&
00307 !strcmp(serialize($this->rowSum), serialize($this->currentPageData['rowSum']))
00308 ) {
00309
00310 $cc['all'] = $this->currentPageData['all'];
00311 $cc['rowSum'] = $this->currentPageData['rowSum'];
00312 $cc = $this->matching($cc);
00313 $hash = md5(serialize($cc));
00314 } else {
00315
00316 $rowSumHash = md5('ROWSUM:'.serialize($this->rowSum));
00317 $result = t3lib_pageSelect::getHash($rowSumHash, 0);
00318 if ($result) {
00319 $cc['all'] = unserialize($result);
00320 $cc['rowSum'] = $this->rowSum;
00321 $cc = $this->matching($cc);
00322 $hash = md5(serialize($cc));
00323 }
00324 }
00325
00326 if ($hash) {
00327
00328 $setupData = t3lib_pageSelect::getHash($hash, 0);
00329 }
00330
00331 if ($hash && $setupData && !$this->forceTemplateParsing) {
00332
00333 $this->setup = unserialize($setupData);
00334 } else {
00335
00336 $this->generateConfig();
00337
00338
00339 $cc=Array();
00340 $cc['all']=$this->sections;
00341 $cc['rowSum']=$this->rowSum;
00342 $cc = $this->matching($cc);
00343
00344 $hash = md5(serialize($cc));
00345
00346
00347 t3lib_pageSelect::storeHash($hash, serialize($this->setup), 'TS TEMPLATE');
00348
00349 if ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('TS template size, serialized: '.strlen(serialize($this->setup)).' bytes');
00350
00351 $rowSumHash = md5('ROWSUM:'.serialize($this->rowSum));
00352 t3lib_pageSelect::storeHash($rowSumHash, serialize($cc['all']), 'TMPL CONDITIONS - AL');
00353 }
00354
00355 $cc['rootLine'] = $this->rootLine;
00356
00357 $GLOBALS['TSFE']->all=$cc;
00358
00359 if (!$this->simulationHiddenOrTime && !$GLOBALS['TSFE']->no_cache) {
00360 $dbFields = array(
00361 'content' => serialize($cc),
00362 'tstamp' => $GLOBALS['EXEC_TIME']
00363 );
00364 $mpvar_hash = t3lib_div::md5int($GLOBALS['TSFE']->MP);
00365 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('cache_pagesection', 'page_id=' . intval($GLOBALS['TSFE']->id) . ' AND mpvar_hash=' . $mpvar_hash, $dbFields);
00366 if ($GLOBALS['TYPO3_DB']->sql_affected_rows() == 0) {
00367 $dbFields['page_id'] = intval($GLOBALS['TSFE']->id);
00368 $dbFields['mpvar_hash'] = $mpvar_hash;
00369 $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_pagesection', $dbFields);
00370 }
00371 }
00372
00373 if ($this->rootId && $this->rootLine && $this->setup) {
00374 $this->loaded = 1;
00375 }
00376 }
00377 }
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00409 function runThroughTemplates($theRootLine,$start_template_uid=0) {
00410 $this->constants = Array();
00411 $this->config = Array();
00412 $this->editorcfg = Array();
00413 $this->rowSum = Array();
00414 $this->hierarchyInfoToRoot = Array();
00415 $this->absoluteRootLine=$theRootLine;
00416
00417 reset ($this->absoluteRootLine);
00418 $c=count($this->absoluteRootLine);
00419 for ($a=0;$a<$c;$a++) {
00420 if ($this->nextLevel) {
00421 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'uid='.intval($this->nextLevel).' '.$this->whereClause);
00422 $this->nextLevel = 0;
00423 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00424 $this->versionOL($row);
00425 if (is_array($row)) {
00426 $this->processTemplate($row,'sys_'.$row['uid'],$this->absoluteRootLine[$a]['uid'],'sys_'.$row['uid']);
00427 $this->outermostRootlineIndexWithTemplate=$a;
00428 }
00429 }
00430 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00431 }
00432 $addC='';
00433 if ($a==($c-1) && $start_template_uid) {
00434 $addC=' AND uid='.intval($start_template_uid);
00435 }
00436
00437 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid='.intval($this->absoluteRootLine[$a]['uid']).$addC.' '.$this->whereClause,'','sorting',1);
00438 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00439 $this->versionOL($row);
00440 if (is_array($row)) {
00441 $this->processTemplate($row,'sys_'.$row['uid'],$this->absoluteRootLine[$a]['uid'],'sys_'.$row['uid']);
00442 $this->outermostRootlineIndexWithTemplate=$a;
00443 }
00444 }
00445 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00446 $this->rootLine[] = $this->absoluteRootLine[$a];
00447 }
00448 }
00449
00462 function processTemplate($row, $idList,$pid,$templateID='',$templateParent='') {
00463
00464 $this->rowSum[]=Array($row['uid'],$row['title'],$row['tstamp']);
00465
00466
00467 if ($row['clear']) {
00468 $clConst = $row['clear']&1;
00469 $clConf = $row['clear']&2;
00470 if ($clConst) {
00471 $this->constants = Array();
00472 $this->clearList_const=array();
00473 }
00474 if ($clConf) {
00475 $this->config = Array();
00476 $this->hierarchyInfoToRoot = Array();
00477 $this->clearList_setup=array();
00478
00479 $this->editorcfg = Array();
00480 $this->clearList_editorcfg=array();
00481 }
00482 }
00483
00484
00485 if (!$row['includeStaticAfterBasedOn']) {
00486 $this->includeStaticTypoScriptSources($idList,$templateID,$pid,$row);
00487 }
00488
00489
00490 if (trim($row['basedOn'])) {
00491
00492
00493
00494 $basedOn_hackFeature = explode('=',$row['basedOn']);
00495 if ($basedOn_hackFeature[0]=='EXTERNAL_BASED_ON_TEMPLATE_ID' && $basedOn_hackFeature[1]) {
00496 $id = intval(t3lib_div::_GET($basedOn_hackFeature[1]));
00497 if ($id && !t3lib_div::inList($idList,'sys_'.$id)) {
00498 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'uid='.$id.' '.$this->whereClause);
00499 if ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00500 $this->versionOL($subrow);
00501 if (is_array($subrow)) {
00502 $this->processTemplate($subrow,$idList.',sys_'.$id,$pid, 'sys_'.$id,$templateID);
00503 }
00504 }
00505 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00506 }
00507 } else {
00508 $basedOnArr = t3lib_div::intExplode(',',$row['basedOn']);
00509 while(list(,$id)=each($basedOnArr)) {
00510 if (!t3lib_div::inList($idList,'sys_'.$id)) {
00511 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'uid='.intval($id).' '.$this->whereClause);
00512 if ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00513 $this->versionOL($subrow);
00514 if (is_array($subrow)) {
00515 $this->processTemplate($subrow,$idList.',sys_'.$id,$pid, 'sys_'.$id,$templateID);
00516 }
00517 }
00518 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00519 }
00520 }
00521 }
00522 }
00523
00524
00525 if ($row['includeStaticAfterBasedOn']) {
00526 $this->includeStaticTypoScriptSources($idList,$templateID,$pid,$row);
00527 }
00528
00529
00530 $this->hierarchyInfo[] = $this->hierarchyInfoToRoot[] = array(
00531 'root'=>trim($row['root']),
00532 'next'=>$row['nextLevel'],
00533 'clConst'=>$clConst,
00534 'clConf'=>$clConf,
00535 'templateID'=>$templateID,
00536 'templateParent'=>$templateParent,
00537 'title'=>$row['title'],
00538 'uid'=>$row['uid'],
00539 'pid'=>$row['pid'],
00540 'configLines' => substr_count($row['config'], chr(10))+1
00541 );
00542
00543
00544 $this->constants[] = $row['constants'];
00545 $this->config[] = $row['config'];
00546 if ($this->parseEditorCfgField) $this->editorcfg[] = $row['editorcfg'];
00547
00548
00549 $this->clearList_const[]=$templateID;
00550 $this->clearList_setup[]=$templateID;
00551 if ($this->parseEditorCfgField) $this->clearList_editorcfg[]=$templateID;
00552
00553
00554 if (trim($row['resources'])) {
00555 $this->resources = $row['resources'].','.$this->resources;
00556 }
00557 if (trim($row['sitetitle'])) {
00558 $this->sitetitle = $row['sitetitle'];
00559 }
00560
00561 if (trim($row['root'])) {
00562 $this->rootId = $pid;
00563 $this->rootLine = Array();
00564 }
00565
00566 if ($row['nextLevel']) {
00567 $this->nextLevel = $row['nextLevel'];
00568 } else {
00569 $this->nextLevel = 0;
00570 }
00571 }
00572
00583 function includeStaticTypoScriptSources($idList,$templateID,$pid,$row) {
00584
00585 if (trim($row['include_static'])) {
00586 $include_staticArr = t3lib_div::intExplode(',',$row['include_static']);
00587 reset($include_staticArr);
00588 while(list(,$id)=each($include_staticArr)) {
00589 if (!t3lib_div::inList($idList,'static_'.$id)) {
00590 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'static_template', 'uid='.intval($id));
00591 if ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00592 $subrow = $this->prependStaticExtra($subrow);
00593 $this->processTemplate($subrow,$idList.',static_'.$id,$pid,'static_'.$id,$templateID);
00594 }
00595 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00596 }
00597 }
00598 }
00599
00600
00601 if (trim($row['include_static_file'])) {
00602 $include_static_fileArr = t3lib_div::trimExplode(',',$row['include_static_file'],1);
00603 reset($include_static_fileArr);
00604 while(list(,$ISF_file)=each($include_static_fileArr)) {
00605 $ISF_file = trim($ISF_file);
00606 if (substr($ISF_file,0,4)=='EXT:') {
00607 list($ISF_extKey,$ISF_localPath) = explode('/',substr($ISF_file,4),2);
00608 if (strcmp($ISF_extKey,'') && t3lib_extMgm::isLoaded($ISF_extKey) && strcmp($ISF_localPath,'')) {
00609 $ISF_localPath = ereg_replace('\/$','',$ISF_localPath).'/';
00610 $ISF_filePath = t3lib_extMgm::extPath($ISF_extKey).$ISF_localPath;
00611 if (@is_dir($ISF_filePath)) {
00612 $mExtKey = str_replace('_','',$ISF_extKey.'/'.$ISF_localPath);
00613 $subrow=array(
00614 'constants'=> @is_file($ISF_filePath.'constants.txt') ?t3lib_div::getUrl($ISF_filePath.'constants.txt'):'',
00615 'config'=> @is_file($ISF_filePath.'setup.txt') ?t3lib_div::getUrl($ISF_filePath.'setup.txt'):'',
00616 'editorcfg'=> @is_file($ISF_filePath.'editorcfg.txt') ?t3lib_div::getUrl($ISF_filePath.'editorcfg.txt'):'',
00617 'include_static'=> @is_file($ISF_filePath.'include_static.txt')?implode(',',array_unique(t3lib_div::intExplode(',',t3lib_div::getUrl($ISF_filePath.'include_static.txt')))):'',
00618 'include_static_file'=> @is_file($ISF_filePath.'include_static_file.txt')?implode(',',array_unique(explode(',',t3lib_div::getUrl($ISF_filePath.'include_static_file.txt')))):'',
00619 'title' => $ISF_file,
00620 'uid' => $mExtKey
00621 );
00622 $subrow = $this->prependStaticExtra($subrow);
00623
00624 $this->processTemplate($subrow,$idList.',ext_'.$mExtKey,$pid, 'ext_'.$mExtKey,$templateID);
00625 }
00626 }
00627 }
00628 }
00629 }
00630
00631 $this->addExtensionStatics($idList,$templateID,$pid,$row);
00632 }
00633
00645 function addExtensionStatics($idList,$templateID,$pid,$row) {
00646 global $TYPO3_LOADED_EXT;
00647
00648 if ($row['static_file_mode']==1 || ($row['static_file_mode']==0 && substr($templateID,0,4)=='sys_' && $row['root'])) {
00649 reset($TYPO3_LOADED_EXT);
00650 while(list($extKey,$files)=each($TYPO3_LOADED_EXT)) {
00651 if (is_array($files) && ($files['ext_typoscript_constants.txt'] || $files['ext_typoscript_setup.txt'] || $files['ext_typoscript_editorcfg.txt'])) {
00652 $mExtKey = str_replace('_','',$extKey);
00653 $subrow=array(
00654 'constants'=> $files['ext_typoscript_constants.txt']?t3lib_div::getUrl($files['ext_typoscript_constants.txt']):'',
00655 'config'=> $files['ext_typoscript_setup.txt']?t3lib_div::getUrl($files['ext_typoscript_setup.txt']):'',
00656 'editorcfg'=> $files['ext_typoscript_editorcfg.txt']?t3lib_div::getUrl($files['ext_typoscript_editorcfg.txt']):'',
00657 'title' => $extKey,
00658 'uid' => $mExtKey
00659 );
00660 $subrow = $this->prependStaticExtra($subrow);
00661
00662 $this->processTemplate($subrow,$idList.',ext_'.$mExtKey,$pid, 'ext_'.$mExtKey,$templateID);
00663 }
00664 }
00665 }
00666 }
00667
00678 function prependStaticExtra($subrow) {
00679 $subrow['config'].=$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'][$subrow['uid']];
00680 $subrow['editorcfg'].=$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_editorcfg.'][$subrow['uid']];
00681 $subrow['constants'].=$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants.'][$subrow['uid']];
00682 return $subrow;
00683 }
00684
00691 function versionOL(&$row) {
00692 if (is_object($GLOBALS['TSFE'])) {
00693 $GLOBALS['TSFE']->sys_page->versionOL('sys_template',$row);
00694 } else {
00695 t3lib_BEfunc::workspaceOL('sys_template',$row);
00696 }
00697 }
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00728 function generateConfig() {
00729
00730 array_unshift($this->constants,''.$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants']);
00731 array_unshift($this->config,''.$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup']);
00732 array_unshift($this->editorcfg,''.$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_editorcfg']);
00733
00734
00735 $this->procesIncludes();
00736
00737
00738 $this->setup['resources']= $this->resources;
00739 $this->setup['sitetitle']= $this->sitetitle;
00740
00741
00742
00743
00744
00745
00746
00747
00748 $constants = t3lib_div::makeInstance('t3lib_TSparser');
00749 $constants->breakPointLN=intval($this->ext_constants_BRP);
00750 $constants->setup = $this->const;
00751 $constants->setup = $this->mergeConstantsFromPageTSconfig($constants->setup);
00752 $matchObj = t3lib_div::makeInstance('t3lib_matchCondition');
00753 $matchObj->matchAlternative = $this->matchAlternative;
00754 $matchObj->matchAll = $this->matchAll;
00755
00756
00757 foreach($this->constants as $str) {
00758 $constants->parse($str,$matchObj);
00759 }
00760
00761
00762 $this->parserErrors['constants']=$constants->errors;
00763
00764
00765 $this->flatSetup = Array();
00766 $this->flattenSetup($constants->setup,'','');
00767
00768
00769
00770
00771
00772
00773
00774 $config = t3lib_div::makeInstance('t3lib_TSparser');
00775 $config->breakPointLN = intval($this->ext_config_BRP);
00776 $config->regLinenumbers = $this->ext_regLinenumbers;
00777 $config->regComments = $this->ext_regComments;
00778 $config->setup = $this->setup;
00779
00780
00781 $config->sections = $constants->sections;
00782 $config->sectionsMatch = $constants->sectionsMatch;
00783
00784
00785 $all='';
00786 foreach($this->config as $str) {
00787 $all.="\n[GLOBAL]\n".$str;
00788 }
00789
00790
00791 if ($this->tt_track) $GLOBALS['TT']->push('Substitute Constants ('.count($this->flatSetup).')');
00792 $all = $this->substituteConstants($all);
00793 if ($this->tt_track) $GLOBALS['TT']->pull();
00794
00795
00796 if (strstr($all,'{$')) {
00797 $findConst = explode('{$',$all);
00798 $theConstList=Array();
00799 next($findConst);
00800 while(list(,$constVal)=each($findConst)) {
00801 $constLen=t3lib_div::intInRange(strcspn($constVal,'}'),0,50);
00802 $theConstList[]='{$'.substr($constVal,0,$constLen+1);
00803 }
00804 if ($this->tt_track) $GLOBALS['TT']->setTSlogMessage(implode(',',$theConstList).': Constants may remain un-substituted!!',2);
00805 }
00806
00807
00808 if ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('TypoScript template size as textfile: '.strlen($all).' bytes');
00809
00810
00811 $config->parse($all,$matchObj);
00812
00813
00814 $this->parserErrors['config']=$config->errors;
00815
00816
00817 $this->setup = $config->setup;
00818 if ($this->backend_info) {
00819 $this->setup_constants = $constants->setup;
00820 }
00821
00822
00823
00824
00825
00826
00827
00828 if ($this->parseEditorCfgField) {
00829 $editorcfg = t3lib_div::makeInstance('t3lib_TSparser');
00830 $editorcfg->breakPointLN=intval($this->ext_editorcfg_BRP);
00831 $editorcfg->setup = array();
00832
00833 $all = implode("\n[GLOBAL]\n",$this->editorcfg);
00834
00835
00836 $all = $this->substituteConstants($all);
00837
00838
00839 $matchObj->matchAll=1;
00840 $editorcfg->parse($all,$matchObj);
00841 $this->parserErrors['editorcfg']=$editorcfg->errors;
00842 $this->setup_editorcfg = $editorcfg->setup;
00843 }
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855 unset($this->setup['resources']);
00856 unset($this->setup['resources.']);
00857 $this->setup['resources']= implode(',',t3lib_div::trimExplode(',',$this->resources,1));
00858
00859 unset($this->setup['sitetitle']);
00860 unset($this->setup['sitetitle.']);
00861 $this->setup['sitetitle']= $this->sitetitle;
00862
00863
00864 unset($this->setup['types.']);
00865 unset($this->setup['types']);
00866 if (is_array($this->setup)) {
00867 reset ($this->setup);
00868 while(list($theKey,)=each($this->setup)) {
00869 if ($this->setup[$theKey]=='PAGE') {
00870 $tN = $this->setup[$theKey.'.']['typeNum'];
00871 if (isset($tN)) {
00872 $this->setup['types.'][$tN] = $theKey;
00873 } elseif(!$this->setup['types.'][0]) {
00874 $this->setup['types.'][0] = $theKey;
00875 }
00876 }
00877 }
00878 }
00879 unset($this->setup['styles.']);
00880 unset($this->setup['temp.']);
00881 unset($constants);
00882
00883
00884 $this->sections = $config->sections;
00885 $this->sectionsMatch = $config->sectionsMatch;
00886 }
00887
00895 function procesIncludes() {
00896 reset($this->constants);
00897 while(list($k)=each($this->constants)) {
00898 $this->constants[$k]=t3lib_TSparser::checkIncludeLines($this->constants[$k]);
00899 }
00900
00901 reset($this->config);
00902 while(list($k)=each($this->config)) {
00903 $this->config[$k]=t3lib_TSparser::checkIncludeLines($this->config[$k]);
00904 }
00905
00906 reset($this->editorcfg);
00907 while(list($k)=each($this->editorcfg)) {
00908 $this->editorcfg[$k]=t3lib_TSparser::checkIncludeLines($this->editorcfg[$k]);
00909 }
00910 }
00911
00919 function mergeConstantsFromPageTSconfig($constArray) {
00920 $TSdataArray = array();
00921 $TSdataArray[]=$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig'];
00922
00923 for ($a=0;$a<=$this->outermostRootlineIndexWithTemplate;$a++) {
00924 $TSdataArray[]=$this->absoluteRootLine[$a]['TSconfig'];
00925 }
00926
00927 $TSdataArray = t3lib_TSparser::checkIncludeLines_array($TSdataArray);
00928 $userTS = implode(chr(10).'[GLOBAL]'.chr(10),$TSdataArray);
00929
00930 $parseObj = t3lib_div::makeInstance('t3lib_TSparser');
00931 $parseObj->parse($userTS);
00932
00933 if (is_array($parseObj->setup['TSFE.']['constants.'])) {
00934 $constArray = t3lib_div::array_merge_recursive_overrule($constArray,$parseObj->setup['TSFE.']['constants.']);
00935 }
00936 return $constArray;
00937 }
00938
00948 function flattenSetup($setupArray, $prefix, $resourceFlag) {
00949 if (is_array($setupArray)) {
00950 reset($setupArray);
00951 while(list($key,$val)=each($setupArray)) {
00952 if ($prefix || substr($key,0,16)!='TSConstantEditor') {
00953 if (is_array($val)) {
00954 $this->flattenSetup($val,$prefix.$key, ($key=='file.'));
00955 } elseif ($resourceFlag) {
00956 $this->flatSetup[$prefix.$key] = $this->getFileName($val);
00957 } else {
00958 $this->flatSetup[$prefix.$key] = $val;
00959 }
00960 }
00961 }
00962 }
00963 }
00964
00972 function substituteConstants($all) {
00973 if ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('Constants to substitute: '.count($this->flatSetup));
00974
00975 $noChange = false;
00976
00977 for ($i = 0; $i < 10 && !$noChange; $i++) {
00978 $old_all = $all;
00979 $all = preg_replace_callback('/\{\$(.[^}]*)\}/', array($this, 'substituteConstantsCallBack'), $all);
00980 if ($old_all == $all) {
00981 $noChange = true;
00982 }
00983 }
00984
00985 return $all;
00986 }
00987
00995 function substituteConstantsCallBack($matches) {
00996
00997 return isset($this->flatSetup[$matches[1]]) && !is_array($this->flatSetup[$matches[1]]) ? $this->flatSetup[$matches[1]] : $matches[0];
00998 }
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01026 function splitConfArray($conf,$splitCount) {
01027
01028
01029 $splitCount = intval($splitCount);
01030 $conf2 = Array();
01031
01032 if ($splitCount && is_array($conf)) {
01033
01034
01035 for ($aKey=0;$aKey<$splitCount;$aKey++) {
01036 $conf2[$aKey] = array();
01037 }
01038
01039
01040 foreach($conf as $cKey => $val) {
01041 if (is_array($val)) {
01042 $tempConf = $this->splitConfArray($val,$splitCount);
01043 foreach($tempConf as $aKey => $val) {
01044 $conf2[$aKey][$cKey] = $val;
01045 }
01046 }
01047 }
01048
01049
01050 foreach($conf as $cKey => $val) {
01051 if (!is_array($val)) {
01052 if (!strstr($val,'|*|') && !strstr($val,'||')) {
01053 for ($aKey=0;$aKey<$splitCount;$aKey++) {
01054 $conf2[$aKey][$cKey] = $val;
01055 }
01056 } else {
01057 $main = explode ('|*|',$val);
01058 $mainCount = count($main);
01059
01060 $lastC = 0;
01061 $middleC = 0;
01062 $firstC = 0;
01063
01064 if ($main[0]) {
01065 $first = explode('||',$main[0]);
01066 $firstC = count($first);
01067 }
01068 if ($main[1]) {
01069 $middle = explode('||',$main[1]);
01070 $middleC = count($middle);
01071 }
01072 if ($main[2]) {
01073 $last = explode('||',$main[2]);
01074 $lastC = count($last);
01075 $value = $last[0];
01076 }
01077
01078 for ($aKey=0;$aKey<$splitCount;$aKey++) {
01079 if ($firstC && isset($first[$aKey])) {
01080 $value = $first[$aKey];
01081 } elseif ($middleC) {
01082 $value = $middle[($aKey-$firstC)%$middleC];
01083 }
01084 if ($lastC && $lastC>=($splitCount-$aKey)) {
01085 $value = $last[$lastC-($splitCount-$aKey)];
01086 }
01087 $conf2[$aKey][$cKey] = trim($value);
01088 }
01089 }
01090 }
01091 }
01092 }
01093 return $conf2;
01094 }
01095
01103 function getFileName($fileFromSetup) {
01104 $file = trim($fileFromSetup);
01105 if (!$file) {
01106 return;
01107 } elseif (strstr($file,'../')) {
01108 if ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('File path "'.$file.'" contained illegal string "../"!',3);
01109 return;
01110 }
01111
01112 $hash = md5($file);
01113 if (isset($this->fileCache[$hash])) {
01114 return $this->fileCache[$hash];
01115 }
01116
01117 if (!strcmp(substr($file,0,4),'EXT:')) {
01118 $newFile='';
01119 list($extKey,$script)=explode('/',substr($file,4),2);
01120 if ($extKey && t3lib_extMgm::isLoaded($extKey)) {
01121 $extPath=t3lib_extMgm::extPath($extKey);
01122 $newFile=substr($extPath,strlen(PATH_site)).$script;
01123 }
01124 if (!@is_file(PATH_site.$newFile)) {
01125 if ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('Extension media file "'.$newFile.'" was not found!',3);
01126 return;
01127 } else $file=$newFile;
01128 }
01129
01130
01131 if (strstr($file,'/')) {
01132 if(!strcmp(substr($file,0,6),'media/')) $file = 'typo3/sysext/cms/tslib/'.$file;
01133 if (@is_file($this->getFileName_backPath.$file)) {
01134 $outFile = $file;
01135 $fileInfo = t3lib_div::split_fileref($outFile);
01136 reset($this->allowedPaths);
01137 $OK=0;
01138 while(list(,$val)=each($this->allowedPaths)) {
01139 if (substr($fileInfo['path'],0,strlen($val))==$val){$OK=1; break;}
01140 }
01141 if ($OK) {
01142 $this->fileCache[$hash]=$outFile;
01143 return $outFile;
01144 } elseif ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('"'.$file.'" was not located in the allowed paths: ('.implode(',',$this->allowedPaths).')',3);
01145 } elseif ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('"'.$this->getFileName_backPath.$file.'" is not a file (non-uploads/.. resource, did not exist).',3);
01146 } else { // Here it is uploaded media:
01147 $outFile = $this->extractFromResources($this->setup['resources'],$file);
01148 if ($outFile) {
01149 if (@is_file($this->uplPath.$outFile)) {
01150 $this->fileCache[$hash] = $this->uplPath.$outFile;
01151 return $this->uplPath.$outFile;
01152 } elseif ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('"'.$this->uplPath.$outFile.'" is not a file (did not exist).',3);
01153 } elseif ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('"'.$file.'" is not a file (uploads/.. resource).',3);
01154 }
01155 }
01156
01166 function extractFromResources($res,$file) {
01167 if (t3lib_div::inList($res,$file)) {
01168 $outFile = $file;
01169 } elseif (strstr($file,'*')) {
01170 $fileparts=explode('*',$file);
01171 $c=count($fileparts);
01172 $files = explode(',',$res);
01173 while(list(,$val)=each($files)) {
01174 $test = trim($val);
01175 if (ereg('^'.quotemeta($fileparts[0]).'.*'.quotemeta($fileparts[$c-1]).'$', $test)) {
01176 $outFile = $test;
01177 break;
01178 }
01179 }
01180 }
01181 return $outFile;
01182 }
01183
01194 function checkFile($name,$menuArr) {
01195 reset ($menuArr);
01196 while (list($aKey,)=each($menuArr)) {
01197 $menuArr[$aKey][$name] = $this->getFileName($menuArr[$aKey][$name]);
01198 }
01199 return $menuArr;
01200 }
01201
01211 function printTitle($title,$no_title=0,$titleFirst=0) {
01212 $st = trim($this->setup['sitetitle']) ? $this->setup['sitetitle']:'';
01213 $title = $no_title ? '' : $title;
01214 if ($titleFirst) {
01215 $temp=$st;
01216 $st=$title;
01217 $title=$temp;
01218 }
01219 if ($title && $st) {
01220 return $st.': '.$title;
01221 } else {
01222 return $st.$title;
01223 }
01224 }
01225
01234 function fileContent($fName) {
01235 $incFile = $this->getFileName($fName);
01236 if ($incFile) {
01237 return @file_get_contents($incFile);
01238 }
01239 }
01240
01249 function wrap($content,$wrap) {
01250 if ($wrap) {
01251 $wrapArr = explode('|', $wrap);
01252 return trim($wrapArr[0]).$content.trim($wrapArr[1]);
01253 } else return $content;
01254 }
01255
01263 function removeQueryString($url) {
01264 if (substr($url,-1)=='?') {
01265 return substr($url,0,-1);
01266 } else {
01267 return $url;
01268 }
01269 }
01270
01280 function sortedKeyList($setupArr, $acceptOnlyProperties=FALSE) {
01281 $keyArr = Array();
01282
01283 reset($setupArr);
01284 while(list($key,)=each($setupArr)) {
01285 $ikey = intval($key);
01286 if (!strcmp($ikey,$key) || $acceptOnlyProperties) {
01287 $keyArr[] = $ikey;
01288 }
01289 }
01290
01291 $keyArr = array_unique($keyArr);
01292 sort($keyArr);
01293 return $keyArr;
01294 }
01295
01296
01297
01298
01299
01300
01301
01302
01303
01304
01305 /*******************************************************************
01306 *
01307 * Functions for creating links
01308 *
01309 *******************************************************************/
01310
01327 function linkData($page,$oTarget,$no_cache,$script,$overrideArray='',$addParams='',$typeOverride='') {
01328 global $TYPO3_CONF_VARS;
01329
01330 $LD = Array();
01331
01332 // Overriding some fields in the page record and still preserves the values by adding them as parameters. Little strange function.
01333 if (is_array($overrideArray)) {
01334 foreach($overrideArray as $theKey => $theNewVal) {
01335 $addParams.= '&real_'.$theKey.'='.rawurlencode($page[$theKey]);
01336 $page[$theKey] = $theNewVal;
01337 }
01338 }
01339
01340 // Adding Mount Points, "&MP=", parameter for the current page if any is set:
01341 if (!strstr($addParams,'&MP=')) {
01342 if (trim($GLOBALS['TSFE']->MP_defaults[$page['uid']])) { // Looking for hardcoded defaults:
01343 $addParams.= '&MP='.rawurlencode(trim($GLOBALS['TSFE']->MP_defaults[$page['uid']]));
01344 } elseif ($GLOBALS['TSFE']->config['config']['MP_mapRootPoints']) { // Else look in automatically created map:
01345 $m = $this->getFromMPmap($page['uid']);
01346 if ($m) {
01347 $addParams.= '&MP='.rawurlencode($m);
01348 }
01349 }
01350 }
01351
01352 // Setting ID/alias:
01353 if (!$script) {$script = $GLOBALS['TSFE']->config['mainScript'];}
01354 if ($page['alias']) {