Completed
Push — master ( 4fec92...72e61b )
by Fabien
68:14 queued 13:14
created
Classes/Form/FileUploadTceForms.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -20,56 +20,56 @@
 block discarded – undo
20 20
  */
21 21
 class FileUploadTceForms extends FileUpload
22 22
 {
23
-    /**
24
-     * @var string
25
-     */
26
-    protected string $templateFile = 'Resources/Private/Standalone/FileUploadTceFormsTemplate.html';
23
+	/**
24
+	 * @var string
25
+	 */
26
+	protected string $templateFile = 'Resources/Private/Standalone/FileUploadTceFormsTemplate.html';
27 27
 
28
-    /**
29
-     * Fetch the JavaScript to be rendered and replace the markers with "live" variables.
30
-     */
31
-    protected function getJavaScript(): string
32
-    {
33
-        // Get the base prefix.
34
-        $basePrefix = $this->getBasePrefix($this->getPrefix());
35
-        $filePath = ExtensionManagementUtility::extPath('media') . 'Resources/Private/Standalone/FileUploadTceForms.js';
28
+	/**
29
+	 * Fetch the JavaScript to be rendered and replace the markers with "live" variables.
30
+	 */
31
+	protected function getJavaScript(): string
32
+	{
33
+		// Get the base prefix.
34
+		$basePrefix = $this->getBasePrefix($this->getPrefix());
35
+		$filePath = ExtensionManagementUtility::extPath('media') . 'Resources/Private/Standalone/FileUploadTceForms.js';
36 36
 
37
-        return sprintf(
38
-            file_get_contents($filePath),
39
-            $basePrefix,
40
-            $this->elementId,
41
-            $this->getModuleUrl(),
42
-            $this->getAllowedExtension(),
43
-            GeneralUtility::getMaxUploadFileSize() * 1024,
44
-            $this->getValue()
45
-        );
46
-    }
37
+		return sprintf(
38
+			file_get_contents($filePath),
39
+			$basePrefix,
40
+			$this->elementId,
41
+			$this->getModuleUrl(),
42
+			$this->getAllowedExtension(),
43
+			GeneralUtility::getMaxUploadFileSize() * 1024,
44
+			$this->getValue()
45
+		);
46
+	}
47 47
 
48
-    protected function getModuleUrl(): string
49
-    {
50
-        $moduleSignature = MediaModule::getSignature();
51
-        return BackendUtility::getModuleUrl($moduleSignature);
52
-    }
48
+	protected function getModuleUrl(): string
49
+	{
50
+		$moduleSignature = MediaModule::getSignature();
51
+		return BackendUtility::getModuleUrl($moduleSignature);
52
+	}
53 53
 
54
-    /**
55
-     * Get allowed extension.
56
-     */
57
-    protected function getAllowedExtension(): string
58
-    {
59
-        return $this->file->getExtension();
60
-    }
54
+	/**
55
+	 * Get allowed extension.
56
+	 */
57
+	protected function getAllowedExtension(): string
58
+	{
59
+		return $this->file->getExtension();
60
+	}
61 61
 
62
-    /**
63
-     * Returns additional file info.
64
-     */
65
-    protected function getFileInfo(): string
66
-    {
67
-        /** @var MetadataView $metadataView */
68
-        $metadataView = GeneralUtility::makeInstance(MetadataView::class);
62
+	/**
63
+	 * Returns additional file info.
64
+	 */
65
+	protected function getFileInfo(): string
66
+	{
67
+		/** @var MetadataView $metadataView */
68
+		$metadataView = GeneralUtility::makeInstance(MetadataView::class);
69 69
 
70
-        return sprintf(
71
-            '<div class="container-fileInfo" style="font-size: 7pt; color: #777;">%s</div>',
72
-            $metadataView->render($this->file)
73
-        );
74
-    }
70
+		return sprintf(
71
+			'<div class="container-fileInfo" style="font-size: 7pt; color: #777;">%s</div>',
72
+			$metadataView->render($this->file)
73
+		);
74
+	}
75 75
 }
Please login to merge, or discard this patch.
Classes/Controller/AssetController.php 1 patch
Indentation   +309 added lines, -309 removed lines patch added patch discarded remove patch
@@ -47,313 +47,313 @@
 block discarded – undo
47 47
  */
48 48
 class AssetController extends ActionController
49 49
 {
50
-    /**
51
-     * @var string
52
-     */
53
-    protected $dataType = 'sys_file';
54
-
55
-    /**
56
-     * @throws StorageNotOnlineException
57
-     * @throws \InvalidArgumentException
58
-     * @throws NoSuchArgumentException
59
-     */
60
-    public function initializeAction()
61
-    {
62
-        $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
63
-        $pageRenderer->addInlineLanguageLabelFile('EXT:media/Resources/Private/Language/locallang.xlf');
64
-
65
-        // Configure property mapping to retrieve the file object.
66
-        if ($this->arguments->hasArgument('file')) {
67
-            /** @var FileConverter $typeConverter */
68
-            $typeConverter = GeneralUtility::makeInstance(FileConverter::class);
69
-
70
-            $propertyMappingConfiguration = $this->arguments->getArgument('file')->getPropertyMappingConfiguration();
71
-            $propertyMappingConfiguration->setTypeConverter($typeConverter);
72
-        }
73
-    }
74
-
75
-    /**
76
-     * Force download of the file.
77
-     *
78
-     * @param File $file
79
-     * @param bool $forceDownload
80
-     * @return bool|string
81
-     * @throws \RuntimeException
82
-     */
83
-    public function downloadAction(File $file, $forceDownload = false): ResponseInterface
84
-    {
85
-        if ($file->exists() && $file->getStorage()->isWithinFileMountBoundaries($file->getParentFolder())) {
86
-            // Emit signal before downloading the file.
87
-            $this->emitBeforeDownloadSignal($file);
88
-
89
-            // Read the file and dump it with the flag "forceDownload" set to true or false.
90
-            $file->getStorage()->streamFile($file, $forceDownload);
91
-
92
-            $result = true;
93
-        } else {
94
-            $result = 'Access denied!';
95
-        }
96
-
97
-        return $this->htmlResponse($result);
98
-    }
99
-
100
-    /**
101
-     * Handle file upload for a new file.
102
-     *
103
-     * @param string $combinedIdentifier
104
-     * @Extbase\Validate("\Fab\Media\Domain\Validator\StorageValidator", param="combinedIdentifier")
105
-     * @return string
106
-     */
107
-    public function createAction($combinedIdentifier): ResponseInterface
108
-    {
109
-        /** @var UploadedFileInterface $uploadedFile */
110
-        $uploadedFile = $this->handleUpload();
111
-        if (!is_object($uploadedFile)) {
112
-            return $this->htmlResponse(htmlspecialchars(json_encode($uploadedFile), ENT_NOQUOTES));
113
-        }
114
-
115
-        // Get the target folder.
116
-        if ($this->getMediaModule()->hasFolderTree()) {
117
-            $targetFolder = $this->getMediaModule()->getFolderForCombinedIdentifier($combinedIdentifier);
118
-        } else {
119
-            $storage = $this->getResourceFactory()->getStorageObjectFromCombinedIdentifier($combinedIdentifier);
120
-            $targetFolder = $this->getMediaModule()->getTargetFolderForUploadedFile($uploadedFile, $storage);
121
-        }
122
-
123
-        try {
124
-            $conflictMode = DuplicationBehavior::RENAME;
125
-            $fileName = $uploadedFile->getName();
126
-            $file = $targetFolder->addFile($uploadedFile->getFileWithAbsolutePath(), $fileName, $conflictMode);
127
-
128
-            // Run the indexer for extracting metadata.
129
-            $this->getMediaIndexer($file->getStorage())
130
-                ->extractMetadata($file)
131
-                ->applyDefaultCategories($file);
132
-
133
-            $response = array(
134
-                'success' => true,
135
-                'uid' => $file->getUid(),
136
-                'name' => $file->getName(),
137
-                'thumbnail' => $this->getThumbnailService($file)->create(),
138
-            );
139
-        } catch (UploadException $e) {
140
-            $response = array('error' => 'The upload has failed, no uploaded file found!');
141
-        } catch (InsufficientUserPermissionsException $e) {
142
-            $response = array('error' => 'You are not allowed to upload files!');
143
-        } catch (UploadSizeException $e) {
144
-            $response = array('error' => vsprintf('The uploaded file "%s" exceeds the size-limit', array($uploadedFile->getName())));
145
-        } catch (InsufficientFolderWritePermissionsException $e) {
146
-            $response = array('error' => vsprintf('Destination path "%s" was not within your mount points!', array($targetFolder->getIdentifier())));
147
-        } catch (IllegalFileExtensionException $e) {
148
-            $response = array('error' => vsprintf('Extension of file name "%s" is not allowed in "%s"!', array($uploadedFile->getName(), $targetFolder->getIdentifier())));
149
-        } catch (ExistingTargetFileNameException $e) {
150
-            $response = array('error' => vsprintf('No unique filename available in "%s"!', array($targetFolder->getIdentifier())));
151
-        } catch (\RuntimeException $e) {
152
-            $response = array('error' => vsprintf('Uploaded file could not be moved! Write-permission problem in "%s"?', array($targetFolder->getIdentifier())));
153
-        }
154
-
155
-        // to pass data through iframe you will need to encode all html tags
156
-        header("Content-Type: text/plain");
157
-        return $this->htmlResponse(htmlspecialchars(json_encode($response), ENT_NOQUOTES));
158
-    }
159
-
160
-    /**
161
-     * Handle file upload for an existing file.
162
-     *
163
-     * @param File $file
164
-     * @return string
165
-     * @throws \InvalidArgumentException
166
-     * @throws \RuntimeException
167
-     */
168
-    public function updateAction(File $file): ResponseInterface
169
-    {
170
-        $uploadedFile = $this->handleUpload();
171
-        if (!is_object($uploadedFile)) {
172
-            return $this->htmlResponse(htmlspecialchars(json_encode($uploadedFile), ENT_NOQUOTES));
173
-        }
174
-
175
-        /** @var $file File */
176
-        $targetFolder = $file->getStorage()->getFolder(dirname($file->getIdentifier()));
177
-
178
-        try {
179
-            $storage = $file->getStorage();
180
-            $storage->replaceFile($file, $uploadedFile->getFileWithAbsolutePath());
181
-
182
-            // Run the indexer for extracting metadata.
183
-            $this->getMediaIndexer($file->getStorage())
184
-                ->updateIndex($file)
185
-                ->extractMetadata($file);
186
-
187
-            // Clear cache on pages holding a reference to this file.
188
-            $this->getCacheService()->clearCache($file);
189
-
190
-            $response = array(
191
-                'success' => true,
192
-                'uid' => $file->getUid(),
193
-                'name' => $file->getName(),
194
-                'thumbnail' => $this->getThumbnailService($file)->create(),
195
-                'fileInfo' => $this->getMetadataView()->render($file),
196
-            );
197
-        } catch (UploadException $e) {
198
-            $response = array('error' => 'The upload has failed, no uploaded file found!');
199
-        } catch (InsufficientUserPermissionsException $e) {
200
-            $response = array('error' => 'You are not allowed to upload files!');
201
-        } catch (UploadSizeException $e) {
202
-            $response = array('error' => vsprintf('The uploaded file "%s" exceeds the size-limit', array($uploadedFile->getName())));
203
-        } catch (InsufficientFolderWritePermissionsException $e) {
204
-            $response = array('error' => vsprintf('Destination path "%s" was not within your mount points!', array($targetFolder->getIdentifier())));
205
-        } catch (IllegalFileExtensionException $e) {
206
-            $response = array('error' => vsprintf('Extension of file name "%s" is not allowed in "%s"!', array($uploadedFile->getName(), $targetFolder->getIdentifier())));
207
-        } catch (ExistingTargetFileNameException $e) {
208
-            $response = array('error' => vsprintf('No unique filename available in "%s"!', array($targetFolder->getIdentifier())));
209
-        } catch (\RuntimeException $e) {
210
-            $response = array('error' => vsprintf('Uploaded file could not be moved! Write-permission problem in "%s"?', array($targetFolder->getIdentifier())));
211
-        }
212
-
213
-        // to pass data through iframe you will need to encode all html tags
214
-        header("Content-Type: text/plain");
215
-        return $this->htmlResponse(htmlspecialchars(json_encode($response), ENT_NOQUOTES));
216
-    }
217
-
218
-    /**
219
-     * Returns an editing form for moving Files between storage.
220
-     *
221
-     * @param array $matches
222
-     * @throws \Exception
223
-     */
224
-    public function editStorageAction(array $matches = []): ResponseInterface
225
-    {
226
-        $this->view->assign('storages', $this->getMediaModule()->getAllowedStorages());
227
-        $this->view->assign('storageTitle', Tca::table('sys_file_storage')->getTitle());
228
-
229
-        $fieldName = 'storage';
230
-
231
-        // Instantiate the Matcher object according different rules.
232
-        $matcher = MatcherObjectFactory::getInstance()->getMatcher($matches, $this->dataType);
233
-
234
-        // Fetch objects via the Content Service.
235
-        $contentService = $this->getContentService()->findBy($matcher);
236
-
237
-        $fieldType = Tca::table($this->dataType)->field($fieldName)->getType();
238
-
239
-        $this->view->assign('fieldType', ucfirst($fieldType));
240
-        $this->view->assign('dataType', $this->dataType);
241
-        $this->view->assign('matches', $matches);
242
-        $this->view->assign('fieldNameAndPath', $fieldName);
243
-        $this->view->assign('numberOfObjects', $contentService->getNumberOfObjects());
244
-        $this->view->assign('editWholeSelection', empty($matches['uid'])); // necessary??
245
-        return $this->htmlResponse();
246
-    }
247
-
248
-    /**
249
-     * Handle file upload.
250
-     *
251
-     * @return UploadedFileInterface|array
252
-     * @throws \InvalidArgumentException
253
-     */
254
-    protected function handleUpload()
255
-    {
256
-        /** @var $uploadManager UploadManager */
257
-        $uploadManager = GeneralUtility::makeInstance(UploadManager::class);
258
-
259
-        try {
260
-            /** @var $result \Fab\Media\FileUpload\UploadedFileInterface */
261
-            $result = $uploadManager->handleUpload();
262
-        } catch (\Exception $e) {
263
-            $result = array('error' => $e->getMessage());
264
-        }
265
-
266
-        return $result;
267
-    }
268
-
269
-    /**
270
-     * @return MetadataView
271
-     * @throws \InvalidArgumentException
272
-     */
273
-    protected function getMetadataView()
274
-    {
275
-        return GeneralUtility::makeInstance(MetadataView::class);
276
-    }
277
-
278
-    /**
279
-     * @param File $file
280
-     * @return ThumbnailService
281
-     * @throws InvalidKeyInArrayException
282
-     * @throws \InvalidArgumentException
283
-     */
284
-    protected function getThumbnailService(File $file)
285
-    {
286
-        /** @var $thumbnailService ThumbnailService */
287
-        $thumbnailService = GeneralUtility::makeInstance(ThumbnailService::class, $file);
288
-        $thumbnailService->setAppendTimeStamp(true)
289
-            ->setOutputType(ThumbnailInterface::OUTPUT_IMAGE_WRAPPED);
290
-        return $thumbnailService;
291
-    }
292
-
293
-    /**
294
-     * Get the instance of the Indexer service to update the metadata of the file.
295
-     *
296
-     * @param int|ResourceStorage $storage
297
-     * @return MediaIndexer
298
-     * @throws \InvalidArgumentException
299
-     */
300
-    protected function getMediaIndexer($storage)
301
-    {
302
-        return GeneralUtility::makeInstance(MediaIndexer::class, $storage);
303
-    }
304
-
305
-    /**
306
-     * @return CacheService
307
-     * @throws \InvalidArgumentException
308
-     */
309
-    protected function getCacheService()
310
-    {
311
-        return GeneralUtility::makeInstance(CacheService::class);
312
-    }
313
-
314
-    /**
315
-     * Signal that is emitted before a file is downloaded.
316
-     *
317
-     * @param File $file
318
-     * @return void
319
-     * @throws InvalidSlotReturnException
320
-     * @throws InvalidSlotException
321
-     */
322
-    protected function emitBeforeDownloadSignal(File $file)
323
-    {
324
-        $this->getSignalSlotDispatcher()->dispatch('Fab\Media\Controller\Backend\AssetController', 'beforeDownload', array($file));
325
-    }
326
-
327
-    /**
328
-     * Get the SignalSlot dispatcher.
329
-     *
330
-     * @return Dispatcher
331
-     */
332
-    protected function getSignalSlotDispatcher()
333
-    {
334
-        return GeneralUtility::makeInstance(Dispatcher::class);
335
-    }
336
-
337
-    /**
338
-     * @return ContentService
339
-     * @throws \InvalidArgumentException
340
-     */
341
-    protected function getContentService()
342
-    {
343
-        return GeneralUtility::makeInstance(ContentService::class, $this->dataType);
344
-    }
345
-
346
-    /**
347
-     * @return MediaModule|object
348
-     * @throws \InvalidArgumentException
349
-     */
350
-    protected function getMediaModule()
351
-    {
352
-        return GeneralUtility::makeInstance(MediaModule::class);
353
-    }
354
-
355
-    protected function getResourceFactory(): ResourceFactory
356
-    {
357
-        return GeneralUtility::makeInstance(ResourceFactory::class);
358
-    }
50
+	/**
51
+	 * @var string
52
+	 */
53
+	protected $dataType = 'sys_file';
54
+
55
+	/**
56
+	 * @throws StorageNotOnlineException
57
+	 * @throws \InvalidArgumentException
58
+	 * @throws NoSuchArgumentException
59
+	 */
60
+	public function initializeAction()
61
+	{
62
+		$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
63
+		$pageRenderer->addInlineLanguageLabelFile('EXT:media/Resources/Private/Language/locallang.xlf');
64
+
65
+		// Configure property mapping to retrieve the file object.
66
+		if ($this->arguments->hasArgument('file')) {
67
+			/** @var FileConverter $typeConverter */
68
+			$typeConverter = GeneralUtility::makeInstance(FileConverter::class);
69
+
70
+			$propertyMappingConfiguration = $this->arguments->getArgument('file')->getPropertyMappingConfiguration();
71
+			$propertyMappingConfiguration->setTypeConverter($typeConverter);
72
+		}
73
+	}
74
+
75
+	/**
76
+	 * Force download of the file.
77
+	 *
78
+	 * @param File $file
79
+	 * @param bool $forceDownload
80
+	 * @return bool|string
81
+	 * @throws \RuntimeException
82
+	 */
83
+	public function downloadAction(File $file, $forceDownload = false): ResponseInterface
84
+	{
85
+		if ($file->exists() && $file->getStorage()->isWithinFileMountBoundaries($file->getParentFolder())) {
86
+			// Emit signal before downloading the file.
87
+			$this->emitBeforeDownloadSignal($file);
88
+
89
+			// Read the file and dump it with the flag "forceDownload" set to true or false.
90
+			$file->getStorage()->streamFile($file, $forceDownload);
91
+
92
+			$result = true;
93
+		} else {
94
+			$result = 'Access denied!';
95
+		}
96
+
97
+		return $this->htmlResponse($result);
98
+	}
99
+
100
+	/**
101
+	 * Handle file upload for a new file.
102
+	 *
103
+	 * @param string $combinedIdentifier
104
+	 * @Extbase\Validate("\Fab\Media\Domain\Validator\StorageValidator", param="combinedIdentifier")
105
+	 * @return string
106
+	 */
107
+	public function createAction($combinedIdentifier): ResponseInterface
108
+	{
109
+		/** @var UploadedFileInterface $uploadedFile */
110
+		$uploadedFile = $this->handleUpload();
111
+		if (!is_object($uploadedFile)) {
112
+			return $this->htmlResponse(htmlspecialchars(json_encode($uploadedFile), ENT_NOQUOTES));
113
+		}
114
+
115
+		// Get the target folder.
116
+		if ($this->getMediaModule()->hasFolderTree()) {
117
+			$targetFolder = $this->getMediaModule()->getFolderForCombinedIdentifier($combinedIdentifier);
118
+		} else {
119
+			$storage = $this->getResourceFactory()->getStorageObjectFromCombinedIdentifier($combinedIdentifier);
120
+			$targetFolder = $this->getMediaModule()->getTargetFolderForUploadedFile($uploadedFile, $storage);
121
+		}
122
+
123
+		try {
124
+			$conflictMode = DuplicationBehavior::RENAME;
125
+			$fileName = $uploadedFile->getName();
126
+			$file = $targetFolder->addFile($uploadedFile->getFileWithAbsolutePath(), $fileName, $conflictMode);
127
+
128
+			// Run the indexer for extracting metadata.
129
+			$this->getMediaIndexer($file->getStorage())
130
+				->extractMetadata($file)
131
+				->applyDefaultCategories($file);
132
+
133
+			$response = array(
134
+				'success' => true,
135
+				'uid' => $file->getUid(),
136
+				'name' => $file->getName(),
137
+				'thumbnail' => $this->getThumbnailService($file)->create(),
138
+			);
139
+		} catch (UploadException $e) {
140
+			$response = array('error' => 'The upload has failed, no uploaded file found!');
141
+		} catch (InsufficientUserPermissionsException $e) {
142
+			$response = array('error' => 'You are not allowed to upload files!');
143
+		} catch (UploadSizeException $e) {
144
+			$response = array('error' => vsprintf('The uploaded file "%s" exceeds the size-limit', array($uploadedFile->getName())));
145
+		} catch (InsufficientFolderWritePermissionsException $e) {
146
+			$response = array('error' => vsprintf('Destination path "%s" was not within your mount points!', array($targetFolder->getIdentifier())));
147
+		} catch (IllegalFileExtensionException $e) {
148
+			$response = array('error' => vsprintf('Extension of file name "%s" is not allowed in "%s"!', array($uploadedFile->getName(), $targetFolder->getIdentifier())));
149
+		} catch (ExistingTargetFileNameException $e) {
150
+			$response = array('error' => vsprintf('No unique filename available in "%s"!', array($targetFolder->getIdentifier())));
151
+		} catch (\RuntimeException $e) {
152
+			$response = array('error' => vsprintf('Uploaded file could not be moved! Write-permission problem in "%s"?', array($targetFolder->getIdentifier())));
153
+		}
154
+
155
+		// to pass data through iframe you will need to encode all html tags
156
+		header("Content-Type: text/plain");
157
+		return $this->htmlResponse(htmlspecialchars(json_encode($response), ENT_NOQUOTES));
158
+	}
159
+
160
+	/**
161
+	 * Handle file upload for an existing file.
162
+	 *
163
+	 * @param File $file
164
+	 * @return string
165
+	 * @throws \InvalidArgumentException
166
+	 * @throws \RuntimeException
167
+	 */
168
+	public function updateAction(File $file): ResponseInterface
169
+	{
170
+		$uploadedFile = $this->handleUpload();
171
+		if (!is_object($uploadedFile)) {
172
+			return $this->htmlResponse(htmlspecialchars(json_encode($uploadedFile), ENT_NOQUOTES));
173
+		}
174
+
175
+		/** @var $file File */
176
+		$targetFolder = $file->getStorage()->getFolder(dirname($file->getIdentifier()));
177
+
178
+		try {
179
+			$storage = $file->getStorage();
180
+			$storage->replaceFile($file, $uploadedFile->getFileWithAbsolutePath());
181
+
182
+			// Run the indexer for extracting metadata.
183
+			$this->getMediaIndexer($file->getStorage())
184
+				->updateIndex($file)
185
+				->extractMetadata($file);
186
+
187
+			// Clear cache on pages holding a reference to this file.
188
+			$this->getCacheService()->clearCache($file);
189
+
190
+			$response = array(
191
+				'success' => true,
192
+				'uid' => $file->getUid(),
193
+				'name' => $file->getName(),
194
+				'thumbnail' => $this->getThumbnailService($file)->create(),
195
+				'fileInfo' => $this->getMetadataView()->render($file),
196
+			);
197
+		} catch (UploadException $e) {
198
+			$response = array('error' => 'The upload has failed, no uploaded file found!');
199
+		} catch (InsufficientUserPermissionsException $e) {
200
+			$response = array('error' => 'You are not allowed to upload files!');
201
+		} catch (UploadSizeException $e) {
202
+			$response = array('error' => vsprintf('The uploaded file "%s" exceeds the size-limit', array($uploadedFile->getName())));
203
+		} catch (InsufficientFolderWritePermissionsException $e) {
204
+			$response = array('error' => vsprintf('Destination path "%s" was not within your mount points!', array($targetFolder->getIdentifier())));
205
+		} catch (IllegalFileExtensionException $e) {
206
+			$response = array('error' => vsprintf('Extension of file name "%s" is not allowed in "%s"!', array($uploadedFile->getName(), $targetFolder->getIdentifier())));
207
+		} catch (ExistingTargetFileNameException $e) {
208
+			$response = array('error' => vsprintf('No unique filename available in "%s"!', array($targetFolder->getIdentifier())));
209
+		} catch (\RuntimeException $e) {
210
+			$response = array('error' => vsprintf('Uploaded file could not be moved! Write-permission problem in "%s"?', array($targetFolder->getIdentifier())));
211
+		}
212
+
213
+		// to pass data through iframe you will need to encode all html tags
214
+		header("Content-Type: text/plain");
215
+		return $this->htmlResponse(htmlspecialchars(json_encode($response), ENT_NOQUOTES));
216
+	}
217
+
218
+	/**
219
+	 * Returns an editing form for moving Files between storage.
220
+	 *
221
+	 * @param array $matches
222
+	 * @throws \Exception
223
+	 */
224
+	public function editStorageAction(array $matches = []): ResponseInterface
225
+	{
226
+		$this->view->assign('storages', $this->getMediaModule()->getAllowedStorages());
227
+		$this->view->assign('storageTitle', Tca::table('sys_file_storage')->getTitle());
228
+
229
+		$fieldName = 'storage';
230
+
231
+		// Instantiate the Matcher object according different rules.
232
+		$matcher = MatcherObjectFactory::getInstance()->getMatcher($matches, $this->dataType);
233
+
234
+		// Fetch objects via the Content Service.
235
+		$contentService = $this->getContentService()->findBy($matcher);
236
+
237
+		$fieldType = Tca::table($this->dataType)->field($fieldName)->getType();
238
+
239
+		$this->view->assign('fieldType', ucfirst($fieldType));
240
+		$this->view->assign('dataType', $this->dataType);
241
+		$this->view->assign('matches', $matches);
242
+		$this->view->assign('fieldNameAndPath', $fieldName);
243
+		$this->view->assign('numberOfObjects', $contentService->getNumberOfObjects());
244
+		$this->view->assign('editWholeSelection', empty($matches['uid'])); // necessary??
245
+		return $this->htmlResponse();
246
+	}
247
+
248
+	/**
249
+	 * Handle file upload.
250
+	 *
251
+	 * @return UploadedFileInterface|array
252
+	 * @throws \InvalidArgumentException
253
+	 */
254
+	protected function handleUpload()
255
+	{
256
+		/** @var $uploadManager UploadManager */
257
+		$uploadManager = GeneralUtility::makeInstance(UploadManager::class);
258
+
259
+		try {
260
+			/** @var $result \Fab\Media\FileUpload\UploadedFileInterface */
261
+			$result = $uploadManager->handleUpload();
262
+		} catch (\Exception $e) {
263
+			$result = array('error' => $e->getMessage());
264
+		}
265
+
266
+		return $result;
267
+	}
268
+
269
+	/**
270
+	 * @return MetadataView
271
+	 * @throws \InvalidArgumentException
272
+	 */
273
+	protected function getMetadataView()
274
+	{
275
+		return GeneralUtility::makeInstance(MetadataView::class);
276
+	}
277
+
278
+	/**
279
+	 * @param File $file
280
+	 * @return ThumbnailService
281
+	 * @throws InvalidKeyInArrayException
282
+	 * @throws \InvalidArgumentException
283
+	 */
284
+	protected function getThumbnailService(File $file)
285
+	{
286
+		/** @var $thumbnailService ThumbnailService */
287
+		$thumbnailService = GeneralUtility::makeInstance(ThumbnailService::class, $file);
288
+		$thumbnailService->setAppendTimeStamp(true)
289
+			->setOutputType(ThumbnailInterface::OUTPUT_IMAGE_WRAPPED);
290
+		return $thumbnailService;
291
+	}
292
+
293
+	/**
294
+	 * Get the instance of the Indexer service to update the metadata of the file.
295
+	 *
296
+	 * @param int|ResourceStorage $storage
297
+	 * @return MediaIndexer
298
+	 * @throws \InvalidArgumentException
299
+	 */
300
+	protected function getMediaIndexer($storage)
301
+	{
302
+		return GeneralUtility::makeInstance(MediaIndexer::class, $storage);
303
+	}
304
+
305
+	/**
306
+	 * @return CacheService
307
+	 * @throws \InvalidArgumentException
308
+	 */
309
+	protected function getCacheService()
310
+	{
311
+		return GeneralUtility::makeInstance(CacheService::class);
312
+	}
313
+
314
+	/**
315
+	 * Signal that is emitted before a file is downloaded.
316
+	 *
317
+	 * @param File $file
318
+	 * @return void
319
+	 * @throws InvalidSlotReturnException
320
+	 * @throws InvalidSlotException
321
+	 */
322
+	protected function emitBeforeDownloadSignal(File $file)
323
+	{
324
+		$this->getSignalSlotDispatcher()->dispatch('Fab\Media\Controller\Backend\AssetController', 'beforeDownload', array($file));
325
+	}
326
+
327
+	/**
328
+	 * Get the SignalSlot dispatcher.
329
+	 *
330
+	 * @return Dispatcher
331
+	 */
332
+	protected function getSignalSlotDispatcher()
333
+	{
334
+		return GeneralUtility::makeInstance(Dispatcher::class);
335
+	}
336
+
337
+	/**
338
+	 * @return ContentService
339
+	 * @throws \InvalidArgumentException
340
+	 */
341
+	protected function getContentService()
342
+	{
343
+		return GeneralUtility::makeInstance(ContentService::class, $this->dataType);
344
+	}
345
+
346
+	/**
347
+	 * @return MediaModule|object
348
+	 * @throws \InvalidArgumentException
349
+	 */
350
+	protected function getMediaModule()
351
+	{
352
+		return GeneralUtility::makeInstance(MediaModule::class);
353
+	}
354
+
355
+	protected function getResourceFactory(): ResourceFactory
356
+	{
357
+		return GeneralUtility::makeInstance(ResourceFactory::class);
358
+	}
359 359
 }
Please login to merge, or discard this patch.
Classes/Grid/PreviewRenderer.php 1 patch
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -23,81 +23,81 @@
 block discarded – undo
23 23
  */
24 24
 class PreviewRenderer extends ColumnRendererAbstract
25 25
 {
26
-    /**
27
-     * Render a preview of a file in the Grid.
28
-     *
29
-     * @return string
30
-     */
31
-    public function render()
32
-    {
33
-        $file = $this->getFileConverter()->convert($this->object);
26
+	/**
27
+	 * Render a preview of a file in the Grid.
28
+	 *
29
+	 * @return string
30
+	 */
31
+	public function render()
32
+	{
33
+		$file = $this->getFileConverter()->convert($this->object);
34 34
 
35
-        $uri = false;
36
-        $appendTime = true;
35
+		$uri = false;
36
+		$appendTime = true;
37 37
 
38
-        // Compute image-editor or link-creator URL.
39
-        if ($this->getModuleLoader()->hasPlugin('imageEditor')) {
40
-            $appendTime = false;
41
-            $uri = $this->getPluginUri('ImageEditor');
42
-        } elseif ($this->getModuleLoader()->hasPlugin('linkCreator')) {
43
-            $appendTime = false;
44
-            $uri = $this->getPluginUri('LinkCreator');
45
-        }
38
+		// Compute image-editor or link-creator URL.
39
+		if ($this->getModuleLoader()->hasPlugin('imageEditor')) {
40
+			$appendTime = false;
41
+			$uri = $this->getPluginUri('ImageEditor');
42
+		} elseif ($this->getModuleLoader()->hasPlugin('linkCreator')) {
43
+			$appendTime = false;
44
+			$uri = $this->getPluginUri('LinkCreator');
45
+		}
46 46
 
47
-        $result = $this->getThumbnailService($file)
48
-            ->setOutputType(ThumbnailInterface::OUTPUT_IMAGE_WRAPPED)
49
-            ->setAppendTimeStamp($appendTime)
50
-            ->setTarget(ThumbnailInterface::TARGET_BLANK)
51
-            ->setAnchorUri($uri)
52
-            ->setAttributes([])
53
-            ->create();
47
+		$result = $this->getThumbnailService($file)
48
+			->setOutputType(ThumbnailInterface::OUTPUT_IMAGE_WRAPPED)
49
+			->setAppendTimeStamp($appendTime)
50
+			->setTarget(ThumbnailInterface::TARGET_BLANK)
51
+			->setAnchorUri($uri)
52
+			->setAttributes([])
53
+			->create();
54 54
 
55
-        // Add file info
56
-        $result .= sprintf(
57
-            '<div class="container-fileInfo" style="font-size: 7pt; color: #777;">%s</div>',
58
-            $this->getMetadataView()->render($file)
59
-        );
60
-        return $result;
61
-    }
55
+		// Add file info
56
+		$result .= sprintf(
57
+			'<div class="container-fileInfo" style="font-size: 7pt; color: #777;">%s</div>',
58
+			$this->getMetadataView()->render($file)
59
+		);
60
+		return $result;
61
+	}
62 62
 
63
-    /**
64
-     * @param File $file
65
-     * @return ThumbnailService|object
66
-     */
67
-    protected function getThumbnailService(File $file)
68
-    {
69
-        return GeneralUtility::makeInstance(ThumbnailService::class, $file);
70
-    }
63
+	/**
64
+	 * @param File $file
65
+	 * @return ThumbnailService|object
66
+	 */
67
+	protected function getThumbnailService(File $file)
68
+	{
69
+		return GeneralUtility::makeInstance(ThumbnailService::class, $file);
70
+	}
71 71
 
72
-    /**
73
-     * @return MetadataView|object
74
-     */
75
-    protected function getMetadataView()
76
-    {
77
-        return GeneralUtility::makeInstance(MetadataView::class);
78
-    }
72
+	/**
73
+	 * @return MetadataView|object
74
+	 */
75
+	protected function getMetadataView()
76
+	{
77
+		return GeneralUtility::makeInstance(MetadataView::class);
78
+	}
79 79
 
80
-    /**
81
-     * @param string $controllerName
82
-     * @return string
83
-     */
84
-    protected function getPluginUri($controllerName)
85
-    {
86
-        $urlParameters = array(
87
-            MediaModule::getParameterPrefix() => array(
88
-                'controller' => $controllerName,
89
-                'action' => 'show',
90
-                'file' => $this->object->getUid(),
91
-            ),
92
-        );
93
-        return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters);
94
-    }
80
+	/**
81
+	 * @param string $controllerName
82
+	 * @return string
83
+	 */
84
+	protected function getPluginUri($controllerName)
85
+	{
86
+		$urlParameters = array(
87
+			MediaModule::getParameterPrefix() => array(
88
+				'controller' => $controllerName,
89
+				'action' => 'show',
90
+				'file' => $this->object->getUid(),
91
+			),
92
+		);
93
+		return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters);
94
+	}
95 95
 
96
-    /**
97
-     * @return ContentToFileConverter|object
98
-     */
99
-    protected function getFileConverter()
100
-    {
101
-        return GeneralUtility::makeInstance(ContentToFileConverter::class);
102
-    }
96
+	/**
97
+	 * @return ContentToFileConverter|object
98
+	 */
99
+	protected function getFileConverter()
100
+	{
101
+		return GeneralUtility::makeInstance(ContentToFileConverter::class);
102
+	}
103 103
 }
Please login to merge, or discard this patch.