| 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.popup_posts','popup_posts.php'); |
|---|
| 183 | $core->adminurl->register('admin.post','post.php'); |
|---|
| 184 | $core->adminurl->register('admin.post.media','post_media.php'); |
|---|
| 185 | $core->adminurl->register('admin.blog.theme','blog_theme.php'); |
|---|
| 186 | $core->adminurl->register('admin.blog.pref','blog_pref.php'); |
|---|
| 187 | $core->adminurl->register('admin.blog.del','blog_del.php'); |
|---|
| 188 | $core->adminurl->register('admin.blog','blog.php'); |
|---|
| 189 | $core->adminurl->register('admin.blogs','blogs.php'); |
|---|
| 190 | $core->adminurl->register('admin.categories','categories.php'); |
|---|
| 191 | $core->adminurl->register('admin.category','category.php'); |
|---|
| 192 | $core->adminurl->register('admin.comments','comments.php'); |
|---|
| 193 | $core->adminurl->register('admin.comment','comment.php'); |
|---|
| 194 | $core->adminurl->register('admin.help','help.php'); |
|---|
| 195 | $core->adminurl->register('admin.home','index.php'); |
|---|
| 196 | $core->adminurl->register('admin.langs','langs.php'); |
|---|
| 197 | $core->adminurl->register('admin.media','media.php'); |
|---|
| 198 | $core->adminurl->register('admin.media.item','media_item.php'); |
|---|
| 199 | $core->adminurl->register('admin.plugins','plugins.php'); |
|---|
| 200 | $core->adminurl->register('admin.plugin','plugin.php'); |
|---|
| 201 | $core->adminurl->register('admin.search','search.php'); |
|---|
| 202 | $core->adminurl->register('admin.user.preferences','preferences.php'); |
|---|
| 203 | $core->adminurl->register('admin.user','user.php'); |
|---|
| 204 | $core->adminurl->register('admin.user.actions','users_actions.php'); |
|---|
| 205 | $core->adminurl->register('admin.users','users.php'); |
|---|
| 206 | $core->adminurl->register('admin.auth','auth.php'); |
|---|
| 207 | $core->adminurl->register('admin.help','help.php'); |
|---|
| 208 | $core->adminurl->register('admin.update','update.php'); |
|---|
| 209 | |
|---|
| 210 | $core->adminurl->registercopy('load.plugin.file','admin.home',array('pf' => 'dummy.css')); |
|---|
| 211 | $core->adminurl->registercopy('load.var.file','admin.home',array('vf' => 'dummy.json')); |
|---|
| 212 | |
|---|
| 213 | if ($core->auth->userID() && $core->blog !== null) |
|---|
| 214 | { |
|---|
| 215 | # Loading resources and help files |
|---|
| 216 | $locales_root = dirname(__FILE__).'/../../locales/'; |
|---|
| 217 | require $locales_root.'/en/resources.php'; |
|---|
| 218 | if (($f = l10n::getFilePath($locales_root,'resources.php',$_lang))) { |
|---|
| 219 | require $f; |
|---|
| 220 | } |
|---|
| 221 | unset($f); |
|---|
| 222 | |
|---|
| 223 | if (($hfiles = @scandir($locales_root.$_lang.'/help')) !== false) |
|---|
| 224 | { |
|---|
| 225 | foreach ($hfiles as $hfile) { |
|---|
| 226 | if (preg_match('/^(.*)\.html$/',$hfile,$m)) { |
|---|
| 227 | $GLOBALS['__resources']['help'][$m[1]] = $locales_root.$_lang.'/help/'.$hfile; |
|---|
| 228 | } |
|---|
| 229 | } |
|---|
| 230 | } |
|---|
| 231 | unset($hfiles,$locales_root); |
|---|
| 232 | // Contextual help flag |
|---|
| 233 | $GLOBALS['__resources']['ctxhelp'] = false; |
|---|
| 234 | |
|---|
| 235 | $core->auth->user_prefs->addWorkspace('interface'); |
|---|
| 236 | $user_ui_nofavmenu = $core->auth->user_prefs->interface->nofavmenu; |
|---|
| 237 | |
|---|
| 238 | $core->favs = new dcFavorites($core); |
|---|
| 239 | |
|---|
| 240 | # [] : Title, URL, small icon, large icon, permissions, id, class |
|---|
| 241 | # NB : '*' in permissions means any, null means super admin only |
|---|
| 242 | |
|---|
| 243 | # Menus creation |
|---|
| 244 | $_menu = new ArrayObject(); |
|---|
| 245 | $_menu['Dashboard'] = new dcMenu('dashboard-menu',null); |
|---|
| 246 | if (!$user_ui_nofavmenu) { |
|---|
| 247 | $core->favs->appendMenuTitle($_menu); |
|---|
| 248 | } |
|---|
| 249 | $_menu['Blog'] = new dcMenu('blog-menu','Blog'); |
|---|
| 250 | $_menu['System'] = new dcMenu('system-menu','System'); |
|---|
| 251 | $_menu['Plugins'] = new dcMenu('plugins-menu','Plugins'); |
|---|
| 252 | # Loading plugins |
|---|
| 253 | $core->plugins->loadModules(DC_PLUGINS_ROOT,'admin',$_lang); |
|---|
| 254 | $core->favs->setup(); |
|---|
| 255 | |
|---|
| 256 | if (!$user_ui_nofavmenu) { |
|---|
| 257 | $core->favs->appendMenu($_menu); |
|---|
| 258 | } |
|---|
| 259 | |
|---|
| 260 | # Set menu titles |
|---|
| 261 | |
|---|
| 262 | $_menu['System']->title = __('System settings'); |
|---|
| 263 | $_menu['Blog']->title = __('Blog'); |
|---|
| 264 | $_menu['Plugins']->title = __('Plugins'); |
|---|
| 265 | |
|---|
| 266 | addMenuItem('Blog',__('Blog appearance'),'admin.blog.theme','images/menu/themes.png', |
|---|
| 267 | $core->auth->check('admin',$core->blog->id)); |
|---|
| 268 | addMenuItem('Blog',__('Blog settings'),'admin.blog.pref','images/menu/blog-pref.png', |
|---|
| 269 | $core->auth->check('admin',$core->blog->id)); |
|---|
| 270 | addMenuItem('Blog',__('Media manager'),'admin.media','images/menu/media.png', |
|---|
| 271 | $core->auth->check('media,media_admin',$core->blog->id)); |
|---|
| 272 | addMenuItem('Blog',__('Categories'),'admin.categories','images/menu/categories.png', |
|---|
| 273 | $core->auth->check('categories',$core->blog->id)); |
|---|
| 274 | addMenuItem('Blog',__('Search'),'admin.search','images/menu/search.png', |
|---|
| 275 | $core->auth->check('usage,contentadmin',$core->blog->id)); |
|---|
| 276 | addMenuItem('Blog',__('Comments'),'admin.comments','images/menu/comments.png', |
|---|
| 277 | $core->auth->check('usage,contentadmin',$core->blog->id)); |
|---|
| 278 | addMenuItem('Blog',__('Entries'),'admin.posts','images/menu/entries.png', |
|---|
| 279 | $core->auth->check('usage,contentadmin',$core->blog->id)); |
|---|
| 280 | addMenuItem('Blog',__('New entry'),'admin.post','images/menu/edit.png', |
|---|
| 281 | $core->auth->check('usage,contentadmin',$core->blog->id),true); |
|---|
| 282 | |
|---|
| 283 | addMenuItem('System',__('Update'),'admin.update','images/menu/update.png', |
|---|
| 284 | $core->auth->isSuperAdmin() && is_readable(DC_DIGESTS)); |
|---|
| 285 | addMenuItem('System',__('Languages'),'admin.langs','images/menu/langs.png', |
|---|
| 286 | $core->auth->isSuperAdmin()); |
|---|
| 287 | addMenuItem('System',__('Plugins management'),'admin.plugins','images/menu/plugins.png', |
|---|
| 288 | $core->auth->isSuperAdmin()); |
|---|
| 289 | addMenuItem('System',__('Users'),'admin.users','images/menu/users.png', |
|---|
| 290 | $core->auth->isSuperAdmin()); |
|---|
| 291 | addMenuItem('System',__('Blogs'),'admin.blogs','images/menu/blogs.png', |
|---|
| 292 | $core->auth->isSuperAdmin() || |
|---|
| 293 | $core->auth->check('usage,contentadmin',$core->blog->id) && $core->auth->getBlogCount() > 1); |
|---|
| 294 | |
|---|
| 295 | if (empty($core->blog->settings->system->jquery_migrate_mute)) { |
|---|
| 296 | $core->blog->settings->system->put('jquery_migrate_mute', true, 'boolean', 'Mute warnings for jquery migrate plugin ?', false); |
|---|
| 297 | } |
|---|
| 298 | } |
|---|
| 299 | |
|---|