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