Edit File by line
/home/barbar84/www/wp-conte.../plugins/updraftp.../methods
File: dropbox.php
try {
[500] Fix | Delete
$dropbox->delete($ufile);
[501] Fix | Delete
$file_success = 1;
[502] Fix | Delete
} catch (Exception $e) {
[503] Fix | Delete
$this->log($e->getMessage().' (line: '.$e->getLine().', file: '.$e->getFile().')');
[504] Fix | Delete
}
[505] Fix | Delete
[506] Fix | Delete
if (isset($file_success)) {
[507] Fix | Delete
$this->log('deletion succeeded');
[508] Fix | Delete
} else {
[509] Fix | Delete
$this->log('deletion failed');
[510] Fix | Delete
$any_failures = true;
[511] Fix | Delete
}
[512] Fix | Delete
}
[513] Fix | Delete
[514] Fix | Delete
return $any_failures ? 'file_delete_error' : true;
[515] Fix | Delete
[516] Fix | Delete
}
[517] Fix | Delete
[518] Fix | Delete
public function download($file) {
[519] Fix | Delete
[520] Fix | Delete
global $updraftplus;
[521] Fix | Delete
[522] Fix | Delete
$opts = $this->get_options();
[523] Fix | Delete
[524] Fix | Delete
if (empty($opts['tk_access_token'])) {
[525] Fix | Delete
$this->log('You do not appear to be authenticated with Dropbox (4)');
[526] Fix | Delete
$this->log(sprintf(__('You do not appear to be authenticated with %s', 'updraftplus'), 'Dropbox'), 'error');
[527] Fix | Delete
return false;
[528] Fix | Delete
}
[529] Fix | Delete
[530] Fix | Delete
try {
[531] Fix | Delete
$dropbox = $this->bootstrap();
[532] Fix | Delete
} catch (Exception $e) {
[533] Fix | Delete
$this->log($e->getMessage().' (line: '.$e->getLine().', file: '.$e->getFile().')');
[534] Fix | Delete
$this->log($e->getMessage().' (line: '.$e->getLine().', file: '.$e->getFile().')', 'error');
[535] Fix | Delete
return false;
[536] Fix | Delete
}
[537] Fix | Delete
if (false === $dropbox) return false;
[538] Fix | Delete
[539] Fix | Delete
$remote_files = $this->listfiles($file);
[540] Fix | Delete
[541] Fix | Delete
foreach ($remote_files as $file_info) {
[542] Fix | Delete
if ($file_info['name'] == $file) {
[543] Fix | Delete
return $updraftplus->chunked_download($file, $this, $file_info['size'], apply_filters('updraftplus_dropbox_downloads_manually_break_up', false), null, 2*1048576);
[544] Fix | Delete
}
[545] Fix | Delete
}
[546] Fix | Delete
[547] Fix | Delete
$this->log("$file: file not found in listing of remote directory");
[548] Fix | Delete
[549] Fix | Delete
return false;
[550] Fix | Delete
}
[551] Fix | Delete
[552] Fix | Delete
/**
[553] Fix | Delete
* Callback used by by chunked downloading API
[554] Fix | Delete
*
[555] Fix | Delete
* @param String $file - the file (basename) to be downloaded
[556] Fix | Delete
* @param Array $headers - supplied headers
[557] Fix | Delete
* @param Mixed $data - pass-back from our call to the API (which we don't use)
[558] Fix | Delete
* @param resource $fh - the local file handle
[559] Fix | Delete
*
[560] Fix | Delete
* @return String - the data downloaded
[561] Fix | Delete
*/
[562] Fix | Delete
public function chunked_download($file, $headers, $data, $fh) {// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
[563] Fix | Delete
[564] Fix | Delete
$opts = $this->get_options();// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- filter use
[565] Fix | Delete
$storage = $this->get_storage();
[566] Fix | Delete
[567] Fix | Delete
$try_the_other_one = false;// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- filter use
[568] Fix | Delete
[569] Fix | Delete
$ufile = apply_filters('updraftplus_dropbox_modpath', $file, $this);
[570] Fix | Delete
[571] Fix | Delete
$options = array();
[572] Fix | Delete
[573] Fix | Delete
if (!empty($headers)) $options['headers'] = $headers;
[574] Fix | Delete
[575] Fix | Delete
try {
[576] Fix | Delete
$get = $storage->download($ufile, $fh, $options);
[577] Fix | Delete
} catch (Exception $e) {
[578] Fix | Delete
$this->log($e);
[579] Fix | Delete
$this->log($e->getMessage(), 'error');
[580] Fix | Delete
$get = false;
[581] Fix | Delete
}
[582] Fix | Delete
[583] Fix | Delete
return $get;
[584] Fix | Delete
}
[585] Fix | Delete
[586] Fix | Delete
/**
[587] Fix | Delete
* Get the pre configuration template
[588] Fix | Delete
*
[589] Fix | Delete
* @return String - the template
[590] Fix | Delete
*/
[591] Fix | Delete
public function get_pre_configuration_template() {
[592] Fix | Delete
[593] Fix | Delete
global $updraftplus_admin;
[594] Fix | Delete
[595] Fix | Delete
$classes = $this->get_css_classes(false);
[596] Fix | Delete
[597] Fix | Delete
?>
[598] Fix | Delete
<tr class="<?php echo $classes . ' ' . 'dropbox_pre_config_container';?>">
[599] Fix | Delete
<td colspan="2">
[600] Fix | Delete
<img alt="<?php _e(sprintf(__('%s logo', 'updraftplus'), 'Dropbox')); ?>" src="<?php echo UPDRAFTPLUS_URL.'/images/dropbox-logo.png'; ?>">
[601] Fix | Delete
<br>
[602] Fix | Delete
<p>
[603] Fix | Delete
<?php
[604] Fix | Delete
global $updraftplus_admin;
[605] Fix | Delete
$updraftplus_admin->curl_check('Dropbox', false, 'dropbox');
[606] Fix | Delete
?>
[607] Fix | Delete
</p>
[608] Fix | Delete
<p>
[609] Fix | Delete
<?php echo sprintf(__('Please read %s for use of our %s authorization app (none of your backup data is sent to us).', 'updraftplus'), '<a target="_blank" href="https://updraftplus.com/faqs/what-is-your-privacy-policy-for-the-use-of-your-dropbox-app/">'.__('this privacy policy', 'updraftplus').'</a>', 'Dropbox');?>
[610] Fix | Delete
</p>
[611] Fix | Delete
</td>
[612] Fix | Delete
</tr>
[613] Fix | Delete
[614] Fix | Delete
<?php
[615] Fix | Delete
}
[616] Fix | Delete
[617] Fix | Delete
/**
[618] Fix | Delete
* Get the configuration template
[619] Fix | Delete
*
[620] Fix | Delete
* @return String - the template, ready for substitutions to be carried out
[621] Fix | Delete
*/
[622] Fix | Delete
public function get_configuration_template() {
[623] Fix | Delete
ob_start();
[624] Fix | Delete
$classes = $this->get_css_classes();
[625] Fix | Delete
[626] Fix | Delete
$defmsg = '<tr class="'.$classes.'"><td></td><td><strong>'.__('Need to use sub-folders?', 'updraftplus').'</strong> '.sprintf(__('Backups are saved in %s.', 'updraftplus'), 'apps/UpdraftPlus').' '.sprintf(__('If you backup several sites into the same Dropbox and want to organize with sub-folders, then %scheck out Premium%s', 'updraftplus'), '<a href="'.apply_filters("updraftplus_com_link", "https://updraftplus.com/shop/").'" target="_blank">', '</a>').'</td></tr>';
[627] Fix | Delete
[628] Fix | Delete
$extra_config = apply_filters('updraftplus_dropbox_extra_config_template', $defmsg, $this);
[629] Fix | Delete
echo $extra_config;
[630] Fix | Delete
?>
[631] Fix | Delete
<tr class="<?php echo $classes;?>">
[632] Fix | Delete
<th><?php echo sprintf(__('Authenticate with %s', 'updraftplus'), __('Dropbox', 'updraftplus'));?>:</th>
[633] Fix | Delete
<td>
[634] Fix | Delete
{{#if is_authenticated}}
[635] Fix | Delete
<?php
[636] Fix | Delete
echo "<p><strong>".__('(You appear to be already authenticated).', 'updraftplus')."</strong>";
[637] Fix | Delete
$this->get_deauthentication_link();
[638] Fix | Delete
echo '</p>';
[639] Fix | Delete
?>
[640] Fix | Delete
{{/if}}
[641] Fix | Delete
{{#if ownername_sentence}}
[642] Fix | Delete
<br/>
[643] Fix | Delete
{{ownername_sentence}}
[644] Fix | Delete
{{/if}}
[645] Fix | Delete
<?php
[646] Fix | Delete
echo '<p>';
[647] Fix | Delete
$this->get_authentication_link();
[648] Fix | Delete
echo '</p>';
[649] Fix | Delete
?>
[650] Fix | Delete
</td>
[651] Fix | Delete
</tr>
[652] Fix | Delete
{{!-- Legacy: only show this next setting to old users who had a setting stored --}}
[653] Fix | Delete
{{#if old_user_settings}}
[654] Fix | Delete
<tr class="<?php echo $classes;?>">
[655] Fix | Delete
<th></th>
[656] Fix | Delete
<td>
[657] Fix | Delete
<?php echo '<p>'.htmlspecialchars(__('You must add the following as the authorised redirect URI in your Dropbox console (under "API Settings") when asked', 'updraftplus')).': <kbd>'.UpdraftPlus_Options::admin_page_url().'?page=updraftplus&action=updraftmethod-dropbox-auth</kbd></p>'; ?>
[658] Fix | Delete
</td>
[659] Fix | Delete
</tr>
[660] Fix | Delete
<tr class="<?php echo $classes;?>">
[661] Fix | Delete
<th>Your Dropbox App Key:</th>
[662] Fix | Delete
<td><input type="text" autocomplete="off" style="width:332px" <?php $this->output_settings_field_name_and_id('appkey');?> value="{{appkey}}" /></td>
[663] Fix | Delete
</tr>
[664] Fix | Delete
<tr class="<?php echo $classes;?>">
[665] Fix | Delete
<th>Your Dropbox App Secret:</th>
[666] Fix | Delete
<td><input type="text" style="width:332px" <?php $this->output_settings_field_name_and_id('secret');?> value="{{secret}}" /></td>
[667] Fix | Delete
</tr>
[668] Fix | Delete
{{else}}
[669] Fix | Delete
<?php if (false === strpos($extra_config, '<input')) {
[670] Fix | Delete
// We need to make sure that it is not the case that the module has no settings whatsoever - this can result in the module being effectively invisible.
[671] Fix | Delete
?>
[672] Fix | Delete
<input type="hidden" <?php $this->output_settings_field_name_and_id('dummy-nosave');?> value="0">
[673] Fix | Delete
<?php } ?>
[674] Fix | Delete
{{/if}}
[675] Fix | Delete
<?php
[676] Fix | Delete
return ob_get_clean();
[677] Fix | Delete
}
[678] Fix | Delete
[679] Fix | Delete
/**
[680] Fix | Delete
* Modifies handerbar template options
[681] Fix | Delete
*
[682] Fix | Delete
* @param array $opts
[683] Fix | Delete
* @return Array - Modified handerbar template options
[684] Fix | Delete
*/
[685] Fix | Delete
public function transform_options_for_template($opts) {
[686] Fix | Delete
if (!empty($opts['tk_access_token'])) {
[687] Fix | Delete
$opts['ownername'] = empty($opts['ownername']) ? '' : $opts['ownername'];
[688] Fix | Delete
if ($opts['ownername']) {
[689] Fix | Delete
$opts['ownername_sentence'] = sprintf(__("Account holder's name: %s.", 'updraftplus'), $opts['ownername']).' ';
[690] Fix | Delete
}
[691] Fix | Delete
$opts['is_authenticated'] = true;
[692] Fix | Delete
}
[693] Fix | Delete
$opts['old_user_settings'] = (!empty($opts['appkey']) || (defined('UPDRAFTPLUS_CUSTOM_DROPBOX_APP') && UPDRAFTPLUS_CUSTOM_DROPBOX_APP));
[694] Fix | Delete
if ($opts['old_user_settings']) {
[695] Fix | Delete
$opts['appkey'] = empty($opts['appkey']) ? '' : $opts['appkey'];
[696] Fix | Delete
$opts['secret'] = empty($opts['secret']) ? '' : $opts['secret'];
[697] Fix | Delete
}
[698] Fix | Delete
$opts = apply_filters("updraftplus_options_dropbox_options", $opts);
[699] Fix | Delete
return $opts;
[700] Fix | Delete
}
[701] Fix | Delete
[702] Fix | Delete
/**
[703] Fix | Delete
* Gives settings keys which values should not passed to handlebarsjs context.
[704] Fix | Delete
* The settings stored in UD in the database sometimes also include internal information that it would be best not to send to the front-end (so that it can't be stolen by a man-in-the-middle attacker)
[705] Fix | Delete
*
[706] Fix | Delete
* @return Array - Settings array keys which should be filtered
[707] Fix | Delete
*/
[708] Fix | Delete
public function filter_frontend_settings_keys() {
[709] Fix | Delete
return array(
[710] Fix | Delete
'CSRF',
[711] Fix | Delete
'code',
[712] Fix | Delete
'ownername',
[713] Fix | Delete
'tk_access_token',
[714] Fix | Delete
);
[715] Fix | Delete
}
[716] Fix | Delete
[717] Fix | Delete
/**
[718] Fix | Delete
* Over-rides the parent to allow this method to output extra information about using the correct account for OAuth authentication
[719] Fix | Delete
*
[720] Fix | Delete
* @return [boolean] - return false so that no extra information is output
[721] Fix | Delete
*/
[722] Fix | Delete
public function output_account_warning() {
[723] Fix | Delete
return true;
[724] Fix | Delete
}
[725] Fix | Delete
[726] Fix | Delete
/**
[727] Fix | Delete
* Handles various URL actions, as indicated by the updraftplus_dropboxauth URL parameter
[728] Fix | Delete
*
[729] Fix | Delete
* @return null
[730] Fix | Delete
*/
[731] Fix | Delete
public function action_auth() {
[732] Fix | Delete
if (isset($_GET['updraftplus_dropboxauth'])) {
[733] Fix | Delete
if ('doit' == $_GET['updraftplus_dropboxauth']) {
[734] Fix | Delete
$this->action_authenticate_storage();
[735] Fix | Delete
return;
[736] Fix | Delete
} elseif ('deauth' == $_GET['updraftplus_dropboxauth']) {
[737] Fix | Delete
$this->action_deauthenticate_storage();
[738] Fix | Delete
return;
[739] Fix | Delete
}
[740] Fix | Delete
} elseif (isset($_REQUEST['state'])) {
[741] Fix | Delete
[742] Fix | Delete
if ('POST' == $_SERVER['REQUEST_METHOD']) {
[743] Fix | Delete
$raw_state = urldecode($_POST['state']);
[744] Fix | Delete
if (isset($_POST['code'])) $raw_code = urldecode($_POST['code']);
[745] Fix | Delete
} else {
[746] Fix | Delete
$raw_state = $_GET['state'];
[747] Fix | Delete
if (isset($_GET['code'])) $raw_code = $_GET['code'];
[748] Fix | Delete
}
[749] Fix | Delete
[750] Fix | Delete
$this->do_complete_authentication($raw_state, $raw_code);
[751] Fix | Delete
}
[752] Fix | Delete
try {
[753] Fix | Delete
$this->auth_request();
[754] Fix | Delete
} catch (Exception $e) {
[755] Fix | Delete
$this->log(sprintf(__("%s error: %s", 'updraftplus'), sprintf(__("%s authentication", 'updraftplus'), 'Dropbox'), $e->getMessage()), 'error');
[756] Fix | Delete
}
[757] Fix | Delete
}
[758] Fix | Delete
[759] Fix | Delete
/**
[760] Fix | Delete
* This function will complete the oAuth flow, if return_instead_of_echo is true then add the action to display the authed admin notice, otherwise echo this notice to page.
[761] Fix | Delete
*
[762] Fix | Delete
* @param string $raw_state - the state
[763] Fix | Delete
* @param string $raw_code - the oauth code
[764] Fix | Delete
* @param boolean $return_instead_of_echo - a boolean to indicate if we should return the result or echo it
[765] Fix | Delete
*
[766] Fix | Delete
* @return void|string - returns the authentication message if return_instead_of_echo is true
[767] Fix | Delete
*/
[768] Fix | Delete
public function do_complete_authentication($raw_state, $raw_code, $return_instead_of_echo = false) {
[769] Fix | Delete
// Get the CSRF from setting and check it matches the one returned if it does no CSRF attack has happened
[770] Fix | Delete
$opts = $this->get_options();
[771] Fix | Delete
$csrf = $opts['CSRF'];
[772] Fix | Delete
$state = stripslashes($raw_state);
[773] Fix | Delete
// Check the state to see if an instance_id has been attached and if it has then extract the state
[774] Fix | Delete
$parts = explode(':', $state);
[775] Fix | Delete
$state = $parts[0];
[776] Fix | Delete
[777] Fix | Delete
if (strcmp($csrf, $state) == 0) {
[778] Fix | Delete
$opts['CSRF'] = '';
[779] Fix | Delete
if (isset($raw_code)) {
[780] Fix | Delete
// set code so it can be accessed in the next authentication step
[781] Fix | Delete
$opts['code'] = stripslashes($raw_code);
[782] Fix | Delete
// remove our flag so we know this authentication is complete
[783] Fix | Delete
if (isset($opts['auth_in_progress'])) unset($opts['auth_in_progress']);
[784] Fix | Delete
$this->set_options($opts, true);
[785] Fix | Delete
$auth_result = $this->auth_token($return_instead_of_echo);
[786] Fix | Delete
if ($return_instead_of_echo) return $auth_result;
[787] Fix | Delete
}
[788] Fix | Delete
} else {
[789] Fix | Delete
error_log("UpdraftPlus: CSRF comparison failure: $csrf != $state");
[790] Fix | Delete
}
[791] Fix | Delete
}
[792] Fix | Delete
[793] Fix | Delete
/**
[794] Fix | Delete
* This method will reset any saved options and start the bootstrap process for an authentication
[795] Fix | Delete
*
[796] Fix | Delete
* @param String $instance_id - the instance id of the settings we want to authenticate
[797] Fix | Delete
*/
[798] Fix | Delete
public function do_authenticate_storage($instance_id) {
[799] Fix | Delete
try {
[800] Fix | Delete
// Clear out the existing credentials
[801] Fix | Delete
$opts = $this->get_options();
[802] Fix | Delete
$opts['tk_access_token'] = '';
[803] Fix | Delete
unset($opts['tk_request_token']);
[804] Fix | Delete
$opts['ownername'] = '';
[805] Fix | Delete
// Set a flag so we know this authentication is in progress
[806] Fix | Delete
$opts['auth_in_progress'] = true;
[807] Fix | Delete
$this->set_options($opts, true);
[808] Fix | Delete
[809] Fix | Delete
$this->set_instance_id($instance_id);
[810] Fix | Delete
$this->bootstrap(false);
[811] Fix | Delete
} catch (Exception $e) {
[812] Fix | Delete
$this->log(sprintf(__("%s error: %s", 'updraftplus'), sprintf(__("%s authentication", 'updraftplus'), 'Dropbox'), $e->getMessage()), 'error');
[813] Fix | Delete
}
[814] Fix | Delete
}
[815] Fix | Delete
[816] Fix | Delete
/**
[817] Fix | Delete
* This method will start the bootstrap process for a de-authentication
[818] Fix | Delete
*
[819] Fix | Delete
* @param String $instance_id - the instance id of the settings we want to de-authenticate
[820] Fix | Delete
*/
[821] Fix | Delete
public function do_deauthenticate_storage($instance_id) {
[822] Fix | Delete
try {
[823] Fix | Delete
$this->set_instance_id($instance_id);
[824] Fix | Delete
$this->bootstrap(true);
[825] Fix | Delete
} catch (Exception $e) {
[826] Fix | Delete
$this->log(sprintf(__("%s error: %s", 'updraftplus'), sprintf(__("%s de-authentication", 'updraftplus'), 'Dropbox'), $e->getMessage()), 'error');
[827] Fix | Delete
}
[828] Fix | Delete
}
[829] Fix | Delete
[830] Fix | Delete
/**
[831] Fix | Delete
* This method will setup the authenticated admin warning, it can either return this or echo it
[832] Fix | Delete
*
[833] Fix | Delete
* @param boolean $return_instead_of_echo - a boolean to indicate if we should return the result or echo it
[834] Fix | Delete
*
[835] Fix | Delete
* @return void|string - returns the authentication message if return_instead_of_echo is true
[836] Fix | Delete
*/
[837] Fix | Delete
public function show_authed_admin_warning($return_instead_of_echo) {
[838] Fix | Delete
global $updraftplus_admin;
[839] Fix | Delete
[840] Fix | Delete
$dropbox = $this->bootstrap();
[841] Fix | Delete
if (false === $dropbox) return false;
[842] Fix | Delete
[843] Fix | Delete
try {
[844] Fix | Delete
$account_info = $dropbox->accountInfo();
[845] Fix | Delete
} catch (Exception $e) {
[846] Fix | Delete
$accountinfo_err = sprintf(__("%s error: %s", 'updraftplus'), 'Dropbox', $e->getMessage()).' ('.$e->getCode().')';
[847] Fix | Delete
}
[848] Fix | Delete
[849] Fix | Delete
$message = "<strong>".__('Success:', 'updraftplus').'</strong> '.sprintf(__('you have authenticated your %s account', 'updraftplus'), 'Dropbox');
[850] Fix | Delete
// We log, because otherwise people get confused by the most recent log message of 'Parameter not found: oauth_token' and raise support requests
[851] Fix | Delete
$this->log(__('Success:', 'updraftplus').' '.sprintf(__('you have authenticated your %s account', 'updraftplus'), 'Dropbox'));
[852] Fix | Delete
[853] Fix | Delete
if (empty($account_info['code']) || "200" != $account_info['code']) {
[854] Fix | Delete
$message .= " (".__('though part of the returned information was not as expected - your mileage may vary', 'updraftplus').") ". $account_info['code'];
[855] Fix | Delete
if (!empty($accountinfo_err)) $message .= "<br>".htmlspecialchars($accountinfo_err);
[856] Fix | Delete
} else {
[857] Fix | Delete
$body = $account_info['body'];
[858] Fix | Delete
$name = '';
[859] Fix | Delete
if (isset($body->display_name)) {
[860] Fix | Delete
$name = $body->display_name;
[861] Fix | Delete
} else {
[862] Fix | Delete
$name = $body->name->display_name;
[863] Fix | Delete
}
[864] Fix | Delete
$message .= ". <br>".sprintf(__('Your %s account name: %s', 'updraftplus'), 'Dropbox', htmlspecialchars($name));
[865] Fix | Delete
$opts = $this->get_options();
[866] Fix | Delete
$opts['ownername'] = $name;
[867] Fix | Delete
$this->set_options($opts, true);
[868] Fix | Delete
[869] Fix | Delete
try {
[870] Fix | Delete
/**
[871] Fix | Delete
* Quota information is no longer provided with account information a new call to qoutaInfo must be made to get this information. The timeout is because we've seen cases where it returned after 180 seconds (apparently a faulty outgoing proxy), and we may as well wait as cause an error leading to user confusion.
[872] Fix | Delete
*/
[873] Fix | Delete
$quota_info = $dropbox->quotaInfo(array('timeout' => 190));
[874] Fix | Delete
[875] Fix | Delete
if (empty($quota_info['code']) || "200" != $quota_info['code']) {
[876] Fix | Delete
$message .= " (".__('though part of the returned information was not as expected - your mileage may vary', 'updraftplus').")". $quota_info['code'];
[877] Fix | Delete
if (!empty($accountinfo_err)) $message .= "<br>".htmlspecialchars($accountinfo_err);
[878] Fix | Delete
} else {
[879] Fix | Delete
$body = $quota_info['body'];
[880] Fix | Delete
if (isset($body->quota_info)) {
[881] Fix | Delete
$quota_info = $body->quota_info;
[882] Fix | Delete
$total_quota = max($quota_info->quota, 1);
[883] Fix | Delete
$normal_quota = $quota_info->normal;
[884] Fix | Delete
$shared_quota = $quota_info->shared;
[885] Fix | Delete
$available_quota =$total_quota - ($normal_quota + $shared_quota);
[886] Fix | Delete
$used_perc = round(($normal_quota + $shared_quota)*100/$total_quota, 1);
[887] Fix | Delete
$message .= ' <br>'.sprintf(__('Your %s quota usage: %s %% used, %s available', 'updraftplus'), 'Dropbox', $used_perc, round($available_quota/1048576, 1).' MB');
[888] Fix | Delete
} else {
[889] Fix | Delete
$total_quota = max($body->allocation->allocated, 1);
[890] Fix | Delete
$used = $body->used;
[891] Fix | Delete
/* check here to see if the account is a team account and if so use the other used value
[892] Fix | Delete
This will give us their total usage including their individual account and team account */
[893] Fix | Delete
if (isset($body->allocation->used)) $used = $body->allocation->used;
[894] Fix | Delete
$available_quota =$total_quota - $used;
[895] Fix | Delete
$used_perc = round($used*100/$total_quota, 1);
[896] Fix | Delete
$message .= ' <br>'.sprintf(__('Your %s quota usage: %s %% used, %s available', 'updraftplus'), 'Dropbox', $used_perc, round($available_quota/1048576, 1).' MB');
[897] Fix | Delete
}
[898] Fix | Delete
}
[899] Fix | Delete
} catch (Exception $e) {
[900] Fix | Delete
// Catch
[901] Fix | Delete
}
[902] Fix | Delete
[903] Fix | Delete
}
[904] Fix | Delete
if ($return_instead_of_echo) {
[905] Fix | Delete
return "<div class='updraftmessage updated'><p>{$message}</p></div>";
[906] Fix | Delete
} else {
[907] Fix | Delete
$updraftplus_admin->show_admin_warning($message);
[908] Fix | Delete
}
[909] Fix | Delete
[910] Fix | Delete
}
[911] Fix | Delete
[912] Fix | Delete
/**
[913] Fix | Delete
* Bootstrap and check token, can also return the authentication method if return_instead_of_echo is true
[914] Fix | Delete
*
[915] Fix | Delete
* @param boolean $return_instead_of_echo - a boolean to indicate if we should return the result or echo it
[916] Fix | Delete
*
[917] Fix | Delete
* @return void|string - returns the authentication message if return_instead_of_echo is true
[918] Fix | Delete
*/
[919] Fix | Delete
public function auth_token($return_instead_of_echo) {
[920] Fix | Delete
$this->bootstrap();
[921] Fix | Delete
$opts = $this->get_options();
[922] Fix | Delete
if (!empty($opts['tk_access_token'])) {
[923] Fix | Delete
if ($return_instead_of_echo) {
[924] Fix | Delete
return $this->show_authed_admin_warning($return_instead_of_echo);
[925] Fix | Delete
} else {
[926] Fix | Delete
add_action('all_admin_notices', array($this, 'show_authed_admin_warning'));
[927] Fix | Delete
}
[928] Fix | Delete
}
[929] Fix | Delete
}
[930] Fix | Delete
[931] Fix | Delete
/**
[932] Fix | Delete
* Acquire single-use authorization code
[933] Fix | Delete
*/
[934] Fix | Delete
public function auth_request() {
[935] Fix | Delete
$this->bootstrap();
[936] Fix | Delete
}
[937] Fix | Delete
[938] Fix | Delete
/**
[939] Fix | Delete
* This basically reproduces the relevant bits of bootstrap.php from the SDK
[940] Fix | Delete
*
[941] Fix | Delete
* @param Boolean $deauthenticate indicates if we should bootstrap for a deauth or auth request
[942] Fix | Delete
* @return object
[943] Fix | Delete
*/
[944] Fix | Delete
public function bootstrap($deauthenticate = false) {
[945] Fix | Delete
[946] Fix | Delete
$storage = $this->get_storage();
[947] Fix | Delete
[948] Fix | Delete
if (!empty($storage) && !is_wp_error($storage)) return $storage;
[949] Fix | Delete
[950] Fix | Delete
// Dropbox APIv1 is dead, but we'll keep the variable in case v3 is ever announced
[951] Fix | Delete
$dropbox_api = 'Dropbox2';
[952] Fix | Delete
[953] Fix | Delete
include_once(UPDRAFTPLUS_DIR.'/includes/'.$dropbox_api.'/API.php');
[954] Fix | Delete
include_once(UPDRAFTPLUS_DIR.'/includes/'.$dropbox_api.'/Exception.php');
[955] Fix | Delete
include_once(UPDRAFTPLUS_DIR.'/includes/'.$dropbox_api.'/OAuth/Consumer/ConsumerAbstract.php');
[956] Fix | Delete
include_once(UPDRAFTPLUS_DIR.'/includes/'.$dropbox_api.'/OAuth/Storage/StorageInterface.php');
[957] Fix | Delete
include_once(UPDRAFTPLUS_DIR.'/includes/'.$dropbox_api.'/OAuth/Storage/Encrypter.php');
[958] Fix | Delete
include_once(UPDRAFTPLUS_DIR.'/includes/'.$dropbox_api.'/OAuth/Storage/WordPress.php');
[959] Fix | Delete
include_once(UPDRAFTPLUS_DIR.'/includes/'.$dropbox_api.'/OAuth/Consumer/Curl.php');
[960] Fix | Delete
// require_once(UPDRAFTPLUS_DIR.'/includes/'.$dropbox_api.'/OAuth/Consumer/WordPress.php');
[961] Fix | Delete
[962] Fix | Delete
$opts = $this->get_options();
[963] Fix | Delete
[964] Fix | Delete
$key = empty($opts['secret']) ? '' : $opts['secret'];
[965] Fix | Delete
$sec = empty($opts['appkey']) ? '' : $opts['appkey'];
[966] Fix | Delete
[967] Fix | Delete
$oauth2_id = defined('UPDRAFTPLUS_DROPBOX_CLIENT_ID') ? UPDRAFTPLUS_DROPBOX_CLIENT_ID : base64_decode('dzQxM3o0cWhqejY1Nm5l');
[968] Fix | Delete
[969] Fix | Delete
// Set the callback URL
[970] Fix | Delete
$callbackhome = UpdraftPlus_Options::admin_page_url().'?page=updraftplus&action=updraftmethod-dropbox-auth';
[971] Fix | Delete
$callback = defined('UPDRAFTPLUS_DROPBOX_AUTH_RETURN_URL') ? UPDRAFTPLUS_DROPBOX_AUTH_RETURN_URL : 'https://auth.updraftplus.com/auth/dropbox/';
[972] Fix | Delete
[973] Fix | Delete
$instance_id = $this->get_instance_id();
[974] Fix | Delete
// Instantiate the Encrypter and storage objects
[975] Fix | Delete
$encrypter = new Dropbox_Encrypter('ThisOneDoesNotMatterBeyondLength');
[976] Fix | Delete
[977] Fix | Delete
// Instantiate the storage
[978] Fix | Delete
$dropbox_storage = new Dropbox_WordPress($encrypter, "tk_", 'updraft_dropbox', $this);
[979] Fix | Delete
[980] Fix | Delete
// WordPress consumer does not yet work
[981] Fix | Delete
// $oauth = new Dropbox_ConsumerWordPress($sec, $key, $dropbox_storage, $callback);
[982] Fix | Delete
[983] Fix | Delete
// Get the DropBox API access details
[984] Fix | Delete
list($d2, $d1) = $this->defaults();
[985] Fix | Delete
if (empty($sec)) {
[986] Fix | Delete
$sec = base64_decode($d1);
[987] Fix | Delete
}
[988] Fix | Delete
[989] Fix | Delete
if (empty($key)) {
[990] Fix | Delete
$key = base64_decode($d2);
[991] Fix | Delete
}
[992] Fix | Delete
[993] Fix | Delete
$root = 'sandbox';
[994] Fix | Delete
if ('dropbox:' == substr($sec, 0, 8)) {
[995] Fix | Delete
$sec = substr($sec, 8);
[996] Fix | Delete
$root = 'dropbox';
[997] Fix | Delete
}
[998] Fix | Delete
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function