Dotclear

source: admin/index.php @ 142:8928a4f3e67b

Revision 142:8928a4f3e67b, 10.4 KB checked in by xave <xave@…>, 13 years ago (diff)

Let's not waste expensive blank lines.

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

Sites map