From fdef77d4a8817b6e8940951f3301ad94bde0e6c6 Mon Sep 17 00:00:00 2001 From: polo Date: Mon, 5 Jun 2023 14:51:09 +0200 Subject: suppression de $_SESSION['file_code'] --- controller/ckeditor.php | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) (limited to 'controller/ckeditor.php') diff --git a/controller/ckeditor.php b/controller/ckeditor.php index 3765261..7b4f1bb 100644 --- a/controller/ckeditor.php +++ b/controller/ckeditor.php @@ -31,6 +31,29 @@ function preparationCKeditor($html) return($html); } +// utilisée par submitCKeditor() +function getFileCodeFromHTTPReferrer(): string +{ + if(isset($_SERVER['HTTP_REFERER'])) + { + $referrer = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_QUERY); + $pattern = '#file_code=#'; + $split = preg_split($pattern, $referrer); + if(isset($split[1]) && is_numeric($split[1])) + { + return $split[1]; + } + else + { + return ''; + } + } + else + { + return ''; + } +} + // réception du HTML créé par l'éditeur function submitCKeditor() { @@ -66,11 +89,12 @@ function submitCKeditor() if($_GET['page'] === 'discographie' || $_GET['page'] === 'album') { $Album = new Album($_GET['page'], 'discographie'); + + $Album->fileCode = getFileCodeFromHTTPReferrer(); // on retrouve les données si nécessaire - if(isset($_SESSION['file_code']) && $_SESSION['file_code'] != '') + if($Album->fileCode != '') { - $Album->fileCode = $_SESSION['file_code']; $Album->readOne(); } @@ -87,7 +111,6 @@ function submitCKeditor() $Image->setThumbnailWidth(201); $nouvellePochette = $nomFichier; - /*$nouvellePochetteMini = pathinfo($_FILES['upload']['name'], PATHINFO_FILENAME) . '-mini.' . pathinfo($_FILES['upload']['name'], PATHINFO_EXTENSION);*/ $nouvellePochetteMini = pathinfo($nomFichier, PATHINFO_FILENAME) . '-mini.' . pathinfo($nomFichier, PATHINFO_EXTENSION); $Image->upload(); @@ -104,11 +127,9 @@ function submitCKeditor() $nouvellePochette = ''; $nouvellePochetteMini = ''; } - - //var_dump($nouvellePochetteMini); die(); // enregistrement du texte JSON - if(!isset($_SESSION['file_code']) || $_SESSION['file_code'] == '') + if($Album->fileCode === '') { // page disco $Album->createVignetteJSON($nouveauTitre, $nouvelleAnnee, $nouvellePochette, $nouvellePochetteMini); @@ -123,8 +144,6 @@ function submitCKeditor() // modification else { - $Album->albumCode = $_SESSION['file_code']; - // page disco $Album->format = 'json'; @@ -142,7 +161,9 @@ function submitCKeditor() { $Article = new Article($_GET['page'], $_GET['page']); - if(!isset($_SESSION['file_code']) || $_SESSION['file_code'] === '') + $Article->fileCode = getFileCodeFromHTTPReferrer(); + + if($Article->fileCode === '') { $Article->create($html); @@ -150,16 +171,12 @@ function submitCKeditor() } else { - $Article->fileCode = $_SESSION['file_code']; // erreur ici? $Article->update($html); // update html-mini } } - // nettoyage - unset($_SESSION['file_code']); - if($_GET['page'] === 'discographie' || $_GET['page'] === 'album') { if($html === '') -- cgit v1.2.3