| 1 |
<?php |
| 2 |
include plugin_dir_path(__FILE__).'DropboxClient.php'; |
| 3 |
$dropbox = new DropboxClient(array( |
| 4 |
'app_key' => "cv3o964lig1qrga", |
| 5 |
'app_secret' => "7g05tjesk5fgqjk", |
| 6 |
'app_full_access' => false, |
| 7 |
),'en'); |
| 8 |
|
| 9 |
handle_dropbox_auth($dropbox); // see below |
| 10 |
// if there is no upload, show the form |
| 11 |
|
| 12 |
|
| 13 |
// store_token, load_token, delete_token are SAMPLE functions! please replace with your own! |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
function store_token($token, $name) |
| 18 |
{ |
| 19 |
|
| 20 |
file_put_contents(plugin_dir_path(__FILE__)."tokens/$name.token", serialize($token)); |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
function load_token($name) |
| 25 |
{ |
| 26 |
if(!file_exists(plugin_dir_path(__FILE__)."tokens/$name.token")) return null; |
| 27 |
return @unserialize(@file_get_contents(plugin_dir_path(__FILE__)."tokens/$name.token")); |
| 28 |
} |
| 29 |
|
| 30 |
function delete_token($name) |
| 31 |
{ |
| 32 |
@unlink(plugin_dir_path(__FILE__)."tokens/$name.token"); |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
function handle_dropbox_auth($dropbox) |
| 40 |
{ |
| 41 |
// first try to load existing access token |
| 42 |
$access_token = load_token("access"); |
| 43 |
|
| 44 |
if(!empty($access_token)) { |
| 45 |
|
| 46 |
$dropbox->SetAccessToken($access_token); |
| 47 |
} |
| 48 |
elseif(!empty($_GET['auth_callback'])) // are we coming from dropbox's oauth page? |
| 49 |
{ |
| 50 |
|
| 51 |
// then load our previosly created request token |
| 52 |
$request_token = load_token($_GET['oauth_token']); |
| 53 |
|
| 54 |
|
| 55 |
if(empty($request_token)) die('Request token not found!'); |
| 56 |
// get & store access token, the request token is not needed anymore |
| 57 |
$access_token = $dropbox->GetAccessToken($request_token); |
| 58 |
store_token($access_token, "access"); |
| 59 |
delete_token($_GET['oauth_token']); |
| 60 |
} |
| 61 |
// checks if access token is required |
| 62 |
|
| 63 |
|
| 64 |
if($dropbox->IsAuthorized()) |
| 65 |
{ |
| 66 |
$dropb_autho="yes"; |
| 67 |
update_option('dropb_autho', $dropb_autho ); |
| 68 |
echo '<h3>Dropbox Account Details</h3>'; |
| 69 |
$account_info = $dropbox->GetAccountInfo(); |
| 70 |
$used = round(($account_info->quota_info->quota - ($account_info->quota_info->normal + $account_info->quota_info->shared)) / 1073741824, 1); |
| 71 |
$quota = round($account_info->quota_info->quota / 1073741824, 1); |
| 72 |
echo $account_info->display_name . ', ' .'you have'. ' ' .$used .'GB' .'of'. ' ' . $quota . 'GB (' . round(($used / $quota) * 100, 0) .'%) ' .'free'; |
| 73 |
|
| 74 |
echo '</br><p>Unlink Account for local backups</p></br>'; |
| 75 |
echo '<td><a href="'.get_bloginfo('url').'/wp-admin/tools.php?page=wp-database-backup&action=unlink" class="button-primary">Unlink Account<a/>'; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
} |
| 81 |
|
| 82 |
else |
| 83 |
{ |
| 84 |
$dropb_autho="no"; |
| 85 |
update_option('dropb_autho', $dropb_autho ); |
| 86 |
// redirect user to dropbox oauth page |
| 87 |
$return_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']."?page=wp-database-backup&auth_callback=1"; |
| 88 |
$auth_url = $dropbox->BuildAuthorizeUrl($return_url); |
| 89 |
$request_token = $dropbox->GetRequestToken(); |
| 90 |
store_token($request_token, $request_token['t']); |
| 91 |
|
| 92 |
?> |
| 93 |
<style> |
| 94 |
#adminmenuwrap { |
| 95 |
padding-bottom: 838px; |
| 96 |
} |
| 97 |
</style> |
| 98 |
<h3>Dropbox</h3> |
| 99 |
<p>Define an Dropbox destination connection.</p> |
| 100 |
<p>In order to use Dropbox destination you will need to authorized it with your Dropbox account</p> |
| 101 |
<p>Please click the authorize button below and follow the instructions inside the pop up window</p> |
| 102 |
<p>For local backup leave the setting as it is</p> |
| 103 |
<p> |
| 104 |
<form action="" method="get"> |
| 105 |
<a href="<?php echo $auth_url?>"><input type="button" name="authorize" id="authorize" value="Authorize" |
| 106 |
class="button-primary" /></a><br/> |
| 107 |
</form> |
| 108 |
</p> |
| 109 |
<?php |
| 110 |
|
| 111 |
die(); |
| 112 |
//die("Authentication required".$auth_url); |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
?> |