[TASK] Add tool-function to strip PATH_site-part of paths
[Packages/TYPO3.CMS.git] / typo3 / sysext / recordlist / Classes / Browser / ElementBrowser.php
index d925294..27ce173 100644 (file)
@@ -307,7 +307,7 @@ class ElementBrowser {
                                        $currentLinkParts[0] = rawurldecode(substr($this->curUrlArray['href'], 5));
                                } elseif (file_exists(PATH_site . rawurldecode($this->curUrlArray['href']))) {
                                        if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($this->curUrlArray['href'], PATH_site)) {
-                                               $currentLinkParts[0] = substr($this->curUrlArray['href'], strlen(PATH_site));
+                                               $currentLinkParts[0] = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($this->curUrlArray['href']);
                                        }
                                        $this->curUrlInfo = $this->parseCurUrl($this->siteURL . $this->curUrlArray['href'], $this->siteURL);
                                } elseif (strstr($this->curUrlArray['href'], '@')) {
@@ -822,7 +822,10 @@ class ElementBrowser {
                                // Create upload/create folder forms, if a path is given
                                if ($this->expandFolder) {
                                        $selectedFolder = FALSE;
-                                       $fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->expandFolder);
+                                       try {
+                                               $fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->expandFolder);
+                                       } catch (\Exception $e) {
+                                       }
 
                                        if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
                                                // It's a folder
@@ -842,11 +845,9 @@ class ElementBrowser {
                                // Build the file upload and folder creation form
                                $uploadForm = '';
                                $createFolder = '';
-                               if ($selectedFolder && !$this->isReadOnlyFolder($selectedFolder)) {
+                               if ($selectedFolder) {
                                        $uploadForm = ($this->act === 'file') ? $this->uploadForm($selectedFolder) : '';
-                                       if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.createFoldersInEB')) {
-                                               $createFolder = $this->createFolder($selectedFolder);
-                                       }
+                                       $createFolder = $this->createFolder($selectedFolder);
                                }
                                // Insert the upload form on top, if so configured
                                if ($GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
@@ -1211,17 +1212,9 @@ class ElementBrowser {
                        // Build the file upload and folder creation form
                $uploadForm = '';
                $createFolder = '';
-               if ($this->selectedFolder && !$this->isReadOnlyFolder($this->selectedFolder)) {
-                       $uploadForm = ($this->act === 'file') ? $this->uploadForm($this->selectedFolder) : '';
-                       if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.createFoldersInEB')) {
-                               $createFolder =  $this->createFolder($this->selectedFolder);
-                       }
-               }
                if ($this->selectedFolder) {
                        $uploadForm = $this->uploadForm($this->selectedFolder);
                        $createFolder = $this->createFolder($this->selectedFolder);
-               } else {
-                       $uploadForm = $createFolder = '';
                }
                // Insert the upload form on top, if so configured
                if ($GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
@@ -1242,10 +1235,14 @@ class ElementBrowser {
                $foldertree->ext_noTempRecyclerDirs = $this->mode == 'filedrag';
                $tree = $foldertree->getBrowsableTree();
                list(, , $specUid) = explode('_', $this->PM);
-               if ($this->mode == 'filedrag') {
-                       $files = $this->TBE_dragNDrop($this->selectedFolder, $pArr[3]);
+               if ($this->selectedFolder) {
+                       if ($this->mode == 'filedrag') {
+                               $files = $this->TBE_dragNDrop($this->selectedFolder, $pArr[3]);
+                       } else {
+                               $files = $this->TBE_expandFolder($this->selectedFolder, $pArr[3], $noThumbs);
+                       }
                } else {
-                       $files = $this->TBE_expandFolder($this->selectedFolder, $pArr[3], $noThumbs);
+                       $files = '';
                }
                // Putting the parts together, side by side:
                $content .= '
@@ -1295,7 +1292,7 @@ class ElementBrowser {
                if ($this->expandFolder) {
                        $this->selectedFolder = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($this->expandFolder);
                }
-               if ($this->selectedFolder && !$this->isReadOnlyFolder($this->selectedFolder)) {
+               if ($this->selectedFolder) {
                        $createFolder = $this->createFolder($this->selectedFolder);
                } else {
                        $createFolder = '';
@@ -1325,9 +1322,7 @@ class ElementBrowser {
                        </table>
                        ';
                // Adding create folder if applicable:
-               if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.createFoldersInEB')) {
-                       $content .= $createFolder;
-               }
+               $content .= $createFolder;
                // Add some space
                $content .= '<br /><br />';
                // Ending page, returning content:
@@ -1504,7 +1499,7 @@ class ElementBrowser {
        /**
         * For RTE: This displays all files from folder. No thumbnails shown
         *
-        * @param string $folder The folder path to expand
+        * @param \TYPO3\CMS\Core\Resource\Folder $folder The folder path to expand
         * @param string $extensionList List of fileextensions to show
         * @return string HTML output
         * @todo Define visibility
@@ -1533,11 +1528,7 @@ class ElementBrowser {
                        if ($renderFolders) {
                                $items = $folder->getSubfolders();
                        } else {
-                               $filter = new \TYPO3\CMS\Core\Resource\Filter\FileExtensionFilter();
-                               $filter->setAllowedFileExtensions($extensionList);
-                               $folder->getStorage()->setFileAndFolderNameFilters(array(array($filter, 'filterFileList')));
-
-                               $items = $folder->getFiles();
+                               $items = $this->getFilesInFolder($folder, $extensionList);
                        }
                        $c = 0;
                        $totalItems = count($items);
@@ -1578,16 +1569,13 @@ class ElementBrowser {
         * @return string HTML output
         * @todo Define visibility
         */
-       public function TBE_expandFolder(\TYPO3\CMS\Core\Resource\Folder $folder, $extensionList = '', $noThumbs = 0) {
-               $extensionList = $extensionList == '*' ? '' : $extensionList;
-               $content = '';
-               if ($folder->checkActionPermission('read')) {
-                       // Listing the files:
-                       $files = $folder->getFiles($extensionList);
-                       $content = $this->fileList($files, $folder, $noThumbs);
+       public function TBE_expandFolder(\TYPO3\CMS\Core\Resource\Folder $folder, $extensionList = '', $noThumbs = FALSE) {
+               if (!$folder->checkActionPermission('read')) {
+                       return '';
                }
-               // Return accumulated content for filelisting:
-               return $content;
+               $extensionList = $extensionList == '*' ? '' : $extensionList;
+               $files = $this->getFilesInFolder($folder, $extensionList);
+               return $this->fileList($files, $folder, $noThumbs);
        }
 
        /**
@@ -1637,7 +1625,7 @@ class ElementBrowser {
                                        $imageUrl = $fileObject->process(\TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW, array('width' => 64, 'height' => 64))->getPublicUrl(TRUE);
                                        $imgInfo = $imgObj->getImageDimensions($fileObject->getForLocalProcessing(FALSE));
                                        $pDim = $imgInfo[0] . 'x' . $imgInfo[1] . ' pixels';
-                                       $clickIcon = '<img src="' . $imageUrl . '" hspace="5" vspace="5" border="1"';
+                                       $clickIcon = '<img src="' . $imageUrl . '" hspace="5" vspace="5" border="1" />';
                                } else {
                                        $clickIcon = '';
                                        $pDim = '';
@@ -1807,86 +1795,85 @@ class ElementBrowser {
         * @todo Define visibility
         */
        public function TBE_dragNDrop(\TYPO3\CMS\Core\Resource\Folder $folder, $extensionList = '') {
-               $extensionList = $extensionList == '*' ? '' : $extensionList;
+               if (!$folder) {
+                       return '';
+               }
                $out = '';
-               if ($folder) {
-                       if ($folder->getStorage()->isPublic()) {
-                               // Read files from directory:
-                               $files = $folder->getFiles($extensionList);
-                               if (is_array($files)) {
-                                       $out .= $this->barheader(sprintf($GLOBALS['LANG']->getLL('files') . ' (%s):', count($files)));
-                                       $titleLen = intval($GLOBALS['BE_USER']->uc['titleLen']);
-                                       $picon = '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/i/_icon_webfolders.gif', 'width="18" height="16"') . ' alt="" />';
-                                       $picon .= htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs(basename($folder->getName()), $titleLen));
-                                       $out .= $picon . '<br />';
-                                       // Init row-array:
-                                       $lines = array();
-                                       // Add "drag-n-drop" message:
+               if ($folder->getStorage()->isPublic()) {
+                       // Read files from directory:
+                       $extensionList = $extensionList == '*' ? '' : $extensionList;
+                       $files = $this->getFilesInFolder($folder, $extensionList);
+                       $out .= $this->barheader(sprintf($GLOBALS['LANG']->getLL('files') . ' (%s):', count($files)));
+                       $titleLen = intval($GLOBALS['BE_USER']->uc['titleLen']);
+                       $picon = '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/i/_icon_webfolders.gif', 'width="18" height="16"') . ' alt="" />';
+                       $picon .= htmlspecialchars(GeneralUtility::fixed_lgd_cs(basename($folder->getName()), $titleLen));
+                       $out .= $picon . '<br />';
+                       // Init row-array:
+                       $lines = array();
+                       // Add "drag-n-drop" message:
+                       $lines[] = '
+                               <tr>
+                                       <td colspan="2">' . $this->getMsgBox($GLOBALS['LANG']->getLL('findDragDrop')) . '</td>
+                               </tr>';
+                       // Traverse files:
+                       foreach ($files as $fileObject) {
+                               $fileInfo = $fileObject->getStorage()->getFileInfo($fileObject);
+                               // URL of image:
+                               $iUrl = GeneralUtility::rawurlencodeFP($fileObject->getPublicUrl(TRUE));
+                               // Show only web-images
+                               $fileExtension = strtolower($fileObject->getExtension());
+                               if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList('gif,jpeg,jpg,png', $fileExtension)) {
+                                       $imgInfo = @getimagesize($fileObject->getForLocalProcessing(FALSE));
+                                       $pDim = $imgInfo[0] . 'x' . $imgInfo[1] . ' pixels';
+                                       $size = ' (' . GeneralUtility::formatSize($fileObject->getSize()) . 'bytes' . ($pDim ? ', ' . $pDim : '') . ')';
+                                       $filenameAndIcon = IconUtility::getSpriteIconForFile($fileExtension, array('title' => $fileObject->getName() . $size));
+                                       if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('noLimit')) {
+                                               $maxW = 10000;
+                                               $maxH = 10000;
+                                       } else {
+                                               $maxW = 380;
+                                               $maxH = 500;
+                                       }
+                                       $IW = $imgInfo[0];
+                                       $IH = $imgInfo[1];
+                                       if ($IW > $maxW) {
+                                               $IH = ceil($IH / $IW * $maxW);
+                                               $IW = $maxW;
+                                       }
+                                       if ($IH > $maxH) {
+                                               $IW = ceil($IW / $IH * $maxH);
+                                               $IH = $maxH;
+                                       }
+                                       // Make row:
+                                       $lines[] = '
+                                               <tr class="bgColor4">
+                                                       <td nowrap="nowrap">' . $filenameAndIcon . '&nbsp;</td>
+                                                       <td nowrap="nowrap">' . ($imgInfo[0] != $IW ? '<a href="' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(array('noLimit' => '1'))) . '">' . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/icon_warning2.gif', 'width="18" height="16"') . ' title="' . $GLOBALS['LANG']->getLL('clickToRedrawFullSize', TRUE) . '" alt="" />' . '</a>' : '') . $pDim . '&nbsp;</td>
+                                               </tr>';
                                        $lines[] = '
                                                <tr>
-                                                       <td colspan="2">' . $this->getMsgBox($GLOBALS['LANG']->getLL('findDragDrop')) . '</td>
+                                                       <td colspan="2"><img src="' . $iUrl . '" data-htmlarea-file-uid="' . $fileObject->getUid() . '" width="' . $IW . '" height="' . $IH . '" border="1" alt="" /></td>
+                                               </tr>';
+                                       $lines[] = '
+                                               <tr>
+                                                       <td colspan="2"><img src="clear.gif" width="1" height="3" alt="" /></td>
                                                </tr>';
-                                       // Traverse files:
-                                       foreach ($files as $fileObject) {
-                                               $fileInfo = $fileObject->getStorage()->getFileInfo($fileObject);
-                                               // URL of image:
-                                               $iUrl = GeneralUtility::rawurlencodeFP($fileObject->getPublicUrl(TRUE));
-                                               // Show only web-images
-                                               $fileExtension = strtolower($fileObject->getExtension());
-                                               if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList('gif,jpeg,jpg,png', $fileExtension)) {
-                                                       $imgInfo = @getimagesize($fileObject->getForLocalProcessing(FALSE));
-                                                       $pDim = $imgInfo[0] . 'x' . $imgInfo[1] . ' pixels';
-                                                       $size = ' (' . GeneralUtility::formatSize($fileObject->getSize()) . 'bytes' . ($pDim ? ', ' . $pDim : '') . ')';
-                                                       $filenameAndIcon = IconUtility::getSpriteIconForFile($fileExtension, array('title' => $fileObject->getName() . $size));
-                                                       if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('noLimit')) {
-                                                               $maxW = 10000;
-                                                               $maxH = 10000;
-                                                       } else {
-                                                               $maxW = 380;
-                                                               $maxH = 500;
-                                                       }
-                                                       $IW = $imgInfo[0];
-                                                       $IH = $imgInfo[1];
-                                                       if ($IW > $maxW) {
-                                                               $IH = ceil($IH / $IW * $maxW);
-                                                               $IW = $maxW;
-                                                       }
-                                                       if ($IH > $maxH) {
-                                                               $IW = ceil($IW / $IH * $maxH);
-                                                               $IH = $maxH;
-                                                       }
-                                                       // Make row:
-                                                       $lines[] = '
-                                                               <tr class="bgColor4">
-                                                                       <td nowrap="nowrap">' . $filenameAndIcon . '&nbsp;</td>
-                                                                       <td nowrap="nowrap">' . ($imgInfo[0] != $IW ? '<a href="' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(array('noLimit' => '1'))) . '">' . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/icon_warning2.gif', 'width="18" height="16"') . ' title="' . $GLOBALS['LANG']->getLL('clickToRedrawFullSize', TRUE) . '" alt="" />' . '</a>' : '') . $pDim . '&nbsp;</td>
-                                                               </tr>';
-                                                       $lines[] = '
-                                                               <tr>
-                                                                       <td colspan="2"><img src="' . $iUrl . '" data-htmlarea-file-uid="' . $fileObject->getUid() . '" width="' . $IW . '" height="' . $IH . '" border="1" alt="" /></td>
-                                                               </tr>';
-                                                       $lines[] = '
-                                                               <tr>
-                                                                       <td colspan="2"><img src="clear.gif" width="1" height="3" alt="" /></td>
-                                                               </tr>';
-                                               }
-                                       }
-                                       // Finally, wrap all rows in a table tag:
-                                       $out .= '
-
-
-                       <!--
-                               File listing / Drag-n-drop
-                       -->
-                                               <table border="0" cellpadding="0" cellspacing="1" id="typo3-dragBox">
-                                                       ' . implode('', $lines) . '
-                                               </table>';
                                }
-                       } else {
-                               // Print this warning if the folder is NOT a web folder:
-                               $out .= $this->barheader($GLOBALS['LANG']->getLL('files'));
-                               $out .= $this->getMsgBox($GLOBALS['LANG']->getLL('noWebFolder'), 'icon_warning2');
                        }
+                       // Finally, wrap all rows in a table tag:
+                       $out .= '
+
+
+       <!--
+               File listing / Drag-n-drop
+       -->
+                               <table border="0" cellpadding="0" cellspacing="1" id="typo3-dragBox">
+                                       ' . implode('', $lines) . '
+                               </table>';
+               } else {
+                       // Print this warning if the folder is NOT a web folder:
+                       $out .= $this->barheader($GLOBALS['LANG']->getLL('files'));
+                       $out .= $this->getMsgBox($GLOBALS['LANG']->getLL('noWebFolder'), 'icon_warning2');
                }
                return $out;
        }
@@ -1920,17 +1907,6 @@ class ElementBrowser {
        }
 
        /**
-        * Checks, if a path is within a read-only mountpoint of the backend user
-        *
-        * @param string $folder Absolute filepath
-        * @return boolean If the input path is found in the backend users filemounts and if the filemount is of type readonly, then return TRUE.
-        * @todo Define visibility
-        */
-       public function isReadOnlyFolder($folder) {
-               return $GLOBALS['FILEMOUNTS'][$this->fileProcessor->checkPathAgainstMounts(rtrim($folder, '/') . '/')]['type'] == 'readonly';
-       }
-
-       /**
         * Prints a 'header' where string is in a tablecell
         *
         * @param string $str The string to print in the header. The value is htmlspecialchars()'ed before output.
@@ -2174,6 +2150,9 @@ class ElementBrowser {
                if (!$folderObject->checkActionPermission('write')) {
                        return '';
                }
+               if (!($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.createFoldersInEB'))) {
+                       return '';
+               }
                // Don't show Folder-create form if it's denied
                if ($GLOBALS['BE_USER']->getTSConfigVal('options.folderTree.hideCreateFolder')) {
                        return '';
@@ -2266,4 +2245,21 @@ class ElementBrowser {
                return $result;
        }
 
+       /**
+        * Get a list of Files in a folder filtered by extension
+        *
+        * @param \TYPO3\CMS\Core\Resource\Folder $folder
+        * @param string $extensionList
+        * @return \TYPO3\CMS\Core\Resource\File[]
+        */
+       protected function getFilesInFolder(\TYPO3\CMS\Core\Resource\Folder $folder, $extensionList) {
+               if ($extensionList !== '') {
+                       /** @var \TYPO3\CMS\Core\Resource\Filter\FileExtensionFilter $filter */
+                       $filter = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Filter\\FileExtensionFilter');
+                       $filter->setAllowedFileExtensions($extensionList);
+                       $folder->setFileAndFolderNameFilters(array(array($filter, 'filterFileList')));
+               }
+               return $folder->getFiles();
+       }
+
 }