From 90b3efeeb9d939303ff80b180725e06e2e57af79 Mon Sep 17 00:00:00 2001 From: polo Date: Thu, 13 Apr 2023 03:02:57 +0200 Subject: =?UTF-8?q?=C3=A9diteur=20page=20album?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/Album.php | 22 +++++++++++----------- model/Article.php | 40 +++++++++++++++++++++++----------------- model/Image.php | 22 +++++++++++++++------- 3 files changed, 49 insertions(+), 35 deletions(-) (limited to 'model') diff --git a/model/Album.php b/model/Album.php index b4b7afe..d2537f7 100644 --- a/model/Album.php +++ b/model/Album.php @@ -5,12 +5,12 @@ class Album extends Article { public $oneAlbum; - public function __construct($page) + public function __construct(string $page, string $folder) { $this->format = 'json'; // vaut 'html' dans la classe mère // pour: page, fileCode, time et makeFileList() - parent::__construct($page); + parent::__construct($page, $folder); } // GET @@ -49,7 +49,7 @@ class Album extends Article // télécharger la pochette require('model/Image.php'); - $Image = new Image(false); + $Image = new Image($this->page, $this->folder, false); $Image->upload(); $Image->makeThumbnail(201); @@ -61,7 +61,7 @@ class Album extends Article $albumJSON = json_encode([$titre, $annee, $pochette, $pochetteMini]); //var_dump($albumJSON); die(); - $nom_fichier = 'data/' . $this->page . '/' . $this->format . '/' . $this->time . '.' . $this->format; + $nom_fichier = 'data/' . $this->folder . '/' . $this->format . '/' . $this->time . '.' . $this->format; $fichier = fopen($nom_fichier, 'w'); // w pour créer ou écraser fputs($fichier, $albumJSON); @@ -95,9 +95,9 @@ class Album extends Article $this->fileList[$i]['pochetteMini'] = $content[3]; // ajout du HTML si il existe - if(file_exists('data/' . $this->page . '/' . $this->format . '/' . $this->fileList[$i]['fileCode'] . '.' . $this->format)) + if(file_exists('data/' . $this->folder . '/' . $this->format . '/' . $this->fileList[$i]['fileCode'] . '.' . $this->format)) { - $this->fileList[$i]['HTMLfileName'] = 'data/' . $this->page . '/' . $this->format . '/' . $this->fileList[$i]['fileCode'] . '.' . $this->format; + $this->fileList[$i]['HTMLfileName'] = 'data/' . $this->folder . '/' . $this->format . '/' . $this->fileList[$i]['fileCode'] . '.' . $this->format; $this->fileList[$i]['HTMLcontent'] = file_get_contents($this->fileList[$i]['HTMLfileName']); } // utile? @@ -120,7 +120,7 @@ class Album extends Article { // json $this->oneAlbum['fileCode'] = $this->fileList[$i]['fileCode']; - $this->oneAlbum['fileName'] = 'data/' . $this->page . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format; + $this->oneAlbum['fileName'] = 'data/' . $this->folder . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format; $this->oneAlbum['content'] = file_get_contents($this->fileList[$i]['fileName']); $content = json_decode($this->oneAlbum['content']); $this->oneAlbum['titre'] = $content[0]; @@ -130,9 +130,9 @@ class Album extends Article // html $this->format = 'html'; - if(file_exists('data/' . $this->page . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format)) + if(file_exists('data/' . $this->folder . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format)) { - $this->oneAlbum['HTMLfileName'] = 'data/' . $this->page . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format; + $this->oneAlbum['HTMLfileName'] = 'data/' . $this->folder . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format; $this->oneAlbum['HTMLcontent'] = file_get_contents($this->oneAlbum['HTMLfileName']); } } @@ -175,7 +175,7 @@ class Album extends Article { // télécharger la pochette require('model/Image.php'); - $Image = new Image(false); + $Image = new Image($this->page, $this->folder, false); $Image->upload(); $Image->makeThumbnail(201); $erreur = $Image->erreur; @@ -203,7 +203,7 @@ class Album extends Article { parent::delete(); // json - if(file_exists('data/' . $this->page . '/html/' . $this->fileCode . '.' . $this->format)); + if(file_exists('data/' . $this->folder . '/html/' . $this->fileCode . '.' . $this->format)); { $this->format = 'html'; parent::delete(); // html diff --git a/model/Article.php b/model/Article.php index 33848bb..2ea80f8 100644 --- a/model/Article.php +++ b/model/Article.php @@ -9,7 +9,8 @@ class Article { // pour tous les articles - public $page; // page et donc dossier concerné + public $page; // page du site + public $folder; // dossier des données (vaut souvent $page) public $format = 'html'; // 'html' ou 'json' public $fileListCount; // pour les boucles "for" // pas de "foreach", on a besoin des compteurs $i @@ -20,20 +21,29 @@ class Article public $fileCode = ''; // $_SESSION['target'] protected $time; // timestamp pour noms des fichiers créés - public function __construct($page) + public function __construct(string $page, string $folder) { $this->page = $page; + $this->folder = $folder; $this->time = time(); $this->makeFileList(); } + // GET + + // SET + public function setFolder(string $folder) + { + $this->folder = $folder; + } + // tableaux des noms des fichiers // noter que le chemin et l'extension ne varient pas public function makeFileList() { // noms des fichiers // globbing = utiliser un pattern pour cibler des fichiers - $nameList = glob('data/' . $this->page . '/' . $this->format . '/*.' . $this->format); + $nameList = glob('data/' . $this->folder . '/' . $this->format . '/*.' . $this->format); $this->fileListCount = count($nameList); @@ -77,10 +87,10 @@ class Article private function readPositionsJSON() // retourne array ou NULL { - if(file_exists('data/' . $this->page . '/positions.json')) + if(file_exists('data/' . $this->folder . '/positions.json')) { // "true" pour retourner un tableau et non un objet - $positions = json_decode(file_get_contents('data/' . $this->page . '/positions.json'), true); + $positions = json_decode(file_get_contents('data/' . $this->folder . '/positions.json'), true); } return $positions; } @@ -105,7 +115,7 @@ class Article $positions[$this->fileList[$i]['fileCode']] = $this->fileList[$i]['position']; } - file_put_contents('data/' . $this->page . '/positions.json', json_encode($positions)); + file_put_contents('data/' . $this->folder . '/positions.json', json_encode($positions)); } private function sortFileListByPositions() @@ -157,10 +167,6 @@ class Article return $content; } - - // GET - - // SET // fonctions CRUD (create - read - update - delete) @@ -177,7 +183,7 @@ class Article { // html version images normales $contentMaxi = $content; - $fileName = 'data/' . $this->page . '/' . $this->format . '-maxi-images/' . $this->time . '.' . $this->format; + $fileName = 'data/' . $this->folder . '/' . $this->format . '-maxi-images/' . $this->time . '.' . $this->format; $file = fopen($fileName, 'w'); // w pour créer ou écraser fputs($file, $contentMaxi); fclose($file); @@ -187,7 +193,7 @@ class Article $content = self::makeHtmlMiniImages($content); } - $fileName = 'data/' . $this->page . '/' . $this->format . '/' . $this->time . '.' . $this->format; + $fileName = 'data/' . $this->folder . '/' . $this->format . '/' . $this->time . '.' . $this->format; $file = fopen($fileName, 'w'); // w pour créer ou écraser fputs($file, $content); fclose($file); @@ -207,7 +213,7 @@ class Article } public function readOne() { - return(file_get_contents('data/' . $this->page . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format)); + return(file_get_contents('data/' . $this->folder . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format)); } // update @@ -217,7 +223,7 @@ class Article { // html version images normales $contentMaxi = $content; - $fileName = 'data/' . $this->page . '/' . $this->format . '-maxi-images/' . $this->fileCode . '.' . $this->format; + $fileName = 'data/' . $this->folder . '/' . $this->format . '-maxi-images/' . $this->fileCode . '.' . $this->format; if(file_exists($fileName) && empty($content)) { $this->delete(); @@ -235,7 +241,7 @@ class Article } // json ou html version petites images - $fileName = 'data/' . $this->page . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format; + $fileName = 'data/' . $this->folder . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format; if(file_exists($fileName) && empty($content)) { $this->delete(); @@ -252,11 +258,11 @@ class Article // delete public function delete() { - $path = 'data/' . $this->page . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format; + $path = 'data/' . $this->folder . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format; unlink($path); // fichiers html dans html-maxi-images - $path_maxi = 'data/' . $this->page . '/' . $this->format . '-maxi-images/' . $this->fileCode . '.' . $this->format; + $path_maxi = 'data/' . $this->folder . '/' . $this->format . '-maxi-images/' . $this->fileCode . '.' . $this->format; if(file_exists($path_maxi)) { unlink($path_maxi); diff --git a/model/Image.php b/model/Image.php index 1cc0e22..d71b96a 100644 --- a/model/Image.php +++ b/model/Image.php @@ -4,6 +4,7 @@ class Image { private $page; + private $folder; private $ajax; // vaut true avec le ckeditor public $reponseAjax; @@ -13,18 +14,25 @@ class Image public $pathInfos; public $erreur; - public function __construct($ajax) + public function __construct(string $page, string $folder, bool $ajax) { - // get envoyé avec le javascript $this->ajax = $ajax; - $this->page = $_GET['page']; - $this->path = 'data/' . $this->page . '/images/'; - $this->pathMini = 'data/' . $this->page . '/images-mini/'; + $this->page = $page; + $this->folder = $folder; + $this->path = 'data/' . $this->folder . '/images/'; + $this->pathMini = 'data/' . $this->folder . '/images-mini/'; } // GET // SET + public function setFolder(string $folder) + { + $this->folder = $folder; + $this->path = 'data/' . $this->folder . '/images/'; + $this->pathMini = 'data/' . $this->folder . '/images-mini/'; + } + public function upload() { @@ -55,7 +63,7 @@ class Image if($this->ajax && empty($Image->erreur)) { // chemin en JSON attendu par l'éditeur - $this->reponseAjax = '{"url": "data/' . $this->page . '/images/' . $_FILES['upload']['name'] . '"}'; + $this->reponseAjax = '{"url": "data/' . $this->folder . '/images/' . $_FILES['upload']['name'] . '"}'; } } @@ -108,7 +116,7 @@ class Image // message d'erreur $_SESSION['erreur'] = addslashes("Echec de la création d'une miniature. Vérifier le fichier config.php"); - header('Location: index.php?page=' . $this->page . '&erreur=dependance_bibli_images'); + header('Location: index.php?page=' . $this->folder . '&erreur=dependance_bibli_images'); exit(); } } -- cgit v1.2.3