PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0.09
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.0.09
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 5.0.09, at classes/helpers/FrmStylesHelper.php

512 lines 13.6 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 * @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 /**
67 * Called from the admin header.
68 *
69 * @since 4.0
70 */
71 public static function save_button() {
72 ?>
73 <input type="submit" name="submit" class="button button-primary frm-button-primary" value="<?php esc_attr_e( 'Update', 'formidable' ); ?>" />
74 <?php
75 }
76
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 /**
97 * @since 2.05
98 */
99 public static function get_css_label_positions() {
100 return array(
101 'none' => __( 'top', 'formidable' ),
102 'left' => __( 'left', 'formidable' ),
103 'right' => __( 'right', 'formidable' ),
104 'no_label' => __( 'none', 'formidable' ),
105 'inside' => __( 'inside', 'formidable' ),
106 );
107 }
108
109 public static function get_single_label_positions() {
110 return array(
111 'top' => __( 'Top', 'formidable' ),
112 'left' => __( 'Left', 'formidable' ),
113 'right' => __( 'Right', 'formidable' ),
114 'inline' => __( 'Inline (left without a set width)', 'formidable' ),
115 'none' => __( 'None', 'formidable' ),
116 'hidden' => __( 'Hidden (but leave the space)', 'formidable' ),
117 'inside' => __( 'Placeholder inside the field', 'formidable' ),
118 );
119 }
120
121 public static function minus_icons() {
122 return array(
123 0 => array(
124 '-' => '62e',
125 '+' => '62f',
126 ),
127 1 => array(
128 '-' => '600',
129 '+' => '602',
130 ),
131 2 => array(
132 '-' => '604',
133 '+' => '603',
134 ),
135 3 => array(
136 '-' => '633',
137 '+' => '632',
138 ),
139 4 => array(
140 '-' => '613',
141 '+' => '60f',
142 ),
143 );
144 }
145
146 public static function arrow_icons() {
147 $minus_icons = self::minus_icons();
148
149 return array(
150 6 => array(
151 '-' => '62d',
152 '+' => '62a',
153 ),
154 0 => array(
155 '-' => '60d',
156 '+' => '609',
157 ),
158 1 => array(
159 '-' => '60e',
160 '+' => '60c',
161 ),
162 2 => array(
163 '-' => '630',
164 '+' => '631',
165 ),
166 3 => array(
167 '-' => '62b',
168 '+' => '628',
169 ),
170 4 => array(
171 '-' => '62c',
172 '+' => '629',
173 ),
174 5 => array(
175 '-' => '635',
176 '+' => '634',
177 ),
178 'p0' => $minus_icons[0],
179 'p1' => $minus_icons[1],
180 'p2' => $minus_icons[2],
181 'p3' => $minus_icons[3],
182 'p4' => $minus_icons[4],
183 );
184 }
185
186 /**
187 * @since 2.0
188 * @return string The class for this icon.
189 */
190 public static function icon_key_to_class( $key, $icon = '+', $type = 'arrow' ) {
191 if ( 'arrow' === $type && is_numeric( $key ) ) {
192 //frm_arrowup6_icon
193 $arrow = array(
194 '-' => 'down',
195 '+' => 'up',
196 );
197 $class = 'frm_arrow' . $arrow[ $icon ];
198 } else {
199 //frm_minus1_icon
200 $key = str_replace( 'p', '', $key );
201 $plus = array(
202 '-' => 'minus',
203 '+' => 'plus',
204 );
205 $class = 'frm_' . $plus[ $icon ];
206 }
207
208 if ( $key ) {
209 $class .= $key;
210 }
211 $class .= '_icon';
212
213 return $class;
214 }
215
216 public static function bs_icon_select( $style, $frm_style, $type = 'arrow' ) {
217 $function_name = $type . '_icons';
218 $icons = self::$function_name();
219 unset( $function_name );
220
221 $name = ( 'arrow' == $type ) ? 'collapse_icon' : 'repeat_icon';
222 ?>
223 <div class="btn-group" id="frm_<?php echo esc_attr( $name ); ?>_select">
224 <button class="multiselect dropdown-toggle btn btn-default" data-toggle="dropdown" type="button">
225 <?php FrmAppHelper::icon_by_class( 'frmfont ' . self::icon_key_to_class( $style->post_content[ $name ], '+', $type ) ); ?>
226 <?php FrmAppHelper::icon_by_class( 'frmfont ' . self::icon_key_to_class( $style->post_content[ $name ], '-', $type ) ); ?>
227 <b class="caret"></b>
228 </button>
229 <ul class="multiselect-container frm-dropdown-menu">
230 <?php foreach ( $icons as $key => $icon ) { ?>
231 <li <?php echo ( $style->post_content['collapse_icon'] == $key ) ? 'class="active"' : ''; ?>>
232 <a href="javascript:void(0);">
233 <label>
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 ); ?>/>
235 <span>
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 ) ); ?>
238 </span>
239 </label>
240 </a>
241 </li>
242 <?php } ?>
243 </ul>
244 </div>
245 <?php
246 }
247
248 public static function hex2rgb( $hex ) {
249 $hex = str_replace( '#', '', $hex );
250
251 list( $r, $g, $b ) = sscanf( $hex, '%02x%02x%02x' );
252
253 $rgb = array( $r, $g, $b );
254
255 return implode( ',', $rgb );
256 }
257
258 /**
259 * @since 4.0
260 */
261 public static function hex2rgba( $hex, $a ) {
262 $rgb = self::hex2rgb( $hex );
263
264 return 'rgba(' . $rgb . ',' . $a . ')';
265 }
266
267 /**
268 * @param $hex string - The original color in hex format #ffffff
269 * @param $steps integer - should be between -255 and 255. Negative = darker, positive = lighter
270 *
271 * @since 2.3
272 */
273 public static function adjust_brightness( $hex, $steps ) {
274 $steps = max( - 255, min( 255, $steps ) );
275
276 // Normalize into a six character long hex string
277 $hex = str_replace( '#', '', $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 }
283
284 // Split into three parts: R, G and B
285 $color_parts = str_split( $hex, 2 );
286 $return = '#';
287
288 foreach ( $color_parts as $color ) {
289 $color = hexdec( $color ); // Convert to decimal
290 $color = max( 0, min( 255, $color + $steps ) ); // Adjust color
291 $return .= str_pad( dechex( $color ), 2, '0', STR_PAD_LEFT ); // Make two char hex code
292 }
293
294 return $return;
295 }
296
297 /**
298 * @since 4.05.02
299 */
300 public static function get_css_vars( $vars = array() ) {
301 $vars = apply_filters( 'frm_css_vars', $vars );
302 return array_unique( $vars );
303 }
304
305 /**
306 * @since 4.05.02
307 */
308 public static function output_vars( $settings, $defaults = array(), $vars = array() ) {
309 if ( empty( $vars ) ) {
310 $vars = self::get_css_vars( array_keys( $settings ) );
311 }
312 $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' );
313 $vars = array_diff( $vars, $remove );
314
315 foreach ( $vars as $var ) {
316 if ( ! isset( $settings[ $var ] ) ) {
317 continue;
318 }
319 if ( ! isset( $defaults[ $var ] ) ) {
320 $defaults[ $var ] = '';
321 }
322 $show = empty( $defaults ) || ( $settings[ $var ] !== '' && $settings[ $var ] !== $defaults[ $var ] );
323 if ( $show ) {
324 echo '--' . esc_html( str_replace( '_', '-', $var ) ) . ':' . ( $var === 'font' ? FrmAppHelper::kses( $settings[ $var ] ) : esc_html( $settings[ $var ] ) ) . ';'; // WPCS: XSS ok.
325 }
326 }
327 }
328
329 /**
330 * @since 2.3
331 */
332 public static function get_settings_for_output( $style ) {
333 if ( self::previewing_style() ) {
334
335 if ( isset( $_POST['frm_style_setting'] ) ) {
336 // Sanitizing is done later.
337 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
338 $posted = wp_unslash( $_POST['frm_style_setting'] );
339 if ( ! is_array( $posted ) ) {
340 $posted = json_decode( $posted, true );
341 FrmAppHelper::format_form_data( $posted );
342 $settings = $posted['frm_style_setting']['post_content'];
343 $style_name = sanitize_title( $posted['style_name'] );
344 } else {
345 $settings = $posted['post_content'];
346 $style_name = FrmAppHelper::get_post_param( 'style_name', '', 'sanitize_title' );
347 }
348 } else {
349 $settings = $_GET;
350 $style_name = FrmAppHelper::get_param( 'style_name', '', 'get', 'sanitize_title' );
351 }
352
353 FrmAppHelper::sanitize_value( 'sanitize_text_field', $settings );
354
355 $settings['style_class'] = '';
356 if ( ! empty( $style_name ) ) {
357 $settings['style_class'] = $style_name . '.';
358 }
359 } else {
360 $settings = $style->post_content;
361 $settings['style_class'] = 'frm_style_' . $style->post_name . '.';
362 }
363
364 $settings['style_class'] .= 'with_frm_style';
365 $settings['font'] = stripslashes( $settings['font'] );
366 $settings['change_margin'] = self::description_margin_for_screensize( $settings['width'] );
367
368 $checkbox_opts = array( 'important_style', 'auto_width', 'submit_style', 'collapse_icon', 'center_form' );
369 foreach ( $checkbox_opts as $opt ) {
370 if ( ! isset( $settings[ $opt ] ) ) {
371 $settings[ $opt ] = 0;
372 }
373 }
374
375 self::prepare_color_output( $settings );
376
377 $settings['field_height'] = $settings['field_height'] === '' ? 'auto' : $settings['field_height'];
378 $settings['field_width'] = $settings['field_width'] === '' ? 'auto' : $settings['field_width'];
379 $settings['auto_width'] = $settings['auto_width'] ? 'auto' : $settings['field_width'];
380 $settings['box_shadow'] = ( isset( $settings['remove_box_shadow'] ) && $settings['remove_box_shadow'] ) ? 'none' : '0 1px 1px rgba(0, 0, 0, 0.075) inset';
381
382 if ( ! isset( $settings['repeat_icon'] ) ) {
383 $settings['repeat_icon'] = 1;
384 }
385
386 return $settings;
387 }
388
389 /**
390 * @since 2.3
391 */
392 public static function prepare_color_output( &$settings, $allow_transparent = true ) {
393 $colors = self::allow_color_override();
394 foreach ( $colors as $css => $opts ) {
395 if ( $css === 'transparent' && ! $allow_transparent ) {
396 $css = '';
397 }
398 foreach ( $opts as $opt ) {
399 self::get_color_output( $css, $settings[ $opt ] );
400 }
401 }
402 }
403
404 /**
405 * @since 2.3
406 */
407 private static function allow_color_override() {
408 $frm_style = new FrmStyle();
409 $colors = $frm_style->get_color_settings();
410
411 $transparent = array(
412 'fieldset_color',
413 'fieldset_bg_color',
414 'bg_color',
415 'section_bg_color',
416 'error_bg',
417 'success_bg_color',
418 'progress_bg_color',
419 'progress_active_bg_color',
420 );
421
422 return array(
423 'transparent' => $transparent,
424 '' => array_diff( $colors, $transparent ),
425 );
426 }
427
428 /**
429 * @since 2.3
430 */
431 private static function get_color_output( $default, &$color ) {
432 $color = trim( $color );
433 if ( empty( $color ) ) {
434 $color = $default;
435 } elseif ( false !== strpos( $color, 'rgb(' ) ) {
436 $color = str_replace( 'rgb(', 'rgba(', $color );
437 $color = str_replace( ')', ',1)', $color );
438 } elseif ( strpos( $color, '#' ) === false && false === strpos( $color, 'rgba(' ) ) {
439 $color = '#' . $color;
440 }
441 }
442
443 /**
444 * If left/right label is over a certain size,
445 * adjust the field description margin at a different screen size
446 *
447 * @since 2.3
448 */
449 private static function description_margin_for_screensize( $width ) {
450 $temp_label_width = str_replace( 'px', '', $width );
451 $change_margin = false;
452 if ( $temp_label_width >= 230 ) {
453 $change_margin = '800px';
454 } elseif ( $width >= 215 ) {
455 $change_margin = '700px';
456 } elseif ( $width >= 180 ) {
457 $change_margin = '650px';
458 }
459
460 return $change_margin;
461 }
462
463 /**
464 * @since 2.3
465 */
466 public static function previewing_style() {
467 $ajax_change = isset( $_POST['action'] ) && $_POST['action'] === 'frm_change_styling' && isset( $_POST['frm_style_setting'] );
468
469 return $ajax_change || isset( $_GET['flat'] );
470 }
471
472 /**
473 * @deprecated 3.01
474 * @codeCoverageIgnore
475 */
476 public static function get_sigle_label_postitions() {
477 return FrmDeprecated::get_sigle_label_postitions();
478 }
479
480 /**
481 * @deprecated 3.02.03
482 * @codeCoverageIgnore
483 */
484 public static function jquery_themes() {
485 return FrmDeprecated::jquery_themes();
486 }
487
488 /**
489 * @deprecated 3.02.03
490 * @codeCoverageIgnore
491 */
492 public static function jquery_css_url( $theme_css ) {
493 return FrmDeprecated::jquery_css_url( $theme_css );
494 }
495
496 /**
497 * @deprecated 3.02.03
498 * @codeCoverageIgnore
499 */
500 public static function enqueue_jquery_css() {
501 FrmDeprecated::enqueue_jquery_css();
502 }
503
504 /**
505 * @deprecated 3.02.03
506 * @codeCoverageIgnore
507 */
508 public static function get_form_for_page() {
509 return FrmDeprecated::get_form_for_page();
510 }
511 }
512