function remote_send_dropbox($token, $directory, $file, $limit = 0, $send_importbuddy = false) { // Normalize picky dropbox directory. $directory = trim($directory, '\\/'); $directory = str_replace(' ', '%20', $directory); pb_backupbuddy::status('details', 'Starting Dropbox transfer.'); require_once pb_backupbuddy::plugin_path() . '/lib/dropbuddy/dropbuddy.php'; $dropbuddy = new pb_backupbuddy_dropbuddy($token); if ($dropbuddy->authenticate() !== true) { pb_backupbuddy::status('details', 'Dropbox authentication failed in remote_send_dropbox.'); return false; } pb_backupbuddy::status('details', 'About to put object `' . basename($file) . '` to Dropbox cron.'); $status = $dropbuddy->put_file($directory . '/' . basename($file), $file); 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; } // Handle sending importbuddy.php. if ($send_importbuddy === true) { pb_backupbuddy::status('details', 'Sending importbuddy to Dropbox based on settings.'); $importbuddy_temp = pb_backupbuddy::$options['temp_directory'] . 'importbuddy_' . pb_backupbuddy::random_string(10) . '.php.tmp'; // Full path & filename to temporary importbuddy $this->importbuddy($importbuddy_temp); // Create temporary importbuddy. $dropbuddy->put_file($directory . '/' . basename($file), $file); @unlink($importbuddy_temp); // Delete temporary importbuddy. } // 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 = $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) { 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) { $this->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 return true; // Success if made it this far. }
pb_backupbuddy::$ui->title('Dropbox'); require_once pb_backupbuddy::plugin_path() . '/destinations/dropbox/lib/dropbuddy/dropbuddy.php'; $dropbuddy = new pb_backupbuddy_dropbuddy($destination['token']); if ($dropbuddy->authenticate() === true) { $account_info = $dropbuddy->get_account_info(); } else { $account_info = false; } if (!isset($destination['directory'])) { $destination['directory'] = ''; } if (!isset($destination['title'])) { $destination['title'] = ''; } $meta_data = $dropbuddy->get_meta_data($destination['directory']); /* echo '<pre>'; print_r( $meta_data ) ); echo '</pre>'; */ // Delete dropbox backups if (!empty($_POST['delete_file'])) { pb_backupbuddy::verify_nonce(); $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);
public static function send($settings = array(), $files = array()) { $token =& $settings['token']; $directory = $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.'); } pb_backupbuddy::status('details', 'Looping through files to send to Dropbox.'); foreach ($files as $file) { pb_backupbuddy::status('details', 'About to put object `' . basename($file) . '` to Dropbox cron.'); 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 = pb_backupbuddy::$classes['core']->backup_prefix(); $backups = array(); foreach ((array) $meta_data['contents'] as $looping_file) { // 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) { pb_backupbuddy::$classes['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. }
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. }