Esempio n. 1
0
$pb_hide_test = true;
// Always hiding test button for Dropbox.
$pb_hide_save = true;
$hide_add = true;
if ($mode == 'edit' || $mode == 'add') {
    ?>
	<script type="text/javascript">
		jQuery(document).ready(function() {
			jQuery('.pb_dropbox_authorize').click(function(e) {
				jQuery('.pb_dropbox_authorize').hide();
				jQuery('#pb_dropbox_authorize').slideDown();
			});
		});
	</script>
	<?php 
    $memory = pb_backupbuddy_destination_dropbox::memory_guesstimate();
    pb_backupbuddy::alert('Note: The Dropbox API limits uploads to a maximum of 150MB.  Additionally, backup files must be fully loaded into memory to transfer to Dropbox.
		BackupBuddy estimates you will be able to transfer backups up to ' . round($memory['hypothesis'], 0) . ' MB with your current memory limit of ' . $memory['limit'] . ' MB
		and <a target="_new" href="https://www.dropbox.com/developers/reference/api">Dropbox\'s 150 MB limit</a>.');
    // Handle token resetting when user clicked re-authorize button on config.
    if (isset($_GET['clear_dropboxtemptoken']) && $_GET['clear_dropboxtemptoken'] == 'true') {
        pb_backupbuddy::$options['dropboxtemptoken'] = '';
        // Clear temp token.
        pb_backupbuddy::save();
    }
    require_once dirname(__FILE__) . '/lib/dropbuddy/dropbuddy.php';
    if (isset($destination_settings['token']) && $destination_settings['token'] != '') {
        $dropbox_token = $destination_settings['token'];
    } else {
        $dropbox_token =& pb_backupbuddy::$options['dropboxtemptoken'];
    }
Esempio n. 2
0
 public static function send($settings = array(), $files = array(), $send_id = '')
 {
     global $pb_backupbuddy_destination_errors;
     if ('1' == $settings['disabled']) {
         $pb_backupbuddy_destination_errors[] = __('Error #48933: This destination is currently disabled. Enable it under this destination\'s Advanced Settings.', 'it-l10n-backupbuddy');
         return false;
     }
     if (!is_array($files)) {
         $files = array($files);
     }
     $token =& $settings['token'];
     $directory = '/' . ltrim($settings['directory'], '/\\');
     $limit = $settings['archive_limit'];
     // Normalize picky dropbox directory.
     $directory = trim($directory, '\\/');
     pb_backupbuddy::status('details', 'About to load Dropbuddy library...');
     require_once pb_backupbuddy::plugin_path() . '/destinations/dropbox/lib/dropbuddy/dropbuddy.php';
     pb_backupbuddy::status('details', 'Dropbuddy loaded.');
     //pb_backupbuddy::status( 'details', 'Authenticating to dropbox with token: `' . implode( ';', $token ) . '`.' );
     $dropbuddy = new pb_backupbuddy_dropbuddy($token);
     pb_backupbuddy::status('details', 'Dropbuddy object created.');
     if ($dropbuddy->authenticate() !== true) {
         pb_backupbuddy::status('details', 'Dropbox authentication failed in send().');
         return false;
     } else {
         pb_backupbuddy::status('details', 'Authenticated to Dropbox.');
     }
     $memory = pb_backupbuddy_destination_dropbox::memory_guesstimate();
     pb_backupbuddy::status('details', 'Dropbox limitation estimated to be max transfer size of ' . round($memory['hypothesis'], 0) . 'MB based on PHP memory limit of ' . $memory['limit'] . 'MB & current loaded WordPress plugins.');
     pb_backupbuddy::status('details', 'Looping through files to send to Dropbox.');
     foreach ($files as $file) {
         pb_backupbuddy::status('details', 'About to put file `' . basename($file) . '` (' . pb_backupbuddy::$format->file_size(filesize($file)) . ') to Dropbox (v1).');
         try {
             $status = $dropbuddy->put_file($directory . '/' . basename($file), $file);
         } catch (Dropbox_Exception $e) {
             pb_backupbuddy::status('error', 'Dropbox exception caught. Error #8954785: ' . $e->getMessage());
             return false;
         }
         if ($status === true) {
             pb_backupbuddy::status('details', 'SUCCESS sending to Dropbox!');
         } else {
             pb_backupbuddy::status('details', 'Dropbox file send FAILURE. HTTP Status: ' . $status['httpStatus'] . '; Body: ' . $status['body'], 'error');
             return false;
         }
         // Start remote backup limit
         if ($limit > 0) {
             pb_backupbuddy::status('details', 'Dropbox file limit in place. Proceeding with enforcement.');
             $meta_data = $dropbuddy->get_meta_data($directory);
             // Create array of backups and organize by date
             $bkupprefix = backupbuddy_core::backup_prefix();
             $backups = array();
             foreach ((array) $meta_data['contents'] as $looping_file) {
                 if ('1' == $looping_file['is_dir']) {
                     // Additional safety layer to ignore subdirectory.
                     continue;
                 }
                 // check if file is backup
                 if (strpos($looping_file['path'], 'backup-' . $bkupprefix . '-') !== false) {
                     $backups[$looping_file['path']] = strtotime($looping_file['modified']);
                 }
             }
             arsort($backups);
             if (count($backups) > $limit) {
                 pb_backupbuddy::status('details', '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.
                             pb_backupbuddy::status('details', 'Unable to delete excess Dropbox file: `' . $buname . '`');
                             $delete_fail_count++;
                         }
                     }
                 }
                 if ($delete_fail_count !== 0) {
                     backupbuddy_core::mail_error(sprintf(__('Dropbox remote limit could not delete %s backups.', 'it-l10n-backupbuddy'), $delete_fail_count));
                 }
             }
         } else {
             pb_backupbuddy::status('details', 'No Dropbox file limit to enforce.');
         }
         // End remote backup limit
     }
     // end foreach.
     pb_backupbuddy::status('details', 'All files sent.');
     return true;
     // Success if made it this far.
 }