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