Dotclear

source: admin/index.php @ 139:3ccd56e7922b

Revision 139:3ccd56e7922b, 10.5 KB checked in by xave <xave@…>, 14 years ago (diff)

Back where we started!

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               # Let plugins set their own title for favorite on dashboard
89               $core->callBehavior('adminDashboardFavsIcon',$core,$fav['name'],$__dashboard_icons[$fav['name']]);
90          }
91     }
92}   
93if (!$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}
108if (!$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;
121if ($core->auth->user_prefs->dashboard->doclinks) {
122     if (!empty($__resources['doc']))
123     {
124          $doc_links = '<h3>'.__('Documentation').'</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
136if ($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/* DISPLAY
180-------------------------------------------------------- */
181dcPage::open(__('Dashboard'),
182     dcPage::jsToolBar().
183     dcPage::jsLoad('js/_index.js').
184     # --BEHAVIOR-- adminDashboardHeaders
185     $core->callBehavior('adminDashboardHeaders')
186);
187
188echo '<h2>'.html::escapeHTML($core->blog->name).' &rsaquo; '.__('Dashboard');
189
190if ($core->auth->getInfo('user_default_blog') != $core->blog->id && $core->auth->blog_count > 1) {
191     echo
192     ' - <a href="index.php?default_blog=1" class="button">'.__('Make this blog my default blog').'</a>';
193}
194
195echo '</h2>';
196
197if ($core->blog->status == 0) {
198     echo '<p class="static-msg">'.__('This blog is offline').'</p>';
199} elseif ($core->blog->status == -1) {
200     echo '<p class="static-msg">'.__('This blog is removed').'</p>';
201}
202
203if (!DC_ADMIN_URL) {
204     echo
205     '<p class="static-msg">'.
206     __('DC_ADMIN_URL is not defined, you should edit your configuration file.').
207     '</p>';
208}
209
210# Plugins install messages
211if (!empty($plugins_install['success']))
212{
213     echo '<div class="static-msg">'.__('Following plugins have been installed:').'<ul>';
214     foreach ($plugins_install['success'] as $k => $v) {
215          echo '<li>'.$k.'</li>';
216     }
217     echo '</ul></div>';
218}
219if (!empty($plugins_install['failure']))
220{
221     echo '<div class="error">'.__('Following plugins have not been installed:').'<ul>';
222     foreach ($plugins_install['failure'] as $k => $v) {
223          echo '<li>'.$k.' ('.$v.')</li>';
224     }
225     echo '</ul></div>';
226}
227
228# Dashboard columns (processed first, as we need to know the result before displaying the icons.)
229$dashboardItems = '';
230
231# Dotclear updates notifications
232if ($core->auth->isSuperAdmin() && is_readable(DC_DIGESTS))
233{
234     $updater = new dcUpdate(DC_UPDATE_URL,'dotclear',DC_UPDATE_VERSION,DC_TPL_CACHE.'/versions');
235     $new_v = $updater->check(DC_VERSION);
236     
237     if ($updater->getNotify() && $new_v) {
238          $dashboardItems .=
239          '<div id="upg-notify" class="static-msg"><p>'.sprintf(__('Dotclear %s is available!'),$new_v).'</p> '.
240          '<ul><li><strong><a href="update.php">'.sprintf(__('Upgrade now'),$new_v).'</a></strong>'.
241          '</li><li><a href="update.php?hide_msg=1">'.__('Remind me later').'</a>'.
242          '</li></ul></div>';
243     }
244}
245
246# Errors modules notifications
247if ($core->auth->isSuperAdmin())
248{
249     $list = array();
250     foreach ($core->plugins->getErrors() as $k => $error) {
251          $list[] = '<li>'.$error.'</li>';
252     }
253     
254     if (count($list) > 0) {
255          $dashboardItems .=
256          '<div id="module-errors" class="error"><p>'.__('Some plugins are installed twice:').'</p> '.
257          '<ul>'.implode("\n",$list).'</ul></div>';
258     }
259     
260}
261
262foreach ($__dashboard_items as $i)
263{   
264     if ($i->count() > 0)
265     {
266          $dashboardItems .= '<div>';
267          foreach ($i as $v) {
268               $dashboardItems .= $v;
269          }
270          $dashboardItems .= '</div>';
271     }
272}
273
274# Dashboard icons
275echo '<div id="dashboard-main"'.($dashboardItems ? '' : ' class="fullwidth"').'><div id="icons">';
276foreach ($__dashboard_icons as $i)
277{
278     echo
279     '<p><a href="'.$i[1].'"><img src="'.$i[2].'" alt="" /></a>'.
280     '<span><a href="'.$i[1].'">'.$i[0].'</a></span></p>';
281}
282echo '</div>';
283
284if ($core->auth->user_prefs->dashboard->quickentry) {
285     if ($core->auth->check('usage,contentadmin',$core->blog->id))
286     {
287          $categories_combo = array('&nbsp;' => '');
288          try {
289               $categories = $core->blog->getCategories(array('post_type'=>'post'));
290               while ($categories->fetch()) {
291                    $categories_combo[] = new formSelectOption(
292                         str_repeat('&nbsp;&nbsp;',$categories->level-1).'&bull; '.html::escapeHTML($categories->cat_title),
293                         $categories->cat_id
294                    );
295               }
296          } catch (Exception $e) { }
297     
298          echo
299          '<div id="quick">'.
300          '<h3>'.__('Quick entry').'</h3>'.
301          '<form id="quick-entry" action="post.php" method="post">'.
302          '<fieldset>'.
303          '<p class="col"><label for="post_title" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Title:').
304          form::field('post_title',20,255,'','maximal',2).
305          '</label></p>'.
306          '<p class="area"><label class="required" '.
307          'for="post_content"><abbr title="'.__('Required field').'">*</abbr> '.__('Content:').'</label> '.
308          form::textarea('post_content',50,7,'','',2).
309          '</p>'.
310          '<p><label for="cat_id" class="classic">'.__('Category:').' '.
311          form::combo('cat_id',$categories_combo,'','',2).'</label></p>'.
312          '<p><input type="submit" value="'.__('save').'" name="save" tabindex="3" /> '.
313          ($core->auth->check('publish',$core->blog->id)
314               ? '<input type="hidden" value="'.__('save and publish').'" name="save-publish" />'
315               : '').
316          $core->formNonce().
317          form::hidden('post_status',-2).
318          form::hidden('post_format',$core->auth->getOption('post_format')).
319          form::hidden('post_excerpt','').
320          form::hidden('post_lang',$core->auth->getInfo('user_lang')).
321          form::hidden('post_notes','').
322          '</p>'.
323          '</fieldset>'.
324          '</form>'.
325          '</div>';
326     }
327}
328
329echo '</div>';
330
331echo ($dashboardItems ? '<div id="dashboard-items">'.$dashboardItems.'</div>' : '');
332
333dcPage::close();
334?>
Note: See TracBrowser for help on using the repository browser.

Sites map