Skip to content
Merged

Dev #3568

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/HomeSlide.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App;

use Illuminate\Database\Eloquent\Model;
use Stevebauman\Purify\Facades\Purify;

class HomeSlide extends Model
{
Expand Down Expand Up @@ -94,6 +95,18 @@ public function button2TextForLocale(?string $locale = null): ?string
return $val === null || $val === '' ? null : (string) __($val);
}

/**
* Sanitize homepage slide description HTML, allowing only safe links.
*/
public static function sanitizeDescriptionHtml(string $html): string
{
if ($html === '') {
return '';
}

return (string) Purify::config('home_slide')->clean($html);
}

public function scopeActive($query)
{
return $query->where('active', true);
Expand Down
2 changes: 1 addition & 1 deletion app/Nova/HomeSlide.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public function fields(Request $request): array

Textarea::make('Description', 'description')
->nullable()
->help('Lang key (e.g. home.banner4_description) or plain text. Translated via resources/lang per locale.'),
->help('Lang key (e.g. home.banner4_description) or plain text. HTML links allowed, e.g. Check our <a href="https://codeweek.eu/dream-jobs-in-digital">Careers in Digital page</a>! Translated via resources/lang per locale.'),

Text::make('Primary button URL', 'url')->rules('required')->hideFromIndex(),
Text::make('Primary button label', 'button_text')
Expand Down
12 changes: 12 additions & 0 deletions config/purify.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@
'AutoFormat.RemoveEmpty' => false,
],

'home_slide' => [
'Core.Encoding' => 'utf-8',
'HTML.Doctype' => 'HTML 4.01 Transitional',
'HTML.Allowed' => 'a[href|target|rel]',
'HTML.ForbiddenElements' => '',
'CSS.AllowedProperties' => '',
'AutoFormat.AutoParagraph' => false,
'AutoFormat.RemoveEmpty' => false,
'Attr.AllowedFrameTargets' => ['_blank'],
'URI.AllowedSchemes' => ['http' => true, 'https' => true, 'mailto' => true],
],

],

/*
Expand Down
4 changes: 2 additions & 2 deletions resources/views/static/home.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ class="text-[#1C4DA1] text-[30px] md:text-[60px] leading-9 md:leading-[72px] fon
{{ __($activity['title']) }}
</h2>
<p
class="text-xl md:text-2xl leading-8 text-[#333E48] p-0 mb-4 max-md:max-w-full max-w-[525px]">
{{ strip_tags(__($activity['description'] ?? '')) }}
class="text-xl md:text-2xl leading-8 text-[#333E48] p-0 mb-4 max-md:max-w-full max-w-[525px] [&_a]:text-[#1C4DA1] [&_a]:font-semibold [&_a]:underline hover:[&_a]:opacity-80">
{!! \App\HomeSlide::sanitizeDescriptionHtml(__($activity['description'] ?? '')) !!}
</p>
<div class="flex flex-col space-y-4 md:flex-row md:space-x-4 md:space-y-0">
<a class="inline-block bg-primary hover:bg-hover-orange rounded-full py-4 px-6 md:px-10 font-semibold text-base w-full md:w-auto text-center text-[#20262C] transition-all duration-300"
Expand Down
Loading