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
00128
00129 var $uplPath = 'uploads/tf/';
00130 var $tempPath = 'typo3temp/';
00131 var $menuclasses = 'gmenu,tmenu,imgmenu,jsmenu';
00132
00133
00134 var $whereClause = '';
00135 var $debug = 0;
00136 var $allowedPaths = array();
00137 var $currentPageData = '';
00138 var $simulationHiddenOrTime=0;
00139
00140 var $loaded = 0;
00141 var $setup = Array(
00142 'styles.' => Array (
00143 'insertContent' => 'CONTENT',
00144 'insertContent.' => Array (
00145 'table' => 'tt_content',
00146 'select.' => Array (
00147 'orderBy' => 'sorting',
00148 'where' => 'colPos=0',
00149 'languageField' => 'sys_language_uid'
00150 )
00151 )
00152 ),
00153 'config.' => Array (
00154 'extTarget' => '_top',
00155 'stat' => 1,
00156 'stat_typeNumList' => '0,1'
00157 )
00158 );
00159 var $flatSetup = Array (
00160 );
00161 var $const = Array (
00162 '_clear' => '<img src="clear.gif" width="1" height="1" alt="" />',
00163 '_blackBorderWrap' => '<table border="0" bgcolor="black" cellspacing="0" cellpadding="1"><tr><td> | </td></tr></table>',
00164 '_tableWrap' => '<table border="0" cellspacing="0" cellpadding="0"> | </table>',
00165 '_tableWrap_DEBUG' => '<table border="1" cellspacing="0" cellpadding="0"> | </table>',
00166 '_stdFrameParams' => 'frameborder="no" marginheight="0" marginwidth="0" noresize="noresize"',
00167 '_stdFramesetParams' => 'border="0" framespacing="0" frameborder="no"'
00168 );
00169
00170
00171
00172 var $config = array();
00173 var $constants = array();
00174 var $editorcfg = array();
00175
00176 var $hierarchyInfo = array();
00177 var $hierarchyInfoToRoot = array();
00178 var $nextLevel=0;
00179 var $rootId;
00180 var $rootLine;
00181 var $absoluteRootLine;
00182 var $outermostRootlineIndexWithTemplate=0;
00183 var $rowSum;
00184 var $resources='';
00185 var $sitetitle='';
00186 var $sections;
00187 var $sectionsMatch;
00188
00189
00190 var $clearList_const=array();
00191 var $clearList_setup=array();
00192 var $clearList_editorcfg=array();
00193 var $parserErrors=array();
00194 var $setup_constants = array();
00195
00196
00197 var $fileCache = Array();
00198 var $frames = Array();
00199 var $MPmap = '';
00200
00201
00202
00203
00211 function init() {
00212
00213
00214 $this->whereClause='AND deleted=0 ';
00215 if (!$GLOBALS['TSFE']->showHiddenRecords) {
00216 $this->whereClause.='AND hidden=0 ';
00217 }
00218 if ($GLOBALS['TSFE']->showHiddenRecords || $GLOBALS['SIM_EXEC_TIME']!=$GLOBALS['EXEC_TIME']) {
00219 $this->simulationHiddenOrTime=1;
00220 }
00221 $this->whereClause.= 'AND (starttime<='.$GLOBALS['SIM_EXEC_TIME'].') AND (endtime=0 OR endtime>'.$GLOBALS['SIM_EXEC_TIME'].')';
00222 if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib']) {
00223 $this->menuclasses='tmenu,jsmenu,gmenu';
00224 }
00225
00226
00227 $this->allowedPaths = Array ('media/','fileadmin/','uploads/','typo3temp/','t3lib/fonts/',TYPO3_mainDir.'ext/',TYPO3_mainDir.'sysext/','typo3conf/ext/');
00228 if ($GLOBALS['TYPO3_CONF_VARS']['FE']['addAllowedPaths']) {
00229 $pathArr = t3lib_div::trimExplode(',',$GLOBALS['TYPO3_CONF_VARS']['FE']['addAllowedPaths'],1);
00230 while(list(,$p)=each($pathArr)) {
00231
00232 $this->allowedPaths[] = $p;
00233 }
00234 }
00235 }
00236
00249 function getCurrentPageData() {
00250 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('content', 'cache_pagesection', 'page_id='.intval($GLOBALS['TSFE']->id).' AND mpvar_hash='.t3lib_div::md5int($GLOBALS['TSFE']->MP));
00251 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00252 $this->currentPageData = unserialize($row['content']);
00253 } else {
00254 $this->currentPageData = 'none';
00255 }
00256 return $this->currentPageData;
00257 }
00258
00266 function matching($cc) {
00267 if (is_array($cc['all'])) {
00268 reset($cc['all']);
00269 $matchObj = t3lib_div::makeInstance('t3lib_matchCondition');
00270 $matchObj->altRootLine=$cc['rootLine'];
00271 while(list($key,$pre)=each($cc['all'])) {
00272 if ($matchObj->match($pre)) {
00273 $sectionsMatch[$key]=$pre;
00274 }
00275 }
00276 $cc['match']=$sectionsMatch;
00277 }
00278 return $cc;
00279 }
00280
00290 function start($theRootLine) {
00291 if (is_array($theRootLine)) {
00292 $setupData='';
00293 $cc=Array();
00294 $hash='';
00295 $this->runThroughTemplates($theRootLine);
00296
00297
00298 if (!$this->currentPageData) {
00299 $this->getCurrentPageData();
00300 }
00301
00302
00303
00304
00305 if (is_array($this->currentPageData) &&
00306 !strcmp(serialize($this->rowSum), serialize($this->currentPageData['rowSum']))
00307 ) {
00308
00309 $cc['all'] = $this->currentPageData['all'];
00310 $cc['rowSum'] = $this->currentPageData['rowSum'];
00311 $cc = $this->matching($cc);
00312 $hash = md5(serialize($cc));
00313 } else {
00314
00315 $rowSumHash = md5('ROWSUM:'.serialize($this->rowSum));
00316 $result = t3lib_pageSelect::getHash($rowSumHash, 0);
00317 if ($result) {
00318 $cc['all'] = unserialize($result);
00319 $cc['rowSum'] = $this->rowSum;
00320 $cc = $this->matching($cc);
00321 $hash = md5(serialize($cc));
00322 }
00323 }
00324
00325 if ($hash) {
00326
00327 $setupData = t3lib_pageSelect::getHash($hash, 0);
00328 }
00329
00330 if ($hash && $setupData && !$this->forceTemplateParsing) {
00331
00332 $this->setup = unserialize($setupData);
00333 } else {
00334
00335 $this->generateConfig();
00336
00337
00338 $cc=Array();
00339 $cc['all']=$this->sections;
00340 $cc['rowSum']=$this->rowSum;
00341 $cc = $this->matching($cc);
00342
00343 $hash = md5(serialize($cc));
00344
00345
00346 t3lib_pageSelect::storeHash($hash, serialize($this->setup), 'TS TEMPLATE');
00347
00348 if ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('TS template size, serialized: '.strlen(serialize($this->setup)).' bytes');
00349
00350 $rowSumHash = md5('ROWSUM:'.serialize($this->rowSum));
00351 t3lib_pageSelect::storeHash($rowSumHash, serialize($cc['all']), 'TMPL CONDITIONS - AL');
00352 }
00353
00354 $cc['rootLine'] = $this->rootLine;
00355
00356 $GLOBALS['TSFE']->all=$cc;
00357
00358 if (!$this->simulationHiddenOrTime) {
00359 $insertFields = array(
00360 'page_id' => intval($GLOBALS['TSFE']->id),
00361 'mpvar_hash' => t3lib_div::md5int($GLOBALS['TSFE']->MP),
00362 'content' => serialize($cc),
00363 'tstamp' => $GLOBALS['EXEC_TIME']
00364 );
00365 $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pagesection', 'page_id='.intval($GLOBALS['TSFE']->id).' AND mpvar_hash='.t3lib_div::md5int($GLOBALS['TSFE']->MP));
00366
00367 $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_pagesection', $insertFields);
00368 }
00369
00370 if ($this->rootId && $this->rootLine && $this->setup) {
00371 $this->loaded = 1;
00372 }
00373 }
00374 }
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00406 function runThroughTemplates($theRootLine,$start_template_uid=0) {
00407 $this->constants = Array();
00408 $this->config = Array();
00409 $this->editorcfg = Array();
00410 $this->rowSum = Array();
00411 $this->hierarchyInfoToRoot = Array();
00412 $this->absoluteRootLine=$theRootLine;
00413
00414 reset ($this->absoluteRootLine);
00415 $c=count($this->absoluteRootLine);
00416 for ($a=0;$a<$c;$a++) {
00417 if ($this->nextLevel) {
00418 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'uid='.intval($this->nextLevel).' '.$this->whereClause);
00419 $this->nextLevel = 0;
00420 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00421 $this->versionOL($row);
00422 if (is_array($row)) {
00423 $this->processTemplate($row,'sys_'.$row['uid'],$this->absoluteRootLine[$a]['uid'],'sys_'.$row['uid']);
00424 $this->outermostRootlineIndexWithTemplate=$a;
00425 }
00426 }
00427 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00428 }
00429 $addC='';
00430 if ($a==($c-1) && $start_template_uid) {
00431 $addC=' AND uid='.intval($start_template_uid);
00432 }
00433
00434 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid='.intval($this->absoluteRootLine[$a]['uid']).$addC.' '.$this->whereClause,'','sorting',1);
00435 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00436 $this->versionOL($row);
00437 if (is_array($row)) {
00438 $this->processTemplate($row,'sys_'.$row['uid'],$this->absoluteRootLine[$a]['uid'],'sys_'.$row['uid']);
00439 $this->outermostRootlineIndexWithTemplate=$a;
00440 }
00441 }
00442 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00443 $this->rootLine[] = $this->absoluteRootLine[$a];
00444 }
00445 }
00446
00459 function processTemplate($row, $idList,$pid,$templateID='',$templateParent='') {
00460
00461 $this->rowSum[]=Array($row['uid'],$row['title'],$row['tstamp']);
00462
00463
00464 if ($row['clear']) {
00465 $clConst = $row['clear']&1;
00466 $clConf = $row['clear']&2;
00467 if ($clConst) {
00468 $this->constants = Array();
00469 $this->clearList_const=array();
00470 }
00471 if ($clConf) {
00472 $this->config = Array();
00473 $this->hierarchyInfoToRoot = Array();
00474 $this->clearList_setup=array();
00475
00476 $this->editorcfg = Array();
00477 $this->clearList_editorcfg=array();
00478 }
00479 }
00480
00481
00482 if (!$row['includeStaticAfterBasedOn']) {
00483 $this->includeStaticTypoScriptSources($idList,$templateID,$pid,$row);
00484 }
00485
00486
00487 if (trim($row['basedOn'])) {
00488
00489
00490
00491 $basedOn_hackFeature = explode('=',$row['basedOn']);
00492 if ($basedOn_hackFeature[0]=='EXTERNAL_BASED_ON_TEMPLATE_ID' && $basedOn_hackFeature[1]) {
00493 $id = intval(t3lib_div::_GET($basedOn_hackFeature[1]));
00494 if ($id && !t3lib_div::inList($idList,'sys_'.$id)) {
00495 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'uid='.$id.' '.$this->whereClause);
00496 if ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00497 $this->versionOL($subrow);
00498 if (is_array($subrow)) {
00499 $this->processTemplate($subrow,$idList.',sys_'.$id,$pid, 'sys_'.$id,$templateID);
00500 }
00501 }
00502 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00503 }
00504 } else {
00505 $basedOnArr = t3lib_div::intExplode(',',$row['basedOn']);
00506 while(list(,$id)=each($basedOnArr)) {
00507 if (!t3lib_div::inList($idList,'sys_'.$id)) {
00508 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'uid='.intval($id).' '.$this->whereClause);
00509 if ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00510 $this->versionOL($subrow);
00511 if (is_array($subrow)) {
00512 $this->processTemplate($subrow,$idList.',sys_'.$id,$pid, 'sys_'.$id,$templateID);
00513 }
00514 }
00515 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00516 }
00517 }
00518 }
00519 }
00520
00521
00522 if ($row['includeStaticAfterBasedOn']) {
00523 $this->includeStaticTypoScriptSources($idList,$templateID,$pid,$row);
00524 }
00525
00526
00527 $this->hierarchyInfo[] = $this->hierarchyInfoToRoot[] = array(
00528 'root'=>trim($row['root']),
00529 'next'=>$row['nextLevel'],
00530 'clConst'=>$clConst,
00531 'clConf'=>$clConf,
00532 'templateID'=>$templateID,
00533 'templateParent'=>$templateParent,
00534 'title'=>$row['title'],
00535 'uid'=>$row['uid'],
00536 'pid'=>$row['pid'],
00537 'configLines' => substr_count($row['config'], chr(10))+1
00538 );
00539
00540
00541 $this->constants[] = $row['constants'];
00542 $this->config[] = $row['config'];
00543 if ($this->parseEditorCfgField) $this->editorcfg[] = $row['editorcfg'];
00544
00545
00546 $this->clearList_const[]=$templateID;
00547 $this->clearList_setup[]=$templateID;
00548 if ($this->parseEditorCfgField) $this->clearList_editorcfg[]=$templateID;
00549
00550
00551 if (trim($row['resources'])) {
00552 $this->resources = $row['resources'].','.$this->resources;
00553 }
00554 if (trim($row['sitetitle'])) {
00555 $this->sitetitle = $row['sitetitle'];
00556 }
00557
00558 if (trim($row['root'])) {
00559 $this->rootId = $pid;
00560 $this->rootLine = Array();
00561 }
00562
00563 if ($row['nextLevel']) {
00564 $this->nextLevel = $row['nextLevel'];
00565 } else {
00566 $this->nextLevel = 0;
00567 }
00568 }
00569
00580 function includeStaticTypoScriptSources($idList,$templateID,$pid,$row) {
00581
00582 if (trim($row['include_static'])) {
00583 $include_staticArr = t3lib_div::intExplode(',',$row['include_static']);
00584 reset($include_staticArr);
00585 while(list(,$id)=each($include_staticArr)) {
00586 if (!t3lib_div::inList($idList,'static_'.$id)) {
00587 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'static_template', 'uid='.intval($id));
00588 if ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00589 $subrow = $this->prependStaticExtra($subrow);
00590 $this->processTemplate($subrow,$idList.',static_'.$id,$pid,'static_'.$id,$templateID);
00591 }
00592 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00593 }
00594 }
00595 }
00596
00597
00598 if (trim($row['include_static_file'])) {
00599 $include_static_fileArr = t3lib_div::trimExplode(',',$row['include_static_file'],1);
00600 reset($include_static_fileArr);
00601 while(list(,$ISF_file)=each($include_static_fileArr)) {
00602 $ISF_file = trim($ISF_file);
00603 if (substr($ISF_file,0,4)=='EXT:') {
00604 list($ISF_extKey,$ISF_localPath) = explode('/',substr($ISF_file,4),2);
00605 if (strcmp($ISF_extKey,'') && t3lib_extMgm::isLoaded($ISF_extKey) && strcmp($ISF_localPath,'')) {
00606 $ISF_localPath = ereg_replace('\/$','',$ISF_localPath).'/';
00607 $ISF_filePath = t3lib_extMgm::extPath($ISF_extKey).$ISF_localPath;
00608 if (@is_dir($ISF_filePath)) {
00609 $mExtKey = str_replace('_','',$ISF_extKey.'/'.$ISF_localPath);
00610 $subrow=array(
00611 'constants'=> @is_file($ISF_filePath.'constants.txt') ?t3lib_div::getUrl($ISF_filePath.'constants.txt'):'',
00612 'config'=> @is_file($ISF_filePath.'setup.txt') ?t3lib_div::getUrl($ISF_filePath.'setup.txt'):'',
00613 'editorcfg'=> @is_file($ISF_filePath.'editorcfg.txt') ?t3lib_div::getUrl($ISF_filePath.'editorcfg.txt'):'',
00614 'include_static'=> @is_file($ISF_filePath.'include_static.txt')?implode(',',array_unique(t3lib_div::intExplode(',',t3lib_div::getUrl($ISF_filePath.'include_static.txt')))):'',
00615 'include_static_file'=> @is_file($ISF_filePath.'include_static_file.txt')?implode(',',array_unique(explode(',',t3lib_div::getUrl($ISF_filePath.'include_static_file.txt')))):'',
00616 'title' => $ISF_file,
00617 'uid' => $mExtKey
00618 );
00619 $subrow = $this->prependStaticExtra($subrow);
00620
00621 $this->processTemplate($subrow,$idList.',ext_'.$mExtKey,$pid, 'ext_'.$mExtKey,$templateID);
00622 }
00623 }
00624 }
00625 }
00626 }
00627
00628 $this->addExtensionStatics($idList,$templateID,$pid,$row);
00629 }
00630
00642 function addExtensionStatics($idList,$templateID,$pid,$row) {
00643 global $TYPO3_LOADED_EXT;
00644
00645 if ($row['static_file_mode']==1 || ($row['static_file_mode']==0 && substr($templateID,0,4)=='sys_' && $row['root'])) {
00646 reset($TYPO3_LOADED_EXT);
00647 while(list($extKey,$files)=each($TYPO3_LOADED_EXT)) {
00648 if (is_array($files) && ($files['ext_typoscript_constants.txt'] || $files['ext_typoscript_setup.txt'] || $files['ext_typoscript_editorcfg.txt'])) {
00649 $mExtKey = str_replace('_','',$extKey);
00650 $subrow=array(
00651 'constants'=> $files['ext_typoscript_constants.txt']?t3lib_div::getUrl($files['ext_typoscript_constants.txt']):'',
00652 'config'=> $files['ext_typoscript_setup.txt']?t3lib_div::getUrl($files['ext_typoscript_setup.txt']):'',
00653 'editorcfg'=> $files['ext_typoscript_editorcfg.txt']?t3lib_div::getUrl($files['ext_typoscript_editorcfg.txt']):'',
00654 'title' => $extKey,
00655 'uid' => $mExtKey
00656 );
00657 $subrow = $this->prependStaticExtra($subrow);
00658
00659 $this->processTemplate($subrow,$idList.',ext_'.$mExtKey,$pid, 'ext_'.$mExtKey,$templateID);
00660 }
00661 }
00662 }
00663 }
00664
00675 function prependStaticExtra($subrow) {
00676 $subrow['config'].=$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'][$subrow['uid']];
00677 $subrow['editorcfg'].=$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_editorcfg.'][$subrow['uid']];
00678 $subrow['constants'].=$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants.'][$subrow['uid']];
00679 return $subrow;
00680 }
00681
00688 function versionOL(&$row) {
00689 if (is_object($GLOBALS['TSFE'])) {
00690 $GLOBALS['TSFE']->sys_page->versionOL('sys_template',$row);
00691 } else {
00692 t3lib_BEfunc::workspaceOL('sys_template',$row);
00693 }
00694 }
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00725 function generateConfig() {
00726
00727 array_unshift($this->constants,''.$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants']);
00728 array_unshift($this->config,''.$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup']);
00729 array_unshift($this->editorcfg,''.$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_editorcfg']);
00730
00731
00732 $this->procesIncludes();
00733
00734
00735 $this->setup['resources']= $this->resources;
00736 $this->setup['sitetitle']= $this->sitetitle;
00737
00738
00739
00740
00741
00742
00743
00744
00745 $constants = t3lib_div::makeInstance('t3lib_TSparser');
00746 $constants->breakPointLN=intval($this->ext_constants_BRP);
00747 $constants->setup = $this->const;
00748 $constants->setup = $this->mergeConstantsFromPageTSconfig($constants->setup);
00749 $matchObj = t3lib_div::makeInstance('t3lib_matchCondition');
00750 $matchObj->matchAlternative = $this->matchAlternative;
00751 $matchObj->matchAll = $this->matchAll;
00752
00753
00754 foreach($this->constants as $str) {
00755 $constants->parse($str,$matchObj);
00756 }
00757
00758
00759 $this->parserErrors['constants']=$constants->errors;
00760
00761
00762 $this->flatSetup = Array();
00763 $this->flattenSetup($constants->setup,'','');
00764
00765
00766
00767
00768
00769
00770
00771 $config = t3lib_div::makeInstance('t3lib_TSparser');
00772 $config->breakPointLN = intval($this->ext_config_BRP);
00773 $config->regLinenumbers = $this->ext_regLinenumbers;
00774 $config->setup = $this->setup;
00775
00776
00777 $config->sections = $constants->sections;
00778 $config->sectionsMatch = $constants->sectionsMatch;
00779
00780
00781 $all='';
00782 foreach($this->config as $str) {
00783 $all.="\n[GLOBAL]\n".$str;
00784 }
00785
00786
00787 if ($this->tt_track) $GLOBALS['TT']->push('Substitute Constants ('.count($this->flatSetup).')');
00788 $all = $this->substituteConstants($all);
00789 if ($this->tt_track) $GLOBALS['TT']->pull();
00790
00791
00792 if (strstr($all,'{$')) {
00793 $findConst = explode('{$',$all);
00794 $theConstList=Array();
00795 next($findConst);
00796 while(list(,$constVal)=each($findConst)) {
00797 $constLen=t3lib_div::intInRange(strcspn($constVal,'}'),0,50);
00798 $theConstList[]='{$'.substr($constVal,0,$constLen+1);
00799 }
00800 if ($this->tt_track) $GLOBALS['TT']->setTSlogMessage(implode(',',$theConstList).': Constants may remain un-substituted!!',2);
00801 }
00802
00803
00804 if ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('TypoScript template size as textfile: '.strlen($all).' bytes');
00805
00806
00807 $config->parse($all,$matchObj);
00808
00809
00810 $this->parserErrors['config']=$config->errors;
00811
00812
00813 $this->setup = $config->setup;
00814 if ($this->backend_info) {
00815 $this->setup_constants = $constants->setup;
00816 }
00817
00818
00819
00820
00821
00822
00823
00824 if ($this->parseEditorCfgField) {
00825 $editorcfg = t3lib_div::makeInstance('t3lib_TSparser');
00826 $editorcfg->breakPointLN=intval($this->ext_editorcfg_BRP);
00827 $editorcfg->setup = array();
00828
00829 $all = implode("\n[GLOBAL]\n",$this->editorcfg);
00830
00831
00832 $all = $this->substituteConstants($all);
00833
00834
00835 $matchObj->matchAll=1;
00836 $editorcfg->parse($all,$matchObj);
00837 $this->parserErrors['editorcfg']=$editorcfg->errors;
00838 $this->setup_editorcfg = $editorcfg->setup;
00839 }
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851 unset($this->setup['resources']);
00852 unset($this->setup['resources.']);
00853 $this->setup['resources']= implode(',',t3lib_div::trimExplode(',',$this->resources,1));
00854
00855 unset($this->setup['sitetitle']);
00856 unset($this->setup['sitetitle.']);
00857 $this->setup['sitetitle']= $this->sitetitle;
00858
00859
00860 unset($this->setup['types.']);
00861 unset($this->setup['types']);
00862 if (is_array($this->setup)) {
00863 reset ($this->setup);
00864 while(list($theKey,)=each($this->setup)) {
00865 if ($this->setup[$theKey]=='PAGE') {
00866 $tN = $this->setup[$theKey.'.']['typeNum'];
00867 if (isset($tN)) {
00868 $this->setup['types.'][$tN] = $theKey;
00869 } elseif(!$this->setup['types.'][0]) {
00870 $this->setup['types.'][0] = $theKey;
00871 }
00872 }
00873 }
00874 }
00875 unset($this->setup['styles.']);
00876 unset($this->setup['temp.']);
00877 unset($constants);
00878
00879
00880 $this->sections = $config->sections;
00881 $this->sectionsMatch = $config->sectionsMatch;
00882 }
00883
00891 function procesIncludes() {
00892 reset($this->constants);
00893 while(list($k)=each($this->constants)) {
00894 $this->constants[$k]=t3lib_TSparser::checkIncludeLines($this->constants[$k]);
00895 }
00896
00897 reset($this->config);
00898 while(list($k)=each($this->config)) {
00899 $this->config[$k]=t3lib_TSparser::checkIncludeLines($this->config[$k]);
00900 }
00901
00902 reset($this->editorcfg);
00903 while(list($k)=each($this->editorcfg)) {
00904 $this->editorcfg[$k]=t3lib_TSparser::checkIncludeLines($this->editorcfg[$k]);
00905 }
00906 }
00907
00915 function mergeConstantsFromPageTSconfig($constArray) {
00916 $TSdataArray = array();
00917 $TSdataArray[]=$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig'];
00918
00919 for ($a=0;$a<=$this->outermostRootlineIndexWithTemplate;$a++) {
00920 $TSdataArray[]=$this->absoluteRootLine[$a]['TSconfig'];
00921 }
00922
00923 $TSdataArray = t3lib_TSparser::checkIncludeLines_array($TSdataArray);
00924 $userTS = implode(chr(10).'[GLOBAL]'.chr(10),$TSdataArray);
00925
00926 $parseObj = t3lib_div::makeInstance('t3lib_TSparser');
00927 $parseObj->parse($userTS);
00928
00929 if (is_array($parseObj->setup['TSFE.']['constants.'])) {
00930 $constArray = t3lib_div::array_merge_recursive_overrule($constArray,$parseObj->setup['TSFE.']['constants.']);
00931 }
00932 return $constArray;
00933 }
00934
00944 function flattenSetup($setupArray, $prefix, $resourceFlag) {
00945 if (is_array($setupArray)) {
00946 reset($setupArray);
00947 while(list($key,$val)=each($setupArray)) {
00948 if ($prefix || substr($key,0,16)!='TSConstantEditor') {
00949 if (is_array($val)) {
00950 $this->flattenSetup($val,$prefix.$key, ($key=='file.'));
00951 } elseif ($resourceFlag) {
00952 $this->flatSetup[$prefix.$key] = $this->getFileName($val);
00953 } else {
00954 $this->flatSetup[$prefix.$key] = $val;
00955 }
00956 }
00957 }
00958 }
00959 }
00960
00968 function substituteConstants($all) {
00969 if ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('Constants to substitute: '.count($this->flatSetup));
00970
00971 $noChange = false;
00972
00973 for ($i = 0; $i < 10 && !$noChange; $i++) {
00974 $old_all = $all;
00975 $all = preg_replace_callback('/\{\$(.[^}]*)\}/', array($this, 'substituteConstantsCallBack'), $all);
00976 if ($old_all == $all) {
00977 $noChange = true;
00978 }
00979 }
00980
00981 return $all;
00982 }
00983
00991 function substituteConstantsCallBack($matches) {
00992
00993 return isset($this->flatSetup[$matches[1]]) && !is_array($this->flatSetup[$matches[1]]) ? $this->flatSetup[$matches[1]] : $matches[0];
00994 }
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01022 function splitConfArray($conf,$splitCount) {
01023
01024
01025 $splitCount = intval($splitCount);
01026 $conf2 = Array();
01027
01028 if ($splitCount && is_array($conf)) {
01029
01030
01031 for ($aKey=0;$aKey<$splitCount;$aKey++) {
01032 $conf2[$aKey] = array();
01033 }
01034
01035
01036 foreach($conf as $cKey => $val) {
01037 if (is_array($val)) {
01038 $tempConf = $this->splitConfArray($val,$splitCount);
01039 foreach($tempConf as $aKey => $val) {
01040 $conf2[$aKey][$cKey] = $val;
01041 }
01042 }
01043 }
01044
01045
01046 foreach($conf as $cKey => $val) {
01047 if (!is_array($val)) {
01048 if (!strstr($val,'|*|') && !strstr($val,'||')) {
01049 for ($aKey=0;$aKey<$splitCount;$aKey++) {
01050 $conf2[$aKey][$cKey] = $val;
01051 }
01052 } else {
01053 $main = explode ('|*|',$val);
01054 $mainCount = count($main);
01055
01056 $lastC = 0;
01057 $middleC = 0;
01058 $firstC = 0;
01059
01060 if ($main[0]) {
01061 $first = explode('||',$main[0]);
01062 $firstC = count($first);
01063 }
01064 if ($main[1]) {
01065 $middle = explode('||',$main[1]);
01066 $middleC = count($middle);
01067 }
01068 if ($main[2]) {
01069 $last = explode('||',$main[2]);
01070 $lastC = count($last);
01071 $value = $last[0];
01072 }
01073
01074 for ($aKey=0;$aKey<$splitCount;$aKey++) {
01075 if ($firstC && isset($first[$aKey])) {
01076 $value = $first[$aKey];
01077 } elseif ($middleC) {
01078 $value = $middle[($aKey-$firstC)%$middleC];
01079 }
01080 if ($lastC && $lastC>=($splitCount-$aKey)) {
01081 $value = $last[$lastC-($splitCount-$aKey)];
01082 }
01083 $conf2[$aKey][$cKey] = trim($value);
01084 }
01085 }
01086 }
01087 }
01088 }
01089 return $conf2;
01090 }
01091
01099 function getFileName($fileFromSetup) {
01100 $file = trim($fileFromSetup);
01101 if (!$file) {
01102 return;
01103 } elseif (strstr($file,'../')) {
01104 if ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('File path "'.$file.'" contained illegal string "../"!',3);
01105 return;
01106 }
01107
01108 $hash = md5($file);
01109 if (isset($this->fileCache[$hash])) {
01110 return $this->fileCache[$hash];
01111 }
01112
01113 if (!strcmp(substr($file,0,4),'EXT:')) {
01114 $newFile='';
01115 list($extKey,$script)=explode('/',substr($file,4),2);
01116 if ($extKey && t3lib_extMgm::isLoaded($extKey)) {
01117 $extPath=t3lib_extMgm::extPath($extKey);
01118 $newFile=substr($extPath,strlen(PATH_site)).$script;
01119 }
01120 if (!@is_file(PATH_site.$newFile)) {
01121 if ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('Extension media file "'.$newFile.'" was not found!',3);
01122 return;
01123 } else $file=$newFile;
01124 }
01125
01126
01127 if (strstr($file,'/')) {
01128 if(!strcmp(substr($file,0,6),'media/')) $file = 'typo3/sysext/cms/tslib/'.$file;
01129 if (@is_file($this->getFileName_backPath.$file)) {
01130 $outFile = $file;
01131 $fileInfo = t3lib_div::split_fileref($outFile);
01132 reset($this->allowedPaths);
01133 $OK=0;
01134 while(list(,$val)=each($this->allowedPaths)) {
01135 if (substr($fileInfo['path'],0,strlen($val))==$val){$OK=1; break;}
01136 }
01137 if ($OK) {
01138 $this->fileCache[$hash]=$outFile;
01139 return $outFile;
01140 } elseif ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('"'.$file.'" was not located in the allowed paths: ('.implode(',',$this->allowedPaths).')',3);
01141 } elseif ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('"'.$this->getFileName_backPath.$file.'" is not a file (non-uploads/.. resource, did not exist).',3);
01142 } else { // Here it is uploaded media:
01143 $outFile = $this->extractFromResources($this->setup['resources'],$file);
01144 if ($outFile) {
01145 if (@is_file($this->uplPath.$outFile)) {
01146 $this->fileCache[$hash] = $this->uplPath.$outFile;
01147 return $this->uplPath.$outFile;
01148 } elseif ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('"'.$this->uplPath.$outFile.'" is not a file (did not exist).',3);
01149 } elseif ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('"'.$file.'" is not a file (uploads/.. resource).',3);
01150 }
01151 }
01152
01162 function extractFromResources($res,$file) {
01163 if (t3lib_div::inList($res,$file)) {
01164 $outFile = $file;
01165 } elseif (strstr($file,'*')) {
01166 $fileparts=explode('*',$file);
01167 $c=count($fileparts);
01168 $files = explode(',',$res);
01169 while(list(,$val)=each($files)) {
01170 $test = trim($val);
01171 if (ereg('^'.quotemeta($fileparts[0]).'.*'.quotemeta($fileparts[$c-1]).'$', $test)) {
01172 $outFile = $test;
01173 break;
01174 }
01175 }
01176 }
01177 return $outFile;
01178 }
01179
01190 function checkFile($name,$menuArr) {
01191 reset ($menuArr);
01192 while (list($aKey,)=each($menuArr)) {
01193 $menuArr[$aKey][$name] = $this->getFileName($menuArr[$aKey][$name]);
01194 }
01195 return $menuArr;
01196 }
01197
01207 function printTitle($title,$no_title=0,$titleFirst=0) {
01208 $st = trim($this->setup['sitetitle']) ? $this->setup['sitetitle']:'';
01209 $title = $no_title ? '' : $title;
01210 if ($titleFirst) {
01211 $temp=$st;
01212 $st=$title;
01213 $title=$temp;
01214 }
01215 if ($title && $st) {
01216 return $st.': '.$title;
01217 } else {
01218 return $st.$title;
01219 }
01220 }
01221
01230 function fileContent($fName) {
01231 $incFile = $this->getFileName($fName);
01232 if ($incFile && $fd=fopen($incFile,'rb')) {
01233 $content = '';
01234 while (!feof($fd)) {
01235 $content.=fread($fd, 5000);
01236 }
01237 fclose( $fd );
01238 return $content;
01239 }
01240 }
01241
01250 function wrap($content,$wrap) {
01251 if ($wrap) {
01252 $wrapArr = explode('|', $wrap);
01253 return trim($wrapArr[0]).$content.trim($wrapArr[1]);
01254 } else return $content;
01255 }
01256
01264 function removeQueryString($url) {
01265 if (substr($url,-1)=='?') {
01266 return substr($url,0,-1);
01267 } else {
01268 return $url;
01269 }
01270 }
01271
01281 function sortedKeyList($setupArr, $acceptOnlyProperties=FALSE) {
01282 $keyArr = Array();
01283
01284 reset($setupArr);
01285 while(list($key,)=each($setupArr)) {
01286 $ikey = intval($key);
01287 if (!strcmp($ikey,$key) || $acceptOnlyProperties) {
01288 $keyArr[] = $ikey;
01289 }
01290 }
01291
01292 $keyArr = array_unique($keyArr);
01293 sort($keyArr);
01294 return $keyArr;
01295 }
01296
01297
01298
01299
01300
01301
01302
01303
01304
01305
01306 /*******************************************************************
01307 *
01308 * Functions for creating links
01309 *
01310 *******************************************************************/
01311
01328 function linkData($page,$oTarget,$no_cache,$script,$overrideArray='',$addParams='',$typeOverride='') {
01329 global $TYPO3_CONF_VARS;
01330
01331 $LD = Array();
01332
01333 // Overriding some fields in the page record and still preserves the values by adding them as parameters. Little strange function.
01334 if (is_array($overrideArray)) {
01335 foreach($overrideArray as $theKey => $theNewVal) {
01336 $addParams.= '&real_'.$theKey.'='.rawurlencode($page[$theKey]);
01337 $page[$theKey] = $theNewVal;
01338 }
01339 }
01340
01341 // Adding Mount Points, "&MP=", parameter for the current page if any is set:
01342 if (!strstr($addParams,'&MP=')) {
01343 if (trim($GLOBALS['TSFE']->MP_defaults[$page['uid']])) { // Looking for hardcoded defaults:
01344 $addParams.= '&MP='.rawurlencode(trim($GLOBALS['TSFE']->MP_defaults[$page['uid']]));
01345 } elseif ($GLOBALS['TSFE']->config['config']['MP_mapRootPoints']) { // Else look in automatically created map:
01346 $m = $this->getFromMPmap($page['uid']);
01347 if ($m) {
01348 $addParams.= '&MP='.rawurlencode($m);
01349 }
01350 }
01351 }
01352
01353 // Setting ID/alias:
01354 if (!$script) {$script = $GLOBALS['TSFE']->config['mainScript'];}
01355 if ($page['alias']) {
01356 $LD['url'] = $script.'?id='.rawurlencode($page['alias']);
01357 } else {
01358 $LD['url'] = $script.'?id='.$page['uid'];
01359 }
01360 // Setting target
01361 $LD['target'] = trim($page['target']) ? trim($page['target']) : $oTarget;
01362
01363 // typeNum
01364 $typeNum = $this->setup[$LD['target'].'.']['typeNum'];
01365 if (!$typeOverride && intval($GLOBALS['TSFE']->config['config']['forceTypeValue'])) {
01366 $typeOverride = intval($GLOBALS['TSFE']->config['config']['forceTypeValue']);
01367 }
01368 if (strcmp($typeOverride,'')) { $typeNum = $typeOverride; } // Override...
01369 if ($typeNum) {
01370 $LD['type'] = '&type='.intval($typeNum);
01371 } else {
01372 $LD['type'] = '';
01373 }
01374 $LD['orig_type'] = $LD['type']; // Preserving the type number. Will not be cleared if simulateStaticDocuments.
01375
01376 // noCache
01377 $LD['no_cache'] = (trim($page['no_cache']) || $no_cache) ? '&no_cache=1' : '';
01378
01379 // linkVars
01380 if ($GLOBALS['TSFE']->config['config']['uniqueLinkVars']) {
01381 if ($addParams) {
01382 $LD['linkVars'] = t3lib_div::implodeArrayForUrl('',t3lib_div::explodeUrl2Array($GLOBALS['TSFE']->linkVars.$addParams));
01383 } else {
01384 $LD['linkVars'] = $GLOBALS['TSFE']->linkVars;
01385 }
01386 } else {
01387 $LD['linkVars'] = $GLOBALS['TSFE']->linkVars.$addParams;
01388 }
01389
01390 // If simulateStaticDocuments is enabled:
01391 if ($GLOBALS['TSFE']->config['config']['simulateStaticDocuments']) {
01392 $LD['type'] = '';
01393 $LD['url'] = '';
01394
01395 // MD5/base64 method limitation:
01396 $remainLinkVars='';
01397 $flag_simulateStaticDocuments_pEnc = t3lib_div::inList('md5,base64',$GLOBALS['TSFE']->config['config']['simulateStaticDocuments_pEnc']) && !$LD['no_cache'];
01398 if ($flag_simulateStaticDocuments_pEnc) {
01399 list($LD['linkVars'], $remainLinkVars) = $GLOBALS['TSFE']->simulateStaticDocuments_pEnc_onlyP_proc($LD['linkVars']);
01400 }
01401
01402 $LD['url'].=$GLOBALS['TSFE']->makeSimulFileName(
01403 $page['title'],
01404 $page['alias'] ? $page['alias'] : $page['uid'],
01405 intval($typeNum),
01406 $LD['linkVars'],
01407 $LD['no_cache']?1:0
01408 );
01409
01410 if ($flag_simulateStaticDocuments_pEnc) {
01411 $LD['linkVars']=$remainLinkVars;
01412 }
01413 if ($GLOBALS['TSFE']->config['config']['simulateStaticDocuments']=='PATH_INFO') {
01414 $LD['url'] = str_replace('.','/',$LD['url']);
01415 $LD['url'] = 'index.php/'.$LD['url'].'/?';
01416 } else {
01417 $LD['url'].= '.html?';
01418 }
01419 }
01420
01421 // Add absRefPrefix if exists.
01422 $LD['url'] = $GLOBALS['TSFE']->absRefPrefix.$LD['url'];
01423
01424 // If the special key 'sectionIndex_uid' (added 'manually' in tslib/menu.php to the page-record) is set, then the link jumps directly to a section on the page.
01425 $LD['sectionIndex'] = $page['sectionIndex_uid'] ? '#'.$page['sectionIndex_uid'] : '';
01426
01427 // Compile the normal total url
01428 $LD['totalURL']= $this->removeQueryString($LD['url'].$LD['type'].$LD['no_cache'].$LD['linkVars'].$GLOBALS['TSFE']->getMethodUrlIdToken).$LD['sectionIndex'];
01429
01430 // Call post processing function for link rendering:
01431 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['linkData-PostProc'])) {
01432 $_params = array(
01433 'LD' => &$LD,
01434 'args' => array('page'=>$page, 'oTarget'=>$oTarget, 'no_cache'=>$no_cache, 'script'=>$script, 'overrideArray'=>$overrideArray, 'addParams'=>$addParams, 'typeOverride'=>$typeOverride),
01435 'typeNum' => $typeNum
01436 );
01437 foreach($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['linkData-PostProc'] as $_funcRef) {
01438 t3lib_div::callUserFunction($_funcRef,$_params,$this);
01439 }
01440 }
01441
01442 // Return the LD-array
01443 return $LD;
01444 }
01445
01455 function getFromMPmap($pageId=0) {
01456
01457 // Create map if not found already:
01458 if (!is_array($this->MPmap)) {
01459 $this->MPmap = array();
01460
01461 $rootPoints = t3lib_div::trimExplode(',', strtolower($GLOBALS['TSFE']->config['config']['MP_mapRootPoints']),1);
01462 foreach($rootPoints as $p) { // Traverse rootpoints:
01463 if ($p == 'root') {
01464 $p = $this->rootLine[0]['uid'];
01465 $initMParray = array();
01466 if ($this->rootLine[0]['_MOUNT_OL'] && $this->rootLine[0]['_MP_PARAM']) {
01467 $initMParray[] = $this->rootLine[0]['_MP_PARAM'];
01468 }
01469 }
01470 $this->initMPmap_create($p,$initMParray);
01471 }
01472 }
01473
01474 // Finding MP var for Page ID:
01475 if ($pageId) {
01476 if (is_array($this->MPmap[$pageId]) && count($this->MPmap[$pageId])) {
01477 return implode(',',$this->MPmap[$pageId]);
01478 }
01479 }
01480 }
01481
01491 function initMPmap_create($id,$MP_array=array(),$level=0) {
01492
01493 $id = intval($id);
01494 if($id<=0) return;
01495
01496 // First level, check id
01497 if (!$level) {
01498
01499 // Find mount point if any:
01500 $mount_info = $GLOBALS['TSFE']->sys_page->getMountPointInfo($id);
01501
01502 // Overlay mode:
01503 if (is_array($mount_info) && $mount_info['overlay']) {
01504 $MP_array[] = $mount_info['MPvar'];
01505 $id = $mount_info['mount_pid'];
01506 }
01507
01508 // Set mapping information for this level:
01509 $this->MPmap[$id] = $MP_array;
01510
01511 // Normal mode:
01512 if (is_array($mount_info) && !$mount_info['overlay']) {
01513 $MP_array[] = $mount_info['MPvar'];
01514 $id = $mount_info['mount_pid'];
01515 }
01516 }
01517
01518 if ($id && $level<20) {
01519
01520 $nextLevelAcc = array();
01521
01522 // Select and traverse current level pages:
01523 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
01524 'uid,pid,doktype,mount_pid,mount_pid_ol',
01525 'pages',
01526 'pid='.intval($id).' AND deleted=0 AND doktype!=255 AND doktype!=6' // 255 = Garbage bin, 6 = Backend User Section
01527 );
01528 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
01529
01530 // Find mount point if any:
01531 $next_id = $row['uid'];
01532 $next_MP_array = $MP_array;
01533 $mount_info = $GLOBALS['TSFE']->sys_page->getMountPointInfo($next_id, $row);
01534
01535 // Overlay mode:
01536 if (is_array($mount_info) && $mount_info['overlay']) {
01537 $next_MP_array[] = $mount_info['MPvar'];
01538 $next_id = $mount_info['mount_pid'];
01539 }
01540
01541 if (!isset($this->MPmap[$next_id])) {
01542
01543 // Set mapping information for this level:
01544 $this->MPmap[$next_id] = $next_MP_array;
01545
01546 // Normal mode:
01547 if (is_array($mount_info) && !$mount_info['overlay']) {
01548 $next_MP_array[] = $mount_info['MPvar'];
01549 $next_id = $mount_info['mount_pid'];
01550 }
01551
01552 // Register recursive call
01553 // (have to do it this way since ALL of the current level should be registered BEFORE the sublevel at any time)
01554 $nextLevelAcc[] = array($next_id,$next_MP_array);
01555 }
01556 }
01557
01558 // Call recursively, if any:
01559 foreach($nextLevelAcc as $pSet) {
01560 $this->initMPmap_create($pSet[0],$pSet[1],$level+1);
01561 }
01562 }
01563 }
01564 }
01565
01566
01567 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tstemplate.php']) {
01568 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tstemplate.php']);
01569 }
01570 ?>