1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
3 | # |
---|
4 | # This file is part of Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear |
---|
7 | # Licensed under the GPL version 2.0 license. |
---|
8 | # See LICENSE file or |
---|
9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
10 | # |
---|
11 | # -- END LICENSE BLOCK ----------------------------------------- |
---|
12 | |
---|
13 | define('DC_CONTEXT_ADMIN', true); |
---|
14 | |
---|
15 | require_once dirname(__FILE__) . '/../prepend.php'; |
---|
16 | |
---|
17 | // HTTP/1.1 |
---|
18 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
---|
19 | header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0'); |
---|
20 | |
---|
21 | // HTTP/1.0 |
---|
22 | header("Pragma: no-cache"); |
---|
23 | |
---|
24 | function dc_load_locales() |
---|
25 | { |
---|
26 | global $_lang, $core; |
---|
27 | |
---|
28 | $_lang = $core->auth->getInfo('user_lang'); |
---|
29 | $_lang = preg_match('/^[a-z]{2}(-[a-z]{2})?$/', $_lang) ? $_lang : 'en'; |
---|
30 | |
---|
31 | l10n::lang($_lang); |
---|
32 | if (l10n::set(dirname(__FILE__) . '/../../locales/' . $_lang . '/date') === false && $_lang != 'en') { |
---|
33 | l10n::set(dirname(__FILE__) . '/../../locales/en/date'); |
---|
34 | } |
---|
35 | l10n::set(dirname(__FILE__) . '/../../locales/' . $_lang . '/main'); |
---|
36 | l10n::set(dirname(__FILE__) . '/../../locales/' . $_lang . '/public'); |
---|
37 | l10n::set(dirname(__FILE__) . '/../../locales/' . $_lang . '/plugins'); |
---|
38 | |
---|
39 | // Set lexical lang |
---|
40 | dcUtils::setlexicalLang('admin', $_lang); |
---|
41 | } |
---|
42 | |
---|
43 | function dc_admin_icon_url($img) |
---|
44 | { |
---|
45 | global $core; |
---|
46 | |
---|
47 | $core->auth->user_prefs->addWorkspace('interface'); |
---|
48 | $user_ui_iconset = @$core->auth->user_prefs->interface->iconset; |
---|
49 | if (($user_ui_iconset) && ($img)) { |
---|
50 | $icon = false; |
---|
51 | if ((preg_match('/^images\/menu\/(.+)$/', $img, $m)) || |
---|
52 | (preg_match('/^index\.php\?pf=(.+)$/', $img, $m))) { |
---|
53 | if ($m[1]) { |
---|
54 | $icon = path::real(dirname(__FILE__) . '/../../admin/images/iconset/' . $user_ui_iconset . '/' . $m[1], false); |
---|
55 | if ($icon !== false) { |
---|
56 | $allow_types = array('png', 'jpg', 'jpeg', 'gif'); |
---|
57 | if (is_file($icon) && is_readable($icon) && in_array(files::getExtension($icon), $allow_types)) { |
---|
58 | return DC_ADMIN_URL . 'images/iconset/' . $user_ui_iconset . '/' . $m[1]; |
---|
59 | } |
---|
60 | } |
---|
61 | } |
---|
62 | } |
---|
63 | } |
---|
64 | return $img; |
---|
65 | } |
---|
66 | |
---|
67 | function addMenuItem($section, $desc, $adminurl, $icon, $perm, $pinned = false) |
---|
68 | { |
---|
69 | global $core, $_menu; |
---|
70 | |
---|
71 | $url = $core->adminurl->get($adminurl); |
---|
72 | $_menu[$section]->prependItem($desc, $url, $icon, |
---|
73 | preg_match('/' . preg_quote($url) . '(\?.*)?$/', $_SERVER['REQUEST_URI']), $perm, null, null, $pinned); |
---|
74 | } |
---|
75 | |
---|
76 | if (defined('DC_AUTH_SESS_ID') && defined('DC_AUTH_SESS_UID')) { |
---|
77 | # We have session information in constants |
---|
78 | $_COOKIE[DC_SESSION_NAME] = DC_AUTH_SESS_ID; |
---|
79 | |
---|
80 | if (!$core->auth->checkSession(DC_AUTH_SESS_UID)) { |
---|
81 | throw new Exception('Invalid session data.'); |
---|
82 | } |
---|
83 | |
---|
84 | # Check nonce from POST requests |
---|
85 | if (!empty($_POST)) { |
---|
86 | if (empty($_POST['xd_check']) || !$core->checkNonce($_POST['xd_check'])) { |
---|
87 | throw new Exception('Precondition Failed.'); |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | if (empty($_SESSION['sess_blog_id'])) { |
---|
92 | throw new Exception('Permission denied.'); |
---|
93 | } |
---|
94 | |
---|
95 | # Loading locales |
---|
96 | dc_load_locales(); |
---|
97 | |
---|
98 | $core->setBlog($_SESSION['sess_blog_id']); |
---|
99 | if (!$core->blog->id) { |
---|
100 | throw new Exception('Permission denied.'); |
---|
101 | } |
---|
102 | } elseif ($core->auth->sessionExists()) { |
---|
103 | # If we have a session we launch it now |
---|
104 | try { |
---|
105 | if (!$core->auth->checkSession()) { |
---|
106 | # Avoid loop caused by old cookie |
---|
107 | $p = $core->session->getCookieParameters(false, -600); |
---|
108 | $p[3] = '/'; |
---|
109 | call_user_func_array('setcookie', $p); |
---|
110 | |
---|
111 | http::redirect('auth.php'); |
---|
112 | } |
---|
113 | } catch (Exception $e) { |
---|
114 | __error(__('Database error') |
---|
115 | , __('There seems to be no Session table in your database. Is Dotclear completly installed?') |
---|
116 | , 20); |
---|
117 | } |
---|
118 | |
---|
119 | # Check nonce from POST requests |
---|
120 | if (!empty($_POST)) { |
---|
121 | if (empty($_POST['xd_check']) || !$core->checkNonce($_POST['xd_check'])) { |
---|
122 | http::head(412); |
---|
123 | header('Content-Type: text/plain'); |
---|
124 | echo 'Precondition Failed'; |
---|
125 | exit; |
---|
126 | } |
---|
127 | } |
---|
128 | |
---|
129 | if (!empty($_REQUEST['switchblog']) |
---|
130 | && $core->auth->getPermissions($_REQUEST['switchblog']) !== false) { |
---|
131 | $_SESSION['sess_blog_id'] = $_REQUEST['switchblog']; |
---|
132 | if (isset($_SESSION['media_manager_dir'])) { |
---|
133 | unset($_SESSION['media_manager_dir']); |
---|
134 | } |
---|
135 | if (isset($_SESSION['media_manager_page'])) { |
---|
136 | unset($_SESSION['media_manager_page']); |
---|
137 | } |
---|
138 | |
---|
139 | # Removing switchblog from URL |
---|
140 | $redir = $_SERVER['REQUEST_URI']; |
---|
141 | $redir = preg_replace('/switchblog=(.*?)(&|$)/', '', $redir); |
---|
142 | $redir = preg_replace('/\?$/', '', $redir); |
---|
143 | http::redirect($redir); |
---|
144 | exit; |
---|
145 | } |
---|
146 | |
---|
147 | # Check blog to use and log out if no result |
---|
148 | if (isset($_SESSION['sess_blog_id'])) { |
---|
149 | if ($core->auth->getPermissions($_SESSION['sess_blog_id']) === false) { |
---|
150 | unset($_SESSION['sess_blog_id']); |
---|
151 | } |
---|
152 | } else { |
---|
153 | if (($b = $core->auth->findUserBlog($core->auth->getInfo('user_default_blog'))) !== false) { |
---|
154 | $_SESSION['sess_blog_id'] = $b; |
---|
155 | unset($b); |
---|
156 | } |
---|
157 | } |
---|
158 | |
---|
159 | # Loading locales |
---|
160 | dc_load_locales(); |
---|
161 | |
---|
162 | if (isset($_SESSION['sess_blog_id'])) { |
---|
163 | $core->setBlog($_SESSION['sess_blog_id']); |
---|
164 | } else { |
---|
165 | $core->session->destroy(); |
---|
166 | http::redirect('auth.php'); |
---|
167 | } |
---|
168 | } |
---|
169 | |
---|
170 | $core->adminurl = new dcAdminURL($core); |
---|
171 | |
---|
172 | $core->adminurl->register('admin.posts', 'posts.php'); |
---|
173 | $core->adminurl->register('admin.popup_posts', 'popup_posts.php'); |
---|
174 | $core->adminurl->register('admin.post', 'post.php'); |
---|
175 | $core->adminurl->register('admin.post.media', 'post_media.php'); |
---|
176 | $core->adminurl->register('admin.blog.theme', 'blog_theme.php'); |
---|
177 | $core->adminurl->register('admin.blog.pref', 'blog_pref.php'); |
---|
178 | $core->adminurl->register('admin.blog.del', 'blog_del.php'); |
---|
179 | $core->adminurl->register('admin.blog', 'blog.php'); |
---|
180 | $core->adminurl->register('admin.blogs', 'blogs.php'); |
---|
181 | $core->adminurl->register('admin.categories', 'categories.php'); |
---|
182 | $core->adminurl->register('admin.category', 'category.php'); |
---|
183 | $core->adminurl->register('admin.comments', 'comments.php'); |
---|
184 | $core->adminurl->register('admin.comment', 'comment.php'); |
---|
185 | $core->adminurl->register('admin.help', 'help.php'); |
---|
186 | $core->adminurl->register('admin.home', 'index.php'); |
---|
187 | $core->adminurl->register('admin.langs', 'langs.php'); |
---|
188 | $core->adminurl->register('admin.media', 'media.php'); |
---|
189 | $core->adminurl->register('admin.media.item', 'media_item.php'); |
---|
190 | $core->adminurl->register('admin.plugins', 'plugins.php'); |
---|
191 | $core->adminurl->register('admin.plugin', 'plugin.php'); |
---|
192 | $core->adminurl->register('admin.search', 'search.php'); |
---|
193 | $core->adminurl->register('admin.user.preferences', 'preferences.php'); |
---|
194 | $core->adminurl->register('admin.user', 'user.php'); |
---|
195 | $core->adminurl->register('admin.user.actions', 'users_actions.php'); |
---|
196 | $core->adminurl->register('admin.users', 'users.php'); |
---|
197 | $core->adminurl->register('admin.auth', 'auth.php'); |
---|
198 | $core->adminurl->register('admin.help', 'help.php'); |
---|
199 | $core->adminurl->register('admin.update', 'update.php'); |
---|
200 | |
---|
201 | $core->adminurl->registercopy('load.plugin.file', 'admin.home', array('pf' => 'dummy.css')); |
---|
202 | $core->adminurl->registercopy('load.var.file', 'admin.home', array('vf' => 'dummy.json')); |
---|
203 | |
---|
204 | if ($core->auth->userID() && $core->blog !== null) { |
---|
205 | # Loading resources and help files |
---|
206 | $locales_root = dirname(__FILE__) . '/../../locales/'; |
---|
207 | require $locales_root . '/en/resources.php'; |
---|
208 | if (($f = l10n::getFilePath($locales_root, 'resources.php', $_lang))) { |
---|
209 | require $f; |
---|
210 | } |
---|
211 | unset($f); |
---|
212 | |
---|
213 | if (($hfiles = @scandir($locales_root . $_lang . '/help')) !== false) { |
---|
214 | foreach ($hfiles as $hfile) { |
---|
215 | if (preg_match('/^(.*)\.html$/', $hfile, $m)) { |
---|
216 | $GLOBALS['__resources']['help'][$m[1]] = $locales_root . $_lang . '/help/' . $hfile; |
---|
217 | } |
---|
218 | } |
---|
219 | } |
---|
220 | unset($hfiles, $locales_root); |
---|
221 | // Contextual help flag |
---|
222 | $GLOBALS['__resources']['ctxhelp'] = false; |
---|
223 | |
---|
224 | $core->auth->user_prefs->addWorkspace('interface'); |
---|
225 | $user_ui_nofavmenu = $core->auth->user_prefs->interface->nofavmenu; |
---|
226 | |
---|
227 | $core->favs = new dcFavorites($core); |
---|
228 | |
---|
229 | # [] : Title, URL, small icon, large icon, permissions, id, class |
---|
230 | # NB : '*' in permissions means any, null means super admin only |
---|
231 | |
---|
232 | # Menus creation |
---|
233 | $_menu = new ArrayObject(); |
---|
234 | $_menu['Dashboard'] = new dcMenu('dashboard-menu', null); |
---|
235 | if (!$user_ui_nofavmenu) { |
---|
236 | $core->favs->appendMenuTitle($_menu); |
---|
237 | } |
---|
238 | $_menu['Blog'] = new dcMenu('blog-menu', 'Blog'); |
---|
239 | $_menu['System'] = new dcMenu('system-menu', 'System'); |
---|
240 | $_menu['Plugins'] = new dcMenu('plugins-menu', 'Plugins'); |
---|
241 | # Loading plugins |
---|
242 | $core->plugins->loadModules(DC_PLUGINS_ROOT, 'admin', $_lang); |
---|
243 | $core->favs->setup(); |
---|
244 | |
---|
245 | if (!$user_ui_nofavmenu) { |
---|
246 | $core->favs->appendMenu($_menu); |
---|
247 | } |
---|
248 | |
---|
249 | # Set menu titles |
---|
250 | |
---|
251 | $_menu['System']->title = __('System settings'); |
---|
252 | $_menu['Blog']->title = __('Blog'); |
---|
253 | $_menu['Plugins']->title = __('Plugins'); |
---|
254 | |
---|
255 | addMenuItem('Blog', __('Blog appearance'), 'admin.blog.theme', 'images/menu/themes.png', |
---|
256 | $core->auth->check('admin', $core->blog->id)); |
---|
257 | addMenuItem('Blog', __('Blog settings'), 'admin.blog.pref', 'images/menu/blog-pref.png', |
---|
258 | $core->auth->check('admin', $core->blog->id)); |
---|
259 | addMenuItem('Blog', __('Media manager'), 'admin.media', 'images/menu/media.png', |
---|
260 | $core->auth->check('media,media_admin', $core->blog->id)); |
---|
261 | addMenuItem('Blog', __('Categories'), 'admin.categories', 'images/menu/categories.png', |
---|
262 | $core->auth->check('categories', $core->blog->id)); |
---|
263 | addMenuItem('Blog', __('Search'), 'admin.search', 'images/menu/search.png', |
---|
264 | $core->auth->check('usage,contentadmin', $core->blog->id)); |
---|
265 | addMenuItem('Blog', __('Comments'), 'admin.comments', 'images/menu/comments.png', |
---|
266 | $core->auth->check('usage,contentadmin', $core->blog->id)); |
---|
267 | addMenuItem('Blog', __('Entries'), 'admin.posts', 'images/menu/entries.png', |
---|
268 | $core->auth->check('usage,contentadmin', $core->blog->id)); |
---|
269 | addMenuItem('Blog', __('New entry'), 'admin.post', 'images/menu/edit.png', |
---|
270 | $core->auth->check('usage,contentadmin', $core->blog->id), true); |
---|
271 | |
---|
272 | addMenuItem('System', __('Update'), 'admin.update', 'images/menu/update.png', |
---|
273 | $core->auth->isSuperAdmin() && is_readable(DC_DIGESTS)); |
---|
274 | addMenuItem('System', __('Languages'), 'admin.langs', 'images/menu/langs.png', |
---|
275 | $core->auth->isSuperAdmin()); |
---|
276 | addMenuItem('System', __('Plugins management'), 'admin.plugins', 'images/menu/plugins.png', |
---|
277 | $core->auth->isSuperAdmin()); |
---|
278 | addMenuItem('System', __('Users'), 'admin.users', 'images/menu/users.png', |
---|
279 | $core->auth->isSuperAdmin()); |
---|
280 | addMenuItem('System', __('Blogs'), 'admin.blogs', 'images/menu/blogs.png', |
---|
281 | $core->auth->isSuperAdmin() || |
---|
282 | $core->auth->check('usage,contentadmin', $core->blog->id) && $core->auth->getBlogCount() > 1); |
---|
283 | |
---|
284 | if (empty($core->blog->settings->system->jquery_migrate_mute)) { |
---|
285 | $core->blog->settings->system->put('jquery_migrate_mute', true, 'boolean', 'Mute warnings for jquery migrate plugin ?', false); |
---|
286 | } |
---|
287 | } |
---|