Fixed bug #15383: [Unit tests] Add tests for t3lib_div::validEmail
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_treeview.php
old mode 100755 (executable)
new mode 100644 (file)
index 6acd2b3..d568a07
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
+*  (c) 1999-2010 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
@@ -31,7 +31,7 @@
  * Revised for TYPO3 3.6 November/2003 by Kasper Skaarhoj
  *
  * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
  * Revised for TYPO3 3.6 November/2003 by Kasper Skaarhoj
  *
  * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
- * @coauthor   René Fritz <r.fritz@colorcube.de>
+ * @coauthor   René Fritz <r.fritz@colorcube.de>
  */
 /**
  * [CLASS/FUNCTION INDEX of SCRIPT]
  */
 /**
  * [CLASS/FUNCTION INDEX of SCRIPT]
 
 
 
 
 
 
-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>
 
 
 /**
  * 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>
+ * @coauthor   René Fritz <r.fritz@colorcube.de>
  * @package TYPO3
  * @subpackage t3lib
  * @see t3lib_browsetree, t3lib_pagetree, t3lib_foldertree
  * @package TYPO3
  * @subpackage t3lib
  * @see t3lib_browsetree, t3lib_pagetree, t3lib_foldertree
@@ -128,6 +125,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 +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
                // 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 +322,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 +331,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();
        }
 
 
        }
 
 
@@ -533,7 +534,7 @@ class t3lib_treeView {
         * @return      string          Image tag, modified with $attr attributes added.
         */
        function addTagAttributes($icon,$attr)  {
         * @return      string          Image tag, modified with $attr attributes added.
         */
        function addTagAttributes($icon,$attr)  {
-               return ereg_replace(' ?\/?>$','',$icon).' '.$attr.' />';
+               return preg_replace('/ ?\/?>$/','',$icon).' '.$attr.' />';
        }
 
        /**
        }
 
        /**
@@ -546,7 +547,7 @@ class t3lib_treeView {
         */
        function wrapStop($str,$row)    {
                if ($row['php_tree_stop'])      {
         */
        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;
        }
                }
                return $str;
        }
@@ -639,7 +640,7 @@ class t3lib_treeView {
         * @return      string          Icon image tag.
         */
        function getRootIcon($rec) {
         * @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);
        }
 
 
        }
 
 
@@ -655,7 +656,12 @@ class t3lib_treeView {
                if ($this->iconPath && $this->iconName) {
                        $icon = '<img'.t3lib_iconWorks::skinImg('',$this->iconPath.$this->iconName,'width="18" height="16"').' alt=""'.($this->showDefaultTitleAttribute ? ' title="UID: '.$row['uid'].'"':'').' />';
                } else {
                if ($this->iconPath && $this->iconName) {
                        $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"'.($this->showDefaultTitleAttribute ? ' title="UID: '.$row['uid'].'"':''));
+
+                       $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);
@@ -663,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)
         * 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 +677,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 +756,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='';
@@ -774,8 +788,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="" />';
@@ -847,16 +862,14 @@ class t3lib_treeView {
                        $res = $this->getDataInit($uid);
                        return $this->getDataCount($res);
                } else {
                        $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).
-                                                       t3lib_BEfunc::versioningPlaceholderClause($this->table).
-                                                       $this->clause   // whereClauseMightContainGroupOrderBy
-                                       );
-                       $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
+                       );
                }
        }
 
                }
        }
 
@@ -869,7 +882,7 @@ class t3lib_treeView {
         * @return      array           Array with title/uid keys with values of $this->title/0 (zero)
         */
        function getRootRecord($uid) {
         * @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);
        }
 
 
        }
 
 
@@ -885,9 +898,7 @@ class t3lib_treeView {
                if (is_array($this->data)) {
                        return $this->dataLookup[$uid];
                } else {
                if (is_array($this->data)) {
                        return $this->dataLookup[$uid];
                } else {
-                       $row = t3lib_befunc::getRecordWSOL($this->table,$uid);
-
-                       return $row;
+                       return t3lib_BEfunc::getRecordWSOL($this->table, $uid);
                }
        }
 
                }
        }
 
@@ -964,8 +975,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!=='')        {
@@ -989,10 +1002,8 @@ class t3lib_treeView {
         * @return      void
         * @access private
         */
         * @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);
                }
        }
                        $GLOBALS['TYPO3_DB']->sql_free_result($res);
                }
        }
@@ -1086,4 +1097,5 @@ 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') && $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