Dotclear

source: plugins/maintenance/_admin.php @ 2196:234c9e083cfb

Revision 2196:234c9e083cfb, 8.9 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 -----------------------------------------
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          $icon[2] = 'index.php?pf=maintenance/icon-big-update.png';
132     }
133
134     /**
135      * Dashboard items stack.
136      *
137      * @param $core     <b>dcCore</b>  dcCore instance
138      * @param $items    <b>arrayObject</b>  Dashboard items
139      */
140     public static function adminDashboardItems($core, $items)
141     {
142          $core->auth->user_prefs->addWorkspace('maintenance');
143          if (!$core->auth->user_prefs->maintenance->dashboard_item) {
144               return null;
145          }
146
147          $maintenance = new dcMaintenance($core);
148
149          $lines = array();
150          foreach($maintenance->getTasks() as $t)
151          {
152               $ts = $t->expired();
153               if ($ts === false){
154                    continue;
155               }
156
157               $lines[] = 
158               '<li title="'.($ts === null ?
159                    __('This task has never been executed.')
160                    :
161                    sprintf(__('Last execution of this task was on %s.'),
162                         dt::dt2str($core->blog->settings->system->date_format, $ts).' '.
163                         dt::dt2str($core->blog->settings->system->time_format, $ts)
164                    )
165               ).'">'.$t->task().'</li>';
166          }
167
168          if (empty($lines)) {
169               return null;
170          }
171
172          $items[] = new ArrayObject(array(
173               '<div id="maintenance-expired" class="box small">'.
174               '<h3><img src="index.php?pf=maintenance/icon-small.png" alt="" /> '.__('Maintenance').'</h3>'.
175               '<p class="warning no-margin">'.sprintf(__('There is a task to execute.', 'There are %s tasks to execute.', count($lines)), count($lines)).'</p>'.
176               '<ul>'.implode('',$lines).'</ul>'.
177               '<p><a href="plugin.php?p=maintenance">'.__('Manage tasks').'</a></p>'.
178               '</div>'
179               ));
180     }
181
182     /**
183      * User preferences form.
184      *
185      * This add options for superadmin user
186      * to show or not expired taks.
187      *
188      * @param $args     <b>object</b>  dcCore instance or record
189      */
190     public static function adminDashboardOptionsForm($core)
191     {
192          $core->auth->user_prefs->addWorkspace('maintenance');
193
194          echo
195          '<div class="fieldset">'.
196          '<h4>'.__('Maintenance').'</h4>'.
197
198          '<p><label for="maintenance_dashboard_icon" class="classic">'.
199          form::checkbox('maintenance_dashboard_icon', 1, $core->auth->user_prefs->maintenance->dashboard_icon).
200          __('Display count of late tasks on maintenance dashboard icon').'</label></p>'.
201
202          '<p><label for="maintenance_dashboard_item" class="classic">'.
203          form::checkbox('maintenance_dashboard_item', 1, $core->auth->user_prefs->maintenance->dashboard_item).
204          __('Display list of late tasks on dashboard items').'</label></p>'.
205
206          '</div>';
207     }
208
209     /**
210      * User preferences update.
211      *
212      * @param $user_id  <b>string</b>  User ID
213      */
214     public static function adminAfterDashboardOptionsUpdate($user_id=null)
215     {
216          global $core;
217
218          if (is_null($user_id)) {
219               return null;
220          }
221
222          $core->auth->user_prefs->addWorkspace('maintenance');
223          $core->auth->user_prefs->maintenance->put('dashboard_icon', !empty($_POST['maintenance_dashboard_icon']), 'boolean');
224          $core->auth->user_prefs->maintenance->put('dashboard_item', !empty($_POST['maintenance_dashboard_item']), 'boolean');
225     }
226
227     /**
228      * Build a well sorted help for tasks.
229      *
230      * This method is not so good if used with lot of tranlsations
231      * as it grows memory usage and translations files size,
232      * it is better to use help ressource files
233      * but keep it for exemple of how to use behavior adminPageHelpBlock.
234      * Cheers, JC
235      *
236      * @param $block    <b>arrayObject</b>  Called helpblocks
237      */
238     public static function adminPageHelpBlock($blocks)
239     {
240          $found = false;
241          foreach($blocks as $block) {
242               if ($block == 'maintenancetasks') {
243                    $found = true;
244                    break;
245               }
246          }
247          if (!$found) {
248               return null;
249          }
250
251          $maintenance = new dcMaintenance($GLOBALS['core']);
252
253          $res_tab = '';
254          foreach($maintenance->getTabs() as $tab_obj)
255          {
256               $res_group = '';
257               foreach($maintenance->getGroups() as $group_obj)
258               {
259                    $res_task = '';
260                    foreach($maintenance->getTasks() as $t)
261                    {
262                         if ($t->group() != $group_obj->id() 
263                          || $t->tab() != $tab_obj->id()) {
264                              continue;
265                         }
266                         if (($desc = $t->description()) != '') {
267                              $res_task .= 
268                              '<dt>'.$t->task().'</dt>'.
269                              '<dd>'.$desc.'</dd>';
270                         }
271                    }
272                    if (!empty($res_task)) {
273                         $desc = $group_obj->description ? $group_obj->description : $group_obj->summary;
274
275                         $res_group .= 
276                         '<h5>'.$group_obj->name().'</h5>'.
277                         ($desc ? '<p>'.$desc.'</p>' : '').
278                         '<dl>'.$res_task.'</dl>';
279                    }
280               }
281               if (!empty($res_group)) {
282                    $desc = $tab_obj->description ? $tab_obj->description : $tab_obj->summary;
283
284                    $res_tab .= 
285                    '<h4>'.$tab_obj->name().'</h4>'.
286                    ($desc ? '<p>'.$desc.'</p>' : '').
287                    $res_group;
288               }
289          }
290          if (!empty($res_tab)) {
291               $res = new ArrayObject();
292               $res->content = $res_tab;
293               $blocks[] = $res;
294          }
295     }
296
297     /**
298      * Add javascript for plugin configuration.
299      *
300      * @param $core     <b>dcCore</b>  dcCore instance
301      * @param $module   <b>mixed</b>   Module ID or false if none
302      * @return     <b>string</b>  Header code for js inclusion
303      */
304     public static function pluginsToolsHeaders($core, $module)
305     {
306          if ($module == 'maintenance') {
307               return dcPage::jsLoad('index.php?pf=maintenance/js/settings.js');
308          }
309     }
310}
Note: See TracBrowser for help on using the repository browser.

Sites map