Dotclear

source: inc/admin/prepend.php @ 80:095353a21556

Revision 80:095353a21556, 11.9 KB checked in by Franck <carnet.franck.paul@…>, 15 years ago (diff)

Finally avoid to do some unecessary things before logout

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

Sites map