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