/** * Returns TRUE if the input "record" contains a folder which can be linked. * * @param \TYPO3\CMS\Core\Resource\Folder $folderObject object with information about the folder element. Contains keys like title, uid, path, _title * * @return bool TRUE is returned if the path is NOT a recycler or temp folder AND if ->ext_noTempRecyclerDirs is not set. */ public function ext_isLinkable($folderObject) { if ($this->ext_noTempRecyclerDirs && (substr($folderObject->getIdentifier(), -7) == '_temp_/' || substr($folderObject->getIdentifier(), -11) == '_recycler_/')) { return FALSE; } else { return TRUE; } }
/** * Returns TRUE if the input "record" contains a folder which can be linked. * * @param \TYPO3\CMS\Core\Resource\Folder $folderObject Object with information about the folder element. Contains keys like title, uid, path, _title * @return bool TRUE is returned if the path is found in the web-part of the server and is NOT a recycler or temp folder */ public function ext_isLinkable(\TYPO3\CMS\Core\Resource\Folder $folderObject) { if (strstr($folderObject->getIdentifier(), '_recycler_') || strstr($folderObject->getIdentifier(), '_temp_')) { return FALSE; } else { return TRUE; } }
/** * @throws \PHPUnit_Framework_Exception */ protected function setUp() { $this->storageMock = $this->getMock(ResourceStorage::class, array(), array(), '', FALSE); $this->storageMock->expects($this->any())->method('getUid')->will($this->returnValue(5)); $this->folderMock = $this->getMock(Folder::class, array(), array(), '', FALSE); $this->folderMock->expects($this->any())->method('getStorage')->willReturn($this->storageMock); $this->storageMock->expects($this->any())->method('getProcessingFolder')->willReturn($this->folderMock); $this->databaseRow = array('uid' => '1234567', 'identifier' => 'dummy.txt', 'name' => $this->getUniqueId('dummy_'), 'storage' => $this->storageMock->getUid()); }
/** * @test */ public function flattenResultDataValueFlattensFileAndFolderResourcesButReturnsAnythingElseAsIs() { $this->fileController = $this->getAccessibleMock('TYPO3\\CMS\\Backend\\Controller\\File\\FileController', array('dummy')); $this->folderResourceMock->expects($this->once())->method('getIdentifier')->will($this->returnValue('bar')); $this->mockFileProcessor->expects($this->any())->method('getErrorMessages')->will($this->returnValue(array())); $this->assertTrue($this->fileController->_call('flattenResultDataValue', TRUE)); $this->assertSame(array(), $this->fileController->_call('flattenResultDataValue', array())); $this->assertSame(array('id' => 'foo', 'date' => '29-11-73', 'iconClasses' => 't3-icon t3-icon-mimetypes t3-icon-mimetypes-text t3-icon-text-html'), $this->fileController->_call('flattenResultDataValue', $this->fileResourceMock)); $this->assertSame('bar', $this->fileController->_call('flattenResultDataValue', $this->folderResourceMock)); }
/** * renders <f:then> child if the current visitor ... * otherwise renders <f:else> child. * * @param Folder $folder * @return string */ public function render(Folder $folder) { /** @var $leafStateService \BeechIt\FalSecuredownload\Service\LeafStateService */ $leafStateService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('BeechIt\\FalSecuredownload\\Service\\LeafStateService'); $feUser = !empty($GLOBALS['TSFE']) ? $GLOBALS['TSFE']->fe_user : false; if ($feUser && $leafStateService->getLeafStateForUser($feUser, $folder->getCombinedIdentifier())) { return $this->renderThenChild(); } else { return $this->renderElseChild(); } }
/** * @test */ public function flattenResultDataValueFlattensFileAndFolderResourcesButReturnsAnythingElseAsIs() { $this->fileController = $this->getAccessibleMock(\TYPO3\CMS\Backend\Controller\File\FileController::class, array('dummy')); $this->folderResourceMock->expects($this->once())->method('getIdentifier')->will($this->returnValue('bar')); $this->mockFileProcessor->expects($this->any())->method('getErrorMessages')->will($this->returnValue(array())); $this->assertTrue($this->fileController->_call('flattenResultDataValue', true)); $this->assertSame(array(), $this->fileController->_call('flattenResultDataValue', array())); $result = $this->fileController->_call('flattenResultDataValue', $this->fileResourceMock); $this->assertContains('<span class="t3js-icon icon icon-size-small icon-state-default icon-mimetypes-text-html" data-identifier="mimetypes-text-html">', $result['icon']); unset($result['icon']); $this->assertSame(array('id' => 'foo', 'date' => '29-11-73', 'thumbUrl' => ''), $result); $this->assertSame('bar', $this->fileController->_call('flattenResultDataValue', $this->folderResourceMock)); }
/** * Get main headline based on active folder or storage for backend module * * Folder names are resolved to their special names like done in the tree view. * * @param Folder $folder * @return string */ protected function getFolderName(Folder $folder) { $name = $folder->getName(); if ($name === '') { // Show storage name on storage root if ($folder->getIdentifier() === '/') { $name = $folder->getStorage()->getName(); } } else { $name = key(ListUtility::resolveSpecialFolderNames(array($name => $folder))); } return $name; }
/** * 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); } } }
/** * Create the panel of buttons for submitting the form or otherwise perform operations. * * @return array All available buttons as an assoc. array */ protected function registerButtons() { /** @var ButtonBar $buttonBar */ $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar(); /** @var IconFactory $iconFactory */ $iconFactory = $this->view->getModuleTemplate()->getIconFactory(); /** @var $resourceFactory ResourceFactory */ $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class); $lang = $this->getLanguageService(); // Refresh page $refreshLink = GeneralUtility::linkThisScript(['target' => rawurlencode($this->folderObject->getCombinedIdentifier()), 'imagemode' => $this->filelist->thumbs]); $refreshButton = $buttonBar->makeLinkButton()->setHref($refreshLink)->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.reload'))->setIcon($iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL)); $buttonBar->addButton($refreshButton, ButtonBar::BUTTON_POSITION_RIGHT); // Level up try { $currentStorage = $this->folderObject->getStorage(); $parentFolder = $this->folderObject->getParentFolder(); if ($parentFolder->getIdentifier() !== $this->folderObject->getIdentifier() && $currentStorage->isWithinFileMountBoundaries($parentFolder)) { $levelUpClick = 'top.document.getElementsByName("navigation")[0].contentWindow.Tree.highlightActiveItem("file","folder' . GeneralUtility::md5int($parentFolder->getCombinedIdentifier()) . '_"+top.fsMod.currentBank)'; $levelUpButton = $buttonBar->makeLinkButton()->setHref(BackendUtility::getModuleUrl('file_FilelistList', ['id' => $parentFolder->getCombinedIdentifier()]))->setOnClick($levelUpClick)->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.upOneLevel'))->setIcon($iconFactory->getIcon('actions-view-go-up', Icon::SIZE_SMALL)); $buttonBar->addButton($levelUpButton, ButtonBar::BUTTON_POSITION_LEFT, 1); } } catch (\Exception $e) { } // Shortcut if ($this->getBackendUser()->mayMakeShortcut()) { $shortCutButton = $buttonBar->makeShortcutButton()->setModuleName('file_FilelistList'); $buttonBar->addButton($shortCutButton, ButtonBar::BUTTON_POSITION_RIGHT); } // Upload button (only if upload to this directory is allowed) if ($this->folderObject && $this->folderObject->getStorage()->checkUserActionPermission('add', 'File') && $this->folderObject->checkActionPermission('write')) { $uploadButton = $buttonBar->makeLinkButton()->setHref(BackendUtility::getModuleUrl('file_upload', ['target' => $this->folderObject->getCombinedIdentifier(), 'returnUrl' => $this->filelist->listURL()]))->setClasses('t3js-drag-uploader-trigger')->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.upload'))->setIcon($iconFactory->getIcon('actions-edit-upload', Icon::SIZE_SMALL)); $buttonBar->addButton($uploadButton, ButtonBar::BUTTON_POSITION_LEFT, 1); } // New folder button if ($this->folderObject && $this->folderObject->checkActionPermission('write') && ($this->folderObject->getStorage()->checkUserActionPermission('add', 'File') || $this->folderObject->checkActionPermission('add'))) { $newButton = $buttonBar->makeLinkButton()->setHref(BackendUtility::getModuleUrl('file_newfolder', ['target' => $this->folderObject->getCombinedIdentifier(), 'returnUrl' => $this->filelist->listURL()]))->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.new'))->setIcon($iconFactory->getIcon('actions-document-new', Icon::SIZE_SMALL)); $buttonBar->addButton($newButton, ButtonBar::BUTTON_POSITION_LEFT, 1); } // Add paste button if clipboard is initialized if ($this->filelist->clipObj instanceof Clipboard && $this->folderObject->checkActionPermission('write')) { $elFromTable = $this->filelist->clipObj->elFromTable('_FILE'); if (!empty($elFromTable)) { $addPasteButton = true; $elToConfirm = []; foreach ($elFromTable as $key => $element) { $clipBoardElement = $resourceFactory->retrieveFileOrFolderObject($element); if ($clipBoardElement instanceof Folder && $clipBoardElement->getStorage()->isWithinFolder($clipBoardElement, $this->folderObject)) { $addPasteButton = false; } $elToConfirm[$key] = $clipBoardElement->getName(); } if ($addPasteButton) { $confirmText = $this->filelist->clipObj->confirmMsgText('_FILE', $this->folderObject->getReadablePath(), 'into', $elToConfirm); $pasteButton = $buttonBar->makeLinkButton()->setHref($this->filelist->clipObj->pasteUrl('_FILE', $this->folderObject->getCombinedIdentifier()))->setClasses('t3js-modal-trigger')->setDataAttributes(['severity' => 'warning', 'content' => $confirmText, 'title' => $lang->getLL('clip_paste')])->setTitle($lang->getLL('clip_paste'))->setIcon($iconFactory->getIcon('actions-document-paste-into', Icon::SIZE_SMALL)); $buttonBar->addButton($pasteButton, ButtonBar::BUTTON_POSITION_LEFT, 2); } } } }
/** * This function renders the upload form * * @return string The HTML form as a string, ready for outputting */ public function renderUploadForm() { // Make checkbox for "overwrite" $content = ' <div id="c-override"> <p><label for="overwriteExistingFiles"><input type="checkbox" class="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="replace" /> ' . $this->getLanguageService()->getLL('overwriteExistingFiles', 1) . '</label></p> <p> </p> <p>' . $this->getLanguageService()->getLL('uploadMultipleFilesInfo', true) . '</p> </div> '; // Produce the number of upload-fields needed: $content .= ' <div id="c-upload"> '; // Adding 'size="50" ' for the sake of Mozilla! $content .= ' <input type="file" multiple="true" name="upload_1[]" /> <input type="hidden" name="file[upload][1][target]" value="' . htmlspecialchars($this->folderObject->getCombinedIdentifier()) . '" /> <input type="hidden" name="file[upload][1][data]" value="1" /><br /> '; $content .= ' </div> '; // Submit button: $content .= ' <div id="c-submit"> <input type="hidden" name="redirect" value="' . $this->returnUrl . '" /><br /> <input class="btn btn-default" type="submit" value="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.submit', true) . '" /> </div> '; return $content; }
/** * Get folder configuration record * * @param Folder $folder * @return array */ public function getFolderRecord(Folder $folder) { if (!isset(self::$folderRecordCache[$folder->getCombinedIdentifier()]) || !array_key_exists($folder->getCombinedIdentifier(), self::$folderRecordCache)) { $record = $this->getDatabase()->exec_SELECTgetSingleRow('*', 'tx_falsecuredownload_folder', 'storage = ' . (int) $folder->getStorage()->getUid() . ' AND folder_hash = ' . $this->getDatabase()->fullQuoteStr($folder->getHashedIdentifier(), 'tx_falsecuredownload_folder')); // cache results self::$folderRecordCache[$folder->getCombinedIdentifier()] = $record; } return self::$folderRecordCache[$folder->getCombinedIdentifier()]; }
/** * Constructor function for class * * @return void * @todo Define visibility */ public function init() { // Initialize GPvars: $this->number = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('number'); $this->target = $combinedIdentifier = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('target'); $this->returnUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::sanitizeLocalUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('returnUrl')); // create the folder object if ($combinedIdentifier) { $this->folderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($combinedIdentifier); } // Cleaning and checking target directory if (!$this->folderObject) { $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:paramError', TRUE); $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:targetNoDir', TRUE); throw new \RuntimeException($title . ': ' . $message, 1294586843); } // Setting the title and the icon $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('apps-filetree-root'); $this->title = $icon . htmlspecialchars($this->folderObject->getStorage()->getName()) . ': ' . htmlspecialchars($this->folderObject->getIdentifier()); // Setting template object $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate'); $this->doc->setModuleTemplate('templates/file_newfolder.html'); $this->doc->backPath = $GLOBALS['BACK_PATH']; $this->doc->JScode = $this->doc->wrapScriptTags(' var path = "' . $this->target . '"; function reload(a) { // if (!changed || (changed && confirm(' . $GLOBALS['LANG']->JScharCode($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.redraw')) . '))) { var params = "&target="+encodeURIComponent(path)+"&number="+a+"&returnUrl=' . rawurlencode($this->returnUrl) . '"; window.location.href = "file_newfolder.php?"+params; } } function backToList() { // top.goToModule("file_list"); } var changed = 0; '); }
/** * Writes the file with the is $fileId to the legacy import folder. The file name will used from * argument $fileName and the file was successfully created or an identical file was already found, * $fileName will held the uid of the new created file record. * * @param string $fileName The file name for the new file. Value would be changed to the uid of the new created file record. * @param int $fileId The id of the file in data array * @return bool */ protected function writeSysFileResourceForLegacyImport(&$fileName, $fileId) { if ($this->legacyImportFolder === null) { return false; } if (!isset($this->dat['files'][$fileId])) { $this->error('ERROR: File ID "' . $fileId . '" could not be found'); return false; } $temporaryFile = $this->writeTemporaryFileFromData($fileId, 'files'); if ($temporaryFile === null) { // error on writing the file. Error message was already added return false; } $importFolder = $this->legacyImportFolder; if (isset($this->dat['files'][$fileId]['relFileName'])) { $relativeFilePath = PathUtility::dirname($this->dat['files'][$fileId]['relFileName']); if (!$this->legacyImportFolder->hasFolder($relativeFilePath)) { $this->legacyImportFolder->createFolder($relativeFilePath); } $importFolder = $this->legacyImportFolder->getSubfolder($relativeFilePath); } $fileObject = null; try { // check, if there is alreay the same file in the folder if ($importFolder->hasFile($fileName)) { $fileStorage = $importFolder->getStorage(); $file = $fileStorage->getFile($importFolder->getIdentifier() . $fileName); if ($file->getSha1() === sha1_file($temporaryFile)) { $fileObject = $file; } } } catch (Exception $e) { } if ($fileObject === null) { try { $fileObject = $importFolder->addFile($temporaryFile, $fileName, DuplicationBehavior::RENAME); } catch (Exception $e) { $this->error('Error: no file could be added to the storage for file name ' . $this->alternativeFileName[$temporaryFile]); } } if (md5_file(PATH_site . $fileObject->getPublicUrl()) == $this->dat['files'][$fileId]['content_md5']) { $fileName = $fileObject->getUid(); $this->fileIDMap[$fileId] = $fileName; $this->filePathMap[$fileId] = $fileObject->getPublicUrl(); return true; } else { $this->error('ERROR: File content "' . $this->dat['files'][$fileId]['relFileName'] . '" was corrupted'); } return false; }
/** * Simple function to make a hierarchical subfolder request into * a "flat" option list * * @param \TYPO3\CMS\Core\Resource\Folder $parentFolder * @param integer $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) { $subFolderItems = $this->getSubfoldersForOptionList($subFolder, $level); $allFolderItems = array_merge($allFolderItems, $subFolderItems); } return $allFolderItems; }
/** * Create the panel of buttons for submitting the form or otherwise perform operations. * * @return array All available buttons as an assoc. array */ public function getButtons() { $buttons = array('csh' => '', 'shortcut' => '', 'upload' => '', 'new' => ''); // Add shortcut if ($this->getBackendUser()->mayMakeShortcut()) { $buttons['shortcut'] = $this->doc->makeShortcutIcon('pointer,id,target,table', implode(',', array_keys($this->MOD_MENU)), $this->moduleName); } // FileList Module CSH: $buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'filelist_module'); // Upload button (only if upload to this directory is allowed) if ($this->folderObject && $this->folderObject->getStorage()->checkUserActionPermission('add', 'File') && $this->folderObject->checkActionPermission('write')) { $buttons['upload'] = '<a href="' . htmlspecialchars($GLOBALS['BACK_PATH'] . BackendUtility::getModuleUrl('file_upload', array('target' => $this->folderObject->getCombinedIdentifier(), 'returnUrl' => $this->filelist->listURL()))) . '" id="button-upload" title="' . $this->getLanguageService()->makeEntities($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.upload', TRUE)) . '">' . IconUtility::getSpriteIcon('actions-edit-upload') . '</a>'; } // New folder button if ($this->folderObject && $this->folderObject->checkActionPermission('write') && ($this->folderObject->getStorage()->checkUserActionPermission('add', 'File') || $this->folderObject->checkActionPermission('add'))) { $buttons['new'] = '<a href="' . htmlspecialchars($GLOBALS['BACK_PATH'] . BackendUtility::getModuleUrl('file_newfolder', array('target' => $this->folderObject->getCombinedIdentifier(), 'returnUrl' => $this->filelist->listURL()))) . '" title="' . $this->getLanguageService()->makeEntities($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.new', TRUE)) . '">' . IconUtility::getSpriteIcon('actions-document-new') . '</a>'; } return $buttons; }
/** * Create the panel of buttons for submitting the form or otherwise perform operations. * * @return array All available buttons as an assoc. array * @todo Define visibility */ public function getButtons() { $buttons = array('csh' => '', 'shortcut' => '', 'upload' => '', 'new' => ''); // Add shortcut if ($GLOBALS['BE_USER']->mayMakeShortcut()) { $buttons['shortcut'] = $this->doc->makeShortcutIcon('pointer,id,target,table', implode(',', array_keys($this->MOD_MENU)), $this->MCONF['name']); } // FileList Module CSH: $buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'filelist_module', $GLOBALS['BACK_PATH'], '', TRUE); // Upload button (only if upload to this directory is allowed) if ($this->folderObject && $this->folderObject->getStorage()->checkUserActionPermission('add', 'File') && $this->folderObject->checkActionPermission('write')) { $buttons['upload'] = '<a href="' . $GLOBALS['BACK_PATH'] . 'file_upload.php?target=' . rawurlencode($this->folderObject->getCombinedIdentifier()) . '&returnUrl=' . rawurlencode($this->filelist->listURL()) . '" id="button-upload" title="' . $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:cm.upload', TRUE)) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-edit-upload') . '</a>'; } // New folder button if ($this->folderObject && $this->folderObject->checkActionPermission('write') && ($this->folderObject->getStorage()->checkUserActionPermission('add', 'File') || $this->folderObject->checkActionPermission('add'))) { $buttons['new'] = '<a href="' . $GLOBALS['BACK_PATH'] . 'file_newfolder.php?target=' . rawurlencode($this->folderObject->getCombinedIdentifier()) . '&returnUrl=' . rawurlencode($this->filelist->listURL()) . '" title="' . $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:cm.new', TRUE)) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-new') . '</a>'; } return $buttons; }
/** * Init file/folder parameters */ protected function initFileOrFolderRecord() { $fileOrFolderObject = ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->uid); if ($fileOrFolderObject instanceof Folder) { $this->folderObject = $fileOrFolderObject; $this->access = $this->folderObject->checkActionPermission('read'); $this->type = 'folder'; } else { $this->fileObject = $fileOrFolderObject; $this->access = $this->fileObject->checkActionPermission('read'); $this->type = 'file'; $this->table = 'sys_file'; try { $this->row = BackendUtility::getRecordWSOL($this->table, $fileOrFolderObject->getUid()); } catch (\Exception $e) { $this->row = array(); } } }
/** * Init file/folder parameters */ protected function initFileOrFolderRecord() { $fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->uid); if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) { $this->folderObject = $fileOrFolderObject; $this->access = $this->folderObject->checkActionPermission('read'); $this->type = 'folder'; } else { $this->fileObject = $fileOrFolderObject; $this->access = $this->fileObject->checkActionPermission('read'); $this->type = 'file'; $this->table = 'sys_file_metadata'; try { $metaData = $fileOrFolderObject->_getMetaData(); $this->row = BackendUtility::getRecordWSOL($this->table, $metaData['uid']); } catch (\Exception $e) { $this->row = array(); } } }
/** * Main function, rendering the content of the rename form * * @return void */ public function main() { if ($this->fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) { $fileIdentifier = $this->fileOrFolderObject->getCombinedIdentifier(); } else { $fileIdentifier = $this->fileOrFolderObject->getUid(); } $pageContent = '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('tce_file')) . '" method="post" name="editform" role="form">'; // Making the formfields for renaming: $pageContent .= ' <div class="form-group"> <input class="form-control" type="text" name="file[rename][0][target]" value="' . htmlspecialchars($this->fileOrFolderObject->getName()) . '" ' . $this->getDocumentTemplate()->formWidth(40) . ' /> <input type="hidden" name="file[rename][0][data]" value="' . htmlspecialchars($fileIdentifier) . '" /> </div> '; // Making submit button: $pageContent .= ' <div class="form-group"> <input class="btn btn-primary" type="submit" value="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.submit', true) . '" /> <input class="btn btn-danger" type="submit" value="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.cancel', true) . '" onclick="backToList(); return false;" /> <input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl) . '" /> </div> '; $pageContent .= '</form>'; // Create buttons $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar(); // csh button $cshButton = $buttonBar->makeHelpButton()->setModuleName('xMOD_csh_corebe')->setFieldName('file_rename'); $buttonBar->addButton($cshButton); // back button if ($this->returnUrl) { $backButton = $buttonBar->makeLinkButton()->sethref(GeneralUtility::linkThisUrl($this->returnUrl))->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.goBack', true))->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-back', Icon::SIZE_SMALL)); $buttonBar->addButton($backButton); } // set header $this->content = '<h1>' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.pagetitle') . '</h1>'; // add section $this->content .= $this->moduleTemplate->section('', $pageContent); $this->moduleTemplate->setContent($this->content); }
/** * Main function, rendering the content of the rename form * * @return void */ public function main() { // Make page header: $this->content = $this->doc->startPage($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.pagetitle')); $pageContent = $this->doc->header($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.pagetitle')); if ($this->fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) { $fileIdentifier = $this->fileOrFolderObject->getCombinedIdentifier(); } else { $fileIdentifier = $this->fileOrFolderObject->getUid(); } $pageContent .= '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('tce_file')) . '" method="post" name="editform" role="form">'; // Making the formfields for renaming: $pageContent .= ' <div class="form-group"> <input class="form-control" type="text" name="file[rename][0][target]" value="' . htmlspecialchars($this->fileOrFolderObject->getName()) . '" ' . $this->getDocumentTemplate()->formWidth(40) . ' /> <input type="hidden" name="file[rename][0][data]" value="' . htmlspecialchars($fileIdentifier) . '" /> </div> '; // Making submit button: $pageContent .= ' <div class="form-group"> <input class="btn btn-primary" type="submit" value="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.submit', TRUE) . '" /> <input class="btn btn-danger" type="submit" value="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.cancel', TRUE) . '" onclick="backToList(); return false;" /> <input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl) . '" /> ' . \TYPO3\CMS\Backend\Form\FormEngine::getHiddenTokenField('tceAction') . ' </div> '; $pageContent .= '</form>'; $docHeaderButtons = array('back' => ''); $docHeaderButtons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'file_rename'); // Back if ($this->returnUrl) { $docHeaderButtons['back'] = '<a href="' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisUrl($this->returnUrl)) . '" class="typo3-goBack" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.goBack', TRUE) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-view-go-back') . '</a>'; } // Add the HTML as a section: $markerArray = array('CSH' => $docHeaderButtons['csh'], 'FUNC_MENU' => '', 'CONTENT' => $pageContent, 'PATH' => $this->title); $this->content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray); $this->content .= $this->doc->endPage(); $this->content = $this->doc->insertStylesAndJS($this->content); }
/** * Get the HTML data required for a bulk selection of files of the TYPO3 Element Browser. * * @param int $filesCount Number of files currently displayed * @return string HTML data required for a bulk selection of files - if $filesCount is 0, nothing is returned */ protected function getBulkSelector($filesCount) { if (!$filesCount) { return ''; } $lang = $this->getLanguageService(); $out = ''; // Getting flag for showing/not showing thumbnails: $noThumbsInEB = $this->getBackendUser()->getTSConfigVal('options.noThumbsInEB'); if (!$noThumbsInEB && $this->selectedFolder) { // MENU-ITEMS, fetching the setting for thumbnails from File>List module: $_MOD_MENU = array('displayThumbs' => ''); $_MCONF['name'] = 'file_list'; $_MOD_SETTINGS = BackendUtility::getModuleData($_MOD_MENU, GeneralUtility::_GP('SET'), $_MCONF['name']); $addParams = GeneralUtility::implodeArrayForUrl('', $this->getUrlParameters(['identifier' => $this->selectedFolder->getCombinedIdentifier()])); $thumbNailCheck = '<div class="checkbox" style="padding:5px 0 15px 0"><label for="checkDisplayThumbs">' . BackendUtility::getFuncCheck('', 'SET[displayThumbs]', $_MOD_SETTINGS['displayThumbs'], $this->thisScript, $addParams, 'id="checkDisplayThumbs"') . $lang->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:displayThumbs', true) . '</label></div>'; $out .= $thumbNailCheck; } else { $out .= '<div style="padding-top: 15px;"></div>'; } return $out; }
/** * Get the HTML data required for a bulk selection of files of the TYPO3 Element Browser. * * @param int $filesCount Number of files currently displayed * @return string HTML data required for a bulk selection of files - if $filesCount is 0, nothing is returned */ protected function getBulkSelector($filesCount) { if (!$filesCount) { return ''; } $lang = $this->getLanguageService(); $labelToggleSelection = $lang->sL('LLL:EXT:lang/locallang_browse_links.xlf:toggleSelection', true); $labelImportSelection = $lang->sL('LLL:EXT:lang/locallang_browse_links.xlf:importSelection', true); $out = $this->doc->spacer(10) . '<div>' . '<a href="#" id="t3-js-importSelection" title="' . $labelImportSelection . '">' . $this->iconFactory->getIcon('actions-document-import-t3d', Icon::SIZE_SMALL) . $labelImportSelection . '</a> ' . '<a href="#" id="t3-js-toggleSelection" title="' . $labelToggleSelection . '">' . $this->iconFactory->getIcon('actions-document-select', Icon::SIZE_SMALL) . $labelToggleSelection . '</a>' . '</div>'; // Getting flag for showing/not showing thumbnails: $noThumbsInEB = $this->getBackendUser()->getTSConfigVal('options.noThumbsInEB'); if (!$noThumbsInEB && $this->selectedFolder) { // MENU-ITEMS, fetching the setting for thumbnails from File>List module: $_MOD_MENU = array('displayThumbs' => ''); $_MCONF['name'] = 'file_list'; $_MOD_SETTINGS = BackendUtility::getModuleData($_MOD_MENU, GeneralUtility::_GP('SET'), $_MCONF['name']); $addParams = GeneralUtility::implodeArrayForUrl('', $this->getUrlParameters(['identifier' => $this->selectedFolder->getCombinedIdentifier()])); $thumbNailCheck = '<div class="checkbox"><label for="checkDisplayThumbs">' . BackendUtility::getFuncCheck('', 'SET[displayThumbs]', $_MOD_SETTINGS['displayThumbs'], $this->thisScript, $addParams, 'id="checkDisplayThumbs"') . $lang->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:displayThumbs', true) . '</label></div>'; $out .= $this->doc->spacer(5) . $thumbNailCheck . $this->doc->spacer(15); } else { $out .= $this->doc->spacer(15); } return $out; }
/** * Main function, rendering the main module content * * @return void */ public function main() { $lang = $this->getLanguageService(); $pageContent = '<h1>' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.pagetitle') . '</h1>'; if ($this->folderObject->checkActionPermission('add')) { $code = '<form role="form" action="' . htmlspecialchars(BackendUtility::getModuleUrl('tce_file')) . '" method="post" name="editform">'; // Making the selector box for the number of concurrent folder-creations $this->number = MathUtility::forceIntegerInRange($this->number, 1, 10); $code .= ' <div class="form-group"> <div class="form-section"> <div class="form-group"> <label for="number-of-new-folders">' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.number_of_folders') . '</label> ' . BackendUtility::cshItem('xMOD_csh_corebe', 'file_newfolder') . ' <div class="form-control-wrap"> <div class="input-group"> <select class="form-control form-control-adapt" name="number" id="number-of-new-folders" onchange="reload(this.options[this.selectedIndex].value);">'; for ($a = 1; $a <= $this->folderNumber; $a++) { $code .= '<option value="' . $a . '"' . ($this->number == $a ? ' selected="selected"' : '') . '>' . $a . '</option>'; } $code .= ' </select> </div> </div> </div> </div> '; // Making the number of new-folder boxes needed: for ($a = 0; $a < $this->number; $a++) { $code .= ' <div class="form-section"> <div class="form-group"> <label for="folder_new_' . $a . '">' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.label_newfolder') . ' ' . ($a + 1) . ':</label> <div class="form-control-wrap"> <input type="text" class="form-control" id="folder_new_' . $a . '" name="file[newfolder][' . $a . '][data]" onchange="changed=true;" /> <input type="hidden" name="file[newfolder][' . $a . '][target]" value="' . htmlspecialchars($this->target) . '" /> </div> </div> </div>'; } // Making submit button for folder creation: $code .= ' </div><div class="form-group"> <input class="btn btn-default" type="submit" value="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.submit', true) . '" /> <input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl) . '" /> </div> '; // Switching form tags: $pageContent .= '<h3>' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.newfolders', true) . '</h3>'; $pageContent .= '<div>' . $code . '</form></div>'; } if ($this->folderObject->getStorage()->checkUserActionPermission('add', 'File')) { $pageContent .= '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('online_media')) . '" method="post" name="editform2">'; // Create a list of allowed file extensions with the readable format "youtube, vimeo" etc. $fileExtList = array(); $onlineMediaFileExt = OnlineMediaHelperRegistry::getInstance()->getSupportedFileExtensions(); foreach ($onlineMediaFileExt as $fileExt) { if (GeneralUtility::verifyFilenameAgainstDenyPattern($fileExt)) { $fileExtList[] = '<span class="label label-success">' . strtoupper(htmlspecialchars($fileExt)) . '</span>'; } } // Add form fields for adding media files: $code = ' <div class="form-group"> <div class="form-section"> <div class="form-group"> <label for="newMedia">' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media.label', true) . '</label> ' . BackendUtility::cshItem('xMOD_csh_corebe', 'file_newMedia') . ' <div class="form-control-wrap"> <input class="form-control" type="text" id="newMedia" name="file[newMedia][0][url]" placeholder="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media.placeholder', true) . '" /> <input type="hidden" name="file[newMedia][0][target]" value="' . htmlspecialchars($this->target) . '" /> </div> <div class="help-block"> ' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media.allowedProviders', true) . '<br> ' . implode(' ', $fileExtList) . ' </div> </div> </div> </div> '; // Submit button for creation of a new media: $code .= ' <div class="form-group"> <input class="btn btn-default" type="submit" value="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media.submit', true) . '" /> <input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl) . '" /> </div> '; $pageContent .= '<h3>' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media', true) . '</h3>'; $pageContent .= '<div>' . $code . '</div>'; $pageContent .= '</form>'; $pageContent .= '<form action="' . BackendUtility::getModuleUrl('tce_file') . '" method="post" name="editform3">'; // Create a list of allowed file extensions with the nice format "*.jpg, *.gif" etc. $fileExtList = array(); $textFileExt = GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], true); foreach ($textFileExt as $fileExt) { if (GeneralUtility::verifyFilenameAgainstDenyPattern($fileExt)) { $fileExtList[] = '<span class="label label-success">' . strtoupper(htmlspecialchars($fileExt)) . '</span>'; } } // Add form fields for creation of a new, blank text file: $code = ' <div class="form-group"> <div class="form-section"> <div class="form-group"> <label for="newfile">' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.label_newfile', true) . '</label> ' . BackendUtility::cshItem('xMOD_csh_corebe', 'file_newfile') . ' <div class="form-control-wrap"> <input class="form-control" type="text" id="newfile" name="file[newfile][0][data]" onchange="changed=true;" /> <input type="hidden" name="file[newfile][0][target]" value="' . htmlspecialchars($this->target) . '" /> </div> <div class="help-block"> ' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:cm.allowedFileExtensions', true) . '<br> ' . implode(' ', $fileExtList) . ' </div> </div> </div> </div> '; // Submit button for creation of a new file: $code .= ' <div class="form-group"> <input class="btn btn-default" type="submit" value="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.newfile_submit', true) . '" /> <input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl) . '" /> </div> '; $pageContent .= '<h3>' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.newfile', true) . '</h3>'; $pageContent .= '<div>' . $code . '</div>'; $pageContent .= '</form>'; } $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar(); // Back if ($this->returnUrl) { $backButton = $buttonBar->makeLinkButton()->setHref(GeneralUtility::linkThisUrl($this->returnUrl))->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.goBack'))->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-back', Icon::SIZE_SMALL)); $buttonBar->addButton($backButton); } $this->content .= '<div>' . $pageContent . '</div>'; $this->moduleTemplate->setContent($this->content); }
/** * Checks if a given object or identifier is within a container, e.g. if * a file or folder is within another folder. * This can e.g. be used to check for webmounts. * * @param \TYPO3\CMS\Core\Resource\Folder $container * @param mixed $content An object or an identifier to check * @return boolean TRUE if $content is within $container */ public function isWithin(\TYPO3\CMS\Core\Resource\Folder $container, $content) { // TODO: Implement isWithin() method. error_log('CALLED: ' . __FUNCTION__ . ' with ' . $content . ' in folder ' . $container->getCombinedIdentifier()); }
/** * Make reference count * * @param File|Folder $fileOrFolderObject Array with information about the file/directory for which to make the clipboard panel for the listing. * @return string HTML */ public function makeRef($fileOrFolderObject) { if ($fileOrFolderObject instanceof FolderInterface) { return '-'; } // Look up the file in the sys_refindex. // Exclude sys_file_metadata records as these are no use references $databaseConnection = $this->getDatabaseConnection(); $table = 'sys_refindex'; $referenceCount = $databaseConnection->exec_SELECTcountRows('*', $table, 'ref_table=' . $databaseConnection->fullQuoteStr('sys_file', $table) . ' AND ref_uid=' . (int) $fileOrFolderObject->getUid() . ' AND deleted=0' . ' AND tablename != ' . $databaseConnection->fullQuoteStr('sys_file_metadata', $table)); return $this->generateReferenceToolTip($referenceCount, '\'_FILE\', ' . GeneralUtility::quoteJSvalue($fileOrFolderObject->getCombinedIdentifier())); }
/** * @param $path * @param int $start * @param int $numberOfItems * @param array $folderFilterCallbacks * @param boolean $recursive * @return array */ public function fetchFolderListFromDriver($path, $start = 0, $numberOfItems = 0, array $folderFilterCallbacks = array(), $recursive = FALSE) { $items = $this->driver->getFolderList($path, $start, $numberOfItems, $folderFilterCallbacks, $recursive); // Exclude the _processed_ folder, so it won't get indexed etc $processingFolder = $this->getProcessingFolder(); if ($processingFolder && $path == '/') { $processedFolderIdentifier = $this->processingFolder->getIdentifier(); $processedFolderIdentifier = trim($processedFolderIdentifier, '/'); if (isset($items[$processedFolderIdentifier])) { unset($items[$processedFolderIdentifier]); } } uksort($items, 'strnatcasecmp'); return $items; }
/** * 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(); }
/** * 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; }
/** * Returns the destination path/fileName of a unique fileName/foldername in that path. * If $theFile exists in $theDest (directory) the file have numbers appended up to $this->maxNumber. Hereafter a unique string will be appended. * This function is used by fx. TCEmain when files are attached to records and needs to be uniquely named in the uploads/* folders * * @param Folder $folder * @param string $theFile The input fileName to check * @param bool $dontCheckForUnique If set the fileName is returned with the path prepended without checking whether it already existed! * * @throws \RuntimeException * @return string A unique fileName inside $folder, based on $theFile. * @see \TYPO3\CMS\Core\Utility\File\BasicFileUtility::getUniqueName() */ protected function getUniqueName(Folder $folder, $theFile, $dontCheckForUnique = false) { static $maxNumber = 99, $uniqueNamePrefix = ''; // Fetches info about path, name, extension of $theFile $origFileInfo = PathUtility::pathinfo($theFile); // Adds prefix if ($uniqueNamePrefix) { $origFileInfo['basename'] = $uniqueNamePrefix . $origFileInfo['basename']; $origFileInfo['filename'] = $uniqueNamePrefix . $origFileInfo['filename']; } // Check if the file exists and if not - return the fileName... // The destinations file $theDestFile = $origFileInfo['basename']; // If the file does NOT exist we return this fileName if (!$this->driver->fileExistsInFolder($theDestFile, $folder->getIdentifier()) || $dontCheckForUnique) { return $theDestFile; } // Well the fileName in its pure form existed. Now we try to append // numbers / unique-strings and see if we can find an available fileName // This removes _xx if appended to the file $theTempFileBody = preg_replace('/_[0-9][0-9]$/', '', $origFileInfo['filename']); $theOrigExt = $origFileInfo['extension'] ? '.' . $origFileInfo['extension'] : ''; for ($a = 1; $a <= $maxNumber + 1; $a++) { // First we try to append numbers if ($a <= $maxNumber) { $insert = '_' . sprintf('%02d', $a); } else { $insert = '_' . substr(md5(uniqid('', true)), 0, 6); } $theTestFile = $theTempFileBody . $insert . $theOrigExt; // The destinations file $theDestFile = $theTestFile; // If the file does NOT exist we return this fileName if (!$this->driver->fileExistsInFolder($theDestFile, $folder->getIdentifier())) { return $theDestFile; } } throw new \RuntimeException('Last possible name "' . $theDestFile . '" is already taken.', 1325194291); }
/** * Generates the "PM" string to sent to expand/collapse items * * @param string $mountKey The mount key / storage UID * @param bool $doExpand Whether to expand/collapse * @param \TYPO3\CMS\Core\Resource\Folder $folderObject The folder object * @param string $treeName The name of the tree * @return string */ protected function generateExpandCollapseParameter($mountKey = NULL, $doExpand = FALSE, \TYPO3\CMS\Core\Resource\Folder $folderObject = NULL, $treeName = NULL) { $parts = array($mountKey !== NULL ? $mountKey : $this->bank, $doExpand == 1 ? 1 : 0, $folderObject !== NULL ? GeneralUtility::md5int($folderObject->getCombinedIdentifier()) : '', $treeName !== NULL ? $treeName : $this->treeName); return implode('_', $parts); }