]> git.immae.eu Git - github/wallabag/wallabag.git/blob - index.php
Merge pull request #567 from mariroz/fix-session-livetime
[github/wallabag/wallabag.git] / index.php
1 <?php
2 /**
3 * wallabag, self hostable application allowing you to not miss any content anymore
4 *
5 * @category wallabag
6 * @author Nicolas LÅ“uillet <nicolas@loeuillet.org>
7 * @copyright 2013
8 * @license http://www.wtfpl.net/ see COPYING file
9 */
10
11 define ('POCHE', '1.5.3');
12 require 'check_setup.php';
13 require_once 'inc/poche/global.inc.php';
14
15 # Start session
16 Session::$sessionName = 'poche';
17 if ( !isset($_GET['login']) ) {
18 Session::init();
19 }
20
21 # Start Poche
22 $poche = new Poche();
23 $notInstalledMessage = $poche -> getNotInstalledMessage();
24
25 # Parse GET & REFERER vars
26 $referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
27 $view = Tools::checkVar('view', 'home');
28 $action = Tools::checkVar('action');
29 $id = Tools::checkVar('id');
30 $_SESSION['sort'] = Tools::checkVar('sort', 'id');
31 $url = new Url((isset ($_GET['url'])) ? $_GET['url'] : '');
32
33 # vars to _always_ send to templates
34 $tpl_vars = array(
35 'referer' => $referer,
36 'view' => $view,
37 'poche_url' => Tools::getPocheUrl(),
38 'title' => _('wallabag, a read it later open source system'),
39 'token' => Session::getToken(),
40 'theme' => $poche->getTheme()
41 );
42
43 if (! empty($notInstalledMessage)) {
44 if (! Poche::$canRenderTemplates || ! Poche::$configFileAvailable) {
45 # We cannot use Twig to display the error message
46 echo '<h1>Errors</h1><ol>';
47 foreach ($notInstalledMessage as $message) {
48 echo '<li>' . $message . '</li>';
49 }
50 echo '</ol>';
51 die();
52 } else {
53 # Twig is installed, put the error message in the template
54 $tpl_file = Tools::getTplFile('error');
55 $tpl_vars = array_merge($tpl_vars, array('msg' => $poche->getNotInstalledMessage()));
56 echo $poche->tpl->render($tpl_file, $tpl_vars);
57 exit;
58 }
59 }
60
61 # poche actions
62 if (isset($_GET['login'])) {
63 # hello you
64 $poche->login($referer);
65 } elseif (isset($_GET['logout'])) {
66 # see you soon !
67 $poche->logout();
68 } elseif (isset($_GET['config'])) {
69 # Update password
70 $poche->updatePassword();
71 } elseif (isset($_GET['import'])) {
72 $import = $poche->import($_GET['from']);
73 } elseif (isset($_GET['download'])) {
74 Tools::download_db();
75 } elseif (isset($_GET['empty-cache'])) {
76 $poche->emptyCache();
77 } elseif (isset($_GET['export'])) {
78 $poche->export();
79 } elseif (isset($_GET['updatetheme'])) {
80 $poche->updateTheme();
81 } elseif (isset($_GET['updatelanguage'])) {
82 $poche->updateLanguage();
83 } elseif (isset($_GET['uploadfile'])) {
84 $poche->uploadFile();
85 } elseif (isset($_GET['feed'])) {
86 if (isset($_GET['action']) && $_GET['action'] == 'generate') {
87 $poche->generateToken();
88 }
89 else {
90 $tag_id = (isset($_GET['tag_id']) ? intval($_GET['tag_id']) : 0);
91 $poche->generateFeeds($_GET['token'], $_GET['user_id'], $tag_id, $_GET['type']);
92 }
93 }
94
95 elseif (isset($_GET['plainurl']) && !empty($_GET['plainurl'])) {
96 $plain_url = new Url(base64_encode($_GET['plainurl']));
97 $poche->action('add', $plain_url);
98 }
99
100 if (Session::isLogged()) {
101 $poche->action($action, $url, $id);
102 $tpl_file = Tools::getTplFile($view);
103 $tpl_vars = array_merge($tpl_vars, $poche->displayView($view, $id));
104 } elseif(isset($_SERVER['PHP_AUTH_USER'])) {
105 if($poche->store->userExists($_SERVER['PHP_AUTH_USER'])) {
106 $poche->login($referer);
107 } else {
108 $poche->messages->add('e', _('login failed: user doesn\'t exist'));
109 Tools::logm('user doesn\'t exist');
110 $tpl_file = Tools::getTplFile('login');
111 $tpl_vars['http_auth'] = 1;
112 }
113 } elseif(isset($_SERVER['REMOTE_USER'])) {
114 if($poche->store->userExists($_SERVER['REMOTE_USER'])) {
115 $poche->login($referer);
116 } else {
117 $poche->messages->add('e', _('login failed: user doesn\'t exist'));
118 Tools::logm('user doesn\'t exist');
119 $tpl_file = Tools::getTplFile('login');
120 $tpl_vars['http_auth'] = 1;
121 }
122 } else {
123 $tpl_file = Tools::getTplFile('login');
124 $tpl_vars['http_auth'] = 0;
125 }
126
127 # because messages can be added in $poche->action(), we have to add this entry now (we can add it before)
128 $messages = $poche->messages->display('all', FALSE);
129 $tpl_vars = array_merge($tpl_vars, array('messages' => $messages));
130
131 # display poche
132 echo $poche->tpl->render($tpl_file, $tpl_vars);