Skip to content

Commit

Permalink
Merge branch 'release/1.4.10'
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Jan 26, 2018
2 parents 1330b56 + 23f60cb commit 6e38c1d
Show file tree
Hide file tree
Showing 13 changed files with 171 additions and 59 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# ImageOptimize Changelog

## 1.4.10 - 2018.01.26
### Added
* Shows an error if an OptimizedImages field is added to anything other than an Asset's layout
* Added a warning if a config setting is being overridden by the `config.php`
* Added a number of config settings to the AdminCP GUI

### Changed
* `UrlHelper::urlWithProtocol` -> `UrlHelper::urlWithScheme` for Craft CMS 3 RC7 compatibility
* Fixed an issue where you could delete the last Image Variant in the field settings, even though the option was disabled
* Handle the display of Optimized Image Variant names better when coming from Imgix

## 1.4.9 - 2018.01.20
### Added
* Added an *Edit Image* button to the Optimized Images field view
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "nystudio107/craft3-imageoptimize",
"description": "Automatically create & optimize responsive image transforms, using either native Craft transforms or a service like Imgix, with zero template changes.",
"type": "craft-plugin",
"version": "1.4.9",
"version": "1.4.10",
"keywords": [
"craft",
"cms",
Expand All @@ -28,7 +28,7 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"craftcms/cms": "^3.0.0-RC3",
"craftcms/cms": "^3.0.0-RC7",
"cloudinary/cloudinary_php": "^1.8.0",
"imageoptim/imageoptim": "^1.0.0",
"imgix/imgix-php": "^1.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ Craft.OptimizedImagesInput = Garnish.Base.extend(
break;
}
case 'delete': {
this.deleteVariantBlock(container);
if (!$option.hasClass('disabled')) {
this.deleteVariantBlock(container);
}
break;
}
}
Expand Down Expand Up @@ -184,9 +186,9 @@ Craft.OptimizedImagesInput = Garnish.Base.extend(
menuBtn = $value.data('menubtn');
$menuItem = $(menuBtn.menu.$menuList[1]);
if (disabledDeleteItem) {
$menuItem.addClass('disabled');
$menuItem.find("> li > a").addClass('disabled').disable();
} else {
$menuItem.removeClass('disabled');
$menuItem.find("> li > a").removeClass('disabled').enable();
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
// as per https://www.netvlies.nl/tips-updates/design-interactie/design-interactie/retina-revolution/
'lowerQualityRetinaImageVariants' => true,

// Controls whether Optimized Image Variants be created that would be up-scaled
// Controls whether Optimized Image Variants are created that would be up-scaled
// to be larger than the original source image
'allowUpScaledImageVariants' => false,

Expand Down
79 changes: 45 additions & 34 deletions src/fields/OptimizedImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,39 +225,50 @@ public function getSettingsHtml()
*/
public function getInputHtml($value, ElementInterface $element = null): string
{
// Register our asset bundle
Craft::$app->getView()->registerAssetBundle(OptimizedImagesFieldAsset::class);

// Get our id and namespace
$id = Craft::$app->getView()->formatInputId($this->handle);
$nameSpaceId = Craft::$app->getView()->namespaceInputId($id);

// Variables to pass down to our field JavaScript to let it namespace properly
$jsonVars = [
'id' => $id,
'name' => $this->handle,
'namespace' => $nameSpaceId,
'prefix' => Craft::$app->getView()->namespaceInputId(''),
];
$jsonVars = Json::encode($jsonVars);
$view = Craft::$app->getView();
$view->registerJs("$('#{$nameSpaceId}-field').ImageOptimizeOptimizedImages(".$jsonVars.");");

$settings = ImageOptimize::$plugin->getSettings();

// Render the input template
return Craft::$app->getView()->renderTemplate(
'image-optimize/_components/fields/OptimizedImages_input',
[
'name' => $this->handle,
'value' => $value,
'variants' => $this->variants,
'field' => $this,
'settings' => $settings,
'elementId' => $element->id,
'id' => $id,
'nameSpaceId' => $nameSpaceId,
]
);
if (!empty($element) && $element instanceof Asset) {
/** @var Asset $element */
// Register our asset bundle
Craft::$app->getView()->registerAssetBundle(OptimizedImagesFieldAsset::class);

// Get our id and namespace
$id = Craft::$app->getView()->formatInputId($this->handle);
$nameSpaceId = Craft::$app->getView()->namespaceInputId($id);

// Variables to pass down to our field JavaScript to let it namespace properly
$jsonVars = [
'id' => $id,
'name' => $this->handle,
'namespace' => $nameSpaceId,
'prefix' => Craft::$app->getView()->namespaceInputId(''),
];
$jsonVars = Json::encode($jsonVars);
$view = Craft::$app->getView();
$view->registerJs("$('#{$nameSpaceId}-field').ImageOptimizeOptimizedImages(".$jsonVars.");");

$settings = ImageOptimize::$plugin->getSettings();

// Render the input template
return Craft::$app->getView()->renderTemplate(
'image-optimize/_components/fields/OptimizedImages_input',
[
'name' => $this->handle,
'value' => $value,
'variants' => $this->variants,
'field' => $this,
'settings' => $settings,
'elementId' => $element->id,
'format' => $element->getExtension(),
'id' => $id,
'nameSpaceId' => $nameSpaceId,
]
);
} else {
// Render an error template, since the field only works when attached to an Asset
return Craft::$app->getView()->renderTemplate(
'image-optimize/_components/fields/OptimizedImages_error',
[
]
);
}
}
}
9 changes: 7 additions & 2 deletions src/imagetransforms/ImageTransform.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use craft\helpers\UrlHelper;
use craft\models\AssetTransform;

use yii\base\Exception;

/**
* @author nystudio107
* @package ImageOptimize
Expand Down Expand Up @@ -116,9 +118,12 @@ public static function prefetchRemoteFile($url)
} else {
$protocol = "http";
}
$url = UrlHelper::urlWithProtocol($url, $protocol);
$url = UrlHelper::urlWithScheme($url, $protocol);
} else {
$url = UrlHelper::siteUrl($url);
try {
$url = UrlHelper::siteUrl($url);
} catch (Exception $e) {
}
}
}

Expand Down
19 changes: 10 additions & 9 deletions src/models/OptimizedImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use craft\helpers\UrlHelper;
use craft\base\Model;
use craft\validators\ArrayValidator;

use yii\base\Exception;

/**
Expand Down Expand Up @@ -340,18 +341,18 @@ public function getRemoteFileSize($url, $formatSize = true, $useHead = true)
{
// Make this a full URL / aaw -- 2017.09.08
if (!UrlHelper::isAbsoluteUrl($url)) {
if (isset($_SERVER['HTTPS']) && (strcasecmp($_SERVER['HTTPS'], 'on') === 0 || $_SERVER['HTTPS'] == 1)
|| isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strcasecmp($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') === 0
) {
$protocol = "https";
} else {
$protocol = "http";
}
if (UrlHelper::isProtocolRelativeUrl($url)) {
$url = UrlHelper::urlWithProtocol($url, $protocol);
if (isset($_SERVER['HTTPS']) && (strcasecmp($_SERVER['HTTPS'], 'on') === 0 || $_SERVER['HTTPS'] == 1)
|| isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strcasecmp($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') === 0
) {
$protocol = "https";
} else {
$protocol = "http";
}
$url = UrlHelper::urlWithScheme($url, $protocol);
} else {
try {
$url = UrlHelper::siteUrl($url, null, $protocol);
$url = UrlHelper::siteUrl($url);
} catch (Exception $e) {
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Settings extends Model
public $lowerQualityRetinaImageVariants = true;

/**
* Controls whether Optimized Image Variants be created that would be up-scaled
* Controls whether Optimized Image Variants are created that would be up-scaled
* to be larger than the original source image
*
* @var bool
Expand Down
21 changes: 21 additions & 0 deletions src/templates/_components/fields/OptimizedImages_error.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{#
/**
* Image Optimize plugin for Craft CMS 3.x
*
* OptimizedImages Field Input
*
* @author nystudio107
* @copyright Copyright (c) 2017 nystudio107
* @link https://nystudio107.com
* @package ImageOptimize
* @since 1.4.10
*/
#}

{% import "_includes/forms" as forms %}

<div class="field">
<div class="heading">
<label>{{ "OptimizedImages fields only work when added to an Asset Volume's layout." |t('image-optimize') }} </label>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
</a>
</div>
{% if variant.format == null %}
{% set thisFormat = thisUrl |split('.') |last %}
{% set thisFormat = format %}
{% else %}
{% set thisFormat = variant.format %}
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{# @var craft \craft\web\twig\variables\CraftVariable #}
{#
/**
* Image Optimize plugin for Craft CMS
Expand Down
8 changes: 8 additions & 0 deletions src/templates/macros.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% macro configWarning(setting, file) -%}
{%- set configArray = craft.app.config.getConfigFromFile(file) -%}
{%- if configArray[setting] is defined -%}
{{- "This is being overridden by the `#{setting}` setting in the `config/#{file}.php` file." |raw }}
{%- else -%}
{{ false }}
{%- endif -%}
{%- endmacro %}
64 changes: 58 additions & 6 deletions src/templates/settings.twig
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
#}

{% from 'image-optimize/macros' import configWarning %}

{% import "_includes/forms" as forms %}

{% do view.registerAssetBundle("nystudio107\\imageoptimize\\assetbundles\\imageoptimize\\ImageOptimizeAsset") %}
Expand All @@ -29,37 +31,87 @@
'craft': 'Craft'|t('image-optimize'),
'imgix': "Imgix"|t('image-optimize'),
},
class: 'io-transform-method'
class: 'io-transform-method',
warning: configWarning('transformMethod', 'image-optimize'),
}) }}
<!-- createColorPalette -->
{{ forms.lightswitchField({
label: "Create Color Palette"|t('image-optimize'),
instructions: "Controls whether a dominant color palette should be created for image variants. It takes a bit of time, so if you never plan to use it, you can turn it off."|t('image-optimize'),
'id': 'createColorPalette',
'name': 'createColorPalette',
'on': settings.createColorPalette,
'warning': configWarning('createColorPalette', 'image-optimize')
}) }}
<!-- createPlaceholderSilhouettes -->
{{ forms.lightswitchField({
label: "Create Placeholder Silhouettes"|t('image-optimize'),
instructions: "Controls whether SVG placeholder silhouettes should be created for image variants. It takes a bit of time, so if you never plan to use them, you can turn it off."|t('image-optimize'),
'id': 'createPlaceholderSilhouettes',
'name': 'createPlaceholderSilhouettes',
'on': settings.createPlaceholderSilhouettes,
'warning': configWarning('createPlaceholderSilhouettes', 'image-optimize')
}) }}
<!-- lowerQualityRetinaImageVariants -->
{{ forms.lightswitchField({
label: "Lower Quality Retina Image Variants"|t('image-optimize'),
instructions: "Controls whether retina images are automatically created with reduced quality as per <a href='https://www.netvlies.nl/tips-updates/design-interactie/design-interactie/retina-revolution/' target='_blank'>here</a>."|t('image-optimize') |raw,
'id': 'lowerQualityRetinaImageVariants',
'name': 'lowerQualityRetinaImageVariants',
'on': settings.lowerQualityRetinaImageVariants,
'warning': configWarning('lowerQualityRetinaImageVariants', 'image-optimize')
}) }}
<!-- allowUpScaledImageVariants -->
{{ forms.lightswitchField({
label: "Allow Up-Scaled Image Variants"|t('image-optimize'),
instructions: "Controls whether Optimized Image Variants are created that would be up-scaled to be larger than the original source image."|t('image-optimize'),
'id': 'allowUpScaledImageVariants',
'name': 'allowUpScaledImageVariants',
'on': settings.allowUpScaledImageVariants,
'warning': configWarning('allowUpScaledImageVariants', 'image-optimize')
}) }}
<!-- autoSharpenScaledImages -->
{{ forms.lightswitchField({
label: "Auto Sharpen Scaled Images"|t('image-optimize'),
instructions: "Controls whether images scaled down >= 50% should be automatically sharpened."|t('image-optimize'),
'id': 'autoSharpenScaledImages',
'name': 'autoSharpenScaledImages',
'on': settings.autoSharpenScaledImages,
'warning': configWarning('autoSharpenScaledImages', 'image-optimize')
}) }}

<div class="io-method-settings io-imgix-method"{% if settings.transformMethod != 'imgix' %} style="display: none;"{% endif %}>
<!-- imgixDomain -->
{{ forms.textField({
label: 'Imgix Source Domain',
instructions: "The source domain to use for the Imgix transforms."|t('image-optimize'),
id: 'imgixDomain',
name: 'imgixDomain',
value: settings.imgixDomain
value: settings.imgixDomain,
warning: configWarning('imgixDomain', 'image-optimize'),
}) }}
<!-- imgixApiKey -->
{{ forms.textField({
label: 'Imgix API Key',
instructions: "The API key to use for the Imgix transforms (needed for auto-purging changed assets)."|t('image-optimize'),
id: 'imgixApiKey',
name: 'imgixApiKey',
value: settings.imgixApiKey
value: settings.imgixApiKey,
warning: configWarning('imgixApiKey', 'image-optimize'),
}) }}
</div>
<div class="field io-method-settings io-craft-method"{% if settings.transformMethod != 'craft' %} style="display: none;"{% endif %}>
<div class="heading">
<h2>{{ 'Image Processors & Variant Creators' }}</h2>
<div class="instructions">
<p class="readable">
These ImageOptimize settings are not editable here; this is just an informational display.
The following ImageOptimize settings are not editable here; this is just an informational display.
Instead copy the <code>imageoptimize/config.php</code> file to Craft's <code>config/</code> directory, renaming it to <code>image-optimize.php</code>, and make your changes there to override default settings.
</p>
</div>
</div>
{% if imageProcessors is defined and imageProcessors |length %}
<h2>{{ 'Active Image Processors' }}</h2>
<h3>{{ 'Active Image Processors' }}</h3>
<table id="imageProcessors" class="data collapsible image-optimize">
<thead class="">
<tr>
Expand Down Expand Up @@ -102,7 +154,7 @@
{% endif %}

{% if variantCreators is defined and variantCreators |length %}
<h2>{{ 'Active Image Variant Creators' }}</h2>
<h3>{{ 'Active Image Variant Creators' }}</h3>
<table id="variantCreators" class="data collapsible image-optimize">
<thead class="">
<tr>
Expand Down

0 comments on commit 6e38c1d

Please sign in to comment.