Fixed bug 10056: Misspelling english word "guesbooks"
[Packages/TYPO3.CMS.git] / typo3 / class.file_list.inc
index fd87213..51ac0fd 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
@@ -93,6 +93,7 @@ class fileList extends t3lib_recordList {
        var $files = Array();
        var $path = '';
        var $eCounter=0;                                        // Counting the elements no matter what...
        var $files = Array();
        var $path = '';
        var $eCounter=0;                                        // Counting the elements no matter what...
+       var $dirCounter = 0;
        var $totalItems='';
 
        var $CBnames=array();
        var $totalItems='';
 
        var $CBnames=array();
@@ -119,10 +120,13 @@ class fileList extends t3lib_recordList {
                $this->sortRev=$sortRev;
                $this->firstElementNumber=$pointer;
                $this->clipBoard = $clipBoard;
                $this->sortRev=$sortRev;
                $this->firstElementNumber=$pointer;
                $this->clipBoard = $clipBoard;
+                       // setting the maximum length of the filenames to the user's settings or minimum 30 (= $this->fixedL)
+               $this->fixedL = max($this->fixedL, $GLOBALS['BE_USER']->uc['titleLen']);
 
                if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails'])  {
                        $this->thumbScript='gfx/notfound_thumb.gif';
                }
 
                if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails'])  {
                        $this->thumbScript='gfx/notfound_thumb.gif';
                }
+               $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_common.xml');
        }
 
        /**
        }
 
        /**
@@ -138,58 +142,57 @@ class fileList extends t3lib_recordList {
        }
 
        /**
        }
 
        /**
-        * Make the top of the list
+        * Return the buttons used by the file list to include in the top header
         *
         *
-        * @param       string          The path to list.
-        * @return      void
+        * @return      array
         */
         */
-       function writeTop($path)        {
+       function getButtonsAndOtherMarkers($path) {
+
                        // Makes the code for the foldericon in the top
                $path = $GLOBALS['SOBE']->basicFF->is_directory($path); // Cleaning name...
 
                if ($path)      {
                        // Makes the code for the foldericon in the top
                $path = $GLOBALS['SOBE']->basicFF->is_directory($path); // Cleaning name...
 
                if ($path)      {
-                       $out='';
+                       $otherMarkers = array(
+                               'PAGE_ICON' => '',
+                               'TITLE' => '',
+                       );
+
+                       $buttons = array(
+                               'level_up' => '',
+                               'refresh' => '',
+                               'title' => '',
+                               'page_icon' => '',
+                       );
+
                        $theFile = $GLOBALS['SOBE']->basicFF->getTotalFileInfo($path);
                        $theFile = $GLOBALS['SOBE']->basicFF->getTotalFileInfo($path);
-                       $root = $GLOBALS['SOBE']->basicFF->checkPathAgainstMounts($theFile['path']);
-                       $titleCol='path';
-                       $this->fieldArray = Array($titleCol,'up');
 
                        list($title,$icon,$path) =  $this->dirData($theFile);
 
                                // Start compiling the HTML
 
                        list($title,$icon,$path) =  $this->dirData($theFile);
 
                                // Start compiling the HTML
-                       $theData = Array();
-                       $theData[$titleCol] = $this->widthGif;
-
                        $title = $GLOBALS['SOBE']->basicFF->blindPath($path);
                        $title = $GLOBALS['SOBE']->basicFF->blindPath($path);
-                       $theData['up']='<a href="'.htmlspecialchars($this->listURL()).'">'.
-                                       '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/refresh_n.gif','width="14" height="14"').' title="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.reload',1).'" alt="" />'.
-                                       '</a>';
 
 
-                       if ($root)      {
+                               // if this is some subpage under the mount root....
+                       if ($GLOBALS['SOBE']->basicFF->checkPathAgainstMounts($theFile['path'])) {
                                        // The icon with link
                                        // The icon with link
-                               $theIcon = '<img'.t3lib_iconWorks::skinImg($this->backPath,$icon,'width="18" height="16"').' title="'.htmlspecialchars($theFile['file']).'" alt="" />';
-                               if ($this->clickMenus) $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($theIcon,$path);
+                               $otherMarkers['PAGE_ICON'] = '<img'.t3lib_iconWorks::skinImg($this->backPath,$icon,'width="18" height="16"').' title="'.htmlspecialchars($theFile['file']).'" alt="" />';
+                               if ($this->clickMenus) $otherMarkers['PAGE_ICON'] = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($otherMarkers['PAGE_ICON'],$path);
+
+                               $buttons['level_up'] .= $this->linkWrapDir('<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/i/folder_up.gif','width="18" height="16"').' title="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.upOneLevel',1).'" alt="" />',$theFile['path']);
+                               $otherMarkers['TITLE'] .= t3lib_div::fixed_lgd_cs($title,-($this->fixedL+20));  // No HTML specialchars here - HTML like <b> </b> is allowed
 
 
-                               $theData[$titleCol].='<br />'.t3lib_div::fixed_lgd_cs($title,-($this->fixedL+20));      // No HTML specialchars here - HTML like <b> </b> is allowed
-                               $theData['up'].=$this->linkWrapDir('<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/i/folder_up.gif','width="18" height="16"').' title="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.upOneLevel',1).'" alt="" />',$theFile['path']);
+                               // this is the root page
                        } else {
                        } else {
-                                       // root:0
-                               $theIcon='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/i/_icon_ftp.gif','width="18" height="16"').' alt="" />';
-                               $theData[$titleCol].='<br />'.htmlspecialchars(t3lib_div::fixed_lgd_cs($title,-($this->fixedL+20)));
+                               $otherMarkers['PAGE_ICON'] = '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/i/_icon_ftp.gif','width="18" height="16"').' alt="" />';
+                               if ($this->clickMenus) $otherMarkers['PAGE_ICON'] = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($otherMarkers['PAGE_ICON'],$path);
+                               $otherMarkers['TITLE'] .= htmlspecialchars(t3lib_div::fixed_lgd_cs($title,-($this->fixedL+20)));
                        }
                        }
+               }
 
 
-                               // Adding top element
-                       $out.=$this->addelement(1,'',$theData,'','',$theIcon);
-
-                       $this->HTMLcode.='
+               $buttons['refresh'] = '<a href="'.htmlspecialchars($this->listURL()).'">'.
+                               '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/refresh_n.gif','width="14" height="14"').' title="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.reload',1).'" alt="" />'.
+                               '</a>';
 
 
-               <!--
-                       Page header for file list
-               -->
-                               <table border="0" cellpadding="0" cellspacing="0" id="typo3-filelist-top">
-                                       '.$out.'
-                               </table>';
-               }
+               return array($buttons, $otherMarkers);
        }
 
        /**
        }
 
        /**
@@ -227,13 +230,6 @@ class fileList extends t3lib_recordList {
                if ($this->clipBoard)   $rowlist.=',_CLIPBOARD_';
                $this->fieldArray = explode(',',$rowlist);
 
                if ($this->clipBoard)   $rowlist.=',_CLIPBOARD_';
                $this->fieldArray = explode(',',$rowlist);
 
-                       // half line is drawn
-               $theData = Array();
-               $theData[$titleCol] = $this->widthGif;
-               $out.=$this->addelement(0,'',$theData,'');
-
-
-
                        // Directories are added
                $iOut = '';
                $iOut.= $this->formatDirList($dirs);
                        // Directories are added
                $iOut = '';
                $iOut.= $this->formatDirList($dirs);
@@ -242,7 +238,6 @@ class fileList extends t3lib_recordList {
                                // half line is drawn
                        $theData = Array();
                        $theData[$titleCol] = '';
                                // half line is drawn
                        $theData = Array();
                        $theData[$titleCol] = '';
-                       $iOut.=$this->addelement(0,'',$theData);
                }
 
 
                }
 
 
@@ -281,9 +276,6 @@ class fileList extends t3lib_recordList {
                $out.=$iOut;
 
                        // half line is drawn
                $out.=$iOut;
 
                        // half line is drawn
-               $theData = Array();
-               $theData[$titleCol] = $this->counter.' File(s), '.t3lib_div::formatSize($this->totalbytes).'bytes';
-               $out.=$this->addelement(1,'',$theData);
 
                        // finish
                return '
 
                        // finish
                return '
@@ -292,12 +284,26 @@ class fileList extends t3lib_recordList {
                <!--
                        File list table:
                -->
                <!--
                        File list table:
                -->
-                       <table border="0" cellpadding="0" cellspacing="0" id="typo3-filelist">
+                       <table border="0" cellpadding="0" cellspacing="1" id="typo3-filelist">
                                '.$out.'
                        </table>';
        }
 
        /**
                                '.$out.'
                        </table>';
        }
 
        /**
+        * Gets the number of files and total size of a folder
+        *
+        * @return string
+        **/
+       function getFolderInfo() {
+               if($this->counter == 1) {
+                       $fileLabel = $GLOBALS['LANG']->getLL('file', true);
+               } else {
+                       $fileLabel = $GLOBALS['LANG']->getLL('files', true);
+               }
+               return $this->counter . ' ' . $fileLabel . ', ' . t3lib_div::formatSize($this->totalbytes, $GLOBALS['LANG']->getLL('byteSizeUnits', true));
+       }
+
+       /**
         * This returns tablerows for the directories in the array $items['sorting'].
         *
         * @param       array           Directory items
         * This returns tablerows for the directories in the array $items['sorting'].
         *
         * @param       array           Directory items
@@ -306,7 +312,7 @@ class fileList extends t3lib_recordList {
        function formatDirList($items)  {
                $out='';
 
        function formatDirList($items)  {
                $out='';
 
-                       // Files:
+               // Folders:
                if (count($items['sorting']))   {
                        reset($items['sorting']);
                        while (list($key,) = each($items['sorting']))   {
                if (count($items['sorting']))   {
                        reset($items['sorting']);
                        while (list($key,) = each($items['sorting']))   {
@@ -329,13 +335,13 @@ class fileList extends t3lib_recordList {
                                        while(list(,$field)=each($this->fieldArray))    {
                                                switch($field)  {
                                                        case 'size':
                                        while(list(,$field)=each($this->fieldArray))    {
                                                switch($field)  {
                                                        case 'size':
-       //                                                      $theData[$field]=t3lib_div::formatSize($theFile[$field]);
+                                                               $theData[$field] = t3lib_div::formatSize($theFile[$field], $GLOBALS['LANG']->getLL('byteSizeUnits', true));
                                                        break;
                                                        case 'rw':
                                                        break;
                                                        case 'rw':
-                                                               $theData[$field]= (($theFile['readable'])?'':'<span class="typo3-red"><b>R</b></span>').(($theFile['writable'])?'':'<span class="typo3-red"><b>W</b></span>');
+                                                               $theData[$field] = (($theFile['readable']) ? '' : '<span class="typo3-red"><strong>' . $GLOBALS['LANG']->getLL('read', true) . '</strong></span>') . (($theFile['writable']) ? '' : '<span class="typo3-red"><strong>' . $GLOBALS['LANG']->getLL('write', true) . '</strong></span>');
                                                        break;
                                                        case 'fileext':
                                                        break;
                                                        case 'fileext':
-       //                                                      $theData[$field]=strtoupper($theFile['fileext']);
+                                                               $theData[$field]=strtoupper($theFile['fileext']);
                                                        break;
                                                        case 'tstamp':
                                                                $theData[$field]=Date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $theFile['tstamp']);
                                                        break;
                                                        case 'tstamp':
                                                                $theData[$field]=Date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $theFile['tstamp']);
@@ -354,9 +360,12 @@ class fileList extends t3lib_recordList {
                                                        break;
                                                }
                                        }
                                                        break;
                                                }
                                        }
-                                       $out.=$this->addelement(1,$theIcon,$theData);
+                                       $altRows = 'class="' . ($i++ % 2 == 0 ? 'bgColor6' : 'bgColor4') . '"';
+
+                                       $out .= $this->addelement(1, $theIcon, $theData, $altRows);
                                }
                                $this->eCounter++;
                                }
                                $this->eCounter++;
+                               $this->dirCounter = $this->eCounter;
                        }
                }
                return $out;
                        }
                }
                return $out;
@@ -414,22 +423,22 @@ class fileList extends t3lib_recordList {
         * @return      array           (title, icon, path)
         */
        function dirData($theFile)      {
         * @return      array           (title, icon, path)
         */
        function dirData($theFile)      {
-               $path = $theFile['path'].$theFile['file'].'/';
-               $webpath=t3lib_BEfunc::getPathType_web_nonweb($path);
+               $path = $theFile['path'] . $theFile['file'] . '/';
+               $webpath = t3lib_BEfunc::getPathType_web_nonweb($path);
 
 
-               $title=htmlspecialchars($theFile['file']);
-               $icon = 'gfx/i/_icon_'.$webpath.'folders.gif';
-               if ($title=='_temp_')   {
+               $title = htmlspecialchars($theFile['file']);
+               $icon = 'gfx/i/_icon_' . $webpath . 'folders.gif';
+               if ($title == '_temp_') {
                        $icon = 'gfx/i/sysf.gif';
                        $icon = 'gfx/i/sysf.gif';
-                       $title='<b>TEMP</b>';
+                       $title = '<strong>' . $GLOBALS['LANG']->getLL('temp', true) . '</strong>';
                }
                }
-               if ($title=='_recycler_')       {
+               if ($title == '_recycler_')     {
                        $icon = 'gfx/i/recycler.gif';
                        $icon = 'gfx/i/recycler.gif';
-                       $title='<b>RECYCLER</b>';
+                       $title = '<strong>' . $GLOBALS['LANG']->getLL('recycler', true) . '</strong>';
                }
                }
-               $icon = $theFile['writable'] ? 'gfx/i/_icon_'.$webpath.'folders_ro.gif' : $icon;
+               $icon = $theFile['writable'] ? 'gfx/i/_icon_' . $webpath . 'folders_ro.gif' : $icon;
 
 
-               return Array($title,$icon,$path);
+               return array($title, $icon, $path);
        }
 
        /**
        }
 
        /**
@@ -466,10 +475,10 @@ class fileList extends t3lib_recordList {
                                        while(list(,$field)=each($this->fieldArray))    {
                                                switch($field)  {
                                                        case 'size':
                                        while(list(,$field)=each($this->fieldArray))    {
                                                switch($field)  {
                                                        case 'size':
-                                                               $theData[$field]=t3lib_div::formatSize($theFile[$field]);
+                                                               $theData[$field] = t3lib_div::formatSize($theFile[$field], $GLOBALS['LANG']->getLL('byteSizeUnits', true));
                                                        break;
                                                        case 'rw':
                                                        break;
                                                        case 'rw':
-                                                               $theData[$field]= (($theFile['readable'])?'':'<span class="typo3-red"><b>R</b></span>').(($theFile['writable'])?'':'<span class="typo3-red"><b>W</b></span>');
+                                                               $theData[$field] = (($theFile['readable']) ? '' : '<span class="typo3-red"><strong>' . $GLOBALS['LANG']->getLL('read', true) . '</strong></span>') . (($theFile['writable']) ? '' : '<span class="typo3-red"><strong>' . $GLOBALS['LANG']->getLL('write', true) . '</strong></span>');
                                                        break;
                                                        case 'fileext':
                                                                $theData[$field]=strtoupper($theFile[$field]);
                                                        break;
                                                        case 'fileext':
                                                                $theData[$field]=strtoupper($theFile[$field]);
@@ -491,16 +500,28 @@ class fileList extends t3lib_recordList {
                                                        break;
                                                }
                                        }
                                                        break;
                                                }
                                        }
-                                       $out.=$this->addelement(1,$theIcon,$theData);
+                                       if ($this->dirCounter % 2 == 0) {
+                                               $altRows = 'class="' . ($i++ % 2 == 0 ? 'bgColor6' : 'bgColor4') . '"';
+                                       } else {
+                                               $altRows = 'class="' . ($i++ % 2 == 0 ? 'bgColor4' : 'bgColor6') . '"';
+                                       }
+
+                                       $out .= $this->addelement(1, $theIcon, $theData, $altRows);
 
                                                // Thumbsnails?
                                        if ($this->thumbs && $this->isImage($theFile['fileext']))       {
 
                                                // Thumbsnails?
                                        if ($this->thumbs && $this->isImage($theFile['fileext']))       {
-                                               $thumbData=Array();
+                                               $thumbData = array();
                                                $theFile_R = rawurlencode($theFile['path'].$theFile['file']);
                                                $theFile_R = rawurlencode($theFile['path'].$theFile['file']);
-                                               $titleCol=$this->fieldArray[0];
-                                               $href = $this->backPath.$this->thumbScript.'?&dummy='.$GLOBALS['EXEC_TIME'].'&file='.$theFile_R;
+                                               $titleCol = $this->fieldArray[0];
+
+                                               $theFile_abs = $theFile['path'].$theFile['file'];
+                                               $check = basename($theFile_abs).':'.filemtime($theFile_abs).':'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
+                                               $params = '&file='.$theFile_R;
+                                               $params.= '&md5sum='.t3lib_div::shortMD5($check);
+                                               $href = $this->backPath.$this->thumbScript.'?&dummy='.$GLOBALS['EXEC_TIME'].$params;
+
                                                $thumbData[$titleCol]='<img src="'.htmlspecialchars($href).'" hspace="2" title="'.htmlspecialchars(trim($theFile['file'])).'" alt="" />';
                                                $thumbData[$titleCol]='<img src="'.htmlspecialchars($href).'" hspace="2" title="'.htmlspecialchars(trim($theFile['file'])).'" alt="" />';
-                                               $out.=$this->addelement(4,'',$thumbData);
+                                               $out.= $this->addelement(4,'',$thumbData);
                                        }
                                }
                                $this->eCounter++;
                                        }
                                }
                                $this->eCounter++;
@@ -553,7 +574,7 @@ class fileList extends t3lib_recordList {
                        $d = @dir($path);
                        $tempArray=Array();
                        if (is_object($d))      {
                        $d = @dir($path);
                        $tempArray=Array();
                        if (is_object($d))      {
-                               while($entry=$d->read()) {
+                               while(false !== ($entry=$d->read())) {
                                        if ($entry!='.' && $entry!='..')        {
                                                $wholePath = $path.'/'.$entry;          // Because of odd PHP-error where  <br />-tag is sometimes placed after a filename!!
                                                if (@file_exists($wholePath) && (!$type || t3lib_div::inList($type,filetype($wholePath))))      {
                                        if ($entry!='.' && $entry!='..')        {
                                                $wholePath = $path.'/'.$entry;          // Because of odd PHP-error where  <br />-tag is sometimes placed after a filename!!
                                                if (@file_exists($wholePath) && (!$type || t3lib_div::inList($type,filetype($wholePath))))      {