aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/store/sqlite.class.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/store/sqlite.class.php')
-rw-r--r--inc/store/sqlite.class.php197
1 files changed, 0 insertions, 197 deletions
diff --git a/inc/store/sqlite.class.php b/inc/store/sqlite.class.php
deleted file mode 100644
index 4c628dc1..00000000
--- a/inc/store/sqlite.class.php
+++ /dev/null
@@ -1,197 +0,0 @@
1<?php
2/**
3 * poche, a read it later open source system
4 *
5 * @category poche
6 * @author Nicolas LÅ“uillet <support@inthepoche.com>
7 * @copyright 2013
8 * @license http://www.wtfpl.net/ see COPYING file
9 */
10
11class Sqlite extends Store {
12
13 public static $db_path = 'sqlite:./db/poche.sqlite';
14 var $handle;
15
16 function __construct() {
17 parent::__construct();
18
19 $this->handle = new PDO(self::$db_path);
20 $this->handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
21 }
22
23 private function getHandle() {
24 return $this->handle;
25 }
26
27 public function isInstalled() {
28 $sql = "SELECT username FROM users WHERE id=?";
29 $query = $this->executeQuery($sql, array('1'));
30 $hasAdmin = $query->fetchAll();
31
32 if (count($hasAdmin) == 0)
33 return FALSE;
34
35 return TRUE;
36 }
37
38 public function install($login, $password) {
39 $sql = 'INSERT INTO users ( username, password ) VALUES (?, ?)';
40 $params = array($login, $password);
41 $query = $this->executeQuery($sql, $params);
42
43 return TRUE;
44 }
45
46 private function getConfigUser($id) {
47 $sql = "SELECT * FROM users_config WHERE user_id = ?";
48 $query = $this->executeQuery($sql, array($id));
49 $result = $query->fetchAll();
50 $user_config = array();
51
52 foreach ($result as $key => $value) {
53 $user_config[$value['name']] = $value['value'];
54 }
55
56 return $user_config;
57 }
58
59 public function login($username, $password) {
60 $sql = "SELECT * FROM users WHERE username=? AND password=?";
61 $query = $this->executeQuery($sql, array($username, $password));
62 $login = $query->fetchAll();
63
64 $user = array();
65 if (isset($login[0])) {
66 $user['id'] = $login[0]['id'];
67 $user['username'] = $login[0]['username'];
68 $user['password'] = $login[0]['password'];
69 $user['name'] = $login[0]['name'];
70 $user['email'] = $login[0]['email'];
71 $user['config'] = $this->getConfigUser($login[0]['id']);
72 }
73
74 return $user;
75 }
76
77 public function updatePassword($id, $password)
78 {
79 $sql_update = "UPDATE users SET password=? WHERE id=?";
80 $params_update = array($password, $id);
81 $query = $this->executeQuery($sql_update, $params_update);
82 }
83
84 private function executeQuery($sql, $params) {
85 try
86 {
87 $query = $this->getHandle()->prepare($sql);
88 $query->execute($params);
89 return $query;
90 }
91 catch (Exception $e)
92 {
93 Tools::logm('execute query error : '.$e->getMessage());
94 }
95 }
96
97 public function retrieveAll($user_id) {
98 $sql = "SELECT * FROM entries WHERE user_id=? ORDER BY id";
99 $query = $this->executeQuery($sql, array($user_id));
100 $entries = $query->fetchAll();
101
102 return $entries;
103 }
104
105 public function retrieveOneById($id, $user_id) {
106 parent::__construct();
107
108 $entry = NULL;
109 $sql = "SELECT * FROM entries WHERE id=? AND user_id=?";
110 $params = array(intval($id), $user_id);
111 $query = $this->executeQuery($sql, $params);
112 $entry = $query->fetchAll();
113
114 return $entry[0];
115 }
116
117 public function getEntriesByView($view, $user_id, $limit = '') {
118 parent::__construct();
119
120 switch ($_SESSION['sort'])
121 {
122 case 'ia':
123 $order = 'ORDER BY id';
124 break;
125 case 'id':
126 $order = 'ORDER BY id DESC';
127 break;
128 case 'ta':
129 $order = 'ORDER BY lower(title)';
130 break;
131 case 'td':
132 $order = 'ORDER BY lower(title) DESC';
133 break;
134 default:
135 $order = 'ORDER BY id';
136 break;
137 }
138
139 switch ($view)
140 {
141 case 'archive':
142 $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? " . $order;
143 $params = array($user_id, -1);
144 break;
145 case 'fav' :
146 $sql = "SELECT * FROM entries WHERE user_id=? AND is_fav=? " . $order;
147 $params = array($user_id, -1);
148 break;
149 default:
150 $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? " . $order;
151 $params = array($user_id, 0);
152 break;
153 }
154
155 $sql .= ' ' . $limit;
156
157 $query = $this->executeQuery($sql, $params);
158 $entries = $query->fetchAll();
159
160 return $entries;
161 }
162
163 public function add($url, $title, $content, $user_id) {
164 parent::__construct();
165 $sql_action = 'INSERT INTO entries ( url, title, content, user_id ) VALUES (?, ?, ?, ?)';
166 $params_action = array($url, $title, $content, $user_id);
167 $query = $this->executeQuery($sql_action, $params_action);
168 return $query;
169 }
170
171 public function deleteById($id, $user_id) {
172 parent::__construct();
173 $sql_action = "DELETE FROM entries WHERE id=? AND user_id=?";
174 $params_action = array($id, $user_id);
175 $query = $this->executeQuery($sql_action, $params_action);
176 return $query;
177 }
178
179 public function favoriteById($id, $user_id) {
180 parent::__construct();
181 $sql_action = "UPDATE entries SET is_fav=~is_fav WHERE id=? AND user_id=?";
182 $params_action = array($id, $user_id);
183 $query = $this->executeQuery($sql_action, $params_action);
184 }
185
186 public function archiveById($id, $user_id) {
187 parent::__construct();
188 $sql_action = "UPDATE entries SET is_read=~is_read WHERE id=? AND user_id=?";
189 $params_action = array($id, $user_id);
190 $query = $this->executeQuery($sql_action, $params_action);
191 }
192
193 public function getLastId() {
194 parent::__construct();
195 return $this->getHandle()->lastInsertId();
196 }
197}