/** * Remove the file if it is located within its album path. * That means, it does not remove files located in an other directory (like files imported by the directory importer) * * @param Tx_Yag_Domain_Model_Item $item */ public function removeImageFileFromAlbumDirectory(Tx_Yag_Domain_Model_Item $item) { $albumPath = $this->getOrigFileDirectoryPathForAlbum($item->getAlbum()); $imageFilePath = Tx_Yag_Domain_FileSystem_Div::makePathAbsolute($item->getSourceuri()); if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($imageFilePath, $albumPath) && file_exists($imageFilePath)) { unlink($imageFilePath); } }
/** * @return Tx_Yag_Domain_Model_Item */ protected function getTestItemObject() { $item = new Tx_Yag_Domain_Model_Item(); $album = new Tx_Yag_Domain_Model_Album(); $gallery = new Tx_Yag_Domain_Model_Gallery(); $album->setGallery($gallery); $item->setAlbum($album); $item->setSourceuri(substr(ExtensionManagementUtility::extPath($this->extensionName) . 'Tests/Unit/TestImages/', strlen(PATH_site)) . 'testImage.jpg'); return $item; }
/** * Renders link for an image * * @param int $itemUid UID of item to render link for * @param Tx_Yag_Domain_Model_Item $item Item to render a link to * @param int pageUid (Optional) ID of page to render link for. If null, current page is used * @param integer $pageType type of the target page. See typolink.parameter * @return string Rendered link for album * @throws Exception */ public function render($itemUid = null, Tx_Yag_Domain_Model_Item $item = null, $pageUid = null, $pageType = 0) { if ($itemUid === null && $item === null) { throw new Exception('You have to set "imageUid" or "item" as parameter. Both parameters can not be empty when using imageLinkViewHelper', 1358059753); } if ($itemUid === null) { $itemUid = $item->getUid(); } return parent::render('showSingle', array('item' => $itemUid), 'Item', null, null, $pageUid, $pageType); }
/** * @return void */ public function deleteThumb() { if ($this->thumb && is_object($this->thumb)) { $this->thumb->delete(); $this->thumb = null; } }
/** * @param Tx_Yag_Domain_Model_Item $item * @return string */ public function render(Tx_Yag_Domain_Model_Item $item) { $customMetaDataArray = $item->getItemMeta()->getCustomMetaDataArray(); $content = ''; if (is_array($customMetaDataArray) && count($customMetaDataArray) || $this->arguments['showEmptyFields']) { foreach ($this->definedCustomMetaDataConfigCollection as $customMetaDataKey => $customMetaDataConfig) { $customMetaData['config'] = $customMetaDataConfig; if (array_key_exists($customMetaDataKey, $customMetaDataArray)) { $customMetaData['data'] = $customMetaDataArray[$customMetaDataKey]; } $this->templateVariableContainer->add('customMetaData', $customMetaData); $content .= $this->renderChildren(); $this->templateVariableContainer->remove('customMetaData'); } } return $content; }
/** * @param Tx_Yag_Domain_Model_Item $item * @param null $resolutionName * @param null $width * @param null $height * @param null $quality * @param boolean $absolute * @return string */ public function render(Tx_Yag_Domain_Model_Item $item, $resolutionName = null, $width = null, $height = null, $quality = null, $absolute = false) { if ($resolutionName) { $resolutionConfig = Tx_Yag_Domain_Configuration_ConfigurationBuilderFactory::getInstance()->buildThemeConfiguration()->getResolutionConfigCollection()->getResolutionConfig($resolutionName); } elseif ($width || $height) { $resolutionSettings = array('width' => $width, 'height' => $height, 'quality' => $quality); $resolutionConfig = new Tx_Yag_Domain_Configuration_Image_ResolutionConfig(Tx_Yag_Domain_Configuration_ConfigurationBuilderFactory::getInstance(), $resolutionSettings); } else { $resolutionConfig = null; } $imageResolution = $item->getResolutionByConfig($resolutionConfig); if ($absolute == true) { $imageSource = $this->controllerContext->getRequest()->getBaseUri() . $imageResolution->getPath(); } else { $imageSource = TYPO3_MODE === 'BE' ? '../' . $imageResolution->getPath() : $GLOBALS['TSFE']->absRefPrefix . $imageResolution->getPath(); } return $imageSource; }
protected function createItems(Tx_Yag_Domain_Model_Album $album) { $itemRepository = $this->objectManager->get('Tx_Yag_Domain_Repository_ItemRepository'); /* @var $itemRepository Tx_Yag_Domain_Repository_ItemRepository */ $first = true; for ($i = 1; $i <= $this->itemsPerGalleryCount; $i++) { $item = new Tx_Yag_Domain_Model_Item(); $item->setTitle('TestItem ' . $i); $item->setAlbum($album); $item->setSourceuri(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('yag') . 'Tests/Unit/TestImages/testImage.jpg'); if ($first) { $album->setThumb($item); $first = FALSE; } $itemRepository->add($item); } }
/** * @param Tx_Yag_Domain_Model_Item $item * @return string */ protected function getFilePathOfResolution(Tx_Yag_Domain_Model_Item $item) { if ($this->resolutionIdentifier === 'original') { return Tx_Yag_Domain_FileSystem_Div::makePathAbsolute($item->getSourceuri()); } else { return Tx_Yag_Domain_FileSystem_Div::makePathAbsolute($item->getResolutionByConfig($this->getRequestedResolutionConfig())->getPath()); } }
/** * @test */ public function processStringFromMetaDataWithOverwrite() { $this->markTestSkipped('Single Run of test passes whereas two tests in row semm to have a side effect on the cObj creation / usage'); $titleFormat = array('_typoScriptNodeValue' => 'TEXT', 'dataWrap' => '{field:fileName} by {field:artist}'); $itemMeta = new Tx_Yag_Domain_Model_ItemMeta(); $itemMeta->setCaptureDate(new DateTime('2012-10-08')); $itemMeta->setArtist('Daniel Lienert'); $item = new Tx_Yag_Domain_Model_Item(); $item->setOriginalFilename('test.jpg'); $item->setFilename('test.jpg'); $item->setItemMeta($itemMeta); $overWriteVars = array('artist' => 'Daniel'); $formattedString = $this->fixture->_call('processStringFromMetaData', $item, $titleFormat, $overWriteVars); $this->assertEquals('Test by Daniel', $formattedString); }
/** * Get the item which is in the database after the given item * * @param Tx_Yag_Domain_Model_Item $item * @param int $limit of items to return * @return Tx_Yag_Domain_Model_Item $item */ public function getItemsAfterThisItem(Tx_Yag_Domain_Model_Item $item = null, $limit = 1) { $itemUid = $item ? $item->getUid() : 0; $query = $this->createQuery(); $result = $query->matching($query->greaterThan('uid', $itemUid))->setLimit($limit)->execute(); $object = null; if ($result->count() == 0) { return false; } elseif ($result->count() == 1 && $result->current() !== false) { $object = $result->current(); $session = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Session'); $session->registerObject($object, $object->getUid()); return $object; } else { return $result; } }
/** * Moves a file from given filepath to directory for original images for album * * If an item is given, UID of item is used as filename for item in original items directory * * @param string $filePath Full qualified filepath of file to move * @param Tx_Yag_Domain_Model_Item $item Item that should hold file (not modified, make sure to set sourceuri manually! * @return string * @throws Exception */ protected function moveFileToOrigsDirectory($filePath, Tx_Yag_Domain_Model_Item $item = null) { // Create path to move file to $origsFilePath = $this->fileManager->getOrigFileDirectoryPathForAlbum($this->album); $fileSuffix = pathinfo($filePath, PATHINFO_EXTENSION); if ($item !== null) { if ($item->getOriginalFilename()) { $origsFilePath .= $item->getUid() . '_' . $this->fileSystemDiv->cleanFileName($item->getOriginalFilename()); } else { $origsFilePath .= $item->getUid() . '.' . $fileSuffix; // if we get an item, we use UID of item as a part of the filename } } else { $origsFilePath .= Tx_Yag_Domain_FileSystem_Div::getFilenameFromFilePath($filePath); // if we do not get one, we use filename of given filepart } if (!rename($filePath, $origsFilePath)) { throw new Exception('Could not move file ' . $filePath . ' to ' . $origsFilePath, 1294176900); } // Set appropriate file mask $this->setFileMask($origsFilePath); return $origsFilePath; }
/** * Wrapper for cObj->getImageResource in FE and BE * * @param Tx_Yag_Domain_Model_Item $origFile The original image * @param string $sourcePathAndFileName Must be used to access the file, as it may be overwritten if the original file was not found * @param Tx_Yag_Domain_Configuration_Image_ResolutionConfig $resolutionConfiguration * @return TYPO3\CMS\Core\Resource\ProcessedFile */ protected function getImageResource(Tx_Yag_Domain_Model_Item $origFile, $sourcePathAndFileName, Tx_Yag_Domain_Configuration_Image_ResolutionConfig $resolutionConfiguration) { $typoScriptSettings = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Service\\TypoScriptService')->convertPlainArrayToTypoScriptArray($resolutionConfiguration->getSettings()); $contentObject = $this->configurationManager->getContentObject(); /** @var $contentObject \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer */ if ($resolutionConfiguration->getMode() == 'GIFBUILDER') { $gifBuilderData = ['yagImage' => $sourcePathAndFileName, 'yagImageTitle' => $origFile->getTitle(), 'yagImageHref' => $origFile->getHref(), 'yagImageUid' => $origFile->getUid(), 'yagAlbumUid' => $origFile->getAlbum()->getUid(), 'yagAlbumTitle' => $origFile->getAlbum()->getName(), 'yagGalleryUid' => $origFile->getAlbum()->getGallery()->getUid(), 'yagGalleryTitle' => $origFile->getAlbum()->getGallery()->getName()]; $contentObject->start($gifBuilderData); $imageResource = $contentObject->getImgResource('GIFBUILDER', $typoScriptSettings); } else { $fileObject = $this->getResourceFactory()->retrieveFileOrFolderObject($sourcePathAndFileName); $imageResource = $contentObject->getImgResource($fileObject, $typoScriptSettings); } // $this->typo3CleanUp($imageResource); return $imageResource['processedFile']; }
/** * Updates description for a given item * * @param Tx_Yag_Domain_Model_Item $item Item to be updated * @param string $itemDescription Description of item * @rbacNeedsAccess * @rbacObject Item * @rbacAction update */ public function updateItemDescriptionAction($item, $itemDescription) { $item->setDescription(utf8_encode($itemDescription)); $this->itemRepository->update($item); $this->persistenceManager->persistAll(); $this->returnDataAndShutDown(); }
protected function buildItemObjectInfo(PathInfo $pathInfo, \Tx_Yag_Domain_Model_Item $item) { return array('size' => $item->getFilesize(), 'atime' => $item->getTstamp()->getTimestamp(), 'mtime' => $item->getTstamp()->getTimestamp(), 'ctime' => $item->getCrdate()->getTimestamp(), 'mimetype' => 'image/jpeg', 'yagItem' => $item, 'name' => $item->getOriginalFilename(), 'identifier' => \Tx_Yag_Domain_FileSystem_Div::concatenatePaths(array($pathInfo->getAlbumPath(), $item->getTitle() . ' |' . $item->getUid())), 'storage' => $this->storage->getUid(), 'description' => $item->getDescription(), 'title' => $item->getTitle(), 'height' => $item->getHeight(), 'width' => $item->getWidth(), 'sourceUri' => $item->getSourceuri()); }
/** * Sends an item as download. The fileHash (or at least a part of 5 characters) is used to avoid grabbing the whole * database by incrementing the itemUid. * * @param Tx_Yag_Domain_Model_Item $item * @param string $fileHash */ public function downloadAction(Tx_Yag_Domain_Model_Item $item, $fileHash) { $requestedFileName = Tx_Yag_Domain_FileSystem_Div::makePathAbsolute($item->getSourceuri()); $hashLength = strlen($fileHash) > 5 ? 5 : strlen($fileHash); if ($fileHash == '' || $fileHash !== substr($item->getFilehash(), 0, $hashLength) || !is_readable($requestedFileName)) { $this->flashMessageContainer->add('The requested file was not found.', 'File not found', FlashMessage::ERROR); $this->forward('index', 'Error'); } $this->response->setHeader('Cache-control', 'public', true); $this->response->setHeader('Content-Description', 'File transfer', true); $this->response->setHeader('Content-Disposition', 'attachment; filename="' . $item->getOriginalFilename() . '"', true); $this->response->setHeader('Content-Type', $item->getItemType(), true); $this->response->setHeader('Content-Transfer-Encoding', 'binary', true); $this->response->sendHeaders(); @readfile($requestedFileName); exit; }
/** * Removes all cached files for a given item * * @param Tx_Yag_Domain_Model_Item $item Item to remove cached files for */ public function removeByItem(Tx_Yag_Domain_Model_Item $item) { $query = $this->createQuery(); $query->matching($query->equals('item', $item->getUid())); $cachedFilesForItem = $query->execute(); foreach ($cachedFilesForItem as $cachedFileForItem) { /* @var $cachedFileForItem Tx_Yag_Domain_Model_ResolutionFileCache */ $this->remove($cachedFileForItem); } }
/** * Get the item which is in the database after the given item * * @param Tx_Yag_Domain_Model_Item $item * @param int $limit of items to return * @return Tx_Yag_Domain_Model_Item $item */ public function getItemsAfterThisItem(Tx_Yag_Domain_Model_Item $item = NULL, $limit = 1) { $itemUid = $item ? $item->getUid() : 0; $query = $this->createQuery(); $result = $query->matching($query->greaterThan('uid', $itemUid))->setLimit($limit)->execute(); $object = NULL; if ($result->count() == 0) { return FALSE; } elseif ($result->count() == 1 && $result->current() !== FALSE) { $object = $result->current(); $this->identityMap->registerObject($object, $object->getUid()); return $object; } else { return $result; } }
/** * Retrieve a resolution file from local cache * * @param Tx_Yag_Domain_Configuration_Image_ResolutionConfig $resolutionConfiguration * @param Tx_Yag_Domain_Model_Item $item * @return Tx_Yag_Domain_Model_ResolutionFileCache|null */ protected function getResolutionFileFromLocalCache(Tx_Yag_Domain_Configuration_Image_ResolutionConfig $resolutionConfiguration, Tx_Yag_Domain_Model_Item $item) { $objectIdentifier = md5($resolutionConfiguration->getParameterHash() . $item->getSourceuri()); if (array_key_exists($objectIdentifier, $this->localResolutionFileCache)) { return $this->localResolutionFileCache[$objectIdentifier]; } return NULL; }
/** * @return Tx_Yag_Domain_Model_Item */ public function getItem() { if (!$this->selectedItemUid) { return NULL; } if ($this->selectedItem instanceof Tx_Yag_Domain_Model_Item && $this->selectedItem->getUid() == $this->selectedItemUid) { return $this->selectedItem; } else { return $this->objectManager->get('Tx_Yag_Domain_Repository_ItemRepository')->findByUid($this->selectedItemUid); } }
/** * Wrapper for cObj->getImageResource in FE and BE * * @param Tx_Yag_Domain_Model_Item $origFile The original image * @param string $sourcePathAndFileName Must be used to access the file, as it may be overwritten if the original file was not found * @param Tx_Yag_Domain_Configuration_Image_ResolutionConfig $resolutionConfiguration * @return array $imageData */ protected function getImageResource(Tx_Yag_Domain_Model_Item $origFile, $sourcePathAndFileName, Tx_Yag_Domain_Configuration_Image_ResolutionConfig $resolutionConfiguration) { $typoScriptSettings = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Service\\TypoScriptService')->convertPlainArrayToTypoScriptArray($resolutionConfiguration->getSettings()); $contentObject = $this->configurationManager->getContentObject(); /** @var $contentObject tslib_cObj */ if ($resolutionConfiguration->getMode() == 'GIFBUILDER') { $gifBuilderData = array('yagImage' => $sourcePathAndFileName, 'yagImageTitle' => $origFile->getTitle(), 'yagImageUid' => $origFile->getUid(), 'yagAlbumUid' => $origFile->getAlbum()->getUid(), 'yagAlbumTitle' => $origFile->getAlbum()->getName(), 'yagGalleryUid' => $origFile->getAlbum()->getGallery()->getUid(), 'yagGalleryTitle' => $origFile->getAlbum()->getGallery()->getName()); $contentObject->start($gifBuilderData); $imageResource = $contentObject->getImgResource('GIFBUILDER', $typoScriptSettings); } else { $imageResource = $contentObject->getImgResource($sourcePathAndFileName, $typoScriptSettings); } $this->typo3CleanUp($imageResource, $sourcePathAndFileName); return $imageResource; }