Dotclear

source: admin/index.php @ 1418:3df1516e0112

Revision 1418:3df1516e0112, 12.5 KB checked in by Denis Jean-Christian <contact@…>, 12 years ago (diff)

Enhance categories combo and other fix, step 5, addresses #1424

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

Sites map