/**
  * Tells the ImageService to render the resource of this ImageVariant according to the existing adjustments.
  *
  * @return void
  */
 protected function renderResource()
 {
     $processedImageInfo = $this->imageService->processImage($this->originalAsset->getResource(), $this->adjustments->toArray());
     $this->resource = $processedImageInfo['resource'];
     $this->width = $processedImageInfo['width'];
     $this->height = $processedImageInfo['height'];
     $this->persistenceManager->whiteListObject($this->resource);
 }
 /**
  * @param Image $image
  * @return array
  */
 protected function getImagePreviewData(Image $image)
 {
     $imageProperties = ['originalImageResourceUri' => $this->resourceManager->getPublicPersistentResourceUri($image->getResource()), 'originalDimensions' => ['width' => $image->getWidth(), 'height' => $image->getHeight(), 'aspectRatio' => $image->getAspectRatio()], 'mediaType' => $image->getResource()->getMediaType()];
     $thumbnail = $this->thumbnailService->getThumbnail($image, $this->thumbnailService->getThumbnailConfigurationForPreset('TYPO3.Neos:Preview'));
     if ($thumbnail !== null) {
         $imageProperties['previewImageResourceUri'] = $this->thumbnailService->getUriForThumbnail($thumbnail);
         $imageProperties['previewDimensions'] = ['width' => $thumbnail->getWidth(), 'height' => $thumbnail->getHeight()];
     }
     return $imageProperties;
 }
    /**
     * Import resources to asset management
     *
     * This command detects Flow "Resource" objects which are not yet available as "Asset" objects and thus don't appear
     * in the asset management. The type of the imported asset is determined by the file extension provided by the
     * Resource object.
     *
     * @param boolean $simulate If set, this command will only tell what it would do instead of doing it right away
     * @return void
     */
    public function importResourcesCommand($simulate = false)
    {
        $this->initializeConnection();
        $sql = '
			SELECT
				r.persistence_object_identifier, r.filename, r.mediatype
			FROM typo3_flow_resource_resource r
			LEFT JOIN typo3_media_domain_model_asset a
			ON a.resource = r.persistence_object_identifier
			LEFT JOIN typo3_media_domain_model_thumbnail t
			ON t.resource = r.persistence_object_identifier
			WHERE a.persistence_object_identifier IS NULL AND t.persistence_object_identifier IS NULL
		';
        $statement = $this->dbalConnection->prepare($sql);
        $statement->execute();
        $resourceInfos = $statement->fetchAll();
        if ($resourceInfos === array()) {
            $this->outputLine('Found no resources which need to be imported.');
            $this->quit();
        }
        foreach ($resourceInfos as $resourceInfo) {
            $mediaType = $resourceInfo['mediatype'];
            if (substr($mediaType, 0, 6) === 'image/') {
                $resource = $this->persistenceManager->getObjectByIdentifier($resourceInfo['persistence_object_identifier'], 'TYPO3\\Flow\\Resource\\Resource');
                if ($resource === null) {
                    $this->outputLine('Warning: Resource for file "%s" seems to be corrupt. No resource object with identifier %s could be retrieved from the Persistence Manager.', array($resourceInfo['filename'], $resourceInfo['persistence_object_identifier']));
                    continue;
                }
                if (!$resource->getStream()) {
                    $this->outputLine('Warning: Resource for file "%s" seems to be corrupt. The actual data of resource %s could not be found in the resource storage.', array($resourceInfo['filename'], $resourceInfo['persistence_object_identifier']));
                    continue;
                }
                $image = new Image($resource);
                if ($simulate) {
                    $this->outputLine('Simulate: Adding new image "%s" (%sx%s px)', array($image->getResource()->getFilename(), $image->getWidth(), $image->getHeight()));
                } else {
                    $this->assetRepository->add($image);
                    $this->outputLine('Adding new image "%s" (%sx%s px)', array($image->getResource()->getFilename(), $image->getWidth(), $image->getHeight()));
                }
            }
        }
    }
 /**
  * @param NodeInterface $node
  * @param Image $newImage
  * @param string $title
  * @param string|array $tagLabel
  * @param string $propertyName
  * @param boolean $removePreviousProfileImage
  * @return NodeInterface
  */
 public function setImageToNode(NodeInterface $node, Image $newImage, $title, $tagLabel = NULL, $propertyName = 'image', $removePreviousProfileImage = FALSE)
 {
     $newImage->setTitle($title);
     if ($tagLabel !== NULL) {
         if (is_array($tagLabel) && !is_string($tagLabel)) {
             if ($removePreviousProfileImage === TRUE) {
                 $this->removePreviousProfilePictureBasedOnTags($title, $tagLabel);
             }
             foreach ($tagLabel as $key => $label) {
                 $tag = $this->tagRepository->findOneByLabel($label);
                 if (!$tag instanceof Tag) {
                     $tag = new Tag($label);
                     $this->tagRepository->add($tag);
                 }
                 $newImage->addTag($tag);
             }
         } elseif (is_string($tagLabel) && !is_array($tagLabel)) {
             $tag = $this->tagRepository->findOneByLabel($tagLabel);
             if (!$tag instanceof Tag) {
                 $tag = new Tag($tagLabel);
                 $this->tagRepository->add($tag);
             }
             $newImage->addTag($tag);
         }
     }
     /** @var Image $image */
     $image = $this->imageRepository->findByIdentifier($newImage->getIdentifier());
     if ($image !== NULL) {
         try {
             $this->imageRepository->update($image);
             $node->setProperty($propertyName, $image);
         } catch (\Exception $exception) {
             // Image repository might give back an image while not stored for some reason. If so, catch that error and store it anyway
             $image->setTitle($title);
             $this->imageRepository->add($image);
             $node->setProperty($propertyName, $image);
             $this->systemLogger->log('Image with identifier ' . $image->getIdentifier() . ' stored while preceding an error that is not stored yet fetched using ImageRepository', LOG_CRIT);
         }
     } else {
         $this->imageRepository->add($newImage);
         $node->setProperty($propertyName, $newImage);
     }
     return $node;
 }
 /**
  * @param Image $image
  * @return array
  */
 protected function getImagePreviewData(Image $image)
 {
     $thumbnail = $image->getThumbnail(600, 600);
     $imageProperties = array('originalImageResourceUri' => $this->resourceManager->getPublicPersistentResourceUri($image->getResource()), 'previewImageResourceUri' => $this->resourceManager->getPublicPersistentResourceUri($thumbnail->getResource()), 'originalDimensions' => array('width' => $image->getWidth(), 'height' => $image->getHeight(), 'aspectRatio' => $image->getAspectRatio()), 'previewDimensions' => array('width' => $thumbnail->getWidth(), 'height' => $thumbnail->getHeight()), 'mediaType' => $image->getResource()->getMediaType());
     return $imageProperties;
 }
예제 #6
0
 /**
  * Fetch the metadata for a given image
  *
  * @param \TYPO3\Media\Domain\Model\Image $image
  * @return string
  */
 public function imageWithMetadataAction(\TYPO3\Media\Domain\Model\Image $image)
 {
     $thumbnail = $image->getThumbnail(500, 500);
     return json_encode(array('imageUuid' => $this->persistenceManager->getIdentifierByObject($image), 'previewImageResourceUri' => $this->resourcePublisher->getPersistentResourceWebUri($thumbnail->getResource()), 'originalSize' => array('w' => $image->getWidth(), 'h' => $image->getHeight()), 'previewSize' => array('w' => $thumbnail->getWidth(), 'h' => $thumbnail->getHeight())));
 }
 /**
  * Replaces images (<img src="Foo.png">) by persistent resources (<img src="_Resources/....">)
  *
  * @param string $bodyText
  * @return string the text with replaced image tags
  */
 protected function replaceImages($bodyText)
 {
     $self = $this;
     $configuration = $this->bundleConfiguration;
     $resourceManager = $this->resourceManager;
     $resourcePublisher = $this->resourcePublisher;
     $bodyText = preg_replace_callback('/(<img .*?src=")([^"]*)(".*?\\/>)/', function ($matches) use($self, $configuration, $resourceManager, $resourcePublisher) {
         $imageRootPath = isset($configuration['imageRootPath']) ? $configuration['imageRootPath'] : Files::concatenatePaths(array($configuration['renderedDocumentationRootPath'], '_images'));
         $imagePathAndFilename = Files::concatenatePaths(array($imageRootPath, basename($matches[2])));
         $imageResource = $resourceManager->importResource($imagePathAndFilename);
         $image = new Image($imageResource);
         if ($image->getWidth() > $configuration['imageMaxWidth'] || $image->getHeight() > $configuration['imageMaxHeight']) {
             $image = $image->getThumbnail($configuration['imageMaxWidth'], $configuration['imageMaxHeight']);
         }
         $imageUri = $resourcePublisher->publishPersistentResource($image->getResource());
         if ($image->getWidth() > $configuration['thumbnailMaxWidth'] || $image->getHeight() > $configuration['thumbnailMaxHeight']) {
             $thumbnail = $image->getThumbnail(710, 800);
             $thumbnailUri = $resourcePublisher->getPersistentResourceWebUri($thumbnail->getResource());
             return sprintf('<a href="/%s" class="lightbox">%s/%s" style="width: %dpx" /></a>', $imageUri, $matches[1], $thumbnailUri, $thumbnail->getWidth());
         } else {
             return sprintf('%s/%s" style="width: %dpx" />', $matches[1], $imageUri, $image->getWidth());
         }
     }, $bodyText);
     return $bodyText;
 }
예제 #8
0
 /**
  * Creates a user based on the given information
  *
  * The created user and account are automatically added to their respective repositories and thus be persisted.
  *
  * @param string $username The username of the user to be created.
  * @param string $password Password of the user to be created
  * @param string $firstName First name of the user to be created
  * @param string $lastName Last name of the user to be created
  * @param string $department department of the user to be created
  * @param string $photo photo of the user to be created
  * @param array $roleIdentifiers A list of role identifiers to assign
  * @param string $authenticationProviderName Name of the authentication provider to use. Example: "Typo3BackendProvider"
  * @return User The created user instance
  * @api
  */
 public function createUserPhlu($username, $password, $firstName, $lastName, $department, $photo, array $roleIdentifiers = null, $authenticationProviderName = null)
 {
     $collection = $this->assetCollectionRepository->findByCollectionName('phluCollection2')->getFirst();
     if (!$collection) {
         $collection = new \TYPO3\Media\Domain\Model\AssetCollection('phluCollection2');
         $this->assetCollectionRepository->add($collection);
         $this->persistenceManager->persistAll();
     }
     $user = new User();
     $user->setDepartment($department);
     $name = new PersonName('', $firstName, '', $lastName, '', $username);
     $user->setName($name);
     $resource = $this->resourceManager->importResource($photo);
     $image = new Image($resource);
     $image->setTitle($name->getFullName());
     $tag = $this->tagRepository->findBySearchTerm('Hauswart')->getFirst();
     if (!$tag) {
         $tag = new Tag();
         $tag->setLabel('Hauswart');
         $this->tagRepository->add($tag);
         $collection->addTag($tag);
     }
     $image->addTag($tag);
     $user->setPhoto($image);
     $this->assetRepository->add($image);
     $collection->addAsset($image);
     $this->assetCollectionRepository->update($collection);
     return $this->addUserPhlu($username, $password, $user, $roleIdentifiers, $authenticationProviderName);
 }
예제 #9
0
 /**
  * Updates the given news object
  *
  * @param \Lelesys\Plugin\News\Domain\Model\News $news The news to update
  * @param array $media  News media
  * @param array $file News file
  * @param array $tags News tags
  * @param array $relatedLink News related links
  * @return void
  */
 public function update(\Lelesys\Plugin\News\Domain\Model\News $news, $media, $file, $relatedLink, $tags)
 {
     if (!empty($tags['title'])) {
         $tagsArray = array_unique(\TYPO3\Flow\Utility\Arrays::trimExplode(',', strtolower($tags['title'])));
         foreach ($tagsArray as $tag) {
             $existTag = $this->tagService->findTagByName($tag);
             if (!empty($existTag)) {
                 $newsTags = $news->getTags()->toArray();
                 if (!in_array($existTag, $newsTags)) {
                     $news->addTags($existTag);
                 }
             } else {
                 $newTag = new \Lelesys\Plugin\News\Domain\Model\Tag();
                 $newTag->setTitle($tag);
                 $this->tagService->create($newTag);
                 $news->addTags($newTag);
             }
         }
     }
     $news->setUpdatedDate(new \DateTime());
     $mediaPath = $media;
     foreach ($mediaPath as $mediaSource) {
         if (!empty($mediaSource['uuid'])) {
             $updateAsset = $this->propertyMapper->convert($mediaSource['uuid']['__identity'], '\\TYPO3\\Media\\Domain\\Model\\Image');
             $updateAsset->setCaption($mediaSource['caption']);
             $this->imageRepository->update($updateAsset);
         } else {
             if (!empty($mediaSource['resource']['name'])) {
                 $resource = $this->propertyMapper->convert($mediaSource['resource'], 'TYPO3\\Flow\\Resource\\Resource');
                 $media = new \TYPO3\Media\Domain\Model\Image($resource);
                 $media->setCaption($mediaSource['caption']);
                 $this->imageRepository->add($media);
                 $news->addAssets($media);
             }
         }
     }
     $filePath = $file;
     foreach ($filePath as $fileSource) {
         if (isset($fileSource['uuid'])) {
             $updateFile = $this->propertyMapper->convert($fileSource['uuid']['__identity'], '\\TYPO3\\Media\\Domain\\Model\\Document');
             $updateFile->setTitle($fileSource['title']);
             $this->assetRepository->update($updateFile);
         } else {
             if (!empty($fileSource['resource']['name'])) {
                 $resource = $this->propertyMapper->convert($fileSource['resource'], 'TYPO3\\Flow\\Resource\\Resource');
                 $file = new \TYPO3\Media\Domain\Model\Document($resource);
                 $file->setTitle($fileSource['title']);
                 $this->assetRepository->add($file);
                 $news->addFiles($file);
             }
         }
     }
     $related = $relatedLink;
     foreach ($related as $link) {
         if (isset($link['uuid'])) {
             $updateLink = $this->linkService->findById($link['uuid']);
             $updateLink->setUri($link['relatedUri']);
             $updateLink->setTitle($link['relatedUriTitle']);
             $updateLink->setDescription($link['relatedUriDescription']);
             $updateLink->setHidden($link['hidden']);
             $this->linkService->update($updateLink);
         } else {
             if (!empty($link['relatedUri'])) {
                 $newLink = new \Lelesys\Plugin\News\Domain\Model\Link();
                 $newLink->setTitle($link['relatedUriTitle']);
                 $newLink->setUri($link['relatedUri']);
                 $newLink->setDescription($link['relatedUriDescription']);
                 $newLink->setHidden($link['hidden']);
                 $this->linkService->create($newLink);
                 $news->addRelatedLinks($newLink);
             }
         }
     }
     $this->newsRepository->update($news);
     $this->emitNewsUpdated($news);
 }
예제 #10
0
 /**
  * @param Image $image
  * @return array
  */
 protected function buildImageMetaDataArray(Image $image)
 {
     return ['title' => $image->getTitle(), 'caption' => $image->getCaption()];
 }