get('Name') . ' ' . $theme_data->get('Version'); $parent_theme = $theme_data->get('Template'); if (!empty($parent_theme)) { $parent_theme_data = wp_get_theme($parent_theme); $parent_theme_name_version = $parent_theme_data->get('Name') . ' ' . $parent_theme_data->get('Version'); } else { $parent_theme_name_version = 'N/A'; } // Check plugin version and subscription plan $plugin_version = defined('GS_CONNECTOR_VERSION') ? GS_CONNECTOR_VERSION : 'N/A'; $subscription_plan = 'FREE'; // Check Google Account Authentication // $api_token = get_option('gs_token'); // $google_sheet = new CF7GSC_googlesheet_PRO(); // $email_account = $google_sheet->gsheet_print_google_account_email(); $api_token_auto = get_option('gs_token'); if (!empty($api_token_auto)) { // The user is authenticated through the auto method $google_sheet_auto = new CF7GSC_googlesheet(); $email_account_auto = $google_sheet_auto->gsheet_print_google_account_email(); $connected_email = !empty($email_account_auto) ? esc_html($email_account_auto) : 'Not Auth'; } else { // Neither auto nor manual authentication is available $connected_email = 'Not Auth'; } // Check Google Permission $gs_verify_status = get_option('gs_verify'); $search_permission = ($gs_verify_status === 'valid') ? 'Given' : 'Not Given'; // Create the system info HTML $system_info = '
'; $system_info .= '

'; $system_info .= ''; // Add WordPress info // Create a button for WordPress info $system_info .= '

'; $system_info .= ''; // info about active theme $active_theme = wp_get_theme(); $system_info .= '

'; $system_info .= ''; // Get a list of other plugins you want to check compatibility with $other_plugins = array( 'plugin-folder/plugin-file.php', // Replace with the actual plugin slug // Add more plugins as needed ); // Network Active Plugins if (is_multisite()) { $network_active_plugins = get_site_option('active_sitewide_plugins', array()); if (!empty($network_active_plugins)) { $system_info .= '

'; $system_info .= ''; } } // Active plugins $system_info .= '

'; $system_info .= ''; // Webserver Configuration $system_info .= '

'; $system_info .= ''; // Database Configuration $system_info .= '

'; $system_info .= ''; // wordpress constants $system_info .= '

'; $system_info .= ''; // Filesystem Permission $system_info .= '

'; $system_info .= ''; return $system_info; } public function display_error_cf7_log() { // Define the path to your debug log file $debug_log_file = WP_CONTENT_DIR. '/debug.log'; // Check if the debug log file exists if (file_exists($debug_log_file)) { // Read the contents of the debug log file $debug_log_contents = file_get_contents($debug_log_file); // Split the log content into an array of lines $log_lines = explode("\n", $debug_log_contents); // Get the last 100 lines in reversed order $last_100_lines = array_slice(array_reverse($log_lines), 0, 100); // Join the lines back together with line breaks $last_100_log = implode("\n", $last_100_lines); // Output the last 100 lines in reversed order in a textarea ?> revokeToken_auto($accesstoken); delete_option('gs_token'); delete_option('gs_access_code'); delete_option('gs_verify'); wp_send_json_success(); } else { wp_send_json_error(); } } /** * AJAX function - clear log file * @since 2.1 */ public function gs_clear_logs() { // nonce check check_ajax_referer( 'gs-ajax-nonce', 'security' ); $existDebugFile = get_option('gs_debug_log_file'); $clear_file_msg =''; // check if debug unique log file exist or not then exists to clear file if (!empty($existDebugFile) && file_exists($existDebugFile)) { $handle = fopen ( $existDebugFile, 'w'); fclose( $handle ); $clear_file_msg ='Logs are cleared.'; } else{ $clear_file_msg = 'No log file exists to clear logs.'; } wp_send_json_success($clear_file_msg); } /** * AJAX function - clear log file for system status tab * @since 2.1 */ public function cf7_clear_debug_logs() { // nonce check check_ajax_referer('gs-ajax-nonce', 'security'); $handle = fopen(WP_CONTENT_DIR . '/debug.log', 'w'); fclose($handle); wp_send_json_success(); } /** * Add new tab to contact form 7 editors panel * @since 1.0 */ public function cf7_gs_editor_panels( $panels ) { if ( current_user_can( 'wpcf7_edit_contact_forms' ) ) { $panels['google_sheets'] = array( 'title' => __( '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 ); } /** * Create array of file name for the uploaded files * @since 4.5 */ public function save_uploaded_files_local() { $form = WPCF7_Submission::get_instance(); if ( $form ) { $files = $form->uploaded_files(); $uploads_stored = array(); foreach ( $files as $field_name => $file_path ) { if ( ! isset( $_FILES[ $field_name ] ) ) { continue; } $file_details = $_FILES[ $field_name ]; $file_name = $file_details['name']; $uploads_stored[ $field_name ] = $file_name; } $this->gs_uploads = $uploads_stored; } } /** * 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 ) { $tagname = sprintf( '_%s', $smt ); $mail_tag = new WPCF7_MailTag( sprintf( '[%s]', $tagname ), $tagname, '' ); $meta[$smt] = apply_filters( 'wpcf7_special_mail_tags', '', $tagname, false, $mail_tag ); } 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 { // Get file name array $uploaded_file = $this->gs_uploads; if ( array_key_exists( $key, $uploaded_file ) || isset( $uploaded_file[ $key ] ) ) { $data[ $key ] = sanitize_file_name( $uploaded_file[ $key ] ); continue; } // handle strings and array elements if ( is_array( $value ) ) { $data[ $key ] = sanitize_text_field( implode( ', ', $value ) ); } else { //$data[$key] = sanitize_text_field(stripcslashes($value));//Old Code $data[$key] = sanitize_textarea_field(stripcslashes($value));//Line Break in textarea issue resolved. } } } // Filter Form Submitted data such as for repetable fields plugin $data = apply_filters( 'gsc_filter_form_data', $data, $form ); if( ! empty( $data[0] ) && is_array( $data[0] ) ) { $doc->add_multiple_row( $data ); } else { $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' ); // Check if the user is authenticated $authenticated = get_option('gs_token'); $per = get_option('gs_verify'); $per_msg = __( 'invalid-auth', 'gsconnector' ); // check user is authenticated when save existing api method $show_setting = 0; if ((!empty($authenticated) && $per == "valid") ) { $show_setting = 1; } else{ ?>

Authentication Required: You must have to Authenticate using your Google Account along with Google Drive and Google Sheets Permissions in order to enable the settings for configuration.', '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 ) ) { ?> ' . __( '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; ?>

' . __( '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();