/**
  * Constructor for initializing the class
  *
  * @return 	void
  * @todo Define visibility
  */
 public function init()
 {
     // Initialize GPvars:
     $this->target = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('target');
     $this->returnUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::sanitizeLocalUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('returnUrl'));
     if (!$this->returnUrl) {
         $this->returnUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir . \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('file_list') . '&id=' . rawurlencode($this->target);
     }
     // Create the folder object
     if ($this->target) {
         $this->folderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->target);
     }
     // 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_upload.html');
     $this->doc->backPath = $GLOBALS['BACK_PATH'];
     $this->doc->form = '<form action="tce_file.php" method="post" name="editform" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '">';
 }
 /**
  * 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;
     }
 }
 /**
  * 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;
     }
 }
Ejemplo n.º 4
0
 /**
  * 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);
             }
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Initialize
  *
  * @return void
  */
 protected function init()
 {
     // Initialize GPvars:
     $this->target = GeneralUtility::_GP('target');
     $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
     if (!$this->returnUrl) {
         $this->returnUrl = GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir . BackendUtility::getModuleUrl('file_list') . '&id=' . rawurlencode($this->target);
     }
     // Create the folder object
     if ($this->target) {
         $this->folderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->target);
     }
     if ($this->folderObject->getStorage()->getUid() === 0) {
         throw new \TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException('You are not allowed to access folders outside your storages', 1375889834);
     }
     // Cleaning and checking target directory
     if (!$this->folderObject) {
         $title = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:paramError', true);
         $message = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:targetNoDir', true);
         throw new \RuntimeException($title . ': ' . $message, 1294586843);
     }
     // Setting the title and the icon
     $icon = $this->iconFactory->getIcon('apps-filetree-root', Icon::SIZE_SMALL)->render();
     $this->title = $icon . htmlspecialchars($this->folderObject->getStorage()->getName()) . ': ' . htmlspecialchars($this->folderObject->getIdentifier());
     // Setting template object
     $this->doc = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
     $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/file_upload.html');
     $this->doc->form = '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('tce_file')) . '" method="post" name="editform" enctype="multipart/form-data">';
 }
Ejemplo n.º 6
0
 /**
  * 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;
 }
Ejemplo n.º 7
0
 /**
  * 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.
  *
  * @return string
  */
 protected function getModuleHeadline()
 {
     $name = $this->folderObject->getName();
     if ($name === '') {
         // Show storage name on storage root
         if ($this->folderObject->getIdentifier() === '/') {
             $name = $this->folderObject->getStorage()->getName();
         }
     } else {
         $name = key(ListUtility::resolveSpecialFolderNames(array($name => $this->folderObject)));
     }
     return $name;
 }
    /**
     * 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;
		');
    }
Ejemplo n.º 9
0
    /**
     * Initialize
     *
     * @return void
     */
    protected function init()
    {
        // Initialize GPvars:
        $this->number = GeneralUtility::_GP('number');
        $this->target = $combinedIdentifier = GeneralUtility::_GP('target');
        $this->returnUrl = GeneralUtility::sanitizeLocalUrl(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 = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:paramError', TRUE);
            $message = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:targetNoDir', TRUE);
            throw new \RuntimeException($title . ': ' . $message, 1294586845);
        }
        if ($this->folderObject->getStorage()->getUid() === 0) {
            throw new \TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException('You are not allowed to access folders outside your storages', 1375889838);
        }
        // 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 = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
        $this->doc->setModuleTemplate('EXT:backend/Resources/Private/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(' . GeneralUtility::quoteJSvalue($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:mess.redraw')) . '))) {
					var params = "&target="+encodeURIComponent(path)+"&number="+a+"&returnUrl=' . rawurlencode($this->returnUrl) . '";
					window.location.href = ' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('file_newfolder')) . '+params;
				}
			}
			function backToList() {	//
				top.goToModule("file_list");
			}

			var changed = 0;
		');
    }
Ejemplo n.º 10
0
    /**
     * Initialize
     *
     * @throws \TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException
     */
    protected function init()
    {
        // Initialize GPvars:
        $this->target = GeneralUtility::_GP('target');
        $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
        // Cleaning and checking target
        if ($this->target) {
            $this->fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->target);
        }
        if (!$this->fileOrFolderObject) {
            $title = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:paramError', TRUE);
            $message = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:targetNoDir', TRUE);
            throw new \RuntimeException($title . ': ' . $message, 1294586844);
        }
        if ($this->fileOrFolderObject->getStorage()->getUid() === 0) {
            throw new \TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException('You are not allowed to access files outside your storages', 1375889840);
        }
        // If a folder should be renamed, AND the returnURL should go to the old directory name, the redirect is forced
        // so the redirect will NOT end in a error message
        // this case only happens if you select the folder itself in the foldertree and then use the clickmenu to
        // rename the folder
        if ($this->fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
            $parsedUrl = parse_url($this->returnUrl);
            $queryParts = GeneralUtility::explodeUrl2Array(urldecode($parsedUrl['query']));
            if ($queryParts['id'] === $this->fileOrFolderObject->getCombinedIdentifier()) {
                $this->returnUrl = str_replace(urlencode($queryParts['id']), urlencode($this->fileOrFolderObject->getStorage()->getRootLevelFolder()->getCombinedIdentifier()), $this->returnUrl);
            }
        }
        // Setting icon and title
        $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('apps-filetree-root');
        $this->title = $icon . htmlspecialchars($this->fileOrFolderObject->getStorage()->getName()) . ': ' . htmlspecialchars($this->fileOrFolderObject->getIdentifier());
        // Setting template object
        $this->doc = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
        $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/file_rename.html');
        $this->doc->backPath = $GLOBALS['BACK_PATH'];
        $this->doc->JScode = $this->doc->wrapScriptTags('
			function backToList() {	//
				top.goToModule("file_list");
			}
		');
    }
Ejemplo n.º 11
0
    /**
     * For TBE: Makes a form for creating new folders in the filemount the user is browsing.
     * The folder creation request is sent to the tce_file.php script in the core which will handle the creation.
     *
     * @param Folder $folderObject Absolute filepath on server in which to create the new folder.
     * @return string HTML for the create folder form.
     * @todo Define visibility
     */
    public function createFolder(Folder $folderObject)
    {
        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 '';
        }
        // Create header, showing upload path:
        $header = $folderObject->getIdentifier();
        $code = '

			<!--
				Form, for creating new folders:
			-->
			<form action="' . $GLOBALS['BACK_PATH'] . 'tce_file.php" method="post" name="editform2" id="typo3-crFolderForm">
				<table border="0" cellpadding="0" cellspacing="0" id="typo3-crFolder">
					<tr>
						<td>' . $this->barheader($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.pagetitle') . ':') . '</td>
					</tr>
					<tr>
						<td class="c-wCell c-hCell"><strong>' . $GLOBALS['LANG']->getLL('path', TRUE) . ':</strong> ' . htmlspecialchars($header) . '</td>
					</tr>
					<tr>
						<td class="c-wCell c-hCell">';
        // Create the new-folder name field:
        $a = 1;
        $code .= '<input' . $this->doc->formWidth(20) . ' type="text" name="file[newfolder][' . $a . '][data]" />' . '<input type="hidden" name="file[newfolder][' . $a . '][target]" value="' . htmlspecialchars($folderObject->getCombinedIdentifier()) . '" />';
        // Make footer of upload form, including the submit button:
        $redirectValue = $this->getThisScript() . 'act=' . $this->act . '&mode=' . $this->mode . '&expandFolder=' . rawurlencode($folderObject->getCombinedIdentifier()) . '&bparams=' . rawurlencode($this->bparams);
        $code .= '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />' . \TYPO3\CMS\Backend\Form\FormEngine::getHiddenTokenField('tceAction') . '<input type="submit" name="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.submit', TRUE) . '" />';
        $code .= '</td>
					</tr>
				</table>
			</form>';
        return $code;
    }
Ejemplo n.º 12
0
 /**
  * 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);
 }
Ejemplo n.º 13
0
 /**
  * Returns TRUE if the input "record" contains a folder which can be linked.
  *
  * @param 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 AND if ->ext_noTempRecyclerDirs is not set.
  */
 public function ext_isLinkable(Folder $folderObject)
 {
     $identifier = $folderObject->getIdentifier();
     return !$this->ext_noTempRecyclerDirs || substr($identifier, -7) !== '_temp_/' && substr($identifier, -11) !== '_recycler_/';
 }
Ejemplo n.º 14
0
    /**
     * For TBE: Makes a form for creating new folders in the filemount the user is browsing.
     * The folder creation request is sent to the tce_file.php script in the core which will handle the creation.
     *
     * @param Folder $folderObject Absolute filepath on server in which to create the new folder.
     * @return string HTML for the create folder form.
     */
    public function createFolder(Folder $folderObject)
    {
        if (!$folderObject->checkActionPermission('write')) {
            return '';
        }
        $backendUser = $this->getBackendUser();
        if (!($backendUser->isAdmin() || $backendUser->getTSConfigVal('options.createFoldersInEB'))) {
            return '';
        }
        // Don't show Folder-create form if it's denied
        if ($backendUser->getTSConfigVal('options.folderTree.hideCreateFolder')) {
            return '';
        }
        $lang = $this->getLanguageService();
        // Create header, showing upload path:
        $header = $folderObject->getIdentifier();
        $code = '

			<!--
				Form, for creating new folders:
			-->
			<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('tce_file')) . '" method="post" name="editform2" id="typo3-crFolderForm">
				<table border="0" cellpadding="0" cellspacing="0" id="typo3-crFolder">
					<tr>
						<td>' . $this->barheader($lang->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.pagetitle') . ':') . '</td>
					</tr>
					<tr>
						<td class="c-wCell c-hCell"><strong>' . $lang->getLL('path', true) . ':</strong> ' . htmlspecialchars($header) . '</td>
					</tr>
					<tr>
						<td class="c-wCell c-hCell">';
        // Create the new-folder name field:
        $a = 1;
        $code .= '<input' . $this->doc->formWidth(20) . ' type="text" name="file[newfolder][' . $a . '][data]" />' . '<input type="hidden" name="file[newfolder][' . $a . '][target]" value="' . htmlspecialchars($folderObject->getCombinedIdentifier()) . '" />';
        // Make footer of upload form, including the submit button:
        $redirectValue = $this->getThisScript() . 'act=' . $this->act . '&mode=' . $this->mode . '&expandFolder=' . rawurlencode($folderObject->getCombinedIdentifier()) . '&bparams=' . rawurlencode($this->bparams) . (is_array($this->P) ? GeneralUtility::implodeArrayForUrl('P', $this->P) : '');
        $code .= '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />' . '<input class="btn btn-default" type="submit" name="submit" value="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_newfolder.php.submit', true) . '" />';
        $code .= '</td>
					</tr>
				</table>
			</form>';
        return $code;
    }
 /**
  * Update folder permissions records when a folder is renamed
  *
  * @param Folder $folder
  * @param string $newName
  */
 public function postFolderRename(Folder $folder, $newName)
 {
     $newFolder = $folder->getParentFolder()->getSubfolder($newName);
     $oldStorageUid = $folder->getStorage()->getUid();
     $newStorageUid = $newFolder->getStorage()->getUid();
     $this->utilityService->updateFolderRecord($oldStorageUid, $folder->getHashedIdentifier(), $folder->getIdentifier(), array('storage' => $newStorageUid, 'folder_hash' => $newFolder->getHashedIdentifier(), 'folder' => $newFolder->getIdentifier()));
     if (!empty($this->folderMapping[$folder->getCombinedIdentifier()])) {
         $newMapping = $this->getSubFolderIdentifiers($newFolder);
         foreach ($this->folderMapping[$folder->getCombinedIdentifier()] as $key => $folderInfo) {
             $this->utilityService->updateFolderRecord($oldStorageUid, $folderInfo[0], $folderInfo[1], array('storage' => $newStorageUid, 'folder_hash' => $newMapping[$key][0], 'folder' => $newMapping[$key][1]));
         }
     }
 }
Ejemplo n.º 16
0
 /**
  * Creates a new file and returns the matching file object for it.
  *
  * @param string $fileName
  * @param \TYPO3\CMS\Core\Resource\Folder $parentFolder
  * @return \TYPO3\CMS\Core\Resource\File
  */
 public function createFile($fileName, \TYPO3\CMS\Core\Resource\Folder $parentFolder)
 {
     if (!$this->isValidFilename($fileName)) {
         throw new \TYPO3\CMS\Core\Resource\Exception\InvalidFileNameException('Invalid characters in fileName "' . $fileName . '"', 1320572272);
     }
     $filePath = $parentFolder->getIdentifier() . ltrim($fileName, '/');
     // TODO set permissions of new file
     $result = touch($this->absoluteBasePath . $filePath);
     clearstatcache();
     if ($result !== TRUE) {
         throw new \RuntimeException('Creating file ' . $filePath . ' failed.', 1320569854);
     }
     $fileInfo = $this->getFileInfoByIdentifier($filePath);
     return $this->getFileObject($fileInfo);
 }
 /**
  * Returns an array of the persistable properties and contents
  * which are processable by TCEmain.
  *
  * @return array
  */
 protected function getPersistableDataArray()
 {
     return array('title' => $this->getTitle(), 'type' => self::$type, 'description' => $this->getDescription(), 'folder' => $this->folder->getIdentifier(), 'storage' => $this->folder->getStorage()->getUid());
 }
Ejemplo n.º 18
0
 /**
  * Returns the index-data of all files within that folder
  *
  * @param \TYPO3\CMS\Core\Resource\Folder $folder
  * @return array
  */
 public function getFileIndexRecordsForFolder(\TYPO3\CMS\Core\Resource\Folder $folder)
 {
     $identifier = $folder->getIdentifier();
     $storage = $folder->getStorage()->getUid();
     $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', $this->table, sprintf('storage=%u AND identifier LIKE "%s" AND NOT identifier LIKE "%s"', $storage, $GLOBALS['TYPO3_DB']->escapeStrForLike($identifier, $this->table) . '%', $GLOBALS['TYPO3_DB']->escapeStrForLike($identifier, $this->table) . '%/%'), '', '', '', 'identifier');
     return (array) $rows;
 }
Ejemplo n.º 19
0
 /**
  * Creates the edit control section
  *
  * @param File|Folder $fileOrFolderObject Array with information about the file/directory for which to make the edit control section for the listing.
  * @return string HTML-table
  */
 public function makeEdit($fileOrFolderObject)
 {
     $cells = [];
     $fullIdentifier = $fileOrFolderObject->getCombinedIdentifier();
     // Edit file content (if editable)
     if ($fileOrFolderObject instanceof File && $fileOrFolderObject->checkActionPermission('write') && GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], $fileOrFolderObject->getExtension())) {
         $url = BackendUtility::getModuleUrl('file_edit', ['target' => $fullIdentifier]);
         $editOnClick = 'top.list_frame.location.href=' . GeneralUtility::quoteJSvalue($url) . '+\'&returnUrl=\'+top.rawurlencode(top.list_frame.document.location.pathname+top.list_frame.document.location.search);return false;';
         $cells['edit'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($editOnClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.editcontent') . '">' . $this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL)->render() . '</a>';
     } else {
         $cells['edit'] = $this->spaceIcon;
     }
     if ($fileOrFolderObject instanceof File) {
         $fileUrl = $fileOrFolderObject->getPublicUrl(true);
         if ($fileUrl) {
             $aOnClick = 'return top.openUrlInWindow(' . GeneralUtility::quoteJSvalue($fileUrl) . ', \'WebFile\');';
             $cells['view'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($aOnClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.view') . '">' . $this->iconFactory->getIcon('actions-document-view', Icon::SIZE_SMALL)->render() . '</a>';
         } else {
             $cells['view'] = $this->spaceIcon;
         }
     } else {
         $cells['view'] = $this->spaceIcon;
     }
     // replace file
     if ($fileOrFolderObject instanceof File && $fileOrFolderObject->checkActionPermission('replace')) {
         $url = BackendUtility::getModuleUrl('file_replace', ['target' => $fullIdentifier, 'uid' => $fileOrFolderObject->getUid()]);
         $replaceOnClick = 'top.list_frame.location.href = ' . GeneralUtility::quoteJSvalue($url) . '+\'&returnUrl=\'+top.rawurlencode(top.list_frame.document.location.pathname+top.list_frame.document.location.search);return false;';
         $cells['replace'] = '<a href="#" class="btn btn-default" onclick="' . $replaceOnClick . '"  title="' . $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.replace') . '">' . $this->iconFactory->getIcon('actions-edit-replace', Icon::SIZE_SMALL)->render() . '</a>';
     }
     // rename the file
     if ($fileOrFolderObject->checkActionPermission('rename')) {
         $url = BackendUtility::getModuleUrl('file_rename', ['target' => $fullIdentifier]);
         $renameOnClick = 'top.list_frame.location.href = ' . GeneralUtility::quoteJSvalue($url) . '+\'&returnUrl=\'+top.rawurlencode(top.list_frame.document.location.pathname+top.list_frame.document.location.search);return false;';
         $cells['rename'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($renameOnClick) . '"  title="' . $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.rename') . '">' . $this->iconFactory->getIcon('actions-edit-rename', Icon::SIZE_SMALL)->render() . '</a>';
     } else {
         $cells['rename'] = $this->spaceIcon;
     }
     if ($fileOrFolderObject->checkActionPermission('read')) {
         $infoOnClick = '';
         if ($fileOrFolderObject instanceof Folder) {
             $infoOnClick = 'top.launchView( \'_FOLDER\', ' . GeneralUtility::quoteJSvalue($fullIdentifier) . ');return false;';
         } elseif ($fileOrFolderObject instanceof File) {
             $infoOnClick = 'top.launchView( \'_FILE\', ' . GeneralUtility::quoteJSvalue($fullIdentifier) . ');return false;';
         }
         $cells['info'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($infoOnClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.info') . '">' . $this->iconFactory->getIcon('actions-document-info', Icon::SIZE_SMALL)->render() . '</a>';
     } else {
         $cells['info'] = $this->spaceIcon;
     }
     // delete the file
     if ($fileOrFolderObject->checkActionPermission('delete')) {
         $identifier = $fileOrFolderObject->getIdentifier();
         if ($fileOrFolderObject instanceof Folder) {
             $referenceCountText = BackendUtility::referenceCount('_FILE', $identifier, ' ' . $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.referencesToFolder'));
             $deleteType = 'delete_folder';
         } else {
             $referenceCountText = BackendUtility::referenceCount('sys_file', $fileOrFolderObject->getUid(), ' ' . $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.referencesToFile'));
             $deleteType = 'delete_file';
         }
         if ($this->getBackendUser()->jsConfirmation(JsConfirmation::DELETE)) {
             $confirmationCheck = '1';
         } else {
             $confirmationCheck = '0';
         }
         $deleteUrl = BackendUtility::getModuleUrl('tce_file');
         $confirmationMessage = sprintf($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:mess.delete'), $fileOrFolderObject->getName()) . $referenceCountText;
         $title = $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.delete');
         $cells['delete'] = '<a href="#" class="btn btn-default t3js-filelist-delete" data-content="' . htmlspecialchars($confirmationMessage) . '" data-check="' . $confirmationCheck . '" data-delete-url="' . htmlspecialchars($deleteUrl) . '" data-title="' . htmlspecialchars($title) . '" data-identifier="' . htmlspecialchars($fileOrFolderObject->getCombinedIdentifier()) . '" data-veri-code="' . $this->getBackendUser()->veriCode() . '" data-delete-type="' . $deleteType . '" title="' . htmlspecialchars($title) . '">' . $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render() . '</a>';
     } else {
         $cells['delete'] = $this->spaceIcon;
     }
     // Hook for manipulating edit icons.
     if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'])) {
         $cells['__fileOrFolderObject'] = $fileOrFolderObject;
         foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'] as $classData) {
             $hookObject = GeneralUtility::getUserObj($classData);
             if (!$hookObject instanceof FileListEditIconHookInterface) {
                 throw new \UnexpectedValueException($classData . ' must implement interface ' . FileListEditIconHookInterface::class, 1235225797);
             }
             $hookObject->manipulateEditIcons($cells, $this);
         }
         unset($cells['__fileOrFolderObject']);
     }
     // Compile items into a DIV-element:
     return '<div class="btn-group">' . implode('', $cells) . '</div>';
 }
Ejemplo n.º 20
0
 /**
  * Returns some data specific for the directories...
  *
  * @param \TYPO3\CMS\Core\Resource\Folder $folderObject File information array
  * @return array (title, icon, path)
  * @deprecated since 6.2 - will be removed two versions later without replacement
  */
 public function dirData(\TYPO3\CMS\Core\Resource\Folder $folderObject)
 {
     GeneralUtility::logDeprecatedFunction();
     $title = htmlspecialchars($folderObject->getName());
     $icon = 'apps-filetree-folder-default';
     $role = $folderObject->getRole();
     if ($role === FolderInterface::ROLE_TEMPORARY) {
         $title = '<strong>' . $GLOBALS['LANG']->getLL('temp', TRUE) . '</strong>';
         $icon = 'apps-filetree-folder-temp';
     } elseif ($role === FolderInterface::ROLE_RECYCLER) {
         $icon = 'apps-filetree-folder-recycler';
         $title = '<strong>' . $GLOBALS['LANG']->getLL('recycler', TRUE) . '</strong>';
     }
     return array($title, $icon, $folderObject->getIdentifier());
 }
Ejemplo n.º 21
0
 /**
  * Adds a file from the local server hard disk to a given path in TYPO3s virtual file system.
  *
  * This assumes that the local file exists, so no further check is done here!
  *
  * @param string $localFilePath
  * @param \TYPO3\CMS\Core\Resource\Folder $targetFolder
  * @param string $fileName The name to add the file under
  * @param \TYPO3\CMS\Core\Resource\AbstractFile $updateFileObject Optional file object to update (instead of creating a new object). With this parameter, this function can be used to "populate" a dummy file object with a real file underneath.
  * @return \TYPO3\CMS\Core\Resource\FileInterface
  */
 public function addFile($localFilePath, \TYPO3\CMS\Core\Resource\Folder $targetFolder, $fileName, \TYPO3\CMS\Core\Resource\AbstractFile $updateFileObject = null)
 {
     // TODO: Implement addFile() method.
     error_log('FAL DRIVER: ' . __FUNCTION__ . ' Folder: ' . $targetFolder->getCombinedIdentifier() . ' FileName ' . $fileName) . 'FileObject ';
     if ($targetFolder == $this->storage->getProcessingFolder()) {
         $yagTempFolder = 'typo3temp/yag';
         // TODO: use configured value
         $falTempFolder = $this->yagFileSystemDiv->makePathAbsolute($yagTempFolder . $targetFolder->getIdentifier());
         $this->yagFileSystemDiv->checkDirAndCreateIfMissing($falTempFolder);
         $falTempFilePath = \Tx_Yag_Domain_FileSystem_Div::concatenatePaths(array($falTempFolder, $fileName));
         rename($localFilePath, $falTempFilePath);
     }
     return $this->getFile($falTempFilePath);
 }
Ejemplo n.º 22
0
 /**
  * @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;
 }
Ejemplo n.º 23
0
 /**
  * Returns some data specific for the directories...
  *
  * @param \TYPO3\CMS\Core\Resource\Folder $folderObject File information array
  * @return array (title, icon, path)
  * @todo Define visibility
  */
 public function dirData(\TYPO3\CMS\Core\Resource\Folder $folderObject)
 {
     $title = htmlspecialchars($folderObject->getName());
     $icon = 'apps-filetree-folder-default';
     if ($title == '_temp_') {
         $icon = 'apps-filetree-folder-temp';
         $title = '<strong>' . $GLOBALS['LANG']->getLL('temp', TRUE) . '</strong>';
     }
     if ($title == '_recycler_') {
         $icon = 'apps-filetree-folder-recycler';
         $title = '<strong>' . $GLOBALS['LANG']->getLL('recycler', TRUE) . '</strong>';
     }
     // Mark the icon as read-only icon if the folder is not writable
     if ($folderObject->checkActionPermission('write') === FALSE) {
         $icon = 'apps-filetree-folder-locked';
     }
     return array($title, $icon, $folderObject->getIdentifier());
 }
Ejemplo n.º 24
0
    /**
     * Render list of files.
     *
     * @param 	array		List of files. See t3lib_div::getFilesInDir
     * @param 	string		If set a header with a folder icon and folder name are shown
     * @param 	boolean		Whether to show thumbnails or not. If set, no thumbnails are shown.
     * @return 	string		HTML output
     * @todo Define visibility
     */
    public function fileList(array $files, \TYPO3\CMS\Core\Resource\Folder $folder = NULL, $noThumbs = 0)
    {
        $out = '';
        // Listing the files:
        if (is_array($files)) {
            $lines = array();
            // Create headline (showing number of files):
            $filesCount = count($files);
            $out .= $this->barheader(sprintf($GLOBALS['LANG']->getLL('files') . ' (%s):', $filesCount));
            $out .= '<div id="filelist">';
            $out .= $this->getBulkSelector($filesCount);
            $titleLen = intval($GLOBALS['BE_USER']->uc['titleLen']);
            // Create the header of current folder:
            if ($folder) {
                $folderIcon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile('folder');
                $lines[] = '<tr class="t3-row-header">
					<td colspan="4">' . $folderIcon . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($folder->getIdentifier(), $titleLen)) . '</td>
				</tr>';
            }
            if ($filesCount == 0) {
                $lines[] = '
					<tr class="file_list_normal">
						<td colspan="4">No files found.</td>
					</tr>';
            }
            // Init graphic object for reading file and image dimensions:
            /** @var $imgObj \TYPO3\CMS\Core\Imaging\GraphicalFunctions */
            $imgObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Imaging\\GraphicalFunctions');
            $imgObj->init();
            $imgObj->mayScaleUp = 0;
            $imgObj->tempPath = PATH_site . $imgObj->tempPath;
            // Traverse the file list:
            /** @var $fileObject \TYPO3\CMS\Core\Resource\File */
            foreach ($files as $fileObject) {
                $fileExtension = $fileObject->getExtension();
                // Thumbnail/size generation:
                if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList(strtolower($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']), strtolower($fileExtension)) && !$noThumbs) {
                    $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"';
                } else {
                    $clickIcon = '';
                    $pDim = '';
                }
                // Create file icon:
                $size = ' (' . \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($fileObject->getSize()) . 'bytes' . ($pDim ? ', ' . $pDim : '') . ')';
                $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile($fileExtension, array('title' => $fileObject->getName() . $size));
                // Create links for adding the file:
                $filesIndex = count($this->elements);
                $this->elements['file_' . $filesIndex] = array('type' => 'file', 'table' => 'sys_file', 'uid' => $fileObject->getUid(), 'fileName' => $fileObject->getName(), 'filePath' => $fileObject->getUid(), 'fileExt' => $fileExtension, 'fileIcon' => $icon);
                $element = $this->elements['file_' . $filesIndex];
                if ($this->act === 'plain' && ($imgInfo[0] > $this->plainMaxWidth || $imgInfo[1] > $this->plainMaxHeight) || !\TYPO3\CMS\Core\Utility\GeneralUtility::inList('jpg,jpeg,gif,png', $fileExtension)) {
                    $ATag = '';
                    $ATag_alt = '';
                    $ATag_e = '';
                } else {
                    $this->elements['file_' . $filesIndex] = array('type' => 'file', 'table' => 'sys_file', 'uid' => $fileObject->getUid(), 'fileName' => $fileObject->getName(), 'filePath' => $fileObject->getUid(), 'fileExt' => $fileExtension, 'fileIcon' => $icon);
                    $ATag = '<a href="#" onclick="return BrowseLinks.File.insertElement(\'file_' . $filesIndex . '\');">';
                    $ATag_alt = substr($ATag, 0, -4) . ',1);">';
                    $ATag_e = '</a>';
                }
                // Create link to showing details about the file in a window:
                $Ahref = $GLOBALS['BACK_PATH'] . 'show_item.php?type=file&table=' . rawurlencode($fileObject->getCombinedIdentifier()) . '&returnUrl=' . rawurlencode(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI'));
                $ATag2 = '<a href="' . htmlspecialchars($Ahref) . '">';
                $ATag2_e = '</a>';
                // Combine the stuff:
                $filenameAndIcon = $ATag_alt . $icon . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($fileObject->getName(), $titleLen)) . $ATag_e;
                // Show element:
                if ($pDim) {
                    // Image...
                    $lines[] = '
						<tr class="file_list_normal">
							<td nowrap="nowrap">' . $filenameAndIcon . '&nbsp;</td>
							<td nowrap="nowrap">' . ($ATag2 . '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/zoom2.gif', 'width="12" height="12"') . ' title="' . $GLOBALS['LANG']->getLL('info', 1) . '" alt="" /> ' . $GLOBALS['LANG']->getLL('info', 1) . $ATag2_e) . '</td>
							<td nowrap="nowrap">&nbsp;' . $pDim . '</td>
						</tr>';
                    $lines[] = '
						<tr>
							<td class="filelistThumbnail" colspan="4">' . $ATag_alt . $clickIcon . $ATag_e . '</td>
						</tr>';
                } else {
                    $lines[] = '
						<tr class="file_list_normal">
							<td nowrap="nowrap">' . $filenameAndIcon . '&nbsp;</td>
							<td nowrap="nowrap">' . ($ATag2 . '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/zoom2.gif', 'width="12" height="12"') . ' title="' . $GLOBALS['LANG']->getLL('info', 1) . '" alt="" /> ' . $GLOBALS['LANG']->getLL('info', 1) . $ATag2_e) . '</td>
							<td>&nbsp;</td>
						</tr>';
                }
            }
            // Wrap all the rows in table tags:
            $out .= '



		<!--
			File listing
		-->
				<table cellpadding="0" cellspacing="0" id="typo3-filelist">
					' . implode('', $lines) . '
				</table>';
        }
        // Return accumulated content for filelisting:
        $out .= '</div>';
        return $out;
    }
Ejemplo n.º 25
0
 /**
  * @param Folder $parentFolder
  * @return bool
  */
 protected function folderIsInsideSelectedStorage(Folder $parentFolder)
 {
     $parentFolderIdentifier = $parentFolder->getIdentifier();
     $selectedFolderIdentifier = $this->selectedFolder->getIdentifier();
     if (substr($parentFolderIdentifier, 0, strlen($selectedFolderIdentifier)) === $selectedFolderIdentifier) {
         return true;
     }
     return false;
 }
Ejemplo n.º 26
0
 /**
  * Creates the edit control section
  *
  * @param File|Folder $fileOrFolderObject Array with information about the file/directory for which to make the edit control section for the listing.
  * @return string HTML-table
  */
 public function makeEdit($fileOrFolderObject)
 {
     $cells = array();
     $fullIdentifier = $fileOrFolderObject->getCombinedIdentifier();
     // Edit file content (if editable)
     if ($fileOrFolderObject instanceof File && $fileOrFolderObject->checkActionPermission('write') && GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], $fileOrFolderObject->getExtension())) {
         $url = BackendUtility::getModuleUrl('file_edit', array('target' => $fullIdentifier));
         $editOnClick = 'top.content.list_frame.location.href=' . GeneralUtility::quoteJSvalue($url) . '+\'&returnUrl=\'+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search);return false;';
         $cells['edit'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($editOnClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.editcontent') . '">' . IconUtility::getSpriteIcon('actions-page-open') . '</a>';
     } else {
         $cells['edit'] = $this->spaceIcon;
     }
     if ($fileOrFolderObject instanceof File) {
         $fileUrl = $fileOrFolderObject->getPublicUrl(TRUE);
         if ($fileUrl) {
             $aOnClick = 'return top.openUrlInWindow(' . GeneralUtility::quoteJSvalue($fileUrl) . ', \'WebFile\');';
             $cells['view'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($aOnClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.view') . '">' . IconUtility::getSpriteIcon('actions-document-view') . '</a>';
         } else {
             $cells['view'] = $this->spaceIcon;
         }
     } else {
         $cells['view'] = $this->spaceIcon;
     }
     // rename the file
     if ($fileOrFolderObject->checkActionPermission('rename')) {
         $url = BackendUtility::getModuleUrl('file_rename', array('target' => $fullIdentifier));
         $renameOnClick = 'top.content.list_frame.location.href = ' . GeneralUtility::quoteJSvalue($url) . '+\'&returnUrl=\'+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search);return false;';
         $cells['rename'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($renameOnClick) . '"  title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.rename') . '">' . IconUtility::getSpriteIcon('actions-edit-rename') . '</a>';
     } else {
         $cells['rename'] = $this->spaceIcon;
     }
     if ($fileOrFolderObject->checkActionPermission('read')) {
         $infoOnClick = '';
         if ($fileOrFolderObject instanceof Folder) {
             $infoOnClick = 'top.launchView( \'_FOLDER\', ' . GeneralUtility::quoteJSvalue($fullIdentifier) . ');return false;';
         } elseif ($fileOrFolderObject instanceof File) {
             $infoOnClick = 'top.launchView( \'_FILE\', ' . GeneralUtility::quoteJSvalue($fullIdentifier) . ');return false;';
         }
         $cells['info'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($infoOnClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.info') . '">' . IconUtility::getSpriteIcon('status-dialog-information') . '</a>';
     } else {
         $cells['info'] = $this->spaceIcon;
     }
     // delete the file
     if ($fileOrFolderObject->checkActionPermission('delete')) {
         $identifier = $fileOrFolderObject->getIdentifier();
         if ($fileOrFolderObject instanceof Folder) {
             $referenceCountText = BackendUtility::referenceCount('_FILE', $identifier, ' (There are %s reference(s) to this folder!)');
         } else {
             $referenceCountText = BackendUtility::referenceCount('sys_file', $fileOrFolderObject->getUid(), ' (There are %s reference(s) to this file!)');
         }
         if ($this->getBackendUser()->jsConfirmation(JsConfirmation::DELETE)) {
             $confirmationCheck = 'confirm(' . GeneralUtility::quoteJSvalue(sprintf($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:mess.delete'), $fileOrFolderObject->getName()) . $referenceCountText) . ')';
         } else {
             $confirmationCheck = '1 == 1';
         }
         $removeOnClick = 'if (' . $confirmationCheck . ') { top.content.list_frame.location.href=' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('tce_file') . '&file[delete][0][data]=' . rawurlencode($fileOrFolderObject->getCombinedIdentifier()) . '&vC=' . $this->getBackendUser()->veriCode() . BackendUtility::getUrlToken('tceAction') . '&redirect=') . '+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search);};';
         $cells['delete'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($removeOnClick) . '"  title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.delete') . '">' . IconUtility::getSpriteIcon('actions-edit-delete') . '</a>';
     } else {
         $cells['delete'] = $this->spaceIcon;
     }
     // Hook for manipulating edit icons.
     if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'])) {
         foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['fileList']['editIconsHook'] as $classData) {
             $hookObject = GeneralUtility::getUserObj($classData);
             if (!$hookObject instanceof FileListEditIconHookInterface) {
                 throw new \UnexpectedValueException('$hookObject must implement interface \\TYPO3\\CMS\\Filelist\\FileListEditIconHookInterface', 1235225797);
             }
             $hookObject->manipulateEditIcons($cells, $this);
         }
     }
     // Compile items into a DIV-element:
     return '<div class="btn-group">' . implode('', $cells) . '</div>';
 }
Ejemplo n.º 27
0
 /**
  * Makes an upload form for uploading files to the filemount the user is browsing.
  * The files are uploaded to the tce_file.php script in the core which will handle the upload.
  *
  * @param Folder $folderObject
  * @param string[] $allowedExtensions
  *
  * @return string HTML for an upload form.
  */
 public function uploadForm(Folder $folderObject, array $allowedExtensions)
 {
     if (!$folderObject->checkActionPermission('write')) {
         return '';
     }
     // Read configuration of upload field count
     $userSetting = $this->getBackendUser()->getTSConfigVal('options.folderTree.uploadFieldsInLinkBrowser');
     $count = isset($userSetting) ? (int) $userSetting : 1;
     if ($count === 0) {
         return '';
     }
     $count = (int) $count === 0 ? 1 : (int) $count;
     // Create header, showing upload path:
     $header = $folderObject->getIdentifier();
     $lang = $this->getLanguageService();
     // Create a list of allowed file extensions with the readable format "youtube, vimeo" etc.
     $fileExtList = array();
     foreach ($allowedExtensions as $fileExt) {
         if (GeneralUtility::verifyFilenameAgainstDenyPattern($fileExt)) {
             $fileExtList[] = '<span class="label label-success">' . strtoupper(htmlspecialchars($fileExt)) . '</span>';
         }
     }
     $formAction = BackendUtility::getModuleUrl('tce_file');
     $combinedIdentifier = $folderObject->getCombinedIdentifier();
     $markup = array();
     $markup[] = '<div class="element-browser-section element-browser-upload">';
     $markup[] = '   <form action="' . htmlspecialchars($formAction) . '" method="post" name="editform" enctype="multipart/form-data">';
     $markup[] = '   <h3>' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.pagetitle', true) . ':</h3>';
     $markup[] = '   <p><strong>' . $lang->getLL('path', true) . ':</strong>' . htmlspecialchars($header) . '</p>';
     // Traverse the number of upload fields:
     for ($a = 1; $a <= $count; $a++) {
         $markup[] = '<div class="form-group">';
         $markup[] = '<span class="btn btn-default btn-file">';
         $markup[] = '<input type="file" multiple="multiple" name="upload_' . $a . '[]" size="50" />';
         $markup[] = '</span>';
         $markup[] = '</div>';
         $markup[] = '<input type="hidden" name="file[upload][' . $a . '][target]" value="' . htmlspecialchars($combinedIdentifier) . '" />';
         $markup[] = '<input type="hidden" name="file[upload][' . $a . '][data]" value="' . $a . '" />';
     }
     $redirectValue = $this->parameterProvider->getScriptUrl() . GeneralUtility::implodeArrayForUrl('', $this->parameterProvider->getUrlParameters(['identifier' => $combinedIdentifier]));
     $markup[] = '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />';
     if (!empty($fileExtList)) {
         $markup[] = '<div class="form-group">';
         $markup[] = '    <label>';
         $markup[] = $lang->sL('LLL:EXT:lang/locallang_core.xlf:cm.allowedFileExtensions', true) . '<br/>';
         $markup[] = '    </label>';
         $markup[] = '    <div class="form-control">';
         $markup[] = implode(' ', $fileExtList);
         $markup[] = '    </div>';
         $markup[] = '</div>';
     }
     $markup[] = '<div class="checkbox">';
     $markup[] = '    <label>';
     $markup[] = '    <input type="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="1" />';
     $markup[] = $lang->sL('LLL:EXT:lang/locallang_misc.xlf:overwriteExistingFiles', true);
     $markup[] = '    </label>';
     $markup[] = '</div>';
     $markup[] = '<input class="btn btn-default" type="submit" name="submit" value="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.submit', true) . '" />';
     $markup[] = '   </form>';
     $markup[] = '</div>';
     $code = implode(LF, $markup);
     // Add online media
     // Create a list of allowed file extensions in a readable format "youtube, vimeo" etc.
     $fileExtList = array();
     $onlineMediaFileExt = OnlineMediaHelperRegistry::getInstance()->getSupportedFileExtensions();
     foreach ($onlineMediaFileExt as $fileExt) {
         if (GeneralUtility::verifyFilenameAgainstDenyPattern($fileExt) && (empty($allowedExtensions) || in_array($fileExt, $allowedExtensions, true))) {
             $fileExtList[] = '<span class="label label-success">' . strtoupper(htmlspecialchars($fileExt)) . '</span>';
         }
     }
     if (!empty($fileExtList)) {
         $formAction = BackendUtility::getModuleUrl('online_media');
         $markup = array();
         $markup[] = '<div class="element-browser-section element-browser-mediaurls">';
         $markup[] = '   <form action="' . htmlspecialchars($formAction) . '" method="post" name="editform1" id="typo3-addMediaForm" enctype="multipart/form-data">';
         $markup[] = '<h3>' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media', true) . ':</h3>';
         $markup[] = '<p><strong>' . $lang->getLL('path', true) . ':</strong>' . htmlspecialchars($header) . '</p>';
         $markup[] = '<div class="form-group">';
         $markup[] = '<input type="hidden" name="file[newMedia][0][target]" value="' . htmlspecialchars($folderObject->getCombinedIdentifier()) . '" />';
         $markup[] = '<input type="hidden" name="file[newMedia][0][allowed]" value="' . htmlspecialchars(implode(',', $allowedExtensions)) . '" />';
         $markup[] = '<input type="text" name="file[newMedia][0][url]" class="form-control" placeholder="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media.placeholder', true) . '" />';
         $markup[] = '<button class="btn btn-default">' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media.submit', true) . '</button>';
         $markup[] = '</div>';
         $markup[] = '<div class="form-group">';
         $markup[] = '    <label>';
         $markup[] = $lang->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media.allowedProviders') . '<br/>';
         $markup[] = '    </label>';
         $markup[] = '    <div class="form-control">';
         $markup[] = implode(' ', $fileExtList);
         $markup[] = '    </div>';
         $markup[] = '</div>';
         $markup[] = '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />';
         $markup[] = '</div>';
         $markup[] = '</form>';
         $markup[] = '</div>';
         $code .= implode(LF, $markup);
     }
     return $code;
 }
Ejemplo n.º 28
0
 /**
  * At the end of the import process all file and DB relations should be set properly (that is relations
  * to imported records are all re-created so imported records are correctly related again)
  * Relations in flexform fields are processed in setFlexFormRelations() after this function
  *
  * @return void
  * @see setFlexFormRelations()
  */
 public function setRelations()
 {
     $updateData = array();
     // import_newId contains a register of all records that was in the import memorys "records" key
     foreach ($this->import_newId as $nId => $dat) {
         $table = $dat['table'];
         $uid = $dat['uid'];
         // original UID - NOT the new one!
         // If the record has been written and received a new id, then proceed:
         if (is_array($this->import_mapId[$table]) && isset($this->import_mapId[$table][$uid])) {
             $thisNewUid = BackendUtility::wsMapId($table, $this->import_mapId[$table][$uid]);
             if (is_array($this->dat['records'][$table . ':' . $uid]['rels'])) {
                 $thisNewPageUid = 0;
                 if ($this->legacyImport) {
                     if ($table != 'pages') {
                         $oldPid = $this->dat['records'][$table . ':' . $uid]['data']['pid'];
                         $thisNewPageUid = BackendUtility::wsMapId($table, $this->import_mapId['pages'][$oldPid]);
                     } else {
                         $thisNewPageUid = $thisNewUid;
                     }
                 }
                 // Traverse relation fields of each record
                 foreach ($this->dat['records'][$table . ':' . $uid]['rels'] as $field => $config) {
                     // uid_local of sys_file_reference needs no update because the correct reference uid was already written
                     // @see ImportExport::fixUidLocalInSysFileReferenceRecords()
                     if ($table === 'sys_file_reference' && $field === 'uid_local') {
                         continue;
                     }
                     switch ((string) $config['type']) {
                         case 'db':
                             if (is_array($config['itemArray']) && !empty($config['itemArray'])) {
                                 $itemConfig = $GLOBALS['TCA'][$table]['columns'][$field]['config'];
                                 $valArray = $this->setRelations_db($config['itemArray'], $itemConfig);
                                 $updateData[$table][$thisNewUid][$field] = implode(',', $valArray);
                             }
                             break;
                         case 'file':
                             if (is_array($config['newValueFiles']) && !empty($config['newValueFiles'])) {
                                 $valArr = array();
                                 foreach ($config['newValueFiles'] as $fI) {
                                     $valArr[] = $this->import_addFileNameToBeCopied($fI);
                                 }
                                 if ($this->legacyImport && $this->legacyImportFolder === null && isset($this->legacyImportMigrationTables[$table][$field])) {
                                     // Do nothing - the legacy import folder is missing
                                 } elseif ($this->legacyImport && $this->legacyImportFolder !== null && isset($this->legacyImportMigrationTables[$table][$field])) {
                                     $refIds = array();
                                     foreach ($valArr as $tempFile) {
                                         $fileName = $this->alternativeFileName[$tempFile];
                                         $fileObject = null;
                                         try {
                                             // check, if there is alreay the same file in the folder
                                             if ($this->legacyImportFolder->hasFile($fileName)) {
                                                 $fileStorage = $this->legacyImportFolder->getStorage();
                                                 $file = $fileStorage->getFile($this->legacyImportFolder->getIdentifier() . $fileName);
                                                 if ($file->getSha1() === sha1_file($tempFile)) {
                                                     $fileObject = $file;
                                                 }
                                             }
                                         } catch (Exception $e) {
                                         }
                                         if ($fileObject === null) {
                                             try {
                                                 $fileObject = $this->legacyImportFolder->addFile($tempFile, $fileName, DuplicationBehavior::RENAME);
                                             } catch (Exception $e) {
                                                 $this->error('Error: no file could be added to the storage for file name' . $this->alternativeFileName[$tempFile]);
                                             }
                                         }
                                         if ($fileObject !== null) {
                                             $refId = StringUtility::getUniqueId('NEW');
                                             $refIds[] = $refId;
                                             $updateData['sys_file_reference'][$refId] = array('uid_local' => $fileObject->getUid(), 'uid_foreign' => $thisNewUid, 'tablenames' => $table, 'fieldname' => $field, 'pid' => $thisNewPageUid, 'table_local' => 'sys_file');
                                         }
                                     }
                                     $updateData[$table][$thisNewUid][$field] = implode(',', $refIds);
                                     if (!empty($this->legacyImportMigrationTables[$table][$field])) {
                                         $this->legacyImportMigrationRecords[$table][$thisNewUid][$field] = $refIds;
                                     }
                                 } else {
                                     $updateData[$table][$thisNewUid][$field] = implode(',', $valArr);
                                 }
                             }
                             break;
                     }
                 }
             } else {
                 $this->error('Error: no record was found in data array!');
             }
         } else {
             $this->error('Error: this records is NOT created it seems! (' . $table . ':' . $uid . ')');
         }
     }
     if (!empty($updateData)) {
         $tce = $this->getNewTCE();
         $tce->isImporting = true;
         $this->callHook('before_setRelation', array('tce' => &$tce, 'data' => &$updateData));
         $tce->start($updateData, array());
         $tce->process_datamap();
         // Replace the temporary "NEW" ids with the final ones.
         foreach ($this->legacyImportMigrationRecords as $table => $records) {
             foreach ($records as $uid => $fields) {
                 foreach ($fields as $field => $referenceIds) {
                     foreach ($referenceIds as $key => $referenceId) {
                         $this->legacyImportMigrationRecords[$table][$uid][$field][$key] = $tce->substNEWwithIDs[$referenceId];
                     }
                 }
             }
         }
         $this->callHook('after_setRelations', array('tce' => &$tce));
     }
 }
Ejemplo n.º 29
0
 /**
  * Auto-resizes a given source file (possibly converting it as well).
  *
  * @param string $targetFileName
  * @param \TYPO3\CMS\Core\Resource\Folder $folder
  * @param string $sourceFile
  * @return void
  */
 public function preFileAdd(&$targetFileName, \TYPO3\CMS\Core\Resource\Folder $folder, $sourceFile)
 {
     $storageConfiguration = $folder->getStorage()->getConfiguration();
     $storageRecord = $folder->getStorage()->getStorageRecord();
     if ($storageRecord['driver'] !== 'Local') {
         // Unfortunately unsupported yet
         return;
     }
     if (static::$originalFileName) {
         // Temporarily change back the file name to ensure original format is used
         // when converting from one format to another with IM/GM
         $targetFileName = static::$originalFileName;
         static::$originalFileName = null;
     }
     $targetDirectory = $storageConfiguration['pathType'] === 'relative' ? PATH_site : '';
     $targetDirectory .= rtrim(rtrim($storageConfiguration['basePath'], '/') . $folder->getIdentifier(), '/');
     $extension = strtolower(substr($targetFileName, strrpos($targetFileName, '.') + 1));
     // Various operation (including IM/GM) relies on a file WITH an extension
     $originalSourceFile = $sourceFile;
     $sourceFile .= '.' . $extension;
     if (rename($originalSourceFile, $sourceFile)) {
         $newSourceFile = $this->processFile($sourceFile, $targetFileName, $targetDirectory);
         $newExtension = strtolower(substr($newSourceFile, strrpos($newSourceFile, '.') + 1));
         // We must go back to original (temporary) file name
         rename($newSourceFile, $originalSourceFile);
         if ($newExtension !== $extension) {
             $targetFileName = substr($targetFileName, 0, -strlen($extension)) . $newExtension;
         }
     }
 }