diff options
Diffstat (limited to 'src/controller/HeadFootController.php')
| -rw-r--r-- | src/controller/HeadFootController.php | 60 |
1 files changed, 54 insertions, 6 deletions
diff --git a/src/controller/HeadFootController.php b/src/controller/HeadFootController.php index 8d59d10..0429aac 100644 --- a/src/controller/HeadFootController.php +++ b/src/controller/HeadFootController.php | |||
| @@ -5,23 +5,24 @@ declare(strict_types=1); | |||
| 5 | 5 | ||
| 6 | //use App\Entity\Node; | 6 | //use App\Entity\Node; |
| 7 | //use App\Entity\NodeData; | 7 | //use App\Entity\NodeData; |
| 8 | //use App\Entity\Image; | 8 | use App\Entity\Asset; |
| 9 | //use Doctrine\Common\Collections\ArrayCollection; | 9 | use Doctrine\Common\Collections\ArrayCollection; |
| 10 | use Doctrine\ORM\EntityManager; | 10 | use Doctrine\ORM\EntityManager; |
| 11 | 11 | ||
| 12 | class HeadFootController | 12 | class HeadFootController |
| 13 | { | 13 | { |
| 14 | static public function setTextData(EntityManager $entityManager, array $request_params, array $json): void | 14 | static public function setTextData(EntityManager $entityManager, string $request_params, array $json): void |
| 15 | { | 15 | { |
| 16 | if(count($request_params) !== 2){ | 16 | $params_array = explode('_', $request_params); // header_title, header_description, footer_name, footer_address, footer_email |
| 17 | if(count($params_array) !== 2){ | ||
| 17 | echo json_encode(['success' => false]); | 18 | echo json_encode(['success' => false]); |
| 18 | die; | 19 | die; |
| 19 | } | 20 | } |
| 20 | 21 | ||
| 21 | $model = new Model($entityManager); | 22 | $model = new Model($entityManager); |
| 22 | if($model->findWhateverNode('name_node', $request_params[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($request_params[1], $json['new_text']); // $request_params[1] n'est pas contrôlé | 25 | $node_data->updateData($params_array[1], $json['new_text']); // $params_array[1] n'est pas contrôlé |
| 25 | $entityManager->flush(); | 26 | $entityManager->flush(); |
| 26 | echo json_encode(['success' => true]); | 27 | echo json_encode(['success' => true]); |
| 27 | } | 28 | } |
| @@ -30,4 +31,51 @@ class HeadFootController | |||
| 30 | } | 31 | } |
| 31 | die; | 32 | die; |
| 32 | } | 33 | } |
| 34 | static public function uploadAsset(EntityManager $entityManager, string $request_params): void | ||
| 35 | { | ||
| 36 | if(empty($_FILES)){ | ||
| 37 | http_response_code(400); | ||
| 38 | echo json_encode(['success' => false]); | ||
| 39 | } | ||
| 40 | else{ | ||
| 41 | $file = $_FILES['file']; | ||
| 42 | |||
| 43 | if(!is_dir(Asset::USER_PATH)){ | ||
| 44 | mkdir(Asset::USER_PATH, 0700, true); | ||
| 45 | } | ||
| 46 | |||
| 47 | $allowed_extensions = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'tiff', 'tif', 'ico', 'bmp']; // pas de SVG | ||
| 48 | $name = Security::secureFileName(pathinfo($file['name'], PATHINFO_FILENAME)); | ||
| 49 | $extension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)); | ||
| 50 | if(!in_array($extension, $allowed_extensions) || $extension === 'jpg'){ | ||
| 51 | $extension = 'jpeg'; | ||
| 52 | } | ||
| 53 | $file_path = uniqid($name . '_') . '.' . $extension; | ||
| 54 | |||
| 55 | if(ImageUploadController::imagickCleanImage(file_get_contents($file['tmp_name']), Asset::USER_PATH . $file_path, $extension)){ // recréer l’image pour la nettoyer | ||
| 56 | $params_array = explode('_', $request_params); // favicon, header_logo, header_background, footer_logo | ||
| 57 | |||
| 58 | $model = new Model($entityManager); | ||
| 59 | if($model->findWhateverNode('name_node', $params_array[0])){ | ||
| 60 | $node_data = $model->getNode()->getNodeData(); | ||
| 61 | $image = new Asset($name, $file_path, mime_content_type($file['tmp_name']), $request_params); | ||
| 62 | $node_data->addAsset($image); | ||
| 63 | |||
| 64 | $entityManager->persist($image); | ||
| 65 | $entityManager->flush(); | ||
| 66 | echo json_encode(['success' => true, 'location' => Asset::USER_PATH . $file_path]); | ||
| 67 | } | ||
| 68 | else{ | ||
| 69 | echo json_encode(['success' => false, 'message' => 'Erreur noeud non trouvé.']); | ||
| 70 | } | ||
| 71 | } | ||
| 72 | else{ | ||
| 73 | http_response_code(500); | ||
| 74 | echo json_encode(['success' => false, 'message' => 'Erreur image non valide.']); | ||
| 75 | } | ||
| 76 | } | ||
| 77 | die; | ||
| 78 | } | ||
| 79 | |||
| 80 | //static public function uploadImage(EntityManager $entityManager, array $request_params): void | ||
| 33 | } \ No newline at end of file | 81 | } \ No newline at end of file |
