Skip to content

Commit 5cf6cfe

Browse files
authored
Merge pull request #2 from Vendic/feature/imgproxy-custom-url-source
Use custom imageproxy url
2 parents bc8fe7d + a441410 commit 5cf6cfe

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

Helper/Data.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ public function getImgProxyUrl(string $imageUrl, array $params)
118118
$path = $prefix . '/' . $path;
119119
}
120120
$sourceUrl = 'local:///' . $path;
121+
} elseif ($this->customConfig->getImgproxySourceType() === CustomConfig::IMGPROXY_CUSTOM_URL) {
122+
$proxyUrl = trim($this->customConfig->getImgproxySourceCustomUrl(), '/');
123+
$sourceUrl = $proxyUrl . '/' . $path;
121124
} else {
122125
$sourceUrl = $imageUrl;
123126
}

Model/Config/CustomConfig.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ class CustomConfig
2525

2626
public const XML_PATH_CATALOG_MEDIA_URL_FORMAT_CUSTOM_IMGPROXY_SOURCE_TYPE = 'web/url/catalog_media_url_format_custom_imgproxy_source_type';
2727
public const XML_PATH_CATALOG_MEDIA_URL_FORMAT_CUSTOM_IMGPROXY_SOURCE_PREFIX = 'web/url/catalog_media_url_format_custom_imgproxy_source_prefix';
28+
public const XML_PATH_CATALOG_MEDIA_URL_FORMAT_CUSTOM_IMGPROXY_SOURCE_CUSTOM_URL = 'web/url/catalog_media_url_format_custom_imgproxy_source_custom_url';
2829

2930
public const TYPE_DEFAULT = 'default';
3031
public const TYPE_PATTERN = 'pattern';
3132
public const TYPE_IMGPROXY = 'imgproxy';
3233

3334
public const IMGPROXY_URL = 'url';
35+
public const IMGPROXY_CUSTOM_URL = 'custom_url';
3436
public const IMGPROXY_LOCAL = 'local';
3537
public const IMGPROXY_S3 = 's3';
3638

@@ -108,6 +110,14 @@ public function getImgproxySourcePrefix($storeId = null): string
108110
) ?: '';
109111
}
110112

113+
public function getImgproxySourceCustomUrl($storeId = null): string
114+
{
115+
return $this->scopeConfig->getValue(
116+
self::XML_PATH_CATALOG_MEDIA_URL_FORMAT_CUSTOM_IMGPROXY_SOURCE_CUSTOM_URL,
117+
ScopeInterface::SCOPE_STORE,
118+
$storeId
119+
) ?: '';
120+
}
111121

112122
public function getImgproxyKey($storeId = null): string
113123
{

Model/Config/Source/ImgproxySourceType.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public function toOptionArray(): array
2727
'value' => CustomConfig::IMGPROXY_URL,
2828
'label' => __('URL: Proxy the default URL')
2929
],
30+
[
31+
'value' => CustomConfig::IMGPROXY_CUSTOM_URL,
32+
'label' => __('Custom URL: Proxy an url other than the default URL')
33+
],
3034
[
3135
'value' => CustomConfig::IMGPROXY_LOCAL,
3236
'label' => __('Local: Pass the local path')

Plugin/AssetImagePlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class AssetImagePlugin
99
{
10-
/** @var $helper */
10+
/** @var Data $helper */
1111
private $helper;
1212

1313
public function __construct(Data $helper)

etc/adminhtml/system.xml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<field id="catalog_media_url_format_custom_pattern" translate="label comment" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="0">
1414
<label>Custom URL format</label>
1515
<depends>
16+
<field id="catalog_media_url_format">image_optimization_parameters</field>
1617
<field id="catalog_media_url_format_custom_type">pattern</field>
1718
</depends>
1819
<comment><![CDATA[Custom format to add dynamic parameters.<br/>
@@ -23,36 +24,40 @@
2324
<field id="catalog_media_url_format_custom_imgproxy_host" translate="label comment" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="0">
2425
<label>Imgproxy Host</label>
2526
<depends>
27+
<field id="catalog_media_url_format">image_optimization_parameters</field>
2628
<field id="catalog_media_url_format_custom_type">imgproxy</field>
2729
</depends>
2830
<comment><![CDATA[The host the Imgproxy instance can be reached, eg https://example.com:8080/]]></comment>
2931
</field>
3032
<field id="catalog_media_url_format_custom_imgproxy_key" translate="label comment" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="0">
3133
<label>Imgproxy Key</label>
3234
<depends>
35+
<field id="catalog_media_url_format">image_optimization_parameters</field>
3336
<field id="catalog_media_url_format_custom_type">imgproxy</field>
3437
</depends>
3538
<comment><![CDATA[The IMGPROXY_KEY value, if signing is required]]></comment>
3639
</field>
3740
<field id="catalog_media_url_format_custom_imgproxy_salt" translate="label comment" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="0">
3841
<label>Imgproxy Salt</label>
3942
<depends>
43+
<field id="catalog_media_url_format">image_optimization_parameters</field>
4044
<field id="catalog_media_url_format_custom_type">imgproxy</field>
4145
</depends>
4246
<comment><![CDATA[The IMGPROXY_SALT value, if signing is required]]></comment>
4347
</field>
4448
<field id="catalog_media_url_format_custom_imgproxy_resize" translate="label comment" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="0">
4549
<label>Imgproxy Resize Type</label>
4650
<depends>
51+
<field id="catalog_media_url_format">image_optimization_parameters</field>
4752
<field id="catalog_media_url_format_custom_type">imgproxy</field>
4853
</depends>
4954
<source_model>Fruitcake\CustomImageUrl\Model\Config\Source\ImgproxyResizeType</source_model>
50-
5155
<comment><![CDATA[The Resize type]]></comment>
5256
</field>
5357
<field id="catalog_media_url_format_custom_imgproxy_source_type" translate="label comment" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="0">
5458
<label>Imgproxy Source Type</label>
5559
<depends>
60+
<field id="catalog_media_url_format">image_optimization_parameters</field>
5661
<field id="catalog_media_url_format_custom_type">imgproxy</field>
5762
</depends>
5863
<source_model>Fruitcake\CustomImageUrl\Model\Config\Source\ImgproxySourceType</source_model>
@@ -61,11 +66,21 @@
6166
<field id="catalog_media_url_format_custom_imgproxy_source_prefix" translate="label comment" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="0">
6267
<label>Imgproxy Source Prefix</label>
6368
<depends>
69+
<field id="catalog_media_url_format">image_optimization_parameters</field>
6470
<field id="catalog_media_url_format_custom_type">imgproxy</field>
6571
<field id="catalog_media_url_format_custom_imgproxy_source_type" separator=",">local,s3</field>
6672
</depends>
6773
<comment><![CDATA[For s3, provide both the bucket and optional prefix.]]></comment>
6874
</field>
75+
<field id="catalog_media_url_format_custom_imgproxy_source_custom_url" translate="label comment" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="0">
76+
<label>Imgproxy Source Custom URL</label>
77+
<depends>
78+
<field id="catalog_media_url_format">image_optimization_parameters</field>
79+
<field id="catalog_media_url_format_custom_type">imgproxy</field>
80+
<field id="catalog_media_url_format_custom_imgproxy_source_type" separator=",">custom_url</field>
81+
</depends>
82+
<comment><![CDATA[Enter a custom URL to proxy.]]></comment>
83+
</field>
6984
</group>
7085
</section>
7186
</system>

0 commit comments

Comments
 (0)