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 - ALL');
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 $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_pagesection', $insertFields);
00365 }
00366
00367 if ($this->rootId && $this->rootLine && $this->setup) {
00368 $this->loaded = 1;
00369 }
00370 }
00371 }
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00403 function runThroughTemplates($theRootLine,$start_template_uid=0) {
00404 $this->constants = Array();
00405 $this->config = Array();
00406 $this->editorcfg = Array();
00407 $this->rowSum = Array();
00408 $this->hierarchyInfoToRoot = Array();
00409 $this->absoluteRootLine=$theRootLine;
00410
00411 reset ($this->absoluteRootLine);
00412 $c=count($this->absoluteRootLine);
00413 for ($a=0;$a<$c;$a++) {
00414 if ($this->nextLevel) {
00415 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'uid='.intval($this->nextLevel).' '.$this->whereClause);
00416 $this->nextLevel = 0;
00417 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00418 $this->processTemplate($row,'sys_'.$row['uid'],$this->absoluteRootLine[$a]['uid'],'sys_'.$row['uid']);
00419 $this->outermostRootlineIndexWithTemplate=$a;
00420 }
00421 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00422 }
00423 $addC='';
00424 if ($a==($c-1) && $start_template_uid) {
00425 $addC=' AND uid='.intval($start_template_uid);
00426 }
00427
00428 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid='.intval($this->absoluteRootLine[$a]['uid']).$addC.' '.$this->whereClause,'','sorting',1);
00429 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00430 $this->processTemplate($row,'sys_'.$row['uid'],$this->absoluteRootLine[$a]['uid'],'sys_'.$row['uid']);
00431 $this->outermostRootlineIndexWithTemplate=$a;
00432 }
00433 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00434 $this->rootLine[] = $this->absoluteRootLine[$a];
00435 }
00436 }
00437
00450 function processTemplate($row, $idList,$pid,$templateID='',$templateParent='') {
00451
00452 $this->rowSum[]=Array($row['uid'],$row['title'],$row['tstamp']);
00453
00454
00455 if ($row['clear']) {
00456 $clConst = $row['clear']&1;
00457 $clConf = $row['clear']&2;
00458 if ($clConst) {
00459 $this->constants = Array();
00460 $this->clearList_const=array();
00461 }
00462 if ($clConf) {
00463 $this->config = Array();
00464 $this->hierarchyInfoToRoot = Array();
00465 $this->clearList_setup=array();
00466
00467 $this->editorcfg = Array();
00468 $this->clearList_editorcfg=array();
00469 }
00470 }
00471
00472
00473 if (!$row['includeStaticAfterBasedOn']) {
00474 $this->includeStaticTypoScriptSources($idList,$templateID,$pid,$row);
00475 }
00476
00477
00478 if (trim($row['basedOn'])) {
00479
00480
00481
00482 $basedOn_hackFeature = explode('=',$row['basedOn']);
00483 if ($basedOn_hackFeature[0]=='EXTERNAL_BASED_ON_TEMPLATE_ID' && $basedOn_hackFeature[1]) {
00484 $id = intval(t3lib_div::_GET($basedOn_hackFeature[1]));
00485 if ($id && !t3lib_div::inList($idList,'sys_'.$id)) {
00486 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'uid='.$id.' '.$this->whereClause);
00487 if ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00488 $this->processTemplate($subrow,$idList.',sys_'.$id,$pid, 'sys_'.$id,$templateID);
00489 }
00490 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00491 }
00492 } else {
00493 $basedOnArr = t3lib_div::intExplode(',',$row['basedOn']);
00494 while(list(,$id)=each($basedOnArr)) {
00495 if (!t3lib_div::inList($idList,'sys_'.$id)) {
00496 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'uid='.intval($id).' '.$this->whereClause);
00497 if ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00498 $this->processTemplate($subrow,$idList.',sys_'.$id,$pid, 'sys_'.$id,$templateID);
00499 }
00500 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00501 }
00502 }
00503 }
00504 }
00505
00506
00507 if ($row['includeStaticAfterBasedOn']) {
00508 $this->includeStaticTypoScriptSources($idList,$templateID,$pid,$row);
00509 }
00510
00511
00512 $this->hierarchyInfo[] = $this->hierarchyInfoToRoot[] = array(
00513 'root'=>trim($row['root']),
00514 'next'=>$row['nextLevel'],
00515 'clConst'=>$clConst,
00516 'clConf'=>$clConf,
00517 'templateID'=>$templateID,
00518 'templateParent'=>$templateParent,
00519 'title'=>$row['title'],
00520 'uid'=>$row['uid'],
00521 'pid'=>$row['pid'],
00522 'configLines' => substr_count($row['config'], chr(10))+1
00523 );
00524
00525
00526 $this->constants[] = $row['constants'];
00527 $this->config[] = $row['config'];
00528 if ($this->parseEditorCfgField) $this->editorcfg[] = $row['editorcfg'];
00529
00530
00531 $this->clearList_const[]=$templateID;
00532 $this->clearList_setup[]=$templateID;
00533 if ($this->parseEditorCfgField) $this->clearList_editorcfg[]=$templateID;
00534
00535
00536 if (trim($row['resources'])) {
00537 $this->resources = $row['resources'].','.$this->resources;
00538 }
00539 if (trim($row['sitetitle'])) {
00540 $this->sitetitle = $row['sitetitle'];
00541 }
00542
00543 if (trim($row['root'])) {
00544 $this->rootId = $pid;
00545 $this->rootLine = Array();
00546 }
00547
00548 if ($row['nextLevel']) {
00549 $this->nextLevel = $row['nextLevel'];
00550 } else {
00551 $this->nextLevel = 0;
00552 }
00553 }
00554
00565 function includeStaticTypoScriptSources($idList,$templateID,$pid,$row) {
00566
00567 if (trim($row['include_static'])) {
00568 $include_staticArr = t3lib_div::intExplode(',',$row['include_static']);
00569 reset($include_staticArr);
00570 while(list(,$id)=each($include_staticArr)) {
00571 if (!t3lib_div::inList($idList,'static_'.$id)) {
00572 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'static_template', 'uid='.intval($id));
00573 if ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00574 $subrow = $this->prependStaticExtra($subrow);
00575 $this->processTemplate($subrow,$idList.',static_'.$id,$pid,'static_'.$id,$templateID);
00576 }
00577 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00578 }
00579 }
00580 }
00581
00582
00583 if (trim($row['include_static_file'])) {
00584 $include_static_fileArr = t3lib_div::trimExplode(',',$row['include_static_file'],1);
00585 reset($include_static_fileArr);
00586 while(list(,$ISF_file)=each($include_static_fileArr)) {
00587 $ISF_file = trim($ISF_file);
00588 if (substr($ISF_file,0,4)=='EXT:') {
00589 list($ISF_extKey,$ISF_localPath) = explode('/',substr($ISF_file,4),2);
00590 if (strcmp($ISF_extKey,'') && t3lib_extMgm::isLoaded($ISF_extKey) && strcmp($ISF_localPath,'')) {
00591 $ISF_localPath = ereg_replace('\/$','',$ISF_localPath).'/';
00592 $ISF_filePath = t3lib_extMgm::extPath($ISF_extKey).$ISF_localPath;
00593 if (@is_dir($ISF_filePath)) {
00594 $mExtKey = str_replace('_','',$ISF_extKey.'/'.$ISF_localPath);
00595 $subrow=array(
00596 'constants'=> @is_file($ISF_filePath.'constants.txt') ?t3lib_div::getUrl($ISF_filePath.'constants.txt'):'',
00597 'config'=> @is_file($ISF_filePath.'setup.txt') ?t3lib_div::getUrl($ISF_filePath.'setup.txt'):'',
00598 'editorcfg'=> @is_file($ISF_filePath.'editorcfg.txt') ?t3lib_div::getUrl($ISF_filePath.'editorcfg.txt'):'',
00599 'include_static'=> @is_file($ISF_filePath.'include_static.txt')?implode(',',array_unique(t3lib_div::intExplode(',',t3lib_div::getUrl($ISF_filePath.'include_static.txt')))):'',
00600 'title' => $ISF_file,
00601 'uid' => $mExtKey
00602 );
00603 $subrow = $this->prependStaticExtra($subrow);
00604
00605 $this->processTemplate($subrow,$idList.',ext_'.$mExtKey,$pid, 'ext_'.$mExtKey,$templateID);
00606 }
00607 }
00608 }
00609 }
00610 }
00611
00612 $this->addExtensionStatics($idList,$templateID,$pid,$row);
00613 }
00614
00626 function addExtensionStatics($idList,$templateID,$pid,$row) {
00627 global $TYPO3_LOADED_EXT;
00628
00629 if ($row['static_file_mode']==1 || ($row['static_file_mode']==0 && substr($templateID,0,4)=='sys_' && $row['root'])) {
00630 reset($TYPO3_LOADED_EXT);
00631 while(list($extKey,$files)=each($TYPO3_LOADED_EXT)) {
00632 if (is_array($files) && ($files['ext_typoscript_constants.txt'] || $files['ext_typoscript_setup.txt'] || $files['ext_typoscript_editorcfg.txt'])) {
00633 $mExtKey = str_replace('_','',$extKey);
00634 $subrow=array(
00635 'constants'=> $files['ext_typoscript_constants.txt']?t3lib_div::getUrl($files['ext_typoscript_constants.txt']):'',
00636 'config'=> $files['ext_typoscript_setup.txt']?t3lib_div::getUrl($files['ext_typoscript_setup.txt']):'',
00637 'editorcfg'=> $files['ext_typoscript_editorcfg.txt']?t3lib_div::getUrl($files['ext_typoscript_editorcfg.txt']):'',
00638 'title' => $extKey,
00639 'uid' => $mExtKey
00640 );
00641 $subrow = $this->prependStaticExtra($subrow);
00642
00643 $this->processTemplate($subrow,$idList.',ext_'.$mExtKey,$pid, 'ext_'.$mExtKey,$templateID);
00644 }
00645 }
00646 }
00647 }
00648
00659 function prependStaticExtra($subrow) {
00660 $subrow['config'].=$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'][$subrow['uid']];
00661 $subrow['editorcfg'].=$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_editorcfg.'][$subrow['uid']];
00662 $subrow['constants'].=$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants.'][$subrow['uid']];
00663 return $subrow;
00664 }
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00695 function generateConfig() {
00696
00697 array_unshift($this->constants,''.$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants']);
00698 array_unshift($this->config,''.$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup']);
00699 array_unshift($this->editorcfg,''.$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_editorcfg']);
00700
00701
00702 $this->procesIncludes();
00703
00704
00705 $this->setup['resources']= $this->resources;
00706 $this->setup['sitetitle']= $this->sitetitle;
00707
00708
00709
00710
00711
00712
00713
00714
00715 $constants = t3lib_div::makeInstance('t3lib_TSparser');
00716 $constants->breakPointLN=intval($this->ext_constants_BRP);
00717 $constants->setup = $this->const;
00718 $constants->setup = $this->mergeConstantsFromPageTSconfig($constants->setup);
00719 $matchObj = t3lib_div::makeInstance('t3lib_matchCondition');
00720 $matchObj->matchAlternative = $this->matchAlternative;
00721 $matchObj->matchAll = $this->matchAll;
00722
00723
00724 foreach($this->constants as $str) {
00725 $constants->parse($str,$matchObj);
00726 }
00727
00728
00729 $this->parserErrors['constants']=$constants->errors;
00730
00731
00732 $this->flatSetup = Array();
00733 $this->flattenSetup($constants->setup,'','');
00734
00735
00736
00737
00738
00739
00740
00741 $config = t3lib_div::makeInstance('t3lib_TSparser');
00742 $config->breakPointLN = intval($this->ext_config_BRP);
00743 $config->regLinenumbers = $this->ext_regLinenumbers;
00744 $config->setup = $this->setup;
00745
00746
00747 $config->sections = $constants->sections;
00748 $config->sectionsMatch = $constants->sectionsMatch;
00749
00750
00751 $all='';
00752 foreach($this->config as $str) {
00753 $all.="\n[GLOBAL]\n".$str;
00754 }
00755
00756
00757 if ($this->tt_track) $GLOBALS['TT']->push('Substitute Constants ('.count($this->flatSetup).')');
00758 $all = $this->substituteConstants($all);
00759 if ($this->tt_track) $GLOBALS['TT']->pull();
00760
00761
00762 if (strstr($all,'{$')) {
00763 $findConst = explode('{$',$all);
00764 $theConstList=Array();
00765 next($findConst);
00766 while(list(,$constVal)=each($findConst)) {
00767 $constLen=t3lib_div::intInRange(strcspn($constVal,'}'),0,50);
00768 $theConstList[]='{$'.substr($constVal,0,$constLen+1);
00769 }
00770 if ($this->tt_track) $GLOBALS['TT']->setTSlogMessage(implode(',',$theConstList).': Constants may remain un-substituted!!',2);
00771 }
00772
00773
00774 if ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('TypoScript template size as textfile: '.strlen($all).' bytes');
00775
00776
00777 $config->parse($all,$matchObj);
00778
00779
00780 $this->parserErrors['config']=$config->errors;
00781
00782
00783 $this->setup = $config->setup;
00784 if ($this->backend_info) {
00785 $this->setup_constants = $constants->setup;
00786 }
00787
00788
00789
00790
00791
00792
00793
00794 if ($this->parseEditorCfgField) {
00795 $editorcfg = t3lib_div::makeInstance('t3lib_TSparser');
00796 $editorcfg->breakPointLN=intval($this->ext_editorcfg_BRP);
00797 $editorcfg->setup = array();
00798
00799 $all = implode("\n[GLOBAL]\n",$this->editorcfg);
00800
00801
00802 $all = $this->substituteConstants($all);
00803
00804
00805 $matchObj->matchAll=1;
00806 $editorcfg->parse($all,$matchObj);
00807 $this->parserErrors['editorcfg']=$editorcfg->errors;
00808 $this->setup_editorcfg = $editorcfg->setup;
00809 }
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821 unset($this->setup['resources']);
00822 unset($this->setup['resources.']);
00823 $this->setup['resources']= implode(',',t3lib_div::trimExplode(',',$this->resources,1));
00824
00825 unset($this->setup['sitetitle']);
00826 unset($this->setup['sitetitle.']);
00827 $this->setup['sitetitle']= $this->sitetitle;
00828
00829
00830 unset($this->setup['types.']);
00831 unset($this->setup['types']);
00832 if (is_array($this->setup)) {
00833 reset ($this->setup);
00834 while(list($theKey,)=each($this->setup)) {
00835 if ($this->setup[$theKey]=='PAGE') {
00836 $tN = $this->setup[$theKey.'.']['typeNum'];
00837 if (isset($tN)) {
00838 $this->setup['types.'][$tN] = $theKey;
00839 }
00840 }
00841 }
00842 }
00843 unset($this->setup['styles.']);
00844 unset($this->setup['temp.']);
00845 unset($constants);
00846
00847
00848 $this->sections = $config->sections;
00849 $this->sectionsMatch = $config->sectionsMatch;
00850 }
00851
00859 function procesIncludes() {
00860 reset($this->constants);
00861 while(list($k)=each($this->constants)) {
00862 $this->constants[$k]=t3lib_TSparser::checkIncludeLines($this->constants[$k]);
00863 }
00864
00865 reset($this->config);
00866 while(list($k)=each($this->config)) {
00867 $this->config[$k]=t3lib_TSparser::checkIncludeLines($this->config[$k]);
00868 }
00869
00870 reset($this->editorcfg);
00871 while(list($k)=each($this->editorcfg)) {
00872 $this->editorcfg[$k]=t3lib_TSparser::checkIncludeLines($this->editorcfg[$k]);
00873 }
00874 }
00875
00883 function mergeConstantsFromPageTSconfig($constArray) {
00884 $TSdataArray = array();
00885 $TSdataArray[]=$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig'];
00886
00887 for ($a=0;$a<=$this->outermostRootlineIndexWithTemplate;$a++) {
00888 $TSdataArray[]=$this->absoluteRootLine[$a]['TSconfig'];
00889 }
00890
00891 $TSdataArray = t3lib_TSparser::checkIncludeLines_array($TSdataArray);
00892 $userTS = implode(chr(10).'[GLOBAL]'.chr(10),$TSdataArray);
00893
00894 $parseObj = t3lib_div::makeInstance('t3lib_TSparser');
00895 $parseObj->parse($userTS);
00896
00897 if (is_array($parseObj->setup['TSFE.']['constants.'])) {
00898 $constArray = t3lib_div::array_merge_recursive_overrule($constArray,$parseObj->setup['TSFE.']['constants.']);
00899 }
00900 return $constArray;
00901 }
00902
00912 function flattenSetup($setupArray, $prefix, $resourceFlag) {
00913 if (is_array($setupArray)) {
00914 reset($setupArray);
00915 while(list($key,$val)=each($setupArray)) {
00916 if ($prefix || substr($key,0,16)!='TSConstantEditor') {
00917 if (is_array($val)) {
00918 $this->flattenSetup($val,$prefix.$key, ($key=='file.'));
00919 } elseif ($resourceFlag) {
00920 $this->flatSetup[$prefix.$key] = $this->getFileName($val);
00921 } else {
00922 $this->flatSetup[$prefix.$key] = $val;
00923 }
00924 }
00925 }
00926 }
00927 }
00928
00936 function substituteConstants($all) {
00937 if ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('Constants to substitute: '.count($this->flatSetup));
00938 reset($this->flatSetup);
00939 while (list($const,$val)=each($this->flatSetup)) {
00940 if (!is_array($val)) {
00941 $all = str_replace('{$'.$const.'}',$val,$all);
00942 }
00943 }
00944 return $all;
00945 }
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00974 function splitConfArray($conf,$splitCount) {
00975
00976
00977 $splitCount = intval($splitCount);
00978 $conf2 = Array();
00979
00980 if ($splitCount && is_array($conf)) {
00981
00982
00983 for ($aKey=0;$aKey<$splitCount;$aKey++) {
00984 $conf2[$aKey] = array();
00985 }
00986
00987
00988 foreach($conf as $cKey => $val) {
00989 if (is_array($val)) {
00990 $tempConf = $this->splitConfArray($val,$splitCount);
00991 foreach($tempConf as $aKey => $val) {
00992 $conf2[$aKey][$cKey] = $val;
00993 }
00994 }
00995 }
00996
00997
00998 foreach($conf as $cKey => $val) {
00999 if (!is_array($val)) {
01000 if (!strstr($val,'|*|') && !strstr($val,'||')) {
01001 for ($aKey=0;$aKey<$splitCount;$aKey++) {
01002 $conf2[$aKey][$cKey] = $val;
01003 }
01004 } else {
01005 $main = explode ('|*|',$val);
01006 $mainCount = count($main);
01007
01008 $lastC = 0;
01009 $middleC = 0;
01010 $firstC = 0;
01011
01012 if ($main[0]) {
01013 $first = explode('||',$main[0]);
01014 $firstC = count($first);
01015 }
01016 if ($main[1]) {
01017 $middle = explode('||',$main[1]);
01018 $middleC = count($middle);
01019 }
01020 if ($main[2]) {
01021 $last = explode('||',$main[2]);
01022 $lastC = count($last);
01023 $value = $last[0];
01024 }
01025
01026 for ($aKey=0;$aKey<$splitCount;$aKey++) {
01027 if ($firstC && isset($first[$aKey])) {
01028 $value = $first[$aKey];
01029 } elseif ($middleC) {
01030 $value = $middle[($aKey-$firstC)%$middleC];
01031 }
01032 if ($lastC && $lastC>=($splitCount-$aKey)) {
01033 $value = $last[$lastC-($splitCount-$aKey)];
01034 }
01035 $conf2[$aKey][$cKey] = trim($value);
01036 }
01037 }
01038 }
01039 }
01040 }
01041 return $conf2;
01042 }
01043
01051 function getFileName($fileFromSetup) {
01052 $file = trim($fileFromSetup);
01053 if (!$file) return;
01054
01055 $hash = md5($file);
01056 if (isset($this->fileCache[$hash])) {
01057 return $this->fileCache[$hash];
01058 }
01059
01060 if (!strcmp(substr($file,0,4),'EXT:')) {
01061 $newFile='';
01062 list($extKey,$script)=explode('/',substr($file,4),2);
01063 if ($extKey && t3lib_extMgm::isLoaded($extKey)) {
01064 $extPath=t3lib_extMgm::extPath($extKey);
01065 $newFile=substr($extPath,strlen(PATH_site)).$script;
01066 }
01067 if (!@is_file(PATH_site.$newFile)) {
01068 if ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('Extension media file "'.$newFile.'" was not found!',3);
01069 return;
01070 } else $file=$newFile;
01071 }
01072
01073
01074 if (strstr($file,'/')) {
01075 if (@is_file($this->getFileName_backPath.$file)) {
01076 $outFile = $file;
01077 $fileInfo = t3lib_div::split_fileref($outFile);
01078 reset($this->allowedPaths);
01079 $OK=0;
01080 while(list(,$val)=each($this->allowedPaths)) {
01081 if (substr($fileInfo['path'],0,strlen($val))==$val){$OK=1; break;}
01082 }
01083 if ($OK) {
01084 $this->fileCache[$hash]=$outFile;
01085 return $outFile;
01086 } elseif ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('"'.$file.'" was not located in the allowed paths: ('.implode(',',$this->allowedPaths).')',3);
01087 } elseif ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('"'.$this->getFileName_backPath.$file.'" is not a file (non-uploads/.. resource, did not exist).',3);
01088 } else {
01089 $outFile = $this->extractFromResources($this->setup['resources'],$file);
01090 if ($outFile) {
01091 if (@is_file($this->uplPath.$outFile)) {
01092 $this->fileCache[$hash] = $this->uplPath.$outFile;
01093 return $this->uplPath.$outFile;
01094 } elseif ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('"'.$this->uplPath.$outFile.'" is not a file (did not exist).',3);
01095 } elseif ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('"'.$file.'" is not a file (uploads/.. resource).',3);
01096 }
01097 }
01098
01108 function extractFromResources($res,$file) {
01109 if (t3lib_div::inList($res,$file)) {
01110 $outFile = $file;
01111 } elseif (strstr($file,'*')) {
01112 $fileparts=explode('*',$file);
01113 $c=count($fileparts);
01114 $files = explode(',',$res);
01115 while(list(,$val)=each($files)) {
01116 $test = trim($val);
01117 if (ereg('^'.quotemeta($fileparts[0]).'.*'.quotemeta($fileparts[$c-1]).'$', $test)) {
01118 $outFile = $test;
01119 break;
01120 }
01121 }
01122 }
01123 return $outFile;
01124 }
01125
01136 function checkFile($name,$menuArr) {
01137 reset ($menuArr);
01138 while (list($aKey,)=each($menuArr)) {
01139 $menuArr[$aKey][$name] = $this->getFileName($menuArr[$aKey][$name]);
01140 }
01141 return $menuArr;
01142 }
01143
01153 function printTitle($title,$no_title=0,$titleFirst=0) {
01154 $st = trim($this->setup['sitetitle']) ? $this->setup['sitetitle']:'';
01155 $title = $no_title ? '' : $title;
01156 if ($titleFirst) {
01157 $temp=$st;
01158 $st=$title;
01159 $title=$temp;
01160 }
01161 if ($title && $st) {
01162 return $st.': '.$title;
01163 } else {
01164 return $st.$title;
01165 }
01166 }
01167
01176 function fileContent($fName) {
01177 $incFile = $this->getFileName($fName);
01178 if ($incFile && $fd=fopen($incFile,'rb')) {
01179 $content = '';
01180 while (!feof($fd)) {
01181 $content.=fread($fd, 5000);
01182 }
01183 fclose( $fd );
01184 return $content;
01185 }
01186 }
01187
01196 function wrap($content,$wrap) {
01197 if ($wrap) {
01198 $wrapArr = explode('|', $wrap);
01199 return trim($wrapArr[0]).$content.trim($wrapArr[1]);
01200 } else return $content;
01201 }
01202
01210 function removeQueryString($url) {
01211 if (substr($url,-1)=='?') {
01212 return substr($url,0,-1);
01213 } else {
01214 return $url;
01215 }
01216 }
01217
01227 function sortedKeyList($setupArr, $acceptOnlyProperties=FALSE) {
01228 $keyArr = Array();
01229
01230 reset($setupArr);
01231 while(list($key,)=each($setupArr)) {
01232 $ikey = intval($key);
01233 if (!strcmp($ikey,$key) || $acceptOnlyProperties) {
01234 $keyArr[] = $ikey;
01235 }
01236 }
01237
01238 $keyArr = array_unique($keyArr);
01239 sort($keyArr);
01240 return $keyArr;
01241 }
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01274 function linkData($page,$oTarget,$no_cache,$script,$overrideArray='',$addParams='',$typeOverride='') {
01275 global $TYPO3_CONF_VARS;
01276
01277 $LD = Array();
01278
01279
01280 if (is_array($overrideArray)) {
01281 foreach($overrideArray as $theKey => $theNewVal) {
01282 $addParams.= '&real_'.$theKey.'='.rawurlencode($page[$theKey]);
01283 $page[$theKey] = $theNewVal;
01284 }
01285 }
01286
01287
01288 if (!strstr($addParams,'&MP=')) {
01289 if (trim($GLOBALS['TSFE']->MP_defaults[$page['uid']])) {
01290 $addParams.= '&MP='.rawurlencode(trim($GLOBALS['TSFE']->MP_defaults[$page['uid']]));
01291 } elseif ($GLOBALS['TSFE']->config['config']['MP_mapRootPoints']) {
01292 $m = $this->getFromMPmap($page['uid']);
01293 if ($m) {
01294 $addParams.= '&MP='.rawurlencode($m);
01295 }
01296 }
01297 }
01298
01299
01300 if (!$script) {$script = $GLOBALS['TSFE']->config['mainScript'];}
01301 if ($page['alias']) {
01302 $LD['url'] = $script.'?id='.rawurlencode($page['alias']);
01303 } else {
01304 $LD['url'] = $script.'?id='.$page['uid'];
01305 }
01306
01307 $LD['target'] = trim($page['target']) ? trim($page['target']) : $oTarget;
01308
01309
01310 $typeNum = $this->setup[$LD['target'].'.']['typeNum'];
01311 if (!$typeOverride && intval($GLOBALS['TSFE']->config['config']['forceTypeValue'])) {
01312 $typeOverride = intval($GLOBALS['TSFE']->config['config']['forceTypeValue']);
01313 }
01314 if (strcmp($typeOverride,'')) { $typeNum = $typeOverride; }
01315 if ($typeNum) {
01316 $LD['type'] = '&type='.intval($typeNum);
01317 } else {
01318 $LD['type'] = '';
01319 }
01320 $LD['orig_type'] = $LD['type'];
01321
01322
01323 $LD['no_cache'] = (trim($page['no_cache']) || $no_cache) ? '&no_cache=1' : '';
01324
01325
01326 $LD['linkVars'] = $GLOBALS['TSFE']->linkVars.$addParams;
01327
01328
01329 if ($GLOBALS['TSFE']->config['config']['simulateStaticDocuments']) {
01330 $LD['type'] = '';
01331 $LD['url'] = '';
01332
01333
01334 $remainLinkVars='';
01335 $flag_simulateStaticDocuments_pEnc = t3lib_div::inList('md5,base64',$GLOBALS['TSFE']->config['config']['simulateStaticDocuments_pEnc']) && !$LD['no_cache'];
01336 if ($flag_simulateStaticDocuments_pEnc) {
01337 list($LD['linkVars'], $remainLinkVars) = $GLOBALS['TSFE']->simulateStaticDocuments_pEnc_onlyP_proc($LD['linkVars']);
01338 }
01339
01340 $LD['url'].=$GLOBALS['TSFE']->makeSimulFileName(
01341 $page['title'],
01342 $page['alias'] ? $page['alias'] : $page['uid'],
01343 intval($typeNum),
01344 $LD['linkVars'],
01345 $LD['no_cache']?1:0
01346 );
01347
01348 if ($flag_simulateStaticDocuments_pEnc) {
01349 $LD['linkVars']=$remainLinkVars;
01350 }
01351 if ($GLOBALS['TSFE']->config['config']['simulateStaticDocuments']=='PATH_INFO') {
01352 $LD['url'] = str_replace('.','/',$LD['url']);
01353 $LD['url'] = 'index.php/'.$LD['url'].'/?';
01354 } else {
01355 $LD['url'].= '.html?';
01356 }
01357 }
01358
01359
01360 $LD['url'] = $GLOBALS['TSFE']->absRefPrefix.$LD['url'];
01361
01362
01363 $LD['sectionIndex'] = $page['sectionIndex_uid'] ? '#'.$page['sectionIndex_uid'] : '';
01364
01365
01366 $LD['totalURL']= $this->removeQueryString($LD['url'].$LD['type'].$LD['no_cache'].$LD['linkVars'].$GLOBALS['TSFE']->getMethodUrlIdToken).$LD['sectionIndex'];
01367
01368
01369 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['linkData-PostProc'])) {
01370 $_params = array(
01371 'LD' => &$LD,
01372 'args' => array('page'=>$page, 'oTarget'=>$oTarget, 'no_cache'=>$no_cache, 'script'=>$script, 'overrideArray'=>$overrideArray, 'addParams'=>$addParams, 'typeOverride'=>$typeOverride),
01373 'typeNum' => $typeNum
01374 );
01375 foreach($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['linkData-PostProc'] as $_funcRef) {
01376 t3lib_div::callUserFunction($_funcRef,$_params,$this);
01377 }
01378 }
01379
01380
01381 return $LD;
01382 }
01383
01393 function getFromMPmap($pageId=0) {
01394
01395
01396 if (!is_array($this->MPmap)) {
01397 $this->MPmap = array();
01398
01399 $rootPoints = t3lib_div::trimExplode(',', strtolower($GLOBALS['TSFE']->config['config']['MP_mapRootPoints']),1);
01400 foreach($rootPoints as $p) {
01401 if ($p == 'root') {
01402 $p = $this->rootLine[0]['uid'];
01403 $initMParray = array();
01404 if ($this->rootLine[0]['_MOUNT_OL'] && $this->rootLine[0]['_MP_PARAM']) {
01405 $initMParray[] = $this->rootLine[0]['_MP_PARAM'];
01406 }
01407 }
01408 $this->initMPmap_create($p,$initMParray);
01409 }
01410 }
01411
01412
01413 if ($pageId) {
01414 if (is_array($this->MPmap[$pageId]) && count($this->MPmap[$pageId])) {
01415 return implode(',',$this->MPmap[$pageId]);
01416 }
01417 }
01418 }
01419
01429 function initMPmap_create($id,$MP_array=array(),$level=0) {
01430
01431 $id = intval($id);
01432 if($id<=0) return;
01433
01434
01435 if (!$level) {
01436
01437
01438 $mount_info = $GLOBALS['TSFE']->sys_page->getMountPointInfo($id);
01439
01440
01441 if (is_array($mount_info) && $mount_info['overlay']) {
01442 $MP_array[] = $mount_info['MPvar'];
01443 $id = $mount_info['mount_pid'];
01444 }
01445
01446
01447 $this->MPmap[$id] = $MP_array;
01448
01449
01450 if (is_array($mount_info) && !$mount_info['overlay']) {
01451 $MP_array[] = $mount_info['MPvar'];
01452 $id = $mount_info['mount_pid'];
01453 }
01454 }
01455
01456 if ($id && $level<20) {
01457
01458 $nextLevelAcc = array();
01459
01460
01461 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
01462 'uid,pid,doktype,mount_pid,mount_pid_ol',
01463 'pages',
01464 'pid='.intval($id).' AND deleted=0 AND doktype!=255 AND doktype!=6'
01465 );
01466 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
01467
01468
01469 $next_id = $row['uid'];
01470 $next_MP_array = $MP_array;
01471 $mount_info = $GLOBALS['TSFE']->sys_page->getMountPointInfo($next_id, $row);
01472
01473
01474 if (is_array($mount_info) && $mount_info['overlay']) {
01475 $next_MP_array[] = $mount_info['MPvar'];
01476 $next_id = $mount_info['mount_pid'];
01477 }
01478
01479 if (!isset($this->MPmap[$next_id])) {
01480
01481
01482 $this->MPmap[$next_id] = $next_MP_array;
01483
01484
01485 if (is_array($mount_info) && !$mount_info['overlay']) {
01486 $next_MP_array[] = $mount_info['MPvar'];
01487 $next_id = $mount_info['mount_pid'];
01488 }
01489
01490
01491
01492 $nextLevelAcc[] = array($next_id,$next_MP_array);
01493 }
01494 }
01495
01496
01497 foreach($nextLevelAcc as $pSet) {
01498 $this->initMPmap_create($pSet[0],$pSet[1],$level+1);
01499 }
01500 }
01501 }
01502 }
01503
01504
01505 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tstemplate.php']) {
01506 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tstemplate.php']);
01507 }
01508 ?>