diff options
Diffstat (limited to 'inc/functions.php')
-rwxr-xr-x | inc/functions.php | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/inc/functions.php b/inc/functions.php index ffd400ef..45828bf2 100755 --- a/inc/functions.php +++ b/inc/functions.php | |||
@@ -120,4 +120,108 @@ function prepare_url($url) | |||
120 | $parametres['content'] = $r->articleContent->innerHTML; | 120 | $parametres['content'] = $r->articleContent->innerHTML; |
121 | 121 | ||
122 | return $parametres; | 122 | return $parametres; |
123 | } | ||
124 | |||
125 | /** | ||
126 | * Appel d'une action (mark as fav, archive, delete) | ||
127 | */ | ||
128 | function action_to_do($action, $id) | ||
129 | { | ||
130 | global $db; | ||
131 | |||
132 | switch ($action) | ||
133 | { | ||
134 | case 'add': | ||
135 | if ($url == '') | ||
136 | continue; | ||
137 | |||
138 | $parametres_url = prepare_url($url); | ||
139 | $sql_action = 'INSERT INTO entries ( url, title, content ) VALUES (?, ?, ?)'; | ||
140 | $params_action = array($url, $parametres_url['title'], $parametres_url['content']); | ||
141 | break; | ||
142 | case 'delete': | ||
143 | $sql_action = "DELETE FROM entries WHERE id=?"; | ||
144 | $params_action = array($id); | ||
145 | break; | ||
146 | default: | ||
147 | break; | ||
148 | } | ||
149 | |||
150 | try | ||
151 | { | ||
152 | # action query | ||
153 | if (isset($sql_action)) | ||
154 | { | ||
155 | $query = $db->getHandle()->prepare($sql_action); | ||
156 | $query->execute($params_action); | ||
157 | } | ||
158 | } | ||
159 | catch (Exception $e) | ||
160 | { | ||
161 | die('action query error : '.$e->getMessage()); | ||
162 | } | ||
163 | } | ||
164 | |||
165 | /** | ||
166 | * Détermine quels liens afficher : home, fav ou archives | ||
167 | */ | ||
168 | function display_view($view) | ||
169 | { | ||
170 | global $db; | ||
171 | |||
172 | switch ($view) | ||
173 | { | ||
174 | case 'archive': | ||
175 | $sql = "SELECT * FROM entries WHERE is_read=? ORDER BY id desc"; | ||
176 | $params = array(-1); | ||
177 | break; | ||
178 | case 'fav' : | ||
179 | $sql = "SELECT * FROM entries WHERE is_fav=? ORDER BY id desc"; | ||
180 | $params = array(-1); | ||
181 | break; | ||
182 | default: | ||
183 | $sql = "SELECT * FROM entries WHERE is_read=? ORDER BY id desc"; | ||
184 | $params = array(0); | ||
185 | break; | ||
186 | } | ||
187 | |||
188 | # view query | ||
189 | try | ||
190 | { | ||
191 | $query = $db->getHandle()->prepare($sql); | ||
192 | $query->execute($params); | ||
193 | $entries = $query->fetchAll(); | ||
194 | } | ||
195 | catch (Exception $e) | ||
196 | { | ||
197 | die('view query error : '.$e->getMessage()); | ||
198 | } | ||
199 | |||
200 | return $entries; | ||
201 | } | ||
202 | |||
203 | /** | ||
204 | * Récupère un article en fonction d'un ID | ||
205 | */ | ||
206 | function get_article($id) | ||
207 | { | ||
208 | global $db; | ||
209 | |||
210 | $entry = NULL; | ||
211 | $sql = "SELECT * FROM entries WHERE id=?"; | ||
212 | $params = array(intval($id)); | ||
213 | |||
214 | # view article query | ||
215 | try | ||
216 | { | ||
217 | $query = $db->getHandle()->prepare($sql); | ||
218 | $query->execute($params); | ||
219 | $entry = $query->fetchAll(); | ||
220 | } | ||
221 | catch (Exception $e) | ||
222 | { | ||
223 | die('query error : '.$e->getMessage()); | ||
224 | } | ||
225 | |||
226 | return $entry; | ||
123 | } \ No newline at end of file | 227 | } \ No newline at end of file |