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