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 | if (!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->isSuperAdmin() |
---|
21 | ); |
---|
22 | |
---|
23 | // Admin behaviors |
---|
24 | $core->addBehavior('dcMaintenanceRegister', array('dcMaintenanceAdmin', 'dcMaintenanceRegister')); |
---|
25 | $core->addBehavior('adminPreferencesHeaders', array('dcMaintenanceAdmin', 'adminPreferencesHeaders')); |
---|
26 | $core->addBehavior('adminDashboardFavs', array('dcMaintenanceAdmin', 'adminDashboardFavs')); |
---|
27 | $core->addBehavior('adminDashboardFavsIcon', array('dcMaintenanceAdmin', 'adminDashboardFavsIcon')); |
---|
28 | $core->addBehavior('adminDashboardItems', array('dcMaintenanceAdmin', 'adminDashboardItems')); |
---|
29 | $core->addBehavior('adminPreferencesForm', array('dcMaintenanceAdmin', 'adminPreferencesForm')); |
---|
30 | $core->addBehavior('adminBeforeUserOptionsUpdate', array('dcMaintenanceAdmin', 'adminBeforeUserOptionsUpdate')); |
---|
31 | |
---|
32 | /** |
---|
33 | @ingroup PLUGIN_MAINTENANCE |
---|
34 | @nosubgrouping |
---|
35 | @brief Maintenance plugin admin class. |
---|
36 | |
---|
37 | Group of methods used on behaviors. |
---|
38 | */ |
---|
39 | class dcMaintenanceAdmin |
---|
40 | { |
---|
41 | /** |
---|
42 | * Register default tasks. |
---|
43 | * |
---|
44 | * @param $core <b>dcCore</b> dcCore instance |
---|
45 | * @param $tasks <b>arrayObject</b> Array of tasks to register |
---|
46 | * @param $groups <b>arrayObject</b> Array of groups to register |
---|
47 | * @param $tabs <b>arrayObject</b> Array of tabs to register |
---|
48 | */ |
---|
49 | public static function dcMaintenanceRegister($core, $tasks, $groups, $tabs) |
---|
50 | { |
---|
51 | $tabs['maintenance'] = __('Servicing'); |
---|
52 | $tabs['backup'] = __('Backup'); |
---|
53 | |
---|
54 | $groups['optimize'] = __('Optimize'); |
---|
55 | $groups['index'] = __('Count and index'); |
---|
56 | $groups['purge'] = __('Purge'); |
---|
57 | $groups['other'] = __('Other'); |
---|
58 | $groups['zipblog'] = __('Compressed file for current blog'); |
---|
59 | $groups['zipfull'] = __('Compressed file for all blogs'); |
---|
60 | |
---|
61 | $tasks[] = 'dcMaintenanceCache'; |
---|
62 | $tasks[] = 'dcMaintenanceCountcomments'; |
---|
63 | $tasks[] = 'dcMaintenanceIndexcomments'; |
---|
64 | $tasks[] = 'dcMaintenanceIndexposts'; |
---|
65 | $tasks[] = 'dcMaintenanceLogs'; |
---|
66 | $tasks[] = 'dcMaintenanceVacuum'; |
---|
67 | $tasks[] = 'dcMaintenanceZipmedia'; |
---|
68 | $tasks[] = 'dcMaintenanceZiptheme'; |
---|
69 | } |
---|
70 | |
---|
71 | /** |
---|
72 | * Dashboard headers. |
---|
73 | * |
---|
74 | * Add ajavascript to toggle tasks list. |
---|
75 | */ |
---|
76 | public static function adminPreferencesHeaders() |
---|
77 | { |
---|
78 | return dcPage::jsLoad('index.php?pf=maintenance/js/preferences.js'); |
---|
79 | } |
---|
80 | |
---|
81 | /** |
---|
82 | * Dashboard favs. |
---|
83 | * |
---|
84 | * @param $core <b>dcCore</b> dcCore instance |
---|
85 | * @param $favs <b>arrayObject</b> Array of favs |
---|
86 | */ |
---|
87 | public static function adminDashboardFavs($core, $favs) |
---|
88 | { |
---|
89 | $favs['maintenance'] = new ArrayObject(array( |
---|
90 | 'maintenance', |
---|
91 | 'Maintenance', |
---|
92 | 'plugin.php?p=maintenance', |
---|
93 | 'index.php?pf=maintenance/icon.png', |
---|
94 | 'index.php?pf=maintenance/icon-big.png', |
---|
95 | null,null,null |
---|
96 | )); |
---|
97 | } |
---|
98 | |
---|
99 | /** |
---|
100 | * Dashboard favs icon. |
---|
101 | * |
---|
102 | * This updates maintenance fav icon text |
---|
103 | * if there are tasks required maintenance. |
---|
104 | * |
---|
105 | * @param $core <b>dcCore</b> dcCore instance |
---|
106 | * @param $name <b>string</b> Current fav name |
---|
107 | * @param $icon <b>arrayObject</b> Current fav attributes |
---|
108 | */ |
---|
109 | public static function adminDashboardFavsIcon($core, $name, $icon) |
---|
110 | { |
---|
111 | // Check icon |
---|
112 | if ($name !== 'maintenance') { |
---|
113 | return null; |
---|
114 | } |
---|
115 | |
---|
116 | // Check user option |
---|
117 | $core->auth->user_prefs->addWorkspace('maintenance'); |
---|
118 | if (!$core->auth->user_prefs->maintenance->dashboard_icon) { |
---|
119 | return null; |
---|
120 | } |
---|
121 | |
---|
122 | // Check expired tasks |
---|
123 | $maintenance = new dcMaintenance($core); |
---|
124 | $expired = $maintenance->getExpired(); |
---|
125 | $expired = count($expired); |
---|
126 | if (!$expired) { |
---|
127 | return null; |
---|
128 | } |
---|
129 | |
---|
130 | $icon[0] .= '<br />'.sprintf(__('One task to update', '%s tasks to update', $expired), $expired); |
---|
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 | $tasks = $maintenance->getExpired(); |
---|
148 | if (empty($tasks)) { |
---|
149 | return null; |
---|
150 | } |
---|
151 | |
---|
152 | $lines = array(); |
---|
153 | foreach($tasks as $id => $ts) { |
---|
154 | $lines[$ts] = |
---|
155 | '<li title="'.sprintf(__('Last updated on %s'), |
---|
156 | dt::dt2str($core->blog->settings->system->date_format, $ts).' '. |
---|
157 | dt::dt2str($core->blog->settings->system->time_format, $ts) |
---|
158 | ).'">'.$maintenance->getTask($id)->task().'</li>'; |
---|
159 | } |
---|
160 | ksort($lines); |
---|
161 | |
---|
162 | $items[] = new ArrayObject(array( |
---|
163 | '<div id="maintenance-expired">'. |
---|
164 | '<h3><img src="index.php?pf=maintenance/icon.png" alt="" /> '.__('Maintenance').'</h3>'. |
---|
165 | '<p>'.sprintf(__('There is a task to update.', 'There are %s tasks to update.', count($tasks)), count($tasks)).'</p>'. |
---|
166 | '<ul>'.implode('',$lines).'</ul>'. |
---|
167 | '<p><a href="plugin.php?p=maintenance">'.__('Manage task').'</a></p>'. |
---|
168 | '</div>' |
---|
169 | )); |
---|
170 | } |
---|
171 | |
---|
172 | /** |
---|
173 | * User preferences form. |
---|
174 | * |
---|
175 | * This add options for superadmin user |
---|
176 | * to show or not expired taks. |
---|
177 | * |
---|
178 | * @param $args <b>object</b> dcCore instance or record |
---|
179 | */ |
---|
180 | public static function adminPreferencesForm($core) |
---|
181 | { |
---|
182 | $core->auth->user_prefs->addWorkspace('maintenance'); |
---|
183 | $maintenance = new dcMaintenance($core); |
---|
184 | |
---|
185 | $tasks = $maintenance->getTasks(); |
---|
186 | if (empty($tasks)) { |
---|
187 | return null; |
---|
188 | } |
---|
189 | |
---|
190 | $full_combo_ts = array_merge(array( |
---|
191 | __('Use different periods for each task') => 'seperate'), |
---|
192 | self::comboTs() |
---|
193 | ); |
---|
194 | |
---|
195 | $task_combo_ts = array_merge(array( |
---|
196 | __('Never') => 0), |
---|
197 | self::comboTs() |
---|
198 | ); |
---|
199 | |
---|
200 | echo |
---|
201 | '<div class="fieldset">'. |
---|
202 | '<h4>'.__('Maintenance').'</h4>'. |
---|
203 | |
---|
204 | '<div class="two-boxes">'. |
---|
205 | |
---|
206 | '<p><label for="maintenance_dashboard_icon" class="classic">'. |
---|
207 | form::checkbox('maintenance_dashboard_icon', 1, $core->auth->user_prefs->maintenance->dashboard_icon). |
---|
208 | __('Display count of expired tasks on maintenance dashboard icon').'</label></p>'. |
---|
209 | |
---|
210 | '<p><label for="maintenance_dashboard_item" class="classic">'. |
---|
211 | form::checkbox('maintenance_dashboard_item', 1, $core->auth->user_prefs->maintenance->dashboard_item). |
---|
212 | __('Display list of expired tasks on dashboard contents').'</label></p>'. |
---|
213 | |
---|
214 | '<p><label for="maintenance_plugin_message" class="classic">'. |
---|
215 | form::checkbox('maintenance_plugin_message', 1, $core->auth->user_prefs->maintenance->plugin_message). |
---|
216 | __('Display alert message of expired tasks on plugin page').'</label></p>'. |
---|
217 | |
---|
218 | '</div>'. |
---|
219 | |
---|
220 | '<div class="two-boxes">'. |
---|
221 | |
---|
222 | '<p><label for="maintenance_recall_time">'.__('Recall time for all tasks').'</label>'. |
---|
223 | form::combo('maintenance_recall_time', $full_combo_ts, 'seperate', 'recall-for-all'). |
---|
224 | '</p>'. |
---|
225 | |
---|
226 | '</div>'. |
---|
227 | |
---|
228 | '<div id="maintenance-recall-time">'. |
---|
229 | '<h5>'.__('Recall time per task').'</h5>'; |
---|
230 | |
---|
231 | foreach($tasks as $task) { |
---|
232 | echo |
---|
233 | '<div class="two-boxes">'. |
---|
234 | |
---|
235 | '<p><label for="maintenance_ts_'.$task->id().'">'.$task->task().'</label>'. |
---|
236 | form::combo('maintenance_ts_'.$task->id(), $task_combo_ts, $task->ts(), 'recall-per-task'). |
---|
237 | '</p>'. |
---|
238 | |
---|
239 | '</div>'; |
---|
240 | } |
---|
241 | |
---|
242 | echo |
---|
243 | '</div>'. |
---|
244 | '</div>'; |
---|
245 | } |
---|
246 | |
---|
247 | /** |
---|
248 | * User preferences update. |
---|
249 | * |
---|
250 | * @param $cur <b>cursor</b> Cursor of user options |
---|
251 | * @param $user_id <b>string</b> User ID |
---|
252 | */ |
---|
253 | public static function adminBeforeUserOptionsUpdate($cur, $user_id=null) |
---|
254 | { |
---|
255 | global $core; |
---|
256 | |
---|
257 | if (is_null($user_id)) { |
---|
258 | return null; |
---|
259 | } |
---|
260 | |
---|
261 | $maintenance = new dcMaintenance($core); |
---|
262 | $tasks = $maintenance->getTasks(); |
---|
263 | if (empty($tasks)) { |
---|
264 | return null; |
---|
265 | } |
---|
266 | |
---|
267 | $core->auth->user_prefs->addWorkspace('maintenance'); |
---|
268 | $core->auth->user_prefs->maintenance->put('dashboard_icon', !empty($_POST['maintenance_dashboard_icon']), 'boolean'); |
---|
269 | $core->auth->user_prefs->maintenance->put('dashboard_item', !empty($_POST['maintenance_dashboard_item']), 'boolean'); |
---|
270 | $core->auth->user_prefs->maintenance->put('plugin_message', !empty($_POST['maintenance_plugin_message']), 'boolean'); |
---|
271 | |
---|
272 | foreach($tasks as $task) { |
---|
273 | if ($_POST['maintenance_recall_time'] == 'seperate') { |
---|
274 | $ts = empty($_POST['maintenance_ts_'.$task->id()]) ? 0 : $_POST['maintenance_ts_'.$task->id()]; |
---|
275 | } |
---|
276 | else { |
---|
277 | $ts = $_POST['maintenance_recall_time']; |
---|
278 | } |
---|
279 | $core->auth->user_prefs->maintenance->put('ts_'.$task->id(), abs((integer) $ts), 'integer'); |
---|
280 | } |
---|
281 | } |
---|
282 | |
---|
283 | /* @ignore */ |
---|
284 | public static function comboTs() |
---|
285 | { |
---|
286 | return array( |
---|
287 | __('Every week') => 604800, |
---|
288 | __('Every two weeks') => 1209600, |
---|
289 | __('Every month') => 2592000, |
---|
290 | __('Every two months') => 5184000 |
---|
291 | ); |
---|
292 | } |
---|
293 | } |
---|