From ac6daad444444d2dd6fa46a1f980691b1eec86c5 Mon Sep 17 00:00:00 2001 From: Julian Prieber Date: Tue, 15 Oct 2024 12:39:10 +0200 Subject: [PATCH] Add validation to blocks --- blocks/email/handler.php | 11 ++++++++++- blocks/heading/handler.php | 13 ++++++++++--- blocks/link/handler.php | 10 +++++++++- blocks/spacer/handler.php | 10 +++++++++- blocks/telephone/handler.php | 11 ++++++++++- blocks/text/handler.php | 11 ++++++++++- blocks/vcard/handler.php | 5 ++++- 7 files changed, 62 insertions(+), 9 deletions(-) diff --git a/blocks/email/handler.php b/blocks/email/handler.php index e3c1fbc9..d94a6904 100644 --- a/blocks/email/handler.php +++ b/blocks/email/handler.php @@ -8,6 +8,15 @@ * @return array The prepared link data. */ function handleLinkType($request, $linkType) { + + $rules = [ + 'link' => [ + 'required', + 'string', + 'max:255', + ], + ]; + // Prepare the link data $linkData = [ 'title' => $request->title, @@ -15,5 +24,5 @@ function handleLinkType($request, $linkType) { 'link' => $request->link, ]; - return $linkData; + return ['rules' => $rules, 'linkData' => $linkData]; } \ No newline at end of file diff --git a/blocks/heading/handler.php b/blocks/heading/handler.php index ecfa2a0a..97b6f6c0 100644 --- a/blocks/heading/handler.php +++ b/blocks/heading/handler.php @@ -8,13 +8,20 @@ * @return array The prepared link data. */ function handleLinkType($request, $linkType) { + + $rules = [ + 'title' => [ + 'required', + 'string', + 'max:255', + ], + ]; + // Prepare the link data $linkData = [ 'title' => $request->title, 'button_id' => "42", - 'var1' => "1", - 'var2' => "1", ]; - return $linkData; + return ['rules' => $rules, 'linkData' => $linkData]; } \ No newline at end of file diff --git a/blocks/link/handler.php b/blocks/link/handler.php index 881b221a..f3b13d14 100644 --- a/blocks/link/handler.php +++ b/blocks/link/handler.php @@ -9,6 +9,14 @@ */ function handleLinkType($request, $linkType) { + $rules = [ + 'title' => [ + 'required', + 'string', + 'max:255', + ], + ]; + if ($request->GetSiteIcon == "1") { $buttonID = "2"; } else { @@ -21,5 +29,5 @@ function handleLinkType($request, $linkType) { 'button_id' => $buttonID, ]; - return $linkData; + return ['rules' => $rules, 'linkData' => $linkData]; } \ No newline at end of file diff --git a/blocks/spacer/handler.php b/blocks/spacer/handler.php index b8e29aa7..063ba4f2 100644 --- a/blocks/spacer/handler.php +++ b/blocks/spacer/handler.php @@ -8,11 +8,19 @@ * @return array The prepared link data. */ function handleLinkType($request, $linkType) { + + $rules = [ + 'height' => [ + 'required', + 'max:255', + ], + ]; + // Prepare the link data $linkData = [ 'title' => $request->height ?? null, 'button_id' => "43", ]; - return $linkData; + return ['rules' => $rules, 'linkData' => $linkData]; } \ No newline at end of file diff --git a/blocks/telephone/handler.php b/blocks/telephone/handler.php index 4a8c416c..d0030ba5 100644 --- a/blocks/telephone/handler.php +++ b/blocks/telephone/handler.php @@ -8,11 +8,20 @@ * @return array The prepared link data. */ function handleLinkType($request, $linkType) { + + $rules = [ + 'link' => [ + 'required', + 'max:255', + ], + ]; + // Prepare the link data $linkData = [ 'title' => $request->title, 'button_id' => "44", + 'link' => $request->link, ]; - return $linkData; + return ['rules' => $rules, 'linkData' => $linkData]; } \ No newline at end of file diff --git a/blocks/text/handler.php b/blocks/text/handler.php index 73bf9673..4d503c6f 100644 --- a/blocks/text/handler.php +++ b/blocks/text/handler.php @@ -8,6 +8,15 @@ * @return array The prepared link data. */ function handleLinkType($request, $linkType) { + + $rules = [ + 'text' => [ + 'required', + 'string', + 'max:5000', + ], + ]; + // Sanitize the text input $sanitizedText = $request->text; $sanitizedText = strip_tags($sanitizedText, '