Dotclear

source: admin/index.php @ 1699:5b68157bf85e

Revision 1699:5b68157bf85e, 14.3 KB checked in by Dsls, 11 years ago (diff)

Turned cookies into user_prefs for sections folding/unfolding, closes #1573

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2013 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',false,'boolean','',null,true);
62     }
63     $core->auth->user_prefs->dashboard->put('quickentry',false,'boolean');
64}
65
66// Handle folded/unfolded sections in admin from user preferences
67$ws = $core->auth->user_prefs->addWorkspace('toggles');
68if (!$core->auth->user_prefs->toggles->prefExists('unfolded_sections')) {
69     $core->auth->user_prefs->toggles->put('unfolded_sections','','string','Folded sections in admin',null,true);
70}
71
72
73# Dashboard icons
74$__dashboard_icons = new ArrayObject();
75
76# Dashboard favorites
77$post_count = $core->blog->getPosts(array(),true)->f(0);
78$str_entries = ($post_count > 1) ? __('%d entries') : __('%d entry');
79
80$comment_count = $core->blog->getComments(array(),true)->f(0);
81$str_comments = ($comment_count > 1) ? __('%d comments') : __('%d comment');
82
83$ws = $core->auth->user_prefs->addWorkspace('favorites');
84$count = 0;
85foreach ($ws->dumpPrefs() as $k => $v) {
86     // User favorites only
87     if (!$v['global']) {
88          $fav = unserialize($v['value']);
89          if (($fav['permissions'] == '*') || $core->auth->check($fav['permissions'],$core->blog->id)) {
90               if (dc_valid_fav($fav['url'])) {
91                    $count++;
92                    $title = ($fav['name'] == 'posts' ? sprintf($str_entries,$post_count) : 
93                         ($fav['name'] == 'comments' ? sprintf($str_comments,$comment_count) : $fav['title']));
94                    $__dashboard_icons[$fav['name']] = new ArrayObject(array(__($title),$fav['url'],$fav['large-icon']));
95
96                    # Let plugins set their own title for favorite on dashboard
97                    $core->callBehavior('adminDashboardFavsIcon',$core,$fav['name'],$__dashboard_icons[$fav['name']]);
98               }
99          }
100     }
101}   
102if (!$count) {
103     // Global favorites if any
104     foreach ($ws->dumpPrefs() as $k => $v) {
105          $fav = unserialize($v['value']);
106          if (($fav['permissions'] == '*') || $core->auth->check($fav['permissions'],$core->blog->id)) {
107               if (dc_valid_fav($fav['url'])) {
108                    $count++;
109                    $title = ($fav['name'] == 'posts' ? sprintf($str_entries,$post_count) : 
110                         ($fav['name'] == 'comments' ? sprintf($str_comments,$comment_count) : $fav['title']));
111                    $__dashboard_icons[$fav['name']] = new ArrayObject(array(__($title),$fav['url'],$fav['large-icon']));
112
113                    # Let plugins set their own title for favorite on dashboard
114                    $core->callBehavior('adminDashboardFavsIcon',$core,$fav['name'],$__dashboard_icons[$fav['name']]);
115               }
116          }
117     }
118}
119if (!$count) {
120     // No user or global favorites, add "user pref" and "new entry" fav
121     if ($core->auth->check('usage,contentadmin',$core->blog->id)) {
122          $__dashboard_icons['new_post'] = new ArrayObject(array(__('New entry'),'post.php','images/menu/edit-b.png'));
123     }
124     $__dashboard_icons['prefs'] = new ArrayObject(array(__('My preferences'),'preferences.php','images/menu/user-pref-b.png'));
125}
126
127# Latest news for dashboard
128$__dashboard_items = new ArrayObject(array(new ArrayObject,new ArrayObject));
129
130$dashboardItem = 0;
131
132if ($core->auth->user_prefs->dashboard->dcnews) {
133     try
134     {
135          if (empty($__resources['rss_news'])) {
136               throw new Exception();
137          }
138     
139          $feed_reader = new feedReader;
140          $feed_reader->setCacheDir(DC_TPL_CACHE);
141          $feed_reader->setTimeout(2);
142          $feed_reader->setUserAgent('Dotclear - http://www.dotclear.org/');
143          $feed = $feed_reader->parse($__resources['rss_news']);
144          if ($feed)
145          {
146               $latest_news = '<h3>'.__('Latest news').'</h3><dl id="news">';
147               $i = 1;
148               foreach ($feed->items as $item)
149               {
150                    $dt = isset($item->link) ? '<a href="'.$item->link.'" title="'.$item->title.' '.__('(external link)').'">'.
151                         $item->title.'</a>' : $item->title;
152               
153                    if ($i < 3) {
154                         $latest_news .=
155                         '<dt>'.$dt.'</dt>'.
156                         '<dd><p><strong>'.dt::dt2str(__('%d %B %Y:'),$item->pubdate,'Europe/Paris').'</strong> '.
157                         '<em>'.text::cutString(html::clean($item->content),120).'...</em></p></dd>';
158                    } else {
159                         $latest_news .=
160                         '<dt>'.$dt.'</dt>'.
161                         '<dd>'.dt::dt2str(__('%d %B %Y:'),$item->pubdate,'Europe/Paris').'</dd>';
162                    }
163                    $i++;
164                    if ($i > 3) { break; }
165               }
166               $latest_news .= '</dl>';
167               $__dashboard_items[$dashboardItem][] = $latest_news;
168               $dashboardItem++;
169          }
170     }
171     catch (Exception $e) {}
172}
173
174# Documentation links
175if ($core->auth->user_prefs->dashboard->doclinks) {
176     if (!empty($__resources['doc']))
177     {
178          $doc_links = '<h3>'.__('Documentation and support').'</h3><ul>';
179     
180          foreach ($__resources['doc'] as $k => $v) {
181               $doc_links .= '<li><a href="'.$v.'" title="'.$k.' '.__('(external link)').'">'.$k.'</a></li>';
182          }
183     
184          $doc_links .= '</ul>';
185          $__dashboard_items[$dashboardItem][] = $doc_links;
186          $dashboardItem++;
187     }
188}
189
190$core->callBehavior('adminDashboardItems', $core, $__dashboard_items);
191
192# Dashboard content
193$dashboardContents = '';
194$__dashboard_contents = new ArrayObject(array(new ArrayObject,new ArrayObject));
195$core->callBehavior('adminDashboardContents', $core, $__dashboard_contents);
196
197/* DISPLAY
198-------------------------------------------------------- */
199dcPage::open(__('Dashboard'),
200     dcPage::jsToolBar().
201     dcPage::jsLoad('js/_index.js').
202     # --BEHAVIOR-- adminDashboardHeaders
203     $core->callBehavior('adminDashboardHeaders'),
204     dcPage::breadcrumb(
205          array(
206          '<span class="page-title">'.__('Dashboard').' : '.html::escapeHTML($core->blog->name).'</span>' => ''
207          ),
208          false)
209);
210
211# Dotclear updates notifications
212if ($core->auth->isSuperAdmin() && is_readable(DC_DIGESTS))
213{
214     $updater = new dcUpdate(DC_UPDATE_URL,'dotclear',DC_UPDATE_VERSION,DC_TPL_CACHE.'/versions');
215     $new_v = $updater->check(DC_VERSION);
216     $version_info = $new_v ? $updater->getInfoURL() : '';
217
218     if ($updater->getNotify() && $new_v) {
219          echo
220          '<div class="dc-update"><h3>'.sprintf(__('Dotclear %s is available!'),$new_v).'</h3> '.
221          '<p><a class="button submit" href="update.php">'.sprintf(__('Upgrade now'),$new_v).'</a> '.
222          '<a href="update.php?hide_msg=1">'.__('Remind me later').'</a>'.
223          ($version_info ? ' </p>'.
224          '<p><a href="'.$version_info.'" class="info">'.__('information about this version').'</a>' : '').'</p>'.
225          '</div>';
226     }
227}
228
229if ($core->auth->getInfo('user_default_blog') != $core->blog->id && $core->auth->blog_count > 1) {
230     echo
231     '<p><a href="index.php?default_blog=1" class="button">'.__('Make this blog my default blog').'</a></p>';
232}
233
234if ($core->blog->status == 0) {
235     echo '<p class="static-msg">'.__('This blog is offline').'.</p>';
236} elseif ($core->blog->status == -1) {
237     echo '<p class="static-msg">'.__('This blog is removed').'.</p>';
238}
239
240if (!defined('DC_ADMIN_URL') || !DC_ADMIN_URL) {
241     echo
242     '<p class="static-msg">'.
243     sprintf(__('%s is not defined, you should edit your configuration file.'),'DC_ADMIN_URL').
244     ' '.__('See <a href="http://dotclear.org/documentation/2.0/admin/config">documentation</a> for more information.').
245     '</p>';
246}
247
248if (!defined('DC_ADMIN_MAILFROM') || !DC_ADMIN_MAILFROM) {
249     echo
250     '<p class="static-msg">'.
251     sprintf(__('%s is not defined, you should edit your configuration file.'),'DC_ADMIN_MAILFROM').
252     ' '.__('See <a href="http://dotclear.org/documentation/2.0/admin/config">documentation</a> for more information.').
253     '</p>';
254}
255
256$err = array();
257
258# Check cache directory
259if (!is_dir(DC_TPL_CACHE)) {
260     $err[] = '<p>'.sprintf(__('Cache directory %s does not exist.'),DC_TPL_CACHE).'</p>';
261} else if (!is_writable(DC_TPL_CACHE)) {
262     $err[] = '<p>'.sprintf(__('Cache directory %s is not writable.'),DC_TPL_CACHE).'</p>';
263}
264
265# Check public directory
266if (!is_dir($core->blog->public_path)) {
267     $err[] = '<p>'.sprintf(__('Directory %s does not exist.'),$core->blog->public_path).'</p>';
268} else if (!is_writable($core->blog->public_path)) {
269     $err[] = '<p>'.sprintf(__('Directory %s is not writable.'),$core->blog->public_path).'</p>';
270}
271
272# Error list
273if (count($err) > 0) {
274     echo '<div class="error"><p><strong>Erreur&nbsp;:</strong></p>'.
275     '<ul><li>'.implode("</li><li>",$err).'</li></ul></div>';
276}
277
278# Plugins install messages
279if (!empty($plugins_install['success']))
280{
281     echo '<div class="static-msg">'.__('Following plugins have been installed:').'<ul>';
282     foreach ($plugins_install['success'] as $k => $v) {
283          echo '<li>'.$k.'</li>';
284     }
285     echo '</ul></div>';
286}
287if (!empty($plugins_install['failure']))
288{
289     echo '<div class="error">'.__('Following plugins have not been installed:').'<ul>';
290     foreach ($plugins_install['failure'] as $k => $v) {
291          echo '<li>'.$k.' ('.$v.')</li>';
292     }
293     echo '</ul></div>';
294}
295
296# Dashboard columns (processed first, as we need to know the result before displaying the icons.)
297$dashboardItems = '';
298
299# Dotclear updates notifications
300if ($core->auth->isSuperAdmin() && is_readable(DC_DIGESTS))
301{
302     $updater = new dcUpdate(DC_UPDATE_URL,'dotclear',DC_UPDATE_VERSION,DC_TPL_CACHE.'/versions');
303     $new_v = $updater->check(DC_VERSION);
304     $version_info = $new_v ? $updater->getInfoURL() : '';
305     
306     if ($updater->getNotify() && $new_v) {
307          $dashboardItems .=
308          '<div id="upg-notify" class="static-msg"><p>'.sprintf(__('Dotclear %s is available!'),$new_v).'</p> '.
309          '<ul><li><strong><a href="update.php">'.sprintf(__('Upgrade now'),$new_v).'</a></strong>'.
310          '</li><li><a href="update.php?hide_msg=1">'.__('Remind me later').'</a>'.
311          ($version_info ? ' </li><li>'.sprintf(__('<a href=\"%s\">Information about this version</a>.'),$version_info) : '').
312          '</li></ul></div>';
313     }
314}
315
316# Errors modules notifications
317if ($core->auth->isSuperAdmin())
318{
319     $list = array();
320     foreach ($core->plugins->getErrors() as $k => $error) {
321          $list[] = '<li>'.$error.'</li>';
322     }
323     
324     if (count($list) > 0) {
325          $dashboardItems .=
326          '<div id="module-errors" class="error"><p>'.__('Some plugins are installed twice:').'</p> '.
327          '<ul>'.implode("\n",$list).'</ul></div>';
328     }
329     
330}
331
332foreach ($__dashboard_items as $i)
333{   
334     if ($i->count() > 0)
335     {
336          $dashboardItems .= '<div class="db-item">';
337          foreach ($i as $v) {
338               $dashboardItems .= $v;
339          }
340          $dashboardItems .= '</div>';
341     }
342}
343
344# Dashboard icons
345echo '<div id="dashboard-main"'.($dashboardItems ? '' : ' class="fullwidth"').'><div id="icons">';
346foreach ($__dashboard_icons as $i)
347{
348     echo
349     '<p><a href="'.$i[1].'"><img src="'.dc_admin_icon_url($i[2]).'" alt="" />'.
350     '<br /><span>'.$i[0].'</span></a></p>';
351}
352echo '</div>';
353
354if ($core->auth->user_prefs->dashboard->quickentry) {
355     if ($core->auth->check('usage,contentadmin',$core->blog->id))
356     {
357          # Getting categories
358          $categories_combo = array(__('(No cat)') => '');
359          try {
360               $categories = $core->blog->getCategories(array('post_type'=>'post'));
361               if (!$categories->isEmpty()) {
362                    while ($categories->fetch()) {
363                         $catparents_combo[] = $categories_combo[] = new formSelectOption(
364                              str_repeat('&nbsp;&nbsp;',$categories->level-1).($categories->level-1 == 0 ? '' : '&bull; ').html::escapeHTML($categories->cat_title),
365                              $categories->cat_id
366                         );
367                    }
368               }
369          } catch (Exception $e) { }
370     
371          echo
372          '<div id="quick">'.
373          '<h3>'.__('Quick entry').'</h3>'.
374          '<form id="quick-entry" action="post.php" method="post" class="fieldset">'.
375          '<h4>'.__('New entry').'</h4>'.
376          '<p class="col"><label for="post_title" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Title:').'</label>'.
377          form::field('post_title',20,255,'','maximal').
378          '</p>'.
379          '<p class="area"><label class="required" '.
380          'for="post_content"><abbr title="'.__('Required field').'">*</abbr> '.__('Content:').'</label> '.
381          form::textarea('post_content',50,7).
382          '</p>'.
383          '<p><label for="cat_id" class="classic">'.__('Category:').'</label> '.
384          form::combo('cat_id',$categories_combo).'</p>'.
385          ($core->auth->check('categories', $core->blog->id)
386               ? '<div>'.
387               '<p id="new_cat" class="q-cat">'.__('Add a new category').'</p>'.
388               '<p class="q-cat"><label for="new_cat_title">'.__('Title:').'</label> '.
389               form::field('new_cat_title',30,255,'','').'</p>'.
390               '<p class="q-cat"><label for="new_cat_parent">'.__('Parent:').'</label> '.
391               form::combo('new_cat_parent',$categories_combo,'','').
392               '</p>'.
393               '<p class="form-note info clear">'.__('This category will be created when you will save your post.').'</p>'.
394               '</div>'
395               : '').
396          '<p><input type="submit" value="'.__('Save').'" name="save" /> '.
397          ($core->auth->check('publish',$core->blog->id)
398               ? '<input type="hidden" value="'.__('Save and publish').'" name="save-publish" />'
399               : '').
400          $core->formNonce().
401          form::hidden('post_status',-2).
402          form::hidden('post_format',$core->auth->getOption('post_format')).
403          form::hidden('post_excerpt','').
404          form::hidden('post_lang',$core->auth->getInfo('user_lang')).
405          form::hidden('post_notes','').
406          '</p>'.
407          '</form>'.
408          '</div>';
409     }
410}
411
412foreach ($__dashboard_contents as $i)
413{   
414     if ($i->count() > 0)
415     {
416          $dashboardContents .= '<div>';
417          foreach ($i as $v) {
418               $dashboardContents .= $v;
419          }
420          $dashboardContents .= '</div>';
421     }
422}
423echo ($dashboardContents ? '<div id="dashboard-contents">'.$dashboardContents.'</div>' : '');
424
425echo '</div>';
426
427echo ($dashboardItems ? '<div id="dashboard-items">'.$dashboardItems.'</div>' : '');
428
429dcPage::close();
430?>
Note: See TracBrowser for help on using the repository browser.

Sites map