blog->settings->addNamespace('maintenance'); $maintenance = new dcMaintenance($core); $tasks = $maintenance->getTasks(); $headers = ''; $p_url = $core->adminurl->get('admin.plugin.maintenance'); $task = null; $expired = []; $code = empty($_POST['code']) ? null : (integer) $_POST['code']; $tab = empty($_REQUEST['tab']) ? '' : $_REQUEST['tab']; // Get task object if (!empty($_REQUEST['task'])) { $task = $maintenance->getTask($_REQUEST['task']); if ($task === null) { $core->error->add('Unknow task ID'); } $task->code($code); } // Execute task if ($task && !empty($_POST['task']) && $task->id() == $_POST['task']) { try { $code = $task->execute(); if (false === $code) { throw new Exception($task->error()); } if (true === $code) { $maintenance->setLog($task->id()); dcPage::addSuccessNotice($task->success()); http::redirect($p_url . '&task=' . $task->id() . '&tab=' . $tab . '#' . $tab); } } catch (Exception $e) { $core->error->add($e->getMessage()); } } // Save settings if (!empty($_POST['save_settings'])) { try { $core->blog->settings->maintenance->put( 'plugin_message', !empty($_POST['settings_plugin_message']), 'boolean', 'Display alert message of late tasks on plugin page', true, true ); foreach ($tasks as $t) { if (!$t->id()) { continue; } if (!empty($_POST['settings_recall_type']) && $_POST['settings_recall_type'] == 'all') { $ts = $_POST['settings_recall_time']; } else { $ts = empty($_POST['settings_ts_' . $t->id()]) ? 0 : $_POST['settings_ts_' . $t->id()]; } $core->blog->settings->maintenance->put( 'ts_' . $t->id(), abs((integer) $ts), 'integer', sprintf('Recall time for task %s', $t->id()), true, $t->blog() ); } dcPage::addSuccessNotice(__('Maintenance plugin has been successfully configured.')); http::redirect($p_url . '&tab=' . $tab . '#' . $tab); } catch (Exception $e) { $core->error->add($e->getMessage()); } } // Combos $combo_ts = [ __('Never') => 0, __('Every week') => 604800, __('Every two weeks') => 1209600, __('Every month') => 2592000, __('Every two months') => 5184000 ]; // Display page echo ' ' . __('Maintenance') . '' . dcPage::jsPageTabs($tab) . dcPage::jsLoad(dcPage::getPF('maintenance/js/settings.js')); if ($task && $task->ajax()) { echo '' . dcPage::jsLoad(dcPage::getPF('maintenance/js/dc.maintenance.js')); } echo $maintenance->getHeaders() . ' '; // Check if there is somthing to display according to user permissions if (empty($tasks)) { echo dcPage::breadcrumb( [ __('Plugins') => '', __('Maintenance') => '' ] ) . '

' . __('You have not sufficient permissions to view this page.') . '

' . ''; return; } if ($task && ($res = $task->step()) !== null) { // Page title echo dcPage::breadcrumb( [ __('Plugins') => '', '' . __('Maintenance') . '' => '', html::escapeHTML($task->name()) => '' ] ) . dcPage::notices(); // content if (substr($res, 0, 1) != '<') { $res = sprintf('

%s

', $res); } // Intermediate task (task required several steps) echo '
' . '

' . '' . __('Back') . '' . '

' . '

' . html::escapeHTML($task->name()) . '

' . '
' . $res . '

' . ' ' . form::hidden(['task'], $task->id()) . form::hidden(['code'], (integer) $code) . $core->formNonce() . '

' . '
' . '
'; } else { // Page title echo dcPage::breadcrumb( [ __('Plugins') => '', __('Maintenance') => '' ] ) . dcPage::notices(); // Simple task (with only a button to start it) foreach ($maintenance->getTabs() as $tab_obj) { $res_group = ''; foreach ($maintenance->getGroups() as $group_obj) { $res_task = ''; foreach ($tasks as $t) { if (!$t->id() || $t->group() != $group_obj->id() || $t->tab() != $tab_obj->id()) { continue; } $res_task .= '

' . form::radio(['task', $t->id()], $t->id()) . ' ' . ''; // Expired task alert message $ts = $t->expired(); if ($core->blog->settings->maintenance->plugin_message && $ts !== false) { if ($ts === null) { $res_task .= '
' . __('This task has never been executed.') . ' ' . __('You should execute it now.') . ''; } else { $res_task .= '
' . sprintf( __('Last execution of this task was on %s.'), dt::str($core->blog->settings->system->date_format, $ts) . ' ' . dt::str($core->blog->settings->system->time_format, $ts) ) . ' ' . __('You should execute it now.') . ''; } } $res_task .= '

'; } if (!empty($res_task)) { $res_group .= '
' . '

' . $group_obj->name() . '

' . $res_task . '
'; } } if (!empty($res_group)) { echo '
' . '

' . $tab_obj->name() . '

' . // ($tab_obj->option('summary') ? '

'.$tab_obj->option('summary').'

' : ''). '
' . $res_group . '

' . form::hidden(['tab'], $tab_obj->id()) . $core->formNonce() . '

' . '

' . __('This may take a very long time.') . '

' . '
' . '
'; } } // Advanced tasks (that required a tab) foreach ($tasks as $t) { if (!$t->id() || $t->group() !== null) { continue; } echo '
' . '

' . $t->name() . '

' . '
' . $t->content() . '

' . form::hidden(['task'], $t->id()) . form::hidden(['tab'], $t->id()) . $core->formNonce() . '

' . '
' . '
'; } // Settings echo '
' . '

' . __('Alert settings') . '

' . '
' . '

' . __('Activation') . '

' . '

' . '

' . sprintf( __('You can place list of late tasks on your %s.'), '' . __('Dashboard') . '' ) . '

' . '

' . __('Frequency') . '

' . '

' . form::radio(['settings_recall_type', 'settings_recall_all'], 'all') . ' ' . '

' . '

' . form::combo('settings_recall_time', $combo_ts, 'seperate', 'recall-for-all') . '

' . '

' . form::radio(['settings_recall_type', 'settings_recall_separate'], 'separate', 1) . ' ' . '

'; foreach ($tasks as $t) { if (!$t->id()) { continue; } echo '
' . '

' . form::combo('settings_ts_' . $t->id(), $combo_ts, $t->ts(), 'recall-per-task') . '

' . '
'; } echo '

' . form::hidden(['tab'], 'settings') . form::hidden(['save_settings'], 1) . $core->formNonce() . '

' . '
' . '
'; } dcPage::helpBlock('maintenance', 'maintenancetasks'); echo '';