Dotclear

source: admin/index.php @ 13:c7a0f4cc3aab

Revision 13:c7a0f4cc3aab, 9.8 KB checked in by franckpaul, 14 years ago (diff)

Mise en place des options d'affichage des modules du dashboard
Fix de la gestion des préférences utilisateur (onglets User profile et User options)

Line 
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
13if (!empty($_GET['pf'])) {
14     require dirname(__FILE__).'/../inc/load_plugin_file.php';
15     exit;
16}
17
18require dirname(__FILE__).'/../inc/admin/prepend.php';
19
20if (!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
29dcPage::check('usage,contentadmin');
30
31# Logout
32if (!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->addWorkspace('dashboard');
47if (!$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}
53if (!$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}
59if (!$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;
78foreach ($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     }
89}   
90if (!$count) {
91     // Global favorites if any
92     foreach ($ws->dumpPrefs() as $k => $v) {
93          $fav = unserialize($v['value']);
94          if (($fav['permissions'] == '*') || $core->auth->check($fav['permissions'],$core->blog->id)) {
95               $count++;
96               $title = ($fav['name'] == 'posts' ? sprintf($str_entries,$post_count) : 
97                    ($fav['name'] == 'comments' ? sprintf($str_comments,$comment_count) : $fav['title']));
98               $__dashboard_icons[$fav['name']] = new ArrayObject(array($title,$fav['url'],$fav['large-icon']));
99          }
100     }
101}
102if (!$count) {
103     // No user or global favorites, add "user pref" and "new entry" fav
104     if ($core->auth->check('usage,contentadmin',$core->blog->id)) {
105          $__dashboard_icons['new_post'] = new ArrayObject(array(__('New entry'),'post.php','images/menu/edit-b.png'));
106     }
107     $__dashboard_icons['prefs'] = new ArrayObject(array(__('My preferences'),'preferences.php','images/menu/user-pref-b.png'));
108}
109
110# Latest news for dashboard
111$__dashboard_items = new ArrayObject(array(new ArrayObject,new ArrayObject));
112
113# Documentation links
114$dashboardItem = 0;
115if ($core->auth->user_prefs->dashboard->doclinks) {
116     if (!empty($__resources['doc']))
117     {
118          $doc_links = '<h3>'.__('Documentation').'</h3><ul>';
119     
120          foreach ($__resources['doc'] as $k => $v) {
121               $doc_links .= '<li><a href="'.$v.'">'.$k.'</a></li>';
122          }
123     
124          $doc_links .= '</ul>';
125          $__dashboard_items[$dashboardItem][] = $doc_links;
126          $dashboardItem++;
127     }
128}
129
130if ($core->auth->user_prefs->dashboard->dcnews) {
131     try
132     {
133          if (empty($__resources['rss_news'])) {
134               throw new Exception();
135          }
136     
137          $feed_reader = new feedReader;
138          $feed_reader->setCacheDir(DC_TPL_CACHE);
139          $feed_reader->setTimeout(2);
140          $feed_reader->setUserAgent('Dotclear - http://www.dotclear.org/');
141          $feed = $feed_reader->parse($__resources['rss_news']);
142          if ($feed)
143          {
144               $latest_news = '<h3>'.__('Latest news').'</h3><dl id="news">';
145               $i = 1;
146               foreach ($feed->items as $item)
147               {
148                    $dt = isset($item->link) ? '<a href="'.$item->link.'">'.$item->title.'</a>' : $item->title;
149               
150                    if ($i < 3) {
151                         $latest_news .=
152                         '<dt>'.$dt.'</dt>'.
153                         '<dd><p><strong>'.dt::dt2str('%d %B %Y',$item->pubdate,'Europe/Paris').'</strong>: '.
154                         '<em>'.text::cutString(html::clean($item->content),120).'...</em></p></dd>';
155                    } else {
156                         $latest_news .=
157                         '<dt>'.$dt.'</dt>'.
158                         '<dd>'.dt::dt2str('%d %B %Y',$item->pubdate,'Europe/Paris').'</dd>';
159                    }
160                    $i++;
161                    if ($i > 3) { break; }
162               }
163               $latest_news .= '</dl>';
164               $__dashboard_items[$dashboardItem][] = $latest_news;
165               $dashboardItem++;
166          }
167     }
168     catch (Exception $e) {}
169}
170
171$core->callBehavior('adminDashboardItems', $core, $__dashboard_items);
172
173/* DISPLAY
174-------------------------------------------------------- */
175dcPage::open(__('Dashboard'),
176     dcPage::jsToolBar().
177     dcPage::jsLoad('js/_index.js').
178     # --BEHAVIOR-- adminDashboardHeaders
179     $core->callBehavior('adminDashboardHeaders')
180);
181
182echo '<h2>'.html::escapeHTML($core->blog->name).' &rsaquo; '.__('Dashboard');
183
184if ($core->auth->getInfo('user_default_blog') != $core->blog->id && $core->auth->blog_count > 1) {
185     echo
186     ' - <a href="index.php?default_blog=1" class="button">'.__('Make this blog my default blog').'</a>';
187}
188
189echo '</h2>';
190
191if ($core->blog->status == 0) {
192     echo '<p class="static-msg">'.__('This blog is offline').'</p>';
193} elseif ($core->blog->status == -1) {
194     echo '<p class="static-msg">'.__('This blog is removed').'</p>';
195}
196
197if (!DC_ADMIN_URL) {
198     echo
199     '<p class="static-msg">'.
200     __('DC_ADMIN_URL is not defined, you should edit your configuration file.').
201     '</p>';
202}
203
204# Plugins install messages
205if (!empty($plugins_install['success']))
206{
207     echo '<div class="static-msg">'.__('Following plugins have been installed:').'<ul>';
208     foreach ($plugins_install['success'] as $k => $v) {
209          echo '<li>'.$k.'</li>';
210     }
211     echo '</ul></div>';
212}
213if (!empty($plugins_install['failure']))
214{
215     echo '<div class="error">'.__('Following plugins have not been installed:').'<ul>';
216     foreach ($plugins_install['failure'] as $k => $v) {
217          echo '<li>'.$k.' ('.$v.')</li>';
218     }
219     echo '</ul></div>';
220}
221
222# Dashboard icons
223echo '<div id="dashboard-main"><div id="icons">';
224foreach ($__dashboard_icons as $i)
225{
226     echo
227     '<p><a href="'.$i[1].'"><img src="'.$i[2].'" alt="" /></a>'.
228     '<span><a href="'.$i[1].'">'.$i[0].'</a></span></p>';
229}
230echo '</div>';
231
232if ($core->auth->user_prefs->dashboard->quickentry) {
233     if ($core->auth->check('usage,contentadmin',$core->blog->id))
234     {
235          $categories_combo = array('&nbsp;' => '');
236          try {
237               $categories = $core->blog->getCategories(array('post_type'=>'post'));
238               while ($categories->fetch()) {
239                    $categories_combo[] = new formSelectOption(
240                         str_repeat('&nbsp;&nbsp;',$categories->level-1).'&bull; '.html::escapeHTML($categories->cat_title),
241                         $categories->cat_id
242                    );
243               }
244          } catch (Exception $e) { }
245     
246          echo
247          '<div id="quick">'.
248          '<h3>'.__('Quick entry').'</h3>'.
249          '<form id="quick-entry" action="post.php" method="post">'.
250          '<fieldset>'.
251          '<p class="col"><label class="required" title="'.__('Required field').'">'.__('Title:').
252          form::field('post_title',20,255,'','maximal',2).
253          '</label></p>'.
254          '<p class="area"><label class="required" title="'.__('Required field').'" '.
255          'for="post_content">'.__('Content:').'</label> '.
256          form::textarea('post_content',50,7,'','',2).
257          '</p>'.
258          '<p><label class="classic">'.__('Category:').' '.
259          form::combo('cat_id',$categories_combo,'','',2).'</label></p>'.
260          '<p><input type="submit" value="'.__('save').'" name="save" tabindex="3" /> '.
261          ($core->auth->check('publish',$core->blog->id)
262               ? '<input type="hidden" value="'.__('save and publish').'" name="save-publish" />'
263               : '').
264          $core->formNonce().
265          form::hidden('post_status',-2).
266          form::hidden('post_format',$core->auth->getOption('post_format')).
267          form::hidden('post_excerpt','').
268          form::hidden('post_lang',$core->auth->getInfo('user_lang')).
269          form::hidden('post_notes','').
270          '</p>'.
271          '</fieldset>'.
272          '</form>'.
273          '</div>';
274     }
275}
276
277echo '</div>';
278
279# Dashboard columns
280echo '<div id="dashboard-items">';
281
282# Dotclear updates notifications
283if ($core->auth->isSuperAdmin() && is_readable(DC_DIGESTS))
284{
285     $updater = new dcUpdate(DC_UPDATE_URL,'dotclear',DC_UPDATE_VERSION,DC_TPL_CACHE.'/versions');
286     $new_v = $updater->check(DC_VERSION);
287     
288     if ($updater->getNotify() && $new_v) {
289          echo
290          '<div id="upg-notify" class="static-msg"><p>'.sprintf(__('Dotclear %s is available!'),$new_v).'</p> '.
291          '<ul><li><strong><a href="update.php">'.sprintf(__('Upgrade now'),$new_v).'</a></strong>'.
292          '</li><li><a href="update.php?hide_msg=1">'.__('Remind me later').'</a>'.
293          '</li></ul></div>';
294     }
295}
296
297# Errors modules notifications
298if ($core->auth->isSuperAdmin())
299{
300     $list = array();
301     foreach ($core->plugins->getErrors() as $k => $error) {
302          $list[] = '<li>'.$error.'</li>';
303     }
304     
305     if (count($list) > 0) {
306          echo
307          '<div id="module-errors" class="error"><p>'.__('Some plugins are installed twice:').'</p> '.
308          '<ul>'.implode("\n",$list).'</ul></div>';
309     }
310     
311}
312
313foreach ($__dashboard_items as $i)
314{
315     echo '<div>';
316     foreach ($i as $v) {
317          echo $v;
318     }
319     echo '</div>';
320}
321echo '</div>';
322
323dcPage::close();
324?>
Note: See TracBrowser for help on using the repository browser.

Sites map