Dotclear

source: admin/index.php @ 1056:b67f949a98f8

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

Sites map