[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'), |
---|
| 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 | ); |
---|
[3] | 22 | |
---|
[1925] | 23 | // Admin behaviors |
---|
| 24 | $core->addBehavior('dcMaintenanceRegister', array('dcMaintenanceAdmin', 'register')); |
---|
| 25 | $core->addBehavior('adminDashboardFavs', array('dcMaintenanceAdmin', 'favs')); |
---|
[1940] | 26 | $core->addBehavior('adminDashboardFavsIcon', array('dcMaintenanceAdmin', 'favsicon')); |
---|
| 27 | $core->addBehavior('adminPreferencesForm', array('dcMaintenanceAdmin', 'prefform')); |
---|
| 28 | $core->addBehavior('adminBeforeUserOptionsUpdate', array('dcMaintenanceAdmin', 'userupd')); |
---|
[3] | 29 | |
---|
[1925] | 30 | /** |
---|
| 31 | @ingroup PLUGIN_MAINTENANCE |
---|
| 32 | @nosubgrouping |
---|
| 33 | @brief Maintenance plugin admin class. |
---|
| 34 | |
---|
| 35 | Group of methods used on behaviors. |
---|
| 36 | */ |
---|
| 37 | class dcMaintenanceAdmin |
---|
[3] | 38 | { |
---|
[1925] | 39 | /** |
---|
[1940] | 40 | * Register default tasks. |
---|
[1925] | 41 | * |
---|
| 42 | * @param $core <b>dcCore</b> dcCore instance |
---|
| 43 | * @param $tasks <b>arrayObject</b> Array of tasks to register |
---|
| 44 | * @param $groups <b>arrayObject</b> Array of groups to register |
---|
[1955] | 45 | * @param $tabs <b>arrayObject</b> Array of tabs to register |
---|
[1925] | 46 | */ |
---|
[1955] | 47 | public static function register($core, $tasks, $groups, $tabs) |
---|
[1925] | 48 | { |
---|
[1955] | 49 | $tabs['maintenance'] = __('Servicing'); |
---|
| 50 | $tabs['backup'] = __('Backup'); |
---|
| 51 | |
---|
[1925] | 52 | $groups['optimize'] = __('Optimize'); |
---|
| 53 | $groups['index'] = __('Count and index'); |
---|
| 54 | $groups['purge'] = __('Purge'); |
---|
| 55 | $groups['other'] = __('Other'); |
---|
[1955] | 56 | $groups['zipblog'] = __('Compressed file for current blog'); |
---|
| 57 | $groups['zipfull'] = __('Compressed file for all blogs'); |
---|
[1925] | 58 | |
---|
| 59 | $tasks[] = 'dcMaintenanceCache'; |
---|
| 60 | $tasks[] = 'dcMaintenanceCountcomments'; |
---|
| 61 | $tasks[] = 'dcMaintenanceIndexcomments'; |
---|
| 62 | $tasks[] = 'dcMaintenanceIndexposts'; |
---|
| 63 | $tasks[] = 'dcMaintenanceLogs'; |
---|
| 64 | $tasks[] = 'dcMaintenanceVacuum'; |
---|
[1955] | 65 | $tasks[] = 'dcMaintenanceZipmedia'; |
---|
| 66 | $tasks[] = 'dcMaintenanceZiptheme'; |
---|
[1925] | 67 | } |
---|
| 68 | |
---|
| 69 | /** |
---|
[1940] | 70 | * Dashboard favs. |
---|
[1925] | 71 | * |
---|
| 72 | * @param $core <b>dcCore</b> dcCore instance |
---|
| 73 | * @param $favs <b>arrayObject</b> Array of favs |
---|
| 74 | */ |
---|
| 75 | public static function favs($core, $favs) |
---|
| 76 | { |
---|
| 77 | $favs['maintenance'] = new ArrayObject(array( |
---|
| 78 | 'maintenance', |
---|
| 79 | 'Maintenance', |
---|
| 80 | 'plugin.php?p=maintenance', |
---|
| 81 | 'index.php?pf=maintenance/icon.png', |
---|
| 82 | 'index.php?pf=maintenance/icon-big.png', |
---|
| 83 | null,null,null |
---|
| 84 | )); |
---|
| 85 | } |
---|
| 86 | |
---|
[1940] | 87 | /** |
---|
| 88 | * Dashboard favs icon. |
---|
| 89 | * |
---|
| 90 | * This updates maintenance fav icon text |
---|
| 91 | * if there are tasks required maintenance. |
---|
| 92 | * |
---|
| 93 | * @param $core <b>dcCore</b> dcCore instance |
---|
| 94 | * @param $name <b>string</b> Current fav name |
---|
| 95 | * @param $icon <b>arrayObject</b> Current fav attributes |
---|
| 96 | */ |
---|
| 97 | public static function favsicon($core, $name, $icon) |
---|
| 98 | { |
---|
| 99 | // Check icon |
---|
| 100 | if ($name !== 'maintenance') { |
---|
| 101 | return null; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | // Check user option |
---|
| 105 | $user_options = $core->auth->getOptions(); |
---|
| 106 | if (empty($user_options['user_maintenance_expired'])) { |
---|
| 107 | return null; |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | // Check expired tasks |
---|
| 111 | $maintenance = new dcMaintenance($core); |
---|
| 112 | $expired = $maintenance->getExpired(); |
---|
| 113 | $expired = count($expired); |
---|
| 114 | if (!$expired) { |
---|
| 115 | return null; |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | $icon[0] .= '<br />'.sprintf(__('One task to update', '%s tasks to update', $expired), $expired); |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | /** |
---|
| 122 | * User preferences form. |
---|
| 123 | * |
---|
| 124 | * This add options for superadmin user |
---|
| 125 | * to show or not expired taks. |
---|
| 126 | * |
---|
| 127 | * @param $args <b>object</b> dcCore instance or record |
---|
| 128 | */ |
---|
| 129 | public static function prefform($args) |
---|
| 130 | { |
---|
| 131 | $opts = array(); |
---|
| 132 | if ($args instanceof dcCore) { |
---|
| 133 | $opts = $args->auth->getOptions(); |
---|
| 134 | $core = $args; |
---|
| 135 | } |
---|
| 136 | elseif ($args instanceof record) { |
---|
| 137 | $opts = $args->options(); |
---|
| 138 | $core = $args->core; |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | echo |
---|
| 142 | '<p><label for="user_maintenance_expired" class="classic">'. |
---|
| 143 | form::checkbox('user_maintenance_expired', 1, !empty($opts['user_maintenance_expired'])).' '. |
---|
| 144 | __('Show maintenance tasks to update.').'</label></p>'; |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | /** |
---|
| 148 | * User preferences update. |
---|
| 149 | * |
---|
| 150 | * @param $cur <b>cursor</b> Cursor of user options |
---|
| 151 | * @param $user_id <b>string</b> User ID |
---|
| 152 | */ |
---|
| 153 | public static function userupd($cur, $user_id=null) |
---|
| 154 | { |
---|
| 155 | if (!is_null($user_id)) { |
---|
| 156 | $cur->user_options['user_maintenance_expired'] = !empty($_POST['user_maintenance_expired']); |
---|
| 157 | } |
---|
| 158 | } |
---|
[3] | 159 | } |
---|