public function _action_download()
 {
     if (!isset($_GET[self::$download_GET_parameter]) || !is_string($archive_filename = $_GET[self::$download_GET_parameter]) || !$this->is_backups_page()) {
         return;
     }
     $error = __('Unknown error', 'fw');
     do {
         if (!current_user_can($this->get_capability())) {
             $error = __('Access Denied', 'fw');
             break;
         }
         $archives = $this->get_archives();
         if (!isset($archives[$archive_filename])) {
             $error = __('Archive not found', 'fw');
             break;
         }
         $archive = $archives[$archive_filename];
         if ($archive['full'] && !fw_ext_backups_current_user_can_full()) {
             $error = __('Access Denied', 'fw');
             break;
         }
         if ($f = fopen($archive['path'], 'r')) {
             // ok
         } else {
             $error = __('Failed to open file', 'fw');
             break;
         }
         header('Content-Disposition: attachment; filename="' . esc_attr($archive_filename) . '"');
         header('Content-Type: application/zip, application/octet-stream');
         /**
          * Some files can be huge, do not load entire file in php memory then output, it can cause memory limit error
          * Read and output parts
          */
         while (!feof($f)) {
             echo fread($f, 1000000);
         }
         fclose($f);
         exit;
     } while (false);
     wp_die($error, $error);
 }
Ejemplo n.º 2
0
				</span>
			</li>
		</ul>
	</div>

	<div id="fw-ext-backups-schedule-status"></div>

	<div>
		<a href="#" onclick="return false;" id="fw-ext-backups-edit-schedule"
		   class="button button-primary"><?php 
esc_html_e('Edit Backup Schedule', 'fw');
?>
</a>
		&nbsp;
		<?php 
if (fw_ext_backups_current_user_can_full()) {
    ?>
		<a href="#" onclick="return false;" id="fw-ext-backups-full-backup-now"
		   class="button fw-ext-backups-backup-now" data-full="1"><?php 
    esc_html_e('Create Full Backup Now', 'fw');
    ?>
</a>
		&nbsp;
		<?php 
}
?>
		<a href="#" onclick="return false;" id="fw-ext-backups-content-backup-now"
		   class="button fw-ext-backups-backup-now" data-full=""><?php 
esc_html_e('Create Content Backup Now', 'fw');
?>
</a>
 public function _action_ajax_set_settings()
 {
     if (!current_user_can(self::backups()->get_capability())) {
         wp_send_json_error();
     }
     if (empty($_POST['values']) || !is_array($values = $_POST['values'])) {
         wp_send_json_error();
     }
     foreach (array('full', 'content') as $type) {
         if ($type === 'full' && !fw_ext_backups_current_user_can_full()) {
             $this->set_settings($type, array('interval' => '', 'lifetime' => self::$default_lifetime));
         } else {
             $this->set_settings($type, array('interval' => $values[$type]['interval'], 'lifetime' => isset($values[$type][$values[$type]['interval']]) ? $values[$type][$values[$type]['interval']]['lifetime'] : self::$default_lifetime));
         }
     }
     wp_send_json_success();
 }