';
// info about active theme
$active_theme = wp_get_theme();
$system_info .= '';
$system_info .= '
';
$system_info .= '
Active Theme
';
$system_info .= '
';
$system_info .= '
Name
' . $active_theme->get('Name') .'
';
$system_info .= '
Version
' . $active_theme->get('Version') .'
';
$system_info .= '
Author
' . $active_theme->get('Author') .'
';
$system_info .= '
Author website
' . $active_theme->get('AuthorURI') .'
';
$system_info .= '
Theme directory location
' . $active_theme->get_template_directory() .'
';
$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 .= '
';
// Retrieve all active plugins data
$active_plugins_data = array();
$active_plugins = get_option('active_plugins', array());
foreach ($active_plugins as $plugin) {
$plugin_data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin);
$active_plugins_data[$plugin] = array(
'name' => $plugin_data['Name'],
'version' => $plugin_data['Version'],
'count' => 0, // Initialize the count to zero
);
}
// Count the number of active installations for each plugin
$all_plugins = get_plugins();
foreach ($all_plugins as $plugin_file => $plugin_data) {
if (array_key_exists($plugin_file, $active_plugins_data)) {
$active_plugins_data[$plugin_file]['count']++;
}
}
// Sort plugins based on the number of active installations (descending order)
uasort($active_plugins_data, function ($a, $b) {
return $b['count'] - $a['count'];
});
// Display the top 5 most used plugins
$counter = 0;
foreach ($active_plugins_data as $plugin_data) {
$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 ) ) {
?>
';
$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 .= '