-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathboot.php
More file actions
261 lines (223 loc) · 11.5 KB
/
boot.php
File metadata and controls
261 lines (223 loc) · 11.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
<?php
/** @var rex_addon $this */
use FriendsOfRedaxo\FilePond\FilePondMediaCleanup;
rex_yform::addTemplatePath($this->getPath('ytemplates'));
// MEDIA_IS_IN_USE Extension Point registrieren für bessere Kontrolle
rex_extension::register('MEDIA_IS_IN_USE', [FilePondMediaCleanup::class, 'isMediaInUse']);
// Mediapool MIME-Types erweitern für Typen, die FilePond erlaubt aber der Mediapool nicht kennt
if (rex_addon::get('mediapool')->isAvailable()) {
$filepondMimeMap = [
// Bilder
'image/jpeg' => ['ext' => 'jpg', 'alt' => ['image/pjpeg']],
'image/png' => ['ext' => 'png'],
'image/gif' => ['ext' => 'gif'],
'image/webp' => ['ext' => 'webp'],
'image/svg+xml' => ['ext' => 'svg'],
'image/tiff' => ['ext' => 'tiff'],
'image/bmp' => ['ext' => 'bmp'],
'image/heic' => ['ext' => 'heic'],
'image/avif' => ['ext' => 'avif'],
'image/x-icon' => ['ext' => 'ico', 'alt' => ['image/vnd.microsoft.icon']],
// Dokumente
'application/pdf' => ['ext' => 'pdf'],
'text/plain' => ['ext' => 'txt', 'alt' => ['application/octet-stream']],
'text/csv' => ['ext' => 'csv', 'alt' => ['text/plain', 'application/octet-stream']],
'text/calendar' => ['ext' => 'ics', 'alt' => ['text/plain', 'application/octet-stream']],
'text/x-vcalendar' => ['ext' => 'vcal', 'alt' => ['text/calendar', 'text/plain', 'application/octet-stream']],
'text/vcard' => ['ext' => 'vcf', 'alt' => ['text/x-vcard', 'text/plain', 'application/octet-stream']],
'text/markdown' => ['ext' => 'md', 'alt' => ['text/plain', 'application/octet-stream']],
'application/rtf' => ['ext' => 'rtf'],
'application/json' => ['ext' => 'json', 'alt' => ['text/plain']],
'text/xml' => ['ext' => 'xml', 'alt' => ['application/xml']],
'text/vtt' => ['ext' => 'vtt'],
'text/srt' => ['ext' => 'srt', 'alt' => ['text/plain']],
// Archive
'application/zip' => ['ext' => 'zip', 'alt' => ['application/x-zip-compressed']],
'application/x-gzip' => ['ext' => 'gz', 'alt' => ['application/gzip']],
'application/x-tar' => ['ext' => 'tar'],
'application/x-rar-compressed' => ['ext' => 'rar', 'alt' => ['application/vnd.rar']],
'application/x-7z-compressed' => ['ext' => '7z'],
// Video
'video/mp4' => ['ext' => 'mp4'],
'video/mpeg' => ['ext' => 'mpeg'],
'video/quicktime' => ['ext' => 'mov'],
'video/webm' => ['ext' => 'webm'],
'video/ogg' => ['ext' => 'ogv'],
'video/x-msvideo' => ['ext' => 'avi'],
'video/x-matroska' => ['ext' => 'mkv'],
// Audio
'audio/mpeg' => ['ext' => 'mp3'],
'audio/wav' => ['ext' => 'wav', 'alt' => ['audio/x-wav']],
'audio/ogg' => ['ext' => 'ogg'],
'audio/aac' => ['ext' => 'aac'],
'audio/midi' => ['ext' => 'midi', 'alt' => ['audio/x-midi']],
'audio/flac' => ['ext' => 'flac'],
'audio/mp4' => ['ext' => 'm4a'],
'audio/webm' => ['ext' => 'weba'],
// Office (Modern)
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => ['ext' => 'docx', 'alt' => ['application/octet-stream', 'application/encrypted']],
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => ['ext' => 'xlsx', 'alt' => ['application/octet-stream', 'application/encrypted']],
'application/vnd.openxmlformats-officedocument.presentationml.presentation' => ['ext' => 'pptx'],
'application/vnd.openxmlformats-officedocument.wordprocessingml.template' => ['ext' => 'dotx', 'alt' => ['application/octet-stream']],
'application/vnd.openxmlformats-officedocument.presentationml.template' => ['ext' => 'potx'],
'application/vnd.openxmlformats-officedocument.presentationml.slideshow' => ['ext' => 'ppsx'],
// Office (Legacy)
'application/msword' => ['ext' => 'doc', 'alt' => ['application/octet-stream', 'application/encrypted']],
'application/vnd.ms-excel' => ['ext' => 'xls', 'alt' => ['application/octet-stream', 'application/encrypted']],
'application/vnd.ms-powerpoint' => ['ext' => 'ppt'],
// OpenDocument
'application/vnd.oasis.opendocument.text' => ['ext' => 'odt'],
'application/vnd.oasis.opendocument.spreadsheet' => ['ext' => 'ods'],
'application/vnd.oasis.opendocument.presentation' => ['ext' => 'odp'],
// Fonts
'font/woff' => ['ext' => 'woff', 'alt' => ['application/font-woff']],
'font/woff2' => ['ext' => 'woff2'],
'font/ttf' => ['ext' => 'ttf', 'alt' => ['application/x-font-ttf']],
'font/otf' => ['ext' => 'otf', 'alt' => ['application/x-font-opentype']],
// Sonstige
'application/postscript' => ['ext' => 'eps'],
'application/epub+zip' => ['ext' => 'epub'],
];
$allowedTypes = rex_config::get('filepond_uploader', 'allowed_types', '');
if ('' !== $allowedTypes) {
// FilePond nutzt Komma-getrennte MIME-Types, kann aber auch Wildcards (image/*) und Endungen (.pdf) enthalten
$configuredTypes = array_map('trim', explode(',', $allowedTypes));
$mediapoolMimes = rex_addon::get('mediapool')->getProperty('allowed_mime_types', []);
$changed = false;
foreach ($configuredTypes as $type) {
// Wildcard-Typen wie "image/*" oder "video/*" auflösen
if (str_contains($type, '/*')) {
$prefix = explode('/*', $type)[0] . '/';
foreach ($filepondMimeMap as $mime => $info) {
if (str_starts_with($mime, $prefix) && !isset($mediapoolMimes[$info['ext']])) {
$mediapoolMimes[$info['ext']] = array_merge([$mime], $info['alt'] ?? []);
$changed = true;
}
}
} elseif (isset($filepondMimeMap[$type])) {
// Exakter MIME-Type
$ext = $filepondMimeMap[$type]['ext'];
if (!isset($mediapoolMimes[$ext])) {
$mediapoolMimes[$ext] = array_merge([$type], $filepondMimeMap[$type]['alt'] ?? []);
$changed = true;
}
} elseif (str_starts_with($type, '.')) {
// Dateiendung wie ".pdf", ".docx" – passenden MIME-Type finden
$extLookup = ltrim($type, '.');
foreach ($filepondMimeMap as $mime => $info) {
if ($info['ext'] === $extLookup && !isset($mediapoolMimes[$extLookup])) {
$mediapoolMimes[$extLookup] = array_merge([$mime], $info['alt'] ?? []);
$changed = true;
break;
}
}
}
}
if ($changed) {
rex_addon::get('mediapool')->setProperty('allowed_mime_types', $mediapoolMimes);
}
}
}
if (rex::isBackend() && rex::getUser()) {
// Einbindung über Static-Properties sicherstellen
static $filepondScriptsLoaded = false;
if (!$filepondScriptsLoaded) {
filepond_helper::getStyles();
filepond_helper::getScripts();
$filepondScriptsLoaded = true;
}
// Settings-Seite: JS für Dateitypen-Auswahl
if ('filepond_uploader/settings' === rex_be_controller::getCurrentPage()) {
rex_view::addJsFile($this->getAssetsUrl('filepond_settings.js'));
}
}
if(rex_config::get('filepond_uploader', 'replace_mediapool', false))
{
rex_extension::register('PAGES_PREPARED', function (rex_extension_point $ep) {
/** @var array<string, rex_be_page> $pages */
$pages = $ep->getSubject();
if (isset($pages['mediapool'])) {
$mediapoolPage = $pages['mediapool'];
if ($uploadPage = $mediapoolPage->getSubpage('upload')) {
// Nur das subPath ändern, der Rest bleibt gleich
$uploadPage->setSubPath(
rex_path::addon('filepond_uploader', 'pages/upload.php')
);
}
}
});
}
// Multiupload als Medienpool-Unterseite registrieren
$mediapoolSubpage = rex_config::get('filepond_uploader', 'mediapool_subpage', '');
if ($mediapoolSubpage === '|1|' || $mediapoolSubpage === '1') {
rex_extension::register('PAGES_PREPARED', function (rex_extension_point $ep) {
$user = rex::getUser();
if (!$user) {
return;
}
/** @var array<string, rex_be_page> $pages */
$pages = $ep->getSubject();
if (isset($pages['mediapool'])) {
$mediapoolPage = $pages['mediapool'];
$title = '<i class="fa-solid fa-cloud-arrow-up"></i> ' . rex_i18n::msg('filepond_multiupload_title');
$multiuploadPage = new rex_be_page('filepond_multiupload', $title);
$multiuploadPage->setSubPath(rex_path::addon('filepond_uploader', 'pages/upload.php'));
$multiuploadPage->setRequiredPermissions('filepond_uploader[upload]');
// Nach der 'upload'-Seite einfügen
$subpages = $mediapoolPage->getSubpages();
$ordered = [];
$inserted = false;
foreach ($subpages as $key => $subpage) {
$ordered[$key] = $subpage;
if ($key === 'upload' && !$inserted) {
$ordered['filepond_multiupload'] = $multiuploadPage;
$inserted = true;
}
}
if (!$inserted) {
$ordered['filepond_multiupload'] = $multiuploadPage;
}
$mediapoolPage->setSubpages($ordered);
}
});
}
// Alt-Text-Checker als Medienpool-Unterseite registrieren
$enableAltChecker = rex_config::get('filepond_uploader', 'enable_alt_checker', '');
if ($enableAltChecker === '|1|' || $enableAltChecker === '1') {
rex_extension::register('PAGES_PREPARED', function (rex_extension_point $ep) {
$user = rex::getUser();
if (!$user) return;
// Nur für Admins oder Nutzer mit entsprechender Berechtigung
if (!$user->isAdmin() && !$user->hasPerm('filepond_uploader[alt_checker]')) {
return;
}
// Nur einbinden wenn med_alt Feld überhaupt vorhanden ist
if (!filepond_alt_text_checker::checkAltFieldExists()) {
return;
}
/** @var array<string, rex_be_page> $pages */
$pages = $ep->getSubject();
if (isset($pages['mediapool'])) {
$mediapoolPage = $pages['mediapool'];
// Neue Unterseite erstellen
$title = '<i class="fa-solid fa-universal-access"></i> ' . rex_i18n::msg('filepond_alt_checker_title');
$altCheckerPage = new rex_be_page('alt_checker', $title);
$altCheckerPage->setSubPath(rex_path::addon('filepond_uploader', 'pages/alt_checker.php'));
$altCheckerPage->setRequiredPermissions('filepond_uploader[alt_checker]');
// Als Unterseite hinzufügen
$mediapoolPage->addSubpage($altCheckerPage);
}
});
}
// Info Center FilePond Upload Widget Integration
if (rex_addon::exists('info_center') && rex_addon::get('info_center')->isAvailable()) {
rex_extension::register('PACKAGES_INCLUDED', function() {
$infoCenter = \KLXM\InfoCenter\InfoCenter::getInstance();
// Check if user has permission (only for logged-in users)
if (rex::getUser()) {
$widget = new \KLXM\InfoCenter\Widgets\FilePondUploadWidget();
$widget->setPriority(0.5); // After TimeTracker (0), before Article (1)
$infoCenter->registerWidget($widget);
}
});
}