diff options
Diffstat (limited to 'model/Article.php')
| -rw-r--r-- | model/Article.php | 60 |
1 files changed, 47 insertions, 13 deletions
diff --git a/model/Article.php b/model/Article.php index f9c5b89..bad6948 100644 --- a/model/Article.php +++ b/model/Article.php | |||
| @@ -49,33 +49,47 @@ class Article | |||
| 49 | //var_dump($this->fileList); die(); | 49 | //var_dump($this->fileList); die(); |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | private function makeHtmlMiniImages($content) | ||
| 53 | { | ||
| 54 | return $content; | ||
| 55 | } | ||
| 56 | |||
| 52 | // GET | 57 | // GET |
| 53 | 58 | ||
| 54 | // SET | 59 | // SET |
| 55 | /*public function setFileName() | ||
| 56 | { | ||
| 57 | if(file_exists('data/' . $this->page . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format)) | ||
| 58 | { | ||
| 59 | $this->fileName = 'data/' . $this->page . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format; | ||
| 60 | } | ||
| 61 | }*/ | ||
| 62 | 60 | ||
| 63 | // fonctions CRUD (create - read - update - delete) | 61 | // fonctions CRUD (create - read - update - delete) |
| 64 | 62 | ||
| 65 | // create | 63 | // create |
| 66 | public function create($content) | 64 | public function create($content) |
| 67 | { | 65 | { |
| 68 | //$format = 'html'; | 66 | // $format dépend de la classe qui a été instanciée |
| 69 | 67 | ||
| 70 | // nommer les fichiers avec le timestamp pour: | 68 | // nommer les fichiers avec le timestamp pour: |
| 71 | // - les trier par ordre chronologique | 69 | // - les trier par ordre chronologique |
| 72 | // - rendre quasi impossible d'avoir deux fois le même nom | 70 | // - rendre quasi impossible d'avoir deux fois le même nom |
| 73 | $fileName = 'data/' . $this->page . '/' . $this->format . '/' . $this->time . '.' . $this->format; | ||
| 74 | 71 | ||
| 72 | if($this->format == 'html') | ||
| 73 | { | ||
| 74 | // html version images normales | ||
| 75 | $contentMaxi = $content; | ||
| 76 | $fileName = 'data/' . $this->page . '/' . $this->format . '-maxi-images/' . $this->time . '.' . $this->format; | ||
| 77 | $file = fopen($fileName, 'w'); // w pour créer ou écraser | ||
| 78 | fputs($file, $contentMaxi); | ||
| 79 | fclose($file); | ||
| 80 | chmod($fileName, 0666); | ||
| 81 | |||
| 82 | // html version petites images | ||
| 83 | $content = self::makeHtmlMiniImages($content); | ||
| 84 | } | ||
| 85 | |||
| 86 | $fileName = 'data/' . $this->page . '/' . $this->format . '/' . $this->time . '.' . $this->format; | ||
| 75 | $file = fopen($fileName, 'w'); // w pour créer ou écraser | 87 | $file = fopen($fileName, 'w'); // w pour créer ou écraser |
| 76 | fputs($file, $content); | 88 | fputs($file, $content); |
| 77 | fclose($file); | 89 | fclose($file); |
| 78 | chmod($fileName, 0666); | 90 | chmod($fileName, 0666); |
| 91 | |||
| 92 | |||
| 79 | } | 93 | } |
| 80 | 94 | ||
| 81 | // read | 95 | // read |
| @@ -96,8 +110,29 @@ class Article | |||
| 96 | // update | 110 | // update |
| 97 | public function update($content) | 111 | public function update($content) |
| 98 | { | 112 | { |
| 113 | if($this->format == 'html') | ||
| 114 | { | ||
| 115 | // html version images normales | ||
| 116 | $contentMaxi = $content; | ||
| 117 | $fileName = 'data/' . $this->page . '/' . $this->format . '-maxi-images/' . $this->fileCode . '.' . $this->format; | ||
| 118 | if(file_exists($fileName) && empty($content)) | ||
| 119 | { | ||
| 120 | $this->delete(); | ||
| 121 | } | ||
| 122 | elseif(!empty($content)) | ||
| 123 | { | ||
| 124 | $file = fopen($fileName, 'w'); // w pour créer ou écraser | ||
| 125 | fputs($file, $contentMaxi); | ||
| 126 | fclose($file); | ||
| 127 | chmod($fileName, 0666); | ||
| 128 | } | ||
| 129 | |||
| 130 | // html version petites images | ||
| 131 | $content = self::makeHtmlMiniImages($content); | ||
| 132 | } | ||
| 133 | |||
| 134 | // json ou html version petites images | ||
| 99 | $fileName = 'data/' . $this->page . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format; | 135 | $fileName = 'data/' . $this->page . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format; |
| 100 | //var_dump(file_get_contents($fileName)); die(); | ||
| 101 | if(file_exists($fileName) && empty($content)) | 136 | if(file_exists($fileName) && empty($content)) |
| 102 | { | 137 | { |
| 103 | $this->delete(); | 138 | $this->delete(); |
| @@ -107,8 +142,7 @@ class Article | |||
| 107 | $file = fopen($fileName, 'w'); // w pour créer ou écraser | 142 | $file = fopen($fileName, 'w'); // w pour créer ou écraser |
| 108 | fputs($file, $content); | 143 | fputs($file, $content); |
| 109 | fclose($file); | 144 | fclose($file); |
| 110 | //chown($this->fileName, 'http'); | 145 | chmod($fileName, 0666); |
| 111 | chmod($fileName, 0666); | ||
| 112 | } | 146 | } |
| 113 | } | 147 | } |
| 114 | 148 | ||
