Dotclear

source: admin/index.php @ 141:340bbc2cd9f4

Revision 141:340bbc2cd9f4, 10.4 KB checked in by xave <xave@…>, 15 years ago (diff)

Deported the error handling found in constructors. Now we can upgrade.

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

Sites map