]> git.immae.eu Git - github/wallabag/wallabag.git/blame - index.php
Merge pull request #576 from mariroz/fix-session-livetime
[github/wallabag/wallabag.git] / index.php
CommitLineData
1a268ba7
NL
1<?php
2/**
c95b78a8 3 * wallabag, self hostable application allowing you to not miss any content anymore
1a268ba7 4 *
c95b78a8
NL
5 * @category wallabag
6 * @author Nicolas Lœuillet <nicolas@loeuillet.org>
1a268ba7
NL
7 * @copyright 2013
8 * @license http://www.wtfpl.net/ see COPYING file
9 */
10
4c149363 11define ('POCHE', '1.5.3');
792097fb 12require 'check_setup.php';
00dbaf90 13require_once 'inc/poche/global.inc.php';
bb5a7d9e 14
eb5b6772
MR
15# Start session
16Session::$sessionName = 'poche';
17if ( !isset($_GET['login']) ) {
18 Session::init();
19}
20
00dbaf90
NL
21# Start Poche
22$poche = new Poche();
23$notInstalledMessage = $poche -> getNotInstalledMessage();
1a268ba7 24
ed06f040 25# Parse GET & REFERER vars
a4565e88 26$referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
7f959169 27$view = Tools::checkVar('view', 'home');
63c35580
NL
28$action = Tools::checkVar('action');
29$id = Tools::checkVar('id');
f6df40db 30$_SESSION['sort'] = Tools::checkVar('sort', 'id');
63c35580 31$url = new Url((isset ($_GET['url'])) ? $_GET['url'] : '');
8c72b98d 32
00dbaf90
NL
33# vars to _always_ send to templates
34$tpl_vars = array(
35 'referer' => $referer,
36 'view' => $view,
37 'poche_url' => Tools::getPocheUrl(),
dcc73856 38 'title' => _('wallabag, a read it later open source system'),
00dbaf90
NL
39 'token' => Session::getToken(),
40 'theme' => $poche->getTheme()
41);
42
43if (! empty($notInstalledMessage)) {
44 if (! Poche::$canRenderTemplates || ! Poche::$configFileAvailable) {
45 # We cannot use Twig to display the error message
9d3b88b3
NL
46 echo '<h1>Errors</h1><ol>';
47 foreach ($notInstalledMessage as $message) {
48 echo '<li>' . $message . '</li>';
49 }
50 echo '</ol>';
51 die();
00dbaf90
NL
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
ed06f040 61# poche actions
a1953dff 62if (isset($_GET['login'])) {
4f5b44bd 63 # hello you
c765c367 64 $poche->login($referer);
00dbaf90 65} elseif (isset($_GET['logout'])) {
4f5b44bd 66 # see you soon !
c765c367 67 $poche->logout();
00dbaf90 68} elseif (isset($_GET['config'])) {
4f5b44bd 69 # Update password
c765c367 70 $poche->updatePassword();
00dbaf90 71} elseif (isset($_GET['import'])) {
07ee09f4 72 $import = $poche->import($_GET['from']);
d460914f 73} elseif (isset($_GET['download'])) {
6285e57c
NL
74 Tools::download_db();
75} elseif (isset($_GET['empty-cache'])) {
76 $poche->emptyCache();
00dbaf90 77} elseif (isset($_GET['export'])) {
63c35580 78 $poche->export();
00dbaf90
NL
79} elseif (isset($_GET['updatetheme'])) {
80 $poche->updateTheme();
5011388f
NL
81} elseif (isset($_GET['updatelanguage'])) {
82 $poche->updateLanguage();
31a10069
NL
83} elseif (isset($_GET['uploadfile'])) {
84 $poche->uploadFile();
72c20a52 85} elseif (isset($_GET['feed'])) {
f0133fe5 86 if (isset($_GET['action']) && $_GET['action'] == 'generate') {
72c20a52
NL
87 $poche->generateToken();
88 }
89 else {
f778e472
NL
90 $tag_id = (isset($_GET['tag_id']) ? intval($_GET['tag_id']) : 0);
91 $poche->generateFeeds($_GET['token'], $_GET['user_id'], $tag_id, $_GET['type']);
72c20a52 92 }
63c35580 93}
5011388f 94
ce4a1dcc
NL
95elseif (isset($_GET['plainurl']) && !empty($_GET['plainurl'])) {
96 $plain_url = new Url(base64_encode($_GET['plainurl']));
97 $poche->action('add', $plain_url);
98}
693b3f86 99
e4d2565e 100if (Session::isLogged()) {
eb1af592
NL
101 $poche->action($action, $url, $id);
102 $tpl_file = Tools::getTplFile($view);
103 $tpl_vars = array_merge($tpl_vars, $poche->displayView($view, $id));
df6afaf0 104} elseif(isset($_SERVER['PHP_AUTH_USER'])) {
027b4e15
DS
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 }
1810c13b
NL
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 }
00dbaf90
NL
122} else {
123 $tpl_file = Tools::getTplFile('login');
027b4e15 124 $tpl_vars['http_auth'] = 0;
8c72b98d 125}
a4565e88 126
55821e04 127# because messages can be added in $poche->action(), we have to add this entry now (we can add it before)
6a361945
NL
128$messages = $poche->messages->display('all', FALSE);
129$tpl_vars = array_merge($tpl_vars, array('messages' => $messages));
55821e04 130
ed06f040 131# display poche
df6afaf0 132echo $poche->tpl->render($tpl_file, $tpl_vars);