From f27cca08ff786ceff1870147f6d6bad14d71117f Mon Sep 17 00:00:00 2001 From: polo Date: Fri, 23 Oct 2026 00:47:32 +0200 Subject: =?UTF-8?q?dossiers=20avec=20majuscule,=20namespace=20pour=20toute?= =?UTF-8?q?s=20les=20classes,=20autoload=20psr-4,=20UserDataService::creat?= =?UTF-8?q?eZip=20d=C3=A9plac=C3=A9=20dans=20Backup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/HeadFootController.php | 141 ---------------------------------- 1 file changed, 141 deletions(-) delete mode 100644 src/controller/HeadFootController.php (limited to 'src/controller/HeadFootController.php') diff --git a/src/controller/HeadFootController.php b/src/controller/HeadFootController.php deleted file mode 100644 index 72487d8..0000000 --- a/src/controller/HeadFootController.php +++ /dev/null @@ -1,141 +0,0 @@ - false]); - } - - $model = new Model($entityManager); - if($model->findWhateverNode('name_node', $params_array[0])){ - $node_data = $model->getNode()->getNodeData(); - - // liens réseaux sociaux - if(in_array($params_array[1], NodeData::$social_networks)){ - $social = $node_data->getData()['social'] ?? []; - $social[$params_array[1]] = $json['new_text']; - $node_data->updateData('social', $social); - } - // autres textes - else{ - $node_data->updateData($params_array[1], $json['new_text']); // $params_array[1] n'est pas contrôlé - } - - $entityManager->flush(); - return new JsonResponse(['success' => true]); - } - else{ - return new JsonResponse(['success' => false]); - } - } - static public function uploadAsset(EntityManager $entityManager, string $request_params): JsonResponse - { - if(empty($_FILES)){ - return new JsonResponse(['success' => false], JsonResponse::HTTP_BAD_REQUEST); // code 400 - } - else{ - if(!is_dir(Asset::USER_PATH)){ - mkdir(Asset::USER_PATH, 0777, true); - } - - /* -- téléchargement -- */ - $file = $_FILES['file']; - $allowed_extensions = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'tiff', 'tif', 'ico', 'bmp']; // pas de SVG - $extension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)); - if(!in_array($extension, $allowed_extensions) || $extension === 'jpg'){ - $extension = 'jpeg'; - } - $mime_type = mime_content_type($file['tmp_name']); - $hash = hash_file('sha256', $file['tmp_name']); - - /* -- instance d'Asset -- */ - $model = new Model($entityManager); - $result = $model->getWhatever('App\Entity\Asset', 'hash', $hash); - - if(count($result) > 0){ // asset existant trouvé - $asset = $result[0]; - - // correction des informations - $name = $asset->getFileName(); // permet à priori de réécrire par dessus le précédent fichier - //$asset->setFileName($name); - $asset->setMimeType($mime_type); - } - else{ - $name = Security::secureFileName(pathinfo($file['name'], PATHINFO_FILENAME)); - $name = uniqid($name . '_') . '.' . $extension; - $asset = new Asset($name, $mime_type, $hash); - } - - /* -- écriture du fichier sur le disque -- */ - if(!ImageUploadController::imagickCleanAndWriteImage(file_get_contents($file['tmp_name']), Asset::USER_PATH . $name)){ // recréer l’image pour la nettoyer - return new JsonResponse(['success' => false, 'message' => "Erreur de l'enregistrement de l'image: problème de permission ou format non valide.", 'format' => $extension], JsonResponse::HTTP_INTERNAL_SERVER_ERROR); // code 500 - } - else{ - $params_array = explode('_', $request_params); // head_favicon, header_logo, header_background, footer_logo - - /* -- table intermédiaire node_data/asset-- */ - if($model->findWhateverNode('name_node', $params_array[0])){ // noeud (head, header ou footer) - $node_data = $model->getNode()->getNodeData(); - - // recherche à l'aide du rôle - $old_nda = null; - foreach($node_data->getNodeDataAssets() as $nda){ - if($nda->getRole() === $request_params){ - $old_nda = $nda; - $old_nda->setAsset($asset); - break; - } - } - // entrée pas trouvée - if($old_nda === null){ - $new_nda = new AssetEmployment($node_data, $asset, $request_params); // $request_params sera le rôle de l'asset - $entityManager->persist($new_nda); - } - - if(count($result) === 0){ - $entityManager->persist($asset); - } - $entityManager->flush(); - return new JsonResponse(['success' => true, 'location' => Asset::USER_PATH . $name, 'mime_type' => $mime_type]); - } - else{ - return new JsonResponse(['success' => false, 'message' => "Erreur noeud non trouvé, c'est pas du tout normal!"], JsonResponse::HTTP_INTERNAL_SERVER_ERROR); // code 500 - } - } - } - } - - static public function displaySocialNetwork(EntityManager $entityManager, string $request_params, array $json): JsonResponse - { - $params_array = explode('_', $request_params); - if(count($params_array) !== 2){ - return new JsonResponse(['success' => false]); - } - - $model = new Model($entityManager); - if(in_array($params_array[1], NodeData::$social_networks) && $model->findWhateverNode('name_node', $params_array[0])){ - $node_data = $model->getNode()->getNodeData(); - $social_show = $node_data->getData()['social_show'] ?? []; - $social_show[$params_array[1]] = $json['checked']; - $node_data->updateData('social_show', $social_show); - - $entityManager->flush(); - return new JsonResponse(['success' => true, 'checked' => $json['checked']]); - } - else{ - return new JsonResponse(['success' => false]); - } - } -} \ No newline at end of file -- cgit v1.2.3