Fixed bug #14050: CleanUp - CGL format of t3lib files - t3lib_scbase
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_treeview.php
old mode 100755 (executable)
new mode 100644 (file)
index ca11272..6e05fe5
@@ -1,22 +1,22 @@
 <?php
 /***************************************************************
 *  Copyright notice
-*  
-*  (c) 1999-2004 Kasper Skaarhoj (kasper@typo3.com)
+*
+*  (c) 1999-2010 Kasper Skårhøj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
-*  This script is part of the TYPO3 project. The TYPO3 project is 
+*  This script is part of the TYPO3 project. The TYPO3 project is
 *  free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
-* 
+*
 *  The GNU General Public License can be found at
 *  http://www.gnu.org/copyleft/gpl.html.
-*  A copy is found in the textfile GPL.txt and important notices to the license 
+*  A copy is found in the textfile GPL.txt and important notices to the license
 *  from the author is found in LICENSE.txt distributed with these scripts.
 *
-* 
+*
 *  This script is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/
-/** 
+/**
  * Contains base class for creating a browsable array/page/folder tree in HTML
  *
  * $Id$
- * Revised for TYPO3 3.6 November/2003 by Kasper Skaarhoj
+ * Revised for TYPO3 3.6 November/2003 by Kasper Skårhøj
  *
- * @author     Kasper Skaarhoj <kasper@typo3.com>
- * @coauthor   René Fritz <r.fritz@colorcube.de>
+ * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
+ * @coauthor   René Fritz <r.fritz@colorcube.de>
  */
 /**
  * [CLASS/FUNCTION INDEX of SCRIPT]
  *
  *
  *
- *  115: class t3lib_treeView 
- *  267:     function init($clause='', $orderByFields='')      
- *  294:     function setTreeName($treeName='') 
- *  308:     function addField($field,$noCheck=0)      
- *  322:     function reset()  
+ *  115: class t3lib_treeView
+ *  270:     function init($clause='', $orderByFields='')
+ *  301:     function setTreeName($treeName='')
+ *  315:     function addField($field,$noCheck=0)
+ *  329:     function reset()
  *
  *              SECTION: output
- *  346:     function getBrowsableTree()       
- *  405:     function printTree($treeArr='')   
+ *  349:     function getBrowsableTree()
+ *  412:     function printTree($treeArr='')
  *
  *              SECTION: rendering parts
- *  458:     function PMicon($row,$a,$c,$nextCount,$exp)       
- *  480:     function PM_ATagWrap($icon,$cmd,$bMark='')        
- *  502:     function wrapTitle($title,$row,$bank=0)   
- *  515:     function wrapIcon($icon,$row)     
- *  526:     function addTagAttributes($icon,$attr)    
- *  538:     function wrapStop($str,$row)      
+ *  467:     function PMicon($row,$a,$c,$nextCount,$exp)
+ *  489:     function PM_ATagWrap($icon,$cmd,$bMark='')
+ *  511:     function wrapTitle($title,$row,$bank=0)
+ *  524:     function wrapIcon($icon,$row)
+ *  535:     function addTagAttributes($icon,$attr)
+ *  547:     function wrapStop($str,$row)
  *
  *              SECTION: tree handling
- *  566:     function expandNext($id)  
- *  576:     function initializePositionSaving()       
- *  603:     function savePosition()   
+ *  575:     function expandNext($id)
+ *  585:     function initializePositionSaving()
+ *  612:     function savePosition()
  *
  *              SECTION: Functions that might be overwritten by extended classes
- *  632:     function getRootIcon($rec) 
- *  645:     function getIcon($row) 
- *  664:     function getTitleStr($row,$titleLen=30)   
- *  676:     function getTitleAttrib($row) 
- *  686:     function getId($row) 
- *  696:     function getJumpToParm($row) 
+ *  641:     function getRootIcon($rec)
+ *  654:     function getIcon($row)
+ *  673:     function getTitleStr($row,$titleLen=30)
+ *  685:     function getTitleAttrib($row)
+ *  695:     function getId($row)
+ *  705:     function getJumpToParam($row)
  *
  *              SECTION: tree data buidling
- *  729:     function getTree($uid, $depth=999, $depthData='',$blankLineCode='')       
+ *  739:     function getTree($uid, $depth=999, $depthData='',$blankLineCode='',$subCSSclass='')
  *
  *              SECTION: Data handling
- *  826:     function getCount($uid)   
- *  853:     function getRootRecord($uid) 
- *  866:     function getRecord($uid) 
- *  883:     function getDataInit($parentId) 
- *  913:     function getDataCount(&$res) 
- *  930:     function getDataNext(&$res)
- *  958:     function getDataFree(&$res)
- *  978:     function setDataFromArray(&$dataArr,$traverse=FALSE,$pid=0)       
- * 1011:     function setDataFromTreeArray(&$treeArr, &$treeLookupArr) 
+ *  839:     function getCount($uid)
+ *  865:     function getRootRecord($uid)
+ *  878:     function getRecord($uid)
+ *  898:     function getDataInit($parentId,$subCSSclass='')
+ *  929:     function getDataCount(&$res)
+ *  947:     function getDataNext(&$res,$subCSSclass='')
+ *  986:     function getDataFree(&$res)
+ * 1006:     function setDataFromArray(&$dataArr,$traverse=FALSE,$pid=0)
+ * 1035:     function setDataFromTreeArray(&$treeArr, &$treeLookupArr)
  *
  * TOTAL FUNCTIONS: 31
  * (This index is automatically created/updated by the extension "extdeveval")
  *
  */
 
 
 
 
 
 
-require_once (PATH_t3lib.'class.t3lib_iconworks.php');
-require_once (PATH_t3lib.'class.t3lib_befunc.php');
-require_once (PATH_t3lib.'class.t3lib_div.php');
+
+
 
 
 /**
  * Base class for creating a browsable array/page/folder tree in HTML
  *
- * @author     Kasper Skaarhoj <kasper@typo3.com>
- * @coauthor   René Fritz <r.fritz@colorcube.de>
+ * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
+ * @coauthor   René Fritz <r.fritz@colorcube.de>
  * @package TYPO3
  * @subpackage t3lib
  * @see t3lib_browsetree, t3lib_pagetree, t3lib_foldertree
@@ -122,10 +119,14 @@ class t3lib_treeView {
        var $ext_IconMode = false;              // If true, no context menu is rendered on icons. If set to "titlelink" the icon is linked as the title is.
        var $addSelfId = 0;                             // If set, the id of the mounts will be added to the internal ids array
        var $title='no title';                  // Used if the tree is made of records (not folders for ex.)
+       var $showDefaultTitleAttribute = FALSE;         // If true, a default title attribute showing the UID of the record is shown. This cannot be enabled by default because it will destroy many applications where another title attribute is in fact applied later.
+       var $highlightPagesWithVersions = TRUE;         // If true, pages containing child records which has versions will be highlighted in yellow. This might be too expensive in terms of processing power.
 
        /**
         * Needs to be initialized with $GLOBALS['BE_USER']
         * Done by default in init()
+        *
+        * @var t3lib_beUserAuth
         */
        var $BE_USER='';
 
@@ -212,6 +213,7 @@ class t3lib_treeView {
 
        /**
         * If true, HTML code is also accumulated in ->tree array during rendering of the tree.
+        * If 2, then also the icon prefix code (depthData) is stored
         */
        var $makeHTML=1;
 
@@ -224,7 +226,7 @@ class t3lib_treeView {
         * Sets the associative array key which identifies a new sublevel if arrays are used for trees.
         * This value has formerly been "subLevel" and "--sublevel--"
         */
-       var $subLevelID = '_SUB_LEVEL'; 
+       var $subLevelID = '_SUB_LEVEL';
 
 
 
@@ -235,6 +237,7 @@ class t3lib_treeView {
                // For record trees:
        var $ids = Array();                             // one-dim array of the uid's selected.
        var $ids_hierarchy = array();   // The hierarchy of element uids
+       var $orig_ids_hierarchy = array();      // The hierarchy of versioned element uids
        var $buffer_idH = array();              // Temporary, internal array
 
                // For FOLDER trees:
@@ -250,7 +253,7 @@ class t3lib_treeView {
        var $bank=0;                                    // Points to the current mountpoint key
        var $recs = array();                    // Accumulates the displayed records.
 
-       
+
 
 
 
@@ -281,6 +284,10 @@ class t3lib_treeView {
                if($this->table) {
                        t3lib_div::loadTCA($this->table);
                }
+
+                       // setting this to false disables the use of array-trees by default
+               $this->data = false;
+               $this->dataLookup = false;
        }
 
 
@@ -311,11 +318,11 @@ class t3lib_treeView {
                        $this->fieldArray[]=$field;
                }
        }
-       
-       
-       
+
+
+
        /**
-        * Resets the tree, recs, ids, and ids_hierarchy internal variables. Use it if you need it.
+        * Resets the tree, recs, ids, ids_hierarchy and orig_ids_hierarchy internal variables. Use it if you need it.
         *
         * @return      void
         */
@@ -324,10 +331,7 @@ class t3lib_treeView {
                $this->recs = array();
                $this->ids = array();
                $this->ids_hierarchy = array();
-       
-       # These lines should be removed; The first one does not do anything since $This is not $this; The second makes tree generation based on an array impossible...  
-#              $This->data = false;
-#              $this->dataLookup = false;
+               $this->orig_ids_hierarchy = array();
        }
 
 
@@ -354,13 +358,13 @@ class t3lib_treeView {
 
                        // Traverse mounts:
                foreach($this->MOUNTS as $idx => $uid)  {
-                               
+
                                // Set first:
                        $this->bank=$idx;
                        $isOpen = $this->stored[$idx][$uid] || $this->expandFirst;
 
                                // Save ids while resetting everything else.
-                       $curIds = $this->ids;   
+                       $curIds = $this->ids;
                        $this->reset();
                        $this->ids = $curIds;
 
@@ -371,31 +375,35 @@ class t3lib_treeView {
 
                                // Preparing rootRec for the mount
                        if ($uid)       {
-                               $rootRec=$this->getRecord($uid);
+                               $rootRec = $this->getRecord($uid);
                                $firstHtml.=$this->getIcon($rootRec);
                        } else {
                                        // Artificial record for the tree root, id=0
-                               $rootRec=$this->getRootRecord($uid);
+                               $rootRec = $this->getRootRecord($uid);
                                $firstHtml.=$this->getRootIcon($rootRec);
                        }
 
-                               // Add the root of the mount to ->tree
-                       $this->tree[]=array('HTML'=>$firstHtml,'row'=>$rootRec,'bank'=>$this->bank);
+                       if (is_array($rootRec)) {
+                               $uid = $rootRec['uid'];         // In case it was swapped inside getRecord due to workspaces.
 
-                               // If the mount is expanded, go down:
-                       if ($isOpen)    {
-                                       // Set depth:
-                               $depthD='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/blank.gif','width="18" height="16"').' alt="" />';
-                               if ($this->addSelfId)   $this->ids[] = $uid;
-                               $this->getTree($uid,999,$depthD);
-                       }
+                                       // Add the root of the mount to ->tree
+                               $this->tree[]=array('HTML'=>$firstHtml, 'row'=>$rootRec, 'bank'=>$this->bank);
+
+                                       // If the mount is expanded, go down:
+                               if ($isOpen)    {
+                                               // Set depth:
+                                       $depthD='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/blank.gif','width="18" height="16"').' alt="" />';
+                                       if ($this->addSelfId)   $this->ids[] = $uid;
+                                       $this->getTree($uid,999,$depthD,'',$rootRec['_SUBCSSCLASS']);
+                               }
 
-                               // Add tree:
-                       $treeArr=array_merge($treeArr,$this->tree);
+                                       // Add tree:
+                               $treeArr=array_merge($treeArr,$this->tree);
+                       }
                }
                return $this->printTree($treeArr);
        }
-       
+
        /**
         * Compiles the HTML code for displaying the structure found inside the ->tree array
         *
@@ -411,17 +419,19 @@ class t3lib_treeView {
                        // not a problem if you don't need it
                        // In XHTML there is no "name" attribute of <td> elements - but Mozilla will not be able to highlight rows if the name attribute is NOT there.
                $out .= '
-               
-                       <!-- 
+
+                       <!--
                          TYPO3 tree structure.
                        -->
                        <table cellpadding="0" cellspacing="0" border="0" id="typo3-tree">';
 
                foreach($treeArr as $k => $v)   {
                        $idAttr = htmlspecialchars($this->domIdPrefix.$this->getId($v['row']).'_'.$v['bank']);
+
                        $out.='
                                <tr>
-                                       <td id="'.$idAttr.'">'.
+                                       <td id="'.$idAttr.'"'.
+                                               ($v['row']['_CSSCLASS'] ? ' class="'.$v['row']['_CSSCLASS'].'"' : '').'>'.
                                                $v['HTML'].
                                                $this->wrapTitle($this->getTitleStr($v['row'],$titleLen),$v['row'],$v['bank']).
                                        '</td>
@@ -500,7 +510,7 @@ class t3lib_treeView {
         * @access private
         */
        function wrapTitle($title,$row,$bank=0) {
-               $aOnClick = 'return jumpTo('.$this->getJumpToParm($row).',this,\''.$this->domIdPrefix.$this->getId($row).'_'.$bank.'\');';
+               $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix.$this->getId($row).'\','.$bank.');';
                return '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$title.'</a>';
        }
 
@@ -515,7 +525,7 @@ class t3lib_treeView {
        function wrapIcon($icon,$row)   {
                return $icon;
        }
-       
+
        /**
         * Adds attributes to image tag.
         *
@@ -524,7 +534,7 @@ class t3lib_treeView {
         * @return      string          Image tag, modified with $attr attributes added.
         */
        function addTagAttributes($icon,$attr)  {
-               return ereg_replace(' ?\/?>$','',$icon).' '.$attr.' />'; 
+               return preg_replace('/ ?\/?>$/','',$icon).' '.$attr.' />';
        }
 
        /**
@@ -537,7 +547,7 @@ class t3lib_treeView {
         */
        function wrapStop($str,$row)    {
                if ($row['php_tree_stop'])      {
-                       $str.='<span class="typo3-red">+ </span>';
+                       $str .= '<span class="typo3-red"><a href="' . htmlspecialchars(t3lib_div::linkThisScript(array('setTempDBmount' => $row['uid']))) . '" class="typo3-red">+</a> </span>';
                }
                return $str;
        }
@@ -606,7 +616,7 @@ class t3lib_treeView {
        }
 
 
-       
+
 
 
 
@@ -618,9 +628,9 @@ class t3lib_treeView {
 
 
        /******************************
-        * 
+        *
         * Functions that might be overwritten by extended classes
-        * 
+        *
         ********************************/
 
        /**
@@ -630,7 +640,7 @@ class t3lib_treeView {
         * @return      string          Icon image tag.
         */
        function getRootIcon($rec) {
-               return $this->wrapIcon('<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/i/_icon_website.gif','width="18" height="16"').' alt="" />',$rec);
+               return $this->wrapIcon(t3lib_iconWorks::getSpriteIcon('apps-pagetree-root'),$rec);
        }
 
 
@@ -644,9 +654,14 @@ class t3lib_treeView {
         */
        function getIcon($row) {
                if ($this->iconPath && $this->iconName) {
-                       $icon = '<img'.t3lib_iconWorks::skinImg('',$this->iconPath.$this->iconName,'width="18" height="16"').' alt="" />';
+                       $icon = '<img'.t3lib_iconWorks::skinImg('',$this->iconPath.$this->iconName,'width="18" height="16"').' alt=""'.($this->showDefaultTitleAttribute ? ' title="UID: '.$row['uid'].'"':'').' />';
                } else {
-                       $icon = t3lib_iconWorks::getIconImage($this->table,$row,$this->backPath,'align="top" class="c-recIcon"');
+
+                       $icon = t3lib_iconWorks::getSpriteIconForRecord($this->table, $row, array(
+                               'title' => ($this->showDefaultTitleAttribute ? 'UID: ' . $row['uid'] : $this->getTitleAttrib($row)),
+                               'class' => 'c-recIcon'
+                       ));
+
                }
 
                return $this->wrapIcon($icon,$row);
@@ -654,7 +669,7 @@ class t3lib_treeView {
 
 
        /**
-        * Returns the title for the input record. If blank, a "no title" labele (localized) will be returned.
+        * Returns the title for the input record. If blank, a "no title" label (localized) will be returned.
         * Do NOT htmlspecialchar the string from this function - has already been done.
         *
         * @param       array           The input row array (where the key "title" is used for the title)
@@ -662,7 +677,16 @@ class t3lib_treeView {
         * @return      string          The title.
         */
        function getTitleStr($row,$titleLen=30) {
-               $title = (!strcmp(trim($row['title']),'')) ? '<em>['.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.no_title',1).']</em>' : htmlspecialchars(t3lib_div::fixed_lgd($row['title'],$titleLen));
+               if ($this->ext_showNavTitle && strlen(trim($row['nav_title'])) > 0)     {
+                       $title = '<span title="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_tca.xml:title',1).' '.htmlspecialchars(trim($row['title'])).'">'.htmlspecialchars(t3lib_div::fixed_lgd_cs($row['nav_title'],$titleLen)).'</span>';
+               } else {
+                       $title = htmlspecialchars(t3lib_div::fixed_lgd_cs($row['title'],$titleLen));
+                       if (strlen(trim($row['nav_title'])) > 0)        {
+                               $title = '<span title="'.$GLOBALS['LANG']->sL('LLL:EXT:cms/locallang_tca.xml:pages.nav_title',1).' '.htmlspecialchars(trim($row['nav_title'])).'">'.$title.'</span>';
+                       }
+                       $title = (strlen(trim($row['title'])) == 0) ? '<em>['.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.no_title',1).']</em>' : $title;
+               }
+
                return $title;
        }
 
@@ -676,7 +700,7 @@ class t3lib_treeView {
        function getTitleAttrib($row) {
                return htmlspecialchars($row['title']);
        }
-       
+
        /**
         * Returns the id from the record (typ. uid)
         *
@@ -693,8 +717,8 @@ class t3lib_treeView {
         * @param       array           The record array.
         * @return      string          The jump-url parameter.
         */
-       function getJumpToParm($row) {
-               return "'".$this->getId($row)."'";
+       function getJumpToParam($row) {
+               return $this->getId($row);
        }
 
 
@@ -724,29 +748,36 @@ class t3lib_treeView {
         * @param       integer         Max depth (recursivity limit)
         * @param       string          HTML-code prefix for recursive calls.
         * @param       string          ? (internal)
+        * @param       string          CSS class to use for <td> sub-elements
         * @return      integer         The count of items on the level
         */
-       function getTree($uid, $depth=999, $depthData='',$blankLineCode='')     {
+       function getTree($uid, $depth=999, $depthData='',$blankLineCode='',$subCSSclass='')     {
 
                        // Buffer for id hierarchy is reset:
                $this->buffer_idH=array();
-               
 
                        // Init vars
                $depth=intval($depth);
                $HTML='';
                $a=0;
 
-               $res = $this->getDataInit($uid);
+               $res = $this->getDataInit($uid,$subCSSclass);
                $c = $this->getDataCount($res);
                $crazyRecursionLimiter = 999;
 
+               $idH = array();
+
                        // Traverse the records:
-               while ($crazyRecursionLimiter>0 && $row = $this->getDataNext($res))     {
+               while ($crazyRecursionLimiter>0 && $row = $this->getDataNext($res,$subCSSclass))        {
                        $a++;
                        $crazyRecursionLimiter--;
 
-                       $newID =$row['uid'];
+                       $newID = $row['uid'];
+
+                       if ($newID == 0) {
+                               throw new RuntimeException('Endless recursion detected: TYPO3 has detected an error in the database. Please fix it manually (e.g. using phpMyAdmin) and change the UID of '.$this->table.':0 to a new value.<br /><br />See <a href="http://bugs.typo3.org/view.php?id=3495" target="_blank">bugs.typo3.org/view.php?id=3495</a> to get more information about a possible cause.');
+                       }
+
                        $this->tree[]=array();          // Reserve space.
                        end($this->tree);
                        $treeKey = key($this->tree);    // Get the key for this space
@@ -758,16 +789,19 @@ class t3lib_treeView {
                        }
 
                                // Accumulate the id of the element in the internal arrays
-                       $this->ids[]=$idH[$row['uid']]['uid']=$row['uid'];
-                       $this->ids_hierarchy[$depth][]=$row['uid'];
+                       $this->ids[] = $idH[$row['uid']]['uid'] = $row['uid'];
+                       $this->ids_hierarchy[$depth][] = $row['uid'];
+                       $this->orig_ids_hierarchy[$depth][] = $row['_ORIG_uid'] ? $row['_ORIG_uid'] : $row['uid'];
 
                                // Make a recursive call to the next level
+                       $HTML_depthData = $depthData.'<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.$LN.'.gif','width="18" height="16"').' alt="" />';
                        if ($depth>1 && $this->expandNext($newID) && !$row['php_tree_stop'])    {
                                $nextCount=$this->getTree(
                                                $newID,
                                                $depth-1,
-                                               $this->makeHTML?$depthData.'<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.$LN.'.gif','width="18" height="16"').' alt="" />':'',
-                                               $blankLineCode.','.$LN
+                                               $this->makeHTML ? $HTML_depthData : '',
+                                               $blankLineCode.','.$LN,
+                                               $row['_SUBCSSCLASS']
                                        );
                                if (count($this->buffer_idH))   $idH[$row['uid']]['subrow']=$this->buffer_idH;
                                $exp=1; // Set "did expand" flag
@@ -787,6 +821,7 @@ class t3lib_treeView {
                        $this->tree[$treeKey] = Array(
                                'row'=>$row,
                                'HTML'=>$HTML,
+                               'HTML_depthData' => $this->makeHTML==2 ? $HTML_depthData : '',
                                'invertedDepth'=>$depth,
                                'blankLineCode'=>$blankLineCode,
                                'bank' => $this->bank
@@ -828,19 +863,16 @@ class t3lib_treeView {
                        $res = $this->getDataInit($uid);
                        return $this->getDataCount($res);
                } else {
-                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
-                                               'count(*)', 
-                                               $this->table, 
-                                               $this->parentField.'="'.$GLOBALS['TYPO3_DB']->quoteStr($uid, $this->table).'"'.
-                                                       t3lib_BEfunc::deleteClause($this->table).
-                                                       $this->clause,  // whereClauseMightContainGroupOrderBy
-                                               '',
-                                               $this->orderByFields
-                                       );
-                       $row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
-                       return $row[0];
+                       return $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
+                               'uid',
+                               $this->table,
+                               $this->parentField . '=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($uid, $this->table) .
+                                       t3lib_BEfunc::deleteClause($this->table) .
+                                       t3lib_BEfunc::versioningPlaceholderClause($this->table) .
+                                       $this->clause   // whereClauseMightContainGroupOrderBy
+                       );
                }
-       }       
+       }
 
 
 
@@ -851,7 +883,7 @@ class t3lib_treeView {
         * @return      array           Array with title/uid keys with values of $this->title/0 (zero)
         */
        function getRootRecord($uid) {
-               return array('title'=>$this->title, 'uid'=>0);
+               return array('title' => $this->title, 'uid' => 0);
        }
 
 
@@ -867,7 +899,7 @@ class t3lib_treeView {
                if (is_array($this->data)) {
                        return $this->dataLookup[$uid];
                } else {
-                       return t3lib_befunc::getRecord($this->table,$uid);
+                       return t3lib_BEfunc::getRecordWSOL($this->table, $uid);
                }
        }
 
@@ -877,10 +909,11 @@ class t3lib_treeView {
         * For arrays: This will return key to the ->dataLookup array
         *
         * @param       integer         parent item id
+        * @param       string          Class for sub-elements.
         * @return      mixed           data handle (Tables: An sql-resource, arrays: A parentId integer. -1 is returned if there were NO subLevel.)
         * @access private
         */
-       function getDataInit($parentId) {
+       function getDataInit($parentId,$subCSSclass='') {
                if (is_array($this->data)) {
                        if (!is_array($this->dataLookup[$parentId][$this->subLevelID])) {
                                $parentId = -1;
@@ -890,10 +923,11 @@ class t3lib_treeView {
                        return $parentId;
                } else {
                        $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
-                                               implode($this->fieldArray,','), 
-                                               $this->table, 
-                                               $this->parentField.'="'.$GLOBALS['TYPO3_DB']->quoteStr($parentId, $this->table).'"'.
+                                               implode(',',$this->fieldArray),
+                                               $this->table,
+                                               $this->parentField.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($parentId, $this->table).
                                                        t3lib_BEfunc::deleteClause($this->table).
+                                                       t3lib_BEfunc::versioningPlaceholderClause($this->table).
                                                        $this->clause,  // whereClauseMightContainGroupOrderBy
                                                '',
                                                $this->orderByFields
@@ -923,28 +957,42 @@ class t3lib_treeView {
         * Getting the tree data: next entry
         *
         * @param       mixed           data handle
+        * @param       string          CSS class for sub elements (workspace related)
         * @return      array           item data array OR FALSE if end of elements.
         * @access private
         * @see getDataInit()
         */
-       function getDataNext(&$res){
+       function getDataNext(&$res,$subCSSclass='')     {
                if (is_array($this->data)) {
                        if ($res<0) {
                                $row=FALSE;
                        } else {
                                list(,$row) = each($this->dataLookup[$res][$this->subLevelID]);
 
-                               /*
-                               if (!is_array($row))    {
-                                       $row=FALSE;
-                               } else {
-                                       unset($row['subLevel']);
-                               }       
-                               */
+                                       // Passing on default <td> class for subelements:
+                               if (is_array($row) && $subCSSclass!=='')        {
+                                       $row['_CSSCLASS'] = $row['_SUBCSSCLASS'] = $subCSSclass;
+                               }
                        }
                        return $row;
                } else {
-                       return @$GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
+                       while($row = @$GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))      {
+                               t3lib_BEfunc::workspaceOL($this->table, $row, $this->BE_USER->workspace, TRUE);
+                               if (is_array($row))     break;
+                       }
+
+                               // Passing on default <td> class for subelements:
+                       if (is_array($row) && $subCSSclass!=='')        {
+
+                               if ($this->table==='pages' && $this->highlightPagesWithVersions && !isset($row['_CSSCLASS']) && count(t3lib_BEfunc::countVersionsOfRecordsOnPage($this->BE_USER->workspace, $row['uid'], TRUE)))        {
+                                       $row['_CSSCLASS'] = 'ver-versions';
+                               }
+
+                               if (!isset($row['_CSSCLASS']))  $row['_CSSCLASS'] = $subCSSclass;
+                               if (!isset($row['_SUBCSSCLASS']))       $row['_SUBCSSCLASS'] = $subCSSclass;
+                       }
+
+                       return $row;
                }
        }
 
@@ -955,10 +1003,8 @@ class t3lib_treeView {
         * @return      void
         * @access private
         */
-       function getDataFree(&$res){
-               if (is_array($this->data)) {
-               #       unset();
-               } else {
+       function getDataFree(&$res) {
+               if (!is_array($this->data)) {
                        $GLOBALS['TYPO3_DB']->sql_free_result($res);
                }
        }
@@ -993,12 +1039,8 @@ class t3lib_treeView {
 
                        if (is_array($val[$this->subLevelID])) {
                                $this->setDataFromArray($dataArr[$uid][$this->subLevelID],TRUE,$uid);
-                               unset($dataArr[$uid][$this->subLevelID]);
                        }
                }
-               if (!$traverse) {
-                       $this->data = &$dataArr;
-               }
        }
 
        /**
@@ -1043,7 +1085,7 @@ class t3lib_treeView {
                                        ),
                                        [6] => array(
                                                'title'=>'title...',
-                                               'id' => 'id...', 
+                                               'id' => 'id...',
                                                'icon' => 'icon ref, relative to typo3/ folder...'
                                        ),
                                )
@@ -1053,9 +1095,8 @@ class t3lib_treeView {
 }
 
 
-                       
-
 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_treeview.php']) {
        include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_treeview.php']);
 }
-?>
+
+?>
\ No newline at end of file