[BUGFIX] Error in filelist for Storage context menu 46/19246/2
authorNicole Cordes <typo3@cordes.co>
Fri, 22 Mar 2013 22:40:35 +0000 (23:40 +0100)
committerSteffen Ritter <info@rs-websystems.de>
Fri, 5 Apr 2013 19:12:42 +0000 (21:12 +0200)
The click menu for storage roots or mount points in filelist contains
functions which are not supported (e.g. cut/copy). This patch improves the
menu and only displays options which are allowed for storages/mount points
and for the current user.

Change-Id: I8e729eb3ea2d3977551ec689230ac9accfa76c4c
Resolves: #46575
Releases: 6.1, 6.0
Reviewed-on: https://review.typo3.org/19246
Reviewed-by: Steffen Ritter
Tested-by: Steffen Ritter
typo3/sysext/backend/Classes/ClickMenu/ClickMenu.php
typo3/sysext/backend/Classes/Tree/View/FolderTreeView.php
typo3/sysext/lang/locallang_core.xlf

index c782e99..8c8de7a 100644 (file)
@@ -1,6 +1,33 @@
 <?php
 namespace TYPO3\CMS\Backend\ClickMenu;
 
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 1999-2013 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!
+ ***************************************************************/
+
+use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
@@ -708,6 +735,10 @@ class ClickMenu {
                                ->retrieveFileOrFolderObject($combinedIdentifier);
                if ($fileObject) {
                        $folder = FALSE;
+                       $isStorageRoot = FALSE;
+                       $isOnline = TRUE;
+                       $userMayViewStorage = FALSE;
+                       $userMayEditStorage = FALSE;
                        $identifier = $fileObject->getCombinedIdentifier();
                        if ($fileObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
                                $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile('folder', array(
@@ -715,39 +746,70 @@ class ClickMenu {
                                        'title' => htmlspecialchars($fileObject->getName())
                                ));
                                $folder = TRUE;
+                               if ($fileObject->getIdentifier() === $fileObject->getStorage()->getRootLevelFolder()->getIdentifier()) {
+                                       $isStorageRoot = TRUE;
+                                       if ($GLOBALS['BE_USER']->check('tables_select', 'sys_file_storage')) {
+                                               $userMayViewStorage = TRUE;
+                                       }
+                                       if ($GLOBALS['BE_USER']->check('tables_modify', 'sys_file_storage')) {
+                                               $userMayEditStorage = TRUE;
+                                       }
+                               }
+                               if (!$fileObject->getStorage()->isOnline()) {
+                                       $isOnline = FALSE;
+                               }
                        } else {
                                $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile($fileObject->getExtension(), array(
                                        'class' => 'absmiddle',
                                        'title' => htmlspecialchars($fileObject->getName() . ' (' . GeneralUtility::formatSize($fileObject->getSize()) . ')')
                                ));
                        }
+                       // Hide
+                       if (!in_array('hide', $this->disabledItems) && $isStorageRoot && $userMayEditStorage) {
+                               $record = BackendUtility::getRecord('sys_file_storage', $fileObject->getStorage()->getUid());
+                               $menuItems['hide'] = $this->DB_changeFlag(
+                                       'sys_file_storage',
+                                       $record,
+                                       'is_online',
+                                       $this->label($record['is_online'] ? 'offline' : 'online'),
+                                       'hide'
+                               );
+                       }
                        // Edit
-                       if (!in_array('edit', $this->disabledItems) && !$folder && GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], $fileObject->getExtension())) {
-                               $menuItems['edit'] = $this->FILE_launch($identifier, 'file_edit.php', 'edit', 'edit_file.gif');
+                       if (!in_array('edit', $this->disabledItems)) {
+                               if (!$folder && GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], $fileObject->getExtension())) {
+                                       $menuItems['edit'] = $this->FILE_launch($identifier, 'file_edit.php', 'edit', 'edit_file.gif');
+                               } elseif ($isStorageRoot && $userMayEditStorage) {
+                                       $menuItems['edit'] = $this->DB_edit('sys_file_storage', $fileObject->getStorage()->getUid());
+                               }
                        }
                        // Rename
-                       if (!in_array('rename', $this->disabledItems)) {
+                       if (!in_array('rename', $this->disabledItems) && !$isStorageRoot) {
                                $menuItems['rename'] = $this->FILE_launch($identifier, 'file_rename.php', 'rename', 'rename.gif');
                        }
                        // Upload
-                       if (!in_array('upload', $this->disabledItems) && $folder) {
+                       if (!in_array('upload', $this->disabledItems) && $folder && $isOnline) {
                                $menuItems['upload'] = $this->FILE_upload($identifier);
                        }
                        // New
-                       if (!in_array('new', $this->disabledItems) && $folder) {
+                       if (!in_array('new', $this->disabledItems) && $folder && $isOnline) {
                                $menuItems['new'] = $this->FILE_launch($identifier, 'file_newfolder.php', 'new', 'new_file.gif');
                        }
                        // Info
                        if (!in_array('info', $this->disabledItems)) {
-                               $menuItems['info'] = $this->fileInfo($identifier);
+                               if ($isStorageRoot && $userMayViewStorage) {
+                                       $menuItems['info'] = $this->DB_info('sys_file_storage', $fileObject->getStorage()->getUid());
+                               } elseif (!$folder) {
+                                       $menuItems['info'] = $this->fileInfo($identifier);
+                               }
                        }
                        $menuItems[] = 'spacer';
                        // Copy:
-                       if (!in_array('copy', $this->disabledItems)) {
+                       if (!in_array('copy', $this->disabledItems) && !$isStorageRoot) {
                                $menuItems['copy'] = $this->FILE_copycut($identifier, 'copy');
                        }
                        // Cut:
-                       if (!in_array('cut', $this->disabledItems)) {
+                       if (!in_array('cut', $this->disabledItems) && !$isStorageRoot) {
                                $menuItems['cut'] = $this->FILE_copycut($identifier, 'cut');
                        }
                        // Paste:
@@ -765,7 +827,12 @@ class ClickMenu {
                        $menuItems[] = 'spacer';
                        // Delete:
                        if (!in_array('delete', $this->disabledItems)) {
-                               $menuItems['delete'] = $this->FILE_delete($identifier);
+                               if ($isStorageRoot && $userMayEditStorage) {
+                                       $elInfo = array(GeneralUtility::fixed_lgd_cs($fileObject->getStorage()->getName(), $GLOBALS['BE_USER']->uc['titleLen']));
+                                       $menuItems['delete'] = $this->DB_delete('sys_file_storage', $fileObject->getStorage()->getUid(), $elInfo);
+                               } elseif (!$isStorageRoot) {
+                                       $menuItems['delete'] = $this->FILE_delete($identifier);
+                               }
                        }
                }
                // Adding external elements to the menuItems array
index 3d77fa9..bde73a5 100644 (file)
@@ -130,7 +130,10 @@ class FolderTreeView extends \TYPO3\CMS\Backend\Tree\View\AbstractTreeView {
                $theFolderIcon = $this->addTagAttributes($icon, $this->titleAttrib ? $this->titleAttrib . '="' . $this->getTitleAttrib($folderObject) . '"' : '');
                // Wrap icon in click-menu link.
                if (!$this->ext_IconMode) {
-                       $theFolderIcon = $GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon($theFolderIcon, $folderObject->getCombinedIdentifier(), '', 0);
+                       // Check storage access to wrap with click menu
+                       if ($folderObject->getStorage()->hasFolder('/')) {
+                               $theFolderIcon = $GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon($theFolderIcon, $folderObject->getCombinedIdentifier(), '', 0);
+                       }
                } elseif (!strcmp($this->ext_IconMode, 'titlelink')) {
                        $aOnClick = 'return jumpTo(\'' . $this->getJumpToParam($folderObject) . '\',this,\'' . $this->domIdPrefix . $this->getId($folderObject) . '\',' . $this->bank . ');';
                        $theFolderIcon = '<a href="#" onclick="' . htmlspecialchars($aOnClick) . '">' . $theFolderIcon . '</a>';
@@ -148,6 +151,10 @@ class FolderTreeView extends \TYPO3\CMS\Backend\Tree\View\AbstractTreeView {
         * @internal
         */
        public function wrapTitle($title, \TYPO3\CMS\Core\Resource\Folder $folderObject, $bank = 0) {
+               // Check storage access to wrap with click menu
+               if (!$folderObject->getStorage()->hasFolder('/')) {
+                       return $title;
+               }
                $aOnClick = 'return jumpTo(\'' . $this->getJumpToParam($folderObject) . '\', this, \'' . $this->domIdPrefix . $this->getId($folderObject) . '\', ' . $bank . ');';
                $CSM = ' oncontextmenu="' . htmlspecialchars($GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon('', $folderObject->getCombinedIdentifier(), '', 0, ('&bank=' . $this->bank), '', TRUE)) . '"';
                return '<a href="#" title="' . htmlspecialchars($title) . '" onclick="' . htmlspecialchars($aOnClick) . '"' . $CSM . '>' . $title . '</a>';
@@ -653,4 +660,4 @@ class FolderTreeView extends \TYPO3\CMS\Backend\Tree\View\AbstractTreeView {
 }
 
 
-?>
\ No newline at end of file
+?>
index 810f8ad..f59e23c 100644 (file)
@@ -702,6 +702,12 @@ Would you like to save now in order to refresh the display?</source>
                        <trans-unit id="cm.unhide" xml:space="preserve">
                                <source>Unhide</source>
                        </trans-unit>
+                       <trans-unit id="cm.online" xml:space="preserve">
+                               <source>Turn online</source>
+                       </trans-unit>
+                       <trans-unit id="cm.offline" xml:space="preserve">
+                               <source>Turn offline</source>
+                       </trans-unit>
                        <trans-unit id="cm.upload" xml:space="preserve">
                                <source>Upload Files</source>
                        </trans-unit>