/var/www/(Del)hsihk.com/wp-content/plugins/backupbuddy/destinations/dropbox2/_configure.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php
/*
 * Dropbox Destination for PHP 5.3+. Requires PHP 5.3+ and Curl.
 *
 * @author Dustin Bolton, July 2013.
 *
 * Incoming variables:
 *        $mode                    string        Mode for configuring this destination. Values:  add, edit, save
 *        $destination_settings    array        Array of this destination's configuration settings. Key => value pairs.
 *
 * Globally editable variables:
 *        $pb_hide_test            bool        Whether or not to hide the "Test" button. Modifiable.
 *        $pb_hide_save            bool        Whether or not to hide the "Save" button. Modifiable.
 *
 */
global $pb_hide_test,$pb_hide_save;
$pb_hide_test true// Always hiding test button for Dropbox.
$pb_hide_save true;



$show_config_form false;

if ( 
'add' == $mode ) { // ADD mode.
    
    
$webAuth = new \Dropbox\WebAuthNoRedirectpb_backupbuddy_destination_dropbox2::$appInfo'BackupBuddy v' pb_backupbuddy::settings'version' ), 'en' );
    
    
$bad_auth_code false;
    if ( 
'' != pb_backupbuddy::_POST'dropbox_authorization_code' ) ) { // Authorization code entered. Try it out before showing form or not.
        
        
        
$pb_hide_save false;
        
$authCode trimpb_backupbuddy::_POST'dropbox_authorization_code' ) );
        try {
            list( 
$accessToken$dropboxUserId ) = $webAuth->finish$authCode );
        } catch ( \
Exception $e ) {
            
pb_backupbuddy::alert'<b>Verify you authorized BackupBuddy access in Dropbox and copied the Dropbox authorization code exactly in the BackupBuddy field.</b><br><br>Error details: ' $e->getMessage(), true ); // '<br><br>' . pb_backupbuddy::$ui->button( pb_backupbuddy::page_url(), '&larr; go back & retry' )
            
$bad_auth_code true;
            
$pb_hide_save true;
        }
        
        if ( 
false === $bad_auth_code ) {
            
$dropboxClient = new \Dropbox\Client$accessToken'BackupBuddy v' pb_backupbuddy::settings'version' ) );
            
$accountInfo $dropboxClient->getAccountInfo();
            
$show_config_form true;
        }
        
    }
    
    
    if ( 
'' == pb_backupbuddy::_POST'dropbox_authorization_code' ) || ( true === $bad_auth_code ) ) { // No authorization code entered yet so user needs to authorize.
        
        
try {
            
$authorizeUrl $webAuth->start();
        } catch( 
Exception $e ) {
            
pb_backupbuddy::alert'Error #8778656: Dropbox error. Details: `' $e->getMessage() . '`.'true );
            return 
false;
        }
        
        echo 
'<form method="post" action="' pb_backupbuddy::ajax_url'destination_picker' ) . '&add=dropbox2&callback_data=' pb_backupbuddy::_GET'callback_data' ) . '">';
        echo 
'<br><b>Adding a Dropbox destination</b><ol>';
        echo 
'<li> <a href="' $authorizeUrl '" class="button-primary pb_dropbox_authorize" target="_new">' __('Connect to Dropbox.com & Authorize (opens new window)''it-l10n-backupbuddy' ) . '</a></li>';
        echo 
'<li>Click <b>Allow</b> in the new window (you may need to login to Dropbox.com first).</li>';
        echo 
'<li>Enter the provided <b>Authorization Code</b>: <input type="text" name="dropbox_authorization_code" size="45"></li>';
        echo 
'<li><input type="submit" class="button-primary" value="' __"Yes, I've Authorized BackupBuddy with Dropbox & Entered the Code above"'it-l10n-backupbuddy' ) . '"></li>';
        echo 
'</ol>';
        echo 
'</form>';
        
    } 
// end authorication code submitted.
    
} elseif ( 'edit' == $mode ) { // EDIT mode.
    
    
$accessToken $destination_settings['access_token'];
    try {
        
$dropboxClient = new \Dropbox\Client$accessToken'BackupBuddy v' pb_backupbuddy::settings'version' ) );
    } catch ( \
Exception $e ) {
        
pb_backupbuddy::alert'Dropbox Error #143838: ' $e->getMessage() . '<br><br>' pb_backupbuddy::$ui->buttonpb_backupbuddy::page_url(), '&larr; go back & retry' ), true );
        return 
false;
    }
    try {
        
$accountInfo $dropboxClient->getAccountInfo();
    } catch ( \
Exception $e ) {
        
pb_backupbuddy::alert'Dropbox Error #132852: ' $e->getMessage() . '<br><br>' pb_backupbuddy::$ui->buttonpb_backupbuddy::page_url(), '&larr; go back & retry' ), true );
        return 
false;
    }
    
    
$show_config_form true// Enable showing configuration form below.
    
} elseif ( 'save' == $mode ) {
    
    
$show_config_form true;
    
} else { 
// UNKNOWN mode.
    
    
die( 'Error #3283489434: Unknown destination form mode.' );
        
// End checking mode.



// Display configuration form.
if ( true === $show_config_form ) {
    
    if ( 
'save' != $mode ) {
        
// Account info.
        
$settings_form->add_setting( array(
            
'type'        =>        'plaintext',
            
'name'        =>        'plaintext_owner',
            
'title'        =>        __'Dropbox Owner''it-l10n-backupbuddy' ),
            
'default'    =>        $accountInfo['display_name'] . ' (UID: ' $accountInfo['uid'] . ') [<a href="' $accountInfo['referral_link'] . '" target="_new">' __('Referral Link''it-l10n-backupbuddy' ) .'</a>]',
        ) );
        
$settings_form->add_setting( array(
            
'type'        =>        'plaintext',
            
'name'        =>        'plaintext_email',
            
'title'        =>        __'Email''it-l10n-backupbuddy' ),
            
'default'    =>        $accountInfo['email'],
        ) );
        
$settings_form->add_setting( array(
            
'type'        =>        'plaintext',
            
'name'        =>        'plaintext_quotausage',
            
'title'        =>        __('Quota Usage''it-l10n-backupbuddy' ),
            
'default'    =>        pb_backupbuddy::$format->file_size$accountInfo['quota_info']['normal'] ) . ' normal + ' pb_backupbuddy::$format->file_size$accountInfo['quota_info']['shared'] ) . ' shared out of ' pb_backupbuddy::$format->file_size$accountInfo['quota_info']['quota'] ) . ' (' round( ( ( $accountInfo['quota_info']['normal']+$accountInfo['quota_info']['shared'] ) / $accountInfo['quota_info']['quota'] ) * 100) . '%)',
        ) );
    }
    
    
$default_name NULL;
    
// Settings.
    
if ( 'add' == $mode ) {
        
$default_name 'My Dropbox';
        
$settings_form->add_setting( array(
            
'type'        =>        'hidden',
            
'name'        =>        'access_token',
            
'title'        =>        'Access Token for oAuth2',
            
'rules'        =>        'required',
            
'default'    =>        $accessToken,
        ) );
    }
    
$settings_form->add_setting( array(
        
'type'        =>        'text',
        
'name'        =>        'title',
        
'title'        =>        __'Destination name''it-l10n-backupbuddy' ),
        
'tip'        =>        __'Name of the new destination to create. This is for your convenience only.''it-l10n-backupbuddy' ),
        
'rules'        =>        'required|string[1-45]',
        
'default'    =>        $default_name,
    ) );
    
$settings_form->add_setting( array(
        
'type'        =>        'text',
        
'name'        =>        'directory',
        
'title'        =>        __'Directory (optional)''it-l10n-backupbuddy' ),
        
'tip'        =>        __'[Example: backupbuddy or backupbuddy/mysite/ or myfiles/backups/mysite] - Directory (or subdirectory) name to place the backups within.''it-l10n-backupbuddy' ),
        
'rules'        =>        'string[0-250]',
    ) );
    
$settings_form->add_setting( array(
        
'type'        =>        'text',
        
'name'        =>        'archive_limit',
        
'title'        =>        __'Archive limit''it-l10n-backupbuddy' ),
        
'tip'        =>        __'[Example: 5] - Enter 0 for no limit. This is the maximum number of archives to be stored in this specific destination. If this limit is met the oldest backups will be deleted.''it-l10n-backupbuddy' ),
        
'rules'        =>        'required|int[0-9999999]',
        
'css'        =>        'width: 50px;',
        
'after'        =>        ' backups',
    ) );
    
$settings_form->add_setting( array(
        
'type'        =>        'text',
        
'name'        =>        'max_chunk_size',
        
'title'        =>        __'Max chunk size''it-l10n-backupbuddy' ),
        
'tip'        =>        __'[Example: 5] - Enter 0 for no chunking; minimum of 5 if enabling. This is the maximum file size to send in one whole piece. Files larger than this will be transferred in pieces up to this file size one part at a time. This allows to transfer of larger files than you server may allow by breaking up the send process. Chunked files may be delayed if there is little site traffic to trigger them.''it-l10n-backupbuddy' ),
        
'rules'        =>        'required|int[0-9999999]',
        
'css'        =>        'width: 50px;',
        
'after'        =>        ' MB (leave at 0 if unsure)',
    ) );
    if ( 
$mode !== 'edit' ) {
        
$settings_form->add_setting( array(
            
'type'        =>        'checkbox',
            
'name'        =>        'disable_file_management',
            
'options'    =>        array( 'unchecked' => '0''checked' => '1' ),
            
'title'        =>        __'Disable file management''it-l10n-backupbuddy' ),
            
'tip'        =>        __'[Default: unchecked] - When checked, selecting this destination disables browsing or accessing files stored at this destination from within BackupBuddy.''it-l10n-backupbuddy' ),
            
'css'        =>        '',
            
'rules'        =>        '',
        ) );
    }
    
// End showing config form.