Dotclear

source: admin/index.php @ 3066:aa297059d2a0

Revision 3066:aa297059d2a0, 13.4 KB checked in by Dsls, 10 years ago (diff)

Disable plugins with unmetdependencies, in admin home and plugins.php admin page. See #1842, fixed partially (need to see how to cope with themes now)

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          $core->adminurl->redirect("admin.home");
24     } catch (Exception $e) {
25          $core->error->add($e->getMessage());
26     }
27}
28
29dcPage::check('usage,contentadmin');
30
31if ($core->plugins->disableDepModules($core->adminurl->get('admin.home',array()))) {
32     exit;
33}
34
35# Logout
36if (!empty($_GET['logout'])) {
37     $core->session->destroy();
38     if (isset($_COOKIE['dc_admin'])) {
39          unset($_COOKIE['dc_admin']);
40          setcookie('dc_admin',false,-600,'','',DC_ADMIN_SSL);
41     }
42     $core->adminurl->redirect("admin.auth");
43     exit;
44}
45
46# Plugin install
47$plugins_install = $core->plugins->installModules();
48
49# Check dashboard module prefs
50$ws = $core->auth->user_prefs->addWorkspace('dashboard');
51if (!$core->auth->user_prefs->dashboard->prefExists('doclinks')) {
52     if (!$core->auth->user_prefs->dashboard->prefExists('doclinks',true)) {
53          $core->auth->user_prefs->dashboard->put('doclinks',true,'boolean','',null,true);
54     }
55     $core->auth->user_prefs->dashboard->put('doclinks',true,'boolean');
56}
57if (!$core->auth->user_prefs->dashboard->prefExists('dcnews')) {
58     if (!$core->auth->user_prefs->dashboard->prefExists('dcnews',true)) {
59          $core->auth->user_prefs->dashboard->put('dcnews',true,'boolean','',null,true);
60     }
61     $core->auth->user_prefs->dashboard->put('dcnews',true,'boolean');
62}
63if (!$core->auth->user_prefs->dashboard->prefExists('quickentry')) {
64     if (!$core->auth->user_prefs->dashboard->prefExists('quickentry',true)) {
65          $core->auth->user_prefs->dashboard->put('quickentry',false,'boolean','',null,true);
66     }
67     $core->auth->user_prefs->dashboard->put('quickentry',false,'boolean');
68}
69
70// Handle folded/unfolded sections in admin from user preferences
71$ws = $core->auth->user_prefs->addWorkspace('toggles');
72if (!$core->auth->user_prefs->toggles->prefExists('unfolded_sections')) {
73     $core->auth->user_prefs->toggles->put('unfolded_sections','','string','Folded sections in admin',null,true);
74}
75
76
77# Dashboard icons
78$__dashboard_icons = new ArrayObject();
79
80$favs = $core->favs->getUserFavorites();
81$core->favs->appendDashboardIcons($__dashboard_icons);
82
83# Check plugins and themes update from repository
84function dc_check_store_update($mod, $url, $img, $icon)
85{
86     $repo = new dcStore($mod, $url);
87     $upd = $repo->get(true);
88     if (!empty($upd)) {
89          $icon[0] .= '<br />'.sprintf(__('An update is available', '%s updates are available.', count($upd)),count($upd));
90          $icon[1] .= '#update';
91          $icon[2] = 'images/menu/'.$img.'-b-update.png';
92     }
93}
94if (isset($__dashboard_icons['plugins'])) {
95     dc_check_store_update($core->plugins, $core->blog->settings->system->store_plugin_url, 'plugins', $__dashboard_icons['plugins']);
96}
97if (isset($__dashboard_icons['blog_theme'])) {
98     $themes = new dcThemes($core);
99     $themes->loadModules($core->blog->themes_path, null);
100     dc_check_store_update($themes, $core->blog->settings->system->store_theme_url, 'blog-theme', $__dashboard_icons['blog_theme']);
101}
102
103# Latest news for dashboard
104$__dashboard_items = new ArrayObject(array(new ArrayObject(),new ArrayObject()));
105
106$dashboardItem = 0;
107
108if ($core->auth->user_prefs->dashboard->dcnews) {
109     try
110     {
111          if (empty($__resources['rss_news'])) {
112               throw new Exception();
113          }
114
115          $feed_reader = new feedReader;
116          $feed_reader->setCacheDir(DC_TPL_CACHE);
117          $feed_reader->setTimeout(2);
118          $feed_reader->setUserAgent('Dotclear - http://www.dotclear.org/');
119          $feed = $feed_reader->parse($__resources['rss_news']);
120          if ($feed)
121          {
122               $latest_news = '<div class="box medium dc-box"><h3>'.__('Dotclear news').'</h3><dl id="news">';
123               $i = 1;
124               foreach ($feed->items as $item)
125               {
126                    $dt = isset($item->link) ? '<a href="'.$item->link.'" class="outgoing" title="'.$item->title.'">'.
127                         $item->title.' <img src="images/outgoing-blue.png" alt="" /></a>' : $item->title;
128
129                    if ($i < 3) {
130                         $latest_news .=
131                         '<dt>'.$dt.'</dt>'.
132                         '<dd><p><strong>'.dt::dt2str(__('%d %B %Y:'),$item->pubdate,'Europe/Paris').'</strong> '.
133                         '<em>'.text::cutString(html::clean($item->content),120).'...</em></p></dd>';
134                    } else {
135                         $latest_news .=
136                         '<dt>'.$dt.'</dt>'.
137                         '<dd>'.dt::dt2str(__('%d %B %Y:'),$item->pubdate,'Europe/Paris').'</dd>';
138                    }
139                    $i++;
140                    if ($i > 2) { break; }
141               }
142               $latest_news .= '</dl></div>';
143               $__dashboard_items[$dashboardItem][] = $latest_news;
144               $dashboardItem++;
145          }
146     }
147     catch (Exception $e) {}
148}
149
150# Documentation links
151if ($core->auth->user_prefs->dashboard->doclinks) {
152     if (!empty($__resources['doc']))
153     {
154          $doc_links = '<div class="box small dc-box"><h3>'.__('Documentation and support').'</h3><ul>';
155
156          foreach ($__resources['doc'] as $k => $v) {
157               $doc_links .= '<li><a class="outgoing" href="'.$v.'" title="'.$k.'">'.$k.
158               ' <img src="images/outgoing-blue.png" alt="" /></a></li>';
159          }
160
161          $doc_links .= '</ul></div>';
162          $__dashboard_items[$dashboardItem][] = $doc_links;
163          $dashboardItem++;
164     }
165}
166
167$core->callBehavior('adminDashboardItems', $core, $__dashboard_items);
168
169# Dashboard content
170$dashboardContents = '';
171$__dashboard_contents = new ArrayObject(array(new ArrayObject,new ArrayObject));
172$core->callBehavior('adminDashboardContents', $core, $__dashboard_contents);
173
174# Editor stuff
175$admin_post_behavior = '';
176if ($core->auth->user_prefs->dashboard->quickentry) {
177     if ($core->auth->check('usage,contentadmin',$core->blog->id))
178     {
179          $post_format = $core->auth->getOption('post_format');
180          $post_editor = $core->auth->getOption('editor');
181          if ($post_editor && !empty($post_editor[$post_format])) {
182               // context is not post because of tags not available
183               $admin_post_behavior = $core->callBehavior('adminPostEditor', $post_editor[$post_format], 'quickentry', array('#post_content'),$post_format);
184          }
185     }
186}
187
188/* DISPLAY
189-------------------------------------------------------- */
190dcPage::open(__('Dashboard'),
191     dcPage::jsLoad('js/_index.js').
192     $admin_post_behavior.
193     # --BEHAVIOR-- adminDashboardHeaders
194     $core->callBehavior('adminDashboardHeaders'),
195     dcPage::breadcrumb(
196          array(
197          __('Dashboard').' : '.html::escapeHTML($core->blog->name) => ''
198          ),
199          array('home_link' =>false)
200     )
201);
202
203# Dotclear updates notifications
204if ($core->auth->isSuperAdmin() && is_readable(DC_DIGESTS))
205{
206     $updater = new dcUpdate(DC_UPDATE_URL,'dotclear',DC_UPDATE_VERSION,DC_TPL_CACHE.'/versions');
207     $new_v = $updater->check(DC_VERSION);
208     $version_info = $new_v ? $updater->getInfoURL() : '';
209
210     if ($updater->getNotify() && $new_v) {
211          echo
212          '<div class="dc-update"><h3>'.sprintf(__('Dotclear %s is available!'),$new_v).'</h3> '.
213          '<p><a class="button submit" href="'.$core->adminurl->get("admin.update").'">'.sprintf(__('Upgrade now'),$new_v).'</a> '.
214          '<a class="button" href="'.$core->adminurl->get("admin.update", array('hide_msg' => 1)).'">'.__('Remind me later').'</a>'.
215          ($version_info ? ' </p>'.
216          '<p class="updt-info"><a href="'.$version_info.'">'.__('Information about this version').'</a>' : '').'</p>'.
217          '</div>';
218     }
219}
220
221if ($core->auth->getInfo('user_default_blog') != $core->blog->id && $core->auth->getBlogCount() > 1) {
222     echo
223     '<p><a href="'.$core->adminurl->get("admin.home",array('default_blog' => 1)).'" class="button">'.__('Make this blog my default blog').'</a></p>';
224}
225
226if ($core->blog->status == 0) {
227     echo '<p class="static-msg">'.__('This blog is offline').'.</p>';
228} elseif ($core->blog->status == -1) {
229     echo '<p class="static-msg">'.__('This blog is removed').'.</p>';
230}
231
232if (!defined('DC_ADMIN_URL') || !DC_ADMIN_URL) {
233     echo
234     '<p class="static-msg">'.
235     sprintf(__('%s is not defined, you should edit your configuration file.'),'DC_ADMIN_URL').
236     ' '.__('See <a href="http://dotclear.org/documentation/2.0/admin/config">documentation</a> for more information.').
237     '</p>';
238}
239
240if (!defined('DC_ADMIN_MAILFROM') || !DC_ADMIN_MAILFROM) {
241     echo
242     '<p class="static-msg">'.
243     sprintf(__('%s is not defined, you should edit your configuration file.'),'DC_ADMIN_MAILFROM').
244     ' '.__('See <a href="http://dotclear.org/documentation/2.0/admin/config">documentation</a> for more information.').
245     '</p>';
246}
247
248$err = array();
249
250# Check cache directory
251if ( $core->auth->isSuperAdmin() ) {
252     if (!is_dir(DC_TPL_CACHE) || !is_writable(DC_TPL_CACHE)) {
253          $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>';
254     }
255} else {
256     if (!is_dir(DC_TPL_CACHE) || !is_writable(DC_TPL_CACHE)) {
257          $err[] = '<p>'.__("The cache directory does not exist or is not writable. You should contact your administrator.").'</p>';
258     }
259}
260
261# Check public directory
262if ( $core->auth->isSuperAdmin() ) {
263     if (!is_dir($core->blog->public_path) || !is_writable($core->blog->public_path)) {
264          $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>';
265     }
266} else {
267     if (!is_dir($core->blog->public_path) || !is_writable($core->blog->public_path)) {
268          $err[] = '<p>'.__("There is no writable root directory for the media manager. You should contact your administrator.").'</p>';
269     }
270}
271
272# Error list
273if (count($err) > 0) {
274     echo '<div class="error"><p><strong>'.__('Error:').'</strong></p>'.
275     '<ul><li>'.implode("</li><li>",$err).'</li></ul></div>';
276}
277
278# Plugins install messages
279if (!empty($plugins_install['success']))
280{
281     echo '<div class="success">'.__('Following plugins have been installed:').'<ul>';
282     foreach ($plugins_install['success'] as $k => $v) {
283          echo '<li>'.$k.'</li>';
284     }
285     echo '</ul></div>';
286}
287if (!empty($plugins_install['failure']))
288{
289     echo '<div class="error">'.__('Following plugins have not been installed:').'<ul>';
290     foreach ($plugins_install['failure'] as $k => $v) {
291          echo '<li>'.$k.' ('.$v.')</li>';
292     }
293     echo '</ul></div>';
294}
295# Errors modules notifications
296if ($core->auth->isSuperAdmin())
297{
298     $list = $core->plugins->getErrors();
299     if (!empty($list)) {
300          echo
301          '<div class="error" id="module-errors" class="error"><p>'.__('Errors have occured with following plugins:').'</p> '.
302          '<ul><li>'.implode("</li>\n<li>", $list).'</li></ul></div>';
303     }
304}
305
306# Dashboard columns (processed first, as we need to know the result before displaying the icons.)
307$dashboardItems = '';
308
309foreach ($__dashboard_items as $i)
310{
311     if ($i->count() > 0)
312     {
313          $dashboardItems .= '';
314          foreach ($i as $v) {
315               $dashboardItems .= $v;
316          }
317          $dashboardItems .= '';
318     }
319}
320
321# Dashboard elements
322echo '<div id="dashboard-main">';
323
324# Dashboard icons
325echo '<div id="icons">';
326foreach ($__dashboard_icons as $i)
327{
328     echo
329     '<p><a href="'.$i[1].'"><img src="'.dc_admin_icon_url($i[2]).'" alt="" />'.
330     '<br /><span>'.$i[0].'</span></a></p>';
331}
332echo '</div>';
333
334if ($core->auth->user_prefs->dashboard->quickentry) {
335     if ($core->auth->check('usage,contentadmin',$core->blog->id))
336     {
337          # Getting categories
338          $categories_combo = dcAdminCombos::getCategoriesCombo(
339               $core->blog->getCategories(array('post_type'=>'post'))
340          );
341
342          echo
343          '<div id="quick">'.
344          '<h3>'.__('Quick entry').sprintf(' &rsaquo; %s',$core->auth->getOption('post_format')).'</h3>'.
345          '<form id="quick-entry" action="'.$core->adminurl->get('admin.post').'" method="post" class="fieldset">'.
346          '<h4>'.__('New entry').'</h4>'.
347          '<p class="col"><label for="post_title" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Title:').'</label>'.
348          form::field('post_title',20,255,'','maximal').
349          '</p>'.
350          '<p class="area"><label class="required" '.
351          'for="post_content"><abbr title="'.__('Required field').'">*</abbr> '.__('Content:').'</label> '.
352          form::textarea('post_content',50,10).
353          '</p>'.
354          '<p><label for="cat_id" class="classic">'.__('Category:').'</label> '.
355          form::combo('cat_id',$categories_combo).'</p>'.
356          ($core->auth->check('categories', $core->blog->id)
357               ? '<div>'.
358               '<p id="new_cat" class="q-cat">'.__('Add a new category').'</p>'.
359               '<p class="q-cat"><label for="new_cat_title">'.__('Title:').'</label> '.
360               form::field('new_cat_title',30,255,'','').'</p>'.
361               '<p class="q-cat"><label for="new_cat_parent">'.__('Parent:').'</label> '.
362               form::combo('new_cat_parent',$categories_combo,'','').
363               '</p>'.
364               '<p class="form-note info clear">'.__('This category will be created when you will save your post.').'</p>'.
365               '</div>'
366               : '').
367          '<p><input type="submit" value="'.__('Save').'" name="save" /> '.
368          ($core->auth->check('publish',$core->blog->id)
369               ? '<input type="hidden" value="'.__('Save and publish').'" name="save-publish" />'
370               : '').
371          $core->formNonce().
372          form::hidden('post_status',-2).
373          form::hidden('post_format',$core->auth->getOption('post_format')).
374          form::hidden('post_excerpt','').
375          form::hidden('post_lang',$core->auth->getInfo('user_lang')).
376          form::hidden('post_notes','').
377          '</p>'.
378          '</form>'.
379          '</div>';
380     }
381}
382
383foreach ($__dashboard_contents as $i)
384{
385     if ($i->count() > 0)
386     {
387          $dashboardContents .= '';
388          foreach ($i as $v) {
389               $dashboardContents .= $v;
390          }
391          $dashboardContents .= '';
392     }
393}
394
395if ($dashboardContents != '' || $dashboardItems != '') {
396     echo
397     '<div id="dashboard-boxes">'.
398     '<div class="db-items">'.$dashboardItems.$dashboardContents.'</div>'.
399     '</div>';
400}
401
402echo '</div>'; #end dashboard-main
403dcPage::helpBlock('core_dashboard');
404dcPage::close();
Note: See TracBrowser for help on using the repository browser.

Sites map