‪TYPO3CMS  10.4
ImageManipulationController.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\ResponseInterface;
21 use Psr\Http\Message\ServerRequestInterface;
28 
34 {
38  private ‪$templateView;
39 
43  public function ‪__construct(‪StandaloneView ‪$templateView = null)
44  {
45  if (!‪$templateView) {
46  ‪$templateView = GeneralUtility::makeInstance(StandaloneView::class);
47  ‪$templateView->‪setLayoutRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Layouts/')]);
48  ‪$templateView->‪setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials/ImageManipulation/')]);
49  ‪$templateView->‪setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/ImageManipulation/ImageManipulationWizard.html'));
50  }
51  $this->templateView = ‪$templateView;
52  }
53 
60  public function ‪getWizardContent(ServerRequestInterface $request): ResponseInterface
61  {
62  if ($this->‪isSignatureValid($request)) {
63  $parsedBody = json_decode($request->getParsedBody()['arguments'], true);
64  $fileUid = $parsedBody['image'];
65  $image = null;
67  try {
68  $image = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObject($fileUid);
69  } catch (‪FileDoesNotExistException $e) {
70  }
71  }
72  $viewData = [
73  'image' => $image,
74  'cropVariants' => $parsedBody['cropVariants']
75  ];
76  $content = $this->templateView->renderSection('Main', $viewData);
77  return new ‪HtmlResponse($content);
78  }
79  return new ‪HtmlResponse('', 403);
80  }
81 
88  protected function ‪isSignatureValid(ServerRequestInterface $request): bool
89  {
90  $token = GeneralUtility::hmac($request->getParsedBody()['arguments'], 'ajax_wizard_image_manipulation');
91  return hash_equals($token, $request->getParsedBody()['signature']);
92  }
93 }
‪TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger
‪static bool canBeInterpretedAsInteger($var)
Definition: MathUtility.php:74
‪TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException
Definition: FileDoesNotExistException.php:22
‪TYPO3\CMS\Backend\Controller\Wizard\ImageManipulationController\getWizardContent
‪ResponseInterface getWizardContent(ServerRequestInterface $request)
Definition: ImageManipulationController.php:59
‪TYPO3\CMS\Backend\Controller\Wizard\ImageManipulationController\isSignatureValid
‪bool isSignatureValid(ServerRequestInterface $request)
Definition: ImageManipulationController.php:87
‪TYPO3\CMS\Backend\Controller\Wizard\ImageManipulationController\__construct
‪__construct(StandaloneView $templateView=null)
Definition: ImageManipulationController.php:42
‪TYPO3\CMS\Backend\Controller\Wizard
Definition: AbstractWizardController.php:16
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:41
‪TYPO3\CMS\Fluid\View\AbstractTemplateView\setTemplatePathAndFilename
‪setTemplatePathAndFilename($templatePathAndFilename)
Definition: AbstractTemplateView.php:103
‪TYPO3\CMS\Backend\Controller\Wizard\ImageManipulationController
Definition: ImageManipulationController.php:34
‪TYPO3\CMS\Backend\Controller\Wizard\ImageManipulationController\$templateView
‪StandaloneView $templateView
Definition: ImageManipulationController.php:37
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:34
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:22
‪TYPO3\CMS\Fluid\View\AbstractTemplateView\setLayoutRootPaths
‪setLayoutRootPaths(array $layoutRootPaths)
Definition: AbstractTemplateView.php:167
‪TYPO3\CMS\Fluid\View\AbstractTemplateView\setPartialRootPaths
‪setPartialRootPaths(array $partialRootPaths)
Definition: AbstractTemplateView.php:134
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:26