Small things
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / class.tslib_content.php
index 652b76d..713ec7d 100755 (executable)
@@ -31,7 +31,7 @@
  * 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)
@@ -603,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.']);
        }
@@ -1023,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;
                                                }
@@ -1136,39 +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))      {
+                       $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);
+                                               $GLOBALS['TSFE']->sys_page->versionOL($conf['table'],$row);
 
                                                // Language Overlay:
-                                       if ($GLOBALS['TSFE']->sys_language_contentOL)   {
+                                               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 (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'])      { $theValue.='<!--DMAILER_SECTION_BOUNDARY_'.intval($row['module_sys_dmail_category']).'-->'; }
-                                                       $theValue.= $cObj->cObjGetSingle($renderObjName, $renderObjConf, $renderObjKey);
-                                               }# else debug($GLOBALS['TSFE']->recordRegister,'CONTENT');
+                                       if ($GLOBALS['TSFE']->config['config']['insertDmailerBoundaries']) { $cobjValue.='<!--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;
                                }
-                               if ($GLOBALS['TSFE']->config['config']['insertDmailerBoundaries'])      { $theValue.='<!--DMAILER_SECTION_BOUNDARY_END-->'; }
-                       }
+                       } while ($again&&(($slide&&!strlen($tmpValue)&&$slideCollectFuzzy)||($slide&&$slideCollect)));
                }
 
                $theValue = $this->wrap($theValue,$conf['wrap']);
@@ -1228,7 +1254,7 @@ class tslib_cObj {
                                $GLOBALS['TSFE']->sys_page->versionOL($val['table'],$row);
 
                                        // Language Overlay:
-                               if ($GLOBALS['TSFE']->sys_language_contentOL)   {
+                               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);
                                }
 
@@ -1572,6 +1598,12 @@ 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++;
@@ -1631,7 +1663,7 @@ class tslib_cObj {
 
                                        // Accessibility: Set id = fieldname attribute:
                                if ($conf['accessibility'])     {
-                                       $elementIdAttribute = ' id="'.$confData['fieldname'].'"';
+                                       $elementIdAttribute = ' id="'.$formname.'_'.md5($confData['fieldname']).'"';
                                } else {
                                        $elementIdAttribute = '';
                                }
@@ -1645,7 +1677,12 @@ 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"';
+                                               $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));
@@ -1749,7 +1786,7 @@ class tslib_cObj {
                                        case 'hidden':
                                                $value = trim($parts[2]);
                                                if(strlen($value) && t3lib_div::inList('recipient_copy,recipient',$confData['fieldname']) && $GLOBALS['TYPO3_CONF_VARS']['FE']['secureFormmail']) {
-                                                 break;
+                                                       break;
                                                }
                                                if (strlen($value) && t3lib_div::inList('recipient_copy,recipient',$confData['fieldname']))     {
                                                        $value = $GLOBALS['TSFE']->codeString($value);
@@ -1826,7 +1863,7 @@ class tslib_cObj {
                                                // Field:
                                        $fieldLabel = $confData['label'];
                                        if ($conf['accessibility'])     {
-                                               $fieldLabel = '<label for="'.htmlspecialchars($confData['fieldname']).'">'.$fieldLabel.'</label>';
+                                               $fieldLabel = '<label for="'.$formname.'_'.md5($confData['fieldname']).'">'.$fieldLabel.'</label>';
                                        }
 
                                                // Getting template code:
@@ -1920,9 +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;
-                                         }
+                                               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).'" />';
@@ -1930,8 +1967,9 @@ 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']).'\')"';
                        $GLOBALS['TSFE']->additionalHeaderData['JSFormValidate'] = '<script type="text/javascript" src="'.$GLOBALS['TSFE']->absRefPrefix.'t3lib/jsfunc.validateform.js"></script>';
@@ -2097,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');
                                }
@@ -2406,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"
         *
@@ -2487,7 +2556,7 @@ class tslib_cObj {
                        }
                        $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']) {
@@ -2496,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.
@@ -2579,7 +2659,7 @@ class tslib_cObj {
                        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" '.$addParams.' />';
+                               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);
                        }
@@ -3021,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']);}
@@ -3700,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"'.$this->getAltParam($conf).' />';
+                                               $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"'.$this->getAltParam($conf).' />';
+                                       $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.']);
@@ -4670,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':
@@ -4724,7 +4813,7 @@ 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 that $GLOBALS used, then just put it in here!
+        * @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()
@@ -4925,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='';
@@ -4957,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;
@@ -4969,7 +5060,8 @@ 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:
@@ -5009,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;
@@ -5094,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;
@@ -5203,27 +5306,30 @@ class tslib_cObj {
         * @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('mailto:'.$mailAddress);
+                                       $mailToUrl = $GLOBALS['TSFE']->encryptEmail($mailToUrl);
                                } else {
-                                       $mailToUrl = "javascript:linkTo_UnCryptMailto('".$GLOBALS['TSFE']->encryptEmail('mailto:'.$mailAddress)."');";
+                                       $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);
                                }
+                               $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 = 'mailto:'.$mailAddress;
                        }
                } else {
-                       $mailToUrl = $GLOBALS['TSFE']->absRefPrefix.$GLOBALS['TSFE']->config['mainScript'].$initP.'&jumpurl='.rawurlencode('mailto:'.$mailAddress).$GLOBALS['TSFE']->getMethodUrlIdToken;
+                       $mailToUrl = $GLOBALS['TSFE']->absRefPrefix.$GLOBALS['TSFE']->config['mainScript'].$initP.'&jumpurl='.rawurlencode($mailToUrl).$GLOBALS['TSFE']->getMethodUrlIdToken;
                }
                return array($mailToUrl,$linktxt);
        }
@@ -5299,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;
@@ -5984,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);
@@ -6021,37 +6127,43 @@ class tslib_cObj {
 
                                // Select sublevel:
                        if ($depth>0)   {
-                               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($allFields, 'pages', 'pid='.intval($id).' AND deleted=0 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))      {
-#??                            $GLOBALS['TSFE']->sys_page->versionOL('pages',$row);
+                                       $GLOBALS['TSFE']->sys_page->versionOL('pages',$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 AND doktype!=255 AND doktype!=6'.$moreWhereClauses, '' ,'sorting');
-                                               $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res2);
-#??                                            $GLOBALS['TSFE']->sys_page->versionOL('pages',$row);
-                                       }
-                                               // 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.',';
-                                                       }
+                                       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);
+                                                               }
                                                        }
                                                }
                                        }
@@ -6306,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!!
@@ -6336,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);
                }
@@ -6590,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;
@@ -6743,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;
        }