/** * Gets a list of all files in a directory recursively and removes * old ones. * * @param Folder $folder the folder * @param int $timestamp Timestamp of the last file modification */ protected function cleanupRecycledFiles(Folder $folder, $timestamp) { foreach ($folder->getFiles() as $file) { if ($timestamp > $file->getModificationTime()) { $file->delete(); } } foreach ($folder->getSubfolders() as $subFolder) { $this->cleanupRecycledFiles($subFolder, $timestamp); // if no more files and subdirectories are in the folder, remove the folder as well if ($subFolder->getFileCount() === 0 && count($subFolder->getSubfolders()) === 0) { $subFolder->delete(true); } } }
/** * Render list of folders. * * @param Folder $baseFolder * @return string HTML output * @todo Define visibility */ public function folderList(Folder $baseFolder) { $content = ''; $folders = $baseFolder->getSubfolders(); $baseFolderPath = $baseFolder->getPublicUrl(); // Create headline (showing number of folders): $content .= $this->barheader(sprintf($GLOBALS['LANG']->getLL('folders') . ' (%s):', count($folders))); $titleLength = (int) $GLOBALS['BE_USER']->uc['titleLen']; // Create the header of current folder: $aTag = '<a href="#" onclick="return insertElement(\'\',' . GeneralUtility::quoteJSvalue($baseFolderPath) . ', \'folder\', ' . GeneralUtility::quoteJSvalue($baseFolderPath) . ', ' . GeneralUtility::quoteJSvalue($baseFolderPath) . ', \'\', \'\',\'\',1);">'; // Add the foder icon $folderIcon = $aTag; $folderIcon .= '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/i/_icon_webfolders.gif', 'width="18" height="16"') . ' alt="" />'; $folderIcon .= htmlspecialchars(GeneralUtility::fixed_lgd_cs(basename($baseFolder), $titleLength)); $folderIcon .= '</a>'; $content .= $folderIcon . '<br />'; $lines = array(); // Traverse the folder list: foreach ($folders as $folderPath) { $pathInfo = pathinfo($folderPath); // Create folder icon: $icon = '<img src="clear.gif" width="16" height="16" alt="" /><img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/i/_icon_webfolders.gif', 'width="16" height="16"') . ' title="' . htmlspecialchars($pathInfo['basename']) . '" class="absmiddle" alt="" />'; // Create links for adding the folder: if ($this->P['itemName'] != '' && $this->P['formName'] != '') { $aTag = '<a href="#" onclick="return set_folderpath(' . GeneralUtility::quoteJSvalue($folderPath) . ');">'; } else { $aTag = '<a href="#" onclick="return insertElement(\'\',' . GeneralUtility::quoteJSvalue($folderPath) . ', \'folder\', ' . GeneralUtility::quoteJSvalue($folderPath) . ', ' . GeneralUtility::quoteJSvalue($folderPath) . ', \'' . $pathInfo['extension'] . '\', \'\');">'; } if (strstr($folderPath, ',') || strstr($folderPath, '|')) { // In case an invalid character is in the filepath, display error message: $errorMessage = GeneralUtility::quoteJSvalue(sprintf($GLOBALS['LANG']->getLL('invalidChar'), ', |')); $aTag = $aTag_alt = '<a href="#" onclick="alert(' . $errorMessage . ');return false;">'; } else { // If foldername is OK, just add it: $aTag_alt = substr($aTag, 0, -4) . ',\'\',1);">'; } $aTag_e = '</a>'; // Combine icon and folderpath: $foldernameAndIcon = $aTag_alt . $icon . htmlspecialchars(GeneralUtility::fixed_lgd_cs(basename($folderPath), $titleLength)) . $aTag_e; if ($this->P['itemName'] != '') { $lines[] = ' <tr class="bgColor4"> <td nowrap="nowrap">' . $foldernameAndIcon . ' </td> <td> </td> </tr>'; } else { $lines[] = ' <tr class="bgColor4"> <td nowrap="nowrap">' . $foldernameAndIcon . ' </td> <td>' . $aTag . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/plusbullet2.gif', 'width="18" height="16"') . ' title="' . $GLOBALS['LANG']->getLL('addToList', TRUE) . '" alt="" />' . $aTag_e . ' </td> <td> </td> </tr>'; } $lines[] = ' <tr> <td colspan="3"><img src="clear.gif" width="1" height="3" alt="" /></td> </tr>'; } // Wrap all the rows in table tags: $content .= ' <!-- Folder listing --> <table border="0" cellpadding="0" cellspacing="1" id="typo3-folderList"> ' . implode('', $lines) . ' </table>'; // Return accumulated content for folderlisting: return $content; }
/** * Indexes all files in a given storage folder. * currently this is done in a simple way, however could be changed to be more performant * * @param \TYPO3\CMS\Core\Resource\Folder $folder * @return int The number of indexed files. */ public function indexFilesInFolder(\TYPO3\CMS\Core\Resource\Folder $folder) { $numberOfIndexedFiles = 0; // Index all files in this folder $fileObjects = $folder->getFiles(); // emit signal $this->emitPreMultipleFilesIndexSignal($fileObjects); foreach ($fileObjects as $fileObject) { $this->indexFile($fileObject); $numberOfIndexedFiles++; } // emit signal $this->emitPostMultipleFilesIndexSignal($fileObjects); // Call this function recursively for each subfolder $subFolders = $folder->getSubfolders(); foreach ($subFolders as $subFolder) { $numberOfIndexedFiles += $this->indexFilesInFolder($subFolder); } return $numberOfIndexedFiles; }
/** * Simple function to make a hierarchical subfolder request into * a "flat" option list * * @param \TYPO3\CMS\Core\Resource\Folder $parentFolder * @param int $level a limiter * @return \TYPO3\CMS\Core\Resource\Folder[] */ protected function getSubfoldersForOptionList(\TYPO3\CMS\Core\Resource\Folder $parentFolder, $level = 0) { $level++; // hard break on recursion if ($level > 99) { return array(); } $allFolderItems = array($parentFolder); $subFolders = $parentFolder->getSubfolders(); foreach ($subFolders as $subFolder) { try { $subFolderItems = $this->getSubfoldersForOptionList($subFolder, $level); } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFolderReadPermissionsException $e) { $subFolderItems = array(); } $allFolderItems = array_merge($allFolderItems, $subFolderItems); } return $allFolderItems; }
/** * Counts the number of directories in a file path. * * @param \TYPO3\CMS\Core\Resource\Folder $folderObject File path. * @return int */ public function getNumberOfSubfolders(\TYPO3\CMS\Core\Resource\Folder $folderObject) { $subFolders = $folderObject->getSubfolders(); return count($subFolders); }
/** * @param Folder $parentFolder * @return string HTML code */ protected function renderFolders(Folder $parentFolder) { if (!$parentFolder->checkActionPermission('read')) { return ''; } $content = ''; $lang = $this->getLanguageService(); $folders = $parentFolder->getSubfolders(); $folderIdentifier = $parentFolder->getCombinedIdentifier(); // Create headline (showing number of folders): $content .= '<h3>' . sprintf($lang->getLL('folders', true) . ' (%s):', count($folders)) . '</h3>'; $titleLength = (int) $this->getBackendUser()->uc['titleLen']; // Create the header of current folder: $folderIcon = '<a href="#" data-folder-id="' . htmlspecialchars($folderIdentifier) . '" data-close="1">'; $folderIcon .= $this->iconFactory->getIcon('apps-filetree-folder-default', Icon::SIZE_SMALL); $folderIcon .= htmlspecialchars(GeneralUtility::fixed_lgd_cs($parentFolder->getName(), $titleLength)); $folderIcon .= '</a>'; $content .= $folderIcon . '<br />'; $lines = array(); // Traverse the folder list: foreach ($folders as $subFolder) { $subFolderIdentifier = $subFolder->getCombinedIdentifier(); // Create folder icon: $icon = '<span style="width: 16px; height: 16px; display: inline-block;"></span>'; $icon .= '<span title="' . htmlspecialchars($subFolder->getName()) . '">' . $this->iconFactory->getIcon('apps-filetree-folder-default', Icon::SIZE_SMALL) . '</span>'; // Create links for adding the folder: $aTag = '<a href="#" data-folder-id="' . htmlspecialchars($folderIdentifier) . '" data-close="0">'; $aTag_alt = '<a href="#" data-folder-id="' . htmlspecialchars($folderIdentifier) . '" data-close="1">'; if (strstr($subFolderIdentifier, ',') || strstr($subFolderIdentifier, '|')) { // In case an invalid character is in the filepath, display error message: $errorMessage = sprintf($lang->getLL('invalidChar', true), ', |'); $aTag = '<a href="#" class="t3-js-folderIdError" data-message="' . $errorMessage . '">'; } $aTag_e = '</a>'; // Combine icon and folderpath: $foldernameAndIcon = $aTag_alt . $icon . htmlspecialchars(GeneralUtility::fixed_lgd_cs($subFolder->getName(), $titleLength)) . $aTag_e; $lines[] = ' <tr class="bgColor4"> <td nowrap="nowrap">' . $foldernameAndIcon . ' </td> <td>' . $aTag . '<span title="' . $lang->getLL('addToList', true) . '">' . $this->iconFactory->getIcon('actions-edit-add', Icon::SIZE_SMALL)->render() . '</span>' . $aTag_e . '</td> <td> </td> </tr>'; $lines[] = ' <tr> <td colspan="3"><span style="width: 1px; height: 3px; display: inline-block;"></span></td> </tr>'; } // Wrap all the rows in table tags: $content .= ' <!-- Folder listing --> <table border="0" cellpadding="0" cellspacing="1" id="typo3-folderList"> ' . implode('', $lines) . ' </table>'; return $content; }
/** * Render list of folders. * * @param Folder $baseFolder * @return string HTML output */ public function folderList(Folder $baseFolder) { $content = ''; $lang = $this->getLanguageService(); $folders = $baseFolder->getSubfolders(); $folderIdentifier = $baseFolder->getCombinedIdentifier(); // Create headline (showing number of folders): $content .= $this->barheader(sprintf($lang->getLL('folders') . ' (%s):', count($folders))); $titleLength = (int) $this->getBackendUserAuthentication()->uc['titleLen']; // Create the header of current folder: $aTag = '<a href="#" onclick="return insertElement(\'\',' . GeneralUtility::quoteJSvalue($folderIdentifier) . ', \'folder\', ' . GeneralUtility::quoteJSvalue($folderIdentifier) . ', ' . GeneralUtility::quoteJSvalue($folderIdentifier) . ', \'\', \'\',\'\',1);">'; // Add the foder icon $folderIcon = $aTag; $folderIcon .= IconUtility::getSpriteIcon('apps-filetree-folder-default'); $folderIcon .= htmlspecialchars(GeneralUtility::fixed_lgd_cs($baseFolder->getName(), $titleLength)); $folderIcon .= '</a>'; $content .= $folderIcon . '<br />'; $lines = array(); // Traverse the folder list: foreach ($folders as $subFolder) { $subFolderIdentifier = $subFolder->getCombinedIdentifier(); // Create folder icon: $icon = '<img src="clear.gif" width="16" height="16" alt="" />'; $icon .= IconUtility::getSpriteIcon('apps-filetree-folder-default', array('title' => htmlspecialchars($subFolder->getName()))); // Create links for adding the folder: if ($this->P['itemName'] != '' && $this->P['formName'] != '') { $aTag = '<a href="#" onclick="return set_folderpath(' . GeneralUtility::quoteJSvalue($subFolderIdentifier) . ');">'; } else { $aTag = '<a href="#" onclick="return insertElement(\'\',' . GeneralUtility::quoteJSvalue($subFolderIdentifier) . ', \'folder\', ' . GeneralUtility::quoteJSvalue($subFolderIdentifier) . ', ' . GeneralUtility::quoteJSvalue($subFolderIdentifier) . ', \'\', \'\');">'; } if (strstr($subFolderIdentifier, ',') || strstr($subFolderIdentifier, '|')) { // In case an invalid character is in the filepath, display error message: $errorMessage = GeneralUtility::quoteJSvalue(sprintf($lang->getLL('invalidChar'), ', |')); $aTag = $aTag_alt = '<a href="#" onclick="alert(' . $errorMessage . ');return false;">'; } else { // If foldername is OK, just add it: $aTag_alt = substr($aTag, 0, -4) . ',\'\',1);">'; } $aTag_e = '</a>'; // Combine icon and folderpath: $foldernameAndIcon = $aTag_alt . $icon . htmlspecialchars(GeneralUtility::fixed_lgd_cs($subFolder->getName(), $titleLength)) . $aTag_e; if ($this->P['itemName'] != '') { $lines[] = ' <tr class="bgColor4"> <td nowrap="nowrap">' . $foldernameAndIcon . ' </td> <td> </td> </tr>'; } else { $lines[] = ' <tr class="bgColor4"> <td nowrap="nowrap">' . $foldernameAndIcon . ' </td> <td>' . $aTag . IconUtility::getSpriteIcon('actions-edit-add', array('title' => $lang->getLL('addToList', TRUE))) . $aTag_e . ' </td> <td> </td> </tr>'; } $lines[] = ' <tr> <td colspan="3"><img src="clear.gif" width="1" height="3" alt="" /></td> </tr>'; } // Wrap all the rows in table tags: $content .= ' <!-- Folder listing --> <table border="0" cellpadding="0" cellspacing="1" id="typo3-folderList"> ' . implode('', $lines) . ' </table>'; // Return accumulated content for folderlisting: return $content; }
/** * Counts the number of directories in a file path. * * @param Folder $folderObject File path. * * @return int */ public function getNumberOfSubfolders(Folder $folderObject) { $subFolders = $folderObject->getSubfolders(); return count($subFolders); }
/** * For RTE: This displays all files from folder. No thumbnails shown * * @param string $folder The folder path to expand * @param string $extensionList List of fileextensions to show * @return string HTML output * @todo Define visibility */ public function expandFolder(\TYPO3\CMS\Core\Resource\Folder $folder, $extensionList = '') { $out = ''; $renderFolders = $this->act === 'folder'; if ($folder->checkActionPermission('browse')) { // Create header for filelisting: $out .= $this->barheader($GLOBALS['LANG']->getLL('files') . ':'); // Prepare current path value for comparison (showing red arrow) $currentIdentifier = ''; if ($this->curUrlInfo['value']) { $currentIdentifier = $this->curUrlInfo['info']; } // Create header element; The folder from which files are listed. $titleLen = intval($GLOBALS['BE_USER']->uc['titleLen']); $folderIcon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile('folder'); $folderIcon .= htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($folder->getIdentifier(), $titleLen)); $picon = '<a href="#" onclick="return link_folder(\'file:' . $folder->getCombinedIdentifier() . '\');">' . $folderIcon . '</a>'; if ($this->curUrlInfo['act'] == 'folder' && $currentIdentifier == $folder->getCombinedIdentifier()) { $out .= '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/blinkarrow_left.gif', 'width="5" height="9"') . ' class="c-blinkArrowL" alt="" />'; } $out .= $picon . '<br />'; // Get files from the folder: 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(); } $c = 0; $totalItems = count($items); foreach ($items as $fileOrFolderObject) { $c++; if ($renderFolders) { $fileIdentifier = $fileOrFolderObject->getCombinedIdentifier(); $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile('folder'); $itemUid = 'file:' . $fileIdentifier; } else { $fileIdentifier = $fileOrFolderObject->getUid(); // File icon: $fileExtension = $fileOrFolderObject->getExtension(); // Get size and icon: $size = ' (' . \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($fileOrFolderObject->getSize()) . 'bytes)'; $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile($fileExtension, array('title' => $fileOrFolderObject->getName() . $size)); $itemUid = 'file:' . $fileIdentifier; } // If the listed file turns out to be the CURRENT file, then show blinking arrow: if (($this->curUrlInfo['act'] == 'file' || $this->curUrlInfo['act'] == 'folder') && $currentIdentifier == $fileIdentifier) { $arrCol = '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/blinkarrow_left.gif', 'width="5" height="9"') . ' class="c-blinkArrowL" alt="" />'; } else { $arrCol = ''; } // Put it all together for the file element: $out .= '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/ol/join' . ($c == $totalItems ? 'bottom' : '') . '.gif', 'width="18" height="16"') . ' alt="" />' . $arrCol . '<a href="#" onclick="return link_folder(\'' . $itemUid . '\');">' . $icon . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($fileOrFolderObject->getName(), $titleLen)) . '</a><br />'; } } return $out; }
/** * @param Folder $folder * @return array */ protected function getSubFoldersWithImage(Folder $folder) { $allFoldersInFolder = $folder->getSubfolders(); $foldersToDisplay = array(); /** @var Folder $folder */ foreach ($allFoldersInFolder as $identifier => $folder) { $folderImage = $this->getFolderImage($folder); $foldersToDisplay[$identifier] = array('folder' => $folder, 'folderImage' => $folderImage); } return $foldersToDisplay; }
/** * Get folder * * @param Folder $folder * @return array */ protected function getSubFolderIdentifiers(Folder $folder) { $folderIdentifiers = array(); foreach ($folder->getSubfolders() as $subFolder) { $folderIdentifiers[] = array($subFolder->getHashedIdentifier(), $subFolder->getIdentifier()); $folderIdentifiers = array_merge($folderIdentifiers, $this->getSubFolderIdentifiers($subFolder)); } return $folderIdentifiers; }
/** * @param Folder $folder * @param string $extensionList * @return FileInterface[]|Folder[] */ protected function getFolderContent(Folder $folder, $extensionList) { return $folder->getSubfolders(); }