]> git.immae.eu Git - github/wallabag/wallabag.git/blame - index.php
Merge pull request #715 from mariroz/dev
[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
8038b388 11define ('POCHE', '1.7.0');
792097fb 12require 'check_setup.php';
00dbaf90 13require_once 'inc/poche/global.inc.php';
bb5a7d9e 14
eb5b6772
MR
15# Start session
16Session::$sessionName = 'poche';
ad53faf2 17Session::init();
eb5b6772 18
00dbaf90
NL
19# Start Poche
20$poche = new Poche();
21$notInstalledMessage = $poche -> getNotInstalledMessage();
1a268ba7 22
ed06f040 23# Parse GET & REFERER vars
a4565e88 24$referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
7f959169 25$view = Tools::checkVar('view', 'home');
63c35580
NL
26$action = Tools::checkVar('action');
27$id = Tools::checkVar('id');
f6df40db 28$_SESSION['sort'] = Tools::checkVar('sort', 'id');
63c35580 29$url = new Url((isset ($_GET['url'])) ? $_GET['url'] : '');
8c72b98d 30
00dbaf90
NL
31# vars to _always_ send to templates
32$tpl_vars = array(
33 'referer' => $referer,
34 'view' => $view,
35 'poche_url' => Tools::getPocheUrl(),
dcc73856 36 'title' => _('wallabag, a read it later open source system'),
00dbaf90
NL
37 'token' => Session::getToken(),
38 'theme' => $poche->getTheme()
39);
40
41if (! empty($notInstalledMessage)) {
42 if (! Poche::$canRenderTemplates || ! Poche::$configFileAvailable) {
182faf26 43 # We cannot use Twig to display the error message
9d3b88b3
NL
44 echo '<h1>Errors</h1><ol>';
45 foreach ($notInstalledMessage as $message) {
46 echo '<li>' . $message . '</li>';
47 }
48 echo '</ol>';
49 die();
00dbaf90
NL
50 } else {
51 # Twig is installed, put the error message in the template
52 $tpl_file = Tools::getTplFile('error');
53 $tpl_vars = array_merge($tpl_vars, array('msg' => $poche->getNotInstalledMessage()));
54 echo $poche->tpl->render($tpl_file, $tpl_vars);
55 exit;
56 }
57}
58
ed06f040 59# poche actions
a1953dff 60if (isset($_GET['login'])) {
4f5b44bd 61 # hello you
c765c367 62 $poche->login($referer);
00dbaf90 63} elseif (isset($_GET['logout'])) {
4f5b44bd 64 # see you soon !
c765c367 65 $poche->logout();
00dbaf90 66} elseif (isset($_GET['config'])) {
4f5b44bd 67 # Update password
c765c367 68 $poche->updatePassword();
4d99bae8 69} elseif (isset($_GET['newuser'])) {
70 $poche->createNewUser();
71} elseif (isset($_GET['deluser'])) {
72 $poche->deleteUser();
87090d8a 73} elseif (isset($_GET['epub'])) {
74 $poche->createEpub();
00dbaf90 75} elseif (isset($_GET['import'])) {
182faf26
MR
76 $import = $poche->import();
77 $tpl_vars = array_merge($tpl_vars, $import);
d460914f 78} elseif (isset($_GET['download'])) {
6285e57c
NL
79 Tools::download_db();
80} elseif (isset($_GET['empty-cache'])) {
81 $poche->emptyCache();
00dbaf90 82} elseif (isset($_GET['export'])) {
63c35580 83 $poche->export();
00dbaf90
NL
84} elseif (isset($_GET['updatetheme'])) {
85 $poche->updateTheme();
5011388f
NL
86} elseif (isset($_GET['updatelanguage'])) {
87 $poche->updateLanguage();
31a10069
NL
88} elseif (isset($_GET['uploadfile'])) {
89 $poche->uploadFile();
72c20a52 90} elseif (isset($_GET['feed'])) {
f0133fe5 91 if (isset($_GET['action']) && $_GET['action'] == 'generate') {
72c20a52
NL
92 $poche->generateToken();
93 }
94 else {
f778e472
NL
95 $tag_id = (isset($_GET['tag_id']) ? intval($_GET['tag_id']) : 0);
96 $poche->generateFeeds($_GET['token'], $_GET['user_id'], $tag_id, $_GET['type']);
72c20a52 97 }
63c35580 98}
5011388f 99
ce4a1dcc
NL
100elseif (isset($_GET['plainurl']) && !empty($_GET['plainurl'])) {
101 $plain_url = new Url(base64_encode($_GET['plainurl']));
102 $poche->action('add', $plain_url);
103}
693b3f86 104
e4d2565e 105if (Session::isLogged()) {
eb1af592
NL
106 $poche->action($action, $url, $id);
107 $tpl_file = Tools::getTplFile($view);
108 $tpl_vars = array_merge($tpl_vars, $poche->displayView($view, $id));
df6afaf0 109} elseif(isset($_SERVER['PHP_AUTH_USER'])) {
027b4e15
DS
110 if($poche->store->userExists($_SERVER['PHP_AUTH_USER'])) {
111 $poche->login($referer);
112 } else {
113 $poche->messages->add('e', _('login failed: user doesn\'t exist'));
114 Tools::logm('user doesn\'t exist');
115 $tpl_file = Tools::getTplFile('login');
116 $tpl_vars['http_auth'] = 1;
117 }
1810c13b
NL
118} elseif(isset($_SERVER['REMOTE_USER'])) {
119 if($poche->store->userExists($_SERVER['REMOTE_USER'])) {
120 $poche->login($referer);
121 } else {
122 $poche->messages->add('e', _('login failed: user doesn\'t exist'));
123 Tools::logm('user doesn\'t exist');
124 $tpl_file = Tools::getTplFile('login');
125 $tpl_vars['http_auth'] = 1;
126 }
00dbaf90
NL
127} else {
128 $tpl_file = Tools::getTplFile('login');
027b4e15 129 $tpl_vars['http_auth'] = 0;
ad53faf2 130 Session::logout();
8c72b98d 131}
a4565e88 132
55821e04 133# because messages can be added in $poche->action(), we have to add this entry now (we can add it before)
6a361945
NL
134$messages = $poche->messages->display('all', FALSE);
135$tpl_vars = array_merge($tpl_vars, array('messages' => $messages));
55821e04 136
ed06f040 137# display poche
df6afaf0 138echo $poche->tpl->render($tpl_file, $tpl_vars);