Sanitize survey frontend and PDF output

This commit is contained in:
Jürgen Mummert
2026-05-24 17:53:53 +02:00
parent 64fc578d4c
commit 6eec9ec537
6 changed files with 84 additions and 41 deletions
+37
View File
@@ -197,9 +197,46 @@ final class SurveyResultsPdfService
'completedSubmissionCount' => $completedSubmissionCount,
'questionResults' => $questionResults,
'exportedAt' => (new \DateTimeImmutable())->format('d.m.Y H:i'),
'documentTitle' => $this->buildDocumentTitle((string) $survey->title),
'fontFaceCss' => $this->buildEmbeddedFontFaceCss(),
]);
}
private function buildDocumentTitle(string $surveyTitle): string
{
$title = trim(strip_tags($surveyTitle));
return '' !== $title ? $title.' Ergebnisse' : 'Umfrage Ergebnisse';
}
private function buildEmbeddedFontFaceCss(): string
{
$fontDefinitions = [
['family' => 'PT Sans Narrow', 'weight' => 400, 'path' => __DIR__.'/../../public/fonts/PTSansNarrow-Regular.woff2'],
['family' => 'PT Sans Narrow', 'weight' => 700, 'path' => __DIR__.'/../../public/fonts/PTSansNarrow-Bold.woff2'],
['family' => 'Blogger Sans', 'weight' => 500, 'path' => __DIR__.'/../../public/fonts/Blogger Sans-Medium.woff2'],
];
$rules = [];
foreach ($fontDefinitions as $fontDefinition) {
$fontContent = @file_get_contents($fontDefinition['path']);
if (false === $fontContent) {
continue;
}
$rules[] = sprintf(
'@font-face { font-family: "%s"; src: url("data:font/woff2;base64,%s") format("woff2"); font-weight: %d; font-style: normal; font-display: swap; }',
$fontDefinition['family'],
base64_encode($fontContent),
$fontDefinition['weight'],
);
}
return implode("\n", $rules);
}
/**
* @param array<string, mixed> $questionResult
*/