__( 'Google Sheets', 'contact-form-7' ), 'callback' => array( $this, 'cf7_editor_panel_google_sheet' ) ); } return $panels; } /** * Set Google sheet settings with contact form * @since 1.0 */ public function save_gs_settings( $post ) { $default = array( "sheet-name" => "", "sheet-id" => "", "sheet-tab-name" => "", "tab-id" => "" ); $sheet_data = isset( $_POST['cf7-gs'] ) ? $_POST['cf7-gs'] : $default; update_post_meta( $post->id(), 'gs_settings', $sheet_data ); } /** * Function - To send contact form data to google spreadsheet * @param object $form * @since 1.0 */ public function cf7_save_to_google_sheets( $form ) { $submission = WPCF7_Submission::get_instance(); // get form data $form_id = $form->id(); $form_data = get_post_meta( $form_id, 'gs_settings' ); $data = array(); // if contact form sheet name and tab name is not empty than send data to spreedsheet if ( $submission && (! empty( $form_data[0]['sheet-name'] ) ) && (! empty( $form_data[0]['sheet-tab-name'] ) ) ) { $posted_data = $submission->get_posted_data(); // make sure the form ID matches the setting otherwise don't do anything try { include_once( GS_CONNECTOR_ROOT . "/lib/google-sheets.php" ); $doc = new cf7gsc_googlesheet(); $doc->auth(); $doc->setSpreadsheetId( $form_data[0]['sheet-id'] ); $doc->setWorkTabId( $form_data[0]['tab-id'] ); // Special Mail Tags $meta = array(); $special_mail_tags = array( 'serial_number', 'remote_ip', 'user_agent', 'url', 'date', 'time', 'post_id', 'post_name', 'post_title', 'post_url', 'post_author', 'post_author_email', 'site_title', 'site_description', 'site_url', 'site_admin_email', 'user_login', 'user_email', 'user_url', 'user_first_name', 'user_last_name', 'user_nickname', 'user_display_name' ); foreach ( $special_mail_tags as $smt ) { $meta[$smt] = apply_filters( 'wpcf7_special_mail_tags', '', sprintf( '_%s', $smt ), '', false ); } if ( ! empty( $meta ) ) { $data["date"] = $meta["date"]; $data["time"] = $meta["time"]; $data["serial-number"] = $meta["serial_number"]; $data["remote-ip"] = $meta["remote_ip"]; $data["user-agent"] = $meta["user_agent"]; $data["url"] = $meta["url"]; $data["post-id"] = $meta["post_id"]; $data["post-name"] = $meta["post_name"]; $data["post-title"] = $meta["post_title"]; $data["post-url"] = $meta["post_url"]; $data["post-author"] = $meta["post_author"]; $data["post-author-email"] = $meta["post_author_email"]; $data["site-title"] = $meta["site_title"]; $data["site-description"] = $meta["site_description"]; $data["site-url"] = $meta["site_url"]; $data["site-admin-email"] = $meta["site_admin_email"]; $data["user-login"] = $meta["user_login"]; $data["user-email"] = $meta["user_email"]; $data["user-url"] = $meta["user_url"]; $data["user-first-name"] = $meta["user_first_name"]; $data["user-last-name"] = $meta["user_last_name"]; $data["user-nickname"] = $meta["user_nickname"]; $data["user-display-name"] = $meta["user_display_name"]; } foreach ( $posted_data as $key => $value ) { // exclude the default wpcf7 fields in object if ( strpos( $key, '_wpcf7' ) !== false || strpos( $key, '_wpnonce' ) !== false ) { // do nothing } else { // handle strings and array elements if ( is_array( $value ) ) { $data[$key] = implode( ', ', $value ); } else { $data[$key] = stripcslashes( $value ); } } } $doc->add_row( $data ); } catch ( Exception $e ) { $data['ERROR_MSG'] = $e->getMessage(); $data['TRACE_STK'] = $e->getTraceAsString(); Gs_Connector_Utility::gs_debug_log( $data ); } } } /* * Google sheet settings page * @since 1.0 */ public function cf7_editor_panel_google_sheet( $post ) { $form_id = sanitize_text_field( $_GET['post'] ); $form_data = get_post_meta( $form_id, 'gs_settings' ); ?>

PRO version )', 'gsconnector'); ?>

get_results("SELECT ID, post_title, meta_value from ".$wpdb->prefix."posts as p JOIN ".$wpdb->prefix."postmeta as pm on p.ID = pm.post_id where pm.meta_key='gs_settings' AND p.post_type='wpcf7_contact_form' ORDER BY p.ID"); return $query; } /** * Function - display contact form fields to be mapped to google sheet * @param int $form_id * @since 1.0 */ public function display_form_fields( $form_id ) { ?> get_contact_form_fields( $meta ); if( $fields ) { foreach ( $fields as $field ) { $single = $this->get_field_assoc( $field ); if ( $single ) { $assoc_arr[] = $single; } } } if( ! empty( $assoc_arr ) ) { ?> $value ) { foreach ( $value as $k => $v ) { $saved_val = ""; $checked = ""; if( ! empty( $saved_mail_tags ) && array_key_exists( $v, $saved_mail_tags[0] ) ) : $saved_val = $saved_mail_tags[0][$v]; $checked = "checked"; endif; $placeholder = preg_replace('/[\\_]|\\s+/', '-', $v ); ?>
> :
' . __( 'No mail tags available.','gsconnector' ) . '

'; } } public function get_contact_form_fields( $meta ) { $regexp = '/\[.*\]/'; $arr = []; if ( preg_match_all($regexp, $meta, $arr) == false) { return false; } return $arr[0]; } public function get_field_assoc($content) { $regexp_type = '/(?<=\[)[^\s\*]*/'; $regexp_name = '/(?<=\s)[^\s\]]*/'; $arr_type = []; $arr_name = []; if (preg_match($regexp_type, $content, $arr_type) == false) { return false; } if (!in_array($arr_type[0], $this->allowed_tags)) { return false; } if (preg_match($regexp_name, $content, $arr_name) == false) { return false; } return array($arr_type[0] => $arr_name[0]); } /** * Function - display contact form special mail tags to be mapped to google sheet * @since 2.6 */ public function display_form_special_tags( $form_id ) { $tags_count = count( $this->special_mail_tags ); $num_of_cols = 1; ?>

special_mail_tags[ $i ]; $placeholder = str_replace( '_', '-', $tag_name ); echo ''; echo ''; echo ''; echo ''; if ( $i % $num_of_cols == 1 ) { echo ''; } } ?>
[_' . $tag_name . ']
'; for ( $i = 0; $i <= $custom_tags_count; $i++ ) { if ( $i == $custom_tags_count ) { break; } $tag_name = $custom_tags[ $i ]; $modify_tag = ltrim( $tag_name, '_' ); $saved_val = ""; $checked = ""; if( ! empty( $saved_cmail_tags ) && array_key_exists( $modify_tag, $saved_cmail_tags[0] ) ) : $saved_val = $saved_cmail_tags[0][$modify_tag]; $checked = "checked"; endif; //hack - todo $placeholder_explode = explode( '_', $tag_name, 2 ); $placeholder = str_replace( '_', '-', $placeholder_explode[1] ); echo ''; echo ''; echo ''; if ( $i % $num_of_cols == 1 ) { echo ''; } } ?>
[' . $tag_name . ']
' . __( 'No custom mail tags available.','gsconnector' ) . '

'; } } public function display_upgrade_notice() { $get_notification_display_interval = get_option( 'gs_upgrade_notice_interval' ); $close_notification_interval = get_option( 'gs_close_upgrade_notice' ); if( $close_notification_interval === "off" ) { return; } if ( ! empty( $get_notification_display_interval ) ) { $adds_interval_date_object = DateTime::createFromFormat( "Y-m-d", $get_notification_display_interval ); $notice_interval_timestamp = $adds_interval_date_object->getTimestamp(); } if ( empty( $get_notification_display_interval ) || current_time( 'timestamp' ) > $notice_interval_timestamp ) { $ajax_nonce = wp_create_nonce( "gs_upgrade_ajax_nonce" ); $upgrade_text = '
'; $upgrade_text .= 'CF7 Google Sheet Connector '; $upgrade_text .= 'version 4.0 would required you to reauthenticate with your Google Account again due to update of Google API V3 to V4.

'; $upgrade_text .= 'To avoid any loss of data redo the Google Sheet settings of each Contact Forms again with required sheet and tab details.
'; $upgrade_text .= ''; $upgrade_text .= ''; $upgrade_text .= '
'; $upgrade_block = Gs_Connector_Utility::instance()->admin_notice( array( 'type' => 'upgrade', 'message' => $upgrade_text ) ); echo $upgrade_block; } } public function set_upgrade_notification_interval() { // check nonce check_ajax_referer( 'gs_upgrade_ajax_nonce', 'security' ); $time_interval = date( 'Y-m-d', strtotime( '+10 day' ) ); update_option( 'gs_upgrade_notice_interval', $time_interval ); wp_send_json_success(); } public function close_upgrade_notification_interval() { // check nonce check_ajax_referer( 'gs_upgrade_ajax_nonce', 'security' ); update_option( 'gs_close_upgrade_notice', 'off' ); wp_send_json_success(); } } $gs_connector_service = new Gs_Connector_Service();