diff options
| author | polo <ordipolo@gmx.fr> | 2025-03-23 15:21:46 +0100 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2025-03-23 15:21:46 +0100 |
| commit | a2bfa172e9184f220469a40611d70177e9c02bca (patch) | |
| tree | e470ac66bb419cce22e86c064cd6296fbe66a9b7 | |
| parent | 3c474461ca5dd8f54aee29efbc2156df025025e0 (diff) | |
| download | tinymce-a2bfa172e9184f220469a40611d70177e9c02bca.tar.gz tinymce-a2bfa172e9184f220469a40611d70177e9c02bca.tar.bz2 tinymce-a2bfa172e9184f220469a40611d70177e9c02bca.zip | |
affichage toolbar, bouton suppression
| -rw-r--r-- | public/index.php | 70 |
1 files changed, 61 insertions, 9 deletions
diff --git a/public/index.php b/public/index.php index 81a0408..233d85d 100644 --- a/public/index.php +++ b/public/index.php | |||
| @@ -4,9 +4,8 @@ if(isset($_GET['action']) && $_GET['action'] == 'editor_submit'){ | |||
| 4 | $data = file_get_contents('php://input'); | 4 | $data = file_get_contents('php://input'); |
| 5 | $json = json_decode($data, true); | 5 | $json = json_decode($data, true); |
| 6 | 6 | ||
| 7 | // Vérifier du décodage du JSON | ||
| 8 | if(json_last_error() === JSON_ERROR_NONE) { | 7 | if(json_last_error() === JSON_ERROR_NONE) { |
| 9 | // Traitement les données... | 8 | // Traitement côté serveur |
| 10 | $articleId = $json['id']; | 9 | $articleId = $json['id']; |
| 11 | $content = $json['content']; | 10 | $content = $json['content']; |
| 12 | 11 | ||
| @@ -18,6 +17,26 @@ if(isset($_GET['action']) && $_GET['action'] == 'editor_submit'){ | |||
| 18 | } | 17 | } |
| 19 | die; | 18 | die; |
| 20 | } | 19 | } |
| 20 | elseif(isset($_GET['action']) && $_GET['action'] == 'delete_article'){ | ||
| 21 | // récupération des données | ||
| 22 | $post = json_decode(file_get_contents('php://input'), true); | ||
| 23 | //echo $post['id']; | ||
| 24 | |||
| 25 | if(json_last_error() === JSON_ERROR_NONE){ | ||
| 26 | // Traitement côté serveur | ||
| 27 | $success = true; | ||
| 28 | |||
| 29 | // retour au client | ||
| 30 | if($success) { | ||
| 31 | echo json_encode(['success' => true]); | ||
| 32 | } | ||
| 33 | else { | ||
| 34 | http_response_code(500); | ||
| 35 | echo json_encode(['success' => false, 'message' => 'Erreur lors de la suppression de l\'article.']); | ||
| 36 | } | ||
| 37 | } | ||
| 38 | die; | ||
| 39 | } | ||
| 21 | elseif(isset($_GET['action']) && $_GET['action'] == 'upload_image'){ | 40 | elseif(isset($_GET['action']) && $_GET['action'] == 'upload_image'){ |
| 22 | if (isset($_FILES['file'])) { | 41 | if (isset($_FILES['file'])) { |
| 23 | $file = $_FILES['file']; | 42 | $file = $_FILES['file']; |
| @@ -30,8 +49,8 @@ elseif(isset($_GET['action']) && $_GET['action'] == 'upload_image'){ | |||
| 30 | 49 | ||
| 31 | $filePath = $dest . basename($file['name']); | 50 | $filePath = $dest . basename($file['name']); |
| 32 | if(move_uploaded_file($file['tmp_name'], $filePath)) { | 51 | if(move_uploaded_file($file['tmp_name'], $filePath)) { |
| 33 | // Répondre avec l'URL de l'image téléchargée | 52 | $image_url = str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']); |
| 34 | echo json_encode(['location' => '/' . $filePath]); | 53 | echo json_encode(['location' => $image_url . $filePath]); // renvoyer l'URL de l'image téléchargée |
| 35 | } | 54 | } |
| 36 | else{ | 55 | else{ |
| 37 | http_response_code(500); | 56 | http_response_code(500); |
| @@ -44,6 +63,7 @@ elseif(isset($_GET['action']) && $_GET['action'] == 'upload_image'){ | |||
| 44 | } | 63 | } |
| 45 | die; | 64 | die; |
| 46 | } | 65 | } |
| 66 | |||
| 47 | ?> | 67 | ?> |
| 48 | <!DOCTYPE html> | 68 | <!DOCTYPE html> |
| 49 | <html lang="fr"> | 69 | <html lang="fr"> |
| @@ -58,6 +78,12 @@ elseif(isset($_GET['action']) && $_GET['action'] == 'upload_image'){ | |||
| 58 | .hidden{ | 78 | .hidden{ |
| 59 | display: none; | 79 | display: none; |
| 60 | } | 80 | } |
| 81 | figure .align-center{ | ||
| 82 | |||
| 83 | } | ||
| 84 | figcaption { | ||
| 85 | |||
| 86 | } | ||
| 61 | </style> | 87 | </style> |
| 62 | <script src="../node_modules/tinymce/tinymce.min.js"></script> | 88 | <script src="../node_modules/tinymce/tinymce.min.js"></script> |
| 63 | <!-- peut-être qu'on devra utiliser un lien symbolique vers ce fichier dans /public --> | 89 | <!-- peut-être qu'on devra utiliser un lien symbolique vers ce fichier dans /public --> |
| @@ -74,8 +100,11 @@ elseif(isset($_GET['action']) && $_GET['action'] == 'upload_image'){ | |||
| 74 | language: 'fr_FR', // télécharger le paquet correspondant ici: https://www.tiny.cloud/get-tiny/language-packages/ | 100 | language: 'fr_FR', // télécharger le paquet correspondant ici: https://www.tiny.cloud/get-tiny/language-packages/ |
| 75 | license_key: 'gpl', | 101 | license_key: 'gpl', |
| 76 | branding: false, | 102 | branding: false, |
| 77 | plugins: 'lists advlist link autolink table image media autoresize help', | 103 | plugins: 'lists link autolink table image media autoresize help', |
| 78 | toolbar: 'undo redo print | styles | bold italic underline strikethrough | align outdent indent | numlist bullist | link table image media | help', | 104 | toolbar: 'undo redo newdocument print selectall styles bold italic underline strikethrough fontsize forecolor backcolor fontfamily align numlist bullist outdent indent table link image media help', |
| 105 | menubar: false, | ||
| 106 | toolbar_mode: 'wrap', | ||
| 107 | statusbar: false, | ||
| 79 | setup: function (editor) { | 108 | setup: function (editor) { |
| 80 | editor.on('init', function () { | 109 | editor.on('init', function () { |
| 81 | editors[articleId] = editor; | 110 | editors[articleId] = editor; |
| @@ -108,7 +137,8 @@ elseif(isset($_GET['action']) && $_GET['action'] == 'upload_image'){ | |||
| 108 | .catch(error => { | 137 | .catch(error => { |
| 109 | reject("Erreur lors de l'upload"); | 138 | reject("Erreur lors de l'upload"); |
| 110 | }); | 139 | }); |
| 111 | }) | 140 | }), |
| 141 | image_caption: true | ||
| 112 | }); | 142 | }); |
| 113 | 143 | ||
| 114 | // Remplacer le contenu de l'article par l'éditeur | 144 | // Remplacer le contenu de l'article par l'éditeur |
| @@ -116,8 +146,30 @@ elseif(isset($_GET['action']) && $_GET['action'] == 'upload_image'){ | |||
| 116 | } | 146 | } |
| 117 | 147 | ||
| 118 | function deleteArticle(articleId) { | 148 | function deleteArticle(articleId) { |
| 119 | console.log("suppression"); | 149 | if (confirm('Voulez-vous vraiment supprimer cet article ?')) { |
| 120 | // code similaire à submitArticle() | 150 | // Envoyer une requête au serveur pour supprimer l'article |
| 151 | fetch('index.php?action=delete_article', { | ||
| 152 | method: 'POST', | ||
| 153 | headers: { | ||
| 154 | 'Content-Type': 'application/json' | ||
| 155 | }, | ||
| 156 | body: JSON.stringify({ id: articleId }) | ||
| 157 | }) | ||
| 158 | .then(response => response.json()) | ||
| 159 | .then(data => { | ||
| 160 | if (data.success) { | ||
| 161 | // Supprimer l'article du DOM | ||
| 162 | const articleElement = document.getElementById(articleId); | ||
| 163 | articleElement.parentElement.remove(); | ||
| 164 | } | ||
| 165 | else { | ||
| 166 | alert('Erreur lors de la suppression de l\'article.'); | ||
| 167 | } | ||
| 168 | }) | ||
| 169 | .catch(error => { | ||
| 170 | console.error('Erreur:', error); | ||
| 171 | }); | ||
| 172 | } | ||
| 121 | } | 173 | } |
| 122 | 174 | ||
| 123 | function closeEditor(articleId) { | 175 | function closeEditor(articleId) { |
