-
-
Notifications
You must be signed in to change notification settings - Fork 117
/
function_rex_mediapool.php
377 lines (331 loc) · 11.8 KB
/
function_rex_mediapool.php
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
<?php
/**
* Funktionensammlung für den Medienpool.
*
* @package redaxo\mediapool
*/
/**
* Erstellt einen Filename der eindeutig ist für den Medienpool.
*
* @param string $mediaName Dateiname
* @param bool $doSubindexing
*
* @deprecated since 2.11, use `rex_mediapool::filename` instead
*/
function rex_mediapool_filename($mediaName, $doSubindexing = true): string
{
return rex_mediapool::filename($mediaName, $doSubindexing);
}
/**
* Holt ein upgeloadetes File und legt es in den Medienpool
* Dabei wird kontrolliert ob das File schon vorhanden ist und es
* wird eventuell angepasst, weiterhin werden die Fileinformationen übergeben.
*
* @param array $FILE
* @param int $rexFileCategory
* @param array $FILEINFOS
* @param string $userlogin
* @param bool $doSubindexing
*
* @return array
* @deprecated since 2.11, use `rex_media_service::addMedia` instead
* @psalm-suppress UnusedParam
*/
function rex_mediapool_saveMedia($FILE, $rexFileCategory, $FILEINFOS, $userlogin = null, $doSubindexing = true)
{
$data = $FILEINFOS;
$data['category_id'] = (int) $rexFileCategory;
if ($FILE) {
$data['file'] = $FILE;
if (!isset($data['file']['path']) && isset($FILE['name']) && !isset($FILE['tmp_name'])) {
$data['file']['path'] = rex_path::media($FILE['name']);
}
}
try {
return rex_media_service::addMedia($data, $doSubindexing);
} catch (rex_api_exception $e) {
// BC
// Missing Fields
$RETURN = [];
$RETURN['title'] = $FILEINFOS['title'];
// $RETURN['type'] = $FILETYPE;
$RETURN['msg'] = $e->getMessage();
$RETURN['ok'] = 0;
// $RETURN['filename'] = $NFILENAME;
// $RETURN['old_filename'] = $FILENAME;
$RETURN['category_id'] = $rexFileCategory;
// if (isset($size) && $size) {
// $RETURN['width'] = $size[0];
// $RETURN['height'] = $size[1];
// }
return $RETURN;
}
}
/**
* Holt ein upgeloadetes File und legt es in den Medienpool
* Dabei wird kontrolliert ob das File schon vorhanden ist und es
* wird eventuell angepasst, weiterhin werden die Fileinformationen übergeben.
*
* @param array $FILE
* @param array $FILEINFOS
* @param string $userlogin
*
* @return array
* @deprecated since 2.11, use `rex_media_service::updateMedia` instead
* @psalm-suppress UnusedParam
*/
function rex_mediapool_updateMedia($FILE, &$FILEINFOS, $userlogin = null)
{
$data = [
'category_id' => $FILEINFOS['rex_file_category'],
'title' => $FILEINFOS['title'],
];
if ($FILE && 'none' !== ($FILE['name'] ?? null)) {
$data['file'] = $FILE;
}
try {
return rex_media_service::updateMedia($FILEINFOS['filename'], $data);
} catch (rex_api_exception $e) {
return [
'ok' => 0,
'msg' => $e->getMessage(),
];
}
}
/**
* Synchronisiert die Datei $physical_filename des Mediafolders in den
* Medienpool.
*
* @param string $physicalFilename
* @param int $categoryId
* @param string $title
* @param null|int $filesize
* @param null|string $filetype
* @param null|string $userlogin
*
* @return array
* @deprecated since 2.11, use `rex_media_service::addMedia` instead
* @psalm-suppress UnusedParam
*/
function rex_mediapool_syncFile($physicalFilename, $categoryId, $title, $filesize = null, $filetype = null, $userlogin = null)
{
$data = [];
$data['title'] = $title;
$data['category_id'] = $categoryId;
$data['file'] = [
'name' => $physicalFilename,
'path' => rex_path::media($physicalFilename),
];
try {
return rex_media_service::addMedia($data, false);
} catch (rex_api_exception $e) {
return [
'ok' => 0,
'msg' => $e->getMessage(),
];
}
}
/**
* @param string $filename
*
* @return array
*
* @psalm-return array{ok: bool, msg: string}
* @deprecated since 2.11, use `rex_media_service::deleteMedia` instead
*/
function rex_mediapool_deleteMedia($filename)
{
try {
rex_media_service::deleteMedia($filename);
return ['ok' => true, 'msg' => rex_i18n::msg('pool_file_deleted')];
} catch (rex_api_exception $exception) {
return ['ok' => false, 'msg' => '<strong>' . $exception->getMessage() . '</strong>'];
}
}
/**
* @param string $filename
*
* @return bool|string
* @deprecated since 2.11, use `rex_mediapool::mediaIsInUse` instead
*/
function rex_mediapool_mediaIsInUse($filename)
{
return rex_mediapool::mediaIsInUse($filename);
}
/**
* Ausgabe des Medienpool Formulars.
*
* @return string
*/
function rex_mediapool_Mediaform($formTitle, $buttonTitle, $rexFileCategory, $fileChooser, $closeForm)
{
global $ftitle, $warning, $info;
$s = '';
$catsSel = new rex_media_category_select();
$catsSel->setStyle('class="form-control"');
$catsSel->setSize(1);
$catsSel->setName('rex_file_category');
$catsSel->setId('rex-mediapool-category');
$catsSel->setAttribute('class', 'selectpicker form-control');
$catsSel->setAttribute('data-live-search', 'true');
$catsSel->setAttribute('onchange', 'this.form.submit()');
$catsSel->setSelected($rexFileCategory);
if (rex::getUser()->getComplexPerm('media')->hasAll()) {
$catsSel->addOption(rex_i18n::msg('pool_kats_no'), '0');
}
if (isset($warning)) {
if (is_array($warning)) {
if (count($warning) > 0) {
$s .= rex_view::error(implode('<br />', $warning));
}
} elseif ('' != $warning) {
$s .= rex_view::error($warning);
}
$warning = '';
}
if (isset($info)) {
if (is_array($info)) {
if (count($info) > 0) {
$s .= rex_view::success(implode('<br />', $info));
}
} elseif ('' != $info) {
$s .= rex_view::success($info);
}
$info = '';
}
if (!isset($ftitle)) {
$ftitle = '';
}
$argFields = '';
foreach (rex_request('args', 'array') as $argName => $argValue) {
$argFields .= '<input type="hidden" name="args[' . rex_escape($argName) . ']" value="' . rex_escape($argValue) . '" />' . "\n";
}
$openerInputField = rex_request('opener_input_field', 'string');
if ('' != $openerInputField) {
$argFields .= '<input type="hidden" name="opener_input_field" value="' . rex_escape($openerInputField) . '" />' . "\n";
}
$addSubmit = '';
if ($closeForm && '' != $openerInputField) {
$addSubmit = '<button class="btn btn-save" type="submit" name="saveandexit" value="' . rex_i18n::msg('pool_file_upload_get') . '"' . rex::getAccesskey(rex_i18n::msg('save_and_close_tooltip'), 'save') . '>' . rex_i18n::msg('pool_file_upload_get') . '</button>';
}
$panel = '';
$panel .= '<fieldset>';
$formElements = [];
$e = [];
$e['label'] = '<label for="rex-mediapool-category">' . rex_i18n::msg('pool_file_category') . '</label>';
$e['field'] = $catsSel->get();
$formElements[] = $e;
$e = [];
$e['label'] = '<label for="rex-mediapool-title">' . rex_i18n::msg('pool_file_title') . '</label>';
$e['field'] = '<input class="form-control" type="text" id="rex-mediapool-title" name="ftitle" value="' . rex_escape($ftitle) . '" />';
$formElements[] = $e;
$fragment = new rex_fragment();
$fragment->setVar('elements', $formElements, false);
$panel .= $fragment->parse('core/form/form.php');
$panel .= rex_extension::registerPoint(new rex_extension_point('MEDIA_FORM_ADD', ''));
if ($fileChooser) {
$e = [];
$e['label'] = '<label for="rex-mediapool-choose-file">' . rex_i18n::msg('pool_file_file') . '</label>';
$e['field'] = '<input id="rex-mediapool-choose-file" type="file" name="file_new" />';
$e['after'] = '<h3>' . rex_i18n::msg('phpini_settings') . '</h3>
<dl class="dl-horizontal text-left">
' . ((0 == rex_ini_get('file_uploads')) ? '<dt><span class="text-warning">' . rex_i18n::msg('pool_upload') . '</span></dt><dd><span class="text-warning">' . rex_i18n::msg('pool_upload_disabled') . '</span></dd>' : '') . '
<dt>' . rex_i18n::msg('pool_max_uploadsize') . ':</dt><dd>' . rex_formatter::bytes(rex_ini_get('upload_max_filesize')) . '</dd>
<dt>' . rex_i18n::msg('pool_max_uploadtime') . ':</dt><dd>' . rex_ini_get('max_input_time') . 's</dd>
</dl>';
$fragment = new rex_fragment();
$fragment->setVar('elements', [$e], false);
$panel .= $fragment->parse('core/form/form.php');
}
$panel .= '</fieldset>';
$formElements = [];
$e = [];
$e['field'] = '<button class="btn btn-save rex-form-aligned" type="submit" name="save" value="' . $buttonTitle . '"' . rex::getAccesskey($buttonTitle, 'save') . '>' . $buttonTitle . '</button>';
$formElements[] = $e;
$e = [];
$e['field'] = $addSubmit;
$formElements[] = $e;
$fragment = new rex_fragment();
$fragment->setVar('elements', $formElements, false);
$buttons = $fragment->parse('core/form/submit.php');
$fragment = new rex_fragment();
$fragment->setVar('class', 'edit', false);
$fragment->setVar('title', $formTitle, false);
$fragment->setVar('body', $panel, false);
$fragment->setVar('buttons', $buttons, false);
$content = $fragment->parse('core/page/section.php');
$s .= ' <form action="' . rex_url::currentBackendPage() . '" method="post" enctype="multipart/form-data" data-pjax="false">
' . rex_csrf_token::factory('mediapool')->getHiddenField() . '
<fieldset>
<input type="hidden" name="media_method" value="add_file" />
' . $argFields . '
' . $content . '
</fieldset>
';
if ($closeForm) {
$s .= '</form>' . "\n";
}
return $s;
}
/**
* Ausgabe des Medienpool Upload-Formulars.
*/
function rex_mediapool_Uploadform($rexFileCategory)
{
return rex_mediapool_Mediaform(rex_i18n::msg('pool_file_insert'), rex_i18n::msg('pool_file_upload'), $rexFileCategory, true, true);
}
/**
* Ausgabe des Medienpool Sync-Formulars.
*/
function rex_mediapool_Syncform($rexFileCategory)
{
return rex_mediapool_Mediaform(rex_i18n::msg('pool_sync_title'), rex_i18n::msg('pool_sync_button'), $rexFileCategory, false, false);
}
/**
* check if mediatpye(extension) is allowed for upload.
*
* @param string $filename
*
* @return bool
* @deprecated since 2.11, use `rex_mediapool::isAllowedExtension` instead
*/
function rex_mediapool_isAllowedMediaType($filename, array $args = [])
{
return rex_mediapool::isAllowedExtension($filename, $args);
}
/**
* Checks file against optional property `allowed_mime_types`.
*
* @param string $path Path to the physical file
* @param null|string $filename Optional filename, will be used for extracting the file extension.
* If not given, the extension is extracted from `$path`.
*
* @return bool
* @deprecated since 2.11, use `rex_mediapool::isAllowedMimeType` instead
*/
function rex_mediapool_isAllowedMimeType($path, $filename = null)
{
return rex_mediapool::isAllowedMimeType($path, $filename);
}
/**
* Get allowed mediatype extensions given via media widget "types" param.
*
* @param array $args widget params
*
* @return array allowed extensions
* @deprecated since 2.11, use `rex_mediapool::getAllowedExtensions` instead
*/
function rex_mediapool_getMediaTypeWhitelist($args = [])
{
return rex_mediapool::getAllowedExtensions($args);
}
/**
* Get global blocked mediatype extensions.
*
* @return array blocked mediatype extensions
* @deprecated since 2.11, use `rex_mediapool::getBlockedExtensions` instead
*/
function rex_mediapool_getMediaTypeBlacklist()
{
return rex_mediapool::getBlockedExtensions();
}