diff options
Diffstat (limited to 'model/Page.php')
| -rw-r--r-- | model/Page.php | 104 |
1 files changed, 0 insertions, 104 deletions
diff --git a/model/Page.php b/model/Page.php deleted file mode 100644 index 63730d8..0000000 --- a/model/Page.php +++ /dev/null | |||
| @@ -1,104 +0,0 @@ | |||
| 1 | <?php | ||
| 2 | // model/Page.php | ||
| 3 | |||
| 4 | class Page // classe "objet" | ||
| 5 | { | ||
| 6 | public $page; // page et donc dossier concerné | ||
| 7 | public $format = 'html'; // vaut 'html' ou 'json' | ||
| 8 | public $fileList; // noms des fichiers dans ce dossier | ||
| 9 | protected $articles; // contenu de toute la page | ||
| 10 | protected $nbArticles; // un fichier = un article | ||
| 11 | |||
| 12 | // gestion d'un article spécifique | ||
| 13 | public $fileName = ''; // correspond à $_SESSION['nomFichier'] | ||
| 14 | protected $time; // timestamp pour noms des fichiers créés | ||
| 15 | |||
| 16 | public function __construct($page) | ||
| 17 | { | ||
| 18 | $this->page = $page; | ||
| 19 | $this->time = time(); | ||
| 20 | $this->makeFileList(); | ||
| 21 | } | ||
| 22 | |||
| 23 | // tableaux des noms des fichiers | ||
| 24 | public function makeFileList() | ||
| 25 | { | ||
| 26 | $this->fileList = glob('data/' . $this->page . '/' . $this->format . '/*.' . $this->format); | ||
| 27 | //$this->files = glob('*.' . $this->format); | ||
| 28 | } | ||
| 29 | /*public function makeFilePath() | ||
| 30 | {}*/ | ||
| 31 | |||
| 32 | // nom d'un fichier | ||
| 33 | public function findFileName($numArticle) | ||
| 34 | { | ||
| 35 | if($numArticle > 0) | ||
| 36 | { | ||
| 37 | $this->fileName = $this->fileList[$numArticle - 1]; | ||
| 38 | } | ||
| 39 | } | ||
| 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 | |||
| 49 | // GET | ||
| 50 | |||
| 51 | // SET | ||
| 52 | |||
| 53 | // fonctions CRUD (create - read - update - delete) | ||
| 54 | |||
| 55 | // create | ||
| 56 | public function create($content) | ||
| 57 | { | ||
| 58 | //$format = 'html'; | ||
| 59 | |||
| 60 | // nommer les fichiers avec le timestamp pour: | ||
| 61 | // - les trier par ordre chronologique | ||
| 62 | // - rendre quasi impossible d'avoir deux fois le même nom (à la condition de gérer la "concurrence") | ||
| 63 | $nom_fichier = 'data/' . $this->page . '/' . $format . '/' . $this->time . '.' . $format; | ||
| 64 | |||
| 65 | $fichier = fopen($nom_fichier, 'w'); // w pour créer ou écraser | ||
| 66 | fputs($fichier, $content); | ||
| 67 | fclose($fichier); | ||
| 68 | chmod($nom_fichier, 0666); | ||
| 69 | } | ||
| 70 | |||
| 71 | // read | ||
| 72 | public function readAll() | ||
| 73 | { | ||
| 74 | $i = 0; | ||
| 75 | $articles = []; | ||
| 76 | foreach ($this->fileList as $oneFile) | ||
| 77 | { | ||
| 78 | $articles[$i] = file_get_contents($oneFile); | ||
| 79 | $i++; | ||
| 80 | } | ||
| 81 | //print_r($articles); | ||
| 82 | return $articles; | ||
| 83 | } | ||
| 84 | public function readOne() | ||
| 85 | { | ||
| 86 | return(file_get_contents($this->fileName)); | ||
| 87 | } | ||
| 88 | |||
| 89 | // update | ||
| 90 | public function update($content) | ||
| 91 | { | ||
| 92 | $file = fopen($this->fileName, 'w'); // crée ou écrase | ||
| 93 | fputs($file, $content); | ||
| 94 | fclose($file); | ||
| 95 | //chown($this->fileName, 'http'); | ||
| 96 | chmod($this->fileName, 0666); | ||
| 97 | } | ||
| 98 | |||
| 99 | // delete | ||
| 100 | public function delete() | ||
| 101 | { | ||
| 102 | unlink($this->fileName); | ||
| 103 | } | ||
| 104 | } \ No newline at end of file | ||
