Skip to content

Commit

Permalink
Merge branch 'main' into magicsunday-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Gitsko authored Jun 6, 2024
2 parents 797e5c3 + a4461bb commit a392589
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 36 deletions.
28 changes: 27 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 12.0.1
# 12.0.2

## TASK

Expand All @@ -20,6 +20,32 @@

## MISC

- Allow inline images 0316b33
- Ignore .cache and composer.json.testing which are created during running the test suites, because they do not need to beeing tracked in the repository. 8978558
- chore: update actions to fix Node.js 16 actions are deprecated. db31a83
- Show more information in functional tests e673dcc
- fix previous test changes 300ba5d
- make test compatible with TYPO3 > v12 3f98798
- improve functional test job name ec3dfc1
- chore: exclude TYPO3 v13 + PHP 8.1 from test matrix due to 'typo3/cms-core v13.0.1 requires php ^8.2' 5cf301d
- chore: migrate composeUpdate step for supporting TYPO3 v12 as default and TYPO3 v13 ae7b4b1
- use Postgres as default DBMS in tests - it's image is smaller and the tests therefore faster 462deec
- chore: update test suite with latest PHP and TYPO3 versions a392215
- chore: give the action job a meaningful name d882e78
- chore: fix package name for cms_rte_ckeditor in ext_emconf.php 5cff197
- chore: migrate phpunit configuration bb2e525
- fix: functional tests adb9c9c
- fix: do not override TYPO3_SITE_URL 2b8c79a
- chore: fix CS 10e2bb2
- fix: validate imageSource only if not NULL 753b3fc
- fix: call to undefined method - GeneralUtility::shortMD5() was removed in TYPO3 v12 e89e844
- fix: remove access to non existant property It was removed long ago and requested configuration option does not exists anymore since TYPO3 v10 f5ce607
- chore: fix function name case a370ff7
- chore: remove dead code a096121
- fix: ensure $imageSource is valid before working with it. 41d67f8
- chore: remove obsolete phpstan ignore error patterns dc80f2e
- set GitHub codespace environment container to PHP (8.2) 3d74578
- fix #270: circumvent PHP < 7.4.4 bug with childNodes being NULL 36201ef
- Apply class to bacbd45
- chore: coding style 962dd48
- chore: fix coding style 9f8628a
Expand Down
64 changes: 32 additions & 32 deletions Classes/Controller/ImageRenderingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

namespace Netresearch\RteCKEditorImage\Controller;

use Netresearch\RteCKEditorImage\Utils\ProcessedFilesHandler;
use Psr\Log\LogLevel as PsrLogLevel;
use TYPO3\CMS\Core\Log\Logger;
use TYPO3\CMS\Core\Log\LogManager;
use TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\ProcessedFile;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Resource\Service\MagicImageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down Expand Up @@ -78,44 +80,42 @@ public function renderImageAttributes(?string $content, array $conf = []): strin
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
$systemImage = $resourceFactory->getFileObject($fileUid);

if ($imageSource !== $systemImage->getPublicUrl()) {
// Source file is a processed image
$imageConfiguration = [
'width' => (int) ($imageAttributes['width'] ?? $systemImage->getProperty('width') ?? 0),
'height' => (int) ($imageAttributes['height'] ?? $systemImage->getProperty('height') ?? 0),
];
// check if there is a processed variant, if not, create one
/** @var ProcessedFilesHandler $processedHandler */
$processedHandler = GeneralUtility::makeInstance(ProcessedFilesHandler::class);
$imageConfiguration = [
'width' => (int) ($imageAttributes['width'] ?? $systemImage->getProperty('width') ?? 0),
'height' => (int) ($imageAttributes['height'] ?? $systemImage->getProperty('height') ?? 0),
];
$processedFile = $processedHandler->createProcessedFile($systemImage, $imageConfiguration);

$processedFile = $this->getMagicImageService()
->createMagicImage($systemImage, $imageConfiguration);
$imageSource = $processedFile->getPublicUrl();

$imageSource = $processedFile->getPublicUrl();

if (null === $imageSource) {
throw new FileDoesNotExistException();
}
if (null === $imageSource) {
throw new FileDoesNotExistException();
}

$additionalAttributes = [
'src' => $imageSource,
'title' => $this->getAttributeValue('title', $imageAttributes, $systemImage),
'alt' => $this->getAttributeValue('alt', $imageAttributes, $systemImage),
'width' => $processedFile->getProperty('width') ?? $imageConfiguration['width'],
'height' => $processedFile->getProperty('height') ?? $imageConfiguration['height'],
];
$additionalAttributes = [
'src' => $imageSource,
'title' => $this->getAttributeValue('title', $imageAttributes, $systemImage),
'alt' => $this->getAttributeValue('alt', $imageAttributes, $systemImage),
'width' => $processedFile->getProperty('width') ?? $imageConfiguration['width'],
'height' => $processedFile->getProperty('height') ?? $imageConfiguration['height'],
];

$lazyLoading = $this->getLazyLoadingConfiguration();
$lazyLoading = $this->getLazyLoadingConfiguration();

if ($lazyLoading !== null) {
$additionalAttributes['loading'] = $lazyLoading;
}
if ($lazyLoading !== null) {
$additionalAttributes['loading'] = $lazyLoading;
}

// Remove internal attributes
unset(
$imageAttributes['data-title-override'],
$imageAttributes['data-alt-override']
);
// Remove internal attributes
unset(
$imageAttributes['data-title-override'],
$imageAttributes['data-alt-override']
);

$imageAttributes = array_merge($imageAttributes, $additionalAttributes);
}
$imageAttributes = array_merge($imageAttributes, $additionalAttributes);
} catch (FileDoesNotExistException $fileDoesNotExistException) {
// Log in fact the file could not be retrieved
$this->getLogger()->log(
Expand Down Expand Up @@ -159,7 +159,7 @@ public function renderImageAttributes(?string $content, array $conf = []): strin
// Popup rendering (support new `zoom` and legacy `clickenlarge` attributes)
if (
(isset($imageAttributes['data-htmlarea-zoom'])
|| isset($imageAttributes['data-htmlarea-clickenlarge']))
|| isset($imageAttributes['data-htmlarea-clickenlarge']))
&& isset($systemImage)
) {
$config = $GLOBALS['TSFE']->tmpl->setup['lib.']['contentElement.']['settings.']['media.']['popup.'] ?? [];
Expand Down
2 changes: 1 addition & 1 deletion Classes/Database/RteImagesDbHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ private function modifyRteField(string $value): string
$magicImageService = GeneralUtility::makeInstance(MagicImageService::class);

$pageTsConfig = BackendUtility::getPagesTSconfig(0);
$magicImageService->setMagicImageMaximumDimensions($pageTsConfig['TCEFORM.']['RTE.']['default.'] ?? []);
$magicImageService->setMagicImageMaximumDimensions($pageTsConfig['RTE.']['default.'] ?? []);

foreach ($imgSplit as $key => $v) {
// Odd numbers contains the <img> tags
Expand Down
39 changes: 39 additions & 0 deletions Classes/Utils/ProcessedFilesHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Netresearch\RteCKEditorImage\Utils;

use Symfony\Component\Process\Process;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\ProcessedFile;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Service\ImageService;

class ProcessedFilesHandler
{
/**
* Create a processed variant of a file based on the given configuration.
* Returns the ProcessedFile or throws an exception if creation failed.
*
* Example for the image configuration:
* $imageConfiguration = [
* 'width' => '200c',
* 'height' => '200c',
* ];
*
* @param File $file The file object
* @param array $imageConfiguration The image configuration
* @return ProcessedFile
*/
public function createProcessedFile(File $file, array $imageConfiguration): ProcessedFile
{
/** @var ImageService $imageService */
$imageService = GeneralUtility::makeInstance(ImageService::class);

// Process the file with the given configuration
try {
return $imageService->applyProcessingInstructions($file, $imageConfiguration);
} catch (\Exception $e) {
throw new \Exception('Could not create processed file', 1716565499);
}
}
}
2 changes: 1 addition & 1 deletion Resources/Public/JavaScript/Plugins/typo3image.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ export default class Typo3Image extends Core.Plugin {

editor.model.schema.register('typo3image', {
inheritAllFrom: '$blockObject',
allowIn: '$text',
allowIn: ['$text', '$block'],
allowAttributes: [
'src',
'fileUid',
Expand Down
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
'clearCacheOnLoad' => 0,
'author' => 'Sebastian Koschel',
'author_email' => '[email protected]',
'version' => '12.0.1',
'version' => '12.0.2',
'constraints' => [
'depends' => [
'php' => '8.1.0-8.9.99',
Expand Down

0 comments on commit a392589

Please sign in to comment.