Dotclear

source: admin/index.php @ 2229:d5e819e27bea

Revision 2229:d5e819e27bea, 11.8 KB checked in by Dsls, 12 years ago (diff)

reworked favorites handling (wip)

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$favs = $core->favs->getUserFavorites();
77$core->favs->appendDashboardIcons($__dashboard_icons);
78
79# Latest news for dashboard
80$__dashboard_items = new ArrayObject(array(new ArrayObject(),new ArrayObject()));
81
82$dashboardItem = 0;
83
84if ($core->auth->user_prefs->dashboard->dcnews) {
85     try
86     {
87          if (empty($__resources['rss_news'])) {
88               throw new Exception();
89          }
90     
91          $feed_reader = new feedReader;
92          $feed_reader->setCacheDir(DC_TPL_CACHE);
93          $feed_reader->setTimeout(2);
94          $feed_reader->setUserAgent('Dotclear - http://www.dotclear.org/');
95          $feed = $feed_reader->parse($__resources['rss_news']);
96          if ($feed)
97          {
98               $latest_news = '<div class="box medium dc-box"><h3>'.__('Dotclear news').'</h3><dl id="news">';
99               $i = 1;
100               foreach ($feed->items as $item)
101               {
102                    $dt = isset($item->link) ? '<a href="'.$item->link.'" class="outgoing" title="'.$item->title.'">'.
103                         $item->title.' <img src="images/outgoing-blue.png" alt="" /></a>' : $item->title;
104               
105                    if ($i < 3) {
106                         $latest_news .=
107                         '<dt>'.$dt.'</dt>'.
108                         '<dd><p><strong>'.dt::dt2str(__('%d %B %Y:'),$item->pubdate,'Europe/Paris').'</strong> '.
109                         '<em>'.text::cutString(html::clean($item->content),120).'...</em></p></dd>';
110                    } else {
111                         $latest_news .=
112                         '<dt>'.$dt.'</dt>'.
113                         '<dd>'.dt::dt2str(__('%d %B %Y:'),$item->pubdate,'Europe/Paris').'</dd>';
114                    }
115                    $i++;
116                    if ($i > 2) { break; }
117               }
118               $latest_news .= '</dl></div>';
119               $__dashboard_items[$dashboardItem][] = $latest_news;
120               $dashboardItem++;
121          }
122     }
123     catch (Exception $e) {}
124}
125
126# Documentation links
127if ($core->auth->user_prefs->dashboard->doclinks) {
128     if (!empty($__resources['doc']))
129     {
130          $doc_links = '<div class="box small dc-box"><h3>'.__('Documentation and support').'</h3><ul>';
131     
132          foreach ($__resources['doc'] as $k => $v) {
133               $doc_links .= '<li><a class="outgoing" href="'.$v.'" title="'.$k.'">'.$k.
134               ' <img src="images/outgoing-blue.png" alt="" /></a></li>';
135          }
136     
137          $doc_links .= '</ul></div>';
138          $__dashboard_items[$dashboardItem][] = $doc_links;
139          $dashboardItem++;
140     }
141}
142
143$core->callBehavior('adminDashboardItems', $core, $__dashboard_items);
144
145# Dashboard content
146$dashboardContents = '';
147$__dashboard_contents = new ArrayObject(array(new ArrayObject,new ArrayObject));
148$core->callBehavior('adminDashboardContents', $core, $__dashboard_contents);
149
150/* DISPLAY
151-------------------------------------------------------- */
152dcPage::open(__('Dashboard'),
153     dcPage::jsToolBar().
154     dcPage::jsLoad('js/_index.js').
155     # --BEHAVIOR-- adminDashboardHeaders
156     $core->callBehavior('adminDashboardHeaders'),
157     dcPage::breadcrumb(
158          array(
159          __('Dashboard').' : '.html::escapeHTML($core->blog->name) => ''
160          ),
161          array('home_link' =>false)
162     )
163);
164
165# Dotclear updates notifications
166if ($core->auth->isSuperAdmin() && is_readable(DC_DIGESTS))
167{
168     $updater = new dcUpdate(DC_UPDATE_URL,'dotclear',DC_UPDATE_VERSION,DC_TPL_CACHE.'/versions');
169     $new_v = $updater->check(DC_VERSION);
170     $version_info = $new_v ? $updater->getInfoURL() : '';
171
172     if ($updater->getNotify() && $new_v) {
173          echo
174          '<div class="dc-update"><h3>'.sprintf(__('Dotclear %s is available!'),$new_v).'</h3> '.
175          '<p><a class="button submit" href="update.php">'.sprintf(__('Upgrade now'),$new_v).'</a> '.
176          '<a class="button" href="update.php?hide_msg=1">'.__('Remind me later').'</a>'.
177          ($version_info ? ' </p>'.
178          '<p class="updt-info"><a href="'.$version_info.'">'.__('Information about this version').'</a>' : '').'</p>'.
179          '</div>';
180     }
181}
182
183if ($core->auth->getInfo('user_default_blog') != $core->blog->id && $core->auth->getBlogCount() > 1) {
184     echo
185     '<p><a href="index.php?default_blog=1" class="button">'.__('Make this blog my default blog').'</a></p>';
186}
187
188if ($core->blog->status == 0) {
189     echo '<p class="static-msg">'.__('This blog is offline').'.</p>';
190} elseif ($core->blog->status == -1) {
191     echo '<p class="static-msg">'.__('This blog is removed').'.</p>';
192}
193
194if (!defined('DC_ADMIN_URL') || !DC_ADMIN_URL) {
195     echo
196     '<p class="static-msg">'.
197     sprintf(__('%s is not defined, you should edit your configuration file.'),'DC_ADMIN_URL').
198     ' '.__('See <a href="http://dotclear.org/documentation/2.0/admin/config">documentation</a> for more information.').
199     '</p>';
200}
201
202if (!defined('DC_ADMIN_MAILFROM') || !DC_ADMIN_MAILFROM) {
203     echo
204     '<p class="static-msg">'.
205     sprintf(__('%s is not defined, you should edit your configuration file.'),'DC_ADMIN_MAILFROM').
206     ' '.__('See <a href="http://dotclear.org/documentation/2.0/admin/config">documentation</a> for more information.').
207     '</p>';
208}
209
210$err = array();
211
212# Check cache directory
213if ( $core->auth->isSuperAdmin() ) {
214     if (!is_dir(DC_TPL_CACHE) || !is_writable(DC_TPL_CACHE)) {
215          $err[] = '<p>'.__("The cache directory does not exist or is not writable. You must create this directory with sufficient rights and affect this location to \"DC_TPL_CACHE\" in inc/config.php file.").'</p>';
216     }
217} else {
218     if (!is_dir(DC_TPL_CACHE) || !is_writable(DC_TPL_CACHE)) {
219          $err[] = '<p>'.__("The cache directory does not exist or is not writable. You should contact your administrator.").'</p>';
220     }
221}
222
223# Check public directory
224if ( $core->auth->isSuperAdmin() ) {
225     if (!is_dir($core->blog->public_path) || !is_writable($core->blog->public_path)) {
226          $err[] = '<p>'.__("There is no writable directory /public/ at the location set in about:config \"public_path\". You must create this directory with sufficient rights (or change this setting).").'</p>';
227     }
228} else {
229     if (!is_dir($core->blog->public_path) || !is_writable($core->blog->public_path)) {
230          $err[] = '<p>'.__("There is no writable root directory for the media manager. You should contact your administrator.").'</p>';
231     }
232}
233
234# Error list
235if (count($err) > 0) {
236     echo '<div class="error"><p><strong>Erreur&nbsp;:</strong></p>'.
237     '<ul><li>'.implode("</li><li>",$err).'</li></ul></div>';
238}
239
240# Plugins install messages
241if (!empty($plugins_install['success']))
242{
243     echo '<div class="success">'.__('Following plugins have been installed:').'<ul>';
244     foreach ($plugins_install['success'] as $k => $v) {
245          echo '<li>'.$k.'</li>';
246     }
247     echo '</ul></div>';
248}
249if (!empty($plugins_install['failure']))
250{
251     echo '<div class="error">'.__('Following plugins have not been installed:').'<ul>';
252     foreach ($plugins_install['failure'] as $k => $v) {
253          echo '<li>'.$k.' ('.$v.')</li>';
254     }
255     echo '</ul></div>';
256}
257# Errors modules notifications
258if ($core->auth->isSuperAdmin())
259{
260     $list = array();
261     foreach ($core->plugins->getErrors() as $k => $error) {
262          $list[] = '<li>'.$error.'</li>';
263     }
264     
265     if (count($list) > 0) {
266          echo 
267          '<div class="error" id="module-errors" class="error"><p>'.__('Some plugins are installed twice:').'</p> '.
268          '<ul>'.implode("\n",$list).'</ul></div>';
269     }
270}
271
272# Dashboard columns (processed first, as we need to know the result before displaying the icons.)
273$dashboardItems = '';
274
275foreach ($__dashboard_items as $i)
276{   
277     if ($i->count() > 0)
278     {
279          $dashboardItems .= '';
280          foreach ($i as $v) {
281               $dashboardItems .= $v;
282          }
283          $dashboardItems .= '';
284     }
285}
286
287# Dashboard elements
288echo '<div id="dashboard-main">';
289
290# Dashboard icons
291echo '<div id="icons">';
292foreach ($__dashboard_icons as $i)
293{
294     echo
295     '<p><a href="'.$i[1].'"><img src="'.dc_admin_icon_url($i[2]).'" alt="" />'.
296     '<br /><span>'.$i[0].'</span></a></p>';
297}
298echo '</div>';
299
300if ($core->auth->user_prefs->dashboard->quickentry) {
301     if ($core->auth->check('usage,contentadmin',$core->blog->id))
302     {
303          # Getting categories
304          $categories_combo = dcAdminCombos::getCategoriesCombo(
305               $core->blog->getCategories(array('post_type'=>'post'))
306          );
307     
308          echo
309          '<div id="quick">'.
310          '<h3>'.__('Quick entry').'</h3>'.
311          '<form id="quick-entry" action="post.php" method="post" class="fieldset">'.
312          '<h4>'.__('New entry').'</h4>'.
313          '<p class="col"><label for="post_title" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Title:').'</label>'.
314          form::field('post_title',20,255,'','maximal').
315          '</p>'.
316          '<p class="area"><label class="required" '.
317          'for="post_content"><abbr title="'.__('Required field').'">*</abbr> '.__('Content:').'</label> '.
318          form::textarea('post_content',50,7).
319          '</p>'.
320          '<p><label for="cat_id" class="classic">'.__('Category:').'</label> '.
321          form::combo('cat_id',$categories_combo).'</p>'.
322          ($core->auth->check('categories', $core->blog->id)
323               ? '<div>'.
324               '<p id="new_cat" class="q-cat">'.__('Add a new category').'</p>'.
325               '<p class="q-cat"><label for="new_cat_title">'.__('Title:').'</label> '.
326               form::field('new_cat_title',30,255,'','').'</p>'.
327               '<p class="q-cat"><label for="new_cat_parent">'.__('Parent:').'</label> '.
328               form::combo('new_cat_parent',$categories_combo,'','').
329               '</p>'.
330               '<p class="form-note info clear">'.__('This category will be created when you will save your post.').'</p>'.
331               '</div>'
332               : '').
333          '<p><input type="submit" value="'.__('Save').'" name="save" /> '.
334          ($core->auth->check('publish',$core->blog->id)
335               ? '<input type="hidden" value="'.__('Save and publish').'" name="save-publish" />'
336               : '').
337          $core->formNonce().
338          form::hidden('post_status',-2).
339          form::hidden('post_format',$core->auth->getOption('post_format')).
340          form::hidden('post_excerpt','').
341          form::hidden('post_lang',$core->auth->getInfo('user_lang')).
342          form::hidden('post_notes','').
343          '</p>'.
344          '</form>'.
345          '</div>';
346     }
347}
348
349foreach ($__dashboard_contents as $i)
350{   
351     if ($i->count() > 0)
352     {
353          $dashboardContents .= '';
354          foreach ($i as $v) {
355               $dashboardContents .= $v;
356          }
357          $dashboardContents .= '';
358     }
359}
360
361if ($dashboardContents != '' || $dashboardItems != '') {
362     echo 
363     '<div id="dashboard-boxes">'.
364     '<div class="db-items">'.$dashboardItems.$dashboardContents.'</div>'.
365     '</div>';     
366}
367
368echo '</div>'; #end dashboard-main
369
370dcPage::close();
371?>
Note: See TracBrowser for help on using the repository browser.

Sites map