示例#1
0
 function remote_send_dropbox($token, $directory, $file)
 {
     $this->log('Starting Dropbox transfer.');
     require_once $this->_pluginPath . '/lib/dropbuddy/dropbuddy.php';
     $dropbuddy = new pluginbuddy_dropbuddy($this, $token);
     if ($dropbuddy->authenticate() !== true) {
         $this->log('Dropbox authentication failed in remote_send_dropbox.');
         return false;
     }
     $this->log('About to put object (the file) to Dropbox cron.');
     $status = $dropbuddy->put_file($directory . '/' . basename($file), $file);
     //if ( $status['httpStatus'] != 200 ) {
     if ($status !== true) {
         $this->log('Dropbox file send FAILURE. HTTP Status: ' . $status['httpStatus'] . '; Body: ' . $status['body'], 'error');
         return false;
     }
     $this->log('SUCCESS sending to Dropbox!');
     return true;
 }
<?php

$this->title('Dropbox');
require_once $this->_pluginPath . '/lib/dropbuddy/dropbuddy.php';
$dropbuddy = new pluginbuddy_dropbuddy($this, $destination['token']);
if ($dropbuddy->authenticate() === true) {
    $account_info = $dropbuddy->get_account_info();
} else {
    $account_info = false;
}
$meta_data = $dropbuddy->get_meta_data($destination['directory']);
/*
echo '<pre>';
print_r( $meta_data ) );
echo '</pre>';
*/
// Delete dropbox backups
if (!empty($_POST['delete_file'])) {
    $delete_count = 0;
    if (!empty($_POST['files']) && is_array($_POST['files'])) {
        // loop through and delete dropbox files
        foreach ($_POST['files'] as $dropboxfile) {
            $delete_count++;
            // Delete dropbox file
            $dropbuddy->delete($dropboxfile);
        }
    }
    if ($delete_count > 0) {
        $this->alert('Deleted ' . $delete_count . ' file(s).');
        $meta_data = $dropbuddy->get_meta_data($destination['directory']);
        // Refresh listing.
    $options = array_merge($this->_parent->_dropboxdefaults, (array) $this->_options['remote_destinations'][$_GET['edit']]);
    echo '<h3>' . __('Edit Destination', 'it-l10n-backupbuddy') . '</h3>';
    echo '<form method="post" action="' . admin_url('admin-ajax.php') . '?action=pb_backupbuddy_remotedestination&edit=' . htmlentities($edit_id) . '&callback_data=' . $callback_data . '&type=dropbox#pb_backupbuddy_tab_dropbox">';
    echo '	<input type="hidden" name="savepoint" value="remote_destinations#' . $_GET['edit'] . '" />';
} else {
    if ($dropbox_connected === true) {
        $options = $this->_parent->_dropboxdefaults;
        echo '<h3>' . __('Add New Destination', 'it-l10n-backupbuddy') . ' ' . $this->video('', 'Add a new Dropbox destination', false) . '</h3>';
        echo '<form method="post" action="' . admin_url('admin-ajax.php') . '?action=pb_backupbuddy_remotedestination&callback_data=' . $callback_data . '&type=dropbox#pb_backupbuddy_tab_dropbox">';
    } else {
        $hide_add = true;
    }
}
if ($hide_add !== true) {
    if (!isset($account_info)) {
        $dropbuddy = new pluginbuddy_dropbuddy($this, $this->_options['remote_destinations'][$_GET['edit']]['token']);
        if ($dropbuddy->authenticate() === true) {
            $dropbox_connected = true;
            $account_info = $dropbuddy->get_account_info();
        } else {
            echo __('Dropbox Access Denied', 'it-l10n-backupbuddy');
        }
    }
    ?>
	<input type="hidden" name="#type" value="dropbox" />
	<table class="form-table">
		<tr>
			<td><label><?php 
    _e('Dropbox Owner', 'it-l10n-backupbuddy');
    ?>
</label></td>
 function remote_send_dropbox($token, $directory, $file, $limit = 0)
 {
     $this->log('Starting Dropbox transfer.');
     require_once $this->_pluginPath . '/lib/dropbuddy/dropbuddy.php';
     $dropbuddy = new pluginbuddy_dropbuddy($this, $token);
     if ($dropbuddy->authenticate() !== true) {
         $this->log('Dropbox authentication failed in remote_send_dropbox.');
         return false;
     }
     $this->log('About to put object (the file) to Dropbox cron.');
     $status = $dropbuddy->put_file($directory . '/' . basename($file), $file);
     //if ( $status['httpStatus'] != 200 ) {
     if ($status === true) {
         $this->log('SUCCESS sending to Dropbox!');
     } else {
         $this->log('Dropbox file send FAILURE. HTTP Status: ' . $status['httpStatus'] . '; Body: ' . $status['body'], 'error');
         return false;
     }
     // Start remote backup limit
     if ($limit > 0) {
         $this->log('Dropbox file limit in place. Proceeding with enforcement.');
         $meta_data = $dropbuddy->get_meta_data($directory);
         // Create array of backups and organize by date
         $bkupprefix = $this->backup_prefix();
         $backups = array();
         foreach ((array) $meta_data['contents'] as $file) {
             // check if file is backup
             if (strpos($file['path'], 'backup-' . $bkupprefix . '-') !== FALSE) {
                 $backups[$file['path']] = strtotime($file['modified']);
             }
         }
         arsort($backups);
         if (count($backups) > $limit) {
             $this->log('Dropbox backup file count of `' . count($backups) . '` exceeds limit of `' . $limit . '`.');
             $i = 0;
             $delete_fail_count = 0;
             foreach ($backups as $buname => $butime) {
                 $i++;
                 if ($i > $limit) {
                     if (!$dropbuddy->delete($buname)) {
                         // Try to delete backup on Dropbox. Increment failure count if unable to.
                         $this->log('Unable to delete excess Dropbox file: `' . $buname . '`');
                         $delete_fail_count++;
                     }
                 }
             }
             if ($delete_fail_count !== 0) {
                 $this->mail_error(sprintf(__('Dropbox remote limit could not delete %s backups.', 'it-l10n-backupbuddy'), $delete_fail_count));
             }
         }
     } else {
         $this->log('No Dropbox file limit to enforce.');
     }
     // End remote backup limit
     return true;
 }