Quellcode durchsuchen

Merge branch 'develop' into features/background

François Drouhard vor 2 Jahren
Ursprung
Commit
eef74312f4

+ 1 - 1
composer.json

@@ -37,7 +37,7 @@
         "symfony/web-link": "^5.4",
         "symfony/webpack-encore-bundle": "^1.12",
         "symfony/yaml": "^5.4",
-        "twig/extra-bundle": "^2.12|^3.0",
+        "twig/extra-bundle": "^3.4",
         "twig/twig": "^2.12|^3.0"
     },
     "require-dev": {

+ 1 - 1
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "7e8426ea8af2574e4072a37165ca7eb5",
+    "content-hash": "1c713b3f6e195c2f6e26119496d5876a",
     "packages": [
         {
             "name": "composer/package-versions-deprecated",

+ 7 - 7
src/Form/CommentaireType.php

@@ -15,7 +15,7 @@ class CommentaireType extends AbstractType
     /**
      * {@inheritdoc}
      */
-    public function buildForm(FormBuilderInterface $builder, array $options)
+    public function buildForm(FormBuilderInterface $builder, array $options): void
     {
 	    $builder
             ->add('note', NumberType::class, array (
@@ -35,8 +35,8 @@ class CommentaireType extends AbstractType
             ->add('contenu', TextareaType::class, array(
                 'required' => false,
                 'label' => false
-            ))
-		    ->add('save', SubmitType::class, array(
+                ))
+                ->add('save', SubmitType::class, array(
 		        'label' => 'Enregistrer le commentaire',
                 'attr'=>array(
                     'class'  =>  'btn-primary'
@@ -46,11 +46,11 @@ class CommentaireType extends AbstractType
     /**
      * {@inheritdoc}
      */
-    public function configureOptions(OptionsResolver $resolver)
+    public function configureOptions(OptionsResolver $resolver): void
     {
-        $resolver->setDefaults(array(
-            'data_class' => 'App\Entity\Commentaire'
-        ));
+        $resolver->setDefaults([
+            'data_class' => 'App\Entity\Commentaire',
+        ]);
     }
 
     /**

+ 2 - 0
src/Service/CommentaireManager.php

@@ -26,6 +26,7 @@ class CommentaireManager {
 
     public function addCommentaire (Commentaire $commentaire, Film $film): void
     {
+        $commentaire->setContenu(htmlspecialchars($commentaire->getContenu()));
         $commentaire->setUser($this->user);
         $commentaire->setFilm(($film));
         $film->addCommentaire($commentaire);
@@ -35,6 +36,7 @@ class CommentaireManager {
 
     public function editCommentaire(Commentaire $commentaire): void
     {
+        $commentaire->setContenu(htmlspecialchars($commentaire->getContenu()));
         $this->em->flush();
     }
 

+ 25 - 0
src/Twig/Extension/ShowLinksExtension.php

@@ -0,0 +1,25 @@
+<?php
+
+namespace App\Twig\Extension;
+
+use Twig\Extension\AbstractExtension;
+use Twig\TwigFilter;
+use Twig\TwigFunction;
+
+class ShowLinksExtension extends AbstractExtension
+{
+    public function getFilters(): array
+    {
+        return [
+            // If your filter generates SAFE HTML, you should add a third
+            // parameter: ['is_safe' => ['html']]
+            // Reference: https://twig.symfony.com/doc/3.x/advanced.html#automatic-escaping
+            new TwigFilter('show_links', [$this, 'showLinks']),
+        ];
+    }
+
+    public function showLinks(string $texte): string
+    {
+        return preg_replace('#((https?|ftp)://(\S*?\.\S*?))([\s)\[\]{},;"\':<]|\.\s|$)#i', "<a href=\"$1\" target=\"_blank\">$1</a>$4", $texte);
+    }
+}

+ 1 - 1
templates/videotheque/voirfilm.html.twig

@@ -174,7 +174,7 @@
                                            value="{{ commentaire.note }}">
                                 {% endif %}
                                 {% if commentaire.contenu != "" %}
-                                    <p class="mb-1">{{ commentaire.contenu | nl2br }}</p>
+                                    <p>{{ commentaire.contenu | show_links | raw | nl2br }}</p>
                                 {%  endif %}
                             </div>
                         {% endfor %}