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