Rename all mini acf , and nutrition page inputype text to html field name to apply html saznitizer on these fileds only with route middleware

This commit is contained in:
Jérémy Munsch 2021-10-04 17:30:07 +02:00
parent c6b7500f19
commit 7f6a9cab8d
No known key found for this signature in database
GPG key ID: 55196BEE445F6049
11 changed files with 58 additions and 32 deletions

View file

@ -216,7 +216,7 @@ class UpdateMiniAcfRequest extends FormRequest
private function handleText(string $inputKey): array
{
return ["$inputKey.value" => 'required|string|min:15'];
return ["$inputKey.html" => 'required|string|min:15'];
}
private function handleString(string $inputKey): array

View file

@ -54,7 +54,7 @@ class NutritionPage extends Model
'content' => [
'label' => 'Contenu',
'inputType' => InputType::text(),
'value' => ''
'html' => ''
],
'side' => [
'label' => 'Orientation de l\'image (gauche ou droite)',
@ -86,7 +86,7 @@ class NutritionPage extends Model
'content' => [
'label' => 'Contenu',
'inputType' => InputType::text(),
'value' => ''
'html' => ''
],
'labels' => [
'label' => 'Labels avec titre',
@ -113,7 +113,7 @@ class NutritionPage extends Model
'content' => [
'label' => 'Contenu',
'inputType' => InputType::text(),
'value' => ''
'html' => ''
],
'link' => [
'label' => 'Lien en bas du bloc',
@ -148,7 +148,7 @@ class NutritionPage extends Model
'content' => [
'label' => 'Contenu',
'inputType' => InputType::text(),
'value' => ''
'html' => ''
],
'dropdownArray' => [
'label' => 'Dropdowns',
@ -170,7 +170,7 @@ class NutritionPage extends Model
'content' => [
'label' => 'Contenu',
'inputType' => InputType::text(),
'value' => ''
'html' => ''
]
]
],

View file

@ -62,7 +62,7 @@ trait MiniAcfModel
{
return [
'title' => '',
'content' => ''
'html' => ''
];
}

View file

@ -60,7 +60,7 @@ class CreateNutritionPagesTable extends Migration
'value' => $faker->sentence(7)
],
'content' => [
'value' => $faker->text(620)
'html' => $faker->text(620)
],
'side' => [
// image à gauche
@ -73,7 +73,7 @@ class CreateNutritionPagesTable extends Migration
for ($i = 0; $i < $max; $i++) {
$out[] = [
'title' => $faker->sentence(8),
'content' =>
'html' =>
// phpcs:ignore Generic.Files.LineLength.TooLong
'<a href="#">En savoir + sur chenilles à pattes de poulets</a>&nbsp;'
. $faker->text(620)
@ -101,7 +101,7 @@ class CreateNutritionPagesTable extends Migration
'value' => $faker->sentence(9)
],
'content' => [
'value' => $faker->text(600)
'html' => $faker->text(600)
],
'side' => [
// image à droite
@ -114,7 +114,7 @@ class CreateNutritionPagesTable extends Migration
for ($i = 0; $i < $max; $i++) {
$out[] = [
'title' => $faker->sentence(8),
'content' =>
'html' =>
// phpcs:ignore Generic.Files.LineLength.TooLong
'<a href="#">En savoir + sur chenilles à pattes de poulets</a>&nbsp;'
. $faker->text(620)
@ -142,7 +142,7 @@ class CreateNutritionPagesTable extends Migration
'value' => $faker->sentence(9)
],
'content' => [
'value' => $faker->text(600)
'html' => $faker->text(600)
],
'link' => [
'status' => false,
@ -173,7 +173,7 @@ class CreateNutritionPagesTable extends Migration
'value' => $faker->sentence(9)
],
'content' => [
'value' => $faker->text(750)
'html' => $faker->text(750)
],
'dropdownArray' => [
'value' => (function () use ($faker) {
@ -182,7 +182,7 @@ class CreateNutritionPagesTable extends Migration
for ($i = 0; $i < $max; $i++) {
$out[] = [
'title' => $faker->sentence(8),
'content' =>
'html' =>
// phpcs:ignore Generic.Files.LineLength.TooLong
'<a href="#">En savoir + sur chenilles à pattes de poulets</a>&nbsp;'
. $faker->text(620)
@ -223,7 +223,7 @@ class CreateNutritionPagesTable extends Migration
'value' => $faker->sentence(7)
],
'content' => [
'value' => $faker->text(620)
'html' => $faker->text(620)
],
'side' => [
// image à droite
@ -236,7 +236,7 @@ class CreateNutritionPagesTable extends Migration
for ($i = 0; $i < $max; $i++) {
$out[] = [
'title' => $faker->sentence(8),
'content' =>
'html' =>
// phpcs:ignore Generic.Files.LineLength.TooLong
'<a href="#">En savoir + sur chenilles à pattes de poulets</a>&nbsp;'
. $faker->text(620)
@ -264,7 +264,7 @@ class CreateNutritionPagesTable extends Migration
'value' => $faker->sentence(7)
],
'content' => [
'value' => $faker->text(620)
'html' => $faker->text(620)
],
'labels' => [
'value' => (function () use ($faker) {
@ -298,7 +298,7 @@ class CreateNutritionPagesTable extends Migration
'value' => $faker->sentence(9)
],
'content' => [
'value' => $faker->text(600)
'html' => $faker->text(600)
],
'link' => [
'status' => true,
@ -325,7 +325,7 @@ class CreateNutritionPagesTable extends Migration
))
],
'content' => [
'value' => $faker->text(600)
'html' => $faker->text(600)
]
]
]

View file

@ -9,12 +9,12 @@ $o = $o ?? 'X';
<label for="{{ $i.$k }}_title_{{ ($tmpl ? 'X' : $o) }}" data-count="{{ $o }}"><small>{{ __('Titre') }}*</small></label>
<input id="{{ $i.$k }}_title_{{ ($tmpl ? 'X' : $o) }}" type="text" class="form-control" name="content[{{$i}}][content][{{$k}}][value][{{ ($tmpl ? 'X' : $o) }}][title]" placeholder="Titre" value="{{ old("content.$i.content.$k.value.$o.title") ?? (!$tmpl ? ($dropdown['title'] ?? '') : '') }}">
<br>
<label for="{{ $i.$k }}_content_{{ ($tmpl ? 'X' : $o) }}"><small>{{ __('Contenu') }}*</small></label>
<label for="{{ $i.$k }}_html_{{ ($tmpl ? 'X' : $o) }}"><small>{{ __('Contenu') }}*</small></label>
<custom-ckeditor
id="{{ $i.$k }}_content_{{ ($tmpl ? 'X' : $o) }}"
id="{{ $i.$k }}_html_{{ ($tmpl ? 'X' : $o) }}"
class="CKEDITOR"
name="content[{{$i}}][content][{{$k}}][value][{{ ($tmpl ? 'X' : $o) }}][content]"
dbtext="{{ old("content.$i.content.$k.value.$o.content") ?? (!$tmpl ? ($dropdown['content'] ?? '') : '') }}"></custom-ckeditor>
name="content[{{$i}}][content][{{$k}}][value][{{ ($tmpl ? 'X' : $o) }}][html]"
dbtext="{{ old("content.$i.content.$k.value.$o.html") ?? (!$tmpl ? ($dropdown['html'] ?? '') : '') }}"></custom-ckeditor>
</div>
</div>
@ -70,7 +70,7 @@ if(!__MINIACF.dropdown) {
$(el).prev().attr('for', xfor.join('_'));
}
$(el).attr('name', $(el).attr('name')
.replace(/(?:\[(X|[0-9]*)\])\[(title|content)\]$/, '[' + (c-1) + '][$2]'));
.replace(/(?:\[(X|[0-9]*)\])\[(title|html)\]$/, '[' + (c-1) + '][$2]'));
console.log(el)
});
};

View file

@ -19,8 +19,8 @@
<div class="form-group vueComponent">
<label class="col-form-label">{{ $input['label'] }}*</label>
<custom-ckeditor
name="content[{{$i}}][content][{{$k}}][value]"
dbtext="{{ old("content.$i.content.$k.value") ?? $input['value'] ?? '' }}"></custom-ckeditor>
name="content[{{$i}}][content][{{$k}}][html]"
dbtext="{{ old("content.$i.content.$k.html") ?? $input['html'] ?? '' }}"></custom-ckeditor>
</div>
@break
@case(InputType::boolean()->value)
@ -128,8 +128,34 @@
</div>
</div>
@break
@case(InputType::miniblocArray()->value)
<div class="card">
<div class="card-header">
<h6>{{ __('Minibloc') }}</h6>
</div>
<div class="card-body">
@include('bo.modules.mini-acf.minibloc-input', [
'i' => $i,
'k' => $k,
'tmpl' => true,
])
@foreach($input['value'] as $o => $minibloc)
@include('bo.modules.mini-acf.minibloc-input', [
'i' => $i,
'k' => $k,
'o' => $o,
'tmpl' => false,
'minibloc' => $minibloc,
])
@endforeach
<div class="row d-flex justify-content-end">
<button class="btn btn-primary miniblocAdd">{{ __('Ajouter') }}</button>
</div>
</div>
</div>
@break
@default
@dump('unknown input type')
@dump('unknown input type',$input['inputType'])
@endswitch
@endforeach
</div>

View file

@ -3,7 +3,7 @@
<div class="content">
<h2 class="title">{!! clean($bloc['content']['title']['value']) !!}</h2>
<div class="text ck-content">
{!! clean($bloc['content']['content']['value']) !!}
{!! clean($bloc['content']['content']['html']) !!}
</div>
@if(count($bloc['content']['dropdownArray']['value']))
<div class="dropdowns">

View file

@ -3,7 +3,7 @@
<div class="content">
<h2 class="title">{!! clean($bloc['content']['title']['value']) !!}</h2>
<div class="text ck-content">
{!! clean($bloc['content']['content']['value']) !!}
{!! clean($bloc['content']['content']['html']) !!}
</div>
@if($bloc['content']['link']['status'])
<div class="link">

View file

@ -4,7 +4,7 @@
<div class="content">
<h2 class="title">{!! clean($bloc['content']['title']['value']) !!}</h2>
<div class="text ck-content">
{!! clean($bloc['content']['content']['value']) !!}
{!! clean($bloc['content']['content']['html']) !!}
</div>
@if(count($bloc['content']['dropdownArray']['value']))
<div class="dropdowns">

View file

@ -2,5 +2,5 @@
@php $rId = Str::uuid(); @endphp
<input id="{{$rId}}" type="checkbox" @if(isset($openned) and $openned)checked @endif>
<label for="{{$rId}}" class="title"><h3>{!! clean($dropdown['title']) !!}</h3></label>
<div class="ck-content">{!! clean($dropdown['content']) !!}</div>
<div class="ck-content">{!! clean($dropdown['html']) !!}</div>
</div>

View file

@ -87,7 +87,7 @@ Route::prefix('bo')
Route::resource('tags', TagController::class)->except(['show']);
Route::resource('nutrition-page', NutritionPageController::class)->except(['show', 'create', 'store', 'destroy'])
->withoutMiddleware('xss')
->middleware('xss:headerContent,content,title,value,text,bigText');
->middleware('xss:headerContent,html');
});
Route::get('/', [DashboardController::class, 'index'])->name('dashboard');