diff options
| author | polo <contact@ordipolo.fr> | 2023-04-13 03:02:57 +0200 |
|---|---|---|
| committer | polo <contact@ordipolo.fr> | 2023-04-13 03:02:57 +0200 |
| commit | 90b3efeeb9d939303ff80b180725e06e2e57af79 (patch) | |
| tree | 5e7de4e34d37988aae95ab26d876faf06d37eedb /model | |
| parent | 95ffc4febd33918a78a65053ee3d39cb19b259b2 (diff) | |
| download | melaine-90b3efeeb9d939303ff80b180725e06e2e57af79.tar.gz melaine-90b3efeeb9d939303ff80b180725e06e2e57af79.tar.bz2 melaine-90b3efeeb9d939303ff80b180725e06e2e57af79.zip | |
éditeur page album
Diffstat (limited to 'model')
| -rw-r--r-- | model/Album.php | 22 | ||||
| -rw-r--r-- | model/Article.php | 40 | ||||
| -rw-r--r-- | model/Image.php | 22 |
3 files changed, 49 insertions, 35 deletions
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 | |||
| 5 | { | 5 | { |
| 6 | public $oneAlbum; | 6 | public $oneAlbum; |
| 7 | 7 | ||
| 8 | public function __construct($page) | 8 | public function __construct(string $page, string $folder) |
| 9 | { | 9 | { |
| 10 | $this->format = 'json'; // vaut 'html' dans la classe mère | 10 | $this->format = 'json'; // vaut 'html' dans la classe mère |
| 11 | 11 | ||
| 12 | // pour: page, fileCode, time et makeFileList() | 12 | // pour: page, fileCode, time et makeFileList() |
| 13 | parent::__construct($page); | 13 | parent::__construct($page, $folder); |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | // GET | 16 | // GET |
| @@ -49,7 +49,7 @@ class Album extends Article | |||
| 49 | 49 | ||
| 50 | // télécharger la pochette | 50 | // télécharger la pochette |
| 51 | require('model/Image.php'); | 51 | require('model/Image.php'); |
| 52 | $Image = new Image(false); | 52 | $Image = new Image($this->page, $this->folder, false); |
| 53 | $Image->upload(); | 53 | $Image->upload(); |
| 54 | $Image->makeThumbnail(201); | 54 | $Image->makeThumbnail(201); |
| 55 | 55 | ||
| @@ -61,7 +61,7 @@ class Album extends Article | |||
| 61 | $albumJSON = json_encode([$titre, $annee, $pochette, $pochetteMini]); | 61 | $albumJSON = json_encode([$titre, $annee, $pochette, $pochetteMini]); |
| 62 | //var_dump($albumJSON); die(); | 62 | //var_dump($albumJSON); die(); |
| 63 | 63 | ||
| 64 | $nom_fichier = 'data/' . $this->page . '/' . $this->format . '/' . $this->time . '.' . $this->format; | 64 | $nom_fichier = 'data/' . $this->folder . '/' . $this->format . '/' . $this->time . '.' . $this->format; |
| 65 | 65 | ||
| 66 | $fichier = fopen($nom_fichier, 'w'); // w pour créer ou écraser | 66 | $fichier = fopen($nom_fichier, 'w'); // w pour créer ou écraser |
| 67 | fputs($fichier, $albumJSON); | 67 | fputs($fichier, $albumJSON); |
| @@ -95,9 +95,9 @@ class Album extends Article | |||
| 95 | $this->fileList[$i]['pochetteMini'] = $content[3]; | 95 | $this->fileList[$i]['pochetteMini'] = $content[3]; |
| 96 | 96 | ||
| 97 | // ajout du HTML si il existe | 97 | // ajout du HTML si il existe |
| 98 | if(file_exists('data/' . $this->page . '/' . $this->format . '/' . $this->fileList[$i]['fileCode'] . '.' . $this->format)) | 98 | if(file_exists('data/' . $this->folder . '/' . $this->format . '/' . $this->fileList[$i]['fileCode'] . '.' . $this->format)) |
| 99 | { | 99 | { |
| 100 | $this->fileList[$i]['HTMLfileName'] = 'data/' . $this->page . '/' . $this->format . '/' . $this->fileList[$i]['fileCode'] . '.' . $this->format; | 100 | $this->fileList[$i]['HTMLfileName'] = 'data/' . $this->folder . '/' . $this->format . '/' . $this->fileList[$i]['fileCode'] . '.' . $this->format; |
| 101 | $this->fileList[$i]['HTMLcontent'] = file_get_contents($this->fileList[$i]['HTMLfileName']); | 101 | $this->fileList[$i]['HTMLcontent'] = file_get_contents($this->fileList[$i]['HTMLfileName']); |
| 102 | } | 102 | } |
| 103 | // utile? | 103 | // utile? |
| @@ -120,7 +120,7 @@ class Album extends Article | |||
| 120 | { | 120 | { |
| 121 | // json | 121 | // json |
| 122 | $this->oneAlbum['fileCode'] = $this->fileList[$i]['fileCode']; | 122 | $this->oneAlbum['fileCode'] = $this->fileList[$i]['fileCode']; |
| 123 | $this->oneAlbum['fileName'] = 'data/' . $this->page . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format; | 123 | $this->oneAlbum['fileName'] = 'data/' . $this->folder . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format; |
| 124 | $this->oneAlbum['content'] = file_get_contents($this->fileList[$i]['fileName']); | 124 | $this->oneAlbum['content'] = file_get_contents($this->fileList[$i]['fileName']); |
| 125 | $content = json_decode($this->oneAlbum['content']); | 125 | $content = json_decode($this->oneAlbum['content']); |
| 126 | $this->oneAlbum['titre'] = $content[0]; | 126 | $this->oneAlbum['titre'] = $content[0]; |
| @@ -130,9 +130,9 @@ class Album extends Article | |||
| 130 | 130 | ||
| 131 | // html | 131 | // html |
| 132 | $this->format = 'html'; | 132 | $this->format = 'html'; |
| 133 | if(file_exists('data/' . $this->page . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format)) | 133 | if(file_exists('data/' . $this->folder . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format)) |
| 134 | { | 134 | { |
| 135 | $this->oneAlbum['HTMLfileName'] = 'data/' . $this->page . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format; | 135 | $this->oneAlbum['HTMLfileName'] = 'data/' . $this->folder . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format; |
| 136 | $this->oneAlbum['HTMLcontent'] = file_get_contents($this->oneAlbum['HTMLfileName']); | 136 | $this->oneAlbum['HTMLcontent'] = file_get_contents($this->oneAlbum['HTMLfileName']); |
| 137 | } | 137 | } |
| 138 | } | 138 | } |
| @@ -175,7 +175,7 @@ class Album extends Article | |||
| 175 | { | 175 | { |
| 176 | // télécharger la pochette | 176 | // télécharger la pochette |
| 177 | require('model/Image.php'); | 177 | require('model/Image.php'); |
| 178 | $Image = new Image(false); | 178 | $Image = new Image($this->page, $this->folder, false); |
| 179 | $Image->upload(); | 179 | $Image->upload(); |
| 180 | $Image->makeThumbnail(201); | 180 | $Image->makeThumbnail(201); |
| 181 | $erreur = $Image->erreur; | 181 | $erreur = $Image->erreur; |
| @@ -203,7 +203,7 @@ class Album extends Article | |||
| 203 | { | 203 | { |
| 204 | parent::delete(); // json | 204 | parent::delete(); // json |
| 205 | 205 | ||
| 206 | if(file_exists('data/' . $this->page . '/html/' . $this->fileCode . '.' . $this->format)); | 206 | if(file_exists('data/' . $this->folder . '/html/' . $this->fileCode . '.' . $this->format)); |
| 207 | { | 207 | { |
| 208 | $this->format = 'html'; | 208 | $this->format = 'html'; |
| 209 | parent::delete(); // html | 209 | 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 @@ | |||
| 9 | class Article | 9 | class Article |
| 10 | { | 10 | { |
| 11 | // pour tous les articles | 11 | // pour tous les articles |
| 12 | public $page; // page et donc dossier concerné | 12 | public $page; // page du site |
| 13 | public $folder; // dossier des données (vaut souvent $page) | ||
| 13 | public $format = 'html'; // 'html' ou 'json' | 14 | public $format = 'html'; // 'html' ou 'json' |
| 14 | public $fileListCount; // pour les boucles "for" | 15 | public $fileListCount; // pour les boucles "for" |
| 15 | // pas de "foreach", on a besoin des compteurs $i | 16 | // pas de "foreach", on a besoin des compteurs $i |
| @@ -20,20 +21,29 @@ class Article | |||
| 20 | public $fileCode = ''; // $_SESSION['target'] | 21 | public $fileCode = ''; // $_SESSION['target'] |
| 21 | protected $time; // timestamp pour noms des fichiers créés | 22 | protected $time; // timestamp pour noms des fichiers créés |
| 22 | 23 | ||
| 23 | public function __construct($page) | 24 | public function __construct(string $page, string $folder) |
| 24 | { | 25 | { |
| 25 | $this->page = $page; | 26 | $this->page = $page; |
| 27 | $this->folder = $folder; | ||
| 26 | $this->time = time(); | 28 | $this->time = time(); |
| 27 | $this->makeFileList(); | 29 | $this->makeFileList(); |
| 28 | } | 30 | } |
| 29 | 31 | ||
| 32 | // GET | ||
| 33 | |||
| 34 | // SET | ||
| 35 | public function setFolder(string $folder) | ||
| 36 | { | ||
| 37 | $this->folder = $folder; | ||
| 38 | } | ||
| 39 | |||
| 30 | // tableaux des noms des fichiers | 40 | // tableaux des noms des fichiers |
| 31 | // noter que le chemin et l'extension ne varient pas | 41 | // noter que le chemin et l'extension ne varient pas |
| 32 | public function makeFileList() | 42 | public function makeFileList() |
| 33 | { | 43 | { |
| 34 | // noms des fichiers | 44 | // noms des fichiers |
| 35 | // globbing = utiliser un pattern pour cibler des fichiers | 45 | // globbing = utiliser un pattern pour cibler des fichiers |
| 36 | $nameList = glob('data/' . $this->page . '/' . $this->format . '/*.' . $this->format); | 46 | $nameList = glob('data/' . $this->folder . '/' . $this->format . '/*.' . $this->format); |
| 37 | 47 | ||
| 38 | $this->fileListCount = count($nameList); | 48 | $this->fileListCount = count($nameList); |
| 39 | 49 | ||
| @@ -77,10 +87,10 @@ class Article | |||
| 77 | 87 | ||
| 78 | private function readPositionsJSON() // retourne array ou NULL | 88 | private function readPositionsJSON() // retourne array ou NULL |
| 79 | { | 89 | { |
| 80 | if(file_exists('data/' . $this->page . '/positions.json')) | 90 | if(file_exists('data/' . $this->folder . '/positions.json')) |
| 81 | { | 91 | { |
| 82 | // "true" pour retourner un tableau et non un objet | 92 | // "true" pour retourner un tableau et non un objet |
| 83 | $positions = json_decode(file_get_contents('data/' . $this->page . '/positions.json'), true); | 93 | $positions = json_decode(file_get_contents('data/' . $this->folder . '/positions.json'), true); |
| 84 | } | 94 | } |
| 85 | return $positions; | 95 | return $positions; |
| 86 | } | 96 | } |
| @@ -105,7 +115,7 @@ class Article | |||
| 105 | $positions[$this->fileList[$i]['fileCode']] = $this->fileList[$i]['position']; | 115 | $positions[$this->fileList[$i]['fileCode']] = $this->fileList[$i]['position']; |
| 106 | } | 116 | } |
| 107 | 117 | ||
| 108 | file_put_contents('data/' . $this->page . '/positions.json', json_encode($positions)); | 118 | file_put_contents('data/' . $this->folder . '/positions.json', json_encode($positions)); |
| 109 | } | 119 | } |
| 110 | 120 | ||
| 111 | private function sortFileListByPositions() | 121 | private function sortFileListByPositions() |
| @@ -157,10 +167,6 @@ class Article | |||
| 157 | 167 | ||
| 158 | return $content; | 168 | return $content; |
| 159 | } | 169 | } |
| 160 | |||
| 161 | // GET | ||
| 162 | |||
| 163 | // SET | ||
| 164 | 170 | ||
| 165 | // fonctions CRUD (create - read - update - delete) | 171 | // fonctions CRUD (create - read - update - delete) |
| 166 | 172 | ||
| @@ -177,7 +183,7 @@ class Article | |||
| 177 | { | 183 | { |
| 178 | // html version images normales | 184 | // html version images normales |
| 179 | $contentMaxi = $content; | 185 | $contentMaxi = $content; |
| 180 | $fileName = 'data/' . $this->page . '/' . $this->format . '-maxi-images/' . $this->time . '.' . $this->format; | 186 | $fileName = 'data/' . $this->folder . '/' . $this->format . '-maxi-images/' . $this->time . '.' . $this->format; |
| 181 | $file = fopen($fileName, 'w'); // w pour créer ou écraser | 187 | $file = fopen($fileName, 'w'); // w pour créer ou écraser |
| 182 | fputs($file, $contentMaxi); | 188 | fputs($file, $contentMaxi); |
| 183 | fclose($file); | 189 | fclose($file); |
| @@ -187,7 +193,7 @@ class Article | |||
| 187 | $content = self::makeHtmlMiniImages($content); | 193 | $content = self::makeHtmlMiniImages($content); |
| 188 | } | 194 | } |
| 189 | 195 | ||
| 190 | $fileName = 'data/' . $this->page . '/' . $this->format . '/' . $this->time . '.' . $this->format; | 196 | $fileName = 'data/' . $this->folder . '/' . $this->format . '/' . $this->time . '.' . $this->format; |
| 191 | $file = fopen($fileName, 'w'); // w pour créer ou écraser | 197 | $file = fopen($fileName, 'w'); // w pour créer ou écraser |
| 192 | fputs($file, $content); | 198 | fputs($file, $content); |
| 193 | fclose($file); | 199 | fclose($file); |
| @@ -207,7 +213,7 @@ class Article | |||
| 207 | } | 213 | } |
| 208 | public function readOne() | 214 | public function readOne() |
| 209 | { | 215 | { |
| 210 | return(file_get_contents('data/' . $this->page . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format)); | 216 | return(file_get_contents('data/' . $this->folder . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format)); |
| 211 | } | 217 | } |
| 212 | 218 | ||
| 213 | // update | 219 | // update |
| @@ -217,7 +223,7 @@ class Article | |||
| 217 | { | 223 | { |
| 218 | // html version images normales | 224 | // html version images normales |
| 219 | $contentMaxi = $content; | 225 | $contentMaxi = $content; |
| 220 | $fileName = 'data/' . $this->page . '/' . $this->format . '-maxi-images/' . $this->fileCode . '.' . $this->format; | 226 | $fileName = 'data/' . $this->folder . '/' . $this->format . '-maxi-images/' . $this->fileCode . '.' . $this->format; |
| 221 | if(file_exists($fileName) && empty($content)) | 227 | if(file_exists($fileName) && empty($content)) |
| 222 | { | 228 | { |
| 223 | $this->delete(); | 229 | $this->delete(); |
| @@ -235,7 +241,7 @@ class Article | |||
| 235 | } | 241 | } |
| 236 | 242 | ||
| 237 | // json ou html version petites images | 243 | // json ou html version petites images |
| 238 | $fileName = 'data/' . $this->page . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format; | 244 | $fileName = 'data/' . $this->folder . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format; |
| 239 | if(file_exists($fileName) && empty($content)) | 245 | if(file_exists($fileName) && empty($content)) |
| 240 | { | 246 | { |
| 241 | $this->delete(); | 247 | $this->delete(); |
| @@ -252,11 +258,11 @@ class Article | |||
| 252 | // delete | 258 | // delete |
| 253 | public function delete() | 259 | public function delete() |
| 254 | { | 260 | { |
| 255 | $path = 'data/' . $this->page . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format; | 261 | $path = 'data/' . $this->folder . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format; |
| 256 | unlink($path); | 262 | unlink($path); |
| 257 | 263 | ||
| 258 | // fichiers html dans html-maxi-images | 264 | // fichiers html dans html-maxi-images |
| 259 | $path_maxi = 'data/' . $this->page . '/' . $this->format . '-maxi-images/' . $this->fileCode . '.' . $this->format; | 265 | $path_maxi = 'data/' . $this->folder . '/' . $this->format . '-maxi-images/' . $this->fileCode . '.' . $this->format; |
| 260 | if(file_exists($path_maxi)) | 266 | if(file_exists($path_maxi)) |
| 261 | { | 267 | { |
| 262 | unlink($path_maxi); | 268 | 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 @@ | |||
| 4 | class Image | 4 | class Image |
| 5 | { | 5 | { |
| 6 | private $page; | 6 | private $page; |
| 7 | private $folder; | ||
| 7 | 8 | ||
| 8 | private $ajax; // vaut true avec le ckeditor | 9 | private $ajax; // vaut true avec le ckeditor |
| 9 | public $reponseAjax; | 10 | public $reponseAjax; |
| @@ -13,18 +14,25 @@ class Image | |||
| 13 | public $pathInfos; | 14 | public $pathInfos; |
| 14 | public $erreur; | 15 | public $erreur; |
| 15 | 16 | ||
| 16 | public function __construct($ajax) | 17 | public function __construct(string $page, string $folder, bool $ajax) |
| 17 | { | 18 | { |
| 18 | // get envoyé avec le javascript | ||
| 19 | $this->ajax = $ajax; | 19 | $this->ajax = $ajax; |
| 20 | $this->page = $_GET['page']; | 20 | $this->page = $page; |
| 21 | $this->path = 'data/' . $this->page . '/images/'; | 21 | $this->folder = $folder; |
| 22 | $this->pathMini = 'data/' . $this->page . '/images-mini/'; | 22 | $this->path = 'data/' . $this->folder . '/images/'; |
| 23 | $this->pathMini = 'data/' . $this->folder . '/images-mini/'; | ||
| 23 | } | 24 | } |
| 24 | 25 | ||
| 25 | // GET | 26 | // GET |
| 26 | 27 | ||
| 27 | // SET | 28 | // SET |
| 29 | public function setFolder(string $folder) | ||
| 30 | { | ||
| 31 | $this->folder = $folder; | ||
| 32 | $this->path = 'data/' . $this->folder . '/images/'; | ||
| 33 | $this->pathMini = 'data/' . $this->folder . '/images-mini/'; | ||
| 34 | } | ||
| 35 | |||
| 28 | 36 | ||
| 29 | public function upload() | 37 | public function upload() |
| 30 | { | 38 | { |
| @@ -55,7 +63,7 @@ class Image | |||
| 55 | if($this->ajax && empty($Image->erreur)) | 63 | if($this->ajax && empty($Image->erreur)) |
| 56 | { | 64 | { |
| 57 | // chemin en JSON attendu par l'éditeur | 65 | // chemin en JSON attendu par l'éditeur |
| 58 | $this->reponseAjax = '{"url": "data/' . $this->page . '/images/' . $_FILES['upload']['name'] . '"}'; | 66 | $this->reponseAjax = '{"url": "data/' . $this->folder . '/images/' . $_FILES['upload']['name'] . '"}'; |
| 59 | } | 67 | } |
| 60 | } | 68 | } |
| 61 | 69 | ||
| @@ -108,7 +116,7 @@ class Image | |||
| 108 | 116 | ||
| 109 | // message d'erreur | 117 | // message d'erreur |
| 110 | $_SESSION['erreur'] = addslashes("Echec de la création d'une miniature. Vérifier le fichier config.php"); | 118 | $_SESSION['erreur'] = addslashes("Echec de la création d'une miniature. Vérifier le fichier config.php"); |
| 111 | header('Location: index.php?page=' . $this->page . '&erreur=dependance_bibli_images'); | 119 | header('Location: index.php?page=' . $this->folder . '&erreur=dependance_bibli_images'); |
| 112 | exit(); | 120 | exit(); |
| 113 | } | 121 | } |
| 114 | } | 122 | } |
