Completed
Push — master ( fb6736...59da86 )
by Fabien
03:11 queued 01:31
created
Classes/Form/FileUpload.php 1 patch
Indentation   +232 added lines, -232 removed lines patch added patch discarded remove patch
@@ -24,30 +24,30 @@  discard block
 block discarded – undo
24 24
 class FileUpload extends AbstractFormField
25 25
 {
26 26
 
27
-    /**
28
-     * @var string
29
-     */
30
-    protected $elementId;
31
-
32
-    /**
33
-     * @var \TYPO3\CMS\Core\Resource\File
34
-     */
35
-    protected $file;
36
-
37
-    /**
38
-     * @var string
39
-     */
40
-    protected $templateFile = 'Resources/Private/Standalone/FileUploadTemplate.html';
41
-
42
-    /**
43
-     * @return \Fab\Media\Form\FileUpload
44
-     */
45
-    public function __construct()
46
-    {
47
-        $this->addLanguage();
48
-        $this->elementId = 'jquery-wrapped-fine-uploader-' . uniqid();
49
-
50
-        $this->template = <<<EOF
27
+	/**
28
+	 * @var string
29
+	 */
30
+	protected $elementId;
31
+
32
+	/**
33
+	 * @var \TYPO3\CMS\Core\Resource\File
34
+	 */
35
+	protected $file;
36
+
37
+	/**
38
+	 * @var string
39
+	 */
40
+	protected $templateFile = 'Resources/Private/Standalone/FileUploadTemplate.html';
41
+
42
+	/**
43
+	 * @return \Fab\Media\Form\FileUpload
44
+	 */
45
+	public function __construct()
46
+	{
47
+		$this->addLanguage();
48
+		$this->elementId = 'jquery-wrapped-fine-uploader-' . uniqid();
49
+
50
+		$this->template = <<<EOF
51 51
 <div class="control-group control-group-upload" style="%s">
52 52
     <div class="container-thumbnail">%s</div>
53 53
     %s
@@ -59,213 +59,213 @@  discard block
 block discarded – undo
59 59
 </div>
60 60
 
61 61
 EOF;
62
-    }
63
-
64
-    /**
65
-     * Add language labels for JavaScript files
66
-     */
67
-    protected function addLanguage()
68
-    {
69
-        /** @var PageRenderer $pageRenderer */
70
-        $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
71
-        $pageRenderer->addInlineLanguageLabelFile(ExtensionManagementUtility::extPath('media') . 'Resources/Private/Language/locallang.xlf', 'media_file_upload');
72
-    }
73
-
74
-    /**
75
-     * Render a file upload field.
76
-     *
77
-     * @throws \Fab\Media\Exception\EmptyPropertyException
78
-     * @return string
79
-     */
80
-    public function render()
81
-    {
82
-
83
-        // Instantiate the file object for the whole class if possible.
84
-        if ($this->getValue()) {
85
-            $this->file = ResourceFactory::getInstance()->getFileObject($this->getValue());
86
-        }
87
-
88
-        $result = sprintf(
89
-            $this->template,
90
-            $this->getInlineStyle(),
91
-            $this->getThumbnail(),
92
-            $this->getFileInfo(),
93
-            $this->elementId,
94
-            $this->getJavaScriptTemplate(),
95
-            $this->getJavaScript()
96
-        );
97
-        return $result;
98
-    }
99
-
100
-    /**
101
-     * @return string
102
-     */
103
-    protected function getInlineStyle()
104
-    {
105
-        $style = 'float: left';
106
-        if ($this->getMediaModule()->hasFolderTree() && !$this->getModuleLoader()->hasPlugin()) {
107
-            $style .= '; padding-left: 3px';
108
-        }
109
-        return $style;
110
-    }
111
-
112
-    /**
113
-     * Get the javascript from a file and replace the markers with live variables.
114
-     *
115
-     * @return string
116
-     */
117
-    protected function getThumbnail()
118
-    {
119
-        $thumbnail = '';
120
-        if ($this->file) {
121
-
122
-            /** @var $thumbnailService \Fab\Media\Thumbnail\ThumbnailService */
123
-            $thumbnailService = GeneralUtility::makeInstance(\Fab\Media\Thumbnail\ThumbnailService::class, $this->file);
124
-            $thumbnail = $thumbnailService
125
-                ->setOutputType(ThumbnailInterface::OUTPUT_IMAGE_WRAPPED)
126
-                ->setAppendTimeStamp(true)
127
-                ->create();
128
-        }
129
-        return $thumbnail;
130
-    }
131
-
132
-    /**
133
-     * Get the javascript from a file and replace the markers with live variables.
134
-     *
135
-     * @return string
136
-     */
137
-    protected function getJavaScriptTemplate()
138
-    {
139
-        $view = $this->getStandaloneView();
140
-        $view->assignMultiple(
141
-            array(
142
-                'maximumUploadLabel' => $this->getMaximumUploadLabel(),
143
-            )
144
-        );
145
-        return $view->render();
146
-    }
147
-
148
-    /**
149
-     * @return \TYPO3\CMS\Fluid\View\StandaloneView
150
-     */
151
-    protected function getStandaloneView()
152
-    {
153
-        $objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
154
-
155
-        /** @var \TYPO3\CMS\Fluid\View\StandaloneView $view */
156
-        $view = $objectManager->get('TYPO3\CMS\Fluid\View\StandaloneView');
157
-
158
-        $templatePathAndFilename = ExtensionManagementUtility::extPath('media') . $this->templateFile;
159
-        $view->setTemplatePathAndFilename($templatePathAndFilename);
160
-
161
-        return $view;
162
-    }
163
-
164
-    /**
165
-     * Get the javascript from a file and replace the markers with live variables.
166
-     *
167
-     * @return string
168
-     */
169
-    protected function getJavaScript()
170
-    {
171
-
172
-        // Get the base prefix
173
-        $basePrefix = $this->getBasePrefix($this->getPrefix());
174
-
175
-        $filePath = ExtensionManagementUtility::extPath('media') . 'Resources/Private/Standalone/FileUpload.js';
176
-
177
-        return sprintf(
178
-            file_get_contents($filePath),
179
-            $basePrefix,
180
-            $this->elementId,
181
-            $this->getModuleUrl(),
182
-            $this->getAllowedExtensions(),
183
-            GeneralUtility::getMaxUploadFileSize() * 1024,
184
-            $this->isDrivenByFolder() ?
185
-                $this->getMediaModule()->getCurrentFolder()->getCombinedIdentifier() :
186
-                $this->getMediaModule()->getCurrentStorage()->getUid() . ':/'
187
-
188
-        );
189
-    }
190
-
191
-    /**
192
-     * @return bool
193
-     */
194
-    protected function isDrivenByFolder()
195
-    {
196
-        return $this->getMediaModule()->hasFolderTree() && !$this->getModuleLoader()->hasPlugin();
197
-    }
198
-
199
-    /**
200
-     * @return string
201
-     */
202
-    protected function getModuleUrl()
203
-    {
204
-        $moduleSignature = MediaModule::getSignature();
205
-        return BackendUtility::getModuleUrl($moduleSignature);
206
-    }
207
-
208
-    /**
209
-     * Returns the max upload file size in Mo.
210
-     *
211
-     * @return string
212
-     */
213
-    protected function getMaximumUploadLabel()
214
-    {
215
-        $result = round(GeneralUtility::getMaxUploadFileSize() / 1024, 2);
216
-        $label = LocalizationUtility::translate('max_upload_file', 'media');
217
-        $result = sprintf($label, $result);
218
-        return $result;
219
-    }
220
-
221
-    /**
222
-     * Get allowed extension.
223
-     *
224
-     * @return string
225
-     */
226
-    protected function getAllowedExtensions()
227
-    {
228
-        return implode("','", PermissionUtility::getInstance()->getAllowedExtensions());
229
-    }
230
-
231
-    /**
232
-     * Compute the base prefix by removing the square brackets.
233
-     *
234
-     * @param string $prefix
235
-     * @return string
236
-     */
237
-    protected function getBasePrefix($prefix)
238
-    {
239
-        $parts = explode('[', $prefix);
240
-        return empty($parts) ? '' : $parts[0];
241
-    }
242
-
243
-    /**
244
-     * Returns additional file info.
245
-     *
246
-     * @return string
247
-     */
248
-    protected function getFileInfo()
249
-    {
250
-        return ''; // empty return here but check out Tceforms/FileUpload
251
-    }
252
-
253
-    /**
254
-     * @return MediaModule|object
255
-     */
256
-    protected function getMediaModule()
257
-    {
258
-        return GeneralUtility::makeInstance(MediaModule::class);
259
-    }
260
-
261
-    /**
262
-     * Get the Vidi Module Loader.
263
-     *
264
-     * @return \Fab\Vidi\Module\ModuleLoader|object
265
-     */
266
-    protected function getModuleLoader()
267
-    {
268
-        return GeneralUtility::makeInstance(\Fab\Vidi\Module\ModuleLoader::class);
269
-    }
62
+	}
63
+
64
+	/**
65
+	 * Add language labels for JavaScript files
66
+	 */
67
+	protected function addLanguage()
68
+	{
69
+		/** @var PageRenderer $pageRenderer */
70
+		$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
71
+		$pageRenderer->addInlineLanguageLabelFile(ExtensionManagementUtility::extPath('media') . 'Resources/Private/Language/locallang.xlf', 'media_file_upload');
72
+	}
73
+
74
+	/**
75
+	 * Render a file upload field.
76
+	 *
77
+	 * @throws \Fab\Media\Exception\EmptyPropertyException
78
+	 * @return string
79
+	 */
80
+	public function render()
81
+	{
82
+
83
+		// Instantiate the file object for the whole class if possible.
84
+		if ($this->getValue()) {
85
+			$this->file = ResourceFactory::getInstance()->getFileObject($this->getValue());
86
+		}
87
+
88
+		$result = sprintf(
89
+			$this->template,
90
+			$this->getInlineStyle(),
91
+			$this->getThumbnail(),
92
+			$this->getFileInfo(),
93
+			$this->elementId,
94
+			$this->getJavaScriptTemplate(),
95
+			$this->getJavaScript()
96
+		);
97
+		return $result;
98
+	}
99
+
100
+	/**
101
+	 * @return string
102
+	 */
103
+	protected function getInlineStyle()
104
+	{
105
+		$style = 'float: left';
106
+		if ($this->getMediaModule()->hasFolderTree() && !$this->getModuleLoader()->hasPlugin()) {
107
+			$style .= '; padding-left: 3px';
108
+		}
109
+		return $style;
110
+	}
111
+
112
+	/**
113
+	 * Get the javascript from a file and replace the markers with live variables.
114
+	 *
115
+	 * @return string
116
+	 */
117
+	protected function getThumbnail()
118
+	{
119
+		$thumbnail = '';
120
+		if ($this->file) {
121
+
122
+			/** @var $thumbnailService \Fab\Media\Thumbnail\ThumbnailService */
123
+			$thumbnailService = GeneralUtility::makeInstance(\Fab\Media\Thumbnail\ThumbnailService::class, $this->file);
124
+			$thumbnail = $thumbnailService
125
+				->setOutputType(ThumbnailInterface::OUTPUT_IMAGE_WRAPPED)
126
+				->setAppendTimeStamp(true)
127
+				->create();
128
+		}
129
+		return $thumbnail;
130
+	}
131
+
132
+	/**
133
+	 * Get the javascript from a file and replace the markers with live variables.
134
+	 *
135
+	 * @return string
136
+	 */
137
+	protected function getJavaScriptTemplate()
138
+	{
139
+		$view = $this->getStandaloneView();
140
+		$view->assignMultiple(
141
+			array(
142
+				'maximumUploadLabel' => $this->getMaximumUploadLabel(),
143
+			)
144
+		);
145
+		return $view->render();
146
+	}
147
+
148
+	/**
149
+	 * @return \TYPO3\CMS\Fluid\View\StandaloneView
150
+	 */
151
+	protected function getStandaloneView()
152
+	{
153
+		$objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
154
+
155
+		/** @var \TYPO3\CMS\Fluid\View\StandaloneView $view */
156
+		$view = $objectManager->get('TYPO3\CMS\Fluid\View\StandaloneView');
157
+
158
+		$templatePathAndFilename = ExtensionManagementUtility::extPath('media') . $this->templateFile;
159
+		$view->setTemplatePathAndFilename($templatePathAndFilename);
160
+
161
+		return $view;
162
+	}
163
+
164
+	/**
165
+	 * Get the javascript from a file and replace the markers with live variables.
166
+	 *
167
+	 * @return string
168
+	 */
169
+	protected function getJavaScript()
170
+	{
171
+
172
+		// Get the base prefix
173
+		$basePrefix = $this->getBasePrefix($this->getPrefix());
174
+
175
+		$filePath = ExtensionManagementUtility::extPath('media') . 'Resources/Private/Standalone/FileUpload.js';
176
+
177
+		return sprintf(
178
+			file_get_contents($filePath),
179
+			$basePrefix,
180
+			$this->elementId,
181
+			$this->getModuleUrl(),
182
+			$this->getAllowedExtensions(),
183
+			GeneralUtility::getMaxUploadFileSize() * 1024,
184
+			$this->isDrivenByFolder() ?
185
+				$this->getMediaModule()->getCurrentFolder()->getCombinedIdentifier() :
186
+				$this->getMediaModule()->getCurrentStorage()->getUid() . ':/'
187
+
188
+		);
189
+	}
190
+
191
+	/**
192
+	 * @return bool
193
+	 */
194
+	protected function isDrivenByFolder()
195
+	{
196
+		return $this->getMediaModule()->hasFolderTree() && !$this->getModuleLoader()->hasPlugin();
197
+	}
198
+
199
+	/**
200
+	 * @return string
201
+	 */
202
+	protected function getModuleUrl()
203
+	{
204
+		$moduleSignature = MediaModule::getSignature();
205
+		return BackendUtility::getModuleUrl($moduleSignature);
206
+	}
207
+
208
+	/**
209
+	 * Returns the max upload file size in Mo.
210
+	 *
211
+	 * @return string
212
+	 */
213
+	protected function getMaximumUploadLabel()
214
+	{
215
+		$result = round(GeneralUtility::getMaxUploadFileSize() / 1024, 2);
216
+		$label = LocalizationUtility::translate('max_upload_file', 'media');
217
+		$result = sprintf($label, $result);
218
+		return $result;
219
+	}
220
+
221
+	/**
222
+	 * Get allowed extension.
223
+	 *
224
+	 * @return string
225
+	 */
226
+	protected function getAllowedExtensions()
227
+	{
228
+		return implode("','", PermissionUtility::getInstance()->getAllowedExtensions());
229
+	}
230
+
231
+	/**
232
+	 * Compute the base prefix by removing the square brackets.
233
+	 *
234
+	 * @param string $prefix
235
+	 * @return string
236
+	 */
237
+	protected function getBasePrefix($prefix)
238
+	{
239
+		$parts = explode('[', $prefix);
240
+		return empty($parts) ? '' : $parts[0];
241
+	}
242
+
243
+	/**
244
+	 * Returns additional file info.
245
+	 *
246
+	 * @return string
247
+	 */
248
+	protected function getFileInfo()
249
+	{
250
+		return ''; // empty return here but check out Tceforms/FileUpload
251
+	}
252
+
253
+	/**
254
+	 * @return MediaModule|object
255
+	 */
256
+	protected function getMediaModule()
257
+	{
258
+		return GeneralUtility::makeInstance(MediaModule::class);
259
+	}
260
+
261
+	/**
262
+	 * Get the Vidi Module Loader.
263
+	 *
264
+	 * @return \Fab\Vidi\Module\ModuleLoader|object
265
+	 */
266
+	protected function getModuleLoader()
267
+	{
268
+		return GeneralUtility::makeInstance(\Fab\Vidi\Module\ModuleLoader::class);
269
+	}
270 270
 
271 271
 }
Please login to merge, or discard this patch.
Classes/Domain/Validator/StorageValidator.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -19,32 +19,32 @@
 block discarded – undo
19 19
 class StorageValidator extends AbstractValidator
20 20
 {
21 21
 
22
-    /**
23
-     * Check if $storageIdentifier is allowed. If it is not valid, throw an exception.
24
-     *
25
-     * @param int $combinedIdentifier
26
-     * @return void
27
-     */
28
-    public function isValid($combinedIdentifier)
29
-    {
22
+	/**
23
+	 * Check if $storageIdentifier is allowed. If it is not valid, throw an exception.
24
+	 *
25
+	 * @param int $combinedIdentifier
26
+	 * @return void
27
+	 */
28
+	public function isValid($combinedIdentifier)
29
+	{
30 30
 
31
-        $allowedStorageIdentifiers = [];
32
-        foreach ($this->getMediaModule()->getAllowedStorages() as $allowedStorage) {
33
-            $allowedStorageIdentifiers[] = $allowedStorage->getUid();
34
-        }
31
+		$allowedStorageIdentifiers = [];
32
+		foreach ($this->getMediaModule()->getAllowedStorages() as $allowedStorage) {
33
+			$allowedStorageIdentifiers[] = $allowedStorage->getUid();
34
+		}
35 35
 
36
-        $storage = ResourceFactory::getInstance()->getStorageObjectFromCombinedIdentifier($combinedIdentifier);
37
-        if (!in_array($storage->getUid(), $allowedStorageIdentifiers)) {
38
-            $message = sprintf('Storage identifier "%s" is not allowed or is currently off-line.', $combinedIdentifier);
39
-            $this->addError($message, 1380813503);
40
-        }
41
-    }
36
+		$storage = ResourceFactory::getInstance()->getStorageObjectFromCombinedIdentifier($combinedIdentifier);
37
+		if (!in_array($storage->getUid(), $allowedStorageIdentifiers)) {
38
+			$message = sprintf('Storage identifier "%s" is not allowed or is currently off-line.', $combinedIdentifier);
39
+			$this->addError($message, 1380813503);
40
+		}
41
+	}
42 42
 
43
-    /**
44
-     * @return MediaModule|object
45
-     */
46
-    protected function getMediaModule()
47
-    {
48
-        return GeneralUtility::makeInstance(\Fab\Media\Module\MediaModule::class);
49
-    }
43
+	/**
44
+	 * @return MediaModule|object
45
+	 */
46
+	protected function getMediaModule()
47
+	{
48
+		return GeneralUtility::makeInstance(\Fab\Media\Module\MediaModule::class);
49
+	}
50 50
 }
Please login to merge, or discard this patch.
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/Grid/ActionPermissionColumn.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -17,34 +17,34 @@
 block discarded – undo
17 17
 class ActionPermissionColumn extends ColumnRendererAbstract
18 18
 {
19 19
 
20
-    /**
21
-     * Renders a configurable metadata property of a file in the Grid.
22
-     *
23
-     * @throws \Exception
24
-     * @return string
25
-     */
26
-    public function render()
27
-    {
28
-
29
-        $file = $this->getFileConverter()->convert($this->object);
30
-        $permission = '';
31
-
32
-        if ($file->checkActionPermission('read')) {
33
-            $permission = 'R';
34
-        }
35
-        if ($file->checkActionPermission('write')) {
36
-            $permission .= 'W';
37
-        }
38
-
39
-        return '<strong>' . $permission . '</strong>';
40
-    }
41
-
42
-    /**
43
-     * @return \Fab\Media\TypeConverter\ContentToFileConverter|object
44
-     */
45
-    protected function getFileConverter()
46
-    {
47
-        return GeneralUtility::makeInstance(\Fab\Media\TypeConverter\ContentToFileConverter::class);
48
-    }
20
+	/**
21
+	 * Renders a configurable metadata property of a file in the Grid.
22
+	 *
23
+	 * @throws \Exception
24
+	 * @return string
25
+	 */
26
+	public function render()
27
+	{
28
+
29
+		$file = $this->getFileConverter()->convert($this->object);
30
+		$permission = '';
31
+
32
+		if ($file->checkActionPermission('read')) {
33
+			$permission = 'R';
34
+		}
35
+		if ($file->checkActionPermission('write')) {
36
+			$permission .= 'W';
37
+		}
38
+
39
+		return '<strong>' . $permission . '</strong>';
40
+	}
41
+
42
+	/**
43
+	 * @return \Fab\Media\TypeConverter\ContentToFileConverter|object
44
+	 */
45
+	protected function getFileConverter()
46
+	{
47
+		return GeneralUtility::makeInstance(\Fab\Media\TypeConverter\ContentToFileConverter::class);
48
+	}
49 49
 
50 50
 }
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 1 patch
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.
Configuration/TCA/Overrides/sys_file_metadata.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -3,31 +3,31 @@
 block discarded – undo
3 3
 
4 4
 // We only want to have file relations if extension File advanced metadata is loaded.
5 5
 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('filemetadata')) {
6
-    $configuration = '--div--;LLL:EXT:media/Resources/Private/Language/locallang_db.xlf:tab.relations, related_files';
7
-    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('sys_file_metadata', $configuration);
6
+	$configuration = '--div--;LLL:EXT:media/Resources/Private/Language/locallang_db.xlf:tab.relations, related_files';
7
+	\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('sys_file_metadata', $configuration);
8 8
 }
9 9
 
10 10
 $tca = [
11
-    'ctrl' => [
12
-        'default_sortby' => 'ORDER BY uid DESC',
13
-        'searchFields' => 'uid,extension,name', // sys_file_metadata.title,sys_file_metadata.keywords,
14
-    ],
15
-    'columns' => [
16
-        'fileinfo' => [
17
-            'config' => [
18
-                'type' => 'user',
19
-                'renderType' => 'findUploader',
20
-            ],
21
-        ],
22
-        'related_files' => [
23
-            'displayCond' => 'FIELD:sys_language_uid:<=:0',
24
-            'label' => 'LLL:EXT:media/Resources/Private/Language/locallang_db.xlf:sys_file_metadata.relations',
25
-            'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
26
-                'related_files',
27
-                [],
28
-                ''
29
-            ),
30
-        ],
31
-    ],
11
+	'ctrl' => [
12
+		'default_sortby' => 'ORDER BY uid DESC',
13
+		'searchFields' => 'uid,extension,name', // sys_file_metadata.title,sys_file_metadata.keywords,
14
+	],
15
+	'columns' => [
16
+		'fileinfo' => [
17
+			'config' => [
18
+				'type' => 'user',
19
+				'renderType' => 'findUploader',
20
+			],
21
+		],
22
+		'related_files' => [
23
+			'displayCond' => 'FIELD:sys_language_uid:<=:0',
24
+			'label' => 'LLL:EXT:media/Resources/Private/Language/locallang_db.xlf:sys_file_metadata.relations',
25
+			'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
26
+				'related_files',
27
+				[],
28
+				''
29
+			),
30
+		],
31
+	],
32 32
 ];
33 33
 \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($GLOBALS['TCA']['sys_file_metadata'], $tca);
34 34
\ No newline at end of file
Please login to merge, or discard this patch.