Fixed bug #15383: [Unit tests] Add tests for t3lib_div::validEmail
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_foldertree.php
old mode 100755 (executable)
new mode 100644 (file)
index 2613b2c..5230d76
@@ -1,22 +1,22 @@
 <?php
 /***************************************************************
 *  Copyright notice
-*  
-*  (c) 1999-2002 Kasper Skaarhoj (kasper@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 
+*  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
@@ -30,7 +30,7 @@
  * $Id$
  * Revised for TYPO3 3.6 November/2003 by Kasper Skaarhoj
  *
- * @author     Kasper Skaarhoj <kasper@typo3.com>
+ * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
  * @coauthor   RenĂ© Fritz <r.fritz@colorcube.de>
  */
 /**
  *
  *
  *
- *   82: class t3lib_folderTree extends t3lib_treeView  
- *   89:     function t3lib_folderTree()       
- *  108:     function wrapTitle($title,$row)   
- *  121:     function wrapIcon($icon,$row)     
- *  141:     function getId($v) 
- *  151:     function getJumpToParm($v) 
- *  163:     function getTitleStr($row,$titleLen=30)   
- *  173:     function getBrowsableTree()       
- *  236:     function getFolderTree($files_path, $depth=999, $depthData='')    
- *  315:     function getCount($files_path)    
- *  331:     function initializePositionSaving()       
+ *   82: class t3lib_folderTree extends t3lib_treeView
+ *   89:     function t3lib_folderTree()
+ *  107:     function wrapIcon($icon,$row)
+ *  130:     function wrapTitle($title,$row,$bank=0)
+ *  145:     function getId($v)
+ *  155:     function getJumpToParam($v)
+ *  167:     function getTitleStr($row,$titleLen=30)
+ *  177:     function getBrowsableTree()
+ *  240:     function getFolderTree($files_path, $depth=999, $depthData='')
+ *  320:     function getCount($files_path)
+ *  336:     function initializePositionSaving()
  *
  * TOTAL FUNCTIONS: 10
  * (This index is automatically created/updated by the extension "extdeveval")
  *
  */
 
-require_once (PATH_t3lib.'class.t3lib_treeview.php');
 
 
 
@@ -72,8 +71,8 @@ require_once (PATH_t3lib.'class.t3lib_treeview.php');
 
 /**
  * Extension class for the t3lib_treeView class, specially made for browsing folders in the File module
- * 
- * @author     Kasper Skaarhoj <kasper@typo3.com>
+ *
+ * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
  * @coauthor   RenĂ© Fritz <r.fritz@colorcube.de>
  * @package TYPO3
  * @subpackage t3lib
@@ -83,8 +82,8 @@ class t3lib_folderTree extends t3lib_treeView  {
 
        /**
         * Constructor function of the class
-        * 
-        * @return      void            
+        *
+        * @return      void
         */
        function t3lib_folderTree()     {
                parent::init();
@@ -95,10 +94,10 @@ class t3lib_folderTree extends t3lib_treeView  {
                $this->titleAttrib=''; //don't apply any title
                $this->domIdPrefix = 'folder';
        }
-       
+
        /**
         * Wrapping the folder icon
-        * 
+        *
         * @param       string          The image tag for the icon
         * @param       array           The row for the current element
         * @return      string          The processed icon input value.
@@ -112,36 +111,54 @@ class t3lib_folderTree extends t3lib_treeView  {
                if (!$this->ext_IconMode)       {
                        $theFolderIcon = $GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon($theFolderIcon,$row['path'],'',0);
                } elseif (!strcmp($this->ext_IconMode,'titlelink'))     {
-                       $aOnClick = 'return jumpTo('.$this->getJumpToParm($row).'\',this,\''.$this->domIdPrefix.$this->getId($row).'_'.$this->bank.'\');';
+                       $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix.$this->getId($row).'\','.$this->bank.');';
                        $theFolderIcon='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$theFolderIcon.'</a>';
                }
                return $theFolderIcon;
        }
 
        /**
+        * Wrapping $title in a-tags.
+        *
+        * @param       string          Title string
+        * @param       string          Item record
+        * @param       integer         Bank pointer (which mount point number)
+        * @return      string
+        * @access private
+        */
+       function wrapTitle($title,$row,$bank=0) {
+               $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix.$this->getId($row).'\','.$bank.');';
+               $CSM = '';
+               if ($GLOBALS['TYPO3_CONF_VARS']['BE']['useOnContextMenuHandler'])       {
+                       $CSM = ' oncontextmenu="'.htmlspecialchars($GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon('',$row['path'],'',0,'','',TRUE)).'"';
+               }
+               return '<a href="#" title="'.htmlspecialchars($row['title']).'" onclick="'.htmlspecialchars($aOnClick).'"'.$CSM.'>'.$title.'</a>';
+       }
+
+       /**
         * Returns the id from the record - for folders, this is an md5 hash.
-        * 
+        *
         * @param       array           Record array
         * @return      integer         The "uid" field value.
         */
-       function getId($v) {
+       function getId($v)      {
                return t3lib_div::md5Int($v['path']);
        }
 
        /**
         * Returns jump-url parameter value.
-        * 
+        *
         * @param       array           The record array.
         * @return      string          The jump-url parameter.
         */
-       function getJumpToParm($v) {
-               return "'".rawurlencode($v['path'])."'";
+       function getJumpToParam($v)     {
+               return rawurlencode($v['path']);
        }
 
        /**
-        * 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" labele (localized) will be returned.
         * '_title' is used for setting an alternative title for folders.
-        * 
+        *
         * @param       array           The input row array (where the key "_title" is used for the title)
         * @param       integer         Title length (30)
         * @return      string          The title.
@@ -153,7 +170,7 @@ class t3lib_folderTree extends t3lib_treeView  {
        /**
         * Will create and return the HTML code for a browsable tree of folders.
         * Is based on the mounts found in the internal array ->MOUNTS (set in the constructor)
-        * 
+        *
         * @return      string          HTML code for the browsable tree
         */
        function getBrowsableTree()     {
@@ -181,10 +198,19 @@ class t3lib_folderTree extends t3lib_treeView  {
                        $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);
 
-                       switch($val['type'])    {
-                               case 'user':    $icon = 'gfx/i/_icon_ftp_user.gif';     break;
-                               case 'group':   $icon = 'gfx/i/_icon_ftp_group.gif'; break;
-                               default:                $icon = 'gfx/i/_icon_ftp.gif'; break;
+                       switch ($val['type']) {
+                               case 'user':
+                                       $icon = 'gfx/i/_icon_ftp_user.gif';
+                                       break;
+                               case 'group':
+                                       $icon = 'gfx/i/_icon_ftp_group.gif';
+                                       break;
+                               case 'readonly':
+                                       $icon = 'gfx/i/_icon_ftp_readonly.gif';
+                                       break;
+                               default:
+                                       $icon = 'gfx/i/_icon_ftp.gif';
+                                       break;
                        }
 
                                // Preparing rootRec for the mount
@@ -193,7 +219,7 @@ class t3lib_folderTree extends t3lib_treeView  {
                                $row['path']=$val['path'];
                                $row['uid']=$specUID;
                                $row['title']=$val['name'];
-                               
+
                                // Add the root of the mount to ->tree
                        $this->tree[]=array('HTML'=>$firstHtml,'row'=>$row,'bank'=>$this->bank);
 
@@ -201,7 +227,7 @@ class t3lib_folderTree extends t3lib_treeView  {
                        if ($isOpen)    {
                                        // Set depth:
                                $depthD='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/blank.gif','width="18" height="16"').' alt="" />';
-                               $this->getFolderTree($val['path'],999,$depthD);
+                               $this->getFolderTree($val['path'], 999, $depthD, $val['type']);
                        }
 
                                // Add tree:
@@ -212,14 +238,14 @@ class t3lib_folderTree extends t3lib_treeView  {
 
        /**
         * Fetches the data for the tree
-        * 
+        *
         * @param       string          Abs file path
         * @param       integer         Max depth (recursivity limit)
         * @param       string          HTML-code prefix for recursive calls.
         * @return      integer         The count of items on the level
         * @see getBrowsableTree()
         */
-       function getFolderTree($files_path, $depth=999, $depthData='' {
+       function getFolderTree($files_path, $depth=999, $depthData='', $type='') {
 
                        // This generates the directory tree
                $dirs = t3lib_div::get_dirs($files_path);
@@ -239,7 +265,7 @@ class t3lib_folderTree extends t3lib_treeView  {
                                $treeKey = key($this->tree);    // Get the key for this space
                                $LN = ($a==$c)?'blank':'line';
 
-                               $val = ereg_replace('^\./','',$val);
+                               $val = preg_replace('/^\.\//','',$val);
                                $title = $val;
                                $path = $files_path.$val.'/';
                                $webpath=t3lib_BEfunc::getPathType_web_nonweb($path);
@@ -254,37 +280,38 @@ class t3lib_folderTree extends t3lib_treeView  {
 
                                if ($depth>1 && $this->expandNext($specUID))    {
                                        $nextCount=$this->getFolderTree(
-                                               $path, 
-                                               $depth-1, 
-                                               $this->makeHTML ? $depthData.'<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.$LN.'.gif','width="18" height="16"').' alt="" />' : ''
+                                               $path,
+                                               $depth-1,
+                                               $this->makeHTML ? $depthData.'<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.$LN.'.gif','width="18" height="16"').' alt="" />' : '',
+                                               $type
                                        );
                                        $exp=1;         // Set "did expand" flag
                                } else {
                                        $nextCount=$this->getCount($path);
                                        $exp=0;         // Clear "did expand" flag
                                }
-       
+
                                        // Set HTML-icons, if any:
                                if ($this->makeHTML)    {
                                        $HTML=$depthData.$this->PMicon($row,$a,$c,$nextCount,$exp);
 
-                                       $icon = 'gfx/i/_icon_'.$webpath.'folders.gif';
+                                       $icon = 'gfx/i/_icon_' .$webpath . 'folders' . ($type == 'readonly' ? '_ro' : '') . '.gif';
                                        if ($val=='_temp_')     {
                                                $icon = 'gfx/i/sysf.gif';
-                                               $row['title']='TEMP';
-                                               $row['_title']='<b>TEMP</b>';
+                                               $row['title'] = $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_mod_file_list.xml:temp', true);
+                                               $row['_title'] = '<strong>' . $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_mod_file_list.xml:temp', true) . '</strong>';
                                        }
                                        if ($val=='_recycler_') {
                                                $icon = 'gfx/i/recycler.gif';
-                                               $row['title']='RECYCLER';
-                                               $row['_title']='<b>RECYCLER</b>';
+                                               $row['title'] = $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_mod_file_list.xml:recycler', true);
+                                               $row['_title'] = '<strong>' . $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_mod_file_list.xml:recycler', true) . '</strong>';
                                        }
                                        $HTML.=$this->wrapIcon('<img'.t3lib_iconWorks::skinImg($this->backPath,$icon,'width="18" height="16"').' alt="" />',$row);
                                }
 
                                        // Finally, add the row/HTML content to the ->tree array in the reserved key.
                                $this->tree[$treeKey] = Array(
-                                       'row'=>$row, 
+                                       'row'=>$row,
                                        'HTML'=>$HTML,
                                        'bank'=>$this->bank
                                );
@@ -295,9 +322,9 @@ class t3lib_folderTree extends t3lib_treeView  {
 
        /**
         * Counts the number of directories in a file path.
-        * 
+        *
         * @param       string          File path.
-        * @return      integer         
+        * @return      integer
         */
        function getCount($files_path)  {
                        // This generates the directory tree
@@ -308,11 +335,11 @@ class t3lib_folderTree extends t3lib_treeView  {
                }
                return $c;
        }
-       
+
        /**
         * Get stored tree structure AND updating it if needed according to incoming PM GET var.
-        * 
-        * @return      void            
+        *
+        * @return      void
         * @access private
         */
        function initializePositionSaving()     {
@@ -329,7 +356,7 @@ class t3lib_folderTree extends t3lib_treeView  {
 
                        // 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::GPvar('PM'));      // 0: mount key, 1: set/clear boolean, 2: item ID (cannot contain "_"), 3: treeName
+               $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[$hashMap[$PM[0]]]))     {
                                if ($PM[1])     {       // set
@@ -341,10 +368,11 @@ class t3lib_folderTree extends t3lib_treeView  {
                                }
                        }
                }
-       }       
+       }
 }
+
 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_foldertree.php'])       {
        include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_foldertree.php']);
 }
+
 ?>
\ No newline at end of file