Fixed bug #14050: CleanUp - CGL format of t3lib files - t3lib_foldertree
authorSteffen Kamper <info@sk-typo3.de>
Wed, 24 Nov 2010 10:47:36 +0000 (10:47 +0000)
committerSteffen Kamper <info@sk-typo3.de>
Wed, 24 Nov 2010 10:47:36 +0000 (10:47 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@9541 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_foldertree.php

index ec2ebcc..3d47362 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
 2010-11-24  Steffen Kamper  <steffen@typo3.org>
 
+       * Fixed bug #14050: CleanUp - CGL format of t3lib files - t3lib_foldertree
        * Fixed bug #14050: CleanUp - CGL format of t3lib files - t3lib_flexformtools
        * Fixed bug #14050: CleanUp - CGL format of t3lib files - t3lib_flashmessagequeue
        * Fixed bug #14050: CleanUp - CGL format of t3lib files - t3lib_flashmessage
index f153173..7fba756 100644 (file)
@@ -1,29 +1,29 @@
 <?php
 /***************************************************************
-*  Copyright notice
-*
-*  (c) 1999-2010 Kasper Skårhøj (kasperYYYY@typo3.com)
-*  All rights reserved
-*
-*  This script is part of the TYPO3 project. The TYPO3 project is
-*  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!
-***************************************************************/
+ *  Copyright notice
+ *
+ *  (c) 1999-2010 Kasper Skårhøj (kasperYYYY@typo3.com)
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  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!
+ ***************************************************************/
 /**
  * Generate a folder tree
  *
  *
  *
  *   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()
+ *   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")
  */
 
 
-
-
-
-
-
-
-
-
-
-
-
-
-
 /**
  * Extension class for the t3lib_treeView class, specially made for browsing folders in the File module
  *
  * @subpackage t3lib
  * @see class t3lib_treeView
  */
-class t3lib_folderTree extends t3lib_treeView  {
+class t3lib_folderTree extends t3lib_treeView {
 
        /**
         * Constructor function of the class
         *
         * @return      void
         */
-       function t3lib_folderTree()     {
+       function t3lib_folderTree() {
                parent::init();
 
                $this->MOUNTS = $GLOBALS['FILEMOUNTS'];
 
-               $this->treeName='folder';
-               $this->titleAttrib=''; //don't apply any title
+               $this->treeName = 'folder';
+               $this->titleAttrib = ''; //don't apply any title
                $this->domIdPrefix = 'folder';
        }
 
@@ -103,16 +90,16 @@ class t3lib_folderTree extends t3lib_treeView  {
         * @return      string          The processed icon input value.
         * @access private
         */
-       function wrapIcon($icon,$row)   {
+       function wrapIcon($icon, $row) {
                        // Add title attribute to input icon tag
-               $theFolderIcon = $this->addTagAttributes($icon,($this->titleAttrib ? $this->titleAttrib.'="'.$this->getTitleAttrib($row).'"' : ''));
+               $theFolderIcon = $this->addTagAttributes($icon, ($this->titleAttrib ? $this->titleAttrib . '="' . $this->getTitleAttrib($row) . '"' : ''));
 
                        // Wrap icon in click-menu link.
-               if (!$this->ext_IconMode)       {
-                       $theFolderIcon = $GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon($theFolderIcon,$row['path'],'',0);
-               } elseif (!strcmp($this->ext_IconMode,'titlelink'))     {
-                       $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix.$this->getId($row).'\','.$this->bank.');';
-                       $theFolderIcon='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$theFolderIcon.'</a>';
+               if (!$this->ext_IconMode) {
+                       $theFolderIcon = $GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon($theFolderIcon, $row['path'], '', 0);
+               } elseif (!strcmp($this->ext_IconMode, 'titlelink')) {
+                       $aOnClick = 'return jumpTo(\'' . $this->getJumpToParam($row) . '\',this,\'' . $this->domIdPrefix . $this->getId($row) . '\',' . $this->bank . ');';
+                       $theFolderIcon = '<a href="#" onclick="' . htmlspecialchars($aOnClick) . '">' . $theFolderIcon . '</a>';
                }
                return $theFolderIcon;
        }
@@ -126,13 +113,13 @@ class t3lib_folderTree extends 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.');';
+       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)).'"';
+               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>';
+               return '<a href="#" title="' . htmlspecialchars($row['title']) . '" onclick="' . htmlspecialchars($aOnClick) . '"' . $CSM . '>' . $title . '</a>';
        }
 
        /**
@@ -141,7 +128,7 @@ class t3lib_folderTree extends t3lib_treeView  {
         * @param       array           Record array
         * @return      integer         The "uid" field value.
         */
-       function getId($v)      {
+       function getId($v) {
                return t3lib_div::md5Int($v['path']);
        }
 
@@ -151,7 +138,7 @@ class t3lib_folderTree extends t3lib_treeView  {
         * @param       array           The record array.
         * @return      string          The jump-url parameter.
         */
-       function getJumpToParam($v)     {
+       function getJumpToParam($v) {
                return rawurlencode($v['path']);
        }
 
@@ -163,8 +150,8 @@ class t3lib_folderTree extends t3lib_treeView  {
         * @param       integer         Title length (30)
         * @return      string          The title.
         */
-       function getTitleStr($row,$titleLen=30) {
-               return $row['_title'] ? $row['_title'] : parent::getTitleStr($row,$titleLen);
+       function getTitleStr($row, $titleLen = 30) {
+               return $row['_title'] ? $row['_title'] : parent::getTitleStr($row, $titleLen);
        }
 
        /**
@@ -173,65 +160,65 @@ class t3lib_folderTree extends 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 $key => $val)  {
+               foreach ($this->MOUNTS as $key => $val) {
                        $md5_uid = md5($val['path']);
-                       $specUID=hexdec(substr($md5_uid,0,6));
-                       $this->specUIDmap[$specUID]=$val['path'];
+                       $specUID = hexdec(substr($md5_uid, 0, 6));
+                       $this->specUIDmap[$specUID] = $val['path'];
 
                                // Set first:
-                       $this->bank=$val['nkey'];
+                       $this->bank = $val['nkey'];
                        $isOpen = $this->stored[$val['nkey']][$specUID] || $this->expandFirst;
                        $this->reset();
 
                                // Set PM icon:
-                       $cmd=$this->bank.'_'.($isOpen?'0_':'1_').$specUID.'_'.$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_') . $specUID . '_' . $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);
 
                        switch ($val['type']) {
                                case 'user':
                                        $icon = 'gfx/i/_icon_ftp_user.gif';
-                                       break;
+                               break;
                                case 'group':
                                        $icon = 'gfx/i/_icon_ftp_group.gif';
-                                       break;
+                               break;
                                case 'readonly':
                                        $icon = 'gfx/i/_icon_ftp_readonly.gif';
-                                       break;
+                               break;
                                default:
                                        $icon = 'gfx/i/_icon_ftp.gif';
-                                       break;
+                               break;
                        }
 
                                // Preparing rootRec for the mount
-                       $firstHtml.=$this->wrapIcon('<img'.t3lib_iconWorks::skinImg($this->backPath,$icon,'width="18" height="16"').' alt="" />',$val);
-                               $row=array();
-                               $row['path']=$val['path'];
-                               $row['uid']=$specUID;
-                               $row['title']=$val['name'];
+                       $firstHtml .= $this->wrapIcon('<img' . t3lib_iconWorks::skinImg($this->backPath, $icon, 'width="18" height="16"') . ' alt="" />', $val);
+                       $row = array();
+                       $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);
+                       $this->tree[] = array('HTML' => $firstHtml, 'row' => $row, '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="" />';
+                               $depthD = '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/ol/blank.gif', 'width="18" height="16"') . ' alt="" />';
                                $this->getFolderTree($val['path'], 999, $depthD, $val['type']);
                        }
 
                                // Add tree:
-                       $treeArr=array_merge($treeArr,$this->tree);
+                       $treeArr = array_merge($treeArr, $this->tree);
                }
                return $this->printTree($treeArr);
        }
@@ -245,75 +232,75 @@ class t3lib_folderTree extends t3lib_treeView  {
         * @return      integer         The count of items on the level
         * @see getBrowsableTree()
         */
-       function getFolderTree($files_path, $depth=999, $depthData='', $type='') {
+       function getFolderTree($files_path, $depth = 999, $depthData = '', $type = '') {
 
                        // This generates the directory tree
                $dirs = t3lib_div::get_dirs($files_path);
 
-               $c=0;
-               if (is_array($dirs))    {
-                       $depth=intval($depth);
-                       $HTML='';
-                       $a=0;
-                       $c=count($dirs);
+               $c = 0;
+               if (is_array($dirs)) {
+                       $depth = intval($depth);
+                       $HTML = '';
+                       $a = 0;
+                       $c = count($dirs);
                        sort($dirs);
 
-                       foreach($dirs as $key => $val)  {
+                       foreach ($dirs as $key => $val) {
                                $a++;
-                               $this->tree[]=array();          // Reserve space.
+                               $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';
 
-                               $val = preg_replace('/^\.\//','',$val);
+                               $val = preg_replace('/^\.\//', '', $val);
                                $title = $val;
-                               $path = $files_path.$val.'/';
-                               $webpath=t3lib_BEfunc::getPathType_web_nonweb($path);
+                               $path = $files_path . $val . '/';
+                               $webpath = t3lib_BEfunc::getPathType_web_nonweb($path);
 
                                $md5_uid = md5($path);
-                               $specUID=hexdec(substr($md5_uid,0,6));
-                               $this->specUIDmap[$specUID]=$path;
-                               $row=array();
-                               $row['path']=$path;
-                               $row['uid']=$specUID;
-                               $row['title']=$title;
-
-                               if ($depth>1 && $this->expandNext($specUID))    {
-                                       $nextCount=$this->getFolderTree(
+                               $specUID = hexdec(substr($md5_uid, 0, 6));
+                               $this->specUIDmap[$specUID] = $path;
+                               $row = array();
+                               $row['path'] = $path;
+                               $row['uid'] = $specUID;
+                               $row['title'] = $title;
+
+                               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="" />' : '',
+                                                       $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
+                                       $exp = 1; // Set "did expand" flag
                                } else {
-                                       $nextCount=$this->getCount($path);
-                                       $exp=0;         // Clear "did expand" flag
+                                       $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);
+                               if ($this->makeHTML) {
+                                       $HTML = $depthData . $this->PMicon($row, $a, $c, $nextCount, $exp);
 
-                                       $icon = 'gfx/i/_icon_' .$webpath . 'folders' . ($type == 'readonly' ? '_ro' : '') . '.gif';
-                                       if ($val=='_temp_')     {
+                                       $icon = 'gfx/i/_icon_' . $webpath . 'folders' . ($type == 'readonly' ? '_ro' : '') . '.gif';
+                                       if ($val == '_temp_') {
                                                $icon = 'gfx/i/sysf.gif';
-                                               $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>';
+                                               $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_') {
+                                       if ($val == '_recycler_') {
                                                $icon = 'gfx/i/recycler.gif';
-                                               $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>';
+                                               $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);
+                                       $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,
-                                       'HTML'=>$HTML,
-                                       'bank'=>$this->bank
+                                       'row' => $row,
+                                       'HTML' => $HTML,
+                                       'bank' => $this->bank
                                );
                        }
                }
@@ -326,12 +313,12 @@ class t3lib_folderTree extends t3lib_treeView  {
         * @param       string          File path.
         * @return      integer
         */
-       function getCount($files_path)  {
+       function getCount($files_path) {
                        // This generates the directory tree
                $dirs = t3lib_div::get_dirs($files_path);
-               $c=0;
-               if (is_array($dirs))    {
-                       $c=count($dirs);
+               $c = 0;
+               if (is_array($dirs)) {
+                       $c = count($dirs);
                }
                return $c;
        }
@@ -342,27 +329,27 @@ class t3lib_folderTree extends 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]);
 
                        // Mapping md5-hash to shorter number:
-               $hashMap=array();
-               foreach($this->MOUNTS as $key => $val)  {
-                       $nkey = hexdec(substr($key,0,4));
-                       $hashMap[$nkey]=$key;
-                       $this->MOUNTS[$key]['nkey']=$nkey;
+               $hashMap = array();
+               foreach ($this->MOUNTS as $key => $val) {
+                       $nkey = hexdec(substr($key, 0, 4));
+                       $hashMap[$nkey] = $key;
+                       $this->MOUNTS[$key]['nkey'] = $nkey;
                }
 
                        // 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[$hashMap[$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[$hashMap[$PM[0]]])) {
+                               if ($PM[1]) { // set
+                                       $this->stored[$PM[0]][$PM[2]] = 1;
                                        $this->savePosition($this->treeName);
-                               } else {        // clear
+                               } else { // clear
                                        unset($this->stored[$PM[0]][$PM[2]]);
                                        $this->savePosition($this->treeName);
                                }
@@ -371,7 +358,7 @@ class t3lib_folderTree extends t3lib_treeView  {
        }
 }
 
-if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_foldertree.php'])       {
+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']);
 }