PluginProbe
WP Database Backup – Unlimited Database & Files Backup by Backup for WP / 6.11
WP Database Backup – Unlimited Database & Files Backup by Backup for WP v6.11
7.13 7.12 trunk 1.1 2.1.1 5.9 6.0 6.1 6.10 6.11 6.12 6.12.1 6.2 6.3 6.4 6.5 6.5.1 6.6 6.7 6.8 6.9 7.0 7.0.1 7.1 7.10 All 34 releases
wp-database-backup / includes / admin / Destination / Google / google-form.php

google-form.php in WP Database Backup – Unlimited Database & Files Backup by Backup for WP 6.11, at includes/admin/Destination/Google/google-form.php

142 lines 7.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Destination form.
4 *
5 * @package wpdbbkp
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11 ob_start();
12
13 $update_msg = '';
14 if ( isset( $_POST['wpdb_google_drive'] ) && 'Y' === $_POST['wpdb_google_drive'] ) {
15 // Validate that the contents of the form request came from the current site and not somewhere else added 21-08-15 V.3.4.
16 if ( ! isset( $_POST['wpdbbackup_update_google_setting'] ) ) {
17 wp_die( esc_html__('Invalid form data. form request came from the somewhere else not current site!','wpdbbkp') );
18 }
19 if ( ! wp_verify_nonce( $_POST['wpdbbackup_update_google_setting'] , 'wpdbbackup-update-google-setting' ) ) {
20 wp_die( esc_html__('Invalid form data. form request came from the somewhere else not current site!','wpdbbkp') );
21 }
22 $client_id = '';
23 $client_secret = '';
24 if ( isset( $_POST['Save'] ) && 'Save' === $_POST['Save'] ) {
25 if ( true === isset( $_POST['wpdb_dest_google_client_key'] ) ) {
26 $client_id = sanitize_text_field( wp_unslash( $_POST['wpdb_dest_google_client_key'] ) );
27 }
28 if ( true === isset( $_POST['wpdb_dest_google_secret_key'] ) ) {
29 $client_secret = sanitize_text_field( wp_unslash( $_POST['wpdb_dest_google_secret_key'] ) );
30 }
31 update_option( 'wpdb_dest_google_client_key', wp_db_filter_data( $client_id ) , false);
32 update_option( 'wpdb_dest_google_secret_key', wp_db_filter_data( $client_secret ) , false);
33 } elseif ( isset( $_POST['Submit'] ) && 'Allow Access' === $_POST['Submit'] ) {
34 // Save the posted value in the database.
35 if ( true === isset( $_POST['wpdb_dest_google_client_key'] ) ) {
36 $client_id = sanitize_text_field( wp_unslash( $_POST['wpdb_dest_google_client_key'] ) );
37 }
38 if ( true === isset( $_POST['wpdb_dest_google_secret_key'] ) ) {
39 $client_secret = sanitize_text_field( wp_unslash( $_POST['wpdb_dest_google_secret_key'] ) );
40 }
41 update_option( 'wpdb_dest_google_client_key', wp_db_filter_data( $client_id ) , false);
42 update_option( 'wpdb_dest_google_secret_key', wp_db_filter_data( $client_secret ) , false);
43
44 require_once 'google-api-php-client/src/Google_Client.php';
45 require_once 'google-api-php-client/src/contrib/Google_DriveService.php';
46
47 $client = new Google_Client();
48 // Get your credentials from the APIs Console.
49 $client->setClientId( $client_id );
50 $client->setClientSecret( $client_secret );
51 $client->setRedirectUri( site_url() . '/wp-admin/admin.php?page=wp-database-backup&action=auth' );
52 $client->setScopes( array( 'https://www.googleapis.com/auth/drive' ) );
53
54 $service = new Google_DriveService( $client );
55
56 $auth_url = $client->createAuthUrl();
57
58 if ( isset( $_GET['code'] ) ) {
59 update_option( 'wpdb_dest_google_authCode', wp_db_filter_data( sanitize_text_field( wp_unslash( $_GET['code'] ) ) ), false );
60 } else {
61 if ( isset( $_POST['wpdb_dest_google_client_key'] ) && ! empty( $_POST['wpdb_dest_google_client_key'] ) && isset( $_POST['wpdb_dest_google_secret_key'] ) && ! empty( $_POST['wpdb_dest_google_secret_key'] ) ) {
62 wp_redirect( filter_var( $auth_url, FILTER_SANITIZE_URL ) );
63 exit;
64 }
65 }
66 } elseif ( isset( $_POST['reset'] ) && 'Reset Configure' === $_POST['reset'] ) {
67 update_option( 'wpdb_dest_google_authCode', '' , false);
68 wp_safe_redirect( esc_url( site_url() . '/wp-admin/admin.php?page=wp-database-backup' ) );
69 exit;
70 }
71
72 // Put a "settings updated" message on the screen.
73 $update_msg = '<div class="updated"><p><strong>Your google drive setting has been saved.</strong></p></div>';
74 }
75 if ( isset( $_GET['code'] ) ) {
76 update_option( 'wpdb_dest_google_authCode', wp_db_filter_data( sanitize_text_field( wp_unslash( $_GET['code'] ) ) ) , false);
77 $wpdbbkp_gdrive_authCode = wp_db_filter_data( sanitize_text_field( wp_unslash( $_GET['code'] ) ) );
78 }
79
80 $wpdb_dest_google_auth_code = get_option( 'wpdb_dest_google_authCode' );
81 $wpdb_dest_google_client_key = get_option( 'wpdb_dest_google_client_key' );
82 $wpdb_dest_google_secret_key = get_option( 'wpdb_dest_google_secret_key' );
83 $wpdbbkp_gdrive_status = '<label><b>Status</b>: Not Configured </label> ';
84
85 if(!empty($wpdb_dest_google_auth_code) && !empty($wpdb_dest_google_client_key) && !empty($wpdb_dest_google_secret_key))
86 {
87 $wpdbbkp_gdrive_status='<label><b>Status</b>: <span class="dashicons dashicons-yes-alt" style="color:green;font-size:16px" title="Destination enabled"></span><span class="configured">Configured </span> </label> ';
88 }
89 ?>
90 <div class="panel panel-default">
91 <div class="panel-heading">
92 <h4 class="panel-title">
93 <a data-toggle="collapse" data-parent="#accordion" href="#collapsegoogle">
94 <h2>Google drive<?php echo $wpdbbkp_gdrive_status;?> <span class="dashicons dashicons-admin-generic"></span></h2>
95 </a>
96 </h4>
97 </div>
98 <div id="collapsegoogle" class="panel-collapse collapse">
99 <div class="panel-body">
100 <?php echo esc_html( $update_msg ); ?>
101 <form class="form-group" name="googledrive" method="post" action="">
102 <input type="hidden" name="wpdb_google_drive" value="Y">
103 <input name="wpdbbackup_update_google_setting" type="hidden" value="<?php echo esc_attr( wp_create_nonce( 'wpdbbackup-update-google-setting' ) ); ?>" />
104 <?php
105 wp_nonce_field( 'wp-database-backup' );
106 if ( ! empty( $wpdb_dest_google_auth_code ) && ! empty( $wpdb_dest_google_client_key ) && ! empty( $wpdb_dest_google_secret_key ) ) {
107 ?>
108 <p class="text-success"><?php echo esc_html__('Configuration to Google Drive Access has been done successfully', 'wpdbbkp') ?></p>
109 <p><?php echo esc_html__('By clicking reset, you can reconfigure Google Account', 'wpdbbkp') ?></p>
110 <p><?php echo esc_html__('For local backup click on Reset Configure', 'wpdbbkp') ?></p>
111 <p><input type="submit" name="reset" class="btn btn-primary" value="<?php esc_attr_e( 'Reset Configure' , 'wpdbbkp' ); ?>" />&nbsp;
112 </p>
113 <?php } else { ?>
114
115 <p><?php echo esc_html__('Back up WordPress database to google drive.', 'wpdbbkp') ?></p>
116 <p><?php echo esc_html__('Configure google account, you need to create Client ID &amp; Client secret from the API section ', 'wpdbbkp') ?><a href="https://code.google.com/apis/console/" target="_blank"><?php echo esc_html__('Google API Console', 'wpdbbkp') ?></a><?php echo esc_html__("' also use authorization redirecting url as", 'wpdbbkp') ?> <br>
117 <strong> <?php echo esc_url( site_url() . '/wp-admin/admin.php?page=wp-database-backup&action=auth' ); ?></strong></p>
118 <p><?php echo esc_html__('For local backup leave the setting as it is', 'wpdbbkp') ?></p>
119
120 <div class="row form-group">
121 <label class="col-sm-2" for="wpdb_dest_google_client_key"><?php echo esc_html__('Client ID', 'wpdbbkp') ?></label>
122 <div class="col-sm-6">
123 <input type="text" id="wpdb_dest_google_client_key" class="form-control" name="wpdb_dest_google_client_key" value="<?php echo esc_html( get_option( 'wpdb_dest_google_client_key' ) ); ?>" size="25" placeholder="your client id">
124 </div>
125 </div>
126
127 <div class="row form-group">
128 <label class="col-sm-2" for="wpdb_dest_google_secret_key"><?php echo esc_html__('Client secret:', 'wpdbbkp') ?></label>
129 <div class="col-sm-6">
130 <input type="text" id="wpdb_dest_google_secret_key" class="form-control" name="wpdb_dest_google_secret_key" value="<?php echo esc_html( get_option( 'wpdb_dest_google_secret_key' ) ); ?>" size="25" placeholder="your client secret key">
131 </div>
132 </div>
133
134 <p><input type="submit" name="Submit" class="btn btn-primary" value="<?php esc_attr_e( 'Allow Access' , 'wpdbbkp' ); ?>" />&nbsp;
135 <input type="submit" name="Save" class="btn btn-secondary" value="<?php esc_attr_e( 'Save' , 'wpdbbkp' ); ?>" />&nbsp;
136 </p>
137 <?php } ?>
138 </form>
139 </div>
140 </div>
141 </div>
142