]> git.immae.eu Git - github/wallabag/wallabag.git/blob - index.php
Merge pull request #622 from wallabag/fix-612
[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.6.0');
12 require 'check_setup.php';
13 require_once 'inc/poche/global.inc.php';
14
15 # Start session
16 Session::$sessionName = 'poche';
17 Session::init();
18
19 # Start Poche
20 $poche = new Poche();
21 $notInstalledMessage = $poche -> getNotInstalledMessage();
22
23 # Parse GET & REFERER vars
24 $referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
25 $view = Tools::checkVar('view', 'home');
26 $action = Tools::checkVar('action');
27 $id = Tools::checkVar('id');
28 $_SESSION['sort'] = Tools::checkVar('sort', 'id');
29 $url = new Url((isset ($_GET['url'])) ? $_GET['url'] : '');
30
31 # vars to _always_ send to templates
32 $tpl_vars = array(
33 'referer' => $referer,
34 'view' => $view,
35 'poche_url' => Tools::getPocheUrl(),
36 'title' => _('wallabag, a read it later open source system'),
37 'token' => Session::getToken(),
38 'theme' => $poche->getTheme()
39 );
40
41 if (! empty($notInstalledMessage)) {
42 if (! Poche::$canRenderTemplates || ! Poche::$configFileAvailable) {
43 # We cannot use Twig to display the error message
44 echo '<h1>Errors</h1><ol>';
45 foreach ($notInstalledMessage as $message) {
46 echo '<li>' . $message . '</li>';
47 }
48 echo '</ol>';
49 die();
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
59 # poche actions
60 if (isset($_GET['login'])) {
61 # hello you
62 $poche->login($referer);
63 } elseif (isset($_GET['logout'])) {
64 # see you soon !
65 $poche->logout();
66 } elseif (isset($_GET['config'])) {
67 # Update password
68 $poche->updatePassword();
69 } elseif (isset($_GET['import'])) {
70 $import = $poche->import();
71 $tpl_vars = array_merge($tpl_vars, $import);
72 } elseif (isset($_GET['download'])) {
73 Tools::download_db();
74 } elseif (isset($_GET['empty-cache'])) {
75 $poche->emptyCache();
76 } elseif (isset($_GET['export'])) {
77 $poche->export();
78 } elseif (isset($_GET['updatetheme'])) {
79 $poche->updateTheme();
80 } elseif (isset($_GET['updatelanguage'])) {
81 $poche->updateLanguage();
82 } elseif (isset($_GET['uploadfile'])) {
83 $poche->uploadFile();
84 } elseif (isset($_GET['feed'])) {
85 if (isset($_GET['action']) && $_GET['action'] == 'generate') {
86 $poche->generateToken();
87 }
88 else {
89 $tag_id = (isset($_GET['tag_id']) ? intval($_GET['tag_id']) : 0);
90 $poche->generateFeeds($_GET['token'], $_GET['user_id'], $tag_id, $_GET['type']);
91 }
92 }
93
94 elseif (isset($_GET['plainurl']) && !empty($_GET['plainurl'])) {
95 $plain_url = new Url(base64_encode($_GET['plainurl']));
96 $poche->action('add', $plain_url);
97 }
98
99 if (Session::isLogged()) {
100 $poche->action($action, $url, $id);
101 $tpl_file = Tools::getTplFile($view);
102 $tpl_vars = array_merge($tpl_vars, $poche->displayView($view, $id));
103 } elseif(isset($_SERVER['PHP_AUTH_USER'])) {
104 if($poche->store->userExists($_SERVER['PHP_AUTH_USER'])) {
105 $poche->login($referer);
106 } else {
107 $poche->messages->add('e', _('login failed: user doesn\'t exist'));
108 Tools::logm('user doesn\'t exist');
109 $tpl_file = Tools::getTplFile('login');
110 $tpl_vars['http_auth'] = 1;
111 }
112 } elseif(isset($_SERVER['REMOTE_USER'])) {
113 if($poche->store->userExists($_SERVER['REMOTE_USER'])) {
114 $poche->login($referer);
115 } else {
116 $poche->messages->add('e', _('login failed: user doesn\'t exist'));
117 Tools::logm('user doesn\'t exist');
118 $tpl_file = Tools::getTplFile('login');
119 $tpl_vars['http_auth'] = 1;
120 }
121 } else {
122 $tpl_file = Tools::getTplFile('login');
123 $tpl_vars['http_auth'] = 0;
124 Session::logout();
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);