diff options
author | nicosomb <nicolas@loeuillet.org> | 2013-04-15 09:58:34 +0200 |
---|---|---|
committer | nicosomb <nicolas@loeuillet.org> | 2013-04-15 09:58:34 +0200 |
commit | 263d6c6756a2549100ae186042f157ff64944bfa (patch) | |
tree | dc7a9e874438584ab809393d88b41050b75cff34 /index.php | |
parent | 8046748b424f95a92ab599ecc973f57eb05246ce (diff) | |
download | wallabag-263d6c6756a2549100ae186042f157ff64944bfa.tar.gz wallabag-263d6c6756a2549100ae186042f157ff64944bfa.tar.zst wallabag-263d6c6756a2549100ae186042f157ff64944bfa.zip |
factorisation code
Diffstat (limited to 'index.php')
-rwxr-xr-x | index.php | 64 |
1 files changed, 3 insertions, 61 deletions
@@ -11,70 +11,12 @@ | |||
11 | include dirname(__FILE__).'/inc/config.php'; | 11 | include 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 | ||
18 | switch ($action) | 18 | action_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 | |||
36 | try | ||
37 | { | ||
38 | # action query | ||
39 | if (isset($sql_action)) | ||
40 | { | ||
41 | $query = $db->getHandle()->prepare($sql_action); | ||
42 | $query->execute($params_action); | ||
43 | } | ||
44 | } | ||
45 | catch (Exception $e) | ||
46 | { | ||
47 | die('action query error : '.$e->getMessage()); | ||
48 | } | ||
49 | |||
50 | switch ($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 | ||
68 | try | ||
69 | { | ||
70 | $query = $db->getHandle()->prepare($sql); | ||
71 | $query->execute($params); | ||
72 | $entries = $query->fetchAll(); | ||
73 | } | ||
74 | catch (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); |