Fixed bug #15580: Add calls to logDeprecatedFunction() for more deprecated functions...
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / class.tslib_pibase.php
old mode 100755 (executable)
new mode 100644 (file)
index d0597e7..7f2e984
@@ -1,22 +1,22 @@
 <?php
 /***************************************************************
 *  Copyright notice
 <?php
 /***************************************************************
 *  Copyright notice
-*  
-*  (c) 1999-2004 Kasper Skaarhoj (kasper@typo3.com)
+*
+*  (c) 1999-2010 Kasper Skårhøj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  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.
 *  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.
 *  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.
 *
 *  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 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!
 ***************************************************************/
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/
-/** 
+/**
  * This script contains the parent class, 'pibase', providing an API with the most basic methods for frontend plugins
  *
  * $Id$
  * This script contains the parent class, 'pibase', providing an API with the most basic methods for frontend plugins
  *
  * $Id$
- * Revised for TYPO3 3.6 June/2003 by Kasper Skaarhoj
+ * Revised for TYPO3 3.6 June/2003 by Kasper Skårhøj
  * XHTML compliant
  *
  * XHTML compliant
  *
- * @author     Kasper Skaarhoj <kasper@typo3.com>
+ * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
  */
 /**
  * [CLASS/FUNCTION INDEX of SCRIPT]
  *
  *
  *
  */
 /**
  * [CLASS/FUNCTION INDEX of SCRIPT]
  *
  *
  *
- *  132: class tslib_pibase 
+ *  132: class tslib_pibase
  *
  *              SECTION: Init functions
  *
  *              SECTION: Init functions
- *  211:     function tslib_pibase()   
- *  225:     function pi_setPiVarDefaults()    
+ *  214:     function tslib_pibase()
+ *  240:     function pi_setPiVarDefaults()
  *
  *              SECTION: Link functions
  *
  *              SECTION: Link functions
- *  264:     function pi_getPageLink($id,$target='',$urlParameters=array())    
- *  280:     function pi_linkToPage($str,$id,$target='',$urlParameters=array())        
- *  295:     function pi_linkTP($str,$urlParameters=array(),$cache=0,$altPageId=0)     
- *  318:     function pi_linkTP_keepPIvars($str,$overrulePIvars=array(),$cache=0,$clearAnyway=0,$altPageId=0)  
- *  342:     function pi_linkTP_keepPIvars_url($overrulePIvars=array(),$cache=0,$clearAnyway=0,$altPageId=0)   
- *  360:     function pi_list_linkSingle($str,$uid,$cache=FALSE,$mergeArr=array(),$urlOnly=FALSE,$altPageId=0) 
- *  388:     function pi_openAtagHrefInJSwindow($str,$winName='',$winParams='width=670,height=500,status=0,menubar=0,scrollbars=1,resizable=1')        
+ *  277:     function pi_getPageLink($id,$target='',$urlParameters=array())
+ *  293:     function pi_linkToPage($str,$id,$target='',$urlParameters=array())
+ *  308:     function pi_linkTP($str,$urlParameters=array(),$cache=0,$altPageId=0)
+ *  331:     function pi_linkTP_keepPIvars($str,$overrulePIvars=array(),$cache=0,$clearAnyway=0,$altPageId=0)
+ *  355:     function pi_linkTP_keepPIvars_url($overrulePIvars=array(),$cache=0,$clearAnyway=0,$altPageId=0)
+ *  373:     function pi_list_linkSingle($str,$uid,$cache=FALSE,$mergeArr=array(),$urlOnly=FALSE,$altPageId=0)
+ *  401:     function pi_openAtagHrefInJSwindow($str,$winName='',$winParams='width=670,height=500,status=0,menubar=0,scrollbars=1,resizable=1')
  *
  *              SECTION: Functions for listing, browsing, searching etc.
  *
  *              SECTION: Functions for listing, browsing, searching etc.
- *  428:     function pi_list_browseresults($showResultCount=1,$tableParams='')        
- *  497:     function pi_list_searchBox($tableParams='')       
- *  525:     function pi_list_modeSelector($items=array(),$tableParams='')     
- *  563:     function pi_list_makelist($res,$tableParams='')   
- *  598:     function pi_list_row($c)  
- *  610:     function pi_list_header() 
+ *  456:     function pi_list_browseresults($showResultCount=1,$tableParams='',$wrapArr=array(), $pointerName = 'pointer', $hscText = TRUE)
+ *  618:     function pi_list_searchBox($tableParams='')
+ *  649:     function pi_list_modeSelector($items=array(),$tableParams='')
+ *  687:     function pi_list_makelist($res,$tableParams='')
+ *  722:     function pi_list_row($c)
+ *  734:     function pi_list_header()
  *
  *              SECTION: Stylesheet, CSS
  *
  *              SECTION: Stylesheet, CSS
- *  641:     function pi_getClassName($class)  
- *  653:     function pi_classParam($class)    
- *  667:     function pi_setClassStyle($class,$data,$selector='')      
- *  678:     function pi_wrapInBaseClass($str) 
+ *  765:     function pi_getClassName($class)
+ *  777:     function pi_classParam($class)
+ *  791:     function pi_setClassStyle($class,$data,$selector='')
+ *  802:     function pi_wrapInBaseClass($str)
  *
  *              SECTION: Frontend editing: Edit panel, edit icons
  *
  *              SECTION: Frontend editing: Edit panel, edit icons
- *  727:     function pi_getEditPanel($row='',$tablename='',$label='',$conf=Array())   
- *  769:     function pi_getEditIcon($content,$fields,$title='',$row='',$tablename='',$oConf=array())  
+ *  858:     function pi_getEditPanel($row='',$tablename='',$label='',$conf=Array())
+ *  900:     function pi_getEditIcon($content,$fields,$title='',$row='',$tablename='',$oConf=array())
  *
  *              SECTION: Localization, locallang functions
  *
  *              SECTION: Localization, locallang functions
- *  816:     function pi_getLL($key,$alt='',$hsc=FALSE)        
- *  837:     function pi_loadLL()      
+ *  947:     function pi_getLL($key,$alt='',$hsc=FALSE)
+ *  970:     function pi_loadLL()
  *
  *              SECTION: Database, queries
  *
  *              SECTION: Database, queries
- *  902:     function pi_list_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='',$returnQueryArray=FALSE) 
- *  994:     function pi_exec_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='') 
- * 1009:     function pi_getRecord($table,$uid,$checkPage=0)   
- * 1020:     function pi_getPidList($pid_list,$recursive=0)    
- * 1041:     function pi_prependFieldsWithTable($table,$fieldList)     
- * 1061:     function pi_getCategoryTableContents($table,$pid,$whereClause='',$groupBy='',$orderBy='',$limit='')       
+ * 1048:     function pi_list_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='',$returnQueryArray=FALSE)
+ * 1140:     function pi_exec_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='')
+ * 1155:     function pi_getRecord($table,$uid,$checkPage=0)
+ * 1166:     function pi_getPidList($pid_list,$recursive=0)
+ * 1191:     function pi_prependFieldsWithTable($table,$fieldList)
+ * 1211:     function pi_getCategoryTableContents($table,$pid,$whereClause='',$groupBy='',$orderBy='',$limit='')
  *
  *              SECTION: Various
  *
  *              SECTION: Various
- * 1105:     function pi_isOnlyFields($fList,$lowerThan=-1)    
- * 1125:     function pi_autoCache($inArray)   
- * 1156:     function pi_RTEcssText($str)      
+ * 1255:     function pi_isOnlyFields($fList,$lowerThan=-1)
+ * 1275:     function pi_autoCache($inArray)
+ * 1306:     function pi_RTEcssText($str)
  *
  *              SECTION: FlexForms related functions
  *
  *              SECTION: FlexForms related functions
- * 1177:     function pi_initPIflexForm()      
- * 1195:     function pi_getFFvalue($T3FlexForm_array,$fieldName,$sheet='sDEF',$lang='lDEF',$value='vDEF')     
- * 1212:     function pi_getFFvalueFromSheetArray($sheetArray,$fieldNameArr,$value)    
+ * 1328:     function pi_initPIflexForm($field='pi_flexform')
+ * 1346:     function pi_getFFvalue($T3FlexForm_array,$fieldName,$sheet='sDEF',$lang='lDEF',$value='vDEF')
+ * 1363:     function pi_getFFvalueFromSheetArray($sheetArray,$fieldNameArr,$value)
  *
  * TOTAL FUNCTIONS: 35
  * (This index is automatically created/updated by the extension "extdeveval")
  *
  * TOTAL FUNCTIONS: 35
  * (This index is automatically created/updated by the extension "extdeveval")
 
 
 
 
 
 
-
-
-
-
-
-
-
-
-
-
-
 /**
  * Base class for frontend plugins
  * Most modern frontend plugins are extension classes of this one.
  * This class contains functions which assists these plugins in creating lists, searching, displaying menus, page-browsing (next/previous/1/2/3) and handling links.
  * Functions are all prefixed "pi_" which is reserved for this class. Those functions can of course be overridden in the extension classes (that is the point...)
  *
 /**
  * Base class for frontend plugins
  * Most modern frontend plugins are extension classes of this one.
  * This class contains functions which assists these plugins in creating lists, searching, displaying menus, page-browsing (next/previous/1/2/3) and handling links.
  * Functions are all prefixed "pi_" which is reserved for this class. Those functions can of course be overridden in the extension classes (that is the point...)
  *
- * @author     Kasper Skaarhoj <kasper@typo3.com>
+ * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage tslib
  */
 class tslib_pibase {
 
                // Reserved variables:
  * @package TYPO3
  * @subpackage tslib
  */
 class tslib_pibase {
 
                // Reserved variables:
-       var $cObj;                      // The backReference to the mother cObj object set at call time
+       /**
+        * The backReference to the mother cObj object set at call time
+        *
+        * @var tslib_cObj
+        */
+       var $cObj;
        var $prefixId;          // Should be same as classname of the plugin, used for CSS classes, variables
        var $scriptRelPath;     // Path to the plugin class script relative to extension directory, eg. 'pi1/class.tx_newfaq_pi1.php'
        var $extKey;            // Extension key.
        var $prefixId;          // Should be same as classname of the plugin, used for CSS classes, variables
        var $scriptRelPath;     // Path to the plugin class script relative to extension directory, eg. 'pi1/class.tx_newfaq_pi1.php'
        var $extKey;            // Extension key.
-       var $piVars = Array (   // This is the incomming array by name $this->prefixId merged between POST and GET, POST taking precedence. Eg. if the class name is 'tx_myext' then the content of this array will be whatever comes into &tx_myext[...]=...
-               'pointer' => '',                        // Used as a pointer for lists
-               'mode' => '',                           // List mode
-               'sword' => '',                          // Search word
-               'sort' => '',                           // [Sorting column]:[ASC=0/DESC=1]
+       var $piVars = Array (   // This is the incoming array by name $this->prefixId merged between POST and GET, POST taking precedence. Eg. if the class name is 'tx_myext' then the content of this array will be whatever comes into &tx_myext[...]=...
+               'pointer' => '',                // Used as a pointer for lists
+               'mode' => '',                   // List mode
+               'sword' => '',                  // Search word
+               'sort' => '',                   // [Sorting column]:[ASC=0/DESC=1]
        );
        var $internal = Array(  // Used internally for general storage of values between methods
        );
        var $internal = Array(  // Used internally for general storage of values between methods
-               'res_count' => 0,                       // Total query count
+               'res_count' => 0,               // Total query count
                'results_at_a_time' => 20,      // pi_list_browseresults(): Show number of results at a time
                'results_at_a_time' => 20,      // pi_list_browseresults(): Show number of results at a time
-               'maxPages' => 10,                       // pi_list_browseresults(): Max number of 'Page 1 - Page 2 - ...' in the list browser
+               'maxPages' => 10,               // pi_list_browseresults(): Max number of 'Page 1 - Page 2 - ...' in the list browser
                'currentRow' => Array(),        // Current result row
                'currentTable' => '',           // Current table
        );
 
                'currentRow' => Array(),        // Current result row
                'currentTable' => '',           // Current table
        );
 
-       var $LOCAL_LANG = Array();      // Local Language content
-       var $LOCAL_LANG_loaded = 0;     // Flag that tells if the locallang file has been fetch (or tried to be fetched) already.
-       var $LLkey='default';           // Pointer to the language to use.
-       var $LLtestPrefix='';           // You can set this during development to some value that makes it easy for you to spot all labels that ARe delivered by the getLL function.
-       var $LLtestPrefixAlt='';        // Save as LLtestPrefix, but additional prefix for the alternative value in getLL() function calls
+       var $LOCAL_LANG = Array();              // Local Language content
+       var $LOCAL_LANG_charset = Array();      // Local Language content charset for individual labels (overriding)
+       var $LOCAL_LANG_loaded = 0;             // Flag that tells if the locallang file has been fetch (or tried to be fetched) already.
+       var $LLkey='default';                   // Pointer to the language to use.
+       var $altLLkey='';                       // Pointer to alternative fall-back language to use.
+       var $LLtestPrefix='';                   // You can set this during development to some value that makes it easy for you to spot all labels that ARe delivered by the getLL function.
+       var $LLtestPrefixAlt='';                // Save as LLtestPrefix, but additional prefix for the alternative value in getLL() function calls
 
        var $pi_isOnlyFields = 'mode,pointer';
        var $pi_alwaysPrev = 0;
        var $pi_lowerThan = 5;
        var $pi_moreParams='';
        var $pi_listFields='*';
 
        var $pi_isOnlyFields = 'mode,pointer';
        var $pi_alwaysPrev = 0;
        var $pi_lowerThan = 5;
        var $pi_moreParams='';
        var $pi_listFields='*';
-       
+
        var $pi_autoCacheFields=array();
        var $pi_autoCacheEn=0;
        var $pi_autoCacheFields=array();
        var $pi_autoCacheEn=0;
-       
-       var $pi_USER_INT_obj = 0;       // If set, then links are 1) not using cHash and 2) allowing pages to be cached.
-       
+
+       var $pi_USER_INT_obj = FALSE;           // If set, then links are 1) not using cHash and 2) not allowing pages to be cached. (Set this for all USER_INT plugins!)
+       var $pi_checkCHash = FALSE;             // If set, then caching is disabled if piVars are incoming while no cHash was set (Set this for all USER plugins!)
+
        /**
         * Should normally be set in the main function with the TypoScript content passed to the method.
        /**
         * Should normally be set in the main function with the TypoScript content passed to the method.
-        * 
+        *
         * $conf[LOCAL_LANG][_key_] is reserved for Local Language overrides.
         * $conf[userFunc] / $conf[includeLibs]  reserved for setting up the USER / USER_INT object. See TSref
         * $conf[LOCAL_LANG][_key_] is reserved for Local Language overrides.
         * $conf[userFunc] / $conf[includeLibs]  reserved for setting up the USER / USER_INT object. See TSref
-        */ 
-       var $conf = Array();    
-       
+        */
+       var $conf = Array();
+
        // internal, don't mess with...
        // internal, don't mess with...
-       var $pi_EPtemp_cObj;    
+       var $pi_EPtemp_cObj;
        var $pi_tmpPageId=0;
 
        var $pi_tmpPageId=0;
 
-       
-       
+
+
 
 
 
 
 
 
@@ -196,7 +193,7 @@ class tslib_pibase {
 
 
        /***************************
 
 
        /***************************
-        * 
+        *
         * Init functions
         *
         **************************/
         * Init functions
         *
         **************************/
@@ -209,11 +206,23 @@ class tslib_pibase {
         * @return      void
         */
        function tslib_pibase() {
         * @return      void
         */
        function tslib_pibase() {
+
+                       // Setting piVars:
                if ($this->prefixId)    {
                if ($this->prefixId)    {
-                       $this->piVars = t3lib_div::GParrayMerged($this->prefixId);
+                       $this->piVars = t3lib_div::_GPmerged($this->prefixId);
+
+                               // cHash mode check
+                               // IMPORTANT FOR CACHED PLUGINS (USER cObject): As soon as you generate cached plugin output which depends on parameters (eg. seeing the details of a news item) you MUST check if a cHash value is set.
+                               // Background: The function call will check if a cHash parameter was sent with the URL because only if it was the page may be cached. If no cHash was found the function will simply disable caching to avoid unpredictable caching behaviour. In any case your plugin can generate the expected output and the only risk is that the content may not be cached. A missing cHash value is considered a mistake in the URL resulting from either URL manipulation, "realurl" "grayzones" etc. The problem is rare (more frequent with "realurl") but when it occurs it is very puzzling!
+                       if ($this->pi_checkCHash && count($this->piVars))       {
+                               $GLOBALS['TSFE']->reqCHash();
+                       }
                }
                }
-               if ($GLOBALS['TSFE']->config['config']['language'])     {
+               if (!empty($GLOBALS['TSFE']->config['config']['language'])) {
                        $this->LLkey = $GLOBALS['TSFE']->config['config']['language'];
                        $this->LLkey = $GLOBALS['TSFE']->config['config']['language'];
+                       if (!empty($GLOBALS['TSFE']->config['config']['language_alt'])) {
+                               $this->altLLkey = $GLOBALS['TSFE']->config['config']['language_alt'];
+                       }
                }
        }
 
                }
        }
 
@@ -229,8 +238,6 @@ class tslib_pibase {
        }
 
 
        }
 
 
-       
-
 
 
 
 
 
 
@@ -243,7 +250,7 @@ class tslib_pibase {
 
 
        /***************************
 
 
        /***************************
-        * 
+        *
         * Link functions
         *
         **************************/
         * Link functions
         *
         **************************/
@@ -268,7 +275,7 @@ class tslib_pibase {
        /**
         * Link a string to some page.
         * Like pi_getPageLink() but takes a string as first parameter which will in turn be wrapped with the URL including target attribute
        /**
         * Link a string to some page.
         * Like pi_getPageLink() but takes a string as first parameter which will in turn be wrapped with the URL including target attribute
-        * Simple example: $this->pi_getPageLink('My link', 123) to get something like <a href="index.php?id=123&type=1">My link</a> (or <a href="123.1.html">My link</a> if simulateStaticDocuments is set)
+        * Simple example: $this->pi_linkToPage('My link', 123) to get something like <a href="index.php?id=123&type=1">My link</a> (or <a href="123.1.html">My link</a> if simulateStaticDocuments is set)
         *
         * @param       string          The content string to wrap in <a> tags
         * @param       integer         Page id
         *
         * @param       string          The content string to wrap in <a> tags
         * @param       integer         Page id
@@ -297,8 +304,8 @@ class tslib_pibase {
                $conf['useCacheHash'] = $this->pi_USER_INT_obj ? 0 : $cache;
                $conf['no_cache'] = $this->pi_USER_INT_obj ? 0 : !$cache;
                $conf['parameter'] = $altPageId ? $altPageId : ($this->pi_tmpPageId ? $this->pi_tmpPageId : $GLOBALS['TSFE']->id);
                $conf['useCacheHash'] = $this->pi_USER_INT_obj ? 0 : $cache;
                $conf['no_cache'] = $this->pi_USER_INT_obj ? 0 : !$cache;
                $conf['parameter'] = $altPageId ? $altPageId : ($this->pi_tmpPageId ? $this->pi_tmpPageId : $GLOBALS['TSFE']->id);
-               $conf['additionalParams'] = $this->conf['parent.']['addParams'].t3lib_div::implodeArrayForUrl('',$urlParameters,'',1).$this->pi_moreParams;
-               
+               $conf['additionalParams'] = $this->conf['parent.']['addParams'].t3lib_div::implodeArrayForUrl('', $urlParameters, '', true).$this->pi_moreParams;
+
                return $this->cObj->typoLink($str, $conf);
        }
 
                return $this->cObj->typoLink($str, $conf);
        }
 
@@ -361,14 +368,14 @@ class tslib_pibase {
                if ($this->prefixId)    {
                        if ($cache)     {
                                $overrulePIvars=$uid?array('showUid'=>$uid):Array();
                if ($this->prefixId)    {
                        if ($cache)     {
                                $overrulePIvars=$uid?array('showUid'=>$uid):Array();
-                               $overrulePIvars=array_merge($overrulePIvars,$mergeArr);
+                               $overrulePIvars=array_merge($overrulePIvars,(array)$mergeArr);
                                $str = $this->pi_linkTP($str,Array($this->prefixId=>$overrulePIvars),$cache,$altPageId);
                        } else {
                                $overrulePIvars=array('showUid'=>$uid?$uid:'');
                                $str = $this->pi_linkTP($str,Array($this->prefixId=>$overrulePIvars),$cache,$altPageId);
                        } else {
                                $overrulePIvars=array('showUid'=>$uid?$uid:'');
-                               $overrulePIvars=array_merge($overrulePIvars,$mergeArr);
+                               $overrulePIvars=array_merge($overrulePIvars,(array)$mergeArr);
                                $str = $this->pi_linkTP_keepPIvars($str,$overrulePIvars,$cache,0,$altPageId);
                        }
                                $str = $this->pi_linkTP_keepPIvars($str,$overrulePIvars,$cache,0,$altPageId);
                        }
-                       
+
                                // If urlOnly flag, return only URL as it has recently be generated.
                        if ($urlOnly)   {
                                $str = $this->cObj->lastTypoLinkUrl;
                                // If urlOnly flag, return only URL as it has recently be generated.
                        if ($urlOnly)   {
                                $str = $this->cObj->lastTypoLinkUrl;
@@ -386,10 +393,10 @@ class tslib_pibase {
         * @return      string          The processed input string, modified IF a <a> tag was found
         */
        function pi_openAtagHrefInJSwindow($str,$winName='',$winParams='width=670,height=500,status=0,menubar=0,scrollbars=1,resizable=1')      {
         * @return      string          The processed input string, modified IF a <a> tag was found
         */
        function pi_openAtagHrefInJSwindow($str,$winName='',$winParams='width=670,height=500,status=0,menubar=0,scrollbars=1,resizable=1')      {
-               if (eregi('(.*)(<a[^>]*>)(.*)',$str,$match))    {
+               if (preg_match('/(.*)(<a[^>]*>)(.*)/i',$str,$match))    {
                        $aTagContent = t3lib_div::get_tag_attributes($match[2]);
                        $match[2]='<a href="#" onclick="'.
                        $aTagContent = t3lib_div::get_tag_attributes($match[2]);
                        $match[2]='<a href="#" onclick="'.
-                               htmlspecialchars('vHWin=window.open(\''.$aTagContent['href'].'\',\''.($winName?$winName:md5($aTagContent['href'])).'\',\''.$winParams.'\');vHWin.focus();return false;').
+                               htmlspecialchars('vHWin=window.open(\''.$GLOBALS['TSFE']->baseUrlWrap($aTagContent['href']).'\',\''.($winName?$winName:md5($aTagContent['href'])).'\',\''.$winParams.'\');vHWin.focus();return false;').
                                '">';
                        $str=$match[1].$match[2].$match[3];
                }
                                '">';
                        $str=$match[1].$match[2].$match[3];
                }
@@ -409,81 +416,192 @@ class tslib_pibase {
 
 
 
 
 
 
-
        /***************************
        /***************************
-        * 
+        *
         * Functions for listing, browsing, searching etc.
         *
         **************************/
 
        /**
         * Returns a results browser. This means a bar of page numbers plus a "previous" and "next" link. For each entry in the bar the piVars "pointer" will be pointing to the "result page" to show.
         * Functions for listing, browsing, searching etc.
         *
         **************************/
 
        /**
         * Returns a results browser. This means a bar of page numbers plus a "previous" and "next" link. For each entry in the bar the piVars "pointer" will be pointing to the "result page" to show.
-        * Using $this->piVars['pointer'] as pointer to the page to display
+        * Using $this->piVars['pointer'] as pointer to the page to display. Can be overwritten with another string ($pointerName) to make it possible to have more than one pagebrowser on a page)
         * Using $this->internal['res_count'], $this->internal['results_at_a_time'] and $this->internal['maxPages'] for count number, how many results to show and the max number of pages to include in the browse bar.
         * Using $this->internal['res_count'], $this->internal['results_at_a_time'] and $this->internal['maxPages'] for count number, how many results to show and the max number of pages to include in the browse bar.
+        * Using $this->internal['dontLinkActivePage'] as switch if the active (current) page should be displayed as pure text or as a link to itself
+        * Using $this->internal['showFirstLast'] as switch if the two links named "<< First" and "LAST >>" will be shown and point to the first or last page.
+        * Using $this->internal['pagefloat']: this defines were the current page is shown in the list of pages in the Pagebrowser. If this var is an integer it will be interpreted as position in the list of pages. If its value is the keyword "center" the current page will be shown in the middle of the pagelist.
+        * Using $this->internal['showRange']: this var switches the display of the pagelinks from pagenumbers to ranges f.e.: 1-5 6-10 11-15... instead of 1 2 3...
+        * Using $this->pi_isOnlyFields: this holds a comma-separated list of fieldnames which - if they are among the GETvars - will not disable caching for the page with pagebrowser.
         *
         *
-        * @param       boolean         If set (default) the text "Displaying results..." will be show, otherwise not.
+        * The third parameter is an array with several wraps for the parts of the pagebrowser. The following elements will be recognized:
+        * disabledLinkWrap, inactiveLinkWrap, activeLinkWrap, browseLinksWrap, showResultsWrap, showResultsNumbersWrap, browseBoxWrap.
+        *
+        * If $wrapArr['showResultsNumbersWrap'] is set, the formatting string is expected to hold template markers (###FROM###, ###TO###, ###OUT_OF###, ###FROM_TO###, ###CURRENT_PAGE###, ###TOTAL_PAGES###)
+        * otherwise the formatting string is expected to hold sprintf-markers (%s) for from, to, outof (in that sequence)
+        *
+        * @param       integer         determines how the results of the pagerowser will be shown. See description below
         * @param       string          Attributes for the table tag which is wrapped around the table cells containing the browse links
         * @param       string          Attributes for the table tag which is wrapped around the table cells containing the browse links
-        * @return      string          Output HTML, wrapped in <div>-tags with a class attribute
+        * @param       array           Array with elements to overwrite the default $wrapper-array.
+        * @param       string          varname for the pointer.
+        * @param       boolean         enable htmlspecialchars() for the pi_getLL function (set this to FALSE if you want f.e use images instead of text for links like 'previous' and 'next').
+        * @param   boolean     forces the output of the page browser if you set this option to "true" (otherwise it's only drawn if enough entries are available)
+        * @return      string          Output HTML-Table, wrapped in <div>-tags with a class attribute (if $wrapArr is not passed,
         */
         */
-       function pi_list_browseresults($showResultCount=1,$tableParams='')      {
-                       
+       function pi_list_browseresults($showResultCount=1, $tableParams='', $wrapArr=array(), $pointerName='pointer', $hscText=TRUE, $forceOutput=FALSE) {
+
+               // example $wrapArr-array how it could be traversed from an extension
+               /* $wrapArr = array(
+                       'browseBoxWrap' => '<div class="browseBoxWrap">|</div>',
+                       'showResultsWrap' => '<div class="showResultsWrap">|</div>',
+                       'browseLinksWrap' => '<div class="browseLinksWrap">|</div>',
+                       'showResultsNumbersWrap' => '<span class="showResultsNumbersWrap">|</span>',
+                       'disabledLinkWrap' => '<span class="disabledLinkWrap">|</span>',
+                       'inactiveLinkWrap' => '<span class="inactiveLinkWrap">|</span>',
+                       'activeLinkWrap' => '<span class="activeLinkWrap">|</span>'
+               ); */
+
                        // Initializing variables:
                        // Initializing variables:
-               $pointer=$this->piVars['pointer'];
-               $count=$this->internal['res_count'];
+               $pointer = intval($this->piVars[$pointerName]);
+               $count = intval($this->internal['res_count']);
                $results_at_a_time = t3lib_div::intInRange($this->internal['results_at_a_time'],1,1000);
                $results_at_a_time = t3lib_div::intInRange($this->internal['results_at_a_time'],1,1000);
+               $totalPages = ceil($count/$results_at_a_time);
                $maxPages = t3lib_div::intInRange($this->internal['maxPages'],1,100);
                $maxPages = t3lib_div::intInRange($this->internal['maxPages'],1,100);
-               $max = t3lib_div::intInRange(ceil($count/$results_at_a_time),1,$maxPages);
-               $pointer=intval($pointer);
-               $links=array();
-
-                       // Make browse-table/links:     
-               if ($this->pi_alwaysPrev>=0)    {
-                       if ($pointer>0) {
-                               $links[]='
-                                       <td nowrap="nowrap"><p>'.$this->pi_linkTP_keepPIvars($this->pi_getLL('pi_list_browseresults_prev','< Previous',TRUE),array('pointer'=>($pointer-1?$pointer-1:'')),0).'</p></td>';
-                       } elseif ($this->pi_alwaysPrev) {
-                               $links[]='
-                                       <td nowrap="nowrap"><p>'.$this->pi_getLL('pi_list_browseresults_prev','< Previous',TRUE).'</p></td>';
-                       }
-               }
-               for($a=0;$a<$max;$a++)  {
-                       $links[]='
-                                       <td'.($pointer==$a?$this->pi_classParam('browsebox-SCell'):'').' nowrap="nowrap"><p>'.
-                               $this->pi_linkTP_keepPIvars(trim($this->pi_getLL('pi_list_browseresults_page','Page',TRUE).' '.($a+1)),array('pointer'=>($a?$a:'')),$this->pi_isOnlyFields($this->pi_isOnlyFields)).
-                               '</p></td>';
+               $pi_isOnlyFields = $this->pi_isOnlyFields($this->pi_isOnlyFields);
+
+               if (!$forceOutput && $count <= $results_at_a_time) {
+                       return '';
                }
                }
-               if ($pointer<ceil($count/$results_at_a_time)-1) {
-                       $links[]='
-                                       <td nowrap="nowrap"><p>'.
-                               $this->pi_linkTP_keepPIvars($this->pi_getLL('pi_list_browseresults_next','Next >',TRUE),array('pointer'=>$pointer+1)).
-                               '</p></td>';
+
+                       // $showResultCount determines how the results of the pagerowser will be shown.
+                       // If set to 0: only the result-browser will be shown
+                       //                       1: (default) the text "Displaying results..." and the result-browser will be shown.
+                       //                       2: only the text "Displaying results..." will be shown
+               $showResultCount = intval($showResultCount);
+
+                       // if this is set, two links named "<< First" and "LAST >>" will be shown and point to the very first or last page.
+               $showFirstLast = $this->internal['showFirstLast'];
+
+                       // if this has a value the "previous" button is always visible (will be forced if "showFirstLast" is set)
+               $alwaysPrev = $showFirstLast?1:$this->pi_alwaysPrev;
+
+               if (isset($this->internal['pagefloat'])) {
+                       if (strtoupper($this->internal['pagefloat']) == 'CENTER') {
+                               $pagefloat = ceil(($maxPages - 1)/2);
+                       } else {
+                               // pagefloat set as integer. 0 = left, value >= $this->internal['maxPages'] = right
+                               $pagefloat = t3lib_div::intInRange($this->internal['pagefloat'],-1,$maxPages-1);
+                       }
+               } else {
+                       $pagefloat = -1; // pagefloat disabled
                }
                }
-               
-               $pR1 = $pointer*$results_at_a_time+1;
-               $pR2 = $pointer*$results_at_a_time+$results_at_a_time;
-               $sTables = '
-               
+
+                       // default values for "traditional" wrapping with a table. Can be overwritten by vars from $wrapArr
+               $wrapper['disabledLinkWrap'] = '<td nowrap="nowrap"><p>|</p></td>';
+               $wrapper['inactiveLinkWrap'] = '<td nowrap="nowrap"><p>|</p></td>';
+               $wrapper['activeLinkWrap'] = '<td'.$this->pi_classParam('browsebox-SCell').' nowrap="nowrap"><p>|</p></td>';
+               $wrapper['browseLinksWrap'] = trim('<table '.$tableParams).'><tr>|</tr></table>';
+               $wrapper['showResultsWrap'] = '<p>|</p>';
+               $wrapper['browseBoxWrap'] = '
                <!--
                        List browsing box:
                <!--
                        List browsing box:
-               -->     
-               <div'.$this->pi_classParam('browsebox').'>'.
-                       ($showResultCount ? '
-                       <p>'.sprintf(
-                               str_replace('###SPAN_BEGIN###','<span'.$this->pi_classParam('browsebox-strong').'>',$this->pi_getLL('pi_list_browseresults_displays','Displaying results ###SPAN_BEGIN###%s to %s</span> out of ###SPAN_BEGIN###%s</span>')),
-                               $pR1,
-                               min(array($this->internal['res_count'],$pR2)),
-                               $this->internal['res_count']
-                               ).'</p>':''
-                       ).
-               '
-               
-                       <'.trim('table '.$tableParams).'>
-                               <tr>
-                                       '.implode('',$links).'
-                               </tr>
-                       </table>
+               -->
+               <div '.$this->pi_classParam('browsebox').'>
+                       |
                </div>';
                </div>';
-               
+
+                       // now overwrite all entries in $wrapper which are also in $wrapArr
+               $wrapper = array_merge($wrapper,$wrapArr);
+
+               if ($showResultCount != 2) { //show pagebrowser
+                       if ($pagefloat > -1) {
+                               $lastPage = min($totalPages,max($pointer+1 + $pagefloat,$maxPages));
+                               $firstPage = max(0,$lastPage-$maxPages);
+                       } else {
+                               $firstPage = 0;
+                               $lastPage = t3lib_div::intInRange($totalPages,1,$maxPages);
+                       }
+                       $links=array();
+
+                               // Make browse-table/links:
+                       if ($showFirstLast) { // Link to first page
+                               if ($pointer>0) {
+                                       $links[]=$this->cObj->wrap($this->pi_linkTP_keepPIvars($this->pi_getLL('pi_list_browseresults_first','<< First',$hscText),array($pointerName => null),$pi_isOnlyFields),$wrapper['inactiveLinkWrap']);
+                               } else {
+                                       $links[]=$this->cObj->wrap($this->pi_getLL('pi_list_browseresults_first','<< First',$hscText),$wrapper['disabledLinkWrap']);
+                               }
+                       }
+                       if ($alwaysPrev>=0)     { // Link to previous page
+                               if ($pointer>0) {
+                                       $links[]=$this->cObj->wrap($this->pi_linkTP_keepPIvars($this->pi_getLL('pi_list_browseresults_prev','< Previous',$hscText),array($pointerName => ($pointer-1?$pointer-1:'')),$pi_isOnlyFields),$wrapper['inactiveLinkWrap']);
+                               } elseif ($alwaysPrev)  {
+                                       $links[]=$this->cObj->wrap($this->pi_getLL('pi_list_browseresults_prev','< Previous',$hscText),$wrapper['disabledLinkWrap']);
+                               }
+                       }
+                       for($a=$firstPage;$a<$lastPage;$a++)    { // Links to pages
+                               if ($this->internal['showRange']) {
+                                       $pageText = (($a*$results_at_a_time)+1).'-'.min($count,(($a+1)*$results_at_a_time));
+                               } else {
+                                       $pageText = trim($this->pi_getLL('pi_list_browseresults_page','Page',$hscText).' '.($a+1));
+                               }
+                               if ($pointer == $a) { // current page
+                                       if ($this->internal['dontLinkActivePage']) {
+                                               $links[] = $this->cObj->wrap($pageText,$wrapper['activeLinkWrap']);
+                                       } else {
+                                               $links[] = $this->cObj->wrap($this->pi_linkTP_keepPIvars($pageText,array($pointerName  => ($a?$a:'')),$pi_isOnlyFields),$wrapper['activeLinkWrap']);
+                                       }
+                               } else {
+                                       $links[] = $this->cObj->wrap($this->pi_linkTP_keepPIvars($pageText,array($pointerName => ($a?$a:'')),$pi_isOnlyFields),$wrapper['inactiveLinkWrap']);
+                               }
+                       }
+                       if ($pointer<$totalPages-1 || $showFirstLast)   {
+                               if ($pointer>=$totalPages-1) { // Link to next page
+                                       $links[]=$this->cObj->wrap($this->pi_getLL('pi_list_browseresults_next','Next >',$hscText),$wrapper['disabledLinkWrap']);
+                               } else {
+                                       $links[]=$this->cObj->wrap($this->pi_linkTP_keepPIvars($this->pi_getLL('pi_list_browseresults_next','Next >',$hscText),array($pointerName => $pointer+1),$pi_isOnlyFields),$wrapper['inactiveLinkWrap']);
+                               }
+                       }
+                       if ($showFirstLast) { // Link to last page
+                               if ($pointer<$totalPages-1) {
+                                       $links[]=$this->cObj->wrap($this->pi_linkTP_keepPIvars($this->pi_getLL('pi_list_browseresults_last','Last >>',$hscText),array($pointerName => $totalPages-1),$pi_isOnlyFields),$wrapper['inactiveLinkWrap']);
+                               } else {
+                                       $links[]=$this->cObj->wrap($this->pi_getLL('pi_list_browseresults_last','Last >>',$hscText),$wrapper['disabledLinkWrap']);
+                               }
+                       }
+                       $theLinks = $this->cObj->wrap(implode(LF,$links),$wrapper['browseLinksWrap']);
+               } else {
+                       $theLinks = '';
+               }
+
+               $pR1 = $pointer*$results_at_a_time+1;
+               $pR2 = $pointer*$results_at_a_time+$results_at_a_time;
+
+               if ($showResultCount) {
+                       if ($wrapper['showResultsNumbersWrap']) {
+                               // this will render the resultcount in a more flexible way using markers (new in TYPO3 3.8.0).
+                               // the formatting string is expected to hold template markers (see function header). Example: 'Displaying results ###FROM### to ###TO### out of ###OUT_OF###'
+
+                               $markerArray['###FROM###'] = $this->cObj->wrap($this->internal['res_count'] > 0 ? $pR1 : 0,$wrapper['showResultsNumbersWrap']);
+                               $markerArray['###TO###'] = $this->cObj->wrap(min($this->internal['res_count'],$pR2),$wrapper['showResultsNumbersWrap']);
+                               $markerArray['###OUT_OF###'] = $this->cObj->wrap($this->internal['res_count'],$wrapper['showResultsNumbersWrap']);
+                               $markerArray['###FROM_TO###'] = $this->cObj->wrap(($this->internal['res_count'] > 0 ? $pR1 : 0).' '.$this->pi_getLL('pi_list_browseresults_to','to').' '.min($this->internal['res_count'],$pR2),$wrapper['showResultsNumbersWrap']);
+                               $markerArray['###CURRENT_PAGE###'] = $this->cObj->wrap($pointer+1,$wrapper['showResultsNumbersWrap']);
+                               $markerArray['###TOTAL_PAGES###'] = $this->cObj->wrap($totalPages,$wrapper['showResultsNumbersWrap']);
+                               // substitute markers
+                               $resultCountMsg = $this->cObj->substituteMarkerArray($this->pi_getLL('pi_list_browseresults_displays','Displaying results ###FROM### to ###TO### out of ###OUT_OF###'),$markerArray);
+                       } else {
+                               // render the resultcount in the "traditional" way using sprintf
+                               $resultCountMsg = sprintf(
+                                       str_replace('###SPAN_BEGIN###','<span'.$this->pi_classParam('browsebox-strong').'>',$this->pi_getLL('pi_list_browseresults_displays','Displaying results ###SPAN_BEGIN###%s to %s</span> out of ###SPAN_BEGIN###%s</span>')),
+                                       $count > 0 ? $pR1 : 0,
+                                       min($count,$pR2),
+                                       $count);
+                       }
+                       $resultCountMsg = $this->cObj->wrap($resultCountMsg,$wrapper['showResultsWrap']);
+               } else {
+                       $resultCountMsg = '';
+               }
+
+               $sTables = $this->cObj->wrap($resultCountMsg.$theLinks,$wrapper['browseBoxWrap']);
+
                return $sTables;
        }
 
                return $sTables;
        }
 
@@ -497,21 +615,24 @@ class tslib_pibase {
        function pi_list_searchBox($tableParams='')     {
                        // Search box design:
                $sTables = '
        function pi_list_searchBox($tableParams='')     {
                        // Search box design:
                $sTables = '
-               
+
                <!--
                        List search box:
                <!--
                        List search box:
-               -->     
+               -->
                <div'.$this->pi_classParam('searchbox').'>
                        <form action="'.htmlspecialchars(t3lib_div::getIndpEnv('REQUEST_URI')).'" method="post" style="margin: 0 0 0 0;">
                        <'.trim('table '.$tableParams).'>
                                <tr>
                                        <td><input type="text" name="'.$this->prefixId.'[sword]" value="'.htmlspecialchars($this->piVars['sword']).'"'.$this->pi_classParam('searchbox-sword').' /></td>
                <div'.$this->pi_classParam('searchbox').'>
                        <form action="'.htmlspecialchars(t3lib_div::getIndpEnv('REQUEST_URI')).'" method="post" style="margin: 0 0 0 0;">
                        <'.trim('table '.$tableParams).'>
                                <tr>
                                        <td><input type="text" name="'.$this->prefixId.'[sword]" value="'.htmlspecialchars($this->piVars['sword']).'"'.$this->pi_classParam('searchbox-sword').' /></td>
-                                       <td><input type="submit" value="'.$this->pi_getLL('pi_list_searchBox_search','Search',TRUE).'"'.$this->pi_classParam('searchbox-button').' /><input type="hidden" name="no_cache" value="1" /></td>
+                                       <td><input type="submit" value="'.$this->pi_getLL('pi_list_searchBox_search','Search',TRUE).'"'.$this->pi_classParam('searchbox-button').' />'.
+                                               '<input type="hidden" name="no_cache" value="1" />'.
+                                               '<input type="hidden" name="'.$this->prefixId.'[pointer]" value="" />'.
+                                               '</td>
                                </tr>
                        </table>
                        </form>
                </div>';
                                </tr>
                        </table>
                        </form>
                </div>';
-               
+
                return $sTables;
        }
 
                return $sTables;
        }
 
@@ -524,19 +645,18 @@ class tslib_pibase {
         */
        function pi_list_modeSelector($items=array(),$tableParams='')   {
                $cells=array();
         */
        function pi_list_modeSelector($items=array(),$tableParams='')   {
                $cells=array();
-               reset($items);
-               while(list($k,$v)=each($items)) {
+               foreach ($items as $k => $v) {
                        $cells[]='
                                        <td'.($this->piVars['mode']==$k?$this->pi_classParam('modeSelector-SCell'):'').'><p>'.
                                $this->pi_linkTP_keepPIvars(htmlspecialchars($v),array('mode'=>$k),$this->pi_isOnlyFields($this->pi_isOnlyFields)).
                                '</p></td>';
                }
                        $cells[]='
                                        <td'.($this->piVars['mode']==$k?$this->pi_classParam('modeSelector-SCell'):'').'><p>'.
                                $this->pi_linkTP_keepPIvars(htmlspecialchars($v),array('mode'=>$k),$this->pi_isOnlyFields($this->pi_isOnlyFields)).
                                '</p></td>';
                }
-               
+
                $sTables = '
                $sTables = '
-               
+
                <!--
                        Mode selector (menu for list):
                <!--
                        Mode selector (menu for list):
-               -->     
+               -->
                <div'.$this->pi_classParam('modeSelector').'>
                        <'.trim('table '.$tableParams).'>
                                <tr>
                <div'.$this->pi_classParam('modeSelector').'>
                        <'.trim('table '.$tableParams).'>
                                <tr>
@@ -544,7 +664,7 @@ class tslib_pibase {
                                </tr>
                        </table>
                </div>';
                                </tr>
                        </table>
                </div>';
-               
+
                return $sTables;
        }
 
                return $sTables;
        }
 
@@ -574,16 +694,16 @@ class tslib_pibase {
                }
 
                $out = '
                }
 
                $out = '
-               
+
                <!--
                        Record list:
                <!--
                        Record list:
-               -->     
+               -->
                <div'.$this->pi_classParam('listrow').'>
                        <'.trim('table '.$tableParams).'>
                                '.implode('',$tRows).'
                        </table>
                </div>';
                <div'.$this->pi_classParam('listrow').'>
                        <'.trim('table '.$tableParams).'>
                                '.implode('',$tRows).'
                        </table>
                </div>';
-               
+
                return $out;
        }
 
                return $out;
        }
 
@@ -626,7 +746,7 @@ class tslib_pibase {
 
 
        /***************************
 
 
        /***************************
-        * 
+        *
         * Stylesheet, CSS
         *
         **************************/
         * Stylesheet, CSS
         *
         **************************/
@@ -646,12 +766,20 @@ class tslib_pibase {
         * Returns the class-attribute with the correctly prefixed classname
         * Using pi_getClassName()
         *
         * Returns the class-attribute with the correctly prefixed classname
         * Using pi_getClassName()
         *
-        * @param       string          The class name (suffix)
+        * @param       string          The class name(s) (suffix) - separate multiple classes with commas
+        * @param       string          Additional class names which should not be prefixed - separate multiple classes with commas
         * @return      string          A "class" attribute with value and a single space char before it.
         * @see pi_getClassName()
         */
         * @return      string          A "class" attribute with value and a single space char before it.
         * @see pi_getClassName()
         */
-       function pi_classParam($class)  {
-               return ' class="'.$this->pi_getClassName($class).'"';
+       function pi_classParam($class, $addClasses='')  {
+               $output = '';
+               foreach (t3lib_div::trimExplode(',',$class) as $v)      {
+                       $output.= ' '.$this->pi_getClassName($v);
+               }
+               foreach (t3lib_div::trimExplode(',',$addClasses) as $v) {
+                       $output.= ' '.$v;
+               }
+               return ' class="'.trim($output).'"';
        }
 
        /**
        }
 
        /**
@@ -661,10 +789,13 @@ class tslib_pibase {
         * @param       string          $data: CSS data
         * @param       string          If $selector is set to any CSS selector, eg 'P' or 'H1' or 'TABLE' then the style $data will regard those HTML-elements only
         * @return      void
         * @param       string          $data: CSS data
         * @param       string          If $selector is set to any CSS selector, eg 'P' or 'H1' or 'TABLE' then the style $data will regard those HTML-elements only
         * @return      void
-        * @depreciated         I think this function should not be used (and probably isn't used anywhere). It was a part of a concept which was left behind quite quickly.
+        * @deprecated since TYPO3 3.6, this function will be removed in TYPO3 4.6, I think this function should not be used (and probably isn't used anywhere). It was a part of a concept which was left behind quite quickly.
+        * @obsolete
         * @private
         */
        function pi_setClassStyle($class,$data,$selector='')    {
         * @private
         */
        function pi_setClassStyle($class,$data,$selector='')    {
+               t3lib_div::logDeprecatedFunction();
+
                $GLOBALS['TSFE']->setCSS($this->pi_getClassName($class).($selector?' '.$selector:''),'.'.$this->pi_getClassName($class).($selector?' '.$selector:'').' {'.$data.'}');
        }
 
                $GLOBALS['TSFE']->setCSS($this->pi_getClassName($class).($selector?' '.$selector:''),'.'.$this->pi_getClassName($class).($selector?' '.$selector:'').' {'.$data.'}');
        }
 
@@ -676,20 +807,27 @@ class tslib_pibase {
         * @return      string          HTML content wrapped, ready to return to the parent object.
         */
        function pi_wrapInBaseClass($str)       {
         * @return      string          HTML content wrapped, ready to return to the parent object.
         */
        function pi_wrapInBaseClass($str)       {
-               return '
-                               
+               $content = '<div class="'.str_replace('_','-',$this->prefixId).'">
+               '.$str.'
+       </div>
+       ';
+
+               if(!$GLOBALS['TSFE']->config['config']['disablePrefixComment']) {
+                       $content = '
+
 
        <!--
 
        <!--
-       
+
                BEGIN: Content of extension "'.$this->extKey.'", plugin "'.$this->prefixId.'"
                BEGIN: Content of extension "'.$this->extKey.'", plugin "'.$this->prefixId.'"
-       
-       -->     
-       <div class="'.str_replace('_','-',$this->prefixId).'">
-               '.$str.'
-       </div>
+
+       -->
+       '.$content.'
        <!-- END: Content of extension "'.$this->extKey.'", plugin "'.$this->prefixId.'" -->
 
        ';
        <!-- END: Content of extension "'.$this->extKey.'", plugin "'.$this->prefixId.'" -->
 
        ';
+               }
+
+               return $content;
        }
 
 
        }
 
 
@@ -709,7 +847,7 @@ class tslib_pibase {
 
 
        /***************************
 
 
        /***************************
-        * 
+        *
         * Frontend editing: Edit panel, edit icons
         *
         **************************/
         * Frontend editing: Edit panel, edit icons
         *
         **************************/
@@ -730,22 +868,22 @@ class tslib_pibase {
                        $row = $this->internal['currentRow'];
                        $tablename = $this->internal['currentTable'];
                }
                        $row = $this->internal['currentRow'];
                        $tablename = $this->internal['currentTable'];
                }
-               
+
                if ($GLOBALS['TSFE']->beUserLogin)      {
                                // Create local cObj if not set:
                        if (!is_object($this->pi_EPtemp_cObj))  {
                                $this->pi_EPtemp_cObj = t3lib_div::makeInstance('tslib_cObj');
                                $this->pi_EPtemp_cObj->setParent($this->cObj->data,$this->cObj->currentRecord);
                        }
                if ($GLOBALS['TSFE']->beUserLogin)      {
                                // Create local cObj if not set:
                        if (!is_object($this->pi_EPtemp_cObj))  {
                                $this->pi_EPtemp_cObj = t3lib_div::makeInstance('tslib_cObj');
                                $this->pi_EPtemp_cObj->setParent($this->cObj->data,$this->cObj->currentRecord);
                        }
-                       
+
                                // Initialize the cObj object with current row
                        $this->pi_EPtemp_cObj->start($row,$tablename);
                                // Initialize the cObj object with current row
                        $this->pi_EPtemp_cObj->start($row,$tablename);
-                       
+
                                // Setting TypoScript values in the $conf array. See documentation in TSref for the EDITPANEL cObject.
                        $conf['allow'] = 'edit,new,delete,move,hide';
                        $panel = $this->pi_EPtemp_cObj->cObjGetSingle('EDITPANEL',$conf,'editpanel');
                }
                                // Setting TypoScript values in the $conf array. See documentation in TSref for the EDITPANEL cObject.
                        $conf['allow'] = 'edit,new,delete,move,hide';
                        $panel = $this->pi_EPtemp_cObj->cObjGetSingle('EDITPANEL',$conf,'editpanel');
                }
-               
+
                if ($panel)     {
                        if ($label)     {
                                return '<!-- BEGIN: EDIT PANEL --><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td valign="top">'.$label.'</td><td valign="top" align="right">'.$panel.'</td></tr></table><!-- END: EDIT PANEL -->';
                if ($panel)     {
                        if ($label)     {
                                return '<!-- BEGIN: EDIT PANEL --><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td valign="top">'.$label.'</td><td valign="top" align="right">'.$panel.'</td></tr></table><!-- END: EDIT PANEL -->';
@@ -777,7 +915,7 @@ class tslib_pibase {
                                'iconTitle' => $title
                        ),$oConf);
                        $content=$this->cObj->editIcons($content,$tablename.':'.$fields,$conf,$tablename.':'.$row['uid'],$row,'&viewUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')));
                                'iconTitle' => $title
                        ),$oConf);
                        $content=$this->cObj->editIcons($content,$tablename.':'.$fields,$conf,$tablename.':'.$row['uid'],$row,'&viewUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')));
-               }       
+               }
                return $content;
        }
 
                return $content;
        }
 
@@ -798,7 +936,7 @@ class tslib_pibase {
 
 
        /***************************
 
 
        /***************************
-        * 
+        *
         * Localization, locallang functions
         *
         **************************/
         * Localization, locallang functions
         *
         **************************/
@@ -814,10 +952,13 @@ class tslib_pibase {
         * @return      string          The value from LOCAL_LANG.
         */
        function pi_getLL($key,$alt='',$hsc=FALSE)      {
         * @return      string          The value from LOCAL_LANG.
         */
        function pi_getLL($key,$alt='',$hsc=FALSE)      {
+                       // The "from" charset of csConv() is only set for strings from TypoScript via _LOCAL_LANG
                if (isset($this->LOCAL_LANG[$this->LLkey][$key]))       {
                if (isset($this->LOCAL_LANG[$this->LLkey][$key]))       {
-                       $word = $GLOBALS['TSFE']->csConv($this->LOCAL_LANG[$this->LLkey][$key]);
+                       $word = $GLOBALS['TSFE']->csConv($this->LOCAL_LANG[$this->LLkey][$key], $this->LOCAL_LANG_charset[$this->LLkey][$key]);
+               } elseif ($this->altLLkey && isset($this->LOCAL_LANG[$this->altLLkey][$key]))   {
+                       $word = $GLOBALS['TSFE']->csConv($this->LOCAL_LANG[$this->altLLkey][$key], $this->LOCAL_LANG_charset[$this->altLLkey][$key]);
                } elseif (isset($this->LOCAL_LANG['default'][$key]))    {
                } elseif (isset($this->LOCAL_LANG['default'][$key]))    {
-                       $word = $this->LOCAL_LANG['default'][$key];
+                       $word = $this->LOCAL_LANG['default'][$key];     // No charset conversion because default is english and thereby ASCII
                } else {
                        $word = $this->LLtestPrefixAlt.$alt;
                }
                } else {
                        $word = $this->LLtestPrefixAlt.$alt;
                }
@@ -827,7 +968,7 @@ class tslib_pibase {
 
                return $output;
        }
 
                return $output;
        }
-       
+
        /**
         * Loads local-language values by looking for a "locallang.php" file in the plugin class directory ($this->scriptRelPath) and if found includes it.
         * Also locallang values set in the TypoScript property "_LOCAL_LANG" are merged onto the values found in the "locallang.php" file.
        /**
         * Loads local-language values by looking for a "locallang.php" file in the plugin class directory ($this->scriptRelPath) and if found includes it.
         * Also locallang values set in the TypoScript property "_LOCAL_LANG" are merged onto the values found in the "locallang.php" file.
@@ -836,16 +977,27 @@ class tslib_pibase {
         */
        function pi_loadLL()    {
                if (!$this->LOCAL_LANG_loaded && $this->scriptRelPath)  {
         */
        function pi_loadLL()    {
                if (!$this->LOCAL_LANG_loaded && $this->scriptRelPath)  {
-                       $basePath = t3lib_extMgm::siteRelPath($this->extKey).dirname($this->scriptRelPath).'/locallang.php';
-                       if (@is_file($basePath))        {
-                               include('./'.$basePath);
-                               $this->LOCAL_LANG = $LOCAL_LANG;
-                               if (is_array($this->conf['_LOCAL_LANG.']))      {
-                                       reset($this->conf['_LOCAL_LANG.']);
-                                       while(list($k,$lA)=each($this->conf['_LOCAL_LANG.']))   {
-                                               if (is_array($lA))      {
-                                                       $k = substr($k,0,-1);
-                                                       $this->LOCAL_LANG[$k] = t3lib_div::array_merge_recursive_overrule(is_array($this->LOCAL_LANG[$k])?$this->LOCAL_LANG[$k]:array(), $lA);
+                       $basePath = 'EXT:' . $this->extKey . '/' . dirname($this->scriptRelPath) . '/locallang.xml';
+
+                               // Read the strings in the required charset (since TYPO3 4.2)
+                       $this->LOCAL_LANG = t3lib_div::readLLfile($basePath,$this->LLkey,$GLOBALS['TSFE']->renderCharset);
+                       if ($this->altLLkey)    {
+                               $tempLOCAL_LANG = t3lib_div::readLLfile($basePath,$this->altLLkey);
+                               $this->LOCAL_LANG = array_merge(is_array($this->LOCAL_LANG) ? $this->LOCAL_LANG : array(),$tempLOCAL_LANG);
+                       }
+
+                               // Overlaying labels from TypoScript (including fictitious language keys for non-system languages!):
+                       $confLL = $this->conf['_LOCAL_LANG.'];
+                       if (is_array($confLL)) {
+                               foreach ($confLL as $k => $lA) {
+                                       if (is_array($lA))      {
+                                               $k = substr($k,0,-1);
+                                               foreach($lA as $llK => $llV)    {
+                                                       if (!is_array($llV))    {
+                                                               $this->LOCAL_LANG[$k][$llK] = $llV;
+                                                                       // For labels coming from the TypoScript (database) the charset is assumed to be "forceCharset" and if that is not set, assumed to be that of the individual system languages
+                                                               $this->LOCAL_LANG_charset[$k][$llK] = $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] ? $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] : $GLOBALS['TSFE']->csConvObj->charSetArray[$k];
+                                                       }
                                                }
                                        }
                                }
                                                }
                                        }
                                }
@@ -853,7 +1005,7 @@ class tslib_pibase {
                }
                $this->LOCAL_LANG_loaded = 1;
        }
                }
                $this->LOCAL_LANG_loaded = 1;
        }
-       
+
 
 
 
 
 
 
@@ -877,7 +1029,7 @@ class tslib_pibase {
 
 
        /***************************
 
 
        /***************************
-        * 
+        *
         * Database, queries
         *
         **************************/
         * Database, queries
         *
         **************************/
@@ -897,39 +1049,40 @@ class tslib_pibase {
         * @param       boolean         If set, the function will return the query not as a string but array with the various parts.
         * @return      mixed           The query build.
         * @access private
         * @param       boolean         If set, the function will return the query not as a string but array with the various parts.
         * @return      mixed           The query build.
         * @access private
-        * @depreciated         Use pi_exec_query() instead!
+        * @deprecated since TYPO3 3.6, this function will be removed in TYPO3 4.5, use pi_exec_query() instead!
+        * @todo        Deprecated but still used in the Core!
         */
        function pi_list_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='',$returnQueryArray=FALSE)       {
 
         */
        function pi_list_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='',$returnQueryArray=FALSE)       {
 
-                       // Begin Query:
+               // Begin Query:
                if (!$query)    {
                if (!$query)    {
-                               // Fetches the list of PIDs to select from. 
+                               // Fetches the list of PIDs to select from.
                                // TypoScript property .pidList is a comma list of pids. If blank, current page id is used.
                                // TypoScript property .recursive is a int+ which determines how many levels down from the pids in the pid-list subpages should be included in the select.
                        $pidList = $this->pi_getPidList($this->conf['pidList'],$this->conf['recursive']);
                        if (is_array($mm_cat))  {
                                // TypoScript property .pidList is a comma list of pids. If blank, current page id is used.
                                // TypoScript property .recursive is a int+ which determines how many levels down from the pids in the pid-list subpages should be included in the select.
                        $pidList = $this->pi_getPidList($this->conf['pidList'],$this->conf['recursive']);
                        if (is_array($mm_cat))  {
-                               $query='FROM '.$table.','.$mm_cat['table'].','.$mm_cat['mmtable'].chr(10).
-                                               ' WHERE '.$table.'.uid='.$mm_cat['mmtable'].'.uid_local AND '.$mm_cat['table'].'.uid='.$mm_cat['mmtable'].'.uid_foreign '.chr(10).
-                                               (strcmp($mm_cat['catUidList'],'')?' AND '.$mm_cat['table'].'.uid IN ('.$mm_cat['catUidList'].')':'').chr(10).
-                                               ' AND '.$table.'.pid IN ('.$pidList.')'.chr(10).
-                                               $this->cObj->enableFields($table).chr(10);      // This adds WHERE-clauses that ensures deleted, hidden, starttime/endtime/access records are NOT selected, if they should not! Almost ALWAYS add this to your queries!
+                               $query='FROM '.$table.','.$mm_cat['table'].','.$mm_cat['mmtable'].LF.
+                                               ' WHERE '.$table.'.uid='.$mm_cat['mmtable'].'.uid_local AND '.$mm_cat['table'].'.uid='.$mm_cat['mmtable'].'.uid_foreign '.LF.
+                                               (strcmp($mm_cat['catUidList'],'')?' AND '.$mm_cat['table'].'.uid IN ('.$mm_cat['catUidList'].')':'').LF.
+                                               ' AND '.$table.'.pid IN ('.$pidList.')'.LF.
+                                               $this->cObj->enableFields($table).LF;   // This adds WHERE-clauses that ensures deleted, hidden, starttime/endtime/access records are NOT selected, if they should not! Almost ALWAYS add this to your queries!
                        } else {
                        } else {
-                               $query='FROM '.$table.' WHERE pid IN ('.$pidList.')'.chr(10).
-                                               $this->cObj->enableFields($table).chr(10);      // This adds WHERE-clauses that ensures deleted, hidden, starttime/endtime/access records are NOT selected, if they should not! Almost ALWAYS add this to your queries!
+                               $query='FROM '.$table.' WHERE pid IN ('.$pidList.')'.LF.
+                                               $this->cObj->enableFields($table).LF;   // This adds WHERE-clauses that ensures deleted, hidden, starttime/endtime/access records are NOT selected, if they should not! Almost ALWAYS add this to your queries!
                        }
                }
 
                        // Split the "FROM ... WHERE" string so we get the WHERE part and TABLE names separated...:
                        }
                }
 
                        // Split the "FROM ... WHERE" string so we get the WHERE part and TABLE names separated...:
-               list($TABLENAMES,$WHERE) = spliti('WHERE', trim($query), 2);
+               list($TABLENAMES, $WHERE) = preg_split('/WHERE/i', trim($query), 2);
                $TABLENAMES = trim(substr(trim($TABLENAMES),5));
                $WHERE = trim($WHERE);
 
                        // Add '$addWhere'
                $TABLENAMES = trim(substr(trim($TABLENAMES),5));
                $WHERE = trim($WHERE);
 
                        // Add '$addWhere'
-               if ($addWhere)  {$WHERE.=' '.$addWhere.chr(10);}
+               if ($addWhere)  {$WHERE.=' '.$addWhere.LF;}
 
 
-                       // Search word:                         
+                       // Search word:
                if ($this->piVars['sword'] && $this->internal['searchFieldList'])       {
                if ($this->piVars['sword'] && $this->internal['searchFieldList'])       {
-                       $WHERE.=$this->cObj->searchWhere($this->piVars['sword'],$this->internal['searchFieldList'],$table).chr(10);
+                       $WHERE.=$this->cObj->searchWhere($this->piVars['sword'],$this->internal['searchFieldList'],$table).LF;
                }
 
                if ($count) {
                }
 
                if ($count) {
@@ -943,12 +1096,12 @@ class tslib_pibase {
                        );
                } else {
                                // Order by data:
                        );
                } else {
                                // Order by data:
-                       if (!$orderBy)  {
+                       if (!$orderBy && $this->internal['orderBy'])    {
                                if (t3lib_div::inList($this->internal['orderByList'],$this->internal['orderBy']))       {
                                        $orderBy = 'ORDER BY '.$table.'.'.$this->internal['orderBy'].($this->internal['descFlag']?' DESC':'');
                                }
                        }
                                if (t3lib_div::inList($this->internal['orderByList'],$this->internal['orderBy']))       {
                                        $orderBy = 'ORDER BY '.$table.'.'.$this->internal['orderBy'].($this->internal['descFlag']?' DESC':'');
                                }
                        }
-                       
+
                                // Limit data:
                        $pointer = $this->piVars['pointer'];
                        $pointer = intval($pointer);
                                // Limit data:
                        $pointer = $this->piVars['pointer'];
                        $pointer = intval($pointer);
@@ -957,8 +1110,8 @@ class tslib_pibase {
 
                                // Add 'SELECT'
                        $queryParts = array(
 
                                // Add 'SELECT'
                        $queryParts = array(
-                               'SELECT' => $this->pi_prependFieldsWithTable($table,$this->pi_listFields), 
-                               'FROM' => $TABLENAMES, 
+                               'SELECT' => $this->pi_prependFieldsWithTable($table,$this->pi_listFields),
+                               'FROM' => $TABLENAMES,
                                'WHERE' => $WHERE,
                                'GROUPBY' => $GLOBALS['TYPO3_DB']->stripGroupBy($groupBy),
                                'ORDERBY' => $GLOBALS['TYPO3_DB']->stripOrderBy($orderBy),
                                'WHERE' => $WHERE,
                                'GROUPBY' => $GLOBALS['TYPO3_DB']->stripGroupBy($groupBy),
                                'ORDERBY' => $GLOBALS['TYPO3_DB']->stripOrderBy($orderBy),
@@ -967,11 +1120,11 @@ class tslib_pibase {
                }
 
                $query = $GLOBALS['TYPO3_DB']->SELECTquery (
                }
 
                $query = $GLOBALS['TYPO3_DB']->SELECTquery (
-                                       $queryParts['SELECT'], 
-                                       $queryParts['FROM'], 
-                                       $queryParts['WHERE'], 
-                                       $queryParts['GROUPBY'], 
-                                       $queryParts['ORDERBY'], 
+                                       $queryParts['SELECT'],
+                                       $queryParts['FROM'],
+                                       $queryParts['WHERE'],
+                                       $queryParts['GROUPBY'],
+                                       $queryParts['ORDERBY'],
                                        $queryParts['LIMIT']
                                );
                return $returnQueryArray ? $queryParts : $query;
                                        $queryParts['LIMIT']
                                );
                return $returnQueryArray ? $queryParts : $query;
@@ -988,7 +1141,7 @@ class tslib_pibase {
         * @param       mixed           If an array, then it must contain the keys "table", "mmtable" and (optionally) "catUidList" defining a table to make a MM-relation to in the query (based on fields uid_local and uid_foreign). If not array, the query will be a plain query looking up data in only one table.
         * @param       string          If set, this is added as a " GROUP BY ...." part of the query.
         * @param       string          If set, this is added as a " ORDER BY ...." part of the query. The default is that an ORDER BY clause is made based on $this->internal['orderBy'] and $this->internal['descFlag'] where the orderBy field must be found in $this->internal['orderByList']
         * @param       mixed           If an array, then it must contain the keys "table", "mmtable" and (optionally) "catUidList" defining a table to make a MM-relation to in the query (based on fields uid_local and uid_foreign). If not array, the query will be a plain query looking up data in only one table.
         * @param       string          If set, this is added as a " GROUP BY ...." part of the query.
         * @param       string          If set, this is added as a " ORDER BY ...." part of the query. The default is that an ORDER BY clause is made based on $this->internal['orderBy'] and $this->internal['descFlag'] where the orderBy field must be found in $this->internal['orderByList']
-        * @param       string          If set, this is taken as the first part of the query instead of what is created internally. Basically this should be a query starting with "FROM [table] WHERE ... AND ...". The $addWhere clauses and all the other stuff is still added. Only the tables and PID selecting clauses are bypassed. May be depreciated in the future!
+        * @param       string          If set, this is taken as the first part of the query instead of what is created internally. Basically this should be a query starting with "FROM [table] WHERE ... AND ...". The $addWhere clauses and all the other stuff is still added. Only the tables and PID selecting clauses are bypassed. May be deprecated in the future!
         * @return      pointer         SQL result pointer
         */
        function pi_exec_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='')       {
         * @return      pointer         SQL result pointer
         */
        function pi_exec_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='')       {
@@ -996,7 +1149,7 @@ class tslib_pibase {
 
                return $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
        }
 
                return $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
        }
-       
+
        /**
         * Returns the row $uid from $table
         * (Simply calling $GLOBALS['TSFE']->sys_page->checkRecord())
        /**
         * Returns the row $uid from $table
         * (Simply calling $GLOBALS['TSFE']->sys_page->checkRecord())
@@ -1007,9 +1160,9 @@ class tslib_pibase {
         * @return      array           If record is found, an array. Otherwise false.
         */
        function pi_getRecord($table,$uid,$checkPage=0) {
         * @return      array           If record is found, an array. Otherwise false.
         */
        function pi_getRecord($table,$uid,$checkPage=0) {
-               return $GLOBALS['TSFE']->sys_page->checkRecord($table,$uid,$checkPage); 
+               return $GLOBALS['TSFE']->sys_page->checkRecord($table,$uid,$checkPage);
        }
        }
-       
+
        /**
         * Returns a commalist of page ids for a query (eg. 'WHERE pid IN (...)')
         *
        /**
         * Returns a commalist of page ids for a query (eg. 'WHERE pid IN (...)')
         *
@@ -1017,20 +1170,29 @@ class tslib_pibase {
         * @param       integer         $recursive is an integer >=0 telling how deep to dig for pids under each entry in $pid_list
         * @return      string          List of PID values (comma separated)
         */
         * @param       integer         $recursive is an integer >=0 telling how deep to dig for pids under each entry in $pid_list
         * @return      string          List of PID values (comma separated)
         */
-       function pi_getPidList($pid_list,$recursive=0)  {
-               if (!strcmp($pid_list,''))      $pid_list = $GLOBALS['TSFE']->id;
-               $recursive = t3lib_div::intInRange($recursive,0);
-               
-               $pid_list_arr = array_unique(t3lib_div::trimExplode(',',$pid_list,1));
-               $pid_list='';
-               reset($pid_list_arr);
-               while(list(,$val)=each($pid_list_arr))  {       
-                       $val = t3lib_div::intInRange($val,0);
-                       if ($val)       $pid_list.=$val.','.$this->cObj->getTreeList($val,$recursive);
+       function pi_getPidList($pid_list, $recursive = 0) {
+               if (!strcmp($pid_list, '')) {
+                       $pid_list = $GLOBALS['TSFE']->id;
                }
                }
-               return ereg_replace(',$','',$pid_list);
+
+               $recursive = t3lib_div::intInRange($recursive, 0);
+
+               $pid_list_arr = array_unique(t3lib_div::trimExplode(',', $pid_list, 1));
+               $pid_list     = array();
+
+               foreach($pid_list_arr as $val) {
+                       $val = t3lib_div::intInRange($val, 0);
+                       if ($val) {
+                               $_list = $this->cObj->getTreeList(-1 * $val, $recursive);
+                               if ($_list) {
+                                       $pid_list[] = $_list;
+                               }
+                       }
+               }
+
+               return implode(',', $pid_list);
        }
        }
-       
+
        /**
         * Having a comma list of fields ($fieldList) this is prepended with the $table.'.' name
         *
        /**
         * Having a comma list of fields ($fieldList) this is prepended with the $table.'.' name
         *
@@ -1041,7 +1203,7 @@ class tslib_pibase {
        function pi_prependFieldsWithTable($table,$fieldList)   {
                $list=t3lib_div::trimExplode(',',$fieldList,1);
                $return=array();
        function pi_prependFieldsWithTable($table,$fieldList)   {
                $list=t3lib_div::trimExplode(',',$fieldList,1);
                $return=array();
-               while(list(,$listItem)=each($list))     {
+               foreach ($list as $listItem) {
                        $return[]=$table.'.'.$listItem;
                }
                return implode(',',$return);
                        $return[]=$table.'.'.$listItem;
                }
                return implode(',',$return);
@@ -1060,8 +1222,8 @@ class tslib_pibase {
         */
        function pi_getCategoryTableContents($table,$pid,$whereClause='',$groupBy='',$orderBy='',$limit='')     {
                $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
         */
        function pi_getCategoryTableContents($table,$pid,$whereClause='',$groupBy='',$orderBy='',$limit='')     {
                $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
-                                       '*', 
-                                       $table, 
+                                       '*',
+                                       $table,
                                        'pid='.intval($pid).
                                                $this->cObj->enableFields($table).' '.
                                                $whereClause,   // whereClauseMightContainGroupOrderBy
                                        'pid='.intval($pid).
                                                $this->cObj->enableFields($table).' '.
                                                $whereClause,   // whereClauseMightContainGroupOrderBy
@@ -1083,17 +1245,17 @@ class tslib_pibase {
 
 
 
 
 
 
-       
+
 
 
 
 
        /***************************
 
 
 
 
        /***************************
-        * 
+        *
         * Various
         *
         **************************/
         * Various
         *
         **************************/
-       
+
        /**
         * Returns true if the piVars array has ONLY those fields entered that is set in the $fList (commalist) AND if none of those fields value is greater than $lowerThan field if they are integers.
         * Notice that this function will only work as long as values are integers.
        /**
         * Returns true if the piVars array has ONLY those fields entered that is set in the $fList (commalist) AND if none of those fields value is greater than $lowerThan field if they are integers.
         * Notice that this function will only work as long as values are integers.
@@ -1107,12 +1269,12 @@ class tslib_pibase {
 
                $fList = t3lib_div::trimExplode(',',$fList,1);
                $tempPiVars = $this->piVars;
 
                $fList = t3lib_div::trimExplode(',',$fList,1);
                $tempPiVars = $this->piVars;
-               while(list(,$k)=each($fList))   {
+               foreach ($fList as $k) {
                        if (!t3lib_div::testInt($tempPiVars[$k]) || $tempPiVars[$k]<$lowerThan)         unset($tempPiVars[$k]);
                }
                if (!count($tempPiVars))        return 1;
        }
                        if (!t3lib_div::testInt($tempPiVars[$k]) || $tempPiVars[$k]<$lowerThan)         unset($tempPiVars[$k]);
                }
                if (!count($tempPiVars))        return 1;
        }
-       
+
        /**
         * Returns true if the array $inArray contains only values allowed to be cached based on the configuration in $this->pi_autoCacheFields
         * Used by ->pi_linkTP_keepPIvars
        /**
         * Returns true if the array $inArray contains only values allowed to be cached based on the configuration in $this->pi_autoCacheFields
         * Used by ->pi_linkTP_keepPIvars
@@ -1124,13 +1286,12 @@ class tslib_pibase {
         */
        function pi_autoCache($inArray) {
                if (is_array($inArray)) {
         */
        function pi_autoCache($inArray) {
                if (is_array($inArray)) {
-                       reset($inArray);
-                       while(list($fN,$fV)=each($inArray))     {
+                       foreach ($inArray as $fN => $fV) {
                                if (!strcmp($inArray[$fN],''))  {
                                        unset($inArray[$fN]);
                                } elseif (is_array($this->pi_autoCacheFields[$fN]))     {
                                        if (is_array($this->pi_autoCacheFields[$fN]['range'])
                                if (!strcmp($inArray[$fN],''))  {
                                        unset($inArray[$fN]);
                                } elseif (is_array($this->pi_autoCacheFields[$fN]))     {
                                        if (is_array($this->pi_autoCacheFields[$fN]['range'])
-                                                        && intval($inArray[$fN])>=intval($this->pi_autoCacheFields[$fN]['range'][0]) 
+                                                        && intval($inArray[$fN])>=intval($this->pi_autoCacheFields[$fN]['range'][0])
                                                         && intval($inArray[$fN])<=intval($this->pi_autoCacheFields[$fN]['range'][1]))  {
                                                                unset($inArray[$fN]);
                                        }
                                                         && intval($inArray[$fN])<=intval($this->pi_autoCacheFields[$fN]['range'][1]))  {
                                                                unset($inArray[$fN]);
                                        }
@@ -1158,7 +1319,7 @@ class tslib_pibase {
                if (is_array($parseFunc))       $str = $this->cObj->parseFunc($str, $parseFunc);
                return $str;
        }
                if (is_array($parseFunc))       $str = $this->cObj->parseFunc($str, $parseFunc);
                return $str;
        }
-       
+
 
 
 
 
 
 
@@ -1172,16 +1333,17 @@ class tslib_pibase {
        /**
         * Converts $this->cObj->data['pi_flexform'] from XML string to flexForm array.
         *
        /**
         * Converts $this->cObj->data['pi_flexform'] from XML string to flexForm array.
         *
+        * @param       string          Field name to convert
         * @return      void
         */
         * @return      void
         */
-       function pi_initPIflexForm()    {
+       function pi_initPIflexForm($field='pi_flexform')        {
                        // Converting flexform data into array:
                        // Converting flexform data into array:
-               if (!is_array($this->cObj->data['pi_flexform']) && $this->cObj->data['pi_flexform'])    {
-                       $this->cObj->data['pi_flexform'] = t3lib_div::xml2array($this->cObj->data['pi_flexform']);
-                       if (!is_array($this->cObj->data['pi_flexform']))        $this->cObj->data['pi_flexform']=array();
+               if (!is_array($this->cObj->data[$field]) && $this->cObj->data[$field])  {
+                       $this->cObj->data[$field] = t3lib_div::xml2array($this->cObj->data[$field]);
+                       if (!is_array($this->cObj->data[$field]))       $this->cObj->data[$field]=array();
                }
        }
                }
        }
-       
+
        /**
         * Return value from somewhere inside a FlexForm structure
         *
        /**
         * Return value from somewhere inside a FlexForm structure
         *
@@ -1193,7 +1355,7 @@ class tslib_pibase {
         * @return      string          The content.
         */
        function pi_getFFvalue($T3FlexForm_array,$fieldName,$sheet='sDEF',$lang='lDEF',$value='vDEF')   {
         * @return      string          The content.
         */
        function pi_getFFvalue($T3FlexForm_array,$fieldName,$sheet='sDEF',$lang='lDEF',$value='vDEF')   {
-               $sheetArray = $T3FlexForm_array['data'][$sheet][$lang];
+               $sheetArray = is_array($T3FlexForm_array) ? $T3FlexForm_array['data'][$sheet][$lang] : '';
                if (is_array($sheetArray))      {
                        return $this->pi_getFFvalueFromSheetArray($sheetArray,explode('/',$fieldName),$value);
                }
                if (is_array($sheetArray))      {
                        return $this->pi_getFFvalueFromSheetArray($sheetArray,explode('/',$fieldName),$value);
                }
@@ -1210,7 +1372,7 @@ class tslib_pibase {
         * @see pi_getFFvalue()
         */
        function pi_getFFvalueFromSheetArray($sheetArray,$fieldNameArr,$value)  {
         * @see pi_getFFvalue()
         */
        function pi_getFFvalueFromSheetArray($sheetArray,$fieldNameArr,$value)  {
-       
+
                $tempArr=$sheetArray;
                foreach($fieldNameArr as $k => $v)      {
                        if (t3lib_div::testInt($v))     {
                $tempArr=$sheetArray;
                foreach($fieldNameArr as $k => $v)      {
                        if (t3lib_div::testInt($v))     {
@@ -1218,7 +1380,7 @@ class tslib_pibase {
                                        $c=0;
                                        foreach($tempArr as $values)    {
                                                if ($c==$v)     {
                                        $c=0;
                                        foreach($tempArr as $values)    {
                                                if ($c==$v)     {
-                                                       debug($values);
+                                                       #debug($values);
                                                        $tempArr=$values;
                                                        break;
                                                }
                                                        $tempArr=$values;
                                                        break;
                                                }
@@ -1234,4 +1396,5 @@ class tslib_pibase {
 }
 
 // NO extension of class - does not make sense here.
 }
 
 // NO extension of class - does not make sense here.
+
 ?>
\ No newline at end of file
 ?>
\ No newline at end of file