Dotclear

source: admin/index.php @ 854:893c8fc07a74

Revision 854:893c8fc07a74, 10.6 KB checked in by Dsls <dsls@…>, 13 years ago (diff)

sexy step 4 : wysiwyg no more.

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

Sites map