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