Dotclear

source: plugins/maintenance/_admin.php @ 2163:d41b59b0ae2e

Revision 2163:d41b59b0ae2e, 8.8 KB checked in by Denis Jean-Chirstian <contact@…>, 12 years ago (diff)

Move maintenance configuration to the new plugins configurator

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 -----------------------------------------
12if (!defined('DC_CONTEXT_ADMIN')) { return; }
13
14// Sidebar menu
15$_menu['Plugins']->addItem(
16     __('Maintenance'),
17     'plugin.php?p=maintenance',
18     'index.php?pf=maintenance/icon.png',
19     preg_match('/plugin.php\?p=maintenance(&.*)?$/', $_SERVER['REQUEST_URI']),
20     $core->auth->check('admin', $core->blog->id)
21);
22
23// Admin behaviors
24$core->addBehavior('dcMaintenanceInit', array('dcMaintenanceAdmin', 'dcMaintenanceInit'));
25$core->addBehavior('adminDashboardFavs', array('dcMaintenanceAdmin', 'adminDashboardFavs'));
26$core->addBehavior('adminDashboardFavsIcon', array('dcMaintenanceAdmin', 'adminDashboardFavsIcon'));
27$core->addBehavior('adminDashboardContents', array('dcMaintenanceAdmin', 'adminDashboardItems'));
28$core->addBehavior('adminDashboardOptionsForm',   array('dcMaintenanceAdmin',   'adminDashboardOptionsForm'));
29$core->addBehavior('adminAfterDashboardOptionsUpdate', array('dcMaintenanceAdmin',   'adminAfterDashboardOptionsUpdate'));
30$core->addBehavior('adminPageHelpBlock',     array('dcMaintenanceAdmin',   'adminPageHelpBlock'));
31$core->addBehavior('pluginsToolsHeaders',    array('dcMaintenanceAdmin',   'pluginsToolsHeaders'));
32
33/**
34@ingroup PLUGIN_MAINTENANCE
35@nosubgrouping
36@brief Maintenance plugin admin class.
37
38Group of methods used on behaviors.
39*/
40class dcMaintenanceAdmin
41{
42     /**
43      * Register default tasks.
44      *
45      * @param $maintenance   <b>dcMaintenance</b>     dcMaintenance instance
46      */
47      public static function dcMaintenanceInit($maintenance)
48     {
49          $maintenance
50          ->addTab('maintenance', __('Servicing'), array('summary' => __('Tools to maintain the performance of your blogs.')))
51          ->addTab('backup', __('Backup'), array('summary' => __('Tools to back up your content.')))
52          ->addTab('dev', __('Development'), array('summary' => __('Tools to assist in development of plugins, themes and core.')))
53
54          ->addGroup('optimize', __('Optimize'))
55          ->addGroup('index', __('Count and index'))
56          ->addGroup('purge', __('Purge'))
57          ->addGroup('other', __('Other'))
58          ->addGroup('zipblog', __('Current blog'))
59          ->addGroup('zipfull', __('All blogs'))
60
61          ->addGroup('l10n', __('Translations'), array('summary' => __('Maintain translations')))
62
63          ->addTask('dcMaintenanceCache')
64          ->addTask('dcMaintenanceIndexposts')
65          ->addTask('dcMaintenanceIndexcomments')
66          ->addTask('dcMaintenanceCountcomments')
67          ->addTask('dcMaintenanceSynchpostsmeta')
68          ->addTask('dcMaintenanceLogs')
69          ->addTask('dcMaintenanceVacuum')
70          ->addTask('dcMaintenanceZipmedia')
71          ->addTask('dcMaintenanceZiptheme')
72          ;
73     }
74
75     /**
76      * Dashboard favs.
77      *
78      * @param $core     <b>dcCore</b>  dcCore instance
79      * @param $favs     <b>arrayObject</b>  Array of favs
80      */
81     public static function adminDashboardFavs($core, $favs)
82     {
83          $favs['maintenance'] = new ArrayObject(array(
84               'maintenance',
85               'Maintenance',
86               'plugin.php?p=maintenance',
87               'index.php?pf=maintenance/icon.png',
88               'index.php?pf=maintenance/icon-big.png',
89               null,null,null
90          ));
91     }
92
93     /**
94      * Dashboard favs icon.
95      *
96      * This updates maintenance fav icon text
97      * if there are tasks required maintenance.
98      *
99      * @param $core     <b>dcCore</b>  dcCore instance
100      * @param $name     <b>string</b>  Current fav name
101      * @param $icon     <b>arrayObject</b>  Current fav attributes
102      */
103     public static function adminDashboardFavsIcon($core, $name, $icon)
104     {
105          // Check icon
106          if ($name !== 'maintenance') {
107               return null;
108          }
109
110          // Check user option
111          $core->auth->user_prefs->addWorkspace('maintenance');
112          if (!$core->auth->user_prefs->maintenance->dashboard_icon) {
113               return null;
114          }
115
116          // Check expired tasks
117          $maintenance = new dcMaintenance($core);
118          $count = 0;
119          foreach($maintenance->getTasks() as $t)
120          {
121               if ($t->expired() !== false){
122                    $count++;
123               }
124          }
125
126          if (!$count) {
127               return null;
128          }
129
130          $icon[0] .= '<br />'.sprintf(__('One task to execute', '%s tasks to execute', $count), $count);
131     }
132
133     /**
134      * Dashboard items stack.
135      *
136      * @param $core     <b>dcCore</b>  dcCore instance
137      * @param $items    <b>arrayObject</b>  Dashboard items
138      */
139     public static function adminDashboardItems($core, $items)
140     {
141          $core->auth->user_prefs->addWorkspace('maintenance');
142          if (!$core->auth->user_prefs->maintenance->dashboard_item) {
143               return null;
144          }
145
146          $maintenance = new dcMaintenance($core);
147
148          $lines = array();
149          foreach($maintenance->getTasks() as $t)
150          {
151               $ts = $t->expired();
152               if ($ts === false){
153                    continue;
154               }
155
156               $lines[] = 
157               '<li title="'.($ts === null ?
158                    __('This task has never been executed.')
159                    :
160                    sprintf(__('Last execution of this task was on %s.'),
161                         dt::dt2str($core->blog->settings->system->date_format, $ts).' '.
162                         dt::dt2str($core->blog->settings->system->time_format, $ts)
163                    )
164               ).'">'.$t->task().'</li>';
165          }
166
167          if (empty($lines)) {
168               return null;
169          }
170
171          $items[] = new ArrayObject(array(
172               '<div id="maintenance-expired" class="box small">'.
173               '<h3><img src="index.php?pf=maintenance/icon-small.png" alt="" /> '.__('Maintenance').'</h3>'.
174               '<p class="warning no-margin">'.sprintf(__('There is a task to execute.', 'There are %s tasks to execute.', count($lines)), count($lines)).'</p>'.
175               '<ul>'.implode('',$lines).'</ul>'.
176               '<p><a href="plugin.php?p=maintenance">'.__('Manage tasks').'</a></p>'.
177               '</div>'
178               ));
179     }
180
181     /**
182      * User preferences form.
183      *
184      * This add options for superadmin user
185      * to show or not expired taks.
186      *
187      * @param $args     <b>object</b>  dcCore instance or record
188      */
189     public static function adminDashboardOptionsForm($core)
190     {
191          $core->auth->user_prefs->addWorkspace('maintenance');
192
193          echo
194          '<div class="fieldset">'.
195          '<h4>'.__('Maintenance').'</h4>'.
196
197          '<p><label for="maintenance_dashboard_icon" class="classic">'.
198          form::checkbox('maintenance_dashboard_icon', 1, $core->auth->user_prefs->maintenance->dashboard_icon).
199          __('Display count of late tasks on maintenance dashboard icon').'</label></p>'.
200
201          '<p><label for="maintenance_dashboard_item" class="classic">'.
202          form::checkbox('maintenance_dashboard_item', 1, $core->auth->user_prefs->maintenance->dashboard_item).
203          __('Display list of late tasks on dashboard items').'</label></p>'.
204
205          '</div>';
206     }
207
208     /**
209      * User preferences update.
210      *
211      * @param $user_id  <b>string</b>  User ID
212      */
213     public static function adminAfterDashboardOptionsUpdate($user_id=null)
214     {
215          global $core;
216
217          if (is_null($user_id)) {
218               return null;
219          }
220
221          $core->auth->user_prefs->addWorkspace('maintenance');
222          $core->auth->user_prefs->maintenance->put('dashboard_icon', !empty($_POST['maintenance_dashboard_icon']), 'boolean');
223          $core->auth->user_prefs->maintenance->put('dashboard_item', !empty($_POST['maintenance_dashboard_item']), 'boolean');
224     }
225
226     /**
227      * Build a well sorted help for tasks.
228      *
229      * This method is not so good if used with lot of tranlsations
230      * as it grows memory usage and translations files size,
231      * it is better to use help ressource files
232      * but keep it for exemple of how to use behavior adminPageHelpBlock.
233      * Cheers, JC
234      *
235      * @param $block    <b>arrayObject</b>  Called helpblocks
236      */
237     public static function adminPageHelpBlock($blocks)
238     {
239          $found = false;
240          foreach($blocks as $block) {
241               if ($block == 'maintenancetasks') {
242                    $found = true;
243                    break;
244               }
245          }
246          if (!$found) {
247               return null;
248          }
249
250          $maintenance = new dcMaintenance($GLOBALS['core']);
251
252          $res_tab = '';
253          foreach($maintenance->getTabs() as $tab_obj)
254          {
255               $res_group = '';
256               foreach($maintenance->getGroups() as $group_obj)
257               {
258                    $res_task = '';
259                    foreach($maintenance->getTasks() as $t)
260                    {
261                         if ($t->group() != $group_obj->id() 
262                          || $t->tab() != $tab_obj->id()) {
263                              continue;
264                         }
265                         if (($desc = $t->description()) != '') {
266                              $res_task .= 
267                              '<dt>'.$t->task().'</dt>'.
268                              '<dd>'.$desc.'</dd>';
269                         }
270                    }
271                    if (!empty($res_task)) {
272                         $desc = $group_obj->description ? $group_obj->description : $group_obj->summary;
273
274                         $res_group .= 
275                         '<h5>'.$group_obj->name().'</h5>'.
276                         ($desc ? '<p>'.$desc.'</p>' : '').
277                         '<dl>'.$res_task.'</dl>';
278                    }
279               }
280               if (!empty($res_group)) {
281                    $desc = $tab_obj->description ? $tab_obj->description : $tab_obj->summary;
282
283                    $res_tab .= 
284                    '<h4>'.$tab_obj->name().'</h4>'.
285                    ($desc ? '<p>'.$desc.'</p>' : '').
286                    $res_group;
287               }
288          }
289          if (!empty($res_tab)) {
290               $res = new ArrayObject();
291               $res->content = $res_tab;
292               $blocks[] = $res;
293          }
294     }
295
296     /**
297      * Add javascript for plugin configuration.
298      *
299      * @param $core     <b>dcCore</b>  dcCore instance
300      * @param $module   <b>mixed</b>   Module ID or false if none
301      * @return     <b>string</b>  Header code for js inclusion
302      */
303     public static function pluginsToolsHeaders($core, $module)
304     {
305          if ($module == 'maintenance') {
306               return dcPage::jsLoad('index.php?pf=maintenance/js/settings.js');
307          }
308     }
309}
Note: See TracBrowser for help on using the repository browser.

Sites map