Dotclear

source: admin/index.php @ 106:cca7b21765d2

Revision 106:cca7b21765d2, 11.1 KB checked in by xpla@…, 13 years ago (diff)

Bugfix for userprefs load.

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

Sites map