Fixed bug #7860: Coloring in TS Object Browser depends on Crop Lines (thanks to Steff...
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_treeview.php
index bf9cad4..5978140 100755 (executable)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
+*  (c) 1999-2008 Kasper Skaarhoj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
  *
  *
  *  115: class t3lib_treeView
  *
  *
  *  115: class t3lib_treeView
- *  267:     function init($clause='', $orderByFields='')
- *  298:     function setTreeName($treeName='')
- *  312:     function addField($field,$noCheck=0)
- *  326:     function reset()
+ *  270:     function init($clause='', $orderByFields='')
+ *  301:     function setTreeName($treeName='')
+ *  315:     function addField($field,$noCheck=0)
+ *  329:     function reset()
  *
  *              SECTION: output
  *
  *              SECTION: output
- *  346:     function getBrowsableTree()
- *  407:     function printTree($treeArr='')
+ *  349:     function getBrowsableTree()
+ *  412:     function printTree($treeArr='')
  *
  *              SECTION: rendering parts
  *
  *              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)
+ *  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
  *
  *              SECTION: tree handling
- *  568:     function expandNext($id)
- *  578:     function initializePositionSaving()
- *  605:     function savePosition()
+ *  575:     function expandNext($id)
+ *  585:     function initializePositionSaving()
+ *  612:     function savePosition()
  *
  *              SECTION: Functions that might be overwritten by extended classes
  *
  *              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)
+ *  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
  *
  *              SECTION: tree data buidling
- *  731:     function getTree($uid, $depth=999, $depthData='',$blankLineCode='')
+ *  739:     function getTree($uid, $depth=999, $depthData='',$blankLineCode='',$subCSSclass='')
  *
  *              SECTION: Data handling
  *
  *              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)
+ *  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")
  *
  * TOTAL FUNCTIONS: 31
  * (This index is automatically created/updated by the extension "extdeveval")
@@ -128,6 +128,8 @@ class t3lib_treeView {
        /**
         * Needs to be initialized with $GLOBALS['BE_USER']
         * Done by default in init()
        /**
         * Needs to be initialized with $GLOBALS['BE_USER']
         * Done by default in init()
+        *
+        * @var t3lib_beUserAuth
         */
        var $BE_USER='';
 
         */
        var $BE_USER='';
 
@@ -238,6 +240,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
                // 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:
        var $buffer_idH = array();              // Temporary, internal array
 
                // For FOLDER trees:
@@ -322,7 +325,7 @@ class t3lib_treeView {
 
 
        /**
 
 
        /**
-        * 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
         */
         *
         * @return      void
         */
@@ -331,6 +334,7 @@ class t3lib_treeView {
                $this->recs = array();
                $this->ids = array();
                $this->ids_hierarchy = array();
                $this->recs = array();
                $this->ids = array();
                $this->ids_hierarchy = array();
+               $this->orig_ids_hierarchy = array();
        }
 
 
        }
 
 
@@ -509,7 +513,7 @@ class t3lib_treeView {
         * @access private
         */
        function wrapTitle($title,$row,$bank=0) {
         * @access private
         */
        function wrapTitle($title,$row,$bank=0) {
-               $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($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>';
        }
 
                return '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$title.'</a>';
        }
 
@@ -663,7 +667,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)
         * 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)
@@ -671,7 +675,16 @@ class t3lib_treeView {
         * @return      string          The title.
         */
        function getTitleStr($row,$titleLen=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));
+               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;
        }
 
                return $title;
        }
 
@@ -741,7 +754,6 @@ class t3lib_treeView {
                        // Buffer for id hierarchy is reset:
                $this->buffer_idH=array();
 
                        // Buffer for id hierarchy is reset:
                $this->buffer_idH=array();
 
-
                        // Init vars
                $depth=intval($depth);
                $HTML='';
                        // Init vars
                $depth=intval($depth);
                $HTML='';
@@ -756,7 +768,13 @@ class t3lib_treeView {
                        $a++;
                        $crazyRecursionLimiter--;
 
                        $a++;
                        $crazyRecursionLimiter--;
 
-                       $newID =$row['uid'];
+                       $newID = $row['uid'];
+
+                       if ($newID==0)  {
+                               t3lib_BEfunc::typo3PrintError ('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.',0);
+                               exit;
+                       }
+
                        $this->tree[]=array();          // Reserve space.
                        end($this->tree);
                        $treeKey = key($this->tree);    // Get the key for this space
                        $this->tree[]=array();          // Reserve space.
                        end($this->tree);
                        $treeKey = key($this->tree);    // Get the key for this space
@@ -768,8 +786,9 @@ class t3lib_treeView {
                        }
 
                                // Accumulate the id of the element in the internal arrays
                        }
 
                                // Accumulate the id of the element in the internal arrays
-                       $this->ids[]=$idH[$row['uid']]['uid'] = $row['uid'];
+                       $this->ids[] = $idH[$row['uid']]['uid'] = $row['uid'];
                        $this->ids_hierarchy[$depth][] = $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="" />';
 
                                // 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="" />';
@@ -891,6 +910,7 @@ class t3lib_treeView {
         * For arrays: This will return key to the ->dataLookup array
         *
         * @param       integer         parent item id
         * 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
         */
         * @return      mixed           data handle (Tables: An sql-resource, arrays: A parentId integer. -1 is returned if there were NO subLevel.)
         * @access private
         */
@@ -938,11 +958,12 @@ class t3lib_treeView {
         * Getting the tree data: next entry
         *
         * @param       mixed           data handle
         * 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()
         */
         * @return      array           item data array OR FALSE if end of elements.
         * @access private
         * @see getDataInit()
         */
-       function getDataNext(&$res,$subCSSclass=''){
+       function getDataNext(&$res,$subCSSclass='')     {
                if (is_array($this->data)) {
                        if ($res<0) {
                                $row=FALSE;
                if (is_array($this->data)) {
                        if ($res<0) {
                                $row=FALSE;
@@ -956,8 +977,10 @@ class t3lib_treeView {
                        }
                        return $row;
                } else {
                        }
                        return $row;
                } else {
-                       $row = @$GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
-                       t3lib_BEfunc::workspaceOL($this->table, $row, $this->BE_USER->workspace);
+                       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!=='')        {
 
                                // Passing on default <td> class for subelements:
                        if (is_array($row) && $subCSSclass!=='')        {