@@ -21,51 +21,51 @@ |
||
21 | 21 | */ |
22 | 22 | class ImageEditorPlugin extends AbstractComponentView |
23 | 23 | { |
24 | - /** |
|
25 | - * Renders a hidden link for image editor. |
|
26 | - * |
|
27 | - * @return string |
|
28 | - */ |
|
29 | - public function render() |
|
30 | - { |
|
31 | - $result = ''; |
|
32 | - if ($this->getModuleLoader()->hasPlugin('imageEditor')) { |
|
33 | - // Load Require JS code |
|
34 | - $this->loadRequireJsCode(); |
|
24 | + /** |
|
25 | + * Renders a hidden link for image editor. |
|
26 | + * |
|
27 | + * @return string |
|
28 | + */ |
|
29 | + public function render() |
|
30 | + { |
|
31 | + $result = ''; |
|
32 | + if ($this->getModuleLoader()->hasPlugin('imageEditor')) { |
|
33 | + // Load Require JS code |
|
34 | + $this->loadRequireJsCode(); |
|
35 | 35 | |
36 | - $result = sprintf( |
|
37 | - '<a href="%s" id="btn-imageEditor-current" class="btn btn-imageEditor" style="display: none"></a>', |
|
38 | - $this->getImageEditorUri() |
|
39 | - ); |
|
40 | - }; |
|
41 | - return $result; |
|
42 | - } |
|
36 | + $result = sprintf( |
|
37 | + '<a href="%s" id="btn-imageEditor-current" class="btn btn-imageEditor" style="display: none"></a>', |
|
38 | + $this->getImageEditorUri() |
|
39 | + ); |
|
40 | + }; |
|
41 | + return $result; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - protected function getImageEditorUri() |
|
48 | - { |
|
49 | - $urlParameters = array( |
|
50 | - MediaModule::getParameterPrefix() => array( |
|
51 | - 'controller' => 'ImageEditor', |
|
52 | - 'action' => 'show', |
|
53 | - ), |
|
54 | - ); |
|
55 | - return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters); |
|
56 | - } |
|
44 | + /** |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + protected function getImageEditorUri() |
|
48 | + { |
|
49 | + $urlParameters = array( |
|
50 | + MediaModule::getParameterPrefix() => array( |
|
51 | + 'controller' => 'ImageEditor', |
|
52 | + 'action' => 'show', |
|
53 | + ), |
|
54 | + ); |
|
55 | + return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @return void |
|
60 | - */ |
|
61 | - protected function loadRequireJsCode() |
|
62 | - { |
|
63 | - $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
58 | + /** |
|
59 | + * @return void |
|
60 | + */ |
|
61 | + protected function loadRequireJsCode() |
|
62 | + { |
|
63 | + $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
64 | 64 | |
65 | - $publicResourcesPath = PathUtility::getPublicResourceWebPath('EXT:media/Resources/Public/'); |
|
66 | - $configuration['paths']['Fab/Media'] = $publicResourcesPath . 'JavaScript'; |
|
65 | + $publicResourcesPath = PathUtility::getPublicResourceWebPath('EXT:media/Resources/Public/'); |
|
66 | + $configuration['paths']['Fab/Media'] = $publicResourcesPath . 'JavaScript'; |
|
67 | 67 | |
68 | - $pageRenderer->addRequireJsConfiguration($configuration); |
|
69 | - $pageRenderer->loadRequireJsModule('Fab/Media/PluginImageEditor'); |
|
70 | - } |
|
68 | + $pageRenderer->addRequireJsConfiguration($configuration); |
|
69 | + $pageRenderer->loadRequireJsModule('Fab/Media/PluginImageEditor'); |
|
70 | + } |
|
71 | 71 | } |
@@ -19,30 +19,30 @@ |
||
19 | 19 | */ |
20 | 20 | class FilePickerPlugin extends AbstractComponentView |
21 | 21 | { |
22 | - /** |
|
23 | - * Renders a hidden link for file picker. |
|
24 | - * |
|
25 | - * @return string |
|
26 | - */ |
|
27 | - public function render() |
|
28 | - { |
|
29 | - if ($this->getModuleLoader()->hasPlugin('filePicker')) { |
|
30 | - $this->loadRequireJsCode(); |
|
31 | - }; |
|
32 | - return ''; |
|
33 | - } |
|
22 | + /** |
|
23 | + * Renders a hidden link for file picker. |
|
24 | + * |
|
25 | + * @return string |
|
26 | + */ |
|
27 | + public function render() |
|
28 | + { |
|
29 | + if ($this->getModuleLoader()->hasPlugin('filePicker')) { |
|
30 | + $this->loadRequireJsCode(); |
|
31 | + }; |
|
32 | + return ''; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * @return void |
|
37 | - */ |
|
38 | - protected function loadRequireJsCode() |
|
39 | - { |
|
40 | - $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
35 | + /** |
|
36 | + * @return void |
|
37 | + */ |
|
38 | + protected function loadRequireJsCode() |
|
39 | + { |
|
40 | + $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
41 | 41 | |
42 | - $publicResourcesPath = PathUtility::getPublicResourceWebPath('EXT:media/Resources/Public/'); |
|
43 | - $configuration['paths']['Fab/Media'] = $publicResourcesPath . 'JavaScript'; |
|
42 | + $publicResourcesPath = PathUtility::getPublicResourceWebPath('EXT:media/Resources/Public/'); |
|
43 | + $configuration['paths']['Fab/Media'] = $publicResourcesPath . 'JavaScript'; |
|
44 | 44 | |
45 | - $pageRenderer->addRequireJsConfiguration($configuration); |
|
46 | - $pageRenderer->loadRequireJsModule('Fab/Media/PluginFilePicker'); |
|
47 | - } |
|
45 | + $pageRenderer->addRequireJsConfiguration($configuration); |
|
46 | + $pageRenderer->loadRequireJsModule('Fab/Media/PluginFilePicker'); |
|
47 | + } |
|
48 | 48 | } |
@@ -21,51 +21,51 @@ |
||
21 | 21 | */ |
22 | 22 | class LinkCreatorPlugin extends AbstractComponentView |
23 | 23 | { |
24 | - /** |
|
25 | - * Renders a hidden link for link creator. |
|
26 | - * |
|
27 | - * @return string |
|
28 | - */ |
|
29 | - public function render() |
|
30 | - { |
|
31 | - $result = ''; |
|
32 | - if ($this->getModuleLoader()->hasPlugin('linkCreator')) { |
|
33 | - // Load Require JS code |
|
34 | - $this->loadRequireJsCode(); |
|
24 | + /** |
|
25 | + * Renders a hidden link for link creator. |
|
26 | + * |
|
27 | + * @return string |
|
28 | + */ |
|
29 | + public function render() |
|
30 | + { |
|
31 | + $result = ''; |
|
32 | + if ($this->getModuleLoader()->hasPlugin('linkCreator')) { |
|
33 | + // Load Require JS code |
|
34 | + $this->loadRequireJsCode(); |
|
35 | 35 | |
36 | - $result = sprintf( |
|
37 | - '<a href="%s" id="btn-linkCreator-current" class="btn btn-linkCreator" style="display: none"></a>', |
|
38 | - $this->getLinkCreatorUri() |
|
39 | - ); |
|
40 | - }; |
|
41 | - return $result; |
|
42 | - } |
|
36 | + $result = sprintf( |
|
37 | + '<a href="%s" id="btn-linkCreator-current" class="btn btn-linkCreator" style="display: none"></a>', |
|
38 | + $this->getLinkCreatorUri() |
|
39 | + ); |
|
40 | + }; |
|
41 | + return $result; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - protected function getLinkCreatorUri() |
|
48 | - { |
|
49 | - $urlParameters = array( |
|
50 | - MediaModule::getParameterPrefix() => array( |
|
51 | - 'controller' => 'LinkCreator', |
|
52 | - 'action' => 'show', |
|
53 | - ), |
|
54 | - ); |
|
55 | - return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters); |
|
56 | - } |
|
44 | + /** |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + protected function getLinkCreatorUri() |
|
48 | + { |
|
49 | + $urlParameters = array( |
|
50 | + MediaModule::getParameterPrefix() => array( |
|
51 | + 'controller' => 'LinkCreator', |
|
52 | + 'action' => 'show', |
|
53 | + ), |
|
54 | + ); |
|
55 | + return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @return void |
|
60 | - */ |
|
61 | - protected function loadRequireJsCode() |
|
62 | - { |
|
63 | - $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
58 | + /** |
|
59 | + * @return void |
|
60 | + */ |
|
61 | + protected function loadRequireJsCode() |
|
62 | + { |
|
63 | + $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
64 | 64 | |
65 | - $publicResourcesPath = PathUtility::getPublicResourceWebPath('EXT:media/Resources/Public/'); |
|
66 | - $configuration['paths']['Fab/Media'] = $publicResourcesPath . 'JavaScript'; |
|
65 | + $publicResourcesPath = PathUtility::getPublicResourceWebPath('EXT:media/Resources/Public/'); |
|
66 | + $configuration['paths']['Fab/Media'] = $publicResourcesPath . 'JavaScript'; |
|
67 | 67 | |
68 | - $pageRenderer->addRequireJsConfiguration($configuration); |
|
69 | - $pageRenderer->loadRequireJsModule('Fab/Media/PluginLinkCreator'); |
|
70 | - } |
|
68 | + $pageRenderer->addRequireJsConfiguration($configuration); |
|
69 | + $pageRenderer->loadRequireJsModule('Fab/Media/PluginLinkCreator'); |
|
70 | + } |
|
71 | 71 | } |
@@ -20,161 +20,161 @@ |
||
20 | 20 | */ |
21 | 21 | class FileReferenceService |
22 | 22 | { |
23 | - /** |
|
24 | - * Return all references found in sys_file_reference. |
|
25 | - * |
|
26 | - * @param File|int $file |
|
27 | - * @return array |
|
28 | - */ |
|
29 | - public function findFileReferences($file) |
|
30 | - { |
|
31 | - $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file; |
|
32 | - |
|
33 | - // Get the file references of the file. |
|
34 | - return $this->getDataService()->getRecords( |
|
35 | - 'sys_file_reference', |
|
36 | - [ |
|
37 | - 'uid_local' => $fileIdentifier, |
|
38 | - ] |
|
39 | - ); |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Return soft image references. |
|
44 | - * |
|
45 | - * @param File|int $file |
|
46 | - * @return array |
|
47 | - */ |
|
48 | - public function findSoftImageReferences($file) |
|
49 | - { |
|
50 | - $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file; |
|
51 | - |
|
52 | - // Get the file references of the file in the RTE. |
|
53 | - $softReferences = $this->getDataService()->getRecords( |
|
54 | - 'sys_refindex', |
|
55 | - [ |
|
56 | - 'softref_key' => 'rtehtmlarea_images', |
|
57 | - 'ref_table' => 'sys_file', |
|
58 | - 'ref_uid' => $fileIdentifier, |
|
59 | - ] |
|
60 | - ); |
|
61 | - return $softReferences; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Return link image references. |
|
66 | - * |
|
67 | - * @param File|int $file |
|
68 | - * @return array |
|
69 | - */ |
|
70 | - public function findSoftLinkReferences($file) |
|
71 | - { |
|
72 | - $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file; |
|
73 | - |
|
74 | - // Get the link references of the file. |
|
75 | - $softReferences = $this->getDataService()->getRecords( |
|
76 | - 'sys_refindex', |
|
77 | - [ |
|
78 | - 'softref_key' => 'typolink_tag', |
|
79 | - 'ref_table' => 'sys_file', |
|
80 | - 'ref_uid' => $fileIdentifier, |
|
81 | - ] |
|
82 | - ); |
|
83 | - return $softReferences; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Count all references found in sys_file_reference. |
|
88 | - * |
|
89 | - * @param File|int $file |
|
90 | - * @return int |
|
91 | - */ |
|
92 | - public function countFileReferences($file) |
|
93 | - { |
|
94 | - $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file; |
|
95 | - |
|
96 | - return $this->getDataService() |
|
97 | - ->count( |
|
98 | - 'sys_file_reference', |
|
99 | - [ |
|
100 | - 'uid_local' => $fileIdentifier |
|
101 | - ] |
|
102 | - ); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Count soft image references. |
|
107 | - * |
|
108 | - * @param File|int $file |
|
109 | - * @return int |
|
110 | - */ |
|
111 | - public function countSoftImageReferences($file) |
|
112 | - { |
|
113 | - $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file; |
|
114 | - |
|
115 | - return $this->getDataService() |
|
116 | - ->count( |
|
117 | - 'sys_refindex', |
|
118 | - [ |
|
119 | - 'softref_key' => 'rtehtmlarea_images', |
|
120 | - 'ref_table' => 'sys_file', |
|
121 | - 'ref_uid' => $fileIdentifier |
|
122 | - ] |
|
123 | - ); |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Count link image references. |
|
128 | - * |
|
129 | - * @param File|int $file |
|
130 | - * @return int |
|
131 | - */ |
|
132 | - public function countSoftLinkReferences($file) |
|
133 | - { |
|
134 | - $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file; |
|
135 | - |
|
136 | - return $this->getDataService() |
|
137 | - ->count( |
|
138 | - 'sys_refindex', |
|
139 | - [ |
|
140 | - 'softref_key' => 'typolink_tag', |
|
141 | - 'ref_table' => 'sys_file', |
|
142 | - 'ref_uid' => $fileIdentifier |
|
143 | - ] |
|
144 | - ); |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Count total reference. |
|
149 | - * |
|
150 | - * @param File|int $file |
|
151 | - * @return int |
|
152 | - */ |
|
153 | - public function countTotalReferences($file) |
|
154 | - { |
|
155 | - $numberOfReferences = $this->countFileReferences($file); |
|
156 | - $numberOfReferences += $this->countSoftImageReferences($file); |
|
157 | - $numberOfReferences += $this->countSoftLinkReferences($file); |
|
158 | - |
|
159 | - return $numberOfReferences; |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * @param string $tableName |
|
164 | - * @return object|QueryBuilder |
|
165 | - */ |
|
166 | - protected function getQueryBuilder($tableName): QueryBuilder |
|
167 | - { |
|
168 | - /** @var ConnectionPool $connectionPool */ |
|
169 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
170 | - return $connectionPool->getQueryBuilderForTable($tableName); |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * @return object|DataService |
|
175 | - */ |
|
176 | - protected function getDataService(): DataService |
|
177 | - { |
|
178 | - return GeneralUtility::makeInstance(DataService::class); |
|
179 | - } |
|
23 | + /** |
|
24 | + * Return all references found in sys_file_reference. |
|
25 | + * |
|
26 | + * @param File|int $file |
|
27 | + * @return array |
|
28 | + */ |
|
29 | + public function findFileReferences($file) |
|
30 | + { |
|
31 | + $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file; |
|
32 | + |
|
33 | + // Get the file references of the file. |
|
34 | + return $this->getDataService()->getRecords( |
|
35 | + 'sys_file_reference', |
|
36 | + [ |
|
37 | + 'uid_local' => $fileIdentifier, |
|
38 | + ] |
|
39 | + ); |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Return soft image references. |
|
44 | + * |
|
45 | + * @param File|int $file |
|
46 | + * @return array |
|
47 | + */ |
|
48 | + public function findSoftImageReferences($file) |
|
49 | + { |
|
50 | + $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file; |
|
51 | + |
|
52 | + // Get the file references of the file in the RTE. |
|
53 | + $softReferences = $this->getDataService()->getRecords( |
|
54 | + 'sys_refindex', |
|
55 | + [ |
|
56 | + 'softref_key' => 'rtehtmlarea_images', |
|
57 | + 'ref_table' => 'sys_file', |
|
58 | + 'ref_uid' => $fileIdentifier, |
|
59 | + ] |
|
60 | + ); |
|
61 | + return $softReferences; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Return link image references. |
|
66 | + * |
|
67 | + * @param File|int $file |
|
68 | + * @return array |
|
69 | + */ |
|
70 | + public function findSoftLinkReferences($file) |
|
71 | + { |
|
72 | + $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file; |
|
73 | + |
|
74 | + // Get the link references of the file. |
|
75 | + $softReferences = $this->getDataService()->getRecords( |
|
76 | + 'sys_refindex', |
|
77 | + [ |
|
78 | + 'softref_key' => 'typolink_tag', |
|
79 | + 'ref_table' => 'sys_file', |
|
80 | + 'ref_uid' => $fileIdentifier, |
|
81 | + ] |
|
82 | + ); |
|
83 | + return $softReferences; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Count all references found in sys_file_reference. |
|
88 | + * |
|
89 | + * @param File|int $file |
|
90 | + * @return int |
|
91 | + */ |
|
92 | + public function countFileReferences($file) |
|
93 | + { |
|
94 | + $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file; |
|
95 | + |
|
96 | + return $this->getDataService() |
|
97 | + ->count( |
|
98 | + 'sys_file_reference', |
|
99 | + [ |
|
100 | + 'uid_local' => $fileIdentifier |
|
101 | + ] |
|
102 | + ); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Count soft image references. |
|
107 | + * |
|
108 | + * @param File|int $file |
|
109 | + * @return int |
|
110 | + */ |
|
111 | + public function countSoftImageReferences($file) |
|
112 | + { |
|
113 | + $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file; |
|
114 | + |
|
115 | + return $this->getDataService() |
|
116 | + ->count( |
|
117 | + 'sys_refindex', |
|
118 | + [ |
|
119 | + 'softref_key' => 'rtehtmlarea_images', |
|
120 | + 'ref_table' => 'sys_file', |
|
121 | + 'ref_uid' => $fileIdentifier |
|
122 | + ] |
|
123 | + ); |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * Count link image references. |
|
128 | + * |
|
129 | + * @param File|int $file |
|
130 | + * @return int |
|
131 | + */ |
|
132 | + public function countSoftLinkReferences($file) |
|
133 | + { |
|
134 | + $fileIdentifier = $file instanceof File ? $file->getUid() : (int)$file; |
|
135 | + |
|
136 | + return $this->getDataService() |
|
137 | + ->count( |
|
138 | + 'sys_refindex', |
|
139 | + [ |
|
140 | + 'softref_key' => 'typolink_tag', |
|
141 | + 'ref_table' => 'sys_file', |
|
142 | + 'ref_uid' => $fileIdentifier |
|
143 | + ] |
|
144 | + ); |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Count total reference. |
|
149 | + * |
|
150 | + * @param File|int $file |
|
151 | + * @return int |
|
152 | + */ |
|
153 | + public function countTotalReferences($file) |
|
154 | + { |
|
155 | + $numberOfReferences = $this->countFileReferences($file); |
|
156 | + $numberOfReferences += $this->countSoftImageReferences($file); |
|
157 | + $numberOfReferences += $this->countSoftLinkReferences($file); |
|
158 | + |
|
159 | + return $numberOfReferences; |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * @param string $tableName |
|
164 | + * @return object|QueryBuilder |
|
165 | + */ |
|
166 | + protected function getQueryBuilder($tableName): QueryBuilder |
|
167 | + { |
|
168 | + /** @var ConnectionPool $connectionPool */ |
|
169 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
170 | + return $connectionPool->getQueryBuilderForTable($tableName); |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * @return object|DataService |
|
175 | + */ |
|
176 | + protected function getDataService(): DataService |
|
177 | + { |
|
178 | + return GeneralUtility::makeInstance(DataService::class); |
|
179 | + } |
|
180 | 180 | } |
@@ -20,42 +20,42 @@ |
||
20 | 20 | */ |
21 | 21 | class ProcessedFileController extends ActionController |
22 | 22 | { |
23 | - /** |
|
24 | - * Initializes the controller before invoking an action method. |
|
25 | - */ |
|
26 | - public function initializeAction() |
|
27 | - { |
|
28 | - // Configure property mapping to retrieve the file object. |
|
29 | - if ($this->arguments->hasArgument('file')) { |
|
30 | - /** @var FileConverter $typeConverter */ |
|
31 | - $typeConverter = GeneralUtility::makeInstance(FileConverter::class); |
|
23 | + /** |
|
24 | + * Initializes the controller before invoking an action method. |
|
25 | + */ |
|
26 | + public function initializeAction() |
|
27 | + { |
|
28 | + // Configure property mapping to retrieve the file object. |
|
29 | + if ($this->arguments->hasArgument('file')) { |
|
30 | + /** @var FileConverter $typeConverter */ |
|
31 | + $typeConverter = GeneralUtility::makeInstance(FileConverter::class); |
|
32 | 32 | |
33 | - $propertyMappingConfiguration = $this->arguments->getArgument('file')->getPropertyMappingConfiguration(); |
|
34 | - $propertyMappingConfiguration->setTypeConverter($typeConverter); |
|
35 | - } |
|
36 | - } |
|
33 | + $propertyMappingConfiguration = $this->arguments->getArgument('file')->getPropertyMappingConfiguration(); |
|
34 | + $propertyMappingConfiguration->setTypeConverter($typeConverter); |
|
35 | + } |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Create a processed file according to some configuration. |
|
40 | - * |
|
41 | - * @param File $file |
|
42 | - * @param array $processingConfiguration |
|
43 | - * @return string |
|
44 | - */ |
|
45 | - public function createAction(File $file, array $processingConfiguration = []): ResponseInterface |
|
46 | - { |
|
47 | - $processedFile = $file->process(ProcessedFile::CONTEXT_IMAGECROPSCALEMASK, $processingConfiguration); |
|
38 | + /** |
|
39 | + * Create a processed file according to some configuration. |
|
40 | + * |
|
41 | + * @param File $file |
|
42 | + * @param array $processingConfiguration |
|
43 | + * @return string |
|
44 | + */ |
|
45 | + public function createAction(File $file, array $processingConfiguration = []): ResponseInterface |
|
46 | + { |
|
47 | + $processedFile = $file->process(ProcessedFile::CONTEXT_IMAGECROPSCALEMASK, $processingConfiguration); |
|
48 | 48 | |
49 | - $response = array( |
|
50 | - 'success' => true, |
|
51 | - 'original' => $file->getUid(), |
|
52 | - 'title' => $file->getProperty('title') ? $file->getProperty('title') : $file->getName(), |
|
53 | - 'publicUrl' => $processedFile->getPublicUrl(), |
|
54 | - 'width' => $processedFile->getProperty('width'), |
|
55 | - 'height' => $processedFile->getProperty('height'), |
|
56 | - ); |
|
49 | + $response = array( |
|
50 | + 'success' => true, |
|
51 | + 'original' => $file->getUid(), |
|
52 | + 'title' => $file->getProperty('title') ? $file->getProperty('title') : $file->getName(), |
|
53 | + 'publicUrl' => $processedFile->getPublicUrl(), |
|
54 | + 'width' => $processedFile->getProperty('width'), |
|
55 | + 'height' => $processedFile->getProperty('height'), |
|
56 | + ); |
|
57 | 57 | |
58 | - header("Content-Type: text/json"); |
|
59 | - return $this->htmlResponse(htmlspecialchars(json_encode($response), ENT_NOQUOTES)); |
|
60 | - } |
|
58 | + header("Content-Type: text/json"); |
|
59 | + return $this->htmlResponse(htmlspecialchars(json_encode($response), ENT_NOQUOTES)); |
|
60 | + } |
|
61 | 61 | } |
@@ -22,36 +22,36 @@ |
||
22 | 22 | */ |
23 | 23 | class ImageEditorController extends ActionController |
24 | 24 | { |
25 | - /** |
|
26 | - * Initializes the controller before invoking an action method. |
|
27 | - */ |
|
28 | - public function initializeAction() |
|
29 | - { |
|
30 | - /** @var PageRenderer $pageRenderer */ |
|
31 | - $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
32 | - $pageRenderer->addInlineLanguageLabelFile('EXT:media/Resources/Private/Language/locallang.xlf'); |
|
25 | + /** |
|
26 | + * Initializes the controller before invoking an action method. |
|
27 | + */ |
|
28 | + public function initializeAction() |
|
29 | + { |
|
30 | + /** @var PageRenderer $pageRenderer */ |
|
31 | + $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
32 | + $pageRenderer->addInlineLanguageLabelFile('EXT:media/Resources/Private/Language/locallang.xlf'); |
|
33 | 33 | |
34 | - // Configure property mapping to retrieve the file object. |
|
35 | - if ($this->arguments->hasArgument('file')) { |
|
36 | - /** @var FileConverter $typeConverter */ |
|
37 | - $typeConverter = GeneralUtility::makeInstance(FileConverter::class); |
|
34 | + // Configure property mapping to retrieve the file object. |
|
35 | + if ($this->arguments->hasArgument('file')) { |
|
36 | + /** @var FileConverter $typeConverter */ |
|
37 | + $typeConverter = GeneralUtility::makeInstance(FileConverter::class); |
|
38 | 38 | |
39 | - $propertyMappingConfiguration = $this->arguments->getArgument('file')->getPropertyMappingConfiguration(); |
|
40 | - $propertyMappingConfiguration->setTypeConverter($typeConverter); |
|
41 | - } |
|
42 | - } |
|
39 | + $propertyMappingConfiguration = $this->arguments->getArgument('file')->getPropertyMappingConfiguration(); |
|
40 | + $propertyMappingConfiguration->setTypeConverter($typeConverter); |
|
41 | + } |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Handle GUI for inserting an image in the RTE. |
|
46 | - * |
|
47 | - * @param File $file |
|
48 | - * @return void |
|
49 | - */ |
|
50 | - public function showAction(File $file): ResponseInterface |
|
51 | - { |
|
52 | - $this->view->assign('file', $file); |
|
53 | - $moduleSignature = MediaModule::getSignature(); |
|
54 | - $this->view->assign('moduleUrl', BackendUtility::getModuleUrl($moduleSignature)); |
|
55 | - return $this->htmlResponse(); |
|
56 | - } |
|
44 | + /** |
|
45 | + * Handle GUI for inserting an image in the RTE. |
|
46 | + * |
|
47 | + * @param File $file |
|
48 | + * @return void |
|
49 | + */ |
|
50 | + public function showAction(File $file): ResponseInterface |
|
51 | + { |
|
52 | + $this->view->assign('file', $file); |
|
53 | + $moduleSignature = MediaModule::getSignature(); |
|
54 | + $this->view->assign('moduleUrl', BackendUtility::getModuleUrl($moduleSignature)); |
|
55 | + return $this->htmlResponse(); |
|
56 | + } |
|
57 | 57 | } |
@@ -19,30 +19,30 @@ |
||
19 | 19 | */ |
20 | 20 | class LinkCreatorController extends ActionController |
21 | 21 | { |
22 | - /** |
|
23 | - * Initializes the controller before invoking an action method. |
|
24 | - */ |
|
25 | - public function initializeAction() |
|
26 | - { |
|
27 | - // Configure property mapping to retrieve the file object. |
|
28 | - if ($this->arguments->hasArgument('file')) { |
|
29 | - /** @var FileConverter $typeConverter */ |
|
30 | - $typeConverter = GeneralUtility::makeInstance(FileConverter::class); |
|
22 | + /** |
|
23 | + * Initializes the controller before invoking an action method. |
|
24 | + */ |
|
25 | + public function initializeAction() |
|
26 | + { |
|
27 | + // Configure property mapping to retrieve the file object. |
|
28 | + if ($this->arguments->hasArgument('file')) { |
|
29 | + /** @var FileConverter $typeConverter */ |
|
30 | + $typeConverter = GeneralUtility::makeInstance(FileConverter::class); |
|
31 | 31 | |
32 | - $propertyMappingConfiguration = $this->arguments->getArgument('file')->getPropertyMappingConfiguration(); |
|
33 | - $propertyMappingConfiguration->setTypeConverter($typeConverter); |
|
34 | - } |
|
35 | - } |
|
32 | + $propertyMappingConfiguration = $this->arguments->getArgument('file')->getPropertyMappingConfiguration(); |
|
33 | + $propertyMappingConfiguration->setTypeConverter($typeConverter); |
|
34 | + } |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Handle GUI for creating a link in the RTE. |
|
39 | - * |
|
40 | - * @param File $file |
|
41 | - * @return void |
|
42 | - */ |
|
43 | - public function showAction(File $file): ResponseInterface |
|
44 | - { |
|
45 | - $this->view->assign('file', $file); |
|
46 | - return $this->htmlResponse(); |
|
47 | - } |
|
37 | + /** |
|
38 | + * Handle GUI for creating a link in the RTE. |
|
39 | + * |
|
40 | + * @param File $file |
|
41 | + * @return void |
|
42 | + */ |
|
43 | + public function showAction(File $file): ResponseInterface |
|
44 | + { |
|
45 | + $this->view->assign('file', $file); |
|
46 | + return $this->htmlResponse(); |
|
47 | + } |
|
48 | 48 | } |
@@ -47,313 +47,313 @@ |
||
47 | 47 | */ |
48 | 48 | class AssetController extends ActionController |
49 | 49 | { |
50 | - /** |
|
51 | - * @var string |
|
52 | - */ |
|
53 | - protected $dataType = 'sys_file'; |
|
54 | - |
|
55 | - /** |
|
56 | - * @throws StorageNotOnlineException |
|
57 | - * @throws \InvalidArgumentException |
|
58 | - * @throws NoSuchArgumentException |
|
59 | - */ |
|
60 | - public function initializeAction() |
|
61 | - { |
|
62 | - $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
63 | - $pageRenderer->addInlineLanguageLabelFile('EXT:media/Resources/Private/Language/locallang.xlf'); |
|
64 | - |
|
65 | - // Configure property mapping to retrieve the file object. |
|
66 | - if ($this->arguments->hasArgument('file')) { |
|
67 | - /** @var FileConverter $typeConverter */ |
|
68 | - $typeConverter = GeneralUtility::makeInstance(FileConverter::class); |
|
69 | - |
|
70 | - $propertyMappingConfiguration = $this->arguments->getArgument('file')->getPropertyMappingConfiguration(); |
|
71 | - $propertyMappingConfiguration->setTypeConverter($typeConverter); |
|
72 | - } |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Force download of the file. |
|
77 | - * |
|
78 | - * @param File $file |
|
79 | - * @param bool $forceDownload |
|
80 | - * @return bool|string |
|
81 | - * @throws \RuntimeException |
|
82 | - */ |
|
83 | - public function downloadAction(File $file, $forceDownload = false): ResponseInterface |
|
84 | - { |
|
85 | - if ($file->exists() && $file->getStorage()->isWithinFileMountBoundaries($file->getParentFolder())) { |
|
86 | - // Emit signal before downloading the file. |
|
87 | - $this->emitBeforeDownloadSignal($file); |
|
88 | - |
|
89 | - // Read the file and dump it with the flag "forceDownload" set to true or false. |
|
90 | - $file->getStorage()->streamFile($file, $forceDownload); |
|
91 | - |
|
92 | - $result = true; |
|
93 | - } else { |
|
94 | - $result = 'Access denied!'; |
|
95 | - } |
|
96 | - |
|
97 | - return $this->htmlResponse($result); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Handle file upload for a new file. |
|
102 | - * |
|
103 | - * @param string $combinedIdentifier |
|
104 | - * @Extbase\Validate("\Fab\Media\Domain\Validator\StorageValidator", param="combinedIdentifier") |
|
105 | - * @return string |
|
106 | - */ |
|
107 | - public function createAction($combinedIdentifier): ResponseInterface |
|
108 | - { |
|
109 | - /** @var UploadedFileInterface $uploadedFile */ |
|
110 | - $uploadedFile = $this->handleUpload(); |
|
111 | - if (!is_object($uploadedFile)) { |
|
112 | - return $this->htmlResponse(htmlspecialchars(json_encode($uploadedFile), ENT_NOQUOTES)); |
|
113 | - } |
|
114 | - |
|
115 | - // Get the target folder. |
|
116 | - if ($this->getMediaModule()->hasFolderTree()) { |
|
117 | - $targetFolder = $this->getMediaModule()->getFolderForCombinedIdentifier($combinedIdentifier); |
|
118 | - } else { |
|
119 | - $storage = $this->getResourceFactory()->getStorageObjectFromCombinedIdentifier($combinedIdentifier); |
|
120 | - $targetFolder = $this->getMediaModule()->getTargetFolderForUploadedFile($uploadedFile, $storage); |
|
121 | - } |
|
122 | - |
|
123 | - try { |
|
124 | - $conflictMode = DuplicationBehavior::RENAME; |
|
125 | - $fileName = $uploadedFile->getName(); |
|
126 | - $file = $targetFolder->addFile($uploadedFile->getFileWithAbsolutePath(), $fileName, $conflictMode); |
|
127 | - |
|
128 | - // Run the indexer for extracting metadata. |
|
129 | - $this->getMediaIndexer($file->getStorage()) |
|
130 | - ->extractMetadata($file) |
|
131 | - ->applyDefaultCategories($file); |
|
132 | - |
|
133 | - $response = array( |
|
134 | - 'success' => true, |
|
135 | - 'uid' => $file->getUid(), |
|
136 | - 'name' => $file->getName(), |
|
137 | - 'thumbnail' => $this->getThumbnailService($file)->create(), |
|
138 | - ); |
|
139 | - } catch (UploadException $e) { |
|
140 | - $response = array('error' => 'The upload has failed, no uploaded file found!'); |
|
141 | - } catch (InsufficientUserPermissionsException $e) { |
|
142 | - $response = array('error' => 'You are not allowed to upload files!'); |
|
143 | - } catch (UploadSizeException $e) { |
|
144 | - $response = array('error' => vsprintf('The uploaded file "%s" exceeds the size-limit', array($uploadedFile->getName()))); |
|
145 | - } catch (InsufficientFolderWritePermissionsException $e) { |
|
146 | - $response = array('error' => vsprintf('Destination path "%s" was not within your mount points!', array($targetFolder->getIdentifier()))); |
|
147 | - } catch (IllegalFileExtensionException $e) { |
|
148 | - $response = array('error' => vsprintf('Extension of file name "%s" is not allowed in "%s"!', array($uploadedFile->getName(), $targetFolder->getIdentifier()))); |
|
149 | - } catch (ExistingTargetFileNameException $e) { |
|
150 | - $response = array('error' => vsprintf('No unique filename available in "%s"!', array($targetFolder->getIdentifier()))); |
|
151 | - } catch (\RuntimeException $e) { |
|
152 | - $response = array('error' => vsprintf('Uploaded file could not be moved! Write-permission problem in "%s"?', array($targetFolder->getIdentifier()))); |
|
153 | - } |
|
154 | - |
|
155 | - // to pass data through iframe you will need to encode all html tags |
|
156 | - header("Content-Type: text/plain"); |
|
157 | - return $this->htmlResponse(htmlspecialchars(json_encode($response), ENT_NOQUOTES)); |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * Handle file upload for an existing file. |
|
162 | - * |
|
163 | - * @param File $file |
|
164 | - * @return string |
|
165 | - * @throws \InvalidArgumentException |
|
166 | - * @throws \RuntimeException |
|
167 | - */ |
|
168 | - public function updateAction(File $file): ResponseInterface |
|
169 | - { |
|
170 | - $uploadedFile = $this->handleUpload(); |
|
171 | - if (!is_object($uploadedFile)) { |
|
172 | - return $this->htmlResponse(htmlspecialchars(json_encode($uploadedFile), ENT_NOQUOTES)); |
|
173 | - } |
|
174 | - |
|
175 | - /** @var $file File */ |
|
176 | - $targetFolder = $file->getStorage()->getFolder(dirname($file->getIdentifier())); |
|
177 | - |
|
178 | - try { |
|
179 | - $storage = $file->getStorage(); |
|
180 | - $storage->replaceFile($file, $uploadedFile->getFileWithAbsolutePath()); |
|
181 | - |
|
182 | - // Run the indexer for extracting metadata. |
|
183 | - $this->getMediaIndexer($file->getStorage()) |
|
184 | - ->updateIndex($file) |
|
185 | - ->extractMetadata($file); |
|
186 | - |
|
187 | - // Clear cache on pages holding a reference to this file. |
|
188 | - $this->getCacheService()->clearCache($file); |
|
189 | - |
|
190 | - $response = array( |
|
191 | - 'success' => true, |
|
192 | - 'uid' => $file->getUid(), |
|
193 | - 'name' => $file->getName(), |
|
194 | - 'thumbnail' => $this->getThumbnailService($file)->create(), |
|
195 | - 'fileInfo' => $this->getMetadataViewHelper()->render($file), |
|
196 | - ); |
|
197 | - } catch (UploadException $e) { |
|
198 | - $response = array('error' => 'The upload has failed, no uploaded file found!'); |
|
199 | - } catch (InsufficientUserPermissionsException $e) { |
|
200 | - $response = array('error' => 'You are not allowed to upload files!'); |
|
201 | - } catch (UploadSizeException $e) { |
|
202 | - $response = array('error' => vsprintf('The uploaded file "%s" exceeds the size-limit', array($uploadedFile->getName()))); |
|
203 | - } catch (InsufficientFolderWritePermissionsException $e) { |
|
204 | - $response = array('error' => vsprintf('Destination path "%s" was not within your mount points!', array($targetFolder->getIdentifier()))); |
|
205 | - } catch (IllegalFileExtensionException $e) { |
|
206 | - $response = array('error' => vsprintf('Extension of file name "%s" is not allowed in "%s"!', array($uploadedFile->getName(), $targetFolder->getIdentifier()))); |
|
207 | - } catch (ExistingTargetFileNameException $e) { |
|
208 | - $response = array('error' => vsprintf('No unique filename available in "%s"!', array($targetFolder->getIdentifier()))); |
|
209 | - } catch (\RuntimeException $e) { |
|
210 | - $response = array('error' => vsprintf('Uploaded file could not be moved! Write-permission problem in "%s"?', array($targetFolder->getIdentifier()))); |
|
211 | - } |
|
212 | - |
|
213 | - // to pass data through iframe you will need to encode all html tags |
|
214 | - header("Content-Type: text/plain"); |
|
215 | - return $this->htmlResponse(htmlspecialchars(json_encode($response), ENT_NOQUOTES)); |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * Returns an editing form for moving Files between storage. |
|
220 | - * |
|
221 | - * @param array $matches |
|
222 | - * @throws \Exception |
|
223 | - */ |
|
224 | - public function editStorageAction(array $matches = []): ResponseInterface |
|
225 | - { |
|
226 | - $this->view->assign('storages', $this->getMediaModule()->getAllowedStorages()); |
|
227 | - $this->view->assign('storageTitle', Tca::table('sys_file_storage')->getTitle()); |
|
228 | - |
|
229 | - $fieldName = 'storage'; |
|
230 | - |
|
231 | - // Instantiate the Matcher object according different rules. |
|
232 | - $matcher = MatcherObjectFactory::getInstance()->getMatcher($matches, $this->dataType); |
|
233 | - |
|
234 | - // Fetch objects via the Content Service. |
|
235 | - $contentService = $this->getContentService()->findBy($matcher); |
|
236 | - |
|
237 | - $fieldType = Tca::table($this->dataType)->field($fieldName)->getType(); |
|
238 | - |
|
239 | - $this->view->assign('fieldType', ucfirst($fieldType)); |
|
240 | - $this->view->assign('dataType', $this->dataType); |
|
241 | - $this->view->assign('matches', $matches); |
|
242 | - $this->view->assign('fieldNameAndPath', $fieldName); |
|
243 | - $this->view->assign('numberOfObjects', $contentService->getNumberOfObjects()); |
|
244 | - $this->view->assign('editWholeSelection', empty($matches['uid'])); // necessary?? |
|
245 | - return $this->htmlResponse(); |
|
246 | - } |
|
247 | - |
|
248 | - /** |
|
249 | - * Handle file upload. |
|
250 | - * |
|
251 | - * @return UploadedFileInterface|array |
|
252 | - * @throws \InvalidArgumentException |
|
253 | - */ |
|
254 | - protected function handleUpload() |
|
255 | - { |
|
256 | - /** @var $uploadManager UploadManager */ |
|
257 | - $uploadManager = GeneralUtility::makeInstance(UploadManager::class); |
|
258 | - |
|
259 | - try { |
|
260 | - /** @var $result \Fab\Media\FileUpload\UploadedFileInterface */ |
|
261 | - $result = $uploadManager->handleUpload(); |
|
262 | - } catch (\Exception $e) { |
|
263 | - $result = array('error' => $e->getMessage()); |
|
264 | - } |
|
265 | - |
|
266 | - return $result; |
|
267 | - } |
|
268 | - |
|
269 | - /** |
|
270 | - * @return MetadataViewHelper |
|
271 | - * @throws \InvalidArgumentException |
|
272 | - */ |
|
273 | - protected function getMetadataViewHelper() |
|
274 | - { |
|
275 | - return GeneralUtility::makeInstance(MetadataViewHelper::class); |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * @param File $file |
|
280 | - * @return ThumbnailService |
|
281 | - * @throws InvalidKeyInArrayException |
|
282 | - * @throws \InvalidArgumentException |
|
283 | - */ |
|
284 | - protected function getThumbnailService(File $file) |
|
285 | - { |
|
286 | - /** @var $thumbnailService ThumbnailService */ |
|
287 | - $thumbnailService = GeneralUtility::makeInstance(ThumbnailService::class, $file); |
|
288 | - $thumbnailService->setAppendTimeStamp(true) |
|
289 | - ->setOutputType(ThumbnailInterface::OUTPUT_IMAGE_WRAPPED); |
|
290 | - return $thumbnailService; |
|
291 | - } |
|
292 | - |
|
293 | - /** |
|
294 | - * Get the instance of the Indexer service to update the metadata of the file. |
|
295 | - * |
|
296 | - * @param int|ResourceStorage $storage |
|
297 | - * @return MediaIndexer |
|
298 | - * @throws \InvalidArgumentException |
|
299 | - */ |
|
300 | - protected function getMediaIndexer($storage) |
|
301 | - { |
|
302 | - return GeneralUtility::makeInstance(MediaIndexer::class, $storage); |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * @return CacheService |
|
307 | - * @throws \InvalidArgumentException |
|
308 | - */ |
|
309 | - protected function getCacheService() |
|
310 | - { |
|
311 | - return GeneralUtility::makeInstance(CacheService::class); |
|
312 | - } |
|
313 | - |
|
314 | - /** |
|
315 | - * Signal that is emitted before a file is downloaded. |
|
316 | - * |
|
317 | - * @param File $file |
|
318 | - * @return void |
|
319 | - * @throws InvalidSlotReturnException |
|
320 | - * @throws InvalidSlotException |
|
321 | - */ |
|
322 | - protected function emitBeforeDownloadSignal(File $file) |
|
323 | - { |
|
324 | - $this->getSignalSlotDispatcher()->dispatch('Fab\Media\Controller\Backend\AssetController', 'beforeDownload', array($file)); |
|
325 | - } |
|
326 | - |
|
327 | - /** |
|
328 | - * Get the SignalSlot dispatcher. |
|
329 | - * |
|
330 | - * @return Dispatcher |
|
331 | - */ |
|
332 | - protected function getSignalSlotDispatcher() |
|
333 | - { |
|
334 | - return GeneralUtility::makeInstance(Dispatcher::class); |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * @return ContentService |
|
339 | - * @throws \InvalidArgumentException |
|
340 | - */ |
|
341 | - protected function getContentService() |
|
342 | - { |
|
343 | - return GeneralUtility::makeInstance(ContentService::class, $this->dataType); |
|
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * @return MediaModule|object |
|
348 | - * @throws \InvalidArgumentException |
|
349 | - */ |
|
350 | - protected function getMediaModule() |
|
351 | - { |
|
352 | - return GeneralUtility::makeInstance(MediaModule::class); |
|
353 | - } |
|
354 | - |
|
355 | - protected function getResourceFactory(): ResourceFactory |
|
356 | - { |
|
357 | - return GeneralUtility::makeInstance(ResourceFactory::class); |
|
358 | - } |
|
50 | + /** |
|
51 | + * @var string |
|
52 | + */ |
|
53 | + protected $dataType = 'sys_file'; |
|
54 | + |
|
55 | + /** |
|
56 | + * @throws StorageNotOnlineException |
|
57 | + * @throws \InvalidArgumentException |
|
58 | + * @throws NoSuchArgumentException |
|
59 | + */ |
|
60 | + public function initializeAction() |
|
61 | + { |
|
62 | + $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
63 | + $pageRenderer->addInlineLanguageLabelFile('EXT:media/Resources/Private/Language/locallang.xlf'); |
|
64 | + |
|
65 | + // Configure property mapping to retrieve the file object. |
|
66 | + if ($this->arguments->hasArgument('file')) { |
|
67 | + /** @var FileConverter $typeConverter */ |
|
68 | + $typeConverter = GeneralUtility::makeInstance(FileConverter::class); |
|
69 | + |
|
70 | + $propertyMappingConfiguration = $this->arguments->getArgument('file')->getPropertyMappingConfiguration(); |
|
71 | + $propertyMappingConfiguration->setTypeConverter($typeConverter); |
|
72 | + } |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Force download of the file. |
|
77 | + * |
|
78 | + * @param File $file |
|
79 | + * @param bool $forceDownload |
|
80 | + * @return bool|string |
|
81 | + * @throws \RuntimeException |
|
82 | + */ |
|
83 | + public function downloadAction(File $file, $forceDownload = false): ResponseInterface |
|
84 | + { |
|
85 | + if ($file->exists() && $file->getStorage()->isWithinFileMountBoundaries($file->getParentFolder())) { |
|
86 | + // Emit signal before downloading the file. |
|
87 | + $this->emitBeforeDownloadSignal($file); |
|
88 | + |
|
89 | + // Read the file and dump it with the flag "forceDownload" set to true or false. |
|
90 | + $file->getStorage()->streamFile($file, $forceDownload); |
|
91 | + |
|
92 | + $result = true; |
|
93 | + } else { |
|
94 | + $result = 'Access denied!'; |
|
95 | + } |
|
96 | + |
|
97 | + return $this->htmlResponse($result); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Handle file upload for a new file. |
|
102 | + * |
|
103 | + * @param string $combinedIdentifier |
|
104 | + * @Extbase\Validate("\Fab\Media\Domain\Validator\StorageValidator", param="combinedIdentifier") |
|
105 | + * @return string |
|
106 | + */ |
|
107 | + public function createAction($combinedIdentifier): ResponseInterface |
|
108 | + { |
|
109 | + /** @var UploadedFileInterface $uploadedFile */ |
|
110 | + $uploadedFile = $this->handleUpload(); |
|
111 | + if (!is_object($uploadedFile)) { |
|
112 | + return $this->htmlResponse(htmlspecialchars(json_encode($uploadedFile), ENT_NOQUOTES)); |
|
113 | + } |
|
114 | + |
|
115 | + // Get the target folder. |
|
116 | + if ($this->getMediaModule()->hasFolderTree()) { |
|
117 | + $targetFolder = $this->getMediaModule()->getFolderForCombinedIdentifier($combinedIdentifier); |
|
118 | + } else { |
|
119 | + $storage = $this->getResourceFactory()->getStorageObjectFromCombinedIdentifier($combinedIdentifier); |
|
120 | + $targetFolder = $this->getMediaModule()->getTargetFolderForUploadedFile($uploadedFile, $storage); |
|
121 | + } |
|
122 | + |
|
123 | + try { |
|
124 | + $conflictMode = DuplicationBehavior::RENAME; |
|
125 | + $fileName = $uploadedFile->getName(); |
|
126 | + $file = $targetFolder->addFile($uploadedFile->getFileWithAbsolutePath(), $fileName, $conflictMode); |
|
127 | + |
|
128 | + // Run the indexer for extracting metadata. |
|
129 | + $this->getMediaIndexer($file->getStorage()) |
|
130 | + ->extractMetadata($file) |
|
131 | + ->applyDefaultCategories($file); |
|
132 | + |
|
133 | + $response = array( |
|
134 | + 'success' => true, |
|
135 | + 'uid' => $file->getUid(), |
|
136 | + 'name' => $file->getName(), |
|
137 | + 'thumbnail' => $this->getThumbnailService($file)->create(), |
|
138 | + ); |
|
139 | + } catch (UploadException $e) { |
|
140 | + $response = array('error' => 'The upload has failed, no uploaded file found!'); |
|
141 | + } catch (InsufficientUserPermissionsException $e) { |
|
142 | + $response = array('error' => 'You are not allowed to upload files!'); |
|
143 | + } catch (UploadSizeException $e) { |
|
144 | + $response = array('error' => vsprintf('The uploaded file "%s" exceeds the size-limit', array($uploadedFile->getName()))); |
|
145 | + } catch (InsufficientFolderWritePermissionsException $e) { |
|
146 | + $response = array('error' => vsprintf('Destination path "%s" was not within your mount points!', array($targetFolder->getIdentifier()))); |
|
147 | + } catch (IllegalFileExtensionException $e) { |
|
148 | + $response = array('error' => vsprintf('Extension of file name "%s" is not allowed in "%s"!', array($uploadedFile->getName(), $targetFolder->getIdentifier()))); |
|
149 | + } catch (ExistingTargetFileNameException $e) { |
|
150 | + $response = array('error' => vsprintf('No unique filename available in "%s"!', array($targetFolder->getIdentifier()))); |
|
151 | + } catch (\RuntimeException $e) { |
|
152 | + $response = array('error' => vsprintf('Uploaded file could not be moved! Write-permission problem in "%s"?', array($targetFolder->getIdentifier()))); |
|
153 | + } |
|
154 | + |
|
155 | + // to pass data through iframe you will need to encode all html tags |
|
156 | + header("Content-Type: text/plain"); |
|
157 | + return $this->htmlResponse(htmlspecialchars(json_encode($response), ENT_NOQUOTES)); |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * Handle file upload for an existing file. |
|
162 | + * |
|
163 | + * @param File $file |
|
164 | + * @return string |
|
165 | + * @throws \InvalidArgumentException |
|
166 | + * @throws \RuntimeException |
|
167 | + */ |
|
168 | + public function updateAction(File $file): ResponseInterface |
|
169 | + { |
|
170 | + $uploadedFile = $this->handleUpload(); |
|
171 | + if (!is_object($uploadedFile)) { |
|
172 | + return $this->htmlResponse(htmlspecialchars(json_encode($uploadedFile), ENT_NOQUOTES)); |
|
173 | + } |
|
174 | + |
|
175 | + /** @var $file File */ |
|
176 | + $targetFolder = $file->getStorage()->getFolder(dirname($file->getIdentifier())); |
|
177 | + |
|
178 | + try { |
|
179 | + $storage = $file->getStorage(); |
|
180 | + $storage->replaceFile($file, $uploadedFile->getFileWithAbsolutePath()); |
|
181 | + |
|
182 | + // Run the indexer for extracting metadata. |
|
183 | + $this->getMediaIndexer($file->getStorage()) |
|
184 | + ->updateIndex($file) |
|
185 | + ->extractMetadata($file); |
|
186 | + |
|
187 | + // Clear cache on pages holding a reference to this file. |
|
188 | + $this->getCacheService()->clearCache($file); |
|
189 | + |
|
190 | + $response = array( |
|
191 | + 'success' => true, |
|
192 | + 'uid' => $file->getUid(), |
|
193 | + 'name' => $file->getName(), |
|
194 | + 'thumbnail' => $this->getThumbnailService($file)->create(), |
|
195 | + 'fileInfo' => $this->getMetadataViewHelper()->render($file), |
|
196 | + ); |
|
197 | + } catch (UploadException $e) { |
|
198 | + $response = array('error' => 'The upload has failed, no uploaded file found!'); |
|
199 | + } catch (InsufficientUserPermissionsException $e) { |
|
200 | + $response = array('error' => 'You are not allowed to upload files!'); |
|
201 | + } catch (UploadSizeException $e) { |
|
202 | + $response = array('error' => vsprintf('The uploaded file "%s" exceeds the size-limit', array($uploadedFile->getName()))); |
|
203 | + } catch (InsufficientFolderWritePermissionsException $e) { |
|
204 | + $response = array('error' => vsprintf('Destination path "%s" was not within your mount points!', array($targetFolder->getIdentifier()))); |
|
205 | + } catch (IllegalFileExtensionException $e) { |
|
206 | + $response = array('error' => vsprintf('Extension of file name "%s" is not allowed in "%s"!', array($uploadedFile->getName(), $targetFolder->getIdentifier()))); |
|
207 | + } catch (ExistingTargetFileNameException $e) { |
|
208 | + $response = array('error' => vsprintf('No unique filename available in "%s"!', array($targetFolder->getIdentifier()))); |
|
209 | + } catch (\RuntimeException $e) { |
|
210 | + $response = array('error' => vsprintf('Uploaded file could not be moved! Write-permission problem in "%s"?', array($targetFolder->getIdentifier()))); |
|
211 | + } |
|
212 | + |
|
213 | + // to pass data through iframe you will need to encode all html tags |
|
214 | + header("Content-Type: text/plain"); |
|
215 | + return $this->htmlResponse(htmlspecialchars(json_encode($response), ENT_NOQUOTES)); |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * Returns an editing form for moving Files between storage. |
|
220 | + * |
|
221 | + * @param array $matches |
|
222 | + * @throws \Exception |
|
223 | + */ |
|
224 | + public function editStorageAction(array $matches = []): ResponseInterface |
|
225 | + { |
|
226 | + $this->view->assign('storages', $this->getMediaModule()->getAllowedStorages()); |
|
227 | + $this->view->assign('storageTitle', Tca::table('sys_file_storage')->getTitle()); |
|
228 | + |
|
229 | + $fieldName = 'storage'; |
|
230 | + |
|
231 | + // Instantiate the Matcher object according different rules. |
|
232 | + $matcher = MatcherObjectFactory::getInstance()->getMatcher($matches, $this->dataType); |
|
233 | + |
|
234 | + // Fetch objects via the Content Service. |
|
235 | + $contentService = $this->getContentService()->findBy($matcher); |
|
236 | + |
|
237 | + $fieldType = Tca::table($this->dataType)->field($fieldName)->getType(); |
|
238 | + |
|
239 | + $this->view->assign('fieldType', ucfirst($fieldType)); |
|
240 | + $this->view->assign('dataType', $this->dataType); |
|
241 | + $this->view->assign('matches', $matches); |
|
242 | + $this->view->assign('fieldNameAndPath', $fieldName); |
|
243 | + $this->view->assign('numberOfObjects', $contentService->getNumberOfObjects()); |
|
244 | + $this->view->assign('editWholeSelection', empty($matches['uid'])); // necessary?? |
|
245 | + return $this->htmlResponse(); |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * Handle file upload. |
|
250 | + * |
|
251 | + * @return UploadedFileInterface|array |
|
252 | + * @throws \InvalidArgumentException |
|
253 | + */ |
|
254 | + protected function handleUpload() |
|
255 | + { |
|
256 | + /** @var $uploadManager UploadManager */ |
|
257 | + $uploadManager = GeneralUtility::makeInstance(UploadManager::class); |
|
258 | + |
|
259 | + try { |
|
260 | + /** @var $result \Fab\Media\FileUpload\UploadedFileInterface */ |
|
261 | + $result = $uploadManager->handleUpload(); |
|
262 | + } catch (\Exception $e) { |
|
263 | + $result = array('error' => $e->getMessage()); |
|
264 | + } |
|
265 | + |
|
266 | + return $result; |
|
267 | + } |
|
268 | + |
|
269 | + /** |
|
270 | + * @return MetadataViewHelper |
|
271 | + * @throws \InvalidArgumentException |
|
272 | + */ |
|
273 | + protected function getMetadataViewHelper() |
|
274 | + { |
|
275 | + return GeneralUtility::makeInstance(MetadataViewHelper::class); |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * @param File $file |
|
280 | + * @return ThumbnailService |
|
281 | + * @throws InvalidKeyInArrayException |
|
282 | + * @throws \InvalidArgumentException |
|
283 | + */ |
|
284 | + protected function getThumbnailService(File $file) |
|
285 | + { |
|
286 | + /** @var $thumbnailService ThumbnailService */ |
|
287 | + $thumbnailService = GeneralUtility::makeInstance(ThumbnailService::class, $file); |
|
288 | + $thumbnailService->setAppendTimeStamp(true) |
|
289 | + ->setOutputType(ThumbnailInterface::OUTPUT_IMAGE_WRAPPED); |
|
290 | + return $thumbnailService; |
|
291 | + } |
|
292 | + |
|
293 | + /** |
|
294 | + * Get the instance of the Indexer service to update the metadata of the file. |
|
295 | + * |
|
296 | + * @param int|ResourceStorage $storage |
|
297 | + * @return MediaIndexer |
|
298 | + * @throws \InvalidArgumentException |
|
299 | + */ |
|
300 | + protected function getMediaIndexer($storage) |
|
301 | + { |
|
302 | + return GeneralUtility::makeInstance(MediaIndexer::class, $storage); |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * @return CacheService |
|
307 | + * @throws \InvalidArgumentException |
|
308 | + */ |
|
309 | + protected function getCacheService() |
|
310 | + { |
|
311 | + return GeneralUtility::makeInstance(CacheService::class); |
|
312 | + } |
|
313 | + |
|
314 | + /** |
|
315 | + * Signal that is emitted before a file is downloaded. |
|
316 | + * |
|
317 | + * @param File $file |
|
318 | + * @return void |
|
319 | + * @throws InvalidSlotReturnException |
|
320 | + * @throws InvalidSlotException |
|
321 | + */ |
|
322 | + protected function emitBeforeDownloadSignal(File $file) |
|
323 | + { |
|
324 | + $this->getSignalSlotDispatcher()->dispatch('Fab\Media\Controller\Backend\AssetController', 'beforeDownload', array($file)); |
|
325 | + } |
|
326 | + |
|
327 | + /** |
|
328 | + * Get the SignalSlot dispatcher. |
|
329 | + * |
|
330 | + * @return Dispatcher |
|
331 | + */ |
|
332 | + protected function getSignalSlotDispatcher() |
|
333 | + { |
|
334 | + return GeneralUtility::makeInstance(Dispatcher::class); |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * @return ContentService |
|
339 | + * @throws \InvalidArgumentException |
|
340 | + */ |
|
341 | + protected function getContentService() |
|
342 | + { |
|
343 | + return GeneralUtility::makeInstance(ContentService::class, $this->dataType); |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * @return MediaModule|object |
|
348 | + * @throws \InvalidArgumentException |
|
349 | + */ |
|
350 | + protected function getMediaModule() |
|
351 | + { |
|
352 | + return GeneralUtility::makeInstance(MediaModule::class); |
|
353 | + } |
|
354 | + |
|
355 | + protected function getResourceFactory(): ResourceFactory |
|
356 | + { |
|
357 | + return GeneralUtility::makeInstance(ResourceFactory::class); |
|
358 | + } |
|
359 | 359 | } |
@@ -27,327 +27,327 @@ |
||
27 | 27 | */ |
28 | 28 | class MediaModule implements SingletonInterface |
29 | 29 | { |
30 | - /** |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - public const SIGNATURE = 'user_MediaM1'; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - public const PARAMETER_PREFIX = 'tx_media_user_mediam1'; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var ResourceStorage |
|
42 | - */ |
|
43 | - protected $currentStorage; |
|
44 | - |
|
45 | - /** |
|
46 | - * @return string |
|
47 | - */ |
|
48 | - public static function getSignature() |
|
49 | - { |
|
50 | - return self::SIGNATURE; |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * @return string |
|
55 | - */ |
|
56 | - public static function getParameterPrefix() |
|
57 | - { |
|
58 | - return self::PARAMETER_PREFIX; |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Return all storage allowed for the Backend User. |
|
63 | - * |
|
64 | - * @throws \RuntimeException |
|
65 | - * @return ResourceStorage[] |
|
66 | - */ |
|
67 | - public function getAllowedStorages() |
|
68 | - { |
|
69 | - $storages = $this->getBackendUser()->getFileStorages(); |
|
70 | - if (empty($storages)) { |
|
71 | - throw new \RuntimeException('No storage is accessible for the current BE User. Forgotten to define a mount point for this BE User?', 1380801970); |
|
72 | - } |
|
73 | - return $storages; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Returns the current file storage in use. |
|
78 | - * |
|
79 | - * @return ResourceStorage |
|
80 | - */ |
|
81 | - public function getCurrentStorage() |
|
82 | - { |
|
83 | - if (is_null($this->currentStorage)) { |
|
84 | - $storageIdentifier = $this->getStorageIdentifierFromSessionOrArguments(); |
|
85 | - |
|
86 | - if ($storageIdentifier > 0) { |
|
87 | - $currentStorage = $this->getResourceFactory()->getStorageObject($storageIdentifier); |
|
88 | - } else { |
|
89 | - // We differentiate the cases whether the User is admin or not. |
|
90 | - if ($this->getBackendUser()->isAdmin()) { |
|
91 | - $currentStorage = $this->getResourceFactory()->getDefaultStorage(); |
|
92 | - |
|
93 | - // Not default storage has been flagged in "sys_file_storage". |
|
94 | - // Fallback approach: take the first storage as the current. |
|
95 | - if (!$currentStorage) { |
|
96 | - /** @var $storageRepository StorageRepository */ |
|
97 | - $storageRepository = GeneralUtility::makeInstance(StorageRepository::class); |
|
98 | - |
|
99 | - $storages = $storageRepository->findAll(); |
|
100 | - $currentStorage = current($storages); |
|
101 | - } |
|
102 | - } else { |
|
103 | - $fileMounts = $this->getBackendUser()->getFileMountRecords(); |
|
104 | - $firstFileMount = current($fileMounts); |
|
105 | - $currentStorage = $this->getResourceFactory()->getStorageObject($firstFileMount['base']); |
|
106 | - } |
|
107 | - } |
|
108 | - |
|
109 | - $this->currentStorage = $currentStorage; |
|
110 | - } |
|
111 | - return $this->currentStorage; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Retrieve a possible storage identifier from the session or from the arguments. |
|
116 | - * |
|
117 | - * @return int |
|
118 | - */ |
|
119 | - protected function getStorageIdentifierFromSessionOrArguments() |
|
120 | - { |
|
121 | - // Default value |
|
122 | - $storageIdentifier = 0; |
|
123 | - |
|
124 | - // Get last selected storage from User settings |
|
125 | - if (SessionUtility::getInstance()->get('lastSelectedStorage') > 0) { |
|
126 | - $storageIdentifier = SessionUtility::getInstance()->get('lastSelectedStorage'); |
|
127 | - } |
|
128 | - |
|
129 | - $argumentPrefix = $this->getModuleLoader()->getParameterPrefix(); |
|
130 | - $arguments = GeneralUtility::_GET($argumentPrefix); |
|
131 | - |
|
132 | - // Override selected storage from the session if GET argument "storage" is detected. |
|
133 | - if (!empty($arguments['storage']) && (int)$arguments['storage'] > 0) { |
|
134 | - $storageIdentifier = (int)$arguments['storage']; |
|
135 | - |
|
136 | - // Save state |
|
137 | - SessionUtility::getInstance()->set('lastSelectedStorage', $storageIdentifier); |
|
138 | - } |
|
139 | - |
|
140 | - return (int)$storageIdentifier; |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Return the combined parameter from the URL. |
|
145 | - * |
|
146 | - * @return string |
|
147 | - */ |
|
148 | - public function getCombinedIdentifier() |
|
149 | - { |
|
150 | - // Fetch possible combined identifier. |
|
151 | - $combinedIdentifier = GeneralUtility::_GET('id'); |
|
152 | - |
|
153 | - if ($combinedIdentifier) { |
|
154 | - // Fix a bug at the Core level: the "id" parameter is encoded again when translating file. |
|
155 | - // Add a loop to decode maximum 999 time! |
|
156 | - $semaphore = 0; |
|
157 | - $semaphoreLimit = 999; |
|
158 | - while (!$this->isWellDecoded($combinedIdentifier) && $semaphore < $semaphoreLimit) { |
|
159 | - $combinedIdentifier = urldecode($combinedIdentifier); |
|
160 | - $semaphore++; |
|
161 | - } |
|
162 | - } |
|
163 | - |
|
164 | - return $combinedIdentifier; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * @param $combinedIdentifier |
|
169 | - * @return bool |
|
170 | - */ |
|
171 | - protected function isWellDecoded($combinedIdentifier) |
|
172 | - { |
|
173 | - return preg_match('/.*:.*/', $combinedIdentifier); |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * @return Folder |
|
178 | - */ |
|
179 | - public function getFirstAvailableFolder() |
|
180 | - { |
|
181 | - // Take the first object of the first storage. |
|
182 | - $storages = $this->getBackendUser()->getFileStorages(); |
|
183 | - $storage = reset($storages); |
|
184 | - if ($storage) { |
|
185 | - $folder = $storage->getRootLevelFolder(); |
|
186 | - } else { |
|
187 | - throw new \RuntimeException('Could not find any folder to be displayed.', 1444665954); |
|
188 | - } |
|
189 | - return $folder; |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * @return Folder |
|
194 | - */ |
|
195 | - public function getCurrentFolder() |
|
196 | - { |
|
197 | - $combinedIdentifier = $this->getCombinedIdentifier(); |
|
198 | - |
|
199 | - if ($combinedIdentifier) { |
|
200 | - $folder = $this->getFolderForCombinedIdentifier($combinedIdentifier); |
|
201 | - } else { |
|
202 | - $folder = $this->getFirstAvailableFolder(); |
|
203 | - } |
|
204 | - |
|
205 | - return $folder; |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * @param string $combinedIdentifier |
|
210 | - * @return Folder |
|
211 | - */ |
|
212 | - public function getFolderForCombinedIdentifier($combinedIdentifier) |
|
213 | - { |
|
214 | - // Code taken from FileListController.php |
|
215 | - $storage = $this->getResourceFactory()->getStorageObjectFromCombinedIdentifier($combinedIdentifier); |
|
216 | - $identifier = substr($combinedIdentifier, strpos($combinedIdentifier, ':') + 1); |
|
217 | - if (!$storage->hasFolder($identifier)) { |
|
218 | - $identifier = $storage->getFolderIdentifierFromFileIdentifier($identifier); |
|
219 | - } |
|
220 | - |
|
221 | - // Retrieve the folder object. |
|
222 | - $folder = $this->getResourceFactory()->getFolderObjectFromCombinedIdentifier($storage->getUid() . ':' . $identifier); |
|
223 | - |
|
224 | - // Disallow the rendering of the processing folder (e.g. could be called manually) |
|
225 | - // and all folders without any defined storage |
|
226 | - if ($folder && ($folder->getStorage()->getUid() == 0 || trim($folder->getStorage()->getProcessingFolder()->getIdentifier(), '/') === trim($folder->getIdentifier(), '/'))) { |
|
227 | - $storage = $this->getResourceFactory()->getStorageObjectFromCombinedIdentifier($combinedIdentifier); |
|
228 | - $folder = $storage->getRootLevelFolder(); |
|
229 | - } |
|
230 | - |
|
231 | - return $folder; |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * Tell whether the Folder Tree is display or not. |
|
236 | - * |
|
237 | - * @return bool |
|
238 | - */ |
|
239 | - public function hasFolderTree() |
|
240 | - { |
|
241 | - $configuration = $this->getModuleConfiguration(); |
|
242 | - return (bool)$configuration['has_folder_tree']; |
|
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * Tell whether the sub-folders must be included when browsing. |
|
247 | - * |
|
248 | - * @return bool |
|
249 | - */ |
|
250 | - public function hasRecursiveSelection() |
|
251 | - { |
|
252 | - $parameterPrefix = $this->getModuleLoader()->getParameterPrefix(); |
|
253 | - $parameters = GeneralUtility::_GET($parameterPrefix); |
|
254 | - |
|
255 | - $hasRecursiveSelection = true; |
|
256 | - if (isset($parameters['hasRecursiveSelection'])) { |
|
257 | - $hasRecursiveSelection = (bool)$parameters['hasRecursiveSelection']; |
|
258 | - } |
|
259 | - |
|
260 | - return $hasRecursiveSelection; |
|
261 | - } |
|
262 | - |
|
263 | - /** |
|
264 | - * Return the target folder for the uploaded file. |
|
265 | - * |
|
266 | - * @param UploadedFileInterface $uploadedFile |
|
267 | - * @param ResourceStorage $storage |
|
268 | - * @return Folder |
|
269 | - */ |
|
270 | - public function getTargetFolderForUploadedFile(UploadedFileInterface $uploadedFile, ResourceStorage $storage) |
|
271 | - { |
|
272 | - // default is the root level |
|
273 | - $folder = $storage->getRootLevelFolder(); // get the root folder by default |
|
274 | - |
|
275 | - // Get a possible mount point coming from the storage record. |
|
276 | - $storageRecord = $storage->getStorageRecord(); |
|
277 | - $mountPointIdentifier = $storageRecord['mount_point_file_type_' . $uploadedFile->getType()]; |
|
278 | - if ($mountPointIdentifier > 0) { |
|
279 | - // We don't have a Mount Point repository in FAL, so query the database directly. |
|
280 | - $record = $this->getDataService()->getRecord('sys_filemounts', ['uid' => $mountPointIdentifier]); |
|
281 | - |
|
282 | - if (!empty($record['path'])) { |
|
283 | - $folder = $storage->getFolder($record['path']); |
|
284 | - } |
|
285 | - } |
|
286 | - return $folder; |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * Return a new target folder when moving file from one storage to another. |
|
291 | - * |
|
292 | - * @param ResourceStorage $storage |
|
293 | - * @param File $file |
|
294 | - * @return Folder |
|
295 | - */ |
|
296 | - public function getDefaultFolderInStorage(ResourceStorage $storage, File $file) |
|
297 | - { |
|
298 | - // default is the root level |
|
299 | - $folder = $storage->getRootLevelFolder(); |
|
300 | - |
|
301 | - // Retrieve storage record and a possible configured mount point. |
|
302 | - $storageRecord = $storage->getStorageRecord(); |
|
303 | - $mountPointIdentifier = $storageRecord['mount_point_file_type_' . $file->getType()]; |
|
304 | - |
|
305 | - if ($mountPointIdentifier > 0) { |
|
306 | - // We don't have a Mount Point repository in FAL, so query the database directly. |
|
307 | - $record = $this->getDataService()->getRecord('sys_filemounts', ['uid' => $mountPointIdentifier]); |
|
308 | - if (!empty($record['path'])) { |
|
309 | - $folder = $storage->getFolder($record['path']); |
|
310 | - } |
|
311 | - } |
|
312 | - return $folder; |
|
313 | - } |
|
314 | - |
|
315 | - /** |
|
316 | - * @return array |
|
317 | - */ |
|
318 | - protected function getModuleConfiguration() |
|
319 | - { |
|
320 | - return GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('media'); |
|
321 | - } |
|
322 | - |
|
323 | - /** |
|
324 | - * @return object|DataService |
|
325 | - */ |
|
326 | - protected function getDataService(): DataService |
|
327 | - { |
|
328 | - return GeneralUtility::makeInstance(DataService::class); |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * Returns an instance of the current Backend User. |
|
333 | - * |
|
334 | - * @return BackendUserAuthentication |
|
335 | - */ |
|
336 | - protected function getBackendUser() |
|
337 | - { |
|
338 | - return $GLOBALS['BE_USER']; |
|
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * @return ModuleLoader|object |
|
343 | - */ |
|
344 | - protected function getModuleLoader() |
|
345 | - { |
|
346 | - return GeneralUtility::makeInstance(ModuleLoader::class); |
|
347 | - } |
|
348 | - |
|
349 | - protected function getResourceFactory(): ResourceFactory |
|
350 | - { |
|
351 | - return GeneralUtility::makeInstance(ResourceFactory::class); |
|
352 | - } |
|
30 | + /** |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + public const SIGNATURE = 'user_MediaM1'; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + public const PARAMETER_PREFIX = 'tx_media_user_mediam1'; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var ResourceStorage |
|
42 | + */ |
|
43 | + protected $currentStorage; |
|
44 | + |
|
45 | + /** |
|
46 | + * @return string |
|
47 | + */ |
|
48 | + public static function getSignature() |
|
49 | + { |
|
50 | + return self::SIGNATURE; |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * @return string |
|
55 | + */ |
|
56 | + public static function getParameterPrefix() |
|
57 | + { |
|
58 | + return self::PARAMETER_PREFIX; |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Return all storage allowed for the Backend User. |
|
63 | + * |
|
64 | + * @throws \RuntimeException |
|
65 | + * @return ResourceStorage[] |
|
66 | + */ |
|
67 | + public function getAllowedStorages() |
|
68 | + { |
|
69 | + $storages = $this->getBackendUser()->getFileStorages(); |
|
70 | + if (empty($storages)) { |
|
71 | + throw new \RuntimeException('No storage is accessible for the current BE User. Forgotten to define a mount point for this BE User?', 1380801970); |
|
72 | + } |
|
73 | + return $storages; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Returns the current file storage in use. |
|
78 | + * |
|
79 | + * @return ResourceStorage |
|
80 | + */ |
|
81 | + public function getCurrentStorage() |
|
82 | + { |
|
83 | + if (is_null($this->currentStorage)) { |
|
84 | + $storageIdentifier = $this->getStorageIdentifierFromSessionOrArguments(); |
|
85 | + |
|
86 | + if ($storageIdentifier > 0) { |
|
87 | + $currentStorage = $this->getResourceFactory()->getStorageObject($storageIdentifier); |
|
88 | + } else { |
|
89 | + // We differentiate the cases whether the User is admin or not. |
|
90 | + if ($this->getBackendUser()->isAdmin()) { |
|
91 | + $currentStorage = $this->getResourceFactory()->getDefaultStorage(); |
|
92 | + |
|
93 | + // Not default storage has been flagged in "sys_file_storage". |
|
94 | + // Fallback approach: take the first storage as the current. |
|
95 | + if (!$currentStorage) { |
|
96 | + /** @var $storageRepository StorageRepository */ |
|
97 | + $storageRepository = GeneralUtility::makeInstance(StorageRepository::class); |
|
98 | + |
|
99 | + $storages = $storageRepository->findAll(); |
|
100 | + $currentStorage = current($storages); |
|
101 | + } |
|
102 | + } else { |
|
103 | + $fileMounts = $this->getBackendUser()->getFileMountRecords(); |
|
104 | + $firstFileMount = current($fileMounts); |
|
105 | + $currentStorage = $this->getResourceFactory()->getStorageObject($firstFileMount['base']); |
|
106 | + } |
|
107 | + } |
|
108 | + |
|
109 | + $this->currentStorage = $currentStorage; |
|
110 | + } |
|
111 | + return $this->currentStorage; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Retrieve a possible storage identifier from the session or from the arguments. |
|
116 | + * |
|
117 | + * @return int |
|
118 | + */ |
|
119 | + protected function getStorageIdentifierFromSessionOrArguments() |
|
120 | + { |
|
121 | + // Default value |
|
122 | + $storageIdentifier = 0; |
|
123 | + |
|
124 | + // Get last selected storage from User settings |
|
125 | + if (SessionUtility::getInstance()->get('lastSelectedStorage') > 0) { |
|
126 | + $storageIdentifier = SessionUtility::getInstance()->get('lastSelectedStorage'); |
|
127 | + } |
|
128 | + |
|
129 | + $argumentPrefix = $this->getModuleLoader()->getParameterPrefix(); |
|
130 | + $arguments = GeneralUtility::_GET($argumentPrefix); |
|
131 | + |
|
132 | + // Override selected storage from the session if GET argument "storage" is detected. |
|
133 | + if (!empty($arguments['storage']) && (int)$arguments['storage'] > 0) { |
|
134 | + $storageIdentifier = (int)$arguments['storage']; |
|
135 | + |
|
136 | + // Save state |
|
137 | + SessionUtility::getInstance()->set('lastSelectedStorage', $storageIdentifier); |
|
138 | + } |
|
139 | + |
|
140 | + return (int)$storageIdentifier; |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Return the combined parameter from the URL. |
|
145 | + * |
|
146 | + * @return string |
|
147 | + */ |
|
148 | + public function getCombinedIdentifier() |
|
149 | + { |
|
150 | + // Fetch possible combined identifier. |
|
151 | + $combinedIdentifier = GeneralUtility::_GET('id'); |
|
152 | + |
|
153 | + if ($combinedIdentifier) { |
|
154 | + // Fix a bug at the Core level: the "id" parameter is encoded again when translating file. |
|
155 | + // Add a loop to decode maximum 999 time! |
|
156 | + $semaphore = 0; |
|
157 | + $semaphoreLimit = 999; |
|
158 | + while (!$this->isWellDecoded($combinedIdentifier) && $semaphore < $semaphoreLimit) { |
|
159 | + $combinedIdentifier = urldecode($combinedIdentifier); |
|
160 | + $semaphore++; |
|
161 | + } |
|
162 | + } |
|
163 | + |
|
164 | + return $combinedIdentifier; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * @param $combinedIdentifier |
|
169 | + * @return bool |
|
170 | + */ |
|
171 | + protected function isWellDecoded($combinedIdentifier) |
|
172 | + { |
|
173 | + return preg_match('/.*:.*/', $combinedIdentifier); |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * @return Folder |
|
178 | + */ |
|
179 | + public function getFirstAvailableFolder() |
|
180 | + { |
|
181 | + // Take the first object of the first storage. |
|
182 | + $storages = $this->getBackendUser()->getFileStorages(); |
|
183 | + $storage = reset($storages); |
|
184 | + if ($storage) { |
|
185 | + $folder = $storage->getRootLevelFolder(); |
|
186 | + } else { |
|
187 | + throw new \RuntimeException('Could not find any folder to be displayed.', 1444665954); |
|
188 | + } |
|
189 | + return $folder; |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * @return Folder |
|
194 | + */ |
|
195 | + public function getCurrentFolder() |
|
196 | + { |
|
197 | + $combinedIdentifier = $this->getCombinedIdentifier(); |
|
198 | + |
|
199 | + if ($combinedIdentifier) { |
|
200 | + $folder = $this->getFolderForCombinedIdentifier($combinedIdentifier); |
|
201 | + } else { |
|
202 | + $folder = $this->getFirstAvailableFolder(); |
|
203 | + } |
|
204 | + |
|
205 | + return $folder; |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * @param string $combinedIdentifier |
|
210 | + * @return Folder |
|
211 | + */ |
|
212 | + public function getFolderForCombinedIdentifier($combinedIdentifier) |
|
213 | + { |
|
214 | + // Code taken from FileListController.php |
|
215 | + $storage = $this->getResourceFactory()->getStorageObjectFromCombinedIdentifier($combinedIdentifier); |
|
216 | + $identifier = substr($combinedIdentifier, strpos($combinedIdentifier, ':') + 1); |
|
217 | + if (!$storage->hasFolder($identifier)) { |
|
218 | + $identifier = $storage->getFolderIdentifierFromFileIdentifier($identifier); |
|
219 | + } |
|
220 | + |
|
221 | + // Retrieve the folder object. |
|
222 | + $folder = $this->getResourceFactory()->getFolderObjectFromCombinedIdentifier($storage->getUid() . ':' . $identifier); |
|
223 | + |
|
224 | + // Disallow the rendering of the processing folder (e.g. could be called manually) |
|
225 | + // and all folders without any defined storage |
|
226 | + if ($folder && ($folder->getStorage()->getUid() == 0 || trim($folder->getStorage()->getProcessingFolder()->getIdentifier(), '/') === trim($folder->getIdentifier(), '/'))) { |
|
227 | + $storage = $this->getResourceFactory()->getStorageObjectFromCombinedIdentifier($combinedIdentifier); |
|
228 | + $folder = $storage->getRootLevelFolder(); |
|
229 | + } |
|
230 | + |
|
231 | + return $folder; |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * Tell whether the Folder Tree is display or not. |
|
236 | + * |
|
237 | + * @return bool |
|
238 | + */ |
|
239 | + public function hasFolderTree() |
|
240 | + { |
|
241 | + $configuration = $this->getModuleConfiguration(); |
|
242 | + return (bool)$configuration['has_folder_tree']; |
|
243 | + } |
|
244 | + |
|
245 | + /** |
|
246 | + * Tell whether the sub-folders must be included when browsing. |
|
247 | + * |
|
248 | + * @return bool |
|
249 | + */ |
|
250 | + public function hasRecursiveSelection() |
|
251 | + { |
|
252 | + $parameterPrefix = $this->getModuleLoader()->getParameterPrefix(); |
|
253 | + $parameters = GeneralUtility::_GET($parameterPrefix); |
|
254 | + |
|
255 | + $hasRecursiveSelection = true; |
|
256 | + if (isset($parameters['hasRecursiveSelection'])) { |
|
257 | + $hasRecursiveSelection = (bool)$parameters['hasRecursiveSelection']; |
|
258 | + } |
|
259 | + |
|
260 | + return $hasRecursiveSelection; |
|
261 | + } |
|
262 | + |
|
263 | + /** |
|
264 | + * Return the target folder for the uploaded file. |
|
265 | + * |
|
266 | + * @param UploadedFileInterface $uploadedFile |
|
267 | + * @param ResourceStorage $storage |
|
268 | + * @return Folder |
|
269 | + */ |
|
270 | + public function getTargetFolderForUploadedFile(UploadedFileInterface $uploadedFile, ResourceStorage $storage) |
|
271 | + { |
|
272 | + // default is the root level |
|
273 | + $folder = $storage->getRootLevelFolder(); // get the root folder by default |
|
274 | + |
|
275 | + // Get a possible mount point coming from the storage record. |
|
276 | + $storageRecord = $storage->getStorageRecord(); |
|
277 | + $mountPointIdentifier = $storageRecord['mount_point_file_type_' . $uploadedFile->getType()]; |
|
278 | + if ($mountPointIdentifier > 0) { |
|
279 | + // We don't have a Mount Point repository in FAL, so query the database directly. |
|
280 | + $record = $this->getDataService()->getRecord('sys_filemounts', ['uid' => $mountPointIdentifier]); |
|
281 | + |
|
282 | + if (!empty($record['path'])) { |
|
283 | + $folder = $storage->getFolder($record['path']); |
|
284 | + } |
|
285 | + } |
|
286 | + return $folder; |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * Return a new target folder when moving file from one storage to another. |
|
291 | + * |
|
292 | + * @param ResourceStorage $storage |
|
293 | + * @param File $file |
|
294 | + * @return Folder |
|
295 | + */ |
|
296 | + public function getDefaultFolderInStorage(ResourceStorage $storage, File $file) |
|
297 | + { |
|
298 | + // default is the root level |
|
299 | + $folder = $storage->getRootLevelFolder(); |
|
300 | + |
|
301 | + // Retrieve storage record and a possible configured mount point. |
|
302 | + $storageRecord = $storage->getStorageRecord(); |
|
303 | + $mountPointIdentifier = $storageRecord['mount_point_file_type_' . $file->getType()]; |
|
304 | + |
|
305 | + if ($mountPointIdentifier > 0) { |
|
306 | + // We don't have a Mount Point repository in FAL, so query the database directly. |
|
307 | + $record = $this->getDataService()->getRecord('sys_filemounts', ['uid' => $mountPointIdentifier]); |
|
308 | + if (!empty($record['path'])) { |
|
309 | + $folder = $storage->getFolder($record['path']); |
|
310 | + } |
|
311 | + } |
|
312 | + return $folder; |
|
313 | + } |
|
314 | + |
|
315 | + /** |
|
316 | + * @return array |
|
317 | + */ |
|
318 | + protected function getModuleConfiguration() |
|
319 | + { |
|
320 | + return GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('media'); |
|
321 | + } |
|
322 | + |
|
323 | + /** |
|
324 | + * @return object|DataService |
|
325 | + */ |
|
326 | + protected function getDataService(): DataService |
|
327 | + { |
|
328 | + return GeneralUtility::makeInstance(DataService::class); |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * Returns an instance of the current Backend User. |
|
333 | + * |
|
334 | + * @return BackendUserAuthentication |
|
335 | + */ |
|
336 | + protected function getBackendUser() |
|
337 | + { |
|
338 | + return $GLOBALS['BE_USER']; |
|
339 | + } |
|
340 | + |
|
341 | + /** |
|
342 | + * @return ModuleLoader|object |
|
343 | + */ |
|
344 | + protected function getModuleLoader() |
|
345 | + { |
|
346 | + return GeneralUtility::makeInstance(ModuleLoader::class); |
|
347 | + } |
|
348 | + |
|
349 | + protected function getResourceFactory(): ResourceFactory |
|
350 | + { |
|
351 | + return GeneralUtility::makeInstance(ResourceFactory::class); |
|
352 | + } |
|
353 | 353 | } |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | } |
220 | 220 | |
221 | 221 | // Retrieve the folder object. |
222 | - $folder = $this->getResourceFactory()->getFolderObjectFromCombinedIdentifier($storage->getUid() . ':' . $identifier); |
|
222 | + $folder = $this->getResourceFactory()->getFolderObjectFromCombinedIdentifier($storage->getUid().':'.$identifier); |
|
223 | 223 | |
224 | 224 | // Disallow the rendering of the processing folder (e.g. could be called manually) |
225 | 225 | // and all folders without any defined storage |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | |
275 | 275 | // Get a possible mount point coming from the storage record. |
276 | 276 | $storageRecord = $storage->getStorageRecord(); |
277 | - $mountPointIdentifier = $storageRecord['mount_point_file_type_' . $uploadedFile->getType()]; |
|
277 | + $mountPointIdentifier = $storageRecord['mount_point_file_type_'.$uploadedFile->getType()]; |
|
278 | 278 | if ($mountPointIdentifier > 0) { |
279 | 279 | // We don't have a Mount Point repository in FAL, so query the database directly. |
280 | 280 | $record = $this->getDataService()->getRecord('sys_filemounts', ['uid' => $mountPointIdentifier]); |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | |
301 | 301 | // Retrieve storage record and a possible configured mount point. |
302 | 302 | $storageRecord = $storage->getStorageRecord(); |
303 | - $mountPointIdentifier = $storageRecord['mount_point_file_type_' . $file->getType()]; |
|
303 | + $mountPointIdentifier = $storageRecord['mount_point_file_type_'.$file->getType()]; |
|
304 | 304 | |
305 | 305 | if ($mountPointIdentifier > 0) { |
306 | 306 | // We don't have a Mount Point repository in FAL, so query the database directly. |