-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathFrontend.php
More file actions
657 lines (561 loc) · 26.2 KB
/
Frontend.php
File metadata and controls
657 lines (561 loc) · 26.2 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
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
<?php
namespace FriendsOfRedaxo\ConsentManager;
use rex_addon;
use rex_article;
use rex_clang;
use rex_file;
use rex_fragment;
use rex_logger;
use rex_path;
use rex_request;
use rex_response;
use rex_url;
use function count;
use function function_exists;
use function in_array;
use function is_array;
use function is_string;
use const ENT_QUOTES;
use const JSON_UNESCAPED_SLASHES;
use const PHP_EOL;
/**
* @api
*/
class Frontend
{
/** @var array<array<string,mixed>> */
public array $cookiegroups = [];
/** @var array<array<string,mixed>> */
public array $cookies = [];
/** @var array<string,string> */
public array $texts = [];
public string $domainName = '';
/** @var array<string,mixed> */
public array $domainInfo = [];
/** @var array<string,int> */
public array $links = [];
/** @var array<string,string> */
public array $scripts = [];
/** @var array<string,string> */
public array $scriptsUnselect = [];
public string $boxClass = '';
/** @var array<int|string,mixed> */
public array $cache = [];
public string $version = '';
public string $cacheLogId = '';
public function __construct(int $forceWrite = 0)
{
if (1 === $forceWrite) {
Cache::forceWrite();
}
$this->cache = ConsentManager::getCache();
$this->cacheLogId = ConsentManager::getCacheLogId();
$this->version = ConsentManager::getVersion();
}
/**
* @api
*/
public static function getFragment(int $forceCache, int $forceReload, string $fragmentFilename): string
{
$fragment = new rex_fragment();
$fragment->setVar('forceCache', $forceCache);
$fragment->setVar('forceReload', $forceReload);
$fragment->setVar('cspNonce', rex_response::getNonce());
return $fragment->parse($fragmentFilename);
}
/**
* @param array<string, mixed> $additionalVars
* @api
*/
public static function getFragmentWithVars(int $forceCache, int $forceReload, string $fragmentFilename, array $additionalVars = []): string
{
$fragment = new rex_fragment();
$fragment->setVar('forceCache', $forceCache);
$fragment->setVar('forceReload', $forceReload);
$fragment->setVar('cspNonce', rex_response::getNonce());
// Zusätzliche Variablen setzen
foreach ($additionalVars as $key => $value) {
$fragment->setVar($key, $value);
}
return $fragment->parse($fragmentFilename);
}
/**
* @api
* @return void
*/
public function setDomain(string $domain)
{
// Domain immer in Kleinbuchstaben normalisieren für den Lookup
$domain = Utility::hostname();
$domains = ConsentManager::getDomains();
if (empty($domains)) {
return;
}
// Zuerst exakte Domain suchen
if (isset($domains[$domain])) {
$this->domainName = $domain;
} else {
// Dann HTTP_HOST versuchen (für Fälle mit Port oder Subdomain)
$httpHost = strtolower(rex_request::server('HTTP_HOST'));
if (isset($domains[$httpHost])) {
$this->domainName = $httpHost;
} else {
// Domain ohne Port versuchen
$httpHostNoPort = preg_replace('/:\d+$/', '', $httpHost);
if (isset($domains[$httpHostNoPort])) {
$this->domainName = $httpHostNoPort;
} else {
return;
}
}
}
// Zusätzliche Sicherheitsabfrage
if ('' === $this->domainName || !isset($domains[$this->domainName])) {
return;
}
$domainData = $domains[$this->domainName];
// Sicherstellen, dass Domain-Daten ein Array sind
if (!is_array($domainData)) {
return;
}
$this->domainInfo = $domainData;
$this->links['privacy_policy'] = $domainData['privacy_policy'] ?? 0;
$this->links['legal_notice'] = $domainData['legal_notice'] ?? 0;
$article = rex_article::getCurrentId();
$clang = rex_request::request('lang', 'integer', 0);
if (0 === $clang) {
$clang = rex_clang::getCurrent()->getId();
}
if (in_array($article, [(int) $this->links['privacy_policy'], (int) $this->links['legal_notice']], true)) {
$this->boxClass = 'consent_manager-initially-hidden';
}
if (isset($this->cache['cookies'][$clang]) && is_array($this->cache['cookies'][$clang])) {
foreach ($this->cache['cookies'][$clang] as $uid => $cookie) {
if (is_array($cookie) && '' === ($cookie['provider_link_privacy'] ?? '')) {
// Sicherstellen, dass das Array-Element existiert und veränderbar ist
if (isset($this->cache['cookies'][$clang][$uid]) && is_array($this->cache['cookies'][$clang][$uid])) {
$this->cache['cookies'][$clang][$uid]['provider_link_privacy'] = rex_getUrl($this->links['privacy_policy'], $clang);
}
}
}
}
if (isset($domainData['cookiegroups']) && is_array($domainData['cookiegroups'])) {
foreach ($domainData['cookiegroups'] as $uid) {
if (isset($this->cache['cookiegroups'][$clang][$uid])) {
$this->cookiegroups[$uid] = $this->cache['cookiegroups'][$clang][$uid];
}
}
}
foreach ($this->cookiegroups as $cookiegroup) {
if (isset($cookiegroup['cookie_uids'])) {
foreach ($cookiegroup['cookie_uids'] as $uid) {
if (isset($this->cache['cookies'][$clang][$uid])) {
$cookieData = $this->cache['cookies'][$clang][$uid];
$this->cookies[$uid] = $cookieData;
// Fallback zur Start-Sprache wenn Script-Felder leer sind
$script = $cookieData['script'] ?? '';
$scriptUnselect = $cookieData['script_unselect'] ?? '';
// Wenn aktuelle Sprache leer ist, versuche Fallback zur Start-Sprache
if ('' === trim($script) && $clang !== rex_clang::getStartId()) {
$startLangId = rex_clang::getStartId();
if (isset($this->cache['cookies'][$startLangId][$uid]['script'])) {
$script = $this->cache['cookies'][$startLangId][$uid]['script'];
}
}
if ('' === trim($scriptUnselect) && $clang !== rex_clang::getStartId()) {
$startLangId = rex_clang::getStartId();
if (isset($this->cache['cookies'][$startLangId][$uid]['script_unselect'])) {
$scriptUnselect = $this->cache['cookies'][$startLangId][$uid]['script_unselect'];
}
}
$this->scripts[$uid] = $script;
$this->scriptsUnselect[$uid] = $scriptUnselect;
}
}
}
$this->scripts = array_map(trim(...), $this->scripts);
$this->scripts = array_filter($this->scripts, strlen(...)); // @phpstan-ignore-line
$this->scriptsUnselect = array_map(trim(...), $this->scriptsUnselect);
$this->scriptsUnselect = array_filter($this->scriptsUnselect, strlen(...)); // @phpstan-ignore-line
}
if (isset($this->cache['texts'][$clang])) {
$this->texts = $this->cache['texts'][$clang];
}
}
/**
* @api
*/
public function outputJavascript(): never
{
$addon = rex_addon::get('consent_manager');
$clang = rex_request::request('lang', 'integer', 0);
if (0 === $clang) {
$clang = rex_clang::getCurrent()->getId();
}
rex_response::cleanOutputBuffers();
header_remove();
header('Content-Type: application/javascript; charset=utf-8');
// Use ETag based on version and timestamp for proper caching
$cacheVersion = rex_request::get('t', 'string', time());
$etag = md5($addon->getVersion() . '-' . $cacheVersion);
header('ETag: "' . $etag . '"');
header('Cache-Control: max-age=604800, public');
// Check if client has current version
$clientEtag = (string) rex_request::server('HTTP_IF_NONE_MATCH', 'string', '');
if (trim($clientEtag, '"') === $etag) {
http_response_code(304);
exit;
}
$boxtemplate = '';
ob_start();
echo self::getFragment(0, 0, self::getBoxFragmentName());
$boxtemplate = (string) ob_get_contents();
ob_end_clean();
if ('' === $boxtemplate) {
rex_logger::factory()->log('warning', 'Addon consent_manager: Keine Cookie-Gruppen / Cookies ausgewählt bzw. keine Domain zugewiesen! (' . Utility::hostname() . ')');
}
if (rex_addon::get('sprog')->isInstalled() && rex_addon::get('sprog')->isAvailable() && function_exists('sprogdown')) {
/** @phpstan-ignore-next-line */
$boxtemplate = sprogdown($boxtemplate, $clang);
}
$boxtemplate = str_replace("\r", '', $boxtemplate);
$boxtemplate = str_replace("\n", ' ', $boxtemplate);
echo '/* --- Parameters --- */' . PHP_EOL;
// Sanitize input parameters to prevent XSS
$cacheLogId = preg_replace('/[^a-zA-Z0-9_\-]/', '', rex_request::get('cid', 'string', ''));
$version = preg_replace('/[^0-9.]/', '', rex_request::get('v', 'string', ''));
$consent_manager_parameters = [
'initially_hidden' => 'true' === rex_request::get('i', 'string', 'false'),
'domain' => Utility::hostname(),
'consentid' => uniqid('', true),
'cachelogid' => $cacheLogId,
'version' => $version,
'fe_controller' => rex_url::frontend(),
'forcereload' => rex_request::get('r', 'int', 0),
'hidebodyscrollbar' => 'true' === rex_request::get('h', 'string', 'false'),
'cspNonce' => rex_response::getNonce(),
'cookieSameSite' => $addon->getConfig('cookie_samesite', 'Lax'),
'cookieSecure' => (bool) $addon->getConfig('cookie_secure', false),
'cookieName' => $addon->getConfig('cookie_name', 'consentmanager'),
];
echo 'var consent_manager_parameters = ' . json_encode($consent_manager_parameters, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT) . ';' . PHP_EOL . PHP_EOL;
echo '/* --- Consent-Manager Box Template lang=' . $clang . ' --- */' . PHP_EOL;
echo 'var consent_manager_box_template = ' . json_encode($boxtemplate, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT) . ';' . PHP_EOL . PHP_EOL;
$lifespan = $addon->getConfig('lifespan', 365);
if ('' === $lifespan) {
$lifespan = 365;
}
$content = 'var cmCookieExpires = ' . $lifespan . ';' . PHP_EOL . PHP_EOL;
$filenames = [];
$filenames[] = 'js.cookie.min.js';
$filenames[] = 'consent_manager_polyfills.js';
if (file_exists($addon->getAssetsPath('consent_manager_frontend.min.js'))) {
$filenames[] = 'consent_manager_frontend.min.js';
} else {
$filenames[] = 'consent_manager_frontend.js';
}
foreach ($filenames as $filename) {
$content .= '/* --- ' . rex_url::base('assets/addons/consent_manager/') . $filename . ' --- */' . PHP_EOL . rex_file::get(rex_path::addonAssets('consent_manager', $filename)) . PHP_EOL . PHP_EOL;
}
echo $content;
exit;
}
/**
* Minify CSS content.
* Removes comments, unnecessary whitespace, and optimizes syntax spacing.
* Preserves spaces around + and - operators in calc() expressions as required by CSS spec.
*/
private static function minifyCss(string $css): string
{
// Remove comments (using # as delimiter to avoid conflicts with ! in CSS)
$css = preg_replace('#/\*.*?\*/#s', '', $css);
// Remove whitespace and newlines
$css = preg_replace('/\s+/', ' ', $css);
// Remove spaces around CSS syntax characters
// Note: + and - are NOT included to preserve calc() expressions
$css = preg_replace('/\s*([{}:;,>~])\s*/', '$1', $css);
// Remove space after opening parenthesis and before closing parenthesis
$css = preg_replace('/\(\s+/', '(', $css);
$css = preg_replace('/\s+\)/', ')', $css);
// Remove trailing semicolons before closing braces
$css = preg_replace('/;+}/', '}', $css);
return trim($css);
}
/**
* @api
*/
public static function getFrontendCss(): string
{
$addon = rex_addon::get('consent_manager');
// Standard CSS-Datei
$_cssfilename = 'consent_manager_frontend.css';
// 1. Prüfen ob Domain-spezifisches Theme existiert
$domainTheme = null;
$hasDomainConfig = false;
if (is_string(rex_request::server('HTTP_HOST'))) {
$frontend = new self(0);
$frontend->setDomain(rex_request::server('HTTP_HOST'));
// Prüfen ob Domain konfiguriert ist
if ('' !== $frontend->domainName) {
$hasDomainConfig = true;
// Theme auslesen - auch wenn leer (= "Standard" gewählt)
if (isset($frontend->domainInfo['theme'])) {
$domainTheme = $frontend->domainInfo['theme'];
}
}
}
// 2. Domain-Theme hat Priorität (wenn Domain konfiguriert ist und Theme nicht leer)
if ($hasDomainConfig && null !== $domainTheme && '' !== $domainTheme) {
// Validiere Theme-Namen: Erlaube nur alphanumerisch, _, -, / und :
// Verhindere Path-Traversal durch ..
if (preg_match('/^[a-zA-Z0-9_\-\/:.]+$/', $domainTheme) && !str_contains($domainTheme, '..')) {
$_themecssfilename = str_replace('project:', 'project_', str_replace('.scss', '.css', $domainTheme));
// Normalisiere Pfad und prüfe dass er im Assets-Verzeichnis liegt
$fullPath = $addon->getAssetsPath($_themecssfilename);
$assetsPath = $addon->getAssetsPath();
if ('' !== $_themecssfilename && file_exists($fullPath) && str_starts_with(realpath($fullPath), realpath($assetsPath))) {
$_cssfilename = $_themecssfilename;
}
}
}
// 3. Fallback: Globales Theme (wenn kein Domain-Theme gesetzt oder "Standard" gewählt)
if ('consent_manager_frontend.css' === $_cssfilename && false !== $addon->getConfig('theme', false) && is_string($addon->getConfig('theme', false))) {
$_themecssfilename = $addon->getConfig('theme', false);
$_themecssfilename = str_replace('project:', 'project_', str_replace('.scss', '.css', $_themecssfilename));
if ('' !== $_themecssfilename && file_exists($addon->getAssetsPath($_themecssfilename))) {
$_cssfilename = $_themecssfilename;
}
}
$_csscontent = file_get_contents($addon->getAssetsPath($_cssfilename));
if (false === $_csscontent) {
return '';
}
// Minify CSS and prepend filename comment for debugging
return '/*' . $_cssfilename . '*/' . self::minifyCss($_csscontent);
}
/**
* Get nonce attribute for script tags using REDAXO's CSP nonce.
*
* @api
*/
public static function getNonceAttribute(): string
{
$nonce = rex_response::getNonce();
return ' nonce="' . htmlspecialchars($nonce, ENT_QUOTES, 'UTF-8') . '"';
}
/**
* Get CSS output for consent manager
* Alias for getFrontendCss() for consistency with Issue #282.
*
* @return string CSS content
* @api
*/
public static function getCSS(): string
{
return self::getFrontendCss();
}
/**
* Get JavaScript output for consent manager
* Returns complete JavaScript including parameters, box template and all required libraries.
*
* @api
*
* TODO: sollte man das JS nicht besser als Fragment bereitstellen ... das hier ist etwas unübersichtlich
*/
public static function getJS(): string
{
$addon = rex_addon::get('consent_manager');
$clang = rex_clang::getCurrentId();
// Get box template
$boxtemplate = '';
ob_start();
echo self::getFragment(0, 0, self::getBoxFragmentName());
$boxTemplateResult = ob_get_contents();
ob_end_clean();
// Ensure we have a string for further processing
if (false === $boxTemplateResult) {
$boxtemplate = '';
} else {
$boxtemplate = $boxTemplateResult;
}
if ('' === $boxtemplate) {
// TODO: Prüfen,ob die Log-Meldungen engl. sein sollte wie an anderen Stellen bzw. nach .lang übertragen werden
rex_logger::factory()->log('warning', 'Addon consent_manager: Keine Cookie-Gruppen / Cookies ausgewählt bzw. keine Domain zugewiesen! (' . Utility::hostname() . ')');
}
// Process with sprog if available
if (rex_addon::get('sprog')->isInstalled() && rex_addon::get('sprog')->isAvailable() && function_exists('sprogdown')) {
// @phpstan-ignore-next-line (sprogdown is optional dependency from sprog addon)
$sprogResult = sprogdown($boxtemplate, $clang);
$boxtemplate = is_string($sprogResult) ? $sprogResult : $boxtemplate;
}
$output = '';
// Parameters
$output .= '/* --- Parameters --- */' . PHP_EOL;
$consent_manager_parameters = [
'initially_hidden' => false,
'domain' => Utility::hostname(),
'consentid' => uniqid('', true),
'cachelogid' => '',
'version' => $addon->getVersion(),
'fe_controller' => rex_url::frontend(),
'forcereload' => 0,
'hidebodyscrollbar' => false,
'cspNonce' => rex_response::getNonce(),
'cookieSameSite' => $addon->getConfig('cookie_samesite', 'Lax'),
'cookieSecure' => (bool) $addon->getConfig('cookie_secure', false),
'cookieName' => $addon->getConfig('cookie_name', 'consentmanager'),
];
$output .= 'var consent_manager_parameters = ' . json_encode($consent_manager_parameters, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT) . ';' . PHP_EOL . PHP_EOL;
// Box template
$output .= '/* --- Consent-Manager Box Template lang=' . $clang . ' --- */' . PHP_EOL;
$output .= 'var consent_manager_box_template = ' . json_encode($boxtemplate, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT) . ';' . PHP_EOL . PHP_EOL;
// Cookie expiration
$lifespan = $addon->getConfig('lifespan', 365);
if ('' === $lifespan) {
$lifespan = 365;
}
$output .= 'var cmCookieExpires = ' . $lifespan . ';' . PHP_EOL . PHP_EOL;
// JavaScript files
$filenames = [];
$filenames[] = 'js.cookie.min.js';
$filenames[] = 'consent_manager_polyfills.js';
if (file_exists($addon->getAssetsPath('consent_manager_frontend.min.js'))) {
$filenames[] = 'consent_manager_frontend.min.js';
} else {
$filenames[] = 'consent_manager_frontend.js';
}
foreach ($filenames as $filename) {
$output .= '/* --- ' . rex_url::base('assets/addons/consent_manager/') . $filename . ' --- */' . PHP_EOL;
$output .= rex_file::get(rex_path::addonAssets('consent_manager', $filename)) . PHP_EOL . PHP_EOL;
}
return $output;
}
/**
* Get HTML output for consent manager box
* Returns only the box HTML without CSS or JavaScript.
*
* @api
*/
public static function getBox(): string
{
return self::getFragment(0, 0, self::getBoxFragmentName());
}
/**
* Get completing logic for selecting the correct box fragment.
*
* @return string
* @api
*/
public static function getBoxFragmentName(): string
{
$frameworkMode = rex_addon::get('consent_manager')->getConfig('css_framework_mode', '');
if ('' !== $frameworkMode && in_array($frameworkMode, ['uikit3', 'bootstrap5', 'tailwind', 'bulma'], true)) {
return 'ConsentManager/box_' . $frameworkMode . '.php';
}
return 'ConsentManager/box.php';
}
/**
* Get formatted cookie list for privacy policy pages.
* Returns HTML table or definition list of all cookies used on the domain.
*
* @param string $format 'table' for HTML table, 'dl' for definition list
* @param string|null $domainName Optional specific domain, null for current domain
* @return string HTML output
* @api
*/
public static function getCookieList(string $format = 'table', ?string $domainName = null): string
{
$consent = new self(0);
if (null === $domainName) {
// Aktuelle Domain verwenden
if (is_string(rex_request::server('HTTP_HOST'))) {
$consent->setDomain(rex_request::server('HTTP_HOST'));
}
} else {
// Spezifische Domain verwenden
$consent->setDomain($domainName);
}
if (0 === count($consent->cookiegroups)) {
return '<div class="alert alert-info"><i class="fa fa-info-circle"></i> Keine Cookie-Informationen verfügbar.</div>';
}
$clang = rex_clang::getCurrentId();
$output = '';
if ('dl' === $format) {
// Definition List Format
$output .= '<dl class="consent-manager-cookie-list">' . PHP_EOL;
foreach ($consent->cookiegroups as $group) {
if (!isset($group['cookie_uids']) || 0 === count($group['cookie_uids'])) {
continue;
}
$output .= '<dt class="consent-group-name"><strong>' . rex_escape($group['name']) . '</strong></dt>' . PHP_EOL;
$output .= '<dd class="consent-group-description">' . $group['description'] . '</dd>' . PHP_EOL;
foreach ($group['cookie_uids'] as $cookieUid) {
if (!isset($consent->cookies[$cookieUid])) {
continue;
}
$cookie = $consent->cookies[$cookieUid];
if (isset($cookie['definition']) && is_array($cookie['definition'])) {
foreach ($cookie['definition'] as $def) {
$output .= '<dt class="consent-cookie-name">' . rex_escape($def['cookie_name'] ?? '') . '</dt>' . PHP_EOL;
$output .= '<dd class="consent-cookie-details">' . PHP_EOL;
if ('' !== ($cookie['service_name'] ?? '')) {
$output .= '<strong>Service:</strong> ' . rex_escape($cookie['service_name']) . '<br>' . PHP_EOL;
}
if ('' !== ($def['cookie_purpose'] ?? '')) {
$output .= '<strong>Zweck:</strong> ' . rex_escape($def['cookie_purpose']) . '<br>' . PHP_EOL;
}
if ('' !== ($def['cookie_lifetime'] ?? '')) {
$output .= '<strong>Laufzeit:</strong> ' . rex_escape($def['cookie_lifetime']) . '<br>' . PHP_EOL;
}
if ('' !== ($cookie['provider'] ?? '')) {
$output .= '<strong>Anbieter:</strong> ' . rex_escape($cookie['provider']) . PHP_EOL;
}
$output .= '</dd>' . PHP_EOL;
}
}
}
}
$output .= '</dl>' . PHP_EOL;
} else {
// Table Format (default)
$output .= '<table class="consent-manager-cookie-list table table-striped">' . PHP_EOL;
$output .= '<thead>' . PHP_EOL;
$output .= '<tr>' . PHP_EOL;
$output .= '<th>Cookie-Name</th>' . PHP_EOL;
$output .= '<th>Service</th>' . PHP_EOL;
$output .= '<th>Zweck</th>' . PHP_EOL;
$output .= '<th>Laufzeit</th>' . PHP_EOL;
$output .= '<th>Anbieter</th>' . PHP_EOL;
$output .= '<th>Kategorie</th>' . PHP_EOL;
$output .= '</tr>' . PHP_EOL;
$output .= '</thead>' . PHP_EOL;
$output .= '<tbody>' . PHP_EOL;
foreach ($consent->cookiegroups as $group) {
if (!isset($group['cookie_uids']) || 0 === count($group['cookie_uids'])) {
continue;
}
foreach ($group['cookie_uids'] as $cookieUid) {
if (!isset($consent->cookies[$cookieUid])) {
continue;
}
$cookie = $consent->cookies[$cookieUid];
if (isset($cookie['definition']) && is_array($cookie['definition'])) {
foreach ($cookie['definition'] as $def) {
$output .= '<tr>' . PHP_EOL;
$output .= '<td>' . rex_escape($def['cookie_name'] ?? '') . '</td>' . PHP_EOL;
$output .= '<td>' . rex_escape($cookie['service_name'] ?? '') . '</td>' . PHP_EOL;
$output .= '<td>' . rex_escape($def['cookie_purpose'] ?? '') . '</td>' . PHP_EOL;
$output .= '<td>' . rex_escape($def['cookie_lifetime'] ?? '') . '</td>' . PHP_EOL;
$output .= '<td>' . rex_escape($cookie['provider'] ?? '') . '</td>' . PHP_EOL;
$output .= '<td>' . rex_escape($group['name']) . '</td>' . PHP_EOL;
$output .= '</tr>' . PHP_EOL;
}
}
}
}
$output .= '</tbody>' . PHP_EOL;
$output .= '</table>' . PHP_EOL;
}
return $output;
}
}