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('adminDashboardFavs', array('dcMaintenanceAdmin', 'adminDashboardFavs')); |
---|
26 | $core->addBehavior('adminDashboardFavsIcon', array('dcMaintenanceAdmin', 'adminDashboardFavsIcon')); |
---|
27 | $core->addBehavior('adminDashboardItems', array('dcMaintenanceAdmin', 'adminDashboardItems')); |
---|
28 | $core->addBehavior('adminDashboardOptionsForm', array('dcMaintenanceAdmin', 'adminDashboardOptionsForm')); |
---|
29 | $core->addBehavior('adminAfterDashboardOptionsUpdate', array('dcMaintenanceAdmin', 'adminAfterDashboardOptionsUpdate')); |
---|
30 | |
---|
31 | /** |
---|
32 | @ingroup PLUGIN_MAINTENANCE |
---|
33 | @nosubgrouping |
---|
34 | @brief Maintenance plugin admin class. |
---|
35 | |
---|
36 | Group of methods used on behaviors. |
---|
37 | */ |
---|
38 | class dcMaintenanceAdmin |
---|
39 | { |
---|
40 | /** |
---|
41 | * Register default tasks. |
---|
42 | * |
---|
43 | * @param $core <b>dcCore</b> dcCore instance |
---|
44 | * @param $tasks <b>arrayObject</b> Array of tasks to register |
---|
45 | * @param $groups <b>arrayObject</b> Array of groups to register |
---|
46 | * @param $tabs <b>arrayObject</b> Array of tabs to register |
---|
47 | */ |
---|
48 | public static function dcMaintenanceRegister($core, $tasks, $groups, $tabs) |
---|
49 | { |
---|
50 | $tabs['maintenance'] = __('Servicing'); |
---|
51 | $tabs['backup'] = __('Backup'); |
---|
52 | |
---|
53 | $groups['optimize'] = __('Optimize'); |
---|
54 | $groups['index'] = __('Count and index'); |
---|
55 | $groups['purge'] = __('Purge'); |
---|
56 | $groups['other'] = __('Other'); |
---|
57 | $groups['zipblog'] = __('Compressed file for current blog'); |
---|
58 | $groups['zipfull'] = __('Compressed file for all blogs'); |
---|
59 | |
---|
60 | $tasks[] = 'dcMaintenanceCache'; |
---|
61 | $tasks[] = 'dcMaintenanceIndexposts'; |
---|
62 | $tasks[] = 'dcMaintenanceIndexcomments'; |
---|
63 | $tasks[] = 'dcMaintenanceCountcomments'; |
---|
64 | $tasks[] = 'dcMaintenanceLogs'; |
---|
65 | $tasks[] = 'dcMaintenanceVacuum'; |
---|
66 | $tasks[] = 'dcMaintenanceZipmedia'; |
---|
67 | $tasks[] = 'dcMaintenanceZiptheme'; |
---|
68 | } |
---|
69 | |
---|
70 | /** |
---|
71 | * Dashboard favs. |
---|
72 | * |
---|
73 | * @param $core <b>dcCore</b> dcCore instance |
---|
74 | * @param $favs <b>arrayObject</b> Array of favs |
---|
75 | */ |
---|
76 | public static function adminDashboardFavs($core, $favs) |
---|
77 | { |
---|
78 | $favs['maintenance'] = new ArrayObject(array( |
---|
79 | 'maintenance', |
---|
80 | 'Maintenance', |
---|
81 | 'plugin.php?p=maintenance', |
---|
82 | 'index.php?pf=maintenance/icon.png', |
---|
83 | 'index.php?pf=maintenance/icon-big.png', |
---|
84 | null,null,null |
---|
85 | )); |
---|
86 | } |
---|
87 | |
---|
88 | /** |
---|
89 | * Dashboard favs icon. |
---|
90 | * |
---|
91 | * This updates maintenance fav icon text |
---|
92 | * if there are tasks required maintenance. |
---|
93 | * |
---|
94 | * @param $core <b>dcCore</b> dcCore instance |
---|
95 | * @param $name <b>string</b> Current fav name |
---|
96 | * @param $icon <b>arrayObject</b> Current fav attributes |
---|
97 | */ |
---|
98 | public static function adminDashboardFavsIcon($core, $name, $icon) |
---|
99 | { |
---|
100 | // Check icon |
---|
101 | if ($name !== 'maintenance') { |
---|
102 | return null; |
---|
103 | } |
---|
104 | |
---|
105 | // Check user option |
---|
106 | $core->auth->user_prefs->addWorkspace('maintenance'); |
---|
107 | if (!$core->auth->user_prefs->maintenance->dashboard_icon) { |
---|
108 | return null; |
---|
109 | } |
---|
110 | |
---|
111 | // Check expired tasks |
---|
112 | $maintenance = new dcMaintenance($core); |
---|
113 | $count = 0; |
---|
114 | foreach($maintenance->getTasks() as $t) |
---|
115 | { |
---|
116 | if ($t->expired() !== false){ |
---|
117 | $count++; |
---|
118 | } |
---|
119 | } |
---|
120 | |
---|
121 | if (!$count) { |
---|
122 | return null; |
---|
123 | } |
---|
124 | |
---|
125 | $icon[0] .= '<br />'.sprintf(__('One task to execute', '%s tasks to execute', $count), $count); |
---|
126 | } |
---|
127 | |
---|
128 | /** |
---|
129 | * Dashboard items stack. |
---|
130 | * |
---|
131 | * @param $core <b>dcCore</b> dcCore instance |
---|
132 | * @param $items <b>arrayObject</b> Dashboard items |
---|
133 | */ |
---|
134 | public static function adminDashboardItems($core, $items) |
---|
135 | { |
---|
136 | $core->auth->user_prefs->addWorkspace('maintenance'); |
---|
137 | if (!$core->auth->user_prefs->maintenance->dashboard_item) { |
---|
138 | return null; |
---|
139 | } |
---|
140 | |
---|
141 | $maintenance = new dcMaintenance($core); |
---|
142 | |
---|
143 | $lines = array(); |
---|
144 | foreach($maintenance->getTasks() as $t) |
---|
145 | { |
---|
146 | $ts = $t->expired(); |
---|
147 | if ($ts === false){ |
---|
148 | continue; |
---|
149 | } |
---|
150 | |
---|
151 | $lines[] = |
---|
152 | '<li title="'.($ts === null ? |
---|
153 | __('This task has never been executed.') |
---|
154 | : |
---|
155 | sprintf(__('Last execution of this task was on %s.'), |
---|
156 | dt::dt2str($core->blog->settings->system->date_format, $ts).' '. |
---|
157 | dt::dt2str($core->blog->settings->system->time_format, $ts) |
---|
158 | ) |
---|
159 | ).'">'.$t->task().'</li>'; |
---|
160 | } |
---|
161 | |
---|
162 | if (empty($lines)) { |
---|
163 | return null; |
---|
164 | } |
---|
165 | |
---|
166 | $items[] = new ArrayObject(array( |
---|
167 | '<div id="maintenance-expired">'. |
---|
168 | '<h3><img src="index.php?pf=maintenance/icon.png" alt="" /> '.__('Maintenance').'</h3>'. |
---|
169 | '<p class="warn">'.sprintf(__('There is a task to execute.', 'There are %s tasks to execute.', count($lines)), count($lines)).'</p>'. |
---|
170 | '<ul>'.implode('',$lines).'</ul>'. |
---|
171 | '<p><a href="plugin.php?p=maintenance">'.__('Manage tasks').'</a></p>'. |
---|
172 | '</div>' |
---|
173 | )); |
---|
174 | } |
---|
175 | |
---|
176 | /** |
---|
177 | * User preferences form. |
---|
178 | * |
---|
179 | * This add options for superadmin user |
---|
180 | * to show or not expired taks. |
---|
181 | * |
---|
182 | * @param $args <b>object</b> dcCore instance or record |
---|
183 | */ |
---|
184 | public static function adminDashboardOptionsForm($core) |
---|
185 | { |
---|
186 | $core->auth->user_prefs->addWorkspace('maintenance'); |
---|
187 | |
---|
188 | echo |
---|
189 | '<div class="fieldset">'. |
---|
190 | '<h4>'.__('Maintenance').'</h4>'. |
---|
191 | |
---|
192 | '<p><label for="maintenance_dashboard_icon" class="classic">'. |
---|
193 | form::checkbox('maintenance_dashboard_icon', 1, $core->auth->user_prefs->maintenance->dashboard_icon). |
---|
194 | __('Display count of expired tasks on maintenance dashboard icon').'</label></p>'. |
---|
195 | |
---|
196 | '<p><label for="maintenance_dashboard_item" class="classic">'. |
---|
197 | form::checkbox('maintenance_dashboard_item', 1, $core->auth->user_prefs->maintenance->dashboard_item). |
---|
198 | __('Display list of expired tasks on dashboard items').'</label></p>'. |
---|
199 | |
---|
200 | '</div>'; |
---|
201 | } |
---|
202 | |
---|
203 | /** |
---|
204 | * User preferences update. |
---|
205 | * |
---|
206 | * @param $user_id <b>string</b> User ID |
---|
207 | */ |
---|
208 | public static function adminAfterDashboardOptionsUpdate($user_id=null) |
---|
209 | { |
---|
210 | global $core; |
---|
211 | |
---|
212 | if (is_null($user_id)) { |
---|
213 | return null; |
---|
214 | } |
---|
215 | |
---|
216 | $core->auth->user_prefs->addWorkspace('maintenance'); |
---|
217 | $core->auth->user_prefs->maintenance->put('dashboard_icon', !empty($_POST['maintenance_dashboard_icon']), 'boolean'); |
---|
218 | $core->auth->user_prefs->maintenance->put('dashboard_item', !empty($_POST['maintenance_dashboard_item']), 'boolean'); |
---|
219 | } |
---|
220 | } |
---|