[BUGFIX] Untrusted GP data is unserialized in wizard_colorpicker.php and view_help.php
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_treeview.php
old mode 100755 (executable)
new mode 100644 (file)
index e2af995..0dfa456
 <?php
 /***************************************************************
-*  Copyright notice
-*
-*  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
-*  All rights reserved
-*
-*  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
-*  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
-*  GNU General Public License for more details.
-*
-*  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
- *
- * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
- * @coauthor   René Fritz <r.fritz@colorcube.de>
- */
-/**
- * [CLASS/FUNCTION INDEX of SCRIPT]
- *
+ *  Copyright notice
  *
+ *  (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
+ *  All rights reserved
  *
- *  115: class t3lib_treeView
- *  267:     function init($clause='', $orderByFields='')
- *  298:     function setTreeName($treeName='')
- *  312:     function addField($field,$noCheck=0)
- *  326:     function reset()
+ *  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.
  *
- *              SECTION: output
- *  346:     function getBrowsableTree()
- *  407:     function printTree($treeArr='')
+ *  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
+ *  from the author is found in LICENSE.txt distributed with these scripts.
  *
- *              SECTION: rendering parts
- *  460:     function PMicon($row,$a,$c,$nextCount,$exp)
- *  482:     function PM_ATagWrap($icon,$cmd,$bMark='')
- *  504:     function wrapTitle($title,$row,$bank=0)
- *  517:     function wrapIcon($icon,$row)
- *  528:     function addTagAttributes($icon,$attr)
- *  540:     function wrapStop($str,$row)
  *
- *              SECTION: tree handling
- *  568:     function expandNext($id)
- *  578:     function initializePositionSaving()
- *  605:     function savePosition()
+ *  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
+ *  GNU General Public License for more details.
  *
- *              SECTION: Functions that might be overwritten by extended classes
- *  634:     function getRootIcon($rec)
- *  647:     function getIcon($row)
- *  666:     function getTitleStr($row,$titleLen=30)
- *  678:     function getTitleAttrib($row)
- *  688:     function getId($row)
- *  698:     function getJumpToParam($row)
- *
- *              SECTION: tree data buidling
- *  731:     function getTree($uid, $depth=999, $depthData='',$blankLineCode='')
- *
- *              SECTION: Data handling
- *  828:     function getCount($uid)
- *  855:     function getRootRecord($uid)
- *  868:     function getRecord($uid)
- *  885:     function getDataInit($parentId)
- *  915:     function getDataCount(&$res)
- *  932:     function getDataNext(&$res)
- *  960:     function getDataFree(&$res)
- *  980:     function setDataFromArray(&$dataArr,$traverse=FALSE,$pid=0)
- * 1009:     function setDataFromTreeArray(&$treeArr, &$treeLookupArr)
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+/**
+ * Contains base class for creating a browsable array/page/folder tree in HTML
  *
- * TOTAL FUNCTIONS: 31
- * (This index is automatically created/updated by the extension "extdeveval")
+ * Revised for TYPO3 3.6 November/2003 by Kasper Skårhøj
  *
+ * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
+ * @coauthor   René Fritz <r.fritz@colorcube.de>
  */
 
 
-
-
-
-
-
-
-
-
-
-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 <kasperYYYY@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
@@ -115,60 +46,63 @@ require_once (PATH_t3lib.'class.t3lib_div.php');
 class t3lib_treeView {
 
                // EXTERNAL, static:
-       var $expandFirst=0;             // If set, the first element in the tree is always expanded.
-       var $expandAll=0;               // If set, then ALL items will be expanded, regardless of stored settings.
-       var $thisScript='';             // Holds the current script to reload to.
-       var $titleAttrib = 'title';             // Which HTML attribute to use: alt/title. See init().
-       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 $expandFirst = 0; // If set, the first element in the tree is always expanded.
+       var $expandAll = 0; // If set, then ALL items will be expanded, regardless of stored settings.
+       var $thisScript = ''; // Holds the current script to reload to.
+       var $titleAttrib = 'title'; // Which HTML attribute to use: alt/title. See init().
+       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='';
+       var $BE_USER = '';
 
        /**
         * Needs to be initialized with e.g. $GLOBALS['WEBMOUNTS']
         * Default setting in init() is 0 => 0
         * The keys are mount-ids (can be anything basically) and the values are the ID of the root element (COULD be zero or anything else. For pages that would be the uid of the page, zero for the pagetree root.)
         */
-       var $MOUNTS='';
-
+       var $MOUNTS = '';
 
 
        /**
         * Database table to get the tree data from.
         * Leave blank if data comes from an array.
         */
-       var $table='';
+       var $table = '';
 
        /**
         * Defines the field of $table which is the parent id field (like pid for table pages).
         */
-       var $parentField='pid';
+       var $parentField = 'pid';
 
        /**
         * WHERE clause used for selecting records for the tree. Is set by function init.
         * Only makes sense when $this->table is set.
         * @see init()
         */
-       var $clause='';
+       var $clause = '';
 
        /**
         * Field for ORDER BY. Is set by function init.
         * Only makes sense when $this->table is set.
         * @see init()
         */
-       var $orderByFields='';
+       var $orderByFields = '';
 
        /**
         * Default set of fields selected from the tree table.
         * Make SURE that these fields names listed herein are actually possible to select from $this->table (if that variable is set to a TCA table name)
         * @see addField()
         */
-       var $fieldArray = Array('uid','title');
+       var $fieldArray = array('uid', 'title');
 
        /**
         * List of other fields which are ALLOWED to set (here, based on the "pages" table!)
@@ -211,12 +145,13 @@ class t3lib_treeView {
        var $iconName = 'default.gif';
 
        /**
-        * If true, HTML code is also accumulated in ->tree array during rendering of the tree.
+        * 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;
+       var $makeHTML = 1;
 
        /**
-        * If true, records as selected will be stored internally in the ->recs array
+        * If TRUE, records as selected will be stored internally in the ->recs array
         */
        var $setRecs = 0;
 
@@ -227,33 +162,27 @@ class t3lib_treeView {
        var $subLevelID = '_SUB_LEVEL';
 
 
-
-
                // *********
                // Internal
                // *********
                // For record trees:
-       var $ids = Array();                             // one-dim array of the uid's selected.
-       var $ids_hierarchy = array();   // The hierarchy of element uids
-       var $buffer_idH = array();              // Temporary, internal array
+       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:
-       var $specUIDmap=array();                // Special UIDs for folders (integer-hashes of paths)
+       var $specUIDmap = array(); // Special UIDs for folders (integer-hashes of paths)
 
                // For arrays:
-       var $data = false;                              // Holds the input data array
-       var $dataLookup = false;                // Holds an index with references to the data array.
+       var $data = FALSE; // Holds the input data array
+       var $dataLookup = FALSE; // Holds an index with references to the data array.
 
                // For both types
-       var $tree = Array();                    // Tree is accumulated in this variable
-       var $stored = array();                  // Holds (session stored) information about which items in the tree are unfolded and which are not.
-       var $bank=0;                                    // Points to the current mountpoint key
-       var $recs = array();                    // Accumulates the displayed records.
-
-
-
-
-
+       var $tree = array(); // Tree is accumulated in this variable
+       var $stored = array(); // Holds (session stored) information about which items in the tree are unfolded and which are not.
+       var $bank = 0; // Points to the current mountpoint key
+       var $recs = array(); // Accumulates the displayed records.
 
 
        /**
@@ -264,27 +193,31 @@ class t3lib_treeView {
         * @param       string          record ORDER BY field
         * @return      void
         */
-       function init($clause='', $orderByFields='')    {
-               $this->BE_USER = $GLOBALS['BE_USER'];   // Setting BE_USER by default
-               $this->titleAttrib = 'title';   // Setting title attribute to use.
-               $this->backPath = $GLOBALS['BACK_PATH'];        // Setting backpath.
+       function init($clause = '', $orderByFields = '') {
+               $this->BE_USER = $GLOBALS['BE_USER']; // Setting BE_USER by default
+               $this->titleAttrib = 'title'; // Setting title attribute to use.
+               $this->backPath = $GLOBALS['BACK_PATH']; // Setting backpath.
 
-               if ($clause)    $this->clause = $clause;        // Setting clause
-               if ($orderByFields)     $this->orderByFields = $orderByFields;
+               if ($clause) {
+                       $this->clause = $clause;
+               } // Setting clause
+               if ($orderByFields) {
+                       $this->orderByFields = $orderByFields;
+               }
 
-               if (!is_array($this->MOUNTS))   {
+               if (!is_array($this->MOUNTS)) {
                        $this->MOUNTS = array(0 => 0); // dummy
                }
 
                $this->setTreeName();
 
-               if($this->table) {
+               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;
+                       // setting this to FALSE disables the use of array-trees by default
+               $this->data = FALSE;
+               $this->dataLookup = FALSE;
        }
 
 
@@ -295,10 +228,10 @@ class t3lib_treeView {
         * @param       string          Default is the table name. Underscores are stripped.
         * @return      void
         */
-       function setTreeName($treeName='') {
+       function setTreeName($treeName = '') {
                $this->treeName = $treeName ? $treeName : $this->treeName;
                $this->treeName = $this->treeName ? $this->treeName : $this->table;
-               $this->treeName = str_replace('_','',$this->treeName);
+               $this->treeName = str_replace('_', '', $this->treeName);
        }
 
 
@@ -306,28 +239,27 @@ class t3lib_treeView {
         * Adds a fieldname to the internal array ->fieldArray
         *
         * @param       string          Field name to
-        * @param       boolean         If set, the fieldname will be set no matter what. Otherwise the field name must either be found as key in $TCA[$table]['columns'] or in the list ->defaultList
+        * @param       boolean         If set, the fieldname will be set no matter what. Otherwise the field name must either be found as key in $GLOBALS['TCA'][$table]['columns'] or in the list ->defaultList
         * @return      void
         */
-       function addField($field,$noCheck=0)    {
-               global $TCA;
-               if ($noCheck || is_array($TCA[$this->table]['columns'][$field]) || t3lib_div::inList($this->defaultList,$field))        {
-                       $this->fieldArray[]=$field;
+       function addField($field, $noCheck = 0) {
+               if ($noCheck || is_array($GLOBALS['TCA'][$this->table]['columns'][$field]) || t3lib_div::inList($this->defaultList, $field)) {
+                       $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
         */
-       function reset()        {
+       function reset() {
                $this->tree = array();
                $this->recs = array();
                $this->ids = array();
                $this->ids_hierarchy = array();
+               $this->orig_ids_hierarchy = array();
        }
 
 
@@ -343,20 +275,20 @@ class t3lib_treeView {
         *
         * @return      string          HTML code for the browsable tree
         */
-       function getBrowsableTree()     {
+       function getBrowsableTree() {
 
                        // Get stored tree structure AND updating it if needed according to incoming PM GET var.
                $this->initializePositionSaving();
 
                        // Init done:
-               $titleLen=intval($this->BE_USER->uc['titleLen']);
-               $treeArr=array();
+               $titleLen = intval($this->BE_USER->uc['titleLen']);
+               $treeArr = array();
 
                        // Traverse mounts:
-               foreach($this->MOUNTS as $idx => $uid)  {
+               foreach ($this->MOUNTS as $idx => $uid) {
 
                                // Set first:
-                       $this->bank=$idx;
+                       $this->bank = $idx;
                        $isOpen = $this->stored[$idx][$uid] || $this->expandFirst;
 
                                // Save ids while resetting everything else.
@@ -365,34 +297,38 @@ class t3lib_treeView {
                        $this->ids = $curIds;
 
                                // Set PM icon for root of mount:
-                       $cmd=$this->bank.'_'.($isOpen?"0_":"1_").$uid.'_'.$this->treeName;
-                       $icon='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.($isOpen?'minus':'plus').'only.gif','width="18" height="16"').' alt="" />';
-                       $firstHtml= $this->PM_ATagWrap($icon,$cmd);
+                       $cmd = $this->bank . '_' . ($isOpen ? "0_" : "1_") . $uid . '_' . $this->treeName;
+                       $icon = '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/ol/' . ($isOpen ? 'minus' : 'plus') . 'only.gif', 'width="18" height="16"') . ' alt="" />';
+                       $firstHtml = $this->PM_ATagWrap($icon, $cmd);
 
                                // Preparing rootRec for the mount
-                       if ($uid)       {
+                       if ($uid) {
                                $rootRec = $this->getRecord($uid);
-                               $firstHtml.=$this->getIcon($rootRec);
+                               $firstHtml .= $this->getIcon($rootRec);
                        } else {
                                        // Artificial record for the tree root, id=0
                                $rootRec = $this->getRootRecord($uid);
-                               $firstHtml.=$this->getRootIcon($rootRec);
+                               $firstHtml .= $this->getRootIcon($rootRec);
                        }
 
-                       if (is_array($rootRec)) {
+                       if (is_array($rootRec)) {
+                               $uid = $rootRec['uid']; // In case it was swapped inside getRecord due to workspaces.
+
                                        // Add the root of the mount to ->tree
-                               $this->tree[]=array('HTML'=>$firstHtml,'row'=>$rootRec,'bank'=>$this->bank);
+                               $this->tree[] = array('HTML' => $firstHtml, 'row' => $rootRec, 'bank' => $this->bank);
 
                                        // If the mount is expanded, go down:
-                               if ($isOpen)    {
+                               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);
+                                       $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);
+                               $treeArr = array_merge($treeArr, $this->tree);
                        }
                }
                return $this->printTree($treeArr);
@@ -404,10 +340,12 @@ class t3lib_treeView {
         * @param       array           "tree-array" - if blank string, the internal ->tree array is used.
         * @return      string          The HTML code for the tree
         */
-       function printTree($treeArr='') {
-               $titleLen=intval($this->BE_USER->uc['titleLen']);
-               if (!is_array($treeArr))        $treeArr=$this->tree;
-               $out='';
+       function printTree($treeArr = '') {
+               $titleLen = intval($this->BE_USER->uc['titleLen']);
+               if (!is_array($treeArr)) {
+                       $treeArr = $this->tree;
+               }
+               $out = '';
 
                        // put a table around it with IDs to access the rows from JS
                        // not a problem if you don't need it
@@ -419,13 +357,15 @@ class t3lib_treeView {
                        -->
                        <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.='
+               foreach ($treeArr as $k => $v) {
+                       $idAttr = htmlspecialchars($this->domIdPrefix . $this->getId($v['row']) . '_' . $v['bank']);
+
+                       $out .= '
                                <tr>
-                                       <td id="'.$idAttr.'">'.
-                                               $v['HTML'].
-                                               $this->wrapTitle($this->getTitleStr($v['row'],$titleLen),$v['row'],$v['bank']).
+                                       <td id="' . $idAttr . '"' .
+                                       ($v['row']['_CSSCLASS'] ? ' class="' . $v['row']['_CSSCLASS'] . '"' : '') . '>' .
+                                       $v['HTML'] .
+                                       $this->wrapTitle($this->getTitleStr($v['row'], $titleLen), $v['row'], $v['bank']) .
                                        '</td>
                                </tr>
                        ';
@@ -436,7 +376,6 @@ class t3lib_treeView {
        }
 
 
-
        /*******************************************
         *
         * rendering parts
@@ -444,7 +383,6 @@ class t3lib_treeView {
         *******************************************/
 
 
-
        /**
         * Generate the plus/minus icon for the browsable tree.
         *
@@ -457,15 +395,15 @@ class t3lib_treeView {
         * @access private
         * @see t3lib_pageTree::PMicon()
         */
-       function PMicon($row,$a,$c,$nextCount,$exp)     {
-               $PM = $nextCount ? ($exp?'minus':'plus') : 'join';
-               $BTM = ($a==$c)?'bottom':'';
-               $icon = '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.$PM.$BTM.'.gif','width="18" height="16"').' alt="" />';
-
-               if ($nextCount) {
-                       $cmd=$this->bank.'_'.($exp?'0_':'1_').$row['uid'].'_'.$this->treeName;
-                       $bMark=($this->bank.'_'.$row['uid']);
-                       $icon = $this->PM_ATagWrap($icon,$cmd,$bMark);
+       function PMicon($row, $a, $c, $nextCount, $exp) {
+               $PM = $nextCount ? ($exp ? 'minus' : 'plus') : 'join';
+               $BTM = ($a == $c) ? 'bottom' : '';
+               $icon = '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/ol/' . $PM . $BTM . '.gif', 'width="18" height="16"') . ' alt="" />';
+
+               if ($nextCount) {
+                       $cmd = $this->bank . '_' . ($exp ? '0_' : '1_') . $row['uid'] . '_' . $this->treeName;
+                       $bMark = ($this->bank . '_' . $row['uid']);
+                       $icon = $this->PM_ATagWrap($icon, $cmd, $bMark);
                }
                return $icon;
        }
@@ -479,14 +417,14 @@ class t3lib_treeView {
         * @return      string          Link-wrapped input string
         * @access private
         */
-       function PM_ATagWrap($icon,$cmd,$bMark='')      {
+       function PM_ATagWrap($icon, $cmd, $bMark = '') {
                if ($this->thisScript) {
-                       if ($bMark)     {
-                               $anchor = '#'.$bMark;
-                               $name=' name="'.$bMark.'"';
+                       if ($bMark) {
+                               $anchor = '#' . $bMark;
+                               $name = ' name="' . $bMark . '"';
                        }
-                       $aUrl = $this->thisScript.'?PM='.$cmd.$anchor;
-                       return '<a href="'.htmlspecialchars($aUrl).'"'.$name.'>'.$icon.'</a>';
+                       $aUrl = $this->thisScript . '?PM=' . $cmd . $anchor;
+                       return '<a href="' . htmlspecialchars($aUrl) . '"' . $name . '>' . $icon . '</a>';
                } else {
                        return $icon;
                }
@@ -501,9 +439,9 @@ class t3lib_treeView {
         * @return      string
         * @access private
         */
-       function wrapTitle($title,$row,$bank=0) {
-               $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix.$this->getId($row).'_'.$bank.'\');';
-               return '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$title.'</a>';
+       function wrapTitle($title, $row, $bank = 0) {
+               $aOnClick = 'return jumpTo(\'' . $this->getJumpToParam($row) . '\',this,\'' . $this->domIdPrefix . $this->getId($row) . '\',' . $bank . ');';
+               return '<a href="#" onclick="' . htmlspecialchars($aOnClick) . '">' . $title . '</a>';
        }
 
        /**
@@ -514,7 +452,7 @@ class t3lib_treeView {
         * @return      string          The processed icon input value.
         * @access private
         */
-       function wrapIcon($icon,$row)   {
+       function wrapIcon($icon, $row) {
                return $icon;
        }
 
@@ -525,8 +463,8 @@ class t3lib_treeView {
         * @param       string          Attributes to add, eg. ' border="0"'
         * @return      string          Image tag, modified with $attr attributes added.
         */
-       function addTagAttributes($icon,$attr)  {
-               return ereg_replace(' ?\/?>$','',$icon).' '.$attr.' />';
+       function addTagAttributes($icon, $attr) {
+               return preg_replace('/ ?\/?>$/', '', $icon) . ' ' . $attr . ' />';
        }
 
        /**
@@ -537,18 +475,14 @@ class t3lib_treeView {
         * @return      string          Modified string
         * @access private
         */
-       function wrapStop($str,$row)    {
-               if ($row['php_tree_stop'])      {
-                       $str.='<span class="typo3-red">+ </span>';
+       function wrapStop($str, $row) {
+               if ($row['php_tree_stop']) {
+                       $str .= '<span class="typo3-red"><a href="' . htmlspecialchars(t3lib_div::linkThisScript(array('setTempDBmount' => $row['uid']))) . '" class="typo3-red">+</a> </span>';
                }
                return $str;
        }
 
 
-
-
-
-
        /*******************************************
         *
         * tree handling
@@ -557,7 +491,7 @@ class t3lib_treeView {
 
 
        /**
-        * Returns true/false if the next level for $id should be expanded - based on data in $this->stored[][] and ->expandAll flag.
+        * Returns TRUE/FALSE if the next level for $id should be expanded - based on data in $this->stored[][] and ->expandAll flag.
         * Extending parent function
         *
         * @param       integer         record id/key
@@ -565,8 +499,8 @@ class t3lib_treeView {
         * @access private
         * @see t3lib_pageTree::expandNext()
         */
-       function expandNext($id)        {
-               return ($this->stored[$this->bank][$id] || $this->expandAll)? 1 : 0;
+       function expandNext($id) {
+               return ($this->stored[$this->bank][$id] || $this->expandAll) ? 1 : 0;
        }
 
        /**
@@ -575,19 +509,19 @@ class t3lib_treeView {
         * @return      void
         * @access private
         */
-       function initializePositionSaving()     {
+       function initializePositionSaving() {
                        // Get stored tree structure:
-               $this->stored=unserialize($this->BE_USER->uc['browseTrees'][$this->treeName]);
+               $this->stored = unserialize($this->BE_USER->uc['browseTrees'][$this->treeName]);
 
                        // PM action
                        // (If an plus/minus icon has been clicked, the PM GET var is sent and we must update the stored positions in the tree):
-               $PM = explode('_',t3lib_div::_GP('PM'));        // 0: mount key, 1: set/clear boolean, 2: item ID (cannot contain "_"), 3: treeName
-               if (count($PM)==4 && $PM[3]==$this->treeName)   {
-                       if (isset($this->MOUNTS[$PM[0]]))       {
-                               if ($PM[1])     {       // set
-                                       $this->stored[$PM[0]][$PM[2]]=1;
+               $PM = explode('_', t3lib_div::_GP('PM')); // 0: mount key, 1: set/clear boolean, 2: item ID (cannot contain "_"), 3: treeName
+               if (count($PM) == 4 && $PM[3] == $this->treeName) {
+                       if (isset($this->MOUNTS[$PM[0]])) {
+                               if ($PM[1]) { // set
+                                       $this->stored[$PM[0]][$PM[2]] = 1;
                                        $this->savePosition();
-                               } else {        // clear
+                               } else { // clear
                                        unset($this->stored[$PM[0]][$PM[2]]);
                                        $this->savePosition();
                                }
@@ -602,23 +536,12 @@ class t3lib_treeView {
         * @return      void
         * @access private
         */
-       function savePosition() {
+       function savePosition() {
                $this->BE_USER->uc['browseTrees'][$this->treeName] = serialize($this->stored);
                $this->BE_USER->writeUC();
        }
 
 
-
-
-
-
-
-
-
-
-
-
-
        /******************************
         *
         * Functions that might be overwritten by extended classes
@@ -632,11 +555,10 @@ 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);
        }
 
 
-
        /**
         * Get icon for the row.
         * If $this->iconPath and $this->iconName is set, try to get icon based on those values.
@@ -646,25 +568,39 @@ 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);
+               return $this->wrapIcon($icon, $row);
        }
 
 
        /**
-        * 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)
         * @param       integer         Title length (30)
         * @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_cs($row['title'],$titleLen));
+       function getTitleStr($row, $titleLen = 30) {
+               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;
        }
 
@@ -700,19 +636,6 @@ class t3lib_treeView {
        }
 
 
-
-
-
-
-
-
-
-
-
-
-
-
-
        /********************************
         *
         * tree data buidling
@@ -726,91 +649,94 @@ 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();
-
+               $this->buffer_idH = array();
 
                        // Init vars
-               $depth=intval($depth);
-               $HTML='';
-               $a=0;
+               $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'];
-                       $this->tree[]=array();          // Reserve space.
+                       $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.', 1294586383);
+                       }
+
+                       $this->tree[] = array(); // Reserve space.
                        end($this->tree);
-                       $treeKey = key($this->tree);    // Get the key for this space
-                       $LN = ($a==$c)?'blank':'line';
+                       $treeKey = key($this->tree); // Get the key for this space
+                       $LN = ($a == $c) ? 'blank' : 'line';
 
                                // If records should be accumulated, do so
-                       if ($this->setRecs)     {
+                       if ($this->setRecs) {
                                $this->recs[$row['uid']] = $row;
                        }
 
                                // 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
-                       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
-                                       );
-                               if (count($this->buffer_idH))   $idH[$row['uid']]['subrow']=$this->buffer_idH;
-                               $exp=1; // Set "did expand" flag
+                       $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 ? $HTML_depthData : '',
+                                       $blankLineCode . ',' . $LN,
+                                       $row['_SUBCSSCLASS']
+                               );
+                               if (count($this->buffer_idH)) {
+                                       $idH[$row['uid']]['subrow'] = $this->buffer_idH;
+                               }
+                               $exp = 1; // Set "did expand" flag
                        } else {
-                               $nextCount=$this->getCount($newID);
-                               $exp=0; // Clear "did expand" flag
+                               $nextCount = $this->getCount($newID);
+                               $exp = 0; // Clear "did expand" flag
                        }
 
                                // Set HTML-icons, if any:
-                       if ($this->makeHTML)    {
-                               $HTML = $depthData.$this->PMicon($row,$a,$c,$nextCount,$exp);
-                               $HTML.=$this->wrapStop($this->getIcon($row),$row);
+                       if ($this->makeHTML) {
+                               $HTML = $depthData . $this->PMicon($row, $a, $c, $nextCount, $exp);
+                               $HTML .= $this->wrapStop($this->getIcon($row), $row);
                                #       $HTML.=$this->wrapStop($this->wrapIcon($this->getIcon($row),$row),$row);
                        }
 
                                // Finally, add the row/HTML content to the ->tree array in the reserved key.
-                       $this->tree[$treeKey] = Array(
-                               'row'=>$row,
-                               'HTML'=>$HTML,
-                               'invertedDepth'=>$depth,
-                               'blankLineCode'=>$blankLineCode,
+                       $this->tree[$treeKey] = array(
+                               'row' => $row,
+                               'HTML' => $HTML,
+                               'HTML_depthData' => $this->makeHTML == 2 ? $HTML_depthData : '',
+                               'invertedDepth' => $depth,
+                               'blankLineCode' => $blankLineCode,
                                'bank' => $this->bank
                        );
                }
 
                $this->getDataFree($res);
-               $this->buffer_idH=$idH;
+               $this->buffer_idH = $idH;
                return $c;
        }
 
 
-
-
-
-
-
-
-
-
-
-
        /********************************
         *
         * Data handling
@@ -825,27 +751,23 @@ class t3lib_treeView {
         * @return      integer
         * @access private
         */
-       function getCount($uid) {
+       function getCount($uid) {
                if (is_array($this->data)) {
                        $res = $this->getDataInit($uid);
                        return $this->getDataCount($res);
                } else {
-                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
-                                               'count(*)',
-                                               $this->table,
-                                               $this->parentField.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($uid, $this->table).
-                                                       t3lib_BEfunc::deleteClause($this->table).
-                                                       $this->clause,  // whereClauseMightContainGroupOrderBy
-                                               '',
-                                               '' //$this->orderByFields // sorting is senseless for count(*) !?!
-                                       );
-                       $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
+                       );
                }
        }
 
 
-
        /**
         * Returns root record for uid (<=0)
         *
@@ -853,7 +775,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);
        }
 
 
@@ -869,7 +791,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);
                }
        }
 
@@ -879,10 +801,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;
@@ -892,14 +815,15 @@ class t3lib_treeView {
                        return $parentId;
                } else {
                        $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
-                                               implode(',',$this->fieldArray),
-                                               $this->table,
-                                               $this->parentField.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($parentId, $this->table).
-                                                       t3lib_BEfunc::deleteClause($this->table).
-                                                       $this->clause,  // whereClauseMightContainGroupOrderBy
-                                               '',
-                                               $this->orderByFields
-                                       );
+                               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
+                       );
                        return $res;
                }
        }
@@ -925,28 +849,48 @@ 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;
+                       if ($res < 0) {
+                               $row = FALSE;
                        } else {
-                               list(,$row) = each($this->dataLookup[$res][$this->subLevelID]);
+                               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;
                }
        }
 
@@ -957,10 +901,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);
                }
        }
@@ -977,24 +919,24 @@ class t3lib_treeView {
         * @param       integer         Internal, for recursion.
         * @return      void
         */
-       function setDataFromArray(&$dataArr,$traverse=FALSE,$pid=0)     {
+       function setDataFromArray(&$dataArr, $traverse = FALSE, $pid = 0) {
                if (!$traverse) {
                        $this->data = &$dataArr;
-                       $this->dataLookup=array();
+                       $this->dataLookup = array();
                                // add root
-                       $this->dataLookup[0][$this->subLevelID]=&$dataArr;
+                       $this->dataLookup[0][$this->subLevelID] =& $dataArr;
                }
 
-               foreach($dataArr as $uid => $val)       {
+               foreach ($dataArr as $uid => $val) {
 
-                       $dataArr[$uid]['uid']=$uid;
-                       $dataArr[$uid]['pid']=$pid;
+                       $dataArr[$uid]['uid'] = $uid;
+                       $dataArr[$uid]['pid'] = $pid;
 
                                // gives quick access to id's
                        $this->dataLookup[$uid] = &$dataArr[$uid];
 
                        if (is_array($val[$this->subLevelID])) {
-                               $this->setDataFromArray($dataArr[$uid][$this->subLevelID],TRUE,$uid);
+                               $this->setDataFromArray($dataArr[$uid][$this->subLevelID], TRUE, $uid);
                        }
                }
        }
@@ -1006,9 +948,9 @@ class t3lib_treeView {
         * @param       array           Content for $this->dataLookup
         * @return      void
         */
-       function setDataFromTreeArray(&$treeArr, &$treeLookupArr)       {
+       function setDataFromTreeArray(&$treeArr, &$treeLookupArr) {
                $this->data = &$treeArr;
-               $this->dataLookup=&$treeLookupArr;
+               $this->dataLookup =& $treeLookupArr;
        }
 
 
@@ -1051,7 +993,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']);
+if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_treeview.php'])) {
+       include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_treeview.php']);
 }
-?>
+
+?>
\ No newline at end of file