@@ -17,85 +17,85 @@ |
||
17 | 17 | */ |
18 | 18 | class AudioThumbnailProcessor extends AbstractThumbnailProcessor |
19 | 19 | { |
20 | - /** |
|
21 | - * Render a thumbnail of a resource of type audio. |
|
22 | - */ |
|
23 | - public function create(): string |
|
24 | - { |
|
25 | - $steps = $this->getRenderingSteps(); |
|
20 | + /** |
|
21 | + * Render a thumbnail of a resource of type audio. |
|
22 | + */ |
|
23 | + public function create(): string |
|
24 | + { |
|
25 | + $steps = $this->getRenderingSteps(); |
|
26 | 26 | |
27 | - $result = ''; |
|
28 | - while ($step = array_shift($steps)) { |
|
29 | - $result = $this->$step($result); |
|
30 | - } |
|
27 | + $result = ''; |
|
28 | + while ($step = array_shift($steps)) { |
|
29 | + $result = $this->$step($result); |
|
30 | + } |
|
31 | 31 | |
32 | - return $result; |
|
33 | - } |
|
32 | + return $result; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Render the URI of the thumbnail. |
|
37 | - */ |
|
38 | - public function renderUri(): string |
|
39 | - { |
|
40 | - $relativePath = sprintf('Icons/MimeType/%s.png', $this->getFile()->getProperty('extension')); |
|
41 | - $fileNameAndPath = GeneralUtility::getFileAbsFileName('EXT:media/Resources/Public/' . $relativePath); |
|
42 | - if (!file_exists($fileNameAndPath)) { |
|
43 | - $relativePath = 'Icons/UnknownMimeType.png'; |
|
44 | - } |
|
35 | + /** |
|
36 | + * Render the URI of the thumbnail. |
|
37 | + */ |
|
38 | + public function renderUri(): string |
|
39 | + { |
|
40 | + $relativePath = sprintf('Icons/MimeType/%s.png', $this->getFile()->getProperty('extension')); |
|
41 | + $fileNameAndPath = GeneralUtility::getFileAbsFileName('EXT:media/Resources/Public/' . $relativePath); |
|
42 | + if (!file_exists($fileNameAndPath)) { |
|
43 | + $relativePath = 'Icons/UnknownMimeType.png'; |
|
44 | + } |
|
45 | 45 | |
46 | - $uri = Path::getRelativePath($relativePath); |
|
47 | - return $this->prefixUri($uri); |
|
48 | - } |
|
46 | + $uri = Path::getRelativePath($relativePath); |
|
47 | + return $this->prefixUri($uri); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Render the tag image which is the main one for a thumbnail. |
|
52 | - * |
|
53 | - * @param string $result |
|
54 | - */ |
|
55 | - public function renderTagImage($result): string |
|
56 | - { |
|
57 | - // Variable $result corresponds to an URL in this case. |
|
58 | - // Analyse the URL and compute the adequate separator between arguments. |
|
59 | - $parameterSeparator = strpos($result, '?') === false ? '?' : '&'; |
|
50 | + /** |
|
51 | + * Render the tag image which is the main one for a thumbnail. |
|
52 | + * |
|
53 | + * @param string $result |
|
54 | + */ |
|
55 | + public function renderTagImage($result): string |
|
56 | + { |
|
57 | + // Variable $result corresponds to an URL in this case. |
|
58 | + // Analyse the URL and compute the adequate separator between arguments. |
|
59 | + $parameterSeparator = strpos($result, '?') === false ? '?' : '&'; |
|
60 | 60 | |
61 | - return sprintf( |
|
62 | - '<img src="%s%s" title="%s" alt="%s" %s/>', |
|
63 | - $result, |
|
64 | - $this->thumbnailService->getAppendTimeStamp() ? $parameterSeparator . $this->getFile()->getProperty('tstamp') : '', |
|
65 | - $this->getTitle(), |
|
66 | - $this->getTitle(), |
|
67 | - $this->renderAttributes() |
|
68 | - ); |
|
69 | - } |
|
61 | + return sprintf( |
|
62 | + '<img src="%s%s" title="%s" alt="%s" %s/>', |
|
63 | + $result, |
|
64 | + $this->thumbnailService->getAppendTimeStamp() ? $parameterSeparator . $this->getFile()->getProperty('tstamp') : '', |
|
65 | + $this->getTitle(), |
|
66 | + $this->getTitle(), |
|
67 | + $this->renderAttributes() |
|
68 | + ); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Compute and return the title of the file. |
|
73 | - */ |
|
74 | - protected function getTitle(): string |
|
75 | - { |
|
76 | - $result = $this->getFile()->getProperty('title'); |
|
77 | - if (!$result) { |
|
78 | - $result = $this->getFile()->getName(); |
|
79 | - } |
|
80 | - return htmlspecialchars($result); |
|
81 | - } |
|
71 | + /** |
|
72 | + * Compute and return the title of the file. |
|
73 | + */ |
|
74 | + protected function getTitle(): string |
|
75 | + { |
|
76 | + $result = $this->getFile()->getProperty('title'); |
|
77 | + if (!$result) { |
|
78 | + $result = $this->getFile()->getName(); |
|
79 | + } |
|
80 | + return htmlspecialchars($result); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Render a wrapping anchor around the thumbnail. |
|
85 | - * |
|
86 | - * @param string $result |
|
87 | - */ |
|
88 | - public function renderTagAnchor($result): string |
|
89 | - { |
|
90 | - $file = $this->getFile(); |
|
83 | + /** |
|
84 | + * Render a wrapping anchor around the thumbnail. |
|
85 | + * |
|
86 | + * @param string $result |
|
87 | + */ |
|
88 | + public function renderTagAnchor($result): string |
|
89 | + { |
|
90 | + $file = $this->getFile(); |
|
91 | 91 | |
92 | - return sprintf( |
|
93 | - '<a href="%s%s" target="%s" data-uid="%s">%s</a>', |
|
94 | - $this->thumbnailService->getAnchorUri() ? $this->thumbnailService->getAnchorUri() : $file->getPublicUrl(true), |
|
95 | - $this->thumbnailService->getAppendTimeStamp() ? '?' . $file->getProperty('tstamp') : '', |
|
96 | - $this->thumbnailService->getTarget(), |
|
97 | - $file->getUid(), |
|
98 | - $result |
|
99 | - ); |
|
100 | - } |
|
92 | + return sprintf( |
|
93 | + '<a href="%s%s" target="%s" data-uid="%s">%s</a>', |
|
94 | + $this->thumbnailService->getAnchorUri() ? $this->thumbnailService->getAnchorUri() : $file->getPublicUrl(true), |
|
95 | + $this->thumbnailService->getAppendTimeStamp() ? '?' . $file->getProperty('tstamp') : '', |
|
96 | + $this->thumbnailService->getTarget(), |
|
97 | + $file->getUid(), |
|
98 | + $result |
|
99 | + ); |
|
100 | + } |
|
101 | 101 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | public function renderUri(): string |
39 | 39 | { |
40 | 40 | $relativePath = sprintf('Icons/MimeType/%s.png', $this->getFile()->getProperty('extension')); |
41 | - $fileNameAndPath = GeneralUtility::getFileAbsFileName('EXT:media/Resources/Public/' . $relativePath); |
|
41 | + $fileNameAndPath = GeneralUtility::getFileAbsFileName('EXT:media/Resources/Public/'.$relativePath); |
|
42 | 42 | if (!file_exists($fileNameAndPath)) { |
43 | 43 | $relativePath = 'Icons/UnknownMimeType.png'; |
44 | 44 | } |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | return sprintf( |
62 | 62 | '<img src="%s%s" title="%s" alt="%s" %s/>', |
63 | 63 | $result, |
64 | - $this->thumbnailService->getAppendTimeStamp() ? $parameterSeparator . $this->getFile()->getProperty('tstamp') : '', |
|
64 | + $this->thumbnailService->getAppendTimeStamp() ? $parameterSeparator.$this->getFile()->getProperty('tstamp') : '', |
|
65 | 65 | $this->getTitle(), |
66 | 66 | $this->getTitle(), |
67 | 67 | $this->renderAttributes() |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | return sprintf( |
93 | 93 | '<a href="%s%s" target="%s" data-uid="%s">%s</a>', |
94 | 94 | $this->thumbnailService->getAnchorUri() ? $this->thumbnailService->getAnchorUri() : $file->getPublicUrl(true), |
95 | - $this->thumbnailService->getAppendTimeStamp() ? '?' . $file->getProperty('tstamp') : '', |
|
95 | + $this->thumbnailService->getAppendTimeStamp() ? '?'.$file->getProperty('tstamp') : '', |
|
96 | 96 | $this->thumbnailService->getTarget(), |
97 | 97 | $file->getUid(), |
98 | 98 | $result |
@@ -23,241 +23,241 @@ |
||
23 | 23 | */ |
24 | 24 | class ActionPermissionFacet implements FacetInterface |
25 | 25 | { |
26 | - /** |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - protected $name = '__action_permission'; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - protected $label = 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:permission'; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var array |
|
38 | - */ |
|
39 | - protected $suggestions = array( |
|
40 | - 'r' => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:facet.read_only', |
|
41 | - 'w' => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:facet.write', |
|
42 | - ); |
|
43 | - |
|
44 | - /** |
|
45 | - * @var string |
|
46 | - */ |
|
47 | - protected $fieldNameAndPath = ''; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - protected $dataType; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var bool |
|
56 | - */ |
|
57 | - protected $canModifyMatcher = false; |
|
58 | - |
|
59 | - /** |
|
60 | - * Constructor of a Generic Facet in Vidi. |
|
61 | - * |
|
62 | - * @param string $name |
|
63 | - * @param string $label |
|
64 | - * @param array $suggestions |
|
65 | - * @param string $fieldNameAndPath |
|
66 | - */ |
|
67 | - public function __construct($name = '', $label = '', array $suggestions = [], $fieldNameAndPath = '') |
|
68 | - { |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @return string |
|
73 | - */ |
|
74 | - public function getName() |
|
75 | - { |
|
76 | - return $this->name; |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * @return string |
|
81 | - */ |
|
82 | - public function getLabel() |
|
83 | - { |
|
84 | - return $this->getLanguageService()->sL($this->label); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @return array |
|
89 | - */ |
|
90 | - public function getSuggestions() |
|
91 | - { |
|
92 | - $suggestions = []; |
|
93 | - foreach ($this->suggestions as $key => $label) { |
|
94 | - $suggestions[] = array($key => $this->getLanguageService()->sL($label)); |
|
95 | - } |
|
96 | - |
|
97 | - return $suggestions; |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * @return bool |
|
102 | - */ |
|
103 | - public function hasSuggestions() |
|
104 | - { |
|
105 | - return true; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * @param string $dataType |
|
110 | - * @return $this |
|
111 | - */ |
|
112 | - public function setDataType($dataType) |
|
113 | - { |
|
114 | - $this->dataType = $dataType; |
|
115 | - return $this; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * @return bool |
|
120 | - */ |
|
121 | - public function canModifyMatcher() |
|
122 | - { |
|
123 | - return $this->canModifyMatcher; |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * @param Matcher $matcher |
|
128 | - * @param $value |
|
129 | - * @return Matcher |
|
130 | - */ |
|
131 | - public function modifyMatcher(Matcher $matcher, $value) |
|
132 | - { |
|
133 | - return $matcher; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * @param AfterFindContentObjectsSignalArguments $signalArguments |
|
138 | - * @return array |
|
139 | - */ |
|
140 | - public function modifyResultSet(AfterFindContentObjectsSignalArguments $signalArguments) |
|
141 | - { |
|
142 | - if ($signalArguments->getDataType() === 'sys_file') { |
|
143 | - $queryParts = $this->getQueryParts(); |
|
144 | - |
|
145 | - if (!empty($queryParts)) { |
|
146 | - $permission = $this->getPermissionValue($queryParts); |
|
147 | - |
|
148 | - if ($permission) { |
|
149 | - // We are force to query the content repository again here without limit |
|
150 | - $matcher = $signalArguments->getMatcher(); |
|
151 | - $order = $signalArguments->getOrder(); |
|
152 | - $objects = ContentRepositoryFactory::getInstance($this->dataType)->findBy($matcher, $order); |
|
153 | - |
|
154 | - $filteredObjects = []; |
|
155 | - foreach ($objects as $object) { |
|
156 | - $file = $this->getFileConverter()->convert($object->getUid()); |
|
157 | - if ($permission === 'read' && !$file->checkActionPermission('write')) { |
|
158 | - $filteredObjects[] = $object; |
|
159 | - } elseif ($permission === 'write' && $file->checkActionPermission('write')) { |
|
160 | - $filteredObjects[] = $object; |
|
161 | - } |
|
162 | - } |
|
163 | - |
|
164 | - // Only take part of the array according to offset and limit. |
|
165 | - $offset = $signalArguments->getOffset(); |
|
166 | - $limit = $signalArguments->getLimit(); |
|
167 | - $signalArguments->setContentObjects(array_slice($filteredObjects, $offset, $limit)); |
|
168 | - |
|
169 | - // Count number of records |
|
170 | - $signalArguments->setNumberOfObjects(count($filteredObjects)); |
|
171 | - $signalArguments->setHasBeenProcessed(true); |
|
172 | - } |
|
173 | - } |
|
174 | - } |
|
175 | - |
|
176 | - return array($signalArguments); |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * @return array |
|
181 | - */ |
|
182 | - protected function getQueryParts() |
|
183 | - { |
|
184 | - // Transmit recursive selection parameter. |
|
185 | - $parameterPrefix = $this->getModuleLoader()->getParameterPrefix(); |
|
186 | - $parameters = GeneralUtility::_GP($parameterPrefix); |
|
187 | - |
|
188 | - $queryParts = []; |
|
189 | - if (!empty($parameters['searchTerm'])) { |
|
190 | - $query = rawurldecode($parameters['searchTerm']); |
|
191 | - $queryParts = json_decode($query, true); |
|
192 | - } |
|
193 | - |
|
194 | - return $queryParts; |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * Retrieve the search permission value. |
|
199 | - * |
|
200 | - * @param array $queryParts |
|
201 | - * @return string |
|
202 | - */ |
|
203 | - protected function getPermissionValue(array $queryParts) |
|
204 | - { |
|
205 | - $permission = ''; |
|
206 | - |
|
207 | - // Check also amongst labels. |
|
208 | - $labelReadOnly = $this->getLanguageService()->sL($this->suggestions['r']); |
|
209 | - $labelWrite = $this->getLanguageService()->sL($this->suggestions['w']); |
|
210 | - |
|
211 | - foreach ($queryParts as $queryPart) { |
|
212 | - $facetName = key($queryPart); |
|
213 | - $value = $queryPart[$facetName]; |
|
214 | - if ($facetName === $this->name) { |
|
215 | - if ($value === 'r' || $value === $labelReadOnly) { |
|
216 | - $permission = 'read'; |
|
217 | - } elseif ($value === 'w' || $value === $labelWrite) { |
|
218 | - $permission = 'write'; |
|
219 | - } |
|
220 | - } |
|
221 | - } |
|
222 | - return $permission; |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * Magic method implementation for retrieving state. |
|
227 | - * |
|
228 | - * @param array $states |
|
229 | - * @return $this |
|
230 | - */ |
|
231 | - public static function __set_state($states) |
|
232 | - { |
|
233 | - return new ActionPermissionFacet($states['name'], $states['label'], $states['suggestions'], $states['fieldNameAndPath']); |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * @return LanguageService |
|
238 | - */ |
|
239 | - protected function getLanguageService() |
|
240 | - { |
|
241 | - return $GLOBALS['LANG']; |
|
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * @return ContentToFileConverter |
|
246 | - * @throws \InvalidArgumentException |
|
247 | - */ |
|
248 | - protected function getFileConverter() |
|
249 | - { |
|
250 | - return GeneralUtility::makeInstance(ContentToFileConverter::class); |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * Get the Vidi Module Loader. |
|
255 | - * |
|
256 | - * @return ModuleLoader |
|
257 | - * @throws \InvalidArgumentException |
|
258 | - */ |
|
259 | - protected function getModuleLoader() |
|
260 | - { |
|
261 | - return GeneralUtility::makeInstance(ModuleLoader::class); |
|
262 | - } |
|
26 | + /** |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + protected $name = '__action_permission'; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + protected $label = 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:permission'; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var array |
|
38 | + */ |
|
39 | + protected $suggestions = array( |
|
40 | + 'r' => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:facet.read_only', |
|
41 | + 'w' => 'LLL:EXT:media/Resources/Private/Language/locallang.xlf:facet.write', |
|
42 | + ); |
|
43 | + |
|
44 | + /** |
|
45 | + * @var string |
|
46 | + */ |
|
47 | + protected $fieldNameAndPath = ''; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + protected $dataType; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var bool |
|
56 | + */ |
|
57 | + protected $canModifyMatcher = false; |
|
58 | + |
|
59 | + /** |
|
60 | + * Constructor of a Generic Facet in Vidi. |
|
61 | + * |
|
62 | + * @param string $name |
|
63 | + * @param string $label |
|
64 | + * @param array $suggestions |
|
65 | + * @param string $fieldNameAndPath |
|
66 | + */ |
|
67 | + public function __construct($name = '', $label = '', array $suggestions = [], $fieldNameAndPath = '') |
|
68 | + { |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @return string |
|
73 | + */ |
|
74 | + public function getName() |
|
75 | + { |
|
76 | + return $this->name; |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * @return string |
|
81 | + */ |
|
82 | + public function getLabel() |
|
83 | + { |
|
84 | + return $this->getLanguageService()->sL($this->label); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @return array |
|
89 | + */ |
|
90 | + public function getSuggestions() |
|
91 | + { |
|
92 | + $suggestions = []; |
|
93 | + foreach ($this->suggestions as $key => $label) { |
|
94 | + $suggestions[] = array($key => $this->getLanguageService()->sL($label)); |
|
95 | + } |
|
96 | + |
|
97 | + return $suggestions; |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * @return bool |
|
102 | + */ |
|
103 | + public function hasSuggestions() |
|
104 | + { |
|
105 | + return true; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * @param string $dataType |
|
110 | + * @return $this |
|
111 | + */ |
|
112 | + public function setDataType($dataType) |
|
113 | + { |
|
114 | + $this->dataType = $dataType; |
|
115 | + return $this; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * @return bool |
|
120 | + */ |
|
121 | + public function canModifyMatcher() |
|
122 | + { |
|
123 | + return $this->canModifyMatcher; |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * @param Matcher $matcher |
|
128 | + * @param $value |
|
129 | + * @return Matcher |
|
130 | + */ |
|
131 | + public function modifyMatcher(Matcher $matcher, $value) |
|
132 | + { |
|
133 | + return $matcher; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * @param AfterFindContentObjectsSignalArguments $signalArguments |
|
138 | + * @return array |
|
139 | + */ |
|
140 | + public function modifyResultSet(AfterFindContentObjectsSignalArguments $signalArguments) |
|
141 | + { |
|
142 | + if ($signalArguments->getDataType() === 'sys_file') { |
|
143 | + $queryParts = $this->getQueryParts(); |
|
144 | + |
|
145 | + if (!empty($queryParts)) { |
|
146 | + $permission = $this->getPermissionValue($queryParts); |
|
147 | + |
|
148 | + if ($permission) { |
|
149 | + // We are force to query the content repository again here without limit |
|
150 | + $matcher = $signalArguments->getMatcher(); |
|
151 | + $order = $signalArguments->getOrder(); |
|
152 | + $objects = ContentRepositoryFactory::getInstance($this->dataType)->findBy($matcher, $order); |
|
153 | + |
|
154 | + $filteredObjects = []; |
|
155 | + foreach ($objects as $object) { |
|
156 | + $file = $this->getFileConverter()->convert($object->getUid()); |
|
157 | + if ($permission === 'read' && !$file->checkActionPermission('write')) { |
|
158 | + $filteredObjects[] = $object; |
|
159 | + } elseif ($permission === 'write' && $file->checkActionPermission('write')) { |
|
160 | + $filteredObjects[] = $object; |
|
161 | + } |
|
162 | + } |
|
163 | + |
|
164 | + // Only take part of the array according to offset and limit. |
|
165 | + $offset = $signalArguments->getOffset(); |
|
166 | + $limit = $signalArguments->getLimit(); |
|
167 | + $signalArguments->setContentObjects(array_slice($filteredObjects, $offset, $limit)); |
|
168 | + |
|
169 | + // Count number of records |
|
170 | + $signalArguments->setNumberOfObjects(count($filteredObjects)); |
|
171 | + $signalArguments->setHasBeenProcessed(true); |
|
172 | + } |
|
173 | + } |
|
174 | + } |
|
175 | + |
|
176 | + return array($signalArguments); |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * @return array |
|
181 | + */ |
|
182 | + protected function getQueryParts() |
|
183 | + { |
|
184 | + // Transmit recursive selection parameter. |
|
185 | + $parameterPrefix = $this->getModuleLoader()->getParameterPrefix(); |
|
186 | + $parameters = GeneralUtility::_GP($parameterPrefix); |
|
187 | + |
|
188 | + $queryParts = []; |
|
189 | + if (!empty($parameters['searchTerm'])) { |
|
190 | + $query = rawurldecode($parameters['searchTerm']); |
|
191 | + $queryParts = json_decode($query, true); |
|
192 | + } |
|
193 | + |
|
194 | + return $queryParts; |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * Retrieve the search permission value. |
|
199 | + * |
|
200 | + * @param array $queryParts |
|
201 | + * @return string |
|
202 | + */ |
|
203 | + protected function getPermissionValue(array $queryParts) |
|
204 | + { |
|
205 | + $permission = ''; |
|
206 | + |
|
207 | + // Check also amongst labels. |
|
208 | + $labelReadOnly = $this->getLanguageService()->sL($this->suggestions['r']); |
|
209 | + $labelWrite = $this->getLanguageService()->sL($this->suggestions['w']); |
|
210 | + |
|
211 | + foreach ($queryParts as $queryPart) { |
|
212 | + $facetName = key($queryPart); |
|
213 | + $value = $queryPart[$facetName]; |
|
214 | + if ($facetName === $this->name) { |
|
215 | + if ($value === 'r' || $value === $labelReadOnly) { |
|
216 | + $permission = 'read'; |
|
217 | + } elseif ($value === 'w' || $value === $labelWrite) { |
|
218 | + $permission = 'write'; |
|
219 | + } |
|
220 | + } |
|
221 | + } |
|
222 | + return $permission; |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * Magic method implementation for retrieving state. |
|
227 | + * |
|
228 | + * @param array $states |
|
229 | + * @return $this |
|
230 | + */ |
|
231 | + public static function __set_state($states) |
|
232 | + { |
|
233 | + return new ActionPermissionFacet($states['name'], $states['label'], $states['suggestions'], $states['fieldNameAndPath']); |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * @return LanguageService |
|
238 | + */ |
|
239 | + protected function getLanguageService() |
|
240 | + { |
|
241 | + return $GLOBALS['LANG']; |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * @return ContentToFileConverter |
|
246 | + * @throws \InvalidArgumentException |
|
247 | + */ |
|
248 | + protected function getFileConverter() |
|
249 | + { |
|
250 | + return GeneralUtility::makeInstance(ContentToFileConverter::class); |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * Get the Vidi Module Loader. |
|
255 | + * |
|
256 | + * @return ModuleLoader |
|
257 | + * @throws \InvalidArgumentException |
|
258 | + */ |
|
259 | + protected function getModuleLoader() |
|
260 | + { |
|
261 | + return GeneralUtility::makeInstance(ModuleLoader::class); |
|
262 | + } |
|
263 | 263 | } |
@@ -23,151 +23,151 @@ |
||
23 | 23 | */ |
24 | 24 | class MediaIndexer |
25 | 25 | { |
26 | - /** |
|
27 | - * @var ResourceStorage |
|
28 | - */ |
|
29 | - protected $storage = null; |
|
30 | - |
|
31 | - /** |
|
32 | - * @param ResourceStorage $storage |
|
33 | - */ |
|
34 | - public function __construct(ResourceStorage $storage) |
|
35 | - { |
|
36 | - $this->storage = $storage; |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * @param File $file |
|
41 | - * @return $this |
|
42 | - */ |
|
43 | - public function updateIndex(File $file) |
|
44 | - { |
|
45 | - $this->getCoreIndexer()->updateIndexEntry($file); |
|
46 | - return $this; |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * @param File $file |
|
51 | - * @return $this |
|
52 | - */ |
|
53 | - public function extractMetadata(File $file) |
|
54 | - { |
|
55 | - $extractionServices = $this->getExtractorRegistry()->getExtractorsWithDriverSupport($this->storage->getDriverType()); |
|
56 | - |
|
57 | - $newMetaData = array( |
|
58 | - 0 => $file->getMetaData()->get() |
|
59 | - ); |
|
60 | - |
|
61 | - foreach ($extractionServices as $services) { |
|
62 | - if (is_array($services)) { |
|
63 | - foreach ($services as $service) { |
|
64 | - if ($service->canProcess($file)) { |
|
65 | - $newMetaData[$service->getPriority()] = $service->extractMetaData($file, $newMetaData); |
|
66 | - } |
|
67 | - } |
|
68 | - } else { |
|
69 | - $service = $services; |
|
70 | - // We could optimise here for not repeating this bit |
|
71 | - if ($service->canProcess($file)) { |
|
72 | - $newMetaData[$service->getPriority()] = $service->extractMetaData($file, $newMetaData); |
|
73 | - } |
|
74 | - } |
|
75 | - } |
|
76 | - |
|
77 | - ksort($newMetaData); |
|
78 | - $metaData = []; |
|
79 | - foreach ($newMetaData as $data) { |
|
80 | - $metaData = array_merge($metaData, $data); |
|
81 | - } |
|
82 | - $file->updateProperties($metaData); |
|
83 | - $this->getMetaDataRepository()->update($file->getUid(), $metaData); |
|
84 | - $this->getFileIndexRepository()->updateIndexingTime($file->getUid()); |
|
85 | - |
|
86 | - return $this; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * @param File $file |
|
91 | - * @return $this |
|
92 | - */ |
|
93 | - public function applyDefaultCategories(File $file) |
|
94 | - { |
|
95 | - $categoryList = ConfigurationUtility::getInstance()->get('default_categories'); |
|
96 | - $categories = GeneralUtility::trimExplode(',', $categoryList, true); |
|
97 | - |
|
98 | - foreach ($categories as $category) { |
|
99 | - $values = array( |
|
100 | - 'uid_local' => $category, |
|
101 | - 'uid_foreign' => $this->getFileMetadataIdentifier($file), |
|
102 | - 'tablenames' => 'sys_file_metadata', |
|
103 | - 'fieldname' => 'categories', |
|
104 | - ); |
|
105 | - $this->getDataService()->insert('sys_category_record_mm', $values); |
|
106 | - } |
|
107 | - |
|
108 | - $metaData['categories'] = count($categories); |
|
109 | - $file->updateProperties($metaData); |
|
110 | - $this->getMetaDataRepository()->update($file->getUid(), $metaData); |
|
111 | - $this->getFileIndexRepository()->updateIndexingTime($file->getUid()); |
|
112 | - return $this; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Retrieve the file metadata uid which is different from the file uid. |
|
117 | - * |
|
118 | - * @param File $file |
|
119 | - * @return int |
|
120 | - */ |
|
121 | - protected function getFileMetadataIdentifier(File $file) |
|
122 | - { |
|
123 | - $metadataProperties = $file->getMetaData()->get(); |
|
124 | - return isset($metadataProperties['_ORIG_uid']) ? (int)$metadataProperties['_ORIG_uid'] : (int)$metadataProperties['uid']; |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * Returns an instance of the FileIndexRepository |
|
130 | - * |
|
131 | - * @return FileIndexRepository |
|
132 | - */ |
|
133 | - protected function getFileIndexRepository() |
|
134 | - { |
|
135 | - return GeneralUtility::makeInstance(FileIndexRepository::class); |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Returns an instance of the FileIndexRepository |
|
140 | - * |
|
141 | - * @return MetaDataRepository |
|
142 | - */ |
|
143 | - protected function getMetaDataRepository() |
|
144 | - { |
|
145 | - return GeneralUtility::makeInstance(MetaDataRepository::class); |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * Returns an instance of the FileIndexRepository |
|
150 | - * |
|
151 | - * @return ExtractorRegistry |
|
152 | - */ |
|
153 | - protected function getExtractorRegistry() |
|
154 | - { |
|
155 | - return GeneralUtility::makeInstance(ExtractorRegistry::class); |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * @return object|DataService |
|
160 | - */ |
|
161 | - protected function getDataService(): DataService |
|
162 | - { |
|
163 | - return GeneralUtility::makeInstance(DataService::class); |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * @return Indexer|object |
|
168 | - */ |
|
169 | - protected function getCoreIndexer() |
|
170 | - { |
|
171 | - return GeneralUtility::makeInstance(Indexer::class, $this->storage); |
|
172 | - } |
|
26 | + /** |
|
27 | + * @var ResourceStorage |
|
28 | + */ |
|
29 | + protected $storage = null; |
|
30 | + |
|
31 | + /** |
|
32 | + * @param ResourceStorage $storage |
|
33 | + */ |
|
34 | + public function __construct(ResourceStorage $storage) |
|
35 | + { |
|
36 | + $this->storage = $storage; |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * @param File $file |
|
41 | + * @return $this |
|
42 | + */ |
|
43 | + public function updateIndex(File $file) |
|
44 | + { |
|
45 | + $this->getCoreIndexer()->updateIndexEntry($file); |
|
46 | + return $this; |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * @param File $file |
|
51 | + * @return $this |
|
52 | + */ |
|
53 | + public function extractMetadata(File $file) |
|
54 | + { |
|
55 | + $extractionServices = $this->getExtractorRegistry()->getExtractorsWithDriverSupport($this->storage->getDriverType()); |
|
56 | + |
|
57 | + $newMetaData = array( |
|
58 | + 0 => $file->getMetaData()->get() |
|
59 | + ); |
|
60 | + |
|
61 | + foreach ($extractionServices as $services) { |
|
62 | + if (is_array($services)) { |
|
63 | + foreach ($services as $service) { |
|
64 | + if ($service->canProcess($file)) { |
|
65 | + $newMetaData[$service->getPriority()] = $service->extractMetaData($file, $newMetaData); |
|
66 | + } |
|
67 | + } |
|
68 | + } else { |
|
69 | + $service = $services; |
|
70 | + // We could optimise here for not repeating this bit |
|
71 | + if ($service->canProcess($file)) { |
|
72 | + $newMetaData[$service->getPriority()] = $service->extractMetaData($file, $newMetaData); |
|
73 | + } |
|
74 | + } |
|
75 | + } |
|
76 | + |
|
77 | + ksort($newMetaData); |
|
78 | + $metaData = []; |
|
79 | + foreach ($newMetaData as $data) { |
|
80 | + $metaData = array_merge($metaData, $data); |
|
81 | + } |
|
82 | + $file->updateProperties($metaData); |
|
83 | + $this->getMetaDataRepository()->update($file->getUid(), $metaData); |
|
84 | + $this->getFileIndexRepository()->updateIndexingTime($file->getUid()); |
|
85 | + |
|
86 | + return $this; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * @param File $file |
|
91 | + * @return $this |
|
92 | + */ |
|
93 | + public function applyDefaultCategories(File $file) |
|
94 | + { |
|
95 | + $categoryList = ConfigurationUtility::getInstance()->get('default_categories'); |
|
96 | + $categories = GeneralUtility::trimExplode(',', $categoryList, true); |
|
97 | + |
|
98 | + foreach ($categories as $category) { |
|
99 | + $values = array( |
|
100 | + 'uid_local' => $category, |
|
101 | + 'uid_foreign' => $this->getFileMetadataIdentifier($file), |
|
102 | + 'tablenames' => 'sys_file_metadata', |
|
103 | + 'fieldname' => 'categories', |
|
104 | + ); |
|
105 | + $this->getDataService()->insert('sys_category_record_mm', $values); |
|
106 | + } |
|
107 | + |
|
108 | + $metaData['categories'] = count($categories); |
|
109 | + $file->updateProperties($metaData); |
|
110 | + $this->getMetaDataRepository()->update($file->getUid(), $metaData); |
|
111 | + $this->getFileIndexRepository()->updateIndexingTime($file->getUid()); |
|
112 | + return $this; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Retrieve the file metadata uid which is different from the file uid. |
|
117 | + * |
|
118 | + * @param File $file |
|
119 | + * @return int |
|
120 | + */ |
|
121 | + protected function getFileMetadataIdentifier(File $file) |
|
122 | + { |
|
123 | + $metadataProperties = $file->getMetaData()->get(); |
|
124 | + return isset($metadataProperties['_ORIG_uid']) ? (int)$metadataProperties['_ORIG_uid'] : (int)$metadataProperties['uid']; |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * Returns an instance of the FileIndexRepository |
|
130 | + * |
|
131 | + * @return FileIndexRepository |
|
132 | + */ |
|
133 | + protected function getFileIndexRepository() |
|
134 | + { |
|
135 | + return GeneralUtility::makeInstance(FileIndexRepository::class); |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Returns an instance of the FileIndexRepository |
|
140 | + * |
|
141 | + * @return MetaDataRepository |
|
142 | + */ |
|
143 | + protected function getMetaDataRepository() |
|
144 | + { |
|
145 | + return GeneralUtility::makeInstance(MetaDataRepository::class); |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * Returns an instance of the FileIndexRepository |
|
150 | + * |
|
151 | + * @return ExtractorRegistry |
|
152 | + */ |
|
153 | + protected function getExtractorRegistry() |
|
154 | + { |
|
155 | + return GeneralUtility::makeInstance(ExtractorRegistry::class); |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * @return object|DataService |
|
160 | + */ |
|
161 | + protected function getDataService(): DataService |
|
162 | + { |
|
163 | + return GeneralUtility::makeInstance(DataService::class); |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * @return Indexer|object |
|
168 | + */ |
|
169 | + protected function getCoreIndexer() |
|
170 | + { |
|
171 | + return GeneralUtility::makeInstance(Indexer::class, $this->storage); |
|
172 | + } |
|
173 | 173 | } |
@@ -22,170 +22,170 @@ |
||
22 | 22 | */ |
23 | 23 | class IndexAnalyser implements SingletonInterface |
24 | 24 | { |
25 | - /** |
|
26 | - * Return missing file for a given storage. |
|
27 | - * |
|
28 | - * @param ResourceStorage $storage |
|
29 | - * @return array |
|
30 | - */ |
|
31 | - public function searchForMissingFiles(ResourceStorage $storage) |
|
32 | - { |
|
33 | - /** @var ConnectionPool $connectionPool */ |
|
34 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
35 | - $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file'); |
|
36 | - |
|
37 | - $missingFiles = []; |
|
38 | - $statement = $queryBuilder |
|
39 | - ->select('*') |
|
40 | - ->from('sys_file') |
|
41 | - ->where( |
|
42 | - $queryBuilder->expr()->eq('storage', $storage->getUid()) |
|
43 | - )->execute(); |
|
44 | - while ($row = $statement->fetchAssociative()) { |
|
45 | - // This task is very memory consuming on large data set e.g > 20'000 records. |
|
46 | - // We must think of having a pagination if there is the need for such thing. |
|
47 | - $file = $this->getResourceFactory()->getFileObject($row['uid'], $row); |
|
48 | - if (!$file->exists()) { |
|
49 | - $missingFiles[] = $file; |
|
50 | - } |
|
51 | - } |
|
52 | - return $missingFiles; |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * Deletes all missing files for a given storage. |
|
57 | - * |
|
58 | - * @param ResourceStorage $storage |
|
59 | - * @return array |
|
60 | - * @throws \InvalidArgumentException |
|
61 | - */ |
|
62 | - public function deleteMissingFiles(ResourceStorage $storage) |
|
63 | - { |
|
64 | - /** @var FileReferenceService $fileReferenceService */ |
|
65 | - $fileReferenceService = GeneralUtility::makeInstance(FileReferenceService::class); |
|
66 | - $missingFiles = $this->searchForMissingFiles($storage); |
|
67 | - $deletedFiles = []; |
|
68 | - |
|
69 | - /** @var ConnectionPool $connectionPool */ |
|
70 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
71 | - |
|
72 | - /** @var File $missingFile */ |
|
73 | - foreach ($missingFiles as $missingFile) { |
|
74 | - try { |
|
75 | - // if missingFile has no file references |
|
76 | - if ($missingFile && count($fileReferenceService->findFileReferences($missingFile)) === 0) { |
|
77 | - // The case is special as we have a missing file in the file system |
|
78 | - // As a result, we can't use $fileObject->delete(); which will |
|
79 | - // raise exception "Error while fetching permissions" |
|
80 | - $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file'); |
|
81 | - $queryBuilder->delete('sys_file') |
|
82 | - ->where($queryBuilder->expr()->eq('uid', $missingFile->getUid())) |
|
83 | - ->execute(); |
|
84 | - |
|
85 | - $deletedFiles[$missingFile->getUid()] = $missingFile->getIdentifier(); |
|
86 | - } |
|
87 | - } catch (\Exception $e) { |
|
88 | - continue; |
|
89 | - } |
|
90 | - } |
|
91 | - return $deletedFiles; |
|
92 | - } |
|
93 | - |
|
94 | - /* |
|
25 | + /** |
|
26 | + * Return missing file for a given storage. |
|
27 | + * |
|
28 | + * @param ResourceStorage $storage |
|
29 | + * @return array |
|
30 | + */ |
|
31 | + public function searchForMissingFiles(ResourceStorage $storage) |
|
32 | + { |
|
33 | + /** @var ConnectionPool $connectionPool */ |
|
34 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
35 | + $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file'); |
|
36 | + |
|
37 | + $missingFiles = []; |
|
38 | + $statement = $queryBuilder |
|
39 | + ->select('*') |
|
40 | + ->from('sys_file') |
|
41 | + ->where( |
|
42 | + $queryBuilder->expr()->eq('storage', $storage->getUid()) |
|
43 | + )->execute(); |
|
44 | + while ($row = $statement->fetchAssociative()) { |
|
45 | + // This task is very memory consuming on large data set e.g > 20'000 records. |
|
46 | + // We must think of having a pagination if there is the need for such thing. |
|
47 | + $file = $this->getResourceFactory()->getFileObject($row['uid'], $row); |
|
48 | + if (!$file->exists()) { |
|
49 | + $missingFiles[] = $file; |
|
50 | + } |
|
51 | + } |
|
52 | + return $missingFiles; |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * Deletes all missing files for a given storage. |
|
57 | + * |
|
58 | + * @param ResourceStorage $storage |
|
59 | + * @return array |
|
60 | + * @throws \InvalidArgumentException |
|
61 | + */ |
|
62 | + public function deleteMissingFiles(ResourceStorage $storage) |
|
63 | + { |
|
64 | + /** @var FileReferenceService $fileReferenceService */ |
|
65 | + $fileReferenceService = GeneralUtility::makeInstance(FileReferenceService::class); |
|
66 | + $missingFiles = $this->searchForMissingFiles($storage); |
|
67 | + $deletedFiles = []; |
|
68 | + |
|
69 | + /** @var ConnectionPool $connectionPool */ |
|
70 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
71 | + |
|
72 | + /** @var File $missingFile */ |
|
73 | + foreach ($missingFiles as $missingFile) { |
|
74 | + try { |
|
75 | + // if missingFile has no file references |
|
76 | + if ($missingFile && count($fileReferenceService->findFileReferences($missingFile)) === 0) { |
|
77 | + // The case is special as we have a missing file in the file system |
|
78 | + // As a result, we can't use $fileObject->delete(); which will |
|
79 | + // raise exception "Error while fetching permissions" |
|
80 | + $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file'); |
|
81 | + $queryBuilder->delete('sys_file') |
|
82 | + ->where($queryBuilder->expr()->eq('uid', $missingFile->getUid())) |
|
83 | + ->execute(); |
|
84 | + |
|
85 | + $deletedFiles[$missingFile->getUid()] = $missingFile->getIdentifier(); |
|
86 | + } |
|
87 | + } catch (\Exception $e) { |
|
88 | + continue; |
|
89 | + } |
|
90 | + } |
|
91 | + return $deletedFiles; |
|
92 | + } |
|
93 | + |
|
94 | + /* |
|
95 | 95 | * Return duplicates file records |
96 | 96 | * |
97 | 97 | * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage |
98 | 98 | * @return array |
99 | 99 | */ |
100 | - public function searchForDuplicateIdentifiers(ResourceStorage $storage) |
|
101 | - { |
|
102 | - /** @var ConnectionPool $connectionPool */ |
|
103 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
104 | - $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file'); |
|
105 | - |
|
106 | - $statement = $queryBuilder |
|
107 | - ->select('*') |
|
108 | - ->from('sys_file') |
|
109 | - ->where( |
|
110 | - $queryBuilder->expr()->eq('storage', $storage->getUid()) |
|
111 | - ) |
|
112 | - ->groupby('identifier') |
|
113 | - ->having('count(*) > 1') |
|
114 | - ->execute(); |
|
115 | - |
|
116 | - // Detect duplicate records. |
|
117 | - $duplicates = []; |
|
118 | - while ($row = $statement->fetchAssociative()) { |
|
119 | - $records = $queryBuilder |
|
120 | - ->select('*') |
|
121 | - ->from('sys_file') |
|
122 | - ->where( |
|
123 | - $queryBuilder->expr()->eq('storage', $storage->getUid()) |
|
124 | - ) |
|
125 | - ->andWhere( |
|
126 | - $queryBuilder->expr()->eq('identifier', $queryBuilder->createNamedParameter($row['identifier'])) |
|
127 | - ) |
|
128 | - ->execute(); |
|
129 | - $records = $records->fetchAllAssociative(); |
|
130 | - $duplicates[$row['identifier']] = $records; |
|
131 | - } |
|
132 | - return $duplicates; |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Return duplicates file records |
|
137 | - * |
|
138 | - * @param ResourceStorage $storage |
|
139 | - * @return array |
|
140 | - */ |
|
141 | - public function searchForDuplicateSha1(ResourceStorage $storage) |
|
142 | - { |
|
143 | - /** @var ConnectionPool $connectionPool */ |
|
144 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
145 | - $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file'); |
|
146 | - |
|
147 | - $statement = $queryBuilder |
|
148 | - ->select('*') |
|
149 | - ->from('sys_file') |
|
150 | - ->where( |
|
151 | - $queryBuilder->expr()->eq('storage', $storage->getUid()) |
|
152 | - ) |
|
153 | - ->groupby('sha1') |
|
154 | - ->having('count(*) > 1') |
|
155 | - ->execute(); |
|
156 | - |
|
157 | - // Detect duplicate records. |
|
158 | - $duplicates = []; |
|
159 | - while ($row = $statement->fetchAssociative()) { |
|
160 | - $records = $queryBuilder |
|
161 | - ->select('*') |
|
162 | - ->from('sys_file') |
|
163 | - ->where( |
|
164 | - $queryBuilder->expr()->eq('storage', $storage->getUid()) |
|
165 | - ) |
|
166 | - ->andWhere( |
|
167 | - $queryBuilder->expr()->eq('identifier', $queryBuilder->createNamedParameter($row['sha1'])) |
|
168 | - ) |
|
169 | - ->execute(); |
|
170 | - $records = $records->fetchAllAssociative(); |
|
171 | - $duplicates[$row['sha1']] = $records; |
|
172 | - } |
|
173 | - return $duplicates; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * @param string $tableName |
|
178 | - * @return object|QueryBuilder |
|
179 | - */ |
|
180 | - protected function getQueryBuilder($tableName): QueryBuilder |
|
181 | - { |
|
182 | - /** @var ConnectionPool $connectionPool */ |
|
183 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
184 | - return $connectionPool->getQueryBuilderForTable($tableName); |
|
185 | - } |
|
186 | - |
|
187 | - protected function getResourceFactory(): ResourceFactory |
|
188 | - { |
|
189 | - return GeneralUtility::makeInstance(ResourceFactory::class); |
|
190 | - } |
|
100 | + public function searchForDuplicateIdentifiers(ResourceStorage $storage) |
|
101 | + { |
|
102 | + /** @var ConnectionPool $connectionPool */ |
|
103 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
104 | + $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file'); |
|
105 | + |
|
106 | + $statement = $queryBuilder |
|
107 | + ->select('*') |
|
108 | + ->from('sys_file') |
|
109 | + ->where( |
|
110 | + $queryBuilder->expr()->eq('storage', $storage->getUid()) |
|
111 | + ) |
|
112 | + ->groupby('identifier') |
|
113 | + ->having('count(*) > 1') |
|
114 | + ->execute(); |
|
115 | + |
|
116 | + // Detect duplicate records. |
|
117 | + $duplicates = []; |
|
118 | + while ($row = $statement->fetchAssociative()) { |
|
119 | + $records = $queryBuilder |
|
120 | + ->select('*') |
|
121 | + ->from('sys_file') |
|
122 | + ->where( |
|
123 | + $queryBuilder->expr()->eq('storage', $storage->getUid()) |
|
124 | + ) |
|
125 | + ->andWhere( |
|
126 | + $queryBuilder->expr()->eq('identifier', $queryBuilder->createNamedParameter($row['identifier'])) |
|
127 | + ) |
|
128 | + ->execute(); |
|
129 | + $records = $records->fetchAllAssociative(); |
|
130 | + $duplicates[$row['identifier']] = $records; |
|
131 | + } |
|
132 | + return $duplicates; |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Return duplicates file records |
|
137 | + * |
|
138 | + * @param ResourceStorage $storage |
|
139 | + * @return array |
|
140 | + */ |
|
141 | + public function searchForDuplicateSha1(ResourceStorage $storage) |
|
142 | + { |
|
143 | + /** @var ConnectionPool $connectionPool */ |
|
144 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
145 | + $queryBuilder = $connectionPool->getQueryBuilderForTable('sys_file'); |
|
146 | + |
|
147 | + $statement = $queryBuilder |
|
148 | + ->select('*') |
|
149 | + ->from('sys_file') |
|
150 | + ->where( |
|
151 | + $queryBuilder->expr()->eq('storage', $storage->getUid()) |
|
152 | + ) |
|
153 | + ->groupby('sha1') |
|
154 | + ->having('count(*) > 1') |
|
155 | + ->execute(); |
|
156 | + |
|
157 | + // Detect duplicate records. |
|
158 | + $duplicates = []; |
|
159 | + while ($row = $statement->fetchAssociative()) { |
|
160 | + $records = $queryBuilder |
|
161 | + ->select('*') |
|
162 | + ->from('sys_file') |
|
163 | + ->where( |
|
164 | + $queryBuilder->expr()->eq('storage', $storage->getUid()) |
|
165 | + ) |
|
166 | + ->andWhere( |
|
167 | + $queryBuilder->expr()->eq('identifier', $queryBuilder->createNamedParameter($row['sha1'])) |
|
168 | + ) |
|
169 | + ->execute(); |
|
170 | + $records = $records->fetchAllAssociative(); |
|
171 | + $duplicates[$row['sha1']] = $records; |
|
172 | + } |
|
173 | + return $duplicates; |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * @param string $tableName |
|
178 | + * @return object|QueryBuilder |
|
179 | + */ |
|
180 | + protected function getQueryBuilder($tableName): QueryBuilder |
|
181 | + { |
|
182 | + /** @var ConnectionPool $connectionPool */ |
|
183 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
184 | + return $connectionPool->getQueryBuilderForTable($tableName); |
|
185 | + } |
|
186 | + |
|
187 | + protected function getResourceFactory(): ResourceFactory |
|
188 | + { |
|
189 | + return GeneralUtility::makeInstance(ResourceFactory::class); |
|
190 | + } |
|
191 | 191 | } |
@@ -20,124 +20,124 @@ |
||
20 | 20 | */ |
21 | 21 | class TitleMetadataExtractor implements ExtractorInterface |
22 | 22 | { |
23 | - /** |
|
24 | - * Returns an array of supported file types; |
|
25 | - * An empty array indicates all filetypes |
|
26 | - * |
|
27 | - * @return array |
|
28 | - */ |
|
29 | - public function getFileTypeRestrictions() |
|
30 | - { |
|
31 | - return []; |
|
32 | - } |
|
23 | + /** |
|
24 | + * Returns an array of supported file types; |
|
25 | + * An empty array indicates all filetypes |
|
26 | + * |
|
27 | + * @return array |
|
28 | + */ |
|
29 | + public function getFileTypeRestrictions() |
|
30 | + { |
|
31 | + return []; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Get all supported DriverClasses |
|
36 | - * Since some extractors may only work for local files, and other extractors |
|
37 | - * are especially made for grabbing data from remote. |
|
38 | - * Returns array of string with driver names of Drivers which are supported, |
|
39 | - * If the driver did not register a name, it's the classname. |
|
40 | - * empty array indicates no restrictions |
|
41 | - * |
|
42 | - * @return array |
|
43 | - */ |
|
44 | - public function getDriverRestrictions() |
|
45 | - { |
|
46 | - return []; |
|
47 | - } |
|
34 | + /** |
|
35 | + * Get all supported DriverClasses |
|
36 | + * Since some extractors may only work for local files, and other extractors |
|
37 | + * are especially made for grabbing data from remote. |
|
38 | + * Returns array of string with driver names of Drivers which are supported, |
|
39 | + * If the driver did not register a name, it's the classname. |
|
40 | + * empty array indicates no restrictions |
|
41 | + * |
|
42 | + * @return array |
|
43 | + */ |
|
44 | + public function getDriverRestrictions() |
|
45 | + { |
|
46 | + return []; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Returns the data priority of the extraction Service. |
|
51 | - * Defines the precedence of Data if several extractors |
|
52 | - * extracted the same property. |
|
53 | - * Should be between 1 and 100, 100 is more important than 1 |
|
54 | - * |
|
55 | - * @return integer |
|
56 | - */ |
|
57 | - public function getPriority() |
|
58 | - { |
|
59 | - return 15; |
|
60 | - } |
|
49 | + /** |
|
50 | + * Returns the data priority of the extraction Service. |
|
51 | + * Defines the precedence of Data if several extractors |
|
52 | + * extracted the same property. |
|
53 | + * Should be between 1 and 100, 100 is more important than 1 |
|
54 | + * |
|
55 | + * @return integer |
|
56 | + */ |
|
57 | + public function getPriority() |
|
58 | + { |
|
59 | + return 15; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Returns the execution priority of the extraction Service |
|
64 | - * Should be between 1 and 100, 100 means runs as first service, 1 runs at last service |
|
65 | - * |
|
66 | - * @return integer |
|
67 | - */ |
|
68 | - public function getExecutionPriority() |
|
69 | - { |
|
70 | - return 15; |
|
71 | - } |
|
62 | + /** |
|
63 | + * Returns the execution priority of the extraction Service |
|
64 | + * Should be between 1 and 100, 100 means runs as first service, 1 runs at last service |
|
65 | + * |
|
66 | + * @return integer |
|
67 | + */ |
|
68 | + public function getExecutionPriority() |
|
69 | + { |
|
70 | + return 15; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Checks if the given file can be processed by this Extractor |
|
75 | - * |
|
76 | - * @param File $file |
|
77 | - * @return boolean |
|
78 | - */ |
|
79 | - public function canProcess(File $file) |
|
80 | - { |
|
81 | - return true; |
|
82 | - } |
|
73 | + /** |
|
74 | + * Checks if the given file can be processed by this Extractor |
|
75 | + * |
|
76 | + * @param File $file |
|
77 | + * @return boolean |
|
78 | + */ |
|
79 | + public function canProcess(File $file) |
|
80 | + { |
|
81 | + return true; |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * The actual processing TASK |
|
86 | - * Should return an array with database properties for sys_file_metadata to write |
|
87 | - * |
|
88 | - * @param File $file |
|
89 | - * @param array $previousExtractedData optional, contains the array of already extracted data |
|
90 | - * @return array |
|
91 | - */ |
|
92 | - public function extractMetaData(File $file, array $previousExtractedData = []) |
|
93 | - { |
|
94 | - $metadata = []; |
|
95 | - $title = $file->getProperty('title'); |
|
96 | - if (empty($title)) { |
|
97 | - $metadata = array('title' => $this->guessTitle($file->getName())); |
|
98 | - } |
|
99 | - return $metadata; |
|
100 | - } |
|
84 | + /** |
|
85 | + * The actual processing TASK |
|
86 | + * Should return an array with database properties for sys_file_metadata to write |
|
87 | + * |
|
88 | + * @param File $file |
|
89 | + * @param array $previousExtractedData optional, contains the array of already extracted data |
|
90 | + * @return array |
|
91 | + */ |
|
92 | + public function extractMetaData(File $file, array $previousExtractedData = []) |
|
93 | + { |
|
94 | + $metadata = []; |
|
95 | + $title = $file->getProperty('title'); |
|
96 | + if (empty($title)) { |
|
97 | + $metadata = array('title' => $this->guessTitle($file->getName())); |
|
98 | + } |
|
99 | + return $metadata; |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * Guess a title given a file name. Examples: |
|
104 | - * name: my-file-name.jpg -> title: My file name |
|
105 | - * name: myFileName.jpg -> title: My file name |
|
106 | - * |
|
107 | - * @param string $fileName |
|
108 | - * @return string |
|
109 | - */ |
|
110 | - protected function guessTitle($fileName) |
|
111 | - { |
|
112 | - $fileNameWithoutExtension = $this->removeExtension($fileName); |
|
102 | + /** |
|
103 | + * Guess a title given a file name. Examples: |
|
104 | + * name: my-file-name.jpg -> title: My file name |
|
105 | + * name: myFileName.jpg -> title: My file name |
|
106 | + * |
|
107 | + * @param string $fileName |
|
108 | + * @return string |
|
109 | + */ |
|
110 | + protected function guessTitle($fileName) |
|
111 | + { |
|
112 | + $fileNameWithoutExtension = $this->removeExtension($fileName); |
|
113 | 113 | |
114 | - $title = $fileNameWithoutExtension; |
|
115 | - // first case: the name is separated by _ or - |
|
116 | - // second case: this is an upper camel case name |
|
117 | - if (preg_match('/-|_/is', $fileNameWithoutExtension)) { |
|
118 | - $title = preg_replace('/-|_/is', ' ', $fileNameWithoutExtension); |
|
119 | - } elseif (preg_match('/[A-Z]/', $fileNameWithoutExtension)) { |
|
120 | - $parts = preg_split('/(?=[A-Z])/', $fileNameWithoutExtension, -1, PREG_SPLIT_NO_EMPTY); |
|
121 | - $title = implode(' ', $parts); |
|
122 | - } |
|
114 | + $title = $fileNameWithoutExtension; |
|
115 | + // first case: the name is separated by _ or - |
|
116 | + // second case: this is an upper camel case name |
|
117 | + if (preg_match('/-|_/is', $fileNameWithoutExtension)) { |
|
118 | + $title = preg_replace('/-|_/is', ' ', $fileNameWithoutExtension); |
|
119 | + } elseif (preg_match('/[A-Z]/', $fileNameWithoutExtension)) { |
|
120 | + $parts = preg_split('/(?=[A-Z])/', $fileNameWithoutExtension, -1, PREG_SPLIT_NO_EMPTY); |
|
121 | + $title = implode(' ', $parts); |
|
122 | + } |
|
123 | 123 | |
124 | - // Remove double space. |
|
125 | - $title = preg_replace('/\s+/', ' ', $title); |
|
126 | - return ucfirst($title); |
|
127 | - } |
|
124 | + // Remove double space. |
|
125 | + $title = preg_replace('/\s+/', ' ', $title); |
|
126 | + return ucfirst($title); |
|
127 | + } |
|
128 | 128 | |
129 | - /** |
|
130 | - * Remove extension of a file. |
|
131 | - * |
|
132 | - * @param string $fileName |
|
133 | - * @return string |
|
134 | - */ |
|
135 | - protected function removeExtension($fileName) |
|
136 | - { |
|
137 | - $parts = explode('.', $fileName); |
|
138 | - if (!empty($parts)) { |
|
139 | - array_pop($parts); |
|
140 | - } |
|
141 | - return implode('.', $parts); |
|
142 | - } |
|
129 | + /** |
|
130 | + * Remove extension of a file. |
|
131 | + * |
|
132 | + * @param string $fileName |
|
133 | + * @return string |
|
134 | + */ |
|
135 | + protected function removeExtension($fileName) |
|
136 | + { |
|
137 | + $parts = explode('.', $fileName); |
|
138 | + if (!empty($parts)) { |
|
139 | + array_pop($parts); |
|
140 | + } |
|
141 | + return implode('.', $parts); |
|
142 | + } |
|
143 | 143 | } |
@@ -18,268 +18,268 @@ |
||
18 | 18 | */ |
19 | 19 | abstract class AbstractFormField implements FormFieldInterface |
20 | 20 | { |
21 | - /** |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $template = ''; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - protected $value = ''; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - protected $name = ''; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - protected $id = ''; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var string |
|
43 | - */ |
|
44 | - protected $prefix = ''; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - protected $label = ''; |
|
50 | - |
|
51 | - /** |
|
52 | - * Store what child element will contain this element. |
|
53 | - * |
|
54 | - * @var array |
|
55 | - */ |
|
56 | - protected $items = []; |
|
57 | - |
|
58 | - /** |
|
59 | - * Attributes in sense of DOM attribute, e.g. class, style, etc... |
|
60 | - * |
|
61 | - * @var array |
|
62 | - */ |
|
63 | - protected $attributes = []; |
|
64 | - |
|
65 | - /** |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - public function render() |
|
69 | - { |
|
70 | - return $this->template; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Render the label if possible. Otherwise return an empty string. |
|
75 | - * |
|
76 | - * @return string |
|
77 | - */ |
|
78 | - public function renderLabel() |
|
79 | - { |
|
80 | - $result = ''; |
|
81 | - if ($this->label) { |
|
82 | - $template = '<label class="control-label" for="%s">%s</label>'; |
|
83 | - |
|
84 | - if (strpos($this->label, 'LLL:') === 0) { |
|
85 | - $this->label = LocalizationUtility::translate($this->label, ''); |
|
86 | - } |
|
87 | - |
|
88 | - $result = sprintf( |
|
89 | - $template, |
|
90 | - $this->getId(), |
|
91 | - $this->label |
|
92 | - ); |
|
93 | - } |
|
94 | - return $result; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Render additional attribute for this DOM element. |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - public function renderAttributes() |
|
103 | - { |
|
104 | - $result = ''; |
|
105 | - if (!empty($this->attributes)) { |
|
106 | - foreach ($this->attributes as $attribute => $value) { |
|
107 | - $result .= sprintf( |
|
108 | - '%s="%s" ', |
|
109 | - htmlspecialchars($attribute), |
|
110 | - htmlspecialchars($value) |
|
111 | - ); |
|
112 | - } |
|
113 | - } |
|
114 | - return $result; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Add an additional (DOM) attribute to be added to this template. |
|
119 | - * |
|
120 | - * @throws InvalidStringException |
|
121 | - * @param array $attribute associative array that contains attribute => value |
|
122 | - * @return \Fab\Media\Form\AbstractFormField |
|
123 | - */ |
|
124 | - public function addAttribute(array $attribute) |
|
125 | - { |
|
126 | - if (!empty($attribute)) { |
|
127 | - reset($attribute); |
|
128 | - $key = key($attribute); |
|
129 | - if (!is_string($key)) { |
|
130 | - throw new InvalidStringException('Not an associative array. Is not a key: ' . $key, 1356478742); |
|
131 | - } |
|
132 | - |
|
133 | - $this->attributes[$key] = $attribute[$key]; |
|
134 | - } |
|
135 | - return $this; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * @return string |
|
140 | - */ |
|
141 | - public function getTemplate() |
|
142 | - { |
|
143 | - return $this->template; |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * @param string $template |
|
148 | - * @return \Fab\Media\Form\AbstractFormField |
|
149 | - */ |
|
150 | - public function setTemplate($template) |
|
151 | - { |
|
152 | - $this->template = $template; |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * @return string |
|
157 | - */ |
|
158 | - public function getLabel() |
|
159 | - { |
|
160 | - return $this->label; |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * @param string $label |
|
165 | - * @return \Fab\Media\Form\AbstractFormField |
|
166 | - */ |
|
167 | - public function setLabel($label) |
|
168 | - { |
|
169 | - $this->label = $label; |
|
170 | - return $this; |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * @return string |
|
175 | - */ |
|
176 | - public function getPrefix() |
|
177 | - { |
|
178 | - return $this->prefix; |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * @param string $prefix |
|
183 | - * @return \Fab\Media\Form\AbstractFormField |
|
184 | - */ |
|
185 | - public function setPrefix($prefix) |
|
186 | - { |
|
187 | - $this->prefix = $prefix; |
|
188 | - return $this; |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * @return array |
|
193 | - */ |
|
194 | - public function getItems() |
|
195 | - { |
|
196 | - return $this->items; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * @param array $items |
|
201 | - */ |
|
202 | - public function setItems($items) |
|
203 | - { |
|
204 | - $this->items = $items; |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * @return string |
|
209 | - */ |
|
210 | - public function getValue() |
|
211 | - { |
|
212 | - return htmlspecialchars($this->value); |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * @param string $value |
|
217 | - * @return \Fab\Media\Form\AbstractFormField |
|
218 | - */ |
|
219 | - public function setValue($value) |
|
220 | - { |
|
221 | - $this->value = $value; |
|
222 | - return $this; |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * @return string |
|
227 | - */ |
|
228 | - public function getName() |
|
229 | - { |
|
230 | - $result = $this->name; |
|
231 | - if ($this->getPrefix()) { |
|
232 | - $result = sprintf('%s[%s]', $this->getPrefix(), $this->name); |
|
233 | - } |
|
234 | - return $result; |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * @param string $name |
|
239 | - * @return \Fab\Media\Form\AbstractFormField |
|
240 | - */ |
|
241 | - public function setName($name) |
|
242 | - { |
|
243 | - $this->name = $name; |
|
244 | - return $this; |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * @return string |
|
249 | - */ |
|
250 | - public function getId() |
|
251 | - { |
|
252 | - if ($this->id === '') { |
|
253 | - $this->id = DomElement::getInstance()->formatId($this->getName()); |
|
254 | - } |
|
255 | - return $this->id; |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * @param string $id |
|
260 | - * @return \Fab\Media\Form\AbstractFormField |
|
261 | - */ |
|
262 | - public function setId($id) |
|
263 | - { |
|
264 | - $this->id = $id; |
|
265 | - return $this; |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * @return array |
|
270 | - */ |
|
271 | - public function getAttributes() |
|
272 | - { |
|
273 | - return $this->attributes; |
|
274 | - } |
|
275 | - |
|
276 | - /** |
|
277 | - * @param array $attributes |
|
278 | - * @return \Fab\Media\Form\AbstractFormField |
|
279 | - */ |
|
280 | - public function setAttributes($attributes) |
|
281 | - { |
|
282 | - $this->attributes = $attributes; |
|
283 | - return $this; |
|
284 | - } |
|
21 | + /** |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $template = ''; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + protected $value = ''; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + protected $name = ''; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + protected $id = ''; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var string |
|
43 | + */ |
|
44 | + protected $prefix = ''; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + protected $label = ''; |
|
50 | + |
|
51 | + /** |
|
52 | + * Store what child element will contain this element. |
|
53 | + * |
|
54 | + * @var array |
|
55 | + */ |
|
56 | + protected $items = []; |
|
57 | + |
|
58 | + /** |
|
59 | + * Attributes in sense of DOM attribute, e.g. class, style, etc... |
|
60 | + * |
|
61 | + * @var array |
|
62 | + */ |
|
63 | + protected $attributes = []; |
|
64 | + |
|
65 | + /** |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + public function render() |
|
69 | + { |
|
70 | + return $this->template; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Render the label if possible. Otherwise return an empty string. |
|
75 | + * |
|
76 | + * @return string |
|
77 | + */ |
|
78 | + public function renderLabel() |
|
79 | + { |
|
80 | + $result = ''; |
|
81 | + if ($this->label) { |
|
82 | + $template = '<label class="control-label" for="%s">%s</label>'; |
|
83 | + |
|
84 | + if (strpos($this->label, 'LLL:') === 0) { |
|
85 | + $this->label = LocalizationUtility::translate($this->label, ''); |
|
86 | + } |
|
87 | + |
|
88 | + $result = sprintf( |
|
89 | + $template, |
|
90 | + $this->getId(), |
|
91 | + $this->label |
|
92 | + ); |
|
93 | + } |
|
94 | + return $result; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Render additional attribute for this DOM element. |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + public function renderAttributes() |
|
103 | + { |
|
104 | + $result = ''; |
|
105 | + if (!empty($this->attributes)) { |
|
106 | + foreach ($this->attributes as $attribute => $value) { |
|
107 | + $result .= sprintf( |
|
108 | + '%s="%s" ', |
|
109 | + htmlspecialchars($attribute), |
|
110 | + htmlspecialchars($value) |
|
111 | + ); |
|
112 | + } |
|
113 | + } |
|
114 | + return $result; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Add an additional (DOM) attribute to be added to this template. |
|
119 | + * |
|
120 | + * @throws InvalidStringException |
|
121 | + * @param array $attribute associative array that contains attribute => value |
|
122 | + * @return \Fab\Media\Form\AbstractFormField |
|
123 | + */ |
|
124 | + public function addAttribute(array $attribute) |
|
125 | + { |
|
126 | + if (!empty($attribute)) { |
|
127 | + reset($attribute); |
|
128 | + $key = key($attribute); |
|
129 | + if (!is_string($key)) { |
|
130 | + throw new InvalidStringException('Not an associative array. Is not a key: ' . $key, 1356478742); |
|
131 | + } |
|
132 | + |
|
133 | + $this->attributes[$key] = $attribute[$key]; |
|
134 | + } |
|
135 | + return $this; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * @return string |
|
140 | + */ |
|
141 | + public function getTemplate() |
|
142 | + { |
|
143 | + return $this->template; |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * @param string $template |
|
148 | + * @return \Fab\Media\Form\AbstractFormField |
|
149 | + */ |
|
150 | + public function setTemplate($template) |
|
151 | + { |
|
152 | + $this->template = $template; |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * @return string |
|
157 | + */ |
|
158 | + public function getLabel() |
|
159 | + { |
|
160 | + return $this->label; |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * @param string $label |
|
165 | + * @return \Fab\Media\Form\AbstractFormField |
|
166 | + */ |
|
167 | + public function setLabel($label) |
|
168 | + { |
|
169 | + $this->label = $label; |
|
170 | + return $this; |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * @return string |
|
175 | + */ |
|
176 | + public function getPrefix() |
|
177 | + { |
|
178 | + return $this->prefix; |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * @param string $prefix |
|
183 | + * @return \Fab\Media\Form\AbstractFormField |
|
184 | + */ |
|
185 | + public function setPrefix($prefix) |
|
186 | + { |
|
187 | + $this->prefix = $prefix; |
|
188 | + return $this; |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * @return array |
|
193 | + */ |
|
194 | + public function getItems() |
|
195 | + { |
|
196 | + return $this->items; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * @param array $items |
|
201 | + */ |
|
202 | + public function setItems($items) |
|
203 | + { |
|
204 | + $this->items = $items; |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * @return string |
|
209 | + */ |
|
210 | + public function getValue() |
|
211 | + { |
|
212 | + return htmlspecialchars($this->value); |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * @param string $value |
|
217 | + * @return \Fab\Media\Form\AbstractFormField |
|
218 | + */ |
|
219 | + public function setValue($value) |
|
220 | + { |
|
221 | + $this->value = $value; |
|
222 | + return $this; |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * @return string |
|
227 | + */ |
|
228 | + public function getName() |
|
229 | + { |
|
230 | + $result = $this->name; |
|
231 | + if ($this->getPrefix()) { |
|
232 | + $result = sprintf('%s[%s]', $this->getPrefix(), $this->name); |
|
233 | + } |
|
234 | + return $result; |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * @param string $name |
|
239 | + * @return \Fab\Media\Form\AbstractFormField |
|
240 | + */ |
|
241 | + public function setName($name) |
|
242 | + { |
|
243 | + $this->name = $name; |
|
244 | + return $this; |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * @return string |
|
249 | + */ |
|
250 | + public function getId() |
|
251 | + { |
|
252 | + if ($this->id === '') { |
|
253 | + $this->id = DomElement::getInstance()->formatId($this->getName()); |
|
254 | + } |
|
255 | + return $this->id; |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * @param string $id |
|
260 | + * @return \Fab\Media\Form\AbstractFormField |
|
261 | + */ |
|
262 | + public function setId($id) |
|
263 | + { |
|
264 | + $this->id = $id; |
|
265 | + return $this; |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * @return array |
|
270 | + */ |
|
271 | + public function getAttributes() |
|
272 | + { |
|
273 | + return $this->attributes; |
|
274 | + } |
|
275 | + |
|
276 | + /** |
|
277 | + * @param array $attributes |
|
278 | + * @return \Fab\Media\Form\AbstractFormField |
|
279 | + */ |
|
280 | + public function setAttributes($attributes) |
|
281 | + { |
|
282 | + $this->attributes = $attributes; |
|
283 | + return $this; |
|
284 | + } |
|
285 | 285 | } |
@@ -20,65 +20,65 @@ |
||
20 | 20 | */ |
21 | 21 | class FileUploadTceForms extends FileUpload |
22 | 22 | { |
23 | - /** |
|
24 | - * @var string |
|
25 | - */ |
|
26 | - protected $templateFile = 'Resources/Private/Standalone/FileUploadTceFormsTemplate.html'; |
|
23 | + /** |
|
24 | + * @var string |
|
25 | + */ |
|
26 | + protected $templateFile = 'Resources/Private/Standalone/FileUploadTceFormsTemplate.html'; |
|
27 | 27 | |
28 | - /** |
|
29 | - * Fetch the JavaScript to be rendered and replace the markers with "live" variables. |
|
30 | - * |
|
31 | - * @return string |
|
32 | - */ |
|
33 | - protected function getJavaScript() |
|
34 | - { |
|
35 | - // Get the base prefix. |
|
36 | - $basePrefix = $this->getBasePrefix($this->getPrefix()); |
|
37 | - $filePath = ExtensionManagementUtility::extPath('media') . 'Resources/Private/Standalone/FileUploadTceForms.js'; |
|
28 | + /** |
|
29 | + * Fetch the JavaScript to be rendered and replace the markers with "live" variables. |
|
30 | + * |
|
31 | + * @return string |
|
32 | + */ |
|
33 | + protected function getJavaScript() |
|
34 | + { |
|
35 | + // Get the base prefix. |
|
36 | + $basePrefix = $this->getBasePrefix($this->getPrefix()); |
|
37 | + $filePath = ExtensionManagementUtility::extPath('media') . 'Resources/Private/Standalone/FileUploadTceForms.js'; |
|
38 | 38 | |
39 | - return sprintf( |
|
40 | - file_get_contents($filePath), |
|
41 | - $basePrefix, |
|
42 | - $this->elementId, |
|
43 | - $this->getModuleUrl(), |
|
44 | - $this->getAllowedExtension(), |
|
45 | - GeneralUtility::getMaxUploadFileSize() * 1024, |
|
46 | - $this->getValue() |
|
47 | - ); |
|
48 | - } |
|
39 | + return sprintf( |
|
40 | + file_get_contents($filePath), |
|
41 | + $basePrefix, |
|
42 | + $this->elementId, |
|
43 | + $this->getModuleUrl(), |
|
44 | + $this->getAllowedExtension(), |
|
45 | + GeneralUtility::getMaxUploadFileSize() * 1024, |
|
46 | + $this->getValue() |
|
47 | + ); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @return string |
|
52 | - */ |
|
53 | - protected function getModuleUrl() |
|
54 | - { |
|
55 | - $moduleSignature = MediaModule::getSignature(); |
|
56 | - return BackendUtility::getModuleUrl($moduleSignature); |
|
57 | - } |
|
50 | + /** |
|
51 | + * @return string |
|
52 | + */ |
|
53 | + protected function getModuleUrl() |
|
54 | + { |
|
55 | + $moduleSignature = MediaModule::getSignature(); |
|
56 | + return BackendUtility::getModuleUrl($moduleSignature); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Get allowed extension. |
|
61 | - * |
|
62 | - * @return string |
|
63 | - */ |
|
64 | - protected function getAllowedExtension() |
|
65 | - { |
|
66 | - return $this->file->getExtension(); |
|
67 | - } |
|
59 | + /** |
|
60 | + * Get allowed extension. |
|
61 | + * |
|
62 | + * @return string |
|
63 | + */ |
|
64 | + protected function getAllowedExtension() |
|
65 | + { |
|
66 | + return $this->file->getExtension(); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * Returns additional file info. |
|
71 | - * |
|
72 | - * @return string |
|
73 | - */ |
|
74 | - protected function getFileInfo() |
|
75 | - { |
|
76 | - /** @var MetadataViewHelper $metadataViewHelper */ |
|
77 | - $metadataViewHelper = GeneralUtility::makeInstance(MetadataViewHelper::class); |
|
69 | + /** |
|
70 | + * Returns additional file info. |
|
71 | + * |
|
72 | + * @return string |
|
73 | + */ |
|
74 | + protected function getFileInfo() |
|
75 | + { |
|
76 | + /** @var MetadataViewHelper $metadataViewHelper */ |
|
77 | + $metadataViewHelper = GeneralUtility::makeInstance(MetadataViewHelper::class); |
|
78 | 78 | |
79 | - return sprintf( |
|
80 | - '<div class="container-fileInfo" style="font-size: 7pt; color: #777;">%s</div>', |
|
81 | - $metadataViewHelper->render($this->file) |
|
82 | - ); |
|
83 | - } |
|
79 | + return sprintf( |
|
80 | + '<div class="container-fileInfo" style="font-size: 7pt; color: #777;">%s</div>', |
|
81 | + $metadataViewHelper->render($this->file) |
|
82 | + ); |
|
83 | + } |
|
84 | 84 | } |
@@ -34,7 +34,7 @@ |
||
34 | 34 | { |
35 | 35 | // Get the base prefix. |
36 | 36 | $basePrefix = $this->getBasePrefix($this->getPrefix()); |
37 | - $filePath = ExtensionManagementUtility::extPath('media') . 'Resources/Private/Standalone/FileUploadTceForms.js'; |
|
37 | + $filePath = ExtensionManagementUtility::extPath('media').'Resources/Private/Standalone/FileUploadTceForms.js'; |
|
38 | 38 | |
39 | 39 | return sprintf( |
40 | 40 | file_get_contents($filePath), |
@@ -14,14 +14,14 @@ |
||
14 | 14 | */ |
15 | 15 | interface FormFieldInterface |
16 | 16 | { |
17 | - /** |
|
18 | - * @return string |
|
19 | - */ |
|
20 | - public function render(); |
|
17 | + /** |
|
18 | + * @return string |
|
19 | + */ |
|
20 | + public function render(); |
|
21 | 21 | |
22 | - /** |
|
23 | - * @param string $template |
|
24 | - * @return \Fab\Media\Form\FormFieldInterface |
|
25 | - */ |
|
26 | - public function setTemplate($template); |
|
22 | + /** |
|
23 | + * @param string $template |
|
24 | + * @return \Fab\Media\Form\FormFieldInterface |
|
25 | + */ |
|
26 | + public function setTemplate($template); |
|
27 | 27 | } |
@@ -28,30 +28,30 @@ discard block |
||
28 | 28 | */ |
29 | 29 | class FileUpload extends AbstractFormField |
30 | 30 | { |
31 | - /** |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - protected $elementId; |
|
31 | + /** |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + protected $elementId; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var File |
|
38 | - */ |
|
39 | - protected $file; |
|
36 | + /** |
|
37 | + * @var File |
|
38 | + */ |
|
39 | + protected $file; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @var string |
|
43 | - */ |
|
44 | - protected $templateFile = 'Resources/Private/Standalone/FileUploadTemplate.html'; |
|
41 | + /** |
|
42 | + * @var string |
|
43 | + */ |
|
44 | + protected $templateFile = 'Resources/Private/Standalone/FileUploadTemplate.html'; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @return \Fab\Media\Form\FileUpload |
|
48 | - */ |
|
49 | - public function __construct() |
|
50 | - { |
|
51 | - $this->addLanguage(); |
|
52 | - $this->elementId = 'jquery-wrapped-fine-uploader-' . uniqid(); |
|
46 | + /** |
|
47 | + * @return \Fab\Media\Form\FileUpload |
|
48 | + */ |
|
49 | + public function __construct() |
|
50 | + { |
|
51 | + $this->addLanguage(); |
|
52 | + $this->elementId = 'jquery-wrapped-fine-uploader-' . uniqid(); |
|
53 | 53 | |
54 | - $this->template = <<<EOF |
|
54 | + $this->template = <<<EOF |
|
55 | 55 | <div class="control-group control-group-upload" style="%s"> |
56 | 56 | <div class="container-thumbnail">%s</div> |
57 | 57 | %s |
@@ -63,211 +63,211 @@ discard block |
||
63 | 63 | </div> |
64 | 64 | |
65 | 65 | EOF; |
66 | - } |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Add language labels for JavaScript files |
|
70 | - */ |
|
71 | - protected function addLanguage() |
|
72 | - { |
|
73 | - /** @var PageRenderer $pageRenderer */ |
|
74 | - $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
75 | - $pageRenderer->addInlineLanguageLabelFile(ExtensionManagementUtility::extPath('media') . 'Resources/Private/Language/locallang.xlf', 'media_file_upload'); |
|
76 | - } |
|
68 | + /** |
|
69 | + * Add language labels for JavaScript files |
|
70 | + */ |
|
71 | + protected function addLanguage() |
|
72 | + { |
|
73 | + /** @var PageRenderer $pageRenderer */ |
|
74 | + $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
75 | + $pageRenderer->addInlineLanguageLabelFile(ExtensionManagementUtility::extPath('media') . 'Resources/Private/Language/locallang.xlf', 'media_file_upload'); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Render a file upload field. |
|
80 | - * |
|
81 | - * @throws EmptyPropertyException |
|
82 | - * @return string |
|
83 | - */ |
|
84 | - public function render() |
|
85 | - { |
|
86 | - // Instantiate the file object for the whole class if possible. |
|
87 | - if ($this->getValue()) { |
|
88 | - $this->file = $this->getResourceFactory()->getFileObject($this->getValue()); |
|
89 | - } |
|
78 | + /** |
|
79 | + * Render a file upload field. |
|
80 | + * |
|
81 | + * @throws EmptyPropertyException |
|
82 | + * @return string |
|
83 | + */ |
|
84 | + public function render() |
|
85 | + { |
|
86 | + // Instantiate the file object for the whole class if possible. |
|
87 | + if ($this->getValue()) { |
|
88 | + $this->file = $this->getResourceFactory()->getFileObject($this->getValue()); |
|
89 | + } |
|
90 | 90 | |
91 | - $result = sprintf( |
|
92 | - $this->template, |
|
93 | - $this->getInlineStyle(), |
|
94 | - $this->getThumbnail(), |
|
95 | - $this->getFileInfo(), |
|
96 | - $this->elementId, |
|
97 | - $this->getJavaScriptTemplate(), |
|
98 | - $this->getJavaScript() |
|
99 | - ); |
|
100 | - return $result; |
|
101 | - } |
|
91 | + $result = sprintf( |
|
92 | + $this->template, |
|
93 | + $this->getInlineStyle(), |
|
94 | + $this->getThumbnail(), |
|
95 | + $this->getFileInfo(), |
|
96 | + $this->elementId, |
|
97 | + $this->getJavaScriptTemplate(), |
|
98 | + $this->getJavaScript() |
|
99 | + ); |
|
100 | + return $result; |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * @return string |
|
105 | - */ |
|
106 | - protected function getInlineStyle() |
|
107 | - { |
|
108 | - $style = 'float: left'; |
|
109 | - if ($this->getMediaModule()->hasFolderTree() && !$this->getModuleLoader()->hasPlugin()) { |
|
110 | - $style .= '; padding-left: 3px'; |
|
111 | - } |
|
112 | - return $style; |
|
113 | - } |
|
103 | + /** |
|
104 | + * @return string |
|
105 | + */ |
|
106 | + protected function getInlineStyle() |
|
107 | + { |
|
108 | + $style = 'float: left'; |
|
109 | + if ($this->getMediaModule()->hasFolderTree() && !$this->getModuleLoader()->hasPlugin()) { |
|
110 | + $style .= '; padding-left: 3px'; |
|
111 | + } |
|
112 | + return $style; |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * Get the javascript from a file and replace the markers with live variables. |
|
117 | - * |
|
118 | - * @return string |
|
119 | - */ |
|
120 | - protected function getThumbnail() |
|
121 | - { |
|
122 | - $thumbnail = ''; |
|
123 | - if ($this->file) { |
|
124 | - /** @var $thumbnailService \Fab\Media\Thumbnail\ThumbnailService */ |
|
125 | - $thumbnailService = GeneralUtility::makeInstance(ThumbnailService::class, $this->file); |
|
126 | - $thumbnail = $thumbnailService |
|
127 | - ->setOutputType(ThumbnailInterface::OUTPUT_IMAGE_WRAPPED) |
|
128 | - ->setAppendTimeStamp(true) |
|
129 | - ->create(); |
|
130 | - } |
|
131 | - return $thumbnail; |
|
132 | - } |
|
115 | + /** |
|
116 | + * Get the javascript from a file and replace the markers with live variables. |
|
117 | + * |
|
118 | + * @return string |
|
119 | + */ |
|
120 | + protected function getThumbnail() |
|
121 | + { |
|
122 | + $thumbnail = ''; |
|
123 | + if ($this->file) { |
|
124 | + /** @var $thumbnailService \Fab\Media\Thumbnail\ThumbnailService */ |
|
125 | + $thumbnailService = GeneralUtility::makeInstance(ThumbnailService::class, $this->file); |
|
126 | + $thumbnail = $thumbnailService |
|
127 | + ->setOutputType(ThumbnailInterface::OUTPUT_IMAGE_WRAPPED) |
|
128 | + ->setAppendTimeStamp(true) |
|
129 | + ->create(); |
|
130 | + } |
|
131 | + return $thumbnail; |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * Get the javascript from a file and replace the markers with live variables. |
|
136 | - * |
|
137 | - * @return string |
|
138 | - */ |
|
139 | - protected function getJavaScriptTemplate() |
|
140 | - { |
|
141 | - $view = $this->getStandaloneView(); |
|
142 | - $view->assignMultiple( |
|
143 | - array( |
|
144 | - 'maximumUploadLabel' => $this->getMaximumUploadLabel(), |
|
145 | - ) |
|
146 | - ); |
|
147 | - return $view->render(); |
|
148 | - } |
|
134 | + /** |
|
135 | + * Get the javascript from a file and replace the markers with live variables. |
|
136 | + * |
|
137 | + * @return string |
|
138 | + */ |
|
139 | + protected function getJavaScriptTemplate() |
|
140 | + { |
|
141 | + $view = $this->getStandaloneView(); |
|
142 | + $view->assignMultiple( |
|
143 | + array( |
|
144 | + 'maximumUploadLabel' => $this->getMaximumUploadLabel(), |
|
145 | + ) |
|
146 | + ); |
|
147 | + return $view->render(); |
|
148 | + } |
|
149 | 149 | |
150 | - /** |
|
151 | - * @return StandaloneView |
|
152 | - */ |
|
153 | - protected function getStandaloneView() |
|
154 | - { |
|
155 | - /** @var StandaloneView $view */ |
|
156 | - $view = GeneralUtility::makeInstance(StandaloneView::class); |
|
150 | + /** |
|
151 | + * @return StandaloneView |
|
152 | + */ |
|
153 | + protected function getStandaloneView() |
|
154 | + { |
|
155 | + /** @var StandaloneView $view */ |
|
156 | + $view = GeneralUtility::makeInstance(StandaloneView::class); |
|
157 | 157 | |
158 | - $templatePathAndFilename = ExtensionManagementUtility::extPath('media') . $this->templateFile; |
|
159 | - $view->setTemplatePathAndFilename($templatePathAndFilename); |
|
158 | + $templatePathAndFilename = ExtensionManagementUtility::extPath('media') . $this->templateFile; |
|
159 | + $view->setTemplatePathAndFilename($templatePathAndFilename); |
|
160 | 160 | |
161 | - return $view; |
|
162 | - } |
|
161 | + return $view; |
|
162 | + } |
|
163 | 163 | |
164 | - /** |
|
165 | - * Get the javascript from a file and replace the markers with live variables. |
|
166 | - * |
|
167 | - * @return string |
|
168 | - */ |
|
169 | - protected function getJavaScript() |
|
170 | - { |
|
171 | - // Get the base prefix |
|
172 | - $basePrefix = $this->getBasePrefix($this->getPrefix()); |
|
164 | + /** |
|
165 | + * Get the javascript from a file and replace the markers with live variables. |
|
166 | + * |
|
167 | + * @return string |
|
168 | + */ |
|
169 | + protected function getJavaScript() |
|
170 | + { |
|
171 | + // Get the base prefix |
|
172 | + $basePrefix = $this->getBasePrefix($this->getPrefix()); |
|
173 | 173 | |
174 | - $filePath = ExtensionManagementUtility::extPath('media') . 'Resources/Private/Standalone/FileUpload.js'; |
|
174 | + $filePath = ExtensionManagementUtility::extPath('media') . 'Resources/Private/Standalone/FileUpload.js'; |
|
175 | 175 | |
176 | - return sprintf( |
|
177 | - file_get_contents($filePath), |
|
178 | - $basePrefix, |
|
179 | - $this->elementId, |
|
180 | - $this->getModuleUrl(), |
|
181 | - $this->getAllowedExtensions(), |
|
182 | - GeneralUtility::getMaxUploadFileSize() * 1024, |
|
183 | - $this->isDrivenByFolder() ? |
|
184 | - $this->getMediaModule()->getCurrentFolder()->getCombinedIdentifier() : |
|
185 | - $this->getMediaModule()->getCurrentStorage()->getUid() . ':/' |
|
186 | - ); |
|
187 | - } |
|
176 | + return sprintf( |
|
177 | + file_get_contents($filePath), |
|
178 | + $basePrefix, |
|
179 | + $this->elementId, |
|
180 | + $this->getModuleUrl(), |
|
181 | + $this->getAllowedExtensions(), |
|
182 | + GeneralUtility::getMaxUploadFileSize() * 1024, |
|
183 | + $this->isDrivenByFolder() ? |
|
184 | + $this->getMediaModule()->getCurrentFolder()->getCombinedIdentifier() : |
|
185 | + $this->getMediaModule()->getCurrentStorage()->getUid() . ':/' |
|
186 | + ); |
|
187 | + } |
|
188 | 188 | |
189 | - /** |
|
190 | - * @return bool |
|
191 | - */ |
|
192 | - protected function isDrivenByFolder() |
|
193 | - { |
|
194 | - return $this->getMediaModule()->hasFolderTree() && !$this->getModuleLoader()->hasPlugin(); |
|
195 | - } |
|
189 | + /** |
|
190 | + * @return bool |
|
191 | + */ |
|
192 | + protected function isDrivenByFolder() |
|
193 | + { |
|
194 | + return $this->getMediaModule()->hasFolderTree() && !$this->getModuleLoader()->hasPlugin(); |
|
195 | + } |
|
196 | 196 | |
197 | - /** |
|
198 | - * @return string |
|
199 | - */ |
|
200 | - protected function getModuleUrl() |
|
201 | - { |
|
202 | - $moduleSignature = MediaModule::getSignature(); |
|
203 | - return BackendUtility::getModuleUrl($moduleSignature); |
|
204 | - } |
|
197 | + /** |
|
198 | + * @return string |
|
199 | + */ |
|
200 | + protected function getModuleUrl() |
|
201 | + { |
|
202 | + $moduleSignature = MediaModule::getSignature(); |
|
203 | + return BackendUtility::getModuleUrl($moduleSignature); |
|
204 | + } |
|
205 | 205 | |
206 | - /** |
|
207 | - * Returns the max upload file size in Mo. |
|
208 | - * |
|
209 | - * @return string |
|
210 | - */ |
|
211 | - protected function getMaximumUploadLabel() |
|
212 | - { |
|
213 | - $result = round(GeneralUtility::getMaxUploadFileSize() / 1024, 2); |
|
214 | - $label = LocalizationUtility::translate('max_upload_file', 'media'); |
|
215 | - $result = sprintf($label, $result); |
|
216 | - return $result; |
|
217 | - } |
|
206 | + /** |
|
207 | + * Returns the max upload file size in Mo. |
|
208 | + * |
|
209 | + * @return string |
|
210 | + */ |
|
211 | + protected function getMaximumUploadLabel() |
|
212 | + { |
|
213 | + $result = round(GeneralUtility::getMaxUploadFileSize() / 1024, 2); |
|
214 | + $label = LocalizationUtility::translate('max_upload_file', 'media'); |
|
215 | + $result = sprintf($label, $result); |
|
216 | + return $result; |
|
217 | + } |
|
218 | 218 | |
219 | - /** |
|
220 | - * Get allowed extension. |
|
221 | - * |
|
222 | - * @return string |
|
223 | - */ |
|
224 | - protected function getAllowedExtensions() |
|
225 | - { |
|
226 | - return implode("','", PermissionUtility::getInstance()->getAllowedExtensions()); |
|
227 | - } |
|
219 | + /** |
|
220 | + * Get allowed extension. |
|
221 | + * |
|
222 | + * @return string |
|
223 | + */ |
|
224 | + protected function getAllowedExtensions() |
|
225 | + { |
|
226 | + return implode("','", PermissionUtility::getInstance()->getAllowedExtensions()); |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * Compute the base prefix by removing the square brackets. |
|
231 | - * |
|
232 | - * @param string $prefix |
|
233 | - * @return string |
|
234 | - */ |
|
235 | - protected function getBasePrefix($prefix) |
|
236 | - { |
|
237 | - $parts = explode('[', $prefix); |
|
238 | - return empty($parts) ? '' : $parts[0]; |
|
239 | - } |
|
229 | + /** |
|
230 | + * Compute the base prefix by removing the square brackets. |
|
231 | + * |
|
232 | + * @param string $prefix |
|
233 | + * @return string |
|
234 | + */ |
|
235 | + protected function getBasePrefix($prefix) |
|
236 | + { |
|
237 | + $parts = explode('[', $prefix); |
|
238 | + return empty($parts) ? '' : $parts[0]; |
|
239 | + } |
|
240 | 240 | |
241 | - /** |
|
242 | - * Returns additional file info. |
|
243 | - * |
|
244 | - * @return string |
|
245 | - */ |
|
246 | - protected function getFileInfo() |
|
247 | - { |
|
248 | - return ''; // empty return here but check out Tceforms/FileUpload |
|
249 | - } |
|
241 | + /** |
|
242 | + * Returns additional file info. |
|
243 | + * |
|
244 | + * @return string |
|
245 | + */ |
|
246 | + protected function getFileInfo() |
|
247 | + { |
|
248 | + return ''; // empty return here but check out Tceforms/FileUpload |
|
249 | + } |
|
250 | 250 | |
251 | - /** |
|
252 | - * @return MediaModule|object |
|
253 | - */ |
|
254 | - protected function getMediaModule() |
|
255 | - { |
|
256 | - return GeneralUtility::makeInstance(MediaModule::class); |
|
257 | - } |
|
251 | + /** |
|
252 | + * @return MediaModule|object |
|
253 | + */ |
|
254 | + protected function getMediaModule() |
|
255 | + { |
|
256 | + return GeneralUtility::makeInstance(MediaModule::class); |
|
257 | + } |
|
258 | 258 | |
259 | - /** |
|
260 | - * Get the Vidi Module Loader. |
|
261 | - * |
|
262 | - * @return ModuleLoader|object |
|
263 | - */ |
|
264 | - protected function getModuleLoader() |
|
265 | - { |
|
266 | - return GeneralUtility::makeInstance(ModuleLoader::class); |
|
267 | - } |
|
259 | + /** |
|
260 | + * Get the Vidi Module Loader. |
|
261 | + * |
|
262 | + * @return ModuleLoader|object |
|
263 | + */ |
|
264 | + protected function getModuleLoader() |
|
265 | + { |
|
266 | + return GeneralUtility::makeInstance(ModuleLoader::class); |
|
267 | + } |
|
268 | 268 | |
269 | - protected function getResourceFactory(): ResourceFactory |
|
270 | - { |
|
271 | - return GeneralUtility::makeInstance(ResourceFactory::class); |
|
272 | - } |
|
269 | + protected function getResourceFactory(): ResourceFactory |
|
270 | + { |
|
271 | + return GeneralUtility::makeInstance(ResourceFactory::class); |
|
272 | + } |
|
273 | 273 | } |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | public function __construct() |
50 | 50 | { |
51 | 51 | $this->addLanguage(); |
52 | - $this->elementId = 'jquery-wrapped-fine-uploader-' . uniqid(); |
|
52 | + $this->elementId = 'jquery-wrapped-fine-uploader-'.uniqid(); |
|
53 | 53 | |
54 | 54 | $this->template = <<<EOF |
55 | 55 | <div class="control-group control-group-upload" style="%s"> |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | { |
73 | 73 | /** @var PageRenderer $pageRenderer */ |
74 | 74 | $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
75 | - $pageRenderer->addInlineLanguageLabelFile(ExtensionManagementUtility::extPath('media') . 'Resources/Private/Language/locallang.xlf', 'media_file_upload'); |
|
75 | + $pageRenderer->addInlineLanguageLabelFile(ExtensionManagementUtility::extPath('media').'Resources/Private/Language/locallang.xlf', 'media_file_upload'); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | /** @var StandaloneView $view */ |
156 | 156 | $view = GeneralUtility::makeInstance(StandaloneView::class); |
157 | 157 | |
158 | - $templatePathAndFilename = ExtensionManagementUtility::extPath('media') . $this->templateFile; |
|
158 | + $templatePathAndFilename = ExtensionManagementUtility::extPath('media').$this->templateFile; |
|
159 | 159 | $view->setTemplatePathAndFilename($templatePathAndFilename); |
160 | 160 | |
161 | 161 | return $view; |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | // Get the base prefix |
172 | 172 | $basePrefix = $this->getBasePrefix($this->getPrefix()); |
173 | 173 | |
174 | - $filePath = ExtensionManagementUtility::extPath('media') . 'Resources/Private/Standalone/FileUpload.js'; |
|
174 | + $filePath = ExtensionManagementUtility::extPath('media').'Resources/Private/Standalone/FileUpload.js'; |
|
175 | 175 | |
176 | 176 | return sprintf( |
177 | 177 | file_get_contents($filePath), |
@@ -181,8 +181,7 @@ discard block |
||
181 | 181 | $this->getAllowedExtensions(), |
182 | 182 | GeneralUtility::getMaxUploadFileSize() * 1024, |
183 | 183 | $this->isDrivenByFolder() ? |
184 | - $this->getMediaModule()->getCurrentFolder()->getCombinedIdentifier() : |
|
185 | - $this->getMediaModule()->getCurrentStorage()->getUid() . ':/' |
|
184 | + $this->getMediaModule()->getCurrentFolder()->getCombinedIdentifier() : $this->getMediaModule()->getCurrentStorage()->getUid().':/' |
|
186 | 185 | ); |
187 | 186 | } |
188 | 187 |