Dotclear

source: inc/admin/prepend.php @ 2721:58e31e9e3503

Revision 2721:58e31e9e3503, 10.5 KB checked in by Dsls, 11 years ago (diff)

fixed typo in adminurl handler for admin.comment

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

Sites map