/**
  * Save Form data
  */
 public static function save_post_form($tab, $jobid)
 {
     if (!current_user_can('backwpup_jobs_edit')) {
         return __('Sorry, you don\'t have permissions to do that.', 'backwpup');
     }
     $destinations = BackWPup::get_registered_destinations();
     $job_types = BackWPup::get_job_types();
     switch ($tab) {
         case 'job':
             BackWPup_Option::update($jobid, 'jobid', $jobid);
             if (isset($_POST['type']) && is_array($_POST['type'])) {
                 foreach ((array) $_POST['type'] as $typeid) {
                     if (empty($job_types[$typeid])) {
                         unset($_POST['type'][$typeid]);
                     }
                 }
                 if (is_array($_POST['type'])) {
                     sort($_POST['type']);
                 }
             } else {
                 $_POST['type'] = array();
             }
             //test if job type makes backup
             /* @var BackWPup_JobTypes $job_type */
             $makes_file = FALSE;
             foreach ($job_types as $type_id => $job_type) {
                 if (in_array($type_id, $_POST['type'])) {
                     if ($job_type->creates_file()) {
                         $makes_file = TRUE;
                         break;
                     }
                 }
             }
             if (!$makes_file) {
                 $_POST['destinations'] = array();
             }
             BackWPup_Option::update($jobid, 'type', $_POST['type']);
             if (isset($_POST['destinations']) && is_array($_POST['destinations'])) {
                 foreach ((array) $_POST['destinations'] as $key => $destid) {
                     if (empty($destinations[$destid])) {
                         //remove all destinations that not exists
                         unset($_POST['destinations'][$key]);
                     }
                     if (class_exists('BackWPup_Pro', FALSE) && $_POST['backuptype'] == 'sync') {
                         //if sync remove all not sync destinations
                         if (!$destinations[$destid]['can_sync']) {
                             unset($_POST['destinations'][$key]);
                         }
                     }
                 }
                 if (is_array($_POST['destinations'])) {
                     sort($_POST['destinations']);
                 }
             } else {
                 $_POST['destinations'] = array();
             }
             BackWPup_Option::update($jobid, 'destinations', $_POST['destinations']);
             $name = esc_html(trim($_POST['name']));
             if (empty($name) || $_POST['name'] == __('New Job', 'backwpup')) {
                 $name = sprintf(__('Job with ID %d', 'backwpup'), $jobid);
             }
             BackWPup_Option::update($jobid, 'name', $name);
             $emails = explode(',', $_POST['mailaddresslog']);
             foreach ($emails as $key => $email) {
                 $emails[$key] = sanitize_email(trim($email));
                 if (!is_email($emails[$key])) {
                     unset($emails[$key]);
                 }
             }
             $mailaddresslog = implode(', ', $emails);
             BackWPup_Option::update($jobid, 'mailaddresslog', $mailaddresslog);
             $_POST['mailaddresssenderlog'] = trim($_POST['mailaddresssenderlog']);
             if (empty($_POST['mailaddresssenderlog'])) {
                 BackWPup_Option::delete($jobid, 'mailaddresssenderlog');
             } else {
                 BackWPup_Option::update($jobid, 'mailaddresssenderlog', $_POST['mailaddresssenderlog']);
             }
             BackWPup_Option::update($jobid, 'mailerroronly', isset($_POST['mailerroronly']) && $_POST['mailerroronly'] == 1 ? TRUE : FALSE);
             if (class_exists('BackWPup_Pro', FALSE)) {
                 BackWPup_Option::update($jobid, 'backuptype', esc_html($_POST['backuptype']));
             } else {
                 BackWPup_Option::update($jobid, 'backuptype', 'archive');
             }
             BackWPup_Option::update($jobid, 'archiveformat', esc_html($_POST['archiveformat']));
             BackWPup_Option::update($jobid, 'archivename', BackWPup_Job::sanitize_file_name($_POST['archivename']));
             break;
         case 'cron':
             if ($_POST['activetype'] == '' || $_POST['activetype'] == 'wpcron' || $_POST['activetype'] == 'easycron' || $_POST['activetype'] == 'link') {
                 BackWPup_Option::update($jobid, 'activetype', $_POST['activetype']);
             }
             BackWPup_Option::update($jobid, 'cronselect', $_POST['cronselect'] == 'advanced' ? 'advanced' : 'basic');
             if (isset($_POST['cronselect']) && $_POST['cronselect'] == 'advanced') {
                 //save advanced
                 if (empty($_POST['cronminutes']) || $_POST['cronminutes'][0] == '*') {
                     if (!empty($_POST['cronminutes'][1])) {
                         $_POST['cronminutes'] = array('*/' . $_POST['cronminutes'][1]);
                     } else {
                         $_POST['cronminutes'] = array('*');
                     }
                 }
                 if (empty($_POST['cronhours']) || $_POST['cronhours'][0] == '*') {
                     if (!empty($_POST['cronhours'][1])) {
                         $_POST['cronhours'] = array('*/' . $_POST['cronhours'][1]);
                     } else {
                         $_POST['cronhours'] = array('*');
                     }
                 }
                 if (empty($_POST['cronmday']) || $_POST['cronmday'][0] == '*') {
                     if (!empty($_POST['cronmday'][1])) {
                         $_POST['cronmday'] = array('*/' . $_POST['cronmday'][1]);
                     } else {
                         $_POST['cronmday'] = array('*');
                     }
                 }
                 if (empty($_POST['cronmon']) || $_POST['cronmon'][0] == '*') {
                     if (!empty($_POST['cronmon'][1])) {
                         $_POST['cronmon'] = array('*/' . $_POST['cronmon'][1]);
                     } else {
                         $_POST['cronmon'] = array('*');
                     }
                 }
                 if (empty($_POST['cronwday']) || $_POST['cronwday'][0] == '*') {
                     if (!empty($_POST['cronwday'][1])) {
                         $_POST['cronwday'] = array('*/' . $_POST['cronwday'][1]);
                     } else {
                         $_POST['cronwday'] = array('*');
                     }
                 }
                 $cron = implode(",", $_POST['cronminutes']) . ' ' . implode(",", $_POST['cronhours']) . ' ' . implode(",", $_POST['cronmday']) . ' ' . implode(",", $_POST['cronmon']) . ' ' . implode(",", $_POST['cronwday']);
                 BackWPup_Option::update($jobid, 'cron', $cron);
             } else {
                 //Save basic
                 if ($_POST['cronbtype'] == 'mon') {
                     BackWPup_Option::update($jobid, 'cron', $_POST['moncronminutes'] . ' ' . $_POST['moncronhours'] . ' ' . $_POST['moncronmday'] . ' * *');
                 }
                 if ($_POST['cronbtype'] == 'week') {
                     BackWPup_Option::update($jobid, 'cron', $_POST['weekcronminutes'] . ' ' . $_POST['weekcronhours'] . ' * * ' . $_POST['weekcronwday']);
                 }
                 if ($_POST['cronbtype'] == 'day') {
                     BackWPup_Option::update($jobid, 'cron', $_POST['daycronminutes'] . ' ' . $_POST['daycronhours'] . ' * * *');
                 }
                 if ($_POST['cronbtype'] == 'hour') {
                     BackWPup_Option::update($jobid, 'cron', $_POST['hourcronminutes'] . ' * * * *');
                 }
             }
             //reschedule
             wp_clear_scheduled_hook('backwpup_cron', array('id' => $jobid));
             if (BackWPup_Option::get($jobid, 'activetype') == 'wpcron') {
                 $cron_next = BackWPup_Cron::cron_next(BackWPup_Option::get($jobid, 'cron'));
                 wp_schedule_single_event($cron_next, 'backwpup_cron', array('id' => $jobid));
             }
             $easy_cron_job_id = BackWPup_Option::get($jobid, 'easycronjobid');
             if (BackWPup_Option::get($jobid, 'activetype') == 'easycron') {
                 BackWPup_EasyCron::update($jobid);
             } elseif (!empty($easy_cron_job_id)) {
                 BackWPup_EasyCron::delete($jobid);
             }
             break;
         default:
             if (strstr($tab, 'dest-')) {
                 $dest_class = BackWPup::get_destination(str_replace('dest-', '', $tab));
                 $dest_class->edit_form_post_save($jobid);
             }
             if (strstr($tab, 'jobtype-')) {
                 $id = strtoupper(str_replace('jobtype-', '', $tab));
                 $job_types[$id]->edit_form_post_save($jobid);
             }
     }
     //saved message
     $messages = BackWPup_Admin::get_messages();
     if (empty($messages['error'])) {
         $url = BackWPup_Job::get_jobrun_url('runnowlink', $jobid);
         BackWPup_Admin::message(sprintf(__('Changes for job <i>%s</i> saved.', 'backwpup'), BackWPup_Option::get($jobid, 'name')) . ' <a href="' . network_admin_url('admin.php') . '?page=backwpupjobs">' . __('Jobs overview', 'backwpup') . '</a> | <a href="' . $url['url'] . '">' . __('Run now', 'backwpup') . '</a>');
     }
 }
Ejemplo n.º 2
0
 /**
  *
  * Cleanup on Plugin deactivation
  *
  * @return void
  */
 public static function deactivate()
 {
     wp_clear_scheduled_hook('backwpup_cron');
     $activejobs = BackWPup_Option::get_job_ids('activetype', 'wpcron');
     if (!empty($activejobs)) {
         foreach ($activejobs as $id) {
             wp_clear_scheduled_hook('backwpup_cron', array('id' => $id));
         }
     }
     wp_clear_scheduled_hook('backwpup_check_cleanup');
     $activejobs = BackWPup_Option::get_job_ids('activetype', 'easycron');
     if (!empty($activejobs)) {
         foreach ($activejobs as $id) {
             BackWPup_EasyCron::delete($id);
         }
     }
     //to reschedule on activation and so on
     update_site_option('backwpup_version', get_site_option('backwpup_version') . '-inactive');
 }
Ejemplo n.º 3
0
 public function api_key_save_form()
 {
     if (!empty($_POST['easycronapikey'])) {
         update_site_option('backwpup_cfg_easycronapikey', esc_attr($_POST['easycronapikey']));
     } else {
         delete_site_option('backwpup_cfg_easycronapikey');
     }
     if (!empty($_POST['easycronwp']) && $_POST['easycronwp'] == 1) {
         BackWPup_EasyCron::update(0);
     } else {
         BackWPup_EasyCron::delete(0);
     }
 }
Ejemplo n.º 4
0
 /**
  * The next Column
  *
  * @param $item
  * @return string
  */
 function column_next($item)
 {
     $r = '';
     $job_normal_hide = '';
     if (is_object($this->job_object)) {
         $job_normal_hide = ' style="display:none;"';
     }
     if (is_object($this->job_object) && $this->job_object->job['jobid'] == $item) {
         $runtime = current_time('timestamp') - $this->job_object->start_time;
         $r .= '<div class="job-run">' . sprintf(esc_html__('Running for: %s seconds', 'backwpup'), '<span id="runtime">' . $runtime . '</span>') . '</div>';
     }
     if (is_object($this->job_object) && $this->job_object->job['jobid'] == $item) {
         $r .= '<div class="job-normal"' . $job_normal_hide . '>';
     }
     if (BackWPup_Option::get($item, 'activetype') == 'wpcron') {
         if ($nextrun = wp_next_scheduled('backwpup_cron', array('id' => $item)) + get_option('gmt_offset') * 3600) {
             $r .= '<span title="' . sprintf(esc_html__('Cron: %s', 'backwpup'), BackWPup_Option::get($item, 'cron')) . '">' . sprintf(__('%1$s at %2$s by WP-Cron', 'backwpup'), date_i18n(get_option('date_format'), $nextrun, TRUE), date_i18n(get_option('time_format'), $nextrun, TRUE)) . '</span><br />';
         } else {
             $r .= __('Not scheduled!', 'backwpup') . '<br />';
         }
     } elseif (BackWPup_Option::get($item, 'activetype') == 'easycron') {
         $easycron_status = BackWPup_EasyCron::status($item);
         if (!empty($easycron_status)) {
             $nextrun = BackWPup_Cron::cron_next($easycron_status['cron_expression']) + get_option('gmt_offset') * 3600;
             $r .= '<span title="' . sprintf(esc_html__('Cron: %s', 'backwpup'), $easycron_status['cron_expression']) . '">' . sprintf(__('%1$s at %2$s by EasyCron', 'backwpup'), date_i18n(get_option('date_format'), $nextrun, TRUE), date_i18n(get_option('time_format'), $nextrun, TRUE)) . '</span><br />';
         } else {
             $r .= __('Not scheduled!', 'backwpup') . '<br />';
         }
     } elseif (BackWPup_Option::get($item, 'activetype') == 'link') {
         $r .= __('External link', 'backwpup') . '<br />';
     } else {
         $r .= __('Inactive', 'backwpup');
     }
     if (is_object($this->job_object) && $this->job_object->job['jobid'] == $item) {
         $r .= '</div>';
     }
     return $r;
 }
Ejemplo n.º 5
0
 /**
  *
  * Cleanup on Plugin deactivation
  *
  * @return void
  */
 public static function deactivate()
 {
     wp_clear_scheduled_hook('backwpup_cron');
     $activejobs = BackWPup_Option::get_job_ids('activetype', 'wpcron');
     if (!empty($activejobs)) {
         foreach ($activejobs as $id) {
             wp_clear_scheduled_hook('backwpup_cron', array('id' => $id));
         }
     }
     wp_clear_scheduled_hook('backwpup_check_cleanup');
     $activejobs = BackWPup_Option::get_job_ids('activetype', 'easycron');
     if (!empty($activejobs)) {
         foreach ($activejobs as $id) {
             BackWPup_EasyCron::delete($id);
         }
     }
     //remove roles
     remove_role('backwpup_admin');
     remove_role('backwpup_helper');
     remove_role('backwpup_check');
     //remove capabilities to administrator role
     $role = get_role('administrator');
     if (is_object($role) && method_exists($role, 'remove_cap')) {
         $role->remove_cap('backwpup');
         $role->remove_cap('backwpup_jobs');
         $role->remove_cap('backwpup_jobs_edit');
         $role->remove_cap('backwpup_jobs_start');
         $role->remove_cap('backwpup_backups');
         $role->remove_cap('backwpup_backups_download');
         $role->remove_cap('backwpup_backups_delete');
         $role->remove_cap('backwpup_logs');
         $role->remove_cap('backwpup_logs_delete');
         $role->remove_cap('backwpup_settings');
     }
     //to reschedule on activation and so on
     update_site_option('backwpup_version', get_site_option('backwpup_version') . '-inactive');
 }
Ejemplo n.º 6
0
 public function api_key_save_form()
 {
     if (!empty($_POST['easycronapikey'])) {
         update_site_option('backwpup_cfg_easycronapikey', sanitize_text_field($_POST['easycronapikey']));
     } else {
         delete_site_option('backwpup_cfg_easycronapikey');
     }
     if (!empty($_POST['easycronwp'])) {
         BackWPup_EasyCron::update(0);
     } else {
         BackWPup_EasyCron::delete(0);
     }
 }