Completed
Push — master ( ad447f...f2215d )
by Fabien
03:37 queued 48s
created
Classes/Grid/MetadataRenderer.php 1 patch
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -19,78 +19,78 @@
 block discarded – undo
19 19
 class MetadataRenderer extends ColumnRendererAbstract
20 20
 {
21 21
 
22
-    /**
23
-     * Renders a configurable metadata property of a file in the Grid.
24
-     *
25
-     * @throws \Exception
26
-     * @return string
27
-     */
28
-    public function render()
29
-    {
22
+	/**
23
+	 * Renders a configurable metadata property of a file in the Grid.
24
+	 *
25
+	 * @throws \Exception
26
+	 * @return string
27
+	 */
28
+	public function render()
29
+	{
30 30
 
31
-        if (empty($this->gridRendererConfiguration['property'])) {
32
-            throw new \Exception('Missing property value for Grid Renderer Metadata', 1390391042);
33
-        }
31
+		if (empty($this->gridRendererConfiguration['property'])) {
32
+			throw new \Exception('Missing property value for Grid Renderer Metadata', 1390391042);
33
+		}
34 34
 
35
-        $file = $this->getFileConverter()->convert($this->object);
36
-        $propertyName = $this->gridRendererConfiguration['property'];
35
+		$file = $this->getFileConverter()->convert($this->object);
36
+		$propertyName = $this->gridRendererConfiguration['property'];
37 37
 
38
-        if ($propertyName === 'uid') {
39
-            $metadata = $file->_getMetaData();
40
-            $result = $metadata['uid']; // make an exception here to retrieve the uid of the metadata.
41
-        } else {
42
-            $result = $file->getProperty($propertyName);
43
-        }
38
+		if ($propertyName === 'uid') {
39
+			$metadata = $file->_getMetaData();
40
+			$result = $metadata['uid']; // make an exception here to retrieve the uid of the metadata.
41
+		} else {
42
+			$result = $file->getProperty($propertyName);
43
+		}
44 44
 
45
-        // Avoid bad surprise, converts characters to HTML.
46
-        $fieldType = Tca::table('sys_file_metadata')->field($propertyName)->getType();
47
-        if ($fieldType !== FieldType::TEXTAREA) {
48
-            $result = htmlentities($result);
49
-        } elseif ($fieldType === FieldType::TEXTAREA && !$this->isClean($result)) {
50
-            $result = htmlentities($result);
51
-        } elseif ($fieldType === FieldType::TEXTAREA && !$this->hasHtml($result)) {
52
-            $result = nl2br($result);
53
-        }
45
+		// Avoid bad surprise, converts characters to HTML.
46
+		$fieldType = Tca::table('sys_file_metadata')->field($propertyName)->getType();
47
+		if ($fieldType !== FieldType::TEXTAREA) {
48
+			$result = htmlentities($result);
49
+		} elseif ($fieldType === FieldType::TEXTAREA && !$this->isClean($result)) {
50
+			$result = htmlentities($result);
51
+		} elseif ($fieldType === FieldType::TEXTAREA && !$this->hasHtml($result)) {
52
+			$result = nl2br($result);
53
+		}
54 54
 
55
-        return $result;
56
-    }
55
+		return $result;
56
+	}
57 57
 
58
-    /**
59
-     * Check whether a string contains HTML tags.
60
-     *
61
-     * @param string $content the content to be analyzed
62
-     * @return boolean
63
-     */
64
-    protected function hasHtml($content)
65
-    {
66
-        $result = false;
58
+	/**
59
+	 * Check whether a string contains HTML tags.
60
+	 *
61
+	 * @param string $content the content to be analyzed
62
+	 * @return boolean
63
+	 */
64
+	protected function hasHtml($content)
65
+	{
66
+		$result = false;
67 67
 
68
-        // We compare the length of the string with html tags and without html tags.
69
-        if (strlen($content) != strlen(strip_tags($content))) {
70
-            $result = true;
71
-        }
72
-        return $result;
73
-    }
68
+		// We compare the length of the string with html tags and without html tags.
69
+		if (strlen($content) != strlen(strip_tags($content))) {
70
+			$result = true;
71
+		}
72
+		return $result;
73
+	}
74 74
 
75
-    /**
76
-     * Check whether a string contains potential XSS
77
-     *
78
-     * @param string $content the content to be analyzed
79
-     * @return boolean
80
-     */
81
-    protected function isClean($content)
82
-    {
75
+	/**
76
+	 * Check whether a string contains potential XSS
77
+	 *
78
+	 * @param string $content the content to be analyzed
79
+	 * @return boolean
80
+	 */
81
+	protected function isClean($content)
82
+	{
83 83
 
84
-        // @todo implement me!
85
-        $result = true;
86
-        return $result;
87
-    }
84
+		// @todo implement me!
85
+		$result = true;
86
+		return $result;
87
+	}
88 88
 
89
-    /**
90
-     * @return \Fab\Media\TypeConverter\ContentToFileConverter|object
91
-     */
92
-    protected function getFileConverter()
93
-    {
94
-        return GeneralUtility::makeInstance(\Fab\Media\TypeConverter\ContentToFileConverter::class);
95
-    }
89
+	/**
90
+	 * @return \Fab\Media\TypeConverter\ContentToFileConverter|object
91
+	 */
92
+	protected function getFileConverter()
93
+	{
94
+		return GeneralUtility::makeInstance(\Fab\Media\TypeConverter\ContentToFileConverter::class);
95
+	}
96 96
 }
Please login to merge, or discard this patch.
Classes/Grid/PreviewRenderer.php 1 patch
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -21,82 +21,82 @@
 block discarded – undo
21 21
 class PreviewRenderer extends ColumnRendererAbstract
22 22
 {
23 23
 
24
-    /**
25
-     * Render a preview of a file in the Grid.
26
-     *
27
-     * @return string
28
-     */
29
-    public function render()
30
-    {
24
+	/**
25
+	 * Render a preview of a file in the Grid.
26
+	 *
27
+	 * @return string
28
+	 */
29
+	public function render()
30
+	{
31 31
 
32
-        $file = $this->getFileConverter()->convert($this->object);
32
+		$file = $this->getFileConverter()->convert($this->object);
33 33
 
34
-        $uri = false;
35
-        $appendTime = true;
34
+		$uri = false;
35
+		$appendTime = true;
36 36
 
37
-        // Compute image-editor or link-creator URL.
38
-        if ($this->getModuleLoader()->hasPlugin('imageEditor')) {
39
-            $appendTime = false;
40
-            $uri = $this->getPluginUri('ImageEditor');
41
-        } elseif ($this->getModuleLoader()->hasPlugin('linkCreator')) {
42
-            $appendTime = false;
43
-            $uri = $this->getPluginUri('LinkCreator');
44
-        }
37
+		// Compute image-editor or link-creator URL.
38
+		if ($this->getModuleLoader()->hasPlugin('imageEditor')) {
39
+			$appendTime = false;
40
+			$uri = $this->getPluginUri('ImageEditor');
41
+		} elseif ($this->getModuleLoader()->hasPlugin('linkCreator')) {
42
+			$appendTime = false;
43
+			$uri = $this->getPluginUri('LinkCreator');
44
+		}
45 45
 
46
-        $result = $this->getThumbnailService($file)
47
-            ->setOutputType(ThumbnailInterface::OUTPUT_IMAGE_WRAPPED)
48
-            ->setAppendTimeStamp($appendTime)
49
-            ->setTarget(ThumbnailInterface::TARGET_BLANK)
50
-            ->setAnchorUri($uri)
51
-            ->setAttributes([])
52
-            ->create();
46
+		$result = $this->getThumbnailService($file)
47
+			->setOutputType(ThumbnailInterface::OUTPUT_IMAGE_WRAPPED)
48
+			->setAppendTimeStamp($appendTime)
49
+			->setTarget(ThumbnailInterface::TARGET_BLANK)
50
+			->setAnchorUri($uri)
51
+			->setAttributes([])
52
+			->create();
53 53
 
54
-        // Add file info
55
-        $result .= sprintf('<div class="container-fileInfo" style="font-size: 7pt; color: #777;">%s</div>',
56
-            $this->getMetadataViewHelper()->render($file)
57
-        );
58
-        return $result;
59
-    }
54
+		// Add file info
55
+		$result .= sprintf('<div class="container-fileInfo" style="font-size: 7pt; color: #777;">%s</div>',
56
+			$this->getMetadataViewHelper()->render($file)
57
+		);
58
+		return $result;
59
+	}
60 60
 
61
-    /**
62
-     * @param File $file
63
-     * @return \Fab\Media\Thumbnail\ThumbnailService|object
64
-     */
65
-    protected function getThumbnailService(File $file)
66
-    {
67
-        return GeneralUtility::makeInstance(\Fab\Media\Thumbnail\ThumbnailService::class, $file);
68
-    }
61
+	/**
62
+	 * @param File $file
63
+	 * @return \Fab\Media\Thumbnail\ThumbnailService|object
64
+	 */
65
+	protected function getThumbnailService(File $file)
66
+	{
67
+		return GeneralUtility::makeInstance(\Fab\Media\Thumbnail\ThumbnailService::class, $file);
68
+	}
69 69
 
70
-    /**
71
-     * @return \Fab\Media\ViewHelpers\MetadataViewHelper|object
72
-     */
73
-    protected function getMetadataViewHelper()
74
-    {
75
-        return GeneralUtility::makeInstance(\Fab\Media\ViewHelpers\MetadataViewHelper::class);
76
-    }
70
+	/**
71
+	 * @return \Fab\Media\ViewHelpers\MetadataViewHelper|object
72
+	 */
73
+	protected function getMetadataViewHelper()
74
+	{
75
+		return GeneralUtility::makeInstance(\Fab\Media\ViewHelpers\MetadataViewHelper::class);
76
+	}
77 77
 
78
-    /**
79
-     * @param string $controllerName
80
-     * @return string
81
-     */
82
-    protected function getPluginUri($controllerName)
83
-    {
84
-        $urlParameters = array(
85
-            MediaModule::getParameterPrefix() => array(
86
-                'controller' => $controllerName,
87
-                'action' => 'show',
88
-                'file' => $this->object->getUid(),
89
-            ),
90
-        );
91
-        return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters);
92
-    }
78
+	/**
79
+	 * @param string $controllerName
80
+	 * @return string
81
+	 */
82
+	protected function getPluginUri($controllerName)
83
+	{
84
+		$urlParameters = array(
85
+			MediaModule::getParameterPrefix() => array(
86
+				'controller' => $controllerName,
87
+				'action' => 'show',
88
+				'file' => $this->object->getUid(),
89
+			),
90
+		);
91
+		return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters);
92
+	}
93 93
 
94
-    /**
95
-     * @return \Fab\Media\TypeConverter\ContentToFileConverter|object
96
-     */
97
-    protected function getFileConverter()
98
-    {
99
-        return GeneralUtility::makeInstance(\Fab\Media\TypeConverter\ContentToFileConverter::class);
100
-    }
94
+	/**
95
+	 * @return \Fab\Media\TypeConverter\ContentToFileConverter|object
96
+	 */
97
+	protected function getFileConverter()
98
+	{
99
+		return GeneralUtility::makeInstance(\Fab\Media\TypeConverter\ContentToFileConverter::class);
100
+	}
101 101
 
102 102
 }
Please login to merge, or discard this patch.
Classes/Hook/FileUploadHook.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -19,40 +19,40 @@
 block discarded – undo
19 19
 class FileUploadHook implements ExtendedFileUtilityProcessDataHookInterface
20 20
 {
21 21
 
22
-    /**
23
-     * @param string $action The action
24
-     * @param array $cmdArr The parameter sent to the action handler
25
-     * @param array $result The results of all calls to the action handler
26
-     * @param ExtendedFileUtility $pObj The parent object
27
-     * @return void
28
-     */
29
-    public function processData_postProcessAction($action, array $cmdArr, array $result, ExtendedFileUtility $pObj)
30
-    {
31
-        if ($action === 'upload') {
32
-            /** @var \TYPO3\CMS\Core\Resource\File[] $files */
33
-            $files = array_pop($result);
34
-            if (!is_array($files)) {
35
-                return;
36
-            }
22
+	/**
23
+	 * @param string $action The action
24
+	 * @param array $cmdArr The parameter sent to the action handler
25
+	 * @param array $result The results of all calls to the action handler
26
+	 * @param ExtendedFileUtility $pObj The parent object
27
+	 * @return void
28
+	 */
29
+	public function processData_postProcessAction($action, array $cmdArr, array $result, ExtendedFileUtility $pObj)
30
+	{
31
+		if ($action === 'upload') {
32
+			/** @var \TYPO3\CMS\Core\Resource\File[] $files */
33
+			$files = array_pop($result);
34
+			if (!is_array($files)) {
35
+				return;
36
+			}
37 37
 
38
-            foreach ($files as $file) {
39
-                // Run the indexer for extracting metadata.
40
-                $this->getMediaIndexer($file->getStorage())
41
-                    ->extractMetadata($file)
42
-                    ->applyDefaultCategories($file);
43
-            }
44
-        }
45
-    }
38
+			foreach ($files as $file) {
39
+				// Run the indexer for extracting metadata.
40
+				$this->getMediaIndexer($file->getStorage())
41
+					->extractMetadata($file)
42
+					->applyDefaultCategories($file);
43
+			}
44
+		}
45
+	}
46 46
 
47
-    /**
48
-     * Get the instance of the Indexer service to update the metadata of the file.
49
-     *
50
-     * @param ResourceStorage $storage
51
-     * @return \Fab\Media\Index\MediaIndexer|object
52
-     */
53
-    protected function getMediaIndexer($storage)
54
-    {
55
-        return GeneralUtility::makeInstance(\Fab\Media\Index\MediaIndexer::class, $storage);
56
-    }
47
+	/**
48
+	 * Get the instance of the Indexer service to update the metadata of the file.
49
+	 *
50
+	 * @param ResourceStorage $storage
51
+	 * @return \Fab\Media\Index\MediaIndexer|object
52
+	 */
53
+	protected function getMediaIndexer($storage)
54
+	{
55
+		return GeneralUtility::makeInstance(\Fab\Media\Index\MediaIndexer::class, $storage);
56
+	}
57 57
 
58 58
 }
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
@@ -41,314 +41,314 @@
 block discarded – undo
41 41
 class AssetController extends ActionController
42 42
 {
43 43
 
44
-    /**
45
-     * @var string
46
-     */
47
-    protected $dataType = 'sys_file';
48
-
49
-    /**
50
-     * @throws \Fab\Media\Exception\StorageNotOnlineException
51
-     * @throws \InvalidArgumentException
52
-     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException
53
-     */
54
-    public function initializeAction()
55
-    {
56
-        $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
57
-        $pageRenderer->addInlineLanguageLabelFile('EXT:media/Resources/Private/Language/locallang.xlf');
58
-
59
-        // Configure property mapping to retrieve the file object.
60
-        if ($this->arguments->hasArgument('file')) {
61
-
62
-            /** @var FileConverter $typeConverter */
63
-            $typeConverter = $this->objectManager->get(FileConverter::class);
64
-
65
-            $propertyMappingConfiguration = $this->arguments->getArgument('file')->getPropertyMappingConfiguration();
66
-            $propertyMappingConfiguration->setTypeConverter($typeConverter);
67
-        }
68
-    }
69
-
70
-    /**
71
-     * Force download of the file.
72
-     *
73
-     * @param File $file
74
-     * @param bool $forceDownload
75
-     * @return bool|string
76
-     * @throws \RuntimeException
77
-     */
78
-    public function downloadAction(File $file, $forceDownload = false)
79
-    {
80
-
81
-        if ($file->exists() && $file->getStorage()->isWithinFileMountBoundaries($file->getParentFolder())) {
82
-
83
-            // Emit signal before downloading the file.
84
-            $this->emitBeforeDownloadSignal($file);
85
-
86
-            // Read the file and dump it with the flag "forceDownload" set to true or false.
87
-            $file->getStorage()->dumpFileContents($file, $forceDownload);
88
-
89
-            $result = true;
90
-        } else {
91
-            $result = 'Access denied!';
92
-        }
93
-
94
-        return $result;
95
-    }
96
-
97
-    /**
98
-     * Handle file upload for a new file.
99
-     *
100
-     * @param string $combinedIdentifier
101
-     * @validate $combinedIdentifier \Fab\Media\Domain\Validator\StorageValidator
102
-     * @return string
103
-     */
104
-    public function createAction($combinedIdentifier)
105
-    {
106
-        /** @var UploadedFileInterface $uploadedFile */
107
-        $uploadedFile = $this->handleUpload();
108
-        if (!is_object($uploadedFile)) {
109
-            return htmlspecialchars(json_encode($uploadedFile), ENT_NOQUOTES);
110
-        }
111
-
112
-        // Get the target folder.
113
-        if ($this->getMediaModule()->hasFolderTree()) {
114
-            $targetFolder = $this->getMediaModule()->getFolderForCombinedIdentifier($combinedIdentifier);
115
-        } else {
116
-            $storage = ResourceFactory::getInstance()->getStorageObjectFromCombinedIdentifier($combinedIdentifier);
117
-            $targetFolder = $this->getMediaModule()->getTargetFolderForUploadedFile($uploadedFile, $storage);
118
-        }
119
-
120
-        try {
121
-            $conflictMode = DuplicationBehavior::RENAME;
122
-            $fileName = $uploadedFile->getName();
123
-            $file = $targetFolder->addFile($uploadedFile->getFileWithAbsolutePath(), $fileName, $conflictMode);
124
-
125
-            // Run the indexer for extracting metadata.
126
-            $this->getMediaIndexer($file->getStorage())
127
-                ->extractMetadata($file)
128
-                ->applyDefaultCategories($file);
129
-
130
-            $response = array(
131
-                'success' => true,
132
-                'uid' => $file->getUid(),
133
-                'name' => $file->getName(),
134
-                'thumbnail' => $this->getThumbnailService($file)->create(),
135
-            );
136
-        } catch (UploadException $e) {
137
-            $response = array('error' => 'The upload has failed, no uploaded file found!');
138
-        } catch (InsufficientUserPermissionsException $e) {
139
-            $response = array('error' => 'You are not allowed to upload files!');
140
-        } catch (UploadSizeException $e) {
141
-            $response = array('error' => vsprintf('The uploaded file "%s" exceeds the size-limit', array($uploadedFile->getName())));
142
-        } catch (InsufficientFolderWritePermissionsException $e) {
143
-            $response = array('error' => vsprintf('Destination path "%s" was not within your mount points!', array($targetFolder->getIdentifier())));
144
-        } catch (IllegalFileExtensionException $e) {
145
-            $response = array('error' => vsprintf('Extension of file name "%s" is not allowed in "%s"!', array($uploadedFile->getName(), $targetFolder->getIdentifier())));
146
-        } catch (ExistingTargetFileNameException $e) {
147
-            $response = array('error' => vsprintf('No unique filename available in "%s"!', array($targetFolder->getIdentifier())));
148
-        } catch (\RuntimeException $e) {
149
-            $response = array('error' => vsprintf('Uploaded file could not be moved! Write-permission problem in "%s"?', array($targetFolder->getIdentifier())));
150
-        }
151
-
152
-        // to pass data through iframe you will need to encode all html tags
153
-        header("Content-Type: text/plain");
154
-        return htmlspecialchars(json_encode($response), ENT_NOQUOTES);
155
-    }
156
-
157
-    /**
158
-     * Handle file upload for an existing file.
159
-     *
160
-     * @param File $file
161
-     * @return string
162
-     * @throws \InvalidArgumentException
163
-     * @throws \RuntimeException
164
-     */
165
-    public function updateAction(File $file)
166
-    {
167
-        $uploadedFile = $this->handleUpload();
168
-        if (!is_object($uploadedFile)) {
169
-            return htmlspecialchars(json_encode($uploadedFile), ENT_NOQUOTES);
170
-        }
171
-
172
-        /** @var $file File */
173
-        $targetFolder = $file->getStorage()->getFolder(dirname($file->getIdentifier()));
174
-
175
-        try {
176
-            $storage = $file->getStorage();
177
-            $storage->replaceFile($file, $uploadedFile->getFileWithAbsolutePath());
178
-
179
-            // Run the indexer for extracting metadata.
180
-            $this->getMediaIndexer($file->getStorage())
181
-                ->updateIndex($file)
182
-                ->extractMetadata($file);
183
-
184
-            // Clear cache on pages holding a reference to this file.
185
-            $this->getCacheService()->clearCache($file);
186
-
187
-            $response = array(
188
-                'success' => true,
189
-                'uid' => $file->getUid(),
190
-                'name' => $file->getName(),
191
-                'thumbnail' => $this->getThumbnailService($file)->create(),
192
-                'fileInfo' => $this->getMetadataViewHelper()->render($file),
193
-            );
194
-        } catch (UploadException $e) {
195
-            $response = array('error' => 'The upload has failed, no uploaded file found!');
196
-        } catch (InsufficientUserPermissionsException $e) {
197
-            $response = array('error' => 'You are not allowed to upload files!');
198
-        } catch (UploadSizeException $e) {
199
-            $response = array('error' => vsprintf('The uploaded file "%s" exceeds the size-limit', array($uploadedFile->getName())));
200
-        } catch (InsufficientFolderWritePermissionsException $e) {
201
-            $response = array('error' => vsprintf('Destination path "%s" was not within your mount points!', array($targetFolder->getIdentifier())));
202
-        } catch (IllegalFileExtensionException $e) {
203
-            $response = array('error' => vsprintf('Extension of file name "%s" is not allowed in "%s"!', array($uploadedFile->getName(), $targetFolder->getIdentifier())));
204
-        } catch (ExistingTargetFileNameException $e) {
205
-            $response = array('error' => vsprintf('No unique filename available in "%s"!', array($targetFolder->getIdentifier())));
206
-        } catch (\RuntimeException $e) {
207
-            $response = array('error' => vsprintf('Uploaded file could not be moved! Write-permission problem in "%s"?', array($targetFolder->getIdentifier())));
208
-        }
209
-
210
-        // to pass data through iframe you will need to encode all html tags
211
-        header("Content-Type: text/plain");
212
-        return htmlspecialchars(json_encode($response), ENT_NOQUOTES);
213
-    }
214
-
215
-    /**
216
-     * Returns an editing form for moving Files between storage.
217
-     *
218
-     * @param array $matches
219
-     * @throws \Exception
220
-     */
221
-    public function editStorageAction(array $matches = [])
222
-    {
223
-
224
-        $this->view->assign('storages', $this->getMediaModule()->getAllowedStorages());
225
-        $this->view->assign('storageTitle', Tca::table('sys_file_storage')->getTitle());
226
-
227
-        $fieldName = 'storage';
228
-
229
-        // Instantiate the Matcher object according different rules.
230
-        $matcher = MatcherObjectFactory::getInstance()->getMatcher($matches, $this->dataType);
231
-
232
-        // Fetch objects via the Content Service.
233
-        $contentService = $this->getContentService()->findBy($matcher);
234
-
235
-        $fieldType = Tca::table($this->dataType)->field($fieldName)->getType();
236
-
237
-        $this->view->assign('fieldType', ucfirst($fieldType));
238
-        $this->view->assign('dataType', $this->dataType);
239
-        $this->view->assign('matches', $matches);
240
-        $this->view->assign('fieldNameAndPath', $fieldName);
241
-        $this->view->assign('numberOfObjects', $contentService->getNumberOfObjects());
242
-        $this->view->assign('editWholeSelection', empty($matches['uid'])); // necessary??
243
-    }
244
-
245
-    /**
246
-     * Handle file upload.
247
-     *
248
-     * @return \Fab\Media\FileUpload\UploadedFileInterface|array
249
-     * @throws \InvalidArgumentException
250
-     */
251
-    protected function handleUpload()
252
-    {
253
-
254
-        /** @var $uploadManager UploadManager */
255
-        $uploadManager = GeneralUtility::makeInstance(UploadManager::class);
256
-
257
-        try {
258
-            /** @var $result \Fab\Media\FileUpload\UploadedFileInterface */
259
-            $result = $uploadManager->handleUpload();
260
-        } catch (\Exception $e) {
261
-            $result = array('error' => $e->getMessage());
262
-        }
263
-
264
-        return $result;
265
-    }
266
-
267
-    /**
268
-     * @return MetadataViewHelper
269
-     * @throws \InvalidArgumentException
270
-     */
271
-    protected function getMetadataViewHelper()
272
-    {
273
-        return GeneralUtility::makeInstance(MetadataViewHelper::class);
274
-    }
275
-
276
-    /**
277
-     * @param File $file
278
-     * @return ThumbnailService
279
-     * @throws \Fab\Media\Exception\InvalidKeyInArrayException
280
-     * @throws \InvalidArgumentException
281
-     */
282
-    protected function getThumbnailService(File $file)
283
-    {
284
-
285
-        /** @var $thumbnailService ThumbnailService */
286
-        $thumbnailService = GeneralUtility::makeInstance(ThumbnailService::class, $file);
287
-        $thumbnailService->setAppendTimeStamp(true)
288
-            ->setOutputType(ThumbnailInterface::OUTPUT_IMAGE_WRAPPED);
289
-        return $thumbnailService;
290
-    }
291
-
292
-    /**
293
-     * Get the instance of the Indexer service to update the metadata of the file.
294
-     *
295
-     * @param int|ResourceStorage $storage
296
-     * @return MediaIndexer
297
-     * @throws \InvalidArgumentException
298
-     */
299
-    protected function getMediaIndexer($storage)
300
-    {
301
-        return GeneralUtility::makeInstance(MediaIndexer::class, $storage);
302
-    }
303
-
304
-    /**
305
-     * @return CacheService
306
-     * @throws \InvalidArgumentException
307
-     */
308
-    protected function getCacheService()
309
-    {
310
-        return GeneralUtility::makeInstance(CacheService::class);
311
-    }
312
-
313
-    /**
314
-     * Signal that is emitted before a file is downloaded.
315
-     *
316
-     * @param File $file
317
-     * @return void
318
-     * @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotReturnException
319
-     * @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotException
320
-     */
321
-    protected function emitBeforeDownloadSignal(File $file)
322
-    {
323
-        $this->getSignalSlotDispatcher()->dispatch('Fab\Media\Controller\Backend\AssetController', 'beforeDownload', array($file));
324
-    }
325
-
326
-    /**
327
-     * Get the SignalSlot dispatcher.
328
-     *
329
-     * @return Dispatcher
330
-     */
331
-    protected function getSignalSlotDispatcher()
332
-    {
333
-        return $this->objectManager->get(Dispatcher::class);
334
-    }
335
-
336
-    /**
337
-     * @return ContentService
338
-     * @throws \InvalidArgumentException
339
-     */
340
-    protected function getContentService()
341
-    {
342
-        return GeneralUtility::makeInstance(ContentService::class, $this->dataType);
343
-    }
344
-
345
-    /**
346
-     * @return MediaModule|object
347
-     * @throws \InvalidArgumentException
348
-     */
349
-    protected function getMediaModule()
350
-    {
351
-        return GeneralUtility::makeInstance(MediaModule::class);
352
-    }
44
+	/**
45
+	 * @var string
46
+	 */
47
+	protected $dataType = 'sys_file';
48
+
49
+	/**
50
+	 * @throws \Fab\Media\Exception\StorageNotOnlineException
51
+	 * @throws \InvalidArgumentException
52
+	 * @throws \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException
53
+	 */
54
+	public function initializeAction()
55
+	{
56
+		$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
57
+		$pageRenderer->addInlineLanguageLabelFile('EXT:media/Resources/Private/Language/locallang.xlf');
58
+
59
+		// Configure property mapping to retrieve the file object.
60
+		if ($this->arguments->hasArgument('file')) {
61
+
62
+			/** @var FileConverter $typeConverter */
63
+			$typeConverter = $this->objectManager->get(FileConverter::class);
64
+
65
+			$propertyMappingConfiguration = $this->arguments->getArgument('file')->getPropertyMappingConfiguration();
66
+			$propertyMappingConfiguration->setTypeConverter($typeConverter);
67
+		}
68
+	}
69
+
70
+	/**
71
+	 * Force download of the file.
72
+	 *
73
+	 * @param File $file
74
+	 * @param bool $forceDownload
75
+	 * @return bool|string
76
+	 * @throws \RuntimeException
77
+	 */
78
+	public function downloadAction(File $file, $forceDownload = false)
79
+	{
80
+
81
+		if ($file->exists() && $file->getStorage()->isWithinFileMountBoundaries($file->getParentFolder())) {
82
+
83
+			// Emit signal before downloading the file.
84
+			$this->emitBeforeDownloadSignal($file);
85
+
86
+			// Read the file and dump it with the flag "forceDownload" set to true or false.
87
+			$file->getStorage()->dumpFileContents($file, $forceDownload);
88
+
89
+			$result = true;
90
+		} else {
91
+			$result = 'Access denied!';
92
+		}
93
+
94
+		return $result;
95
+	}
96
+
97
+	/**
98
+	 * Handle file upload for a new file.
99
+	 *
100
+	 * @param string $combinedIdentifier
101
+	 * @validate $combinedIdentifier \Fab\Media\Domain\Validator\StorageValidator
102
+	 * @return string
103
+	 */
104
+	public function createAction($combinedIdentifier)
105
+	{
106
+		/** @var UploadedFileInterface $uploadedFile */
107
+		$uploadedFile = $this->handleUpload();
108
+		if (!is_object($uploadedFile)) {
109
+			return htmlspecialchars(json_encode($uploadedFile), ENT_NOQUOTES);
110
+		}
111
+
112
+		// Get the target folder.
113
+		if ($this->getMediaModule()->hasFolderTree()) {
114
+			$targetFolder = $this->getMediaModule()->getFolderForCombinedIdentifier($combinedIdentifier);
115
+		} else {
116
+			$storage = ResourceFactory::getInstance()->getStorageObjectFromCombinedIdentifier($combinedIdentifier);
117
+			$targetFolder = $this->getMediaModule()->getTargetFolderForUploadedFile($uploadedFile, $storage);
118
+		}
119
+
120
+		try {
121
+			$conflictMode = DuplicationBehavior::RENAME;
122
+			$fileName = $uploadedFile->getName();
123
+			$file = $targetFolder->addFile($uploadedFile->getFileWithAbsolutePath(), $fileName, $conflictMode);
124
+
125
+			// Run the indexer for extracting metadata.
126
+			$this->getMediaIndexer($file->getStorage())
127
+				->extractMetadata($file)
128
+				->applyDefaultCategories($file);
129
+
130
+			$response = array(
131
+				'success' => true,
132
+				'uid' => $file->getUid(),
133
+				'name' => $file->getName(),
134
+				'thumbnail' => $this->getThumbnailService($file)->create(),
135
+			);
136
+		} catch (UploadException $e) {
137
+			$response = array('error' => 'The upload has failed, no uploaded file found!');
138
+		} catch (InsufficientUserPermissionsException $e) {
139
+			$response = array('error' => 'You are not allowed to upload files!');
140
+		} catch (UploadSizeException $e) {
141
+			$response = array('error' => vsprintf('The uploaded file "%s" exceeds the size-limit', array($uploadedFile->getName())));
142
+		} catch (InsufficientFolderWritePermissionsException $e) {
143
+			$response = array('error' => vsprintf('Destination path "%s" was not within your mount points!', array($targetFolder->getIdentifier())));
144
+		} catch (IllegalFileExtensionException $e) {
145
+			$response = array('error' => vsprintf('Extension of file name "%s" is not allowed in "%s"!', array($uploadedFile->getName(), $targetFolder->getIdentifier())));
146
+		} catch (ExistingTargetFileNameException $e) {
147
+			$response = array('error' => vsprintf('No unique filename available in "%s"!', array($targetFolder->getIdentifier())));
148
+		} catch (\RuntimeException $e) {
149
+			$response = array('error' => vsprintf('Uploaded file could not be moved! Write-permission problem in "%s"?', array($targetFolder->getIdentifier())));
150
+		}
151
+
152
+		// to pass data through iframe you will need to encode all html tags
153
+		header("Content-Type: text/plain");
154
+		return htmlspecialchars(json_encode($response), ENT_NOQUOTES);
155
+	}
156
+
157
+	/**
158
+	 * Handle file upload for an existing file.
159
+	 *
160
+	 * @param File $file
161
+	 * @return string
162
+	 * @throws \InvalidArgumentException
163
+	 * @throws \RuntimeException
164
+	 */
165
+	public function updateAction(File $file)
166
+	{
167
+		$uploadedFile = $this->handleUpload();
168
+		if (!is_object($uploadedFile)) {
169
+			return htmlspecialchars(json_encode($uploadedFile), ENT_NOQUOTES);
170
+		}
171
+
172
+		/** @var $file File */
173
+		$targetFolder = $file->getStorage()->getFolder(dirname($file->getIdentifier()));
174
+
175
+		try {
176
+			$storage = $file->getStorage();
177
+			$storage->replaceFile($file, $uploadedFile->getFileWithAbsolutePath());
178
+
179
+			// Run the indexer for extracting metadata.
180
+			$this->getMediaIndexer($file->getStorage())
181
+				->updateIndex($file)
182
+				->extractMetadata($file);
183
+
184
+			// Clear cache on pages holding a reference to this file.
185
+			$this->getCacheService()->clearCache($file);
186
+
187
+			$response = array(
188
+				'success' => true,
189
+				'uid' => $file->getUid(),
190
+				'name' => $file->getName(),
191
+				'thumbnail' => $this->getThumbnailService($file)->create(),
192
+				'fileInfo' => $this->getMetadataViewHelper()->render($file),
193
+			);
194
+		} catch (UploadException $e) {
195
+			$response = array('error' => 'The upload has failed, no uploaded file found!');
196
+		} catch (InsufficientUserPermissionsException $e) {
197
+			$response = array('error' => 'You are not allowed to upload files!');
198
+		} catch (UploadSizeException $e) {
199
+			$response = array('error' => vsprintf('The uploaded file "%s" exceeds the size-limit', array($uploadedFile->getName())));
200
+		} catch (InsufficientFolderWritePermissionsException $e) {
201
+			$response = array('error' => vsprintf('Destination path "%s" was not within your mount points!', array($targetFolder->getIdentifier())));
202
+		} catch (IllegalFileExtensionException $e) {
203
+			$response = array('error' => vsprintf('Extension of file name "%s" is not allowed in "%s"!', array($uploadedFile->getName(), $targetFolder->getIdentifier())));
204
+		} catch (ExistingTargetFileNameException $e) {
205
+			$response = array('error' => vsprintf('No unique filename available in "%s"!', array($targetFolder->getIdentifier())));
206
+		} catch (\RuntimeException $e) {
207
+			$response = array('error' => vsprintf('Uploaded file could not be moved! Write-permission problem in "%s"?', array($targetFolder->getIdentifier())));
208
+		}
209
+
210
+		// to pass data through iframe you will need to encode all html tags
211
+		header("Content-Type: text/plain");
212
+		return htmlspecialchars(json_encode($response), ENT_NOQUOTES);
213
+	}
214
+
215
+	/**
216
+	 * Returns an editing form for moving Files between storage.
217
+	 *
218
+	 * @param array $matches
219
+	 * @throws \Exception
220
+	 */
221
+	public function editStorageAction(array $matches = [])
222
+	{
223
+
224
+		$this->view->assign('storages', $this->getMediaModule()->getAllowedStorages());
225
+		$this->view->assign('storageTitle', Tca::table('sys_file_storage')->getTitle());
226
+
227
+		$fieldName = 'storage';
228
+
229
+		// Instantiate the Matcher object according different rules.
230
+		$matcher = MatcherObjectFactory::getInstance()->getMatcher($matches, $this->dataType);
231
+
232
+		// Fetch objects via the Content Service.
233
+		$contentService = $this->getContentService()->findBy($matcher);
234
+
235
+		$fieldType = Tca::table($this->dataType)->field($fieldName)->getType();
236
+
237
+		$this->view->assign('fieldType', ucfirst($fieldType));
238
+		$this->view->assign('dataType', $this->dataType);
239
+		$this->view->assign('matches', $matches);
240
+		$this->view->assign('fieldNameAndPath', $fieldName);
241
+		$this->view->assign('numberOfObjects', $contentService->getNumberOfObjects());
242
+		$this->view->assign('editWholeSelection', empty($matches['uid'])); // necessary??
243
+	}
244
+
245
+	/**
246
+	 * Handle file upload.
247
+	 *
248
+	 * @return \Fab\Media\FileUpload\UploadedFileInterface|array
249
+	 * @throws \InvalidArgumentException
250
+	 */
251
+	protected function handleUpload()
252
+	{
253
+
254
+		/** @var $uploadManager UploadManager */
255
+		$uploadManager = GeneralUtility::makeInstance(UploadManager::class);
256
+
257
+		try {
258
+			/** @var $result \Fab\Media\FileUpload\UploadedFileInterface */
259
+			$result = $uploadManager->handleUpload();
260
+		} catch (\Exception $e) {
261
+			$result = array('error' => $e->getMessage());
262
+		}
263
+
264
+		return $result;
265
+	}
266
+
267
+	/**
268
+	 * @return MetadataViewHelper
269
+	 * @throws \InvalidArgumentException
270
+	 */
271
+	protected function getMetadataViewHelper()
272
+	{
273
+		return GeneralUtility::makeInstance(MetadataViewHelper::class);
274
+	}
275
+
276
+	/**
277
+	 * @param File $file
278
+	 * @return ThumbnailService
279
+	 * @throws \Fab\Media\Exception\InvalidKeyInArrayException
280
+	 * @throws \InvalidArgumentException
281
+	 */
282
+	protected function getThumbnailService(File $file)
283
+	{
284
+
285
+		/** @var $thumbnailService ThumbnailService */
286
+		$thumbnailService = GeneralUtility::makeInstance(ThumbnailService::class, $file);
287
+		$thumbnailService->setAppendTimeStamp(true)
288
+			->setOutputType(ThumbnailInterface::OUTPUT_IMAGE_WRAPPED);
289
+		return $thumbnailService;
290
+	}
291
+
292
+	/**
293
+	 * Get the instance of the Indexer service to update the metadata of the file.
294
+	 *
295
+	 * @param int|ResourceStorage $storage
296
+	 * @return MediaIndexer
297
+	 * @throws \InvalidArgumentException
298
+	 */
299
+	protected function getMediaIndexer($storage)
300
+	{
301
+		return GeneralUtility::makeInstance(MediaIndexer::class, $storage);
302
+	}
303
+
304
+	/**
305
+	 * @return CacheService
306
+	 * @throws \InvalidArgumentException
307
+	 */
308
+	protected function getCacheService()
309
+	{
310
+		return GeneralUtility::makeInstance(CacheService::class);
311
+	}
312
+
313
+	/**
314
+	 * Signal that is emitted before a file is downloaded.
315
+	 *
316
+	 * @param File $file
317
+	 * @return void
318
+	 * @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotReturnException
319
+	 * @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotException
320
+	 */
321
+	protected function emitBeforeDownloadSignal(File $file)
322
+	{
323
+		$this->getSignalSlotDispatcher()->dispatch('Fab\Media\Controller\Backend\AssetController', 'beforeDownload', array($file));
324
+	}
325
+
326
+	/**
327
+	 * Get the SignalSlot dispatcher.
328
+	 *
329
+	 * @return Dispatcher
330
+	 */
331
+	protected function getSignalSlotDispatcher()
332
+	{
333
+		return $this->objectManager->get(Dispatcher::class);
334
+	}
335
+
336
+	/**
337
+	 * @return ContentService
338
+	 * @throws \InvalidArgumentException
339
+	 */
340
+	protected function getContentService()
341
+	{
342
+		return GeneralUtility::makeInstance(ContentService::class, $this->dataType);
343
+	}
344
+
345
+	/**
346
+	 * @return MediaModule|object
347
+	 * @throws \InvalidArgumentException
348
+	 */
349
+	protected function getMediaModule()
350
+	{
351
+		return GeneralUtility::makeInstance(MediaModule::class);
352
+	}
353 353
 
354 354
 }
Please login to merge, or discard this patch.
ext_localconf.php 2 patches
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -3,39 +3,39 @@
 block discarded – undo
3 3
 
4 4
 call_user_func(function () {
5 5
 
6
-    $configuration = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
7
-        \TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class
8
-    )->get('media');
6
+	$configuration = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
7
+		\TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class
8
+	)->get('media');
9 9
 
10
-    $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'][1547054767] = [
11
-        'nodeName' => 'findUploader',
12
-        'priority' => 40,
13
-        'class' => \Fab\Media\Backend\TceForms::class,
14
-    ];
10
+	$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'][1547054767] = [
11
+		'nodeName' => 'findUploader',
12
+		'priority' => 40,
13
+		'class' => \Fab\Media\Backend\TceForms::class,
14
+	];
15 15
 
16
-    $disableTitleMetadataExtractor = isset($configuration['disable_title_metadata_extractor']) ? $configuration['disable_title_metadata_extractor'] : FALSE;
17
-    if (!$disableTitleMetadataExtractor) {
16
+	$disableTitleMetadataExtractor = isset($configuration['disable_title_metadata_extractor']) ? $configuration['disable_title_metadata_extractor'] : FALSE;
17
+	if (!$disableTitleMetadataExtractor) {
18 18
 
19
-        // Register basic metadata extractor. Will feed the file with a "title" when indexing, e.g. upload, through scheduler
20
-        \TYPO3\CMS\Core\Resource\Index\ExtractorRegistry::getInstance()->registerExtractionService('Fab\Media\Index\TitleMetadataExtractor');
21
-    }
19
+		// Register basic metadata extractor. Will feed the file with a "title" when indexing, e.g. upload, through scheduler
20
+		\TYPO3\CMS\Core\Resource\Index\ExtractorRegistry::getInstance()->registerExtractionService('Fab\Media\Index\TitleMetadataExtractor');
21
+	}
22 22
 
23
-    // Hook for traditional file upload, trigger metadata indexing as well.
24
-    // Could be done at the Core level in the future...
25
-    $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_extfilefunc.php']['processData'][] = 'Fab\Media\Hook\FileUploadHook';
23
+	// Hook for traditional file upload, trigger metadata indexing as well.
24
+	// Could be done at the Core level in the future...
25
+	$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_extfilefunc.php']['processData'][] = 'Fab\Media\Hook\FileUploadHook';
26 26
 
27
-    if (TYPO3_MODE === 'BE') {
27
+	if (TYPO3_MODE === 'BE') {
28 28
 
29
-        // Special process to fill column "usage" which indicates the total number of file reference including soft references.
30
-        $GLOBALS ['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][] = 'Fab\Media\Hook\DataHandlerHook';
29
+		// Special process to fill column "usage" which indicates the total number of file reference including soft references.
30
+		$GLOBALS ['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][] = 'Fab\Media\Hook\DataHandlerHook';
31 31
 
32
-        $hasMediaFilePicker = isset($configuration['has_media_file_picker']) ? $configuration['has_media_file_picker'] : FALSE;
33
-        if ($hasMediaFilePicker) {
32
+		$hasMediaFilePicker = isset($configuration['has_media_file_picker']) ? $configuration['has_media_file_picker'] : FALSE;
33
+		if ($hasMediaFilePicker) {
34 34
 
35
-            // Override classes for the Object Manager.
36
-            $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\TYPO3\CMS\Backend\Form\FormResultCompiler::class] = array(
37
-                'className' => \Fab\Media\Override\Backend\Form\FormResultCompiler::class
38
-            );
39
-        }
40
-    }
35
+			// Override classes for the Object Manager.
36
+			$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\TYPO3\CMS\Backend\Form\FormResultCompiler::class] = array(
37
+				'className' => \Fab\Media\Override\Backend\Form\FormResultCompiler::class
38
+			);
39
+		}
40
+	}
41 41
 });
42 42
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@
 block discarded – undo
1 1
 <?php
2 2
 defined('TYPO3_MODE') or die();
3 3
 
4
-call_user_func(function () {
4
+call_user_func(function() {
5 5
 
6 6
     $configuration = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
7 7
         \TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class
Please login to merge, or discard this patch.
ext_emconf.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -1,30 +1,30 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 $EM_CONF[$_EXTKEY] = [
4
-    'title' => 'Media management',
5
-    'description' => 'Media management system for TYPO3 CMS.',
6
-    'category' => 'module',
7
-    'author' => 'Fabien Udriot',
8
-    'author_email' => '[email protected]',
9
-    'state' => 'stable',
10
-    'version' => '5.1.0-dev',
11
-    'autoload' => [
12
-        'psr-4' => ['Fab\\Media\\' => 'Classes']
13
-    ],
14
-    'constraints' =>
15
-        [
16
-            'depends' =>
17
-                [
18
-                    'typo3' => '9.5.0-9.5.99',
19
-                    'vidi' => '3.0.0-0.0.0',
20
-                ],
21
-            'conflicts' =>
22
-                [
23
-                ],
24
-            'suggests' =>
25
-                [
26
-                    'metadata' => '',
27
-                    'filemetadata' => '',
28
-                ],
29
-        ]
4
+	'title' => 'Media management',
5
+	'description' => 'Media management system for TYPO3 CMS.',
6
+	'category' => 'module',
7
+	'author' => 'Fabien Udriot',
8
+	'author_email' => '[email protected]',
9
+	'state' => 'stable',
10
+	'version' => '5.1.0-dev',
11
+	'autoload' => [
12
+		'psr-4' => ['Fab\\Media\\' => 'Classes']
13
+	],
14
+	'constraints' =>
15
+		[
16
+			'depends' =>
17
+				[
18
+					'typo3' => '9.5.0-9.5.99',
19
+					'vidi' => '3.0.0-0.0.0',
20
+				],
21
+			'conflicts' =>
22
+				[
23
+				],
24
+			'suggests' =>
25
+				[
26
+					'metadata' => '',
27
+					'filemetadata' => '',
28
+				],
29
+		]
30 30
 ];
Please login to merge, or discard this patch.