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

131 lines 6.6 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/tools.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/tools.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 <div class="panel panel-default">
77 <div class="panel-heading">
78 <h4 class="panel-title">
79 <a data-toggle="collapse" data-parent="#accordion" href="#collapsegoogle">
80 <h2>Google drive</h2>
81 </a>
82 </h4>
83 </div>
84 <div id="collapsegoogle" class="panel-collapse collapse in">
85 <div class="panel-body">
86 <?php echo esc_html( $update_msg ); ?>
87 <form class="form-group" name="googledrive" method="post" action="">
88 <input type="hidden" name="wpdb_google_drive" value="Y">
89 <input name="wpdbbackup_update_google_setting" type="hidden" value="<?php echo esc_attr( wp_create_nonce( 'wpdbbackup-update-google-setting' ) ); ?>" />
90 <?php
91 wp_nonce_field( 'wp-database-backup' );
92 $wpdb_dest_google_auth_code = get_option( 'wpdb_dest_google_authCode' );
93 $wpdb_dest_google_client_key = get_option( 'wpdb_dest_google_client_key' );
94 $wpdb_dest_google_secret_key = get_option( 'wpdb_dest_google_secret_key' );
95 if ( ! empty( $wpdb_dest_google_auth_code ) && ! empty( $wpdb_dest_google_client_key ) && ! empty( $wpdb_dest_google_secret_key ) ) {
96 ?>
97 <p class="text-success">Configuration to Google Drive Access has been done successfully</p>
98 <p>By clicking reset, you can reconfigure Google Account</p>
99 <p>For local backup click on Reset Configure</p>
100 <p><input type="submit" name="reset" class="btn btn-primary" value="<?php esc_attr_e( 'Reset Configure' ); ?>" />&nbsp;
101 </p>
102 <?php } else { ?>
103
104 <p><a href="http://www.wpseeds.com/wp-database-backup/#google" target="_blank"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a> Back up WordPress database to google drive.</p>
105 <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>
106 <strong> <?php echo esc_url( site_url() . '/wp-admin/tools.php?page=wp-database-backup&action=auth' ); ?></strong></p>
107 <p>For local backup leave the setting as it is</p>
108
109 <div class="row form-group">
110 <label class="col-sm-2" for="wpdb_dest_google_client_key">Client ID</label>
111 <div class="col-sm-6">
112 <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">
113 </div>
114 </div>
115
116 <div class="row form-group">
117 <label class="col-sm-2" for="wpdb_dest_google_secret_key">Client secret:</label>
118 <div class="col-sm-6">
119 <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">
120 </div>
121 </div>
122
123 <p><input type="submit" name="Submit" class="btn btn-primary" value="<?php esc_attr_e( 'Allow Access' ); ?>" />&nbsp;
124 <input type="submit" name="Save" class="btn btn-secondary" value="<?php esc_attr_e( 'Save' ); ?>" />&nbsp;
125 </p>
126 <?php } ?>
127 </form>
128 </div>
129 </div>
130 </div>
131