Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] 1.2 - Fix MediaManger Thumbnail View #596

Merged
merged 3 commits into from
Jul 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
407 changes: 133 additions & 274 deletions modules/backend/widgets/MediaManager.php

Large diffs are not rendered by default.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -499,8 +499,7 @@ MediaManagerImageCropPopup.prototype.updateSelectionSizeLabel=function(width,hei
return}this.selectionSizeLabel.setAttribute('class','')
this.selectionSizeLabel.querySelector('[data-label=selection-width]').textContent=parseInt(width)
this.selectionSizeLabel.querySelector('[data-label=selection-height]').textContent=parseInt(height)}
MediaManagerImageCropPopup.prototype.onPopupHidden=function(event,element,popup){this.$popupElement.find('form').request(this.options.alias+'::onEndCroppingSession')
$(document).trigger('mousedown')
MediaManagerImageCropPopup.prototype.onPopupHidden=function(event,element,popup){$(document).trigger('mousedown')
this.dispose()}
MediaManagerImageCropPopup.prototype.onPopupShown=function(event,element,popup){this.$popupElement=popup
this.$popupElement.on('change','[data-control="selection-mode"]',this.proxy(this.onSelectionModeChanged))
Original file line number Diff line number Diff line change
@@ -378,8 +378,6 @@
// ============================

MediaManagerImageCropPopup.prototype.onPopupHidden = function(event, element, popup) {
this.$popupElement.find('form').request(this.options.alias+'::onEndCroppingSession')

// Release clickedElement reference inside redactor.js
// If we don't do it, the image editor popup DOM elements
// won't be removed from the memory.
18 changes: 8 additions & 10 deletions modules/backend/widgets/mediamanager/partials/_item-icon.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<div class="icon-container <?= $itemType ?>">
<div class="icon-wrapper"><i class="<?= $this->itemTypeToIconClass($item, $itemType) ?>"></i></div>

<?php
if ($itemType == System\Classes\MediaLibraryItem::FILE_TYPE_IMAGE):
$thumbnailPath = $this->thumbnailExists($thumbnailParams, $item->path, $item->lastModified);
?>

<?php if (
$itemType == System\Classes\MediaLibraryItem::FILE_TYPE_IMAGE
&& $thumbnailUrl = $this->getResizedImageUrl($item->path, $thumbnailParams)
): ?>
<div>
<?php if (!$thumbnailPath): ?>
<div class="image-placeholder"
<?php if (!$thumbnailUrl): ?>
<div
class="image-placeholder"
data-width="<?= $thumbnailParams['width'] ?>"
data-height="<?= $thumbnailParams['height'] ?>"
data-path="<?= e($item->path) ?>"
@@ -19,8 +18,7 @@
</div>
<?php else: ?>
<?= $this->makePartial('thumbnail-image', [
'isError' => $this->thumbnailIsError($thumbnailPath),
'imageUrl' => $this->getThumbnailImageUrl($thumbnailPath)
'imageUrl' => $thumbnailUrl,
]) ?>
<?php endif ?>
</div>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php if (!$isError): ?>
<?php if ($imageUrl): ?>
<img src="<?= $imageUrl ?>"/>
<?php else: ?>
<i class="icon-chain-broken" title="<?= e(trans('backend::lang.media.thumbnail_error')) ?>"></i>
<p class="thumbnail-error-message"><?= e(trans('backend::lang.media.thumbnail_error')) ?></p>
<?php endif ?>
<?php endif ?>
27 changes: 0 additions & 27 deletions modules/system/classes/ImageResizer.php
Original file line number Diff line number Diff line change
@@ -48,12 +48,6 @@ class ImageResizer
*/
public const CACHE_PREFIX = 'system.resizer.';

/**
* Available methods to use when processing images
*/
public const METHOD_RESIZE = 'resize';
public const METHOD_CROP = 'crop';

/**
* @var array Available sources to get images from
*/
@@ -108,27 +102,6 @@ public function __construct($image, $width = 0, $height = 0, $options = [])
$this->options = array_merge($this->getDefaultOptions(), $options);
}

/**
* A simple static method for resizing an image and receiving the output path
*
* @throws ApplicationException If an invalid resize mode is passed to the the method.
*/
public static function processImage(
mixed $image,
int|float $width = 0,
int|float $height = 0,
array $options = [],
string $method = self::METHOD_RESIZE
): string {
if (!in_array($method, [static::METHOD_RESIZE, static::METHOD_CROP])) {
throw new \ApplicationException('Invalid method passed to processImage');
}

$resizer = new static($image, $width, $height, $options);
$resizer->{$method}();
return $resizer->getPathToResizedImage();
}

/**
* Get the default options for the resizer
*/
2 changes: 2 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -131,6 +131,8 @@
<exclude-pattern>*/vendor/*</exclude-pattern>
<!-- Ignore this view file as fixing the issues in here will break the template -->
<exclude-pattern>modules/system/views/exception.php</exclude-pattern>
<!-- Ignore this view file as PHPCS wants line 8 to have 44 spaces instead of 12, clearly insane -->
<exclude-pattern>modules/backend/widgets/mediamanager/partials/_item-icon.php</exclude-pattern>
<!-- Ignore this test case completely as it's testing a parse error -->
<exclude-pattern>tests/fixtures/plugins/testvendor/goto/Plugin.php</exclude-pattern>
</ruleset>