]>
Commit | Line | Data |
---|---|---|
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 | ||
d3b47e94 | 11 | define ('POCHE', '1.5.2'); |
792097fb | 12 | require 'check_setup.php'; |
00dbaf90 | 13 | require_once 'inc/poche/global.inc.php'; |
36b92198 | 14 | session_start(); |
bb5a7d9e | 15 | |
00dbaf90 NL |
16 | # Start Poche |
17 | $poche = new Poche(); | |
18 | $notInstalledMessage = $poche -> getNotInstalledMessage(); | |
1a268ba7 | 19 | |
ed06f040 | 20 | # Parse GET & REFERER vars |
a4565e88 | 21 | $referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER']; |
7f959169 | 22 | $view = Tools::checkVar('view', 'home'); |
63c35580 NL |
23 | $action = Tools::checkVar('action'); |
24 | $id = Tools::checkVar('id'); | |
f6df40db | 25 | $_SESSION['sort'] = Tools::checkVar('sort', 'id'); |
63c35580 | 26 | $url = new Url((isset ($_GET['url'])) ? $_GET['url'] : ''); |
8c72b98d | 27 | |
00dbaf90 NL |
28 | # vars to _always_ send to templates |
29 | $tpl_vars = array( | |
30 | 'referer' => $referer, | |
31 | 'view' => $view, | |
32 | 'poche_url' => Tools::getPocheUrl(), | |
33 | 'title' => _('poche, 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 | |
9d3b88b3 NL |
41 | echo '<h1>Errors</h1><ol>'; |
42 | foreach ($notInstalledMessage as $message) { | |
43 | echo '<li>' . $message . '</li>'; | |
44 | } | |
45 | echo '</ol>'; | |
46 | die(); | |
00dbaf90 NL |
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 | ||
ed06f040 | 56 | # poche actions |
a1953dff | 57 | if (isset($_GET['login'])) { |
4f5b44bd | 58 | # hello you |
c765c367 | 59 | $poche->login($referer); |
00dbaf90 | 60 | } elseif (isset($_GET['logout'])) { |
4f5b44bd | 61 | # see you soon ! |
c765c367 | 62 | $poche->logout(); |
00dbaf90 | 63 | } elseif (isset($_GET['config'])) { |
4f5b44bd | 64 | # Update password |
c765c367 | 65 | $poche->updatePassword(); |
00dbaf90 | 66 | } elseif (isset($_GET['import'])) { |
07ee09f4 | 67 | $import = $poche->import($_GET['from']); |
d460914f | 68 | } elseif (isset($_GET['download'])) { |
6285e57c NL |
69 | Tools::download_db(); |
70 | } elseif (isset($_GET['empty-cache'])) { | |
71 | $poche->emptyCache(); | |
00dbaf90 | 72 | } elseif (isset($_GET['export'])) { |
63c35580 | 73 | $poche->export(); |
00dbaf90 NL |
74 | } elseif (isset($_GET['updatetheme'])) { |
75 | $poche->updateTheme(); | |
5011388f NL |
76 | } elseif (isset($_GET['updatelanguage'])) { |
77 | $poche->updateLanguage(); | |
72c20a52 | 78 | } elseif (isset($_GET['feed'])) { |
f0133fe5 | 79 | if (isset($_GET['action']) && $_GET['action'] == 'generate') { |
72c20a52 NL |
80 | $poche->generateToken(); |
81 | } | |
82 | else { | |
f778e472 NL |
83 | $tag_id = (isset($_GET['tag_id']) ? intval($_GET['tag_id']) : 0); |
84 | $poche->generateFeeds($_GET['token'], $_GET['user_id'], $tag_id, $_GET['type']); | |
72c20a52 | 85 | } |
63c35580 | 86 | } |
5011388f | 87 | |
ce4a1dcc NL |
88 | elseif (isset($_GET['plainurl']) && !empty($_GET['plainurl'])) { |
89 | $plain_url = new Url(base64_encode($_GET['plainurl'])); | |
90 | $poche->action('add', $plain_url); | |
91 | } | |
693b3f86 | 92 | |
e4d2565e | 93 | if (Session::isLogged()) { |
eb1af592 NL |
94 | $poche->action($action, $url, $id); |
95 | $tpl_file = Tools::getTplFile($view); | |
96 | $tpl_vars = array_merge($tpl_vars, $poche->displayView($view, $id)); | |
df6afaf0 | 97 | } elseif(isset($_SERVER['PHP_AUTH_USER'])) { |
027b4e15 DS |
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 | } | |
1810c13b NL |
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 | } | |
00dbaf90 NL |
115 | } else { |
116 | $tpl_file = Tools::getTplFile('login'); | |
027b4e15 | 117 | $tpl_vars['http_auth'] = 0; |
8c72b98d | 118 | } |
a4565e88 | 119 | |
55821e04 | 120 | # because messages can be added in $poche->action(), we have to add this entry now (we can add it before) |
6a361945 NL |
121 | $messages = $poche->messages->display('all', FALSE); |
122 | $tpl_vars = array_merge($tpl_vars, array('messages' => $messages)); | |
55821e04 | 123 | |
ed06f040 | 124 | # display poche |
df6afaf0 | 125 | echo $poche->tpl->render($tpl_file, $tpl_vars); |