diff options
author | polo <ordipolo@gmx.fr> | 2021-11-29 03:25:19 +0100 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2021-11-29 03:25:19 +0100 |
commit | 29df6f1362745eabf4fbcaedf309eb63795152fa (patch) | |
tree | 8c2f4839c119db193eca4f35aeac96356a8ef439 /model | |
parent | b97a68343ec5c4ff1fae25ff5dc41f1a2ce6a17f (diff) | |
download | melaine-29df6f1362745eabf4fbcaedf309eb63795152fa.zip |
discographie
Diffstat (limited to 'model')
-rw-r--r-- | model/Album.php | 73 | ||||
-rw-r--r-- | model/Image.php | 16 | ||||
-rw-r--r-- | model/Page.php | 15 |
3 files changed, 84 insertions, 20 deletions
diff --git a/model/Album.php b/model/Album.php index 2254c10..1631c46 100644 --- a/model/Album.php +++ b/model/Album.php | |||
@@ -6,6 +6,7 @@ class Album extends Page // classe "objet" | |||
6 | public function __construct($page) | 6 | public function __construct($page) |
7 | { | 7 | { |
8 | $this->page = $page; | 8 | $this->page = $page; |
9 | $this->albumCode = ''; // désigne un fichier json et un html | ||
9 | $this->format = 'json'; // vaut 'html' dans la classe mère | 10 | $this->format = 'json'; // vaut 'html' dans la classe mère |
10 | $this->time = time(); | 11 | $this->time = time(); |
11 | } | 12 | } |
@@ -19,7 +20,7 @@ class Album extends Page // classe "objet" | |||
19 | // create | 20 | // create |
20 | public function createVignette($titre, $annee, $pochette) | 21 | public function createVignette($titre, $annee, $pochette) |
21 | { | 22 | { |
22 | $this->format = 'json'; | 23 | //$this->format = 'json'; |
23 | 24 | ||
24 | if($pochette != '') | 25 | if($pochette != '') |
25 | { | 26 | { |
@@ -28,7 +29,7 @@ class Album extends Page // classe "objet" | |||
28 | $Image = new Image(false); | 29 | $Image = new Image(false); |
29 | $Image->upload(); | 30 | $Image->upload(); |
30 | 31 | ||
31 | /*$erreur = $Image->getError(); | 32 | /*$erreur = $Image->erreur; |
32 | if(!empty($erreur)) | 33 | if(!empty($erreur)) |
33 | {}*/ | 34 | {}*/ |
34 | } | 35 | } |
@@ -41,18 +42,41 @@ class Album extends Page // classe "objet" | |||
41 | fputs($fichier, $albumJSON); | 42 | fputs($fichier, $albumJSON); |
42 | fclose($fichier); | 43 | fclose($fichier); |
43 | chmod($nom_fichier, 0666); | 44 | chmod($nom_fichier, 0666); |
45 | |||
46 | return($Image->erreur); | ||
44 | } | 47 | } |
45 | 48 | ||
46 | // read | 49 | // read |
47 | public function getVignette() | 50 | public function readAll() |
51 | { | ||
52 | // lecture des données | ||
53 | $albumsJSON = parent::readAll(); | ||
54 | |||
55 | // conversion des chaines JSON en tableaux: titre, année, pochette | ||
56 | for($i = 0; $i < count($albumsJSON); $i++) | ||
57 | { | ||
58 | $albumsJSON[$i] = json_decode($albumsJSON[$i], true); | ||
59 | } | ||
60 | |||
61 | return($albumsJSON); | ||
62 | } | ||
63 | |||
64 | public function getVignetteJSON() | ||
48 | { | 65 | { |
49 | return(file_get_contents($this->fileName)); | 66 | return(json_decode(file_get_contents('data/discographie/json/' . $this->albumCode . '.json'))); |
50 | } | 67 | } |
51 | 68 | ||
52 | // page de l'album | 69 | // page de l'album |
53 | public static function readOneAlbum($albumCode) | 70 | public static function readOneHTML($albumCode) |
54 | { | 71 | { |
55 | return(file_get_contents('data/discographie/html/' . $albumCode . '.html')); | 72 | if(file_exists('data/discographie/html/' . $albumCode . '.html')) |
73 | { | ||
74 | return(file_get_contents('data/discographie/html/' . $albumCode . '.html')); | ||
75 | } | ||
76 | else | ||
77 | { | ||
78 | return(''); | ||
79 | } | ||
56 | } | 80 | } |
57 | 81 | ||
58 | // pour afficher des dates | 82 | // pour afficher des dates |
@@ -64,12 +88,43 @@ class Album extends Page // classe "objet" | |||
64 | }*/ | 88 | }*/ |
65 | 89 | ||
66 | // update | 90 | // update |
67 | public function updateVignette() | 91 | public function updateVignetteJSON($titre, $annee, $pochette) |
68 | {} | 92 | { |
93 | // garder l'ancienne image | ||
94 | $albumJSON = self::getVignetteJSON(); | ||
95 | |||
96 | if($pochette == '') | ||
97 | { | ||
98 | $pochette = $albumJSON[2]; | ||
99 | } | ||
100 | else | ||
101 | { | ||
102 | // télécharger la pochette | ||
103 | require('model/Image.php'); | ||
104 | $Image = new Image(false); | ||
105 | $Image->upload(); | ||
106 | } | ||
107 | |||
108 | $albumJSON = json_encode([$titre, $annee, $pochette]); | ||
109 | |||
110 | // écriture | ||
111 | $nom_fichier = 'data/discographie/json/' . $this->albumCode . '.json'; | ||
112 | $fichier = fopen($nom_fichier, 'w+'); // w pour créer ou écraser | ||
113 | fputs($fichier, $albumJSON); | ||
114 | fclose($fichier); | ||
115 | chmod($nom_fichier, 0666); | ||
116 | |||
117 | return($Image->erreur); | ||
118 | } | ||
69 | 119 | ||
70 | // delete | 120 | // delete |
71 | public function delete() | 121 | public function delete() |
72 | { | 122 | { |
73 | unlink($this->fileName); | 123 | unlink('data/' . $this->page . '/' . $this->format . '/' . $this->albumCode . '.json'); |
124 | |||
125 | if(file_exists('data/' . $this->page . '/html/' . $this->albumCode . '.html')); | ||
126 | { | ||
127 | unlink('data/' . $this->page . '/html/' . $this->albumCode . '.html'); | ||
128 | } | ||
74 | } | 129 | } |
75 | } | 130 | } |
diff --git a/model/Image.php b/model/Image.php index efd75cc..51d2fa4 100644 --- a/model/Image.php +++ b/model/Image.php | |||
@@ -3,10 +3,10 @@ | |||
3 | 3 | ||
4 | class Image | 4 | class Image |
5 | { | 5 | { |
6 | private const MAX_WEIGHT = 2000000; // taille max des images (par défaut 2Mo dans php.ini) | 6 | private const MAX_WEIGHT = 2000000; // à adapter au php.ini |
7 | private $page; | 7 | private $page; |
8 | private $ajax = false; | 8 | private $ajax = false; // vaut true avec le ckeditor |
9 | public $erreur = ''; | 9 | public $erreur; |
10 | 10 | ||
11 | public function __construct($ajax) | 11 | public function __construct($ajax) |
12 | { | 12 | { |
@@ -37,19 +37,21 @@ class Image | |||
37 | } | 37 | } |
38 | else{$this->erreur = 'mauvais format, veuillez utiliser une image comportant un de ces formats: jpg ou jpeg, png, gif, bmp, webp, tiff<br />le format svg n\'est pas supporté';} | 38 | else{$this->erreur = 'mauvais format, veuillez utiliser une image comportant un de ces formats: jpg ou jpeg, png, gif, bmp, webp, tiff<br />le format svg n\'est pas supporté';} |
39 | } | 39 | } |
40 | else{$this->erreur = 'fichier trop lourd';} | 40 | else |
41 | { | ||
42 | $this->erreur = 'erreur du serveur: le fichier téléchargé est trop lourd, poids max = ' . self::MAX_WEIGHT . ' octets'; | ||
43 | } | ||
41 | } | 44 | } |
42 | else | 45 | else |
43 | { | 46 | { |
44 | $this->erreur = $_FILES['upload']['error']; | 47 | $this->erreur = 'erreur du serveur: le fichier téléchargé est trop lourd, poids max = ' . self::MAX_WEIGHT . ' octets'; |
45 | } | 48 | } |
46 | 49 | ||
47 | // retour des rêquetes AJAX | 50 | // retour des rêquetes AJAX |
48 | if($this->ajax) | 51 | if($this->ajax && empty($Image->erreur)) |
49 | { | 52 | { |
50 | // nouveau chemin à renvoyer en format json | 53 | // nouveau chemin à renvoyer en format json |
51 | $chemin = '{"url": "data/' . $this->page . '/images/' . $_FILES['upload']['name'] . '"}'; | 54 | $chemin = '{"url": "data/' . $this->page . '/images/' . $_FILES['upload']['name'] . '"}'; |
52 | //echo json_encode($chemin); | ||
53 | echo $chemin; | 55 | echo $chemin; |
54 | } | 56 | } |
55 | } | 57 | } |
diff --git a/model/Page.php b/model/Page.php index e03efe1..63730d8 100644 --- a/model/Page.php +++ b/model/Page.php | |||
@@ -13,10 +13,9 @@ class Page // classe "objet" | |||
13 | public $fileName = ''; // correspond à $_SESSION['nomFichier'] | 13 | public $fileName = ''; // correspond à $_SESSION['nomFichier'] |
14 | protected $time; // timestamp pour noms des fichiers créés | 14 | protected $time; // timestamp pour noms des fichiers créés |
15 | 15 | ||
16 | public function __construct($page, $format) | 16 | public function __construct($page) |
17 | { | 17 | { |
18 | $this->page = $page; | 18 | $this->page = $page; |
19 | $this->format = $format; | ||
20 | $this->time = time(); | 19 | $this->time = time(); |
21 | $this->makeFileList(); | 20 | $this->makeFileList(); |
22 | } | 21 | } |
@@ -39,6 +38,14 @@ class Page // classe "objet" | |||
39 | } | 38 | } |
40 | } | 39 | } |
41 | 40 | ||
41 | public function setFileName() | ||
42 | { | ||
43 | if(file_exists('data/' . $this->page . '/' . $this->format . '/' . $this->albumCode . '.' . $this->format)) | ||
44 | { | ||
45 | $this->fileName = 'data/' . $this->page . '/' . $this->format . '/' . $this->albumCode . '.' . $this->format; | ||
46 | } | ||
47 | } | ||
48 | |||
42 | // GET | 49 | // GET |
43 | 50 | ||
44 | // SET | 51 | // SET |
@@ -48,7 +55,7 @@ class Page // classe "objet" | |||
48 | // create | 55 | // create |
49 | public function create($content) | 56 | public function create($content) |
50 | { | 57 | { |
51 | $format = 'html'; | 58 | //$format = 'html'; |
52 | 59 | ||
53 | // nommer les fichiers avec le timestamp pour: | 60 | // nommer les fichiers avec le timestamp pour: |
54 | // - les trier par ordre chronologique | 61 | // - les trier par ordre chronologique |
@@ -65,7 +72,7 @@ class Page // classe "objet" | |||
65 | public function readAll() | 72 | public function readAll() |
66 | { | 73 | { |
67 | $i = 0; | 74 | $i = 0; |
68 | $articles = array(); | 75 | $articles = []; |
69 | foreach ($this->fileList as $oneFile) | 76 | foreach ($this->fileList as $oneFile) |
70 | { | 77 | { |
71 | $articles[$i] = file_get_contents($oneFile); | 78 | $articles[$i] = file_get_contents($oneFile); |