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
00081 require_once (PATH_t3lib.'class.t3lib_tsparser.php');
00082 require_once (PATH_t3lib.'class.t3lib_matchcondition.php');
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00107 class t3lib_TStemplate {
00108
00109
00110 var $tt_track = 1;
00111 var $forceTemplateParsing=0;
00112
00113
00114 var $matchAlternative=array();
00115 var $matchAll=0;
00116 var $parseEditorCfgField=0;
00117 var $backend_info = 0;
00118 var $getFileName_backPath='';
00119
00120
00121 var $ext_constants_BRP=0;
00122 var $ext_config_BRP=0;
00123 var $ext_editorcfg_BRP=0;
00124 var $ext_regLinenumbers=FALSE;
00125
00126
00127 var $uplPath = 'uploads/tf/';
00128 var $tempPath = 'typo3temp/';
00129 var $menuclasses = 'gmenu,tmenu,imgmenu,jsmenu';
00130
00131
00132 var $whereClause = '';
00133 var $debug = 0;
00134 var $allowedPaths = array();
00135 var $currentPageData = '';
00136 var $simulationHiddenOrTime=0;
00137
00138 var $loaded = 0;
00139 var $setup = Array(
00140 'styles.' => Array (
00141 'insertContent' => 'CONTENT',
00142 'insertContent.' => Array (
00143 'table' => 'tt_content',
00144 'select.' => Array (
00145 'orderBy' => 'sorting',
00146 'where' => 'colPos=0',
00147 'languageField' => 'sys_language_uid'
00148 )
00149 )
00150 ),
00151 'config.' => Array (
00152 'extTarget' => '_top',
00153 'stat' => 1,
00154 'stat_typeNumList' => '0,1'
00155 )
00156 );
00157 var $flatSetup = Array (
00158 );
00159 var $const = Array (
00160 '_clear' => '<img src="clear.gif" width="1" height="1" alt="" />',
00161 '_blackBorderWrap' => '<table border="0" bgcolor="black" cellspacing="0" cellpadding="1"><tr><td> | </td></tr></table>',
00162 '_tableWrap' => '<table border="0" cellspacing="0" cellpadding="0"> | </table>',
00163 '_tableWrap_DEBUG' => '<table border="1" cellspacing="0" cellpadding="0"> | </table>',
00164 '_stdFrameParams' => 'frameborder="no" marginheight="0" marginwidth="0" noresize="noresize"',
00165 '_stdFramesetParams' => 'border="0" framespacing="0" frameborder="no"'
00166 );
00167
00168
00169
00170 var $config = array();
00171 var $constants = array();
00172 var $editorcfg = array();
00173
00174 var $hierarchyInfo = array();
00175 var $hierarchyInfoToRoot = array();
00176 var $nextLevel=0;
00177 var $rootId;
00178 var $rootLine;
00179 var $absoluteRootLine;
00180 var $outermostRootlineIndexWithTemplate=0;
00181 var $rowSum;
00182 var $resources='';
00183 var $sitetitle='';
00184 var $sections;
00185 var $sectionsMatch;
00186
00187
00188 var $clearList_const=array();
00189 var $clearList_setup=array();
00190 var $clearList_editorcfg=array();
00191 var $parserErrors=array();
00192 var $setup_constants = array();
00193
00194
00195 var $fileCache = Array();
00196 var $frames = Array();
00197 var $MPmap = '';
00198
00199
00200
00201
00209 function init() {
00210
00211
00212 $this->whereClause='AND deleted=0 ';
00213 if (!$GLOBALS['TSFE']->showHiddenRecords) {
00214 $this->whereClause.='AND hidden=0 ';
00215 }
00216 if ($GLOBALS['TSFE']->showHiddenRecords || $GLOBALS['SIM_EXEC_TIME']!=$GLOBALS['EXEC_TIME']) {
00217 $this->simulationHiddenOrTime=1;
00218 }
00219 $this->whereClause.= 'AND (starttime<='.$GLOBALS['SIM_EXEC_TIME'].') AND (endtime=0 OR endtime>'.$GLOBALS['SIM_EXEC_TIME'].')';
00220 if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib']) {
00221 $this->menuclasses='tmenu,jsmenu,gmenu';
00222 }
00223
00224
00225 $this->allowedPaths = Array ('media/','fileadmin/','uploads/','typo3temp/','t3lib/fonts/',TYPO3_mainDir.'ext/',TYPO3_mainDir.'sysext/','typo3conf/ext/');
00226 if ($GLOBALS['TYPO3_CONF_VARS']['FE']['addAllowedPaths']) {
00227 $pathArr = t3lib_div::trimExplode(',',$GLOBALS['TYPO3_CONF_VARS']['FE']['addAllowedPaths'],1);
00228 while(list(,$p)=each($pathArr)) {
00229
00230 $this->allowedPaths[] = $p;
00231 }
00232 }
00233 }
00234
00247 function getCurrentPageData() {
00248 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('content', 'cache_pagesection', 'page_id='.intval($GLOBALS['TSFE']->id).' AND mpvar_hash='.t3lib_div::md5int($GLOBALS['TSFE']->MP));
00249 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00250 $this->currentPageData = unserialize($row['content']);
00251 } else {
00252 $this->currentPageData = 'none';
00253 }
00254 return $this->currentPageData;
00255 }
00256
00264 function matching($cc) {
00265 if (is_array($cc['all'])) {
00266 reset($cc['all']);
00267 $matchObj = t3lib_div::makeInstance('t3lib_matchCondition');
00268 $matchObj->altRootLine=$cc['rootLine'];
00269 while(list($key,$pre)=each($cc['all'])) {
00270 if ($matchObj->match($pre)) {
00271 $sectionsMatch[$key]=$pre;
00272 }
00273 }
00274 $cc['match']=$sectionsMatch;
00275 }
00276 return $cc;
00277 }
00278
00288 function start($theRootLine) {
00289 if (is_array($theRootLine)) {
00290 $setupData='';
00291 $cc=Array();
00292 $hash='';
00293 $this->runThroughTemplates($theRootLine);
00294
00295
00296 if (!$this->currentPageData) {
00297 $this->getCurrentPageData();
00298 }
00299
00300
00301
00302
00303 if (is_array($this->currentPageData) &&
00304 !strcmp(serialize($this->rowSum), serialize($this->currentPageData['rowSum']))
00305 ) {
00306
00307 $cc['all'] = $this->currentPageData['all'];
00308 $cc['rowSum'] = $this->currentPageData['rowSum'];
00309 $cc = $this->matching($cc);
00310 $hash = md5(serialize($cc));
00311 } else {
00312
00313 $rowSumHash = md5('ROWSUM:'.serialize($this->rowSum));
00314 $result = t3lib_pageSelect::getHash($rowSumHash, 0);
00315 if ($result) {
00316 $cc['all'] = unserialize($result);
00317 $cc['rowSum'] = $this->rowSum;
00318 $cc = $this->matching($cc);
00319 $hash = md5(serialize($cc));
00320 }
00321 }
00322
00323 if ($hash) {
00324
00325 $setupData = t3lib_pageSelect::getHash($hash, 0);
00326 }
00327
00328 if ($hash && $setupData && !$this->forceTemplateParsing) {
00329
00330 $this->setup = unserialize($setupData);
00331 } else {
00332
00333 $this->generateConfig();
00334
00335
00336 $cc=Array();
00337 $cc['all']=$this->sections;
00338 $cc['rowSum']=$this->rowSum;
00339 $cc = $this->matching($cc);
00340
00341 $hash = md5(serialize($cc));
00342
00343
00344 t3lib_pageSelect::storeHash($hash, serialize($this->setup), 'TS TEMPLATE');
00345
00346 if ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('TS template size, serialized: '.strlen(serialize($this->setup)).' bytes');
00347
00348 $rowSumHash = md5('ROWSUM:'.serialize($this->rowSum));
00349 t3lib_pageSelect::storeHash($rowSumHash, serialize($cc['all']), 'TMPL CONDITIONS - AL');
00350 }
00351
00352 $cc['rootLine'] = $this->rootLine;
00353
00354 $GLOBALS['TSFE']->all=$cc;
00355
00356 if (!$this->simulationHiddenOrTime) {
00357 $insertFields = array(
00358 'page_id' => intval($GLOBALS['TSFE']->id),
00359 'mpvar_hash' => t3lib_div::md5int($GLOBALS['TSFE']->MP),
00360 'content' => serialize($cc),
00361 'tstamp' => $GLOBALS['EXEC_TIME']
00362 );
00363 $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pagesection', 'page_id='.intval($GLOBALS['TSFE']->id).' AND mpvar_hash='.t3lib_div::md5int($GLOBALS['TSFE']->MP));
00364
00365 $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_pagesection', $insertFields);
00366 }
00367
00368 if ($this->rootId && $this->rootLine && $this->setup) {
00369 $this->loaded = 1;
00370 }
00371 }
00372 }
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00404 function runThroughTemplates($theRootLine,$start_template_uid=0) {
00405 $this->constants = Array();
00406 $this->config = Array();
00407 $this->editorcfg = Array();
00408 $this->rowSum = Array();
00409 $this->hierarchyInfoToRoot = Array();
00410 $this->absoluteRootLine=$theRootLine;
00411
00412 reset ($this->absoluteRootLine);
00413 $c=count($this->absoluteRootLine);
00414 for ($a=0;$a<$c;$a++) {
00415 if ($this->nextLevel) {
00416 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'uid='.intval($this->nextLevel).' '.$this->whereClause);
00417 $this->nextLevel = 0;
00418 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00419 $this->processTemplate($row,'sys_'.$row['uid'],$this->absoluteRootLine[$a]['uid'],'sys_'.$row['uid']);
00420 $this->outermostRootlineIndexWithTemplate=$a;
00421 }
00422 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00423 }
00424 $addC='';
00425 if ($a==($c-1) && $start_template_uid) {
00426 $addC=' AND uid='.intval($start_template_uid);
00427 }
00428
00429 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid='.intval($this->absoluteRootLine[$a]['uid']).$addC.' '.$this->whereClause,'','sorting',1);
00430 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00431 $this->processTemplate($row,'sys_'.$row['uid'],$this->absoluteRootLine[$a]['uid'],'sys_'.$row['uid']);
00432 $this->outermostRootlineIndexWithTemplate=$a;
00433 }
00434 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00435 $this->rootLine[] = $this->absoluteRootLine[$a];
00436 }
00437 }
00438
00451 function processTemplate($row, $idList,$pid,$templateID='',$templateParent='') {
00452
00453 $this->rowSum[]=Array($row['uid'],$row['title'],$row['tstamp']);
00454
00455
00456 if ($row['clear']) {
00457 $clConst = $row['clear']&1;
00458 $clConf = $row['clear']&2;
00459 if ($clConst) {
00460 $this->constants = Array();
00461 $this->clearList_const=array();
00462 }
00463 if ($clConf) {
00464 $this->config = Array();
00465 $this->hierarchyInfoToRoot = Array();
00466 $this->clearList_setup=array();
00467
00468 $this->editorcfg = Array();
00469 $this->clearList_editorcfg=array();
00470 }
00471 }
00472
00473
00474 if (!$row['includeStaticAfterBasedOn']) {
00475 $this->includeStaticTypoScriptSources($idList,$templateID,$pid,$row);
00476 }
00477
00478
00479 if (trim($row['basedOn'])) {
00480
00481
00482
00483 $basedOn_hackFeature = explode('=',$row['basedOn']);
00484 if ($basedOn_hackFeature[0]=='EXTERNAL_BASED_ON_TEMPLATE_ID' && $basedOn_hackFeature[1]) {
00485 $id = intval(t3lib_div::_GET($basedOn_hackFeature[1]));
00486 if ($id && !t3lib_div::inList($idList,'sys_'.$id)) {
00487 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'uid='.$id.' '.$this->whereClause);
00488 if ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00489 $this->processTemplate($subrow,$idList.',sys_'.$id,$pid, 'sys_'.$id,$templateID);
00490 }
00491 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00492 }
00493 } else {
00494 $basedOnArr = t3lib_div::intExplode(',',$row['basedOn']);
00495 while(list(,$id)=each($basedOnArr)) {
00496 if (!t3lib_div::inList($idList,'sys_'.$id)) {
00497 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'uid='.intval($id).' '.$this->whereClause);
00498 if ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00499 $this->processTemplate($subrow,$idList.',sys_'.$id,$pid, 'sys_'.$id,$templateID);
00500 }
00501 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00502 }
00503 }
00504 }
00505 }
00506
00507
00508 if ($row['includeStaticAfterBasedOn']) {
00509 $this->includeStaticTypoScriptSources($idList,$templateID,$pid,$row);
00510 }
00511
00512
00513 $this->hierarchyInfo[] = $this->hierarchyInfoToRoot[] = array(
00514 'root'=>trim($row['root']),
00515 'next'=>$row['nextLevel'],
00516 'clConst'=>$clConst,
00517 'clConf'=>$clConf,
00518 'templateID'=>$templateID,
00519 'templateParent'=>$templateParent,
00520 'title'=>$row['title'],
00521 'uid'=>$row['uid'],
00522 'pid'=>$row['pid'],
00523 'configLines' => substr_count($row['config'], chr(10))+1
00524 );
00525
00526
00527 $this->constants[] = $row['constants'];
00528 $this->config[] = $row['config'];
00529 if ($this->parseEditorCfgField) $this->editorcfg[] = $row['editorcfg'];
00530
00531
00532 $this->clearList_const[]=$templateID;
00533 $this->clearList_setup[]=$templateID;
00534 if ($this->parseEditorCfgField) $this->clearList_editorcfg[]=$templateID;
00535
00536
00537 if (trim($row['resources'])) {
00538 $this->resources = $row['resources'].','.$this->resources;
00539 }
00540 if (trim($row['sitetitle'])) {
00541 $this->sitetitle = $row['sitetitle'];
00542 }
00543
00544 if (trim($row['root'])) {
00545 $this->rootId = $pid;
00546 $this->rootLine = Array();
00547 }
00548
00549 if ($row['nextLevel']) {
00550 $this->nextLevel = $row['nextLevel'];
00551 } else {
00552 $this->nextLevel = 0;
00553 }
00554 }
00555
00566 function includeStaticTypoScriptSources($idList,$templateID,$pid,$row) {
00567
00568 if (trim($row['include_static'])) {
00569 $include_staticArr = t3lib_div::intExplode(',',$row['include_static']);
00570 reset($include_staticArr);
00571 while(list(,$id)=each($include_staticArr)) {
00572 if (!t3lib_div::inList($idList,'static_'.$id)) {
00573 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'static_template', 'uid='.intval($id));
00574 if ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00575 $subrow = $this->prependStaticExtra($subrow);
00576 $this->processTemplate($subrow,$idList.',static_'.$id,$pid,'static_'.$id,$templateID);
00577 }
00578 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00579 }
00580 }
00581 }
00582
00583
00584 if (trim($row['include_static_file'])) {
00585 $include_static_fileArr = t3lib_div::trimExplode(',',$row['include_static_file'],1);
00586 reset($include_static_fileArr);
00587 while(list(,$ISF_file)=each($include_static_fileArr)) {
00588 $ISF_file = trim($ISF_file);
00589 if (substr($ISF_file,0,4)=='EXT:') {
00590 list($ISF_extKey,$ISF_localPath) = explode('/',substr($ISF_file,4),2);
00591 if (strcmp($ISF_extKey,'') && t3lib_extMgm::isLoaded($ISF_extKey) && strcmp($ISF_localPath,'')) {
00592 $ISF_localPath = ereg_replace('\/$','',$ISF_localPath).'/';
00593 $ISF_filePath = t3lib_extMgm::extPath($ISF_extKey).$ISF_localPath;
00594 if (@is_dir($ISF_filePath)) {
00595 $mExtKey = str_replace('_','',$ISF_extKey.'/'.$ISF_localPath);
00596 $subrow=array(
00597 'constants'=> @is_file($ISF_filePath.'constants.txt') ?t3lib_div::getUrl($ISF_filePath.'constants.txt'):'',
00598 'config'=> @is_file($ISF_filePath.'setup.txt') ?t3lib_div::getUrl($ISF_filePath.'setup.txt'):'',
00599 'editorcfg'=> @is_file($ISF_filePath.'editorcfg.txt') ?t3lib_div::getUrl($ISF_filePath.'editorcfg.txt'):'',
00600 'include_static'=> @is_file($ISF_filePath.'include_static.txt')?implode(',',array_unique(t3lib_div::intExplode(',',t3lib_div::getUrl($ISF_filePath.'include_static.txt')))):'',
00601 'include_static_file'=> @is_file($ISF_filePath.'include_static_file.txt')?implode(',',array_unique(explode(',',t3lib_div::getUrl($ISF_filePath.'include_static_file.txt')))):'',
00602 'title' => $ISF_file,
00603 'uid' => $mExtKey
00604 );
00605 $subrow = $this->prependStaticExtra($subrow);
00606
00607 $this->processTemplate($subrow,$idList.',ext_'.$mExtKey,$pid, 'ext_'.$mExtKey,$templateID);
00608 }
00609 }
00610 }
00611 }
00612 }
00613
00614 $this->addExtensionStatics($idList,$templateID,$pid,$row);
00615 }
00616
00628 function addExtensionStatics($idList,$templateID,$pid,$row) {
00629 global $TYPO3_LOADED_EXT;
00630
00631 if ($row['static_file_mode']==1 || ($row['static_file_mode']==0 && substr($templateID,0,4)=='sys_' && $row['root'])) {
00632 reset($TYPO3_LOADED_EXT);
00633 while(list($extKey,$files)=each($TYPO3_LOADED_EXT)) {
00634 if (is_array($files) && ($files['ext_typoscript_constants.txt'] || $files['ext_typoscript_setup.txt'] || $files['ext_typoscript_editorcfg.txt'])) {
00635 $mExtKey = str_replace('_','',$extKey);
00636 $subrow=array(
00637 'constants'=> $files['ext_typoscript_constants.txt']?t3lib_div::getUrl($files['ext_typoscript_constants.txt']):'',
00638 'config'=> $files['ext_typoscript_setup.txt']?t3lib_div::getUrl($files['ext_typoscript_setup.txt']):'',
00639 'editorcfg'=> $files['ext_typoscript_editorcfg.txt']?t3lib_div::getUrl($files['ext_typoscript_editorcfg.txt']):'',
00640 'title' => $extKey,
00641 'uid' => $mExtKey
00642 );
00643 $subrow = $this->prependStaticExtra($subrow);
00644
00645 $this->processTemplate($subrow,$idList.',ext_'.$mExtKey,$pid, 'ext_'.$mExtKey,$templateID);
00646 }
00647 }
00648 }
00649 }
00650
00661 function prependStaticExtra($subrow) {
00662 $subrow['config'].=$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'][$subrow['uid']];
00663 $subrow['editorcfg'].=$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_editorcfg.'][$subrow['uid']];
00664 $subrow['constants'].=$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants.'][$subrow['uid']];
00665 return $subrow;
00666 }
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00697 function generateConfig() {
00698
00699 array_unshift($this->constants,''.$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants']);
00700 array_unshift($this->config,''.$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup']);
00701 array_unshift($this->editorcfg,''.$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_editorcfg']);
00702
00703
00704 $this->procesIncludes();
00705
00706
00707 $this->setup['resources']= $this->resources;
00708 $this->setup['sitetitle']= $this->sitetitle;
00709
00710
00711
00712
00713
00714
00715
00716
00717 $constants = t3lib_div::makeInstance('t3lib_TSparser');
00718 $constants->breakPointLN=intval($this->ext_constants_BRP);
00719 $constants->setup = $this->const;
00720 $constants->setup = $this->mergeConstantsFromPageTSconfig($constants->setup);
00721 $matchObj = t3lib_div::makeInstance('t3lib_matchCondition');
00722 $matchObj->matchAlternative = $this->matchAlternative;
00723 $matchObj->matchAll = $this->matchAll;
00724
00725
00726 foreach($this->constants as $str) {
00727 $constants->parse($str,$matchObj);
00728 }
00729
00730
00731 $this->parserErrors['constants']=$constants->errors;
00732
00733
00734 $this->flatSetup = Array();
00735 $this->flattenSetup($constants->setup,'','');
00736
00737
00738
00739
00740
00741
00742
00743 $config = t3lib_div::makeInstance('t3lib_TSparser');
00744 $config->breakPointLN = intval($this->ext_config_BRP);
00745 $config->regLinenumbers = $this->ext_regLinenumbers;
00746 $config->setup = $this->setup;
00747
00748
00749 $config->sections = $constants->sections;
00750 $config->sectionsMatch = $constants->sectionsMatch;
00751
00752
00753 $all='';
00754 foreach($this->config as $str) {
00755 $all.="\n[GLOBAL]\n".$str;
00756 }
00757
00758
00759 if ($this->tt_track) $GLOBALS['TT']->push('Substitute Constants ('.count($this->flatSetup).')');
00760 $all = $this->substituteConstants($all);
00761 if ($this->tt_track) $GLOBALS['TT']->pull();
00762
00763
00764 if (strstr($all,'{$')) {
00765 $findConst = explode('{$',$all);
00766 $theConstList=Array();
00767 next($findConst);
00768 while(list(,$constVal)=each($findConst)) {
00769 $constLen=t3lib_div::intInRange(strcspn($constVal,'}'),0,50);
00770 $theConstList[]='{$'.substr($constVal,0,$constLen+1);
00771 }
00772 if ($this->tt_track) $GLOBALS['TT']->setTSlogMessage(implode(',',$theConstList).': Constants may remain un-substituted!!',2);
00773 }
00774
00775
00776 if ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('TypoScript template size as textfile: '.strlen($all).' bytes');
00777
00778
00779 $config->parse($all,$matchObj);
00780
00781
00782 $this->parserErrors['config']=$config->errors;
00783
00784
00785 $this->setup = $config->setup;
00786 if ($this->backend_info) {
00787 $this->setup_constants = $constants->setup;
00788 }
00789
00790
00791
00792
00793
00794
00795
00796 if ($this->parseEditorCfgField) {
00797 $editorcfg = t3lib_div::makeInstance('t3lib_TSparser');
00798 $editorcfg->breakPointLN=intval($this->ext_editorcfg_BRP);
00799 $editorcfg->setup = array();
00800
00801 $all = implode("\n[GLOBAL]\n",$this->editorcfg);
00802
00803
00804 $all = $this->substituteConstants($all);
00805
00806
00807 $matchObj->matchAll=1;
00808 $editorcfg->parse($all,$matchObj);
00809 $this->parserErrors['editorcfg']=$editorcfg->errors;
00810 $this->setup_editorcfg = $editorcfg->setup;
00811 }
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823 unset($this->setup['resources']);
00824 unset($this->setup['resources.']);
00825 $this->setup['resources']= implode(',',t3lib_div::trimExplode(',',$this->resources,1));
00826
00827 unset($this->setup['sitetitle']);
00828 unset($this->setup['sitetitle.']);
00829 $this->setup['sitetitle']= $this->sitetitle;
00830
00831
00832 unset($this->setup['types.']);
00833 unset($this->setup['types']);
00834 if (is_array($this->setup)) {
00835 reset ($this->setup);
00836 while(list($theKey,)=each($this->setup)) {
00837 if ($this->setup[$theKey]=='PAGE') {
00838 $tN = $this->setup[$theKey.'.']['typeNum'];
00839 if (isset($tN)) {
00840 $this->setup['types.'][$tN] = $theKey;
00841 } elseif(!$this->setup['types.'][0]) {
00842 $this->setup['types.'][0] = $theKey;
00843 }
00844 }
00845 }
00846 }
00847 unset($this->setup['styles.']);
00848 unset($this->setup['temp.']);
00849 unset($constants);
00850
00851
00852 $this->sections = $config->sections;
00853 $this->sectionsMatch = $config->sectionsMatch;
00854 }
00855
00863 function procesIncludes() {
00864 reset($this->constants);
00865 while(list($k)=each($this->constants)) {
00866 $this->constants[$k]=t3lib_TSparser::checkIncludeLines($this->constants[$k]);
00867 }
00868
00869 reset($this->config);
00870 while(list($k)=each($this->config)) {
00871 $this->config[$k]=t3lib_TSparser::checkIncludeLines($this->config[$k]);
00872 }
00873
00874 reset($this->editorcfg);
00875 while(list($k)=each($this->editorcfg)) {
00876 $this->editorcfg[$k]=t3lib_TSparser::checkIncludeLines($this->editorcfg[$k]);
00877 }
00878 }
00879
00887 function mergeConstantsFromPageTSconfig($constArray) {
00888 $TSdataArray = array();
00889 $TSdataArray[]=$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig'];
00890
00891 for ($a=0;$a<=$this->outermostRootlineIndexWithTemplate;$a++) {
00892 $TSdataArray[]=$this->absoluteRootLine[$a]['TSconfig'];
00893 }
00894
00895 $TSdataArray = t3lib_TSparser::checkIncludeLines_array($TSdataArray);
00896 $userTS = implode(chr(10).'[GLOBAL]'.chr(10),$TSdataArray);
00897
00898 $parseObj = t3lib_div::makeInstance('t3lib_TSparser');
00899 $parseObj->parse($userTS);
00900
00901 if (is_array($parseObj->setup['TSFE.']['constants.'])) {
00902 $constArray = t3lib_div::array_merge_recursive_overrule($constArray,$parseObj->setup['TSFE.']['constants.']);
00903 }
00904 return $constArray;
00905 }
00906
00916 function flattenSetup($setupArray, $prefix, $resourceFlag) {
00917 if (is_array($setupArray)) {
00918 reset($setupArray);
00919 while(list($key,$val)=each($setupArray)) {
00920 if ($prefix || substr($key,0,16)!='TSConstantEditor') {
00921 if (is_array($val)) {
00922 $this->flattenSetup($val,$prefix.$key, ($key=='file.'));
00923 } elseif ($resourceFlag) {
00924 $this->flatSetup[$prefix.$key] = $this->getFileName($val);
00925 } else {
00926 $this->flatSetup[$prefix.$key] = $val;
00927 }
00928 }
00929 }
00930 }
00931 }
00932
00940 function substituteConstants($all) {
00941 if ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('Constants to substitute: '.count($this->flatSetup));
00942 reset($this->flatSetup);
00943 while (list($const,$val)=each($this->flatSetup)) {
00944 if (!is_array($val)) {
00945 $all = str_replace('{$'.$const.'}',$val,$all);
00946 }
00947 }
00948 return $all;
00949 }
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00978 function splitConfArray($conf,$splitCount) {
00979
00980
00981 $splitCount = intval($splitCount);
00982 $conf2 = Array();
00983
00984 if ($splitCount && is_array($conf)) {
00985
00986
00987 for ($aKey=0;$aKey<$splitCount;$aKey++) {
00988 $conf2[$aKey] = array();
00989 }
00990
00991
00992 foreach($conf as $cKey => $val) {
00993 if (is_array($val)) {
00994 $tempConf = $this->splitConfArray($val,$splitCount);
00995 foreach($tempConf as $aKey => $val) {
00996 $conf2[$aKey][$cKey] = $val;
00997 }
00998 }
00999 }
01000
01001
01002 foreach($conf as $cKey => $val) {
01003 if (!is_array($val)) {
01004 if (!strstr($val,'|*|') && !strstr($val,'||')) {
01005 for ($aKey=0;$aKey<$splitCount;$aKey++) {
01006 $conf2[$aKey][$cKey] = $val;
01007 }
01008 } else {
01009 $main = explode ('|*|',$val);
01010 $mainCount = count($main);
01011
01012 $lastC = 0;
01013 $middleC = 0;
01014 $firstC = 0;
01015
01016 if ($main[0]) {
01017 $first = explode('||',$main[0]);
01018 $firstC = count($first);
01019 }
01020 if ($main[1]) {
01021 $middle = explode('||',$main[1]);
01022 $middleC = count($middle);
01023 }
01024 if ($main[2]) {
01025 $last = explode('||',$main[2]);
01026 $lastC = count($last);
01027 $value = $last[0];
01028 }
01029
01030 for ($aKey=0;$aKey<$splitCount;$aKey++) {
01031 if ($firstC && isset($first[$aKey])) {
01032 $value = $first[$aKey];
01033 } elseif ($middleC) {
01034 $value = $middle[($aKey-$firstC)%$middleC];
01035 }
01036 if ($lastC && $lastC>=($splitCount-$aKey)) {
01037 $value = $last[$lastC-($splitCount-$aKey)];
01038 }
01039 $conf2[$aKey][$cKey] = trim($value);
01040 }
01041 }
01042 }
01043 }
01044 }
01045 return $conf2;
01046 }
01047
01055 function getFileName($fileFromSetup) {
01056 $file = trim($fileFromSetup);
01057 if (!$file) return;
01058
01059 $hash = md5($file);
01060 if (isset($this->fileCache[$hash])) {
01061 return $this->fileCache[$hash];
01062 }
01063
01064 if (!strcmp(substr($file,0,4),'EXT:')) {
01065 $newFile='';
01066 list($extKey,$script)=explode('/',substr($file,4),2);
01067 if ($extKey && t3lib_extMgm::isLoaded($extKey)) {
01068 $extPath=t3lib_extMgm::extPath($extKey);
01069 $newFile=substr($extPath,strlen(PATH_site)).$script;
01070 }
01071 if (!@is_file(PATH_site.$newFile)) {
01072 if ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('Extension media file "'.$newFile.'" was not found!',3);
01073 return;
01074 } else $file=$newFile;
01075 }
01076
01077
01078 if (strstr($file,'/')) {
01079 if (@is_file($this->getFileName_backPath.$file)) {
01080 $outFile = $file;
01081 $fileInfo = t3lib_div::split_fileref($outFile);
01082 reset($this->allowedPaths);
01083 $OK=0;
01084 while(list(,$val)=each($this->allowedPaths)) {
01085 if (substr($fileInfo['path'],0,strlen($val))==$val){$OK=1; break;}
01086 }
01087 if ($OK) {
01088 $this->fileCache[$hash]=$outFile;
01089 return $outFile;
01090 } elseif ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('"'.$file.'" was not located in the allowed paths: ('.implode(',',$this->allowedPaths).')',3);
01091 } elseif ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('"'.$this->getFileName_backPath.$file.'" is not a file (non-uploads/.. resource, did not exist).',3);
01092 } else { // Here it is uploaded media:
01093 $outFile = $this->extractFromResources($this->setup['resources'],$file);
01094 if ($outFile) {
01095 if (@is_file($this->uplPath.$outFile)) {
01096 $this->fileCache[$hash] = $this->uplPath.$outFile;
01097 return $this->uplPath.$outFile;
01098 } elseif ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('"'.$this->uplPath.$outFile.'" is not a file (did not exist).',3);
01099 } elseif ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('"'.$file.'" is not a file (uploads/.. resource).',3);
01100 }
01101 }
01102
01112 function extractFromResources($res,$file) {
01113 if (t3lib_div::inList($res,$file)) {
01114 $outFile = $file;
01115 } elseif (strstr($file,'*')) {
01116 $fileparts=explode('*',$file);
01117 $c=count($fileparts);
01118 $files = explode(',',$res);
01119 while(list(,$val)=each($files)) {
01120 $test = trim($val);
01121 if (ereg('^'.quotemeta($fileparts[0]).'.*'.quotemeta($fileparts[$c-1]).'$', $test)) {
01122 $outFile = $test;
01123 break;
01124 }
01125 }
01126 }
01127 return $outFile;
01128 }
01129
01140 function checkFile($name,$menuArr) {
01141 reset ($menuArr);
01142 while (list($aKey,)=each($menuArr)) {
01143 $menuArr[$aKey][$name] = $this->getFileName($menuArr[$aKey][$name]);
01144 }
01145 return $menuArr;
01146 }
01147
01157 function printTitle($title,$no_title=0,$titleFirst=0) {
01158 $st = trim($this->setup['sitetitle']) ? $this->setup['sitetitle']:'';
01159 $title = $no_title ? '' : $title;
01160 if ($titleFirst) {
01161 $temp=$st;
01162 $st=$title;
01163 $title=$temp;
01164 }
01165 if ($title && $st) {
01166 return $st.': '.$title;
01167 } else {
01168 return $st.$title;
01169 }
01170 }
01171
01180 function fileContent($fName) {
01181 $incFile = $this->getFileName($fName);
01182 if ($incFile && $fd=fopen($incFile,'rb')) {
01183 $content = '';
01184 while (!feof($fd)) {
01185 $content.=fread($fd, 5000);
01186 }
01187 fclose( $fd );
01188 return $content;
01189 }
01190 }
01191
01200 function wrap($content,$wrap) {
01201 if ($wrap) {
01202 $wrapArr = explode('|', $wrap);
01203 return trim($wrapArr[0]).$content.trim($wrapArr[1]);
01204 } else return $content;
01205 }
01206
01214 function removeQueryString($url) {
01215 if (substr($url,-1)=='?') {
01216 return substr($url,0,-1);
01217 } else {
01218 return $url;
01219 }
01220 }
01221
01231 function sortedKeyList($setupArr, $acceptOnlyProperties=FALSE) {
01232 $keyArr = Array();
01233
01234 reset($setupArr);
01235 while(list($key,)=each($setupArr)) {
01236 $ikey = intval($key);
01237 if (!strcmp($ikey,$key) || $acceptOnlyProperties) {
01238 $keyArr[] = $ikey;
01239 }
01240 }
01241
01242 $keyArr = array_unique($keyArr);
01243 sort($keyArr);
01244 return $keyArr;
01245 }
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256 /*******************************************************************
01257 *
01258 * Functions for creating links
01259 *
01260 *******************************************************************/
01261
01278 function linkData($page,$oTarget,$no_cache,$script,$overrideArray='',$addParams='',$typeOverride='') {
01279 global $TYPO3_CONF_VARS;
01280
01281 $LD = Array();
01282
01283 // Overriding some fields in the page record and still preserves the values by adding them as parameters. Little strange function.
01284 if (is_array($overrideArray)) {
01285 foreach($overrideArray as $theKey => $theNewVal) {
01286 $addParams.= '&real_'.$theKey.'='.rawurlencode($page[$theKey]);
01287 $page[$theKey] = $theNewVal;
01288 }
01289 }
01290
01291 // Adding Mount Points, "&MP=", parameter for the current page if any is set:
01292 if (!strstr($addParams,'&MP=')) {
01293 if (trim($GLOBALS['TSFE']->MP_defaults[$page['uid']])) { // Looking for hardcoded defaults:
01294 $addParams.= '&MP='.rawurlencode(trim($GLOBALS['TSFE']->MP_defaults[$page['uid']]));
01295 } elseif ($GLOBALS['TSFE']->config['config']['MP_mapRootPoints']) { // Else look in automatically created map:
01296 $m = $this->getFromMPmap($page['uid']);
01297 if ($m) {
01298 $addParams.= '&MP='.rawurlencode($m);
01299 }
01300 }
01301 }
01302
01303 // Setting ID/alias:
01304 if (!$script) {$script = $GLOBALS['TSFE']->config['mainScript'];}
01305 if ($page['alias']) {
01306 $LD['url'] = $script.'?id='.rawurlencode($page['alias']);
01307 } else {
01308 $LD['url'] = $script.'?id='.$page['uid'];
01309 }
01310 // Setting target
01311 $LD['target'] = trim($page['target']) ? trim($page['target']) : $oTarget;
01312
01313 // typeNum
01314 $typeNum = $this->setup[$LD['target'].'.']['typeNum'];
01315 if (!$typeOverride && intval($GLOBALS['TSFE']->config['config']['forceTypeValue'])) {
01316 $typeOverride = intval($GLOBALS['TSFE']->config['config']['forceTypeValue']);
01317 }
01318 if (strcmp($typeOverride,'')) { $typeNum = $typeOverride; } // Override...
01319 if ($typeNum) {
01320 $LD['type'] = '&type='.intval($typeNum);
01321 } else {
01322 $LD['type'] = '';
01323 }
01324 $LD['orig_type'] = $LD['type']; // Preserving the type number. Will not be cleared if simulateStaticDocuments.
01325
01326 // noCache
01327 $LD['no_cache'] = (trim($page['no_cache']) || $no_cache) ? '&no_cache=1' : '';
01328
01329 // linkVars
01330 if ($GLOBALS['TSFE']->config['config']['uniqueLinkVars']) {
01331 if ($addParams) {
01332 $LD['linkVars'] = t3lib_div::implodeArrayForUrl('',t3lib_div::explodeUrl2Array($GLOBALS['TSFE']->linkVars.$addParams));
01333 } else {
01334 $LD['linkVars'] = $GLOBALS['TSFE']->linkVars;
01335 }
01336 } else {
01337 $LD['linkVars'] = $GLOBALS['TSFE']->linkVars.$addParams;
01338 }
01339
01340 // If simulateStaticDocuments is enabled:
01341 if ($GLOBALS['TSFE']->config['config']['simulateStaticDocuments']) {
01342 $LD['type'] = '';
01343 $LD['url'] = '';
01344
01345 // MD5/base64 method limitation:
01346 $remainLinkVars='';
01347 $flag_simulateStaticDocuments_pEnc = t3lib_div::inList('md5,base64',$GLOBALS['TSFE']->config['config']['simulateStaticDocuments_pEnc']) && !$LD['no_cache'];
01348 if ($flag_simulateStaticDocuments_pEnc) {
01349 list($LD['linkVars'], $remainLinkVars) = $GLOBALS['TSFE']->simulateStaticDocuments_pEnc_onlyP_proc($LD['linkVars']);
01350 }
01351
01352 $LD['url'].=$GLOBALS['TSFE']->makeSimulFileName(
01353 $page['title'],
01354 $page['alias'] ? $page['alias'] : $page['uid'],
01355 intval($typeNum),
01356 $LD['linkVars'],
01357 $LD['no_cache']?1:0
01358 );
01359
01360 if ($flag_simulateStaticDocuments_pEnc) {
01361 $LD['linkVars']=$remainLinkVars;
01362 }
01363 if ($GLOBALS['TSFE']->config['config']['simulateStaticDocuments']=='PATH_INFO') {
01364 $LD['url'] = str_replace('.','/',$LD['url']);
01365 $LD['url'] = 'index.php/'.$LD['url'].'/?';
01366 } else {
01367 $LD['url'].= '.html?';
01368 }
01369 }
01370
01371 // Add absRefPrefix if exists.
01372 $LD['url'] = $GLOBALS['TSFE']->absRefPrefix.$LD['url'];
01373
01374 // 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.
01375 $LD['sectionIndex'] = $page['sectionIndex_uid'] ? '#'.$page['sectionIndex_uid'] : '';
01376
01377 // Compile the normal total url
01378 $LD['totalURL']= $this->removeQueryString($LD['url'].$LD['type'].$LD['no_cache'].$LD['linkVars'].$GLOBALS['TSFE']->getMethodUrlIdToken).$LD['sectionIndex'];
01379
01380 // Call post processing function for link rendering:
01381 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['linkData-PostProc'])) {
01382 $_params = array(
01383 'LD' => &$LD,
01384 'args' => array('page'=>$page, 'oTarget'=>$oTarget, 'no_cache'=>$no_cache, 'script'=>$script, 'overrideArray'=>$overrideArray, 'addParams'=>$addParams, 'typeOverride'=>$typeOverride),
01385 'typeNum' => $typeNum
01386 );
01387 foreach($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['linkData-PostProc'] as $_funcRef) {
01388 t3lib_div::callUserFunction($_funcRef,$_params,$this);
01389 }
01390 }
01391
01392 // Return the LD-array
01393 return $LD;
01394 }
01395
01405 function getFromMPmap($pageId=0) {
01406
01407 // Create map if not found already:
01408 if (!is_array($this->MPmap)) {
01409 $this->MPmap = array();
01410
01411 $rootPoints = t3lib_div::trimExplode(',', strtolower($GLOBALS['TSFE']->config['config']['MP_mapRootPoints']),1);
01412 foreach($rootPoints as $p) { // Traverse rootpoints:
01413 if ($p == 'root') {
01414 $p = $this->rootLine[0]['uid'];
01415 $initMParray = array();
01416 if ($this->rootLine[0]['_MOUNT_OL'] && $this->rootLine[0]['_MP_PARAM']) {
01417 $initMParray[] = $this->rootLine[0]['_MP_PARAM'];
01418 }
01419 }
01420 $this->initMPmap_create($p,$initMParray);
01421 }
01422 }
01423
01424 // Finding MP var for Page ID:
01425 if ($pageId) {
01426 if (is_array($this->MPmap[$pageId]) && count($this->MPmap[$pageId])) {
01427 return implode(',',$this->MPmap[$pageId]);
01428 }
01429 }
01430 }
01431
01441 function initMPmap_create($id,$MP_array=array(),$level=0) {
01442
01443 $id = intval($id);
01444 if($id<=0) return;
01445
01446 // First level, check id
01447 if (!$level) {
01448
01449 // Find mount point if any:
01450 $mount_info = $GLOBALS['TSFE']->sys_page->getMountPointInfo($id);
01451
01452 // Overlay mode:
01453 if (is_array($mount_info) && $mount_info['overlay']) {
01454 $MP_array[] = $mount_info['MPvar'];
01455 $id = $mount_info['mount_pid'];
01456 }
01457
01458 // Set mapping information for this level:
01459 $this->MPmap[$id] = $MP_array;
01460
01461 // Normal mode:
01462 if (is_array($mount_info) && !$mount_info['overlay']) {
01463 $MP_array[] = $mount_info['MPvar'];
01464 $id = $mount_info['mount_pid'];
01465 }
01466 }
01467
01468 if ($id && $level<20) {
01469
01470 $nextLevelAcc = array();
01471
01472 // Select and traverse current level pages:
01473 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
01474 'uid,pid,doktype,mount_pid,mount_pid_ol',
01475 'pages',
01476 'pid='.intval($id).' AND deleted=0 AND doktype!=255 AND doktype!=6' // 255 = Garbage bin, 6 = Backend User Section
01477 );
01478 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
01479
01480 // Find mount point if any:
01481 $next_id = $row['uid'];
01482 $next_MP_array = $MP_array;
01483 $mount_info = $GLOBALS['TSFE']->sys_page->getMountPointInfo($next_id, $row);
01484
01485 // Overlay mode:
01486 if (is_array($mount_info) && $mount_info['overlay']) {
01487 $next_MP_array[] = $mount_info['MPvar'];
01488 $next_id = $mount_info['mount_pid'];
01489 }
01490
01491 if (!isset($this->MPmap[$next_id])) {
01492
01493 // Set mapping information for this level:
01494 $this->MPmap[$next_id] = $next_MP_array;
01495
01496 // Normal mode:
01497 if (is_array($mount_info) && !$mount_info['overlay']) {
01498 $next_MP_array[] = $mount_info['MPvar'];
01499 $next_id = $mount_info['mount_pid'];
01500 }
01501
01502 // Register recursive call
01503 // (have to do it this way since ALL of the current level should be registered BEFORE the sublevel at any time)
01504 $nextLevelAcc[] = array($next_id,$next_MP_array);
01505 }
01506 }
01507
01508 // Call recursively, if any:
01509 foreach($nextLevelAcc as $pSet) {
01510 $this->initMPmap_create($pSet[0],$pSet[1],$level+1);
01511 }
01512 }
01513 }
01514 }
01515
01516
01517 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tstemplate.php']) {
01518 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tstemplate.php']);
01519 }
01520 ?>