PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.9
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.9
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / classes / helpers / FrmStylesHelper.php

FrmStylesHelper.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.9, at classes/helpers/FrmStylesHelper.php

844 lines 22.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 class FrmStylesHelper {
7
8 public static function get_upload_base() {
9 $uploads = wp_upload_dir();
10 if ( is_ssl() && ! preg_match( '/^https:\/\/.*\..*$/', $uploads['baseurl'] ) ) {
11 $uploads['baseurl'] = str_replace( 'http://', 'https://', $uploads['baseurl'] );
12 }
13
14 return $uploads;
15 }
16
17 /**
18 * Called from the admin header.
19 *
20 * @since 4.0
21 */
22 public static function save_button() {
23 ?>
24 <input type="submit" name="submit" class="button button-primary frm-button-primary" value="<?php esc_attr_e( 'Update', 'formidable' ); ?>" />
25 <?php
26 }
27
28 /**
29 * @since 2.05
30 */
31 public static function get_css_label_positions() {
32 return array(
33 'none' => __( 'top', 'formidable' ),
34 'left' => __( 'left', 'formidable' ),
35 'right' => __( 'right', 'formidable' ),
36 'no_label' => __( 'none', 'formidable' ),
37 'inside' => __( 'inside', 'formidable' ),
38 );
39 }
40
41 public static function get_single_label_positions() {
42 return array(
43 'top' => __( 'Top', 'formidable' ),
44 'left' => __( 'Left', 'formidable' ),
45 'right' => __( 'Right', 'formidable' ),
46 'inline' => __( 'Inline (left without a set width)', 'formidable' ),
47 'none' => __( 'None', 'formidable' ),
48 'hidden' => __( 'Hidden (but leave the space)', 'formidable' ),
49 'inside' => __( 'Placeholder inside the field', 'formidable' ),
50 );
51 }
52
53 public static function minus_icons() {
54 return array(
55 0 => array(
56 '-' => '62e',
57 '+' => '62f',
58 ),
59 1 => array(
60 '-' => '600',
61 '+' => '602',
62 ),
63 2 => array(
64 '-' => '604',
65 '+' => '603',
66 ),
67 3 => array(
68 '-' => '633',
69 '+' => '632',
70 ),
71 4 => array(
72 '-' => '613',
73 '+' => '60f',
74 ),
75 );
76 }
77
78 public static function arrow_icons() {
79 $minus_icons = self::minus_icons();
80
81 return array(
82 6 => array(
83 '-' => '62d',
84 '+' => '62a',
85 ),
86 0 => array(
87 '-' => '60d',
88 '+' => '609',
89 ),
90 1 => array(
91 '-' => '60e',
92 '+' => '60c',
93 ),
94 2 => array(
95 '-' => '630',
96 '+' => '631',
97 ),
98 3 => array(
99 '-' => '62b',
100 '+' => '628',
101 ),
102 4 => array(
103 '-' => '62c',
104 '+' => '629',
105 ),
106 5 => array(
107 '-' => '635',
108 '+' => '634',
109 ),
110 'p0' => $minus_icons[0],
111 'p1' => $minus_icons[1],
112 'p2' => $minus_icons[2],
113 'p3' => $minus_icons[3],
114 'p4' => $minus_icons[4],
115 );
116 }
117
118 /**
119 * @since 2.0
120 * @return string The class for this icon.
121 */
122 public static function icon_key_to_class( $key, $icon = '+', $type = 'arrow' ) {
123 if ( 'arrow' === $type && is_numeric( $key ) ) {
124 // frm_arrowup6_icon.
125 $arrow = array(
126 '-' => 'down',
127 '+' => 'up',
128 );
129 $class = 'frm_arrow' . $arrow[ $icon ];
130 } else {
131 // frm_minus1_icon.
132 $key = str_replace( 'p', '', $key );
133 $plus = array(
134 '-' => 'minus',
135 '+' => 'plus',
136 );
137 $class = 'frm_' . $plus[ $icon ];
138 }
139
140 if ( $key ) {
141 $class .= $key;
142 }
143 $class .= '_icon';
144
145 return $class;
146 }
147
148 /**
149 * @param WP_Post $style
150 * @param FrmStyle $frm_style
151 * @param string $type
152 * @return void
153 */
154 public static function bs_icon_select( $style, $frm_style, $type = 'arrow' ) {
155 $function_name = $type . '_icons';
156 $icons = self::$function_name();
157 unset( $function_name );
158
159 $name = 'arrow' === $type ? 'collapse_icon' : 'repeat_icon';
160 ?>
161 <div class="btn-group" id="frm_<?php echo esc_attr( $name ); ?>_select">
162 <button class="multiselect dropdown-toggle btn btn-default" data-toggle="dropdown" type="button">
163 <?php FrmAppHelper::icon_by_class( 'frmfont ' . self::icon_key_to_class( $style->post_content[ $name ], '+', $type ) ); ?>
164 <?php FrmAppHelper::icon_by_class( 'frmfont ' . self::icon_key_to_class( $style->post_content[ $name ], '-', $type ) ); ?>
165 <b class="caret"></b>
166 </button>
167 <ul class="multiselect-container frm-dropdown-menu">
168 <?php foreach ( $icons as $key => $icon ) { ?>
169 <li <?php echo ( $style->post_content['collapse_icon'] == $key ) ? 'class="active"' : ''; ?>>
170 <a href="javascript:void(0);">
171 <label>
172 <input type="radio" value="<?php echo esc_attr( $key ); ?>" name="<?php echo esc_attr( $frm_style->get_field_name( $name ) ); ?>" <?php checked( $style->post_content[ $name ], $key ); ?> />
173 <span>
174 <?php
175 FrmAppHelper::icon_by_class( 'frmfont ' . self::icon_key_to_class( $key, '+', $type ) );
176 FrmAppHelper::icon_by_class( 'frmfont ' . self::icon_key_to_class( $key, '-', $type ) );
177 ?>
178 </span>
179 </label>
180 </a>
181 </li>
182 <?php } ?>
183 </ul>
184 </div>
185 <?php
186 }
187
188 /**
189 * Convert a color setting to a RGB CSV (without the rgb()/rgba() wrapper).
190 *
191 * @since 2.0
192 *
193 * @param string $color Color setting value. This could be hex or rgb.
194 * @return string RGB value without the rgb() wrapper.
195 */
196 public static function hex2rgb( $color ) {
197 if ( 0 === strpos( $color, 'rgb' ) ) {
198 $rgb = self::get_rgb_array_from_rgb( $color );
199 } else {
200 $rgb = self::get_rgb_array_from_hex( $color );
201 }
202 return implode( ',', $rgb );
203 }
204
205 /**
206 * Remove the rgb()/rgba() wrapper from a RGB color and return its R, G and B values as an array.
207 *
208 * @since 6.8.3
209 *
210 * @param string $rgb RGB value including the rgb() or rgba() wrapper.
211 * @return array<string> including three numeric values for R, G, and B.
212 */
213 private static function get_rgb_array_from_rgb( $rgb ) {
214 $rgb = str_replace( array( 'rgb(', 'rgba(', ')' ), '', $rgb );
215 $rgb = explode( ',', $rgb );
216 if ( 4 === count( $rgb ) ) {
217 // Drop the alpha. The function is expected to only return r,g,b with no alpha.
218 array_pop( $rgb );
219 }
220 return $rgb;
221 }
222
223 /**
224 * Get the R, G, and B array values from a Hex color code.
225 *
226 * @since 6.8.3
227 *
228 * @param string $hex A hex color string.
229 * @return array<string> Including three numeric values for R, G, and B.
230 */
231 private static function get_rgb_array_from_hex( $hex ) {
232 $hex = str_replace( '#', '', $hex );
233 list( $r, $g, $b ) = sscanf( $hex, '%02x%02x%02x' );
234 return array( $r, $g, $b );
235 }
236
237 /**
238 * @since 4.0
239 */
240 public static function hex2rgba( $hex, $a ) {
241 $rgb = self::hex2rgb( $hex );
242
243 return 'rgba(' . $rgb . ',' . $a . ')';
244 }
245
246 /**
247 * @since 6.0
248 *
249 * @param string $rgba Color setting value. This could be hex or rgb.
250 * @return string Hex color value.
251 */
252 private static function rgb_to_hex( $rgba ) {
253 if ( strpos( $rgba, '#' ) === 0 ) {
254 // Color is already hex.
255 return $rgba;
256 }
257 preg_match( '/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i', $rgba, $by_color );
258 return sprintf( '%02x%02x%02x', $by_color[1], $by_color[2], $by_color[3] );
259 }
260
261 /**
262 * @since 6.8
263 *
264 * @param string $hsl
265 * @return string|null Null if it fails to parse the HSL string.
266 */
267 private static function hsl_to_hex( $hsl ) {
268 // Convert hsla to hsl.
269 $hsl = preg_replace( '/hsla\((\d+),\s*([\d.]+)%,\s*([\d.]+)%,\s*([\d.]+)\)/', 'hsl($1, $2%, $3%)', $hsl );
270
271 // Extract HSL components from the color string.
272 preg_match( '/hsl\((\d+),\s*(\d+)%,\s*(\d+)%\)/', $hsl, $matches );
273
274 if ( count( $matches ) !== 4 ) {
275 // Invalid HSL string format.
276 return null;
277 }
278
279 // Extract HSL values.
280 $h = (int) $matches[1];
281 $s = (int) $matches[2] / 100;
282 $l = (int) $matches[3] / 100;
283
284 // Calculate RGB values.
285 $c = ( 1 - abs( 2 * $l - 1 ) ) * $s;
286 $x = $c * ( 1 - abs( ( (int) ( $h / 60 ) % 2 ) - 1 ) );
287 $m = $l - $c / 2;
288 $r = 0;
289 $g = 0;
290 $b = 0;
291
292 if ( $h >= 0 && $h < 60 ) {
293 $r = $c;
294 $g = $x;
295 } elseif ( $h >= 60 && $h < 120 ) {
296 $r = $x;
297 $g = $c;
298 } elseif ( $h >= 120 && $h < 180 ) {
299 $g = $c;
300 $b = $x;
301 } elseif ( $h >= 180 && $h < 240 ) {
302 $g = $x;
303 $b = $c;
304 } elseif ( $h >= 240 && $h < 300 ) {
305 $r = $x;
306 $b = $c;
307 } elseif ( $h >= 300 && $h < 360 ) {
308 $r = $c;
309 $b = $x;
310 }//end if
311
312 // Convert RGB to 8-bit values
313 $r = round( ( $r + $m ) * 255 );
314 $g = round( ( $g + $m ) * 255 );
315 $b = round( ( $b + $m ) * 255 );
316
317 // Convert RGB to hex
318 $hex = sprintf( '%02x%02x%02x', $r, $g, $b );
319
320 return $hex;
321 }
322
323 /**
324 * @param string $hex string The original color in hex format #ffffff.
325 * @param int $steps integer Should be between -255 and 255. Negative = darker, positive = lighter.
326 *
327 * @since 2.3
328 */
329 public static function adjust_brightness( $hex, $steps ) {
330 $steps = max( - 255, min( 255, $steps ) );
331
332 if ( 0 === strpos( $hex, 'rgba(' ) ) {
333 $rgba = str_replace( ')', '', str_replace( 'rgba(', '', $hex ) );
334 list ( $r, $g, $b, $a ) = array_map( 'trim', explode( ',', $rgba ) );
335 $r = max( 0, min( 255, $r + $steps ) );
336 $g = max( 0, min( 255, $g + $steps ) );
337 $b = max( 0, min( 255, $b + $steps ) );
338 return 'rgba(' . $r . ',' . $g . ',' . $b . ',' . $a . ')';
339 }
340
341 // Normalize into a six character long hex string
342 $hex = str_replace( '#', '', $hex );
343 self::fill_hex( $hex );
344
345 // Split into three parts: R, G and B
346 $color_parts = str_split( $hex, 2 );
347 $return = '#';
348
349 foreach ( $color_parts as $color ) {
350 // Convert to decimal.
351 $color = hexdec( $color );
352 // Adjust color.
353 $color = max( 0, min( 255, $color + $steps ) );
354
355 // Make two char hex code.
356 $return .= str_pad( dechex( $color ), 2, '0', STR_PAD_LEFT );
357 }
358
359 return $return;
360 }
361
362 /**
363 * @since 6.0
364 *
365 * @param string $color
366 * @return int
367 */
368 public static function get_color_brightness( $color ) {
369 if ( 0 === strpos( $color, 'rgb' ) ) {
370 $color = self::rgb_to_hex( $color );
371 }
372
373 if ( 0 === strpos( $color, 'hsl' ) ) {
374 $hsl_to_hex = self::hsl_to_hex( $color );
375 if ( is_null( $hsl_to_hex ) ) {
376 // Fallback if we cannot convert the HSL value.
377 return 0;
378 }
379 $color = $hsl_to_hex;
380 }
381
382 self::fill_hex( $color );
383
384 $c_r = hexdec( substr( $color, 0, 2 ) );
385 $c_g = hexdec( substr( $color, 2, 2 ) );
386 $c_b = hexdec( substr( $color, 4, 2 ) );
387 $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
388
389 return $brightness;
390 }
391
392 /**
393 * Change a 3 character hex color to a 6 character one.
394 *
395 * @since 6.0
396 *
397 * @return void
398 */
399 private static function fill_hex( &$color ) {
400 if ( 3 === strlen( $color ) ) {
401 $color = $color[0] . $color[0] . $color[1] . $color[1] . $color[2] . $color[2];
402 }
403 }
404
405 /**
406 * @since 4.05.02
407 */
408 public static function get_css_vars( $vars = array() ) {
409 $vars = apply_filters( 'frm_css_vars', $vars );
410 return array_unique( $vars );
411 }
412
413 /**
414 * @since 4.05.02
415 */
416 public static function output_vars( $settings, $defaults = array(), $vars = array() ) {
417 if ( empty( $vars ) ) {
418 $vars = self::get_css_vars( array_keys( $settings ) );
419 }
420 $remove = array( 'remove_box_shadow', 'remove_box_shadow_active', 'theme_css', 'theme_name', 'theme_selector', 'important_style', 'submit_style', 'collapse_icon', 'center_form', 'custom_css', 'style_class', 'submit_bg_img', 'change_margin', 'repeat_icon' );
421 $vars = array_diff( $vars, $remove );
422
423 foreach ( $vars as $var ) {
424 if ( ! isset( $settings[ $var ] ) ) {
425 continue;
426 }
427 if ( ! isset( $defaults[ $var ] ) ) {
428 $defaults[ $var ] = '';
429 }
430 $show = empty( $defaults ) || ( $settings[ $var ] !== '' && $settings[ $var ] !== $defaults[ $var ] );
431 if ( $show ) {
432 echo '--' . esc_html( str_replace( '_', '-', $var ) ) . ':' . ( $var === 'font' ? FrmAppHelper::kses( $settings[ $var ] ) : esc_html( $settings[ $var ] ) ) . ';'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
433 }
434 }
435 }
436
437 /**
438 * @since 2.3
439 *
440 * @param WP_Post $style
441 * @return array
442 */
443 public static function get_settings_for_output( $style ) {
444 if ( self::previewing_style() ) {
445 $frm_style = new FrmStyle();
446 if ( isset( $_POST['frm_style_setting'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
447
448 // Sanitizing is done later.
449 $posted = wp_unslash( $_POST['frm_style_setting'] ); //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
450 if ( ! is_array( $posted ) ) {
451 $posted = json_decode( $posted, true );
452 FrmAppHelper::format_form_data( $posted );
453 $settings = $frm_style->sanitize_post_content( $posted['frm_style_setting']['post_content'] );
454 $style_name = sanitize_title( $posted['style_name'] );
455 } else {
456 $settings = $frm_style->sanitize_post_content( $posted['post_content'] );
457 $style_name = FrmAppHelper::get_post_param( 'style_name', '', 'sanitize_title' );
458 }
459 } else {
460 $settings = $frm_style->sanitize_post_content( wp_unslash( $_GET ) );
461 $style_name = FrmAppHelper::get_param( 'style_name', '', 'get', 'sanitize_title' );
462 }
463
464 FrmAppHelper::sanitize_value( 'sanitize_text_field', $settings );
465
466 $settings['style_class'] = '';
467 if ( ! empty( $style_name ) ) {
468 $settings['style_class'] = $style_name . '.';
469 }
470 } else {
471 $settings = $style->post_content;
472 $settings['style_class'] = 'frm_style_' . $style->post_name . '.';
473 }//end if
474
475 $settings['style_class'] .= 'with_frm_style';
476 $settings['font'] = stripslashes( $settings['font'] );
477 $settings['change_margin'] = self::description_margin_for_screensize( $settings['width'] );
478
479 $checkbox_opts = array( 'important_style', 'auto_width', 'submit_style', 'collapse_icon', 'center_form' );
480 foreach ( $checkbox_opts as $opt ) {
481 if ( ! isset( $settings[ $opt ] ) ) {
482 $settings[ $opt ] = 0;
483 }
484 }
485
486 self::prepare_color_output( $settings );
487
488 $settings['field_height'] = $settings['field_height'] === '' ? 'auto' : $settings['field_height'];
489 $settings['field_width'] = $settings['field_width'] === '' ? 'auto' : $settings['field_width'];
490 $settings['auto_width'] = $settings['auto_width'] ? 'auto' : $settings['field_width'];
491 $settings['box_shadow'] = ! empty( $settings['remove_box_shadow'] ) ? 'none' : '0 1px 1px rgba(0, 0, 0, 0.075) inset';
492
493 if ( ! isset( $settings['repeat_icon'] ) ) {
494 $settings['repeat_icon'] = 1;
495 }
496
497 return $settings;
498 }
499
500 /**
501 * @since 2.3
502 */
503 public static function prepare_color_output( &$settings, $allow_transparent = true ) {
504 $colors = self::allow_color_override();
505 foreach ( $colors as $css => $opts ) {
506 if ( $css === 'transparent' && ! $allow_transparent ) {
507 $css = '';
508 }
509 foreach ( $opts as $opt ) {
510 self::get_color_output( $css, $settings[ $opt ] );
511 }
512 }
513 }
514
515 /**
516 * @since 2.3
517 *
518 * @return array
519 */
520 private static function allow_color_override() {
521 $frm_style = new FrmStyle();
522 $colors = $frm_style->get_color_settings();
523
524 $transparent = array(
525 'fieldset_color',
526 'fieldset_bg_color',
527 'bg_color',
528 'bg_color_active',
529 'bg_color_disabled',
530 'section_bg_color',
531 'error_bg',
532 'success_bg_color',
533 'progress_bg_color',
534 'progress_active_bg_color',
535 'submit_border_color',
536 'submit_hover_border_color',
537 'submit_active_border_color',
538 'submit_hover_bg_color',
539 'submit_active_bg_color',
540 );
541
542 return array(
543 'transparent' => $transparent,
544 '' => array_diff( $colors, $transparent ),
545 );
546 }
547
548 /**
549 * @since 2.3
550 */
551 private static function get_color_output( $default, &$color ) {
552 $color = trim( $color );
553 if ( empty( $color ) ) {
554 $color = $default;
555 } elseif ( false !== strpos( $color, 'rgb(' ) ) {
556 $color = str_replace( 'rgb(', 'rgba(', $color );
557 $color = str_replace( ')', ',1)', $color );
558 } elseif ( strpos( $color, '#' ) === false && self::is_hex( $color ) ) {
559 $color = '#' . $color;
560 }
561 }
562
563 /**
564 * If a color looks like a hex code without the #, prepend the #.
565 * A color looks like a hex code if it does not contain the substrings "rgb", "rgba", "hsl", "hsla", or "hwb".
566 *
567 * @since 6.8
568 *
569 * @param string $color
570 * @return bool
571 */
572 private static function is_hex( $color ) {
573 $non_hex_substrings = array(
574 'rgba(',
575 'hsl(',
576 'hsla(',
577 'hwb(',
578 );
579
580 foreach ( $non_hex_substrings as $substring ) {
581 if ( false !== strpos( $color, $substring ) ) {
582 return false;
583 }
584 }
585
586 return true;
587 }
588
589 /**
590 * If left/right label is over a certain size,
591 * adjust the field description margin at a different screen size
592 *
593 * @since 2.3
594 */
595 private static function description_margin_for_screensize( $width ) {
596 $temp_label_width = str_replace( 'px', '', $width );
597 $change_margin = false;
598 if ( $temp_label_width >= 230 ) {
599 $change_margin = '800px';
600 } elseif ( $width >= 215 ) {
601 $change_margin = '700px';
602 } elseif ( $width >= 180 ) {
603 $change_margin = '650px';
604 }
605
606 return $change_margin;
607 }
608
609 /**
610 * @since 2.3
611 *
612 * @return bool
613 */
614 public static function previewing_style() {
615 $ajax_change = isset( $_POST['action'] ) && $_POST['action'] === 'frm_change_styling' && isset( $_POST['frm_style_setting'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
616
617 return $ajax_change || isset( $_GET['flat'] );
618 }
619
620 /**
621 * @since 5.5.1
622 * @return void
623 */
624 public static function maybe_include_font_icon_css() {
625 $signature_add_on_is_active = class_exists( 'FrmSigAppHelper', false );
626
627 if ( ! FrmAppHelper::pro_is_installed() && ! $signature_add_on_is_active ) {
628 // If Pro and Signatures are both not active, there is no need to include the font icon CSS in lite.
629 return;
630 }
631
632 $pro_version_will_handle_loading = false;
633
634 if ( class_exists( 'FrmProDb', false ) ) {
635 $pro_version_that_includes_font_icons_css = '5.5.1';
636
637 // Include font icons in Lite for backward compatibility with older version of Pro.
638 $pro_version_will_handle_loading = version_compare( FrmProDb::$plug_version, $pro_version_that_includes_font_icons_css, '>=' );
639 }
640
641 $load_it_here = false;
642 if ( ! $pro_version_will_handle_loading ) {
643 // If Pro is not handling it, we still need to include it for the Signature add on.
644 $load_it_here = $signature_add_on_is_active;
645 }
646
647 if ( $load_it_here ) {
648 readfile( FrmAppHelper::plugin_path() . '/css/font_icons.css' );
649 }
650 }
651
652 /**
653 * Get the URL for the Styler page list view (where you can assign styles to a form and view style templates) for a target form.
654 *
655 * @since 6.0
656 *
657 * @param string|int $form_id
658 * @return string
659 */
660 public static function get_list_url( $form_id ) {
661 return admin_url( 'admin.php?page=formidable-styles&form=' . absint( $form_id ) );
662 }
663
664 /**
665 * Get a link to edit a target style post object in the visual styler.
666 *
667 * @param WP_Post|stdClass $style
668 * @param string|int $form_id Used for the back button and preview form target.
669 * @return string
670 */
671 public static function get_edit_url( $style, $form_id = 0 ) {
672 $query_args = array(
673 'page' => 'formidable-styles',
674 'frm_action' => 'edit',
675 'id' => $style->ID,
676 );
677
678 if ( $form_id ) {
679 // We include &form_id for the back button to know where to point to.
680 $query_args['form'] = $form_id;
681 }
682
683 return add_query_arg( $query_args, admin_url( 'admin.php' ) );
684 }
685
686 /**
687 * Get a count of the number of forms assigned to a target style ID.
688 * All unassigned forms are included in the count for the default style.
689 *
690 * @since 6.0
691 *
692 * @param string|int $style_id
693 * @param bool $is_default
694 * @return int
695 */
696 public static function get_form_count_for_style( $style_id, $is_default ) {
697 $serialized = serialize( array( 'custom_style' => (string) $style_id ) );
698 // Chop off the "a:1:{" from the front and the "}" from the back.
699 $substring = substr( $serialized, 5, -1 );
700 $number_of_forms = FrmDb::get_count(
701 'frm_forms',
702 array(
703 'status' => 'published',
704 'options LIKE' => $substring,
705 )
706 );
707
708 if ( ! $is_default ) {
709 // Exit early as the rest of the code is about including the default count.
710 return $number_of_forms;
711 }
712
713 $conversational_style_id = FrmDb::get_var( 'posts', array( 'post_name' => 'lines-no-boxes' ), 'ID' );
714 $number_of_forms += self::get_default_style_count( $style_id, $conversational_style_id );
715
716 return $number_of_forms;
717 }
718
719 /**
720 * Get the number of forms that use the default style.
721 *
722 * @since 6.0
723 *
724 * @param string|int $style_id
725 * @param mixed $conversational_style_id
726 * @return int
727 */
728 private static function get_default_style_count( $style_id, $conversational_style_id ) {
729 $substrings = array_map(
730 function ( $value ) {
731 $substring = serialize( array( 'custom_style' => $value ) );
732 return substr( $substring, 5, -1 );
733 },
734 array( '1', 1 )
735 );
736 $where = array(
737 'status' => 'published',
738 0 => array(
739 'options NOT LIKE' => 'custom_style',
740 'or' => 1,
741 'options LIKE' => $substrings,
742 ),
743 );
744
745 if ( $conversational_style_id ) {
746 // When a conversational style is set, check for it in the query by wrapping the where and adding a conversational option check.
747 $is_conversational_style = (int) $style_id === (int) $conversational_style_id;
748 $where[0] = array(
749 // The chat option doesn't exist if it isn't on.
750 ( $is_conversational_style ? 'options LIKE' : 'options NOT LIKE' ) => ';s:4:"chat";',
751 $where[0],
752 );
753 }
754
755 return FrmDb::get_count( 'frm_forms', $where );
756 }
757
758 /**
759 * @deprecated 3.01
760 * @codeCoverageIgnore
761 */
762 public static function get_sigle_label_postitions() {
763 return FrmDeprecated::get_sigle_label_postitions();
764 }
765
766 /**
767 * @deprecated 3.02.03
768 * @codeCoverageIgnore
769 */
770 public static function jquery_themes() {
771 return FrmDeprecated::jquery_themes();
772 }
773
774 /**
775 * @deprecated 3.02.03
776 * @codeCoverageIgnore
777 */
778 public static function jquery_css_url( $theme_css ) {
779 return FrmDeprecated::jquery_css_url( $theme_css );
780 }
781
782 /**
783 * @deprecated 3.02.03
784 * @codeCoverageIgnore
785 */
786 public static function enqueue_jquery_css() {
787 FrmDeprecated::enqueue_jquery_css();
788 }
789
790 /**
791 * @deprecated 3.02.03
792 * @codeCoverageIgnore
793 */
794 public static function get_form_for_page() {
795 return FrmDeprecated::get_form_for_page();
796 }
797
798 /**
799 * @since 4.0
800 * @deprecated 6.0 The style menu is no longer used in the styler.
801 *
802 * @param string $active
803 * @return string
804 */
805 public static function get_style_menu( $active = '' ) {
806 _deprecated_function( __METHOD__, '6.0' );
807 return '';
808 }
809
810 /**
811 * @deprecated 6.0 The style menu is no longer used in the styler.
812 *
813 * @param string $active
814 * @return void
815 */
816 public static function style_menu( $active = '' ) {
817 _deprecated_function( __METHOD__, '6.0' );
818 }
819
820 /**
821 * Either get the heading or the style switcher.
822 *
823 * @since 4.0
824 * @deprecated 6.0 The style switcher was replaced with a form switcher and is no longer used.
825 *
826 * @param array $atts
827 * @return void
828 */
829 public static function styler_switcher( $atts ) {
830 _deprecated_function( __METHOD__, '6.0' );
831 }
832
833 /**
834 * @since 4.0
835 * @deprecated 6.0 The styler now uses the Embed/Preview/Update header. It uses the same save button as other pages with Form tabs.
836 *
837 * @param array $atts
838 * @return void
839 */
840 public static function styler_save_button( $atts ) {
841 _deprecated_function( __METHOD__, '6.0' );
842 }
843 }
844