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