diff options
Diffstat (limited to 'index.php')
-rwxr-xr-x | index.php | 137 |
1 files changed, 8 insertions, 129 deletions
@@ -5,139 +5,18 @@ | |||
5 | * @category wallabag | 5 | * @category wallabag |
6 | * @author Nicolas LÅ“uillet <nicolas@loeuillet.org> | 6 | * @author Nicolas LÅ“uillet <nicolas@loeuillet.org> |
7 | * @copyright 2013 | 7 | * @copyright 2013 |
8 | * @license http://www.wtfpl.net/ see COPYING file | 8 | * @license http://opensource.org/licenses/MIT see COPYING file |
9 | */ | 9 | */ |
10 | 10 | ||
11 | define ('POCHE', '1.7.2'); | 11 | define ('POCHE', '1.8.0'); |
12 | require 'check_essentials.php'; | ||
12 | require 'check_setup.php'; | 13 | require 'check_setup.php'; |
13 | require_once 'inc/poche/global.inc.php'; | 14 | require_once 'inc/poche/global.inc.php'; |
14 | 15 | ||
15 | # Set error reporting level | 16 | // Start session |
16 | if (defined('ERROR_REPORTING')) { | 17 | Session::$sessionName = 'wallabag'; |
17 | error_reporting(ERROR_REPORTING); | ||
18 | } | ||
19 | |||
20 | # Start session | ||
21 | Session::$sessionName = 'poche'; | ||
22 | Session::init(); | 18 | Session::init(); |
23 | 19 | ||
24 | # Start Poche | 20 | // Let's rock ! |
25 | $poche = new Poche(); | 21 | $wallabag = new Poche(); |
26 | $notInstalledMessage = $poche -> getNotInstalledMessage(); | 22 | $wallabag->run(); \ No newline at end of file |
27 | |||
28 | # Parse GET & REFERER vars | ||
29 | $referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER']; | ||
30 | $view = Tools::checkVar('view', 'home'); | ||
31 | $action = Tools::checkVar('action'); | ||
32 | $id = Tools::checkVar('id'); | ||
33 | $_SESSION['sort'] = Tools::checkVar('sort', 'id'); | ||
34 | $url = new Url((isset ($_GET['url'])) ? $_GET['url'] : ''); | ||
35 | |||
36 | # vars to _always_ send to templates | ||
37 | $tpl_vars = array( | ||
38 | 'referer' => $referer, | ||
39 | 'view' => $view, | ||
40 | 'poche_url' => Tools::getPocheUrl(), | ||
41 | 'title' => _('wallabag, a read it later open source system'), | ||
42 | 'token' => Session::getToken(), | ||
43 | 'theme' => $poche->getTheme() | ||
44 | ); | ||
45 | |||
46 | if (! empty($notInstalledMessage)) { | ||
47 | if (! Poche::$canRenderTemplates || ! Poche::$configFileAvailable) { | ||
48 | # We cannot use Twig to display the error message | ||
49 | echo '<h1>Errors</h1><ol>'; | ||
50 | foreach ($notInstalledMessage as $message) { | ||
51 | echo '<li>' . $message . '</li>'; | ||
52 | } | ||
53 | echo '</ol>'; | ||
54 | die(); | ||
55 | } else { | ||
56 | # Twig is installed, put the error message in the template | ||
57 | $tpl_file = Tools::getTplFile('error'); | ||
58 | $tpl_vars = array_merge($tpl_vars, array('msg' => $poche->getNotInstalledMessage())); | ||
59 | echo $poche->tpl->render($tpl_file, $tpl_vars); | ||
60 | exit; | ||
61 | } | ||
62 | } | ||
63 | |||
64 | # poche actions | ||
65 | if (isset($_GET['login'])) { | ||
66 | # hello to you | ||
67 | $poche->login($referer); | ||
68 | } elseif (isset($_GET['feed']) && isset($_GET['user_id'])) { | ||
69 | $tag_id = (isset($_GET['tag_id']) ? intval($_GET['tag_id']) : 0); | ||
70 | $poche->generateFeeds($_GET['token'], filter_var($_GET['user_id'],FILTER_SANITIZE_NUMBER_INT), $tag_id, $_GET['type']); | ||
71 | } | ||
72 | |||
73 | if (Session::isLogged()) { | ||
74 | |||
75 | if (isset($_GET['logout'])) { | ||
76 | # see you soon ! | ||
77 | $poche->logout(); | ||
78 | } elseif (isset($_GET['config'])) { | ||
79 | # Update password | ||
80 | $poche->updatePassword(); | ||
81 | } elseif (isset($_GET['newuser'])) { | ||
82 | $poche->createNewUser(); | ||
83 | } elseif (isset($_GET['deluser'])) { | ||
84 | $poche->deleteUser(); | ||
85 | } elseif (isset($_GET['epub'])) { | ||
86 | $poche->createEpub(); | ||
87 | } elseif (isset($_GET['import'])) { | ||
88 | $import = $poche->import(); | ||
89 | $tpl_vars = array_merge($tpl_vars, $import); | ||
90 | } elseif (isset($_GET['download'])) { | ||
91 | Tools::download_db(); | ||
92 | } elseif (isset($_GET['empty-cache'])) { | ||
93 | $poche->emptyCache(); | ||
94 | } elseif (isset($_GET['export'])) { | ||
95 | $poche->export(); | ||
96 | } elseif (isset($_GET['updatetheme'])) { | ||
97 | $poche->updateTheme(); | ||
98 | } elseif (isset($_GET['updatelanguage'])) { | ||
99 | $poche->updateLanguage(); | ||
100 | } elseif (isset($_GET['uploadfile'])) { | ||
101 | $poche->uploadFile(); | ||
102 | } elseif (isset($_GET['feed']) && isset($_GET['action']) && $_GET['action'] == 'generate') { | ||
103 | $poche->generateToken(); | ||
104 | } | ||
105 | elseif (isset($_GET['plainurl']) && !empty($_GET['plainurl'])) { | ||
106 | $plain_url = new Url(base64_encode($_GET['plainurl'])); | ||
107 | $poche->action('add', $plain_url); | ||
108 | } | ||
109 | |||
110 | $poche->action($action, $url, $id); | ||
111 | $tpl_file = Tools::getTplFile($view); | ||
112 | $tpl_vars = array_merge($tpl_vars, $poche->displayView($view, $id)); | ||
113 | |||
114 | } elseif(isset($_SERVER['PHP_AUTH_USER'])) { | ||
115 | if($poche->store->userExists($_SERVER['PHP_AUTH_USER'])) { | ||
116 | $poche->login($referer); | ||
117 | } else { | ||
118 | $poche->messages->add('e', _('login failed: user doesn\'t exist')); | ||
119 | Tools::logm('user doesn\'t exist'); | ||
120 | $tpl_file = Tools::getTplFile('login'); | ||
121 | $tpl_vars['http_auth'] = 1; | ||
122 | } | ||
123 | } elseif(isset($_SERVER['REMOTE_USER'])) { | ||
124 | if($poche->store->userExists($_SERVER['REMOTE_USER'])) { | ||
125 | $poche->login($referer); | ||
126 | } else { | ||
127 | $poche->messages->add('e', _('login failed: user doesn\'t exist')); | ||
128 | Tools::logm('user doesn\'t exist'); | ||
129 | $tpl_file = Tools::getTplFile('login'); | ||
130 | $tpl_vars['http_auth'] = 1; | ||
131 | } | ||
132 | } else { | ||
133 | $tpl_file = Tools::getTplFile('login'); | ||
134 | $tpl_vars['http_auth'] = 0; | ||
135 | Session::logout(); | ||
136 | } | ||
137 | |||
138 | # because messages can be added in $poche->action(), we have to add this entry now (we can add it before) | ||
139 | $messages = $poche->messages->display('all', FALSE); | ||
140 | $tpl_vars = array_merge($tpl_vars, array('messages' => $messages)); | ||
141 | |||
142 | # display poche | ||
143 | echo $poche->tpl->render($tpl_file, $tpl_vars); | ||