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 / render / modals.php

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

188 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 /**
5 * Methods for creating Qcformbuilder Forms in modals
6 *
7 * @package Caldera_Forms Modified by QuantumCloud
8 * @author Josh Pollock <Josh@CalderaWP.com>
9 * @license GPL-2.0+
10 * @link
11 * @copyright 2017 CalderaWP LLC
12 */
13 class Qcformbuilder_Forms_Render_Modals {
14
15 /**
16 * Holds modal HTML to be loaded in footer
17 *
18 * @since 1.5.0.7
19 * since 1.4.2 in Qcformbuilder_Forms
20 *
21 * @var string
22 */
23 protected static $footer_modals;
24
25 /**
26 * Load a Qcformbuilder Form in a modal.
27 *
28 * @since 1.5.0.7
29 * since unknown in Calder_Forms
30 *
31 * @param string|array $atts Shortcode atts or form ID
32 * @param string $content Content to use in trigger link.
33 *
34 * @return string
35 */
36 public static function modal_form( $atts, $content, $is_revision = false ) {
37
38 if ( empty( $atts[ 'id' ] ) ) {
39 return $content;
40 }
41 if ( ! $is_revision ) {
42 $form = Qcformbuilder_Forms_Forms::get_form( $atts[ 'id' ] );
43 }else{
44 $form = $atts;
45 }
46
47 if ( empty( $form[ 'ID' ] ) || $form[ 'ID' ] != $atts[ 'id' ] ) {
48 return $content;
49 }
50
51 $modal_id = self::modal_id( $form );
52
53 $out = self::modal_button( $atts, $content, $form, $modal_id );
54
55 if(!empty($_GET['wfb_er'])){
56 $transdata = Qcformbuilder_Forms_Transient::get_transient( $_GET[ 'wfb_er' ] );
57 if($transdata['transient'] == $_GET['wfb_er']){
58 $current_state = 'style="display:block;"';
59 }
60 }
61 if ( ! empty( $_GET[ 'wfb_su' ] ) ) {
62 // disable notices
63 unset( $_GET[ 'wfb_su' ] );
64 }
65
66 $form_html = Qcformbuilder_Forms::render_form( $atts );
67
68 self::add_to_footer( self::modal_body( $form_html, $modal_id, $atts[ 'id' ] ) );
69
70 return $out;
71 }
72
73 /**
74 * Create modal body
75 *
76 * @since 1.5.0.7
77 *
78 * @param string $form_html HTML for modal body
79 * @param string $modal_id ID attribute for modal Should be created with self::modal_id()
80 * @param string $classes Optional. Additional classes for the modal. "remodal qcformbuilder-front-modal-container" are always applied
81 *
82 * @return string
83 */
84 public static function modal_body( $form_html, $modal_id, $form_id, $classes = '' ){
85 $class_attr = 'remodal qcformbuilder-front-modal-container';
86 if( ! empty( $classes ) ){
87 $class_attr .= $classes;
88 }
89
90 ob_start();
91 ?>
92 <div data-remodal-id="<?php echo esc_attr( $modal_id ); ?>" id="<?php echo esc_attr( $modal_id ); ?>" class="<?php echo esc_attr( $class_attr ); ?>" data-form-id="<?php echo esc_attr( $form_id ); ?>" data-remodal-options="hashTracking: true, closeOnOutsideClick: false">
93 <button data-remodal-action="close" class="remodal-close"></button>
94 <div class="qcformbuilder-modal-body qcformbuilder-front-modal-body" id="<?php echo $modal_id; ?>_modal_body">
95 <?php echo $form_html ?>
96 </div>
97 </div>
98
99 <?php
100 Qcformbuilder_Forms_Render_Assets::enqueue_modals();
101
102 return ob_get_clean();
103 }
104
105 /**
106 * Add modal to footer
107 *
108 * @since 1.5.0.7
109 *
110 * @param $html
111 */
112 public static function add_to_footer( $html ){
113 self::$footer_modals .= $html;
114 }
115
116 /**
117 * Print modal content in footer.
118 *
119 * @since 1.5.0.7
120 * since unknown in Qcformbuilder_Forms
121 *
122 * @uses "wp_footer"
123 */
124 public static function render_footer_modals() {
125 $footer_modals = self::$footer_modals;
126 if ( ! empty( $footer_modals ) && is_string( $footer_modals ) ) {
127 echo $footer_modals;
128 }
129
130 }
131
132
133 /**
134 * Create a modal button's HTML
135 *
136 * @since 1.5.0.7
137 * since 1.5.0.4 in Qcformbuilder_Forms
138 *
139 * @param array $atts Form atts Form atts for Qcformbuilder_Forms::render_form()
140 * @param string $content Content for opener
141 * @param array $form Form config
142 * @param string|null $modal_id Optional, modal ID. self::modal_id() will be used if empty.
143 *
144 * @return string
145 */
146 public static function modal_button( $atts, $content, $form, $modal_id = null ){
147 if( ! $modal_id ){
148 $modal_id = self::modal_id( $form );
149 }
150 if ( empty( $content ) ) {
151 $content = $form[ 'name' ];
152 }
153
154 $tag_atts = sprintf( 'data-form="%1s"', $form[ 'ID' ] );
155
156 if ( ! empty( $atts[ 'width' ] ) ) {
157 $tag_atts .= sprintf( ' data-width="%1s"', $atts[ 'width' ] );
158 }
159 if ( ! empty( $atts[ 'height' ] ) ) {
160 $tag_atts .= sprintf( ' data-height="%1s"', $atts[ 'height' ] );
161 }
162
163
164 $title = sprintf( __( 'Click to open the form %s in a modal', 'qcformbuilder-forms' ), $form[ 'name' ] );
165 if ( ! empty( $atts[ 'type' ] ) && $atts[ 'type' ] == 'button' ) {
166 $tag_atts .= sprintf( 'data-remodal-target="%1s"', $modal_id );
167 return sprintf( '<button class="qcformbuilder-forms-modal" %s title="%s">%s</button>', $tag_atts, $title, $content );
168 } else {
169 return sprintf( '<a href="%s" class="qcformbuilder-forms-modal" %s title="%s">%s</a>', '#' . $modal_id, $tag_atts, esc_attr( $title ), $content );
170 }
171 }
172
173 /**
174 * Create a modal ID
175 *
176 * @since 1.5.0.7
177 *
178 * @param $form
179 *
180 * @return string
181 */
182 public static function modal_id( $form ){
183 $modal_id = 'wfb-modal-' . uniqid( $form[ 'ID' ] );
184
185 return $modal_id;
186 }
187
188 }