]>
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 | ||
c13aac1b | 11 | define ('POCHE', '1.7.1'); |
9c67b1b8 | 12 | require 'check_essentials.php'; |
00dbaf90 | 13 | require_once 'inc/poche/global.inc.php'; |
9c67b1b8 | 14 | require 'check_setup.php'; |
bb5a7d9e | 15 | |
752cd4a8 | 16 | # Set error reporting level |
a13ff957 | 17 | if (defined('ERROR_REPORTING')) { |
18 | error_reporting(ERROR_REPORTING); | |
752cd4a8 MR |
19 | } |
20 | ||
eb5b6772 MR |
21 | # Start session |
22 | Session::$sessionName = 'poche'; | |
ad53faf2 | 23 | Session::init(); |
eb5b6772 | 24 | |
00dbaf90 NL |
25 | # Start Poche |
26 | $poche = new Poche(); | |
27 | $notInstalledMessage = $poche -> getNotInstalledMessage(); | |
1a268ba7 | 28 | |
ed06f040 | 29 | # Parse GET & REFERER vars |
a4565e88 | 30 | $referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER']; |
7f959169 | 31 | $view = Tools::checkVar('view', 'home'); |
63c35580 NL |
32 | $action = Tools::checkVar('action'); |
33 | $id = Tools::checkVar('id'); | |
f6df40db | 34 | $_SESSION['sort'] = Tools::checkVar('sort', 'id'); |
63c35580 | 35 | $url = new Url((isset ($_GET['url'])) ? $_GET['url'] : ''); |
8c72b98d | 36 | |
00dbaf90 NL |
37 | # vars to _always_ send to templates |
38 | $tpl_vars = array( | |
39 | 'referer' => $referer, | |
40 | 'view' => $view, | |
41 | 'poche_url' => Tools::getPocheUrl(), | |
dcc73856 | 42 | 'title' => _('wallabag, a read it later open source system'), |
00dbaf90 NL |
43 | 'token' => Session::getToken(), |
44 | 'theme' => $poche->getTheme() | |
45 | ); | |
46 | ||
47 | if (! empty($notInstalledMessage)) { | |
48 | if (! Poche::$canRenderTemplates || ! Poche::$configFileAvailable) { | |
182faf26 | 49 | # We cannot use Twig to display the error message |
9d3b88b3 NL |
50 | echo '<h1>Errors</h1><ol>'; |
51 | foreach ($notInstalledMessage as $message) { | |
52 | echo '<li>' . $message . '</li>'; | |
53 | } | |
54 | echo '</ol>'; | |
55 | die(); | |
00dbaf90 NL |
56 | } else { |
57 | # Twig is installed, put the error message in the template | |
58 | $tpl_file = Tools::getTplFile('error'); | |
59 | $tpl_vars = array_merge($tpl_vars, array('msg' => $poche->getNotInstalledMessage())); | |
60 | echo $poche->tpl->render($tpl_file, $tpl_vars); | |
61 | exit; | |
62 | } | |
63 | } | |
64 | ||
ed06f040 | 65 | # poche actions |
a1953dff | 66 | if (isset($_GET['login'])) { |
4f5b44bd | 67 | # hello you |
c765c367 | 68 | $poche->login($referer); |
00dbaf90 | 69 | } elseif (isset($_GET['logout'])) { |
4f5b44bd | 70 | # see you soon ! |
c765c367 | 71 | $poche->logout(); |
00dbaf90 | 72 | } elseif (isset($_GET['config'])) { |
4f5b44bd | 73 | # Update password |
c765c367 | 74 | $poche->updatePassword(); |
4d99bae8 | 75 | } elseif (isset($_GET['newuser'])) { |
76 | $poche->createNewUser(); | |
77 | } elseif (isset($_GET['deluser'])) { | |
78 | $poche->deleteUser(); | |
87090d8a | 79 | } elseif (isset($_GET['epub'])) { |
80 | $poche->createEpub(); | |
00dbaf90 | 81 | } elseif (isset($_GET['import'])) { |
182faf26 MR |
82 | $import = $poche->import(); |
83 | $tpl_vars = array_merge($tpl_vars, $import); | |
d460914f | 84 | } elseif (isset($_GET['download'])) { |
6285e57c NL |
85 | Tools::download_db(); |
86 | } elseif (isset($_GET['empty-cache'])) { | |
87 | $poche->emptyCache(); | |
00dbaf90 | 88 | } elseif (isset($_GET['export'])) { |
63c35580 | 89 | $poche->export(); |
00dbaf90 NL |
90 | } elseif (isset($_GET['updatetheme'])) { |
91 | $poche->updateTheme(); | |
5011388f NL |
92 | } elseif (isset($_GET['updatelanguage'])) { |
93 | $poche->updateLanguage(); | |
31a10069 NL |
94 | } elseif (isset($_GET['uploadfile'])) { |
95 | $poche->uploadFile(); | |
72c20a52 | 96 | } elseif (isset($_GET['feed'])) { |
f0133fe5 | 97 | if (isset($_GET['action']) && $_GET['action'] == 'generate') { |
72c20a52 NL |
98 | $poche->generateToken(); |
99 | } | |
100 | else { | |
f778e472 | 101 | $tag_id = (isset($_GET['tag_id']) ? intval($_GET['tag_id']) : 0); |
a13ff957 | 102 | $poche->generateFeeds($_GET['token'], filter_var($_GET['user_id'],FILTER_SANITIZE_NUMBER_INT), $tag_id, $_GET['type']); |
72c20a52 | 103 | } |
63c35580 | 104 | } |
5011388f | 105 | |
ce4a1dcc NL |
106 | elseif (isset($_GET['plainurl']) && !empty($_GET['plainurl'])) { |
107 | $plain_url = new Url(base64_encode($_GET['plainurl'])); | |
108 | $poche->action('add', $plain_url); | |
109 | } | |
693b3f86 | 110 | |
e4d2565e | 111 | if (Session::isLogged()) { |
eb1af592 NL |
112 | $poche->action($action, $url, $id); |
113 | $tpl_file = Tools::getTplFile($view); | |
114 | $tpl_vars = array_merge($tpl_vars, $poche->displayView($view, $id)); | |
df6afaf0 | 115 | } elseif(isset($_SERVER['PHP_AUTH_USER'])) { |
027b4e15 DS |
116 | if($poche->store->userExists($_SERVER['PHP_AUTH_USER'])) { |
117 | $poche->login($referer); | |
118 | } else { | |
119 | $poche->messages->add('e', _('login failed: user doesn\'t exist')); | |
120 | Tools::logm('user doesn\'t exist'); | |
121 | $tpl_file = Tools::getTplFile('login'); | |
122 | $tpl_vars['http_auth'] = 1; | |
123 | } | |
1810c13b NL |
124 | } elseif(isset($_SERVER['REMOTE_USER'])) { |
125 | if($poche->store->userExists($_SERVER['REMOTE_USER'])) { | |
126 | $poche->login($referer); | |
127 | } else { | |
128 | $poche->messages->add('e', _('login failed: user doesn\'t exist')); | |
129 | Tools::logm('user doesn\'t exist'); | |
130 | $tpl_file = Tools::getTplFile('login'); | |
131 | $tpl_vars['http_auth'] = 1; | |
132 | } | |
00dbaf90 NL |
133 | } else { |
134 | $tpl_file = Tools::getTplFile('login'); | |
027b4e15 | 135 | $tpl_vars['http_auth'] = 0; |
ad53faf2 | 136 | Session::logout(); |
8c72b98d | 137 | } |
a4565e88 | 138 | |
55821e04 | 139 | # because messages can be added in $poche->action(), we have to add this entry now (we can add it before) |
6a361945 NL |
140 | $messages = $poche->messages->display('all', FALSE); |
141 | $tpl_vars = array_merge($tpl_vars, array('messages' => $messages)); | |
55821e04 | 142 | |
ed06f040 | 143 | # display poche |
df6afaf0 | 144 | echo $poche->tpl->render($tpl_file, $tpl_vars); |