PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.0
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
← All changes | classes/helpers/FrmStylesHelper.php +90 -283 6.45.0 View file →
@@ -14,8 +14,57 @@
14 14 return $uploads;
15 15 }
16 16
17 17 /**
18 + * @since 4.0
19 + */
20 + public static function get_style_menu( $active = '' ) {
21 + ob_start();
22 + self::style_menu( $active );
23 + $menu = ob_get_contents();
24 + ob_end_clean();
25 +
26 + return $menu;
27 + }
28 +
29 + public static function style_menu( $active = '' ) {
30 + ?>
31 + <ul class="frm_form_nav">
32 + <li>
33 + <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable-styles' ) ); ?>"
34 + class="<?php echo ( '' == $active ) ? 'current_page' : ''; ?>">
35 + <?php esc_html_e( 'Edit Styles', 'formidable' ); ?>
36 + </a>
37 + </li>
38 + <li>
39 + <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable-styles&frm_action=manage' ) ); ?>"
40 + class="<?php echo ( 'manage' == $active ) ? 'current_page' : ''; ?>">
41 + <?php esc_html_e( 'Manage Styles', 'formidable' ); ?>
42 + </a>
43 + </li>
44 + <li>
45 + <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable-styles&frm_action=custom_css' ) ); ?>"
46 + class="<?php echo ( 'custom_css' == $active ) ? 'current_page' : ''; ?>">
47 + <?php esc_html_e( 'Custom CSS', 'formidable' ); ?>
48 + </a>
49 + </li>
50 + </ul>
51 + <?php
52 + }
53 +
54 + /**
55 + * @since 4.0
56 + */
57 + public static function styler_save_button( $atts ) {
58 + $style = $atts['style'];
59 + if ( ! empty( $style->ID ) && empty( $style->menu_order ) ) {
60 + $delete_link = admin_url( 'admin.php?page=formidable-styles&frm_action=destroy&id=' . $style->ID );
61 + }
62 +
63 + include( FrmAppHelper::plugin_path() . '/classes/views/styles/header-buttons.php' );
64 + }
65 +
66 + /**
18 67 * Called from the admin header.
19 68 *
20 69 * @since 4.0
21 70 */
@@ -25,8 +74,27 @@
25 74 <?php
26 75 }
27 76
28 77 /**
78 + * Either get the heading or the style switcher.
79 + *
80 + * @since 4.0
81 + */
82 + public static function styler_switcher( $atts ) {
83 + if ( has_action( 'frm_style_switcher_heading' ) ) {
84 + do_action( 'frm_style_switcher_heading', $atts );
85 + } else {
86 + ?>
87 + <div class="frm_top_left">
88 + <h1>
89 + <?php echo esc_html( $atts['style']->post_title ); ?>
90 + </h1>
91 + </div>
92 + <?php
93 + }
94 + }
95 +
96 + /**
29 97 * @since 2.05
30 98 */
31 99 public static function get_css_label_positions() {
32 100 return array(
@@ -116,12 +184,12 @@
116 184 }
117 185
118 186 /**
119 187 * @since 2.0
120 - * @return string The class for this icon.
188 + * @return The class for this icon
121 189 */
122 190 public static function icon_key_to_class( $key, $icon = '+', $type = 'arrow' ) {
123 - if ( 'arrow' === $type && is_numeric( $key ) ) {
191 + if ( 'arrow' == $type && is_numeric( $key ) ) {
124 192 //frm_arrowup6_icon
125 193 $arrow = array(
126 194 '-' => 'down',
127 195 '+' => 'up',
@@ -144,20 +212,14 @@
144 212
145 213 return $class;
146 214 }
147 215
148 - /**
149 - * @param WP_Post $style
150 - * @param FrmStyle $frm_style
151 - * @param string $type
152 - * @return void
153 - */
154 216 public static function bs_icon_select( $style, $frm_style, $type = 'arrow' ) {
155 217 $function_name = $type . '_icons';
156 218 $icons = self::$function_name();
157 219 unset( $function_name );
158 220
159 - $name = 'arrow' === $type ? 'collapse_icon' : 'repeat_icon';
221 + $name = ( 'arrow' == $type ) ? 'collapse_icon' : 'repeat_icon';
160 222 ?>
161 223 <div class="btn-group" id="frm_<?php echo esc_attr( $name ); ?>_select">
162 224 <button class="multiselect dropdown-toggle btn btn-default" data-toggle="dropdown" type="button">
163 225 <?php FrmAppHelper::icon_by_class( 'frmfont ' . self::icon_key_to_class( $style->post_content[ $name ], '+', $type ) ); ?>
@@ -168,14 +230,12 @@
168 230 <?php foreach ( $icons as $key => $icon ) { ?>
169 231 <li <?php echo ( $style->post_content['collapse_icon'] == $key ) ? 'class="active"' : ''; ?>>
170 232 <a href="javascript:void(0);">
171 233 <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 ); ?> />
234 + <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 235 <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 - ?>
236 + <?php FrmAppHelper::icon_by_class( 'frmfont ' . self::icon_key_to_class( $key, '+', $type ) ); ?>
237 + <?php FrmAppHelper::icon_by_class( 'frmfont ' . self::icon_key_to_class( $key, '-', $type ) ); ?>
178 238 </span>
179 239 </label>
180 240 </a>
181 241 </li>
@@ -204,22 +264,8 @@
204 264 return 'rgba(' . $rgb . ',' . $a . ')';
205 265 }
206 266
207 267 /**
208 - * @since 6.0
209 - *
210 - * @param string $rgba
211 - * @return string
212 - */
213 - private static function rgb_to_hex( $rgba ) {
214 - if ( strpos( $rgba, '#' ) === 0 ) {
215 - return $rgba;
216 - }
217 - preg_match( '/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i', $rgba, $by_color );
218 - return sprintf( '%02x%02x%02x', $by_color[1], $by_color[2], $by_color[3] );
219 - }
220 -
221 - /**
222 268 * @param $hex string - The original color in hex format #ffffff
223 269 * @param $steps integer - should be between -255 and 255. Negative = darker, positive = lighter
224 270 *
225 271 * @since 2.3
@@ -226,20 +272,15 @@
226 272 */
227 273 public static function adjust_brightness( $hex, $steps ) {
228 274 $steps = max( - 255, min( 255, $steps ) );
229 275
230 - if ( 0 === strpos( $hex, 'rgba(' ) ) {
231 - $rgba = str_replace( ')', '', str_replace( 'rgba(', '', $hex ) );
232 - list ( $r, $g, $b, $a ) = array_map( 'trim', explode( ',', $rgba ) );
233 - $r = max( 0, min( 255, $r + $steps ) );
234 - $g = max( 0, min( 255, $g + $steps ) );
235 - $b = max( 0, min( 255, $b + $steps ) );
236 - return 'rgba(' . $r . ',' . $g . ',' . $b . ',' . $a . ')';
237 - }
238 -
239 276 // Normalize into a six character long hex string
240 277 $hex = str_replace( '#', '', $hex );
241 - self::fill_hex( $hex );
278 + if ( strlen( $hex ) == 3 ) {
279 + $hex = str_repeat( substr( $hex, 0, 1 ), 2 );
280 + $hex .= str_repeat( substr( $hex, 1, 1 ), 2 );
281 + $hex .= str_repeat( substr( $hex, 2, 1 ), 2 );
282 + }
242 283
243 284 // Split into three parts: R, G and B
244 285 $color_parts = str_split( $hex, 2 );
245 286 $return = '#';
@@ -253,42 +294,8 @@
253 294 return $return;
254 295 }
255 296
256 297 /**
257 - * @since 6.0
258 - *
259 - * @param string $color
260 - * @return int
261 - */
262 - public static function get_color_brightness( $color ) {
263 - if ( 0 === strpos( $color, 'rgb' ) ) {
264 - $color = self::rgb_to_hex( $color );
265 - }
266 -
267 - self::fill_hex( $color );
268 -
269 - $c_r = hexdec( substr( $color, 0, 2 ) );
270 - $c_g = hexdec( substr( $color, 2, 2 ) );
271 - $c_b = hexdec( substr( $color, 4, 2 ) );
272 - $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
273 -
274 - return $brightness;
275 - }
276 -
277 - /**
278 - * Change a 3 character hex color to a 6 character one.
279 - *
280 - * @since 6.0
281 - *
282 - * @return array
283 - */
284 - private static function fill_hex( &$color ) {
285 - if ( 3 === strlen( $color ) ) {
286 - $color = $color[0] . $color[0] . $color[1] . $color[1] . $color[2] . $color[2];
287 - }
288 - }
289 -
290 - /**
291 298 * @since 4.05.02
292 299 */
293 300 public static function get_css_vars( $vars = array() ) {
294 301 $vars = apply_filters( 'frm_css_vars', $vars );
@@ -313,9 +320,9 @@
313 320 $defaults[ $var ] = '';
314 321 }
315 322 $show = empty( $defaults ) || ( $settings[ $var ] !== '' && $settings[ $var ] !== $defaults[ $var ] );
316 323 if ( $show ) {
317 - echo '--' . esc_html( str_replace( '_', '-', $var ) ) . ':' . ( $var === 'font' ? FrmAppHelper::kses( $settings[ $var ] ) : esc_html( $settings[ $var ] ) ) . ';'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
324 + echo '--' . esc_html( str_replace( '_', '-', $var ) ) . ':' . ( $var === 'font' ? FrmAppHelper::kses( $settings[ $var ] ) : esc_html( $settings[ $var ] ) ) . ';'; // WPCS: XSS ok.
318 325 }
319 326 }
320 327 }
321 328
@@ -320,30 +327,27 @@
320 327 }
321 328
322 329 /**
323 330 * @since 2.3
324 - *
325 - * @param WP_Post $style
326 - * @return array
327 331 */
328 332 public static function get_settings_for_output( $style ) {
329 333 if ( self::previewing_style() ) {
330 - $frm_style = new FrmStyle();
331 - if ( isset( $_POST['frm_style_setting'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
332 334
335 + if ( isset( $_POST['frm_style_setting'] ) ) {
333 336 // Sanitizing is done later.
334 - $posted = wp_unslash( $_POST['frm_style_setting'] ); //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
337 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
338 + $posted = wp_unslash( $_POST['frm_style_setting'] );
335 339 if ( ! is_array( $posted ) ) {
336 340 $posted = json_decode( $posted, true );
337 341 FrmAppHelper::format_form_data( $posted );
338 - $settings = $frm_style->sanitize_post_content( $posted['frm_style_setting']['post_content'] );
342 + $settings = $posted['frm_style_setting']['post_content'];
339 343 $style_name = sanitize_title( $posted['style_name'] );
340 344 } else {
341 - $settings = $frm_style->sanitize_post_content( $posted['post_content'] );
345 + $settings = $posted['post_content'];
342 346 $style_name = FrmAppHelper::get_post_param( 'style_name', '', 'sanitize_title' );
343 347 }
344 348 } else {
345 - $settings = $frm_style->sanitize_post_content( wp_unslash( $_GET ) );
349 + $settings = $_GET;
346 350 $style_name = FrmAppHelper::get_param( 'style_name', '', 'get', 'sanitize_title' );
347 351 }
348 352
349 353 FrmAppHelper::sanitize_value( 'sanitize_text_field', $settings );
@@ -356,9 +360,9 @@
356 360 $settings = $style->post_content;
357 361 $settings['style_class'] = 'frm_style_' . $style->post_name . '.';
358 362 }
359 363
360 - $settings['style_class'] .= 'with_frm_style';
364 + $settings['style_class'] .= 'with_frm_style';
361 365 $settings['font'] = stripslashes( $settings['font'] );
362 366 $settings['change_margin'] = self::description_margin_for_screensize( $settings['width'] );
363 367
364 368 $checkbox_opts = array( 'important_style', 'auto_width', 'submit_style', 'collapse_icon', 'center_form' );
@@ -372,9 +376,9 @@
372 376
373 377 $settings['field_height'] = $settings['field_height'] === '' ? 'auto' : $settings['field_height'];
374 378 $settings['field_width'] = $settings['field_width'] === '' ? 'auto' : $settings['field_width'];
375 379 $settings['auto_width'] = $settings['auto_width'] ? 'auto' : $settings['field_width'];
376 - $settings['box_shadow'] = ! empty( $settings['remove_box_shadow'] ) ? 'none' : '0 1px 1px rgba(0, 0, 0, 0.075) inset';
380 + $settings['box_shadow'] = ( isset( $settings['remove_box_shadow'] ) && $settings['remove_box_shadow'] ) ? 'none' : '0 1px 1px rgba(0, 0, 0, 0.075) inset';
377 381
378 382 if ( ! isset( $settings['repeat_icon'] ) ) {
379 383 $settings['repeat_icon'] = 1;
380 384 }
@@ -398,10 +402,8 @@
398 402 }
399 403
400 404 /**
401 405 * @since 2.3
402 - *
403 - * @return array
404 406 */
405 407 private static function allow_color_override() {
406 408 $frm_style = new FrmStyle();
407 409 $colors = $frm_style->get_color_settings();
@@ -409,20 +411,13 @@
409 411 $transparent = array(
410 412 'fieldset_color',
411 413 'fieldset_bg_color',
412 414 'bg_color',
413 - 'bg_color_active',
414 - 'bg_color_disabled',
415 415 'section_bg_color',
416 416 'error_bg',
417 417 'success_bg_color',
418 418 'progress_bg_color',
419 419 'progress_active_bg_color',
420 - 'submit_border_color',
421 - 'submit_hover_border_color',
422 - 'submit_active_border_color',
423 - 'submit_hover_bg_color',
424 - 'submit_active_bg_color',
425 420 );
426 421
427 422 return array(
428 423 'transparent' => $transparent,
@@ -436,12 +431,9 @@
436 431 private static function get_color_output( $default, &$color ) {
437 432 $color = trim( $color );
438 433 if ( empty( $color ) ) {
439 434 $color = $default;
440 - } elseif ( false !== strpos( $color, 'rgb(' ) ) {
441 - $color = str_replace( 'rgb(', 'rgba(', $color );
442 - $color = str_replace( ')', ',1)', $color );
443 - } elseif ( strpos( $color, '#' ) === false && false === strpos( $color, 'rgba(' ) ) {
435 + } elseif ( strpos( $color, '#' ) === false ) {
444 436 $color = '#' . $color;
445 437 }
446 438 }
447 439
@@ -466,155 +458,16 @@
466 458 }
467 459
468 460 /**
469 461 * @since 2.3
470 - *
471 - * @return bool
472 462 */
473 463 public static function previewing_style() {
474 - $ajax_change = isset( $_POST['action'] ) && $_POST['action'] === 'frm_change_styling' && isset( $_POST['frm_style_setting'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
464 + $ajax_change = isset( $_POST['action'] ) && $_POST['action'] === 'frm_change_styling' && isset( $_POST['frm_style_setting'] );
475 465
476 466 return $ajax_change || isset( $_GET['flat'] );
477 467 }
478 468
479 469 /**
480 - * @since 5.5.1
481 - * @return void
482 - */
483 - public static function maybe_include_font_icon_css() {
484 - $signature_add_on_is_active = class_exists( 'FrmSigAppHelper', false );
485 -
486 - if ( ! FrmAppHelper::pro_is_installed() && ! $signature_add_on_is_active ) {
487 - // If Pro and Signatures are both not active, there is no need to include the font icon CSS in lite.
488 - return;
489 - }
490 -
491 - $pro_version_will_handle_loading = false;
492 -
493 - if ( class_exists( 'FrmProDb', false ) ) {
494 - $pro_version_that_includes_font_icons_css = '5.5.1';
495 -
496 - // Include font icons in Lite for backward compatibility with older version of Pro.
497 - $pro_version_will_handle_loading = version_compare( FrmProDb::$plug_version, $pro_version_that_includes_font_icons_css, '>=' );
498 - }
499 -
500 - $load_it_here = false;
501 - if ( ! $pro_version_will_handle_loading ) {
502 - // If Pro is not handling it, we still need to include it for the Signature add on.
503 - $load_it_here = $signature_add_on_is_active;
504 - }
505 -
506 - if ( $load_it_here ) {
507 - readfile( FrmAppHelper::plugin_path() . '/css/font_icons.css' );
508 - }
509 - }
510 -
511 - /**
512 - * 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.
513 - *
514 - * @since 6.0
515 - *
516 - * @param string|int $form_id
517 - * @return string
518 - */
519 - public static function get_list_url( $form_id ) {
520 - return admin_url( 'admin.php?page=formidable-styles&form=' . absint( $form_id ) );
521 - }
522 -
523 - /**
524 - * Get a link to edit a target style post object in the visual styler.
525 - *
526 - * @param WP_Post|stdClass $style
527 - * @param string|int $form_id Used for the back button and preview form target.
528 - * @return string
529 - */
530 - public static function get_edit_url( $style, $form_id = 0 ) {
531 - $query_args = array(
532 - 'page' => 'formidable-styles',
533 - 'frm_action' => 'edit',
534 - 'id' => $style->ID,
535 - );
536 -
537 - if ( $form_id ) {
538 - // We include &form_id for the back button to know where to point to.
539 - $query_args['form'] = $form_id;
540 - }
541 -
542 - return add_query_arg( $query_args, admin_url( 'admin.php' ) );
543 - }
544 -
545 - /**
546 - * Get a count of the number of forms assigned to a target style ID.
547 - * All unassigned forms are included in the count for the default style.
548 - *
549 - * @since 6.0
550 - *
551 - * @param string|int $style_id
552 - * @param bool $is_default
553 - * @return int
554 - */
555 - public static function get_form_count_for_style( $style_id, $is_default ) {
556 - $serialized = serialize( array( 'custom_style' => (string) $style_id ) );
557 - $substring = substr( $serialized, 5, -1 ); // Chop off the "a:1:{" from the front and the "}" from the back.
558 - $number_of_forms = FrmDb::get_count(
559 - 'frm_forms',
560 - array(
561 - 'status' => 'published',
562 - 'options LIKE' => $substring,
563 - )
564 - );
565 -
566 - if ( ! $is_default ) {
567 - // Exit early as the rest of the code is about including the default count.
568 - return $number_of_forms;
569 - }
570 -
571 - $conversational_style_id = FrmDb::get_var( 'posts', array( 'post_name' => 'lines-no-boxes' ), 'ID' );
572 - $number_of_forms += self::get_default_style_count( $style_id, $conversational_style_id );
573 -
574 - return $number_of_forms;
575 - }
576 -
577 - /**
578 - * Get the number of forms that use the default style.
579 - *
580 - * @since 6.0
581 - *
582 - * @param string|int $style_id
583 - * @param mixed $conversational_style_id
584 - * @return int
585 - */
586 - private static function get_default_style_count( $style_id, $conversational_style_id ) {
587 - $substrings = array_map(
588 - function( $value ) {
589 - $substring = serialize( array( 'custom_style' => $value ) );
590 - return substr( $substring, 5, -1 );
591 - },
592 - array( '1', 1 )
593 - );
594 - $where = array(
595 - 'status' => 'published',
596 - 0 => array(
597 - 'options NOT LIKE' => 'custom_style',
598 - 'or' => 1,
599 - 'options LIKE' => $substrings,
600 - ),
601 - );
602 -
603 - if ( $conversational_style_id ) {
604 - // When a conversational style is set, check for it in the query by wrapping the where and adding a conversational option check.
605 - $is_conversational_style = (int) $style_id === (int) $conversational_style_id;
606 - $where[0] = array(
607 - // The chat option doesn't exist if it isn't on.
608 - ( $is_conversational_style ? 'options LIKE' : 'options NOT LIKE' ) => ';s:4:"chat";',
609 - $where[0],
610 - );
611 - }
612 -
613 - return FrmDb::get_count( 'frm_forms', $where );
614 - }
615 -
616 - /**
617 470 * @deprecated 3.01
618 471 * @codeCoverageIgnore
619 472 */
620 473 public static function get_sigle_label_postitions() {
@@ -650,52 +503,6 @@
650 503 * @codeCoverageIgnore
651 504 */
652 505 public static function get_form_for_page() {
653 506 return FrmDeprecated::get_form_for_page();
654 - }
655 -
656 - /**
657 - * @since 4.0
658 - * @deprecated 6.0 The style menu is no longer used in the styler.
659 - *
660 - * @param string $active
661 - * @return string
662 - */
663 - public static function get_style_menu( $active = '' ) {
664 - _deprecated_function( __METHOD__, '6.0' );
665 - return '';
666 - }
667 -
668 - /**
669 - * @deprecated 6.0 The style menu is no longer used in the styler.
670 - *
671 - * @param string $active
672 - * @return void
673 - */
674 - public static function style_menu( $active = '' ) {
675 - _deprecated_function( __METHOD__, '6.0' );
676 - }
677 -
678 - /**
679 - * Either get the heading or the style switcher.
680 - *
681 - * @since 4.0
682 - * @deprecated 6.0 The style switcher was replaced with a form switcher and is no longer used.
683 - *
684 - * @param array $atts
685 - * @return void
686 - */
687 - public static function styler_switcher( $atts ) {
688 - _deprecated_function( __METHOD__, '6.0' );
689 - }
690 -
691 - /**
692 - * @since 4.0
693 - * @deprecated 6.0 The styler now uses the Embed/Preview/Update header. It uses the same save button as other pages with Form tabs.
694 - *
695 - * @param array $atts
696 - * @return void
697 - */
698 - public static function styler_save_button( $atts ) {
699 - _deprecated_function( __METHOD__, '6.0' );
700 507 }
701 508 }