Skip to content

Commit

Permalink
Cloudinary v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Plopix committed May 14, 2021
1 parent 28026c3 commit a9a1a0c
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions components/CloudinaryBundle/Core/AliasGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace Novactive\Bundle\eZCloudinaryBundle\Core;

use Cloudinary;
use Cloudinary\Tag\ImageTag;
use eZ\Publish\API\Repository\Values\Content\Field;
use eZ\Publish\API\Repository\Values\Content\VersionInfo;
use eZ\Publish\Core\MVC\ConfigResolverInterface;
Expand Down Expand Up @@ -49,13 +49,18 @@ public function __construct(
$this->configResolver = $configResolver;
$this->variationService = $variationService;
$this->logger = $logger;
Cloudinary::config(
[
'cloud_name' => $auth['cloud_name'],
'api_key' => $auth['api_key'],
'api_secret' => $auth['api_secret'],
]
);

$config = [
'cloud_name' => $auth['cloud_name'],
'api_key' => $auth['api_key'],
'api_secret' => $auth['api_secret'],
];

if (class_exists(\Cloudinary\Configuration\Configuration::class)) {
\Cloudinary\Configuration\Configuration::instance($config);
} else {
\Cloudinary::config($config);
}
}

/**
Expand Down Expand Up @@ -135,10 +140,19 @@ public function getVariation(Field $field, VersionInfo $versionInfo, $variationN
if (!empty($fetchPort)) {
$components['port'] = $fetchPort;
}
$html = fetch_image_tag(
$this->unparseUrl($components),
$cloudinaryVariationsList[$variationName]['filters']
);

if (class_exists(\Cloudinary\Configuration\Configuration::class)) {
$html = ImageTag::fetch(
$this->unparseUrl($components),
$cloudinaryVariationsList[$variationName]['filters']
)->toTag();
} else {
$html = fetch_image_tag(
$this->unparseUrl($components),
$cloudinaryVariationsList[$variationName]['filters']
);
}

$attributes = [];
foreach ($this->parseAttributes($html) as $key => $value) {
if ('img' === $key) {
Expand Down

0 comments on commit a9a1a0c

Please sign in to comment.