1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
3 | # |
---|
4 | # This file is part of Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2003-2011 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 | require_once dirname(__FILE__).'/../prepend.php'; |
---|
14 | |
---|
15 | // HTTP/1.1 |
---|
16 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
---|
17 | header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0'); |
---|
18 | |
---|
19 | // HTTP/1.0 |
---|
20 | header("Pragma: no-cache"); |
---|
21 | |
---|
22 | define('DC_CONTEXT_ADMIN',true); |
---|
23 | |
---|
24 | function dc_valid_fav($url) { |
---|
25 | global $core; |
---|
26 | |
---|
27 | if (preg_match('#plugin\.php\?p=([^&]+)#',$url,$matches)) { |
---|
28 | if (isset($matches[1])) { |
---|
29 | if (!$core->plugins->moduleExists($matches[1])) { |
---|
30 | return false; |
---|
31 | } |
---|
32 | } |
---|
33 | } |
---|
34 | return true; |
---|
35 | } |
---|
36 | |
---|
37 | function dc_prepare_url($url) { |
---|
38 | |
---|
39 | $u = str_replace(array('?','&','/'),array('\?','&','\\/'),$url); |
---|
40 | return (!strpos($u,'\?') ? |
---|
41 | '/'.$u.'$/' : |
---|
42 | (!strpos($u,'&') ? |
---|
43 | '/'.$u.'(\?.*)?$/' : |
---|
44 | '/'.$u.'(&.*)?$/')); |
---|
45 | } |
---|
46 | |
---|
47 | function dc_load_locales() { |
---|
48 | global $_lang, $core; |
---|
49 | |
---|
50 | $_lang = $core->auth->getInfo('user_lang'); |
---|
51 | $_lang = preg_match('/^[a-z]{2}(-[a-z]{2})?$/',$_lang) ? $_lang : 'en'; |
---|
52 | |
---|
53 | if (l10n::set(dirname(__FILE__).'/../../locales/'.$_lang.'/date') === false && $_lang != 'en') { |
---|
54 | l10n::set(dirname(__FILE__).'/../../locales/en/date'); |
---|
55 | } |
---|
56 | l10n::set(dirname(__FILE__).'/../../locales/'.$_lang.'/main'); |
---|
57 | l10n::set(dirname(__FILE__).'/../../locales/'.$_lang.'/plugins'); |
---|
58 | } |
---|
59 | |
---|
60 | function dc_admin_icon_url($img) |
---|
61 | { |
---|
62 | global $core; |
---|
63 | |
---|
64 | $core->auth->user_prefs->addWorkspace('interface'); |
---|
65 | $user_ui_iconset = @$core->auth->user_prefs->interface->iconset; |
---|
66 | if (($user_ui_iconset) && ($img)) { |
---|
67 | $icon = false; |
---|
68 | if ((preg_match('/^images\/menu\/(.+)$/',$img,$m)) || |
---|
69 | (preg_match('/^index\.php\?pf=(.+)$/',$img,$m))) { |
---|
70 | if ($m[1]) { |
---|
71 | $icon = path::real(dirname(__FILE__).'/../../admin/images/iconset/'.$user_ui_iconset.'/'.$m[1],false); |
---|
72 | if ($icon !== false) { |
---|
73 | $allow_types = array('png','jpg','jpeg','gif'); |
---|
74 | if (is_file($icon) && is_readable($icon) && in_array(files::getExtension($icon),$allow_types)) { |
---|
75 | return DC_ADMIN_URL.'images/iconset/'.$user_ui_iconset.'/'.$m[1]; |
---|
76 | } |
---|
77 | } |
---|
78 | } |
---|
79 | } |
---|
80 | } |
---|
81 | return $img; |
---|
82 | } |
---|
83 | |
---|
84 | if (defined('DC_AUTH_SESS_ID') && defined('DC_AUTH_SESS_UID')) |
---|
85 | { |
---|
86 | # We have session information in constants |
---|
87 | $_COOKIE[DC_SESSION_NAME] = DC_AUTH_SESS_ID; |
---|
88 | |
---|
89 | if (!$core->auth->checkSession(DC_AUTH_SESS_UID)) { |
---|
90 | throw new Exception('Invalid session data.'); |
---|
91 | } |
---|
92 | |
---|
93 | # Check nonce from POST requests |
---|
94 | if (!empty($_POST)) |
---|
95 | { |
---|
96 | if (empty($_POST['xd_check']) || !$core->checkNonce($_POST['xd_check'])) { |
---|
97 | throw new Exception('Precondition Failed.'); |
---|
98 | } |
---|
99 | } |
---|
100 | |
---|
101 | if (empty($_SESSION['sess_blog_id'])) { |
---|
102 | throw new Exception('Permission denied.'); |
---|
103 | } |
---|
104 | |
---|
105 | # Loading locales |
---|
106 | dc_load_locales(); |
---|
107 | |
---|
108 | $core->setBlog($_SESSION['sess_blog_id']); |
---|
109 | if (!$core->blog->id) { |
---|
110 | throw new Exception('Permission denied.'); |
---|
111 | } |
---|
112 | } |
---|
113 | elseif ($core->auth->sessionExists()) |
---|
114 | { |
---|
115 | # If we have a session we launch it now |
---|
116 | try { |
---|
117 | if (!$core->auth->checkSession()) |
---|
118 | { |
---|
119 | # Avoid loop caused by old cookie |
---|
120 | $p = $core->session->getCookieParameters(false,-600); |
---|
121 | $p[3] = '/'; |
---|
122 | call_user_func_array('setcookie',$p); |
---|
123 | |
---|
124 | http::redirect('auth.php'); |
---|
125 | } |
---|
126 | } catch (Exception $e) { |
---|
127 | __error(__('Database error') |
---|
128 | ,__('There seems to be no Session table in your database. Is Dotclear completly installed?') |
---|
129 | ,20); |
---|
130 | } |
---|
131 | |
---|
132 | # Check nonce from POST requests |
---|
133 | if (!empty($_POST)) |
---|
134 | { |
---|
135 | if (empty($_POST['xd_check']) || !$core->checkNonce($_POST['xd_check'])) { |
---|
136 | http::head(412); |
---|
137 | header('Content-Type: text/plain'); |
---|
138 | echo 'Precondition Failed'; |
---|
139 | exit; |
---|
140 | } |
---|
141 | } |
---|
142 | |
---|
143 | |
---|
144 | if (!empty($_REQUEST['switchblog']) |
---|
145 | && $core->auth->getPermissions($_REQUEST['switchblog']) !== false) |
---|
146 | { |
---|
147 | $_SESSION['sess_blog_id'] = $_REQUEST['switchblog']; |
---|
148 | if (isset($_SESSION['media_manager_dir'])) { |
---|
149 | unset($_SESSION['media_manager_dir']); |
---|
150 | } |
---|
151 | if (isset($_SESSION['media_manager_page'])) { |
---|
152 | unset($_SESSION['media_manager_page']); |
---|
153 | } |
---|
154 | |
---|
155 | # Removing switchblog from URL |
---|
156 | $redir = $_SERVER['REQUEST_URI']; |
---|
157 | $redir = preg_replace('/switchblog=(.*?)(&|$)/','',$redir); |
---|
158 | $redir = preg_replace('/\?$/','',$redir); |
---|
159 | http::redirect($redir); |
---|
160 | exit; |
---|
161 | } |
---|
162 | |
---|
163 | # Check blog to use and log out if no result |
---|
164 | if (isset($_SESSION['sess_blog_id'])) |
---|
165 | { |
---|
166 | if ($core->auth->getPermissions($_SESSION['sess_blog_id']) === false) { |
---|
167 | unset($_SESSION['sess_blog_id']); |
---|
168 | } |
---|
169 | } |
---|
170 | else |
---|
171 | { |
---|
172 | if (($b = $core->auth->findUserBlog($core->auth->getInfo('user_default_blog'))) !== false) { |
---|
173 | $_SESSION['sess_blog_id'] = $b; |
---|
174 | unset($b); |
---|
175 | } |
---|
176 | } |
---|
177 | |
---|
178 | # Loading locales |
---|
179 | dc_load_locales(); |
---|
180 | |
---|
181 | if (isset($_SESSION['sess_blog_id'])) { |
---|
182 | $core->setBlog($_SESSION['sess_blog_id']); |
---|
183 | } else { |
---|
184 | $core->session->destroy(); |
---|
185 | http::redirect('auth.php'); |
---|
186 | } |
---|
187 | |
---|
188 | /* |
---|
189 | # Check add to my fav fired |
---|
190 | if (!empty($_REQUEST['add-favorite'])) { |
---|
191 | $redir = $_SERVER['REQUEST_URI']; |
---|
192 | # Extract admin page from URI |
---|
193 | # TO BE COMPLETED |
---|
194 | } |
---|
195 | */ |
---|
196 | } |
---|
197 | |
---|
198 | if ($core->auth->userID() && $core->blog !== null) |
---|
199 | { |
---|
200 | # Loading resources and help files |
---|
201 | $locales_root = dirname(__FILE__).'/../../locales/'; |
---|
202 | require $locales_root.'/en/resources.php'; |
---|
203 | if (($f = l10n::getFilePath($locales_root,'resources.php',$_lang))) { |
---|
204 | require $f; |
---|
205 | } |
---|
206 | unset($f); |
---|
207 | |
---|
208 | if (($hfiles = @scandir($locales_root.$_lang.'/help')) !== false) |
---|
209 | { |
---|
210 | foreach ($hfiles as $hfile) { |
---|
211 | if (preg_match('/^(.*)\.html$/',$hfile,$m)) { |
---|
212 | $GLOBALS['__resources']['help'][$m[1]] = $locales_root.$_lang.'/help/'.$hfile; |
---|
213 | } |
---|
214 | } |
---|
215 | } |
---|
216 | unset($hfiles,$locales_root); |
---|
217 | |
---|
218 | $core->auth->user_prefs->addWorkspace('interface'); |
---|
219 | $user_ui_nofavmenu = $core->auth->user_prefs->interface->nofavmenu; |
---|
220 | |
---|
221 | # Standard favorites |
---|
222 | $_fav = new ArrayObject(); |
---|
223 | |
---|
224 | # [] : Title, URL, small icon, large icon, permissions, id, class |
---|
225 | # NB : '*' in permissions means any, null means super admin only |
---|
226 | |
---|
227 | $_fav['prefs'] = new ArrayObject(array('prefs','My preferences','preferences.php', |
---|
228 | 'images/menu/user-pref.png','images/menu/user-pref-b.png', |
---|
229 | '*',null,null)); |
---|
230 | |
---|
231 | $_fav['new_post'] = new ArrayObject(array('new_post','New entry','post.php', |
---|
232 | 'images/menu/edit.png','images/menu/edit-b.png', |
---|
233 | 'usage,contentadmin',null,'menu-new-post')); |
---|
234 | $_fav['posts'] = new ArrayObject(array('posts','Entries','posts.php', |
---|
235 | 'images/menu/entries.png','images/menu/entries-b.png', |
---|
236 | 'usage,contentadmin',null,null)); |
---|
237 | $_fav['comments'] = new ArrayObject(array('comments','Comments','comments.php', |
---|
238 | 'images/menu/comments.png','images/menu/comments-b.png', |
---|
239 | 'usage,contentadmin',null,null)); |
---|
240 | $_fav['search'] = new ArrayObject(array('search','Search','search.php', |
---|
241 | 'images/menu/search.png','images/menu/search-b.png', |
---|
242 | 'usage,contentadmin',null,null)); |
---|
243 | $_fav['categories'] = new ArrayObject(array('categories','Categories','categories.php', |
---|
244 | 'images/menu/categories.png','images/menu/categories-b.png', |
---|
245 | 'categories',null,null)); |
---|
246 | $_fav['media'] = new ArrayObject(array('media','Media manager','media.php', |
---|
247 | 'images/menu/media.png','images/menu/media-b.png', |
---|
248 | 'media,media_admin',null,null)); |
---|
249 | $_fav['blog_pref'] = new ArrayObject(array('blog_pref','Blog settings','blog_pref.php', |
---|
250 | 'images/menu/blog-pref.png','images/menu/blog-pref-b.png', |
---|
251 | 'admin',null,null)); |
---|
252 | $_fav['blog_theme'] = new ArrayObject(array('blog_theme','Blog appearance','blog_theme.php', |
---|
253 | 'images/menu/themes.png','images/menu/blog-theme-b.png', |
---|
254 | 'admin',null,null)); |
---|
255 | |
---|
256 | $_fav['blogs'] = new ArrayObject(array('blogs','Blogs','blogs.php', |
---|
257 | 'images/menu/blogs.png','images/menu/blogs-b.png', |
---|
258 | 'usage,contentadmin',null,null)); |
---|
259 | $_fav['users'] = new ArrayObject(array('users','Users','users.php', |
---|
260 | 'images/menu/users.png','images/menu/users-b.png', |
---|
261 | null,null,null)); |
---|
262 | $_fav['plugins'] = new ArrayObject(array('plugins','Plugins','plugins.php', |
---|
263 | 'images/menu/plugins.png','images/menu/plugins-b.png', |
---|
264 | null,null,null)); |
---|
265 | $_fav['langs'] = new ArrayObject(array('langs','Languages','langs.php', |
---|
266 | 'images/menu/langs.png','images/menu/langs-b.png', |
---|
267 | null,null,null)); |
---|
268 | |
---|
269 | # Menus creation |
---|
270 | $_menu['Dashboard'] = new dcMenu('dashboard-menu',null); |
---|
271 | if (!$user_ui_nofavmenu) |
---|
272 | $_menu['Favorites'] = new dcMenu('favorites-menu','My favorites'); |
---|
273 | $_menu['Blog'] = new dcMenu('blog-menu','Blog'); |
---|
274 | $_menu['System'] = new dcMenu('system-menu','System'); |
---|
275 | $_menu['Plugins'] = new dcMenu('plugins-menu','Plugins'); |
---|
276 | |
---|
277 | # Loading plugins |
---|
278 | $core->plugins->loadModules(DC_PLUGINS_ROOT,'admin',$_lang); |
---|
279 | |
---|
280 | # Loading favorites info from plugins |
---|
281 | $core->callBehavior('adminDashboardFavs', $core, $_fav); |
---|
282 | |
---|
283 | # Set menu titles |
---|
284 | |
---|
285 | $_menu['System']->title = __('System'); |
---|
286 | $_menu['Blog']->title = __('Blog'); |
---|
287 | $_menu['Plugins']->title = __('Plugins'); |
---|
288 | if (!$user_ui_nofavmenu) |
---|
289 | $_menu['Favorites']->title = __('My favorites'); |
---|
290 | |
---|
291 | /* |
---|
292 | if (!preg_match('/index.php$/',$_SERVER['REQUEST_URI'])) { |
---|
293 | # Admin index can't be add in fav's |
---|
294 | $_menu['Dashboard']->prependItem(__('Add this page to my favorites'),'#','images/menu/add_to_favorites.png', |
---|
295 | false,$core->auth->check('usage,contentadmin',$core->blog->id),'fav-add'); |
---|
296 | } |
---|
297 | */ |
---|
298 | $_menu['Blog']->prependItem(__('Blog appearance'),'blog_theme.php','images/menu/themes.png', |
---|
299 | preg_match('/blog_theme.php(\?.*)?$/',$_SERVER['REQUEST_URI']), |
---|
300 | $core->auth->check('admin',$core->blog->id)); |
---|
301 | $_menu['Blog']->prependItem(__('Blog settings'),'blog_pref.php','images/menu/blog-pref.png', |
---|
302 | preg_match('/blog_pref.php(\?.*)?$/',$_SERVER['REQUEST_URI']), |
---|
303 | $core->auth->check('admin',$core->blog->id)); |
---|
304 | $_menu['Blog']->prependItem(__('Media manager'),'media.php','images/menu/media.png', |
---|
305 | preg_match('/media(_item)?.php(\?.*)?$/',$_SERVER['REQUEST_URI']), |
---|
306 | $core->auth->check('media,media_admin',$core->blog->id)); |
---|
307 | $_menu['Blog']->prependItem(__('Categories'),'categories.php','images/menu/categories.png', |
---|
308 | preg_match('/categories.php(\?.*)?$/',$_SERVER['REQUEST_URI']), |
---|
309 | $core->auth->check('categories',$core->blog->id)); |
---|
310 | $_menu['Blog']->prependItem(__('Search'),'search.php','images/menu/search.png', |
---|
311 | preg_match('/search.php(\?.*)?$/',$_SERVER['REQUEST_URI']), |
---|
312 | $core->auth->check('usage,contentadmin',$core->blog->id)); |
---|
313 | $_menu['Blog']->prependItem(__('Comments'),'comments.php','images/menu/comments.png', |
---|
314 | preg_match('/comments.php(\?.*)?$/',$_SERVER['REQUEST_URI']), |
---|
315 | $core->auth->check('usage,contentadmin',$core->blog->id)); |
---|
316 | $_menu['Blog']->prependItem(__('Entries'),'posts.php','images/menu/entries.png', |
---|
317 | preg_match('/posts.php(\?.*)?$/',$_SERVER['REQUEST_URI']), |
---|
318 | $core->auth->check('usage,contentadmin',$core->blog->id)); |
---|
319 | $_menu['Blog']->prependItem(__('New entry'),'post.php','images/menu/edit.png', |
---|
320 | preg_match('/post.php$/',$_SERVER['REQUEST_URI']), |
---|
321 | $core->auth->check('usage,contentadmin',$core->blog->id),'menu-new-post'); |
---|
322 | |
---|
323 | $_menu['System']->prependItem(__('Updates'),'update.php','images/menu/update.png', |
---|
324 | preg_match('/update.php(\?.*)?$/',$_SERVER['REQUEST_URI']), |
---|
325 | $core->auth->isSuperAdmin() && is_readable(DC_DIGESTS)); |
---|
326 | $_menu['System']->prependItem(__('Languages'),'langs.php','images/menu/langs.png', |
---|
327 | preg_match('/langs.php(\?.*)?$/',$_SERVER['REQUEST_URI']), |
---|
328 | $core->auth->isSuperAdmin()); |
---|
329 | $_menu['System']->prependItem(__('Plugins'),'plugins.php','images/menu/plugins.png', |
---|
330 | preg_match('/plugins.php(\?.*)?$/',$_SERVER['REQUEST_URI']), |
---|
331 | $core->auth->isSuperAdmin()); |
---|
332 | $_menu['System']->prependItem(__('Users'),'users.php','images/menu/users.png', |
---|
333 | preg_match('/users.php$/',$_SERVER['REQUEST_URI']), |
---|
334 | $core->auth->isSuperAdmin()); |
---|
335 | $_menu['System']->prependItem(__('Blogs'),'blogs.php','images/menu/blogs.png', |
---|
336 | preg_match('/blogs.php$/',$_SERVER['REQUEST_URI']), |
---|
337 | $core->auth->isSuperAdmin() || |
---|
338 | $core->auth->check('usage,contentadmin',$core->blog->id) && $core->auth->blog_count > 1); |
---|
339 | |
---|
340 | if (!$user_ui_nofavmenu) { |
---|
341 | // Set favorites menu |
---|
342 | $ws = $core->auth->user_prefs->addWorkspace('favorites'); |
---|
343 | $count = 0; |
---|
344 | foreach ($ws->dumpPrefs() as $k => $v) { |
---|
345 | // User favorites only |
---|
346 | if (!$v['global']) { |
---|
347 | $fav = unserialize($v['value']); |
---|
348 | if (dc_valid_fav($fav['url'])) { |
---|
349 | $count++; |
---|
350 | $_menu['Favorites']->addItem(__($fav['title']),$fav['url'],$fav['small-icon'], |
---|
351 | preg_match(dc_prepare_url($fav['url']),$_SERVER['REQUEST_URI']), |
---|
352 | (($fav['permissions'] == '*') || $core->auth->check($fav['permissions'],$core->blog->id)),$fav['id'],$fav['class']); |
---|
353 | } |
---|
354 | } |
---|
355 | } |
---|
356 | if (!$count) { |
---|
357 | // Global favorites if any |
---|
358 | foreach ($ws->dumpPrefs() as $k => $v) { |
---|
359 | $fav = unserialize($v['value']); |
---|
360 | if (dc_valid_fav($fav['url'])) { |
---|
361 | $count++; |
---|
362 | $_menu['Favorites']->addItem(__($fav['title']),$fav['url'],$fav['small-icon'], |
---|
363 | preg_match(dc_prepare_url($fav['url']),$_SERVER['REQUEST_URI']), |
---|
364 | (($fav['permissions'] == '*') || $core->auth->check($fav['permissions'],$core->blog->id)),$fav['id'],$fav['class']); |
---|
365 | } |
---|
366 | } |
---|
367 | } |
---|
368 | if (!$count) { |
---|
369 | // No user or global favorites, add "new entry" fav |
---|
370 | $_menu['Favorites']->addItem(__('New entry'),'post.php','images/menu/edit.png', |
---|
371 | preg_match('/post.php$/',$_SERVER['REQUEST_URI']), |
---|
372 | $core->auth->check('usage,contentadmin',$core->blog->id),'menu-new-post',null); |
---|
373 | } |
---|
374 | } |
---|
375 | } |
---|
376 | ?> |
---|