Version Description
Download this release
Release Info
Developer | arshidkv12 |
Plugin | Contact Form 7 Database Addon – CFDB7 |
Version | 1.0.8 |
Comparing to | |
See all releases |
Version 1.0.8
- contact-form-cfdb-7.php +193 -0
- inc/admin-form-details.php +91 -0
- inc/admin-mainpage.php +182 -0
- inc/admin-subpage.php +435 -0
- inc/export-csv.php +111 -0
- readme.txt +39 -0
contact-form-cfdb-7.php
ADDED
@@ -0,0 +1,193 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin name: Contact Form CFDB7
|
4 |
+
Plugin URI: http://ciphercoin.com/
|
5 |
+
Description: Save and manage Contact Form 7 messages. Never lose important data. Contact Form CFDB7 plugin is an add-on for the Contact Form 7 plugin.
|
6 |
+
Author: Arshid
|
7 |
+
Author URI: http://ciphercoin.com/
|
8 |
+
Text Domain: contact-form-cfdb7
|
9 |
+
Version: 1.0.8
|
10 |
+
*/
|
11 |
+
|
12 |
+
|
13 |
+
register_activation_hook( __FILE__, 'cfdb7_pugin_activation' );
|
14 |
+
function cfdb7_pugin_activation(){
|
15 |
+
|
16 |
+
global $wpdb;
|
17 |
+
$table_name = $wpdb->prefix.'db7_forms';
|
18 |
+
|
19 |
+
if( $wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name ) {
|
20 |
+
|
21 |
+
$charset_collate = $wpdb->get_charset_collate();
|
22 |
+
|
23 |
+
$sql = "CREATE TABLE $table_name (
|
24 |
+
form_id bigint(20) NOT NULL AUTO_INCREMENT,
|
25 |
+
form_post_id bigint(20) NOT NULL,
|
26 |
+
form_value longtext NOT NULL,
|
27 |
+
form_date datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
|
28 |
+
PRIMARY KEY (form_id)
|
29 |
+
) $charset_collate;";
|
30 |
+
|
31 |
+
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
32 |
+
dbDelta( $sql );
|
33 |
+
}
|
34 |
+
|
35 |
+
$upload_dir = wp_upload_dir();
|
36 |
+
$cfdb7_dirname = $upload_dir['basedir'].'/cfdb7_uploads';
|
37 |
+
if ( ! file_exists( $cfdb7_dirname ) ) {
|
38 |
+
wp_mkdir_p( $cfdb7_dirname );
|
39 |
+
}
|
40 |
+
add_option( 'cfdb7_view_install_date', date('Y-m-d G:i:s'), '', 'yes');
|
41 |
+
|
42 |
+
}
|
43 |
+
|
44 |
+
function cfdb7_before_send_mail( $form_tag ) {
|
45 |
+
|
46 |
+
global $wpdb;
|
47 |
+
$table_name = $wpdb->prefix.'db7_forms';
|
48 |
+
$upload_dir = wp_upload_dir();
|
49 |
+
$cfdb7_dirname = $upload_dir['basedir'].'/cfdb7_uploads';
|
50 |
+
$time_now = time();
|
51 |
+
|
52 |
+
$form = WPCF7_Submission::get_instance();
|
53 |
+
|
54 |
+
if ( $form ) {
|
55 |
+
|
56 |
+
$black_list = array('_wpcf7', '_wpcf7_version', '_wpcf7_locale', '_wpcf7_unit_tag',
|
57 |
+
'_wpcf7_is_ajax_call','cfdb7_name');
|
58 |
+
|
59 |
+
$data = $form->get_posted_data();
|
60 |
+
$files = $form->uploaded_files();
|
61 |
+
$uploaded_files = array();
|
62 |
+
|
63 |
+
foreach ($files as $file_key => $file) {
|
64 |
+
array_push($uploaded_files, $file_key);
|
65 |
+
copy($file, $cfdb7_dirname.'/'.$time_now.'-'.basename($file));
|
66 |
+
}
|
67 |
+
|
68 |
+
$form_data = array();
|
69 |
+
|
70 |
+
$form_data['cfdb7_status'] = 'unread';
|
71 |
+
foreach ($data as $key => $d) {
|
72 |
+
if ( !in_array($key, $black_list ) && !in_array($key, $uploaded_files ) ) {
|
73 |
+
|
74 |
+
$tmpD = $d;
|
75 |
+
|
76 |
+
if ( ! is_array($d) ){
|
77 |
+
|
78 |
+
//$tmpD = stripslashes($d);
|
79 |
+
$bl = array('\"',"\'",'/','\\');
|
80 |
+
$wl = array('"',''','/', '\');
|
81 |
+
|
82 |
+
$tmpD = str_replace($bl, $wl, $tmpD );
|
83 |
+
}
|
84 |
+
|
85 |
+
$form_data[$key] = $tmpD;
|
86 |
+
}
|
87 |
+
if ( in_array($key, $uploaded_files ) ) {
|
88 |
+
$form_data[$key.'cfdb7_file'] = $time_now.'-'.$d;
|
89 |
+
}
|
90 |
+
}
|
91 |
+
|
92 |
+
/* cfdb7 before save data */
|
93 |
+
do_action( 'cfdb7_before_save_data', $form_data );
|
94 |
+
|
95 |
+
$form_post_id = $form_tag->id();
|
96 |
+
$form_value = serialize( $form_data );
|
97 |
+
$form_date = date('Y-m-d H:i:s');
|
98 |
+
|
99 |
+
$wpdb->insert( $table_name, array(
|
100 |
+
'form_post_id' => $form_post_id,
|
101 |
+
'form_value' => $form_value,
|
102 |
+
'form_date' => $form_date
|
103 |
+
) );
|
104 |
+
|
105 |
+
/* cfdb7 after save data */
|
106 |
+
$insert_id = $wpdb->insert_id;
|
107 |
+
do_action( 'cfdb7_after_save_data', $insert_id );
|
108 |
+
}
|
109 |
+
|
110 |
+
}
|
111 |
+
|
112 |
+
add_action( 'wpcf7_before_send_mail', 'cfdb7_before_send_mail' );
|
113 |
+
|
114 |
+
|
115 |
+
add_action( 'init', 'cfdb7_admin_settings');
|
116 |
+
|
117 |
+
function cfdb7_admin_settings(){
|
118 |
+
|
119 |
+
|
120 |
+
if( is_admin() ){
|
121 |
+
|
122 |
+
require_once 'inc/admin-mainpage.php';
|
123 |
+
require_once 'inc/admin-subpage.php';
|
124 |
+
require_once 'inc/admin-form-details.php';
|
125 |
+
require_once 'inc/export-csv.php';
|
126 |
+
|
127 |
+
$csv = new Expoert_CSV();
|
128 |
+
if( isset($_REQUEST['csv']) && ( $_REQUEST['csv'] == true ) && isset( $_REQUEST['nonce'] ) ) {
|
129 |
+
|
130 |
+
$nonce = filter_input( INPUT_GET, 'nonce', FILTER_SANITIZE_STRING );
|
131 |
+
|
132 |
+
if ( ! wp_verify_nonce( $nonce, 'dnonce' ) ) wp_die('Invalid nonce..!!');
|
133 |
+
|
134 |
+
$csv->download_csv_file();
|
135 |
+
}
|
136 |
+
new Cfdb7_Wp_Main_Page();
|
137 |
+
}
|
138 |
+
}
|
139 |
+
|
140 |
+
|
141 |
+
|
142 |
+
add_action( 'admin_notices', 'cfdb7_admin_notice' );
|
143 |
+
add_action('admin_init', 'cfdb7_view_ignore_notice' );
|
144 |
+
|
145 |
+
function cfdb7_admin_notice() {
|
146 |
+
|
147 |
+
$install_date = get_option( 'cfdb7_view_install_date', '');
|
148 |
+
$install_date = date_create( $install_date );
|
149 |
+
$date_now = date_create( date('Y-m-d G:i:s') );
|
150 |
+
$date_diff = date_diff( $install_date, $date_now );
|
151 |
+
|
152 |
+
if ( $date_diff->format("%d") < 7 ) {
|
153 |
+
|
154 |
+
return false;
|
155 |
+
}
|
156 |
+
|
157 |
+
global $current_user ;
|
158 |
+
$user_id = $current_user->ID;
|
159 |
+
|
160 |
+
if ( ! get_user_meta($user_id, 'cfdb7_view_ignore_notice' ) ) {
|
161 |
+
|
162 |
+
echo '<div class="updated"><p>';
|
163 |
+
|
164 |
+
printf(__('Awesome, you\'ve been using <a href="admin.php?page=cfdb7-list.php">Contact Form CFDB7</a> for more than 1 week. May we ask you to give it a 5-star rating on WordPress? | <a href="%2$s" target="_blank">Ok, you deserved it</a> | <a href="%1$s">I alredy did</a> | <a href="%1$s">No, not good enough</a>'), 'admin.php?page=cfdb7-list.php&cfdb7-ignore-notice=0','https://wordpress.org/plugins/contact-form-cfdb7/');
|
165 |
+
echo "</p></div>";
|
166 |
+
}
|
167 |
+
}
|
168 |
+
|
169 |
+
function cfdb7_view_ignore_notice() {
|
170 |
+
global $current_user;
|
171 |
+
$user_id = $current_user->ID;
|
172 |
+
|
173 |
+
if ( isset($_GET['cfdb7-ignore-notice']) && '0' == $_GET['cfdb7-ignore-notice'] ) {
|
174 |
+
|
175 |
+
add_user_meta($user_id, 'cfdb7_view_ignore_notice', 'true', true);
|
176 |
+
}
|
177 |
+
}
|
178 |
+
|
179 |
+
/**
|
180 |
+
* Plugin settings link
|
181 |
+
* @param array $links list of links
|
182 |
+
* @return array of links
|
183 |
+
*/
|
184 |
+
function cfdb7_settings_link( $links ) {
|
185 |
+
$forms_link = '<a href="admin.php?page=cfdb7-list.php">Contact Forms</a>';
|
186 |
+
array_unshift($links, $forms_link);
|
187 |
+
return $links;
|
188 |
+
}
|
189 |
+
|
190 |
+
$plugin = plugin_basename(__FILE__);
|
191 |
+
add_filter("plugin_action_links_$plugin", 'cfdb7_settings_link' );
|
192 |
+
|
193 |
+
|
inc/admin-form-details.php
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if (!defined( 'ABSPATH')) exit;
|
4 |
+
|
5 |
+
/**
|
6 |
+
*
|
7 |
+
*/
|
8 |
+
class CFdb7_Form_Details
|
9 |
+
{
|
10 |
+
private $form_id;
|
11 |
+
private $form_post_id;
|
12 |
+
|
13 |
+
|
14 |
+
public function __construct()
|
15 |
+
{
|
16 |
+
$this->form_post_id = esc_sql( $_GET['fid'] );
|
17 |
+
$this->form_id = esc_sql( $_GET['ufid'] );
|
18 |
+
|
19 |
+
$this->form_details_page();
|
20 |
+
}
|
21 |
+
|
22 |
+
public function form_details_page(){
|
23 |
+
global $wpdb;
|
24 |
+
$table_name = $wpdb->prefix.'db7_forms';
|
25 |
+
$upload_dir = wp_upload_dir();
|
26 |
+
$cfdb7_dir_url = $upload_dir['baseurl'].'/cfdb7_uploads';
|
27 |
+
|
28 |
+
if ( is_numeric($this->form_post_id) && is_numeric($this->form_id) ) {
|
29 |
+
|
30 |
+
$results = $wpdb->get_results( "SELECT * FROM $table_name WHERE form_post_id = $this->form_post_id AND form_id = $this->form_id LIMIT 1", OBJECT );
|
31 |
+
}
|
32 |
+
|
33 |
+
if ( empty($results) ) {
|
34 |
+
wp_die( $message = 'Not valid contact form' );
|
35 |
+
}
|
36 |
+
?>
|
37 |
+
<div class="wrap">
|
38 |
+
<div id="welcome-panel" class="welcome-panel">
|
39 |
+
<div class="welcome-panel-content">
|
40 |
+
<div class="welcome-panel-column-container">
|
41 |
+
<h3><?php echo get_the_title( $this->form_post_id ); ?></h3>
|
42 |
+
<p></span><?php echo $results[0]->form_date; ?></p>
|
43 |
+
<?php $form_data = unserialize( $results[0]->form_value );
|
44 |
+
|
45 |
+
foreach ($form_data as $key => $data):
|
46 |
+
|
47 |
+
if ( $key == 'cfdb7_status' ) continue;
|
48 |
+
|
49 |
+
if ( strpos($key, 'cfdb7_file') !== false ){
|
50 |
+
|
51 |
+
$key_val = str_replace('cfdb7_file', '', $key);
|
52 |
+
$key_val = str_replace('your-', '', $key_val);
|
53 |
+
$key_val = ucfirst( $key_val );
|
54 |
+
echo '<p><b>'.$key_val.'</b>: <a href="'.$cfdb7_dir_url.'/'.$data.'">'
|
55 |
+
.$data.'</a></p>';
|
56 |
+
}else{
|
57 |
+
|
58 |
+
|
59 |
+
if ( is_array($data) ) {
|
60 |
+
|
61 |
+
$key_val = str_replace('your-', '', $key);
|
62 |
+
$key_val = ucfirst( $key_val );
|
63 |
+
$arr_str_data = implode(', ',$data);
|
64 |
+
echo '<p><b>'.$key_val.'</b>: '. $arr_str_data .'</p>';
|
65 |
+
|
66 |
+
}else{
|
67 |
+
|
68 |
+
$key_val = str_replace('your-', '', $key);
|
69 |
+
$key_val = ucfirst( $key_val );
|
70 |
+
echo '<p><b>'.$key_val.'</b>: '.$data.'</p>';
|
71 |
+
}
|
72 |
+
}
|
73 |
+
|
74 |
+
endforeach;
|
75 |
+
|
76 |
+
$form_data['cfdb7_status'] = 'read';
|
77 |
+
$form_data = serialize( $form_data );
|
78 |
+
$form_id = $results[0]->form_id;
|
79 |
+
|
80 |
+
$wpdb->query( "UPDATE $table_name SET form_value =
|
81 |
+
'$form_data' WHERE form_id = $form_id"
|
82 |
+
);
|
83 |
+
?>
|
84 |
+
</div>
|
85 |
+
</div>
|
86 |
+
</div>
|
87 |
+
</div>
|
88 |
+
<?php
|
89 |
+
}
|
90 |
+
|
91 |
+
}
|
inc/admin-mainpage.php
ADDED
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* CFDB7 Admin section
|
4 |
+
*/
|
5 |
+
|
6 |
+
if (!defined( 'ABSPATH')) exit;
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Cfdb7_Wp_List_Table class will create the page to load the table
|
10 |
+
*/
|
11 |
+
class Cfdb7_Wp_Main_Page
|
12 |
+
{
|
13 |
+
/**
|
14 |
+
* Constructor will create the menu item
|
15 |
+
*/
|
16 |
+
public function __construct()
|
17 |
+
{
|
18 |
+
add_action( 'admin_menu', array($this, 'admin_list_table_page' ));
|
19 |
+
}
|
20 |
+
/**
|
21 |
+
* Menu item will allow us to load the page to display the table
|
22 |
+
*/
|
23 |
+
public function admin_list_table_page()
|
24 |
+
{
|
25 |
+
|
26 |
+
add_menu_page( 'Contact Forms', 'Contact Forms', 'manage_options', 'cfdb7-list.php', array($this, 'list_table_page'), 'dashicons-list-view' );
|
27 |
+
|
28 |
+
}
|
29 |
+
/**
|
30 |
+
* Display the list table page
|
31 |
+
*
|
32 |
+
* @return Void
|
33 |
+
*/
|
34 |
+
public function list_table_page()
|
35 |
+
{
|
36 |
+
if ( ! in_array( 'contact-form-7/wp-contact-form-7.php',
|
37 |
+
apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
|
38 |
+
|
39 |
+
wp_die( 'Please activate <a href="https://wordpress.org/plugins/contact-form-7/" target="_blank">contact form 7</a> plugin.' );
|
40 |
+
}
|
41 |
+
|
42 |
+
$fid = empty($_GET['fid']) ? 0 : (int) $_GET['fid'];
|
43 |
+
$ufid = empty($_GET['ufid']) ? 0 : (int) $_GET['ufid'];
|
44 |
+
|
45 |
+
if ( !empty($fid) && empty($_GET['ufid']) ) {
|
46 |
+
|
47 |
+
new Cfdb7_Wp_Sub_Page();
|
48 |
+
return;
|
49 |
+
}
|
50 |
+
|
51 |
+
if( !empty($ufid) && !empty($fid) ){
|
52 |
+
|
53 |
+
new CFdb7_Form_Details();
|
54 |
+
return;
|
55 |
+
}
|
56 |
+
|
57 |
+
$ListTable = new CFDB7_Main_List_Table();
|
58 |
+
$ListTable->prepare_items();
|
59 |
+
?>
|
60 |
+
<div class="wrap">
|
61 |
+
<div id="icon-users" class="icon32"></div>
|
62 |
+
<h2>Contact Forms List</h2>
|
63 |
+
<?php $ListTable->display(); ?>
|
64 |
+
</div>
|
65 |
+
<?php
|
66 |
+
}
|
67 |
+
}
|
68 |
+
// WP_List_Table is not loaded automatically so we need to load it in our application
|
69 |
+
if( ! class_exists( 'WP_List_Table' ) ) {
|
70 |
+
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
|
71 |
+
}
|
72 |
+
/**
|
73 |
+
* Create a new table class that will extend the WP_List_Table
|
74 |
+
*/
|
75 |
+
class CFDB7_Main_List_Table extends WP_List_Table
|
76 |
+
{
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Prepare the items for the table to process
|
80 |
+
*
|
81 |
+
* @return Void
|
82 |
+
*/
|
83 |
+
public function prepare_items()
|
84 |
+
{
|
85 |
+
|
86 |
+
global $wpdb;
|
87 |
+
|
88 |
+
$table_name = $wpdb->prefix.'db7_forms';
|
89 |
+
$columns = $this->get_columns();
|
90 |
+
$hidden = $this->get_hidden_columns();
|
91 |
+
$data = $this->table_data();
|
92 |
+
$perPage = 10;
|
93 |
+
$currentPage = $this->get_pagenum();
|
94 |
+
$count_forms = wp_count_posts('wpcf7_contact_form');
|
95 |
+
$totalItems = $count_forms->publish;
|
96 |
+
|
97 |
+
|
98 |
+
$this->set_pagination_args( array(
|
99 |
+
'total_items' => $totalItems,
|
100 |
+
'per_page' => $perPage
|
101 |
+
) );
|
102 |
+
|
103 |
+
$this->_column_headers = array($columns, $hidden );
|
104 |
+
$this->items = $data;
|
105 |
+
}
|
106 |
+
/**
|
107 |
+
* Override the parent columns method. Defines the columns to use in your listing table
|
108 |
+
*
|
109 |
+
* @return Array
|
110 |
+
*/
|
111 |
+
public function get_columns()
|
112 |
+
{
|
113 |
+
|
114 |
+
|
115 |
+
$columns = array(
|
116 |
+
'name' => 'Name',
|
117 |
+
'count'=> 'Count'
|
118 |
+
);
|
119 |
+
|
120 |
+
return $columns;
|
121 |
+
}
|
122 |
+
/**
|
123 |
+
* Define which columns are hidden
|
124 |
+
*
|
125 |
+
* @return Array
|
126 |
+
*/
|
127 |
+
public function get_hidden_columns()
|
128 |
+
{
|
129 |
+
return array();
|
130 |
+
}
|
131 |
+
|
132 |
+
/**
|
133 |
+
* Get the table data
|
134 |
+
*
|
135 |
+
* @return Array
|
136 |
+
*/
|
137 |
+
private function table_data()
|
138 |
+
{
|
139 |
+
global $wpdb;
|
140 |
+
|
141 |
+
$data = array();
|
142 |
+
$table_name = $wpdb->prefix.'db7_forms';
|
143 |
+
$page = $this->get_pagenum();
|
144 |
+
$page = $page - 1;
|
145 |
+
$start = $page * 10;
|
146 |
+
|
147 |
+
$args = array(
|
148 |
+
'post_type'=> 'wpcf7_contact_form',
|
149 |
+
'order' => 'ASC',
|
150 |
+
'posts_per_page' => 10,
|
151 |
+
'offset' => $start
|
152 |
+
);
|
153 |
+
|
154 |
+
$the_query = new WP_Query( $args );
|
155 |
+
|
156 |
+
while ( $the_query->have_posts() ) : $the_query->the_post();
|
157 |
+
$form_post_id = get_the_id();
|
158 |
+
$totalItems = $wpdb->get_var("SELECT COUNT(*) FROM $table_name WHERE form_post_id = $form_post_id");
|
159 |
+
$title = get_the_title();
|
160 |
+
$link = "<a class='row-title' href=admin.php?page=cfdb7-list.php&fid=$form_post_id>%s</a>";
|
161 |
+
$data_value['name'] = sprintf( $link, $title );
|
162 |
+
$data_value['count'] = sprintf( $link, $totalItems );
|
163 |
+
$data[] = $data_value;
|
164 |
+
endwhile;
|
165 |
+
|
166 |
+
return $data;
|
167 |
+
}
|
168 |
+
/**
|
169 |
+
* Define what data to show on each column of the table
|
170 |
+
*
|
171 |
+
* @param Array $item Data
|
172 |
+
* @param String $column_name - Current column name
|
173 |
+
*
|
174 |
+
* @return Mixed
|
175 |
+
*/
|
176 |
+
public function column_default( $item, $column_name )
|
177 |
+
{
|
178 |
+
return $item[ $column_name ];
|
179 |
+
|
180 |
+
}
|
181 |
+
|
182 |
+
}
|
inc/admin-subpage.php
ADDED
@@ -0,0 +1,435 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* CFDB7 Admin subpage
|
5 |
+
*/
|
6 |
+
|
7 |
+
if (!defined( 'ABSPATH')) exit;
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Cfdb7_Wp_List_Table class will create the page to load the table
|
11 |
+
*/
|
12 |
+
class Cfdb7_Wp_Sub_Page
|
13 |
+
{
|
14 |
+
private $form_post_id;
|
15 |
+
private $search;
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Constructor start subpage
|
19 |
+
*/
|
20 |
+
public function __construct()
|
21 |
+
{
|
22 |
+
$this->form_post_id = (int) $_GET['fid'];
|
23 |
+
$this->list_table_page();
|
24 |
+
|
25 |
+
}
|
26 |
+
/**
|
27 |
+
* Display the list table page
|
28 |
+
*
|
29 |
+
* @return Void
|
30 |
+
*/
|
31 |
+
public function list_table_page()
|
32 |
+
{
|
33 |
+
$ListTable = new CFDB7_List_Table();
|
34 |
+
$ListTable->prepare_items();
|
35 |
+
?>
|
36 |
+
<div class="wrap">
|
37 |
+
<div id="icon-users" class="icon32"></div>
|
38 |
+
<h2><?php echo get_the_title( $this->form_post_id ); ?></h2>
|
39 |
+
<form method="post" action="">
|
40 |
+
|
41 |
+
<?php $ListTable->search_box('Search', 'search'); ?>
|
42 |
+
<?php $ListTable->display(); ?>
|
43 |
+
</form>
|
44 |
+
</div>
|
45 |
+
<?php
|
46 |
+
}
|
47 |
+
|
48 |
+
}
|
49 |
+
// WP_List_Table is not loaded automatically so we need to load it in our application
|
50 |
+
if( ! class_exists( 'WP_List_Table' ) ) {
|
51 |
+
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
|
52 |
+
}
|
53 |
+
/**
|
54 |
+
* Create a new table class that will extend the WP_List_Table
|
55 |
+
*/
|
56 |
+
class CFDB7_List_Table extends WP_List_Table
|
57 |
+
{
|
58 |
+
private $form_post_id;
|
59 |
+
|
60 |
+
public function __construct() {
|
61 |
+
|
62 |
+
parent::__construct(
|
63 |
+
array(
|
64 |
+
'singular' => 'contact_form',
|
65 |
+
'plural' => 'contact_forms',
|
66 |
+
'ajax' => false
|
67 |
+
)
|
68 |
+
);
|
69 |
+
|
70 |
+
}
|
71 |
+
|
72 |
+
/**
|
73 |
+
* Prepare the items for the table to process
|
74 |
+
*
|
75 |
+
* @return Void
|
76 |
+
*/
|
77 |
+
public function prepare_items()
|
78 |
+
{
|
79 |
+
|
80 |
+
$this->form_post_id = (int) $_GET['fid'];
|
81 |
+
$search = empty( $_REQUEST['s'] ) ? false : esc_sql( $_POST['s'] );
|
82 |
+
echo $this->search;
|
83 |
+
$form_post_id = $this->form_post_id;
|
84 |
+
|
85 |
+
global $wpdb;
|
86 |
+
|
87 |
+
$this->process_bulk_action();
|
88 |
+
|
89 |
+
$table_name = $wpdb->prefix.'db7_forms';
|
90 |
+
$columns = $this->get_columns();
|
91 |
+
$hidden = $this->get_hidden_columns();
|
92 |
+
$sortable = $this->get_sortable_columns();
|
93 |
+
$data = $this->table_data();
|
94 |
+
|
95 |
+
usort( $data, array( &$this, 'sort_data' ) );
|
96 |
+
|
97 |
+
$perPage = 10;
|
98 |
+
$currentPage = $this->get_pagenum();
|
99 |
+
if ( ! empty($search) ) {
|
100 |
+
|
101 |
+
$totalItems = $wpdb->get_var("SELECT COUNT(*) FROM $table_name WHERE form_value LIKE '%$search%'");
|
102 |
+
}else{
|
103 |
+
|
104 |
+
$totalItems = $wpdb->get_var("SELECT COUNT(*) FROM $table_name WHERE form_post_id = '$form_post_id'");
|
105 |
+
}
|
106 |
+
|
107 |
+
$this->set_pagination_args( array(
|
108 |
+
'total_items' => $totalItems,
|
109 |
+
'per_page' => $perPage
|
110 |
+
) );
|
111 |
+
$this->_column_headers = array($columns, $hidden ,$sortable);
|
112 |
+
$this->items = $data;
|
113 |
+
}
|
114 |
+
/**
|
115 |
+
* Override the parent columns method. Defines the columns to use in your listing table
|
116 |
+
*
|
117 |
+
* @return Array
|
118 |
+
*/
|
119 |
+
public function get_columns()
|
120 |
+
{
|
121 |
+
$form_post_id = $this->form_post_id;
|
122 |
+
|
123 |
+
global $wpdb;
|
124 |
+
$table_name = $wpdb->prefix.'db7_forms';
|
125 |
+
|
126 |
+
$results = $wpdb->get_results( "SELECT * FROM $table_name WHERE form_post_id = $form_post_id LIMIT 1", OBJECT );
|
127 |
+
|
128 |
+
$first_row = isset($results[0]) ? unserialize( $results[0]->form_value ): 0 ;
|
129 |
+
$columns = array();
|
130 |
+
|
131 |
+
if( !empty($first_row) ){
|
132 |
+
$columns['form_id'] = $results[0]->form_id;
|
133 |
+
$columns['cb'] = '<input type="checkbox" />';
|
134 |
+
foreach ($first_row as $key => $value) {
|
135 |
+
|
136 |
+
if ( ( $key == 'cfdb7_status' ) || $key == 'cfdb7_file' ) continue;
|
137 |
+
|
138 |
+
$key_val = str_replace('your-', '', $key);
|
139 |
+
$columns[$key] = ucfirst( $key_val );
|
140 |
+
|
141 |
+
if ( sizeof($columns) > 4) break;
|
142 |
+
}
|
143 |
+
$columns['form-date'] = 'Date';
|
144 |
+
}
|
145 |
+
|
146 |
+
|
147 |
+
return $columns;
|
148 |
+
}
|
149 |
+
/**
|
150 |
+
* Define check box for bulk action (each row)
|
151 |
+
* @param $item
|
152 |
+
* @return checkbox
|
153 |
+
*/
|
154 |
+
public function column_cb($item){
|
155 |
+
return sprintf(
|
156 |
+
'<input type="checkbox" name="%1$s[]" value="%2$s" />',
|
157 |
+
$this->_args['singular'],
|
158 |
+
$item['form_id']
|
159 |
+
);
|
160 |
+
}
|
161 |
+
/**
|
162 |
+
* Define which columns are hidden
|
163 |
+
*
|
164 |
+
* @return Array
|
165 |
+
*/
|
166 |
+
public function get_hidden_columns()
|
167 |
+
{
|
168 |
+
return array('form_id');
|
169 |
+
}
|
170 |
+
/**
|
171 |
+
* Define the sortable columns
|
172 |
+
*
|
173 |
+
* @return Array
|
174 |
+
*/
|
175 |
+
public function get_sortable_columns()
|
176 |
+
{
|
177 |
+
return array('form-date' => array('form-date', false));
|
178 |
+
}
|
179 |
+
/**
|
180 |
+
* Define bulk action
|
181 |
+
* @return Array
|
182 |
+
*/
|
183 |
+
public function get_bulk_actions() {
|
184 |
+
|
185 |
+
return array(
|
186 |
+
'read' => 'Read',
|
187 |
+
'unread' => 'Unread',
|
188 |
+
'delete' => 'Delete'
|
189 |
+
);
|
190 |
+
|
191 |
+
}
|
192 |
+
/**
|
193 |
+
* Get the table data
|
194 |
+
*
|
195 |
+
* @return Array
|
196 |
+
*/
|
197 |
+
private function table_data()
|
198 |
+
{
|
199 |
+
$data = array();
|
200 |
+
global $wpdb;
|
201 |
+
$search = empty( $_REQUEST['s'] ) ? false : esc_sql( $_POST['s'] );
|
202 |
+
$table_name = $wpdb->prefix.'db7_forms';
|
203 |
+
$page = $this->get_pagenum();
|
204 |
+
$page = $page - 1;
|
205 |
+
$start = $page * 10;
|
206 |
+
$form_post_id = $this->form_post_id;
|
207 |
+
|
208 |
+
if ( ! empty($search) ) {
|
209 |
+
|
210 |
+
$results = $wpdb->get_results( "SELECT * FROM $table_name WHERE form_value LIKE '%$search%' LIMIT $start,10", OBJECT );
|
211 |
+
}else{
|
212 |
+
|
213 |
+
$results = $wpdb->get_results( "SELECT * FROM $table_name WHERE form_post_id = $form_post_id LIMIT $start,10", OBJECT );
|
214 |
+
}
|
215 |
+
|
216 |
+
foreach ( $results as $result ) {
|
217 |
+
|
218 |
+
$form_value = unserialize( $result->form_value );
|
219 |
+
|
220 |
+
$link = "<b><a href=admin.php?page=cfdb7-list.php&fid=%s&ufid=%s>%s</a></b>";
|
221 |
+
if(isset($form_value['cfdb7_status']) && ( $form_value['cfdb7_status'] === 'read' ) )
|
222 |
+
$link = "<a href=admin.php?page=cfdb7-list.php&fid=%s&ufid=%s>%s</a>";
|
223 |
+
|
224 |
+
|
225 |
+
|
226 |
+
$fid = $result->form_post_id;
|
227 |
+
$form_values['form_id'] = $result->form_id;
|
228 |
+
|
229 |
+
foreach ($form_value as $k => $value) {
|
230 |
+
|
231 |
+
$ktmp = str_replace('cfdb7_file', '', $k);
|
232 |
+
|
233 |
+
$can_foreach = is_array($value) || is_object($value);
|
234 |
+
|
235 |
+
if ( $can_foreach ) {
|
236 |
+
|
237 |
+
foreach ($value as $k_val => $val):
|
238 |
+
|
239 |
+
$form_values[$ktmp] = ( strlen($val) > 150 ) ? substr($val, 0, 150).'...': $val;
|
240 |
+
$form_values[$ktmp] = sprintf($link, $fid, $result->form_id, $form_values[$ktmp]);
|
241 |
+
|
242 |
+
endforeach;
|
243 |
+
}else{
|
244 |
+
$form_values[$ktmp] = ( strlen($value) > 150 ) ? substr($value, 0, 150).'...': $value;
|
245 |
+
$form_values[$ktmp] = sprintf($link, $fid, $result->form_id, $form_values[$ktmp]);
|
246 |
+
}
|
247 |
+
|
248 |
+
}
|
249 |
+
$form_values['form-date'] = sprintf($link, $fid, $result->form_id, $result->form_date );
|
250 |
+
$data[] = $form_values;
|
251 |
+
}
|
252 |
+
|
253 |
+
return $data;
|
254 |
+
}
|
255 |
+
/**
|
256 |
+
* Define bulk action
|
257 |
+
*
|
258 |
+
*/
|
259 |
+
public function process_bulk_action(){
|
260 |
+
|
261 |
+
global $wpdb;
|
262 |
+
$table_name = $wpdb->prefix.'db7_forms';
|
263 |
+
$action = $this->current_action();
|
264 |
+
|
265 |
+
if ( isset( $_POST['_wpnonce'] ) && ! empty( $_POST['_wpnonce'] ) ) {
|
266 |
+
|
267 |
+
$nonce = filter_input( INPUT_POST, '_wpnonce', FILTER_SANITIZE_STRING );
|
268 |
+
$nonce_action = 'bulk-' . $this->_args['plural'];
|
269 |
+
|
270 |
+
if ( !wp_verify_nonce( $nonce, $nonce_action ) ){
|
271 |
+
|
272 |
+
wp_die( 'Not valid..!!' );
|
273 |
+
}
|
274 |
+
}
|
275 |
+
|
276 |
+
if( 'delete' === $action ) {
|
277 |
+
|
278 |
+
$form_ids = esc_sql( $_POST['contact_form'] );
|
279 |
+
|
280 |
+
foreach ($form_ids as $form_id):
|
281 |
+
|
282 |
+
$results = $wpdb->get_results( "SELECT * FROM $table_name WHERE form_id = $form_id LIMIT 1", OBJECT );
|
283 |
+
$result_value = $results[0]->form_value;
|
284 |
+
$result_values = unserialize($result_value);
|
285 |
+
$upload_dir = wp_upload_dir();
|
286 |
+
$cfdb7_dirname = $upload_dir['basedir'].'/cfdb7_uploads';
|
287 |
+
|
288 |
+
foreach ($result_values as $key => $result) {
|
289 |
+
|
290 |
+
if ( ( strpos($key, 'cfdb7_file') !== false ) &&
|
291 |
+
file_exists($cfdb7_dirname.'/'.$result) ) {
|
292 |
+
|
293 |
+
unlink($cfdb7_dirname.'/'.$result);
|
294 |
+
}
|
295 |
+
|
296 |
+
}
|
297 |
+
|
298 |
+
$wpdb->delete(
|
299 |
+
$table_name ,
|
300 |
+
array( 'form_id' => $form_id ),
|
301 |
+
array( '%d' )
|
302 |
+
);
|
303 |
+
endforeach;
|
304 |
+
|
305 |
+
}else if( 'read' === $action ){
|
306 |
+
|
307 |
+
$form_ids = esc_sql( $_POST['contact_form'] );
|
308 |
+
foreach ($form_ids as $form_id):
|
309 |
+
|
310 |
+
$results = $wpdb->get_results( "SELECT * FROM $table_name WHERE form_id = '$form_id' LIMIT 1", OBJECT );
|
311 |
+
$result_value = $results[0]->form_value;
|
312 |
+
$result_values = unserialize( $result_value );
|
313 |
+
$result_values['cfdb7_status'] = 'read';
|
314 |
+
$form_data = serialize( $result_values );
|
315 |
+
$wpdb->query(
|
316 |
+
"UPDATE $table_name SET form_value = '$form_data' WHERE form_id = '$form_id'"
|
317 |
+
);
|
318 |
+
|
319 |
+
endforeach;
|
320 |
+
|
321 |
+
}else if( 'unread' === $action ){
|
322 |
+
|
323 |
+
$form_ids = esc_sql( $_POST['contact_form'] );
|
324 |
+
foreach ($form_ids as $form_id):
|
325 |
+
|
326 |
+
$results = $wpdb->get_results( "SELECT * FROM $table_name WHERE form_id = '$form_id' LIMIT 1", OBJECT );
|
327 |
+
$result_value = $results[0]->form_value;
|
328 |
+
$result_values = unserialize( $result_value );
|
329 |
+
$result_values['cfdb7_status'] = 'unread';
|
330 |
+
$form_data = serialize( $result_values );
|
331 |
+
$wpdb->query(
|
332 |
+
"UPDATE $table_name SET form_value = '$form_data' WHERE form_id = '$form_id'"
|
333 |
+
);
|
334 |
+
endforeach;
|
335 |
+
}else{
|
336 |
+
|
337 |
+
}
|
338 |
+
|
339 |
+
|
340 |
+
|
341 |
+
|
342 |
+
}
|
343 |
+
/**
|
344 |
+
* Define what data to show on each column of the table
|
345 |
+
*
|
346 |
+
* @param Array $item Data
|
347 |
+
* @param String $column_name - Current column name
|
348 |
+
*
|
349 |
+
* @return Mixed
|
350 |
+
*/
|
351 |
+
public function column_default( $item, $column_name )
|
352 |
+
{
|
353 |
+
return $item[ $column_name ];
|
354 |
+
|
355 |
+
}
|
356 |
+
/**
|
357 |
+
* Allows you to sort the data by the variables set in the $_GET
|
358 |
+
*
|
359 |
+
* @return Mixed
|
360 |
+
*/
|
361 |
+
private function sort_data( $a, $b )
|
362 |
+
{
|
363 |
+
// Set defaults
|
364 |
+
$orderby = 'form-date';
|
365 |
+
$order = 'asc';
|
366 |
+
// If orderby is set, use this as the sort column
|
367 |
+
if(!empty($_GET['orderby']))
|
368 |
+
{
|
369 |
+
$orderby = $_GET['orderby'];
|
370 |
+
}
|
371 |
+
// If order is set use this as the order
|
372 |
+
if(!empty($_GET['order']))
|
373 |
+
{
|
374 |
+
$order = $_GET['order'];
|
375 |
+
}
|
376 |
+
$result = strcmp( $a[$orderby], $b[$orderby] );
|
377 |
+
if($order === 'asc')
|
378 |
+
{
|
379 |
+
return $result;
|
380 |
+
}
|
381 |
+
return -$result;
|
382 |
+
}
|
383 |
+
/**
|
384 |
+
* Display the bulk actions dropdown.
|
385 |
+
*
|
386 |
+
* @since 3.1.0
|
387 |
+
* @access protected
|
388 |
+
*
|
389 |
+
* @param string $which The location of the bulk actions: 'top' or 'bottom'.
|
390 |
+
* This is designated as optional for backward compatibility.
|
391 |
+
*/
|
392 |
+
protected function bulk_actions( $which = '' ) {
|
393 |
+
if ( is_null( $this->_actions ) ) {
|
394 |
+
$this->_actions = $this->get_bulk_actions();
|
395 |
+
/**
|
396 |
+
* Filters the list table Bulk Actions drop-down.
|
397 |
+
*
|
398 |
+
* The dynamic portion of the hook name, `$this->screen->id`, refers
|
399 |
+
* to the ID of the current screen, usually a string.
|
400 |
+
*
|
401 |
+
* This filter can currently only be used to remove bulk actions.
|
402 |
+
*
|
403 |
+
* @since 3.5.0
|
404 |
+
*
|
405 |
+
* @param array $actions An array of the available bulk actions.
|
406 |
+
*/
|
407 |
+
$this->_actions = apply_filters( "bulk_actions-{$this->screen->id}", $this->_actions );
|
408 |
+
$two = '';
|
409 |
+
} else {
|
410 |
+
$two = '2';
|
411 |
+
}
|
412 |
+
|
413 |
+
if ( empty( $this->_actions ) )
|
414 |
+
return;
|
415 |
+
|
416 |
+
echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>';
|
417 |
+
echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">\n";
|
418 |
+
echo '<option value="-1">' . __( 'Bulk Actions' ) . "</option>\n";
|
419 |
+
|
420 |
+
foreach ( $this->_actions as $name => $title ) {
|
421 |
+
$class = 'edit' === $name ? ' class="hide-if-no-js"' : '';
|
422 |
+
|
423 |
+
echo "\t" . '<option value="' . $name . '"' . $class . '>' . $title . "</option>\n";
|
424 |
+
}
|
425 |
+
|
426 |
+
echo "</select>\n";
|
427 |
+
|
428 |
+
submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) );
|
429 |
+
echo "\n";
|
430 |
+
$nonce = wp_create_nonce( 'dnonce' );
|
431 |
+
echo "<a href='".$_SERVER['REQUEST_URI']."&csv=true&nonce=".$nonce."' style='float:right; margin:0;' class='button'>";
|
432 |
+
echo 'Export CSV';
|
433 |
+
echo '</a>';
|
434 |
+
}
|
435 |
+
}
|
inc/export-csv.php
ADDED
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* CFDB7 csv
|
4 |
+
*/
|
5 |
+
|
6 |
+
if (!defined( 'ABSPATH')) exit;
|
7 |
+
|
8 |
+
class Expoert_CSV{
|
9 |
+
|
10 |
+
/**
|
11 |
+
* Download csv file
|
12 |
+
* @param String $filename
|
13 |
+
* @return file
|
14 |
+
*/
|
15 |
+
public function download_send_headers( $filename ) {
|
16 |
+
// disable caching
|
17 |
+
$now = gmdate("D, d M Y H:i:s");
|
18 |
+
header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
|
19 |
+
header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate");
|
20 |
+
header("Last-Modified: {$now} GMT");
|
21 |
+
|
22 |
+
// force download
|
23 |
+
header("Content-Type: application/force-download");
|
24 |
+
header("Content-Type: application/octet-stream");
|
25 |
+
header("Content-Type: application/download");
|
26 |
+
|
27 |
+
// disposition / encoding on response body
|
28 |
+
header("Content-Disposition: attachment;filename={$filename}");
|
29 |
+
header("Content-Transfer-Encoding: binary");
|
30 |
+
|
31 |
+
}
|
32 |
+
/**
|
33 |
+
* Convert array to csv format
|
34 |
+
* @param array &$array
|
35 |
+
* @return file csv format
|
36 |
+
*/
|
37 |
+
public function array2csv(array &$array){
|
38 |
+
|
39 |
+
if (count($array) == 0) {
|
40 |
+
return null;
|
41 |
+
}
|
42 |
+
ob_start();
|
43 |
+
$df = fopen("php://output", 'w');
|
44 |
+
$array_keys = array_keys(reset($array));
|
45 |
+
$heading = array();
|
46 |
+
$unwanted = array('cfdb7_', 'your-');
|
47 |
+
foreach ($array_keys as $aKeys) {
|
48 |
+
$tmp = str_replace($unwanted, '', $aKeys);
|
49 |
+
$heading[] = ucfirst($tmp);
|
50 |
+
}
|
51 |
+
fputcsv($df, $heading);
|
52 |
+
|
53 |
+
foreach ($array as $row) {
|
54 |
+
fputcsv($df, $row);
|
55 |
+
}
|
56 |
+
fclose($df);
|
57 |
+
return ob_get_clean();
|
58 |
+
}
|
59 |
+
/**
|
60 |
+
* Download file
|
61 |
+
* @return csv file
|
62 |
+
*/
|
63 |
+
public function download_csv_file(){
|
64 |
+
|
65 |
+
global $wpdb;
|
66 |
+
$table_name = $wpdb->prefix.'db7_forms';
|
67 |
+
|
68 |
+
if( isset($_REQUEST['csv']) && isset( $_REQUEST['nonce'] ) ){
|
69 |
+
|
70 |
+
$nonce = $_REQUEST['nonce'];
|
71 |
+
if ( ! wp_verify_nonce( $nonce, 'dnonce')) {
|
72 |
+
|
73 |
+
wp_die( 'Not Valid.. Download nonce..!! ' );
|
74 |
+
}
|
75 |
+
$fid = (int)$_REQUEST['fid'];
|
76 |
+
$results = $wpdb->get_results("SELECT form_id, form_value, form_date FROM $table_name
|
77 |
+
WHERE form_post_id = '$fid' ",OBJECT);
|
78 |
+
$data = array();
|
79 |
+
$i = 0;
|
80 |
+
foreach ($results as $result) :
|
81 |
+
$i++;
|
82 |
+
$data[$i]['form_id'] = $result->form_id;
|
83 |
+
$data[$i]['form_date'] = $result->form_date;
|
84 |
+
$resultTmp = unserialize( $result->form_value );
|
85 |
+
$upload_dir = wp_upload_dir();
|
86 |
+
$cfdb7_dir_url = $upload_dir['baseurl'].'/cfdb7_uploads';
|
87 |
+
foreach ($resultTmp as $key => $value):
|
88 |
+
|
89 |
+
if (strpos($key, 'cfdb7_file') !== false ){
|
90 |
+
$data[$i][$key] = $cfdb7_dir_url.'/'.$value;
|
91 |
+
continue;
|
92 |
+
}
|
93 |
+
if ( is_array($value) ){
|
94 |
+
|
95 |
+
$data[$i][$key] = implode(', ', $value);
|
96 |
+
continue;
|
97 |
+
}
|
98 |
+
|
99 |
+
$data[$i][$key] = str_replace( array('"',''','/','\')
|
100 |
+
, array('"',"'",'/','\\'), $value );
|
101 |
+
|
102 |
+
endforeach;
|
103 |
+
|
104 |
+
endforeach;
|
105 |
+
|
106 |
+
$this->download_send_headers( "cfdb7-" . date("Y-m-d") . ".csv" );
|
107 |
+
echo $this->array2csv( $data );
|
108 |
+
die();
|
109 |
+
}
|
110 |
+
}
|
111 |
+
}
|
readme.txt
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Contact Form 7 Database Addon - CFDB7 ===
|
2 |
+
Contributors: arshidkv12
|
3 |
+
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=H5F3Z6S3MNTXA&lc=IN&item_name=wp%2dlogin%2dlimit&amount=5%2e00¤cy_code=USD&button_subtype=services&bn=PP%2dBuyNowBF%3abtn_buynowCC_LG%2egif%3aNonHosted
|
4 |
+
Tags: cf7, contact form 7, contact form 7 db, contact form db, contact form seven, contact form storage, export contact form, save contact form, wpcf7
|
5 |
+
Requires at least: 3.5
|
6 |
+
Tested up to: 4.7.3
|
7 |
+
Stable tag: 1.0.8
|
8 |
+
License: GPLv2
|
9 |
+
|
10 |
+
Save and manage Contact Form 7 messages. Never lose important data. It is lightweight contact form 7 db plugin.
|
11 |
+
|
12 |
+
|
13 |
+
== Description ==
|
14 |
+
|
15 |
+
The "CFDB7" plugin saves contact form 7 submissions to your WordPress database. Export the data to a csv file.
|
16 |
+
By simply installing the plugin, it will automatically begin to capture form submissions from contact form 7.
|
17 |
+
|
18 |
+
= Features of CFDB 7 =
|
19 |
+
|
20 |
+
* No configuration is needed
|
21 |
+
* Single database table for all forms
|
22 |
+
* Easy to use ang lightweight plugin
|
23 |
+
* Developer friendly & easy to customize
|
24 |
+
* No configuration is needed
|
25 |
+
|
26 |
+
Support : [http://www.ciphercoin.com/contact/](http://www.ciphercoin.com/contact/)
|
27 |
+
|
28 |
+
== Installation ==
|
29 |
+
|
30 |
+
1. Download and extract plugin files to a wp-content/plugin directory.
|
31 |
+
2. Activate the plugin through the WordPress admin interface.
|
32 |
+
3. Done !
|
33 |
+
|
34 |
+
|
35 |
+
== Screenshots ==
|
36 |
+
1. Admin
|
37 |
+
|
38 |
+
|
39 |
+
|