PluginProbe
WPBot – ChatBot Conversational Forms / 1.2.0
WPBot – ChatBot Conversational Forms v1.2.0
1.5.0 1.4.8 1.4.7 trunk 0.9.2 0.9.3 0.9.5 0.9.6 0.9.7 0.9.8 0.9.9 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.6 1.1.7 1.1.8 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 All 36 releases
conversational-forms / classes / admin.php

admin.php in WPBot – ChatBot Conversational Forms 1.2.0, at classes/admin.php

2,161 lines 67.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Qcformbuilder Forms.
4 *
5 * @package Caldera_Forms Modified by QuantumCloud
6 * @author David <david@digilab.co.za>
7 * @license GPL-2.0+
8 * @link
9 * @copyright 2014 David Cramer
10 */
11 /**
12 * Qcformbuilder_Forms Plugin class.
13 * @package Caldera_Forms Modified by QuantumCloud
14 * @author David Cramer <david@digilab.co.za>
15 */
16
17 class Qcformbuilder_Forms_Admin {
18
19 /**
20 * @var string
21 */
22 const VERSION = WFBCORE_VER;
23
24 /**
25 * GET var for from ID to edit
26 *
27 * @since 1.5.3
28 *
29 * @var string
30 */
31 const EDIT_KEY = 'edit';
32
33 /**
34 * GET var for revision ID to edit
35 *
36 * @since 1.5.3
37 *
38 * @var string
39 */
40 const REVISION_KEY = 'wfb_revision';
41
42 /**
43 * GET var for form ID when doing a preview
44 *
45 * @since 1.5.3
46 *
47 * @var string
48 */
49 const PREVIEW_KEY = 'wfb_preview';
50
51 /**
52 * GET var for what to order forms by
53 *
54 * @since 1.5.6
55 *
56 * @var string
57 */
58 const ORDERBY_KEY = 'wfb_orderby';
59
60
61 /**
62 * @var string
63 */
64 protected $plugin_slug = 'qcformbuilder-forms';
65
66
67 /**
68 * @var string
69 */
70 protected $screen_prefix = array();
71
72 /**
73 * @var string
74 */
75 protected $sub_prefix = null;
76
77 /**
78 * @var string
79 */
80 protected $addons = array();
81
82 /**
83 * @var object
84 */
85 protected static $instance = null;
86
87 /**
88 * Holds admin notices
89 *
90 * @since 1.3.0
91 *
92 * @var array
93 */
94 private static $admin_notices;
95
96 /**
97 * Initialize the plugin by setting localization, filters, and administration functions.
98 *
99 */
100 private function __construct() {
101
102 add_filter( 'all_plugins', array( $this, 'prepare_filter_addons' ) );
103
104 // Load plugin text domain
105 add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
106
107 // Add Admin menu page
108 add_action( 'admin_menu', array( $this, 'register_admin_page' ), 9 );
109
110 // Add admin scritps and styles
111 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_stylescripts' ), 1 );
112
113 // add element & fields filters
114 add_filter('qcformbuilder_forms_get_panel_extensions', array( $this, 'get_panel_extensions'), 1);
115 add_filter('qcformbuilder_forms_entry_viewer_buttons', array( $this, 'set_viewer_buttons'),10, 4);
116 add_filter('qcformbuilder_forms_entry_editor_buttons', array( $this, 'set_editor_buttons'),10, 4);
117
118 // action
119
120 add_action('qcformbuilder_forms_admin_templates', array( $this, 'get_admin_templates'),1);
121 add_action('qcformbuilder_forms_entry_meta_templates', array( $this, 'get_admin_meta_templates'),1);
122
123 add_action( 'init', array( $this, 'save_form') );
124 //add_action( 'media_buttons', array($this, 'shortcode_insert_button' ), 11 );
125 add_filter( 'wp_fullscreen_buttons', array($this, 'shortcode_insert_button_fs' ), 11 );
126
127 // filter for adding presets
128 add_filter( 'qcformbuilder_forms_field_option_presets', array($this, 'load_option_presets' ) );
129
130 if( current_user_can( Qcformbuilder_Forms::get_manage_cap( 'create' ) ) ){
131 // create forms
132 add_action("wp_ajax_wfb_create_form", array( $this, 'create_form') );
133 }
134
135 if( current_user_can( Qcformbuilder_Forms::get_manage_cap( 'admin' ) ) ) {
136 add_action( "wp_ajax_toggle_form_state", array( $this, 'toggle_form_state' ) );
137 add_action( "wp_ajax_save_wfb_setting", array( $this, 'save_wfb_setting' ) );
138 add_action( "wp_ajax_wfb_dismiss_pointer", array( $this, 'update_pointer' ) );
139 add_action( "wp_ajax_wfb_bulk_action", array( $this, 'bulk_action' ) );
140 }
141 add_action("wp_ajax_wfb_get_form_preview", array( $this, 'get_form_preview') );
142 add_action( 'admin_footer', array( $this, 'add_shortcode_inserter'));
143
144 $this->addons = apply_filters( 'qcformbuilder_forms_get_active_addons', array() );
145
146 add_action('admin_footer-edit.php', array( $this, 'render_editor_template')); // Fired on the page with the posts table
147 add_action('admin_footer-post.php', array( $this, 'render_editor_template')); // Fired on post edit page
148 add_action('admin_footer-post-new.php', array( $this, 'render_editor_template')); // Fired on add new post page
149
150 add_action( 'qcformbuilder_forms_new_form_template_end', array( $this, 'load_new_form_templates') );
151
152 add_action( 'qcformbuilder_forms_prerender_edit', array( __CLASS__, 'easy_pods_auto_populate' ) );
153
154 add_action( 'init', array( 'Qcformbuilder_Forms_Admin_Resend', 'watch_for_resend' ) );
155
156 add_action( 'qcformbuilder_forms_admin_footer', array( 'Qcformbuilder_Forms_Email_Settings', 'ui' ) );
157
158 add_action( 'qcformbuilder_forms_admin_init', array( __CLASS__ , 'init_privacy_settings' ) );
159
160 add_action( 'admin_init', array( __CLASS__, 'add_suggested_privacy_content' ), 35 );
161
162 /**
163 * Runs after Qcformbuilder Forms admin is initialized
164 *
165 * @since 1.3.5.3
166 */
167 do_action( 'qcformbuilder_forms_admin_init' );
168
169 /** Adding anything to this constructor after qcformbuilder_forms_admin_init action is a violation of intergalactic law */
170 }
171
172 public function render_editor_template(){
173 ?>
174 <script type="text/html" id="tmpl-editor-qcformbuilder-forms">
175 <# if ( data.html ) { #>
176 {{{ data.html }}}
177 <# } else { #>
178 <div class="wpview-error">
179 <div class="dashicons dashicons-wfb-logo"></div><p style="font-size: 13px;"><?php _e( 'Invalid Form.', 'qcformbuilder-forms' ); ?></p>
180 </div>
181 <# } #>
182 </script>
183 <?php
184
185 }
186
187 /**
188 * Returns the array of option presets for option based fields.
189 *
190 * @since 1.4.0
191 * @param array $presets current array of presets
192 *
193 * @return array array of presets
194 */
195 public function load_option_presets( $presets ){
196
197 $internal = array_merge( $presets, array(
198 'countries_iso_alpha_2' => array(
199 'name' => __( 'Countries (ISO Alpha-2)', 'qcformbuilder-forms'),
200 'data' => file_get_contents( WFBCORE_PATH . 'includes/presets/countries_iso_alpha_2.txt' ),
201 ),
202 'countries_names' => array(
203 'name' => __( 'Countries (Names Only)', 'qcformbuilder-forms'),
204 'data' => file_get_contents( WFBCORE_PATH . 'includes/presets/countries_names.txt' ),
205 ),
206 'continents' => array(
207 'name' => __( 'Continents', 'qcformbuilder-forms'),
208 'data' => array(
209 "Africa",
210 "Antarctica",
211 "Asia",
212 "Australia",
213 "Europe",
214 "North America",
215 "South America",
216 ),
217 ),
218 'canadian_provinces_territories' => array(
219 'name' => __( 'Canadian Provinces & Territories', 'qcformbuilder-forms'),
220 'data' => array(
221 "Alberta",
222 "British Columbia",
223 "Manitoba",
224 "New Brunswick",
225 "Newfoundland and Labrador",
226 "Northwest Territories",
227 "Nova Scotia",
228 "Nunavut",
229 "Ontario",
230 "Prince Edward Island",
231 "Quebec",
232 "Saskatchewan",
233 "Yukon",
234 ),
235 ),
236 'us_states' => array(
237 'name' => __( 'US States', 'qcformbuilder-forms'),
238 'data' => file_get_contents( WFBCORE_PATH . 'includes/presets/us_states.txt' ),
239 ),
240 ));
241
242 return $internal;
243 }
244
245 /**
246 * Returns the array of form templates.
247 *
248 * @since 1.2.3
249 *
250 * @return array The form templates
251 */
252 public static function internal_form_templates(){
253
254 $internal_templates = array(
255
256 'simple-feedback-example' => array(
257 'name' => esc_html__( 'Simple Feedback', 'qcformbuilder-forms' ),
258 'template' => include WFBCORE_PATH . 'includes/templates/simple-feedback-example.php'
259 ),
260 'simple-survey-example' => array(
261 'name' => esc_html__( 'Simple Survey', 'qcformbuilder-forms' ),
262 'template' => include WFBCORE_PATH . 'includes/templates/simple-survey-example.php'
263 ),
264
265 'simple_booking_form_example' => array(
266 'name' => esc_html__( 'Simple Booking', 'qcformbuilder-forms' ),
267 'template' => include WFBCORE_PATH . 'includes/templates/simple-booking-form-example.php'
268 ),
269
270
271
272 );
273
274 /**
275 * Filter form templates
276 *
277 * @since 1.2.3
278 *
279 * @param array $internal_templates Form templates
280 */
281 return apply_filters( 'qcformbuilder_forms_get_form_templates', $internal_templates );
282
283 }
284
285 public function load_new_form_templates(){
286
287 $form_templates = self::internal_form_templates();
288
289 ?>
290 <div class="wfb-templates-wrapper">
291 <?php
292 $selected_field = '';//' checked="checked"';
293 $selected_template = '';//' selected';
294
295 foreach( $form_templates as $template_slug => $template ){
296 if( !empty( $template['template'] ) && !empty( $template['name'] ) ){
297
298 echo '<label class="qcformbuilder-grid wfb-form-template' . $selected_template . '">';
299 echo '<small>' . $template['name'] . '</small>';
300
301 echo '<input type="radio" name="template" value="' . $template_slug . '" class="wfb-template-select"' . $selected_field . '>';
302
303
304 // check a layout exists
305 if( !empty( $template['preview'] ) ){
306 echo '<img src="' . esc_url( $template['preview'] ) . '"></label>';
307 continue;
308 }
309 if( empty( $template['template']['layout_grid'] ) || empty( $template['template']['layout_grid']['structure'] ) || empty( $template['template']['layout_grid']['fields'] ) ){
310 echo '<p class="description" style="padding: 50px 0px; text-align: center;">' . esc_html__( 'Preview not available', 'qcformbuilder-forms' ) . '</p></label>';
311 continue;
312 }
313
314 $struct = explode('|', $template['template']['layout_grid']['structure'] );
315
316 foreach ($struct as $row_num=>$row) {
317
318 $columns = explode( ':', $row );
319 echo '<div class="row" style="margin: 6px 0px;">';
320 foreach ($columns as $column_num=>$column) {
321 //var_dump( $template['template']['layout_grid']['fields'][ ( $row_num+1) . ':' . ( $column_num+1) ] );
322 $fields = array_keys( $template['template']['layout_grid']['fields'], ( $row_num+1) . ':' . ( $column_num+1) );
323 echo '<div class="col-sm-' . $column . '" style="padding: 0px 3px;">';
324 echo '<div class="wfb-template-column">';
325 foreach( $fields as $field ){
326 if( isset( $template['template']['fields'][ $field ] ) ){
327 if( $template['template']['fields'][ $field ]['type'] == 'button'){
328 echo '<small class="wfb-preview-field wfb-preview-button">' . $template['template']['fields'][ $field ]['label'] .'</small>';
329 }elseif( $template['template']['fields'][ $field ]['type'] == 'html'){
330 echo '<small class="wfb-preview-field wfb-preview-field-html"></small>';
331 }elseif( $template['template']['fields'][ $field ]['type'] == 'paragraph'){
332 echo '<small class="wfb-preview-field" style="height:50px;">' . $template['template']['fields'][ $field ]['label'] .'</small>';
333 }elseif( $template['template']['fields'][ $field ]['type'] == 'hidden'){
334 // nope- nothing
335 }else{
336 echo '<small class="wfb-preview-field">' . $template['template']['fields'][ $field ]['label'] .'</small>';
337 }
338 }
339 }
340 echo '</div>';
341 echo '</div>';
342 }
343
344 echo '</div>';
345 }
346
347 echo '</label>';
348 // unset selection
349 $selected_field = null;
350 $selected_template = null;
351 }
352 }
353
354 ?>
355 <label class="qcformbuilder-grid wfb-form-template">
356 <small><?php echo esc_html__( 'Blank Form', 'qcformbuilder-forms' ); ?></small>
357 <input type="radio" name="template" value="" class="wfb-template-select">
358 </label>
359 <div class="qcformbuilder-grid wfb-form-create" style="display:none; visibility: hidden;" aria-hidden="true">
360 <div class="wfb-template-title"></div>
361
362 <div class="qcformbuilder-config-field">
363 <input type="text" class="new-form-name block-input field-config" name="name" value="" required="required" autofocus="true" autocomplete="off" placeholder="<?php echo esc_html__('Form Name', 'qcformbuilder-forms' ); ?>">
364 </div>
365
366 <button type="button" class="wfb-change-template-button"><span class="dashicons dashicons-arrow-left-alt"></span> <?php echo esc_html__( 'Change Template', 'qcformbuilder-forms' ); ?></button>
367 <button type="button" class="wfb-create-form-button ajax-trigger"
368 data-action="wfb_create_form"
369 data-active-class="disabled"
370 data-load-class="disabled"
371 data-callback="new_form_redirect"
372 data-before="serialize_modal_form"
373 data-modal-autoclose="new_form"
374 data-nonce=<?php echo wp_create_nonce( 'wfb_create_form' ); ?>
375 ><?php echo esc_html__( 'Create Form', 'qcformbuilder-forms' ); ?> <span class="dashicons dashicons-yes"></span><span class="spinner"></span></button>
376
377 </div>
378
379 </div>
380 <?php
381 /**
382 * Runs at the bottom of the new form modal
383 *
384 * Use to add extra buttons, etc.
385 *
386 * @since 1.4.2
387 */
388 do_action( 'qcformbuilder_forms_new_form_modal_bottom' );
389 }
390
391 public function get_form_preview(){
392 global $post;
393 add_filter('qcformbuilder_forms_render_form_element', array( $this, 'set_preview_form_element') );
394 $post = get_post( (int) $_POST['post_id'] );
395 if( isset($_POST['atts']['named']['id']) ){
396 $form = $_POST['atts']['named']['id'];
397 }elseif( isset($_POST['atts']['named']['name']) ){
398 $form = $_POST['atts']['named']['name'];
399 }
400
401 add_filter('qcformbuilder_forms_get_form-' . $form, array( $this, 'set_preview_get_form'),100 );
402
403 $atts = $_POST['atts']['named'];
404 $atts['preview'] = true;
405
406 if( !empty( $form ) ){
407 ob_start();
408 wp_head();
409 echo Qcformbuilder_Forms::render_form( $form );
410 wp_print_footer_scripts();
411 $html = ob_get_clean();
412 }
413 $out = array();
414 if( !empty( $html ) ){
415 $out['html'] = $html;
416 }
417
418 wp_send_json_success( $out );
419 }
420 public function set_preview_get_form( $form ){
421 $form['form_ajax'] = false;
422 $form['settings']['responsive']['break_point'] = 'xs';
423 return $form;
424 }
425 public function set_preview_form_element($element){
426 return 'div';
427 }
428
429 public function prepare_filter_addons($plugins){
430 global $wp_list_table, $status;
431
432 if( !empty( $this->addons ) ){
433 $addons = array();
434 foreach( $this->addons as $addon ){
435 $plugin_slug = basename( dirname( $addon['file'] ) ) .'/'.basename( $addon['file'] );
436 if( isset( $plugins[$plugin_slug] ) ){
437 if( isset( $addon['slug'] ) ){
438 $plugins[$plugin_slug]['slug'] = $addon['slug'];
439 }
440 }
441 }
442 }
443 if( isset( $_REQUEST['plugin_status'] ) && $_REQUEST['plugin_status'] === 'qcformbuilder_forms' ){
444 $status = 'qcformbuilder_forms';
445 }
446
447 return $plugins;
448 }
449
450 public function bulk_action(){
451
452 // first validate
453 self::verify_ajax_action();
454
455
456 if(empty($_POST['do'])){
457 die;
458 }
459
460 $do_action = strtolower( $_POST['do'] );
461
462 switch ( $do_action ) {
463 case 'active':
464 case 'trash':
465 case 'delete':
466 global $wpdb;
467
468 $result = false;
469 $items = array();
470 $selectors = array();
471 foreach ( (array) $_POST[ 'items' ] as $item_id ) {
472 $items[] = (int) $item_id;
473 $selectors[] = '#entry_row_' . (int) $item_id;
474 }
475
476 switch ( $do_action ) {
477 case 'delete':
478 if( current_user_can( Qcformbuilder_Forms::get_manage_cap( 'delete-entry' ) ) ){
479 $result = Qcformbuilder_Forms_Entry_Bulk::delete_entries( $items );
480 }
481 $out['status'] = 'reload';
482 wp_send_json( $out );
483 break;
484
485 default:
486 if( current_user_can( Qcformbuilder_Forms::get_manage_cap( 'edit-entry' ) ) ){
487 $result = Qcformbuilder_Forms_Entry_Bulk::change_status( $items, $do_action );
488 }
489 break;
490 }
491
492 if( $result ){
493 $out[ 'status' ] = $do_action;
494 $out[ 'undo' ] = ( $do_action === 'trash' ? 'active' : esc_html_x( 'Trash', 'Verb: Action of moving to trash', 'qcformbuilder-forms' ) );
495 $out[ 'undo_text' ] = ( $do_action === 'trash' ? esc_html__( 'Restore', 'qcformbuilder-forms' ) : esc_html_x( 'Trash', 'Verb: Action of moving to trash', 'qcformbuilder-forms' ) );
496
497 $form = strip_tags( $_POST[ 'form' ] );
498 $out[ 'entries' ] = implode( ',', $selectors );
499 $out[ 'total' ] = Qcformbuilder_Forms_Entry_Bulk::count( $form, false );
500 $out[ 'trash' ] = Qcformbuilder_Forms_Entry_Bulk::count( $form, 'trash' );
501 wp_send_json( $out );
502 }
503 exit();
504
505 break;
506 case 'export':
507
508 $transientid = uniqid('cfe');
509 Qcformbuilder_Forms_Transient::set_transient( $transientid, $_POST['items'], 180 );
510 $out['url'] = "admin.php?page=qcformbuilder-forms&export=" . $_POST['form'] . "&tid=" . $transientid;
511 wp_send_json( $out );
512 exit();
513 break;
514 default:
515 # code...
516 break;
517 }
518 exit();
519 }
520
521 /**
522 * Dismiss admin pointer
523 *
524 * @since unknown
525 *
526 * @uses "wp_ajax_wfb_dismiss_pointer" action
527 */
528 public static function update_pointer(){
529 if( ! isset( $_POST[ 'nonce' ] ) || ! wp_verify_nonce( $_POST[ 'nonce' ], 'wfb_dismiss_pointer' ) ){
530 status_header( 500 );
531 exit;
532 }
533
534 if ( ! empty( $_POST[ 'pointer' ] ) ) {
535 add_user_meta( get_current_user_id(), 'wfb_pointer_' . $_POST[ 'pointer' ], array( 0 => NULL ) );
536 }
537 exit;
538 }
539
540 /**
541 * Load the plugin text domain for translation.
542 *
543 */
544 public function load_plugin_textdomain() {
545 load_plugin_textdomain( $this->plugin_slug, FALSE, basename( WFBCORE_PATH ) . '/languages');
546 }
547
548
549
550 public static function add_shortcode_inserter(){
551
552 $screen = get_current_screen();
553
554 if($screen->base === 'post'){
555 include WFBCORE_PATH . 'ui/insert_shortcode.php';
556 }
557 }
558
559 public static function get_admin_templates(){
560 include WFBCORE_PATH . 'ui/news_templates.php';
561 include WFBCORE_PATH . 'ui/admin_templates.php';
562 }
563 public static function get_admin_meta_templates(){
564
565 $processors = $processors = Qcformbuilder_Forms_Processor_Load::get_instance()->get_processors();
566 if(!empty($processors)){
567 foreach($processors as $processor_type=>$processor_config){
568 if( isset( $processor_config['meta_template'] ) && file_exists( $processor_config['meta_template'] ) ){
569 echo "{{#if ".$processor_type."_template}}\r\n";
570 echo "{{#each data}}\r\n";
571 echo "{{#if title}}\r\n";
572 echo "<h4>{{title}}</h4>\r\n";
573 echo "{{/if}}\r\n";
574 echo "{{#each entry}}\r\n";
575 include $processor_config['meta_template'];
576 echo "{{/each}}\r\n";
577 echo "{{/each}}\r\n";
578 echo "{{/if}}\r\n";
579 }
580 }
581 }
582 }
583
584 /**
585 * Get the entry editor's buttons
586 *
587 * @since unknown
588 *
589 * @deprecated
590 */
591 public static function get_entry_actions(){
592 _deprecated_function( __FUNCTION__, 'Qcformbuilder_Forms_Entry_UI::get_entry_actions()', '1.5.0' );
593 Qcformbuilder_Forms_Entry_UI::get_entry_actions();
594 }
595
596 /**
597 * Set buttons for entry viewer
598 *
599 * @since 1.4.0
600 *
601 * @uses "qcformbuilder_forms_entry_viewer_buttons" filter
602 *
603 * @param array $buttons
604 *
605 * @return array
606 */
607 public static function set_viewer_buttons($buttons){
608
609 $buttons[ 'close_panel' ] = array(
610 'label' => esc_html__( 'Close', 'qcformbuilder-forms' ),
611 'config' => 'dismiss',
612 'class' => 'right'
613 );
614
615 if ( current_user_can( Qcformbuilder_Forms::get_manage_cap( 'edit-entry' ) ) ) {
616 $buttons[ 'edit_entry' ] = array(
617 'label' => esc_html__( 'Edit Entry', 'qcformbuilder-forms' ),
618 'config' => array(
619 'data-trigger' => '#edit-entry-{{_entry_id}}'
620 ),
621 'class' => 'button-primary'
622 );
623
624 }
625
626
627 return $buttons;
628 }
629
630
631 public static function set_editor_buttons($buttons){
632
633 $buttons['submit_form'] = array(
634 'label' => esc_html__( 'Save Changes', 'qcformbuilder-forms' ),
635 'config' => array(
636 "data-for" => "#view_entry_baldrickModalBody .qcformbuilder_forms_form"
637 ),
638 'class' => 'right button-primary'
639 );
640 $buttons['view_entry'] = array(
641 'label' => esc_html__( 'View Entry', 'qcformbuilder-forms' ),
642 'config' => array(
643 "data-for" => ".view-entry-btn.current-view"
644 ),
645 'class' => ''
646 );
647
648
649 return $buttons;
650 }
651
652 /**
653 * Handles saving general settings
654 *
655 * @since unknown
656 *
657 * @uses "wp_ajax_save_wfb_setting" action
658 */
659 public static function save_wfb_setting(){
660 self::verify_ajax_action();
661 if(empty($_POST['set'])){
662 exit;
663 }
664 $style_includes = get_option( '_qcformbuilder_forms_styleincludes' );
665
666
667 if( 'cdn_enable' == $_POST[ 'set' ] ){
668 Qcformbuilder_Forms::settings()->get_cdn()->toggle_cdn_enable();
669
670 }else{
671 if(empty($style_includes[$_POST['set']])){
672 $style_includes[$_POST['set']] = true;
673 }else{
674 $style_includes[$_POST['set']] = false;
675 }
676 update_option( '_qcformbuilder_forms_styleincludes', $style_includes);
677
678 }
679
680 $return_data = array_merge( $style_includes, array(
681 'cdn_enable' => Qcformbuilder_Forms::settings()->get_cdn()->enabled()
682 ) );
683
684 wp_send_json( $return_data );
685 exit;
686 }
687
688 /**
689 * Insert shortcode media button
690 *
691 * Add shortcode insert button in classic editor
692 *
693 * Function is intentionally not static
694 *
695 * @since unknown
696 */
697 public function shortcode_insert_button(){
698 if( Qcformbuilder_Forms_Admin_Assets::is_woocommerce_page() ){
699 return;
700 }
701 global $post;
702 if(!empty($post)){
703 echo "<a id=\"qcformbuilder-forms-form-insert\" title=\"". esc_attr__( 'Add Form to Page', 'qcformbuilder-forms' ) . "\" class=\"button qcformbuilder-forms-insert-button\" href=\"#inst\">\n";
704 echo " <img src=\"". WFBCORE_URL . "assets/images/qcformbuilder-globe-logo-sm.png\" alt=\"". esc_attr__( 'Insert Form Shortcode' , 'qcformbuilder-forms') . "\" style=\"padding: 0px 2px 0px 0px; width: 16px; margin: -2px 0px 0px;\" /> ".__('Qcformbuilder Form', 'qcformbuilder-forms' )."\n";
705 echo "</a>\n";
706 }
707 }
708
709
710 function shortcode_insert_button_fs($buttons){
711
712 $buttons['qcformbuilder-forms'] = array(
713 "title" => __( 'Add Form to Page', 'qcformbuilder-forms' ),
714 "both" => true
715 );
716 return $buttons;
717 }
718
719 /**
720 * Change form's state
721 *
722 * @uses "wp_ajax_toggle_form_state" action
723 *
724 * @since unknown
725 */
726 public static function toggle_form_state(){
727 if( ! isset( $_POST[ 'nonce' ] ) || !wp_verify_nonce( $_POST[ 'nonce' ], 'toggle_form_state' ) ){
728 wp_send_json_error( $_POST );
729 }
730
731 $forms = Qcformbuilder_Forms_Forms::get_forms( true );
732 $form = sanitize_text_field( $_POST['form'] );
733 $form = Qcformbuilder_Forms_Forms::get_form( $form );
734 if( empty( $form ) || empty( $form['ID'] ) || empty( $forms[ $form['ID'] ]) ){
735 wp_send_json_error( );
736 }
737
738 add_filter( 'qcformbuilder_forms_save_revision', '__return_false' );
739
740 if ( ! empty( $form[ 'form_draft' ] ) ) {
741 unset( $form['form_draft'] );
742 unset( $forms[ $form['ID'] ]['form_draft'] );
743 Qcformbuilder_Forms_Forms::form_state( $form );
744 $state = 'active-form';
745 $label = esc_html__( 'Disable', 'qcformbuilder-forms' );
746 }else{
747 Qcformbuilder_Forms_Forms::form_state( $form , false );
748 $state = 'draft-form';
749 $label = esc_html__( 'Enable', 'qcformbuilder-forms' );
750 }
751
752 add_filter( 'qcformbuilder_forms_save_revision', '__return_true' );
753
754
755 wp_send_json_success( array( 'ID' => $form['ID'], 'state' => $state, 'label' => $label ) );
756 }
757
758 /**
759 * nonce verifier for ajax actions
760 *
761 * @since 1.3.2.1
762 */
763 private static function verify_ajax_action(){
764 if ( ! isset( $_POST['wfb_toolbar_actions'] ) || ! wp_verify_nonce( $_POST['wfb_toolbar_actions'], 'wfb_toolbar' ) || !check_admin_referer( 'wfb_toolbar', 'wfb_toolbar_actions' ) ) {
765 wp_send_json_error( $_POST );
766 }
767 }
768
769 /**
770 * Show entries in admin
771 *
772 * @deprecated 1.4.0 Use Qcformbuilder_Forms_Entry_UI::view_entries()
773 *
774 * @since unknown
775 */
776 public static function browse_entries(){
777 _deprecated_function( __FUNCTION__, '1.4.0', 'Qcformbuilder_Forms_Entry_UI::view_entries' );
778 self::verify_ajax_action();
779 if ( isset( $_POST[ 'page' ] ) && 0 < $_POST[ 'page' ] ) {
780 $page = absint( $_POST[ 'page' ] );
781 }else{
782 $page = 1;
783 }
784 $entry_perpage = get_option( '_qcformbuilder_forms_entry_perpage', 20 );
785 if ( isset( $_POST[ 'perpage' ] ) && 0 < $_POST[ 'perpage' ] ) {
786 $perpage = absint( (int) $_POST[ 'perpage' ] );
787 if( $entry_perpage != $perpage ){
788 update_option( '_qcformbuilder_forms_entry_perpage', $perpage );
789 }
790 }else{
791 $perpage = $entry_perpage;
792 }
793
794 if ( isset( $_POST[ 'status' ] ) ) {
795 $status = strip_tags( $_POST[ 'status' ] );
796 }else{
797 $status = 'active';
798 }
799
800 $form = Qcformbuilder_Forms_Forms::get_form( $_POST['form'] );
801
802 $data = self::get_entries( $form, $page, $perpage, $status );
803
804 // set status output
805 $data['is_' . $status ] = true;
806
807 wp_send_json( $data );
808 exit;
809
810
811 }
812
813 /**
814 * Get entries from a form
815 *
816 * @since 1.2.1
817 *
818 * @param string|array $form_or_id Form ID or form config.
819 * @param int $page Optional. Page of entries to get per page. Default is 1.
820 * @param int $perpage Optional. Number of entries per page. Default is 20.
821 * @param string $status Optional. Form status. Default is active.
822 *
823 * @return array
824 */
825 public static function get_entries( $form_or_id, $page = 1, $perpage = 20, $status = 'active' ) {
826
827 if ( is_string( $form_or_id ) ) {
828 $form_or_id = Qcformbuilder_Forms_Forms::get_form( $form_or_id );
829 }
830
831 if ( isset( $form_or_id[ 'ID' ])) {
832 $form_id = $form_or_id[ 'ID' ];
833 }else{
834 return;
835 }
836
837 global $form;
838 $form = $form_or_id;
839
840 global $wpdb;
841
842 $field_labels = array();
843 $backup_labels = array();
844 $selects = array();
845
846
847 $fields = array();
848 if ( ! empty( $form[ 'fields' ] ) ) {
849 foreach ( $form[ 'fields' ] as $fid => $field ) {
850 $fields[ $field[ 'slug' ] ] = $field;
851
852 if ( ! empty( $field[ 'entry_list' ] ) ) {
853 $selects[] = "'" . $field[ 'slug' ] . "'";
854 $field_labels[ $field[ 'slug' ] ] = $field[ 'label' ];
855 }
856 $has_vars = array();
857 if ( ! empty( $form[ 'variables' ][ 'types' ] ) ) {
858 $has_vars = $form[ 'variables' ][ 'types' ];
859 }
860 if ( ( count( $backup_labels ) < 4 && ! in_array( 'entryitem', $has_vars ) ) && in_array( $field[ 'type' ], array(
861 'text',
862 'email',
863 'date',
864 'name'
865 ) )
866 ) {
867 // backup only first 4 fields
868 $backup_labels[ $field[ 'slug' ] ] = $field[ 'label' ];
869 }
870 }
871 }
872
873 if ( empty( $field_labels ) ) {
874 $field_labels = $backup_labels;
875 }
876
877 $entries = new Qcformbuilder_Forms_Entry_Entries( $form, $perpage );
878
879 $data = array();
880
881 $filter = null;
882
883 $data[ 'trash' ] = $entries->get_total( 'trash' );
884 $data[ 'active' ] = $entries->get_total( 'active' );
885
886 // set current total
887 if ( ! empty( $status ) && isset( $data[ $status ] ) ) {
888 $data[ 'total' ] = $entries->get_total( $status );
889 } else {
890 $data[ 'total' ] = $data[ 'active' ];
891 }
892
893
894 $data[ 'pages' ] = ceil( $data[ 'total' ] / $perpage );
895
896 if ( ! empty( $page ) ) {
897 $page = abs( $page );
898 if ( $page > $data[ 'pages' ] ) {
899 $page = $data[ 'pages' ];
900 }
901 }
902
903 $data['current_page'] = $page;
904
905 if($data['total'] > 0){
906
907 $data[ 'form' ] = $form_id;
908
909 $data[ 'fields' ] = $field_labels;
910
911
912 $the_entries = $entries->get_page( $page, $status );
913
914 if ( ! empty( $the_entries ) ) {
915
916 $ids = array();
917 $data[ 'entries' ] = array();
918
919
920 /** @var Qcformbuilder_Forms_Entry $an_entry */
921 foreach ( $the_entries as $an_entry ) {
922 $ids[] = $an_entry->get_entry_id();
923 }
924 // init field types to initialize view rendering in entry lists
925 Qcformbuilder_Forms_Fields::get_all();
926
927 foreach ( $ids as $entry_id ) {
928 $rows = $entries->get_rows( $page, (int) $entry_id, $status );
929 foreach ( $rows as $row ) {
930 $e = 'E' . $row->entry_id;
931 if ( ! empty( $row->_user_id ) ) {
932 $user = get_userdata( $row->_user_id );
933 if ( ! empty( $user ) ) {
934 $data[ 'entries' ][ $e ][ 'user' ][ 'ID' ] = $user->ID;
935 $data[ 'entries' ][ $e ][ 'user' ][ 'name' ] = $user->data->display_name;
936 $data[ 'entries' ][ $e ][ 'user' ][ 'email' ] = $user->data->user_email;
937 $data[ 'entries' ][ $e ][ 'user' ][ 'avatar' ] = get_avatar( $user->ID, 64 );
938 }
939 }
940
941 $data[ 'entries' ][ $e ][ '_entry_id' ] = $row->entry_id;
942
943 $submitted = $row->_datestamp;
944
945
946 $data[ 'entries' ][ $e ][ '_date' ] = Qcformbuilder_Forms::localize_time( $submitted );
947
948 // setup default data array
949 if ( ! isset( $data[ 'entries' ][ $e ][ 'data' ] ) ) {
950 if ( isset( $field_labels ) ) {
951 foreach ( $field_labels as $slug => $label ) {
952 // setup labels ordering
953 $data[ 'entries' ][ $e ][ 'data' ][ $slug ] = null;
954 }
955 }
956 }
957
958 if ( ! empty( $field_labels[ $row->slug ] ) ) {
959
960 $label = $field_labels[ $row->slug ];
961
962 // check view handler
963 $field = Qcformbuilder_Forms_Field_Util::get_field( $row->slug, $form, true );
964
965 // maybe json?
966 if ( is_string($row->value) ) {
967 $is_json = json_decode( $row->value, ARRAY_A );
968 } else if ( is_array($row->value) ) { //Process all checkbox values
969 $is_json = $row->value;
970 }
971
972 if ( ! empty( $is_json ) ) {
973 $row->value = $is_json;
974 }else {
975 $row->value = maybe_unserialize( $row->value );
976 }
977
978 if( is_array( $row->value ) ) {
979 $row->value = implode( ',' , $row->value );
980 }
981
982 if( is_string( $row->value ) ){
983 $row->value = esc_html( stripslashes_deep( $row->value ) );
984 }else{
985 $row->value = stripslashes_deep( Qcformbuilder_Forms_Sanitize::sanitize( $row->value ) );
986 }
987
988 $row->value = apply_filters( 'qcformbuilder_forms_view_field_' . $field[ 'type' ], $row->value, $field, $form );
989
990 if ( isset( $data[ 'entries' ][ $e ][ 'data' ][ $row->slug ] ) ) {
991 // array based - add another entry
992 if ( ! is_array( $data[ 'entries' ][ $e ][ 'data' ][ $row->slug ] ) ) {
993 $tmp = $data[ 'entries' ][ $e ][ 'data' ][ $row->slug ];
994 $data[ 'entries' ][ $e ][ 'data' ][ $row->slug ] = array( $tmp );
995 }
996 $data[ 'entries' ][ $e ][ 'data' ][ $row->slug ][] = $row->value;
997 } else {
998 $data[ 'entries' ][ $e ][ 'data' ][ $row->slug ] = $row->value;
999 }
1000 }
1001
1002 if ( ! empty( $form[ 'variables' ][ 'types' ] ) ) {
1003 foreach ( $form[ 'variables' ][ 'types' ] as $var_key => $var_type ) {
1004 if ( $var_type == 'entryitem' ) {
1005 $data[ 'fields' ][ $form[ 'variables' ][ 'keys' ][ $var_key ] ] = ucwords( str_replace( '_', ' ', $form[ 'variables' ][ 'keys' ][ $var_key ] ) );
1006 $data[ 'entries' ][ $e ][ 'data' ][ $form[ 'variables' ][ 'keys' ][ $var_key ] ] = Qcformbuilder_Forms::do_magic_tags( $form[ 'variables' ][ 'values' ][ $var_key ], $row->_entryid );
1007 }
1008 }
1009 }
1010
1011
1012 }
1013 }
1014 }
1015 }
1016
1017
1018 return $data;
1019
1020 }
1021
1022
1023 /**
1024 * Return an instance of this class.
1025 *
1026 *
1027 * @return object A single instance of this class.
1028 */
1029 public static function get_instance() {
1030
1031 // If the single instance hasn't been set, set it now.
1032 if ( null == self::$instance ) {
1033 self::$instance = new self;
1034 }
1035
1036 return self::$instance;
1037 }
1038
1039 /**
1040 * Registers the admin page
1041 *
1042 */
1043 public function register_admin_page(){
1044 global $menu, $submenu;
1045
1046 $forms = Qcformbuilder_Forms_Forms::get_forms( true );
1047
1048
1049 // get current user
1050 if( current_user_can( Qcformbuilder_Forms::get_manage_cap() ) ){
1051
1052 $this->screen_prefix[] = add_menu_page(
1053 __('Chatbot Form Builder', 'qcformbuilder-forms' ),
1054 __('Chatbot Form Builder', 'qcformbuilder-forms' ),
1055 Qcformbuilder_Forms::get_manage_cap(),
1056 $this->plugin_slug, array( $this, 'render_admin' ),
1057 'dashicons-format-aside',
1058 '9'
1059 );
1060
1061 add_submenu_page(
1062 $this->plugin_slug,
1063 __('Qcformbuilder Forms Admin', 'qcformbuilder-forms' ),
1064 __('Chatbot Form Builder', 'qcformbuilder-forms' ),
1065 Qcformbuilder_Forms::get_manage_cap(),
1066 $this->plugin_slug, array( $this, 'render_admin' ) );
1067
1068 if( ! empty( $forms ) ){
1069 foreach($forms as $form_id=>$form){
1070 if(!empty($form['pinned'])){
1071
1072 $this->screen_prefix[] = add_submenu_page(
1073 $this->plugin_slug,
1074 __('Qcformbuilder Forms', 'qcformbuilder-forms' ).' - ' . $form['name'], '- '.$form['name'],
1075 Qcformbuilder_Forms::get_manage_cap(), $this->plugin_slug . '-pin-' . $form_id, array( $this, 'render_admin' )
1076 );
1077 }
1078 }
1079 }
1080
1081 }else{
1082 // not an admin - pin for user
1083 if( ! empty( $forms ) ){
1084 $user = wp_get_current_user();
1085 if(empty($user->roles)){
1086 // no role - bye bye.
1087 return;
1088 }
1089
1090 foreach($forms as $form_id=>$form){
1091 $capability = null;
1092 if(!empty($form['pinned']) && !empty( $form['pin_roles'] ) ){
1093 if( !empty( $form['pin_roles']['all_roles'] ) ){
1094 $user = wp_get_current_user();
1095 if( empty( $user ) || empty( $user->roles ) ){
1096 continue;
1097 }
1098 $capabilities = array_keys( $user->allcaps );
1099 if( empty( $capabilities ) ){
1100 continue;
1101 }
1102 $capability = $capabilities[0];
1103 }elseif( !empty( $form['pin_roles']['access_role'] ) ){
1104 foreach ($form['pin_roles']['access_role'] as $role => $enabled) {
1105 if( in_array( $role, $user->roles ) ){
1106 $role_details = get_role( $role );
1107 if(empty($role_details->capabilities)){
1108 continue;
1109 }
1110 $capabilities = array_keys( $role_details->capabilities );
1111 $capability = $capabilities[0];
1112 break;
1113 }
1114 }
1115 }
1116 if( empty($capability)){
1117 // not this one.
1118 continue;
1119 }
1120
1121 if( empty( $this->screen_prefix ) ){
1122 // make top menu
1123 $main_slug = $this->plugin_slug . '-pin-' . $form_id;
1124 $this->screen_prefix[] = add_menu_page( __('Chatbot Form Builder', 'qcformbuilder-forms' ), __('Chatbot Form Builder', 'qcformbuilder-forms' ), $capability, $main_slug, array( $this, 'render_admin' ), 'dashicons-format-aside', 52.999 );
1125
1126 }
1127
1128 $this->screen_prefix[] = add_submenu_page( $main_slug, __('Chatbot Form Builder', 'qcformbuilder-forms' ).' - ' . $form['name'], $form['name'], $capability, $this->plugin_slug . '-pin-' . $form_id, array( $this, 'render_admin' ) );
1129
1130 }
1131 }
1132 }
1133 }
1134
1135
1136 }
1137
1138 /**
1139 * Register and enqueue admin-specific style sheet.
1140 *
1141 * @return null
1142 */
1143 public function enqueue_admin_stylescripts() {
1144
1145 $screen = get_current_screen();
1146 Qcformbuilder_Forms_Render_Assets::register();
1147 Qcformbuilder_Forms_Admin_Assets::register_scripts();
1148 Qcformbuilder_Forms_Admin_Assets::register_styles();
1149
1150 wp_enqueue_style( $this->plugin_slug . '-admin-icon-styles', WFBCORE_URL . 'assets/css/dashicon.css', array(), self::VERSION );
1151
1152 add_action( 'qcformbuilder_forms_admin_enqueue_post_editor', ['Qcformbuilder_Forms_Admin_Assets', 'post_editor' ]);
1153 add_action( 'qcformbuilder_forms_admin_main_enqueue', ['Qcformbuilder_Forms_Admin_Assets', 'admin_common' ],1);
1154 add_action( 'qcformbuilder_forms_admin_enqueue_form_editor', ['Qcformbuilder_Forms_Admin_Assets', 'form_editor' ]);
1155
1156 /**
1157 * Runs directly before assets MIGHT be enqueued in the WordPress admin
1158 *
1159 * @since 1.7.3
1160 */
1161 do_action( 'qcformbuilder_forms_admin_pre_enqueue' );
1162 /**
1163 * Control if Qcformbuilder Forms assets run in post editor
1164 *
1165 * @since 1.5.7
1166 *
1167 * @param bool $use Return false to disable.
1168 * @param string $post_type Current post type
1169 */
1170 if ( $screen->base === 'post' && apply_filters( 'qcformbuilder_forms_insert_button_include', true, get_post_type() ) ) {
1171 /**
1172 * This action causes the assets Qcformbuilder Forms loads in the post editor to be enqueued
1173 *
1174 * @since 1.7.3
1175 */
1176 do_action( 'qcformbuilder_forms_admin_enqueue_post_editor' );
1177 }
1178
1179 if ( ! in_array( $screen->base, $this->screen_prefix ) ) {
1180 return;
1181 }
1182
1183 add_action( 'admin_head', array( __CLASS__, 'remove_notice_actions' ) );
1184 if( self::is_page( 'qcformbuilder-forms-extend' ) ){
1185 add_action( 'admin_enqueue_scripts', array( 'Qcformbuilder_Forms_Admin_Extend', 'scripts' ), 55 );
1186 return;
1187 }
1188
1189
1190 /**
1191 * This action causes the assets Qcformbuilder Forms loads in the main admin page to be enqueued
1192 *
1193 * @since 1.7.3
1194 */
1195 do_action( 'qcformbuilder_forms_admin_main_enqueue' );
1196
1197 if ( Qcformbuilder_Forms_Admin::is_edit() ) {
1198
1199 /**
1200 * This action causes the assets Qcformbuilder Forms loads in the form editor to be enqueued
1201 *
1202 * @since 1.7.3
1203 */
1204 do_action( 'qcformbuilder_forms_admin_enqueue_form_editor' );
1205
1206 } else {
1207 Qcformbuilder_Forms_Render_Assets::enqueue_all_fields();
1208 if ( ! empty( $_GET[ 'edit-entry' ] ) ) {
1209 Qcformbuilder_Forms_Render_Assets::enqueue_style('grid');
1210 }
1211 }
1212
1213 Qcformbuilder_Forms_Admin_Assets::panels();
1214
1215 }
1216
1217 /**
1218 * Renders the admin pages
1219 *
1220 */
1221 public function render_admin(){
1222
1223 echo " <div class=\"wrap\">\r\n";
1224 if(!empty($_GET['edit'])){
1225 echo "<form method=\"POST\" action=\"admin.php?page=" . $this->plugin_slug . "\" data-load-element=\"#save_indicator\" data-sender=\"ajax\" class=\"qcformbuilder-forms-options-form edit-update-trigger\">\r\n";
1226 include WFBCORE_PATH . 'ui/edit.php';
1227 echo "</form>\r\n";
1228 }elseif(!empty($_GET['page']) && $_GET['page'] == 'qcformbuilder-forms-extend'){
1229 include WFBCORE_PATH . 'ui/extend.php';
1230 }elseif(!empty($_GET['page']) && false !== strpos($_GET['page'], 'qcformbuilder-forms-pin-')){
1231 $formID = substr($_GET['page'], 18);
1232 $form = Qcformbuilder_Forms_Forms::get_form( $formID );
1233 include WFBCORE_PATH . 'ui/entries.php';
1234
1235 }else{
1236 add_action( 'qcformbuilder_forms_admin_footer', array( 'Qcformbuilder_Forms_Entry_Viewer', 'print_scripts' ) );
1237 include WFBCORE_PATH . 'ui/admin.php';
1238
1239 }
1240 echo " </div>\r\n";
1241
1242
1243
1244 }
1245
1246 /***
1247 * Handles form updating, deleting, exporting and importing
1248 *
1249 * @uses "init" action
1250 */
1251 static function save_form(){
1252 if( ! isset( $_GET[ 'page' ] ) || 'qcformbuilder-forms' != $_GET[ 'page' ] ){
1253 return;
1254 }
1255
1256 /// check for form delete
1257 if(!empty($_GET['delete']) && !empty($_GET['cal_del']) && current_user_can( Qcformbuilder_Forms::get_manage_cap( 'save' ), strip_tags( $_GET[ 'delete' ] ) ) ){
1258
1259 if ( ! wp_verify_nonce( $_GET['cal_del'], 'wfb_del_frm' ) ) {
1260 // This nonce is not valid.
1261 wp_die( __('Sorry, please try again', 'qcformbuilder-forms' ), __('Form Delete Error', 'qcformbuilder-forms' ) );
1262 }else{
1263 $deleted = Qcformbuilder_Forms_Forms::delete_form( strip_tags( $_GET['delete'] ) );
1264 if ( $deleted ) {
1265 wp_redirect( 'admin.php?page=qcformbuilder-forms' );
1266 exit;
1267 } else {
1268 wp_die( __('Form could not be deleted.', 'qcformbuilder-forms' ) );
1269 }
1270
1271 }
1272
1273 }
1274
1275 /** IMPORT */
1276 if( isset($_POST['cfimporter']) && current_user_can( Qcformbuilder_Forms::get_manage_cap( 'import' ) ) ){
1277
1278 if ( check_admin_referer( 'wfb-import', 'cfimporter' ) ) {
1279 if ( isset( $_FILES[ 'import_file' ] ) && ! empty( $_FILES[ 'import_file' ][ 'size' ] ) ) {
1280 $loc = wp_upload_dir();
1281 $temp_name = $_FILES[ 'import_file' ][ 'tmp_name' ];
1282 $name = $_FILES[ 'import_file' ][ 'name' ];
1283 $type_check = wp_check_filetype_and_ext($temp_name,$name, [
1284 'json' => 'application/json',
1285 ]);
1286 if( ! $type_check['type'] ){
1287 $type_check = wp_check_filetype_and_ext($temp_name,$name, [
1288 'json' => 'text/plain',
1289 ]);
1290 }
1291
1292 if( ! 'json' === $type_check[ 'ext'] ){
1293 wp_die( esc_html__( 'Form could not be imported. File type must be JSON.', 'qcformbuilder-forms' ) );
1294 }
1295
1296 $location = $loc[ 'path' ] . '/wfb-form-import.json';
1297 if ( move_uploaded_file( $temp_name, $location ) ) {
1298 $data = json_decode( file_get_contents($location ), true );
1299 unlink($location);
1300 if( ! is_array( $data ) ){
1301 wp_die( esc_html__( 'File is not a valid Qcformbuilder Form Import', 'qcformbuilder-forms' ) );
1302 }
1303 if( ! isset( $_POST[ 'name' ] ) ){
1304 wp_die( esc_html__( 'Form must have a name.', 'qcformbuilder-forms' ) );
1305 }
1306
1307 $data[ 'name' ] = strip_tags( $_POST[ 'name' ] );
1308 $trusted = isset( $_POST[ 'import_trusted' ] ) ? boolval( $_POST[ 'import_trusted' ] ) : false;
1309 $new_form_id = Qcformbuilder_Forms_Forms::import_form( $data, $trusted );
1310 if( is_string( $new_form_id ) ){
1311
1312 wfb_redirect( add_query_arg(array(
1313 'page' => 'qcformbuilder-forms',
1314 'edit' => $new_form_id,
1315 't' => $trusted
1316 ), admin_url( 'admin.php' ) ), 302 );
1317 exit;
1318
1319 }else{
1320 wp_die( esc_html__( 'Form could not be imported.', 'qcformbuilder-forms' ) );
1321 }
1322
1323
1324
1325
1326 }
1327 } else {
1328 wp_die( esc_html__( 'Sorry, File not uploaded.', 'qcformbuilder-forms' ), esc_html__( 'Form Import Error', 'qcformbuilder-forms' ) );
1329 }
1330
1331 } else {
1332
1333 wp_die( esc_html__( 'Sorry, please try again', 'qcformbuilder-forms' ), esc_html__( 'Form Import Error', 'qcformbuilder-forms' ) );
1334 }
1335
1336 }
1337
1338 if(!empty($_GET['export-form']) && current_user_can( Qcformbuilder_Forms::get_manage_cap( 'export', strip_tags( $_GET[ 'export-form' ] ) ) )){
1339
1340 $form = Qcformbuilder_Forms_Forms::get_form( $_GET['export-form'] );
1341
1342 if(empty($form)){
1343 wp_die( __('Form does not exist.', 'qcformbuilder-forms' ) );
1344 }
1345
1346 header("Pragma: public");
1347 header("Expires: 0");
1348 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
1349 header("Cache-Control: private",false);
1350 if( empty( $_GET['format'] ) || $_GET['format'] != 'php' ){
1351 header("Content-Type: application/json");
1352 header("Content-Disposition: attachment; filename=\"" . sanitize_file_name( strtolower( $form['name'] ) ) . "-export.json\";" );
1353 echo json_encode($form);
1354 }else{
1355
1356 $form_id = sanitize_key( $_GET['form_id'] );
1357 $form['_external_form'] = 1;
1358 if( !empty( $_GET['pin_menu'] ) ){
1359 $form['pinned'] = 1;
1360 }
1361 header("Content-Type: application/php");
1362 header("Content-Disposition: attachment; filename=\"" . sanitize_file_name( strtolower( $form_id ) ) . "-include.php\";" );
1363 echo '<?php' . "\r\n";
1364 echo "/**\r\n * Qcformbuilder Forms - PHP Export \r\n * {$form['name']} \r\n * @see https://quantumcloud.com/doc/exporting-qcformbuilder-forms/ \r\n * @version " . WFBCORE_VER . "\r\n * @license GPL-2.0+\r\n * \r\n */\r\n\r\n\r\n";
1365
1366 $callback_function = 'slug_register_qcformbuilder_forms_' . preg_replace("/[^A-Za-z0-9 ]/", '', $form_id);
1367
1368 $structure = sprintf( '
1369 /**
1370 * Hooks to load form.
1371 * Remove "qcformbuilder_forms_admin_forms" if you do not want this form to show in admin entry viewer
1372 */
1373 add_filter( "qcformbuilder_forms_get_forms", "%s" );
1374 add_filter( "qcformbuilder_forms_admin_forms", "%s" );
1375 /**
1376 * Add form to front-end and admin
1377 *
1378 * @param array $forms All registered forms
1379 *
1380 * @return array
1381 */
1382 function %s( $forms ) {
1383 $forms["%s"] = apply_filters( "qcformbuilder_forms_get_form-%s", array() );
1384 return $forms;
1385 };',
1386 $callback_function,
1387 $callback_function,
1388 $callback_function,
1389 $form_id,
1390 $form_id
1391 );
1392 $structure = ltrim($structure) . "\r\n\r\n";
1393
1394 $structure .= "/**\r\n * Filter form request to include form structure to be rendered\r\n *\r\n * @since 1.3.1\r\n *\r\n * @param \$form array form structure\r\n */\r\n";
1395 $structure .= "add_filter( 'qcformbuilder_forms_get_form-{$form_id}', function( \$form ){\r\n return " . var_export( $form, true ) . ";\r\n" . '} );' . "\r\n";
1396 // cleanups because I'm me
1397 $structure = str_replace( 'array (', 'array(', $structure );
1398 $structure = str_replace( $form['ID'], $form_id, $structure );
1399 // switch field IDs
1400 if( !empty( $_GET['convert_slugs'] ) ){
1401 if ( !empty( $form['fields'] ) ){
1402 foreach( $form['fields'] as $field_id=>$field ){
1403 $structure = str_replace( $field_id, $field['slug'], $structure );
1404 }
1405 }
1406 }
1407
1408 echo $structure;
1409 }
1410 exit;
1411
1412 }
1413
1414 if(!empty($_GET['export']) && current_user_can( Qcformbuilder_Forms::get_manage_cap( 'export', strip_tags( $_GET[ 'export' ] ) ) ) ){
1415
1416 $form = Qcformbuilder_Forms_Forms::get_form( $_GET['export'] );
1417
1418 global $wpdb;
1419
1420 //build labels
1421 $labels = array();
1422 $structure = array();
1423 $field_types = Qcformbuilder_Forms_Fields::get_all();
1424 $headers = array();
1425 if(!empty($form['fields'])){
1426 $headers['date_submitted'] = 'Submitted';
1427 foreach( Qcformbuilder_Forms_Forms::get_fields( $form, true ) as $field_id => $field ){
1428 if(isset($field_types[$field['type']]['capture']) && false === $field_types[$field['type']]['capture']){
1429 continue;
1430 }
1431 $headers[$field['slug']] = $field['label'];
1432 $structure[$field['slug']] = $field_id;
1433 }
1434 }
1435 $filter = null;
1436 // export set - transient
1437 if(!empty($_GET['tid'])){
1438 $items = Qcformbuilder_Forms_Transient::get_transient( $_GET[ 'tid' ] );
1439
1440 if(!empty($items)){
1441 Qcformbuilder_Forms_Transient::delete_transient( $_GET[ 'tid' ] );
1442 $filter = ' AND `entry`.`id` IN (' . implode(',', $items) . ') ';
1443 }else{
1444 wp_die( __('Export selection has expired', 'qcformbuilder-forms' ) , __('Export Expired', 'qcformbuilder-forms' ) );
1445 }
1446 }
1447
1448 $rawdata = $wpdb->get_results($wpdb->prepare("
1449 SELECT
1450 `entry`.`id` as `_entryid`,
1451 `entry`.`form_id` AS `_form_id`,
1452 `entry`.`datestamp` AS `_date_submitted`,
1453 `entry`.`user_id` AS `_user_id`
1454
1455 FROM `" . $wpdb->prefix ."wfb_form_entries` AS `entry`
1456
1457
1458 WHERE `entry`.`form_id` = %s
1459 " . $filter . "
1460 AND `entry`.`status` = 'active'
1461 ORDER BY `entry`.`datestamp` DESC;", Qcformbuilder_Forms_Sanitize::sanitize($_GET['export'])));
1462
1463
1464 $data = array();
1465
1466 $localize_time = Qcformbuilder_Forms_CSV_Util::should_localize_time( $form );
1467 foreach( $rawdata as $entry){
1468 $submission = Qcformbuilder_Forms::get_entry( $entry->_entryid, $form);
1469 if( $localize_time ){
1470 $data[$entry->_entryid]['date_submitted'] = Qcformbuilder_Forms::localize_time( $entry->_date_submitted, true );
1471 }else{
1472 $data[$entry->_entryid]['date_submitted'] = $entry->_date_submitted;
1473 }
1474
1475 foreach ($structure as $slug => $field_id) {
1476 $data[$entry->_entryid][$slug] = (
1477 isset( $submission['data'][$field_id]['view'] ) ? $submission['data'][$field_id]['view']
1478 : ( isset( $submission['data'][$field_id]['value'] ) ? $submission['data'][$field_id]['value'] : null )
1479 );
1480 }
1481
1482 }
1483
1484 if( empty( $headers ) ){
1485 wp_die( esc_html__( 'Could not process export. This is most likely due to a problem with the form configuration.', 'qcformbuilder-forms' ) );
1486 }
1487 $encoding = Qcformbuilder_Forms_CSV_Util::character_encoding( $form );
1488
1489 $file_type = Qcformbuilder_Forms_CSV_Util::file_type( $form );
1490
1491 header("Pragma: public");
1492 header("Expires: 0");
1493 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
1494 header("Cache-Control: private",false);
1495 header("Content-Type: text/csv charset=$encoding;");
1496 header("Content-Disposition: attachment; filename=\"" . sanitize_file_name( $form['name'] ) . ".$file_type\";" );
1497 header("Content-Transfer-Encoding: binary");
1498 $df = fopen("php://output", 'w');
1499
1500 if ( 'tsv' == $file_type ) {
1501 $delimiter = chr(9);
1502 } else {
1503 $delimiter = ',';
1504 }
1505 $csv_data = apply_filters( 'qcformbuilder_forms_admin_csv', array(
1506 'headers' => $headers,
1507 'data' => $data
1508 ), $form );
1509 $data = $csv_data[ 'data' ];
1510 $headers = $csv_data[ 'headers' ];
1511
1512 fputcsv($df, $headers, $delimiter);
1513 foreach($data as $row){
1514 $csvrow = array();
1515 foreach($headers as $key=>$label){
1516 if(!isset($row[$key])){
1517 $row[$key] = null;
1518 }else{
1519 if( is_array( $row[$key] ) && isset( $row[$key]['label'] ) ){
1520 $row[$key] = $row[$key]['value'];
1521 }elseif( is_array( $row[$key] ) ){
1522 $subs = array();
1523 foreach( $row[$key] as $row_part ){
1524 if( is_array( $row_part ) && isset( $row_part['label'] ) ){
1525 $subs[] = $row_part['value'];
1526 }else{
1527 if( is_string( $row_part ) && '{"opt' == substr( $row_part, 0, 5 ) ){
1528 continue;
1529 }
1530 $subs[] = $row_part;
1531 }
1532 }
1533 $row[$key] = implode(', ', $subs );
1534 }
1535 }
1536
1537 $csvrow[] = $row[$key];
1538 }
1539 fputcsv($df, $row, $delimiter);
1540 }
1541 fclose($df);
1542 exit;
1543 }
1544
1545 if( isset($_POST['config']) && isset( $_POST['wfb_edit_nonce'] ) && current_user_can( Qcformbuilder_Forms::get_manage_cap( 'manage' ) ) ){
1546
1547 // if this fails, check_admin_referer() will automatically print a "failed" page and die.
1548 if ( check_admin_referer( 'wfb_edit_element', 'wfb_edit_nonce' ) ) {
1549
1550 // strip slashes
1551 $data = json_decode( stripslashes_deep($_POST['config']) , ARRAY_A );
1552 self::save_a_form( $data );
1553
1554 if(!empty($_POST['sender'])){
1555 exit;
1556 }
1557
1558 wp_redirect('admin.php?page=qcformbuilder-forms');
1559 die;
1560
1561 }
1562 return;
1563 }
1564
1565 /** Resotre revisions */
1566 if( isset( $_POST[ 'wfb_edit_nonce' ], $_POST[ self::REVISION_KEY ], $_POST[ 'form' ], $_POST[ 'restore' ] ) ){
1567 if( ! current_user_can( Qcformbuilder_Forms::get_manage_cap( 'manage' ) ) || ! wp_verify_nonce( $_POST[ 'wfb_edit_nonce' ], 'wfb_edit_element' ) ){
1568 wp_send_json_error();
1569
1570 }
1571 $restored = Qcformbuilder_Forms_Forms::restore_revision( absint( $_POST[ self::REVISION_KEY ] ));
1572 if( $restored ){
1573 wp_send_json_success();
1574 }else{
1575 wp_send_json_error();
1576 }
1577
1578 exit;
1579 }
1580 }
1581
1582 /**
1583 * Save a form
1584 *
1585 * @since 1.3.4
1586 *
1587 * @param array $data
1588 */
1589 public static function save_a_form( $data ){
1590 $saved_form = Qcformbuilder_Forms_Forms::get_form( $data['ID'] );
1591 if( ! empty( $saved_form ) && isset( $saved_form[ 'fields' ] ) ){
1592 $extra_fields = self::get_editor_extra_fields($saved_form );
1593 $form = new Qcformbuilder_Forms_API_Privacy($data);
1594 if( isset( $extra_fields['email_identifying_fields'] ) ){
1595 $form->set_email_identifying_fields( $extra_fields['email_identifying_fields'] );
1596 }
1597 if( isset( $extra_fields['personally_identifying_fields'] ) ){
1598 $form->set_pii_fields( $extra_fields['personally_identifying_fields'] );
1599 }
1600
1601 $data = $form->get_form();
1602 if( isset( $extra_fields['is_privacy_export_enabled'] ) ){
1603 $data = Qcformbuilder_Forms_Forms::update_privacy_export_enabled( $data, boolval($extra_fields['is_privacy_export_enabled']));
1604 }
1605 }
1606
1607 Qcformbuilder_Forms_Forms::save_form( $data );
1608
1609 }
1610
1611
1612 /**
1613 * Get the additional fields of form that are not used in the editor
1614 *
1615 * @since 1.7.1
1616 *
1617 * @param array $form Form config to get saved field values from
1618 * @return array
1619 */
1620 public static function get_editor_extra_fields(array $form )
1621 {
1622 return array_merge(
1623 [
1624 'email_identifying_fields' => Qcformbuilder_Forms_Forms::email_identifying_fields($form, true ),
1625 'personally_identifying_fields' => Qcformbuilder_Forms_Forms::personally_identifying_fields($form,true),
1626 'is_privacy_export_enabled' => Qcformbuilder_Forms_Forms::is_privacy_export_enabled($form),
1627 ],
1628 /**
1629 * Add additional fields to the non-editor fields
1630 *
1631 * These values will be saved with the form, unedited.
1632 *
1633 * @since 1.7.0
1634 *
1635 * @param array $field Extra fields.
1636 */
1637 apply_filters( 'qcformbuilder_forms_editor_extra_fields', [] )
1638
1639 );
1640 }
1641
1642 /**
1643 * AJAX callback for new form creation
1644 *
1645 * @since unknown
1646 *
1647 * @uses "wp_ajax_create_form" action
1648 */
1649 public static function create_form(){
1650 $nonce_validated = false;
1651 if( isset( $_POST[ 'nonce' ] ) && wp_verify_nonce( $_POST[ 'nonce'], 'wfb_create_form' ) ){
1652 $nonce_validated = true;
1653 }
1654
1655 parse_str( $_POST['data'], $newform );
1656
1657
1658 if( ! $nonce_validated ){
1659 if( isset( $newform, $newform[ 'nonce' ] ) ) {
1660 if( wp_verify_nonce( $newform[ 'nonce' ], 'wfb_create_form' ) ){
1661 $nonce_validated = true;
1662 }
1663 }
1664
1665 }
1666
1667 if( ! $nonce_validated ){
1668 status_header(500);
1669 wp_send_json_error( );
1670 }
1671 $newform = Qcformbuilder_Forms_Forms::create_form( $newform );
1672 echo $newform['ID'];
1673 exit;
1674
1675
1676 }
1677
1678
1679 /**
1680 * Set panels to be used in Qcformbuilder Forms form editor
1681 *
1682 * @since unknown
1683 *
1684 * @uses "qcformbuilder_forms_get_panel_extensions" fitler
1685 *
1686 * @param array $panels
1687 *
1688 * @return array
1689 */
1690 public function get_panel_extensions($panels){
1691
1692 $path = WFBCORE_PATH . "ui/panels/";
1693
1694 $internal_panels = array(
1695 'form_layout' => array(
1696 "name" => __( 'Layout', 'qcformbuilder-forms' ),
1697 "setup" => array(
1698 "scripts" => array(
1699 'jquery-ui-sortable',
1700 'jquery-ui-draggable',
1701 'jquery-ui-droppable',
1702 ),
1703 "styles" => array(
1704 WFBCORE_URL . "assets/css/editor-grid.css",
1705 WFBCORE_URL . "assets/css/processors-edit.css"
1706 ),
1707 ),
1708 "tabs" => array(
1709 "layout" => array(
1710 "name" => __( 'Layout', 'qcformbuilder-forms' ),
1711 "location" => "lower",
1712 "label" => __( 'Layout', 'qcformbuilder-forms' ),
1713 "active" => true,
1714 "actions" => array(
1715 $path . "layout_toolbar.php"
1716 ),
1717 "repeat" => 0,
1718 "canvas" => $path . "layout.php",
1719 "side_panel" => $path . "layout_side.php",
1720
1721 ),
1722 /*
1723 "pages" => array(
1724 "name" => __( 'Pages', 'qcformbuilder-forms' ),
1725 "location" => "lower",
1726 "label" => __( 'Form Pages', 'qcformbuilder-forms' ),
1727 "canvas" => $path . "pages.php",
1728 'tip' => array(
1729 'link' => 'https://quantumcloud.com/doc/using-multi-page-forms/?utm_source=wp-admin&utm_medium=form-editor&utm_term=tabs',
1730 'text' => __( 'Using multi-page forms.', 'qcformbuilder-forms' ),
1731 )
1732 ),
1733 */
1734 "mailer" => array(
1735 "name" => __( 'Email', 'qcformbuilder-forms' ),
1736 "location" => "lower",
1737 "label" => __( 'Email Notification Settings', 'qcformbuilder-forms' ),
1738 "canvas" => $path . "emailer.php",
1739 'tip' => array()
1740 ),
1741 "processors" => array(
1742 "name" => __( 'Processors', 'qcformbuilder-forms' ),
1743 "location" => "lower",
1744 "label" => __( 'Form Processors', 'qcformbuilder-forms' ),
1745 "canvas" => $path . "processors.php",
1746 'tip' => array()
1747 ),
1748 /*
1749 "antispam" => array(
1750 "name" => __( 'Anti-Spam', 'qcformbuilder-forms' ),
1751 "location" => "lower",
1752 "label" => __( 'Anti Spam', 'qcformbuilder-forms' ),
1753 "canvas" => $path . "anti-spam.php",
1754 'tip' => array(
1755 'link' => 'https://quantumcloud.com/doc/protect-form-spam-qcformbuilder-forms/?utm_source=wp-admin&utm_medium=form-editor&utm_term=tabs',
1756 'text' => __( 'Anti-spam documentation', 'qcformbuilder-forms' )
1757 )
1758 ),
1759 */
1760 "conditions" => array(
1761 "name" => __( 'Conditions', 'qcformbuilder-forms' ),
1762 "location" => "lower",
1763 "label" => __( 'Conditions', 'qcformbuilder-forms' ),
1764 "canvas" => $path . "conditions.php",
1765 'tip' => array()
1766 ),
1767
1768 "variables" => array(
1769 "name" => __( 'Variables', 'qcformbuilder-forms' ),
1770 "location" => "lower",
1771 "label" => __( 'Variables', 'qcformbuilder-forms' ),
1772 "canvas" => $path . "variables.php",
1773 "actions" => array(
1774 $path . "variable_add.php"
1775 ),
1776 'tip' => array()
1777 ),
1778 "revisions" => array(
1779 "name" => __( 'Revisions', 'qcformbuilder-forms' ),
1780 "location" => "lower",
1781 "label" => __( 'Revisions', 'qcformbuilder-forms' ),
1782 "canvas" => $path . "revisions.php",
1783
1784 ),
1785 /*
1786 "responsive" => array(
1787 "name" => __( 'Responsive', 'qcformbuilder-forms' ),
1788 "location" => "lower",
1789 "label" => __( 'Responsive Settings', 'qcformbuilder-forms' ),
1790 "repeat" => 0,
1791 "fields" => array(
1792 "break_point" => array(
1793 "label" => __( 'Grid Collapse', 'qcformbuilder-forms' ),
1794 "slug" => "break_point",
1795 "caption" => __( 'Set the smallest screen size at which to collapse the grid. (based on Bootstrap 3.0)', 'qcformbuilder-forms' ),
1796 "type" => "radio",
1797 "config" => array(
1798 "default" => "sm",
1799 "option" => array(
1800 "xs" => array(
1801 'value' => 'xs',
1802 'label' => __('Maintain grid always', 'qcformbuilder-forms' ),
1803 ),
1804 "sm" => array(
1805 'value' => 'sm',
1806 'label' => '< 767px'
1807 ),
1808 "md" => array(
1809 'value' => 'md',
1810 'label' => '< 991px'
1811 ),
1812 "lg" => array(
1813 'value' => 'lg',
1814 'label' => '< 1199px'
1815 )
1816 )
1817 ),
1818 )
1819 ),
1820 'tip' => array(
1821 'link' => 'https://quantumcloud.com/doc/configure-responsive-settings/?utm_source=wp-admin&utm_medium=form-editor&utm_term=tabs',
1822 'text' => __( 'Responsive settings getting started guide', 'qcformbuilder-forms' )
1823 )
1824
1825 ),
1826 */
1827 ),
1828 ),
1829 );
1830
1831
1832 if( self::is_revision_edit() ){
1833 unset( $internal_panels[ 'revisions' ] );
1834 }
1835
1836
1837
1838 return array_merge( $panels, $internal_panels );
1839
1840 }
1841
1842 /**
1843 * Add to the admin notices
1844 *
1845 * @since 1.3.0
1846 *
1847 * @param string|array $notice The notice or array of notices to add.
1848 */
1849 public static function add_admin_notice( $notice ) {
1850 if ( is_string( $notice ) ) {
1851 self::$admin_notices[] = $notice;
1852 }
1853
1854 if ( is_array( $notice ) ) {
1855 foreach( $notice as $n) {
1856 self::add_admin_notice( $n );
1857 }
1858
1859 }
1860
1861 }
1862
1863 /**
1864 * Get the admin messages
1865 *
1866 * @since 1.3
1867 *
1868 * @param bool $as_string Optional. To return as string, the default, or as an array
1869 * @param string $seperator Optional. What to break notices with, when returning as string. Default is "\n"
1870 *
1871 * @return string|array|void
1872 */
1873 public static function get_admin_notices( $as_string = true, $seperator = "\n" ) {
1874 if ( ! empty( self::$admin_notices ) ) {
1875 if ( $as_string ) {
1876 return implode( $seperator, self::$admin_notices );
1877
1878 }else{
1879 return self::$admin_notices;
1880
1881 }
1882
1883 }
1884
1885 }
1886
1887 /**
1888 * Create an admin notice
1889 *
1890 * @since 1.3.4
1891 *
1892 * @param $title
1893 * @param $content
1894 */
1895 public static function create_admin_notice( $title, $content, $sanitize = true ){
1896 if( $sanitize ) {
1897 $content = wp_kses( $content, wp_kses_allowed_html( 'post' ) );
1898 }
1899 ?>
1900 <div
1901 class="ajax-trigger"
1902 data-modal="wfb-admin-notice"
1903 data-modal-title="<?php echo esc_html( $title ); ?>"
1904 data-template="#<?php echo esc_attr( sanitize_key( 'admin-modal' . $title ) ); ?>"
1905 data-modal-height="300"
1906 data-modal-width="650"
1907 data-autoload="true"
1908 >
1909 </div>
1910 <script type="text/html" id="<?php echo esc_attr( sanitize_key('admin-modal' . $title ) ); ?>">
1911 <?php echo $content; ?>
1912 </script>
1913 <?php
1914 }
1915
1916 /**
1917 * Add Easy Pods as an auto-populate option in admin
1918 *
1919 * @since 1.4.3
1920 *
1921 * @uses "qcformbuilder_forms_prerender_edit" action
1922 */
1923 public static function easy_pods_auto_populate(){
1924 if( version_compare( phpversion(), '5.3.0', '>=' ) ){
1925 if( class_exists( 'Qcformbuilder_Easy_Pods' ) ){
1926 new Qcformbuilder_Forms_Admin_APEasyPods;
1927 }
1928
1929 if( defined( 'CAEQ_PATH' ) ){
1930 new Qcformbuilder_Forms_Admin_APEasyQueries;
1931 }
1932 }
1933
1934 }
1935
1936 /**
1937 * Remove hooks for admin notices while in Qcformbuilder Forms admin
1938 *
1939 * Qcformbuilder Forms admin does not play nice with admin notices, so we use a series of steps to remove most of them, sadly can not beat them all.
1940 *
1941 * @since 1.4.7
1942 * @uses "admin_head" action
1943 */
1944 public static function remove_notice_actions(){
1945 remove_all_actions( 'admin_notices' );
1946 remove_all_actions( 'network_admin_notices' );
1947 remove_all_actions( 'user_admin_notices' );
1948 remove_all_actions( 'all_admin_notices' );
1949 }
1950
1951 /**
1952 * Check if is a Qcformbuilder Forms page
1953 *
1954 * @since 1.5.0.9
1955 *
1956 * @param null|string $page Optional. Pass page name (get var) for sub page
1957 *
1958 * @return bool
1959 */
1960 public static function is_page( $page = null ){
1961 if( is_admin() && isset( $_GET[ 'page' ] ) ){
1962 if( is_null( $page ) ){
1963 return Qcformbuilder_Forms::PLUGIN_SLUG == $_GET[ 'page' ];
1964 }elseif ( is_string( $page ) ){
1965 return $page == $_GET[ 'page' ];
1966 }
1967 }
1968
1969 return false;
1970 }
1971
1972 /**
1973 * Check if is form editor page
1974 *
1975 * @since 1.5.0.9
1976 *
1977 * @return bool
1978 */
1979 public static function is_edit(){
1980 return Qcformbuilder_Forms_Admin::is_page() && isset( $_GET[ self::EDIT_KEY ] );
1981
1982 }
1983
1984 /**
1985 * Check if is form revision edit page
1986 *
1987 * @since 1.5.0.9
1988 *
1989 * @return bool
1990 */
1991 public static function is_revision_edit(){
1992 return self::is_edit() && isset( $_GET[ self::REVISION_KEY ] ) && is_numeric( $_GET[ self::REVISION_KEY ] );
1993 }
1994
1995 /**
1996 * Check if is main admin page
1997 *
1998 * @since 1.5.0.9
1999 *
2000 * @return bool
2001 */
2002 public static function is_main_page(){
2003 return Qcformbuilder_Forms_Admin::is_page() && ! isset( $_GET[ self::EDIT_KEY ] );
2004
2005 }
2006
2007 /**
2008 * Get URL for main admin page
2009 *
2010 * @since 1.5.2
2011 *
2012 * @param string|bool $orderby Optional. If valid string ("name") then that is appended as orderby. Default is false, which does nothing, default link.
2013 *
2014 * @return string
2015 */
2016 public static function main_admin_page_url( $orderby = false ){
2017 $url = add_query_arg( 'page', Qcformbuilder_Forms::PLUGIN_SLUG, admin_url( 'admin.php' ) );
2018 if( 'name' === $orderby ){
2019 $url = add_query_arg( self::ORDERBY_KEY, 'name', $url );
2020 }
2021
2022 return $url;
2023 }
2024
2025 /**
2026 * Get link for form editor
2027 *
2028 * @since 1.5.3
2029 *
2030 * @param string $form_id ID of form to edit
2031 * @param int $revision_id Optional The ID of the revision to edit if editing a revision
2032 *
2033 * @return string
2034 */
2035 public static function form_edit_link( $form_id, $revision_id = false ){
2036 $args = array(
2037 self::EDIT_KEY => $form_id,
2038 'page' => Qcformbuilder_Forms::PLUGIN_SLUG
2039 );
2040
2041 if( $revision_id ){
2042 $args[ self::REVISION_KEY ] = $revision_id;
2043 }
2044
2045 return add_query_arg( $args, admin_url( 'admin.php' ) );
2046 }
2047
2048 /**
2049 * @param $form_id
2050 * @param bool $revision_id
2051 *
2052 * @return string
2053 */
2054 public static function preview_link( $form_id, $revision_id = false ){
2055 $args = array(
2056 self::PREVIEW_KEY => $form_id
2057 );
2058 if( $revision_id ){
2059 $args[ self::REVISION_KEY ] = $revision_id;
2060 }
2061
2062 return add_query_arg( $args, get_home_url() );
2063 }
2064
2065 /**
2066 * Prevent re-sending email on form edit
2067 *
2068 * @uses "qcformbuilder_forms_send_email" filter
2069 *
2070 * @param bool $send
2071 *
2072 * @return bool
2073 */
2074 public static function block_email_on_edit( $send ){
2075 if( isset( $_POST, $_POST[ '_wfb_frm_edt' ] ) && 0 < absint( $_POST[ '_wfb_frm_edt' ] ) ){
2076 return false;
2077 }
2078
2079 return $send;
2080 }
2081
2082 /**
2083 * Setup privacy settings
2084 *
2085 * @since 1.6.1
2086 *
2087 * @uses "qcformbuilder_forms_admin_init" action
2088 */
2089 public static function init_privacy_settings()
2090 {
2091 /*Qcformbuilder_Forms_Admin_Factory::menu_page('privacy', __('Privacy Settings', 'qcformbuilder-forms'), '<div id="qcformbuilder-forms-privacy-settings"></div>', [
2092 'scripts' => [
2093 'privacy',
2094 'admin',
2095
2096 ],
2097 'styles' => [
2098 'editor-grid'
2099 ]
2100 ]);*/
2101
2102 }
2103
2104
2105 /**
2106 * Return the default suggested privacy policy content.
2107 *
2108 * @since 1.7.0
2109 *
2110 * @return string The default policy content.
2111 */
2112 protected static function core_privacy_content() {
2113 return
2114 '<h2>' . esc_html__( 'Qcformbuilder Forms: Data Collection', 'qcformbuilder-forms') . '</h2>' .
2115 '<em>' . esc_html__( 'Suggested Text (if you have entry tracking enabled) -', 'qcformbuilder-forms' ) . '</em>' .
2116 '<p>' . esc_html__( 'Qcformbuilder Forms stores a record of all form submissions. Your data may be deleted by the site administrator. You may request a report of saved data related to your email address.', 'qcformbuilder-forms' ) . '</p>' .
2117 '<em>' . esc_html__( 'Suggested Text (if you do not have entry tracking enabled) -', 'qcformbuilder-forms' ) . '</em>' .
2118 '<p>' . esc_html__( 'Qcformbuilder Forms stores data only briefly for each submission. Uploaded media files may remain on the server' ) . '</p>' .
2119 '<em>' . esc_html__( 'Suggested Text (if you use add-ons that interact with third party services) -', 'qcformbuilder-forms' ) . '</em>' .
2120 '<p>' . esc_html__( 'Some data may be shared with other services including [list services such as MailChimp, PayPal]', 'qcformbuilder-forms' ) . '</p>';
2121 }
2122
2123 /**
2124 * Return the default suggested privacy policy content for Qcformbuilder Forms Pro.
2125 *
2126 * @since 1.7.0
2127 *
2128 * @return string The default policy content.
2129 */
2130 protected static function pro_privacy_content() {
2131 return
2132 '<h2>' . esc_html__( 'Qcformbuilder Forms Pro: Data Collection', 'qcformbuilder-forms') . '</h2>' .
2133 '<p>' . esc_html__( 'This site uses a third-party service to deliver some emails.', 'qcformbuilder-forms' ) . '</p>' .
2134 '<p>' . esc_html__( 'This data will be stored on servers controlled by CalderaWP LLC, the makers of Qcformbuilder Forms, and operated by Linode and Amazon Web Services. Meta data about emails will be stored by SendGrid and Amazon Web Services', 'qcformbuilder-forms' ) . '</p>';
2135 '<p>' . esc_html__( 'If you request that personal data shared with this site is deleted, the corresponding data shared with QcformbuilderWP will also be deleted when the request is fulfilled.', 'qcformbuilder-forms' ) . '</p>';
2136 }
2137
2138
2139
2140 /**
2141 * Add the suggested privacy policy text to the policy postbox.
2142 *
2143 * @uses "qcformbuilder_forms_admin_init" action
2144 *
2145 * @since 1.7.0
2146 */
2147 public static function add_suggested_privacy_content() {
2148 if( function_exists( 'wp_add_privacy_policy_content' ) ){
2149 wp_add_privacy_policy_content( esc_html__( 'Qcformbuilder Forms', 'qcformbuilder-forms' ), self::core_privacy_content() );
2150 if ( qcformbuilder_forms_pro_is_active() ) {
2151 wp_add_privacy_policy_content(esc_html__('Qcformbuilder Forms Pro', 'qcformbuilder-forms'), self::pro_privacy_content());
2152 }
2153 }
2154 }
2155
2156
2157
2158 }
2159
2160
2161