PluginProbe
WP Database Backup – Unlimited Database & Files Backup by Backup for WP / 6.1
WP Database Backup – Unlimited Database & Files Backup by Backup for WP v6.1
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.1, at includes/admin/Destination/Google/google-form.php

140 lines 7.3 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 die( '<br><br>Invalid form data. form request came from the somewhere else not current site!' );
18 }
19 if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['wpdbbackup_update_google_setting'] ) ), 'wpdbbackup-update-google-setting' ) ) {
20 die( '<br><br>Invalid form data. form request came from the somewhere else not current site! ' );
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 ) );
32 update_option( 'wpdb_dest_google_secret_key', wp_db_filter_data( $client_secret ) );
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 ) );
42 update_option( 'wpdb_dest_google_secret_key', wp_db_filter_data( $client_secret ) );
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 if ( isset( $_GET['code'] ) ) {
58 update_option( 'wpdb_dest_google_authCode', wp_db_filter_data( sanitize_text_field( wp_unslash( $_GET['code'] ) ) ) );
59 } else {
60 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'] ) ) {
61 wp_safe_redirect( filter_var( $auth_url, FILTER_SANITIZE_URL ) );
62 }
63 }
64 } elseif ( isset( $_POST['reset'] ) && 'Reset Configure' === $_POST['reset'] ) {
65 update_option( 'wpdb_dest_google_authCode', '' );
66 wp_safe_redirect( esc_url( site_url() . '/wp-admin/admin.php?page=wp-database-backup' ) );
67 }
68
69 // Put a "settings updated" message on the screen.
70 $update_msg = '<div class="updated"><p><strong>Your google drive setting has been saved.</strong></p></div>';
71 }
72 if ( isset( $_GET['code'] ) ) {
73 update_option( 'wpdb_dest_google_authCode', wp_db_filter_data( sanitize_text_field( wp_unslash( $_GET['code'] ) ) ) );
74 }
75
76 $wpdbbkp_gdrive_authCode = get_option( 'wpdb_dest_google_authCode',null );
77 $wpdbbkp_gdrive_secret_key = get_option( 'wpdb_dest_google_client_key',null );
78 $wpdbbkp_gdrive_secret_key = get_option( 'wpdb_dest_google_secret_key',null );
79 $wpdbbkp_gdrive_status = '<label><b>Status</b>: Not Configured </label> ';
80 if(!empty($wpdbbkp_gdrive_authCode) && !empty($wpdbbkp_gdrive_client_key) && !empty($wpdbbkp_gdrive_secret_key))
81 {
82 $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> ';
83 }
84 ?>
85 <div class="panel panel-default">
86 <div class="panel-heading">
87 <h4 class="panel-title">
88 <a data-toggle="collapse" data-parent="#accordion" href="#collapsegoogle">
89 <h2>Google drive <?php echo $wpdbbkp_gdrive_status;?> <span class="dashicons dashicons-admin-generic"></span></h2>
90 </a>
91 </h4>
92 </div>
93 <div id="collapsegoogle" class="panel-collapse collapse">
94 <div class="panel-body">
95 <?php echo esc_html( $update_msg ); ?>
96 <form class="form-group" name="googledrive" method="post" action="">
97 <input type="hidden" name="wpdb_google_drive" value="Y">
98 <input name="wpdbbackup_update_google_setting" type="hidden" value="<?php echo esc_attr( wp_create_nonce( 'wpdbbackup-update-google-setting' ) ); ?>" />
99 <?php
100 wp_nonce_field( 'wp-database-backup' );
101 $wpdb_dest_google_auth_code = get_option( 'wpdb_dest_google_authCode' );
102 $wpdb_dest_google_client_key = get_option( 'wpdb_dest_google_client_key' );
103 $wpdb_dest_google_secret_key = get_option( 'wpdb_dest_google_secret_key' );
104 if ( ! empty( $wpdb_dest_google_auth_code ) && ! empty( $wpdb_dest_google_client_key ) && ! empty( $wpdb_dest_google_secret_key ) ) {
105 ?>
106 <p class="text-success">Configuration to Google Drive Access has been done successfully</p>
107 <p>By clicking reset, you can reconfigure Google Account</p>
108 <p>For local backup click on Reset Configure</p>
109 <p><input type="submit" name="reset" class="btn btn-primary" value="<?php esc_attr_e( 'Reset Configure' ); ?>" />&nbsp;
110 </p>
111 <?php } else { ?>
112
113 <p>Back up WordPress database to google drive.</p>
114 <p>Configure google account, you need to create Client ID &amp; Client secret from the API section '<a href="https://code.google.com/apis/console/" target="_blank">Google API Console</a>' also use authorization redirecting url as <br>
115 <strong> <?php echo esc_url( site_url() . '/wp-admin/admin.php?page=wp-database-backup&action=auth' ); ?></strong></p>
116 <p>For local backup leave the setting as it is</p>
117
118 <div class="row form-group">
119 <label class="col-sm-2" for="wpdb_dest_google_client_key">Client ID</label>
120 <div class="col-sm-6">
121 <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">
122 </div>
123 </div>
124
125 <div class="row form-group">
126 <label class="col-sm-2" for="wpdb_dest_google_secret_key">Client secret:</label>
127 <div class="col-sm-6">
128 <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">
129 </div>
130 </div>
131
132 <p><input type="submit" name="Submit" class="btn btn-primary" value="<?php esc_attr_e( 'Allow Access' ); ?>" />&nbsp;
133 <input type="submit" name="Save" class="btn btn-secondary" value="<?php esc_attr_e( 'Save' ); ?>" />&nbsp;
134 </p>
135 <?php } ?>
136 </form>
137 </div>
138 </div>
139 </div>
140