Completed
Push — master ( ad447f...f2215d )
by Fabien
03:37 queued 48s
created
Classes/Controller/LinkCreatorController.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -23,32 +23,32 @@
 block discarded – undo
23 23
 class LinkCreatorController extends ActionController
24 24
 {
25 25
 
26
-    /**
27
-     * Initializes the controller before invoking an action method.
28
-     */
29
-    public function initializeAction()
30
-    {
31
-
32
-        // Configure property mapping to retrieve the file object.
33
-        if ($this->arguments->hasArgument('file')) {
34
-
35
-            /** @var \Fab\Media\TypeConverter\FileConverter $typeConverter */
36
-            $typeConverter = $this->objectManager->get('Fab\Media\TypeConverter\FileConverter');
37
-
38
-            $propertyMappingConfiguration = $this->arguments->getArgument('file')->getPropertyMappingConfiguration();
39
-            $propertyMappingConfiguration->setTypeConverter($typeConverter);
40
-        }
41
-    }
42
-
43
-    /**
44
-     * Handle GUI for creating a link in the RTE.
45
-     *
46
-     * @param File $file
47
-     * @return void
48
-     */
49
-    public function showAction(File $file)
50
-    {
51
-        $this->view->assign('file', $file);
52
-    }
26
+	/**
27
+	 * Initializes the controller before invoking an action method.
28
+	 */
29
+	public function initializeAction()
30
+	{
31
+
32
+		// Configure property mapping to retrieve the file object.
33
+		if ($this->arguments->hasArgument('file')) {
34
+
35
+			/** @var \Fab\Media\TypeConverter\FileConverter $typeConverter */
36
+			$typeConverter = $this->objectManager->get('Fab\Media\TypeConverter\FileConverter');
37
+
38
+			$propertyMappingConfiguration = $this->arguments->getArgument('file')->getPropertyMappingConfiguration();
39
+			$propertyMappingConfiguration->setTypeConverter($typeConverter);
40
+		}
41
+	}
42
+
43
+	/**
44
+	 * Handle GUI for creating a link in the RTE.
45
+	 *
46
+	 * @param File $file
47
+	 * @return void
48
+	 */
49
+	public function showAction(File $file)
50
+	{
51
+		$this->view->assign('file', $file);
52
+	}
53 53
 
54 54
 }
Please login to merge, or discard this patch.
Classes/View/Plugin/FilePickerPlugin.php 2 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -25,30 +25,30 @@
 block discarded – undo
25 25
 class FilePickerPlugin extends AbstractComponentView
26 26
 {
27 27
 
28
-    /**
29
-     * Renders a hidden link for file picker.
30
-     *
31
-     * @return string
32
-     */
33
-    public function render()
34
-    {
35
-
36
-        if ($this->getModuleLoader()->hasPlugin('filePicker')) {
37
-            $this->loadRequireJsCode();
38
-        };
39
-        return '';
40
-    }
41
-
42
-    /**
43
-     * @return void
44
-     */
45
-    protected function loadRequireJsCode()
46
-    {
47
-        $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
48
-
49
-        $configuration['paths']['Fab/Media'] = '../typo3conf/ext/media/Resources/Public/JavaScript';
50
-        $pageRenderer->addRequireJsConfiguration($configuration);
51
-        $pageRenderer->loadRequireJsModule('Fab/Media/PluginFilePicker');
52
-    }
28
+	/**
29
+	 * Renders a hidden link for file picker.
30
+	 *
31
+	 * @return string
32
+	 */
33
+	public function render()
34
+	{
35
+
36
+		if ($this->getModuleLoader()->hasPlugin('filePicker')) {
37
+			$this->loadRequireJsCode();
38
+		};
39
+		return '';
40
+	}
41
+
42
+	/**
43
+	 * @return void
44
+	 */
45
+	protected function loadRequireJsCode()
46
+	{
47
+		$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
48
+
49
+		$configuration['paths']['Fab/Media'] = '../typo3conf/ext/media/Resources/Public/JavaScript';
50
+		$pageRenderer->addRequireJsConfiguration($configuration);
51
+		$pageRenderer->loadRequireJsModule('Fab/Media/PluginFilePicker');
52
+	}
53 53
 
54 54
 }
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -9,7 +9,6 @@
 block discarded – undo
9 9
  */
10 10
 
11 11
 use Fab\Vidi\View\AbstractComponentView;
12
-use Fab\Media\Utility\Path;
13 12
 use TYPO3\CMS\Core\Page\PageRenderer;
14 13
 use TYPO3\CMS\Core\Utility\GeneralUtility;
15 14
 
Please login to merge, or discard this patch.
Classes/Module/MediaModule.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
         }
233 233
 
234 234
         // Retrieve the folder object.
235
-        $folder = ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($storage->getUid() . ':' . $identifier);
235
+        $folder = ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($storage->getUid().':'.$identifier);
236 236
 
237 237
         // Disallow the rendering of the processing folder (e.g. could be called manually)
238 238
         // and all folders without any defined storage
@@ -289,11 +289,11 @@  discard block
 block discarded – undo
289 289
 
290 290
         // Get a possible mount point coming from the storage record.
291 291
         $storageRecord = $storage->getStorageRecord();
292
-        $mountPointIdentifier = $storageRecord['mount_point_file_type_' . $uploadedFile->getType()];
292
+        $mountPointIdentifier = $storageRecord['mount_point_file_type_'.$uploadedFile->getType()];
293 293
         if ($mountPointIdentifier > 0) {
294 294
 
295 295
             // We don't have a Mount Point repository in FAL, so query the database directly.
296
-            $record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('path', 'sys_filemounts', 'deleted = 0 AND uid = ' . $mountPointIdentifier);
296
+            $record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('path', 'sys_filemounts', 'deleted = 0 AND uid = '.$mountPointIdentifier);
297 297
             if (!empty($record['path'])) {
298 298
                 $folder = $storage->getFolder($record['path']);
299 299
             }
@@ -316,12 +316,12 @@  discard block
 block discarded – undo
316 316
 
317 317
         // Retrieve storage record and a possible configured mount point.
318 318
         $storageRecord = $storage->getStorageRecord();
319
-        $mountPointIdentifier = $storageRecord['mount_point_file_type_' . $file->getType()];
319
+        $mountPointIdentifier = $storageRecord['mount_point_file_type_'.$file->getType()];
320 320
 
321 321
         if ($mountPointIdentifier > 0) {
322 322
 
323 323
             // We don't have a Mount Point repository in FAL, so query the database directly.
324
-            $record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('path', 'sys_filemounts', 'deleted = 0 AND uid = ' . $mountPointIdentifier);
324
+            $record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('path', 'sys_filemounts', 'deleted = 0 AND uid = '.$mountPointIdentifier);
325 325
             if (!empty($record['path'])) {
326 326
                 $folder = $storage->getFolder($record['path']);
327 327
             }
Please login to merge, or discard this patch.
Indentation   +336 added lines, -336 removed lines patch added patch discarded remove patch
@@ -25,341 +25,341 @@
 block discarded – undo
25 25
 class MediaModule implements SingletonInterface
26 26
 {
27 27
 
28
-    /**
29
-     * @var string
30
-     */
31
-    const SIGNATURE = 'user_MediaM1';
32
-
33
-    /**
34
-     * @var string
35
-     */
36
-    const PARAMETER_PREFIX = 'tx_media_user_mediam1';
37
-
38
-    /**
39
-     * @var ResourceStorage
40
-     */
41
-    protected $currentStorage;
42
-
43
-    /**
44
-     * @return string
45
-     */
46
-    static public function getSignature()
47
-    {
48
-        return self::SIGNATURE;
49
-    }
50
-
51
-    /**
52
-     * @return string
53
-     */
54
-    static public function getParameterPrefix()
55
-    {
56
-        return self::PARAMETER_PREFIX;
57
-    }
58
-
59
-    /**
60
-     * Return all storage allowed for the Backend User.
61
-     *
62
-     * @throws \RuntimeException
63
-     * @return ResourceStorage[]
64
-     */
65
-    public function getAllowedStorages()
66
-    {
67
-
68
-        $storages = $this->getBackendUser()->getFileStorages();
69
-        if (empty($storages)) {
70
-            throw new \RuntimeException('No storage is accessible for the current BE User. Forgotten to define a mount point for this BE User?', 1380801970);
71
-        }
72
-        return $storages;
73
-    }
74
-
75
-    /**
76
-     * Returns the current file storage in use.
77
-     *
78
-     * @return ResourceStorage
79
-     */
80
-    public function getCurrentStorage()
81
-    {
82
-        if (is_null($this->currentStorage)) {
83
-
84
-            $storageIdentifier = $this->getStorageIdentifierFromSessionOrArguments();
85
-
86
-            if ($storageIdentifier > 0) {
87
-                $currentStorage = ResourceFactory::getInstance()->getStorageObject($storageIdentifier);
88
-            } else {
89
-
90
-                // We differentiate the cases whether the User is admin or not.
91
-                if ($this->getBackendUser()->isAdmin()) {
92
-
93
-                    $currentStorage = ResourceFactory::getInstance()->getDefaultStorage();
94
-
95
-                    // Not default storage has been flagged in "sys_file_storage".
96
-                    // Fallback approach: take the first storage as the current.
97
-                    if (!$currentStorage) {
98
-                        /** @var $storageRepository StorageRepository */
99
-                        $storageRepository = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class);
100
-
101
-                        $storages = $storageRepository->findAll();
102
-                        $currentStorage = current($storages);
103
-                    }
104
-                } else {
105
-                    $fileMounts = $this->getBackendUser()->getFileMountRecords();
106
-                    $firstFileMount = current($fileMounts);
107
-                    $currentStorage = ResourceFactory::getInstance()->getStorageObject($firstFileMount['base']);
108
-                }
109
-            }
110
-
111
-            $this->currentStorage = $currentStorage;
112
-        }
113
-        return $this->currentStorage;
114
-    }
115
-
116
-    /**
117
-     * Retrieve a possible storage identifier from the session or from the arguments.
118
-     *
119
-     * @return int
120
-     */
121
-    protected function getStorageIdentifierFromSessionOrArguments()
122
-    {
123
-
124
-        // Default value
125
-        $storageIdentifier = 0;
126
-
127
-        // Get last selected storage from User settings
128
-        if (SessionUtility::getInstance()->get('lastSelectedStorage') > 0) {
129
-            $storageIdentifier = SessionUtility::getInstance()->get('lastSelectedStorage');
130
-        }
131
-
132
-        $argumentPrefix = $this->getModuleLoader()->getParameterPrefix();
133
-        $arguments = GeneralUtility::_GET($argumentPrefix);
134
-
135
-        // Override selected storage from the session if GET argument "storage" is detected.
136
-        if (!empty($arguments['storage']) && (int)$arguments['storage'] > 0) {
137
-            $storageIdentifier = (int)$arguments['storage'];
138
-
139
-            // Save state
140
-            SessionUtility::getInstance()->set('lastSelectedStorage', $storageIdentifier);
141
-        }
142
-
143
-        return (int)$storageIdentifier;
144
-    }
145
-
146
-    /**
147
-     * Return the combined parameter from the URL.
148
-     *
149
-     * @return string
150
-     */
151
-    public function getCombinedIdentifier()
152
-    {
153
-
154
-        // Fetch possible combined identifier.
155
-        $combinedIdentifier = GeneralUtility::_GET('id');
156
-
157
-        if ($combinedIdentifier) {
158
-
159
-            // Fix a bug at the Core level: the "id" parameter is encoded again when translating file.
160
-            // Add a loop to decode maximum 999 time!
161
-            $semaphore = 0;
162
-            $semaphoreLimit = 999;
163
-            while (!$this->isWellDecoded($combinedIdentifier) && $semaphore < $semaphoreLimit) {
164
-                $combinedIdentifier = urldecode($combinedIdentifier);
165
-                $semaphore++;
166
-            }
167
-        }
168
-
169
-        return $combinedIdentifier;
170
-    }
171
-
172
-    /**
173
-     * @param $combinedIdentifier
174
-     * @return bool
175
-     */
176
-    protected function isWellDecoded($combinedIdentifier)
177
-    {
178
-        return preg_match('/.*:.*/', $combinedIdentifier);
179
-    }
180
-
181
-    /**
182
-     * @return Folder
183
-     */
184
-    public function getFirstAvailableFolder()
185
-    {
186
-
187
-        // Take the first object of the first storage.
188
-        $storages = $this->getBackendUser()->getFileStorages();
189
-        $storage = reset($storages);
190
-        if ($storage) {
191
-            $folder = $storage->getRootLevelFolder();
192
-        } else {
193
-            throw new \RuntimeException('Could not find any folder to be displayed.', 1444665954);
194
-        }
195
-        return $folder;
196
-    }
197
-
198
-    /**
199
-     * @return Folder
200
-     */
201
-    public function getCurrentFolder()
202
-    {
203
-
204
-        $combinedIdentifier = $this->getCombinedIdentifier();
205
-
206
-        if ($combinedIdentifier) {
207
-            $folder = $this->getFolderForCombinedIdentifier($combinedIdentifier);
208
-        } else {
209
-            $folder = $this->getFirstAvailableFolder();
210
-        }
211
-
212
-        return $folder;
213
-    }
214
-
215
-    /**
216
-     * @param string $combinedIdentifier
217
-     * @return Folder
218
-     */
219
-    public function getFolderForCombinedIdentifier($combinedIdentifier)
220
-    {
221
-
222
-        // Code taken from FileListController.php
223
-        $storage = ResourceFactory::getInstance()->getStorageObjectFromCombinedIdentifier($combinedIdentifier);
224
-        $identifier = substr($combinedIdentifier, strpos($combinedIdentifier, ':') + 1);
225
-        if (!$storage->hasFolder($identifier)) {
226
-            $identifier = $storage->getFolderIdentifierFromFileIdentifier($identifier);
227
-        }
228
-
229
-        // Retrieve the folder object.
230
-        $folder = ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($storage->getUid() . ':' . $identifier);
231
-
232
-        // Disallow the rendering of the processing folder (e.g. could be called manually)
233
-        // and all folders without any defined storage
234
-        if ($folder && ($folder->getStorage()->getUid() == 0 || trim($folder->getStorage()->getProcessingFolder()->getIdentifier(), '/') === trim($folder->getIdentifier(), '/'))) {
235
-            $storage = ResourceFactory::getInstance()->getStorageObjectFromCombinedIdentifier($combinedIdentifier);
236
-            $folder = $storage->getRootLevelFolder();
237
-        }
238
-
239
-        return $folder;
240
-    }
241
-
242
-    /**
243
-     * Tell whether the Folder Tree is display or not.
244
-     *
245
-     * @return bool
246
-     */
247
-    public function hasFolderTree()
248
-    {
249
-        $configuration = $this->getModuleConfiguration();
250
-        return (bool)$configuration['has_folder_tree'];
251
-    }
252
-
253
-    /**
254
-     * Tell whether the sub-folders must be included when browsing.
255
-     *
256
-     * @return bool
257
-     */
258
-    public function hasRecursiveSelection()
259
-    {
260
-
261
-        $parameterPrefix = $this->getModuleLoader()->getParameterPrefix();
262
-        $parameters = GeneralUtility::_GET($parameterPrefix);
263
-
264
-        $hasRecursiveSelection = true;
265
-        if (isset($parameters['hasRecursiveSelection'])) {
266
-            $hasRecursiveSelection = (bool)$parameters['hasRecursiveSelection'];
267
-        }
268
-
269
-        return $hasRecursiveSelection;
270
-    }
271
-
272
-    /**
273
-     * Return the target folder for the uploaded file.
274
-     *
275
-     * @param UploadedFileInterface $uploadedFile
276
-     * @param ResourceStorage $storage
277
-     * @return \TYPO3\CMS\Core\Resource\Folder
278
-     */
279
-    public function getTargetFolderForUploadedFile(UploadedFileInterface $uploadedFile, ResourceStorage $storage)
280
-    {
281
-
282
-        // default is the root level
283
-        $folder = $storage->getRootLevelFolder(); // get the root folder by default
284
-
285
-        // Get a possible mount point coming from the storage record.
286
-        $storageRecord = $storage->getStorageRecord();
287
-        $mountPointIdentifier = $storageRecord['mount_point_file_type_' . $uploadedFile->getType()];
288
-        if ($mountPointIdentifier > 0) {
289
-
290
-            // We don't have a Mount Point repository in FAL, so query the database directly.
291
-            $record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('path', 'sys_filemounts', 'deleted = 0 AND uid = ' . $mountPointIdentifier);
292
-            if (!empty($record['path'])) {
293
-                $folder = $storage->getFolder($record['path']);
294
-            }
295
-        }
296
-        return $folder;
297
-    }
298
-
299
-    /**
300
-     * Return a new target folder when moving file from one storage to another.
301
-     *
302
-     * @param ResourceStorage $storage
303
-     * @param File $file
304
-     * @return \TYPO3\CMS\Core\Resource\Folder
305
-     */
306
-    public function getDefaultFolderInStorage(ResourceStorage $storage, File $file)
307
-    {
308
-
309
-        // default is the root level
310
-        $folder = $storage->getRootLevelFolder();
311
-
312
-        // Retrieve storage record and a possible configured mount point.
313
-        $storageRecord = $storage->getStorageRecord();
314
-        $mountPointIdentifier = $storageRecord['mount_point_file_type_' . $file->getType()];
315
-
316
-        if ($mountPointIdentifier > 0) {
317
-
318
-            // We don't have a Mount Point repository in FAL, so query the database directly.
319
-            $record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('path', 'sys_filemounts', 'deleted = 0 AND uid = ' . $mountPointIdentifier);
320
-            if (!empty($record['path'])) {
321
-                $folder = $storage->getFolder($record['path']);
322
-            }
323
-        }
324
-        return $folder;
325
-    }
326
-
327
-    /**
328
-     * @return array
329
-     */
330
-    protected function getModuleConfiguration()
331
-    {
332
-        return GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('media');
333
-    }
334
-
335
-    /**
336
-     * Return a pointer to the database.
337
-     *
338
-     * @return \Fab\Vidi\Database\DatabaseConnection|object
339
-     */
340
-    protected function getDatabaseConnection()
341
-    {
342
-        return $GLOBALS['TYPO3_DB'];
343
-    }
344
-
345
-    /**
346
-     * Returns an instance of the current Backend User.
347
-     *
348
-     * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
349
-     */
350
-    protected function getBackendUser()
351
-    {
352
-        return $GLOBALS['BE_USER'];
353
-    }
354
-
355
-    /**
356
-     * Return the module loader.
357
-     *
358
-     * @return \Fab\Vidi\Module\ModuleLoader|object
359
-     */
360
-    protected function getModuleLoader()
361
-    {
362
-        return GeneralUtility::makeInstance(\Fab\Vidi\Module\ModuleLoader::class);
363
-    }
28
+	/**
29
+	 * @var string
30
+	 */
31
+	const SIGNATURE = 'user_MediaM1';
32
+
33
+	/**
34
+	 * @var string
35
+	 */
36
+	const PARAMETER_PREFIX = 'tx_media_user_mediam1';
37
+
38
+	/**
39
+	 * @var ResourceStorage
40
+	 */
41
+	protected $currentStorage;
42
+
43
+	/**
44
+	 * @return string
45
+	 */
46
+	static public function getSignature()
47
+	{
48
+		return self::SIGNATURE;
49
+	}
50
+
51
+	/**
52
+	 * @return string
53
+	 */
54
+	static public function getParameterPrefix()
55
+	{
56
+		return self::PARAMETER_PREFIX;
57
+	}
58
+
59
+	/**
60
+	 * Return all storage allowed for the Backend User.
61
+	 *
62
+	 * @throws \RuntimeException
63
+	 * @return ResourceStorage[]
64
+	 */
65
+	public function getAllowedStorages()
66
+	{
67
+
68
+		$storages = $this->getBackendUser()->getFileStorages();
69
+		if (empty($storages)) {
70
+			throw new \RuntimeException('No storage is accessible for the current BE User. Forgotten to define a mount point for this BE User?', 1380801970);
71
+		}
72
+		return $storages;
73
+	}
74
+
75
+	/**
76
+	 * Returns the current file storage in use.
77
+	 *
78
+	 * @return ResourceStorage
79
+	 */
80
+	public function getCurrentStorage()
81
+	{
82
+		if (is_null($this->currentStorage)) {
83
+
84
+			$storageIdentifier = $this->getStorageIdentifierFromSessionOrArguments();
85
+
86
+			if ($storageIdentifier > 0) {
87
+				$currentStorage = ResourceFactory::getInstance()->getStorageObject($storageIdentifier);
88
+			} else {
89
+
90
+				// We differentiate the cases whether the User is admin or not.
91
+				if ($this->getBackendUser()->isAdmin()) {
92
+
93
+					$currentStorage = ResourceFactory::getInstance()->getDefaultStorage();
94
+
95
+					// Not default storage has been flagged in "sys_file_storage".
96
+					// Fallback approach: take the first storage as the current.
97
+					if (!$currentStorage) {
98
+						/** @var $storageRepository StorageRepository */
99
+						$storageRepository = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class);
100
+
101
+						$storages = $storageRepository->findAll();
102
+						$currentStorage = current($storages);
103
+					}
104
+				} else {
105
+					$fileMounts = $this->getBackendUser()->getFileMountRecords();
106
+					$firstFileMount = current($fileMounts);
107
+					$currentStorage = ResourceFactory::getInstance()->getStorageObject($firstFileMount['base']);
108
+				}
109
+			}
110
+
111
+			$this->currentStorage = $currentStorage;
112
+		}
113
+		return $this->currentStorage;
114
+	}
115
+
116
+	/**
117
+	 * Retrieve a possible storage identifier from the session or from the arguments.
118
+	 *
119
+	 * @return int
120
+	 */
121
+	protected function getStorageIdentifierFromSessionOrArguments()
122
+	{
123
+
124
+		// Default value
125
+		$storageIdentifier = 0;
126
+
127
+		// Get last selected storage from User settings
128
+		if (SessionUtility::getInstance()->get('lastSelectedStorage') > 0) {
129
+			$storageIdentifier = SessionUtility::getInstance()->get('lastSelectedStorage');
130
+		}
131
+
132
+		$argumentPrefix = $this->getModuleLoader()->getParameterPrefix();
133
+		$arguments = GeneralUtility::_GET($argumentPrefix);
134
+
135
+		// Override selected storage from the session if GET argument "storage" is detected.
136
+		if (!empty($arguments['storage']) && (int)$arguments['storage'] > 0) {
137
+			$storageIdentifier = (int)$arguments['storage'];
138
+
139
+			// Save state
140
+			SessionUtility::getInstance()->set('lastSelectedStorage', $storageIdentifier);
141
+		}
142
+
143
+		return (int)$storageIdentifier;
144
+	}
145
+
146
+	/**
147
+	 * Return the combined parameter from the URL.
148
+	 *
149
+	 * @return string
150
+	 */
151
+	public function getCombinedIdentifier()
152
+	{
153
+
154
+		// Fetch possible combined identifier.
155
+		$combinedIdentifier = GeneralUtility::_GET('id');
156
+
157
+		if ($combinedIdentifier) {
158
+
159
+			// Fix a bug at the Core level: the "id" parameter is encoded again when translating file.
160
+			// Add a loop to decode maximum 999 time!
161
+			$semaphore = 0;
162
+			$semaphoreLimit = 999;
163
+			while (!$this->isWellDecoded($combinedIdentifier) && $semaphore < $semaphoreLimit) {
164
+				$combinedIdentifier = urldecode($combinedIdentifier);
165
+				$semaphore++;
166
+			}
167
+		}
168
+
169
+		return $combinedIdentifier;
170
+	}
171
+
172
+	/**
173
+	 * @param $combinedIdentifier
174
+	 * @return bool
175
+	 */
176
+	protected function isWellDecoded($combinedIdentifier)
177
+	{
178
+		return preg_match('/.*:.*/', $combinedIdentifier);
179
+	}
180
+
181
+	/**
182
+	 * @return Folder
183
+	 */
184
+	public function getFirstAvailableFolder()
185
+	{
186
+
187
+		// Take the first object of the first storage.
188
+		$storages = $this->getBackendUser()->getFileStorages();
189
+		$storage = reset($storages);
190
+		if ($storage) {
191
+			$folder = $storage->getRootLevelFolder();
192
+		} else {
193
+			throw new \RuntimeException('Could not find any folder to be displayed.', 1444665954);
194
+		}
195
+		return $folder;
196
+	}
197
+
198
+	/**
199
+	 * @return Folder
200
+	 */
201
+	public function getCurrentFolder()
202
+	{
203
+
204
+		$combinedIdentifier = $this->getCombinedIdentifier();
205
+
206
+		if ($combinedIdentifier) {
207
+			$folder = $this->getFolderForCombinedIdentifier($combinedIdentifier);
208
+		} else {
209
+			$folder = $this->getFirstAvailableFolder();
210
+		}
211
+
212
+		return $folder;
213
+	}
214
+
215
+	/**
216
+	 * @param string $combinedIdentifier
217
+	 * @return Folder
218
+	 */
219
+	public function getFolderForCombinedIdentifier($combinedIdentifier)
220
+	{
221
+
222
+		// Code taken from FileListController.php
223
+		$storage = ResourceFactory::getInstance()->getStorageObjectFromCombinedIdentifier($combinedIdentifier);
224
+		$identifier = substr($combinedIdentifier, strpos($combinedIdentifier, ':') + 1);
225
+		if (!$storage->hasFolder($identifier)) {
226
+			$identifier = $storage->getFolderIdentifierFromFileIdentifier($identifier);
227
+		}
228
+
229
+		// Retrieve the folder object.
230
+		$folder = ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($storage->getUid() . ':' . $identifier);
231
+
232
+		// Disallow the rendering of the processing folder (e.g. could be called manually)
233
+		// and all folders without any defined storage
234
+		if ($folder && ($folder->getStorage()->getUid() == 0 || trim($folder->getStorage()->getProcessingFolder()->getIdentifier(), '/') === trim($folder->getIdentifier(), '/'))) {
235
+			$storage = ResourceFactory::getInstance()->getStorageObjectFromCombinedIdentifier($combinedIdentifier);
236
+			$folder = $storage->getRootLevelFolder();
237
+		}
238
+
239
+		return $folder;
240
+	}
241
+
242
+	/**
243
+	 * Tell whether the Folder Tree is display or not.
244
+	 *
245
+	 * @return bool
246
+	 */
247
+	public function hasFolderTree()
248
+	{
249
+		$configuration = $this->getModuleConfiguration();
250
+		return (bool)$configuration['has_folder_tree'];
251
+	}
252
+
253
+	/**
254
+	 * Tell whether the sub-folders must be included when browsing.
255
+	 *
256
+	 * @return bool
257
+	 */
258
+	public function hasRecursiveSelection()
259
+	{
260
+
261
+		$parameterPrefix = $this->getModuleLoader()->getParameterPrefix();
262
+		$parameters = GeneralUtility::_GET($parameterPrefix);
263
+
264
+		$hasRecursiveSelection = true;
265
+		if (isset($parameters['hasRecursiveSelection'])) {
266
+			$hasRecursiveSelection = (bool)$parameters['hasRecursiveSelection'];
267
+		}
268
+
269
+		return $hasRecursiveSelection;
270
+	}
271
+
272
+	/**
273
+	 * Return the target folder for the uploaded file.
274
+	 *
275
+	 * @param UploadedFileInterface $uploadedFile
276
+	 * @param ResourceStorage $storage
277
+	 * @return \TYPO3\CMS\Core\Resource\Folder
278
+	 */
279
+	public function getTargetFolderForUploadedFile(UploadedFileInterface $uploadedFile, ResourceStorage $storage)
280
+	{
281
+
282
+		// default is the root level
283
+		$folder = $storage->getRootLevelFolder(); // get the root folder by default
284
+
285
+		// Get a possible mount point coming from the storage record.
286
+		$storageRecord = $storage->getStorageRecord();
287
+		$mountPointIdentifier = $storageRecord['mount_point_file_type_' . $uploadedFile->getType()];
288
+		if ($mountPointIdentifier > 0) {
289
+
290
+			// We don't have a Mount Point repository in FAL, so query the database directly.
291
+			$record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('path', 'sys_filemounts', 'deleted = 0 AND uid = ' . $mountPointIdentifier);
292
+			if (!empty($record['path'])) {
293
+				$folder = $storage->getFolder($record['path']);
294
+			}
295
+		}
296
+		return $folder;
297
+	}
298
+
299
+	/**
300
+	 * Return a new target folder when moving file from one storage to another.
301
+	 *
302
+	 * @param ResourceStorage $storage
303
+	 * @param File $file
304
+	 * @return \TYPO3\CMS\Core\Resource\Folder
305
+	 */
306
+	public function getDefaultFolderInStorage(ResourceStorage $storage, File $file)
307
+	{
308
+
309
+		// default is the root level
310
+		$folder = $storage->getRootLevelFolder();
311
+
312
+		// Retrieve storage record and a possible configured mount point.
313
+		$storageRecord = $storage->getStorageRecord();
314
+		$mountPointIdentifier = $storageRecord['mount_point_file_type_' . $file->getType()];
315
+
316
+		if ($mountPointIdentifier > 0) {
317
+
318
+			// We don't have a Mount Point repository in FAL, so query the database directly.
319
+			$record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('path', 'sys_filemounts', 'deleted = 0 AND uid = ' . $mountPointIdentifier);
320
+			if (!empty($record['path'])) {
321
+				$folder = $storage->getFolder($record['path']);
322
+			}
323
+		}
324
+		return $folder;
325
+	}
326
+
327
+	/**
328
+	 * @return array
329
+	 */
330
+	protected function getModuleConfiguration()
331
+	{
332
+		return GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('media');
333
+	}
334
+
335
+	/**
336
+	 * Return a pointer to the database.
337
+	 *
338
+	 * @return \Fab\Vidi\Database\DatabaseConnection|object
339
+	 */
340
+	protected function getDatabaseConnection()
341
+	{
342
+		return $GLOBALS['TYPO3_DB'];
343
+	}
344
+
345
+	/**
346
+	 * Returns an instance of the current Backend User.
347
+	 *
348
+	 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
349
+	 */
350
+	protected function getBackendUser()
351
+	{
352
+		return $GLOBALS['BE_USER'];
353
+	}
354
+
355
+	/**
356
+	 * Return the module loader.
357
+	 *
358
+	 * @return \Fab\Vidi\Module\ModuleLoader|object
359
+	 */
360
+	protected function getModuleLoader()
361
+	{
362
+		return GeneralUtility::makeInstance(\Fab\Vidi\Module\ModuleLoader::class);
363
+	}
364 364
 
365 365
 }
366 366
\ No newline at end of file
Please login to merge, or discard this patch.
Classes/Utility/ImagePresetUtility.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@
 block discarded – undo
54 54
     {
55 55
         $size = ConfigurationUtility::getInstance()->get($preset);
56 56
         if (is_null($size)) {
57
-            throw new \Fab\Media\Exception\EmptyValueException('No value for preset: ' . $preset, 1362501066);
57
+            throw new \Fab\Media\Exception\EmptyValueException('No value for preset: '.$preset, 1362501066);
58 58
         }
59 59
 
60 60
         $this->currentPreset = $preset;
Please login to merge, or discard this patch.
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -16,92 +16,92 @@
 block discarded – undo
16 16
 class ImagePresetUtility implements \TYPO3\CMS\Core\SingletonInterface
17 17
 {
18 18
 
19
-    /**
20
-     * @var array
21
-     */
22
-    protected $store = [];
19
+	/**
20
+	 * @var array
21
+	 */
22
+	protected $store = [];
23 23
 
24
-    /**
25
-     * @var string
26
-     */
27
-    protected $currentPreset = '';
24
+	/**
25
+	 * @var string
26
+	 */
27
+	protected $currentPreset = '';
28 28
 
29
-    /**
30
-     * Returns a class instance
31
-     *
32
-     * @return \Fab\Media\Utility\ImagePresetUtility|object
33
-     */
34
-    static public function getInstance()
35
-    {
36
-        return GeneralUtility::makeInstance(\Fab\Media\Utility\ImagePresetUtility::class);
37
-    }
29
+	/**
30
+	 * Returns a class instance
31
+	 *
32
+	 * @return \Fab\Media\Utility\ImagePresetUtility|object
33
+	 */
34
+	static public function getInstance()
35
+	{
36
+		return GeneralUtility::makeInstance(\Fab\Media\Utility\ImagePresetUtility::class);
37
+	}
38 38
 
39
-    /**
40
-     * Set the current preset value. Preset values come from the settings and can be:
41
-     * image_thumbnail, image_mini, image_small, image_medium, image_large
42
-     *
43
-     * @throws \Fab\Media\Exception\EmptyValueException
44
-     * @param string $preset image_thumbnail, image_mini, ...
45
-     * @return \Fab\Media\Utility\ImagePresetUtility
46
-     */
47
-    public function preset($preset)
48
-    {
49
-        $size = ConfigurationUtility::getInstance()->get($preset);
50
-        if (is_null($size)) {
51
-            throw new \Fab\Media\Exception\EmptyValueException('No value for preset: ' . $preset, 1362501066);
52
-        }
39
+	/**
40
+	 * Set the current preset value. Preset values come from the settings and can be:
41
+	 * image_thumbnail, image_mini, image_small, image_medium, image_large
42
+	 *
43
+	 * @throws \Fab\Media\Exception\EmptyValueException
44
+	 * @param string $preset image_thumbnail, image_mini, ...
45
+	 * @return \Fab\Media\Utility\ImagePresetUtility
46
+	 */
47
+	public function preset($preset)
48
+	{
49
+		$size = ConfigurationUtility::getInstance()->get($preset);
50
+		if (is_null($size)) {
51
+			throw new \Fab\Media\Exception\EmptyValueException('No value for preset: ' . $preset, 1362501066);
52
+		}
53 53
 
54
-        $this->currentPreset = $preset;
55
-        if (!isset($this->store[$this->currentPreset])) {
56
-            // @todo use object Dimension instead
57
-            $dimensions = GeneralUtility::trimExplode('x', $size);
58
-            $this->store[$this->currentPreset]['width'] = empty($dimensions[0]) ? 0 : $dimensions[0];
59
-            $this->store[$this->currentPreset]['height'] = empty($dimensions[1]) ? 0 : $dimensions[1];
60
-        }
61
-        return $this;
62
-    }
54
+		$this->currentPreset = $preset;
55
+		if (!isset($this->store[$this->currentPreset])) {
56
+			// @todo use object Dimension instead
57
+			$dimensions = GeneralUtility::trimExplode('x', $size);
58
+			$this->store[$this->currentPreset]['width'] = empty($dimensions[0]) ? 0 : $dimensions[0];
59
+			$this->store[$this->currentPreset]['height'] = empty($dimensions[1]) ? 0 : $dimensions[1];
60
+		}
61
+		return $this;
62
+	}
63 63
 
64
-    /**
65
-     * @return array
66
-     */
67
-    public function getStore()
68
-    {
69
-        return $this->store;
70
-    }
64
+	/**
65
+	 * @return array
66
+	 */
67
+	public function getStore()
68
+	{
69
+		return $this->store;
70
+	}
71 71
 
72
-    /**
73
-     * @param array $store
74
-     */
75
-    public function setStore($store)
76
-    {
77
-        $this->store = $store;
78
-    }
72
+	/**
73
+	 * @param array $store
74
+	 */
75
+	public function setStore($store)
76
+	{
77
+		$this->store = $store;
78
+	}
79 79
 
80
-    /**
81
-     * Returns width of the current preset.
82
-     *
83
-     * @throws \Fab\Media\Exception\InvalidKeyInArrayException
84
-     * @return int
85
-     */
86
-    public function getWidth()
87
-    {
88
-        if (empty($this->store[$this->currentPreset])) {
89
-            throw new \Fab\Media\Exception\InvalidKeyInArrayException('No existing values for current preset. Have you set a preset?', 1362501853);
90
-        }
91
-        return (int)$this->store[$this->currentPreset]['width'];
92
-    }
80
+	/**
81
+	 * Returns width of the current preset.
82
+	 *
83
+	 * @throws \Fab\Media\Exception\InvalidKeyInArrayException
84
+	 * @return int
85
+	 */
86
+	public function getWidth()
87
+	{
88
+		if (empty($this->store[$this->currentPreset])) {
89
+			throw new \Fab\Media\Exception\InvalidKeyInArrayException('No existing values for current preset. Have you set a preset?', 1362501853);
90
+		}
91
+		return (int)$this->store[$this->currentPreset]['width'];
92
+	}
93 93
 
94
-    /**
95
-     * Returns height of the current preset.
96
-     *
97
-     * @throws \Fab\Media\Exception\InvalidKeyInArrayException
98
-     * @return int
99
-     */
100
-    public function getHeight()
101
-    {
102
-        if (empty($this->store[$this->currentPreset])) {
103
-            throw new \Fab\Media\Exception\InvalidKeyInArrayException('No existing values for current preset. Have you set a preset?', 1362501853);
104
-        }
105
-        return (int)$this->store[$this->currentPreset]['height'];
106
-    }
94
+	/**
95
+	 * Returns height of the current preset.
96
+	 *
97
+	 * @throws \Fab\Media\Exception\InvalidKeyInArrayException
98
+	 * @return int
99
+	 */
100
+	public function getHeight()
101
+	{
102
+		if (empty($this->store[$this->currentPreset])) {
103
+			throw new \Fab\Media\Exception\InvalidKeyInArrayException('No existing values for current preset. Have you set a preset?', 1362501853);
104
+		}
105
+		return (int)$this->store[$this->currentPreset]['height'];
106
+	}
107 107
 }
Please login to merge, or discard this patch.
Classes/Thumbnail/ThumbnailGenerator.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -85,13 +85,13 @@  discard block
 block discarded – undo
85 85
         // Compute a possible limit and offset for the query.
86 86
         $limitAndOffset = '';
87 87
         if ($limit > 0 || $offset > 0) {
88
-            $limitAndOffset = $limit . ' OFFSET ' . $offset;
88
+            $limitAndOffset = $limit.' OFFSET '.$offset;
89 89
         }
90 90
 
91 91
         // Retrieve file records.
92 92
         $clause = 'storage > 0';
93 93
         if ($this->storage) {
94
-            $clause = 'storage = ' . $this->storage->getUid();
94
+            $clause = 'storage = '.$this->storage->getUid();
95 95
         }
96 96
 
97 97
         $query = $this->getDatabaseConnection()->SELECTquery('*', 'sys_file', $clause, '', '', $limitAndOffset);
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
     {
165 165
         $clause = 'storage > 0';
166 166
         if ($this->storage) {
167
-            $clause = 'storage = ' . $this->storage->getUid();
167
+            $clause = 'storage = '.$this->storage->getUid();
168 168
         }
169 169
         $record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('count(*) AS totalNumberOfFiles', 'sys_file', $clause);
170 170
         return (int)$record['totalNumberOfFiles'];
Please login to merge, or discard this patch.
Indentation   +246 added lines, -246 removed lines patch added patch discarded remove patch
@@ -20,251 +20,251 @@
 block discarded – undo
20 20
 class ThumbnailGenerator
21 21
 {
22 22
 
23
-    /**
24
-     * @var int
25
-     */
26
-    protected $numberOfTraversedFiles = 0;
27
-
28
-    /**
29
-     * @var int
30
-     */
31
-    protected $numberOfProcessedFiles = 0;
32
-
33
-    /**
34
-     * @var int
35
-     */
36
-    protected $numberOfMissingFiles = 0;
37
-
38
-    /**
39
-     * @var array
40
-     */
41
-    protected $configuration = [];
42
-
43
-    /**
44
-     * @var ResourceStorage
45
-     */
46
-    protected $storage = null;
47
-
48
-    /**
49
-     * @var Selection
50
-     */
51
-    protected $selection = null;
52
-
53
-    /**
54
-     * @var array
55
-     */
56
-    protected $resultSet = [];
57
-
58
-    /**
59
-     * @var array
60
-     */
61
-    protected $newProcessedFileIdentifiers = [];
62
-
63
-    /**
64
-     * Internal variable
65
-     *
66
-     * @var int
67
-     */
68
-    protected $lastInsertedProcessedFile = 0;
69
-
70
-    /**
71
-     * Generate
72
-     *
73
-     * @param int $limit
74
-     * @param int $offset
75
-     * @return void
76
-     * @throws \TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException
77
-     * @throws \InvalidArgumentException
78
-     * @throws \Fab\Media\Exception\InvalidKeyInArrayException
79
-     * @throws \Fab\Media\Exception\MissingTcaConfigurationException
80
-     */
81
-    public function generate($limit = 0, $offset = 0)
82
-    {
83
-
84
-        // Compute a possible limit and offset for the query.
85
-        $limitAndOffset = '';
86
-        if ($limit > 0 || $offset > 0) {
87
-            $limitAndOffset = $limit . ' OFFSET ' . $offset;
88
-        }
89
-
90
-        // Retrieve file records.
91
-        $clause = 'storage > 0';
92
-        if ($this->storage) {
93
-            $clause = 'storage = ' . $this->storage->getUid();
94
-        }
95
-
96
-        $query = $this->getDatabaseConnection()->SELECTquery('*', 'sys_file', $clause, '', '', $limitAndOffset);
97
-        $resource = $this->getDatabaseConnection()->sql_query($query);
98
-
99
-        while ($row = $this->getDatabaseConnection()->sql_fetch_assoc($resource)) {
100
-
101
-            $file = ResourceFactory::getInstance()->getFileObject($row['uid'], $row);
102
-
103
-            if ($file->exists()) {
104
-
105
-                $thumbnailUri = $this->getThumbnailService($file)
106
-                    ->setOutputType(ThumbnailInterface::OUTPUT_URI)
107
-                    ->setConfiguration($this->configuration)
108
-                    ->create();
109
-
110
-                $this->resultSet[$file->getUid()] = array(
111
-                    'fileUid' => $file->getUid(),
112
-                    'fileIdentifier' => $file->getIdentifier(),
113
-                    'thumbnailUri' => strpos($thumbnailUri, '_processed_') > 0 ? $thumbnailUri : '', // only returns the thumbnail uri if a processed file has been created.
114
-                );
115
-
116
-                if ($this->isNewProcessedFile()) {
117
-                    $this->incrementNumberOfProcessedFiles();
118
-                    $this->newProcessedFileIdentifiers[$file->getUid()] = $this->lastInsertedProcessedFile;
119
-                }
120
-
121
-                $this->incrementNumberOfTraversedFiles();
122
-            } else {
123
-                $this->incrementNumberOfMissingFiles();
124
-            }
125
-        }
126
-
127
-    }
128
-
129
-    /**
130
-     * @return int
131
-     */
132
-    protected function isNewProcessedFile()
133
-    {
134
-        $isNewProcessedFile = false;
135
-        $lastInsertedId = $this->getDatabaseConnection()->sql_insert_id();
136
-        if ($lastInsertedId > 0 && $lastInsertedId !== $this->lastInsertedProcessedFile) {
137
-            $this->lastInsertedProcessedFile = $lastInsertedId;
138
-            $isNewProcessedFile = true;
139
-        }
140
-        return $isNewProcessedFile;
141
-    }
142
-
143
-    /**
144
-     * @return int
145
-     */
146
-    public function getNumberOfTraversedFiles()
147
-    {
148
-        return $this->numberOfTraversedFiles;
149
-    }
150
-
151
-    /**
152
-     * @return int
153
-     */
154
-    public function getNumberOfProcessedFiles()
155
-    {
156
-        return $this->numberOfProcessedFiles;
157
-    }
158
-
159
-    /**
160
-     * @return int
161
-     */
162
-    public function getTotalNumberOfFiles()
163
-    {
164
-        $clause = 'storage > 0';
165
-        if ($this->storage) {
166
-            $clause = 'storage = ' . $this->storage->getUid();
167
-        }
168
-        $record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('count(*) AS totalNumberOfFiles', 'sys_file', $clause);
169
-        return (int)$record['totalNumberOfFiles'];
170
-    }
171
-
172
-    /**
173
-     * @return array
174
-     */
175
-    public function getResultSet()
176
-    {
177
-        return $this->resultSet;
178
-    }
179
-
180
-    /**
181
-     * @return array
182
-     */
183
-    public function getNewProcessedFileIdentifiers()
184
-    {
185
-        return $this->newProcessedFileIdentifiers;
186
-    }
187
-
188
-    /**
189
-     * @return int
190
-     */
191
-    public function getNumberOfMissingFiles()
192
-    {
193
-        return $this->numberOfMissingFiles;
194
-    }
195
-
196
-    /**
197
-     * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage
198
-     * @return $this
199
-     */
200
-    public function setStorage($storage)
201
-    {
202
-        $this->storage = $storage;
203
-        return $this;
204
-    }
205
-
206
-    /**
207
-     * @param \Fab\Vidi\Domain\Model\Selection $selection
208
-     * @return $this
209
-     */
210
-    public function setSelection($selection)
211
-    {
212
-        $this->selection = $selection;
213
-        return $this;
214
-    }
215
-
216
-    /**
217
-     * @param array $configuration
218
-     * @return $this
219
-     */
220
-    public function setConfiguration($configuration)
221
-    {
222
-        $this->configuration = $configuration;
223
-        return $this;
224
-    }
225
-
226
-    /**
227
-     * @param File $file
228
-     * @return ThumbnailService
229
-     * @throws \InvalidArgumentException
230
-     */
231
-    protected function getThumbnailService(File $file)
232
-    {
233
-        return GeneralUtility::makeInstance(ThumbnailService::class, $file);
234
-    }
235
-
236
-    /**
237
-     * @return void
238
-     */
239
-    protected function incrementNumberOfTraversedFiles()
240
-    {
241
-        $this->numberOfTraversedFiles++;
242
-    }
243
-
244
-    /**
245
-     * @return void
246
-     */
247
-    protected function incrementNumberOfMissingFiles()
248
-    {
249
-        $this->numberOfMissingFiles++;
250
-    }
251
-
252
-    /**
253
-     * @return void
254
-     */
255
-    protected function incrementNumberOfProcessedFiles()
256
-    {
257
-        $this->numberOfProcessedFiles++;
258
-    }
259
-
260
-    /**
261
-     * Returns a pointer to the database.
262
-     *
263
-     * @return \Fab\Vidi\Database\DatabaseConnection
264
-     */
265
-    protected function getDatabaseConnection()
266
-    {
267
-        return $GLOBALS['TYPO3_DB'];
268
-    }
23
+	/**
24
+	 * @var int
25
+	 */
26
+	protected $numberOfTraversedFiles = 0;
27
+
28
+	/**
29
+	 * @var int
30
+	 */
31
+	protected $numberOfProcessedFiles = 0;
32
+
33
+	/**
34
+	 * @var int
35
+	 */
36
+	protected $numberOfMissingFiles = 0;
37
+
38
+	/**
39
+	 * @var array
40
+	 */
41
+	protected $configuration = [];
42
+
43
+	/**
44
+	 * @var ResourceStorage
45
+	 */
46
+	protected $storage = null;
47
+
48
+	/**
49
+	 * @var Selection
50
+	 */
51
+	protected $selection = null;
52
+
53
+	/**
54
+	 * @var array
55
+	 */
56
+	protected $resultSet = [];
57
+
58
+	/**
59
+	 * @var array
60
+	 */
61
+	protected $newProcessedFileIdentifiers = [];
62
+
63
+	/**
64
+	 * Internal variable
65
+	 *
66
+	 * @var int
67
+	 */
68
+	protected $lastInsertedProcessedFile = 0;
69
+
70
+	/**
71
+	 * Generate
72
+	 *
73
+	 * @param int $limit
74
+	 * @param int $offset
75
+	 * @return void
76
+	 * @throws \TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException
77
+	 * @throws \InvalidArgumentException
78
+	 * @throws \Fab\Media\Exception\InvalidKeyInArrayException
79
+	 * @throws \Fab\Media\Exception\MissingTcaConfigurationException
80
+	 */
81
+	public function generate($limit = 0, $offset = 0)
82
+	{
83
+
84
+		// Compute a possible limit and offset for the query.
85
+		$limitAndOffset = '';
86
+		if ($limit > 0 || $offset > 0) {
87
+			$limitAndOffset = $limit . ' OFFSET ' . $offset;
88
+		}
89
+
90
+		// Retrieve file records.
91
+		$clause = 'storage > 0';
92
+		if ($this->storage) {
93
+			$clause = 'storage = ' . $this->storage->getUid();
94
+		}
95
+
96
+		$query = $this->getDatabaseConnection()->SELECTquery('*', 'sys_file', $clause, '', '', $limitAndOffset);
97
+		$resource = $this->getDatabaseConnection()->sql_query($query);
98
+
99
+		while ($row = $this->getDatabaseConnection()->sql_fetch_assoc($resource)) {
100
+
101
+			$file = ResourceFactory::getInstance()->getFileObject($row['uid'], $row);
102
+
103
+			if ($file->exists()) {
104
+
105
+				$thumbnailUri = $this->getThumbnailService($file)
106
+					->setOutputType(ThumbnailInterface::OUTPUT_URI)
107
+					->setConfiguration($this->configuration)
108
+					->create();
109
+
110
+				$this->resultSet[$file->getUid()] = array(
111
+					'fileUid' => $file->getUid(),
112
+					'fileIdentifier' => $file->getIdentifier(),
113
+					'thumbnailUri' => strpos($thumbnailUri, '_processed_') > 0 ? $thumbnailUri : '', // only returns the thumbnail uri if a processed file has been created.
114
+				);
115
+
116
+				if ($this->isNewProcessedFile()) {
117
+					$this->incrementNumberOfProcessedFiles();
118
+					$this->newProcessedFileIdentifiers[$file->getUid()] = $this->lastInsertedProcessedFile;
119
+				}
120
+
121
+				$this->incrementNumberOfTraversedFiles();
122
+			} else {
123
+				$this->incrementNumberOfMissingFiles();
124
+			}
125
+		}
126
+
127
+	}
128
+
129
+	/**
130
+	 * @return int
131
+	 */
132
+	protected function isNewProcessedFile()
133
+	{
134
+		$isNewProcessedFile = false;
135
+		$lastInsertedId = $this->getDatabaseConnection()->sql_insert_id();
136
+		if ($lastInsertedId > 0 && $lastInsertedId !== $this->lastInsertedProcessedFile) {
137
+			$this->lastInsertedProcessedFile = $lastInsertedId;
138
+			$isNewProcessedFile = true;
139
+		}
140
+		return $isNewProcessedFile;
141
+	}
142
+
143
+	/**
144
+	 * @return int
145
+	 */
146
+	public function getNumberOfTraversedFiles()
147
+	{
148
+		return $this->numberOfTraversedFiles;
149
+	}
150
+
151
+	/**
152
+	 * @return int
153
+	 */
154
+	public function getNumberOfProcessedFiles()
155
+	{
156
+		return $this->numberOfProcessedFiles;
157
+	}
158
+
159
+	/**
160
+	 * @return int
161
+	 */
162
+	public function getTotalNumberOfFiles()
163
+	{
164
+		$clause = 'storage > 0';
165
+		if ($this->storage) {
166
+			$clause = 'storage = ' . $this->storage->getUid();
167
+		}
168
+		$record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('count(*) AS totalNumberOfFiles', 'sys_file', $clause);
169
+		return (int)$record['totalNumberOfFiles'];
170
+	}
171
+
172
+	/**
173
+	 * @return array
174
+	 */
175
+	public function getResultSet()
176
+	{
177
+		return $this->resultSet;
178
+	}
179
+
180
+	/**
181
+	 * @return array
182
+	 */
183
+	public function getNewProcessedFileIdentifiers()
184
+	{
185
+		return $this->newProcessedFileIdentifiers;
186
+	}
187
+
188
+	/**
189
+	 * @return int
190
+	 */
191
+	public function getNumberOfMissingFiles()
192
+	{
193
+		return $this->numberOfMissingFiles;
194
+	}
195
+
196
+	/**
197
+	 * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage
198
+	 * @return $this
199
+	 */
200
+	public function setStorage($storage)
201
+	{
202
+		$this->storage = $storage;
203
+		return $this;
204
+	}
205
+
206
+	/**
207
+	 * @param \Fab\Vidi\Domain\Model\Selection $selection
208
+	 * @return $this
209
+	 */
210
+	public function setSelection($selection)
211
+	{
212
+		$this->selection = $selection;
213
+		return $this;
214
+	}
215
+
216
+	/**
217
+	 * @param array $configuration
218
+	 * @return $this
219
+	 */
220
+	public function setConfiguration($configuration)
221
+	{
222
+		$this->configuration = $configuration;
223
+		return $this;
224
+	}
225
+
226
+	/**
227
+	 * @param File $file
228
+	 * @return ThumbnailService
229
+	 * @throws \InvalidArgumentException
230
+	 */
231
+	protected function getThumbnailService(File $file)
232
+	{
233
+		return GeneralUtility::makeInstance(ThumbnailService::class, $file);
234
+	}
235
+
236
+	/**
237
+	 * @return void
238
+	 */
239
+	protected function incrementNumberOfTraversedFiles()
240
+	{
241
+		$this->numberOfTraversedFiles++;
242
+	}
243
+
244
+	/**
245
+	 * @return void
246
+	 */
247
+	protected function incrementNumberOfMissingFiles()
248
+	{
249
+		$this->numberOfMissingFiles++;
250
+	}
251
+
252
+	/**
253
+	 * @return void
254
+	 */
255
+	protected function incrementNumberOfProcessedFiles()
256
+	{
257
+		$this->numberOfProcessedFiles++;
258
+	}
259
+
260
+	/**
261
+	 * Returns a pointer to the database.
262
+	 *
263
+	 * @return \Fab\Vidi\Database\DatabaseConnection
264
+	 */
265
+	protected function getDatabaseConnection()
266
+	{
267
+		return $GLOBALS['TYPO3_DB'];
268
+	}
269 269
 
270 270
 }
Please login to merge, or discard this patch.
Classes/Thumbnail/AbstractThumbnailProcessor.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -131,7 +131,7 @@
 block discarded – undo
131 131
     public function prefixUri($uri)
132 132
     {
133 133
         if ($this->isFrontendMode() && $this->getFrontendObject()->absRefPrefix) {
134
-            $uri = $this->getFrontendObject()->absRefPrefix . $uri;
134
+            $uri = $this->getFrontendObject()->absRefPrefix.$uri;
135 135
         }
136 136
         return $uri;
137 137
     }
Please login to merge, or discard this patch.
Indentation   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -19,155 +19,155 @@
 block discarded – undo
19 19
 abstract class AbstractThumbnailProcessor implements ThumbnailProcessorInterface
20 20
 {
21 21
 
22
-    /**
23
-     * @var ThumbnailService
24
-     */
25
-    protected $thumbnailService;
26
-
27
-    /**
28
-     * Store a Processed File along the processing.
29
-     *
30
-     * @var \TYPO3\CMS\Core\Resource\ProcessedFile
31
-     */
32
-    protected $processedFile;
33
-
34
-    /**
35
-     * Define what are the rendering steps for a thumbnail.
36
-     *
37
-     * @var array
38
-     */
39
-    protected $renderingSteps = [
40
-        ThumbnailInterface::OUTPUT_URI => 'renderUri',
41
-        ThumbnailInterface::OUTPUT_IMAGE => 'renderTagImage',
42
-        ThumbnailInterface::OUTPUT_IMAGE_WRAPPED => 'renderTagAnchor',
43
-    ];
44
-
45
-    /**
46
-     * @param ThumbnailService $thumbnailService
47
-     * @return $this
48
-     */
49
-    public function setThumbnailService(ThumbnailService $thumbnailService)
50
-    {
51
-        $this->thumbnailService = $thumbnailService;
52
-        return $this;
53
-    }
54
-
55
-    /**
56
-     * Return what needs to be rendered
57
-     *
58
-     * @return array
59
-     */
60
-    protected function getRenderingSteps()
61
-    {
62
-        $position = array_search($this->thumbnailService->getOutputType(), array_keys($this->renderingSteps));
63
-        return array_slice($this->renderingSteps, 0, $position + 1);
64
-    }
65
-
66
-
67
-    /**
68
-     * Render additional attribute for this DOM element.
69
-     *
70
-     * @return string
71
-     */
72
-    protected function renderAttributes()
73
-    {
74
-        $result = '';
75
-        $attributes = $this->thumbnailService->getAttributes();
76
-        if (is_array($attributes)) {
77
-            foreach ($attributes as $attribute => $value) {
78
-                $result .= sprintf('%s="%s" ',
79
-                    htmlspecialchars($attribute),
80
-                    htmlspecialchars($value)
81
-                );
82
-            }
83
-        }
84
-        return $result;
85
-    }
86
-
87
-    /**
88
-     * @return array
89
-     * @throws \Fab\Media\Exception\InvalidKeyInArrayException
90
-     * @throws \Fab\Media\Exception\EmptyValueException
91
-     */
92
-    protected function getConfiguration()
93
-    {
94
-        $configuration = $this->thumbnailService->getConfiguration();
95
-        if (!$configuration) {
96
-            $dimension = ImagePresetUtility::getInstance()->preset('image_thumbnail');
97
-            $configuration = array(
98
-                'width' => $dimension->getWidth(),
99
-                'height' => $dimension->getHeight(),
100
-            );
101
-        }
102
-        return $configuration;
103
-    }
104
-
105
-    /**
106
-     * Returns a path to an icon given an extension.
107
-     *
108
-     * @param string $extension File extension
109
-     * @return string
110
-     */
111
-    protected function getIcon($extension)
112
-    {
113
-        $resource = Path::getRelativePath(sprintf('Icons/MimeType/%s.png', $extension));
114
-
115
-        // If file is not found, fall back to a default icon
116
-        if (Path::notExists($resource)) {
117
-            $resource = Path::getRelativePath('Icons/MissingMimeTypeIcon.png');
118
-        }
119
-
120
-        return $resource;
121
-    }
122
-
123
-    /**
124
-     * @param string $uri
125
-     * @return string
126
-     */
127
-    public function prefixUri($uri)
128
-    {
129
-        if ($this->isFrontendMode() && $this->getFrontendObject()->absRefPrefix) {
130
-            $uri = $this->getFrontendObject()->absRefPrefix . $uri;
131
-        }
132
-        return $uri;
133
-    }
134
-
135
-    /**
136
-     * Returns true whether an thumbnail can be generated
137
-     *
138
-     * @param string $extension File extension
139
-     * @return boolean
140
-     */
141
-    protected function isThumbnailPossible($extension)
142
-    {
143
-        return GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], strtolower($extension));
144
-    }
145
-
146
-    /**
147
-     * @return File
148
-     */
149
-    protected function getFile()
150
-    {
151
-        return $this->thumbnailService->getFile();
152
-    }
153
-
154
-    /**
155
-     * Returns whether the current mode is Frontend
156
-     *
157
-     * @return bool
158
-     */
159
-    protected function isFrontendMode()
160
-    {
161
-        return TYPO3_MODE === 'FE';
162
-    }
163
-
164
-    /**
165
-     * Returns an instance of the Frontend object.
166
-     *
167
-     * @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
168
-     */
169
-    protected function getFrontendObject()
170
-    {
171
-        return $GLOBALS['TSFE'];
172
-    }
22
+	/**
23
+	 * @var ThumbnailService
24
+	 */
25
+	protected $thumbnailService;
26
+
27
+	/**
28
+	 * Store a Processed File along the processing.
29
+	 *
30
+	 * @var \TYPO3\CMS\Core\Resource\ProcessedFile
31
+	 */
32
+	protected $processedFile;
33
+
34
+	/**
35
+	 * Define what are the rendering steps for a thumbnail.
36
+	 *
37
+	 * @var array
38
+	 */
39
+	protected $renderingSteps = [
40
+		ThumbnailInterface::OUTPUT_URI => 'renderUri',
41
+		ThumbnailInterface::OUTPUT_IMAGE => 'renderTagImage',
42
+		ThumbnailInterface::OUTPUT_IMAGE_WRAPPED => 'renderTagAnchor',
43
+	];
44
+
45
+	/**
46
+	 * @param ThumbnailService $thumbnailService
47
+	 * @return $this
48
+	 */
49
+	public function setThumbnailService(ThumbnailService $thumbnailService)
50
+	{
51
+		$this->thumbnailService = $thumbnailService;
52
+		return $this;
53
+	}
54
+
55
+	/**
56
+	 * Return what needs to be rendered
57
+	 *
58
+	 * @return array
59
+	 */
60
+	protected function getRenderingSteps()
61
+	{
62
+		$position = array_search($this->thumbnailService->getOutputType(), array_keys($this->renderingSteps));
63
+		return array_slice($this->renderingSteps, 0, $position + 1);
64
+	}
65
+
66
+
67
+	/**
68
+	 * Render additional attribute for this DOM element.
69
+	 *
70
+	 * @return string
71
+	 */
72
+	protected function renderAttributes()
73
+	{
74
+		$result = '';
75
+		$attributes = $this->thumbnailService->getAttributes();
76
+		if (is_array($attributes)) {
77
+			foreach ($attributes as $attribute => $value) {
78
+				$result .= sprintf('%s="%s" ',
79
+					htmlspecialchars($attribute),
80
+					htmlspecialchars($value)
81
+				);
82
+			}
83
+		}
84
+		return $result;
85
+	}
86
+
87
+	/**
88
+	 * @return array
89
+	 * @throws \Fab\Media\Exception\InvalidKeyInArrayException
90
+	 * @throws \Fab\Media\Exception\EmptyValueException
91
+	 */
92
+	protected function getConfiguration()
93
+	{
94
+		$configuration = $this->thumbnailService->getConfiguration();
95
+		if (!$configuration) {
96
+			$dimension = ImagePresetUtility::getInstance()->preset('image_thumbnail');
97
+			$configuration = array(
98
+				'width' => $dimension->getWidth(),
99
+				'height' => $dimension->getHeight(),
100
+			);
101
+		}
102
+		return $configuration;
103
+	}
104
+
105
+	/**
106
+	 * Returns a path to an icon given an extension.
107
+	 *
108
+	 * @param string $extension File extension
109
+	 * @return string
110
+	 */
111
+	protected function getIcon($extension)
112
+	{
113
+		$resource = Path::getRelativePath(sprintf('Icons/MimeType/%s.png', $extension));
114
+
115
+		// If file is not found, fall back to a default icon
116
+		if (Path::notExists($resource)) {
117
+			$resource = Path::getRelativePath('Icons/MissingMimeTypeIcon.png');
118
+		}
119
+
120
+		return $resource;
121
+	}
122
+
123
+	/**
124
+	 * @param string $uri
125
+	 * @return string
126
+	 */
127
+	public function prefixUri($uri)
128
+	{
129
+		if ($this->isFrontendMode() && $this->getFrontendObject()->absRefPrefix) {
130
+			$uri = $this->getFrontendObject()->absRefPrefix . $uri;
131
+		}
132
+		return $uri;
133
+	}
134
+
135
+	/**
136
+	 * Returns true whether an thumbnail can be generated
137
+	 *
138
+	 * @param string $extension File extension
139
+	 * @return boolean
140
+	 */
141
+	protected function isThumbnailPossible($extension)
142
+	{
143
+		return GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], strtolower($extension));
144
+	}
145
+
146
+	/**
147
+	 * @return File
148
+	 */
149
+	protected function getFile()
150
+	{
151
+		return $this->thumbnailService->getFile();
152
+	}
153
+
154
+	/**
155
+	 * Returns whether the current mode is Frontend
156
+	 *
157
+	 * @return bool
158
+	 */
159
+	protected function isFrontendMode()
160
+	{
161
+		return TYPO3_MODE === 'FE';
162
+	}
163
+
164
+	/**
165
+	 * Returns an instance of the Frontend object.
166
+	 *
167
+	 * @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
168
+	 */
169
+	protected function getFrontendObject()
170
+	{
171
+		return $GLOBALS['TSFE'];
172
+	}
173 173
 }
Please login to merge, or discard this patch.
Classes/Thumbnail/ImageThumbnailProcessor.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 
92 92
         return sprintf('<img src="%s%s" title="%s" alt="%s" %s/>',
93 93
             $result,
94
-            $this->thumbnailService->getAppendTimeStamp() ? $parameterSeparator . $this->processedFile->getProperty('tstamp') : '',
94
+            $this->thumbnailService->getAppendTimeStamp() ? $parameterSeparator.$this->processedFile->getProperty('tstamp') : '',
95 95
             $this->getTitle(),
96 96
             $this->getTitle(),
97 97
             $this->renderAttributes()
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 
147 147
         return sprintf('<a href="%s%s" target="%s" data-uid="%s">%s</a>',
148 148
             $url,
149
-            $this->thumbnailService->getAppendTimeStamp() && !$this->thumbnailService->getAnchorUri() ? $parameterSeparator . $file->getProperty('tstamp') : '',
149
+            $this->thumbnailService->getAppendTimeStamp() && !$this->thumbnailService->getAnchorUri() ? $parameterSeparator.$file->getProperty('tstamp') : '',
150 150
             $this->thumbnailService->getTarget(),
151 151
             $file->getUid(),
152 152
             $result
Please login to merge, or discard this patch.
Indentation   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -16,180 +16,180 @@
 block discarded – undo
16 16
 class ImageThumbnailProcessor extends AbstractThumbnailProcessor
17 17
 {
18 18
 
19
-    /**
20
-     * @var array
21
-     */
22
-    protected $defaultConfigurationWrap = array(
23
-        'width' => 0,
24
-        'height' => 0,
25
-    );
26
-
27
-    /**
28
-     * Render a thumbnail of a resource of type image.
29
-     *
30
-     * @return string
31
-     */
32
-    public function create()
33
-    {
34
-        $steps = $this->getRenderingSteps();
35
-
36
-        $result = '';
37
-        while ($step = array_shift($steps)) {
38
-            $result = $this->$step($result);
39
-        }
40
-
41
-        return $result;
42
-    }
43
-
44
-    /**
45
-     * Render the URI of the thumbnail.
46
-     *
47
-     * @return string
48
-     * @throws \Fab\Media\Exception\EmptyValueException
49
-     */
50
-    public function renderUri()
51
-    {
52
-
53
-        // Makes sure the width and the height of the thumbnail is not bigger than the actual file
54
-        $configuration = $this->getConfiguration();
55
-        if (!empty($configuration['width']) && $configuration['width'] > $this->getFile()->getProperty('width')) {
56
-            $configuration['width'] = $this->getFile()->getProperty('width');
57
-        }
58
-        if (!empty($configuration['height']) && $configuration['height'] > $this->getFile()->getProperty('height')) {
59
-            $configuration['height'] = $this->getFile()->getProperty('height');
60
-        }
61
-
62
-        $configuration = $this->computeFinalImageDimension($configuration);
63
-        $this->processedFile = $this->getFile()->process($this->getProcessingType(), $configuration);
64
-        $uri = $this->processedFile->getPublicUrl(true);
65
-
66
-        // Update time stamp of processed image at this stage. This is needed for the browser to get new version of the thumbnail.
67
-        if ($this->processedFile->getProperty('originalfilesha1') !== $this->getFile()->getProperty('sha1')) {
68
-            $this->processedFile->updateProperties(array('tstamp' => $this->getFile()->getProperty('tstamp')));
69
-        }
70
-
71
-        return $this->prefixUri($uri);
72
-    }
73
-
74
-    /**
75
-     * Render the tag image which is the main one for a thumbnail.
76
-     *
77
-     * @param string $result
78
-     * @return string
79
-     */
80
-    public function renderTagImage($result)
81
-    {
82
-
83
-        // Variable $result corresponds to an URL in this case.
84
-        // Analyse the URL and compute the adequate separator between arguments.
85
-        $parameterSeparator = strpos($result, '?') === false ? '?' : '&';
86
-
87
-        return sprintf('<img src="%s%s" title="%s" alt="%s" %s/>',
88
-            $result,
89
-            $this->thumbnailService->getAppendTimeStamp() ? $parameterSeparator . $this->processedFile->getProperty('tstamp') : '',
90
-            $this->getTitle(),
91
-            $this->getTitle(),
92
-            $this->renderAttributes()
93
-        );
94
-    }
95
-
96
-    /**
97
-     * Compute and return the title of the file.
98
-     *
99
-     * @return string
100
-     */
101
-    protected function getTitle()
102
-    {
103
-        $result = $this->getFile()->getProperty('title');
104
-        if (!$result) {
105
-            $result = $this->getFile()->getName();
106
-        }
107
-        return htmlspecialchars($result);
108
-    }
109
-
110
-    /**
111
-     * Render a wrapping anchor around the thumbnail.
112
-     *
113
-     * @param string $result
114
-     * @return string
115
-     */
116
-    public function renderTagAnchor($result)
117
-    {
118
-
119
-        $file = $this->getFile();
120
-
121
-        // Perhaps the wrapping file must be processed
122
-        $configurationWrap = $this->thumbnailService->getConfigurationWrap();
123
-
124
-        // Make sure we have configurationWrap initialized correctly
125
-        if (!empty($configurationWrap['width']) || !empty($configurationWrap['height'])) {
126
-            $configurationWrap = array_merge($this->defaultConfigurationWrap, $configurationWrap);
127
-
128
-            // It looks maxW or maxH does not work as expected with CONTEXT_IMAGEPREVIEW...
129
-            // ... uses "width" and "height" instead.
130
-            if ($configurationWrap['width'] < $this->getFile()->getProperty('width')
131
-                || $configurationWrap['height'] < $this->getFile()->getProperty('height')
132
-            ) {
133
-                $configurationWrap = $this->computeFinalImageDimension($configurationWrap);
134
-                $file = $this->getFile()->process($this->getProcessingType(), $configurationWrap);
135
-            }
136
-        }
137
-
138
-        // Analyse the current $url and compute the adequate separator between arguments.
139
-        $url = $this->thumbnailService->getAnchorUri() ? $this->thumbnailService->getAnchorUri() : $file->getPublicUrl(true);
140
-        $parameterSeparator = strpos($url, '?') === false ? '?' : '&';
141
-
142
-        return sprintf('<a href="%s%s" target="%s" data-uid="%s">%s</a>',
143
-            $url,
144
-            $this->thumbnailService->getAppendTimeStamp() && !$this->thumbnailService->getAnchorUri() ? $parameterSeparator . $file->getProperty('tstamp') : '',
145
-            $this->thumbnailService->getTarget(),
146
-            $file->getUid(),
147
-            $result
148
-        );
149
-    }
150
-
151
-    /**
152
-     * Compute the final configuration for the image preview.
153
-     * Keep ratio of width / height for the image.
154
-     *
155
-     * @param array $configuration
156
-     * @return array
157
-     */
158
-    protected function computeFinalImageDimension(array $configuration)
159
-    {
160
-        $ratio = $this->computeImageRatio();
161
-
162
-        if ($ratio > 1) {
163
-            $configuration['height'] = round($configuration['width'] / $ratio);
164
-        } else {
165
-            $configuration['width'] = round($configuration['height'] * $ratio);
166
-        }
167
-        return $configuration;
168
-    }
169
-
170
-    /**
171
-     * Compute the width / height ratio of the image.
172
-     *
173
-     * @return null|float
174
-     */
175
-    protected function computeImageRatio()
176
-    {
177
-        $ratio = null;
178
-        if ($this->getFile()->getProperty('width') > 0 && $this->getFile()->getProperty('height') > 0) {
179
-            $ratio = $this->getFile()->getProperty('width') / $this->getFile()->getProperty('height');
180
-        }
181
-        return $ratio;
182
-    }
183
-
184
-    /**
185
-     * @return string
186
-     */
187
-    public function getProcessingType()
188
-    {
189
-        if ($this->thumbnailService->getProcessingType() === null) {
190
-            return ProcessedFile::CONTEXT_IMAGECROPSCALEMASK;
191
-        }
192
-        return $this->thumbnailService->getProcessingType();
193
-    }
19
+	/**
20
+	 * @var array
21
+	 */
22
+	protected $defaultConfigurationWrap = array(
23
+		'width' => 0,
24
+		'height' => 0,
25
+	);
26
+
27
+	/**
28
+	 * Render a thumbnail of a resource of type image.
29
+	 *
30
+	 * @return string
31
+	 */
32
+	public function create()
33
+	{
34
+		$steps = $this->getRenderingSteps();
35
+
36
+		$result = '';
37
+		while ($step = array_shift($steps)) {
38
+			$result = $this->$step($result);
39
+		}
40
+
41
+		return $result;
42
+	}
43
+
44
+	/**
45
+	 * Render the URI of the thumbnail.
46
+	 *
47
+	 * @return string
48
+	 * @throws \Fab\Media\Exception\EmptyValueException
49
+	 */
50
+	public function renderUri()
51
+	{
52
+
53
+		// Makes sure the width and the height of the thumbnail is not bigger than the actual file
54
+		$configuration = $this->getConfiguration();
55
+		if (!empty($configuration['width']) && $configuration['width'] > $this->getFile()->getProperty('width')) {
56
+			$configuration['width'] = $this->getFile()->getProperty('width');
57
+		}
58
+		if (!empty($configuration['height']) && $configuration['height'] > $this->getFile()->getProperty('height')) {
59
+			$configuration['height'] = $this->getFile()->getProperty('height');
60
+		}
61
+
62
+		$configuration = $this->computeFinalImageDimension($configuration);
63
+		$this->processedFile = $this->getFile()->process($this->getProcessingType(), $configuration);
64
+		$uri = $this->processedFile->getPublicUrl(true);
65
+
66
+		// Update time stamp of processed image at this stage. This is needed for the browser to get new version of the thumbnail.
67
+		if ($this->processedFile->getProperty('originalfilesha1') !== $this->getFile()->getProperty('sha1')) {
68
+			$this->processedFile->updateProperties(array('tstamp' => $this->getFile()->getProperty('tstamp')));
69
+		}
70
+
71
+		return $this->prefixUri($uri);
72
+	}
73
+
74
+	/**
75
+	 * Render the tag image which is the main one for a thumbnail.
76
+	 *
77
+	 * @param string $result
78
+	 * @return string
79
+	 */
80
+	public function renderTagImage($result)
81
+	{
82
+
83
+		// Variable $result corresponds to an URL in this case.
84
+		// Analyse the URL and compute the adequate separator between arguments.
85
+		$parameterSeparator = strpos($result, '?') === false ? '?' : '&';
86
+
87
+		return sprintf('<img src="%s%s" title="%s" alt="%s" %s/>',
88
+			$result,
89
+			$this->thumbnailService->getAppendTimeStamp() ? $parameterSeparator . $this->processedFile->getProperty('tstamp') : '',
90
+			$this->getTitle(),
91
+			$this->getTitle(),
92
+			$this->renderAttributes()
93
+		);
94
+	}
95
+
96
+	/**
97
+	 * Compute and return the title of the file.
98
+	 *
99
+	 * @return string
100
+	 */
101
+	protected function getTitle()
102
+	{
103
+		$result = $this->getFile()->getProperty('title');
104
+		if (!$result) {
105
+			$result = $this->getFile()->getName();
106
+		}
107
+		return htmlspecialchars($result);
108
+	}
109
+
110
+	/**
111
+	 * Render a wrapping anchor around the thumbnail.
112
+	 *
113
+	 * @param string $result
114
+	 * @return string
115
+	 */
116
+	public function renderTagAnchor($result)
117
+	{
118
+
119
+		$file = $this->getFile();
120
+
121
+		// Perhaps the wrapping file must be processed
122
+		$configurationWrap = $this->thumbnailService->getConfigurationWrap();
123
+
124
+		// Make sure we have configurationWrap initialized correctly
125
+		if (!empty($configurationWrap['width']) || !empty($configurationWrap['height'])) {
126
+			$configurationWrap = array_merge($this->defaultConfigurationWrap, $configurationWrap);
127
+
128
+			// It looks maxW or maxH does not work as expected with CONTEXT_IMAGEPREVIEW...
129
+			// ... uses "width" and "height" instead.
130
+			if ($configurationWrap['width'] < $this->getFile()->getProperty('width')
131
+				|| $configurationWrap['height'] < $this->getFile()->getProperty('height')
132
+			) {
133
+				$configurationWrap = $this->computeFinalImageDimension($configurationWrap);
134
+				$file = $this->getFile()->process($this->getProcessingType(), $configurationWrap);
135
+			}
136
+		}
137
+
138
+		// Analyse the current $url and compute the adequate separator between arguments.
139
+		$url = $this->thumbnailService->getAnchorUri() ? $this->thumbnailService->getAnchorUri() : $file->getPublicUrl(true);
140
+		$parameterSeparator = strpos($url, '?') === false ? '?' : '&';
141
+
142
+		return sprintf('<a href="%s%s" target="%s" data-uid="%s">%s</a>',
143
+			$url,
144
+			$this->thumbnailService->getAppendTimeStamp() && !$this->thumbnailService->getAnchorUri() ? $parameterSeparator . $file->getProperty('tstamp') : '',
145
+			$this->thumbnailService->getTarget(),
146
+			$file->getUid(),
147
+			$result
148
+		);
149
+	}
150
+
151
+	/**
152
+	 * Compute the final configuration for the image preview.
153
+	 * Keep ratio of width / height for the image.
154
+	 *
155
+	 * @param array $configuration
156
+	 * @return array
157
+	 */
158
+	protected function computeFinalImageDimension(array $configuration)
159
+	{
160
+		$ratio = $this->computeImageRatio();
161
+
162
+		if ($ratio > 1) {
163
+			$configuration['height'] = round($configuration['width'] / $ratio);
164
+		} else {
165
+			$configuration['width'] = round($configuration['height'] * $ratio);
166
+		}
167
+		return $configuration;
168
+	}
169
+
170
+	/**
171
+	 * Compute the width / height ratio of the image.
172
+	 *
173
+	 * @return null|float
174
+	 */
175
+	protected function computeImageRatio()
176
+	{
177
+		$ratio = null;
178
+		if ($this->getFile()->getProperty('width') > 0 && $this->getFile()->getProperty('height') > 0) {
179
+			$ratio = $this->getFile()->getProperty('width') / $this->getFile()->getProperty('height');
180
+		}
181
+		return $ratio;
182
+	}
183
+
184
+	/**
185
+	 * @return string
186
+	 */
187
+	public function getProcessingType()
188
+	{
189
+		if ($this->thumbnailService->getProcessingType() === null) {
190
+			return ProcessedFile::CONTEXT_IMAGECROPSCALEMASK;
191
+		}
192
+		return $this->thumbnailService->getProcessingType();
193
+	}
194 194
 
195 195
 }
Please login to merge, or discard this patch.
Classes/ViewHelpers/Form/FooterViewHelper.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
             $file->getProperty('crdate') ? $this->formatDate($arguments, $file->getProperty('crdate')) : '',
57 57
             $this->getUserName($file->getProperty('cruser_id')),
58 58
             LocalizationUtility::translate('updated_on', 'media'),
59
-            $file->getProperty('tstamp') ? $this->formatDate($arguments, '@' . $file->getProperty('tstamp')) : '',
59
+            $file->getProperty('tstamp') ? $this->formatDate($arguments, '@'.$file->getProperty('tstamp')) : '',
60 60
             $this->getUserName($file->getProperty('upuser_id'))
61 61
         );
62 62
 
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
         $username = '';
77 77
 
78 78
         if ($userIdentifier > 0) {
79
-            $record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', 'be_users', 'uid = ' . $userIdentifier);
79
+            $record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', 'be_users', 'uid = '.$userIdentifier);
80 80
             $username = sprintf('%s %s',
81 81
                 LocalizationUtility::translate('by', 'media'),
82 82
                 empty($record['realName']) ? $record['username'] : $record['realName']
@@ -126,12 +126,12 @@  discard block
 block discarded – undo
126 126
 
127 127
         if (!$date instanceof \DateTimeInterface) {
128 128
             try {
129
-                $base = $base instanceof \DateTimeInterface ? $base->format('U') : strtotime((MathUtility::canBeInterpretedAsInteger($base) ? '@' : '') . $base);
130
-                $dateTimestamp = strtotime((MathUtility::canBeInterpretedAsInteger($date) ? '@' : '') . $date, $base);
131
-                $date = new \DateTime('@' . $dateTimestamp);
129
+                $base = $base instanceof \DateTimeInterface ? $base->format('U') : strtotime((MathUtility::canBeInterpretedAsInteger($base) ? '@' : '').$base);
130
+                $dateTimestamp = strtotime((MathUtility::canBeInterpretedAsInteger($date) ? '@' : '').$date, $base);
131
+                $date = new \DateTime('@'.$dateTimestamp);
132 132
                 $date->setTimezone(new \DateTimeZone(date_default_timezone_get()));
133 133
             } catch (\Exception $exception) {
134
-                throw new Exception('"' . $date . '" could not be parsed by \DateTime constructor: ' . $exception->getMessage(), 1241722579);
134
+                throw new Exception('"'.$date.'" could not be parsed by \DateTime constructor: '.$exception->getMessage(), 1241722579);
135 135
             }
136 136
         }
137 137
 
Please login to merge, or discard this patch.
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -20,119 +20,119 @@
 block discarded – undo
20 20
 class FooterViewHelper extends AbstractViewHelper
21 21
 {
22 22
 
23
-    /**
24
-     * Render a form footer.
25
-     * Example:
26
-     * Created on 30-12-12 by John Updated on 22-05-12 by Jane
27
-     *
28
-     * @return string
29
-     */
30
-    public function render()
31
-    {
32
-
33
-        /** @var File $file */
34
-        $file = $this->templateVariableContainer->get('file');
35
-        $template = '<span>%s %s %s</span> <span style="padding-left: 50px">%s %s %s</span>';
36
-
37
-        $format = sprintf('%s @ %s',
38
-            $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'],
39
-            $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm']
40
-        );
41
-
42
-        $arguments = array(
43
-            'date' => null,
44
-            'format' => $format,
45
-            'base' => null
46
-        );
47
-
48
-        $result = sprintf($template,
49
-            LocalizationUtility::translate('created_on', 'media'),
50
-            $file->getProperty('crdate') ? $this->formatDate($arguments, $file->getProperty('crdate')) : '',
51
-            $this->getUserName($file->getProperty('cruser_id')),
52
-            LocalizationUtility::translate('updated_on', 'media'),
53
-            $file->getProperty('tstamp') ? $this->formatDate($arguments, '@' . $file->getProperty('tstamp')) : '',
54
-            $this->getUserName($file->getProperty('upuser_id'))
55
-        );
56
-
57
-        return $result;
58
-    }
59
-
60
-
61
-    /**
62
-     * Get the User name to be displayed
63
-     *
64
-     * @param int $userIdentifier
65
-     * @return string
66
-     */
67
-    public function getUserName($userIdentifier)
68
-    {
69
-
70
-        $username = '';
71
-
72
-        if ($userIdentifier > 0) {
73
-            $record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', 'be_users', 'uid = ' . $userIdentifier);
74
-            $username = sprintf('%s %s',
75
-                LocalizationUtility::translate('by', 'media'),
76
-                empty($record['realName']) ? $record['username'] : $record['realName']
77
-            );
78
-        }
79
-
80
-        return $username;
81
-    }
82
-
83
-
84
-    /**
85
-     * Returns a pointer to the database.
86
-     *
87
-     * @return \Fab\Vidi\Database\DatabaseConnection
88
-     */
89
-    protected function getDatabaseConnection()
90
-    {
91
-        return $GLOBALS['TYPO3_DB'];
92
-    }
93
-
94
-
95
-    /**
96
-     * @param array $arguments
97
-     * @param int|string $date
98
-     * @return string
99
-     * @throws Exception
100
-     */
101
-    public function formatDate(array $arguments, $date)
102
-    {
103
-        $format = $arguments['format'];
104
-        $base = $date;
105
-        if (is_string($base)) {
106
-            $base = trim($base);
107
-        }
108
-
109
-        if ($format === '') {
110
-            $format = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] ?: 'Y-m-d';
111
-        }
112
-
113
-        if (is_string($date)) {
114
-            $date = trim($date);
115
-        }
116
-
117
-        if ($date === '') {
118
-            $date = 'now';
119
-        }
120
-
121
-        if (!$date instanceof \DateTimeInterface) {
122
-            try {
123
-                $base = $base instanceof \DateTimeInterface ? $base->format('U') : strtotime((MathUtility::canBeInterpretedAsInteger($base) ? '@' : '') . $base);
124
-                $dateTimestamp = strtotime((MathUtility::canBeInterpretedAsInteger($date) ? '@' : '') . $date, $base);
125
-                $date = new \DateTime('@' . $dateTimestamp);
126
-                $date->setTimezone(new \DateTimeZone(date_default_timezone_get()));
127
-            } catch (\Exception $exception) {
128
-                throw new Exception('"' . $date . '" could not be parsed by \DateTime constructor: ' . $exception->getMessage(), 1241722579);
129
-            }
130
-        }
131
-
132
-        if (strpos($format, '%') !== false) {
133
-            return strftime($format, $date->format('U'));
134
-        } else {
135
-            return $date->format($format);
136
-        }
137
-    }
23
+	/**
24
+	 * Render a form footer.
25
+	 * Example:
26
+	 * Created on 30-12-12 by John Updated on 22-05-12 by Jane
27
+	 *
28
+	 * @return string
29
+	 */
30
+	public function render()
31
+	{
32
+
33
+		/** @var File $file */
34
+		$file = $this->templateVariableContainer->get('file');
35
+		$template = '<span>%s %s %s</span> <span style="padding-left: 50px">%s %s %s</span>';
36
+
37
+		$format = sprintf('%s @ %s',
38
+			$GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'],
39
+			$GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm']
40
+		);
41
+
42
+		$arguments = array(
43
+			'date' => null,
44
+			'format' => $format,
45
+			'base' => null
46
+		);
47
+
48
+		$result = sprintf($template,
49
+			LocalizationUtility::translate('created_on', 'media'),
50
+			$file->getProperty('crdate') ? $this->formatDate($arguments, $file->getProperty('crdate')) : '',
51
+			$this->getUserName($file->getProperty('cruser_id')),
52
+			LocalizationUtility::translate('updated_on', 'media'),
53
+			$file->getProperty('tstamp') ? $this->formatDate($arguments, '@' . $file->getProperty('tstamp')) : '',
54
+			$this->getUserName($file->getProperty('upuser_id'))
55
+		);
56
+
57
+		return $result;
58
+	}
59
+
60
+
61
+	/**
62
+	 * Get the User name to be displayed
63
+	 *
64
+	 * @param int $userIdentifier
65
+	 * @return string
66
+	 */
67
+	public function getUserName($userIdentifier)
68
+	{
69
+
70
+		$username = '';
71
+
72
+		if ($userIdentifier > 0) {
73
+			$record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', 'be_users', 'uid = ' . $userIdentifier);
74
+			$username = sprintf('%s %s',
75
+				LocalizationUtility::translate('by', 'media'),
76
+				empty($record['realName']) ? $record['username'] : $record['realName']
77
+			);
78
+		}
79
+
80
+		return $username;
81
+	}
82
+
83
+
84
+	/**
85
+	 * Returns a pointer to the database.
86
+	 *
87
+	 * @return \Fab\Vidi\Database\DatabaseConnection
88
+	 */
89
+	protected function getDatabaseConnection()
90
+	{
91
+		return $GLOBALS['TYPO3_DB'];
92
+	}
93
+
94
+
95
+	/**
96
+	 * @param array $arguments
97
+	 * @param int|string $date
98
+	 * @return string
99
+	 * @throws Exception
100
+	 */
101
+	public function formatDate(array $arguments, $date)
102
+	{
103
+		$format = $arguments['format'];
104
+		$base = $date;
105
+		if (is_string($base)) {
106
+			$base = trim($base);
107
+		}
108
+
109
+		if ($format === '') {
110
+			$format = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] ?: 'Y-m-d';
111
+		}
112
+
113
+		if (is_string($date)) {
114
+			$date = trim($date);
115
+		}
116
+
117
+		if ($date === '') {
118
+			$date = 'now';
119
+		}
120
+
121
+		if (!$date instanceof \DateTimeInterface) {
122
+			try {
123
+				$base = $base instanceof \DateTimeInterface ? $base->format('U') : strtotime((MathUtility::canBeInterpretedAsInteger($base) ? '@' : '') . $base);
124
+				$dateTimestamp = strtotime((MathUtility::canBeInterpretedAsInteger($date) ? '@' : '') . $date, $base);
125
+				$date = new \DateTime('@' . $dateTimestamp);
126
+				$date->setTimezone(new \DateTimeZone(date_default_timezone_get()));
127
+			} catch (\Exception $exception) {
128
+				throw new Exception('"' . $date . '" could not be parsed by \DateTime constructor: ' . $exception->getMessage(), 1241722579);
129
+			}
130
+		}
131
+
132
+		if (strpos($format, '%') !== false) {
133
+			return strftime($format, $date->format('U'));
134
+		} else {
135
+			return $date->format($format);
136
+		}
137
+	}
138 138
 }
Please login to merge, or discard this patch.
Classes/Grid/ActionPermissionColumn.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@
 block discarded – undo
42 42
             $permission .= 'W';
43 43
         }
44 44
 
45
-        return '<strong>' . $permission . '</strong>';
45
+        return '<strong>'.$permission.'</strong>';
46 46
     }
47 47
 
48 48
     /**
Please login to merge, or discard this 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.