Fix SimpleTemplate TypeError with array handling

- Fix htmlspecialchars() receiving arrays instead of strings
- Add proper type checking for string, array, and other types
- Convert arrays to JSON for safe template rendering
- Remove unused German and French language files
This commit is contained in:
2025-11-22 21:32:38 +01:00
parent 4b9551d7e4
commit 434334c810
3 changed files with 10 additions and 548 deletions

View File

@@ -103,11 +103,19 @@ class SimpleTemplate {
foreach ($this->data as $key => $value) {
// Handle triple braces for unescaped HTML content
if (strpos($template, '{{{' . $key . '}}}') !== false) {
$template = str_replace('{{{' . $key . '}}}', $value, $template);
$template = str_replace('{{{' . $key . '}}}', is_string($value) ? $value : print_r($value, true), $template);
}
// Handle double braces for escaped content
elseif (strpos($template, '{{' . $key . '}}') !== false) {
$template = str_replace('{{' . $key . '}}', htmlspecialchars($value, ENT_QUOTES, 'UTF-8'), $template);
if (is_string($value)) {
$template = str_replace('{{' . $key . '}}', htmlspecialchars($value, ENT_QUOTES, 'UTF-8'), $template);
} elseif (is_array($value)) {
// For arrays, convert to JSON string for display
$template = str_replace('{{' . $key . '}}', htmlspecialchars(json_encode($value), ENT_QUOTES, 'UTF-8'), $template);
} else {
// Convert other types to string
$template = str_replace('{{' . $key . '}}', htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'), $template);
}
}
}
return $template;