]> git.immae.eu Git - github/wallabag/wallabag.git/blob - index.php
display flash message in article view
[github/wallabag/wallabag.git] / index.php
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
11 include dirname(__FILE__).'/inc/config.php';
12
13 myTool::initPhp();
14
15 # XSRF protection with token
16 if (!empty($_POST)) {
17 if (!Session::isToken($_POST['token'])) {
18 die('Wrong token.');
19 }
20 unset($_SESSION['tokens']);
21 }
22
23 $ref = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
24
25 if (isset($_GET['login'])) {
26 // Login
27 if (!empty($_POST['login']) && !empty($_POST['password'])) {
28 if (Session::login('poche', 'poche', $_POST['login'], $_POST['password'])) {
29 logm('login successful');
30 $msg->add('s', 'welcome in your pocket!');
31 if (!empty($_POST['longlastingsession'])) {
32 $_SESSION['longlastingsession'] = 31536000;
33 $_SESSION['expires_on'] = time() + $_SESSION['longlastingsession'];
34 session_set_cookie_params($_SESSION['longlastingsession']);
35 } else {
36 session_set_cookie_params(0); // when browser closes
37 }
38 session_regenerate_id(true);
39
40 MyTool::redirect($ref);
41 }
42 logm('login failed');
43 die("Login failed !");
44 } else {
45 logm('login failed');
46 }
47 }
48 elseif (isset($_GET['logout'])) {
49 logm('logout');
50 Session::logout();
51 MyTool::redirect();
52 }
53
54 # Traitement des paramètres et déclenchement des actions
55 $view = (isset ($_REQUEST['view'])) ? htmlentities($_REQUEST['view']) : 'index';
56 $full_head = (isset ($_REQUEST['full_head'])) ? htmlentities($_REQUEST['full_head']) : 'yes';
57 $action = (isset ($_REQUEST['action'])) ? htmlentities($_REQUEST['action']) : '';
58 $_SESSION['sort'] = (isset ($_REQUEST['sort'])) ? htmlentities($_REQUEST['sort']) : 'id';
59 $id = (isset ($_REQUEST['id'])) ? htmlspecialchars($_REQUEST['id']) : '';
60 $url = (isset ($_GET['url'])) ? $_GET['url'] : '';
61
62 $tpl->assign('isLogged', Session::isLogged());
63 $tpl->assign('referer', $ref);
64 $tpl->assign('view', $view);
65 $tpl->assign('poche_url', myTool::getUrl());
66 $tpl->assign('title', 'poche, a read it later open source system');
67
68 if (Session::isLogged()) {
69 action_to_do($action, $url, $id);
70 display_view($view, $id, $full_head);
71 }
72 else {
73 $tpl->draw('login');
74 }