PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.0.0-beta.3
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.0.0-beta.3
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
← All changes | includes/admin/class-admin.php +226 -434 1.6.81.0.0-beta.3 View file →
@@ -1,434 +1,226 @@
1 -<?php
2 -
3 -/**
4 - * The admin page handler class
5 - */
6 -class WeForms_Admin {
7 -
8 - public function __construct() {
9 - add_action( 'init', [ $this, 'register_post_type' ] );
10 - add_action( 'admin_menu', [ $this, 'register_admin_menu' ] );
11 - add_action( 'pre_update_option_wpuf_general', [ $this, 'watch_wpuf_settings' ] );
12 -
13 - add_action( 'admin_notices', array( $this, 'wpuf_premium_cta' ) );
14 -
15 - add_filter( 'admin_footer_text', [ $this, 'admin_footer_text' ] );
16 - add_filter( 'admin_post_weforms_export_forms', [ $this, 'export_forms' ] );
17 - add_filter( 'admin_post_weforms_export_form_entries', [ $this, 'export_form_entries' ] );
18 -
19 - // load default settings tabs
20 - add_filter( 'weforms_settings_tabs', [ $this, 'set_default_settings' ], 5 );
21 - add_action( 'weforms_settings_tab_content_general', [ $this, 'settings_tab_general' ] );
22 - add_action( 'weforms_settings_tab_content_recaptcha', [ $this, 'settings_tab_recaptcha' ] );
23 - add_action( 'weforms_settings_tab_content_secure-database', [ $this, 'settings_tab_secure_database' ] );
24 - add_action( 'weforms_settings_tab_content_humanpresence', [ $this, 'settings_tab_humanpresence' ] );
25 - add_action( 'weforms_settings_tab_content_privacy', [ $this, 'settings_tab_privacy' ] );
26 - }
27 -
28 - /**
29 - * Register form post types
30 - *
31 - * @return void
32 - */
33 - public function register_post_type() {
34 - $capability = weforms_form_access_capability();
35 -
36 - register_post_type( 'wpuf_contact_form', [
37 - 'label' => __( 'Contact Forms', 'weforms' ),
38 - 'public' => false,
39 - 'show_ui' => true,
40 - 'show_in_menu' => false,
41 - 'capability_type' => 'post',
42 - 'hierarchical' => false,
43 - 'query_var' => false,
44 - 'supports' => ['title'],
45 - 'capabilities' => [
46 - 'publish_posts' => $capability,
47 - 'edit_posts' => $capability,
48 - 'edit_others_posts' => $capability,
49 - 'delete_posts' => $capability,
50 - 'delete_others_posts' => $capability,
51 - 'read_private_posts' => $capability,
52 - 'edit_post' => $capability,
53 - 'delete_post' => $capability,
54 - 'read_post' => $capability,
55 - ],
56 - 'labels' => [
57 - 'name' => __( 'Forms', 'weforms' ),
58 - 'singular_name' => __( 'Form', 'weforms' ),
59 - 'menu_name' => __( 'Contact Forms', 'weforms' ),
60 - 'add_new' => __( 'Add Form', 'weforms' ),
61 - 'add_new_item' => __( 'Add New Form', 'weforms' ),
62 - 'edit' => __( 'Edit', 'weforms' ),
63 - 'edit_item' => __( 'Edit Form', 'weforms' ),
64 - 'new_item' => __( 'New Form', 'weforms' ),
65 - 'view' => __( 'View Form', 'weforms' ),
66 - 'view_item' => __( 'View Form', 'weforms' ),
67 - 'search_items' => __( 'Search Form', 'weforms' ),
68 - 'not_found' => __( 'No Form Found', 'weforms' ),
69 - 'not_found_in_trash' => __( 'No Form Found in Trash', 'weforms' ),
70 - 'parent' => __( 'Parent Form', 'weforms' ),
71 - ],
72 - ] );
73 - }
74 -
75 - /**
76 - * Register the admin menu
77 - *
78 - * @return void
79 - */
80 - public function register_admin_menu() {
81 - global $submenu;
82 -
83 - $capability = weforms_form_access_capability();
84 -
85 - $hook = add_menu_page( __( 'weForms - The Best Contact Form', 'weforms' ), 'weForms', $capability, 'weforms', [ $this, 'contact_form_page'], 'data:image/svg+xml;base64,' . base64_encode( '<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 300 300" style="enable-background:new 0 0 300 300;" xml:space="preserve"><g fill="#9ea3a8"><path d="M285.1,24.1C273.1,9.4,254.8,0,234.3,0H65.7C46.6,0,29.3,8.2,17.3,21.2C6.6,32.9,0,48.5,0,65.7v60.5v108.1 C0,270.6,29.4,300,65.7,300h140h28.6c15.3,0,29.5-5.3,40.7-14.1c15.2-12,25-30.7,25-51.6V65.7C300,49.9,294.4,35.4,285.1,24.1z M212.7,187L104.6,233c-11.1,4.8-24-0.3-28.7-11.4c-4.8-11.1,0.3-24,11.4-28.7l108.1-46.1c11.1-4.8,24,0.3,28.7,11.4 C228.9,169.3,223.8,182.2,212.7,187z M217.4,107.1L99.9,157.8c-11.1,4.8-24-0.3-28.7-11.4c-4.8-11.1,0.3-24,11.4-28.7L200.1,67 c11.1-4.8,24,0.3,28.7,11.4v0C233.6,89.5,228.5,102.3,217.4,107.1z"/></g></svg>' ), 56 );
86 -
87 - if ( current_user_can( $capability ) ) {
88 - $submenu['weforms'][] = [ __( 'All Forms', 'weforms' ), $capability, 'admin.php?page=weforms#/' ];
89 - $submenu['weforms'][] = [ __( 'Entries', 'weforms' ), $capability, 'admin.php?page=weforms#/entries' ];
90 - $submenu['weforms'][] = [ __( 'Tools', 'weforms' ), $capability, 'admin.php?page=weforms#/tools' ];
91 -
92 - if ( class_exists( 'WeForms_Pro' ) ) {
93 - if ( current_user_can( 'manage_options' ) ) {
94 - $submenu['weforms'][] = [ __( 'Modules', 'weforms' ), $capability, 'admin.php?page=weforms#/modules' ];
95 - }
96 - } else {
97 - $submenu['weforms'][] = [ __( 'Premium', 'weforms' ), $capability, 'admin.php?page=weforms#/premium' ];
98 - }
99 -
100 - do_action( 'weforms-admin-menu', $hook, $capability );
101 -
102 - $submenu['weforms'][] = [ __( '<span style="color:#f18500">Help</span>', 'weforms' ), $capability, 'admin.php?page=weforms#/help' ];
103 - $submenu['weforms'][] = [ __( 'Privacy', 'weforms' ), $capability, 'admin.php?page=weforms#/privacy' ];
104 - }
105 -
106 - // only admins should see the settings page
107 - if ( current_user_can( 'manage_options' ) ) {
108 - $submenu['weforms'][] = [ __( 'Settings', 'weforms' ), 'manage_options', 'admin.php?page=weforms#/settings' ];
109 - }
110 -
111 - add_action( 'load-' . $hook, [ $this, 'load_assets' ] );
112 - }
113 -
114 - /**
115 - * Load the asset libraries
116 - *
117 - * @return void
118 - */
119 - public function load_assets() {
120 - require_once __DIR__ . '/class-form-builder-assets.php';
121 - new WeForms_Form_Builder_Assets();
122 - }
123 -
124 - /**
125 - * The contact form page handler
126 - *
127 - * @return void
128 - */
129 - public function contact_form_page() {
130 - require_once __DIR__ . '/views/vue-index.php';
131 - }
132 -
133 - /**
134 - * Export forms to JSON
135 - *
136 - * @return void
137 - */
138 - public function export_forms() {
139 - check_admin_referer( 'weforms-export-forms' );
140 -
141 - if ( !isset( $_REQUEST['weforms_export_forms'] ) ) {
142 - return;
143 - }
144 -
145 - $export_type = isset( $_POST['export_type'] ) ? sanitize_text_field( wp_unslash( $_POST['export_type'] ) ) : 'all';
146 - $selected = isset( $_POST['selected_forms'] ) ? array_map( 'absint', $_POST['selected_forms'] ) : array();
147 -
148 - if ( !class_exists( 'WeForms_Admin_Tools' ) ) {
149 - require_once __DIR__ . '/class-admin-tools.php';
150 - }
151 -
152 - switch ( $export_type ) {
153 - case 'all':
154 - WeForms_Admin_Tools::export_to_json();
155 -
156 - return;
157 -
158 - case 'selected':
159 - WeForms_Admin_Tools::export_to_json( $selected );
160 -
161 - return;
162 - }
163 -
164 - exit;
165 - }
166 -
167 - /**
168 - * Export form entries to CSV
169 - *
170 - * @return void
171 - */
172 - public function export_form_entries() {
173 - $form_id = isset( $_REQUEST['selected_forms'] ) ? absint( $_REQUEST['selected_forms'] ) : 0;
174 -
175 - if ( !$form_id ) {
176 - return;
177 - }
178 -
179 - $entry_array = [];
180 - $columns = weforms_get_entry_columns( $form_id, false );
181 - $total_entries = weforms_count_form_entries( $form_id );
182 - $entries = weforms_get_form_entries( $form_id, [
183 - 'number' => $total_entries,
184 - 'offset' => 0,
185 - ] );
186 - $extra_columns = [
187 - 'ip_address' => __( 'IP Address', 'weforms' ),
188 - 'created_at' => __( 'Date', 'weforms' ),
189 - ];
190 -
191 - $columns = array_merge( [ 'id' => 'Entry ID' ], $columns, $extra_columns );
192 -
193 - foreach ( $entries as $entry ) {
194 - $temp = [];
195 -
196 - foreach ( $columns as $column_id => $label ) {
197 - switch ( $column_id ) {
198 - case 'id':
199 - $temp[ $column_id ] = $entry->id;
200 - break;
201 -
202 - case 'ip_address':
203 - $temp[ $column_id ] = $entry->ip_address;
204 - break;
205 -
206 - case 'created_at':
207 - $temp[ $column_id ] = $entry->created_at;
208 - break;
209 -
210 - default:
211 -
212 - $value = weforms_get_entry_meta( $entry->id, $column_id, true );
213 - $value = weforms_get_pain_text( $value );
214 - $temp[ $column_id ] = str_replace( WeForms::$field_separator, ' ', $value );
215 -
216 - break;
217 - }
218 - }
219 -
220 - $entry_array[] = $temp;
221 - }
222 -
223 - error_reporting( 0 );
224 -
225 - if ( ob_get_contents() ) {
226 - ob_clean();
227 - }
228 -
229 - $blogname = sanitize_title( strtolower( str_replace( ' ', '-', get_option( 'blogname' ) ) ) );
230 - $file_name = $blogname . '-weforms-entries-' . time() . '.csv';
231 -
232 - // force download
233 - header( 'Content-Type: application/force-download' );
234 - header( 'Content-Type: application/octet-stream' );
235 - header( 'Content-Type: application/download' );
236 -
237 - // disposition / encoding on response body
238 - header( "Content-Disposition: attachment;filename={$file_name}" );
239 - header( 'Content-Transfer-Encoding: binary' );
240 -
241 - $handle = fopen( 'php://output', 'w' );
242 -
243 - //handle UTF-8 chars conversion for CSV
244 - fprintf( $handle, chr( 0xEF ) . chr( 0xBB ) . chr( 0xBF ) );
245 -
246 - // put the column headers
247 - fputcsv( $handle, array_values( $columns ) );
248 -
249 - // put the entry values
250 - foreach ( $entry_array as $row ) {
251 - fputcsv( $handle, $row );
252 - }
253 -
254 - fclose( $handle );
255 -
256 - exit;
257 - }
258 -
259 - /**
260 - * Watch the wpuf general settings and sync with weforms settings
261 - *
262 - * @param array $value
263 - *
264 - * @return array
265 - */
266 - public function watch_wpuf_settings( $settings ) {
267 - $merge_array = [];
268 -
269 - if ( isset( $settings['gmap_api_key'] ) ) {
270 - $merge_array['gmap_api'] = $settings['gmap_api_key'];
271 - }
272 -
273 - if ( isset( $settings['recaptcha_public'] ) ) {
274 - $recaptcha = new StdClass();
275 - $recaptcha->key = $settings['recaptcha_public'];
276 - $recaptcha->secret = $settings['recaptcha_private'];
277 - $recaptcha->type = $settings['recaptcha_type'];
278 -
279 - $merge_array['recaptcha'] = $recaptcha;
280 - }
281 -
282 - if ( $merge_array ) {
283 - $weforms_settings = get_option( 'weforms_settings', [] );
284 - $weforms_settings = array_merge( $weforms_settings, $merge_array );
285 -
286 - update_option( 'weforms_settings', $weforms_settings );
287 - }
288 -
289 - return $settings;
290 - }
291 -
292 - /**
293 - * Admin footer text.
294 - *
295 - * Fired by `admin_footer_text` filter.
296 - *
297 - * @since 1.3.5
298 - *
299 - * @param string $footer_text the content that will be printed
300 - *
301 - * @return string the content that will be printed
302 - **/
303 - public function admin_footer_text( $footer_text ) {
304 - $current_screen = get_current_screen();
305 - $is_weforms_screen = ( $current_screen && false !== strpos( $current_screen->id, 'weforms' ) );
306 -
307 - if ( $is_weforms_screen ) {
308 - $footer_text = sprintf(
309 - __( 'If you like %1$s please leave us a %2$s rating.', 'weforms' ),
310 - '<strong>' . __( 'weForms', 'weforms' ) . '</strong>',
311 - '<a href="https://wordpress.org/support/plugin/weforms/reviews/" target="_blank">&#9733;&#9733;&#9733;&#9733;&#9733;</a>'
312 - );
313 - }
314 -
315 - return $footer_text;
316 - }
317 -
318 - /**
319 - * Set default settings tabs
320 - *
321 - * @param array $tabs
322 - *
323 - * @return array
324 - */
325 - public function set_default_settings( $tabs = [] ) {
326 - $tabs['general'] = [
327 - 'label' => __( 'General Settings', 'weforms' ),
328 - 'icon' => WEFORMS_ASSET_URI . '/images/integrations/general-setting.svg',
329 - ];
330 -
331 - $tabs['recaptcha'] = [
332 - 'label' => __( 'reCaptcha', 'weforms' ),
333 - 'icon' => WEFORMS_ASSET_URI . '/images/integrations/reCaptcha.svg',
334 - ];
335 -
336 - $tabs['secure-database'] = [
337 - 'label' => __( 'Secure Database', 'weforms' ),
338 - 'icon' => WEFORMS_ASSET_URI . '/images/integrations/secure-database.png',
339 - ];
340 -
341 - $tabs['humanpresence'] = [
342 - 'label' => __( 'Human Presence', 'weforms' ),
343 - 'icon' => WEFORMS_ASSET_URI . '/images/integrations/hp-shield.svg',
344 - ];
345 -
346 - /* TODO: Refactor this block when more options are added in privacy settings*/
347 - if ( class_exists( 'WeForms_Pro' ) ) {
348 - $tabs['privacy'] = [
349 - 'label' => __( 'Privacy', 'weforms' ),
350 - 'icon' => WEFORMS_ASSET_URI . '/images/privacy.svg',
351 - ];
352 - }
353 -
354 - return $tabs;
355 - }
356 -
357 - /**
358 - * General tab content
359 - *
360 - * @param array $tab
361 - *
362 - * @return void
363 - */
364 - public function settings_tab_general( $tab ) {
365 - include __DIR__ . '/views/weforms-settings-general.php';
366 - }
367 -
368 - /**
369 - * recaptcha tab content
370 - *
371 - * @param array $tab
372 - *
373 - * @return void
374 - */
375 - public function settings_tab_recaptcha( $tab ) {
376 - include __DIR__ . '/views/weforms-settings-recaptcha.php';
377 - }
378 - /**
379 - * secure database tab content
380 - *
381 - * @param array $tab
382 - *
383 - * @return void
384 - */
385 - public function settings_tab_secure_database( $tab ) {
386 - include __DIR__ . '/views/weforms-settings-secure-database.php';
387 - }
388 - /**
389 - * Human Presence tab content
390 - *
391 - * @param array $tab
392 - *
393 - * @return void
394 - */
395 - public function settings_tab_humanpresence( $tab ) {
396 - include __DIR__ . '/views/weforms-settings-humanpresence.php';
397 - }
398 - /**
399 - * Privacy tab content
400 - *
401 - * @param array $tab
402 - *
403 - * @return void
404 - */
405 - public function settings_tab_privacy( $tab ) {
406 - include __DIR__ . '/views/weforms-settings-privacy.php';
407 - }
408 -
409 - /**
410 - * WeForms Pro CTA notice
411 - *
412 - * @since 1.6.5
413 - */
414 - public function wpuf_premium_cta() {
415 - $screen = get_current_screen();
416 - if ( $screen && $screen->base && 'toplevel_page_weforms' !== $screen->base ) {
417 - return;
418 - }
419 -
420 - if ( ! class_exists( 'WeForms_Pro' ) ) {
421 - ?>
422 - <div class="notice updated premium-cta">
423 - <p style="display: flex;align-items: center;">
424 - <img style="padding-right:15px;" src="<?php echo WEFORMS_ASSET_URI . '/images/weforms-logo.png'; ?>">
425 - <?php _e( 'You&#39;re using weForms Free. For more features, modules and more consider upgrading to Pro.' , 'weforms' ); ?>
426 - </p>
427 - <p class="submit">
428 - <a href="https://weformspro.com/get-premium/?utm_source=Entries&utm_medium=Button&utm_campaign=Upgrade%20Now" target="_blank" class="button-primary"><?php _e( 'UPGRADE NOW!' , 'weforms' ); ?></a>
429 - </p>
430 - </div>
431 - <?php
432 - }
433 - }
434 -}
1 +<?php
2 +
3 +/**
4 + * The admin page handler class
5 + */
6 +class WeForms_Admin {
7 +
8 + public function __construct() {
9 +
10 + add_action( 'init', array( $this, 'register_post_type' ) );
11 +
12 + add_action( 'admin_menu', array( $this, 'register_admin_menu' ) );
13 +
14 + add_filter( 'admin_post_weforms_export_forms', array( $this, 'export_forms' ) );
15 + add_filter( 'admin_post_weforms_export_form_entries', array( $this, 'export_form_entries' ) );
16 + }
17 +
18 + /**
19 + * Register form post types
20 + *
21 + * @return void
22 + */
23 + public function register_post_type() {
24 + $capability = wpuf_admin_role();
25 +
26 + register_post_type( 'wpuf_contact_form', array(
27 + 'label' => __( 'Contact Forms', 'weforms' ),
28 + 'public' => false,
29 + 'show_ui' => true,
30 + 'show_in_menu' => false,
31 + 'capability_type' => 'post',
32 + 'hierarchical' => false,
33 + 'query_var' => false,
34 + 'supports' => array('title'),
35 + 'capabilities' => array(
36 + 'publish_posts' => $capability,
37 + 'edit_posts' => $capability,
38 + 'edit_others_posts' => $capability,
39 + 'delete_posts' => $capability,
40 + 'delete_others_posts' => $capability,
41 + 'read_private_posts' => $capability,
42 + 'edit_post' => $capability,
43 + 'delete_post' => $capability,
44 + 'read_post' => $capability,
45 + ),
46 + 'labels' => array(
47 + 'name' => __( 'Forms', 'weforms' ),
48 + 'singular_name' => __( 'Form', 'weforms' ),
49 + 'menu_name' => __( 'Contact Forms', 'weforms' ),
50 + 'add_new' => __( 'Add Form', 'weforms' ),
51 + 'add_new_item' => __( 'Add New Form', 'weforms' ),
52 + 'edit' => __( 'Edit', 'weforms' ),
53 + 'edit_item' => __( 'Edit Form', 'weforms' ),
54 + 'new_item' => __( 'New Form', 'weforms' ),
55 + 'view' => __( 'View Form', 'weforms' ),
56 + 'view_item' => __( 'View Form', 'weforms' ),
57 + 'search_items' => __( 'Search Form', 'weforms' ),
58 + 'not_found' => __( 'No Form Found', 'weforms' ),
59 + 'not_found_in_trash' => __( 'No Form Found in Trash', 'weforms' ),
60 + 'parent' => __( 'Parent Form', 'weforms' ),
61 + ),
62 + ) );
63 + }
64 +
65 + /**
66 + * Register the admin menu
67 + *
68 + * @return void
69 + */
70 + public function register_admin_menu() {
71 + global $submenu;
72 +
73 + $capability = wpuf_admin_role();
74 +
75 + $hook = add_menu_page( __( 'weForms - The Best Contact Form', 'weforms' ), 'weForms', $capability, 'weforms', array( $this, 'contact_form_page'), 'data:image/svg+xml;base64,' . base64_encode( '<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 300 300" style="enable-background:new 0 0 300 300;" xml:space="preserve"><g fill="#9ea3a8"><path d="M285.1,24.1C273.1,9.4,254.8,0,234.3,0H65.7C46.6,0,29.3,8.2,17.3,21.2C6.6,32.9,0,48.5,0,65.7v60.5v108.1 C0,270.6,29.4,300,65.7,300h140h28.6c15.3,0,29.5-5.3,40.7-14.1c15.2-12,25-30.7,25-51.6V65.7C300,49.9,294.4,35.4,285.1,24.1z M212.7,187L104.6,233c-11.1,4.8-24-0.3-28.7-11.4c-4.8-11.1,0.3-24,11.4-28.7l108.1-46.1c11.1-4.8,24,0.3,28.7,11.4 C228.9,169.3,223.8,182.2,212.7,187z M217.4,107.1L99.9,157.8c-11.1,4.8-24-0.3-28.7-11.4c-4.8-11.1,0.3-24,11.4-28.7L200.1,67 c11.1-4.8,24,0.3,28.7,11.4v0C233.6,89.5,228.5,102.3,217.4,107.1z"/></g></svg>' ), 56 );
76 +
77 + if ( current_user_can( $capability ) ) {
78 + $submenu['weforms'][] = array( __( 'Contact Forms', 'weforms' ), $capability, 'admin.php?page=weforms#/' );
79 + $submenu['weforms'][] = array( __( 'Tools', 'weforms' ), $capability, 'admin.php?page=weforms#/tools' );
80 +
81 + if ( class_exists( 'WeForms_Pro' ) ) {
82 + $submenu['weforms'][] = array( __( 'Modules', 'weforms' ), $capability, 'admin.php?page=weforms#/modules' );
83 + } else {
84 + $submenu['weforms'][] = array( __( 'Premium', 'weforms' ), $capability, 'admin.php?page=weforms#/premium' );
85 + }
86 +
87 + do_action( 'weforms-admin-menu', $hook );
88 +
89 + $submenu['weforms'][] = array( __( 'Settings', 'weforms' ), $capability, 'admin.php?page=weforms#/settings' );
90 + }
91 +
92 + add_action( 'load-'. $hook, array( $this, 'load_assets' ) );
93 + }
94 +
95 + /**
96 + * Load the asset libraries
97 + *
98 + * @return void
99 + */
100 + public function load_assets() {
101 + require_once dirname( __FILE__ ) . '/class-form-builder-assets.php';
102 + new WeForms_Form_Builder_Assets();
103 + }
104 +
105 + /**
106 + * The contact form page handler
107 + *
108 + * @return void
109 + */
110 + public function contact_form_page() {
111 + require_once dirname( __FILE__ ) . '/views/vue-index.php';
112 + }
113 +
114 + /**
115 + * Export forms to JSON
116 + *
117 + * @return void
118 + */
119 + public function export_forms() {
120 +
121 + check_admin_referer( 'weforms-export-forms' );
122 +
123 + if ( ! isset( $_REQUEST['weforms_export_forms'] ) ) {
124 + return;
125 + }
126 +
127 + $export_type = isset( $_POST['export_type'] ) ? $_POST['export_type'] : 'all';
128 + $selected = isset( $_POST['selected_forms'] ) ? array_map( 'absint', $_POST['selected_forms'] ) : array();
129 +
130 + if ( ! class_exists( 'WPUF_Admin_Tools' ) ) {
131 + require_once WPUF_ROOT . '/admin/class-tools.php';
132 + }
133 +
134 + switch ($export_type) {
135 + case 'all':
136 + WPUF_Admin_Tools::export_to_json( 'wpuf_contact_form' );
137 + return;
138 +
139 + case 'selected':
140 + WPUF_Admin_Tools::export_to_json( 'wpuf_contact_form', $selected );
141 + return;
142 + }
143 +
144 + exit;
145 + }
146 +
147 + /**
148 + * Export form entries to CSV
149 + *
150 + * @return void
151 + */
152 + public function export_form_entries() {
153 +
154 + $form_id = isset( $_REQUEST['selected_forms'] ) ? absint( $_REQUEST['selected_forms'] ) : 0;
155 +
156 + if ( ! $form_id ) {
157 + return;
158 + }
159 +
160 + $entry_array = [];
161 + $columns = weforms_get_entry_columns( $form_id, false );
162 + $total_entries = weforms_count_form_entries( $form_id );
163 + $entries = weforms_get_form_entries( $form_id, array(
164 + 'number' => $total_entries,
165 + 'offset' => 0
166 + ) );
167 + $extra_columns = array(
168 + 'ip_address' => __( 'IP Address', 'weforms' ),
169 + 'created_at' => __( 'Date', 'weforms' )
170 + );
171 +
172 + $columns = array_merge( array( 'id' => 'Entry ID' ), $columns, $extra_columns );
173 +
174 + foreach ($entries as $entry) {
175 + $temp = array();
176 +
177 + foreach ($columns as $column_id => $label) {
178 + switch ( $column_id ) {
179 + case 'id':
180 + $temp[ $column_id ] = $entry->id;
181 + break;
182 +
183 + case 'ip_address':
184 + $temp[ $column_id ] = $entry->ip_address;
185 + break;
186 +
187 + case 'created_at':
188 + $temp[ $column_id ] = $entry->created_at;
189 + break;
190 +
191 + default:
192 + $value = weforms_get_entry_meta( $entry->id, $column_id, true );
193 + $temp[ $column_id ] = str_replace( WPUF_Render_Form::$separator, ' ', $value );
194 + break;
195 + }
196 + }
197 +
198 + $entry_array[] = $temp;
199 + }
200 +
201 + $handle = fopen("php://output", 'w');
202 +
203 + // put the column headers
204 + fputcsv( $handle, array_values( $columns ) );
205 +
206 + // put the entry values
207 + foreach ($entry_array as $row) {
208 + fputcsv( $handle, $row );
209 + }
210 +
211 + fclose( $handle );
212 +
213 + $blogname = strtolower( str_replace( " ", "-", get_option( 'blogname' ) ) );
214 + $file_name = $blogname . "-bcf-entries-" . time() . '.csv';
215 +
216 + // force download
217 + header("Content-Type: application/force-download");
218 + header("Content-Type: application/octet-stream");
219 + header("Content-Type: application/download");
220 +
221 + // disposition / encoding on response body
222 + header("Content-Disposition: attachment;filename={$file_name}");
223 + header("Content-Transfer-Encoding: binary");
224 + exit;
225 + }
226 +}