You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1041 lines
38 KiB
1041 lines
38 KiB
<?php
|
|
/**
|
|
* WPSSLC_Service Class
|
|
*
|
|
* @package contactsheets-lite
|
|
*/
|
|
|
|
/**
|
|
* WPSSLC_Google_API class.
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
class WPSSLC_Service {
|
|
/**
|
|
* Instance of class.
|
|
*
|
|
* @var $instance Instance variable of class.
|
|
*/
|
|
private static $instance = null;
|
|
/**
|
|
* Instance of WPSSLC_Google_API_Functions class.
|
|
*
|
|
* @var $instance_api Instance variable of WPSSLC_Google_API_Functions class.
|
|
*/
|
|
private static $instance_api = null;
|
|
/**
|
|
* Instance of Google API service.
|
|
*
|
|
* @var $instance_service Instance variable of Google API service.
|
|
*/
|
|
private static $instance_service = null;
|
|
/**
|
|
* Allowed Tags.
|
|
*
|
|
* @var $allowed_tags.
|
|
*/
|
|
private $allowed_tags = array( 'text', 'email', 'url', 'file', 'tel', 'number', 'range', 'date', 'textarea', 'select', 'checkbox', 'radio', 'acceptance', 'quiz' );
|
|
/**
|
|
* Get an instance of this class.
|
|
*
|
|
* @return instance
|
|
*/
|
|
public static function get_instance() {
|
|
if ( null === self::$instance ) {
|
|
self::$instance = new WPSSLC_Service();
|
|
}
|
|
return self::$instance;
|
|
}
|
|
/**
|
|
* Get an instance of WPSSLC_Google_API_Functions class.
|
|
*
|
|
* @return WPSSLC_Google_API_Functions class instance
|
|
*/
|
|
public static function get_clientinstance() {
|
|
if ( null === self::$instance_api ) {
|
|
self::$instance_api = new ContactsheetsLite\WPSSLC_Google_API_Functions();
|
|
}
|
|
return self::$instance_api;
|
|
}
|
|
/**
|
|
* Set things up.
|
|
*
|
|
* @since 1.0
|
|
*/
|
|
public function __construct() {
|
|
|
|
// Add new tab to contact form 7 editors panel.
|
|
add_filter( 'wpcf7_editor_panels', array( $this, 'wpsslc_editor_panels' ) );
|
|
add_action( 'wpcf7_after_save', array( $this, 'wpsslc_save_settings' ) );
|
|
add_action( 'wpcf7_before_send_mail', array( $this, 'wpsslc_wpcf7_before_send_mail' ), 10, 1 );
|
|
add_action( 'wpcf7_before_send_mail', array( $this, 'wpsslc_save_to_google_spreadsheets' ), 50, 1 );
|
|
add_action( 'wp_ajax_wpsslc_reset_settings', array( $this, 'wpsslc_reset_settings' ) );
|
|
add_action( 'wp_ajax_wpsslc_clear_sheet', array( $this, 'wpsslc_clear_sheet' ) );
|
|
$this->get_clientinstance();
|
|
}
|
|
|
|
/**
|
|
* Add new tab to contact form 7 editors panel.
|
|
*
|
|
* @since 1.0
|
|
*
|
|
* @param array $panels .
|
|
* @return array
|
|
*/
|
|
public function wpsslc_editor_panels( $panels ) {
|
|
$panels['google_sheets'] = array(
|
|
'title' => __( 'WPSyncSheets Lite Settings', 'wpssc' ),
|
|
'callback' => array( $this, 'wpsslc_editor_panel_google_sheet' ),
|
|
);
|
|
|
|
return $panels;
|
|
}
|
|
|
|
/**
|
|
* Set Google sheet settings with contact form
|
|
*
|
|
* @since 1.0
|
|
*
|
|
* @param object $post The post object to be processed.
|
|
*/
|
|
public function wpsslc_save_settings( $post ) {
|
|
|
|
if ( ! isset( $_POST['wpsslc_sheet_settings'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['wpsslc_sheet_settings'] ) ), 'save_sheet_settings' ) ) {
|
|
echo esc_html__( 'Sorry, your nonce did not verify.', 'wpssc' );
|
|
return;
|
|
}
|
|
if ( ! isset( $_POST['wpsslc_all_settings'] ) ) {
|
|
update_post_meta( $post->id(), 'wpssc_all_settings', 'no' );
|
|
return;
|
|
} else {
|
|
update_post_meta( $post->id(), 'wpssc_all_settings', sanitize_text_field( wp_unslash( $_POST['wpsslc_all_settings'] ) ) );
|
|
}
|
|
if ( ! isset( $_POST['wpsslc']['spreadsheetname'] ) || empty( sanitize_text_field( wp_unslash( $_POST['wpsslc']['spreadsheetname'] ) ) ) ) {
|
|
return;
|
|
}
|
|
$post_data = self::get_form_data( $post->id() );
|
|
$form_fields = self::single_array( $post_data );
|
|
$wpsslc_cf_sheet = array();
|
|
$active_header = array();
|
|
$newsheet = '';
|
|
|
|
array_push( $form_fields, 'IP-address' );
|
|
array_push( $form_fields, 'page-URL' );
|
|
|
|
if ( 'new' === sanitize_text_field( wp_unslash( $_POST['wpsslc']['spreadsheetname'] ) ) ) {
|
|
$newsheet = 'new';
|
|
$wpsslc_cf_sheet['spreadsheetname'] = isset( $_POST['new_spreadsheetname'] ) ? sanitize_text_field( wp_unslash( $_POST['new_spreadsheetname'] ) ) : '';
|
|
$wpsslc_cf_sheet['sheetname'] = isset( $_POST['new_sheetname'] ) ? sanitize_text_field( wp_unslash( $_POST['new_sheetname'] ) ) : '';
|
|
|
|
$requestbody = self::$instance_api->newspreadsheetobject( $wpsslc_cf_sheet['spreadsheetname'], $wpsslc_cf_sheet['sheetname'] );
|
|
|
|
$response = self::$instance_api->createspreadsheet( $requestbody );
|
|
$spreadsheetname = $response['spreadsheetId'];
|
|
$wpsslc_cf_sheet['spreadsheetname'] = $response['spreadsheetId'];
|
|
$_POST['wpsslc']['spreadsheetname'] = $response['spreadsheetId'];
|
|
$_POST['wpsslc']['sheetname'] = $wpsslc_cf_sheet['sheetname'];
|
|
}
|
|
|
|
$mapping = array();
|
|
$wpsslc_cf_sheet['spreadsheetname'] = isset( $_POST['wpsslc']['spreadsheetname'] ) ? sanitize_text_field( wp_unslash( $_POST['wpsslc']['spreadsheetname'] ) ) : '';
|
|
$wpsslc_cf_sheet['sheetname'] = isset( $_POST['wpsslc']['sheetname'] ) ? sanitize_text_field( wp_unslash( $_POST['wpsslc']['sheetname'] ) ) : '';
|
|
if ( isset( $_POST['header_value_0'] ) && 'new' !== (string) $newsheet ) {
|
|
|
|
$spreadsheetname = $wpsslc_cf_sheet['spreadsheetname'];
|
|
$sheetname = $wpsslc_cf_sheet['sheetname'];
|
|
|
|
$wpsslc_existingsheets = array();
|
|
$response = self::$instance_api->get_sheet_listing( $spreadsheetname );
|
|
$wpsslc_existingsheets = self::$instance_api->get_sheet_list( $response );
|
|
$range = trim( $sheetname ) . '!A1';
|
|
$wpsslc_sheetid = $wpsslc_existingsheets[ $sheetname ];
|
|
|
|
$headers = array();
|
|
$active_header = array();
|
|
|
|
$previous_active_headers = self::$instance_api->wpsslc_option( 'wpssc_active_headers', '', $post->id() );
|
|
$wpsslc_neworder = array();
|
|
$wpsslc_total_mapping_fields = isset( $_POST['wpsslc_total_mapping_fields'] ) ? sanitize_text_field( wp_unslash( $_POST['wpsslc_total_mapping_fields'] ) ) : count( $form_fields );
|
|
for ( $i = 0; $i < $wpsslc_total_mapping_fields; $i++ ) {
|
|
if ( isset( $_POST[ 'header_value_' . $i ] ) ) {
|
|
$header_shortcode = isset( $_POST[ 'header_shortcode_' . $i ] ) ? sanitize_text_field( wp_unslash( $_POST[ 'header_shortcode_' . $i ] ) ) : '';
|
|
if ( 'IP Address' === $header_shortcode || 'Page URL' === $header_shortcode ) {
|
|
$header_shortcode = strtolower( str_replace( ' ', '-', $header_shortcode ) );
|
|
}
|
|
|
|
if ( isset( $_POST[ 'active_header_value_' . $i ] ) ) {
|
|
$wpsslc_neworder[] = $header_shortcode;
|
|
$headers[] = sanitize_text_field( wp_unslash( $_POST[ 'header_value_' . $i ] ) );
|
|
$active_header[ $header_shortcode ] = 1;
|
|
}
|
|
$mapping[ $header_shortcode ] = sanitize_text_field( wp_unslash( $_POST[ 'header_value_' . $i ] ) );
|
|
}
|
|
}
|
|
|
|
if ( isset( $previous_active_headers[0] ) ) {
|
|
$wpsslc_old_header_order = array_keys( $previous_active_headers[0] );
|
|
} else {
|
|
$wpsslc_old_header_order = array();
|
|
}
|
|
|
|
$wpsslc_column = array_diff( $wpsslc_old_header_order, $wpsslc_neworder );
|
|
|
|
if ( ! empty( $wpsslc_column ) ) {
|
|
$wpsslc_column = array_reverse( $wpsslc_column, true );
|
|
foreach ( $wpsslc_column as $columnindex => $columnval ) {
|
|
unset( $wpsslc_old_header_order[ $columnindex ] );
|
|
$wpsslc_old_header_order = array_values( $wpsslc_old_header_order );
|
|
if ( array_key_exists( $sheetname, $wpsslc_existingsheets ) ) {
|
|
|
|
$param = array();
|
|
$param['sheetid'] = $wpsslc_sheetid;
|
|
$param['startindex'] = $columnindex;
|
|
$param['endindex'] = $columnindex + 1;
|
|
$deleterequestarray[] = self::$instance_api->deleteDimensionrequests( $param );
|
|
}
|
|
}
|
|
}
|
|
try {
|
|
if ( ! empty( $deleterequestarray ) ) {
|
|
$param = array();
|
|
$param['spreadsheetid'] = $spreadsheetname;
|
|
$param['requestarray'] = $deleterequestarray;
|
|
|
|
$wpsslc_response = self::$instance_api->updatebachrequests( $param );
|
|
}
|
|
} catch ( Exception $e ) {
|
|
echo esc_html( 'Message: ' . $e->getMessage() );
|
|
}
|
|
if ( $wpsslc_old_header_order !== $wpsslc_neworder ) {
|
|
foreach ( $wpsslc_neworder as $key => $hname ) {
|
|
$wpsslc_startindex = array_search( $hname, $wpsslc_old_header_order, true );
|
|
|
|
if ( false !== $wpsslc_startindex && ( isset( $wpsslc_old_header_order[ $key ] ) && $wpsslc_old_header_order[ $key ] !== $hname ) ) {
|
|
unset( $wpsslc_old_header_order[ $wpsslc_startindex ] );
|
|
$wpsslc_old_header_order = array_merge( array_slice( $wpsslc_old_header_order, 0, $key ), array( 0 => $hname ), array_slice( $wpsslc_old_header_order, $key, count( $wpsslc_old_header_order ) - $key ) );
|
|
$wpsslc_endindex = $wpsslc_startindex + 1;
|
|
$wpsslc_destindex = $key;
|
|
|
|
if ( array_key_exists( $sheetname, $wpsslc_existingsheets ) ) {
|
|
|
|
$param = array();
|
|
$param['sheetid'] = $wpsslc_sheetid;
|
|
$param['startindex'] = $wpsslc_startindex;
|
|
$param['endindex'] = $wpsslc_endindex;
|
|
$param['destindex'] = $wpsslc_destindex;
|
|
|
|
$requestarray[] = self::$instance_api->moveDimensionrequests( $param );
|
|
}
|
|
} elseif ( false === $wpsslc_startindex ) {
|
|
|
|
$wpsslc_old_header_order = array_merge( array_slice( $wpsslc_old_header_order, 0, $key ), array( 0 => $hname ), array_slice( $wpsslc_old_header_order, $key, count( $wpsslc_old_header_order ) - $key ) );
|
|
|
|
if ( array_key_exists( $sheetname, $wpsslc_existingsheets ) ) {
|
|
$param = array();
|
|
$param['sheetid'] = $wpsslc_sheetid;
|
|
$param['startindex'] = $key;
|
|
$param['endindex'] = $key + 1;
|
|
$requestarray[] = self::$instance_api->insertdimensionrequests( $param );
|
|
}
|
|
}
|
|
}
|
|
|
|
if ( ! empty( $requestarray ) ) {
|
|
$param = array();
|
|
$param['spreadsheetid'] = $spreadsheetname;
|
|
$param['requestarray'] = $requestarray;
|
|
$wpsslc_response = self::$instance_api->updatebachrequests( $param );
|
|
}
|
|
}
|
|
|
|
if ( isset( $_POST['created_date'] ) ) {
|
|
$headers[] = 'Submission Date';
|
|
}
|
|
|
|
$range = trim( $sheetname ) . '!A1';
|
|
$values = array( $headers );
|
|
$requestbody = self::$instance_api->valuerangeobject( $values );
|
|
$params = array(
|
|
'valueInputOption' => 'RAW',
|
|
);
|
|
|
|
$param = self::$instance_api->setparamater( $spreadsheetname, $range, $requestbody, $params );
|
|
$response = self::$instance_api->updateentry( $param );
|
|
|
|
}
|
|
update_post_meta( $post->id(), 'wpssc_cf_settings', $wpsslc_cf_sheet );
|
|
update_post_meta( $post->id(), 'field_mapping_settings', $mapping );
|
|
update_post_meta( $post->id(), 'wpssc_active_headers', $active_header );
|
|
|
|
if ( isset( $_POST['freeze_header'] ) ) {
|
|
$freeze = 1;
|
|
} else {
|
|
$freeze = 0;
|
|
}
|
|
|
|
if ( ! empty( $wpsslc_cf_sheet['spreadsheetname'] ) && ! empty( $wpsslc_cf_sheet['spreadsheetname'] ) ) {
|
|
$response = self::$instance_api->get_sheet_listing( $wpsslc_cf_sheet['spreadsheetname'] );
|
|
|
|
foreach ( $response->getSheets() as $key => $value ) {
|
|
if ( $wpsslc_cf_sheet['sheetname'] === (string) $value['properties']['title'] ) {
|
|
$requestbody = self::$instance_api->freezeobject( $value['properties']['sheetId'], $freeze );
|
|
$requestobject = array();
|
|
$requestobject['spreadsheetid'] = $wpsslc_cf_sheet['spreadsheetname'];
|
|
$requestobject['requestbody'] = $requestbody;
|
|
self::$instance_api->formatsheet( $requestobject );
|
|
}
|
|
}
|
|
}
|
|
if ( isset( $_POST['freeze_header'] ) ) {
|
|
update_post_meta( $post->id(), 'freeze_header', sanitize_text_field( wp_unslash( $_POST['freeze_header'] ) ) );
|
|
} else {
|
|
update_post_meta( $post->id(), 'freeze_header', '' );
|
|
}
|
|
if ( isset( $_POST['created_date'] ) ) {
|
|
update_post_meta( $post->id(), 'created_date', sanitize_text_field( wp_unslash( $_POST['created_date'] ) ) );
|
|
} else {
|
|
update_post_meta( $post->id(), 'created_date', '' );
|
|
}
|
|
|
|
}
|
|
/**
|
|
* Function - Run before sending mail.
|
|
*
|
|
* @param object $form .
|
|
* @since 1.0
|
|
*/
|
|
public function wpsslc_wpcf7_before_send_mail( $form ) {
|
|
self::$instance_api->getClient();
|
|
}
|
|
/**
|
|
* Function - To send contact form data to google spreadsheet.
|
|
*
|
|
* @param object $form .
|
|
* @since 1.0
|
|
*/
|
|
public function wpsslc_save_to_google_spreadsheets( $form ) {
|
|
// get form data.
|
|
$form_id = $form->id();
|
|
if ( 'no' === (string) get_post_meta( $form_id, 'wpssc_all_settings', true ) ) {
|
|
return;
|
|
}
|
|
|
|
if ( ! self::$instance_api->checkcredenatials() ) {
|
|
return;
|
|
}
|
|
if ( ! self::$instance_api->getClient() ) {
|
|
return;
|
|
}
|
|
$submission = WPCF7_Submission::get_instance();
|
|
|
|
$form_data = self::$instance_api->wpsslc_option( 'wpssc_cf_settings', '', $form_id );
|
|
$mapping_data = get_post_meta( $form_id, 'field_mapping_settings' );
|
|
$active_headers = self::$instance_api->wpsslc_option( 'wpssc_active_headers', '', $form_id );
|
|
$created_date = get_post_meta( $form_id, 'created_date' );
|
|
$data = array();
|
|
self::check_mapping_fields( $mapping_data );
|
|
self::check_active_headers( $active_headers );
|
|
$sheetarray = self::wpsslc_list_googlespreedsheet();
|
|
if ( isset( $form_data[0]['spreadsheetname'] ) && ! empty( $form_data[0]['spreadsheetname'] ) && ! array_key_exists( $form_data[0]['spreadsheetname'], $sheetarray ) ) {
|
|
$form_data[0]['spreadsheetname'] = '';
|
|
$form_data[0]['sheetname'] = '';
|
|
} elseif ( isset( $form_data[0]['spreadsheetname'] ) && ! empty( $form_data[0]['spreadsheetname'] ) ) {
|
|
$sheetname = self::sheet_for_form_setting( $form_data );
|
|
if ( isset( $form_data[0]['sheetname'] ) && ! empty( $form_data[0]['sheetname'] ) && ! in_array( $form_data[0]['sheetname'], $sheetname, true ) ) {
|
|
$form_data[0]['spreadsheetname'] = '';
|
|
$form_data[0]['sheetname'] = '';
|
|
}
|
|
}
|
|
// if contact form sheet name and tab name is not empty than send data to spreedsheet.
|
|
if ( $submission && ( ! empty( $form_data[0]['spreadsheetname'] ) ) && ( ! empty( $form_data[0]['sheetname'] ) ) && ! empty( array_filter( $mapping_data ) ) ) {
|
|
$posted_data = $submission->get_posted_data();
|
|
$file_data = $submission->uploaded_files();
|
|
$field_data = self::get_form_data( $form_id );
|
|
|
|
if ( ! function_exists( 'wp_handle_upload' ) ) {
|
|
require_once ABSPATH . 'wp-admin/includes/file.php';
|
|
}
|
|
global $input_quiz_array;
|
|
$input_quiz_array = array();
|
|
array_walk_recursive(
|
|
$field_data,
|
|
function( $value, $key ) {
|
|
global $input_quiz_array;
|
|
if ( 'quiz' === (string) $key ) {
|
|
$input_quiz_array[] = $value;
|
|
}
|
|
}
|
|
);
|
|
|
|
foreach ( $mapping_data[0] as $key => $val ) {
|
|
if ( $active_headers ) {
|
|
if ( ! array_key_exists( $key, $active_headers[0] ) ) {
|
|
continue;
|
|
}
|
|
}
|
|
if ( 'IP-address' === (string) $key ) {
|
|
|
|
if ( isset( $_SERVER['HTTP_CLIENT_IP'] ) && ! empty( sanitize_text_field( wp_unslash( $_SERVER['HTTP_CLIENT_IP'] ) ) ) ) {
|
|
$data[] = sanitize_text_field( wp_unslash( $_SERVER['HTTP_CLIENT_IP'] ) );
|
|
} elseif ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) && ! empty( sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) ) ) {
|
|
$data[] = sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_FORWARDED_FOR'] ) );
|
|
} else {
|
|
$data[] = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '';
|
|
}
|
|
continue;
|
|
}
|
|
if ( 'page-URL' === (string) $key ) {
|
|
$data[] = isset( $_SERVER['HTTP_REFERER'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '';
|
|
continue;
|
|
}
|
|
|
|
if ( in_array( $key, $input_quiz_array, true ) ) {
|
|
// @codingStandardsIgnoreStart.
|
|
if ( isset( $_POST[ $key ] ) ) {
|
|
$data[] = sanitize_text_field( wp_unslash( $_POST[ $key ] ) );
|
|
// @codingStandardsIgnoreEnd.
|
|
} else {
|
|
$data[] = '';
|
|
}
|
|
continue;
|
|
}
|
|
|
|
if ( ! isset( $posted_data[ $key ] ) ) {
|
|
$data[] = '';
|
|
continue;
|
|
}
|
|
|
|
if ( is_array( $posted_data[ $key ] ) ) {
|
|
$data[] .= implode( ',', $posted_data[ $key ] );
|
|
} else {
|
|
$field_type = self::search_forkey( $key, $field_data );
|
|
if ( 'file' === (string) $field_type ) {
|
|
if ( ! empty( $file_data[ $key ] ) ) {
|
|
$data[] = basename( $file_data[ $key ][0] );
|
|
} else {
|
|
$data[] = '';
|
|
}
|
|
continue;
|
|
}
|
|
if ( 'acceptance' === (string) $field_type ) {
|
|
if ( 1 === (int) $posted_data[ $key ] ) {
|
|
$data[] = 'Yes';
|
|
} else {
|
|
$data[] = 'No';
|
|
}
|
|
continue;
|
|
}
|
|
$data[] = $posted_data[ $key ];
|
|
}
|
|
}
|
|
if ( 'yes' === (string) $created_date[0] ) {
|
|
$data[] = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) );
|
|
}
|
|
$values = array( $data );
|
|
$requestbody = self::$instance_api->valuerangeobject( $values );
|
|
$params = array(
|
|
'valueInputOption' => 'USER_ENTERED',
|
|
);
|
|
$param = self::$instance_api->setparamater( $form_data[0]['spreadsheetname'], $form_data[0]['sheetname'], $requestbody, $params );
|
|
|
|
$response = self::$instance_api->appendentry( $param );
|
|
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Google sheet settings page
|
|
*
|
|
* @param object $post .
|
|
* @since 1.0
|
|
*/
|
|
public function wpsslc_editor_panel_google_sheet( $post ) {
|
|
?>
|
|
<div id="informationdivwpsslc" class="postbox">
|
|
<div class="inside">
|
|
<img src="<?php echo esc_url( plugin_dir_url( __FILE__ ) . '../assets/images/notice-logo.png' ); ?>">
|
|
<ul>
|
|
<li><?php echo esc_html( __( 'Edit Sheet Headers', 'wpssc' ) ); ?></li>
|
|
<li><?php echo esc_html( __( 'Sorting Sheet Headers', 'wpssc' ) ); ?></li>
|
|
<li><?php echo esc_html( __( 'User Agent & Submission Time Sheet Headers', 'wpssc' ) ); ?></li>
|
|
<li><?php echo esc_html( __( 'Special Mail Tags Options', 'wpssc' ) ); ?></li>
|
|
<li><?php echo esc_html( __( '6+ Third Party Plugins Compatibility', 'wpssc' ) ); ?></li>
|
|
</ul>
|
|
<a class="button button-primary" target="_blank" href="<?php echo esc_url( WPSSLC_PRO_VERSION_BUY_URL ); ?>"><?php echo esc_html( __( 'Buy Now', 'wpssc' ) ); ?></a>
|
|
</div>
|
|
</div>
|
|
<?php
|
|
// @codingStandardsIgnoreStart.
|
|
if ( isset( $_GET['post'] ) ) {
|
|
|
|
$form_id = sanitize_text_field( wp_unslash( $_GET['post'] ) );
|
|
// @codingStandardsIgnoreEnd.
|
|
$form_data = self::$instance_api->wpsslc_option( 'wpssc_cf_settings', '', $form_id );
|
|
$wpsslc_google_settings_value = self::$instance_api->wpsslc_option( 'wpssc_google_settings' );
|
|
|
|
$wpsslc_error = '';
|
|
|
|
if ( ! empty( $wpsslc_google_settings_value[2] ) ) {
|
|
if ( ! self::$instance_api->getClient() ) {
|
|
$wpsslc_error = self::$instance_api->getClient( 1 );
|
|
if ( 'Invalid token format' === (string) $wpsslc_error ) {
|
|
|
|
$wpsslc_error = '<strong class="err-msg">' . esc_html__( 'Error: Invalid Token - ', 'wpssc' ) . '<a href="' . esc_url( admin_url( 'admin.php?page=wpsyncsheets-contact-form-7' ) ) . '">' . esc_html__( 'Click here</a> to check more information.', 'wpssc' ) . '';
|
|
|
|
} else {
|
|
|
|
$wpsslc_error = '<strong class="err-msg">Error: ' . $wpsslc_error . '</strong>';
|
|
|
|
}
|
|
}
|
|
} else {
|
|
echo '<strong class="err-msg">' . esc_html__( 'Please genearate authentication code from', 'wpssc' ) . '</strong>';
|
|
?>
|
|
<?php echo esc_html__( 'Google API Settings', 'wpssc' ); ?><strong>
|
|
<a href='<?php echo esc_url( 'admin.php?page=wpsyncsheets-contact-form-7' ); ?>'> <?php echo esc_html__( 'Click here', 'wpssc' ); ?></a></strong>
|
|
<?php
|
|
return;
|
|
}
|
|
if ( ! empty( $wpsslc_error ) ) {
|
|
$allowed_html = wp_kses_allowed_html( 'post' );
|
|
echo wp_kses( $wpsslc_error, $allowed_html );
|
|
return;
|
|
}
|
|
|
|
$sheetarray = self::wpsslc_list_googlespreedsheet();
|
|
$wpsslc_spreadsheetname = '';
|
|
$wpsslc_sheetname = '';
|
|
if ( isset( $form_data[0] ) && isset( $form_data[0]['spreadsheetname'] ) ) {
|
|
$wpsslc_spreadsheetname = $form_data[0]['spreadsheetname'];
|
|
}
|
|
if ( isset( $form_data[0] ) && isset( $form_data[0]['sheetname'] ) ) {
|
|
$wpsslc_sheetname = $form_data[0]['sheetname'];
|
|
}
|
|
if ( ! empty( $wpsslc_spreadsheetname ) && ! array_key_exists( $wpsslc_spreadsheetname, $sheetarray ) ) {
|
|
$wpsslc_spreadsheetname = '';
|
|
$wpsslc_sheetname = '';
|
|
}
|
|
$sheetname = array();
|
|
if ( 'new' !== (string) $wpsslc_spreadsheetname && '' !== (string) $wpsslc_spreadsheetname ) {
|
|
$sheetname = self::sheet_for_form_setting( $form_data );
|
|
}
|
|
if ( isset( $sheetname ) ) {
|
|
if ( in_array( $wpsslc_sheetname, $sheetname, true ) ) {
|
|
$checkheaders = self::wpsslc_check_spreadsheet_header_value( $form_id );
|
|
} else {
|
|
$wpsslc_sheetname = '';
|
|
}
|
|
}
|
|
?>
|
|
<form method="post" id="googlesetting">
|
|
<?php wp_nonce_field( 'save_sheet_settings', 'wpsslc_sheet_settings' ); ?>
|
|
<div class="gs-fields">
|
|
<h2><span><?php echo esc_html( __( 'WPSyncSheets Lite For Contact Form 7 Settings', 'wpssc' ) ); ?></span></h2>
|
|
<p class="wpsslc_all_settings">
|
|
<label><?php echo esc_html( __( 'All Settings', 'wpssc' ) ); ?></label>
|
|
<label>
|
|
<input type="checkbox" name="wpsslc_all_settings" id="wpsslc_all_settings" value="yes"
|
|
<?php
|
|
$wpsslc_all_settings = get_post_meta( $form_id, 'wpssc_all_settings', true );
|
|
if ( 'no' !== (string) $wpsslc_all_settings ) {
|
|
echo 'checked=checked';
|
|
}
|
|
?>
|
|
><span class="checkbox-switch"></span>
|
|
</label>
|
|
</p>
|
|
<div class="all_settings_div">
|
|
<p>
|
|
<label><?php echo esc_html( __( 'Select Google Spreadsheet', 'wpssc' ) ); ?></label>
|
|
<select name="wpsslc[spreadsheetname]" id="spreadsheetid" >
|
|
<?php
|
|
if ( ! empty( $sheetarray ) ) {
|
|
foreach ( $sheetarray as $key => $val ) {
|
|
if ( isset( $wpsslc_spreadsheetname ) && $wpsslc_spreadsheetname === $key ) {
|
|
?>
|
|
<option value="<?php echo esc_attr( $key ); ?>" selected><?php echo esc_html( $val ); ?></option>
|
|
<?php
|
|
} else {
|
|
?>
|
|
<option value="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $val ); ?></option>
|
|
<?php
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
</select>
|
|
<?php if ( isset( $wpsslc_spreadsheetname ) && ! empty( $wpsslc_spreadsheetname ) ) { ?>
|
|
<a id="view_spreadsheet" target="_blank" href="<?php echo esc_url( 'https://docs.google.com/spreadsheets/d/' . $wpsslc_spreadsheetname ); ?>" class="wpsslc-button"><?php echo esc_html( __( 'View Spreadsheet', 'wpssc' ) ); ?></a>
|
|
<a id="download_spreadsheet" target="_blank" href="<?php echo esc_url( 'https://docs.google.com/spreadsheets/d/' . $wpsslc_spreadsheetname . '/export' ); ?>" class="wpsslc-button"><?php echo esc_html( __( 'Download Spreadsheet', 'wpssc' ) ); ?></a>
|
|
<?php } ?>
|
|
</p>
|
|
<?php
|
|
if ( isset( $wpsslc_spreadsheetname ) && 'new' !== (string) $wpsslc_spreadsheetname && '' !== (string) $wpsslc_spreadsheetname ) {
|
|
?>
|
|
<p class="custom-sheet">
|
|
<input type="hidden" id="prev_selected_sheet" value="<?php echo esc_attr( $wpsslc_spreadsheetname ); ?>" />
|
|
<label><?php echo esc_html( __( 'Select Sheet Name', 'wpssc' ) ); ?></label>
|
|
<select name="wpsslc[sheetname]" id="sheetname" >
|
|
<?php
|
|
if ( ! empty( $sheetname ) ) {
|
|
?>
|
|
<option value=""><?php echo esc_html( __( 'Select Sheet', 'wpssc' ) ); ?></option>
|
|
<?php
|
|
foreach ( $sheetname as $key => $val ) {
|
|
if ( isset( $wpsslc_sheetname ) && $wpsslc_sheetname === $val ) {
|
|
?>
|
|
<option value="<?php echo esc_attr( $val ); ?>" selected><?php echo esc_html( $val ); ?></option>
|
|
<?php
|
|
} else {
|
|
?>
|
|
<option value="<?php echo esc_attr( $val ); ?>"><?php echo esc_html( $val ); ?></option>
|
|
<?php
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
</select>
|
|
</p>
|
|
<?php } ?>
|
|
<p class="custom-new-sheet">
|
|
<label><?php echo esc_html( __( 'Enter Spreadsheet name', 'wpssc' ) ); ?></label>
|
|
<input type="text" name="new_spreadsheetname" id="new_spreadsheetname">
|
|
</p>
|
|
<p class="custom-new-sheet">
|
|
<label><?php echo esc_html( __( 'Enter Sheet name', 'wpssc' ) ); ?></label>
|
|
<input type="text" name="new_sheetname" id="new_sheetname">
|
|
</p>
|
|
<?php
|
|
if ( isset( $wpsslc_sheetname ) && ! empty( $wpsslc_sheetname ) ) {
|
|
?>
|
|
<p class="mapfields">
|
|
<label><?php echo esc_html( __( 'Sheet Headers', 'wpssc' ) ); ?></label>
|
|
<?php
|
|
// phpcs:ignore
|
|
$post_data = isset( $_GET['post'] ) ? self::get_form_data( $_GET['post'] ) : array();
|
|
?>
|
|
</p>
|
|
<?php
|
|
$form_fields = self::single_array( $post_data );
|
|
$mapping_fields = get_post_meta( $form_id, 'field_mapping_settings' );
|
|
$active_headers = get_post_meta( $form_id, 'wpssc_active_headers' );
|
|
|
|
$freeze = get_post_meta( $form_id, 'freeze_header' );
|
|
$created_date = get_post_meta( $form_id, 'created_date' );
|
|
$new_headers = array();
|
|
|
|
if ( isset( $mapping_fields[0] ) ) {
|
|
foreach ( $mapping_fields[0] as $key => $value ) {
|
|
if ( 'IP-address' === (string) $key || 'page-URL' === (string) $key ) {
|
|
continue;
|
|
}
|
|
if ( ! in_array( $key, $form_fields, true ) ) {
|
|
if ( isset( $active_headers[0] ) && array_key_exists( $key, $active_headers[0] ) ) {
|
|
continue;
|
|
}
|
|
unset( $mapping_fields[0][ $key ] );
|
|
continue;
|
|
}
|
|
if ( isset( $active_headers[0] ) && false === array_key_exists( $key, $active_headers[0] ) ) {
|
|
$field_name = ucwords( preg_replace( '/[^A-Za-z0-9\-]/', ' ', $key ) );
|
|
$field_name = ucwords( str_replace( '-', ' ', $field_name ) );
|
|
$mapping_fields[0][ $key ] = $field_name;
|
|
}
|
|
}
|
|
}
|
|
|
|
array_push( $form_fields, 'IP-address' );
|
|
array_push( $form_fields, 'page-URL' );
|
|
|
|
if ( isset( $mapping_fields[0] ) && ! empty( $mapping_fields[0] ) ) {
|
|
self::check_mapping_fields( $mapping_fields );
|
|
if ( $active_headers ) {
|
|
self::check_active_headers( $active_headers );
|
|
}
|
|
$j = 0;
|
|
$total_mapping_fields = count( $mapping_fields[0] );
|
|
echo '<input type="hidden" name=wpsslc_total_mapping_fields value="' . esc_html( $total_mapping_fields ) . '">';
|
|
echo '<ul class="sheet-headers ui-sortable" id="sortable">';
|
|
|
|
foreach ( $mapping_fields[0] as $shorcode => $header_title ) {
|
|
|
|
$is_active = '';
|
|
if ( $active_headers ) {
|
|
if ( array_key_exists( $shorcode, $active_headers[0] ) ) {
|
|
$is_active = 'checked';
|
|
}
|
|
} else {
|
|
$is_active = 'checked'; }
|
|
|
|
?>
|
|
<li class="ui-state-default ui-sortable-handle">
|
|
<label for="c_<?php echo esc_attr( $j ); ?>"><span class="contacttextfield"><?php echo esc_html( $header_title ); ?></span>
|
|
<input type="checkbox" class="wpsslc_active" id="c_<?php echo esc_attr( $j ); ?>" name="active_header_value_<?php echo esc_attr( $j ); ?>" value="1" <?php echo esc_attr( $is_active ); ?> >
|
|
<span class="checkbox-switch-new"></span></label>
|
|
<input type="hidden" class="header_shortcode" name="header_shortcode_<?php echo esc_attr( $j ); ?>" value="<?php echo esc_attr( $shorcode ); ?>"/>
|
|
<input type="hidden" class="header_value" name="header_value_<?php echo esc_attr( $j ); ?>" value="<?php echo esc_attr( $header_title ); ?>"/>
|
|
<span class="fieldsmap">
|
|
<?php
|
|
echo esc_html__( 'Map Field : ', 'wpssc' ) . esc_html( $shorcode );
|
|
?>
|
|
</span>
|
|
</li>
|
|
<?php $j++; } ?> </ul>
|
|
<?php } else { ?>
|
|
<ul class="sheet-headers">
|
|
<?php
|
|
$is_active = 'checked';
|
|
$form_fields_count = count( $form_fields );
|
|
for ( $i = 0; $i < $form_fields_count; $i++ ) {
|
|
$field = ucwords( preg_replace( '/[^A-Za-z0-9\-]/', ' ', $form_fields[ $i ] ) );
|
|
$field = ucwords( str_replace( '-', ' ', $field ) );
|
|
?>
|
|
<li class="ui-state-default ui-sortable-handle">
|
|
<label for="c_<?php echo esc_attr( $i ); ?>"><span class="contacttextfield"><?php echo esc_html( $field ); ?></span>
|
|
<input type="checkbox" class="wpsslc_active" id="c_<?php echo esc_attr( $i ); ?>" name="active_header_value_<?php echo esc_attr( $i ); ?>" value="1" <?php echo esc_attr( $is_active ); ?> >
|
|
<span class="checkbox-switch-new"></span></label>
|
|
<input type="hidden" class="header_shortcode" name="header_shortcode_<?php echo esc_attr( $i ); ?>" value="<?php echo esc_attr( $form_fields[ $i ] ); ?>"/>
|
|
<input type="hidden" class="header_value" name="header_value_<?php echo esc_attr( $i ); ?>" value="<?php echo esc_attr( $field ); ?>"/>
|
|
<span class="fieldsmap">
|
|
<?php
|
|
echo esc_html__( 'Map Field : ', 'wpssc' ) . esc_html( $form_fields[ $i ] );
|
|
?>
|
|
</span>
|
|
</li>
|
|
<?php } ?>
|
|
</ul>
|
|
<?php
|
|
}
|
|
?>
|
|
<button type="button" class="wpsslc-button wpsslc-button-secondary" id="selectall"><?php echo esc_html__( 'Select All', 'wpssc' ); ?></button>
|
|
<button type="button" class="wpsslc-button wpsslc-button-secondary" id="selectnone"><?php echo esc_html__( 'Select None', 'wpssc' ); ?></button>
|
|
|
|
<p class="freeze_header">
|
|
<label><?php echo esc_html( __( 'Freeze Header', 'wpssc' ) ); ?></label>
|
|
<label>
|
|
<input type="checkbox" name="freeze_header" value="yes"
|
|
<?php
|
|
if ( isset( $freeze[0] ) && 'yes' === (string) $freeze[0] ) {
|
|
echo 'checked=checked';}
|
|
?>
|
|
><span class="checkbox-switch"></span>
|
|
</label>
|
|
</p>
|
|
<p class="created_date">
|
|
<label><?php echo esc_html( __( 'Submission Date', 'wpssc' ) ); ?></label>
|
|
<label>
|
|
<input type="checkbox" name="created_date" value="yes"
|
|
<?php
|
|
if ( isset( $created_date[0] ) && 'yes' === (string) $created_date[0] ) {
|
|
echo 'checked=checked';}
|
|
?>
|
|
><span class="checkbox-switch"></span>
|
|
</label>
|
|
</p>
|
|
<?php if ( ! empty( $mapping_fields[0] ) ) { ?>
|
|
<p class="clear-spreadsheet">
|
|
<label><?php echo esc_html( __( 'Clear Spreadsheet', 'wpssc' ) ); ?></label>
|
|
<label>
|
|
<a id="clear_spreadsheet" href="" data-form-id="<?php echo esc_attr( $form_id ); ?>" class="wpsslc-button"><?php echo esc_html( __( 'Click to Clear', 'wpssc' ) ); ?></a>
|
|
<img src="<?php dirname( __FILE__ ); ?>images/spinner.gif" id="clearloader">
|
|
</label>
|
|
<?php wp_nonce_field( 'wpnonce_clearsheets', 'wpsslc_clearsheets' ); ?>
|
|
</p>
|
|
<?php }
|
|
}?>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
<?php
|
|
} else {
|
|
echo esc_html__( 'Please save your newly created form for WPSyncSheets Lite For Contact Form 7 settings.', 'wpssc' );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Prepare Google Spreadsheet list
|
|
*
|
|
* @access public
|
|
* @return array $sheetarray
|
|
*/
|
|
public static function wpsslc_list_googlespreedsheet() {
|
|
$sheetarray = array(
|
|
'' => __( 'Select Google Spreeadsheet List', 'wpssc' ),
|
|
);
|
|
$sheetarray = self::$instance_api->get_spreadsheet_listing( $sheetarray );
|
|
return $sheetarray;
|
|
}
|
|
|
|
/**
|
|
* Prepare Google Spreedsheet sheet name for feed setting.
|
|
*
|
|
* @access public
|
|
* @param array $data selected spreadsheet data .
|
|
* @return array $choices
|
|
*/
|
|
public function sheet_for_form_setting( $data ) {
|
|
|
|
/* Build choices array. */
|
|
$choices = 'Select a Sheet List';
|
|
/* Get feed settings. */
|
|
$settings = isset( $data[0]['spreadsheetname'] ) ? $data[0]['spreadsheetname'] : '';
|
|
if ( '' === $data[0]['spreadsheetname'] || 'new' === $data[0]['spreadsheetname'] ) {
|
|
return $choices;
|
|
}
|
|
// get worksheet name.
|
|
$response = self::$instance_api->get_sheet_listing( $data[0]['spreadsheetname'] );
|
|
foreach ( $response->getSheets() as $s ) {
|
|
$sheets[] = $s['properties']['title'];
|
|
}
|
|
return $sheets;
|
|
}
|
|
|
|
/**
|
|
* Get form data.
|
|
*
|
|
* @access public
|
|
* @param object $form .
|
|
* @return array $assoc_arr
|
|
*/
|
|
public function get_form_data( $form ) {
|
|
$assoc_arr = array();
|
|
$meta = get_post_meta( $form, '_form', true );
|
|
|
|
$fields = self::get_fields( $meta );
|
|
foreach ( $fields as $field ) {
|
|
|
|
$single = self::get_field_assoc( $field );
|
|
if ( $single ) {
|
|
$assoc_arr[] = $single;
|
|
}
|
|
}
|
|
return $assoc_arr;
|
|
}
|
|
|
|
/**
|
|
* Get form fields.
|
|
*
|
|
* @access public
|
|
* @param string $meta .
|
|
* @return array $arr
|
|
*/
|
|
public function get_fields( $meta ) {
|
|
$regexp = '/\[.*\]/';
|
|
$arr = array();
|
|
|
|
if ( preg_match_all( $regexp, $meta, $arr ) === false ) {
|
|
return false;
|
|
}
|
|
return $arr[0];
|
|
}
|
|
|
|
/**
|
|
* Get associative form fields.
|
|
*
|
|
* @access public
|
|
* @param string $content .
|
|
* @return array
|
|
*/
|
|
public function get_field_assoc( $content ) {
|
|
$regexp_type = '/(?<=\[)[^\s\*]*/';
|
|
$regexp_name = '/(?<=\s)[^\s\]]*/';
|
|
|
|
$arr_type = array();
|
|
$arr_name = array();
|
|
if ( false === preg_match( $regexp_type, $content, $arr_type ) ) {
|
|
return false;
|
|
}
|
|
if ( ! in_array( $arr_type[0], $this->allowed_tags, true ) ) {
|
|
return false;
|
|
}
|
|
if ( false === preg_match( $regexp_name, $content, $arr_name ) ) {
|
|
return false;
|
|
}
|
|
|
|
return array( $arr_type[0] => $arr_name[0] );
|
|
}
|
|
|
|
/**
|
|
* Serch for key in given array using given value
|
|
*
|
|
* @access public
|
|
* @param string $value is to search in arrray.
|
|
* @param array $array .
|
|
* @return string $key or null
|
|
*/
|
|
public function search_forkey( $value, $array ) {
|
|
foreach ( $array as $key => $val ) {
|
|
$key = array_search( $value, $val, true );
|
|
if ( $key ) {
|
|
return $key;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Check Mapping fields
|
|
*
|
|
* @param array $mapping_fields .
|
|
*/
|
|
public function check_mapping_fields( $mapping_fields ) {
|
|
if ( ! array_key_exists( 'IP-address', $mapping_fields[0] ) ) {
|
|
$mapping_fields[0]['IP-address'] = 'IP Address';
|
|
}
|
|
if ( ! array_key_exists( 'page-URL', $mapping_fields[0] ) ) {
|
|
$mapping_fields[0]['page-URL'] = 'Page URL';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Check active headers
|
|
*
|
|
* @param array $active_headers .
|
|
*/
|
|
public function check_active_headers( $active_headers ) {
|
|
if ( ! array_key_exists( 'IP-address', $active_headers[0] ) ) {
|
|
$active_headers[0]['IP-address'] = '1';
|
|
}
|
|
if ( ! array_key_exists( 'page-URL', $active_headers[0] ) ) {
|
|
$active_headers[0]['page-URL'] = '1';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Create simple index array
|
|
*
|
|
* @access public
|
|
* @param array $arr .
|
|
* @return array $new_arr
|
|
*/
|
|
public static function single_array( $arr ) {
|
|
$new_arr = array();
|
|
foreach ( $arr as $key ) {
|
|
if ( is_array( $key ) ) {
|
|
$arr1 = self::single_array( $key );
|
|
foreach ( $arr1 as $k ) {
|
|
$new_arr[] = $k;
|
|
}
|
|
} else {
|
|
$new_arr[] = $key;
|
|
}
|
|
}
|
|
return $new_arr;
|
|
}
|
|
/**
|
|
* Prepare Google Spreedsheet sheet headers for mapping fields to form fields.
|
|
*
|
|
* @access public
|
|
* @param int $form_id .
|
|
* @param int $param .
|
|
*/
|
|
public static function wpsslc_check_spreadsheet_header_value( $form_id, $param = 0 ) {
|
|
|
|
$form_data = self::$instance_api->wpsslc_option( 'wpssc_cf_settings', '', $form_id );
|
|
|
|
if ( ( ! empty( $form_data[0]['spreadsheetname'] ) ) && ( ! empty( $form_data[0]['sheetname'] ) ) ) {
|
|
|
|
$spreadsheetid = $form_data[0]['spreadsheetname'];
|
|
$spredsheet = $form_data[0]['sheetname'] . '!A1:Z1';
|
|
|
|
$response = self::$instance_api->get_row_list( $spreadsheetid, $spredsheet );
|
|
$values = $response->getValues();
|
|
|
|
if ( 1 === (int) $param ) {
|
|
return $response['values'];
|
|
}
|
|
if ( empty( $response['values'] ) ) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Reset Google API Settings
|
|
*/
|
|
public static function wpsslc_reset_settings() {
|
|
try {
|
|
$wpsslc_google_settings_value = self::$instance_api->wpsslc_option( 'wpssc_google_settings' );
|
|
$settings = array();
|
|
foreach ( $wpsslc_google_settings_value as $key => $value ) {
|
|
$settings[ $key ] = '';
|
|
}
|
|
self::$instance_api->wpsslc_update_option( 'wpssc_google_settings', $settings );
|
|
self::$instance_api->wpsslc_update_option( 'wpssc_google_accessToken', '' );
|
|
} catch ( Exception $e ) {
|
|
echo esc_html( 'Message: ' . $e->getMessage() );
|
|
}
|
|
echo esc_html( 'successful' );
|
|
wp_die();
|
|
}
|
|
/**
|
|
* Clear spreadsheet
|
|
*
|
|
* @access public
|
|
*/
|
|
public static function wpsslc_clear_sheet() {
|
|
|
|
$wpsslc_error = '';
|
|
$form_id = isset( $_POST['form_id'] ) ? sanitize_text_field( wp_unslash( $_POST['form_id'] ) ) : '';
|
|
if ( ! isset( $_POST['wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['wpnonce'] ) ), 'wpnonce_clearsheets' ) || empty( $form_id ) ) {
|
|
echo esc_html__( 'Sorry, your nonce did not verify.', 'wpssc' );
|
|
wp_die();
|
|
}
|
|
|
|
$form_data = self::$instance_api->wpsslc_option( 'wpssc_cf_settings', '', $form_id );
|
|
$wpsslc_active_headers = self::$instance_api->wpsslc_option( 'wpssc_active_headers', '', $form_id );
|
|
|
|
$wpsslc_spreadsheetid = $form_data[0]['spreadsheetname'];
|
|
$sheetname = $form_data[0]['sheetname'];
|
|
|
|
$total_headers = count( $wpsslc_active_headers[0] );
|
|
$r = self::$instance_api->get_row_list( $wpsslc_spreadsheetid, $sheetname );
|
|
|
|
foreach ( $r['values'][0] as $data_value ) {
|
|
if ( 'Submission Date' === (string) $data_value ) {
|
|
$total_headers++;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
$last_column = self::get_column_index( $total_headers );
|
|
try {
|
|
$range = $sheetname . '!A2:' . $last_column . '100000';
|
|
$requestbody = self::$instance_api->clearobject();
|
|
$param = array();
|
|
$param['spreadsheetid'] = $wpsslc_spreadsheetid;
|
|
$param['sheetname'] = $range;
|
|
$param['requestbody'] = $requestbody;
|
|
$response = self::$instance_api->clear( $param );
|
|
echo esc_html( 'successful' );
|
|
} catch ( Exception $e ) {
|
|
echo esc_html( 'Message: ' . $e->getMessage() );
|
|
}
|
|
wp_die();
|
|
}
|
|
/**
|
|
* Get column index of sheet
|
|
*
|
|
* @access public
|
|
* @param int $number .
|
|
* @return string $letter
|
|
*/
|
|
public static function get_column_index( $number ) {
|
|
if ( $number <= 0 ) {
|
|
return null;
|
|
}
|
|
|
|
$temp;
|
|
$letter = '';
|
|
while ( $number > 0 ) {
|
|
$temp = ( $number - 1 ) % 26;
|
|
$letter = chr( $temp + 65 ) . $letter;
|
|
$number = ( $number - $temp - 1 ) / 26;
|
|
}
|
|
return $letter;
|
|
}
|
|
|
|
}
|
|
$instance = new WPSSLC_Service();
|
|
|