‪TYPO3CMS  9.5
ImageManipulationController.php
Go to the documentation of this file.
1 <?php
2 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 
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
26 
32 {
36  private ‪$templateView;
37 
41  public function ‪__construct(‪StandaloneView ‪$templateView = null)
42  {
43  if (!‪$templateView) {
44  ‪$templateView = GeneralUtility::makeInstance(StandaloneView::class);
45  ‪$templateView->‪setLayoutRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Layouts/')]);
46  ‪$templateView->‪setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials/ImageManipulation/')]);
47  ‪$templateView->‪setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/ImageManipulation/ImageManipulationWizard.html'));
48  }
49  $this->templateView = ‪$templateView;
50  }
51 
58  public function ‪getWizardContent(ServerRequestInterface $request): ResponseInterface
59  {
60  if ($this->‪isSignatureValid($request)) {
61  $parsedBody = json_decode($request->getParsedBody()['arguments'], true);
62  $fileUid = $parsedBody['image'];
63  $image = null;
65  try {
67  } catch (‪FileDoesNotExistException $e) {
68  }
69  }
70  $viewData = [
71  'image' => $image,
72  'cropVariants' => $parsedBody['cropVariants']
73  ];
74  $content = $this->templateView->renderSection('Main', $viewData);
75  return new ‪HtmlResponse($content);
76  }
77  return new ‪HtmlResponse('', 403);
78  }
79 
86  protected function ‪isSignatureValid(ServerRequestInterface $request): bool
87  {
88  $token = GeneralUtility::hmac($request->getParsedBody()['arguments'], 'ajax_wizard_image_manipulation');
89  return hash_equals($token, $request->getParsedBody()['signature']);
90  }
91 }
‪TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger
‪static bool canBeInterpretedAsInteger($var)
Definition: MathUtility.php:73
‪TYPO3\CMS\Core\Resource\ResourceFactory\getInstance
‪static ResourceFactory getInstance()
Definition: ResourceFactory.php:39
‪TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException
Definition: FileDoesNotExistException.php:21
‪TYPO3\CMS\Backend\Controller\Wizard\ImageManipulationController\getWizardContent
‪ResponseInterface getWizardContent(ServerRequestInterface $request)
Definition: ImageManipulationController.php:57
‪TYPO3\CMS\Backend\Controller\Wizard\ImageManipulationController\isSignatureValid
‪bool isSignatureValid(ServerRequestInterface $request)
Definition: ImageManipulationController.php:85
‪TYPO3\CMS\Backend\Controller\Wizard\ImageManipulationController\__construct
‪__construct(StandaloneView $templateView=null)
Definition: ImageManipulationController.php:40
‪TYPO3\CMS\Backend\Controller\Wizard
Definition: AbstractWizardController.php:2
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:33
‪TYPO3\CMS\Fluid\View\AbstractTemplateView\setTemplatePathAndFilename
‪setTemplatePathAndFilename($templatePathAndFilename)
Definition: AbstractTemplateView.php:100
‪TYPO3\CMS\Backend\Controller\Wizard\ImageManipulationController
Definition: ImageManipulationController.php:32
‪TYPO3\CMS\Backend\Controller\Wizard\ImageManipulationController\$templateView
‪StandaloneView $templateView
Definition: ImageManipulationController.php:35
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:32
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:21
‪TYPO3\CMS\Core\Resource\ResourceFactory\getFileObject
‪File getFileObject($uid, array $fileData=[])
Definition: ResourceFactory.php:399
‪TYPO3\CMS\Fluid\View\AbstractTemplateView\setLayoutRootPaths
‪setLayoutRootPaths(array $layoutRootPaths)
Definition: AbstractTemplateView.php:164
‪TYPO3\CMS\Fluid\View\AbstractTemplateView\setPartialRootPaths
‪setPartialRootPaths(array $partialRootPaths)
Definition: AbstractTemplateView.php:131
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:25