diff --git a/app/Http/Middleware/SecureHeaders.php b/app/Http/Middleware/SecureHeaders.php index 48b78a4..0b55b3d 100644 --- a/app/Http/Middleware/SecureHeaders.php +++ b/app/Http/Middleware/SecureHeaders.php @@ -68,6 +68,7 @@ class SecureHeaders 'https://recaptcha.google.com/recaptcha/', 'https://www.google.com/maps/', 'https://www.youtube.com', + 'https://player.vimeo.com', ]) . ';', "font-src 'self' data: " . \implode(' ', [ // * VITE DEV diff --git a/app/Http/Requests/Bo/Homepage/UpdateHomepageRequest.php b/app/Http/Requests/Bo/Homepage/UpdateHomepageRequest.php index daa7f4a..f192477 100644 --- a/app/Http/Requests/Bo/Homepage/UpdateHomepageRequest.php +++ b/app/Http/Requests/Bo/Homepage/UpdateHomepageRequest.php @@ -2,6 +2,7 @@ namespace App\Http\Requests\Bo\Homepage; +use App\Rules\IsValidVimeoId; use App\Rules\IsValidYoutubeId; use App\Traits\Requests\HasPicture; use Illuminate\Foundation\Http\FormRequest; @@ -49,9 +50,14 @@ class UpdateHomepageRequest extends FormRequest 'presentation_title' => 'required|string|between:3,255', 'presentation_content' => 'required|string', 'display_video' => 'present|boolean', - 'youtube_video_id' => [ + 'video_id' => [ 'nullable', 'required_if:display_video,true', - new IsValidYoutubeId() + function (string $attribute, mixed $value, \Closure $fail) { + if (!IsValidYoutubeId::validates($value) and !IsValidVimeoId::validates($value)) { + (new IsValidYoutubeId())->validate($attribute, $value, $fail); + (new IsValidVimeoId())->validate($attribute, $value, $fail); + } + } ], ]; return \array_merge( @@ -68,6 +74,7 @@ class UpdateHomepageRequest extends FormRequest public function attributes(): array { return [ + 'video_id' => trans('validation.custom.video_id'), 'title_part1' => trans('validation.custom.title_part1'), 'title_part2' => trans('validation.custom.title_part2'), 'title_part3' => trans('validation.custom.title_part3'), diff --git a/app/Http/Requests/Bo/Joinuspage/UpdateJoinuspageRequest.php b/app/Http/Requests/Bo/Joinuspage/UpdateJoinuspageRequest.php index 8a23506..a425205 100644 --- a/app/Http/Requests/Bo/Joinuspage/UpdateJoinuspageRequest.php +++ b/app/Http/Requests/Bo/Joinuspage/UpdateJoinuspageRequest.php @@ -2,6 +2,8 @@ namespace App\Http\Requests\Bo\Joinuspage; +use App\Rules\IsValidVimeoId; +use App\Rules\IsValidYoutubeId; use Illuminate\Foundation\Http\FormRequest; class UpdateJoinuspageRequest extends FormRequest @@ -24,7 +26,15 @@ class UpdateJoinuspageRequest extends FormRequest public function rules() { return [ - 'video_id' => 'required|string|regex:%([^"&?\/\s]{11})%i', + 'video_id' => [ + 'required', 'string', + function (string $attribute, mixed $value, \Closure $fail) { + if (!IsValidYoutubeId::validates($value) and !IsValidVimeoId::validates($value)) { + (new IsValidYoutubeId())->validate($attribute, $value, $fail); + (new IsValidVimeoId())->validate($attribute, $value, $fail); + } + } + ], ]; } diff --git a/app/Http/Requests/Bo/UpdateMiniCrudRequest.php b/app/Http/Requests/Bo/UpdateMiniCrudRequest.php deleted file mode 100644 index 19b187a..0000000 --- a/app/Http/Requests/Bo/UpdateMiniCrudRequest.php +++ /dev/null @@ -1,229 +0,0 @@ -check(); - } - - /** - * Get the validation rules that apply to the request. - * - * @return array - * @phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh - * @phpcs:disable Generic.Metrics.NestingLevel.TooHigh - */ - public function rules() - { - // phpcs:enable - $rules = []; - foreach ($this->{$this->modelName}->data as $iptName => $input) { - $input = \json_decode(\json_encode($input), true); - switch ($input['inputType']) { - case InputType::number->value: - $rules = array_merge($rules, [ - "data.$iptName.value" => $this->compileValidate('required|numeric', $input) - ]); - break; - case InputType::videoYoutube->value: - $rules = array_merge($rules, [ - "data.$iptName.value" => $this->compileValidate('regex:%([^"&?\/\s]{11})%i', $input) - ]); - break; - case InputType::videoVimeo->value: - $rules = array_merge($rules, [ - "data.$iptName.value" => $this->compileValidate('regex:%([0-9]{8,10})%i', $input) - ]); - break; - case InputType::video->value: - $rules = array_merge($rules, [ - "data.$iptName.value" => $this->compileValidate([ - 'regex:%([0-9]{8,10}|[^"&?\/\s]{11})%i' - ], $input) - ]); - break; - case InputType::string->value: - $rules = array_merge($rules, [ - "data.$iptName.value" => $this->compileValidate('required|string|min:3', $input) - ]); - break; - case InputType::text->value: - $mergeRules = $this->compileValidate('required|string|min:15', $input); - $mergeRules = collect($mergeRules) - ->map(function ($rule) { - if (\strpos($rule, 'max:') !== false) { - $max = \intval(str_replace('max:', '', $rule)); - return function ($attribute, $value, $fail) use ($max) { - if (\strlen(\strip_tags($value)) > $max) { - $fail("$attribute ne doit pas excéder $max caractères"); - } - }; - } - return $rule; - }); - $rules = array_merge($rules, [ - "data.$iptName.value" => $mergeRules - ]); - break; - case InputType::image->value: - $required = $this->isUpdate() ? 'sometimes' : 'required'; - - $ipt = $this->data[$iptName]; - $max = isset($ipt['dimensionsMax']); - $dim = \is_string($input['dimensions']) ? collect(explode( - ',', - (isset($ipt['dimensionsMax']) and is_string($ipt['dimensionsMax'])) ? - $ipt['dimensionsMax'] : $input['dimensions'] - ))->mapWithKeys(function ($v) { - $v = explode(' ', $v); - return [$v[0] => $v[1]]; - }) : $input['dimensions']; - - // * Adapt dimensions - $sizes = (object)[ - 'minHeight' => $dim['height'], - 'maxHeight' => $dim['height'], - 'minWith' => $dim['width'], - 'maxWith' => $dim['width'], - ]; - $rules = array_merge($rules, [ - "data.$iptName.value" => [ - function (string $attribute, $value, callable $fail) use ($sizes) { - ToolboxHelper::validatePicture($attribute, $value, $fail, $sizes); - } - ], - $this->compileValidate( - implode('|', [ - $required, - 'image', - 'mimes:png,jpg,jpeg', - sprintf( - 'dimensions:%s=%d,%s=%d', - $max ? 'max_height' : 'height', - $dim['height'], - $max ? 'max_width' : 'width', - $dim['width'] - ) - ]), - $input - ), - "data.$iptName.alt" => $this->compileValidate("$required|string|min:5", $input), - "data.$iptName.title" => $this->compileValidate("$required|string|min:5", $input) - ]); - break; - case InputType::url->value: - $rules = array_merge($rules, [ - "data.$iptName.value" => [ - 'required', 'url', - // @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed - function ($attribute, $value, $fail) { - try { - ToolboxHelper::assertNoInternalUrls($attribute, $value); - ToolboxHelper::assertNoInternalBoUrls($attribute, $value); - } catch (ValidationException $e) { - $fail(collect($e->errors())->first()[0]); - } - } - ] - ]); - break; - case InputType::boolean->value: - $all = $this->all(); - $nested = ToolboxHelper::dotStringToNestedArray( - "data.$iptName.value", - $this->input("data.$iptName.value") ? true : false - ); - $all = ToolboxHelper::arrayMergeRecursiveDistinct($all, $nested); - $this->merge($all); - $rules = array_merge($rules, [ - "data.$iptName.value" => 'boolean' - ]); - break; - } //end switch - } //end foreach - return $rules; - } - - /** - * Undocumented function - * - * @param string|array $inputTypeValidate - * @param array $input - * @return array - */ - public function compileValidate(string|array $inputTypeValidate, array $input): array - { - if (\is_string($inputTypeValidate)) { - $inputTypeValidate = explode('|', $inputTypeValidate); - } - /** @var array|string */ - $inputValidate = \collect($input)->get('validate', $input); - $inputValidate = \is_string($inputValidate) ? explode('|', $inputValidate) : $inputValidate; - foreach ($inputValidate as $validate) { - if (!\in_array($validate, $inputTypeValidate)) { - $inputTypeValidate[] = $validate; - } - } - - $test = \collect($inputTypeValidate)->all(); - $test = \collect($inputTypeValidate)->sort(function ($valueA, $valueB) { - $valueA = $this->ruleHasToComeFirst($valueA) ? 0 : 2; - $valueB = $this->ruleHasToComeFirst($valueB) ? 1 : 2; - return $valueA - $valueB; - })->unique()->all(); - - return \collect($inputTypeValidate)->unique()->sort(function ($valueA, $valueB) { - $valueA = $this->ruleHasToComeFirst($valueA) ? 0 : 2; - $valueB = $this->ruleHasToComeFirst($valueB) ? 1 : 2; - return $valueA - $valueB; - })->all(); - } - - /** - * Does the rulle need to come first ? - * - * @param string $rule - * @return boolean - */ - private function ruleHasToComeFirst(string $rule): bool - { - $rule = \collect(\explode(':', $rule, 1))->filter()->first(null, ''); - return \collect([ - 'nullable', 'present', 'required', 'required_if', - 'required_unless', 'required_with', 'required_with_all', - 'required_without', 'required_without_all', 'required_with_all', - 'missing', 'missing_if', 'missing_unless', - 'missing_with', 'missing_with_all', - ])->first(fn (string $firstRule) => \strpos($rule, $firstRule) === 0) ? true : false; - } - - /** - * Is this request an update request ? - * - * @return boolean - */ - private function isUpdate(): bool - { - return $this->isMethod('PUT'); - } -} diff --git a/app/Models/Homepage.php b/app/Models/Homepage.php index 7f92c7a..788edc4 100644 --- a/app/Models/Homepage.php +++ b/app/Models/Homepage.php @@ -14,7 +14,7 @@ use Illuminate\Database\Eloquent\Model; * @property string|null $picture Path of the picture (640px * 390px). * @property string $picture_alt Picture alt attribute. * @property string $picture_title Picture title attribute. - * @property string $youtube_video_id The youtube video Id. + * @property string $video_id The youtube or vimeo video Id. * @property boolean $display_video Wether to display video or picture. * @property string $presentation_title Presentation title. * @property string $presentation_content WYSIWYG - Presentation content. @@ -40,7 +40,7 @@ class Homepage extends Model 'picture_title', 'presentation_title', 'presentation_content', - 'youtube_video_id', + 'video_id', 'display_video', ]; diff --git a/app/Rules/IsValidVimeoId.php b/app/Rules/IsValidVimeoId.php new file mode 100644 index 0000000..4a91da6 --- /dev/null +++ b/app/Rules/IsValidVimeoId.php @@ -0,0 +1,43 @@ +isMatch('/^[0-9]{8,10}$/'); + } +} diff --git a/app/Rules/IsValidYoutubeId.php b/app/Rules/IsValidYoutubeId.php index c1db71f..1a41009 100644 --- a/app/Rules/IsValidYoutubeId.php +++ b/app/Rules/IsValidYoutubeId.php @@ -26,8 +26,19 @@ class IsValidYoutubeId implements ValidationRule public function validate(string $attribute, mixed $value, \Closure $fail): void { // phpcs:enable - if (!Str::of($value)->isMatch('/[0-9A-Za-z_-]{10}[048AEIMQUYcgkosw]/')) { + if (!self::validates($value)) { $fail(trans('validation.youtube_id')); } } + + /** + * Validate a value + * + * @param mixed $value + * @return boolean + */ + public static function validates(mixed $value): bool + { + return Str::of($value)->isMatch('/^[0-9A-Za-z_-]{10}[048AEIMQUYcgkosw]$/'); + } } diff --git a/app/Traits/Models/MiniCrudModel.php b/app/Traits/Models/MiniCrudModel.php deleted file mode 100644 index 09109f1..0000000 --- a/app/Traits/Models/MiniCrudModel.php +++ /dev/null @@ -1,180 +0,0 @@ -setData($attributes['data']); - } - } - - /** - * Apply function on data typed text while on save event - * - * @return void - */ - public function minicrudCreating() - { - /** @var array */ - $data = $this->data; - foreach ($data as &$input) { - switch ($input['inputType']) { - case InputType::text->value: - $input['text'] = clean($input['text']); - $input['text'] = FileStorageHelper::storeModelFilesFromHtml($this, $input['text']); - break; - } //end switch - } //end foreach - $this->data = $data; - } - - /** - * Apply function on data typed text while on update event - * - * @return void - */ - public function minicrudUpdating() - { - $this->minicrudCreating(); - } - - /** - * Apply function on data typed text while on updated event - * - * @return void - */ - public function minicrudUpdated() - { - /** @var array */ - foreach ($this->data as $index => $input) { - switch ($input['inputType']) { - case InputType::text->value: - $original = ToolboxHelper::getOriginal($this, 'data'); - FileStorageHelper::removeOldModelFilesFromHtml( - $input['text'], - $original[$index]['text'] ?? '' - ); - break; - } //end switch - } //end foreach - } - - /** - * Apply function on data typed text while on deleted event - * - * @return void - */ - public function minicrudDeleted() - { - /** @var array */ - foreach ($this->data as $input) { - switch ($input['inputType']) { - case InputType::text->value: - FileStorageHelper::removeModelFilesOfHtml($input['text']); - break; - } //end switch - } //end foreach - } - - /** - * Set a specific prop - * - * @param array $data - * @return void - */ - private function setData(array $data): void - { - $attrs = $this->attributes; - if (isset($attrs['data'])) { - unset($attrs['data']); - } - $this->setAttribute('data', $data); - } - - /** - * Set a specific prop - * - * @param array $value - * @return void - */ - protected function setDataAttribute(array $value): void - { - $this->attributes['data'] = $this->castAttributeAsJson( - 'data', - $this->serializeData($value) - ); - } - - /** - * Set a specific prop - * - * @param string|null $data - * @return array - */ - protected function getDataAttribute(string|null $data): array - { - return $this->fromJson($data ?? $this->attributes['data'] ?? '[]'); - } - - /** - * Serialize properties - * - * @param array $data - * @return array - * @throws \ErrorException If input type is no handled. - * @throws \Illuminate\Validation\ValidationException If url is a bo url. - * @phpcs:disable Squiz.Commenting.FunctionCommentThrowTag.WrongNumber - * @phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh - */ - private function serializeData(array $data): array - { - foreach ($data as $o => $input) { - switch ($input['inputType']) { - case InputType::image->value: - $data[$o]['value'] = \preg_replace( - '/^\/|^/', - '', - FileStorageHelper::storeFile($this, $input['value'], true) - ); - break; - case InputType::selectEnum->value: - case InputType::boolean->value: - case InputType::password->value: - case InputType::email->value: - case InputType::number->value: - case InputType::videoVimeo->value: - case InputType::videoYoutube->value: - case InputType::video->value: - break; - case InputType::string->value: - case InputType::text->value: - case InputType::url->value: - ToolboxHelper::assertNoInternalBoUrls('content', $input['value']); - break; - default: - throw new \ErrorException(sprintf( - 'Unknown input Type %s', - $input['inputType'] - )); - } //end switch - } //end foreach - return $data; - } -} diff --git a/database/migrations/2024_02_09_111729_setup_vimeo_video.php b/database/migrations/2024_02_09_111729_setup_vimeo_video.php new file mode 100644 index 0000000..4ca146e --- /dev/null +++ b/database/migrations/2024_02_09_111729_setup_vimeo_video.php @@ -0,0 +1,32 @@ +renameColumn('youtube_video_id', 'video_id'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::table('homepages', function (Blueprint $table) { + $table->renameColumn('video_id', 'youtube_video_id'); + }); + } +}; diff --git a/resources/lang/en/cookie-notice.php b/resources/lang/en/cookie-notice.php index d57c65b..80bcf65 100644 --- a/resources/lang/en/cookie-notice.php +++ b/resources/lang/en/cookie-notice.php @@ -36,6 +36,12 @@ return [ 'labelLink' => 'Learn more', 'warning' => 'You must accept cookies to view this video', ], + 'vimeo' => [ + 'name' => 'Vimeo', + 'description' => 'Les cookies placés via les services de partage de vidéos sont destinés à permettre à l’utilisateur de visionner des contenus multimédias directement sur le site.', + 'labelLink' => 'En apprendre plus', + 'warning' => 'Vous devez accepter les cookies pour visionner cette vidéo', + ], 'matomo' => [ 'title' => 'Matomo', 'description' => 'Audience measurement services are used to generate traffic statistics, which are useful for improving the site.', diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index 62d4df3..f4ea10c 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -217,6 +217,7 @@ return [ ], 'youtube_id' => ':attribute must be a valid Youtube video ID', + 'vimeo_id' => ':attribute must be a valid Vimeo video ID', 'custom' => [ 'of_the' => [ @@ -230,7 +231,6 @@ return [ 'attribute_title' => 'title attribute', 'background' => 'background', 'category' => 'category', - 'category' => 'category', 'civility' => 'civility', 'cooking_advice' => 'cooking advice', 'description' => 'description', @@ -272,7 +272,6 @@ return [ 'product_name' => 'product name', 'publication' => 'publication', 'publish_at' => 'publication date', - 'publish_at' => 'publication date', 'send_data' => 'autorization to send data', 'seo_description' => 'SEO description', 'seo_title' => 'SEO title', @@ -287,7 +286,8 @@ return [ 'title_part2' => 'title part two', 'title_part3' => 'title part three', 'unpublish_at' => 'end of publication date', - 'unpublish_at' => 'end of publication date', 'video_id' => 'ID of the video', + 'youtube_video_id' => 'ID of the youtube video', + 'vimeo_video_id' => 'ID of the vimeo video', ], ]; diff --git a/resources/lang/fr/cookie-notice.php b/resources/lang/fr/cookie-notice.php index 8d9a655..05161ec 100644 --- a/resources/lang/fr/cookie-notice.php +++ b/resources/lang/fr/cookie-notice.php @@ -36,6 +36,12 @@ return [ 'labelLink' => 'En apprendre plus', 'warning' => 'Vous devez accepter les cookies pour visionner cette vidéo', ], + 'vimeo' => [ + 'name' => 'Vimeo', + 'description' => 'Les cookies placés via les services de partage de vidéos sont destinés à permettre à l’utilisateur de visionner des contenus multimédias directement sur le site.', + 'labelLink' => 'En apprendre plus', + 'warning' => 'Vous devez accepter les cookies pour visionner cette vidéo', + ], 'matomo' => [ 'title' => 'Matomo', 'description' => 'Les services de mesure d’audience permettent de générer des statistiques de fréquentation utiles à l’amélioration du site.', diff --git a/resources/lang/fr/validation.php b/resources/lang/fr/validation.php index 4906d5d..cbdf286 100644 --- a/resources/lang/fr/validation.php +++ b/resources/lang/fr/validation.php @@ -219,6 +219,7 @@ return [ ], 'youtube_id' => ':attribute doit être un ID de vidéo Youtube valide', + 'vimeo_id' => ':attribute doit être un ID de vidéo Vimeo valide', 'custom' => [ 'of_the' => [ @@ -232,7 +233,6 @@ return [ 'attribute_title' => 'attribut title', 'background' => 'fond', 'category' => 'catégorie', - 'category' => 'catégorie', 'civility' => 'civilité', 'cooking_advice' => 'conseil de réchauffage', 'description' => 'description', @@ -274,7 +274,6 @@ return [ 'product_name' => 'nom du produit', 'publication' => 'publication', 'publish_at' => 'date de publication', - 'publish_at' => 'date de publication', 'send_data' => 'autorisation d\'enregistrer des données', 'seo_description' => 'description SEO', 'seo_title' => 'titre SEO', @@ -290,9 +289,9 @@ return [ 'title_part3' => 'dernière partie du titre', 'type' => 'type', 'unpublish_at' => 'date de fin de publication', - 'unpublish_at' => 'date de fin de publication', 'video_id' => 'ID de la vidéo', 'youtube_video_id' => 'ID de la vidéo youtube', + 'vimeo_video_id' => 'ID de la vidéo viméo', 'display_video' => 'affichage de la vidéo', ], ]; diff --git a/resources/views/bo/auth/login.blade.php b/resources/views/bo/auth/login.blade.php index 1731442..e370375 100644 --- a/resources/views/bo/auth/login.blade.php +++ b/resources/views/bo/auth/login.blade.php @@ -3,65 +3,66 @@ @section('description', __('Formulaire d\'authentification au back-office.')) @section('content') -
-
-
-
-
{{ __('Connexion') }}
-
-
- @csrf -
- -
- - @error('email') - - {{ $message }} - - @enderror -
-
-
- -
- - @error('password') - - {{ $message }} - - @enderror -
-
-
-
-
- - +
+
+
+
+
{{ __('Connexion') }}
+
+ + @csrf +
+ +
+ + @error('email') + + {{ $message }} + + @enderror
-
-
-
- - @if (Route::has('bo.password.request')) - - {{ __('Mot de passe oublié ?') }} - - @endif +
+ +
+ + @error('password') + + {{ $message }} + + @enderror +
-
- +
+
+
+ + +
+
+
+
+
+ + @if (Route::has('bo.password.request')) + + {{ __('Mot de passe oublié ?') }} + + @endif +
+
+ +
-
@endsection diff --git a/resources/views/bo/layouts/header.blade.php b/resources/views/bo/layouts/header.blade.php index d6d0f89..cfbfa0c 100644 --- a/resources/views/bo/layouts/header.blade.php +++ b/resources/views/bo/layouts/header.blade.php @@ -62,7 +62,7 @@