-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathAdminInput.php
More file actions
560 lines (519 loc) · 26.1 KB
/
AdminInput.php
File metadata and controls
560 lines (519 loc) · 26.1 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
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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
<?php
namespace Photobooth\Utility;
use Photobooth\Enum\Interface\LabelInterface;
use Photobooth\Service\LanguageService;
class AdminInput
{
public static function renderInput(array $setting, string $label): string
{
$attributes = '';
if (isset($setting['attributes'])) {
foreach ($setting['attributes'] as $key => $prop) {
$attributes .= $key . '="' . $prop . '" ';
}
}
return self::renderHeadline($label) . '
<input
class="w-full h-10 border-2 border-solid border-gray-300 focus:border-brand-1 rounded-md px-3 mt-auto"
type="' . ($setting['type'] === 'number' ? 'number' : 'text') . '"
name="' . $setting['name'] . '"
value="' . $setting['value'] . '"
placeholder="' . $setting['placeholder'] . '"
' . $attributes . '
/>
';
}
public static function renderHidden(array $setting): string
{
return '<input type="hidden" name="' . $setting['name'] . '" value="' . $setting['value'] . '"/>';
}
public static function renderCta(string $label, string $btnId = '', ?array $config = null): string
{
$languageService = LanguageService::getInstance();
$labels = '';
if ($config !== null) {
$labels = '
<span class="hidden success"><i class="' . $config['icons']['admin_save_success'] . '"></i> ' . $languageService->translate('success') . '</span>
<span class="hidden error"><i class="' . $config['icons']['admin_save_error'] . '"></i> ' . $languageService->translate('saveerror') . '</span>
';
}
return '
<button class="w-full h-12 rounded-full bg-brand-1 text-white flex items-center justify-center relative ml-auto border-2 border-solid border-brand-1 hover:bg-content-1 hover:text-brand-1 transition font-bold" id="' . $btnId . '">
<span class="save">
' . $languageService->translate($label) . '
</span>
' . $labels . '
</button>
';
}
public static function renderButton(array $setting, string $label, string $key, ?array $config = null): string
{
$btn = self::renderCta($setting['placeholder'], $setting['value'], $config);
$test = '';
switch ($key) {
case 'check_version':
$test = '
<table id="version_text_table">
<tr>
<td><span id="current_version_text"></span></td>
<td><span id="current_version"></span></td>
</tr>
<tr>
<td><span id="available_version_text"></span></td>
<td><span id="available_version"></span></td>
</tr>
</table>
';
break;
default:
break;
}
return self::renderHeadline($label) . '
<div class="w-full flex flex-col mt-auto">
' . $btn . '
</div>
' . $test . '
';
}
public static function renderCheckbox(array $setting, string $label): string
{
$languageService = LanguageService::getInstance();
$checkboxClasses =
"w-11 h-6 bg-gray-200 peer-focus:outline-hidden peer-focus:ring-4 peer-focus:ring-blue-300 dark:peer-focus:ring-blue-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-blue-600";
$init = $setting['value'];
$attributes = '';
if (isset($setting['attributes'])) {
foreach ($setting['attributes'] as $key => $prop) {
$attributes .= $key . '="' . $prop . '" ';
}
}
return self::renderHeadline($label) . '
<label class="adminCheckbox relative inline-flex items-center cursor-pointer mt-auto">
<input type="hidden" name="' . $setting['name'] . '" value="false" />
<input class="hidden peer" type="checkbox" ' . ($setting['value'] == 'true' ? ' checked="checked"' : '') . ' name="' . $setting['name'] . '" value="true" ' . $attributes . ' />
<div class="' . $checkboxClasses . '"></div>
<span class="ml-3 text-sm font-medium text-gray-900 dark:text-gray-300">
<label class="adminCheckbox-true ' . ($init == 'true' ? '' : 'hidden') . '">' . $languageService->translate('adminpanel_toggletextON') . '</label>
<label class="adminCheckbox-false ' . ($init != 'true' ? '' : 'hidden') . '">' . $languageService->translate('adminpanel_toggletextOFF') . '</label>
</span>
</label>
';
}
public static function renderColor(array $setting, string $label): string
{
$languageService = LanguageService::getInstance();
$attributes = '';
if (isset($setting['attributes'])) {
foreach ($setting['attributes'] as $key => $prop) {
$attributes .= $key . '="' . $prop . '" ';
}
}
return '
<label class="mb-3">' . $languageService->translate($label) . '</label>
<input
class="w-full h-10 border-2 border-gray-300 border-solid rounded-lg overflow-hidden p-1 mt-auto"
type="color"
name="' . $setting['name'] . '"
value="' . $setting['value'] . '"
placeholder="' . $setting['placeholder'] . '"
' . $attributes . '
/>
';
}
public static function renderIcon(array $setting, string $label): string
{
return self::renderHeadline($label) . '
' . ($setting['value'] !== '' ? '<div class="text-center mb-3 p-3 border-2 border-solid border-gray-300 rounded-md"><i class="' . $setting['value'] . '"></i></div>' : '') . '
<input
class="w-full h-10 border-2 border-solid border-gray-300 focus:border-brand-1 rounded-md px-3 mt-auto"
type="' . ($setting['type'] === 'number' ? 'number' : 'text') . '"
name="' . $setting['name'] . '"
value="' . $setting['value'] . '"
placeholder="' . $setting['placeholder'] . '"
/>
';
}
public static function renderRange(array $setting, string $label): string
{
$languageService = LanguageService::getInstance();
$inputClass = 'adminRangeInput w-full h-2 mb-1 bg-gray-200 rounded-lg appearance-none cursor-pointer dark:bg-gray-700';
$attributes = '';
if (isset($setting['attributes'])) {
foreach ($setting['attributes'] as $key => $prop) {
$attributes .= $key . '="' . $prop . '" ';
}
}
return self::renderHeadline($label) . '
<div class="w-full flex flex-col mt-auto">
<label id="' . $setting['name'] . '-value" for="' . $setting['name'] . '" class="block mb-3 text-sm font-bold text-gray-900 dark:text-white">
<span class="mr-1">' . $setting['value'] . '</span>
' . ($setting['unit'] == 'empty' ? '' : $languageService->translate($setting['unit'])) . '
</label>
<input
type="range"
name="' . $setting['name'] . '"
class="' . $inputClass . '"
value="' . $setting['value'] . '"
min="' . $setting['range_min'] . '"
max="' . $setting['range_max'] . '"
step="' . $setting['range_step'] . '"
placeholder="' . $setting['placeholder'] . '"
' . $attributes . '
/>
<div class="w-full flex text-gray-300">
<span>' . $setting['range_min'] . '</span>
<span class="ml-auto">' . $setting['range_max'] . '</span>
</div>
</div>
';
}
public static function renderSelect(array $setting, string $label): string
{
$className = $setting['type'] === 'multi-select' ? 'min-h-[30px] h-32 resize-y ' : '';
$className .= 'w-full h-10 border-2 border-solid border-gray-300 focus:border-brand-1 rounded-md px-2 mt-auto';
$settingName = $setting['name'] . '' . ($setting['type'] === 'multi-select' ? '[]' : '');
$options = '';
$attributes = '';
if (isset($setting['attributes'])) {
foreach ($setting['attributes'] as $key => $prop) {
$attributes .= $key . '="' . $prop . '" ';
}
}
foreach ($setting['options'] as $value => $option) {
$optionLabel = $option;
$optionValue = $value;
if ($option instanceof \BackedEnum) {
$optionLabel = ($option instanceof LabelInterface) ? $option->label() : $option->name;
$optionValue = $option;
}
$selected = '';
if ((is_array($setting['value']) && in_array($optionValue, $setting['value'])) || $optionValue === $setting['value']) {
$selected = ' selected="selected"';
}
$styles = '';
if ($settingName === 'text_font_family') {
$styles = 'style="font-family:' . $optionLabel . '"';
}
$options .= '<option ' . $selected . ' value="' . ($optionValue instanceof \BackedEnum ? $optionValue->value : $optionValue) . '"' . $styles . '>' . $optionLabel . '</option>';
}
return self::renderHeadline($label) . '
<select
class="' . $className . '"
name="' . $settingName . '"
' . ($setting['type'] === 'multi-select' ? ' multiple="multiple"' : '') . '
' . $attributes . '
>
' . $options . '
</select>
';
}
public static function renderImageSelect(array $setting, string $label): string
{
$languageService = LanguageService::getInstance();
$images = '';
$attributes = '';
if (isset($setting['attributes'])) {
foreach ($setting['attributes'] as $key => $prop) {
$attributes .= $key . '="' . $prop . '" ';
}
}
if (isset($setting['paths']) && is_array($setting['paths'])) {
foreach ($setting['paths'] as $path) {
$images .= '
<div class="col-span-3">
<h2 class="font-bold">' . PathUtility::getPublicPath($path) . '</h2>
</div>
';
try {
$files = ImageUtility::getImagesFromPath($path, false);
$files = array_map(fn ($file): string => PathUtility::getPublicPath($file), $files);
if (count($files) === 0) {
$images .= '
<div class="col-span-3">
<p>' . $languageService->translate('error_path_noImages') . '</p>
</div>
';
}
foreach ($files as $file) {
$origin = $file;
if (str_contains($setting['value'], 'url(')) {
$origin = 'url(' . $origin . ')';
}
$images .= '
<div class="w-full relative h-0 pb-2/3">
<img
onclick="adminImageSelect(this, \'' . $setting['name'] . '\');"
data-origin="' . $origin . '"
class="w-full h-full left-0 top-0 absolute object-contain"
src="' . $file . '"
title="' . $file . '"
>
</div>
';
}
} catch (\Exception $e) {
$images .= '
<div class="col-span-3">
<p>' . $e->getMessage() . '</p>
</div>
';
}
}
}
$hiddenPreview = '';
if (str_starts_with($setting['value'], 'http')) {
$hiddenPreview = 'hidden';
}
$selectedImage = $setting['value'];
if (str_contains($setting['value'], 'url(')) {
$selectedImage = substr($setting['value'], 4, -1);
}
if (str_contains($setting['value'], $_SERVER['DOCUMENT_ROOT'])) {
$selectedImage = substr($setting['value'], strlen($_SERVER['DOCUMENT_ROOT']));
}
$selectedImage = preg_replace('#/+#', '/', $selectedImage);
return '
<div class="adminImageSelection group">
<div class="w-full flex items-start">
<div class="w-24 flex mb-3 mr-3 shrink-0 cursor-pointer ' . $hiddenPreview . '" onclick="openAdminImageSelect(this)">
<img class="adminImageSelection-preview object-contain" src="' . $selectedImage . '">
</div>
<div class="w-full flex flex-col">
' . self::renderHeadline($label) . '
<div class="adminImageSelection-text text-xs mb-3 -mt-2 break-all">
' . $setting['value'] . '
</div>
' . ($images !== '' ? '<div class="w-full mb-3 h-10 bg-brand-1 text-white flex items-center justify-center rounded-full" onclick="openAdminImageSelect(this)">' . $languageService->translate('choose_image') . '</div>' : '') . '
</div>
</div>
<div class="hidden group-[&.isOpen]:grid w-full h-full fixed left-0 top-0 z-50 place-items-center">
<div class="w-full h-full left-0 top-0 z-10 absolute bg-black/60 cursor-pointer" onclick="closeAdminImageSelect()"></div>
<div class="w-full max-h-3/4 max-w-2xl bg-white p-4 pt-2 rounded-sm relative z-20 flex flex-col overflow-hidden">
<div class="w-full flex items-center">
<h2 class="flex text-brand-1 font-bold">
' . $languageService->translate('choose_image') . '
</h2>
<div class="ml-auto flex items-center justify-center p-3 text-xl fa fa-close" onclick="closeAdminImageSelect()"></div>
</div>
<div class="flex w-full h-full flex-col overflow-y-auto">
<div class="grid grid-cols-3 gap-4">
' . $images . '
</div>
</div>
</div>
</div>
<input
type="input"
class="w-full h-10 border-2 border-solid border-gray-300 focus:border-brand-1 rounded-md px-3 mt-auto"
name="' . $setting['name'] . '"
value="' . $setting['value'] . '"
' . $attributes . '
/>
</div>
';
}
public static function renderFontSelect(array $setting, string $label): string
{
$languageService = LanguageService::getInstance();
$fonts = '';
$attributes = '';
if (isset($setting['attributes'])) {
foreach ($setting['attributes'] as $key => $prop) {
$attributes .= $key . '="' . $prop . '" ';
}
}
if (isset($setting['paths']) && is_array($setting['paths'])) {
$pathIndex = 0;
foreach ($setting['paths'] as $path) {
$fonts .= '
<div class="col-span-3">
<h2 class="font-bold">' . PathUtility::getPublicPath($path) . '</h2>
</div>
';
$fontClassName = 'font-' . $pathIndex;
try {
$files = FontUtility::getFontsFromPath($path, false);
$files = array_map(fn ($file): string => PathUtility::getPublicPath($file), $files);
if (count($files) === 0) {
$fonts .= '
<div class="col-span-3">
<p>' . $languageService->translate('error_path_noFonts') . '</p>
</div>
';
}
$fontIndex = 0;
foreach ($files as $name => $path) {
$fontClassName .= '-' . $fontIndex;
$imageAttributes = [
'onClick' => 'adminFontSelect(this, "' . $setting['name'] . '", "' . $fontClassName . '");',
'data-origin' => $path,
'title' => $name,
'class' => 'w-full h-full left-0 top-0 absolute object-contain cursor-pointer',
];
$fonts .= '<style>.' . $fontClassName . ' {font-family:"' . $name . '"}</style>';
$fonts .= '<div class="w-full relative h-0 pb-2/3">' . FontUtility::getFontPreviewImage(fontPath: $path, attributes: $imageAttributes) . '</div>';
$fontIndex++;
}
} catch (\Exception $e) {
$fonts .= '
<div class="col-span-3">
<p>' . $e->getMessage() . '</p>
</div>
';
}
$pathIndex++;
}
}
$selectedFont = $setting['value'];
if (str_contains($setting['value'], 'url(')) {
$selectedFont = substr($setting['value'], 4, -1);
}
if (str_contains($setting['value'], $_SERVER['DOCUMENT_ROOT'])) {
$selectedFont = substr($setting['value'], strlen($_SERVER['DOCUMENT_ROOT']));
}
return '
<div class="adminFontSelection group">
<div class="w-full flex items-start">
<div class="w-24 flex mb-3 mr-3 shrink-0 cursor-pointer" onclick="openAdminFontSelect(this)">
' . FontUtility::getFontPreviewImage(fontPath: $selectedFont, attributes: ['class' => 'adminFontSelection-preview object-contain']) . '
</div>
<div class="w-full flex flex-col">
' . self::renderHeadline($label) . '
<div class="adminFontSelection-text text-xs mb-3 -mt-2 break-all">
' . $setting['value'] . '
</div>
' . ($fonts !== '' ? '<div class="w-full mb-3 h-10 bg-brand-1 text-white flex items-center justify-center rounded-full" onclick="openAdminFontSelect(this)">' . $languageService->translate('choose_font') . '</div>' : '') . '
</div>
</div>
<div class="hidden group-[&.isOpen]:grid w-full h-full fixed left-0 top-0 z-50 place-items-center">
<div class="w-full h-full left-0 top-0 z-10 absolute bg-black/60 cursor-pointer" onclick="closeAdminFontSelect()"></div>
<div class="w-full max-h-3/4 max-w-2xl bg-white p-4 pt-2 rounded-sm relative z-20 flex flex-col overflow-hidden">
<div class="w-full flex items-center">
<h2 class="flex text-brand-1 font-bold">
' . $languageService->translate('choose_font') . '
</h2>
<div class="ml-auto flex items-center justify-center p-3 text-xl fa fa-close" onclick="closeAdminFontSelect()"></div>
</div>
<div class="flex w-full h-full flex-col overflow-y-auto">
<div class="grid grid-cols-3 gap-4">
' . $fonts . '
</div>
</div>
</div>
</div>
<input
type="input"
class="w-full h-10 border-2 border-solid border-gray-300 focus:border-brand-1 rounded-md px-3 mt-auto"
name="' . $setting['name'] . '"
value="' . $setting['value'] . '"
' . $attributes . '
/>
</div>
';
}
public static function renderVideoSelect(array $setting, string $label): string
{
$languageService = LanguageService::getInstance();
$videos = '';
if (isset($setting['paths']) && is_array($setting['paths'])) {
$pathIndex = 0;
foreach ($setting['paths'] as $path) {
$videos .= '
<div class="col-span-3">
<h2 class="font-bold">' . PathUtility::getPublicPath($path) . '</h2>
</div>
';
try {
$files = VideoUtility::getVideosFromPath($path, false);
$files = array_map(fn ($file): string => PathUtility::getPublicPath($file), $files);
if (count($files) === 0) {
$videos .= '
<div class="col-span-3">
<p>' . $languageService->translate('error_path_noVideos') . '</p>
</div>
';
}
foreach ($files as $file) {
$videoAttributes = [
'onClick' => 'adminVideoSelect(this, "' . $setting['name'] . '");',
'data-origin' => $file,
'title' => $file,
'class' => 'w-full h-full left-0 top-0 absolute object-contain cursor-pointer'
];
$videos .= '<div class="w-full relative h-0 pb-2/3">' . VideoUtility::getVideoPreview(videoPath: $file, attributes: $videoAttributes) . '</div>';
}
} catch (\Exception $e) {
$videos .= '
<div class="col-span-3">
<p>' . $e->getMessage() . '</p>
</div>
';
}
$pathIndex++;
}
}
$selectedVideo = $setting['value'];
if (str_contains($setting['value'], 'url(')) {
$selectedVideo = substr($setting['value'], 4, -1);
}
if (str_contains($setting['value'], $_SERVER['DOCUMENT_ROOT'])) {
$selectedVideo = substr($setting['value'], strlen($_SERVER['DOCUMENT_ROOT']));
}
return '
<div class="adminVideoSelection group">
<div class="w-full flex items-start">
<div class="w-24 flex mb-3 mr-3 shrink-0 cursor-pointer" onclick="openAdminVideoSelect(this)">
' . VideoUtility::getVideoPreview(videoPath: $selectedVideo, attributes: ['class' => 'adminVideoSelection-preview object-contain']) . '
</div>
<div class="w-full flex flex-col">
' . self::renderHeadline($label) . '
<div class="adminVideoSelection-text text-xs mb-3 -mt-2 break-all">
' . $setting['value'] . '
</div>
' . ($videos !== '' ? '<div class="w-full mb-3 h-10 bg-brand-1 text-white flex items-center justify-center rounded-full" onclick="openAdminVideoSelect(this)">' . $languageService->translate('choose_video') . '</div>' : '') . '
</div>
</div>
<div class="hidden group-[&.isOpen]:grid w-full h-full fixed left-0 top-0 z-50 place-items-center">
<div class="w-full h-full left-0 top-0 z-10 absolute bg-black/60 cursor-pointer" onclick="closeAdminVideoSelect()"></div>
<div class="w-full max-h-3/4 max-w-2xl bg-white p-4 pt-2 rounded-sm relative z-20 flex flex-col overflow-hidden">
<div class="w-full flex items-center">
<h2 class="flex text-brand-1 font-bold">
' . $languageService->translate('choose_video') . '
</h2>
<div class="ml-auto flex items-center justify-center p-3 text-xl fa fa-close" onclick="closeAdminVideoSelect()"></div>
</div>
<div class="flex w-full h-full flex-col overflow-y-auto">
<div class="grid grid-cols-3 gap-4">
' . $videos . '
</div>
</div>
</div>
</div>
<input
type="input"
class="w-full h-10 border-2 border-solid border-gray-300 focus:border-brand-1 rounded-md px-3 mt-auto"
name="' . $setting['name'] . '"
value="' . $setting['value'] . '"
/>
</div>
';
}
protected static function renderHeadline(string $label): string
{
$languageService = LanguageService::getInstance();
$tooltipClass = '
absolute z-10 hidden flex-col px-3 py-2 text-sm font-medium text-white transition-opacity duration-300 bg-gray-900 rounded-lg shadow-xs
mt-3
peer-hover:flex
';
return '
<div class="tooltip mb-3 relative">
<label class="peer text-black text-md font-bold">' . $languageService->translate($label) . '</label>
<span class="' . $tooltipClass . '">
<div class="absolute left-5 -top-[10px] h-0 w-0 border-x-8 border-x-transparent border-b-[10px] border-gray-900"></div>
' . $languageService->translate('manual:' . $label) . '
</span>
</div>
';
}
}