| @@ -4,14 +4,10 @@ | ||
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | class FrmStylesHelper { |
| 7 | 7 | |
| 8 | - /** | |
| 9 | - * @return array | |
| 10 | - */ | |
| 11 | 8 | public static function get_upload_base() { |
| 12 | 9 | $uploads = wp_upload_dir(); |
| 13 | - | |
| 14 | 10 | if ( is_ssl() && ! preg_match( '/^https:\/\/.*\..*$/', $uploads['baseurl'] ) ) { |
| 15 | 11 | $uploads['baseurl'] = str_replace( 'http://', 'https://', $uploads['baseurl'] ); |
| 16 | 12 | } |
| 17 | 13 | |
| @@ -21,23 +17,17 @@ | ||
| 21 | 17 | /** |
| 22 | 18 | * Called from the admin header. |
| 23 | 19 | * |
| 24 | 20 | * @since 4.0 |
| 25 | - * | |
| 26 | - * @return void | |
| 27 | 21 | */ |
| 28 | 22 | public static function save_button() { |
| 29 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 30 | 23 | ?> |
| 31 | 24 | <input type="submit" name="submit" class="button button-primary frm-button-primary" value="<?php esc_attr_e( 'Update', 'formidable' ); ?>" /> |
| 32 | 25 | <?php |
| 33 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 34 | 26 | } |
| 35 | 27 | |
| 36 | 28 | /** |
| 37 | 29 | * @since 2.05 |
| 38 | - * | |
| 39 | - * @return array | |
| 40 | 30 | */ |
| 41 | 31 | public static function get_css_label_positions() { |
| 42 | 32 | return array( |
| 43 | 33 | 'none' => __( 'top', 'formidable' ), |
| @@ -76,11 +66,8 @@ | ||
| 76 | 66 | */ |
| 77 | 67 | return apply_filters( 'frm_single_label_positions', $label_positions, $field ); |
| 78 | 68 | } |
| 79 | 69 | |
| 80 | - /** | |
| 81 | - * @return array | |
| 82 | - */ | |
| 83 | 70 | public static function minus_icons() { |
| 84 | 71 | return array( |
| 85 | 72 | 0 => array( |
| 86 | 73 | '-' => '62e', |
| @@ -104,11 +91,8 @@ | ||
| 104 | 91 | ), |
| 105 | 92 | ); |
| 106 | 93 | } |
| 107 | 94 | |
| 108 | - /** | |
| 109 | - * @return array | |
| 110 | - */ | |
| 111 | 95 | public static function arrow_icons() { |
| 112 | 96 | $minus_icons = self::minus_icons(); |
| 113 | 97 | |
| 114 | 98 | return array( |
| @@ -149,13 +133,8 @@ | ||
| 149 | 133 | } |
| 150 | 134 | |
| 151 | 135 | /** |
| 152 | 136 | * @since 2.0 |
| 153 | - * | |
| 154 | - * @param int|string $key Icon key. | |
| 155 | - * @param string $icon Icon state, `+` or `-`. | |
| 156 | - * @param string $type Icon type, such as `arrow`. | |
| 157 | - * | |
| 158 | 137 | * @return string The class for this icon. |
| 159 | 138 | */ |
| 160 | 139 | public static function icon_key_to_class( $key, $icon = '+', $type = 'arrow' ) { |
| 161 | 140 | if ( 'arrow' === $type && is_numeric( $key ) ) { |
| @@ -177,10 +156,11 @@ | ||
| 177 | 156 | |
| 178 | 157 | if ( $key ) { |
| 179 | 158 | $class .= $key; |
| 180 | 159 | } |
| 160 | + $class .= '_icon'; | |
| 181 | 161 | |
| 182 | - return $class . '_icon'; | |
| 162 | + return $class; | |
| 183 | 163 | } |
| 184 | 164 | |
| 185 | 165 | /** |
| 186 | 166 | * @param WP_Post $style |
| @@ -185,9 +165,8 @@ | ||
| 185 | 165 | /** |
| 186 | 166 | * @param WP_Post $style |
| 187 | 167 | * @param FrmStyle $frm_style |
| 188 | 168 | * @param string $type |
| 189 | - * | |
| 190 | 169 | * @return void |
| 191 | 170 | */ |
| 192 | 171 | public static function bs_icon_select( $style, $frm_style, $type = 'arrow' ) { |
| 193 | 172 | $function_name = $type . '_icons'; |
| @@ -194,9 +173,8 @@ | ||
| 194 | 173 | $icons = self::$function_name(); |
| 195 | 174 | unset( $function_name ); |
| 196 | 175 | |
| 197 | 176 | $name = 'arrow' === $type ? 'collapse_icon' : 'repeat_icon'; |
| 198 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 199 | 177 | ?> |
| 200 | 178 | <div class="btn-group" id="frm_<?php echo esc_attr( $name ); ?>_select"> |
| 201 | 179 | <button class="multiselect dropdown-toggle btn btn-default" data-toggle="dropdown" type="button"> |
| 202 | 180 | <?php FrmAppHelper::icon_by_class( 'frmfont ' . self::icon_key_to_class( $style->post_content[ $name ], '+', $type ) ); ?> |
| @@ -204,12 +182,12 @@ | ||
| 204 | 182 | <b class="caret"></b> |
| 205 | 183 | </button> |
| 206 | 184 | <ul class="multiselect-container frm-dropdown-menu"> |
| 207 | 185 | <?php foreach ( $icons as $key => $icon ) { ?> |
| 208 | - <li <?php echo $style->post_content['collapse_icon'] == $key ? 'class="active"' : ''; // phpcs:ignore Universal.Operators.StrictComparisons ?>> | |
| 186 | + <li <?php echo $style->post_content['collapse_icon'] == $key ? 'class="active"' : ''; ?>> | |
| 209 | 187 | <a href="javascript:void(0);"> |
| 210 | 188 | <label> |
| 211 | - <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 ); ?> /><?php // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?> | |
| 189 | + <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 ); ?> /> | |
| 212 | 190 | <span> |
| 213 | 191 | <?php |
| 214 | 192 | FrmAppHelper::icon_by_class( 'frmfont ' . self::icon_key_to_class( $key, '+', $type ) ); |
| 215 | 193 | FrmAppHelper::icon_by_class( 'frmfont ' . self::icon_key_to_class( $key, '-', $type ) ); |
| @@ -221,9 +199,8 @@ | ||
| 221 | 199 | <?php } ?> |
| 222 | 200 | </ul> |
| 223 | 201 | </div> |
| 224 | 202 | <?php |
| 225 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 226 | 203 | } |
| 227 | 204 | |
| 228 | 205 | /** |
| 229 | 206 | * Convert a color setting to a RGB CSV (without the rgb()/rgba() wrapper). |
| @@ -230,13 +207,16 @@ | ||
| 230 | 207 | * |
| 231 | 208 | * @since 2.0 |
| 232 | 209 | * |
| 233 | 210 | * @param string $color Color setting value. This could be hex or rgb. |
| 234 | - * | |
| 235 | 211 | * @return string RGB value without the rgb() wrapper. |
| 236 | 212 | */ |
| 237 | 213 | public static function hex2rgb( $color ) { |
| 238 | - $rgb = str_starts_with( $color, 'rgb' ) ? self::get_rgb_array_from_rgb( $color ) : self::get_rgb_array_from_hex( $color ); | |
| 214 | + if ( 0 === strpos( $color, 'rgb' ) ) { | |
| 215 | + $rgb = self::get_rgb_array_from_rgb( $color ); | |
| 216 | + } else { | |
| 217 | + $rgb = self::get_rgb_array_from_hex( $color ); | |
| 218 | + } | |
| 239 | 219 | return implode( ',', $rgb ); |
| 240 | 220 | } |
| 241 | 221 | |
| 242 | 222 | /** |
| @@ -244,20 +224,17 @@ | ||
| 244 | 224 | * |
| 245 | 225 | * @since 6.8.3 |
| 246 | 226 | * |
| 247 | 227 | * @param string $rgb RGB value including the rgb() or rgba() wrapper. |
| 248 | - * | |
| 249 | 228 | * @return array<string> including three numeric values for R, G, and B. |
| 250 | 229 | */ |
| 251 | 230 | private static function get_rgb_array_from_rgb( $rgb ) { |
| 252 | 231 | $rgb = str_replace( array( 'rgb(', 'rgba(', ')' ), '', $rgb ); |
| 253 | 232 | $rgb = explode( ',', $rgb ); |
| 254 | - | |
| 255 | 233 | if ( 4 === count( $rgb ) ) { |
| 256 | 234 | // Drop the alpha. The function is expected to only return r,g,b with no alpha. |
| 257 | 235 | array_pop( $rgb ); |
| 258 | 236 | } |
| 259 | - | |
| 260 | 237 | return $rgb; |
| 261 | 238 | } |
| 262 | 239 | |
| 263 | 240 | /** |
| @@ -265,9 +242,8 @@ | ||
| 265 | 242 | * |
| 266 | 243 | * @since 6.8.3 |
| 267 | 244 | * |
| 268 | 245 | * @param string $hex A hex color string. |
| 269 | - * | |
| 270 | 246 | * @return array<string> Including three numeric values for R, G, and B. |
| 271 | 247 | */ |
| 272 | 248 | private static function get_rgb_array_from_hex( $hex ) { |
| 273 | 249 | $hex = str_replace( '#', '', $hex ); |
| @@ -276,16 +252,12 @@ | ||
| 276 | 252 | } |
| 277 | 253 | |
| 278 | 254 | /** |
| 279 | 255 | * @since 4.0 |
| 280 | - * | |
| 281 | - * @param string $hex Hex color string. | |
| 282 | - * @param float|int|string $a Alpha channel value. | |
| 283 | - * | |
| 284 | - * @return string | |
| 285 | 256 | */ |
| 286 | 257 | public static function hex2rgba( $hex, $a ) { |
| 287 | 258 | $rgb = self::hex2rgb( $hex ); |
| 259 | + | |
| 288 | 260 | return 'rgba(' . $rgb . ',' . $a . ')'; |
| 289 | 261 | } |
| 290 | 262 | |
| 291 | 263 | /** |
| @@ -291,13 +263,12 @@ | ||
| 291 | 263 | /** |
| 292 | 264 | * @since 6.0 |
| 293 | 265 | * |
| 294 | 266 | * @param string $rgba Color setting value. This could be hex or rgb. |
| 295 | - * | |
| 296 | 267 | * @return string Hex color value. |
| 297 | 268 | */ |
| 298 | 269 | private static function rgb_to_hex( $rgba ) { |
| 299 | - if ( str_starts_with( $rgba, '#' ) ) { | |
| 270 | + if ( strpos( $rgba, '#' ) === 0 ) { | |
| 300 | 271 | // Color is already hex. |
| 301 | 272 | return $rgba; |
| 302 | 273 | } |
| 303 | 274 | preg_match( '/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i', $rgba, $by_color ); |
| @@ -307,9 +278,8 @@ | ||
| 307 | 278 | /** |
| 308 | 279 | * @since 6.8 |
| 309 | 280 | * |
| 310 | 281 | * @param string $hsl |
| 311 | - * | |
| 312 | 282 | * @return string|null Null if it fails to parse the HSL string. |
| 313 | 283 | */ |
| 314 | 284 | private static function hsl_to_hex( $hsl ) { |
| 315 | 285 | // Convert hsla to hsl. |
| @@ -361,23 +331,22 @@ | ||
| 361 | 331 | $g = round( ( $g + $m ) * 255 ); |
| 362 | 332 | $b = round( ( $b + $m ) * 255 ); |
| 363 | 333 | |
| 364 | 334 | // Convert RGB to hex |
| 365 | - return sprintf( '%02x%02x%02x', $r, $g, $b ); | |
| 335 | + $hex = sprintf( '%02x%02x%02x', $r, $g, $b ); | |
| 336 | + | |
| 337 | + return $hex; | |
| 366 | 338 | } |
| 367 | 339 | |
| 368 | 340 | /** |
| 369 | 341 | * @since 2.3 |
| 370 | - * | |
| 371 | 342 | * @param string $hex string The original color in hex format #ffffff. |
| 372 | 343 | * @param int $steps integer Should be between -255 and 255. Negative = darker, positive = lighter. |
| 373 | - * | |
| 374 | - * @return string | |
| 375 | 344 | */ |
| 376 | 345 | public static function adjust_brightness( $hex, $steps ) { |
| 377 | 346 | $steps = max( - 255, min( 255, $steps ) ); |
| 378 | 347 | |
| 379 | - if ( str_starts_with( $hex, 'rgba(' ) ) { | |
| 348 | + if ( 0 === strpos( $hex, 'rgba(' ) ) { | |
| 380 | 349 | $rgba = str_replace( ')', '', str_replace( 'rgba(', '', $hex ) ); |
| 381 | 350 | list ( $r, $g, $b, $a ) = array_map( 'trim', explode( ',', $rgba ) ); |
| 382 | 351 | $r = max( 0, min( 255, $r + $steps ) ); |
| 383 | 352 | $g = max( 0, min( 255, $g + $steps ) ); |
| @@ -409,34 +378,32 @@ | ||
| 409 | 378 | /** |
| 410 | 379 | * @since 6.0 |
| 411 | 380 | * |
| 412 | 381 | * @param string $color |
| 413 | - * | |
| 414 | 382 | * @return int |
| 415 | 383 | */ |
| 416 | 384 | public static function get_color_brightness( $color ) { |
| 417 | - if ( str_starts_with( $color, 'rgb' ) ) { | |
| 385 | + if ( 0 === strpos( $color, 'rgb' ) ) { | |
| 418 | 386 | $color = self::rgb_to_hex( $color ); |
| 419 | 387 | } |
| 420 | 388 | |
| 421 | - if ( str_starts_with( $color, 'hsl' ) ) { | |
| 389 | + if ( 0 === strpos( $color, 'hsl' ) ) { | |
| 422 | 390 | $hsl_to_hex = self::hsl_to_hex( $color ); |
| 423 | - | |
| 424 | 391 | if ( is_null( $hsl_to_hex ) ) { |
| 425 | 392 | // Fallback if we cannot convert the HSL value. |
| 426 | 393 | return 0; |
| 427 | 394 | } |
| 428 | - | |
| 429 | 395 | $color = $hsl_to_hex; |
| 430 | 396 | } |
| 431 | 397 | |
| 432 | 398 | self::fill_hex( $color ); |
| 433 | 399 | |
| 434 | - $c_r = hexdec( substr( $color, 0, 2 ) ); | |
| 435 | - $c_g = hexdec( substr( $color, 2, 2 ) ); | |
| 436 | - $c_b = hexdec( substr( $color, 4, 2 ) ); | |
| 400 | + $c_r = hexdec( substr( $color, 0, 2 ) ); | |
| 401 | + $c_g = hexdec( substr( $color, 2, 2 ) ); | |
| 402 | + $c_b = hexdec( substr( $color, 4, 2 ) ); | |
| 403 | + $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000; | |
| 437 | 404 | |
| 438 | - return ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000; | |
| 405 | + return $brightness; | |
| 439 | 406 | } |
| 440 | 407 | |
| 441 | 408 | /** |
| 442 | 409 | * Change a 3 character hex color to a 6 character one. |
| @@ -442,10 +409,8 @@ | ||
| 442 | 409 | * Change a 3 character hex color to a 6 character one. |
| 443 | 410 | * |
| 444 | 411 | * @since 6.0 |
| 445 | 412 | * |
| 446 | - * @param string $color Color value, passed by reference. | |
| 447 | - * | |
| 448 | 413 | * @return void |
| 449 | 414 | */ |
| 450 | 415 | private static function fill_hex( &$color ) { |
| 451 | 416 | if ( 3 === strlen( $color ) ) { |
| @@ -454,12 +419,8 @@ | ||
| 454 | 419 | } |
| 455 | 420 | |
| 456 | 421 | /** |
| 457 | 422 | * @since 4.05.02 |
| 458 | - * | |
| 459 | - * @param array $vars CSS variable keys. | |
| 460 | - * | |
| 461 | - * @return array | |
| 462 | 423 | */ |
| 463 | 424 | public static function get_css_vars( $vars = array() ) { |
| 464 | 425 | $vars = apply_filters( 'frm_css_vars', $vars ); |
| 465 | 426 | return array_unique( $vars ); |
| @@ -466,110 +427,42 @@ | ||
| 466 | 427 | } |
| 467 | 428 | |
| 468 | 429 | /** |
| 469 | 430 | * @since 4.05.02 |
| 470 | - * | |
| 471 | - * @param array $settings Style settings. | |
| 472 | - * @param array $defaults Default style settings. | |
| 473 | - * @param array $vars CSS variable keys to output. | |
| 474 | - * | |
| 475 | - * @return void | |
| 476 | 431 | */ |
| 477 | 432 | public static function output_vars( $settings, $defaults = array(), $vars = array() ) { |
| 478 | - if ( ! $vars ) { | |
| 433 | + if ( empty( $vars ) ) { | |
| 479 | 434 | $vars = self::get_css_vars( array_keys( $settings ) ); |
| 480 | 435 | } |
| 436 | + $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', 'use_base_font_size', 'field_shape_type' ); | |
| 437 | + $vars = array_diff( $vars, $remove ); | |
| 481 | 438 | |
| 482 | - $vars = array_diff( $vars, self::get_style_keys_to_remove_from_output_vars() ); | |
| 483 | - | |
| 484 | 439 | foreach ( $vars as $var ) { |
| 485 | 440 | if ( ! isset( $settings[ $var ] ) || ! self::css_key_is_valid( $var ) ) { |
| 486 | 441 | continue; |
| 487 | 442 | } |
| 488 | - | |
| 489 | 443 | if ( ! isset( $defaults[ $var ] ) ) { |
| 490 | 444 | $defaults[ $var ] = ''; |
| 491 | 445 | } |
| 492 | - | |
| 493 | - $prepared_value = ''; | |
| 494 | - | |
| 495 | - if ( self::should_add_css_var( $settings, $defaults, $var, $prepared_value ) ) { | |
| 496 | - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 497 | - echo '--' . esc_html( self::clean_var_name( str_replace( '_', '-', $var ) ) ) . ':' . $prepared_value . ';'; | |
| 446 | + $show = empty( $defaults ) || ( $settings[ $var ] !== '' && $settings[ $var ] !== $defaults[ $var ] ); | |
| 447 | + if ( $show && self::css_value_is_valid( $settings[ $var ] ) ) { | |
| 448 | + echo '--' . esc_html( self::clean_var_name( str_replace( '_', '-', $var ) ) ) . ':' . self::css_var_prepare_value( $settings, $var ) . ';'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 498 | 449 | } |
| 499 | 450 | } |
| 500 | 451 | } |
| 501 | 452 | |
| 502 | 453 | /** |
| 503 | - * None of these style settings are used as CSS variables, so we want to exclude them to keep the CSS output clean. | |
| 504 | - * | |
| 505 | - * @since 6.26.1 | |
| 506 | - * | |
| 507 | - * @return array<string> | |
| 508 | - */ | |
| 509 | - private static function get_style_keys_to_remove_from_output_vars() { | |
| 510 | - return array( | |
| 511 | - 'remove_box_shadow', | |
| 512 | - 'remove_box_shadow_active', | |
| 513 | - 'theme_css', | |
| 514 | - 'theme_name', | |
| 515 | - 'theme_selector', | |
| 516 | - 'important_style', | |
| 517 | - 'submit_style', | |
| 518 | - 'collapse_icon', | |
| 519 | - 'center_form', | |
| 520 | - 'custom_css', | |
| 521 | - 'style_class', | |
| 522 | - 'submit_bg_img', | |
| 523 | - 'change_margin', | |
| 524 | - 'repeat_icon', | |
| 525 | - 'use_base_font_size', | |
| 526 | - 'field_shape_type', | |
| 527 | - 'bg_image_id', | |
| 528 | - 'single_style_custom_css', | |
| 529 | - 'enable_style_custom_css', | |
| 530 | - ); | |
| 531 | - } | |
| 532 | - | |
| 533 | - /** | |
| 534 | - * Check if a CSS variable setting is not blank, doesn't match the default, and doesn't include invalid substrings. | |
| 535 | - * | |
| 536 | - * @since 6.24 | |
| 537 | - * | |
| 538 | - * @param array $settings Array of setting values. | |
| 539 | - * @param array $defaults Array of default values. | |
| 540 | - * @param string $var The setting key name. | |
| 541 | - * @param string $prepared_value The value from calling css_var_prepare_value. This is set by reference so it can be used after this function is called. | |
| 542 | - * | |
| 543 | - * @return bool True if the CSS value should be printed. | |
| 544 | - */ | |
| 545 | - private static function should_add_css_var( $settings, $defaults, $var, &$prepared_value ) { | |
| 546 | - $prepared_value = self::css_var_prepare_value( $settings, $var ); | |
| 547 | - | |
| 548 | - if ( $prepared_value === '' ) { | |
| 549 | - return false; | |
| 550 | - } | |
| 551 | - | |
| 552 | - if ( $defaults && $defaults[ $var ] === $prepared_value ) { | |
| 553 | - return false; | |
| 554 | - } | |
| 555 | - | |
| 556 | - return self::css_value_is_valid( $prepared_value ); | |
| 557 | - } | |
| 558 | - | |
| 559 | - /** | |
| 560 | 454 | * Prevent invalid CSS keys from getting added to the generated CSS. |
| 561 | 455 | * |
| 562 | 456 | * @since 6.20 |
| 563 | 457 | * |
| 564 | 458 | * @param string $key |
| 565 | - * | |
| 566 | 459 | * @return bool |
| 567 | 460 | */ |
| 568 | 461 | private static function css_key_is_valid( $key ) { |
| 569 | 462 | // Any key that is abnormally large is not valid. |
| 570 | 463 | // Any key that contains a '{' is not valid. |
| 571 | - return strlen( $key ) < 100 && ! str_contains( $key, '{' ); | |
| 464 | + return strlen( $key ) < 100 && false === strpos( $key, '{' ); | |
| 572 | 465 | } |
| 573 | 466 | |
| 574 | 467 | /** |
| 575 | 468 | * Confirm a CSS value is valid. |
| @@ -576,10 +469,9 @@ | ||
| 576 | 469 | * If it appears to contain JavaScript, it will not be added. |
| 577 | 470 | * |
| 578 | 471 | * @since 6.20 |
| 579 | 472 | * |
| 580 | - * @param string $var | |
| 581 | - * | |
| 473 | + * @param mixed $var | |
| 582 | 474 | * @return bool |
| 583 | 475 | */ |
| 584 | 476 | private static function css_value_is_valid( $var ) { |
| 585 | 477 | if ( is_numeric( $var ) ) { |
| @@ -585,8 +477,12 @@ | ||
| 585 | 477 | if ( is_numeric( $var ) ) { |
| 586 | 478 | return true; |
| 587 | 479 | } |
| 588 | 480 | |
| 481 | + if ( ! is_string( $var ) ) { | |
| 482 | + return false; | |
| 483 | + } | |
| 484 | + | |
| 589 | 485 | // None of these substrings should be present in any CSS value. |
| 590 | 486 | $invalid_substrings = array( |
| 591 | 487 | 'function(', |
| 592 | 488 | ';userAgent', |
| @@ -597,9 +493,9 @@ | ||
| 597 | 493 | 'Array;', |
| 598 | 494 | ); |
| 599 | 495 | |
| 600 | 496 | foreach ( $invalid_substrings as $substring ) { |
| 601 | - if ( str_contains( $var, $substring ) ) { | |
| 497 | + if ( strpos( $var, $substring ) !== false ) { | |
| 602 | 498 | return false; |
| 603 | 499 | } |
| 604 | 500 | } |
| 605 | 501 | |
| @@ -605,13 +501,13 @@ | ||
| 605 | 501 | |
| 606 | 502 | return true; |
| 607 | 503 | } |
| 608 | 504 | |
| 505 | + | |
| 609 | 506 | /** |
| 610 | 507 | * Remove anything that isn't used as a CSS variable name. |
| 611 | 508 | * |
| 612 | 509 | * @param string $var_name |
| 613 | - * | |
| 614 | 510 | * @return string |
| 615 | 511 | */ |
| 616 | 512 | private static function clean_var_name( $var_name ) { |
| 617 | 513 | return preg_replace( '/[^a-zA-Z0-9_-]/', '', $var_name ); |
| @@ -629,12 +525,8 @@ | ||
| 629 | 525 | */ |
| 630 | 526 | private static function css_var_prepare_value( $settings, $key ) { |
| 631 | 527 | $value = $settings[ $key ]; |
| 632 | 528 | |
| 633 | - if ( ! is_string( $value ) && ! is_numeric( $value ) ) { | |
| 634 | - return ''; | |
| 635 | - } | |
| 636 | - | |
| 637 | 529 | switch ( $key ) { |
| 638 | 530 | case 'font': |
| 639 | 531 | return safecss_filter_attr( $value ); |
| 640 | 532 | |
| @@ -663,9 +555,9 @@ | ||
| 663 | 555 | } |
| 664 | 556 | break; |
| 665 | 557 | }//end switch |
| 666 | 558 | |
| 667 | - return esc_html( $value ); | |
| 559 | + return esc_html( $settings[ $key ] ); | |
| 668 | 560 | } |
| 669 | 561 | |
| 670 | 562 | /** |
| 671 | 563 | * @since 2.3 |
| @@ -670,21 +562,17 @@ | ||
| 670 | 562 | /** |
| 671 | 563 | * @since 2.3 |
| 672 | 564 | * |
| 673 | 565 | * @param WP_Post $style |
| 674 | - * | |
| 675 | 566 | * @return array |
| 676 | 567 | */ |
| 677 | 568 | public static function get_settings_for_output( $style ) { |
| 678 | 569 | if ( self::previewing_style() ) { |
| 679 | 570 | $frm_style = new FrmStyle(); |
| 680 | - | |
| 681 | 571 | if ( isset( $_POST['frm_style_setting'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 682 | 572 | |
| 683 | 573 | // Sanitizing is done later. |
| 684 | - //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing | |
| 685 | - $posted = wp_unslash( $_POST['frm_style_setting'] ); | |
| 686 | - | |
| 574 | + $posted = wp_unslash( $_POST['frm_style_setting'] ); //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing | |
| 687 | 575 | if ( ! is_array( $posted ) ) { |
| 688 | 576 | $posted = json_decode( $posted, true ); |
| 689 | 577 | FrmAppHelper::format_form_data( $posted ); |
| 690 | 578 | $settings = $frm_style->sanitize_post_content( $posted['frm_style_setting']['post_content'] ); |
| @@ -702,9 +590,8 @@ | ||
| 702 | 590 | |
| 703 | 591 | FrmAppHelper::sanitize_value( 'sanitize_text_field', $settings ); |
| 704 | 592 | |
| 705 | 593 | $settings['style_class'] = ''; |
| 706 | - | |
| 707 | 594 | if ( ! empty( $style_name ) ) { |
| 708 | 595 | $settings['style_class'] = $style_name . '.'; |
| 709 | 596 | } |
| 710 | 597 | } else { |
| @@ -716,9 +603,8 @@ | ||
| 716 | 603 | $settings['font'] = stripslashes( $settings['font'] ); |
| 717 | 604 | $settings['change_margin'] = self::description_margin_for_screensize( $settings['width'] ); |
| 718 | 605 | |
| 719 | 606 | $checkbox_opts = array( 'important_style', 'auto_width', 'submit_style', 'collapse_icon', 'center_form' ); |
| 720 | - | |
| 721 | 607 | foreach ( $checkbox_opts as $opt ) { |
| 722 | 608 | if ( ! isset( $settings[ $opt ] ) ) { |
| 723 | 609 | $settings[ $opt ] = 0; |
| 724 | 610 | } |
| @@ -743,9 +629,8 @@ | ||
| 743 | 629 | * |
| 744 | 630 | * @since 6.14 |
| 745 | 631 | * |
| 746 | 632 | * @param array $settings An array of css style. |
| 747 | - * @param array $defaults Default style settings. | |
| 748 | 633 | * |
| 749 | 634 | * @return array |
| 750 | 635 | */ |
| 751 | 636 | public static function update_base_font_size( $settings, $defaults ) { |
| @@ -751,11 +636,10 @@ | ||
| 751 | 636 | public static function update_base_font_size( $settings, $defaults ) { |
| 752 | 637 | if ( empty( $settings['base_font_size'] ) || empty( $settings['use_base_font_size'] ) || 'false' === $settings['use_base_font_size'] ) { |
| 753 | 638 | return $settings; |
| 754 | 639 | } |
| 755 | - | |
| 756 | 640 | $base_font_size = (int) $settings['base_font_size']; |
| 757 | - $font_size = $defaults['font_size']; | |
| 641 | + $font_size = $settings['font_size']; | |
| 758 | 642 | $font_sizes_to_update = array( |
| 759 | 643 | 'font_size', |
| 760 | 644 | 'field_font_size', |
| 761 | 645 | 'check_font_size', |
| @@ -785,12 +669,8 @@ | ||
| 785 | 669 | * Get style font size scale value. |
| 786 | 670 | * |
| 787 | 671 | * @since 6.14 |
| 788 | 672 | * |
| 789 | - * @param string $key Setting key. | |
| 790 | - * @param int|string $value Base font size value. | |
| 791 | - * @param array $defaults Default style settings. | |
| 792 | - * | |
| 793 | 673 | * @return float |
| 794 | 674 | */ |
| 795 | 675 | private static function get_base_font_size_scale( $key, $value, $defaults ) { |
| 796 | 676 | if ( empty( $defaults[ $key ] ) || ! is_numeric( (int) $defaults[ $key ] ) || ! is_numeric( (int) $value ) || 0 === (int) $value ) { |
| @@ -801,22 +681,15 @@ | ||
| 801 | 681 | } |
| 802 | 682 | |
| 803 | 683 | /** |
| 804 | 684 | * @since 2.3 |
| 805 | - * | |
| 806 | - * @param array $settings Style settings, passed by reference. | |
| 807 | - * @param bool $allow_transparent Whether transparent colors are allowed. | |
| 808 | - * | |
| 809 | - * @return void | |
| 810 | 685 | */ |
| 811 | 686 | public static function prepare_color_output( &$settings, $allow_transparent = true ) { |
| 812 | 687 | $colors = self::allow_color_override(); |
| 813 | - | |
| 814 | 688 | foreach ( $colors as $css => $opts ) { |
| 815 | 689 | if ( $css === 'transparent' && ! $allow_transparent ) { |
| 816 | 690 | $css = ''; |
| 817 | 691 | } |
| 818 | - | |
| 819 | 692 | foreach ( $opts as $opt ) { |
| 820 | 693 | self::get_color_output( $css, $settings[ $opt ] ); |
| 821 | 694 | } |
| 822 | 695 | } |
| @@ -856,23 +729,17 @@ | ||
| 856 | 729 | } |
| 857 | 730 | |
| 858 | 731 | /** |
| 859 | 732 | * @since 2.3 |
| 860 | - * | |
| 861 | - * @param string $default Default color value. | |
| 862 | - * @param string $color Color value, passed by reference. | |
| 863 | - * | |
| 864 | - * @return void | |
| 865 | 733 | */ |
| 866 | 734 | private static function get_color_output( $default, &$color ) { |
| 867 | 735 | $color = trim( $color ); |
| 868 | - | |
| 869 | - if ( ! $color ) { | |
| 736 | + if ( empty( $color ) ) { | |
| 870 | 737 | $color = $default; |
| 871 | - } elseif ( str_contains( $color, 'rgb(' ) ) { | |
| 738 | + } elseif ( false !== strpos( $color, 'rgb(' ) ) { | |
| 872 | 739 | $color = str_replace( 'rgb(', 'rgba(', $color ); |
| 873 | 740 | $color = str_replace( ')', ',1)', $color ); |
| 874 | - } elseif ( ! str_contains( $color, '#' ) && self::is_hex( $color ) ) { | |
| 741 | + } elseif ( strpos( $color, '#' ) === false && self::is_hex( $color ) ) { | |
| 875 | 742 | $color = '#' . $color; |
| 876 | 743 | } |
| 877 | 744 | } |
| 878 | 745 | |
| @@ -882,9 +749,8 @@ | ||
| 882 | 749 | * |
| 883 | 750 | * @since 6.8 |
| 884 | 751 | * |
| 885 | 752 | * @param string $color |
| 886 | - * | |
| 887 | 753 | * @return bool |
| 888 | 754 | */ |
| 889 | 755 | private static function is_hex( $color ) { |
| 890 | 756 | $non_hex_substrings = array( |
| @@ -894,9 +760,9 @@ | ||
| 894 | 760 | 'hwb(', |
| 895 | 761 | ); |
| 896 | 762 | |
| 897 | 763 | foreach ( $non_hex_substrings as $substring ) { |
| 898 | - if ( str_contains( $color, $substring ) ) { | |
| 764 | + if ( false !== strpos( $color, $substring ) ) { | |
| 899 | 765 | return false; |
| 900 | 766 | } |
| 901 | 767 | } |
| 902 | 768 | |
| @@ -907,17 +773,12 @@ | ||
| 907 | 773 | * If left/right label is over a certain size, |
| 908 | 774 | * adjust the field description margin at a different screen size |
| 909 | 775 | * |
| 910 | 776 | * @since 2.3 |
| 911 | - * | |
| 912 | - * @param string $width Label width value. | |
| 913 | - * | |
| 914 | - * @return false|string | |
| 915 | 777 | */ |
| 916 | 778 | private static function description_margin_for_screensize( $width ) { |
| 917 | 779 | $temp_label_width = str_replace( 'px', '', $width ); |
| 918 | 780 | $change_margin = false; |
| 919 | - | |
| 920 | 781 | if ( $temp_label_width >= 230 ) { |
| 921 | 782 | $change_margin = '800px'; |
| 922 | 783 | } elseif ( $width >= 215 ) { |
| 923 | 784 | $change_margin = '700px'; |
| @@ -933,10 +794,9 @@ | ||
| 933 | 794 | * |
| 934 | 795 | * @return bool |
| 935 | 796 | */ |
| 936 | 797 | public static function previewing_style() { |
| 937 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 938 | - $ajax_change = isset( $_POST['action'] ) && $_POST['action'] === 'frm_change_styling' && isset( $_POST['frm_style_setting'] ); | |
| 798 | + $ajax_change = isset( $_POST['action'] ) && $_POST['action'] === 'frm_change_styling' && isset( $_POST['frm_style_setting'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 939 | 799 | |
| 940 | 800 | return $ajax_change || isset( $_GET['flat'] ); |
| 941 | 801 | } |
| 942 | 802 | |
| @@ -945,9 +805,8 @@ | ||
| 945 | 805 | * |
| 946 | 806 | * @since 6.0 |
| 947 | 807 | * |
| 948 | 808 | * @param int|string $form_id |
| 949 | - * | |
| 950 | 809 | * @return string |
| 951 | 810 | */ |
| 952 | 811 | public static function get_list_url( $form_id ) { |
| 953 | 812 | return admin_url( 'admin.php?page=formidable-styles&form=' . absint( $form_id ) ); |
| @@ -959,9 +818,8 @@ | ||
| 959 | 818 | * @since 6.14 |
| 960 | 819 | * |
| 961 | 820 | * @param stdClass|WP_Post $style |
| 962 | 821 | * @param int $form_id |
| 963 | - * | |
| 964 | 822 | * @return array |
| 965 | 823 | */ |
| 966 | 824 | public static function get_style_options_back_button_args( $style, $form_id ) { |
| 967 | 825 | if ( self::is_advanced_settings() ) { |
| @@ -1008,9 +866,8 @@ | ||
| 1008 | 866 | * @since 6.0 |
| 1009 | 867 | * |
| 1010 | 868 | * @param int|string $style_id |
| 1011 | 869 | * @param bool $is_default |
| 1012 | - * | |
| 1013 | 870 | * @return int |
| 1014 | 871 | */ |
| 1015 | 872 | public static function get_form_count_for_style( $style_id, $is_default ) { |
| 1016 | 873 | $serialized = serialize( array( 'custom_style' => (string) $style_id ) ); |
| @@ -1029,10 +886,11 @@ | ||
| 1029 | 886 | return $number_of_forms; |
| 1030 | 887 | } |
| 1031 | 888 | |
| 1032 | 889 | $conversational_style_id = FrmDb::get_var( 'posts', array( 'post_name' => 'lines-no-boxes' ), 'ID' ); |
| 890 | + $number_of_forms += self::get_default_style_count( $style_id, $conversational_style_id ); | |
| 1033 | 891 | |
| 1034 | - return $number_of_forms + self::get_default_style_count( $style_id, $conversational_style_id ); | |
| 892 | + return $number_of_forms; | |
| 1035 | 893 | } |
| 1036 | 894 | |
| 1037 | 895 | /** |
| 1038 | 896 | * Get the number of forms that use the default style. |
| @@ -1040,9 +898,8 @@ | ||
| 1040 | 898 | * @since 6.0 |
| 1041 | 899 | * |
| 1042 | 900 | * @param int|string $style_id |
| 1043 | 901 | * @param mixed $conversational_style_id |
| 1044 | - * | |
| 1045 | 902 | * @return int |
| 1046 | 903 | */ |
| 1047 | 904 | private static function get_default_style_count( $style_id, $conversational_style_id ) { |
| 1048 | 905 | $substrings = array_map( |
| @@ -1094,13 +951,14 @@ | ||
| 1094 | 951 | * |
| 1095 | 952 | * @return string The style editor wrapper classname. |
| 1096 | 953 | */ |
| 1097 | 954 | public static function style_editor_get_wrapper_classname( $section_type ) { |
| 1098 | - $is_quick_settings = 'quick-settings' === $section_type; | |
| 955 | + $is_quick_settings = ( 'quick-settings' === $section_type ); | |
| 1099 | 956 | $classname = 'frm-style-editor-form'; |
| 1100 | 957 | $classname .= ( ! self::is_advanced_settings() xor $is_quick_settings ) ? ' frm_hidden' : ''; |
| 958 | + $classname .= FrmAppHelper::pro_is_installed() ? ' frm-pro' : ''; | |
| 1101 | 959 | |
| 1102 | - return $classname . ( FrmAppHelper::pro_is_installed() ? ' frm-pro' : '' ); | |
| 960 | + return $classname; | |
| 1103 | 961 | } |
| 1104 | 962 | |
| 1105 | 963 | /** |
| 1106 | 964 | * Retrieve the background image URL of the submit button. |
| @@ -1108,21 +966,16 @@ | ||
| 1108 | 966 | * |
| 1109 | 967 | * @since 6.14 |
| 1110 | 968 | * |
| 1111 | 969 | * @param array $settings |
| 1112 | - * | |
| 1113 | 970 | * @return false|string Return image url or false. |
| 1114 | 971 | */ |
| 1115 | 972 | public static function get_submit_image_bg_url( $settings ) { |
| 1116 | 973 | $background_image = $settings['submit_bg_img']; |
| 1117 | - | |
| 1118 | - if ( ! $background_image ) { | |
| 974 | + if ( empty( $background_image ) ) { | |
| 1119 | 975 | return false; |
| 1120 | 976 | } |
| 1121 | - | |
| 1122 | - // Handle the case where the submit_bg_img is a full URL string. If the | |
| 1123 | - // Settings were saved with the older styler version prior to 6.14, the | |
| 1124 | - // submit_bg_img will be a full URL string. | |
| 977 | + // Handle the case where the submit_bg_img is a full URL string. If the settings were saved with the older styler version prior to 6.14, the submit_bg_img will be a full URL string. | |
| 1125 | 978 | if ( ! is_numeric( $background_image ) ) { |
| 1126 | 979 | return $background_image; |
| 1127 | 980 | } |
| 1128 | 981 | |
| @@ -1140,9 +993,11 @@ | ||
| 1140 | 993 | if ( ! FrmAppHelper::pro_is_installed() ) { |
| 1141 | 994 | return false; |
| 1142 | 995 | } |
| 1143 | 996 | |
| 1144 | - return is_callable( 'FrmProAppHelper::use_chosen_js' ) ? FrmProAppHelper::use_chosen_js() : true; | |
| 997 | + return is_callable( 'FrmProAppHelper::use_chosen_js' ) | |
| 998 | + ? FrmProAppHelper::use_chosen_js() | |
| 999 | + : true; | |
| 1145 | 1000 | } |
| 1146 | 1001 | |
| 1147 | 1002 | /** |
| 1148 | 1003 | * Returns the bottom part from a margin/padding value. |
| @@ -1149,9 +1004,8 @@ | ||
| 1149 | 1004 | * |
| 1150 | 1005 | * @since 6.17 |
| 1151 | 1006 | * |
| 1152 | 1007 | * @param string $value The margin/padding value. |
| 1153 | - * | |
| 1154 | 1008 | * @return string |
| 1155 | 1009 | */ |
| 1156 | 1010 | public static function get_bottom_value( $value ) { |
| 1157 | 1011 | if ( ! $value ) { |
| @@ -1156,10 +1010,11 @@ | ||
| 1156 | 1010 | public static function get_bottom_value( $value ) { |
| 1157 | 1011 | if ( ! $value ) { |
| 1158 | 1012 | return $value; |
| 1159 | 1013 | } |
| 1160 | - | |
| 1161 | 1014 | $parts = explode( ' ', $value ); |
| 1162 | - | |
| 1163 | - return count( $parts ) < 3 ? $parts[0] : $parts[2]; | |
| 1015 | + if ( count( $parts ) < 3 ) { | |
| 1016 | + return $parts[0]; | |
| 1017 | + } | |
| 1018 | + return $parts[2]; | |
| 1164 | 1019 | } |
| 1165 | 1020 | } |