| 1 | <?php |
|---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
|---|
| 3 | # |
|---|
| 4 | # This file is part of Dotclear 2. |
|---|
| 5 | # |
|---|
| 6 | # Copyright (c) 2003-2011 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 | if (!empty($_GET['pf'])) { |
|---|
| 14 | require dirname(__FILE__).'/../inc/load_plugin_file.php'; |
|---|
| 15 | exit; |
|---|
| 16 | } |
|---|
| 17 | |
|---|
| 18 | require dirname(__FILE__).'/../inc/admin/prepend.php'; |
|---|
| 19 | |
|---|
| 20 | if (!empty($_GET['default_blog'])) { |
|---|
| 21 | try { |
|---|
| 22 | $core->setUserDefaultBlog($core->auth->userID(),$core->blog->id); |
|---|
| 23 | http::redirect('index.php'); |
|---|
| 24 | } catch (Exception $e) { |
|---|
| 25 | $core->error->add($e->getMessage()); |
|---|
| 26 | } |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | dcPage::check('usage,contentadmin'); |
|---|
| 30 | |
|---|
| 31 | # Logout |
|---|
| 32 | if (!empty($_GET['logout'])) { |
|---|
| 33 | $core->session->destroy(); |
|---|
| 34 | if (isset($_COOKIE['dc_admin'])) { |
|---|
| 35 | unset($_COOKIE['dc_admin']); |
|---|
| 36 | setcookie('dc_admin',false,-600,'','',DC_ADMIN_SSL); |
|---|
| 37 | } |
|---|
| 38 | http::redirect('auth.php'); |
|---|
| 39 | exit; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | # Plugin install |
|---|
| 43 | $plugins_install = $core->plugins->installModules(); |
|---|
| 44 | |
|---|
| 45 | # Check dashboard module prefs |
|---|
| 46 | $ws = $core->auth->user_prefs->addWorkspace('dashboard'); |
|---|
| 47 | if (!$core->auth->user_prefs->dashboard->prefExists('doclinks')) { |
|---|
| 48 | if (!$core->auth->user_prefs->dashboard->prefExists('doclinks',true)) { |
|---|
| 49 | $core->auth->user_prefs->dashboard->put('doclinks',true,'boolean','',null,true); |
|---|
| 50 | } |
|---|
| 51 | $core->auth->user_prefs->dashboard->put('doclinks',true,'boolean'); |
|---|
| 52 | } |
|---|
| 53 | if (!$core->auth->user_prefs->dashboard->prefExists('dcnews')) { |
|---|
| 54 | if (!$core->auth->user_prefs->dashboard->prefExists('dcnews',true)) { |
|---|
| 55 | $core->auth->user_prefs->dashboard->put('dcnews',true,'boolean','',null,true); |
|---|
| 56 | } |
|---|
| 57 | $core->auth->user_prefs->dashboard->put('dcnews',true,'boolean'); |
|---|
| 58 | } |
|---|
| 59 | if (!$core->auth->user_prefs->dashboard->prefExists('quickentry')) { |
|---|
| 60 | if (!$core->auth->user_prefs->dashboard->prefExists('quickentry',true)) { |
|---|
| 61 | $core->auth->user_prefs->dashboard->put('quickentry',true,'boolean','',null,true); |
|---|
| 62 | } |
|---|
| 63 | $core->auth->user_prefs->dashboard->put('quickentry',true,'boolean'); |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | # Dashboard icons |
|---|
| 67 | $__dashboard_icons = new ArrayObject(); |
|---|
| 68 | |
|---|
| 69 | # Dashboard favorites |
|---|
| 70 | $post_count = $core->blog->getPosts(array(),true)->f(0); |
|---|
| 71 | $str_entries = ($post_count > 1) ? __('%d entries') : __('%d entry'); |
|---|
| 72 | |
|---|
| 73 | $comment_count = $core->blog->getComments(array(),true)->f(0); |
|---|
| 74 | $str_comments = ($comment_count > 1) ? __('%d comments') : __('%d comment'); |
|---|
| 75 | |
|---|
| 76 | $ws = $core->auth->user_prefs->addWorkspace('favorites'); |
|---|
| 77 | $count = 0; |
|---|
| 78 | foreach ($ws->dumpPrefs() as $k => $v) { |
|---|
| 79 | // User favorites only |
|---|
| 80 | if (!$v['global']) { |
|---|
| 81 | $fav = unserialize($v['value']); |
|---|
| 82 | if (($fav['permissions'] == '*') || $core->auth->check($fav['permissions'],$core->blog->id)) { |
|---|
| 83 | $count++; |
|---|
| 84 | $title = ($fav['name'] == 'posts' ? sprintf($str_entries,$post_count) : |
|---|
| 85 | ($fav['name'] == 'comments' ? sprintf($str_comments,$comment_count) : $fav['title'])); |
|---|
| 86 | $__dashboard_icons[$fav['name']] = new ArrayObject(array(__($title),$fav['url'],$fav['large-icon'])); |
|---|
| 87 | |
|---|
| 88 | # Let plugins set their own title for favorite on dashboard |
|---|
| 89 | $core->callBehavior('adminDashboardFavsIcon',$core,$fav['name'],$__dashboard_icons[$fav['name']]); |
|---|
| 90 | } |
|---|
| 91 | } |
|---|
| 92 | } |
|---|
| 93 | if (!$count) { |
|---|
| 94 | // Global favorites if any |
|---|
| 95 | foreach ($ws->dumpPrefs() as $k => $v) { |
|---|
| 96 | $fav = unserialize($v['value']); |
|---|
| 97 | if (($fav['permissions'] == '*') || $core->auth->check($fav['permissions'],$core->blog->id)) { |
|---|
| 98 | $count++; |
|---|
| 99 | $title = ($fav['name'] == 'posts' ? sprintf($str_entries,$post_count) : |
|---|
| 100 | ($fav['name'] == 'comments' ? sprintf($str_comments,$comment_count) : $fav['title'])); |
|---|
| 101 | $__dashboard_icons[$fav['name']] = new ArrayObject(array(__($title),$fav['url'],$fav['large-icon'])); |
|---|
| 102 | |
|---|
| 103 | # Let plugins set their own title for favorite on dashboard |
|---|
| 104 | $core->callBehavior('adminDashboardFavsIcon',$core,$fav['name'],$__dashboard_icons[$fav['name']]); |
|---|
| 105 | } |
|---|
| 106 | } |
|---|
| 107 | } |
|---|
| 108 | if (!$count) { |
|---|
| 109 | // No user or global favorites, add "user pref" and "new entry" fav |
|---|
| 110 | if ($core->auth->check('usage,contentadmin',$core->blog->id)) { |
|---|
| 111 | $__dashboard_icons['new_post'] = new ArrayObject(array(__('New entry'),'post.php','images/menu/edit-b.png')); |
|---|
| 112 | } |
|---|
| 113 | $__dashboard_icons['prefs'] = new ArrayObject(array(__('My preferences'),'preferences.php','images/menu/user-pref-b.png')); |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | # Latest news for dashboard |
|---|
| 117 | $__dashboard_items = new ArrayObject(array(new ArrayObject,new ArrayObject)); |
|---|
| 118 | |
|---|
| 119 | # Documentation links |
|---|
| 120 | $dashboardItem = 0; |
|---|
| 121 | if ($core->auth->user_prefs->dashboard->doclinks) { |
|---|
| 122 | if (!empty($__resources['doc'])) |
|---|
| 123 | { |
|---|
| 124 | $doc_links = '<h3>'.__('Documentation and support').'</h3><ul>'; |
|---|
| 125 | |
|---|
| 126 | foreach ($__resources['doc'] as $k => $v) { |
|---|
| 127 | $doc_links .= '<li><a href="'.$v.'">'.$k.'</a></li>'; |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | $doc_links .= '</ul>'; |
|---|
| 131 | $__dashboard_items[$dashboardItem][] = $doc_links; |
|---|
| 132 | $dashboardItem++; |
|---|
| 133 | } |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | if ($core->auth->user_prefs->dashboard->dcnews) { |
|---|
| 137 | try |
|---|
| 138 | { |
|---|
| 139 | if (empty($__resources['rss_news'])) { |
|---|
| 140 | throw new Exception(); |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | $feed_reader = new feedReader; |
|---|
| 144 | $feed_reader->setCacheDir(DC_TPL_CACHE); |
|---|
| 145 | $feed_reader->setTimeout(2); |
|---|
| 146 | $feed_reader->setUserAgent('Dotclear - http://www.dotclear.org/'); |
|---|
| 147 | $feed = $feed_reader->parse($__resources['rss_news']); |
|---|
| 148 | if ($feed) |
|---|
| 149 | { |
|---|
| 150 | $latest_news = '<h3>'.__('Latest news').'</h3><dl id="news">'; |
|---|
| 151 | $i = 1; |
|---|
| 152 | foreach ($feed->items as $item) |
|---|
| 153 | { |
|---|
| 154 | $dt = isset($item->link) ? '<a href="'.$item->link.'">'.$item->title.'</a>' : $item->title; |
|---|
| 155 | |
|---|
| 156 | if ($i < 3) { |
|---|
| 157 | $latest_news .= |
|---|
| 158 | '<dt>'.$dt.'</dt>'. |
|---|
| 159 | '<dd><p><strong>'.dt::dt2str('%d %B %Y',$item->pubdate,'Europe/Paris').'</strong>: '. |
|---|
| 160 | '<em>'.text::cutString(html::clean($item->content),120).'...</em></p></dd>'; |
|---|
| 161 | } else { |
|---|
| 162 | $latest_news .= |
|---|
| 163 | '<dt>'.$dt.'</dt>'. |
|---|
| 164 | '<dd>'.dt::dt2str('%d %B %Y',$item->pubdate,'Europe/Paris').'</dd>'; |
|---|
| 165 | } |
|---|
| 166 | $i++; |
|---|
| 167 | if ($i > 3) { break; } |
|---|
| 168 | } |
|---|
| 169 | $latest_news .= '</dl>'; |
|---|
| 170 | $__dashboard_items[$dashboardItem][] = $latest_news; |
|---|
| 171 | $dashboardItem++; |
|---|
| 172 | } |
|---|
| 173 | } |
|---|
| 174 | catch (Exception $e) {} |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | $core->callBehavior('adminDashboardItems', $core, $__dashboard_items); |
|---|
| 178 | |
|---|
| 179 | # Dashboard content |
|---|
| 180 | $dashboardContents = ''; |
|---|
| 181 | $__dashboard_contents = new ArrayObject(array(new ArrayObject,new ArrayObject)); |
|---|
| 182 | $core->callBehavior('adminDashboardContents', $core, $__dashboard_contents); |
|---|
| 183 | |
|---|
| 184 | /* DISPLAY |
|---|
| 185 | -------------------------------------------------------- */ |
|---|
| 186 | dcPage::open(__('Dashboard'), |
|---|
| 187 | dcPage::jsToolBar(). |
|---|
| 188 | dcPage::jsLoad('js/_index.js'). |
|---|
| 189 | # --BEHAVIOR-- adminDashboardHeaders |
|---|
| 190 | $core->callBehavior('adminDashboardHeaders') |
|---|
| 191 | ); |
|---|
| 192 | |
|---|
| 193 | echo '<h2>'.html::escapeHTML($core->blog->name).' › '.__('Dashboard'); |
|---|
| 194 | |
|---|
| 195 | if ($core->auth->getInfo('user_default_blog') != $core->blog->id && $core->auth->blog_count > 1) { |
|---|
| 196 | echo |
|---|
| 197 | ' - <a href="index.php?default_blog=1" class="button">'.__('Make this blog my default blog').'</a>'; |
|---|
| 198 | } |
|---|
| 199 | |
|---|
| 200 | echo '</h2>'; |
|---|
| 201 | |
|---|
| 202 | if ($core->blog->status == 0) { |
|---|
| 203 | echo '<p class="static-msg">'.__('This blog is offline').'</p>'; |
|---|
| 204 | } elseif ($core->blog->status == -1) { |
|---|
| 205 | echo '<p class="static-msg">'.__('This blog is removed').'</p>'; |
|---|
| 206 | } |
|---|
| 207 | |
|---|
| 208 | if (!defined('DC_ADMIN_URL') || !DC_ADMIN_URL) { |
|---|
| 209 | echo |
|---|
| 210 | '<p class="static-msg">'. |
|---|
| 211 | 'DC_ADMIN_URL '.__('is not defined, you should edit your configuration file.'). |
|---|
| 212 | '</p>'; |
|---|
| 213 | } |
|---|
| 214 | |
|---|
| 215 | if (!defined('DC_ADMIN_MAILFROM') || !DC_ADMIN_MAILFROM) { |
|---|
| 216 | echo |
|---|
| 217 | '<p class="static-msg">'. |
|---|
| 218 | 'DC_ADMIN_MAILFROM '.__('is not defined, you should edit your configuration file.'). |
|---|
| 219 | '</p>'; |
|---|
| 220 | } |
|---|
| 221 | |
|---|
| 222 | # Plugins install messages |
|---|
| 223 | if (!empty($plugins_install['success'])) |
|---|
| 224 | { |
|---|
| 225 | echo '<div class="static-msg">'.__('Following plugins have been installed:').'<ul>'; |
|---|
| 226 | foreach ($plugins_install['success'] as $k => $v) { |
|---|
| 227 | echo '<li>'.$k.'</li>'; |
|---|
| 228 | } |
|---|
| 229 | echo '</ul></div>'; |
|---|
| 230 | } |
|---|
| 231 | if (!empty($plugins_install['failure'])) |
|---|
| 232 | { |
|---|
| 233 | echo '<div class="error">'.__('Following plugins have not been installed:').'<ul>'; |
|---|
| 234 | foreach ($plugins_install['failure'] as $k => $v) { |
|---|
| 235 | echo '<li>'.$k.' ('.$v.')</li>'; |
|---|
| 236 | } |
|---|
| 237 | echo '</ul></div>'; |
|---|
| 238 | } |
|---|
| 239 | |
|---|
| 240 | # Dashboard columns (processed first, as we need to know the result before displaying the icons.) |
|---|
| 241 | $dashboardItems = ''; |
|---|
| 242 | |
|---|
| 243 | # Dotclear updates notifications |
|---|
| 244 | if ($core->auth->isSuperAdmin() && is_readable(DC_DIGESTS)) |
|---|
| 245 | { |
|---|
| 246 | $updater = new dcUpdate(DC_UPDATE_URL,'dotclear',DC_UPDATE_VERSION,DC_TPL_CACHE.'/versions'); |
|---|
| 247 | $new_v = $updater->check(DC_VERSION); |
|---|
| 248 | $version_info = $new_v ? $updater->getInfoURL() : ''; |
|---|
| 249 | |
|---|
| 250 | if ($updater->getNotify() && $new_v) { |
|---|
| 251 | $dashboardItems .= |
|---|
| 252 | '<div id="upg-notify" class="static-msg"><p>'.sprintf(__('Dotclear %s is available!'),$new_v).'</p> '. |
|---|
| 253 | '<ul><li><strong><a href="update.php">'.sprintf(__('Upgrade now'),$new_v).'</a></strong>'. |
|---|
| 254 | '</li><li><a href="update.php?hide_msg=1">'.__('Remind me later').'</a>'. |
|---|
| 255 | ($version_info ? ' </li><li><a href="'.$version_info.'">'.__('information about this version').'</a>' : ''). |
|---|
| 256 | '</li></ul></div>'; |
|---|
| 257 | } |
|---|
| 258 | } |
|---|
| 259 | |
|---|
| 260 | # Errors modules notifications |
|---|
| 261 | if ($core->auth->isSuperAdmin()) |
|---|
| 262 | { |
|---|
| 263 | $list = array(); |
|---|
| 264 | foreach ($core->plugins->getErrors() as $k => $error) { |
|---|
| 265 | $list[] = '<li>'.$error.'</li>'; |
|---|
| 266 | } |
|---|
| 267 | |
|---|
| 268 | if (count($list) > 0) { |
|---|
| 269 | $dashboardItems .= |
|---|
| 270 | '<div id="module-errors" class="error"><p>'.__('Some plugins are installed twice:').'</p> '. |
|---|
| 271 | '<ul>'.implode("\n",$list).'</ul></div>'; |
|---|
| 272 | } |
|---|
| 273 | |
|---|
| 274 | } |
|---|
| 275 | |
|---|
| 276 | foreach ($__dashboard_items as $i) |
|---|
| 277 | { |
|---|
| 278 | if ($i->count() > 0) |
|---|
| 279 | { |
|---|
| 280 | $dashboardItems .= '<div>'; |
|---|
| 281 | foreach ($i as $v) { |
|---|
| 282 | $dashboardItems .= $v; |
|---|
| 283 | } |
|---|
| 284 | $dashboardItems .= '</div>'; |
|---|
| 285 | } |
|---|
| 286 | } |
|---|
| 287 | |
|---|
| 288 | # Dashboard icons |
|---|
| 289 | echo '<div id="dashboard-main"'.($dashboardItems ? '' : ' class="fullwidth"').'><div id="icons">'; |
|---|
| 290 | foreach ($__dashboard_icons as $i) |
|---|
| 291 | { |
|---|
| 292 | echo |
|---|
| 293 | '<p><a href="'.$i[1].'"><img src="'.$i[2].'" alt="" />'. |
|---|
| 294 | '<br /><span>'.$i[0].'</span></a></p>'; |
|---|
| 295 | } |
|---|
| 296 | echo '</div>'; |
|---|
| 297 | |
|---|
| 298 | if ($core->auth->user_prefs->dashboard->quickentry) { |
|---|
| 299 | if ($core->auth->check('usage,contentadmin',$core->blog->id)) |
|---|
| 300 | { |
|---|
| 301 | $categories_combo = array(' ' => ''); |
|---|
| 302 | try { |
|---|
| 303 | $categories = $core->blog->getCategories(array('post_type'=>'post')); |
|---|
| 304 | while ($categories->fetch()) { |
|---|
| 305 | $categories_combo[] = new formSelectOption( |
|---|
| 306 | str_repeat(' ',$categories->level-1). |
|---|
| 307 | ($categories->level-1 == 0 ? '' : '• ').html::escapeHTML($categories->cat_title), |
|---|
| 308 | $categories->cat_id |
|---|
| 309 | ); |
|---|
| 310 | } |
|---|
| 311 | } catch (Exception $e) { } |
|---|
| 312 | |
|---|
| 313 | echo |
|---|
| 314 | '<div id="quick">'. |
|---|
| 315 | '<h3>'.__('Quick entry').'</h3>'. |
|---|
| 316 | '<form id="quick-entry" action="post.php" method="post">'. |
|---|
| 317 | '<fieldset>'. |
|---|
| 318 | '<p class="col"><label for="post_title" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Title:'). |
|---|
| 319 | form::field('post_title',20,255,'','maximal'). |
|---|
| 320 | '</label></p>'. |
|---|
| 321 | '<p class="area"><label class="required" '. |
|---|
| 322 | 'for="post_content"><abbr title="'.__('Required field').'">*</abbr> '.__('Content:').'</label> '. |
|---|
| 323 | form::textarea('post_content',50,7). |
|---|
| 324 | '</p>'. |
|---|
| 325 | '<p><label for="cat_id" class="classic">'.__('Category:').' '. |
|---|
| 326 | form::combo('cat_id',$categories_combo).'</label></p>'. |
|---|
| 327 | '<p><input type="submit" value="'.__('Save').'" name="save" /> '. |
|---|
| 328 | ($core->auth->check('publish',$core->blog->id) |
|---|
| 329 | ? '<input type="hidden" value="'.__('save and publish').'" name="save-publish" />' |
|---|
| 330 | : ''). |
|---|
| 331 | $core->formNonce(). |
|---|
| 332 | form::hidden('post_status',-2). |
|---|
| 333 | form::hidden('post_format',$core->auth->getOption('post_format')). |
|---|
| 334 | form::hidden('post_excerpt',''). |
|---|
| 335 | form::hidden('post_lang',$core->auth->getInfo('user_lang')). |
|---|
| 336 | form::hidden('post_notes',''). |
|---|
| 337 | '</p>'. |
|---|
| 338 | '</fieldset>'. |
|---|
| 339 | '</form>'. |
|---|
| 340 | '</div>'; |
|---|
| 341 | } |
|---|
| 342 | } |
|---|
| 343 | |
|---|
| 344 | foreach ($__dashboard_contents as $i) |
|---|
| 345 | { |
|---|
| 346 | if ($i->count() > 0) |
|---|
| 347 | { |
|---|
| 348 | $dashboardContents .= '<div>'; |
|---|
| 349 | foreach ($i as $v) { |
|---|
| 350 | $dashboardContents .= $v; |
|---|
| 351 | } |
|---|
| 352 | $dashboardContents .= '</div>'; |
|---|
| 353 | } |
|---|
| 354 | } |
|---|
| 355 | echo ($dashboardContents ? '<div id="dashboard-contents">'.$dashboardContents.'</div>' : ''); |
|---|
| 356 | |
|---|
| 357 | echo '</div>'; |
|---|
| 358 | |
|---|
| 359 | echo ($dashboardItems ? '<div id="dashboard-items">'.$dashboardItems.'</div>' : ''); |
|---|
| 360 | |
|---|
| 361 | dcPage::close(); |
|---|
| 362 | ?> |
|---|