class-settings-apikeys.php
8.84 KB
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<?php
/**
*
*/
class BackWPup_Pro_Settings_APIKeys {
private static $instance = NULL;
/**
*
*/
private function __construct() {
add_action( 'backwpup_page_settings_tab_apikey', array( $this, 'backwpup_hash' ) );
$destinations = BackWPup::get_registered_destinations();
if ( isset( $destinations[ 'DROPBOX' ] ) )
add_action( 'backwpup_page_settings_tab_apikey', array( $this, 'dropbox_keys_form' ) );
if ( isset( $destinations[ 'SUGARSYNC' ] ) )
add_action( 'backwpup_page_settings_tab_apikey', array( $this, 'sugarsync_keys_form' ) );
if ( isset( $destinations[ 'GDRIVE' ] ) )
add_action( 'backwpup_page_settings_tab_apikey', array( $this, 'google_keys_form' ) );
//save settings
add_action( 'backwpup_page_settings_save', array( $this, 'save_form' ) );
}
/**
* @return BackWPup_Pro_Settings_APIKeys|null
*/
public static function get_instance() {
if (NULL === self::$instance) {
self::$instance = new self;
}
return self::$instance;
}
public function backwpup_hash() {
?>
<h3><?php esc_html_e( 'Hash key', 'backwpup' ); ?></h3>
<p><?php esc_html_e( 'Hash Key for BackWPup. It will be used to have hashes in folder and file names. It must at least 6 chars long.', 'backwpup' ); ?></p>
<table class="form-table">
<tr>
<th scope="row"><label for="hashid"><?php esc_html_e( 'Hash key:', 'backwpup' ); ?></label></th>
<td>
<input name="hash" type="text" id="hashid" size="12"
value="<?php echo esc_attr( get_site_option( 'backwpup_cfg_hash' ) );?>"
class="code" autocomplete="off" maxlength="12" />
</td>
</tr>
</table>
<?php
}
public function dropbox_keys_form() {
?>
<h3><?php esc_html_e( 'Dropbox API Keys', 'backwpup' ); ?></h3>
<p><?php esc_html_e( 'If you want to set your own Dropbox API Keys, you can do it here. Leave empty for default.', 'backwpup' ); ?></p>
<table class="form-table">
<tr>
<th scope="row"><label for="dropboxappkey"><?php esc_html_e( 'Full Dropbox App key:', 'backwpup' ); ?></label></th>
<td>
<input name="dropboxappkey" type="text" id="dropboxappkey"
value="<?php echo esc_attr( get_site_option( 'backwpup_cfg_dropboxappkey' ) );?>"
class="regular-text" autocomplete="off" />
</td>
</tr>
<tr>
<th scope="row"><label for="dropboxappsecret"><?php esc_html_e( 'Full Dropbox App secret:', 'backwpup' ); ?></label></th>
<td>
<input name="dropboxappsecret" type="password" id="dropboxappsecret"
value="<?php echo esc_attr( get_site_option( 'backwpup_cfg_dropboxappsecret' ) );?>"
class="regular-text" autocomplete="off" />
</tr>
<tr>
<th scope="row"><label for="dropboxsandboxappkey"><?php esc_html_e( 'Sandbox App key:', 'backwpup' ); ?></label></th>
<td>
<input name="dropboxsandboxappkey" type="text" id="dropboxsandboxappkey"
value="<?php echo esc_attr( get_site_option( 'backwpup_cfg_dropboxsandboxappkey' ) );?>"
class="regular-text" autocomplete="off" />
</td>
</tr>
<tr>
<th scope="row"><label for="dropboxsandboxappsecret"><?php esc_html_e( 'Sandbox App secret:', 'backwpup' ); ?></label></th>
<td>
<input name="dropboxsandboxappsecret" type="password" id="dropboxsandboxappsecret"
value="<?php echo esc_attr( get_site_option( 'backwpup_cfg_dropboxsandboxappsecret' ) );?>"
class="regular-text" autocomplete="off" />
</tr>
</table>
<?php
}
public function sugarsync_keys_form() {
?>
<h3><?php esc_html_e( 'SugarSync API Keys', 'backwpup' ); ?></h3>
<p><?php esc_html_e( 'If you want to set your own SugarSync API keys you can do that here. Leave empty for default.', 'backwpup' ); ?></p>
<table class="form-table">
<tr>
<th scope="row"><label for="sugarsynckey"><?php esc_html_e( 'Access Key ID:', 'backwpup' ); ?></label></th>
<td>
<input name="sugarsynckey" type="text" id="sugarsynckey"
value="<?php echo esc_attr( get_site_option( 'backwpup_cfg_sugarsynckey' ) );?>"
class="regular-text" autocomplete="off" />
</td>
</tr>
<tr>
<th scope="row"><label for="sugarsyncsecret"><?php esc_html_e( 'Private Access Key:', 'backwpup' ); ?></label></th>
<td>
<input name="sugarsyncsecret" type="password" id="sugarsyncsecret"
value="<?php echo esc_attr( get_site_option( 'backwpup_cfg_sugarsyncsecret' ) );?>"
class="regular-text" autocomplete="off" />
</tr>
<tr>
<th scope="row"><label for="sugarsyncappid"><?php esc_html_e( 'App ID:', 'backwpup' ); ?></label></th>
<td>
<input name="sugarsyncappid" type="text" id="sugarsyncappid"
value="<?php echo esc_attr( get_site_option( 'backwpup_cfg_sugarsyncappid' ) );?>"
class="regular-text" autocomplete="off" />
</td>
</tr>
</table>
<?php
}
public function google_keys_form() {
?>
<h3><?php esc_html_e( 'Google API Keys', 'backwpup' ); ?></h3>
<p><a href="https://console.developers.google.com">https://console.developers.google.com</a></p>
<table class="form-table">
<tr>
<th scope="row"><label for="googleclientid"><?php esc_html_e( 'Client ID:', 'backwpup' ); ?></label></th>
<td>
<input name="googleclientid" type="text" id="googleclientid"
value="<?php echo esc_attr( get_site_option( 'backwpup_cfg_googleclientid' ) );?>"
class="regular-text" autocomplete="off" />
</td>
</tr>
<tr>
<th scope="row"><label for="googleclientsecret"><?php esc_html_e( 'Client secret:', 'backwpup' ); ?></label></th>
<td>
<input name="googleclientsecret" type="password" id="googleclientsecret"
value="<?php echo esc_attr( get_site_option( 'backwpup_cfg_googleclientsecret' ) );?>"
class="regular-text" autocomplete="off" />
</tr>
<tr>
<th scope="row"><?php esc_html_e( 'Redirect URIs:', 'backwpup' ); ?></th>
<td>
<span class="code"><?php echo admin_url( 'admin-ajax.php' ) . '?action=backwpup_dest_gdrive'; ?></span>
<br />
<span class="description"><?php esc_html_e( 'Add this URI in a new line to the field.', 'backwpup' ); ?></span>
</td>
</tr>
</table>
<?php
}
public function save_form() {
if ( ! empty( $_POST[ 'hash' ] ) && strlen( $_POST[ 'hash' ] ) >= 6 ) {
update_site_option( 'backwpup_cfg_hash', sanitize_text_field( $_POST[ 'hash' ] ) );
} else {
delete_site_option( 'backwpup_cfg_hash' );
}
if ( $_POST[ 'dropboxappkey' ] ) {
update_site_option( 'backwpup_cfg_dropboxappkey', sanitize_text_field( $_POST[ 'dropboxappkey' ] ) );
} else {
delete_site_option( 'backwpup_cfg_dropboxappkey' );
}
if ( $_POST[ 'dropboxappsecret' ] ) {
update_site_option( 'backwpup_cfg_dropboxappsecret',
BackWPup_Encryption::encrypt( sanitize_text_field( $_POST[ 'dropboxappsecret' ] ) ) );
} else {
delete_site_option( 'backwpup_cfg_dropboxappsecret' );
}
if ( $_POST[ 'dropboxsandboxappkey' ] ) {
update_site_option( 'backwpup_cfg_dropboxsandboxappkey', sanitize_text_field( $_POST[ 'dropboxsandboxappkey' ] ) );
} else {
delete_site_option( 'backwpup_cfg_dropboxsandboxappkey' );
}
if ( $_POST[ 'dropboxsandboxappsecret' ] ) {
update_site_option( 'backwpup_cfg_dropboxsandboxappsecret',
BackWPup_Encryption::encrypt( sanitize_text_field( $_POST[ 'dropboxsandboxappsecret' ] ) ) );
} else {
delete_site_option( 'backwpup_cfg_dropboxsandboxappsecret' );
}
if ( $_POST[ 'sugarsynckey' ] ) {
update_site_option( 'backwpup_cfg_sugarsynckey', sanitize_text_field( $_POST[ 'sugarsynckey' ] ) );
} else {
delete_site_option( 'backwpup_cfg_sugarsynckey' );
}
if ( $_POST[ 'sugarsyncsecret' ] ) {
update_site_option( 'backwpup_cfg_sugarsyncsecret',
BackWPup_Encryption::encrypt( sanitize_text_field( $_POST[ 'sugarsyncsecret' ] ) ) );
} else {
delete_site_option( 'backwpup_cfg_sugarsyncsecret' );
}
if ( $_POST[ 'sugarsyncappid' ] ) {
update_site_option( 'backwpup_cfg_sugarsyncappid', sanitize_text_field( $_POST[ 'sugarsyncappid' ] ) );
} else {
delete_site_option( 'backwpup_cfg_sugarsyncappid' );
}
if ( $_POST[ 'googleclientsecret' ] ) {
update_site_option( 'backwpup_cfg_googleclientsecret',
BackWPup_Encryption::encrypt( sanitize_text_field( $_POST[ 'googleclientsecret' ] ) ) );
} else {
delete_site_option( 'backwpup_cfg_googleclientsecret' );
}
if ( $_POST[ 'googleclientid' ] ) {
update_site_option( 'backwpup_cfg_googleclientid', sanitize_text_field( $_POST[ 'googleclientid' ] ) );
} else {
delete_site_option( 'backwpup_cfg_googleclientid' );
}
}
}