/** * @param mixed $identity * @return mixed */ public function getResource($identity) { $fileReference = $this->resourceFactory->getFileReferenceObject(intval($identity)); $file = $fileReference->getOriginalFile(); $fileReferenceProperties = $fileReference->getProperties(); $fileProperties = ResourceUtility::getFileArray($file); ArrayUtility::mergeRecursiveWithOverrule($fileProperties, $fileReferenceProperties, TRUE, FALSE, FALSE); return $fileProperties; }
/** * Actually convert from $source to $targetType, taking into account the fully * built $convertedChildProperties and $configuration. * * @param string|int $source * @param string $targetType * @param array $convertedChildProperties * @param PropertyMappingConfigurationInterface $configuration * @return AbstractFileFolder * @internal */ public function convertFrom($source, $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null) { if (!isset($source['error']) || $source['error'] === \UPLOAD_ERR_NO_FILE) { if (isset($source['submittedFile']['resourcePointer'])) { try { $resourcePointer = $this->hashService->validateAndStripHmac($source['submittedFile']['resourcePointer']); if (strpos($resourcePointer, 'file:') === 0) { $fileUid = substr($resourcePointer, 5); return $this->createFileReferenceFromFalFileObject($this->resourceFactory->getFileObject($fileUid)); } else { return $this->createFileReferenceFromFalFileReferenceObject($this->resourceFactory->getFileReferenceObject($resourcePointer), $resourcePointer); } } catch (\InvalidArgumentException $e) { // Nothing to do. No file is uploaded and resource pointer is invalid. Discard! } } return null; } if ($source['error'] !== \UPLOAD_ERR_OK) { return $this->objectManager->get(Error::class, $this->getUploadErrorMessage($source['error']), 1471715915); } if (isset($this->convertedResources[$source['tmp_name']])) { return $this->convertedResources[$source['tmp_name']]; } try { $resource = $this->importUploadedResource($source, $configuration); } catch (\Exception $e) { return $this->objectManager->get(Error::class, $e->getMessage(), $e->getCode()); } $this->convertedResources[$source['tmp_name']] = $resource; return $resource; }
/** * Get alle images on the given pages * * @param array $pages * * @return array */ protected function getImagesByPages(array $pages) { $images = array(); if (!sizeof($pages)) { return $images; } $enabledFields = $this->pageRepository->enableFields('sys_file_reference'); $enabledFields .= $this->pageRepository->enableFields('tt_content'); $enabledFields .= $this->pageRepository->enableFields('pages'); $rows = $this->getDatabaseConnection()->exec_SELECTgetRows('sys_file_reference.*', 'sys_file_reference, tt_content, pages', 'sys_file_reference.tablenames = \'tt_content\' AND sys_file_reference.fieldname =\'image\' AND sys_file_reference.uid_foreign = tt_content.uid AND tt_content.pid = pages.uid AND pages.uid IN (' . implode(',', $pages) . ') ' . $enabledFields); foreach ($rows as $row) { $images[] = $this->resourceFactory->getFileReferenceObject($row['uid'], $row); } return $images; }
/** * Get File or FileReference object by src * * @param string $src * @param bool $treatIdAsReference * @return FileInterface|FileReference|\TYPO3\CMS\Core\Resource\Folder */ protected function getImageFromSourceString($src, $treatIdAsReference) { if ($this->environmentService->isEnvironmentInBackendMode() && substr($src, 0, 3) === '../') { $src = substr($src, 3); } if (MathUtility::canBeInterpretedAsInteger($src)) { if ($treatIdAsReference) { $image = $this->resourceFactory->getFileReferenceObject($src); } else { $image = $this->resourceFactory->getFileObject($src); } } else { // We have a combined identifier or legacy (storage 0) path $image = $this->resourceFactory->retrieveFileOrFolderObject($src); } return $image; }
/** * @param array $record * @return array */ public function getResources($record) { $databaseConnection = $this->getDatabaseConnection(); if (isset($record['t3ver_oid']) && (int) $record['t3ver_oid'] !== 0) { $sqlRecordUid = $record['t3ver_oid']; } else { $sqlRecordUid = $record[$this->idField]; } $fileReferences = []; if (empty($GLOBALS['TSFE']->sys_page) === false) { $fileReferences = $this->getFileReferences($this->getTable(), $this->getField(), $sqlRecordUid); } else { if ($GLOBALS['BE_USER']->workspaceRec['uid']) { $versionWhere = 'AND sys_file_reference.deleted=0 AND (sys_file_reference.t3ver_wsid=0 OR ' . 'sys_file_reference.t3ver_wsid=' . $GLOBALS['BE_USER']->workspaceRec['uid'] . ') AND sys_file_reference.pid<>-1'; } else { $versionWhere = 'AND sys_file_reference.deleted=0 AND sys_file_reference.t3ver_state<=0 AND ' . 'sys_file_reference.pid<>-1 AND sys_file_reference.hidden=0'; } $references = $databaseConnection->exec_SELECTgetRows('uid', 'sys_file_reference', 'tablenames=' . $databaseConnection->fullQuoteStr($this->getTable(), 'sys_file_reference') . ' AND uid_foreign=' . (int) $sqlRecordUid . ' AND fieldname=' . $databaseConnection->fullQuoteStr($this->getField(), 'sys_file_reference') . $versionWhere, '', 'sorting_foreign', '', 'uid'); if (empty($references) === false) { $referenceUids = array_keys($references); $fileReferences = []; if (empty($referenceUids) === false) { foreach ($referenceUids as $referenceUid) { try { // Just passing the reference uid, the factory is doing workspace // overlays automatically depending on the current environment $fileReferences[] = $this->resourceFactory->getFileReferenceObject($referenceUid); } catch (ResourceDoesNotExistException $exception) { // No handling, just omit the invalid reference uid continue; } } } } } $resources = []; foreach ($fileReferences as $file) { // Exclude workspace deleted files references if ($file->getProperty('t3ver_state') !== VersionState::DELETE_PLACEHOLDER) { $resources[] = $this->getResource($file); } } return $resources; }
/** * @param array $record * @return array */ public function getResources($record) { /** @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObj */ $contentObjectRenderer = $this->configurationManager->getContentObject(); /** @var \TYPO3\CMS\Core\Database\DatabaseConnection $databaseConnection */ $databaseConnection = $this->getDatabaseConntection(); if (isset($record['t3ver_oid']) && (int) $record['t3ver_oid'] !== 0) { $sqlRecordUid = $record['t3ver_oid']; } else { $sqlRecordUid = $record[$this->idField]; } if (FALSE === empty($GLOBALS['TSFE']->sys_page)) { $images = $this->getFileReferences($this->getTable(), $this->getField(), $sqlRecordUid); } else { if ($GLOBALS['BE_USER']->workspaceRec['uid']) { $versionWhere = 'AND sys_file_reference.deleted=0 AND (sys_file_reference.t3ver_wsid=0 OR sys_file_reference.t3ver_wsid=' . $GLOBALS['BE_USER']->workspaceRec['uid'] . ') AND sys_file_reference.pid<>-1'; } else { $versionWhere = 'AND sys_file_reference.deleted=0 AND sys_file_reference.t3ver_state<=0 AND sys_file_reference.pid<>-1 AND sys_file_reference.hidden=0'; } $references = $databaseConnection->exec_SELECTgetRows('uid', 'sys_file_reference', 'tablenames=' . $databaseConnection->fullQuoteStr($this->getTable(), 'sys_file_reference') . ' AND uid_foreign=' . (int) $sqlRecordUid . ' AND fieldname=' . $databaseConnection->fullQuoteStr($this->getField(), 'sys_file_reference') . $versionWhere, '', 'sorting_foreign', '', 'uid'); if (FALSE === empty($references)) { $referenceUids = array_keys($references); } $images = array(); if (FALSE === empty($referenceUids)) { foreach ($referenceUids as $referenceUid) { try { // Just passing the reference uid, the factory is doing workspace // overlays automatically depending on the current environment $images[] = $this->resourceFactory->getFileReferenceObject($referenceUid); } catch (ResourceDoesNotExistException $exception) { // No handling, just omit the invalid reference uid continue; } } } } $resources = array(); foreach ($images as $file) { $resources[] = $this->getResource($file); } return $resources; }
/** * Actually convert from $source to $targetType, taking into account the fully * built $convertedChildProperties and $configuration. * * @param string|integer $source * @param string $targetType * @param array $convertedChildProperties * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration * @throws \TYPO3\CMS\Extbase\Property\Exception * @return \TYPO3\CMS\Extbase\Domain\Model\AbstractFileFolder * @api */ public function convertFrom($source, $targetType, array $convertedChildProperties = array(), PropertyMappingConfigurationInterface $configuration = NULL) { if (!isset($source['error']) || $source['error'] === \UPLOAD_ERR_NO_FILE) { if (isset($source['submittedFile']['resourcePointer'])) { try { $resourcePointer = $this->hashService->validateAndStripHmac($source['submittedFile']['resourcePointer']); if (strpos($resourcePointer, 'file:') === 0) { $fileUid = substr($resourcePointer, 5); return $this->createFileReferenceFromFalFileObject($this->resourceFactory->getFileObject($fileUid)); } else { return $this->createFileReferenceFromFalFileReferenceObject($this->resourceFactory->getFileReferenceObject($resourcePointer), $resourcePointer); } } catch (\InvalidArgumentException $e) { // Nothing to do. No file is uploaded and resource pointer is invalid. Discard! } } return NULL; } if ($source['error'] !== \UPLOAD_ERR_OK) { switch ($source['error']) { case \UPLOAD_ERR_INI_SIZE: case \UPLOAD_ERR_FORM_SIZE: case \UPLOAD_ERR_PARTIAL: return new Error(Files::getUploadErrorMessage($source['error']), 1264440823); default: return new Error('An error occurred while uploading. Please try again or contact the administrator if the problem remains', 1340193849); } } if (isset($this->convertedResources[$source['tmp_name']])) { return $this->convertedResources[$source['tmp_name']]; } try { $resource = $this->importUploadedResource($source, $configuration); } catch (\Exception $e) { return new Error($e->getMessage(), $e->getCode()); } $this->convertedResources[$source['tmp_name']] = $resource; return $resource; }
/** * @param integer $id * @return array */ public function getInfoByReference($id) { $fileReference = $this->resourceFactory->getFileReferenceObject($id); $file = $fileReference->getOriginalFile(); return ResourceUtility::getFileArray($file); }