Dotclear

source: admin/index.php @ 2175:44a940977175

Revision 2175:44a940977175, 14.7 KB checked in by Denis Jean-Chirstian <contact@…>, 12 years ago (diff)

Merge from default

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# Check plugins and themes update from repository
128function dc_check_repository_update($mod, $url, $img, $icon)
129{
130     $repo = new dcRepository($mod, $url);
131     $repo->check();
132     $upd = $repo->get(true);
133     if (!empty($upd)) {
134          $icon[0] .= '<br />'.sprintf(__('An update is available', '%s updates are available.', count($upd)),count($upd));
135          $icon[1] .= '#update';
136          $icon[2] = 'images/menu/'.$img.'-b-update.png';
137     }
138}
139if (isset($__dashboard_icons['plugins'])) {
140     dc_check_repository_update($core->plugins, $core->blog->settings->system->repository_plugin_url, 'plugins', $__dashboard_icons['plugins']);
141}
142if (isset($__dashboard_icons['blog_theme'])) {
143     $themes = new dcThemes($core);
144     $themes->loadModules($core->blog->themes_path, null);
145     dc_check_repository_update($themes, $core->blog->settings->system->repository_theme_url, 'blog-theme', $__dashboard_icons['blog_theme']);
146}
147
148# Latest news for dashboard
149$__dashboard_items = new ArrayObject(array(new ArrayObject,new ArrayObject));
150
151$dashboardItem = 0;
152
153if ($core->auth->user_prefs->dashboard->dcnews) {
154     try
155     {
156          if (empty($__resources['rss_news'])) {
157               throw new Exception();
158          }
159     
160          $feed_reader = new feedReader;
161          $feed_reader->setCacheDir(DC_TPL_CACHE);
162          $feed_reader->setTimeout(2);
163          $feed_reader->setUserAgent('Dotclear - http://www.dotclear.org/');
164          $feed = $feed_reader->parse($__resources['rss_news']);
165          if ($feed)
166          {
167               $latest_news = '<div class="box medium dc-box"><h3>'.__('Dotclear news').'</h3><dl id="news">';
168               $i = 1;
169               foreach ($feed->items as $item)
170               {
171                    $dt = isset($item->link) ? '<a href="'.$item->link.'" title="'.$item->title.' ('.__('new window').')">'.
172                         $item->title.' <img src="images/outgoing-blue.png" alt="" /></a>' : $item->title;
173               
174                    if ($i < 3) {
175                         $latest_news .=
176                         '<dt>'.$dt.'</dt>'.
177                         '<dd><p><strong>'.dt::dt2str(__('%d %B %Y:'),$item->pubdate,'Europe/Paris').'</strong> '.
178                         '<em>'.text::cutString(html::clean($item->content),120).'...</em></p></dd>';
179                    } else {
180                         $latest_news .=
181                         '<dt>'.$dt.'</dt>'.
182                         '<dd>'.dt::dt2str(__('%d %B %Y:'),$item->pubdate,'Europe/Paris').'</dd>';
183                    }
184                    $i++;
185                    if ($i > 2) { break; }
186               }
187               $latest_news .= '</dl></div>';
188               $__dashboard_items[$dashboardItem][] = $latest_news;
189               $dashboardItem++;
190          }
191     }
192     catch (Exception $e) {}
193}
194
195# Documentation links
196if ($core->auth->user_prefs->dashboard->doclinks) {
197     if (!empty($__resources['doc']))
198     {
199          $doc_links = '<div class="box small dc-box"><h3>'.__('Documentation and support').'</h3><ul>';
200     
201          foreach ($__resources['doc'] as $k => $v) {
202               $doc_links .= '<li><a href="'.$v.'" title="'.$k.' ('.__('new window').')">'.$k.
203               ' <img src="images/outgoing-blue.png" alt="" /></a></li>';
204          }
205     
206          $doc_links .= '</ul></div>';
207          $__dashboard_items[$dashboardItem][] = $doc_links;
208          $dashboardItem++;
209     }
210}
211
212$core->callBehavior('adminDashboardItems', $core, $__dashboard_items);
213
214# Dashboard content
215$dashboardContents = '';
216$__dashboard_contents = new ArrayObject(array(new ArrayObject,new ArrayObject));
217$core->callBehavior('adminDashboardContents', $core, $__dashboard_contents);
218
219/* DISPLAY
220-------------------------------------------------------- */
221dcPage::open(__('Dashboard'),
222     dcPage::jsToolBar().
223     dcPage::jsLoad('js/_index.js').
224     # --BEHAVIOR-- adminDashboardHeaders
225     $core->callBehavior('adminDashboardHeaders'),
226     dcPage::breadcrumb(
227          array(
228          __('Dashboard').' : '.html::escapeHTML($core->blog->name) => ''
229          ),
230          array('home_link' =>false)
231     )
232);
233
234# Dotclear updates notifications
235if ($core->auth->isSuperAdmin() && is_readable(DC_DIGESTS))
236{
237     $updater = new dcUpdate(DC_UPDATE_URL,'dotclear',DC_UPDATE_VERSION,DC_TPL_CACHE.'/versions');
238     $new_v = $updater->check(DC_VERSION);
239     $version_info = $new_v ? $updater->getInfoURL() : '';
240
241     if ($updater->getNotify() && $new_v) {
242          echo
243          '<div class="dc-update"><h3>'.sprintf(__('Dotclear %s is available!'),$new_v).'</h3> '.
244          '<p><a class="button submit" href="update.php">'.sprintf(__('Upgrade now'),$new_v).'</a> '.
245          '<a class="button" href="update.php?hide_msg=1">'.__('Remind me later').'</a>'.
246          ($version_info ? ' </p>'.
247          '<p class="updt-info"><a href="'.$version_info.'">'.__('Information about this version').'</a>' : '').'</p>'.
248          '</div>';
249     }
250}
251
252if ($core->auth->getInfo('user_default_blog') != $core->blog->id && $core->auth->getBlogCount() > 1) {
253     echo
254     '<p><a href="index.php?default_blog=1" class="button">'.__('Make this blog my default blog').'</a></p>';
255}
256
257if ($core->blog->status == 0) {
258     echo '<p class="static-msg">'.__('This blog is offline').'.</p>';
259} elseif ($core->blog->status == -1) {
260     echo '<p class="static-msg">'.__('This blog is removed').'.</p>';
261}
262
263if (!defined('DC_ADMIN_URL') || !DC_ADMIN_URL) {
264     echo
265     '<p class="static-msg">'.
266     sprintf(__('%s is not defined, you should edit your configuration file.'),'DC_ADMIN_URL').
267     ' '.__('See <a href="http://dotclear.org/documentation/2.0/admin/config">documentation</a> for more information.').
268     '</p>';
269}
270
271if (!defined('DC_ADMIN_MAILFROM') || !DC_ADMIN_MAILFROM) {
272     echo
273     '<p class="static-msg">'.
274     sprintf(__('%s is not defined, you should edit your configuration file.'),'DC_ADMIN_MAILFROM').
275     ' '.__('See <a href="http://dotclear.org/documentation/2.0/admin/config">documentation</a> for more information.').
276     '</p>';
277}
278
279$err = array();
280
281# Check cache directory
282if ( $core->auth->isSuperAdmin() ) {
283     if (!is_dir(DC_TPL_CACHE) || !is_writable(DC_TPL_CACHE)) {
284          $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>';
285     }
286} else {
287     if (!is_dir(DC_TPL_CACHE) || !is_writable(DC_TPL_CACHE)) {
288          $err[] = '<p>'.__("The cache directory does not exist or is not writable. You should contact your administrator.").'</p>';
289     }
290}
291
292# Check public directory
293if ( $core->auth->isSuperAdmin() ) {
294     if (!is_dir($core->blog->public_path) || !is_writable($core->blog->public_path)) {
295          $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>';
296     }
297} else {
298     if (!is_dir($core->blog->public_path) || !is_writable($core->blog->public_path)) {
299          $err[] = '<p>'.__("There is no writable root directory for the media manager. You should contact your administrator.").'</p>';
300     }
301}
302
303# Error list
304if (count($err) > 0) {
305     echo '<div class="error"><p><strong>Erreur&nbsp;:</strong></p>'.
306     '<ul><li>'.implode("</li><li>",$err).'</li></ul></div>';
307}
308
309# Plugins install messages
310if (!empty($plugins_install['success']))
311{
312     echo '<div class="success">'.__('Following plugins have been installed:').'<ul>';
313     foreach ($plugins_install['success'] as $k => $v) {
314          echo '<li>'.$k.'</li>';
315     }
316     echo '</ul></div>';
317}
318if (!empty($plugins_install['failure']))
319{
320     echo '<div class="error">'.__('Following plugins have not been installed:').'<ul>';
321     foreach ($plugins_install['failure'] as $k => $v) {
322          echo '<li>'.$k.' ('.$v.')</li>';
323     }
324     echo '</ul></div>';
325}
326# Errors modules notifications
327if ($core->auth->isSuperAdmin())
328{
329     $list = array();
330     foreach ($core->plugins->getErrors() as $k => $error) {
331          $list[] = '<li>'.$error.'</li>';
332     }
333     
334     if (count($list) > 0) {
335          echo 
336          '<div class="error" id="module-errors" class="error"><p>'.__('Some plugins are installed twice:').'</p> '.
337          '<ul>'.implode("\n",$list).'</ul></div>';
338     }
339}
340
341# Dashboard columns (processed first, as we need to know the result before displaying the icons.)
342$dashboardItems = '';
343
344foreach ($__dashboard_items as $i)
345{   
346     if ($i->count() > 0)
347     {
348          $dashboardItems .= '';
349          foreach ($i as $v) {
350               $dashboardItems .= $v;
351          }
352          $dashboardItems .= '';
353     }
354}
355
356# Dashboard elements
357echo '<div id="dashboard-main">';
358
359# Dashboard icons
360echo '<div id="icons">';
361foreach ($__dashboard_icons as $i)
362{
363     echo
364     '<p><a href="'.$i[1].'"><img src="'.dc_admin_icon_url($i[2]).'" alt="" />'.
365     '<br /><span>'.$i[0].'</span></a></p>';
366}
367echo '</div>';
368
369if ($core->auth->user_prefs->dashboard->quickentry) {
370     if ($core->auth->check('usage,contentadmin',$core->blog->id))
371     {
372          # Getting categories
373          $categories_combo = dcAdminCombos::getCategoriesCombo(
374               $core->blog->getCategories(array('post_type'=>'post'))
375          );
376     
377          echo
378          '<div id="quick">'.
379          '<h3>'.__('Quick entry').'</h3>'.
380          '<form id="quick-entry" action="post.php" method="post" class="fieldset">'.
381          '<h4>'.__('New entry').'</h4>'.
382          '<p class="col"><label for="post_title" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Title:').'</label>'.
383          form::field('post_title',20,255,'','maximal').
384          '</p>'.
385          '<p class="area"><label class="required" '.
386          'for="post_content"><abbr title="'.__('Required field').'">*</abbr> '.__('Content:').'</label> '.
387          form::textarea('post_content',50,7).
388          '</p>'.
389          '<p><label for="cat_id" class="classic">'.__('Category:').'</label> '.
390          form::combo('cat_id',$categories_combo).'</p>'.
391          ($core->auth->check('categories', $core->blog->id)
392               ? '<div>'.
393               '<p id="new_cat" class="q-cat">'.__('Add a new category').'</p>'.
394               '<p class="q-cat"><label for="new_cat_title">'.__('Title:').'</label> '.
395               form::field('new_cat_title',30,255,'','').'</p>'.
396               '<p class="q-cat"><label for="new_cat_parent">'.__('Parent:').'</label> '.
397               form::combo('new_cat_parent',$categories_combo,'','').
398               '</p>'.
399               '<p class="form-note info clear">'.__('This category will be created when you will save your post.').'</p>'.
400               '</div>'
401               : '').
402          '<p><input type="submit" value="'.__('Save').'" name="save" /> '.
403          ($core->auth->check('publish',$core->blog->id)
404               ? '<input type="hidden" value="'.__('Save and publish').'" name="save-publish" />'
405               : '').
406          $core->formNonce().
407          form::hidden('post_status',-2).
408          form::hidden('post_format',$core->auth->getOption('post_format')).
409          form::hidden('post_excerpt','').
410          form::hidden('post_lang',$core->auth->getInfo('user_lang')).
411          form::hidden('post_notes','').
412          '</p>'.
413          '</form>'.
414          '</div>';
415     }
416}
417
418foreach ($__dashboard_contents as $i)
419{   
420     if ($i->count() > 0)
421     {
422          $dashboardContents .= '';
423          foreach ($i as $v) {
424               $dashboardContents .= $v;
425          }
426          $dashboardContents .= '';
427     }
428}
429
430if ($dashboardContents != '' || $dashboardItems != '') {
431     echo 
432     '<div id="dashboard-boxes">'.
433     '<div class="db-items">'.$dashboardItems.$dashboardContents.'</div>'.
434     '</div>';     
435}
436
437echo '</div>'; #end dashboard-main
438
439dcPage::close();
440?>
Note: See TracBrowser for help on using the repository browser.

Sites map