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