tslib/class.tslib_content.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00212   // Includes this class since it is used for parsing HTML
00213 require_once(PATH_t3lib."class.t3lib_parsehtml.php");
00214 
00215         // Object TypoScript library included:
00216 if(t3lib_extMgm::isLoaded('obts')) {
00217         require_once(t3lib_extMgm::extPath('obts').'_tsobject/_tso.php');
00218 }
00219 
00220 
00221 
00222 
00223 
00224 
00225 
00226 
00227 
00228 
00229 
00230 
00231 
00232 
00233 
00234 
00235 
00250 class tslib_cObj {
00251         var $align = Array ('center', 'right', 'left');
00252 
00263         var $image_compression = Array(
00264                 10 => Array('params'=>'', 'ext'=>'gif'),
00265                 11 => Array('params'=>'-colors 128', 'ext'=>'gif'),
00266                 12 => Array('params'=>'-colors 64', 'ext'=>'gif'),
00267                 13 => Array('params'=>'-colors 32', 'ext'=>'gif'),
00268                 14 => Array('params'=>'-colors 16', 'ext'=>'gif'),
00269                 15 => Array('params'=>'-colors 8', 'ext'=>'gif'),
00270 
00271                 30 => Array('params'=>'-colors 256', 'ext'=>'png'),
00272                 31 => Array('params'=>'-colors 128', 'ext'=>'png'),
00273                 32 => Array('params'=>'-colors 64', 'ext'=>'png'),
00274                 33 => Array('params'=>'-colors 32', 'ext'=>'png'),
00275                 34 => Array('params'=>'-colors 16', 'ext'=>'png'),
00276                 35 => Array('params'=>'-colors 8', 'ext'=>'png'),
00277                 39 => Array('params'=>'', 'ext'=>'png'),
00278 
00279                 20 => Array('params'=>'-quality 100', 'ext'=>'jpg'),
00280                 21 => Array('params'=>'-quality 90', 'ext'=>'jpg'),
00281                 22 => Array('params'=>'-quality 80', 'ext'=>'jpg'),
00282                 23 => Array('params'=>'-quality 70', 'ext'=>'jpg'),
00283                 24 => Array('params'=>'-quality 60', 'ext'=>'jpg'),
00284                 25 => Array('params'=>'-quality 50', 'ext'=>'jpg'),
00285                 26 => Array('params'=>'-quality 40', 'ext'=>'jpg'),
00286                 27 => Array('params'=>'-quality 30', 'ext'=>'jpg'),
00287                 28 => Array('params'=>'-quality 20', 'ext'=>'jpg')
00288         );
00289 
00295         var $image_effects = Array(
00296                 1 => '-rotate 90',
00297                 2 => '-rotate 270',
00298                 3 => '-rotate 180',
00299                 10 => '-colorspace GRAY',
00300                 11 => '-sharpen 70',
00301                 20 => '-normalize',
00302                 23 => '-contrast',
00303                 25 => '-gamma 1.3',
00304                 26 => '-gamma 0.8'
00305         );
00306 
00314         var $data = Array();
00315         var $oldData = Array();                         // Used for backup...
00316         var $alternativeData ='';                       // If this is set with an array before stdWrap, it's used instead of $this->data in the data-property in stdWrap
00317         var $parameters = Array();                      // Used by the parseFunc function and is loaded with tag-parameters when parsing tags.
00318         var $currentValKey = 'currentValue_kidjls9dksoje';
00319         var $currentRecord = '';                        // This is set to the [table]:[uid] of the record delivered in the $data-array, if the cObjects CONTENT or RECORD is in operation. Note that $GLOBALS['TSFE']->currentRecord is set to an equal value but always indicating the latest record rendered.
00320         var $currentRecordTotal = 0;            // Set in cObj->RECORDS and cObj->CONTENT to the current number of records selected in a query.
00321         var $currentRecordNumber = 0;           // Incremented in cObj->RECORDS and cObj->CONTENT before each record rendering.
00322         var $parentRecordNumber = 0;            // Incremented in parent cObj->RECORDS and cObj->CONTENT before each record rendering.
00323         var $parentRecord = array();            // If the tslib_cObj was started from CONTENT, RECORD or SEARCHRESULT cObject's this array has two keys, 'data' and 'currentRecord' which indicates the record and data for the parent cObj.
00324         var $regObj;            // This may be set as a reference to the calling object of eg. cObjGetSingle. Anyway, just use it as you like. It's used in productsLib.inc for example.
00325 
00326         // internal
00327         var $INT_include=0;             // Is set to 1 if the instance of this cObj is executed from a PHP_SCRIPT_INT -include script (see pagegen, bottom of document)
00328         var $checkPid_cache = Array();          // This is used by checkPid, that checks if pages are accessible. The $checkPid_cache['page_uid'] is set true or false upon this check featuring a caching function for the next request.
00329         var $checkPid_badDoktypeList = '255';
00330         var $lastTypoLinkUrl='';        // This will be set by typoLink() to the url of the most recent link created.
00331         var $lastTypoLinkTarget='';     // DO. link target.
00332         var $substMarkerCache=array();  // Caching substituteMarkerArrayCached function
00333         var $recordRegister=array();    // Array that registers rendered content elements (or any table) to make sure they are not rendered recursively!
00334 
00344         function start($data,$table='') {
00345                 $this->data = $data;
00346                 $this->currentRecord = $table ? $table.':'.$this->data['uid'] : '';
00347                 $this->parameters = Array();
00348         }
00349 
00359         function setParent($data,$currentRecord)        {
00360                 $this->parentRecord=array('data'=>$data, 'currentRecord'=>$currentRecord);
00361         }
00362 
00363 
00364 
00365 
00366 
00367 
00368 
00369 
00370         /***********************************************
00371          *
00372          * CONTENT_OBJ:
00373          *
00374          ***********************************************/
00375 
00384         function getCurrentVal()        {
00385                 return $this->data[$this->currentValKey];
00386         }
00387 
00395         function setCurrentVal($value)  {
00396                 $this->data[$this->currentValKey] = $value;
00397         }
00398 
00408         function cObjGet($setup,$addKey='')     {
00409                 if (is_array($setup))   {
00410                         $sKeyArray=t3lib_TStemplate::sortedKeyList($setup);
00411                         $content ='';
00412                         foreach($sKeyArray as $theKey)  {
00413                                 $theValue=$setup[$theKey];
00414                                 if (intval($theKey) && !strstr($theKey,'.'))    {
00415                                         $conf=$setup[$theKey.'.'];
00416                                         $content.=$this->cObjGetSingle($theValue,$conf,$addKey.$theKey);        // Get the contentObject
00417                                 }
00418                         }
00419                         return $content;
00420                 }
00421         }
00422 
00432         function cObjGetSingle($name,$conf,$TSkey='__') {
00433                 $content='';
00434                         // Checking that the function is not called eternally. This is done by interrupting at a depth of 100
00435                 $GLOBALS['TSFE']->cObjectDepthCounter--;
00436                 if ($GLOBALS['TSFE']->cObjectDepthCounter>0)    {
00437                         $name = trim($name);
00438                         if ($GLOBALS['TT']->LR) $GLOBALS['TT']->push($TSkey, $name);
00439 
00440                                 // Checking if the COBJ is a reference to another object. (eg. name of 'blabla.blabla = < styles.something')
00441                         if (substr($name,0,1)=='<')     {
00442                                 $key = trim(substr($name,1));
00443                                 $cF = t3lib_div::makeInstance('t3lib_TSparser');
00444                                         // $name and $conf is loaded with the referenced values.
00445                                 $old_conf=$conf;
00446                                 list($name, $conf) = $cF->getVal($key,$GLOBALS['TSFE']->tmpl->setup);
00447                                 if (is_array($old_conf) && count($old_conf))    {
00448                                         $conf = $this->joinTSarrays($conf,$old_conf);
00449 //                                      debug($conf);
00450                                 }
00451                                         // Getting the cObject
00452                                 $GLOBALS['TT']->incStackPointer();
00453                                         $content.=$this->cObjGetSingle($name,$conf,$key);
00454                                 $GLOBALS['TT']->decStackPointer();
00455                         } else {
00456 
00457                                         // Object TypoScript hook:
00458                                 if(t3lib_extMgm::isLoaded('obts') && isset($GLOBALS['OBTS']['tso_list'][$name])) {
00459                                         $content.= obts_dtutil::renderDatatypeContent($name, $GLOBALS['OBTS']['tso_list'][$name], $conf, $this);
00460                                 } else {
00461                                                 // Traditional Content Object branching:
00462                                         switch($name)   {
00463                                                 case 'COBJ_ARRAY':
00464                                                 case 'COA':
00465                                                         $content.=$this->COBJ_ARRAY($conf);
00466                                                 break;
00467                                                 case 'COA_INT':
00468                                                         $content.=$this->COBJ_ARRAY($conf,'INT');
00469                                                 break;
00470                                                 case 'HTML':
00471                                                         $content.=$this->HTML($conf);
00472                                                 break;
00473                                                 case 'TEXT':
00474                                                         $content.=$this->TEXT($conf);
00475                                                 break;
00476                                                 case 'CLEARGIF':
00477                                                         $content.=$this->CLEARGIF($conf);
00478                                                 break;
00479                                                 case 'FILE':
00480                                                         $content.=$this->FILE($conf);
00481                                                 break;
00482                                                 case 'IMAGE':
00483                                                         $content.=$this->IMAGE($conf);
00484                                                 break;
00485                                                 case 'IMG_RESOURCE':
00486                                                         $content.=$this->IMG_RESOURCE($conf);
00487                                                 break;
00488                                                 case 'IMGTEXT':
00489                                                         $content.=$this->IMGTEXT($conf);
00490                                                 break;
00491                                                 case 'CONTENT':
00492                                                         $content.=$this->CONTENT($conf);
00493                                                 break;
00494                                                 case 'RECORDS':
00495                                                         $content.=$this->RECORDS($conf);
00496                                                 break;
00497                                                 case 'HMENU':
00498                                                         $content.=$this->HMENU($conf);
00499                                                 break;
00500                                                 case 'CTABLE':
00501                                                         $content.=$this->CTABLE($conf);
00502                                                 break;
00503                                                 case 'OTABLE':
00504                                                         $content.=$this->OTABLE($conf);
00505                                                 break;
00506                                                 case 'COLUMNS':
00507                                                         $content.=$this->COLUMNS($conf);
00508                                                 break;
00509                                                 case 'HRULER':
00510                                                         $content.=$this->HRULER($conf);
00511                                                 break;
00512                                                 case 'CASE':
00513                                                         $content.=$this->CASEFUNC($conf);
00514                                                 break;
00515                                                 case 'LOAD_REGISTER':
00516                                                 case 'RESTORE_REGISTER':
00517                                                         $this->LOAD_REGISTER($conf,$name);
00518                                                 break;
00519                                                 case 'FORM':
00520                                                         $content.=$this->FORM($conf);
00521                                                 break;
00522                                                 case 'SEARCHRESULT':
00523                                                         $content.=$this->SEARCHRESULT($conf);
00524                                                 break;
00525                                                 case 'PHP_SCRIPT':
00526                                                         $content.=$this->PHP_SCRIPT($conf);
00527                                                 break;
00528                                                 case 'PHP_SCRIPT_EXT':
00529                                                         $content.=$this->PHP_SCRIPT($conf,'EXT');
00530                                                 break;
00531                                                 case 'PHP_SCRIPT_INT':
00532                                                         $content.=$this->PHP_SCRIPT($conf,'INT');
00533                                                 break;
00534                                                 case 'USER':
00535                                                         $content.=$this->USER($conf);
00536                                                 break;
00537                                                 case 'USER_INT':
00538                                                         $content.=$this->USER($conf,'INT');
00539                                                 break;
00540                                                 case 'TEMPLATE':
00541                                                         $content.=$this->TEMPLATE($conf);
00542                                                 break;
00543                                                 case 'EDITPANEL':
00544                                                         if ($GLOBALS['TSFE']->beUserLogin)      {$content.=$this->editPanel($content, $conf);}
00545                                                 break;
00546                                                 case 'MULTIMEDIA':
00547                                                         $content.=$this->MULTIMEDIA($conf);
00548                                                 break;
00549                                         }
00550                                 }
00551                         }
00552                         if ($GLOBALS['TT']->LR) $GLOBALS['TT']->pull($content);
00553                 }
00554                         // Increasing on exit...
00555                 $GLOBALS['TSFE']->cObjectDepthCounter++;
00556                 return $content;
00557         }
00558 
00559 
00560 
00561 
00562 
00563 
00564 
00565         /********************************************
00566          *
00567          * Functions rendering content objects (cObjects)
00568          *
00569          ********************************************/
00570 
00578         function HTML($conf)    {
00579                 return $this->stdWrap($conf['value'],$conf['value.']);
00580         }
00581 
00589         function TEXT($conf)    {
00590                 return $this->stdWrap($conf['value'],$conf);
00591         }
00592 
00600         function CLEARGIF($conf)        {
00601                 $w = $this->stdWrap($conf['width'],$conf['width.']);
00602                 $h = $this->stdWrap($conf['height'],$conf['height.']);
00603                 $w = $w ? $w : 1;
00604                 $h = $h ? $h : 1;
00605                 $wrap = $conf['wrap'] ? $conf['wrap'] : '|<br />';
00606                 $theValue = $this->wrap('<img src="'.$GLOBALS['TSFE']->absRefPrefix.'clear.gif" width="'.$w.'" height="'.$h.'"'.$this->getBorderAttr(' border="0"').' alt="" title="" />', $wrap);
00607 
00608                 return $this->stdWrap($theValue,$conf['stdWrap.']);
00609         }
00610 
00619         function COBJ_ARRAY($conf,$ext='')      {
00620                 $content='';
00621                 switch($ext)    {
00622                         case 'INT':
00623                                 $substKey = $ext.'_SCRIPT.'.$GLOBALS['TSFE']->uniqueHash();
00624                                 $content.='<!--'.$substKey.'-->';
00625                                 $GLOBALS['TSFE']->config[$ext.'incScript'][$substKey] = array(
00626                                         'file'=>$incFile,
00627                                         'conf'=>$conf,
00628                                         'cObj'=>serialize($this),
00629                                         'type'=>'COA'
00630                                 );
00631                         break;
00632                         default:
00633                                 if ($this->checkIf($conf['if.']))       {
00634                                         $content=$this->cObjGet($conf);
00635                                         if ($conf['wrap']) {
00636                                                 $content=$this->wrap($content, $conf['wrap']);
00637                                         }
00638                                         if ($conf['stdWrap.']) {
00639                                                 $content=$this->stdWrap($content, $conf['stdWrap.']);
00640                                         }
00641                                 }
00642                         break;
00643                 }
00644                 return $content;
00645         }
00646 
00655         function USER($conf,$ext='')    {
00656                 $content='';
00657                 switch($ext)    {
00658                         case 'INT':
00659                                 $substKey = $ext.'_SCRIPT.'.$GLOBALS['TSFE']->uniqueHash();
00660                                 $content.='<!--'.$substKey.'-->';
00661                                 $GLOBALS['TSFE']->config[$ext.'incScript'][$substKey] = array(
00662                                         'file' => $incFile,
00663                                         'conf' => $conf,
00664                                         'cObj' => serialize($this),
00665                                         'type' => 'FUNC'
00666                                 );
00667                         break;
00668                         default:
00669                                 $content.=$this->callUserFunction($conf['userFunc'],$conf,'');
00670                         break;
00671                 }
00672                 return $content;
00673         }
00674 
00682         function FILE($conf)    {
00683                 $theValue = $this->fileResource($this->stdWrap($conf['file'],$conf['file.']), trim($this->getAltParam($conf)));
00684                 if ($conf['linkWrap'])  {
00685                         $theValue = $this->linkWrap($theValue,$conf['linkWrap']);
00686                 }
00687                 return $this->wrap($theValue,$conf['wrap']);
00688         }
00689 
00698         function IMAGE($conf)   {
00699                 $content='';
00700                 if ($this->checkIf($conf['if.']))       {
00701                         $theValue = $this->cImage($conf['file'],$conf);
00702                         if ($conf['stdWrap.'])  {
00703                                 $theValue = $this->stdWrap($theValue,$conf['stdWrap.']);
00704                         }
00705                         return $theValue;
00706                 }
00707         }
00708 
00717         function IMG_RESOURCE($conf)    {
00718                 $imgArray = $this->getImgResource($conf['file'],$conf['file.']);
00719                 return $this->stdWrap($imgArray[3],$conf['stdWrap.']);
00720         }
00721 
00729         function IMGTEXT($conf) {
00730                 $content='';
00731                 if (is_array($conf['text.']))   {
00732                         $content.= $this->stdWrap($this->cObjGet($conf['text.'],'text.'),$conf['text.']);       // this gets the surrounding content
00733                 }
00734                 $imgList=trim($this->stdWrap($conf['imgList'],$conf['imgList.']));      // gets images
00735                 if ($imgList)   {
00736                         $imgs = t3lib_div::trimExplode(',',$imgList);
00737                         $imgStart = intval($this->stdWrap($conf['imgStart'],$conf['imgStart.']));
00738 
00739                         $imgCount= count($imgs)-$imgStart;
00740 
00741                         $imgMax = intval($this->stdWrap($conf['imgMax'],$conf['imgMax.']));
00742                         if ($imgMax)    {
00743                                 $imgCount = t3lib_div::intInRange($imgCount,0,$conf['imgMax']); // reduces the number of images.
00744                         }
00745 
00746                         $imgPath = $this->stdWrap($conf['imgPath'],$conf['imgPath.']);
00747 
00748                                 // initialisation
00749                         $caption='';
00750                         if (is_array($conf['caption.']))        {
00751                                 $caption= $this->stdWrap($this->cObjGet($conf['caption.'], 'caption.'),$conf['caption.']);
00752                         }
00753                         $captionArray=array();
00754                         if ($conf['captionSplit'])      {
00755                                 $capSplit = $this->stdWrap($conf['captionSplit.']['token'],$conf['captionSplit.']['token.']);
00756                                 if (!$capSplit) {$capSplit=chr(10);}
00757                                 $caption2= $this->cObjGetSingle($conf['captionSplit.']['cObject'],$conf['captionSplit.']['cObject.'],'captionSplit.cObject');
00758                                 $captionArray=explode($capSplit,$caption2);
00759                                 while(list($ca_key,$ca_val)=each($captionArray))        {
00760                                         $captionArray[$ca_key] = $this->stdWrap(trim($captionArray[$ca_key]), $conf['captionSplit.']['stdWrap.']);
00761                                 }
00762                         }
00763 
00764                         $tablecode='';
00765                         $position=$this->stdWrap($conf['textPos'],$conf['textPos.']);
00766 
00767                         $tmppos = $position&7;
00768                         $contentPosition = $position&24;
00769                         $align = $this->align[$tmppos];
00770                         $cap = ($caption)?1:0;
00771                         $txtMarg = intval($this->stdWrap($conf['textMargin'],$conf['textMargin.']));
00772                         if (!$conf['textMargin_outOfText'] && $contentPosition<16)      {
00773                                 $txtMarg=0;
00774                         }
00775 
00776                         $cols = intval($this->stdWrap($conf['cols'],$conf['cols.']));
00777                         $rows = intval($this->stdWrap($conf['rows'],$conf['rows.']));
00778                         $colspacing = intval($this->stdWrap($conf['colSpace'],$conf['colSpace.']));
00779                         $rowspacing = intval($this->stdWrap($conf['rowSpace'],$conf['rowSpace.']));
00780 
00781                         $border = intval($this->stdWrap($conf['border'],$conf['border.'])) ? 1:0;
00782                         $borderColor = $this->stdWrap($conf['borderCol'],$conf['borderCol.']);
00783                         $borderThickness = intval($this->stdWrap($conf['borderThick'],$conf['borderThick.']));
00784 
00785                         $borderColor=$borderColor?$borderColor:'black';
00786                         $borderThickness=$borderThickness?$borderThickness:1;
00787 
00788                         $caption_align = $this->stdWrap($conf['captionAlign'],$conf['captionAlign.']);
00789                         if (!$caption_align) {
00790                                 $caption_align = $align;
00791                         }
00792                                 // generate cols
00793                         $colCount = ($cols > 1) ? $cols : 1;
00794                         if ($colCount > $imgCount)      {$colCount = $imgCount;}
00795                         $rowCount = ($colCount > 1) ? ceil($imgCount / $colCount) : $imgCount;
00796                                 // generate rows
00797                         if ($rows>1)  {
00798                                 $rowCount = $rows;
00799                                 if ($rowCount > $imgCount)      {$rowCount = $imgCount;}
00800                                 $colCount = ($rowCount>1) ? ceil($imgCount / $rowCount) : $imgCount;
00801                         }
00802 
00803                                 // max Width
00804                         $colRelations = trim($this->stdWrap($conf['colRelations'],$conf['colRelations.']));
00805                         $maxW = intval($this->stdWrap($conf['maxW'],$conf['maxW.']));
00806 
00807                         $maxWInText = intval($this->stdWrap($conf['maxWInText'],$conf['maxWInText.']));
00808                         if (!$maxWInText)       {       // If maxWInText is not set, it's calculated to the 70 % of the max...
00809                                 $maxWInText = round($maxW/100*50);
00810                         }
00811 
00812                         if ($maxWInText && $contentPosition>=16)        {       // inText
00813                                 $maxW = $maxWInText;
00814                         }
00815 
00816                         if ($maxW && $colCount > 0) {   // If there is a max width and if colCount is greater than  column
00817 /*                              debug($border*$borderThickness*2);
00818                                 debug($maxW);
00819                                 debug($colspacing);
00820                                 debug(($maxW-$colspacing*($colCount-1)-$colCount*$border*$borderThickness*2));
00821                                 */
00822                                 $maxW = ceil(($maxW-$colspacing*($colCount-1)-$colCount*$border*$borderThickness*2)/$colCount);
00823                         }
00824                                 // create the relation between rows
00825                         $colMaxW = Array();
00826                         if ($colRelations)      {
00827                                 $rel_parts = explode(':',$colRelations);
00828                                 $rel_total = 0;
00829                                 for ($a=0;$a<$colCount;$a++)    {
00830                                         $rel_parts[$a] = intval($rel_parts[$a]);
00831                                         $rel_total+= $rel_parts[$a];
00832                                 }
00833                                 if ($rel_total) {
00834                                         for ($a=0;$a<$colCount;$a++)    {
00835                                                 $colMaxW[$a] = round(($maxW*$colCount)/$rel_total*$rel_parts[$a]);
00836                                         }
00837                                         if (min($colMaxW)<=0 || max($rel_parts)/min($rel_parts)>10)     {               // The difference in size between the largest and smalles must be within a factor of ten.
00838                                                 $colMaxW = Array();
00839                                         }
00840                                 }
00841                         }
00842                         $image_compression = intval($this->stdWrap($conf['image_compression'],$conf['image_compression.']));
00843                         $image_effects = intval($this->stdWrap($conf['image_effects'],$conf['image_effects.']));
00844                         $image_frames = intval($this->stdWrap($conf['image_frames.']['key'],$conf['image_frames.']['key.']));
00845 
00846                                 // fetches pictures
00847                         $splitArr=array();
00848                         $splitArr['imgObjNum']=$conf['imgObjNum'];
00849                         $splitArr = $GLOBALS['TSFE']->tmpl->splitConfArray($splitArr,$imgCount);
00850 
00851                                 // EqualHeight
00852                         $equalHeight = intval($this->stdWrap($conf['equalH'],$conf['equalH.']));
00853                         if ($equalHeight)       {       // Initiate gifbuilder object in order to get dimensions AND calculate the imageWidth's
00854                                 $gifCreator = t3lib_div::makeInstance('tslib_gifbuilder');
00855                                 $gifCreator->init();
00856                                 $relations = Array();
00857                                 $relations_cols = Array();
00858                                 $totalMaxW = $maxW*$colCount;
00859                                 for($a=0;$a<$imgCount;$a++)     {
00860                                         $imgKey = $a+$imgStart;
00861                                         $imgInfo = $gifCreator->getImageDimensions($imgPath.$imgs[$imgKey]);
00862                                         $relations[$a] = $imgInfo[1] / $equalHeight;    // relationship between the original height and the wished height
00863                                         if ($relations[$a])     {       // if relations is zero, then the addition of this value is omitted as the image is not expected to display because of some error.
00864                                                 $relations_cols[floor($a/$colCount)] += $imgInfo[0]/$relations[$a];     // counts the total width of the row with the new height taken into consideration.
00865                                         }
00866                                 }
00867                         }
00868 
00869                         $imageRowsFinalWidths = Array();        // contains the width of every image row
00870                         $imageRowsMaxHeights = Array();
00871                         $imgsTag=array();
00872                         $origImages=array();
00873                         for($a=0;$a<$imgCount;$a++)     {
00874                                 $GLOBALS['TSFE']->register['IMAGE_NUM'] = $a;
00875 
00876                                 $imgKey = $a+$imgStart;
00877                                 $totalImagePath = $imgPath.$imgs[$imgKey];
00878                                 $this->data[$this->currentValKey] = $totalImagePath;
00879                                 $imgObjNum = intval($splitArr[$a]['imgObjNum']);
00880                                 $imgConf = $conf[$imgObjNum.'.'];
00881 
00882                                 if ($equalHeight)       {
00883                                         $scale = 1;
00884                                         if ($totalMaxW) {
00885                                                 $rowTotalMaxW = $relations_cols[floor($a/$colCount)];
00886                                                 if ($rowTotalMaxW > $totalMaxW) {
00887                                                         $scale = $rowTotalMaxW / $totalMaxW;
00888                                                 }
00889                                         }
00890                                                 // transfer info to the imageObject. Please note, that
00891                                         $imgConf['file.']['height'] = round($equalHeight/$scale);
00892 
00893                                         unset($imgConf['file.']['width']);
00894                                         unset($imgConf['file.']['maxW']);
00895                                         unset($imgConf['file.']['maxH']);
00896                                         unset($imgConf['file.']['minW']);
00897                                         unset($imgConf['file.']['minH']);
00898                                         unset($imgConf['file.']['width.']);
00899                                         unset($imgConf['file.']['maxW.']);
00900                                         unset($imgConf['file.']['maxH.']);
00901                                         unset($imgConf['file.']['minW.']);
00902                                         unset($imgConf['file.']['minH.']);
00903                                         $maxW = 0;      // setting this to zero, so that it doesn't disturb
00904                                 }
00905 
00906                                 if ($maxW) {
00907                                         if (count($colMaxW))    {
00908                                                 $imgConf['file.']['maxW'] = $colMaxW[($a%$colCount)];
00909                                         } else {
00910                                                 $imgConf['file.']['maxW'] = $maxW;
00911                                         }
00912                                 }
00913 
00914                                         // Image Object supplied:
00915                                 if (is_array($imgConf)) {
00916                                         if ($this->image_effects[$image_effects])       {
00917                                                 $imgConf['file.']['params'].= ' '.$this->image_effects[$image_effects];
00918                                         }
00919                                         if ($image_frames)      {
00920                                                 if (is_array($conf['image_frames.'][$image_frames.'.']))        {
00921                                                         $imgConf['file.']['m.'] = $conf['image_frames.'][$image_frames.'.'];
00922                                                 }
00923                                         }
00924                                         if ($image_compression && $imgConf['file']!='GIFBUILDER')       {
00925                                                 if ($image_compression==1)      {
00926                                                         $tempImport = $imgConf['file.']['import'];
00927                                                         $tempImport_dot = $imgConf['file.']['import.'];
00928                                                         unset($imgConf['file.']);
00929                                                         $imgConf['file.']['import'] = $tempImport;
00930                                                         $imgConf['file.']['import.'] = $tempImport_dot;
00931                                                 } elseif (isset($this->image_compression[$image_compression])) {
00932                                                         $imgConf['file.']['params'].= ' '.$this->image_compression[$image_compression]['params'];
00933                                                         $imgConf['file.']['ext'] = $this->image_compression[$image_compression]['ext'];
00934                                                         unset($imgConf['file.']['ext.']);
00935                                                 }
00936                                         }
00937 
00938                                                 // "alt", "title" and "longdesc" attributes:
00939                                         if (!strlen($imgConf['altText']) && !is_array($imgConf['altText.'])) {
00940                                                 $imgConf['altText'] = $conf['altText'];
00941                                                 $imgConf['altText.'] = $conf['altText.'];
00942                                         }
00943                                         if (!strlen($imgConf['titleText']) && !is_array($imgConf['titleText.'])) {
00944                                                 $imgConf['titleText'] = $conf['titleText'];
00945                                                 $imgConf['titleText.'] = $conf['titleText.'];
00946                                         }
00947                                         if (!strlen($imgConf['longdescURL']) && !is_array($imgConf['longdescURL.'])) {
00948                                                 $imgConf['longdescURL'] = $conf['longdescURL'];
00949                                                 $imgConf['longdescURL.'] = $conf['longdescURL.'];
00950                                         }
00951                                 } else {
00952                                         $imgConf = array(
00953                                                 'altText' => $conf['altText'],
00954                                                 'titleText' => $conf['titleText'],
00955                                                 'longdescURL' => $conf['longdescURL'],
00956                                                 'file' => $totalImagePath
00957                                         );
00958                                 }
00959 
00960                                 $imgsTag[$imgKey] = $this->IMAGE($imgConf);
00961 
00962                                         // Store the original filepath
00963                                 $origImages[$imgKey]=$GLOBALS['TSFE']->lastImageInfo;
00964 
00965                                 $imageRowsFinalWidths[floor($a/$colCount)] += $GLOBALS['TSFE']->lastImageInfo[0];
00966                                 if ($GLOBALS['TSFE']->lastImageInfo[1]>$imageRowsMaxHeights[floor($a/$colCount)])       {
00967                                         $imageRowsMaxHeights[floor($a/$colCount)] = $GLOBALS['TSFE']->lastImageInfo[1];
00968                                 }
00969                         }
00970                                 // calculating the tableWidth:
00971                                 // TableWidth problems: It creates problems if the pictures are NOT as wide as the tableWidth.
00972                         $tableWidth = max($imageRowsFinalWidths)+ $colspacing*($colCount-1) + $colCount*$border*$borderThickness*2;
00973 
00974                                 // make table for pictures
00975                         $index=$imgStart;
00976 
00977                         $noRows = $this->stdWrap($conf['noRows'],$conf['noRows.']);
00978                         $noCols = $this->stdWrap($conf['noCols'],$conf['noCols.']);
00979                         if ($noRows) {$noCols=0;}       // noRows overrides noCols. They cannot exist at the same time.
00980                         if ($equalHeight) {
00981                                 $noCols=1;
00982                                 $noRows=0;
00983                         }
00984 
00985                         $rowCount_temp=1;
00986                         $colCount_temp=$colCount;
00987                         if ($noRows)    {
00988                                 $rowCount_temp = $rowCount;
00989                                 $rowCount=1;
00990                         }
00991                         if ($noCols)    {
00992                                 $colCount=1;
00993                         }
00994                                 // col- and rowspans calculated
00995                         $colspan = (($colspacing) ? $colCount*2-1 : $colCount);
00996                         $rowspan = (($rowspacing) ? $rowCount*2-1 : $rowCount) + $cap;
00997 
00998 
00999                                 // Edit icons:
01000                         $editIconsHTML = $conf['editIcons']&&$GLOBALS['TSFE']->beUserLogin ? $this->editIcons('',$conf['editIcons'],$conf['editIcons.']) : '';
01001 
01002                                 // strech out table:
01003                         $tablecode='';
01004                         $flag=0;
01005                         if ($conf['noStretchAndMarginCells']!=1)        {
01006                                 $tablecode.='<tr>';
01007                                 if ($txtMarg && $align=='right')        {       // If right aligned, the textborder is added on the right side
01008                                         $tablecode.='<td rowspan="'.($rowspan+1).'" valign="top"><img src="'.$GLOBALS['TSFE']->absRefPrefix.'clear.gif" width="'.$txtMarg.'" height="1" alt="" title="" />'.($editIconsHTML?'<br />'.$editIconsHTML:'').'</td>';
01009                                         $editIconsHTML='';
01010                                         $flag=1;
01011                                 }
01012                                 $tablecode.='<td colspan="'.$colspan.'"><img src="'.$GLOBALS['TSFE']->absRefPrefix.'clear.gif" width="'.$tableWidth.'" height="1" alt="" /></td>';
01013                                 if ($txtMarg && $align=='left') {       // If left aligned, the textborder is added on the left side
01014                                         $tablecode.='<td rowspan="'.($rowspan+1).'" valign="top"><img src="'.$GLOBALS['TSFE']->absRefPrefix.'clear.gif" width="'.$txtMarg.'" height="1" alt="" title="" />'.($editIconsHTML?'<br />'.$editIconsHTML:'').'</td>';
01015                                         $editIconsHTML='';
01016                                         $flag=1;
01017                                 }
01018                                 if ($flag) $tableWidth+=$txtMarg+1;
01019         //                      $tableWidth=0;
01020                                 $tablecode.='</tr>';
01021                         }
01022 
01023                                 // draw table
01024                         for ($c=0;$c<$rowCount;$c++) {  // Looping through rows. If 'noRows' is set, this is '1 time', but $rowCount_temp will hold the actual number of rows!
01025                                 if ($c && $rowspacing)  {               // If this is NOT the first time in the loop AND if space is required, a row-spacer is added. In case of "noRows" rowspacing is done further down.
01026                                         $tablecode.='<tr><td colspan="'.$colspan.'"><img src="'.$GLOBALS['TSFE']->absRefPrefix.'clear.gif" width="1" height="'.$rowspacing.'"'.$this->getBorderAttr(' border="0"').' alt="" title="" /></td></tr>';
01027                                 }
01028                                 $tablecode.='<tr>';     // starting row
01029                                 for ($b=0; $b<$colCount_temp; $b++)     {       // Looping through the columns
01030                                         if ($b && $colspacing)  {               // If this is NOT the first iteration AND if column space is required. In case of "noCols", the space is done without a separate cell.
01031                                                 if (!$noCols)   {
01032                                                         $tablecode.='<td><img src="'.$GLOBALS['TSFE']->absRefPrefix.'clear.gif" width="'.$colspacing.'" height="1"'.$this->getBorderAttr(' border="0"').' alt="" title="" /></td>';
01033                                                 } else {
01034                                                         $colSpacer='<img src="'.$GLOBALS['TSFE']->absRefPrefix.'clear.gif" width="'.($border?$colspacing-6:$colspacing).'" height="'.($imageRowsMaxHeights[$c]+($border?$borderThickness*2:0)).'"'.$this->getBorderAttr(' border="0"').' align="'.($border?'left':'top').'" alt="" title="" />';
01035                                                         $colSpacer='<td valign="top">'.$colSpacer.'</td>';      // added 160301, needed for the new "noCols"-table...
01036                                                         $tablecode.=$colSpacer;
01037                                                 }
01038                                         }
01039                                         if (!$noCols || ($noCols && !$b))       {
01040                                                 $tablecode.='<td valign="top">';        // starting the cell. If "noCols" this cell will hold all images in the row, otherwise only a single image.
01041                                                 if ($noCols)    {$tablecode.='<table width="'.$imageRowsFinalWidths[$c].'" border="0" cellpadding="0" cellspacing="0"><tr>';}           // In case of "noCols" we must set the table-tag that surrounds the images in the row.
01042                                         }
01043                                         for ($a=0;$a<$rowCount_temp;$a++)       {       // Looping through the rows IF "noRows" is set. "noRows"  means that the rows of images is not rendered by physical table rows but images are all in one column and spaced apart with clear-gifs. This loop is only one time if "noRows" is not set.
01044                                                 $imgIndex = $index+$a*$colCount_temp;
01045                                                 if ($imgsTag[$imgIndex])        {
01046                                                         if ($rowspacing && $noRows && $a) {             // Puts distance between the images IF "noRows" is set and this is the first iteration of the loop
01047                                                                 $tablecode.= '<img src="'.$GLOBALS['TSFE']->absRefPrefix.'clear.gif" width="1" height="'.$rowspacing.'" alt="" title="" /><br />';
01048                                                         }
01049 
01050                                                         $imageHTML = $imgsTag[$imgIndex].'<br />';
01051                                                         $Talign = (!trim($captionArray[$imgIndex]) && !$noRows && !$conf['netprintApplicationLink']) ? ' align="left"' : '';  // this is necessary if the tablerows are supposed to space properly together! "noRows" is excluded because else the images "layer" together.
01052                                                         if ($border)    {$imageHTML='<table border="0" cellpadding="'.$borderThickness.'" cellspacing="0" bgcolor="'.$borderColor.'"'.$Talign.'><tr><td>'.$imageHTML.'</td></tr></table>';}             // break-tag added 160301  , ($noRows?'':' align="left"')  removed 160301, break tag removed 160301 (later...)
01053                                                         $imageHTML.=$editIconsHTML;             $editIconsHTML='';
01054                                                         if ($conf['netprintApplicationLink'])   {$imageHTML = $this->netprintApplication_offsiteLinkWrap($imageHTML,$origImages[$imgIndex],$conf['netprintApplicationLink.']);}
01055                                                         $imageHTML.=$captionArray[$imgIndex];   // Adds caption.
01056                                                         if ($noCols)    {$imageHTML='<td valign="top">'.$imageHTML.'</td>';}            // If noCols, put in table cell.
01057                                                         $tablecode.=$imageHTML;
01058                                                 }
01059                                         }
01060                                         $index++;
01061                                         if (!$noCols || ($noCols && $b+1==$colCount_temp))      {
01062                                                 if ($noCols)    {$tablecode.='</tr></table>';}  // In case of "noCols" we must finish the table that surrounds the images in the row.
01063                                                 $tablecode.='</td>';    // Ending the cell. In case of "noCols" the cell holds all pictures!
01064                                         }
01065                                 }
01066                                 $tablecode.='</tr>';    // ending row
01067                         }
01068                         if ($c) {
01069                                 // Table-tag is inserted
01070                                 $i=$contentPosition;
01071                                 $table_align = (($i==16) ? 'align="'.$align.'"' : '');
01072                                 $tablecode = '<table'.($tableWidth?' width="'.$tableWidth.'"':'').' border="0" cellspacing="0" cellpadding="0" '.$table_align.' class="imgtext-table">'.$tablecode;
01073                                 if ($editIconsHTML)     {       // IF this value is not long since reset.
01074                                         $tablecode.='<tr><td colspan="'.$colspan.'">'.$editIconsHTML.'</td></tr>';
01075                                         $editIconsHTML='';
01076                                 }
01077                                 if ($cap)       {
01078                                         $tablecode.='<tr><td colspan="'.$colspan.'" align="'.$caption_align.'">'.$caption.'</td></tr>';
01079                                 }
01080                                 $tablecode.='</table>';
01081                                 if ($conf['tableStdWrap.'])     {$tablecode=$this->stdWrap($tablecode,$conf['tableStdWrap.']);}
01082                         }
01083 
01084                         $spaceBelowAbove = intval($this->stdWrap($conf['spaceBelowAbove'],$conf['spaceBelowAbove.']));
01085                         switch ($contentPosition)       {
01086                                 case '0':       // above
01087                                         $output= '<div style="text-align:'.$align.';">'.$tablecode.'</div>'.$this->wrapSpace($content, $spaceBelowAbove.'|0');
01088                                 break;
01089                                 case '8':       // below
01090                                         $output= $this->wrapSpace($content, '0|'.$spaceBelowAbove).'<div style="text-align:'.$align.';">'.$tablecode.'</div>';
01091                                 break;
01092                                 case '16':      // in text
01093                                         $output= $tablecode.$content;
01094                                 break;
01095                                 case '24':      // in text, no wrap
01096                                         $theResult = '';
01097                                         $theResult.= '<table border="0" cellspacing="0" cellpadding="0" class="imgtext-nowrap"><tr>';
01098                                         if ($align=='right')    {
01099                                                 $theResult.= '<td valign="top">'.$content.'</td><td valign="top">'.$tablecode.'</td>';
01100                                         } else {
01101                                                 $theResult.= '<td valign="top">'.$tablecode.'</td><td valign="top">'.$content.'</td>';
01102                                         }
01103                                         $theResult.= '</tr></table>';
01104                                         $output= $theResult;
01105                                 break;
01106                         }
01107                 } else {
01108                         $output= $content;
01109                 }
01110 
01111                 if ($conf['stdWrap.']) {
01112                         $output = $this->stdWrap($output, $conf['stdWrap.']);
01113                 }
01114 
01115                 return $output;
01116         }
01117 
01125         function CONTENT($conf) {
01126                 $theValue='';
01127 
01128                 $originalRec = $GLOBALS['TSFE']->currentRecord;
01129                 if ($originalRec)       {               // If the currentRecord is set, we register, that this record has invoked this function. It's should not be allowed to do this again then!!
01130                         $GLOBALS['TSFE']->recordRegister[$originalRec]++;
01131                 }
01132 
01133                 if ($conf['table']=='pages' || substr($conf['table'],0,3)=='tt_' || substr($conf['table'],0,3)=='fe_' || substr($conf['table'],0,3)=='tx_' || substr($conf['table'],0,4)=='ttx_' || substr($conf['table'],0,5)=='user_')        {
01134 
01135                         $renderObjName = $conf['renderObj'] ? $conf['renderObj'] : '<'.$conf['table'];
01136                         $renderObjKey = $conf['renderObj'] ? 'renderObj' : '';
01137                         $renderObjConf = $conf['renderObj.'];
01138 
01139                         $res = $this->exec_getQuery($conf['table'],$conf['select.']);
01140                         if ($error = $GLOBALS['TYPO3_DB']->sql_error()) {
01141                                 $GLOBALS['TT']->setTSlogMessage($error,3);
01142                         } else {
01143                                 $this->currentRecordTotal = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
01144                                 $GLOBALS['TT']->setTSlogMessage('NUMROWS: '.$GLOBALS['TYPO3_DB']->sql_num_rows($res));
01145                                 $cObj =t3lib_div::makeInstance('tslib_cObj');
01146                                 $cObj->setParent($this->data,$this->currentRecord);
01147                                 $this->currentRecordNumber=0;
01148                                 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))      {
01149 
01150                                                 // Versioning preview:
01151                                         $GLOBALS['TSFE']->sys_page->versionOL($conf['table'],$row);
01152 
01153                                                 // Language Overlay:
01154                                         if ($GLOBALS['TSFE']->sys_language_contentOL)   {
01155                                                 $row = $GLOBALS['TSFE']->sys_page->getRecordOverlay($conf['table'],$row,$GLOBALS['TSFE']->sys_language_content,$GLOBALS['TSFE']->sys_language_contentOL);
01156                                         }
01157 
01158                                         if (is_array($row))     {       // Might be unset in the sys_language_contentOL
01159                                                 if (!$GLOBALS['TSFE']->recordRegister[$conf['table'].':'.$row['uid']])  {
01160                                                         $this->currentRecordNumber++;
01161                                                         $cObj->parentRecordNumber = $this->currentRecordNumber;
01162                                                         $GLOBALS['TSFE']->currentRecord = $conf['table'].':'.$row['uid'];
01163                                                         $this->lastChanged($row['tstamp']);
01164                                                         $cObj->start($row,$conf['table']);
01165                                                         if ($GLOBALS['TSFE']->config['config']['insertDmailerBoundaries'])      { $theValue.='<!--DMAILER_SECTION_BOUNDARY_'.intval($row['module_sys_dmail_category']).'-->'; }
01166                                                         $theValue.= $cObj->cObjGetSingle($renderObjName, $renderObjConf, $renderObjKey);
01167                                                 }# else debug($GLOBALS['TSFE']->recordRegister,'CONTENT');
01168                                         }
01169                                 }
01170                                 if ($GLOBALS['TSFE']->config['config']['insertDmailerBoundaries'])      { $theValue.='<!--DMAILER_SECTION_BOUNDARY_END-->'; }
01171                         }
01172                 }
01173 
01174                 $theValue = $this->wrap($theValue,$conf['wrap']);
01175                 if ($conf['stdWrap.']) $theValue = $this->stdWrap($theValue,$conf['stdWrap.']);
01176 
01177                 $GLOBALS['TSFE']->currentRecord = $originalRec; // Restore
01178                 return $theValue;
01179         }
01180 
01188         function RECORDS($conf) {
01189                 $theValue='';
01190 
01191                 $originalRec = $GLOBALS['TSFE']->currentRecord;
01192                 if ($originalRec)       {               // If the currentRecord is set, we register, that this record has invoked this function. It's should not be allowed to do this again then!!
01193                         $GLOBALS['TSFE']->recordRegister[$originalRec]++;
01194                 }
01195 
01196                 $conf['source'] = $this->stdWrap($conf['source'],$conf['source.']);
01197                 if ($conf['tables'] && $conf['source']) {
01198                         $allowedTables = $conf['tables'];
01199                         if (is_array($conf['conf.']))   {
01200                                 reset($conf['conf.']);
01201                                 while(list($k)=each($conf['conf.']))    {
01202                                         if (substr($k,-1)!='.')         $allowedTables.=','.$k;
01203                                 }
01204                         }
01205 
01206                         $loadDB = t3lib_div::makeInstance('FE_loadDBGroup');
01207                         $loadDB->start($conf['source'], $allowedTables);
01208                         reset($loadDB->tableArray);
01209                         while(list($table,)=each($loadDB->tableArray))  {
01210                                 if (is_array($GLOBALS['TCA'][$table]))  {
01211                                         $loadDB->additionalWhere[$table]=$this->enableFields($table);
01212                                 }
01213                         }
01214                         $loadDB->getFromDB();
01215 
01216                         reset($loadDB->itemArray);
01217                         $data = $loadDB->results;
01218 
01219                         $cObj =t3lib_div::makeInstance('tslib_cObj');
01220                         $cObj->setParent($this->data,$this->currentRecord);
01221                         $this->currentRecordNumber=0;
01222                         $this->currentRecordTotal = count($loadDB->itemArray);
01223                         reset($loadDB->itemArray);
01224                         while(list(,$val)=each($loadDB->itemArray))     {
01225                                 $row = $data[$val['table']][$val['id']];
01226 
01227                                         // Versioning preview:
01228                                 $GLOBALS['TSFE']->sys_page->versionOL($val['table'],$row);
01229 
01230                                         // Language Overlay:
01231                                 if ($GLOBALS['TSFE']->sys_language_contentOL)   {
01232                                         $row = $GLOBALS['TSFE']->sys_page->getRecordOverlay($val['table'],$row,$GLOBALS['TSFE']->sys_language_content,$GLOBALS['TSFE']->sys_language_contentOL);
01233                                 }
01234 
01235                                 if (is_array($row))     {       // Might be unset in the content overlay things...
01236                                         if (!$conf['dontCheckPid'])     {
01237                                                 $row = $this->checkPid($row['pid']) ? $row : '';
01238                                         }
01239                                         if ($row && !$GLOBALS['TSFE']->recordRegister[$val['table'].':'.$val['id']])    {
01240                                                 $renderObjName = $conf['conf.'][$val['table']] ? $conf['conf.'][$val['table']] : '<'.$val['table'];
01241                                                 $renderObjKey = $conf['conf.'][$val['table']] ? 'conf.'.$val['table'] : '';
01242                                                 $renderObjConf = $conf['conf.'][$val['table'].'.'];
01243                                                 $this->currentRecordNumber++;
01244                                                 $cObj->parentRecordNumber=$this->currentRecordNumber;
01245                                                 $GLOBALS['TSFE']->currentRecord = $val['table'].':'.$val['id'];
01246                                                 $this->lastChanged($row['tstamp']);
01247                                                 $cObj->start($row,$val['table']);
01248                                                 if ($GLOBALS['TSFE']->config['config']['insertDmailerBoundaries'])      {$theValue.='<!--DMAILER_SECTION_BOUNDARY_'.intval($row['module_sys_dmail_category']).'-->';}
01249                                                 $theValue.=$cObj->cObjGetSingle($renderObjName, $renderObjConf, $renderObjKey);
01250                                                 if ($GLOBALS['TSFE']->config['config']['insertDmailerBoundaries'])      {$theValue.='<!--DMAILER_SECTION_BOUNDARY_END-->';}
01251                                         }# else debug($GLOBALS['TSFE']->recordRegister,'RECORDS');
01252                                 }
01253                         }
01254                 }
01255                 $GLOBALS['TSFE']->currentRecord = $originalRec; // Restore
01256                 return $this->wrap($theValue,$conf['wrap']);
01257         }
01258 
01266         function HMENU($conf)   {
01267                 $content='';
01268                 if ($this->checkIf($conf['if.']))       {
01269                         $cls = strtolower($conf[1]);
01270                         if (t3lib_div::inList($GLOBALS['TSFE']->tmpl->menuclasses,$cls))        {
01271                                 if ($conf['special.']['value.'])        {
01272                                         $conf['special.']['value']  = $this->stdWrap($conf['special.']['value'], $conf['special.']['value.']);
01273                                 }
01274                                 $GLOBALS['TSFE']->register['count_HMENU']++;
01275                                 $GLOBALS['TSFE']->register['count_HMENU_MENUOBJ']=0;
01276                                 $GLOBALS['TSFE']->applicationData['GMENU_LAYERS']['WMid']=array();
01277                                 $GLOBALS['TSFE']->applicationData['GMENU_LAYERS']['WMparentId']=array();
01278 
01279                                 $menu = t3lib_div::makeInstance('tslib_'.$cls);
01280                                 $menu->parent_cObj = $this;
01281                                 $menu->start($GLOBALS['TSFE']->tmpl, $GLOBALS['TSFE']->sys_page, '', $conf, 1);
01282                                 $menu->makeMenu();
01283                                 $content.=$menu->writeMenu();
01284                         }
01285                         if ($conf['wrap'])              $content=$this->wrap($content, $conf['wrap']);
01286                         if ($conf['stdWrap.'])  $content = $this->stdWrap($content, $conf['stdWrap.']);
01287                 }
01288                 return $content;
01289         }
01290 
01298         function CTABLE ($conf) {
01299                 $controlTable = t3lib_div::makeInstance('tslib_controlTable');
01300                         if ($conf['tableParams'])       {
01301                         $controlTable->tableParams = $conf['tableParams'];
01302                 }
01303                         // loads the pagecontent
01304                 $controlTable->contentW = $conf['cWidth'];
01305                         // loads the menues if any
01306                 if (is_array($conf['c.']))      {
01307                         $controlTable->content = $this->cObjGet($conf['c.'],'c.');
01308                         $controlTable->contentTDparams = isset($conf['c.']['TDParams']) ? $conf['c.']['TDParams'] : 'valign="top"';
01309                 }
01310                 if (is_array($conf['lm.']))     {
01311                         $controlTable->lm = $this->cObjGet($conf['lm.'],'lm.');
01312                         $controlTable->lmTDparams = isset($conf['lm.']['TDParams']) ? $conf['lm.']['TDParams'] : 'valign="top"';
01313                 }
01314                 if (is_array($conf['tm.']))     {
01315                         $controlTable->tm = $this->cObjGet($conf['tm.'],'tm.');
01316                         $controlTable->tmTDparams = isset($conf['tm.']['TDParams']) ? $conf['tm.']['TDParams'] : 'valign="top"';
01317                 }
01318                 if (is_array($conf['rm.']))     {
01319                         $controlTable->rm = $this->cObjGet($conf['rm.'],'rm.');
01320                         $controlTable->rmTDparams = isset($conf['rm.']['TDParams']) ? $conf['rm.']['TDParams'] : 'valign="top"';
01321                 }
01322                 if (is_array($conf['bm.']))     {
01323                         $controlTable->bm = $this->cObjGet($conf['bm.'],'bm.');
01324                         $controlTable->bmTDparams = isset($conf['bm.']['TDParams']) ? $conf['bm.']['TDParams'] : 'valign="top"';
01325                 }
01326                 return $controlTable->start($conf['offset'],$conf['cMargins']);
01327         }
01328 
01336         function OTABLE ($conf) {
01337                 $controlTable = t3lib_div::makeInstance('tslib_tableOffset');
01338                 if ($conf['tableParams'])       {
01339                         $controlTable->tableParams = $conf['tableParams'];
01340                 }
01341                 return $controlTable->start($this->cObjGet($conf),$conf['offset']);
01342         }
01343 
01351         function COLUMNS ($conf)        {
01352                 $content='';
01353                 if (is_array($conf) && $this->checkIf($conf['if.']))    {
01354                         $tdRowCount=0;
01355                         $tableParams = $conf['tableParams'] ? ' '.$conf['tableParams'] : ' border="0" cellspacing="0" cellpadding="0"';
01356                         $TDparams = $conf['TDparams'] ? ' '.$conf['TDparams']:' valign="top"';
01357                         $rows = t3lib_div::intInRange($conf['rows'],2,20);
01358                         $totalWidth = intval($conf['totalWidth']);
01359                         $columnWidth=0;
01360 
01361                         $totalGapWidth=0;
01362                         $gapData = Array(
01363                                 'gapWidth' => $this->stdWrap($conf['gapWidth'],$conf['gapWidth.']),
01364                                 'gapBgCol' => $this->stdWrap($conf['gapBgCol'],$conf['gapBgCol.']),
01365                                 'gapLineThickness' => $this->stdWrap($conf['gapLineThickness'],$conf['gapLineThickness.']),
01366                                 'gapLineCol' => $this->stdWrap($conf['gapLineCol'],$conf['gapLineCol.'])
01367                         );
01368                         $gapData = $GLOBALS['TSFE']->tmpl->splitConfArray($gapData,$rows-1);
01369                         reset($gapData);
01370                         while(list(,$val)=each($gapData))       {
01371                                 $totalGapWidth+=intval($val['gapWidth']);
01372                         }
01373 
01374                         if ($totalWidth)        {
01375                                 $columnWidth = ceil(($totalWidth-$totalGapWidth)/$rows);
01376                                 $TDparams.=' width="'.$columnWidth.'"';
01377                                 $tableParams.=' width="'.$totalWidth.'"';
01378                         } else {
01379                                 $TDparams.=' width="'.floor(100/$rows).'%"';
01380                                 $tableParams.=' width="100%"';
01381                         }
01382 
01383                         for ($a=1;$a<=$rows;$a++)       {
01384                                 $tdRowCount++;
01385                                 $content.='<td'.$TDparams.'>';
01386                                 $content.=$this->cObjGetSingle($conf[$a],$conf[$a.'.'], $a);
01387                                 $content.='</td>';
01388                                 if ($a < $rows) {
01389                                         $gapConf = $gapData[($a-1)];
01390                                         $gapWidth = intval($gapConf['gapWidth']);
01391                                         if ($gapWidth)  {
01392                                                 $tdPar = $gapConf['gapBgCol'] ? ' bgcolor="'.$gapConf['gapBgCol'].'"' : '';
01393                                                 $gapLine = intval($gapConf['gapLineThickness']);
01394                                                 if ($gapLine)   {
01395                                                         $gapSurround = t3lib_div::intInRange(($gapWidth-$gapLine)/2, 1, 1000);
01396                                                                 // right gap
01397                                                         $content.='<td'.$tdPar.'><img src="'.$GLOBALS['TSFE']->absRefPrefix.'clear.gif" width="'.$gapSurround.'" height="1" alt="" title="" /></td>';
01398                                                         $tdRowCount++;
01399                                                                 // line:
01400                                                         $GtdPar = $gapConf['gapLineCol'] ? ' bgcolor="'.$gapConf['gapLineCol'].'"' : ' bgcolor="black"';
01401                                                         $content.='<td'.$GtdPar.'><img src="'.$GLOBALS['TSFE']->absRefPrefix.'clear.gif" width="'.$gapLine.'" height="1" alt="" title="" /></td>';
01402                                                         $tdRowCount++;
01403                                                                 // left gap
01404                                                         $content.='<td'.$tdPar.'><img src="'.$GLOBALS['TSFE']->absRefPrefix.'clear.gif" width="'.$gapSurround.'" height="1" alt="" title="" /></td>';
01405                                                         $tdRowCount++;
01406                                                 } else {
01407                                                         $content.='<td'.$tdPar.'><img src="'.$GLOBALS['TSFE']->absRefPrefix.'clear.gif" width="'.$gapWidth.'" height="1" alt="" title="" /></td>';
01408                                                         $tdRowCount++;
01409                                                 }
01410                                         }
01411                                 }
01412                         }
01413                         $content='<tr>'.$content.'</tr>';
01414                         $content='<table'.$tableParams.'>'.$content.'</table>';
01415                         $content.=$this->cObjGetSingle($conf['after'],$conf['after.'], 'after');
01416                         if ($conf['stdWrap.'])  {
01417                                 $content = $this->stdWrap($content,$conf['stdWrap.']);
01418                         }
01419                 }
01420                 return $content;
01421         }
01422 
01430         function HRULER ($conf) {
01431                 $lineThickness = t3lib_div::intInRange($this->stdWrap($conf['lineThickness'],$conf['lineThickness.']),1,50);
01432                 $lineColor = $conf['lineColor'] ? $conf['lineColor'] : 'black';
01433                 $spaceBefore = intval($conf['spaceLeft']);
01434                 $spaceAfter = intval($conf['spaceRight']);
01435                 $tableWidth = $conf['tableWidth'] ? $conf['tableWidth'] : '99%';
01436                 $content='';
01437 
01438                 $content.='<table border="0" cellspacing="0" cellpadding="0" width="'.htmlspecialchars($tableWidth).'"><tr>';
01439                 if ($spaceBefore)       {$content.='<td width="1"><img src="'.$GLOBALS['TSFE']->absRefPrefix.'clear.gif" width="'.$spaceBefore.'" height="1" alt="" title="" /></td>'; }
01440                 $content.='<td bgcolor="'.$lineColor.'"><img src="'.$GLOBALS['TSFE']->absRefPrefix.'clear.gif" width="1" height="'.$lineThickness.'" alt="" title="" /></td>';
01441                 if ($spaceAfter)        {$content.='<td width="1"><img src="'.$GLOBALS['TSFE']->absRefPrefix.'clear.gif" width="'.$spaceAfter.'" height="1" alt="" title="" /></td>'; }
01442                 $content.='</tr></table>';
01443 
01444                 $content = $this->stdWrap($content, $conf['stdWrap.']);
01445                 return $content;
01446         }
01447 
01455         function CASEFUNC ($conf){
01456                 $content='';
01457                 if ($this->checkIf($conf['if.']))       {
01458                         if ($conf['setCurrent'] || $conf['setCurrent.']){$this->data[$this->currentValKey] = $this->stdWrap($conf['setCurrent'], $conf['setCurrent.']);}
01459                         $key = $this->stdWrap($conf['key'],$conf['key.']);
01460                         $key = $conf[$key] ? $key : 'default';
01461                         $name = $conf[$key];
01462                         $theValue = $this->cObjGetSingle($name,$conf[$key.'.'], $key);
01463                         if ($conf['stdWrap.'])  {
01464                                 $theValue = $this->stdWrap($theValue,$conf['stdWrap.']);
01465                         }
01466                         return $theValue;
01467                 }
01468         }
01469 
01480         function LOAD_REGISTER($conf,$name)     {
01481                 if ($name=='RESTORE_REGISTER')  {
01482                         $GLOBALS['TSFE']->register = array_pop($GLOBALS['TSFE']->registerStack);
01483                 } else {
01484                         array_push($GLOBALS['TSFE']->registerStack,$GLOBALS['TSFE']->register);
01485                         if (is_array($conf))    {
01486                                 reset($conf);
01487                                 while(list($theKey,$theValue)=each($conf))      {
01488                                         if (!strstr($theKey,'.') || !isset($conf[substr($theKey,0,-1)]))        {               // Only if 1) the property is set but not the value itself, 2) the value and/or any property
01489                                                 if (strstr($theKey,'.'))        {
01490                                                         $theKey = substr($theKey,0,-1);
01491                                                 }
01492                                                 $GLOBALS['TSFE']->register[$theKey] = $this->stdWrap($conf[$theKey],$conf[$theKey.'.']);
01493                                         }
01494                                 }
01495                         }
01496                 }
01497                 return '';
01498         }
01499 
01520         function FORM($conf,$formData='')    {
01521                 $content='';
01522                 if (is_array($formData))        {
01523                         $dataArr = $formData;
01524                 } else {
01525                         $data=$this->stdWrap($conf['data'],$conf['data.']);
01526                                 // Clearing dataArr
01527                         $dataArr=array();
01528                                 // Getting the original config
01529                         if (trim($data))        {
01530                                 $data = ereg_replace(chr(10),'||',$data);
01531                                 $dataArr = explode('||',$data);
01532                         }
01533                                 // Adding the new dataArray config form:
01534                         if (is_array($conf['dataArray.'])) {    // dataArray is supplied
01535                                 $sKeyArray = t3lib_TStemplate::sortedKeyList($conf['dataArray.'], TRUE);
01536                                 foreach($sKeyArray as $theKey)  {
01537                                         $dAA = $conf['dataArray.'][$theKey.'.'];
01538                                         if (is_array($dAA))     {
01539                                                 $temp=array();
01540                                                 list($temp[0])= explode('|',$dAA['label.'] ? $this->stdWrap($dAA['label'],$dAA['label.']) : $dAA['label']);
01541                                                 list($temp[1])= explode('|',$dAA['type']);
01542                                                 if ($dAA['required'])   {$temp[1]='*'.$temp[1];}
01543                                                 list($temp[2])= explode('|',$dAA['value.'] ? $this->stdWrap($dAA['value'],$dAA['value.']) : $dAA['value']);
01544                                                         // If value Array is set, then implode those values.
01545                                                 if (is_array($dAA['valueArray.']))      {
01546                                                         reset($dAA['valueArray.']);
01547                                                         $temp_accum = array();
01548                                                         while(list($dAKey_vA,$dAA_vA)=each($dAA['valueArray.']))        {
01549                                                                 if (is_array($dAA_vA) && !strcmp(intval($dAKey_vA).'.',$dAKey_vA))      {
01550                                                                         $temp_vA=array();
01551                                                                         list($temp_vA[0])= explode('=',$dAA_vA['label.'] ? $this->stdWrap($dAA_vA['label'],$dAA_vA['label.']) : $dAA_vA['label']);
01552                                                                         if ($dAA_vA['selected'])        {$temp_vA[0]='*'.$temp_vA[0];}
01553                                                                         list($temp_vA[1])= explode(',',$dAA_vA['value']);
01554                                                                 }
01555                                                                 $temp_accum[] = implode('=',$temp_vA);
01556                                                         }
01557                                                         $temp[2] = implode(',',$temp_accum);
01558                                                 }
01559                                                 list($temp[3])= explode('|',$dAA['specialEval.'] ? $this->stdWrap($dAA['specialEval'],$dAA['specialEval.']) : $dAA['specialEval']);
01560 
01561                                                         // adding the form entry to the dataArray
01562                                                 $dataArr[] = implode('|',$temp);
01563                                         }
01564                                 }
01565                         }
01566                 }
01567 
01568                 $attachmentCounter = '';
01569                 $hiddenfields = '';
01570                 $fieldlist = Array();
01571                 $propertyOverride = Array();
01572                 $fieldname_hashArray = Array();
01573                 $cc = 0;
01574 
01575                         // Formname;
01576                 $formname = $GLOBALS['TSFE']->uniqueHash();
01577                 if (ctype_digit($formname{0}))  {       // form name must start with a letter
01578                         $formname = 'a'.$formname;
01579                 }
01580 
01581                 foreach($dataArr as $val)       {
01582 
01583                         $cc++;
01584                         $confData=Array();
01585                         if (is_array($formData)) {
01586                                 $parts = $val;
01587                                 $val = 1;    // true...
01588                         } else {
01589                                 $val = trim($val);
01590                                 $parts = explode('|',$val);
01591                         }
01592                         if ($val && strcspn($val,'#/')) {
01593                                         // label:
01594                                 $confData['label'] = trim($parts[0]);
01595                                         // field:
01596                                 $fParts = explode(',',$parts[1]);
01597                                 $fParts[0]=trim($fParts[0]);
01598                                 if (substr($fParts[0],0,1)=='*')        {
01599                                         $confData['required']=1;
01600                                         $fParts[0] = substr($fParts[0],1);
01601                                 }
01602                                 $typeParts = explode('=',$fParts[0]);
01603                                 $confData['type'] = trim(strtolower(end($typeParts)));
01604                                 if (count($typeParts)==1)       {
01605                                         $confData['fieldname'] = substr(ereg_replace('[^a-zA-Z0-9_]','',str_replace(' ','_',trim($parts[0]))),0,30);
01606                                         if (strtolower(ereg_replace('[^[:alnum:]]','',$confData['fieldname']))=='email')        {$confData['fieldname']='email';}
01607                                                 // Duplicate fieldnames resolved
01608                                         if (isset($fieldname_hashArray[md5($confData['fieldname'])]))   {
01609                                                 $confData['fieldname'].='_'.$cc;
01610                                         }
01611                                         $fieldname_hashArray[md5($confData['fieldname'])]=$confData['fieldname'];
01612                                                 // Attachment names...
01613                                         if ($confData['type']=='file')  {
01614                                                 $confData['fieldname']='attachment'.$attachmentCounter;
01615                                                 $attachmentCounter=intval($attachmentCounter)+1;
01616                                         }
01617                                 } else {
01618                                         $confData['fieldname'] = str_replace(' ','_',trim($typeParts[0]));
01619                                 }
01620                                 $fieldCode='';
01621 
01622                                 if ($conf['wrapFieldName'])     {
01623                                         $confData['fieldname'] = $this->wrap($confData['fieldname'],$conf['wrapFieldName']);
01624                                 }
01625 
01626                                         // Set field name as current:
01627                                 $this->setCurrentVal($confData['fieldname']);
01628 
01629                                         // Additional parameters
01630                                 if (trim($confData['type']))    {
01631                                         $addParams=trim($conf['params']);
01632                                         if (is_array($conf['params.']) && isset($conf['params.'][$confData['type']]))   {
01633                                                 $addParams=trim($conf['params.'][$confData['type']]);
01634                                         }
01635                                         if (strcmp('',$addParams))      $addParams=' '.$addParams;
01636                                 } else $addParams='';
01637 
01638                                         // Accessibility: Set id = fieldname attribute:
01639                                 if ($conf['accessibility'])     {
01640                                         $elementIdAttribute = ' id="'.$formname.'_'.md5($confData['fieldname']).'"';
01641                                 } else {
01642                                         $elementIdAttribute = '';
01643                                 }
01644 
01645                                         // Create form field based on configuration/type:
01646                                 switch($confData['type'])       {
01647                                         case 'textarea':
01648                                                 $cols=trim($fParts[1]) ? intval($fParts[1]) : 20;
01649                                                 $compWidth = doubleval($conf['compensateFieldWidth'] ? $conf['compensateFieldWidth'] : $GLOBALS['TSFE']->compensateFieldWidth);
01650                                                 $compWidth = $compWidth ? $compWidth : 1;
01651                                                 $cols = t3lib_div::intInRange($cols*$compWidth, 1, 120);
01652 
01653                                                 $rows=trim($fParts[2]) ? t3lib_div::intInRange($fParts[2],1,30) : 5;
01654                                                 $wrap=trim($fParts[3]);
01655                                                 if ($conf['noWrapAttr'] || $wrap === 'disabled')        {
01656                                                         $wrap='';
01657                                                 } else {
01658                                                         $wrap=$wrap ? ' wrap="'.trim($fParts[3]).'"' : ' wrap="virtual"';
01659                                                 }
01660                                                 $default = $this->getFieldDefaultValue($conf['noValueInsert'], $confData['fieldname'], str_replace('\n',chr(10),trim($parts[2])));
01661                                                 $fieldCode=sprintf('<textarea name="%s"'.$elementIdAttribute.' cols="%s" rows="%s"%s'.$addParams.'>%s</textarea>',
01662                                                         $confData['fieldname'], $cols, $rows, $wrap, t3lib_div::formatForTextarea($default));
01663                                         break;
01664                                         case 'input':
01665                                         case 'password':
01666                                                 $size=trim($fParts[1]) ? intval($fParts[1]) : 20;
01667                                                 $compWidth = doubleval($conf['compensateFieldWidth'] ? $conf['compensateFieldWidth'] : $GLOBALS['TSFE']->compensateFieldWidth);
01668                                                 $compWidth = $compWidth ? $compWidth : 1;
01669                                                 $size = t3lib_div::intInRange($size*$compWidth, 1, 120);
01670                                                 $default = $this->getFieldDefaultValue($conf['noValueInsert'], $confData['fieldname'], trim($parts[2]));
01671 
01672                                                 if ($confData['type']=='password')      {
01673                                                         $default='';
01674                                                 }
01675 
01676                                                 $max=trim($fParts[2]) ? ' maxlength="'.t3lib_div::intInRange($fParts[2],1,1000).'"' : "";
01677                                                 $theType = $confData['type']=='input' ? 'text' : 'password';
01678 
01679                                                 $fieldCode=sprintf('<input type="'.$theType.'" name="%s"'.$elementIdAttribute.' size="%s"%s value="%s"'.$addParams.' />',
01680                                                         $confData['fieldname'], $size, $max, htmlspecialchars($default));
01681 
01682                                         break;
01683                                         case 'file':
01684                                                 $size=trim($fParts[1]) ? t3lib_div::intInRange($fParts[1],1,60) : 20;
01685                                                 $fieldCode=sprintf('<input type="file" name="%s"'.$elementIdAttribute.' size="%s"'.$addParams.' />',
01686                                                         $confData['fieldname'], $size);
01687                                         break;
01688                                         case 'check':
01689                                                         // alternative default value:
01690                                                 $default = $this->getFieldDefaultValue($conf['noValueInsert'], $confData['fieldname'], trim($parts[2]));
01691                                                 $checked = $default ? ' checked="checked"' : '';
01692                                                 $fieldCode=sprintf('<input type="checkbox" value="%s" name="%s"'.$elementIdAttribute.'%s'.$addParams.' />',
01693                                                         1, $confData['fieldname'], $checked);
01694                                         break;
01695                                         case 'select':
01696                                                 $option='';
01697                                                 $valueParts = explode(',',$parts[2]);
01698                                                         // size
01699                                                 if (strtolower(trim($fParts[1]))=='auto')       {$fParts[1]=count($valueParts);}                // Auto size set here. Max 20
01700                                                 $size=trim($fParts[1]) ? t3lib_div::intInRange($fParts[1],1,20) : 1;
01701                                                         // multiple
01702                                                 $multiple = strtolower(trim($fParts[2]))=='m' ? ' multiple="multiple"' : '';
01703 
01704                                                 $items=array();         // Where the items will be
01705                                                 $defaults=array(); //RTF
01706                                                 for($a=0;$a<count($valueParts);$a++)    {
01707                                                         $valueParts[$a]=trim($valueParts[$a]);
01708                                                         if (substr($valueParts[$a],0,1)=='*')   {       // Finding default value
01709                                                                 $sel='selected';
01710                                                                 $valueParts[$a] = substr($valueParts[$a],1);
01711                                                         } else $sel='';
01712                                                                 // Get value/label
01713                                                         $subParts=explode('=',$valueParts[$a]);
01714                                                         $subParts[1] = (isset($subParts[1])?trim($subParts[1]):trim($subParts[0]));             // Sets the value
01715                                                         $items[] = $subParts;   // Adds the value/label pair to the items-array
01716                                                         if ($sel) {$defaults[]=$subParts[1];}   // Sets the default value if value/label pair is marked as default.
01717                                                 }
01718                                                         // alternative default value:
01719                                                 $default = $this->getFieldDefaultValue($conf['noValueInsert'], $confData['fieldname'], $defaults);
01720                                                 if (!is_array($default)) {
01721                                                         $defaults=array();
01722                                                         $defaults[] = $default;
01723                                                 } else $defaults=$default;
01724                                                         // Create the select-box:
01725                                                 for($a=0;$a<count($items);$a++) {
01726                                                         $option.='<option value="'.$items[$a][1].'"'.(in_array($items[$a][1],$defaults)?' selected="selected"':'').'>'.trim($items[$a][0]).'</option>'; //RTF
01727                                                 }
01728 
01729                                                 if ($multiple)  $confData['fieldname'].='[]';   // The fieldname must be prepended '[]' if multiple select. And the reason why it's prepended is, because the required-field list later must also have [] prepended.
01730                                                 $fieldCode=sprintf('<select name="%s"'.$elementIdAttribute.' size="%s"%s'.$addParams.'>%s</select>',
01731                                                         $confData['fieldname'], $size, $multiple, $option); //RTF
01732                                         break;
01733                                         case 'radio':
01734                                                 $option='';
01735                                                 $valueParts = explode(',',$parts[2]);
01736                                                 $items=array();         // Where the items will be
01737                                                 $default='';
01738                                                 for($a=0;$a<count($valueParts);$a++)    {
01739                                                         $valueParts[$a]=trim($valueParts[$a]);
01740                                                         if (substr($valueParts[$a],0,1)=='*')   {
01741                                                                 $sel='checked';
01742                                                                 $valueParts[$a] = substr($valueParts[$a],1);
01743                                                         } else $sel='';
01744                                                                 // Get value/label
01745                                                         $subParts=explode('=',$valueParts[$a]);
01746                                                         $subParts[1] = (isset($subParts[1])?trim($subParts[1]):trim($subParts[0]));             // Sets the value
01747                                                         $items[] = $subParts;   // Adds the value/label pair to the items-array
01748                                                         if ($sel) {$default=$subParts[1];}      // Sets the default value if value/label pair is marked as default.
01749                                                 }
01750                                                         // alternative default value:
01751                                                 $default = $this->getFieldDefaultValue($conf['noValueInsert'], $confData['fieldname'], $default);
01752                                                         // Create the select-box:
01753                                                 for($a=0;$a<count($items);$a++) {
01754                                                         $option.= '<input type="radio" name="'.$confData['fieldname'].'"'.$elementIdAttribute.' value="'.$items[$a][1].'"'.(!strcmp($items[$a][1],$default)?' checked="checked"':'').''.$addParams.' />';
01755                                                         $option.= $this->stdWrap(trim($items[$a][0]), $conf['radioWrap.']);
01756                                                         $option.= '<br />';
01757                                                 }
01758                                                 $fieldCode = $option;
01759                                         break;
01760                                         case 'hidden':
01761                                                 $value = trim($parts[2]);
01762                                                 if(strlen($value) && t3lib_div::inList('recipient_copy,recipient',$confData['fieldname']) && $GLOBALS['TYPO3_CONF_VARS']['FE']['secureFormmail']) {
01763                                                         break;
01764                                                 }
01765                                                 if (strlen($value) && t3lib_div::inList('recipient_copy,recipient',$confData['fieldname']))     {
01766                                                         $value = $GLOBALS['TSFE']->codeString($value);
01767                                                 }
01768                                                 $hiddenfields.=sprintf('<input type="hidden" name="%s"'.$elementIdAttribute.' value="%s" />',
01769                                                         $confData['fieldname'], htmlspecialchars($value));
01770                                         break;
01771                                         case 'property':
01772                                                 if (t3lib_div::inList('type,locationData,goodMess,badMess,emailMess',$confData['fieldname']))   {
01773                                                         $value=trim($parts[2]);
01774                                                         $propertyOverride[$confData['fieldname']] = $value;
01775                                                         $conf[$confData['fieldname']] = $value;
01776                                                 }
01777                                         break;
01778                                         case 'submit':
01779                                                 $value=trim($parts[2]);
01780                                                 if ($conf['image.'])    {
01781                                                         $this->data[$this->currentValKey]=$value;
01782                                                         $image=$this->IMAGE($conf['image.']);
01783                                                 } else $image='';
01784                                                 if($image)      {
01785                                                         $fieldCode = str_replace('<img','<input type="image"'.$addParams.' name="'.$confData['fieldname'].'"' ,$image);
01786                                                 } else  {
01787                                                         $fieldCode=sprintf('<input type="submit" name="%s"'.$elementIdAttribute.' value="%s"'.$addParams.' />',
01788                                                                 $confData['fieldname'], t3lib_div::deHSCentities(htmlspecialchars($value)));
01789                                                 }
01790                                         break;
01791                                         case 'reset':
01792                                                 $value=trim($parts[2]);
01793                                                 $fieldCode=sprintf('<input type="reset" name="%s"'.$elementIdAttribute.' value="%s"'.$addParams.' />',
01794                                                         $confData['fieldname'], t3lib_div::deHSCentities(htmlspecialchars($value)));
01795                                         break;
01796                                         case 'label':
01797                                                 $fieldCode = nl2br(htmlspecialchars(trim($parts[2])));
01798                                         break;
01799                                         default:
01800                                                 $confData['type'] = 'comment';
01801                                                 $fieldCode = trim($parts[2]).'&nbsp;';
01802                                         break;
01803                                 }
01804                                 if ($fieldCode) {
01805 
01806                                                 // Checking for special evaluation modes:
01807                                         if (t3lib_div::inList('textarea,input,password',$confData['type']) && strlen(trim($parts[3])))  {
01808                                                 $modeParameters = t3lib_div::trimExplode(':',$parts[3]);
01809                                         } else {
01810                                                 $modeParameters = array();
01811                                         }
01812 
01813                                                 // Adding evaluation based on settings:
01814                                         switch((string)$modeParameters[0])      {
01815                                                 case 'EREG':
01816                                                         $fieldlist[] = '_EREG';
01817                                                         $fieldlist[] = rawurlencode($modeParameters[1]);
01818                                                         $fieldlist[] = rawurlencode($modeParameters[2]);
01819                                                         $fieldlist[] = rawurlencode($confData['fieldname']);
01820                                                         $fieldlist[] = rawurlencode($confData['label']);
01821                                                         $confData['required'] = 1;      // Setting this so "required" layout is used.
01822                                                 break;
01823                                                 case 'EMAIL':
01824                                                         $fieldlist[] = '_EMAIL';
01825                                                         $fieldlist[] = rawurlencode($confData['fieldname']);
01826                                                         $fieldlist[] = rawurlencode($confData['label']);
01827                                                         $confData['required'] = 1;      // Setting this so "required" layout is used.
01828                                                 break;
01829                                                 default:
01830                                                         if ($confData['required'] && $confData['type']!='check')        {
01831                                                                 $fieldlist[] = rawurlencode($confData['fieldname']);
01832                                                                 $fieldlist[] = rawurlencode($confData['label']);
01833                                                         }
01834                                                 break;
01835                                         }
01836 
01837                                                 // Field:
01838                                         $fieldLabel = $confData['label'];
01839                                         if ($conf['accessibility'])     {
01840                                                 $fieldLabel = '<label for="'.$formname.'_'.md5($confData['fieldname']).'">'.$fieldLabel.'</label>';
01841                                         }
01842 
01843                                                 // Getting template code:
01844                                         $fieldCode = $this->stdWrap($fieldCode, $conf['fieldWrap.']);
01845                                         $labelCode = $this->stdWrap($fieldLabel, $conf['labelWrap.']);
01846                                         $commentCode = $this->stdWrap($confData['label'], $conf['commentWrap.']); // RTF
01847                                         $result = $conf['layout'];
01848                                         if ($conf['REQ'] && $confData['required'])      {
01849                                                 if (is_array($conf['REQ.']['fieldWrap.']))
01850                                                         $fieldCode = $this->stdWrap($fieldCode, $conf['REQ.']['fieldWrap.']);
01851                                                 if (is_array($conf['REQ.']['labelWrap.']))
01852                                                         $labelCode = $this->stdWrap($fieldLabel, $conf['REQ.']['labelWrap.']);
01853                                                 if ($conf['REQ.']['layout'])    {
01854                                                         $result = $conf['REQ.']['layout'];
01855                                                 }
01856                                         }
01857                                         if ($confData['type']=='comment' && $conf['COMMENT.']['layout'])        {
01858                                                 $result = $conf['COMMENT.']['layout'];
01859                                         }
01860                                         if ($confData['type']=='check' && $conf['CHECK.']['layout'])    {
01861                                                 $result = $conf['CHECK.']['layout'];
01862                                         }
01863                                         if ($confData['type']=='radio' && $conf['RADIO.']['layout'])    {
01864                                                 $result = $conf['RADIO.']['layout'];
01865                                         }
01866                                         if ($confData['type']=='label' && $conf['LABEL.']['layout']) {
01867                                                 $result = $conf['LABEL.']['layout'];
01868                                         }
01869                                         $result = str_replace('###FIELD###',$fieldCode,$result);
01870                                         $result = str_replace('###LABEL###',$labelCode,$result);
01871                                         $result = str_replace('###COMMENT###',$commentCode,$result); //RTF
01872                                         $content.= $result;
01873                                 }
01874                         }
01875                 }
01876                 if ($conf['stdWrap.']) $content=$this->stdWrap($content, $conf['stdWrap.']);
01877 
01878 
01879                         // redirect (external: where to go afterwards. internal: where to submit to)
01880                 $theRedirect = $this->stdWrap($conf['redirect'], $conf['redirect.']);                   // redirect should be set to the page to redirect to after an external script has been used. If internal scripts is used, and if no 'type' is set that dictates otherwise, redirect is used as the url to jump to as long as it's an integer (page)
01881                 $page = $GLOBALS['TSFE']->page;
01882                 if (!$theRedirect)      {               // Internal: Just submit to current page
01883                         $LD = $GLOBALS['TSFE']->tmpl->linkData($page, $conf['target'], $conf['no_cache'],'index.php', '', $this->getClosestMPvalueForPage($page['uid']));
01884                 } elseif (t3lib_div::testInt($theRedirect))     {               // Internal: Submit to page with id $theRedirect
01885                         $page = $GLOBALS['TSFE']->sys_page->getPage_noCheck($theRedirect);
01886                         $LD = $GLOBALS['TSFE']->tmpl->linkData($page, $conf['target'], $conf['no_cache'],'index.php', '', $this->getClosestMPvalueForPage($page['uid']));
01887                 } else {        // External url, redirect-hidden field is rendered!
01888                         $LD = $GLOBALS['TSFE']->tmpl->linkData($page, $conf['target'], $conf['no_cache'],'', '', $this->getClosestMPvalueForPage($page['uid']));
01889                         $LD['totalURL'] = $theRedirect;
01890                         $hiddenfields.= '<input type="hidden" name="redirect" value="'.htmlspecialchars($LD['totalURL']).'" />';                // 18-09-00 added
01891                 }
01892 
01893                         // Formtype (where to submit to!):
01894                 $formtype = $propertyOverride['type'] ? $propertyOverride['type'] : $this->stdWrap($conf['type'], $conf['type.']);
01895                 if (t3lib_div::testInt($formtype))      {       // Submit to a specific page
01896                         $page = $GLOBALS['TSFE']->sys_page->getPage_noCheck($formtype);
01897                         $LD_A = $GLOBALS['TSFE']->tmpl->linkData($page, $conf['target'], $conf['no_cache'], '', '', $this->getClosestMPvalueForPage($page['uid']));
01898                         $action = $LD_A['totalURL'];
01899                 } elseif ($formtype){           // Submit to external script
01900                         $LD_A = $LD;
01901                         $action = $formtype;
01902                 } elseif (t3lib_div::testInt($theRedirect)) {
01903                         $LD_A = $LD;
01904                         $action = $LD_A['totalURL'];
01905                 } else {                // Submit to 'nothing' - which is current page
01906                         $LD_A = $GLOBALS['TSFE']->tmpl->linkData($GLOBALS['TSFE']->page, $conf['target'], $conf['no_cache'], '', '', $this->getClosestMPvalueForPage($page['uid']));
01907                         $action = $LD_A['totalURL'];
01908                 }
01909 
01910                         // Recipient:
01911                 $theEmail = $this->stdWrap($conf['recipient'], $conf['recipient.']);
01912                 if ($theEmail && !$GLOBALS['TYPO3_CONF_VARS']['FE']['secureFormmail'])  {
01913                         $theEmail = $GLOBALS['TSFE']->codeString($theEmail);
01914                         $hiddenfields.='<input type="hidden" name="recipient" value="'.htmlspecialchars($theEmail).'" />';
01915                 }
01916 
01917                         // location data:
01918                 if ($conf['locationData'])      {
01919                         if ($conf['locationData']=='HTTP_POST_VARS' && isset($_POST['locationData']))   {
01920                                 $locationData = t3lib_div::_POST('locationData');
01921                         } else {
01922                                 $locationData = $GLOBALS['TSFE']->id.':'.$this->currentRecord;  // locationData is [hte page id]:[tablename]:[uid of record]. Indicates on which page the record (from tablename with uid) is shown. Used to check access.
01923                         }
01924                         $hiddenfields.='<input type="hidden" name="locationData" value="'.htmlspecialchars($locationData).'" />';
01925                 }
01926 
01927                         // hidden fields:
01928                 if (is_array($conf['hiddenFields.']))   {
01929                         reset($conf['hiddenFields.']);
01930                         while(list($hF_key,$hF_conf) = each($conf['hiddenFields.']))    {
01931                                 if (substr($hF_key,-1)!='.')    {
01932                                         $hF_value = $this->cObjGetSingle($hF_conf,$conf['hiddenFields.'][$hF_key.'.'],'hiddenfields');
01933                                         if (strlen($hF_value) && t3lib_div::inList('recipient_copy,recipient',$hF_key)) {
01934                                                 if($GLOBALS['TYPO3_CONF_VARS']['FE']['secureFormmail']) {
01935                                                         continue;
01936                                                 }
01937                                                 $hF_value = $GLOBALS['TSFE']->codeString($hF_value);
01938                                         }
01939                                         $hiddenfields.='<input type="hidden" name="'.$hF_key.'" value="'.htmlspecialchars($hF_value).'" />';
01940                                 }
01941                         }
01942                 }
01943 
01944                         // Wrap all hidden fields in a div tag (see http://bugs.typo3.org/view.php?id=678)
01945                 $hiddenfields = '<div style="display:none;">'.$hiddenfields.'</div>';
01946 
01947                 if ($conf['REQ'])       {
01948                         $validateForm=' onsubmit="return validateForm(\''.$formname.'\',\''.implode(',',$fieldlist).'\',\''.rawurlencode($conf['goodMess']).'\',\''.rawurlencode($conf['badMess']).'\',\''.rawurlencode($conf['emailMess']).'\')"';
01949                         $GLOBALS['TSFE']->additionalHeaderData['JSFormValidate'] = '<script type="text/javascript" src="'.$GLOBALS['TSFE']->absRefPrefix.'t3lib/jsfunc.validateform.js"></script>';
01950                 } else $validateForm='';
01951 
01952                         // Create form tag:
01953                 $theTarget = ($theRedirect?$LD['target']:$LD_A['target']);
01954                 $content = Array(
01955                         '<form'.
01956                                 ' action="'.htmlspecialchars($action).'"'.
01957                                 ' name="'.$formname.'"'.
01958                                 ' enctype="'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'].'"'.
01959                                 ' method="'.($conf['method']?$conf['method']:'post').'"'.
01960                                 ($theTarget ? ' target="'.$theTarget.'"' : '').
01961                                 $validateForm.
01962                                 '>',
01963                         $hiddenfields.$content,
01964                         '</form>'
01965                 );
01966                 if ($conf['arrayReturnMode'])   {
01967                         $content['validateForm']=$validateForm;
01968                         $content['formname']=$formname;
01969                         return $content;
01970                 } else {
01971                         return implode('',$content);
01972                 }
01973         }
01974 
01982         function SEARCHRESULT($conf)    {
01983                 if (t3lib_div::_GP('sword') && t3lib_div::_GP('scols')) {
01984                         $search = t3lib_div::makeInstance('tslib_search');
01985                         $search->register_and_explode_search_string(t3lib_div::_GP('sword'));
01986                         $search->register_tables_and_columns(t3lib_div::_GP('scols'),$conf['allowedCols']);
01987                                 // depth
01988                         $depth=100;
01989                                 // the startId is found
01990                         $theStartId=0;
01991                         if (t3lib_div::testInt(t3lib_div::_GP('stype')))        {
01992                                 $temp_theStartId=t3lib_div::_GP('stype');
01993                                 $rootLine = $GLOBALS['TSFE']->sys_page->getRootLine($temp_theStartId);
01994                                         // The page MUST have a rootline with the Level0-page of the current site inside!!
01995                                 while(list(,$val)=each($rootLine))      {
01996                                         if($val['uid']==$GLOBALS['TSFE']->tmpl->rootLine[0]['uid'])     {
01997                                                 $theStartId=$temp_theStartId;
01998                                         }
01999                                 }
02000                         } else if (t3lib_div::_GP('stype'))     {
02001                                 if (substr(t3lib_div::_GP('stype'),0,1)=='L')   {
02002                                         $pointer = intval(substr(t3lib_div::_GP('stype'),1));
02003                                         $theRootLine = $GLOBALS['TSFE']->tmpl->rootLine;
02004                                                 // location Data:
02005                                         $locDat_arr = explode(':',t3lib_div::_POST('locationData'));
02006                                         $pId = intval($locDat_arr[0]);
02007                                         if ($pId)       {
02008                                                 $altRootLine = $GLOBALS['TSFE']->sys_page->getRootLine($pId);
02009                                                 ksort($altRootLine);
02010                                                 if (count($altRootLine))        {
02011                                                                 // check if the rootline has the real Level0 in it!!
02012                                                         reset($altRootLine);
02013                                                         $hitRoot=0;
02014                                                         $theNewRoot=array();
02015                                                         while(list(,$val)=each($altRootLine))   {
02016                                                                 if($hitRoot || $val['uid']==$GLOBALS['TSFE']->tmpl->rootLine[0]['uid']) {
02017                                                                         $hitRoot=1;
02018                                                                         $theNewRoot[]=$val;
02019                                                                 }
02020                                                         }
02021                                                         if ($hitRoot)   {
02022                                                                 $theRootLine = $theNewRoot;             // Override the real rootline if any thing
02023                                                         }
02024                                                 }
02025                                         }
02026                                         $key = $this->getKey($pointer,$theRootLine);
02027                                         $theStartId = $theRootLine[$key]['uid'];
02028                                 }
02029                         }
02030                         if (!$theStartId)       {
02031                                         // If not set, we use current page
02032                                 $theStartId = $GLOBALS['TSFE']->id;
02033                         }
02034                                 // generate page-tree
02035                         $search->pageIdList.= $this->getTreeList(-1*$theStartId,$depth);
02036 
02037                         $endClause = 'pages.uid IN ('.$search->pageIdList.')
02038                                 AND pages.doktype in ('.$GLOBALS['TYPO3_CONF_VARS']['FE']['content_doktypes'].($conf['addExtUrlsAndShortCuts']?',3,4':'').')
02039                                 AND pages.no_search=0'.
02040                                 $this->enableFields($search->fTable).
02041                                 $this->enableFields('pages');
02042 
02043                         if ($conf['languageField.'][$search->fTable])   {
02044                                 $endClause.= ' AND '.$search->fTable.'.'.$conf['languageField.'][$search->fTable].' = '.intval($GLOBALS['TSFE']->sys_language_uid);     // (using sys_language_uid which is the ACTUAL language of the page. sys_language_content is only for selecting DISPLAY content!)
02045                         }
02046 
02047                                 // build query
02048                         $search->build_search_query($endClause);
02049 
02050                                 // count...
02051                         if (t3lib_div::testInt(t3lib_div::_GP('scount')))       {
02052                                 $search->res_count = t3lib_div::_GP('scount');
02053                         } else {
02054                                 $search->count_query();
02055                         }
02056 
02057                                 // range
02058                         $spointer = intval(t3lib_div::_GP('spointer'));
02059                         if (isset($conf['range']))      {
02060                                 $theRange = intval($conf['range']);
02061                         } else {
02062                                 $theRange = 20;
02063                         }
02064 
02065                                 // Order By:
02066                         if (!$conf['noOrderBy'])        {
02067                                 $search->queryParts['ORDERBY'] = 'pages.lastUpdated, pages.tstamp';
02068                         }
02069 
02070                         $search->queryParts['LIMIT'] = $spointer.','.$theRange;
02071 
02072                                 // search...
02073                         $search->execute_query();
02074                         if ($GLOBALS['TYPO3_DB']->sql_num_rows($search->result))        {
02075                                 $GLOBALS['TSFE']->register['SWORD_PARAMS'] = $search->get_searchwords();
02076 
02077                                 $total = $search->res_count;
02078                                 $rangeLow = t3lib_div::intInRange($spointer+1,1,$total);
02079                                 $rangeHigh = t3lib_div::intInRange($spointer+$theRange,1,$total);
02080                                         // prev/next url:
02081                                 $LD = $GLOBALS['TSFE']->tmpl->linkData($GLOBALS['TSFE']->page,$conf['target'],1,'', '', $this->getClosestMPvalueForPage($GLOBALS['TSFE']->page['uid']));
02082                                 $targetPart = $LD['target'] ? ' target="'.htmlspecialchars($LD['target']).'"' : '';
02083                                 $urlParams = $this->URLqMark($LD['totalURL'],
02084                                                 '&sword='.rawurlencode(t3lib_div::_GP('sword')).
02085                                                 '&scols='.rawurlencode(t3lib_div::_GP('scols')).
02086                                                 '&stype='.rawurlencode(t3lib_div::_GP('stype')).
02087                                                 '&scount='.$total);
02088                                         // substitution:
02089                                 $result= $this->cObjGetSingle($conf['layout'],$conf['layout.'], 'layout');
02090                                 $result = str_replace('###RANGELOW###',$rangeLow,$result);
02091                                 $result = str_replace('###RANGEHIGH###',$rangeHigh,$result);
02092                                 $result = str_replace('###TOTAL###',$total,$result);
02093 
02094                                 if ($rangeHigh<$total)  {
02095                                         $next = $this->cObjGetSingle($conf['next'], $conf['next.'], 'next');
02096                                         $next = '<a href="'.htmlspecialchars($urlParams.'&spointer='.($spointer+$theRange)).'"'.$targetPart.$GLOBALS['TSFE']->ATagParams.'>'.$next.'</a>';
02097                                 } else $next='';
02098                                 $result = str_replace('###NEXT###',$next,$result);
02099 
02100                                 if ($rangeLow>1)        {
02101                                         $prev = $this->cObjGetSingle($conf['prev'], $conf['prev.'], 'prev');
02102                                         $prev = '<a href="'.htmlspecialchars($urlParams.'&spointer='.($spointer-$theRange)).'"'.$targetPart.$GLOBALS['TSFE']->ATagParams.'>'.$prev.'</a>';
02103                                 } else $prev='';
02104                                 $result = str_replace('###PREV###',$prev,$result);
02105 
02106                                         // searching result
02107                                 $theValue = $this->cObjGetSingle($conf['resultObj'], $conf['resultObj.'],'resultObj');
02108                                 $cObj = t3lib_div::makeInstance('tslib_cObj');
02109                                 $cObj->setParent($this->data,$this->currentRecord);
02110                                 $renderCode='';
02111                                 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($search->result))   {
02112                                         $cObj->start($row);
02113                                         $renderCode.=$cObj->cObjGetSingle($conf['renderObj'], $conf['renderObj.'],'renderObj');
02114                                 }
02115                                 $theValue.=$this->wrap($renderCode,$conf['renderWrap']);
02116                                 $theValue = str_replace('###RESULT###',$theValue,$result);
02117                         } else {
02118                                 $theValue = $this->cObjGetSingle($conf['noResultObj'], $conf['noResultObj.'],'noResultObj');
02119                         }
02120 
02121                         $GLOBALS['TT']->setTSlogMessage('Search in fields:   '.$search->listOfSearchFields);
02122 
02123                                 // wrapping
02124                         $content=$theValue;
02125                         if ($conf['wrap']) {
02126                                 $content=$this->wrap($content, $conf['wrap']);
02127                         }
02128                         if ($conf['stdWrap.']) {
02129                                 $content=$this->stdWrap($content, $conf['stdWrap.']);
02130                         }
02131                                 // returning
02132                         $GLOBALS['TSFE']->set_no_cache();
02133                         return $content;
02134                 }
02135         }
02136 
02147         function PHP_SCRIPT($conf,$ext='')      {
02148                 $incFile = $GLOBALS['TSFE']->tmpl->getFileName($conf['file']);
02149                 $content='';
02150                 if ($incFile && $GLOBALS['TSFE']->checkFileInclude($incFile))   {
02151                         switch($ext)    {
02152                                 case 'INT':
02153                                 case 'EXT':
02154                                         $substKey = $ext.'_SCRIPT.'.$GLOBALS['TSFE']->uniqueHash();
02155                                         $content.='<!--'.$substKey.'-->';
02156                                         $GLOBALS['TSFE']->config[$ext.'incScript'][$substKey] = array(
02157                                                 'file'=>$incFile,
02158                                                 'conf'=>$conf,
02159                                                 'type'=>'SCRIPT'
02160                                         );
02161                                         if ($ext=='INT')        {
02162                                                 $GLOBALS['TSFE']->config[$ext.'incScript'][$substKey]['cObj'] = serialize($this);
02163                                         } else {
02164                                                 $GLOBALS['TSFE']->config[$ext.'incScript'][$substKey]['data'] = $this->data;
02165                                         }
02166                                 break;
02167                                 default:
02168                                                 // Added 31-12-00: Make backup...
02169                                         $this->oldData = $this->data;
02170                                                 // Include file..
02171                                         include('./'.$incFile);
02172                                                 // Added 31-12-00: restore...
02173                                         if ($RESTORE_OLD_DATA)  {
02174                                                 $this->data = $this->oldData;
02175                                         }
02176                                 break;
02177                         }
02178                 }
02179                 return $content;
02180         }
02181 
02190         function TEMPLATE($conf)        {
02191                 $subparts = Array();
02192                 $marks = Array();
02193                 $wraps = Array();
02194                 $content='';
02195 
02196                 list($PRE,$POST) = explode('|',$conf['markerWrap'] ? $conf['markerWrap'] : '### | ###');
02197                 $POST = trim($POST);
02198                 $PRE  = trim($PRE);
02199 
02200                         // Getting the content
02201                 $content = $this->cObjGetSingle($conf['template'],$conf['template.'],'template');
02202                 if ($conf['workOnSubpart'])     {
02203                         $content = $this->getSubpart($content, $PRE.$conf['workOnSubpart'].$POST);
02204                 }
02205 
02206                         // Fixing all relative paths found:
02207                 if ($conf['relPathPrefix'])     {
02208                         $htmlParser = t3lib_div::makeInstance('t3lib_parsehtml');
02209                         $content = $htmlParser->prefixResourcePath($conf['relPathPrefix'],$content,$conf['relPathPrefix.']);
02210                 }
02211 
02212                 if ($content)   {
02213                         if ($conf['nonCachedSubst'])    {               // NON-CACHED:
02214                                         // Getting marks
02215                                 if (is_array($conf['marks.']))  {
02216                                         reset($conf['marks.']);
02217                                         while(list($theKey,$theValue)=each($conf['marks.']))    {
02218                                                 if (!strstr($theKey,'.'))       {
02219                                                         $content = str_replace(
02220                                                                 $PRE.$theKey.$POST,
02221                                                                 $this->cObjGetSingle($theValue,$conf['marks.'][$theKey.'.'],'marks.'.$theKey),
02222                                                                 $content);
02223                                                 }
02224                                         }
02225                                 }
02226 
02227                                         // Getting subparts.
02228                                 if (is_array($conf['subparts.']))       {
02229                                         reset($conf['subparts.']);
02230                                         while(list($theKey,$theValue)=each($conf['subparts.'])) {
02231                                                 if (!strstr($theKey,'.'))       {
02232                                                         $subpart = $this->getSubpart($content, $PRE.$theKey.$POST);
02233                                                         if ($subpart)   {
02234                                                                 $this->setCurrentVal($subpart);
02235                                                                 $content = $this->substituteSubpart(
02236                                                                         $content,
02237                                                                         $PRE.$theKey.$POST,
02238                                                                         $this->cObjGetSingle($theValue,$conf['subparts.'][$theKey.'.'],'subparts.'.$theKey),
02239                                                                         1
02240                                                                 );
02241                                                         }
02242                                                 }
02243                                         }
02244                                 }
02245                                         // Getting subpart wraps
02246                                 if (is_array($conf['wraps.']))  {
02247                                         reset($conf['wraps.']);
02248                                         while(list($theKey,$theValue)=each($conf['wraps.']))    {
02249                                                 if (!strstr($theKey,'.'))       {
02250                                                         $subpart = $this->getSubpart($content, $PRE.$theKey.$POST);
02251                                                         if ($subpart)   {
02252                                                                 $this->setCurrentVal($subpart);
02253                                                                 $content = $this->substituteSubpart(
02254                                                                         $content,
02255                                                                         $PRE.$theKey.$POST,
02256                                                                         explode('|',$this->cObjGetSingle($theValue,$conf['wraps.'][$theKey.'.'],'wraps.'.$theKey)),
02257                                                                         1
02258                                                                 );
02259                                                         }
02260                                                 }
02261                                         }
02262                                 }
02263                         } else {        // CACHED
02264                                         // Getting subparts.
02265                                 if (is_array($conf['subparts.']))       {
02266                                         reset($conf['subparts.']);
02267                                         while(list($theKey,$theValue)=each($conf['subparts.'])) {
02268                                                 if (!strstr($theKey,'.'))       {
02269                                                         $subpart = $this->getSubpart($content, $PRE.$theKey.$POST);
02270                                                         if ($subpart)   {
02271                                                                 $GLOBALS['TSFE']->register['SUBPART_'.$theKey] = $subpart;
02272                                                                 $subparts[$theKey]['name'] = $theValue;
02273                                                                 $subparts[$theKey]['conf'] = $conf['subparts.'][$theKey.'.'];
02274                                                         }
02275                                                 }
02276                                         }
02277                                 }
02278                                         // Getting marks
02279                                 if (is_array($conf['marks.']))  {
02280                                         reset($conf['marks.']);
02281                                         while(list($theKey,$theValue)=each($conf['marks.']))    {
02282                                                 if (!strstr($theKey,'.'))       {
02283                                                         $marks[$theKey]['name'] = $theValue;
02284                                                         $marks[$theKey]['conf'] = $conf['marks.'][$theKey.'.'];
02285                                                 }
02286                                         }
02287                                 }
02288                                         // Getting subpart wraps
02289                                 if (is_array($conf['wraps.']))  {
02290                                         reset($conf['wraps.']);
02291                                         while(list($theKey,$theValue)=each($conf['wraps.']))    {
02292                                                 if (!strstr($theKey,'.'))       {
02293                                                         $wraps[$theKey]['name'] = $theValue;
02294                                                         $wraps[$theKey]['conf'] = $conf['wraps.'][$theKey.'.'];
02295                                                 }
02296                                         }
02297                                 }
02298                                         // Getting subparts
02299                                 $subpartArray =array();
02300                                 reset($subparts);
02301                                 while(list($theKey,$theValue)=each($subparts))  {
02302                                                 // Set current with the content of the subpart...
02303                                         $this->data[$this->currentValKey] = $GLOBALS['TSFE']->register['SUBPART_'.$theKey];
02304                                                 // Get subpart cObject and substitute it!
02305                                         $subpartArray[$PRE.$theKey.$POST] = $this->cObjGetSingle($theValue['name'],$theValue['conf'],'subparts.'.$theKey);
02306                                 }
02307                                 $this->data[$this->currentValKey] = ''; // Reset current to empty
02308 
02309                                         // Getting marks
02310                                 $markerArray =array();
02311                                 reset($marks);
02312                                 while(list($theKey,$theValue)=each($marks))     {
02313                                         $markerArray[$PRE.$theKey.$POST] = $this->cObjGetSingle($theValue['name'],$theValue['conf'],'marks.'.$theKey);
02314                                 }
02315                                         // Getting wraps
02316                                 $subpartWraps =array();
02317                                 reset($wraps);
02318                                 while(list($theKey,$theValue)=each($wraps))     {
02319                                         $subpartWraps[$PRE.$theKey.$POST] = explode('|',$this->cObjGetSingle($theValue['name'],$theValue['conf'],'wraps.'.$theKey));
02320                                 }
02321 
02322                                         // Substitution
02323                                 if ($conf['substMarksSeparately'])      {
02324                                         $content = $this->substituteMarkerArrayCached($content,array(),$subpartArray,$subpartWraps);
02325                                         $content = $this->substituteMarkerArray($content, $markerArray);
02326                                 } else {
02327                                         $content = $this->substituteMarkerArrayCached($content,$markerArray,$subpartArray,$subpartWraps);
02328                                 }
02329                         }
02330                 }
02331                 return $content;
02332         }
02333 
02341         function MULTIMEDIA($conf)      {
02342                 $content='';
02343                 $filename=$this->stdWrap($conf['file'],$conf['file.']);
02344                 $incFile = $GLOBALS['TSFE']->tmpl->getFileName($filename);
02345                 if ($incFile)   {
02346                         $fileinfo = t3lib_div::split_fileref($incFile);
02347                         if (t3lib_div::inList('txt,html,htm',$fileinfo['fileext']))     {
02348                                 $content = $GLOBALS['TSFE']->tmpl->fileContent($incFile);
02349                         } else {
02350                                         // default params...
02351                                 $parArray=array();
02352                                         // src is added
02353                                 $parArray['src']='src="'.$GLOBALS['TSFE']->absRefPrefix.$incFile.'"';
02354                                 if (t3lib_div::inList('au,wav,mp3',$fileinfo['fileext']))       {
02355                                 }
02356                                 if (t3lib_div::inList('avi,mov,mpg,asf,wmv',$fileinfo['fileext']))      {
02357                                         $parArray['width'] = 'width="200"';
02358                                         $parArray['height'] = 'height="200"';
02359                                 }
02360                                 if (t3lib_div::inList('swf,swa,dcr',$fileinfo['fileext']))      {
02361                                         $parArray['quality'] = 'quality="high"';
02362                                 }
02363                                 if (t3lib_div::inList('class',$fileinfo['fileext']))    {
02364                                         $parArray['width'] = 'width="200"';
02365                                         $parArray['height'] = 'height="200"';
02366                                 }
02367 
02368                                         // fetching params
02369                                 $lines = explode(chr(10), $this->stdWrap($conf['params'],$conf['params.']));
02370                                 while(list(,$l)=each($lines))   {
02371                                         $parts = explode('=', $l);
02372                                         $parameter = strtolower(trim($parts[0]));
02373                                         $value = trim($parts[1]);
02374                                         if ((string)$value!='') {
02375                                                 $parArray[$parameter] = $parameter.'="'.htmlspecialchars($value).'"';
02376                                         } else {
02377                                                 unset($parArray[$parameter]);
02378                                         }
02379                                 }
02380                                 if ($fileinfo['fileext']=='class')      {
02381                                         unset($parArray['src']);
02382                                         $parArray['code'] = 'code="'.htmlspecialchars($fileinfo['file']).'"';
02383                                         $parArray['codebase'] = 'codebase="'.htmlspecialchars($fileinfo['path']).'"';
02384                                         $content='<applet '.implode(' ',$parArray).'></applet>';
02385                                 } else {
02386                                         $content='<embed '.implode(' ',$parArray).'></embed>';
02387                                 }
02388                         }
02389                 }
02390 
02391                 if ($conf['stdWrap.']) {
02392                         $content=$this->stdWrap($content, $conf['stdWrap.']);
02393                 }
02394 
02395                 return $content;
02396         }
02397 
02398 
02399 
02400 
02401 
02402 
02403 
02404 
02405 
02406 
02407 
02408 
02409 
02410 
02411 
02412 
02413 
02414         /************************************
02415          *
02416          * Various helper functions for content objects:
02417          *
02418          ************************************/
02419 
02430         function netprintApplication_offsiteLinkWrap($str,$imgConf,$conf)       {
02431                 if ($conf['url'] && @is_file($imgConf['origFile']))     {
02432                         $thisUrl = $conf['thisUrl'] ? $conf['thisUrl'] : t3lib_div::getIndpEnv('TYPO3_REQUEST_DIR');
02433                         $origFile=$thisUrl.$imgConf['origFile'];
02434                                 // Original file dimensions:
02435                         $gifCreator = t3lib_div::makeInstance('tslib_gifbuilder');
02436                         $gifCreator->init();
02437                         $origDim = $gifCreator->getImageDimensions($imgConf['origFile']);
02438                         if (!$conf['linkOnlyPixelsAbove'] || $origDim[0]*$origDim[1]>$conf['linkOnlyPixelsAbove'])      {
02439                                         // Set parameters
02440                                 $thumbFile=$thisUrl.$imgConf['3'].'|'.$imgConf[0].'x'.$imgConf[1].'|'.$origDim[0].'x'.$origDim[1].'|'.filesize($imgConf['origFile']).'|'.filemtime($imgConf['origFile']);
02441                                         // Set url:
02442                                 $url = $conf['url']
02443                                         .'&NP[offsite][1]='.rawurlencode($origFile)
02444                                         .'&NP[offsite_thumb][1]='.rawurlencode($thumbFile);
02445                                 $linkCObject = $this->cObjGetSingle($conf['cObject'],$conf['cObject.']);
02446                                 if ($linkCObject)       {
02447                                         $ATagParams = trim($conf['ATagParams']) ? ' '.trim($conf['ATagParams']) : '';
02448                                         $linkCObject='<a href="'.htmlspecialchars($url).'"'.$ATagParams.'>'.$linkCObject.'</a>';
02449                                         $linkCObject=$this->stdWrap($linkCObject,$conf['outerStdWrap.']);
02450                                         if ($conf['before'])    {
02451                                                 $str=$linkCObject.$str;
02452                                         } else {
02453                                                 $str=$str.$linkCObject;
02454                                         }
02455                                 }
02456                         }
02457                 }
02458                 return $str;
02459         }
02460 
02471         function getFieldDefaultValue($noValueInsert, $fieldName, $defaultVal) {
02472                 if (!$GLOBALS['TSFE']->no_cache || (!isset($_POST[$fieldName]) && !isset($_GET[$fieldName])) || $noValueInsert) {
02473                         return $defaultVal;
02474                 } else {
02475                         return t3lib_div::_GP($fieldName);
02476                 }
02477         }
02478 
02489         function cImage($file,$conf) {
02490                 $info = $this->getImgResource($file,$conf['file.']);
02491                 $GLOBALS['TSFE']->lastImageInfo=$info;
02492                 if (is_array($info))    {
02493                         $info[3] = t3lib_div::png_to_gif_by_imagemagick($info[3]);
02494                         $GLOBALS['TSFE']->imagesOnPage[]=$info[3];              // This array is used to collect the image-refs on the page...
02495 
02496                         if (!strlen($conf['altText']) && !is_array($conf['altText.']))  {       // Backwards compatible:
02497                                 $conf['altText'] = $conf['alttext'];
02498                                 $conf['altText.'] = $conf['alttext.'];
02499                         }
02500                         $altParam = $this->getAltParam($conf);
02501 
02502                         $theValue = '<img src="'.htmlspecialchars($GLOBALS['TSFE']->absRefPrefix.t3lib_div::rawUrlEncodeFP($info[3])).'" width="'.$info[0].'" height="'.$info[1].'"'.$this->getBorderAttr(' border="'.intval($conf['border']).'"').($conf['params']?' '.$conf['params']:'').($altParam).' />';
02503                         if ($conf['linkWrap'])  {
02504                                 $theValue = $this->linkWrap($theValue,$conf['linkWrap']);
02505                         } elseif ($conf['imageLinkWrap']) {
02506                                 $theValue = $this->imageLinkWrap($theValue,$info['origFile'],$conf['imageLinkWrap.']);
02507                         }
02508                         return $this->wrap($theValue,$conf['wrap']);
02509                 }
02510         }
02517         function getBorderAttr($borderAttr) {
02518                 if (!t3lib_div::inList('xhtml_strict,xhtml_11,xhtml_2',$GLOBALS['TSFE']->config['config']['doctype']) || $GLOBALS['TSFE']->config['config']['disableImgBorderAttr']) {
02519                         return $borderAttr;
02520                 }
02521         }
02522 
02533         function imageLinkWrap($string,$imageFile,$conf) {
02534                 $a1='';
02535                 $a2='';
02536                 $content=$string;
02537                 if ($this->stdWrap($conf['enable'],$conf['enable.']))   {
02538                         $content=$this->typolink($string, $conf['typolink.']);
02539                                 // imageFileLink:
02540                         if ($content==$string && @is_file($imageFile)) {
02541                                 $params = '';
02542                                 if ($conf['width']) {$params.='&width='.rawurlencode($conf['width']);}
02543                                 if ($conf['height']) {$params.='&height='.rawurlencode($conf['height']);}
02544                                 if ($conf['effects']) {$params.='&effects='.rawurlencode($conf['effects']);}
02545                                 if ($conf['sample']) {$params.='&sample=1';}
02546                                 if ($conf['alternativeTempPath']) {$params.='&alternativeTempPath='.rawurlencode($conf['alternativeTempPath']);}
02547 
02548                                 if ($conf['bodyTag']) {$params.='&bodyTag='.rawurlencode($conf['bodyTag']);}
02549                                 if ($conf['title']) {$params.='&title='.rawurlencode($conf['title']);}
02550                                 if ($conf['wrap']) {$params.='&wrap='.rawurlencode($conf['wrap']);}
02551 
02552                                 $md5_value = md5($imageFile.'|'.$conf['width'].'|'.$conf['height'].'|'.$conf['effects'].'|'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'].'|');
02553 
02554                                 $params.= '&md5='.$md5_value;
02555                                 $url = $GLOBALS['TSFE']->absRefPrefix.'showpic.php?file='.rawurlencode($imageFile).$params;
02556                                 if ($conf['JSwindow.']['altUrl'] || $conf['JSwindow.']['altUrl.'])      {
02557                                         $altUrl = $this->stdWrap($conf['JSwindow.']['altUrl'], $conf['JSwindow.']['altUrl.']);
02558                                         if ($altUrl)    {
02559                                                 $url=$altUrl;
02560                                         }
02561                                 }
02562 
02563                                 if ($conf['JSwindow'])  {
02564                                         $gifCreator = t3lib_div::makeInstance('tslib_gifbuilder');
02565                                         $gifCreator->init();
02566                                         $gifCreator->mayScaleUp = 0;
02567                                         $dims = $gifCreator->getImageScale($gifCreator->getImageDimensions($imageFile),$conf['width'],$conf['height'],'');
02568                                         $offset = t3lib_div::intExplode(',',$conf['JSwindow.']['expand'].',');
02569 
02570                                         $a1='<a href="#" onclick="'.
02571                                                 htmlspecialchars('openPic(\''.$GLOBALS['TSFE']->baseUrlWrap($url).'\',\''.($conf['JSwindow.']['newWindow']?md5($url):'thePicture').'\',\'width='.($dims[0]+$offset[0]).',height='.($dims[1]+$offset[1]).',status=0,menubar=0\'); return false;').
02572                                                 '"'.$GLOBALS['TSFE']->ATagParams.'>';
02573                                         $a2='</a>';
02574                                         $GLOBALS['TSFE']->setJS('openPic');
02575                                 } else {
02576                                         $target = ' target="thePicture"';
02577                                         if (isset($conf['target'])) {
02578                                                 $target= $conf['target'] ? ' target="'.$conf['target'].'"' : '';
02579                                         }
02580                                         $a1='<a href="'.htmlspecialchars($url).'"'.$target.$GLOBALS['TSFE']->ATagParams.'>';
02581                                         $a2='</a>';
02582                                 }
02583                                 $content=$a1.$string.$a2;
02584                         }
02585                 }
02586 
02587                 return $content;
02588         }
02589 
02598         function fileResource($fName, $addParams='alt="" title=""')     {
02599                 $incFile = $GLOBALS['TSFE']->tmpl->getFileName($fName);
02600                 if ($incFile)   {
02601                         $fileinfo = t3lib_div::split_fileref($incFile);
02602                         if (t3lib_div::inList('jpg,gif,jpeg,png',$fileinfo['fileext'])) {
02603                                 $imgFile = $incFile;
02604                                 $imgInfo = @getImageSize($imgFile);
02605                                 return '<img src="'.$GLOBALS['TSFE']->absRefPrefix.$imgFile.'" width="'.$imgInfo[0].'" height="'.$imgInfo[1].'"'.$this->getBorderAttr(' border="0"').' '.$addParams.' />';
02606                         } elseif (filesize($incFile)<1024*1024) {
02607                                 return $GLOBALS['TSFE']->tmpl->fileContent($incFile);
02608                         }
02609                 }
02610         }
02611 
02621         function lastChanged($tstamp)   {
02622                 $tstamp = intval($tstamp);
02623                 if ($tstamp>intval($GLOBALS['TSFE']->register['SYS_LASTCHANGED']))      {
02624                         $GLOBALS['TSFE']->register['SYS_LASTCHANGED'] = $tstamp;
02625                 }
02626         }
02627 
02638         function linkWrap($content,$wrap)       {
02639                 $wrapArr = explode('|', $wrap);
02640                 if (ereg("\{([0-9]*)\}",$wrapArr[0],$reg))      {
02641                         if ($uid = $GLOBALS['TSFE']->tmpl->rootLine[$reg[1]]['uid'])    {
02642                                 $wrapArr[0] = str_replace($reg[0],$uid,$wrapArr[0]);
02643                         }
02644                 }
02645                 return trim($wrapArr[0]).$content.trim($wrapArr[1]);
02646         }
02647 
02656         function getAltParam($conf)     {
02657                 $altText = trim($this->stdWrap($conf['altText'], $conf['altText.']));
02658                 $titleText = trim($this->stdWrap($conf['titleText'],$conf['titleText.']));
02659                 $longDesc = trim($this->stdWrap($conf['longdescURL'],$conf['longdescURL.']));
02660 
02661                         // "alt":
02662                 $altParam = ' alt="'.htmlspecialchars(strip_tags($altText)).'"';
02663 
02664                         // "title":
02665                 if ($titleText) {
02666                         $altParam.= ' title="'.htmlspecialchars(strip_tags($titleText)).'"';
02667                 } else {
02668                         $altParam.= ' title="'.htmlspecialchars(strip_tags($altText)).'"';
02669                 }
02670 
02671                         // "longDesc" URL
02672                 if ($longDesc)  {
02673                         $altParam.= ' longdesc="'.htmlspecialchars($longDesc).'"';
02674                 }
02675 
02676                 return $altParam;
02677         }
02678 
02679 
02680 
02681 
02682 
02683 
02684 
02685 
02686 
02687 
02688 
02689 
02690 
02691 
02692 
02693 
02694 
02695 
02696 
02697         /***********************************************
02698          *
02699          * HTML template processing functions
02700          *
02701          ***********************************************/
02702 
02713         function getSubpart($content, $marker)  {
02714                 if ($marker && strstr($content,$marker))        {
02715                         $start = strpos($content, $marker)+strlen($marker);
02716                         $stop = @strpos($content, $marker, $start+1);
02717                         $sub = substr($content, $start, $stop-$start);
02718 
02719                         $reg=Array();
02720                         ereg('^[^<]*-->',$sub,$reg);
02721                         $start+=strlen($reg[0]);
02722 
02723                         $reg=Array();
02724                         ereg('<!--[^>]*$',$sub,$reg);
02725                         $stop-=strlen($reg[0]);
02726 
02727                         return substr($content, $start, $stop-$start);
02728                 }
02729         }
02730 
02742         function substituteSubpart($content,$marker,$subpartContent,$recursive=1)       {
02743                 $start = strpos($content, $marker);
02744                 $stop = @strpos($content, $marker, $start+1)+strlen($marker);
02745                 if ($start && $stop>$start)     {
02746                                 // code before
02747                         $before = substr($content, 0, $start);
02748                         $reg=Array();
02749                         ereg('<!--[^>]*$',$before,$reg);
02750                         $start-=strlen($reg[0]);
02751                         $before = substr($content, 0, $start);
02752                                 // code after
02753                         $after = substr($content, $stop);
02754                         $reg=Array();
02755                         ereg('^[^<]*-->',$after,$reg);
02756                         $stop+=strlen($reg[0]);
02757                         $after = substr($content, $stop);
02758                                 // replace?
02759                         if (is_array($subpartContent))  {
02760                                 $substContent=$subpartContent[0].$this->getSubpart($content,$marker).$subpartContent[1];
02761                         } else {
02762                                 $substContent=$subpartContent;
02763                         }
02764 
02765                         if ($recursive && strpos($after, $marker))      {
02766                                 return $before.$substContent.$this->substituteSubpart($after,$marker,$subpartContent);
02767                         } else {
02768                                 return $before.$substContent.$after;
02769                         }
02770                 } else {
02771                         return $content;
02772                 }
02773         }
02774 
02784         function substituteMarker($content,$marker,$markContent)        {
02785                 return str_replace($marker,$markContent,$content);
02786         }
02787 
02804         function substituteMarkerArrayCached($content,$markContentArray=array(),$subpartContentArray=array(),$wrappedSubpartContentArray=array())       {
02805                 $GLOBALS['TT']->push('/substituteMarkerArray/');
02806 
02807                         // If not arrays then set them
02808                 if (!is_array($markContentArray))       $markContentArray=array();      // Plain markers
02809                 if (!is_array($subpartContentArray))    $subpartContentArray=array();   // Subparts being directly substituted
02810                 if (!is_array($wrappedSubpartContentArray))     $wrappedSubpartContentArray=array();    // Subparts being wrapped
02811                         // Finding keys and check hash:
02812                 $sPkeys = array_keys($subpartContentArray);
02813                 $wPkeys = array_keys($wrappedSubpartContentArray);
02814                 $aKeys = array_merge(array_keys($markContentArray),$sPkeys,$wPkeys);
02815                 if (!count($aKeys))     {
02816                         $GLOBALS['TT']->pull();
02817                         return $content;
02818                 }
02819                 asort($aKeys);
02820                 $storeKey = md5('substituteMarkerArrayCached_storeKey:'.serialize(array($content,$aKeys)));
02821                 if ($this->substMarkerCache[$storeKey]) {
02822                         $storeArr = $this->substMarkerCache[$storeKey];
02823                         $GLOBALS['TT']->setTSlogMessage('Cached',0);
02824                 } else {
02825                         $storeArrDat = $GLOBALS['TSFE']->sys_page->getHash($storeKey,0);
02826                         if (!isset($storeArrDat))       {
02827                                         // Initialize storeArr
02828                                 $storeArr=array();
02829 
02830                                         // Finding subparts and substituting them with the subpart as a marker
02831                                 reset($sPkeys);
02832                                 while(list(,$sPK)=each($sPkeys))        {
02833                                         $content =$this->substituteSubpart($content,$sPK,$sPK);
02834                                 }
02835 
02836                                         // Finding subparts and wrapping them with markers
02837                                 reset($wPkeys);
02838                                 while(list(,$wPK)=each($wPkeys))        {
02839                                         $content =$this->substituteSubpart($content,$wPK,array($wPK,$wPK));
02840                                 }
02841 
02842                                         // traverse keys and quote them for reg ex.
02843                                 reset($aKeys);
02844                                 while(list($tK,$tV)=each($aKeys))       {
02845                                         $aKeys[$tK]=quotemeta($tV);
02846                                 }
02847                                 $regex = implode('|',$aKeys);
02848                                         // Doing regex's
02849                                 $storeArr['c'] = split($regex,$content);
02850                                 preg_match_all('/'.$regex.'/',$content,$keyList);
02851                                 $storeArr['k']=$keyList[0];
02852                                         // Setting cache:
02853                                 $this->substMarkerCache[$storeKey] = $storeArr;
02854 
02855                                         // Storing the cached data:
02856                                 $GLOBALS['TSFE']->sys_page->storeHash($storeKey, serialize($storeArr), 'substMarkArrayCached');
02857 
02858                                 $GLOBALS['TT']->setTSlogMessage('Parsing',0);
02859                         } else {
02860                                         // Unserializing
02861                                 $storeArr = unserialize($storeArrDat);
02862                                         // Setting cache:
02863                                 $this->substMarkerCache[$storeKey] = $storeArr;
02864                                 $GLOBALS['TT']->setTSlogMessage('Cached from DB',0);
02865                         }
02866                 }
02867 
02868                         // Substitution/Merging:
02869                         // Merging content types together, resetting
02870                 $valueArr = array_merge($markContentArray,$subpartContentArray,$wrappedSubpartContentArray);
02871 
02872                 $wSCA_reg=array();
02873                 reset($storeArr['k']);
02874                 $content = '';
02875                         // traversin the keyList array and merging the static and dynamic content
02876                 while(list($n,$keyN)=each($storeArr['k']))      {
02877                         $content.=$storeArr['c'][$n];
02878                         if (!is_array($valueArr[$keyN]))        {
02879                                 $content.=$valueArr[$keyN];
02880                         } else {
02881                                 $content.=$valueArr[$keyN][(intval($wSCA_reg[$keyN])%2)];
02882                                 $wSCA_reg[$keyN]++;
02883                         }
02884                 }
02885                 $content.=$storeArr['c'][count($storeArr['k'])];
02886 
02887                 $GLOBALS['TT']->pull();
02888                 return $content;
02889         }
02890 
02902         function substituteMarkerArray($content,$markContentArray,$wrap='',$uppercase=0)        {
02903                 if (is_array($markContentArray))        {
02904                         reset($markContentArray);
02905                         $wrapArr=t3lib_div::trimExplode('|',$wrap);
02906                         while(list($marker,$markContent)=each($markContentArray))       {
02907                                 if($uppercase)  $marker=strtoupper($marker);
02908                                 if(strcmp($wrap,''))            $marker=$wrapArr[0].$marker.$wrapArr[1];
02909                                 $content=str_replace($marker,$markContent,$content);
02910                         }
02911                 }
02912                 return $content;
02913         }
02914 
02923         function substituteMarkerInObject(&$tree, $markContentArray) {
02924                 if (is_array ($tree))   {
02925                         reset($tree);
02926                         while(list($key,$value)=each($tree))    {
02927                                 $this->substituteMarkerInObject ($tree[$key], $markContentArray);
02928                         }
02929                 } else {
02930                         $tree = $this->substituteMarkerArray($tree,$markContentArray);
02931                 }
02932                 return $tree;
02933         }
02934 
02946         function fillInMarkerArray($markContentArray, $row, $fieldList='', $nl2br=TRUE, $prefix='FIELD_', $HSC=FALSE)   {
02947                 if ($fieldList) {
02948                         $fArr = t3lib_div::trimExplode(',',$fieldList,1);
02949                         foreach($fArr as $field)        {
02950                                 $markContentArray['###'.$prefix.$field.'###'] = $nl2br?nl2br($row[$field]):$row[$field];
02951                         }
02952                 } else {
02953                         if (is_array($row))     {
02954                                 foreach($row as $field => $value)       {
02955                                         if (!t3lib_div::testInt($field))        {
02956                                                 if ($HSC)       $value = htmlspecialchars($value);
02957                                                 $markContentArray['###'.$prefix.$field.'###'] = $nl2br ? nl2br($value) : $value;
02958                                         }
02959                                 }
02960                         }
02961                 }
02962 
02963                 return $markContentArray;
02964         }
02965 
02966 
02967 
02968 
02969 
02970 
02971 
02972 
02973 
02974 
02975 
02976 
02977 
02978 
02979 
02980 
02981 
02982 
02983 
02984 
02985 
02986 
02987 
02988 
02989 
02990         /***********************************************
02991          *
02992          * "stdWrap" + sub functions
02993          *
02994          ***********************************************/
02995 
02996 
03009         function stdWrap($content,$conf)        {
03010                 if (is_array($conf))    {
03011 
03012                                 // Setting current value, if so
03013                         if ($conf['setContentToCurrent']){$this->data[$this->currentValKey]=$content;}
03014                         if ($conf['setCurrent'] || $conf['setCurrent.']){$this->data[$this->currentValKey] = $this->stdWrap($conf['setCurrent'], $conf['setCurrent.']);}
03015 
03016                                 // Getting data:
03017                         if (isset($conf['lang.']) && $GLOBALS['TSFE']->config['config']['language'] && isset($conf['lang.'][$GLOBALS['TSFE']->config['config']['language']]))   {
03018                                 $content = $conf['lang.'][$GLOBALS['TSFE']->config['config']['language']];
03019                         }
03020                         if ($conf['data']){$content=$this->getData($conf['data'], is_array($this->alternativeData)?$this->alternativeData:$this->data);}
03021                                 $this->alternativeData='';              // This must be unset directly after
03022                         if ($conf['field']) {$content=$this->getFieldVal($conf['field']);}
03023                         if ($conf['current']) {$content=$this->data[$this->currentValKey];}
03024                         if ($conf['cObject']) {$content=$this->cObjGetSingle($conf['cObject'],$conf['cObject.'],'/stdWrap/.cObject');}
03025                         if ($conf['numRows.']) {$content=$this->numRows($conf['numRows.']);}
03026                         if ($conf['filelist'] || $conf['filelist.'])    {$content=$this->filelist($this->stdWrap($conf['filelist'], $conf['filelist.']));}
03027                         if ($conf['preUserFunc'])       {$content = $this->callUserFunction($conf['preUserFunc'], $conf['preUserFunc.'], $content);}
03028 
03029                                 // Overriding values, evaluating conditions
03030                         if ($conf['override'] || $conf['override.']){
03031                                 $override = $this->stdWrap($conf['override'], $conf['override.']);
03032                                 if (trim($override)) {$content=$override;}
03033                         }
03034                         if (isset($conf['preIfEmptyListNum']) || isset($conf['preIfEmptyListNum.']['stdWrap.'])) {
03035                                 $preIfEmptyListNumber = isset($conf['preIfEmptyListNum.']['stdWrap.'])  ?  $this->stdWrap($conf['preIfEmptyListNum'], $conf['preIfEmptyListNum.']['stdWrap.'])  :  $conf['preIfEmptyListNum'];
03036                                 $content=$this->listNum($content,$preIfEmptyListNumber,$conf['preIfEmptyListNum.']['splitChar']);
03037                         }
03038                         if (!trim($content) && ($conf['ifEmpty'] || $conf['ifEmpty.'])){ $content = $this->stdWrap($conf['ifEmpty'], $conf['ifEmpty.']);}
03039 
03040 
03041                                 // values...
03042                         if (isset($conf['listNum']) || isset($conf['listNum.']['stdWrap.'])) {
03043                                 $listNumber = isset($conf['listNum.']['stdWrap.'])  ?  $this->stdWrap($conf['listNum'], $conf['listNum.']['stdWrap.'])  :  $conf['listNum'];
03044                                 $content=$this->listNum($content,$listNumber,$conf['listNum.']['splitChar']);
03045                         }
03046 
03047                         if ($conf['trim'])      { $content=trim($content); }
03048 
03049                                 // Call stdWrap recursively
03050                         if ($conf['stdWrap'])   { $content=$this->stdWrap($content,$conf['stdWrap.']); }
03051 
03052                         if (   ($conf['required'] && (string)$content=='') || ($conf['if.'] && !$this->checkIf($conf['if.'])) || ($conf['fieldRequired'] && !trim($this->data[$conf['fieldRequired']]))    ){
03053                                 $content = '';
03054                         } else  {
03055                                         // Perform data processing:
03056                                 if ($conf['csConv'])    { $content=$GLOBALS['TSFE']->csConv($content,$conf['csConv']); }
03057                                 if ($conf['parseFunc.'] || $conf['parseFunc']) {$content=$this->parseFunc($content,$conf['parseFunc.'],$conf['parseFunc']);}
03058                                 if ($conf['HTMLparser'] && is_array($conf['HTMLparser.'])) {$content=$this->HTMLparser_TSbridge($content,$conf['HTMLparser.']);}
03059                                 if ($conf['split.']){$content=$this->splitObj($content,$conf['split.']);}
03060                                 if ($conf['prioriCalc']){$content=t3lib_div::calcParenthesis($content); if ($conf['prioriCalc']=='intval') $content=intval($content);}
03061                                 if ((string)$conf['char']!=''){$content=chr(intval($conf['char']));}
03062                                 if ($conf['intval']){$content=intval($content);}
03063                                 if ($conf['date']){$content=date($conf['date'], $content);}
03064                                 if ($conf['strftime']){
03065                                         $content = strftime($conf['strftime'], $content);
03066                                         $tmp_charset = $conf['strftime.']['charset'] ? $conf['strftime.']['charset'] : $GLOBALS['TSFE']->localeCharset;
03067                                         if ($tmp_charset)       {
03068                                                 $content = $GLOBALS['TSFE']->csConv($content,$tmp_charset);
03069                                         }
03070                                 }
03071                                 if ($conf['age']){$content=$this->calcAge(time()-$content,$conf['age']);}
03072 
03073                                 if ($conf['case']){$content=$this->HTMLcaseshift($content, $conf['case']);}
03074                                 if ($conf['bytes']){$content=$this->bytes($content,$conf['bytes.']['labels']);}
03075                                 if ($conf['substring']){$content=$this->substring($content,$conf['substring']);}
03076                                 if ($conf['removeBadHTML'])     {$content = $this->removeBadHTML($content, $conf['removeBadHTML.']);}
03077                                 if ($conf['stripHtml']){$content = strip_tags($content);}
03078                                 if ($conf['crop']){$content=$this->crop($content, $conf['crop']);}
03079                                 if ($conf['rawUrlEncode']){$content = rawurlencode($content);}
03080                                 if ($conf['htmlSpecialChars']){
03081                                         $content=htmlSpecialChars($content);
03082                                         if ($conf['htmlSpecialChars.']['preserveEntities'])     $content = t3lib_div::deHSCentities($content);
03083                                 }
03084 
03085                                 if ($conf['doubleBrTag']) {
03086                                         $content=ereg_replace("\r?\n[\t ]*\r?\n",$conf['doubleBrTag'],$content);
03087                                 }
03088                                 if ($conf['br']) {$content=nl2br($content);}
03089                                 if ($conf['brTag']) {$content= ereg_replace(chr(10),$conf['brTag'],$content);}
03090                                 if ($conf['encapsLines.']) {$content=$this->encaps_lineSplit($content,$conf['encapsLines.']);}
03091                                 if ($conf['keywords']) {$content= $this->keywords($content);}
03092                                 if ($conf['innerWrap'] || $conf['innerWrap.']){$content=$this->wrap($content, $this->stdWrap($conf['innerWrap'], $conf['innerWrap.']));}
03093                                 if ($conf['innerWrap2'] || $conf['innerWrap2.']){$content=$this->wrap($content, $this->stdWrap($conf['innerWrap2'], $conf['innerWrap2.']));}
03094                                 if ($conf['fontTag']){$content=$this->wrap($content, $conf['fontTag']);}
03095                                 if ($conf['addParams.']) {$content=$this->addParams($content,$conf['addParams.']);}
03096                                 if ($conf['textStyle.']) {$content=$this->textStyle($content,$conf['textStyle.']);}
03097                                 if ($conf['tableStyle.']) {$content=$this->tableStyle($content,$conf['tableStyle.']);}
03098                                 if ($conf['filelink.']) {$content=$this->filelink($content,$conf['filelink.']);}
03099                                 if ($conf['preCObject']) {$content=$this->cObjGetSingle($conf['preCObject'],$conf['preCObject.'],'/stdWrap/.preCObject').$content;}
03100                                 if ($conf['postCObject']) {$content.=$this->cObjGetSingle($conf['postCObject'],$conf['postCObject.'],'/stdWrap/.postCObject');}
03101 
03102                                 if ($conf['wrapAlign'] || $conf['wrapAlign.']){
03103                                         $wrapAlign = trim($this->stdWrap($conf['wrapAlign'], $conf['wrapAlign.']));
03104                                         if ($wrapAlign) {$content=$this->wrap($content, '<div style="text-align:'.$wrapAlign.';">|</div>');}
03105                                 }
03106                                 if ($conf['typolink.']){$content=$this->typolink($content, $conf['typolink.']);}
03107 
03108                                         // Spacing
03109                                 if ($conf['space']){$content=$this->wrapSpace($content, $conf['space']);}
03110                                 $spaceBefore = '';
03111                                 if ($conf['spaceBefore'] || $conf['spaceBefore.'])      {$spaceBefore = trim($this->stdWrap($conf['spaceBefore'], $conf['spaceBefore.']));}
03112                                 $spaceAfter = '';
03113                                 if ($conf['spaceAfter'] || $conf['spaceAfter.'])        {$spaceAfter = trim($this->stdWrap($conf['spaceAfter'], $conf['spaceAfter.']));}
03114                                 if ($spaceBefore || $spaceAfter)        {$content=$this->wrapSpace($content, $spaceBefore.'|'.$spaceAfter);}
03115 
03116                                         // Wraps
03117                                 if ($conf['wrap']){$content=$this->wrap($content, $conf['wrap'], ($conf['wrap.']['splitChar']?$conf['wrap.']['splitChar']:'|'));}
03118                                 if ($conf['noTrimWrap']){$content=$this->noTrimWrap($content, $conf['noTrimWrap']);}
03119                                 if ($conf['wrap2']){$content=$this->wrap($content, $conf['wrap2'], ($conf['wrap.']['splitChar']?$conf['wrap.']['splitChar']:'|'));}
03120                                 if ($conf['dataWrap']){$content=$this->dataWrap($content, $conf['dataWrap']);}
03121                                 if ($conf['prepend']){$content=$this->cObjGetSingle($conf['prepend'],$conf['prepend.'],'/stdWrap/.prepend').$content;}
03122                                 if ($conf['append']){$content.=$this->cObjGetSingle($conf['append'],$conf['append.'],'/stdWrap/.append');}
03123                                 if ($conf['wrap3']){$content=$this->wrap($content, $conf['wrap3'], ($conf['wrap.']['splitChar']?$conf['wrap.']['splitChar']:'|'));}
03124                                 if ($conf['outerWrap'] || $conf['outerWrap.']){$content=$this->wrap($content, $this->stdWrap($conf['outerWrap'], $conf['outerWrap.']));}
03125                                 if ($conf['insertData'])        {$content = $this->insertData($content);}
03126                                 if ($conf['offsetWrap']){
03127                                         $controlTable = t3lib_div::makeInstance('tslib_tableOffset');
03128                                         if ($conf['offsetWrap.']['tableParams'] || $conf['offsetWrap.']['tableParams.'])        {$controlTable->tableParams = $this->stdWrap($conf['offsetWrap.']['tableParams'], $conf['offsetWrap.']['tableParams.']);}
03129                                         if ($conf['offsetWrap.']['tdParams'] || $conf['offsetWrap.']['tdParams.'])      {$controlTable->tdParams = ' '.$this->stdWrap($conf['offsetWrap.']['tdParams'], $conf['offsetWrap.']['tdParams.']);}
03130                                         $content=$controlTable->start($content,$conf['offsetWrap']);
03131                                         if ($conf['offsetWrap.']['stdWrap.'])   {       $content=$this->stdWrap($content,$conf['offsetWrap.']['stdWrap.']);     }
03132                                 }
03133                                 if ($conf['postUserFunc'])      {$content = $this->callUserFunction($conf['postUserFunc'], $conf['postUserFunc.'], $content);}
03134                                 if ($conf['postUserFuncInt'])   {
03135                                         $substKey = 'INT_SCRIPT.'.$GLOBALS['TSFE']->uniqueHash();
03136                                         $GLOBALS['TSFE']->config['INTincScript'][$substKey] = array(
03137                                                 'content' => $content,
03138                                                 'postUserFunc' => $conf['postUserFuncInt'],
03139                                                 'conf' => $conf['postUserFuncInt.'],
03140                                                 'type' => 'POSTUSERFUNC',
03141                                                 'cObj' => serialize($this),
03142                                         );
03143                                         $content ='<!--'.$substKey.'-->';
03144                                 }
03145                                         // Various:
03146                                 if ($conf['prefixComment'] && !$GLOBALS['TSFE']->config['config']['disablePrefixComment'])      {$content = $this->prefixComment($conf['prefixComment'], $conf['prefixComment.'], $content);}
03147 
03148                                 if ($conf['editIcons'] && $GLOBALS['TSFE']->beUserLogin){$content=$this->editIcons($content,$conf['editIcons'],$conf['editIcons.']);}
03149                                 if ($conf['editPanel'] && $GLOBALS['TSFE']->beUserLogin){$content=$this->editPanel($content, $conf['editPanel.']);}
03150                         }
03151 
03152                                 //Debug:
03153                         if ($conf['debug'])     {$content = '<pre>'.htmlspecialchars($content).'</pre>';}
03154                         if ($conf['debugFunc']) {debug($conf['debugFunc']==2?array($content):$content);}
03155                         if ($conf['debugData']) {
03156                                 echo '<b>$cObj->data:</b>';
03157                                 debug($this->data,'$cObj->data:');
03158                                 if (is_array($this->alternativeData))   {
03159                                         echo '<b>$cObj->alternativeData:</b>';
03160                                         debug($this->alternativeData,'$this->alternativeData');
03161                                 }
03162                         }
03163                 }
03164                 return $content;
03165         }
03166 
03178         function numRows($conf) {
03179                 $conf['select.']['selectFields'] = 'count(*)';
03180 
03181                 $res = $this->exec_getQuery($conf['table'],$conf['select.']);
03182 
03183                 if ($error = $GLOBALS['TYPO3_DB']->sql_error()) {
03184                         $GLOBALS['TT']->setTSlogMessage($error,3);
03185                 } else {
03186                         $row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
03187                         return intval($row[0]);
03188                 }
03189         }
03190 
03199         function listNum($content,$listNum,$char) {
03200                 $char = $char ? $char : ',';
03201                 if (t3lib_div::testInt($char))  {
03202                         $char = chr($char);
03203                 }
03204                 $temp = explode($char,$content);
03205                 $last = ''.(count($temp)-1);
03206                 $index=$this->calc(eregi_replace('last',$last,$listNum));
03207                 return $temp[$index];
03208         }
03209 
03219         function checkIf($conf) {
03220                 if (!is_array($conf))   {return true;}
03221                 if (isset($conf['directReturn']))       {return $conf['directReturn'] ? 1 : 0;}
03222                 $flag = true;
03223                         if (isset($conf['isTrue']) || isset($conf['isTrue.']))  {
03224                                 $isTrue = trim($this->stdWrap($conf['isTrue'],$conf['isTrue.']));
03225                                 if (!$isTrue)   {
03226                                         $flag=0;
03227                                 }
03228                         }
03229                         if (isset($conf['isFalse']) || isset($conf['isFalse.']))        {
03230                                 $isFalse = trim($this->stdWrap($conf['isFalse'],$conf['isFalse.']));
03231                                 if ($isFalse)   {
03232                                         $flag=0;
03233                                 }
03234                         }
03235                         if (isset($conf['isPositive']) || isset($conf['isPositive.']))  {
03236                                 $number = $this->calc($this->stdWrap($conf['isPositive'],$conf['isPositive.']));
03237                                 if ($number<1)  {
03238                                         $flag=0;
03239                                 }
03240                         }
03241                         if ($flag)      {
03242                                 $value = trim($this->stdWrap($conf['value'],$conf['value.']));
03243 
03244                                 if (isset($conf['isGreaterThan']) || isset($conf['isGreaterThan.']))    {
03245                                         $number = trim($this->stdWrap($conf['isGreaterThan'],$conf['isGreaterThan.']));
03246                                         if ($number<=$value)    {
03247                                                 $flag=0;
03248                                         }
03249                                 }
03250                                 if (isset($conf['isLessThan']) || isset($conf['isLessThan.']))  {
03251                                         $number = trim($this->stdWrap($conf['isLessThan'],$conf['isLessThan.']));
03252                                         if ($number>=$value)    {
03253                                                 $flag=0;
03254                                         }
03255                                 }
03256                                 if (isset($conf['equals']) || isset($conf['equals.']))  {
03257                                         $number = trim($this->stdWrap($conf['equals'],$conf['equals.']));
03258                                         if ($number!=$value)    {
03259                                                 $flag=0;
03260                                         }
03261                                 }
03262                                 if (isset($conf['isInList']) || isset($conf['isInList.']))      {
03263                                         $number = trim($this->stdWrap($conf['isInList'],$conf['isInList.']));
03264                                         if (!t3lib_div::inList($value,$number)) {
03265                                                 $flag=0;
03266                                         }
03267                                 }
03268                         }
03269                 if ($conf['negate'])    {$flag = $flag ? 0 : 1;}
03270                 return $flag;
03271         }
03272 
03282         function filelist($data)        {
03283                 $data = trim($data);
03284                 if ($data)      {
03285                         $data_arr = explode('|',$data);
03286                                 // read directory:
03287                         if ($GLOBALS['TSFE']->lockFilePath)     {               // MUST exist!
03288                                 $path = $this->clean_directory($data_arr[0]);   // Cleaning name..., only relative paths accepted.
03289                                 $path = substr($path,0,strlen($GLOBALS['TSFE']->lockFilePath))==$GLOBALS['TSFE']->lockFilePath ? $path : '';
03290                         }
03291                         if ($path)      {
03292                                 $items = Array('files'=>array(), 'sorting'=>array());
03293                                 $ext_list = strtolower(t3lib_div::uniqueList($data_arr[1]));
03294                                 $sorting = trim($data_arr[2]);
03295                                         // read dir:
03296                                 $d = @dir($path);
03297                                 $tempArray=Array();
03298                                 if (is_object($d))      {
03299                                         $count=0;
03300                                         while($entry=$d->read()) {
03301                                                 if ($entry!='.' && $entry!='..')        {
03302                                                         $wholePath = $path.'/'.$entry;          // Because of odd PHP-error where  <br />-tag is sometimes placed after a filename!!
03303                                                         if (@file_exists($wholePath) && filetype($wholePath)=='file')   {
03304                                                                 $info = t3lib_div::split_fileref($wholePath);
03305                                                                 if (!$ext_list || t3lib_div::inList($ext_list,$info['fileext']))        {
03306                                                                         $items['files'][] = $info['file'];
03307                                                                         switch($sorting)        {
03308                                                                                 case 'name':
03309                                                                                         $items['sorting'][] = strtolower($info['file']);
03310                                                                                 break;
03311                                                                                 case 'size':
03312                                                                                         $items['sorting'][] = filesize($wholePath);
03313                                                                                 break;
03314                                                                                 case 'ext':
03315                                                                                         $items['sorting'][] = $info['fileext'];
03316                                                                                 break;
03317                                                                                 case 'date':
03318                                                                                         $items['sorting'][] = filectime($wholePath);
03319                                                                                 break;
03320                                                                                 default:
03321                                                                                         $items['sorting'][] = $count;
03322                                                                                 break;
03323                                                                         }
03324                                                                         $count++;
03325                                                                 }
03326                                                         }
03327                                                 }
03328                                         }
03329                                         $d->close();
03330                                 }
03331                                         // Sort if required
03332                                 if (count($items['sorting']))   {
03333                                         if (strtolower(trim($data_arr[3]))!='r')        {
03334                                                 asort($items['sorting']);
03335                                         } else {
03336                                                 arsort($items['sorting']);
03337                                         }
03338                                 }
03339                                 if (count($items['files']))     {
03340                                                 // make list
03341                                         reset($items['sorting']);
03342                                         $fullPath = trim($data_arr[4]);
03343                                         $list_arr=Array();
03344                                         while(list($key,)=each($items['sorting']))      {
03345                                                 $list_arr[]=  $fullPath ? $path.'/'.$items['files'][$key] : $items['files'][$key];
03346                                         }
03347                                         return implode(',',$list_arr);
03348                                 }
03349                         }
03350                 }
03351         }
03352 
03361         function clean_directory($theDir)       {
03362                 if (t3lib_div::validPathStr($theDir))   {               // proceeds if no '//', '..' or '\' is in the $theFile
03363                         $theDir = ereg_replace("[\/\. ]*$",'',$theDir);         // Removes all dots, slashes and spaces after a path...
03364                         if (!t3lib_div::isAbsPath($theDir) && @is_dir($theDir)) {
03365                                 return $theDir;
03366                         }
03367                 }
03368         }
03369 
03379         function HTMLparser_TSbridge($theValue, $conf)  {
03380                 $htmlParser = t3lib_div::makeInstance('t3lib_parsehtml');
03381                 $htmlParserCfg =  $htmlParser->HTMLparserConfig($conf);
03382                 return $htmlParser->HTMLcleaner($theValue,$htmlParserCfg[0],$htmlParserCfg[1],$htmlParserCfg[2],$htmlParserCfg[3]);
03383         }
03384 
03393         function dataWrap($content,$wrap)       {
03394                 return $this->wrap($content,$this->insertData($wrap));
03395         }
03396 
03406         function insertData($str)       {
03407                 $inside=0;
03408                 $newVal='';
03409                 $pointer=0;
03410                 $totalLen = strlen($str);
03411                 do      {
03412                         if (!$inside)   {
03413                                 $len = strcspn(substr($str,$pointer),'{');
03414                                 $newVal.= substr($str,$pointer,$len);
03415                                 $inside = 1;
03416                         } else {
03417                                 $len = strcspn(substr($str,$pointer),'}')+1;
03418                                 $newVal.= $this->getData(substr($str,$pointer+1,$len-2),$this->data);
03419                                 $inside = 0;
03420                         }
03421                         $pointer+=$len;
03422                 } while($pointer<$totalLen);
03423                 return $newVal;
03424         }
03425 
03436         function prefixComment($str,$conf,$content)     {
03437                 $parts = explode('|',$str);
03438 
03439                 $output =
03440                         chr(10).str_pad('',$parts[0],chr(9)).
03441                         '<!-- '.htmlspecialchars($this->insertData($parts[1])).' [begin] -->'.
03442                         chr(10).str_pad('',$parts[0]+1,chr(9)).
03443                                 $content.
03444                         chr(10).str_pad('',$parts[0],chr(9)).
03445                         '<!-- '.htmlspecialchars($this->insertData($parts[1])).' [end] -->'.
03446                         chr(10).str_pad('',$parts[0]+1,chr(9));
03447 
03448                 return $output;
03449         }
03450 
03460         function substring($content,$options)   {
03461                 $options = t3lib_div::intExplode(',',$options.',');
03462                 if ($options[1])        {
03463                         return $GLOBALS['TSFE']->csConvObj->substr($GLOBALS['TSFE']->renderCharset,$content,$options[0],$options[1]);
03464                 } else {
03465                         return $GLOBALS['TSFE']->csConvObj->substr($GLOBALS['TSFE']->renderCharset,$content,$options[0]);
03466                 }
03467         }
03468 
03478         function crop($content,$options)        {
03479                 $options = explode('|',$options);
03480                 $chars = intval($options[0]);
03481                 $afterstring = trim($options[1]);
03482                 $crop2space = trim($options[2]);
03483                 if ($chars)     {
03484                         if (strlen($content)>abs($chars))       {
03485                                 if ($chars<0)   {
03486                                         $content = $GLOBALS['TSFE']->csConvObj->substr($GLOBALS['TSFE']->renderCharset,$content,$chars);
03487                                         $trunc_at = strpos($content, ' ');
03488                                         $content = ($trunc_at&&$crop2space) ? $afterstring.substr($content,$trunc_at) : $afterstring.$content;
03489                                 } else {
03490                                         $content = $GLOBALS['TSFE']->csConvObj->substr($GLOBALS['TSFE']->renderCharset,$content,0,$chars);
03491                                         $trunc_at = strrpos($content, ' ');
03492                                         $content = ($trunc_at&&$crop2space) ? substr($content, 0, $trunc_at).$afterstring : $content.$afterstring;
03493                                 }
03494                         }
03495                 }
03496                 return $content;
03497         }
03498 
03510         function removeBadHTML($text, $conf)    {
03511 
03512                         // Copyright 2002-2003 Thomas Bley
03513                 $text = preg_replace(
03514                         array(
03515                                 "'<script[^>]*?>.*?</script[^>]*?>'si",
03516                                 "'<applet[^>]*?>.*?</applet[^>]*?>'si",
03517                                 "'<object[^>]*?>.*?</object[^>]*?>'si",
03518                                 "'<iframe[^>]*?>.*?</iframe[^>]*?>'si",
03519                                 "'<frameset[^>]*?>.*?</frameset[^>]*?>'si",
03520                                 "'<style[^>]*?>.*?</style[^>]*?>'si",
03521                                 "'<marquee[^>]*?>.*?</marquee[^>]*?>'si",
03522                                 "'<script[^>]*?>'si",
03523                                 "'<meta[^>]*?>'si",
03524                                 "'<base[^>]*?>'si",
03525                                 "'<applet[^>]*?>'si",
03526                                 "'<object[^>]*?>'si",
03527                                 "'<link[^>]*?>'si",
03528                                 "'<iframe[^>]*?>'si",
03529                                 "'<frame[^>]*?>'si",
03530                                 "'<frameset[^>]*?>'si",
03531                                 "'<input[^>]*?>'si",
03532                                 "'<form[^>]*?>'si",
03533                                 "'<embed[^>]*?>'si",
03534                                 "'background-image:url'si",
03535                                 "'<\w+.*?(onabort|onbeforeunload|onblur|onchange|onclick|ondblclick|ondragdrop|onerror|onfilterchange|onfocus|onhelp|onkeydown|onkeypress|onkeyup|onload|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|onmove|onreadystatechange|onreset|onresize|onscroll|onselect|onselectstart|onsubmit|onunload).*?>'si",
03536                         ), '', $text);
03537 
03538                         $text = eregi_replace('<a[^>]*href[[:space:]]*=[[:space:]]*["\']?[[:space:]]*javascript[^>]*','',$text);
03539 
03540                         // Return clean content
03541                 return $text;
03542         }
03543 
03554         function textStyle($theValue, $conf) {
03555                 $conf['face.'][1] = 'Times New Roman';
03556                 $conf['face.'][2] = 'Verdana,Arial,Helvetica,Sans serif';
03557                 $conf['face.'][3] = 'Arial,Helvetica,Sans serif';
03558 
03559                 $conf['size.'][1] = 1;
03560                 $conf['size.'][2] = 2;
03561                 $conf['size.'][3] = 3;
03562                 $conf['size.'][4] = 4;
03563                 $conf['size.'][5] = 5;
03564                 $conf['size.'][10] = '+1';
03565                 $conf['size.'][11] = '-1';
03566 
03567                 $conf['color.'][240] = 'black';
03568                 $conf['color.'][241] = 'white';
03569                 $conf['color.'][242] = '#333333';
03570                 $conf['color.'][243] = 'gray';
03571                 $conf['color.'][244] = 'silver';
03572                 $conf['color.'][245] = 'red';
03573                 $conf['color.'][246] = 'navy';
03574                 $conf['color.'][247] = 'yellow';
03575                 $conf['color.'][248] = 'green';
03576                 $conf['color.'][249] = 'olive';
03577                 $conf['color.'][250] = 'maroon';
03578 
03579                 $face = $this->data[$conf['face.']['field']];
03580                 $size = $this->data[$conf['size.']['field']];
03581                 $color = $this->data[$conf['color.']['field']];
03582                 $align = $this->data[$conf['align.']['field']];
03583                 $properties = $this->data[$conf['properties.']['field']];
03584                 if (!$properties)       {
03585                         $properties=$this->stdWrap($conf['properties.']['default'],$conf['properties.']['default.']);
03586                 }
03587 
03588                         // properties
03589                 if (($properties&8))    {$theValue=$this->HTMLcaseshift($theValue, 'upper');}
03590                 if (($properties&1))    {$theValue='<b>'.$theValue.'</b>';}
03591                 if (($properties&2))    {$theValue='<i>'.$theValue.'</i>';}
03592                 if (($properties&4))    {$theValue='<u>'.$theValue.'</u>';}
03593 
03594                         // Fonttag
03595                 $theFace = $conf['face.'][$face] ? $conf['face.'][$face] : $this->stdWrap($conf['face.']['default'],$conf['face.']['default.']);
03596                 $theSize = $conf['size.'][$size] ? $conf['size.'][$size] : $this->stdWrap($conf['size.']['default'],$conf['size.']['default.']);
03597                 $theColor = $conf['color.'][$color] ? $conf['color.'][$color] : $this->stdWrap($conf['color.']['default'],$conf['color.']['default.']);
03598 
03599                 if ($conf['altWrap'])   {
03600                         $theValue=$this->wrap($theValue, $conf['altWrap']);
03601                 } elseif ($theFace || $theSize || $theColor)    {
03602                         $fontWrap = '<font'.($theFace?' face="'.$theFace.'"':'').($theSize?' size="'.$theSize.'"':'').($theColor?' color="'.$theColor.'"':'').'>|</font>';
03603                         $theValue=$this->wrap($theValue, $fontWrap);
03604                 }
03605                         // align
03606                 if ($align)     {$theValue=$this->wrap($theValue, '<div style="text-align:'.$align.';">|</div>');}
03607                         // return
03608                 return $theValue;
03609         }
03610 
03621         function tableStyle($theValue, $conf) {
03622                 $conf['color.'][240] = 'black';
03623                 $conf['color.'][241] = 'white';
03624                 $conf['color.'][242] = '#333333';
03625                 $conf['color.'][243] = 'gray';
03626                 $conf['color.'][244] = 'silver';
03627 
03628                 $align = $this->stdWrap($conf['align'],$conf['align.']);
03629                 $border = intval($this->stdWrap($conf['border'],$conf['border.']));
03630                 $cellspacing = intval($this->stdWrap($conf['cellspacing'],$conf['cellspacing.']));
03631                 $cellpadding = intval($this->stdWrap($conf['cellpadding'],$conf['cellpadding.']));
03632 
03633                 $color = $this->data[$conf['color.']['field']];
03634                 $theColor = $conf['color.'][$color] ? $conf['color.'][$color] : $conf['color.']['default'];
03635                         // Assembling the table tag
03636                 $tableTagArray = Array('<table');
03637                 $tableTagArray[]='border="'.$border.'"';
03638                 $tableTagArray[]='cellspacing="'.$cellspacing.'"';
03639                 $tableTagArray[]='cellpadding="'.$cellpadding.'"';
03640                 if ($align)     {$tableTagArray[]='align="'.$align.'"';}
03641                 if ($theColor)  {$tableTagArray[]='bgcolor="'.$theColor.'"';}
03642 
03643                 if ($conf['params'])    {
03644                         $tableTagArray[] = $conf['params'];
03645                 }
03646 
03647                 $tableWrap = implode(' ',$tableTagArray).'> | </table>';
03648                 $theValue=$this->wrap($theValue, $tableWrap);
03649                         // return
03650                 return $theValue;
03651         }
03652 
03662         function addParams($content,$conf) {
03663                 $lowerCaseAttributes = TRUE;    // For XHTML compliance.
03664 
03665                 if (!is_array($conf))   { return $content; }
03666 
03667                 $key = 1;
03668                 $parts = explode('<',$content);
03669                 if (intval($conf['_offset']))   $key = intval($conf['_offset'])<0 ? count($parts)+intval($conf['_offset']) : intval($conf['_offset']);
03670                 $subparts=explode('>',$parts[$key]);
03671                 if (trim($subparts[0])) {
03672                                 // Get attributes and name
03673                         $attribs = t3lib_div::get_tag_attributes('<'.$subparts[0].'>');
03674                         if (!is_array($attribs))        {$attribs=array();}
03675                         list($tagName) = explode(' ',$subparts[0],2);
03676                                 // adds/overrides attributes
03677                         reset($conf);
03678                         while(list($pkey,$val)=each($conf))     {
03679                                 if (substr($pkey,-1)!='.' && substr($pkey,0,1)!='_')    {
03680                                         $tmpVal=$this->stdWrap($conf[$pkey],$conf[$pkey.'.']);
03681                                         if ($lowerCaseAttributes)       { $pkey = strtolower($pkey); }
03682                                         if (strcmp($tmpVal,'')) {$attribs[$pkey]=$tmpVal;}
03683                                 }
03684                         }
03685 
03686                                 // Re-assembles the tag and content
03687                         $subparts[0]=trim($tagName.' '.t3lib_div::implodeAttributes($attribs));
03688                         $parts[$key] = implode('>',$subparts);
03689                         $content = implode('<',$parts);
03690                 }
03691                 return $content;
03692         }
03693 
03705         function filelink($theValue, $conf)     {
03706                 $output = '';
03707                 $aTagParams = $GLOBALS['TSFE']->ATagParams.($conf['ATagParams']?' '.$conf['ATagParams']:'');
03708                 $initP = '?id='.$GLOBALS['TSFE']->id.'&type='.$GLOBALS['TSFE']->type;
03709                 $conf['path'] = $this->stdWrap($conf['path'],$conf['path.']);
03710                 $theFile = trim($conf['path']).$theValue;
03711                 if (@is_file($theFile)) {
03712                         $theFileEnc = str_replace('%2F', '/', rawurlencode($theFile));
03713                         $locDataAdd = $conf['jumpurl.']['secure'] ? $this->locDataJU($theFileEnc,$conf['jumpurl.']['secure.']) : '';
03714                         $url = ($conf['jumpurl']) ? $GLOBALS['TSFE']->config['mainScript'].$initP.'&jumpurl='.rawurlencode($theFileEnc).$locDataAdd.$GLOBALS['TSFE']->getMethodUrlIdToken : $theFileEnc;                // && $GLOBALS['TSFE']->config['config']['jumpurl_enable']
03715                         $theLinkWrap = '<a href="'.htmlspecialchars($GLOBALS['TSFE']->absRefPrefix.$url).'"'.($conf['target']?' target="'.$conf['target'].'"':'').$aTagParams.'>|</a>';
03716 
03717                         $theSize = filesize($theFile);
03718                         $fI = t3lib_div::split_fileref($theFile);
03719                         if ($conf['icon'])      {
03720                                 $iconP = 't3lib/gfx/fileicons/';
03721                                 $icon = @is_file($iconP.$fI['fileext'].'.gif') ? $iconP.$fI['fileext'].'.gif' : $iconP.'default.gif';
03722                                         // Checking for images: If image, then return link to thumbnail.
03723                                 $IEList = $this->stdWrap($conf['icon_image_ext_list'],$conf['icon_image_ext_list.']);
03724                                 $image_ext_list = str_replace(' ','',strtolower($IEList));
03725                                 if ($fI['fileext'] && t3lib_div::inList($image_ext_list, $fI['fileext']))       {
03726                                         if ($conf['iconCObject'])       {
03727                                                 $icon = $this->cObjGetSingle($conf['iconCObject'],$conf['iconCObject.'],'iconCObject');
03728                                         } else {
03729                                                 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails'])   {
03730                                                         $thumbSize = '';
03731                                                         if ($conf['icon_thumbSize'] || $conf['icon_thumbSize.'])        { $thumbSize = '&size='.$this->stdWrap($conf['icon_thumbSize'], $conf['icon_thumbSize.']); }
03732                                                         $icon = 't3lib/thumbs.php?&dummy='.$GLOBALS['EXEC_TIME'].'&file='.rawurlencode('../'.$theFile).$thumbSize;
03733                                                 } else {
03734                                                         $icon = 't3lib/gfx/notfound_thumb.gif';
03735                                                 }
03736                                                 $icon = '<img src="'.htmlspecialchars($GLOBALS['TSFE']->absRefPrefix.$icon).'"'.$this->getBorderAttr(' border="0"').''.$this->getAltParam($conf).' />';
03737                                         }
03738                                 } else {
03739                                         $icon = '<img src="'.htmlspecialchars($GLOBALS['TSFE']->absRefPrefix.$icon).'" width="18" height="16"'.$this->getBorderAttr(' border="0"').''.$this->getAltParam($conf).' />';
03740                                 }
03741                                 if ($conf['icon_link']) {$icon = $this->wrap($icon, $theLinkWrap);}
03742                                 $icon = $this->stdWrap($icon,$conf['icon.']);
03743                         }
03744                         if ($conf['size'])      {
03745                                 $size = $this->stdWrap($theSize,$conf['size.']);
03746                         }
03747 
03748                                 // Wrapping file label
03749                         if ($conf['removePrependedNumbers']) $theValue=ereg_replace('_[0-9][0-9](\.[[:alnum:]]*)$','\1',$theValue);
03750                         $theValue = $this->stdWrap($theValue,$conf['labelStdWrap.']);
03751 
03752                                 // Wrapping file
03753                         if ($conf['ATagBeforeWrap'])    {
03754                                 $theValue = $this->wrap($this->wrap($theValue, $conf['wrap']), $theLinkWrap);
03755                         } else {
03756                                 $theValue = $this->wrap($this->wrap($theValue, $theLinkWrap), $conf['wrap']);
03757                         }
03758                         $file = $this->stdWrap($theValue,$conf['file.']);
03759                                 // output
03760                         return $this->stdWrap($icon.$file.$size, $conf['stdWrap.']);
03761                 }
03762         }
03763 
03774         function locDataJU($jumpUrl,$conf)      {
03775                 $fI = pathinfo($jumpUrl);
03776                 $mimetype='';
03777                 if ($fI['extension'])   {
03778                         $mimeTypes = t3lib_div::trimExplode(',',$conf['mimeTypes'],1);
03779                         reset($mimeTypes);
03780                         while(list(,$v)=each($mimeTypes))       {
03781                                 $parts = explode('=',$v,2);
03782                                 if (strtolower($fI['extension']) == strtolower(trim($parts[0])))        {
03783                                         $mimetype = '&mimeType='.rawurlencode(trim($parts[1]));
03784                                 }
03785                         }
03786                 }
03787                 $locationData = $GLOBALS['TSFE']->id.':'.$this->currentRecord;
03788                 $rec='&locationData='.rawurlencode($locationData);
03789                 $hArr = array(
03790                         $jumpUrl,
03791                         $locationData,
03792                         $GLOBALS['TSFE']->TYPO3_CONF_VARS['SYS']['encryptionKey']
03793                 );
03794                 $juHash='&juHash='.t3lib_div::shortMD5(serialize($hArr));
03795                 return '&juSecure=1'.$mimetype.$rec.$juHash;
03796         }
03797 
03805         function calc($val)     {
03806                 $parts= t3lib_div::splitCalc($val,'+-*/');
03807                 $value=0;
03808                 reset($parts);
03809                 while(list(,$part)=each($parts))        {
03810                         $theVal = $part[1];
03811                         $sign =  $part[0];
03812                         if ((string)intval($theVal)==(string)$theVal)   {
03813                                 $theVal = intval($theVal);
03814                         } else {
03815                                 $theVal =0;
03816                         }
03817                         if ($sign=='-') {$value-=$theVal;}
03818                         if ($sign=='+') {$value+=$theVal;}
03819                         if ($sign=='/') {if (intval($theVal)) $value/=intval($theVal);}
03820                         if ($sign=='*') {$value*=$theVal;}
03821                 }
03822                 return $value;
03823         }
03824 
03834         function calcIntExplode($delim, $string)        {
03835                 $temp = explode($delim,$string);
03836                 while(list($key,$val)=each($temp))      {
03837                         $temp[$key]=intval(tslib_cObj::calc($val));
03838                 }
03839                 return $temp;
03840         }
03841 
03854         function splitObj($value, $conf)        {
03855                 $conf['token']=$this->stdWrap($conf['token'],$conf['token.']);
03856 
03857                 if ($conf['token'])     {
03858                         $conf['max']=intval($this->stdWrap($conf['max'],$conf['max.']));
03859                         $conf['min']=intval($this->stdWrap($conf['min'],$conf['min.']));
03860 
03861                         $valArr=explode($conf['token'],$value);
03862                                 // calculate splitCount
03863                         $splitCount = count($valArr);
03864                         if ($conf['max'] && $splitCount>$conf['max']) {
03865                                 $splitCount=$conf['max'];
03866                         }
03867                         if ($conf['min'] && $splitCount<$conf['min']) {
03868                                 $splitCount=$conf['min'];
03869                         }
03870 
03871                         if ($conf['wrap'] || $conf['cObjNum']) {
03872                                 $splitArr=array();
03873                                 $splitArr['wrap']=$conf['wrap'];
03874                                 $splitArr['cObjNum']=$conf['cObjNum'];
03875                                 $splitArr = $GLOBALS['TSFE']->tmpl->splitConfArray($splitArr,$splitCount);
03876                         }
03877 
03878                         $content='';
03879                         for($a=0;$a<$splitCount;$a++)   {
03880                                 $GLOBALS['TSFE']->register['SPLIT_COUNT']=$a;
03881                                 $value = ''.$valArr[$a];
03882                                 $this->data[$this->currentValKey] = $value;
03883                                 if ($splitArr[$a]['cObjNum']) {
03884                                         $objName=intval($splitArr[$a]['cObjNum']);
03885                                         $value = $this->stdWrap($this->cObjGet($conf[$objName.'.'],$objName.'.'),$conf[$objName.'.']);
03886                                 }
03887                                 if ($splitArr[$a]['wrap']) {
03888                                         $value=$this->wrap($value,$splitArr[$a]['wrap']);
03889                                 }
03890                                 $content.=$value;
03891                         }
03892                 }
03893                 return $content;
03894         }
03895 
03910         function parseFunc($theValue, $conf, $ref='') {
03911 
03912                         // Fetch / merge reference, if any
03913                 if ($ref)       {
03914                         $temp_conf = array(
03915                                                                 'parseFunc' => $ref,
03916                                                                 'parseFunc.' => $conf
03917                                                         );
03918                         $temp_conf = $this->mergeTSRef($temp_conf, 'parseFunc');
03919                         $conf = $temp_conf['parseFunc.'];
03920                 }
03921 
03922                         // Process:
03923                 if (strcmp($conf['externalBlocks'],'')) {
03924                         $tags = strtolower(implode(',',t3lib_div::trimExplode(',',$conf['externalBlocks'])));
03925                         $htmlParser = t3lib_div::makeInstance('t3lib_parsehtml');
03926                         $parts = $htmlParser->splitIntoBlock($tags,$theValue);
03927 
03928                         reset($parts);
03929                         while(list($k,$v)=each($parts)) {
03930                                 if ($k%2)       {       // font:
03931                                         $tagName=strtolower($htmlParser->getFirstTagName($v));
03932                                         $cfg=$conf['externalBlocks.'][$tagName.'.'];
03933                                         if ($cfg['stripNLprev'] || $cfg['stripNL'])     {
03934                                                 $parts[$k-1]=ereg_replace(chr(13).'?'.chr(10).'[ ]*$', '', $parts[$k-1]);
03935                                         }
03936                                         if ($cfg['stripNLnext'] || $cfg['stripNL'])     {
03937                                                 $parts[$k+1]=ereg_replace('^[ ]*'.chr(13).'?'.chr(10), '', $parts[$k+1]);
03938                                         }
03939                                 }
03940                         }
03941 
03942                         reset($parts);
03943                         while(list($k,$v)=each($parts)) {
03944                                 if ($k%2)       {
03945                                         $tag=$htmlParser->getFirstTag($v);
03946                                         $tagName=strtolower($htmlParser->getFirstTagName($v));
03947                                         $cfg=$conf['externalBlocks.'][$tagName.'.'];
03948                                         if ($cfg['callRecursive'])      {
03949                                                 $parts[$k]=$this->parseFunc($htmlParser->removeFirstAndLastTag($v), $conf);
03950                                                 if (!$cfg['callRecursive.']['dontWrapSelf'])    {
03951                                                         if ($cfg['callRecursive.']['alternativeWrap'])  {
03952                                                                 $parts[$k] = $this->wrap($parts[$k], $cfg['callRecursive.']['alternativeWrap']);
03953                                                         } else {
03954                                                                 if (is_array($cfg['callRecursive.']['tagStdWrap.']))    {
03955                                                                         $tag = $this->stdWrap($tag,$cfg['callRecursive.']['tagStdWrap.']);
03956                                                                 }
03957                                                                 $parts[$k]=$tag.$parts[$k].'</'.$tagName.'>';
03958                                                         }
03959                                                 }
03960                                         } elseif($cfg['HTMLtableCells']) {
03961                                                 $rowParts = $htmlParser->splitIntoBlock('tr',$parts[$k]);
03962                                                 reset($rowParts);
03963                                                 while(list($kk,$vv)=each($rowParts))    {
03964                                                         if ($kk%2)      {
03965                                                                 $colParts = $htmlParser->splitIntoBlock('td',$vv);
03966                                                                 reset($colParts);
03967                                                                 $cc=0;
03968                                                                 while(list($kkk,$vvv)=each($colParts))  {
03969                                                                         if ($kkk%2)     {
03970                                                                                 $cc++;
03971                                                                                 $tag=$htmlParser->getFirstTag($vvv);
03972                                                                                 $tagName=strtolower($htmlParser->getFirstTagName($vvv));
03973                                                                                 $colParts[$kkk] = $htmlParser->removeFirstAndLastTag($vvv);
03974 
03975                                                                                 if ($cfg['HTMLtableCells.'][$cc.'.']['callRecursive'] || (!isset($cfg['HTMLtableCells.'][$cc.'.']['callRecursive']) && $cfg['HTMLtableCells.']['default.']['callRecursive']))   {
03976                                                                                         if ($cfg['HTMLtableCells.']['addChr10BetweenParagraphs'])       $colParts[$kkk]=str_replace('</p><p>','</p>'.chr(10).'<p>',$colParts[$kkk]);
03977                                                                                         $colParts[$kkk] = $this->parseFunc($colParts[$kkk], $conf);
03978                                                                                 }
03979 
03980                                                                                 $tagStdWrap = is_array($cfg['HTMLtableCells.'][$cc.'.']['tagStdWrap.'])?$cfg['HTMLtableCells.'][$cc.'.']['tagStdWrap.']:$cfg['HTMLtableCells.']['default.']['tagStdWrap.'];
03981                                                                                 if (is_array($tagStdWrap))      {
03982                                                                                         $tag = $this->stdWrap($tag,$tagStdWrap);
03983                                                                                 }
03984 
03985                                                                                 $stdWrap = is_array($cfg['HTMLtableCells.'][$cc.'.']['stdWrap.'])?$cfg['HTMLtableCells.'][$cc.'.']['stdWrap.']:$cfg['HTMLtableCells.']['default.']['stdWrap.'];
03986                                                                                 if (is_array($stdWrap)) {
03987                                                                                         $colParts[$kkk] = $this->stdWrap($colParts[$kkk],$stdWrap);
03988                                                                                 }
03989 
03990                                                                                 $colParts[$kkk]=$tag.$colParts[$kkk].'</'.$tagName.'>';
03991                                                                         }
03992                                                                 }
03993                                                                 $rowParts[$kk] = implode('',$colParts);
03994                                                         }
03995                                                 }
03996                                                 $parts[$k] = implode('',$rowParts);
03997                                         }
03998 
03999                                         if (is_array($cfg['stdWrap.'])) {
04000                                                 $parts[$k] = $this->stdWrap($parts[$k],$cfg['stdWrap.']);
04001                                         }
04002                                 } else {
04003                                         $parts[$k]=$this->_parseFunc($parts[$k], $conf);
04004                                 }
04005                         }
04006 
04007                         return implode('',$parts);
04008                 } else return $this->_parseFunc($theValue, $conf);
04009         }
04010 
04020         function _parseFunc ($theValue, $conf) {
04021                 if (!$this->checkIf($conf['if.']))      {
04022                         return $theValue;
04023                 }
04024                 $inside=0;      // Indicates that the data is from within a tag.
04025                 $pointer=0;     // Pointer to the total string position
04026                 $currentTag=''; // Loaded with the current typo-tag if any.
04027                 $stripNL=0;
04028                 $contentAccum=array();
04029                 $contentAccumP=0;
04030 
04031                 $allowTags=strtolower(str_replace(' ','',$conf['allowTags']));
04032                 $denyTags=strtolower(str_replace(' ','',$conf['denyTags']));
04033 
04034                 $totalLen = strlen($theValue);
04035                 do      {
04036                         if (!$inside)   {
04037                                 if (!is_array($currentTag))     {                       // These operations should only be performed on code outside the typotags...
04038                                                 // data: this checks that we enter tags ONLY if the first char in the tag is alphanumeric OR '/'
04039                                         $len_p=0;
04040                                         $c=100;
04041                                         do      {
04042                                                 $len = strcspn(substr($theValue,$pointer+$len_p),'<');
04043                                                 $len_p+=$len+1;
04044                                                 $endChar = ord(strtolower(substr($theValue,$pointer+$len_p,1)));
04045                                                 $c--;
04046                                         } while ($c>0 && $endChar && ($endChar<97 || $endChar>122) && $endChar!=47);
04047                                         $len = $len_p-1;
04048                                 } else {
04049                                                 // If we're inside a currentTag, just take it to the end of that tag!
04050                                         $tempContent = strtolower(substr($theValue,$pointer));
04051                                         $len = strpos ($tempContent, '</'.$currentTag[0]);
04052                                         if (is_string ($len) && !$len) {
04053                                                 $len = strlen($tempContent);
04054                                         }
04055                                 }
04056 
04057                                 $data = substr($theValue,$pointer,$len);        // $data is the content until the next <tag-start or end is detected. In case of a currentTag set, this would mean all data between the start- and end-tags
04058                                 if ($data!='')  {
04059                                         if ($stripNL)   {               // If the previous tag was set to strip NewLines in the beginning of the next data-chunk.
04060                                                 $data = ereg_replace('^[ ]*'.chr(13).'?'.chr(10), '', $data);
04061                                         }
04062 
04063                                         if (!is_array($currentTag))     {                       // These operations should only be performed on code outside the tags...
04064                                                         // Constants
04065                                                 if ($conf['constants'] && is_array($GLOBALS['TSFE']->tmpl->setup['constants.']))        {
04066                                                         reset($GLOBALS['TSFE']->tmpl->setup['constants.']);
04067                                                         while(list($key,$val)=each($GLOBALS['TSFE']->tmpl->setup['constants.']))        {
04068                                                                 if (is_string($val))    {
04069                                                                         $data = str_replace('###'.$key.'###', $val, $data);
04070                                                                 }
04071                                                         }
04072                                                 }
04073                                                         // Short
04074                                                 if (is_array($conf['short.']))  {
04075                                                         $shortWords = $conf['short.'];
04076                                                         krsort($shortWords);
04077                                                         reset($shortWords);
04078                                                         while(list($key,$val)=each($shortWords))        {
04079                                                                 if (is_string($val))    {
04080                                                                         $data = str_replace($key, $val, $data);
04081                                                                 }
04082                                                         }
04083                                                 }
04084 
04085                                                         // stdWrap
04086                                                 if (is_array($conf['plainTextStdWrap.']))       {$data = $this->stdWrap($data,$conf['plainTextStdWrap.']);}
04087                                                         // userFunc
04088                                                 if ($conf['userFunc'])  {$data = $this->callUserFunction($conf['userFunc'], $conf['userFunc.'], $data);}
04089 
04090                                                         // Makelinks: (Before search-words as we need the links to be generated when searchwords go on...!)
04091                                                 if ($conf['makelinks']) {
04092                                                         $data = $this->http_makelinks($data,$conf['makelinks.']['http.']);
04093                                                         $data = $this->mailto_makelinks($data,$conf['makelinks.']['mailto.']);
04094                                                 }
04095 
04096                                                         // Search Words:
04097                                                 if ($GLOBALS['TSFE']->no_cache && $conf['sword'] && is_array($GLOBALS['TSFE']->sWordList) && $GLOBALS['TSFE']->sWordRegEx)      {
04098                                                         $newstring = '';
04099                                                         do {
04100                                                                 $pieces = split($GLOBALS['TSFE']->sWordRegEx,$data,2);
04101                                                                 $newstring.=$pieces[0];
04102                                                                 $match_len = strlen($data)-(strlen($pieces[0])+strlen($pieces[1]));
04103                                                                 if (strstr($pieces[0],'<') || strstr($pieces[0],'>'))   {
04104                                                                         $inTag = strrpos($pieces[0],'<') > strrpos($pieces[0],'>');             // Returns true, if a '<' is closer to the string-end than '>'. This is the case if we're INSIDE a tag (that could have been made by makelinks...) and we must secure, that the inside of a tag is not marked up.
04105                                                                 }
04106                                                                         // The searchword:
04107                                                                 $match = substr($data,strlen($pieces[0]),$match_len);
04108 
04109                                                                 if (trim($match) && strlen($match)>1 && !$inTag)        {
04110                                                                         $match = $this->wrap($match, $conf['sword']);
04111                                                                 }
04112                                                                         // Concatenate the Search Word again.
04113                                                                 $newstring.= $match;
04114                                                                 $data=$pieces[1];
04115                                                         } while ($pieces[1]);
04116                                                         $data = $newstring;
04117                                                 }
04118                                         }
04119                                         $contentAccum[$contentAccumP].=$data;
04120                                 }
04121                                 $inside = 1;
04122                         } else {
04123                                         // tags
04124                                 $len = strcspn(substr($theValue,$pointer),'>')+1;
04125                                 $data = substr($theValue,$pointer,$len);
04126 
04127                                 $tag = explode(' ',trim(substr($data,1,-1)),2);
04128                                 $tag[0]=strtolower($tag[0]);
04129                                 if (substr($tag[0],0,1)=='/')   {
04130                                         $tag[0]=substr($tag[0],1);
04131                                         $tag['out']=1;
04132                                 }
04133                                 if($conf['tags.'][$tag[0]])     {
04134                                         $treated=0;
04135                                         $stripNL = 0;
04136                                                 // in-tag
04137                                         if (!$currentTag && !$tag['out'])       {
04138                                                 $currentTag = $tag;             // $currentTag er lig med det tag (array!), man er igang med!
04139                                                 $contentAccumP++;
04140                                                 $treated=1;
04141                                         }
04142                                                 // out-tag
04143                                         if ($currentTag[0]==$tag[0] && $tag['out'])     {
04144                                                 $theName = $conf['tags.'][$tag[0]];
04145                                                 $theConf = $conf['tags.'][$tag[0].'.'];
04146                                                 $stripNL = ($theConf['stripNL'] ? 1 : 0);       // This flag indicates, that NL- (13-10-chars) should be stripped first and last.
04147                                                 $breakOut = ($theConf['breakoutTypoTagContent'] ? 1 : 0);       // This flag indicates, that this TypoTag section should NOT be included in the nonTypoTag content.
04148 
04149                                                 $this->parameters=Array();
04150                                                 if ($currentTag[1])     {
04151                                                         $params=t3lib_div::get_tag_attributes($currentTag[1]);
04152                                                         if (is_array($params))  {
04153                                                                 reset($params);
04154                                                                 while(list($option,$val)=each($params)) {
04155                                                                         $this->parameters[strtolower($option)]=$val;
04156                                                                 }
04157                                                         }
04158                                                 }
04159                                                 $this->parameters['allParams']=trim($currentTag[1]);
04160                                                 if ($stripNL)   {       // Removes NL in the beginning and end of the tag-content AND at the end of the currentTagBuffer. $stripNL depends on the configuration of the current tag
04161                                                         $contentAccum[$contentAccumP-1] = ereg_replace(chr(13).'?'.chr(10).'[ ]*$', '', $contentAccum[$contentAccumP-1]);
04162                                                         $contentAccum[$contentAccumP] = ereg_replace('^[ ]*'.chr(13).'?'.chr(10), '', $contentAccum[$contentAccumP]);
04163                                                         $contentAccum[$contentAccumP] = ereg_replace(chr(13).'?'.chr(10).'[ ]*$', '', $contentAccum[$contentAccumP]);
04164                                                 }
04165                                                 $this->data[$this->currentValKey] = $contentAccum[$contentAccumP];
04166                                                 $newInput=$this->cObjGetSingle($theName,$theConf,'/parseFunc/.tags.'.$tag[0]);  // fetch the content object
04167 
04168                                                 $contentAccum[$contentAccumP]=$newInput;
04169                                                 $contentAccumP++;
04170 
04171                                                         // If the TypoTag section
04172                                                 if (!$breakOut) {
04173                                                         $contentAccum[$contentAccumP-2].=$contentAccum[$contentAccumP-1].$contentAccum[$contentAccumP];
04174                                                         unset($contentAccum[$contentAccumP]);
04175                                                         unset($contentAccum[$contentAccumP-1]);
04176                                                         $contentAccumP-=2;
04177                                                 }
04178 
04179                                                 unset($currentTag);
04180                                                 $treated=1;
04181                                         }
04182                                                 // other tags...
04183                                         if (!$treated)  {
04184                                                 $contentAccum[$contentAccumP].=$data;
04185                                         }
04186                                 } else {
04187                                                 // If a tag was not a typo tag, then it is just added to the content
04188                                         $stripNL = 0;
04189                                         if (t3lib_div::inList($allowTags,$tag[0]) || ($denyTags!='*' && !t3lib_div::inList($denyTags,$tag[0]))) {
04190                                                 $contentAccum[$contentAccumP].=$data;
04191                                         } else {
04192                                                 $contentAccum[$contentAccumP].=HTMLSpecialChars($data);
04193                                         }
04194                                 }
04195                                 $inside = 0;
04196                         }
04197                         $pointer+=$len;
04198                 } while($pointer<$totalLen);
04199 
04200                         // Parsing nonTypoTag content (all even keys):
04201                 reset($contentAccum);
04202                 for ($a=0;$a<count($contentAccum);$a++) {
04203                         if ($a%2 != 1)  {
04204                                         // stdWrap
04205                                 if (is_array($conf['nonTypoTagStdWrap.']))      {$contentAccum[$a] = $this->stdWrap($contentAccum[$a],$conf['nonTypoTagStdWrap.']);}
04206                                         // userFunc
04207                                 if ($conf['nonTypoTagUserFunc'])        {$contentAccum[$a] = $this->callUserFunction($conf['nonTypoTagUserFunc'], $conf['nonTypoTagUserFunc.'], $contentAccum[$a]);}
04208                         }
04209                 }
04210                 return implode('',$contentAccum);
04211         }
04212 
04222         function encaps_lineSplit($theValue, $conf)     {
04223                 $lParts = explode(chr(10),$theValue);
04224 
04225                 $encapTags = t3lib_div::trimExplode(',',strtolower($conf['encapsTagList']),1);
04226                 $nonWrappedTag = $conf['nonWrappedTag'];
04227                 $defaultAlign=trim($this->stdWrap($conf['defaultAlign'],$conf['defaultAlign.']));
04228 
04229                 if (!strcmp('',$theValue))      return '';
04230 
04231                 while(list($k,$l)=each($lParts))        {
04232                         $sameBeginEnd=0;
04233                         $l=trim($l);
04234                         $attrib=array();
04235                         $nWrapped=0;
04236                         $byPass=0;
04237                         if (substr($l,0,1)=='<' && substr($l,-1)=='>')  {
04238                                 $fwParts = explode('>',substr($l,1),2);
04239                                 $backParts = t3lib_div::revExplode('<', substr($fwParts[1],0,-1), 2);
04240                                 $attrib = t3lib_div::get_tag_attributes('<'.$fwParts[0].'>');
04241                                 list($tagName) = explode(' ',$fwParts[0]);
04242                                 $str_content = $backParts[0];
04243                                 $sameBeginEnd = (substr(strtolower($backParts[1]),1,strlen($tagName))==strtolower($tagName));
04244                         }
04245 
04246                         if ($sameBeginEnd && in_array(strtolower($tagName),$encapTags)) {
04247                                 $uTagName = strtoupper($tagName);
04248                                 $uTagName = strtoupper($conf['remapTag.'][$uTagName]?$conf['remapTag.'][$uTagName]:$uTagName);
04249                         } else {
04250                                 $uTagName = strtoupper($nonWrappedTag);
04251                                 $str_content = $lParts[$k];
04252                                 $nWrapped=1;
04253                                 $attrib=array();
04254                         }
04255 
04256                                 // Wrapping all inner-content:
04257                         if (is_array($conf['innerStdWrap_all.']))       {$str_content = $this->stdWrap($str_content,$conf['innerStdWrap_all.']);}
04258 
04259                         if ($uTagName)  {
04260                                         // Setting common attributes
04261                                 if (is_array($conf['addAttributes.'][$uTagName.'.']))   {
04262                                         reset($conf['addAttributes.'][$uTagName.'.']);
04263                                         while(list($kk,$vv)=each($conf['addAttributes.'][$uTagName.'.']))       {
04264                                                 if (!is_array($vv))     {
04265                                                         if ((string)$conf['addAttributes.'][$uTagName.'.'][$kk.'.']['setOnly']=='blank')        {
04266                                                                 if (!strcmp($attrib[$kk],''))   $attrib[$kk]=$vv;
04267                                                         } elseif ((string)$conf['addAttributes.'][$uTagName.'.'][$kk.'.']['setOnly']=='exists') {
04268                                                                 if (!isset($attrib[$kk]))       $attrib[$kk]=$vv;
04269                                                         } else {
04270                                                                 $attrib[$kk]=$vv;
04271                                                         }
04272                                                 }
04273                                         }
04274                                 }
04275                                         // Wrapping all inner-content:
04276                                 if (is_array($conf['encapsLinesStdWrap.'][$uTagName.'.']))      {$str_content = $this->stdWrap($str_content,$conf['encapsLinesStdWrap.'][$uTagName.'.']);}
04277                                         // Default align
04278                                 if (!$attrib['align'] && $defaultAlign) $attrib['align']=$defaultAlign;
04279 
04280                                 $params = t3lib_div::implodeAttributes($attrib,1);
04281                                 if ($conf['removeWrapping'])    {
04282                                         $str_content=$str_content;
04283                                 } else {
04284                                         $str_content='<'.strtolower($uTagName).(trim($params)?' '.trim($params):'').'>'.$str_content.'</'.strtolower($uTagName).'>';
04285                                 }
04286                         }
04287 
04288                         if ($nWrapped && $conf['wrapNonWrappedLines'])  {$str_content = $this->wrap($str_content,$conf['wrapNonWrappedLines']);}
04289                         $lParts[$k] = $str_content;
04290                 }
04291 
04292                 return implode(chr(10),$lParts);
04293         }
04294 
04305         function http_makelinks($data,$conf)    {
04306                 $aTagParams = $GLOBALS['TSFE']->ATagParams.($conf['ATagParams']?' '.$conf['ATagParams']:'');
04307                 $textpieces = explode('http://', $data);
04308                 $pieces = count($textpieces);
04309                 $textstr = $textpieces[0];
04310                 $initP = '?id='.$GLOBALS['TSFE']->id.'&type='.$GLOBALS['TSFE']->type;
04311                 for($i=1; $i<$pieces; $i++)     {
04312                         $len=strcspn($textpieces[$i],chr(32).chr(9).chr(13).chr(10));
04313                         if (trim(substr($textstr,-1))=='' && $len)      {
04314 
04315                                 $lastChar=substr($textpieces[$i],$len-1,1);
04316                                 if (!ereg('[A-Za-z0-9\/#_-]',$lastChar)) {$len--;}              // Included '\/' 3/12
04317 
04318                                 $parts[0]=substr($textpieces[$i],0,$len);
04319                                 $parts[1]=substr($textpieces[$i],$len);
04320 
04321                                 $keep=$conf['keep'];
04322                                 $linkParts=parse_url('http://'.$parts[0]);
04323                                 $linktxt='';
04324                                 if (strstr($keep,'scheme'))     {
04325                                         $linktxt='http://';
04326                                 }
04327                                 $linktxt.= $linkParts['host'];
04328                                 if (strstr($keep,'path'))       {
04329                                         $linktxt.= $linkParts['path'];
04330                                         if (strstr($keep,'query') && $linkParts['query'])       {               // added $linkParts['query'] 3/12
04331                                                 $linktxt.= '?'.$linkParts['query'];
04332                                         } elseif ($linkParts['path']=='/')      {  // If query is NOT added and the path is '/' then remove the slash ('/')   (added 3/12)
04333                                                 $linktxt=substr($linktxt,0,-1);
04334                                         }
04335                                 }
04336                                 $target = isset($conf['extTarget']) ? $conf['extTarget'] : $GLOBALS['TSFE']->extTarget;
04337                                 if ($GLOBALS['TSFE']->config['config']['jumpurl_enable'])       {
04338                                         $res = '<a'.
04339                                                         ' href="'.htmlspecialchars($GLOBALS['TSFE']->absRefPrefix.$GLOBALS['TSFE']->config['mainScript'].$initP.'&jumpurl='.rawurlencode('http://'.$parts[0]).$GLOBALS['TSFE']->getMethodUrlIdToken).'"'.
04340                                                         ($target ? ' target="'.$target.'"' : '').
04341                                                         $aTagParams.
04342                                                         '>';
04343                                 } else {
04344                                         $res = '<a'.
04345                                                         ' href="http://'.htmlspecialchars($parts[0]).'"'.
04346                                                         ($target ? ' target="'.$target.'"' : '').
04347                                                         $aTagParams.
04348                                                         '>';
04349                                 }
04350                                 if ($conf['ATagBeforeWrap'])    {
04351                                         $res= $res.$this->wrap($linktxt, $conf['wrap']).'</a>';
04352                                 } else {
04353                                         $res= $this->wrap($res.$linktxt.'</a>', $conf['wrap']);
04354                                 }
04355                                 $textstr.=$res.$parts[1];
04356                         } else {
04357                                 $textstr.='http://'.$textpieces[$i];
04358                         }
04359                 }
04360                 return $textstr;
04361         }
04362 
04372         function mailto_makelinks($data,$conf)  {
04373                 // http-split
04374                 $aTagParams = $GLOBALS['TSFE']->ATagParams.($conf['ATagParams']?' '.$conf['ATagParams']:'');
04375                 $textpieces = explode('mailto:', $data);
04376                 $pieces = count($textpieces);
04377                 $textstr = $textpieces[0];
04378                 $initP = '?id='.$GLOBALS['TSFE']->id.'&type='.$GLOBALS['TSFE']->type;
04379                 for($i=1; $i<$pieces; $i++)     {
04380                         $len = strcspn($textpieces[$i],chr(32).chr(9).chr(13).chr(10));
04381                         if (trim(substr($textstr,-1))=='' && $len)      {
04382                                 $lastChar = substr($textpieces[$i],$len-1,1);
04383                                 if (!ereg('[A-Za-z0-9]',$lastChar)) {$len--;}
04384 
04385                                 $parts[0] = substr($textpieces[$i],0,$len);
04386                                 $parts[1] = substr($textpieces[$i],$len);
04387                                 $linktxt = ereg_replace('\?.*','',$parts[0]);
04388                                 list($mailToUrl,$linktxt) = $this->getMailTo($parts[0],$linktxt,$initP);
04389                                 $mailToUrl = $GLOBALS['TSFE']->spamProtectEmailAddresses === 'ascii'?$mailToUrl:htmlspecialchars($mailToUrl);
04390                                 $res = '<a href="'.$mailToUrl.'"'.$aTagParams.'>';
04391                                 if ($conf['ATagBeforeWrap'])    {
04392                                         $res= $res.$this->wrap($linktxt, $conf['wrap']).'</a>';
04393                                 } else {
04394                                         $res= $this->wrap($res.$linktxt.'</a>', $conf['wrap']);
04395                                 }
04396                                 $textstr.=$res.$parts[1];
04397                         } else {
04398                                 $textstr.='mailto:'.$textpieces[$i];
04399                         }
04400                 }
04401                 return $textstr;
04402         }
04403 
04415         function getImgResource($file,$fileArray)       {
04416                 if (is_array($fileArray))       {
04417                         switch($file)   {
04418                                 case 'GIFBUILDER':
04419                                         $gifCreator = t3lib_div::makeInstance('tslib_gifbuilder');
04420                                         $gifCreator->init();
04421                                         $theImage='';
04422                                         if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib'])        {
04423                                                 $gifCreator->start($fileArray,$this->data);
04424                                                 $theImage = $gifCreator->gifBuild();
04425                                         }
04426                                         return $gifCreator->getImageDimensions($theImage);
04427                                 break;
04428                                 default:
04429                                         if ($fileArray['import.'])      {
04430                                                 $ifile = $this->stdWrap('',$fileArray['import.']);
04431                                                 if ($ifile)     {$file = $fileArray['import'].$ifile;}
04432                                         }
04433                                         $theImage = $GLOBALS['TSFE']->tmpl->getFileName($file);
04434                                         if ($theImage)  {
04435                                                 $fileArray['width']= $this->stdWrap($fileArray['width'],$fileArray['width.']);
04436                                                 $fileArray['height']= $this->stdWrap($fileArray['height'],$fileArray['height.']);
04437                                                 $fileArray['ext']= $this->stdWrap($fileArray['ext'],$fileArray['ext.']);
04438                                                 $fileArray['maxW']= intval($this->stdWrap($fileArray['maxW'],$fileArray['maxW.']));
04439                                                 $fileArray['maxH']= intval($this->stdWrap($fileArray['maxH'],$fileArray['maxH.']));
04440                                                 $fileArray['minW']= intval($fileArray['minW']);
04441                                                 $fileArray['minH']= intval($fileArray['minH']);
04442                                                 $maskArray=     $fileArray['m.'];
04443                                                 $maskImages=array();
04444                                                 if (is_array($fileArray['m.'])) {       // Must render mask images and include in hash-calculating - else we cannot be sure the filename is unique for the setup!
04445                                                         $maskImages['m_mask'] = $this->getImgResource($maskArray['mask'],$maskArray['mask.']);
04446                                                         $maskImages['m_bgImg'] = $this->getImgResource($maskArray['bgImg'],$maskArray['bgImg.']);
04447                                                         $maskImages['m_bottomImg'] = $this->getImgResource($maskArray['bottomImg'],$maskArray['bottomImg.']);
04448                                                         $maskImages['m_bottomImg_mask'] = $this->getImgResource($maskArray['bottomImg_mask'],$maskArray['bottomImg_mask.']);
04449                                                 }
04450                                                 $hash = t3lib_div::shortMD5($theImage.serialize($fileArray).serialize($maskImages));
04451                                                 if (!isset($GLOBALS['TSFE']->tmpl->fileCache[$hash]))   {
04452                                                         $gifCreator = t3lib_div::makeInstance('tslib_gifbuilder');
04453                                                         $gifCreator->init();
04454 
04455                                                         if ($GLOBALS['TSFE']->config['config']['meaningfulTempFilePrefix'])     {
04456                                                                 $gifCreator->filenamePrefix = $GLOBALS['TSFE']->fileNameASCIIPrefix(ereg_replace('\.[[:alnum:]]+$','',basename($theImage)),intval($GLOBALS['TSFE']->config['config']['meaningfulTempFilePrefix']),'_');
04457                                                         }
04458 
04459                                                         if ($fileArray['sample'])       {
04460                                                                 $gifCreator->scalecmd = '-sample';
04461                                                                 $GLOBALS['TT']->setTSlogMessage('Sample option: Images are scaled with -sample.');
04462                                                         }
04463                                                         if ($fileArray['alternativeTempPath'] && t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['FE']['allowedTempPaths'],$fileArray['alternativeTempPath']))    {
04464                                                                 $gifCreator->tempPath = $fileArray['alternativeTempPath'];
04465                                                                 $GLOBALS['TT']->setTSlogMessage('Set alternativeTempPath: '.$fileArray['alternativeTempPath']);
04466                                                         }
04467 
04468                                                         if (!trim($fileArray['ext'])){$fileArray['ext']='web';}
04469                                                         $options = Array();
04470                                                         if ($fileArray['maxW']) {$options['maxW']=$fileArray['maxW'];}
04471                                                         if ($fileArray['maxH']) {$options['maxH']=$fileArray['maxH'];}
04472                                                         if ($fileArray['minW']) {$options['minW']=$fileArray['minW'];}
04473                                                         if ($fileArray['minH']) {$options['minH']=$fileArray['minH'];}
04474 
04475                                                                 // checks to see if m (the mask array) is defined
04476                                                         if (is_array($maskArray) && $GLOBALS['TYPO3_CONF_VARS']['GFX']['im'])   {
04477                                                                         // Filename:
04478                                                                 $fI = t3lib_div::split_fileref($theImage);
04479                                                                 $dest = $gifCreator->tempPath.$hash.'.'.($fI['fileext']==$gifCreator->gifExtension ? $gifCreator->gifExtension : 'jpg');
04480                                                                 if (!@file_exists($dest))       {               // Generate!
04481                                                                         $m_mask= $maskImages['m_mask'];
04482                                                                         $m_bgImg = $maskImages['m_bgImg'];
04483                                                                         if ($m_mask && $m_bgImg)        {
04484                                                                                 $negate = $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask'] ? ' -negate' : '';
04485 
04486                                                                                 $temp_ext='png';
04487                                                                                 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_mask_temp_ext_gif']) {               // If ImageMagick version 5+
04488                                                                                         $temp_ext=$gifCreator->gifExtension;
04489                                                                                 }
04490 
04491                                                                                 $tempFileInfo = $gifCreator->imageMagickConvert($theImage,$temp_ext,$fileArray['width'],$fileArray['height'],$fileArray['params'],$fileArray['frame'],$options);
04492                                                                                 if (is_array($tempFileInfo))    {
04493                                                                                         $m_bottomImg = $maskImages['m_bottomImg'];
04494                                                                                         if ($m_bottomImg)       {
04495                                                                                                 $m_bottomImg_mask = $maskImages['m_bottomImg_mask'];
04496                                                                                         }
04497                                                                                                 //      Scaling:        ****
04498                                                                                         $tempScale=array();
04499                                                                                         $command = '-geometry '.$tempFileInfo[0].'x'.$tempFileInfo[1].'!';
04500                                                                                         $tmpStr = $gifCreator->randomName();
04501 
04502                                                                                                 //      m_mask
04503                                                                                         $tempScale['m_mask']=$tmpStr.'_mask.'.$temp_ext;
04504                                                                                         $gifCreator->imageMagickExec($m_mask[3],$tempScale['m_mask'],$command.$negate);
04505                                                                                                 //      m_bgImg
04506                                                                                         $tempScale['m_bgImg']=$tmpStr.'_bgImg.'.trim($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_mask_temp_ext_noloss']);
04507                                                                                         $gifCreator->imageMagickExec($m_bgImg[3],$tempScale['m_bgImg'],$command);
04508 
04509                                                                                                 //      m_bottomImg / m_bottomImg_mask
04510                                                                                         if ($m_bottomImg && $m_bottomImg_mask)  {
04511                                                                                                 $tempScale['m_bottomImg']=$tmpStr.'_bottomImg.'.$temp_ext;
04512                                                                                                 $gifCreator->imageMagickExec($m_bottomImg[3],$tempScale['m_bottomImg'],$command);
04513                                                                                                 $tempScale['m_bottomImg_mask']=$tmpStr.'_bottomImg_mask.'.$temp_ext;
04514                                                                                                 $gifCreator->imageMagickExec($m_bottomImg_mask[3],$tempScale['m_bottomImg_mask'],$command.$negate);
04515 
04516                                                                                                         // BEGIN combining:
04517                                                                                                         // The image onto the background
04518                                                                                                 $gifCreator->combineExec($tempScale['m_bgImg'],$tempScale['m_bottomImg'],$tempScale['m_bottomImg_mask'],$tempScale['m_bgImg']);
04519                                                                                         }
04520                                                                                                 // The image onto the background
04521                                                                                         $gifCreator->combineExec($tempScale['m_bgImg'],$tempFileInfo[3],$tempScale['m_mask'],$dest);
04522                                                                                                 // Unlink the temp-images...
04523                                                                                         reset($tempScale);
04524                                                                                         while(list(,$file)=each($tempScale))    {
04525                                                                                                 if (@is_file($file))    {
04526                                                                                                         unlink($file);
04527                                                                                                 }
04528                                                                                         }
04529                                                                                                 //      t3lib_div::print_array($GLOBALS['TSFE']->tmpl->fileCache[$hash]);
04530                                                                                 }
04531                                                                         }
04532                                                                 }
04533                                                                         // Finish off
04534                                                                 $GLOBALS['TSFE']->tmpl->fileCache[$hash]= $gifCreator->getImageDimensions($dest);
04535                                                         } else {                // Normal situation:
04536                                                                 $GLOBALS['TSFE']->tmpl->fileCache[$hash]= $gifCreator->imageMagickConvert($theImage,$fileArray['ext'],$fileArray['width'],$fileArray['height'],$fileArray['params'],$fileArray['frame'],$options);
04537                                                         }
04538                                                         $GLOBALS['TSFE']->tmpl->fileCache[$hash]['origFile'] = $theImage;
04539                                                         $GLOBALS['TSFE']->tmpl->fileCache[$hash]['origFile_mtime'] = @filemtime($theImage);     // This is needed by tslib_gifbuilder, ln 100ff in order for the setup-array to create a unique filename hash.
04540                                                 }
04541                                                 return $GLOBALS['TSFE']->tmpl->fileCache[$hash];
04542                                         }
04543 
04544                                 break;
04545                         }
04546                 }
04547                 $theImage = $GLOBALS['TSFE']->tmpl->getFileName($file);
04548                 if ($theImage)  {
04549                         $gifCreator = t3lib_div::makeInstance('tslib_gifbuilder');
04550                         $gifCreator->init();
04551                         $info= $gifCreator->imageMagickConvert($theImage,'WEB','','','','','');
04552                         $info['origFile'] = $theImage;
04553                         $info['origFile_mtime'] = @filemtime($theImage);        // This is needed by tslib_gifbuilder, ln 100ff in order for the setup-array to create a unique filename hash.
04554                         return $info;
04555                 }
04556         }
04557 
04558 
04559 
04560 
04561 
04562 
04563 
04564 
04565 
04566 
04567 
04568 
04569 
04570 
04571 
04572 
04573 
04574 
04575 
04576 
04577 
04578 
04579         /***********************************************
04580          *
04581          * Data retrieval etc.
04582          *
04583          ***********************************************/
04584 
04585 
04592         function getFieldVal($field)    {
04593                 if (!strstr($field,'//'))       {
04594                         return $this->data[trim($field)];
04595                 } else {
04596                         $sections = t3lib_div::trimExplode('//',$field,1);
04597                         while (list(,$k)=each($sections)) {
04598                                 if (strcmp($this->data[$k],'')) return $this->data[$k];
04599                         }
04600                 }
04601         }
04602 
04612         function getData($string,$fieldArray)   {
04613                 if (!is_array($fieldArray))     {
04614                         $fieldArray=$GLOBALS['TSFE']->page;
04615                 }
04616                 $retVal = '';
04617                 $sections = explode('//',$string);
04618 
04619                 while (!$retVal AND list($secKey, $secVal)=each($sections)) {
04620                         $parts = explode(':',$secVal,2);
04621                         $key = trim($parts[1]);
04622                         if ((string)$key!='')   {
04623                                 switch(strtolower(trim($parts[0])))     {
04624                                         case 'gpvar':
04625                                                 list($firstKey, $rest) = explode('|', $key, 2);
04626                                                 if (strlen(trim($firstKey)))    {
04627                                                         $retVal = t3lib_div::_GP(trim($firstKey));
04628                                                                 // Look for deeper levels:
04629                                                         if (strlen(trim($rest)))        {
04630                                                                 $retVal = is_array($retVal) ? $this->getGlobal($rest, $retVal) : '';
04631                                                         }
04632                                                                 // Check that output is not an array:
04633                                                         if (is_array($retVal))  $retVal = '';
04634                                                 }
04635                                         break;
04636                                         case 'tsfe':
04637                                                 $retVal = $GLOBALS['TSFE']->$key;
04638                                         break;
04639                                         case 'getenv':
04640                                                 $retVal = getenv($key);
04641                                         break;
04642                                         case 'getindpenv':
04643