PluginProbe ʕ •ᴥ•ʔ
Strong Testimonials / 3.2.8
Strong Testimonials v3.2.8
3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.0.1 2.30.9 2.31.10 2.32 2.32.1 2.32.2 2.32.3 2.32.4 2.33 2.34 2.35 2.36 2.37 2.38 2.38.1 2.39 2.39.1 2.39.2 2.39.3 2.40.0 2.40.1 2.40.2 2.40.3 2.40.4 2.40.5 2.40.6 2.40.7 2.41.0 2.41.1 2.50.0 2.50.1 2.50.2 2.50.3 2.50.4 2.51.0 2.51.1 2.51.2 2.51.3 2.51.4 2.51.5 2.51.6 2.51.7 2.51.8 2.51.9 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.20 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.17 3.2.18 3.2.19 3.2.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0
strong-testimonials / includes / class-strong-view-form.php
strong-testimonials / includes Last commit date
elementor 1 year ago logs 1 year ago strong-testimonials-beaver-block 1 year ago submodules 1 year ago class-strong-gutemberg.php 1 year ago class-strong-log.php 1 year ago class-strong-mail.php 1 year ago class-strong-testimonials-average-shortcode.php 1 year ago class-strong-testimonials-count-shortcode.php 1 year ago class-strong-testimonials-form.php 1 year ago class-strong-testimonials-order.php 1 year ago class-strong-testimonials-privacy.php 1 year ago class-strong-testimonials-render.php 1 year ago class-strong-testimonials-templates.php 1 year ago class-strong-testimonials-view-shortcode.php 1 year ago class-strong-testimonials-view-widget.php 1 year ago class-strong-view-display.php 1 year ago class-strong-view-form.php 1 year ago class-strong-view-slideshow.php 1 year ago class-strong-view.php 1 year ago class-walker-strong-category-checklist-front.php 1 year ago deprecated.php 1 year ago filters.php 1 year ago functions-activation.php 1 year ago functions-content.php 1 year ago functions-image.php 1 year ago functions-rating.php 1 year ago functions-template-form.php 1 year ago functions-template.php 1 year ago functions-views.php 1 year ago functions.php 1 year ago l10n-polylang.php 1 year ago l10n-wpml.php 1 year ago post-types.php 1 year ago retro.php 1 year ago scripts.php 1 year ago
class-strong-view-form.php
258 lines
1 <?php
2 /**
3 * Class Strong_View_Form
4 *
5 * @since 2.16.0
6 */
7
8 // Exit if accessed directly
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 if ( ! class_exists( 'Strong_View_Form' ) ) :
14
15 class Strong_View_Form extends Strong_View {
16
17 /**
18 * Strong_View_Form constructor.
19 *
20 * @param array $atts
21 */
22 public function __construct( $atts = array() ) {
23 parent::__construct( $atts );
24 }
25
26 /**
27 * Process the view.
28 *
29 * Used by main class to load the scripts and styles for this View.
30 */
31 public function process() {
32 $this->build_classes();
33 $this->find_stylesheet();
34 $this->load_dependent_scripts();
35 $this->load_extra_stylesheets();
36 $this->load_validator();
37
38 // If we can preprocess, we can add the inline style in the <head>.
39 add_action( 'wp_enqueue_scripts', array( $this, 'add_custom_style' ), 20 );
40 }
41
42 /**
43 * Print overlay while form data is submitted.
44 *
45 * This helps when uploading large files and on slow connections.
46 *
47 * @since 2.31.5
48 */
49 public function print_overlay() {
50 if ( apply_filters( 'wpmtst_form_wait', true ) ) {
51 ?>
52 <div class="strong-form-wait" data-formid="<?php echo esc_attr( WPMST()->atts( 'form_id' ) ); ?>">
53 <div class="message">
54 <?php echo wp_kses_post( apply_filters( 'wpmtst_form_wait_message', '<img src="' . WPMTST_PUBLIC_URL . 'svg/spinner-solid.svg" alt="' . esc_attr__( 'Strong Testimonials form submission spinner.', 'strong-testimonials' ) . '" >' ) ); ?>
55 </div>
56 </div>
57 <?php
58 }
59 }
60
61 /**
62 * Load resources on form success.
63 *
64 * When using normal form submission (not Ajax)
65 * and displaying a success message (not redirecting).
66 */
67 public function success() {
68 $form_options = get_option( 'wpmtst_form_options' );
69
70 // Remember: top level is converted to strings!
71 $args = array(
72 'display' => array(
73 'successMessage' => true,
74 ),
75 'scroll' => array(
76 'onSuccess' => $form_options['scrolltop_success'],
77 'onSuccessOffset' => $form_options['scrolltop_success_offset'],
78 ),
79 );
80
81 WPMST()->render->add_script( 'wpmtst-form-validation' );
82 WPMST()->render->add_script_var( 'wpmtst-form-validation', 'strongForm', $args );
83
84 $this->find_stylesheet();
85 $this->html = wpmtst_get_success_message( $this->atts );
86
87 do_action( 'wpmtst_form_success', $this->atts );
88 }
89
90 /**
91 * Build the view.
92 */
93 public function build() {
94
95 do_action( 'wpmtst_view_build_before', $this );
96
97 $this->build_classes();
98 $this->find_stylesheet();
99 $this->load_dependent_scripts();
100 $this->load_extra_stylesheets();
101 $this->custom_background();
102 $this->load_validator();
103
104 // If we cannot preprocess, add the inline style to the footer.
105 add_action( 'wp_footer', array( $this, 'add_custom_style' ) );
106
107 $form_values = isset( $this->atts['category'] ) ? array( 'category' => $this->atts['category'] ) : array();
108
109 $fields = isset( $this->atts['form_id'] ) ? wpmtst_get_form_fields( $this->atts['form_id'] ) : false;
110 if ( $fields ) {
111 foreach ( $fields as $field ) {
112 $form_values[ $field['name'] ] = '';
113 }
114 }
115
116 $previous_values = WPMST()->form->get_form_values();
117 if ( $previous_values ) {
118 $form_values = array_merge( $form_values, $previous_values );
119 }
120
121 WPMST()->form->set_form_values( $form_values );
122
123 /**
124 * Add filters here.
125 */
126 add_action( 'wpmtst_before_form', array( $this, 'print_overlay' ) );
127
128 /**
129 * Locate template.
130 */
131 $this->template_file = apply_filters( 'wpmtst_view_template_file_form', WPMST()->templates->get_template_attr( $this->atts, 'template' ) );
132
133 /**
134 * Allow add-ons to hijack the output generation.
135 */
136 $atts = $this->atts;
137 if ( has_filter( 'wpmtst_render_view_template' ) ) {
138 $html = apply_filters( 'wpmtst_render_view_template', '', $this );
139 } else {
140
141 /**
142 * Gutenberg. Yay.
143 * @since 2.31.9
144 */
145 global $post;
146 $post_before = $post;
147
148 ob_start();
149 /** @noinspection PhpIncludeInspection */
150 include $this->template_file;
151 $html = ob_get_clean();
152
153 $post = $post_before;
154
155 }
156 // TODO apply content filters
157
158 /**
159 * Remove filters here.
160 */
161 remove_action( 'wpmtst_before_form', array( $this, 'print_overlay' ) );
162
163 /**
164 * Trigger stuff.
165 */
166 do_action( 'wpmtst_form_rendered', $this->atts );
167
168 $this->html = apply_filters( 'strong_view_form_html', $html, $this );
169 }
170
171 /**
172 * Build class list based on view attributes.
173 */
174 public function build_classes() {
175
176 $container_class_list = isset( $this->atts['view'] ) ? array( 'strong-view-id-' . $this->atts['view'] ) : array();
177 $container_class_list = array_merge( $container_class_list, $this->get_template_css_class() );
178
179 if ( is_rtl() ) {
180 $container_class_list[] = 'rtl';
181 }
182
183 if ( isset( $this->atts['class'] ) && $this->atts['class'] ) {
184 $container_class_list[] = $this->atts['class'];
185 }
186
187 $container_data_list = array();
188 $container_data_list['state'] = 'idle';
189
190 /**
191 * Filter classes.
192 */
193 $this->atts['container_data'] = apply_filters( 'wpmtst_view_container_data', $container_data_list, $this->atts );
194 $this->atts['container_class'] = implode( ' ', apply_filters( 'wpmtst_view_container_class', $container_class_list, $this->atts ) );
195
196 /**
197 * Store updated atts.
198 */
199 WPMST()->set_atts( $this->atts );
200 }
201
202 /**
203 * Load validator script.
204 */
205 public function load_validator() {
206
207 // Assemble list of field properties for validation script.
208 $form_id = isset( $this->atts['form_id'] ) ? $this->atts['form_id'] : 1;
209 $form_fields = wpmtst_get_form_fields( $form_id );
210 $fields = array();
211
212 foreach ( $form_fields as $field ) {
213
214 $fields[] = array(
215 'name' => $field['name'],
216 'type' => $field['input_type'],
217 'required' => $field['required'],
218 );
219
220 // Load rating stylesheet if necessary.
221 if ( isset( $field['input_type'] ) && 'rating' === $field['input_type'] ) {
222 WPMST()->render->add_style( 'wpmtst-rating-form' );
223 }
224 }
225
226 // Load validation scripts
227 WPMST()->render->add_script( 'wpmtst-form-validation' );
228 if ( wp_script_is( 'wpmtst-validation-lang', 'registered' ) ) {
229 WPMST()->render->add_script( 'wpmtst-validation-lang' );
230 }
231
232 $form_options = get_option( 'wpmtst_form_options' );
233
234 // Assemble script variable.
235 // Remember: top level is converted to strings!
236 $scroll = array(
237 'onError' => $form_options['scrolltop_error'] ? true : false,
238 'onErrorOffset' => $form_options['scrolltop_error_offset'],
239 'onSuccess' => $form_options['scrolltop_success'] ? true : false,
240 'onSuccessOffset' => $form_options['scrolltop_success_offset'],
241 );
242
243 $args = array(
244 'scroll' => $scroll,
245 'fields' => $fields,
246 );
247
248 if ( isset( $this->atts['form_ajax'] ) && $this->atts['form_ajax'] ) {
249 $args['ajaxUrl'] = admin_url( 'admin-ajax.php' );
250 }
251
252 WPMST()->render->add_script_var( 'wpmtst-form-validation', 'strongForm', $args );
253 WPMST()->render->add_script( 'wpmtst-controller' );
254 }
255 }
256
257 endif;
258