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