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