|
1
|
|
|
<?php |
|
2
|
|
|
namespace Fab\Media\Controller; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* This file is part of the TYPO3 CMS project. |
|
6
|
|
|
* |
|
7
|
|
|
* It is free software; you can redistribute it and/or modify it under |
|
8
|
|
|
* the terms of the GNU General Public License, either version 2 |
|
9
|
|
|
* of the License, or any later version. |
|
10
|
|
|
* |
|
11
|
|
|
* For the full copyright and license information, please read the |
|
12
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
13
|
|
|
* |
|
14
|
|
|
* The TYPO3 project - inspiring people to share! |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
use TYPO3\CMS\Core\Resource\File; |
|
18
|
|
|
use TYPO3\CMS\Core\Resource\ProcessedFile; |
|
19
|
|
|
use TYPO3\CMS\Core\Resource\ResourceFactory; |
|
20
|
|
|
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Controller which handles actions related to Processed File. |
|
24
|
|
|
*/ |
|
25
|
|
|
class ProcessedFileController extends ActionController |
|
26
|
|
|
{ |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Initializes the controller before invoking an action method. |
|
30
|
|
|
*/ |
|
31
|
|
View Code Duplication |
public function initializeAction() |
|
|
|
|
|
|
32
|
|
|
{ |
|
33
|
|
|
|
|
34
|
|
|
// Configure property mapping to retrieve the file object. |
|
35
|
|
|
if ($this->arguments->hasArgument('file')) { |
|
36
|
|
|
|
|
37
|
|
|
/** @var \Fab\Media\TypeConverter\FileConverter $typeConverter */ |
|
38
|
|
|
$typeConverter = $this->objectManager->get('Fab\Media\TypeConverter\FileConverter'); |
|
39
|
|
|
|
|
40
|
|
|
$propertyMappingConfiguration = $this->arguments->getArgument('file')->getPropertyMappingConfiguration(); |
|
41
|
|
|
$propertyMappingConfiguration->setTypeConverter($typeConverter); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Create a processed file according to some configuration. |
|
47
|
|
|
* |
|
48
|
|
|
* @param File $file |
|
49
|
|
|
* @param array $processingConfiguration |
|
50
|
|
|
* @return string |
|
51
|
|
|
*/ |
|
52
|
|
|
public function createAction(File $file, array $processingConfiguration = array()) |
|
53
|
|
|
{ |
|
54
|
|
|
$processedFile = $file->process(ProcessedFile::CONTEXT_IMAGECROPSCALEMASK, $processingConfiguration); |
|
55
|
|
|
|
|
56
|
|
|
$response = array( |
|
57
|
|
|
'success' => TRUE, |
|
58
|
|
|
'original' => $file->getUid(), |
|
59
|
|
|
'title' => $file->getProperty('title') ? $file->getProperty('title') : $file->getName(), |
|
60
|
|
|
'publicUrl' => $processedFile->getPublicUrl(), |
|
61
|
|
|
'width' => $processedFile->getProperty('width'), |
|
62
|
|
|
'height' => $processedFile->getProperty('height'), |
|
63
|
|
|
); |
|
64
|
|
|
|
|
65
|
|
|
header("Content-Type: text/json"); |
|
66
|
|
|
return htmlspecialchars(json_encode($response), ENT_NOQUOTES); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.