diff options
author | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-06 15:51:48 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-06 15:51:48 +0200 |
commit | 8d3275bee488d058c6ff0efe6e81d20a584d3709 (patch) | |
tree | 80b82707b6aecc5e29fa72cbdcf8ffe76ba8b7b4 /inc/poche | |
parent | 7ce7ec4c942e0a3567858ad0ec8e654000b49a3f (diff) | |
download | wallabag-8d3275bee488d058c6ff0efe6e81d20a584d3709.tar.gz wallabag-8d3275bee488d058c6ff0efe6e81d20a584d3709.tar.zst wallabag-8d3275bee488d058c6ff0efe6e81d20a584d3709.zip |
multi user
Diffstat (limited to 'inc/poche')
-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 |
3 files changed, 70 insertions, 37 deletions
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); |