aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--inc/config.php3
-rwxr-xr-xinc/functions.php104
-rwxr-xr-xindex.php64
-rwxr-xr-xview.php17
4 files changed, 111 insertions, 77 deletions
diff --git a/inc/config.php b/inc/config.php
index 6d8be9ee..29a22507 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -22,5 +22,4 @@ raintpl::$cache_dir = './cache/';
22raintpl::$base_url = get_poche_url(); 22raintpl::$base_url = get_poche_url();
23raintpl::configure('path_replace', false); 23raintpl::configure('path_replace', false);
24raintpl::configure('debug', false); 24raintpl::configure('debug', false);
25$tpl = new raintpl(); 25$tpl = new raintpl(); \ No newline at end of file
26?> \ No newline at end of file
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 */
128function 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 */
168function 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 */
206function 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
diff --git a/index.php b/index.php
index ef18254a..1cb32f58 100755
--- a/index.php
+++ b/index.php
@@ -11,70 +11,12 @@
11include dirname(__FILE__).'/inc/config.php'; 11include dirname(__FILE__).'/inc/config.php';
12 12
13$action = (isset ($_GET['action'])) ? htmlspecialchars($_GET['action']) : ''; 13$action = (isset ($_GET['action'])) ? htmlspecialchars($_GET['action']) : '';
14$view = (isset ($_GET['view'])) ? htmlspecialchars($_GET['view']) : ''; 14$view = (isset ($_GET['view'])) ? htmlspecialchars($_GET['view']) : 'index';
15$id = (isset ($_GET['id'])) ? htmlspecialchars($_GET['id']) : ''; 15$id = (isset ($_GET['id'])) ? htmlspecialchars($_GET['id']) : '';
16$url = (isset ($_GET['url'])) ? $_GET['url'] : ''; 16$url = (isset ($_GET['url'])) ? $_GET['url'] : '';
17 17
18switch ($action) 18action_to_do($action, $id);
19{ 19$entries = display_view($view);
20 case 'add':
21 if ($url == '')
22 continue;
23
24 $parametres_url = prepare_url($url);
25 $sql_action = 'INSERT INTO entries ( url, title, content ) VALUES (?, ?, ?)';
26 $params_action = array($url, $parametres_url['title'], $parametres_url['content']);
27 break;
28 case 'delete':
29 $sql_action = "DELETE FROM entries WHERE id=?";
30 $params_action = array($id);
31 break;
32 default:
33 break;
34}
35
36try
37{
38 # action query
39 if (isset($sql_action))
40 {
41 $query = $db->getHandle()->prepare($sql_action);
42 $query->execute($params_action);
43 }
44}
45catch (Exception $e)
46{
47 die('action query error : '.$e->getMessage());
48}
49
50switch ($view)
51{
52 case 'archive':
53 $sql = "SELECT * FROM entries WHERE is_read=? ORDER BY id desc";
54 $params = array(-1);
55 break;
56 case 'fav' :
57 $sql = "SELECT * FROM entries WHERE is_fav=? ORDER BY id desc";
58 $params = array(-1);
59 break;
60 default:
61 $sql = "SELECT * FROM entries WHERE is_read=? ORDER BY id desc";
62 $params = array(0);
63 $view = 'index';
64 break;
65}
66
67# view query
68try
69{
70 $query = $db->getHandle()->prepare($sql);
71 $query->execute($params);
72 $entries = $query->fetchAll();
73}
74catch (Exception $e)
75{
76 die('view query error : '.$e->getMessage());
77}
78 20
79$tpl->assign('title', 'poche, a read it later open source system'); 21$tpl->assign('title', 'poche, a read it later open source system');
80$tpl->assign('view', $view); 22$tpl->assign('view', $view);
diff --git a/view.php b/view.php
index 0ee8957b..dfc26b9d 100755
--- a/view.php
+++ b/view.php
@@ -10,22 +10,11 @@
10 10
11include dirname(__FILE__).'/inc/config.php'; 11include dirname(__FILE__).'/inc/config.php';
12 12
13if(isset($_GET['id']) && $_GET['id'] != '') { 13$id = (isset ($_GET['id'])) ? htmlspecialchars($_GET['id']) : '';
14 14
15 $sql = "SELECT * FROM entries WHERE id=?"; 15if(!empty($id)) {
16 $params = array(intval($_GET['id']));
17 16
18 # view article query 17 $entry = get_article($id);
19 try
20 {
21 $query = $db->getHandle()->prepare($sql);
22 $query->execute($params);
23 $entry = $query->fetchAll();
24 }
25 catch (Exception $e)
26 {
27 die('query error : '.$e->getMessage());
28 }
29 18
30 if ($entry != NULL) { 19 if ($entry != NULL) {
31 $tpl->assign('id', $entry[0]['id']); 20 $tpl->assign('id', $entry[0]['id']);