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