diff options
Diffstat (limited to 'src/Controller')
| -rw-r--r-- | src/Controller/HeadFootController.php | 9 | ||||
| -rw-r--r-- | src/Controller/MenuAndPathsController.php | 22 | ||||
| -rw-r--r-- | src/Controller/ViewController.php | 3 |
3 files changed, 21 insertions, 13 deletions
diff --git a/src/Controller/HeadFootController.php b/src/Controller/HeadFootController.php index e39c07b..2bf210e 100644 --- a/src/Controller/HeadFootController.php +++ b/src/Controller/HeadFootController.php | |||
| @@ -28,14 +28,19 @@ class HeadFootController | |||
| 28 | $node_data = $model->getNode()->getNodeData(); | 28 | $node_data = $model->getNode()->getNodeData(); |
| 29 | 29 | ||
| 30 | // liens réseaux sociaux | 30 | // liens réseaux sociaux |
| 31 | $link = trim($json['new_text'] ?? ''); // trim n'aime pas recevoir un NULL | ||
| 31 | if(in_array($params_array[1], NodeData::$social_networks)){ | 32 | if(in_array($params_array[1], NodeData::$social_networks)){ |
| 33 | if($link !== '' && !Security::validateURL($link)){ | ||
| 34 | return new JsonResponse(['success' => false, 'error' => 'invalid_url']); | ||
| 35 | } | ||
| 36 | |||
| 32 | $social = $node_data->getData()['social'] ?? []; | 37 | $social = $node_data->getData()['social'] ?? []; |
| 33 | $social[$params_array[1]] = $json['new_text']; | 38 | $social[$params_array[1]] = $link; |
| 34 | $node_data->updateData('social', $social); | 39 | $node_data->updateData('social', $social); |
| 35 | } | 40 | } |
| 36 | // autres textes | 41 | // autres textes |
| 37 | else{ | 42 | else{ |
| 38 | $node_data->updateData($params_array[1], $json['new_text']); // $params_array[1] n'est pas contrôlé | 43 | $node_data->updateData($params_array[1], $link); // $params_array[1] n'est pas contrôlé |
| 39 | } | 44 | } |
| 40 | 45 | ||
| 41 | $entityManager->flush(); | 46 | $entityManager->flush(); |
diff --git a/src/Controller/MenuAndPathsController.php b/src/Controller/MenuAndPathsController.php index 1916f06..aa283b6 100644 --- a/src/Controller/MenuAndPathsController.php +++ b/src/Controller/MenuAndPathsController.php | |||
| @@ -6,31 +6,33 @@ declare(strict_types=1); | |||
| 6 | namespace App\Controller; | 6 | namespace App\Controller; |
| 7 | 7 | ||
| 8 | use Doctrine\ORM\EntityManager; | 8 | use Doctrine\ORM\EntityManager; |
| 9 | use Symfony\Component\HttpFoundation\Request; | ||
| 9 | use Symfony\Component\HttpFoundation\JsonResponse; | 10 | use Symfony\Component\HttpFoundation\JsonResponse; |
| 10 | use Symfony\Component\HttpFoundation\RedirectResponse; | 11 | use Symfony\Component\HttpFoundation\RedirectResponse; |
| 11 | use App\Entity\Page; | 12 | use App\Entity\Page; |
| 12 | use App\Model\Menu; | 13 | use App\Model\Menu; |
| 13 | use App\Model\Model; | 14 | use App\Model\Model; |
| 14 | use App\Service\URL; | 15 | use App\Service\URL; |
| 16 | use App\Service\Security; | ||
| 15 | use App\View\NavBuilder; | 17 | use App\View\NavBuilder; |
| 16 | use App\View\MenuBuilder; | 18 | use App\View\MenuBuilder; |
| 17 | 19 | ||
| 18 | class MenuAndPathsController | 20 | class MenuAndPathsController |
| 19 | { | 21 | { |
| 20 | static public function newUrlMenuEntry(EntityManager $entityManager): RedirectResponse | 22 | static public function newUrlMenuEntry(EntityManager $entityManager, Request $request): RedirectResponse |
| 21 | { | 23 | { |
| 22 | Model::$menu = new Menu($entityManager); | 24 | Model::$menu = new Menu($entityManager); |
| 23 | $previous_page = Model::$menu->findPageById((int)$_POST["location"]); // (int) à cause de declare(strict_types=1); | 25 | $previous_page = Model::$menu->findPageById((int)$_POST["location"]); // (int) à cause de declare(strict_types=1); |
| 24 | $parent = $previous_page->getParent(); | 26 | $parent = $previous_page->getParent(); |
| 25 | 27 | ||
| 26 | $url_input = trim($_POST["url_input"]); // faire htmlspecialchars à l'affichage | 28 | $url_input = trim($request->request->get("url_input")); // faire htmlspecialchars à l'affichage |
| 27 | if(!filter_var($url_input, FILTER_VALIDATE_URL) || !str_starts_with($url_input, 'http')){ | 29 | if(!Security::validateURL($url_input)){ |
| 28 | // utiliser une flash error | 30 | // utiliser une flash error |
| 29 | return new RedirectResponse((string)new URL(['page' => $_GET['from'], 'error' => 'invalide_url'])); | 31 | return new RedirectResponse((string)new URL(['page' => $request->query->get('from'), 'error' => 'invalide_url'])); |
| 30 | } | 32 | } |
| 31 | 33 | ||
| 32 | $page = new Page( | 34 | $page = new Page( |
| 33 | trim(htmlspecialchars($_POST["label_input"])), | 35 | trim(htmlspecialchars($request->request->get("label_input"))), |
| 34 | $url_input, '', | 36 | $url_input, '', |
| 35 | true, true, false, | 37 | true, true, false, |
| 36 | $previous_page->getPosition(), | 38 | $previous_page->getPosition(), |
| @@ -47,7 +49,7 @@ class MenuAndPathsController | |||
| 47 | 49 | ||
| 48 | $entityManager->persist($page); | 50 | $entityManager->persist($page); |
| 49 | $entityManager->flush(); | 51 | $entityManager->flush(); |
| 50 | return new RedirectResponse((string)new URL(['page' => $_GET['from']])); | 52 | return new RedirectResponse((string)new URL(['page' => $request->query->get('from')])); |
| 51 | } | 53 | } |
| 52 | 54 | ||
| 53 | // on pourrait utiliser FormValidation ici | 55 | // on pourrait utiliser FormValidation ici |
| @@ -62,7 +64,7 @@ class MenuAndPathsController | |||
| 62 | elseif(!in_array($json['field'], ['url_name', 'url_content'])){ | 64 | elseif(!in_array($json['field'], ['url_name', 'url_content'])){ |
| 63 | return new JsonResponse(['success' => false, 'message' => "champ invalide"]); | 65 | return new JsonResponse(['success' => false, 'message' => "champ invalide"]); |
| 64 | } | 66 | } |
| 65 | elseif($json['field'] === 'url_content' && (!filter_var($url_data, FILTER_VALIDATE_URL) || !str_starts_with($url_data, 'http'))){ | 67 | elseif($json['field'] === 'url_content' && !Security::validateURL($url_data)){ |
| 66 | return new JsonResponse(['success' => false, 'message' => "la chaîne envoyée n'est pas une URL valide"]); | 68 | return new JsonResponse(['success' => false, 'message' => "la chaîne envoyée n'est pas une URL valide"]); |
| 67 | } | 69 | } |
| 68 | else{ | 70 | else{ |
| @@ -77,10 +79,10 @@ class MenuAndPathsController | |||
| 77 | } | 79 | } |
| 78 | } | 80 | } |
| 79 | 81 | ||
| 80 | static public function deleteUrlMenuEntry(EntityManager $entityManager): RedirectResponse | 82 | static public function deleteUrlMenuEntry(EntityManager $entityManager, Request $request): RedirectResponse |
| 81 | { | 83 | { |
| 82 | Model::$menu = new Menu($entityManager); | 84 | Model::$menu = new Menu($entityManager); |
| 83 | $page = Model::$menu->findPageById((int)$_POST["delete"]); | 85 | $page = Model::$menu->findPageById((int)$request->request->get("delete")); |
| 84 | $parent = $page->getParent(); | 86 | $parent = $page->getParent(); |
| 85 | if($parent == null){ | 87 | if($parent == null){ |
| 86 | $parent = Model::$menu; | 88 | $parent = Model::$menu; |
| @@ -91,7 +93,7 @@ class MenuAndPathsController | |||
| 91 | 93 | ||
| 92 | $entityManager->remove($page); // suppression en BDD | 94 | $entityManager->remove($page); // suppression en BDD |
| 93 | $entityManager->flush(); | 95 | $entityManager->flush(); |
| 94 | return new RedirectResponse((string)new URL(['page' => $_GET['from']])); | 96 | return new RedirectResponse((string)new URL(['page' => $request->query->get('from')])); |
| 95 | } | 97 | } |
| 96 | 98 | ||
| 97 | static public function MoveOneLevelUp(EntityManager $entityManager, array $json): JsonResponse | 99 | static public function MoveOneLevelUp(EntityManager $entityManager, array $json): JsonResponse |
diff --git a/src/Controller/ViewController.php b/src/Controller/ViewController.php index 1f13861..5be4ffd 100644 --- a/src/Controller/ViewController.php +++ b/src/Controller/ViewController.php | |||
| @@ -38,7 +38,8 @@ class ViewController{ | |||
| 38 | else{ | 38 | else{ |
| 39 | // mode création d'article | 39 | // mode création d'article |
| 40 | // l'id du bloc et 'from=' sont vérifiés dans ArticleController::editorSubmit | 40 | // l'id du bloc et 'from=' sont vérifiés dans ArticleController::editorSubmit |
| 41 | if($request->query->get('id')[0] === 'n' && $request->query->has('from') && !empty($request->query->get('from'))){ | 41 | if(preg_match('/^n\d+\z/', $request->query->get('id')) // débute par 'n' puis des chiffres, \z au lieu de $ pour éviter un saut de ligne à la fin |
| 42 | && $request->query->has('from') && !empty($request->query->get('from'))){ | ||
| 42 | NewBuilder::$new_article_mode = true; | 43 | NewBuilder::$new_article_mode = true; |
| 43 | } | 44 | } |
| 44 | } | 45 | } |
