diff options
Diffstat (limited to 'model/Article.php')
-rw-r--r-- | model/Article.php | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/model/Article.php b/model/Article.php new file mode 100644 index 0000000..cee594f --- /dev/null +++ b/model/Article.php | |||
@@ -0,0 +1,84 @@ | |||
1 | <?php | ||
2 | // model/Article.php | ||
3 | |||
4 | class Article | ||
5 | { | ||
6 | private $page = ''; // page et donc dossier concerné | ||
7 | private $croissant = True; // ordre des éléments du tableau $files | ||
8 | private $files; // noms des fichiers d'un dossier | ||
9 | private $nbArticles; // peut servir | ||
10 | private $articles; // contenu de ces mêmes fichiers | ||
11 | |||
12 | private function getFiles() | ||
13 | { | ||
14 | if($this->page == '') | ||
15 | { | ||
16 | die("debug: la méthode setPage() doit être appelée avant toute autre."); | ||
17 | } | ||
18 | |||
19 | $this->files = glob('data/' . $this->page . '/html/*.html'); | ||
20 | |||
21 | if($croissant == False) | ||
22 | { | ||
23 | $files = array_reverse($files); | ||
24 | } | ||
25 | |||
26 | $this->nbArticles = count($this->files); | ||
27 | } | ||
28 | |||
29 | public function getNb() | ||
30 | { | ||
31 | return $this->nbArticles; | ||
32 | } | ||
33 | |||
34 | public function getAll($croissant) | ||
35 | { | ||
36 | $this->croissant = $croissant; | ||
37 | |||
38 | getFiles(); | ||
39 | |||
40 | $i = 0; | ||
41 | foreach ($this->files as $file) | ||
42 | { | ||
43 | $articles[$i] = file_get_contents($file); | ||
44 | $i++; | ||
45 | } | ||
46 | |||
47 | return $articles; | ||
48 | } | ||
49 | |||
50 | public function getOne() | ||
51 | {} | ||
52 | |||
53 | public function getDate($fileNumber) | ||
54 | { | ||
55 | // le 2è paramètre exclut le suffixe .html | ||
56 | $timestamp = basename($this->files[$fileNumber], '.html'); | ||
57 | return getdate($timestamp); | ||
58 | } | ||
59 | |||
60 | public function new($content) | ||
61 | { | ||
62 | if($this->page == '') | ||
63 | { | ||
64 | die("debug: la méthode setPage() doit être appelée avant toute autre."); | ||
65 | } | ||
66 | |||
67 | $nom_fichier = time() . '.html'; | ||
68 | $fichier = fopen('data/' . $this->page . '/html/' . $nom_fichier, 'w'); // w peut créer un fichier, si il existe déjà, il est effacé par le nouveau contenu | ||
69 | fputs($fichier, $content); | ||
70 | fclose($fichier); | ||
71 | chmod('data/' . $this->page . '/html/' . $nom_fichier, 0666); | ||
72 | } | ||
73 | |||
74 | public function update() | ||
75 | {} | ||
76 | |||
77 | public function remove() | ||
78 | {} | ||
79 | |||
80 | public function setPage($page) | ||
81 | { | ||
82 | $this->page = $page; | ||
83 | } | ||
84 | } \ No newline at end of file | ||