Skip to content

Commit

Permalink
Use preview images as original for most assets; use title for filename
Browse files Browse the repository at this point in the history
  • Loading branch information
robertlemke committed Jun 13, 2018
1 parent 0aeb917 commit 71bbdc8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
17 changes: 14 additions & 3 deletions Classes/AssetSource/PixxioAssetProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* source code.
*/

use Behat\Transliterator\Transliterator;
use Neos\Flow\Http\Uri;
use Neos\Media\Domain\Model\AssetSource\AssetProxy\AssetProxyInterface;
use Neos\Media\Domain\Model\AssetSource\AssetProxy\HasRemoteOriginalInterface;
Expand Down Expand Up @@ -98,14 +99,18 @@ final class PixxioAssetProxy implements AssetProxyInterface, HasRemoteOriginalIn
*/
static public function fromJsonObject(\stdClass $jsonObject, PixxioAssetSource $assetSource)
{
$usePixxioThumbnailAsOriginal = !in_array($jsonObject->fileType, ['JPG', 'PNG', 'SVG', 'PDF']);

$modifiedFileType = $usePixxioThumbnailAsOriginal ? 'jpg' : strtolower($jsonObject->fileType);

$assetProxy = new static();
$assetProxy->assetSource = $assetSource;
$assetProxy->identifier = $jsonObject->id;
$assetProxy->label = $jsonObject->subject;
$assetProxy->filename = $jsonObject->originalFilename;
$assetProxy->filename = Transliterator::urlize($jsonObject->subject) . '.' . $modifiedFileType;
$assetProxy->lastModified = new \DateTime($jsonObject->modifyDate ?? '1.1.2000');
$assetProxy->fileSize = $jsonObject->fileSize;
$assetProxy->mediaType = MediaTypes::getMediaTypeFromFilename('foo.' . $jsonObject->fileType);
$assetProxy->mediaType = MediaTypes::getMediaTypeFromFilename('foo.' . $modifiedFileType);

$assetProxy->iptcProperties['Title'] = $jsonObject->subject ?? '';
$assetProxy->iptcProperties['CaptionAbstract'] = $jsonObject->description ?? '';
Expand All @@ -122,16 +127,22 @@ static public function fromJsonObject(\stdClass $jsonObject, PixxioAssetSource $
if (isset($modifiedImagePaths[1])) {
$assetProxy->previewUri = new Uri($modifiedImagePaths[1]);
}
if (isset($modifiedImagePaths[2])) {
$assetProxy->originalUri = new Uri($modifiedImagePaths[2]);
}
} else if (is_object($modifiedImagePaths)) {
if (isset($modifiedImagePaths->{'0'})) {
$assetProxy->thumbnailUri = new Uri($modifiedImagePaths->{'0'});
}
if (isset($modifiedImagePaths->{'1'})) {
$assetProxy->previewUri = new Uri($modifiedImagePaths->{'1'});
}
if (isset($modifiedImagePaths->{'2'})) {
$assetProxy->originalUri = new Uri($modifiedImagePaths->{'2'});
}
}
}
if (isset($jsonObject->originalPath)) {
if (!$usePixxioThumbnailAsOriginal && isset($jsonObject->originalPath)) {
$assetProxy->originalUri = new Uri($jsonObject->originalPath);
}
return $assetProxy;
Expand Down
2 changes: 1 addition & 1 deletion Classes/AssetSource/PixxioAssetProxyQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ private function sendSearchRequest(int $limit, array $orderings): Response
break;
case 'All':
default:
$formatTypes = [];
$formatTypes = ['converted'];
$fileTypes = [];
break;
}
Expand Down
4 changes: 4 additions & 0 deletions Classes/Service/PixxioClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public function __construct(string $apiEndpointUri, string $apiKey)
'width' => 1500,
'height' => 1500,
'quality' => 90
],
(object)[
'sizeMax' => 1920,
'quality' => 90
]
];
}
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"license": "MIT",
"require": {
"neos/flow": "5.* || dev-master",
"guzzlehttp/guzzle": "6.*"
"guzzlehttp/guzzle": "6.*",
"behat/transliterator": "~1.0"
},
"autoload": {
"psr-4": {
Expand Down

0 comments on commit 71bbdc8

Please sign in to comment.