diff options
Diffstat (limited to 'inc')
-rw-r--r-- | inc/3rdparty/Session.class.php | 2 | ||||
-rw-r--r-- | inc/poche/Poche.class.php | 72 | ||||
-rw-r--r-- | inc/poche/User.class.php | 33 | ||||
-rw-r--r-- | inc/poche/config.inc.php | 2 | ||||
-rw-r--r-- | inc/store/file.class.php | 4 | ||||
-rw-r--r-- | inc/store/mysql.class.php | 7 | ||||
-rw-r--r-- | inc/store/sqlite.class.php | 75 | ||||
-rw-r--r-- | inc/store/store.class.php | 4 |
8 files changed, 105 insertions, 94 deletions
diff --git a/inc/3rdparty/Session.class.php b/inc/3rdparty/Session.class.php index eff924cc..3162f507 100644 --- a/inc/3rdparty/Session.class.php +++ b/inc/3rdparty/Session.class.php | |||
@@ -93,7 +93,7 @@ class Session | |||
93 | // Force logout | 93 | // Force logout |
94 | public static function logout() | 94 | public static function logout() |
95 | { | 95 | { |
96 | unset($_SESSION['uid'],$_SESSION['info'],$_SESSION['expires_on'],$_SESSION['tokens'], $_SESSION['login'], $_SESSION['pass']); | 96 | unset($_SESSION['uid'],$_SESSION['info'],$_SESSION['expires_on'],$_SESSION['tokens'], $_SESSION['login'], $_SESSION['pass'], $_SESSION['poche_user']); |
97 | } | 97 | } |
98 | 98 | ||
99 | // Make sure user is logged in. | 99 | // Make sure user is logged in. |
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 2c0c73f9..ce5bb54a 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php | |||
@@ -33,10 +33,18 @@ class Poche | |||
33 | { | 33 | { |
34 | Tools::initPhp(); | 34 | Tools::initPhp(); |
35 | Session::init(); | 35 | Session::init(); |
36 | $this->user = isset($_SESSION['poche_user']) ? $_SESSION['poche_user'] : array(); | 36 | |
37 | if (isset($_SESSION['poche_user'])) { | ||
38 | $this->user = $_SESSION['poche_user']; | ||
39 | } | ||
40 | else { | ||
41 | # fake user, just for install & login screens | ||
42 | $this->user = new User(); | ||
43 | $this->user->setConfig($this->getDefaultConfig()); | ||
44 | } | ||
37 | 45 | ||
38 | # l10n | 46 | # l10n |
39 | $language = ($this->user->getConfigValue('language')) ? $this->user->getConfigValue('language') : LANG; | 47 | $language = $this->user->getConfigValue('language'); |
40 | putenv('LC_ALL=' . $language); | 48 | putenv('LC_ALL=' . $language); |
41 | setlocale(LC_ALL, $language); | 49 | setlocale(LC_ALL, $language); |
42 | bindtextdomain($language, LOCALE); | 50 | bindtextdomain($language, LOCALE); |
@@ -53,8 +61,7 @@ class Poche | |||
53 | $this->tpl->addFilter($filter); | 61 | $this->tpl->addFilter($filter); |
54 | 62 | ||
55 | # Pagination | 63 | # Pagination |
56 | $pager = ($this->user->getConfigValue('pager')) ? $this->user->getConfigValue('pager') : PAGINATION; | 64 | $this->pagination = new Paginator($this->user->getConfigValue('pager'), 'p'); |
57 | $this->pagination = new Paginator($pager, 'p'); | ||
58 | } | 65 | } |
59 | 66 | ||
60 | private function install() | 67 | private function install() |
@@ -80,6 +87,14 @@ class Poche | |||
80 | exit(); | 87 | exit(); |
81 | } | 88 | } |
82 | 89 | ||
90 | public function getDefaultConfig() | ||
91 | { | ||
92 | return array( | ||
93 | 'pager' => PAGINATION, | ||
94 | 'language' => LANG, | ||
95 | ); | ||
96 | } | ||
97 | |||
83 | /** | 98 | /** |
84 | * Call action (mark as fav, archive, delete, etc.) | 99 | * Call action (mark as fav, archive, delete, etc.) |
85 | */ | 100 | */ |
@@ -89,7 +104,7 @@ class Poche | |||
89 | { | 104 | { |
90 | case 'add': | 105 | case 'add': |
91 | if($parametres_url = $url->fetchContent()) { | 106 | if($parametres_url = $url->fetchContent()) { |
92 | if ($this->store->add($url->getUrl(), $parametres_url['title'], $parametres_url['content'])) { | 107 | if ($this->store->add($url->getUrl(), $parametres_url['title'], $parametres_url['content'], $this->user->getId())) { |
93 | Tools::logm('add link ' . $url->getUrl()); | 108 | Tools::logm('add link ' . $url->getUrl()); |
94 | $last_id = $this->store->getLastId(); | 109 | $last_id = $this->store->getLastId(); |
95 | if (DOWNLOAD_PICTURES) { | 110 | if (DOWNLOAD_PICTURES) { |
@@ -109,7 +124,7 @@ class Poche | |||
109 | Tools::redirect(); | 124 | Tools::redirect(); |
110 | break; | 125 | break; |
111 | case 'delete': | 126 | case 'delete': |
112 | if ($this->store->deleteById($id)) { | 127 | if ($this->store->deleteById($id, $this->user->getId())) { |
113 | if (DOWNLOAD_PICTURES) { | 128 | if (DOWNLOAD_PICTURES) { |
114 | remove_directory(ABS_PATH . $id); | 129 | remove_directory(ABS_PATH . $id); |
115 | } | 130 | } |
@@ -123,12 +138,12 @@ class Poche | |||
123 | Tools::redirect(); | 138 | Tools::redirect(); |
124 | break; | 139 | break; |
125 | case 'toggle_fav' : | 140 | case 'toggle_fav' : |
126 | $this->store->favoriteById($id); | 141 | $this->store->favoriteById($id, $this->user->getId()); |
127 | Tools::logm('mark as favorite link #' . $id); | 142 | Tools::logm('mark as favorite link #' . $id); |
128 | Tools::redirect(); | 143 | Tools::redirect(); |
129 | break; | 144 | break; |
130 | case 'toggle_archive' : | 145 | case 'toggle_archive' : |
131 | $this->store->archiveById($id); | 146 | $this->store->archiveById($id, $this->user->getId()); |
132 | Tools::logm('archive link #' . $id); | 147 | Tools::logm('archive link #' . $id); |
133 | Tools::redirect(); | 148 | Tools::redirect(); |
134 | break; | 149 | break; |
@@ -157,7 +172,7 @@ class Poche | |||
157 | Tools::logm('config view'); | 172 | Tools::logm('config view'); |
158 | break; | 173 | break; |
159 | case 'view': | 174 | case 'view': |
160 | $entry = $this->store->retrieveOneById($id); | 175 | $entry = $this->store->retrieveOneById($id, $this->user->getId()); |
161 | if ($entry != NULL) { | 176 | if ($entry != NULL) { |
162 | Tools::logm('view link #' . $id); | 177 | Tools::logm('view link #' . $id); |
163 | $content = $entry['content']; | 178 | $content = $entry['content']; |
@@ -176,10 +191,10 @@ class Poche | |||
176 | } | 191 | } |
177 | break; | 192 | break; |
178 | default: # home view | 193 | default: # home view |
179 | $entries = $this->store->getEntriesByView($view); | 194 | $entries = $this->store->getEntriesByView($view, $this->user->getId()); |
180 | $this->pagination->set_total(count($entries)); | 195 | $this->pagination->set_total(count($entries)); |
181 | $page_links = $this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . '&'); | 196 | $page_links = $this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . '&'); |
182 | $datas = $this->store->getEntriesByView($view, $this->pagination->get_limit()); | 197 | $datas = $this->store->getEntriesByView($view, $this->user->getId(), $this->pagination->get_limit()); |
183 | $tpl_vars = array( | 198 | $tpl_vars = array( |
184 | 'entries' => $datas, | 199 | 'entries' => $datas, |
185 | 'page_links' => $page_links, | 200 | 'page_links' => $page_links, |
@@ -194,21 +209,21 @@ class Poche | |||
194 | public function updatePassword() | 209 | public function updatePassword() |
195 | { | 210 | { |
196 | if (MODE_DEMO) { | 211 | if (MODE_DEMO) { |
197 | $this->messages->add('i', 'in demo mode, you can\'t update your password'); | 212 | $this->messages->add('i', _('in demo mode, you can\'t update your password')); |
198 | Tools::logm('in demo mode, you can\'t do this'); | 213 | Tools::logm('in demo mode, you can\'t do this'); |
199 | Tools::redirect('?view=config'); | 214 | Tools::redirect('?view=config'); |
200 | } | 215 | } |
201 | else { | 216 | else { |
202 | if (isset($_POST['password']) && isset($_POST['password_repeat'])) { | 217 | if (isset($_POST['password']) && isset($_POST['password_repeat'])) { |
203 | if ($_POST['password'] == $_POST['password_repeat'] && $_POST['password'] != "") { | 218 | if ($_POST['password'] == $_POST['password_repeat'] && $_POST['password'] != "") { |
204 | Tools::logm('password updated'); | 219 | $this->messages->add('s', _('your password has been updated')); |
205 | $this->messages->add('s', 'your password has been updated'); | 220 | $this->store->updatePassword($this->user->getId(), Tools::encodeString($_POST['password'] . $this->user->getUsername())); |
206 | $this->store->updatePassword(Tools::encodeString($_POST['password'] . $_SESSION['login'])); | ||
207 | Session::logout(); | 221 | Session::logout(); |
222 | Tools::logm('password updated'); | ||
208 | Tools::redirect(); | 223 | Tools::redirect(); |
209 | } | 224 | } |
210 | else { | 225 | else { |
211 | $this->messages->add('e', 'the two fields have to be filled & the password must be the same in the two fields'); | 226 | $this->messages->add('e', _('the two fields have to be filled & the password must be the same in the two fields')); |
212 | Tools::redirect('?view=config'); | 227 | Tools::redirect('?view=config'); |
213 | } | 228 | } |
214 | } | 229 | } |
@@ -223,8 +238,7 @@ class Poche | |||
223 | # Save login into Session | 238 | # Save login into Session |
224 | Session::login($user['username'], $user['password'], $_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login']), array('poche_user' => new User($user))); | 239 | Session::login($user['username'], $user['password'], $_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login']), array('poche_user' => new User($user))); |
225 | 240 | ||
226 | Tools::logm('login successful'); | 241 | $this->messages->add('s', _('welcome to your poche')); |
227 | $this->messages->add('s', 'welcome to your poche'); | ||
228 | if (!empty($_POST['longlastingsession'])) { | 242 | if (!empty($_POST['longlastingsession'])) { |
229 | $_SESSION['longlastingsession'] = 31536000; | 243 | $_SESSION['longlastingsession'] = 31536000; |
230 | $_SESSION['expires_on'] = time() + $_SESSION['longlastingsession']; | 244 | $_SESSION['expires_on'] = time() + $_SESSION['longlastingsession']; |
@@ -233,13 +247,14 @@ class Poche | |||
233 | session_set_cookie_params(0); | 247 | session_set_cookie_params(0); |
234 | } | 248 | } |
235 | session_regenerate_id(true); | 249 | session_regenerate_id(true); |
250 | Tools::logm('login successful'); | ||
236 | Tools::redirect($referer); | 251 | Tools::redirect($referer); |
237 | } | 252 | } |
238 | $this->messages->add('e', 'login failed: bad login or password'); | 253 | $this->messages->add('e', _('login failed: bad login or password')); |
239 | Tools::logm('login failed'); | 254 | Tools::logm('login failed'); |
240 | Tools::redirect(); | 255 | Tools::redirect(); |
241 | } else { | 256 | } else { |
242 | $this->messages->add('e', 'login failed: you have to fill all fields'); | 257 | $this->messages->add('e', _('login failed: you have to fill all fields')); |
243 | Tools::logm('login failed'); | 258 | Tools::logm('login failed'); |
244 | Tools::redirect(); | 259 | Tools::redirect(); |
245 | } | 260 | } |
@@ -247,7 +262,7 @@ class Poche | |||
247 | 262 | ||
248 | public function logout() | 263 | public function logout() |
249 | { | 264 | { |
250 | $this->messages->add('s', 'see you soon!'); | 265 | $this->messages->add('s', _('see you soon!')); |
251 | Tools::logm('logout'); | 266 | Tools::logm('logout'); |
252 | $this->user = array(); | 267 | $this->user = array(); |
253 | Session::logout(); | 268 | Session::logout(); |
@@ -271,14 +286,14 @@ class Poche | |||
271 | $this->action('add', $url); | 286 | $this->action('add', $url); |
272 | if ($read == '1') { | 287 | if ($read == '1') { |
273 | $last_id = $this->store->getLastId(); | 288 | $last_id = $this->store->getLastId(); |
274 | $this->store->archiveById($last_id); | 289 | $this->action('toggle_archive', $url, $last_id); |
275 | } | 290 | } |
276 | } | 291 | } |
277 | 292 | ||
278 | # the second <ol> is for read links | 293 | # the second <ol> is for read links |
279 | $read = 1; | 294 | $read = 1; |
280 | } | 295 | } |
281 | $this->messages->add('s', 'import from instapaper completed'); | 296 | $this->messages->add('s', _('import from instapaper completed')); |
282 | Tools::logm('import from instapaper completed'); | 297 | Tools::logm('import from instapaper completed'); |
283 | Tools::redirect(); | 298 | Tools::redirect(); |
284 | } | 299 | } |
@@ -300,14 +315,14 @@ class Poche | |||
300 | $this->action('add', $url); | 315 | $this->action('add', $url); |
301 | if ($read == '1') { | 316 | if ($read == '1') { |
302 | $last_id = $this->store->getLastId(); | 317 | $last_id = $this->store->getLastId(); |
303 | $this->store->archiveById($last_id); | 318 | $this->action('toggle_archive', $url, $last_id); |
304 | } | 319 | } |
305 | } | 320 | } |
306 | 321 | ||
307 | # the second <ul> is for read links | 322 | # the second <ul> is for read links |
308 | $read = 1; | 323 | $read = 1; |
309 | } | 324 | } |
310 | $this->messages->add('s', 'import from pocket completed'); | 325 | $this->messages->add('s', _('import from pocket completed')); |
311 | Tools::logm('import from pocket completed'); | 326 | Tools::logm('import from pocket completed'); |
312 | Tools::redirect(); | 327 | Tools::redirect(); |
313 | } | 328 | } |
@@ -327,16 +342,17 @@ class Poche | |||
327 | // if ($attr_value == 'favorite' && $attr_value == 'true') { | 342 | // if ($attr_value == 'favorite' && $attr_value == 'true') { |
328 | // $last_id = $this->store->getLastId(); | 343 | // $last_id = $this->store->getLastId(); |
329 | // $this->store->favoriteById($last_id); | 344 | // $this->store->favoriteById($last_id); |
345 | // $this->action('toogle_fav', $url, $last_id); | ||
330 | // } | 346 | // } |
331 | // if ($attr_value == 'archive' && $attr_value == 'true') { | 347 | // if ($attr_value == 'archive' && $attr_value == 'true') { |
332 | // $last_id = $this->store->getLastId(); | 348 | // $last_id = $this->store->getLastId(); |
333 | // $this->store->archiveById($last_id); | 349 | // $this->action('toggle_archive', $url, $last_id); |
334 | // } | 350 | // } |
335 | } | 351 | } |
336 | if ($url->isCorrect()) | 352 | if ($url->isCorrect()) |
337 | $this->action('add', $url); | 353 | $this->action('add', $url); |
338 | } | 354 | } |
339 | $this->messages->add('s', 'import from Readability completed'); | 355 | $this->messages->add('s', _('import from Readability completed')); |
340 | Tools::logm('import from Readability completed'); | 356 | Tools::logm('import from Readability completed'); |
341 | Tools::redirect(); | 357 | Tools::redirect(); |
342 | } | 358 | } |
@@ -356,7 +372,7 @@ class Poche | |||
356 | 372 | ||
357 | public function export() | 373 | public function export() |
358 | { | 374 | { |
359 | $entries = $this->store->retrieveAll(); | 375 | $entries = $this->store->retrieveAll($this->user->getId()); |
360 | echo $this->tpl->render('export.twig', array( | 376 | echo $this->tpl->render('export.twig', array( |
361 | 'export' => Tools::renderJson($entries), | 377 | 'export' => Tools::renderJson($entries), |
362 | )); | 378 | )); |
diff --git a/inc/poche/User.class.php b/inc/poche/User.class.php index ef47730f..6dac7839 100644 --- a/inc/poche/User.class.php +++ b/inc/poche/User.class.php | |||
@@ -17,17 +17,34 @@ class User | |||
17 | public $email; | 17 | public $email; |
18 | public $config; | 18 | public $config; |
19 | 19 | ||
20 | function __construct($user) | 20 | function __construct($user = array()) |
21 | { | 21 | { |
22 | $this->id = $user['id']; | 22 | if ($user != array()) { |
23 | $this->username = $user['username']; | 23 | $this->id = $user['id']; |
24 | $this->name = $user['name']; | 24 | $this->username = $user['username']; |
25 | $this->password = $user['password']; | 25 | $this->name = $user['name']; |
26 | $this->email = $user['email']; | 26 | $this->password = $user['password']; |
27 | $this->config = $user['config']; | 27 | $this->email = $user['email']; |
28 | $this->config = $user['config']; | ||
29 | } | ||
28 | } | 30 | } |
29 | 31 | ||
30 | function getConfigValue($name) { | 32 | public function getId() |
33 | { | ||
34 | return $this->id; | ||
35 | } | ||
36 | |||
37 | public function getUsername() | ||
38 | { | ||
39 | return $this->username; | ||
40 | } | ||
41 | |||
42 | public function setConfig($config) | ||
43 | { | ||
44 | $this->config = $config; | ||
45 | } | ||
46 | |||
47 | public function getConfigValue($name) { | ||
31 | return (isset($this->config[$name])) ? $this->config[$name] : FALSE; | 48 | return (isset($this->config[$name])) ? $this->config[$name] : FALSE; |
32 | } | 49 | } |
33 | } \ No newline at end of file | 50 | } \ No newline at end of file |
diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php index d0c686f0..a8a9c032 100644 --- a/inc/poche/config.inc.php +++ b/inc/poche/config.inc.php | |||
@@ -10,7 +10,7 @@ | |||
10 | 10 | ||
11 | define ('POCHE_VERSION', '1.0-beta'); | 11 | define ('POCHE_VERSION', '1.0-beta'); |
12 | define ('MODE_DEMO', FALSE); | 12 | define ('MODE_DEMO', FALSE); |
13 | define ('DEBUG_POCHE', FALSE); | 13 | define ('DEBUG_POCHE', TRUE); |
14 | define ('CONVERT_LINKS_FOOTNOTES', FALSE); | 14 | define ('CONVERT_LINKS_FOOTNOTES', FALSE); |
15 | define ('REVERT_FORCED_PARAGRAPH_ELEMENTS', FALSE); | 15 | define ('REVERT_FORCED_PARAGRAPH_ELEMENTS', FALSE); |
16 | define ('DOWNLOAD_PICTURES', FALSE); | 16 | define ('DOWNLOAD_PICTURES', FALSE); |
diff --git a/inc/store/file.class.php b/inc/store/file.class.php index ad20937d..c9d85dcc 100644 --- a/inc/store/file.class.php +++ b/inc/store/file.class.php | |||
@@ -44,8 +44,4 @@ class File extends Store { | |||
44 | public function getLastId() { | 44 | public function getLastId() { |
45 | 45 | ||
46 | } | 46 | } |
47 | |||
48 | public function updateContentById($id) { | ||
49 | |||
50 | } | ||
51 | } | 47 | } |
diff --git a/inc/store/mysql.class.php b/inc/store/mysql.class.php index 78254a5f..8b7f83da 100644 --- a/inc/store/mysql.class.php +++ b/inc/store/mysql.class.php | |||
@@ -192,11 +192,4 @@ class Mysql extends Store { | |||
192 | parent::__construct(); | 192 | parent::__construct(); |
193 | return $this->getHandle()->lastInsertId(); | 193 | return $this->getHandle()->lastInsertId(); |
194 | } | 194 | } |
195 | |||
196 | public function updateContentById($id) { | ||
197 | parent::__construct(); | ||
198 | $sql_update = "UPDATE entries SET content=? WHERE id=?"; | ||
199 | $params_update = array($content, $id); | ||
200 | $query = $this->executeQuery($sql_update, $params_update); | ||
201 | } | ||
202 | } | 195 | } |
diff --git a/inc/store/sqlite.class.php b/inc/store/sqlite.class.php index 3cc5276d..4c628dc1 100644 --- a/inc/store/sqlite.class.php +++ b/inc/store/sqlite.class.php | |||
@@ -57,9 +57,9 @@ class Sqlite extends Store { | |||
57 | } | 57 | } |
58 | 58 | ||
59 | public function login($username, $password) { | 59 | public function login($username, $password) { |
60 | $sql = "SELECT * FROM users WHERE username=? AND password=?"; | 60 | $sql = "SELECT * FROM users WHERE username=? AND password=?"; |
61 | $query = $this->executeQuery($sql, array($username, $password)); | 61 | $query = $this->executeQuery($sql, array($username, $password)); |
62 | $login = $query->fetchAll(); | 62 | $login = $query->fetchAll(); |
63 | 63 | ||
64 | $user = array(); | 64 | $user = array(); |
65 | if (isset($login[0])) { | 65 | if (isset($login[0])) { |
@@ -76,9 +76,9 @@ class Sqlite extends Store { | |||
76 | 76 | ||
77 | public function updatePassword($id, $password) | 77 | public function updatePassword($id, $password) |
78 | { | 78 | { |
79 | $sql_update = "UPDATE users SET password=? WHERE id=?"; | 79 | $sql_update = "UPDATE users SET password=? WHERE id=?"; |
80 | $params_update = array($password, $id); | 80 | $params_update = array($password, $id); |
81 | $query = $this->executeQuery($sql_update, $params_update); | 81 | $query = $this->executeQuery($sql_update, $params_update); |
82 | } | 82 | } |
83 | 83 | ||
84 | private function executeQuery($sql, $params) { | 84 | private function executeQuery($sql, $params) { |
@@ -94,27 +94,27 @@ class Sqlite extends Store { | |||
94 | } | 94 | } |
95 | } | 95 | } |
96 | 96 | ||
97 | public function retrieveAll() { | 97 | public function retrieveAll($user_id) { |
98 | $sql = "SELECT * FROM entries ORDER BY id"; | 98 | $sql = "SELECT * FROM entries WHERE user_id=? ORDER BY id"; |
99 | $query = $this->executeQuery($sql, array()); | 99 | $query = $this->executeQuery($sql, array($user_id)); |
100 | $entries = $query->fetchAll(); | 100 | $entries = $query->fetchAll(); |
101 | 101 | ||
102 | return $entries; | 102 | return $entries; |
103 | } | 103 | } |
104 | 104 | ||
105 | public function retrieveOneById($id) { | 105 | public function retrieveOneById($id, $user_id) { |
106 | parent::__construct(); | 106 | parent::__construct(); |
107 | 107 | ||
108 | $entry = NULL; | 108 | $entry = NULL; |
109 | $sql = "SELECT * FROM entries WHERE id=?"; | 109 | $sql = "SELECT * FROM entries WHERE id=? AND user_id=?"; |
110 | $params = array(intval($id)); | 110 | $params = array(intval($id), $user_id); |
111 | $query = $this->executeQuery($sql, $params); | 111 | $query = $this->executeQuery($sql, $params); |
112 | $entry = $query->fetchAll(); | 112 | $entry = $query->fetchAll(); |
113 | 113 | ||
114 | return $entry[0]; | 114 | return $entry[0]; |
115 | } | 115 | } |
116 | 116 | ||
117 | public function getEntriesByView($view, $limit = '') { | 117 | public function getEntriesByView($view, $user_id, $limit = '') { |
118 | parent::__construct(); | 118 | parent::__construct(); |
119 | 119 | ||
120 | switch ($_SESSION['sort']) | 120 | switch ($_SESSION['sort']) |
@@ -139,54 +139,54 @@ class Sqlite extends Store { | |||
139 | switch ($view) | 139 | switch ($view) |
140 | { | 140 | { |
141 | case 'archive': | 141 | case 'archive': |
142 | $sql = "SELECT * FROM entries WHERE is_read=? " . $order; | 142 | $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? " . $order; |
143 | $params = array(-1); | 143 | $params = array($user_id, -1); |
144 | break; | 144 | break; |
145 | case 'fav' : | 145 | case 'fav' : |
146 | $sql = "SELECT * FROM entries WHERE is_fav=? " . $order; | 146 | $sql = "SELECT * FROM entries WHERE user_id=? AND is_fav=? " . $order; |
147 | $params = array(-1); | 147 | $params = array($user_id, -1); |
148 | break; | 148 | break; |
149 | default: | 149 | default: |
150 | $sql = "SELECT * FROM entries WHERE is_read=? " . $order; | 150 | $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? " . $order; |
151 | $params = array(0); | 151 | $params = array($user_id, 0); |
152 | break; | 152 | break; |
153 | } | 153 | } |
154 | 154 | ||
155 | $sql .= ' ' . $limit; | 155 | $sql .= ' ' . $limit; |
156 | 156 | ||
157 | $query = $this->executeQuery($sql, $params); | 157 | $query = $this->executeQuery($sql, $params); |
158 | $entries = $query->fetchAll(); | 158 | $entries = $query->fetchAll(); |
159 | 159 | ||
160 | return $entries; | 160 | return $entries; |
161 | } | 161 | } |
162 | 162 | ||
163 | public function add($url, $title, $content) { | 163 | public function add($url, $title, $content, $user_id) { |
164 | parent::__construct(); | 164 | parent::__construct(); |
165 | $sql_action = 'INSERT INTO entries ( url, title, content ) VALUES (?, ?, ?)'; | 165 | $sql_action = 'INSERT INTO entries ( url, title, content, user_id ) VALUES (?, ?, ?, ?)'; |
166 | $params_action = array($url, $title, $content); | 166 | $params_action = array($url, $title, $content, $user_id); |
167 | $query = $this->executeQuery($sql_action, $params_action); | 167 | $query = $this->executeQuery($sql_action, $params_action); |
168 | return $query; | 168 | return $query; |
169 | } | 169 | } |
170 | 170 | ||
171 | public function deleteById($id) { | 171 | public function deleteById($id, $user_id) { |
172 | parent::__construct(); | 172 | parent::__construct(); |
173 | $sql_action = "DELETE FROM entries WHERE id=?"; | 173 | $sql_action = "DELETE FROM entries WHERE id=? AND user_id=?"; |
174 | $params_action = array($id); | 174 | $params_action = array($id, $user_id); |
175 | $query = $this->executeQuery($sql_action, $params_action); | 175 | $query = $this->executeQuery($sql_action, $params_action); |
176 | return $query; | 176 | return $query; |
177 | } | 177 | } |
178 | 178 | ||
179 | public function favoriteById($id) { | 179 | public function favoriteById($id, $user_id) { |
180 | parent::__construct(); | 180 | parent::__construct(); |
181 | $sql_action = "UPDATE entries SET is_fav=~is_fav WHERE id=?"; | 181 | $sql_action = "UPDATE entries SET is_fav=~is_fav WHERE id=? AND user_id=?"; |
182 | $params_action = array($id); | 182 | $params_action = array($id, $user_id); |
183 | $query = $this->executeQuery($sql_action, $params_action); | 183 | $query = $this->executeQuery($sql_action, $params_action); |
184 | } | 184 | } |
185 | 185 | ||
186 | public function archiveById($id) { | 186 | public function archiveById($id, $user_id) { |
187 | parent::__construct(); | 187 | parent::__construct(); |
188 | $sql_action = "UPDATE entries SET is_read=~is_read WHERE id=?"; | 188 | $sql_action = "UPDATE entries SET is_read=~is_read WHERE id=? AND user_id=?"; |
189 | $params_action = array($id); | 189 | $params_action = array($id, $user_id); |
190 | $query = $this->executeQuery($sql_action, $params_action); | 190 | $query = $this->executeQuery($sql_action, $params_action); |
191 | } | 191 | } |
192 | 192 | ||
@@ -194,11 +194,4 @@ class Sqlite extends Store { | |||
194 | parent::__construct(); | 194 | parent::__construct(); |
195 | return $this->getHandle()->lastInsertId(); | 195 | return $this->getHandle()->lastInsertId(); |
196 | } | 196 | } |
197 | |||
198 | public function updateContentById($id) { | ||
199 | parent::__construct(); | ||
200 | $sql_update = "UPDATE entries SET content=? WHERE id=?"; | ||
201 | $params_update = array($content, $id); | ||
202 | $query = $this->executeQuery($sql_update, $params_update); | ||
203 | } | ||
204 | } | 197 | } |
diff --git a/inc/store/store.class.php b/inc/store/store.class.php index 5f8939b9..d6e63014 100644 --- a/inc/store/store.class.php +++ b/inc/store/store.class.php | |||
@@ -52,8 +52,4 @@ class Store { | |||
52 | public function getLastId() { | 52 | public function getLastId() { |
53 | 53 | ||
54 | } | 54 | } |
55 | |||
56 | public function updateContentById($id) { | ||
57 | |||
58 | } | ||
59 | } | 55 | } |