/**
  * Main rendering method (getting the preview image url)
  */
 public function render()
 {
     $originalFile = $this->arguments['fileReference']->getOriginalFile();
     $onlineMediaHelper = OnlineMediaHelperRegistry::getInstance()->getOnlineMediaHelper($originalFile);
     if (!$onlineMediaHelper) {
         return false;
     }
     return $onlineMediaHelper->getPublicUrl($originalFile);
 }
 /**
  * Main rendering method (getting the preview image url)
  */
 public function render()
 {
     $originalFile = $this->arguments['fileReference']->getOriginalFile();
     $onlineMediaHelper = OnlineMediaHelperRegistry::getInstance()->getOnlineMediaHelper($originalFile);
     if (!$onlineMediaHelper) {
         return false;
     }
     $previewImagePathAbsolute = $onlineMediaHelper->getPreviewImage($originalFile);
     $previewImagePathRelative = str_replace(PATH_site, '/', $previewImagePathAbsolute);
     return $previewImagePathRelative;
 }
 /**
  * Get online media helper
  *
  * @param FileInterface $file
  * @return bool|OnlineMediaHelperInterface
  */
 protected function getOnlineMediaHelper(FileInterface $file)
 {
     if ($this->onlineMediaHelper === null) {
         $orgFile = $file;
         if ($orgFile instanceof FileReference) {
             $orgFile = $orgFile->getOriginalFile();
         }
         if ($orgFile instanceof File) {
             $this->onlineMediaHelper = OnlineMediaHelperRegistry::getInstance()->getOnlineMediaHelper($orgFile);
         } else {
             $this->onlineMediaHelper = false;
         }
     }
     return $this->onlineMediaHelper;
 }
 /**
  * Process file
  * Create static image preview for Online Media item when possible
  *
  * @param FileProcessingService $fileProcessingService
  * @param AbstractDriver $driver
  * @param ProcessedFile $processedFile
  * @param File $file
  * @param string $taskType
  * @param array $configuration
  */
 public function processFile(FileProcessingService $fileProcessingService, AbstractDriver $driver, ProcessedFile $processedFile, File $file, $taskType, array $configuration)
 {
     if ($taskType !== 'Image.Preview' && $taskType !== 'Image.CropScaleMask') {
         return;
     }
     // Check if processing is needed
     if (!$this->needsReprocessing($processedFile)) {
         return;
     }
     // Check if there is a OnlineMediaHelper registered for this file type
     $helper = OnlineMediaHelperRegistry::getInstance()->getOnlineMediaHelper($file);
     if ($helper === false) {
         return;
     }
     // Check if helper provides a preview image
     $temporaryFileName = $helper->getPreviewImage($file);
     if (empty($temporaryFileName) || !file_exists($temporaryFileName)) {
         return;
     }
     $temporaryFileNameForResizedThumb = uniqid(PATH_site . 'typo3temp/var/transient/online_media_' . $file->getHashedIdentifier()) . '.jpg';
     switch ($taskType) {
         case 'Image.Preview':
             // Merge custom configuration with default configuration
             $configuration = array_merge(array('width' => 64, 'height' => 64), $configuration);
             $configuration['width'] = MathUtility::forceIntegerInRange($configuration['width'], 1, 1000);
             $configuration['height'] = MathUtility::forceIntegerInRange($configuration['height'], 1, 1000);
             $this->resizeImage($temporaryFileName, $temporaryFileNameForResizedThumb, $configuration);
             break;
         case 'Image.CropScaleMask':
             $this->cropScaleImage($temporaryFileName, $temporaryFileNameForResizedThumb, $configuration);
             break;
     }
     GeneralUtility::unlink_tempfile($temporaryFileName);
     if (is_file($temporaryFileNameForResizedThumb)) {
         $processedFile->setName($this->getTargetFileName($processedFile));
         list($width, $height) = getimagesize($temporaryFileNameForResizedThumb);
         $processedFile->updateProperties(array('width' => $width, 'height' => $height, 'size' => filesize($temporaryFileNameForResizedThumb), 'checksum' => $processedFile->getTask()->getConfigurationChecksum()));
         $processedFile->updateWithLocalFile($temporaryFileNameForResizedThumb);
         GeneralUtility::unlink_tempfile($temporaryFileNameForResizedThumb);
         /** @var ProcessedFileRepository $processedFileRepository */
         $processedFileRepository = GeneralUtility::makeInstance(ProcessedFileRepository::class);
         $processedFileRepository->add($processedFile);
     }
 }
    /**
     * 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);
    }
    /**
     * Generate a link that opens an element browser in a new window.
     * For group/db there is no way to use a "selector" like a <select>|</select>-box.
     *
     * @param array $conf TCA configuration of the parent(!) field
     * @param array $PA An array with additional configuration options
     * @return string A HTML link that opens an element browser in a new window
     */
    protected function renderPossibleRecordsSelectorTypeGroupDB($conf, &$PA)
    {
        $backendUser = $this->getBackendUserAuthentication();
        $languageService = $this->getLanguageService();
        $config = $PA['fieldConf']['config'];
        ArrayUtility::mergeRecursiveWithOverrule($config, $conf);
        $foreign_table = $config['foreign_table'];
        $allowed = $config['allowed'];
        $objectPrefix = $this->inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($this->data['inlineFirstPid']) . '-' . $foreign_table;
        $nameObject = $this->inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($this->data['inlineFirstPid']);
        $mode = 'db';
        $showUpload = false;
        if (!empty($config['appearance']['createNewRelationLinkTitle'])) {
            $createNewRelationText = $languageService->sL($config['appearance']['createNewRelationLinkTitle'], true);
        } else {
            $createNewRelationText = $languageService->sL('LLL:EXT:lang/locallang_core.xlf:cm.createNewRelation', true);
        }
        if (is_array($config['appearance'])) {
            if (isset($config['appearance']['elementBrowserType'])) {
                $mode = $config['appearance']['elementBrowserType'];
            }
            if ($mode === 'file') {
                $showUpload = true;
            }
            if (isset($config['appearance']['fileUploadAllowed'])) {
                $showUpload = (bool) $config['appearance']['fileUploadAllowed'];
            }
            if (isset($config['appearance']['elementBrowserAllowed'])) {
                $allowed = $config['appearance']['elementBrowserAllowed'];
            }
        }
        $browserParams = '|||' . $allowed . '|' . $objectPrefix . '|inline.checkUniqueElement||inline.importElement';
        $onClick = 'setFormValueOpenBrowser(' . GeneralUtility::quoteJSvalue($mode) . ', ' . GeneralUtility::quoteJSvalue($browserParams) . '); return false;';
        $buttonStyle = '';
        if (isset($config['inline']['inlineNewRelationButtonStyle'])) {
            $buttonStyle = ' style="' . $config['inline']['inlineNewRelationButtonStyle'] . '"';
        }
        $item = '
			<a href="#" class="btn btn-default inlineNewRelationButton ' . $this->inlineData['config'][$nameObject]['md5'] . '"
				' . $buttonStyle . ' onclick="' . htmlspecialchars($onClick) . '" title="' . $createNewRelationText . '">
				' . $this->iconFactory->getIcon('actions-insert-record', Icon::SIZE_SMALL)->render() . '
				' . $createNewRelationText . '
			</a>';
        $isDirectFileUploadEnabled = (bool) $this->getBackendUserAuthentication()->uc['edit_docModuleUpload'];
        $allowedArray = GeneralUtility::trimExplode(',', $allowed, true);
        $onlineMediaAllowed = OnlineMediaHelperRegistry::getInstance()->getSupportedFileExtensions();
        if (!empty($allowedArray)) {
            $onlineMediaAllowed = array_intersect($allowedArray, $onlineMediaAllowed);
        }
        if ($showUpload && $isDirectFileUploadEnabled) {
            $folder = $backendUser->getDefaultUploadFolder($this->data['parentPageRow']['uid'], $this->data['tableName'], $this->data['fieldName']);
            if ($folder instanceof Folder && $folder->checkActionPermission('add')) {
                $maxFileSize = GeneralUtility::getMaxUploadFileSize() * 1024;
                $item .= ' <a href="#" class="btn btn-default t3js-drag-uploader inlineNewFileUploadButton ' . $this->inlineData['config'][$nameObject]['md5'] . '"
					' . $buttonStyle . '
					data-dropzone-target="#' . htmlspecialchars($this->inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($this->data['inlineFirstPid'])) . '"
					data-insert-dropzone-before="1"
					data-file-irre-object="' . htmlspecialchars($objectPrefix) . '"
					data-file-allowed="' . htmlspecialchars($allowed) . '"
					data-target-folder="' . htmlspecialchars($folder->getCombinedIdentifier()) . '"
					data-max-file-size="' . htmlspecialchars($maxFileSize) . '"
					><span class="t3-icon t3-icon-actions t3-icon-actions-edit t3-icon-edit-upload">&nbsp;</span>';
                $item .= $languageService->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.select-and-submit', true);
                $item .= '</a>';
                if (!empty($onlineMediaAllowed)) {
                    $buttonText = $languageService->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media.button', true);
                    $placeholder = $languageService->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media.placeholder', true);
                    $buttonSubmit = $languageService->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media.submit', true);
                    $item .= '
						<span class="btn btn-default t3js-online-media-add-btn"
							data-file-irre-object="' . htmlspecialchars($objectPrefix) . '"
							data-online-media-allowed="' . htmlspecialchars(implode(',', $onlineMediaAllowed)) . '"
							data-target-folder="' . htmlspecialchars($folder->getCombinedIdentifier()) . '"
							title="' . $buttonText . '"
							data-btn-submit="' . $buttonSubmit . '"
							data-placeholder="' . $placeholder . '"
							>
							' . $this->iconFactory->getIcon('actions-online-media-add', Icon::SIZE_SMALL)->render() . '
							' . $buttonText . '</span>';
                }
            }
        }
        $item = '<div class="form-control-wrap">' . $item . '</div>';
        $allowedList = '';
        $allowedLabel = $languageService->sL('LLL:EXT:lang/locallang_core.xlf:cm.allowedFileExtensions', true);
        foreach ($allowedArray as $allowedItem) {
            $allowedList .= '<span class="label label-success">' . strtoupper($allowedItem) . '</span> ';
        }
        if (!empty($allowedList)) {
            $item .= '<div class="help-block">' . $allowedLabel . '<br>' . $allowedList . '</div>';
        }
        $item = '<div class="form-group t3js-formengine-validation-marker">' . $item . '</div>';
        return $item;
    }
 /**
  * Returns a publicly accessible URL for a file.
  *
  * WARNING: Access to the file may be restricted by further means, e.g.
  * some web-based authentication. You have to take care of this yourself.
  *
  * @param ResourceInterface $resourceObject The file or folder object
  * @param bool $relativeToCurrentScript Determines whether the URL returned should be relative to the current script, in case it is relative at all (only for the LocalDriver)
  * @return string
  */
 public function getPublicUrl(ResourceInterface $resourceObject, $relativeToCurrentScript = false)
 {
     $publicUrl = null;
     if ($this->isOnline()) {
         // Pre-process the public URL by an accordant slot
         $this->emitPreGeneratePublicUrlSignal($resourceObject, $relativeToCurrentScript, array('publicUrl' => &$publicUrl));
         if ($publicUrl === null && $resourceObject instanceof File && ($helper = OnlineMediaHelperRegistry::getInstance()->getOnlineMediaHelper($resourceObject)) !== false) {
             $publicUrl = $helper->getPublicUrl($resourceObject, $relativeToCurrentScript);
         }
         // If slot did not handle the signal, use the default way to determine public URL
         if ($publicUrl === null) {
             if ($this->hasCapability(self::CAPABILITY_PUBLIC)) {
                 $publicUrl = $this->driver->getPublicUrl($resourceObject->getIdentifier());
             }
             if ($publicUrl === null && $resourceObject instanceof FileInterface) {
                 $queryParameterArray = array('eID' => 'dumpFile', 't' => '');
                 if ($resourceObject instanceof File) {
                     $queryParameterArray['f'] = $resourceObject->getUid();
                     $queryParameterArray['t'] = 'f';
                 } elseif ($resourceObject instanceof ProcessedFile) {
                     $queryParameterArray['p'] = $resourceObject->getUid();
                     $queryParameterArray['t'] = 'p';
                 }
                 $queryParameterArray['token'] = GeneralUtility::hmac(implode('|', $queryParameterArray), 'resourceStorageDumpFile');
                 $publicUrl = 'index.php?' . str_replace('+', '%20', http_build_query($queryParameterArray));
             }
             // If requested, make the path relative to the current script in order to make it possible
             // to use the relative file
             if ($publicUrl !== null && $relativeToCurrentScript && !GeneralUtility::isValidUrl($publicUrl)) {
                 $absolutePathToContainingFolder = PathUtility::dirname(PATH_site . $publicUrl);
                 $pathPart = PathUtility::getRelativePathTo($absolutePathToContainingFolder);
                 $filePart = substr(PATH_site . $publicUrl, strlen($absolutePathToContainingFolder) + 1);
                 $publicUrl = $pathPart . $filePart;
             }
         }
     }
     return $publicUrl;
 }
 /**
  * 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;
 }
 /**
  * The actual processing TASK
  * Should return an array with database properties for sys_file_metadata to write
  *
  * @param File $file
  * @param array $previousExtractedData optional, contains the array of already extracted data
  * @return array
  */
 public function extractMetaData(File $file, array $previousExtractedData = array())
 {
     /** @var OnlineMediaHelperInterface $helper */
     $helper = OnlineMediaHelperRegistry::getInstance()->getOnlineMediaHelper($file);
     return $helper !== false ? $helper->getMetaData($file) : array();
 }
 /**
  * @param string $url
  * @param string $targetFolderIdentifier
  * @param string[] $allowedExtensions
  * @return File|NULL
  */
 protected function addMediaFromUrl($url, $targetFolderIdentifier, array $allowedExtensions = [])
 {
     $targetFolder = null;
     if ($targetFolderIdentifier) {
         try {
             $targetFolder = ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($targetFolderIdentifier);
         } catch (\Exception $e) {
             $targetFolder = null;
         }
     }
     if ($targetFolder === null) {
         $targetFolder = $this->getBackendUser()->getDefaultUploadFolder();
     }
     return OnlineMediaHelperRegistry::getInstance()->transformUrlToFile($url, $targetFolder, $allowedExtensions);
 }
Beispiel #11
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
     * @return string HTML for an upload form.
     */
    public function uploadForm(Folder $folderObject)
    {
        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 '';
        }
        $pArr = explode('|', $this->bparams);
        $allowedExtensions = isset($pArr[3]) ? GeneralUtility::trimExplode(',', $pArr[3], true) : [];
        $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>';
            }
        }
        $code = '
			<br />
			<!--
				Form, for uploading files:
			-->
			<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('tce_file')) . '" method="post" name="editform"' . ' id="typo3-uplFilesForm" enctype="multipart/form-data">
				<table border="0" cellpadding="0" cellspacing="0" id="typo3-uplFiles">
					<tr>
						<td>' . $this->barheader($lang->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.pagetitle', true) . ':') . '</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">';
        // Traverse the number of upload fields:
        $combinedIdentifier = $folderObject->getCombinedIdentifier();
        for ($a = 1; $a <= $count; $a++) {
            $code .= '<input type="file" multiple="multiple" name="upload_' . $a . '[]"' . $this->doc->formWidth(35) . ' size="50" />
				<input type="hidden" name="file[upload][' . $a . '][target]" value="' . htmlspecialchars($combinedIdentifier) . '" />
				<input type="hidden" name="file[upload][' . $a . '][data]" value="' . $a . '" /><br />';
        }
        // Make footer of upload form, including the submit button:
        $redirectValue = $this->getThisScript() . 'act=' . $this->act . '&mode=' . $this->mode . '&expandFolder=' . rawurlencode($combinedIdentifier) . '&bparams=' . rawurlencode($this->bparams) . (is_array($this->P) ? GeneralUtility::implodeArrayForUrl('P', $this->P) : '');
        $code .= '<input type="hidden" name="redirect" value="' . htmlspecialchars($redirectValue) . '" />';
        if (!empty($fileExtList)) {
            $code .= '
				<div class="help-block">
					' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:cm.allowedFileExtensions', true) . '<br>
					' . implode(' ', $fileExtList) . '
				</div>
			';
        }
        $code .= '
			<div id="c-override">
				<label>
					<input type="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="1" /> ' . $lang->sL('LLL:EXT:lang/locallang_misc.xlf:overwriteExistingFiles', true) . '
				</label>
			</div>
			<input class="btn btn-default" type="submit" name="submit" value="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.submit', true) . '" />
		';
        $code .= '</td>
					</tr>
				</table>
			</form>';
        // 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)) {
            $code .= '
				<!--
			Form, adding online media urls:
				-->
				<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('online_media')) . '" method="post" name="editform1"' . ' id="typo3-addMediaForm">
					<table border="0" cellpadding="0" cellspacing="0" id="typo3-uplFiles">
						<tr>
							<td>' . $this->barheader($lang->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media', true) . ':') . '</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">
								<input type="text" name="file[newMedia][0][url]"' . $this->doc->formWidth(35) . ' size="50" 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($folderObject->getCombinedIdentifier()) . '" />
					<input type="hidden" name="file[newMedia][0][allowed]" value="' . htmlspecialchars(implode(',', $allowedExtensions)) . '" />
					<button>' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media.submit', true) . '</button>
					<div class="help-block">
						' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media.allowedProviders') . '<br>
						' . implode(' ', $fileExtList) . '
					</div>
						';
        }
        // 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) . '" />';
        $code .= '</td>
					</tr>
				</table>
			</form><br />';
        return $code;
    }
Beispiel #12
0
 /**
  * Get online media helper
  *
  * @param $file
  * @return bool|OnlineMediaHelperInterface
  */
 protected function getOnlineMediaHelper($file)
 {
     if ($this->onlineMediaHelper === null) {
         $this->onlineMediaHelper = OnlineMediaHelperRegistry::getInstance()->getOnlineMediaHelper($file);
     }
     return $this->onlineMediaHelper;
 }
Beispiel #13
0
 /**
  * Main function, rendering the main module content
  *
  * @return void
  */
 public function main()
 {
     $lang = $this->getLanguageService();
     $assigns = [];
     $assigns['target'] = $this->target;
     if ($this->folderObject->checkActionPermission('add')) {
         $assigns['moduleUrlTceFile'] = BackendUtility::getModuleUrl('tce_file');
         $assigns['cshFileNewFolder'] = BackendUtility::cshItem('xMOD_csh_corebe', 'file_newfolder');
         // Making the selector box for the number of concurrent folder-creations
         $this->number = MathUtility::forceIntegerInRange($this->number, 1, 10);
         for ($a = 1; $a <= $this->folderNumber; $a++) {
             $options = [];
             $options['value'] = $a;
             $options['selected'] = $this->number == $a ? ' selected="selected"' : '';
             $assigns['options'][] = $options;
         }
         // Making the number of new-folder boxes needed:
         for ($a = 0; $a < $this->number; $a++) {
             $folder = [];
             $folder['this'] = $a;
             $folder['next'] = $a + 1;
             $assigns['folders'][] = $folder;
         }
         // Making submit button for folder creation:
         $assigns['returnUrl'] = $this->returnUrl;
     }
     if ($this->folderObject->getStorage()->checkUserActionPermission('add', 'File')) {
         $assigns['moduleUrlOnlineMedia'] = BackendUtility::getModuleUrl('online_media');
         $assigns['cshFileNewMedia'] = BackendUtility::cshItem('xMOD_csh_corebe', 'file_newMedia');
         // Create a list of allowed file extensions with the readable format "youtube, vimeo" etc.
         $fileExtList = [];
         $onlineMediaFileExt = OnlineMediaHelperRegistry::getInstance()->getSupportedFileExtensions();
         foreach ($onlineMediaFileExt as $fileExt) {
             if (GeneralUtility::verifyFilenameAgainstDenyPattern('.' . $fileExt)) {
                 $fileExtList[] = strtoupper(htmlspecialchars($fileExt));
             }
         }
         $assigns['fileExtList'] = $fileExtList;
         $assigns['moduleUrlTceFile'] = BackendUtility::getModuleUrl('tce_file');
         $assigns['cshFileNewFile'] = BackendUtility::cshItem('xMOD_csh_corebe', 'file_newfile');
         // Create a list of allowed file extensions with a text format "*.txt, *.css" etc.
         $fileExtList = [];
         $textFileExt = GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], true);
         foreach ($textFileExt as $fileExt) {
             if (GeneralUtility::verifyFilenameAgainstDenyPattern('.' . $fileExt)) {
                 $fileExtList[] = strtoupper(htmlspecialchars($fileExt));
             }
         }
         $assigns['txtFileExtList'] = $fileExtList;
     }
     $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
     // Back
     if ($this->returnUrl) {
         $backButton = $buttonBar->makeLinkButton()->setHref($this->returnUrl)->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.goBack'))->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-back', Icon::SIZE_SMALL));
         $buttonBar->addButton($backButton);
     }
     // Rendering of the output via fluid
     $view = GeneralUtility::makeInstance(StandaloneView::class);
     $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates')]);
     $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials')]);
     $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/File/CreateFolder.html'));
     $view->assignMultiple($assigns);
     $this->content = $view->render();
     $this->moduleTemplate->setContent($this->content);
 }