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