/** * @param array $arguments * @param callable $renderChildrenClosure * @param RenderingContextInterface $renderingContext * * @return string */ public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) { $documentTranslation = $arguments['documentTranslation']; $icons = array('html' => '<a class="btn btn-default disabled">' . IconUtility::getSpriteIcon('empty-empty') . '</a>', 'pdf' => '<a class="btn btn-default disabled">' . IconUtility::getSpriteIcon('empty-empty') . '</a>', 'sxw' => '<a class="btn btn-default disabled">' . IconUtility::getSpriteIcon('empty-empty') . '</a>'); $formats = $documentTranslation->getFormats(); foreach ($formats as $format) { $output = ''; /** @var \TYPO3\CMS\Documentation\Domain\Model\DocumentFormat $format */ $output .= '<a '; $uri = '../' . $format->getPath(); $extension = substr($uri, strrpos($uri, '.') + 1); if (strlen($extension) < 5) { // This is direct link to a file $output .= 'href="' . $uri . '" class="btn btn-default"'; } else { $extension = $format->getFormat(); if ($extension === 'json') { $extension = 'js'; } $output .= 'href="#" onclick="top.TYPO3.Backend.ContentContainer.setUrl(' . \TYPO3\CMS\Core\Utility\GeneralUtility::quoteJSvalue($uri) . ')" class="btn btn-default"'; } $xliff = 'LLL:EXT:documentation/Resources/Private/Language/locallang.xlf'; $title = sprintf($GLOBALS['LANG']->sL($xliff . ':tx_documentation_domain_model_documentformat.format.title'), $format->getFormat()); $output .= ' title="' . htmlspecialchars($title) . '">'; $spriteIconHtml = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile($extension); $output .= $spriteIconHtml . '</a>' . LF; $keyFormat = $format->getFormat(); if ($keyFormat === 'json') { // It should take over the place of sxw which will then never be used $keyFormat = 'sxw'; } $icons[$keyFormat] = $output; } return implode('', array_values($icons)); }
/** * Renders all format download links. * * @param \TYPO3\CMS\Documentation\Domain\Model\DocumentTranslation $documentTranslation * @return string */ public function render(\TYPO3\CMS\Documentation\Domain\Model\DocumentTranslation $documentTranslation) { $output = ''; foreach ($documentTranslation->getFormats() as $format) { /** @var \TYPO3\CMS\Documentation\Domain\Model\DocumentFormat $format */ $output .= '<a '; $uri = '../' . $format->getPath(); $extension = substr($uri, strrpos($uri, '.') + 1); if (strlen($extension) < 5) { // This is direct link to a file $output .= 'href="' . $uri . '"'; } else { $extension = $format->getFormat(); if ($extension === 'json') { $extension = 'js'; } $output .= 'href="#" onclick="top.TYPO3.Backend.ContentContainer.setUrl(\'' . $uri . '\')"'; } $xliff = 'LLL:EXT:documentation/Resources/Private/Language/locallang.xlf'; $title = sprintf($GLOBALS['LANG']->sL($xliff . ':tx_documentation_domain_model_documentformat.format.title'), $format->getFormat()); $output .= ' title="' . htmlspecialchars($title) . '">'; $spriteIconHtml = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile($extension); $output .= $spriteIconHtml . '</a>' . LF; } return $output; }
/** * Make 1st level clickmenu: * * @param string $combinedIdentifier The combined identifier * @return string HTML content * @see \TYPO3\CMS\Core\Resource\ResourceFactory::retrieveFileOrFolderObject() * @todo Define visibility */ public function printFileClickMenu($combinedIdentifier) { $menuItems = array(); $combinedIdentifier = rawurldecode($combinedIdentifier); $fileObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($combinedIdentifier); if ($fileObject) { $folder = FALSE; $identifier = $fileObject->getCombinedIdentifier(); if ($fileObject instanceof \TYPO3\CMS\Core\Resource\Folder) { $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile('folder', array('class' => 'absmiddle', 'title' => htmlspecialchars($fileObject->getName()))); $folder = TRUE; } else { $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile($fileObject->getExtension(), array('class' => 'absmiddle', 'title' => htmlspecialchars($fileObject->getName() . ' (' . GeneralUtility::formatSize($fileObject->getSize()) . ')'))); } // Edit if (!in_array('edit', $this->disabledItems) && !$folder && GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], $fileObject->getExtension())) { $menuItems['edit'] = $this->FILE_launch($identifier, 'file_edit.php', 'edit', 'edit_file.gif'); } // Rename if (!in_array('rename', $this->disabledItems)) { $menuItems['rename'] = $this->FILE_launch($identifier, 'file_rename.php', 'rename', 'rename.gif'); } // Upload if (!in_array('upload', $this->disabledItems) && $folder) { $menuItems['upload'] = $this->FILE_upload($identifier); } // New if (!in_array('new', $this->disabledItems) && $folder) { $menuItems['new'] = $this->FILE_launch($identifier, 'file_newfolder.php', 'new', 'new_file.gif'); } // Info if (!in_array('info', $this->disabledItems)) { $menuItems['info'] = $this->DB_info($identifier, ''); } $menuItems[] = 'spacer'; // Copy: if (!in_array('copy', $this->disabledItems)) { $menuItems['copy'] = $this->FILE_copycut($identifier, 'copy'); } // Cut: if (!in_array('cut', $this->disabledItems)) { $menuItems['cut'] = $this->FILE_copycut($identifier, 'cut'); } // Paste: $elFromAllTables = count($this->clipObj->elFromTable('_FILE')); if (!in_array('paste', $this->disabledItems) && $elFromAllTables && $folder) { $elArr = $this->clipObj->elFromTable('_FILE'); $selItem = reset($elArr); $elInfo = array(basename($selItem), basename($path), $this->clipObj->currentMode()); $menuItems['pasteinto'] = $this->FILE_paste($identifier, $selItem, $elInfo); } $menuItems[] = 'spacer'; // Delete: if (!in_array('delete', $this->disabledItems)) { $menuItems['delete'] = $this->FILE_delete($identifier); } } // Adding external elements to the menuItems array $menuItems = $this->processingByExtClassArray($menuItems, $identifier, 0); // Processing by external functions? $menuItems = $this->externalProcessingOfFileMenuItems($menuItems); // Return the printed elements: return $this->printItems($menuItems, $icon . $fileObject->getName()); }
/** * Print the content on a pad. Called from ->printClipboard() * * @access private * @param string $pad Pad reference * @return array Array with table rows for the clipboard. * @todo Define visibility */ public function printContentFromTab($pad) { $lines = array(); if (is_array($this->clipData[$pad]['el'])) { foreach ($this->clipData[$pad]['el'] as $k => $v) { if ($v) { list($table, $uid) = explode('|', $k); $bgColClass = $table == '_FILE' && $this->fileMode || $table != '_FILE' && !$this->fileMode ? 'bgColor4-20' : 'bgColor4'; // Rendering files/directories on the clipboard if ($table == '_FILE') { $fileObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($v); if ($fileObject) { $thumb = ''; $folder = $fileObject instanceof \TYPO3\CMS\Core\Resource\Folder; $size = $folder ? '' : '(' . \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($fileObject->getSize()) . 'bytes)'; $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile($folder ? 'folder' : strtolower($fileObject->getExtension()), array('style' => 'margin: 0 20px;', 'title' => $fileObject->getName() . ' ' . $size)); if ($this->clipData['_setThumb'] && \TYPO3\CMS\Core\Utility\GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileObject->getExtension())) { $thumb = '<br />' . \TYPO3\CMS\Backend\Utility\BackendUtility::getThumbNail($this->backPath . 'thumbs.php', $v, ' vspace="4"'); } $lines[] = ' <tr> <td class="' . $bgColClass . '">' . $icon . '</td> <td class="' . $bgColClass . '" nowrap="nowrap" width="95%"> ' . $this->linkItemText(htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($fileObject->getName(), $GLOBALS['BE_USER']->uc['titleLen'])), $fileObject->getName()) . ($pad == 'normal' ? ' <strong>(' . ($this->clipData['normal']['mode'] == 'copy' ? $this->clLabel('copy', 'cm') : $this->clLabel('cut', 'cm')) . ')</strong>' : '') . ' ' . $thumb . '</td> <td class="' . $bgColClass . '" align="center" nowrap="nowrap">' . '<a href="#" onclick="' . htmlspecialchars('top.launchView(\'' . $table . '\', \'' . $v . '\'); return false;') . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-info', array('title' => $this->clLabel('info', 'cm'))) . '</a>' . '<a href="' . htmlspecialchars($this->removeUrl('_FILE', \TYPO3\CMS\Core\Utility\GeneralUtility::shortmd5($v))) . '#clip_head">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-selection-delete', array('title' => $this->clLabel('removeItem'))) . '</a>' . '</td> </tr>'; } else { // If the file did not exist (or is illegal) then it is removed from the clipboard immediately: unset($this->clipData[$pad]['el'][$k]); $this->changed = 1; } } else { // Rendering records: $rec = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordWSOL($table, $uid); if (is_array($rec)) { $lines[] = ' <tr> <td class="' . $bgColClass . '">' . $this->linkItemText(\TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord($table, $rec, array('style' => 'margin: 0 20px;', 'title' => htmlspecialchars(\TYPO3\CMS\Backend\Utility\BackendUtility::getRecordIconAltText($rec, $table)))), $rec, $table) . '</td> <td class="' . $bgColClass . '" nowrap="nowrap" width="95%"> ' . $this->linkItemText(htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs(\TYPO3\CMS\Backend\Utility\BackendUtility::getRecordTitle($table, $rec), $GLOBALS['BE_USER']->uc['titleLen'])), $rec, $table) . ($pad == 'normal' ? ' <strong>(' . ($this->clipData['normal']['mode'] == 'copy' ? $this->clLabel('copy', 'cm') : $this->clLabel('cut', 'cm')) . ')</strong>' : '') . ' </td> <td class="' . $bgColClass . '" align="center" nowrap="nowrap">' . '<a href="#" onclick="' . htmlspecialchars('top.launchView(\'' . $table . '\', \'' . intval($uid) . '\'); return false;') . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-info', array('title' => $this->clLabel('info', 'cm'))) . '</a>' . '<a href="' . htmlspecialchars($this->removeUrl($table, $uid)) . '#clip_head">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-selection-delete', array('title' => $this->clLabel('removeItem'))) . '</a>' . '</td> </tr>'; $localizationData = $this->getLocalizations($table, $rec, $bgColClass, $pad); if ($localizationData) { $lines[] = $localizationData; } } else { unset($this->clipData[$pad]['el'][$k]); $this->changed = 1; } } } } } if (!count($lines)) { $lines[] = ' <tr> <td class="bgColor4"><img src="clear.gif" width="56" height="1" alt="" /></td> <td colspan="2" class="bgColor4" nowrap="nowrap" width="95%"> <em>(' . $this->clLabel('clipNoEl') . ')</em> </td> </tr>'; } $this->endClipboard(); return $lines; }
/** * Returns a linked image-tag for thumbnail(s)/fileicons/truetype-font-previews from a database row with a list of image files in a field * All $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] extension are made to thumbnails + ttf file (renders font-example) * Thumbsnails are linked to the show_item.php script which will display further details. * * @param array $row Row is the database row from the table, $table. * @param string $table Table name for $row (present in TCA) * @param string $field Field is pointing to the list of image files * @param string $backPath Back path prefix for image tag src="" field * @param string $thumbScript Optional: $thumbScript - not used anymore since FAL * @param string $uploaddir Optional: $uploaddir is the directory relative to PATH_site where the image files from the $field value is found (Is by default set to the entry in $GLOBALS['TCA'] for that field! so you don't have to!) * @param boolean $abs If set, uploaddir is NOT prepended with "../ * @param string $tparams Optional: $tparams is additional attributes for the image tags * @param integer $size Optional: $size is [w]x[h] of the thumbnail. 56 is default. * @param boolean $linkInfoPopup Whether to wrap with a link opening the info popup * @return string Thumbnail image tag. */ public static function thumbCode($row, $table, $field, $backPath, $thumbScript = '', $uploaddir = NULL, $abs = 0, $tparams = '', $size = '', $linkInfoPopup = TRUE) { // Load table. \TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA($table); $tcaConfig = $GLOBALS['TCA'][$table]['columns'][$field]['config']; // Check and parse the size parameter $sizeParts = array(64, 64); if ($size = trim($size)) { $sizeParts = explode('x', $size . 'x' . $size); if (!intval($sizeParts[0])) { $size = ''; } } $thumbData = ''; // FAL references if ($tcaConfig['type'] === 'inline') { $referenceUids = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid', 'sys_file_reference', 'tablenames = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($table, 'sys_file_reference') . ' AND fieldname=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($field, 'sys_file_reference') . ' AND uid_foreign=' . intval($row['uid']) . self::deleteClause('sys_file_reference') . self::versioningPlaceholderClause('sys_file_reference')); foreach ($referenceUids as $referenceUid) { $fileReferenceObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFileReferenceObject($referenceUid['uid']); $fileObject = $fileReferenceObject->getOriginalFile(); // Web image if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileReferenceObject->getExtension())) { $imageUrl = $fileObject->process(\TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW, array('width' => $sizeParts[0], 'height' => $sizeParts[1]))->getPublicUrl(TRUE); $imgTag = '<img src="' . $imageUrl . '" alt="' . htmlspecialchars($fileReferenceObject->getName()) . '" />'; } else { // Icon $imgTag = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile(strtolower($fileObject->getExtension()), array('title' => $fileObject->getName())); } if ($linkInfoPopup) { $onClick = 'top.launchView(\'_FILE\',\'' . $fileObject->getUid() . '\',\'' . $backPath . '\'); return false;'; $thumbData .= '<a href="#" onclick="' . htmlspecialchars($onClick) . '">' . $imgTag . '</a> '; } else { $thumbData .= $imgTag; } } } else { // Find uploaddir automatically if (is_null($uploaddir)) { $uploaddir = $GLOBALS['TCA'][$table]['columns'][$field]['config']['uploadfolder']; } $uploaddir = rtrim($uploaddir, '/'); // Traverse files: $thumbs = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $row[$field], TRUE); $thumbData = ''; foreach ($thumbs as $theFile) { if ($theFile) { $fileName = trim($uploaddir . '/' . $theFile, '/'); $fileObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($fileName); $fileExtension = $fileObject->getExtension(); if ($fileExtension == 'ttf' || \TYPO3\CMS\Core\Utility\GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileExtension)) { $imageUrl = $fileObject->process(\TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW, array('width' => $sizeParts[0], 'height' => $sizeParts[1]))->getPublicUrl(TRUE); if (!$fileObject->checkActionPermission('read')) { /** @var $flashMessage \TYPO3\CMS\Core\Messaging\FlashMessage */ $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.file_missing_text') . ' <abbr title="' . htmlspecialchars($fileObject->getName()) . '">' . htmlspecialchars($fileObject->getName()) . '</abbr>', $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.file_missing'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR); $thumbData .= $flashMessage->render(); continue; } $image = '<img src="' . htmlspecialchars($imageUrl) . '" hspace="2" border="0" title="' . htmlspecialchars($fileObject->getName()) . '"' . $tparams . ' alt="" />'; if ($linkInfoPopup) { $onClick = 'top.launchView(\'_FILE\', \'' . $fileName . '\',\'\',\'' . $backPath . '\');return false;'; $thumbData .= '<a href="#" onclick="' . htmlspecialchars($onClick) . '">' . $image . '</a> '; } else { $thumbData .= $image; } } else { // Gets the icon $fileIcon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile($fileExtension, array('title' => $fileObject->getName())); if ($linkInfoPopup) { $onClick = 'top.launchView(\'_FILE\', \'' . $fileName . '\',\'\',\'' . $backPath . '\'); return false;'; $thumbData .= '<a href="#" onclick="' . htmlspecialchars($onClick) . '">' . $fileIcon . '</a> '; } else { $thumbData .= $fileIcon; } } } } } return $thumbData; }
/** * Rendering preview output of a field value which is not shown as a form field but just outputted. * * @param string $value The value to output * @param array $config Configuration for field. * @param string $field Name of field. * @return string HTML formatted output * @todo Define visibility */ public function previewFieldValue($value, $config, $field = '') { if ($config['config']['type'] === 'group' && ($config['config']['internal_type'] === 'file' || $config['config']['internal_type'] === 'file_reference')) { // Ignore uploadfolder if internal_type is file_reference if ($config['config']['internal_type'] === 'file_reference') { $config['config']['uploadfolder'] = ''; } $show_thumbs = TRUE; $table = 'tt_content'; // Making the array of file items: $itemArray = GeneralUtility::trimExplode(',', $value, TRUE); // Showing thumbnails: $thumbsnail = ''; if ($show_thumbs) { $imgs = array(); foreach ($itemArray as $imgRead) { $imgP = explode('|', $imgRead); $imgPath = rawurldecode($imgP[0]); $rowCopy = array(); $rowCopy[$field] = $imgPath; // Icon + clickmenu: $absFilePath = GeneralUtility::getFileAbsFileName($config['config']['uploadfolder'] ? $config['config']['uploadfolder'] . '/' . $imgPath : $imgPath); $fileInformation = pathinfo($imgPath); $fileIcon = IconUtility::getSpriteIconForFile($imgPath, array('title' => htmlspecialchars($fileInformation['basename'] . ($absFilePath && @is_file($absFilePath) ? ' (' . GeneralUtility::formatSize(filesize($absFilePath)) . 'bytes)' : ' - FILE NOT FOUND!')))); $imgs[] = '<span class="nobr">' . BackendUtility::thumbCode($rowCopy, $table, $field, $this->backPath, 'thumbs.php', $config['config']['uploadfolder'], 0, ' align="middle"') . ($absFilePath ? $this->getClickMenu($fileIcon, $absFilePath) : $fileIcon) . $imgPath . '</span>'; } $thumbsnail = implode('<br />', $imgs); } return $thumbsnail; } else { return nl2br(htmlspecialchars($value)); } }
/** * For RTE: This displays all IMAGES (gif,png,jpg) (from extensionList) from folder. Thumbnails are shown for images. * This listing is of images located in the web-accessible paths ONLY - the listing is for drag-n-drop use in the RTE * * @param \TYPO3\CMS\Core\Resource\Folder $folder The folder path to expand * @param string $extensionList List of fileextensions to show * @return string HTML output * @todo Define visibility */ public function TBE_dragNDrop(\TYPO3\CMS\Core\Resource\Folder $folder, $extensionList = '') { $extensionList = $extensionList == '*' ? '' : $extensionList; $out = ''; if ($folder) { if ($folder->getStorage()->isPublic()) { // Read files from directory: $files = $folder->getFiles($extensionList); if (is_array($files)) { $out .= $this->barheader(sprintf($GLOBALS['LANG']->getLL('files') . ' (%s):', count($files))); $titleLen = intval($GLOBALS['BE_USER']->uc['titleLen']); $picon = '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/i/_icon_webfolders.gif', 'width="18" height="16"') . ' alt="" />'; $picon .= htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs(basename($folder->getName()), $titleLen)); $out .= $picon . '<br />'; // Init row-array: $lines = array(); // Add "drag-n-drop" message: $lines[] = ' <tr> <td colspan="2">' . $this->getMsgBox($GLOBALS['LANG']->getLL('findDragDrop')) . '</td> </tr>'; // Traverse files: foreach ($files as $fileObject) { $fileInfo = $fileObject->getStorage()->getFileInfo($fileObject); // URL of image: $iUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::rawurlencodeFP($fileObject->getPublicUrl(TRUE)); // Show only web-images $fileExtension = strtolower($fileObject->getExtension()); if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList('gif,jpeg,jpg,png', $fileExtension)) { $imgInfo = @getimagesize($fileObject->getForLocalProcessing(FALSE)); $pDim = $imgInfo[0] . 'x' . $imgInfo[1] . ' pixels'; $size = ' (' . \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($fileObject->getSize()) . 'bytes' . ($pDim ? ', ' . $pDim : '') . ')'; $filenameAndIcon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile($fileExtension, array('title' => $fileObject->getName() . $size)); if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('noLimit')) { $maxW = 10000; $maxH = 10000; } else { $maxW = 380; $maxH = 500; } $IW = $imgInfo[0]; $IH = $imgInfo[1]; if ($IW > $maxW) { $IH = ceil($IH / $IW * $maxW); $IW = $maxW; } if ($IH > $maxH) { $IW = ceil($IW / $IH * $maxH); $IH = $maxH; } // Make row: $lines[] = ' <tr class="bgColor4"> <td nowrap="nowrap">' . $filenameAndIcon . ' </td> <td nowrap="nowrap">' . ($imgInfo[0] != $IW ? '<a href="' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(array('noLimit' => '1'))) . '">' . '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/icon_warning2.gif', 'width="18" height="16"') . ' title="' . $GLOBALS['LANG']->getLL('clickToRedrawFullSize', 1) . '" alt="" />' . '</a>' : '') . $pDim . ' </td> </tr>'; $lines[] = ' <tr> <td colspan="2"><img src="' . $iUrl . '" data-htmlarea-file-uid="' . $fileObject->getUid() . '" width="' . $IW . '" height="' . $IH . '" border="1" alt="" /></td> </tr>'; $lines[] = ' <tr> <td colspan="2"><img src="clear.gif" width="1" height="3" alt="" /></td> </tr>'; } } // Finally, wrap all rows in a table tag: $out .= ' <!-- File listing / Drag-n-drop --> <table border="0" cellpadding="0" cellspacing="1" id="typo3-dragBox"> ' . implode('', $lines) . ' </table>'; } } else { // Print this warning if the folder is NOT a web folder: $out .= $this->barheader($GLOBALS['LANG']->getLL('files')); $out .= $this->getMsgBox($GLOBALS['LANG']->getLL('noWebFolder'), 'icon_warning2'); } } return $out; }
/** * This returns tablerows for the files in the array $items['sorting']. * * @param \TYPO3\CMS\Core\Resource\File[] $files File items * @return string HTML table rows. * @todo Define visibility */ public function formatFileList(array $files) { $out = ''; foreach ($files as $fileObject) { list($flag, $code) = $this->fwd_rwd_nav(); $out .= $code; if ($flag) { // Initialization $this->counter++; $fileInfo = $fileObject->getStorage()->getFileInfo($fileObject); $this->totalbytes += $fileObject->getSize(); $ext = $fileObject->getExtension(); $fileName = trim($fileObject->getName()); // The icon with link $theIcon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile($ext, array('title' => $fileName)); if ($this->clickMenus) { $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($theIcon, $fileObject->getCombinedIdentifier()); } // Preparing and getting the data-array $theData = array(); foreach ($this->fieldArray as $field) { switch ($field) { case 'size': $theData[$field] = \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($fileObject->getSize(), $GLOBALS['LANG']->getLL('byteSizeUnits', TRUE)); break; case 'rw': $theData[$field] = '' . (!$fileObject->checkActionPermission('read') ? ' ' : '<span class="typo3-red"><strong>' . $GLOBALS['LANG']->getLL('read', TRUE) . '</strong></span>') . (!$fileObject->checkActionPermission('write') ? '' : '<span class="typo3-red"><strong>' . $GLOBALS['LANG']->getLL('write', TRUE) . '</strong></span>'); break; case 'fileext': $theData[$field] = strtoupper($ext); break; case 'tstamp': $theData[$field] = \TYPO3\CMS\Backend\Utility\BackendUtility::date($fileInfo['mtime']); break; case '_CLIPBOARD_': $temp = ''; if ($this->bigControlPanel) { $temp .= $this->makeEdit($fileObject); } $temp .= $this->makeClip($fileObject); $theData[$field] = $temp; break; case '_REF_': $theData[$field] = $this->makeRef($fileObject); break; case 'file': $theData[$field] = $this->linkWrapFile(htmlspecialchars($fileName), $fileObject); // Thumbnails? if ($this->thumbs && $this->isImage($ext)) { $processedFile = $fileObject->process(\TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW, array()); if ($processedFile) { $thumbUrl = $processedFile->getPublicUrl(TRUE); $theData[$field] .= '<br /><img src="' . $thumbUrl . '" hspace="2" title="' . htmlspecialchars($fileName) . '" alt="" />'; } } break; default: // @todo: fix the access on the array $theData[$field] = htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($theFile[$field], $this->fixedL)); break; } } $out .= $this->addelement(1, $theIcon, $theData, ' class="file_list_normal"'); } $this->eCounter++; } return $out; }
/** * 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 . ' </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"> ' . $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 . ' </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> </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; }
/** * 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() . ' ' . '<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) { // Ignored fields if ($name === 'size') { continue; } 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()) { $references = $this->makeRef('_FILE', $this->fileObject); if (!empty($references)) { $header = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:show_item.php.referencesToThisItem'); $this->content .= $this->doc->section($header, $references); } } }
/** * Tests the returns of file png + option * * @test */ public function getSpriteIconForFileWithPngAndOptionsReturnsPngSpriteAndOptions() { $result = IconUtility::getSpriteIconForFile('png', array('title' => 'bar')); $this->assertEquals('<span title="bar" class="t3-icon t3-icon-mimetypes t3-icon-mimetypes-media t3-icon-media-image"> </span>', $result); }