diff options
Diffstat (limited to 'src/controller')
| -rw-r--r-- | src/controller/HeadFootController.php | 16 | ||||
| -rw-r--r-- | src/controller/ImageUploadController.php | 10 | ||||
| -rw-r--r-- | src/controller/MenuAndPathsController.php | 19 |
3 files changed, 31 insertions, 14 deletions
diff --git a/src/controller/HeadFootController.php b/src/controller/HeadFootController.php index a739df8..ffa33bc 100644 --- a/src/controller/HeadFootController.php +++ b/src/controller/HeadFootController.php | |||
| @@ -5,11 +5,12 @@ declare(strict_types=1); | |||
| 5 | 5 | ||
| 6 | use App\Entity\NodeDataAsset; | 6 | use App\Entity\NodeDataAsset; |
| 7 | use App\Entity\Asset; | 7 | use App\Entity\Asset; |
| 8 | use Doctrine\Common\Collections\ArrayCollection; | ||
| 9 | use Doctrine\ORM\EntityManager; | 8 | use Doctrine\ORM\EntityManager; |
| 10 | 9 | ||
| 11 | class HeadFootController | 10 | class HeadFootController |
| 12 | { | 11 | { |
| 12 | static array $social_networks = ['facebook', 'instagram', 'linkedin', 'github']; // à completer | ||
| 13 | |||
| 13 | static public function setTextData(EntityManager $entityManager, string $request_params, array $json): void | 14 | static public function setTextData(EntityManager $entityManager, string $request_params, array $json): void |
| 14 | { | 15 | { |
| 15 | $params_array = explode('_', $request_params); // header_title, header_description, footer_name, footer_address, footer_email | 16 | $params_array = explode('_', $request_params); // header_title, header_description, footer_name, footer_address, footer_email |
| @@ -21,7 +22,14 @@ class HeadFootController | |||
| 21 | $model = new Model($entityManager); | 22 | $model = new Model($entityManager); |
| 22 | if($model->findWhateverNode('name_node', $params_array[0])){ | 23 | if($model->findWhateverNode('name_node', $params_array[0])){ |
| 23 | $node_data = $model->getNode()->getNodeData(); | 24 | $node_data = $model->getNode()->getNodeData(); |
| 24 | $node_data->updateData($params_array[1], $json['new_text']); // $params_array[1] n'est pas contrôlé | 25 | if(in_array($params_array[1], self::$social_networks)){ |
| 26 | $social = $node_data->getData()['social']; | ||
| 27 | $social[$params_array[1]] = $json['new_text']; | ||
| 28 | $node_data->updateData('social', $social); | ||
| 29 | } | ||
| 30 | else{ | ||
| 31 | $node_data->updateData($params_array[1], $json['new_text']); // $params_array[1] n'est pas contrôlé | ||
| 32 | } | ||
| 25 | $entityManager->flush(); | 33 | $entityManager->flush(); |
| 26 | echo json_encode(['success' => true]); | 34 | echo json_encode(['success' => true]); |
| 27 | } | 35 | } |
| @@ -38,7 +46,7 @@ class HeadFootController | |||
| 38 | } | 46 | } |
| 39 | else{ | 47 | else{ |
| 40 | if(!is_dir(Asset::USER_PATH)){ | 48 | if(!is_dir(Asset::USER_PATH)){ |
| 41 | mkdir(Asset::USER_PATH, 0755, true); | 49 | mkdir(Asset::USER_PATH, 0777, true); |
| 42 | } | 50 | } |
| 43 | 51 | ||
| 44 | /* -- téléchargement -- */ | 52 | /* -- téléchargement -- */ |
| @@ -72,7 +80,7 @@ class HeadFootController | |||
| 72 | /* -- écriture du fichier sur le disque -- */ | 80 | /* -- écriture du fichier sur le disque -- */ |
| 73 | if(!ImageUploadController::imagickCleanImage(file_get_contents($file['tmp_name']), Asset::USER_PATH . $name, $extension)){ // recréer l’image pour la nettoyer | 81 | if(!ImageUploadController::imagickCleanImage(file_get_contents($file['tmp_name']), Asset::USER_PATH . $name, $extension)){ // recréer l’image pour la nettoyer |
| 74 | http_response_code(500); | 82 | http_response_code(500); |
| 75 | echo json_encode(['success' => false, 'message' => 'Erreur image non valide.']); | 83 | echo json_encode(['success' => false, 'message' => 'Erreur image non valide.', 'format' => $extension]); |
| 76 | } | 84 | } |
| 77 | else{ | 85 | else{ |
| 78 | $params_array = explode('_', $request_params); // head_favicon, header_logo, header_background, footer_logo | 86 | $params_array = explode('_', $request_params); // head_favicon, header_logo, header_background, footer_logo |
diff --git a/src/controller/ImageUploadController.php b/src/controller/ImageUploadController.php index 5e80ba5..77f0a47 100644 --- a/src/controller/ImageUploadController.php +++ b/src/controller/ImageUploadController.php | |||
| @@ -66,10 +66,10 @@ class ImageUploadController | |||
| 66 | 66 | ||
| 67 | // Vérifier si les répertoires existent, sinon les créer | 67 | // Vérifier si les répertoires existent, sinon les créer |
| 68 | if(!is_dir($dest)){ | 68 | if(!is_dir($dest)){ |
| 69 | mkdir($dest, 0700, true); | 69 | mkdir($dest, 0777, true); |
| 70 | } | 70 | } |
| 71 | if(!is_dir($dest_mini)){ | 71 | if(!is_dir($dest_mini)){ |
| 72 | mkdir($dest_mini, 0700, true); | 72 | mkdir($dest_mini, 0777, true); |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | $allowed_extensions = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'tiff', 'tif']; | 75 | $allowed_extensions = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'tiff', 'tif']; |
| @@ -88,7 +88,7 @@ class ImageUploadController | |||
| 88 | } | 88 | } |
| 89 | else{ | 89 | else{ |
| 90 | http_response_code(500); | 90 | http_response_code(500); |
| 91 | echo json_encode(['message' => 'Erreur image non valide']); | 91 | echo json_encode(['message' => 'Erreur image non valide', 'format' => $extension]); |
| 92 | } | 92 | } |
| 93 | } | 93 | } |
| 94 | else{ | 94 | else{ |
| @@ -131,7 +131,7 @@ class ImageUploadController | |||
| 131 | } | 131 | } |
| 132 | else{ | 132 | else{ |
| 133 | http_response_code(500); | 133 | http_response_code(500); |
| 134 | echo json_encode(['message' => 'Erreur image non valide']); | 134 | echo json_encode(['message' => 'Erreur image non valide', 'format' => $extension]); |
| 135 | } | 135 | } |
| 136 | } | 136 | } |
| 137 | else{ | 137 | else{ |
| @@ -177,7 +177,7 @@ class ImageUploadController | |||
| 177 | } | 177 | } |
| 178 | else{ | 178 | else{ |
| 179 | http_response_code(500); | 179 | http_response_code(500); |
| 180 | echo json_encode(['message' => 'Erreur image non valide']); | 180 | echo json_encode(['message' => 'Erreur image non valide', 'format' => $extension]); |
| 181 | } | 181 | } |
| 182 | die; | 182 | die; |
| 183 | } | 183 | } |
diff --git a/src/controller/MenuAndPathsController.php b/src/controller/MenuAndPathsController.php index a32b210..6bb098f 100644 --- a/src/controller/MenuAndPathsController.php +++ b/src/controller/MenuAndPathsController.php | |||
| @@ -42,21 +42,30 @@ class MenuAndPathsController | |||
| 42 | die; | 42 | die; |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | static public function editUrlEntry(EntityManager $entityManager, array $json): void | 45 | // on pourrait utiliser FormValidation ici |
| 46 | static public function editUrl(EntityManager $entityManager, array $json): void | ||
| 46 | { | 47 | { |
| 47 | $url_input = trim($json['url_input']); // faire htmlspecialchars à l'affichage | 48 | $url_data = trim($json['input_data']); // garder htmlspecialchars pour l'affichage |
| 48 | $page = $entityManager->find('App\Entity\Page', $json['id']); | 49 | $page = $entityManager->find('App\Entity\Page', $json['id']); |
| 49 | 50 | ||
| 50 | if(!$page){ | 51 | if(!$page){ |
| 51 | echo json_encode(['success' => false, 'message' => "id invalide"]); | 52 | echo json_encode(['success' => false, 'message' => "id invalide"]); |
| 52 | } | 53 | } |
| 53 | elseif(!filter_var($url_input, FILTER_VALIDATE_URL) || !str_starts_with($url_input, 'http')){ | 54 | elseif(!in_array($json['field'], ['url_name', 'url_content'])){ |
| 55 | echo json_encode(['success' => false, 'message' => "champ invalide"]); | ||
| 56 | } | ||
| 57 | elseif($json['field'] === 'url_content' && (!filter_var($url_data, FILTER_VALIDATE_URL) || !str_starts_with($url_data, 'http'))){ | ||
| 54 | echo json_encode(['success' => false, 'message' => "la chaîne envoyée n'est pas une URL valide"]); | 58 | echo json_encode(['success' => false, 'message' => "la chaîne envoyée n'est pas une URL valide"]); |
| 55 | } | 59 | } |
| 56 | else{ | 60 | else{ |
| 57 | $page->setEndOfPath($url_input); | 61 | if($json['field'] === 'url_name'){ |
| 62 | $page->setPageName($url_data); | ||
| 63 | } | ||
| 64 | elseif($json['field'] === 'url_content'){ | ||
| 65 | $page->setEndOfPath($url_data); | ||
| 66 | } | ||
| 58 | $entityManager->flush(); | 67 | $entityManager->flush(); |
| 59 | echo json_encode(['success' => true, 'url_input' => $url_input]); | 68 | echo json_encode(['success' => true, 'url_data' => $url_data]); |
| 60 | } | 69 | } |
| 61 | die; | 70 | die; |
| 62 | } | 71 | } |
