This commit was manufactured by cvs2svn to create tag
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_tsparser_ext.php
index abb45b0..fc5cb15 100755 (executable)
@@ -1,22 +1,22 @@
 <?php
 /***************************************************************
 *  Copyright notice
-*  
-*  (c) 1999-2003 Kasper Skårhøj (kasper@typo3.com)
+*
+*  (c) 1999-2004 Kasper Skaarhoj (kasper@typo3.com)
 *  All rights reserved
 *
-*  This script is part of the TYPO3 project. The TYPO3 project is 
+*  This script is part of the TYPO3 project. The TYPO3 project is
 *  free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
-* 
+*
 *  The GNU General Public License can be found at
 *  http://www.gnu.org/copyleft/gpl.html.
-*  A copy is found in the textfile GPL.txt and important notices to the license 
+*  A copy is found in the textfile GPL.txt and important notices to the license
 *  from the author is found in LICENSE.txt distributed with these scripts.
 *
-* 
+*
 *  This script is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/
-/** 
+/**
  * TSParser extension class to t3lib_TStemplate
  *
+ * $Id$
  * Contains functions for the TS module in TYPO3 backend
  *
- * @author     Kasper Skårhøj <kasper@typo3.com>
- * @package TYPO3
- * @subpackage t3lib
+ * @author     Kasper Skaarhoj <kasper@typo3.com>
+ */
+/**
+ * [CLASS/FUNCTION INDEX of SCRIPT]
+ *
+ *
+ *
+ *  103: class t3lib_tsparser_ext extends t3lib_TStemplate
+ *  191:     function flattenSetup($setupArray, $prefix, $resourceFlag)
+ *  218:     function substituteConstants($all)
+ *  247:     function substituteCMarkers($all)
+ *  269:     function generateConfig_constants()
+ *  318:     function ext_getSetup($theSetup,$theKey)
+ *  349:     function ext_getObjTree($arr, $depth_in, $depthData, $parentType="",$parentValue="")
+ *  437:     function makeHtmlspecialchars($theValue)
+ *  450:     function ext_getSearchKeys($arr, $depth_in, $searchString, $keyArray)
+ *  490:     function ext_getRootlineNumber($pid)
+ *  508:     function ext_getTemplateHierarchyArr($arr,$depthData, $keyArray,$first=0)
+ *  567:     function ext_process_hierarchyInfo($depthDataArr,&$pointer)
+ *  598:     function ext_outputTS($config, $lineNumbers=0, $comments=0, $crop=0, $syntaxHL=0, $syntaxHLBlockmode=0)
+ *  625:     function ext_fixed_lgd($string,$chars)
+ *  641:     function ext_lnBreakPointWrap($ln,$str)
+ *  654:     function ext_formatTS($input, $ln, $comments=1, $crop=0)
+ *  693:     function ext_getFirstTemplate($id,$template_uid=0)
+ *  712:     function ext_getAllTemplates($id)
+ *  732:     function ext_compareFlatSetups($default)
+ *  798:     function ext_categorizeEditableConstants($editConstArray)
+ *  821:     function ext_getCategoryLabelArray()
+ *  838:     function ext_getTypeData($type)
+ *  879:     function ext_getTSCE_config($category)
+ *  918:     function ext_getKeyImage($key)
+ *  928:     function ext_getTSCE_config_image($imgConf)
+ *  952:     function ext_resourceDims()
+ *  982:     function ext_readDirResources($path)
+ *  997:     function readDirectory($path,$type="file")
+ * 1022:     function ext_fNandV($params)
+ * 1040:     function ext_printFields($theConstants,$category)
+ *
+ *              SECTION: Processing input values
+ * 1297:     function ext_regObjectPositions($constants)
+ * 1312:     function ext_regObjects($pre)
+ * 1357:     function ext_putValueInConf($key, $var)
+ * 1380:     function ext_removeValueInConf($key)
+ * 1396:     function ext_depthKeys($arr,$settings)
+ * 1431:     function ext_procesInput($http_post_vars,$http_post_files,$theConstants,$tplRow)
+ * 1558:     function upload_copy_file($typeDat,&$tplRow,$theRealFileName,$tmp_name)
+ * 1604:     function ext_prevPageWithTemplate($id,$perms_clause)
+ * 1620:     function ext_setStar($val)
+ * 1632:     function ext_detectAndFixExtensionPrefix($value)
+ *
+ * TOTAL FUNCTIONS: 39
+ * (This index is automatically created/updated by the extension "extdeveval")
+ *
  */
 
 require_once(PATH_t3lib."class.t3lib_tstemplate.php");
 
+
+
+
+
+
+
+/**
+ * TSParser extension class to t3lib_TStemplate
+ *
+ * @author     Kasper Skaarhoj <kasper@typo3.com>
+ * @package TYPO3
+ * @subpackage t3lib
+ */
 class t3lib_tsparser_ext extends t3lib_TStemplate      {
 
        var $edit_divider = "###MOD_TS:EDITABLE_CONSTANTS###";          // This string is used to indicate the point in a template from where the editable constants are listed. Any vars before this point (if it exists though) is regarded as default values.
-       var $HTMLcolorList = "aqua,black,blue,fuchsia,gray,green,lime,maroon,navy,olive,purple,red,silver,teal,yellow,white";   
+       var $HTMLcolorList = "aqua,black,blue,fuchsia,gray,green,lime,maroon,navy,olive,purple,red,silver,teal,yellow,white";
 
                // internal
        var $categories = array(
@@ -59,12 +123,12 @@ class t3lib_tsparser_ext extends t3lib_TStemplate  {
                "color" => Array("Colors", "e"),
                "links" => Array("Links and targets", "f"),
                "language" => Array("Language specific constants", "g"),
-               
+
        // subcategories based on the default content elements
                "cheader" => Array("Content: 'Header'", "ma"),
                "cheader_g" => Array("Content: 'Header', Graphical", "ma"),
                "ctext" => Array("Content: 'Text'", "mb"),
-//             "ctextpic" => 
+//             "ctextpic" =>
                "cimage" => Array("Content: 'Image'", "md"),
                "cbullets" => Array("Content: 'Bullet list'", "me"),
                "ctable" => Array("Content: 'Table'", "mf"),
@@ -86,7 +150,7 @@ class t3lib_tsparser_ext extends t3lib_TStemplate    {
 //     var $matchAll = 0;              // If set, all conditions are matched!
 
        var $backend_info=1;
-       
+
                // tsconstanteditor
        var $ext_inBrace=0;
 
@@ -97,7 +161,7 @@ class t3lib_tsparser_ext extends t3lib_TStemplate    {
        var $regexMode="";
        var $fixedLgd="";
        var $resourceCheck=0;
-       var $ext_lineNumberOffset=0;    
+       var $ext_lineNumberOffset=0;
        var $ext_localGfxPrefix="";
        var $ext_localWebGfxPrefix="";
        var $ext_expandAllNotes=0;
@@ -110,14 +174,21 @@ class t3lib_tsparser_ext extends t3lib_TStemplate {
        var $ext_printAll=0;
        var $ext_CEformName="forms[0]";
        var $ext_defaultOnlineResourceFlag=0;
-       
+
                // ts analyzer
        var $templateTitles=array();
-       
+
+
+       /**
+        * This flattens a hierarchical setuparray to $this->flatSetup
+        * The original function fetched the resource-file if any ("file."). This functions doesn't.
+        *
+        * @param       [type]          $setupArray: ...
+        * @param       [type]          $prefix: ...
+        * @param       [type]          $resourceFlag: ...
+        * @return      [type]          ...
+        */
        function flattenSetup($setupArray, $prefix, $resourceFlag)      {
-               // This flattens a hierarchical setuparray to $this->flatSetup
-               // The original function fetched the resource-file if any ("file."). This functions doesn't.
-       
                if (is_array($setupArray))      {
                        $this->getFileName_backPath=PATH_site;          // Setting absolute prefixed path for relative resources.
                        reset($setupArray);
@@ -126,13 +197,9 @@ class t3lib_tsparser_ext extends t3lib_TStemplate  {
                                        if (is_array($val))     {
                                                $this->flattenSetup($val,$prefix.$key, ($key=="file."));
                                        } elseif ($resourceFlag && $this->resourceCheck) {
-//                                             debug($prefix.$key."-".$val);
-//                                             debug($this->getFileName($val),1);
                                                $this->flatSetup[$prefix.$key] = $this->getFileName($val);
-#debug(array($prefix.$key,$this->flatSetup[$prefix.$key],$val,$this->getFileName($val)));
                                                if ($this->removeFromGetFilePath && substr($this->flatSetup[$prefix.$key],0,strlen($this->removeFromGetFilePath))==$this->removeFromGetFilePath)        {
                                                        $this->flatSetup[$prefix.$key] = substr($this->flatSetup[$prefix.$key],strlen($this->removeFromGetFilePath));
-//                                                     debug($this->flatSetup[$prefix.$key],1);
                                                }
                                        } else {
                                                $this->flatSetup[$prefix.$key] = $val;
@@ -141,6 +208,13 @@ class t3lib_tsparser_ext extends t3lib_TStemplate  {
                        }
                }
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $all: ...
+        * @return      [type]          ...
+        */
        function substituteConstants($all)      {
                $this->Cmarker=substr(md5(uniqid("")),0,6);
                reset($this->flatSetup);
@@ -161,8 +235,15 @@ class t3lib_tsparser_ext extends t3lib_TStemplate  {
                                }
                        }
                }
-               return $all;    
+               return $all;
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $all: ...
+        * @return      [type]          ...
+        */
        function substituteCMarkers($all)       {
                switch($this->constantMode)     {
                        case "const":
@@ -179,6 +260,12 @@ class t3lib_tsparser_ext extends t3lib_TStemplate  {
                }
                return $all;
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @return      [type]          ...
+        */
        function generateConfig_constants()     {
                        // Parses the constants in $this->const with respect to the constant-editor in this module.
                        // In particular comments in the code are registered and the edit_divider is taken into account.
@@ -190,6 +277,7 @@ class t3lib_tsparser_ext extends t3lib_TStemplate   {
                $constants = t3lib_div::makeInstance("t3lib_TSparser");
                $constants->regComments=1;              // Register comments!
                $constants->setup = $this->const;
+               $constants->setup = $this->mergeConstantsFromPageTSconfig($constants->setup);
 
                $matchObj = t3lib_div::makeInstance("t3lib_matchCondition");
 //             $matchObj->matchAlternative = array("[globalString =  page | title = *test*]");
@@ -216,9 +304,17 @@ class t3lib_tsparser_ext extends t3lib_TStemplate  {
                $this->flatSetup = Array();
                $this->flattenSetup($constants->setup,"","");
                $this->setup["constants"] = $constants->setup;
-               
+
                return $this->ext_compareFlatSetups($defaultConstants);
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $theSetup: ...
+        * @param       [type]          $theKey: ...
+        * @return      [type]          ...
+        */
        function ext_getSetup($theSetup,$theKey)        {
                $parts = explode(".",$theKey,2);
 //             debug("-----------",1);
@@ -239,6 +335,17 @@ class t3lib_tsparser_ext extends t3lib_TStemplate  {
                        }
                }
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $arr: ...
+        * @param       [type]          $depth_in: ...
+        * @param       [type]          $depthData: ...
+        * @param       [type]          $parentType: ...
+        * @param       [type]          $parentValue: ...
+        * @return      [type]          ...
+        */
        function ext_getObjTree($arr, $depth_in, $depthData, $parentType="",$parentValue="")    {
                $HTML="";
                $a=0;
@@ -247,12 +354,14 @@ class t3lib_tsparser_ext extends t3lib_TStemplate {
                $keyArr_num=array();
                $keyArr_alpha=array();
                while (list($key,)=each($arr))  {
-                       $key=ereg_replace("\.$","",$key);
-                       if (substr($key,-1)!=".")       {
-                               if (t3lib_div::testInt($key))   {
-                                       $keyArr_num[$key]=$arr[$key];
-                               } else {
-                                       $keyArr_alpha[$key]=$arr[$key];
+                       if (substr($key,-2)!="..")      {       // Don't do anything with comments / linenumber registrations...
+                               $key=ereg_replace("\.$","",$key);
+                               if (substr($key,-1)!=".")       {
+                                       if (t3lib_div::testInt($key))   {
+                                               $keyArr_num[$key]=$arr[$key];
+                                       } else {
+                                               $keyArr_alpha[$key]=$arr[$key];
+                                       }
                                }
                        }
                }
@@ -261,10 +370,10 @@ class t3lib_tsparser_ext extends t3lib_TStemplate {
                reset($keyArr);
                $c=count($keyArr);
                if ($depth_in)  {$depth_in = $depth_in.".";}
-               
+
 //             $validate_info= verify_TSobjects($keyArr,$parentType,$parentValue);
 //             debug($validate_info);
-               
+
                while (list($key,)=each($keyArr))       {
                        $a++;
                        $depth=$depth_in.$key;
@@ -276,33 +385,37 @@ class t3lib_tsparser_ext extends t3lib_TStemplate {
                                $LN = ($a==$c)?"blank":"line";
                                $BTM = ($a==$c)?"bottom":"";
                                $PM = is_array($arr[$key."."]) && !$this->ext_noPMicons ? ($deeper ? "minus":"plus") : "join";
-       
+
                                $HTML.=$depthData;
-                               $theIcon='<IMG src="'.$GLOBALS["BACK_PATH"].'t3lib/gfx/ol/'.$PM.$BTM.'.gif" width="18" height="16" align="top" border=0>';
+                               $theIcon='<img src="'.$GLOBALS["BACK_PATH"].'t3lib/gfx/ol/'.$PM.$BTM.'.gif" width="18" height="16" align="top" border="0" alt="" />';
                                if ($PM=="join")        {
                                        $HTML.=$theIcon;
                                } else {
-                                       $HTML.='<a name="'.$goto.'" href="index.php?id='.$GLOBALS["SOBE"]->id.'&tsbr['.$depth.']='.($deeper?0:1).'#'.$goto.'">'.$theIcon.'</a>';
+                                       $aHref='index.php?id='.$GLOBALS["SOBE"]->id.'&tsbr['.$depth.']='.($deeper?0:1).'#'.$goto;
+                                       $HTML.='<a name="'.$goto.'" href="'.htmlspecialchars($aHref).'">'.$theIcon.'</a>';
                                }
-       
+
                                $label = $key;
                                if (t3lib_div::inList("types,resources,sitetitle",$depth) && $this->bType=="setup")     {               // Read only...
                                        $label='<font color="#666666">'.$label.'</font>';
                                } else {
                                        if ($this->linkObjects) {
-                                               $label = '<a href="index.php?id='.$GLOBALS["SOBE"]->id.'&sObj='.$depth.'">'.$label.'</a>';
+                                               $aHref = 'index.php?id='.$GLOBALS["SOBE"]->id.'&sObj='.$depth;
+                                               if ($this->bType!="const")      {
+                                                       $ln = is_array($arr[$key.'.ln..']) ? 'Defined in: '.$this->lineNumberToScript($arr[$key.'.ln..']) : 'N/A';
+                                               } else {
+                                                       $ln = '';
+                                               }
+                                               $label = '<a href="'.htmlspecialchars($aHref).'" title="'.htmlspecialchars($ln).'">'.$label.'</a>';
                                        }
                                }
-       //                      if (!isset($validate_info[$key]))       {
-       //                              $HTML.='<font color="red">['.$label.']</font>';
-       //                      } else {
-                                       $HTML.="[".$label."]";
-       //                      }
+
+                               $HTML.="[".$label."]";
+
                                if (isset($arr[$key]))  {
                                        $theValue = $arr[$key];
                                        if ($this->fixedLgd)    {
                                                $imgBlocks = ceil(1+strlen($depthData)/77);
-       //                                      debug($imgBlocks);
                                                $lgdChars = 68-ceil(strlen("[".$key."]")*0.8)-$imgBlocks*3;
                                                $theValue = $this->ext_fixed_lgd($theValue,$lgdChars);
                                        }
@@ -312,18 +425,61 @@ class t3lib_tsparser_ext extends t3lib_TStemplate {
                                                $HTML.="=<b>".$this->makeHtmlspecialchars($theValue)."</b>";
                                        }
                                }
-                               $HTML.="<BR>";
-                                       
+                               $HTML.="<br />";
+
                                if ($deeper)    {
-                                       $HTML.=$this->ext_getObjTree($arr[$key."."], $depth, $depthData.'<IMG src="'.$GLOBALS["BACK_PATH"].'t3lib/gfx/ol/'.$LN.'.gif" width="18" height="16" align="top">', $validate_info[$key], $arr[$key]);
+                                       $HTML.=$this->ext_getObjTree($arr[$key."."], $depth, $depthData.'<img src="'.$GLOBALS["BACK_PATH"].'t3lib/gfx/ol/'.$LN.'.gif" width="18" height="16" align="top" alt="" />', $validate_info[$key], $arr[$key]);
                                }
                        }
                }
                return $HTML;
        }
+
+
+       function lineNumberToScript($lnArr)     {
+               if (!is_array($this->lnToScript))       {
+                       $this->lnToScript = array();
+                       $c=1;
+                       $c+=substr_count($GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup'],chr(10))+2;
+                       $this->lnToScript[$c] = '[Default]';
+
+                       foreach($this->hierarchyInfoToRoot as $info)    {
+                               $c+=$info['configLines']+1;
+                               $this->lnToScript[$c] = $info['title'];
+                       }
+               }
+
+               foreach($lnArr as $k => $ln)    {
+                       foreach($this->lnToScript as $endLn => $title)  {
+                               if ($endLn >= intval($ln))      {
+                                       $lnArr[$k] = '"'.$title.'", '.$ln;
+                                       break;
+                               }
+                       }
+               }
+
+               return implode('; ',$lnArr);
+       }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $theValue: ...
+        * @return      [type]          ...
+        */
        function makeHtmlspecialchars($theValue){
                return $this->ext_noSpecialCharsOnLabels ? $theValue : htmlspecialchars($theValue);
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $arr: ...
+        * @param       [type]          $depth_in: ...
+        * @param       [type]          $searchString: ...
+        * @param       [type]          $keyArray: ...
+        * @return      [type]          ...
+        */
        function ext_getSearchKeys($arr, $depth_in, $searchString, $keyArray)           {
                reset($arr);
                $keyArr=array();
@@ -340,13 +496,13 @@ class t3lib_tsparser_ext extends t3lib_TStemplate {
                while (list($key,)=each($keyArr))       {
                        $depth=$depth_in.$key;
                        $deeper = is_array($arr[$key."."]);
-                       
+
                        if ($this->regexMode)   {
                                if (ereg($searchString,$arr[$key]))     {       $this->tsbrowser_searchKeys[$depth]=1;  }
                        } else {
                                if (stristr($arr[$key],$searchString))  {       $this->tsbrowser_searchKeys[$depth]=1;  }
                        }
-                       
+
                        if ($deeper)    {
                                $cS = count($this->tsbrowser_searchKeys);
                                $keyArray = $this->ext_getSearchKeys($arr[$key."."], $depth, $searchString, $keyArray);
@@ -354,9 +510,16 @@ class t3lib_tsparser_ext extends t3lib_TStemplate  {
                                        $keyArray[$depth]=1;
                                }
                        }
-               }       
+               }
                return $keyArray;
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $pid: ...
+        * @return      [type]          ...
+        */
        function ext_getRootlineNumber($pid)    {
                if ($pid && is_array($GLOBALS["rootLine"]))     {
                        reset($GLOBALS["rootLine"]);
@@ -365,6 +528,16 @@ class t3lib_tsparser_ext extends t3lib_TStemplate  {
                        }
                }
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $arr: ...
+        * @param       [type]          $depthData: ...
+        * @param       [type]          $keyArray: ...
+        * @param       [type]          $first: ...
+        * @return      [type]          ...
+        */
        function ext_getTemplateHierarchyArr($arr,$depthData, $keyArray,$first=0)       {
                reset($arr);
                $keyArr=array();
@@ -382,14 +555,14 @@ class t3lib_tsparser_ext extends t3lib_TStemplate {
                        $a++;
                        $deeper = is_array($arr[$key."."]);
                        $row=$arr[$key];
-                       
+
                        $PM = "join";
                        $LN = ($a==$c)?"blank":"line";
                        $BTM = ($a==$c)?"top":"";
                        $PM = "join";
 
                        $HTML.=$depthData;
-                       $icon = substr($row["templateID"],0,3)=="sys" ? t3lib_iconWorks::getIcon("sys_template",array("root"=>$row["root"])) : 
+                       $icon = substr($row["templateID"],0,3)=="sys" ? t3lib_iconWorks::getIcon("sys_template",array("root"=>$row["root"])) :
                                                        (substr($row["templateID"],0,6)=="static" ? t3lib_iconWorks::getIcon("static_template",array()) : 'gfx/i/default.gif');
                        $alttext= "[".$row['templateID']."]";
                        $alttext.= $row['pid'] ? " - ".t3lib_BEfunc::getRecordPath($row['pid'],$GLOBALS["SOBE"]->perms_clause,20) : "";
@@ -413,9 +586,17 @@ class t3lib_tsparser_ext extends t3lib_TStemplate  {
                        if ($deeper)    {
                                $keyArray = $this->ext_getTemplateHierarchyArr($arr[$key."."], $depthData.($first?'':'<IMG src="'.$GLOBALS["BACK_PATH"].'t3lib/gfx/ol/'.$LN.'.gif" width="18" height="16" align="top">'), $keyArray);
                        }
-               }       
+               }
                return $keyArray;
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $depthDataArr: ...
+        * @param       [type]          $pointer: ...
+        * @return      [type]          ...
+        */
        function ext_process_hierarchyInfo($depthDataArr,&$pointer)     {
                $parent = $this->hierarchyInfo[$pointer-1]['templateParent'];
                while ($pointer>0 && $this->hierarchyInfo[$pointer-1]['templateParent']==$parent)       {
@@ -423,25 +604,37 @@ class t3lib_tsparser_ext extends t3lib_TStemplate {
                        $row = $this->hierarchyInfo[$pointer];
 
                        $depthDataArr[$row['templateID']]=$row;
-                       $depthDataArr[$row['templateID']]["bgcolor_setup"] = isset($this->clearList_setup_temp[$row['templateID']])?' bgColor="'.$GLOBALS["SOBE"]->doc->bgColor5.'"':'';
-                       $depthDataArr[$row['templateID']]["bgcolor_const"] = isset($this->clearList_const_temp[$row['templateID']])?' bgColor="'.$GLOBALS["SOBE"]->doc->bgColor5.'"':'';
+                       $depthDataArr[$row['templateID']]["bgcolor_setup"] = isset($this->clearList_setup_temp[$row['templateID']])?' class="bgColor5"':'';
+                       $depthDataArr[$row['templateID']]["bgcolor_const"] = isset($this->clearList_const_temp[$row['templateID']])?' class="bgColor5"':'';
                        unset($this->clearList_setup_temp[$row['templateID']]);
                        unset($this->clearList_const_temp[$row['templateID']]);
                        $this->templateTitles[$row['templateID']]=$row["title"];
-                       
+
                        if ($row['templateID']==$this->hierarchyInfo[$pointer-1]['templateParent'])     {
                                $depthDataArr[$row['templateID']."."] = $this->ext_process_hierarchyInfo(array(), $pointer);
                        }
                }
                return $depthDataArr;
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $config: ...
+        * @param       [type]          $lineNumbers: ...
+        * @param       [type]          $comments: ...
+        * @param       [type]          $crop: ...
+        * @param       [type]          $syntaxHL: ...
+        * @param       [type]          $syntaxHLBlockmode: ...
+        * @return      [type]          ...
+        */
        function ext_outputTS($config, $lineNumbers=0, $comments=0, $crop=0, $syntaxHL=0, $syntaxHLBlockmode=0) {
                $all="";
                reset($config);
                while (list(,$str)=each($config))       {
                        $all.="\n[GLOBAL]\n".$str;
                }
-               
+
                if ($syntaxHL)  {
                        $all = ereg_replace("^[^".chr(10)."]*.","",$all);
                        $all = chop($all);
@@ -452,10 +645,17 @@ class t3lib_tsparser_ext extends t3lib_TStemplate {
                        return $this->ext_formatTS($all,$lineNumbers,$comments,$crop);
                }
        }
+
+       /**
+        * Returns a new string of max. $chars lenght
+        * If the string is longer, it will be truncated and prepended with "..."
+        * $chars must be an integer of at least 4
+        *
+        * @param       [type]          $string: ...
+        * @param       [type]          $chars: ...
+        * @return      [type]          ...
+        */
        function ext_fixed_lgd($string,$chars)  {
-               // Returns a new string of max. $chars lenght
-               // If the string is longer, it will be truncated and prepended with "..."
-               // $chars must be an integer of at least 4
                if ($chars >= 4)        {
                        if(strlen($string)>$chars)  {
                                return substr($string, 0, $chars-3)."...";
@@ -463,9 +663,27 @@ class t3lib_tsparser_ext extends t3lib_TStemplate  {
                }
                return $string;
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $ln: ...
+        * @param       [type]          $str: ...
+        * @return      [type]          ...
+        */
        function ext_lnBreakPointWrap($ln,$str) {
                return '<A href="#" onClick="return brPoint('.$ln.','.($this->ext_lineNumberOffset_mode=="setup"?1:0).');">'.$str.'</a>';
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $input: ...
+        * @param       [type]          $ln: ...
+        * @param       [type]          $comments: ...
+        * @param       [type]          $crop: ...
+        * @return      [type]          ...
+        */
        function ext_formatTS($input, $ln, $comments=1, $crop=0)        {
                $input = ereg_replace("^[^".chr(10)."]*.","",$input);
                $input = chop($input);
@@ -480,62 +698,71 @@ class t3lib_tsparser_ext extends t3lib_TStemplate {
                        $v=htmlspecialchars($v);
                        if ($crop)      {$v=$this->ext_fixed_lgd($v,($ln?71:77));}
                        $cArr[$k] = $lineNum.str_replace(" ",'&nbsp;',$v);
-                       
+
                        $firstChar = substr(trim($v),0,1);
                        if ($firstChar=="[")    {
                                $cArr[$k] = '<font color="green"><b>'.$cArr[$k].'</b></font>';
                        } elseif ($firstChar=="/" || $firstChar=="#")   {
                                if ($comments)  {
-                                       $cArr[$k] = '<font color="#666666">'.$cArr[$k].'</font>';
+                                       $cArr[$k] = '<span class="typo3-dimmed">'.$cArr[$k].'</span>';
                                } else {
                                        unset($cArr[$k]);
                                }
                        }
 
-/*                     if (ereg('\{\$[^\}]*\}',$v,$reg))       {
-                               while(list(,$f)=each($reg))     {
-                               debug($reg);
-                                       if ($f) {
-                                               $cArr[$k] = str_replace(htmlspecialchars($f),'<font color="green"><b>'.htmlspecialchars($f).'</b></font>',$cArr[$k]);
-//                                             debug($f);
-                                       }
-                               }
-                       }*/
+
                }
                $output = implode($cArr, "<BR>")."<BR>";
-//             $output = '<font face=verdana size=1 color=maroon>'.$output.'</font>';
                return $output;
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $id: ...
+        * @param       [type]          $template_uid: ...
+        * @return      [type]          ...
+        */
        function ext_getFirstTemplate($id,$template_uid=0)              {
                        // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
                if (intval($id))        {
                        if ($template_uid)      {
                                $addC = " AND uid=".$template_uid;
                        }
-                       $query = "SELECT * FROM sys_template WHERE pid = ".intval($id).$addC." ".$this->whereClause." ORDER BY sorting LIMIT 1";
-                       $res = mysql(TYPO3_db, $query);
-                       echo mysql_error();
-                       $row = mysql_fetch_assoc($res);
+                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid='.intval($id).$addC.' '.$this->whereClause, '', 'sorting', '1');
+                       $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
+                       $GLOBALS['TYPO3_DB']->sql_free_result($res);
                        return $row;    // Returns the template row if found.
                }
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $id: ...
+        * @return      [type]          ...
+        */
        function ext_getAllTemplates($id)               {
                        // Query is taken from the runThroughTemplates($theRootLine) function in the parent class.
                if (intval($id))        {
-                       $query = "SELECT * FROM sys_template WHERE pid = ".intval($id)." ".$this->whereClause." ORDER BY sorting";
-                       $res = mysql(TYPO3_db, $query);
-                       echo mysql_error();
                        $outRes=array();
-                       while($row = mysql_fetch_assoc($res))   {
+                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid='.intval($id).' '.$this->whereClause, '', 'sorting');
+                       while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
                                $outRes[] = $row;
                        }
+                       $GLOBALS['TYPO3_DB']->sql_free_result($res);
                        return $outRes; // Returns the template rows in an array.
                }
        }
+
+       /**
+        * This function compares the flattened constants (default and all).
+        * Returns an array with the constants from the whole template which may be edited by the module.
+        *
+        * @param       [type]          $default: ...
+        * @return      [type]          ...
+        */
        function ext_compareFlatSetups($default)        {
-               // This function compares the flattened constants (default and all).
-               // Returns an array with the constants from the whole template which may be edited by the module. 
-       
                $editableComments=array();
                reset($this->flatSetup);
                while(list($const,$value)=each($this->flatSetup))       {
@@ -551,13 +778,13 @@ class t3lib_tsparser_ext extends t3lib_TStemplate {
                                                                $keyValPair =explode("=",$par,2);
                                                                switch(trim(strtolower($keyValPair[0])))        {
                                                                        case "type":
-                                                                                       // Type:        
+                                                                                       // Type:
                                                                                        /*
-       int (range; low-high, list: item,item,item = selector), 
-       boolean (check), 
-       string (default), 
-       wrap, 
-       html-color ..., 
+       int (range; low-high, list: item,item,item = selector),
+       boolean (check),
+       string (default),
+       wrap,
+       html-color ...,
        file
                                                                                        */
                                                                                $editableComments[$const]["type"] = trim($keyValPair[1]);
@@ -594,6 +821,13 @@ class t3lib_tsparser_ext extends t3lib_TStemplate  {
                }
                return $editableComments;
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $editConstArray: ...
+        * @return      [type]          ...
+        */
        function ext_categorizeEditableConstants($editConstArray)       {
                // Runs through the available constants and fills the $this->categories array with pointers and priority-info
                reset($editConstArray);
@@ -611,6 +845,12 @@ class t3lib_tsparser_ext extends t3lib_TStemplate  {
                }
 //             debug($this->categories);
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @return      [type]          ...
+        */
        function ext_getCategoryLabelArray()    {
                // Returns array used for labels in the menu.
                $retArr = array();
@@ -621,6 +861,13 @@ class t3lib_tsparser_ext extends t3lib_TStemplate  {
                }
                return $retArr;
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $type: ...
+        * @return      [type]          ...
+        */
        function ext_getTypeData($type) {
                $retArr = array();
                $type=trim($type);
@@ -655,6 +902,13 @@ class t3lib_tsparser_ext extends t3lib_TStemplate  {
 //             debug($retArr);
                return $retArr;
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $category: ...
+        * @return      [type]          ...
+        */
        function ext_getTSCE_config($category)  {
                $catConf=$this->setup["constants"]["TSConstantEditor."][$category."."];
                $out=array();
@@ -687,9 +941,23 @@ class t3lib_tsparser_ext extends t3lib_TStemplate  {
                }
                $this->helpConfig=$out;
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $key: ...
+        * @return      [type]          ...
+        */
        function ext_getKeyImage($key)  {
                return '<img src="'.$this->ext_localWebGfxPrefix.'gfx/'.$key.'.gif" align="top" hspace=2>';
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $imgConf: ...
+        * @return      [type]          ...
+        */
        function ext_getTSCE_config_image($imgConf)     {
                if (substr($imgConf,0,4)=="gfx/")       {
                        $iFile=$this->ext_localGfxPrefix.$imgConf;
@@ -697,17 +965,23 @@ class t3lib_tsparser_ext extends t3lib_TStemplate {
                } elseif (substr($imgConf,0,4)=='EXT:') {
                        $iFile = t3lib_div::getFileAbsFileName($imgConf);
                        if ($iFile)     {
-                               $f = substr($iFile,strlen(PATH_site));  
-                               $tFile="../".$GLOBALS["BACK_PATH"].$f;
+                               $f = substr($iFile,strlen(PATH_site));
+                               $tFile=$GLOBALS["BACK_PATH"]."../".$f;
                        }
                } else {
                        $f = "uploads/tf/".$this->extractFromResources($this->setup["resources"],$imgConf);
                        $iFile=PATH_site.$f;
-                       $tFile="../".$GLOBALS["BACK_PATH"].$f;
+                       $tFile=$GLOBALS["BACK_PATH"]."../".$f;
                }
                $imageInfo=@getImagesize($iFile);
                return '<img src="'.$tFile.'" '.$imageInfo[3].'>';
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @return      [type]          ...
+        */
        function ext_resourceDims()     {
                if ($this->setup["resources"])  {
                        $rArr=explode(",",$this->setup["resources"]);
@@ -731,6 +1005,13 @@ class t3lib_tsparser_ext extends t3lib_TStemplate {
                        }
                }
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $path: ...
+        * @return      [type]          ...
+        */
        function ext_readDirResources($path)    {
                $path=trim($path);
                if ($path && substr($path,0,10)=="fileadmin/")  {
@@ -738,6 +1019,14 @@ class t3lib_tsparser_ext extends t3lib_TStemplate {
                        $this->readDirectory(PATH_site.$path);
                }
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $path: ...
+        * @param       [type]          $type: ...
+        * @return      [type]          ...
+        */
        function readDirectory($path,$type="file")      {
                if(@is_dir($path))      {
                        $d = @dir($path);
@@ -756,6 +1045,13 @@ class t3lib_tsparser_ext extends t3lib_TStemplate {
                        }
                }
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $params: ...
+        * @return      [type]          ...
+        */
        function ext_fNandV($params)    {
                $fN='data['.$params["name"].']';
                $fV=$params["value"];
@@ -766,16 +1062,24 @@ class t3lib_tsparser_ext extends t3lib_TStemplate        {
 
                return array($fN,$fV,$params);
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $theConstants: ...
+        * @param       [type]          $category: ...
+        * @return      [type]          ...
+        */
        function ext_printFields($theConstants,$category)       {
                        // This functions returns the HTML-code that creates the editor-layout of the module.
                reset($theConstants);
                $output="";
                $subcat="";
                if (is_array($this->categories[$category]))     {
-               
+
                        $help=$this->helpConfig;
                        $this->rArr=explode(",",$this->setup["resources"].",".implode($this->dirResources,","));
-               
+
                        asort($this->categories[$category]);
                        while(list($name,$type)=each($this->categories[$category]))     {
                                $params = $theConstants[$name];
@@ -784,7 +1088,7 @@ class t3lib_tsparser_ext extends t3lib_TStemplate  {
                                                $subcat=$params["subcat_name"];
                                                $subcat_name = $params["subcat_name"] ? $this->subCategories[$params["subcat_name"]][0] : "Others";
                                                $output.='<tr>';
-                                               $output.='<td colspan=2 bgColor="'.$GLOBALS["SOBE"]->doc->bgColor4.'"><div align="center"><b>'.$subcat_name.'</b></div></td>';
+                                               $output.='<td colspan=2 class="bgColor4"><div align="center"><b>'.$subcat_name.'</b></div></td>';
                                                $output.='</tr>';
                                        }
 
@@ -810,7 +1114,7 @@ class t3lib_tsparser_ext extends t3lib_TStemplate  {
                                                if ($this->ext_dontCheckIssetValues || isset($this->objReg[$params["name"]]))   {
                                                        $checked=" checked";
                                                        list($fN,$fV,$params)=$this->ext_fNandV($params);
-                                                       
+
                                                        switch($typeDat["type"])        {
                                                                case "int":
                                                                case "int+":
@@ -862,7 +1166,7 @@ class t3lib_tsparser_ext extends t3lib_TStemplate  {
                                                                                        $vParts = explode("=",$val,2);
                                                                                        $label = $vParts[0];
                                                                                        $val = isset($vParts[1]) ? $vParts[1] : $vParts[0];
-                                                                                       
+
                                                                                                // option tag:
                                                                                        $sel="";
                                                                                        if ($val==$params["value"])     {$sel=" selected";}
@@ -901,7 +1205,7 @@ class t3lib_tsparser_ext extends t3lib_TStemplate  {
                                                                                }
                                                                                reset($this->rArr);
                                                                                $onlineResourceFlag=$this->ext_defaultOnlineResourceFlag;
-                                                                               
+
                                                                                while(list($c,$val)=each($this->rArr))  {
                                                                                        $val=trim($val);
                                                                                        $fI=t3lib_div::split_fileref($val);
@@ -916,7 +1220,7 @@ class t3lib_tsparser_ext extends t3lib_TStemplate  {
                                                                                                }
                                                                                                $dims=$this->resourceDimensions[$val];
                                                                                                $sel="";
-                                                                                               
+
                                                                                                        // Check if $params["value"] is in the list of resources.
                                                                                                if ($selectThisFile && $selectThisFile==$val)   {
                                                                                                        $sel=" selected";
@@ -926,7 +1230,7 @@ class t3lib_tsparser_ext extends t3lib_TStemplate  {
                                                                                                                $theImage=t3lib_BEfunc::thumbCode(array("resources"=>$fI["file"]),"sys_template","resources",$GLOBALS["BACK_PATH"],"",$fI["path"]);
                                                                                                        }
                                                                                                }
-                                                                                               
+
                                                                                                if ($onlineResourceFlag<=0)     {
                                                                                                        $onlineResourceFlag--;
                                                                                                                // Value is set with a *
@@ -959,15 +1263,15 @@ class t3lib_tsparser_ext extends t3lib_TStemplate        {
                                                                                }
 #debug($copyFile);
                                                                                if ($copyFile && @is_file($copyFile))   {
-                                                                                       $p_field.='<img src=clear.gif width=20 height=1><img src="'.$GLOBALS["BACK_PATH"].'gfx/clip_copy.gif" width="12" height="12" border="0"><input type="Checkbox" name="_copyResource['.$params["name"].']" value="'.htmlspecialchars($copyFile).'" onClick="uFormUrl('.$aname.');if (this.checked) {alert(unescape(\''.rawurlencode(sprintf("This will make a copy of the current file, '%s'. Do you really want that?",$params["value"])).'\'));}">';
+                                                                                       $p_field.='<img src="clear.gif" width="20" height="1" alt="" /><img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/clip_copy.gif','width="12" height="12"').' border="0" alt="" /><input type="Checkbox" name="_copyResource['.$params["name"].']" value="'.htmlspecialchars($copyFile).'" onClick="uFormUrl('.$aname.');if (this.checked) {alert(unescape(\''.rawurlencode(sprintf("This will make a copy of the current file, '%s'. Do you really want that?",$params["value"])).'\'));}">';
                                                                                }
                                                                                        // Upload?
                                                                                $p_field.='<BR>';
-                                                                               $p_field.='<input type="file" name="upload_'.$fN.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth().' onChange="uFormUrl('.$aname.')">';
+                                                                               $p_field.='<input type="file" name="upload_'.$fN.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth().' onChange="uFormUrl('.$aname.')" size="50" />';
                                                                        }
                                                                break;
+                                                               case 'small':
                                                                default:
-                                                               case "small":
                                                                        $fwidth= $typeDat["type"]=="small" ? 10 : 46;
                                                                        $p_field='<input type="text" name="'.$fN.'" value="'.$fV.'"'.$GLOBALS["TBE_TEMPLATE"]->formWidth($fwidth).' onChange="uFormUrl('.$aname.')">';
                                                                break;
@@ -977,14 +1281,14 @@ class t3lib_tsparser_ext extends t3lib_TStemplate        {
                                                if ($typeDat["type"]=="color" && substr($params["value"],0,2)!='{$')    {
                                                        $p_field='<table border=0 cellpadding=0 cellspacing=0><tr><td nowrap>'.$p_field.'</td><td>&nbsp;</td><td bgcolor="'.$params["value"].'"><img src="clear.gif" width=50 height=10></td></tr></table>';
                                                } else {
-                                                       $p_field='<nobr>'.$p_field.'</nobr><br>';
+                                                       $p_field='<span class="nobr">'.$p_field.'</span><br />';
                                                }
-       
-                                               $p_name = '<font color="#666666">['.$params["name"].']</font><BR>';
-                                               $p_dlabel='<font color="#666666"><b>Default:</b> '.htmlspecialchars($params["default_value"]).'</font><BR>';                    
+
+                                               $p_name = '<span class="typo3-dimmed">['.$params["name"].']</span><BR>';
+                                               $p_dlabel='<span class="typo3-dimmed"><b>Default:</b> '.htmlspecialchars($params["default_value"]).'</span><BR>';
                                                $p_label = '<b>'.htmlspecialchars($head).'</b>';
                                                $p_descrip = $body ? htmlspecialchars($body)."<BR>" : "";
-                                               
+
                                                $output.='<tr>';
                                                $output.='<td valign=top nowrap><a name="'.$raname.'"></a>'.$help["constants"][$params["name"]].$p_label.'</td>';
                                                $output.='<td valign=top align="right">'.$p_name.'</td>';
@@ -1002,9 +1306,27 @@ class t3lib_tsparser_ext extends t3lib_TStemplate        {
                return $output;
        }
 
-               // ***************************
-               // Processing input values
-               // ***************************
+
+
+
+
+
+
+
+
+
+
+
+       /***************************
+        *
+        * Processing input values
+        *
+        ***************************/
+
+       /**
+        * @param       [type]          $constants: ...
+        * @return      [type]          ...
+        */
        function ext_regObjectPositions($constants)     {
                        // This runs through the lines of the constants-field of the active template and registers the constants-names and linepositions in an array, $this->objReg
                $this->raw = explode(chr(10),$constants);
@@ -1013,6 +1335,13 @@ class t3lib_tsparser_ext extends t3lib_TStemplate        {
                $this->objReg=array();          // resetting the objReg if the divider is found!!
                $this->ext_regObjects("");
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $pre: ...
+        * @return      [type]          ...
+        */
        function ext_regObjects($pre)   {
                        // works with regObjectPositions. "expands" the names of the TypoScript objects
                while (isset($this->raw[$this->rawP]))  {
@@ -1050,8 +1379,16 @@ class t3lib_tsparser_ext extends t3lib_TStemplate        {
                        }
                }
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $key: ...
+        * @param       [type]          $var: ...
+        * @return      [type]          ...
+        */
        function ext_putValueInConf($key, $var) {
-                       // Puts the value $var to the TypoScript value $key in the current lines of the templates. 
+                       // Puts the value $var to the TypoScript value $key in the current lines of the templates.
                        // If the $key is not found in the template constants field, a new line is inserted in the bottom.
                $theValue = " ".trim($var);
                if (isset($this->objReg[$key])) {
@@ -1066,6 +1403,13 @@ class t3lib_tsparser_ext extends t3lib_TStemplate        {
                }
                $this->changed=1;
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $key: ...
+        * @return      [type]          ...
+        */
        function ext_removeValueInConf($key)    {
                        // Removes the value in the configuration
                if (isset($this->objReg[$key])) {
@@ -1074,6 +1418,14 @@ class t3lib_tsparser_ext extends t3lib_TStemplate        {
                }
                $this->changed=1;
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $arr: ...
+        * @param       [type]          $settings: ...
+        * @return      [type]          ...
+        */
        function ext_depthKeys($arr,$settings)  {
                reset($arr);
                $tsbrArray=array();
@@ -1099,6 +1451,16 @@ class t3lib_tsparser_ext extends t3lib_TStemplate        {
                }
                return $settings;
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $http_post_vars: ...
+        * @param       [type]          $http_post_files: ...
+        * @param       [type]          $theConstants: ...
+        * @param       [type]          $tplRow: ...
+        * @return      [type]          ...
+        */
        function ext_procesInput($http_post_vars,$http_post_files,$theConstants,$tplRow)        {
                $data=$http_post_vars["data"];
                $check=$http_post_vars["check"];
@@ -1114,7 +1476,7 @@ class t3lib_tsparser_ext extends t3lib_TStemplate {
                        while(list($key,$var)=each($data))      {
                                if (isset($theConstants[$key])) {
                                        if ($this->ext_dontCheckIssetValues || isset($check[$key]))     {               // If checkbox is set, update the value
-                                               list($var) = explode(chr(10),stripslashes($var));       // exploding with linebreak, just to make sure that no multiline input is given!
+                                               list($var) = explode(chr(10),$var);     // exploding with linebreak, just to make sure that no multiline input is given!
                                                $typeDat=$this->ext_getTypeData($theConstants[$key]["type"]);
                                                switch($typeDat["type"])        {
                                                        case "int":
@@ -1146,7 +1508,7 @@ class t3lib_tsparser_ext extends t3lib_TStemplate {
                                                        break;
                                                        case "wrap":
                                                                if (isset($Wdata[$key]))        {
-                                                                       $var.="|".stripslashes($Wdata[$key]);
+                                                                       $var.="|".$Wdata[$key];
                                                                }
                                                        break;
                                                        case "offset":
@@ -1216,7 +1578,18 @@ class t3lib_tsparser_ext extends t3lib_TStemplate        {
                }
 //             debug($this->objReg);
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $typeDat: ...
+        * @param       [type]          $tplRow: ...
+        * @param       [type]          $theRealFileName: ...
+        * @param       [type]          $tmp_name: ...
+        * @return      [type]          ...
+        */
        function upload_copy_file($typeDat,&$tplRow,$theRealFileName,$tmp_name) {
+
                        // extensions
                $extList = $typeDat["paramstr"];
                if ($extList=="IMAGE_EXT")      {
@@ -1224,12 +1597,14 @@ class t3lib_tsparser_ext extends t3lib_TStemplate       {
                }
                $fI=t3lib_div::split_fileref($theRealFileName);
                if ($theRealFileName && (!$extList || t3lib_div::inList($extList,$fI["fileext"])))      {
+                       $tmp_upload_name = t3lib_div::upload_to_tempfile($tmp_name);    // If there is an uploaded file, move it for the sake of safe_mode.
+
                                // Saving resource
                        $alternativeFileName=array();
-                       $alternativeFileName[$tmp_name] = $theRealFileName;
+                       $alternativeFileName[$tmp_upload_name] = $theRealFileName;
                                // Making list of resources
                        $resList = $tplRow["resources"];
-                       $resList = $tmp_name.",".$resList;
+                       $resList = $tmp_upload_name.",".$resList;
                        $resList=implode(t3lib_div::trimExplode(",",$resList,1),",");
                                // Making data-array
                        $recData=array();
@@ -1240,7 +1615,9 @@ class t3lib_tsparser_ext extends t3lib_TStemplate {
                        $tce->alternativeFileName = $alternativeFileName;
                        $tce->start($recData,Array());
                        $tce->process_datamap();
-                       
+
+                       t3lib_div::unlink_tempfile($tmp_upload_name);
+
                        $tmpRow = t3lib_BEfunc::getRecord("sys_template",$tplRow["uid"],"resources");
                        $tplRow["resources"] = $tmpRow["resources"];
 
@@ -1249,6 +1626,14 @@ class t3lib_tsparser_ext extends t3lib_TStemplate        {
                }
                return $var;
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $id: ...
+        * @param       [type]          $perms_clause: ...
+        * @return      [type]          ...
+        */
        function ext_prevPageWithTemplate($id,$perms_clause)    {
                $rootLine = t3lib_BEfunc::BEgetRootLine($id,$perms_clause?" AND ".$perms_clause:"");
                reset($rootLine);
@@ -1258,11 +1643,25 @@ class t3lib_tsparser_ext extends t3lib_TStemplate       {
                        }
                }
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $val: ...
+        * @return      [type]          ...
+        */
        function ext_setStar($val)      {
                $fParts = explode(".",strrev($val),2);
                $val=ereg_replace("_[0-9][0-9]$","",strrev($fParts[1]))."*.".strrev($fParts[0]);
-               return $val;    
+               return $val;
        }
+
+       /**
+        * [Describe function...]
+        *
+        * @param       [type]          $value: ...
+        * @return      [type]          ...
+        */
        function ext_detectAndFixExtensionPrefix($value)        {
                if (substr($value,0,4)=="EXT:") {
                        $parts = explode("/",substr($value,4),2);
@@ -1277,7 +1676,7 @@ class t3lib_tsparser_ext extends t3lib_TStemplate {
 }
 
 
-if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["t3lib/class.t3lib_tsparser_ext.php"])     {
-       include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["t3lib/class.t3lib_tsparser_ext.php"]);
+if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsparser_ext.php'])     {
+       include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsparser_ext.php']);
 }
 ?>
\ No newline at end of file