PluginProbe
Database Addon For WPForms ( wpforms entries ) – WPFormsDB / trunk
Database Addon For WPForms ( wpforms entries ) – WPFormsDB vtrunk
trunk 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.8.1 1.0.9 1.1.0
database-for-wpforms / database-for-wp-forms.php

database-for-wp-forms.php in Database Addon For WPForms ( wpforms entries ) – WPFormsDB trunk, at database-for-wp-forms.php

218 lines 6.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name:Database for WPforms
4 Description: Save and manage WPForms submissions. Never lose important data. Database add-on for WPForms.
5 Author: wpdebuglog
6 Text Domain: database-for-wpforms
7 Version: 1.1.0
8 License: GPL v2 or later
9 License URI: https://www.gnu.org/licenses/gpl-2.0.html
10 */
11
12 if ( ! defined( 'ABSPATH' ) ) exit;
13
14 function wpforms_db_plugin_load(){
15
16 load_plugin_textdomain( 'database-for-wpforms', false, plugin_basename( dirname( __FILE__ ) ) . '/lang' );
17 }
18
19 add_action('plugins_loaded', 'wpforms_db_plugin_load');
20
21
22 add_action('init', 'wpforms_db_init');
23
24 function wpforms_db_init(){
25 if( is_admin() ){
26 require_once 'inc/class-main-page.php';
27 require_once 'inc/class-sub-page.php';
28 require_once 'inc/class-form-details.php';
29 require_once 'inc/class-export-csv.php';
30
31 if( isset($_REQUEST['wpforms-csv']) && ( $_REQUEST['wpforms-csv'] == true ) && isset( $_REQUEST['nonce'] ) ) {
32
33 $nonce = sanitize_text_field( $_REQUEST['nonce'] );
34
35 if ( ! wp_verify_nonce( $nonce, 'dnonce' ) )
36 wp_die( esc_html__( 'Invalid nonce..!!', 'database-for-wpforms' ) );
37 $csv = new WPFormsDB_Export_CSV();
38 $csv->download_csv_file();
39 }
40 new WPFormsDB_Wp_Main_Page;
41 }
42 }
43
44
45 function WPFormsDB_create_table(){
46
47 global $wpdb;
48 $wpform = apply_filters( 'WPFormsDB_database', $wpdb );
49 $table_name = $wpform->prefix.'wpforms_db';
50
51 if( $wpform->get_var("SHOW TABLES LIKE '$table_name'") != $table_name ) {
52
53 $charset_collate = $wpform->get_charset_collate();
54
55 $sql = "CREATE TABLE $table_name (
56 form_id bigint(20) NOT NULL AUTO_INCREMENT,
57 form_post_id bigint(20) NOT NULL,
58 form_value longtext NOT NULL,
59 form_date datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
60 PRIMARY KEY (form_id)
61 ) $charset_collate;";
62
63 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
64 dbDelta( $sql );
65 }
66
67 add_option( 'WPFormsDB_view_install_date', gmdate('Y-m-d G:i:s'), '', 'yes');
68
69 }
70
71 function WPFormsDB_on_activate( $network_wide ){
72
73 global $wpdb;
74 if ( is_multisite() && $network_wide ) {
75 $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
76 foreach ( $blog_ids as $blog_id ) {
77 switch_to_blog( $blog_id );
78 WPFormsDB_create_table();
79 restore_current_blog();
80 }
81 } else {
82 WPFormsDB_create_table();
83 }
84
85 $role = get_role( 'administrator' );
86 $role->add_cap( 'WPFormsDB_access' );
87 }
88
89 register_activation_hook( __FILE__, 'WPFormsDB_on_activate' );
90
91
92 function WPFormsDB_on_deactivate() {
93
94 global $wp_roles;
95
96 foreach( array_keys( $wp_roles->roles ) as $role ) {
97 $wp_roles->remove_cap( $role, 'WPFormsDB_access' );
98 }
99 }
100
101 register_deactivation_hook( __FILE__, 'WPFormsDB_on_deactivate' );
102
103
104 function WPFormsDB_save( $fields, $entry, $form_id ) {
105
106 global $wpdb;
107 $wpform = apply_filters( 'WPFormsDB_database', $wpdb );
108 $table_name = $wpform->prefix.'wpforms_db';
109 $upload_dir = wp_upload_dir();
110
111
112 if ( $fields ) {
113
114 $data = $fields;
115 $uploaded_files = array();
116
117 $form_data = array();
118
119 $form_data['WPFormsDB_status'] = 'unread';
120 foreach ($data as $key => $d) {
121
122 $d['value'] = is_array( $d['value'] ) ? implode(',', $d['value']) : $d['value'];
123
124 $bl = array('\"',"\'",'/','\\','"',"'");
125 $wl = array('&quot;','&#039;','&#047;', '&#092;','&quot;','&#039;');
126 $d['value'] = str_replace($bl, $wl, $d['value'] );
127
128 $form_data[ $d['name'] ] = $d['value'];
129
130 }
131
132 $form_data = apply_filters('WPFormsDB_before_save_data', $form_data);
133
134 do_action( 'WPFormsDB_before_save_data', $form_data );
135
136 $form_post_id = $form_id;
137 $form_value = serialize( $form_data );
138 $form_date = current_time('Y-m-d H:i:s');
139
140 $wpform->insert( $table_name, array(
141 'form_post_id' => $form_post_id,
142 'form_value' => $form_value,
143 'form_date' => $form_date
144 ) );
145
146 $insert_id = $wpform->insert_id;
147 do_action( 'WPFormsDB_after_save_data', $insert_id, $form_data );
148 }
149
150 }
151
152 add_action( 'wpforms_process_entry_save', 'WPFormsDB_save', 10, 3 );
153
154 /**
155 * Plugin settings link
156 * @param array $links list of links
157 * @return array of links
158 */
159 function wpformsdb_settings_link( $links ) {
160 $forms_link = '<a href="admin.php?page=wp-forms-db-list.php">WPForms DB</a>';
161 array_unshift($links, $forms_link);
162 return $links;
163 }
164
165 $plugin = plugin_basename(__FILE__);
166 add_filter("plugin_action_links_$plugin", 'wpformsdb_settings_link' );
167
168 add_action( 'admin_notices', 'wpformsdb_admin_notice' );
169 add_action('admin_init', 'wpformsdb_view_ignore_notice' );
170
171 function wpformsdb_admin_notice() {
172
173 $install_date = get_option( 'WPFormsDB_view_install_date', '');
174 $install_date = date_create( $install_date );
175 $date_now = date_create( gmdate('Y-m-d G:i:s') );
176 $date_diff = date_diff( $install_date, $date_now );
177
178 if ( $date_diff->days < 7 ) {
179
180 return false;
181 }
182
183 if( empty($_GET['page']) ){
184 return;
185 }
186
187 if( isset($_GET['page']) && $_GET['page'] !== 'wp-forms-db-list.php' ){
188 return;
189 }
190
191 if ( 'true' === get_option( 'wpformsdb_view_ignore_notice' ) ) {
192 return;
193 }
194
195 echo '<div class="updated"><p>';
196
197 printf(
198 /* translators: 1: Settings URL, 2: Repository url */
199 __(
200 'Awesome, you\'ve been using <a href="%s" target="_blank">WPForms DB</a> for more than 1 week. May we ask you to give it a 5-star rating on WordPress? | <a href="%s" target="_blank">Ok, you deserved it</a> | <a href="%s">I already did</a> | <a href="%s">No, not good enough</a>', 'database-for-wpforms' ),
201 'https://wordpress.org/plugins/database-for-wpforms/',
202 'https://wordpress.org/support/plugin/database-for-wpforms/reviews/',
203 '?page=wp-forms-db-list.php&wpformsdb-ignore-notice=0',
204 '?page=wp-forms-db-list.php&wpformsdb-ignore-notice=0',
205 );
206 echo "</p></div>";
207
208 }
209
210 function wpformsdb_view_ignore_notice() {
211
212 if ( isset($_GET['wpformsdb-ignore-notice']) && '0' == $_GET['wpformsdb-ignore-notice'] ) {
213
214 update_option( 'wpformsdb_view_ignore_notice', 'true' );
215 }
216 }
217
218