]>
Commit | Line | Data |
---|---|---|
1a268ba7 NL |
1 | <?php |
2 | /** | |
3 | * poche, a read it later open source system | |
4 | * | |
5 | * @category poche | |
421b65eb | 6 | * @author Nicolas Lœuillet <support@inthepoche.com> |
1a268ba7 NL |
7 | * @copyright 2013 |
8 | * @license http://www.wtfpl.net/ see COPYING file | |
9 | */ | |
10 | ||
031df528 | 11 | define ('POCHE', '1.0.0'); |
00dbaf90 | 12 | require_once 'inc/poche/global.inc.php'; |
bb5a7d9e | 13 | |
00dbaf90 NL |
14 | # Start Poche |
15 | $poche = new Poche(); | |
16 | $notInstalledMessage = $poche -> getNotInstalledMessage(); | |
1a268ba7 | 17 | |
ed06f040 | 18 | # Parse GET & REFERER vars |
a4565e88 | 19 | $referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER']; |
7f959169 | 20 | $view = Tools::checkVar('view', 'home'); |
63c35580 NL |
21 | $action = Tools::checkVar('action'); |
22 | $id = Tools::checkVar('id'); | |
f6df40db | 23 | $_SESSION['sort'] = Tools::checkVar('sort', 'id'); |
63c35580 | 24 | $url = new Url((isset ($_GET['url'])) ? $_GET['url'] : ''); |
8c72b98d | 25 | |
00dbaf90 NL |
26 | # vars to _always_ send to templates |
27 | $tpl_vars = array( | |
28 | 'referer' => $referer, | |
29 | 'view' => $view, | |
30 | 'poche_url' => Tools::getPocheUrl(), | |
31 | 'title' => _('poche, a read it later open source system'), | |
32 | 'token' => Session::getToken(), | |
33 | 'theme' => $poche->getTheme() | |
34 | ); | |
35 | ||
36 | if (! empty($notInstalledMessage)) { | |
37 | if (! Poche::$canRenderTemplates || ! Poche::$configFileAvailable) { | |
38 | # We cannot use Twig to display the error message | |
9d3b88b3 NL |
39 | echo '<h1>Errors</h1><ol>'; |
40 | foreach ($notInstalledMessage as $message) { | |
41 | echo '<li>' . $message . '</li>'; | |
42 | } | |
43 | echo '</ol>'; | |
44 | die(); | |
00dbaf90 NL |
45 | } else { |
46 | # Twig is installed, put the error message in the template | |
47 | $tpl_file = Tools::getTplFile('error'); | |
48 | $tpl_vars = array_merge($tpl_vars, array('msg' => $poche->getNotInstalledMessage())); | |
49 | echo $poche->tpl->render($tpl_file, $tpl_vars); | |
50 | exit; | |
51 | } | |
52 | } | |
53 | ||
ed06f040 | 54 | # poche actions |
a1953dff | 55 | if (isset($_GET['login'])) { |
4f5b44bd | 56 | # hello you |
c765c367 | 57 | $poche->login($referer); |
00dbaf90 | 58 | } elseif (isset($_GET['logout'])) { |
4f5b44bd | 59 | # see you soon ! |
c765c367 | 60 | $poche->logout(); |
00dbaf90 | 61 | } elseif (isset($_GET['config'])) { |
4f5b44bd | 62 | # Update password |
c765c367 | 63 | $poche->updatePassword(); |
00dbaf90 | 64 | } elseif (isset($_GET['import'])) { |
07ee09f4 | 65 | $import = $poche->import($_GET['from']); |
00dbaf90 | 66 | } elseif (isset($_GET['export'])) { |
63c35580 | 67 | $poche->export(); |
00dbaf90 NL |
68 | } elseif (isset($_GET['updatetheme'])) { |
69 | $poche->updateTheme(); | |
5011388f NL |
70 | } elseif (isset($_GET['updatelanguage'])) { |
71 | $poche->updateLanguage(); | |
63c35580 | 72 | } |
5011388f | 73 | |
ce4a1dcc NL |
74 | elseif (isset($_GET['plainurl']) && !empty($_GET['plainurl'])) { |
75 | $plain_url = new Url(base64_encode($_GET['plainurl'])); | |
76 | $poche->action('add', $plain_url); | |
77 | } | |
693b3f86 | 78 | |
e4d2565e | 79 | if (Session::isLogged()) { |
eb1af592 NL |
80 | $poche->action($action, $url, $id); |
81 | $tpl_file = Tools::getTplFile($view); | |
82 | $tpl_vars = array_merge($tpl_vars, $poche->displayView($view, $id)); | |
00dbaf90 NL |
83 | } else { |
84 | $tpl_file = Tools::getTplFile('login'); | |
8c72b98d | 85 | } |
a4565e88 | 86 | |
55821e04 | 87 | # because messages can be added in $poche->action(), we have to add this entry now (we can add it before) |
6a361945 NL |
88 | $messages = $poche->messages->display('all', FALSE); |
89 | $tpl_vars = array_merge($tpl_vars, array('messages' => $messages)); | |
55821e04 | 90 | |
ed06f040 | 91 | # display poche |
eb1af592 | 92 | echo $poche->tpl->render($tpl_file, $tpl_vars); |