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