Ejemplo n.º 1
0
 /**
  * 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)
 {
     // Check and parse the size parameter
     $sizeParts = array(64, 64);
     if ($size = trim($size)) {
         $sizeParts = explode('x', $size . 'x' . $size);
         if (!(int) $sizeParts[0]) {
             $size = '';
         }
     }
     $thumbData = '';
     $fileReferences = static::resolveFileReferences($table, $field, $row);
     // FAL references
     if ($fileReferences !== NULL) {
         foreach ($fileReferences as $fileReferenceObject) {
             $fileObject = $fileReferenceObject->getOriginalFile();
             if ($fileObject->isMissing()) {
                 $flashMessage = \TYPO3\CMS\Core\Resource\Utility\BackendUtility::getFlashMessageForMissingFile($fileObject);
                 $thumbData .= $flashMessage->render();
                 continue;
             }
             // Web image
             if (GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileReferenceObject->getExtension())) {
                 $imageUrl = $fileObject->process(ProcessedFile::CONTEXT_IMAGEPREVIEW, array('width' => $sizeParts[0], 'height' => $sizeParts[1]))->getPublicUrl(TRUE);
                 $imgTag = '<img src="' . $imageUrl . '" alt="' . htmlspecialchars($fileReferenceObject->getName()) . '" />';
             } else {
                 // Icon
                 $imgTag = IconUtility::getSpriteIconForResource($fileObject, 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 = GeneralUtility::trimExplode(',', $row[$field], TRUE);
         $thumbData = '';
         foreach ($thumbs as $theFile) {
             if ($theFile) {
                 $fileName = trim($uploaddir . '/' . $theFile, '/');
                 try {
                     /** @var File $fileObject */
                     $fileObject = ResourceFactory::getInstance()->retrieveFileOrFolderObject($fileName);
                     if ($fileObject->isMissing()) {
                         $flashMessage = \TYPO3\CMS\Core\Resource\Utility\BackendUtility::getFlashMessageForMissingFile($fileObject);
                         $thumbData .= $flashMessage->render();
                         continue;
                     }
                 } catch (\TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException $exception) {
                     /** @var \TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage */
                     $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', htmlspecialchars($exception->getMessage()), $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:warning.file_missing', TRUE), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
                     $thumbData .= $flashMessage->render();
                     continue;
                 }
                 $fileExtension = $fileObject->getExtension();
                 if ($fileExtension == 'ttf' || GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileExtension)) {
                     $imageUrl = $fileObject->process(ProcessedFile::CONTEXT_IMAGEPREVIEW, array('width' => $sizeParts[0], 'height' => $sizeParts[1]))->getPublicUrl(TRUE);
                     $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 = IconUtility::getSpriteIconForResource($fileObject, 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;
 }
Ejemplo n.º 2
0
    /**
     * 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 Folder $folder The folder path to expand
     * @param string $extensionList List of file extensions to show
     * @return string HTML output
     * @todo Define visibility
     */
    public function TBE_dragNDrop(Folder $folder, $extensionList = '')
    {
        if (!$folder) {
            return '';
        }
        if (!$folder->getStorage()->isPublic()) {
            // Print this warning if the folder is NOT a web folder
            return $this->barheader($GLOBALS['LANG']->getLL('files')) . $this->getMsgBox($GLOBALS['LANG']->getLL('noWebFolder'), 'icon_warning2');
        }
        $out = '';
        // Read files from directory:
        $extensionList = $extensionList == '*' ? '' : $extensionList;
        $files = $this->getFilesInFolder($folder, $extensionList);
        $out .= $this->barheader(sprintf($GLOBALS['LANG']->getLL('files') . ' (%s):', count($files)));
        $titleLen = (int) $GLOBALS['BE_USER']->uc['titleLen'];
        $picon = '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/i/_icon_webfolders.gif', 'width="18" height="16"') . ' alt="" />';
        $picon .= htmlspecialchars(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 = GeneralUtility::rawurlencodeFP($fileObject->getPublicUrl(TRUE));
            // Show only web-images
            $fileExtension = strtolower($fileObject->getExtension());
            if (GeneralUtility::inList('gif,jpeg,jpg,png', $fileExtension)) {
                $imgInfo = array($fileObject->getProperty('width'), $fileObject->getProperty('height'));
                $pDim = $imgInfo[0] . 'x' . $imgInfo[1] . ' pixels';
                $size = ' (' . GeneralUtility::formatSize($fileObject->getSize()) . 'bytes' . ($pDim ? ', ' . $pDim : '') . ')';
                $filenameAndIcon = IconUtility::getSpriteIconForResource($fileObject, array('title' => $fileObject->getName() . $size));
                if (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 . '&nbsp;</td>
						<td nowrap="nowrap">' . ($imgInfo[0] != $IW ? '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(array('noLimit' => '1'))) . '">' . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/icon_warning2.gif', 'width="18" height="16"') . ' title="' . $GLOBALS['LANG']->getLL('clickToRedrawFullSize', TRUE) . '" alt="" />' . '</a>' : '') . $pDim . '&nbsp;</td>
					</tr>';
                $lines[] = '
					<tr>
						<td colspan="2"><img src="' . htmlspecialchars($iUrl) . '" data-htmlarea-file-uid="' . $fileObject->getUid() . '" width="' . htmlspecialchars($IW) . '" height="' . htmlspecialchars($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>';
        return $out;
    }
Ejemplo n.º 3
0
 /**
  * This returns tablerows for the files in the array $items['sorting'].
  *
  * @param File[] $files File items
  * @return string HTML table rows.
  */
 public function formatFileList(array $files)
 {
     $out = '';
     // first two keys are "0" (default) and "-1" (multiple), after that comes the "other languages"
     $allSystemLanguages = GeneralUtility::makeInstance(TranslationConfigurationProvider::class)->getSystemLanguages();
     $systemLanguages = array_filter($allSystemLanguages, function ($languageRecord) {
         if ($languageRecord['uid'] === -1 || $languageRecord['uid'] === 0 || !$this->getBackendUser()->checkLanguageAccess($languageRecord['uid'])) {
             return FALSE;
         } else {
             return TRUE;
         }
     });
     foreach ($files as $fileObject) {
         // Initialization
         $this->counter++;
         $this->totalbytes += $fileObject->getSize();
         $ext = $fileObject->getExtension();
         $fileName = trim($fileObject->getName());
         // The icon with link
         $theIcon = IconUtility::getSpriteIconForResource($fileObject, array('title' => $fileName . ' [' . (int) $fileObject->getUid() . ']'));
         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] = GeneralUtility::formatSize($fileObject->getSize(), $this->getLanguageService()->getLL('byteSizeUnits', TRUE));
                     break;
                 case 'rw':
                     $theData[$field] = '' . (!$fileObject->checkActionPermission('read') ? ' ' : '<strong class="text-danger">' . $this->getLanguageService()->getLL('read', TRUE) . '</strong>') . (!$fileObject->checkActionPermission('write') ? '' : '<strong class="text-danger">' . $this->getLanguageService()->getLL('write', TRUE) . '</strong>');
                     break;
                 case 'fileext':
                     $theData[$field] = strtoupper($ext);
                     break;
                 case 'tstamp':
                     $theData[$field] = BackendUtility::date($fileObject->getModificationTime());
                     break;
                 case '_CONTROL_':
                     $theData[$field] = $this->makeEdit($fileObject);
                     break;
                 case '_CLIPBOARD_':
                     $theData[$field] = $this->makeClip($fileObject);
                     break;
                 case '_LOCALIZATION_':
                     if (!empty($systemLanguages) && $fileObject->isIndexed() && $fileObject->checkActionPermission('write') && $this->getBackendUser()->check('tables_modify', 'sys_file_metadata')) {
                         $metaDataRecord = $fileObject->_getMetaData();
                         $translations = $this->getTranslationsForMetaData($metaDataRecord);
                         $languageCode = '';
                         foreach ($systemLanguages as $language) {
                             $languageId = $language['uid'];
                             $flagIcon = $language['flagIcon'];
                             if (array_key_exists($languageId, $translations)) {
                                 $flagButtonIcon = IconUtility::getSpriteIcon('actions-document-open', array('title' => sprintf($GLOBALS['LANG']->getLL('editMetadataForLanguage'), $language['title'])), array($flagIcon . '-overlay' => array()));
                                 $data = array('sys_file_metadata' => array($translations[$languageId]['uid'] => 'edit'));
                                 $editOnClick = BackendUtility::editOnClick(GeneralUtility::implodeArrayForUrl('edit', $data), $GLOBALS['BACK_PATH'], $this->listUrl());
                                 $languageCode .= '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($editOnClick) . '">' . $flagButtonIcon . '</a>';
                             } else {
                                 $parameters = ['justLocalized' => 'sys_file_metadata:' . $metaDataRecord['uid'] . ':' . $languageId, 'returnUrl' => $this->listURL()];
                                 $returnUrl = BackendUtility::getModuleUrl('record_edit', $parameters, $this->backPath) . BackendUtility::getUrlToken('editRecord');
                                 $href = $GLOBALS['SOBE']->doc->issueCommand('&cmd[sys_file_metadata][' . $metaDataRecord['uid'] . '][localize]=' . $languageId, $returnUrl);
                                 $flagButtonIcon = IconUtility::getSpriteIcon($flagIcon, array('title' => sprintf($GLOBALS['LANG']->getLL('createMetadataForLanguage'), $language['title'])), array($flagIcon . '-overlay' => array()));
                                 $languageCode .= '<a href="' . htmlspecialchars($href) . '" class="btn btn-default">' . $flagButtonIcon . '</a> ';
                             }
                         }
                         // Hide flag button bar when not translated yet
                         $theData[$field] = ' <div class="localisationData btn-group" data-fileid="' . $fileObject->getUid() . '"' . (empty($translations) ? ' style="display: none;"' : '') . '>' . $languageCode . '</div>';
                         $theData[$field] .= '<a class="btn btn-default filelist-translationToggler" data-fileid="' . $fileObject->getUid() . '">' . IconUtility::getSpriteIcon('mimetypes-x-content-page-language-overlay', array('title' => $GLOBALS['LANG']->getLL('translateMetadata'))) . '</a>';
                     }
                     break;
                 case '_REF_':
                     $theData[$field] = $this->makeRef($fileObject);
                     break;
                 case 'file':
                     // Edit metadata of file
                     $theData[$field] = $this->linkWrapFile(htmlspecialchars($fileName), $fileObject);
                     if ($fileObject->isMissing()) {
                         $flashMessage = \TYPO3\CMS\Core\Resource\Utility\BackendUtility::getFlashMessageForMissingFile($fileObject);
                         $theData[$field] .= $flashMessage->render();
                         // Thumbnails?
                     } elseif ($this->thumbs && $this->isImage($ext)) {
                         $processedFile = $fileObject->process(ProcessedFile::CONTEXT_IMAGEPREVIEW, array());
                         if ($processedFile) {
                             $thumbUrl = $processedFile->getPublicUrl(TRUE);
                             $theData[$field] .= '<br /><img src="' . $thumbUrl . '" ' . 'width="' . $processedFile->getProperty('width') . '" ' . 'height="' . $processedFile->getProperty('height') . '" ' . 'title="' . htmlspecialchars($fileName) . '" alt="" />';
                         }
                     }
                     break;
                 default:
                     $theData[$field] = '';
                     if ($fileObject->hasProperty($field)) {
                         $theData[$field] = htmlspecialchars(GeneralUtility::fixed_lgd_cs($fileObject->getProperty($field), $this->fixedL));
                     }
             }
         }
         $out .= $this->addelement(1, $theIcon, $theData);
     }
     return $out;
 }
Ejemplo n.º 4
0
 /**
  * Fetches the data for the tree
  *
  * @param \TYPO3\CMS\Core\Resource\Folder $folderObject the folderobject
  * @param int $depth Max depth (recursivity limit)
  * @param string $type HTML-code prefix for recursive calls.
  * @return int The count of items on the level
  * @see getBrowsableTree()
  */
 public function getFolderTree(\TYPO3\CMS\Core\Resource\Folder $folderObject, $depth = 999, $type = '')
 {
     $depth = (int) $depth;
     // This generates the directory tree
     /* array of \TYPO3\CMS\Core\Resource\Folder */
     if ($folderObject instanceof \TYPO3\CMS\Core\Resource\InaccessibleFolder) {
         $subFolders = array();
     } else {
         $subFolders = $folderObject->getSubfolders();
         $subFolders = \TYPO3\CMS\Core\Resource\Utility\ListUtility::resolveSpecialFolderNames($subFolders);
         uksort($subFolders, 'strnatcasecmp');
     }
     $totalSubFolders = count($subFolders);
     $HTML = '';
     $subFolderCounter = 0;
     foreach ($subFolders as $subFolderName => $subFolder) {
         $subFolderCounter++;
         // Reserve space.
         $this->tree[] = array();
         // Get the key for this space
         end($this->tree);
         $isLocked = $subFolder instanceof \TYPO3\CMS\Core\Resource\InaccessibleFolder;
         $treeKey = key($this->tree);
         $specUID = GeneralUtility::md5int($subFolder->getCombinedIdentifier());
         $this->specUIDmap[$specUID] = $subFolder->getCombinedIdentifier();
         $row = array('uid' => $specUID, 'path' => $subFolder->getCombinedIdentifier(), 'title' => $subFolderName, 'folder' => $subFolder);
         // Make a recursive call to the next level
         if (!$isLocked && $depth > 1 && $this->expandNext($specUID)) {
             $nextCount = $this->getFolderTree($subFolder, $depth - 1, $type);
             // Set "did expand" flag
             $isOpen = 1;
         } else {
             $nextCount = $isLocked ? 0 : $this->getNumberOfSubfolders($subFolder);
             // Clear "did expand" flag
             $isOpen = 0;
         }
         // Set HTML-icons, if any:
         if ($this->makeHTML) {
             $HTML = $this->PMicon($subFolder, $subFolderCounter, $totalSubFolders, $nextCount, $isOpen);
             $type = '';
             $role = $subFolder->getRole();
             if ($role !== FolderInterface::ROLE_DEFAULT) {
                 $row['_title'] = '<strong>' . $subFolderName . '</strong>';
             }
             $icon = IconUtility::getSpriteIconForResource($subFolder, array('title' => $subFolderName, 'folder-open' => (bool) $isOpen));
             $HTML .= $this->wrapIcon($icon, $subFolder);
         }
         // Finally, add the row/HTML content to the ->tree array in the reserved key.
         $this->tree[$treeKey] = array('row' => $row, 'HTML' => $HTML, 'hasSub' => $nextCount && $this->expandNext($specUID), 'isFirst' => $subFolderCounter == 1, 'isLast' => FALSE, 'invertedDepth' => $depth, 'bank' => $this->bank);
     }
     if ($subFolderCounter > 0) {
         $this->tree[$treeKey]['isLast'] = TRUE;
     }
     return $totalSubFolders;
 }
Ejemplo n.º 5
0
	/**
	 * This will render a selector box into which elements from either
	 * the file system or database can be inserted. Relations.
	 *
	 * @return array As defined in initializeResultArray() of AbstractNode
	 */
	public function render() {
		$table = $this->globalOptions['table'];
		$fieldName = $this->globalOptions['fieldName'];
		$row = $this->globalOptions['databaseRow'];
		$parameterArray = $this->globalOptions['parameterArray'];
		$config = $parameterArray['fieldConf']['config'];
		$show_thumbs = $config['show_thumbs'];
		$resultArray = $this->initializeResultArray();

		$size = isset($config['size']) ? (int)$config['size'] : $this->minimumInputWidth;
		$maxitems = MathUtility::forceIntegerInRange($config['maxitems'], 0);
		if (!$maxitems) {
			$maxitems = 100000;
		}
		$minitems = MathUtility::forceIntegerInRange($config['minitems'], 0);
		$thumbnails = array();
		$allowed = GeneralUtility::trimExplode(',', $config['allowed'], TRUE);
		$disallowed = GeneralUtility::trimExplode(',', $config['disallowed'], TRUE);
		$disabled = ($this->isGlobalReadonly() || $config['readOnly']);
		$info = array();
		$parameterArray['itemFormElID_file'] = $parameterArray['itemFormElID'] . '_files';

		// whether the list and delete controls should be disabled
		$noList = isset($config['disable_controls']) && GeneralUtility::inList($config['disable_controls'], 'list');
		$noDelete = isset($config['disable_controls']) && GeneralUtility::inList($config['disable_controls'], 'delete');

		// "Extra" configuration; Returns configuration for the field based on settings found in the "types" fieldlist.
		$specConf = BackendUtility::getSpecConfParts($parameterArray['fieldConf']['defaultExtras']);

		// Register properties in requiredElements
		$resultArray['requiredElements'][$parameterArray['itemFormElName']] = array(
			$minitems,
			$maxitems,
			'imgName' => $table . '_' . $row['uid'] . '_' . $fieldName
		);
		$tabAndInlineStack = $this->globalOptions['tabAndInlineStack'];
		if (!empty($tabAndInlineStack) && preg_match('/^(.+\\])\\[(\\w+)\\]$/', $parameterArray['itemFormElName'], $match)) {
			array_shift($match);
			$resultArray['requiredNested'][$parameterArray['itemFormElName']] = array(
				'parts' => $match,
				'level' => $tabAndInlineStack,
			);
		}

		// If maxitems==1 then automatically replace the current item (in list and file selector)
		if ($maxitems === 1) {
			$resultArray['additionalJavaScriptPost'][] =
				'TBE_EDITOR.clearBeforeSettingFormValueFromBrowseWin[' . GeneralUtility::quoteJSvalue($parameterArray['itemFormElName']) . '] = {
					itemFormElID_file: ' . GeneralUtility::quoteJSvalue($parameterArray['itemFormElID_file']) . '
				}';
			$parameterArray['fieldChangeFunc']['TBE_EDITOR_fieldChanged'] = 'setFormValueManipulate(' . GeneralUtility::quoteJSvalue($parameterArray['itemFormElName'])
				. ', \'Remove\'); ' . $parameterArray['fieldChangeFunc']['TBE_EDITOR_fieldChanged'];
		} elseif ($noList) {
			// If the list controls have been removed and the maximum number is reached, remove the first entry to avoid "write once" field
			$parameterArray['fieldChangeFunc']['TBE_EDITOR_fieldChanged'] = 'setFormValueManipulate(' . GeneralUtility::quoteJSvalue($parameterArray['itemFormElName'])
				. ', \'RemoveFirstIfFull\', ' . GeneralUtility::quoteJSvalue($maxitems) . '); ' . $parameterArray['fieldChangeFunc']['TBE_EDITOR_fieldChanged'];
		}

		$html = '<input type="hidden" name="' . $parameterArray['itemFormElName'] . '_mul" value="' . ($config['multiple'] ? 1 : 0) . '"' . $disabled . ' />';

		// Acting according to either "file" or "db" type:
		switch ((string)$config['internal_type']) {
			case 'file_reference':
				$config['uploadfolder'] = '';
				// Fall through
			case 'file':
				// Creating string showing allowed types:
				if (!count($allowed)) {
					$allowed = array('*');
				}
				// Making the array of file items:
				$itemArray = GeneralUtility::trimExplode(',', $parameterArray['itemFormElValue'], TRUE);
				$fileFactory = ResourceFactory::getInstance();
				// Correct the filename for the FAL items
				foreach ($itemArray as &$fileItem) {
					list($fileUid, $fileLabel) = explode('|', $fileItem);
					if (MathUtility::canBeInterpretedAsInteger($fileUid)) {
						$fileObject = $fileFactory->getFileObject($fileUid);
						$fileLabel = $fileObject->getName();
					}
					$fileItem = $fileUid . '|' . $fileLabel;
				}
				// Showing thumbnails:
				if ($show_thumbs) {
					foreach ($itemArray as $imgRead) {
						$imgP = explode('|', $imgRead);
						$imgPath = rawurldecode($imgP[0]);
						// FAL icon production
						if (MathUtility::canBeInterpretedAsInteger($imgP[0])) {
							$fileObject = $fileFactory->getFileObject($imgP[0]);
							if ($fileObject->isMissing()) {
								$thumbnails[] = array(
									'message' => \TYPO3\CMS\Core\Resource\Utility\BackendUtility::getFlashMessageForMissingFile($fileObject)->render()
								);
							} elseif (GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileObject->getExtension())) {
								$thumbnails[] = array(
									'name' => htmlspecialchars($fileObject->getName()),
									'image' => $fileObject->process(ProcessedFile::CONTEXT_IMAGEPREVIEW, array())->getPublicUrl(TRUE)
								);
							} else {
								// Icon
								$thumbnails[] = array(
									'name' => htmlspecialchars($fileObject->getName()),
									'image' => IconUtility::getSpriteIconForResource($fileObject, array('title' => $fileObject->getName()))
								);
							}
						} else {
							$rowCopy = array();
							$rowCopy[$fieldName] = $imgPath;
							try {
								$thumbnails[] = array(
									'name' => $imgPath,
									'image' => BackendUtility::thumbCode(
										$rowCopy,
										$table,
										$fieldName,
										'',
										'',
										$config['uploadfolder'],
										0,
										' align="middle"'
									)
								);
							} catch (\Exception $exception) {
								/** @var $flashMessage FlashMessage */
								$message = $exception->getMessage();
								$flashMessage = GeneralUtility::makeInstance(
									FlashMessage::class,
									htmlspecialchars($message), '', FlashMessage::ERROR, TRUE
								);
								/** @var $flashMessageService FlashMessageService */
								$flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
								$defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
								$defaultFlashMessageQueue->enqueue($flashMessage);
								$logMessage = $message . ' (' . $table . ':' . $row['uid'] . ')';
								GeneralUtility::sysLog($logMessage, 'core', GeneralUtility::SYSLOG_SEVERITY_WARNING);
							}
						}
					}
				}
				// Creating the element:
				$params = array(
					'size' => $size,
					'allowed' => $allowed,
					'disallowed' => $disallowed,
					'dontShowMoveIcons' => $maxitems <= 1,
					'autoSizeMax' => MathUtility::forceIntegerInRange($config['autoSizeMax'], 0),
					'maxitems' => $maxitems,
					'style' => isset($config['selectedListStyle'])
						? ' style="' . htmlspecialchars($config['selectedListStyle']) . '"'
						: '',
					'thumbnails' => $thumbnails,
					'readOnly' => $disabled,
					'noBrowser' => $noList || isset($config['disable_controls']) && GeneralUtility::inList($config['disable_controls'], 'browser'),
					'noList' => $noList,
					'noDelete' => $noDelete
				);
				$html .= $this->dbFileIcons(
					$parameterArray['itemFormElName'],
					'file',
					implode(',', $allowed),
					$itemArray,
					'',
					$params,
					$parameterArray['onFocus'],
					'',
					'',
					'',
					$config);
				if (!$disabled && !(isset($config['disable_controls']) && GeneralUtility::inList($config['disable_controls'], 'upload'))) {
					// Adding the upload field:
					$isDirectFileUploadEnabled = (bool)$this->getBackendUserAuthentication()->uc['edit_docModuleUpload'];
					if ($isDirectFileUploadEnabled && $config['uploadfolder']) {
						// Insert the multiple attribute to enable HTML5 multiple file upload
						$multipleAttribute = '';
						$multipleFilenameSuffix = '';
						if (isset($config['maxitems']) && $config['maxitems'] > 1) {
							$multipleAttribute = ' multiple="multiple"';
							$multipleFilenameSuffix = '[]';
						}
						$html .= '
							<div id="' . $parameterArray['itemFormElID_file'] . '">
								<input type="file"' . $multipleAttribute . '
									name="data_files' . $this->globalOptions['elementBaseName'] . $multipleFilenameSuffix . '"
									size="35" onchange="' . implode('', $parameterArray['fieldChangeFunc']) . '"
								/>
							</div>';
					}
				}
				break;
			case 'folder':
				// If the element is of the internal type "folder":
				// Array of folder items:
				$itemArray = GeneralUtility::trimExplode(',', $parameterArray['itemFormElValue'], TRUE);
				// Creating the element:
				$params = array(
					'size' => $size,
					'dontShowMoveIcons' => $maxitems <= 1,
					'autoSizeMax' => MathUtility::forceIntegerInRange($config['autoSizeMax'], 0),
					'maxitems' => $maxitems,
					'style' => isset($config['selectedListStyle'])
						? ' style="' . htmlspecialchars($config['selectedListStyle']) . '"'
						: '',
					'readOnly' => $disabled,
					'noBrowser' => $noList || isset($config['disable_controls']) && GeneralUtility::inList($config['disable_controls'], 'browser'),
					'noList' => $noList
				);
				$html .= $this->dbFileIcons(
					$parameterArray['itemFormElName'],
					'folder',
					'',
					$itemArray,
					'',
					$params,
					$parameterArray['onFocus']
				);
				break;
			case 'db':
				// If the element is of the internal type "db":
				// Creating string showing allowed types:
				$onlySingleTableAllowed = FALSE;
				$languageService = $this->getLanguageService();

				$allowedTables = array();
				if ($allowed[0] === '*') {
					$allowedTables = array(
						'name' => htmlspecialchars($languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.allTables'))
					);
				} elseif ($allowed) {
					$onlySingleTableAllowed = count($allowed) == 1;
					foreach ($allowed as $allowedTable) {
						$allowedTables[] = array(
							'name' => htmlspecialchars($languageService->sL($GLOBALS['TCA'][$allowedTable]['ctrl']['title'])),
							'icon' => IconUtility::getSpriteIconForRecord($allowedTable, array()),
							'onClick' => 'setFormValueOpenBrowser(\'db\', ' . GeneralUtility::quoteJSvalue($parameterArray['itemFormElName'] . '|||' . $allowedTable) . '); return false;'
						);
					}
				}
				$perms_clause = $this->getBackendUserAuthentication()->getPagePermsClause(1);
				$itemArray = array();

				// Thumbnails:
				$temp_itemArray = GeneralUtility::trimExplode(',', $parameterArray['itemFormElValue'], TRUE);
				foreach ($temp_itemArray as $dbRead) {
					$recordParts = explode('|', $dbRead);
					list($this_table, $this_uid) = BackendUtility::splitTable_Uid($recordParts[0]);
					// For the case that no table was found and only a single table is defined to be allowed, use that one:
					if (!$this_table && $onlySingleTableAllowed) {
						$this_table = $allowed;
					}
					$itemArray[] = array('table' => $this_table, 'id' => $this_uid);
					if (!$disabled && $show_thumbs) {
						$rr = BackendUtility::getRecordWSOL($this_table, $this_uid);
						$thumbnails[] = array(
							'name' => BackendUtility::getRecordTitle($this_table, $rr, TRUE),
							'image' => IconUtility::getSpriteIconForRecord($this_table, $rr),
							'path' => BackendUtility::getRecordPath($rr['pid'], $perms_clause, 15),
							'uid' => $rr['uid'],
							'table' => $this_table
						);
					}
				}
				// Creating the element:
				$params = array(
					'size' => $size,
					'dontShowMoveIcons' => $maxitems <= 1,
					'autoSizeMax' => MathUtility::forceIntegerInRange($config['autoSizeMax'], 0),
					'maxitems' => $maxitems,
					'style' => isset($config['selectedListStyle'])
						? ' style="' . htmlspecialchars($config['selectedListStyle']) . '"'
						: '',
					'info' => $info,
					'allowedTables' => $allowedTables,
					'thumbnails' => $thumbnails,
					'readOnly' => $disabled,
					'noBrowser' => $noList || isset($config['disable_controls']) && GeneralUtility::inList($config['disable_controls'], 'browser'),
					'noList' => $noList
				);
				$html .= $this->dbFileIcons(
					$parameterArray['itemFormElName'],
					'db',
					implode(',', $allowed),
					$itemArray,
					'',
					$params,
					$parameterArray['onFocus'],
					$table,
					$fieldName,
					$row['uid'],
					$config
				);
				break;
		}
		// Wizards:
		$altItem = '<input type="hidden" name="' . $parameterArray['itemFormElName'] . '" value="' . htmlspecialchars($parameterArray['itemFormElValue']) . '" />';
		if (!$disabled) {
			$html = $this->renderWizards(
				array(
					$html,
					$altItem
				),
				$config['wizards'],
				$table,
				$row,
				$fieldName,
				$parameterArray,
				$parameterArray['itemFormElName'],
				$specConf
			);
		}
		$resultArray['html'] = $html;
		return $resultArray;
	}
Ejemplo n.º 6
0
    /**
     * 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 = ResourceFactory::getInstance()->retrieveFileOrFolderObject($v);
                        if ($fileObject) {
                            $thumb = '';
                            $folder = $fileObject instanceof \TYPO3\CMS\Core\Resource\Folder;
                            $size = $folder ? '' : '(' . GeneralUtility::formatSize($fileObject->getSize()) . 'bytes)';
                            $icon = IconUtility::getSpriteIconForResource($fileObject, array('style' => 'margin: 0 20px;', 'title' => $fileObject->getName() . ' ' . $size));
                            if (!$folder && $this->clipData['_setThumb'] && GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileObject->getExtension())) {
                                $processedFile = $fileObject->process(\TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW, array());
                                if ($processedFile) {
                                    $thumbUrl = $processedFile->getPublicUrl(TRUE);
                                    $thumb .= '<br /><img src="' . htmlspecialchars($thumbUrl) . '" title="' . htmlspecialchars($fileObject->getName()) . '" alt="" />';
                                }
                            }
                            $lines[] = '
								<tr>
									<td class="' . $bgColClass . '">' . $icon . '</td>
									<td class="' . $bgColClass . '" nowrap="nowrap" width="95%">&nbsp;' . $this->linkItemText(htmlspecialchars(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>' : '') . '&nbsp;' . $thumb . '</td>
									<td class="' . $bgColClass . '" align="center" nowrap="nowrap">' . '<a href="#" onclick="' . htmlspecialchars('top.launchView(\'' . $table . '\', \'' . $v . '\'); return false;') . '">' . IconUtility::getSpriteIcon('actions-document-info', array('title' => $this->clLabel('info', 'cm'))) . '</a>' . '<a href="' . htmlspecialchars($this->removeUrl('_FILE', GeneralUtility::shortmd5($v))) . '#clip_head">' . 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 = BackendUtility::getRecordWSOL($table, $uid);
                        if (is_array($rec)) {
                            $lines[] = '
								<tr>
									<td class="' . $bgColClass . '">' . $this->linkItemText(IconUtility::getSpriteIconForRecord($table, $rec, array('style' => 'margin: 0 20px;', 'title' => htmlspecialchars(BackendUtility::getRecordIconAltText($rec, $table)))), $rec, $table) . '</td>
									<td class="' . $bgColClass . '" nowrap="nowrap" width="95%">&nbsp;' . $this->linkItemText(htmlspecialchars(GeneralUtility::fixed_lgd_cs(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>' : '') . '&nbsp;</td>
									<td class="' . $bgColClass . '" align="center" nowrap="nowrap">' . '<a href="#" onclick="' . htmlspecialchars('top.launchView(\'' . $table . '\', \'' . (int) $uid . '\'); return false;') . '">' . IconUtility::getSpriteIcon('actions-document-info', array('title' => $this->clLabel('info', 'cm'))) . '</a>' . '<a href="' . htmlspecialchars($this->removeUrl($table, $uid)) . '#clip_head">' . 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%">&nbsp;<em>(' . $this->clLabel('clipNoEl') . ')</em>&nbsp;</td>
								</tr>';
        }
        $this->endClipboard();
        return $lines;
    }
Ejemplo n.º 7
0
 /**
  * Like ->getHeader() but for files and folders
  * Returns the icon with the path of the file/folder set in the alt/title attribute. Shows the name after the icon.
  *
  * @param \TYPO3\CMS\Core\Resource\ResourceInterface $resource
  * @param array $tWrap is an array with indexes 0 and 1 each representing HTML-tags (start/end) which will wrap the title
  * @param bool $enableClickMenu If TRUE, render click menu code around icon image
  * @return string
  */
 public function getResourceHeader(\TYPO3\CMS\Core\Resource\ResourceInterface $resource, $tWrap = array('', ''), $enableClickMenu = TRUE)
 {
     try {
         $path = $resource->getStorage()->getName() . $resource->getParentFolder()->getIdentifier();
         $iconImgTag = IconUtility::getSpriteIconForResource($resource, array('title' => htmlspecialchars($path)));
     } catch (\TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException $e) {
         $iconImgTag = '';
     }
     if ($enableClickMenu && $resource instanceof \TYPO3\CMS\Core\Resource\File) {
         $metaData = $resource->_getMetaData();
         $iconImgTag = $this->wrapClickMenuOnIcon($iconImgTag, 'sys_file_metadata', $metaData['uid']);
     }
     return '<span class="typo3-moduleHeader">' . $iconImgTag . $tWrap[0] . htmlspecialchars(GeneralUtility::fixed_lgd_cs($resource->getName(), 45)) . $tWrap[1] . '</span>';
 }
Ejemplo n.º 8
0
    /**
     * Generation of TCEform elements of the type "group"
     * This will render a selectorbox into which elements from either the file system or database can be inserted. Relations.
     *
     * @param string $table The table name of the record
     * @param string $field The field name which this element is supposed to edit
     * @param array $row The record data array where the value(s) for the field can be found
     * @param array $PA An array with additional configuration options.
     * @return string The HTML code for the TCEform field
     * @todo Define visibility
     */
    public function getSingleField_typeGroup($table, $field, $row, &$PA)
    {
        // Init:
        $config = $PA['fieldConf']['config'];
        $show_thumbs = $config['show_thumbs'];
        $size = isset($config['size']) ? (int) $config['size'] : 5;
        $maxitems = MathUtility::forceIntegerInRange($config['maxitems'], 0);
        if (!$maxitems) {
            $maxitems = 100000;
        }
        $minitems = MathUtility::forceIntegerInRange($config['minitems'], 0);
        $allowed = trim($config['allowed']);
        $disallowed = trim($config['disallowed']);
        $item = '';
        $disabled = '';
        if ($this->renderReadonly || $config['readOnly']) {
            $disabled = ' disabled="disabled"';
        }
        $item .= '<input type="hidden" name="' . $PA['itemFormElName'] . '_mul" value="' . ($config['multiple'] ? 1 : 0) . '"' . $disabled . ' />';
        $this->registerRequiredProperty('range', $PA['itemFormElName'], array($minitems, $maxitems, 'imgName' => $table . '_' . $row['uid'] . '_' . $field));
        $info = '';
        // "Extra" configuration; Returns configuration for the field based on settings found in the "types" fieldlist.
        $specConf = $this->getSpecConfFromString($PA['extra'], $PA['fieldConf']['defaultExtras']);
        $PA['itemFormElID_file'] = $PA['itemFormElID'] . '_files';
        // whether the list and delete controls should be disabled
        $noList = isset($config['disable_controls']) && GeneralUtility::inList($config['disable_controls'], 'list');
        $noDelete = isset($config['disable_controls']) && GeneralUtility::inList($config['disable_controls'], 'delete');
        // if maxitems==1 then automatically replace the current item (in list and file selector)
        if ($maxitems === 1) {
            $this->additionalJS_post[] = 'TBE_EDITOR.clearBeforeSettingFormValueFromBrowseWin[\'' . $PA['itemFormElName'] . '\'] = {
					itemFormElID_file: \'' . $PA['itemFormElID_file'] . '\'
				}';
            $PA['fieldChangeFunc']['TBE_EDITOR_fieldChanged'] = 'setFormValueManipulate(\'' . $PA['itemFormElName'] . '\', \'Remove\'); ' . $PA['fieldChangeFunc']['TBE_EDITOR_fieldChanged'];
        } elseif ($noList) {
            // If the list controls have been removed and the maximum number is reached, remove the first entry to avoid "write once" field
            $PA['fieldChangeFunc']['TBE_EDITOR_fieldChanged'] = 'setFormValueManipulate(\'' . $PA['itemFormElName'] . '\', \'RemoveFirstIfFull\', \'' . $maxitems . '\'); ' . $PA['fieldChangeFunc']['TBE_EDITOR_fieldChanged'];
        }
        // Acting according to either "file" or "db" type:
        switch ((string) $config['internal_type']) {
            case 'file_reference':
                $config['uploadfolder'] = '';
                // Fall through
            // Fall through
            case 'file':
                // Creating string showing allowed types:
                $tempFT = GeneralUtility::trimExplode(',', $allowed, TRUE);
                if (!count($tempFT)) {
                    $info .= '*';
                }
                foreach ($tempFT as $ext) {
                    if ($ext) {
                        $info .= strtoupper($ext) . ' ';
                    }
                }
                // Creating string, showing disallowed types:
                $tempFT_dis = GeneralUtility::trimExplode(',', $disallowed, TRUE);
                if (count($tempFT_dis)) {
                    $info .= '<br />';
                }
                foreach ($tempFT_dis as $ext) {
                    if ($ext) {
                        $info .= '-' . strtoupper($ext) . ' ';
                    }
                }
                // Making the array of file items:
                $itemArray = GeneralUtility::trimExplode(',', $PA['itemFormElValue'], TRUE);
                $fileFactory = ResourceFactory::getInstance();
                // Correct the filename for the FAL items
                foreach ($itemArray as &$fileItem) {
                    list($fileUid, $fileLabel) = explode('|', $fileItem);
                    if (MathUtility::canBeInterpretedAsInteger($fileUid)) {
                        $fileObject = $fileFactory->getFileObject($fileUid);
                        $fileLabel = $fileObject->getName();
                    }
                    $fileItem = $fileUid . '|' . $fileLabel;
                }
                // Showing thumbnails:
                $thumbsnail = '';
                if ($show_thumbs) {
                    $imgs = array();
                    foreach ($itemArray as $imgRead) {
                        $imgP = explode('|', $imgRead);
                        $imgPath = rawurldecode($imgP[0]);
                        // FAL icon production
                        if (MathUtility::canBeInterpretedAsInteger($imgP[0])) {
                            $fileObject = $fileFactory->getFileObject($imgP[0]);
                            if ($fileObject->isMissing()) {
                                $flashMessage = \TYPO3\CMS\Core\Resource\Utility\BackendUtility::getFlashMessageForMissingFile($fileObject);
                                $imgs[] = $flashMessage->render();
                            } elseif (GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileObject->getExtension())) {
                                $imageUrl = $fileObject->process(ProcessedFile::CONTEXT_IMAGEPREVIEW, array())->getPublicUrl(TRUE);
                                $imgTag = '<img src="' . $imageUrl . '" alt="' . htmlspecialchars($fileObject->getName()) . '" />';
                                $imgs[] = '<span class="nobr">' . $imgTag . htmlspecialchars($fileObject->getName()) . '</span>';
                            } else {
                                // Icon
                                $imgTag = IconUtility::getSpriteIconForResource($fileObject, array('title' => $fileObject->getName()));
                                $imgs[] = '<span class="nobr">' . $imgTag . htmlspecialchars($fileObject->getName()) . '</span>';
                            }
                        } else {
                            $rowCopy = array();
                            $rowCopy[$field] = $imgPath;
                            $thumbnailCode = '';
                            try {
                                $thumbnailCode = BackendUtility::thumbCode($rowCopy, $table, $field, $this->backPath, 'thumbs.php', $config['uploadfolder'], 0, ' align="middle"');
                                $thumbnailCode = '<span class="nobr">' . $thumbnailCode . $imgPath . '</span>';
                            } catch (\Exception $exception) {
                                /** @var $flashMessage FlashMessage */
                                $message = $exception->getMessage();
                                $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', htmlspecialchars($message), '', FlashMessage::ERROR, TRUE);
                                $class = 'TYPO3\\CMS\\Core\\Messaging\\FlashMessageService';
                                /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
                                $flashMessageService = GeneralUtility::makeInstance($class);
                                $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
                                $defaultFlashMessageQueue->enqueue($flashMessage);
                                $logMessage = $message . ' (' . $table . ':' . $row['uid'] . ')';
                                GeneralUtility::sysLog($logMessage, 'core', GeneralUtility::SYSLOG_SEVERITY_WARNING);
                            }
                            $imgs[] = $thumbnailCode;
                        }
                    }
                    $thumbsnail = implode('<br />', $imgs);
                }
                // Creating the element:
                $params = array('size' => $size, 'dontShowMoveIcons' => $maxitems <= 1, 'autoSizeMax' => MathUtility::forceIntegerInRange($config['autoSizeMax'], 0), 'maxitems' => $maxitems, 'style' => isset($config['selectedListStyle']) ? ' style="' . htmlspecialchars($config['selectedListStyle']) . '"' : ' style="' . $this->defaultMultipleSelectorStyle . '"', 'info' => $info, 'thumbnails' => $thumbsnail, 'readOnly' => $disabled, 'noBrowser' => $noList || isset($config['disable_controls']) && GeneralUtility::inList($config['disable_controls'], 'browser'), 'noList' => $noList, 'noDelete' => $noDelete);
                $item .= $this->dbFileIcons($PA['itemFormElName'], 'file', implode(',', $tempFT), $itemArray, '', $params, $PA['onFocus'], '', '', '', $config);
                if (!$disabled && !(isset($config['disable_controls']) && GeneralUtility::inList($config['disable_controls'], 'upload'))) {
                    // Adding the upload field:
                    if ($this->edit_docModuleUpload && $config['uploadfolder']) {
                        // Insert the multiple attribute to enable HTML5 multiple file upload
                        $multipleAttribute = '';
                        $multipleFilenameSuffix = '';
                        if (isset($config['maxitems']) && $config['maxitems'] > 1) {
                            $multipleAttribute = ' multiple="multiple"';
                            $multipleFilenameSuffix = '[]';
                        }
                        $item .= '<div id="' . $PA['itemFormElID_file'] . '"><input type="file"' . $multipleAttribute . ' name="' . $PA['itemFormElName_file'] . $multipleFilenameSuffix . '" size="35" onchange="' . implode('', $PA['fieldChangeFunc']) . '" /></div>';
                    }
                }
                break;
            case 'folder':
                // If the element is of the internal type "folder":
                // Array of folder items:
                $itemArray = GeneralUtility::trimExplode(',', $PA['itemFormElValue'], TRUE);
                // Creating the element:
                $params = array('size' => $size, 'dontShowMoveIcons' => $maxitems <= 1, 'autoSizeMax' => MathUtility::forceIntegerInRange($config['autoSizeMax'], 0), 'maxitems' => $maxitems, 'style' => isset($config['selectedListStyle']) ? ' style="' . htmlspecialchars($config['selectedListStyle']) . '"' : ' style="' . $this->defaultMultipleSelectorStyle . '"', 'info' => $info, 'readOnly' => $disabled, 'noBrowser' => $noList || isset($config['disable_controls']) && GeneralUtility::inList($config['disable_controls'], 'browser'), 'noList' => $noList);
                $item .= $this->dbFileIcons($PA['itemFormElName'], 'folder', '', $itemArray, '', $params, $PA['onFocus']);
                break;
            case 'db':
                // If the element is of the internal type "db":
                // Creating string showing allowed types:
                $tempFT = GeneralUtility::trimExplode(',', $allowed, TRUE);
                $onlySingleTableAllowed = FALSE;
                if (trim($tempFT[0]) === '*') {
                    $info .= '<span class="nobr">' . htmlspecialchars($this->getLL('l_allTables')) . '</span><br />';
                } elseif ($tempFT) {
                    $onlySingleTableAllowed = count($tempFT) == 1;
                    foreach ($tempFT as $theT) {
                        $aOnClick = 'setFormValueOpenBrowser(\'db\', \'' . ($PA['itemFormElName'] . '|||' . $theT) . '\'); return false;';
                        $info .= '<span class="nobr">
									<a href="#" onclick="' . htmlspecialchars($aOnClick) . '">' . IconUtility::getSpriteIconForRecord($theT, array()) . htmlspecialchars($this->sL($GLOBALS['TCA'][$theT]['ctrl']['title'])) . '</a></span><br />';
                    }
                }
                $perms_clause = $this->getBackendUserAuthentication()->getPagePermsClause(1);
                $itemArray = array();
                $imgs = array();
                // Thumbnails:
                $temp_itemArray = GeneralUtility::trimExplode(',', $PA['itemFormElValue'], TRUE);
                foreach ($temp_itemArray as $dbRead) {
                    $recordParts = explode('|', $dbRead);
                    list($this_table, $this_uid) = BackendUtility::splitTable_Uid($recordParts[0]);
                    // For the case that no table was found and only a single table is defined to be allowed, use that one:
                    if (!$this_table && $onlySingleTableAllowed) {
                        $this_table = $allowed;
                    }
                    $itemArray[] = array('table' => $this_table, 'id' => $this_uid);
                    if (!$disabled && $show_thumbs) {
                        $rr = BackendUtility::getRecordWSOL($this_table, $this_uid);
                        $imgs[] = '<span class="nobr">' . $this->getClickMenu(IconUtility::getSpriteIconForRecord($this_table, $rr, array('style' => 'vertical-align:top', 'title' => htmlspecialchars(BackendUtility::getRecordPath($rr['pid'], $perms_clause, 15) . ' [UID: ' . $rr['uid'] . ']'))), $this_table, $this_uid) . '&nbsp;' . BackendUtility::getRecordTitle($this_table, $rr, TRUE) . ' <span class="typo3-dimmed"><em>[' . $rr['uid'] . ']</em></span>' . '</span>';
                    }
                }
                $thumbsnail = '';
                if (!$disabled && $show_thumbs) {
                    $thumbsnail = implode('<br />', $imgs);
                }
                // Creating the element:
                $params = array('size' => $size, 'dontShowMoveIcons' => $maxitems <= 1, 'autoSizeMax' => MathUtility::forceIntegerInRange($config['autoSizeMax'], 0), 'maxitems' => $maxitems, 'style' => isset($config['selectedListStyle']) ? ' style="' . htmlspecialchars($config['selectedListStyle']) . '"' : ' style="' . $this->defaultMultipleSelectorStyle . '"', 'info' => $info, 'thumbnails' => $thumbsnail, 'readOnly' => $disabled, 'noBrowser' => $noList || isset($config['disable_controls']) && GeneralUtility::inList($config['disable_controls'], 'browser'), 'noList' => $noList);
                $item .= $this->dbFileIcons($PA['itemFormElName'], 'db', implode(',', $tempFT), $itemArray, '', $params, $PA['onFocus'], $table, $field, $row['uid'], $config);
                break;
        }
        // Wizards:
        $altItem = '<input type="hidden" name="' . $PA['itemFormElName'] . '" value="' . htmlspecialchars($PA['itemFormElValue']) . '" />';
        if (!$disabled) {
            $item = $this->renderWizards(array($item, $altItem), $config['wizards'], $table, $row, $field, $PA, $PA['itemFormElName'], $specConf);
        }
        return $item;
    }
Ejemplo n.º 9
0
 /**
  * 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 = '';
     // first two keys are "0" (default) and "-1" (multiple), after that comes the "other languages"
     $allSystemLanguages = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Configuration\\TranslationConfigurationProvider')->getSystemLanguages();
     $systemLanguages = array_filter($allSystemLanguages, function ($languageRecord) {
         if ($languageRecord['uid'] === -1 || $languageRecord['uid'] === 0 || !$GLOBALS['BE_USER']->checkLanguageAccess($languageRecord['uid'])) {
             return FALSE;
         } else {
             return TRUE;
         }
     });
     foreach ($files as $fileObject) {
         list($flag, $code) = $this->fwd_rwd_nav();
         $out .= $code;
         if ($flag) {
             // Initialization
             $this->counter++;
             $this->totalbytes += $fileObject->getSize();
             $ext = $fileObject->getExtension();
             $fileName = trim($fileObject->getName());
             // The icon with link
             $theIcon = IconUtility::getSpriteIconForResource($fileObject, 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] = 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] = BackendUtility::date($fileObject->getProperty('modification_date'));
                         break;
                     case '_CLIPBOARD_':
                         $temp = '';
                         if ($this->bigControlPanel) {
                             $temp .= $this->makeEdit($fileObject);
                         }
                         $temp .= $this->makeClip($fileObject);
                         if (!empty($systemLanguages)) {
                             $temp .= '<a class="filelist-translationToggler" data-fileid="' . $fileObject->getUid() . '">' . IconUtility::getSpriteIcon('mimetypes-x-content-page-language-overlay') . '</a>';
                         }
                         $theData[$field] = $temp;
                         break;
                     case '_REF_':
                         $theData[$field] = $this->makeRef($fileObject);
                         break;
                     case 'file':
                         $theData[$field] = $this->linkWrapFile(htmlspecialchars($fileName), $fileObject);
                         if ($fileObject->isMissing()) {
                             $flashMessage = \TYPO3\CMS\Core\Resource\Utility\BackendUtility::getFlashMessageForMissingFile($fileObject);
                             $theData[$field] .= $flashMessage->render();
                             // Thumbnails?
                         } elseif ($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 . '" title="' . htmlspecialchars($fileName) . '" alt="" />';
                             }
                         }
                         if (!empty($systemLanguages)) {
                             $metaDataRecord = $fileObject->_getMetaData();
                             $translations = $this->getTranslationsForMetaData($metaDataRecord);
                             $languageCode = '';
                             foreach ($systemLanguages as $language) {
                                 $languageId = $language['uid'];
                                 $flagIcon = $language['flagIcon'];
                                 if (array_key_exists($languageId, $translations)) {
                                     $flagButtonIcon = IconUtility::getSpriteIcon('actions-document-open', array('title' => $fileName), array($flagIcon . '-overlay' => array()));
                                     $data = array('sys_file_metadata' => array($translations[$languageId]['uid'] => 'edit'));
                                     $editOnClick = BackendUtility::editOnClick(GeneralUtility::implodeArrayForUrl('edit', $data), $GLOBALS['BACK_PATH'], $this->listUrl());
                                     $languageCode .= sprintf('<a href="#" onclick="%s">%s</a>', htmlspecialchars($editOnClick), $flagButtonIcon);
                                 } else {
                                     $href = $GLOBALS['SOBE']->doc->issueCommand('&cmd[sys_file_metadata][' . $metaDataRecord['uid'] . '][localize]=' . $languageId, $this->backPath . 'alt_doc.php?justLocalized=' . rawurlencode('sys_file_metadata:' . $metaDataRecord['uid'] . ':' . $languageId) . '&returnUrl=' . rawurlencode($this->listURL()) . BackendUtility::getUrlToken('editRecord'));
                                     $flagButtonIcon = IconUtility::getSpriteIcon($flagIcon);
                                     $languageCode .= sprintf('<a href="%s">%s</a> ', htmlspecialchars($href), $flagButtonIcon);
                                 }
                             }
                             // Hide flag button bar when not translated yet
                             $theData[$field] .= '<div class="localisationData" data-fileid="' . $fileObject->getUid() . '"' . (empty($translations) ? ' style="display: none;"' : '') . '>' . $languageCode . '</div>';
                         }
                         break;
                     default:
                         $theData[$field] = '';
                         if ($fileObject->hasProperty($field)) {
                             $theData[$field] = htmlspecialchars(GeneralUtility::fixed_lgd_cs($fileObject->getProperty($field), $this->fixedL));
                         }
                 }
             }
             $out .= $this->addelement(1, $theIcon, $theData);
         }
         $this->eCounter++;
     }
     return $out;
 }
Ejemplo n.º 10
0
 /**
  * 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 = ResourceFactory::getInstance()->retrieveFileOrFolderObject($combinedIdentifier);
     if ($fileObject) {
         $folder = FALSE;
         $isStorageRoot = FALSE;
         $isOnline = TRUE;
         $userMayViewStorage = FALSE;
         $userMayEditStorage = FALSE;
         $identifier = $fileObject->getCombinedIdentifier();
         if ($fileObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
             $icon = IconUtility::getSpriteIconForResource($fileObject, array('class' => 'absmiddle', 'title' => htmlspecialchars($fileObject->getName())));
             $folder = TRUE;
             if ($fileObject->getIdentifier() === $fileObject->getStorage()->getRootLevelFolder()->getIdentifier()) {
                 $isStorageRoot = TRUE;
                 if ($GLOBALS['BE_USER']->check('tables_select', 'sys_file_storage')) {
                     $userMayViewStorage = TRUE;
                 }
                 if ($GLOBALS['BE_USER']->check('tables_modify', 'sys_file_storage')) {
                     $userMayEditStorage = TRUE;
                 }
             }
             if (!$fileObject->getStorage()->isOnline()) {
                 $isOnline = FALSE;
             }
         } else {
             $icon = IconUtility::getSpriteIconForResource($fileObject, array('class' => 'absmiddle', 'title' => htmlspecialchars($fileObject->getName() . ' (' . GeneralUtility::formatSize($fileObject->getSize()) . ')')));
         }
         // Hide
         if (!in_array('hide', $this->disabledItems) && $isStorageRoot && $userMayEditStorage) {
             $record = BackendUtility::getRecord('sys_file_storage', $fileObject->getStorage()->getUid());
             $menuItems['hide'] = $this->DB_changeFlag('sys_file_storage', $record, 'is_online', $this->label($record['is_online'] ? 'offline' : 'online'), 'hide');
         }
         // Edit
         if (!in_array('edit', $this->disabledItems) && $fileObject->checkActionPermission('write')) {
             if (!$folder && !$isStorageRoot && $fileObject->isIndexed()) {
                 $metaData = $fileObject->_getMetaData();
                 $menuItems['edit2'] = $this->DB_edit('sys_file_metadata', $metaData['uid']);
             }
             if (!$folder && GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'], $fileObject->getExtension()) && $fileObject->checkActionPermission('write')) {
                 $menuItems['edit'] = $this->FILE_launch($identifier, 'file_edit.php', 'editcontent', 'edit_file.gif');
             } elseif ($isStorageRoot && $userMayEditStorage) {
                 $menuItems['edit'] = $this->DB_edit('sys_file_storage', $fileObject->getStorage()->getUid());
             }
         }
         // Rename
         if (!in_array('rename', $this->disabledItems) && !$isStorageRoot && $fileObject->checkActionPermission('rename')) {
             $menuItems['rename'] = $this->FILE_launch($identifier, 'file_rename.php', 'rename', 'rename.gif');
         }
         // Upload
         if (!in_array('upload', $this->disabledItems) && $folder && $isOnline && $fileObject->checkActionPermission('write')) {
             $menuItems['upload'] = $this->FILE_upload($identifier);
         }
         // New
         if (!in_array('new', $this->disabledItems) && $folder && $isOnline && $fileObject->checkActionPermission('write')) {
             $menuItems['new'] = $this->FILE_launch($identifier, 'file_newfolder.php', 'new', 'new_file.gif');
         }
         // Info
         if (!in_array('info', $this->disabledItems) && $fileObject->checkActionPermission('read')) {
             if ($isStorageRoot && $userMayViewStorage) {
                 $menuItems['info'] = $this->DB_info('sys_file_storage', $fileObject->getStorage()->getUid());
             } elseif (!$folder) {
                 $menuItems['info'] = $this->fileInfo($identifier);
             }
         }
         $menuItems[] = 'spacer';
         // Copy:
         if (!in_array('copy', $this->disabledItems) && !$isStorageRoot && $fileObject->checkActionPermission('read')) {
             $menuItems['copy'] = $this->FILE_copycut($identifier, 'copy');
         }
         // Cut:
         if (!in_array('cut', $this->disabledItems) && !$isStorageRoot && $fileObject->checkActionPermission('move')) {
             $menuItems['cut'] = $this->FILE_copycut($identifier, 'cut');
         }
         // Paste:
         $elFromAllTables = count($this->clipObj->elFromTable('_FILE'));
         if (!in_array('paste', $this->disabledItems) && $elFromAllTables && $folder && $fileObject->checkActionPermission('write')) {
             $elArr = $this->clipObj->elFromTable('_FILE');
             $selItem = reset($elArr);
             $elInfo = array(basename($selItem), basename($identifier), $this->clipObj->currentMode());
             $menuItems['pasteinto'] = $this->FILE_paste($identifier, $selItem, $elInfo);
         }
         $menuItems[] = 'spacer';
         // Delete:
         if (!in_array('delete', $this->disabledItems) && $fileObject->checkActionPermission('delete')) {
             if ($isStorageRoot && $userMayEditStorage) {
                 $elInfo = array(GeneralUtility::fixed_lgd_cs($fileObject->getStorage()->getName(), $GLOBALS['BE_USER']->uc['titleLen']));
                 $menuItems['delete'] = $this->DB_delete('sys_file_storage', $fileObject->getStorage()->getUid(), $elInfo);
             } elseif (!$isStorageRoot) {
                 $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());
 }