]> git.immae.eu Git - github/wallabag/wallabag.git/blob - index.php
Merge pull request #274 from NumEricR/select-theme
[github/wallabag/wallabag.git] / index.php
1 <?php
2 /**
3 * poche, a read it later open source system
4 *
5 * @category poche
6 * @author Nicolas LÅ“uillet <support@inthepoche.com>
7 * @copyright 2013
8 * @license http://www.wtfpl.net/ see COPYING file
9 */
10
11 define ('POCHE', '1.0.0');
12 require_once 'inc/poche/global.inc.php';
13
14 # Start Poche
15 $poche = new Poche();
16 $notInstalledMessage = $poche -> getNotInstalledMessage();
17
18 # Parse GET & REFERER vars
19 $referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
20 $view = Tools::checkVar('view', 'home');
21 $action = Tools::checkVar('action');
22 $id = Tools::checkVar('id');
23 $_SESSION['sort'] = Tools::checkVar('sort', 'id');
24 $url = new Url((isset ($_GET['url'])) ? $_GET['url'] : '');
25
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
39 echo '<h1>Errors</h1><ol>';
40 foreach ($notInstalledMessage as $message) {
41 echo '<li>' . $message . '</li>';
42 }
43 echo '</ol>';
44 die();
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
54 # poche actions
55 if (isset($_GET['login'])) {
56 # hello you
57 $poche->login($referer);
58 } elseif (isset($_GET['logout'])) {
59 # see you soon !
60 $poche->logout();
61 } elseif (isset($_GET['config'])) {
62 # Update password
63 $poche->updatePassword();
64 } elseif (isset($_GET['import'])) {
65 $import = $poche->import($_GET['from']);
66 } elseif (isset($_GET['export'])) {
67 $poche->export();
68 } elseif (isset($_GET['updatetheme'])) {
69 $poche->updateTheme();
70 } elseif (isset($_GET['updatelanguage'])) {
71 $poche->updateLanguage();
72 }
73
74 elseif (isset($_GET['plainurl']) && !empty($_GET['plainurl'])) {
75 $plain_url = new Url(base64_encode($_GET['plainurl']));
76 $poche->action('add', $plain_url);
77 }
78
79 if (Session::isLogged()) {
80 $poche->action($action, $url, $id);
81 $tpl_file = Tools::getTplFile($view);
82 $tpl_vars = array_merge($tpl_vars, $poche->displayView($view, $id));
83 } else {
84 $tpl_file = Tools::getTplFile('login');
85 }
86
87 # because messages can be added in $poche->action(), we have to add this entry now (we can add it before)
88 $messages = $poche->messages->display('all', FALSE);
89 $tpl_vars = array_merge($tpl_vars, array('messages' => $messages));
90
91 # display poche
92 echo $poche->tpl->render($tpl_file, $tpl_vars);