Dotclear

source: inc/admin/prepend.php @ 691:c146fe250860

Revision 691:c146fe250860, 12.5 KB checked in by Franck <carnet.franck.paul@…>, 14 years ago (diff)

Prise en charge d'iconsets d'admin (menus et favoris) alternatifs

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

Sites map