Dotclear

source: admin/index.php @ 130:e5a965650d8b

Revision 130:e5a965650d8b, 11.7 KB checked in by Franck <carnet.franck.paul@…>, 13 years ago (diff)

Implements adminDashboardFavsIcon behavior in order to let plugins set their own fav icon title on dashboard

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

Sites map