Exemple #1
0
 /**
  * Renders a HTML Block with file information
  *
  * @param File $file
  * @return string
  */
 protected function renderFileInformationContent(File $file = null)
 {
     /** @var LanguageService $lang */
     $lang = $GLOBALS['LANG'];
     if ($file !== null) {
         $processedFile = $file->process(ProcessedFile::CONTEXT_IMAGEPREVIEW, ['width' => 150, 'height' => 150]);
         $previewImage = $processedFile->getPublicUrl(true);
         $content = '';
         if ($file->isMissing()) {
             $content .= '<span class="label label-danger label-space-right">' . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:warning.file_missing')) . '</span>';
         }
         if ($previewImage) {
             $content .= '<img src="' . htmlspecialchars($previewImage) . '" ' . 'width="' . $processedFile->getProperty('width') . '" ' . 'height="' . $processedFile->getProperty('height') . '" ' . 'alt="" class="t3-tceforms-sysfile-imagepreview" />';
         }
         $content .= '<strong>' . htmlspecialchars($file->getName()) . '</strong>';
         $content .= ' (' . htmlspecialchars(GeneralUtility::formatSize($file->getSize())) . 'bytes)<br />';
         $content .= BackendUtility::getProcessedValue('sys_file', 'type', $file->getType()) . ' (' . $file->getMimeType() . ')<br />';
         $content .= htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_misc.xlf:fileMetaDataLocation')) . ': ';
         $content .= htmlspecialchars($file->getStorage()->getName()) . ' - ' . htmlspecialchars($file->getIdentifier()) . '<br />';
         $content .= '<br />';
     } else {
         $content = '<h2>' . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_misc.xlf:fileMetaErrorInvalidRecord')) . '</h2>';
     }
     return $content;
 }
 /**
  * Render preview for current record
  *
  * @return string
  */
 protected function renderPreview()
 {
     // Perhaps @TODO in future: Also display preview for records - without fileObject
     if (!$this->fileObject) {
         return;
     }
     $imageTag = '';
     $downloadLink = '';
     // check if file is marked as missing
     if ($this->fileObject->isMissing()) {
         $flashMessage = \TYPO3\CMS\Core\Resource\Utility\BackendUtility::getFlashMessageForMissingFile($this->fileObject);
         $imageTag .= $flashMessage->render();
     } else {
         $fileExtension = $this->fileObject->getExtension();
         $thumbUrl = '';
         if (GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileExtension)) {
             $thumbUrl = $this->fileObject->process(ProcessedFile::CONTEXT_IMAGEPREVIEW, array('width' => '400m', 'height' => '400m'))->getPublicUrl(TRUE);
         }
         // Create thumbnail image?
         if ($thumbUrl) {
             $imageTag .= '<img src="' . $thumbUrl . '" ' . 'alt="' . htmlspecialchars(trim($this->fileObject->getName())) . '" ' . 'title="' . htmlspecialchars(trim($this->fileObject->getName())) . '" />';
         }
         // Display download link?
         $url = $this->fileObject->getPublicUrl(TRUE);
         if ($url) {
             $downloadLink .= '<a href="' . htmlspecialchars($url) . '" target="_blank" class="t3-button">' . IconUtility::getSpriteIcon('actions-edit-download') . ' ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:download', TRUE) . '</a>';
         }
     }
     return ($imageTag ? '<p>' . $imageTag . '</p>' : '') . ($downloadLink ? '<p>' . $downloadLink . '</p>' : '');
 }
 /**
  * Create a processed file according to some configuration.
  *
  * @param File $file
  * @param array $processingConfiguration
  * @return string
  */
 public function createAction(File $file, array $processingConfiguration = array())
 {
     $processedFile = $file->process(ProcessedFile::CONTEXT_IMAGECROPSCALEMASK, $processingConfiguration);
     $response = array('success' => TRUE, 'original' => $file->getUid(), 'title' => $file->getProperty('title') ? $file->getProperty('title') : $file->getName(), 'publicUrl' => $processedFile->getPublicUrl(), 'width' => $processedFile->getProperty('width'), 'height' => $processedFile->getProperty('height'));
     header("Content-Type: text/json");
     return htmlspecialchars(json_encode($response), ENT_NOQUOTES);
 }
Exemple #4
0
 /**
  * Get preview for current record
  *
  * @return array
  */
 protected function getPreview() : array
 {
     $preview = [];
     // Perhaps @todo in future: Also display preview for records - without fileObject
     if (!$this->fileObject) {
         return $preview;
     }
     // check if file is marked as missing
     if ($this->fileObject->isMissing()) {
         $preview['missingFile'] = $this->fileObject->getName();
     } else {
         /** @var \TYPO3\CMS\Core\Resource\Rendering\RendererRegistry $rendererRegistry */
         $rendererRegistry = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Rendering\RendererRegistry::class);
         $fileRenderer = $rendererRegistry->getRenderer($this->fileObject);
         $fileExtension = $this->fileObject->getExtension();
         $preview['url'] = $this->fileObject->getPublicUrl(true);
         $width = '590m';
         $heigth = '400m';
         // Check if there is a FileRenderer
         if ($fileRenderer !== null) {
             $preview['fileRenderer'] = $fileRenderer->render($this->fileObject, $width, $heigth, [], true);
             // else check if we can create an Image preview
         } elseif (GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileExtension)) {
             $preview['fileObject'] = $this->fileObject;
             $preview['width'] = $width;
             $preview['heigth'] = $heigth;
         }
     }
     return $preview;
 }
 /**
  * Get the name of the file
  *
  * If there is no processed file in the file system (as the original file did not have to be modified e.g.
  * when the original image is in the boundaries of the maxW/maxH stuff)
  * then just return the name of the original file
  *
  * @return string
  */
 public function getName()
 {
     if ($this->usesOriginalFile()) {
         return $this->originalFile->getName();
     } else {
         return $this->name;
     }
 }
    /**
     * Main function. Will generate the information to display for the item
     * set internally.
     *
     * @param string $returnLinkTag <a> tag closing/returning.
     * @return void
     * @todo Define visibility
     */
    public function renderFileInfo($returnLinkTag)
    {
        $fileExtension = $this->fileObject->getExtension();
        $code = '<div class="fileInfoContainer">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile($fileExtension) . '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.file', TRUE) . ':</strong> ' . $this->fileObject->getName() . '&nbsp;&nbsp;' . '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.filesize') . ':</strong> ' . \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($this->fileObject->getSize()) . '</div>
			';
        $this->content .= $this->doc->section('', $code);
        $this->content .= $this->doc->divider(2);
        // If the file was an image...
        // @todo: add this check in the domain model, or in the processing folder
        if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileExtension)) {
            // @todo: find a way to make getimagesize part of the t3lib_file object
            $imgInfo = @getimagesize($this->fileObject->getForLocalProcessing(FALSE));
            $thumbUrl = $this->fileObject->process(\TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW, array('width' => '150m', 'height' => '150m'))->getPublicUrl(TRUE);
            $code = '<div class="fileInfoContainer fileDimensions">' . '<strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.dimensions') . ':</strong> ' . $imgInfo[0] . 'x' . $imgInfo[1] . ' ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.pixels') . '</div>';
            $code .= '<br />
				<div align="center">' . $returnLinkTag . '<img src="' . $thumbUrl . '" alt="' . htmlspecialchars(trim($this->fileObject->getName())) . '" title="' . htmlspecialchars(trim($this->fileObject->getName())) . '" /></a></div>';
            $this->content .= $this->doc->section('', $code);
        } elseif ($fileExtension == 'ttf') {
            $thumbUrl = $this->fileObject->process(\TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW, array('width' => '530m', 'height' => '600m'))->getPublicUrl(TRUE);
            $thumb = '<br />
				<div align="center">' . $returnLinkTag . '<img src="' . $thumbUrl . '" border="0" title="' . htmlspecialchars(trim($this->fileObject->getName())) . '" alt="" /></a></div>';
            $this->content .= $this->doc->section('', $thumb);
        }
        // Traverse the list of fields to display for the record:
        $tableRows = array();
        $showRecordFieldList = $GLOBALS['TCA'][$this->table]['interface']['showRecordFieldList'];
        $fieldList = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $showRecordFieldList, TRUE);
        foreach ($fieldList as $name) {
            $name = trim($name);
            if (!isset($GLOBALS['TCA'][$this->table]['columns'][$name])) {
                continue;
            }
            $isExcluded = !(!$GLOBALS['TCA'][$this->table]['columns'][$name]['exclude'] || $GLOBALS['BE_USER']->check('non_exclude_fields', $this->table . ':' . $name));
            if ($isExcluded) {
                continue;
            }
            $uid = $this->row['uid'];
            $itemValue = \TYPO3\CMS\Backend\Utility\BackendUtility::getProcessedValue($this->table, $name, $this->row[$name], 0, 0, FALSE, $uid);
            $itemLabel = $GLOBALS['LANG']->sL(\TYPO3\CMS\Backend\Utility\BackendUtility::getItemLabel($this->table, $name), 1);
            $tableRows[] = '
				<tr>
					<td class="t3-col-header">' . $itemLabel . '</td>
					<td>' . htmlspecialchars($itemValue) . '</td>
				</tr>';
        }
        // Create table from the information:
        $tableCode = '
			<table border="0" cellpadding="0" cellspacing="0" id="typo3-showitem" class="t3-table-info">
				' . implode('', $tableRows) . '
			</table>';
        $this->content .= $this->doc->section('', $tableCode);
        // References:
        if ($this->fileObject->isIndexed()) {
            $header = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.referencesToThisItem');
            $this->content .= $this->doc->section($header, $this->makeRef('_FILE', $this->fileObject));
        }
    }
    /**
     * Main function, rendering the content of the rename form
     *
     * @return void
     */
    public function main()
    {
        // Make page header:
        $this->content = $this->doc->startPage($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.pagetitle'));
        $pageContent = $this->doc->header($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.pagetitle'));
        if ($this->fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
            $fileIdentifier = $this->fileOrFolderObject->getCombinedIdentifier();
        } else {
            $fileIdentifier = $this->fileOrFolderObject->getUid();
        }
        $pageContent .= '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('tce_file')) . '" method="post" name="editform" role="form">';
        // Making the formfields for renaming:
        $pageContent .= '

			<div class="form-group">
				<input class="form-control" type="text" name="file[rename][0][target]" value="' . htmlspecialchars($this->fileOrFolderObject->getName()) . '" ' . $this->getDocumentTemplate()->formWidth(40) . ' />
				<input type="hidden" name="file[rename][0][data]" value="' . htmlspecialchars($fileIdentifier) . '" />
			</div>
		';
        // Making submit button:
        $pageContent .= '
			<div class="form-group">
				<input class="btn btn-primary" type="submit" value="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.submit', TRUE) . '" />
				<input class="btn btn-danger" type="submit" value="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.cancel', TRUE) . '" onclick="backToList(); return false;" />
				<input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl) . '" />
				' . \TYPO3\CMS\Backend\Form\FormEngine::getHiddenTokenField('tceAction') . '
			</div>
		';
        $pageContent .= '</form>';
        $docHeaderButtons = array('back' => '');
        $docHeaderButtons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'file_rename');
        // Back
        if ($this->returnUrl) {
            $docHeaderButtons['back'] = '<a href="' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisUrl($this->returnUrl)) . '" class="typo3-goBack" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.goBack', TRUE) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-view-go-back') . '</a>';
        }
        // Add the HTML as a section:
        $markerArray = array('CSH' => $docHeaderButtons['csh'], 'FUNC_MENU' => '', 'CONTENT' => $pageContent, 'PATH' => $this->title);
        $this->content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
        $this->content .= $this->doc->endPage();
        $this->content = $this->doc->insertStylesAndJS($this->content);
    }
    /**
     * Main function, rendering the content of the rename form
     *
     * @return void
     */
    public function main()
    {
        if ($this->fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
            $fileIdentifier = $this->fileOrFolderObject->getCombinedIdentifier();
        } else {
            $fileIdentifier = $this->fileOrFolderObject->getUid();
        }
        $pageContent = '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('tce_file')) . '" method="post" name="editform" role="form">';
        // Making the formfields for renaming:
        $pageContent .= '

			<div class="form-group">
				<input class="form-control" type="text" name="file[rename][0][target]" value="' . htmlspecialchars($this->fileOrFolderObject->getName()) . '" ' . $this->getDocumentTemplate()->formWidth(40) . ' />
				<input type="hidden" name="file[rename][0][data]" value="' . htmlspecialchars($fileIdentifier) . '" />
			</div>
		';
        // Making submit button:
        $pageContent .= '
			<div class="form-group">
				<input class="btn btn-primary" type="submit" value="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.submit', true) . '" />
				<input class="btn btn-danger" type="submit" value="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.cancel', true) . '" onclick="backToList(); return false;" />
				<input type="hidden" name="redirect" value="' . htmlspecialchars($this->returnUrl) . '" />
			</div>
		';
        $pageContent .= '</form>';
        // Create buttons
        $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
        // csh button
        $cshButton = $buttonBar->makeHelpButton()->setModuleName('xMOD_csh_corebe')->setFieldName('file_rename');
        $buttonBar->addButton($cshButton);
        // back button
        if ($this->returnUrl) {
            $backButton = $buttonBar->makeLinkButton()->sethref(GeneralUtility::linkThisUrl($this->returnUrl))->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.goBack', true))->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-back', Icon::SIZE_SMALL));
            $buttonBar->addButton($backButton);
        }
        // set header
        $this->content = '<h1>' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_rename.php.pagetitle') . '</h1>';
        // add section
        $this->content .= $this->moduleTemplate->section('', $pageContent);
        $this->moduleTemplate->setContent($this->content);
    }
    /**
     * Render preview for current record
     *
     * @return string
     */
    protected function renderPreview()
    {
        // Perhaps @todo in future: Also display preview for records - without fileObject
        if (!$this->fileObject) {
            return '';
        }
        $previewTag = '';
        $showLink = '';
        // check if file is marked as missing
        if ($this->fileObject->isMissing()) {
            $flashMessage = \TYPO3\CMS\Core\Resource\Utility\BackendUtility::getFlashMessageForMissingFile($this->fileObject);
            $previewTag .= $flashMessage->render();
        } else {
            /** @var \TYPO3\CMS\Core\Resource\Rendering\RendererRegistry $rendererRegistry */
            $rendererRegistry = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Rendering\RendererRegistry::class);
            $fileRenderer = $rendererRegistry->getRenderer($this->fileObject);
            $fileExtension = $this->fileObject->getExtension();
            $url = $this->fileObject->getPublicUrl(true);
            // Check if there is a FileRenderer
            if ($fileRenderer !== null) {
                $previewTag = $fileRenderer->render($this->fileObject, '590m', '400m', array(), true);
                // else check if we can create an Image preview
            } elseif (GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileExtension)) {
                $processedFile = $this->fileObject->process(ProcessedFile::CONTEXT_IMAGEPREVIEW, array('width' => '590m', 'height' => '400m'));
                // Create thumbnail image?
                if ($processedFile) {
                    $thumbUrl = $processedFile->getPublicUrl(true);
                    $previewTag .= '<img class="img-responsive img-thumbnail" src="' . $thumbUrl . '" ' . 'width="' . $processedFile->getProperty('width') . '" ' . 'height="' . $processedFile->getProperty('height') . '" ' . 'alt="' . htmlspecialchars(trim($this->fileObject->getName())) . '" ' . 'title="' . htmlspecialchars(trim($this->fileObject->getName())) . '" />';
                }
            }
            // Show
            if ($url) {
                $showLink .= '
					<a class="btn btn-primary" href="' . htmlspecialchars($url) . '" target="_blank">
						' . $this->iconFactory->getIcon('actions-document-view', Icon::SIZE_SMALL)->render() . '
						' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.show', true) . '
					</a>';
            }
        }
        return ($previewTag ? '<p>' . $previewTag . '</p>' : '') . ($showLink ? '<p>' . $showLink . '</p>' : '');
    }
 /**
  * Generates a preview for a file
  *
  * @param File $file The source file
  * @param array $configuration Processing configuration
  * @param string $targetFilePath Output file path
  * @return array|NULL
  */
 protected function generatePreviewFromFile(File $file, array $configuration, $targetFilePath)
 {
     $originalFileName = $file->getForLocalProcessing(FALSE);
     // Check file extension
     if ($file->getType() != File::FILETYPE_IMAGE && !GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $file->getExtension())) {
         // Create a default image
         $this->processor->getTemporaryImageWithText($targetFilePath, 'Not imagefile!', 'No ext!', $file->getName());
     } else {
         // Create the temporary file
         if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im']) {
             $parameters = '-sample ' . $configuration['width'] . 'x' . $configuration['height'] . ' ' . $this->processor->wrapFileName($originalFileName) . '[0] ' . $this->processor->wrapFileName($targetFilePath);
             $cmd = GeneralUtility::imageMagickCommand('convert', $parameters) . ' 2>&1';
             CommandUtility::exec($cmd);
             if (!file_exists($targetFilePath)) {
                 // Create a error gif
                 $this->processor->getTemporaryImageWithText($targetFilePath, 'No thumb', 'generated!', $file->getName());
             }
         }
     }
     return array('filePath' => $targetFilePath);
 }
Exemple #11
0
 /**
  * Get an existing items from the references that matches the file
  *
  * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\GeorgRinger\News\Domain\Model\FileReference> $items
  * @param \TYPO3\CMS\Core\Resource\File $file
  * @return bool|FileReference
  */
 protected function getIfFalRelationIfAlreadyExists(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $items, \TYPO3\CMS\Core\Resource\File $file)
 {
     $result = FALSE;
     if ($items->count() !== 0) {
         /** @var $item FileReference */
         foreach ($items as $item) {
             // only check already persisted items
             if ($item->getFileUid() === (int) $file->getUid() || $item->getUid() && $item->getOriginalResource()->getName() === $file->getName() && $item->getOriginalResource()->getSize() === (int) $file->getSize()) {
                 $result = $item;
                 break;
             }
         }
     }
     return $result;
 }
Exemple #12
0
 /**
  * Create the thumbnail
  * Will exit before return if all is well.
  *
  * @return void
  * @todo Define visibility
  */
 public function main()
 {
     // Clean output buffer to ensure no extraneous output exists
     ob_clean();
     // If file exists, we make a thumbnail of the file.
     if (is_object($this->image)) {
         // Check file extension:
         if ($this->image->getExtension() == 'ttf') {
             // Make font preview... (will not return)
             $this->fontGif($this->image);
         } elseif ($this->image->getType() != File::FILETYPE_IMAGE && !GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $this->image->getExtension())) {
             $this->errorGif('Not imagefile!', 'No ext!', $this->image->getName());
         }
         // ... so we passed the extension test meaning that we are going to make a thumbnail here:
         // default
         if (!$this->size) {
             $this->size = $this->sizeDefault;
         }
         // I added extra check, so that the size input option could not be fooled to pass other values.
         // That means the value is exploded, evaluated to an integer and the imploded to [value]x[value].
         // Furthermore you can specify: size=340 and it'll be translated to 340x340.
         // explodes the input size (and if no "x" is found this will add size again so it is the same for both dimensions)
         $sizeParts = explode('x', $this->size . 'x' . $this->size);
         // Cleaning it up, only two parameters now.
         $sizeParts = array(MathUtility::forceIntegerInRange($sizeParts[0], 1, 1000), MathUtility::forceIntegerInRange($sizeParts[1], 1, 1000));
         // Imploding the cleaned size-value back to the internal variable
         $this->size = implode('x', $sizeParts);
         // Getting max value
         $sizeMax = max($sizeParts);
         // Init
         $outpath = PATH_site . $this->outdir;
         // Should be - ? 'png' : 'gif' - , but doesn't work (ImageMagick prob.?)
         // René: png work for me
         $thmMode = MathUtility::forceIntegerInRange($GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails_png'], 0);
         $outext = $this->image->getExtension() != 'jpg' || $thmMode & 2 ? $thmMode & 1 ? 'png' : 'gif' : 'jpg';
         $outfile = 'tmb_' . substr(md5($this->image->getName() . $this->mtime . $this->size), 0, 10) . '.' . $outext;
         $this->output = $outpath . $outfile;
         if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im']) {
             // If thumbnail does not exist, we generate it
             if (!file_exists($this->output)) {
                 $parameters = '-sample ' . $this->size . ' ' . $this->wrapFileName($this->image->getForLocalProcessing(FALSE)) . '[0] ' . $this->wrapFileName($this->output);
                 $cmd = GeneralUtility::imageMagickCommand('convert', $parameters);
                 \TYPO3\CMS\Core\Utility\CommandUtility::exec($cmd);
                 if (!file_exists($this->output)) {
                     $this->errorGif('No thumb', 'generated!', $this->image->getName());
                 } else {
                     GeneralUtility::fixPermissions($this->output);
                 }
             }
             // The thumbnail is read and output to the browser
             if ($fd = @fopen($this->output, 'rb')) {
                 $fileModificationTime = filemtime($this->output);
                 header('Content-Type: image/' . ($outext === 'jpg' ? 'jpeg' : $outext));
                 header('Last-Modified: ' . date('r', $fileModificationTime));
                 header('ETag: ' . md5($this->output) . '-' . $fileModificationTime);
                 // Expiration time is chosen arbitrary to 1 month
                 header('Expires: ' . date('r', $fileModificationTime + 30 * 24 * 60 * 60));
                 fpassthru($fd);
                 fclose($fd);
             } else {
                 $this->errorGif('Read problem!', '', $this->output);
             }
         } else {
             die;
         }
     } else {
         $this->errorGif('No valid', 'inputfile!', basename($this->image));
     }
 }
 /**
  * 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())
 {
     $metadata = array();
     $title = $file->getProperty('title');
     if (empty($title)) {
         $metadata = array('title' => $this->guessTitle($file->getName()));
     }
     return $metadata;
 }
 /**
  * Returns the alternative text to this image
  *
  * TODO: Possibly move this to the image domain object instead
  *
  * @return string
  */
 public function getAlternative()
 {
     return $this->propertiesOfFileReference['alternative'] ? $this->propertiesOfFileReference['alternative'] : $this->originalFile->getName();
 }
 /**
  * Removes a temporary file.
  *
  * When working with a file, the actual file might be on a remote storage.
  * To work with it it gets copied to local storage, those temporary local
  * copies need to be removed when they're not needed anymore.
  *
  * @param string $localTempFilePath Path to the local file copy
  * @param \TYPO3\CMS\Core\Resource\File $sourceFile Original file
  */
 protected function cleanupTempFile($localTempFilePath, File $sourceFile)
 {
     if (PathUtility::basename($localTempFilePath) !== $sourceFile->getName()) {
         unlink($localTempFilePath);
     }
 }
Exemple #16
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>';
 }
Exemple #17
0
 /**
  * Returns the name of this file
  *
  * @return string
  */
 public function getName()
 {
     return $this->originalFile->getName();
 }
 /**
  * Generates a preview for a file
  *
  * @param File $file The source file
  * @param array $configuration Processing configuration
  * @param string $targetFilePath Output file path
  * @return array|NULL
  */
 protected function generatePreviewFromFile(File $file, array $configuration, $targetFilePath)
 {
     $originalFileName = $file->getForLocalProcessing(FALSE);
     // Check file extension
     if ($file->getType() != File::FILETYPE_IMAGE && !GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $file->getExtension())) {
         // Create a default image
         $graphicalFunctions = GeneralUtility::makeInstance(GraphicalFunctions::class);
         $graphicalFunctions->getTemporaryImageWithText($targetFilePath, 'Not imagefile!', 'No ext!', $file->getName());
         $result = array('filePath' => $targetFilePath);
     } elseif ($file->getExtension() === 'svg') {
         /** @var $gifBuilder \TYPO3\CMS\Frontend\Imaging\GifBuilder */
         $gifBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Imaging\GifBuilder::class);
         $gifBuilder->init();
         $gifBuilder->absPrefix = PATH_site;
         $info = $gifBuilder->getImageDimensions($originalFileName);
         $newInfo = $gifBuilder->getImageScale($info, $configuration['width'], $configuration['height'], array());
         $result = array('width' => $newInfo[0], 'height' => $newInfo[1], 'filePath' => '');
     } else {
         // Create the temporary file
         if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im']) {
             $parameters = '-sample ' . $configuration['width'] . 'x' . $configuration['height'] . ' ' . CommandUtility::escapeShellArgument($originalFileName) . '[0] ' . CommandUtility::escapeShellArgument($targetFilePath);
             $cmd = GeneralUtility::imageMagickCommand('convert', $parameters) . ' 2>&1';
             CommandUtility::exec($cmd);
             if (!file_exists($targetFilePath)) {
                 // Create a error gif
                 $graphicalFunctions = GeneralUtility::makeInstance(GraphicalFunctions::class);
                 $graphicalFunctions->getTemporaryImageWithText($targetFilePath, 'No thumb', 'generated!', $file->getName());
             }
         }
         $result = array('filePath' => $targetFilePath);
     }
     return $result;
 }
Exemple #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 = 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>';
 }
 /**
  * A file is about to be added as a *replacement* of an existing
  * one.
  *
  * @param File $file
  * @param string $uploadedFileName
  * @return void
  */
 public function postFileReplace(File $file, $uploadedFileName)
 {
     $folder = $file->getParentFolder();
     $storageConfiguration = $folder->getStorage()->getConfiguration();
     $storageRecord = $folder->getStorage()->getStorageRecord();
     if ($storageRecord['driver'] !== 'Local') {
         // Unfortunately unsupported yet
         return;
     }
     $targetDirectory = $storageConfiguration['pathType'] === 'relative' ? PATH_site : '';
     $targetDirectory .= rtrim(rtrim($storageConfiguration['basePath'], '/') . $folder->getIdentifier(), '/');
     $targetFileName = $targetDirectory . '/' . $file->getName();
     $this->processFile($targetFileName, PathUtility::basename($targetFileName), $targetDirectory, $file);
     $this->populateMetadata($file, $folder);
 }