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