Dotclear

source: admin/index.php @ 896:89a7eea61559

Revision 896:89a7eea61559, 11.5 KB checked in by franck <carnet.franck.paul@…>, 13 years ago (diff)

Favs are displayed on Dashboard only if enabled, fixes #1301

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

Sites map