Small things
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / class.tslib_content.php
index 7202fdc..713ec7d 100755 (executable)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2004 Kasper Skaarhoj (kasper@typo3.com)
+*  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
  * Revised for TYPO3 3.6 June/2003 by Kasper Skaarhoj
  * XHTML compliant
  *
- * class tslib_cObj                            :               All main TypoScript features, rendering of content objects (cObjects). This class is the backbone of TypoScript Template rendering.
+ * class tslib_cObj                    :               All main TypoScript features, rendering of content objects (cObjects). This class is the backbone of TypoScript Template rendering.
  * class tslib_controlTable            :               Makes a table CTABLE (TS cObject)
  * class tslib_tableOffset             :               Makes a table-offset (TS)
  * class tslib_frameset                        :               Generates framesets (TS)
  *
- * @author     Kasper Skaarhoj <kasper@typo3.com>
+ * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
  */
 /**
  * [CLASS/FUNCTION INDEX of SCRIPT]
  *
  *
  *
- *  245: class tslib_cObj
- *  343:     function start($data,$table='')
- *  358:     function setParent($data,$currentRecord)
+ *  250: class tslib_cObj
+ *  344:     function start($data,$table='')
+ *  359:     function setParent($data,$currentRecord)
  *
  *              SECTION: CONTENT_OBJ:
- *  383:     function getCurrentVal()
- *  394:     function setCurrentVal($value)
- *  407:     function cObjGet($setup,$addKey='')
- *  431:     function cObjGetSingle($name,$conf,$TSkey='__')
+ *  384:     function getCurrentVal()
+ *  395:     function setCurrentVal($value)
+ *  408:     function cObjGet($setup,$addKey='')
+ *  432:     function cObjGetSingle($name,$conf,$TSkey='__')
  *
  *              SECTION: Functions rendering content objects (cObjects)
- *  570:     function HTML($conf)
- *  581:     function TEXT($conf)
- *  592:     function CLEARGIF($conf)
- *  611:     function COBJ_ARRAY($conf,$ext='')
- *  647:     function USER($conf,$ext='')
- *  674:     function FILE($conf)
- *  690:     function IMAGE($conf)
- *  709:     function IMG_RESOURCE($conf)
- *  721:     function IMGTEXT($conf)
- * 1099:     function CONTENT($conf)
- * 1151:     function RECORDS($conf)
- * 1218:     function HMENU($conf)
- * 1250:     function CTABLE ($conf)
- * 1288:     function OTABLE ($conf)
- * 1303:     function COLUMNS ($conf)
- * 1382:     function HRULER ($conf)
- * 1407:     function CASEFUNC ($conf)
- * 1432:     function LOAD_REGISTER($conf,$name)
- * 1472:     function FORM($conf,$formData='')
- * 1854:     function SEARCHRESULT($conf)
- * 2019:     function PHP_SCRIPT($conf,$ext='')
- * 2062:     function TEMPLATE($conf)
- * 2206:     function MULTIMEDIA($conf)
+ *  578:     function HTML($conf)
+ *  589:     function TEXT($conf)
+ *  600:     function CLEARGIF($conf)
+ *  619:     function COBJ_ARRAY($conf,$ext='')
+ *  655:     function USER($conf,$ext='')
+ *  682:     function FILE($conf)
+ *  698:     function IMAGE($conf)
+ *  717:     function IMG_RESOURCE($conf)
+ *  729:     function IMGTEXT($conf)
+ * 1125:     function CONTENT($conf)
+ * 1188:     function RECORDS($conf)
+ * 1266:     function HMENU($conf)
+ * 1298:     function CTABLE ($conf)
+ * 1336:     function OTABLE ($conf)
+ * 1351:     function COLUMNS ($conf)
+ * 1430:     function HRULER ($conf)
+ * 1455:     function CASEFUNC ($conf)
+ * 1480:     function LOAD_REGISTER($conf,$name)
+ * 1520:     function FORM($conf,$formData='')
+ * 1970:     function SEARCHRESULT($conf)
+ * 2135:     function PHP_SCRIPT($conf,$ext='')
+ * 2178:     function TEMPLATE($conf)
+ * 2329:     function MULTIMEDIA($conf)
  *
  *              SECTION: Various helper functions for content objects:
- * 2295:     function netprintApplication_offsiteLinkWrap($str,$imgConf,$conf)
- * 2336:     function getFieldDefaultValue($noValueInsert, $fieldName, $defaultVal)
- * 2354:     function cImage($file,$conf)
- * 2381:     function imageLinkWrap($string,$imageFile,$conf)
- * 2445:     function fileResource($fName)
- * 2468:     function lastChanged($tstamp)
- * 2485:     function linkWrap($content,$wrap)
- * 2502:     function getAltParam($conf)
+ * 2418:     function netprintApplication_offsiteLinkWrap($str,$imgConf,$conf)
+ * 2459:     function getFieldDefaultValue($noValueInsert, $fieldName, $defaultVal)
+ * 2477:     function cImage($file,$conf)
+ * 2510:     function imageLinkWrap($string,$imageFile,$conf)
+ * 2575:     function fileResource($fName, $addParams='alt="" title=""')
+ * 2598:     function lastChanged($tstamp)
+ * 2615:     function linkWrap($content,$wrap)
+ * 2633:     function getAltParam($conf)
  *
  *              SECTION: HTML template processing functions
- * 2549:     function getSubpart($content, $marker)
- * 2578:     function substituteSubpart($content,$marker,$subpartContent,$recursive=1)
- * 2620:     function substituteMarker($content,$marker,$markContent)
- * 2640:     function substituteMarkerArrayCached($content,$markContentArray=array(),$subpartContentArray=array(),$wrappedSubpartContentArray=array())
- * 2738:     function substituteMarkerArray($content,$markContentArray,$wrap='',$uppercase=0)
- * 2759:     function substituteMarkerInObject(&$tree, $markContentArray)
- * 2782:     function fillInMarkerArray($markContentArray, $row, $fieldList='', $nl2br=TRUE, $prefix='FIELD_', $HSC=FALSE)
+ * 2690:     function getSubpart($content, $marker)
+ * 2719:     function substituteSubpart($content,$marker,$subpartContent,$recursive=1)
+ * 2761:     function substituteMarker($content,$marker,$markContent)
+ * 2781:     function substituteMarkerArrayCached($content,$markContentArray=array(),$subpartContentArray=array(),$wrappedSubpartContentArray=array())
+ * 2879:     function substituteMarkerArray($content,$markContentArray,$wrap='',$uppercase=0)
+ * 2900:     function substituteMarkerInObject(&$tree, $markContentArray)
+ * 2923:     function fillInMarkerArray($markContentArray, $row, $fieldList='', $nl2br=TRUE, $prefix='FIELD_', $HSC=FALSE)
  *
  *              SECTION: "stdWrap" + sub functions
- * 2845:     function stdWrap($content,$conf)
- * 3003:     function numRows($conf)
- * 3024:     function listNum($content,$listNum,$char)
- * 3044:     function checkIf($conf)
- * 3107:     function filelist($data)
- * 3186:     function clean_directory($theDir)
- * 3204:     function HTMLparser_TSbridge($theValue, $conf)
- * 3218:     function dataWrap($content,$wrap)
- * 3231:     function insertData($str)
- * 3261:     function prefixComment($str,$conf,$content)
- * 3285:     function substring($content,$options)
- * 3303:     function crop($content,$options)
- * 3329:     function textStyle($theValue, $conf)
- * 3396:     function tableStyle($theValue, $conf)
- * 3437:     function addParams($content,$conf)
- * 3480:     function filelink($theValue, $conf)
- * 3547:     function locDataJU($jumpUrl,$conf)
- * 3578:     function calc($val)
- * 3607:     function calcIntExplode($delim, $string)
- * 3627:     function splitObj($value, $conf)
- * 3683:     function parseFunc($theValue, $conf, $ref='')
- * 3789:     function _parseFunc ($theValue, $conf)
- * 3991:     function encaps_lineSplit($theValue, $conf)
- * 4074:     function http_makelinks($data,$conf)
- * 4141:     function mailto_makelinks($data,$conf)
- * 4193:     function getImgResource($file,$fileArray)
+ * 2986:     function stdWrap($content,$conf)
+ * 3151:     function numRows($conf)
+ * 3172:     function listNum($content,$listNum,$char)
+ * 3192:     function checkIf($conf)
+ * 3255:     function filelist($data)
+ * 3334:     function clean_directory($theDir)
+ * 3352:     function HTMLparser_TSbridge($theValue, $conf)
+ * 3366:     function dataWrap($content,$wrap)
+ * 3379:     function insertData($str)
+ * 3409:     function prefixComment($str,$conf,$content)
+ * 3433:     function substring($content,$options)
+ * 3451:     function crop($content,$options)
+ * 3483:     function removeBadHTML($text, $conf)
+ * 3527:     function textStyle($theValue, $conf)
+ * 3594:     function tableStyle($theValue, $conf)
+ * 3635:     function addParams($content,$conf)
+ * 3678:     function filelink($theValue, $conf)
+ * 3745:     function locDataJU($jumpUrl,$conf)
+ * 3776:     function calc($val)
+ * 3805:     function calcIntExplode($delim, $string)
+ * 3825:     function splitObj($value, $conf)
+ * 3881:     function parseFunc($theValue, $conf, $ref='')
+ * 3991:     function _parseFunc ($theValue, $conf)
+ * 4193:     function encaps_lineSplit($theValue, $conf)
+ * 4276:     function http_makelinks($data,$conf)
+ * 4343:     function mailto_makelinks($data,$conf)
+ * 4406:     function getImgResource($file,$fileArray)
  *
  *              SECTION: Data retrieval etc.
- * 4365:     function getFieldVal($field)
- * 4385:     function getData($string,$fieldArray)
- * 4503:     function rootLineValue($key,$field,$slideBack=0,$altRootLine='')
- * 4524:     function getGlobal($var)
- * 4549:     function getKey($key,$arr)
+ * 4583:     function getFieldVal($field)
+ * 4603:     function getData($string,$fieldArray)
+ * 4730:     function rootLineValue($key,$field,$slideBack=0,$altRootLine='')
+ * 4752:     function getGlobal($var, $source=NULL)
+ * 4777:     function getKey($key,$arr)
  *
  *              SECTION: Link functions (typolink)
- * 4601:     function typoLink($linktxt, $conf)
- * 4862:     function typoLink_URL($conf)
- * 4880:     function getTypoLink($label,$params,$urlParameters=array(),$target='')
- * 4910:     function getTypoLink_URL($params,$urlParameters=array(),$target='')
- * 4922:     function typolinkWrap($conf)
- * 4935:     function currentPageUrl($urlParameters=array(),$id=0)
- * 4948:     function getClosestMPvalueForPage($pageId, $raw=FALSE)
+ * 4829:     function typoLink($linktxt, $conf)
+ * 5111:     function typoLink_URL($conf)
+ * 5129:     function getTypoLink($label,$params,$urlParameters=array(),$target='')
+ * 5159:     function getTypoLink_URL($params,$urlParameters=array(),$target='')
+ * 5171:     function typolinkWrap($conf)
+ * 5184:     function currentPageUrl($urlParameters=array(),$id=0)
+ * 5197:     function getClosestMPvalueForPage($pageId, $raw=FALSE)
  *
  *              SECTION: Miscellaneous functions, stand alone
- * 5024:     function wrap($content,$wrap,$char='|')
- * 5040:     function noTrimWrap($content,$wrap)
- * 5054:     function wrapSpace($content, $wrap)
- * 5080:     function callUserFunction($funcName,$conf,$content)
- * 5121:     function processParams($params)
- * 5139:     function keywords($content)
- * 5156:     function caseshift($theValue, $case)
- * 5179:     function HTMLcaseshift($theValue, $case)
- * 5208:     function bytes($sizeInBytes,$labels)
- * 5219:     function calcAge($seconds,$labels)
- * 5250:     function sendNotifyEmail($msg, $recipients, $cc, $email_from, $email_fromName='', $replyTo='')
- * 5277:     function URLqMark($url,$params)
- * 5293:     function checkEmail($email)
- * 5305:     function clearTSProperties($TSArr,$propList)
- * 5324:     function mergeTSRef($confArr,$prop)
- * 5347:     function joinTSarrays($conf,$old_conf)
- * 5370:     function gifBuilderTextBox($gifbuilderConf, $conf, $text)
- * 5426:     function linebreaks($string,$chars,$maxLines=0)
- * 5457:     function getUpdateJS($dataArray, $formName, $arrPrefix, $fieldList)
+ * 5273:     function wrap($content,$wrap,$char='|')
+ * 5289:     function noTrimWrap($content,$wrap)
+ * 5303:     function wrapSpace($content, $wrap)
+ * 5329:     function callUserFunction($funcName,$conf,$content)
+ * 5370:     function processParams($params)
+ * 5388:     function keywords($content)
+ * 5405:     function caseshift($theValue, $case)
+ * 5430:     function HTMLcaseshift($theValue, $case)
+ * 5459:     function bytes($sizeInBytes,$labels)
+ * 5470:     function calcAge($seconds,$labels)
+ * 5501:     function sendNotifyEmail($msg, $recipients, $cc, $email_from, $email_fromName='', $replyTo='')
+ * 5528:     function URLqMark($url,$params)
+ * 5544:     function checkEmail($email)
+ * 5556:     function clearTSProperties($TSArr,$propList)
+ * 5575:     function mergeTSRef($confArr,$prop)
+ * 5598:     function joinTSarrays($conf,$old_conf)
+ * 5621:     function gifBuilderTextBox($gifbuilderConf, $conf, $text)
+ * 5677:     function linebreaks($string,$chars,$maxLines=0)
+ * 5708:     function getUpdateJS($dataArray, $formName, $arrPrefix, $fieldList)
  *
  *              SECTION: Database functions, making of queries
- * 5526:     function DBgetDelete($table, $uid, $doExec=FALSE)
- * 5558:     function DBgetUpdate($table, $uid, $dataArr, $fieldList, $doExec=FALSE)
- * 5600:     function DBgetInsert($table, $pid, $dataArr, $fieldList, $doExec=FALSE)
- * 5637:     function DBmayFEUserEdit($table,$row, $feUserRow, $allowedGroups='',$feEditSelf=0)
- * 5677:     function DBmayFEUserEditSelect($table,$feUserRow,$allowedGroups='',$feEditSelf=0)
- * 5717:     function enableFields($table,$show_hidden=0)
- * 5741:     function getTreeList($id,$depth,$begin=0,$dontCheckEnableFields=FALSE,$addSelectFields='',$moreWhereClauses='', $prevId_array=array(), $recursionLevel=0)
- * 5838:     function whereSelectFromList($field,$value)
- * 5856:     function exec_mm_query($select,$local_table,$mm_table,$foreign_table,$whereClause='',$groupBy='',$orderBy='',$limit='')
- * 5883:     function exec_mm_query_uidList($select,$local_table_uidlist,$mm_table,$foreign_table='',$whereClause='',$groupBy='',$orderBy='',$limit='')
- * 5904:     function searchWhere($sw,$searchFieldList,$searchTable='')
- * 5937:     function exec_getQuery($table, $conf)
- * 5955:     function getQuery($table, $conf, $returnQueryArray=FALSE)
- * 6034:     function getWhere($table,$conf, $returnQueryArray=FALSE)
- * 6120:     function checkPidArray($listArr)
- * 6143:     function checkPid($uid)
+ * 5777:     function DBgetDelete($table, $uid, $doExec=FALSE)
+ * 5809:     function DBgetUpdate($table, $uid, $dataArr, $fieldList, $doExec=FALSE)
+ * 5851:     function DBgetInsert($table, $pid, $dataArr, $fieldList, $doExec=FALSE)
+ * 5888:     function DBmayFEUserEdit($table,$row, $feUserRow, $allowedGroups='',$feEditSelf=0)
+ * 5928:     function DBmayFEUserEditSelect($table,$feUserRow,$allowedGroups='',$feEditSelf=0)
+ * 5968:     function enableFields($table,$show_hidden=0)
+ * 5992:     function getTreeList($id,$depth,$begin=0,$dontCheckEnableFields=FALSE,$addSelectFields='',$moreWhereClauses='', $prevId_array=array(), $recursionLevel=0)
+ * 6092:     function whereSelectFromList($field,$value)
+ * 6110:     function exec_mm_query($select,$local_table,$mm_table,$foreign_table,$whereClause='',$groupBy='',$orderBy='',$limit='')
+ * 6137:     function exec_mm_query_uidList($select,$local_table_uidlist,$mm_table,$foreign_table='',$whereClause='',$groupBy='',$orderBy='',$limit='')
+ * 6158:     function searchWhere($sw,$searchFieldList,$searchTable='')
+ * 6191:     function exec_getQuery($table, $conf)
+ * 6209:     function getQuery($table, $conf, $returnQueryArray=FALSE)
+ * 6288:     function getWhere($table,$conf, $returnQueryArray=FALSE)
+ * 6382:     function checkPidArray($listArr)
+ * 6405:     function checkPid($uid)
  *
  *              SECTION: Frontend editing functions
- * 6199:     function editPanel($content, $conf, $currentRecord='', $dataArr=array())
- * 6363:     function editIcons($content,$params, $conf=array(), $currentRecord='', $dataArr=array(),$addUrlParamStr='')
- * 6427:     function editPanelLinkWrap($string,$formName,$cmd,$currentRecord='',$confirm='')
- * 6465:     function editPanelLinkWrap_doWrap($string,$url,$currentRecord)
- * 6492:     function editPanelPreviewBorder($table,$row,$content,$thick)
- * 6509:     function isDisabled($table,$row)
+ * 6461:     function editPanel($content, $conf, $currentRecord='', $dataArr=array())
+ * 6626:     function editIcons($content,$params, $conf=array(), $currentRecord='', $dataArr=array(),$addUrlParamStr='')
+ * 6691:     function editPanelLinkWrap($string,$formName,$cmd,$currentRecord='',$confirm='')
+ * 6731:     function editPanelLinkWrap_doWrap($string,$url,$currentRecord)
+ * 6758:     function editPanelPreviewBorder($table,$row,$content,$thick)
+ * 6775:     function isDisabled($table,$row)
  *
  *
- * 6540: class tslib_frameset
- * 6550:     function make($setup)
- * 6587:     function frameParams($setup, $typeNum)
- * 6630:     function framesetParams($setup)
+ * 6806: class tslib_frameset
+ * 6816:     function make($setup)
+ * 6853:     function frameParams($setup, $typeNum)
+ * 6896:     function framesetParams($setup)
  *
  *
- * 6663: class tslib_tableOffset
- * 6675:     function start($content,$offset)
+ * 6929: class tslib_tableOffset
+ * 6941:     function start($content,$offset)
  *
  *
- * 6753: class tslib_controlTable
- * 6788:     function start($offset,$cMargins)
+ * 7019: class tslib_controlTable
+ * 7054:     function start($offset,$cMargins)
  *
- * TOTAL FUNCTIONS: 128
+ * TOTAL FUNCTIONS: 129
  * (This index is automatically created/updated by the extension "extdeveval")
  *
  */
 
 
   // Includes this class since it is used for parsing HTML
-require_once (PATH_t3lib."class.t3lib_parsehtml.php");
+require_once(PATH_t3lib."class.t3lib_parsehtml.php");
 
+       // Object TypoScript library included:
+if(t3lib_extMgm::isLoaded('obts')) {
+       require_once(t3lib_extMgm::extPath('obts').'_tsobject/_tso.php');
+}
 
 
 
@@ -237,17 +242,13 @@ require_once (PATH_t3lib."class.t3lib_parsehtml.php");
  * The class "tslib_cObj" is normally instantiated and referred to as "cObj".
  * When you call your own PHP-code typically through a USER or USER_INT cObject then it is this class that instantiates the object and calls the main method. Before it does so it will set (if you are using classes) a reference to itself in the internal variable "cObj" of the object. Thus you can access all functions and data from this class by $this->cObj->... from within you classes written to be USER or USER_INT content objects.
  *
- * @author     Kasper Skaarhoj <kasper@typo3.com>
+ * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage tslib
  * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&cHash=4ad9d7acb4
  */
 class tslib_cObj {
        var $align = Array ('center', 'right', 'left');
-       var $caseConvStrings = array(
-                       'áéúíâêûôîæøåäöü',
-                       'ÁÉÚÍÄËÜÖÏÆØÅÄÖÜ'
-               );
 
        /**
         * Holds ImageMagick parameters and extensions used for compression
@@ -452,93 +453,100 @@ class tslib_cObj {
                                        $content.=$this->cObjGetSingle($name,$conf,$key);
                                $GLOBALS['TT']->decStackPointer();
                        } else {
-                               switch($name)   {
-                                       case 'COBJ_ARRAY':
-                                       case 'COA':
-                                               $content.=$this->COBJ_ARRAY($conf);
-                                       break;
-                                       case 'COA_INT':
-                                               $content.=$this->COBJ_ARRAY($conf,'INT');
-                                       break;
-                                       case 'HTML':
-                                               $content.=$this->HTML($conf);
-                                       break;
-                                       case 'TEXT':
-                                               $content.=$this->TEXT($conf);
-                                       break;
-                                       case 'CLEARGIF':
-                                               $content.=$this->CLEARGIF($conf);
-                                       break;
-                                       case 'FILE':
-                                               $content.=$this->FILE($conf);
-                                       break;
-                                       case 'IMAGE':
-                                               $content.=$this->IMAGE($conf);
-                                       break;
-                                       case 'IMG_RESOURCE':
-                                               $content.=$this->IMG_RESOURCE($conf);
-                                       break;
-                                       case 'IMGTEXT':
-                                               $content.=$this->IMGTEXT($conf);
-                                       break;
-                                       case 'CONTENT':
-                                               $content.=$this->CONTENT($conf);
-                                       break;
-                                       case 'RECORDS':
-                                               $content.=$this->RECORDS($conf);
-                                       break;
-                                       case 'HMENU':
-                                               $content.=$this->HMENU($conf);
-                                       break;
-                                       case 'CTABLE':
-                                               $content.=$this->CTABLE($conf);
-                                       break;
-                                       case 'OTABLE':
-                                               $content.=$this->OTABLE($conf);
-                                       break;
-                                       case 'COLUMNS':
-                                               $content.=$this->COLUMNS($conf);
-                                       break;
-                                       case 'HRULER':
-                                               $content.=$this->HRULER($conf);
-                                       break;
-                                       case 'CASE':
-                                               $content.=$this->CASEFUNC($conf);
-                                       break;
-                                       case 'LOAD_REGISTER':
-                                       case 'RESTORE_REGISTER':
-                                               $this->LOAD_REGISTER($conf,$name);
-                                       break;
-                                       case 'FORM':
-                                               $content.=$this->FORM($conf);
-                                       break;
-                                       case 'SEARCHRESULT':
-                                               $content.=$this->SEARCHRESULT($conf);
-                                       break;
-                                       case 'PHP_SCRIPT':
-                                               $content.=$this->PHP_SCRIPT($conf);
-                                       break;
-                                       case 'PHP_SCRIPT_EXT':
-                                               $content.=$this->PHP_SCRIPT($conf,'EXT');
-                                       break;
-                                       case 'PHP_SCRIPT_INT':
-                                               $content.=$this->PHP_SCRIPT($conf,'INT');
-                                       break;
-                                       case 'USER':
-                                               $content.=$this->USER($conf);
-                                       break;
-                                       case 'USER_INT':
-                                               $content.=$this->USER($conf,'INT');
-                                       break;
-                                       case 'TEMPLATE':
-                                               $content.=$this->TEMPLATE($conf);
-                                       break;
-                                       case 'EDITPANEL':
-                                               if ($GLOBALS['TSFE']->beUserLogin)      {$content.=$this->editPanel($content, $conf);}
-                                       break;
-                                       case 'MULTIMEDIA':
-                                               $content.=$this->MULTIMEDIA($conf);
-                                       break;
+
+                                       // Object TypoScript hook:
+                               if(t3lib_extMgm::isLoaded('obts') && isset($GLOBALS['OBTS']['tso_list'][$name])) {
+                                       $content.= obts_dtutil::renderDatatypeContent($name, $GLOBALS['OBTS']['tso_list'][$name], $conf, $this);
+                               } else {
+                                               // Traditional Content Object branching:
+                                       switch($name)   {
+                                               case 'COBJ_ARRAY':
+                                               case 'COA':
+                                                       $content.=$this->COBJ_ARRAY($conf);
+                                               break;
+                                               case 'COA_INT':
+                                                       $content.=$this->COBJ_ARRAY($conf,'INT');
+                                               break;
+                                               case 'HTML':
+                                                       $content.=$this->HTML($conf);
+                                               break;
+                                               case 'TEXT':
+                                                       $content.=$this->TEXT($conf);
+                                               break;
+                                               case 'CLEARGIF':
+                                                       $content.=$this->CLEARGIF($conf);
+                                               break;
+                                               case 'FILE':
+                                                       $content.=$this->FILE($conf);
+                                               break;
+                                               case 'IMAGE':
+                                                       $content.=$this->IMAGE($conf);
+                                               break;
+                                               case 'IMG_RESOURCE':
+                                                       $content.=$this->IMG_RESOURCE($conf);
+                                               break;
+                                               case 'IMGTEXT':
+                                                       $content.=$this->IMGTEXT($conf);
+                                               break;
+                                               case 'CONTENT':
+                                                       $content.=$this->CONTENT($conf);
+                                               break;
+                                               case 'RECORDS':
+                                                       $content.=$this->RECORDS($conf);
+                                               break;
+                                               case 'HMENU':
+                                                       $content.=$this->HMENU($conf);
+                                               break;
+                                               case 'CTABLE':
+                                                       $content.=$this->CTABLE($conf);
+                                               break;
+                                               case 'OTABLE':
+                                                       $content.=$this->OTABLE($conf);
+                                               break;
+                                               case 'COLUMNS':
+                                                       $content.=$this->COLUMNS($conf);
+                                               break;
+                                               case 'HRULER':
+                                                       $content.=$this->HRULER($conf);
+                                               break;
+                                               case 'CASE':
+                                                       $content.=$this->CASEFUNC($conf);
+                                               break;
+                                               case 'LOAD_REGISTER':
+                                               case 'RESTORE_REGISTER':
+                                                       $this->LOAD_REGISTER($conf,$name);
+                                               break;
+                                               case 'FORM':
+                                                       $content.=$this->FORM($conf);
+                                               break;
+                                               case 'SEARCHRESULT':
+                                                       $content.=$this->SEARCHRESULT($conf);
+                                               break;
+                                               case 'PHP_SCRIPT':
+                                                       $content.=$this->PHP_SCRIPT($conf);
+                                               break;
+                                               case 'PHP_SCRIPT_EXT':
+                                                       $content.=$this->PHP_SCRIPT($conf,'EXT');
+                                               break;
+                                               case 'PHP_SCRIPT_INT':
+                                                       $content.=$this->PHP_SCRIPT($conf,'INT');
+                                               break;
+                                               case 'USER':
+                                                       $content.=$this->USER($conf);
+                                               break;
+                                               case 'USER_INT':
+                                                       $content.=$this->USER($conf,'INT');
+                                               break;
+                                               case 'TEMPLATE':
+                                                       $content.=$this->TEMPLATE($conf);
+                                               break;
+                                               case 'EDITPANEL':
+                                                       if ($GLOBALS['TSFE']->beUserLogin)      {$content.=$this->editPanel($content, $conf);}
+                                               break;
+                                               case 'MULTIMEDIA':
+                                                       $content.=$this->MULTIMEDIA($conf);
+                                               break;
+                                       }
                                }
                        }
                        if ($GLOBALS['TT']->LR) $GLOBALS['TT']->pull($content);
@@ -595,7 +603,7 @@ class tslib_cObj {
                $w = $w ? $w : 1;
                $h = $h ? $h : 1;
                $wrap = $conf['wrap'] ? $conf['wrap'] : '|<br />';
-               $theValue = $this->wrap('<img src="'.$GLOBALS['TSFE']->absRefPrefix.'clear.gif" width="'.$w.'" height="'.$h.'" border="0" alt="" title="" />', $wrap);
+               $theValue = $this->wrap('<img src="'.$GLOBALS['TSFE']->absRefPrefix.'clear.gif" width="'.$w.'" height="'.$h.'"'.$this->getBorderAttr(' border="0"').' alt="" title="" />', $wrap);
 
                return $this->stdWrap($theValue,$conf['stdWrap.']);
        }
@@ -672,7 +680,7 @@ class tslib_cObj {
         * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=352&cHash=379c60f8bc
         */
        function FILE($conf)    {
-               $theValue = $this->fileResource($this->stdWrap($conf['file'],$conf['file.']));
+               $theValue = $this->fileResource($this->stdWrap($conf['file'],$conf['file.']), trim($this->getAltParam($conf)));
                if ($conf['linkWrap'])  {
                        $theValue = $this->linkWrap($theValue,$conf['linkWrap']);
                }
@@ -903,7 +911,8 @@ class tslib_cObj {
                                        }
                                }
 
-                               if ($imgConf || $imgConf['file']) {
+                                       // Image Object supplied:
+                               if (is_array($imgConf)) {
                                        if ($this->image_effects[$image_effects])       {
                                                $imgConf['file.']['params'].= ' '.$this->image_effects[$image_effects];
                                        }
@@ -925,12 +934,31 @@ class tslib_cObj {
                                                        unset($imgConf['file.']['ext.']);
                                                }
                                        }
-                                       if (!isset ($imgConf['alttext'])) $imgConf['alttext'] = $conf['alttext'];
-                                       if (!isset ($imgConf['titletext'])) $imgConf['titletext'] = $conf['titletext'];
-                                       $imgsTag[$imgKey] = $this->IMAGE($imgConf);
+
+                                               // "alt", "title" and "longdesc" attributes:
+                                       if (!strlen($imgConf['altText']) && !is_array($imgConf['altText.'])) {
+                                               $imgConf['altText'] = $conf['altText'];
+                                               $imgConf['altText.'] = $conf['altText.'];
+                                       }
+                                       if (!strlen($imgConf['titleText']) && !is_array($imgConf['titleText.'])) {
+                                               $imgConf['titleText'] = $conf['titleText'];
+                                               $imgConf['titleText.'] = $conf['titleText.'];
+                                       }
+                                       if (!strlen($imgConf['longdescURL']) && !is_array($imgConf['longdescURL.'])) {
+                                               $imgConf['longdescURL'] = $conf['longdescURL'];
+                                               $imgConf['longdescURL.'] = $conf['longdescURL.'];
+                                       }
                                } else {
-                                       $imgsTag[$imgKey] = $this->IMAGE(Array('alttext'=>$conf['alttext'], 'titletext'=>$conf['titletext'], 'file'=>$totalImagePath));         // currentValKey !!!
+                                       $imgConf = array(
+                                               'altText' => $conf['altText'],
+                                               'titleText' => $conf['titleText'],
+                                               'longdescURL' => $conf['longdescURL'],
+                                               'file' => $totalImagePath
+                                       );
                                }
+
+                               $imgsTag[$imgKey] = $this->IMAGE($imgConf);
+
                                        // Store the original filepath
                                $origImages[$imgKey]=$GLOBALS['TSFE']->lastImageInfo;
 
@@ -995,15 +1023,15 @@ class tslib_cObj {
                                // draw table
                        for ($c=0;$c<$rowCount;$c++) {  // Looping through rows. If 'noRows' is set, this is '1 time', but $rowCount_temp will hold the actual number of rows!
                                if ($c && $rowspacing)  {               // If this is NOT the first time in the loop AND if space is required, a row-spacer is added. In case of "noRows" rowspacing is done further down.
-                                       $tablecode.='<tr><td colspan="'.$colspan.'"><img src="'.$GLOBALS['TSFE']->absRefPrefix.'clear.gif" width="1" height="'.$rowspacing.'" border="0" alt="" title="" /></td></tr>';
+                                       $tablecode.='<tr><td colspan="'.$colspan.'"><img src="'.$GLOBALS['TSFE']->absRefPrefix.'clear.gif" width="1" height="'.$rowspacing.'"'.$this->getBorderAttr(' border="0"').' alt="" title="" /></td></tr>';
                                }
                                $tablecode.='<tr>';     // starting row
                                for ($b=0; $b<$colCount_temp; $b++)     {       // Looping through the columns
                                        if ($b && $colspacing)  {               // If this is NOT the first iteration AND if column space is required. In case of "noCols", the space is done without a separate cell.
                                                if (!$noCols)   {
-                                                       $tablecode.='<td><img src="'.$GLOBALS['TSFE']->absRefPrefix.'clear.gif" width="'.$colspacing.'" height="1" border="0" alt="" title="" /></td>';
+                                                       $tablecode.='<td><img src="'.$GLOBALS['TSFE']->absRefPrefix.'clear.gif" width="'.$colspacing.'" height="1"'.$this->getBorderAttr(' border="0"').' alt="" title="" /></td>';
                                                } else {
-                                                       $colSpacer='<img src="'.$GLOBALS['TSFE']->absRefPrefix.'clear.gif" width="'.($border?$colspacing-6:$colspacing).'" height="'.($imageRowsMaxHeights[$c]+($border?$borderThickness*2:0)).'" border="0" align="'.($border?'left':'top').'" alt="" title="" />';
+                                                       $colSpacer='<img src="'.$GLOBALS['TSFE']->absRefPrefix.'clear.gif" width="'.($border?$colspacing-6:$colspacing).'" height="'.($imageRowsMaxHeights[$c]+($border?$borderThickness*2:0)).'"'.$this->getBorderAttr(' border="0"').' align="'.($border?'left':'top').'" alt="" title="" />';
                                                        $colSpacer='<td valign="top">'.$colSpacer.'</td>';      // added 160301, needed for the new "noCols"-table...
                                                        $tablecode.=$colSpacer;
                                                }
@@ -1056,10 +1084,10 @@ class tslib_cObj {
                        $spaceBelowAbove = intval($this->stdWrap($conf['spaceBelowAbove'],$conf['spaceBelowAbove.']));
                        switch ($contentPosition)       {
                                case '0':       // above
-                                       $output= '<div align="'.$align.'">'.$tablecode.'</div>'.$this->wrapSpace($content, $spaceBelowAbove.'|0');
+                                       $output= '<div style="text-align:'.$align.';">'.$tablecode.'</div>'.$this->wrapSpace($content, $spaceBelowAbove.'|0');
                                break;
                                case '8':       // below
-                                       $output= $this->wrapSpace($content, '0|'.$spaceBelowAbove).'<div align="'.$align.'">'.$tablecode.'</div>';
+                                       $output= $this->wrapSpace($content, '0|'.$spaceBelowAbove).'<div style="text-align:'.$align.';">'.$tablecode.'</div>';
                                break;
                                case '16':      // in text
                                        $output= $tablecode.$content;
@@ -1108,28 +1136,65 @@ class tslib_cObj {
                        $renderObjKey = $conf['renderObj'] ? 'renderObj' : '';
                        $renderObjConf = $conf['renderObj.'];
 
-                       $res = $this->exec_getQuery($conf['table'],$conf['select.']);
-                       if ($error = $GLOBALS['TYPO3_DB']->sql_error()) {
-                               $GLOBALS['TT']->setTSlogMessage($error,3);
-                       } else {
-                               $this->currentRecordTotal = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
-                               $GLOBALS['TT']->setTSlogMessage('NUMROWS: '.$GLOBALS['TYPO3_DB']->sql_num_rows($res));
-                               $cObj =t3lib_div::makeInstance('tslib_cObj');
-                               $cObj->setParent($this->data,$this->currentRecord);
-                               $this->currentRecordNumber=0;
-                               while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))      {
-                                       if (!$GLOBALS['TSFE']->recordRegister[$conf['table'].':'.$row['uid']])  {
-                                               $this->currentRecordNumber++;
-                                               $cObj->parentRecordNumber = $this->currentRecordNumber;
-                                               $GLOBALS['TSFE']->currentRecord = $conf['table'].':'.$row['uid'];
-                                               $this->lastChanged($row['tstamp']);
-                                               $cObj->start($row,$conf['table']);
-                                               if ($GLOBALS['TSFE']->config['config']['insertDmailerBoundaries'])      { $theValue.='<!--DMAILER_SECTION_BOUNDARY_'.intval($row['module_sys_dmail_category']).'-->'; }
-                                               $theValue.= $cObj->cObjGetSingle($renderObjName, $renderObjConf, $renderObjKey);
-                                       }# else debug($GLOBALS['TSFE']->recordRegister,'CONTENT');
+                       $slide = intval($conf['slide'])?intval($conf['slide']):0;
+                       $slideCollect = intval($conf['slide.']['collect'])?intval($conf['slide.']['collect']):0;
+                       $slideCollectReverse = intval($conf['slide.']['collectReverse'])?true:false;
+                       $slideCollectFuzzy = $slideCollect?(intval($conf['slide.']['collectFuzzy'])?true:false):true;
+                       $again = false;
+
+                       do {
+                               $res = $this->exec_getQuery($conf['table'],$conf['select.']);
+                               if ($error = $GLOBALS['TYPO3_DB']->sql_error()) {
+                                       $GLOBALS['TT']->setTSlogMessage($error,3);
+                               } else {
+                                       $this->currentRecordTotal = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
+                                       $GLOBALS['TT']->setTSlogMessage('NUMROWS: '.$GLOBALS['TYPO3_DB']->sql_num_rows($res));
+                                       $cObj =t3lib_div::makeInstance('tslib_cObj');
+                                       $cObj->setParent($this->data,$this->currentRecord);
+                                       $this->currentRecordNumber=0;
+                                       $cobjValue = '';
+                                       while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
+
+                                               // Versioning preview:
+                                               $GLOBALS['TSFE']->sys_page->versionOL($conf['table'],$row);
+
+                                               // Language Overlay:
+                                               if (is_array($row) && $GLOBALS['TSFE']->sys_language_contentOL) {
+                                               $row = $GLOBALS['TSFE']->sys_page->getRecordOverlay($conf['table'],$row,$GLOBALS['TSFE']->sys_language_content,$GLOBALS['TSFE']->sys_language_contentOL);
+                                               }
+
+                                               if (is_array($row)) { // Might be unset in the sys_language_contentOL
+                                                       if (!$GLOBALS['TSFE']->recordRegister[$conf['table'].':'.$row['uid']]) {
+                                                               $this->currentRecordNumber++;
+                                                               $cObj->parentRecordNumber = $this->currentRecordNumber;
+                                                               $GLOBALS['TSFE']->currentRecord = $conf['table'].':'.$row['uid'];
+                                                               $this->lastChanged($row['tstamp']);
+                                                               $cObj->start($row,$conf['table']);
+                                                               if ($GLOBALS['TSFE']->config['config']['insertDmailerBoundaries']) { $cobjValue.='<!--DMAILER_SECTION_BOUNDARY_'.intval($row['module_sys_dmail_category']).'-->'; }
+                                                               $tmpValue = $cObj->cObjGetSingle($renderObjName, $renderObjConf, $renderObjKey);
+                                                               $cobjValue .= $tmpValue;
+                                                       }# else debug($GLOBALS['TSFE']->recordRegister,'CONTENT');
+                                               }
+                                       }
+
+                                       if ($GLOBALS['TSFE']->config['config']['insertDmailerBoundaries']) { $cobjValue.='<!--DMAILER_SECTION_BOUNDARY_END-->'; }
                                }
-                               if ($GLOBALS['TSFE']->config['config']['insertDmailerBoundaries'])      { $theValue.='<!--DMAILER_SECTION_BOUNDARY_END-->'; }
-                       }
+                               if ($slideCollectReverse) {
+                                       $theValue = $cobjValue.$theValue;
+                               } else {
+                                       $theValue .= $cobjValue;
+                               }
+                               if ($slideCollect>0) {
+                                       $slideCollect--;
+                               }
+                               if ($slide) {
+                                       if ($slide>0) {
+                                               $slide--;
+                                       }
+                                       $conf['select.']['pidInList'] = $this->getSlidePids($conf['select.']['pidInList'], $conf['select.']['pidInList.']);
+                                       $again = strlen($conf['select.']['pidInList'])?true:false;
+                               }
+                       } while ($again&&(($slide&&!strlen($tmpValue)&&$slideCollectFuzzy)||($slide&&$slideCollect)));
                }
 
                $theValue = $this->wrap($theValue,$conf['wrap']);
@@ -1184,22 +1249,33 @@ class tslib_cObj {
                        reset($loadDB->itemArray);
                        while(list(,$val)=each($loadDB->itemArray))     {
                                $row = $data[$val['table']][$val['id']];
-                               if (!$conf['dontCheckPid'])     {
-                                       $row = $this->checkPid($row['pid']) ? $row : '';
-                               }
-                               if ($row && !$GLOBALS['TSFE']->recordRegister[$val['table'].':'.$val['id']])    {
-                                       $renderObjName = $conf['conf.'][$val['table']] ? $conf['conf.'][$val['table']] : '<'.$val['table'];
-                                       $renderObjKey = $conf['conf.'][$val['table']] ? 'conf.'.$val['table'] : '';
-                                       $renderObjConf = $conf['conf.'][$val['table'].'.'];
-                                       $this->currentRecordNumber++;
-                                       $cObj->parentRecordNumber=$this->currentRecordNumber;
-                                       $GLOBALS['TSFE']->currentRecord = $val['table'].':'.$val['id'];
-                                       $this->lastChanged($row['tstamp']);
-                                       $cObj->start($row,$val['table']);
-                                       if ($GLOBALS['TSFE']->config['config']['insertDmailerBoundaries'])      {$theValue.='<!--DMAILER_SECTION_BOUNDARY_'.intval($row['module_sys_dmail_category']).'-->';}
-                                       $theValue.=$cObj->cObjGetSingle($renderObjName, $renderObjConf, $renderObjKey);
-                                       if ($GLOBALS['TSFE']->config['config']['insertDmailerBoundaries'])      {$theValue.='<!--DMAILER_SECTION_BOUNDARY_END-->';}
-                               }# else debug($GLOBALS['TSFE']->recordRegister,'RECORDS');
+
+                                       // Versioning preview:
+                               $GLOBALS['TSFE']->sys_page->versionOL($val['table'],$row);
+
+                                       // Language Overlay:
+                               if (is_array($row) && $GLOBALS['TSFE']->sys_language_contentOL) {
+                                       $row = $GLOBALS['TSFE']->sys_page->getRecordOverlay($val['table'],$row,$GLOBALS['TSFE']->sys_language_content,$GLOBALS['TSFE']->sys_language_contentOL);
+                               }
+
+                               if (is_array($row))     {       // Might be unset in the content overlay things...
+                                       if (!$conf['dontCheckPid'])     {
+                                               $row = $this->checkPid($row['pid']) ? $row : '';
+                                       }
+                                       if ($row && !$GLOBALS['TSFE']->recordRegister[$val['table'].':'.$val['id']])    {
+                                               $renderObjName = $conf['conf.'][$val['table']] ? $conf['conf.'][$val['table']] : '<'.$val['table'];
+                                               $renderObjKey = $conf['conf.'][$val['table']] ? 'conf.'.$val['table'] : '';
+                                               $renderObjConf = $conf['conf.'][$val['table'].'.'];
+                                               $this->currentRecordNumber++;
+                                               $cObj->parentRecordNumber=$this->currentRecordNumber;
+                                               $GLOBALS['TSFE']->currentRecord = $val['table'].':'.$val['id'];
+                                               $this->lastChanged($row['tstamp']);
+                                               $cObj->start($row,$val['table']);
+                                               if ($GLOBALS['TSFE']->config['config']['insertDmailerBoundaries'])      {$theValue.='<!--DMAILER_SECTION_BOUNDARY_'.intval($row['module_sys_dmail_category']).'-->';}
+                                               $theValue.=$cObj->cObjGetSingle($renderObjName, $renderObjConf, $renderObjKey);
+                                               if ($GLOBALS['TSFE']->config['config']['insertDmailerBoundaries'])      {$theValue.='<!--DMAILER_SECTION_BOUNDARY_END-->';}
+                                       }# else debug($GLOBALS['TSFE']->recordRegister,'RECORDS');
+                               }
                        }
                }
                $GLOBALS['TSFE']->currentRecord = $originalRec; // Restore
@@ -1482,9 +1558,10 @@ class tslib_cObj {
                        }
                                // Adding the new dataArray config form:
                        if (is_array($conf['dataArray.'])) {    // dataArray is supplied
-                               reset($conf['dataArray.']);
-                               while(list($dAKey,$dAA)=each($conf['dataArray.']))      {
-                                       if (is_array($dAA) && !strcmp(intval($dAKey).'.',$dAKey))       {
+                               $sKeyArray = t3lib_TStemplate::sortedKeyList($conf['dataArray.'], TRUE);
+                               foreach($sKeyArray as $theKey)  {
+                                       $dAA = $conf['dataArray.'][$theKey.'.'];
+                                       if (is_array($dAA))     {
                                                $temp=array();
                                                list($temp[0])= explode('|',$dAA['label.'] ? $this->stdWrap($dAA['label'],$dAA['label.']) : $dAA['label']);
                                                list($temp[1])= explode('|',$dAA['type']);
@@ -1521,7 +1598,14 @@ class tslib_cObj {
                $fieldname_hashArray = Array();
                $cc = 0;
 
+                       // Formname;
+               $formname = $GLOBALS['TSFE']->uniqueHash();
+               if (ctype_digit($formname{0}))  {       // form name must start with a letter
+                       $formname = 'a'.$formname;
+               }
+
                foreach($dataArr as $val)       {
+
                        $cc++;
                        $confData=Array();
                        if (is_array($formData)) {
@@ -1561,11 +1645,13 @@ class tslib_cObj {
                                }
                                $fieldCode='';
 
-
                                if ($conf['wrapFieldName'])     {
                                        $confData['fieldname'] = $this->wrap($confData['fieldname'],$conf['wrapFieldName']);
                                }
 
+                                       // Set field name as current:
+                               $this->setCurrentVal($confData['fieldname']);
+
                                        // Additional parameters
                                if (trim($confData['type']))    {
                                        $addParams=trim($conf['params']);
@@ -1575,6 +1661,14 @@ class tslib_cObj {
                                        if (strcmp('',$addParams))      $addParams=' '.$addParams;
                                } else $addParams='';
 
+                                       // Accessibility: Set id = fieldname attribute:
+                               if ($conf['accessibility'])     {
+                                       $elementIdAttribute = ' id="'.$formname.'_'.md5($confData['fieldname']).'"';
+                               } else {
+                                       $elementIdAttribute = '';
+                               }
+
+                                       // Create form field based on configuration/type:
                                switch($confData['type'])       {
                                        case 'textarea':
                                                $cols=trim($fParts[1]) ? intval($fParts[1]) : 20;
@@ -1583,9 +1677,14 @@ class tslib_cObj {
                                                $cols = t3lib_div::intInRange($cols*$compWidth, 1, 120);
 
                                                $rows=trim($fParts[2]) ? t3lib_div::intInRange($fParts[2],1,30) : 5;
-                                               $wrap=trim($fParts[3]) ? ' wrap="'.trim($fParts[3]).'"' : ' wrap="virtual"';
-                                               $default = $this->getFieldDefaultValue($conf['noValueInsert'], $confData['fieldname'], trim($parts[2]));
-                                               $fieldCode=sprintf('<textarea name="%s" cols="%s" rows="%s"%s'.$addParams.'>%s</textarea>',
+                                               $wrap=trim($fParts[3]);
+                                               if ($conf['noWrapAttr'] || $wrap === 'disabled')        {
+                                                       $wrap='';
+                                               } else {
+                                                       $wrap = $wrap ? ' wrap="'.$wrap.'"' : ' wrap="virtual"';
+                                               }
+                                               $default = $this->getFieldDefaultValue($conf['noValueInsert'], $confData['fieldname'], str_replace('\n',chr(10),trim($parts[2])));
+                                               $fieldCode=sprintf('<textarea name="%s"'.$elementIdAttribute.' cols="%s" rows="%s"%s'.$addParams.'>%s</textarea>',
                                                        $confData['fieldname'], $cols, $rows, $wrap, t3lib_div::formatForTextarea($default));
                                        break;
                                        case 'input':
@@ -1595,6 +1694,7 @@ class tslib_cObj {
                                                $compWidth = $compWidth ? $compWidth : 1;
                                                $size = t3lib_div::intInRange($size*$compWidth, 1, 120);
                                                $default = $this->getFieldDefaultValue($conf['noValueInsert'], $confData['fieldname'], trim($parts[2]));
+
                                                if ($confData['type']=='password')      {
                                                        $default='';
                                                }
@@ -1602,19 +1702,20 @@ class tslib_cObj {
                                                $max=trim($fParts[2]) ? ' maxlength="'.t3lib_div::intInRange($fParts[2],1,1000).'"' : "";
                                                $theType = $confData['type']=='input' ? 'text' : 'password';
 
-                                               $fieldCode=sprintf('<input type="'.$theType.'" name="%s" size="%s"%s value="%s"'.$addParams.' />',
+                                               $fieldCode=sprintf('<input type="'.$theType.'" name="%s"'.$elementIdAttribute.' size="%s"%s value="%s"'.$addParams.' />',
                                                        $confData['fieldname'], $size, $max, htmlspecialchars($default));
+
                                        break;
                                        case 'file':
                                                $size=trim($fParts[1]) ? t3lib_div::intInRange($fParts[1],1,60) : 20;
-                                               $fieldCode=sprintf('<input type="file" name="%s" size="%s"'.$addParams.' />',
+                                               $fieldCode=sprintf('<input type="file" name="%s"'.$elementIdAttribute.' size="%s"'.$addParams.' />',
                                                        $confData['fieldname'], $size);
                                        break;
                                        case 'check':
                                                        // alternative default value:
                                                $default = $this->getFieldDefaultValue($conf['noValueInsert'], $confData['fieldname'], trim($parts[2]));
                                                $checked = $default ? ' checked="checked"' : '';
-                                               $fieldCode=sprintf('<input type="checkbox" value="%s" name="%s"%s'.$addParams.' />',
+                                               $fieldCode=sprintf('<input type="checkbox" value="%s" name="%s"'.$elementIdAttribute.'%s'.$addParams.' />',
                                                        1, $confData['fieldname'], $checked);
                                        break;
                                        case 'select':
@@ -1652,7 +1753,7 @@ class tslib_cObj {
                                                }
 
                                                if ($multiple)  $confData['fieldname'].='[]';   // The fieldname must be prepended '[]' if multiple select. And the reason why it's prepended is, because the required-field list later must also have [] prepended.
-                                               $fieldCode=sprintf('<select name="%s" size="%s"%s'.$addParams.'>%s</select>',
+                                               $fieldCode=sprintf('<select name="%s"'.$elementIdAttribute.' size="%s"%s'.$addParams.'>%s</select>',
                                                        $confData['fieldname'], $size, $multiple, $option); //RTF
                                        break;
                                        case 'radio':
@@ -1676,7 +1777,7 @@ class tslib_cObj {
                                                $default = $this->getFieldDefaultValue($conf['noValueInsert'], $confData['fieldname'], $default);
                                                        // Create the select-box:
                                                for($a=0;$a<count($items);$a++) {
-                                                       $option.= '<input type="radio" name="'.$confData['fieldname'].'" value="'.$items[$a][1].'"'.(!strcmp($items[$a][1],$default)?' checked="checked"':'').''.$addParams.' />';
+                                                       $option.= '<input type="radio" name="'.$confData['fieldname'].'"'.$elementIdAttribute.' value="'.$items[$a][1].'"'.(!strcmp($items[$a][1],$default)?' checked="checked"':'').''.$addParams.' />';
                                                        $option.= $this->stdWrap(trim($items[$a][0]), $conf['radioWrap.']);
                                                        $option.= '<br />';
                                                }
@@ -1684,10 +1785,13 @@ class tslib_cObj {
                                        break;
                                        case 'hidden':
                                                $value = trim($parts[2]);
+                                               if(strlen($value) && t3lib_div::inList('recipient_copy,recipient',$confData['fieldname']) && $GLOBALS['TYPO3_CONF_VARS']['FE']['secureFormmail']) {
+                                                       break;
+                                               }
                                                if (strlen($value) && t3lib_div::inList('recipient_copy,recipient',$confData['fieldname']))     {
                                                        $value = $GLOBALS['TSFE']->codeString($value);
                                                }
-                                               $hiddenfields.=sprintf('<input type="hidden" name="%s" value="%s" />',
+                                               $hiddenfields.=sprintf('<input type="hidden" name="%s"'.$elementIdAttribute.' value="%s" />',
                                                        $confData['fieldname'], htmlspecialchars($value));
                                        break;
                                        case 'property':
@@ -1705,14 +1809,22 @@ class tslib_cObj {
                                                } else $image='';
                                                if($image)      {
                                                        $fieldCode = str_replace('<img','<input type="image"'.$addParams.' name="'.$confData['fieldname'].'"' ,$image);
-                                               } else {
-                                                       $fieldCode=sprintf('<input type="submit" name="%s" value="%s"'.$addParams.' />',
+                                               } else  {
+                                                       $fieldCode=sprintf('<input type="submit" name="%s"'.$elementIdAttribute.' value="%s"'.$addParams.' />',
                                                                $confData['fieldname'], t3lib_div::deHSCentities(htmlspecialchars($value)));
                                                }
                                        break;
+                                       case 'reset':
+                                               $value=trim($parts[2]);
+                                               $fieldCode=sprintf('<input type="reset" name="%s"'.$elementIdAttribute.' value="%s"'.$addParams.' />',
+                                                       $confData['fieldname'], t3lib_div::deHSCentities(htmlspecialchars($value)));
+                                       break;
+                                       case 'label':
+                                               $fieldCode = nl2br(htmlspecialchars(trim($parts[2])));
+                                       break;
                                        default:
-                                               $confData['type']='comment';
-                                               $fieldCode=trim($parts[2]).'&nbsp;';
+                                               $confData['type'] = 'comment';
+                                               $fieldCode = trim($parts[2]).'&nbsp;';
                                        break;
                                }
                                if ($fieldCode) {
@@ -1748,16 +1860,22 @@ class tslib_cObj {
                                                break;
                                        }
 
+                                               // Field:
+                                       $fieldLabel = $confData['label'];
+                                       if ($conf['accessibility'])     {
+                                               $fieldLabel = '<label for="'.$formname.'_'.md5($confData['fieldname']).'">'.$fieldLabel.'</label>';
+                                       }
+
                                                // Getting template code:
                                        $fieldCode = $this->stdWrap($fieldCode, $conf['fieldWrap.']);
-                                       $labelCode = $this->stdWrap($confData['label'], $conf['labelWrap.']);
+                                       $labelCode = $this->stdWrap($fieldLabel, $conf['labelWrap.']);
                                        $commentCode = $this->stdWrap($confData['label'], $conf['commentWrap.']); // RTF
                                        $result = $conf['layout'];
                                        if ($conf['REQ'] && $confData['required'])      {
                                                if (is_array($conf['REQ.']['fieldWrap.']))
                                                        $fieldCode = $this->stdWrap($fieldCode, $conf['REQ.']['fieldWrap.']);
                                                if (is_array($conf['REQ.']['labelWrap.']))
-                                                       $labelCode = $this->stdWrap($confData['label'], $conf['REQ.']['labelWrap.']);
+                                                       $labelCode = $this->stdWrap($fieldLabel, $conf['REQ.']['labelWrap.']);
                                                if ($conf['REQ.']['layout'])    {
                                                        $result = $conf['REQ.']['layout'];
                                                }
@@ -1771,6 +1889,9 @@ class tslib_cObj {
                                        if ($confData['type']=='radio' && $conf['RADIO.']['layout'])    {
                                                $result = $conf['RADIO.']['layout'];
                                        }
+                                       if ($confData['type']=='label' && $conf['LABEL.']['layout']) {
+                                               $result = $conf['LABEL.']['layout'];
+                                       }
                                        $result = str_replace('###FIELD###',$fieldCode,$result);
                                        $result = str_replace('###LABEL###',$labelCode,$result);
                                        $result = str_replace('###COMMENT###',$commentCode,$result); //RTF
@@ -1814,14 +1935,14 @@ class tslib_cObj {
 
                        // Recipient:
                $theEmail = $this->stdWrap($conf['recipient'], $conf['recipient.']);
-               if ($theEmail)  {
+               if ($theEmail && !$GLOBALS['TYPO3_CONF_VARS']['FE']['secureFormmail'])  {
                        $theEmail = $GLOBALS['TSFE']->codeString($theEmail);
                        $hiddenfields.='<input type="hidden" name="recipient" value="'.htmlspecialchars($theEmail).'" />';
                }
 
                        // location data:
                if ($conf['locationData'])      {
-                       if ($conf['locationData']=='HTTP_POST_VARS' && isset($GLOBALS['HTTP_POST_VARS']['locationData']))       {
+                       if ($conf['locationData']=='HTTP_POST_VARS' && isset($_POST['locationData']))   {
                                $locationData = t3lib_div::_POST('locationData');
                        } else {
                                $locationData = $GLOBALS['TSFE']->id.':'.$this->currentRecord;  // locationData is [hte page id]:[tablename]:[uid of record]. Indicates on which page the record (from tablename with uid) is shown. Used to check access.
@@ -1836,6 +1957,9 @@ class tslib_cObj {
                                if (substr($hF_key,-1)!='.')    {
                                        $hF_value = $this->cObjGetSingle($hF_conf,$conf['hiddenFields.'][$hF_key.'.'],'hiddenfields');
                                        if (strlen($hF_value) && t3lib_div::inList('recipient_copy,recipient',$hF_key)) {
+                                               if($GLOBALS['TYPO3_CONF_VARS']['FE']['secureFormmail']) {
+                                                       continue;
+                                               }
                                                $hF_value = $GLOBALS['TSFE']->codeString($hF_value);
                                        }
                                        $hiddenfields.='<input type="hidden" name="'.$hF_key.'" value="'.htmlspecialchars($hF_value).'" />';
@@ -1843,10 +1967,11 @@ class tslib_cObj {
                        }
                }
 
-                       // Formname;
-               $formname = $GLOBALS['TSFE']->uniqueHash();
+                       // Wrap all hidden fields in a div tag (see http://bugs.typo3.org/view.php?id=678)
+               $hiddenfields = '<div style="display:none;">'.$hiddenfields.'</div>';
+
                if ($conf['REQ'])       {
-                       $validateForm=' onsubmit="return validateForm(\''.$formname.'\',\''.implode($fieldlist,',').'\',\''.rawurlencode($conf['goodMess']).'\',\''.rawurlencode($conf['badMess']).'\',\''.rawurlencode($conf['emailMess']).'\')"';
+                       $validateForm=' onsubmit="return validateForm(\''.$formname.'\',\''.implode(',',$fieldlist).'\',\''.rawurlencode($conf['goodMess']).'\',\''.rawurlencode($conf['badMess']).'\',\''.rawurlencode($conf['emailMess']).'\')"';
                        $GLOBALS['TSFE']->additionalHeaderData['JSFormValidate'] = '<script type="text/javascript" src="'.$GLOBALS['TSFE']->absRefPrefix.'t3lib/jsfunc.validateform.js"></script>';
                } else $validateForm='';
 
@@ -1942,7 +2067,7 @@ class tslib_cObj {
                                $this->enableFields('pages');
 
                        if ($conf['languageField.'][$search->fTable])   {
-                               $endClause.= ' AND '.$search->fTable.'.'.       $conf['languageField.'][$search->fTable].' = '.intval($GLOBALS['TSFE']->sys_language_uid);
+                               $endClause.= ' AND '.$search->fTable.'.'.$conf['languageField.'][$search->fTable].' = '.intval($GLOBALS['TSFE']->sys_language_uid);     // (using sys_language_uid which is the ACTUAL language of the page. sys_language_content is only for selecting DISPLAY content!)
                        }
 
                                // build query
@@ -2010,6 +2135,7 @@ class tslib_cObj {
                                $cObj->setParent($this->data,$this->currentRecord);
                                $renderCode='';
                                while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($search->result))   {
+                                               // versionOL() here? This is search result displays, is that possible to preview anyway? Or are records selected here already future versions?
                                        $cObj->start($row);
                                        $renderCode.=$cObj->cObjGetSingle($conf['renderObj'], $conf['renderObj.'],'renderObj');
                                }
@@ -2103,6 +2229,13 @@ class tslib_cObj {
                if ($conf['workOnSubpart'])     {
                        $content = $this->getSubpart($content, $PRE.$conf['workOnSubpart'].$POST);
                }
+
+                       // Fixing all relative paths found:
+               if ($conf['relPathPrefix'])     {
+                       $htmlParser = t3lib_div::makeInstance('t3lib_parsehtml');
+                       $content = $htmlParser->prefixResourcePath($conf['relPathPrefix'],$content,$conf['relPathPrefix.']);
+               }
+
                if ($content)   {
                        if ($conf['nonCachedSubst'])    {               // NON-CACHED:
                                        // Getting marks
@@ -2275,9 +2408,9 @@ class tslib_cObj {
                                        unset($parArray['src']);
                                        $parArray['code'] = 'code="'.htmlspecialchars($fileinfo['file']).'"';
                                        $parArray['codebase'] = 'codebase="'.htmlspecialchars($fileinfo['path']).'"';
-                                       $content='<applet '.implode($parArray,' ').'></applet>';
+                                       $content='<applet '.implode(' ',$parArray).'></applet>';
                                } else {
-                                       $content='<embed '.implode($parArray,' ').'></embed>';
+                                       $content='<embed '.implode(' ',$parArray).'></embed>';
                                }
                        }
                }
@@ -2312,6 +2445,36 @@ class tslib_cObj {
         ************************************/
 
        /**
+        * Returns all parents of the given PID (Page UID) list
+        *
+        * @param       string          A list of page Content-Element PIDs (Page UIDs) / stdWrap
+        * @param       array           stdWrap array for the list
+        * @return      string          A list of PIDs
+        * @access private
+        */
+       function getSlidePids($pidList, $pidConf)       {
+               $pidList = trim($this->stdWrap($pidList,$pidConf));
+               if (!strcmp($pidList,''))       {
+                       $pidList = 'this';
+               }
+               if (trim($pidList))     {
+                       $listArr = t3lib_div::intExplode(',',str_replace('this',$GLOBALS['TSFE']->contentPid,$pidList));
+                       $listArr = $this->checkPidArray($listArr);
+               }
+               $pidList = array();
+               if (is_array($listArr)&&count($listArr))        {
+                       foreach ($listArr as $uid)      {
+                               $page = $GLOBALS['TSFE']->sys_page->getPage($uid);
+                               if (!$page['is_siteroot'])      {
+                                       $pidList[] = $page['pid'];
+                               }
+                       }
+               }
+               return implode(',', $pidList);
+       }
+
+
+       /**
         * Creates a link to a netprint application on another website (where the "netprint" extension is running")
         * Related to the extension "netprint"
         *
@@ -2363,7 +2526,7 @@ class tslib_cObj {
         * @access private
         */
        function getFieldDefaultValue($noValueInsert, $fieldName, $defaultVal) {
-               if (!$GLOBALS['TSFE']->no_cache || (!isset($GLOBALS['HTTP_POST_VARS'][$fieldName]) && !isset($GLOBALS['HTTP_GET_VARS'][$fieldName])) || $noValueInsert) {
+               if (!$GLOBALS['TSFE']->no_cache || (!isset($_POST[$fieldName]) && !isset($_GET[$fieldName])) || $noValueInsert) {
                        return $defaultVal;
                } else {
                        return t3lib_div::_GP($fieldName);
@@ -2386,8 +2549,14 @@ class tslib_cObj {
                if (is_array($info))    {
                        $info[3] = t3lib_div::png_to_gif_by_imagemagick($info[3]);
                        $GLOBALS['TSFE']->imagesOnPage[]=$info[3];              // This array is used to collect the image-refs on the page...
+
+                       if (!strlen($conf['altText']) && !is_array($conf['altText.']))  {       // Backwards compatible:
+                               $conf['altText'] = $conf['alttext'];
+                               $conf['altText.'] = $conf['alttext.'];
+                       }
                        $altParam = $this->getAltParam($conf);
-                       $theValue = '<img src="'.htmlspecialchars($GLOBALS['TSFE']->absRefPrefix.t3lib_div::rawUrlEncodeFP($info[3])).'" width="'.$info[0].'" height="'.$info[1].'"  border="'.intval($conf['border']).'"'.($conf['params']?' '.$conf['params']:'').($altParam).' />';
+
+                       $theValue = '<img src="'.htmlspecialchars($GLOBALS['TSFE']->absRefPrefix.t3lib_div::rawUrlEncodeFP($info[3])).'" width="'.$info[0].'" height="'.$info[1].'"'.$this->getBorderAttr(' border="'.intval($conf['border']).'"').($conf['params']?' '.$conf['params']:'').($altParam).' />';
                        if ($conf['linkWrap'])  {
                                $theValue = $this->linkWrap($theValue,$conf['linkWrap']);
                        } elseif ($conf['imageLinkWrap']) {
@@ -2396,6 +2565,17 @@ class tslib_cObj {
                        return $this->wrap($theValue,$conf['wrap']);
                }
        }
+       /**
+        * Returns the 'border' attribute for an <img> tag only if the doctype is not xhtml_strict,xhtml_11 or xhtml_2 or if the config parameter 'disableImgBorderAttr' is not set.
+        *
+        * @param       string          the border attribute
+        * @return      string          the border attribute
+        */
+       function getBorderAttr($borderAttr) {
+               if (!t3lib_div::inList('xhtml_strict,xhtml_11,xhtml_2',$GLOBALS['TSFE']->config['config']['doctype']) || !$GLOBALS['TSFE']->config['config']['disableImgBorderAttr']) {
+                       return $borderAttr;
+               }
+       }
 
        /**
         * Wraps the input string in link-tags that opens the image in a new window.
@@ -2445,7 +2625,7 @@ class tslib_cObj {
                                        $offset = t3lib_div::intExplode(',',$conf['JSwindow.']['expand'].',');
 
                                        $a1='<a href="#" onclick="'.
-                                               htmlspecialchars('openPic(\''.$url.'\',\''.($conf['JSwindow.']['newWindow']?md5($url):'thePicture').'\',\'width='.($dims[0]+$offset[0]).',height='.($dims[1]+$offset[1]).',status=0,menubar=0\'); return false;').
+                                               htmlspecialchars('openPic(\''.$GLOBALS['TSFE']->baseUrlWrap($url).'\',\''.($conf['JSwindow.']['newWindow']?md5($url):'thePicture').'\',\'width='.($dims[0]+$offset[0]).',height='.($dims[1]+$offset[1]).',status=0,menubar=0\'); return false;').
                                                '"'.$GLOBALS['TSFE']->ATagParams.'>';
                                        $a2='</a>';
                                        $GLOBALS['TSFE']->setJS('openPic');
@@ -2465,20 +2645,21 @@ class tslib_cObj {
        }
 
        /**
-        * Returns content of a file. If its an image the content of the file is not returned but rather an image tag is.
+        * Returns content of a file. If it's an image the content of the file is not returned but rather an image tag is.
         *
         * @param       string          The filename, being a TypoScript resource data type
+        * @param       string          Additional parameters (attributes). Default is empty alt and title tags.
         * @return      string          If jpg,gif,jpeg,png: returns image_tag with picture in. If html,txt: returns content string
         * @see FILE()
         */
-       function fileResource($fName)   {
+       function fileResource($fName, $addParams='alt="" title=""')     {
                $incFile = $GLOBALS['TSFE']->tmpl->getFileName($fName);
                if ($incFile)   {
                        $fileinfo = t3lib_div::split_fileref($incFile);
                        if (t3lib_div::inList('jpg,gif,jpeg,png',$fileinfo['fileext'])) {
                                $imgFile = $incFile;
                                $imgInfo = @getImageSize($imgFile);
-                               return '<img src="'.$GLOBALS['TSFE']->absRefPrefix.$imgFile.'" width="'.$imgInfo[0].'" height="'.$imgInfo[1].'" border="0" alt="" title="" />';
+                               return '<img src="'.$GLOBALS['TSFE']->absRefPrefix.$imgFile.'" width="'.$imgInfo[0].'" height="'.$imgInfo[1].'"'.$this->getBorderAttr(' border="0"').' '.$addParams.' />';
                        } elseif (filesize($incFile)<1024*1024) {
                                return $GLOBALS['TSFE']->tmpl->fileContent($incFile);
                        }
@@ -2523,21 +2704,32 @@ class tslib_cObj {
 
        /**
         * An abstraction method which creates an alt or title parameter for an HTML img tag.
+        * From the $conf array it implements the properties "altText", "titleText" and "longdescURL"
         *
         * @param       array           TypoScript configuration properties
         * @return      string          Parameter string containing alt and title parameters (if any)
         * @see IMGTEXT(), cImage()
         */
        function getAltParam($conf)     {
-               $alttext = $this->stdWrap($conf['alttext'], $conf['alttext.']);
-               $altParam = ' alt="'.htmlspecialchars(strip_tags($alttext)).'"';
+               $altText = trim($this->stdWrap($conf['altText'], $conf['altText.']));
+               $titleText = trim($this->stdWrap($conf['titleText'],$conf['titleText.']));
+               $longDesc = trim($this->stdWrap($conf['longdescURL'],$conf['longdescURL.']));
+
+                       // "alt":
+               $altParam = ' alt="'.htmlspecialchars(strip_tags($altText)).'"';
 
-               $titletext = $this->stdWrap($conf['titletext'],$conf['titletext.']);
-               if ($titletext) {
-                       $altParam .= ' title="'.htmlspecialchars(strip_tags($titletext)).'"';
+                       // "title":
+               if ($titleText) {
+                       $altParam.= ' title="'.htmlspecialchars(strip_tags($titleText)).'"';
                } else {
-                       $altParam .= ' title="'.htmlspecialchars(strip_tags($alttext)).'"';
+                       $altParam.= ' title="'.htmlspecialchars(strip_tags($altText)).'"';
                }
+
+                       // "longDesc" URL
+               if ($longDesc)  {
+                       $altParam.= ' longdesc="'.htmlspecialchars($longDesc).'"';
+               }
+
                return $altParam;
        }
 
@@ -2909,10 +3101,14 @@ class tslib_cObj {
                                $content=$this->listNum($content,$listNumber,$conf['listNum.']['splitChar']);
                        }
 
-                       if ($conf['trim']){$content=trim($content);}
+                       if ($conf['trim'])      { $content=trim($content); }
+
+                               // Call stdWrap recursively
+                       if ($conf['stdWrap'])   { $content=$this->stdWrap($content,$conf['stdWrap.']); }
+
                        if (   ($conf['required'] && (string)$content=='') || ($conf['if.'] && !$this->checkIf($conf['if.'])) || ($conf['fieldRequired'] && !trim($this->data[$conf['fieldRequired']]))    ){
                                $content = '';
-                       } else {
+                       } else  {
                                        // Perform data processing:
                                if ($conf['csConv'])    { $content=$GLOBALS['TSFE']->csConv($content,$conf['csConv']); }
                                if ($conf['parseFunc.'] || $conf['parseFunc']) {$content=$this->parseFunc($content,$conf['parseFunc.'],$conf['parseFunc']);}
@@ -2922,14 +3118,21 @@ class tslib_cObj {
                                if ((string)$conf['char']!=''){$content=chr(intval($conf['char']));}
                                if ($conf['intval']){$content=intval($content);}
                                if ($conf['date']){$content=date($conf['date'], $content);}
-                               if ($conf['strftime']){$content=strftime($conf['strftime'], $content);}
+                               if ($conf['strftime']){
+                                       $content = strftime($conf['strftime'], $content);
+                                       $tmp_charset = $conf['strftime.']['charset'] ? $conf['strftime.']['charset'] : $GLOBALS['TSFE']->localeCharset;
+                                       if ($tmp_charset)       {
+                                               $content = $GLOBALS['TSFE']->csConv($content,$tmp_charset);
+                                       }
+                               }
                                if ($conf['age']){$content=$this->calcAge(time()-$content,$conf['age']);}
 
                                if ($conf['case']){$content=$this->HTMLcaseshift($content, $conf['case']);}
                                if ($conf['bytes']){$content=$this->bytes($content,$conf['bytes.']['labels']);}
                                if ($conf['substring']){$content=$this->substring($content,$conf['substring']);}
-                               if ($conf['crop']){$content=$this->crop($content, $conf['crop']);}
+                               if ($conf['removeBadHTML'])     {$content = $this->removeBadHTML($content, $conf['removeBadHTML.']);}
                                if ($conf['stripHtml']){$content = strip_tags($content);}
+                               if ($conf['crop']){$content=$this->crop($content, $conf['crop']);}
                                if ($conf['rawUrlEncode']){$content = rawurlencode($content);}
                                if ($conf['htmlSpecialChars']){
                                        $content=htmlSpecialChars($content);
@@ -2955,7 +3158,7 @@ class tslib_cObj {
 
                                if ($conf['wrapAlign'] || $conf['wrapAlign.']){
                                        $wrapAlign = trim($this->stdWrap($conf['wrapAlign'], $conf['wrapAlign.']));
-                                       if ($wrapAlign) {$content=$this->wrap($content, '<div align="'.$wrapAlign.'">|</div>');}
+                                       if ($wrapAlign) {$content=$this->wrap($content, '<div style="text-align:'.$wrapAlign.';">|</div>');}
                                }
                                if ($conf['typolink.']){$content=$this->typolink($content, $conf['typolink.']);}
 
@@ -3008,10 +3211,10 @@ class tslib_cObj {
                        if ($conf['debugFunc']) {debug($conf['debugFunc']==2?array($content):$content);}
                        if ($conf['debugData']) {
                                echo '<b>$cObj->data:</b>';
-                               debug($this->data);
+                               debug($this->data,'$cObj->data:');
                                if (is_array($this->alternativeData))   {
                                        echo '<b>$cObj->alternativeData:</b>';
-                                       debug($this->alternativeData);
+                                       debug($this->alternativeData,'$this->alternativeData');
                                }
                        }
                }
@@ -3198,7 +3401,7 @@ class tslib_cObj {
                                        while(list($key,)=each($items['sorting']))      {
                                                $list_arr[]=  $fullPath ? $path.'/'.$items['files'][$key] : $items['files'][$key];
                                        }
-                                       return implode($list_arr,',');
+                                       return implode(',',$list_arr);
                                }
                        }
                }
@@ -3265,11 +3468,11 @@ class tslib_cObj {
                do      {
                        if (!$inside)   {
                                $len = strcspn(substr($str,$pointer),'{');
-                               $newVal.=substr($str,$pointer,$len);
+                               $newVal.= substr($str,$pointer,$len);
                                $inside = 1;
                        } else {
                                $len = strcspn(substr($str,$pointer),'}')+1;
-                               $newVal.=$this->getData(substr($str,$pointer+1,$len-2),$this->data);
+                               $newVal.= $this->getData(substr($str,$pointer+1,$len-2),$this->data);
                                $inside = 0;
                        }
                        $pointer+=$len;
@@ -3314,9 +3517,9 @@ class tslib_cObj {
        function substring($content,$options)   {
                $options = t3lib_div::intExplode(',',$options.',');
                if ($options[1])        {
-                       return substr($content,$options[0],$options[1]);
+                       return $GLOBALS['TSFE']->csConvObj->substr($GLOBALS['TSFE']->renderCharset,$content,$options[0],$options[1]);
                } else {
-                       return substr($content,$options[0]);
+                       return $GLOBALS['TSFE']->csConvObj->substr($GLOBALS['TSFE']->renderCharset,$content,$options[0]);
                }
        }
 
@@ -3324,21 +3527,26 @@ class tslib_cObj {
         * Implements the stdWrap property "crop" which is a modified "substr" function allowing to limit a string lenght to a certain number of chars (from either start or end of string) and having a pre/postfix applied if the string really was cropped.
         *
         * @param       string          The string to perform the operation on
-        * @param       string          The parameters splitted by "|": First parameter is the max number of chars of the string. Negative value means cropping from end of string. Second parameter is the pre/postfix string to apply if cropping occurs.
+        * @param       string          The parameters splitted by "|": First parameter is the max number of chars of the string. Negative value means cropping from end of string. Second parameter is the pre/postfix string to apply if cropping occurs. Third parameter is a boolean value. If set then crop will be applied at nearest space.
         * @return      string          The processed input value.
         * @access private
         * @see stdWrap()
         */
        function crop($content,$options)        {
                $options = explode('|',$options);
-               $chars=intval($options[0]);
-               $afterstring=trim($options[1]);
+               $chars = intval($options[0]);
+               $afterstring = trim($options[1]);
+               $crop2space = trim($options[2]);
                if ($chars)     {
                        if (strlen($content)>abs($chars))       {
                                if ($chars<0)   {
-                                       $content= $afterstring.substr($content,$chars);
+                                       $content = $GLOBALS['TSFE']->csConvObj->substr($GLOBALS['TSFE']->renderCharset,$content,$chars);
+                                       $trunc_at = strpos($content, ' ');
+                                       $content = ($trunc_at&&$crop2space) ? $afterstring.substr($content,$trunc_at) : $afterstring.$content;
                                } else {
-                                       $content= substr($content,0,$chars).$afterstring;
+                                       $content = $GLOBALS['TSFE']->csConvObj->substr($GLOBALS['TSFE']->renderCharset,$content,0,$chars);
+                                       $trunc_at = strrpos($content, ' ');
+                                       $content = ($trunc_at&&$crop2space) ? substr($content, 0, $trunc_at).$afterstring : $content.$afterstring;
                                }
                        }
                }
@@ -3346,6 +3554,51 @@ class tslib_cObj {
        }
 
        /**
+        * Function for removing malicious HTML code when you want to provide some HTML code user-editable.
+        * The purpose is to avoid XSS attacks and the code will be continously modified to remove such code.
+        * For a complete reference with javascript-on-events, see http://www.wdvl.com/Authoring/JavaScript/Events/events_target.html
+        *
+        * @param       string          Input string to be cleaned.
+        * @param       array           TypoScript configuration.
+        * @return      string          Return string
+        * @author      Thomas Bley (all from moregroupware cvs code / readmessage.inc.php, published under gpl by Thomas)
+        * @author      Kasper Skaarhoj
+        */
+       function removeBadHTML($text, $conf)    {
+
+                       // Copyright 2002-2003 Thomas Bley
+               $text = preg_replace(
+                       array(
+                               "'<script[^>]*?>.*?</script[^>]*?>'si",
+                               "'<applet[^>]*?>.*?</applet[^>]*?>'si",
+                               "'<object[^>]*?>.*?</object[^>]*?>'si",
+                               "'<iframe[^>]*?>.*?</iframe[^>]*?>'si",
+                               "'<frameset[^>]*?>.*?</frameset[^>]*?>'si",
+                               "'<style[^>]*?>.*?</style[^>]*?>'si",
+                               "'<marquee[^>]*?>.*?</marquee[^>]*?>'si",
+                               "'<script[^>]*?>'si",
+                               "'<meta[^>]*?>'si",
+                               "'<base[^>]*?>'si",
+                               "'<applet[^>]*?>'si",
+                               "'<object[^>]*?>'si",
+                               "'<link[^>]*?>'si",
+                               "'<iframe[^>]*?>'si",
+                               "'<frame[^>]*?>'si",
+                               "'<frameset[^>]*?>'si",
+                               "'<input[^>]*?>'si",
+                               "'<form[^>]*?>'si",
+                               "'<embed[^>]*?>'si",
+                               "'background-image:url'si",
+                               "'<\w+.*?(onabort|onbeforeunload|onblur|onchange|onclick|ondblclick|ondragdrop|onerror|onfilterchange|onfocus|onhelp|onkeydown|onkeypress|onkeyup|onload|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|onmove|onreadystatechange|onreset|onresize|onscroll|onselect|onselectstart|onsubmit|onunload).*?>'si",
+                       ), '', $text);
+
+                       $text = eregi_replace('<a[^>]*href[[:space:]]*=[[:space:]]*["\']?[[:space:]]*javascript[^>]*','',$text);
+
+                       // Return clean content
+               return $text;
+       }
+
+       /**
         * Implements the stdWrap property "textStyle"; This generates a <font>-tag (and a <div>-tag for align-attributes) which is wrapped around the input value.
         *
         * @param       string          The input value
@@ -3407,7 +3660,7 @@ class tslib_cObj {
                        $theValue=$this->wrap($theValue, $fontWrap);
                }
                        // align
-               if ($align)     {$theValue=$this->wrap($theValue, '<div align="'.$align.'">|</div>');}
+               if ($align)     {$theValue=$this->wrap($theValue, '<div style="text-align:'.$align.';">|</div>');}
                        // return
                return $theValue;
        }
@@ -3448,7 +3701,7 @@ class tslib_cObj {
                        $tableTagArray[] = $conf['params'];
                }
 
-               $tableWrap = implode($tableTagArray,' ').'> | </table>';
+               $tableWrap = implode(' ',$tableTagArray).'> | </table>';
                $theValue=$this->wrap($theValue, $tableWrap);
                        // return
                return $theValue;
@@ -3488,7 +3741,7 @@ class tslib_cObj {
                        }
 
                                // Re-assembles the tag and content
-                       $subparts[0]=trim($tagName.' '.t3lib_div::implodeParams($attribs));
+                       $subparts[0]=trim($tagName.' '.t3lib_div::implodeAttributes($attribs));
                        $parts[$key] = implode('>',$subparts);
                        $content = implode('<',$parts);
                }
@@ -3531,14 +3784,16 @@ class tslib_cObj {
                                                $icon = $this->cObjGetSingle($conf['iconCObject'],$conf['iconCObject.'],'iconCObject');
                                        } else {
                                                if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails'])   {
-                                                       $icon = 't3lib/thumbs.php?&dummy='.$GLOBALS['EXEC_TIME'].'&file='.rawurlencode('../'.$theFile);
+                                                       $thumbSize = '';
+                                                       if ($conf['icon_thumbSize'] || $conf['icon_thumbSize.'])        { $thumbSize = '&size='.$this->stdWrap($conf['icon_thumbSize'], $conf['icon_thumbSize.']); }
+                                                       $icon = 't3lib/thumbs.php?&dummy='.$GLOBALS['EXEC_TIME'].'&file='.rawurlencode('../'.$theFile).$thumbSize;
                                                } else {
                                                        $icon = 't3lib/gfx/notfound_thumb.gif';
                                                }
-                                               $icon = '<img src="'.htmlspecialchars($GLOBALS['TSFE']->absRefPrefix.$icon).'" border="0" alt="" title="" />';
+                                               $icon = '<img src="'.htmlspecialchars($GLOBALS['TSFE']->absRefPrefix.$icon).'"'.$this->getBorderAttr(' border="0"').''.$this->getAltParam($conf).' />';
                                        }
                                } else {
-                                       $icon = '<img src="'.htmlspecialchars($GLOBALS['TSFE']->absRefPrefix.$icon).'" width="18" height="16" border="0" alt="" title="" />';
+                                       $icon = '<img src="'.htmlspecialchars($GLOBALS['TSFE']->absRefPrefix.$icon).'" width="18" height="16"'.$this->getBorderAttr(' border="0"').''.$this->getAltParam($conf).' />';
                                }
                                if ($conf['icon_link']) {$icon = $this->wrap($icon, $theLinkWrap);}
                                $icon = $this->stdWrap($icon,$conf['icon.']);
@@ -3587,7 +3842,7 @@ class tslib_cObj {
                        }
                }
                $locationData = $GLOBALS['TSFE']->id.':'.$this->currentRecord;
-               $rec='&locationData='.$locationData;
+               $rec='&locationData='.rawurlencode($locationData);
                $hArr = array(
                        $jumpUrl,
                        $locationData,
@@ -3750,10 +4005,14 @@ class tslib_cObj {
                                        if ($cfg['callRecursive'])      {
                                                $parts[$k]=$this->parseFunc($htmlParser->removeFirstAndLastTag($v), $conf);
                                                if (!$cfg['callRecursive.']['dontWrapSelf'])    {
-                                                       if (is_array($cfg['callRecursive.']['tagStdWrap.']))    {
-                                                               $tag = $this->stdWrap($tag,$cfg['callRecursive.']['tagStdWrap.']);
+                                                       if ($cfg['callRecursive.']['alternativeWrap'])  {
+                                                               $parts[$k] = $this->wrap($parts[$k], $cfg['callRecursive.']['alternativeWrap']);
+                                                       } else {
+                                                               if (is_array($cfg['callRecursive.']['tagStdWrap.']))    {
+                                                                       $tag = $this->stdWrap($tag,$cfg['callRecursive.']['tagStdWrap.']);
+                                                               }
+                                                               $parts[$k]=$tag.$parts[$k].'</'.$tagName.'>';
                                                        }
-                                                       $parts[$k]=$tag.$parts[$k].'</'.$tagName.'>';
                                                }
                                        } elseif($cfg['HTMLtableCells']) {
                                                $rowParts = $htmlParser->splitIntoBlock('tr',$parts[$k]);
@@ -4075,7 +4334,7 @@ class tslib_cObj {
                                        // Default align
                                if (!$attrib['align'] && $defaultAlign) $attrib['align']=$defaultAlign;
 
-                               $params = t3lib_div::implodeParams($attrib,1);
+                               $params = t3lib_div::implodeAttributes($attrib,1);
                                if ($conf['removeWrapping'])    {
                                        $str_content=$str_content;
                                } else {
@@ -4183,18 +4442,9 @@ class tslib_cObj {
                                $parts[0] = substr($textpieces[$i],0,$len);
                                $parts[1] = substr($textpieces[$i],$len);
                                $linktxt = ereg_replace('\?.*','',$parts[0]);
-                               if (!$GLOBALS['TSFE']->config['config']['jumpurl_enable'] || $GLOBALS['TSFE']->config['config']['jumpurl_mailto_disable'])      {
-                                       if ($GLOBALS['TSFE']->spamProtectEmailAddresses)        {
-                                               $mailToUrl = "javascript:linkTo_UnCryptMailto('".$GLOBALS['TSFE']->encryptEmail('mailto:'.$parts[0])."');";
-                                               $atLabel = trim($GLOBALS['TSFE']->config['config']['spamProtectEmailAddresses_atSubst']);
-                                               $linktxt = str_replace('@',$atLabel ? $atLabel : '(at)', $linktxt);
-                                       } else {
-                                               $mailToUrl = 'mailto:'.$parts[0];
-                                       }
-                                       $res = '<a href="'.htmlspecialchars($mailToUrl).'"'.$aTagParams.'>';
-                               } else {
-                                       $res = '<a href="'.htmlspecialchars($GLOBALS['TSFE']->absRefPrefix.$GLOBALS['TSFE']->config['mainScript'].$initP.'&jumpurl='.rawurlencode('mailto:'.$parts[0]).$GLOBALS['TSFE']->getMethodUrlIdToken).'"'.$aTagParams.'>';
-                               }
+                               list($mailToUrl,$linktxt) = $this->getMailTo($parts[0],$linktxt,$initP);
+                               $mailToUrl = $GLOBALS['TSFE']->spamProtectEmailAddresses === 'ascii'?$mailToUrl:htmlspecialchars($mailToUrl);
+                               $res = '<a href="'.$mailToUrl.'"'.$aTagParams.'>';
                                if ($conf['ATagBeforeWrap'])    {
                                        $res= $res.$this->wrap($linktxt, $conf['wrap']).'</a>';
                                } else {
@@ -4258,6 +4508,11 @@ class tslib_cObj {
                                                if (!isset($GLOBALS['TSFE']->tmpl->fileCache[$hash]))   {
                                                        $gifCreator = t3lib_div::makeInstance('tslib_gifbuilder');
                                                        $gifCreator->init();
+
+                                                       if ($GLOBALS['TSFE']->config['config']['meaningfulTempFilePrefix'])     {
+                                                               $gifCreator->filenamePrefix = $GLOBALS['TSFE']->fileNameASCIIPrefix(ereg_replace('\.[[:alnum:]]+$','',basename($theImage)),intval($GLOBALS['TSFE']->config['config']['meaningfulTempFilePrefix']),'_');
+                                                       }
+
                                                        if ($fileArray['sample'])       {
                                                                $gifCreator->scalecmd = '-sample';
                                                                $GLOBALS['TT']->setTSlogMessage('Sample option: Images are scaled with -sample.');
@@ -4424,7 +4679,16 @@ class tslib_cObj {
                        if ((string)$key!='')   {
                                switch(strtolower(trim($parts[0])))     {
                                        case 'gpvar':
-                                               $retVal = t3lib_div::_GP($key);
+                                               list($firstKey, $rest) = explode('|', $key, 2);
+                                               if (strlen(trim($firstKey)))    {
+                                                       $retVal = t3lib_div::_GP(trim($firstKey));
+                                                               // Look for deeper levels:
+                                                       if (strlen(trim($rest)))        {
+                                                               $retVal = is_array($retVal) ? $this->getGlobal($rest, $retVal) : '';
+                                                       }
+                                                               // Check that output is not an array:
+                                                       if (is_array($retVal))  $retVal = '';
+                                               }
                                        break;
                                        case 'tsfe':
                                                $retVal = $GLOBALS['TSFE']->$key;
@@ -4492,6 +4756,9 @@ class tslib_cObj {
                                        case 'lll':
                                                $retVal = $GLOBALS['TSFE']->sL('LLL:'.$key);
                                        break;
+                                       case 'path':
+                                               $retVal = $GLOBALS['TSFE']->tmpl->getFileName($key);
+                                       break;
                                        case 'cobj':
                                                switch((string)$key)    {
                                                        case 'parentRecordNumber':
@@ -4546,14 +4813,15 @@ class tslib_cObj {
         * Example: $var = "HTTP_SERVER_VARS | something" will return the value $GLOBALS['HTTP_SERVER_VARS']['something'] value
         *
         * @param       string          Key, see description of functon
+        * @param       array           If you want another array than $GLOBALS used, then just put it in here!
         * @return      mixed           Value from $GLOBALS
         * @access private
         * @see getData()
         */
-       function getGlobal($var) {
-               $vars = explode('|',$var);
+       function getGlobal($var, $source=NULL) {
+               $vars = explode('|', $var);
                $c = count($vars);
-               $theVar = $GLOBALS[trim($vars[0])];
+               $theVar = isset($source) ? $source[trim($vars[0])] : $GLOBALS[trim($vars[0])];
                for ($a=1;$a<$c;$a++) {
                        if (!isset($theVar))    {break;}
                        $theVar = $theVar[trim($vars[$a])];
@@ -4673,17 +4941,7 @@ class tslib_cObj {
                                // Detecting kind of link:
                        if(strstr($link_param,'@') && !$pU['scheme'])   {               // If it's a mail address:
                                $link_param = eregi_replace('^mailto:','',$link_param);
-                               if ($linktxt=='') $linktxt = $link_param;
-                               if (!$GLOBALS['TSFE']->config['config']['jumpurl_enable'] || $GLOBALS['TSFE']->config['config']['jumpurl_mailto_disable'])      {
-                                       $this->lastTypoLinkUrl = 'mailto:'.$link_param;
-                                       if ($GLOBALS['TSFE']->spamProtectEmailAddresses)        {
-                                               $this->lastTypoLinkUrl = "javascript:linkTo_UnCryptMailto('".$GLOBALS['TSFE']->encryptEmail($this->lastTypoLinkUrl)."');";
-                                               $atLabel = trim($GLOBALS['TSFE']->config['config']['spamProtectEmailAddresses_atSubst']);
-                                               $linktxt=str_replace('@',$atLabel?$atLabel:'(at)',$linktxt);
-                                       }
-                               } else {
-                                       $this->lastTypoLinkUrl = $GLOBALS['TSFE']->absRefPrefix.$GLOBALS['TSFE']->config['mainScript'].$initP.'&jumpurl='.rawurlencode('mailto:'.$link_param).$GLOBALS['TSFE']->getMethodUrlIdToken;
-                               }
+                               list($this->lastTypoLinkUrl,$linktxt) = $this->getMailTo($link_param,$linktxt,$initP);
                                $finalTagParts['url']=$this->lastTypoLinkUrl;
                                $finalTagParts['TYPE']='mailto';
                        } else {
@@ -4693,12 +4951,15 @@ class tslib_cObj {
 
                                        // Detects if a file is found in site-root (or is a 'virtual' simulateStaticDocument file!) and if so it will be treated like a normal file.
                                list($rootFileDat) = explode('?',rawurldecode($link_param));
+                               $containsSlash = strstr($rootFileDat,'/');
                                $rFD_fI = pathinfo($rootFileDat);
-                               if (trim($rootFileDat) && !strstr($link_param,'/') && (@is_file(PATH_site.$rootFileDat) || t3lib_div::inList('php,html,htm',strtolower($rFD_fI['extension'])))) {
-                                       $isLocalFile=1;
+                               if (trim($rootFileDat) && !$containsSlash && (@is_file(PATH_site.$rootFileDat) || t3lib_div::inList('php,html,htm',strtolower($rFD_fI['extension']))))  {
+                                       $isLocalFile = 1;
+                               } elseif ($containsSlash)       {
+                                       $isLocalFile = 2;               // Adding this so realurl directories are linked right (non-existing).
                                }
 
-                               if($pU['scheme'] || (!$isLocalFile && $urlChar && (!$fileChar || $urlChar<$fileChar)))  {       // url (external): If doubleSlash or if a '.' comes before a '/'.
+                               if($pU['scheme'] || ($isLocalFile!=1 && $urlChar && (!$containsSlash || $urlChar<$fileChar)))   {       // url (external): If doubleSlash or if a '.' comes before a '/'.
                                        $target = isset($conf['extTarget']) ? $conf['extTarget'] : $GLOBALS['TSFE']->extTarget;
                                        if ($conf['extTarget.'])        {$target = $this->stdWrap($target, $conf['extTarget.']);}
                                        if ($forceTarget)       {$target=$forceTarget;}
@@ -4713,7 +4974,7 @@ class tslib_cObj {
                                        $finalTagParts['url']=$this->lastTypoLinkUrl;
                                        $finalTagParts['targetParams'] = $target ? ' target="'.$target.'"' : '';
                                        $finalTagParts['TYPE']='url';
-                               } elseif ($fileChar || $isLocalFile)    {       // file (internal)
+                               } elseif ($containsSlash || $isLocalFile)       {       // file (internal)
                                        $splitLinkParam = explode('?', $link_param);
                                        if (@file_exists(rawurldecode($splitLinkParam[0])) || $isLocalFile)     {
                                                if ($linktxt=='') $linktxt = rawurldecode($link_param);
@@ -4732,7 +4993,7 @@ class tslib_cObj {
                                                $GLOBALS['TT']->setTSlogMessage("typolink(): File '".$splitLinkParam[0]."' did not exist, so '".$linktxt."' was not linked.",1);
                                                return $linktxt;
                                        }
-                               } else {        // integer or alias (alias is without slashes or periods or commas, that is 'nospace,alphanum_x,lower,unique' according to tables.php!!)
+                               } else {        // integer or alias (alias is without slashes or periods or commas, that is 'nospace,alphanum_x,lower,unique' according to definition in $TCA!)
                                        if ($conf['no_cache.']) $conf['no_cache']=$this->stdWrap($conf['no_cache'], $conf['no_cache.']);
                                        $link_params_parts=explode('#',$link_param);
                                        $link_param = trim($link_params_parts[0]);              // Link-data del
@@ -4753,7 +5014,9 @@ class tslib_cObj {
                                        }
 
                                                // Looking up the page record to verify its existence:
-                                       $page = $GLOBALS['TSFE']->sys_page->getPage($link_param);
+                                       $disableGroupAccessCheck = $GLOBALS['TSFE']->config['config']['typolinkLinkAccessRestrictedPages'] ? TRUE : FALSE;
+                                       $page = $GLOBALS['TSFE']->sys_page->getPage($link_param,$disableGroupAccessCheck);
+
                                        if (count($page))       {
                                                        // This checks if the linked id is in the rootline of this site and if not it will find the domain for that ID and prefix it:
                                                $tCR_domain='';
@@ -4768,7 +5031,7 @@ class tslib_cObj {
                                                        }
                                                        if (!$tCR_flag) {
                                                                foreach($tCR_rootline as $tCR_data)     {
-                                                                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_domain', 'pid='.intval($tCR_data['uid']).' AND redirectTo=""'.$this->enableFields('sys_domain'), '', 'sorting');
+                                                                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_domain', 'pid='.intval($tCR_data['uid']).' AND redirectTo=\'\''.$this->enableFields('sys_domain'), '', 'sorting');
                                                                        if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                                                                                $tCR_domain = ereg_replace('\/$','',$row['domainName']);
                                                                                break;
@@ -4785,7 +5048,7 @@ class tslib_cObj {
                                                        // Look for overlay Mount Point:
                                                $mount_info = $GLOBALS['TSFE']->sys_page->getMountPointInfo($page['uid'], $page);
                                                if (is_array($mount_info) && $mount_info['overlay'])    {
-                                                       $page = $GLOBALS['TSFE']->sys_page->getPage($mount_info['mount_pid']);
+                                                       $page = $GLOBALS['TSFE']->sys_page->getPage($mount_info['mount_pid'],$disableGroupAccessCheck);
                                                        if (!count($page))      {
                                                                $GLOBALS['TT']->setTSlogMessage("typolink(): Mount point '".$mount_info['mount_pid']."' was not available, so '".$linktxt."' was not linked.",1);
                                                                return $linktxt;
@@ -4797,11 +5060,12 @@ class tslib_cObj {
                                                if ($linktxt=='') $linktxt = $page['title'];
 
                                                        // Query Params:
-                                               $addQueryParams = trim($this->stdWrap($conf['additionalParams'],$conf['additionalParams.']));
+                                               $addQueryParams = $conf['addQueryString'] ? '&'.t3lib_div::getIndpEnv('QUERY_STRING') : '';
+                                               $addQueryParams .= trim($this->stdWrap($conf['additionalParams'],$conf['additionalParams.']));
                                                if (substr($addQueryParams,0,1)!='&')           {
                                                        $addQueryParams = '';
                                                } elseif ($conf['useCacheHash']) {      // cache hashing:
-                                                       $pA = $GLOBALS['TSFE']->cHashParams($addQueryParams.$GLOBALS['TSFE']->linkVars);        // Added '.$this->linkVars' dec 2003: The need for adding the linkVars is that they will be included in the link, but not the cHash. Thus the linkVars will always be the problem that prevents the cHash from working. I cannot see what negative implications in terms of incompatibilities this could bring, but for now I hope there are none. So here we go... (- kasper)
+                                                       $pA = t3lib_div::cHashParams($addQueryParams.$GLOBALS['TSFE']->linkVars);       // Added '.$this->linkVars' dec 2003: The need for adding the linkVars is that they will be included in the link, but not the cHash. Thus the linkVars will always be the problem that prevents the cHash from working. I cannot see what negative implications in terms of incompatibilities this could bring, but for now I hope there are none. So here we go... (- kasper)
                                                        $addQueryParams.= '&cHash='.t3lib_div::shortMD5(serialize($pA));
                                                }
                                                        // Add "&MP" var:
@@ -4837,6 +5101,20 @@ class tslib_cObj {
                                                                }
                                                        }
                                                }
+
+                                                       // If link is to a access restricted page which should be redirected, then find new URL:
+                                               if ($GLOBALS['TSFE']->config['config']['typolinkLinkAccessRestrictedPages'] &&
+                                                               $GLOBALS['TSFE']->config['config']['typolinkLinkAccessRestrictedPages']!=='NONE' &&
+                                                               !$GLOBALS['TSFE']->checkPageGroupAccess($page)) {
+                                                                       $thePage = $GLOBALS['TSFE']->sys_page->getPage($GLOBALS['TSFE']->config['config']['typolinkLinkAccessRestrictedPages']);
+
+                                                                       $addParams = $GLOBALS['TSFE']->config['config']['typolinkLinkAccessRestrictedPages_addParams'];
+                                                                       $addParams = str_replace('###RETURN_URL###',rawurlencode($this->lastTypoLinkUrl),$addParams);
+                                                                       $addParams = str_replace('###PAGE_ID###',$page['uid'],$addParams);
+                                                                       $LD = $GLOBALS['TSFE']->tmpl->linkData($thePage,$target,'','','',$addParams,$theTypeP);
+                                                                       $this->lastTypoLinkUrl = $this->URLqMark($LD['totalURL'],'');
+                                               }
+
                                                        // Rendering the tag.
                                                $finalTagParts['url']=$this->lastTypoLinkUrl;
                                                $finalTagParts['targetParams']=$targetPart;
@@ -4849,10 +5127,14 @@ class tslib_cObj {
                        }
 
                        if ($JSwindowParams)    {
-                               $onClick="vHWin=window.open('".$finalTagParts['url']."','FEopenLink','".$JSwindowParams."');vHWin.focus();return false;";
+                               $onClick="vHWin=window.open('".$GLOBALS['TSFE']->baseUrlWrap($finalTagParts['url'])."','FEopenLink','".$JSwindowParams."');vHWin.focus();return false;";
                                $res = '<a href="#" onclick="'.htmlspecialchars($onClick).'"'.($linkClass?' class="'.$linkClass.'"':'').$finalTagParts['aTagParams'].'>';
                        } else {
-                               $res = '<a href="'.htmlspecialchars($finalTagParts['url']).'"'.$finalTagParts['targetParams'].($linkClass?' class="'.$linkClass.'"':'').$finalTagParts['aTagParams'].'>';
+                               if ($GLOBALS['TSFE']->spamProtectEmailAddresses === 'ascii' && $finalTagParts['TYPE'] === 'mailto') {
+                                       $res = '<a href="'.$finalTagParts['url'].'"'.$finalTagParts['targetParams'].($linkClass?' class="'.$linkClass.'"':'').$finalTagParts['aTagParams'].'>';
+                               } else {
+                                       $res = '<a href="'.htmlspecialchars($finalTagParts['url']).'"'.$finalTagParts['targetParams'].($linkClass?' class="'.$linkClass.'"':'').$finalTagParts['aTagParams'].'>';
+                               }
                        }
 
                                // Call user function:
@@ -4903,7 +5185,7 @@ class tslib_cObj {
         * Optionally you can supply $urlParameters which is an array with key/value pairs that are rawurlencoded and appended to the resulting url.
         *
         * @param       string          Text string being wrapped by the link.
-        * @param       string          Link parameter; eg. "123" for page id, "kasper@typo3.com" for email address, "http://...." for URL, "fileadmin/blabla.txt" for file.
+        * @param       string          Link parameter; eg. "123" for page id, "kasperYYYY@typo3.com" for email address, "http://...." for URL, "fileadmin/blabla.txt" for file.
         * @param       array           An array with key/value pairs representing URL parameters to set. Values NOT URL-encoded yet.
         * @param       string          Specific target set, if any. (Default is using the current)
         * @return      string          The wrapped $label-text string
@@ -4918,10 +5200,7 @@ class tslib_cObj {
                }
                if (is_array($urlParameters))   {
                        if (count($urlParameters))      {
-                               reset($urlParameters);
-                               while(list($k,$v)=each($urlParameters)) {
-                                       $conf['additionalParams'].='&'.$k.'='.rawurlencode($v);
-                               }
+                               $conf['additionalParams'].= t3lib_div::implodeArrayForUrl('',$urlParameters);
                        }
                } else {
                        $conf['additionalParams'].=$urlParameters;
@@ -4933,7 +5212,7 @@ class tslib_cObj {
        /**
         * Returns the URL of a "typolink" create from the input parameter string, url-parameters and target
         *
-        * @param       string          Link parameter; eg. "123" for page id, "kasper@typo3.com" for email address, "http://...." for URL, "fileadmin/blabla.txt" for file.
+        * @param       string          Link parameter; eg. "123" for page id, "kasperYYYY@typo3.com" for email address, "http://...." for URL, "fileadmin/blabla.txt" for file.
         * @param       array           An array with key/value pairs representing URL parameters to set. Values NOT URL-encoded yet.
         * @param       string          Specific target set, if any. (Default is using the current)
         * @return      string          The URL
@@ -5017,7 +5296,43 @@ class tslib_cObj {
                return !$raw  ? ($MP ? '&MP='.rawurlencode($MP) : '') : $MP;
        }
 
+       /**
+        * Creates a href attibute for given $mailAddress.
+        * The function uses spamProtectEmailAddresses and Jumpurl functionality for encoding the mailto statement.
+        * If spamProtectEmailAddresses is disabled, it'll just return a string like "mailto:user@example.tld".
+        *
+        * @param       string          Email address
+        * @param       string          $initP: Initial link parameters, only used if Jumpurl functionality is enabled. Example: ?id=5&type=0
+        * @return      string          Returns a numerical array with two elements: 1) $mailToUrl, string ready to be inserted into the href attribute of the <a> tag, b) $linktxt: The string between starting and ending <a> tag.
+        */
+       function getMailTo($mailAddress,$linktxt,$initP='?') {
+               if(!strcmp($linktxt,''))        { $linktxt = $mailAddress; }
+
+               $mailToUrl = 'mailto:'.$mailAddress;
+
+               if (!$GLOBALS['TSFE']->config['config']['jumpurl_enable'] || $GLOBALS['TSFE']->config['config']['jumpurl_mailto_disable']) {
+                       if ($GLOBALS['TSFE']->spamProtectEmailAddresses) {
+                               if ($GLOBALS['TSFE']->spamProtectEmailAddresses === 'ascii')    {
+                                       $mailToUrl = $GLOBALS['TSFE']->encryptEmail($mailToUrl);
+                               } else {
+                                       $mailToUrl = "javascript:linkTo_UnCryptMailto('".$GLOBALS['TSFE']->encryptEmail($mailToUrl)."');";
+                               }
+                               if ($GLOBALS['TSFE']->config['config']['spamProtectEmailAddresses_atSubst']) {
+                                       $atLabel = trim($GLOBALS['TSFE']->config['config']['spamProtectEmailAddresses_atSubst']);
+                               }
+                               $linktxt = str_replace('@',$atLabel?$atLabel:'(at)',$linktxt);
 
+                               if ($GLOBALS['TSFE']->config['config']['spamProtectEmailAddresses_lastDotSubst']) {
+                                       $lastDotLabel = trim($GLOBALS['TSFE']->config['config']['spamProtectEmailAddresses_lastDotSubst']);
+                                       $lastDotLabel = $lastDotLabel ? $lastDotLabel : '(dot)';
+                                       $linktxt = preg_replace('/\.([^\.]+)$/', $lastDotLabel.'$1', $linktxt);
+                               }
+                       }
+               } else {
+                       $mailToUrl = $GLOBALS['TSFE']->absRefPrefix.$GLOBALS['TSFE']->config['mainScript'].$initP.'&jumpurl='.rawurlencode($mailToUrl).$GLOBALS['TSFE']->getMethodUrlIdToken;
+               }
+               return array($mailToUrl,$linktxt);
+       }
 
 
 
@@ -5090,10 +5405,10 @@ class tslib_cObj {
                        $wrapBefore = intval($wrapArray[0]);
                        $wrapAfter = intval($wrapArray[1]);
                        if ($wrapBefore)        {
-                               $result = '<img src="'.$GLOBALS['TSFE']->absRefPrefix.'clear.gif" width="1" height="'.$wrapBefore.'" border="0" class="spacer-gif" alt="" title="" /><br />'.$result;
+                               $result = '<img src="'.$GLOBALS['TSFE']->absRefPrefix.'clear.gif" width="1" height="'.$wrapBefore.'"'.$this->getBorderAttr(' border="0"').' class="spacer-gif" alt="" title="" /><br />'.$result;
                        }
                        if ($wrapAfter) {
-                               $result.='<img src="'.$GLOBALS['TSFE']->absRefPrefix.'clear.gif" width="1" height="'.$wrapAfter.'" border="0" class="spacer-gif" alt="" title="" /><br />';
+                               $result.='<img src="'.$GLOBALS['TSFE']->absRefPrefix.'clear.gif" width="1" height="'.$wrapAfter.'"'.$this->getBorderAttr(' border="0"').' class="spacer-gif" alt="" title="" /><br />';
                        }
                }
                return $result;
@@ -5174,7 +5489,7 @@ class tslib_cObj {
                while(list($k,$v)=each($listArr))       {
                        $listArr[$k]=trim($v);
                }
-               return implode($listArr,',');
+               return implode(',',$listArr);
        }
 
        /**
@@ -5189,12 +5504,14 @@ class tslib_cObj {
                $case = strtolower($case);
                switch($case)   {
                        case 'upper':
-                               $theValue = strtoupper($theValue);
-                               $theValue = strtr($theValue, $this->caseConvStrings[0], $this->caseConvStrings[1]);
+                               $theValue = $GLOBALS['TSFE']->csConvObj->conv_case($GLOBALS['TSFE']->renderCharset,$theValue,'toUpper');
+                               #$theValue = strtoupper($theValue);
+                               #$theValue = strtr($theValue, $this->caseConvStrings[0], $this->caseConvStrings[1]);
                        break;
                        case 'lower':
-                               $theValue = strtolower($theValue);
-                               $theValue = strtr($theValue, $this->caseConvStrings[1], $this->caseConvStrings[0]);
+                               $theValue = $GLOBALS['TSFE']->csConvObj->conv_case($GLOBALS['TSFE']->renderCharset,$theValue,'toLower');
+                               #$theValue = strtolower($theValue);
+                               #$theValue = strtr($theValue, $this->caseConvStrings[1], $this->caseConvStrings[0]);
                        break;
                }
                return $theValue;
@@ -5209,18 +5526,18 @@ class tslib_cObj {
         * @see caseshift()
         */
        function HTMLcaseshift($theValue, $case)        {
-               $inside=0;
-               $newVal='';
-               $pointer=0;
+               $inside = 0;
+               $newVal = '';
+               $pointer = 0;
                $totalLen = strlen($theValue);
                do      {
                        if (!$inside)   {
                                $len = strcspn(substr($theValue,$pointer),'<');
-                               $newVal.=$this->caseshift(substr($theValue,$pointer,$len),$case);
+                               $newVal.= $this->caseshift(substr($theValue,$pointer,$len),$case);
                                $inside = 1;
                        } else {
                                $len = strcspn(substr($theValue,$pointer),'>')+1;
-                               $newVal.=substr($theValue,$pointer,$len);
+                               $newVal.= substr($theValue,$pointer,$len);
                                $inside = 0;
                        }
                        $pointer+=$len;
@@ -5285,7 +5602,7 @@ class tslib_cObj {
                if ($email_from)        {$headers[]='From: '.$email_fromName.' <'.$email_from.'>';}
                if ($replyTo)           {$headers[]='Reply-To: '.$replyTo;}
 
-               $recipients=implode(t3lib_div::trimExplode(',',$recipients,1),',');
+               $recipients=implode(',',t3lib_div::trimExplode(',',$recipients,1));
 
                $emailContent = trim($msg);
                if ($emailContent)      {
@@ -5293,8 +5610,8 @@ class tslib_cObj {
                        $subject=trim($parts[0]);
                        $plain_message=trim($parts[1]);
 
-                       if ($recipients)        $GLOBALS['TSFE']->plainMailEncoded($recipients, $subject, $plain_message, implode($headers,chr(10)));
-                       if ($cc)        $GLOBALS['TSFE']->plainMailEncoded($cc, $subject, $plain_message, implode($headers,chr(10)));
+                       if ($recipients)        $GLOBALS['TSFE']->plainMailEncoded($recipients, $subject, $plain_message, implode(chr(10),$headers));
+                       if ($cc)        $GLOBALS['TSFE']->plainMailEncoded($cc, $subject, $plain_message, implode(chr(10),$headers));
                        return true;
                }
        }
@@ -5592,7 +5909,7 @@ class tslib_cObj {
                $uid=intval($uid);
 
                if ($uid)       {
-                       $fieldList = implode(t3lib_div::trimExplode(',',$fieldList,1),',');
+                       $fieldList = implode(',',t3lib_div::trimExplode(',',$fieldList,1));
                        $updateFields=array();
 
                        foreach($dataArr as $f => $v)   {
@@ -5639,7 +5956,7 @@ class tslib_cObj {
 
                unset($dataArr['uid']); // uid can never be set
                if ($pid>=0)    { $dataArr['pid'] = $pid; }             // Set pid < 0 and the dataarr-pid will be used!
-               $fieldList = implode(t3lib_div::trimExplode(',',$fieldList.','.$extraList,1),',');
+               $fieldList = implode(',',t3lib_div::trimExplode(',',$fieldList.','.$extraList,1));
 
                $insertFields = array();
                foreach($dataArr as $f => $v)   {
@@ -5667,7 +5984,7 @@ class tslib_cObj {
         * @see user_feAdmin
         */
        function DBmayFEUserEdit($table,$row, $feUserRow, $allowedGroups='',$feEditSelf=0)      {
-               $groupList = $allowedGroups ? implode(array_intersect(t3lib_div::trimExplode(',',$feUserRow['usergroup'],1),t3lib_div::trimExplode(',',$allowedGroups,1)),',') : $feUserRow['usergroup'];
+               $groupList = $allowedGroups ? implode(',',array_intersect(t3lib_div::trimExplode(',',$feUserRow['usergroup'],1),t3lib_div::trimExplode(',',$allowedGroups,1))) : $feUserRow['usergroup'];
                $ok=0;
                        // points to the field that allows further editing from frontend if not set. If set the record is locked.
                if (!$GLOBALS['TCA'][$table]['ctrl']['fe_admin_lock'] || !$row[$GLOBALS['TCA'][$table]['ctrl']['fe_admin_lock']])       {
@@ -5708,7 +6025,7 @@ class tslib_cObj {
         */
        function DBmayFEUserEditSelect($table,$feUserRow,$allowedGroups='',$feEditSelf=0)       {
                        // Returns where-definition that selects user-editable records.
-               $groupList = $allowedGroups ? implode(array_intersect(t3lib_div::trimExplode(',',$feUserRow['usergroup'],1),t3lib_div::trimExplode(',',$allowedGroups,1)),',') : $feUserRow['usergroup'];
+               $groupList = $allowedGroups ? implode(',',array_intersect(t3lib_div::trimExplode(',',$feUserRow['usergroup'],1),t3lib_div::trimExplode(',',$allowedGroups,1))) : $feUserRow['usergroup'];
                $OR_arr=array();
                        // points to the field (integer) that holds the fe_users-id of the creator fe_user
                if ($GLOBALS['TCA'][$table]['ctrl']['fe_cruser_id'])    {
@@ -5728,9 +6045,9 @@ class tslib_cObj {
 
                $whereDef=' AND 1=0';
                if (count($OR_arr))     {
-                       $whereDef=' AND ('.implode($OR_arr,' OR ').')';
+                       $whereDef=' AND ('.implode(' OR ',$OR_arr).')';
                        if ($GLOBALS['TCA'][$table]['ctrl']['fe_admin_lock'])   {
-                               $whereDef.=' AND NOT '.$GLOBALS['TCA'][$table]['ctrl']['fe_admin_lock'];
+                               $whereDef.=' AND '.$GLOBALS['TCA'][$table]['ctrl']['fe_admin_lock'].'=0';
                        }
                }
                return $whereDef;
@@ -5743,7 +6060,7 @@ class tslib_cObj {
         *
         * @param       string          The table for which to get the where clause
         * @param       boolean         If set, then you want NOT to filter out hidden records. Otherwise hidden record are filtered based on the current preview settings.
-        * @return      string          The part of the where clause on the form " AND NOT [fieldname] AND ...". Eg. " AND NOT hidden AND starttime < 123345567"
+        * @return      string          The part of the where clause on the form " AND [fieldname]=0 AND ...". Eg. " AND hidden=0 AND starttime < 123345567"
         * @see t3lib_pageSelect::enableFields()
         */
        function enableFields($table,$show_hidden=0)    {
@@ -5773,7 +6090,7 @@ class tslib_cObj {
        function getTreeList($id,$depth,$begin=0,$dontCheckEnableFields=FALSE,$addSelectFields='',$moreWhereClauses='', $prevId_array=array(), $recursionLevel=0)       {
 
                        // Init vars:
-               $allFields = 'uid,hidden,starttime,endtime,fe_group,extendToSubpages,doktype,php_tree_stop,mount_pid,mount_pid_ol'.$addSelectFields;
+               $allFields = 'uid,hidden,starttime,endtime,fe_group,extendToSubpages,doktype,php_tree_stop,mount_pid,mount_pid_ol,t3ver_state'.$addSelectFields;
                $depth = intval($depth);
                $begin = intval($begin);
                $id = intval($id);
@@ -5810,34 +6127,43 @@ class tslib_cObj {
 
                                // Select sublevel:
                        if ($depth>0)   {
-                               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($allFields, 'pages', 'pid='.intval($id).' AND NOT deleted AND doktype!=255 AND doktype!=6'.$moreWhereClauses, '' ,'sorting');
+                               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($allFields, 'pages', 'pid='.intval($id).' AND deleted=0'.$moreWhereClauses, '' ,'sorting');
                                while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))      {
-                                               // Find mount point if any:
-                                       $next_id = $row['uid'];
-                                       $mount_info = $GLOBALS['TSFE']->sys_page->getMountPointInfo($next_id, $row);
-                                               // Overlay mode:
-                                       if (is_array($mount_info) && $mount_info['overlay'])    {
-                                               $next_id = $mount_info['mount_pid'];
-                                               $res2 = $GLOBALS['TYPO3_DB']->exec_SELECTquery($allFields, 'pages', 'uid='.intval($next_id).' AND NOT deleted AND doktype!=255 AND doktype!=6'.$moreWhereClauses, '' ,'sorting');
-                                               $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res2);
-                                       }
-                                               // Add record:
-                                       if (is_array($row) && $dontCheckEnableFields || $GLOBALS['TSFE']->checkPagerecordForIncludeSection($row))       {
-                                                       // Add ID to list:
-                                               if ($begin<=0)  {
-                                                       if ($dontCheckEnableFields || $GLOBALS['TSFE']->checkEnableFields($row))        {
-                                                               $theList.= $next_id.',';
-                                                       }
+                                       $GLOBALS['TSFE']->sys_page->versionOL('pages',$row);
+
+                                       if ($row['doktype']==255 || $row['doktype']==6 || $row['t3ver_state']==1)       { unset($row); }        // Doing this after the overlay to make sure changes in the overlay are respected.
+
+                                       if (is_array($row))     {
+                                                       // Find mount point if any:
+                                               $next_id = $row['uid'];
+                                               $mount_info = $GLOBALS['TSFE']->sys_page->getMountPointInfo($next_id, $row);
+                                                       // Overlay mode:
+                                               if (is_array($mount_info) && $mount_info['overlay'])    {
+                                                       $next_id = $mount_info['mount_pid'];
+                                                       $res2 = $GLOBALS['TYPO3_DB']->exec_SELECTquery($allFields, 'pages', 'uid='.intval($next_id).' AND deleted=0'.$moreWhereClauses, '' ,'sorting');
+                                                       $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res2);
+                                                       $GLOBALS['TSFE']->sys_page->versionOL('pages',$row);
+
+                                                       if ($row['doktype']==255 || $row['doktype']==6 || $row['t3ver_state']==1)       { unset($row); }        // Doing this after the overlay to make sure changes in the overlay are respected.
                                                }
-                                                       // Next level:
-                                               if ($depth>1 && !$row['php_tree_stop']) {
-                                                               // Normal mode:
-                                                       if (is_array($mount_info) && !$mount_info['overlay'])   {
-                                                               $next_id = $mount_info['mount_pid'];
+                                                       // Add record:
+                                               if (is_array($row) && ($dontCheckEnableFields || $GLOBALS['TSFE']->checkPagerecordForIncludeSection($row)))     {
+                                                               // Add ID to list:
+                                                       if ($begin<=0)  {
+                                                               if ($dontCheckEnableFields || $GLOBALS['TSFE']->checkEnableFields($row))        {
+                                                                       $theList.= $next_id.',';
+                                                               }
                                                        }
-                                                               // Call recursively, if the id is not in prevID_array:
-                                                       if (!in_array($next_id,$prevId_array))  {
-                                                               $theList.= tslib_cObj::getTreeList($next_id, $depth-1, $begin-1, $dontCheckEnableFields, $addSelectFields, $moreWhereClauses, $prevId_array, $recursionLevel+1);
+                                                               // Next level:
+                                                       if ($depth>1 && !$row['php_tree_stop']) {
+                                                                       // Normal mode:
+                                                               if (is_array($mount_info) && !$mount_info['overlay'])   {
+                                                                       $next_id = $mount_info['mount_pid'];
+                                                               }
+                                                                       // Call recursively, if the id is not in prevID_array:
+                                                               if (!in_array($next_id,$prevId_array))  {
+                                                                       $theList.= tslib_cObj::getTreeList($next_id, $depth-1, $begin-1, $dontCheckEnableFields, $addSelectFields, $moreWhereClauses, $prevId_array, $recursionLevel+1);
+                                                               }
                                                        }
                                                }
                                        }
@@ -5872,7 +6198,7 @@ class tslib_cObj {
        }
 
        /**
-        * Executes a SELECT query for joining three tables according the the MM-relation standards used for tables configured in $TCA. That means MM-joins where the join table has the fields "uid_local" and "uid_foreign"
+        * Executes a SELECT query for joining three tables according to the MM-relation standards used for tables configured in $TCA. That means MM-joins where the join table has the fields "uid_local" and "uid_foreign"
         *
         * @param       string          List of fields to select
         * @param       string          The local table
@@ -5898,7 +6224,7 @@ class tslib_cObj {
        }
 
        /**
-        * Executes a SELECT query for joining two tables according the the MM-relation standards used for tables configured in $TCA. That means MM-joins where the join table has the fields "uid_local" and "uid_foreign"
+        * Executes a SELECT query for joining two tables according to the MM-relation standards used for tables configured in $TCA. That means MM-joins where the join table has the fields "uid_local" and "uid_foreign"
         * The two tables joined is the join table ($mm_table) and the foreign table ($foreign_table) - so the "local table" is not included but instead you can supply a list of UID integers from the local table to match in the join-table.
         *
         * @param       string          List of fields to select
@@ -5946,11 +6272,11 @@ class tslib_cObj {
                                if (strlen($val)>=2)    {
                                        reset($searchFields);
                                        while(list(,$field)=each($searchFields))        {
-                                               $where_p[]=$prefixTableName.$field.' LIKE "%'.$GLOBALS['TYPO3_DB']->quoteStr($val, $searchTable).'%"';
+                                               $where_p[] = $prefixTableName.$field.' LIKE \'%'.$GLOBALS['TYPO3_DB']->quoteStr($val, $searchTable).'%\'';
                                        }
                                }
                                if (count($where_p))    {
-                                       $where.=' AND ('.implode($where_p,' OR ').')';
+                                       $where.=' AND ('.implode(' OR ',$where_p).')';
                                }
                        }
                }
@@ -6064,6 +6390,7 @@ class tslib_cObj {
         * @see getQuery()
         */
        function getWhere($table,$conf, $returnQueryArray=FALSE)        {
+               global $TCA;
 
                        // Init:
                $query = '';
@@ -6091,7 +6418,7 @@ class tslib_cObj {
                                // removes all pages which are not visible for the user!
                        $listArr = $this->checkPidArray($listArr);
                        if (count($listArr))    {
-                           $query.=' AND '.$table.'.pid IN ('.implode(',',$GLOBALS['TYPO3_DB']->cleanIntArray($listArr)).')';
+                               $query.=' AND '.$table.'.pid IN ('.implode(',',$GLOBALS['TYPO3_DB']->cleanIntArray($listArr)).')';
                                $pid_uid_flag++;
                        } else {
                                $pid_uid_flag=0;                // If not uid and not pid then uid is set to 0 - which results in nothing!!
@@ -6103,8 +6430,15 @@ class tslib_cObj {
                if ($where = trim($conf['where']))      {
                        $query.=' AND '.$where;
                }
+
                if ($conf['languageField'])     {
-                       $query.=' AND '.$conf['languageField'].'='.intval($GLOBALS['TSFE']->sys_language_uid);
+                       if ($GLOBALS['TSFE']->sys_language_contentOL && $TCA[$table] && $TCA[$table]['ctrl']['languageField'] && $TCA[$table]['ctrl']['transOrigPointerField']) {
+                                       // Sys language content is set to zero/-1 - and it is expected that whatever routine processes the output will OVERLAY the records with localized versions!
+                               $sys_language_content = '0,-1';
+                       } else {
+                               $sys_language_content = intval($GLOBALS['TSFE']->sys_language_content);
+                       }
+                       $query.=' AND '.$conf['languageField'].' IN ('.$sys_language_content.')';
                }
 
                $andWhere = trim($this->stdWrap($conf['andWhere'],$conf['andWhere.']));
@@ -6114,7 +6448,8 @@ class tslib_cObj {
 
                        // enablefields
                if ($table=='pages')    {
-                       $query.=' '.$GLOBALS['TSFE']->sys_page->where_hid_del;
+                       $query.=' '.$GLOBALS['TSFE']->sys_page->where_hid_del.
+                                               $GLOBALS['TSFE']->sys_page->where_groupAccess;
                } else {
                        $query.=$this->enableFields($table);
                }
@@ -6152,7 +6487,7 @@ class tslib_cObj {
        function checkPidArray($listArr)        {
                $outArr = Array();
                if (is_array($listArr) && count($listArr))      {
-                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'pages', 'uid IN ('.implode($listArr,',').')'.$this->enableFields('pages').' AND doktype NOT IN ('.$this->checkPid_badDoktypeList.')');
+                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'pages', 'uid IN ('.implode(',',$listArr).')'.$this->enableFields('pages').' AND doktype NOT IN ('.$this->checkPid_badDoktypeList.')');
                        if ($error = $GLOBALS['TYPO3_DB']->sql_error()) {
                                $GLOBALS['TT']->setTSlogMessage($error.': '.$query,3);
                        } else {
@@ -6298,6 +6633,7 @@ class tslib_cObj {
                                        $tceforms->helpTextFontTag='<font face="verdana,sans-serif" color="#333333" size="1">';
 
                                        $trData = t3lib_div::makeInstance('t3lib_transferData');
+                                       $trData->addRawData = TRUE;
                                        $trData->defVals = t3lib_div::_GP('defVals');           // Added without testing - should provide ability to submit default values in frontend editing, in-page.
                                        $trData->fetchRecord($table,    ($theCmd=='new'?$newUid:$dataArr['uid']), ($theCmd=='new'?'new':'') );
                                        reset($trData->regTableItems_data);
@@ -6367,13 +6703,19 @@ class tslib_cObj {
                                                                                </tr>
                                                                        </table>
                                                                </form>';
+                                               // wrap the panel
+                                       if ($conf['innerWrap']) $panel = $this->wrap($panel,$conf['innerWrap']);
+                                       if ($conf['innerWrap.']) $panel = $this->stdWrap($panel,$conf['innerWrap.']);
                                                // add black line:
                                        $panel.=$blackLine;
+                                               // wrap the complete panel
+                                       if ($conf['outerWrap']) $panel = $this->wrap($panel,$conf['outerWrap']);
+                                       if ($conf['outerWrap.']) $panel = $this->stdWrap($panel,$conf['outerWrap.']);
                                        $finalOut = $content.$panel;
                                break;
                        }
 
-                       if ($conf['previewBorder']) $finalOut = $this->editPanelPreviewBorder($table,$dataArr,$finalOut,$conf['previewBorder']);
+                       if ($conf['previewBorder']) $finalOut = $this->editPanelPreviewBorder($table,$dataArr,$finalOut,$conf['previewBorder'],$conf['previewBorder.']);
                        return $finalOut;
                } else {
                        return $content;
@@ -6425,7 +6767,8 @@ class tslib_cObj {
                        $iconTitle = $this->stdWrap($conf['iconTitle'],$conf['iconTitle.']);
                        $iconImg = $conf['iconImg'] ? $conf['iconImg'] : '<img src="t3lib/gfx/edit_fe.gif" width="11" height="12" border="0" align="top" title="'.t3lib_div::deHSCentities(htmlspecialchars($iconTitle)).'"'.$style.' class="frontEndEditIcons" alt="" title="" />';
                        $nV=t3lib_div::_GP('ADMCMD_view')?1:0;
-                       $icon = $this->editPanelLinkWrap_doWrap($iconImg,TYPO3_mainDir.'alt_doc.php?edit['.$rParts[0].']['.$rParts[1].']=edit&columnsOnly='.rawurlencode($fieldList).'&noView='.$nV.$addUrlParamStr,implode(':',$rParts));
+                       $adminURL = t3lib_div::getIndpEnv('TYPO3_SITE_URL').TYPO3_mainDir;
+                       $icon = $this->editPanelLinkWrap_doWrap($iconImg, $adminURL.'alt_doc.php?edit['.$rParts[0].']['.$rParts[1].']=edit&columnsOnly='.rawurlencode($fieldList).'&noView='.$nV.$addUrlParamStr,implode(':',$rParts));
                        if ($conf['beforeLastTag']<0)   {
                                $content=$icon.$content;
                        } elseif ($conf['beforeLastTag']>0)     {
@@ -6459,16 +6802,18 @@ class tslib_cObj {
        function editPanelLinkWrap($string,$formName,$cmd,$currentRecord='',$confirm='')        {
                $eFONPage = $GLOBALS['BE_USER']->uc['TSFE_adminConfig']['edit_editFormsOnPage'];
                $nV=t3lib_div::_GP('ADMCMD_view')?1:0;
+               $adminURL = t3lib_div::getIndpEnv('TYPO3_SITE_URL').TYPO3_mainDir;
+
                if ($cmd=='edit' && !$eFONPage) {
                        $rParts = explode(':',$currentRecord);
-                       $out=$this->editPanelLinkWrap_doWrap($string,TYPO3_mainDir.'alt_doc.php?edit['.$rParts[0].']['.$rParts[1].']=edit&noView='.$nV,$currentRecord);
+                       $out=$this->editPanelLinkWrap_doWrap($string,$adminURL.'alt_doc.php?edit['.$rParts[0].']['.$rParts[1].']=edit&noView='.$nV,$currentRecord);
                } elseif ($cmd=='new' && !$eFONPage)    {
                        $rParts = explode(':',$currentRecord);
                        if ($rParts[0]=='pages')        {
-                               $out=$this->editPanelLinkWrap_doWrap($string,TYPO3_mainDir.'db_new.php?id='.$rParts[1].'&pagesOnly=1',$currentRecord);
+                               $out=$this->editPanelLinkWrap_doWrap($string,$adminURL.'db_new.php?id='.$rParts[1].'&pagesOnly=1',$currentRecord);
                        } else {
                                $nPid = t3lib_div::testInt($rParts[1]) ? -$rParts[1] : $GLOBALS['TSFE']->id;
-                               $out=$this->editPanelLinkWrap_doWrap($string,TYPO3_mainDir.'alt_doc.php?edit['.$rParts[0].']['.$nPid.']=new&noView='.$nV,$currentRecord);
+                               $out=$this->editPanelLinkWrap_doWrap($string,$adminURL.'alt_doc.php?edit['.$rParts[0].']['.$nPid.']=new&noView='.$nV,$currentRecord);
                        }
                } else {
                        if ($confirm)   {
@@ -6488,7 +6833,7 @@ class tslib_cObj {
         * Creates a link to a script (eg. typo3/alt_doc.php or typo3/db_new.php) which either opens in the current frame OR in a pop-up window.
         *
         * @param       string          The string to wrap in a link, typ. and image used as button in the edit panel.
-        * @param       string          The URL of the link
+        * @param       string          The URL of the link. Should be absolute if supposed to work with <base> path set.
         * @param       string          The "table:uid" of the record being processed by the panel.
         * @return      string          A <a> tag wrapped string.
         * @access private
@@ -6517,14 +6862,20 @@ class tslib_cObj {
         * @param       array           The data record from $table
         * @param       string          The content string to wrap
         * @param       integer         The thickness of the border
+        * @param       array           The array with TypoScript properties for the content object
         * @return      string          The input string wrapped in a table with a border color of #cccccc and thickness = $thick
         * @access private
         * @see editPanel()
         */
-       function editPanelPreviewBorder($table,$row,$content,$thick)    {
-               $thick = t3lib_div::intInRange($thick,1,100);
+       function editPanelPreviewBorder($table,$row,$content,$thick,$conf=array())      {
                if ($this->isDisabled($table,$row))     {
-                       $content='<table border="'.$thick.'" cellpadding="0" cellspacing="0" bordercolor="#cccccc" width="100%"><tr><td>'.$content.'</td></tr></table>';
+                       $thick = t3lib_div::intInRange($thick,1,100);
+                       $color = $conf['color'] ? $conf['color'] : '#cccccc';
+                       if ($conf['innerWrap']) $content = $this->wrap($content,$conf['innerWrap']);
+                       if ($conf['innerWrap.'])        $content = $this->stdWrap($content,$conf['innerWrap.']);
+                       $content='<table class="typo3-editPanel-previewBorder" border="'.$thick.'" cellpadding="0" cellspacing="0" bordercolor="'.$color.'" width="100%"><tr><td>'.$content.'</td></tr></table>';
+                       if ($conf['outerWrap']) $content = $this->wrap($content,$conf['outerWrap']);
+                       if ($conf['outerWrap.'])        $content = $this->stdWrap($panel,$conf['outerWrap.']);
                }
                return $content;
        }
@@ -6565,7 +6916,7 @@ class tslib_cObj {
 /**
  * Rendering of framesets
  *
- * @author     Kasper Skaarhoj <kasper@typo3.com>
+ * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage tslib
  */
@@ -6688,7 +7039,7 @@ class tslib_frameset {
  * Rendering of tables for offset
  *
  * @see        tslib_cObj::OTABLE(), tslib_cObj::stdWrap()
- * @author     Kasper Skaarhoj <kasper@typo3.com>
+ * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage tslib
  */
@@ -6778,7 +7129,7 @@ class tslib_tableOffset   {
  * Rendering of tables for content positioning
  *
  * @see tslib_cObj::CTABLE()
- * @author     Kasper Skaarhoj <kasper@typo3.com>
+ * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage tslib
  */
@@ -6803,7 +7154,7 @@ class tslib_controlTable  {
        var $cMt = 0;           // content margin, top
        var $cMb = 1;           // content margin, bottom
 
-       var $contentW = 0;      // sætter en lille gif-spacer nedest i content-framen
+       var $contentW = 0;      // Places a little gif-spacer in the bottom of the content frame
 
        var $tableParams = 'border="0" cellspacing="0" cellpadding="0"';
 
@@ -6836,7 +7187,7 @@ class tslib_controlTable  {
                if ($this->bm) $rows++;
                if ($this->content) $rows++;
                if ($this->contentW) $rows++;
-               if (!$rows && $cols) $rows=1;           // hvis der slet ingen rækker er sat i midten men der trods alt er nogle kolonner
+               if (!$rows && $cols) $rows=1;           // If there are no rows in the middle but still som columns...
 
                if ($rows&&$cols)       {
                        $res = chr(10).'<table '.$this->tableParams.'>';
@@ -6863,12 +7214,12 @@ class tslib_controlTable        {
                        if ($this->contentW)    {       $middle[]='<td><img src="'.$GLOBALS['TSFE']->absRefPrefix.'clear.gif" height="1" width="'.$this->contentW.'" alt="" title="" /></td>';}
                        if (isset($middle[0]))  {$res.=$middle[0];}
 
-                               // venstre for content
+                               // Left of content
                        if ($cMargArr[2])       {       $res.='<td'.$rowspan.'><img src="'.$GLOBALS['TSFE']->absRefPrefix.'clear.gif" height="1" width="'.$cMargArr[2].'" alt="" title="" /></td>';             }
                        if ($this->rm)  {       $res.='<td'.$rowspan.' '.$this->rmTDparams.'>'.$this->rm.'</td>';               }
                        $res.= '</tr>';
 
-                               // flere end de 2 rækker
+                               // More than the two rows
                        $mCount = count($middle);
                        for($a=1;$a<$mCount;$a++)       {
                                $res.='<tr>'.$middle[$a].'</tr>';